@artkit-ai/core 0.1.0 → 0.2.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.
- package/dist/adapter.d.ts +119 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +45 -0
- package/dist/adapter.js.map +1 -0
- package/dist/diff.d.ts +1 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/engine.d.ts +29 -23
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +148 -197
- package/dist/engine.js.map +1 -1
- package/dist/envelope.d.ts +10 -27
- package/dist/envelope.d.ts.map +1 -1
- package/dist/envelope.js +8 -20
- package/dist/envelope.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +4 -4
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +2 -10
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/i18n.d.ts +8 -14
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +12 -18
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/memory.d.ts +0 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +15 -109
- package/dist/memory.js.map +1 -1
- package/dist/migrations.d.ts +6 -5
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +20 -14
- package/dist/migrations.js.map +1 -1
- package/dist/projection.d.ts +22 -6
- package/dist/projection.d.ts.map +1 -1
- package/dist/projection.js +5 -5
- package/dist/projection.js.map +1 -1
- package/dist/registry.d.ts +17 -16
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +25 -25
- package/dist/registry.js.map +1 -1
- package/dist/service.d.ts +19 -51
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +119 -404
- package/dist/service.js.map +1 -1
- package/dist/store.d.ts +12 -61
- package/dist/store.d.ts.map +1 -1
- package/dist/testing/index.d.ts +10 -9
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +75 -136
- package/dist/testing/index.js.map +1 -1
- package/dist/theme.js +1 -1
- package/dist/ui.d.ts +18 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +5 -3
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter.ts +180 -0
- package/src/diff.ts +1 -1
- package/src/engine.ts +183 -230
- package/src/envelope.ts +11 -29
- package/src/errors.ts +4 -4
- package/src/events.ts +2 -11
- package/src/i18n.ts +14 -20
- package/src/index.ts +2 -4
- package/src/logger.ts +1 -2
- package/src/memory.ts +16 -122
- package/src/migrations.ts +24 -18
- package/src/projection.ts +25 -7
- package/src/registry.ts +45 -41
- package/src/service.ts +144 -540
- package/src/store.ts +12 -64
- package/src/testing/index.ts +89 -164
- package/src/theme.ts +1 -1
- package/src/ui.ts +24 -4
- package/dist/kind.d.ts +0 -156
- package/dist/kind.d.ts.map +0 -1
- package/dist/kind.js +0 -52
- package/dist/kind.js.map +0 -1
- package/src/kind.ts +0 -217
package/dist/kind.d.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ErrorIssue } from './errors.js';
|
|
3
|
-
import type { Theme } from './theme.js';
|
|
4
|
-
export type ProjectionMode = 'outline' | 'full' | 'range';
|
|
5
|
-
export interface ProjectionOptions {
|
|
6
|
-
mode: ProjectionMode;
|
|
7
|
-
/**
|
|
8
|
-
* Kind-specific range: block ids ("intro..escopo"), A1 range ("Resumo!A1:D20"), slide ids or 1-based
|
|
9
|
-
* indexes ("3-5"), or a group id for diagrams.
|
|
10
|
-
*/
|
|
11
|
-
range?: string;
|
|
12
|
-
/** Token budget; text is cut at an item boundary and a cursor is returned. */
|
|
13
|
-
maxTokens?: number;
|
|
14
|
-
/** Continuation cursor returned by a previous truncated projection. */
|
|
15
|
-
cursor?: string;
|
|
16
|
-
/** Characters per token used for the estimate (default 4). */
|
|
17
|
-
charsPerToken?: number;
|
|
18
|
-
locale: string;
|
|
19
|
-
theme?: Theme;
|
|
20
|
-
}
|
|
21
|
-
export interface Projection {
|
|
22
|
-
text: string;
|
|
23
|
-
truncated: boolean;
|
|
24
|
-
/** Present when truncated: pass it back to continue reading. */
|
|
25
|
-
cursor?: string;
|
|
26
|
-
/** Outline of what was left out, so the model can jump with `range`. */
|
|
27
|
-
remainingOutline?: string;
|
|
28
|
-
}
|
|
29
|
-
export type LintSeverity = 'warning' | 'info';
|
|
30
|
-
export interface LintIssue {
|
|
31
|
-
code: string;
|
|
32
|
-
severity: LintSeverity;
|
|
33
|
-
/** `block:intro`, `cell:Resumo!D14`, `slide:cronograma`, `node:api`… */
|
|
34
|
-
target: string;
|
|
35
|
-
message: string;
|
|
36
|
-
hint?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface LintContext {
|
|
39
|
-
locale: string;
|
|
40
|
-
theme: Theme;
|
|
41
|
-
}
|
|
42
|
-
export type ChangeType = 'added' | 'removed' | 'changed' | 'moved';
|
|
43
|
-
export interface ChangeSummary {
|
|
44
|
-
type: ChangeType;
|
|
45
|
-
/** `block:premissa-api`, `cell:Resumo!D14`, `slide:cronograma`, `envelope:title`… */
|
|
46
|
-
target: string;
|
|
47
|
-
summary: string;
|
|
48
|
-
}
|
|
49
|
-
export interface Migration {
|
|
50
|
-
from: number;
|
|
51
|
-
to: number;
|
|
52
|
-
migrate(content: unknown): unknown;
|
|
53
|
-
}
|
|
54
|
-
/** Limits are plain counters, compared with what `measure` returns under the same keys (spec §6.6). */
|
|
55
|
-
export type KindLimits = Record<string, number>;
|
|
56
|
-
export interface KindExample {
|
|
57
|
-
title: string;
|
|
58
|
-
/**
|
|
59
|
-
* Alternative input that creates the example (e.g. `{ format: 'mermaid', source: 'flowchart LR…' }`).
|
|
60
|
-
* When `content` is also given, it is the content the input must produce.
|
|
61
|
-
*/
|
|
62
|
-
input?: {
|
|
63
|
-
format: string;
|
|
64
|
-
source: unknown;
|
|
65
|
-
};
|
|
66
|
-
content?: unknown;
|
|
67
|
-
operations?: unknown[];
|
|
68
|
-
}
|
|
69
|
-
export interface KindInstructions {
|
|
70
|
-
/** What the kind is and when to use it. */
|
|
71
|
-
summary: string;
|
|
72
|
-
/** Short, verifiable rules. */
|
|
73
|
-
rules: string[];
|
|
74
|
-
examples: KindExample[];
|
|
75
|
-
}
|
|
76
|
-
export interface ContentInput<Content> {
|
|
77
|
-
/** Shown in model instructions. */
|
|
78
|
-
description: string;
|
|
79
|
-
schema: z.ZodType<unknown>;
|
|
80
|
-
/** Deterministic conversion. Throw `ArtifactError('INVALID_CONTENT')` on bad input. */
|
|
81
|
-
toContent(input: unknown, ctx: InputContext): Content;
|
|
82
|
-
}
|
|
83
|
-
export interface InputContext {
|
|
84
|
-
locale: string;
|
|
85
|
-
/**
|
|
86
|
-
* Records a non-blocking conversion note (an ignored directive, a mapped shape). Notes are returned
|
|
87
|
-
* to the caller as `info` lint issues with code `input-note`.
|
|
88
|
-
*/
|
|
89
|
-
note?(message: string): void;
|
|
90
|
-
}
|
|
91
|
-
export interface IdContext {
|
|
92
|
-
/** Deterministic id for a new item, e.g. `nextId('p')` → `p12`. */
|
|
93
|
-
nextId(prefix: string): string;
|
|
94
|
-
/** True when the id already exists in the content (including ids created earlier in the batch). */
|
|
95
|
-
hasId(id: string): boolean;
|
|
96
|
-
/** Registers an explicitly provided id so later operations in the batch see it. */
|
|
97
|
-
reserveId(id: string): void;
|
|
98
|
-
}
|
|
99
|
-
export interface ApplyContext extends IdContext {
|
|
100
|
-
/** Aborts the batch with `OPERATION_FAILED` and a model-facing hint. */
|
|
101
|
-
fail(message: string, options?: {
|
|
102
|
-
hint?: string;
|
|
103
|
-
path?: string;
|
|
104
|
-
}): never;
|
|
105
|
-
locale: string;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Contract every kind implements, native or third-party (spec §7).
|
|
109
|
-
* `apply` mutates a clone and must be pure: no clock, network or randomness.
|
|
110
|
-
*/
|
|
111
|
-
export interface ArtifactKind<Content = unknown, Operation = unknown> {
|
|
112
|
-
kind: string;
|
|
113
|
-
version: number;
|
|
114
|
-
label: string;
|
|
115
|
-
contentSchema: z.ZodType<Content>;
|
|
116
|
-
operationSchema: z.ZodType<Operation>;
|
|
117
|
-
/** Smallest valid content, used for skeleton creation. */
|
|
118
|
-
empty(): Content;
|
|
119
|
-
/**
|
|
120
|
-
* Prepares raw content before validation: fills missing ids deterministically (ids are optional on
|
|
121
|
-
* creation, spec §6.2). Must not throw on malformed input; validation reports problems afterwards.
|
|
122
|
-
*/
|
|
123
|
-
normalize?(raw: unknown, ctx: IdContext): unknown;
|
|
124
|
-
apply(draft: Content, op: Operation, ctx: ApplyContext): void;
|
|
125
|
-
/** Every item id in the content (unique across the whole artifact). */
|
|
126
|
-
ids(content: Content): Iterable<string>;
|
|
127
|
-
/** Integrity rules beyond the schema (references, unique ids, table widths). Empty array means valid. */
|
|
128
|
-
validate?(content: Content, locale?: string): ErrorIssue[];
|
|
129
|
-
/** Counters checked against `limits`. */
|
|
130
|
-
measure?(content: Content): Record<string, number>;
|
|
131
|
-
/** Derived step after operations (e.g. formula recalculation). Mutates the draft; must stay deterministic. */
|
|
132
|
-
derive?(draft: Content): void;
|
|
133
|
-
/** Item targets an operation touches, used for automatic rebase. Defaults to diff-based detection. */
|
|
134
|
-
targets?(op: Operation): string[];
|
|
135
|
-
project(content: Content, options: ProjectionOptions): Projection;
|
|
136
|
-
lint(content: Content, ctx: LintContext): LintIssue[];
|
|
137
|
-
/** `locale` selects the language of the summaries (pt-BR or English). */
|
|
138
|
-
diff(before: Content, after: Content, locale?: string): ChangeSummary[];
|
|
139
|
-
/** Best-effort preview while the model is still streaming; drops incomplete trailing items. */
|
|
140
|
-
parsePartial(raw: unknown): Content | undefined;
|
|
141
|
-
inputs?: Record<string, ContentInput<Content>>;
|
|
142
|
-
migrations: Migration[];
|
|
143
|
-
limits: KindLimits;
|
|
144
|
-
instructions: KindInstructions;
|
|
145
|
-
}
|
|
146
|
-
export type AnyArtifactKind = ArtifactKind<any, any>;
|
|
147
|
-
export declare class KindDefinitionError extends Error {
|
|
148
|
-
constructor(kind: string, problem: string);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Validates a kind definition and returns it unchanged. Use it for third-party kinds (spec §20);
|
|
152
|
-
* the registry runs the same checks on `register`.
|
|
153
|
-
*/
|
|
154
|
-
export declare function defineKind<Content, Operation>(kind: ArtifactKind<Content, Operation>): ArtifactKind<Content, Operation>;
|
|
155
|
-
export declare function assertKindContract(kind: AnyArtifactKind): void;
|
|
156
|
-
//# sourceMappingURL=kind.d.ts.map
|
package/dist/kind.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kind.d.ts","sourceRoot":"","sources":["../src/kind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EA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S,EAAE,CAAC;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAGD,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAErD,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAGxC;CACF;AAID;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAC3C,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,GACrC,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,CAGlC;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAgC9D"}
|
package/dist/kind.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export class KindDefinitionError extends Error {
|
|
3
|
-
constructor(kind, problem) {
|
|
4
|
-
super(`Invalid kind "${kind}": ${problem}`);
|
|
5
|
-
this.name = 'KindDefinitionError';
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
const KIND_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
9
|
-
/**
|
|
10
|
-
* Validates a kind definition and returns it unchanged. Use it for third-party kinds (spec §20);
|
|
11
|
-
* the registry runs the same checks on `register`.
|
|
12
|
-
*/
|
|
13
|
-
export function defineKind(kind) {
|
|
14
|
-
assertKindContract(kind);
|
|
15
|
-
return kind;
|
|
16
|
-
}
|
|
17
|
-
export function assertKindContract(kind) {
|
|
18
|
-
const name = typeof kind?.kind === 'string' ? kind.kind : '<unnamed>';
|
|
19
|
-
if (!KIND_NAME.test(name))
|
|
20
|
-
throw new KindDefinitionError(name, 'kind must match /^[a-z][a-z0-9-]{0,63}$/');
|
|
21
|
-
if (!Number.isInteger(kind.version) || kind.version < 1)
|
|
22
|
-
throw new KindDefinitionError(name, 'version must be an integer >= 1');
|
|
23
|
-
if (!(kind.contentSchema instanceof z.ZodType))
|
|
24
|
-
throw new KindDefinitionError(name, 'contentSchema must be a zod schema');
|
|
25
|
-
if (!(kind.operationSchema instanceof z.ZodType))
|
|
26
|
-
throw new KindDefinitionError(name, 'operationSchema must be a zod schema');
|
|
27
|
-
for (const fn of ['empty', 'apply', 'ids', 'project', 'lint', 'diff', 'parsePartial']) {
|
|
28
|
-
if (typeof kind[fn] !== 'function')
|
|
29
|
-
throw new KindDefinitionError(name, `${fn} must be a function`);
|
|
30
|
-
}
|
|
31
|
-
if (!Array.isArray(kind.migrations))
|
|
32
|
-
throw new KindDefinitionError(name, 'migrations must be an array');
|
|
33
|
-
let expected = 1;
|
|
34
|
-
for (const migration of [...kind.migrations].sort((a, b) => a.from - b.from)) {
|
|
35
|
-
if (migration.from !== expected || migration.to !== migration.from + 1) {
|
|
36
|
-
throw new KindDefinitionError(name, `migrations must form a chain 1→2→…→${kind.version}`);
|
|
37
|
-
}
|
|
38
|
-
expected = migration.to;
|
|
39
|
-
}
|
|
40
|
-
if (kind.migrations.length > 0 && expected !== kind.version) {
|
|
41
|
-
throw new KindDefinitionError(name, `migrations end at ${expected} but version is ${kind.version}`);
|
|
42
|
-
}
|
|
43
|
-
if (!kind.instructions ||
|
|
44
|
-
typeof kind.instructions.summary !== 'string' ||
|
|
45
|
-
!Array.isArray(kind.instructions.rules)) {
|
|
46
|
-
throw new KindDefinitionError(name, 'instructions need summary, rules and examples');
|
|
47
|
-
}
|
|
48
|
-
const empty = kind.contentSchema.safeParse(kind.empty());
|
|
49
|
-
if (!empty.success)
|
|
50
|
-
throw new KindDefinitionError(name, 'empty() does not satisfy contentSchema');
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=kind.js.map
|
package/dist/kind.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kind.js","sourceRoot":"","sources":["../src/kind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE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,CAAC,CAAC;IACvF,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,MAAM,IAAI,mBAAmB,CAAC,IAAI,EAAE,wCAAwC,CAAC,CAAC;AACpG,CAAC"}
|
package/src/kind.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import type { ErrorIssue } from './errors.js';
|
|
3
|
-
import type { Theme } from './theme.js';
|
|
4
|
-
|
|
5
|
-
export type ProjectionMode = 'outline' | 'full' | 'range';
|
|
6
|
-
|
|
7
|
-
export interface ProjectionOptions {
|
|
8
|
-
mode: ProjectionMode;
|
|
9
|
-
/**
|
|
10
|
-
* Kind-specific range: block ids ("intro..escopo"), A1 range ("Resumo!A1:D20"), slide ids or 1-based
|
|
11
|
-
* indexes ("3-5"), or a group id for diagrams.
|
|
12
|
-
*/
|
|
13
|
-
range?: string;
|
|
14
|
-
/** Token budget; text is cut at an item boundary and a cursor is returned. */
|
|
15
|
-
maxTokens?: number;
|
|
16
|
-
/** Continuation cursor returned by a previous truncated projection. */
|
|
17
|
-
cursor?: string;
|
|
18
|
-
/** Characters per token used for the estimate (default 4). */
|
|
19
|
-
charsPerToken?: number;
|
|
20
|
-
locale: string;
|
|
21
|
-
theme?: Theme;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface Projection {
|
|
25
|
-
text: string;
|
|
26
|
-
truncated: boolean;
|
|
27
|
-
/** Present when truncated: pass it back to continue reading. */
|
|
28
|
-
cursor?: string;
|
|
29
|
-
/** Outline of what was left out, so the model can jump with `range`. */
|
|
30
|
-
remainingOutline?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type LintSeverity = 'warning' | 'info';
|
|
34
|
-
|
|
35
|
-
export interface LintIssue {
|
|
36
|
-
code: string;
|
|
37
|
-
severity: LintSeverity;
|
|
38
|
-
/** `block:intro`, `cell:Resumo!D14`, `slide:cronograma`, `node:api`… */
|
|
39
|
-
target: string;
|
|
40
|
-
message: string;
|
|
41
|
-
hint?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface LintContext {
|
|
45
|
-
locale: string;
|
|
46
|
-
theme: Theme;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type ChangeType = 'added' | 'removed' | 'changed' | 'moved';
|
|
50
|
-
|
|
51
|
-
export interface ChangeSummary {
|
|
52
|
-
type: ChangeType;
|
|
53
|
-
/** `block:premissa-api`, `cell:Resumo!D14`, `slide:cronograma`, `envelope:title`… */
|
|
54
|
-
target: string;
|
|
55
|
-
summary: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface Migration {
|
|
59
|
-
from: number;
|
|
60
|
-
to: number;
|
|
61
|
-
migrate(content: unknown): unknown;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Limits are plain counters, compared with what `measure` returns under the same keys (spec §6.6). */
|
|
65
|
-
export type KindLimits = Record<string, number>;
|
|
66
|
-
|
|
67
|
-
export interface KindExample {
|
|
68
|
-
title: string;
|
|
69
|
-
/**
|
|
70
|
-
* Alternative input that creates the example (e.g. `{ format: 'mermaid', source: 'flowchart LR…' }`).
|
|
71
|
-
* When `content` is also given, it is the content the input must produce.
|
|
72
|
-
*/
|
|
73
|
-
input?: { format: string; source: unknown };
|
|
74
|
-
content?: unknown;
|
|
75
|
-
operations?: unknown[];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface KindInstructions {
|
|
79
|
-
/** What the kind is and when to use it. */
|
|
80
|
-
summary: string;
|
|
81
|
-
/** Short, verifiable rules. */
|
|
82
|
-
rules: string[];
|
|
83
|
-
examples: KindExample[];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface ContentInput<Content> {
|
|
87
|
-
/** Shown in model instructions. */
|
|
88
|
-
description: string;
|
|
89
|
-
schema: z.ZodType<unknown>;
|
|
90
|
-
/** Deterministic conversion. Throw `ArtifactError('INVALID_CONTENT')` on bad input. */
|
|
91
|
-
toContent(input: unknown, ctx: InputContext): Content;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface InputContext {
|
|
95
|
-
locale: string;
|
|
96
|
-
/**
|
|
97
|
-
* Records a non-blocking conversion note (an ignored directive, a mapped shape). Notes are returned
|
|
98
|
-
* to the caller as `info` lint issues with code `input-note`.
|
|
99
|
-
*/
|
|
100
|
-
note?(message: string): void;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface IdContext {
|
|
104
|
-
/** Deterministic id for a new item, e.g. `nextId('p')` → `p12`. */
|
|
105
|
-
nextId(prefix: string): string;
|
|
106
|
-
/** True when the id already exists in the content (including ids created earlier in the batch). */
|
|
107
|
-
hasId(id: string): boolean;
|
|
108
|
-
/** Registers an explicitly provided id so later operations in the batch see it. */
|
|
109
|
-
reserveId(id: string): void;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface ApplyContext extends IdContext {
|
|
113
|
-
/** Aborts the batch with `OPERATION_FAILED` and a model-facing hint. */
|
|
114
|
-
fail(message: string, options?: { hint?: string; path?: string }): never;
|
|
115
|
-
locale: string;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Contract every kind implements, native or third-party (spec §7).
|
|
120
|
-
* `apply` mutates a clone and must be pure: no clock, network or randomness.
|
|
121
|
-
*/
|
|
122
|
-
export interface ArtifactKind<Content = unknown, Operation = unknown> {
|
|
123
|
-
kind: string;
|
|
124
|
-
version: number;
|
|
125
|
-
label: string;
|
|
126
|
-
|
|
127
|
-
contentSchema: z.ZodType<Content>;
|
|
128
|
-
operationSchema: z.ZodType<Operation>;
|
|
129
|
-
|
|
130
|
-
/** Smallest valid content, used for skeleton creation. */
|
|
131
|
-
empty(): Content;
|
|
132
|
-
/**
|
|
133
|
-
* Prepares raw content before validation: fills missing ids deterministically (ids are optional on
|
|
134
|
-
* creation, spec §6.2). Must not throw on malformed input; validation reports problems afterwards.
|
|
135
|
-
*/
|
|
136
|
-
normalize?(raw: unknown, ctx: IdContext): unknown;
|
|
137
|
-
apply(draft: Content, op: Operation, ctx: ApplyContext): void;
|
|
138
|
-
/** Every item id in the content (unique across the whole artifact). */
|
|
139
|
-
ids(content: Content): Iterable<string>;
|
|
140
|
-
/** Integrity rules beyond the schema (references, unique ids, table widths). Empty array means valid. */
|
|
141
|
-
validate?(content: Content, locale?: string): ErrorIssue[];
|
|
142
|
-
/** Counters checked against `limits`. */
|
|
143
|
-
measure?(content: Content): Record<string, number>;
|
|
144
|
-
/** Derived step after operations (e.g. formula recalculation). Mutates the draft; must stay deterministic. */
|
|
145
|
-
derive?(draft: Content): void;
|
|
146
|
-
/** Item targets an operation touches, used for automatic rebase. Defaults to diff-based detection. */
|
|
147
|
-
targets?(op: Operation): string[];
|
|
148
|
-
|
|
149
|
-
project(content: Content, options: ProjectionOptions): Projection;
|
|
150
|
-
lint(content: Content, ctx: LintContext): LintIssue[];
|
|
151
|
-
/** `locale` selects the language of the summaries (pt-BR or English). */
|
|
152
|
-
diff(before: Content, after: Content, locale?: string): ChangeSummary[];
|
|
153
|
-
/** Best-effort preview while the model is still streaming; drops incomplete trailing items. */
|
|
154
|
-
parsePartial(raw: unknown): Content | undefined;
|
|
155
|
-
|
|
156
|
-
inputs?: Record<string, ContentInput<Content>>;
|
|
157
|
-
migrations: Migration[];
|
|
158
|
-
limits: KindLimits;
|
|
159
|
-
instructions: KindInstructions;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// biome-ignore lint/suspicious/noExplicitAny: registry stores heterogeneous kinds.
|
|
163
|
-
export type AnyArtifactKind = ArtifactKind<any, any>;
|
|
164
|
-
|
|
165
|
-
export class KindDefinitionError extends Error {
|
|
166
|
-
constructor(kind: string, problem: string) {
|
|
167
|
-
super(`Invalid kind "${kind}": ${problem}`);
|
|
168
|
-
this.name = 'KindDefinitionError';
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const KIND_NAME = /^[a-z][a-z0-9-]{0,63}$/;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Validates a kind definition and returns it unchanged. Use it for third-party kinds (spec §20);
|
|
176
|
-
* the registry runs the same checks on `register`.
|
|
177
|
-
*/
|
|
178
|
-
export function defineKind<Content, Operation>(
|
|
179
|
-
kind: ArtifactKind<Content, Operation>,
|
|
180
|
-
): ArtifactKind<Content, Operation> {
|
|
181
|
-
assertKindContract(kind);
|
|
182
|
-
return kind;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function assertKindContract(kind: AnyArtifactKind): void {
|
|
186
|
-
const name = typeof kind?.kind === 'string' ? kind.kind : '<unnamed>';
|
|
187
|
-
if (!KIND_NAME.test(name)) throw new KindDefinitionError(name, 'kind must match /^[a-z][a-z0-9-]{0,63}$/');
|
|
188
|
-
if (!Number.isInteger(kind.version) || kind.version < 1)
|
|
189
|
-
throw new KindDefinitionError(name, 'version must be an integer >= 1');
|
|
190
|
-
if (!(kind.contentSchema instanceof z.ZodType))
|
|
191
|
-
throw new KindDefinitionError(name, 'contentSchema must be a zod schema');
|
|
192
|
-
if (!(kind.operationSchema instanceof z.ZodType))
|
|
193
|
-
throw new KindDefinitionError(name, 'operationSchema must be a zod schema');
|
|
194
|
-
for (const fn of ['empty', 'apply', 'ids', 'project', 'lint', 'diff', 'parsePartial'] as const) {
|
|
195
|
-
if (typeof kind[fn] !== 'function') throw new KindDefinitionError(name, `${fn} must be a function`);
|
|
196
|
-
}
|
|
197
|
-
if (!Array.isArray(kind.migrations)) throw new KindDefinitionError(name, 'migrations must be an array');
|
|
198
|
-
let expected = 1;
|
|
199
|
-
for (const migration of [...kind.migrations].sort((a, b) => a.from - b.from)) {
|
|
200
|
-
if (migration.from !== expected || migration.to !== migration.from + 1) {
|
|
201
|
-
throw new KindDefinitionError(name, `migrations must form a chain 1→2→…→${kind.version}`);
|
|
202
|
-
}
|
|
203
|
-
expected = migration.to;
|
|
204
|
-
}
|
|
205
|
-
if (kind.migrations.length > 0 && expected !== kind.version) {
|
|
206
|
-
throw new KindDefinitionError(name, `migrations end at ${expected} but version is ${kind.version}`);
|
|
207
|
-
}
|
|
208
|
-
if (
|
|
209
|
-
!kind.instructions ||
|
|
210
|
-
typeof kind.instructions.summary !== 'string' ||
|
|
211
|
-
!Array.isArray(kind.instructions.rules)
|
|
212
|
-
) {
|
|
213
|
-
throw new KindDefinitionError(name, 'instructions need summary, rules and examples');
|
|
214
|
-
}
|
|
215
|
-
const empty = kind.contentSchema.safeParse(kind.empty());
|
|
216
|
-
if (!empty.success) throw new KindDefinitionError(name, 'empty() does not satisfy contentSchema');
|
|
217
|
-
}
|