@agent-api/sdk 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +26 -4
  3. package/dist/client.d.ts +4 -1
  4. package/dist/client.js +5 -1
  5. package/dist/index.d.ts +1 -5
  6. package/dist/index.js +1 -3
  7. package/dist/local-skills.js +13 -1
  8. package/dist/node-client.d.ts +6 -0
  9. package/dist/node-client.js +7 -0
  10. package/dist/node.d.ts +8 -0
  11. package/dist/node.js +6 -0
  12. package/dist/resources/auth.d.ts +3 -1
  13. package/dist/resources/auth.js +18 -0
  14. package/dist/resources/skills-node.d.ts +7 -0
  15. package/dist/resources/skills-node.js +156 -0
  16. package/dist/resources/skills.d.ts +1 -3
  17. package/dist/resources/skills.js +0 -153
  18. package/dist/types/auth.d.ts +3 -0
  19. package/dist/types/responses.d.ts +4 -0
  20. package/dist/version.d.ts +2 -2
  21. package/dist/version.js +1 -1
  22. package/dist-cjs/client.js +72 -0
  23. package/dist-cjs/errors.js +146 -0
  24. package/dist-cjs/index.js +52 -0
  25. package/dist-cjs/internal/env.js +7 -0
  26. package/dist-cjs/internal/http.js +108 -0
  27. package/dist-cjs/internal/output-text.js +15 -0
  28. package/dist-cjs/internal/query.js +13 -0
  29. package/dist-cjs/local/context.js +158 -0
  30. package/dist-cjs/local/core.js +1077 -0
  31. package/dist-cjs/local/index.js +19 -0
  32. package/dist-cjs/local/tools.js +380 -0
  33. package/dist-cjs/local-functions.js +37 -0
  34. package/dist-cjs/local-skills.js +308 -0
  35. package/dist-cjs/node-client.js +11 -0
  36. package/dist-cjs/node.js +32 -0
  37. package/dist-cjs/package.json +3 -0
  38. package/dist-cjs/pagination.js +43 -0
  39. package/dist-cjs/preset-tools.js +91 -0
  40. package/dist-cjs/resources/auth.js +111 -0
  41. package/dist-cjs/resources/models.js +13 -0
  42. package/dist-cjs/resources/presets.js +13 -0
  43. package/dist-cjs/resources/responses.js +58 -0
  44. package/dist-cjs/resources/skills-node.js +193 -0
  45. package/dist-cjs/resources/skills.js +112 -0
  46. package/dist-cjs/resources/tools.js +13 -0
  47. package/dist-cjs/resources/volumes.js +114 -0
  48. package/dist-cjs/streaming.js +42 -0
  49. package/dist-cjs/tool-validation.js +18 -0
  50. package/dist-cjs/types/auth.js +2 -0
  51. package/dist-cjs/types/catalog.js +2 -0
  52. package/dist-cjs/types/common.js +2 -0
  53. package/dist-cjs/types/index.js +25 -0
  54. package/dist-cjs/types/input.js +2 -0
  55. package/dist-cjs/types/responses.js +2 -0
  56. package/dist-cjs/types/skills.js +2 -0
  57. package/dist-cjs/types/streaming.js +2 -0
  58. package/dist-cjs/types/tools.js +2 -0
  59. package/dist-cjs/types/volumes.js +2 -0
  60. package/dist-cjs/version.js +5 -0
  61. package/package.json +20 -5
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core.js"), exports);
18
+ __exportStar(require("./context.js"), exports);
19
+ __exportStar(require("./tools.js"), exports);
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalWorkspaceDriver = void 0;
4
+ exports.createLocalWorkspaceToolRegistry = createLocalWorkspaceToolRegistry;
5
+ exports.localWorkspaceToolDefinition = localWorkspaceToolDefinition;
6
+ exports.localWorkspaceToolInstructions = localWorkspaceToolInstructions;
7
+ const context_js_1 = require("./context.js");
8
+ class LocalWorkspaceDriver {
9
+ workspace;
10
+ accessMode;
11
+ constructor(workspace, options = {}) {
12
+ this.workspace = workspace;
13
+ this.accessMode = options.accessMode ?? "approval";
14
+ }
15
+ async dispatch(args) {
16
+ const action = workspaceAction(args);
17
+ switch (action) {
18
+ case "summarize":
19
+ return localToolResult(action, localSummaryResult(await this.workspace.summarize(summaryArgs(args))));
20
+ case "list":
21
+ return localToolResult(action, await this.workspace.listEntries(optionalStringArg(args, "path") ?? ".", listArgs(args)));
22
+ case "search":
23
+ return localToolResult(action, await this.workspace.searchEntries(searchEntriesArgs(args)));
24
+ case "grep":
25
+ return localToolResult(action, await this.workspace.grep(grepArgs(args)));
26
+ case "read":
27
+ return localToolResult(action, await this.workspace.readFile(stringArg(args, "path"), readFileArgs(args)));
28
+ case "read_lines":
29
+ return localToolResult(action, await this.workspace.readLines(stringArg(args, "path"), readLinesArgs(args)));
30
+ case "context":
31
+ return localToolResult(action, await (0, context_js_1.createLocalContextPackage)(this.workspace, contextPackageArgs(args)));
32
+ case "snapshot":
33
+ return localToolResult(action, await this.workspace.snapshot(snapshotArgs(args)));
34
+ case "classify_path":
35
+ return localToolResult(action, this.workspace.classifyPath(stringArg(args, "path")));
36
+ case "preview_edits":
37
+ return localToolResult(action, await this.workspace.previewEdits(editsArg(args)));
38
+ case "apply_edits":
39
+ return await this.dispatchApplyEdits(args);
40
+ case "write":
41
+ return await this.dispatchWrite(args);
42
+ case "mkdir":
43
+ return await this.dispatchMkdir(args);
44
+ case "delete":
45
+ return await this.dispatchDelete(args);
46
+ default:
47
+ throw new Error(`unsupported local_workspace action: ${action}`);
48
+ }
49
+ }
50
+ requiresApproval(args) {
51
+ if (this.accessMode === "full") {
52
+ return false;
53
+ }
54
+ return mutatingLocalWorkspaceActions.has(workspaceAction(args));
55
+ }
56
+ async dispatchApplyEdits(args) {
57
+ const edits = editsArg(args);
58
+ if (this.accessMode !== "full") {
59
+ return approvalRequired("apply_edits", args, await this.workspace.previewEdits(edits));
60
+ }
61
+ return localToolResult("apply_edits", await this.workspace.applyEdits(edits));
62
+ }
63
+ async dispatchWrite(args) {
64
+ if (this.accessMode !== "full") {
65
+ return approvalRequired("write", args);
66
+ }
67
+ return localToolResult("write", await this.workspace.writeText(stringArg(args, "path"), stringArg(args, "content")));
68
+ }
69
+ async dispatchMkdir(args) {
70
+ if (this.accessMode !== "full") {
71
+ return approvalRequired("mkdir", args);
72
+ }
73
+ return localToolResult("mkdir", await this.workspace.createDirectory(stringArg(args, "path")));
74
+ }
75
+ async dispatchDelete(args) {
76
+ if (this.accessMode !== "full") {
77
+ return approvalRequired("delete", args);
78
+ }
79
+ return localToolResult("delete", await this.workspace.deletePath(stringArg(args, "path")));
80
+ }
81
+ }
82
+ exports.LocalWorkspaceDriver = LocalWorkspaceDriver;
83
+ function createLocalWorkspaceToolRegistry(workspace, options = {}) {
84
+ const toolName = options.toolName ?? "local_workspace";
85
+ const driver = new LocalWorkspaceDriver(workspace, { accessMode: options.accessMode });
86
+ const definition = localWorkspaceToolDefinition(toolName);
87
+ return {
88
+ workspace,
89
+ accessMode: driver.accessMode,
90
+ toolName,
91
+ definitions: () => [{ ...definition }],
92
+ handlers: () => ({ [toolName]: (args) => driver.dispatch(args) }),
93
+ execute: async (name, args) => {
94
+ if (name !== toolName) {
95
+ throw new Error(`unknown local workspace tool: ${name}`);
96
+ }
97
+ return await driver.dispatch(args);
98
+ },
99
+ requiresApproval: (name, args = {}) => name === toolName && driver.requiresApproval(args),
100
+ };
101
+ }
102
+ function localWorkspaceToolDefinition(name = "local_workspace") {
103
+ return {
104
+ type: "function",
105
+ name,
106
+ description: localWorkspaceToolDescription,
107
+ parameters: localWorkspaceToolParameters(),
108
+ strict: false,
109
+ };
110
+ }
111
+ function localWorkspaceToolInstructions() {
112
+ return localWorkspaceToolDescription;
113
+ }
114
+ const localWorkspaceActions = [
115
+ "summarize",
116
+ "list",
117
+ "search",
118
+ "grep",
119
+ "read",
120
+ "read_lines",
121
+ "context",
122
+ "snapshot",
123
+ "classify_path",
124
+ "preview_edits",
125
+ "apply_edits",
126
+ "write",
127
+ "mkdir",
128
+ "delete",
129
+ ];
130
+ const mutatingLocalWorkspaceActions = new Set([
131
+ "apply_edits",
132
+ "write",
133
+ "mkdir",
134
+ "delete",
135
+ ]);
136
+ const localWorkspaceToolDescription = [
137
+ "Inspect and modify the selected local workspace through one model-facing primitive.",
138
+ "Use action=list/search/grep/summarize/context to discover files, read/read_lines for file content, preview_edits before edits, and apply_edits/write/mkdir/delete only when mutation is intended.",
139
+ "In approval mode, mutating actions return requires_approval with a safe preview instead of changing files. In full mode, mutating actions execute immediately.",
140
+ "Paths are relative to the selected local workspace; never use absolute paths.",
141
+ ].join(" ");
142
+ function localWorkspaceToolParameters() {
143
+ return objectSchema({
144
+ action: {
145
+ type: "string",
146
+ enum: localWorkspaceActions,
147
+ description: "Workspace operation. Prefer summarize/list/search/grep before reading or editing. Prefer read_lines and apply_edits for source changes.",
148
+ },
149
+ path: stringSchema("Relative path. File path for read/write/delete/edit actions; directory base for list/search/grep/summarize/context/snapshot."),
150
+ query: stringSchema("Path/name query for search, or optional context query."),
151
+ pattern: stringSchema("Literal text pattern for grep."),
152
+ content: stringSchema("Text content for write."),
153
+ start_line: integerSchema("1-based start line for read_lines and edit entries."),
154
+ end_line: integerSchema("1-based inclusive end line; omit or 0 for EOF when supported."),
155
+ replacement: stringSchema("Replacement text for simple single edit flows."),
156
+ edits: {
157
+ type: "array",
158
+ minItems: 1,
159
+ description: "Line edits for preview_edits/apply_edits.",
160
+ items: objectSchema({
161
+ path: requiredStringSchema("Relative file path."),
162
+ start_line: requiredIntegerSchema("1-based start line."),
163
+ end_line: integerSchema("1-based inclusive end line."),
164
+ replacement: stringSchema("Replacement text. Empty string deletes the line range."),
165
+ expected_sha256: stringSchema("Optional expected SHA-256 for conflict detection."),
166
+ }, ["path", "start_line"]),
167
+ },
168
+ options: objectSchema({
169
+ recursive: booleanSchema("List recursively."),
170
+ include_directories: booleanSchema("Include directories in list results."),
171
+ max_depth: integerSchema("Maximum recursive list depth."),
172
+ limit: integerSchema("Maximum entries or matches."),
173
+ max_files: integerSchema("Maximum files to scan or package."),
174
+ max_bytes: integerSchema("Maximum total bytes to read/package."),
175
+ max_bytes_per_file: integerSchema("Maximum bytes per file."),
176
+ max_previews: integerSchema("Maximum summary previews."),
177
+ include_content: booleanSchema("Include file contents in context packages."),
178
+ include_summary: booleanSchema("Include workspace summary in context packages."),
179
+ include_search: booleanSchema("Include grep results in context packages when query is set."),
180
+ include_secrets: booleanSchema("Include likely secret file contents in context packages."),
181
+ hash: booleanSchema("Include SHA-256 hashes in snapshots."),
182
+ }),
183
+ }, ["action"]);
184
+ }
185
+ function workspaceAction(args) {
186
+ const value = stringArg(args, "action").trim().toLowerCase();
187
+ if (!localWorkspaceActions.includes(value)) {
188
+ throw new Error(`unsupported local_workspace action: ${value}`);
189
+ }
190
+ return value;
191
+ }
192
+ function summaryArgs(args) {
193
+ return {
194
+ path: optionalStringArg(args, "path"),
195
+ maxFiles: optionalNumberArg(args, "maxFiles", "max_files"),
196
+ maxPreviews: optionalNumberArg(args, "maxPreviews", "max_previews"),
197
+ };
198
+ }
199
+ function grepArgs(args) {
200
+ return {
201
+ pattern: stringArg(args, "pattern"),
202
+ path: optionalStringArg(args, "path"),
203
+ limit: optionalNumberArg(args, "limit"),
204
+ maxFiles: optionalNumberArg(args, "maxFiles", "max_files"),
205
+ };
206
+ }
207
+ function listArgs(args) {
208
+ return {
209
+ recursive: optionalBooleanArg(args, "recursive"),
210
+ includeDirectories: optionalBooleanArg(args, "includeDirectories", "include_directories"),
211
+ maxDepth: optionalNumberArg(args, "maxDepth", "max_depth"),
212
+ };
213
+ }
214
+ function searchEntriesArgs(args) {
215
+ return {
216
+ query: stringArg(args, "query"),
217
+ path: optionalStringArg(args, "path"),
218
+ limit: optionalNumberArg(args, "limit"),
219
+ };
220
+ }
221
+ function readFileArgs(args) {
222
+ return {
223
+ maxBytes: optionalNumberArg(args, "maxBytes", "max_bytes"),
224
+ };
225
+ }
226
+ function readLinesArgs(args) {
227
+ return {
228
+ startLine: numberArg(args, "startLine", "start_line"),
229
+ endLine: optionalNumberArg(args, "endLine", "end_line"),
230
+ maxBytes: optionalNumberArg(args, "maxBytes", "max_bytes"),
231
+ };
232
+ }
233
+ function snapshotArgs(args) {
234
+ return {
235
+ path: optionalStringArg(args, "path"),
236
+ hash: optionalBooleanArg(args, "hash"),
237
+ maxBytesPerFile: optionalNumberArg(args, "maxBytesPerFile", "max_bytes_per_file"),
238
+ };
239
+ }
240
+ function contextPackageArgs(args) {
241
+ return {
242
+ path: optionalStringArg(args, "path"),
243
+ query: optionalStringArg(args, "query"),
244
+ maxFiles: optionalNumberArg(args, "maxFiles", "max_files"),
245
+ maxBytes: optionalNumberArg(args, "maxBytes", "max_bytes"),
246
+ maxBytesPerFile: optionalNumberArg(args, "maxBytesPerFile", "max_bytes_per_file"),
247
+ includeContent: optionalBooleanArg(args, "includeContent", "include_content"),
248
+ includeSummary: optionalBooleanArg(args, "includeSummary", "include_summary"),
249
+ includeSearch: optionalBooleanArg(args, "includeSearch", "include_search"),
250
+ includeSecrets: optionalBooleanArg(args, "includeSecrets", "include_secrets"),
251
+ };
252
+ }
253
+ function editsArg(args) {
254
+ const edits = args.edits;
255
+ if (Array.isArray(edits) && edits.length > 0) {
256
+ return edits.map((edit) => {
257
+ if (!edit || typeof edit !== "object") {
258
+ throw new Error("each edit must be an object");
259
+ }
260
+ return editArg(edit);
261
+ });
262
+ }
263
+ if (typeof args.path === "string" && typeof (args.startLine ?? args.start_line) === "number") {
264
+ return [editArg(args)];
265
+ }
266
+ throw new Error("edits must be a non-empty array");
267
+ }
268
+ function editArg(record) {
269
+ return {
270
+ path: stringArg(record, "path"),
271
+ startLine: numberArg(record, "startLine", "start_line"),
272
+ endLine: optionalNumberArg(record, "endLine", "end_line"),
273
+ replacement: typeof record.replacement === "string" ? record.replacement : "",
274
+ expectedSha256: optionalStringArg(record, "expectedSha256", "expected_sha256"),
275
+ };
276
+ }
277
+ function localSummaryResult(summary) {
278
+ return summary;
279
+ }
280
+ function localToolResult(action, value) {
281
+ const result = value;
282
+ if (result && typeof result === "object" && !Array.isArray(result)) {
283
+ return { ok: true, action, ...result };
284
+ }
285
+ return { ok: true, action, result };
286
+ }
287
+ function stringArg(args, key, alternateKey) {
288
+ const direct = args[key] ?? (alternateKey ? args[alternateKey] : undefined);
289
+ const fromOptions = args.options && typeof args.options === "object"
290
+ ? args.options[key] ?? (alternateKey ? args.options[alternateKey] : undefined)
291
+ : undefined;
292
+ const value = direct ?? fromOptions;
293
+ if (typeof value !== "string" || !value.trim()) {
294
+ throw new Error(`${key} must be a non-empty string`);
295
+ }
296
+ return value;
297
+ }
298
+ function optionalStringArg(args, key, alternateKey) {
299
+ const direct = args[key] ?? (alternateKey ? args[alternateKey] : undefined);
300
+ const fromOptions = args.options && typeof args.options === "object"
301
+ ? args.options[key] ?? (alternateKey ? args.options[alternateKey] : undefined)
302
+ : undefined;
303
+ const value = direct ?? fromOptions;
304
+ if (value == null || value === "")
305
+ return undefined;
306
+ if (typeof value !== "string") {
307
+ throw new Error(`${key} must be a string`);
308
+ }
309
+ return value;
310
+ }
311
+ function numberArg(args, key, alternateKey) {
312
+ const direct = args[key] ?? (alternateKey ? args[alternateKey] : undefined);
313
+ const fromOptions = args.options && typeof args.options === "object"
314
+ ? args.options[key] ?? (alternateKey ? args.options[alternateKey] : undefined)
315
+ : undefined;
316
+ const value = direct ?? fromOptions;
317
+ if (typeof value !== "number" || !Number.isFinite(value)) {
318
+ throw new Error(`${key} must be a number`);
319
+ }
320
+ return Math.trunc(value);
321
+ }
322
+ function optionalNumberArg(args, key, alternateKey) {
323
+ const direct = args[key] ?? (alternateKey ? args[alternateKey] : undefined);
324
+ const fromOptions = args.options && typeof args.options === "object"
325
+ ? args.options[key] ?? (alternateKey ? args.options[alternateKey] : undefined)
326
+ : undefined;
327
+ const value = direct ?? fromOptions;
328
+ if (value == null)
329
+ return undefined;
330
+ if (typeof value !== "number" || !Number.isFinite(value)) {
331
+ throw new Error(`${key} must be a number`);
332
+ }
333
+ return Math.trunc(value);
334
+ }
335
+ function optionalBooleanArg(args, key, alternateKey) {
336
+ const direct = args[key] ?? (alternateKey ? args[alternateKey] : undefined);
337
+ const fromOptions = args.options && typeof args.options === "object"
338
+ ? args.options[key] ?? (alternateKey ? args.options[alternateKey] : undefined)
339
+ : undefined;
340
+ const value = direct ?? fromOptions;
341
+ if (value == null)
342
+ return undefined;
343
+ if (typeof value !== "boolean") {
344
+ throw new Error(`${key} must be a boolean`);
345
+ }
346
+ return value;
347
+ }
348
+ function approvalRequired(action, args, preview) {
349
+ return {
350
+ ok: false,
351
+ action,
352
+ requires_approval: true,
353
+ arguments: args,
354
+ preview,
355
+ message: `local_workspace action ${action} requires approval`,
356
+ };
357
+ }
358
+ function objectSchema(properties, required = []) {
359
+ return {
360
+ type: "object",
361
+ properties,
362
+ required,
363
+ additionalProperties: false,
364
+ };
365
+ }
366
+ function stringSchema(description) {
367
+ return { type: "string", description };
368
+ }
369
+ function requiredStringSchema(description) {
370
+ return stringSchema(description);
371
+ }
372
+ function integerSchema(description) {
373
+ return { type: "integer", description };
374
+ }
375
+ function booleanSchema(description) {
376
+ return { type: "boolean", description };
377
+ }
378
+ function requiredIntegerSchema(description) {
379
+ return integerSchema(description);
380
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pendingFunctionCalls = pendingFunctionCalls;
4
+ exports.functionCallOutputInput = functionCallOutputInput;
5
+ exports.runLocalFunctionHandlers = runLocalFunctionHandlers;
6
+ /** Pending client-executed function calls from a requires_action response. */
7
+ function pendingFunctionCalls(response) {
8
+ if (response.status !== "requires_action") {
9
+ return [];
10
+ }
11
+ return response.output.filter((item) => item.type === "function_call");
12
+ }
13
+ function functionCallOutputInput(callID, output) {
14
+ return {
15
+ type: "function_call_output",
16
+ call_id: callID,
17
+ output: typeof output === "string" ? output : JSON.stringify(output),
18
+ };
19
+ }
20
+ /** Run local handlers for pending function calls and return function_call_output input items. */
21
+ async function runLocalFunctionHandlers(response, handlers) {
22
+ const pending = pendingFunctionCalls(response);
23
+ const outputs = [];
24
+ for (const call of pending) {
25
+ const handler = handlers[call.name];
26
+ if (!handler) {
27
+ throw new Error(`no local handler registered for function ${call.name}`);
28
+ }
29
+ let args = {};
30
+ if (call.arguments) {
31
+ args = JSON.parse(call.arguments);
32
+ }
33
+ const result = await handler(args);
34
+ outputs.push(functionCallOutputInput(call.call_id, result));
35
+ }
36
+ return outputs;
37
+ }