@superatomai/sdk-web 0.0.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.
- package/README.md +526 -0
- package/dist/index.cjs +1611 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1550 -0
- package/dist/index.d.ts +1550 -0
- package/dist/index.js +1570 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1570 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
var ExpressionSchema = z.object({
|
|
9
|
+
$exp: z.string(),
|
|
10
|
+
$deps: z.array(z.string()).optional()
|
|
11
|
+
});
|
|
12
|
+
var BindingSchema = z.object({
|
|
13
|
+
$bind: z.string(),
|
|
14
|
+
$transform: z.array(
|
|
15
|
+
z.object({
|
|
16
|
+
name: z.string(),
|
|
17
|
+
args: z.array(z.any()).optional()
|
|
18
|
+
})
|
|
19
|
+
).optional()
|
|
20
|
+
});
|
|
21
|
+
var ForDirectiveSchema = z.object({
|
|
22
|
+
in: z.union([ExpressionSchema, BindingSchema, z.string()]),
|
|
23
|
+
as: z.string(),
|
|
24
|
+
key: z.string().optional(),
|
|
25
|
+
index: z.string().optional()
|
|
26
|
+
});
|
|
27
|
+
var QuerySpecSchema = z.object({
|
|
28
|
+
graphql: z.string().optional(),
|
|
29
|
+
sql: z.string().optional(),
|
|
30
|
+
variables: z.record(z.string(), z.any()).optional(),
|
|
31
|
+
params: z.record(z.string(), z.any()).optional(),
|
|
32
|
+
key: z.string().optional(),
|
|
33
|
+
refetchPolicy: z.enum(["cache-first", "network-only", "cache-and-network"]).optional(),
|
|
34
|
+
dependencies: z.array(z.string()).optional()
|
|
35
|
+
});
|
|
36
|
+
var UIElementSchema = z.lazy(
|
|
37
|
+
() => z.object({
|
|
38
|
+
id: z.string(),
|
|
39
|
+
type: z.string(),
|
|
40
|
+
key: z.union([z.string(), ExpressionSchema]).optional(),
|
|
41
|
+
props: z.record(z.string(), z.any()).optional(),
|
|
42
|
+
query: QuerySpecSchema.optional(),
|
|
43
|
+
if: ExpressionSchema.optional(),
|
|
44
|
+
elseIf: ExpressionSchema.optional(),
|
|
45
|
+
for: ForDirectiveSchema.optional(),
|
|
46
|
+
"link-to": z.union([
|
|
47
|
+
z.string(),
|
|
48
|
+
ExpressionSchema,
|
|
49
|
+
BindingSchema,
|
|
50
|
+
z.object({
|
|
51
|
+
ui: z.union([z.string(), ExpressionSchema, BindingSchema]),
|
|
52
|
+
params: z.record(z.string(), z.any()).optional()
|
|
53
|
+
})
|
|
54
|
+
]).optional(),
|
|
55
|
+
_meta: z.object({
|
|
56
|
+
id: z.string().optional(),
|
|
57
|
+
version: z.string().optional(),
|
|
58
|
+
created: z.string().optional(),
|
|
59
|
+
lastModified: z.string().optional()
|
|
60
|
+
}).optional(),
|
|
61
|
+
children: z.any().optional(),
|
|
62
|
+
else: UIElementSchema.optional(),
|
|
63
|
+
slots: z.record(z.string(), z.union([UIElementSchema, z.array(UIElementSchema)])).optional(),
|
|
64
|
+
platform: z.object({
|
|
65
|
+
web: z.any().optional(),
|
|
66
|
+
ios: z.any().optional(),
|
|
67
|
+
android: z.any().optional()
|
|
68
|
+
}).optional()
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
var UIComponentSchema = z.object({
|
|
72
|
+
id: z.string(),
|
|
73
|
+
name: z.string().optional(),
|
|
74
|
+
props: z.record(z.string(), z.any()).optional(),
|
|
75
|
+
states: z.record(z.string(), z.any()).optional(),
|
|
76
|
+
methods: z.record(
|
|
77
|
+
z.string(),
|
|
78
|
+
z.object({
|
|
79
|
+
fn: z.string(),
|
|
80
|
+
params: z.record(z.string(), z.any()).optional()
|
|
81
|
+
})
|
|
82
|
+
).optional(),
|
|
83
|
+
effects: z.array(
|
|
84
|
+
z.object({
|
|
85
|
+
fn: z.string(),
|
|
86
|
+
deps: z.array(z.string()).optional()
|
|
87
|
+
})
|
|
88
|
+
).optional(),
|
|
89
|
+
data: z.record(z.string(), z.any()).optional(),
|
|
90
|
+
render: UIElementSchema,
|
|
91
|
+
query: QuerySpecSchema.optional()
|
|
92
|
+
});
|
|
93
|
+
var DSLRendererPropsSchema = z.object({
|
|
94
|
+
dsl: UIComponentSchema,
|
|
95
|
+
data: z.record(z.string(), z.any()).optional(),
|
|
96
|
+
context: z.record(z.string(), z.any()).optional()
|
|
97
|
+
});
|
|
98
|
+
var ExpressionSchema2 = z.object({
|
|
99
|
+
$exp: z.string(),
|
|
100
|
+
$deps: z.array(z.string()).optional()
|
|
101
|
+
});
|
|
102
|
+
var BindingSchema2 = z.object({
|
|
103
|
+
$bind: z.string(),
|
|
104
|
+
$transform: z.array(
|
|
105
|
+
z.object({
|
|
106
|
+
name: z.string(),
|
|
107
|
+
args: z.array(z.any()).optional()
|
|
108
|
+
})
|
|
109
|
+
).optional()
|
|
110
|
+
});
|
|
111
|
+
var ForDirectiveSchema2 = z.object({
|
|
112
|
+
in: z.union([ExpressionSchema2, BindingSchema2, z.string()]),
|
|
113
|
+
as: z.string(),
|
|
114
|
+
key: z.string().optional(),
|
|
115
|
+
index: z.string().optional()
|
|
116
|
+
});
|
|
117
|
+
var QuerySpecSchema2 = z.object({
|
|
118
|
+
graphql: z.string().optional(),
|
|
119
|
+
sql: z.string().optional(),
|
|
120
|
+
variables: z.record(z.string(), z.any()).optional(),
|
|
121
|
+
params: z.record(z.string(), z.any()).optional(),
|
|
122
|
+
key: z.string().optional(),
|
|
123
|
+
refetchPolicy: z.enum(["cache-first", "network-only", "cache-and-network"]).optional(),
|
|
124
|
+
dependencies: z.array(z.string()).optional()
|
|
125
|
+
});
|
|
126
|
+
var UIElementSchema2 = z.lazy(
|
|
127
|
+
() => z.object({
|
|
128
|
+
id: z.string(),
|
|
129
|
+
type: z.string(),
|
|
130
|
+
key: z.union([z.string(), ExpressionSchema2]).optional(),
|
|
131
|
+
props: z.record(z.string(), z.any()).optional(),
|
|
132
|
+
query: QuerySpecSchema2.optional(),
|
|
133
|
+
if: ExpressionSchema2.optional(),
|
|
134
|
+
elseIf: ExpressionSchema2.optional(),
|
|
135
|
+
for: ForDirectiveSchema2.optional(),
|
|
136
|
+
"link-to": z.union([
|
|
137
|
+
z.string(),
|
|
138
|
+
ExpressionSchema2,
|
|
139
|
+
BindingSchema2,
|
|
140
|
+
z.object({
|
|
141
|
+
ui: z.union([z.string(), ExpressionSchema2, BindingSchema2]),
|
|
142
|
+
params: z.record(z.string(), z.any()).optional()
|
|
143
|
+
})
|
|
144
|
+
]).optional(),
|
|
145
|
+
_meta: z.object({
|
|
146
|
+
id: z.string().optional(),
|
|
147
|
+
version: z.string().optional(),
|
|
148
|
+
created: z.string().optional(),
|
|
149
|
+
lastModified: z.string().optional()
|
|
150
|
+
}).optional(),
|
|
151
|
+
children: z.any().optional(),
|
|
152
|
+
else: UIElementSchema2.optional(),
|
|
153
|
+
slots: z.record(z.string(), z.union([UIElementSchema2, z.array(UIElementSchema2)])).optional(),
|
|
154
|
+
platform: z.object({
|
|
155
|
+
web: z.any().optional(),
|
|
156
|
+
ios: z.any().optional(),
|
|
157
|
+
android: z.any().optional()
|
|
158
|
+
}).optional()
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
var UIComponentSchema2 = z.object({
|
|
162
|
+
id: z.string(),
|
|
163
|
+
name: z.string().optional(),
|
|
164
|
+
props: z.record(z.string(), z.any()).optional(),
|
|
165
|
+
states: z.record(z.string(), z.any()).optional(),
|
|
166
|
+
methods: z.record(
|
|
167
|
+
z.string(),
|
|
168
|
+
z.object({
|
|
169
|
+
fn: z.string(),
|
|
170
|
+
params: z.record(z.string(), z.any()).optional()
|
|
171
|
+
})
|
|
172
|
+
).optional(),
|
|
173
|
+
effects: z.array(
|
|
174
|
+
z.object({
|
|
175
|
+
fn: z.string(),
|
|
176
|
+
deps: z.array(z.string()).optional()
|
|
177
|
+
})
|
|
178
|
+
).optional(),
|
|
179
|
+
data: z.record(z.string(), z.any()).optional(),
|
|
180
|
+
render: UIElementSchema2,
|
|
181
|
+
query: QuerySpecSchema2.optional()
|
|
182
|
+
});
|
|
183
|
+
var DSLRendererPropsSchema2 = z.object({
|
|
184
|
+
dsl: UIComponentSchema2,
|
|
185
|
+
data: z.record(z.string(), z.any()).optional(),
|
|
186
|
+
context: z.record(z.string(), z.any()).optional()
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// src/schemas.ts
|
|
190
|
+
var MessageParticipantSchema = z.object({
|
|
191
|
+
id: z.string().optional(),
|
|
192
|
+
type: z.string().optional()
|
|
193
|
+
});
|
|
194
|
+
var MessageSchema = z.object({
|
|
195
|
+
id: z.string(),
|
|
196
|
+
type: z.string(),
|
|
197
|
+
from: MessageParticipantSchema,
|
|
198
|
+
to: MessageParticipantSchema.optional(),
|
|
199
|
+
payload: z.unknown()
|
|
200
|
+
});
|
|
201
|
+
var AuthLoginPayloadSchema = z.object({
|
|
202
|
+
login_data: z.string()
|
|
203
|
+
// Base64 encoded login data (username + SHA-1 hashed password)
|
|
204
|
+
});
|
|
205
|
+
var AuthLoginRequestMessageSchema = z.object({
|
|
206
|
+
id: z.string(),
|
|
207
|
+
type: z.literal("AUTH_LOGIN_REQ"),
|
|
208
|
+
from: MessageParticipantSchema,
|
|
209
|
+
to: MessageParticipantSchema.optional(),
|
|
210
|
+
payload: AuthLoginPayloadSchema
|
|
211
|
+
});
|
|
212
|
+
var AuthLoginResponsePayloadSchema = z.object({
|
|
213
|
+
success: z.boolean(),
|
|
214
|
+
error: z.string().optional(),
|
|
215
|
+
data: z.unknown().optional()
|
|
216
|
+
// User ID or additional auth data
|
|
217
|
+
});
|
|
218
|
+
var AuthLoginResponseMessageSchema = z.object({
|
|
219
|
+
id: z.string(),
|
|
220
|
+
type: z.literal("AUTH_LOGIN_RES"),
|
|
221
|
+
from: MessageParticipantSchema,
|
|
222
|
+
to: MessageParticipantSchema.optional(),
|
|
223
|
+
payload: AuthLoginResponsePayloadSchema
|
|
224
|
+
});
|
|
225
|
+
var AuthVerifyPayloadSchema = z.object({
|
|
226
|
+
token: z.string()
|
|
227
|
+
// Base64 encoded authentication token
|
|
228
|
+
});
|
|
229
|
+
var AuthVerifyRequestMessageSchema = z.object({
|
|
230
|
+
id: z.string(),
|
|
231
|
+
type: z.literal("AUTH_VERIFY_REQ"),
|
|
232
|
+
from: MessageParticipantSchema,
|
|
233
|
+
to: MessageParticipantSchema.optional(),
|
|
234
|
+
payload: AuthVerifyPayloadSchema
|
|
235
|
+
});
|
|
236
|
+
var AuthVerifyResponsePayloadSchema = z.object({
|
|
237
|
+
success: z.boolean(),
|
|
238
|
+
error: z.string().optional(),
|
|
239
|
+
data: z.unknown().optional()
|
|
240
|
+
});
|
|
241
|
+
var AuthVerifyResponseMessageSchema = z.object({
|
|
242
|
+
id: z.string(),
|
|
243
|
+
type: z.literal("AUTH_VERIFY_RES"),
|
|
244
|
+
from: MessageParticipantSchema,
|
|
245
|
+
to: MessageParticipantSchema.optional(),
|
|
246
|
+
payload: AuthVerifyResponsePayloadSchema
|
|
247
|
+
});
|
|
248
|
+
var UserPromptRequestPayloadSchema = z.object({
|
|
249
|
+
prompt: z.string(),
|
|
250
|
+
SA_RUNTIME: z.object({
|
|
251
|
+
threadId: z.string(),
|
|
252
|
+
uiBlockId: z.string()
|
|
253
|
+
}).optional()
|
|
254
|
+
});
|
|
255
|
+
var UserPromptRequestMessageSchema = z.object({
|
|
256
|
+
id: z.string(),
|
|
257
|
+
type: z.literal("USER_PROMPT_REQ"),
|
|
258
|
+
from: MessageParticipantSchema,
|
|
259
|
+
to: MessageParticipantSchema.optional(),
|
|
260
|
+
payload: UserPromptRequestPayloadSchema
|
|
261
|
+
});
|
|
262
|
+
var ComponentSchema = z.object({
|
|
263
|
+
id: z.string(),
|
|
264
|
+
name: z.string(),
|
|
265
|
+
type: z.string(),
|
|
266
|
+
description: z.string(),
|
|
267
|
+
props: z.object({
|
|
268
|
+
query: z.string().optional(),
|
|
269
|
+
title: z.string().optional(),
|
|
270
|
+
description: z.string().optional(),
|
|
271
|
+
config: z.record(z.string(), z.unknown()).optional()
|
|
272
|
+
}),
|
|
273
|
+
category: z.string().optional(),
|
|
274
|
+
keywords: z.array(z.string()).optional()
|
|
275
|
+
});
|
|
276
|
+
var UserPromptResponsePayloadSchema = z.object({
|
|
277
|
+
success: z.boolean(),
|
|
278
|
+
error: z.string().optional(),
|
|
279
|
+
data: z.object({
|
|
280
|
+
component: ComponentSchema.optional()
|
|
281
|
+
}).optional(),
|
|
282
|
+
uiBlockId: z.string().optional(),
|
|
283
|
+
threadId: z.string().optional()
|
|
284
|
+
});
|
|
285
|
+
var UserPromptResponseMessageSchema = z.object({
|
|
286
|
+
id: z.string(),
|
|
287
|
+
type: z.literal("USER_PROMPT_RES"),
|
|
288
|
+
from: MessageParticipantSchema,
|
|
289
|
+
to: MessageParticipantSchema.optional(),
|
|
290
|
+
payload: UserPromptResponsePayloadSchema
|
|
291
|
+
});
|
|
292
|
+
var UserPromptSuggestionsRequestPayloadSchema = z.object({
|
|
293
|
+
prompt: z.string(),
|
|
294
|
+
limit: z.number().int().positive().default(5)
|
|
295
|
+
});
|
|
296
|
+
var UserPromptSuggestionsRequestMessageSchema = z.object({
|
|
297
|
+
id: z.string(),
|
|
298
|
+
type: z.literal("USER_PROMPT_SUGGESTIONS_REQ"),
|
|
299
|
+
from: MessageParticipantSchema,
|
|
300
|
+
to: MessageParticipantSchema.optional(),
|
|
301
|
+
payload: UserPromptSuggestionsRequestPayloadSchema
|
|
302
|
+
});
|
|
303
|
+
var UserPromptSuggestionsResponsePayloadSchema = z.object({
|
|
304
|
+
success: z.boolean(),
|
|
305
|
+
error: z.string().optional(),
|
|
306
|
+
data: z.object({
|
|
307
|
+
prompt: z.string(),
|
|
308
|
+
suggestions: z.array(ComponentSchema),
|
|
309
|
+
count: z.number(),
|
|
310
|
+
message: z.string().optional()
|
|
311
|
+
}).optional()
|
|
312
|
+
});
|
|
313
|
+
var UserPromptSuggestionsResponseMessageSchema = z.object({
|
|
314
|
+
id: z.string(),
|
|
315
|
+
type: z.literal("USER_PROMPT_SUGGESTIONS_RES"),
|
|
316
|
+
from: MessageParticipantSchema,
|
|
317
|
+
to: MessageParticipantSchema.optional(),
|
|
318
|
+
payload: UserPromptSuggestionsResponsePayloadSchema
|
|
319
|
+
});
|
|
320
|
+
var BundleRequestPayloadSchema = z.object({});
|
|
321
|
+
var BundleRequestMessageSchema = z.object({
|
|
322
|
+
id: z.string(),
|
|
323
|
+
type: z.literal("BUNDLE_REQ"),
|
|
324
|
+
from: MessageParticipantSchema,
|
|
325
|
+
to: MessageParticipantSchema.optional(),
|
|
326
|
+
payload: BundleRequestPayloadSchema
|
|
327
|
+
});
|
|
328
|
+
var BundleChunkPayloadSchema = z.object({
|
|
329
|
+
chunk: z.string(),
|
|
330
|
+
chunkIndex: z.number(),
|
|
331
|
+
totalChunks: z.number(),
|
|
332
|
+
isComplete: z.boolean(),
|
|
333
|
+
progress: z.number()
|
|
334
|
+
});
|
|
335
|
+
var BundleChunkMessageSchema = z.object({
|
|
336
|
+
id: z.string(),
|
|
337
|
+
type: z.literal("BUNDLE_CHUNK"),
|
|
338
|
+
from: MessageParticipantSchema,
|
|
339
|
+
to: MessageParticipantSchema.optional(),
|
|
340
|
+
payload: BundleChunkPayloadSchema
|
|
341
|
+
});
|
|
342
|
+
var BundleErrorPayloadSchema = z.object({
|
|
343
|
+
error: z.string()
|
|
344
|
+
});
|
|
345
|
+
var BundleErrorMessageSchema = z.object({
|
|
346
|
+
id: z.string(),
|
|
347
|
+
type: z.literal("BUNDLE_RES"),
|
|
348
|
+
from: MessageParticipantSchema,
|
|
349
|
+
to: MessageParticipantSchema.optional(),
|
|
350
|
+
payload: BundleErrorPayloadSchema
|
|
351
|
+
});
|
|
352
|
+
var DataRequestPayloadSchema = z.object({
|
|
353
|
+
collection: z.string(),
|
|
354
|
+
op: z.string(),
|
|
355
|
+
params: z.record(z.string(), z.unknown()).optional(),
|
|
356
|
+
SA_RUNTIME: z.record(z.string(), z.unknown()).optional()
|
|
357
|
+
});
|
|
358
|
+
var DataRequestMessageSchema = z.object({
|
|
359
|
+
id: z.string(),
|
|
360
|
+
type: z.literal("DATA_REQ"),
|
|
361
|
+
from: MessageParticipantSchema,
|
|
362
|
+
to: MessageParticipantSchema.optional(),
|
|
363
|
+
payload: DataRequestPayloadSchema
|
|
364
|
+
});
|
|
365
|
+
var DataResponsePayloadSchema = z.object({
|
|
366
|
+
collection: z.string(),
|
|
367
|
+
op: z.string(),
|
|
368
|
+
data: z.unknown(),
|
|
369
|
+
executionMs: z.number().optional(),
|
|
370
|
+
error: z.string().optional()
|
|
371
|
+
});
|
|
372
|
+
var DataResponseMessageSchema = z.object({
|
|
373
|
+
id: z.string(),
|
|
374
|
+
type: z.literal("DATA_RES"),
|
|
375
|
+
from: MessageParticipantSchema,
|
|
376
|
+
to: MessageParticipantSchema.optional(),
|
|
377
|
+
payload: DataResponsePayloadSchema
|
|
378
|
+
});
|
|
379
|
+
var UILogEntrySchema = z.object({
|
|
380
|
+
timestamp: z.number(),
|
|
381
|
+
level: z.enum(["info", "error", "warn", "debug"]),
|
|
382
|
+
message: z.string(),
|
|
383
|
+
type: z.enum(["explanation", "query", "general"]).optional(),
|
|
384
|
+
data: z.record(z.string(), z.unknown()).optional()
|
|
385
|
+
});
|
|
386
|
+
var UILogsPayloadSchema = z.object({
|
|
387
|
+
logs: z.array(UILogEntrySchema)
|
|
388
|
+
});
|
|
389
|
+
var UILogsMessageSchema = z.object({
|
|
390
|
+
id: z.string(),
|
|
391
|
+
// uiBlockId
|
|
392
|
+
type: z.literal("UI_LOGS"),
|
|
393
|
+
from: MessageParticipantSchema,
|
|
394
|
+
to: MessageParticipantSchema.optional(),
|
|
395
|
+
payload: UILogsPayloadSchema
|
|
396
|
+
});
|
|
397
|
+
var UsersRequestPayloadSchema = z.object({
|
|
398
|
+
operation: z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
399
|
+
data: z.object({
|
|
400
|
+
username: z.string().optional(),
|
|
401
|
+
password: z.string().optional()
|
|
402
|
+
}).optional()
|
|
403
|
+
});
|
|
404
|
+
var UsersRequestMessageSchema = z.object({
|
|
405
|
+
id: z.string(),
|
|
406
|
+
type: z.literal("USERS"),
|
|
407
|
+
from: MessageParticipantSchema,
|
|
408
|
+
to: MessageParticipantSchema.optional(),
|
|
409
|
+
payload: UsersRequestPayloadSchema
|
|
410
|
+
});
|
|
411
|
+
var UsersResponsePayloadSchema = z.object({
|
|
412
|
+
success: z.boolean(),
|
|
413
|
+
error: z.string().optional(),
|
|
414
|
+
data: z.object({
|
|
415
|
+
username: z.string().optional(),
|
|
416
|
+
message: z.string().optional(),
|
|
417
|
+
users: z.array(z.object({
|
|
418
|
+
username: z.string(),
|
|
419
|
+
wsIds: z.array(z.string())
|
|
420
|
+
})).optional(),
|
|
421
|
+
user: z.object({
|
|
422
|
+
username: z.string(),
|
|
423
|
+
wsIds: z.array(z.string())
|
|
424
|
+
}).optional(),
|
|
425
|
+
count: z.number().optional()
|
|
426
|
+
}).optional()
|
|
427
|
+
});
|
|
428
|
+
z.object({
|
|
429
|
+
id: z.string(),
|
|
430
|
+
type: z.literal("USERS_RES"),
|
|
431
|
+
from: MessageParticipantSchema,
|
|
432
|
+
to: MessageParticipantSchema.optional(),
|
|
433
|
+
payload: UsersResponsePayloadSchema
|
|
434
|
+
});
|
|
435
|
+
var DashboardsRequestPayloadSchema = z.object({
|
|
436
|
+
operation: z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
437
|
+
data: z.object({
|
|
438
|
+
dashboardId: z.string().optional(),
|
|
439
|
+
dashboard: DSLRendererPropsSchema.optional()
|
|
440
|
+
}).optional()
|
|
441
|
+
});
|
|
442
|
+
var DashboardsRequestMessageSchema = z.object({
|
|
443
|
+
id: z.string(),
|
|
444
|
+
type: z.literal("DASHBOARDS"),
|
|
445
|
+
from: MessageParticipantSchema,
|
|
446
|
+
to: MessageParticipantSchema.optional(),
|
|
447
|
+
payload: DashboardsRequestPayloadSchema
|
|
448
|
+
});
|
|
449
|
+
var DashboardsResponsePayloadSchema = z.object({
|
|
450
|
+
success: z.boolean(),
|
|
451
|
+
error: z.string().optional(),
|
|
452
|
+
data: z.object({
|
|
453
|
+
dashboardId: z.string().optional(),
|
|
454
|
+
dashboard: DSLRendererPropsSchema.optional(),
|
|
455
|
+
dashboards: z.array(z.object({
|
|
456
|
+
dashboardId: z.string(),
|
|
457
|
+
dashboard: DSLRendererPropsSchema
|
|
458
|
+
})).optional(),
|
|
459
|
+
count: z.number().optional(),
|
|
460
|
+
message: z.string().optional()
|
|
461
|
+
}).optional()
|
|
462
|
+
});
|
|
463
|
+
z.object({
|
|
464
|
+
id: z.string(),
|
|
465
|
+
type: z.literal("DASHBOARDS_RES"),
|
|
466
|
+
from: MessageParticipantSchema,
|
|
467
|
+
to: MessageParticipantSchema.optional(),
|
|
468
|
+
payload: DashboardsResponsePayloadSchema
|
|
469
|
+
});
|
|
470
|
+
var ReportsRequestPayloadSchema = z.object({
|
|
471
|
+
operation: z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
472
|
+
data: z.object({
|
|
473
|
+
reportId: z.string().optional(),
|
|
474
|
+
report: DSLRendererPropsSchema2.optional()
|
|
475
|
+
}).optional()
|
|
476
|
+
});
|
|
477
|
+
var ReportsRequestMessageSchema = z.object({
|
|
478
|
+
id: z.string(),
|
|
479
|
+
type: z.literal("REPORTS"),
|
|
480
|
+
from: MessageParticipantSchema,
|
|
481
|
+
to: MessageParticipantSchema.optional(),
|
|
482
|
+
payload: ReportsRequestPayloadSchema
|
|
483
|
+
});
|
|
484
|
+
var ReportsResponsePayloadSchema = z.object({
|
|
485
|
+
success: z.boolean(),
|
|
486
|
+
error: z.string().optional(),
|
|
487
|
+
data: z.object({
|
|
488
|
+
reportId: z.string().optional(),
|
|
489
|
+
report: DSLRendererPropsSchema2.optional(),
|
|
490
|
+
reports: z.array(z.object({
|
|
491
|
+
reportId: z.string(),
|
|
492
|
+
report: DSLRendererPropsSchema2
|
|
493
|
+
})).optional(),
|
|
494
|
+
count: z.number().optional(),
|
|
495
|
+
message: z.string().optional()
|
|
496
|
+
}).optional()
|
|
497
|
+
});
|
|
498
|
+
z.object({
|
|
499
|
+
id: z.string(),
|
|
500
|
+
type: z.literal("REPORTS_RES"),
|
|
501
|
+
from: MessageParticipantSchema,
|
|
502
|
+
to: MessageParticipantSchema.optional(),
|
|
503
|
+
payload: ReportsResponsePayloadSchema
|
|
504
|
+
});
|
|
505
|
+
var ClientConfigSchema = z.object({
|
|
506
|
+
userId: z.string(),
|
|
507
|
+
projectId: z.string(),
|
|
508
|
+
baseUrl: z.string().default("wss://ws.superatom.ai/websocket"),
|
|
509
|
+
type: z.string().default("runtime"),
|
|
510
|
+
maxReconnectAttempts: z.number().min(0).default(Infinity),
|
|
511
|
+
initialReconnectDelay: z.number().min(0).default(1e3),
|
|
512
|
+
maxReconnectDelay: z.number().min(0).default(3e4),
|
|
513
|
+
defaultTimeout: z.number().min(0).default(3e4),
|
|
514
|
+
debug: z.boolean().default(false)
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
// src/services/index.ts
|
|
518
|
+
var services_exports = {};
|
|
519
|
+
__export(services_exports, {
|
|
520
|
+
BindingSchema: () => BindingSchema,
|
|
521
|
+
DSLRendererPropsSchema: () => DSLRendererPropsSchema,
|
|
522
|
+
ExpressionSchema: () => ExpressionSchema,
|
|
523
|
+
ForDirectiveSchema: () => ForDirectiveSchema,
|
|
524
|
+
QuerySpecSchema: () => QuerySpecSchema,
|
|
525
|
+
UIComponentSchema: () => UIComponentSchema,
|
|
526
|
+
UIElementSchema: () => UIElementSchema,
|
|
527
|
+
createDashboard: () => createDashboard,
|
|
528
|
+
createReport: () => createReport,
|
|
529
|
+
createUser: () => createUser,
|
|
530
|
+
deleteDashboard: () => deleteDashboard,
|
|
531
|
+
deleteReport: () => deleteReport,
|
|
532
|
+
deleteUser: () => deleteUser,
|
|
533
|
+
getAllDashboards: () => getAllDashboards,
|
|
534
|
+
getAllReports: () => getAllReports,
|
|
535
|
+
getAllUsers: () => getAllUsers,
|
|
536
|
+
getComponentSuggestions: () => getComponentSuggestions,
|
|
537
|
+
getDashboard: () => getDashboard,
|
|
538
|
+
getReport: () => getReport,
|
|
539
|
+
getUser: () => getUser,
|
|
540
|
+
requestBundle: () => requestBundle,
|
|
541
|
+
requestData: () => requestData,
|
|
542
|
+
sendAuthLoginRequest: () => sendAuthLoginRequest,
|
|
543
|
+
sendAuthVerifyRequest: () => sendAuthVerifyRequest,
|
|
544
|
+
sendUserPromptRequest: () => sendUserPromptRequest,
|
|
545
|
+
sendUserPromptSuggestionsRequest: () => sendUserPromptSuggestionsRequest,
|
|
546
|
+
updateDashboard: () => updateDashboard,
|
|
547
|
+
updateReport: () => updateReport,
|
|
548
|
+
updateUser: () => updateUser
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
// src/services/auth.ts
|
|
552
|
+
async function sendAuthLoginRequest(client, loginDataBase64, timeout) {
|
|
553
|
+
const messageId = `login_${Date.now()}`;
|
|
554
|
+
const message = AuthLoginRequestMessageSchema.parse({
|
|
555
|
+
id: messageId,
|
|
556
|
+
type: "AUTH_LOGIN_REQ",
|
|
557
|
+
from: {
|
|
558
|
+
type: "runtime"
|
|
559
|
+
},
|
|
560
|
+
to: {
|
|
561
|
+
type: "data-agent"
|
|
562
|
+
},
|
|
563
|
+
payload: {
|
|
564
|
+
login_data: loginDataBase64
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
568
|
+
return response;
|
|
569
|
+
}
|
|
570
|
+
async function sendAuthVerifyRequest(client, token, timeout) {
|
|
571
|
+
const messageId = `verify_${Date.now()}`;
|
|
572
|
+
const message = AuthVerifyRequestMessageSchema.parse({
|
|
573
|
+
id: messageId,
|
|
574
|
+
type: "AUTH_VERIFY_REQ",
|
|
575
|
+
from: {
|
|
576
|
+
type: "runtime"
|
|
577
|
+
},
|
|
578
|
+
to: {
|
|
579
|
+
type: "data-agent"
|
|
580
|
+
},
|
|
581
|
+
payload: {
|
|
582
|
+
token
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
586
|
+
return response;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/services/userPrompt.ts
|
|
590
|
+
async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeout) {
|
|
591
|
+
const messageId = `msg_${Date.now()}`;
|
|
592
|
+
const message = UserPromptRequestMessageSchema.parse({
|
|
593
|
+
id: messageId,
|
|
594
|
+
type: "USER_PROMPT_REQ",
|
|
595
|
+
from: {
|
|
596
|
+
type: "runtime"
|
|
597
|
+
},
|
|
598
|
+
to: {
|
|
599
|
+
type: "data-agent"
|
|
600
|
+
},
|
|
601
|
+
payload: {
|
|
602
|
+
prompt,
|
|
603
|
+
SA_RUNTIME: {
|
|
604
|
+
threadId,
|
|
605
|
+
uiBlockId
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
610
|
+
return response;
|
|
611
|
+
}
|
|
612
|
+
async function sendUserPromptSuggestionsRequest(client, prompt, limit = 5, timeout) {
|
|
613
|
+
if (!prompt || prompt.trim().length === 0) {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
const messageId = `suggestions_${Date.now()}`;
|
|
617
|
+
const message = UserPromptSuggestionsRequestMessageSchema.parse({
|
|
618
|
+
id: messageId,
|
|
619
|
+
type: "USER_PROMPT_SUGGESTIONS_REQ",
|
|
620
|
+
from: {
|
|
621
|
+
type: "runtime"
|
|
622
|
+
},
|
|
623
|
+
to: {
|
|
624
|
+
type: "data-agent"
|
|
625
|
+
},
|
|
626
|
+
payload: {
|
|
627
|
+
prompt,
|
|
628
|
+
limit
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
632
|
+
return response;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/services/bundle.ts
|
|
636
|
+
async function requestBundle(client, options) {
|
|
637
|
+
const messageId = `msg_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
638
|
+
const message = BundleRequestMessageSchema.parse({
|
|
639
|
+
id: messageId,
|
|
640
|
+
type: "BUNDLE_REQ",
|
|
641
|
+
from: { type: "runtime" },
|
|
642
|
+
to: { type: "data-agent" },
|
|
643
|
+
payload: {}
|
|
644
|
+
});
|
|
645
|
+
const chunks = [];
|
|
646
|
+
let totalChunks = 0;
|
|
647
|
+
const unsubscribe = client.onMessage((msg) => {
|
|
648
|
+
try {
|
|
649
|
+
if (msg.type === "BUNDLE_CHUNK" && msg.id?.startsWith(messageId)) {
|
|
650
|
+
const chunkMessage = BundleChunkMessageSchema.parse(msg);
|
|
651
|
+
const payload = chunkMessage.payload;
|
|
652
|
+
chunks[payload.chunkIndex] = payload.chunk;
|
|
653
|
+
totalChunks = payload.totalChunks;
|
|
654
|
+
if (options?.onProgress) {
|
|
655
|
+
options.onProgress(payload.progress);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
} catch (error) {
|
|
659
|
+
console.error("[SuperAtom] Failed to parse bundle chunk:", error);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
client.send(message);
|
|
663
|
+
const timeout = options?.timeout ?? 6e4;
|
|
664
|
+
const startTime = Date.now();
|
|
665
|
+
return new Promise((resolve, reject) => {
|
|
666
|
+
const checkInterval = setInterval(() => {
|
|
667
|
+
if (Date.now() - startTime > timeout) {
|
|
668
|
+
clearInterval(checkInterval);
|
|
669
|
+
unsubscribe();
|
|
670
|
+
reject(new Error(`Bundle request timeout after ${timeout}ms`));
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (totalChunks > 0 && chunks.length === totalChunks) {
|
|
674
|
+
clearInterval(checkInterval);
|
|
675
|
+
unsubscribe();
|
|
676
|
+
const bundle = chunks.join("");
|
|
677
|
+
resolve(bundle);
|
|
678
|
+
}
|
|
679
|
+
}, 100);
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// src/services/data.ts
|
|
684
|
+
async function requestData(client, options) {
|
|
685
|
+
const messageId = `msg_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
686
|
+
const message = DataRequestMessageSchema.parse({
|
|
687
|
+
id: messageId,
|
|
688
|
+
type: "DATA_REQ",
|
|
689
|
+
from: { type: "runtime" },
|
|
690
|
+
to: { type: "data-agent" },
|
|
691
|
+
payload: {
|
|
692
|
+
collection: options.collection,
|
|
693
|
+
op: options.operation,
|
|
694
|
+
params: options.params
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
const response = await client.sendWithResponse(message, options.timeout);
|
|
698
|
+
const payload = response.payload;
|
|
699
|
+
return {
|
|
700
|
+
data: payload.data,
|
|
701
|
+
error: payload.error,
|
|
702
|
+
executionMs: payload.executionMs
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// src/services/component.ts
|
|
707
|
+
async function getComponentSuggestions(client, query, options) {
|
|
708
|
+
const messageId = `msg_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
709
|
+
const message = {
|
|
710
|
+
id: messageId,
|
|
711
|
+
type: "USER_PROMPT_REQ",
|
|
712
|
+
to: { type: "data-agent" },
|
|
713
|
+
payload: {
|
|
714
|
+
prompt: query
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
const response = await client.sendWithResponse(message, options?.timeout);
|
|
718
|
+
const payload = response.payload;
|
|
719
|
+
return {
|
|
720
|
+
component: payload.component,
|
|
721
|
+
error: payload.error
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/services/users.ts
|
|
726
|
+
async function createUser(client, username, password, timeout) {
|
|
727
|
+
const messageId = `users_create_${Date.now()}`;
|
|
728
|
+
const message = UsersRequestMessageSchema.parse({
|
|
729
|
+
id: messageId,
|
|
730
|
+
type: "USERS",
|
|
731
|
+
from: { type: "admin" },
|
|
732
|
+
to: { type: "data-agent" },
|
|
733
|
+
payload: {
|
|
734
|
+
operation: "create",
|
|
735
|
+
data: {
|
|
736
|
+
username,
|
|
737
|
+
password
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
742
|
+
const payload = response.payload;
|
|
743
|
+
return {
|
|
744
|
+
success: payload.success,
|
|
745
|
+
error: payload.error,
|
|
746
|
+
message: payload.data?.message,
|
|
747
|
+
username: payload.data?.username
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
async function updateUser(client, username, password, timeout) {
|
|
751
|
+
const messageId = `users_update_${Date.now()}`;
|
|
752
|
+
const message = UsersRequestMessageSchema.parse({
|
|
753
|
+
id: messageId,
|
|
754
|
+
type: "USERS",
|
|
755
|
+
from: { type: "admin" },
|
|
756
|
+
to: { type: "data-agent" },
|
|
757
|
+
payload: {
|
|
758
|
+
operation: "update",
|
|
759
|
+
data: {
|
|
760
|
+
username,
|
|
761
|
+
password
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
766
|
+
const payload = response.payload;
|
|
767
|
+
return {
|
|
768
|
+
success: payload.success,
|
|
769
|
+
error: payload.error,
|
|
770
|
+
message: payload.data?.message,
|
|
771
|
+
username: payload.data?.username
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
async function deleteUser(client, username, timeout) {
|
|
775
|
+
const messageId = `users_delete_${Date.now()}`;
|
|
776
|
+
const message = UsersRequestMessageSchema.parse({
|
|
777
|
+
id: messageId,
|
|
778
|
+
type: "USERS",
|
|
779
|
+
from: { type: "admin" },
|
|
780
|
+
to: { type: "data-agent" },
|
|
781
|
+
payload: {
|
|
782
|
+
operation: "delete",
|
|
783
|
+
data: {
|
|
784
|
+
username
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
789
|
+
const payload = response.payload;
|
|
790
|
+
return {
|
|
791
|
+
success: payload.success,
|
|
792
|
+
error: payload.error,
|
|
793
|
+
message: payload.data?.message,
|
|
794
|
+
username: payload.data?.username
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
async function getAllUsers(client, timeout) {
|
|
798
|
+
const messageId = `users_getall_${Date.now()}`;
|
|
799
|
+
const message = UsersRequestMessageSchema.parse({
|
|
800
|
+
id: messageId,
|
|
801
|
+
type: "USERS",
|
|
802
|
+
from: { type: "admin" },
|
|
803
|
+
to: { type: "data-agent" },
|
|
804
|
+
payload: {
|
|
805
|
+
operation: "getAll"
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
809
|
+
const payload = response.payload;
|
|
810
|
+
return {
|
|
811
|
+
success: payload.success,
|
|
812
|
+
error: payload.error,
|
|
813
|
+
users: payload.data?.users,
|
|
814
|
+
count: payload.data?.count,
|
|
815
|
+
message: payload.data?.message
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
async function getUser(client, username, timeout) {
|
|
819
|
+
const messageId = `users_getone_${Date.now()}`;
|
|
820
|
+
const message = UsersRequestMessageSchema.parse({
|
|
821
|
+
id: messageId,
|
|
822
|
+
type: "USERS",
|
|
823
|
+
from: { type: "admin" },
|
|
824
|
+
to: { type: "data-agent" },
|
|
825
|
+
payload: {
|
|
826
|
+
operation: "getOne",
|
|
827
|
+
data: {
|
|
828
|
+
username
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
833
|
+
const payload = response.payload;
|
|
834
|
+
return {
|
|
835
|
+
success: payload.success,
|
|
836
|
+
error: payload.error,
|
|
837
|
+
user: payload.data?.user,
|
|
838
|
+
message: payload.data?.message
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/services/dashboards/index.ts
|
|
843
|
+
async function createDashboard(client, dashboardId, dashboard, timeout) {
|
|
844
|
+
const messageId = `dashboards_create_${Date.now()}`;
|
|
845
|
+
const message = DashboardsRequestMessageSchema.parse({
|
|
846
|
+
id: messageId,
|
|
847
|
+
type: "DASHBOARDS",
|
|
848
|
+
from: { type: "admin" },
|
|
849
|
+
to: { type: "data-agent" },
|
|
850
|
+
payload: {
|
|
851
|
+
operation: "create",
|
|
852
|
+
data: {
|
|
853
|
+
dashboardId,
|
|
854
|
+
dashboard
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
859
|
+
const payload = response.payload;
|
|
860
|
+
return {
|
|
861
|
+
success: payload.success,
|
|
862
|
+
error: payload.error,
|
|
863
|
+
message: payload.data?.message,
|
|
864
|
+
dashboardId: payload.data?.dashboardId,
|
|
865
|
+
dashboard: payload.data?.dashboard
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
async function updateDashboard(client, dashboardId, dashboard, timeout) {
|
|
869
|
+
const messageId = `dashboards_update_${Date.now()}`;
|
|
870
|
+
const message = DashboardsRequestMessageSchema.parse({
|
|
871
|
+
id: messageId,
|
|
872
|
+
type: "DASHBOARDS",
|
|
873
|
+
from: { type: "admin" },
|
|
874
|
+
to: { type: "data-agent" },
|
|
875
|
+
payload: {
|
|
876
|
+
operation: "update",
|
|
877
|
+
data: {
|
|
878
|
+
dashboardId,
|
|
879
|
+
dashboard
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
884
|
+
const payload = response.payload;
|
|
885
|
+
return {
|
|
886
|
+
success: payload.success,
|
|
887
|
+
error: payload.error,
|
|
888
|
+
message: payload.data?.message,
|
|
889
|
+
dashboardId: payload.data?.dashboardId,
|
|
890
|
+
dashboard: payload.data?.dashboard
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
async function deleteDashboard(client, dashboardId, timeout) {
|
|
894
|
+
const messageId = `dashboards_delete_${Date.now()}`;
|
|
895
|
+
const message = DashboardsRequestMessageSchema.parse({
|
|
896
|
+
id: messageId,
|
|
897
|
+
type: "DASHBOARDS",
|
|
898
|
+
from: { type: "admin" },
|
|
899
|
+
to: { type: "data-agent" },
|
|
900
|
+
payload: {
|
|
901
|
+
operation: "delete",
|
|
902
|
+
data: {
|
|
903
|
+
dashboardId
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
908
|
+
const payload = response.payload;
|
|
909
|
+
return {
|
|
910
|
+
success: payload.success,
|
|
911
|
+
error: payload.error,
|
|
912
|
+
message: payload.data?.message,
|
|
913
|
+
dashboardId: payload.data?.dashboardId
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
async function getAllDashboards(client, timeout) {
|
|
917
|
+
const messageId = `dashboards_getall_${Date.now()}`;
|
|
918
|
+
const message = DashboardsRequestMessageSchema.parse({
|
|
919
|
+
id: messageId,
|
|
920
|
+
type: "DASHBOARDS",
|
|
921
|
+
from: { type: "admin" },
|
|
922
|
+
to: { type: "data-agent" },
|
|
923
|
+
payload: {
|
|
924
|
+
operation: "getAll"
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
928
|
+
const payload = response.payload;
|
|
929
|
+
return {
|
|
930
|
+
success: payload.success,
|
|
931
|
+
error: payload.error,
|
|
932
|
+
dashboards: payload.data?.dashboards,
|
|
933
|
+
count: payload.data?.count,
|
|
934
|
+
message: payload.data?.message
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
async function getDashboard(client, dashboardId, timeout) {
|
|
938
|
+
const messageId = `dashboards_getone_${Date.now()}`;
|
|
939
|
+
const message = DashboardsRequestMessageSchema.parse({
|
|
940
|
+
id: messageId,
|
|
941
|
+
type: "DASHBOARDS",
|
|
942
|
+
from: { type: "admin" },
|
|
943
|
+
to: { type: "data-agent" },
|
|
944
|
+
payload: {
|
|
945
|
+
operation: "getOne",
|
|
946
|
+
data: {
|
|
947
|
+
dashboardId
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
952
|
+
const payload = response.payload;
|
|
953
|
+
return {
|
|
954
|
+
success: payload.success,
|
|
955
|
+
error: payload.error,
|
|
956
|
+
dashboardId: payload.data?.dashboardId,
|
|
957
|
+
dashboard: payload.data?.dashboard,
|
|
958
|
+
message: payload.data?.message
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/services/reports/index.ts
|
|
963
|
+
async function createReport(client, reportId, report, timeout) {
|
|
964
|
+
const messageId = `reports_create_${Date.now()}`;
|
|
965
|
+
const message = ReportsRequestMessageSchema.parse({
|
|
966
|
+
id: messageId,
|
|
967
|
+
type: "REPORTS",
|
|
968
|
+
from: { type: "admin" },
|
|
969
|
+
to: { type: "data-agent" },
|
|
970
|
+
payload: {
|
|
971
|
+
operation: "create",
|
|
972
|
+
data: {
|
|
973
|
+
reportId,
|
|
974
|
+
report
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
979
|
+
const payload = response.payload;
|
|
980
|
+
return {
|
|
981
|
+
success: payload.success,
|
|
982
|
+
error: payload.error,
|
|
983
|
+
message: payload.data?.message,
|
|
984
|
+
reportId: payload.data?.reportId,
|
|
985
|
+
report: payload.data?.report
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
async function updateReport(client, reportId, report, timeout) {
|
|
989
|
+
const messageId = `reports_update_${Date.now()}`;
|
|
990
|
+
const message = ReportsRequestMessageSchema.parse({
|
|
991
|
+
id: messageId,
|
|
992
|
+
type: "REPORTS",
|
|
993
|
+
from: { type: "admin" },
|
|
994
|
+
to: { type: "data-agent" },
|
|
995
|
+
payload: {
|
|
996
|
+
operation: "update",
|
|
997
|
+
data: {
|
|
998
|
+
reportId,
|
|
999
|
+
report
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
1004
|
+
const payload = response.payload;
|
|
1005
|
+
return {
|
|
1006
|
+
success: payload.success,
|
|
1007
|
+
error: payload.error,
|
|
1008
|
+
message: payload.data?.message,
|
|
1009
|
+
reportId: payload.data?.reportId,
|
|
1010
|
+
report: payload.data?.report
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
async function deleteReport(client, reportId, timeout) {
|
|
1014
|
+
const messageId = `reports_delete_${Date.now()}`;
|
|
1015
|
+
const message = ReportsRequestMessageSchema.parse({
|
|
1016
|
+
id: messageId,
|
|
1017
|
+
type: "REPORTS",
|
|
1018
|
+
from: { type: "admin" },
|
|
1019
|
+
to: { type: "data-agent" },
|
|
1020
|
+
payload: {
|
|
1021
|
+
operation: "delete",
|
|
1022
|
+
data: {
|
|
1023
|
+
reportId
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
1028
|
+
const payload = response.payload;
|
|
1029
|
+
return {
|
|
1030
|
+
success: payload.success,
|
|
1031
|
+
error: payload.error,
|
|
1032
|
+
message: payload.data?.message,
|
|
1033
|
+
reportId: payload.data?.reportId
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
async function getAllReports(client, timeout) {
|
|
1037
|
+
const messageId = `reports_getall_${Date.now()}`;
|
|
1038
|
+
const message = ReportsRequestMessageSchema.parse({
|
|
1039
|
+
id: messageId,
|
|
1040
|
+
type: "REPORTS",
|
|
1041
|
+
from: { type: "admin" },
|
|
1042
|
+
to: { type: "data-agent" },
|
|
1043
|
+
payload: {
|
|
1044
|
+
operation: "getAll"
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
1048
|
+
const payload = response.payload;
|
|
1049
|
+
return {
|
|
1050
|
+
success: payload.success,
|
|
1051
|
+
error: payload.error,
|
|
1052
|
+
reports: payload.data?.reports,
|
|
1053
|
+
count: payload.data?.count,
|
|
1054
|
+
message: payload.data?.message
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
async function getReport(client, reportId, timeout) {
|
|
1058
|
+
const messageId = `reports_getone_${Date.now()}`;
|
|
1059
|
+
const message = ReportsRequestMessageSchema.parse({
|
|
1060
|
+
id: messageId,
|
|
1061
|
+
type: "REPORTS",
|
|
1062
|
+
from: { type: "admin" },
|
|
1063
|
+
to: { type: "data-agent" },
|
|
1064
|
+
payload: {
|
|
1065
|
+
operation: "getOne",
|
|
1066
|
+
data: {
|
|
1067
|
+
reportId
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
const response = await client.sendWithResponse(message, timeout);
|
|
1072
|
+
const payload = response.payload;
|
|
1073
|
+
return {
|
|
1074
|
+
success: payload.success,
|
|
1075
|
+
error: payload.error,
|
|
1076
|
+
reportId: payload.data?.reportId,
|
|
1077
|
+
report: payload.data?.report,
|
|
1078
|
+
message: payload.data?.message
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// src/client.ts
|
|
1083
|
+
var SuperatomClient = class {
|
|
1084
|
+
constructor(config) {
|
|
1085
|
+
this.socket = null;
|
|
1086
|
+
this.reconnectAttempts = 0;
|
|
1087
|
+
this.reconnectTimer = null;
|
|
1088
|
+
this.shouldReconnect = true;
|
|
1089
|
+
this.messageHandlers = /* @__PURE__ */ new Set();
|
|
1090
|
+
this.connectionHandlers = /* @__PURE__ */ new Set();
|
|
1091
|
+
this.disconnectionHandlers = /* @__PURE__ */ new Set();
|
|
1092
|
+
this.errorHandlers = /* @__PURE__ */ new Set();
|
|
1093
|
+
this.connectPromise = null;
|
|
1094
|
+
this.connectResolve = null;
|
|
1095
|
+
const parsed = ClientConfigSchema.parse(config);
|
|
1096
|
+
this.config = parsed;
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Get WebSocket URL with query parameters
|
|
1100
|
+
*/
|
|
1101
|
+
getWebSocketUrl() {
|
|
1102
|
+
const params = new URLSearchParams({
|
|
1103
|
+
userId: this.config.userId,
|
|
1104
|
+
projectId: this.config.projectId,
|
|
1105
|
+
type: this.config.type
|
|
1106
|
+
});
|
|
1107
|
+
return `${this.config.baseUrl}?${params.toString()}`;
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Calculate reconnection delay with exponential backoff
|
|
1111
|
+
*/
|
|
1112
|
+
calculateReconnectDelay() {
|
|
1113
|
+
const delay = Math.min(
|
|
1114
|
+
this.config.initialReconnectDelay * Math.pow(2, this.reconnectAttempts),
|
|
1115
|
+
this.config.maxReconnectDelay
|
|
1116
|
+
);
|
|
1117
|
+
return delay + Math.random() * 1e3;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Schedule reconnection attempt
|
|
1121
|
+
*/
|
|
1122
|
+
scheduleReconnect() {
|
|
1123
|
+
if (!this.shouldReconnect) {
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
|
|
1127
|
+
const error = new Error("Max reconnection attempts reached");
|
|
1128
|
+
this.log("error", error.message);
|
|
1129
|
+
this.errorHandlers.forEach((handler) => handler(error));
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
const delay = this.calculateReconnectDelay();
|
|
1133
|
+
this.log("info", `Scheduling reconnection attempt ${this.reconnectAttempts + 1} in ${delay}ms`);
|
|
1134
|
+
this.reconnectTimer = setTimeout(() => {
|
|
1135
|
+
this.reconnectAttempts++;
|
|
1136
|
+
this.connect();
|
|
1137
|
+
}, delay);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Setup WebSocket event handlers
|
|
1141
|
+
*/
|
|
1142
|
+
setupSocketHandlers() {
|
|
1143
|
+
if (!this.socket) {
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
this.socket.onopen = () => {
|
|
1147
|
+
this.log("info", "Connected to SuperAtom");
|
|
1148
|
+
this.reconnectAttempts = 0;
|
|
1149
|
+
if (this.connectResolve) {
|
|
1150
|
+
this.connectResolve();
|
|
1151
|
+
this.connectResolve = null;
|
|
1152
|
+
}
|
|
1153
|
+
this.connectionHandlers.forEach((handler) => handler());
|
|
1154
|
+
};
|
|
1155
|
+
this.socket.onmessage = (event) => {
|
|
1156
|
+
try {
|
|
1157
|
+
const parsed = JSON.parse(event.data);
|
|
1158
|
+
const message = MessageSchema.parse(parsed);
|
|
1159
|
+
this.messageHandlers.forEach((handler) => handler(message));
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
this.log("error", "Failed to parse message:", error);
|
|
1162
|
+
const err = error instanceof Error ? error : new Error("Parse error");
|
|
1163
|
+
this.errorHandlers.forEach((handler) => handler(err));
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
this.socket.onclose = (event) => {
|
|
1167
|
+
this.log("info", "Disconnected from SuperAtom", {
|
|
1168
|
+
code: event.code,
|
|
1169
|
+
reason: event.reason,
|
|
1170
|
+
wasClean: event.wasClean
|
|
1171
|
+
});
|
|
1172
|
+
this.disconnectionHandlers.forEach((handler) => handler());
|
|
1173
|
+
if (this.shouldReconnect && !event.wasClean) {
|
|
1174
|
+
this.scheduleReconnect();
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
this.socket.onerror = (error) => {
|
|
1178
|
+
this.log("error", "WebSocket error:", error);
|
|
1179
|
+
this.errorHandlers.forEach((handler) => handler(error));
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Connect to SuperAtom WebSocket server
|
|
1184
|
+
* Returns a Promise that resolves when the connection is established
|
|
1185
|
+
* The Promise never rejects - failures are logged silently and auto-reconnect is triggered
|
|
1186
|
+
*/
|
|
1187
|
+
connect() {
|
|
1188
|
+
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
1189
|
+
this.log("warn", "Already connected");
|
|
1190
|
+
return Promise.resolve();
|
|
1191
|
+
}
|
|
1192
|
+
if (this.socket?.readyState === WebSocket.CONNECTING && this.connectPromise) {
|
|
1193
|
+
this.log("warn", "Connection already in progress");
|
|
1194
|
+
return this.connectPromise;
|
|
1195
|
+
}
|
|
1196
|
+
this.connectPromise = new Promise((resolve) => {
|
|
1197
|
+
this.connectResolve = resolve;
|
|
1198
|
+
});
|
|
1199
|
+
try {
|
|
1200
|
+
this.socket = new WebSocket(this.getWebSocketUrl());
|
|
1201
|
+
this.setupSocketHandlers();
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
this.log("error", "Failed to create WebSocket:", error);
|
|
1204
|
+
const err = error instanceof Error ? error : new Error("Connection failed");
|
|
1205
|
+
this.errorHandlers.forEach((handler) => handler(err));
|
|
1206
|
+
this.scheduleReconnect();
|
|
1207
|
+
}
|
|
1208
|
+
return this.connectPromise;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Disconnect from WebSocket server
|
|
1212
|
+
*/
|
|
1213
|
+
disconnect() {
|
|
1214
|
+
this.shouldReconnect = false;
|
|
1215
|
+
if (this.reconnectTimer) {
|
|
1216
|
+
clearTimeout(this.reconnectTimer);
|
|
1217
|
+
this.reconnectTimer = null;
|
|
1218
|
+
}
|
|
1219
|
+
if (this.socket) {
|
|
1220
|
+
this.socket.close(1e3, "Client disconnect");
|
|
1221
|
+
this.socket = null;
|
|
1222
|
+
}
|
|
1223
|
+
this.reconnectAttempts = 0;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Update client configuration
|
|
1227
|
+
*/
|
|
1228
|
+
updateConfig(config) {
|
|
1229
|
+
const merged = { ...this.config, ...config };
|
|
1230
|
+
const parsed = ClientConfigSchema.parse(merged);
|
|
1231
|
+
this.config = parsed;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Reconnect with new configuration
|
|
1235
|
+
* Disconnects from existing connection and reconnects with updated config
|
|
1236
|
+
* Returns a Promise that resolves when the new connection is established
|
|
1237
|
+
*/
|
|
1238
|
+
reconnectWithConfig(config) {
|
|
1239
|
+
this.updateConfig(config);
|
|
1240
|
+
if (this.socket) {
|
|
1241
|
+
this.disconnect();
|
|
1242
|
+
}
|
|
1243
|
+
this.shouldReconnect = true;
|
|
1244
|
+
return this.connect();
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Send a message to the server
|
|
1248
|
+
*/
|
|
1249
|
+
send(message) {
|
|
1250
|
+
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
1251
|
+
throw new Error("WebSocket is not connected");
|
|
1252
|
+
}
|
|
1253
|
+
const fullMessage = {
|
|
1254
|
+
...message,
|
|
1255
|
+
from: message.from || { type: "runtime" }
|
|
1256
|
+
};
|
|
1257
|
+
try {
|
|
1258
|
+
this.socket.send(JSON.stringify(fullMessage));
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
this.log("error", "Failed to send message:", error);
|
|
1261
|
+
throw error;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Send a message and wait for a response with the same ID
|
|
1266
|
+
* Uses closure-based approach - no global state management needed
|
|
1267
|
+
*/
|
|
1268
|
+
async sendWithResponse(message, timeout) {
|
|
1269
|
+
const messageId = message.id || `msg_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
1270
|
+
const messageWithId = { ...message, id: messageId };
|
|
1271
|
+
const timeoutMs = timeout ?? this.config.defaultTimeout;
|
|
1272
|
+
this.send(messageWithId);
|
|
1273
|
+
return new Promise((resolve, reject) => {
|
|
1274
|
+
let isResolved = false;
|
|
1275
|
+
const responseHandler = (msg) => {
|
|
1276
|
+
if (msg.id === messageId && !isResolved) {
|
|
1277
|
+
isResolved = true;
|
|
1278
|
+
clearTimeout(timer);
|
|
1279
|
+
unsubscribe();
|
|
1280
|
+
resolve(msg);
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
const unsubscribe = this.onMessage(responseHandler);
|
|
1284
|
+
const timer = setTimeout(() => {
|
|
1285
|
+
if (!isResolved) {
|
|
1286
|
+
isResolved = true;
|
|
1287
|
+
unsubscribe();
|
|
1288
|
+
reject(new Error(`Request timeout after ${timeoutMs}ms`));
|
|
1289
|
+
}
|
|
1290
|
+
}, timeoutMs);
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Register message handler
|
|
1295
|
+
*/
|
|
1296
|
+
onMessage(handler) {
|
|
1297
|
+
this.messageHandlers.add(handler);
|
|
1298
|
+
return () => this.messageHandlers.delete(handler);
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Register connection handler
|
|
1302
|
+
*/
|
|
1303
|
+
onConnect(handler) {
|
|
1304
|
+
this.connectionHandlers.add(handler);
|
|
1305
|
+
return () => this.connectionHandlers.delete(handler);
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Register disconnection handler
|
|
1309
|
+
*/
|
|
1310
|
+
onDisconnect(handler) {
|
|
1311
|
+
this.disconnectionHandlers.add(handler);
|
|
1312
|
+
return () => this.disconnectionHandlers.delete(handler);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Register error handler
|
|
1316
|
+
*/
|
|
1317
|
+
onError(handler) {
|
|
1318
|
+
this.errorHandlers.add(handler);
|
|
1319
|
+
return () => this.errorHandlers.delete(handler);
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Check if client is connected
|
|
1323
|
+
*/
|
|
1324
|
+
isConnected() {
|
|
1325
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Get current reconnection attempts
|
|
1329
|
+
*/
|
|
1330
|
+
getReconnectAttempts() {
|
|
1331
|
+
return this.reconnectAttempts;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Send a message and wait for response with timeout (alias for sendWithResponse)
|
|
1335
|
+
*/
|
|
1336
|
+
async ask(message, options) {
|
|
1337
|
+
return this.sendWithResponse(message, options?.timeout);
|
|
1338
|
+
}
|
|
1339
|
+
// ==================== Service Methods ====================
|
|
1340
|
+
// These methods delegate to service functions for better code organization
|
|
1341
|
+
/**
|
|
1342
|
+
* Send authentication login request
|
|
1343
|
+
* Delegates to auth service
|
|
1344
|
+
*/
|
|
1345
|
+
async sendAuthLoginRequest(loginDataBase64, timeout) {
|
|
1346
|
+
this.log("info", "Sending auth login request");
|
|
1347
|
+
return sendAuthLoginRequest(this, loginDataBase64, timeout);
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Send authentication verify request
|
|
1351
|
+
* Delegates to auth service
|
|
1352
|
+
*/
|
|
1353
|
+
async sendAuthVerifyRequest(token, timeout) {
|
|
1354
|
+
this.log("info", "Sending auth verify request");
|
|
1355
|
+
return sendAuthVerifyRequest(this, token, timeout);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Send a user prompt request
|
|
1359
|
+
* Delegates to user prompt service
|
|
1360
|
+
*/
|
|
1361
|
+
async sendUserPromptRequest(prompt, threadId, uiBlockId, timeout) {
|
|
1362
|
+
this.log("info", "Sending user prompt request");
|
|
1363
|
+
return sendUserPromptRequest(this, prompt, threadId, uiBlockId, timeout);
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Send a user prompt suggestions request
|
|
1367
|
+
* Delegates to user prompt service
|
|
1368
|
+
*/
|
|
1369
|
+
async sendUserPromptSuggestionsRequest(prompt, limit = 5, timeout) {
|
|
1370
|
+
this.log("info", "Sending user prompt suggestions request");
|
|
1371
|
+
return sendUserPromptSuggestionsRequest(this, prompt, limit, timeout);
|
|
1372
|
+
}
|
|
1373
|
+
/**
|
|
1374
|
+
* Request bundle from server
|
|
1375
|
+
* Delegates to bundle service
|
|
1376
|
+
*/
|
|
1377
|
+
async requestBundle(options) {
|
|
1378
|
+
this.log("info", "Requesting bundle from server");
|
|
1379
|
+
return requestBundle(this, options);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Request data from a collection
|
|
1383
|
+
* Delegates to data service
|
|
1384
|
+
*/
|
|
1385
|
+
async requestData(options) {
|
|
1386
|
+
this.log("info", `Requesting data from collection: ${options.collection}, operation: ${options.operation}`);
|
|
1387
|
+
return requestData(this, options);
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Get AI-powered component suggestions based on a query
|
|
1391
|
+
* Delegates to component service
|
|
1392
|
+
*/
|
|
1393
|
+
async getComponentSuggestions(query, options) {
|
|
1394
|
+
this.log("info", "Requesting component suggestions for query:", query);
|
|
1395
|
+
return getComponentSuggestions(this, query, options);
|
|
1396
|
+
}
|
|
1397
|
+
// ==================== User Management Methods ====================
|
|
1398
|
+
// These methods delegate to user service for admin user CRUD operations
|
|
1399
|
+
/**
|
|
1400
|
+
* Create a new user
|
|
1401
|
+
* Delegates to users service
|
|
1402
|
+
*/
|
|
1403
|
+
async createUser(username, password, timeout) {
|
|
1404
|
+
this.log("info", "Creating user:", username);
|
|
1405
|
+
return createUser(this, username, password, timeout);
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Update an existing user
|
|
1409
|
+
* Delegates to users service
|
|
1410
|
+
*/
|
|
1411
|
+
async updateUser(username, password, timeout) {
|
|
1412
|
+
this.log("info", "Updating user:", username);
|
|
1413
|
+
return updateUser(this, username, password, timeout);
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Delete a user
|
|
1417
|
+
* Delegates to users service
|
|
1418
|
+
*/
|
|
1419
|
+
async deleteUser(username, timeout) {
|
|
1420
|
+
this.log("info", "Deleting user:", username);
|
|
1421
|
+
return deleteUser(this, username, timeout);
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Get all users
|
|
1425
|
+
* Delegates to users service
|
|
1426
|
+
*/
|
|
1427
|
+
async getAllUsers(timeout) {
|
|
1428
|
+
this.log("info", "Fetching all users");
|
|
1429
|
+
return getAllUsers(this, timeout);
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Get a specific user by username
|
|
1433
|
+
* Delegates to users service
|
|
1434
|
+
*/
|
|
1435
|
+
async getUser(username, timeout) {
|
|
1436
|
+
this.log("info", "Fetching user:", username);
|
|
1437
|
+
return getUser(this, username, timeout);
|
|
1438
|
+
}
|
|
1439
|
+
// ==================== Dashboard Management Methods ====================
|
|
1440
|
+
// These methods delegate to dashboard service for admin dashboard CRUD operations
|
|
1441
|
+
/**
|
|
1442
|
+
* Create a new dashboard
|
|
1443
|
+
* Delegates to dashboards service
|
|
1444
|
+
*/
|
|
1445
|
+
async createDashboard(dashboardId, dashboard, timeout) {
|
|
1446
|
+
this.log("info", "Creating dashboard:", dashboardId);
|
|
1447
|
+
return createDashboard(this, dashboardId, dashboard, timeout);
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Update an existing dashboard
|
|
1451
|
+
* Delegates to dashboards service
|
|
1452
|
+
*/
|
|
1453
|
+
async updateDashboard(dashboardId, dashboard, timeout) {
|
|
1454
|
+
this.log("info", "Updating dashboard:", dashboardId);
|
|
1455
|
+
return updateDashboard(this, dashboardId, dashboard, timeout);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Delete a dashboard
|
|
1459
|
+
* Delegates to dashboards service
|
|
1460
|
+
*/
|
|
1461
|
+
async deleteDashboard(dashboardId, timeout) {
|
|
1462
|
+
this.log("info", "Deleting dashboard:", dashboardId);
|
|
1463
|
+
return deleteDashboard(this, dashboardId, timeout);
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Get all dashboards
|
|
1467
|
+
* Delegates to dashboards service
|
|
1468
|
+
*/
|
|
1469
|
+
async getAllDashboards(timeout) {
|
|
1470
|
+
this.log("info", "Fetching all dashboards");
|
|
1471
|
+
return getAllDashboards(this, timeout);
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Get a specific dashboard by ID
|
|
1475
|
+
* Delegates to dashboards service
|
|
1476
|
+
*/
|
|
1477
|
+
async getDashboard(dashboardId, timeout) {
|
|
1478
|
+
this.log("info", "Fetching dashboard:", dashboardId);
|
|
1479
|
+
return getDashboard(this, dashboardId, timeout);
|
|
1480
|
+
}
|
|
1481
|
+
// ==================== Report Management Methods ====================
|
|
1482
|
+
// These methods delegate to report service for admin report CRUD operations
|
|
1483
|
+
/**
|
|
1484
|
+
* Create a new report
|
|
1485
|
+
* Delegates to reports service
|
|
1486
|
+
*/
|
|
1487
|
+
async createReport(reportId, report, timeout) {
|
|
1488
|
+
this.log("info", "Creating report:", reportId);
|
|
1489
|
+
return createReport(this, reportId, report, timeout);
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Update an existing report
|
|
1493
|
+
* Delegates to reports service
|
|
1494
|
+
*/
|
|
1495
|
+
async updateReport(reportId, report, timeout) {
|
|
1496
|
+
this.log("info", "Updating report:", reportId);
|
|
1497
|
+
return updateReport(this, reportId, report, timeout);
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Delete a report
|
|
1501
|
+
* Delegates to reports service
|
|
1502
|
+
*/
|
|
1503
|
+
async deleteReport(reportId, timeout) {
|
|
1504
|
+
this.log("info", "Deleting report:", reportId);
|
|
1505
|
+
return deleteReport(this, reportId, timeout);
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Get all reports
|
|
1509
|
+
* Delegates to reports service
|
|
1510
|
+
*/
|
|
1511
|
+
async getAllReports(timeout) {
|
|
1512
|
+
this.log("info", "Fetching all reports");
|
|
1513
|
+
return getAllReports(this, timeout);
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Get a specific report by ID
|
|
1517
|
+
* Delegates to reports service
|
|
1518
|
+
*/
|
|
1519
|
+
async getReport(reportId, timeout) {
|
|
1520
|
+
this.log("info", "Fetching report:", reportId);
|
|
1521
|
+
return getReport(this, reportId, timeout);
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Internal logging
|
|
1525
|
+
*/
|
|
1526
|
+
log(level, ...args) {
|
|
1527
|
+
if (!this.config.debug && level === "debug") {
|
|
1528
|
+
return;
|
|
1529
|
+
}
|
|
1530
|
+
console[level]("[SuperAtom]", ...args);
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1534
|
+
// src/setup.ts
|
|
1535
|
+
function setup(components) {
|
|
1536
|
+
if (typeof window === "undefined") {
|
|
1537
|
+
throw new Error("setup() can only be called in a browser environment");
|
|
1538
|
+
}
|
|
1539
|
+
window.SUPERATOM = window.SUPERATOM || {};
|
|
1540
|
+
window.SA = window.SUPERATOM;
|
|
1541
|
+
window.SUPERATOM.COMPONENTS = components;
|
|
1542
|
+
if (window.SUPERATOM.runtime?.componentsLoaded) {
|
|
1543
|
+
window.SUPERATOM.runtime.componentsLoaded();
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
function getComponents() {
|
|
1547
|
+
if (typeof window === "undefined") {
|
|
1548
|
+
return void 0;
|
|
1549
|
+
}
|
|
1550
|
+
return window.SUPERATOM?.COMPONENTS;
|
|
1551
|
+
}
|
|
1552
|
+
function getComponent(name) {
|
|
1553
|
+
if (typeof window === "undefined") {
|
|
1554
|
+
return void 0;
|
|
1555
|
+
}
|
|
1556
|
+
return window.SUPERATOM?.COMPONENTS?.[name];
|
|
1557
|
+
}
|
|
1558
|
+
function hasComponents() {
|
|
1559
|
+
if (typeof window === "undefined") {
|
|
1560
|
+
return false;
|
|
1561
|
+
}
|
|
1562
|
+
return !!window.SUPERATOM?.COMPONENTS;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// src/index.ts
|
|
1566
|
+
var SDK_VERSION = "0.1.0";
|
|
1567
|
+
|
|
1568
|
+
export { AuthLoginPayloadSchema, AuthLoginRequestMessageSchema, AuthLoginResponseMessageSchema, AuthLoginResponsePayloadSchema, AuthVerifyPayloadSchema, AuthVerifyRequestMessageSchema, AuthVerifyResponseMessageSchema, AuthVerifyResponsePayloadSchema, BundleChunkMessageSchema, BundleChunkPayloadSchema, BundleErrorMessageSchema, BundleErrorPayloadSchema, BundleRequestMessageSchema, BundleRequestPayloadSchema, ClientConfigSchema, ComponentSchema, DataRequestMessageSchema, DataRequestPayloadSchema, DataResponseMessageSchema, DataResponsePayloadSchema, MessageParticipantSchema, MessageSchema, SDK_VERSION, SuperatomClient, UILogEntrySchema, UILogsMessageSchema, UILogsPayloadSchema, UserPromptRequestMessageSchema, UserPromptRequestPayloadSchema, UserPromptResponseMessageSchema, UserPromptResponsePayloadSchema, UserPromptSuggestionsRequestMessageSchema, UserPromptSuggestionsRequestPayloadSchema, UserPromptSuggestionsResponseMessageSchema, UserPromptSuggestionsResponsePayloadSchema, getComponent, getComponents, hasComponents, services_exports as services, setup };
|
|
1569
|
+
//# sourceMappingURL=index.js.map
|
|
1570
|
+
//# sourceMappingURL=index.js.map
|