sarvam-agents-client 0.2.1 → 0.2.3
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.
- package/dist/apis/AgentConversationsApi.d.ts +31 -5
- package/dist/apis/AgentConversationsApi.js +33 -5
- package/dist/compose/events.d.ts +10 -0
- package/dist/compose/events.js +7 -0
- package/dist/compose/index.d.ts +1 -1
- package/dist/compose/run.d.ts +7 -0
- package/dist/compose/run.js +15 -0
- package/dist/esm/apis/AgentConversationsApi.d.ts +31 -5
- package/dist/esm/apis/AgentConversationsApi.js +32 -4
- package/dist/esm/compose/events.d.ts +10 -0
- package/dist/esm/compose/events.js +7 -0
- package/dist/esm/compose/index.d.ts +1 -1
- package/dist/esm/compose/run.d.ts +7 -0
- package/dist/esm/compose/run.js +15 -0
- package/package.json +1 -1
- package/src/apis/AgentConversationsApi.ts +39 -5
- package/src/compose/events.ts +12 -0
- package/src/compose/index.ts +1 -1
- package/src/compose/run.ts +22 -0
|
@@ -21,18 +21,20 @@ export interface AgentConversationArtifactDownloadUrlRequest {
|
|
|
21
21
|
export interface GetAgentConversationRequest {
|
|
22
22
|
agentId: string;
|
|
23
23
|
conversationId: string;
|
|
24
|
+
sessionType?: Array<GetAgentConversationSessionTypeEnum>;
|
|
24
25
|
}
|
|
25
26
|
export interface ListAgentConversationMessagesRequest {
|
|
26
27
|
agentId: string;
|
|
27
28
|
conversationId: string;
|
|
28
29
|
before: string;
|
|
30
|
+
sessionType?: Array<ListAgentConversationMessagesSessionTypeEnum>;
|
|
29
31
|
turnLimit?: number | null;
|
|
30
32
|
}
|
|
31
33
|
export interface ListAgentConversationsRequest {
|
|
32
34
|
agentId: string;
|
|
33
35
|
limit?: number;
|
|
34
36
|
cursor?: string | null;
|
|
35
|
-
sessionType?: ListAgentConversationsSessionTypeEnum
|
|
37
|
+
sessionType?: Array<ListAgentConversationsSessionTypeEnum>;
|
|
36
38
|
workspaceId?: Array<string>;
|
|
37
39
|
mine?: boolean | null;
|
|
38
40
|
}
|
|
@@ -51,12 +53,12 @@ export declare class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
51
53
|
*/
|
|
52
54
|
agentConversationArtifactDownloadUrl(requestParameters: AgentConversationArtifactDownloadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DownloadUrlResponse>;
|
|
53
55
|
/**
|
|
54
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
56
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
55
57
|
* Get Agent Conversation Route
|
|
56
58
|
*/
|
|
57
59
|
getAgentConversationRaw(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AgentConversationDetail>>;
|
|
58
60
|
/**
|
|
59
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
61
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
60
62
|
* Get Agent Conversation Route
|
|
61
63
|
*/
|
|
62
64
|
getAgentConversation(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AgentConversationDetail>;
|
|
@@ -71,12 +73,12 @@ export declare class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
71
73
|
*/
|
|
72
74
|
listAgentConversationMessages(requestParameters: ListAgentConversationMessagesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MessagesResponse>;
|
|
73
75
|
/**
|
|
74
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
76
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
75
77
|
* List Agent Conversations Route
|
|
76
78
|
*/
|
|
77
79
|
listAgentConversationsRaw(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PageAgentConversationView>>;
|
|
78
80
|
/**
|
|
79
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
81
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
80
82
|
* List Agent Conversations Route
|
|
81
83
|
*/
|
|
82
84
|
listAgentConversations(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PageAgentConversationView>;
|
|
@@ -89,12 +91,36 @@ export declare const AgentConversationArtifactDownloadUrlDispositionEnum: {
|
|
|
89
91
|
readonly Attachment: "attachment";
|
|
90
92
|
};
|
|
91
93
|
export type AgentConversationArtifactDownloadUrlDispositionEnum = typeof AgentConversationArtifactDownloadUrlDispositionEnum[keyof typeof AgentConversationArtifactDownloadUrlDispositionEnum];
|
|
94
|
+
/**
|
|
95
|
+
* @export
|
|
96
|
+
*/
|
|
97
|
+
export declare const GetAgentConversationSessionTypeEnum: {
|
|
98
|
+
readonly Api: "api";
|
|
99
|
+
readonly Chat: "chat";
|
|
100
|
+
readonly Slack: "slack";
|
|
101
|
+
readonly Teams: "teams";
|
|
102
|
+
readonly All: "all";
|
|
103
|
+
};
|
|
104
|
+
export type GetAgentConversationSessionTypeEnum = typeof GetAgentConversationSessionTypeEnum[keyof typeof GetAgentConversationSessionTypeEnum];
|
|
105
|
+
/**
|
|
106
|
+
* @export
|
|
107
|
+
*/
|
|
108
|
+
export declare const ListAgentConversationMessagesSessionTypeEnum: {
|
|
109
|
+
readonly Api: "api";
|
|
110
|
+
readonly Chat: "chat";
|
|
111
|
+
readonly Slack: "slack";
|
|
112
|
+
readonly Teams: "teams";
|
|
113
|
+
readonly All: "all";
|
|
114
|
+
};
|
|
115
|
+
export type ListAgentConversationMessagesSessionTypeEnum = typeof ListAgentConversationMessagesSessionTypeEnum[keyof typeof ListAgentConversationMessagesSessionTypeEnum];
|
|
92
116
|
/**
|
|
93
117
|
* @export
|
|
94
118
|
*/
|
|
95
119
|
export declare const ListAgentConversationsSessionTypeEnum: {
|
|
96
120
|
readonly Api: "api";
|
|
97
121
|
readonly Chat: "chat";
|
|
122
|
+
readonly Slack: "slack";
|
|
123
|
+
readonly Teams: "teams";
|
|
98
124
|
readonly All: "all";
|
|
99
125
|
};
|
|
100
126
|
export type ListAgentConversationsSessionTypeEnum = typeof ListAgentConversationsSessionTypeEnum[keyof typeof ListAgentConversationsSessionTypeEnum];
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ListAgentConversationsSessionTypeEnum = exports.AgentConversationArtifactDownloadUrlDispositionEnum = exports.AgentConversationsApi = void 0;
|
|
16
|
+
exports.ListAgentConversationsSessionTypeEnum = exports.ListAgentConversationMessagesSessionTypeEnum = exports.GetAgentConversationSessionTypeEnum = exports.AgentConversationArtifactDownloadUrlDispositionEnum = exports.AgentConversationsApi = void 0;
|
|
17
17
|
const runtime = require("../runtime.js");
|
|
18
18
|
const index_js_1 = require("../models/index.js");
|
|
19
19
|
/**
|
|
@@ -66,7 +66,7 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
66
66
|
return await response.value();
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
69
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
70
70
|
* Get Agent Conversation Route
|
|
71
71
|
*/
|
|
72
72
|
async getAgentConversationRaw(requestParameters, initOverrides) {
|
|
@@ -77,6 +77,9 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
77
77
|
throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling getAgentConversation().');
|
|
78
78
|
}
|
|
79
79
|
const queryParameters = {};
|
|
80
|
+
if (requestParameters['sessionType'] != null) {
|
|
81
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
82
|
+
}
|
|
80
83
|
const headerParameters = {};
|
|
81
84
|
if (this.configuration && this.configuration.accessToken) {
|
|
82
85
|
const token = this.configuration.accessToken;
|
|
@@ -94,7 +97,7 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
94
97
|
return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.AgentConversationDetailFromJSON)(jsonValue));
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
100
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
98
101
|
* Get Agent Conversation Route
|
|
99
102
|
*/
|
|
100
103
|
async getAgentConversation(requestParameters, initOverrides) {
|
|
@@ -116,6 +119,9 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
116
119
|
throw new runtime.RequiredError('before', 'Required parameter "before" was null or undefined when calling listAgentConversationMessages().');
|
|
117
120
|
}
|
|
118
121
|
const queryParameters = {};
|
|
122
|
+
if (requestParameters['sessionType'] != null) {
|
|
123
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
124
|
+
}
|
|
119
125
|
if (requestParameters['before'] != null) {
|
|
120
126
|
queryParameters['before'] = requestParameters['before'];
|
|
121
127
|
}
|
|
@@ -147,7 +153,7 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
147
153
|
return await response.value();
|
|
148
154
|
}
|
|
149
155
|
/**
|
|
150
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
156
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
151
157
|
* List Agent Conversations Route
|
|
152
158
|
*/
|
|
153
159
|
async listAgentConversationsRaw(requestParameters, initOverrides) {
|
|
@@ -187,7 +193,7 @@ class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
187
193
|
return new runtime.JSONApiResponse(response, (jsonValue) => (0, index_js_1.PageAgentConversationViewFromJSON)(jsonValue));
|
|
188
194
|
}
|
|
189
195
|
/**
|
|
190
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
196
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
191
197
|
* List Agent Conversations Route
|
|
192
198
|
*/
|
|
193
199
|
async listAgentConversations(requestParameters, initOverrides) {
|
|
@@ -203,11 +209,33 @@ exports.AgentConversationArtifactDownloadUrlDispositionEnum = {
|
|
|
203
209
|
Inline: 'inline',
|
|
204
210
|
Attachment: 'attachment'
|
|
205
211
|
};
|
|
212
|
+
/**
|
|
213
|
+
* @export
|
|
214
|
+
*/
|
|
215
|
+
exports.GetAgentConversationSessionTypeEnum = {
|
|
216
|
+
Api: 'api',
|
|
217
|
+
Chat: 'chat',
|
|
218
|
+
Slack: 'slack',
|
|
219
|
+
Teams: 'teams',
|
|
220
|
+
All: 'all'
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* @export
|
|
224
|
+
*/
|
|
225
|
+
exports.ListAgentConversationMessagesSessionTypeEnum = {
|
|
226
|
+
Api: 'api',
|
|
227
|
+
Chat: 'chat',
|
|
228
|
+
Slack: 'slack',
|
|
229
|
+
Teams: 'teams',
|
|
230
|
+
All: 'all'
|
|
231
|
+
};
|
|
206
232
|
/**
|
|
207
233
|
* @export
|
|
208
234
|
*/
|
|
209
235
|
exports.ListAgentConversationsSessionTypeEnum = {
|
|
210
236
|
Api: 'api',
|
|
211
237
|
Chat: 'chat',
|
|
238
|
+
Slack: 'slack',
|
|
239
|
+
Teams: 'teams',
|
|
212
240
|
All: 'all'
|
|
213
241
|
};
|
package/dist/compose/events.d.ts
CHANGED
|
@@ -45,6 +45,16 @@ export type Event = {
|
|
|
45
45
|
} | {
|
|
46
46
|
kind: "stopped";
|
|
47
47
|
reason: string;
|
|
48
|
+
}
|
|
49
|
+
/** An agent.json limit ended the turn (`data-turn-limit`); the wrap-up answer still follows. `capKind` is the
|
|
50
|
+
* server's cap name: `max_turns`, `tool_calls` or `tokens`. `limit` is the agent.json `limits` key that set it
|
|
51
|
+
* (`max_turns`, `max_tool_calls_per_turn` or `max_tokens_per_turn`) and `value` the configured number; both are
|
|
52
|
+
* absent from a server that predates them. */
|
|
53
|
+
| {
|
|
54
|
+
kind: "turn_limit";
|
|
55
|
+
capKind: string;
|
|
56
|
+
limit?: string;
|
|
57
|
+
value?: number;
|
|
48
58
|
} | {
|
|
49
59
|
kind: "turn_finished";
|
|
50
60
|
reason: string;
|
package/dist/compose/events.js
CHANGED
|
@@ -87,6 +87,13 @@ function map(chunk) {
|
|
|
87
87
|
ev.expiresAt = data["expiresAt"];
|
|
88
88
|
return ev;
|
|
89
89
|
}
|
|
90
|
+
case "data-turn-limit":
|
|
91
|
+
return {
|
|
92
|
+
kind: "turn_limit",
|
|
93
|
+
capKind: str(data["kind"], ""),
|
|
94
|
+
...(typeof data["limit"] === "string" && data["limit"] ? { limit: data["limit"] } : {}),
|
|
95
|
+
...(Number.isInteger(data["value"]) ? { value: data["value"] } : {}),
|
|
96
|
+
};
|
|
90
97
|
case "data-stopped":
|
|
91
98
|
return { kind: "stopped", reason: str(data["reason"], "stopped") };
|
|
92
99
|
case "error":
|
package/dist/compose/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export type { RemoteAgent, SettingsWarning, TurnStream, Transport } from "./tran
|
|
|
8
8
|
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
9
9
|
export type { Deployment } from "./deploy.js";
|
|
10
10
|
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
11
|
-
export type { RunOptions, RunStreamEvent, ClarifyHandler } from "./run.js";
|
|
11
|
+
export type { RunOptions, RunStreamEvent, ClarifyHandler, StopReason } from "./run.js";
|
|
12
12
|
export { RunState } from "./runState.js";
|
|
13
13
|
export type { Interruption } from "./runState.js";
|
package/dist/compose/run.d.ts
CHANGED
|
@@ -29,11 +29,14 @@ export type RunStreamEvent = {
|
|
|
29
29
|
name: "tool_called" | "tool_output" | "message_output_created";
|
|
30
30
|
item: unknown;
|
|
31
31
|
};
|
|
32
|
+
/** Why the run ended early: the `limits` field whose cap the server hit. */
|
|
33
|
+
export type StopReason = "max_turns" | "max_tool_calls" | "max_tokens";
|
|
32
34
|
interface Outcome {
|
|
33
35
|
finalOutput: string | undefined;
|
|
34
36
|
outputText: string;
|
|
35
37
|
newItems: Event[];
|
|
36
38
|
interruptions: Interruption[];
|
|
39
|
+
stopReason: StopReason | undefined;
|
|
37
40
|
conversationId: string | undefined;
|
|
38
41
|
cancelled: boolean;
|
|
39
42
|
}
|
|
@@ -42,6 +45,8 @@ export declare class RunResult {
|
|
|
42
45
|
readonly outputText: string;
|
|
43
46
|
readonly newItems: Event[];
|
|
44
47
|
readonly interruptions: Interruption[];
|
|
48
|
+
/** Set when an agent.json limit ended the turn; `finalOutput` still holds the wrap-up answer. */
|
|
49
|
+
readonly stopReason: StopReason | undefined;
|
|
45
50
|
readonly conversationId: string | undefined;
|
|
46
51
|
/** @internal */
|
|
47
52
|
constructor(outcome: Outcome);
|
|
@@ -63,6 +68,8 @@ export declare class StreamedRunResult implements AsyncIterable<RunStreamEvent>
|
|
|
63
68
|
outputText: string;
|
|
64
69
|
newItems: Event[];
|
|
65
70
|
interruptions: Interruption[];
|
|
71
|
+
/** Set when an agent.json limit ended the turn; read after `completed` settles. */
|
|
72
|
+
stopReason: StopReason | undefined;
|
|
66
73
|
conversationId: string | undefined;
|
|
67
74
|
cancelled: boolean;
|
|
68
75
|
private readonly queue;
|
package/dist/compose/run.js
CHANGED
|
@@ -9,6 +9,12 @@ const runState_js_1 = require("./runState.js");
|
|
|
9
9
|
const MAX_RECONNECTS = 3;
|
|
10
10
|
/** The abort reason ResponseStream (src/streaming.ts) uses when a stream goes quiet. */
|
|
11
11
|
const IDLE_TIMEOUT_MESSAGE = "stream idle timeout";
|
|
12
|
+
/** Server cap kind (`data-turn-limit`) -> stop reason, named like the `limits` field that set it. */
|
|
13
|
+
const STOP_REASONS = {
|
|
14
|
+
max_turns: "max_turns",
|
|
15
|
+
tool_calls: "max_tool_calls",
|
|
16
|
+
tokens: "max_tokens",
|
|
17
|
+
};
|
|
12
18
|
function stateOf(conversationId, interruptions) {
|
|
13
19
|
if (conversationId === undefined)
|
|
14
20
|
throw new errors_js_1.UserError("this run has no conversation to resume");
|
|
@@ -21,6 +27,7 @@ class RunResult {
|
|
|
21
27
|
this.outputText = outcome.outputText;
|
|
22
28
|
this.newItems = outcome.newItems;
|
|
23
29
|
this.interruptions = outcome.interruptions;
|
|
30
|
+
this.stopReason = outcome.stopReason;
|
|
24
31
|
this.conversationId = outcome.conversationId;
|
|
25
32
|
}
|
|
26
33
|
/** A RunState to answer the interruptions and continue; throws UserError when the run has no conversation. */
|
|
@@ -102,6 +109,7 @@ class Loop {
|
|
|
102
109
|
this.onConversation = onConversation;
|
|
103
110
|
this.conversationId = null;
|
|
104
111
|
this.items = [];
|
|
112
|
+
this.stopReason = undefined;
|
|
105
113
|
// Text of the current segment, per text block. Kept per block so a resumed stream, which replays from the start
|
|
106
114
|
// of the block it dropped in, doesn't repeat text.
|
|
107
115
|
this.blocks = [];
|
|
@@ -246,6 +254,9 @@ class Loop {
|
|
|
246
254
|
if (this.signal.aborted)
|
|
247
255
|
throw new Cancelled();
|
|
248
256
|
throw new errors_js_1.RunError("stopped", `the turn was stopped on the server (${event.reason})`);
|
|
257
|
+
case "turn_limit":
|
|
258
|
+
this.stopReason = STOP_REASONS[event.capKind];
|
|
259
|
+
return false;
|
|
249
260
|
case "text_start":
|
|
250
261
|
case "text_end":
|
|
251
262
|
this.onText(event);
|
|
@@ -402,6 +413,7 @@ async function execute(p, controller, emit) {
|
|
|
402
413
|
outputText: text,
|
|
403
414
|
newItems: loop.items,
|
|
404
415
|
interruptions,
|
|
416
|
+
stopReason: loop.stopReason,
|
|
405
417
|
conversationId: (_b = loop.conversationId) !== null && _b !== void 0 ? _b : fallbackConversation,
|
|
406
418
|
cancelled,
|
|
407
419
|
};
|
|
@@ -415,6 +427,8 @@ class StreamedRunResult {
|
|
|
415
427
|
this.outputText = "";
|
|
416
428
|
this.newItems = [];
|
|
417
429
|
this.interruptions = [];
|
|
430
|
+
/** Set when an agent.json limit ended the turn; read after `completed` settles. */
|
|
431
|
+
this.stopReason = undefined;
|
|
418
432
|
this.conversationId = undefined;
|
|
419
433
|
this.cancelled = false;
|
|
420
434
|
this.queue = [];
|
|
@@ -429,6 +443,7 @@ class StreamedRunResult {
|
|
|
429
443
|
this.outputText = outcome.outputText;
|
|
430
444
|
this.newItems = outcome.newItems;
|
|
431
445
|
this.interruptions = outcome.interruptions;
|
|
446
|
+
this.stopReason = outcome.stopReason;
|
|
432
447
|
this.conversationId = outcome.conversationId;
|
|
433
448
|
this.cancelled = outcome.cancelled;
|
|
434
449
|
this.end();
|
|
@@ -21,18 +21,20 @@ export interface AgentConversationArtifactDownloadUrlRequest {
|
|
|
21
21
|
export interface GetAgentConversationRequest {
|
|
22
22
|
agentId: string;
|
|
23
23
|
conversationId: string;
|
|
24
|
+
sessionType?: Array<GetAgentConversationSessionTypeEnum>;
|
|
24
25
|
}
|
|
25
26
|
export interface ListAgentConversationMessagesRequest {
|
|
26
27
|
agentId: string;
|
|
27
28
|
conversationId: string;
|
|
28
29
|
before: string;
|
|
30
|
+
sessionType?: Array<ListAgentConversationMessagesSessionTypeEnum>;
|
|
29
31
|
turnLimit?: number | null;
|
|
30
32
|
}
|
|
31
33
|
export interface ListAgentConversationsRequest {
|
|
32
34
|
agentId: string;
|
|
33
35
|
limit?: number;
|
|
34
36
|
cursor?: string | null;
|
|
35
|
-
sessionType?: ListAgentConversationsSessionTypeEnum
|
|
37
|
+
sessionType?: Array<ListAgentConversationsSessionTypeEnum>;
|
|
36
38
|
workspaceId?: Array<string>;
|
|
37
39
|
mine?: boolean | null;
|
|
38
40
|
}
|
|
@@ -51,12 +53,12 @@ export declare class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
51
53
|
*/
|
|
52
54
|
agentConversationArtifactDownloadUrl(requestParameters: AgentConversationArtifactDownloadUrlRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DownloadUrlResponse>;
|
|
53
55
|
/**
|
|
54
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
56
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
55
57
|
* Get Agent Conversation Route
|
|
56
58
|
*/
|
|
57
59
|
getAgentConversationRaw(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AgentConversationDetail>>;
|
|
58
60
|
/**
|
|
59
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
61
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
60
62
|
* Get Agent Conversation Route
|
|
61
63
|
*/
|
|
62
64
|
getAgentConversation(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AgentConversationDetail>;
|
|
@@ -71,12 +73,12 @@ export declare class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
71
73
|
*/
|
|
72
74
|
listAgentConversationMessages(requestParameters: ListAgentConversationMessagesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MessagesResponse>;
|
|
73
75
|
/**
|
|
74
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
76
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
75
77
|
* List Agent Conversations Route
|
|
76
78
|
*/
|
|
77
79
|
listAgentConversationsRaw(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PageAgentConversationView>>;
|
|
78
80
|
/**
|
|
79
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
81
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
80
82
|
* List Agent Conversations Route
|
|
81
83
|
*/
|
|
82
84
|
listAgentConversations(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PageAgentConversationView>;
|
|
@@ -89,12 +91,36 @@ export declare const AgentConversationArtifactDownloadUrlDispositionEnum: {
|
|
|
89
91
|
readonly Attachment: "attachment";
|
|
90
92
|
};
|
|
91
93
|
export type AgentConversationArtifactDownloadUrlDispositionEnum = typeof AgentConversationArtifactDownloadUrlDispositionEnum[keyof typeof AgentConversationArtifactDownloadUrlDispositionEnum];
|
|
94
|
+
/**
|
|
95
|
+
* @export
|
|
96
|
+
*/
|
|
97
|
+
export declare const GetAgentConversationSessionTypeEnum: {
|
|
98
|
+
readonly Api: "api";
|
|
99
|
+
readonly Chat: "chat";
|
|
100
|
+
readonly Slack: "slack";
|
|
101
|
+
readonly Teams: "teams";
|
|
102
|
+
readonly All: "all";
|
|
103
|
+
};
|
|
104
|
+
export type GetAgentConversationSessionTypeEnum = typeof GetAgentConversationSessionTypeEnum[keyof typeof GetAgentConversationSessionTypeEnum];
|
|
105
|
+
/**
|
|
106
|
+
* @export
|
|
107
|
+
*/
|
|
108
|
+
export declare const ListAgentConversationMessagesSessionTypeEnum: {
|
|
109
|
+
readonly Api: "api";
|
|
110
|
+
readonly Chat: "chat";
|
|
111
|
+
readonly Slack: "slack";
|
|
112
|
+
readonly Teams: "teams";
|
|
113
|
+
readonly All: "all";
|
|
114
|
+
};
|
|
115
|
+
export type ListAgentConversationMessagesSessionTypeEnum = typeof ListAgentConversationMessagesSessionTypeEnum[keyof typeof ListAgentConversationMessagesSessionTypeEnum];
|
|
92
116
|
/**
|
|
93
117
|
* @export
|
|
94
118
|
*/
|
|
95
119
|
export declare const ListAgentConversationsSessionTypeEnum: {
|
|
96
120
|
readonly Api: "api";
|
|
97
121
|
readonly Chat: "chat";
|
|
122
|
+
readonly Slack: "slack";
|
|
123
|
+
readonly Teams: "teams";
|
|
98
124
|
readonly All: "all";
|
|
99
125
|
};
|
|
100
126
|
export type ListAgentConversationsSessionTypeEnum = typeof ListAgentConversationsSessionTypeEnum[keyof typeof ListAgentConversationsSessionTypeEnum];
|
|
@@ -63,7 +63,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
63
63
|
return await response.value();
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
66
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
67
67
|
* Get Agent Conversation Route
|
|
68
68
|
*/
|
|
69
69
|
async getAgentConversationRaw(requestParameters, initOverrides) {
|
|
@@ -74,6 +74,9 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
74
74
|
throw new runtime.RequiredError('conversationId', 'Required parameter "conversationId" was null or undefined when calling getAgentConversation().');
|
|
75
75
|
}
|
|
76
76
|
const queryParameters = {};
|
|
77
|
+
if (requestParameters['sessionType'] != null) {
|
|
78
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
79
|
+
}
|
|
77
80
|
const headerParameters = {};
|
|
78
81
|
if (this.configuration && this.configuration.accessToken) {
|
|
79
82
|
const token = this.configuration.accessToken;
|
|
@@ -91,7 +94,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
91
94
|
return new runtime.JSONApiResponse(response, (jsonValue) => AgentConversationDetailFromJSON(jsonValue));
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
94
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
97
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
95
98
|
* Get Agent Conversation Route
|
|
96
99
|
*/
|
|
97
100
|
async getAgentConversation(requestParameters, initOverrides) {
|
|
@@ -113,6 +116,9 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
113
116
|
throw new runtime.RequiredError('before', 'Required parameter "before" was null or undefined when calling listAgentConversationMessages().');
|
|
114
117
|
}
|
|
115
118
|
const queryParameters = {};
|
|
119
|
+
if (requestParameters['sessionType'] != null) {
|
|
120
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
121
|
+
}
|
|
116
122
|
if (requestParameters['before'] != null) {
|
|
117
123
|
queryParameters['before'] = requestParameters['before'];
|
|
118
124
|
}
|
|
@@ -144,7 +150,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
144
150
|
return await response.value();
|
|
145
151
|
}
|
|
146
152
|
/**
|
|
147
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
153
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
148
154
|
* List Agent Conversations Route
|
|
149
155
|
*/
|
|
150
156
|
async listAgentConversationsRaw(requestParameters, initOverrides) {
|
|
@@ -184,7 +190,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
184
190
|
return new runtime.JSONApiResponse(response, (jsonValue) => PageAgentConversationViewFromJSON(jsonValue));
|
|
185
191
|
}
|
|
186
192
|
/**
|
|
187
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
193
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
188
194
|
* List Agent Conversations Route
|
|
189
195
|
*/
|
|
190
196
|
async listAgentConversations(requestParameters, initOverrides) {
|
|
@@ -199,11 +205,33 @@ export const AgentConversationArtifactDownloadUrlDispositionEnum = {
|
|
|
199
205
|
Inline: 'inline',
|
|
200
206
|
Attachment: 'attachment'
|
|
201
207
|
};
|
|
208
|
+
/**
|
|
209
|
+
* @export
|
|
210
|
+
*/
|
|
211
|
+
export const GetAgentConversationSessionTypeEnum = {
|
|
212
|
+
Api: 'api',
|
|
213
|
+
Chat: 'chat',
|
|
214
|
+
Slack: 'slack',
|
|
215
|
+
Teams: 'teams',
|
|
216
|
+
All: 'all'
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* @export
|
|
220
|
+
*/
|
|
221
|
+
export const ListAgentConversationMessagesSessionTypeEnum = {
|
|
222
|
+
Api: 'api',
|
|
223
|
+
Chat: 'chat',
|
|
224
|
+
Slack: 'slack',
|
|
225
|
+
Teams: 'teams',
|
|
226
|
+
All: 'all'
|
|
227
|
+
};
|
|
202
228
|
/**
|
|
203
229
|
* @export
|
|
204
230
|
*/
|
|
205
231
|
export const ListAgentConversationsSessionTypeEnum = {
|
|
206
232
|
Api: 'api',
|
|
207
233
|
Chat: 'chat',
|
|
234
|
+
Slack: 'slack',
|
|
235
|
+
Teams: 'teams',
|
|
208
236
|
All: 'all'
|
|
209
237
|
};
|
|
@@ -45,6 +45,16 @@ export type Event = {
|
|
|
45
45
|
} | {
|
|
46
46
|
kind: "stopped";
|
|
47
47
|
reason: string;
|
|
48
|
+
}
|
|
49
|
+
/** An agent.json limit ended the turn (`data-turn-limit`); the wrap-up answer still follows. `capKind` is the
|
|
50
|
+
* server's cap name: `max_turns`, `tool_calls` or `tokens`. `limit` is the agent.json `limits` key that set it
|
|
51
|
+
* (`max_turns`, `max_tool_calls_per_turn` or `max_tokens_per_turn`) and `value` the configured number; both are
|
|
52
|
+
* absent from a server that predates them. */
|
|
53
|
+
| {
|
|
54
|
+
kind: "turn_limit";
|
|
55
|
+
capKind: string;
|
|
56
|
+
limit?: string;
|
|
57
|
+
value?: number;
|
|
48
58
|
} | {
|
|
49
59
|
kind: "turn_finished";
|
|
50
60
|
reason: string;
|
|
@@ -84,6 +84,13 @@ function map(chunk) {
|
|
|
84
84
|
ev.expiresAt = data["expiresAt"];
|
|
85
85
|
return ev;
|
|
86
86
|
}
|
|
87
|
+
case "data-turn-limit":
|
|
88
|
+
return {
|
|
89
|
+
kind: "turn_limit",
|
|
90
|
+
capKind: str(data["kind"], ""),
|
|
91
|
+
...(typeof data["limit"] === "string" && data["limit"] ? { limit: data["limit"] } : {}),
|
|
92
|
+
...(Number.isInteger(data["value"]) ? { value: data["value"] } : {}),
|
|
93
|
+
};
|
|
87
94
|
case "data-stopped":
|
|
88
95
|
return { kind: "stopped", reason: str(data["reason"], "stopped") };
|
|
89
96
|
case "error":
|
|
@@ -8,6 +8,6 @@ export type { RemoteAgent, SettingsWarning, TurnStream, Transport } from "./tran
|
|
|
8
8
|
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
9
9
|
export type { Deployment } from "./deploy.js";
|
|
10
10
|
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
11
|
-
export type { RunOptions, RunStreamEvent, ClarifyHandler } from "./run.js";
|
|
11
|
+
export type { RunOptions, RunStreamEvent, ClarifyHandler, StopReason } from "./run.js";
|
|
12
12
|
export { RunState } from "./runState.js";
|
|
13
13
|
export type { Interruption } from "./runState.js";
|
|
@@ -29,11 +29,14 @@ export type RunStreamEvent = {
|
|
|
29
29
|
name: "tool_called" | "tool_output" | "message_output_created";
|
|
30
30
|
item: unknown;
|
|
31
31
|
};
|
|
32
|
+
/** Why the run ended early: the `limits` field whose cap the server hit. */
|
|
33
|
+
export type StopReason = "max_turns" | "max_tool_calls" | "max_tokens";
|
|
32
34
|
interface Outcome {
|
|
33
35
|
finalOutput: string | undefined;
|
|
34
36
|
outputText: string;
|
|
35
37
|
newItems: Event[];
|
|
36
38
|
interruptions: Interruption[];
|
|
39
|
+
stopReason: StopReason | undefined;
|
|
37
40
|
conversationId: string | undefined;
|
|
38
41
|
cancelled: boolean;
|
|
39
42
|
}
|
|
@@ -42,6 +45,8 @@ export declare class RunResult {
|
|
|
42
45
|
readonly outputText: string;
|
|
43
46
|
readonly newItems: Event[];
|
|
44
47
|
readonly interruptions: Interruption[];
|
|
48
|
+
/** Set when an agent.json limit ended the turn; `finalOutput` still holds the wrap-up answer. */
|
|
49
|
+
readonly stopReason: StopReason | undefined;
|
|
45
50
|
readonly conversationId: string | undefined;
|
|
46
51
|
/** @internal */
|
|
47
52
|
constructor(outcome: Outcome);
|
|
@@ -63,6 +68,8 @@ export declare class StreamedRunResult implements AsyncIterable<RunStreamEvent>
|
|
|
63
68
|
outputText: string;
|
|
64
69
|
newItems: Event[];
|
|
65
70
|
interruptions: Interruption[];
|
|
71
|
+
/** Set when an agent.json limit ended the turn; read after `completed` settles. */
|
|
72
|
+
stopReason: StopReason | undefined;
|
|
66
73
|
conversationId: string | undefined;
|
|
67
74
|
cancelled: boolean;
|
|
68
75
|
private readonly queue;
|
package/dist/esm/compose/run.js
CHANGED
|
@@ -5,6 +5,12 @@ import { RunState } from "./runState.js";
|
|
|
5
5
|
const MAX_RECONNECTS = 3;
|
|
6
6
|
/** The abort reason ResponseStream (src/streaming.ts) uses when a stream goes quiet. */
|
|
7
7
|
const IDLE_TIMEOUT_MESSAGE = "stream idle timeout";
|
|
8
|
+
/** Server cap kind (`data-turn-limit`) -> stop reason, named like the `limits` field that set it. */
|
|
9
|
+
const STOP_REASONS = {
|
|
10
|
+
max_turns: "max_turns",
|
|
11
|
+
tool_calls: "max_tool_calls",
|
|
12
|
+
tokens: "max_tokens",
|
|
13
|
+
};
|
|
8
14
|
function stateOf(conversationId, interruptions) {
|
|
9
15
|
if (conversationId === undefined)
|
|
10
16
|
throw new UserError("this run has no conversation to resume");
|
|
@@ -17,6 +23,7 @@ export class RunResult {
|
|
|
17
23
|
this.outputText = outcome.outputText;
|
|
18
24
|
this.newItems = outcome.newItems;
|
|
19
25
|
this.interruptions = outcome.interruptions;
|
|
26
|
+
this.stopReason = outcome.stopReason;
|
|
20
27
|
this.conversationId = outcome.conversationId;
|
|
21
28
|
}
|
|
22
29
|
/** A RunState to answer the interruptions and continue; throws UserError when the run has no conversation. */
|
|
@@ -97,6 +104,7 @@ class Loop {
|
|
|
97
104
|
this.onConversation = onConversation;
|
|
98
105
|
this.conversationId = null;
|
|
99
106
|
this.items = [];
|
|
107
|
+
this.stopReason = undefined;
|
|
100
108
|
// Text of the current segment, per text block. Kept per block so a resumed stream, which replays from the start
|
|
101
109
|
// of the block it dropped in, doesn't repeat text.
|
|
102
110
|
this.blocks = [];
|
|
@@ -241,6 +249,9 @@ class Loop {
|
|
|
241
249
|
if (this.signal.aborted)
|
|
242
250
|
throw new Cancelled();
|
|
243
251
|
throw new RunError("stopped", `the turn was stopped on the server (${event.reason})`);
|
|
252
|
+
case "turn_limit":
|
|
253
|
+
this.stopReason = STOP_REASONS[event.capKind];
|
|
254
|
+
return false;
|
|
244
255
|
case "text_start":
|
|
245
256
|
case "text_end":
|
|
246
257
|
this.onText(event);
|
|
@@ -397,6 +408,7 @@ async function execute(p, controller, emit) {
|
|
|
397
408
|
outputText: text,
|
|
398
409
|
newItems: loop.items,
|
|
399
410
|
interruptions,
|
|
411
|
+
stopReason: loop.stopReason,
|
|
400
412
|
conversationId: (_b = loop.conversationId) !== null && _b !== void 0 ? _b : fallbackConversation,
|
|
401
413
|
cancelled,
|
|
402
414
|
};
|
|
@@ -410,6 +422,8 @@ export class StreamedRunResult {
|
|
|
410
422
|
this.outputText = "";
|
|
411
423
|
this.newItems = [];
|
|
412
424
|
this.interruptions = [];
|
|
425
|
+
/** Set when an agent.json limit ended the turn; read after `completed` settles. */
|
|
426
|
+
this.stopReason = undefined;
|
|
413
427
|
this.conversationId = undefined;
|
|
414
428
|
this.cancelled = false;
|
|
415
429
|
this.queue = [];
|
|
@@ -424,6 +438,7 @@ export class StreamedRunResult {
|
|
|
424
438
|
this.outputText = outcome.outputText;
|
|
425
439
|
this.newItems = outcome.newItems;
|
|
426
440
|
this.interruptions = outcome.interruptions;
|
|
441
|
+
this.stopReason = outcome.stopReason;
|
|
427
442
|
this.conversationId = outcome.conversationId;
|
|
428
443
|
this.cancelled = outcome.cancelled;
|
|
429
444
|
this.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sarvam-agents-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Client for the Sarvam Agents API: chat with an agent, exchange files with it, and set it up from your own code.",
|
|
5
5
|
"author": "Sarvam AI <support@sarvam.ai>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,12 +51,14 @@ export interface AgentConversationArtifactDownloadUrlRequest {
|
|
|
51
51
|
export interface GetAgentConversationRequest {
|
|
52
52
|
agentId: string;
|
|
53
53
|
conversationId: string;
|
|
54
|
+
sessionType?: Array<GetAgentConversationSessionTypeEnum>;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export interface ListAgentConversationMessagesRequest {
|
|
57
58
|
agentId: string;
|
|
58
59
|
conversationId: string;
|
|
59
60
|
before: string;
|
|
61
|
+
sessionType?: Array<ListAgentConversationMessagesSessionTypeEnum>;
|
|
60
62
|
turnLimit?: number | null;
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -64,7 +66,7 @@ export interface ListAgentConversationsRequest {
|
|
|
64
66
|
agentId: string;
|
|
65
67
|
limit?: number;
|
|
66
68
|
cursor?: string | null;
|
|
67
|
-
sessionType?: ListAgentConversationsSessionTypeEnum
|
|
69
|
+
sessionType?: Array<ListAgentConversationsSessionTypeEnum>;
|
|
68
70
|
workspaceId?: Array<string>;
|
|
69
71
|
mine?: boolean | null;
|
|
70
72
|
}
|
|
@@ -140,7 +142,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
145
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
144
146
|
* Get Agent Conversation Route
|
|
145
147
|
*/
|
|
146
148
|
async getAgentConversationRaw(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AgentConversationDetail>> {
|
|
@@ -160,6 +162,10 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
160
162
|
|
|
161
163
|
const queryParameters: any = {};
|
|
162
164
|
|
|
165
|
+
if (requestParameters['sessionType'] != null) {
|
|
166
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
167
|
+
}
|
|
168
|
+
|
|
163
169
|
const headerParameters: runtime.HTTPHeaders = {};
|
|
164
170
|
|
|
165
171
|
if (this.configuration && this.configuration.accessToken) {
|
|
@@ -181,7 +187,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
/**
|
|
184
|
-
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s.
|
|
190
|
+
* One session from the log, with its projected history and tool calls. Read-only: unlike the self route this never marks the row read, because ``last_read_at`` is the owning user\'s unread state, not the agent owner\'s. A Slack or Teams session opens when ``sessionType`` is omitted or names its platform; its ``lastActiveAt`` / ``createdAt`` are those of the turns on the page.
|
|
185
191
|
* Get Agent Conversation Route
|
|
186
192
|
*/
|
|
187
193
|
async getAgentConversation(requestParameters: GetAgentConversationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AgentConversationDetail> {
|
|
@@ -217,6 +223,10 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
217
223
|
|
|
218
224
|
const queryParameters: any = {};
|
|
219
225
|
|
|
226
|
+
if (requestParameters['sessionType'] != null) {
|
|
227
|
+
queryParameters['sessionType'] = requestParameters['sessionType'];
|
|
228
|
+
}
|
|
229
|
+
|
|
220
230
|
if (requestParameters['before'] != null) {
|
|
221
231
|
queryParameters['before'] = requestParameters['before'];
|
|
222
232
|
}
|
|
@@ -255,7 +265,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
255
265
|
}
|
|
256
266
|
|
|
257
267
|
/**
|
|
258
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
268
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
259
269
|
* List Agent Conversations Route
|
|
260
270
|
*/
|
|
261
271
|
async listAgentConversationsRaw(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PageAgentConversationView>> {
|
|
@@ -309,7 +319,7 @@ export class AgentConversationsApi extends runtime.BaseAPI {
|
|
|
309
319
|
}
|
|
310
320
|
|
|
311
321
|
/**
|
|
312
|
-
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first.
|
|
322
|
+
* The agent owner\'s session log: conversations every user in the tenant has had with this agent on the selected surface, newest-active first. ``sessionType`` is repeatable (``api``, ``chat``, ``slack``, ``teams``, ``all``) and the values add up.
|
|
313
323
|
* List Agent Conversations Route
|
|
314
324
|
*/
|
|
315
325
|
async listAgentConversations(requestParameters: ListAgentConversationsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PageAgentConversationView> {
|
|
@@ -327,12 +337,36 @@ export const AgentConversationArtifactDownloadUrlDispositionEnum = {
|
|
|
327
337
|
Attachment: 'attachment'
|
|
328
338
|
} as const;
|
|
329
339
|
export type AgentConversationArtifactDownloadUrlDispositionEnum = typeof AgentConversationArtifactDownloadUrlDispositionEnum[keyof typeof AgentConversationArtifactDownloadUrlDispositionEnum];
|
|
340
|
+
/**
|
|
341
|
+
* @export
|
|
342
|
+
*/
|
|
343
|
+
export const GetAgentConversationSessionTypeEnum = {
|
|
344
|
+
Api: 'api',
|
|
345
|
+
Chat: 'chat',
|
|
346
|
+
Slack: 'slack',
|
|
347
|
+
Teams: 'teams',
|
|
348
|
+
All: 'all'
|
|
349
|
+
} as const;
|
|
350
|
+
export type GetAgentConversationSessionTypeEnum = typeof GetAgentConversationSessionTypeEnum[keyof typeof GetAgentConversationSessionTypeEnum];
|
|
351
|
+
/**
|
|
352
|
+
* @export
|
|
353
|
+
*/
|
|
354
|
+
export const ListAgentConversationMessagesSessionTypeEnum = {
|
|
355
|
+
Api: 'api',
|
|
356
|
+
Chat: 'chat',
|
|
357
|
+
Slack: 'slack',
|
|
358
|
+
Teams: 'teams',
|
|
359
|
+
All: 'all'
|
|
360
|
+
} as const;
|
|
361
|
+
export type ListAgentConversationMessagesSessionTypeEnum = typeof ListAgentConversationMessagesSessionTypeEnum[keyof typeof ListAgentConversationMessagesSessionTypeEnum];
|
|
330
362
|
/**
|
|
331
363
|
* @export
|
|
332
364
|
*/
|
|
333
365
|
export const ListAgentConversationsSessionTypeEnum = {
|
|
334
366
|
Api: 'api',
|
|
335
367
|
Chat: 'chat',
|
|
368
|
+
Slack: 'slack',
|
|
369
|
+
Teams: 'teams',
|
|
336
370
|
All: 'all'
|
|
337
371
|
} as const;
|
|
338
372
|
export type ListAgentConversationsSessionTypeEnum = typeof ListAgentConversationsSessionTypeEnum[keyof typeof ListAgentConversationsSessionTypeEnum];
|
package/src/compose/events.ts
CHANGED
|
@@ -24,6 +24,11 @@ export type Event =
|
|
|
24
24
|
| { kind: "clarify_requested"; requestId: string; questions: ClarifyQuestion[] }
|
|
25
25
|
| { kind: "function_calls_requested"; requestId: string; calls: FunctionCallRequest[]; expiresAt?: string }
|
|
26
26
|
| { kind: "stopped"; reason: string }
|
|
27
|
+
/** An agent.json limit ended the turn (`data-turn-limit`); the wrap-up answer still follows. `capKind` is the
|
|
28
|
+
* server's cap name: `max_turns`, `tool_calls` or `tokens`. `limit` is the agent.json `limits` key that set it
|
|
29
|
+
* (`max_turns`, `max_tool_calls_per_turn` or `max_tokens_per_turn`) and `value` the configured number; both are
|
|
30
|
+
* absent from a server that predates them. */
|
|
31
|
+
| { kind: "turn_limit"; capKind: string; limit?: string; value?: number }
|
|
27
32
|
| { kind: "turn_finished"; reason: string }
|
|
28
33
|
| { kind: "turn_failed"; code: string; message: string }
|
|
29
34
|
| { kind: "unknown"; chunk: Record<string, unknown> };
|
|
@@ -109,6 +114,13 @@ function map(chunk: Record<string, unknown>): Event | null {
|
|
|
109
114
|
if (typeof data["expiresAt"] === "string") ev.expiresAt = data["expiresAt"];
|
|
110
115
|
return ev;
|
|
111
116
|
}
|
|
117
|
+
case "data-turn-limit":
|
|
118
|
+
return {
|
|
119
|
+
kind: "turn_limit",
|
|
120
|
+
capKind: str(data["kind"], ""),
|
|
121
|
+
...(typeof data["limit"] === "string" && data["limit"] ? { limit: data["limit"] } : {}),
|
|
122
|
+
...(Number.isInteger(data["value"]) ? { value: data["value"] as number } : {}),
|
|
123
|
+
};
|
|
112
124
|
case "data-stopped":
|
|
113
125
|
return { kind: "stopped", reason: str(data["reason"], "stopped") };
|
|
114
126
|
case "error":
|
package/src/compose/index.ts
CHANGED
|
@@ -8,6 +8,6 @@ export type { RemoteAgent, SettingsWarning, TurnStream, Transport } from "./tran
|
|
|
8
8
|
export { deploy, undeploy, setDefaultClient } from "./deploy.js";
|
|
9
9
|
export type { Deployment } from "./deploy.js";
|
|
10
10
|
export { run, RunResult, StreamedRunResult } from "./run.js";
|
|
11
|
-
export type { RunOptions, RunStreamEvent, ClarifyHandler } from "./run.js";
|
|
11
|
+
export type { RunOptions, RunStreamEvent, ClarifyHandler, StopReason } from "./run.js";
|
|
12
12
|
export { RunState } from "./runState.js";
|
|
13
13
|
export type { Interruption } from "./runState.js";
|
package/src/compose/run.ts
CHANGED
|
@@ -37,11 +37,22 @@ export type RunStreamEvent =
|
|
|
37
37
|
type ClarifyEvent = Extract<Event, { kind: "clarify_requested" }>;
|
|
38
38
|
type Emit = (event: RunStreamEvent) => void;
|
|
39
39
|
|
|
40
|
+
/** Why the run ended early: the `limits` field whose cap the server hit. */
|
|
41
|
+
export type StopReason = "max_turns" | "max_tool_calls" | "max_tokens";
|
|
42
|
+
|
|
43
|
+
/** Server cap kind (`data-turn-limit`) -> stop reason, named like the `limits` field that set it. */
|
|
44
|
+
const STOP_REASONS: Record<string, StopReason> = {
|
|
45
|
+
max_turns: "max_turns",
|
|
46
|
+
tool_calls: "max_tool_calls",
|
|
47
|
+
tokens: "max_tokens",
|
|
48
|
+
};
|
|
49
|
+
|
|
40
50
|
interface Outcome {
|
|
41
51
|
finalOutput: string | undefined;
|
|
42
52
|
outputText: string;
|
|
43
53
|
newItems: Event[];
|
|
44
54
|
interruptions: Interruption[];
|
|
55
|
+
stopReason: StopReason | undefined;
|
|
45
56
|
conversationId: string | undefined;
|
|
46
57
|
cancelled: boolean;
|
|
47
58
|
}
|
|
@@ -56,6 +67,8 @@ export class RunResult {
|
|
|
56
67
|
readonly outputText: string;
|
|
57
68
|
readonly newItems: Event[];
|
|
58
69
|
readonly interruptions: Interruption[];
|
|
70
|
+
/** Set when an agent.json limit ended the turn; `finalOutput` still holds the wrap-up answer. */
|
|
71
|
+
readonly stopReason: StopReason | undefined;
|
|
59
72
|
readonly conversationId: string | undefined;
|
|
60
73
|
|
|
61
74
|
/** @internal */
|
|
@@ -64,6 +77,7 @@ export class RunResult {
|
|
|
64
77
|
this.outputText = outcome.outputText;
|
|
65
78
|
this.newItems = outcome.newItems;
|
|
66
79
|
this.interruptions = outcome.interruptions;
|
|
80
|
+
this.stopReason = outcome.stopReason;
|
|
67
81
|
this.conversationId = outcome.conversationId;
|
|
68
82
|
}
|
|
69
83
|
|
|
@@ -145,6 +159,7 @@ class Stopper {
|
|
|
145
159
|
class Loop {
|
|
146
160
|
conversationId: string | null = null;
|
|
147
161
|
readonly items: Event[] = [];
|
|
162
|
+
stopReason: StopReason | undefined = undefined;
|
|
148
163
|
// Text of the current segment, per text block. Kept per block so a resumed stream, which replays from the start
|
|
149
164
|
// of the block it dropped in, doesn't repeat text.
|
|
150
165
|
private blocks: [string | null, string[]][] = [];
|
|
@@ -285,6 +300,9 @@ class Loop {
|
|
|
285
300
|
case "stopped":
|
|
286
301
|
if (this.signal.aborted) throw new Cancelled();
|
|
287
302
|
throw new RunError("stopped", `the turn was stopped on the server (${event.reason})`);
|
|
303
|
+
case "turn_limit":
|
|
304
|
+
this.stopReason = STOP_REASONS[event.capKind];
|
|
305
|
+
return false;
|
|
288
306
|
case "text_start":
|
|
289
307
|
case "text_end":
|
|
290
308
|
this.onText(event);
|
|
@@ -447,6 +465,7 @@ async function execute(p: Prepared, controller: AbortController, emit: Emit): Pr
|
|
|
447
465
|
outputText: text,
|
|
448
466
|
newItems: loop.items,
|
|
449
467
|
interruptions,
|
|
468
|
+
stopReason: loop.stopReason,
|
|
450
469
|
conversationId: loop.conversationId ?? fallbackConversation,
|
|
451
470
|
cancelled,
|
|
452
471
|
};
|
|
@@ -462,6 +481,8 @@ export class StreamedRunResult implements AsyncIterable<RunStreamEvent> {
|
|
|
462
481
|
outputText = "";
|
|
463
482
|
newItems: Event[] = [];
|
|
464
483
|
interruptions: Interruption[] = [];
|
|
484
|
+
/** Set when an agent.json limit ended the turn; read after `completed` settles. */
|
|
485
|
+
stopReason: StopReason | undefined = undefined;
|
|
465
486
|
conversationId: string | undefined = undefined;
|
|
466
487
|
cancelled = false;
|
|
467
488
|
|
|
@@ -482,6 +503,7 @@ export class StreamedRunResult implements AsyncIterable<RunStreamEvent> {
|
|
|
482
503
|
this.outputText = outcome.outputText;
|
|
483
504
|
this.newItems = outcome.newItems;
|
|
484
505
|
this.interruptions = outcome.interruptions;
|
|
506
|
+
this.stopReason = outcome.stopReason;
|
|
485
507
|
this.conversationId = outcome.conversationId;
|
|
486
508
|
this.cancelled = outcome.cancelled;
|
|
487
509
|
this.end();
|