sarvam-agents-client 0.2.0 → 0.2.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.
- package/dist/apis/AgentConversationsApi.d.ts +31 -5
- package/dist/apis/AgentConversationsApi.js +33 -5
- package/dist/compose/agent.d.ts +5 -1
- package/dist/compose/agent.js +37 -6
- package/dist/compose/builtins.d.ts +4 -0
- package/dist/compose/builtins.js +22 -0
- package/dist/compose/tools.d.ts +1 -1
- package/dist/compose/tools.js +19 -4
- package/dist/esm/apis/AgentConversationsApi.d.ts +31 -5
- package/dist/esm/apis/AgentConversationsApi.js +32 -4
- package/dist/esm/compose/agent.d.ts +5 -1
- package/dist/esm/compose/agent.js +37 -6
- package/dist/esm/compose/builtins.d.ts +4 -0
- package/dist/esm/compose/builtins.js +18 -0
- package/dist/esm/compose/tools.d.ts +1 -1
- package/dist/esm/compose/tools.js +19 -4
- package/package.json +1 -1
- package/src/apis/AgentConversationsApi.ts +39 -5
- package/src/compose/agent.ts +37 -6
- package/src/compose/builtins.ts +19 -0
- package/src/compose/tools.ts +17 -2
|
@@ -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/agent.d.ts
CHANGED
|
@@ -17,8 +17,11 @@ export interface AgentOptions {
|
|
|
17
17
|
name: string;
|
|
18
18
|
instructions?: string;
|
|
19
19
|
model?: string;
|
|
20
|
+
/** Catalog endpoint to serve `model` from (agent.json `endpoint`). */
|
|
21
|
+
endpoint?: string;
|
|
20
22
|
modelSettings?: ModelSettings;
|
|
21
23
|
fallbackModels?: string[];
|
|
24
|
+
/** Exact list of built-ins to keep on; omit to keep the server default (all on). */
|
|
22
25
|
tools?: BuiltinTool[];
|
|
23
26
|
limits?: Limits;
|
|
24
27
|
metadata?: Record<string, string>;
|
|
@@ -27,9 +30,10 @@ export declare class Agent {
|
|
|
27
30
|
readonly name: string;
|
|
28
31
|
readonly instructions: string;
|
|
29
32
|
readonly model?: string;
|
|
33
|
+
readonly endpoint?: string;
|
|
30
34
|
readonly modelSettings?: ModelSettings;
|
|
31
35
|
readonly fallbackModels?: string[];
|
|
32
|
-
readonly tools
|
|
36
|
+
readonly tools?: readonly BuiltinTool[];
|
|
33
37
|
readonly limits?: Limits;
|
|
34
38
|
readonly metadata?: Record<string, string>;
|
|
35
39
|
constructor(rawOpts: AgentOptions);
|
package/dist/compose/agent.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Agent = void 0;
|
|
4
4
|
const errors_js_1 = require("./errors.js");
|
|
5
5
|
const fingerprint_js_1 = require("./fingerprint.js");
|
|
6
|
+
const builtins_js_1 = require("./builtins.js");
|
|
6
7
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
7
8
|
const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
|
|
8
9
|
const TOOL_CHOICES = ["auto", "none"];
|
|
@@ -74,7 +75,7 @@ const LIMIT_KEYS = [
|
|
|
74
75
|
];
|
|
75
76
|
class Agent {
|
|
76
77
|
constructor(rawOpts) {
|
|
77
|
-
var _a, _b
|
|
78
|
+
var _a, _b;
|
|
78
79
|
const opts = normalize(rawOpts);
|
|
79
80
|
for (const tool of (_a = opts.tools) !== null && _a !== void 0 ? _a : []) {
|
|
80
81
|
if (tool instanceof Agent) {
|
|
@@ -85,18 +86,28 @@ class Agent {
|
|
|
85
86
|
this.name = opts.name;
|
|
86
87
|
this.instructions = (_b = opts.instructions) !== null && _b !== void 0 ? _b : "";
|
|
87
88
|
this.model = opts.model;
|
|
89
|
+
this.endpoint = opts.endpoint;
|
|
88
90
|
this.modelSettings = clone(opts.modelSettings);
|
|
89
91
|
this.fallbackModels = clone(opts.fallbackModels);
|
|
90
|
-
this.tools = clone(
|
|
92
|
+
this.tools = clone(opts.tools);
|
|
91
93
|
this.limits = clone(opts.limits);
|
|
92
94
|
this.metadata = clone(opts.metadata);
|
|
93
95
|
this.check();
|
|
94
96
|
deepFreeze(this);
|
|
95
97
|
}
|
|
96
98
|
check() {
|
|
99
|
+
var _a, _b;
|
|
97
100
|
if (typeof this.name !== "string" || !SLUG.test(this.name)) {
|
|
98
101
|
throw new errors_js_1.UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
|
|
99
102
|
}
|
|
103
|
+
for (const [key, value] of [["model", this.model], ["endpoint", this.endpoint]]) {
|
|
104
|
+
if (value !== undefined && (typeof value !== "string" || value === "")) {
|
|
105
|
+
throw new errors_js_1.UserError(`${key}: must be a non-empty string`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (this.endpoint !== undefined && this.model === undefined) {
|
|
109
|
+
throw new errors_js_1.UserError("endpoint: needs model; set the model this endpoint serves");
|
|
110
|
+
}
|
|
100
111
|
const ms = this.modelSettings;
|
|
101
112
|
if (ms !== undefined) {
|
|
102
113
|
if (ms.reasoning !== undefined && REASONING.indexOf(ms.reasoning.effort) === -1) {
|
|
@@ -129,16 +140,33 @@ class Agent {
|
|
|
129
140
|
throw new errors_js_1.UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
|
-
const names = this.tools.map((t) => t.name);
|
|
143
|
+
const names = ((_a = this.tools) !== null && _a !== void 0 ? _a : []).map((t) => t.name);
|
|
144
|
+
for (const n of names) {
|
|
145
|
+
if (builtins_js_1.BUILTIN_NAMES.indexOf(n) === -1) {
|
|
146
|
+
throw new errors_js_1.UserError(`tools: unknown built-in tool ${JSON.stringify(n)} (known: ${builtins_js_1.BUILTIN_NAMES.join(", ")})`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
133
149
|
const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
|
|
134
150
|
if (dupes.length > 0) {
|
|
135
151
|
throw new errors_js_1.UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
|
|
136
152
|
}
|
|
153
|
+
for (const t of (_b = this.tools) !== null && _b !== void 0 ? _b : []) {
|
|
154
|
+
if (t.options === undefined || Object.keys(t.options).length === 0)
|
|
155
|
+
continue;
|
|
156
|
+
if (t.name !== "web_search")
|
|
157
|
+
throw new errors_js_1.UserError(`tools: ${t.name} takes no options`);
|
|
158
|
+
(0, builtins_js_1.checkWebSearchOptions)(t.options);
|
|
159
|
+
}
|
|
160
|
+
if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
|
|
161
|
+
throw new errors_js_1.UserError("tools: codeMode needs sandbox; add sandbox() to tools");
|
|
162
|
+
}
|
|
137
163
|
}
|
|
138
164
|
baseSettings() {
|
|
139
165
|
const out = { version: 1 };
|
|
140
166
|
if (this.model !== undefined)
|
|
141
167
|
out["model"] = this.model;
|
|
168
|
+
if (this.endpoint !== undefined)
|
|
169
|
+
out["endpoint"] = this.endpoint;
|
|
142
170
|
const ms = this.modelSettings;
|
|
143
171
|
if (ms !== undefined) {
|
|
144
172
|
if (ms.reasoning !== undefined)
|
|
@@ -165,10 +193,13 @@ class Agent {
|
|
|
165
193
|
if (Object.keys(limits).length > 0)
|
|
166
194
|
out["limits"] = limits;
|
|
167
195
|
}
|
|
168
|
-
if (this.tools
|
|
196
|
+
if (this.tools !== undefined) {
|
|
197
|
+
// Built-ins are on by default, so an exact list writes every unlisted one as off.
|
|
169
198
|
const tools = {};
|
|
170
|
-
for (const
|
|
171
|
-
|
|
199
|
+
for (const n of builtins_js_1.BUILTIN_NAMES) {
|
|
200
|
+
const t = this.tools.find((x) => x.name === n);
|
|
201
|
+
tools[n] = t === undefined ? false
|
|
202
|
+
: t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
|
|
172
203
|
}
|
|
173
204
|
out["builtin_tools"] = tools;
|
|
174
205
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
2
|
+
export declare const BUILTIN_NAMES: readonly ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"];
|
|
3
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
4
|
+
export declare function checkWebSearchOptions(options: Record<string, unknown>): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUILTIN_NAMES = void 0;
|
|
4
|
+
exports.checkWebSearchOptions = checkWebSearchOptions;
|
|
5
|
+
/** Internal: built-in tool names and checks shared by tools.ts and agent.ts. Not re-exported from index.ts. */
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
8
|
+
exports.BUILTIN_NAMES = ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"];
|
|
9
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
10
|
+
function checkWebSearchOptions(options) {
|
|
11
|
+
const keys = Object.keys(options);
|
|
12
|
+
for (const k of keys) {
|
|
13
|
+
if (k !== "allowed_domains" && k !== "blocked_domains")
|
|
14
|
+
throw new errors_js_1.UserError(`tools.web_search: unknown option ${JSON.stringify(k)}`);
|
|
15
|
+
const v = options[k];
|
|
16
|
+
if (!Array.isArray(v) || v.length === 0 || v.some((d) => typeof d !== "string")) {
|
|
17
|
+
throw new errors_js_1.UserError(`tools.web_search.${k}: must be a non-empty list of domains`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (keys.length > 1)
|
|
21
|
+
throw new errors_js_1.UserError("tools.web_search: give allowed_domains or blocked_domains, not both");
|
|
22
|
+
}
|
package/dist/compose/tools.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** Built-in (server-side) tools. Listing a tool enables it; unlisted tools keep the server default. */
|
|
2
1
|
export interface BuiltinTool {
|
|
3
2
|
readonly name: string;
|
|
4
3
|
readonly options?: Record<string, unknown>;
|
|
5
4
|
}
|
|
5
|
+
/** Give at most one of `filters.allowedDomains` and `blockedDomains`, and never an empty list. */
|
|
6
6
|
export declare function webSearchTool(opts?: {
|
|
7
7
|
filters?: {
|
|
8
8
|
allowedDomains?: string[] | null;
|
package/dist/compose/tools.js
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/** Built-in (server-side) tools. Listing a tool enables it; unlisted tools keep the server default. */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.subagents = exports.clarify = exports.schedules = exports.todo = exports.codeMode = exports.sandbox = void 0;
|
|
5
4
|
exports.webSearchTool = webSearchTool;
|
|
5
|
+
/**
|
|
6
|
+
* Built-in (server-side) tools. Every built-in is on by default. Passing `tools` to `Agent` makes the list exact:
|
|
7
|
+
* listed built-ins stay on and the rest are turned off. Leave `tools` out to keep the server default.
|
|
8
|
+
*/
|
|
9
|
+
const errors_js_1 = require("./errors.js");
|
|
10
|
+
/** Give at most one of `filters.allowedDomains` and `blockedDomains`, and never an empty list. */
|
|
6
11
|
function webSearchTool(opts = {}) {
|
|
7
|
-
var _a;
|
|
12
|
+
var _a, _b;
|
|
8
13
|
const options = {};
|
|
9
14
|
const allowed = (_a = opts.filters) === null || _a === void 0 ? void 0 : _a.allowedDomains;
|
|
15
|
+
const blocked = (_b = opts.blockedDomains) !== null && _b !== void 0 ? _b : undefined;
|
|
16
|
+
if (allowed !== undefined && allowed !== null && blocked !== undefined) {
|
|
17
|
+
throw new errors_js_1.UserError("webSearchTool: give filters.allowedDomains or blockedDomains, not both");
|
|
18
|
+
}
|
|
19
|
+
if (allowed !== undefined && allowed !== null && allowed.length === 0) {
|
|
20
|
+
throw new errors_js_1.UserError("webSearchTool.filters.allowedDomains: must not be empty (leave it out for no restriction)");
|
|
21
|
+
}
|
|
22
|
+
if (blocked !== undefined && blocked.length === 0) {
|
|
23
|
+
throw new errors_js_1.UserError("webSearchTool.blockedDomains: must not be empty (leave it out for no restriction)");
|
|
24
|
+
}
|
|
10
25
|
if (allowed !== undefined && allowed !== null)
|
|
11
26
|
options["allowed_domains"] = allowed.slice();
|
|
12
|
-
if (
|
|
13
|
-
options["blocked_domains"] =
|
|
27
|
+
if (blocked !== undefined)
|
|
28
|
+
options["blocked_domains"] = blocked.slice();
|
|
14
29
|
const tool = Object.keys(options).length > 0 ? { name: "web_search", options } : { name: "web_search" };
|
|
15
30
|
return tool;
|
|
16
31
|
}
|
|
@@ -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
|
};
|
|
@@ -17,8 +17,11 @@ export interface AgentOptions {
|
|
|
17
17
|
name: string;
|
|
18
18
|
instructions?: string;
|
|
19
19
|
model?: string;
|
|
20
|
+
/** Catalog endpoint to serve `model` from (agent.json `endpoint`). */
|
|
21
|
+
endpoint?: string;
|
|
20
22
|
modelSettings?: ModelSettings;
|
|
21
23
|
fallbackModels?: string[];
|
|
24
|
+
/** Exact list of built-ins to keep on; omit to keep the server default (all on). */
|
|
22
25
|
tools?: BuiltinTool[];
|
|
23
26
|
limits?: Limits;
|
|
24
27
|
metadata?: Record<string, string>;
|
|
@@ -27,9 +30,10 @@ export declare class Agent {
|
|
|
27
30
|
readonly name: string;
|
|
28
31
|
readonly instructions: string;
|
|
29
32
|
readonly model?: string;
|
|
33
|
+
readonly endpoint?: string;
|
|
30
34
|
readonly modelSettings?: ModelSettings;
|
|
31
35
|
readonly fallbackModels?: string[];
|
|
32
|
-
readonly tools
|
|
36
|
+
readonly tools?: readonly BuiltinTool[];
|
|
33
37
|
readonly limits?: Limits;
|
|
34
38
|
readonly metadata?: Record<string, string>;
|
|
35
39
|
constructor(rawOpts: AgentOptions);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NotSupportedError, UserError } from "./errors.js";
|
|
2
2
|
import { settingsFingerprint } from "./fingerprint.js";
|
|
3
|
+
import { BUILTIN_NAMES, checkWebSearchOptions } from "./builtins.js";
|
|
3
4
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
4
5
|
const REASONING = ["off", "none", "low", "medium", "high", "xhigh", "max"];
|
|
5
6
|
const TOOL_CHOICES = ["auto", "none"];
|
|
@@ -71,7 +72,7 @@ const LIMIT_KEYS = [
|
|
|
71
72
|
];
|
|
72
73
|
export class Agent {
|
|
73
74
|
constructor(rawOpts) {
|
|
74
|
-
var _a, _b
|
|
75
|
+
var _a, _b;
|
|
75
76
|
const opts = normalize(rawOpts);
|
|
76
77
|
for (const tool of (_a = opts.tools) !== null && _a !== void 0 ? _a : []) {
|
|
77
78
|
if (tool instanceof Agent) {
|
|
@@ -82,18 +83,28 @@ export class Agent {
|
|
|
82
83
|
this.name = opts.name;
|
|
83
84
|
this.instructions = (_b = opts.instructions) !== null && _b !== void 0 ? _b : "";
|
|
84
85
|
this.model = opts.model;
|
|
86
|
+
this.endpoint = opts.endpoint;
|
|
85
87
|
this.modelSettings = clone(opts.modelSettings);
|
|
86
88
|
this.fallbackModels = clone(opts.fallbackModels);
|
|
87
|
-
this.tools = clone(
|
|
89
|
+
this.tools = clone(opts.tools);
|
|
88
90
|
this.limits = clone(opts.limits);
|
|
89
91
|
this.metadata = clone(opts.metadata);
|
|
90
92
|
this.check();
|
|
91
93
|
deepFreeze(this);
|
|
92
94
|
}
|
|
93
95
|
check() {
|
|
96
|
+
var _a, _b;
|
|
94
97
|
if (typeof this.name !== "string" || !SLUG.test(this.name)) {
|
|
95
98
|
throw new UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
|
|
96
99
|
}
|
|
100
|
+
for (const [key, value] of [["model", this.model], ["endpoint", this.endpoint]]) {
|
|
101
|
+
if (value !== undefined && (typeof value !== "string" || value === "")) {
|
|
102
|
+
throw new UserError(`${key}: must be a non-empty string`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (this.endpoint !== undefined && this.model === undefined) {
|
|
106
|
+
throw new UserError("endpoint: needs model; set the model this endpoint serves");
|
|
107
|
+
}
|
|
97
108
|
const ms = this.modelSettings;
|
|
98
109
|
if (ms !== undefined) {
|
|
99
110
|
if (ms.reasoning !== undefined && REASONING.indexOf(ms.reasoning.effort) === -1) {
|
|
@@ -126,16 +137,33 @@ export class Agent {
|
|
|
126
137
|
throw new UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
|
|
127
138
|
}
|
|
128
139
|
}
|
|
129
|
-
const names = this.tools.map((t) => t.name);
|
|
140
|
+
const names = ((_a = this.tools) !== null && _a !== void 0 ? _a : []).map((t) => t.name);
|
|
141
|
+
for (const n of names) {
|
|
142
|
+
if (BUILTIN_NAMES.indexOf(n) === -1) {
|
|
143
|
+
throw new UserError(`tools: unknown built-in tool ${JSON.stringify(n)} (known: ${BUILTIN_NAMES.join(", ")})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
130
146
|
const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
|
|
131
147
|
if (dupes.length > 0) {
|
|
132
148
|
throw new UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
|
|
133
149
|
}
|
|
150
|
+
for (const t of (_b = this.tools) !== null && _b !== void 0 ? _b : []) {
|
|
151
|
+
if (t.options === undefined || Object.keys(t.options).length === 0)
|
|
152
|
+
continue;
|
|
153
|
+
if (t.name !== "web_search")
|
|
154
|
+
throw new UserError(`tools: ${t.name} takes no options`);
|
|
155
|
+
checkWebSearchOptions(t.options);
|
|
156
|
+
}
|
|
157
|
+
if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
|
|
158
|
+
throw new UserError("tools: codeMode needs sandbox; add sandbox() to tools");
|
|
159
|
+
}
|
|
134
160
|
}
|
|
135
161
|
baseSettings() {
|
|
136
162
|
const out = { version: 1 };
|
|
137
163
|
if (this.model !== undefined)
|
|
138
164
|
out["model"] = this.model;
|
|
165
|
+
if (this.endpoint !== undefined)
|
|
166
|
+
out["endpoint"] = this.endpoint;
|
|
139
167
|
const ms = this.modelSettings;
|
|
140
168
|
if (ms !== undefined) {
|
|
141
169
|
if (ms.reasoning !== undefined)
|
|
@@ -162,10 +190,13 @@ export class Agent {
|
|
|
162
190
|
if (Object.keys(limits).length > 0)
|
|
163
191
|
out["limits"] = limits;
|
|
164
192
|
}
|
|
165
|
-
if (this.tools
|
|
193
|
+
if (this.tools !== undefined) {
|
|
194
|
+
// Built-ins are on by default, so an exact list writes every unlisted one as off.
|
|
166
195
|
const tools = {};
|
|
167
|
-
for (const
|
|
168
|
-
|
|
196
|
+
for (const n of BUILTIN_NAMES) {
|
|
197
|
+
const t = this.tools.find((x) => x.name === n);
|
|
198
|
+
tools[n] = t === undefined ? false
|
|
199
|
+
: t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
|
|
169
200
|
}
|
|
170
201
|
out["builtin_tools"] = tools;
|
|
171
202
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
2
|
+
export declare const BUILTIN_NAMES: readonly ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"];
|
|
3
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
4
|
+
export declare function checkWebSearchOptions(options: Record<string, unknown>): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Internal: built-in tool names and checks shared by tools.ts and agent.ts. Not re-exported from index.ts. */
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
4
|
+
export const BUILTIN_NAMES = ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"];
|
|
5
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
6
|
+
export function checkWebSearchOptions(options) {
|
|
7
|
+
const keys = Object.keys(options);
|
|
8
|
+
for (const k of keys) {
|
|
9
|
+
if (k !== "allowed_domains" && k !== "blocked_domains")
|
|
10
|
+
throw new UserError(`tools.web_search: unknown option ${JSON.stringify(k)}`);
|
|
11
|
+
const v = options[k];
|
|
12
|
+
if (!Array.isArray(v) || v.length === 0 || v.some((d) => typeof d !== "string")) {
|
|
13
|
+
throw new UserError(`tools.web_search.${k}: must be a non-empty list of domains`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (keys.length > 1)
|
|
17
|
+
throw new UserError("tools.web_search: give allowed_domains or blocked_domains, not both");
|
|
18
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** Built-in (server-side) tools. Listing a tool enables it; unlisted tools keep the server default. */
|
|
2
1
|
export interface BuiltinTool {
|
|
3
2
|
readonly name: string;
|
|
4
3
|
readonly options?: Record<string, unknown>;
|
|
5
4
|
}
|
|
5
|
+
/** Give at most one of `filters.allowedDomains` and `blockedDomains`, and never an empty list. */
|
|
6
6
|
export declare function webSearchTool(opts?: {
|
|
7
7
|
filters?: {
|
|
8
8
|
allowedDomains?: string[] | null;
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Built-in (server-side) tools. Every built-in is on by default. Passing `tools` to `Agent` makes the list exact:
|
|
3
|
+
* listed built-ins stay on and the rest are turned off. Leave `tools` out to keep the server default.
|
|
4
|
+
*/
|
|
5
|
+
import { UserError } from "./errors.js";
|
|
6
|
+
/** Give at most one of `filters.allowedDomains` and `blockedDomains`, and never an empty list. */
|
|
2
7
|
export function webSearchTool(opts = {}) {
|
|
3
|
-
var _a;
|
|
8
|
+
var _a, _b;
|
|
4
9
|
const options = {};
|
|
5
10
|
const allowed = (_a = opts.filters) === null || _a === void 0 ? void 0 : _a.allowedDomains;
|
|
11
|
+
const blocked = (_b = opts.blockedDomains) !== null && _b !== void 0 ? _b : undefined;
|
|
12
|
+
if (allowed !== undefined && allowed !== null && blocked !== undefined) {
|
|
13
|
+
throw new UserError("webSearchTool: give filters.allowedDomains or blockedDomains, not both");
|
|
14
|
+
}
|
|
15
|
+
if (allowed !== undefined && allowed !== null && allowed.length === 0) {
|
|
16
|
+
throw new UserError("webSearchTool.filters.allowedDomains: must not be empty (leave it out for no restriction)");
|
|
17
|
+
}
|
|
18
|
+
if (blocked !== undefined && blocked.length === 0) {
|
|
19
|
+
throw new UserError("webSearchTool.blockedDomains: must not be empty (leave it out for no restriction)");
|
|
20
|
+
}
|
|
6
21
|
if (allowed !== undefined && allowed !== null)
|
|
7
22
|
options["allowed_domains"] = allowed.slice();
|
|
8
|
-
if (
|
|
9
|
-
options["blocked_domains"] =
|
|
23
|
+
if (blocked !== undefined)
|
|
24
|
+
options["blocked_domains"] = blocked.slice();
|
|
10
25
|
const tool = Object.keys(options).length > 0 ? { name: "web_search", options } : { name: "web_search" };
|
|
11
26
|
return tool;
|
|
12
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sarvam-agents-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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/agent.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NotSupportedError, UserError } from "./errors.js";
|
|
2
2
|
import { settingsFingerprint } from "./fingerprint.js";
|
|
3
|
+
import { BUILTIN_NAMES, checkWebSearchOptions } from "./builtins.js";
|
|
3
4
|
import { BuiltinTool } from "./tools.js";
|
|
4
5
|
|
|
5
6
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
@@ -24,8 +25,11 @@ export interface AgentOptions {
|
|
|
24
25
|
name: string;
|
|
25
26
|
instructions?: string;
|
|
26
27
|
model?: string;
|
|
28
|
+
/** Catalog endpoint to serve `model` from (agent.json `endpoint`). */
|
|
29
|
+
endpoint?: string;
|
|
27
30
|
modelSettings?: ModelSettings;
|
|
28
31
|
fallbackModels?: string[];
|
|
32
|
+
/** Exact list of built-ins to keep on; omit to keep the server default (all on). */
|
|
29
33
|
tools?: BuiltinTool[];
|
|
30
34
|
limits?: Limits;
|
|
31
35
|
metadata?: Record<string, string>;
|
|
@@ -104,9 +108,10 @@ export class Agent {
|
|
|
104
108
|
readonly name: string;
|
|
105
109
|
readonly instructions: string;
|
|
106
110
|
readonly model?: string;
|
|
111
|
+
readonly endpoint?: string;
|
|
107
112
|
readonly modelSettings?: ModelSettings;
|
|
108
113
|
readonly fallbackModels?: string[];
|
|
109
|
-
readonly tools
|
|
114
|
+
readonly tools?: readonly BuiltinTool[];
|
|
110
115
|
readonly limits?: Limits;
|
|
111
116
|
readonly metadata?: Record<string, string>;
|
|
112
117
|
|
|
@@ -121,9 +126,10 @@ export class Agent {
|
|
|
121
126
|
this.name = opts.name;
|
|
122
127
|
this.instructions = opts.instructions ?? "";
|
|
123
128
|
this.model = opts.model;
|
|
129
|
+
this.endpoint = opts.endpoint;
|
|
124
130
|
this.modelSettings = clone(opts.modelSettings);
|
|
125
131
|
this.fallbackModels = clone(opts.fallbackModels);
|
|
126
|
-
this.tools = clone(opts.tools
|
|
132
|
+
this.tools = clone(opts.tools);
|
|
127
133
|
this.limits = clone(opts.limits);
|
|
128
134
|
this.metadata = clone(opts.metadata);
|
|
129
135
|
this.check();
|
|
@@ -134,6 +140,14 @@ export class Agent {
|
|
|
134
140
|
if (typeof this.name !== "string" || !SLUG.test(this.name)) {
|
|
135
141
|
throw new UserError(`name: ${JSON.stringify(this.name)} must match ${SLUG.source}`);
|
|
136
142
|
}
|
|
143
|
+
for (const [key, value] of [["model", this.model], ["endpoint", this.endpoint]] as [string, unknown][]) {
|
|
144
|
+
if (value !== undefined && (typeof value !== "string" || value === "")) {
|
|
145
|
+
throw new UserError(`${key}: must be a non-empty string`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (this.endpoint !== undefined && this.model === undefined) {
|
|
149
|
+
throw new UserError("endpoint: needs model; set the model this endpoint serves");
|
|
150
|
+
}
|
|
137
151
|
const ms = this.modelSettings;
|
|
138
152
|
if (ms !== undefined) {
|
|
139
153
|
if (ms.reasoning !== undefined && REASONING.indexOf(ms.reasoning.effort) === -1) {
|
|
@@ -168,16 +182,30 @@ export class Agent {
|
|
|
168
182
|
throw new UserError(`metadata: keys starting with 'sdk_' are reserved (${bad.join(", ")})`);
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
|
-
const names = this.tools.map((t) => t.name);
|
|
185
|
+
const names = (this.tools ?? []).map((t) => t.name);
|
|
186
|
+
for (const n of names) {
|
|
187
|
+
if ((BUILTIN_NAMES as readonly string[]).indexOf(n) === -1) {
|
|
188
|
+
throw new UserError(`tools: unknown built-in tool ${JSON.stringify(n)} (known: ${BUILTIN_NAMES.join(", ")})`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
172
191
|
const dupes = Array.from(new Set(names.filter((n, i) => names.indexOf(n) !== i))).sort();
|
|
173
192
|
if (dupes.length > 0) {
|
|
174
193
|
throw new UserError(`tools: duplicate built-in tool(s): ${dupes.join(", ")}`);
|
|
175
194
|
}
|
|
195
|
+
for (const t of this.tools ?? []) {
|
|
196
|
+
if (t.options === undefined || Object.keys(t.options).length === 0) continue;
|
|
197
|
+
if (t.name !== "web_search") throw new UserError(`tools: ${t.name} takes no options`);
|
|
198
|
+
checkWebSearchOptions(t.options);
|
|
199
|
+
}
|
|
200
|
+
if (names.indexOf("code_mode") !== -1 && names.indexOf("sandbox") === -1) {
|
|
201
|
+
throw new UserError("tools: codeMode needs sandbox; add sandbox() to tools");
|
|
202
|
+
}
|
|
176
203
|
}
|
|
177
204
|
|
|
178
205
|
private baseSettings(): Record<string, unknown> {
|
|
179
206
|
const out: Record<string, unknown> = { version: 1 };
|
|
180
207
|
if (this.model !== undefined) out["model"] = this.model;
|
|
208
|
+
if (this.endpoint !== undefined) out["endpoint"] = this.endpoint;
|
|
181
209
|
const ms = this.modelSettings;
|
|
182
210
|
if (ms !== undefined) {
|
|
183
211
|
if (ms.reasoning !== undefined) out["reasoning"] = ms.reasoning.effort;
|
|
@@ -197,10 +225,13 @@ export class Agent {
|
|
|
197
225
|
}
|
|
198
226
|
if (Object.keys(limits).length > 0) out["limits"] = limits;
|
|
199
227
|
}
|
|
200
|
-
if (this.tools
|
|
228
|
+
if (this.tools !== undefined) {
|
|
229
|
+
// Built-ins are on by default, so an exact list writes every unlisted one as off.
|
|
201
230
|
const tools: Record<string, unknown> = {};
|
|
202
|
-
for (const
|
|
203
|
-
|
|
231
|
+
for (const n of BUILTIN_NAMES) {
|
|
232
|
+
const t = this.tools.find((x) => x.name === n);
|
|
233
|
+
tools[n] = t === undefined ? false
|
|
234
|
+
: t.options !== undefined && Object.keys(t.options).length > 0 ? clone(t.options) : true;
|
|
204
235
|
}
|
|
205
236
|
out["builtin_tools"] = tools;
|
|
206
237
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Internal: built-in tool names and checks shared by tools.ts and agent.ts. Not re-exported from index.ts. */
|
|
2
|
+
import { UserError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
/** The agent.json builtin_tools switches, in schema order. */
|
|
5
|
+
export const BUILTIN_NAMES = ["web_search", "sandbox", "code_mode", "todo", "schedules", "clarify", "subagents"] as const;
|
|
6
|
+
|
|
7
|
+
/** The server's web search rules, for options built by hand (`{ name: "web_search", options }`). */
|
|
8
|
+
export function checkWebSearchOptions(options: Record<string, unknown>): void {
|
|
9
|
+
const keys = Object.keys(options);
|
|
10
|
+
for (const k of keys) {
|
|
11
|
+
if (k !== "allowed_domains" && k !== "blocked_domains") throw new UserError(`tools.web_search: unknown option ${JSON.stringify(k)}`);
|
|
12
|
+
const v = options[k];
|
|
13
|
+
if (!Array.isArray(v) || v.length === 0 || v.some((d) => typeof d !== "string")) {
|
|
14
|
+
throw new UserError(`tools.web_search.${k}: must be a non-empty list of domains`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (keys.length > 1) throw new UserError("tools.web_search: give allowed_domains or blocked_domains, not both");
|
|
18
|
+
}
|
|
19
|
+
|
package/src/compose/tools.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Built-in (server-side) tools. Every built-in is on by default. Passing `tools` to `Agent` makes the list exact:
|
|
3
|
+
* listed built-ins stay on and the rest are turned off. Leave `tools` out to keep the server default.
|
|
4
|
+
*/
|
|
5
|
+
import { UserError } from "./errors.js";
|
|
2
6
|
|
|
3
7
|
export interface BuiltinTool {
|
|
4
8
|
readonly name: string;
|
|
5
9
|
readonly options?: Record<string, unknown>;
|
|
6
10
|
}
|
|
7
11
|
|
|
12
|
+
/** Give at most one of `filters.allowedDomains` and `blockedDomains`, and never an empty list. */
|
|
8
13
|
export function webSearchTool(opts: {
|
|
9
14
|
filters?: { allowedDomains?: string[] | null };
|
|
10
15
|
blockedDomains?: string[];
|
|
11
16
|
} = {}): BuiltinTool {
|
|
12
17
|
const options: Record<string, unknown> = {};
|
|
13
18
|
const allowed = opts.filters?.allowedDomains;
|
|
19
|
+
const blocked = opts.blockedDomains ?? undefined;
|
|
20
|
+
if (allowed !== undefined && allowed !== null && blocked !== undefined) {
|
|
21
|
+
throw new UserError("webSearchTool: give filters.allowedDomains or blockedDomains, not both");
|
|
22
|
+
}
|
|
23
|
+
if (allowed !== undefined && allowed !== null && allowed.length === 0) {
|
|
24
|
+
throw new UserError("webSearchTool.filters.allowedDomains: must not be empty (leave it out for no restriction)");
|
|
25
|
+
}
|
|
26
|
+
if (blocked !== undefined && blocked.length === 0) {
|
|
27
|
+
throw new UserError("webSearchTool.blockedDomains: must not be empty (leave it out for no restriction)");
|
|
28
|
+
}
|
|
14
29
|
if (allowed !== undefined && allowed !== null) options["allowed_domains"] = allowed.slice();
|
|
15
|
-
if (
|
|
30
|
+
if (blocked !== undefined) options["blocked_domains"] = blocked.slice();
|
|
16
31
|
const tool: BuiltinTool = Object.keys(options).length > 0 ? { name: "web_search", options } : { name: "web_search" };
|
|
17
32
|
return tool;
|
|
18
33
|
}
|