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,109 +0,0 @@
|
|
|
1
|
-
import { OpenAPI } from '../core/OpenAPI.js';
|
|
2
|
-
import { request as __request } from '../core/request.js';
|
|
3
|
-
export class TriggersService {
|
|
4
|
-
/**
|
|
5
|
-
* List Triggers
|
|
6
|
-
* List triggers.
|
|
7
|
-
* @param triggerType
|
|
8
|
-
* @param isActive
|
|
9
|
-
* @param podId
|
|
10
|
-
* @param limit
|
|
11
|
-
* @param pageToken
|
|
12
|
-
* @returns TriggerListResponse Successful Response
|
|
13
|
-
* @throws ApiError
|
|
14
|
-
*/
|
|
15
|
-
static triggerList(triggerType, isActive, podId, limit = 100, pageToken) {
|
|
16
|
-
return __request(OpenAPI, {
|
|
17
|
-
method: 'GET',
|
|
18
|
-
url: '/triggers',
|
|
19
|
-
query: {
|
|
20
|
-
'trigger_type': triggerType,
|
|
21
|
-
'is_active': isActive,
|
|
22
|
-
'pod_id': podId,
|
|
23
|
-
'limit': limit,
|
|
24
|
-
'page_token': pageToken,
|
|
25
|
-
},
|
|
26
|
-
errors: {
|
|
27
|
-
422: `Validation Error`,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Create Trigger
|
|
33
|
-
* Create a new trigger.
|
|
34
|
-
* @param requestBody
|
|
35
|
-
* @returns TriggerResponse Successful Response
|
|
36
|
-
* @throws ApiError
|
|
37
|
-
*/
|
|
38
|
-
static triggerCreate(requestBody) {
|
|
39
|
-
return __request(OpenAPI, {
|
|
40
|
-
method: 'POST',
|
|
41
|
-
url: '/triggers',
|
|
42
|
-
body: requestBody,
|
|
43
|
-
mediaType: 'application/json',
|
|
44
|
-
errors: {
|
|
45
|
-
422: `Validation Error`,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Delete Trigger
|
|
51
|
-
* Delete a trigger.
|
|
52
|
-
* @param triggerId
|
|
53
|
-
* @returns void
|
|
54
|
-
* @throws ApiError
|
|
55
|
-
*/
|
|
56
|
-
static triggerDelete(triggerId) {
|
|
57
|
-
return __request(OpenAPI, {
|
|
58
|
-
method: 'DELETE',
|
|
59
|
-
url: '/triggers/{trigger_id}',
|
|
60
|
-
path: {
|
|
61
|
-
'trigger_id': triggerId,
|
|
62
|
-
},
|
|
63
|
-
errors: {
|
|
64
|
-
422: `Validation Error`,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get Trigger
|
|
70
|
-
* Get a trigger by ID.
|
|
71
|
-
* @param triggerId
|
|
72
|
-
* @returns TriggerResponse Successful Response
|
|
73
|
-
* @throws ApiError
|
|
74
|
-
*/
|
|
75
|
-
static triggerGet(triggerId) {
|
|
76
|
-
return __request(OpenAPI, {
|
|
77
|
-
method: 'GET',
|
|
78
|
-
url: '/triggers/{trigger_id}',
|
|
79
|
-
path: {
|
|
80
|
-
'trigger_id': triggerId,
|
|
81
|
-
},
|
|
82
|
-
errors: {
|
|
83
|
-
422: `Validation Error`,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Update Trigger
|
|
89
|
-
* Update a trigger.
|
|
90
|
-
* @param triggerId
|
|
91
|
-
* @param requestBody
|
|
92
|
-
* @returns TriggerResponse Successful Response
|
|
93
|
-
* @throws ApiError
|
|
94
|
-
*/
|
|
95
|
-
static triggerUpdate(triggerId, requestBody) {
|
|
96
|
-
return __request(OpenAPI, {
|
|
97
|
-
method: 'PATCH',
|
|
98
|
-
url: '/triggers/{trigger_id}',
|
|
99
|
-
path: {
|
|
100
|
-
'trigger_id': triggerId,
|
|
101
|
-
},
|
|
102
|
-
body: requestBody,
|
|
103
|
-
mediaType: 'application/json',
|
|
104
|
-
errors: {
|
|
105
|
-
422: `Validation Error`,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Conversation, ConversationMessage, Task } from "../types.js";
|
|
2
|
-
import { type UseAssistantSessionOptions } from "./useAssistantSession.js";
|
|
3
|
-
export interface UseAgentRunOptions extends Omit<UseAssistantSessionOptions, "agentName" | "assistantName" | "assistantId" | "conversationId"> {
|
|
4
|
-
agentName?: string;
|
|
5
|
-
conversationId?: string | null;
|
|
6
|
-
taskId?: string | null;
|
|
7
|
-
autoConnect?: boolean;
|
|
8
|
-
autoConnectOnStart?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface UseAgentRunResult {
|
|
11
|
-
taskId: string | null;
|
|
12
|
-
conversationId: string | null;
|
|
13
|
-
task: Task | null;
|
|
14
|
-
conversation: Conversation | null;
|
|
15
|
-
status?: string;
|
|
16
|
-
messages: ConversationMessage[];
|
|
17
|
-
output: unknown;
|
|
18
|
-
finalOutput: unknown;
|
|
19
|
-
outputText: string;
|
|
20
|
-
finalOutputText: string;
|
|
21
|
-
isStreaming: boolean;
|
|
22
|
-
error: Error | null;
|
|
23
|
-
isWaitingForInput: boolean;
|
|
24
|
-
isFinished: boolean;
|
|
25
|
-
setTaskId: (taskId: string | null) => void;
|
|
26
|
-
setConversationId: (conversationId: string | null) => void;
|
|
27
|
-
start: (inputData?: Record<string, unknown> | null, options?: {
|
|
28
|
-
agentName?: string;
|
|
29
|
-
}) => Promise<Task>;
|
|
30
|
-
submitInput: (content: string) => Promise<Task | null>;
|
|
31
|
-
refreshTask: (taskId?: string | null) => Promise<Task | null>;
|
|
32
|
-
loadMessages: (taskId?: string | null) => Promise<ConversationMessage[]>;
|
|
33
|
-
connect: (taskId?: string | null) => Promise<void>;
|
|
34
|
-
disconnect: () => void;
|
|
35
|
-
stop: () => Promise<Task | null>;
|
|
36
|
-
clearMessages: () => void;
|
|
37
|
-
}
|
|
38
|
-
export declare function useAgentRun({ client, podId, agentName, conversationId, taskId, autoConnect, autoConnectOnStart, autoLoad, autoResume, syncOnTurnEnd, onEvent, onStatus, onMessage, onError, }: UseAgentRunOptions): UseAgentRunResult;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from "react";
|
|
2
|
-
import { extractConversationMessageText, getLatestAssistantMessage, isConversationRunningStatus, normalizeConversationStatus, } from "./assistant-output.js";
|
|
3
|
-
import { useAssistantSession, } from "./useAssistantSession.js";
|
|
4
|
-
function resolveAgentName(base, override) {
|
|
5
|
-
const resolved = override ?? base;
|
|
6
|
-
if (!resolved) {
|
|
7
|
-
throw new Error("agentName is required.");
|
|
8
|
-
}
|
|
9
|
-
return resolved;
|
|
10
|
-
}
|
|
11
|
-
function stringifyAgentInput(inputData) {
|
|
12
|
-
if (!inputData || Object.keys(inputData).length === 0) {
|
|
13
|
-
return "";
|
|
14
|
-
}
|
|
15
|
-
const prompt = inputData.prompt ?? inputData.message ?? inputData.content;
|
|
16
|
-
if (typeof prompt === "string" && prompt.trim().length > 0 && Object.keys(inputData).length === 1) {
|
|
17
|
-
return prompt.trim();
|
|
18
|
-
}
|
|
19
|
-
return JSON.stringify(inputData, null, 2);
|
|
20
|
-
}
|
|
21
|
-
function taskFromConversation(conversation, status, inputData, output) {
|
|
22
|
-
if (!conversation)
|
|
23
|
-
return null;
|
|
24
|
-
return {
|
|
25
|
-
id: conversation.id,
|
|
26
|
-
agent_id: conversation.agent_id,
|
|
27
|
-
pod_id: conversation.pod_id,
|
|
28
|
-
user_id: conversation.user_id,
|
|
29
|
-
input_data: inputData ?? null,
|
|
30
|
-
output_data: output ?? null,
|
|
31
|
-
error: null,
|
|
32
|
-
status: normalizeConversationStatus(status ?? conversation.status) ?? "WAITING",
|
|
33
|
-
created_at: conversation.created_at,
|
|
34
|
-
updated_at: conversation.updated_at,
|
|
35
|
-
conversation,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export function useAgentRun({ client, podId, agentName, conversationId, taskId = null, autoConnect = true, autoConnectOnStart = true, autoLoad, autoResume, syncOnTurnEnd, onEvent, onStatus, onMessage, onError, }) {
|
|
39
|
-
const session = useAssistantSession({
|
|
40
|
-
client,
|
|
41
|
-
podId,
|
|
42
|
-
agentName,
|
|
43
|
-
conversationId: conversationId ?? taskId,
|
|
44
|
-
autoLoad: autoLoad ?? autoConnect,
|
|
45
|
-
autoResume: autoResume ?? autoConnect,
|
|
46
|
-
syncOnTurnEnd,
|
|
47
|
-
onEvent,
|
|
48
|
-
onStatus,
|
|
49
|
-
onMessage,
|
|
50
|
-
onError,
|
|
51
|
-
});
|
|
52
|
-
const start = useCallback(async (inputData, options) => {
|
|
53
|
-
const resolvedAgentName = resolveAgentName(agentName, options?.agentName);
|
|
54
|
-
const content = stringifyAgentInput(inputData);
|
|
55
|
-
const conversation = await session.createConversation({
|
|
56
|
-
agentName: resolvedAgentName,
|
|
57
|
-
title: content ? content.slice(0, 120) : resolvedAgentName,
|
|
58
|
-
setActive: true,
|
|
59
|
-
});
|
|
60
|
-
if (content) {
|
|
61
|
-
await session.sendMessage(content, {
|
|
62
|
-
conversationId: conversation.id,
|
|
63
|
-
createIfMissing: false,
|
|
64
|
-
syncOnTurnEnd,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else if (autoConnectOnStart) {
|
|
68
|
-
await session.resume(conversation.id);
|
|
69
|
-
}
|
|
70
|
-
return taskFromConversation(conversation, session.status, inputData) ?? {
|
|
71
|
-
id: conversation.id,
|
|
72
|
-
agent_id: conversation.agent_id,
|
|
73
|
-
pod_id: conversation.pod_id,
|
|
74
|
-
user_id: conversation.user_id,
|
|
75
|
-
input_data: inputData ?? null,
|
|
76
|
-
output_data: null,
|
|
77
|
-
error: null,
|
|
78
|
-
status: "WAITING",
|
|
79
|
-
created_at: conversation.created_at,
|
|
80
|
-
updated_at: conversation.updated_at,
|
|
81
|
-
conversation,
|
|
82
|
-
};
|
|
83
|
-
}, [agentName, autoConnectOnStart, session, syncOnTurnEnd]);
|
|
84
|
-
const submitInput = useCallback(async (content) => {
|
|
85
|
-
const resolvedConversationId = session.conversationId;
|
|
86
|
-
if (!resolvedConversationId) {
|
|
87
|
-
throw new Error("conversationId is required to submit additional agent input.");
|
|
88
|
-
}
|
|
89
|
-
await session.sendMessage(content, {
|
|
90
|
-
conversationId: resolvedConversationId,
|
|
91
|
-
createIfMissing: false,
|
|
92
|
-
syncOnTurnEnd,
|
|
93
|
-
});
|
|
94
|
-
return taskFromConversation(session.conversation, session.status);
|
|
95
|
-
}, [session, syncOnTurnEnd]);
|
|
96
|
-
const refreshTask = useCallback(async (explicitTaskId) => {
|
|
97
|
-
const conversation = await session.refreshConversation(explicitTaskId);
|
|
98
|
-
return taskFromConversation(conversation, session.status);
|
|
99
|
-
}, [session]);
|
|
100
|
-
const loadMessages = useCallback(async (explicitTaskId) => {
|
|
101
|
-
const response = await session.loadMessages({ conversationId: explicitTaskId });
|
|
102
|
-
return response.items;
|
|
103
|
-
}, [session]);
|
|
104
|
-
const connect = useCallback(async (explicitTaskId) => {
|
|
105
|
-
await session.resume(explicitTaskId);
|
|
106
|
-
}, [session]);
|
|
107
|
-
const stop = useCallback(async () => {
|
|
108
|
-
await session.stop();
|
|
109
|
-
return taskFromConversation(session.conversation, "WAITING");
|
|
110
|
-
}, [session]);
|
|
111
|
-
return useMemo(() => {
|
|
112
|
-
const latestAssistantMessage = getLatestAssistantMessage(session.messages);
|
|
113
|
-
const output = latestAssistantMessage?.content ?? session.output ?? null;
|
|
114
|
-
const outputText = latestAssistantMessage
|
|
115
|
-
? extractConversationMessageText(latestAssistantMessage.content)
|
|
116
|
-
: session.outputText;
|
|
117
|
-
const normalizedStatus = normalizeConversationStatus(session.status);
|
|
118
|
-
const running = isConversationRunningStatus(normalizedStatus) || session.isStreaming;
|
|
119
|
-
const isWaitingForInput = normalizedStatus === "WAITING";
|
|
120
|
-
const isFinished = !!latestAssistantMessage && !running;
|
|
121
|
-
const task = taskFromConversation(session.conversation, session.status, null, output);
|
|
122
|
-
return {
|
|
123
|
-
taskId: session.conversationId,
|
|
124
|
-
conversationId: session.conversationId,
|
|
125
|
-
task,
|
|
126
|
-
conversation: session.conversation,
|
|
127
|
-
status: normalizedStatus,
|
|
128
|
-
messages: session.messages,
|
|
129
|
-
output,
|
|
130
|
-
finalOutput: isFinished ? output : null,
|
|
131
|
-
outputText,
|
|
132
|
-
finalOutputText: isFinished ? outputText : "",
|
|
133
|
-
isStreaming: session.isStreaming,
|
|
134
|
-
error: session.error,
|
|
135
|
-
isWaitingForInput,
|
|
136
|
-
isFinished,
|
|
137
|
-
setTaskId: session.setConversationId,
|
|
138
|
-
setConversationId: session.setConversationId,
|
|
139
|
-
start,
|
|
140
|
-
submitInput,
|
|
141
|
-
refreshTask,
|
|
142
|
-
loadMessages,
|
|
143
|
-
connect,
|
|
144
|
-
disconnect: session.cancel,
|
|
145
|
-
stop,
|
|
146
|
-
clearMessages: session.clearMessages,
|
|
147
|
-
};
|
|
148
|
-
}, [connect, loadMessages, refreshTask, session, start, stop, submitInput]);
|
|
149
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { LemmaClient } from "../client.js";
|
|
2
|
-
import type { Task } from "../types.js";
|
|
3
|
-
export interface UseAgentRunsOptions {
|
|
4
|
-
client: LemmaClient;
|
|
5
|
-
podId?: string;
|
|
6
|
-
agentName?: string;
|
|
7
|
-
enabled?: boolean;
|
|
8
|
-
autoLoad?: boolean;
|
|
9
|
-
limit?: number;
|
|
10
|
-
pageToken?: string;
|
|
11
|
-
initialTaskId?: string | null;
|
|
12
|
-
}
|
|
13
|
-
export interface UseAgentRunsResult {
|
|
14
|
-
runs: Task[];
|
|
15
|
-
total: number;
|
|
16
|
-
nextPageToken: string | null;
|
|
17
|
-
selectedTaskId: string | null;
|
|
18
|
-
effectiveSelectedTaskId: string | null;
|
|
19
|
-
selectedRun: Task | null;
|
|
20
|
-
isLoading: boolean;
|
|
21
|
-
isLoadingMore: boolean;
|
|
22
|
-
error: Error | null;
|
|
23
|
-
selectRun: (taskId: string | null) => void;
|
|
24
|
-
clearSelection: () => void;
|
|
25
|
-
refresh: (overrides?: {
|
|
26
|
-
limit?: number;
|
|
27
|
-
pageToken?: string;
|
|
28
|
-
}) => Promise<Task[]>;
|
|
29
|
-
loadMore: (overrides?: {
|
|
30
|
-
limit?: number;
|
|
31
|
-
}) => Promise<Task[]>;
|
|
32
|
-
}
|
|
33
|
-
export declare function useAgentRuns({ client, podId, agentName, enabled, autoLoad, limit, pageToken, initialTaskId, }: UseAgentRunsOptions): UseAgentRunsResult;
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
-
import { normalizeError, resolvePodClient } from "./utils.js";
|
|
3
|
-
export function useAgentRuns({ client, podId, agentName, enabled = true, autoLoad = true, limit = 100, pageToken, initialTaskId = null, }) {
|
|
4
|
-
const [runs, setRuns] = useState([]);
|
|
5
|
-
const [total, setTotal] = useState(0);
|
|
6
|
-
const [nextPageToken, setNextPageToken] = useState(null);
|
|
7
|
-
const [selectedTaskId, setSelectedTaskId] = useState(initialTaskId);
|
|
8
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
9
|
-
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
10
|
-
const [error, setError] = useState(null);
|
|
11
|
-
const refresh = useCallback(async (overrides = {}, signal) => {
|
|
12
|
-
if (!enabled) {
|
|
13
|
-
setRuns([]);
|
|
14
|
-
setTotal(0);
|
|
15
|
-
setNextPageToken(null);
|
|
16
|
-
setError(null);
|
|
17
|
-
setIsLoading(false);
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
setIsLoading(true);
|
|
21
|
-
setError(null);
|
|
22
|
-
try {
|
|
23
|
-
const scopedClient = resolvePodClient(client, podId);
|
|
24
|
-
const response = await scopedClient.tasks.list({
|
|
25
|
-
agent_name: agentName,
|
|
26
|
-
limit: overrides.limit ?? limit,
|
|
27
|
-
page_token: overrides.pageToken ?? pageToken,
|
|
28
|
-
});
|
|
29
|
-
if (signal?.aborted)
|
|
30
|
-
return [];
|
|
31
|
-
const nextRuns = response.items ?? [];
|
|
32
|
-
setRuns(nextRuns);
|
|
33
|
-
setTotal(response.total ?? nextRuns.length);
|
|
34
|
-
setNextPageToken(response.next_page_token ?? null);
|
|
35
|
-
setSelectedTaskId((current) => (current && nextRuns.some((run) => run.id === current) ? current : initialTaskId));
|
|
36
|
-
return nextRuns;
|
|
37
|
-
}
|
|
38
|
-
catch (refreshError) {
|
|
39
|
-
if (signal?.aborted)
|
|
40
|
-
return [];
|
|
41
|
-
const normalized = normalizeError(refreshError, "Failed to load agent runs.");
|
|
42
|
-
setError(normalized);
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
if (!signal?.aborted)
|
|
47
|
-
setIsLoading(false);
|
|
48
|
-
}
|
|
49
|
-
}, [agentName, client, enabled, initialTaskId, limit, pageToken, podId]);
|
|
50
|
-
const loadMore = useCallback(async (overrides = {}) => {
|
|
51
|
-
if (!enabled || !nextPageToken || isLoading || isLoadingMore) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
setIsLoadingMore(true);
|
|
55
|
-
setError(null);
|
|
56
|
-
try {
|
|
57
|
-
const scopedClient = resolvePodClient(client, podId);
|
|
58
|
-
const response = await scopedClient.tasks.list({
|
|
59
|
-
agent_name: agentName,
|
|
60
|
-
limit: overrides.limit ?? limit,
|
|
61
|
-
page_token: nextPageToken,
|
|
62
|
-
});
|
|
63
|
-
const moreRuns = response.items ?? [];
|
|
64
|
-
setRuns((previous) => [...previous, ...moreRuns]);
|
|
65
|
-
setTotal(response.total ?? runs.length + moreRuns.length);
|
|
66
|
-
setNextPageToken(response.next_page_token ?? null);
|
|
67
|
-
return moreRuns;
|
|
68
|
-
}
|
|
69
|
-
catch (loadError) {
|
|
70
|
-
const normalized = normalizeError(loadError, "Failed to load more agent runs.");
|
|
71
|
-
setError(normalized);
|
|
72
|
-
return [];
|
|
73
|
-
}
|
|
74
|
-
finally {
|
|
75
|
-
setIsLoadingMore(false);
|
|
76
|
-
}
|
|
77
|
-
}, [agentName, client, enabled, isLoading, isLoadingMore, limit, nextPageToken, podId]);
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
setSelectedTaskId(initialTaskId);
|
|
80
|
-
}, [initialTaskId]);
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (!enabled) {
|
|
83
|
-
setRuns([]);
|
|
84
|
-
setTotal(0);
|
|
85
|
-
setNextPageToken(null);
|
|
86
|
-
setError(null);
|
|
87
|
-
setIsLoading(false);
|
|
88
|
-
setIsLoadingMore(false);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (!autoLoad)
|
|
92
|
-
return;
|
|
93
|
-
const controller = new AbortController();
|
|
94
|
-
let cancelled = false;
|
|
95
|
-
(async () => {
|
|
96
|
-
try {
|
|
97
|
-
await refresh({}, controller.signal);
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
if (!cancelled) {
|
|
101
|
-
setError(normalizeError(new Error("Failed to load agent runs."), "Failed to load agent runs."));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})();
|
|
105
|
-
return () => {
|
|
106
|
-
cancelled = true;
|
|
107
|
-
controller.abort();
|
|
108
|
-
};
|
|
109
|
-
}, [autoLoad, enabled, refresh]);
|
|
110
|
-
const selectRun = useCallback((taskId) => {
|
|
111
|
-
setSelectedTaskId(taskId);
|
|
112
|
-
}, []);
|
|
113
|
-
const clearSelection = useCallback(() => {
|
|
114
|
-
setSelectedTaskId(null);
|
|
115
|
-
}, []);
|
|
116
|
-
return useMemo(() => {
|
|
117
|
-
const effectiveSelectedTaskId = selectedTaskId ?? runs[0]?.id ?? null;
|
|
118
|
-
const selectedRun = effectiveSelectedTaskId
|
|
119
|
-
? runs.find((run) => run.id === effectiveSelectedTaskId) ?? null
|
|
120
|
-
: null;
|
|
121
|
-
return {
|
|
122
|
-
runs,
|
|
123
|
-
total,
|
|
124
|
-
nextPageToken,
|
|
125
|
-
selectedTaskId,
|
|
126
|
-
effectiveSelectedTaskId,
|
|
127
|
-
selectedRun,
|
|
128
|
-
isLoading,
|
|
129
|
-
isLoadingMore,
|
|
130
|
-
error,
|
|
131
|
-
selectRun,
|
|
132
|
-
clearSelection,
|
|
133
|
-
refresh,
|
|
134
|
-
loadMore,
|
|
135
|
-
};
|
|
136
|
-
}, [
|
|
137
|
-
clearSelection,
|
|
138
|
-
error,
|
|
139
|
-
isLoading,
|
|
140
|
-
isLoadingMore,
|
|
141
|
-
loadMore,
|
|
142
|
-
nextPageToken,
|
|
143
|
-
refresh,
|
|
144
|
-
runs,
|
|
145
|
-
selectRun,
|
|
146
|
-
selectedTaskId,
|
|
147
|
-
total,
|
|
148
|
-
]);
|
|
149
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { LemmaClient } from "../client.js";
|
|
2
|
-
import type { SseRawEvent } from "../streams.js";
|
|
3
|
-
import type { ConversationMessage } from "../types.js";
|
|
4
|
-
export interface UseAssistantRunOptions {
|
|
5
|
-
client: LemmaClient;
|
|
6
|
-
podId?: string;
|
|
7
|
-
conversationId?: string | null;
|
|
8
|
-
onEvent?: (event: SseRawEvent, payload: unknown | null) => void;
|
|
9
|
-
onError?: (error: unknown) => void;
|
|
10
|
-
}
|
|
11
|
-
export interface UseAssistantRunResult {
|
|
12
|
-
isStreaming: boolean;
|
|
13
|
-
error: Error | null;
|
|
14
|
-
status?: string;
|
|
15
|
-
messages: ConversationMessage[];
|
|
16
|
-
output: ConversationMessage["content"] | null;
|
|
17
|
-
outputText: string;
|
|
18
|
-
finalOutput: ConversationMessage["content"] | null;
|
|
19
|
-
finalOutputText: string;
|
|
20
|
-
latestAssistantMessage: ConversationMessage | null;
|
|
21
|
-
refresh: () => Promise<ConversationMessage[]>;
|
|
22
|
-
sendMessage: (content: string) => Promise<void>;
|
|
23
|
-
resume: () => Promise<void>;
|
|
24
|
-
stop: () => Promise<void>;
|
|
25
|
-
cancel: () => void;
|
|
26
|
-
}
|
|
27
|
-
export declare function useAssistantRun({ client, podId, conversationId, onEvent, onError, }: UseAssistantRunOptions): UseAssistantRunResult;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from "react";
|
|
2
|
-
import { useConversationMessages } from "./useConversationMessages.js";
|
|
3
|
-
function requireConversationId(conversationId) {
|
|
4
|
-
if (!conversationId) {
|
|
5
|
-
throw new Error("conversationId is required.");
|
|
6
|
-
}
|
|
7
|
-
return conversationId;
|
|
8
|
-
}
|
|
9
|
-
export function useAssistantRun({ client, podId, conversationId, onEvent, onError, }) {
|
|
10
|
-
const messages = useConversationMessages({
|
|
11
|
-
client,
|
|
12
|
-
podId,
|
|
13
|
-
conversationId,
|
|
14
|
-
autoLoad: true,
|
|
15
|
-
autoResume: false,
|
|
16
|
-
onEvent,
|
|
17
|
-
onError,
|
|
18
|
-
});
|
|
19
|
-
const sendMessage = useCallback(async (content) => {
|
|
20
|
-
await messages.sendMessage(content, {
|
|
21
|
-
conversationId: requireConversationId(conversationId ?? messages.conversationId),
|
|
22
|
-
createIfMissing: false,
|
|
23
|
-
});
|
|
24
|
-
}, [conversationId, messages]);
|
|
25
|
-
const resume = useCallback(async () => {
|
|
26
|
-
await messages.resume(requireConversationId(conversationId ?? messages.conversationId));
|
|
27
|
-
}, [conversationId, messages]);
|
|
28
|
-
const stop = useCallback(async () => {
|
|
29
|
-
await messages.stop(requireConversationId(conversationId ?? messages.conversationId));
|
|
30
|
-
}, [conversationId, messages]);
|
|
31
|
-
return useMemo(() => ({
|
|
32
|
-
isStreaming: messages.isStreaming,
|
|
33
|
-
error: messages.error,
|
|
34
|
-
status: messages.status,
|
|
35
|
-
messages: messages.messages,
|
|
36
|
-
output: messages.output,
|
|
37
|
-
outputText: messages.outputText,
|
|
38
|
-
finalOutput: messages.finalOutput,
|
|
39
|
-
finalOutputText: messages.finalOutputText,
|
|
40
|
-
latestAssistantMessage: messages.latestAssistantMessage,
|
|
41
|
-
refresh: messages.refresh,
|
|
42
|
-
sendMessage,
|
|
43
|
-
resume,
|
|
44
|
-
stop,
|
|
45
|
-
cancel: messages.cancel,
|
|
46
|
-
}), [messages, sendMessage, resume, stop]);
|
|
47
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { LemmaClient } from "../client.js";
|
|
2
|
-
import { type SseRawEvent } from "../streams.js";
|
|
3
|
-
import type { Task, TaskMessage } from "../types.js";
|
|
4
|
-
export interface CreateTaskInput {
|
|
5
|
-
agentName: string;
|
|
6
|
-
inputData?: Record<string, unknown> | null;
|
|
7
|
-
}
|
|
8
|
-
export interface UseTaskSessionOptions {
|
|
9
|
-
client: LemmaClient;
|
|
10
|
-
podId?: string;
|
|
11
|
-
taskId?: string | null;
|
|
12
|
-
autoConnect?: boolean;
|
|
13
|
-
autoConnectOnStart?: boolean;
|
|
14
|
-
onEvent?: (event: SseRawEvent, payload: unknown | null) => void;
|
|
15
|
-
onStatus?: (status: string) => void;
|
|
16
|
-
onMessage?: (message: TaskMessage) => void;
|
|
17
|
-
onError?: (error: unknown) => void;
|
|
18
|
-
}
|
|
19
|
-
export interface UseTaskSessionResult {
|
|
20
|
-
taskId: string | null;
|
|
21
|
-
task: Task | null;
|
|
22
|
-
status?: string;
|
|
23
|
-
messages: TaskMessage[];
|
|
24
|
-
isStreaming: boolean;
|
|
25
|
-
error: Error | null;
|
|
26
|
-
setTaskId: (taskId: string | null) => void;
|
|
27
|
-
start: (input: CreateTaskInput) => Promise<Task>;
|
|
28
|
-
refreshTask: (taskId?: string | null) => Promise<Task | null>;
|
|
29
|
-
loadMessages: (taskId?: string | null) => Promise<TaskMessage[]>;
|
|
30
|
-
connect: (taskId?: string | null) => Promise<void>;
|
|
31
|
-
disconnect: () => void;
|
|
32
|
-
stop: () => Promise<Task | null>;
|
|
33
|
-
clearMessages: () => void;
|
|
34
|
-
}
|
|
35
|
-
export declare function useTaskSession({ client, podId, taskId: externalTaskId, autoConnect, autoConnectOnStart, onEvent, onStatus, onMessage, onError, }: UseTaskSessionOptions): UseTaskSessionResult;
|