@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,537 @@
|
|
|
1
|
+
/** Public types, mirroring the wire contract in camelCase-free form. */
|
|
2
|
+
export type Provider = "nix" | "openai" | "anthropic";
|
|
3
|
+
export type Tier = "fast" | "balanced" | "powerful";
|
|
4
|
+
export type RunStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
|
|
5
|
+
export type RunEventType = "run.started" | "run.completed" | "run.failed" | "run.cancelled" | "run.paused" | "run.continued" | "run.output" | "run.model.started" | "run.model.completed" | "run.tool.started" | "run.tool.completed" | "run.tool.failed" | "run.knowledge.started" | "run.knowledge.completed" | "run.memory.recall.started" | "run.memory.recall.completed" | "run.memory.update.started" | "run.memory.update.completed" | "run.reasoning.started" | "run.reasoning.completed" | "run.subagent.spawned" | "run.subagent.completed" | "run.subagent.failed" | "run.subagent.killed" | "run.workflow.step.started" | "run.workflow.step.completed" | "run.workflow.step.failed" | "run.workflow.step.skipped" | "run.task.created" | "run.task.status" | "run.session.summarised" | "run.context.compressed"
|
|
6
|
+
/** A skill was loaded into the agent, before the first model call. */
|
|
7
|
+
| "run.skill.loaded";
|
|
8
|
+
/**
|
|
9
|
+
* What an event describes.
|
|
10
|
+
*
|
|
11
|
+
* Coarser than the type, so a timeline can be grouped or filtered without
|
|
12
|
+
* knowing every individual event.
|
|
13
|
+
*/
|
|
14
|
+
export type EventCategory = "run" | "model" | "tool" | "output" | "memory" | "knowledge" | "reasoning" | "approval" | "subagent" | "workflow" | "task" | "session" | "context" | "skill";
|
|
15
|
+
/** Token counts for one span, where the provider reports them. */
|
|
16
|
+
export interface EventTokens {
|
|
17
|
+
input?: number;
|
|
18
|
+
output?: number;
|
|
19
|
+
cache_read?: number;
|
|
20
|
+
reasoning?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Agent {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description: string | null;
|
|
26
|
+
/** Version used when a run does not name one. Null until the first publish. */
|
|
27
|
+
current_version: string | null;
|
|
28
|
+
created_at: string;
|
|
29
|
+
updated_at: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Model selection.
|
|
33
|
+
*
|
|
34
|
+
* `nix` is managed and picks a model from `tier`. The other providers need an
|
|
35
|
+
* explicit `model`, because the caller is paying for it.
|
|
36
|
+
*/
|
|
37
|
+
export type ModelConfig = {
|
|
38
|
+
provider?: "nix";
|
|
39
|
+
tier?: Tier;
|
|
40
|
+
temperature?: number;
|
|
41
|
+
max_tokens?: number;
|
|
42
|
+
} | {
|
|
43
|
+
provider: "openai" | "anthropic";
|
|
44
|
+
model: string;
|
|
45
|
+
temperature?: number;
|
|
46
|
+
max_tokens?: number;
|
|
47
|
+
};
|
|
48
|
+
export interface ToolRef {
|
|
49
|
+
name: string;
|
|
50
|
+
}
|
|
51
|
+
export interface AgentVersion {
|
|
52
|
+
id: string;
|
|
53
|
+
agent_id: string;
|
|
54
|
+
version: string;
|
|
55
|
+
instructions: string;
|
|
56
|
+
model: ModelConfig;
|
|
57
|
+
tools: ToolRef[];
|
|
58
|
+
/**
|
|
59
|
+
* Skills this version uses, each already pinned to one version. A bare name
|
|
60
|
+
* resolving at run time would make a past run unreproducible.
|
|
61
|
+
*/
|
|
62
|
+
skills: ResolvedSkill[];
|
|
63
|
+
/** Masking applied to run input and output. Part of the digest. */
|
|
64
|
+
redaction: RedactionPolicy;
|
|
65
|
+
/** MCP servers this version may use, pinned by name at publish. */
|
|
66
|
+
mcp_servers: string[];
|
|
67
|
+
/** Per-tool overrides as `server.tool`. Only the exceptions are stored. */
|
|
68
|
+
tool_policies: Record<string, ToolPolicy>;
|
|
69
|
+
/** Knowledge collections this version may search, pinned by name. */
|
|
70
|
+
knowledge_collections: string[];
|
|
71
|
+
/**
|
|
72
|
+
* Placeholders in `instructions` that a run must supply.
|
|
73
|
+
*
|
|
74
|
+
* Read this to know what a run needs: every name here is required on
|
|
75
|
+
* `variables`, and nothing outside it is accepted.
|
|
76
|
+
*/
|
|
77
|
+
variables: string[];
|
|
78
|
+
/** Guardrails this version runs, pinned by name at publish. */
|
|
79
|
+
guardrails: GuardrailBinding;
|
|
80
|
+
/** Content hash of the frozen configuration; recorded on every run. */
|
|
81
|
+
digest: string;
|
|
82
|
+
created_at: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Which guardrails a version runs, and what a block does.
|
|
86
|
+
*
|
|
87
|
+
* Order is the order given: under `run_all` each guard sees the text the
|
|
88
|
+
* previous one produced.
|
|
89
|
+
*/
|
|
90
|
+
export interface GuardrailBinding {
|
|
91
|
+
input: string[];
|
|
92
|
+
output: string[];
|
|
93
|
+
tool_result: string[];
|
|
94
|
+
mode: "run_all" | "fail_fast";
|
|
95
|
+
on_block: "return_message" | "error";
|
|
96
|
+
}
|
|
97
|
+
export interface Usage {
|
|
98
|
+
input_tokens: number;
|
|
99
|
+
output_tokens: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* How much of a run's input and output is masked before dispatch.
|
|
103
|
+
*
|
|
104
|
+
* Only `structured` is entirely checksum-validated. `standard` covers every
|
|
105
|
+
* category that identifies a person; `strict` adds the company they work for.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* What a version returns, which is the wire shape.
|
|
109
|
+
*
|
|
110
|
+
* Distinct from `RedactionPolicyInput` because the API speaks snake_case and
|
|
111
|
+
* the SDK does not translate a response. Claiming otherwise would hand back an
|
|
112
|
+
* object whose fields are all undefined.
|
|
113
|
+
*/
|
|
114
|
+
export interface RedactionPolicy {
|
|
115
|
+
mode: RedactionMode;
|
|
116
|
+
reversible: boolean;
|
|
117
|
+
minimum_confidence: number;
|
|
118
|
+
labels?: RedactionLabel[];
|
|
119
|
+
retain_for: "1h" | "24h" | "7d" | "30d";
|
|
120
|
+
}
|
|
121
|
+
/** What a caller passes when publishing a version. */
|
|
122
|
+
export interface RedactionPolicyInput {
|
|
123
|
+
mode: RedactionMode;
|
|
124
|
+
/** Keep the map so the reply can be restored. Off by default. */
|
|
125
|
+
reversible?: boolean;
|
|
126
|
+
/** Confidence floor for model-inferred labels. Structured labels ignore it. */
|
|
127
|
+
minimumConfidence?: number;
|
|
128
|
+
/** Narrows the mode to these categories. Rarely needed. */
|
|
129
|
+
labels?: RedactionLabel[];
|
|
130
|
+
/** How long a reversible map is kept. */
|
|
131
|
+
retainFor?: "1h" | "24h" | "7d" | "30d";
|
|
132
|
+
}
|
|
133
|
+
/** Detection categories the redactor reports. */
|
|
134
|
+
export type RedactionLabel = "GIVEN_NAME" | "SURNAME" | "STREET_NAME" | "BUILDING_NUMBER" | "SECONDARY_ADDRESS" | "CITY" | "STATE" | "ZIP_CODE" | "EMAIL" | "PHONE" | "CREDIT_CARD" | "BANK_ACCOUNT" | "ROUTING_NUMBER" | "IP_ADDRESS" | "URL" | "GOVERNMENT_ID" | "PASSPORT" | "DRIVERS_LICENSE" | "TAX_ID" | "SSN" | "IMEI" | "ORG";
|
|
135
|
+
export type RedactionMode = "off" | "structured" | "standard" | "strict";
|
|
136
|
+
/**
|
|
137
|
+
* What a run masked.
|
|
138
|
+
*
|
|
139
|
+
* Counts only. The masked values are the personal data the run removed, so they
|
|
140
|
+
* are never returned.
|
|
141
|
+
*/
|
|
142
|
+
export interface RedactionSummary {
|
|
143
|
+
mode: RedactionMode;
|
|
144
|
+
reversible: boolean;
|
|
145
|
+
counts: Partial<Record<RedactionLabel, number>>;
|
|
146
|
+
item_count: number;
|
|
147
|
+
/** When the stored map is destroyed. Null when the run kept none. */
|
|
148
|
+
expires_at: string | null;
|
|
149
|
+
}
|
|
150
|
+
export interface Run {
|
|
151
|
+
id: string;
|
|
152
|
+
agent_id: string;
|
|
153
|
+
agent_version: string;
|
|
154
|
+
/** Placeholder values this run was given. Null when the version declared none. */
|
|
155
|
+
variables: Record<string, string> | null;
|
|
156
|
+
version_digest: string;
|
|
157
|
+
status: RunStatus;
|
|
158
|
+
provider: Provider;
|
|
159
|
+
/** Masked when the version redacts: what was stored, not what was sent. */
|
|
160
|
+
input: string;
|
|
161
|
+
output: string | null;
|
|
162
|
+
error: string | null;
|
|
163
|
+
usage: Usage | null;
|
|
164
|
+
/** What was masked, as counts. Null when the version does not redact. */
|
|
165
|
+
redaction: RedactionSummary | null;
|
|
166
|
+
/** Wall-clock duration of the run. */
|
|
167
|
+
latency_ms: number | null;
|
|
168
|
+
/** Total USD, summed from the run's model calls. */
|
|
169
|
+
cost_usd: number | null;
|
|
170
|
+
trace_id: string | null;
|
|
171
|
+
session_id: string | null;
|
|
172
|
+
created_at: string;
|
|
173
|
+
completed_at: string | null;
|
|
174
|
+
}
|
|
175
|
+
export interface RunEvent {
|
|
176
|
+
/** Monotonic within a run, so a dropped stream can resume. */
|
|
177
|
+
sequence: number;
|
|
178
|
+
type: RunEventType;
|
|
179
|
+
category: EventCategory;
|
|
180
|
+
run_id: string;
|
|
181
|
+
/** Short label: a text delta, a tool name, or a failure reason. */
|
|
182
|
+
data: string | null;
|
|
183
|
+
/**
|
|
184
|
+
* Fields specific to this event type. Shapes differ by category: a tool event
|
|
185
|
+
* carries arguments and a result, a knowledge event carries documents found.
|
|
186
|
+
*/
|
|
187
|
+
payload: Record<string, unknown> | null;
|
|
188
|
+
duration_ms: number | null;
|
|
189
|
+
tokens: EventTokens | null;
|
|
190
|
+
/** Computed from tokens; null when the model has no published rate. */
|
|
191
|
+
cost_usd: number | null;
|
|
192
|
+
/**
|
|
193
|
+
* The event that produced this one, so a trace reads as a tree. A sub-agent's
|
|
194
|
+
* events point at the event that spawned it.
|
|
195
|
+
*/
|
|
196
|
+
parent_event_id: string | null;
|
|
197
|
+
created_at: string;
|
|
198
|
+
}
|
|
199
|
+
export interface Identity {
|
|
200
|
+
key_id: string | null;
|
|
201
|
+
organization_id: string;
|
|
202
|
+
project_id: string;
|
|
203
|
+
environment_id: "development" | "production";
|
|
204
|
+
permissions: string[];
|
|
205
|
+
}
|
|
206
|
+
/** A list response. `count` is the total, not the page length. */
|
|
207
|
+
export interface Page<T> {
|
|
208
|
+
data: T[];
|
|
209
|
+
count: number;
|
|
210
|
+
}
|
|
211
|
+
export interface ListParams {
|
|
212
|
+
limit?: number;
|
|
213
|
+
offset?: number;
|
|
214
|
+
}
|
|
215
|
+
export interface Skill {
|
|
216
|
+
id: string;
|
|
217
|
+
name: string;
|
|
218
|
+
description: string | null;
|
|
219
|
+
current_version: string | null;
|
|
220
|
+
created_at: string;
|
|
221
|
+
updated_at: string;
|
|
222
|
+
}
|
|
223
|
+
export interface SkillVersion {
|
|
224
|
+
id: string;
|
|
225
|
+
skill_id: string;
|
|
226
|
+
version: string;
|
|
227
|
+
instructions: string;
|
|
228
|
+
tools: ToolRef[];
|
|
229
|
+
digest: string;
|
|
230
|
+
created_at: string;
|
|
231
|
+
}
|
|
232
|
+
/** A skill as pinned on an agent version. */
|
|
233
|
+
export interface ResolvedSkill {
|
|
234
|
+
name: string;
|
|
235
|
+
version: string;
|
|
236
|
+
digest: string;
|
|
237
|
+
}
|
|
238
|
+
/** A person your agent serves. Not a Nixet console member. */
|
|
239
|
+
export interface User {
|
|
240
|
+
id: string;
|
|
241
|
+
reference: string;
|
|
242
|
+
email: string | null;
|
|
243
|
+
name: string | null;
|
|
244
|
+
metadata: Record<string, unknown>;
|
|
245
|
+
created_at: string;
|
|
246
|
+
updated_at: string;
|
|
247
|
+
}
|
|
248
|
+
/** What an agent may remember. Everything is off unless asked for. */
|
|
249
|
+
export interface MemoryPolicy {
|
|
250
|
+
conversation: boolean;
|
|
251
|
+
user: boolean;
|
|
252
|
+
agent: boolean;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Every state a task can report.
|
|
256
|
+
*
|
|
257
|
+
* Four of these are declared but not yet produced: nothing pauses a task or
|
|
258
|
+
* waits for a tool, an approval or a user until tools and policies exist. They
|
|
259
|
+
* are in the union so adding them later is not a breaking change.
|
|
260
|
+
*/
|
|
261
|
+
export type TaskStatus = "queued" | "running" | "waiting_for_tool" | "waiting_for_approval" | "waiting_for_user" | "paused" | "completed" | "failed" | "cancelled";
|
|
262
|
+
/** Work that outlives the request that asked for it. */
|
|
263
|
+
export interface Task {
|
|
264
|
+
id: string;
|
|
265
|
+
agent_id: string;
|
|
266
|
+
/** Pinned when the task was queued, not when it runs. */
|
|
267
|
+
agent_version: string;
|
|
268
|
+
version_digest: string;
|
|
269
|
+
status: TaskStatus;
|
|
270
|
+
input: string;
|
|
271
|
+
output: string | null;
|
|
272
|
+
error: string | null;
|
|
273
|
+
/** Where the trace, events and cost live. Null until a worker starts it. */
|
|
274
|
+
run_id: string | null;
|
|
275
|
+
conversation_id: string | null;
|
|
276
|
+
user_id: string | null;
|
|
277
|
+
attempt: number;
|
|
278
|
+
max_attempts: number;
|
|
279
|
+
/** Set while a failed task waits out its backoff. */
|
|
280
|
+
run_after: string | null;
|
|
281
|
+
created_at: string;
|
|
282
|
+
updated_at: string;
|
|
283
|
+
completed_at: string | null;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* A credential you gave us so an agent can reach something of yours.
|
|
287
|
+
*
|
|
288
|
+
* There is no `value`: the API has no route that returns one. Everything that
|
|
289
|
+
* uses a secret names it, so a configuration can be read and versioned without
|
|
290
|
+
* the credential travelling with it.
|
|
291
|
+
*/
|
|
292
|
+
export interface Secret {
|
|
293
|
+
id: string;
|
|
294
|
+
name: string;
|
|
295
|
+
description: string | null;
|
|
296
|
+
/** A few characters, enough to tell two secrets apart and useless otherwise. */
|
|
297
|
+
hint: string;
|
|
298
|
+
created_at: string;
|
|
299
|
+
updated_at: string;
|
|
300
|
+
}
|
|
301
|
+
/** Remote only. `stdio` would mean running your process inside our runtime. */
|
|
302
|
+
export type McpTransport = "http" | "sse";
|
|
303
|
+
/**
|
|
304
|
+
* How an end user's credential for a server was obtained.
|
|
305
|
+
*
|
|
306
|
+
* `api_key` is supplied directly and does not expire. `oauth2` sends the user
|
|
307
|
+
* through a consent screen and expires. `session` is a session identifier a
|
|
308
|
+
* tool on the server returns, with nothing to refresh it — expiry means
|
|
309
|
+
* signing in again, which is why it is not a short-lived `oauth2`.
|
|
310
|
+
*/
|
|
311
|
+
export type McpConnectionScheme = "api_key" | "oauth2" | "session";
|
|
312
|
+
/**
|
|
313
|
+
* How Nixet proves who it is to your server.
|
|
314
|
+
*
|
|
315
|
+
* The first four name a stored secret rather than carrying a token, so a
|
|
316
|
+
* configuration can be read and copied without the credential. `oauth` is an
|
|
317
|
+
* access token you obtained yourself: Nixet does not run that flow, so an
|
|
318
|
+
* expired token is replaced rather than refreshed.
|
|
319
|
+
*
|
|
320
|
+
* `per_user` names no secret at all. The credential belongs to an end user
|
|
321
|
+
* rather than the workspace, so the server is registered once and a run
|
|
322
|
+
* resolves whose account it reaches from the user it names. Without it, the
|
|
323
|
+
* same URL for every user would need one registration per user, and that
|
|
324
|
+
* would force one agent version per user.
|
|
325
|
+
*/
|
|
326
|
+
export type McpAuth = {
|
|
327
|
+
type: "none";
|
|
328
|
+
} | {
|
|
329
|
+
type: "bearer";
|
|
330
|
+
secret: string;
|
|
331
|
+
} | {
|
|
332
|
+
type: "header";
|
|
333
|
+
header: string;
|
|
334
|
+
secret: string;
|
|
335
|
+
} | {
|
|
336
|
+
type: "oauth";
|
|
337
|
+
secret: string;
|
|
338
|
+
} | {
|
|
339
|
+
type: "per_user";
|
|
340
|
+
scheme: McpConnectionScheme;
|
|
341
|
+
};
|
|
342
|
+
/** What a tool does, as far as anyone can tell. */
|
|
343
|
+
export type ToolTag = "read" | "write" | "destructive" | "external";
|
|
344
|
+
/** What Nixet does when an agent reaches for a tool. */
|
|
345
|
+
export type ToolPolicy = "allow" | "ask" | "deny";
|
|
346
|
+
/**
|
|
347
|
+
* A tool your server advertised the last time we asked.
|
|
348
|
+
*
|
|
349
|
+
* `tags` are a claim rather than a guarantee. Where they came from the server's
|
|
350
|
+
* own annotations, that is the server describing itself, and the MCP
|
|
351
|
+
* specification is explicit that a server can claim `readOnlyHint: true` and
|
|
352
|
+
* delete your files anyway. Tags decide what you are shown and which default
|
|
353
|
+
* applies; what Nixet permits is the policy, and that is yours.
|
|
354
|
+
*/
|
|
355
|
+
export interface McpTool {
|
|
356
|
+
id: string;
|
|
357
|
+
server_id: string;
|
|
358
|
+
/** The handle an agent version pins, and how a policy addresses this tool. */
|
|
359
|
+
server_name: string;
|
|
360
|
+
name: string;
|
|
361
|
+
description: string | null;
|
|
362
|
+
tags: ToolTag[];
|
|
363
|
+
/** `server` where it annotated itself, `inferred` where we read the name. */
|
|
364
|
+
tag_source: "server" | "inferred";
|
|
365
|
+
annotations: Record<string, unknown> | null;
|
|
366
|
+
/** What this tool gets when a version does not name it. */
|
|
367
|
+
default_policy: ToolPolicy;
|
|
368
|
+
discovered_at: string;
|
|
369
|
+
updated_at: string;
|
|
370
|
+
}
|
|
371
|
+
export interface McpServer {
|
|
372
|
+
id: string;
|
|
373
|
+
/** The handle an agent version pins, e.g. `github`. */
|
|
374
|
+
name: string;
|
|
375
|
+
description: string | null;
|
|
376
|
+
transport: McpTransport;
|
|
377
|
+
url: string;
|
|
378
|
+
auth: McpAuth;
|
|
379
|
+
/** Discovered at registration. Zero where the server could not be reached. */
|
|
380
|
+
tool_count: number;
|
|
381
|
+
tools_refreshed_at: string | null;
|
|
382
|
+
/** Why the last connection failed, when it did. */
|
|
383
|
+
last_error: string | null;
|
|
384
|
+
created_at: string;
|
|
385
|
+
updated_at: string;
|
|
386
|
+
}
|
|
387
|
+
/** Where a source's content came from. */
|
|
388
|
+
export type SourceKind = "file" | "text" | "url";
|
|
389
|
+
/**
|
|
390
|
+
* How far a source has got.
|
|
391
|
+
*
|
|
392
|
+
* Named after the step in progress rather than a generic "processing", so a
|
|
393
|
+
* customer waiting on a slow document can see whether it is being OCR'd — the
|
|
394
|
+
* one step that takes minutes rather than milliseconds. `ready` and `failed`
|
|
395
|
+
* are the only states nothing further happens from.
|
|
396
|
+
*/
|
|
397
|
+
export type SourceStatus = "pending" | "converting" | "ocr" | "chunking" | "embedding" | "ready" | "failed";
|
|
398
|
+
/**
|
|
399
|
+
* How a collection splits a document.
|
|
400
|
+
*
|
|
401
|
+
* `markdown` follows headings, which suits documents with a structure worth
|
|
402
|
+
* preserving. `recursive` splits on paragraph and sentence boundaries and is
|
|
403
|
+
* the safe default for prose that has none.
|
|
404
|
+
*/
|
|
405
|
+
export type ChunkStrategy = "markdown" | "recursive";
|
|
406
|
+
/**
|
|
407
|
+
* A named index an agent version pins so it can search your own documents.
|
|
408
|
+
*
|
|
409
|
+
* The chunk settings are fixed at creation. Half a collection split at 1000
|
|
410
|
+
* characters and half at 400 retrieves badly, and there is no honest way to
|
|
411
|
+
* report which half a run searched, so re-chunking means another collection
|
|
412
|
+
* rather than an edit to this one.
|
|
413
|
+
*/
|
|
414
|
+
export interface KnowledgeCollection {
|
|
415
|
+
id: string;
|
|
416
|
+
/** The handle a version pins, e.g. `support-policies`. */
|
|
417
|
+
name: string;
|
|
418
|
+
description: string | null;
|
|
419
|
+
chunk_strategy: ChunkStrategy;
|
|
420
|
+
chunk_size: number;
|
|
421
|
+
chunk_overlap: number;
|
|
422
|
+
/**
|
|
423
|
+
* The model that embedded every chunk in here. Reported rather than chosen:
|
|
424
|
+
* the vectors in one collection are only comparable because one model
|
|
425
|
+
* produced them all.
|
|
426
|
+
*/
|
|
427
|
+
embedding_model: string;
|
|
428
|
+
/** Sources in this collection, whatever their status. */
|
|
429
|
+
source_count: number;
|
|
430
|
+
/** Chunks across every source that reached `ready`. */
|
|
431
|
+
chunk_count: number;
|
|
432
|
+
created_at: string;
|
|
433
|
+
updated_at: string;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* One document inside a collection.
|
|
437
|
+
*
|
|
438
|
+
* The chunks it produced are not here: they carry an embedding and live beside
|
|
439
|
+
* the vector index that searches them, so a hundred chunks of one PDF are not
|
|
440
|
+
* returned in a response about that PDF. Neither is the document's own text —
|
|
441
|
+
* this describes a document rather than containing it.
|
|
442
|
+
*/
|
|
443
|
+
export interface KnowledgeSource {
|
|
444
|
+
id: string;
|
|
445
|
+
collection_id: string;
|
|
446
|
+
/** The collection's handle, so a source reads without a second call. */
|
|
447
|
+
collection_name: string;
|
|
448
|
+
kind: SourceKind;
|
|
449
|
+
/** A file's original name, a URL, or a title given to pasted text. */
|
|
450
|
+
title: string;
|
|
451
|
+
/** Whether an agent can search this yet. Ingestion happens after the call. */
|
|
452
|
+
status: SourceStatus;
|
|
453
|
+
/** Why ingestion failed, when it did. */
|
|
454
|
+
error: string | null;
|
|
455
|
+
/** Bytes of the original. Zero for text that was pasted rather than uploaded. */
|
|
456
|
+
size: number;
|
|
457
|
+
mime_type: string | null;
|
|
458
|
+
checksum: string | null;
|
|
459
|
+
/** How many chunks this source produced. Zero until it is `ready`. */
|
|
460
|
+
chunk_count: number;
|
|
461
|
+
/**
|
|
462
|
+
* Pages that needed OCR, and how many there were, so "2 of 340 pages were
|
|
463
|
+
* scanned" answers why ingestion was slow.
|
|
464
|
+
*/
|
|
465
|
+
ocr_pages: number[] | null;
|
|
466
|
+
page_count: number | null;
|
|
467
|
+
/**
|
|
468
|
+
* The page a `url` source was actually read from, when a redirect moved it.
|
|
469
|
+
* Null when nothing redirected, and for every other kind — `title` holds the
|
|
470
|
+
* address that was asked for either way.
|
|
471
|
+
*/
|
|
472
|
+
fetched_url: string | null;
|
|
473
|
+
/**
|
|
474
|
+
* Increments when a source is re-ingested. The chunks of an older generation
|
|
475
|
+
* stay in the store, so a run that already happened can still be explained
|
|
476
|
+
* by what it actually searched.
|
|
477
|
+
*/
|
|
478
|
+
generation: number;
|
|
479
|
+
created_at: string;
|
|
480
|
+
updated_at: string;
|
|
481
|
+
}
|
|
482
|
+
export interface Conversation {
|
|
483
|
+
id: string;
|
|
484
|
+
agent_id: string;
|
|
485
|
+
/** Pinned at creation, so a long thread cannot change behaviour. */
|
|
486
|
+
agent_version: string | null;
|
|
487
|
+
user_id: string | null;
|
|
488
|
+
title: string | null;
|
|
489
|
+
status: "open" | "closed";
|
|
490
|
+
memory: MemoryPolicy;
|
|
491
|
+
message_count: number;
|
|
492
|
+
last_run_id: string | null;
|
|
493
|
+
created_at: string;
|
|
494
|
+
updated_at: string;
|
|
495
|
+
}
|
|
496
|
+
export interface ConversationMessage {
|
|
497
|
+
id: string;
|
|
498
|
+
conversation_id: string;
|
|
499
|
+
/** Monotonic within a conversation. */
|
|
500
|
+
sequence: number;
|
|
501
|
+
role: "user" | "assistant" | "system" | "summary";
|
|
502
|
+
content: string;
|
|
503
|
+
run_id: string | null;
|
|
504
|
+
token_count: number | null;
|
|
505
|
+
created_at: string;
|
|
506
|
+
}
|
|
507
|
+
/** What a send returns: the reply, and the run that produced it. */
|
|
508
|
+
export interface SendMessageResponse {
|
|
509
|
+
message: ConversationMessage;
|
|
510
|
+
run_id: string;
|
|
511
|
+
usage: {
|
|
512
|
+
input_tokens: number;
|
|
513
|
+
output_tokens: number;
|
|
514
|
+
} | null;
|
|
515
|
+
cost_usd: number | null;
|
|
516
|
+
}
|
|
517
|
+
/** Who a memory belongs to. */
|
|
518
|
+
export type MemoryScope = "conversation" | "user" | "agent";
|
|
519
|
+
/** A remembered fact. */
|
|
520
|
+
export interface MemoryRow {
|
|
521
|
+
id: string | null;
|
|
522
|
+
content: string;
|
|
523
|
+
/** Similarity to the query, 0 to 1. Null when not from a search. */
|
|
524
|
+
score: number | null;
|
|
525
|
+
scope: MemoryScope;
|
|
526
|
+
metadata: Record<string, unknown>;
|
|
527
|
+
/**
|
|
528
|
+
* Set when a later fact replaced this one. The store adds rather than
|
|
529
|
+
* updates, so both survive and the older is marked instead of removed.
|
|
530
|
+
*/
|
|
531
|
+
superseded: boolean;
|
|
532
|
+
superseded_by: string | null;
|
|
533
|
+
/** Set when a memory stops being recalled after a date. */
|
|
534
|
+
expires_at: string | null;
|
|
535
|
+
created_at: string | null;
|
|
536
|
+
updated_at: string | null;
|
|
537
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors the SDK raises.
|
|
3
|
+
*
|
|
4
|
+
* Subclasses exist per status so callers can branch on the kind of failure
|
|
5
|
+
* rather than parse a message: a rate limit is worth retrying, a permission
|
|
6
|
+
* problem is not.
|
|
7
|
+
*/
|
|
8
|
+
export class NixetError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = new.target.name;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class APIError extends NixetError {
|
|
15
|
+
status;
|
|
16
|
+
/** Correlates a report with a server-side log entry. */
|
|
17
|
+
requestId;
|
|
18
|
+
constructor(status, message, requestId) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.requestId = requestId;
|
|
22
|
+
}
|
|
23
|
+
/** Build the most specific error class the status warrants. */
|
|
24
|
+
static from(status, message, requestId) {
|
|
25
|
+
switch (status) {
|
|
26
|
+
case 400:
|
|
27
|
+
return new BadRequestError(status, message, requestId);
|
|
28
|
+
case 401:
|
|
29
|
+
return new AuthenticationError(status, message, requestId);
|
|
30
|
+
case 403:
|
|
31
|
+
return new PermissionError(status, message, requestId);
|
|
32
|
+
case 404:
|
|
33
|
+
return new NotFoundError(status, message, requestId);
|
|
34
|
+
case 409:
|
|
35
|
+
return new ConflictError(status, message, requestId);
|
|
36
|
+
case 429:
|
|
37
|
+
return new RateLimitError(status, message, requestId);
|
|
38
|
+
default:
|
|
39
|
+
return status >= 500
|
|
40
|
+
? new ServerError(status, message, requestId)
|
|
41
|
+
: new APIError(status, message, requestId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class BadRequestError extends APIError {
|
|
46
|
+
}
|
|
47
|
+
export class AuthenticationError extends APIError {
|
|
48
|
+
}
|
|
49
|
+
export class PermissionError extends APIError {
|
|
50
|
+
}
|
|
51
|
+
export class NotFoundError extends APIError {
|
|
52
|
+
}
|
|
53
|
+
export class ConflictError extends APIError {
|
|
54
|
+
}
|
|
55
|
+
export class RateLimitError extends APIError {
|
|
56
|
+
}
|
|
57
|
+
export class ServerError extends APIError {
|
|
58
|
+
}
|
|
59
|
+
/** The API was unreachable, which is different from the API refusing. */
|
|
60
|
+
export class ConnectionError extends NixetError {
|
|
61
|
+
cause;
|
|
62
|
+
constructor(message, cause) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.cause = cause;
|
|
65
|
+
}
|
|
66
|
+
}
|