lemma-sdk 0.2.37 → 0.2.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -14
- package/dist/browser/lemma-client.js +260 -206
- package/dist/client.d.ts +2 -2
- package/dist/client.js +3 -3
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -2
- package/dist/namespaces/conversations.d.ts +0 -5
- package/dist/namespaces/conversations.js +0 -15
- package/dist/namespaces/pod-members.d.ts +5 -3
- package/dist/namespaces/pod-members.js +12 -6
- package/dist/namespaces/schedules.d.ts +22 -0
- package/dist/namespaces/schedules.js +24 -0
- package/dist/namespaces/workflows.d.ts +4 -5
- package/dist/namespaces/workflows.js +1 -4
- package/dist/openapi_client/index.d.ts +12 -12
- package/dist/openapi_client/index.js +5 -3
- package/dist/openapi_client/models/AgentModelName.d.ts +1 -1
- package/dist/openapi_client/models/AgentModelName.js +1 -1
- package/dist/openapi_client/models/CreateScheduleRequest.d.ts +14 -0
- package/dist/openapi_client/models/FlowResponse.d.ts +2 -2
- package/dist/openapi_client/models/FlowRunEntity.d.ts +5 -4
- package/dist/openapi_client/models/FormNodeConfig.d.ts +8 -0
- package/dist/openapi_client/models/MessageResponse.d.ts +0 -1
- package/dist/openapi_client/models/PodConfigResponse.d.ts +0 -2
- package/dist/openapi_client/models/PodMemberDetailResponse.d.ts +2 -0
- package/dist/openapi_client/models/PodMemberResponse.d.ts +2 -0
- package/dist/openapi_client/models/ScheduleListResponse.d.ts +9 -0
- package/dist/openapi_client/models/{TriggerResponse.d.ts → ScheduleResponse.d.ts} +8 -4
- package/dist/openapi_client/models/{TriggerType.d.ts → ScheduleType.d.ts} +2 -2
- package/dist/openapi_client/models/ScheduleType.js +13 -0
- package/dist/openapi_client/models/ScheduledFlowStartInput.d.ts +1 -1
- package/dist/openapi_client/models/ScheduledFlowStartOutput.d.ts +1 -1
- package/dist/openapi_client/models/SendMessageRequest.d.ts +0 -2
- package/dist/openapi_client/models/{UpdateTriggerRequest.d.ts → UpdateScheduleRequest.d.ts} +4 -2
- package/dist/openapi_client/models/WorkflowCreateRequest.d.ts +3 -3
- package/dist/openapi_client/models/WorkflowMode.d.ts +7 -0
- package/dist/openapi_client/models/WorkflowMode.js +12 -0
- package/dist/openapi_client/models/WorkflowRunWaitAssignment.d.ts +6 -0
- package/dist/openapi_client/models/WorkflowRunWaitAssignmentListResponse.d.ts +6 -0
- package/dist/openapi_client/models/WorkflowRunWaitEntity.d.ts +20 -0
- package/dist/openapi_client/models/WorkflowRunWaitStatus.d.ts +6 -0
- package/dist/openapi_client/models/WorkflowRunWaitStatus.js +11 -0
- package/dist/openapi_client/models/WorkflowRunWaitType.d.ts +7 -0
- package/dist/openapi_client/models/WorkflowRunWaitType.js +12 -0
- package/dist/openapi_client/models/WorkflowUpdateRequest.d.ts +3 -3
- package/dist/openapi_client/services/AgentConversationsService.d.ts +4 -14
- package/dist/openapi_client/services/AgentConversationsService.js +4 -30
- package/dist/openapi_client/services/PodMembersService.d.ts +25 -7
- package/dist/openapi_client/services/PodMembersService.js +57 -13
- package/dist/openapi_client/services/SchedulesService.d.ts +59 -0
- package/dist/openapi_client/services/SchedulesService.js +125 -0
- package/dist/openapi_client/services/WebhooksService.d.ts +4 -4
- package/dist/openapi_client/services/WebhooksService.js +6 -6
- package/dist/openapi_client/services/WorkflowsService.d.ts +12 -33
- package/dist/openapi_client/services/WorkflowsService.js +26 -69
- package/dist/react/AuthGuard.js +1 -1
- package/dist/react/index.d.ts +10 -8
- package/dist/react/index.js +5 -4
- package/dist/react/useAssistantController.js +0 -2
- package/dist/react/useAssistantSession.d.ts +0 -2
- package/dist/react/useAssistantSession.js +8 -14
- package/dist/react/useCreateSchedule.d.ts +17 -0
- package/dist/react/useCreateSchedule.js +45 -0
- package/dist/react/useDeleteSchedule.d.ts +19 -0
- package/dist/react/useDeleteSchedule.js +49 -0
- package/dist/react/usePodAccess.js +1 -1
- package/dist/react/useSchedules.d.ts +30 -0
- package/dist/react/useSchedules.js +123 -0
- package/dist/react/useUpdateSchedule.d.ts +20 -0
- package/dist/react/useUpdateSchedule.js +49 -0
- package/dist/react/useWorkflowRun.js +1 -1
- package/dist/react/useWorkflowRunWaitAssignments.d.ts +26 -0
- package/dist/react/useWorkflowRunWaitAssignments.js +102 -0
- package/dist/react/useWorkflowStart.js +1 -1
- package/dist/run-utils.d.ts +1 -5
- package/dist/run-utils.js +0 -10
- package/dist/types.d.ts +3 -43
- package/package.json +1 -1
- package/dist/namespaces/tasks.d.ts +0 -25
- package/dist/namespaces/tasks.js +0 -91
- package/dist/openapi_client/models/CreateTriggerRequest.d.ts +0 -13
- package/dist/openapi_client/models/FlowInstallResponse.d.ts +0 -15
- package/dist/openapi_client/models/PodFlowConfigItem.d.ts +0 -7
- package/dist/openapi_client/models/TriggerListResponse.d.ts +0 -9
- package/dist/openapi_client/models/TriggerType.js +0 -13
- package/dist/openapi_client/models/WorkflowInstallListResponse.d.ts +0 -4
- package/dist/openapi_client/models/WorkflowInstallMode.d.ts +0 -7
- package/dist/openapi_client/models/WorkflowInstallMode.js +0 -12
- package/dist/openapi_client/models/WorkflowInstallRequest.d.ts +0 -11
- package/dist/openapi_client/models/WorkflowInstallRequest.js +0 -1
- package/dist/openapi_client/models/WorkflowTimeInstallConfig.d.ts +0 -19
- package/dist/openapi_client/models/WorkflowTimeInstallConfig.js +0 -1
- package/dist/openapi_client/services/TriggersService.d.ts +0 -53
- package/dist/openapi_client/services/TriggersService.js +0 -109
- package/dist/react/useAgentRun.d.ts +0 -38
- package/dist/react/useAgentRun.js +0 -149
- package/dist/react/useAgentRuns.d.ts +0 -33
- package/dist/react/useAgentRuns.js +0 -149
- package/dist/react/useAssistantRun.d.ts +0 -27
- package/dist/react/useAssistantRun.js +0 -47
- package/dist/react/useTaskSession.d.ts +0 -35
- package/dist/react/useTaskSession.js +0 -269
- package/dist/task-events.d.ts +0 -8
- package/dist/task-events.js +0 -115
- /package/dist/openapi_client/models/{CreateTriggerRequest.js → CreateScheduleRequest.js} +0 -0
- /package/dist/openapi_client/models/{FlowInstallResponse.js → ScheduleListResponse.js} +0 -0
- /package/dist/openapi_client/models/{PodFlowConfigItem.js → ScheduleResponse.js} +0 -0
- /package/dist/openapi_client/models/{TriggerListResponse.js → UpdateScheduleRequest.js} +0 -0
- /package/dist/openapi_client/models/{TriggerResponse.js → WorkflowRunWaitAssignment.js} +0 -0
- /package/dist/openapi_client/models/{UpdateTriggerRequest.js → WorkflowRunWaitAssignmentListResponse.js} +0 -0
- /package/dist/openapi_client/models/{WorkflowInstallListResponse.js → WorkflowRunWaitEntity.js} +0 -0
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
-
import { parseSSEJson, readSSE } from "../streams.js";
|
|
3
|
-
import { isTerminalTaskStatus, normalizeRunStatus } from "../run-utils.js";
|
|
4
|
-
import { parseTaskStreamEvent, upsertTaskMessage } from "../task-events.js";
|
|
5
|
-
import { normalizeError, resolvePodClient, resolvePodId } from "./utils.js";
|
|
6
|
-
function sleep(ms) {
|
|
7
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
8
|
-
}
|
|
9
|
-
export function useTaskSession({ client, podId, taskId: externalTaskId = null, autoConnect = true, autoConnectOnStart = true, onEvent, onStatus, onMessage, onError, }) {
|
|
10
|
-
const [taskId, setTaskIdState] = useState(externalTaskId);
|
|
11
|
-
const [task, setTask] = useState(null);
|
|
12
|
-
const [status, setStatus] = useState(undefined);
|
|
13
|
-
const [messages, setMessages] = useState([]);
|
|
14
|
-
const [isStreaming, setIsStreaming] = useState(false);
|
|
15
|
-
const [error, setError] = useState(null);
|
|
16
|
-
const abortRef = useRef(null);
|
|
17
|
-
const previousExternalTaskIdRef = useRef(externalTaskId);
|
|
18
|
-
const taskIdRef = useRef(externalTaskId);
|
|
19
|
-
const statusRef = useRef(undefined);
|
|
20
|
-
const onEventRef = useRef(onEvent);
|
|
21
|
-
const onStatusRef = useRef(onStatus);
|
|
22
|
-
const onMessageRef = useRef(onMessage);
|
|
23
|
-
const onErrorRef = useRef(onError);
|
|
24
|
-
const setTaskStatus = useCallback((nextStatus) => {
|
|
25
|
-
const normalized = normalizeRunStatus(nextStatus);
|
|
26
|
-
setStatus(normalized);
|
|
27
|
-
statusRef.current = normalized;
|
|
28
|
-
if (normalized) {
|
|
29
|
-
onStatusRef.current?.(normalized);
|
|
30
|
-
}
|
|
31
|
-
}, []);
|
|
32
|
-
const setTaskId = useCallback((nextTaskId) => {
|
|
33
|
-
setTaskIdState((currentTaskId) => {
|
|
34
|
-
if (currentTaskId === nextTaskId) {
|
|
35
|
-
return currentTaskId;
|
|
36
|
-
}
|
|
37
|
-
abortRef.current?.abort();
|
|
38
|
-
abortRef.current = null;
|
|
39
|
-
taskIdRef.current = nextTaskId;
|
|
40
|
-
setError(null);
|
|
41
|
-
setIsStreaming(false);
|
|
42
|
-
if (!nextTaskId) {
|
|
43
|
-
setTask(null);
|
|
44
|
-
setTaskStatus(undefined);
|
|
45
|
-
setMessages([]);
|
|
46
|
-
}
|
|
47
|
-
return nextTaskId;
|
|
48
|
-
});
|
|
49
|
-
}, [setTaskStatus]);
|
|
50
|
-
const disconnect = useCallback(() => {
|
|
51
|
-
abortRef.current?.abort();
|
|
52
|
-
abortRef.current = null;
|
|
53
|
-
setIsStreaming(false);
|
|
54
|
-
}, []);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
taskIdRef.current = taskId;
|
|
57
|
-
}, [taskId]);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
statusRef.current = status;
|
|
60
|
-
}, [status]);
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
onEventRef.current = onEvent;
|
|
63
|
-
}, [onEvent]);
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
onStatusRef.current = onStatus;
|
|
66
|
-
}, [onStatus]);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
onMessageRef.current = onMessage;
|
|
69
|
-
}, [onMessage]);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
onErrorRef.current = onError;
|
|
72
|
-
}, [onError]);
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (previousExternalTaskIdRef.current === externalTaskId) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
previousExternalTaskIdRef.current = externalTaskId;
|
|
78
|
-
setTaskId(externalTaskId);
|
|
79
|
-
}, [externalTaskId, setTaskId]);
|
|
80
|
-
const refreshTask = useCallback(async (explicitTaskId) => {
|
|
81
|
-
const id = explicitTaskId ?? taskIdRef.current;
|
|
82
|
-
if (!id)
|
|
83
|
-
return null;
|
|
84
|
-
try {
|
|
85
|
-
const scopedClient = resolvePodClient(client, resolvePodId(client, podId));
|
|
86
|
-
const nextTask = await scopedClient.tasks.get(id);
|
|
87
|
-
setTask(nextTask);
|
|
88
|
-
setTaskStatus(nextTask.status);
|
|
89
|
-
return nextTask;
|
|
90
|
-
}
|
|
91
|
-
catch (refreshError) {
|
|
92
|
-
const normalized = normalizeError(refreshError, "Failed to fetch task.");
|
|
93
|
-
setError(normalized);
|
|
94
|
-
onErrorRef.current?.(refreshError);
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
}, [client, podId, setTaskStatus]);
|
|
98
|
-
const loadMessages = useCallback(async (explicitTaskId) => {
|
|
99
|
-
const id = explicitTaskId ?? taskIdRef.current;
|
|
100
|
-
if (!id)
|
|
101
|
-
return [];
|
|
102
|
-
try {
|
|
103
|
-
const scopedClient = resolvePodClient(client, resolvePodId(client, podId));
|
|
104
|
-
const response = await scopedClient.tasks.messages.list(id, { limit: 100 });
|
|
105
|
-
const nextMessages = response.items ?? [];
|
|
106
|
-
setMessages(nextMessages);
|
|
107
|
-
return nextMessages;
|
|
108
|
-
}
|
|
109
|
-
catch (messageError) {
|
|
110
|
-
const normalized = normalizeError(messageError, "Failed to fetch task messages.");
|
|
111
|
-
setError(normalized);
|
|
112
|
-
onErrorRef.current?.(messageError);
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
}, [client, podId]);
|
|
116
|
-
const connect = useCallback(async (explicitTaskId) => {
|
|
117
|
-
const id = explicitTaskId ?? taskIdRef.current;
|
|
118
|
-
if (!id)
|
|
119
|
-
return;
|
|
120
|
-
setTaskIdState(id);
|
|
121
|
-
taskIdRef.current = id;
|
|
122
|
-
disconnect();
|
|
123
|
-
const controller = new AbortController();
|
|
124
|
-
abortRef.current = controller;
|
|
125
|
-
setError(null);
|
|
126
|
-
setIsStreaming(true);
|
|
127
|
-
let reconnectDelayMs = 1000;
|
|
128
|
-
try {
|
|
129
|
-
while (!controller.signal.aborted) {
|
|
130
|
-
if (isTerminalTaskStatus(statusRef.current)) {
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
try {
|
|
134
|
-
const scopedClient = resolvePodClient(client, resolvePodId(client, podId));
|
|
135
|
-
const stream = await scopedClient.tasks.stream(id, { signal: controller.signal });
|
|
136
|
-
reconnectDelayMs = 1000;
|
|
137
|
-
for await (const event of readSSE(stream)) {
|
|
138
|
-
if (controller.signal.aborted) {
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
const payload = parseSSEJson(event);
|
|
142
|
-
onEventRef.current?.(event, payload);
|
|
143
|
-
const parsed = parseTaskStreamEvent(payload);
|
|
144
|
-
if (parsed.task?.id === id) {
|
|
145
|
-
setTask(parsed.task);
|
|
146
|
-
setTaskStatus(parsed.task.status);
|
|
147
|
-
}
|
|
148
|
-
if (parsed.message) {
|
|
149
|
-
setMessages((previous) => upsertTaskMessage(previous, parsed.message));
|
|
150
|
-
onMessageRef.current?.(parsed.message);
|
|
151
|
-
}
|
|
152
|
-
if (parsed.status) {
|
|
153
|
-
setTaskStatus(parsed.status);
|
|
154
|
-
setTask((previous) => {
|
|
155
|
-
if (!previous || previous.id !== id)
|
|
156
|
-
return previous;
|
|
157
|
-
return {
|
|
158
|
-
...previous,
|
|
159
|
-
status: parsed.status,
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (isTerminalTaskStatus(statusRef.current)) {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (controller.signal.aborted || isTerminalTaskStatus(statusRef.current)) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
await sleep(Math.max(reconnectDelayMs, 2000));
|
|
171
|
-
reconnectDelayMs = Math.min(Math.max(reconnectDelayMs * 2, 2000), 6000);
|
|
172
|
-
}
|
|
173
|
-
catch (streamError) {
|
|
174
|
-
if (streamError instanceof Error && streamError.name === "AbortError") {
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
const normalized = normalizeError(streamError, "Failed to stream task run.");
|
|
178
|
-
setError(normalized);
|
|
179
|
-
onErrorRef.current?.(streamError);
|
|
180
|
-
await sleep(reconnectDelayMs);
|
|
181
|
-
reconnectDelayMs = Math.min(reconnectDelayMs * 2, 6000);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
finally {
|
|
186
|
-
if (abortRef.current === controller) {
|
|
187
|
-
abortRef.current = null;
|
|
188
|
-
}
|
|
189
|
-
setIsStreaming(false);
|
|
190
|
-
}
|
|
191
|
-
}, [client, disconnect, podId, setTaskStatus]);
|
|
192
|
-
const start = useCallback(async (input) => {
|
|
193
|
-
setError(null);
|
|
194
|
-
const scopedClient = resolvePodClient(client, resolvePodId(client, podId));
|
|
195
|
-
const created = await scopedClient.tasks.create({
|
|
196
|
-
agent_name: input.agentName,
|
|
197
|
-
input_data: input.inputData,
|
|
198
|
-
});
|
|
199
|
-
taskIdRef.current = created.id;
|
|
200
|
-
setTask(created);
|
|
201
|
-
setTaskIdState(created.id);
|
|
202
|
-
setMessages([]);
|
|
203
|
-
setTaskStatus(created.status);
|
|
204
|
-
if (autoConnectOnStart && !autoConnect) {
|
|
205
|
-
await connect(created.id);
|
|
206
|
-
}
|
|
207
|
-
return created;
|
|
208
|
-
}, [autoConnect, autoConnectOnStart, client, connect, podId, setTaskStatus]);
|
|
209
|
-
const stop = useCallback(async () => {
|
|
210
|
-
const id = taskIdRef.current;
|
|
211
|
-
if (!id)
|
|
212
|
-
return null;
|
|
213
|
-
try {
|
|
214
|
-
const scopedClient = resolvePodClient(client, resolvePodId(client, podId));
|
|
215
|
-
const stopped = await scopedClient.tasks.stop(id);
|
|
216
|
-
setTask(stopped);
|
|
217
|
-
setTaskStatus(stopped.status);
|
|
218
|
-
return stopped;
|
|
219
|
-
}
|
|
220
|
-
catch (stopError) {
|
|
221
|
-
const normalized = normalizeError(stopError, "Failed to stop task run.");
|
|
222
|
-
setError(normalized);
|
|
223
|
-
onErrorRef.current?.(stopError);
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
}, [client, podId, setTaskStatus]);
|
|
227
|
-
const clearMessages = useCallback(() => {
|
|
228
|
-
setMessages([]);
|
|
229
|
-
}, []);
|
|
230
|
-
useEffect(() => {
|
|
231
|
-
if (!taskId)
|
|
232
|
-
return;
|
|
233
|
-
let cancelled = false;
|
|
234
|
-
const bootstrapTask = async () => {
|
|
235
|
-
const latestTask = await refreshTask(taskId);
|
|
236
|
-
if (cancelled)
|
|
237
|
-
return;
|
|
238
|
-
await loadMessages(taskId);
|
|
239
|
-
if (cancelled || !autoConnect)
|
|
240
|
-
return;
|
|
241
|
-
const latestStatus = normalizeRunStatus(latestTask?.status) ?? normalizeRunStatus(statusRef.current);
|
|
242
|
-
if (isTerminalTaskStatus(latestStatus)) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
await connect(taskId);
|
|
246
|
-
};
|
|
247
|
-
void bootstrapTask();
|
|
248
|
-
return () => {
|
|
249
|
-
cancelled = true;
|
|
250
|
-
disconnect();
|
|
251
|
-
};
|
|
252
|
-
}, [autoConnect, connect, disconnect, loadMessages, refreshTask, taskId]);
|
|
253
|
-
return {
|
|
254
|
-
taskId,
|
|
255
|
-
task,
|
|
256
|
-
status,
|
|
257
|
-
messages,
|
|
258
|
-
isStreaming,
|
|
259
|
-
error,
|
|
260
|
-
setTaskId,
|
|
261
|
-
start,
|
|
262
|
-
refreshTask,
|
|
263
|
-
loadMessages,
|
|
264
|
-
connect,
|
|
265
|
-
disconnect,
|
|
266
|
-
stop,
|
|
267
|
-
clearMessages,
|
|
268
|
-
};
|
|
269
|
-
}
|
package/dist/task-events.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Task, TaskMessage } from "./types.js";
|
|
2
|
-
export interface ParsedTaskStreamEvent {
|
|
3
|
-
message?: TaskMessage;
|
|
4
|
-
status?: string;
|
|
5
|
-
task?: Task;
|
|
6
|
-
}
|
|
7
|
-
export declare function parseTaskStreamEvent(value: unknown): ParsedTaskStreamEvent;
|
|
8
|
-
export declare function upsertTaskMessage(messages: TaskMessage[], incoming: TaskMessage): TaskMessage[];
|
package/dist/task-events.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
function isRecord(value) {
|
|
2
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
3
|
-
}
|
|
4
|
-
function normalizeStatus(status) {
|
|
5
|
-
if (typeof status !== "string")
|
|
6
|
-
return undefined;
|
|
7
|
-
const normalized = status.trim().toUpperCase();
|
|
8
|
-
return normalized.length > 0 ? normalized : undefined;
|
|
9
|
-
}
|
|
10
|
-
function toTaskMessage(value) {
|
|
11
|
-
if (!isRecord(value))
|
|
12
|
-
return undefined;
|
|
13
|
-
if (typeof value.id !== "string")
|
|
14
|
-
return undefined;
|
|
15
|
-
if (typeof value.role !== "string")
|
|
16
|
-
return undefined;
|
|
17
|
-
if (!("content" in value))
|
|
18
|
-
return undefined;
|
|
19
|
-
const content = value.content;
|
|
20
|
-
const message = {
|
|
21
|
-
id: value.id,
|
|
22
|
-
role: value.role,
|
|
23
|
-
content: content,
|
|
24
|
-
created_at: typeof value.created_at === "string" ? value.created_at : new Date().toISOString(),
|
|
25
|
-
metadata: isRecord(value.metadata) ? value.metadata : null,
|
|
26
|
-
};
|
|
27
|
-
return message;
|
|
28
|
-
}
|
|
29
|
-
function toTask(value) {
|
|
30
|
-
if (!isRecord(value))
|
|
31
|
-
return undefined;
|
|
32
|
-
if (typeof value.id !== "string")
|
|
33
|
-
return undefined;
|
|
34
|
-
const status = normalizeStatus(value.status);
|
|
35
|
-
if (!status)
|
|
36
|
-
return undefined;
|
|
37
|
-
if (typeof value.agent_id !== "string")
|
|
38
|
-
return undefined;
|
|
39
|
-
if (typeof value.pod_id !== "string")
|
|
40
|
-
return undefined;
|
|
41
|
-
if (typeof value.user_id !== "string")
|
|
42
|
-
return undefined;
|
|
43
|
-
if (typeof value.created_at !== "string")
|
|
44
|
-
return undefined;
|
|
45
|
-
if (typeof value.updated_at !== "string")
|
|
46
|
-
return undefined;
|
|
47
|
-
return {
|
|
48
|
-
id: value.id,
|
|
49
|
-
agent_id: value.agent_id,
|
|
50
|
-
pod_id: value.pod_id,
|
|
51
|
-
user_id: value.user_id,
|
|
52
|
-
input_data: isRecord(value.input_data) ? value.input_data : null,
|
|
53
|
-
output_data: isRecord(value.output_data) ? value.output_data : null,
|
|
54
|
-
error: typeof value.error === "string" ? value.error : null,
|
|
55
|
-
status: status,
|
|
56
|
-
created_at: value.created_at,
|
|
57
|
-
updated_at: value.updated_at,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function extractPayload(record) {
|
|
61
|
-
if ("data" in record)
|
|
62
|
-
return record.data;
|
|
63
|
-
if ("payload" in record)
|
|
64
|
-
return record.payload;
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
function extractStatus(payload) {
|
|
68
|
-
if (isRecord(payload)) {
|
|
69
|
-
return normalizeStatus(payload.status)
|
|
70
|
-
?? normalizeStatus(payload.task_status)
|
|
71
|
-
?? (isRecord(payload.task) ? normalizeStatus(payload.task.status) : undefined);
|
|
72
|
-
}
|
|
73
|
-
return normalizeStatus(payload);
|
|
74
|
-
}
|
|
75
|
-
export function parseTaskStreamEvent(value) {
|
|
76
|
-
const directMessage = toTaskMessage(value);
|
|
77
|
-
if (directMessage) {
|
|
78
|
-
return { message: directMessage };
|
|
79
|
-
}
|
|
80
|
-
if (!isRecord(value)) {
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
|
-
const eventType = typeof value.type === "string" ? value.type.toLowerCase() : "";
|
|
84
|
-
const payload = extractPayload(value);
|
|
85
|
-
if (eventType === "message" || eventType === "message_added") {
|
|
86
|
-
const message = toTaskMessage(payload);
|
|
87
|
-
return message ? { message } : {};
|
|
88
|
-
}
|
|
89
|
-
if (eventType === "status"
|
|
90
|
-
|| eventType === "task_status"
|
|
91
|
-
|| eventType === "task"
|
|
92
|
-
|| eventType === "task_updated") {
|
|
93
|
-
const task = toTask(payload) ?? (isRecord(payload) ? toTask(payload.task) : undefined);
|
|
94
|
-
const status = extractStatus(payload);
|
|
95
|
-
if (task || status) {
|
|
96
|
-
return {
|
|
97
|
-
task,
|
|
98
|
-
status: status ?? task?.status,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
export function upsertTaskMessage(messages, incoming) {
|
|
105
|
-
const next = [...messages];
|
|
106
|
-
const index = next.findIndex((message) => message.id === incoming.id);
|
|
107
|
-
if (index >= 0) {
|
|
108
|
-
next[index] = incoming;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
next.push(incoming);
|
|
112
|
-
}
|
|
113
|
-
next.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
|
|
114
|
-
return next;
|
|
115
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/openapi_client/models/{WorkflowInstallListResponse.js → WorkflowRunWaitEntity.js}
RENAMED
|
File without changes
|