@@ -19,6 +19,32 @@ import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
1919import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypes
2020import org.apache.commons.httpclient.HttpStatus
2121
22+ /* *
23+ * Returns a list of supported task types.
24+ *
25+ * Example JSON representation of one task type:
26+ * ```
27+ * {
28+ * "id": "core:text2text",
29+ * "name": "Free text to text prompt",
30+ * "description": "Runs an arbitrary prompt through a language model that returns a reply",
31+ * "inputShape": {
32+ * "input": {
33+ * "name": "Prompt",
34+ * "description": "Describe a task that you want the assistant to do or ask a question",
35+ * "type": "Text"
36+ * }
37+ * },
38+ * "outputShape": {
39+ * "output": {
40+ * "name": "Generated reply",
41+ * "description": "The generated text from the assistant",
42+ * "type": "Text"
43+ * }
44+ * }
45+ * }
46+ * ```
47+ */
2248class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation <List <TaskTypeData >>() {
2349 private val supportedTaskType = " Text"
2450
@@ -36,21 +62,18 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
3662 getServerResponse(
3763 getMethod,
3864 object : TypeToken <ServerResponse <TaskTypes >>() {}
39- )?.ocs?.data?.types
65+ )
4066
4167 val taskTypeList =
42- response?.map { (key, value) ->
43- value.copy(id = value.id ? : key)
44- }
45-
46- val supportedTaskTypeList =
47- taskTypeList?.filter { taskType ->
48- taskType.inputShape?.input?.type == supportedTaskType &&
49- taskType.outputShape?.output?.type == supportedTaskType
50- }
68+ response
69+ ?.ocs
70+ ?.data
71+ ?.types
72+ ?.map { (key, value) -> value.copy(id = value.id ? : key) }
73+ ?.filter { taskType -> isSingleTextInputOutput(taskType) }
5174
5275 result = RemoteOperationResult (true , getMethod)
53- result.setResultData(supportedTaskTypeList)
76+ result.resultData = taskTypeList
5477 } else {
5578 result = RemoteOperationResult (false , getMethod)
5679 }
@@ -67,6 +90,21 @@ class GetTaskTypesRemoteOperationV2 : OCSRemoteOperation<List<TaskTypeData>>() {
6790 return result
6891 }
6992
93+ private fun isSingleTextInputOutput (taskType : TaskTypeData ): Boolean {
94+ val inputShape = taskType.inputShape
95+ val outputShape = taskType.outputShape
96+
97+ val hasOneTextInput =
98+ inputShape?.size == 1 &&
99+ inputShape.values.first().type == supportedTaskType
100+
101+ val hasOneTextOutput =
102+ outputShape?.size == 1 &&
103+ outputShape.values.first().type == supportedTaskType
104+
105+ return hasOneTextInput && hasOneTextOutput
106+ }
107+
70108 companion object {
71109 private val TAG = GetTaskTypesRemoteOperationV2 ::class .java.simpleName
72110 private const val DIRECT_ENDPOINT = " /ocs/v2.php/taskprocessing/tasktypes"
0 commit comments