lemma-sdk 0.2.3 → 0.2.5

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.
Files changed (75) hide show
  1. package/README.md +88 -0
  2. package/dist/assistant-events.d.ts +7 -0
  3. package/dist/assistant-events.js +78 -0
  4. package/dist/auth.d.ts +56 -5
  5. package/dist/auth.js +247 -30
  6. package/dist/browser/lemma-client.js +283 -53
  7. package/dist/browser.d.ts +1 -1
  8. package/dist/browser.js +1 -1
  9. package/dist/client.d.ts +4 -1
  10. package/dist/client.js +3 -3
  11. package/dist/index.d.ts +8 -2
  12. package/dist/index.js +4 -1
  13. package/dist/namespaces/desks.d.ts +2 -2
  14. package/dist/namespaces/desks.js +7 -7
  15. package/dist/namespaces/icons.js +4 -1
  16. package/dist/openapi_client/index.d.ts +10 -7
  17. package/dist/openapi_client/models/{AgentNode.d.ts → AgentNode_Input.d.ts} +1 -1
  18. package/dist/openapi_client/models/AgentNode_Output.d.ts +11 -0
  19. package/dist/openapi_client/models/AppDescriptorResponse.d.ts +2 -2
  20. package/dist/openapi_client/models/Body_upload_file_files__resource_type___resource_id__upload_post.d.ts +1 -1
  21. package/dist/openapi_client/models/{Body_file_upload.d.ts → DatastoreFileUploadRequest.d.ts} +2 -2
  22. package/dist/openapi_client/models/{DecisionNode.d.ts → DecisionNode_Input.d.ts} +1 -1
  23. package/dist/openapi_client/models/DecisionNode_Output.d.ts +11 -0
  24. package/dist/openapi_client/models/DeskBundleUploadRequest.d.ts +4 -0
  25. package/dist/openapi_client/models/FlowEntity.d.ts +4 -4
  26. package/dist/openapi_client/models/{FunctionNode.d.ts → FunctionNode_Input.d.ts} +1 -1
  27. package/dist/openapi_client/models/FunctionNode_Output.d.ts +11 -0
  28. package/dist/openapi_client/models/FunctionNode_Output.js +1 -0
  29. package/dist/openapi_client/models/IconUploadRequest.d.ts +3 -0
  30. package/dist/openapi_client/models/IconUploadRequest.js +1 -0
  31. package/dist/openapi_client/models/ValidationError.d.ts +2 -0
  32. package/dist/openapi_client/models/WorkflowGraphUpdateRequest.d.ts +4 -4
  33. package/dist/openapi_client/models/{Body_file_update.d.ts → update.d.ts} +2 -2
  34. package/dist/openapi_client/models/update.js +1 -0
  35. package/dist/openapi_client/services/ApplicationsService.d.ts +2 -2
  36. package/dist/openapi_client/services/ApplicationsService.js +3 -3
  37. package/dist/openapi_client/services/DesksService.d.ts +9 -9
  38. package/dist/openapi_client/services/DesksService.js +8 -8
  39. package/dist/openapi_client/services/FilesService.d.ts +4 -4
  40. package/dist/openapi_client/services/IconsService.d.ts +2 -2
  41. package/dist/openapi_client/services/PublicSdkService.d.ts +1 -1
  42. package/dist/openapi_client/services/PublicSdkService.js +1 -1
  43. package/dist/react/index.d.ts +12 -0
  44. package/dist/react/index.js +6 -0
  45. package/dist/react/useAssistantRun.d.ts +1 -1
  46. package/dist/react/useAssistantRun.js +23 -69
  47. package/dist/react/useAssistantRuntime.d.ts +13 -0
  48. package/dist/react/useAssistantRuntime.js +108 -0
  49. package/dist/react/useAssistantSession.d.ts +61 -0
  50. package/dist/react/useAssistantSession.js +278 -0
  51. package/dist/react/useAuth.d.ts +6 -2
  52. package/dist/react/useAuth.js +1 -1
  53. package/dist/react/useFlowRunHistory.d.ts +19 -0
  54. package/dist/react/useFlowRunHistory.js +77 -0
  55. package/dist/react/useFlowSession.d.ts +39 -0
  56. package/dist/react/useFlowSession.js +195 -0
  57. package/dist/react/useFunctionSession.d.ts +32 -0
  58. package/dist/react/useFunctionSession.js +147 -0
  59. package/dist/react/useTaskSession.d.ts +35 -0
  60. package/dist/react/useTaskSession.js +207 -0
  61. package/dist/run-utils.d.ts +18 -0
  62. package/dist/run-utils.js +62 -0
  63. package/dist/task-events.d.ts +7 -0
  64. package/dist/task-events.js +78 -0
  65. package/dist/types.d.ts +3 -1
  66. package/package.json +1 -1
  67. package/dist/openapi_client/models/Body_icon_upload.d.ts +0 -3
  68. package/dist/openapi_client/models/Body_pod_desk_bundle_upload.d.ts +0 -4
  69. /package/dist/openapi_client/models/{AgentNode.js → AgentNode_Input.js} +0 -0
  70. /package/dist/openapi_client/models/{Body_file_update.js → AgentNode_Output.js} +0 -0
  71. /package/dist/openapi_client/models/{Body_file_upload.js → DatastoreFileUploadRequest.js} +0 -0
  72. /package/dist/openapi_client/models/{Body_icon_upload.js → DecisionNode_Input.js} +0 -0
  73. /package/dist/openapi_client/models/{Body_pod_desk_bundle_upload.js → DecisionNode_Output.js} +0 -0
  74. /package/dist/openapi_client/models/{DecisionNode.js → DeskBundleUploadRequest.js} +0 -0
  75. /package/dist/openapi_client/models/{FunctionNode.js → FunctionNode_Input.js} +0 -0
@@ -0,0 +1,77 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ function normalizeError(error, fallback) {
3
+ if (error instanceof Error)
4
+ return error;
5
+ return new Error(fallback);
6
+ }
7
+ export function useFlowRunHistory({ session, flowName, limit = 100, autoRefresh = true, }) {
8
+ const { listHistory, run: liveRun, runId: liveRunId, setRunId } = session;
9
+ const [runs, setRuns] = useState([]);
10
+ const [selectedRunId, setSelectedRunId] = useState(null);
11
+ const [isLoading, setIsLoading] = useState(false);
12
+ const [error, setError] = useState(null);
13
+ const effectiveSelectedRunId = selectedRunId ?? runs[0]?.id ?? null;
14
+ const refresh = useCallback(async () => {
15
+ setIsLoading(true);
16
+ setError(null);
17
+ try {
18
+ const nextRuns = await listHistory({ flowName, limit });
19
+ setRuns(nextRuns);
20
+ setSelectedRunId((previous) => (previous && nextRuns.some((run) => run.id === previous) ? previous : null));
21
+ return nextRuns;
22
+ }
23
+ catch (refreshError) {
24
+ const normalized = normalizeError(refreshError, "Failed to list flow runs.");
25
+ setError(normalized);
26
+ return [];
27
+ }
28
+ finally {
29
+ setIsLoading(false);
30
+ }
31
+ }, [flowName, limit, listHistory]);
32
+ useEffect(() => {
33
+ if (!autoRefresh)
34
+ return;
35
+ void refresh();
36
+ }, [autoRefresh, flowName, refresh]);
37
+ useEffect(() => {
38
+ if (!autoRefresh || !liveRunId)
39
+ return;
40
+ void refresh();
41
+ }, [autoRefresh, liveRunId, refresh]);
42
+ useEffect(() => {
43
+ if (!effectiveSelectedRunId)
44
+ return;
45
+ setRunId(effectiveSelectedRunId);
46
+ }, [effectiveSelectedRunId, setRunId]);
47
+ useEffect(() => {
48
+ if (!liveRun?.id)
49
+ return;
50
+ setRuns((previous) => {
51
+ const index = previous.findIndex((run) => run.id === liveRun.id);
52
+ if (index === -1) {
53
+ return [liveRun, ...previous];
54
+ }
55
+ const next = [...previous];
56
+ next[index] = { ...next[index], ...liveRun };
57
+ return next;
58
+ });
59
+ }, [liveRun]);
60
+ const selectedRun = useMemo(() => {
61
+ if (!effectiveSelectedRunId)
62
+ return null;
63
+ if (liveRun?.id === effectiveSelectedRunId)
64
+ return liveRun;
65
+ return runs.find((run) => run.id === effectiveSelectedRunId) ?? null;
66
+ }, [effectiveSelectedRunId, liveRun, runs]);
67
+ return {
68
+ runs,
69
+ selectedRunId,
70
+ effectiveSelectedRunId,
71
+ selectedRun,
72
+ isLoading,
73
+ error,
74
+ setSelectedRunId,
75
+ refresh,
76
+ };
77
+ }
@@ -0,0 +1,39 @@
1
+ import type { LemmaClient } from "../client.js";
2
+ import type { FlowRun, WorkflowRunInputs } from "../types.js";
3
+ export interface UseFlowSessionOptions {
4
+ client: LemmaClient;
5
+ podId?: string;
6
+ flowName?: string;
7
+ runId?: string | null;
8
+ autoPoll?: boolean;
9
+ pollIntervalMs?: number;
10
+ onRun?: (run: FlowRun) => void;
11
+ onError?: (error: unknown) => void;
12
+ }
13
+ export interface UseFlowSessionResult {
14
+ runId: string | null;
15
+ run: FlowRun | null;
16
+ status?: string;
17
+ isPolling: boolean;
18
+ error: Error | null;
19
+ setRunId: (runId: string | null) => void;
20
+ start: (options?: {
21
+ flowName?: string;
22
+ inputs?: WorkflowRunInputs;
23
+ connect?: boolean;
24
+ }) => Promise<FlowRun>;
25
+ resume: (options: {
26
+ runId?: string | null;
27
+ inputs?: WorkflowRunInputs;
28
+ connect?: boolean;
29
+ }) => Promise<FlowRun>;
30
+ refresh: (runId?: string | null) => Promise<FlowRun | null>;
31
+ listHistory: (options?: {
32
+ flowName?: string;
33
+ limit?: number;
34
+ pageToken?: string;
35
+ }) => Promise<FlowRun[]>;
36
+ cancel: (runId?: string | null) => Promise<void>;
37
+ retry: (runId?: string | null) => Promise<void>;
38
+ }
39
+ export declare function useFlowSession({ client, podId, flowName, runId: initialRunId, autoPoll, pollIntervalMs, onRun, onError, }: UseFlowSessionOptions): UseFlowSessionResult;
@@ -0,0 +1,195 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { isTerminalFlowStatus, normalizeRunStatus, sleep } from "../run-utils.js";
3
+ function resolvePodId(client, podId) {
4
+ const resolved = podId ?? client.podId;
5
+ if (!resolved) {
6
+ throw new Error("podId is required. Pass podId or set it on LemmaClient.");
7
+ }
8
+ return resolved;
9
+ }
10
+ function resolveFlowName(base, override) {
11
+ const resolved = override ?? base;
12
+ if (!resolved) {
13
+ throw new Error("flowName is required.");
14
+ }
15
+ return resolved;
16
+ }
17
+ function resolveRunId(base, override) {
18
+ const resolved = override ?? base;
19
+ if (!resolved) {
20
+ throw new Error("runId is required.");
21
+ }
22
+ return resolved;
23
+ }
24
+ function normalizeError(error, fallback) {
25
+ if (error instanceof Error)
26
+ return error;
27
+ return new Error(fallback);
28
+ }
29
+ export function useFlowSession({ client, podId, flowName, runId: initialRunId = null, autoPoll = true, pollIntervalMs = 2000, onRun, onError, }) {
30
+ const [runId, setRunIdState] = useState(initialRunId);
31
+ const [run, setRun] = useState(null);
32
+ const [status, setStatus] = useState(undefined);
33
+ const [isPolling, setIsPolling] = useState(false);
34
+ const [error, setError] = useState(null);
35
+ const setRunId = useCallback((nextRunId) => {
36
+ setRunIdState(nextRunId);
37
+ if (!nextRunId) {
38
+ setRun(null);
39
+ setStatus(undefined);
40
+ }
41
+ }, []);
42
+ const refresh = useCallback(async (explicitRunId) => {
43
+ const id = explicitRunId ?? runId;
44
+ if (!id)
45
+ return null;
46
+ try {
47
+ const resolvedPodId = resolvePodId(client, podId);
48
+ const nextRun = await client.workflows.runs.get(id, resolvedPodId);
49
+ setRun(nextRun);
50
+ const nextStatus = normalizeRunStatus(nextRun.status);
51
+ setStatus(nextStatus);
52
+ onRun?.(nextRun);
53
+ return nextRun;
54
+ }
55
+ catch (refreshError) {
56
+ const normalized = normalizeError(refreshError, "Failed to fetch flow run.");
57
+ setError(normalized);
58
+ onError?.(refreshError);
59
+ return null;
60
+ }
61
+ }, [client, onError, onRun, podId, runId]);
62
+ const listHistory = useCallback(async (options = {}) => {
63
+ try {
64
+ client.setPodId(resolvePodId(client, podId));
65
+ const name = resolveFlowName(flowName, options.flowName);
66
+ const response = await client.workflows.runs.list(name, {
67
+ limit: options.limit,
68
+ pageToken: options.pageToken,
69
+ });
70
+ return response.items ?? [];
71
+ }
72
+ catch (listError) {
73
+ const normalized = normalizeError(listError, "Failed to list flow runs.");
74
+ setError(normalized);
75
+ onError?.(listError);
76
+ return [];
77
+ }
78
+ }, [client, flowName, onError, podId]);
79
+ const start = useCallback(async (options = {}) => {
80
+ setError(null);
81
+ client.setPodId(resolvePodId(client, podId));
82
+ const name = resolveFlowName(flowName, options.flowName);
83
+ const created = await client.workflows.runs.start(name, options.inputs);
84
+ setRun(created);
85
+ setRunIdState(created.id ?? null);
86
+ const nextStatus = normalizeRunStatus(created.status);
87
+ setStatus(nextStatus);
88
+ onRun?.(created);
89
+ if (options.connect !== false && created.id) {
90
+ await refresh(created.id);
91
+ }
92
+ return created;
93
+ }, [client, flowName, onRun, podId, refresh]);
94
+ const resume = useCallback(async (options) => {
95
+ setError(null);
96
+ const resolvedPodId = resolvePodId(client, podId);
97
+ const id = resolveRunId(runId, options.runId);
98
+ const resumed = await client.workflows.runs.resume(id, options.inputs, resolvedPodId);
99
+ setRun(resumed);
100
+ setRunIdState(resumed.id ?? id);
101
+ const nextStatus = normalizeRunStatus(resumed.status);
102
+ setStatus(nextStatus);
103
+ onRun?.(resumed);
104
+ if (options.connect !== false) {
105
+ await refresh(resumed.id ?? id);
106
+ }
107
+ return resumed;
108
+ }, [client, onRun, podId, refresh, runId]);
109
+ const cancel = useCallback(async (explicitRunId) => {
110
+ try {
111
+ const resolvedPodId = resolvePodId(client, podId);
112
+ const id = resolveRunId(runId, explicitRunId);
113
+ await client.workflows.runs.cancel(id, resolvedPodId);
114
+ await refresh(id);
115
+ }
116
+ catch (cancelError) {
117
+ const normalized = normalizeError(cancelError, "Failed to cancel flow run.");
118
+ setError(normalized);
119
+ onError?.(cancelError);
120
+ }
121
+ }, [client, onError, podId, refresh, runId]);
122
+ const retry = useCallback(async (explicitRunId) => {
123
+ try {
124
+ const resolvedPodId = resolvePodId(client, podId);
125
+ const id = resolveRunId(runId, explicitRunId);
126
+ await client.workflows.runs.retry(id, resolvedPodId);
127
+ await refresh(id);
128
+ }
129
+ catch (retryError) {
130
+ const normalized = normalizeError(retryError, "Failed to retry flow run.");
131
+ setError(normalized);
132
+ onError?.(retryError);
133
+ }
134
+ }, [client, onError, podId, refresh, runId]);
135
+ useEffect(() => {
136
+ if (!runId) {
137
+ return;
138
+ }
139
+ void refresh(runId);
140
+ }, [refresh, runId]);
141
+ useEffect(() => {
142
+ if (!autoPoll || !runId) {
143
+ return;
144
+ }
145
+ let active = true;
146
+ const abortController = new AbortController();
147
+ const loop = async () => {
148
+ setIsPolling(true);
149
+ while (active) {
150
+ const latest = await refresh(runId);
151
+ if (!latest) {
152
+ break;
153
+ }
154
+ const latestStatus = normalizeRunStatus(latest?.status);
155
+ if (latestStatus && isTerminalFlowStatus(latestStatus)) {
156
+ break;
157
+ }
158
+ try {
159
+ await sleep(pollIntervalMs, abortController.signal);
160
+ }
161
+ catch (sleepError) {
162
+ if (sleepError instanceof Error && sleepError.name === "AbortError") {
163
+ break;
164
+ }
165
+ throw sleepError;
166
+ }
167
+ }
168
+ setIsPolling(false);
169
+ };
170
+ void loop().catch((pollError) => {
171
+ const normalized = normalizeError(pollError, "Failed while polling flow run.");
172
+ setError(normalized);
173
+ onError?.(pollError);
174
+ setIsPolling(false);
175
+ });
176
+ return () => {
177
+ active = false;
178
+ abortController.abort();
179
+ };
180
+ }, [autoPoll, onError, pollIntervalMs, refresh, runId]);
181
+ return {
182
+ runId,
183
+ run,
184
+ status,
185
+ isPolling,
186
+ error,
187
+ setRunId,
188
+ start,
189
+ resume,
190
+ refresh,
191
+ listHistory,
192
+ cancel,
193
+ retry,
194
+ };
195
+ }
@@ -0,0 +1,32 @@
1
+ import type { LemmaClient } from "../client.js";
2
+ import type { FunctionRun } from "../types.js";
3
+ export interface UseFunctionSessionOptions {
4
+ client: LemmaClient;
5
+ podId?: string;
6
+ functionName?: string;
7
+ runId?: string | null;
8
+ autoPoll?: boolean;
9
+ pollIntervalMs?: number;
10
+ onRun?: (run: FunctionRun) => void;
11
+ onError?: (error: unknown) => void;
12
+ }
13
+ export interface UseFunctionSessionResult {
14
+ runId: string | null;
15
+ run: FunctionRun | null;
16
+ status?: string;
17
+ isPolling: boolean;
18
+ error: Error | null;
19
+ setRunId: (runId: string | null) => void;
20
+ start: (options?: {
21
+ functionName?: string;
22
+ input?: Record<string, unknown>;
23
+ connect?: boolean;
24
+ }) => Promise<FunctionRun>;
25
+ refresh: (runId?: string | null) => Promise<FunctionRun | null>;
26
+ listHistory: (options?: {
27
+ functionName?: string;
28
+ limit?: number;
29
+ pageToken?: string;
30
+ }) => Promise<FunctionRun[]>;
31
+ }
32
+ export declare function useFunctionSession({ client, podId, functionName, runId: initialRunId, autoPoll, pollIntervalMs, onRun, onError, }: UseFunctionSessionOptions): UseFunctionSessionResult;
@@ -0,0 +1,147 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { isTerminalFunctionStatus, normalizeRunStatus, sleep } from "../run-utils.js";
3
+ function resolvePodId(client, podId) {
4
+ const resolved = podId ?? client.podId;
5
+ if (!resolved) {
6
+ throw new Error("podId is required. Pass podId or set it on LemmaClient.");
7
+ }
8
+ return resolved;
9
+ }
10
+ function resolveFunctionName(base, override) {
11
+ const resolved = override ?? base;
12
+ if (!resolved) {
13
+ throw new Error("functionName is required.");
14
+ }
15
+ return resolved;
16
+ }
17
+ function normalizeError(error, fallback) {
18
+ if (error instanceof Error)
19
+ return error;
20
+ return new Error(fallback);
21
+ }
22
+ export function useFunctionSession({ client, podId, functionName, runId: initialRunId = null, autoPoll = true, pollIntervalMs = 2000, onRun, onError, }) {
23
+ const [runId, setRunIdState] = useState(initialRunId);
24
+ const [run, setRun] = useState(null);
25
+ const [status, setStatus] = useState(undefined);
26
+ const [isPolling, setIsPolling] = useState(false);
27
+ const [error, setError] = useState(null);
28
+ const setRunId = useCallback((nextRunId) => {
29
+ setRunIdState(nextRunId);
30
+ if (!nextRunId) {
31
+ setRun(null);
32
+ setStatus(undefined);
33
+ }
34
+ }, []);
35
+ const refresh = useCallback(async (explicitRunId) => {
36
+ const id = explicitRunId ?? runId;
37
+ if (!id)
38
+ return null;
39
+ try {
40
+ client.setPodId(resolvePodId(client, podId));
41
+ const name = resolveFunctionName(functionName);
42
+ const nextRun = await client.functions.runs.get(name, id);
43
+ setRun(nextRun);
44
+ const nextStatus = normalizeRunStatus(nextRun.status);
45
+ setStatus(nextStatus);
46
+ onRun?.(nextRun);
47
+ return nextRun;
48
+ }
49
+ catch (refreshError) {
50
+ const normalized = normalizeError(refreshError, "Failed to fetch function run.");
51
+ setError(normalized);
52
+ onError?.(refreshError);
53
+ return null;
54
+ }
55
+ }, [client, functionName, onError, onRun, podId, runId]);
56
+ const listHistory = useCallback(async (options = {}) => {
57
+ try {
58
+ client.setPodId(resolvePodId(client, podId));
59
+ const name = resolveFunctionName(functionName, options.functionName);
60
+ const response = await client.functions.runs.list(name, {
61
+ limit: options.limit,
62
+ pageToken: options.pageToken,
63
+ });
64
+ return response.items ?? [];
65
+ }
66
+ catch (listError) {
67
+ const normalized = normalizeError(listError, "Failed to list function runs.");
68
+ setError(normalized);
69
+ onError?.(listError);
70
+ return [];
71
+ }
72
+ }, [client, functionName, onError, podId]);
73
+ const start = useCallback(async (options = {}) => {
74
+ setError(null);
75
+ client.setPodId(resolvePodId(client, podId));
76
+ const name = resolveFunctionName(functionName, options.functionName);
77
+ const created = await client.functions.runs.create(name, {
78
+ input: options.input,
79
+ });
80
+ setRun(created);
81
+ setRunIdState(created.id);
82
+ const nextStatus = normalizeRunStatus(created.status);
83
+ setStatus(nextStatus);
84
+ onRun?.(created);
85
+ if (options.connect !== false) {
86
+ await refresh(created.id);
87
+ }
88
+ return created;
89
+ }, [client, functionName, onRun, podId, refresh]);
90
+ useEffect(() => {
91
+ if (!runId) {
92
+ return;
93
+ }
94
+ void refresh(runId);
95
+ }, [refresh, runId]);
96
+ useEffect(() => {
97
+ if (!autoPoll || !runId) {
98
+ return;
99
+ }
100
+ let active = true;
101
+ const abortController = new AbortController();
102
+ const loop = async () => {
103
+ setIsPolling(true);
104
+ while (active) {
105
+ const latest = await refresh(runId);
106
+ if (!latest) {
107
+ break;
108
+ }
109
+ const latestStatus = normalizeRunStatus(latest?.status);
110
+ if (latestStatus && isTerminalFunctionStatus(latestStatus)) {
111
+ break;
112
+ }
113
+ try {
114
+ await sleep(pollIntervalMs, abortController.signal);
115
+ }
116
+ catch (sleepError) {
117
+ if (sleepError instanceof Error && sleepError.name === "AbortError") {
118
+ break;
119
+ }
120
+ throw sleepError;
121
+ }
122
+ }
123
+ setIsPolling(false);
124
+ };
125
+ void loop().catch((pollError) => {
126
+ const normalized = normalizeError(pollError, "Failed while polling function run.");
127
+ setError(normalized);
128
+ onError?.(pollError);
129
+ setIsPolling(false);
130
+ });
131
+ return () => {
132
+ active = false;
133
+ abortController.abort();
134
+ };
135
+ }, [autoPoll, onError, pollIntervalMs, refresh, runId]);
136
+ return {
137
+ runId,
138
+ run,
139
+ status,
140
+ isPolling,
141
+ error,
142
+ setRunId,
143
+ start,
144
+ refresh,
145
+ listHistory,
146
+ };
147
+ }
@@ -0,0 +1,35 @@
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;