@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,94 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { Connection, ConnectionStatus } from "@nixet/contracts";
|
|
3
|
+
import type { ListParams, Page } from "../types.js";
|
|
4
|
+
export interface CreateConnectionParams {
|
|
5
|
+
/** The end user this credential belongs to, as `usr_…`. */
|
|
6
|
+
userId: string;
|
|
7
|
+
/** A registered MCP server whose `auth.type` is `per_user`. */
|
|
8
|
+
server: string;
|
|
9
|
+
/** The credential. Stored encrypted and never returned. */
|
|
10
|
+
value: string;
|
|
11
|
+
/**
|
|
12
|
+
* When it stops working, if you know.
|
|
13
|
+
*
|
|
14
|
+
* Trusted when given: an opaque token says nothing about its own lifetime,
|
|
15
|
+
* so Nixet cannot infer this. Omitted means no known expiry, and a run will
|
|
16
|
+
* use the credential until the provider refuses it.
|
|
17
|
+
*/
|
|
18
|
+
expiresAt?: string;
|
|
19
|
+
/** The refresh token, where the provider issued one. */
|
|
20
|
+
refreshValue?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ListConnectionParams extends ListParams {
|
|
23
|
+
userId?: string;
|
|
24
|
+
server?: string;
|
|
25
|
+
status?: ConnectionStatus;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Connections: an end user's credential for a server you registered once.
|
|
29
|
+
*
|
|
30
|
+
* The split that makes this worth having. A server registration carries one
|
|
31
|
+
* credential, which is right for an integration you own — your GitHub, your
|
|
32
|
+
* internal API. It is wrong when every end user links their own account,
|
|
33
|
+
* because the URL is identical for all of them and only the token differs. A
|
|
34
|
+
* registration per user would force an agent version per user, and version
|
|
35
|
+
* history would stop describing behaviour and become a credential registry.
|
|
36
|
+
*
|
|
37
|
+
* So the provider is registered once with `auth: { type: "per_user" }`, and a
|
|
38
|
+
* connection binds one user to one credential for it. A run naming a user
|
|
39
|
+
* reaches that user's account; the version still decides which servers and
|
|
40
|
+
* which tools, because that is a capability rather than an identity.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* await nixet.mcpServers.create({
|
|
44
|
+
* name: "broker",
|
|
45
|
+
* url: "https://mcp.broker.com/mcp",
|
|
46
|
+
* auth: { type: "per_user", scheme: "api_key" },
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* await nixet.connections.create({
|
|
50
|
+
* userId: user.id,
|
|
51
|
+
* server: "broker",
|
|
52
|
+
* value: userSuppliedKey,
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // The run picks the credential up from the user it names.
|
|
56
|
+
* await nixet.runs.create(agentId, { input: "What do I hold?", userId: user.id });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* A credential is write-only: nothing here returns one, and there is no
|
|
60
|
+
* method that could. A read gives back the scheme, the status and the expiry.
|
|
61
|
+
*
|
|
62
|
+
* `revoke` rather than delete. A run recorded that it authenticated as a
|
|
63
|
+
* connection, and removing the row would leave that run unexplainable, so the
|
|
64
|
+
* credential is erased and the record of it is not.
|
|
65
|
+
*
|
|
66
|
+
* A missing or expired connection fails the run rather than calling the
|
|
67
|
+
* server unauthenticated. Reaching someone's broker as nobody is worse than a
|
|
68
|
+
* refused run, and nothing outside would reveal it had happened.
|
|
69
|
+
*/
|
|
70
|
+
export declare class Connections {
|
|
71
|
+
private readonly transport;
|
|
72
|
+
constructor(transport: Transport);
|
|
73
|
+
/**
|
|
74
|
+
* Store a credential the user already holds.
|
|
75
|
+
*
|
|
76
|
+
* For an `api_key` server, where there is nothing to redirect the user
|
|
77
|
+
* through. Also how a platform that runs its own OAuth pushes a fresh token:
|
|
78
|
+
* creating again for the same user and server replaces nothing, so revoke
|
|
79
|
+
* the old one first.
|
|
80
|
+
*/
|
|
81
|
+
create(params: CreateConnectionParams, options?: {
|
|
82
|
+
signal?: AbortSignal;
|
|
83
|
+
}): Promise<Connection>;
|
|
84
|
+
list(params?: ListConnectionParams, options?: {
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}): Promise<Page<Connection>>;
|
|
87
|
+
retrieve(id: string, options?: {
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
}): Promise<Connection>;
|
|
90
|
+
/** Erase the credential and keep the record that it existed. */
|
|
91
|
+
revoke(id: string, options?: {
|
|
92
|
+
signal?: AbortSignal;
|
|
93
|
+
}): Promise<Connection>;
|
|
94
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Connections = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Connections: an end user's credential for a server you registered once.
|
|
6
|
+
*
|
|
7
|
+
* The split that makes this worth having. A server registration carries one
|
|
8
|
+
* credential, which is right for an integration you own — your GitHub, your
|
|
9
|
+
* internal API. It is wrong when every end user links their own account,
|
|
10
|
+
* because the URL is identical for all of them and only the token differs. A
|
|
11
|
+
* registration per user would force an agent version per user, and version
|
|
12
|
+
* history would stop describing behaviour and become a credential registry.
|
|
13
|
+
*
|
|
14
|
+
* So the provider is registered once with `auth: { type: "per_user" }`, and a
|
|
15
|
+
* connection binds one user to one credential for it. A run naming a user
|
|
16
|
+
* reaches that user's account; the version still decides which servers and
|
|
17
|
+
* which tools, because that is a capability rather than an identity.
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* await nixet.mcpServers.create({
|
|
21
|
+
* name: "broker",
|
|
22
|
+
* url: "https://mcp.broker.com/mcp",
|
|
23
|
+
* auth: { type: "per_user", scheme: "api_key" },
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* await nixet.connections.create({
|
|
27
|
+
* userId: user.id,
|
|
28
|
+
* server: "broker",
|
|
29
|
+
* value: userSuppliedKey,
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // The run picks the credential up from the user it names.
|
|
33
|
+
* await nixet.runs.create(agentId, { input: "What do I hold?", userId: user.id });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* A credential is write-only: nothing here returns one, and there is no
|
|
37
|
+
* method that could. A read gives back the scheme, the status and the expiry.
|
|
38
|
+
*
|
|
39
|
+
* `revoke` rather than delete. A run recorded that it authenticated as a
|
|
40
|
+
* connection, and removing the row would leave that run unexplainable, so the
|
|
41
|
+
* credential is erased and the record of it is not.
|
|
42
|
+
*
|
|
43
|
+
* A missing or expired connection fails the run rather than calling the
|
|
44
|
+
* server unauthenticated. Reaching someone's broker as nobody is worse than a
|
|
45
|
+
* refused run, and nothing outside would reveal it had happened.
|
|
46
|
+
*/
|
|
47
|
+
class Connections {
|
|
48
|
+
transport;
|
|
49
|
+
constructor(transport) {
|
|
50
|
+
this.transport = transport;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Store a credential the user already holds.
|
|
54
|
+
*
|
|
55
|
+
* For an `api_key` server, where there is nothing to redirect the user
|
|
56
|
+
* through. Also how a platform that runs its own OAuth pushes a fresh token:
|
|
57
|
+
* creating again for the same user and server replaces nothing, so revoke
|
|
58
|
+
* the old one first.
|
|
59
|
+
*/
|
|
60
|
+
create(params, options = {}) {
|
|
61
|
+
return this.transport.request({
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: "/mcp/connections",
|
|
64
|
+
body: {
|
|
65
|
+
user_id: params.userId,
|
|
66
|
+
server: params.server,
|
|
67
|
+
value: params.value,
|
|
68
|
+
...(params.expiresAt ? { expires_at: params.expiresAt } : {}),
|
|
69
|
+
...(params.refreshValue ? { refresh_value: params.refreshValue } : {}),
|
|
70
|
+
},
|
|
71
|
+
signal: options.signal,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
list(params = {}, options = {}) {
|
|
75
|
+
return this.transport.requestPage({
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: "/mcp/connections",
|
|
78
|
+
// Mapped rather than spread: `$limit` is the wire name and `limit` is
|
|
79
|
+
// what a caller writes, and spreading would send both.
|
|
80
|
+
query: {
|
|
81
|
+
$limit: params.limit,
|
|
82
|
+
$offset: params.offset,
|
|
83
|
+
user_id: params.userId,
|
|
84
|
+
server: params.server,
|
|
85
|
+
status: params.status,
|
|
86
|
+
},
|
|
87
|
+
signal: options.signal,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
retrieve(id, options = {}) {
|
|
91
|
+
return this.transport.request({
|
|
92
|
+
method: "GET",
|
|
93
|
+
path: `/mcp/connections/${id}`,
|
|
94
|
+
signal: options.signal,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Erase the credential and keep the record that it existed. */
|
|
98
|
+
revoke(id, options = {}) {
|
|
99
|
+
return this.transport.request({
|
|
100
|
+
method: "DELETE",
|
|
101
|
+
path: `/mcp/connections/${id}`,
|
|
102
|
+
signal: options.signal,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.Connections = Connections;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { Conversation, ConversationMessage, ListParams, MemoryPolicy, Page, SendMessageResponse } from "../types.js";
|
|
3
|
+
export interface CreateConversationParams {
|
|
4
|
+
agentId: string;
|
|
5
|
+
/** Who the thread is with. Memory is isolated per user. */
|
|
6
|
+
userId?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Pins a version, so a long thread cannot change behaviour mid-way. */
|
|
9
|
+
agentVersion?: string;
|
|
10
|
+
/** What the agent may remember. Everything is off unless asked for. */
|
|
11
|
+
memory?: Partial<MemoryPolicy>;
|
|
12
|
+
}
|
|
13
|
+
export interface SendMessageParams {
|
|
14
|
+
input: string;
|
|
15
|
+
provider?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Conversations: a durable thread between an agent and a user.
|
|
19
|
+
*
|
|
20
|
+
* Each message creates a run, so cost, usage and the trace work exactly as
|
|
21
|
+
* they do for a single-shot run. The conversation adds the history around them.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* const convo = await nixet.conversations.create({
|
|
25
|
+
* agentId: agent.id,
|
|
26
|
+
* userId: user.id,
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* await nixet.conversations.send(convo.id, { input: "Hi, I'm Sam." });
|
|
30
|
+
* await nixet.conversations.send(convo.id, { input: "What's my name?" });
|
|
31
|
+
* // → "Sam"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class Conversations {
|
|
35
|
+
private readonly transport;
|
|
36
|
+
constructor(transport: Transport);
|
|
37
|
+
create(params: CreateConversationParams, options?: {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<Conversation>;
|
|
40
|
+
retrieve(conversationId: string, options?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<Conversation>;
|
|
43
|
+
list(params?: ListParams & {
|
|
44
|
+
agentId?: string;
|
|
45
|
+
userId?: string;
|
|
46
|
+
}, options?: {
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}): Promise<Page<Conversation>>;
|
|
49
|
+
/** Send a message and wait for the reply. */
|
|
50
|
+
send(conversationId: string, params: SendMessageParams, options?: {
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
}): Promise<SendMessageResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* The full transcript, oldest first.
|
|
55
|
+
*
|
|
56
|
+
* Includes turns a summary has since replaced, so what a person actually
|
|
57
|
+
* said is still readable even after the thread has been compacted.
|
|
58
|
+
*/
|
|
59
|
+
messages(conversationId: string, options?: {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<Page<ConversationMessage>>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Conversations = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Conversations: a durable thread between an agent and a user.
|
|
6
|
+
*
|
|
7
|
+
* Each message creates a run, so cost, usage and the trace work exactly as
|
|
8
|
+
* they do for a single-shot run. The conversation adds the history around them.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const convo = await nixet.conversations.create({
|
|
12
|
+
* agentId: agent.id,
|
|
13
|
+
* userId: user.id,
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* await nixet.conversations.send(convo.id, { input: "Hi, I'm Sam." });
|
|
17
|
+
* await nixet.conversations.send(convo.id, { input: "What's my name?" });
|
|
18
|
+
* // → "Sam"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
class Conversations {
|
|
22
|
+
transport;
|
|
23
|
+
constructor(transport) {
|
|
24
|
+
this.transport = transport;
|
|
25
|
+
}
|
|
26
|
+
create(params, options = {}) {
|
|
27
|
+
return this.transport.request({
|
|
28
|
+
method: "POST",
|
|
29
|
+
path: "/conversations",
|
|
30
|
+
body: {
|
|
31
|
+
agent_id: params.agentId,
|
|
32
|
+
...(params.userId ? { user_id: params.userId } : {}),
|
|
33
|
+
...(params.title ? { title: params.title } : {}),
|
|
34
|
+
...(params.agentVersion ? { agent_version: params.agentVersion } : {}),
|
|
35
|
+
...(params.memory ? { memory: params.memory } : {}),
|
|
36
|
+
},
|
|
37
|
+
signal: options.signal,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
retrieve(conversationId, options = {}) {
|
|
41
|
+
return this.transport.request({
|
|
42
|
+
method: "GET",
|
|
43
|
+
path: `/conversations/${encodeURIComponent(conversationId)}`,
|
|
44
|
+
signal: options.signal,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
list(params = {}, options = {}) {
|
|
48
|
+
return this.transport.requestPage({
|
|
49
|
+
method: "GET",
|
|
50
|
+
path: "/conversations",
|
|
51
|
+
query: {
|
|
52
|
+
$limit: params.limit,
|
|
53
|
+
$offset: params.offset,
|
|
54
|
+
agent_id: params.agentId,
|
|
55
|
+
user_id: params.userId,
|
|
56
|
+
},
|
|
57
|
+
signal: options.signal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Send a message and wait for the reply. */
|
|
61
|
+
send(conversationId, params, options = {}) {
|
|
62
|
+
return this.transport.request({
|
|
63
|
+
method: "POST",
|
|
64
|
+
path: `/conversations/${encodeURIComponent(conversationId)}/messages`,
|
|
65
|
+
body: {
|
|
66
|
+
input: params.input,
|
|
67
|
+
...(params.provider ? { provider: params.provider } : {}),
|
|
68
|
+
},
|
|
69
|
+
signal: options.signal,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The full transcript, oldest first.
|
|
74
|
+
*
|
|
75
|
+
* Includes turns a summary has since replaced, so what a person actually
|
|
76
|
+
* said is still readable even after the thread has been compacted.
|
|
77
|
+
*/
|
|
78
|
+
messages(conversationId, options = {}) {
|
|
79
|
+
return this.transport.requestPage({
|
|
80
|
+
method: "GET",
|
|
81
|
+
path: `/conversations/${encodeURIComponent(conversationId)}/messages`,
|
|
82
|
+
signal: options.signal,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.Conversations = Conversations;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { DocumentConversionResult } from "@nixet/contracts";
|
|
3
|
+
export interface ConvertDocumentParams {
|
|
4
|
+
/**
|
|
5
|
+
* The document.
|
|
6
|
+
*
|
|
7
|
+
* A `Blob` or `File` in a browser and in Node 20+, or a `Uint8Array` with a
|
|
8
|
+
* filename. The name matters only for formats with no signature of their own
|
|
9
|
+
* — CSV is the one that needs it — because the format is otherwise read from
|
|
10
|
+
* the content.
|
|
11
|
+
*/
|
|
12
|
+
file: Blob | Uint8Array;
|
|
13
|
+
/** Required when `file` is bytes rather than a `File`. */
|
|
14
|
+
filename?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Opens a password protected PDF.
|
|
17
|
+
*
|
|
18
|
+
* Used to read the document and then dropped: it is not stored, not logged
|
|
19
|
+
* and not returned. A protected document cannot also be stored in a
|
|
20
|
+
* collection, because nothing would be able to open the original again.
|
|
21
|
+
*/
|
|
22
|
+
password?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Keep the document as a knowledge source in this collection.
|
|
25
|
+
*
|
|
26
|
+
* Omitted, nothing is stored: the bytes live for the length of the request
|
|
27
|
+
* and the Markdown is the whole answer. Named, the document is also chunked
|
|
28
|
+
* and embedded so an agent can search it, which needs `knowledge:write`.
|
|
29
|
+
*/
|
|
30
|
+
collection?: string;
|
|
31
|
+
/** Defaults to the file's own name. Only used when storing. */
|
|
32
|
+
title?: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reading a document.
|
|
37
|
+
*
|
|
38
|
+
* Converts fourteen formats to Markdown — PDF, Word, Excel, PowerPoint and the
|
|
39
|
+
* rest — locally, with no third party seeing the file. A PDF whose pages are
|
|
40
|
+
* scans needs an OCR engine and reports which pages it read that way.
|
|
41
|
+
*
|
|
42
|
+
* Separate from knowledge because the intent is different. A knowledge source
|
|
43
|
+
* is converted so an agent can search it, and what comes back are chunks
|
|
44
|
+
* ordered by similarity. This returns the document.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const { markdown } = await nixet.documents.convert({
|
|
48
|
+
* file: await fs.openAsBlob("statement.pdf"),
|
|
49
|
+
* password: "secret",
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class Documents {
|
|
54
|
+
private readonly transport;
|
|
55
|
+
constructor(transport: Transport);
|
|
56
|
+
/**
|
|
57
|
+
* Convert a document to Markdown.
|
|
58
|
+
*
|
|
59
|
+
* Synchronous: the Markdown is in the response. That holds below the size
|
|
60
|
+
* limit, which is lower than the knowledge upload limit for the same reason
|
|
61
|
+
* — a caller is waiting on this, where an ingested document is converted by
|
|
62
|
+
* a worker that can take as long as it needs.
|
|
63
|
+
*/
|
|
64
|
+
convert(params: ConvertDocumentParams): Promise<DocumentConversionResult>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Documents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Reading a document.
|
|
6
|
+
*
|
|
7
|
+
* Converts fourteen formats to Markdown — PDF, Word, Excel, PowerPoint and the
|
|
8
|
+
* rest — locally, with no third party seeing the file. A PDF whose pages are
|
|
9
|
+
* scans needs an OCR engine and reports which pages it read that way.
|
|
10
|
+
*
|
|
11
|
+
* Separate from knowledge because the intent is different. A knowledge source
|
|
12
|
+
* is converted so an agent can search it, and what comes back are chunks
|
|
13
|
+
* ordered by similarity. This returns the document.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { markdown } = await nixet.documents.convert({
|
|
17
|
+
* file: await fs.openAsBlob("statement.pdf"),
|
|
18
|
+
* password: "secret",
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
class Documents {
|
|
23
|
+
transport;
|
|
24
|
+
constructor(transport) {
|
|
25
|
+
this.transport = transport;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert a document to Markdown.
|
|
29
|
+
*
|
|
30
|
+
* Synchronous: the Markdown is in the response. That holds below the size
|
|
31
|
+
* limit, which is lower than the knowledge upload limit for the same reason
|
|
32
|
+
* — a caller is waiting on this, where an ingested document is converted by
|
|
33
|
+
* a worker that can take as long as it needs.
|
|
34
|
+
*/
|
|
35
|
+
async convert(params) {
|
|
36
|
+
const form = new FormData();
|
|
37
|
+
// A Blob keeps its own name; bytes need one supplied. `document` is the
|
|
38
|
+
// fallback rather than an error, because the name is only consulted for
|
|
39
|
+
// signature-less formats.
|
|
40
|
+
if (params.file instanceof Blob) {
|
|
41
|
+
form.append("file", params.file, params.filename ?? "document");
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
form.append("file", new Blob([params.file]), params.filename ?? "document");
|
|
45
|
+
}
|
|
46
|
+
if (params.password)
|
|
47
|
+
form.append("password", params.password);
|
|
48
|
+
if (params.collection)
|
|
49
|
+
form.append("collection", params.collection);
|
|
50
|
+
if (params.title)
|
|
51
|
+
form.append("title", params.title);
|
|
52
|
+
return this.transport.request({
|
|
53
|
+
method: "POST",
|
|
54
|
+
path: "/documents/convert",
|
|
55
|
+
body: form,
|
|
56
|
+
form: true,
|
|
57
|
+
signal: params.signal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Documents = Documents;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Transport } from "../transport.js";
|
|
2
|
+
import type { CreateGuardrailRequest, Guardrail, GuardrailStage } from "@nixet/contracts";
|
|
3
|
+
import type { ListParams, Page } from "../types.js";
|
|
4
|
+
export interface ListGuardrailParams extends ListParams {
|
|
5
|
+
name?: string;
|
|
6
|
+
stage?: GuardrailStage;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Guardrails: what an agent may be given, and what it may say.
|
|
10
|
+
*
|
|
11
|
+
* Defined once for the workspace and named by a version, the same way MCP
|
|
12
|
+
* servers and knowledge collections are. A rule like "never name a specific
|
|
13
|
+
* fund" applies to every agent a customer runs, so it is defined in one place
|
|
14
|
+
* rather than once per version.
|
|
15
|
+
*
|
|
16
|
+
* Three stages. `input` runs before a model sees the text, `output` before a
|
|
17
|
+
* caller does, and `tool_result` on what a tool returned — the one that
|
|
18
|
+
* matters for an agent rendering structured data, because that never passes
|
|
19
|
+
* through the agent's text and an output guard never sees it.
|
|
20
|
+
*
|
|
21
|
+
* Four actions. `modify` is the useful one: scrubbing a fund name and letting
|
|
22
|
+
* the rest through is better behaviour than refusing the turn.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* await nixet.guardrails.create({
|
|
26
|
+
* name: "pii-scrub",
|
|
27
|
+
* stage: "output",
|
|
28
|
+
* action: "modify",
|
|
29
|
+
* patterns: [{ match: "\\b\\d{12}\\b", replace: "[ACCOUNT]" }],
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await nixet.agents.versions.create(agentId, {
|
|
33
|
+
* instructions: "…",
|
|
34
|
+
* guardrails: { output: ["pii-scrub"], mode: "run_all" },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* There is no update and no delete. A version pins a guard by name, so
|
|
39
|
+
* renaming one would silently redirect what a published agent applies, and
|
|
40
|
+
* removing one would leave a version naming a rule that no longer exists.
|
|
41
|
+
* Editing a guard's rules does take effect on the next run everywhere it is
|
|
42
|
+
* named, which is the point of defining it at workspace level.
|
|
43
|
+
*/
|
|
44
|
+
export declare class Guardrails {
|
|
45
|
+
private readonly transport;
|
|
46
|
+
constructor(transport: Transport);
|
|
47
|
+
create(params: CreateGuardrailRequest, options?: {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}): Promise<Guardrail>;
|
|
50
|
+
list(params?: ListGuardrailParams, options?: {
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
}): Promise<Page<Guardrail>>;
|
|
53
|
+
retrieve(id: string, options?: {
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}): Promise<Guardrail>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Guardrails = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Guardrails: what an agent may be given, and what it may say.
|
|
6
|
+
*
|
|
7
|
+
* Defined once for the workspace and named by a version, the same way MCP
|
|
8
|
+
* servers and knowledge collections are. A rule like "never name a specific
|
|
9
|
+
* fund" applies to every agent a customer runs, so it is defined in one place
|
|
10
|
+
* rather than once per version.
|
|
11
|
+
*
|
|
12
|
+
* Three stages. `input` runs before a model sees the text, `output` before a
|
|
13
|
+
* caller does, and `tool_result` on what a tool returned — the one that
|
|
14
|
+
* matters for an agent rendering structured data, because that never passes
|
|
15
|
+
* through the agent's text and an output guard never sees it.
|
|
16
|
+
*
|
|
17
|
+
* Four actions. `modify` is the useful one: scrubbing a fund name and letting
|
|
18
|
+
* the rest through is better behaviour than refusing the turn.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* await nixet.guardrails.create({
|
|
22
|
+
* name: "pii-scrub",
|
|
23
|
+
* stage: "output",
|
|
24
|
+
* action: "modify",
|
|
25
|
+
* patterns: [{ match: "\\b\\d{12}\\b", replace: "[ACCOUNT]" }],
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* await nixet.agents.versions.create(agentId, {
|
|
29
|
+
* instructions: "…",
|
|
30
|
+
* guardrails: { output: ["pii-scrub"], mode: "run_all" },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* There is no update and no delete. A version pins a guard by name, so
|
|
35
|
+
* renaming one would silently redirect what a published agent applies, and
|
|
36
|
+
* removing one would leave a version naming a rule that no longer exists.
|
|
37
|
+
* Editing a guard's rules does take effect on the next run everywhere it is
|
|
38
|
+
* named, which is the point of defining it at workspace level.
|
|
39
|
+
*/
|
|
40
|
+
class Guardrails {
|
|
41
|
+
transport;
|
|
42
|
+
constructor(transport) {
|
|
43
|
+
this.transport = transport;
|
|
44
|
+
}
|
|
45
|
+
create(params, options = {}) {
|
|
46
|
+
return this.transport.request({
|
|
47
|
+
method: "POST",
|
|
48
|
+
path: "/guardrails",
|
|
49
|
+
body: params,
|
|
50
|
+
signal: options.signal,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
list(params = {}, options = {}) {
|
|
54
|
+
return this.transport.requestPage({
|
|
55
|
+
method: "GET",
|
|
56
|
+
path: "/guardrails",
|
|
57
|
+
// Mapped rather than spread: `$limit` is the wire name and `limit` is
|
|
58
|
+
// the one a caller writes, and spreading would send both.
|
|
59
|
+
query: {
|
|
60
|
+
$limit: params.limit,
|
|
61
|
+
$offset: params.offset,
|
|
62
|
+
name: params.name,
|
|
63
|
+
stage: params.stage,
|
|
64
|
+
},
|
|
65
|
+
signal: options.signal,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
retrieve(id, options = {}) {
|
|
69
|
+
return this.transport.request({
|
|
70
|
+
method: "GET",
|
|
71
|
+
path: `/guardrails/${id}`,
|
|
72
|
+
signal: options.signal,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Guardrails = Guardrails;
|