sarvam-agents-client 0.3.0 → 0.3.2

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 (135) hide show
  1. package/README.md +98 -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 +20 -3
  7. package/dist/compose/agent.js +84 -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 +6 -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 +28 -1
  23. package/dist/compose/settingsTransport.js +389 -7
  24. package/dist/compose/transport.d.ts +18 -1
  25. package/dist/compose/webhook.d.ts +19 -0
  26. package/dist/compose/webhook.js +184 -0
  27. package/dist/esm/apis/FunctionToolsApi.d.ts +33 -0
  28. package/dist/esm/apis/FunctionToolsApi.js +61 -0
  29. package/dist/esm/apis/index.d.ts +1 -0
  30. package/dist/esm/apis/index.js +1 -0
  31. package/dist/esm/compose/agent.d.ts +20 -3
  32. package/dist/esm/compose/agent.js +84 -7
  33. package/dist/esm/compose/errors.d.ts +5 -1
  34. package/dist/esm/compose/errors.js +4 -1
  35. package/dist/esm/compose/events.d.ts +4 -0
  36. package/dist/esm/compose/events.js +33 -0
  37. package/dist/esm/compose/functionTool.d.ts +101 -0
  38. package/dist/esm/compose/functionTool.js +406 -0
  39. package/dist/esm/compose/index.d.ts +6 -2
  40. package/dist/esm/compose/index.js +1 -0
  41. package/dist/esm/compose/output.d.ts +11 -0
  42. package/dist/esm/compose/output.js +30 -9
  43. package/dist/esm/compose/run.d.ts +5 -1
  44. package/dist/esm/compose/run.js +118 -25
  45. package/dist/esm/compose/runState.d.ts +26 -1
  46. package/dist/esm/compose/runState.js +31 -1
  47. package/dist/esm/compose/settingsTransport.d.ts +28 -1
  48. package/dist/esm/compose/settingsTransport.js +392 -11
  49. package/dist/esm/compose/transport.d.ts +18 -1
  50. package/dist/esm/compose/webhook.d.ts +19 -0
  51. package/dist/esm/compose/webhook.js +177 -0
  52. package/dist/esm/models/AgentConversationDetail.d.ts +7 -0
  53. package/dist/esm/models/AgentConversationDetail.js +3 -0
  54. package/dist/esm/models/ClarifyBody.d.ts +6 -0
  55. package/dist/esm/models/ClarifyBody.js +2 -0
  56. package/dist/esm/models/ConversationDetail.d.ts +7 -0
  57. package/dist/esm/models/ConversationDetail.js +3 -0
  58. package/dist/esm/models/ErrorDetail.d.ts +1 -0
  59. package/dist/esm/models/ErrorDetail.js +2 -1
  60. package/dist/esm/models/FunctionResultBody.d.ts +44 -0
  61. package/dist/esm/models/FunctionResultBody.js +49 -0
  62. package/dist/esm/models/QueueMessageInput.d.ts +23 -0
  63. package/dist/esm/models/QueueMessageInput.js +14 -0
  64. package/dist/esm/models/RequiredAction.d.ts +77 -0
  65. package/dist/esm/models/RequiredAction.js +69 -0
  66. package/dist/esm/models/ResponseDetail.d.ts +8 -0
  67. package/dist/esm/models/ResponseDetail.js +2 -0
  68. package/dist/esm/models/ResponseInput.d.ts +23 -0
  69. package/dist/esm/models/ResponseInput.js +14 -0
  70. package/dist/esm/models/ToolResults200Response.d.ts +38 -0
  71. package/dist/esm/models/ToolResults200Response.js +47 -0
  72. package/dist/esm/models/ToolResultsBody.d.ts +39 -0
  73. package/dist/esm/models/ToolResultsBody.js +48 -0
  74. package/dist/esm/models/index.d.ts +4 -0
  75. package/dist/esm/models/index.js +4 -0
  76. package/dist/esm/streaming.d.ts +14 -2
  77. package/dist/esm/streaming.js +26 -4
  78. package/dist/esm/webhooks.d.ts +203 -0
  79. package/dist/esm/webhooks.js +215 -0
  80. package/dist/models/AgentConversationDetail.d.ts +7 -0
  81. package/dist/models/AgentConversationDetail.js +3 -0
  82. package/dist/models/ClarifyBody.d.ts +6 -0
  83. package/dist/models/ClarifyBody.js +2 -0
  84. package/dist/models/ConversationDetail.d.ts +7 -0
  85. package/dist/models/ConversationDetail.js +3 -0
  86. package/dist/models/ErrorDetail.d.ts +1 -0
  87. package/dist/models/ErrorDetail.js +2 -1
  88. package/dist/models/FunctionResultBody.d.ts +44 -0
  89. package/dist/models/FunctionResultBody.js +56 -0
  90. package/dist/models/QueueMessageInput.d.ts +23 -0
  91. package/dist/models/QueueMessageInput.js +15 -1
  92. package/dist/models/RequiredAction.d.ts +77 -0
  93. package/dist/models/RequiredAction.js +77 -0
  94. package/dist/models/ResponseDetail.d.ts +8 -0
  95. package/dist/models/ResponseDetail.js +2 -0
  96. package/dist/models/ResponseInput.d.ts +23 -0
  97. package/dist/models/ResponseInput.js +15 -0
  98. package/dist/models/ToolResults200Response.d.ts +38 -0
  99. package/dist/models/ToolResults200Response.js +54 -0
  100. package/dist/models/ToolResultsBody.d.ts +39 -0
  101. package/dist/models/ToolResultsBody.js +55 -0
  102. package/dist/models/index.d.ts +4 -0
  103. package/dist/models/index.js +4 -0
  104. package/dist/streaming.d.ts +14 -2
  105. package/dist/streaming.js +27 -4
  106. package/dist/webhooks.d.ts +203 -0
  107. package/dist/webhooks.js +224 -0
  108. package/package.json +9 -1
  109. package/src/apis/FunctionToolsApi.ts +102 -0
  110. package/src/apis/index.ts +1 -0
  111. package/src/compose/agent.ts +96 -9
  112. package/src/compose/errors.ts +7 -1
  113. package/src/compose/events.ts +30 -0
  114. package/src/compose/functionTool.ts +441 -0
  115. package/src/compose/index.ts +6 -2
  116. package/src/compose/output.ts +30 -9
  117. package/src/compose/run.ts +115 -18
  118. package/src/compose/runState.ts +44 -5
  119. package/src/compose/settingsTransport.ts +379 -8
  120. package/src/compose/transport.ts +24 -1
  121. package/src/compose/webhook.ts +181 -0
  122. package/src/models/AgentConversationDetail.ts +15 -0
  123. package/src/models/ClarifyBody.ts +8 -0
  124. package/src/models/ConversationDetail.ts +15 -0
  125. package/src/models/ErrorDetail.ts +2 -1
  126. package/src/models/FunctionResultBody.ts +83 -0
  127. package/src/models/QueueMessageInput.ts +28 -0
  128. package/src/models/RequiredAction.ts +128 -0
  129. package/src/models/ResponseDetail.ts +8 -0
  130. package/src/models/ResponseInput.ts +30 -0
  131. package/src/models/ToolResults200Response.ts +75 -0
  132. package/src/models/ToolResultsBody.ts +83 -0
  133. package/src/models/index.ts +4 -0
  134. package/src/streaming.ts +39 -3
  135. package/src/webhooks.ts +390 -0
@@ -0,0 +1,181 @@
1
+ /**
2
+ * `webhooks` entries of `agent.json`, checked locally with the server's cheap rules (as the Python SDK does).
3
+ *
4
+ * The server (`claw_common/agent_settings/webhooks.py`) also checks that the host resolves to a public address and
5
+ * that `secret_credential` names a vault credential bound to the agent whose allowed hosts cover the URL; those need
6
+ * I/O and stay on the server, which refuses the save with a 422 that `deploy` throws as `UserError`. A new agent has
7
+ * no credentials bound yet, so the deploy that creates it binds the caller's Custom API of each named credential first
8
+ * (`SettingsTransport.createAgent`).
9
+ */
10
+ import { UserError } from "./errors.js";
11
+ import { WEBHOOK_EVENTS } from "../webhooks.js";
12
+ import type { WebhookEventType } from "../webhooks.js";
13
+
14
+ /** Where the agent reports a finished, failed or paused turn (agent.json `webhooks[]`). */
15
+ export interface Webhook {
16
+ /** An `https://` URL on port 443 with a DNS host; a query string is allowed. */
17
+ url: string;
18
+ /** 1 to 4 distinct events. `approval.requested` is reserved: accepted, not sent yet. */
19
+ events: WebhookEventType[];
20
+ /** The vault credential holding the `whsec_` signing secret (agent.json `secret_credential`). */
21
+ secretCredential: string;
22
+ }
23
+
24
+ export const WEBHOOKS_MAX = 5;
25
+ const WEBHOOK_URL_MAX = 2048;
26
+ const SECRET_CREDENTIAL_MAX = 256;
27
+
28
+ const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
29
+ // A last label that is a number (decimal, or 0x hex) makes resolvers read the whole host as an IPv4 address.
30
+ const NUMERIC_LABEL = /^(?:[0-9]+|0x[0-9a-f]*)$/;
31
+ const SCHEME = /^[A-Za-z][A-Za-z0-9+\-.]*$/;
32
+
33
+ /** Length in code points, as Python's `len`. */
34
+ function codePoints(text: string): number {
35
+ return Array.from(text).length;
36
+ }
37
+
38
+ /** `[scheme, netloc, path, query]` as Python 3.12's `urlsplit` splits a URL without a fragment. */
39
+ function split(url: string): [string, string, string, string] {
40
+ let rest = url;
41
+ let scheme = "";
42
+ const i = rest.indexOf(":");
43
+ if (i > 0 && SCHEME.test(rest.slice(0, i))) {
44
+ scheme = rest.slice(0, i).toLowerCase();
45
+ rest = rest.slice(i + 1);
46
+ }
47
+ let netloc = "";
48
+ if (rest.slice(0, 2) === "//") {
49
+ let end = rest.length;
50
+ for (const c of "/?#") {
51
+ const at = rest.indexOf(c, 2);
52
+ if (at >= 0) end = Math.min(end, at);
53
+ }
54
+ netloc = rest.slice(2, end);
55
+ rest = rest.slice(end);
56
+ }
57
+ let query = "";
58
+ const q = rest.indexOf("?");
59
+ if (q >= 0) {
60
+ query = rest.slice(q + 1);
61
+ rest = rest.slice(0, q);
62
+ }
63
+ return [scheme, netloc, rest, query];
64
+ }
65
+
66
+ /** Python's `str.partition`. */
67
+ function partition(text: string, sep: string): [string, string, string] {
68
+ const at = text.indexOf(sep);
69
+ return at < 0 ? [text, "", ""] : [text.slice(0, at), sep, text.slice(at + sep.length)];
70
+ }
71
+
72
+ /** `urlsplit`'s host (lowercased) and raw port (`null` when absent or empty). */
73
+ function hostPort(netloc: string): [string, string | null] {
74
+ const hostinfo = netloc.slice(netloc.lastIndexOf("@") + 1);
75
+ const [, bracket, bracketed] = partition(hostinfo, "[");
76
+ let host: string;
77
+ let port: string;
78
+ if (bracket) {
79
+ const [inner, , after] = partition(bracketed, "]");
80
+ host = inner;
81
+ port = partition(after, ":")[2];
82
+ } else {
83
+ [host, , port] = partition(hostinfo, ":");
84
+ }
85
+ return [host.toLowerCase(), port || null];
86
+ }
87
+
88
+ function stripTrailingDots(host: string): string {
89
+ return host.replace(/\.+$/, "");
90
+ }
91
+
92
+ /** Why `url` is not an allowed webhook URL, or null. Every URL the server refuses is refused, with the server's
93
+ * sentence for every URL Python's `urlsplit` parses; for a netloc its NFKC check refuses, the sentence may differ. */
94
+ export function urlProblem(url: string): string | null {
95
+ if (codePoints(url) > WEBHOOK_URL_MAX) return `url must be at most ${WEBHOOK_URL_MAX} characters.`;
96
+ for (let i = 0; i < url.length; i++) {
97
+ const code = url.charCodeAt(i);
98
+ if (code <= 0x20 || code === 0x7f) return "url must not contain spaces or control characters.";
99
+ }
100
+ if (url.indexOf("#") !== -1) return "url must not have a fragment.";
101
+ const [scheme, netloc, path] = split(url);
102
+ if (scheme !== "https") return "url must start with https://.";
103
+ if (netloc.indexOf("@") !== -1) return "url must not contain a user name or password.";
104
+ // urlsplit refuses unbalanced brackets outright
105
+ if ((netloc.indexOf("[") !== -1) !== (netloc.indexOf("]") !== -1)) {
106
+ return "url host must be a DNS name, not an IP address.";
107
+ }
108
+ const [rawHost, port] = hostPort(netloc);
109
+ if (port !== null) {
110
+ if (!/^[0-9]+$/.test(port) || Number(port) > 65535) {
111
+ return "url has an invalid port; leave the port out (443 is used).";
112
+ }
113
+ if (Number(port) !== 443) return "url must use port 443; leave the port out.";
114
+ }
115
+ const host = stripTrailingDots(rawHost);
116
+ if (!host) return "url must name a host, like https://hooks.example.com/panja.";
117
+ if (netloc.indexOf("[") !== -1) return "url host must be a DNS name, not an IP address.";
118
+ const labels = host.split(".");
119
+ if (!labels.every((label) => LABEL.test(label))) return "url host must be a DNS name, like hooks.example.com.";
120
+ if (NUMERIC_LABEL.test(labels[labels.length - 1])) return "url host must be a DNS name, not an IP address.";
121
+ if (path.split("/").some((seg) => seg === "." || seg === "..")) return "url path must not contain . or .. segments.";
122
+ return null;
123
+ }
124
+
125
+ /** Host (lowercased, no trailing dot, no port), path and query: two URLs with one key are one endpoint. */
126
+ function urlKey(url: string): string {
127
+ const [, netloc, path, query] = split(url);
128
+ return `${stripTrailingDots(hostPort(netloc)[0])}${path}?${query}`;
129
+ }
130
+
131
+ /** The server's pure `webhooks` rules (types first); throws `UserError` naming the agent.json path. */
132
+ export function checkWebhooks(webhooks: unknown): void {
133
+ if (!Array.isArray(webhooks)) throw new UserError("webhooks: must be a list of webhooks");
134
+ if (webhooks.length > WEBHOOKS_MAX) {
135
+ throw new UserError(`webhooks: webhooks may hold at most ${WEBHOOKS_MAX} endpoints.`);
136
+ }
137
+ const seen = new Set<string>();
138
+ webhooks.forEach((hook: unknown, i: number) => {
139
+ const where = `webhooks.${i}.`;
140
+ if (typeof hook !== "object" || hook === null || Array.isArray(hook)) {
141
+ throw new UserError(`webhooks.${i}: must be an object with url, events and secretCredential`);
142
+ }
143
+ const { url, events, secretCredential } = hook as Record<string, unknown>;
144
+ if (typeof url !== "string") throw new UserError(where + "url: must be a string");
145
+ if (!Array.isArray(events) || !events.every((e) => typeof e === "string")) {
146
+ throw new UserError(where + "events: must be a list of event names");
147
+ }
148
+ if (typeof secretCredential !== "string") throw new UserError(where + "secretCredential: must be a string");
149
+ // Python's Webhook is extra="forbid": a key dropped silently (a misplaced secret) would never verify.
150
+ const extra = Object.keys(hook).find((k) => k !== "url" && k !== "events" && k !== "secretCredential");
151
+ if (extra !== undefined) throw new UserError(where + extra + ": Extra inputs are not permitted");
152
+ const problem = urlProblem(url);
153
+ if (problem !== null) throw new UserError(where + "url: " + problem);
154
+ if (events.length < 1 || events.length > WEBHOOK_EVENTS.length) {
155
+ throw new UserError(where + `events: events must list 1 to ${WEBHOOK_EVENTS.length} events.`);
156
+ }
157
+ if (events.some((e) => (WEBHOOK_EVENTS as readonly string[]).indexOf(e) === -1)) {
158
+ throw new UserError(where + `events: events must be from: ${WEBHOOK_EVENTS.join(", ")}.`);
159
+ }
160
+ if (new Set(events).size !== events.length) throw new UserError(where + "events: events must not repeat an event.");
161
+ const n = codePoints(secretCredential);
162
+ if (n < 1 || n > SECRET_CREDENTIAL_MAX) {
163
+ throw new UserError(where + "secret_credential: secret_credential must be the name of a vault credential " +
164
+ `(1 to ${SECRET_CREDENTIAL_MAX} characters).`);
165
+ }
166
+ const key = urlKey(url);
167
+ if (seen.has(key)) {
168
+ throw new UserError(where + "url: webhooks must not list the same url twice; put all its events on one entry.");
169
+ }
170
+ seen.add(key);
171
+ });
172
+ }
173
+
174
+ /** Only the three fields, in agent.json's names (a copy). */
175
+ export function copyWebhooks(webhooks: readonly Webhook[]): Webhook[] {
176
+ return webhooks.map((h) => ({ url: h.url, events: [...h.events], secretCredential: h.secretCredential }));
177
+ }
178
+
179
+ export function webhooksJson(webhooks: readonly Webhook[]): Record<string, unknown>[] {
180
+ return webhooks.map((h) => ({ url: h.url, events: [...h.events], secret_credential: h.secretCredential }));
181
+ }
@@ -27,6 +27,13 @@ import {
27
27
  FieldHighlightToJSON,
28
28
  FieldHighlightToJSONTyped,
29
29
  } from './FieldHighlight.js';
30
+ import type { RequiredAction } from './RequiredAction.js';
31
+ import {
32
+ RequiredActionFromJSON,
33
+ RequiredActionFromJSONTyped,
34
+ RequiredActionToJSON,
35
+ RequiredActionToJSONTyped,
36
+ } from './RequiredAction.js';
30
37
  import type { QueuedTurnView } from './QueuedTurnView.js';
31
38
  import {
32
39
  QueuedTurnViewFromJSON,
@@ -155,6 +162,12 @@ export interface AgentConversationDetail {
155
162
  * @memberof AgentConversationDetail
156
163
  */
157
164
  queuedTurns?: Array<QueuedTurnView>;
165
+ /**
166
+ *
167
+ * @type {Array<RequiredAction>}
168
+ * @memberof AgentConversationDetail
169
+ */
170
+ requiredActions?: Array<RequiredAction>;
158
171
  /**
159
172
  *
160
173
  * @type {boolean}
@@ -234,6 +247,7 @@ export function AgentConversationDetailFromJSONTyped(json: any, ignoreDiscrimina
234
247
  'hasMore': json['hasMore'] == null ? undefined : json['hasMore'],
235
248
  'nextBeforeCursor': json['nextBeforeCursor'] == null ? undefined : json['nextBeforeCursor'],
236
249
  'queuedTurns': json['queuedTurns'] == null ? undefined : ((json['queuedTurns'] as Array<any>).map(QueuedTurnViewFromJSON)),
250
+ 'requiredActions': json['requiredActions'] == null ? undefined : ((json['requiredActions'] as Array<any>).map(RequiredActionFromJSON)),
237
251
  'isMine': json['isMine'] == null ? undefined : json['isMine'],
238
252
  'panjaWsId': json['panjaWsId'],
239
253
  'readOnly': json['readOnly'] == null ? undefined : json['readOnly'],
@@ -271,6 +285,7 @@ export function AgentConversationDetailToJSONTyped(value?: AgentConversationDeta
271
285
  'hasMore': value['hasMore'],
272
286
  'nextBeforeCursor': value['nextBeforeCursor'],
273
287
  'queuedTurns': value['queuedTurns'] == null ? undefined : ((value['queuedTurns'] as Array<any>).map(QueuedTurnViewToJSON)),
288
+ 'requiredActions': value['requiredActions'] == null ? undefined : ((value['requiredActions'] as Array<any>).map(RequiredActionToJSON)),
274
289
  'isMine': value['isMine'],
275
290
  'panjaWsId': value['panjaWsId'],
276
291
  'readOnly': value['readOnly'],
@@ -37,6 +37,12 @@ export interface ClarifyBody {
37
37
  * @memberof ClarifyBody
38
38
  */
39
39
  answers?: { [key: string]: any; };
40
+ /**
41
+ *
42
+ * @type {string}
43
+ * @memberof ClarifyBody
44
+ */
45
+ endUserId?: string | null;
40
46
  }
41
47
 
42
48
  /**
@@ -60,6 +66,7 @@ export function ClarifyBodyFromJSONTyped(json: any, ignoreDiscriminator: boolean
60
66
  'requestId': json['requestId'],
61
67
  'action': json['action'] == null ? undefined : json['action'],
62
68
  'answers': json['answers'] == null ? undefined : json['answers'],
69
+ 'endUserId': json['endUserId'] == null ? undefined : json['endUserId'],
63
70
  };
64
71
  }
65
72
 
@@ -77,6 +84,7 @@ export function ClarifyBodyToJSONTyped(value?: ClarifyBody | null, ignoreDiscrim
77
84
  'requestId': value['requestId'],
78
85
  'action': value['action'],
79
86
  'answers': value['answers'],
87
+ 'endUserId': value['endUserId'],
80
88
  };
81
89
  }
82
90
 
@@ -27,6 +27,13 @@ import {
27
27
  FieldHighlightToJSON,
28
28
  FieldHighlightToJSONTyped,
29
29
  } from './FieldHighlight.js';
30
+ import type { RequiredAction } from './RequiredAction.js';
31
+ import {
32
+ RequiredActionFromJSON,
33
+ RequiredActionFromJSONTyped,
34
+ RequiredActionToJSON,
35
+ RequiredActionToJSONTyped,
36
+ } from './RequiredAction.js';
30
37
  import type { QueuedTurnView } from './QueuedTurnView.js';
31
38
  import {
32
39
  QueuedTurnViewFromJSON,
@@ -156,6 +163,12 @@ export interface ConversationDetail {
156
163
  * @memberof ConversationDetail
157
164
  */
158
165
  queuedTurns?: Array<QueuedTurnView>;
166
+ /**
167
+ *
168
+ * @type {Array<RequiredAction>}
169
+ * @memberof ConversationDetail
170
+ */
171
+ requiredActions?: Array<RequiredAction>;
159
172
  }
160
173
 
161
174
  /**
@@ -209,6 +222,7 @@ export function ConversationDetailFromJSONTyped(json: any, ignoreDiscriminator:
209
222
  'hasMore': json['hasMore'] == null ? undefined : json['hasMore'],
210
223
  'nextBeforeCursor': json['nextBeforeCursor'] == null ? undefined : json['nextBeforeCursor'],
211
224
  'queuedTurns': json['queuedTurns'] == null ? undefined : ((json['queuedTurns'] as Array<any>).map(QueuedTurnViewFromJSON)),
225
+ 'requiredActions': json['requiredActions'] == null ? undefined : ((json['requiredActions'] as Array<any>).map(RequiredActionFromJSON)),
212
226
  };
213
227
  }
214
228
 
@@ -242,6 +256,7 @@ export function ConversationDetailToJSONTyped(value?: ConversationDetail | null,
242
256
  'hasMore': value['hasMore'],
243
257
  'nextBeforeCursor': value['nextBeforeCursor'],
244
258
  'queuedTurns': value['queuedTurns'] == null ? undefined : ((value['queuedTurns'] as Array<any>).map(QueuedTurnViewToJSON)),
259
+ 'requiredActions': value['requiredActions'] == null ? undefined : ((value['requiredActions'] as Array<any>).map(RequiredActionToJSON)),
245
260
  };
246
261
  }
247
262
 
@@ -70,7 +70,8 @@ export const ErrorDetailCodeEnum = {
70
70
  RateLimit: 'CHAT_RATE_LIMIT',
71
71
  Unavailable: 'CHAT_UNAVAILABLE',
72
72
  Upstream: 'CHAT_UPSTREAM',
73
- Internal: 'CHAT_INTERNAL'
73
+ Internal: 'CHAT_INTERNAL',
74
+ BalanceExhausted: 'CHAT_BALANCE_EXHAUSTED'
74
75
  } as const;
75
76
  export type ErrorDetailCodeEnum = typeof ErrorDetailCodeEnum[keyof typeof ErrorDetailCodeEnum];
76
77
 
@@ -0,0 +1,83 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Sarvam Agents API
5
+ * 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.
6
+ *
7
+ * The version of the OpenAPI document: 0.1.0
8
+ * Contact: support@sarvam.ai
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime.js';
16
+ /**
17
+ * One call's result, as the app ran it.
18
+ * @export
19
+ * @interface FunctionResultBody
20
+ */
21
+ export interface FunctionResultBody {
22
+ /**
23
+ *
24
+ * @type {string}
25
+ * @memberof FunctionResultBody
26
+ */
27
+ toolCallId: string;
28
+ /**
29
+ *
30
+ * @type {string}
31
+ * @memberof FunctionResultBody
32
+ */
33
+ output: string;
34
+ /**
35
+ *
36
+ * @type {boolean}
37
+ * @memberof FunctionResultBody
38
+ */
39
+ isError?: boolean;
40
+ }
41
+
42
+ /**
43
+ * Check if a given object implements the FunctionResultBody interface.
44
+ */
45
+ export function instanceOfFunctionResultBody(value: object): value is FunctionResultBody {
46
+ if (!('toolCallId' in value) || value['toolCallId'] === undefined) return false;
47
+ if (!('output' in value) || value['output'] === undefined) return false;
48
+ return true;
49
+ }
50
+
51
+ export function FunctionResultBodyFromJSON(json: any): FunctionResultBody {
52
+ return FunctionResultBodyFromJSONTyped(json, false);
53
+ }
54
+
55
+ export function FunctionResultBodyFromJSONTyped(json: any, ignoreDiscriminator: boolean): FunctionResultBody {
56
+ if (json == null) {
57
+ return json;
58
+ }
59
+ return {
60
+
61
+ 'toolCallId': json['toolCallId'],
62
+ 'output': json['output'],
63
+ 'isError': json['isError'] == null ? undefined : json['isError'],
64
+ };
65
+ }
66
+
67
+ export function FunctionResultBodyToJSON(json: any): FunctionResultBody {
68
+ return FunctionResultBodyToJSONTyped(json, false);
69
+ }
70
+
71
+ export function FunctionResultBodyToJSONTyped(value?: FunctionResultBody | null, ignoreDiscriminator: boolean = false): any {
72
+ if (value == null) {
73
+ return value;
74
+ }
75
+
76
+ return {
77
+
78
+ 'toolCallId': value['toolCallId'],
79
+ 'output': value['output'],
80
+ 'isError': value['isError'],
81
+ };
82
+ }
83
+
@@ -51,6 +51,18 @@ export interface QueueMessageInput {
51
51
  * @memberof QueueMessageInput
52
52
  */
53
53
  retryOf?: string | null;
54
+ /**
55
+ *
56
+ * @type {string}
57
+ * @memberof QueueMessageInput
58
+ */
59
+ surface?: QueueMessageInputSurfaceEnum | null;
60
+ /**
61
+ *
62
+ * @type {string}
63
+ * @memberof QueueMessageInput
64
+ */
65
+ endUserId?: string | null;
54
66
  }
55
67
 
56
68
 
@@ -63,6 +75,18 @@ export const QueueMessageInputDeliveryEnum = {
63
75
  } as const;
64
76
  export type QueueMessageInputDeliveryEnum = typeof QueueMessageInputDeliveryEnum[keyof typeof QueueMessageInputDeliveryEnum];
65
77
 
78
+ /**
79
+ * @export
80
+ */
81
+ export const QueueMessageInputSurfaceEnum = {
82
+ Builder: 'builder',
83
+ Playground: 'playground',
84
+ Tests: 'tests',
85
+ Evals: 'evals',
86
+ Cowork: 'cowork'
87
+ } as const;
88
+ export type QueueMessageInputSurfaceEnum = typeof QueueMessageInputSurfaceEnum[keyof typeof QueueMessageInputSurfaceEnum];
89
+
66
90
 
67
91
  /**
68
92
  * Check if a given object implements the QueueMessageInput interface.
@@ -86,6 +110,8 @@ export function QueueMessageInputFromJSONTyped(json: any, ignoreDiscriminator: b
86
110
  'delivery': json['delivery'] == null ? undefined : json['delivery'],
87
111
  'agentId': json['agentId'] == null ? undefined : json['agentId'],
88
112
  'retryOf': json['retryOf'] == null ? undefined : json['retryOf'],
113
+ 'surface': json['surface'] == null ? undefined : json['surface'],
114
+ 'endUserId': json['endUserId'] == null ? undefined : json['endUserId'],
89
115
  };
90
116
  }
91
117
 
@@ -104,6 +130,8 @@ export function QueueMessageInputToJSONTyped(value?: QueueMessageInput | null, i
104
130
  'delivery': value['delivery'],
105
131
  'agentId': value['agentId'],
106
132
  'retryOf': value['retryOf'],
133
+ 'surface': value['surface'],
134
+ 'endUserId': value['endUserId'],
107
135
  };
108
136
  }
109
137
 
@@ -0,0 +1,128 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Sarvam Agents API
5
+ * 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.
6
+ *
7
+ * The version of the OpenAPI document: 0.1.0
8
+ * Contact: support@sarvam.ai
9
+ *
10
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
+ * https://openapi-generator.tech
12
+ * Do not edit the class manually.
13
+ */
14
+
15
+ import { mapValues } from '../runtime.js';
16
+ /**
17
+ * One function call the app must run before the turn can continue.
18
+ * @export
19
+ * @interface RequiredAction
20
+ */
21
+ export interface RequiredAction {
22
+ /**
23
+ *
24
+ * @type {string}
25
+ * @memberof RequiredAction
26
+ */
27
+ type?: RequiredActionTypeEnum;
28
+ /**
29
+ *
30
+ * @type {string}
31
+ * @memberof RequiredAction
32
+ */
33
+ requestId: string;
34
+ /**
35
+ *
36
+ * @type {string}
37
+ * @memberof RequiredAction
38
+ */
39
+ toolCallId: string;
40
+ /**
41
+ *
42
+ * @type {string}
43
+ * @memberof RequiredAction
44
+ */
45
+ name: string;
46
+ /**
47
+ *
48
+ * @type {{ [key: string]: any; }}
49
+ * @memberof RequiredAction
50
+ */
51
+ arguments: { [key: string]: any; };
52
+ /**
53
+ *
54
+ * @type {Date}
55
+ * @memberof RequiredAction
56
+ */
57
+ createdAt: Date;
58
+ /**
59
+ *
60
+ * @type {Date}
61
+ * @memberof RequiredAction
62
+ */
63
+ expiresAt?: Date | null;
64
+ }
65
+
66
+
67
+ /**
68
+ * @export
69
+ */
70
+ export const RequiredActionTypeEnum = {
71
+ FunctionCall: 'function_call'
72
+ } as const;
73
+ export type RequiredActionTypeEnum = typeof RequiredActionTypeEnum[keyof typeof RequiredActionTypeEnum];
74
+
75
+
76
+ /**
77
+ * Check if a given object implements the RequiredAction interface.
78
+ */
79
+ export function instanceOfRequiredAction(value: object): value is RequiredAction {
80
+ if (!('requestId' in value) || value['requestId'] === undefined) return false;
81
+ if (!('toolCallId' in value) || value['toolCallId'] === undefined) return false;
82
+ if (!('name' in value) || value['name'] === undefined) return false;
83
+ if (!('arguments' in value) || value['arguments'] === undefined) return false;
84
+ if (!('createdAt' in value) || value['createdAt'] === undefined) return false;
85
+ return true;
86
+ }
87
+
88
+ export function RequiredActionFromJSON(json: any): RequiredAction {
89
+ return RequiredActionFromJSONTyped(json, false);
90
+ }
91
+
92
+ export function RequiredActionFromJSONTyped(json: any, ignoreDiscriminator: boolean): RequiredAction {
93
+ if (json == null) {
94
+ return json;
95
+ }
96
+ return {
97
+
98
+ 'type': json['type'] == null ? undefined : json['type'],
99
+ 'requestId': json['requestId'],
100
+ 'toolCallId': json['toolCallId'],
101
+ 'name': json['name'],
102
+ 'arguments': json['arguments'],
103
+ 'createdAt': (new Date(json['createdAt'])),
104
+ 'expiresAt': json['expiresAt'] == null ? undefined : (new Date(json['expiresAt'])),
105
+ };
106
+ }
107
+
108
+ export function RequiredActionToJSON(json: any): RequiredAction {
109
+ return RequiredActionToJSONTyped(json, false);
110
+ }
111
+
112
+ export function RequiredActionToJSONTyped(value?: RequiredAction | null, ignoreDiscriminator: boolean = false): any {
113
+ if (value == null) {
114
+ return value;
115
+ }
116
+
117
+ return {
118
+
119
+ 'type': value['type'],
120
+ 'requestId': value['requestId'],
121
+ 'toolCallId': value['toolCallId'],
122
+ 'name': value['name'],
123
+ 'arguments': value['arguments'],
124
+ 'createdAt': ((value['createdAt']).toISOString()),
125
+ 'expiresAt': value['expiresAt'] == null ? undefined : ((value['expiresAt'] as any).toISOString()),
126
+ };
127
+ }
128
+
@@ -45,6 +45,12 @@ export interface ResponseDetail {
45
45
  * @memberof ResponseDetail
46
46
  */
47
47
  output: Array<UIMessage>;
48
+ /**
49
+ *
50
+ * @type {{ [key: string]: any; }}
51
+ * @memberof ResponseDetail
52
+ */
53
+ usage?: { [key: string]: any; } | null;
48
54
  /**
49
55
  *
50
56
  * @type {any}
@@ -113,6 +119,7 @@ export function ResponseDetailFromJSONTyped(json: any, ignoreDiscriminator: bool
113
119
  'responseId': json['responseId'],
114
120
  'status': json['status'],
115
121
  'output': ((json['output'] as Array<any>).map(UIMessageFromJSON)),
122
+ 'usage': json['usage'] == null ? undefined : json['usage'],
116
123
  'structuredOutput': json['structuredOutput'] == null ? undefined : json['structuredOutput'],
117
124
  'outputErrors': json['outputErrors'] == null ? undefined : json['outputErrors'],
118
125
  'outputCitations': json['outputCitations'] == null ? undefined : json['outputCitations'],
@@ -135,6 +142,7 @@ export function ResponseDetailToJSONTyped(value?: ResponseDetail | null, ignoreD
135
142
  'responseId': value['responseId'],
136
143
  'status': value['status'],
137
144
  'output': ((value['output'] as Array<any>).map(UIMessageToJSON)),
145
+ 'usage': value['usage'],
138
146
  'structuredOutput': value['structuredOutput'],
139
147
  'outputErrors': value['outputErrors'],
140
148
  'outputCitations': value['outputCitations'],
@@ -69,8 +69,34 @@ export interface ResponseInput {
69
69
  * @memberof ResponseInput
70
70
  */
71
71
  retryOf?: string | null;
72
+ /**
73
+ *
74
+ * @type {string}
75
+ * @memberof ResponseInput
76
+ */
77
+ surface?: ResponseInputSurfaceEnum | null;
78
+ /**
79
+ *
80
+ * @type {string}
81
+ * @memberof ResponseInput
82
+ */
83
+ endUserId?: string | null;
72
84
  }
73
85
 
86
+
87
+ /**
88
+ * @export
89
+ */
90
+ export const ResponseInputSurfaceEnum = {
91
+ Builder: 'builder',
92
+ Playground: 'playground',
93
+ Tests: 'tests',
94
+ Evals: 'evals',
95
+ Cowork: 'cowork'
96
+ } as const;
97
+ export type ResponseInputSurfaceEnum = typeof ResponseInputSurfaceEnum[keyof typeof ResponseInputSurfaceEnum];
98
+
99
+
74
100
  /**
75
101
  * Check if a given object implements the ResponseInput interface.
76
102
  */
@@ -97,6 +123,8 @@ export function ResponseInputFromJSONTyped(json: any, ignoreDiscriminator: boole
97
123
  'agentId': json['agentId'] == null ? undefined : json['agentId'],
98
124
  'regenerateAfter': json['regenerateAfter'] == null ? undefined : json['regenerateAfter'],
99
125
  'retryOf': json['retryOf'] == null ? undefined : json['retryOf'],
126
+ 'surface': json['surface'] == null ? undefined : json['surface'],
127
+ 'endUserId': json['endUserId'] == null ? undefined : json['endUserId'],
100
128
  };
101
129
  }
102
130
 
@@ -118,6 +146,8 @@ export function ResponseInputToJSONTyped(value?: ResponseInput | null, ignoreDis
118
146
  'agentId': value['agentId'],
119
147
  'regenerateAfter': value['regenerateAfter'],
120
148
  'retryOf': value['retryOf'],
149
+ 'surface': value['surface'],
150
+ 'endUserId': value['endUserId'],
121
151
  };
122
152
  }
123
153