@brixel_ai/artifact-sdk 1.0.2 → 1.0.4
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 +9 -5
- package/dist/index.d.mts +25 -10
- package/dist/index.d.ts +25 -10
- package/dist/index.js +59 -26
- package/dist/index.mjs +58 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,6 +157,9 @@ 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
|
+
`executeTask` returns `{ success, data }`:
|
|
161
|
+
- `success: true` => `data` is the task result
|
|
162
|
+
- `success: false` => `data` is an `ExecuteTaskError`
|
|
160
163
|
|
|
161
164
|
### Basic Usage
|
|
162
165
|
|
|
@@ -167,16 +170,17 @@ function MyUITask() {
|
|
|
167
170
|
const { executeTask } = useBrixelArtifact();
|
|
168
171
|
|
|
169
172
|
const handleExecuteTask = async () => {
|
|
170
|
-
const
|
|
173
|
+
const response = await executeTask<{ message: string }>({
|
|
171
174
|
taskId: "78c2482f-b47d-461c-9fd0-509476687be9",
|
|
172
175
|
inputs: { name: "value" },
|
|
173
176
|
});
|
|
174
177
|
|
|
175
|
-
if (
|
|
176
|
-
console.
|
|
177
|
-
|
|
178
|
-
console.error("Error:", result.error);
|
|
178
|
+
if (!response.success) {
|
|
179
|
+
console.error("Error:", response.data);
|
|
180
|
+
return;
|
|
179
181
|
}
|
|
182
|
+
|
|
183
|
+
console.debug("Task executed:", response.data);
|
|
180
184
|
};
|
|
181
185
|
|
|
182
186
|
return <button onClick={handleExecuteTask}>Execute Task</button>;
|
package/dist/index.d.mts
CHANGED
|
@@ -241,17 +241,31 @@ 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
|
+
* Successful executeTask response.
|
|
253
|
+
*/
|
|
254
|
+
interface ExecuteTaskSuccessResponse<TOutput = unknown> {
|
|
255
|
+
success: true;
|
|
256
|
+
data: TOutput;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Failed executeTask response.
|
|
260
|
+
*/
|
|
261
|
+
interface ExecuteTaskFailureResponse {
|
|
262
|
+
success: false;
|
|
263
|
+
data: ExecuteTaskError;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Return value from executeTask.
|
|
267
|
+
*/
|
|
268
|
+
type ExecuteTaskResponse<TOutput = unknown> = ExecuteTaskSuccessResponse<TOutput> | ExecuteTaskFailureResponse;
|
|
255
269
|
/**
|
|
256
270
|
* Parameters for uploading a file to Brixel
|
|
257
271
|
*/
|
|
@@ -347,6 +361,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
347
361
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
348
362
|
organizationId?: string;
|
|
349
363
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
364
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError | ExecuteTaskFailureResponse;
|
|
350
365
|
|
|
351
366
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
352
367
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -410,4 +425,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
410
425
|
*/
|
|
411
426
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
412
427
|
|
|
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 };
|
|
428
|
+
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskError, type ExecuteTaskFailureResponse, type ExecuteTaskParams, type ExecuteTaskResponse, type ExecuteTaskSuccessResponse, 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,31 @@ 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
|
+
* Successful executeTask response.
|
|
253
|
+
*/
|
|
254
|
+
interface ExecuteTaskSuccessResponse<TOutput = unknown> {
|
|
255
|
+
success: true;
|
|
256
|
+
data: TOutput;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Failed executeTask response.
|
|
260
|
+
*/
|
|
261
|
+
interface ExecuteTaskFailureResponse {
|
|
262
|
+
success: false;
|
|
263
|
+
data: ExecuteTaskError;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Return value from executeTask.
|
|
267
|
+
*/
|
|
268
|
+
type ExecuteTaskResponse<TOutput = unknown> = ExecuteTaskSuccessResponse<TOutput> | ExecuteTaskFailureResponse;
|
|
255
269
|
/**
|
|
256
270
|
* Parameters for uploading a file to Brixel
|
|
257
271
|
*/
|
|
@@ -347,6 +361,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
347
361
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
348
362
|
organizationId?: string;
|
|
349
363
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
364
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError | ExecuteTaskFailureResponse;
|
|
350
365
|
|
|
351
366
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
352
367
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -410,4 +425,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
410
425
|
*/
|
|
411
426
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
412
427
|
|
|
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 };
|
|
428
|
+
export { type ArtifactManifest, type BrixelContext, type CancelMessage, type CompleteMessage, type DestroyMessage, type ErrorMessage, type ExecuteTaskError, type ExecuteTaskFailureResponse, type ExecuteTaskParams, type ExecuteTaskResponse, type ExecuteTaskSuccessResponse, 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,
|
|
@@ -89,22 +90,16 @@ async function executeTask(params) {
|
|
|
89
90
|
debugApiBaseUrl(baseUrl);
|
|
90
91
|
try {
|
|
91
92
|
if (!organizationId) {
|
|
92
|
-
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
message: "organizationId is required to execute a task"
|
|
97
|
-
}
|
|
98
|
-
};
|
|
93
|
+
return toExecuteTaskFailure({
|
|
94
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
95
|
+
message: "organizationId is required to execute a task"
|
|
96
|
+
});
|
|
99
97
|
}
|
|
100
98
|
if (!taskId) {
|
|
101
|
-
return {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
message: "taskId is required to execute a task"
|
|
106
|
-
}
|
|
107
|
-
};
|
|
99
|
+
return toExecuteTaskFailure({
|
|
100
|
+
code: "MISSING_TASK_ID",
|
|
101
|
+
message: "taskId is required to execute a task"
|
|
102
|
+
});
|
|
108
103
|
}
|
|
109
104
|
const headers = {
|
|
110
105
|
"Content-Type": "application/json"
|
|
@@ -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 toExecuteTaskFailure(toHttpError(response, data));
|
|
134
126
|
}
|
|
135
|
-
|
|
136
|
-
success
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
if (isActionExecutePayload(data)) {
|
|
128
|
+
if (data.success === false) {
|
|
129
|
+
return toExecuteTaskFailure(toActionExecutionError(data));
|
|
130
|
+
}
|
|
131
|
+
if ("result" in data) {
|
|
132
|
+
return toExecuteTaskSuccess(data.result);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return toExecuteTaskSuccess(data ?? void 0);
|
|
139
136
|
} catch (error) {
|
|
140
|
-
return
|
|
141
|
-
success: false,
|
|
142
|
-
error: toNetworkError(error)
|
|
143
|
-
};
|
|
137
|
+
return toExecuteTaskFailure(toNetworkError(error));
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
function createExecuteTask(contextAuth) {
|
|
@@ -155,6 +149,44 @@ 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 toExecuteTaskSuccess(data) {
|
|
167
|
+
return {
|
|
168
|
+
success: true,
|
|
169
|
+
data
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function toExecuteTaskFailure(error) {
|
|
173
|
+
return {
|
|
174
|
+
success: false,
|
|
175
|
+
data: error
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function isExecuteTaskError(value) {
|
|
179
|
+
if (!isRecord(value)) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (typeof value.code === "string" && typeof value.message === "string") {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (value.success !== false || !("data" in value) || !isRecord(value.data)) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
return typeof value.data.code === "string" && typeof value.data.message === "string";
|
|
189
|
+
}
|
|
158
190
|
|
|
159
191
|
// src/uploadFile.ts
|
|
160
192
|
async function uploadFile(params) {
|
|
@@ -557,6 +589,7 @@ function listenToUITaskMessages(callback) {
|
|
|
557
589
|
createUploadFile,
|
|
558
590
|
executeTask,
|
|
559
591
|
getFileContent,
|
|
592
|
+
isExecuteTaskError,
|
|
560
593
|
listenToUITaskMessages,
|
|
561
594
|
simulateBrixelInit,
|
|
562
595
|
uploadFile,
|
package/dist/index.mjs
CHANGED
|
@@ -55,22 +55,16 @@ async function executeTask(params) {
|
|
|
55
55
|
debugApiBaseUrl(baseUrl);
|
|
56
56
|
try {
|
|
57
57
|
if (!organizationId) {
|
|
58
|
-
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
message: "organizationId is required to execute a task"
|
|
63
|
-
}
|
|
64
|
-
};
|
|
58
|
+
return toExecuteTaskFailure({
|
|
59
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
60
|
+
message: "organizationId is required to execute a task"
|
|
61
|
+
});
|
|
65
62
|
}
|
|
66
63
|
if (!taskId) {
|
|
67
|
-
return {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
message: "taskId is required to execute a task"
|
|
72
|
-
}
|
|
73
|
-
};
|
|
64
|
+
return toExecuteTaskFailure({
|
|
65
|
+
code: "MISSING_TASK_ID",
|
|
66
|
+
message: "taskId is required to execute a task"
|
|
67
|
+
});
|
|
74
68
|
}
|
|
75
69
|
const headers = {
|
|
76
70
|
"Content-Type": "application/json"
|
|
@@ -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 toExecuteTaskFailure(toHttpError(response, data));
|
|
100
91
|
}
|
|
101
|
-
|
|
102
|
-
success
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
if (isActionExecutePayload(data)) {
|
|
93
|
+
if (data.success === false) {
|
|
94
|
+
return toExecuteTaskFailure(toActionExecutionError(data));
|
|
95
|
+
}
|
|
96
|
+
if ("result" in data) {
|
|
97
|
+
return toExecuteTaskSuccess(data.result);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return toExecuteTaskSuccess(data ?? void 0);
|
|
105
101
|
} catch (error) {
|
|
106
|
-
return
|
|
107
|
-
success: false,
|
|
108
|
-
error: toNetworkError(error)
|
|
109
|
-
};
|
|
102
|
+
return toExecuteTaskFailure(toNetworkError(error));
|
|
110
103
|
}
|
|
111
104
|
}
|
|
112
105
|
function createExecuteTask(contextAuth) {
|
|
@@ -121,6 +114,44 @@ 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 toExecuteTaskSuccess(data) {
|
|
132
|
+
return {
|
|
133
|
+
success: true,
|
|
134
|
+
data
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function toExecuteTaskFailure(error) {
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
data: error
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function isExecuteTaskError(value) {
|
|
144
|
+
if (!isRecord(value)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (typeof value.code === "string" && typeof value.message === "string") {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (value.success !== false || !("data" in value) || !isRecord(value.data)) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return typeof value.data.code === "string" && typeof value.data.message === "string";
|
|
154
|
+
}
|
|
124
155
|
|
|
125
156
|
// src/uploadFile.ts
|
|
126
157
|
async function uploadFile(params) {
|
|
@@ -522,6 +553,7 @@ export {
|
|
|
522
553
|
createUploadFile,
|
|
523
554
|
executeTask,
|
|
524
555
|
getFileContent,
|
|
556
|
+
isExecuteTaskError,
|
|
525
557
|
listenToUITaskMessages,
|
|
526
558
|
simulateBrixelInit,
|
|
527
559
|
uploadFile,
|
package/package.json
CHANGED