@composio/core 0.21.0 → 0.22.0
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/dist/{CustomTool-BHOYxLZX.d.mts → CustomTool-CKBCElpT.d.mts} +1 -1
- package/dist/{Telemetry-JRJJYS4I.mjs → Telemetry-41JkqpZ7.mjs} +3 -2
- package/dist/{composio-BTZsFajb.d.mts → composio-C-418N1P.d.mts} +80 -166
- package/dist/{customTool.types-D_w21L56.d.mts → customTool.types-CK408sI-.d.mts} +122 -61
- package/dist/experimental/index.d.mts +2 -2
- package/dist/index.d.mts +5 -6
- package/dist/index.mjs +6070 -6259
- package/dist/models/Files.node.mjs +1 -1
- package/dist/{types-CgRsUGqm.d.mts → types-RpMRVn4D.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +4 -4
- package/src/lib/toolRouterParams.ts +18 -10
- package/src/models/AuthConfigs.ts +0 -9
- package/src/models/ConnectionRequest.ts +21 -18
- package/src/models/Logs.ts +2 -2
- package/src/models/ToolRouter.ts +7 -5
- package/src/models/ToolRouterSession.ts +6 -5
- package/src/models/Tools.ts +2 -2
- package/src/models/Usage.ts +2 -1
- package/src/provider/OpenAIProvider.ts +0 -283
- package/src/telemetry/Telemetry.ts +4 -2
- package/src/types/logs.types.ts +9 -1
- package/src/types/tool.types.ts +3 -3
- package/src/types/toolRouter.types.ts +43 -21
- package/src/types/usage.types.ts +2 -0
- package/src/utils/transformers/logs.ts +3 -2
- package/src/utils/transformers/toolRouterResponseTransform.ts +23 -5
- package/src/utils/transformers/usage.ts +4 -0
|
@@ -8,10 +8,8 @@
|
|
|
8
8
|
* This will be shipped with the SDK and users don't need to install it separately.
|
|
9
9
|
*/
|
|
10
10
|
import { OpenAI } from 'openai';
|
|
11
|
-
import { Stream } from 'openai/streaming';
|
|
12
11
|
import { BaseNonAgenticProvider } from './BaseProvider';
|
|
13
12
|
import { Tool } from '../types/tool.types';
|
|
14
|
-
import logger from '../utils/logger';
|
|
15
13
|
import { ExecuteToolModifiers } from '../types/modifiers.types';
|
|
16
14
|
import {
|
|
17
15
|
ExecuteToolFnOptions,
|
|
@@ -296,285 +294,4 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
|
|
|
296
294
|
}
|
|
297
295
|
return outputs;
|
|
298
296
|
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Handles all the tool calls from the OpenAI Assistant API.
|
|
302
|
-
*
|
|
303
|
-
* This method processes tool calls from an OpenAI Assistant run,
|
|
304
|
-
* executes each tool call, and returns the tool outputs for submission.
|
|
305
|
-
*
|
|
306
|
-
* @deprecated Assistant API is deprecated, please use responses or chat completions instead. This method will be removed in the next major version.
|
|
307
|
-
*
|
|
308
|
-
* @param {string} userId - The user ID for authentication and tracking
|
|
309
|
-
* @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls
|
|
310
|
-
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
311
|
-
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
312
|
-
* @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```typescript
|
|
317
|
-
* // Handle tool calls from an OpenAI Assistant run
|
|
318
|
-
* const run = {
|
|
319
|
-
* id: 'run_abc123',
|
|
320
|
-
* required_action: {
|
|
321
|
-
* submit_tool_outputs: {
|
|
322
|
-
* tool_calls: [
|
|
323
|
-
* {
|
|
324
|
-
* id: 'call_xyz789',
|
|
325
|
-
* type: 'function',
|
|
326
|
-
* function: {
|
|
327
|
-
* name: 'SEARCH_TOOL',
|
|
328
|
-
* arguments: '{"query":"composio documentation"}'
|
|
329
|
-
* }
|
|
330
|
-
* }
|
|
331
|
-
* ]
|
|
332
|
-
* }
|
|
333
|
-
* }
|
|
334
|
-
* };
|
|
335
|
-
*
|
|
336
|
-
* const toolOutputs = await provider.handleAssistantMessage(
|
|
337
|
-
* 'user123',
|
|
338
|
-
* run,
|
|
339
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
340
|
-
* );
|
|
341
|
-
*
|
|
342
|
-
* // Submit tool outputs back to OpenAI
|
|
343
|
-
* await openai.beta.threads.runs.submitToolOutputs(
|
|
344
|
-
* thread.id,
|
|
345
|
-
* run.id,
|
|
346
|
-
* { tool_outputs: toolOutputs }
|
|
347
|
-
* );
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
350
|
-
async handleAssistantMessage(
|
|
351
|
-
userId: string,
|
|
352
|
-
run: OpenAI.Beta.Threads.Run,
|
|
353
|
-
options?: ExecuteToolFnOptions,
|
|
354
|
-
modifiers?: ExecuteToolModifiers
|
|
355
|
-
) {
|
|
356
|
-
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
|
|
357
|
-
const tool_outputs: Array<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput> =
|
|
358
|
-
await Promise.all(
|
|
359
|
-
tool_calls.map(async tool_call => {
|
|
360
|
-
logger.debug(`Executing tool call: ${tool_call.id}`);
|
|
361
|
-
|
|
362
|
-
// Execute each tool call and get the response
|
|
363
|
-
const tool_response = await this.executeToolCall(
|
|
364
|
-
userId,
|
|
365
|
-
tool_call as OpenAI.ChatCompletionMessageFunctionToolCall,
|
|
366
|
-
options,
|
|
367
|
-
modifiers
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
logger.debug(`Tool call ${tool_call.id} executed with response: ${tool_response}`);
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
tool_call_id: tool_call.id,
|
|
374
|
-
output: JSON.stringify(tool_response),
|
|
375
|
-
};
|
|
376
|
-
})
|
|
377
|
-
);
|
|
378
|
-
return tool_outputs;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Waits for the assistant stream and handles the tool calls.
|
|
383
|
-
*
|
|
384
|
-
* This method processes an OpenAI Assistant stream, handles any tool calls
|
|
385
|
-
* that require action, and yields each event from the stream. It's designed
|
|
386
|
-
* for streaming Assistant responses while handling tool calls in real-time.
|
|
387
|
-
*
|
|
388
|
-
* @deprecated Assistant API is deprecated, please use responses or chat completions instead. It will be removed in the next major version.
|
|
389
|
-
*
|
|
390
|
-
* @param {string} userId - The user ID for authentication and tracking
|
|
391
|
-
* @param {OpenAI} client - The OpenAI client instance
|
|
392
|
-
* @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream
|
|
393
|
-
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
394
|
-
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
395
|
-
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
396
|
-
* @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
* @example
|
|
401
|
-
* ```typescript
|
|
402
|
-
* // Process an OpenAI Assistant stream with tool calls
|
|
403
|
-
* const thread = await openai.beta.threads.create();
|
|
404
|
-
* const runStream = openai.beta.threads.runs.stream(thread.id, {
|
|
405
|
-
* assistant_id: 'asst_abc123',
|
|
406
|
-
* tools: provider.wrapTools(composioTools)
|
|
407
|
-
* });
|
|
408
|
-
*
|
|
409
|
-
* // Process the stream and handle tool calls
|
|
410
|
-
* const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(
|
|
411
|
-
* 'user123',
|
|
412
|
-
* openai,
|
|
413
|
-
* runStream,
|
|
414
|
-
* thread,
|
|
415
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
416
|
-
* );
|
|
417
|
-
*
|
|
418
|
-
* // Consume the stream events
|
|
419
|
-
* for await (const event of streamProcessor) {
|
|
420
|
-
* if (event.event === 'thread.message.delta') {
|
|
421
|
-
* console.log(event.data.delta.content);
|
|
422
|
-
* }
|
|
423
|
-
* }
|
|
424
|
-
* ```
|
|
425
|
-
*/
|
|
426
|
-
async *waitAndHandleAssistantStreamToolCalls(
|
|
427
|
-
userId: string,
|
|
428
|
-
client: OpenAI,
|
|
429
|
-
runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>,
|
|
430
|
-
thread: OpenAI.Beta.Threads.Thread,
|
|
431
|
-
options?: ExecuteToolFnOptions,
|
|
432
|
-
modifiers?: ExecuteToolModifiers
|
|
433
|
-
) {
|
|
434
|
-
// @TODO: Log the run stream
|
|
435
|
-
let runId = null;
|
|
436
|
-
|
|
437
|
-
// Start processing the runStream events
|
|
438
|
-
for await (const event of runStream) {
|
|
439
|
-
yield event; // Yield each event from the stream as it arrives
|
|
440
|
-
|
|
441
|
-
if (event.event === 'thread.run.created') {
|
|
442
|
-
const { id } = event.data;
|
|
443
|
-
runId = id;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
if (!runId) {
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Handle the 'requires_action' event
|
|
451
|
-
if (event.event === 'thread.run.requires_action') {
|
|
452
|
-
const toolOutputs = await this.handleAssistantMessage(
|
|
453
|
-
userId,
|
|
454
|
-
event.data,
|
|
455
|
-
options,
|
|
456
|
-
modifiers
|
|
457
|
-
);
|
|
458
|
-
|
|
459
|
-
// Submit the tool outputs
|
|
460
|
-
await client.beta.threads.runs.submitToolOutputs(runId, {
|
|
461
|
-
thread_id: thread.id,
|
|
462
|
-
tool_outputs: toolOutputs,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Break if the run status becomes inactive
|
|
467
|
-
if (
|
|
468
|
-
[
|
|
469
|
-
'thread.run.completed',
|
|
470
|
-
'thread.run.failed',
|
|
471
|
-
'thread.run.cancelled',
|
|
472
|
-
'thread.run.expired',
|
|
473
|
-
].includes(event.event)
|
|
474
|
-
) {
|
|
475
|
-
break;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (!runId) {
|
|
480
|
-
throw new Error('No run ID found');
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// Handle any final actions after the stream ends
|
|
484
|
-
let finalRun = await client.beta.threads.runs.retrieve(runId, {
|
|
485
|
-
thread_id: thread.id,
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
while (['queued', 'in_progress', 'requires_action'].includes(finalRun.status)) {
|
|
489
|
-
if (finalRun.status === 'requires_action') {
|
|
490
|
-
const toolOutputs = await this.handleAssistantMessage(userId, finalRun, options, modifiers);
|
|
491
|
-
|
|
492
|
-
// Submit tool outputs
|
|
493
|
-
finalRun = await client.beta.threads.runs.submitToolOutputs(runId, {
|
|
494
|
-
thread_id: thread.id,
|
|
495
|
-
tool_outputs: toolOutputs,
|
|
496
|
-
});
|
|
497
|
-
} else {
|
|
498
|
-
// Update the run status
|
|
499
|
-
finalRun = await client.beta.threads.runs.retrieve(runId, {
|
|
500
|
-
thread_id: thread.id,
|
|
501
|
-
});
|
|
502
|
-
await new Promise(resolve => setTimeout(resolve, 500)); // Wait before rechecking
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Waits for the assistant tool calls and handles them.
|
|
509
|
-
*
|
|
510
|
-
* This method polls an OpenAI Assistant run until it completes or requires action,
|
|
511
|
-
* handles any tool calls, and returns the final run object. It's designed for
|
|
512
|
-
* non-streaming Assistant interactions.
|
|
513
|
-
*
|
|
514
|
-
* @deprecated Assistant API is deprecated, please use responses or chat completions instead. It will be removed in the next major version.
|
|
515
|
-
*
|
|
516
|
-
* @param {string} userId - The user ID for authentication and tracking
|
|
517
|
-
* @param {OpenAI} client - The OpenAI client instance
|
|
518
|
-
* @param {OpenAI.Beta.Threads.Run} run - The initial run object
|
|
519
|
-
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
520
|
-
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
521
|
-
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
522
|
-
* @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* ```typescript
|
|
526
|
-
* // Process an OpenAI Assistant run with tool calls
|
|
527
|
-
* const thread = await openai.beta.threads.create();
|
|
528
|
-
* await openai.beta.threads.messages.create(thread.id, {
|
|
529
|
-
* role: 'user',
|
|
530
|
-
* content: 'Find information about Composio'
|
|
531
|
-
* });
|
|
532
|
-
*
|
|
533
|
-
* let run = await openai.beta.threads.runs.create(thread.id, {
|
|
534
|
-
* assistant_id: 'asst_abc123',
|
|
535
|
-
* tools: provider.wrapTools(composioTools)
|
|
536
|
-
* });
|
|
537
|
-
*
|
|
538
|
-
* // Wait for the run to complete, handling any tool calls
|
|
539
|
-
* run = await provider.waitAndHandleAssistantToolCalls(
|
|
540
|
-
* 'user123',
|
|
541
|
-
* openai,
|
|
542
|
-
* run,
|
|
543
|
-
* thread,
|
|
544
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
545
|
-
* );
|
|
546
|
-
*
|
|
547
|
-
* // Get the final messages after run completion
|
|
548
|
-
* const messages = await openai.beta.threads.messages.list(thread.id);
|
|
549
|
-
* console.log(messages.data[0].content);
|
|
550
|
-
* ```
|
|
551
|
-
*/
|
|
552
|
-
async waitAndHandleAssistantToolCalls(
|
|
553
|
-
userId: string,
|
|
554
|
-
client: OpenAI,
|
|
555
|
-
run: OpenAI.Beta.Threads.Run,
|
|
556
|
-
thread: OpenAI.Beta.Threads.Thread,
|
|
557
|
-
options?: ExecuteToolFnOptions,
|
|
558
|
-
modifiers?: ExecuteToolModifiers
|
|
559
|
-
) {
|
|
560
|
-
while (['queued', 'in_progress', 'requires_action'].includes(run.status)) {
|
|
561
|
-
// logger.debug(`Current run status: ${run.status}`);
|
|
562
|
-
const tool_outputs = await this.handleAssistantMessage(userId, run, options, modifiers);
|
|
563
|
-
if (run.status === 'requires_action') {
|
|
564
|
-
// logger.debug(
|
|
565
|
-
// `Submitting tool outputs for run ID: ${run.id} in thread ID: ${thread.id}`
|
|
566
|
-
// );
|
|
567
|
-
run = await client.beta.threads.runs.submitToolOutputs(run.id, {
|
|
568
|
-
thread_id: thread.id,
|
|
569
|
-
tool_outputs: tool_outputs,
|
|
570
|
-
});
|
|
571
|
-
} else {
|
|
572
|
-
run = await client.beta.threads.runs.retrieve(run.id, {
|
|
573
|
-
thread_id: thread.id,
|
|
574
|
-
});
|
|
575
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
return run;
|
|
579
|
-
}
|
|
580
297
|
}
|
|
@@ -94,8 +94,10 @@ export class TelemetryTransport {
|
|
|
94
94
|
*/
|
|
95
95
|
instrument<T extends object>(instance: T, fileName?: string) {
|
|
96
96
|
const proto = Object.getPrototypeOf(instance);
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
// Objects returned by factory functions carry their methods as own properties.
|
|
98
|
+
const methodSource = proto === Object.prototype || proto === null ? instance : proto;
|
|
99
|
+
const methodNames = Object.getOwnPropertyNames(methodSource).filter(key => {
|
|
100
|
+
const descriptor = Object.getOwnPropertyDescriptor(methodSource, key);
|
|
99
101
|
return (
|
|
100
102
|
key !== 'constructor' &&
|
|
101
103
|
descriptor &&
|
package/src/types/logs.types.ts
CHANGED
|
@@ -56,6 +56,14 @@ export const ToolExecutionLogParentSchema = z
|
|
|
56
56
|
})
|
|
57
57
|
.nullable();
|
|
58
58
|
|
|
59
|
+
/** Tool log metadata, including the optional exact USD Instant charge. */
|
|
60
|
+
export const ToolExecutionLogMetadataSchema = z
|
|
61
|
+
.object({
|
|
62
|
+
instant_charge: z.string().optional(),
|
|
63
|
+
})
|
|
64
|
+
.catchall(z.unknown());
|
|
65
|
+
export type ToolExecutionLogMetadata = z.infer<typeof ToolExecutionLogMetadataSchema>;
|
|
66
|
+
|
|
59
67
|
/**
|
|
60
68
|
* A tool-execution log entry as returned by `composio.logs.search()`.
|
|
61
69
|
*/
|
|
@@ -68,7 +76,7 @@ export const ToolExecutionLogSchema = z.object({
|
|
|
68
76
|
status: ToolExecutionLogStatusSchema,
|
|
69
77
|
level: ToolExecutionLogLevelSchema,
|
|
70
78
|
message: z.string().optional(),
|
|
71
|
-
metadata:
|
|
79
|
+
metadata: ToolExecutionLogMetadataSchema,
|
|
72
80
|
metrics: z.record(z.string(), z.unknown()),
|
|
73
81
|
parent: ToolExecutionLogParentSchema,
|
|
74
82
|
});
|
package/src/types/tool.types.ts
CHANGED
|
@@ -347,7 +347,7 @@ export type CustomAuthParams = z.infer<typeof CustomAuthParamsSchema>;
|
|
|
347
347
|
* Parameters for tool execution.
|
|
348
348
|
*
|
|
349
349
|
* @property {boolean} [allowTracing] - Enable tracing for this tool execution
|
|
350
|
-
* @property {string} [connectedAccountId] -
|
|
350
|
+
* @property {string} [connectedAccountId] - Connected account ID, or `instant_account` to explicitly use the Composio Instant account
|
|
351
351
|
* @property {CustomAuthParams} [customAuthParams] - Custom authentication parameters
|
|
352
352
|
* @property {CustomConnectionData} [customConnectionData] - Custom connection data (takes priority over customAuthParams)
|
|
353
353
|
* @property {Record<string, unknown>} [arguments] - The arguments to pass to the tool
|
|
@@ -407,8 +407,8 @@ export const ToolExecuteResponseSchema = z.object({
|
|
|
407
407
|
successful: z.boolean(),
|
|
408
408
|
logId: z.string().optional(),
|
|
409
409
|
sessionInfo: z.unknown().optional(),
|
|
410
|
-
/** Actual
|
|
411
|
-
|
|
410
|
+
/** Actual Instant usage charge when the Session opts into returning it. */
|
|
411
|
+
instantCharge: z.unknown().optional(),
|
|
412
412
|
});
|
|
413
413
|
export type ToolExecuteResponse = z.infer<typeof ToolExecuteResponseSchema>;
|
|
414
414
|
|
|
@@ -108,8 +108,8 @@ export const ToolRouterToolkitsEnabledConfigSchema = z
|
|
|
108
108
|
})
|
|
109
109
|
.strict();
|
|
110
110
|
|
|
111
|
-
/** Experimental
|
|
112
|
-
export const
|
|
111
|
+
/** Experimental Instant usage policy for a Session. */
|
|
112
|
+
export const ToolRouterInstantSchema = z.union([
|
|
113
113
|
z.literal(false),
|
|
114
114
|
z
|
|
115
115
|
.object({
|
|
@@ -126,15 +126,15 @@ export const ToolRouterPremiumUsageSchema = z.union([
|
|
|
126
126
|
)
|
|
127
127
|
.optional(),
|
|
128
128
|
/**
|
|
129
|
-
* Return the actual
|
|
130
|
-
* visibility only; on update, any policy object still re-enables
|
|
129
|
+
* Return the actual Instant charge in Session tool responses. Controls
|
|
130
|
+
* visibility only; on update, any policy object still re-enables Instant
|
|
131
131
|
* usage on a Session set to `false`.
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
returnInstantCharge: z.boolean().optional(),
|
|
134
134
|
})
|
|
135
135
|
.strict(),
|
|
136
136
|
]);
|
|
137
|
-
export type
|
|
137
|
+
export type ToolRouterInstant = z.infer<typeof ToolRouterInstantSchema>;
|
|
138
138
|
|
|
139
139
|
export const ToolRouterManageConnectionsConfigSchema = z.object({
|
|
140
140
|
enable: z
|
|
@@ -265,8 +265,8 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
265
265
|
.optional()
|
|
266
266
|
.describe('The toolkits to use in the tool router session'),
|
|
267
267
|
|
|
268
|
-
|
|
269
|
-
'Experimental
|
|
268
|
+
instant: ToolRouterInstantSchema.optional().describe(
|
|
269
|
+
'Experimental Instant usage policy. Omission permits eligible tools when the project allows Instant usage; false disables it for this Session.'
|
|
270
270
|
),
|
|
271
271
|
|
|
272
272
|
authConfigs: z
|
|
@@ -426,7 +426,7 @@ export const ToolRouterCreateSessionConfigSchema = z
|
|
|
426
426
|
* @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
|
|
427
427
|
* @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
|
|
428
428
|
* @param {Record<string, string | string[]>} connectedAccounts - The connected accounts to use in the tool router session. A single string is coerced to a single-element array before being sent to the backend.
|
|
429
|
-
* @param {
|
|
429
|
+
* @param {ToolRouterInstant} [instant] - Experimental Instant usage policy. The project must allow Instant usage.
|
|
430
430
|
* @param {ToolRouterConfigManageConnectionsSchema | boolean} manageConnections - The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.
|
|
431
431
|
* @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
|
|
432
432
|
* @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session
|
|
@@ -608,8 +608,8 @@ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
|
|
|
608
608
|
statusMessage: z.string(),
|
|
609
609
|
connectionDetails: z.record(z.string(), z.unknown()).optional(),
|
|
610
610
|
currentUserInfo: z.record(z.string(), z.unknown()).optional(),
|
|
611
|
-
/** Present when the toolkit runs on a Composio
|
|
612
|
-
|
|
611
|
+
/** Present when the toolkit runs on a Composio Instant account; only these tools run on it. */
|
|
612
|
+
instantAccount: z.object({ allowedToolSlugs: z.array(z.string()) }).optional(),
|
|
613
613
|
});
|
|
614
614
|
|
|
615
615
|
export const ToolRouterSessionSearchResponseSchema = z.object({
|
|
@@ -630,8 +630,8 @@ export const ToolRouterSessionExecuteResponseSchema = z.object({
|
|
|
630
630
|
data: z.record(z.string(), z.unknown()),
|
|
631
631
|
error: z.string().nullable(),
|
|
632
632
|
logId: z.string(),
|
|
633
|
-
/** Actual
|
|
634
|
-
|
|
633
|
+
/** Actual Instant usage charge when the Session opts into returning it. */
|
|
634
|
+
instantCharge: z.unknown().optional(),
|
|
635
635
|
});
|
|
636
636
|
export type ToolRouterSessionExecuteResponse = z.infer<
|
|
637
637
|
typeof ToolRouterSessionExecuteResponseSchema
|
|
@@ -692,7 +692,8 @@ export type ToolRouterSessionExecuteFn = (
|
|
|
692
692
|
|
|
693
693
|
export interface ToolRouterSessionExecuteOptions {
|
|
694
694
|
/**
|
|
695
|
-
* Account identifier for direct app tool execution.
|
|
695
|
+
* Account identifier for direct app tool execution. Use `instant_account` to
|
|
696
|
+
* explicitly select the Composio Instant account. Accepted on every project:
|
|
696
697
|
* in multi-account sessions it picks the account; on single-account projects it
|
|
697
698
|
* must match one of the session's active connections for the toolkit.
|
|
698
699
|
* Meta/helper tools either ignore this top-level field or define
|
|
@@ -708,12 +709,28 @@ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Work
|
|
|
708
709
|
|
|
709
710
|
export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
|
|
710
711
|
|
|
712
|
+
const ToolRouterInstantResponseFilterSchema = z.union([
|
|
713
|
+
z.object({ enabled: z.array(z.string()) }),
|
|
714
|
+
z.object({ disabled: z.array(z.string()) }),
|
|
715
|
+
]);
|
|
716
|
+
|
|
717
|
+
/** Instant policy in the server's Session config (wire field casing). */
|
|
718
|
+
export const ToolRouterInstantResponseSchema = z.object({
|
|
719
|
+
toolkits: ToolRouterInstantResponseFilterSchema.optional(),
|
|
720
|
+
tools: z.record(z.string(), ToolRouterInstantResponseFilterSchema).optional(),
|
|
721
|
+
return_instant_charge: z.boolean(),
|
|
722
|
+
});
|
|
723
|
+
export type ToolRouterInstantResponse = z.infer<typeof ToolRouterInstantResponseSchema>;
|
|
724
|
+
|
|
711
725
|
/**
|
|
712
|
-
* Server-side session configuration as returned by the API: toolkit
|
|
726
|
+
* Server-side session configuration as returned by the API: toolkit/tool
|
|
713
727
|
* allowlists, tags, auth configs, connected accounts, manage_connections,
|
|
714
|
-
* preload, sandbox (`workbench`), search and
|
|
728
|
+
* preload, sandbox (`workbench`), search, execute and Instant settings.
|
|
729
|
+
* The generated client still declares the old policy name.
|
|
715
730
|
*/
|
|
716
|
-
export type ToolRouterSessionConfig = SessionCreateResponse.Config
|
|
731
|
+
export type ToolRouterSessionConfig = Omit<SessionCreateResponse.Config, 'premium_usage'> & {
|
|
732
|
+
instant?: false | ToolRouterInstantResponse;
|
|
733
|
+
};
|
|
717
734
|
|
|
718
735
|
export interface ToolRouterSessionMetadata {
|
|
719
736
|
/** Present on every session built from an API response; the constructor synthesises a minimal config when absent. */
|
|
@@ -858,8 +875,8 @@ export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdate
|
|
|
858
875
|
*/
|
|
859
876
|
export const ToolRouterUpdateSessionConfigSchema = z
|
|
860
877
|
.object({
|
|
861
|
-
|
|
862
|
-
'Experimental
|
|
878
|
+
instant: ToolRouterInstantSchema.optional().describe(
|
|
879
|
+
'Experimental Instant usage policy. False disables it. Any supplied object, even one that only sets returnInstantCharge, re-enables it. Omitted subfields keep their stored values.'
|
|
863
880
|
),
|
|
864
881
|
toolkits: z
|
|
865
882
|
.union([
|
|
@@ -1027,9 +1044,14 @@ export type ToolRouterSessionListConfigHistoryOptions = z.infer<
|
|
|
1027
1044
|
|
|
1028
1045
|
/**
|
|
1029
1046
|
* The session configuration at one version, as stored by the API. This is
|
|
1030
|
-
* the wire shape (snake_case),
|
|
1047
|
+
* the wire shape (snake_case), with the Instant policy under `instant`.
|
|
1031
1048
|
*/
|
|
1032
|
-
export type ToolRouterSessionConfigHistoryConfig =
|
|
1049
|
+
export type ToolRouterSessionConfigHistoryConfig = Omit<
|
|
1050
|
+
SessionConfigHistoryResponse.Item.Config,
|
|
1051
|
+
'premium_usage'
|
|
1052
|
+
> & {
|
|
1053
|
+
instant?: false | ToolRouterInstantResponse;
|
|
1054
|
+
};
|
|
1033
1055
|
|
|
1034
1056
|
export type ToolRouterSessionConfigHistoryItem = {
|
|
1035
1057
|
/** The config version this entry represents. */
|
package/src/types/usage.types.ts
CHANGED
|
@@ -61,6 +61,8 @@ export type UsageEntitySummary = z.infer<typeof UsageEntitySummarySchema>;
|
|
|
61
61
|
export const UsageSummaryResponseSchema = z.object({
|
|
62
62
|
/** Aggregates keyed by metering entity type (e.g. `tool_calls`, `sessions`). */
|
|
63
63
|
entities: z.record(z.string(), UsageEntitySummarySchema),
|
|
64
|
+
/** Total Instant charge for the window, in USD as an exact decimal string. */
|
|
65
|
+
instantCharge: z.string(),
|
|
64
66
|
});
|
|
65
67
|
export type UsageSummaryResponse = z.infer<typeof UsageSummaryResponseSchema>;
|
|
66
68
|
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
ToolExecutionLog,
|
|
11
11
|
ToolExecutionLogDetail,
|
|
12
12
|
ToolExecutionLogDetailSchema,
|
|
13
|
+
ToolExecutionLogMetadataSchema,
|
|
13
14
|
ToolExecutionLogSchema,
|
|
14
15
|
} from '../../types/logs.types';
|
|
15
16
|
import { transform } from '../transform';
|
|
@@ -33,7 +34,7 @@ export const transformToolExecutionLog = (
|
|
|
33
34
|
status: response.status,
|
|
34
35
|
level: response.level,
|
|
35
36
|
message: response.message,
|
|
36
|
-
metadata: response.metadata,
|
|
37
|
+
metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
|
|
37
38
|
metrics: response.metrics,
|
|
38
39
|
parent: response.parent
|
|
39
40
|
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
@@ -62,7 +63,7 @@ export const transformToolExecutionLogDetail = (
|
|
|
62
63
|
status: response.status,
|
|
63
64
|
level: response.level,
|
|
64
65
|
message: response.message,
|
|
65
|
-
metadata: response.metadata,
|
|
66
|
+
metadata: ToolExecutionLogMetadataSchema.parse(response.metadata),
|
|
66
67
|
metrics: response.metrics,
|
|
67
68
|
parent: response.parent
|
|
68
69
|
? { logId: response.parent.log_id, toolSlug: response.parent.tool_slug }
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transforms snake_case Tool Router API responses to camelCase for SDK consumers.
|
|
3
3
|
*/
|
|
4
|
+
import { z } from 'zod/v3';
|
|
5
|
+
import {
|
|
6
|
+
ToolRouterInstantResponseSchema,
|
|
7
|
+
type ToolRouterInstantResponse,
|
|
8
|
+
} from '../../types/toolRouter.types';
|
|
9
|
+
|
|
10
|
+
const SessionConfigInstantSchema = z.object({
|
|
11
|
+
instant: z.union([z.literal(false), ToolRouterInstantResponseSchema]).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** Session config retains its API casing, including `instant.return_instant_charge`. */
|
|
15
|
+
export function transformSessionConfig<Config extends { premium_usage?: unknown }>(
|
|
16
|
+
raw: Config
|
|
17
|
+
): Omit<Config, 'premium_usage'> & { instant?: false | ToolRouterInstantResponse } {
|
|
18
|
+
const { instant } = SessionConfigInstantSchema.parse(raw);
|
|
19
|
+
const { premium_usage: _previousPolicy, ...config } = raw;
|
|
20
|
+
return { ...config, ...(instant !== undefined && { instant }) };
|
|
21
|
+
}
|
|
4
22
|
|
|
5
23
|
interface RawSearchResult {
|
|
6
24
|
index: number;
|
|
@@ -51,7 +69,7 @@ interface RawToolkitConnectionStatus {
|
|
|
51
69
|
status_message: string;
|
|
52
70
|
connection_details?: Record<string, unknown>;
|
|
53
71
|
current_user_info?: Record<string, unknown>;
|
|
54
|
-
|
|
72
|
+
instant_account?: { allowed_tool_slugs: string[] };
|
|
55
73
|
}
|
|
56
74
|
|
|
57
75
|
interface RawSearchResponse {
|
|
@@ -69,7 +87,7 @@ interface RawExecuteResponse {
|
|
|
69
87
|
data: Record<string, unknown>;
|
|
70
88
|
error: string | null;
|
|
71
89
|
log_id: string;
|
|
72
|
-
|
|
90
|
+
instant_charge?: unknown;
|
|
73
91
|
}
|
|
74
92
|
|
|
75
93
|
function transformSearchResult(raw: RawSearchResult) {
|
|
@@ -116,8 +134,8 @@ function transformToolkitConnectionStatus(raw: RawToolkitConnectionStatus) {
|
|
|
116
134
|
statusMessage: raw.status_message,
|
|
117
135
|
connectionDetails: raw.connection_details,
|
|
118
136
|
currentUserInfo: raw.current_user_info,
|
|
119
|
-
...(raw.
|
|
120
|
-
|
|
137
|
+
...(raw.instant_account !== undefined && {
|
|
138
|
+
instantAccount: { allowedToolSlugs: raw.instant_account.allowed_tool_slugs },
|
|
121
139
|
}),
|
|
122
140
|
};
|
|
123
141
|
}
|
|
@@ -161,6 +179,6 @@ export function transformExecuteResponse(raw: RawExecuteResponse) {
|
|
|
161
179
|
data: raw.data,
|
|
162
180
|
error: raw.error,
|
|
163
181
|
logId: raw.log_id,
|
|
164
|
-
...(raw.
|
|
182
|
+
...(raw.instant_charge !== undefined && { instantCharge: raw.instant_charge }),
|
|
165
183
|
};
|
|
166
184
|
}
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
UsageRetrieveSummaryParams as RawUsageSummaryParams,
|
|
5
5
|
UsageRetrieveSummaryResponse as RawUsageSummaryResponse,
|
|
6
6
|
} from '@composio/client/resources/project/usage';
|
|
7
|
+
import { z } from 'zod/v3';
|
|
7
8
|
import {
|
|
8
9
|
UsageBreakdownParams,
|
|
9
10
|
UsageBreakdownResponse,
|
|
@@ -42,6 +43,8 @@ export const transformUsageBreakdownParams = (
|
|
|
42
43
|
export const transformUsageSummaryResponse = (
|
|
43
44
|
response: RawUsageSummaryResponse
|
|
44
45
|
): UsageSummaryResponse => {
|
|
46
|
+
// The pinned generated client predates this response field but preserves the raw JSON.
|
|
47
|
+
const { instant_charge } = z.object({ instant_charge: z.string() }).parse(response);
|
|
45
48
|
return transform(response)
|
|
46
49
|
.with(UsageSummaryResponseSchema)
|
|
47
50
|
.using(response => ({
|
|
@@ -55,6 +58,7 @@ export const transformUsageSummaryResponse = (
|
|
|
55
58
|
},
|
|
56
59
|
])
|
|
57
60
|
),
|
|
61
|
+
instantCharge: instant_charge,
|
|
58
62
|
}));
|
|
59
63
|
};
|
|
60
64
|
|