@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,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.guardrailOutcomeSchema = exports.GUARDRAILS_OFF = exports.guardrailBindingSchema = exports.guardrailOnBlockSchema = exports.guardrailModeSchema = exports.createGuardrailSchema = exports.guardrailSchema = exports.guardrailPatternSchema = exports.guardrailDetectorSchema = exports.guardrailKindSchema = exports.guardrailActionSchema = exports.guardrailStageSchema = void 0;
4
+ exports.guardrailNamesIn = guardrailNamesIn;
5
+ const zod_1 = require("zod");
6
+ /**
7
+ * Guardrails: inspecting and rewriting what an agent is given and what it says.
8
+ *
9
+ * A guard belongs to the workspace, not to a version. A rule like "never name
10
+ * a specific fund" applies to every agent a customer will ever run, and
11
+ * defining it per version would mean maintaining it in as many places as there
12
+ * are versions. A version names the guards it uses, the same way it names MCP
13
+ * servers and knowledge collections, and pins them by name at publish.
14
+ *
15
+ * Declarative rather than code. A guard runs on every turn, and an output
16
+ * guard runs inside the stream, so a network hop per guard would be paid in
17
+ * first-token latency — four guards on one turn would be felt. Patterns and
18
+ * the built-in detectors cover the common rules; anything needing real logic
19
+ * is a separate question with a different cost, and is deliberately not
20
+ * pretended to here.
21
+ */
22
+ /**
23
+ * Where a guard runs.
24
+ *
25
+ * `tool_result` is the one that is easy to leave out and the one that leaves a
26
+ * hole. A tool returning structured data — a component tree, a row set —
27
+ * reaches the caller without passing through the agent's text, so an output
28
+ * guard never sees it. Any agent that renders what a tool returns needs this
29
+ * stage.
30
+ */
31
+ exports.guardrailStageSchema = zod_1.z.enum(["input", "output", "tool_result"]);
32
+ /**
33
+ * What a guard does when it matches.
34
+ *
35
+ * `modify` is the one that earns its place. "Scrub the fund name and let the
36
+ * rest through" is better product behaviour than refusing the turn, and
37
+ * refusing is what a guard that can only block has to do.
38
+ *
39
+ * `warn` passes the text through unchanged and records that it matched, which
40
+ * is how a rule is introduced before it is enforced.
41
+ */
42
+ exports.guardrailActionSchema = zod_1.z.enum(["allow", "modify", "warn", "block"]);
43
+ /** What a guard inspects with. */
44
+ exports.guardrailKindSchema = zod_1.z.enum(["patterns", "builtin"]);
45
+ /**
46
+ * The detectors the runtime already carries.
47
+ *
48
+ * Named rather than described, because each is code in the runtime and a
49
+ * customer choosing one is choosing behaviour that already exists rather than
50
+ * specifying new behaviour.
51
+ */
52
+ exports.guardrailDetectorSchema = zod_1.z.enum([
53
+ /** Personal data: names, emails, phone numbers, account identifiers. */
54
+ "pii",
55
+ /** Refuses text about a named subject. Needs `topics`. */
56
+ "topics",
57
+ /** Refuses text longer than `max_characters`. */
58
+ "length",
59
+ ]);
60
+ /**
61
+ * One find-and-replace rule.
62
+ *
63
+ * `replace` is what makes a pattern guard a rewriter rather than only a
64
+ * detector. Omitted, a match means the guard's action fires with nothing
65
+ * substituted, which is what `block` and `warn` want.
66
+ */
67
+ exports.guardrailPatternSchema = zod_1.z
68
+ .object({
69
+ match: zod_1.z
70
+ .string()
71
+ .min(1)
72
+ .max(500)
73
+ .describe("A regular expression, applied case-insensitively."),
74
+ replace: zod_1.z
75
+ .string()
76
+ .max(200)
77
+ .optional()
78
+ .describe("What to put in its place. Required by `modify`, ignored otherwise."),
79
+ })
80
+ .strict();
81
+ exports.guardrailSchema = zod_1.z.object({
82
+ id: zod_1.z.string().describe("Unique identifier, prefixed `grd_`."),
83
+ name: zod_1.z.string().describe("The handle a version pins."),
84
+ description: zod_1.z.string().nullable(),
85
+ stage: exports.guardrailStageSchema,
86
+ kind: exports.guardrailKindSchema,
87
+ action: exports.guardrailActionSchema,
88
+ patterns: zod_1.z.array(exports.guardrailPatternSchema),
89
+ detector: exports.guardrailDetectorSchema.nullable(),
90
+ topics: zod_1.z.array(zod_1.z.string()),
91
+ max_characters: zod_1.z.number().int().positive().nullable(),
92
+ /** Shown to the caller when the guard blocks, and recorded when it matches. */
93
+ message: zod_1.z.string().nullable(),
94
+ created_at: zod_1.z.string(),
95
+ updated_at: zod_1.z.string(),
96
+ });
97
+ exports.createGuardrailSchema = zod_1.z
98
+ .object({
99
+ name: zod_1.z
100
+ .string()
101
+ .trim()
102
+ .min(1)
103
+ .max(64)
104
+ .regex(/^[a-z0-9][a-z0-9-]*$/, "A guardrail name holds lowercase letters, numbers and hyphens.")
105
+ .describe("How a version refers to this guard."),
106
+ description: zod_1.z.string().trim().max(200).optional(),
107
+ stage: exports.guardrailStageSchema,
108
+ action: exports.guardrailActionSchema.describe("What happens on a match. `modify` needs a `replace` on every pattern."),
109
+ patterns: zod_1.z
110
+ .array(exports.guardrailPatternSchema)
111
+ .max(50)
112
+ .default([])
113
+ .describe("Rules for a `patterns` guard. Omit for a `builtin` one."),
114
+ detector: exports.guardrailDetectorSchema
115
+ .optional()
116
+ .describe("One of the runtime's own detectors. Omit for a `patterns` guard."),
117
+ topics: zod_1.z
118
+ .array(zod_1.z.string().trim().min(1).max(80))
119
+ .max(50)
120
+ .default([])
121
+ .describe("Subjects the `topics` detector refuses."),
122
+ max_characters: zod_1.z
123
+ .number()
124
+ .int()
125
+ .positive()
126
+ .max(1_000_000)
127
+ .optional()
128
+ .describe("Limit for the `length` detector."),
129
+ message: zod_1.z
130
+ .string()
131
+ .trim()
132
+ .max(500)
133
+ .optional()
134
+ .describe("Shown when this guard blocks. Recorded whenever it matches."),
135
+ })
136
+ .strict()
137
+ .refine((value) => Boolean(value.detector) !== value.patterns.length > 0, {
138
+ message: "A guardrail is either patterns or a built-in detector, not both and not neither.",
139
+ })
140
+ .refine((value) => value.action !== "modify" ||
141
+ value.detector !== undefined ||
142
+ value.patterns.every((pattern) => pattern.replace !== undefined), {
143
+ message: "A `modify` guardrail needs a `replace` on every pattern: there is nothing to rewrite with otherwise.",
144
+ })
145
+ .refine((value) => value.detector !== "topics" || value.topics.length > 0, {
146
+ message: "The `topics` detector needs at least one topic.",
147
+ })
148
+ .refine((value) => value.detector !== "length" || value.max_characters !== undefined, {
149
+ message: "The `length` detector needs `max_characters`.",
150
+ });
151
+ /**
152
+ * How a version runs the guards it names.
153
+ *
154
+ * `fail_fast` stops at the first block, which is what a caller wants when any
155
+ * single refusal ends the turn. `run_all` applies every guard, and each sees
156
+ * the text the previous one produced — so four scrubbing rules compose into
157
+ * one rewritten response instead of the last one winning. Ordering within each
158
+ * stage is the order given here, and is therefore explicit rather than
159
+ * incidental.
160
+ */
161
+ exports.guardrailModeSchema = zod_1.z.enum(["fail_fast", "run_all"]);
162
+ /**
163
+ * What a blocked run answers with.
164
+ *
165
+ * `return_message` completes the run with the guard's message as the output,
166
+ * which is a turn the caller can show someone. `error` fails the run, which is
167
+ * right when a block means the request should never have been made.
168
+ */
169
+ exports.guardrailOnBlockSchema = zod_1.z.enum(["return_message", "error"]);
170
+ exports.guardrailBindingSchema = zod_1.z
171
+ .object({
172
+ input: zod_1.z.array(zod_1.z.string().min(1).max(64)).max(10).default([]),
173
+ output: zod_1.z.array(zod_1.z.string().min(1).max(64)).max(10).default([]),
174
+ tool_result: zod_1.z.array(zod_1.z.string().min(1).max(64)).max(10).default([]),
175
+ mode: exports.guardrailModeSchema.default("run_all"),
176
+ on_block: exports.guardrailOnBlockSchema.default("return_message"),
177
+ })
178
+ .strict();
179
+ exports.GUARDRAILS_OFF = {
180
+ input: [],
181
+ output: [],
182
+ tool_result: [],
183
+ mode: "run_all",
184
+ on_block: "return_message",
185
+ };
186
+ /** Every guard a binding names, across all three stages, without repeats. */
187
+ function guardrailNamesIn(binding) {
188
+ return [
189
+ ...new Set([...binding.input, ...binding.output, ...binding.tool_result]),
190
+ ];
191
+ }
192
+ /**
193
+ * One guard's verdict on one piece of text.
194
+ *
195
+ * Reported per guard rather than collapsed, so a trace can say which rule
196
+ * rewrote what. A `modify` carries the text it produced, which is also the
197
+ * input to the next guard in `run_all`.
198
+ */
199
+ exports.guardrailOutcomeSchema = zod_1.z.object({
200
+ guardrail: zod_1.z.string(),
201
+ stage: exports.guardrailStageSchema,
202
+ action: exports.guardrailActionSchema,
203
+ message: zod_1.z.string().nullable(),
204
+ /** How many of its patterns or detections matched. Zero means it allowed. */
205
+ matches: zod_1.z.number().int().nonnegative(),
206
+ });
@@ -0,0 +1,55 @@
1
+ import { z } from "zod";
2
+ export declare const roleSchema: z.ZodEnum<{
3
+ owner: "owner";
4
+ admin: "admin";
5
+ developer: "developer";
6
+ operator: "operator";
7
+ viewer: "viewer";
8
+ }>;
9
+ export type Role = z.infer<typeof roleSchema>;
10
+ export declare const membershipSchema: z.ZodObject<{
11
+ organization_id: z.ZodString;
12
+ project_id: z.ZodString;
13
+ role: z.ZodEnum<{
14
+ owner: "owner";
15
+ admin: "admin";
16
+ developer: "developer";
17
+ operator: "operator";
18
+ viewer: "viewer";
19
+ }>;
20
+ }, z.core.$strip>;
21
+ /** Verified console identity. Never carries a credential. */
22
+ export declare const sessionSchema: z.ZodObject<{
23
+ subject: z.ZodString;
24
+ email: z.ZodNullable<z.ZodString>;
25
+ memberships: z.ZodArray<z.ZodObject<{
26
+ organization_id: z.ZodString;
27
+ project_id: z.ZodString;
28
+ role: z.ZodEnum<{
29
+ owner: "owner";
30
+ admin: "admin";
31
+ developer: "developer";
32
+ operator: "operator";
33
+ viewer: "viewer";
34
+ }>;
35
+ }, z.core.$strip>>;
36
+ }, z.core.$strip>;
37
+ export type Session = z.infer<typeof sessionSchema>;
38
+ export declare const sessionResponseSchema: z.ZodObject<{
39
+ message: z.ZodString;
40
+ data: z.ZodObject<{
41
+ subject: z.ZodString;
42
+ email: z.ZodNullable<z.ZodString>;
43
+ memberships: z.ZodArray<z.ZodObject<{
44
+ organization_id: z.ZodString;
45
+ project_id: z.ZodString;
46
+ role: z.ZodEnum<{
47
+ owner: "owner";
48
+ admin: "admin";
49
+ developer: "developer";
50
+ operator: "operator";
51
+ viewer: "viewer";
52
+ }>;
53
+ }, z.core.$strip>>;
54
+ }, z.core.$strip>;
55
+ }, z.core.$strip>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sessionResponseSchema = exports.sessionSchema = exports.membershipSchema = exports.roleSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.roleSchema = zod_1.z.enum([
6
+ "owner",
7
+ "admin",
8
+ "developer",
9
+ "operator",
10
+ "viewer",
11
+ ]);
12
+ exports.membershipSchema = zod_1.z.object({
13
+ organization_id: zod_1.z.string(),
14
+ project_id: zod_1.z.string(),
15
+ role: exports.roleSchema,
16
+ });
17
+ /** Verified console identity. Never carries a credential. */
18
+ exports.sessionSchema = zod_1.z.object({
19
+ subject: zod_1.z.string(),
20
+ email: zod_1.z.string().nullable(),
21
+ memberships: zod_1.z.array(exports.membershipSchema),
22
+ });
23
+ exports.sessionResponseSchema = zod_1.z.object({
24
+ message: zod_1.z.string(),
25
+ data: exports.sessionSchema,
26
+ });
@@ -0,0 +1,167 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Knowledge: a customer's own documents, searchable by an agent.
4
+ *
5
+ * A collection is a named index an agent version pins, the way it pins an MCP
6
+ * server. A source is one document in it. Chunks are what a search returns,
7
+ * and they are not a resource here: they live in the vector store the runtime
8
+ * owns, because a hundred chunks of one PDF do not belong in a response about
9
+ * that PDF.
10
+ *
11
+ * Ingestion is asynchronous. A source is registered immediately and processed
12
+ * by a worker, so the status on the row is the honest answer to "can my agent
13
+ * use this yet".
14
+ */
15
+ /** Where a source's content came from. */
16
+ export declare const sourceKindSchema: z.ZodEnum<{
17
+ file: "file";
18
+ url: "url";
19
+ text: "text";
20
+ }>;
21
+ export type SourceKind = z.infer<typeof sourceKindSchema>;
22
+ /**
23
+ * How far a source has got.
24
+ *
25
+ * Named after the step in progress rather than a generic "processing", so a
26
+ * customer waiting on a slow document can see whether it is being OCR'd — the
27
+ * one step that takes minutes rather than milliseconds.
28
+ */
29
+ export declare const sourceStatusSchema: z.ZodEnum<{
30
+ failed: "failed";
31
+ pending: "pending";
32
+ converting: "converting";
33
+ ocr: "ocr";
34
+ chunking: "chunking";
35
+ embedding: "embedding";
36
+ ready: "ready";
37
+ }>;
38
+ export type SourceStatus = z.infer<typeof sourceStatusSchema>;
39
+ /**
40
+ * How a collection splits a document.
41
+ *
42
+ * `markdown` follows headings, which suits documents with a structure worth
43
+ * preserving. `recursive` splits on paragraph and sentence boundaries and is
44
+ * the safe default for prose that has none.
45
+ */
46
+ export declare const chunkStrategySchema: z.ZodEnum<{
47
+ markdown: "markdown";
48
+ recursive: "recursive";
49
+ }>;
50
+ export type ChunkStrategy = z.infer<typeof chunkStrategySchema>;
51
+ export declare const knowledgeNameSchema: z.ZodString;
52
+ /**
53
+ * A collection.
54
+ *
55
+ * `chunk_size` and `chunk_overlap` are fixed when it is created, because
56
+ * changing them would make the chunks already in it inconsistent with the ones
57
+ * added next. Re-chunking differently means a new collection.
58
+ */
59
+ export declare const knowledgeCollectionSchema: z.ZodObject<{
60
+ id: z.ZodString;
61
+ name: z.ZodString;
62
+ description: z.ZodNullable<z.ZodString>;
63
+ chunk_strategy: z.ZodEnum<{
64
+ markdown: "markdown";
65
+ recursive: "recursive";
66
+ }>;
67
+ chunk_size: z.ZodNumber;
68
+ chunk_overlap: z.ZodNumber;
69
+ embedding_model: z.ZodString;
70
+ source_count: z.ZodNumber;
71
+ chunk_count: z.ZodNumber;
72
+ created_at: z.ZodString;
73
+ updated_at: z.ZodString;
74
+ }, z.core.$strip>;
75
+ export type KnowledgeCollection = z.infer<typeof knowledgeCollectionSchema>;
76
+ export declare const createKnowledgeCollectionSchema: z.ZodObject<{
77
+ name: z.ZodString;
78
+ description: z.ZodOptional<z.ZodString>;
79
+ chunk_strategy: z.ZodDefault<z.ZodEnum<{
80
+ markdown: "markdown";
81
+ recursive: "recursive";
82
+ }>>;
83
+ chunk_size: z.ZodDefault<z.ZodNumber>;
84
+ chunk_overlap: z.ZodDefault<z.ZodNumber>;
85
+ }, z.core.$strict>;
86
+ export type CreateKnowledgeCollectionRequest = z.infer<typeof createKnowledgeCollectionSchema>;
87
+ /**
88
+ * A source.
89
+ *
90
+ * `storage_key` and `checksum` describe the original, which is kept:
91
+ * re-chunking at a different size, or re-running a better OCR engine, should
92
+ * not require the customer to upload the file again.
93
+ *
94
+ * `generation` increments when a source is re-ingested. The chunks of an older
95
+ * generation stay in the store, so a run that already happened can still be
96
+ * explained by what it actually searched.
97
+ */
98
+ export declare const knowledgeSourceSchema: z.ZodObject<{
99
+ id: z.ZodString;
100
+ collection_id: z.ZodString;
101
+ collection_name: z.ZodString;
102
+ kind: z.ZodEnum<{
103
+ file: "file";
104
+ url: "url";
105
+ text: "text";
106
+ }>;
107
+ title: z.ZodString;
108
+ status: z.ZodEnum<{
109
+ failed: "failed";
110
+ pending: "pending";
111
+ converting: "converting";
112
+ ocr: "ocr";
113
+ chunking: "chunking";
114
+ embedding: "embedding";
115
+ ready: "ready";
116
+ }>;
117
+ error: z.ZodNullable<z.ZodString>;
118
+ size: z.ZodNumber;
119
+ mime_type: z.ZodNullable<z.ZodString>;
120
+ checksum: z.ZodNullable<z.ZodString>;
121
+ chunk_count: z.ZodNumber;
122
+ ocr_pages: z.ZodNullable<z.ZodArray<z.ZodNumber>>;
123
+ page_count: z.ZodNullable<z.ZodNumber>;
124
+ fetched_url: z.ZodNullable<z.ZodString>;
125
+ generation: z.ZodNumber;
126
+ created_at: z.ZodString;
127
+ updated_at: z.ZodString;
128
+ }, z.core.$strip>;
129
+ export type KnowledgeSource = z.infer<typeof knowledgeSourceSchema>;
130
+ /**
131
+ * Registering a source.
132
+ *
133
+ * A file arrives as multipart rather than through this schema — bytes do not
134
+ * belong in JSON — so this covers `text` and `url`, and the file path carries
135
+ * its own validation.
136
+ */
137
+ export declare const createKnowledgeSourceSchema: z.ZodObject<{
138
+ collection: z.ZodString;
139
+ kind: z.ZodEnum<{
140
+ url: "url";
141
+ text: "text";
142
+ }>;
143
+ title: z.ZodString;
144
+ content: z.ZodString;
145
+ }, z.core.$strict>;
146
+ export type CreateKnowledgeSourceRequest = z.infer<typeof createKnowledgeSourceSchema>;
147
+ /**
148
+ * What a run searched, recorded on the trace.
149
+ *
150
+ * The chunk's text is not here. A trace is read by people who may not be
151
+ * entitled to the document, and a retrieval event that quoted it would be a
152
+ * copy of the content outside the store that governs access to it.
153
+ */
154
+ export declare const retrievedChunkSchema: z.ZodObject<{
155
+ source_id: z.ZodString;
156
+ source_title: z.ZodString;
157
+ collection_name: z.ZodString;
158
+ score: z.ZodNumber;
159
+ generation: z.ZodNumber;
160
+ }, z.core.$strip>;
161
+ export type RetrievedChunk = z.infer<typeof retrievedChunkSchema>;
162
+ /** The states a worker may claim, and what it moves them to. */
163
+ export declare const INGESTIBLE_STATUSES: readonly SourceStatus[];
164
+ /** Statuses from which nothing further happens on its own. */
165
+ export declare const TERMINAL_STATUSES: readonly SourceStatus[];
166
+ /** Whether a source is still on its way to being searchable. */
167
+ export declare function isInFlight(status: SourceStatus): boolean;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TERMINAL_STATUSES = exports.INGESTIBLE_STATUSES = exports.retrievedChunkSchema = exports.createKnowledgeSourceSchema = exports.knowledgeSourceSchema = exports.createKnowledgeCollectionSchema = exports.knowledgeCollectionSchema = exports.knowledgeNameSchema = exports.chunkStrategySchema = exports.sourceStatusSchema = exports.sourceKindSchema = void 0;
4
+ exports.isInFlight = isInFlight;
5
+ const zod_1 = require("zod");
6
+ /**
7
+ * Knowledge: a customer's own documents, searchable by an agent.
8
+ *
9
+ * A collection is a named index an agent version pins, the way it pins an MCP
10
+ * server. A source is one document in it. Chunks are what a search returns,
11
+ * and they are not a resource here: they live in the vector store the runtime
12
+ * owns, because a hundred chunks of one PDF do not belong in a response about
13
+ * that PDF.
14
+ *
15
+ * Ingestion is asynchronous. A source is registered immediately and processed
16
+ * by a worker, so the status on the row is the honest answer to "can my agent
17
+ * use this yet".
18
+ */
19
+ /** Where a source's content came from. */
20
+ exports.sourceKindSchema = zod_1.z.enum(["file", "text", "url"]);
21
+ /**
22
+ * How far a source has got.
23
+ *
24
+ * Named after the step in progress rather than a generic "processing", so a
25
+ * customer waiting on a slow document can see whether it is being OCR'd — the
26
+ * one step that takes minutes rather than milliseconds.
27
+ */
28
+ exports.sourceStatusSchema = zod_1.z.enum([
29
+ "pending",
30
+ "converting",
31
+ "ocr",
32
+ "chunking",
33
+ "embedding",
34
+ "ready",
35
+ "failed",
36
+ ]);
37
+ /**
38
+ * How a collection splits a document.
39
+ *
40
+ * `markdown` follows headings, which suits documents with a structure worth
41
+ * preserving. `recursive` splits on paragraph and sentence boundaries and is
42
+ * the safe default for prose that has none.
43
+ */
44
+ exports.chunkStrategySchema = zod_1.z.enum(["markdown", "recursive"]);
45
+ exports.knowledgeNameSchema = zod_1.z
46
+ .string()
47
+ .trim()
48
+ .min(1)
49
+ .max(64)
50
+ .regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "Use lowercase letters, numbers and hyphens, e.g. `support-policies`.");
51
+ /**
52
+ * A collection.
53
+ *
54
+ * `chunk_size` and `chunk_overlap` are fixed when it is created, because
55
+ * changing them would make the chunks already in it inconsistent with the ones
56
+ * added next. Re-chunking differently means a new collection.
57
+ */
58
+ exports.knowledgeCollectionSchema = zod_1.z.object({
59
+ id: zod_1.z.string().describe("Unique identifier, prefixed `kbc_`."),
60
+ name: zod_1.z
61
+ .string()
62
+ .describe("Stable handle a version pins, e.g. `support-policies`."),
63
+ description: zod_1.z.string().nullable(),
64
+ chunk_strategy: exports.chunkStrategySchema,
65
+ chunk_size: zod_1.z.number(),
66
+ chunk_overlap: zod_1.z.number(),
67
+ /** The model that embedded every chunk in here. */
68
+ embedding_model: zod_1.z.string(),
69
+ /** How many sources are in this collection, whatever their status. */
70
+ source_count: zod_1.z.number(),
71
+ /** Chunks across every source that reached `ready`. */
72
+ chunk_count: zod_1.z.number(),
73
+ created_at: zod_1.z.string(),
74
+ updated_at: zod_1.z.string(),
75
+ });
76
+ exports.createKnowledgeCollectionSchema = zod_1.z
77
+ .object({
78
+ name: exports.knowledgeNameSchema,
79
+ description: zod_1.z.string().trim().max(200).optional(),
80
+ chunk_strategy: exports.chunkStrategySchema.default("recursive"),
81
+ chunk_size: zod_1.z.number().int().min(128).max(8000).default(1000),
82
+ chunk_overlap: zod_1.z.number().int().min(0).max(2000).default(200),
83
+ })
84
+ .strict()
85
+ .refine((value) => value.chunk_overlap < value.chunk_size, {
86
+ message: "chunk_overlap must be smaller than chunk_size.",
87
+ path: ["chunk_overlap"],
88
+ });
89
+ /**
90
+ * A source.
91
+ *
92
+ * `storage_key` and `checksum` describe the original, which is kept:
93
+ * re-chunking at a different size, or re-running a better OCR engine, should
94
+ * not require the customer to upload the file again.
95
+ *
96
+ * `generation` increments when a source is re-ingested. The chunks of an older
97
+ * generation stay in the store, so a run that already happened can still be
98
+ * explained by what it actually searched.
99
+ */
100
+ exports.knowledgeSourceSchema = zod_1.z.object({
101
+ id: zod_1.z.string().describe("Unique identifier, prefixed `kbs_`."),
102
+ collection_id: zod_1.z.string(),
103
+ /** The collection's handle, so a source can be read without a second call. */
104
+ collection_name: zod_1.z.string(),
105
+ kind: exports.sourceKindSchema,
106
+ /** A file's original name, a URL, or a title given to pasted text. */
107
+ title: zod_1.z.string(),
108
+ status: exports.sourceStatusSchema,
109
+ /** Why ingestion failed, when it did. */
110
+ error: zod_1.z.string().nullable(),
111
+ /** Bytes of the original. Zero for text that was pasted rather than uploaded. */
112
+ size: zod_1.z.number(),
113
+ mime_type: zod_1.z.string().nullable(),
114
+ checksum: zod_1.z.string().nullable(),
115
+ /** How many chunks this source produced. Zero until it is `ready`. */
116
+ chunk_count: zod_1.z.number(),
117
+ /**
118
+ * Pages that needed OCR, and how many there were.
119
+ *
120
+ * anydoc names the scanned pages when it refuses a PDF, so "2 of 340 pages
121
+ * were scanned" is answerable when someone asks why ingestion was slow.
122
+ */
123
+ ocr_pages: zod_1.z.array(zod_1.z.number()).nullable(),
124
+ page_count: zod_1.z.number().nullable(),
125
+ /**
126
+ * The page a `url` source was actually read from, when a redirect moved it.
127
+ *
128
+ * Null when nothing redirected, and for every other kind. `title` holds the
129
+ * address that was asked for, so a source that ended up somewhere else says
130
+ * both.
131
+ */
132
+ fetched_url: zod_1.z.string().nullable(),
133
+ generation: zod_1.z.number(),
134
+ created_at: zod_1.z.string(),
135
+ updated_at: zod_1.z.string(),
136
+ });
137
+ /**
138
+ * Registering a source.
139
+ *
140
+ * A file arrives as multipart rather than through this schema — bytes do not
141
+ * belong in JSON — so this covers `text` and `url`, and the file path carries
142
+ * its own validation.
143
+ */
144
+ exports.createKnowledgeSourceSchema = zod_1.z
145
+ .object({
146
+ collection: exports.knowledgeNameSchema,
147
+ kind: zod_1.z.enum(["text", "url"]),
148
+ title: zod_1.z.string().trim().min(1).max(200),
149
+ /** The text itself for `text`, the address for `url`. */
150
+ content: zod_1.z.string().trim().min(1).max(1_000_000),
151
+ })
152
+ .strict();
153
+ /**
154
+ * What a run searched, recorded on the trace.
155
+ *
156
+ * The chunk's text is not here. A trace is read by people who may not be
157
+ * entitled to the document, and a retrieval event that quoted it would be a
158
+ * copy of the content outside the store that governs access to it.
159
+ */
160
+ exports.retrievedChunkSchema = zod_1.z.object({
161
+ source_id: zod_1.z.string(),
162
+ source_title: zod_1.z.string(),
163
+ collection_name: zod_1.z.string(),
164
+ score: zod_1.z.number(),
165
+ generation: zod_1.z.number(),
166
+ });
167
+ /** The states a worker may claim, and what it moves them to. */
168
+ exports.INGESTIBLE_STATUSES = ["pending"];
169
+ /** Statuses from which nothing further happens on its own. */
170
+ exports.TERMINAL_STATUSES = ["ready", "failed"];
171
+ /** Whether a source is still on its way to being searchable. */
172
+ function isInFlight(status) {
173
+ return !exports.TERMINAL_STATUSES.includes(status);
174
+ }