lemma-sdk 0.2.30 → 0.2.31

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 (64) hide show
  1. package/README.md +211 -51
  2. package/dist/react/index.d.ts +20 -0
  3. package/dist/react/index.js +10 -0
  4. package/dist/react/useAgentInputSchema.d.ts +19 -0
  5. package/dist/react/useAgentInputSchema.js +73 -0
  6. package/dist/react/useAgentRun.js +18 -20
  7. package/dist/react/useAgentRuns.d.ts +33 -0
  8. package/dist/react/useAgentRuns.js +149 -0
  9. package/dist/react/useAssistantRun.js +10 -9
  10. package/dist/react/useAssistantSession.js +21 -25
  11. package/dist/react/useBulkRecords.js +9 -16
  12. package/dist/react/useConversation.js +24 -8
  13. package/dist/react/useConversations.d.ts +4 -0
  14. package/dist/react/useConversations.js +49 -3
  15. package/dist/react/useCreateRecord.js +9 -16
  16. package/dist/react/useCurrentUser.d.ts +14 -0
  17. package/dist/react/useCurrentUser.js +68 -0
  18. package/dist/react/useDeleteRecord.js +9 -16
  19. package/dist/react/useFlowRunHistory.js +1 -5
  20. package/dist/react/useFlowSession.js +41 -33
  21. package/dist/react/useForeignKeyOptions.js +26 -15
  22. package/dist/react/useFunctionRun.d.ts +19 -0
  23. package/dist/react/useFunctionRun.js +30 -0
  24. package/dist/react/useFunctionRuns.d.ts +33 -0
  25. package/dist/react/useFunctionRuns.js +149 -0
  26. package/dist/react/useFunctionSession.js +37 -29
  27. package/dist/react/useJoinedRecords.js +24 -23
  28. package/dist/react/useMembers.d.ts +4 -0
  29. package/dist/react/useMembers.js +55 -16
  30. package/dist/react/useOrganizationMembers.d.ts +26 -0
  31. package/dist/react/useOrganizationMembers.js +113 -0
  32. package/dist/react/usePodAccess.d.ts +22 -0
  33. package/dist/react/usePodAccess.js +128 -0
  34. package/dist/react/useRecord.js +24 -13
  35. package/dist/react/useRecordForm.js +1 -18
  36. package/dist/react/useRecords.d.ts +2 -0
  37. package/dist/react/useRecords.js +62 -22
  38. package/dist/react/useRelatedRecords.js +28 -21
  39. package/dist/react/useReverseRelatedRecords.js +30 -21
  40. package/dist/react/useSchemaForm.js +1 -13
  41. package/dist/react/useTable.js +24 -13
  42. package/dist/react/useTables.d.ts +4 -0
  43. package/dist/react/useTables.js +57 -15
  44. package/dist/react/useTaskSession.js +11 -22
  45. package/dist/react/useUpdateRecord.js +9 -16
  46. package/dist/react/useWorkflowResume.d.ts +18 -0
  47. package/dist/react/useWorkflowResume.js +45 -0
  48. package/dist/react/useWorkflowRun.d.ts +21 -0
  49. package/dist/react/useWorkflowRun.js +49 -0
  50. package/dist/react/useWorkflowRuns.d.ts +33 -0
  51. package/dist/react/useWorkflowRuns.js +149 -0
  52. package/dist/react/useWorkflowStart.js +20 -27
  53. package/dist/react/utils.d.ts +5 -0
  54. package/dist/react/utils.js +25 -0
  55. package/dist/types.d.ts +1 -0
  56. package/package.json +2 -4
  57. package/dist/react/components/AssistantChrome.d.ts +0 -86
  58. package/dist/react/components/AssistantChrome.js +0 -48
  59. package/dist/react/components/AssistantEmbedded.d.ts +0 -10
  60. package/dist/react/components/AssistantEmbedded.js +0 -15
  61. package/dist/react/components/AssistantExperience.d.ts +0 -96
  62. package/dist/react/components/AssistantExperience.js +0 -1294
  63. package/dist/react/components/assistant-types.d.ts +0 -80
  64. package/dist/react/components/assistant-types.js +0 -1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Lemma TypeScript SDK
2
2
 
3
- `lemma-sdk` is the headless TypeScript SDK for Lemma. Use `lemma-sdk/react` for hooks and auth primitives, and use the Lemma shadcn registry for stock UI blocks.
3
+ `lemma-sdk` is the headless TypeScript SDK for Lemma. Use `lemma-sdk` for the core client, `lemma-sdk/react` for hooks and auth primitives, and the Lemma shadcn registry for stock UI blocks.
4
+
5
+ `AuthGuard` intentionally stays in `lemma-sdk/react`. Stock assistant, table, workflow, agent, member, and function UI lives in the registry.
4
6
 
5
7
  ## Install
6
8
 
@@ -26,15 +28,34 @@ That adds this namespace to your app's `components.json`:
26
28
 
27
29
  If your app does not have `components.json` yet, run `npx shadcn@latest init` first or after the command above.
28
30
 
29
- ## React Hooks
31
+ ## Core Client
32
+
33
+ ```ts
34
+ import { LemmaClient } from "lemma-sdk";
35
+
36
+ const client = new LemmaClient({
37
+ podId: "<pod-id>",
38
+ });
39
+
40
+ await client.initialize();
41
+
42
+ const tables = await client.tables.list();
43
+ const records = await client.records.list("tickets");
44
+ ```
45
+
46
+ Pod-scoped namespaces include `tables`, `records`, `assistants`, `agents`, `tasks`, `workflows`, `functions`, `files`, `desks`, `integrations`, `resources`, and `datastore`.
47
+
48
+ Org and user surfaces include `users`, `organizations`, `pods`, `podMembers`, `podJoinRequests`, and `podSurfaces`.
49
+
50
+ ## React Package
30
51
 
31
- Install React if your app needs it:
52
+ Install React if your app needs hooks:
32
53
 
33
54
  ```bash
34
55
  npm install react react-dom
35
56
  ```
36
57
 
37
- `lemma-sdk/react` is intentionally headless-first. It includes hooks plus `AuthGuard`, but not stock assistant or records UI.
58
+ `lemma-sdk/react` is headless-first. It exports hooks plus `AuthGuard`; it does not export stock UI components or CSS.
38
59
 
39
60
  ```tsx
40
61
  import {
@@ -42,105 +63,231 @@ import {
42
63
  useAgentRun,
43
64
  useConversationMessages,
44
65
  useConversations,
45
- useForeignKeyOptions,
46
- useMembers,
47
- useRecordForm,
48
- useRecordSchema,
49
66
  useRecords,
50
67
  useSchemaForm,
51
- useTables,
52
68
  useWorkflowStart,
53
69
  } from "lemma-sdk/react";
54
70
  ```
55
71
 
56
- Typical hook groups:
72
+ ### Hook Matrix
57
73
 
58
- - data tables: `useTables`, `useTable`, `useRecords`, `useRecord`, `useRelatedRecords`, `useReverseRelatedRecords`
59
- - record mutations and forms: `useCreateRecord`, `useUpdateRecord`, `useDeleteRecord`, `useBulkRecords`, `useRecordSchema`, `useRecordForm`, `useSchemaForm`
60
- - assistant and runs: `useConversation`, `useConversations`, `useConversationMessages`, `useAssistantController`, `useAssistantRun`, `useAgentRun`, `useWorkflowStart`
61
- - org and auth: `AuthGuard`, `useMembers`
74
+ | Area | Hooks | Stability | Use when |
75
+ | --- | --- | --- | --- |
76
+ | Auth | `AuthGuard`, `useAuth`, `useCurrentUser`, `usePodAccess` | Stable | Gate an app, read signed-in user state, or request pod access. |
77
+ | Tables | `useTables`, `useTable`, `useRecords`, `useRecord`, `useJoinedRecords`, `useRelatedRecords`, `useReverseRelatedRecords` | Stable | Build custom table browsers, details views, related-record views, and relational reads. |
78
+ | Record mutations | `useCreateRecord`, `useUpdateRecord`, `useDeleteRecord`, `useBulkRecords` | Stable | Create, update, delete, or bulk-delete rows from headless UI. |
79
+ | Record forms | `useRecordSchema`, `useRecordForm`, `useForeignKeyOptions`, `useSchemaForm` | Stable | Render schema-driven forms, enum fields, and foreign-key selectors. |
80
+ | Assistant | `useConversations`, `useConversation`, `useConversationMessages`, `useAssistantRun`, `useAssistantSession`, `useAssistantRuntime`, `useAssistantController` | Stable except controller/runtime | Build custom chat, conversation lists, streaming output, and final-output views. |
81
+ | Agents | `useAgentRun`, `useAgentRuns`, `useAgentInputSchema`, `useTaskSession` | Stable except raw session | Start agent tasks, submit follow-up input, read task history, and inspect input/output schemas. |
82
+ | Workflows | `useWorkflowStart`, `useWorkflowRun`, `useWorkflowRuns`, `useWorkflowResume` | Stable | Start, poll, resume, cancel, retry, and inspect workflow runs. |
83
+ | Workflow compatibility | `useFlowSession`, `useFlowRunHistory` | Deprecated naming | Kept for existing callers; prefer workflow-named hooks for new code. |
84
+ | Functions | `useFunctionRun`, `useFunctionRuns`, `useFunctionSession` | Stable except raw session | Run functions, poll function runs, and list function history. |
85
+ | Members and org | `useMembers`, `useOrganizationMembers` | Stable | Read pod and organization member lists. `useMembers` is intentionally read-only. |
62
86
 
63
- Minimal example:
87
+ ### Common Hook Shapes
88
+
89
+ List hooks generally expose:
90
+
91
+ - `items` named for the resource, such as `records`, `runs`, or `members`
92
+ - `isLoading`
93
+ - `error`
94
+ - `nextPageToken`
95
+ - `refresh(...)`
96
+ - `loadMore(...)` where pagination is useful
97
+
98
+ Run hooks generally expose:
99
+
100
+ - `run` or `task`
101
+ - `status`
102
+ - `isPolling`, `isStreaming`, or `isRunning`
103
+ - `output`
104
+ - `finalOutput`
105
+ - `start(...)`
106
+ - `refresh(...)`
107
+ - follow-up helpers such as `resume(...)`, `submitInput(...)`, `cancel(...)`, or `retry(...)`
108
+
109
+ ### Headless Examples
110
+
111
+ Records:
64
112
 
65
113
  ```tsx
66
114
  import { LemmaClient } from "lemma-sdk";
67
- import { AuthGuard, useConversations, useConversationMessages } from "lemma-sdk/react";
115
+ import { useRecords } from "lemma-sdk/react";
68
116
 
69
117
  const client = new LemmaClient({ podId: "<pod-id>" });
70
118
 
71
- function SupportThread() {
119
+ function TicketList() {
120
+ const tickets = useRecords({
121
+ client,
122
+ tableName: "tickets",
123
+ limit: 25,
124
+ sortBy: "created_at",
125
+ order: "desc",
126
+ });
127
+
128
+ if (tickets.error) return <p>{tickets.error.message}</p>;
129
+
130
+ return (
131
+ <ul>
132
+ {tickets.records.map((ticket) => (
133
+ <li key={String(ticket.id)}>{String(ticket.title ?? ticket.id)}</li>
134
+ ))}
135
+ </ul>
136
+ );
137
+ }
138
+ ```
139
+
140
+ Assistant final output:
141
+
142
+ ```tsx
143
+ import { useConversationMessages, useConversations } from "lemma-sdk/react";
144
+
145
+ function SupportThread({ client }: { client: LemmaClient }) {
72
146
  const conversations = useConversations({
73
147
  client,
74
- podId: "<pod-id>",
75
148
  assistantName: "support_assistant",
76
149
  });
77
150
 
78
- const thread = useConversationMessages({
151
+ const messages = useConversationMessages({
79
152
  client,
80
- podId: "<pod-id>",
81
153
  conversationId: conversations.effectiveSelectedConversationId,
154
+ autoResume: true,
82
155
  });
83
156
 
84
- return <pre>{thread.finalOutputText ?? "No assistant output yet."}</pre>;
157
+ return <pre>{messages.finalOutputText || messages.outputText || "No output yet."}</pre>;
85
158
  }
159
+ ```
160
+
161
+ Agent run:
162
+
163
+ ```tsx
164
+ import { useAgentRun } from "lemma-sdk/react";
165
+
166
+ function AgentButton({ client }: { client: LemmaClient }) {
167
+ const agent = useAgentRun({
168
+ client,
169
+ agentName: "triage_agent",
170
+ });
171
+
172
+ return (
173
+ <button
174
+ disabled={agent.isStreaming}
175
+ onClick={() => {
176
+ void agent.start({ ticket_id: "ticket_123" });
177
+ }}
178
+ >
179
+ {agent.status ?? "Run agent"}
180
+ </button>
181
+ );
182
+ }
183
+ ```
184
+
185
+ Workflow run:
186
+
187
+ ```tsx
188
+ import { useWorkflowRun } from "lemma-sdk/react";
189
+
190
+ function WorkflowButton({ client }: { client: LemmaClient }) {
191
+ const workflow = useWorkflowRun({
192
+ client,
193
+ workflowName: "approve_ticket",
194
+ });
86
195
 
87
- export function App() {
88
196
  return (
89
- <AuthGuard client={client}>
90
- <SupportThread />
91
- </AuthGuard>
197
+ <button
198
+ disabled={workflow.isPolling}
199
+ onClick={() => {
200
+ void workflow.start({ ticket_id: "ticket_123" });
201
+ }}
202
+ >
203
+ {workflow.status ?? "Start workflow"}
204
+ </button>
92
205
  );
93
206
  }
94
207
  ```
95
208
 
96
209
  ## Shadcn Registry
97
210
 
98
- Lemma UI now lives in the registry, not in `lemma-sdk/react`.
211
+ Lemma UI lives in the registry, not in `lemma-sdk/react`.
99
212
 
100
213
  After running `npx lemma-sdk init-shadcn`, install blocks like:
101
214
 
102
215
  ```bash
103
216
  npx shadcn@latest add @lemma/lemma-records-page
104
- npx shadcn@latest add @lemma/lemma-assistant-embedded
105
- npx shadcn@latest add @lemma/lemma-workflow-start-form
217
+ npx shadcn@latest add @lemma/lemma-agent-runner-page
218
+ npx shadcn@latest add @lemma/lemma-workflow-launcher-page
219
+ npx shadcn@latest add @lemma/lemma-function-runner-page
106
220
  ```
107
221
 
108
- Current registry items include:
222
+ Current registry items:
109
223
 
110
- - `lemma-assistant-experience`
111
- - `lemma-assistant-embedded`
112
- - `lemma-schema-form`
113
- - `lemma-records-page`
114
- - `lemma-record-form`
115
- - `lemma-records-table`
116
- - `lemma-related-records-table`
117
- - `lemma-reverse-related-records-table`
118
- - `lemma-workflow-start-form`
224
+ | Area | Items |
225
+ | --- | --- |
226
+ | Assistant | `lemma-assistant-experience`, `lemma-assistant-embedded` |
227
+ | Schema | `lemma-schema-form` |
228
+ | Tables | `lemma-table-picker`, `lemma-record-picker`, `lemma-record-filters-bar`, `lemma-records-table`, `lemma-record-details-card`, `lemma-record-form`, `lemma-related-records-table`, `lemma-reverse-related-records-table`, `lemma-bulk-actions-bar`, `lemma-records-page` |
229
+ | Agents | `lemma-agent-run-panel`, `lemma-agent-output-card`, `lemma-agent-messages`, `lemma-agent-runner-page` |
230
+ | Workflows | `lemma-workflow-start-form`, `lemma-workflow-history`, `lemma-workflow-run-status`, `lemma-workflow-run-details`, `lemma-workflow-launcher-page` |
231
+ | Members and access | `lemma-members-table`, `lemma-member-picker`, `lemma-org-member-picker`, `lemma-pod-access-card` |
232
+ | Functions | `lemma-function-run-panel`, `lemma-function-run-history`, `lemma-function-runner-page` |
119
233
 
120
234
  The registry is currently served from jsDelivr against this public repo:
121
235
 
122
236
  - registry root: `https://cdn.jsdelivr.net/gh/gappyai/lemma-typescript@main/public/r/registry.json`
123
237
  - item shape: `https://cdn.jsdelivr.net/gh/gappyai/lemma-typescript@main/public/r/{name}.json`
124
238
 
125
- For more stable installs, prefer pinning the registry URL to a tag or commit SHA instead of `@main`.
239
+ For more stable installs, pin the registry URL to a tag or commit SHA instead of `@main`.
126
240
 
127
- ## Core Client
241
+ ### Records Workspace Customization
128
242
 
129
- ```ts
130
- import { LemmaClient } from "lemma-sdk";
243
+ The records blocks are meant to be configured with props before you reach for a fork.
131
244
 
132
- const client = new LemmaClient({
133
- podId: "<pod-id>",
134
- });
245
+ `lemma-records-page` supports:
135
246
 
136
- await client.initialize();
247
+ - capability toggles such as `allowCreate`, `allowEdit`, `allowSelection`, `allowBulkDelete`, `allowSearch`, `allowFilters`, `allowSorting`, `allowPageSizeSelect`, and `allowColumnVisibility`
248
+ - layout toggles such as `showTablePicker`, `showRecordPicker`, and `showRecordDetails`
249
+ - column control through `columns`, `hiddenColumnNames`, `defaultHiddenColumnNames`, and `onHiddenColumnNamesChange`
250
+ - non-`id` primary keys through `recordIdField` or `getRecordId`
251
+ - record-form overrides through `recordFormHiddenFields`, `recordFormFieldOrder`, `recordFormFieldLabels`, `recordFormFieldDescriptions`, `createFormTitle`, `editFormTitle`, `createSubmitLabel`, and `editSubmitLabel`
137
252
 
138
- const tables = await client.tables.list();
139
- const records = await client.records.list("tickets");
140
- ```
253
+ `lemma-records-table` supports richer column definitions:
254
+
255
+ - `label`, `description`, `type`, `width`, `minWidth`, `align`
256
+ - `searchable`, `hideable`, `hidden`
257
+ - `renderCell(...)` for custom cell output
258
+ - per-row buttons through `rowActions`
141
259
 
142
- Pod-scoped namespaces include `tables`, `records`, `assistants`, `agents`, `workflows`, `functions`, `files`, and `resources`.
143
- Org and user surfaces include `users`, `organizations`, `pods`, `podMembers`, and `podJoinRequests`.
260
+ ```tsx
261
+ import { LemmaRecordsPage } from "@/components/lemma/lemma-records-page";
262
+ import type { LemmaRecordsTableColumn } from "@/components/lemma/lemma-records-table";
263
+
264
+ const columns: LemmaRecordsTableColumn[] = [
265
+ { name: "item_id", label: "Item ID", hideable: false, width: 180 },
266
+ { name: "group_id", label: "Group", width: 160 },
267
+ { name: "name", label: "Name", minWidth: 320, searchable: true },
268
+ {
269
+ name: "sellable",
270
+ label: "Sellable",
271
+ type: "boolean",
272
+ width: 120,
273
+ align: "center",
274
+ renderCell: ({ value }) => (value ? "Yes" : "No"),
275
+ },
276
+ ];
277
+
278
+ <LemmaRecordsPage
279
+ allowColumnVisibility
280
+ allowCreate
281
+ allowEdit
282
+ columns={columns}
283
+ createButtonLabel="New SKU"
284
+ defaultHiddenColumnNames={["group_id"]}
285
+ editSubmitLabel="Save SKU"
286
+ recordFormFieldLabels={{ item_id: "Item ID" }}
287
+ recordIdField="item_id"
288
+ tableName="catalog_items"
289
+ />;
290
+ ```
144
291
 
145
292
  ## Auth
146
293
 
@@ -156,6 +303,19 @@ Useful helpers:
156
303
 
157
304
  When `client.podId` is set and the signed-in user is not a pod member, `AuthGuard` can render the request-access flow and create or show pod join requests.
158
305
 
306
+ `usePodAccess` exposes the same membership/request-access state as a hook for custom UI.
307
+
308
+ ## Migration Notes
309
+
310
+ From `0.2.30` onward:
311
+
312
+ - `lemma-sdk/react` should be treated as hooks plus auth primitives.
313
+ - `AuthGuard` remains in `lemma-sdk/react`.
314
+ - Stock UI should be installed from the shadcn registry.
315
+ - Assistant UI source and CSS are no longer part of the React SDK internals.
316
+ - `react-markdown` and `remark-gfm` are registry-block dependencies for assistant UI, not core SDK dependencies.
317
+ - New workflow code should prefer `useWorkflowRun`, `useWorkflowRuns`, and `useWorkflowResume` over the older `flow`-named hooks.
318
+
159
319
  ## Local Development
160
320
 
161
321
  From the root of this repository:
@@ -12,12 +12,22 @@ export { useConversationMessages } from "./useConversationMessages.js";
12
12
  export type { UseConversationMessagesOptions, UseConversationMessagesResult, } from "./useConversationMessages.js";
13
13
  export { useAgentRun } from "./useAgentRun.js";
14
14
  export type { UseAgentRunOptions, UseAgentRunResult } from "./useAgentRun.js";
15
+ export { useAgentRuns } from "./useAgentRuns.js";
16
+ export type { UseAgentRunsOptions, UseAgentRunsResult } from "./useAgentRuns.js";
17
+ export { useAgentInputSchema } from "./useAgentInputSchema.js";
18
+ export type { UseAgentInputSchemaOptions, UseAgentInputSchemaResult, } from "./useAgentInputSchema.js";
15
19
  export { useAssistantSession } from "./useAssistantSession.js";
16
20
  export type { CreateConversationInput, SendAssistantMessageOptions, UseAssistantSessionOptions, UseAssistantSessionResult, } from "./useAssistantSession.js";
17
21
  export { useAssistantRuntime } from "./useAssistantRuntime.js";
18
22
  export type { UseAssistantRuntimeOptions, UseAssistantRuntimeResult, } from "./useAssistantRuntime.js";
19
23
  export { useMembers } from "./useMembers.js";
20
24
  export type { UseMembersOptions, UseMembersResult } from "./useMembers.js";
25
+ export { useOrganizationMembers } from "./useOrganizationMembers.js";
26
+ export type { UseOrganizationMembersOptions, UseOrganizationMembersResult, } from "./useOrganizationMembers.js";
27
+ export { useCurrentUser } from "./useCurrentUser.js";
28
+ export type { UseCurrentUserOptions, UseCurrentUserResult } from "./useCurrentUser.js";
29
+ export { usePodAccess } from "./usePodAccess.js";
30
+ export type { PodAccessStatus, UsePodAccessOptions, UsePodAccessResult, } from "./usePodAccess.js";
21
31
  export { useTables } from "./useTables.js";
22
32
  export type { UseTablesOptions, UseTablesResult } from "./useTables.js";
23
33
  export { useTable } from "./useTable.js";
@@ -54,9 +64,19 @@ export { useTaskSession } from "./useTaskSession.js";
54
64
  export type { CreateTaskInput, UseTaskSessionOptions, UseTaskSessionResult, } from "./useTaskSession.js";
55
65
  export { useFunctionSession } from "./useFunctionSession.js";
56
66
  export type { UseFunctionSessionOptions, UseFunctionSessionResult, } from "./useFunctionSession.js";
67
+ export { useFunctionRun } from "./useFunctionRun.js";
68
+ export type { UseFunctionRunOptions, UseFunctionRunResult } from "./useFunctionRun.js";
69
+ export { useFunctionRuns } from "./useFunctionRuns.js";
70
+ export type { UseFunctionRunsOptions, UseFunctionRunsResult } from "./useFunctionRuns.js";
57
71
  export { useFlowSession } from "./useFlowSession.js";
58
72
  export type { UseFlowSessionOptions, UseFlowSessionResult, } from "./useFlowSession.js";
59
73
  export { useWorkflowStart } from "./useWorkflowStart.js";
60
74
  export type { UseWorkflowStartOptions, UseWorkflowStartResult, } from "./useWorkflowStart.js";
75
+ export { useWorkflowRun } from "./useWorkflowRun.js";
76
+ export type { UseWorkflowRunOptions, UseWorkflowRunResult } from "./useWorkflowRun.js";
77
+ export { useWorkflowRuns } from "./useWorkflowRuns.js";
78
+ export type { UseWorkflowRunsOptions, UseWorkflowRunsResult } from "./useWorkflowRuns.js";
79
+ export { useWorkflowResume } from "./useWorkflowResume.js";
80
+ export type { UseWorkflowResumeOptions, UseWorkflowResumeResult, } from "./useWorkflowResume.js";
61
81
  export { useFlowRunHistory } from "./useFlowRunHistory.js";
62
82
  export type { UseFlowRunHistoryOptions, UseFlowRunHistoryResult, } from "./useFlowRunHistory.js";
@@ -5,9 +5,14 @@ export { useConversations } from "./useConversations.js";
5
5
  export { useConversation } from "./useConversation.js";
6
6
  export { useConversationMessages } from "./useConversationMessages.js";
7
7
  export { useAgentRun } from "./useAgentRun.js";
8
+ export { useAgentRuns } from "./useAgentRuns.js";
9
+ export { useAgentInputSchema } from "./useAgentInputSchema.js";
8
10
  export { useAssistantSession } from "./useAssistantSession.js";
9
11
  export { useAssistantRuntime } from "./useAssistantRuntime.js";
10
12
  export { useMembers } from "./useMembers.js";
13
+ export { useOrganizationMembers } from "./useOrganizationMembers.js";
14
+ export { useCurrentUser } from "./useCurrentUser.js";
15
+ export { usePodAccess } from "./usePodAccess.js";
11
16
  export { useTables } from "./useTables.js";
12
17
  export { useTable } from "./useTable.js";
13
18
  export { useRecords } from "./useRecords.js";
@@ -26,6 +31,11 @@ export { useSchemaForm } from "./useSchemaForm.js";
26
31
  export { useAssistantController } from "./useAssistantController.js";
27
32
  export { useTaskSession } from "./useTaskSession.js";
28
33
  export { useFunctionSession } from "./useFunctionSession.js";
34
+ export { useFunctionRun } from "./useFunctionRun.js";
35
+ export { useFunctionRuns } from "./useFunctionRuns.js";
29
36
  export { useFlowSession } from "./useFlowSession.js";
30
37
  export { useWorkflowStart } from "./useWorkflowStart.js";
38
+ export { useWorkflowRun } from "./useWorkflowRun.js";
39
+ export { useWorkflowRuns } from "./useWorkflowRuns.js";
40
+ export { useWorkflowResume } from "./useWorkflowResume.js";
31
41
  export { useFlowRunHistory } from "./useFlowRunHistory.js";
@@ -0,0 +1,19 @@
1
+ import type { LemmaClient } from "../client.js";
2
+ import type { JsonSchemaLike } from "../schema-form.js";
3
+ import type { Agent } from "../types.js";
4
+ export interface UseAgentInputSchemaOptions {
5
+ client: LemmaClient;
6
+ podId?: string;
7
+ agentName: string;
8
+ enabled?: boolean;
9
+ autoLoad?: boolean;
10
+ }
11
+ export interface UseAgentInputSchemaResult {
12
+ agent: Agent | null;
13
+ inputSchema: JsonSchemaLike | null;
14
+ outputSchema: JsonSchemaLike | null;
15
+ isLoading: boolean;
16
+ error: Error | null;
17
+ refresh: () => Promise<Agent | null>;
18
+ }
19
+ export declare function useAgentInputSchema({ client, podId, agentName, enabled, autoLoad, }: UseAgentInputSchemaOptions): UseAgentInputSchemaResult;
@@ -0,0 +1,73 @@
1
+ import { useCallback, useEffect, useMemo, useState } from "react";
2
+ import { normalizeError, resolvePodClient } from "./utils.js";
3
+ export function useAgentInputSchema({ client, podId, agentName, enabled = true, autoLoad = true, }) {
4
+ const [agent, setAgent] = useState(null);
5
+ const [isLoading, setIsLoading] = useState(false);
6
+ const [error, setError] = useState(null);
7
+ const trimmedAgentName = agentName.trim();
8
+ const isEnabled = enabled && trimmedAgentName.length > 0;
9
+ const refresh = useCallback(async (signal) => {
10
+ if (!isEnabled) {
11
+ setAgent(null);
12
+ setError(null);
13
+ setIsLoading(false);
14
+ return null;
15
+ }
16
+ setIsLoading(true);
17
+ setError(null);
18
+ try {
19
+ const scopedClient = resolvePodClient(client, podId);
20
+ const nextAgent = await scopedClient.agents.get(trimmedAgentName);
21
+ if (signal?.aborted)
22
+ return null;
23
+ setAgent(nextAgent);
24
+ return nextAgent;
25
+ }
26
+ catch (refreshError) {
27
+ if (signal?.aborted)
28
+ return null;
29
+ const normalized = normalizeError(refreshError, "Failed to load agent schema.");
30
+ setError(normalized);
31
+ setAgent(null);
32
+ return null;
33
+ }
34
+ finally {
35
+ if (!signal?.aborted)
36
+ setIsLoading(false);
37
+ }
38
+ }, [client, isEnabled, podId, trimmedAgentName]);
39
+ useEffect(() => {
40
+ if (!isEnabled) {
41
+ setAgent(null);
42
+ setError(null);
43
+ setIsLoading(false);
44
+ return;
45
+ }
46
+ if (!autoLoad)
47
+ return;
48
+ const controller = new AbortController();
49
+ let cancelled = false;
50
+ (async () => {
51
+ try {
52
+ await refresh(controller.signal);
53
+ }
54
+ catch {
55
+ if (!cancelled) {
56
+ setError(normalizeError(new Error("Failed to load agent schema."), "Failed to load agent schema."));
57
+ }
58
+ }
59
+ })();
60
+ return () => {
61
+ cancelled = true;
62
+ controller.abort();
63
+ };
64
+ }, [autoLoad, isEnabled, refresh]);
65
+ return useMemo(() => ({
66
+ agent,
67
+ inputSchema: (agent?.input_schema ?? null),
68
+ outputSchema: (agent?.output_schema ?? null),
69
+ isLoading,
70
+ error,
71
+ refresh,
72
+ }), [agent, error, isLoading, refresh]);
73
+ }
@@ -1,5 +1,6 @@
1
- import { useCallback } from "react";
1
+ import { useCallback, useMemo } from "react";
2
2
  import { isTerminalTaskStatus, normalizeRunStatus } from "../run-utils.js";
3
+ import { resolvePodClient } from "./utils.js";
3
4
  import { useTaskSession, } from "./useTaskSession.js";
4
5
  function resolveAgentName(base, override) {
5
6
  const resolved = override ?? base;
@@ -8,11 +9,6 @@ function resolveAgentName(base, override) {
8
9
  }
9
10
  return resolved;
10
11
  }
11
- function resolvePodClient(client, podId) {
12
- if (!podId || podId === client.podId)
13
- return client;
14
- return client.withPod(podId);
15
- }
16
12
  export function useAgentRun({ client, podId, agentName, taskId = null, autoConnect = true, autoConnectOnStart = true, onEvent, onStatus, onMessage, onError, }) {
17
13
  const session = useTaskSession({
18
14
  client,
@@ -41,18 +37,20 @@ export function useAgentRun({ client, podId, agentName, taskId = null, autoConne
41
37
  await session.loadMessages(resolvedTaskId);
42
38
  return session.refreshTask(resolvedTaskId);
43
39
  }, [client, podId, session]);
44
- const normalizedStatus = normalizeRunStatus(session.status);
45
- const isFinished = isTerminalTaskStatus(normalizedStatus);
46
- const isWaitingForInput = normalizedStatus === "WAITING";
47
- const output = session.task?.output_data ?? null;
48
- const finalOutput = isFinished ? output : null;
49
- return {
50
- ...session,
51
- output,
52
- finalOutput,
53
- isWaitingForInput,
54
- isFinished,
55
- start,
56
- submitInput,
57
- };
40
+ return useMemo(() => {
41
+ const normalizedStatus = normalizeRunStatus(session.status);
42
+ const isFinished = isTerminalTaskStatus(normalizedStatus);
43
+ const isWaitingForInput = normalizedStatus === "WAITING";
44
+ const output = session.task?.output_data ?? null;
45
+ const finalOutput = isFinished ? output : null;
46
+ return {
47
+ ...session,
48
+ output,
49
+ finalOutput,
50
+ isWaitingForInput,
51
+ isFinished,
52
+ start,
53
+ submitInput,
54
+ };
55
+ }, [session, start, submitInput]);
58
56
  }
@@ -0,0 +1,33 @@
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;