@nixet/contracts 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 +12 -2
  3. package/dist/cjs/domains/agents.d.ts +284 -0
  4. package/dist/cjs/domains/agents.js +244 -0
  5. package/dist/cjs/domains/api-keys.d.ts +265 -0
  6. package/dist/cjs/domains/api-keys.js +87 -0
  7. package/dist/cjs/domains/billing.d.ts +98 -0
  8. package/dist/cjs/domains/billing.js +122 -0
  9. package/dist/cjs/domains/connections.d.ts +101 -0
  10. package/dist/cjs/domains/connections.js +130 -0
  11. package/dist/cjs/domains/conversations.d.ts +113 -0
  12. package/dist/cjs/domains/conversations.js +85 -0
  13. package/dist/cjs/domains/documents.d.ts +48 -0
  14. package/dist/cjs/domains/documents.js +64 -0
  15. package/dist/cjs/domains/guardrails.d.ts +211 -0
  16. package/dist/cjs/domains/guardrails.js +206 -0
  17. package/dist/cjs/domains/identity.d.ts +55 -0
  18. package/dist/cjs/domains/identity.js +26 -0
  19. package/dist/cjs/domains/knowledge.d.ts +167 -0
  20. package/dist/cjs/domains/knowledge.js +174 -0
  21. package/dist/cjs/domains/mcp.d.ts +189 -0
  22. package/dist/cjs/domains/mcp.js +183 -0
  23. package/dist/cjs/domains/memory.d.ts +109 -0
  24. package/dist/cjs/domains/memory.js +92 -0
  25. package/dist/cjs/domains/redaction.d.ts +181 -0
  26. package/dist/cjs/domains/redaction.js +166 -0
  27. package/dist/cjs/domains/runs.d.ts +260 -0
  28. package/dist/cjs/domains/runs.js +260 -0
  29. package/dist/cjs/domains/secrets.d.ts +56 -0
  30. package/dist/cjs/domains/secrets.js +72 -0
  31. package/dist/cjs/domains/skills.d.ts +70 -0
  32. package/dist/cjs/domains/skills.js +82 -0
  33. package/dist/cjs/domains/tasks.d.ts +111 -0
  34. package/dist/cjs/domains/tasks.js +113 -0
  35. package/dist/cjs/domains/tools.d.ts +159 -0
  36. package/dist/cjs/domains/tools.js +203 -0
  37. package/dist/cjs/domains/users.d.ts +40 -0
  38. package/dist/cjs/domains/users.js +48 -0
  39. package/dist/cjs/index.d.ts +25 -0
  40. package/dist/cjs/index.js +41 -0
  41. package/dist/cjs/primitives.d.ts +75 -0
  42. package/dist/cjs/primitives.js +117 -0
  43. package/dist/esm/domains/agents.js +239 -0
  44. package/dist/esm/domains/api-keys.js +83 -0
  45. package/dist/esm/domains/billing.js +116 -0
  46. package/dist/esm/domains/connections.js +127 -0
  47. package/dist/esm/domains/conversations.js +82 -0
  48. package/dist/esm/domains/documents.js +61 -0
  49. package/dist/esm/domains/guardrails.js +202 -0
  50. package/dist/esm/domains/identity.js +23 -0
  51. package/dist/esm/domains/knowledge.js +170 -0
  52. package/dist/esm/domains/mcp.js +178 -0
  53. package/dist/esm/domains/memory.js +89 -0
  54. package/dist/esm/domains/redaction.js +162 -0
  55. package/dist/esm/domains/runs.js +256 -0
  56. package/dist/esm/domains/secrets.js +68 -0
  57. package/dist/esm/domains/skills.js +79 -0
  58. package/dist/esm/domains/tasks.js +109 -0
  59. package/dist/esm/domains/tools.js +196 -0
  60. package/dist/esm/domains/users.js +45 -0
  61. package/dist/esm/index.js +25 -0
  62. package/dist/esm/package.json +1 -0
  63. package/dist/esm/primitives.js +114 -0
  64. package/package.json +38 -4
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findConnectionsSchema = exports.authorizationSchema = exports.authorizeConnectionSchema = exports.createConnectionSchema = exports.connectionSchema = exports.connectionStatusSchema = exports.MAX_CONNECTION_VALUE = void 0;
4
+ const zod_1 = require("zod");
5
+ const mcp_js_1 = require("./mcp.js");
6
+ /**
7
+ * An end user's credential for one MCP server.
8
+ *
9
+ * The catalog and the connection are deliberately separate. A server is
10
+ * registered once — `https://broker.example.com/mcp` is the same URL for every user, and
11
+ * only the token differs — and a connection binds one user to one credential
12
+ * for it. That split is what keeps an agent version about behaviour: the
13
+ * version names which servers it may reach, and a connection decides whose
14
+ * account it reaches them as.
15
+ *
16
+ * A stored value is write-only. Nothing here returns it over HTTP; it is
17
+ * decrypted only when a run is dispatched, into a header the runtime receives.
18
+ */
19
+ exports.MAX_CONNECTION_VALUE = 8_192;
20
+ /**
21
+ * Whether a connection can currently authenticate a run.
22
+ *
23
+ * `pending` exists because an OAuth connection is created before the user has
24
+ * consented: the row is the thing the callback completes. A run naming a
25
+ * pending or expired connection fails rather than calling the server without
26
+ * a credential — the server would answer as an anonymous caller, and for a
27
+ * broker that is a worse outcome than a refused run.
28
+ */
29
+ exports.connectionStatusSchema = zod_1.z.enum([
30
+ "pending",
31
+ "active",
32
+ "expired",
33
+ "revoked",
34
+ ]);
35
+ exports.connectionSchema = zod_1.z.object({
36
+ id: zod_1.z.string().describe("Unique identifier, prefixed `con_`."),
37
+ user_id: zod_1.z.string().describe("The end user this credential belongs to."),
38
+ server: zod_1.z.string().describe("Name of the registered MCP server."),
39
+ scheme: mcp_js_1.mcpConnectionSchemeSchema,
40
+ status: exports.connectionStatusSchema,
41
+ /**
42
+ * When the credential stops working, where the provider said so.
43
+ *
44
+ * Null for a scheme that does not expire, and for a provider that returned
45
+ * no expiry. A null expiry is not a promise that the credential is valid: it
46
+ * means nobody told us otherwise, and a rejected call is what reveals it.
47
+ */
48
+ expires_at: zod_1.z.string().nullable(),
49
+ /** Set when a run last authenticated with it. Null until one does. */
50
+ last_used_at: zod_1.z.string().nullable(),
51
+ created_at: zod_1.z.string(),
52
+ updated_at: zod_1.z.string(),
53
+ });
54
+ /**
55
+ * Supply a credential directly.
56
+ *
57
+ * For `api_key`, where the user already holds the value and there is nothing
58
+ * to redirect them through. Also the path a platform uses to push a token it
59
+ * obtained itself, which is how refresh works until Nixet performs it.
60
+ */
61
+ exports.createConnectionSchema = zod_1.z
62
+ .object({
63
+ user_id: zod_1.z.string().min(1).max(64).describe("End user to bind this credential to."),
64
+ server: zod_1.z
65
+ .string()
66
+ .min(1)
67
+ .max(64)
68
+ .describe("Registered MCP server. Its auth must be `per_user`."),
69
+ value: zod_1.z
70
+ .string()
71
+ .min(1)
72
+ .max(exports.MAX_CONNECTION_VALUE)
73
+ .describe("The credential. Stored encrypted and never returned."),
74
+ /**
75
+ * Optional, and trusted when given.
76
+ *
77
+ * A platform pushing an OAuth token knows when it expires; Nixet cannot
78
+ * infer it from an opaque string. Omitted means no known expiry, which the
79
+ * dispatch check treats as usable until the server says otherwise.
80
+ */
81
+ expires_at: zod_1.z
82
+ .string()
83
+ .datetime()
84
+ .optional()
85
+ .describe("When the credential stops working, if known."),
86
+ refresh_value: zod_1.z
87
+ .string()
88
+ .min(1)
89
+ .max(exports.MAX_CONNECTION_VALUE)
90
+ .optional()
91
+ .describe("Refresh token, where the provider issued one."),
92
+ })
93
+ .strict();
94
+ /**
95
+ * Begin a scheme that cannot be completed in one request.
96
+ *
97
+ * `oauth2` needs the user at the provider's consent screen, and `session`
98
+ * needs them at a sign-in page whose URL the server itself returns. Both answer
99
+ * with somewhere to send the user, and both leave a `pending` connection that
100
+ * the callback completes.
101
+ */
102
+ exports.authorizeConnectionSchema = zod_1.z
103
+ .object({
104
+ user_id: zod_1.z.string().min(1).max(64),
105
+ server: zod_1.z.string().min(1).max(64),
106
+ /**
107
+ * Where to send the user once the provider is done.
108
+ *
109
+ * Required, and checked against the workspace's registered origins: an
110
+ * open redirect here would hand an authorization code to whoever asked.
111
+ */
112
+ return_url: zod_1.z.string().url().max(500),
113
+ })
114
+ .strict();
115
+ exports.authorizationSchema = zod_1.z.object({
116
+ connection_id: zod_1.z.string(),
117
+ /** Send the user here. Single use, and short lived. */
118
+ redirect_url: zod_1.z.string(),
119
+ expires_at: zod_1.z.string(),
120
+ });
121
+ /** Filters for listing a user's connections. */
122
+ exports.findConnectionsSchema = zod_1.z
123
+ .object({
124
+ user_id: zod_1.z.string().min(1).max(64).optional(),
125
+ server: zod_1.z.string().min(1).max(64).optional(),
126
+ status: exports.connectionStatusSchema.optional(),
127
+ $limit: zod_1.z.coerce.number().int().min(1).max(100).optional(),
128
+ $offset: zod_1.z.coerce.number().int().min(0).optional(),
129
+ })
130
+ .strict();
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Conversations.
4
+ *
5
+ * A durable thread between one agent and one user. Each message sent creates a
6
+ * run, so cost, usage and the trace stay exactly as they are for a single-shot
7
+ * run; the conversation adds the history around them.
8
+ */
9
+ export declare const MAX_MESSAGE_LENGTH = 100000;
10
+ /**
11
+ * Which memories an agent may keep from this conversation.
12
+ *
13
+ * All default to off. The product rule is that an agent must not retain
14
+ * information without being told to, so retention is something a caller asks
15
+ * for rather than something they have to remember to switch off.
16
+ */
17
+ export declare const memoryPolicySchema: z.ZodObject<{
18
+ conversation: z.ZodDefault<z.ZodBoolean>;
19
+ user: z.ZodDefault<z.ZodBoolean>;
20
+ agent: z.ZodDefault<z.ZodBoolean>;
21
+ }, z.core.$strict>;
22
+ export type MemoryPolicy = z.infer<typeof memoryPolicySchema>;
23
+ export declare const conversationStatusSchema: z.ZodEnum<{
24
+ open: "open";
25
+ closed: "closed";
26
+ }>;
27
+ export type ConversationStatus = z.infer<typeof conversationStatusSchema>;
28
+ export declare const conversationSchema: z.ZodObject<{
29
+ id: z.ZodString;
30
+ agent_id: z.ZodString;
31
+ agent_version: z.ZodNullable<z.ZodString>;
32
+ user_id: z.ZodNullable<z.ZodString>;
33
+ title: z.ZodNullable<z.ZodString>;
34
+ status: z.ZodEnum<{
35
+ open: "open";
36
+ closed: "closed";
37
+ }>;
38
+ memory: z.ZodObject<{
39
+ conversation: z.ZodDefault<z.ZodBoolean>;
40
+ user: z.ZodDefault<z.ZodBoolean>;
41
+ agent: z.ZodDefault<z.ZodBoolean>;
42
+ }, z.core.$strict>;
43
+ message_count: z.ZodNumber;
44
+ last_run_id: z.ZodNullable<z.ZodString>;
45
+ created_at: z.ZodString;
46
+ updated_at: z.ZodString;
47
+ }, z.core.$strip>;
48
+ export type Conversation = z.infer<typeof conversationSchema>;
49
+ export declare const createConversationSchema: z.ZodObject<{
50
+ agent_id: z.ZodString;
51
+ user_id: z.ZodOptional<z.ZodString>;
52
+ title: z.ZodOptional<z.ZodString>;
53
+ memory: z.ZodOptional<z.ZodObject<{
54
+ conversation: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
55
+ user: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
56
+ agent: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
57
+ }, z.core.$strict>>;
58
+ agent_version: z.ZodOptional<z.ZodString>;
59
+ }, z.core.$strict>;
60
+ export type CreateConversationRequest = z.infer<typeof createConversationSchema>;
61
+ export declare const messageRoleSchema: z.ZodEnum<{
62
+ user: "user";
63
+ assistant: "assistant";
64
+ system: "system";
65
+ summary: "summary";
66
+ }>;
67
+ export type MessageRole = z.infer<typeof messageRoleSchema>;
68
+ export declare const conversationMessageSchema: z.ZodObject<{
69
+ id: z.ZodString;
70
+ conversation_id: z.ZodString;
71
+ sequence: z.ZodNumber;
72
+ role: z.ZodEnum<{
73
+ user: "user";
74
+ assistant: "assistant";
75
+ system: "system";
76
+ summary: "summary";
77
+ }>;
78
+ content: z.ZodString;
79
+ run_id: z.ZodNullable<z.ZodString>;
80
+ token_count: z.ZodNullable<z.ZodNumber>;
81
+ created_at: z.ZodString;
82
+ }, z.core.$strip>;
83
+ export type ConversationMessage = z.infer<typeof conversationMessageSchema>;
84
+ export declare const sendMessageSchema: z.ZodObject<{
85
+ input: z.ZodString;
86
+ provider: z.ZodOptional<z.ZodString>;
87
+ }, z.core.$strict>;
88
+ export type SendMessageRequest = z.infer<typeof sendMessageSchema>;
89
+ /** What a send returns: the reply, plus the run that produced it. */
90
+ export declare const sendMessageResponseSchema: z.ZodObject<{
91
+ message: z.ZodObject<{
92
+ id: z.ZodString;
93
+ conversation_id: z.ZodString;
94
+ sequence: z.ZodNumber;
95
+ role: z.ZodEnum<{
96
+ user: "user";
97
+ assistant: "assistant";
98
+ system: "system";
99
+ summary: "summary";
100
+ }>;
101
+ content: z.ZodString;
102
+ run_id: z.ZodNullable<z.ZodString>;
103
+ token_count: z.ZodNullable<z.ZodNumber>;
104
+ created_at: z.ZodString;
105
+ }, z.core.$strip>;
106
+ run_id: z.ZodString;
107
+ usage: z.ZodNullable<z.ZodObject<{
108
+ input_tokens: z.ZodNumber;
109
+ output_tokens: z.ZodNumber;
110
+ }, z.core.$strip>>;
111
+ cost_usd: z.ZodNullable<z.ZodNumber>;
112
+ }, z.core.$strip>;
113
+ export type SendMessageResponse = z.infer<typeof sendMessageResponseSchema>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendMessageResponseSchema = exports.sendMessageSchema = exports.conversationMessageSchema = exports.messageRoleSchema = exports.createConversationSchema = exports.conversationSchema = exports.conversationStatusSchema = exports.memoryPolicySchema = exports.MAX_MESSAGE_LENGTH = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Conversations.
7
+ *
8
+ * A durable thread between one agent and one user. Each message sent creates a
9
+ * run, so cost, usage and the trace stay exactly as they are for a single-shot
10
+ * run; the conversation adds the history around them.
11
+ */
12
+ exports.MAX_MESSAGE_LENGTH = 100_000;
13
+ /**
14
+ * Which memories an agent may keep from this conversation.
15
+ *
16
+ * All default to off. The product rule is that an agent must not retain
17
+ * information without being told to, so retention is something a caller asks
18
+ * for rather than something they have to remember to switch off.
19
+ */
20
+ exports.memoryPolicySchema = zod_1.z
21
+ .object({
22
+ conversation: zod_1.z.boolean().default(false).describe("Facts within this thread."),
23
+ user: zod_1.z.boolean().default(false).describe("Facts about this person."),
24
+ agent: zod_1.z.boolean().default(false).describe("Facts shared by every user."),
25
+ })
26
+ .strict();
27
+ exports.conversationStatusSchema = zod_1.z.enum(["open", "closed"]);
28
+ exports.conversationSchema = zod_1.z.object({
29
+ id: zod_1.z.string().describe("Unique identifier, prefixed `cnv_`."),
30
+ agent_id: zod_1.z.string(),
31
+ agent_version: zod_1.z
32
+ .string()
33
+ .nullable()
34
+ .describe("Pinned at creation, so a long thread cannot change behaviour."),
35
+ user_id: zod_1.z.string().nullable().describe("The person this thread is with."),
36
+ title: zod_1.z.string().nullable(),
37
+ status: exports.conversationStatusSchema,
38
+ memory: exports.memoryPolicySchema,
39
+ message_count: zod_1.z.number().int().nonnegative(),
40
+ last_run_id: zod_1.z.string().nullable(),
41
+ created_at: zod_1.z.string(),
42
+ updated_at: zod_1.z.string(),
43
+ });
44
+ exports.createConversationSchema = zod_1.z
45
+ .object({
46
+ agent_id: zod_1.z.string().min(1),
47
+ user_id: zod_1.z.string().min(1).optional(),
48
+ title: zod_1.z.string().trim().min(1).max(200).optional(),
49
+ memory: exports.memoryPolicySchema.partial().optional(),
50
+ /** Pins the agent version, so a long thread cannot change behaviour mid-way. */
51
+ agent_version: zod_1.z.string().min(1).optional(),
52
+ })
53
+ .strict();
54
+ exports.messageRoleSchema = zod_1.z.enum(["user", "assistant", "system", "summary"]);
55
+ exports.conversationMessageSchema = zod_1.z.object({
56
+ id: zod_1.z.string().describe("Unique identifier, prefixed `msg_`."),
57
+ conversation_id: zod_1.z.string(),
58
+ /** Monotonic within a conversation, so a transcript has a stable order. */
59
+ sequence: zod_1.z.number().int().nonnegative(),
60
+ role: exports.messageRoleSchema,
61
+ content: zod_1.z.string(),
62
+ /** The run that produced an assistant message; null for anything else. */
63
+ run_id: zod_1.z.string().nullable(),
64
+ token_count: zod_1.z.number().int().nonnegative().nullable(),
65
+ created_at: zod_1.z.string(),
66
+ });
67
+ exports.sendMessageSchema = zod_1.z
68
+ .object({
69
+ input: zod_1.z.string().trim().min(1).max(exports.MAX_MESSAGE_LENGTH),
70
+ /** Overrides the model provider for this message only. */
71
+ provider: zod_1.z.string().min(1).optional(),
72
+ })
73
+ .strict();
74
+ /** What a send returns: the reply, plus the run that produced it. */
75
+ exports.sendMessageResponseSchema = zod_1.z.object({
76
+ message: exports.conversationMessageSchema,
77
+ run_id: zod_1.z.string(),
78
+ usage: zod_1.z
79
+ .object({
80
+ input_tokens: zod_1.z.number().int().nonnegative(),
81
+ output_tokens: zod_1.z.number().int().nonnegative(),
82
+ })
83
+ .nullable(),
84
+ cost_usd: zod_1.z.number().nullable(),
85
+ });
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Converting a document to Markdown.
4
+ *
5
+ * The same conversion knowledge ingestion runs, exposed on its own. Ingestion
6
+ * chunks and embeds what it converts and keeps the result in a vector store;
7
+ * this answers with the Markdown and stores nothing, which is what a caller
8
+ * wanting to read a PDF rather than search it needs.
9
+ *
10
+ * Synchronous, so the Markdown is in the response rather than behind a job id.
11
+ * That is only honest below a size: conversion is local and fast for a
12
+ * document with a text layer, and a scanned document needs an OCR engine and
13
+ * minutes rather than milliseconds. The limit here is what keeps the
14
+ * difference from reaching the caller as a timeout.
15
+ */
16
+ /** Fourteen formats, identified from content rather than extension. */
17
+ export declare const MAX_DOCUMENT_BYTES: number;
18
+ export declare const documentConversionSchema: z.ZodObject<{
19
+ markdown: z.ZodString;
20
+ bytes: z.ZodNumber;
21
+ ocr_pages: z.ZodArray<z.ZodNumber>;
22
+ page_count: z.ZodNullable<z.ZodNumber>;
23
+ }, z.core.$strip>;
24
+ export type DocumentConversion = z.infer<typeof documentConversionSchema>;
25
+ /**
26
+ * A conversion, and the knowledge source it was filed as if one was asked for.
27
+ *
28
+ * Converting stores nothing by default: the bytes live for the length of the
29
+ * request and the Markdown is the answer. Naming a collection keeps the
30
+ * document as well, which means it is chunked, embedded and searchable by an
31
+ * agent — the same thing uploading it as a source would have done, in one
32
+ * call instead of two.
33
+ *
34
+ * `source` is null when nothing was stored, rather than the field being
35
+ * absent, so a caller reads one shape either way.
36
+ */
37
+ export declare const documentConversionResultSchema: z.ZodObject<{
38
+ markdown: z.ZodString;
39
+ bytes: z.ZodNumber;
40
+ ocr_pages: z.ZodArray<z.ZodNumber>;
41
+ page_count: z.ZodNullable<z.ZodNumber>;
42
+ source: z.ZodNullable<z.ZodObject<{
43
+ id: z.ZodString;
44
+ collection: z.ZodString;
45
+ status: z.ZodString;
46
+ }, z.core.$strip>>;
47
+ }, z.core.$strip>;
48
+ export type DocumentConversionResult = z.infer<typeof documentConversionResultSchema>;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.documentConversionResultSchema = exports.documentConversionSchema = exports.MAX_DOCUMENT_BYTES = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Converting a document to Markdown.
7
+ *
8
+ * The same conversion knowledge ingestion runs, exposed on its own. Ingestion
9
+ * chunks and embeds what it converts and keeps the result in a vector store;
10
+ * this answers with the Markdown and stores nothing, which is what a caller
11
+ * wanting to read a PDF rather than search it needs.
12
+ *
13
+ * Synchronous, so the Markdown is in the response rather than behind a job id.
14
+ * That is only honest below a size: conversion is local and fast for a
15
+ * document with a text layer, and a scanned document needs an OCR engine and
16
+ * minutes rather than milliseconds. The limit here is what keeps the
17
+ * difference from reaching the caller as a timeout.
18
+ */
19
+ /** Fourteen formats, identified from content rather than extension. */
20
+ exports.MAX_DOCUMENT_BYTES = 20 * 1024 * 1024;
21
+ exports.documentConversionSchema = zod_1.z.object({
22
+ /** The document, as Markdown. */
23
+ markdown: zod_1.z.string(),
24
+ /** Bytes read. Useful when the caller streamed rather than measured. */
25
+ bytes: zod_1.z.number().int().nonnegative(),
26
+ /**
27
+ * Pages that held no text and were read by an OCR engine.
28
+ *
29
+ * Empty for a document with a text layer, which is most of them. Non-empty
30
+ * means the Markdown came from reading pictures of text, and is worth
31
+ * showing a caller deciding whether to trust it.
32
+ */
33
+ ocr_pages: zod_1.z.array(zod_1.z.number().int().positive()),
34
+ /** Total pages, where the format has them. Null for a spreadsheet. */
35
+ page_count: zod_1.z.number().int().positive().nullable(),
36
+ });
37
+ /**
38
+ * A conversion, and the knowledge source it was filed as if one was asked for.
39
+ *
40
+ * Converting stores nothing by default: the bytes live for the length of the
41
+ * request and the Markdown is the answer. Naming a collection keeps the
42
+ * document as well, which means it is chunked, embedded and searchable by an
43
+ * agent — the same thing uploading it as a source would have done, in one
44
+ * call instead of two.
45
+ *
46
+ * `source` is null when nothing was stored, rather than the field being
47
+ * absent, so a caller reads one shape either way.
48
+ */
49
+ exports.documentConversionResultSchema = exports.documentConversionSchema.extend({
50
+ source: zod_1.z
51
+ .object({
52
+ id: zod_1.z.string().describe("Identifier of the stored source, prefixed `src_`."),
53
+ collection: zod_1.z.string(),
54
+ /**
55
+ * Always `pending` here.
56
+ *
57
+ * The row is written once the bytes are in storage, and a worker claims
58
+ * it afterwards to chunk and embed. So the Markdown in this response is
59
+ * ready and the searchable copy is not yet.
60
+ */
61
+ status: zod_1.z.string(),
62
+ })
63
+ .nullable(),
64
+ });
@@ -0,0 +1,211 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Guardrails: inspecting and rewriting what an agent is given and what it says.
4
+ *
5
+ * A guard belongs to the workspace, not to a version. A rule like "never name
6
+ * a specific fund" applies to every agent a customer will ever run, and
7
+ * defining it per version would mean maintaining it in as many places as there
8
+ * are versions. A version names the guards it uses, the same way it names MCP
9
+ * servers and knowledge collections, and pins them by name at publish.
10
+ *
11
+ * Declarative rather than code. A guard runs on every turn, and an output
12
+ * guard runs inside the stream, so a network hop per guard would be paid in
13
+ * first-token latency — four guards on one turn would be felt. Patterns and
14
+ * the built-in detectors cover the common rules; anything needing real logic
15
+ * is a separate question with a different cost, and is deliberately not
16
+ * pretended to here.
17
+ */
18
+ /**
19
+ * Where a guard runs.
20
+ *
21
+ * `tool_result` is the one that is easy to leave out and the one that leaves a
22
+ * hole. A tool returning structured data — a component tree, a row set —
23
+ * reaches the caller without passing through the agent's text, so an output
24
+ * guard never sees it. Any agent that renders what a tool returns needs this
25
+ * stage.
26
+ */
27
+ export declare const guardrailStageSchema: z.ZodEnum<{
28
+ output: "output";
29
+ input: "input";
30
+ tool_result: "tool_result";
31
+ }>;
32
+ export type GuardrailStage = z.infer<typeof guardrailStageSchema>;
33
+ /**
34
+ * What a guard does when it matches.
35
+ *
36
+ * `modify` is the one that earns its place. "Scrub the fund name and let the
37
+ * rest through" is better product behaviour than refusing the turn, and
38
+ * refusing is what a guard that can only block has to do.
39
+ *
40
+ * `warn` passes the text through unchanged and records that it matched, which
41
+ * is how a rule is introduced before it is enforced.
42
+ */
43
+ export declare const guardrailActionSchema: z.ZodEnum<{
44
+ allow: "allow";
45
+ modify: "modify";
46
+ warn: "warn";
47
+ block: "block";
48
+ }>;
49
+ export type GuardrailAction = z.infer<typeof guardrailActionSchema>;
50
+ /** What a guard inspects with. */
51
+ export declare const guardrailKindSchema: z.ZodEnum<{
52
+ patterns: "patterns";
53
+ builtin: "builtin";
54
+ }>;
55
+ export type GuardrailKind = z.infer<typeof guardrailKindSchema>;
56
+ /**
57
+ * The detectors the runtime already carries.
58
+ *
59
+ * Named rather than described, because each is code in the runtime and a
60
+ * customer choosing one is choosing behaviour that already exists rather than
61
+ * specifying new behaviour.
62
+ */
63
+ export declare const guardrailDetectorSchema: z.ZodEnum<{
64
+ pii: "pii";
65
+ topics: "topics";
66
+ length: "length";
67
+ }>;
68
+ export type GuardrailDetector = z.infer<typeof guardrailDetectorSchema>;
69
+ /**
70
+ * One find-and-replace rule.
71
+ *
72
+ * `replace` is what makes a pattern guard a rewriter rather than only a
73
+ * detector. Omitted, a match means the guard's action fires with nothing
74
+ * substituted, which is what `block` and `warn` want.
75
+ */
76
+ export declare const guardrailPatternSchema: z.ZodObject<{
77
+ match: z.ZodString;
78
+ replace: z.ZodOptional<z.ZodString>;
79
+ }, z.core.$strict>;
80
+ export type GuardrailPattern = z.infer<typeof guardrailPatternSchema>;
81
+ export declare const guardrailSchema: z.ZodObject<{
82
+ id: z.ZodString;
83
+ name: z.ZodString;
84
+ description: z.ZodNullable<z.ZodString>;
85
+ stage: z.ZodEnum<{
86
+ output: "output";
87
+ input: "input";
88
+ tool_result: "tool_result";
89
+ }>;
90
+ kind: z.ZodEnum<{
91
+ patterns: "patterns";
92
+ builtin: "builtin";
93
+ }>;
94
+ action: z.ZodEnum<{
95
+ allow: "allow";
96
+ modify: "modify";
97
+ warn: "warn";
98
+ block: "block";
99
+ }>;
100
+ patterns: z.ZodArray<z.ZodObject<{
101
+ match: z.ZodString;
102
+ replace: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strict>>;
104
+ detector: z.ZodNullable<z.ZodEnum<{
105
+ pii: "pii";
106
+ topics: "topics";
107
+ length: "length";
108
+ }>>;
109
+ topics: z.ZodArray<z.ZodString>;
110
+ max_characters: z.ZodNullable<z.ZodNumber>;
111
+ message: z.ZodNullable<z.ZodString>;
112
+ created_at: z.ZodString;
113
+ updated_at: z.ZodString;
114
+ }, z.core.$strip>;
115
+ export type Guardrail = z.infer<typeof guardrailSchema>;
116
+ export declare const createGuardrailSchema: z.ZodObject<{
117
+ name: z.ZodString;
118
+ description: z.ZodOptional<z.ZodString>;
119
+ stage: z.ZodEnum<{
120
+ output: "output";
121
+ input: "input";
122
+ tool_result: "tool_result";
123
+ }>;
124
+ action: z.ZodEnum<{
125
+ allow: "allow";
126
+ modify: "modify";
127
+ warn: "warn";
128
+ block: "block";
129
+ }>;
130
+ patterns: z.ZodDefault<z.ZodArray<z.ZodObject<{
131
+ match: z.ZodString;
132
+ replace: z.ZodOptional<z.ZodString>;
133
+ }, z.core.$strict>>>;
134
+ detector: z.ZodOptional<z.ZodEnum<{
135
+ pii: "pii";
136
+ topics: "topics";
137
+ length: "length";
138
+ }>>;
139
+ topics: z.ZodDefault<z.ZodArray<z.ZodString>>;
140
+ max_characters: z.ZodOptional<z.ZodNumber>;
141
+ message: z.ZodOptional<z.ZodString>;
142
+ }, z.core.$strict>;
143
+ export type CreateGuardrailRequest = z.infer<typeof createGuardrailSchema>;
144
+ /**
145
+ * How a version runs the guards it names.
146
+ *
147
+ * `fail_fast` stops at the first block, which is what a caller wants when any
148
+ * single refusal ends the turn. `run_all` applies every guard, and each sees
149
+ * the text the previous one produced — so four scrubbing rules compose into
150
+ * one rewritten response instead of the last one winning. Ordering within each
151
+ * stage is the order given here, and is therefore explicit rather than
152
+ * incidental.
153
+ */
154
+ export declare const guardrailModeSchema: z.ZodEnum<{
155
+ fail_fast: "fail_fast";
156
+ run_all: "run_all";
157
+ }>;
158
+ export type GuardrailMode = z.infer<typeof guardrailModeSchema>;
159
+ /**
160
+ * What a blocked run answers with.
161
+ *
162
+ * `return_message` completes the run with the guard's message as the output,
163
+ * which is a turn the caller can show someone. `error` fails the run, which is
164
+ * right when a block means the request should never have been made.
165
+ */
166
+ export declare const guardrailOnBlockSchema: z.ZodEnum<{
167
+ error: "error";
168
+ return_message: "return_message";
169
+ }>;
170
+ export type GuardrailOnBlock = z.infer<typeof guardrailOnBlockSchema>;
171
+ export declare const guardrailBindingSchema: z.ZodObject<{
172
+ input: z.ZodDefault<z.ZodArray<z.ZodString>>;
173
+ output: z.ZodDefault<z.ZodArray<z.ZodString>>;
174
+ tool_result: z.ZodDefault<z.ZodArray<z.ZodString>>;
175
+ mode: z.ZodDefault<z.ZodEnum<{
176
+ fail_fast: "fail_fast";
177
+ run_all: "run_all";
178
+ }>>;
179
+ on_block: z.ZodDefault<z.ZodEnum<{
180
+ error: "error";
181
+ return_message: "return_message";
182
+ }>>;
183
+ }, z.core.$strict>;
184
+ export type GuardrailBinding = z.infer<typeof guardrailBindingSchema>;
185
+ export declare const GUARDRAILS_OFF: GuardrailBinding;
186
+ /** Every guard a binding names, across all three stages, without repeats. */
187
+ export declare function guardrailNamesIn(binding: GuardrailBinding): string[];
188
+ /**
189
+ * One guard's verdict on one piece of text.
190
+ *
191
+ * Reported per guard rather than collapsed, so a trace can say which rule
192
+ * rewrote what. A `modify` carries the text it produced, which is also the
193
+ * input to the next guard in `run_all`.
194
+ */
195
+ export declare const guardrailOutcomeSchema: z.ZodObject<{
196
+ guardrail: z.ZodString;
197
+ stage: z.ZodEnum<{
198
+ output: "output";
199
+ input: "input";
200
+ tool_result: "tool_result";
201
+ }>;
202
+ action: z.ZodEnum<{
203
+ allow: "allow";
204
+ modify: "modify";
205
+ warn: "warn";
206
+ block: "block";
207
+ }>;
208
+ message: z.ZodNullable<z.ZodString>;
209
+ matches: z.ZodNumber;
210
+ }, z.core.$strip>;
211
+ export type GuardrailOutcome = z.infer<typeof guardrailOutcomeSchema>;