lemma-sdk 0.2.27 → 0.2.30

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 (90) hide show
  1. package/README.md +113 -233
  2. package/bin/lemma-sdk.js +108 -0
  3. package/dist/browser/lemma-client.js +125 -4
  4. package/dist/client.d.ts +2 -0
  5. package/dist/client.js +3 -0
  6. package/dist/config.d.ts +2 -2
  7. package/dist/config.js +2 -2
  8. package/dist/datastore-query.d.ts +54 -0
  9. package/dist/datastore-query.js +157 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.js +3 -0
  12. package/dist/namespaces/datastore.d.ts +9 -0
  13. package/dist/namespaces/datastore.js +13 -0
  14. package/dist/namespaces/records.d.ts +1 -1
  15. package/dist/openapi_client/index.d.ts +4 -0
  16. package/dist/openapi_client/index.js +1 -0
  17. package/dist/openapi_client/models/ConvertedArtifactResponse.d.ts +6 -0
  18. package/dist/openapi_client/models/ConvertedArtifactResponse.js +1 -0
  19. package/dist/openapi_client/models/ConvertedFileResponse.d.ts +10 -0
  20. package/dist/openapi_client/models/ConvertedFileResponse.js +1 -0
  21. package/dist/openapi_client/models/CreateFolderRequest.d.ts +3 -1
  22. package/dist/openapi_client/models/FlowRunEntity.d.ts +1 -0
  23. package/dist/openapi_client/models/ScheduledFlowStart.d.ts +3 -6
  24. package/dist/openapi_client/models/ScheduledFlowStartType.d.ts +4 -0
  25. package/dist/openapi_client/models/ScheduledFlowStartType.js +9 -0
  26. package/dist/openapi_client/models/WorkflowInstallRequest.d.ts +5 -0
  27. package/dist/openapi_client/models/WorkflowTimeInstallConfig.d.ts +19 -0
  28. package/dist/openapi_client/models/WorkflowTimeInstallConfig.js +1 -0
  29. package/dist/openapi_client/services/FilesService.d.ts +27 -1
  30. package/dist/openapi_client/services/FilesService.js +69 -1
  31. package/dist/openapi_client/services/WorkflowsService.d.ts +1 -1
  32. package/dist/openapi_client/services/WorkflowsService.js +1 -1
  33. package/dist/react/assistant-output.d.ts +6 -0
  34. package/dist/react/assistant-output.js +90 -0
  35. package/dist/react/components/AssistantExperience.js +6 -4
  36. package/dist/react/index.d.ts +42 -8
  37. package/dist/react/index.js +21 -4
  38. package/dist/react/useAgentRun.d.ts +17 -0
  39. package/dist/react/useAgentRun.js +58 -0
  40. package/dist/react/useAssistantRun.d.ts +9 -0
  41. package/dist/react/useAssistantRun.js +19 -9
  42. package/dist/react/useAssistantSession.d.ts +5 -0
  43. package/dist/react/useAssistantSession.js +123 -70
  44. package/dist/react/useBulkRecords.d.ts +20 -0
  45. package/dist/react/useBulkRecords.js +72 -0
  46. package/dist/react/useConversation.d.ts +18 -0
  47. package/dist/react/useConversation.js +59 -0
  48. package/dist/react/useConversationMessages.d.ts +59 -0
  49. package/dist/react/useConversationMessages.js +167 -0
  50. package/dist/react/useConversations.d.ts +48 -0
  51. package/dist/react/useConversations.js +182 -0
  52. package/dist/react/useCreateRecord.d.ts +18 -0
  53. package/dist/react/useCreateRecord.js +58 -0
  54. package/dist/react/useDeleteRecord.d.ts +21 -0
  55. package/dist/react/useDeleteRecord.js +59 -0
  56. package/dist/react/useForeignKeyOptions.d.ts +31 -0
  57. package/dist/react/useForeignKeyOptions.js +150 -0
  58. package/dist/react/useJoinedRecords.d.ts +18 -0
  59. package/dist/react/useJoinedRecords.js +79 -0
  60. package/dist/react/useMembers.d.ts +22 -0
  61. package/dist/react/useMembers.js +59 -0
  62. package/dist/react/useRecord.d.ts +18 -0
  63. package/dist/react/useRecord.js +64 -0
  64. package/dist/react/useRecordForm.d.ts +42 -0
  65. package/dist/react/useRecordForm.js +238 -0
  66. package/dist/react/useRecordSchema.d.ts +20 -0
  67. package/dist/react/useRecordSchema.js +24 -0
  68. package/dist/react/useRecords.d.ts +18 -0
  69. package/dist/react/useRecords.js +106 -0
  70. package/dist/react/useRelatedRecords.d.ts +43 -0
  71. package/dist/react/useRelatedRecords.js +232 -0
  72. package/dist/react/useReverseRelatedRecords.d.ts +47 -0
  73. package/dist/react/useReverseRelatedRecords.js +226 -0
  74. package/dist/react/useSchemaForm.d.ts +24 -0
  75. package/dist/react/useSchemaForm.js +116 -0
  76. package/dist/react/useTable.d.ts +16 -0
  77. package/dist/react/useTable.js +59 -0
  78. package/dist/react/useTables.d.ts +22 -0
  79. package/dist/react/useTables.js +71 -0
  80. package/dist/react/useUpdateRecord.d.ts +21 -0
  81. package/dist/react/useUpdateRecord.js +62 -0
  82. package/dist/react/useWorkflowStart.d.ts +33 -0
  83. package/dist/react/useWorkflowStart.js +155 -0
  84. package/dist/record-form.d.ts +30 -0
  85. package/dist/record-form.js +199 -0
  86. package/dist/schema-form.d.ts +41 -0
  87. package/dist/schema-form.js +200 -0
  88. package/dist/types.d.ts +5 -1
  89. package/package.json +10 -5
  90. package/dist/react/styles.css +0 -2401
@@ -0,0 +1,41 @@
1
+ export type JsonSchemaPrimitiveType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
2
+ export interface JsonSchemaLike {
3
+ type?: JsonSchemaPrimitiveType | JsonSchemaPrimitiveType[];
4
+ title?: string;
5
+ description?: string;
6
+ format?: string;
7
+ default?: unknown;
8
+ enum?: unknown[];
9
+ properties?: Record<string, JsonSchemaLike>;
10
+ required?: string[];
11
+ items?: JsonSchemaLike;
12
+ anyOf?: JsonSchemaLike[];
13
+ oneOf?: JsonSchemaLike[];
14
+ allOf?: JsonSchemaLike[];
15
+ [key: string]: unknown;
16
+ }
17
+ export type SchemaFormFieldKind = "text" | "textarea" | "number" | "boolean" | "select" | "json" | "date" | "datetime" | "email";
18
+ export interface SchemaFormField {
19
+ name: string;
20
+ label: string;
21
+ description?: string;
22
+ required: boolean;
23
+ kind: SchemaFormFieldKind;
24
+ type: JsonSchemaPrimitiveType | "unknown";
25
+ format?: string;
26
+ options: Array<{
27
+ label: string;
28
+ value: string;
29
+ }>;
30
+ defaultValue?: unknown;
31
+ schema: JsonSchemaLike;
32
+ }
33
+ export interface BuildSchemaFormPayloadResult {
34
+ data: Record<string, unknown>;
35
+ errors: Record<string, string>;
36
+ isValid: boolean;
37
+ }
38
+ export declare function buildSchemaFormFields(schema: JsonSchemaLike | null | undefined, uiSchema?: Record<string, unknown> | null): SchemaFormField[];
39
+ export declare function formatSchemaFieldValueForForm(field: SchemaFormField, value: unknown): unknown;
40
+ export declare function buildSchemaFormValues(schema: JsonSchemaLike | null | undefined, values?: Record<string, unknown>, uiSchema?: Record<string, unknown> | null): Record<string, unknown>;
41
+ export declare function buildSchemaFormPayload(schema: JsonSchemaLike | null | undefined, values: Record<string, unknown>, uiSchema?: Record<string, unknown> | null): BuildSchemaFormPayloadResult;
@@ -0,0 +1,200 @@
1
+ function sentenceCase(value) {
2
+ return value
3
+ .replace(/_/g, " ")
4
+ .replace(/\s+/g, " ")
5
+ .trim()
6
+ .replace(/\b\w/g, (match) => match.toUpperCase());
7
+ }
8
+ function isRecord(value) {
9
+ return !!value && typeof value === "object" && !Array.isArray(value);
10
+ }
11
+ function isBlank(value) {
12
+ return value === null || typeof value === "undefined" || (typeof value === "string" && value.trim() === "");
13
+ }
14
+ function normalizeSchemaType(schema) {
15
+ if (Array.isArray(schema.type)) {
16
+ const nonNull = schema.type.find((entry) => entry !== "null");
17
+ return nonNull ?? "unknown";
18
+ }
19
+ if (typeof schema.type === "string") {
20
+ return schema.type;
21
+ }
22
+ if (schema.enum?.length) {
23
+ return "string";
24
+ }
25
+ if (schema.properties && isRecord(schema.properties)) {
26
+ return "object";
27
+ }
28
+ if (schema.items) {
29
+ return "array";
30
+ }
31
+ return "unknown";
32
+ }
33
+ function getSchemaFieldKind(schema) {
34
+ if (schema.enum?.length)
35
+ return "select";
36
+ const type = normalizeSchemaType(schema);
37
+ const format = typeof schema.format === "string" ? schema.format : undefined;
38
+ if (type === "boolean")
39
+ return "boolean";
40
+ if (type === "number" || type === "integer")
41
+ return "number";
42
+ if (format === "date")
43
+ return "date";
44
+ if (format === "date-time")
45
+ return "datetime";
46
+ if (format === "email")
47
+ return "email";
48
+ if (type === "object" || type === "array")
49
+ return "json";
50
+ if (format === "textarea")
51
+ return "textarea";
52
+ const title = `${schema.title ?? ""} ${schema.description ?? ""}`.toLowerCase();
53
+ if (/(description|body|content|message|note|summary|instructions)/.test(title)) {
54
+ return "textarea";
55
+ }
56
+ return "text";
57
+ }
58
+ function formatDateInputValue(value) {
59
+ if (typeof value === "string") {
60
+ return value.includes("T") ? value.slice(0, 10) : value;
61
+ }
62
+ if (value instanceof Date && !Number.isNaN(value.getTime())) {
63
+ return value.toISOString().slice(0, 10);
64
+ }
65
+ return String(value);
66
+ }
67
+ function formatDateTimeLocalInputValue(value) {
68
+ const date = value instanceof Date ? value : new Date(String(value));
69
+ if (Number.isNaN(date.getTime())) {
70
+ return String(value);
71
+ }
72
+ const pad = (part) => String(part).padStart(2, "0");
73
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
74
+ }
75
+ export function buildSchemaFormFields(schema, uiSchema) {
76
+ if (!schema || !isRecord(schema.properties))
77
+ return [];
78
+ const required = Array.isArray(schema.required) ? schema.required : [];
79
+ const order = Array.isArray(uiSchema?.["ui:order"])
80
+ ? (uiSchema?.["ui:order"]).filter((entry) => typeof entry === "string")
81
+ : [];
82
+ const orderIndex = new Map(order.map((name, index) => [name, index]));
83
+ const fields = Object.entries(schema.properties).map(([name, propertySchema]) => {
84
+ const property = isRecord(propertySchema) ? propertySchema : {};
85
+ const uiFieldConfig = isRecord(uiSchema?.[name]) ? uiSchema?.[name] : {};
86
+ const widget = typeof uiFieldConfig["ui:widget"] === "string" ? uiFieldConfig["ui:widget"] : undefined;
87
+ const kind = widget === "textarea" ? "textarea" : getSchemaFieldKind(property);
88
+ return {
89
+ name,
90
+ label: typeof property.title === "string" && property.title.trim().length > 0
91
+ ? property.title
92
+ : sentenceCase(name),
93
+ description: typeof property.description === "string" ? property.description : undefined,
94
+ required: required.includes(name),
95
+ kind,
96
+ type: normalizeSchemaType(property),
97
+ format: typeof property.format === "string" ? property.format : undefined,
98
+ options: (property.enum ?? []).map((value) => ({
99
+ label: typeof value === "string" ? value : JSON.stringify(value),
100
+ value: typeof value === "string" ? value : JSON.stringify(value),
101
+ })),
102
+ defaultValue: property.default,
103
+ schema: property,
104
+ };
105
+ });
106
+ return fields.sort((left, right) => {
107
+ const leftIndex = orderIndex.get(left.name);
108
+ const rightIndex = orderIndex.get(right.name);
109
+ if (typeof leftIndex === "number" && typeof rightIndex === "number") {
110
+ return leftIndex - rightIndex;
111
+ }
112
+ if (typeof leftIndex === "number")
113
+ return -1;
114
+ if (typeof rightIndex === "number")
115
+ return 1;
116
+ return left.label.localeCompare(right.label);
117
+ });
118
+ }
119
+ export function formatSchemaFieldValueForForm(field, value) {
120
+ if (value === null || typeof value === "undefined") {
121
+ if (field.kind === "boolean")
122
+ return false;
123
+ return "";
124
+ }
125
+ if (field.kind === "boolean")
126
+ return Boolean(value);
127
+ if (field.kind === "number")
128
+ return String(value);
129
+ if (field.kind === "date")
130
+ return formatDateInputValue(value);
131
+ if (field.kind === "datetime")
132
+ return formatDateTimeLocalInputValue(value);
133
+ if (field.kind === "json") {
134
+ if (typeof value === "string")
135
+ return value;
136
+ try {
137
+ return JSON.stringify(value, null, 2);
138
+ }
139
+ catch {
140
+ return String(value);
141
+ }
142
+ }
143
+ return String(value);
144
+ }
145
+ export function buildSchemaFormValues(schema, values = {}, uiSchema) {
146
+ const fields = buildSchemaFormFields(schema, uiSchema);
147
+ const next = {};
148
+ fields.forEach((field) => {
149
+ const provided = values[field.name];
150
+ const source = typeof provided !== "undefined" ? provided : field.defaultValue;
151
+ next[field.name] = formatSchemaFieldValueForForm(field, source);
152
+ });
153
+ return next;
154
+ }
155
+ export function buildSchemaFormPayload(schema, values, uiSchema) {
156
+ const fields = buildSchemaFormFields(schema, uiSchema);
157
+ const data = {};
158
+ const errors = {};
159
+ fields.forEach((field) => {
160
+ const rawValue = values[field.name];
161
+ if (field.kind === "boolean") {
162
+ data[field.name] = Boolean(rawValue);
163
+ return;
164
+ }
165
+ if (isBlank(rawValue)) {
166
+ if (field.required) {
167
+ errors[field.name] = `${field.label} is required.`;
168
+ }
169
+ return;
170
+ }
171
+ if (field.kind === "number") {
172
+ const parsed = Number(rawValue);
173
+ if (!Number.isFinite(parsed)) {
174
+ errors[field.name] = `${field.label} must be a valid number.`;
175
+ return;
176
+ }
177
+ if (field.type === "integer" && !Number.isInteger(parsed)) {
178
+ errors[field.name] = `${field.label} must be a whole number.`;
179
+ return;
180
+ }
181
+ data[field.name] = parsed;
182
+ return;
183
+ }
184
+ if (field.kind === "json") {
185
+ try {
186
+ data[field.name] = typeof rawValue === "string" ? JSON.parse(rawValue) : rawValue;
187
+ }
188
+ catch {
189
+ errors[field.name] = `${field.label} must be valid JSON.`;
190
+ }
191
+ return;
192
+ }
193
+ data[field.name] = rawValue;
194
+ });
195
+ return {
196
+ data,
197
+ errors,
198
+ isValid: Object.keys(errors).length === 0,
199
+ };
200
+ }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AgentResponse, AssistantResponse, AvailableModels, ConversationMessageResponse, ConversationResponse, CreateAgentRequest, CreateAssistantRequest, CreateTaskRequest, FlowRunEntity, FunctionRunResponse, IconUploadResponse, OrganizationInvitationResponse, OrganizationMemberResponse, OrganizationResponse, PodConfigResponse, PodJoinRequestCreateResponse, PodMemberResponse, PodResponse, TaskMessageResponse, TaskResponse, UpdateAgentRequest, UpdateAssistantRequest, UserResponse } from "./openapi_client/index.js";
1
+ import type { AgentResponse, AssistantResponse, AvailableModels, ColumnSchema, ConversationMessageResponse, ConversationResponse, CreateAgentRequest, CreateAssistantRequest, CreateTaskRequest, DatastoreQueryResponse, FlowRunEntity, FlowResponse, FunctionRunResponse, IconUploadResponse, OrganizationInvitationResponse, OrganizationMemberResponse, OrganizationResponse, PodConfigResponse, PodJoinRequestCreateResponse, PodMemberResponse, PodResponse, TableResponse, TaskMessageResponse, TaskResponse, UpdateAgentRequest, UpdateAssistantRequest, UserResponse } from "./openapi_client/index.js";
2
2
  /** Public ergonomic types. */
3
3
  export interface PageResult<T> {
4
4
  items: T[];
@@ -51,6 +51,10 @@ export type Task = TaskResponse;
51
51
  export type TaskMessage = TaskMessageResponse;
52
52
  export type FunctionRun = FunctionRunResponse;
53
53
  export type FlowRun = FlowRunEntity;
54
+ export type Workflow = FlowResponse;
55
+ export type Table = TableResponse;
56
+ export type TableColumn = ColumnSchema;
57
+ export type DatastoreQueryResult = DatastoreQueryResponse;
54
58
  export type Pod = PodResponse;
55
59
  export type PodConfig = PodConfigResponse;
56
60
  export type PodMember = PodMemberResponse;
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "lemma-sdk",
3
- "version": "0.2.27",
3
+ "version": "0.2.30",
4
4
  "description": "Official TypeScript SDK for Lemma pod-scoped APIs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "lemma-sdk": "./bin/lemma-sdk.js"
10
+ },
8
11
  "repository": {
9
12
  "type": "git",
10
- "url": "git+https://github.com/gappyai/lemma-typescript.git"
13
+ "url": "https://github.com/gappyai/lemma-typescript"
11
14
  },
12
15
  "homepage": "https://github.com/gappyai/lemma-typescript#readme",
13
16
  "bugs": {
@@ -29,18 +32,19 @@
29
32
  "types": "./dist/react/index.d.ts",
30
33
  "default": "./dist/react/index.js"
31
34
  },
32
- "./react/styles.css": "./dist/react/styles.css",
33
35
  "./browser-bundle": "./dist/browser/lemma-client.js"
34
36
  },
35
37
  "unpkg": "dist/browser/lemma-client.js",
36
38
  "files": [
37
- "dist"
39
+ "dist",
40
+ "bin"
38
41
  ],
39
42
  "scripts": {
40
43
  "generate:client": "./scripts/generate_openapi_client.sh",
41
- "build": "npm run clean && tsc -p tsconfig.json && node ./scripts/copy_react_styles.mjs && npm run build:bundle",
44
+ "build": "npm run clean && tsc -p tsconfig.json && npm run build:bundle",
42
45
  "build:bundle": "tsc -p tsconfig.bundle.json && node ./scripts/build_browser_bundle.mjs",
43
46
  "clean": "rm -rf dist",
47
+ "registry:build": "shadcn build ./registry.json -o ./public/r",
44
48
  "prepublishOnly": "npm run build",
45
49
  "release:check": "npm run build && npm_config_cache=.npm-cache npm pack --dry-run"
46
50
  },
@@ -60,6 +64,7 @@
60
64
  "devDependencies": {
61
65
  "@types/react": "^18.3.28",
62
66
  "openapi-typescript-codegen": "^0.29.0",
67
+ "shadcn": "^4.2.0",
63
68
  "typescript": "^5.6.3"
64
69
  }
65
70
  }