@zuora/agent-toolkit 0.0.1-alpha.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/README.md +298 -0
- package/dist/async-jobs-Dd8Jafv0.d.ts +532 -0
- package/dist/bundle-catalog-3V6EICKE.json +289 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +496 -0
- package/dist/index.js.map +1 -0
- package/dist/langchain/index.d.ts +2 -0
- package/dist/langchain/index.js +1 -0
- package/dist/langchain/index.js.map +1 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/openai/index.d.ts +165 -0
- package/dist/openai/index.js +5257 -0
- package/dist/openai/index.js.map +1 -0
- package/dist/openai-agents/index.d.ts +94 -0
- package/dist/openai-agents/index.js +5203 -0
- package/dist/openai-agents/index.js.map +1 -0
- package/dist/shared/resources/bundle-catalog.json +289 -0
- package/dist/shared/toolkit-core.d.ts +73 -0
- package/dist/shared/toolkit-core.js +4686 -0
- package/dist/shared/toolkit-core.js.map +1 -0
- package/dist/toolkit-CafRZuAV.d.ts +31 -0
- package/dist/vercel-ai/index.d.ts +2 -0
- package/dist/vercel-ai/index.js +1 -0
- package/dist/vercel-ai/index.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Z as ZuoraOpenAIAgentToolkit } from '../toolkit-CafRZuAV.js';
|
|
2
|
+
export { c as createZuoraOpenAIAgentToolkit } from '../toolkit-CafRZuAV.js';
|
|
3
|
+
import { ChatCompletion, ChatCompletionToolMessageParam } from 'openai/resources/chat/completions';
|
|
4
|
+
import { b as ZuoraToolExecutionResult, Z as ZuoraToolDefinition, c as ZuoraAsyncJobResult } from '../async-jobs-Dd8Jafv0.js';
|
|
5
|
+
import '../shared/toolkit-core.js';
|
|
6
|
+
|
|
7
|
+
type ZuoraOpenAIToolExecutionContext = {
|
|
8
|
+
toolName: string;
|
|
9
|
+
input: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Return value from `shouldExecute` when the hook wants to decline a tool call.
|
|
13
|
+
* Returning `void` (or `undefined`) from `shouldExecute` means proceed.
|
|
14
|
+
*/
|
|
15
|
+
type ZuoraToolDecision = {
|
|
16
|
+
/**
|
|
17
|
+
* Set to `true` to decline the tool call. `handleToolCalls` will inject a
|
|
18
|
+
* "declined" tool message into the conversation and skip execution.
|
|
19
|
+
* `onToolExecuted` and `onToolComplete` will not fire for declined calls.
|
|
20
|
+
*/
|
|
21
|
+
decline: true;
|
|
22
|
+
/**
|
|
23
|
+
* Optional message sent to the model explaining why the call was declined.
|
|
24
|
+
* Defaults to "The operation was not approved." when omitted.
|
|
25
|
+
* Keep it instructional — e.g. "User declined. Do not retry."
|
|
26
|
+
*/
|
|
27
|
+
message?: string;
|
|
28
|
+
};
|
|
29
|
+
type ZuoraOpenAIAgentToolkitHooks = {
|
|
30
|
+
onToolStart?: (context: ZuoraOpenAIToolExecutionContext) => void | Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Fires after the raw MCP result is received from `callTool`, before any
|
|
33
|
+
* async-job handling. Useful for logging or side-effects that must observe
|
|
34
|
+
* the exact, unmodified tool output.
|
|
35
|
+
*
|
|
36
|
+
* For async tools, `result.data` will be a pending `ZuoraAsyncJobResult`
|
|
37
|
+
* here even when `shouldAutoWait` returns `true` — `onToolExecuted` always
|
|
38
|
+
* sees the immediate return value. `onToolComplete` receives the final
|
|
39
|
+
* resolved result after any auto-waiting.
|
|
40
|
+
*
|
|
41
|
+
* `onToolExecuted` is not called when `callTool` throws.
|
|
42
|
+
*
|
|
43
|
+
* @param context.toolName - The name of the tool that was executed.
|
|
44
|
+
* @param context.input - The input arguments passed to the tool.
|
|
45
|
+
* @param context.result - The raw execution result from `callTool`.
|
|
46
|
+
*/
|
|
47
|
+
onToolExecuted?: (context: ZuoraOpenAIToolExecutionContext & {
|
|
48
|
+
result: ZuoraToolExecutionResult;
|
|
49
|
+
}) => void | Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Fires after all async-job handling is complete and the final result is
|
|
52
|
+
* ready to be sent back to the model.
|
|
53
|
+
*
|
|
54
|
+
* - For **synchronous tools**: `result` is the direct return value of
|
|
55
|
+
* `callTool` — identical to what `onToolExecuted` receives.
|
|
56
|
+
* - For **async tools with `shouldAutoWait: true`**: `result` is the final
|
|
57
|
+
* resolved value after `waitForJob()` finishes polling — it differs from
|
|
58
|
+
* the pending `result` that `onToolExecuted` received.
|
|
59
|
+
* - For **async tools with `shouldAutoWait: false`** (or unset): `result`
|
|
60
|
+
* is the pending async job result, same as `onToolExecuted`. The caller
|
|
61
|
+
* is expected to poll via `requireToolOnNextStep` / `loadFollowUpTools`.
|
|
62
|
+
*
|
|
63
|
+
* `onToolComplete` is not called when `callTool` throws — use error
|
|
64
|
+
* handling in the agent loop for that case.
|
|
65
|
+
*
|
|
66
|
+
* @param context.toolName - The name of the tool that completed.
|
|
67
|
+
* @param context.input - The input arguments passed to the tool.
|
|
68
|
+
* @param context.result - The final execution result (post async-wait).
|
|
69
|
+
*/
|
|
70
|
+
onToolComplete?: (context: ZuoraOpenAIToolExecutionContext & {
|
|
71
|
+
result: ZuoraToolExecutionResult;
|
|
72
|
+
}) => void | Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Controls whether `handleToolCalls` automatically polls an async job to
|
|
75
|
+
* completion before returning the result to the caller.
|
|
76
|
+
*
|
|
77
|
+
* When this hook returns `true` for a given async job, `handleToolCalls`
|
|
78
|
+
* will call `toolkit.waitForJob()` and return the final result instead of
|
|
79
|
+
* the pending async job result.
|
|
80
|
+
*
|
|
81
|
+
* When this hook returns `false` (or is not provided), the pending async
|
|
82
|
+
* job result is returned as-is and `requireToolOnNextStep` is set to `true`
|
|
83
|
+
* so the caller knows to continue the agent loop with a polling call.
|
|
84
|
+
*
|
|
85
|
+
* @param context.toolName - The name of the tool that started the async job.
|
|
86
|
+
* @param context.asyncResult - The pending async job result.
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* Called before each tool is executed. Return `{ decline: true }` to skip
|
|
90
|
+
* execution and inject a "declined" message into the conversation so the
|
|
91
|
+
* model can respond gracefully. Return `void` (or nothing) to proceed.
|
|
92
|
+
*
|
|
93
|
+
* Use this hook for interactive human-in-the-loop decisions — e.g. prompting
|
|
94
|
+
* the user at the CLI before a write operation runs. For automated policy
|
|
95
|
+
* enforcement that applies across all adapters, use `approvalPolicy` on the
|
|
96
|
+
* toolkit config instead.
|
|
97
|
+
*
|
|
98
|
+
* `context.tool` carries the full tool definition — `meta.access`,
|
|
99
|
+
* `meta.riskLevel`, `meta.bundle` — so the handler can make a
|
|
100
|
+
* context-aware decision without resolving the tool separately.
|
|
101
|
+
*
|
|
102
|
+
* `onToolExecuted` and `onToolComplete` do not fire for declined calls.
|
|
103
|
+
* `abortTurn` is NOT set — the agent loop continues after a decline.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* shouldExecute: async ({ toolName, input, tool }) => {
|
|
108
|
+
* if (tool.meta.access === "read") return; // reads proceed silently
|
|
109
|
+
* const ok = await askUser(`Allow ${toolName}?`);
|
|
110
|
+
* if (!ok) return { decline: true, message: "User declined. Do not retry." };
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
shouldExecute?: (context: ZuoraOpenAIToolExecutionContext & {
|
|
115
|
+
tool: ZuoraToolDefinition;
|
|
116
|
+
}) => void | ZuoraToolDecision | Promise<void | ZuoraToolDecision>;
|
|
117
|
+
/**
|
|
118
|
+
* Controls whether `handleToolCalls` automatically polls an async job to
|
|
119
|
+
* completion before returning the result to the caller.
|
|
120
|
+
*
|
|
121
|
+
* When this hook returns `true` for a given async job, `handleToolCalls`
|
|
122
|
+
* will call `toolkit.waitForJob()` and return the final result instead of
|
|
123
|
+
* the pending async job result.
|
|
124
|
+
*
|
|
125
|
+
* When this hook returns `false` (or is not provided), the pending async
|
|
126
|
+
* job result is returned as-is and `requireToolOnNextStep` is set to `true`
|
|
127
|
+
* so the caller knows to continue the agent loop with a polling call.
|
|
128
|
+
*
|
|
129
|
+
* @param context.toolName - The name of the tool that started the async job.
|
|
130
|
+
* @param context.asyncResult - The pending async job result.
|
|
131
|
+
*/
|
|
132
|
+
shouldAutoWait?: (context: ZuoraOpenAIToolExecutionContext & {
|
|
133
|
+
asyncResult: ZuoraAsyncJobResult;
|
|
134
|
+
}) => boolean | Promise<boolean>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
type HandleToolCallsInput = {
|
|
138
|
+
toolkit: ZuoraOpenAIAgentToolkit;
|
|
139
|
+
response: ChatCompletion;
|
|
140
|
+
hooks?: ZuoraOpenAIAgentToolkitHooks;
|
|
141
|
+
};
|
|
142
|
+
type HandleToolCallsResult = {
|
|
143
|
+
/** Tool message params to append to the conversation. */
|
|
144
|
+
messages: ChatCompletionToolMessageParam[];
|
|
145
|
+
/**
|
|
146
|
+
* True when a non-recoverable tool error occurred. The caller should break
|
|
147
|
+
* the agent loop rather than sending the messages back to the model.
|
|
148
|
+
*/
|
|
149
|
+
abortTurn: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* True when at least one async job is pending (status: "pending" was returned
|
|
152
|
+
* by a tool). The caller should set `tool_choice: "required"` on the next
|
|
153
|
+
* model call so the model continues polling rather than generating prose.
|
|
154
|
+
*/
|
|
155
|
+
requireToolOnNextStep: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Names of tools the server recommends calling next (e.g. the polling tool
|
|
158
|
+
* for an async job that was just started). The caller may use these to
|
|
159
|
+
* narrow the `tools` list on the next model call.
|
|
160
|
+
*/
|
|
161
|
+
followUpToolNames: string[];
|
|
162
|
+
};
|
|
163
|
+
declare const handleToolCalls: (input: HandleToolCallsInput) => Promise<HandleToolCallsResult>;
|
|
164
|
+
|
|
165
|
+
export { type HandleToolCallsInput, type HandleToolCallsResult, ZuoraOpenAIAgentToolkit, type ZuoraOpenAIAgentToolkitHooks, type ZuoraOpenAIToolExecutionContext, handleToolCalls };
|