sarvam-agents-client 0.5.4 → 0.5.5

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 (62) hide show
  1. package/README.md +80 -0
  2. package/dist/apis/ConversationsApi.d.ts +15 -1
  3. package/dist/apis/ConversationsApi.js +36 -0
  4. package/dist/apis/FunctionToolsApi.d.ts +3 -3
  5. package/dist/apis/FunctionToolsApi.js +2 -1
  6. package/dist/apis/ResponsesApi.d.ts +3 -3
  7. package/dist/apis/ResponsesApi.js +4 -0
  8. package/dist/esm/apis/ConversationsApi.d.ts +15 -1
  9. package/dist/esm/apis/ConversationsApi.js +37 -1
  10. package/dist/esm/apis/FunctionToolsApi.d.ts +3 -3
  11. package/dist/esm/apis/FunctionToolsApi.js +3 -2
  12. package/dist/esm/apis/ResponsesApi.d.ts +3 -3
  13. package/dist/esm/apis/ResponsesApi.js +5 -1
  14. package/dist/esm/index.d.ts +1 -0
  15. package/dist/esm/index.js +3 -1
  16. package/dist/esm/models/ResponseAccepted.d.ts +57 -0
  17. package/dist/esm/models/ResponseAccepted.js +57 -0
  18. package/dist/esm/models/ResponseStatusError.d.ts +38 -0
  19. package/dist/esm/models/ResponseStatusError.js +47 -0
  20. package/dist/esm/models/ResponseStatusView.d.ts +99 -0
  21. package/dist/esm/models/ResponseStatusView.js +79 -0
  22. package/dist/esm/models/ToolResultsAccepted.d.ts +52 -0
  23. package/dist/esm/models/ToolResultsAccepted.js +55 -0
  24. package/dist/esm/models/ToolResultsBody.d.ts +6 -0
  25. package/dist/esm/models/ToolResultsBody.js +2 -0
  26. package/dist/esm/models/index.d.ts +4 -0
  27. package/dist/esm/models/index.js +4 -0
  28. package/dist/esm/polling.d.ts +122 -0
  29. package/dist/esm/polling.js +249 -0
  30. package/dist/esm/streaming.d.ts +5 -2
  31. package/dist/esm/streaming.js +9 -5
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.js +3 -1
  34. package/dist/models/ResponseAccepted.d.ts +57 -0
  35. package/dist/models/ResponseAccepted.js +65 -0
  36. package/dist/models/ResponseStatusError.d.ts +38 -0
  37. package/dist/models/ResponseStatusError.js +54 -0
  38. package/dist/models/ResponseStatusView.d.ts +99 -0
  39. package/dist/models/ResponseStatusView.js +87 -0
  40. package/dist/models/ToolResultsAccepted.d.ts +52 -0
  41. package/dist/models/ToolResultsAccepted.js +63 -0
  42. package/dist/models/ToolResultsBody.d.ts +6 -0
  43. package/dist/models/ToolResultsBody.js +2 -0
  44. package/dist/models/index.d.ts +4 -0
  45. package/dist/models/index.js +4 -0
  46. package/dist/polling.d.ts +122 -0
  47. package/dist/polling.js +258 -0
  48. package/dist/streaming.d.ts +5 -2
  49. package/dist/streaming.js +9 -5
  50. package/package.json +1 -1
  51. package/src/apis/ConversationsApi.ts +58 -0
  52. package/src/apis/FunctionToolsApi.ts +7 -3
  53. package/src/apis/ResponsesApi.ts +9 -2
  54. package/src/index.ts +3 -1
  55. package/src/models/ResponseAccepted.ts +101 -0
  56. package/src/models/ResponseStatusError.ts +75 -0
  57. package/src/models/ResponseStatusView.ts +164 -0
  58. package/src/models/ToolResultsAccepted.ts +94 -0
  59. package/src/models/ToolResultsBody.ts +8 -0
  60. package/src/models/index.ts +4 -0
  61. package/src/polling.ts +339 -0
  62. package/src/streaming.ts +12 -5
package/README.md CHANGED
@@ -122,6 +122,86 @@ limit for the whole SDK, set `defaults.requestTimeoutMs`. A stream is aborted if
122
122
  server sends a ping every 15 seconds. You can change the limit with `{ idleTimeoutMs }`. To cancel from your own code,
123
123
  pass `{ signal }`. If you stop reading early, call `stream.close()`.
124
124
 
125
+ ## Send a message without streaming (poll for the reply)
126
+
127
+ Use the polling helpers when you don't want to hold a connection open for the whole turn (a background job, a
128
+ serverless function, a client behind a proxy that cuts long requests).
129
+
130
+ `startResponse` sends the message with `stream: false`. The server answers as soon as the turn has started, and the
131
+ turn keeps running on the server whether you stay connected or not. Then poll the status until the turn ends, and
132
+ read the reply once:
133
+
134
+ ```ts
135
+ import { ConversationsApi, startResponse, waitForResponse } from "sarvam-agents-client";
136
+
137
+ const accepted = await startResponse(config, body); // the same body as for streamResponse
138
+ const { conversationId, responseId } = accepted;
139
+ const status = await waitForResponse(config, conversationId, responseId);
140
+
141
+ if (status.status === "completed") {
142
+ const reply = await new ConversationsApi(config).getResponse({ conversationId, responseId });
143
+ // reply.output: the reply's messages
144
+ } else if (status.status === "failed") {
145
+ console.log(status.error?.code, status.error?.message);
146
+ }
147
+ ```
148
+
149
+ The status is one of:
150
+
151
+ | `status` | What it means |
152
+ |---|---|
153
+ | `in_progress` | The agent is still working |
154
+ | `requires_action` | The agent called one of your function tools and waits for the results |
155
+ | `completed` | The reply is ready: read it with `ConversationsApi.getResponse` |
156
+ | `failed` | The turn failed; `status.error` says why (`undelivered`: the message never ran; send it again) |
157
+ | `stopped` | The turn was stopped |
158
+
159
+ Treat a status you don't know as the turn having ended: the server may add more.
160
+
161
+ `waitForResponse` reads the status every second (`{ intervalMs }`) and resolves on any status but `in_progress`. Pass
162
+ `{ maxWaitMs }` to give up waiting: it bounds the whole wait, status reads included, and throws `PollTimeoutError`
163
+ (with `responseId` and `lastStatus`) while the turn goes on running on the server. Pass `{ onStatus }` to see every
164
+ read and `{ signal }` to cancel (the helpers then reject with the signal's reason). `getStatus` is a single read.
165
+ Every helper takes `{ timeoutMs }`, each request's timeout (default 30 s, a `TimeoutError` past it); these requests
166
+ never carry a stream, so they always have one.
167
+
168
+ **Answer the agent's function calls.** On `requires_action`, `status.requiredActions` lists the calls (`requestId`,
169
+ `toolCallId`, `name`, `arguments`, `expiresAt`). Run them, post every result in one request, then wait again on the
170
+ same response id:
171
+
172
+ ```ts
173
+ import { submitToolResults } from "sarvam-agents-client";
174
+
175
+ let current = status;
176
+ while (current.status === "requires_action" && current.requiredActions?.length) {
177
+ const actions = current.requiredActions;
178
+ await submitToolResults(config, conversationId, {
179
+ requestId: actions[0].requestId,
180
+ results: actions.map((a) => ({ toolCallId: a.toolCallId, output: run(a.name, a.arguments) })),
181
+ }, { idempotencyKey: actions[0].requestId });
182
+ current = await waitForResponse(config, conversationId, responseId);
183
+ }
184
+ ```
185
+
186
+ Keep the same `idempotencyKey` when you retry a post (the request id above is one that stays the same); a repeat the
187
+ server already has resolves with `duplicate: true` and changes nothing.
188
+
189
+ **Retrying a send.** The server knows a message by its `message.id`. If `startResponse` fails without an answer
190
+ (a timeout, a dropped connection), send the same body again, with the same `message.id`: if the first send started
191
+ the turn, you get that turn back (`accepted.duplicate` is `true`) and nothing runs twice. A `409` whose
192
+ `details[0].reason` is `RESPONSE_STARTING` means the first send is still starting: send it again in a moment. Give
193
+ every new message a new `message.id`.
194
+
195
+ **Errors.** A refused start throws `ResponseError` and leaves nothing behind: `409` while another response runs in
196
+ the conversation, `503` on a server where polling is not turned on (send that turn with streaming instead) or when
197
+ the server could not record the turn (send it again). A `503` from `submitToolResults` means nothing was forwarded:
198
+ retry with the same `idempotencyKey`.
199
+ Non-streaming needs a server that supports it; an older server streams the turn instead, and the helpers then cancel
200
+ that stream and throw `PollingUnsupportedError` (the turn still runs, and its reply lands in the conversation's
201
+ history).
202
+
203
+ The streaming helpers (`streamResponse`, `postToolResults`) always send `stream: true`, whatever your body says.
204
+
125
205
  ## Files
126
206
 
127
207
  To attach a file to a message:
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ConversationDetail, ConversationView, CreateConversationBody, FeedbackBody, FeedbackResult, PageConversationView, ResponseDetail, UpdateConversationBody } from '../models/index.js';
13
+ import type { ConversationDetail, ConversationView, CreateConversationBody, FeedbackBody, FeedbackResult, PageConversationView, ResponseDetail, ResponseStatusView, UpdateConversationBody } from '../models/index.js';
14
14
  export interface CreateConversationRequest {
15
15
  createConversationBody: CreateConversationBody;
16
16
  origin?: CreateConversationOriginEnum;
@@ -30,6 +30,10 @@ export interface GetResponseRequest {
30
30
  responseId: string;
31
31
  xClientFeatures?: string | null;
32
32
  }
33
+ export interface GetResponseStatusRequest {
34
+ conversationId: string;
35
+ responseId: string;
36
+ }
33
37
  export interface ListConversationsRequest {
34
38
  limit?: number;
35
39
  cursor?: string | null;
@@ -92,6 +96,16 @@ export declare class ConversationsApi extends runtime.BaseAPI {
92
96
  * Get Response Route
93
97
  */
94
98
  getResponse(requestParameters: GetResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ResponseDetail>;
99
+ /**
100
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
101
+ * Get Response Status Route
102
+ */
103
+ getResponseStatusRaw(requestParameters: GetResponseStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ResponseStatusView>>;
104
+ /**
105
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
106
+ * Get Response Status Route
107
+ */
108
+ getResponseStatus(requestParameters: GetResponseStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ResponseStatusView>;
95
109
  /**
96
110
  * List Conversations Route
97
111
  */
@@ -170,6 +170,42 @@ class ConversationsApi extends runtime.BaseAPI {
170
170
  const response = await this.getResponseRaw(requestParameters, initOverrides);
171
171
  return await response.value();
172
172
  }
173
+ /**
174
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
175
+ * Get Response Status Route
176
+ */
177
+ async getResponseStatusRaw(requestParameters, initOverrides) {
178
+ if (requestParameters['conversationId'] == null) {
179
+ throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling getResponseStatus().');
180
+ }
181
+ if (requestParameters['responseId'] == null) {
182
+ throw new runtime.RequiredError('responseId', 'Required parameter "responseId" was null or undefined when calling getResponseStatus().');
183
+ }
184
+ const queryParameters = {};
185
+ const headerParameters = {};
186
+ if (this.configuration && this.configuration.accessToken) {
187
+ const token = this.configuration.accessToken;
188
+ const tokenString = await token("bearerAuth", []);
189
+ if (tokenString) {
190
+ headerParameters["Authorization"] = `Bearer ${tokenString}`;
191
+ }
192
+ }
193
+ const response = await this.request({
194
+ path: `/v1/conversations/{conversationId}/responses/{responseId}/status`.replace(`{${"conversationId"}}`, runtime.encodePathParam('conversationId', requestParameters['conversationId'])).replace(`{${"responseId"}}`, runtime.encodePathParam('responseId', requestParameters['responseId'])),
195
+ method: 'GET',
196
+ headers: headerParameters,
197
+ query: queryParameters,
198
+ }, initOverrides);
199
+ return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.ResponseStatusViewFromJSON)(jsonValue));
200
+ }
201
+ /**
202
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
203
+ * Get Response Status Route
204
+ */
205
+ async getResponseStatus(requestParameters, initOverrides) {
206
+ const response = await this.getResponseStatusRaw(requestParameters, initOverrides);
207
+ return await response.value();
208
+ }
173
209
  /**
174
210
  * List Conversations Route
175
211
  */
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ToolResults200Response, ToolResultsBody } from '../models/index.js';
13
+ import type { ToolResults200Response, ToolResultsAccepted, ToolResultsBody } from '../models/index.js';
14
14
  export interface ToolResultsRequest {
15
15
  conversationId: string;
16
16
  toolResultsBody: ToolResultsBody;
@@ -24,10 +24,10 @@ export declare class FunctionToolsApi extends runtime.BaseAPI {
24
24
  * Answer a paused turn\'s function calls and stream its continuation.
25
25
  * Tool Results Route
26
26
  */
27
- toolResultsRaw(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ToolResults200Response>>;
27
+ toolResultsRaw(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ToolResults200Response | ToolResultsAccepted>>;
28
28
  /**
29
29
  * Answer a paused turn\'s function calls and stream its continuation.
30
30
  * Tool Results Route
31
31
  */
32
- toolResults(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ToolResults200Response>;
32
+ toolResults(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ToolResults200Response | ToolResultsAccepted>;
33
33
  }
@@ -24,6 +24,7 @@ class FunctionToolsApi extends runtime.BaseAPI {
24
24
  * Answer a paused turn\'s function calls and stream its continuation.
25
25
  * Tool Results Route
26
26
  */
27
+ // sarvam: tool-results-202
27
28
  async toolResultsRaw(requestParameters, initOverrides) {
28
29
  if (requestParameters['conversationId'] == null) {
29
30
  throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling toolResults().');
@@ -51,7 +52,7 @@ class FunctionToolsApi extends runtime.BaseAPI {
51
52
  query: queryParameters,
52
53
  body: (0, index_js_1.ToolResultsBodyToJSON)(requestParameters['toolResultsBody']),
53
54
  }, initOverrides);
54
- return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.ToolResults200ResponseFromJSON)(jsonValue));
55
+ return new runtime.JSONApiResponse(response, (jsonValue) => response.status === 202 ? (0, index_js_1.ToolResultsAcceptedFromJSON)(jsonValue) : (0, index_js_1.ToolResults200ResponseFromJSON)(jsonValue)); // sarvam: tool-results-202-body
55
56
  }
56
57
  /**
57
58
  * Answer a paused turn\'s function calls and stream its continuation.
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ResponseInput, StopResponse } from '../models/index.js';
13
+ import type { ResponseAccepted, ResponseInput, StopResponse } from '../models/index.js';
14
14
  export interface CreateResponseRequest {
15
15
  responseInput: ResponseInput;
16
16
  xClientFeatures?: string | null;
@@ -40,11 +40,11 @@ export declare class ResponsesApi extends runtime.BaseAPI {
40
40
  /**
41
41
  * Create Response Route
42
42
  */
43
- createResponseRaw(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string>>;
43
+ createResponseRaw(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string | ResponseAccepted>>;
44
44
  /**
45
45
  * Create Response Route
46
46
  */
47
- createResponse(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string>;
47
+ createResponse(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string | ResponseAccepted>;
48
48
  /**
49
49
  * Resume an in-flight turn. The client supplies the turn it is resuming: ``active_response_id`` (mandatory — the FE has it from GET /conversations or /messages) is used as the assistant message id so the resumed stream merges; ``Last-Event-ID`` is the resume cursor — the ``last_event_id`` from GET /conversations, or ``0`` to replay the whole turn from the digest (works for finished turns too); ``reconnect_flag`` marks a warm reconnect (client still holds history) vs a fresh open after GET /conversations. ``X-New-Conversation: true`` says this is the FIRST turn of a session the caller has just created. It holds nothing and the session holds one turn, so the stream is opened bare — no cursor, no turn scope — and replays the session from its oldest retained event, which is that turn from its start. Nothing is read from the digest. Without this header, an accepted response whose digest has no numeric events waits for the detached relay\'s first durable boundary. This also handles follow-up turns. If the bounded wait expires, the stream reports temporary unavailability and preserves the active response for retry. Only the caller can make the claim, and only the caller that created the conversation should: on a session with history the same subscription replays every retained turn and closes on the first terminal it reaches. ``Last-Event-ID`` is optional, and anything that is not a positive integer (absent, ``null`` from a client that stringified a null cursor, ``0``, junk) means the same thing — the client holds no cursor. It used to be a required int, which made the state this header exists for impossible to even send. The cursor no longer has to come from GET /conversations: every streamed chunk that originated at the gateway carries its JetStream sequence as an SSE ``id:`` line, so a client that tracks the last id it saw can reconnect here directly. Chunks the service synthesizes carry none, which per the SSE spec leaves that cursor untouched. The replay is block-granular: the cursor is rounded down to the last durable block boundary, so a client MUST discard the in-flight message\'s open blocks when this stream opens — at most one partially-seen block is re-sent, and the replay is authoritative. No server-side probe: the FE only opens this when it knows a turn is live. A single-row ownership check guards against streaming someone else\'s conversation (the gateway has no app-layer auth). The relay this opens is detached: a client disconnect closes only the frontend writer, and the relay keeps persisting the turn to its terminal and clears ``active_response_id`` itself. Several reloads of one live turn therefore run several relays on the same response; digest appends are idempotent on ``(conversation_id, event_id)`` and the pointer clear is a compare-and-set, so that is safe, just not free.
50
50
  * Reconnect Stream Route
@@ -23,6 +23,7 @@ class ResponsesApi extends runtime.BaseAPI {
23
23
  /**
24
24
  * Create Response Route
25
25
  */
26
+ // sarvam: responses-202
26
27
  async createResponseRaw(requestParameters, initOverrides) {
27
28
  if (requestParameters['responseInput'] == null) {
28
29
  throw new runtime.RequiredError('responseInput', 'Required parameter "responseInput" was null or undefined when calling createResponse().');
@@ -56,6 +57,9 @@ class ResponsesApi extends runtime.BaseAPI {
56
57
  query: queryParameters,
57
58
  body: (0, index_js_1.ResponseInputToJSON)(requestParameters['responseInput']),
58
59
  }, initOverrides);
60
+ if (response.status === 202) { // sarvam: responses-202-body
61
+ return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.ResponseAcceptedFromJSON)(jsonValue));
62
+ }
59
63
  if (this.isJsonMime(response.headers.get('content-type'))) {
60
64
  return new runtime.JSONApiResponse(response);
61
65
  }
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ConversationDetail, ConversationView, CreateConversationBody, FeedbackBody, FeedbackResult, PageConversationView, ResponseDetail, UpdateConversationBody } from '../models/index.js';
13
+ import type { ConversationDetail, ConversationView, CreateConversationBody, FeedbackBody, FeedbackResult, PageConversationView, ResponseDetail, ResponseStatusView, UpdateConversationBody } from '../models/index.js';
14
14
  export interface CreateConversationRequest {
15
15
  createConversationBody: CreateConversationBody;
16
16
  origin?: CreateConversationOriginEnum;
@@ -30,6 +30,10 @@ export interface GetResponseRequest {
30
30
  responseId: string;
31
31
  xClientFeatures?: string | null;
32
32
  }
33
+ export interface GetResponseStatusRequest {
34
+ conversationId: string;
35
+ responseId: string;
36
+ }
33
37
  export interface ListConversationsRequest {
34
38
  limit?: number;
35
39
  cursor?: string | null;
@@ -92,6 +96,16 @@ export declare class ConversationsApi extends runtime.BaseAPI {
92
96
  * Get Response Route
93
97
  */
94
98
  getResponse(requestParameters: GetResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ResponseDetail>;
99
+ /**
100
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
101
+ * Get Response Status Route
102
+ */
103
+ getResponseStatusRaw(requestParameters: GetResponseStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ResponseStatusView>>;
104
+ /**
105
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
106
+ * Get Response Status Route
107
+ */
108
+ getResponseStatus(requestParameters: GetResponseStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ResponseStatusView>;
95
109
  /**
96
110
  * List Conversations Route
97
111
  */
@@ -12,7 +12,7 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
  import * as runtime from '../runtime.js';
15
- import { ConversationDetailFromJSON, ConversationViewFromJSON, CreateConversationBodyToJSON, FeedbackBodyToJSON, FeedbackResultFromJSON, PageConversationViewFromJSON, ResponseDetailFromJSON, UpdateConversationBodyToJSON, } from '../models/index.js';
15
+ import { ConversationDetailFromJSON, ConversationViewFromJSON, CreateConversationBodyToJSON, FeedbackBodyToJSON, FeedbackResultFromJSON, PageConversationViewFromJSON, ResponseDetailFromJSON, ResponseStatusViewFromJSON, UpdateConversationBodyToJSON, } from '../models/index.js';
16
16
  /**
17
17
  *
18
18
  */
@@ -167,6 +167,42 @@ export class ConversationsApi extends runtime.BaseAPI {
167
167
  const response = await this.getResponseRaw(requestParameters, initOverrides);
168
168
  return await response.value();
169
169
  }
170
+ /**
171
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
172
+ * Get Response Status Route
173
+ */
174
+ async getResponseStatusRaw(requestParameters, initOverrides) {
175
+ if (requestParameters['conversationId'] == null) {
176
+ throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling getResponseStatus().');
177
+ }
178
+ if (requestParameters['responseId'] == null) {
179
+ throw new runtime.RequiredError('responseId', 'Required parameter "responseId" was null or undefined when calling getResponseStatus().');
180
+ }
181
+ const queryParameters = {};
182
+ const headerParameters = {};
183
+ if (this.configuration && this.configuration.accessToken) {
184
+ const token = this.configuration.accessToken;
185
+ const tokenString = await token("bearerAuth", []);
186
+ if (tokenString) {
187
+ headerParameters["Authorization"] = `Bearer ${tokenString}`;
188
+ }
189
+ }
190
+ const response = await this.request({
191
+ path: `/v1/conversations/{conversationId}/responses/{responseId}/status`.replace(`{${"conversationId"}}`, runtime.encodePathParam('conversationId', requestParameters['conversationId'])).replace(`{${"responseId"}}`, runtime.encodePathParam('responseId', requestParameters['responseId'])),
192
+ method: 'GET',
193
+ headers: headerParameters,
194
+ query: queryParameters,
195
+ }, initOverrides);
196
+ return new runtime.JSONApiResponse(response, (jsonValue) => ResponseStatusViewFromJSON(jsonValue));
197
+ }
198
+ /**
199
+ * The status of one response, for a caller that sent ``stream: false``. Poll every 1–2 seconds while it is ``in_progress``. On ``requires_action``, answer ``requiredActions`` with ``POST /v1/conversations/{conversationId}/tool-results``. Once it is ``completed``, ``failed`` or ``stopped``, read the reply once from ``GET /v1/conversations/{conversationId}/responses/{responseId}``.
200
+ * Get Response Status Route
201
+ */
202
+ async getResponseStatus(requestParameters, initOverrides) {
203
+ const response = await this.getResponseStatusRaw(requestParameters, initOverrides);
204
+ return await response.value();
205
+ }
170
206
  /**
171
207
  * List Conversations Route
172
208
  */
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ToolResults200Response, ToolResultsBody } from '../models/index.js';
13
+ import type { ToolResults200Response, ToolResultsAccepted, ToolResultsBody } from '../models/index.js';
14
14
  export interface ToolResultsRequest {
15
15
  conversationId: string;
16
16
  toolResultsBody: ToolResultsBody;
@@ -24,10 +24,10 @@ export declare class FunctionToolsApi extends runtime.BaseAPI {
24
24
  * Answer a paused turn\'s function calls and stream its continuation.
25
25
  * Tool Results Route
26
26
  */
27
- toolResultsRaw(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ToolResults200Response>>;
27
+ toolResultsRaw(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ToolResults200Response | ToolResultsAccepted>>;
28
28
  /**
29
29
  * Answer a paused turn\'s function calls and stream its continuation.
30
30
  * Tool Results Route
31
31
  */
32
- toolResults(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ToolResults200Response>;
32
+ toolResults(requestParameters: ToolResultsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ToolResults200Response | ToolResultsAccepted>;
33
33
  }
@@ -12,7 +12,7 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
  import * as runtime from '../runtime.js';
15
- import { ToolResults200ResponseFromJSON, ToolResultsBodyToJSON, } from '../models/index.js';
15
+ import { ToolResults200ResponseFromJSON, ToolResultsAcceptedFromJSON, ToolResultsBodyToJSON, } from '../models/index.js';
16
16
  /**
17
17
  *
18
18
  */
@@ -21,6 +21,7 @@ export class FunctionToolsApi extends runtime.BaseAPI {
21
21
  * Answer a paused turn\'s function calls and stream its continuation.
22
22
  * Tool Results Route
23
23
  */
24
+ // sarvam: tool-results-202
24
25
  async toolResultsRaw(requestParameters, initOverrides) {
25
26
  if (requestParameters['conversationId'] == null) {
26
27
  throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling toolResults().');
@@ -48,7 +49,7 @@ export class FunctionToolsApi extends runtime.BaseAPI {
48
49
  query: queryParameters,
49
50
  body: ToolResultsBodyToJSON(requestParameters['toolResultsBody']),
50
51
  }, initOverrides);
51
- return new runtime.JSONApiResponse(response, (jsonValue) => ToolResults200ResponseFromJSON(jsonValue));
52
+ return new runtime.JSONApiResponse(response, (jsonValue) => response.status === 202 ? ToolResultsAcceptedFromJSON(jsonValue) : ToolResults200ResponseFromJSON(jsonValue)); // sarvam: tool-results-202-body
52
53
  }
53
54
  /**
54
55
  * Answer a paused turn\'s function calls and stream its continuation.
@@ -10,7 +10,7 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  import * as runtime from '../runtime.js';
13
- import type { ResponseInput, StopResponse } from '../models/index.js';
13
+ import type { ResponseAccepted, ResponseInput, StopResponse } from '../models/index.js';
14
14
  export interface CreateResponseRequest {
15
15
  responseInput: ResponseInput;
16
16
  xClientFeatures?: string | null;
@@ -40,11 +40,11 @@ export declare class ResponsesApi extends runtime.BaseAPI {
40
40
  /**
41
41
  * Create Response Route
42
42
  */
43
- createResponseRaw(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string>>;
43
+ createResponseRaw(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string | ResponseAccepted>>;
44
44
  /**
45
45
  * Create Response Route
46
46
  */
47
- createResponse(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string>;
47
+ createResponse(requestParameters: CreateResponseRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string | ResponseAccepted>;
48
48
  /**
49
49
  * Resume an in-flight turn. The client supplies the turn it is resuming: ``active_response_id`` (mandatory — the FE has it from GET /conversations or /messages) is used as the assistant message id so the resumed stream merges; ``Last-Event-ID`` is the resume cursor — the ``last_event_id`` from GET /conversations, or ``0`` to replay the whole turn from the digest (works for finished turns too); ``reconnect_flag`` marks a warm reconnect (client still holds history) vs a fresh open after GET /conversations. ``X-New-Conversation: true`` says this is the FIRST turn of a session the caller has just created. It holds nothing and the session holds one turn, so the stream is opened bare — no cursor, no turn scope — and replays the session from its oldest retained event, which is that turn from its start. Nothing is read from the digest. Without this header, an accepted response whose digest has no numeric events waits for the detached relay\'s first durable boundary. This also handles follow-up turns. If the bounded wait expires, the stream reports temporary unavailability and preserves the active response for retry. Only the caller can make the claim, and only the caller that created the conversation should: on a session with history the same subscription replays every retained turn and closes on the first terminal it reaches. ``Last-Event-ID`` is optional, and anything that is not a positive integer (absent, ``null`` from a client that stringified a null cursor, ``0``, junk) means the same thing — the client holds no cursor. It used to be a required int, which made the state this header exists for impossible to even send. The cursor no longer has to come from GET /conversations: every streamed chunk that originated at the gateway carries its JetStream sequence as an SSE ``id:`` line, so a client that tracks the last id it saw can reconnect here directly. Chunks the service synthesizes carry none, which per the SSE spec leaves that cursor untouched. The replay is block-granular: the cursor is rounded down to the last durable block boundary, so a client MUST discard the in-flight message\'s open blocks when this stream opens — at most one partially-seen block is re-sent, and the replay is authoritative. No server-side probe: the FE only opens this when it knows a turn is live. A single-row ownership check guards against streaming someone else\'s conversation (the gateway has no app-layer auth). The relay this opens is detached: a client disconnect closes only the frontend writer, and the relay keeps persisting the turn to its terminal and clears ``active_response_id`` itself. Several reloads of one live turn therefore run several relays on the same response; digest appends are idempotent on ``(conversation_id, event_id)`` and the pointer clear is a compare-and-set, so that is safe, just not free.
50
50
  * Reconnect Stream Route
@@ -12,7 +12,7 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
  import * as runtime from '../runtime.js';
15
- import { ResponseInputToJSON, StopResponseFromJSON, } from '../models/index.js';
15
+ import { ResponseAcceptedFromJSON, ResponseInputToJSON, StopResponseFromJSON, } from '../models/index.js';
16
16
  /**
17
17
  *
18
18
  */
@@ -20,6 +20,7 @@ export class ResponsesApi extends runtime.BaseAPI {
20
20
  /**
21
21
  * Create Response Route
22
22
  */
23
+ // sarvam: responses-202
23
24
  async createResponseRaw(requestParameters, initOverrides) {
24
25
  if (requestParameters['responseInput'] == null) {
25
26
  throw new runtime.RequiredError('responseInput', 'Required parameter "responseInput" was null or undefined when calling createResponse().');
@@ -53,6 +54,9 @@ export class ResponsesApi extends runtime.BaseAPI {
53
54
  query: queryParameters,
54
55
  body: ResponseInputToJSON(requestParameters['responseInput']),
55
56
  }, initOverrides);
57
+ if (response.status === 202) { // sarvam: responses-202-body
58
+ return new runtime.JSONApiResponse(response, (jsonValue) => ResponseAcceptedFromJSON(jsonValue));
59
+ }
56
60
  if (this.isJsonMime(response.headers.get('content-type'))) {
57
61
  return new runtime.JSONApiResponse(response);
58
62
  }
@@ -2,6 +2,7 @@ export * from './runtime.js';
2
2
  export * from './apis/index.js';
3
3
  export * from './models/index.js';
4
4
  export * from './streaming.js';
5
+ export * from './polling.js';
5
6
  export { Client } from './client.js';
6
7
  export { WebhookSecrets, PREVIOUS_SECRET_SECONDS } from './compose/webhookSecrets.js';
7
8
  export { SecretExistsError } from './compose/errors.js';
package/dist/esm/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- // Hand-maintained entry point (listed in .openapi-generator-ignore): the generated exports plus the streaming helpers.
3
+ // Hand-maintained entry point (listed in .openapi-generator-ignore): the generated exports plus the streaming and polling helpers.
4
4
  export * from './runtime.js';
5
5
  export * from './apis/index.js';
6
6
  export * from './models/index.js';
7
7
  export * from './streaming.js';
8
+ // Hand-written: start a turn with stream: false and poll its status.
9
+ export * from './polling.js';
8
10
  // Hand-written: the high-level client (client.webhooks, client.triggers).
9
11
  export { Client } from './client.js';
10
12
  export { WebhookSecrets, PREVIOUS_SECRET_SECONDS } from './compose/webhookSecrets.js';
@@ -0,0 +1,57 @@
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
+ /**
13
+ * ``202`` for ``stream: false``: the turn started; poll its status.
14
+ * @export
15
+ * @interface ResponseAccepted
16
+ */
17
+ export interface ResponseAccepted {
18
+ /**
19
+ *
20
+ * @type {string}
21
+ * @memberof ResponseAccepted
22
+ */
23
+ conversationId: string;
24
+ /**
25
+ *
26
+ * @type {string}
27
+ * @memberof ResponseAccepted
28
+ */
29
+ responseId: string;
30
+ /**
31
+ *
32
+ * @type {string}
33
+ * @memberof ResponseAccepted
34
+ */
35
+ status?: ResponseAcceptedStatusEnum;
36
+ /**
37
+ *
38
+ * @type {boolean}
39
+ * @memberof ResponseAccepted
40
+ */
41
+ duplicate?: boolean;
42
+ }
43
+ /**
44
+ * @export
45
+ */
46
+ export declare const ResponseAcceptedStatusEnum: {
47
+ readonly InProgress: "in_progress";
48
+ };
49
+ export type ResponseAcceptedStatusEnum = typeof ResponseAcceptedStatusEnum[keyof typeof ResponseAcceptedStatusEnum];
50
+ /**
51
+ * Check if a given object implements the ResponseAccepted interface.
52
+ */
53
+ export declare function instanceOfResponseAccepted(value: object): value is ResponseAccepted;
54
+ export declare function ResponseAcceptedFromJSON(json: any): ResponseAccepted;
55
+ export declare function ResponseAcceptedFromJSONTyped(json: any, ignoreDiscriminator: boolean): ResponseAccepted;
56
+ export declare function ResponseAcceptedToJSON(json: any): ResponseAccepted;
57
+ export declare function ResponseAcceptedToJSONTyped(value?: ResponseAccepted | null, ignoreDiscriminator?: boolean): any;
@@ -0,0 +1,57 @@
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
+ * @export
16
+ */
17
+ export const ResponseAcceptedStatusEnum = {
18
+ InProgress: 'in_progress'
19
+ };
20
+ /**
21
+ * Check if a given object implements the ResponseAccepted interface.
22
+ */
23
+ export function instanceOfResponseAccepted(value) {
24
+ if (!('conversationId' in value) || value['conversationId'] === undefined)
25
+ return false;
26
+ if (!('responseId' in value) || value['responseId'] === undefined)
27
+ return false;
28
+ return true;
29
+ }
30
+ export function ResponseAcceptedFromJSON(json) {
31
+ return ResponseAcceptedFromJSONTyped(json, false);
32
+ }
33
+ export function ResponseAcceptedFromJSONTyped(json, ignoreDiscriminator) {
34
+ if (json == null) {
35
+ return json;
36
+ }
37
+ return {
38
+ 'conversationId': json['conversationId'],
39
+ 'responseId': json['responseId'],
40
+ 'status': json['status'] == null ? undefined : json['status'],
41
+ 'duplicate': json['duplicate'] == null ? undefined : json['duplicate'],
42
+ };
43
+ }
44
+ export function ResponseAcceptedToJSON(json) {
45
+ return ResponseAcceptedToJSONTyped(json, false);
46
+ }
47
+ export function ResponseAcceptedToJSONTyped(value, ignoreDiscriminator = false) {
48
+ if (value == null) {
49
+ return value;
50
+ }
51
+ return {
52
+ 'conversationId': value['conversationId'],
53
+ 'responseId': value['responseId'],
54
+ 'status': value['status'],
55
+ 'duplicate': value['duplicate'],
56
+ };
57
+ }
@@ -0,0 +1,38 @@
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
+ /**
13
+ *
14
+ * @export
15
+ * @interface ResponseStatusError
16
+ */
17
+ export interface ResponseStatusError {
18
+ /**
19
+ *
20
+ * @type {string}
21
+ * @memberof ResponseStatusError
22
+ */
23
+ code: string;
24
+ /**
25
+ *
26
+ * @type {string}
27
+ * @memberof ResponseStatusError
28
+ */
29
+ message: string;
30
+ }
31
+ /**
32
+ * Check if a given object implements the ResponseStatusError interface.
33
+ */
34
+ export declare function instanceOfResponseStatusError(value: object): value is ResponseStatusError;
35
+ export declare function ResponseStatusErrorFromJSON(json: any): ResponseStatusError;
36
+ export declare function ResponseStatusErrorFromJSONTyped(json: any, ignoreDiscriminator: boolean): ResponseStatusError;
37
+ export declare function ResponseStatusErrorToJSON(json: any): ResponseStatusError;
38
+ export declare function ResponseStatusErrorToJSONTyped(value?: ResponseStatusError | null, ignoreDiscriminator?: boolean): any;