@nixet/sdk 0.0.0-stage → 0.1.1

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 (67) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/LICENSE +21 -0
  3. package/README.md +870 -2
  4. package/SECURITY.md +30 -0
  5. package/api.md +485 -0
  6. package/dist/cjs/errors.d.ts +37 -0
  7. package/dist/cjs/errors.js +79 -0
  8. package/dist/cjs/index.d.ts +89 -0
  9. package/dist/cjs/index.js +118 -0
  10. package/dist/cjs/resources/agents.d.ts +67 -0
  11. package/dist/cjs/resources/agents.js +74 -0
  12. package/dist/cjs/resources/connections.d.ts +94 -0
  13. package/dist/cjs/resources/connections.js +106 -0
  14. package/dist/cjs/resources/conversations.d.ts +62 -0
  15. package/dist/cjs/resources/conversations.js +86 -0
  16. package/dist/cjs/resources/documents.d.ts +65 -0
  17. package/dist/cjs/resources/documents.js +61 -0
  18. package/dist/cjs/resources/guardrails.d.ts +56 -0
  19. package/dist/cjs/resources/guardrails.js +76 -0
  20. package/dist/cjs/resources/knowledge.d.ts +189 -0
  21. package/dist/cjs/resources/knowledge.js +218 -0
  22. package/dist/cjs/resources/mcp-servers.d.ts +83 -0
  23. package/dist/cjs/resources/mcp-servers.js +107 -0
  24. package/dist/cjs/resources/memory.d.ts +95 -0
  25. package/dist/cjs/resources/memory.js +127 -0
  26. package/dist/cjs/resources/runs.d.ts +78 -0
  27. package/dist/cjs/resources/runs.js +87 -0
  28. package/dist/cjs/resources/secrets.d.ts +60 -0
  29. package/dist/cjs/resources/secrets.js +85 -0
  30. package/dist/cjs/resources/skills.d.ts +57 -0
  31. package/dist/cjs/resources/skills.js +78 -0
  32. package/dist/cjs/resources/tasks.d.ts +91 -0
  33. package/dist/cjs/resources/tasks.js +129 -0
  34. package/dist/cjs/resources/tools.d.ts +42 -0
  35. package/dist/cjs/resources/tools.js +57 -0
  36. package/dist/cjs/resources/users.d.ts +39 -0
  37. package/dist/cjs/resources/users.js +57 -0
  38. package/dist/cjs/resources/versions.d.ts +105 -0
  39. package/dist/cjs/resources/versions.js +78 -0
  40. package/dist/cjs/stream.d.ts +57 -0
  41. package/dist/cjs/stream.js +170 -0
  42. package/dist/cjs/transport.d.ts +45 -0
  43. package/dist/cjs/transport.js +106 -0
  44. package/dist/cjs/types.d.ts +537 -0
  45. package/dist/cjs/types.js +3 -0
  46. package/dist/esm/errors.js +66 -0
  47. package/dist/esm/index.js +103 -0
  48. package/dist/esm/package.json +1 -0
  49. package/dist/esm/resources/agents.js +70 -0
  50. package/dist/esm/resources/connections.js +102 -0
  51. package/dist/esm/resources/conversations.js +82 -0
  52. package/dist/esm/resources/documents.js +57 -0
  53. package/dist/esm/resources/guardrails.js +72 -0
  54. package/dist/esm/resources/knowledge.js +212 -0
  55. package/dist/esm/resources/mcp-servers.js +103 -0
  56. package/dist/esm/resources/memory.js +123 -0
  57. package/dist/esm/resources/runs.js +83 -0
  58. package/dist/esm/resources/secrets.js +81 -0
  59. package/dist/esm/resources/skills.js +74 -0
  60. package/dist/esm/resources/tasks.js +125 -0
  61. package/dist/esm/resources/tools.js +53 -0
  62. package/dist/esm/resources/users.js +53 -0
  63. package/dist/esm/resources/versions.js +74 -0
  64. package/dist/esm/stream.js +166 -0
  65. package/dist/esm/transport.js +102 -0
  66. package/dist/esm/types.js +2 -0
  67. package/package.json +59 -4
@@ -0,0 +1,89 @@
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 { CreateGuardrailParams } from "@nixet/contracts";
88
+ export type { CreateConnectionParams, ListConnectionParams, } from "./resources/connections.js";
89
+ 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;
@@ -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
+ }