Skip to content

Commit 2baedff

Browse files
WIP
Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Fix compile Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Finish Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Compliance Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> PR fixes Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Assistant API v2 (#124) * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Fix compile Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * WIP Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Refactor Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Finish Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Compliance Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * PR fixes Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Upload fix multisession (#129) * fix Signed-off-by: Marino Faggiana <marino@marinofaggiana.com> * fix Signed-off-by: Marino Faggiana <marino@marinofaggiana.com> --------- Signed-off-by: Marino Faggiana <marino@marinofaggiana.com> Co-authored-by: Marino Faggiana <marino@marinofaggiana.com> * Fix: Login poll without cached responses. Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> * Linter Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> --------- Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com> Signed-off-by: Marino Faggiana <marino@marinofaggiana.com> Co-authored-by: Marino Faggiana <marino.faggiana@nextcloud.com> Co-authored-by: Marino Faggiana <marino@marinofaggiana.com>
1 parent d7aa6a2 commit 2baedff

6 files changed

Lines changed: 466 additions & 72 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2025 Milen Pivchev
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import SwiftyJSON
6+
7+
public class NKTextProcessingTask {
8+
public var id: Int?
9+
public var type: String?
10+
public var status: Int?
11+
public var userId: String?
12+
public var appId: String?
13+
public var input: String?
14+
public var output: String?
15+
public var identifier: String?
16+
public var completionExpectedAt: Double?
17+
18+
public init(id: Int? = nil, type: String? = nil, status: Int? = nil, userId: String? = nil, appId: String? = nil, input: String? = nil, output: String? = nil, identifier: String? = nil, completionExpectedAt: Double? = nil) {
19+
self.id = id
20+
self.type = type
21+
self.status = status
22+
self.userId = userId
23+
self.appId = appId
24+
self.input = input
25+
self.output = output
26+
self.identifier = identifier
27+
self.completionExpectedAt = completionExpectedAt
28+
}
29+
30+
public init?(json: JSON) {
31+
self.id = json["id"].int
32+
self.type = json["type"].string
33+
self.status = json["status"].int
34+
self.userId = json["userId"].string
35+
self.appId = json["appId"].string
36+
self.input = json["input"].string
37+
self.output = json["output"].string
38+
self.identifier = json["identifier"].string
39+
self.completionExpectedAt = json["completionExpectedAt"].double
40+
}
41+
42+
static func deserialize(multipleObjects data: JSON) -> [NKTextProcessingTask]? {
43+
guard let allResults = data.array else { return nil }
44+
return allResults.compactMap(NKTextProcessingTask.init)
45+
}
46+
47+
static func deserialize(singleObject data: JSON) -> NKTextProcessingTask? {
48+
NKTextProcessingTask(json: data)
49+
}
50+
51+
public static func toV2(tasks: [NKTextProcessingTask]) -> TaskList {
52+
let tasks = tasks.map { task in
53+
AssistantTask(
54+
id: Int64(task.id ?? 0),
55+
type: task.type,
56+
status: String(task.status ?? 0),
57+
userId: task.userId,
58+
appId: task.appId,
59+
input: TaskInput(input: task.input),
60+
output: TaskOutput(output: task.output),
61+
completionExpectedAt: Int(task.completionExpectedAt ?? 0),
62+
progress: nil,
63+
lastUpdated: nil,
64+
scheduledAt: nil,
65+
endedAt: nil
66+
)
67+
}
68+
69+
return TaskList(tasks: tasks)
70+
}
71+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2025 Milen Pivchev
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import SwiftyJSON
6+
7+
public class NKTextProcessingTaskType {
8+
public var id: String?
9+
public var name: String?
10+
public var description: String?
11+
12+
public init(id: String? = nil, name: String? = nil, description: String? = nil) {
13+
self.id = id
14+
self.name = name
15+
self.description = description
16+
}
17+
18+
public init?(json: JSON) {
19+
self.id = json["id"].string
20+
self.name = json["name"].string
21+
self.description = json["description"].string
22+
}
23+
24+
static func deserialize(multipleObjects data: JSON) -> [NKTextProcessingTaskType]? {
25+
guard let allResults = data.array else { return nil }
26+
return allResults.compactMap(NKTextProcessingTaskType.init)
27+
}
28+
29+
public static func toV2(type: [NKTextProcessingTaskType]) -> TaskTypes {
30+
let types = type.map { type in
31+
TaskTypeData(id: type.id, name: type.name, description: type.description, inputShape: nil, outputShape: nil)
32+
}
33+
34+
return TaskTypes(types: types)
35+
}
36+
}
37+
38+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2025 Milen Pivchev
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import SwiftyJSON
6+
7+
public struct TaskList: Codable {
8+
public var tasks: [AssistantTask]
9+
10+
static func deserialize(from data: JSON) -> TaskList? {
11+
let tasks = data.arrayValue.map { taskJson in
12+
AssistantTask(
13+
id: taskJson["id"].int64Value,
14+
type: taskJson["type"].string,
15+
status: taskJson["status"].string,
16+
userId: taskJson["userId"].string,
17+
appId: taskJson["appId"].string,
18+
input: TaskInput(input: taskJson["input"]["input"].string),
19+
output: TaskOutput(output: taskJson["output"]["output"].string),
20+
completionExpectedAt: taskJson["completionExpectedAt"].int,
21+
progress: taskJson["progress"].int,
22+
lastUpdated: taskJson["lastUpdated"].int,
23+
scheduledAt: taskJson["scheduledAt"].int,
24+
endedAt: taskJson["endedAt"].int
25+
)
26+
}
27+
28+
return TaskList(tasks: tasks)
29+
}
30+
}
31+
32+
public struct AssistantTask: Codable {
33+
public let id: Int64
34+
public let type: String?
35+
public let status: String?
36+
public let userId: String?
37+
public let appId: String?
38+
public let input: TaskInput?
39+
public let output: TaskOutput?
40+
public let completionExpectedAt: Int?
41+
public var progress: Int?
42+
public let lastUpdated: Int?
43+
public let scheduledAt: Int?
44+
public let endedAt: Int?
45+
46+
public init(id: Int64, type: String?, status: String?, userId: String?, appId: String?, input: TaskInput?, output: TaskOutput?, completionExpectedAt: Int?, progress: Int? = nil, lastUpdated: Int?, scheduledAt: Int?, endedAt: Int?) {
47+
self.id = id
48+
self.type = type
49+
self.status = status
50+
self.userId = userId
51+
self.appId = appId
52+
self.input = input
53+
self.output = output
54+
self.completionExpectedAt = completionExpectedAt
55+
self.progress = progress
56+
self.lastUpdated = lastUpdated
57+
self.scheduledAt = scheduledAt
58+
self.endedAt = endedAt
59+
}
60+
61+
static func deserialize(from data: JSON) -> AssistantTask? {
62+
let task = AssistantTask(
63+
id: data["id"].int64Value,
64+
type: data["type"].string,
65+
status: data["status"].string,
66+
userId: data["userId"].string,
67+
appId: data["appId"].string,
68+
input: TaskInput(input: data["input"]["input"].string),
69+
output: TaskOutput(output: data["output"]["output"].string),
70+
completionExpectedAt: data["completionExpectedAt"].int,
71+
progress: data["progress"].int,
72+
lastUpdated: data["lastUpdated"].int,
73+
scheduledAt: data["scheduledAt"].int,
74+
endedAt: data["endedAt"].int
75+
)
76+
77+
return task
78+
}
79+
}
80+
81+
public struct TaskInput: Codable {
82+
public var input: String?
83+
84+
public init(input: String? = nil) {
85+
self.input = input
86+
}
87+
}
88+
89+
public struct TaskOutput: Codable {
90+
public var output: String?
91+
92+
public init(output: String? = nil) {
93+
self.output = output
94+
}
95+
}
96+
97+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// SPDX-FileCopyrightText: Nextcloud GmbH
2+
// SPDX-FileCopyrightText: 2025 Milen Pivchev
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
import SwiftyJSON
6+
7+
public struct TaskTypes: Codable {
8+
public let types: [TaskTypeData]
9+
10+
static func deserialize(from data: JSON) -> TaskTypes? {
11+
var taskTypes: [TaskTypeData] = []
12+
13+
for (key, subJson) in data {
14+
let taskTypeData = TaskTypeData(
15+
id: key,
16+
name: subJson["name"].string,
17+
description: subJson["description"].string,
18+
inputShape: subJson["inputShape"].dictionary != nil ? TaskInputShape(
19+
input: subJson["inputShape"]["input"].dictionary != nil ? Shape(
20+
name: subJson["inputShape"]["input"]["name"].stringValue,
21+
description: subJson["inputShape"]["input"]["description"].stringValue,
22+
type: subJson["inputShape"]["input"]["type"].stringValue
23+
) : nil
24+
) : nil,
25+
outputShape: subJson["outputShape"].dictionary != nil ? TaskOutputShape(
26+
output: subJson["outputShape"]["output"].dictionary != nil ? Shape(
27+
name: subJson["outputShape"]["output"]["name"].stringValue,
28+
description: subJson["outputShape"]["output"]["description"].stringValue,
29+
type: subJson["outputShape"]["output"]["type"].stringValue
30+
) : nil
31+
) : nil
32+
)
33+
34+
taskTypes.append(taskTypeData)
35+
}
36+
37+
return TaskTypes(types: taskTypes)
38+
}
39+
}
40+
41+
public struct TaskTypeData: Codable {
42+
public let id: String?
43+
public let name: String?
44+
public let description: String?
45+
public let inputShape: TaskInputShape?
46+
public let outputShape: TaskOutputShape?
47+
48+
public init(id: String?, name: String?, description: String?, inputShape: TaskInputShape?, outputShape: TaskOutputShape?) {
49+
self.id = id
50+
self.name = name
51+
self.description = description
52+
self.inputShape = inputShape
53+
self.outputShape = outputShape
54+
}
55+
}
56+
57+
public struct TaskInputShape: Codable {
58+
public let input: Shape?
59+
60+
public init(input: Shape?) {
61+
self.input = input
62+
}
63+
}
64+
65+
public struct TaskOutputShape: Codable {
66+
public let output: Shape?
67+
68+
public init(output: Shape?) {
69+
self.output = output
70+
}
71+
}
72+
73+
public struct Shape: Codable {
74+
public let name: String
75+
public let description: String
76+
public let type: String
77+
78+
public init(name: String, description: String, type: String) {
79+
self.name = name
80+
self.description = description
81+
self.type = type
82+
}
83+
}
84+
85+
86+
87+
88+
89+

0 commit comments

Comments
 (0)