@nixet/sdk 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +164 -2
- package/dist/cjs/errors.d.ts +37 -0
- package/dist/cjs/errors.js +79 -0
- package/dist/cjs/index.d.ts +88 -0
- package/dist/cjs/index.js +118 -0
- package/dist/cjs/resources/agents.d.ts +67 -0
- package/dist/cjs/resources/agents.js +74 -0
- package/dist/cjs/resources/connections.d.ts +94 -0
- package/dist/cjs/resources/connections.js +106 -0
- package/dist/cjs/resources/conversations.d.ts +62 -0
- package/dist/cjs/resources/conversations.js +86 -0
- package/dist/cjs/resources/documents.d.ts +65 -0
- package/dist/cjs/resources/documents.js +61 -0
- package/dist/cjs/resources/guardrails.d.ts +56 -0
- package/dist/cjs/resources/guardrails.js +76 -0
- package/dist/cjs/resources/knowledge.d.ts +192 -0
- package/dist/cjs/resources/knowledge.js +221 -0
- package/dist/cjs/resources/mcp-servers.d.ts +83 -0
- package/dist/cjs/resources/mcp-servers.js +107 -0
- package/dist/cjs/resources/memory.d.ts +95 -0
- package/dist/cjs/resources/memory.js +127 -0
- package/dist/cjs/resources/runs.d.ts +78 -0
- package/dist/cjs/resources/runs.js +87 -0
- package/dist/cjs/resources/secrets.d.ts +60 -0
- package/dist/cjs/resources/secrets.js +85 -0
- package/dist/cjs/resources/skills.d.ts +57 -0
- package/dist/cjs/resources/skills.js +78 -0
- package/dist/cjs/resources/tasks.d.ts +91 -0
- package/dist/cjs/resources/tasks.js +129 -0
- package/dist/cjs/resources/tools.d.ts +42 -0
- package/dist/cjs/resources/tools.js +57 -0
- package/dist/cjs/resources/users.d.ts +39 -0
- package/dist/cjs/resources/users.js +57 -0
- package/dist/cjs/resources/versions.d.ts +105 -0
- package/dist/cjs/resources/versions.js +78 -0
- package/dist/cjs/stream.d.ts +57 -0
- package/dist/cjs/stream.js +170 -0
- package/dist/cjs/transport.d.ts +45 -0
- package/dist/cjs/transport.js +106 -0
- package/dist/cjs/types.d.ts +537 -0
- package/dist/cjs/types.js +3 -0
- package/dist/esm/errors.js +66 -0
- package/dist/esm/index.js +103 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/resources/agents.js +70 -0
- package/dist/esm/resources/connections.js +102 -0
- package/dist/esm/resources/conversations.js +82 -0
- package/dist/esm/resources/documents.js +57 -0
- package/dist/esm/resources/guardrails.js +72 -0
- package/dist/esm/resources/knowledge.js +215 -0
- package/dist/esm/resources/mcp-servers.js +103 -0
- package/dist/esm/resources/memory.js +123 -0
- package/dist/esm/resources/runs.js +83 -0
- package/dist/esm/resources/secrets.js +81 -0
- package/dist/esm/resources/skills.js +74 -0
- package/dist/esm/resources/tasks.js +125 -0
- package/dist/esm/resources/tools.js +53 -0
- package/dist/esm/resources/users.js +53 -0
- package/dist/esm/resources/versions.js +74 -0
- package/dist/esm/stream.js +166 -0
- package/dist/esm/transport.js +102 -0
- package/dist/esm/types.js +2 -0
- package/package.json +42 -4
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tasks = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tasks: work that outlives the request that asked for it.
|
|
6
|
+
*
|
|
7
|
+
* A run has to finish inside its HTTP request. A task does not: it is queued,
|
|
8
|
+
* executed by a worker, and polled for. Use it for anything that would
|
|
9
|
+
* otherwise time out — research, a long report, a batch of lookups.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const task = await nixet.tasks.create({
|
|
13
|
+
* agentId: agent.id,
|
|
14
|
+
* input: "Research this company and produce a report.",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const finished = await nixet.tasks.wait(task.id);
|
|
18
|
+
* console.log(finished.output);
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The work runs as a normal run, so `task.run_id` is where the trace, the
|
|
22
|
+
* events and the cost live.
|
|
23
|
+
*/
|
|
24
|
+
class Tasks {
|
|
25
|
+
transport;
|
|
26
|
+
constructor(transport) {
|
|
27
|
+
this.transport = transport;
|
|
28
|
+
}
|
|
29
|
+
/** Queue a task. Returns immediately, before the work starts. */
|
|
30
|
+
create(params, options = {}) {
|
|
31
|
+
return this.transport.request({
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: "/tasks",
|
|
34
|
+
body: {
|
|
35
|
+
agent_id: params.agentId,
|
|
36
|
+
input: params.input,
|
|
37
|
+
...(params.version ? { agent_version: params.version } : {}),
|
|
38
|
+
...(params.conversationId ? { conversation_id: params.conversationId } : {}),
|
|
39
|
+
...(params.userId ? { user_id: params.userId } : {}),
|
|
40
|
+
...(params.provider ? { provider: params.provider } : {}),
|
|
41
|
+
...(params.memory ? { memory: params.memory } : {}),
|
|
42
|
+
...(params.maxAttempts ? { max_attempts: params.maxAttempts } : {}),
|
|
43
|
+
},
|
|
44
|
+
signal: options.signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
retrieve(taskId, options = {}) {
|
|
48
|
+
return this.transport.request({
|
|
49
|
+
method: "GET",
|
|
50
|
+
path: `/tasks/${encodeURIComponent(taskId)}`,
|
|
51
|
+
signal: options.signal,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
list(params = {}, options = {}) {
|
|
55
|
+
return this.transport.requestPage({
|
|
56
|
+
method: "GET",
|
|
57
|
+
path: "/tasks",
|
|
58
|
+
query: {
|
|
59
|
+
...(params.limit ? { $limit: params.limit } : {}),
|
|
60
|
+
...(params.offset ? { $offset: params.offset } : {}),
|
|
61
|
+
...(params.status ? { status: params.status } : {}),
|
|
62
|
+
...(params.agentId ? { agent_id: params.agentId } : {}),
|
|
63
|
+
...(params.conversationId ? { conversation_id: params.conversationId } : {}),
|
|
64
|
+
},
|
|
65
|
+
signal: options.signal,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Stop a task.
|
|
70
|
+
*
|
|
71
|
+
* A queued task stops immediately. A running one is marked cancelled and the
|
|
72
|
+
* worker notices when its run finishes, because interrupting a model call
|
|
73
|
+
* mid-flight would still be billed for.
|
|
74
|
+
*/
|
|
75
|
+
cancel(taskId, options = {}) {
|
|
76
|
+
return this.transport.request({
|
|
77
|
+
method: "POST",
|
|
78
|
+
path: `/tasks/${encodeURIComponent(taskId)}/cancel`,
|
|
79
|
+
signal: options.signal,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Try a failed or cancelled task again, with its attempts reset. */
|
|
83
|
+
retry(taskId, options = {}) {
|
|
84
|
+
return this.transport.request({
|
|
85
|
+
method: "POST",
|
|
86
|
+
path: `/tasks/${encodeURIComponent(taskId)}/retry`,
|
|
87
|
+
signal: options.signal,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Continue a paused task.
|
|
92
|
+
*
|
|
93
|
+
* Nothing pauses a task yet — that arrives with tools and approvals — so
|
|
94
|
+
* this currently answers that there is nothing to resume.
|
|
95
|
+
*/
|
|
96
|
+
resume(taskId, options = {}) {
|
|
97
|
+
return this.transport.request({
|
|
98
|
+
method: "POST",
|
|
99
|
+
path: `/tasks/${encodeURIComponent(taskId)}/resume`,
|
|
100
|
+
signal: options.signal,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Poll until the task stops, and return it.
|
|
105
|
+
*
|
|
106
|
+
* Convenience over `retrieve`, not a different mechanism: there is no push
|
|
107
|
+
* for tasks yet, so this is the loop everyone would otherwise write. The
|
|
108
|
+
* timeout exists so a stuck task fails the caller rather than hanging.
|
|
109
|
+
*/
|
|
110
|
+
async wait(taskId, options = {}) {
|
|
111
|
+
const intervalMs = options.intervalMs ?? 2_000;
|
|
112
|
+
const deadline = Date.now() + (options.timeoutMs ?? 600_000);
|
|
113
|
+
for (;;) {
|
|
114
|
+
const task = await this.retrieve(taskId, { signal: options.signal });
|
|
115
|
+
options.onUpdate?.(task);
|
|
116
|
+
if (task.status === "completed" ||
|
|
117
|
+
task.status === "failed" ||
|
|
118
|
+
task.status === "cancelled") {
|
|
119
|
+
return task;
|
|
120
|
+
}
|
|
121
|
+
if (Date.now() >= deadline) {
|
|
122
|
+
throw new Error(`The task ${taskId} was still ${task.status} after the timeout. ` +
|
|
123
|
+
"It has not been cancelled; retrieve it later to see how it ended.");
|
|
124
|
+
}
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.Tasks = Tasks;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { ListParams, McpTool, Page } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Tools: what your servers offer, and what agents may do with each.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const tools = await nixet.tools.list({ serverName: "github" });
|
|
8
|
+
*
|
|
9
|
+
* await nixet.agents.versions.create(agent.id, {
|
|
10
|
+
* instructions: "Use the GitHub tools to answer questions about the repo.",
|
|
11
|
+
* mcpServers: ["github"],
|
|
12
|
+
* toolPolicies: { "github.delete_repo": "deny" },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Read-only: a tool exists because a server advertised it, so there is nothing
|
|
17
|
+
* here to create. Discovery runs when a server is registered and again when its
|
|
18
|
+
* URL moves, which is why a server that could not be reached has none listed.
|
|
19
|
+
*
|
|
20
|
+
* Each tool carries `tags` and a `default_policy`, and the two are not the same
|
|
21
|
+
* kind of thing. A tag is a claim — taken from the server's own annotations
|
|
22
|
+
* where it published any, and from our reading of the name where it did not —
|
|
23
|
+
* and the MCP specification is explicit that a server can claim `readOnlyHint`
|
|
24
|
+
* and delete your files regardless. So tags decide what you are shown and which
|
|
25
|
+
* default applies. What actually happens is the policy on the version, which is
|
|
26
|
+
* yours to set.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Tools {
|
|
29
|
+
private readonly transport;
|
|
30
|
+
constructor(transport: Transport);
|
|
31
|
+
/** One tool, by id. */
|
|
32
|
+
retrieve(toolId: string, options?: {
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<McpTool>;
|
|
35
|
+
/** Every tool on record, or those of one server. */
|
|
36
|
+
list(params?: ListParams & {
|
|
37
|
+
serverName?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
}, options?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): Promise<Page<McpTool>>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tools = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tools: what your servers offer, and what agents may do with each.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const tools = await nixet.tools.list({ serverName: "github" });
|
|
9
|
+
*
|
|
10
|
+
* await nixet.agents.versions.create(agent.id, {
|
|
11
|
+
* instructions: "Use the GitHub tools to answer questions about the repo.",
|
|
12
|
+
* mcpServers: ["github"],
|
|
13
|
+
* toolPolicies: { "github.delete_repo": "deny" },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Read-only: a tool exists because a server advertised it, so there is nothing
|
|
18
|
+
* here to create. Discovery runs when a server is registered and again when its
|
|
19
|
+
* URL moves, which is why a server that could not be reached has none listed.
|
|
20
|
+
*
|
|
21
|
+
* Each tool carries `tags` and a `default_policy`, and the two are not the same
|
|
22
|
+
* kind of thing. A tag is a claim — taken from the server's own annotations
|
|
23
|
+
* where it published any, and from our reading of the name where it did not —
|
|
24
|
+
* and the MCP specification is explicit that a server can claim `readOnlyHint`
|
|
25
|
+
* and delete your files regardless. So tags decide what you are shown and which
|
|
26
|
+
* default applies. What actually happens is the policy on the version, which is
|
|
27
|
+
* yours to set.
|
|
28
|
+
*/
|
|
29
|
+
class Tools {
|
|
30
|
+
transport;
|
|
31
|
+
constructor(transport) {
|
|
32
|
+
this.transport = transport;
|
|
33
|
+
}
|
|
34
|
+
/** One tool, by id. */
|
|
35
|
+
retrieve(toolId, options = {}) {
|
|
36
|
+
return this.transport.request({
|
|
37
|
+
method: "GET",
|
|
38
|
+
path: `/mcp/tools/${encodeURIComponent(toolId)}`,
|
|
39
|
+
signal: options.signal,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Every tool on record, or those of one server. */
|
|
43
|
+
list(params = {}, options = {}) {
|
|
44
|
+
return this.transport.requestPage({
|
|
45
|
+
method: "GET",
|
|
46
|
+
path: "/mcp/tools",
|
|
47
|
+
query: {
|
|
48
|
+
$limit: params.limit,
|
|
49
|
+
$offset: params.offset,
|
|
50
|
+
server_name: params.serverName,
|
|
51
|
+
name: params.name,
|
|
52
|
+
},
|
|
53
|
+
signal: options.signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Tools = Tools;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { ListParams, Page, User } from "../types.js";
|
|
3
|
+
export interface CreateUserParams {
|
|
4
|
+
/** Your own identifier for this person. Unique within your workspace. */
|
|
5
|
+
reference: string;
|
|
6
|
+
email?: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Users: the people your agent serves.
|
|
12
|
+
*
|
|
13
|
+
* Not the people who sign into the Nixet console — those are members. A user
|
|
14
|
+
* is yours: you supply the reference, and memory is isolated per user so one
|
|
15
|
+
* of your customers can never read another's.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Users {
|
|
18
|
+
private readonly transport;
|
|
19
|
+
constructor(transport: Transport);
|
|
20
|
+
/**
|
|
21
|
+
* Register a user.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const user = await nixet.users.create({ reference: "acme_user_8821" });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
create(params: CreateUserParams, options?: {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}): Promise<User>;
|
|
30
|
+
retrieve(userId: string, options?: {
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): Promise<User>;
|
|
33
|
+
/** Filter by `reference` to find a person by your own identifier. */
|
|
34
|
+
list(params?: ListParams & {
|
|
35
|
+
reference?: string;
|
|
36
|
+
}, options?: {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}): Promise<Page<User>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Users = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Users: the people your agent serves.
|
|
6
|
+
*
|
|
7
|
+
* Not the people who sign into the Nixet console — those are members. A user
|
|
8
|
+
* is yours: you supply the reference, and memory is isolated per user so one
|
|
9
|
+
* of your customers can never read another's.
|
|
10
|
+
*/
|
|
11
|
+
class Users {
|
|
12
|
+
transport;
|
|
13
|
+
constructor(transport) {
|
|
14
|
+
this.transport = transport;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Register a user.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const user = await nixet.users.create({ reference: "acme_user_8821" });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
create(params, options = {}) {
|
|
24
|
+
return this.transport.request({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: "/users",
|
|
27
|
+
body: {
|
|
28
|
+
reference: params.reference,
|
|
29
|
+
...(params.email ? { email: params.email } : {}),
|
|
30
|
+
...(params.name ? { name: params.name } : {}),
|
|
31
|
+
...(params.metadata ? { metadata: params.metadata } : {}),
|
|
32
|
+
},
|
|
33
|
+
signal: options.signal,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
retrieve(userId, options = {}) {
|
|
37
|
+
return this.transport.request({
|
|
38
|
+
method: "GET",
|
|
39
|
+
path: `/users/${encodeURIComponent(userId)}`,
|
|
40
|
+
signal: options.signal,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Filter by `reference` to find a person by your own identifier. */
|
|
44
|
+
list(params = {}, options = {}) {
|
|
45
|
+
return this.transport.requestPage({
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: "/users",
|
|
48
|
+
query: {
|
|
49
|
+
$limit: params.limit,
|
|
50
|
+
$offset: params.offset,
|
|
51
|
+
reference: params.reference,
|
|
52
|
+
},
|
|
53
|
+
signal: options.signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Users = Users;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { AgentVersion, ListParams, ModelConfig, Page, RedactionPolicyInput, ToolPolicy, ToolRef } from "../types.js";
|
|
3
|
+
export interface CreateVersionParams {
|
|
4
|
+
/** System prompt that defines the agent's behaviour. */
|
|
5
|
+
instructions: string;
|
|
6
|
+
/** Defaults to the managed provider at its balanced tier. */
|
|
7
|
+
model?: ModelConfig;
|
|
8
|
+
/** Tools the agent may call. Unknown names are rejected at publish. */
|
|
9
|
+
tools?: (ToolRef | string)[];
|
|
10
|
+
/** Skills to use, as `name` or `name@v2`. Pinned at publish. */
|
|
11
|
+
skills?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Mask personal data in run input and output before dispatch.
|
|
14
|
+
*
|
|
15
|
+
* Defaults to off. Traces are not redacted, and about one item in ten is
|
|
16
|
+
* missed, so this reduces personal data rather than removing it.
|
|
17
|
+
*/
|
|
18
|
+
redaction?: RedactionPolicyInput;
|
|
19
|
+
/**
|
|
20
|
+
* Names of registered MCP servers this version may use.
|
|
21
|
+
*
|
|
22
|
+
* Pinned by name rather than by id, so moving a server's URL changes what a
|
|
23
|
+
* published version reaches without republishing it. Cannot be combined with
|
|
24
|
+
* redaction: a masked run would hand tools placeholders instead of values.
|
|
25
|
+
*/
|
|
26
|
+
mcpServers?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* What this version may do with a tool, as `server.tool` to policy.
|
|
29
|
+
*
|
|
30
|
+
* Only the exceptions: anything unnamed takes the default its tags imply, so
|
|
31
|
+
* a version does not need rewriting when a server adds a tool. Qualified by
|
|
32
|
+
* server because two servers can both offer `search`.
|
|
33
|
+
*
|
|
34
|
+
* `ask` is refused at publish until approvals exist — nothing can pause a run
|
|
35
|
+
* for a human yet, and a policy that cannot mean what it says should not
|
|
36
|
+
* become runnable.
|
|
37
|
+
*/
|
|
38
|
+
toolPolicies?: Record<string, ToolPolicy>;
|
|
39
|
+
/**
|
|
40
|
+
* Knowledge collections this version may search, by name.
|
|
41
|
+
*
|
|
42
|
+
* Named rather than embedded, so a document added after publishing is found
|
|
43
|
+
* without a new version. A collection with no ready sources is not an error:
|
|
44
|
+
* it returns nothing until one finishes ingesting.
|
|
45
|
+
*/
|
|
46
|
+
knowledgeCollections?: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Placeholders in `instructions`, as `{{name}}`, that a run supplies.
|
|
49
|
+
*
|
|
50
|
+
* Declared rather than inferred, and checked against the instructions at
|
|
51
|
+
* publish: a placeholder used without being declared, or declared without
|
|
52
|
+
* being used, is refused. Both are mistakes in a version, and a version is
|
|
53
|
+
* immutable, so publish is the only time they are cheap to find.
|
|
54
|
+
*
|
|
55
|
+
* Declaring them is also what keeps a run from reaching a slot this version
|
|
56
|
+
* never named — a run that could inject arbitrary prompt text would make
|
|
57
|
+
* your own backend a prompt-injection surface.
|
|
58
|
+
*/
|
|
59
|
+
variables?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Guardrails to run, by name, per stage.
|
|
62
|
+
*
|
|
63
|
+
* Created with `nixet.guardrails.create` and named here, the way MCP servers
|
|
64
|
+
* and knowledge collections are. Order is the order given: under `run_all`
|
|
65
|
+
* each guard sees the text the previous one produced, so four scrubbing
|
|
66
|
+
* rules compose into one rewritten response rather than the last one
|
|
67
|
+
* winning.
|
|
68
|
+
*
|
|
69
|
+
* `tool_result` is the stage worth not forgetting. A tool answering with
|
|
70
|
+
* structured data reaches the caller without passing through the agent's
|
|
71
|
+
* text, so an `output` guard never sees it.
|
|
72
|
+
*/
|
|
73
|
+
guardrails?: {
|
|
74
|
+
input?: string[];
|
|
75
|
+
output?: string[];
|
|
76
|
+
tool_result?: string[];
|
|
77
|
+
/** Defaults to `run_all`. */
|
|
78
|
+
mode?: "run_all" | "fail_fast";
|
|
79
|
+
/** Defaults to `return_message`. */
|
|
80
|
+
on_block?: "return_message" | "error";
|
|
81
|
+
};
|
|
82
|
+
/** Make this the version new runs use. Defaults to true. */
|
|
83
|
+
publish?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Immutable snapshots of an agent's configuration.
|
|
87
|
+
*
|
|
88
|
+
* A published version is never edited, which is what lets a past run be
|
|
89
|
+
* explained by the configuration it recorded.
|
|
90
|
+
*/
|
|
91
|
+
export declare class Versions {
|
|
92
|
+
private readonly transport;
|
|
93
|
+
constructor(transport: Transport);
|
|
94
|
+
/** Publish a new version. Returns it, numbered in order: v1, v2, v3. */
|
|
95
|
+
create(agentId: string, params: CreateVersionParams, options?: {
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}): Promise<AgentVersion>;
|
|
98
|
+
list(agentId: string, params?: ListParams, options?: {
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
}): Promise<Page<AgentVersion>>;
|
|
101
|
+
/** Retrieve one version by its label, such as `v1`. */
|
|
102
|
+
retrieve(agentId: string, version: string, options?: {
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
}): Promise<AgentVersion>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Versions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Immutable snapshots of an agent's configuration.
|
|
6
|
+
*
|
|
7
|
+
* A published version is never edited, which is what lets a past run be
|
|
8
|
+
* explained by the configuration it recorded.
|
|
9
|
+
*/
|
|
10
|
+
class Versions {
|
|
11
|
+
transport;
|
|
12
|
+
constructor(transport) {
|
|
13
|
+
this.transport = transport;
|
|
14
|
+
}
|
|
15
|
+
/** Publish a new version. Returns it, numbered in order: v1, v2, v3. */
|
|
16
|
+
async create(agentId, params, options = {}) {
|
|
17
|
+
return this.transport.request({
|
|
18
|
+
method: "POST",
|
|
19
|
+
path: `/agents/${encodeURIComponent(agentId)}/versions`,
|
|
20
|
+
body: {
|
|
21
|
+
instructions: params.instructions,
|
|
22
|
+
...(params.model ? { model: params.model } : {}),
|
|
23
|
+
// A bare string is the common case, so accept it as shorthand.
|
|
24
|
+
...(params.tools ? { tools: params.tools.map(toToolRef) } : {}),
|
|
25
|
+
...(params.skills ? { skills: params.skills } : {}),
|
|
26
|
+
// Named in the SDK's own casing, so a caller is not asked to know
|
|
27
|
+
// which fields happen to reach the wire untouched.
|
|
28
|
+
...(params.redaction
|
|
29
|
+
? {
|
|
30
|
+
redaction: {
|
|
31
|
+
mode: params.redaction.mode,
|
|
32
|
+
...(params.redaction.reversible === undefined
|
|
33
|
+
? {}
|
|
34
|
+
: { reversible: params.redaction.reversible }),
|
|
35
|
+
...(params.redaction.minimumConfidence === undefined
|
|
36
|
+
? {}
|
|
37
|
+
: { minimum_confidence: params.redaction.minimumConfidence }),
|
|
38
|
+
...(params.redaction.labels ? { labels: params.redaction.labels } : {}),
|
|
39
|
+
...(params.redaction.retainFor
|
|
40
|
+
? { retain_for: params.redaction.retainFor }
|
|
41
|
+
: {}),
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
: {}),
|
|
45
|
+
...(params.mcpServers ? { mcp_servers: params.mcpServers } : {}),
|
|
46
|
+
...(params.toolPolicies ? { tool_policies: params.toolPolicies } : {}),
|
|
47
|
+
...(params.knowledgeCollections
|
|
48
|
+
? { knowledge_collections: params.knowledgeCollections }
|
|
49
|
+
: {}),
|
|
50
|
+
...(params.variables ? { variables: params.variables } : {}),
|
|
51
|
+
// Sent whole rather than field by field: the server defaults `mode`
|
|
52
|
+
// and `on_block`, and a partial object here would be a second place
|
|
53
|
+
// those defaults are decided.
|
|
54
|
+
...(params.guardrails ? { guardrails: params.guardrails } : {}),
|
|
55
|
+
...(params.publish === undefined ? {} : { publish: params.publish }),
|
|
56
|
+
},
|
|
57
|
+
signal: options.signal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async list(agentId, params = {}, options = {}) {
|
|
61
|
+
return this.transport.requestPage({
|
|
62
|
+
method: "GET",
|
|
63
|
+
path: `/agents/${encodeURIComponent(agentId)}/versions`,
|
|
64
|
+
query: { $limit: params.limit, $offset: params.offset },
|
|
65
|
+
signal: options.signal,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Retrieve one version by its label, such as `v1`. */
|
|
69
|
+
async retrieve(agentId, version, options = {}) {
|
|
70
|
+
return this.transport.request({
|
|
71
|
+
method: "GET",
|
|
72
|
+
path: `/agents/${encodeURIComponent(agentId)}/versions/${encodeURIComponent(version)}`,
|
|
73
|
+
signal: options.signal,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Versions = Versions;
|
|
78
|
+
const toToolRef = (tool) => typeof tool === "string" ? { name: tool } : tool;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Run, RunEvent } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A live run.
|
|
4
|
+
*
|
|
5
|
+
* Iterate it for events, await `text()` for the finished output, or attach
|
|
6
|
+
* handlers. All three read the same underlying stream, so choose one style per
|
|
7
|
+
* run rather than mixing them.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* for await (const event of stream) {
|
|
11
|
+
* if (event.type === "run.output") process.stdout.write(event.data ?? "");
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class RunStream implements AsyncIterable<RunEvent> {
|
|
16
|
+
/**
|
|
17
|
+
* Resolves once the server acknowledges the run, before it finishes.
|
|
18
|
+
*
|
|
19
|
+
* Awaiting this starts reading the stream, so it is safe to call before
|
|
20
|
+
* iterating: the acceptance frame is consumed here and the events that follow
|
|
21
|
+
* are buffered for whichever reader comes next.
|
|
22
|
+
*/
|
|
23
|
+
readonly runId: Promise<string>;
|
|
24
|
+
private readonly response;
|
|
25
|
+
private readonly handlers;
|
|
26
|
+
private resolveRunId;
|
|
27
|
+
private rejectRunId;
|
|
28
|
+
private consumed;
|
|
29
|
+
/** Events read while resolving `runId`, replayed to the first real reader. */
|
|
30
|
+
private buffered;
|
|
31
|
+
private reading;
|
|
32
|
+
private reader;
|
|
33
|
+
private pending;
|
|
34
|
+
private readonly decoder;
|
|
35
|
+
constructor(response: Response);
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to one event type, or to `"*"` for all of them.
|
|
38
|
+
* Returns an unsubscribe function.
|
|
39
|
+
*/
|
|
40
|
+
on(type: RunEvent["type"] | "*", handler: (event: RunEvent) => void): () => void;
|
|
41
|
+
/** The concatenated output, once the run finishes. */
|
|
42
|
+
text(): Promise<string>;
|
|
43
|
+
/** Only the text deltas, for writing straight to a terminal or a socket. */
|
|
44
|
+
chunks(): AsyncGenerator<string>;
|
|
45
|
+
[Symbol.asyncIterator](): AsyncGenerator<RunEvent>;
|
|
46
|
+
/**
|
|
47
|
+
* Read until the acceptance frame arrives, then stop.
|
|
48
|
+
*
|
|
49
|
+
* Runs once, so `runId` is available without a consumer while the events
|
|
50
|
+
* after it stay queued for the first reader.
|
|
51
|
+
*/
|
|
52
|
+
private pump;
|
|
53
|
+
/** One event from the shared cursor, or null at end of stream. */
|
|
54
|
+
private next;
|
|
55
|
+
private emit;
|
|
56
|
+
}
|
|
57
|
+
export type { Run };
|