@brixel_ai/artifact-sdk 1.0.2 → 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 -6
- package/dist/index.d.mts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +34 -22
- package/dist/index.mjs +33 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,26 +157,28 @@ interface BrixelContext {
|
|
|
157
157
|
## Executing Other UI Tasks
|
|
158
158
|
|
|
159
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`.
|
|
160
161
|
|
|
161
162
|
### Basic Usage
|
|
162
163
|
|
|
163
164
|
```tsx
|
|
164
|
-
import { useBrixelArtifact } from "@brixel_ai/artifact-sdk";
|
|
165
|
+
import { isExecuteTaskError, useBrixelArtifact } from "@brixel_ai/artifact-sdk";
|
|
165
166
|
|
|
166
167
|
function MyUITask() {
|
|
167
168
|
const { executeTask } = useBrixelArtifact();
|
|
168
169
|
|
|
169
170
|
const handleExecuteTask = async () => {
|
|
170
|
-
const result = await executeTask({
|
|
171
|
+
const result = await executeTask<{ message: string }>({
|
|
171
172
|
taskId: "78c2482f-b47d-461c-9fd0-509476687be9",
|
|
172
173
|
inputs: { name: "value" },
|
|
173
174
|
});
|
|
174
175
|
|
|
175
|
-
if (result
|
|
176
|
-
console.
|
|
177
|
-
|
|
178
|
-
console.error("Error:", result.error);
|
|
176
|
+
if (isExecuteTaskError(result)) {
|
|
177
|
+
console.error("Error:", result);
|
|
178
|
+
return;
|
|
179
179
|
}
|
|
180
|
+
|
|
181
|
+
console.debug("Task executed:", result);
|
|
180
182
|
};
|
|
181
183
|
|
|
182
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?: {
|
|
@@ -410,4 +413,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
410
413
|
*/
|
|
411
414
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
412
415
|
|
|
413
|
-
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, createUploadFile, executeTask, getFileContent, listenToUITaskMessages, simulateBrixelInit, uploadFile, useBrixelArtifact };
|
|
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?: {
|
|
@@ -410,4 +413,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
410
413
|
*/
|
|
411
414
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
412
415
|
|
|
413
|
-
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, createUploadFile, executeTask, getFileContent, listenToUITaskMessages, simulateBrixelInit, uploadFile, useBrixelArtifact };
|
|
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
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
createUploadFile: () => createUploadFile,
|
|
26
26
|
executeTask: () => executeTask,
|
|
27
27
|
getFileContent: () => getFileContent,
|
|
28
|
+
isExecuteTaskError: () => isExecuteTaskError,
|
|
28
29
|
listenToUITaskMessages: () => listenToUITaskMessages,
|
|
29
30
|
simulateBrixelInit: () => simulateBrixelInit,
|
|
30
31
|
uploadFile: () => uploadFile,
|
|
@@ -90,20 +91,14 @@ async function executeTask(params) {
|
|
|
90
91
|
try {
|
|
91
92
|
if (!organizationId) {
|
|
92
93
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
code: "MISSING_ORGANIZATION_ID",
|
|
96
|
-
message: "organizationId is required to execute a task"
|
|
97
|
-
}
|
|
94
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
95
|
+
message: "organizationId is required to execute a task"
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
if (!taskId) {
|
|
101
99
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
code: "MISSING_TASK_ID",
|
|
105
|
-
message: "taskId is required to execute a task"
|
|
106
|
-
}
|
|
100
|
+
code: "MISSING_TASK_ID",
|
|
101
|
+
message: "taskId is required to execute a task"
|
|
107
102
|
};
|
|
108
103
|
}
|
|
109
104
|
const headers = {
|
|
@@ -127,20 +122,19 @@ async function executeTask(params) {
|
|
|
127
122
|
);
|
|
128
123
|
const data = await parseJsonOrText(response);
|
|
129
124
|
if (!response.ok) {
|
|
130
|
-
return
|
|
131
|
-
success: false,
|
|
132
|
-
error: toHttpError(response, data)
|
|
133
|
-
};
|
|
125
|
+
return toHttpError(response, data);
|
|
134
126
|
}
|
|
135
|
-
|
|
136
|
-
success
|
|
137
|
-
|
|
138
|
-
|
|
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;
|
|
139
136
|
} catch (error) {
|
|
140
|
-
return
|
|
141
|
-
success: false,
|
|
142
|
-
error: toNetworkError(error)
|
|
143
|
-
};
|
|
137
|
+
return toNetworkError(error);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
function createExecuteTask(contextAuth) {
|
|
@@ -155,6 +149,23 @@ function createExecuteTask(contextAuth) {
|
|
|
155
149
|
});
|
|
156
150
|
};
|
|
157
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
|
+
}
|
|
158
169
|
|
|
159
170
|
// src/uploadFile.ts
|
|
160
171
|
async function uploadFile(params) {
|
|
@@ -557,6 +568,7 @@ function listenToUITaskMessages(callback) {
|
|
|
557
568
|
createUploadFile,
|
|
558
569
|
executeTask,
|
|
559
570
|
getFileContent,
|
|
571
|
+
isExecuteTaskError,
|
|
560
572
|
listenToUITaskMessages,
|
|
561
573
|
simulateBrixelInit,
|
|
562
574
|
uploadFile,
|
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) {
|
|
@@ -522,6 +532,7 @@ export {
|
|
|
522
532
|
createUploadFile,
|
|
523
533
|
executeTask,
|
|
524
534
|
getFileContent,
|
|
535
|
+
isExecuteTaskError,
|
|
525
536
|
listenToUITaskMessages,
|
|
526
537
|
simulateBrixelInit,
|
|
527
538
|
uploadFile,
|
package/package.json
CHANGED