@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,103 @@
|
|
|
1
|
+
import { Agents } from "./resources/agents.js";
|
|
2
|
+
import { Runs } from "./resources/runs.js";
|
|
3
|
+
import { Skills } from "./resources/skills.js";
|
|
4
|
+
import { Users } from "./resources/users.js";
|
|
5
|
+
import { Conversations } from "./resources/conversations.js";
|
|
6
|
+
import { MemoryResource } from "./resources/memory.js";
|
|
7
|
+
import { Tasks } from "./resources/tasks.js";
|
|
8
|
+
import { Secrets } from "./resources/secrets.js";
|
|
9
|
+
import { McpServers } from "./resources/mcp-servers.js";
|
|
10
|
+
import { Tools } from "./resources/tools.js";
|
|
11
|
+
import { Documents } from "./resources/documents.js";
|
|
12
|
+
import { Guardrails } from "./resources/guardrails.js";
|
|
13
|
+
import { Connections } from "./resources/connections.js";
|
|
14
|
+
import { Knowledge, KnowledgeCollections, KnowledgeSources, } from "./resources/knowledge.js";
|
|
15
|
+
import { Versions } from "./resources/versions.js";
|
|
16
|
+
import { Transport } from "./transport.js";
|
|
17
|
+
/**
|
|
18
|
+
* The Nixet client.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Nixet } from "@nixet/sdk";
|
|
22
|
+
*
|
|
23
|
+
* const nixet = new Nixet(); // reads NIXET_API_KEY
|
|
24
|
+
*
|
|
25
|
+
* const agent = await nixet.agents.create({
|
|
26
|
+
* name: "Support Assistant",
|
|
27
|
+
* instructions: "You are concise.",
|
|
28
|
+
* tools: ["calculate"],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* const run = await nixet.runs.create(agent.id, { input: "What is 23 × 7?" });
|
|
32
|
+
* console.log(run.output);
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* A key is bound to one workspace and environment, so there is nothing else to
|
|
36
|
+
* configure.
|
|
37
|
+
*/
|
|
38
|
+
export class Nixet {
|
|
39
|
+
agents;
|
|
40
|
+
runs;
|
|
41
|
+
skills;
|
|
42
|
+
users;
|
|
43
|
+
conversations;
|
|
44
|
+
memory;
|
|
45
|
+
tasks;
|
|
46
|
+
secrets;
|
|
47
|
+
mcpServers;
|
|
48
|
+
/** Converting a document to Markdown. */
|
|
49
|
+
documents;
|
|
50
|
+
/** Rules applied to what an agent is given and what it says. */
|
|
51
|
+
guardrails;
|
|
52
|
+
/** End users' credentials for the servers you registered. */
|
|
53
|
+
connections;
|
|
54
|
+
tools;
|
|
55
|
+
knowledge;
|
|
56
|
+
transport;
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
const apiKey = options.apiKey ?? readEnv("NIXET_API_KEY");
|
|
59
|
+
if (!apiKey) {
|
|
60
|
+
throw new Error("A Nixet API key is required. Pass `apiKey`, or set NIXET_API_KEY. " +
|
|
61
|
+
"Create one in the console under API keys.");
|
|
62
|
+
}
|
|
63
|
+
this.transport = new Transport({
|
|
64
|
+
apiKey,
|
|
65
|
+
baseURL: options.baseURL ?? readEnv("NIXET_BASE_URL") ?? "https://api.nixet.ai/v1",
|
|
66
|
+
// Generous by default: a run waits on a model, not on the network.
|
|
67
|
+
timeout: options.timeout ?? 600_000,
|
|
68
|
+
maxRetries: options.maxRetries ?? 2,
|
|
69
|
+
fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
|
|
70
|
+
});
|
|
71
|
+
const versions = new Versions(this.transport);
|
|
72
|
+
this.agents = new Agents(this.transport, versions);
|
|
73
|
+
this.runs = new Runs(this.transport);
|
|
74
|
+
this.skills = new Skills(this.transport);
|
|
75
|
+
this.users = new Users(this.transport);
|
|
76
|
+
this.conversations = new Conversations(this.transport);
|
|
77
|
+
this.memory = new MemoryResource(this.transport);
|
|
78
|
+
this.tasks = new Tasks(this.transport);
|
|
79
|
+
this.secrets = new Secrets(this.transport);
|
|
80
|
+
this.mcpServers = new McpServers(this.transport);
|
|
81
|
+
this.documents = new Documents(this.transport);
|
|
82
|
+
this.guardrails = new Guardrails(this.transport);
|
|
83
|
+
this.connections = new Connections(this.transport);
|
|
84
|
+
this.tools = new Tools(this.transport);
|
|
85
|
+
this.knowledge = new Knowledge(new KnowledgeCollections(this.transport), new KnowledgeSources(this.transport));
|
|
86
|
+
}
|
|
87
|
+
/** Confirm which workspace and permissions this key carries. */
|
|
88
|
+
async whoami(options = {}) {
|
|
89
|
+
return this.transport.request({
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "/whoami",
|
|
92
|
+
signal: options.signal,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** Reads from Node or Deno without assuming either is present. */
|
|
97
|
+
function readEnv(name) {
|
|
98
|
+
const runtime = globalThis;
|
|
99
|
+
return runtime.process?.env?.[name];
|
|
100
|
+
}
|
|
101
|
+
export default Nixet;
|
|
102
|
+
export { RunStream } from "./stream.js";
|
|
103
|
+
export { APIError, AuthenticationError, BadRequestError, ConflictError, ConnectionError, NixetError, NotFoundError, PermissionError, RateLimitError, ServerError, } from "./errors.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents.
|
|
3
|
+
*
|
|
4
|
+
* An agent is an identity; its behaviour lives in versions. `create` accepts
|
|
5
|
+
* instructions so that the usual case is one call rather than two.
|
|
6
|
+
*/
|
|
7
|
+
export class Agents {
|
|
8
|
+
transport;
|
|
9
|
+
versions;
|
|
10
|
+
constructor(transport,
|
|
11
|
+
/** Sub-resource, so `nixet.agents.versions.create(...)` reads naturally. */
|
|
12
|
+
versions) {
|
|
13
|
+
this.transport = transport;
|
|
14
|
+
this.versions = versions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create an agent, optionally publishing its first version.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const agent = await nixet.agents.create({
|
|
21
|
+
* name: "Support Assistant",
|
|
22
|
+
* instructions: "You are concise.",
|
|
23
|
+
* model: { provider: "nix", tier: "fast" },
|
|
24
|
+
* tools: ["calculate"],
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
async create(params, options = {}) {
|
|
29
|
+
const agent = await this.transport.request({
|
|
30
|
+
method: "POST",
|
|
31
|
+
path: "/agents",
|
|
32
|
+
body: {
|
|
33
|
+
name: params.name,
|
|
34
|
+
...(params.description ? { description: params.description } : {}),
|
|
35
|
+
},
|
|
36
|
+
signal: options.signal,
|
|
37
|
+
});
|
|
38
|
+
if (!params.instructions)
|
|
39
|
+
return agent;
|
|
40
|
+
const version = await this.versions.create(agent.id, {
|
|
41
|
+
instructions: params.instructions,
|
|
42
|
+
model: params.model,
|
|
43
|
+
tools: params.tools,
|
|
44
|
+
skills: params.skills,
|
|
45
|
+
mcpServers: params.mcpServers,
|
|
46
|
+
toolPolicies: params.toolPolicies,
|
|
47
|
+
knowledgeCollections: params.knowledgeCollections,
|
|
48
|
+
variables: params.variables,
|
|
49
|
+
guardrails: params.guardrails,
|
|
50
|
+
}, options);
|
|
51
|
+
// The agent was fetched before the version published, so its pointer is
|
|
52
|
+
// stale. Reflect the version that now exists rather than returning null.
|
|
53
|
+
return { ...agent, current_version: version.version, version };
|
|
54
|
+
}
|
|
55
|
+
async retrieve(agentId, options = {}) {
|
|
56
|
+
return this.transport.request({
|
|
57
|
+
method: "GET",
|
|
58
|
+
path: `/agents/${encodeURIComponent(agentId)}`,
|
|
59
|
+
signal: options.signal,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async list(params = {}, options = {}) {
|
|
63
|
+
return this.transport.requestPage({
|
|
64
|
+
method: "GET",
|
|
65
|
+
path: "/agents",
|
|
66
|
+
query: { $limit: params.limit, $offset: params.offset },
|
|
67
|
+
signal: options.signal,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connections: an end user's credential for a server you registered once.
|
|
3
|
+
*
|
|
4
|
+
* The split that makes this worth having. A server registration carries one
|
|
5
|
+
* credential, which is right for an integration you own — your GitHub, your
|
|
6
|
+
* internal API. It is wrong when every end user links their own account,
|
|
7
|
+
* because the URL is identical for all of them and only the token differs. A
|
|
8
|
+
* registration per user would force an agent version per user, and version
|
|
9
|
+
* history would stop describing behaviour and become a credential registry.
|
|
10
|
+
*
|
|
11
|
+
* So the provider is registered once with `auth: { type: "per_user" }`, and a
|
|
12
|
+
* connection binds one user to one credential for it. A run naming a user
|
|
13
|
+
* reaches that user's account; the version still decides which servers and
|
|
14
|
+
* which tools, because that is a capability rather than an identity.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* await nixet.mcpServers.create({
|
|
18
|
+
* name: "broker",
|
|
19
|
+
* url: "https://mcp.broker.com/mcp",
|
|
20
|
+
* auth: { type: "per_user", scheme: "api_key" },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await nixet.connections.create({
|
|
24
|
+
* userId: user.id,
|
|
25
|
+
* server: "broker",
|
|
26
|
+
* value: userSuppliedKey,
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // The run picks the credential up from the user it names.
|
|
30
|
+
* await nixet.runs.create(agentId, { input: "What do I hold?", userId: user.id });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* A credential is write-only: nothing here returns one, and there is no
|
|
34
|
+
* method that could. A read gives back the scheme, the status and the expiry.
|
|
35
|
+
*
|
|
36
|
+
* `revoke` rather than delete. A run recorded that it authenticated as a
|
|
37
|
+
* connection, and removing the row would leave that run unexplainable, so the
|
|
38
|
+
* credential is erased and the record of it is not.
|
|
39
|
+
*
|
|
40
|
+
* A missing or expired connection fails the run rather than calling the
|
|
41
|
+
* server unauthenticated. Reaching someone's broker as nobody is worse than a
|
|
42
|
+
* refused run, and nothing outside would reveal it had happened.
|
|
43
|
+
*/
|
|
44
|
+
export class Connections {
|
|
45
|
+
transport;
|
|
46
|
+
constructor(transport) {
|
|
47
|
+
this.transport = transport;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Store a credential the user already holds.
|
|
51
|
+
*
|
|
52
|
+
* For an `api_key` server, where there is nothing to redirect the user
|
|
53
|
+
* through. Also how a platform that runs its own OAuth pushes a fresh token:
|
|
54
|
+
* creating again for the same user and server replaces nothing, so revoke
|
|
55
|
+
* the old one first.
|
|
56
|
+
*/
|
|
57
|
+
create(params, options = {}) {
|
|
58
|
+
return this.transport.request({
|
|
59
|
+
method: "POST",
|
|
60
|
+
path: "/mcp/connections",
|
|
61
|
+
body: {
|
|
62
|
+
user_id: params.userId,
|
|
63
|
+
server: params.server,
|
|
64
|
+
value: params.value,
|
|
65
|
+
...(params.expiresAt ? { expires_at: params.expiresAt } : {}),
|
|
66
|
+
...(params.refreshValue ? { refresh_value: params.refreshValue } : {}),
|
|
67
|
+
},
|
|
68
|
+
signal: options.signal,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
list(params = {}, options = {}) {
|
|
72
|
+
return this.transport.requestPage({
|
|
73
|
+
method: "GET",
|
|
74
|
+
path: "/mcp/connections",
|
|
75
|
+
// Mapped rather than spread: `$limit` is the wire name and `limit` is
|
|
76
|
+
// what a caller writes, and spreading would send both.
|
|
77
|
+
query: {
|
|
78
|
+
$limit: params.limit,
|
|
79
|
+
$offset: params.offset,
|
|
80
|
+
user_id: params.userId,
|
|
81
|
+
server: params.server,
|
|
82
|
+
status: params.status,
|
|
83
|
+
},
|
|
84
|
+
signal: options.signal,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
retrieve(id, options = {}) {
|
|
88
|
+
return this.transport.request({
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: `/mcp/connections/${id}`,
|
|
91
|
+
signal: options.signal,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** Erase the credential and keep the record that it existed. */
|
|
95
|
+
revoke(id, options = {}) {
|
|
96
|
+
return this.transport.request({
|
|
97
|
+
method: "DELETE",
|
|
98
|
+
path: `/mcp/connections/${id}`,
|
|
99
|
+
signal: options.signal,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversations: a durable thread between an agent and a user.
|
|
3
|
+
*
|
|
4
|
+
* Each message creates a run, so cost, usage and the trace work exactly as
|
|
5
|
+
* they do for a single-shot run. The conversation adds the history around them.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const convo = await nixet.conversations.create({
|
|
9
|
+
* agentId: agent.id,
|
|
10
|
+
* userId: user.id,
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* await nixet.conversations.send(convo.id, { input: "Hi, I'm Sam." });
|
|
14
|
+
* await nixet.conversations.send(convo.id, { input: "What's my name?" });
|
|
15
|
+
* // → "Sam"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class Conversations {
|
|
19
|
+
transport;
|
|
20
|
+
constructor(transport) {
|
|
21
|
+
this.transport = transport;
|
|
22
|
+
}
|
|
23
|
+
create(params, options = {}) {
|
|
24
|
+
return this.transport.request({
|
|
25
|
+
method: "POST",
|
|
26
|
+
path: "/conversations",
|
|
27
|
+
body: {
|
|
28
|
+
agent_id: params.agentId,
|
|
29
|
+
...(params.userId ? { user_id: params.userId } : {}),
|
|
30
|
+
...(params.title ? { title: params.title } : {}),
|
|
31
|
+
...(params.agentVersion ? { agent_version: params.agentVersion } : {}),
|
|
32
|
+
...(params.memory ? { memory: params.memory } : {}),
|
|
33
|
+
},
|
|
34
|
+
signal: options.signal,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
retrieve(conversationId, options = {}) {
|
|
38
|
+
return this.transport.request({
|
|
39
|
+
method: "GET",
|
|
40
|
+
path: `/conversations/${encodeURIComponent(conversationId)}`,
|
|
41
|
+
signal: options.signal,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
list(params = {}, options = {}) {
|
|
45
|
+
return this.transport.requestPage({
|
|
46
|
+
method: "GET",
|
|
47
|
+
path: "/conversations",
|
|
48
|
+
query: {
|
|
49
|
+
$limit: params.limit,
|
|
50
|
+
$offset: params.offset,
|
|
51
|
+
agent_id: params.agentId,
|
|
52
|
+
user_id: params.userId,
|
|
53
|
+
},
|
|
54
|
+
signal: options.signal,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Send a message and wait for the reply. */
|
|
58
|
+
send(conversationId, params, options = {}) {
|
|
59
|
+
return this.transport.request({
|
|
60
|
+
method: "POST",
|
|
61
|
+
path: `/conversations/${encodeURIComponent(conversationId)}/messages`,
|
|
62
|
+
body: {
|
|
63
|
+
input: params.input,
|
|
64
|
+
...(params.provider ? { provider: params.provider } : {}),
|
|
65
|
+
},
|
|
66
|
+
signal: options.signal,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The full transcript, oldest first.
|
|
71
|
+
*
|
|
72
|
+
* Includes turns a summary has since replaced, so what a person actually
|
|
73
|
+
* said is still readable even after the thread has been compacted.
|
|
74
|
+
*/
|
|
75
|
+
messages(conversationId, options = {}) {
|
|
76
|
+
return this.transport.requestPage({
|
|
77
|
+
method: "GET",
|
|
78
|
+
path: `/conversations/${encodeURIComponent(conversationId)}/messages`,
|
|
79
|
+
signal: options.signal,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a document.
|
|
3
|
+
*
|
|
4
|
+
* Converts fourteen formats to Markdown — PDF, Word, Excel, PowerPoint and the
|
|
5
|
+
* rest — locally, with no third party seeing the file. A PDF whose pages are
|
|
6
|
+
* scans needs an OCR engine and reports which pages it read that way.
|
|
7
|
+
*
|
|
8
|
+
* Separate from knowledge because the intent is different. A knowledge source
|
|
9
|
+
* is converted so an agent can search it, and what comes back are chunks
|
|
10
|
+
* ordered by similarity. This returns the document.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* const { markdown } = await nixet.documents.convert({
|
|
14
|
+
* file: await fs.openAsBlob("statement.pdf"),
|
|
15
|
+
* password: "secret",
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export class Documents {
|
|
20
|
+
transport;
|
|
21
|
+
constructor(transport) {
|
|
22
|
+
this.transport = transport;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert a document to Markdown.
|
|
26
|
+
*
|
|
27
|
+
* Synchronous: the Markdown is in the response. That holds below the size
|
|
28
|
+
* limit, which is lower than the knowledge upload limit for the same reason
|
|
29
|
+
* — a caller is waiting on this, where an ingested document is converted by
|
|
30
|
+
* a worker that can take as long as it needs.
|
|
31
|
+
*/
|
|
32
|
+
async convert(params) {
|
|
33
|
+
const form = new FormData();
|
|
34
|
+
// A Blob keeps its own name; bytes need one supplied. `document` is the
|
|
35
|
+
// fallback rather than an error, because the name is only consulted for
|
|
36
|
+
// signature-less formats.
|
|
37
|
+
if (params.file instanceof Blob) {
|
|
38
|
+
form.append("file", params.file, params.filename ?? "document");
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
form.append("file", new Blob([params.file]), params.filename ?? "document");
|
|
42
|
+
}
|
|
43
|
+
if (params.password)
|
|
44
|
+
form.append("password", params.password);
|
|
45
|
+
if (params.collection)
|
|
46
|
+
form.append("collection", params.collection);
|
|
47
|
+
if (params.title)
|
|
48
|
+
form.append("title", params.title);
|
|
49
|
+
return this.transport.request({
|
|
50
|
+
method: "POST",
|
|
51
|
+
path: "/documents/convert",
|
|
52
|
+
body: form,
|
|
53
|
+
form: true,
|
|
54
|
+
signal: params.signal,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guardrails: what an agent may be given, and what it may say.
|
|
3
|
+
*
|
|
4
|
+
* Defined once for the workspace and named by a version, the same way MCP
|
|
5
|
+
* servers and knowledge collections are. A rule like "never name a specific
|
|
6
|
+
* fund" applies to every agent a customer runs, so it is defined in one place
|
|
7
|
+
* rather than once per version.
|
|
8
|
+
*
|
|
9
|
+
* Three stages. `input` runs before a model sees the text, `output` before a
|
|
10
|
+
* caller does, and `tool_result` on what a tool returned — the one that
|
|
11
|
+
* matters for an agent rendering structured data, because that never passes
|
|
12
|
+
* through the agent's text and an output guard never sees it.
|
|
13
|
+
*
|
|
14
|
+
* Four actions. `modify` is the useful one: scrubbing a fund name and letting
|
|
15
|
+
* the rest through is better behaviour than refusing the turn.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* await nixet.guardrails.create({
|
|
19
|
+
* name: "pii-scrub",
|
|
20
|
+
* stage: "output",
|
|
21
|
+
* action: "modify",
|
|
22
|
+
* patterns: [{ match: "\\b\\d{12}\\b", replace: "[ACCOUNT]" }],
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* await nixet.agents.versions.create(agentId, {
|
|
26
|
+
* instructions: "…",
|
|
27
|
+
* guardrails: { output: ["pii-scrub"], mode: "run_all" },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* There is no update and no delete. A version pins a guard by name, so
|
|
32
|
+
* renaming one would silently redirect what a published agent applies, and
|
|
33
|
+
* removing one would leave a version naming a rule that no longer exists.
|
|
34
|
+
* Editing a guard's rules does take effect on the next run everywhere it is
|
|
35
|
+
* named, which is the point of defining it at workspace level.
|
|
36
|
+
*/
|
|
37
|
+
export class Guardrails {
|
|
38
|
+
transport;
|
|
39
|
+
constructor(transport) {
|
|
40
|
+
this.transport = transport;
|
|
41
|
+
}
|
|
42
|
+
create(params, options = {}) {
|
|
43
|
+
return this.transport.request({
|
|
44
|
+
method: "POST",
|
|
45
|
+
path: "/guardrails",
|
|
46
|
+
body: params,
|
|
47
|
+
signal: options.signal,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
list(params = {}, options = {}) {
|
|
51
|
+
return this.transport.requestPage({
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/guardrails",
|
|
54
|
+
// Mapped rather than spread: `$limit` is the wire name and `limit` is
|
|
55
|
+
// the one a caller writes, and spreading would send both.
|
|
56
|
+
query: {
|
|
57
|
+
$limit: params.limit,
|
|
58
|
+
$offset: params.offset,
|
|
59
|
+
name: params.name,
|
|
60
|
+
stage: params.stage,
|
|
61
|
+
},
|
|
62
|
+
signal: options.signal,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
retrieve(id, options = {}) {
|
|
66
|
+
return this.transport.request({
|
|
67
|
+
method: "GET",
|
|
68
|
+
path: `/guardrails/${id}`,
|
|
69
|
+
signal: options.signal,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|