@brixel_ai/artifact-sdk 1.0.1 → 1.0.3
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 +8 -24
- package/dist/index.d.mts +13 -49
- package/dist/index.d.ts +13 -49
- package/dist/index.js +35 -117
- package/dist/index.mjs +34 -115
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -104,24 +104,6 @@ if (import.meta.env.DEV) {
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
### Mock Host for Testing
|
|
108
|
-
|
|
109
|
-
```tsx
|
|
110
|
-
import { createMockBrixelHost } from "@brixel_ai/artifact-sdk";
|
|
111
|
-
|
|
112
|
-
const host = createMockBrixelHost({
|
|
113
|
-
onComplete: (output) => console.debug("Completed:", output),
|
|
114
|
-
onCancel: (reason) => console.debug("Cancelled:", reason),
|
|
115
|
-
onResize: (height) => console.debug("Resize:", height),
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Send init
|
|
119
|
-
host.init({ title: "Test" });
|
|
120
|
-
|
|
121
|
-
// Later: cleanup
|
|
122
|
-
host.destroy();
|
|
123
|
-
```
|
|
124
|
-
|
|
125
107
|
## Render Modes
|
|
126
108
|
|
|
127
109
|
### Display Mode
|
|
@@ -175,26 +157,28 @@ interface BrixelContext {
|
|
|
175
157
|
## Executing Other UI Tasks
|
|
176
158
|
|
|
177
159
|
The SDK allows UI Tasks to execute other UI Tasks programmatically using the `executeTask` function.
|
|
160
|
+
On success, `executeTask` returns the action `result` directly. On failure, it returns an `ExecuteTaskError`.
|
|
178
161
|
|
|
179
162
|
### Basic Usage
|
|
180
163
|
|
|
181
164
|
```tsx
|
|
182
|
-
import { useBrixelArtifact } from "@brixel_ai/artifact-sdk";
|
|
165
|
+
import { isExecuteTaskError, useBrixelArtifact } from "@brixel_ai/artifact-sdk";
|
|
183
166
|
|
|
184
167
|
function MyUITask() {
|
|
185
168
|
const { executeTask } = useBrixelArtifact();
|
|
186
169
|
|
|
187
170
|
const handleExecuteTask = async () => {
|
|
188
|
-
const result = await executeTask({
|
|
171
|
+
const result = await executeTask<{ message: string }>({
|
|
189
172
|
taskId: "78c2482f-b47d-461c-9fd0-509476687be9",
|
|
190
173
|
inputs: { name: "value" },
|
|
191
174
|
});
|
|
192
175
|
|
|
193
|
-
if (result
|
|
194
|
-
console.
|
|
195
|
-
|
|
196
|
-
console.error("Error:", result.error);
|
|
176
|
+
if (isExecuteTaskError(result)) {
|
|
177
|
+
console.error("Error:", result);
|
|
178
|
+
return;
|
|
197
179
|
}
|
|
180
|
+
|
|
181
|
+
console.debug("Task executed:", result);
|
|
198
182
|
};
|
|
199
183
|
|
|
200
184
|
return <button onClick={handleExecuteTask}>Execute Task</button>;
|
package/dist/index.d.mts
CHANGED
|
@@ -241,17 +241,19 @@ interface ExecuteTaskParams {
|
|
|
241
241
|
apiBaseUrl?: string;
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* Error returned by executeTask when execution fails.
|
|
245
245
|
*/
|
|
246
|
-
interface
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
code: string;
|
|
251
|
-
message: string;
|
|
252
|
-
details?: unknown;
|
|
253
|
-
};
|
|
246
|
+
interface ExecuteTaskError {
|
|
247
|
+
code: string;
|
|
248
|
+
message: string;
|
|
249
|
+
details?: unknown;
|
|
254
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Return value from executeTask:
|
|
253
|
+
* - success: returns task result directly
|
|
254
|
+
* - failure: returns ExecuteTaskError
|
|
255
|
+
*/
|
|
256
|
+
type ExecuteTaskResponse<TOutput = unknown> = TOutput | ExecuteTaskError;
|
|
255
257
|
/**
|
|
256
258
|
* Parameters for uploading a file to Brixel
|
|
257
259
|
*/
|
|
@@ -347,6 +349,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
347
349
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
348
350
|
organizationId?: string;
|
|
349
351
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
352
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError;
|
|
350
353
|
|
|
351
354
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
352
355
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -373,10 +376,6 @@ declare function createGetFileContent(contextAuth?: {
|
|
|
373
376
|
*
|
|
374
377
|
* These utilities help simulate the Brixel host environment during development
|
|
375
378
|
*/
|
|
376
|
-
/**
|
|
377
|
-
* Default mock context for development
|
|
378
|
-
*/
|
|
379
|
-
declare const mockContext: BrixelContext;
|
|
380
379
|
/**
|
|
381
380
|
* Simulate the Brixel host sending an INIT message
|
|
382
381
|
*
|
|
@@ -413,40 +412,5 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
413
412
|
* ```
|
|
414
413
|
*/
|
|
415
414
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
416
|
-
/**
|
|
417
|
-
* Create a mock Brixel host for development
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```tsx
|
|
421
|
-
* const host = createMockBrixelHost({
|
|
422
|
-
* onComplete: (output) => console.debug("Completed:", output),
|
|
423
|
-
* onCancel: (reason) => console.debug("Cancelled:", reason),
|
|
424
|
-
* });
|
|
425
|
-
*
|
|
426
|
-
* // Send init
|
|
427
|
-
* host.init({ title: "Test" });
|
|
428
|
-
*
|
|
429
|
-
* // Cleanup
|
|
430
|
-
* host.destroy();
|
|
431
|
-
* ```
|
|
432
|
-
*/
|
|
433
|
-
declare function createMockBrixelHost<TInputs = unknown, TOutput = unknown>(options: {
|
|
434
|
-
onReady?: (version: string) => void;
|
|
435
|
-
onComplete?: (output: TOutput) => void;
|
|
436
|
-
onCancel?: (reason?: string) => void;
|
|
437
|
-
onResize?: (height: number | "auto") => void;
|
|
438
|
-
onLog?: (level: string, message: string, data?: unknown) => void;
|
|
439
|
-
onError?: (error: {
|
|
440
|
-
code: string;
|
|
441
|
-
message: string;
|
|
442
|
-
details?: unknown;
|
|
443
|
-
}) => void;
|
|
444
|
-
}): {
|
|
445
|
-
init(inputs: TInputs, runId?: string, renderMode?: RenderMode): void;
|
|
446
|
-
updateInputs(inputs: Partial<TInputs>): void;
|
|
447
|
-
destroy(): void;
|
|
448
|
-
updateTheme(theme: BrixelContext["theme"]): void;
|
|
449
|
-
updateLocale(locale: string): void;
|
|
450
|
-
};
|
|
451
415
|
|
|
452
|
-
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskParams, type ExecuteTaskResponse, type FileContentData, type GetFileContentParams, type GetFileContentResponse, type HostToIframeMessage, type IframeToHostMessage, type InitMessage, type InternalFileMimeType, type InternalFilePublicOut, type LogMessage, type ReadyMessage, type RenderMode, type ResizeMessage, type TaskStatus, type UpdateInputsMessage, type UpdateLocaleMessage, type UpdateThemeMessage, type UploadFileParams, type UploadFileResponse, type UseBrixelTaskOptions, type UseBrixelTaskResult, createExecuteTask, createGetFileContent,
|
|
416
|
+
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskError, type ExecuteTaskParams, type ExecuteTaskResponse, type FileContentData, type GetFileContentParams, type GetFileContentResponse, type HostToIframeMessage, type IframeToHostMessage, type InitMessage, type InternalFileMimeType, type InternalFilePublicOut, type LogMessage, type ReadyMessage, type RenderMode, type ResizeMessage, type TaskStatus, type UpdateInputsMessage, type UpdateLocaleMessage, type UpdateThemeMessage, type UploadFileParams, type UploadFileResponse, type UseBrixelTaskOptions, type UseBrixelTaskResult, createExecuteTask, createGetFileContent, createUploadFile, executeTask, getFileContent, isExecuteTaskError, listenToUITaskMessages, simulateBrixelInit, uploadFile, useBrixelArtifact };
|
package/dist/index.d.ts
CHANGED
|
@@ -241,17 +241,19 @@ interface ExecuteTaskParams {
|
|
|
241
241
|
apiBaseUrl?: string;
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* Error returned by executeTask when execution fails.
|
|
245
245
|
*/
|
|
246
|
-
interface
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
code: string;
|
|
251
|
-
message: string;
|
|
252
|
-
details?: unknown;
|
|
253
|
-
};
|
|
246
|
+
interface ExecuteTaskError {
|
|
247
|
+
code: string;
|
|
248
|
+
message: string;
|
|
249
|
+
details?: unknown;
|
|
254
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Return value from executeTask:
|
|
253
|
+
* - success: returns task result directly
|
|
254
|
+
* - failure: returns ExecuteTaskError
|
|
255
|
+
*/
|
|
256
|
+
type ExecuteTaskResponse<TOutput = unknown> = TOutput | ExecuteTaskError;
|
|
255
257
|
/**
|
|
256
258
|
* Parameters for uploading a file to Brixel
|
|
257
259
|
*/
|
|
@@ -347,6 +349,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
347
349
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
348
350
|
organizationId?: string;
|
|
349
351
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
352
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError;
|
|
350
353
|
|
|
351
354
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
352
355
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -373,10 +376,6 @@ declare function createGetFileContent(contextAuth?: {
|
|
|
373
376
|
*
|
|
374
377
|
* These utilities help simulate the Brixel host environment during development
|
|
375
378
|
*/
|
|
376
|
-
/**
|
|
377
|
-
* Default mock context for development
|
|
378
|
-
*/
|
|
379
|
-
declare const mockContext: BrixelContext;
|
|
380
379
|
/**
|
|
381
380
|
* Simulate the Brixel host sending an INIT message
|
|
382
381
|
*
|
|
@@ -413,40 +412,5 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
413
412
|
* ```
|
|
414
413
|
*/
|
|
415
414
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
416
|
-
/**
|
|
417
|
-
* Create a mock Brixel host for development
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```tsx
|
|
421
|
-
* const host = createMockBrixelHost({
|
|
422
|
-
* onComplete: (output) => console.debug("Completed:", output),
|
|
423
|
-
* onCancel: (reason) => console.debug("Cancelled:", reason),
|
|
424
|
-
* });
|
|
425
|
-
*
|
|
426
|
-
* // Send init
|
|
427
|
-
* host.init({ title: "Test" });
|
|
428
|
-
*
|
|
429
|
-
* // Cleanup
|
|
430
|
-
* host.destroy();
|
|
431
|
-
* ```
|
|
432
|
-
*/
|
|
433
|
-
declare function createMockBrixelHost<TInputs = unknown, TOutput = unknown>(options: {
|
|
434
|
-
onReady?: (version: string) => void;
|
|
435
|
-
onComplete?: (output: TOutput) => void;
|
|
436
|
-
onCancel?: (reason?: string) => void;
|
|
437
|
-
onResize?: (height: number | "auto") => void;
|
|
438
|
-
onLog?: (level: string, message: string, data?: unknown) => void;
|
|
439
|
-
onError?: (error: {
|
|
440
|
-
code: string;
|
|
441
|
-
message: string;
|
|
442
|
-
details?: unknown;
|
|
443
|
-
}) => void;
|
|
444
|
-
}): {
|
|
445
|
-
init(inputs: TInputs, runId?: string, renderMode?: RenderMode): void;
|
|
446
|
-
updateInputs(inputs: Partial<TInputs>): void;
|
|
447
|
-
destroy(): void;
|
|
448
|
-
updateTheme(theme: BrixelContext["theme"]): void;
|
|
449
|
-
updateLocale(locale: string): void;
|
|
450
|
-
};
|
|
451
415
|
|
|
452
|
-
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskParams, type ExecuteTaskResponse, type FileContentData, type GetFileContentParams, type GetFileContentResponse, type HostToIframeMessage, type IframeToHostMessage, type InitMessage, type InternalFileMimeType, type InternalFilePublicOut, type LogMessage, type ReadyMessage, type RenderMode, type ResizeMessage, type TaskStatus, type UpdateInputsMessage, type UpdateLocaleMessage, type UpdateThemeMessage, type UploadFileParams, type UploadFileResponse, type UseBrixelTaskOptions, type UseBrixelTaskResult, createExecuteTask, createGetFileContent,
|
|
416
|
+
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskError, type ExecuteTaskParams, type ExecuteTaskResponse, type FileContentData, type GetFileContentParams, type GetFileContentResponse, type HostToIframeMessage, type IframeToHostMessage, type InitMessage, type InternalFileMimeType, type InternalFilePublicOut, type LogMessage, type ReadyMessage, type RenderMode, type ResizeMessage, type TaskStatus, type UpdateInputsMessage, type UpdateLocaleMessage, type UpdateThemeMessage, type UploadFileParams, type UploadFileResponse, type UseBrixelTaskOptions, type UseBrixelTaskResult, createExecuteTask, createGetFileContent, createUploadFile, executeTask, getFileContent, isExecuteTaskError, listenToUITaskMessages, simulateBrixelInit, uploadFile, useBrixelArtifact };
|
package/dist/index.js
CHANGED
|
@@ -22,12 +22,11 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
createExecuteTask: () => createExecuteTask,
|
|
24
24
|
createGetFileContent: () => createGetFileContent,
|
|
25
|
-
createMockBrixelHost: () => createMockBrixelHost,
|
|
26
25
|
createUploadFile: () => createUploadFile,
|
|
27
26
|
executeTask: () => executeTask,
|
|
28
27
|
getFileContent: () => getFileContent,
|
|
28
|
+
isExecuteTaskError: () => isExecuteTaskError,
|
|
29
29
|
listenToUITaskMessages: () => listenToUITaskMessages,
|
|
30
|
-
mockContext: () => mockContext,
|
|
31
30
|
simulateBrixelInit: () => simulateBrixelInit,
|
|
32
31
|
uploadFile: () => uploadFile,
|
|
33
32
|
useBrixelArtifact: () => useBrixelArtifact
|
|
@@ -92,20 +91,14 @@ async function executeTask(params) {
|
|
|
92
91
|
try {
|
|
93
92
|
if (!organizationId) {
|
|
94
93
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
code: "MISSING_ORGANIZATION_ID",
|
|
98
|
-
message: "organizationId is required to execute a task"
|
|
99
|
-
}
|
|
94
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
95
|
+
message: "organizationId is required to execute a task"
|
|
100
96
|
};
|
|
101
97
|
}
|
|
102
98
|
if (!taskId) {
|
|
103
99
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
code: "MISSING_TASK_ID",
|
|
107
|
-
message: "taskId is required to execute a task"
|
|
108
|
-
}
|
|
100
|
+
code: "MISSING_TASK_ID",
|
|
101
|
+
message: "taskId is required to execute a task"
|
|
109
102
|
};
|
|
110
103
|
}
|
|
111
104
|
const headers = {
|
|
@@ -129,20 +122,19 @@ async function executeTask(params) {
|
|
|
129
122
|
);
|
|
130
123
|
const data = await parseJsonOrText(response);
|
|
131
124
|
if (!response.ok) {
|
|
132
|
-
return
|
|
133
|
-
success: false,
|
|
134
|
-
error: toHttpError(response, data)
|
|
135
|
-
};
|
|
125
|
+
return toHttpError(response, data);
|
|
136
126
|
}
|
|
137
|
-
|
|
138
|
-
success
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
if (isActionExecutePayload(data)) {
|
|
128
|
+
if (data.success === false) {
|
|
129
|
+
return toActionExecutionError(data);
|
|
130
|
+
}
|
|
131
|
+
if ("result" in data) {
|
|
132
|
+
return data.result;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return data ?? void 0;
|
|
141
136
|
} catch (error) {
|
|
142
|
-
return
|
|
143
|
-
success: false,
|
|
144
|
-
error: toNetworkError(error)
|
|
145
|
-
};
|
|
137
|
+
return toNetworkError(error);
|
|
146
138
|
}
|
|
147
139
|
}
|
|
148
140
|
function createExecuteTask(contextAuth) {
|
|
@@ -157,6 +149,23 @@ function createExecuteTask(contextAuth) {
|
|
|
157
149
|
});
|
|
158
150
|
};
|
|
159
151
|
}
|
|
152
|
+
function isRecord(value) {
|
|
153
|
+
return typeof value === "object" && value !== null;
|
|
154
|
+
}
|
|
155
|
+
function isActionExecutePayload(value) {
|
|
156
|
+
return isRecord(value) && ("result" in value || "success" in value || "error" in value);
|
|
157
|
+
}
|
|
158
|
+
function toActionExecutionError(payload) {
|
|
159
|
+
const message = typeof payload.error === "string" && payload.error.trim() ? payload.error : "Task execution failed";
|
|
160
|
+
return {
|
|
161
|
+
code: "TASK_EXECUTION_FAILED",
|
|
162
|
+
message,
|
|
163
|
+
details: payload
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function isExecuteTaskError(value) {
|
|
167
|
+
return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
|
|
168
|
+
}
|
|
160
169
|
|
|
161
170
|
// src/uploadFile.ts
|
|
162
171
|
async function uploadFile(params) {
|
|
@@ -524,15 +533,6 @@ function useBrixelArtifact(options = {}) {
|
|
|
524
533
|
}
|
|
525
534
|
|
|
526
535
|
// src/devTools.ts
|
|
527
|
-
var mockContext = {
|
|
528
|
-
runId: "dev-run-001",
|
|
529
|
-
stepId: "dev-step-001",
|
|
530
|
-
userId: "dev-user-001",
|
|
531
|
-
organizationId: "dev-org-001",
|
|
532
|
-
theme: "light",
|
|
533
|
-
locale: "en-US",
|
|
534
|
-
conversationId: "dev-conversation-001"
|
|
535
|
-
};
|
|
536
536
|
function simulateBrixelInit(inputs, options = {}) {
|
|
537
537
|
const { runId = "dev-run-001", renderMode = "interaction", context = {}, delay = 100 } = options;
|
|
538
538
|
const message = {
|
|
@@ -540,7 +540,7 @@ function simulateBrixelInit(inputs, options = {}) {
|
|
|
540
540
|
payload: {
|
|
541
541
|
runId,
|
|
542
542
|
inputs,
|
|
543
|
-
context: { ...
|
|
543
|
+
context: { ...context, runId },
|
|
544
544
|
renderMode
|
|
545
545
|
}
|
|
546
546
|
};
|
|
@@ -561,97 +561,15 @@ function listenToUITaskMessages(callback) {
|
|
|
561
561
|
window.removeEventListener("message", handleMessage);
|
|
562
562
|
};
|
|
563
563
|
}
|
|
564
|
-
function createMockBrixelHost(options) {
|
|
565
|
-
const { onReady, onComplete, onCancel, onResize, onLog, onError } = options;
|
|
566
|
-
let currentRunId = null;
|
|
567
|
-
const postMessage = (message) => window.postMessage(message, "*");
|
|
568
|
-
const getRunIdOrWarn = (action) => {
|
|
569
|
-
if (!currentRunId) {
|
|
570
|
-
console.warn(`[MockHost] Cannot ${action} - no active run`);
|
|
571
|
-
return null;
|
|
572
|
-
}
|
|
573
|
-
return currentRunId;
|
|
574
|
-
};
|
|
575
|
-
const handleMessage = (event) => {
|
|
576
|
-
const message = event.data;
|
|
577
|
-
if (!message || typeof message !== "object" || !message.type?.startsWith("BRIXEL_")) {
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
switch (message.type) {
|
|
581
|
-
case "BRIXEL_READY":
|
|
582
|
-
onReady?.(message.payload?.version);
|
|
583
|
-
break;
|
|
584
|
-
case "BRIXEL_COMPLETE":
|
|
585
|
-
onComplete?.(message.payload?.output);
|
|
586
|
-
break;
|
|
587
|
-
case "BRIXEL_CANCEL":
|
|
588
|
-
onCancel?.(message.payload?.reason);
|
|
589
|
-
break;
|
|
590
|
-
case "BRIXEL_RESIZE":
|
|
591
|
-
onResize?.(message.payload?.height);
|
|
592
|
-
break;
|
|
593
|
-
case "BRIXEL_LOG":
|
|
594
|
-
onLog?.(message.payload?.level, message.payload?.message, message.payload?.data);
|
|
595
|
-
break;
|
|
596
|
-
case "BRIXEL_ERROR":
|
|
597
|
-
onError?.(message.payload?.error);
|
|
598
|
-
break;
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
window.addEventListener("message", handleMessage);
|
|
602
|
-
return {
|
|
603
|
-
init(inputs, runId = "mock-run-001", renderMode = "interaction") {
|
|
604
|
-
currentRunId = runId;
|
|
605
|
-
postMessage({
|
|
606
|
-
type: "BRIXEL_INIT",
|
|
607
|
-
payload: {
|
|
608
|
-
runId,
|
|
609
|
-
inputs,
|
|
610
|
-
context: { ...mockContext, runId },
|
|
611
|
-
renderMode
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
},
|
|
615
|
-
updateInputs(inputs) {
|
|
616
|
-
const runId = getRunIdOrWarn("update inputs");
|
|
617
|
-
if (!runId) {
|
|
618
|
-
return;
|
|
619
|
-
}
|
|
620
|
-
postMessage({ type: "BRIXEL_UPDATE_INPUTS", payload: { runId, inputs } });
|
|
621
|
-
},
|
|
622
|
-
destroy() {
|
|
623
|
-
if (currentRunId) {
|
|
624
|
-
postMessage({ type: "BRIXEL_DESTROY", payload: { runId: currentRunId } });
|
|
625
|
-
}
|
|
626
|
-
window.removeEventListener("message", handleMessage);
|
|
627
|
-
currentRunId = null;
|
|
628
|
-
},
|
|
629
|
-
updateTheme(theme) {
|
|
630
|
-
const runId = getRunIdOrWarn("update theme");
|
|
631
|
-
if (!runId) {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
postMessage({ type: "BRIXEL_UPDATE_THEME", payload: { runId, theme } });
|
|
635
|
-
},
|
|
636
|
-
updateLocale(locale) {
|
|
637
|
-
const runId = getRunIdOrWarn("update locale");
|
|
638
|
-
if (!runId) {
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
postMessage({ type: "BRIXEL_UPDATE_LOCALE", payload: { runId, locale } });
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
564
|
// Annotate the CommonJS export names for ESM import in node:
|
|
646
565
|
0 && (module.exports = {
|
|
647
566
|
createExecuteTask,
|
|
648
567
|
createGetFileContent,
|
|
649
|
-
createMockBrixelHost,
|
|
650
568
|
createUploadFile,
|
|
651
569
|
executeTask,
|
|
652
570
|
getFileContent,
|
|
571
|
+
isExecuteTaskError,
|
|
653
572
|
listenToUITaskMessages,
|
|
654
|
-
mockContext,
|
|
655
573
|
simulateBrixelInit,
|
|
656
574
|
uploadFile,
|
|
657
575
|
useBrixelArtifact
|
package/dist/index.mjs
CHANGED
|
@@ -56,20 +56,14 @@ async function executeTask(params) {
|
|
|
56
56
|
try {
|
|
57
57
|
if (!organizationId) {
|
|
58
58
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
code: "MISSING_ORGANIZATION_ID",
|
|
62
|
-
message: "organizationId is required to execute a task"
|
|
63
|
-
}
|
|
59
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
60
|
+
message: "organizationId is required to execute a task"
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
63
|
if (!taskId) {
|
|
67
64
|
return {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
code: "MISSING_TASK_ID",
|
|
71
|
-
message: "taskId is required to execute a task"
|
|
72
|
-
}
|
|
65
|
+
code: "MISSING_TASK_ID",
|
|
66
|
+
message: "taskId is required to execute a task"
|
|
73
67
|
};
|
|
74
68
|
}
|
|
75
69
|
const headers = {
|
|
@@ -93,20 +87,19 @@ async function executeTask(params) {
|
|
|
93
87
|
);
|
|
94
88
|
const data = await parseJsonOrText(response);
|
|
95
89
|
if (!response.ok) {
|
|
96
|
-
return
|
|
97
|
-
success: false,
|
|
98
|
-
error: toHttpError(response, data)
|
|
99
|
-
};
|
|
90
|
+
return toHttpError(response, data);
|
|
100
91
|
}
|
|
101
|
-
|
|
102
|
-
success
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
if (isActionExecutePayload(data)) {
|
|
93
|
+
if (data.success === false) {
|
|
94
|
+
return toActionExecutionError(data);
|
|
95
|
+
}
|
|
96
|
+
if ("result" in data) {
|
|
97
|
+
return data.result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return data ?? void 0;
|
|
105
101
|
} catch (error) {
|
|
106
|
-
return
|
|
107
|
-
success: false,
|
|
108
|
-
error: toNetworkError(error)
|
|
109
|
-
};
|
|
102
|
+
return toNetworkError(error);
|
|
110
103
|
}
|
|
111
104
|
}
|
|
112
105
|
function createExecuteTask(contextAuth) {
|
|
@@ -121,6 +114,23 @@ function createExecuteTask(contextAuth) {
|
|
|
121
114
|
});
|
|
122
115
|
};
|
|
123
116
|
}
|
|
117
|
+
function isRecord(value) {
|
|
118
|
+
return typeof value === "object" && value !== null;
|
|
119
|
+
}
|
|
120
|
+
function isActionExecutePayload(value) {
|
|
121
|
+
return isRecord(value) && ("result" in value || "success" in value || "error" in value);
|
|
122
|
+
}
|
|
123
|
+
function toActionExecutionError(payload) {
|
|
124
|
+
const message = typeof payload.error === "string" && payload.error.trim() ? payload.error : "Task execution failed";
|
|
125
|
+
return {
|
|
126
|
+
code: "TASK_EXECUTION_FAILED",
|
|
127
|
+
message,
|
|
128
|
+
details: payload
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function isExecuteTaskError(value) {
|
|
132
|
+
return isRecord(value) && typeof value.code === "string" && typeof value.message === "string";
|
|
133
|
+
}
|
|
124
134
|
|
|
125
135
|
// src/uploadFile.ts
|
|
126
136
|
async function uploadFile(params) {
|
|
@@ -488,15 +498,6 @@ function useBrixelArtifact(options = {}) {
|
|
|
488
498
|
}
|
|
489
499
|
|
|
490
500
|
// src/devTools.ts
|
|
491
|
-
var mockContext = {
|
|
492
|
-
runId: "dev-run-001",
|
|
493
|
-
stepId: "dev-step-001",
|
|
494
|
-
userId: "dev-user-001",
|
|
495
|
-
organizationId: "dev-org-001",
|
|
496
|
-
theme: "light",
|
|
497
|
-
locale: "en-US",
|
|
498
|
-
conversationId: "dev-conversation-001"
|
|
499
|
-
};
|
|
500
501
|
function simulateBrixelInit(inputs, options = {}) {
|
|
501
502
|
const { runId = "dev-run-001", renderMode = "interaction", context = {}, delay = 100 } = options;
|
|
502
503
|
const message = {
|
|
@@ -504,7 +505,7 @@ function simulateBrixelInit(inputs, options = {}) {
|
|
|
504
505
|
payload: {
|
|
505
506
|
runId,
|
|
506
507
|
inputs,
|
|
507
|
-
context: { ...
|
|
508
|
+
context: { ...context, runId },
|
|
508
509
|
renderMode
|
|
509
510
|
}
|
|
510
511
|
};
|
|
@@ -525,96 +526,14 @@ function listenToUITaskMessages(callback) {
|
|
|
525
526
|
window.removeEventListener("message", handleMessage);
|
|
526
527
|
};
|
|
527
528
|
}
|
|
528
|
-
function createMockBrixelHost(options) {
|
|
529
|
-
const { onReady, onComplete, onCancel, onResize, onLog, onError } = options;
|
|
530
|
-
let currentRunId = null;
|
|
531
|
-
const postMessage = (message) => window.postMessage(message, "*");
|
|
532
|
-
const getRunIdOrWarn = (action) => {
|
|
533
|
-
if (!currentRunId) {
|
|
534
|
-
console.warn(`[MockHost] Cannot ${action} - no active run`);
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
return currentRunId;
|
|
538
|
-
};
|
|
539
|
-
const handleMessage = (event) => {
|
|
540
|
-
const message = event.data;
|
|
541
|
-
if (!message || typeof message !== "object" || !message.type?.startsWith("BRIXEL_")) {
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
switch (message.type) {
|
|
545
|
-
case "BRIXEL_READY":
|
|
546
|
-
onReady?.(message.payload?.version);
|
|
547
|
-
break;
|
|
548
|
-
case "BRIXEL_COMPLETE":
|
|
549
|
-
onComplete?.(message.payload?.output);
|
|
550
|
-
break;
|
|
551
|
-
case "BRIXEL_CANCEL":
|
|
552
|
-
onCancel?.(message.payload?.reason);
|
|
553
|
-
break;
|
|
554
|
-
case "BRIXEL_RESIZE":
|
|
555
|
-
onResize?.(message.payload?.height);
|
|
556
|
-
break;
|
|
557
|
-
case "BRIXEL_LOG":
|
|
558
|
-
onLog?.(message.payload?.level, message.payload?.message, message.payload?.data);
|
|
559
|
-
break;
|
|
560
|
-
case "BRIXEL_ERROR":
|
|
561
|
-
onError?.(message.payload?.error);
|
|
562
|
-
break;
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
window.addEventListener("message", handleMessage);
|
|
566
|
-
return {
|
|
567
|
-
init(inputs, runId = "mock-run-001", renderMode = "interaction") {
|
|
568
|
-
currentRunId = runId;
|
|
569
|
-
postMessage({
|
|
570
|
-
type: "BRIXEL_INIT",
|
|
571
|
-
payload: {
|
|
572
|
-
runId,
|
|
573
|
-
inputs,
|
|
574
|
-
context: { ...mockContext, runId },
|
|
575
|
-
renderMode
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
},
|
|
579
|
-
updateInputs(inputs) {
|
|
580
|
-
const runId = getRunIdOrWarn("update inputs");
|
|
581
|
-
if (!runId) {
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
postMessage({ type: "BRIXEL_UPDATE_INPUTS", payload: { runId, inputs } });
|
|
585
|
-
},
|
|
586
|
-
destroy() {
|
|
587
|
-
if (currentRunId) {
|
|
588
|
-
postMessage({ type: "BRIXEL_DESTROY", payload: { runId: currentRunId } });
|
|
589
|
-
}
|
|
590
|
-
window.removeEventListener("message", handleMessage);
|
|
591
|
-
currentRunId = null;
|
|
592
|
-
},
|
|
593
|
-
updateTheme(theme) {
|
|
594
|
-
const runId = getRunIdOrWarn("update theme");
|
|
595
|
-
if (!runId) {
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
postMessage({ type: "BRIXEL_UPDATE_THEME", payload: { runId, theme } });
|
|
599
|
-
},
|
|
600
|
-
updateLocale(locale) {
|
|
601
|
-
const runId = getRunIdOrWarn("update locale");
|
|
602
|
-
if (!runId) {
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
postMessage({ type: "BRIXEL_UPDATE_LOCALE", payload: { runId, locale } });
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
529
|
export {
|
|
610
530
|
createExecuteTask,
|
|
611
531
|
createGetFileContent,
|
|
612
|
-
createMockBrixelHost,
|
|
613
532
|
createUploadFile,
|
|
614
533
|
executeTask,
|
|
615
534
|
getFileContent,
|
|
535
|
+
isExecuteTaskError,
|
|
616
536
|
listenToUITaskMessages,
|
|
617
|
-
mockContext,
|
|
618
537
|
simulateBrixelInit,
|
|
619
538
|
uploadFile,
|
|
620
539
|
useBrixelArtifact
|
package/package.json
CHANGED