@agent-api/sdk 1.1.2 → 1.1.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/README.md +26 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/preset-tools.d.ts +53 -0
- package/dist/preset-tools.js +85 -0
- package/dist/resources/responses.js +2 -0
- package/dist/tool-validation.d.ts +2 -0
- package/dist/tool-validation.js +15 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Production JavaScript/TypeScript SDK for the Managed Agent API.
|
|
4
4
|
|
|
5
|
-
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.1.
|
|
5
|
+
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.1.3)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -97,6 +97,31 @@ const response = await client.agent.create({
|
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
## Preset tools and local/client tools
|
|
101
|
+
|
|
102
|
+
`tools` is the concrete model-visible tool list. Tool names must be unique because model tool calls select tools by name. When you send `preset` and `tools` together, the explicit `tools` array replaces the preset's default tools. Hybrid apps that add local function tools should resolve the preset defaults first, merge in their local tools, then pass the merged array. The SDK rejects duplicate tool names before submitting requests.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { resolvePresetTools } from "@agent-api/sdk";
|
|
106
|
+
import { createLocalWorkspaceToolRegistry, LocalWorkspace } from "@agent-api/sdk/local";
|
|
107
|
+
|
|
108
|
+
const workspace = new LocalWorkspace("/path/to/project", { trusted: true });
|
|
109
|
+
const registry = createLocalWorkspaceToolRegistry(workspace);
|
|
110
|
+
|
|
111
|
+
const { tools } = await resolvePresetTools(client, {
|
|
112
|
+
preset: "pro-search",
|
|
113
|
+
tools: registry.definitions(),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const response = await client.agent.create({
|
|
117
|
+
preset: "pro-search",
|
|
118
|
+
input: "Research the topic and update local notes.",
|
|
119
|
+
tools,
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
For long-running apps, cache `client.presets.list()` and `client.tools.list()` and refresh them periodically. Use `resolvePresetToolsFromCatalog()` with cached catalogs when you want deterministic request construction without fetching on every turn.
|
|
124
|
+
|
|
100
125
|
## Skills
|
|
101
126
|
|
|
102
127
|
`localSkillFromDirectory()` reads `SKILL.md` into the descriptor for initial local-skill auto-focus; later focused reads still use the local skill tool bridge.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { APIError, APIConnectionError, APIStatusError, AuthenticationError, BadR
|
|
|
5
5
|
export * from "./types/index.js";
|
|
6
6
|
export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers, } from "./local-functions.js";
|
|
7
7
|
export type { LocalFunctionHandler, LocalFunctionHandlers } from "./local-functions.js";
|
|
8
|
+
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
9
|
+
export type { PresetToolCatalogClient, ResolvePresetToolsOptions, ResolvePresetToolsResult, UnknownPresetToolBehavior, } from "./preset-tools.js";
|
|
8
10
|
export { LocalWorkspaceDriver, createLocalWorkspaceToolRegistry, localWorkspaceToolDefinition, localWorkspaceToolInstructions, } from "./local/tools.js";
|
|
9
11
|
export type { LocalWorkspaceAction, LocalWorkspaceAccessMode, LocalWorkspaceToolRegistry, LocalWorkspaceToolRegistryOptions, } from "./local/tools.js";
|
|
10
12
|
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { Page, collectPage } from "./pagination.js";
|
|
|
3
3
|
export { APIError, APIConnectionError, APIStatusError, AuthenticationError, BadRequestError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, isRetryableStatus, parseResponseError, } from "./errors.js";
|
|
4
4
|
export * from "./types/index.js";
|
|
5
5
|
export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers, } from "./local-functions.js";
|
|
6
|
+
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
6
7
|
export { LocalWorkspaceDriver, createLocalWorkspaceToolRegistry, localWorkspaceToolDefinition, localWorkspaceToolInstructions, } from "./local/tools.js";
|
|
7
8
|
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
8
9
|
export { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ListPresetsResponse, Preset } from "./types/catalog.js";
|
|
2
|
+
import type { ListToolsResponse, PublicTool, Tool } from "./types/tools.js";
|
|
3
|
+
export interface PresetToolCatalogClient {
|
|
4
|
+
presets: {
|
|
5
|
+
list(): Promise<ListPresetsResponse>;
|
|
6
|
+
};
|
|
7
|
+
tools: {
|
|
8
|
+
list(): Promise<ListToolsResponse>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type UnknownPresetToolBehavior = "stub" | "omit" | "error";
|
|
12
|
+
export interface ResolvePresetToolsOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Preset id whose policy.allowed_tools should be resolved.
|
|
15
|
+
*/
|
|
16
|
+
preset: string;
|
|
17
|
+
/**
|
|
18
|
+
* Additional caller/client tools to append after the preset tools.
|
|
19
|
+
*/
|
|
20
|
+
tools?: readonly Tool[];
|
|
21
|
+
/**
|
|
22
|
+
* Optional pre-fetched preset catalog. Use this when your app caches discovery
|
|
23
|
+
* responses and wants deterministic request construction.
|
|
24
|
+
*/
|
|
25
|
+
presets?: readonly Preset[];
|
|
26
|
+
/**
|
|
27
|
+
* Optional pre-fetched tool catalog.
|
|
28
|
+
*/
|
|
29
|
+
toolCatalog?: readonly PublicTool[];
|
|
30
|
+
/**
|
|
31
|
+
* Behavior when a preset allows a tool that is not present in the supplied
|
|
32
|
+
* or fetched tool catalog. "stub" keeps a name-only tool definition so the
|
|
33
|
+
* backend can still enrich it by name.
|
|
34
|
+
*/
|
|
35
|
+
unknownPresetTool?: UnknownPresetToolBehavior;
|
|
36
|
+
}
|
|
37
|
+
export interface ResolvePresetToolsResult {
|
|
38
|
+
preset: Preset;
|
|
39
|
+
tools: Tool[];
|
|
40
|
+
missingToolNames: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a preset's allowed tool names into concrete request tools and append
|
|
44
|
+
* caller-provided tools. This is a convenience for hybrid apps that need to add
|
|
45
|
+
* local/client tools while preserving the preset's default server tools.
|
|
46
|
+
*
|
|
47
|
+
* The Agent API request surface remains OpenAI-compatible: the returned array
|
|
48
|
+
* is intended for the normal CreateResponseRequest.tools field.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolvePresetTools(client: PresetToolCatalogClient, options: ResolvePresetToolsOptions): Promise<ResolvePresetToolsResult>;
|
|
51
|
+
export declare function resolvePresetToolsFromCatalog(options: ResolvePresetToolsOptions): ResolvePresetToolsResult;
|
|
52
|
+
export declare function mergeTools(...groups: Array<readonly Tool[]>): Tool[];
|
|
53
|
+
export declare function publicToolToRequestTool(tool: PublicTool): Tool;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { validateUniqueToolNames } from "./tool-validation.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a preset's allowed tool names into concrete request tools and append
|
|
4
|
+
* caller-provided tools. This is a convenience for hybrid apps that need to add
|
|
5
|
+
* local/client tools while preserving the preset's default server tools.
|
|
6
|
+
*
|
|
7
|
+
* The Agent API request surface remains OpenAI-compatible: the returned array
|
|
8
|
+
* is intended for the normal CreateResponseRequest.tools field.
|
|
9
|
+
*/
|
|
10
|
+
export async function resolvePresetTools(client, options) {
|
|
11
|
+
const presets = options.presets ?? (await client.presets.list()).data;
|
|
12
|
+
const toolCatalog = options.toolCatalog ?? (await client.tools.list()).data;
|
|
13
|
+
return resolvePresetToolsFromCatalog({ ...options, presets, toolCatalog });
|
|
14
|
+
}
|
|
15
|
+
export function resolvePresetToolsFromCatalog(options) {
|
|
16
|
+
const presetId = options.preset.trim();
|
|
17
|
+
if (!presetId) {
|
|
18
|
+
throw new Error("preset is required");
|
|
19
|
+
}
|
|
20
|
+
const preset = options.presets?.find((row) => row.preset === presetId);
|
|
21
|
+
if (!preset) {
|
|
22
|
+
throw new Error(`preset not found: ${presetId}`);
|
|
23
|
+
}
|
|
24
|
+
const catalogByName = new Map();
|
|
25
|
+
for (const tool of options.toolCatalog ?? []) {
|
|
26
|
+
const name = tool.name?.trim();
|
|
27
|
+
if (name)
|
|
28
|
+
catalogByName.set(name, tool);
|
|
29
|
+
}
|
|
30
|
+
const missingToolNames = [];
|
|
31
|
+
const presetTools = [];
|
|
32
|
+
const unknownPresetTool = options.unknownPresetTool ?? "stub";
|
|
33
|
+
for (const name of preset.policy?.allowed_tools ?? []) {
|
|
34
|
+
const trimmed = name.trim();
|
|
35
|
+
if (!trimmed)
|
|
36
|
+
continue;
|
|
37
|
+
const catalogTool = catalogByName.get(trimmed);
|
|
38
|
+
if (catalogTool) {
|
|
39
|
+
presetTools.push(publicToolToRequestTool(catalogTool));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
missingToolNames.push(trimmed);
|
|
43
|
+
if (unknownPresetTool === "error") {
|
|
44
|
+
throw new Error(`preset tool not found in catalog: ${trimmed}`);
|
|
45
|
+
}
|
|
46
|
+
if (unknownPresetTool === "stub") {
|
|
47
|
+
presetTools.push({ name: trimmed });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
preset,
|
|
52
|
+
tools: mergeTools(presetTools, options.tools ?? []),
|
|
53
|
+
missingToolNames,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function mergeTools(...groups) {
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const group of groups) {
|
|
59
|
+
for (const tool of group) {
|
|
60
|
+
const name = tool.name?.trim();
|
|
61
|
+
if (!name) {
|
|
62
|
+
throw new Error("tools[].name is required");
|
|
63
|
+
}
|
|
64
|
+
out.push({ ...tool, name });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
validateUniqueToolNames(out);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
export function publicToolToRequestTool(tool) {
|
|
71
|
+
const out = { name: tool.name };
|
|
72
|
+
if (tool.type)
|
|
73
|
+
out.type = tool.type;
|
|
74
|
+
if (tool.description)
|
|
75
|
+
out.description = tool.description;
|
|
76
|
+
if (tool.parameters)
|
|
77
|
+
out.parameters = tool.parameters;
|
|
78
|
+
if (tool.max_tokens != null)
|
|
79
|
+
out.max_tokens = tool.max_tokens;
|
|
80
|
+
if (tool.max_tokens_per_page != null)
|
|
81
|
+
out.max_tokens_per_page = tool.max_tokens_per_page;
|
|
82
|
+
if (tool.version)
|
|
83
|
+
out.version = tool.version;
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addOutputText } from "../internal/output-text.js";
|
|
2
2
|
import { buildQuery } from "../internal/query.js";
|
|
3
3
|
import { collectPage } from "../pagination.js";
|
|
4
|
+
import { validateUniqueToolNames } from "../tool-validation.js";
|
|
4
5
|
export class ResponsesResource {
|
|
5
6
|
http;
|
|
6
7
|
path;
|
|
@@ -9,6 +10,7 @@ export class ResponsesResource {
|
|
|
9
10
|
this.path = path;
|
|
10
11
|
}
|
|
11
12
|
create(params, options) {
|
|
13
|
+
validateUniqueToolNames(params.tools);
|
|
12
14
|
if (params.stream) {
|
|
13
15
|
return this.http.stream(this.path, params, options);
|
|
14
16
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function validateUniqueToolNames(tools) {
|
|
2
|
+
if (!tools)
|
|
3
|
+
return;
|
|
4
|
+
const seen = new Set();
|
|
5
|
+
for (const tool of tools) {
|
|
6
|
+
const name = tool.name?.trim();
|
|
7
|
+
if (!name) {
|
|
8
|
+
throw new Error("tools[].name is required");
|
|
9
|
+
}
|
|
10
|
+
if (seen.has(name)) {
|
|
11
|
+
throw new Error(`duplicate tools[].name: ${name}`);
|
|
12
|
+
}
|
|
13
|
+
seen.add(name);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.1.
|
|
2
|
-
export declare const USER_AGENT = "@agent-api/sdk/1.1.
|
|
1
|
+
export declare const VERSION = "1.1.3";
|
|
2
|
+
export declare const USER_AGENT = "@agent-api/sdk/1.1.3";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "1.1.
|
|
1
|
+
export const VERSION = "1.1.3";
|
|
2
2
|
export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
|