codemie-sdk 0.1.228 → 0.1.230
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 +51 -9
- package/dist/index.cjs +60 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -10
- package/dist/index.d.ts +30 -10
- package/dist/index.js +60 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,7 +212,7 @@ await client.assistants.delete("assistant-id");
|
|
|
212
212
|
|
|
213
213
|
#### Advanced Features
|
|
214
214
|
|
|
215
|
-
6. **Chat with Assistant**
|
|
215
|
+
6. **Chat with Assistant (with MCP header propagation)**
|
|
216
216
|
```typescript
|
|
217
217
|
const params: AssistantChatParams = {
|
|
218
218
|
text: "Your message here",
|
|
@@ -224,11 +224,38 @@ const params: AssistantChatParams = {
|
|
|
224
224
|
system_prompt: "Override default system prompt",
|
|
225
225
|
background_task: false,
|
|
226
226
|
content_raw: "", // Raw content if needed
|
|
227
|
-
file_name: "", // For file processing
|
|
228
227
|
top_k: 1,
|
|
229
|
-
metadata: {} // Additional metadata
|
|
228
|
+
metadata: {}, // Additional metadata
|
|
229
|
+
propagate_headers: true, // Enable propagation of X-* headers
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// Pass X-* headers to be forwarded to MCP servers
|
|
233
|
+
const response = await client.assistants.chat(
|
|
234
|
+
"assistant-id",
|
|
235
|
+
params,
|
|
236
|
+
{
|
|
237
|
+
"X-Tenant-ID": "tenant-abc-123",
|
|
238
|
+
"X-User-ID": "user-456",
|
|
239
|
+
"X-Request-ID": "req-123",
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
6.a. **Chat with Assistant by slug (with MCP header propagation)**
|
|
245
|
+
```typescript
|
|
246
|
+
const params: AssistantChatParams = {
|
|
247
|
+
text: "Your message here",
|
|
248
|
+
propagate_headers: true,
|
|
230
249
|
};
|
|
231
|
-
|
|
250
|
+
|
|
251
|
+
const response = await client.assistants.chatBySlug(
|
|
252
|
+
"assistant-slug",
|
|
253
|
+
params,
|
|
254
|
+
{
|
|
255
|
+
"X-Environment": "production",
|
|
256
|
+
"X-Feature-Flag-Beta": "true",
|
|
257
|
+
}
|
|
258
|
+
);
|
|
232
259
|
```
|
|
233
260
|
7. **Utilize structured outputs with Assistant
|
|
234
261
|
Uzing zod objects
|
|
@@ -679,10 +706,19 @@ const result = await client.workflows.delete("workflow-id");
|
|
|
679
706
|
|
|
680
707
|
The SDK provides comprehensive workflow execution management through the WorkflowExecutionService:
|
|
681
708
|
|
|
682
|
-
1. **Run Workflow**
|
|
709
|
+
1. **Run Workflow (with MCP header propagation)**
|
|
683
710
|
```typescript
|
|
684
|
-
//
|
|
685
|
-
const execution = await client.workflows.run(
|
|
711
|
+
// Enable propagation in payload and pass X-* headers to forward to MCP servers
|
|
712
|
+
const execution = await client.workflows.run(
|
|
713
|
+
"workflow-id",
|
|
714
|
+
"optional input",
|
|
715
|
+
undefined, // fileName
|
|
716
|
+
true, // propagateHeaders
|
|
717
|
+
{
|
|
718
|
+
"X-Request-ID": "req-abc-123",
|
|
719
|
+
"X-Source-App": "analytics-ui",
|
|
720
|
+
},
|
|
721
|
+
);
|
|
686
722
|
|
|
687
723
|
// Get execution service for advanced operations
|
|
688
724
|
const executionService = client.workflows.executions("workflow-id");
|
|
@@ -702,8 +738,14 @@ const execution = await executionService.get("execution-id");
|
|
|
702
738
|
// Abort running execution
|
|
703
739
|
const result = await executionService.abort("execution-id");
|
|
704
740
|
|
|
705
|
-
// Resume interrupted execution
|
|
706
|
-
const result = await executionService.resume(
|
|
741
|
+
// Resume interrupted execution with header propagation (query param + headers)
|
|
742
|
+
const result = await executionService.resume(
|
|
743
|
+
"execution-id",
|
|
744
|
+
true, // propagateHeaders
|
|
745
|
+
{
|
|
746
|
+
"X-Correlation-ID": "corr-456",
|
|
747
|
+
}
|
|
748
|
+
);
|
|
707
749
|
|
|
708
750
|
// Delete all executions
|
|
709
751
|
const result = await executionService.deleteAll();
|
package/dist/index.cjs
CHANGED
|
@@ -226,6 +226,8 @@ var AssistantChatParamsSchema = import_zod.z.object({
|
|
|
226
226
|
]),
|
|
227
227
|
history_index: import_zod.z.number().optional(),
|
|
228
228
|
stream: import_zod.z.boolean().optional(),
|
|
229
|
+
propagate_headers: import_zod.z.boolean().optional(),
|
|
230
|
+
custom_metadata: import_zod.z.record(import_zod.z.unknown()).optional(),
|
|
229
231
|
top_k: import_zod.z.number().optional(),
|
|
230
232
|
system_prompt: import_zod.z.string().optional(),
|
|
231
233
|
background_task: import_zod.z.boolean().optional(),
|
|
@@ -296,11 +298,22 @@ var ApiRequestHandler = class {
|
|
|
296
298
|
});
|
|
297
299
|
return response.data;
|
|
298
300
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Merge extra headers into the request (used for X-* propagation)
|
|
303
|
+
*/
|
|
304
|
+
withHeaders(config = {}, extraHeaders) {
|
|
305
|
+
if (!extraHeaders || Object.keys(extraHeaders).length === 0) return config;
|
|
306
|
+
const headers = config.headers ?? {};
|
|
307
|
+
return { ...config, headers: { ...headers, ...extraHeaders } };
|
|
308
|
+
}
|
|
309
|
+
async get(path, params, config = {}, extraHeaders) {
|
|
310
|
+
return this.request("get", path, this.withHeaders({ ...config, params }, extraHeaders));
|
|
311
|
+
}
|
|
312
|
+
async post(path, data, config = {}, extraHeaders) {
|
|
313
|
+
return this.request("post", path, this.withHeaders({ ...config, data }, extraHeaders));
|
|
301
314
|
}
|
|
302
|
-
async
|
|
303
|
-
return this.request("
|
|
315
|
+
async put(path, data, config = {}, extraHeaders) {
|
|
316
|
+
return this.request("put", path, this.withHeaders({ ...config, data }, extraHeaders));
|
|
304
317
|
}
|
|
305
318
|
async postMultipart(url, formData, params) {
|
|
306
319
|
const response = await this.client.post(url, formData, {
|
|
@@ -311,9 +324,6 @@ var ApiRequestHandler = class {
|
|
|
311
324
|
});
|
|
312
325
|
return response.data;
|
|
313
326
|
}
|
|
314
|
-
async put(path, data, config = {}) {
|
|
315
|
-
return this.request("put", path, { ...config, data });
|
|
316
|
-
}
|
|
317
327
|
async delete(path, config = {}) {
|
|
318
328
|
return this.request("delete", path, config);
|
|
319
329
|
}
|
|
@@ -446,7 +456,7 @@ var AssistantService = class {
|
|
|
446
456
|
/**
|
|
447
457
|
* Send a chat request to an assistant.
|
|
448
458
|
*/
|
|
449
|
-
async chat(assistantId, _params) {
|
|
459
|
+
async chat(assistantId, _params, headers) {
|
|
450
460
|
let zodSchema = void 0;
|
|
451
461
|
let params = { ..._params };
|
|
452
462
|
if (params.output_schema && params.output_schema instanceof import_zod2.z.ZodType) {
|
|
@@ -461,7 +471,33 @@ var AssistantService = class {
|
|
|
461
471
|
params,
|
|
462
472
|
{
|
|
463
473
|
responseType: params.stream ? "stream" : void 0
|
|
464
|
-
}
|
|
474
|
+
},
|
|
475
|
+
headers
|
|
476
|
+
);
|
|
477
|
+
const mapped = AssistantMapper.mapBaseModelApiResponse(response);
|
|
478
|
+
if (!params.stream && zodSchema && mapped.generated) {
|
|
479
|
+
mapped.generated = zodSchema.parse(mapped.generated);
|
|
480
|
+
}
|
|
481
|
+
return mapped;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Send a chat request to an assistant by slug.
|
|
485
|
+
*/
|
|
486
|
+
async chatBySlug(assistantSlug, _params, headers) {
|
|
487
|
+
let zodSchema = void 0;
|
|
488
|
+
let params = { ..._params };
|
|
489
|
+
if (params.output_schema && params.output_schema instanceof import_zod2.z.ZodType) {
|
|
490
|
+
zodSchema = params.output_schema;
|
|
491
|
+
params.output_schema = (0, import_zod_to_json_schema.zodToJsonSchema)(zodSchema, { definitions: {} });
|
|
492
|
+
}
|
|
493
|
+
params = AssistantChatParamsSchema.parse(params);
|
|
494
|
+
const response = await this.api.post(
|
|
495
|
+
`/v1/assistants/slug/${assistantSlug}/model`,
|
|
496
|
+
params,
|
|
497
|
+
{
|
|
498
|
+
responseType: params.stream ? "stream" : void 0
|
|
499
|
+
},
|
|
500
|
+
headers
|
|
465
501
|
);
|
|
466
502
|
const mapped = AssistantMapper.mapBaseModelApiResponse(response);
|
|
467
503
|
if (!params.stream && zodSchema && mapped.generated) {
|
|
@@ -1158,7 +1194,9 @@ var WorkflowExecutionListParamsSchema = import_zod5.z.object({
|
|
|
1158
1194
|
per_page: import_zod5.z.number().default(10)
|
|
1159
1195
|
}).readonly();
|
|
1160
1196
|
var WorkflowExecutionCreateParamsSchema = import_zod5.z.object({
|
|
1161
|
-
user_input: import_zod5.z.string().
|
|
1197
|
+
user_input: import_zod5.z.union([import_zod5.z.string(), import_zod5.z.record(import_zod5.z.unknown()), import_zod5.z.array(import_zod5.z.unknown()), import_zod5.z.number(), import_zod5.z.boolean()]).optional(),
|
|
1198
|
+
file_name: import_zod5.z.string().optional(),
|
|
1199
|
+
propagate_headers: import_zod5.z.boolean().optional()
|
|
1162
1200
|
}).readonly();
|
|
1163
1201
|
var WorkflowExecutionStateListParamsSchema = import_zod5.z.object({
|
|
1164
1202
|
page: import_zod5.z.number().default(0),
|
|
@@ -1221,9 +1259,13 @@ var WorkflowExecutionService = class {
|
|
|
1221
1259
|
/**
|
|
1222
1260
|
* Create a new workflow execution.
|
|
1223
1261
|
*/
|
|
1224
|
-
async create(userInput
|
|
1225
|
-
const params = WorkflowExecutionCreateParamsSchema.parse({
|
|
1226
|
-
|
|
1262
|
+
async create(userInput, fileName, propagateHeaders, headers) {
|
|
1263
|
+
const params = WorkflowExecutionCreateParamsSchema.parse({
|
|
1264
|
+
user_input: userInput,
|
|
1265
|
+
file_name: fileName,
|
|
1266
|
+
propagate_headers: propagateHeaders
|
|
1267
|
+
});
|
|
1268
|
+
return this.api.post(`/v1/workflows/${this.workflowId}/executions`, params, {}, headers);
|
|
1227
1269
|
}
|
|
1228
1270
|
/**
|
|
1229
1271
|
* Get workflow execution by ID.
|
|
@@ -1255,8 +1297,9 @@ var WorkflowExecutionService = class {
|
|
|
1255
1297
|
/**
|
|
1256
1298
|
* Resume an interrupted workflow execution.
|
|
1257
1299
|
*/
|
|
1258
|
-
async resume(executionId) {
|
|
1259
|
-
|
|
1300
|
+
async resume(executionId, propagateHeaders, headers) {
|
|
1301
|
+
const config = { params: { propagate_headers: propagateHeaders } };
|
|
1302
|
+
return this.api.put(`/v1/workflows/${this.workflowId}/executions/${executionId}/resume`, {}, config, headers);
|
|
1260
1303
|
}
|
|
1261
1304
|
};
|
|
1262
1305
|
|
|
@@ -1319,8 +1362,8 @@ var WorkflowService = class {
|
|
|
1319
1362
|
/**
|
|
1320
1363
|
* Run a workflow by ID.
|
|
1321
1364
|
*/
|
|
1322
|
-
async run(workflowId, userInput
|
|
1323
|
-
return this.executions(workflowId).create(userInput);
|
|
1365
|
+
async run(workflowId, userInput, fileName, propagateHeaders, headers) {
|
|
1366
|
+
return this.executions(workflowId).create(userInput, fileName, propagateHeaders, headers);
|
|
1324
1367
|
}
|
|
1325
1368
|
/**
|
|
1326
1369
|
* Get workflow execution service for the specified workflow.
|