sarvam-agents-client 0.2.3 → 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 (178) hide show
  1. package/README.md +16 -1
  2. package/dist/apis/AgentsApi.d.ts +4 -4
  3. package/dist/apis/AgentsApi.js +4 -4
  4. package/dist/apis/AppsApi.d.ts +1 -0
  5. package/dist/apis/AppsApi.js +3 -0
  6. package/dist/apis/FunctionToolsApi.d.ts +33 -0
  7. package/dist/apis/FunctionToolsApi.js +65 -0
  8. package/dist/apis/QueueApi.d.ts +1 -0
  9. package/dist/apis/QueueApi.js +3 -0
  10. package/dist/apis/ResponsesApi.d.ts +2 -0
  11. package/dist/apis/ResponsesApi.js +6 -0
  12. package/dist/apis/index.d.ts +1 -0
  13. package/dist/apis/index.js +1 -0
  14. package/dist/compose/agent.d.ts +26 -6
  15. package/dist/compose/agent.js +84 -7
  16. package/dist/compose/deploy.d.ts +3 -2
  17. package/dist/compose/errors.d.ts +22 -1
  18. package/dist/compose/errors.js +21 -1
  19. package/dist/compose/events.d.ts +38 -0
  20. package/dist/compose/events.js +59 -2
  21. package/dist/compose/functionTool.d.ts +101 -0
  22. package/dist/compose/functionTool.js +420 -0
  23. package/dist/compose/index.d.ts +7 -3
  24. package/dist/compose/index.js +3 -1
  25. package/dist/compose/output.d.ts +40 -0
  26. package/dist/compose/output.js +476 -0
  27. package/dist/compose/run.d.ts +44 -15
  28. package/dist/compose/run.js +164 -21
  29. package/dist/compose/runState.d.ts +28 -2
  30. package/dist/compose/runState.js +30 -0
  31. package/dist/compose/settingsTransport.d.ts +23 -3
  32. package/dist/compose/settingsTransport.js +295 -3
  33. package/dist/compose/transport.d.ts +21 -3
  34. package/dist/esm/apis/AgentsApi.d.ts +4 -4
  35. package/dist/esm/apis/AgentsApi.js +4 -4
  36. package/dist/esm/apis/AppsApi.d.ts +1 -0
  37. package/dist/esm/apis/AppsApi.js +3 -0
  38. package/dist/esm/apis/FunctionToolsApi.d.ts +33 -0
  39. package/dist/esm/apis/FunctionToolsApi.js +61 -0
  40. package/dist/esm/apis/QueueApi.d.ts +1 -0
  41. package/dist/esm/apis/QueueApi.js +3 -0
  42. package/dist/esm/apis/ResponsesApi.d.ts +2 -0
  43. package/dist/esm/apis/ResponsesApi.js +6 -0
  44. package/dist/esm/apis/index.d.ts +1 -0
  45. package/dist/esm/apis/index.js +1 -0
  46. package/dist/esm/compose/agent.d.ts +26 -6
  47. package/dist/esm/compose/agent.js +84 -7
  48. package/dist/esm/compose/deploy.d.ts +3 -2
  49. package/dist/esm/compose/errors.d.ts +22 -1
  50. package/dist/esm/compose/errors.js +21 -1
  51. package/dist/esm/compose/events.d.ts +38 -0
  52. package/dist/esm/compose/events.js +58 -2
  53. package/dist/esm/compose/functionTool.d.ts +101 -0
  54. package/dist/esm/compose/functionTool.js +406 -0
  55. package/dist/esm/compose/index.d.ts +7 -3
  56. package/dist/esm/compose/index.js +1 -0
  57. package/dist/esm/compose/output.d.ts +40 -0
  58. package/dist/esm/compose/output.js +466 -0
  59. package/dist/esm/compose/run.d.ts +44 -15
  60. package/dist/esm/compose/run.js +165 -22
  61. package/dist/esm/compose/runState.d.ts +28 -2
  62. package/dist/esm/compose/runState.js +31 -1
  63. package/dist/esm/compose/settingsTransport.d.ts +23 -3
  64. package/dist/esm/compose/settingsTransport.js +298 -7
  65. package/dist/esm/compose/transport.d.ts +21 -3
  66. package/dist/esm/models/AgentConversationDetail.d.ts +7 -0
  67. package/dist/esm/models/AgentConversationDetail.js +3 -0
  68. package/dist/esm/models/AppResource.d.ts +29 -0
  69. package/dist/esm/models/AppResource.js +16 -0
  70. package/dist/esm/models/AppToolsResponse.d.ts +3 -4
  71. package/dist/esm/models/AppToolsResponse.js +3 -2
  72. package/dist/esm/models/AppView.d.ts +48 -0
  73. package/dist/esm/models/AppView.js +23 -0
  74. package/dist/esm/models/ClarifyBody.d.ts +6 -0
  75. package/dist/esm/models/ClarifyBody.js +2 -0
  76. package/dist/esm/models/ConversationDetail.d.ts +7 -0
  77. package/dist/esm/models/ConversationDetail.js +3 -0
  78. package/dist/esm/models/ErrorDetail.d.ts +1 -0
  79. package/dist/esm/models/ErrorDetail.js +2 -1
  80. package/dist/esm/models/FunctionResultBody.d.ts +44 -0
  81. package/dist/esm/models/FunctionResultBody.js +49 -0
  82. package/dist/esm/models/McpSecurityAppealView.d.ts +50 -0
  83. package/dist/esm/models/McpSecurityAppealView.js +47 -0
  84. package/dist/esm/models/McpSecurityView.d.ts +105 -0
  85. package/dist/esm/models/McpSecurityView.js +66 -0
  86. package/dist/esm/models/MessagesResponse.d.ts +6 -0
  87. package/dist/esm/models/MessagesResponse.js +2 -0
  88. package/dist/esm/models/QueueMessageInput.d.ts +23 -0
  89. package/dist/esm/models/QueueMessageInput.js +14 -0
  90. package/dist/esm/models/RequiredAction.d.ts +77 -0
  91. package/dist/esm/models/RequiredAction.js +69 -0
  92. package/dist/esm/models/ResponseDetail.d.ts +40 -0
  93. package/dist/esm/models/ResponseDetail.js +12 -0
  94. package/dist/esm/models/ResponseInput.d.ts +23 -0
  95. package/dist/esm/models/ResponseInput.js +14 -0
  96. package/dist/esm/models/ToolResults200Response.d.ts +38 -0
  97. package/dist/esm/models/ToolResults200Response.js +47 -0
  98. package/dist/esm/models/ToolResultsBody.d.ts +39 -0
  99. package/dist/esm/models/ToolResultsBody.js +48 -0
  100. package/dist/esm/models/index.d.ts +6 -0
  101. package/dist/esm/models/index.js +6 -0
  102. package/dist/esm/streaming.d.ts +14 -2
  103. package/dist/esm/streaming.js +26 -4
  104. package/dist/models/AgentConversationDetail.d.ts +7 -0
  105. package/dist/models/AgentConversationDetail.js +3 -0
  106. package/dist/models/AppResource.d.ts +29 -0
  107. package/dist/models/AppResource.js +17 -1
  108. package/dist/models/AppToolsResponse.d.ts +3 -4
  109. package/dist/models/AppToolsResponse.js +3 -2
  110. package/dist/models/AppView.d.ts +48 -0
  111. package/dist/models/AppView.js +24 -1
  112. package/dist/models/ClarifyBody.d.ts +6 -0
  113. package/dist/models/ClarifyBody.js +2 -0
  114. package/dist/models/ConversationDetail.d.ts +7 -0
  115. package/dist/models/ConversationDetail.js +3 -0
  116. package/dist/models/ErrorDetail.d.ts +1 -0
  117. package/dist/models/ErrorDetail.js +2 -1
  118. package/dist/models/FunctionResultBody.d.ts +44 -0
  119. package/dist/models/FunctionResultBody.js +56 -0
  120. package/dist/models/McpSecurityAppealView.d.ts +50 -0
  121. package/dist/models/McpSecurityAppealView.js +54 -0
  122. package/dist/models/McpSecurityView.d.ts +105 -0
  123. package/dist/models/McpSecurityView.js +73 -0
  124. package/dist/models/MessagesResponse.d.ts +6 -0
  125. package/dist/models/MessagesResponse.js +2 -0
  126. package/dist/models/QueueMessageInput.d.ts +23 -0
  127. package/dist/models/QueueMessageInput.js +15 -1
  128. package/dist/models/RequiredAction.d.ts +77 -0
  129. package/dist/models/RequiredAction.js +77 -0
  130. package/dist/models/ResponseDetail.d.ts +40 -0
  131. package/dist/models/ResponseDetail.js +12 -0
  132. package/dist/models/ResponseInput.d.ts +23 -0
  133. package/dist/models/ResponseInput.js +15 -0
  134. package/dist/models/ToolResults200Response.d.ts +38 -0
  135. package/dist/models/ToolResults200Response.js +54 -0
  136. package/dist/models/ToolResultsBody.d.ts +39 -0
  137. package/dist/models/ToolResultsBody.js +55 -0
  138. package/dist/models/index.d.ts +6 -0
  139. package/dist/models/index.js +6 -0
  140. package/dist/streaming.d.ts +14 -2
  141. package/dist/streaming.js +27 -4
  142. package/package.json +4 -3
  143. package/src/apis/AgentsApi.ts +4 -4
  144. package/src/apis/AppsApi.ts +5 -0
  145. package/src/apis/FunctionToolsApi.ts +102 -0
  146. package/src/apis/QueueApi.ts +5 -0
  147. package/src/apis/ResponsesApi.ts +10 -0
  148. package/src/apis/index.ts +1 -0
  149. package/src/compose/agent.ts +108 -15
  150. package/src/compose/deploy.ts +6 -5
  151. package/src/compose/errors.ts +35 -2
  152. package/src/compose/events.ts +79 -1
  153. package/src/compose/functionTool.ts +441 -0
  154. package/src/compose/index.ts +7 -3
  155. package/src/compose/output.ts +436 -0
  156. package/src/compose/run.ts +208 -39
  157. package/src/compose/runState.ts +46 -6
  158. package/src/compose/settingsTransport.ts +297 -10
  159. package/src/compose/transport.ts +27 -3
  160. package/src/models/AgentConversationDetail.ts +15 -0
  161. package/src/models/AppResource.ts +42 -0
  162. package/src/models/AppToolsResponse.ts +11 -4
  163. package/src/models/AppView.ts +73 -0
  164. package/src/models/ClarifyBody.ts +8 -0
  165. package/src/models/ConversationDetail.ts +15 -0
  166. package/src/models/ErrorDetail.ts +2 -1
  167. package/src/models/FunctionResultBody.ts +83 -0
  168. package/src/models/McpSecurityAppealView.ts +89 -0
  169. package/src/models/McpSecurityView.ts +169 -0
  170. package/src/models/MessagesResponse.ts +8 -0
  171. package/src/models/QueueMessageInput.ts +28 -0
  172. package/src/models/RequiredAction.ts +128 -0
  173. package/src/models/ResponseDetail.ts +48 -0
  174. package/src/models/ResponseInput.ts +30 -0
  175. package/src/models/ToolResults200Response.ts +75 -0
  176. package/src/models/ToolResultsBody.ts +83 -0
  177. package/src/models/index.ts +6 -0
  178. package/src/streaming.ts +39 -3
package/README.md CHANGED
@@ -103,6 +103,20 @@ streams the rest of the reply:
103
103
  answerClarify(config, conversation.id, { requestId, answers: { ... } })
104
104
  ```
105
105
 
106
+ **Answer the agent's function calls.** An agent with function tools (`agent.json` `functions`) pauses on a
107
+ `data-function-call-request` event (`requestId`, `calls` with `toolCallId`, `name` and `arguments`, `expiresAt`). Run
108
+ the calls, then post every result in one request with `postToolResults`. It streams the rest of the turn:
109
+
110
+ ```ts
111
+ postToolResults(config, conversation.id,
112
+ { requestId, results: [{ toolCallId: "call_1", output: '{"status": "shipped"}' }] }, { idempotencyKey })
113
+ ```
114
+
115
+ Use the same `idempotencyKey` when you retry a post: a repeat the server already delivered resolves to an empty
116
+ stream with `duplicate` set (follow the turn with `reconnect`). Errors are the response's own status (409 with a
117
+ `reason` such as `in_progress` or `expired`, 503 to retry with the same key; see
118
+ [the function tools guide](../docs/compose.md#function-tools)). Compose's `tool()` does all of this for you.
119
+
106
120
  **Timeouts.** Every ordinary call is aborted after 120 seconds unless you pass your own `signal`. To change that
107
121
  limit for the whole SDK, set `defaults.requestTimeoutMs`. A stream is aborted if no data arrives for 60 seconds. A healthy stream never hits this, because the
108
122
  server sends a ping every 15 seconds. You can change the limit with `{ idleTimeoutMs }`. To cancel from your own code,
@@ -137,7 +151,8 @@ one with `ArtifactsApi.downloadUrl`.
137
151
  ## Compose
138
152
 
139
153
  Define an agent in code, deploy it by name and run it with `sarvam-agents-client/compose` (a separate import path; the
140
- package root is unchanged):
154
+ package root is unchanged). Function tools (`tool()`, run in your process), structured output and clarify questions
155
+ are handled for you:
141
156
 
142
157
  ```ts
143
158
  import { Agent, run, deploy } from "sarvam-agents-client/compose";
@@ -133,12 +133,12 @@ export declare class AgentsApi extends runtime.BaseAPI {
133
133
  */
134
134
  createAgent(requestParameters: CreateAgentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AgentResource>;
135
135
  /**
136
- * Owner-only soft delete. Also drops the agent\'s ``managed_agents`` row (if any) so a deleted agent never lingers as a managed agent.
136
+ * Owner-only soft delete. The managed state lives on the agent row, so a deleted agent stops being a managed agent with it.
137
137
  * Delete Agent
138
138
  */
139
139
  deleteAgentRaw(requestParameters: DeleteAgentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;
140
140
  /**
141
- * Owner-only soft delete. Also drops the agent\'s ``managed_agents`` row (if any) so a deleted agent never lingers as a managed agent.
141
+ * Owner-only soft delete. The managed state lives on the agent row, so a deleted agent stops being a managed agent with it.
142
142
  * Delete Agent
143
143
  */
144
144
  deleteAgent(requestParameters: DeleteAgentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;
@@ -237,12 +237,12 @@ export declare class AgentsApi extends runtime.BaseAPI {
237
237
  */
238
238
  listAgentTemplates(requestParameters?: ListAgentTemplatesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<EntityListAgentTemplateResource>;
239
239
  /**
240
- * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which knows nothing about ``managed_agents``, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
240
+ * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which has no managed filter, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
241
241
  * List Agents
242
242
  */
243
243
  listAgentsRaw(requestParameters: ListAgentsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<EntityListAgentResource>>;
244
244
  /**
245
- * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which knows nothing about ``managed_agents``, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
245
+ * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which has no managed filter, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
246
246
  * List Agents
247
247
  */
248
248
  listAgents(requestParameters?: ListAgentsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<EntityListAgentResource>;
@@ -101,7 +101,7 @@ class AgentsApi extends runtime.BaseAPI {
101
101
  return await response.value();
102
102
  }
103
103
  /**
104
- * Owner-only soft delete. Also drops the agent\'s ``managed_agents`` row (if any) so a deleted agent never lingers as a managed agent.
104
+ * Owner-only soft delete. The managed state lives on the agent row, so a deleted agent stops being a managed agent with it.
105
105
  * Delete Agent
106
106
  */
107
107
  async deleteAgentRaw(requestParameters, initOverrides) {
@@ -126,7 +126,7 @@ class AgentsApi extends runtime.BaseAPI {
126
126
  return new runtime.VoidApiResponse(response);
127
127
  }
128
128
  /**
129
- * Owner-only soft delete. Also drops the agent\'s ``managed_agents`` row (if any) so a deleted agent never lingers as a managed agent.
129
+ * Owner-only soft delete. The managed state lives on the agent row, so a deleted agent stops being a managed agent with it.
130
130
  * Delete Agent
131
131
  */
132
132
  async deleteAgent(requestParameters, initOverrides) {
@@ -477,7 +477,7 @@ class AgentsApi extends runtime.BaseAPI {
477
477
  return await response.value();
478
478
  }
479
479
  /**
480
- * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which knows nothing about ``managed_agents``, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
480
+ * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which has no managed filter, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
481
481
  * List Agents
482
482
  */
483
483
  async listAgentsRaw(requestParameters, initOverrides) {
@@ -535,7 +535,7 @@ class AgentsApi extends runtime.BaseAPI {
535
535
  return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.EntityListAgentResourceFromJSON)(jsonValue));
536
536
  }
537
537
  /**
538
- * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which knows nothing about ``managed_agents``, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
538
+ * Flat, scope-filterable agent catalog (contract replaces v1\'s grouped ``GET /v1/agents``; the FE re-groups client-side from each row\'s ``scope``). One gateway call returns the caller\'s full visible set (the triple powers the gateway\'s ``visibility_scope`` clause). We then drop the operator-seeded editor agents, re-apply the visibility predicate (defence in depth — the gateway is identity-agnostic), and apply the ``?scope=``/``q`` filters before counting, so ``total`` is authoritative for the returned set. ``origin=managed_agents`` keeps only managed agents the caller owns (:func:`is_owner`). A teammate\'s published managed agent is visible to the caller but its sessions are owner-only, so listing it would only lead to a 403 on the session log. It always takes the fetch-all path below: the SQL catalog pages at the gateway, which has no managed filter, so filtering its page here would return short pages and a wrong ``total``. Catalog-only filters are therefore a 400 with ``origin`` rather than silently ignored.
539
539
  * List Agents
540
540
  */
541
541
  async listAgents(requestParameters = {}, initOverrides) {
@@ -51,6 +51,7 @@ export interface ListAppsRequest {
51
51
  offset?: number;
52
52
  category?: Array<AppCategory> | null;
53
53
  includeFilterOptions?: boolean;
54
+ custom?: boolean;
54
55
  }
55
56
  export interface UnbindAppRequest {
56
57
  agentId: string;
@@ -353,6 +353,9 @@ class AppsApi extends runtime.BaseAPI {
353
353
  if (requestParameters['includeFilterOptions'] != null) {
354
354
  queryParameters['includeFilterOptions'] = requestParameters['includeFilterOptions'];
355
355
  }
356
+ if (requestParameters['custom'] != null) {
357
+ queryParameters['custom'] = requestParameters['custom'];
358
+ }
356
359
  const headerParameters = {};
357
360
  if (this.configuration && this.configuration.accessToken) {
358
361
  const token = this.configuration.accessToken;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Sarvam Agents API
3
+ * Chat with a Sarvam agent, exchange files with it, and set it up (instructions, skills, knowledge bases, connectors, deploy) from your own code. Authenticate with a service token sent as a Bearer token, and send the header X-Panja-Origin: managed_agents on every request.
4
+ *
5
+ * The version of the OpenAPI document: 0.1.0
6
+ * Contact: support@sarvam.ai
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import * as runtime from '../runtime.js';
13
+ import type { ToolResults200Response, ToolResultsBody } from '../models/index.js';
14
+ export interface ToolResultsRequest {
15
+ conversationId: string;
16
+ toolResultsBody: ToolResultsBody;
17
+ idempotencyKey?: string | null;
18
+ }
19
+ /**
20
+ *
21
+ */
22
+ export declare class FunctionToolsApi extends runtime.BaseAPI {
23
+ /**
24
+ * Answer a paused turn\'s function calls and stream its continuation.
25
+ * Tool Results Route
26
+ */
27
+ toolResultsRaw(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ToolResults200Response>>;
28
+ /**
29
+ * Answer a paused turn\'s function calls and stream its continuation.
30
+ * Tool Results Route
31
+ */
32
+ toolResults(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ToolResults200Response>;
33
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * Sarvam Agents API
6
+ * Chat with a Sarvam agent, exchange files with it, and set it up (instructions, skills, knowledge bases, connectors, deploy) from your own code. Authenticate with a service token sent as a Bearer token, and send the header X-Panja-Origin: managed_agents on every request.
7
+ *
8
+ * The version of the OpenAPI document: 0.1.0
9
+ * Contact: support@sarvam.ai
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.FunctionToolsApi = void 0;
17
+ const runtime = require("../runtime.js");
18
+ const index_js_1 = require("../models/index.js");
19
+ /**
20
+ *
21
+ */
22
+ class FunctionToolsApi extends runtime.BaseAPI {
23
+ /**
24
+ * Answer a paused turn\'s function calls and stream its continuation.
25
+ * Tool Results Route
26
+ */
27
+ async toolResultsRaw(requestParameters, initOverrides) {
28
+ if (requestParameters['conversationId'] == null) {
29
+ throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling toolResults().');
30
+ }
31
+ if (requestParameters['toolResultsBody'] == null) {
32
+ throw new runtime.RequiredError('toolResultsBody', 'Required parameter "toolResultsBody" was null or undefined when calling toolResults().');
33
+ }
34
+ const queryParameters = {};
35
+ const headerParameters = {};
36
+ headerParameters['Content-Type'] = 'application/json';
37
+ if (requestParameters['idempotencyKey'] != null) {
38
+ headerParameters['Idempotency-Key'] = String(requestParameters['idempotencyKey']);
39
+ }
40
+ if (this.configuration && this.configuration.accessToken) {
41
+ const token = this.configuration.accessToken;
42
+ const tokenString = await token("bearerAuth", []);
43
+ if (tokenString) {
44
+ headerParameters["Authorization"] = `Bearer ${tokenString}`;
45
+ }
46
+ }
47
+ const response = await this.request({
48
+ path: `/v1/conversations/{conversationId}/tool-results`.replace(`{${"conversationId"}}`, runtime.encodePathParam('conversationId', requestParameters['conversationId'])),
49
+ method: 'POST',
50
+ headers: headerParameters,
51
+ query: queryParameters,
52
+ body: (0, index_js_1.ToolResultsBodyToJSON)(requestParameters['toolResultsBody']),
53
+ }, initOverrides);
54
+ return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.ToolResults200ResponseFromJSON)(jsonValue));
55
+ }
56
+ /**
57
+ * Answer a paused turn\'s function calls and stream its continuation.
58
+ * Tool Results Route
59
+ */
60
+ async toolResults(requestParameters, initOverrides) {
61
+ const response = await this.toolResultsRaw(requestParameters, initOverrides);
62
+ return await response.value();
63
+ }
64
+ }
65
+ exports.FunctionToolsApi = FunctionToolsApi;
@@ -22,6 +22,7 @@ export interface QueueMessageRequest {
22
22
  xClientFeatures?: string | null;
23
23
  xClientPlatform?: string | null;
24
24
  xClientVersion?: string | null;
25
+ xLoginId?: string | null;
25
26
  }
26
27
  export interface RemoveQueuedRequest {
27
28
  conversationId: string;
@@ -81,6 +81,9 @@ class QueueApi extends runtime.BaseAPI {
81
81
  if (requestParameters['xClientVersion'] != null) {
82
82
  headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
83
83
  }
84
+ if (requestParameters['xLoginId'] != null) {
85
+ headerParameters['X-Login-Id'] = String(requestParameters['xLoginId']);
86
+ }
84
87
  if (this.configuration && this.configuration.accessToken) {
85
88
  const token = this.configuration.accessToken;
86
89
  const tokenString = await token("bearerAuth", []);
@@ -16,6 +16,7 @@ export interface CreateResponseRequest {
16
16
  xClientFeatures?: string | null;
17
17
  xClientPlatform?: string | null;
18
18
  xClientVersion?: string | null;
19
+ xLoginId?: string | null;
19
20
  }
20
21
  export interface ReconnectStreamRequest {
21
22
  conversationId: string;
@@ -30,6 +31,7 @@ export interface StopResponseRequest {
30
31
  conversationId: string;
31
32
  xClientPlatform?: string | null;
32
33
  xClientVersion?: string | null;
34
+ xLoginId?: string | null;
33
35
  }
34
36
  /**
35
37
  *
@@ -39,6 +39,9 @@ class ResponsesApi extends runtime.BaseAPI {
39
39
  if (requestParameters['xClientVersion'] != null) {
40
40
  headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
41
41
  }
42
+ if (requestParameters['xLoginId'] != null) {
43
+ headerParameters['X-Login-Id'] = String(requestParameters['xLoginId']);
44
+ }
42
45
  if (this.configuration && this.configuration.accessToken) {
43
46
  const token = this.configuration.accessToken;
44
47
  const tokenString = await token("bearerAuth", []);
@@ -141,6 +144,9 @@ class ResponsesApi extends runtime.BaseAPI {
141
144
  if (requestParameters['xClientVersion'] != null) {
142
145
  headerParameters['X-Client-Version'] = String(requestParameters['xClientVersion']);
143
146
  }
147
+ if (requestParameters['xLoginId'] != null) {
148
+ headerParameters['X-Login-Id'] = String(requestParameters['xLoginId']);
149
+ }
144
150
  if (this.configuration && this.configuration.accessToken) {
145
151
  const token = this.configuration.accessToken;
146
152
  const tokenString = await token("bearerAuth", []);
@@ -7,6 +7,7 @@ export * from './CollectionsApi.js';
7
7
  export * from './ConversationsApi.js';
8
8
  export * from './CronsApi.js';
9
9
  export * from './CustomAPIsApi.js';
10
+ export * from './FunctionToolsApi.js';
10
11
  export * from './MessagesApi.js';
11
12
  export * from './ModelsApi.js';
12
13
  export * from './QueueApi.js';
@@ -25,6 +25,7 @@ __exportStar(require("./CollectionsApi.js"), exports);
25
25
  __exportStar(require("./ConversationsApi.js"), exports);
26
26
  __exportStar(require("./CronsApi.js"), exports);
27
27
  __exportStar(require("./CustomAPIsApi.js"), exports);
28
+ __exportStar(require("./FunctionToolsApi.js"), exports);
28
29
  __exportStar(require("./MessagesApi.js"), exports);
29
30
  __exportStar(require("./ModelsApi.js"), exports);
30
31
  __exportStar(require("./QueueApi.js"), exports);
@@ -1,4 +1,6 @@
1
1
  import { BuiltinTool } from "./tools.js";
2
+ import type { FunctionTool } from "./functionTool.js";
3
+ import type { OutputType } from "./output.js";
2
4
  export interface ModelSettings {
3
5
  temperature?: number;
4
6
  topP?: number;
@@ -13,7 +15,9 @@ export interface Limits {
13
15
  maxToolCallsPerTurn?: number;
14
16
  maxTokensPerTurn?: number;
15
17
  }
16
- export interface AgentOptions {
18
+ /** An entry of `Agent` `tools`: a built-in (`sandbox()`, `webSearchTool()`, ...) or a function tool (`tool()`). */
19
+ export type AgentTool = BuiltinTool | FunctionTool;
20
+ export interface AgentOptions<TOutput extends OutputType | undefined = undefined> {
17
21
  name: string;
18
22
  instructions?: string;
19
23
  model?: string;
@@ -21,23 +25,39 @@ export interface AgentOptions {
21
25
  endpoint?: string;
22
26
  modelSettings?: ModelSettings;
23
27
  fallbackModels?: string[];
24
- /** Exact list of built-ins to keep on; omit to keep the server default (all on). */
25
- tools?: BuiltinTool[];
28
+ /** Exact list of what the agent may use: built-ins (the unlisted ones are turned off) and function tools (agent.json
29
+ * `functions`). Omit to keep the server default (every built-in on, no functions). */
30
+ tools?: AgentTool[];
31
+ /** Seconds (10 to 3000, default 600) the server waits for this process to answer a function call (`function_timeout_seconds`). */
32
+ functionTimeoutSeconds?: number;
26
33
  limits?: Limits;
27
34
  metadata?: Record<string, string>;
35
+ /** The shape of the final answer: `{ type: "json_schema", schema }` or a zod schema. `finalOutput` follows it. */
36
+ outputType?: TOutput;
28
37
  }
29
- export declare class Agent {
38
+ /** An agent with any output type: use it for helpers that accept every agent (plain `Agent` means a text agent). */
39
+ export type AnyAgent = Agent<OutputType | undefined>;
40
+ export declare class Agent<TOutput extends OutputType | undefined = undefined> {
30
41
  readonly name: string;
31
42
  readonly instructions: string;
32
43
  readonly model?: string;
33
44
  readonly endpoint?: string;
34
45
  readonly modelSettings?: ModelSettings;
35
46
  readonly fallbackModels?: string[];
36
- readonly tools?: readonly BuiltinTool[];
47
+ /** Built-ins and function tools, in the order given. */
48
+ readonly tools?: readonly AgentTool[];
49
+ readonly functionTimeoutSeconds?: number;
37
50
  readonly limits?: Limits;
38
51
  readonly metadata?: Record<string, string>;
39
- constructor(rawOpts: AgentOptions);
52
+ /** Kept by reference and not frozen: a zod schema must stay usable. Non-enumerable, so deepFreeze skips it. */
53
+ readonly outputType: TOutput;
54
+ constructor(rawOpts: AgentOptions<TOutput>);
40
55
  private check;
56
+ private checkFunctions;
57
+ /** The built-in tools in `tools`, in order. */
58
+ get builtinTools(): readonly BuiltinTool[];
59
+ /** The function tools in `tools`, in order. */
60
+ get functionTools(): readonly FunctionTool[];
41
61
  private baseSettings;
42
62
  specHash(): string;
43
63
  toSettings(): Record<string, unknown>;
@@ -4,6 +4,8 @@ exports.Agent = void 0;
4
4
  const errors_js_1 = require("./errors.js");
5
5
  const fingerprint_js_1 = require("./fingerprint.js");
6
6
  const builtins_js_1 = require("./builtins.js");
7
+ const functionTool_js_1 = require("./functionTool.js");
8
+ const output_js_1 = require("./output.js");
7
9
  const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
8
10
  const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
9
11
  const TOOL_CHOICES = ["auto", "none"];
@@ -77,10 +79,18 @@ class Agent {
77
79
  constructor(rawOpts) {
78
80
  var _a, _b;
79
81
  const opts = normalize(rawOpts);
80
- for (const tool of (_a = opts.tools) !== null && _a !== void 0 ? _a : []) {
82
+ for (const tool of ((_a = opts.tools) !== null && _a !== void 0 ? _a : [])) {
81
83
  if (tool instanceof Agent) {
82
84
  throw new errors_js_1.NotSupportedError("sub-agents in tools are not supported yet (field: tools)");
83
85
  }
86
+ if (typeof tool === "function") {
87
+ throw new errors_js_1.UserError(`tools: ${tool.name || "a function"} is not a tool; wrap it with tool({ name, description, ` +
88
+ "parameters, execute })");
89
+ }
90
+ if (tool === null || typeof tool !== "object" || Array.isArray(tool)) {
91
+ throw new errors_js_1.UserError(`tools: ${JSON.stringify(tool)} is not a tool; list built-ins (sandbox(), webSearchTool(), ...) ` +
92
+ "and tool() function tools");
93
+ }
84
94
  }
85
95
  checkNumbers(opts);
86
96
  this.name = opts.name;
@@ -89,17 +99,31 @@ class Agent {
89
99
  this.endpoint = opts.endpoint;
90
100
  this.modelSettings = clone(opts.modelSettings);
91
101
  this.fallbackModels = clone(opts.fallbackModels);
92
- this.tools = clone(opts.tools);
102
+ // A function tool is kept by reference (it holds execute and maybe a zod schema); an object literal of that shape
103
+ // goes through tool().
104
+ this.tools = opts.tools === undefined ? undefined
105
+ : opts.tools.map((t) => {
106
+ if ((0, functionTool_js_1.isBuiltFunctionTool)(t))
107
+ return t;
108
+ if ((0, functionTool_js_1.isFunctionTool)(t))
109
+ return (0, functionTool_js_1.tool)(t);
110
+ return clone(t);
111
+ });
112
+ this.functionTimeoutSeconds = opts.functionTimeoutSeconds;
93
113
  this.limits = clone(opts.limits);
94
114
  this.metadata = clone(opts.metadata);
115
+ Object.defineProperty(this, "outputType", { value: opts.outputType, enumerable: false, writable: false });
95
116
  this.check();
96
117
  deepFreeze(this);
97
118
  }
98
119
  check() {
99
- var _a, _b;
100
120
  if (typeof this.name !== "string" || !SLUG.test(this.name)) {
101
121
  throw new errors_js_1.UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
102
122
  }
123
+ if (this.outputType !== undefined) {
124
+ (0, output_js_1.checkOutputType)(this.outputType);
125
+ (0, output_js_1.outputSchema)(this.outputType); // refuse what the server would, before anything is sent
126
+ }
103
127
  for (const [key, value] of [["model", this.model], ["endpoint", this.endpoint]]) {
104
128
  if (value !== undefined && (typeof value !== "string" || value === "")) {
105
129
  throw new errors_js_1.UserError(`${key}: must be a non-empty string`);
@@ -140,7 +164,7 @@ class Agent {
140
164
  throw new errors_js_1.UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
141
165
  }
142
166
  }
143
- const names = ((_a = this.tools) !== null && _a !== void 0 ? _a : []).map((t) => t.name);
167
+ const names = this.builtinTools.map((t) => t.name);
144
168
  for (const n of names) {
145
169
  if (builtins_js_1.BUILTIN_NAMES.indexOf(n) === -1) {
146
170
  throw new errors_js_1.UserError(`tools: unknown built-in tool ${JSON.stringify(n)} (known: ${builtins_js_1.BUILTIN_NAMES.join(", ")})`);
@@ -150,7 +174,7 @@ class Agent {
150
174
  if (dupes.length > 0) {
151
175
  throw new errors_js_1.UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
152
176
  }
153
- for (const t of (_b = this.tools) !== null && _b !== void 0 ? _b : []) {
177
+ for (const t of this.builtinTools) {
154
178
  if (t.options === undefined || Object.keys(t.options).length === 0)
155
179
  continue;
156
180
  if (t.name !== "web_search")
@@ -160,6 +184,49 @@ class Agent {
160
184
  if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
161
185
  throw new errors_js_1.UserError("tools: codeMode needs sandbox; add sandbox() to tools");
162
186
  }
187
+ this.checkFunctions();
188
+ }
189
+ checkFunctions() {
190
+ const functions = this.functionTools;
191
+ if (functions.length > functionTool_js_1.FUNCTIONS_MAX) {
192
+ throw new errors_js_1.UserError(`tools: at most ${functionTool_js_1.FUNCTIONS_MAX} function tools (got ${functions.length})`);
193
+ }
194
+ const names = functions.map((t) => t.name);
195
+ const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
196
+ if (dupes.length > 0)
197
+ throw new errors_js_1.UserError(`tools: duplicate function tool(s): ${dupes.join(", ")}`);
198
+ const total = functions.reduce((sum, t) => sum + (0, functionTool_js_1.compactBytes)((0, functionTool_js_1.functionToolSettings)(t)), 0);
199
+ if (total > functionTool_js_1.FUNCTIONS_TOTAL_MAX_BYTES) {
200
+ throw new errors_js_1.UserError(`tools: function tools are ${Math.ceil(total / 1024)} KB together (names, descriptions and ` +
201
+ "parameters); the server allows 64 KB, because every model call carries them");
202
+ }
203
+ const timeout = this.functionTimeoutSeconds;
204
+ if (timeout !== undefined) {
205
+ const [low, high] = functionTool_js_1.FUNCTION_TIMEOUT_RANGE;
206
+ if (typeof timeout !== "number" || !Number.isInteger(timeout) || timeout < low || timeout > high) {
207
+ throw new errors_js_1.UserError(`functionTimeoutSeconds: must be a whole number of seconds from ${low} to ${high}`);
208
+ }
209
+ }
210
+ // A call still running when the server's deadline passes is answered too late (409 expired) and the run fails;
211
+ // one that times out here first goes to the model as a failed result in time.
212
+ const deadline = timeout !== null && timeout !== void 0 ? timeout : functionTool_js_1.DEFAULT_FUNCTION_TIMEOUT_SECONDS;
213
+ for (const t of functions) {
214
+ if (t.timeoutMs >= deadline * 1000) {
215
+ throw new errors_js_1.UserError(`${t.name}: timeoutMs=${t.timeoutMs} (${t.timeoutMs / 1000}s) must be shorter than the ` +
216
+ `agent's functionTimeoutSeconds (${deadline}s${timeout === undefined ? ", the server default" : ""}); ` +
217
+ "lower the tool's timeoutMs or raise functionTimeoutSeconds");
218
+ }
219
+ }
220
+ }
221
+ /** The built-in tools in `tools`, in order. */
222
+ get builtinTools() {
223
+ var _a;
224
+ return ((_a = this.tools) !== null && _a !== void 0 ? _a : []).filter((t) => !(0, functionTool_js_1.isFunctionTool)(t));
225
+ }
226
+ /** The function tools in `tools`, in order. */
227
+ get functionTools() {
228
+ var _a;
229
+ return ((_a = this.tools) !== null && _a !== void 0 ? _a : []).filter(functionTool_js_1.isFunctionTool);
163
230
  }
164
231
  baseSettings() {
165
232
  const out = { version: 1 };
@@ -194,15 +261,25 @@ class Agent {
194
261
  out["limits"] = limits;
195
262
  }
196
263
  if (this.tools !== undefined) {
197
- // Built-ins are on by default, so an exact list writes every unlisted one as off.
264
+ // Built-ins are on by default, so an exact list writes every unlisted one as off (function tools included:
265
+ // tools: [tool(...)] means that function and no built-in).
266
+ const builtins = this.builtinTools;
198
267
  const tools = {};
199
268
  for (const n of builtins_js_1.BUILTIN_NAMES) {
200
- const t = this.tools.find((x) => x.name === n);
269
+ const t = builtins.find((x) => x.name === n);
201
270
  tools[n] = t === undefined ? false
202
271
  : t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
203
272
  }
204
273
  out["builtin_tools"] = tools;
274
+ // Never an empty list: that would change every existing agent's fingerprint.
275
+ const functions = this.functionTools;
276
+ if (functions.length > 0)
277
+ out["functions"] = functions.map(functionTool_js_1.functionToolSettings);
205
278
  }
279
+ if (this.functionTimeoutSeconds !== undefined)
280
+ out["function_timeout_seconds"] = this.functionTimeoutSeconds;
281
+ if (this.outputType !== undefined)
282
+ out["output_schema"] = (0, output_js_1.outputSchema)(this.outputType);
206
283
  return out;
207
284
  }
208
285
  specHash() {
@@ -1,6 +1,7 @@
1
1
  /** deploy()/undeploy(): upsert a hosted agent by name, with fingerprint-based drift detection, and the deploy cache. */
2
2
  import type { Configuration } from "../runtime.js";
3
3
  import type { Agent } from "./agent.js";
4
+ import type { OutputType } from "./output.js";
4
5
  import type { Transport } from "./transport.js";
5
6
  export interface Deployment {
6
7
  agentId: string;
@@ -10,7 +11,7 @@ export interface Deployment {
10
11
  export declare function setDefaultClient(config: Configuration | null): void;
11
12
  export declare function getDefaultClient(): Configuration | null;
12
13
  export declare function resolveTransport(client?: Configuration, transport?: Transport): Transport;
13
- export declare function deploy(agent: Agent, opts?: {
14
+ export declare function deploy(agent: Agent<OutputType | undefined>, opts?: {
14
15
  client?: Configuration;
15
16
  transport?: Transport;
16
17
  strict?: boolean;
@@ -27,4 +28,4 @@ export declare function forget(name: string): void;
27
28
  * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
28
29
  * deploys of one name never overlap.
29
30
  */
30
- export declare function agentIdFor(agent: Agent, transport: Transport, owner: object): Promise<string>;
31
+ export declare function agentIdFor(agent: Agent<OutputType | undefined>, transport: Transport, owner: object): Promise<string>;
@@ -16,7 +16,24 @@ export declare class UserError extends AgentsError {
16
16
  message?: string;
17
17
  }>);
18
18
  }
19
+ /** Where a `ModelBehaviorError` came from: the server's check, or the `outputType`'s own `parse`. */
20
+ export type ModelBehaviorErrorSource = "server" | "local_parse";
21
+ /**
22
+ * The agent's answer didn't match its `outputType`. `source` says where: `"server"` (no answer matched the schema
23
+ * after the server's retry; `rawText` is the model's last attempt) or `"local_parse"` (the server accepted the answer
24
+ * but the `outputType`'s `parse` refused it, for example a zod refinement; `rawText` is the server's JSON,
25
+ * re-serialised).
26
+ */
19
27
  export declare class ModelBehaviorError extends AgentsError {
28
+ readonly rawText: string;
29
+ readonly errors: string[];
30
+ /** The server's `outputNote`: the turn's size-refused `final_answer` was not the answer. */
31
+ readonly note: string | undefined;
32
+ readonly source: ModelBehaviorErrorSource;
33
+ /** The run's conversation, set when a run rejects with this, so the caller can continue it (`conversationId`) or
34
+ * fetch its `ResponseDetail`. */
35
+ conversationId: string | undefined;
36
+ constructor(rawText?: string, errors?: string[], note?: string, source?: ModelBehaviorErrorSource);
20
37
  }
21
38
  export declare class MaxTurnsExceededError extends AgentsError {
22
39
  }
@@ -32,7 +49,11 @@ export declare class NotSupportedError extends AgentsError {
32
49
  }
33
50
  export declare class RunError extends AgentsError {
34
51
  readonly code: string;
35
- 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>);
36
57
  }
37
58
  export declare class DriftError extends AgentsError {
38
59
  readonly changed: string[];
@@ -18,7 +18,24 @@ class UserError extends AgentsError {
18
18
  }
19
19
  }
20
20
  exports.UserError = UserError;
21
+ /**
22
+ * The agent's answer didn't match its `outputType`. `source` says where: `"server"` (no answer matched the schema
23
+ * after the server's retry; `rawText` is the model's last attempt) or `"local_parse"` (the server accepted the answer
24
+ * but the `outputType`'s `parse` refused it, for example a zod refinement; `rawText` is the server's JSON,
25
+ * re-serialised).
26
+ */
21
27
  class ModelBehaviorError extends AgentsError {
28
+ constructor(rawText = "", errors = [], note, source = "server") {
29
+ const prefix = source === "server" ? "model output rejected" : "model output rejected by outputType";
30
+ super(errors.length ? `${prefix}: ` + errors.join("; ") : rawText);
31
+ /** The run's conversation, set when a run rejects with this, so the caller can continue it (`conversationId`) or
32
+ * fetch its `ResponseDetail`. */
33
+ this.conversationId = undefined;
34
+ this.rawText = rawText;
35
+ this.errors = errors.slice();
36
+ this.note = note;
37
+ this.source = source;
38
+ }
22
39
  }
23
40
  exports.ModelBehaviorError = ModelBehaviorError;
24
41
  class MaxTurnsExceededError extends AgentsError {
@@ -39,9 +56,12 @@ class NotSupportedError extends AgentsError {
39
56
  }
40
57
  exports.NotSupportedError = NotSupportedError;
41
58
  class RunError extends AgentsError {
42
- constructor(code, message) {
59
+ constructor(code, message, status, details) {
43
60
  super(`${code}: ${message}`);
44
61
  this.code = code;
62
+ if (status !== undefined)
63
+ this.status = status;
64
+ this.details = { ...(details !== null && details !== void 0 ? details : {}) };
45
65
  }
46
66
  }
47
67
  exports.RunError = RunError;