@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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +164 -2
  3. package/dist/cjs/errors.d.ts +37 -0
  4. package/dist/cjs/errors.js +79 -0
  5. package/dist/cjs/index.d.ts +88 -0
  6. package/dist/cjs/index.js +118 -0
  7. package/dist/cjs/resources/agents.d.ts +67 -0
  8. package/dist/cjs/resources/agents.js +74 -0
  9. package/dist/cjs/resources/connections.d.ts +94 -0
  10. package/dist/cjs/resources/connections.js +106 -0
  11. package/dist/cjs/resources/conversations.d.ts +62 -0
  12. package/dist/cjs/resources/conversations.js +86 -0
  13. package/dist/cjs/resources/documents.d.ts +65 -0
  14. package/dist/cjs/resources/documents.js +61 -0
  15. package/dist/cjs/resources/guardrails.d.ts +56 -0
  16. package/dist/cjs/resources/guardrails.js +76 -0
  17. package/dist/cjs/resources/knowledge.d.ts +192 -0
  18. package/dist/cjs/resources/knowledge.js +221 -0
  19. package/dist/cjs/resources/mcp-servers.d.ts +83 -0
  20. package/dist/cjs/resources/mcp-servers.js +107 -0
  21. package/dist/cjs/resources/memory.d.ts +95 -0
  22. package/dist/cjs/resources/memory.js +127 -0
  23. package/dist/cjs/resources/runs.d.ts +78 -0
  24. package/dist/cjs/resources/runs.js +87 -0
  25. package/dist/cjs/resources/secrets.d.ts +60 -0
  26. package/dist/cjs/resources/secrets.js +85 -0
  27. package/dist/cjs/resources/skills.d.ts +57 -0
  28. package/dist/cjs/resources/skills.js +78 -0
  29. package/dist/cjs/resources/tasks.d.ts +91 -0
  30. package/dist/cjs/resources/tasks.js +129 -0
  31. package/dist/cjs/resources/tools.d.ts +42 -0
  32. package/dist/cjs/resources/tools.js +57 -0
  33. package/dist/cjs/resources/users.d.ts +39 -0
  34. package/dist/cjs/resources/users.js +57 -0
  35. package/dist/cjs/resources/versions.d.ts +105 -0
  36. package/dist/cjs/resources/versions.js +78 -0
  37. package/dist/cjs/stream.d.ts +57 -0
  38. package/dist/cjs/stream.js +170 -0
  39. package/dist/cjs/transport.d.ts +45 -0
  40. package/dist/cjs/transport.js +106 -0
  41. package/dist/cjs/types.d.ts +537 -0
  42. package/dist/cjs/types.js +3 -0
  43. package/dist/esm/errors.js +66 -0
  44. package/dist/esm/index.js +103 -0
  45. package/dist/esm/package.json +1 -0
  46. package/dist/esm/resources/agents.js +70 -0
  47. package/dist/esm/resources/connections.js +102 -0
  48. package/dist/esm/resources/conversations.js +82 -0
  49. package/dist/esm/resources/documents.js +57 -0
  50. package/dist/esm/resources/guardrails.js +72 -0
  51. package/dist/esm/resources/knowledge.js +215 -0
  52. package/dist/esm/resources/mcp-servers.js +103 -0
  53. package/dist/esm/resources/memory.js +123 -0
  54. package/dist/esm/resources/runs.js +83 -0
  55. package/dist/esm/resources/secrets.js +81 -0
  56. package/dist/esm/resources/skills.js +74 -0
  57. package/dist/esm/resources/tasks.js +125 -0
  58. package/dist/esm/resources/tools.js +53 -0
  59. package/dist/esm/resources/users.js +53 -0
  60. package/dist/esm/resources/versions.js +74 -0
  61. package/dist/esm/stream.js +166 -0
  62. package/dist/esm/transport.js +102 -0
  63. package/dist/esm/types.js +2 -0
  64. package/package.json +42 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nixet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,165 @@
1
- # Temporary Holding Version
1
+ # @nixet/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official TypeScript SDK for the Nixet agent API. No dependencies.
4
+
5
+ ```bash
6
+ npm install @nixet/sdk
7
+ ```
8
+
9
+ ## Getting started
10
+
11
+ ```ts
12
+ import { Nixet } from "@nixet/sdk";
13
+
14
+ const nixet = new Nixet(); // reads NIXET_API_KEY
15
+
16
+ const agent = await nixet.agents.create({
17
+ name: "Support Assistant",
18
+ instructions: "You are concise. Use tools for arithmetic.",
19
+ tools: ["calculate"],
20
+ });
21
+
22
+ const run = await nixet.runs.create(agent.id, { input: "What is 23 × 7?" });
23
+ console.log(run.output); // "23 times 7 is **161**."
24
+ ```
25
+
26
+ A key is bound to one workspace and environment, so there is nothing else to
27
+ configure. Create one in the console.
28
+
29
+ ## Building an agent
30
+
31
+ Configuration lives in immutable versions, so an agent is composed from parts and
32
+ then frozen:
33
+
34
+ ```ts
35
+ const agent = await nixet.agents.create({
36
+ name: "Research Assistant",
37
+ description: "Answers questions with sources.",
38
+ instructions: "Cite every claim.",
39
+ model: { provider: "nix", tier: "powerful" },
40
+ tools: ["calculate", "current_time"],
41
+ });
42
+ ```
43
+
44
+ `create` publishes the first version for you. To publish another later:
45
+
46
+ ```ts
47
+ await nixet.agents.versions.create(agent.id, {
48
+ instructions: "Cite every claim, and say when you are unsure.",
49
+ });
50
+ ```
51
+
52
+ Versions are numbered in order and never edited, so a past run can always be
53
+ explained by the configuration it recorded.
54
+
55
+ ## Choosing a model
56
+
57
+ The managed provider needs no key of your own, and you pick a capability rather
58
+ than a model:
59
+
60
+ ```ts
61
+ model: { provider: "nix", tier: "fast" } // fast | balanced | powerful
62
+ ```
63
+
64
+ To name a model, bring a key for its provider:
65
+
66
+ ```ts
67
+ model: { provider: "openai", model: "gpt-4o-mini" }
68
+ model: { provider: "anthropic", model: "claude-sonnet-4-20250514" }
69
+ ```
70
+
71
+ The types enforce the difference: `tier` only exists on `nix`, and `model` is
72
+ required on the others.
73
+
74
+ ## Streaming
75
+
76
+ `runs.stream` returns a handle you can read four ways. Pick one per run.
77
+
78
+ ```ts
79
+ const stream = await nixet.runs.stream(agent.id, { input: "Explain gravity" });
80
+
81
+ // Text deltas, for a terminal or a socket
82
+ for await (const chunk of stream.chunks()) process.stdout.write(chunk);
83
+
84
+ // Every event, including tool calls
85
+ for await (const event of stream) console.log(event.type, event.data);
86
+
87
+ // The finished output
88
+ const text = await stream.text();
89
+
90
+ // Handlers
91
+ stream.on("run.tool.started", (e) => console.log("calling", e.data));
92
+ ```
93
+
94
+ | Event | Meaning |
95
+ | --- | --- |
96
+ | `run.started` | Execution began |
97
+ | `run.output` | A text delta |
98
+ | `run.tool.started` / `run.tool.completed` | A tool call |
99
+ | `run.completed` / `run.failed` | Terminal |
100
+
101
+ ### Recovering a dropped stream
102
+
103
+ Every event has a `sequence` and is recorded as it happens, so a lost connection
104
+ does not mean a lost run:
105
+
106
+ ```ts
107
+ const runId = await stream.runId;
108
+ const missed = await nixet.runs.events(runId, { after: lastSequenceSeen });
109
+ ```
110
+
111
+ Execution continues after a client disconnects, so `runs.retrieve(runId)` always
112
+ has an answer.
113
+
114
+ ## Errors
115
+
116
+ Errors are typed by kind, so you can branch without parsing messages:
117
+
118
+ ```ts
119
+ import { RateLimitError, NotFoundError } from "@nixet/sdk";
120
+
121
+ try {
122
+ await nixet.runs.create(agentId, { input: "…" });
123
+ } catch (error) {
124
+ if (error instanceof RateLimitError) { /* already retried; back off */ }
125
+ if (error instanceof NotFoundError) { /* no such agent in this workspace */ }
126
+ }
127
+ ```
128
+
129
+ | Error | Status |
130
+ | --- | --- |
131
+ | `BadRequestError` | 400 |
132
+ | `AuthenticationError` | 401 |
133
+ | `PermissionError` | 403 |
134
+ | `NotFoundError` | 404 |
135
+ | `ConflictError` | 409 |
136
+ | `RateLimitError` | 429 |
137
+ | `ServerError` | 5xx |
138
+ | `ConnectionError` | unreachable |
139
+
140
+ Connection failures, rate limits and server errors are retried automatically with
141
+ exponential backoff. A 4xx is not retried, because repeating a malformed request
142
+ cannot help.
143
+
144
+ ## Configuration
145
+
146
+ ```ts
147
+ new Nixet({
148
+ apiKey: "nxt_live_…", // or NIXET_API_KEY
149
+ baseURL: "…", // or NIXET_BASE_URL
150
+ timeout: 600_000, // a run waits on a model, not the network
151
+ maxRetries: 2,
152
+ });
153
+ ```
154
+
155
+ Every method takes `{ signal }` for cancellation.
156
+
157
+ ## Reference
158
+
159
+ | | |
160
+ | --- | --- |
161
+ | `nixet.whoami()` | Workspace and permissions for this key |
162
+ | `nixet.agents.create/retrieve/list` | Agents |
163
+ | `nixet.agents.versions.create/retrieve/list` | Immutable versions |
164
+ | `nixet.runs.create/stream/retrieve/list` | Execution |
165
+ | `nixet.runs.events` | The recorded event log |
@@ -0,0 +1,37 @@
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 declare class NixetError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ export declare class APIError extends NixetError {
12
+ readonly status: number;
13
+ /** Correlates a report with a server-side log entry. */
14
+ readonly requestId: string | null;
15
+ constructor(status: number, message: string, requestId: string | null);
16
+ /** Build the most specific error class the status warrants. */
17
+ static from(status: number, message: string, requestId: string | null): APIError;
18
+ }
19
+ export declare class BadRequestError extends APIError {
20
+ }
21
+ export declare class AuthenticationError extends APIError {
22
+ }
23
+ export declare class PermissionError extends APIError {
24
+ }
25
+ export declare class NotFoundError extends APIError {
26
+ }
27
+ export declare class ConflictError extends APIError {
28
+ }
29
+ export declare class RateLimitError extends APIError {
30
+ }
31
+ export declare class ServerError extends APIError {
32
+ }
33
+ /** The API was unreachable, which is different from the API refusing. */
34
+ export declare class ConnectionError extends NixetError {
35
+ readonly cause?: unknown;
36
+ constructor(message: string, cause?: unknown);
37
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionError = exports.ServerError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.PermissionError = exports.AuthenticationError = exports.BadRequestError = exports.APIError = exports.NixetError = void 0;
4
+ /**
5
+ * Errors the SDK raises.
6
+ *
7
+ * Subclasses exist per status so callers can branch on the kind of failure
8
+ * rather than parse a message: a rate limit is worth retrying, a permission
9
+ * problem is not.
10
+ */
11
+ class NixetError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = new.target.name;
15
+ }
16
+ }
17
+ exports.NixetError = NixetError;
18
+ class APIError extends NixetError {
19
+ status;
20
+ /** Correlates a report with a server-side log entry. */
21
+ requestId;
22
+ constructor(status, message, requestId) {
23
+ super(message);
24
+ this.status = status;
25
+ this.requestId = requestId;
26
+ }
27
+ /** Build the most specific error class the status warrants. */
28
+ static from(status, message, requestId) {
29
+ switch (status) {
30
+ case 400:
31
+ return new BadRequestError(status, message, requestId);
32
+ case 401:
33
+ return new AuthenticationError(status, message, requestId);
34
+ case 403:
35
+ return new PermissionError(status, message, requestId);
36
+ case 404:
37
+ return new NotFoundError(status, message, requestId);
38
+ case 409:
39
+ return new ConflictError(status, message, requestId);
40
+ case 429:
41
+ return new RateLimitError(status, message, requestId);
42
+ default:
43
+ return status >= 500
44
+ ? new ServerError(status, message, requestId)
45
+ : new APIError(status, message, requestId);
46
+ }
47
+ }
48
+ }
49
+ exports.APIError = APIError;
50
+ class BadRequestError extends APIError {
51
+ }
52
+ exports.BadRequestError = BadRequestError;
53
+ class AuthenticationError extends APIError {
54
+ }
55
+ exports.AuthenticationError = AuthenticationError;
56
+ class PermissionError extends APIError {
57
+ }
58
+ exports.PermissionError = PermissionError;
59
+ class NotFoundError extends APIError {
60
+ }
61
+ exports.NotFoundError = NotFoundError;
62
+ class ConflictError extends APIError {
63
+ }
64
+ exports.ConflictError = ConflictError;
65
+ class RateLimitError extends APIError {
66
+ }
67
+ exports.RateLimitError = RateLimitError;
68
+ class ServerError extends APIError {
69
+ }
70
+ exports.ServerError = ServerError;
71
+ /** The API was unreachable, which is different from the API refusing. */
72
+ class ConnectionError extends NixetError {
73
+ cause;
74
+ constructor(message, cause) {
75
+ super(message);
76
+ this.cause = cause;
77
+ }
78
+ }
79
+ exports.ConnectionError = ConnectionError;
@@ -0,0 +1,88 @@
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 } from "./resources/knowledge.js";
15
+ import type { Identity } from "./types.js";
16
+ export interface NixetOptions {
17
+ /** A key created in the Nixet console. Defaults to `NIXET_API_KEY`. */
18
+ apiKey?: string;
19
+ baseURL?: string;
20
+ /** Request timeout in milliseconds. Defaults to 10 minutes for long runs. */
21
+ timeout?: number;
22
+ /** Retries for connection failures, rate limits and server errors. */
23
+ maxRetries?: number;
24
+ fetch?: typeof fetch;
25
+ }
26
+ /**
27
+ * The Nixet client.
28
+ *
29
+ * ```ts
30
+ * import { Nixet } from "@nixet/sdk";
31
+ *
32
+ * const nixet = new Nixet(); // reads NIXET_API_KEY
33
+ *
34
+ * const agent = await nixet.agents.create({
35
+ * name: "Support Assistant",
36
+ * instructions: "You are concise.",
37
+ * tools: ["calculate"],
38
+ * });
39
+ *
40
+ * const run = await nixet.runs.create(agent.id, { input: "What is 23 × 7?" });
41
+ * console.log(run.output);
42
+ * ```
43
+ *
44
+ * A key is bound to one workspace and environment, so there is nothing else to
45
+ * configure.
46
+ */
47
+ export declare class Nixet {
48
+ readonly agents: Agents;
49
+ readonly runs: Runs;
50
+ readonly skills: Skills;
51
+ readonly users: Users;
52
+ readonly conversations: Conversations;
53
+ readonly memory: MemoryResource;
54
+ readonly tasks: Tasks;
55
+ readonly secrets: Secrets;
56
+ readonly mcpServers: McpServers;
57
+ /** Converting a document to Markdown. */
58
+ readonly documents: Documents;
59
+ /** Rules applied to what an agent is given and what it says. */
60
+ readonly guardrails: Guardrails;
61
+ /** End users' credentials for the servers you registered. */
62
+ readonly connections: Connections;
63
+ readonly tools: Tools;
64
+ readonly knowledge: Knowledge;
65
+ private readonly transport;
66
+ constructor(options?: NixetOptions);
67
+ /** Confirm which workspace and permissions this key carries. */
68
+ whoami(options?: {
69
+ signal?: AbortSignal;
70
+ }): Promise<Identity>;
71
+ }
72
+ export default Nixet;
73
+ export { RunStream } from "./stream.js";
74
+ export { APIError, AuthenticationError, BadRequestError, ConflictError, ConnectionError, NixetError, NotFoundError, PermissionError, RateLimitError, ServerError, } from "./errors.js";
75
+ export type { CreateAgentParams, CreatedAgent } from "./resources/agents.js";
76
+ export type { CreateRunParams, ListEventsParams } from "./resources/runs.js";
77
+ export type { CreateVersionParams } from "./resources/versions.js";
78
+ export type { CreateSkillParams, CreateSkillVersionParams, } from "./resources/skills.js";
79
+ export type { CreateUserParams } from "./resources/users.js";
80
+ export type { CreateConversationParams, SendMessageParams, } from "./resources/conversations.js";
81
+ export type { CreateMemoryParams, SearchMemoryParams, } from "./resources/memory.js";
82
+ export type { CreateSecretParams, UpdateSecretParams, } from "./resources/secrets.js";
83
+ export type { CreateMcpServerParams, UpdateMcpServerParams, } from "./resources/mcp-servers.js";
84
+ export type { CreateKnowledgeCollectionParams, CreateKnowledgeSourceParams, ListKnowledgeCollectionParams, ListKnowledgeSourceParams, } from "./resources/knowledge.js";
85
+ export type { ConvertDocumentParams } from "./resources/documents.js";
86
+ export type { ListGuardrailParams } from "./resources/guardrails.js";
87
+ export type { CreateConnectionParams, ListConnectionParams, } from "./resources/connections.js";
88
+ export type * from "./types.js";
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServerError = exports.RateLimitError = exports.PermissionError = exports.NotFoundError = exports.NixetError = exports.ConnectionError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.APIError = exports.RunStream = exports.Nixet = void 0;
4
+ const agents_js_1 = require("./resources/agents.js");
5
+ const runs_js_1 = require("./resources/runs.js");
6
+ const skills_js_1 = require("./resources/skills.js");
7
+ const users_js_1 = require("./resources/users.js");
8
+ const conversations_js_1 = require("./resources/conversations.js");
9
+ const memory_js_1 = require("./resources/memory.js");
10
+ const tasks_js_1 = require("./resources/tasks.js");
11
+ const secrets_js_1 = require("./resources/secrets.js");
12
+ const mcp_servers_js_1 = require("./resources/mcp-servers.js");
13
+ const tools_js_1 = require("./resources/tools.js");
14
+ const documents_js_1 = require("./resources/documents.js");
15
+ const guardrails_js_1 = require("./resources/guardrails.js");
16
+ const connections_js_1 = require("./resources/connections.js");
17
+ const knowledge_js_1 = require("./resources/knowledge.js");
18
+ const versions_js_1 = require("./resources/versions.js");
19
+ const transport_js_1 = require("./transport.js");
20
+ /**
21
+ * The Nixet client.
22
+ *
23
+ * ```ts
24
+ * import { Nixet } from "@nixet/sdk";
25
+ *
26
+ * const nixet = new Nixet(); // reads NIXET_API_KEY
27
+ *
28
+ * const agent = await nixet.agents.create({
29
+ * name: "Support Assistant",
30
+ * instructions: "You are concise.",
31
+ * tools: ["calculate"],
32
+ * });
33
+ *
34
+ * const run = await nixet.runs.create(agent.id, { input: "What is 23 × 7?" });
35
+ * console.log(run.output);
36
+ * ```
37
+ *
38
+ * A key is bound to one workspace and environment, so there is nothing else to
39
+ * configure.
40
+ */
41
+ class Nixet {
42
+ agents;
43
+ runs;
44
+ skills;
45
+ users;
46
+ conversations;
47
+ memory;
48
+ tasks;
49
+ secrets;
50
+ mcpServers;
51
+ /** Converting a document to Markdown. */
52
+ documents;
53
+ /** Rules applied to what an agent is given and what it says. */
54
+ guardrails;
55
+ /** End users' credentials for the servers you registered. */
56
+ connections;
57
+ tools;
58
+ knowledge;
59
+ transport;
60
+ constructor(options = {}) {
61
+ const apiKey = options.apiKey ?? readEnv("NIXET_API_KEY");
62
+ if (!apiKey) {
63
+ throw new Error("A Nixet API key is required. Pass `apiKey`, or set NIXET_API_KEY. " +
64
+ "Create one in the console under API keys.");
65
+ }
66
+ this.transport = new transport_js_1.Transport({
67
+ apiKey,
68
+ baseURL: options.baseURL ?? readEnv("NIXET_BASE_URL") ?? "https://api.nixet.ai/v1",
69
+ // Generous by default: a run waits on a model, not on the network.
70
+ timeout: options.timeout ?? 600_000,
71
+ maxRetries: options.maxRetries ?? 2,
72
+ fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
73
+ });
74
+ const versions = new versions_js_1.Versions(this.transport);
75
+ this.agents = new agents_js_1.Agents(this.transport, versions);
76
+ this.runs = new runs_js_1.Runs(this.transport);
77
+ this.skills = new skills_js_1.Skills(this.transport);
78
+ this.users = new users_js_1.Users(this.transport);
79
+ this.conversations = new conversations_js_1.Conversations(this.transport);
80
+ this.memory = new memory_js_1.MemoryResource(this.transport);
81
+ this.tasks = new tasks_js_1.Tasks(this.transport);
82
+ this.secrets = new secrets_js_1.Secrets(this.transport);
83
+ this.mcpServers = new mcp_servers_js_1.McpServers(this.transport);
84
+ this.documents = new documents_js_1.Documents(this.transport);
85
+ this.guardrails = new guardrails_js_1.Guardrails(this.transport);
86
+ this.connections = new connections_js_1.Connections(this.transport);
87
+ this.tools = new tools_js_1.Tools(this.transport);
88
+ this.knowledge = new knowledge_js_1.Knowledge(new knowledge_js_1.KnowledgeCollections(this.transport), new knowledge_js_1.KnowledgeSources(this.transport));
89
+ }
90
+ /** Confirm which workspace and permissions this key carries. */
91
+ async whoami(options = {}) {
92
+ return this.transport.request({
93
+ method: "GET",
94
+ path: "/whoami",
95
+ signal: options.signal,
96
+ });
97
+ }
98
+ }
99
+ exports.Nixet = Nixet;
100
+ /** Reads from Node or Deno without assuming either is present. */
101
+ function readEnv(name) {
102
+ const runtime = globalThis;
103
+ return runtime.process?.env?.[name];
104
+ }
105
+ exports.default = Nixet;
106
+ var stream_js_1 = require("./stream.js");
107
+ Object.defineProperty(exports, "RunStream", { enumerable: true, get: function () { return stream_js_1.RunStream; } });
108
+ var errors_js_1 = require("./errors.js");
109
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
110
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
111
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_js_1.BadRequestError; } });
112
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
113
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_js_1.ConnectionError; } });
114
+ Object.defineProperty(exports, "NixetError", { enumerable: true, get: function () { return errors_js_1.NixetError; } });
115
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
116
+ Object.defineProperty(exports, "PermissionError", { enumerable: true, get: function () { return errors_js_1.PermissionError; } });
117
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
118
+ Object.defineProperty(exports, "ServerError", { enumerable: true, get: function () { return errors_js_1.ServerError; } });
@@ -0,0 +1,67 @@
1
+ import type { Transport } from "../transport.js";
2
+ import type { Agent, AgentVersion, ListParams, ModelConfig, Page, ToolPolicy, ToolRef } from "../types.js";
3
+ import type { CreateVersionParams, Versions } from "./versions.js";
4
+ export interface CreateAgentParams {
5
+ name: string;
6
+ description?: string;
7
+ /**
8
+ * Publish a first version at the same time.
9
+ *
10
+ * An agent without a version cannot run, so creating both in one call is the
11
+ * common case. Omit this to create the identity alone.
12
+ */
13
+ instructions?: string;
14
+ model?: ModelConfig;
15
+ tools?: (ToolRef | string)[];
16
+ /** Skills the agent uses, as `name` or `name@v2`. */
17
+ skills?: string[];
18
+ /** Names of registered MCP servers the agent may use. */
19
+ mcpServers?: string[];
20
+ /** Per-tool overrides as `server.tool`. Only the exceptions. */
21
+ toolPolicies?: Record<string, ToolPolicy>;
22
+ /** Knowledge collections this agent may search, by name. */
23
+ knowledgeCollections?: string[];
24
+ /** Placeholders in `instructions`, as `{{name}}`, that a run supplies. */
25
+ variables?: string[];
26
+ /** Guardrails to run, by name, per stage. */
27
+ guardrails?: CreateVersionParams["guardrails"];
28
+ }
29
+ export interface CreatedAgent extends Agent {
30
+ /** Present when `instructions` were supplied. */
31
+ version?: AgentVersion;
32
+ }
33
+ /**
34
+ * Agents.
35
+ *
36
+ * An agent is an identity; its behaviour lives in versions. `create` accepts
37
+ * instructions so that the usual case is one call rather than two.
38
+ */
39
+ export declare class Agents {
40
+ private readonly transport;
41
+ /** Sub-resource, so `nixet.agents.versions.create(...)` reads naturally. */
42
+ readonly versions: Versions;
43
+ constructor(transport: Transport,
44
+ /** Sub-resource, so `nixet.agents.versions.create(...)` reads naturally. */
45
+ versions: Versions);
46
+ /**
47
+ * Create an agent, optionally publishing its first version.
48
+ *
49
+ * ```ts
50
+ * const agent = await nixet.agents.create({
51
+ * name: "Support Assistant",
52
+ * instructions: "You are concise.",
53
+ * model: { provider: "nix", tier: "fast" },
54
+ * tools: ["calculate"],
55
+ * });
56
+ * ```
57
+ */
58
+ create(params: CreateAgentParams, options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<CreatedAgent>;
61
+ retrieve(agentId: string, options?: {
62
+ signal?: AbortSignal;
63
+ }): Promise<Agent>;
64
+ list(params?: ListParams, options?: {
65
+ signal?: AbortSignal;
66
+ }): Promise<Page<Agent>>;
67
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Agents = void 0;
4
+ /**
5
+ * Agents.
6
+ *
7
+ * An agent is an identity; its behaviour lives in versions. `create` accepts
8
+ * instructions so that the usual case is one call rather than two.
9
+ */
10
+ class Agents {
11
+ transport;
12
+ versions;
13
+ constructor(transport,
14
+ /** Sub-resource, so `nixet.agents.versions.create(...)` reads naturally. */
15
+ versions) {
16
+ this.transport = transport;
17
+ this.versions = versions;
18
+ }
19
+ /**
20
+ * Create an agent, optionally publishing its first version.
21
+ *
22
+ * ```ts
23
+ * const agent = await nixet.agents.create({
24
+ * name: "Support Assistant",
25
+ * instructions: "You are concise.",
26
+ * model: { provider: "nix", tier: "fast" },
27
+ * tools: ["calculate"],
28
+ * });
29
+ * ```
30
+ */
31
+ async create(params, options = {}) {
32
+ const agent = await this.transport.request({
33
+ method: "POST",
34
+ path: "/agents",
35
+ body: {
36
+ name: params.name,
37
+ ...(params.description ? { description: params.description } : {}),
38
+ },
39
+ signal: options.signal,
40
+ });
41
+ if (!params.instructions)
42
+ return agent;
43
+ const version = await this.versions.create(agent.id, {
44
+ instructions: params.instructions,
45
+ model: params.model,
46
+ tools: params.tools,
47
+ skills: params.skills,
48
+ mcpServers: params.mcpServers,
49
+ toolPolicies: params.toolPolicies,
50
+ knowledgeCollections: params.knowledgeCollections,
51
+ variables: params.variables,
52
+ guardrails: params.guardrails,
53
+ }, options);
54
+ // The agent was fetched before the version published, so its pointer is
55
+ // stale. Reflect the version that now exists rather than returning null.
56
+ return { ...agent, current_version: version.version, version };
57
+ }
58
+ async retrieve(agentId, options = {}) {
59
+ return this.transport.request({
60
+ method: "GET",
61
+ path: `/agents/${encodeURIComponent(agentId)}`,
62
+ signal: options.signal,
63
+ });
64
+ }
65
+ async list(params = {}, options = {}) {
66
+ return this.transport.requestPage({
67
+ method: "GET",
68
+ path: "/agents",
69
+ query: { $limit: params.limit, $offset: params.offset },
70
+ signal: options.signal,
71
+ });
72
+ }
73
+ }
74
+ exports.Agents = Agents;