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
@@ -58,7 +58,30 @@ export interface ResponseInput {
58
58
  * @memberof ResponseInput
59
59
  */
60
60
  retryOf?: string | null;
61
+ /**
62
+ *
63
+ * @type {string}
64
+ * @memberof ResponseInput
65
+ */
66
+ surface?: ResponseInputSurfaceEnum | null;
67
+ /**
68
+ *
69
+ * @type {string}
70
+ * @memberof ResponseInput
71
+ */
72
+ endUserId?: string | null;
61
73
  }
74
+ /**
75
+ * @export
76
+ */
77
+ export declare const ResponseInputSurfaceEnum: {
78
+ readonly Builder: "builder";
79
+ readonly Playground: "playground";
80
+ readonly Tests: "tests";
81
+ readonly Evals: "evals";
82
+ readonly Cowork: "cowork";
83
+ };
84
+ export type ResponseInputSurfaceEnum = typeof ResponseInputSurfaceEnum[keyof typeof ResponseInputSurfaceEnum];
62
85
  /**
63
86
  * Check if a given object implements the ResponseInput interface.
64
87
  */
@@ -12,6 +12,16 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
  import { InputMessageFromJSON, InputMessageToJSON, } from './InputMessage.js';
15
+ /**
16
+ * @export
17
+ */
18
+ export const ResponseInputSurfaceEnum = {
19
+ Builder: 'builder',
20
+ Playground: 'playground',
21
+ Tests: 'tests',
22
+ Evals: 'evals',
23
+ Cowork: 'cowork'
24
+ };
15
25
  /**
16
26
  * Check if a given object implements the ResponseInput interface.
17
27
  */
@@ -37,6 +47,8 @@ export function ResponseInputFromJSONTyped(json, ignoreDiscriminator) {
37
47
  'agentId': json['agentId'] == null ? undefined : json['agentId'],
38
48
  'regenerateAfter': json['regenerateAfter'] == null ? undefined : json['regenerateAfter'],
39
49
  'retryOf': json['retryOf'] == null ? undefined : json['retryOf'],
50
+ 'surface': json['surface'] == null ? undefined : json['surface'],
51
+ 'endUserId': json['endUserId'] == null ? undefined : json['endUserId'],
40
52
  };
41
53
  }
42
54
  export function ResponseInputToJSON(json) {
@@ -54,5 +66,7 @@ export function ResponseInputToJSONTyped(value, ignoreDiscriminator = false) {
54
66
  'agentId': value['agentId'],
55
67
  'regenerateAfter': value['regenerateAfter'],
56
68
  'retryOf': value['retryOf'],
69
+ 'surface': value['surface'],
70
+ 'endUserId': value['endUserId'],
57
71
  };
58
72
  }
@@ -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 ToolResults200Response
16
+ */
17
+ export interface ToolResults200Response {
18
+ /**
19
+ *
20
+ * @type {boolean}
21
+ * @memberof ToolResults200Response
22
+ */
23
+ accepted: boolean | null;
24
+ /**
25
+ *
26
+ * @type {boolean}
27
+ * @memberof ToolResults200Response
28
+ */
29
+ duplicate: boolean | null;
30
+ }
31
+ /**
32
+ * Check if a given object implements the ToolResults200Response interface.
33
+ */
34
+ export declare function instanceOfToolResults200Response(value: object): value is ToolResults200Response;
35
+ export declare function ToolResults200ResponseFromJSON(json: any): ToolResults200Response;
36
+ export declare function ToolResults200ResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): ToolResults200Response;
37
+ export declare function ToolResults200ResponseToJSON(json: any): ToolResults200Response;
38
+ export declare function ToolResults200ResponseToJSONTyped(value?: ToolResults200Response | null, ignoreDiscriminator?: boolean): any;
@@ -0,0 +1,47 @@
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
+ * Check if a given object implements the ToolResults200Response interface.
16
+ */
17
+ export function instanceOfToolResults200Response(value) {
18
+ if (!('accepted' in value) || value['accepted'] === undefined)
19
+ return false;
20
+ if (!('duplicate' in value) || value['duplicate'] === undefined)
21
+ return false;
22
+ return true;
23
+ }
24
+ export function ToolResults200ResponseFromJSON(json) {
25
+ return ToolResults200ResponseFromJSONTyped(json, false);
26
+ }
27
+ export function ToolResults200ResponseFromJSONTyped(json, ignoreDiscriminator) {
28
+ if (json == null) {
29
+ return json;
30
+ }
31
+ return {
32
+ 'accepted': json['accepted'],
33
+ 'duplicate': json['duplicate'],
34
+ };
35
+ }
36
+ export function ToolResults200ResponseToJSON(json) {
37
+ return ToolResults200ResponseToJSONTyped(json, false);
38
+ }
39
+ export function ToolResults200ResponseToJSONTyped(value, ignoreDiscriminator = false) {
40
+ if (value == null) {
41
+ return value;
42
+ }
43
+ return {
44
+ 'accepted': value['accepted'],
45
+ 'duplicate': value['duplicate'],
46
+ };
47
+ }
@@ -0,0 +1,39 @@
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 type { FunctionResultBody } from './FunctionResultBody.js';
13
+ /**
14
+ *
15
+ * @export
16
+ * @interface ToolResultsBody
17
+ */
18
+ export interface ToolResultsBody {
19
+ /**
20
+ *
21
+ * @type {string}
22
+ * @memberof ToolResultsBody
23
+ */
24
+ requestId: string;
25
+ /**
26
+ *
27
+ * @type {Array<FunctionResultBody>}
28
+ * @memberof ToolResultsBody
29
+ */
30
+ results: Array<FunctionResultBody>;
31
+ }
32
+ /**
33
+ * Check if a given object implements the ToolResultsBody interface.
34
+ */
35
+ export declare function instanceOfToolResultsBody(value: object): value is ToolResultsBody;
36
+ export declare function ToolResultsBodyFromJSON(json: any): ToolResultsBody;
37
+ export declare function ToolResultsBodyFromJSONTyped(json: any, ignoreDiscriminator: boolean): ToolResultsBody;
38
+ export declare function ToolResultsBodyToJSON(json: any): ToolResultsBody;
39
+ export declare function ToolResultsBodyToJSONTyped(value?: ToolResultsBody | null, ignoreDiscriminator?: boolean): any;
@@ -0,0 +1,48 @@
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
+ import { FunctionResultBodyFromJSON, FunctionResultBodyToJSON, } from './FunctionResultBody.js';
15
+ /**
16
+ * Check if a given object implements the ToolResultsBody interface.
17
+ */
18
+ export function instanceOfToolResultsBody(value) {
19
+ if (!('requestId' in value) || value['requestId'] === undefined)
20
+ return false;
21
+ if (!('results' in value) || value['results'] === undefined)
22
+ return false;
23
+ return true;
24
+ }
25
+ export function ToolResultsBodyFromJSON(json) {
26
+ return ToolResultsBodyFromJSONTyped(json, false);
27
+ }
28
+ export function ToolResultsBodyFromJSONTyped(json, ignoreDiscriminator) {
29
+ if (json == null) {
30
+ return json;
31
+ }
32
+ return {
33
+ 'requestId': json['requestId'],
34
+ 'results': (json['results'].map(FunctionResultBodyFromJSON)),
35
+ };
36
+ }
37
+ export function ToolResultsBodyToJSON(json) {
38
+ return ToolResultsBodyToJSONTyped(json, false);
39
+ }
40
+ export function ToolResultsBodyToJSONTyped(value, ignoreDiscriminator = false) {
41
+ if (value == null) {
42
+ return value;
43
+ }
44
+ return {
45
+ 'requestId': value['requestId'],
46
+ 'results': (value['results'].map(FunctionResultBodyToJSON)),
47
+ };
48
+ }
@@ -99,6 +99,7 @@ export * from './FileQueuedResponse.js';
99
99
  export * from './FileRawResponse.js';
100
100
  export * from './FileRead.js';
101
101
  export * from './FileWriteBody.js';
102
+ export * from './FunctionResultBody.js';
102
103
  export * from './HTTPValidationError.js';
103
104
  export * from './HighlightRange.js';
104
105
  export * from './InlineCreateSkillBody.js';
@@ -129,6 +130,7 @@ export * from './QueueMessageInput.js';
129
130
  export * from './QueueMessageResult.js';
130
131
  export * from './QueuedTurnView.js';
131
132
  export * from './Reason.js';
133
+ export * from './RequiredAction.js';
132
134
  export * from './Requiredscope.js';
133
135
  export * from './Resourcetype.js';
134
136
  export * from './ResponseCompleteFileUpload.js';
@@ -152,6 +154,8 @@ export * from './StopResponse.js';
152
154
  export * from './TemplateConnectorTag.js';
153
155
  export * from './TemplateWorksWith.js';
154
156
  export * from './TextPart.js';
157
+ export * from './ToolResults200Response.js';
158
+ export * from './ToolResultsBody.js';
155
159
  export * from './TriggerCronBody.js';
156
160
  export * from './TriggerResponse.js';
157
161
  export * from './UIMessage.js';
@@ -101,6 +101,7 @@ export * from './FileQueuedResponse.js';
101
101
  export * from './FileRawResponse.js';
102
102
  export * from './FileRead.js';
103
103
  export * from './FileWriteBody.js';
104
+ export * from './FunctionResultBody.js';
104
105
  export * from './HTTPValidationError.js';
105
106
  export * from './HighlightRange.js';
106
107
  export * from './InlineCreateSkillBody.js';
@@ -131,6 +132,7 @@ export * from './QueueMessageInput.js';
131
132
  export * from './QueueMessageResult.js';
132
133
  export * from './QueuedTurnView.js';
133
134
  export * from './Reason.js';
135
+ export * from './RequiredAction.js';
134
136
  export * from './Requiredscope.js';
135
137
  export * from './Resourcetype.js';
136
138
  export * from './ResponseCompleteFileUpload.js';
@@ -154,6 +156,8 @@ export * from './StopResponse.js';
154
156
  export * from './TemplateConnectorTag.js';
155
157
  export * from './TemplateWorksWith.js';
156
158
  export * from './TextPart.js';
159
+ export * from './ToolResults200Response.js';
160
+ export * from './ToolResultsBody.js';
157
161
  export * from './TriggerCronBody.js';
158
162
  export * from './TriggerResponse.js';
159
163
  export * from './UIMessage.js';
@@ -14,10 +14,10 @@
14
14
  * const again = await reconnect(config, conversationId, stream.responseId!, stream.lastEventId);
15
15
  *
16
16
  * Each item is the event's JSON payload (`type` is `start`, `text-delta`, `data-file-shared`,
17
- * `data-clarify-request`, `data-stopped`, `error`, `finish`, ...). The stream keeps `lastEventId` and `responseId`
17
+ * `data-clarify-request`, `data-function-call-request`, `data-stopped`, `error`, `finish`, ...). The stream keeps `lastEventId` and `responseId`
18
18
  * up to date, the two values `reconnect` needs.
19
19
  */
20
- import type { ClarifyBody, ResponseInput } from "./models/index.js";
20
+ import type { ClarifyBody, ResponseInput, ToolResultsBody } from "./models/index.js";
21
21
  import type { Configuration } from "./runtime.js";
22
22
  /** One event's JSON payload. */
23
23
  export interface StreamEvent {
@@ -40,6 +40,9 @@ export declare function iterSse(chunks: AsyncIterable<Uint8Array>): AsyncGenerat
40
40
  export declare class ResponseStream implements AsyncIterable<StreamEvent> {
41
41
  responseId: string | null;
42
42
  lastEventId: string | null;
43
+ /** `postToolResults` only: the server already had these results (a repeat with the same idempotency key), so
44
+ * this stream is empty; follow the turn with `reconnect`. */
45
+ duplicate: boolean;
43
46
  private readonly body;
44
47
  private readonly controller;
45
48
  private readonly idleTimeoutMs;
@@ -66,3 +69,12 @@ export declare function reconnect(config: Configuration, conversationId: string,
66
69
  * `body.requestId` comes from that event; put your answers in `body.answers`.
67
70
  */
68
71
  export declare function answerClarify(config: Configuration, conversationId: string, body: ClarifyBody, options?: StreamOptions): Promise<ResponseStream>;
72
+ /**
73
+ * Answer the agent's function calls (a `data-function-call-request` event) and stream the rest of the reply.
74
+ * `body.requestId` comes from that event, with one result per call. Send the same `idempotencyKey` when you retry a
75
+ * post: a repeat the server already has resolves to an empty stream with `duplicate` set, and the turn can be followed
76
+ * with `reconnect`.
77
+ */
78
+ export declare function postToolResults(config: Configuration, conversationId: string, body: ToolResultsBody, options?: StreamOptions & {
79
+ idempotencyKey?: string;
80
+ }): Promise<ResponseStream>;
@@ -14,10 +14,11 @@
14
14
  * const again = await reconnect(config, conversationId, stream.responseId!, stream.lastEventId);
15
15
  *
16
16
  * Each item is the event's JSON payload (`type` is `start`, `text-delta`, `data-file-shared`,
17
- * `data-clarify-request`, `data-stopped`, `error`, `finish`, ...). The stream keeps `lastEventId` and `responseId`
17
+ * `data-clarify-request`, `data-function-call-request`, `data-stopped`, `error`, `finish`, ...). The stream keeps `lastEventId` and `responseId`
18
18
  * up to date, the two values `reconnect` needs.
19
19
  */
20
20
  import { ClarifyApi } from "./apis/ClarifyApi.js";
21
+ import { FunctionToolsApi } from "./apis/FunctionToolsApi.js";
21
22
  import { ResponsesApi } from "./apis/ResponsesApi.js";
22
23
  export const DEFAULT_IDLE_TIMEOUT_MS = 60000;
23
24
  /** Parse a server-sent-events body into [last event id, payload] pairs. */
@@ -77,6 +78,9 @@ export async function* iterSse(chunks) {
77
78
  /** Async iterator over a reply's events. Call `close()` if you stop early. */
78
79
  export class ResponseStream {
79
80
  constructor(body, controller, idleTimeoutMs, responseId = null, lastEventId = null) {
81
+ /** `postToolResults` only: the server already had these results (a repeat with the same idempotency key), so
82
+ * this stream is empty; follow the turn with `reconnect`. */
83
+ this.duplicate = false;
80
84
  this.body = body;
81
85
  this.controller = controller;
82
86
  this.idleTimeoutMs = idleTimeoutMs;
@@ -138,15 +142,24 @@ export class ResponseStream {
138
142
  this.controller.abort();
139
143
  }
140
144
  }
141
- async function open(call, options, responseId = null, lastEventId = null) {
142
- var _a, _b;
145
+ async function open(call, options, responseId = null, lastEventId = null, jsonIsDuplicate = false) {
146
+ var _a, _b, _c, _d, _e;
143
147
  const controller = new AbortController();
144
148
  (_a = options.signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", () => controller.abort(options.signal.reason), { once: true });
145
149
  // Non-2xx responses throw ResponseError here, like every other generated method.
146
150
  const response = await call({ signal: controller.signal });
151
+ const contentType = ((_b = response.raw.headers.get("content-type")) !== null && _b !== void 0 ? _b : "").split(";")[0].trim().toLowerCase();
152
+ if (jsonIsDuplicate && contentType === "application/json") {
153
+ await ((_c = response.raw.body) === null || _c === void 0 ? void 0 : _c.cancel().catch(() => undefined));
154
+ const empty = new ReadableStream({ start: (c) => c.close() });
155
+ const stream = new ResponseStream(empty, controller, (_d = options.idleTimeoutMs) !== null && _d !== void 0 ? _d : DEFAULT_IDLE_TIMEOUT_MS);
156
+ stream.duplicate = true;
157
+ stream.close();
158
+ return stream;
159
+ }
147
160
  if (!response.raw.body)
148
161
  throw new Error("response has no body to stream");
149
- return new ResponseStream(response.raw.body, controller, (_b = options.idleTimeoutMs) !== null && _b !== void 0 ? _b : DEFAULT_IDLE_TIMEOUT_MS, responseId, lastEventId);
162
+ return new ResponseStream(response.raw.body, controller, (_e = options.idleTimeoutMs) !== null && _e !== void 0 ? _e : DEFAULT_IDLE_TIMEOUT_MS, responseId, lastEventId);
150
163
  }
151
164
  /** Send a message (POST /v1/responses) and stream the reply. Same body as `ResponsesApi.createResponse`. */
152
165
  export function streamResponse(config, body, options = {}) {
@@ -169,3 +182,12 @@ export function reconnect(config, conversationId, responseId, lastEventId = null
169
182
  export function answerClarify(config, conversationId, body, options = {}) {
170
183
  return open((init) => new ClarifyApi(config).clarifyRaw({ conversationId, clarifyBody: body }, init), options);
171
184
  }
185
+ /**
186
+ * Answer the agent's function calls (a `data-function-call-request` event) and stream the rest of the reply.
187
+ * `body.requestId` comes from that event, with one result per call. Send the same `idempotencyKey` when you retry a
188
+ * post: a repeat the server already has resolves to an empty stream with `duplicate` set, and the turn can be followed
189
+ * with `reconnect`.
190
+ */
191
+ export function postToolResults(config, conversationId, body, options = {}) {
192
+ return open((init) => new FunctionToolsApi(config).toolResultsRaw({ conversationId, toolResultsBody: body, idempotencyKey: options.idempotencyKey }, init), options, null, null, true);
193
+ }
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Every event an `agent.json` webhook may subscribe to. `approval.requested` is reserved: the server accepts it
3
+ * (with the save warning `event_reserved`) but never sends it yet.
4
+ */
5
+ export declare const WEBHOOK_EVENTS: readonly ["turn.completed", "turn.failed", "turn.requires_action", "approval.requested"];
6
+ export type WebhookEventType = (typeof WEBHOOK_EVENTS)[number];
7
+ export declare const DEFAULT_TOLERANCE_S = 300;
8
+ /** `verify` examines at most this many space-separated signature entries; the rest are ignored. */
9
+ export declare const MAX_SIGNATURES_EXAMINED = 10;
10
+ /**
11
+ * A longer `webhook-timestamp` is refused as `bad_timestamp`, as on the server (where `int()` caps out at 4300
12
+ * digits); no real time needs more than 20.
13
+ */
14
+ export declare const MAX_TIMESTAMP_DIGITS = 20;
15
+ export type SecretFormatReason = "prefix" | "base64" | "length";
16
+ export type VerificationReason = "missing_header" | "bad_timestamp" | "timestamp_too_old" | "timestamp_too_new" | "no_matching_signature";
17
+ /** A secret is not `whsec_` + base64 of 24 to 64 bytes. The message is the reason alone, never the secret. */
18
+ export declare class SecretFormatError extends Error {
19
+ readonly reason: SecretFormatReason;
20
+ constructor(reason: SecretFormatReason);
21
+ }
22
+ /** A delivery failed verification. The message is the reason alone. */
23
+ export declare class WebhookVerificationError extends Error {
24
+ readonly reason: VerificationReason;
25
+ constructor(reason: VerificationReason);
26
+ }
27
+ /** What `verify` vouched for: the `webhook-id` (dedupe on it) and the `webhook-timestamp` in unix seconds. */
28
+ export interface VerifiedMessage {
29
+ msgId: string;
30
+ timestamp: number;
31
+ }
32
+ /** A fetch `Headers`, or a plain object such as Node's `req.headers`. Names are matched case-insensitively. */
33
+ export type HeadersLike = {
34
+ forEach(callback: (value: string, key: string) => void): void;
35
+ get(name: string): string | null;
36
+ } | Record<string, string | string[] | undefined>;
37
+ export type Payload = string | Uint8Array;
38
+ export interface VerifyOptions {
39
+ /** Seconds the timestamp may differ from `now`; default 300. Must be finite and not negative. */
40
+ tolerance?: number;
41
+ /** The current time in unix seconds; default the clock. Must be finite. */
42
+ now?: number;
43
+ }
44
+ /** A fresh `whsec_` secret of `nbytes` (24 to 64) random bytes, to store as the webhook's vault credential. */
45
+ export declare function generateSecret(nbytes?: number): string;
46
+ /** `"v1,<base64 HMAC-SHA256>"` over `{msgId}.{timestamp}.{body}`, as the server signs (for tests). */
47
+ export declare function sign(secret: string, msg: {
48
+ msgId: string;
49
+ timestamp: number;
50
+ body: Payload;
51
+ }): string;
52
+ /**
53
+ * Verify a delivery; throws `WebhookVerificationError` (or `SecretFormatError`) if it fails.
54
+ *
55
+ * `payload` is the raw request body (a `Buffer` from `express.raw()`, or the exact text), before any JSON parsing.
56
+ * `secret` is one `whsec_` secret, or several while you rotate. The `webhook-timestamp` must be 1 to 20 ASCII digits
57
+ * within `tolerance` seconds of `now`; it is checked before any HMAC work. Only the first 10 `webhook-signature`
58
+ * entries are examined and entries not starting `v1,` are skipped. Comparisons are constant time. A header given as
59
+ * an array counts as missing. Throws `TypeError` when `now` or `tolerance` is not a finite number, or `tolerance` is
60
+ * negative: `Number(process.env.UNSET)` is NaN, which would quietly turn off the timestamp check. An empty list of
61
+ * secrets throws `TypeError` too: a receiver missing its secret would otherwise refuse every delivery as forged.
62
+ */
63
+ export declare function verify(payload: Payload, headers: HeadersLike, secret: string | readonly string[], opts?: VerifyOptions): VerifiedMessage;
64
+ export interface TurnSource {
65
+ /** `message`, `cron` or `subagent_result`. */
66
+ kind: string;
67
+ /** `web`, `cli`, `slack`, `teams`, ... */
68
+ platform: string;
69
+ cronId: string | null;
70
+ scheduleRunId: string | null;
71
+ delegationIds: string[];
72
+ }
73
+ export interface TurnUsage {
74
+ inputTokens: number | null;
75
+ outputTokens: number | null;
76
+ reasoningTokens: number | null;
77
+ cacheReadTokens: number | null;
78
+ }
79
+ /** The `agent.json` limit that ended the turn. */
80
+ export interface TurnCap {
81
+ kind: string;
82
+ limit: string;
83
+ value: number | null;
84
+ }
85
+ export interface TurnData {
86
+ agent: {
87
+ id: string;
88
+ };
89
+ /** `id` is the platform's conversation key; on web and API sessions, the id `GET /v1/conversations/{id}` takes. */
90
+ conversation: {
91
+ id: string;
92
+ sessionId: string;
93
+ };
94
+ /** `id` is the same on every event of a turn; `responseId` is currently always null. */
95
+ turn: {
96
+ id: string;
97
+ responseId: string | null;
98
+ };
99
+ source: TurnSource;
100
+ tenantId: string;
101
+ workspaceId: string;
102
+ userId: string;
103
+ /** Fields cut to fit the 64 KiB body cap (`text`, `rawText`, `output`, `actions.<i>.arguments`). */
104
+ truncated: string[];
105
+ }
106
+ export interface TurnCompletedData extends TurnData {
107
+ status: "completed";
108
+ text: string;
109
+ /** The validated structured output, or null. */
110
+ output: unknown;
111
+ /** `tool_in_loop`, `tool_oversize`, `forced_tool`, `native` or `prompted`; passed through as sent. */
112
+ outputMode: string | null;
113
+ /** `limit`, `budget`, `paused` or `suppressed`; passed through as sent. */
114
+ outputSkipped: string | null;
115
+ cap: TurnCap | null;
116
+ usage: TurnUsage;
117
+ }
118
+ export interface TurnFailedData extends TurnData {
119
+ status: "failed";
120
+ /** `code`: `user_stop`, `context_overflow`, `persist_failed`, `seat_budget_exhausted_error`, `schema_mismatch`,
121
+ * or `turn_failed`. */
122
+ error: {
123
+ code: string;
124
+ message: string;
125
+ };
126
+ /** Schema mismatch only: up to three `path: message` strings. */
127
+ errors: string[] | null;
128
+ /** Schema mismatch only: the model's raw text. */
129
+ rawText: string | null;
130
+ cap: TurnCap | null;
131
+ usage: TurnUsage;
132
+ }
133
+ export interface ClarifyQuestion {
134
+ id: string;
135
+ prompt: string;
136
+ inputType?: string;
137
+ choices?: string[] | null;
138
+ [key: string]: unknown;
139
+ }
140
+ export interface ClarifyAction {
141
+ type: "clarify";
142
+ requestId: string;
143
+ questions: ClarifyQuestion[];
144
+ createdAt: string | null;
145
+ expiresAt: string | null;
146
+ }
147
+ /**
148
+ * A function tool call waiting for its result: answer it with `postToolResults`
149
+ * (`POST /v1/conversations/{id}/tool-results` with `requestId` and this `toolCallId`), or continue the run with
150
+ * `run(agent, RunState.fromSession(...))`. A turn the SDK runner is driving answers its own function calls: don't
151
+ * answer those here too (the second answer gets 409 `already_answered`).
152
+ */
153
+ export interface FunctionCallAction {
154
+ type: "function_call";
155
+ requestId: string;
156
+ toolCallId: string;
157
+ name: string;
158
+ /** null when it was cut to fit the body cap (`truncated` lists `actions.<i>.arguments`). */
159
+ arguments: Record<string, unknown> | null;
160
+ createdAt: string | null;
161
+ expiresAt: string | null;
162
+ }
163
+ /**
164
+ * An action of a type this SDK release does not know, as sent. It is not part of `RequiredAction`, so narrowing on
165
+ * `type` keeps working; a newer server may still send one, so keep a default branch when you switch on `type`.
166
+ */
167
+ export interface UnknownAction {
168
+ type: string;
169
+ [key: string]: unknown;
170
+ }
171
+ /**
172
+ * Same shape as `requiredActions` on `GET /v1/conversations/{id}`. A newer server may send other action types
173
+ * (`UnknownAction`): `parseEvent` passes them through, so handle a `type` you don't know in a default branch.
174
+ */
175
+ export type RequiredAction = ClarifyAction | FunctionCallAction;
176
+ export interface TurnRequiresActionData extends TurnData {
177
+ status: "requires_action";
178
+ requestId: string;
179
+ /** `clarify` or `function_call`. */
180
+ kind: string;
181
+ expiresAt: string | null;
182
+ actions: RequiredAction[];
183
+ }
184
+ interface Envelope<T extends string, D> {
185
+ type: T;
186
+ id: string;
187
+ /** When the event was built: ISO 8601, UTC, milliseconds (`2026-11-11T10:15:42.123Z`). */
188
+ timestamp: string;
189
+ data: D;
190
+ }
191
+ export type TurnCompletedEvent = Envelope<"turn.completed", TurnCompletedData>;
192
+ export type TurnFailedEvent = Envelope<"turn.failed", TurnFailedData>;
193
+ export type TurnRequiresActionEvent = Envelope<"turn.requires_action", TurnRequiresActionData>;
194
+ export type WebhookEvent = TurnCompletedEvent | TurnFailedEvent | TurnRequiresActionEvent;
195
+ /**
196
+ * The typed event of a verified body (raw bytes, text or an already-parsed object).
197
+ *
198
+ * Returns `undefined` for an event type this SDK release doesn't know (reply 2xx and skip it). Throws `TypeError`
199
+ * when the body is not a webhook event or its `data.status` doesn't match its type. Only the envelope is checked;
200
+ * the fields are typed as the server documents them.
201
+ */
202
+ export declare function parseEvent(payload: Payload | Record<string, unknown>): WebhookEvent | undefined;
203
+ export {};