@brixel_ai/artifact-sdk 1.0.3 → 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 +8 -6
- package/dist/index.d.mts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.js +31 -10
- package/dist/index.mjs +31 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -157,28 +157,30 @@ 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
|
-
|
|
160
|
+
`executeTask` returns `{ success, data }`:
|
|
161
|
+
- `success: true` => `data` is the task result
|
|
162
|
+
- `success: false` => `data` is an `ExecuteTaskError`
|
|
161
163
|
|
|
162
164
|
### Basic Usage
|
|
163
165
|
|
|
164
166
|
```tsx
|
|
165
|
-
import {
|
|
167
|
+
import { useBrixelArtifact } from "@brixel_ai/artifact-sdk";
|
|
166
168
|
|
|
167
169
|
function MyUITask() {
|
|
168
170
|
const { executeTask } = useBrixelArtifact();
|
|
169
171
|
|
|
170
172
|
const handleExecuteTask = async () => {
|
|
171
|
-
const
|
|
173
|
+
const response = await executeTask<{ message: string }>({
|
|
172
174
|
taskId: "78c2482f-b47d-461c-9fd0-509476687be9",
|
|
173
175
|
inputs: { name: "value" },
|
|
174
176
|
});
|
|
175
177
|
|
|
176
|
-
if (
|
|
177
|
-
console.error("Error:",
|
|
178
|
+
if (!response.success) {
|
|
179
|
+
console.error("Error:", response.data);
|
|
178
180
|
return;
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
console.debug("Task executed:",
|
|
183
|
+
console.debug("Task executed:", response.data);
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
return <button onClick={handleExecuteTask}>Execute Task</button>;
|
package/dist/index.d.mts
CHANGED
|
@@ -249,11 +249,23 @@ interface ExecuteTaskError {
|
|
|
249
249
|
details?: unknown;
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
|
-
*
|
|
253
|
-
* - success: returns task result directly
|
|
254
|
-
* - failure: returns ExecuteTaskError
|
|
252
|
+
* Successful executeTask response.
|
|
255
253
|
*/
|
|
256
|
-
|
|
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;
|
|
257
269
|
/**
|
|
258
270
|
* Parameters for uploading a file to Brixel
|
|
259
271
|
*/
|
|
@@ -349,7 +361,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
349
361
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
350
362
|
organizationId?: string;
|
|
351
363
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
352
|
-
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError;
|
|
364
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError | ExecuteTaskFailureResponse;
|
|
353
365
|
|
|
354
366
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
355
367
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -413,4 +425,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
413
425
|
*/
|
|
414
426
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
415
427
|
|
|
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 };
|
|
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
|
@@ -249,11 +249,23 @@ interface ExecuteTaskError {
|
|
|
249
249
|
details?: unknown;
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
|
-
*
|
|
253
|
-
* - success: returns task result directly
|
|
254
|
-
* - failure: returns ExecuteTaskError
|
|
252
|
+
* Successful executeTask response.
|
|
255
253
|
*/
|
|
256
|
-
|
|
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;
|
|
257
269
|
/**
|
|
258
270
|
* Parameters for uploading a file to Brixel
|
|
259
271
|
*/
|
|
@@ -349,7 +361,7 @@ declare function createExecuteTask(contextAuth?: {
|
|
|
349
361
|
}): <TOutput = unknown>(params: Omit<ExecuteTaskParams, "conversationId" | "apiToken" | "apiBaseUrl"> & {
|
|
350
362
|
organizationId?: string;
|
|
351
363
|
}) => Promise<ExecuteTaskResponse<TOutput>>;
|
|
352
|
-
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError;
|
|
364
|
+
declare function isExecuteTaskError(value: unknown): value is ExecuteTaskError | ExecuteTaskFailureResponse;
|
|
353
365
|
|
|
354
366
|
declare function uploadFile<TOutput = InternalFilePublicOut>(params: UploadFileParams): Promise<UploadFileResponse<TOutput>>;
|
|
355
367
|
declare function createUploadFile(contextAuth?: {
|
|
@@ -413,4 +425,4 @@ declare function simulateBrixelInit<TInputs = unknown>(inputs: TInputs, options?
|
|
|
413
425
|
*/
|
|
414
426
|
declare function listenToUITaskMessages(callback: (message: unknown) => void): () => void;
|
|
415
427
|
|
|
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 };
|
|
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
|
@@ -90,16 +90,16 @@ async function executeTask(params) {
|
|
|
90
90
|
debugApiBaseUrl(baseUrl);
|
|
91
91
|
try {
|
|
92
92
|
if (!organizationId) {
|
|
93
|
-
return {
|
|
93
|
+
return toExecuteTaskFailure({
|
|
94
94
|
code: "MISSING_ORGANIZATION_ID",
|
|
95
95
|
message: "organizationId is required to execute a task"
|
|
96
|
-
};
|
|
96
|
+
});
|
|
97
97
|
}
|
|
98
98
|
if (!taskId) {
|
|
99
|
-
return {
|
|
99
|
+
return toExecuteTaskFailure({
|
|
100
100
|
code: "MISSING_TASK_ID",
|
|
101
101
|
message: "taskId is required to execute a task"
|
|
102
|
-
};
|
|
102
|
+
});
|
|
103
103
|
}
|
|
104
104
|
const headers = {
|
|
105
105
|
"Content-Type": "application/json"
|
|
@@ -122,19 +122,19 @@ async function executeTask(params) {
|
|
|
122
122
|
);
|
|
123
123
|
const data = await parseJsonOrText(response);
|
|
124
124
|
if (!response.ok) {
|
|
125
|
-
return toHttpError(response, data);
|
|
125
|
+
return toExecuteTaskFailure(toHttpError(response, data));
|
|
126
126
|
}
|
|
127
127
|
if (isActionExecutePayload(data)) {
|
|
128
128
|
if (data.success === false) {
|
|
129
|
-
return toActionExecutionError(data);
|
|
129
|
+
return toExecuteTaskFailure(toActionExecutionError(data));
|
|
130
130
|
}
|
|
131
131
|
if ("result" in data) {
|
|
132
|
-
return data.result;
|
|
132
|
+
return toExecuteTaskSuccess(data.result);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
return data ?? void 0;
|
|
135
|
+
return toExecuteTaskSuccess(data ?? void 0);
|
|
136
136
|
} catch (error) {
|
|
137
|
-
return toNetworkError(error);
|
|
137
|
+
return toExecuteTaskFailure(toNetworkError(error));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
function createExecuteTask(contextAuth) {
|
|
@@ -163,8 +163,29 @@ function toActionExecutionError(payload) {
|
|
|
163
163
|
details: payload
|
|
164
164
|
};
|
|
165
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
|
+
}
|
|
166
178
|
function isExecuteTaskError(value) {
|
|
167
|
-
|
|
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";
|
|
168
189
|
}
|
|
169
190
|
|
|
170
191
|
// src/uploadFile.ts
|
package/dist/index.mjs
CHANGED
|
@@ -55,16 +55,16 @@ async function executeTask(params) {
|
|
|
55
55
|
debugApiBaseUrl(baseUrl);
|
|
56
56
|
try {
|
|
57
57
|
if (!organizationId) {
|
|
58
|
-
return {
|
|
58
|
+
return toExecuteTaskFailure({
|
|
59
59
|
code: "MISSING_ORGANIZATION_ID",
|
|
60
60
|
message: "organizationId is required to execute a task"
|
|
61
|
-
};
|
|
61
|
+
});
|
|
62
62
|
}
|
|
63
63
|
if (!taskId) {
|
|
64
|
-
return {
|
|
64
|
+
return toExecuteTaskFailure({
|
|
65
65
|
code: "MISSING_TASK_ID",
|
|
66
66
|
message: "taskId is required to execute a task"
|
|
67
|
-
};
|
|
67
|
+
});
|
|
68
68
|
}
|
|
69
69
|
const headers = {
|
|
70
70
|
"Content-Type": "application/json"
|
|
@@ -87,19 +87,19 @@ async function executeTask(params) {
|
|
|
87
87
|
);
|
|
88
88
|
const data = await parseJsonOrText(response);
|
|
89
89
|
if (!response.ok) {
|
|
90
|
-
return toHttpError(response, data);
|
|
90
|
+
return toExecuteTaskFailure(toHttpError(response, data));
|
|
91
91
|
}
|
|
92
92
|
if (isActionExecutePayload(data)) {
|
|
93
93
|
if (data.success === false) {
|
|
94
|
-
return toActionExecutionError(data);
|
|
94
|
+
return toExecuteTaskFailure(toActionExecutionError(data));
|
|
95
95
|
}
|
|
96
96
|
if ("result" in data) {
|
|
97
|
-
return data.result;
|
|
97
|
+
return toExecuteTaskSuccess(data.result);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
return data ?? void 0;
|
|
100
|
+
return toExecuteTaskSuccess(data ?? void 0);
|
|
101
101
|
} catch (error) {
|
|
102
|
-
return toNetworkError(error);
|
|
102
|
+
return toExecuteTaskFailure(toNetworkError(error));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
function createExecuteTask(contextAuth) {
|
|
@@ -128,8 +128,29 @@ function toActionExecutionError(payload) {
|
|
|
128
128
|
details: payload
|
|
129
129
|
};
|
|
130
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
|
+
}
|
|
131
143
|
function isExecuteTaskError(value) {
|
|
132
|
-
|
|
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";
|
|
133
154
|
}
|
|
134
155
|
|
|
135
156
|
// src/uploadFile.ts
|
package/package.json
CHANGED