@nixet/contracts 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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/cjs/domains/agents.d.ts +284 -0
- package/dist/cjs/domains/agents.js +244 -0
- package/dist/cjs/domains/api-keys.d.ts +265 -0
- package/dist/cjs/domains/api-keys.js +87 -0
- package/dist/cjs/domains/billing.d.ts +98 -0
- package/dist/cjs/domains/billing.js +122 -0
- package/dist/cjs/domains/connections.d.ts +101 -0
- package/dist/cjs/domains/connections.js +130 -0
- package/dist/cjs/domains/conversations.d.ts +113 -0
- package/dist/cjs/domains/conversations.js +85 -0
- package/dist/cjs/domains/documents.d.ts +48 -0
- package/dist/cjs/domains/documents.js +64 -0
- package/dist/cjs/domains/guardrails.d.ts +213 -0
- package/dist/cjs/domains/guardrails.js +206 -0
- package/dist/cjs/domains/identity.d.ts +55 -0
- package/dist/cjs/domains/identity.js +26 -0
- package/dist/cjs/domains/knowledge.d.ts +167 -0
- package/dist/cjs/domains/knowledge.js +174 -0
- package/dist/cjs/domains/mcp.d.ts +189 -0
- package/dist/cjs/domains/mcp.js +183 -0
- package/dist/cjs/domains/memory.d.ts +109 -0
- package/dist/cjs/domains/memory.js +92 -0
- package/dist/cjs/domains/redaction.d.ts +181 -0
- package/dist/cjs/domains/redaction.js +166 -0
- package/dist/cjs/domains/runs.d.ts +260 -0
- package/dist/cjs/domains/runs.js +260 -0
- package/dist/cjs/domains/secrets.d.ts +56 -0
- package/dist/cjs/domains/secrets.js +72 -0
- package/dist/cjs/domains/skills.d.ts +70 -0
- package/dist/cjs/domains/skills.js +82 -0
- package/dist/cjs/domains/tasks.d.ts +111 -0
- package/dist/cjs/domains/tasks.js +113 -0
- package/dist/cjs/domains/tools.d.ts +159 -0
- package/dist/cjs/domains/tools.js +203 -0
- package/dist/cjs/domains/users.d.ts +40 -0
- package/dist/cjs/domains/users.js +48 -0
- package/dist/cjs/index.d.ts +25 -0
- package/dist/cjs/index.js +41 -0
- package/dist/cjs/primitives.d.ts +75 -0
- package/dist/cjs/primitives.js +117 -0
- package/dist/esm/domains/agents.js +239 -0
- package/dist/esm/domains/api-keys.js +83 -0
- package/dist/esm/domains/billing.js +116 -0
- package/dist/esm/domains/connections.js +127 -0
- package/dist/esm/domains/conversations.js +82 -0
- package/dist/esm/domains/documents.js +61 -0
- package/dist/esm/domains/guardrails.js +202 -0
- package/dist/esm/domains/identity.js +23 -0
- package/dist/esm/domains/knowledge.js +170 -0
- package/dist/esm/domains/mcp.js +178 -0
- package/dist/esm/domains/memory.js +89 -0
- package/dist/esm/domains/redaction.js +162 -0
- package/dist/esm/domains/runs.js +256 -0
- package/dist/esm/domains/secrets.js +68 -0
- package/dist/esm/domains/skills.js +79 -0
- package/dist/esm/domains/tasks.js +109 -0
- package/dist/esm/domains/tools.js +196 -0
- package/dist/esm/domains/users.js +45 -0
- package/dist/esm/index.js +25 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/primitives.js +114 -0
- package/package.json +47 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Secrets.
|
|
4
|
+
*
|
|
5
|
+
* A credential a customer gives us so an agent can reach something of theirs —
|
|
6
|
+
* an MCP server's bearer token, later an HTTP tool's API key.
|
|
7
|
+
*
|
|
8
|
+
* The value is written once and never returned. Everything that uses a secret
|
|
9
|
+
* refers to it by name, so a configuration can be read, copied and versioned
|
|
10
|
+
* without the credential travelling with it.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_SECRET_VALUE = 8_000;
|
|
13
|
+
/**
|
|
14
|
+
* Lowercase, hyphenated, stable.
|
|
15
|
+
*
|
|
16
|
+
* A version pins a secret by name, so renaming one would silently change what
|
|
17
|
+
* a published agent reaches for.
|
|
18
|
+
*/
|
|
19
|
+
export const secretNameSchema = z
|
|
20
|
+
.string()
|
|
21
|
+
.trim()
|
|
22
|
+
.min(1)
|
|
23
|
+
.max(64)
|
|
24
|
+
.regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "Use lowercase letters, numbers and hyphens, e.g. `github-token`.");
|
|
25
|
+
/**
|
|
26
|
+
* What a read returns.
|
|
27
|
+
*
|
|
28
|
+
* Never the value. A secret that could be read back is a secret store that
|
|
29
|
+
* leaks the moment any read path is wrong, so the API has no way to ask.
|
|
30
|
+
*/
|
|
31
|
+
export const secretSchema = z.object({
|
|
32
|
+
id: z.string().describe("Unique identifier, prefixed `sec_`."),
|
|
33
|
+
name: secretNameSchema,
|
|
34
|
+
description: z.string().nullable(),
|
|
35
|
+
/** First few characters, so a reader can tell two secrets apart. */
|
|
36
|
+
hint: z.string().describe("A short, non-reversible excerpt. Never the value."),
|
|
37
|
+
created_at: z.string(),
|
|
38
|
+
updated_at: z.string(),
|
|
39
|
+
});
|
|
40
|
+
export const createSecretSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
name: secretNameSchema,
|
|
43
|
+
value: z.string().min(1).max(MAX_SECRET_VALUE),
|
|
44
|
+
description: z.string().trim().max(200).optional(),
|
|
45
|
+
})
|
|
46
|
+
.strict();
|
|
47
|
+
/** Replacing a value. The name cannot change, because versions pin it. */
|
|
48
|
+
export const updateSecretSchema = z
|
|
49
|
+
.object({
|
|
50
|
+
value: z.string().min(1).max(MAX_SECRET_VALUE).optional(),
|
|
51
|
+
description: z.string().trim().max(200).optional(),
|
|
52
|
+
})
|
|
53
|
+
.strict()
|
|
54
|
+
.refine((body) => body.value !== undefined || body.description !== undefined, {
|
|
55
|
+
message: "Nothing to update.",
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* How a configuration refers to a secret.
|
|
59
|
+
*
|
|
60
|
+
* `{{ secret.github-token }}` inside a header value. The reference is what gets
|
|
61
|
+
* stored and versioned; the value is resolved at execution and never persisted
|
|
62
|
+
* alongside the thing that used it.
|
|
63
|
+
*/
|
|
64
|
+
export const SECRET_REFERENCE = /\{\{\s*secret\.([a-z0-9-]+)\s*\}\}/g;
|
|
65
|
+
/** Every secret a string refers to, in the order they appear. */
|
|
66
|
+
export function secretsReferencedBy(value) {
|
|
67
|
+
return [...value.matchAll(SECRET_REFERENCE)].map((match) => match[1]);
|
|
68
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { toolRefSchema } from "./agents.js";
|
|
3
|
+
/**
|
|
4
|
+
* Skills.
|
|
5
|
+
*
|
|
6
|
+
* A skill is reusable expertise: instructions plus the tools that expertise
|
|
7
|
+
* needs, packaged under a name and versioned like an agent. An agent version
|
|
8
|
+
* references skills by `name@version`, so what an agent knew at run time can
|
|
9
|
+
* always be reconstructed.
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_SKILL_NAME = 80;
|
|
12
|
+
export const MAX_SKILL_INSTRUCTIONS = 20_000;
|
|
13
|
+
/**
|
|
14
|
+
* Names may be namespaced with a single slash, as in `research/company-lookup`,
|
|
15
|
+
* which groups related skills without a directory to maintain.
|
|
16
|
+
*/
|
|
17
|
+
export const skillNameSchema = z
|
|
18
|
+
.string()
|
|
19
|
+
.trim()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(MAX_SKILL_NAME)
|
|
22
|
+
.regex(/^[a-z0-9][a-z0-9-]*(\/[a-z0-9][a-z0-9-]*)?$/, "Use lowercase letters, numbers and hyphens, optionally namespaced as `group/name`.");
|
|
23
|
+
export const skillSchema = z.object({
|
|
24
|
+
id: z.string().describe("Unique identifier, prefixed `skl_`."),
|
|
25
|
+
name: skillNameSchema.describe("Unique within a workspace and environment."),
|
|
26
|
+
description: z.string().nullable(),
|
|
27
|
+
current_version: z
|
|
28
|
+
.string()
|
|
29
|
+
.nullable()
|
|
30
|
+
.describe("Version used when a reference names no version."),
|
|
31
|
+
created_at: z.string(),
|
|
32
|
+
updated_at: z.string(),
|
|
33
|
+
});
|
|
34
|
+
export const createSkillSchema = z
|
|
35
|
+
.object({
|
|
36
|
+
name: skillNameSchema,
|
|
37
|
+
description: z.string().trim().max(500).optional(),
|
|
38
|
+
/** Supplying instructions also publishes the first version. */
|
|
39
|
+
instructions: z.string().trim().min(1).max(MAX_SKILL_INSTRUCTIONS).optional(),
|
|
40
|
+
tools: z.array(toolRefSchema).max(32).optional(),
|
|
41
|
+
})
|
|
42
|
+
.strict();
|
|
43
|
+
export const skillVersionSchema = z.object({
|
|
44
|
+
id: z.string(),
|
|
45
|
+
skill_id: z.string(),
|
|
46
|
+
version: z.string().describe("Monotonic within a skill: v1, v2, v3."),
|
|
47
|
+
instructions: z
|
|
48
|
+
.string()
|
|
49
|
+
.describe("Added to the agent's prompt when the skill is in use."),
|
|
50
|
+
tools: z.array(toolRefSchema).describe("Tools this expertise requires."),
|
|
51
|
+
digest: z.string().describe("Content hash of the frozen skill."),
|
|
52
|
+
created_at: z.string(),
|
|
53
|
+
});
|
|
54
|
+
export const createSkillVersionSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
instructions: z.string().trim().min(1).max(MAX_SKILL_INSTRUCTIONS),
|
|
57
|
+
tools: z.array(toolRefSchema).max(32).default([]),
|
|
58
|
+
publish: z.boolean().default(true),
|
|
59
|
+
})
|
|
60
|
+
.strict();
|
|
61
|
+
/**
|
|
62
|
+
* How an agent version names a skill.
|
|
63
|
+
*
|
|
64
|
+
* `name@v2` pins a version. A bare `name` resolves to the published version
|
|
65
|
+
* when the agent version is created, and the resolved value is what gets
|
|
66
|
+
* stored: resolving at run time would make a past run unreproducible.
|
|
67
|
+
*/
|
|
68
|
+
export const skillRefSchema = z
|
|
69
|
+
.string()
|
|
70
|
+
.trim()
|
|
71
|
+
.min(1)
|
|
72
|
+
.max(MAX_SKILL_NAME + 12)
|
|
73
|
+
.regex(/^[a-z0-9][a-z0-9-]*(\/[a-z0-9][a-z0-9-]*)?(@v\d+)?$/, "Reference a skill as `name` or `name@v2`.");
|
|
74
|
+
/** A skill as stored on an agent version, already resolved to one version. */
|
|
75
|
+
export const resolvedSkillSchema = z.object({
|
|
76
|
+
name: z.string(),
|
|
77
|
+
version: z.string(),
|
|
78
|
+
digest: z.string(),
|
|
79
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { memoryPolicySchema } from "./conversations.js";
|
|
3
|
+
import { providerSchema } from "./agents.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tasks.
|
|
6
|
+
*
|
|
7
|
+
* A run is one HTTP request: the caller waits, and the work has to finish
|
|
8
|
+
* inside that request. A task is work that outlives the request — research,
|
|
9
|
+
* a long report, anything that would otherwise time out.
|
|
10
|
+
*
|
|
11
|
+
* A task owns the lifecycle; a run owns the execution. The worker starts a run
|
|
12
|
+
* and records its id, so a task's trace, cost and redaction are the run's and
|
|
13
|
+
* nothing is duplicated.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Every state a task can report.
|
|
17
|
+
*
|
|
18
|
+
* Five are reachable today. `waiting_for_tool`, `waiting_for_approval`,
|
|
19
|
+
* `waiting_for_user` and `paused` are declared because the platform will
|
|
20
|
+
* produce them once tools, policies and a resume mechanism exist — widening a
|
|
21
|
+
* published enum later would break an exhaustive switch a customer already
|
|
22
|
+
* wrote. Until then nothing sets them, and the documentation says so.
|
|
23
|
+
*/
|
|
24
|
+
export const taskStatusSchema = z.enum([
|
|
25
|
+
"queued",
|
|
26
|
+
"running",
|
|
27
|
+
"waiting_for_tool",
|
|
28
|
+
"waiting_for_approval",
|
|
29
|
+
"waiting_for_user",
|
|
30
|
+
"paused",
|
|
31
|
+
"completed",
|
|
32
|
+
"failed",
|
|
33
|
+
"cancelled",
|
|
34
|
+
]);
|
|
35
|
+
/** States nothing currently produces. Exported so the docs cannot drift. */
|
|
36
|
+
export const UNREACHABLE_TASK_STATES = [
|
|
37
|
+
"waiting_for_tool",
|
|
38
|
+
"waiting_for_approval",
|
|
39
|
+
"waiting_for_user",
|
|
40
|
+
"paused",
|
|
41
|
+
];
|
|
42
|
+
/** A task that has stopped for good, whatever the outcome. */
|
|
43
|
+
export const TERMINAL_TASK_STATES = [
|
|
44
|
+
"completed",
|
|
45
|
+
"failed",
|
|
46
|
+
"cancelled",
|
|
47
|
+
];
|
|
48
|
+
export const MAX_TASK_INPUT = 32_000;
|
|
49
|
+
export const DEFAULT_MAX_ATTEMPTS = 3;
|
|
50
|
+
export const taskSchema = z.object({
|
|
51
|
+
id: z.string().describe("Unique identifier, prefixed `tsk_`."),
|
|
52
|
+
agent_id: z.string(),
|
|
53
|
+
agent_version: z
|
|
54
|
+
.string()
|
|
55
|
+
.describe("Pinned when the task is queued, not when it runs."),
|
|
56
|
+
version_digest: z
|
|
57
|
+
.string()
|
|
58
|
+
.describe("Content hash of the configuration that will produce this task."),
|
|
59
|
+
status: taskStatusSchema,
|
|
60
|
+
input: z.string(),
|
|
61
|
+
output: z
|
|
62
|
+
.string()
|
|
63
|
+
.nullable()
|
|
64
|
+
.describe("Final text, present once the task completes."),
|
|
65
|
+
error: z
|
|
66
|
+
.string()
|
|
67
|
+
.nullable()
|
|
68
|
+
.describe("Safe failure reason. Never a stack trace or provider payload."),
|
|
69
|
+
/** Where the trace, events and cost live. Null until a worker starts it. */
|
|
70
|
+
run_id: z.string().nullable(),
|
|
71
|
+
conversation_id: z.string().nullable(),
|
|
72
|
+
user_id: z.string().nullable(),
|
|
73
|
+
attempt: z.number().int().nonnegative().describe("Attempts started so far."),
|
|
74
|
+
max_attempts: z.number().int().positive(),
|
|
75
|
+
/** Set when a failed task is waiting out its backoff before the next attempt. */
|
|
76
|
+
run_after: z.string().nullable(),
|
|
77
|
+
created_at: z.string(),
|
|
78
|
+
updated_at: z.string(),
|
|
79
|
+
completed_at: z.string().nullable(),
|
|
80
|
+
});
|
|
81
|
+
export const createTaskSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
input: z.string().trim().min(1).max(MAX_TASK_INPUT),
|
|
84
|
+
/** Pins a version. Defaults to whatever is published when queued. */
|
|
85
|
+
agent_version: z.string().min(1).optional(),
|
|
86
|
+
conversation_id: z.string().min(1).optional(),
|
|
87
|
+
user_id: z.string().min(1).optional(),
|
|
88
|
+
provider: providerSchema.optional(),
|
|
89
|
+
memory: memoryPolicySchema.partial().optional(),
|
|
90
|
+
max_attempts: z.number().int().min(1).max(10).default(DEFAULT_MAX_ATTEMPTS),
|
|
91
|
+
})
|
|
92
|
+
.strict();
|
|
93
|
+
export const listTasksSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
status: taskStatusSchema.optional(),
|
|
96
|
+
agent_id: z.string().min(1).optional(),
|
|
97
|
+
conversation_id: z.string().min(1).optional(),
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
/**
|
|
101
|
+
* How long to wait before attempt `n`.
|
|
102
|
+
*
|
|
103
|
+
* Exponential from ten seconds, capped at five minutes. A failure is usually a
|
|
104
|
+
* rate limit or a provider blip, so retrying immediately tends to fail the same
|
|
105
|
+
* way; waiting an hour is longer than anyone will tolerate.
|
|
106
|
+
*/
|
|
107
|
+
export function backoffMs(attempt) {
|
|
108
|
+
return Math.min(10_000 * 2 ** Math.max(0, attempt - 1), 300_000);
|
|
109
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Tool access.
|
|
4
|
+
*
|
|
5
|
+
* A server can expose a hundred tools, and a customer rarely wants an agent to
|
|
6
|
+
* have all of them. This is how they say which.
|
|
7
|
+
*
|
|
8
|
+
* Two separate ideas live here, and conflating them is the mistake to avoid:
|
|
9
|
+
*
|
|
10
|
+
* A **tag** describes what a tool does. It comes from the server's own
|
|
11
|
+
* annotations where it published any, and from Nixet's reading of the name
|
|
12
|
+
* and description where it did not. Either way it is a claim, not a
|
|
13
|
+
* guarantee — the MCP specification is explicit that a server can annotate a
|
|
14
|
+
* tool `readOnlyHint: true` and delete your files anyway. A tag decides what
|
|
15
|
+
* a customer is shown and what the default policy is. It enforces nothing.
|
|
16
|
+
*
|
|
17
|
+
* A **policy** is what Nixet will actually do. It is decided by the customer,
|
|
18
|
+
* frozen into an agent version, and enforced before a tool is offered to the
|
|
19
|
+
* model. This is the part that holds.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* What a tool does, as far as anyone can tell.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately coarser than MCP's four booleans. `readOnlyHint` and
|
|
25
|
+
* `destructiveHint` and `idempotentHint` describe behaviour precisely and
|
|
26
|
+
* answer no question a person actually asks, which is "should this thing be
|
|
27
|
+
* allowed to run on its own".
|
|
28
|
+
*/
|
|
29
|
+
export const toolTagSchema = z.enum([
|
|
30
|
+
/** Reads. Changes nothing. */
|
|
31
|
+
"read",
|
|
32
|
+
/** Changes something, additively — creating, appending, updating. */
|
|
33
|
+
"write",
|
|
34
|
+
/** Removes or overwrites. The one whose mistakes are not undoable. */
|
|
35
|
+
"destructive",
|
|
36
|
+
/** Reaches something outside the server: the open web, a third party. */
|
|
37
|
+
"external",
|
|
38
|
+
]);
|
|
39
|
+
/** Where a tag came from, because the two deserve different trust. */
|
|
40
|
+
export const tagSourceSchema = z.enum([
|
|
41
|
+
/** The server's own MCP annotations. Its claim about itself. */
|
|
42
|
+
"server",
|
|
43
|
+
/** Nixet's reading of the name and description. A guess. */
|
|
44
|
+
"inferred",
|
|
45
|
+
]);
|
|
46
|
+
/**
|
|
47
|
+
* What Nixet does when the agent reaches for a tool.
|
|
48
|
+
*
|
|
49
|
+
* `ask` is declared and not yet enforceable: nothing can pause a run for a
|
|
50
|
+
* human until approvals exist. Until then it refuses, with a reason saying so,
|
|
51
|
+
* rather than quietly behaving as `allow` — a policy that silently does the
|
|
52
|
+
* opposite of what it says is worse than one that does not work.
|
|
53
|
+
*/
|
|
54
|
+
export const toolPolicySchema = z.enum(["allow", "ask", "deny"]);
|
|
55
|
+
/**
|
|
56
|
+
* The policy a tag gets when the customer has not named one.
|
|
57
|
+
*
|
|
58
|
+
* A customer publishing against a hundred-tool server should get something
|
|
59
|
+
* sensible without enumerating all hundred, and the tools whose mistakes are
|
|
60
|
+
* expensive should not be the ones that slip through.
|
|
61
|
+
*
|
|
62
|
+
* `write` is `allow` in this release and becomes `ask` once approvals exist.
|
|
63
|
+
* Defaulting it to `ask` now would mean every write tool refusing on day one,
|
|
64
|
+
* since `ask` cannot yet pause for anyone. That is a behaviour change, and it
|
|
65
|
+
* is documented rather than sprung.
|
|
66
|
+
*/
|
|
67
|
+
export const DEFAULT_TOOL_POLICY = {
|
|
68
|
+
read: "allow",
|
|
69
|
+
write: "allow",
|
|
70
|
+
destructive: "ask",
|
|
71
|
+
external: "allow",
|
|
72
|
+
};
|
|
73
|
+
/** MCP's own annotations, as a server publishes them. */
|
|
74
|
+
export const mcpToolAnnotationsSchema = z
|
|
75
|
+
.object({
|
|
76
|
+
title: z.string().optional(),
|
|
77
|
+
readOnlyHint: z.boolean().optional(),
|
|
78
|
+
destructiveHint: z.boolean().optional(),
|
|
79
|
+
idempotentHint: z.boolean().optional(),
|
|
80
|
+
openWorldHint: z.boolean().optional(),
|
|
81
|
+
})
|
|
82
|
+
.loose();
|
|
83
|
+
/** One tool, as discovered from a server. */
|
|
84
|
+
export const toolSchema = z.object({
|
|
85
|
+
id: z.string().describe("Unique identifier, prefixed `tol_`."),
|
|
86
|
+
server_id: z.string(),
|
|
87
|
+
server_name: z.string().describe("The handle an agent version pins."),
|
|
88
|
+
name: z.string().describe("The tool's own name, as the server reports it."),
|
|
89
|
+
description: z.string().nullable(),
|
|
90
|
+
tags: z.array(toolTagSchema),
|
|
91
|
+
tag_source: tagSourceSchema,
|
|
92
|
+
/** What the server claimed, kept so a reader can check our reading of it. */
|
|
93
|
+
annotations: mcpToolAnnotationsSchema.nullable(),
|
|
94
|
+
/** What this tool gets when a version does not name it. */
|
|
95
|
+
default_policy: toolPolicySchema,
|
|
96
|
+
discovered_at: z.string(),
|
|
97
|
+
updated_at: z.string(),
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* A version's overrides, as `server.tool` to `policy`.
|
|
101
|
+
*
|
|
102
|
+
* Qualified by server because two servers can both offer `search`, and a policy
|
|
103
|
+
* that silently applied to both would be a way to grant access nobody asked
|
|
104
|
+
* for. `"github.delete_repo": "deny"`.
|
|
105
|
+
*
|
|
106
|
+
* Only the exceptions are stored. Everything unnamed takes its tag's default,
|
|
107
|
+
* so a version stays readable and does not need rewriting when a server adds a
|
|
108
|
+
* tool.
|
|
109
|
+
*/
|
|
110
|
+
export const toolPoliciesSchema = z
|
|
111
|
+
.record(z
|
|
112
|
+
.string()
|
|
113
|
+
.regex(/^[a-z0-9-]+\.[A-Za-z0-9_-]+$/, "Name a tool as `server.tool`, e.g. `github.delete_repo`."), toolPolicySchema)
|
|
114
|
+
.refine((policies) => Object.keys(policies).length <= 200, {
|
|
115
|
+
message: "A version may override at most 200 tools.",
|
|
116
|
+
});
|
|
117
|
+
/** How a version addresses one tool. */
|
|
118
|
+
export const toolKey = (server, tool) => `${server}.${tool}`;
|
|
119
|
+
/**
|
|
120
|
+
* What a version does about one tool.
|
|
121
|
+
*
|
|
122
|
+
* An explicit override wins; otherwise the tool's tags decide, and the
|
|
123
|
+
* strictest tag wins. A tool tagged both `read` and `destructive` is
|
|
124
|
+
* destructive — a thing that reads and deletes is a thing that deletes.
|
|
125
|
+
*/
|
|
126
|
+
export function resolveToolPolicy(tool, serverName, policies) {
|
|
127
|
+
const override = policies?.[toolKey(serverName, tool.name)];
|
|
128
|
+
if (override)
|
|
129
|
+
return override;
|
|
130
|
+
const order = ["allow", "ask", "deny"];
|
|
131
|
+
return tool.tags.reduce((strictest, tag) => {
|
|
132
|
+
const candidate = DEFAULT_TOOL_POLICY[tag];
|
|
133
|
+
return order.indexOf(candidate) > order.indexOf(strictest) ? candidate : strictest;
|
|
134
|
+
}, "allow");
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Tags for a tool, from the server's annotations where it published any.
|
|
138
|
+
*
|
|
139
|
+
* MCP's defaults are deliberately pessimistic: a tool that says nothing is
|
|
140
|
+
* assumed destructive. That default is right for a client deciding whether to
|
|
141
|
+
* prompt, and wrong here, because it would tag every unannotated tool on every
|
|
142
|
+
* unannotated server as destructive and make the tag meaningless. So absence is
|
|
143
|
+
* treated as absence: no annotations means we infer instead.
|
|
144
|
+
*/
|
|
145
|
+
export function tagsFromAnnotations(annotations) {
|
|
146
|
+
if (!annotations)
|
|
147
|
+
return null;
|
|
148
|
+
const stated = annotations.readOnlyHint !== undefined || annotations.destructiveHint !== undefined;
|
|
149
|
+
if (!stated)
|
|
150
|
+
return null;
|
|
151
|
+
const tags = [];
|
|
152
|
+
if (annotations.readOnlyHint)
|
|
153
|
+
tags.push("read");
|
|
154
|
+
else
|
|
155
|
+
tags.push(annotations.destructiveHint === false ? "write" : "destructive");
|
|
156
|
+
// A read-only tool that reaches the open web still leaves the building, which
|
|
157
|
+
// is worth showing even though it changes nothing.
|
|
158
|
+
if (annotations.openWorldHint)
|
|
159
|
+
tags.push("external");
|
|
160
|
+
return tags;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Verbs that give a tool away.
|
|
164
|
+
*
|
|
165
|
+
* Used only when a server published no annotations. Ordered destructive first,
|
|
166
|
+
* because the cost of the two mistakes is not symmetric: reading a destructive
|
|
167
|
+
* tool as safe is how something gets deleted, and reading a safe tool as
|
|
168
|
+
* destructive only means someone is asked a question they did not need.
|
|
169
|
+
*/
|
|
170
|
+
const DESTRUCTIVE = /^(delete|remove|destroy|drop|purge|truncate|revoke|kill|terminate|uninstall|reset|overwrite|replace|clear|wipe|prune|archive|close|cancel|merge|force)/i;
|
|
171
|
+
const WRITE = /^(create|add|insert|update|edit|modify|set|put|post|patch|write|append|send|publish|upload|push|assign|invite|comment|apply|run|execute|trigger|start|schedule|move|rename|copy|sync|import|export)/i;
|
|
172
|
+
const READ = /^(get|list|read|fetch|find|search|query|show|view|describe|inspect|check|count|lookup|resolve|status|health|ping|has|is)/i;
|
|
173
|
+
const EXTERNAL = /\b(http|https|url|web|browse|crawl|scrape|download|fetch_url|request)\b/i;
|
|
174
|
+
/**
|
|
175
|
+
* Nixet's reading of a tool, when the server said nothing.
|
|
176
|
+
*
|
|
177
|
+
* A guess, and labelled as one. `archive_record` and `sync_all` are exactly the
|
|
178
|
+
* cases this gets wrong, which is why an unrecognised verb is treated as a
|
|
179
|
+
* write rather than a read: unknown is closer to "changes something" than to
|
|
180
|
+
* "changes nothing".
|
|
181
|
+
*/
|
|
182
|
+
export function inferTags(name, description) {
|
|
183
|
+
const subject = `${name} ${description ?? ""}`;
|
|
184
|
+
const tags = [];
|
|
185
|
+
if (DESTRUCTIVE.test(name))
|
|
186
|
+
tags.push("destructive");
|
|
187
|
+
else if (READ.test(name))
|
|
188
|
+
tags.push("read");
|
|
189
|
+
else if (WRITE.test(name))
|
|
190
|
+
tags.push("write");
|
|
191
|
+
else
|
|
192
|
+
tags.push("write");
|
|
193
|
+
if (EXTERNAL.test(subject))
|
|
194
|
+
tags.push("external");
|
|
195
|
+
return tags;
|
|
196
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Users.
|
|
4
|
+
*
|
|
5
|
+
* The people a customer's agent serves, not the people who log into the Nixet
|
|
6
|
+
* console — those are members. A user belongs to one workspace and environment,
|
|
7
|
+
* so two customers can use the same reference for different people.
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_USER_REFERENCE = 128;
|
|
10
|
+
/**
|
|
11
|
+
* The customer's own identifier for this person.
|
|
12
|
+
*
|
|
13
|
+
* Opaque to Nixet and unique within a scope. Customers should keep personal
|
|
14
|
+
* data out of it; `email` and `name` exist for that, and can be erased without
|
|
15
|
+
* breaking the reference their systems rely on.
|
|
16
|
+
*/
|
|
17
|
+
export const userReferenceSchema = z
|
|
18
|
+
.string()
|
|
19
|
+
.trim()
|
|
20
|
+
.min(1)
|
|
21
|
+
.max(MAX_USER_REFERENCE);
|
|
22
|
+
export const userSchema = z.object({
|
|
23
|
+
id: z.string().describe("Unique identifier, prefixed `usr_`."),
|
|
24
|
+
reference: userReferenceSchema.describe("Your identifier for this person."),
|
|
25
|
+
email: z.string().nullable(),
|
|
26
|
+
name: z.string().nullable(),
|
|
27
|
+
metadata: z.record(z.string(), z.unknown()).describe("Your own fields."),
|
|
28
|
+
created_at: z.string(),
|
|
29
|
+
updated_at: z.string(),
|
|
30
|
+
});
|
|
31
|
+
export const createUserSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
reference: userReferenceSchema,
|
|
34
|
+
email: z.string().trim().email().max(320).optional(),
|
|
35
|
+
name: z.string().trim().min(1).max(200).optional(),
|
|
36
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
37
|
+
})
|
|
38
|
+
.strict();
|
|
39
|
+
export const updateUserSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
email: z.string().trim().email().max(320).nullable().optional(),
|
|
42
|
+
name: z.string().trim().min(1).max(200).nullable().optional(),
|
|
43
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
44
|
+
})
|
|
45
|
+
.strict();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public Nixet wire contract.
|
|
3
|
+
*
|
|
4
|
+
* One definition shared by the API, the TypeScript client and the dashboard
|
|
5
|
+
* bindings, so a released shape cannot drift between them.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./primitives.js";
|
|
8
|
+
export * from "./domains/identity.js";
|
|
9
|
+
export * from "./domains/api-keys.js";
|
|
10
|
+
export * from "./domains/agents.js";
|
|
11
|
+
export * from "./domains/skills.js";
|
|
12
|
+
export * from "./domains/runs.js";
|
|
13
|
+
export * from "./domains/users.js";
|
|
14
|
+
export * from "./domains/conversations.js";
|
|
15
|
+
export * from "./domains/memory.js";
|
|
16
|
+
export * from "./domains/redaction.js";
|
|
17
|
+
export * from "./domains/mcp.js";
|
|
18
|
+
export * from "./domains/connections.js";
|
|
19
|
+
export * from "./domains/documents.js";
|
|
20
|
+
export * from "./domains/guardrails.js";
|
|
21
|
+
export * from "./domains/tools.js";
|
|
22
|
+
export * from "./domains/knowledge.js";
|
|
23
|
+
export * from "./domains/billing.js";
|
|
24
|
+
export * from "./domains/secrets.js";
|
|
25
|
+
export * from "./domains/tasks.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Shared wire primitives.
|
|
4
|
+
*
|
|
5
|
+
* Wire fields are snake_case and timestamps are RFC 3339 UTC strings. Nothing
|
|
6
|
+
* in the contract may describe a recoverable secret: a plaintext key appears
|
|
7
|
+
* only in the single creation response, never in a list or get payload.
|
|
8
|
+
*/
|
|
9
|
+
export const API_VERSION = "v1";
|
|
10
|
+
/** Scope headers. A dashboard selects scope; a scoped key derives it. */
|
|
11
|
+
export const SCOPE_HEADERS = {
|
|
12
|
+
organization: "Nixet-Organization",
|
|
13
|
+
project: "Nixet-Project",
|
|
14
|
+
environment: "Nixet-Environment",
|
|
15
|
+
};
|
|
16
|
+
export const IDEMPOTENCY_HEADER = "Idempotency-Key";
|
|
17
|
+
export const REQUEST_ID_HEADER = "X-Request-Id";
|
|
18
|
+
export const environmentSchema = z.enum(["development", "production"]);
|
|
19
|
+
export const scopeSchema = z.object({
|
|
20
|
+
organization_id: z.string().min(1).max(64),
|
|
21
|
+
project_id: z.string().min(1).max(64),
|
|
22
|
+
environment_id: environmentSchema,
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Permissions an issued key may carry. `api_keys:write` is deliberately absent:
|
|
26
|
+
* a customer key must never be able to mint further credentials.
|
|
27
|
+
*
|
|
28
|
+
* `billing:write` is absent for a different reason: there is no such operation.
|
|
29
|
+
* A plan change moves money, so it happens through Stripe and arrives as a
|
|
30
|
+
* webhook. An API that could set a plan would be an API that could grant a
|
|
31
|
+
* customer Scale's allowance without charging for it.
|
|
32
|
+
*/
|
|
33
|
+
export const permissionSchema = z.enum([
|
|
34
|
+
"api_keys:read",
|
|
35
|
+
"agents:read",
|
|
36
|
+
"agents:write",
|
|
37
|
+
"runs:read",
|
|
38
|
+
"runs:write",
|
|
39
|
+
"users:read",
|
|
40
|
+
"users:write",
|
|
41
|
+
"conversations:read",
|
|
42
|
+
"conversations:write",
|
|
43
|
+
"memory:read",
|
|
44
|
+
"memory:write",
|
|
45
|
+
"secrets:read",
|
|
46
|
+
"secrets:write",
|
|
47
|
+
"mcp:read",
|
|
48
|
+
"mcp:write",
|
|
49
|
+
"connections:read",
|
|
50
|
+
"connections:write",
|
|
51
|
+
"knowledge:read",
|
|
52
|
+
"knowledge:write",
|
|
53
|
+
"billing:read",
|
|
54
|
+
]);
|
|
55
|
+
export const PERMISSION_PRESETS = {
|
|
56
|
+
read: [
|
|
57
|
+
"api_keys:read",
|
|
58
|
+
"agents:read",
|
|
59
|
+
"runs:read",
|
|
60
|
+
"users:read",
|
|
61
|
+
"conversations:read",
|
|
62
|
+
"memory:read",
|
|
63
|
+
// Reading a secret never returns its value, so this is genuinely a read.
|
|
64
|
+
"secrets:read",
|
|
65
|
+
"mcp:read",
|
|
66
|
+
// A connection read returns status and expiry, never the credential.
|
|
67
|
+
"connections:read",
|
|
68
|
+
// Reading a collection returns counts and the chunking rule, never a line
|
|
69
|
+
// of a document, so this is a read in the same sense the rest are.
|
|
70
|
+
"knowledge:read",
|
|
71
|
+
// Usage is not a credential, and hiding spend from the person causing it is
|
|
72
|
+
// how surprise invoices happen. There is no write to pair this with.
|
|
73
|
+
"billing:read",
|
|
74
|
+
],
|
|
75
|
+
standard: [
|
|
76
|
+
"api_keys:read",
|
|
77
|
+
"agents:read",
|
|
78
|
+
"agents:write",
|
|
79
|
+
"runs:read",
|
|
80
|
+
"runs:write",
|
|
81
|
+
"users:read",
|
|
82
|
+
"users:write",
|
|
83
|
+
"conversations:read",
|
|
84
|
+
"conversations:write",
|
|
85
|
+
"memory:read",
|
|
86
|
+
"memory:write",
|
|
87
|
+
"secrets:read",
|
|
88
|
+
"secrets:write",
|
|
89
|
+
"mcp:read",
|
|
90
|
+
"mcp:write",
|
|
91
|
+
"connections:read",
|
|
92
|
+
"connections:write",
|
|
93
|
+
"knowledge:read",
|
|
94
|
+
"knowledge:write",
|
|
95
|
+
// No `billing:write` to go beside it: a plan change is a Stripe webhook.
|
|
96
|
+
"billing:read",
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
export const ERROR_CODES = [
|
|
100
|
+
"BAD_REQUEST",
|
|
101
|
+
"UNAUTHENTICATED",
|
|
102
|
+
"FORBIDDEN",
|
|
103
|
+
"NOT_FOUND",
|
|
104
|
+
"CONFLICT",
|
|
105
|
+
"IDEMPOTENCY_CONFLICT",
|
|
106
|
+
"INVALID_CURSOR",
|
|
107
|
+
"SCOPE_MISMATCH",
|
|
108
|
+
"RATE_LIMITED",
|
|
109
|
+
"INTERNAL",
|
|
110
|
+
];
|
|
111
|
+
/** Framework error envelope: a status code plus `{ message }`. */
|
|
112
|
+
export const errorResponseSchema = z.object({
|
|
113
|
+
message: z.string(),
|
|
114
|
+
});
|