sarvam-agents-client 0.3.0 → 0.3.1

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.
Files changed (125) hide show
  1. package/README.md +16 -1
  2. package/dist/apis/FunctionToolsApi.d.ts +33 -0
  3. package/dist/apis/FunctionToolsApi.js +65 -0
  4. package/dist/apis/index.d.ts +1 -0
  5. package/dist/apis/index.js +1 -0
  6. package/dist/compose/agent.d.ts +16 -3
  7. package/dist/compose/agent.js +76 -7
  8. package/dist/compose/errors.d.ts +5 -1
  9. package/dist/compose/errors.js +4 -1
  10. package/dist/compose/events.d.ts +4 -0
  11. package/dist/compose/events.js +34 -0
  12. package/dist/compose/functionTool.d.ts +101 -0
  13. package/dist/compose/functionTool.js +420 -0
  14. package/dist/compose/index.d.ts +5 -2
  15. package/dist/compose/index.js +3 -1
  16. package/dist/compose/output.d.ts +11 -0
  17. package/dist/compose/output.js +32 -7
  18. package/dist/compose/run.d.ts +5 -1
  19. package/dist/compose/run.js +118 -25
  20. package/dist/compose/runState.d.ts +26 -1
  21. package/dist/compose/runState.js +30 -0
  22. package/dist/compose/settingsTransport.d.ts +20 -1
  23. package/dist/compose/settingsTransport.js +295 -3
  24. package/dist/compose/transport.d.ts +18 -1
  25. package/dist/esm/apis/FunctionToolsApi.d.ts +33 -0
  26. package/dist/esm/apis/FunctionToolsApi.js +61 -0
  27. package/dist/esm/apis/index.d.ts +1 -0
  28. package/dist/esm/apis/index.js +1 -0
  29. package/dist/esm/compose/agent.d.ts +16 -3
  30. package/dist/esm/compose/agent.js +76 -7
  31. package/dist/esm/compose/errors.d.ts +5 -1
  32. package/dist/esm/compose/errors.js +4 -1
  33. package/dist/esm/compose/events.d.ts +4 -0
  34. package/dist/esm/compose/events.js +33 -0
  35. package/dist/esm/compose/functionTool.d.ts +101 -0
  36. package/dist/esm/compose/functionTool.js +406 -0
  37. package/dist/esm/compose/index.d.ts +5 -2
  38. package/dist/esm/compose/index.js +1 -0
  39. package/dist/esm/compose/output.d.ts +11 -0
  40. package/dist/esm/compose/output.js +30 -9
  41. package/dist/esm/compose/run.d.ts +5 -1
  42. package/dist/esm/compose/run.js +118 -25
  43. package/dist/esm/compose/runState.d.ts +26 -1
  44. package/dist/esm/compose/runState.js +31 -1
  45. package/dist/esm/compose/settingsTransport.d.ts +20 -1
  46. package/dist/esm/compose/settingsTransport.js +298 -7
  47. package/dist/esm/compose/transport.d.ts +18 -1
  48. package/dist/esm/models/AgentConversationDetail.d.ts +7 -0
  49. package/dist/esm/models/AgentConversationDetail.js +3 -0
  50. package/dist/esm/models/ClarifyBody.d.ts +6 -0
  51. package/dist/esm/models/ClarifyBody.js +2 -0
  52. package/dist/esm/models/ConversationDetail.d.ts +7 -0
  53. package/dist/esm/models/ConversationDetail.js +3 -0
  54. package/dist/esm/models/ErrorDetail.d.ts +1 -0
  55. package/dist/esm/models/ErrorDetail.js +2 -1
  56. package/dist/esm/models/FunctionResultBody.d.ts +44 -0
  57. package/dist/esm/models/FunctionResultBody.js +49 -0
  58. package/dist/esm/models/QueueMessageInput.d.ts +23 -0
  59. package/dist/esm/models/QueueMessageInput.js +14 -0
  60. package/dist/esm/models/RequiredAction.d.ts +77 -0
  61. package/dist/esm/models/RequiredAction.js +69 -0
  62. package/dist/esm/models/ResponseDetail.d.ts +8 -0
  63. package/dist/esm/models/ResponseDetail.js +2 -0
  64. package/dist/esm/models/ResponseInput.d.ts +23 -0
  65. package/dist/esm/models/ResponseInput.js +14 -0
  66. package/dist/esm/models/ToolResults200Response.d.ts +38 -0
  67. package/dist/esm/models/ToolResults200Response.js +47 -0
  68. package/dist/esm/models/ToolResultsBody.d.ts +39 -0
  69. package/dist/esm/models/ToolResultsBody.js +48 -0
  70. package/dist/esm/models/index.d.ts +4 -0
  71. package/dist/esm/models/index.js +4 -0
  72. package/dist/esm/streaming.d.ts +14 -2
  73. package/dist/esm/streaming.js +26 -4
  74. package/dist/models/AgentConversationDetail.d.ts +7 -0
  75. package/dist/models/AgentConversationDetail.js +3 -0
  76. package/dist/models/ClarifyBody.d.ts +6 -0
  77. package/dist/models/ClarifyBody.js +2 -0
  78. package/dist/models/ConversationDetail.d.ts +7 -0
  79. package/dist/models/ConversationDetail.js +3 -0
  80. package/dist/models/ErrorDetail.d.ts +1 -0
  81. package/dist/models/ErrorDetail.js +2 -1
  82. package/dist/models/FunctionResultBody.d.ts +44 -0
  83. package/dist/models/FunctionResultBody.js +56 -0
  84. package/dist/models/QueueMessageInput.d.ts +23 -0
  85. package/dist/models/QueueMessageInput.js +15 -1
  86. package/dist/models/RequiredAction.d.ts +77 -0
  87. package/dist/models/RequiredAction.js +77 -0
  88. package/dist/models/ResponseDetail.d.ts +8 -0
  89. package/dist/models/ResponseDetail.js +2 -0
  90. package/dist/models/ResponseInput.d.ts +23 -0
  91. package/dist/models/ResponseInput.js +15 -0
  92. package/dist/models/ToolResults200Response.d.ts +38 -0
  93. package/dist/models/ToolResults200Response.js +54 -0
  94. package/dist/models/ToolResultsBody.d.ts +39 -0
  95. package/dist/models/ToolResultsBody.js +55 -0
  96. package/dist/models/index.d.ts +4 -0
  97. package/dist/models/index.js +4 -0
  98. package/dist/streaming.d.ts +14 -2
  99. package/dist/streaming.js +27 -4
  100. package/package.json +1 -1
  101. package/src/apis/FunctionToolsApi.ts +102 -0
  102. package/src/apis/index.ts +1 -0
  103. package/src/compose/agent.ts +87 -9
  104. package/src/compose/errors.ts +7 -1
  105. package/src/compose/events.ts +30 -0
  106. package/src/compose/functionTool.ts +441 -0
  107. package/src/compose/index.ts +5 -2
  108. package/src/compose/output.ts +30 -9
  109. package/src/compose/run.ts +115 -18
  110. package/src/compose/runState.ts +44 -5
  111. package/src/compose/settingsTransport.ts +293 -7
  112. package/src/compose/transport.ts +24 -1
  113. package/src/models/AgentConversationDetail.ts +15 -0
  114. package/src/models/ClarifyBody.ts +8 -0
  115. package/src/models/ConversationDetail.ts +15 -0
  116. package/src/models/ErrorDetail.ts +2 -1
  117. package/src/models/FunctionResultBody.ts +83 -0
  118. package/src/models/QueueMessageInput.ts +28 -0
  119. package/src/models/RequiredAction.ts +128 -0
  120. package/src/models/ResponseDetail.ts +8 -0
  121. package/src/models/ResponseInput.ts +30 -0
  122. package/src/models/ToolResults200Response.ts +75 -0
  123. package/src/models/ToolResultsBody.ts +83 -0
  124. package/src/models/index.ts +4 -0
  125. package/src/streaming.ts +39 -3
@@ -1,6 +1,7 @@
1
1
  import { NotSupportedError, UserError } from "./errors.js";
2
2
  import { settingsFingerprint } from "./fingerprint.js";
3
3
  import { BUILTIN_NAMES, checkWebSearchOptions } from "./builtins.js";
4
+ import { DEFAULT_FUNCTION_TIMEOUT_SECONDS, FUNCTION_TIMEOUT_RANGE, FUNCTIONS_MAX, FUNCTIONS_TOTAL_MAX_BYTES, compactBytes, functionToolSettings, isBuiltFunctionTool, isFunctionTool, tool, } from "./functionTool.js";
4
5
  import { checkOutputType, outputSchema } from "./output.js";
5
6
  const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
6
7
  const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
@@ -75,10 +76,18 @@ export class Agent {
75
76
  constructor(rawOpts) {
76
77
  var _a, _b;
77
78
  const opts = normalize(rawOpts);
78
- for (const tool of (_a = opts.tools) !== null && _a !== void 0 ? _a : []) {
79
+ for (const tool of ((_a = opts.tools) !== null && _a !== void 0 ? _a : [])) {
79
80
  if (tool instanceof Agent) {
80
81
  throw new NotSupportedError("sub-agents in tools are not supported yet (field: tools)");
81
82
  }
83
+ if (typeof tool === "function") {
84
+ throw new UserError(`tools: ${tool.name || "a function"} is not a tool; wrap it with tool({ name, description, ` +
85
+ "parameters, execute })");
86
+ }
87
+ if (tool === null || typeof tool !== "object" || Array.isArray(tool)) {
88
+ throw new UserError(`tools: ${JSON.stringify(tool)} is not a tool; list built-ins (sandbox(), webSearchTool(), ...) ` +
89
+ "and tool() function tools");
90
+ }
82
91
  }
83
92
  checkNumbers(opts);
84
93
  this.name = opts.name;
@@ -87,7 +96,17 @@ export class Agent {
87
96
  this.endpoint = opts.endpoint;
88
97
  this.modelSettings = clone(opts.modelSettings);
89
98
  this.fallbackModels = clone(opts.fallbackModels);
90
- this.tools = clone(opts.tools);
99
+ // A function tool is kept by reference (it holds execute and maybe a zod schema); an object literal of that shape
100
+ // goes through tool().
101
+ this.tools = opts.tools === undefined ? undefined
102
+ : opts.tools.map((t) => {
103
+ if (isBuiltFunctionTool(t))
104
+ return t;
105
+ if (isFunctionTool(t))
106
+ return tool(t);
107
+ return clone(t);
108
+ });
109
+ this.functionTimeoutSeconds = opts.functionTimeoutSeconds;
91
110
  this.limits = clone(opts.limits);
92
111
  this.metadata = clone(opts.metadata);
93
112
  Object.defineProperty(this, "outputType", { value: opts.outputType, enumerable: false, writable: false });
@@ -95,7 +114,6 @@ export class Agent {
95
114
  deepFreeze(this);
96
115
  }
97
116
  check() {
98
- var _a, _b;
99
117
  if (typeof this.name !== "string" || !SLUG.test(this.name)) {
100
118
  throw new UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
101
119
  }
@@ -143,7 +161,7 @@ export class Agent {
143
161
  throw new UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
144
162
  }
145
163
  }
146
- const names = ((_a = this.tools) !== null && _a !== void 0 ? _a : []).map((t) => t.name);
164
+ const names = this.builtinTools.map((t) => t.name);
147
165
  for (const n of names) {
148
166
  if (BUILTIN_NAMES.indexOf(n) === -1) {
149
167
  throw new UserError(`tools: unknown built-in tool ${JSON.stringify(n)} (known: ${BUILTIN_NAMES.join(", ")})`);
@@ -153,7 +171,7 @@ export class Agent {
153
171
  if (dupes.length > 0) {
154
172
  throw new UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
155
173
  }
156
- for (const t of (_b = this.tools) !== null && _b !== void 0 ? _b : []) {
174
+ for (const t of this.builtinTools) {
157
175
  if (t.options === undefined || Object.keys(t.options).length === 0)
158
176
  continue;
159
177
  if (t.name !== "web_search")
@@ -163,6 +181,49 @@ export class Agent {
163
181
  if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
164
182
  throw new UserError("tools: codeMode needs sandbox; add sandbox() to tools");
165
183
  }
184
+ this.checkFunctions();
185
+ }
186
+ checkFunctions() {
187
+ const functions = this.functionTools;
188
+ if (functions.length > FUNCTIONS_MAX) {
189
+ throw new UserError(`tools: at most ${FUNCTIONS_MAX} function tools (got ${functions.length})`);
190
+ }
191
+ const names = functions.map((t) => t.name);
192
+ const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
193
+ if (dupes.length > 0)
194
+ throw new UserError(`tools: duplicate function tool(s): ${dupes.join(", ")}`);
195
+ const total = functions.reduce((sum, t) => sum + compactBytes(functionToolSettings(t)), 0);
196
+ if (total > FUNCTIONS_TOTAL_MAX_BYTES) {
197
+ throw new UserError(`tools: function tools are ${Math.ceil(total / 1024)} KB together (names, descriptions and ` +
198
+ "parameters); the server allows 64 KB, because every model call carries them");
199
+ }
200
+ const timeout = this.functionTimeoutSeconds;
201
+ if (timeout !== undefined) {
202
+ const [low, high] = FUNCTION_TIMEOUT_RANGE;
203
+ if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < low || timeout > high) {
204
+ throw new UserError(`functionTimeoutSeconds: must be a whole number of seconds from ${low} to ${high}`);
205
+ }
206
+ }
207
+ // A call still running when the server's deadline passes is answered too late (409 expired) and the run fails;
208
+ // one that times out here first goes to the model as a failed result in time.
209
+ const deadline = timeout !== null && timeout !== void 0 ? timeout : DEFAULT_FUNCTION_TIMEOUT_SECONDS;
210
+ for (const t of functions) {
211
+ if (t.timeoutMs >= deadline * 1000) {
212
+ throw new UserError(`${t.name}: timeoutMs=${t.timeoutMs} (${t.timeoutMs / 1000}s) must be shorter than the ` +
213
+ `agent's functionTimeoutSeconds (${deadline}s${timeout === undefined ? ", the server default" : ""}); ` +
214
+ "lower the tool's timeoutMs or raise functionTimeoutSeconds");
215
+ }
216
+ }
217
+ }
218
+ /** The built-in tools in `tools`, in order. */
219
+ get builtinTools() {
220
+ var _a;
221
+ return ((_a = this.tools) !== null && _a !== void 0 ? _a : []).filter((t) => !isFunctionTool(t));
222
+ }
223
+ /** The function tools in `tools`, in order. */
224
+ get functionTools() {
225
+ var _a;
226
+ return ((_a = this.tools) !== null && _a !== void 0 ? _a : []).filter(isFunctionTool);
166
227
  }
167
228
  baseSettings() {
168
229
  const out = { version: 1 };
@@ -197,15 +258,23 @@ export class Agent {
197
258
  out["limits"] = limits;
198
259
  }
199
260
  if (this.tools !== undefined) {
200
- // Built-ins are on by default, so an exact list writes every unlisted one as off.
261
+ // Built-ins are on by default, so an exact list writes every unlisted one as off (function tools included:
262
+ // tools: [tool(...)] means that function and no built-in).
263
+ const builtins = this.builtinTools;
201
264
  const tools = {};
202
265
  for (const n of BUILTIN_NAMES) {
203
- const t = this.tools.find((x) => x.name === n);
266
+ const t = builtins.find((x) => x.name === n);
204
267
  tools[n] = t === undefined ? false
205
268
  : t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
206
269
  }
207
270
  out["builtin_tools"] = tools;
271
+ // Never an empty list: that would change every existing agent's fingerprint.
272
+ const functions = this.functionTools;
273
+ if (functions.length > 0)
274
+ out["functions"] = functions.map(functionToolSettings);
208
275
  }
276
+ if (this.functionTimeoutSeconds !== undefined)
277
+ out["function_timeout_seconds"] = this.functionTimeoutSeconds;
209
278
  if (this.outputType !== undefined)
210
279
  out["output_schema"] = outputSchema(this.outputType);
211
280
  return out;
@@ -49,7 +49,11 @@ export declare class NotSupportedError extends AgentsError {
49
49
  }
50
50
  export declare class RunError extends AgentsError {
51
51
  readonly code: string;
52
- constructor(code: string, message: string);
52
+ /** The HTTP status when a request was refused (for example 409 on a function-results post). */
53
+ readonly status?: number;
54
+ /** The server's `error.details[0]` (for example `toolCallIds` or `maxBytes`); `{}` when none. */
55
+ readonly details: Record<string, unknown>;
56
+ constructor(code: string, message: string, status?: number, details?: Record<string, unknown>);
53
57
  }
54
58
  export declare class DriftError extends AgentsError {
55
59
  readonly changed: string[];
@@ -45,9 +45,12 @@ export class NotDeployedError extends AgentsError {
45
45
  export class NotSupportedError extends AgentsError {
46
46
  }
47
47
  export class RunError extends AgentsError {
48
- constructor(code, message) {
48
+ constructor(code, message, status, details) {
49
49
  super(`${code}: ${message}`);
50
50
  this.code = code;
51
+ if (status !== undefined)
52
+ this.status = status;
53
+ this.details = { ...(details !== null && details !== void 0 ? details : {}) };
51
54
  }
52
55
  }
53
56
  export class DriftError extends AgentsError {
@@ -105,3 +105,7 @@ export type Event = {
105
105
  * Never throws: malformed chunks degrade to `{ kind: "unknown", chunk }`.
106
106
  */
107
107
  export declare function fromUiChunk(chunk: unknown): Event | null;
108
+ /** A stored UIMessage (`GET /v1/conversations/{id}` `messages`) as the stream chunks that would have produced it,
109
+ * ending with `finish`, so a finished turn can be read like a live one. Text parts become one text block each, tool
110
+ * parts a call and (when they have one) its output, `data-*` parts pass through; reasoning is dropped. */
111
+ export declare function chunksFromUiMessage(message: unknown): Record<string, unknown>[];
@@ -125,3 +125,36 @@ function map(chunk) {
125
125
  return { kind: "unknown", chunk };
126
126
  }
127
127
  }
128
+ /** A stored UIMessage (`GET /v1/conversations/{id}` `messages`) as the stream chunks that would have produced it,
129
+ * ending with `finish`, so a finished turn can be read like a live one. Text parts become one text block each, tool
130
+ * parts a call and (when they have one) its output, `data-*` parts pass through; reasoning is dropped. */
131
+ export function chunksFromUiMessage(message) {
132
+ const chunks = [];
133
+ const parts = isObject(message) && Array.isArray(message["parts"]) ? message["parts"] : [];
134
+ parts.forEach((part, n) => {
135
+ var _a, _b, _c, _d;
136
+ if (!isObject(part))
137
+ return;
138
+ const kind = typeof part["type"] === "string" ? part["type"] : "";
139
+ if (kind === "text") {
140
+ const id = `msg-text-${n}`;
141
+ chunks.push({ type: "text-start", id }, { type: "text-delta", id, delta: String((_a = part["text"]) !== null && _a !== void 0 ? _a : "") }, { type: "text-end", id });
142
+ }
143
+ else if (kind === "dynamic-tool" || kind.startsWith("tool-")) {
144
+ const name = (_b = part["toolName"]) !== null && _b !== void 0 ? _b : (kind.startsWith("tool-") ? kind.slice("tool-".length) : "");
145
+ const toolCallId = (_c = part["toolCallId"]) !== null && _c !== void 0 ? _c : "";
146
+ chunks.push({ type: "tool-input-available", toolCallId, toolName: name, input: part["input"] });
147
+ if (part["state"] === "output-available") {
148
+ chunks.push({ type: "tool-output-available", toolCallId, output: part["output"] });
149
+ }
150
+ else if (part["state"] === "output-error") {
151
+ chunks.push({ type: "tool-output-available", toolCallId, output: { error: (_d = part["errorText"]) !== null && _d !== void 0 ? _d : "" } });
152
+ }
153
+ }
154
+ else if (kind.startsWith("data-")) {
155
+ chunks.push({ type: kind, id: part["id"], data: part["data"] });
156
+ }
157
+ });
158
+ chunks.push({ type: "finish", finishReason: "stop" });
159
+ return chunks;
160
+ }
@@ -0,0 +1,101 @@
1
+ import type { FunctionCallRequest } from "./events.js";
2
+ export declare const NAME_PATTERN: RegExp;
3
+ export declare const DESCRIPTION_MAX_CHARS = 1024;
4
+ /** The server's caps: one function's `parameters` (compact JSON), how many functions, and all of them together. */
5
+ export declare const PARAMETERS_MAX_BYTES: number;
6
+ /** The deepest JSON nesting of `parameters`, counting every object and list (the root object is 1). */
7
+ export declare const PARAMETERS_MAX_DEPTH = 16;
8
+ /** Names a function may not take: panja's `RESERVED_FUNCTION_NAMES` (platform tools, harness plumbing, built-in and
9
+ * sandbox tool names, retired v11 names, `clarify`), expanded. `shared/function_tool_vectors.json` pins it. */
10
+ export declare const RESERVED_FUNCTION_NAMES: ReadonlySet<string>;
11
+ export declare const FUNCTIONS_MAX = 32;
12
+ /** The server's range for `function_timeout_seconds` (save_check's maximum), and its value when agent.json leaves
13
+ * it out. */
14
+ export declare const FUNCTION_TIMEOUT_RANGE: readonly [number, number];
15
+ export declare const DEFAULT_FUNCTION_TIMEOUT_SECONDS = 600;
16
+ export declare const FUNCTIONS_TOTAL_MAX_BYTES: number;
17
+ export declare const MAX_TIMEOUT_MS: number;
18
+ /** The server's default cap on one post's outputs together (`CLAW_FUNCTION_RESULT_MAX_BYTES`, UTF-8). It refuses
19
+ * (413) rather than truncates, so the runner truncates first. */
20
+ export declare const RESULTS_MAX_BYTES = 65536;
21
+ export declare const TRUNCATION_NOTE = "\n[truncated by sarvam-agents-client]";
22
+ /** A zod (v4) schema, or anything with the same two methods. */
23
+ interface ParseableSchema {
24
+ parse(value: unknown): unknown;
25
+ toJSONSchema(params?: {
26
+ io?: "input" | "output";
27
+ }): Record<string, unknown>;
28
+ }
29
+ /** What `execute` gets besides the arguments. */
30
+ export interface FunctionCallDetails {
31
+ /** The model's tool-call id. */
32
+ callId: string;
33
+ /** Aborted when the call times out or the run is cancelled; pass it to `fetch` and the like. */
34
+ signal: AbortSignal;
35
+ }
36
+ /** The arguments `execute` receives: the zod schema's output type, or a plain object for a JSON Schema. */
37
+ export type FunctionToolArgs<P> = P extends ParseableSchema ? ReturnType<P["parse"]> : Record<string, unknown>;
38
+ export interface FunctionToolOptions<P extends ParseableSchema | Record<string, unknown> = Record<string, unknown>> {
39
+ /** Letters, digits, `_` or `-`, starting with a letter or `_`; at most 64 characters. */
40
+ name: string;
41
+ /** 1 to 1024 characters; what the model reads to decide when to call the function. */
42
+ description: string;
43
+ /** A zod object schema (arguments are parsed with it), or a JSON Schema object with `"type": "object"`. */
44
+ parameters: P;
45
+ /** Runs the call. Its return value goes to the model: strings as is, other values as JSON. */
46
+ execute: (args: FunctionToolArgs<P>, details: FunctionCallDetails) => unknown;
47
+ /** After this long the model gets a failed result instead (default 60 000 ms). */
48
+ timeoutMs?: number;
49
+ }
50
+ /** One function tool, as `tool()` returns it: checked and frozen. */
51
+ export interface FunctionTool {
52
+ /** The discriminator `Agent` uses. */
53
+ readonly type: "function";
54
+ readonly name: string;
55
+ readonly description: string;
56
+ /** The resolved JSON Schema (a zod schema's is inlined, `$schema` dropped). */
57
+ readonly parameters: Readonly<Record<string, unknown>>;
58
+ readonly timeoutMs: number;
59
+ }
60
+ /** How deep `value` nests objects and lists, as the server counts it: `value` is 1, scalars don't count. */
61
+ export declare function containerDepth(value: unknown): number;
62
+ export declare function compactBytes(value: unknown): number;
63
+ /**
64
+ * A function the agent may call; it runs in this process when the model calls it.
65
+ *
66
+ * `parameters` is a zod object schema (the model's arguments are parsed with it before `execute` runs) or a JSON
67
+ * Schema object (written as given; required and unknown properties are checked). Throws `UserError` on what the
68
+ * server would refuse.
69
+ */
70
+ export declare function tool<P extends ParseableSchema | Record<string, unknown>>(options: FunctionToolOptions<P>): FunctionTool;
71
+ /** A tool built by `tool()` (or an object of that shape, which Agent re-checks through `tool()`). */
72
+ export declare function isFunctionTool(value: unknown): value is FunctionTool;
73
+ /** Whether `value` came from `tool()` itself, with its `execute` attached. */
74
+ export declare function isBuiltFunctionTool(value: unknown): value is FunctionTool;
75
+ /** One `functions` entry of agent.json. */
76
+ export declare function functionToolSettings(t: FunctionTool): Record<string, unknown>;
77
+ /** One call's result, as posted to the server. */
78
+ export interface FunctionResult {
79
+ callId: string;
80
+ output: string;
81
+ isError: boolean;
82
+ }
83
+ /** Thrown by `runCalls` when its signal aborts. */
84
+ export declare class CallsCancelled extends Error {
85
+ }
86
+ /** The model's arguments as `execute` takes them; throws UserError when they don't fit the schema. */
87
+ export declare function toolArguments(t: FunctionTool, args: unknown): unknown;
88
+ /** Strings as is; everything else as JSON (`String()` when JSON can't hold it). */
89
+ export declare function stringify(value: unknown): string;
90
+ /** Cut the largest outputs first, each ending with a note, so all of them fit `maxBytes` UTF-8 bytes. */
91
+ export declare function fit(outputs: string[], maxBytes?: number): string[];
92
+ /**
93
+ * Run every call at once and return one result per call, in call order. A call that throws, times out, names a
94
+ * function this process doesn't have, or has arguments that don't fit becomes a failed result the model can act on;
95
+ * with `raiseErrors` an error thrown by `execute` is thrown instead.
96
+ */
97
+ export declare function runCalls(tools: ReadonlyMap<string, FunctionTool>, calls: readonly FunctionCallRequest[], { signal, raiseErrors }: {
98
+ signal: AbortSignal;
99
+ raiseErrors?: boolean;
100
+ }): Promise<FunctionResult[]>;
101
+ export {};