@serene-pub/conformance 0.6.0-pr-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/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +187 -0
- package/dist/components.d.ts +93 -0
- package/dist/components.js +270 -0
- package/dist/index.d.ts +405 -0
- package/dist/index.js +1387 -0
- package/dist/packages.d.ts +176 -0
- package/dist/packages.js +157 -0
- package/package.json +48 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A package's own evidence (C31–C33): what a plugin's BUILT artifact — its
|
|
3
|
+
* `manifest.json` and handler bundle — hands the kit, read the way an
|
|
4
|
+
* instance reads it at install, never by evaluating the package's source.
|
|
5
|
+
*
|
|
6
|
+
* The kit stays a host kit: these helpers only build the seams a host
|
|
7
|
+
* supplies (`HostUnderTest.shipped`, `swaps`, `nodeHandler`, `components`),
|
|
8
|
+
* so a package's test runs the same cases core runs, over its artifact.
|
|
9
|
+
*/
|
|
10
|
+
import type { Descriptor, GenreDecl, PresetDecl } from '@serene-pub/sdk';
|
|
11
|
+
/** @experimental One swap a package offers (R28/R29), with the declaration of what it seats. */
|
|
12
|
+
export interface SwapEvidence {
|
|
13
|
+
/** The spec the swap targets (`core:spec/chat-turn-order`). */
|
|
14
|
+
spec: string;
|
|
15
|
+
/** The node key on that spec it stands in for. */
|
|
16
|
+
node: string;
|
|
17
|
+
/** The contributed definition's id. */
|
|
18
|
+
definitionId: string;
|
|
19
|
+
/**
|
|
20
|
+
* Its declaration — the descriptor the package's builder judged, as the
|
|
21
|
+
* manifest carries it (`nodeDefinitions[].declaration`). Undefined when the
|
|
22
|
+
* package offers a definition it does not declare, which C32 refuses.
|
|
23
|
+
*/
|
|
24
|
+
definition: Descriptor | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A manifest's node-definition entry. `ports` and `slots` are the audit
|
|
28
|
+
* summary (names only); `declaration` is the descriptor verbatim (D-6b), which
|
|
29
|
+
* is what a fit check reads.
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
export interface ManifestNodeDefinition {
|
|
33
|
+
id: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
ports?: {
|
|
36
|
+
in: string[];
|
|
37
|
+
out: string[];
|
|
38
|
+
};
|
|
39
|
+
declaration?: Partial<Descriptor> & Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
/** @experimental The parts of a compiled `manifest.json` the kit reads. Structural: any compiler version's manifest fits. */
|
|
42
|
+
export interface PackageManifestLike {
|
|
43
|
+
slug: string;
|
|
44
|
+
genres?: GenreDecl[];
|
|
45
|
+
presets?: PresetDecl[];
|
|
46
|
+
swaps?: Array<{
|
|
47
|
+
spec: string;
|
|
48
|
+
node: string;
|
|
49
|
+
definition: string;
|
|
50
|
+
}>;
|
|
51
|
+
nodeDefinitions?: ManifestNodeDefinition[];
|
|
52
|
+
components?: Array<{
|
|
53
|
+
slug: string;
|
|
54
|
+
entry: string;
|
|
55
|
+
basedOn?: {
|
|
56
|
+
component: string;
|
|
57
|
+
};
|
|
58
|
+
}>;
|
|
59
|
+
/** The widgets it offers: which component each renders, the scopes it asks for, the base sections it reads. */
|
|
60
|
+
widgets?: Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
component?: string;
|
|
63
|
+
scopes?: readonly string[];
|
|
64
|
+
reads?: readonly string[];
|
|
65
|
+
}>;
|
|
66
|
+
hooks?: {
|
|
67
|
+
nodeHandlers?: Record<string, string>;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** @experimental A built module as `HostUnderTest.components()` lists it (C30, C31) — structurally `BuiltComponent`. */
|
|
71
|
+
export interface ManifestComponent {
|
|
72
|
+
id: string;
|
|
73
|
+
code: string;
|
|
74
|
+
grants?: string[];
|
|
75
|
+
reads?: string[];
|
|
76
|
+
/** The core component it is a clone of (`components[].basedOn.component`) — C30's parity half reads it. */
|
|
77
|
+
basedOn?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The BUILT modules a manifest lists, each with what its widgets declare —
|
|
81
|
+
* `HostUnderTest.components` for a package, so C31 mounts every module the
|
|
82
|
+
* way the page mounts it on a layout: granted the section scopes its widgets
|
|
83
|
+
* ask for (`scopes`; a `channel:` scope is not a section grant) and handed
|
|
84
|
+
* only the base sections they read (`reads`, R75).
|
|
85
|
+
*
|
|
86
|
+
* A component more than one widget renders gets the union — the most any
|
|
87
|
+
* placement hands it. When any of those widgets leaves `reads` out, it reads
|
|
88
|
+
* every base section and `reads` is left out here too; a component no widget
|
|
89
|
+
* renders gets neither (every base section, no grants). `code` reads a
|
|
90
|
+
* module's `entry` (a path relative to the package root, as the manifest
|
|
91
|
+
* carries it).
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
94
|
+
export declare function componentsFromManifest(manifest: PackageManifestLike, code: (entry: string) => string | Promise<string>): Promise<ManifestComponent[]>;
|
|
95
|
+
/**
|
|
96
|
+
* A manifest's node definition, back as the descriptor its builder judged.
|
|
97
|
+
*
|
|
98
|
+
* The compiled manifest already carries every definition's declaration
|
|
99
|
+
* verbatim (`nodeDefinitions[].declaration`, D-6b) — port names AND shapes,
|
|
100
|
+
* slot declarations. The top-level `ports`/`slots` stay the names-only audit
|
|
101
|
+
* summary an admin's screen and the install check read; turning them into
|
|
102
|
+
* shapes would change a field every existing manifest reader keys on. So
|
|
103
|
+
* this reads the declaration, and refuses — in a sentence — an entry that
|
|
104
|
+
* has none (a manifest packaged before D-6b: re-package it) or one whose
|
|
105
|
+
* declaration names another definition.
|
|
106
|
+
* @experimental
|
|
107
|
+
*/
|
|
108
|
+
export declare function definitionFromManifest(entry: ManifestNodeDefinition): Descriptor;
|
|
109
|
+
/**
|
|
110
|
+
* The swaps a manifest offers, each with the declaration of the definition it
|
|
111
|
+
* seats — `HostUnderTest.swaps` for a package. A swap naming a definition the
|
|
112
|
+
* manifest does not declare carries `definition: undefined` (C32 says so).
|
|
113
|
+
* @experimental
|
|
114
|
+
*/
|
|
115
|
+
export declare function swapsFromManifest(manifest: PackageManifestLike): SwapEvidence[];
|
|
116
|
+
/**
|
|
117
|
+
* The definition a spec seats at `node`, resolved in this SDK's registry — a
|
|
118
|
+
* host's `pinnedDefinition` over its own compiled spec (for core's, the
|
|
119
|
+
* document `coreSpec(id).build()` returns). Undefined when the spec has no
|
|
120
|
+
* such node or the registry does not know what it seats.
|
|
121
|
+
* @experimental
|
|
122
|
+
*/
|
|
123
|
+
export declare function pinnedDefinitionIn(doc: {
|
|
124
|
+
nodes: ReadonlyArray<{
|
|
125
|
+
key: string;
|
|
126
|
+
definitionId: string;
|
|
127
|
+
definitionVersion: number;
|
|
128
|
+
}>;
|
|
129
|
+
} | undefined, node: string, lookup?: (id: string) => Descriptor | undefined): Descriptor | undefined;
|
|
130
|
+
/** @experimental A node handler as the executor calls it. */
|
|
131
|
+
export type NodeHandler = (input: unknown, ctx: unknown) => unknown;
|
|
132
|
+
/**
|
|
133
|
+
* The hooks a built handler bundle exports (`module.exports.hooks`), by
|
|
134
|
+
* export name. The bundle is the sandbox's self-contained CommonJS module and
|
|
135
|
+
* is evaluated here with a `require` that refuses every id, as the sandbox
|
|
136
|
+
* gives it none — this is NOT the host's isolation (SES/QuickJS are the
|
|
137
|
+
* app's), only the evaluation a test needs to call the handlers.
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
140
|
+
export declare function hooksFromBundle(code: string): Record<string, NodeHandler>;
|
|
141
|
+
/**
|
|
142
|
+
* The seams a package's BUILT artifact supplies, from its manifest (and
|
|
143
|
+
* handler bundle): what it ships (C28, C29), the swaps it offers (C32) and
|
|
144
|
+
* the handler each definition runs (C33). Spread into a `HostUnderTest`
|
|
145
|
+
* beside the seams only the test can give — `pinnedDefinition` (the host's
|
|
146
|
+
* own specs), `components`/`mountComponent` (its harness).
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
149
|
+
export declare function manifestSeams(manifest: PackageManifestLike, bundle?: string): {
|
|
150
|
+
shipped: () => {
|
|
151
|
+
genres: GenreDecl[];
|
|
152
|
+
presets: PresetDecl[];
|
|
153
|
+
};
|
|
154
|
+
swaps: () => SwapEvidence[];
|
|
155
|
+
nodeHandler: (definitionId: string) => NodeHandler | undefined;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* A sample value per shape, for the binding probes' input (C33): a
|
|
159
|
+
* definition whose every in-port has a sample here is probed with it; the
|
|
160
|
+
* host's `probeInput(d)` answers any other. Turn order's two (a strategy
|
|
161
|
+
* reads candidates and the history) are here because every strategy swap
|
|
162
|
+
* reads them.
|
|
163
|
+
* @experimental
|
|
164
|
+
*/
|
|
165
|
+
export declare const PROBE_SAMPLES: Readonly<Record<string, unknown>>;
|
|
166
|
+
/**
|
|
167
|
+
* The probe input for `d` from `PROBE_SAMPLES`, one value per in-port, or
|
|
168
|
+
* the shapes it has no sample for.
|
|
169
|
+
* @experimental
|
|
170
|
+
*/
|
|
171
|
+
export declare function probeSampleFor(d: Pick<Descriptor, 'ports'>): {
|
|
172
|
+
input: Record<string, unknown>;
|
|
173
|
+
} | {
|
|
174
|
+
missing: string[];
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=packages.d.ts.map
|
package/dist/packages.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getDefinition } from '@serene-pub/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* The BUILT modules a manifest lists, each with what its widgets declare —
|
|
4
|
+
* `HostUnderTest.components` for a package, so C31 mounts every module the
|
|
5
|
+
* way the page mounts it on a layout: granted the section scopes its widgets
|
|
6
|
+
* ask for (`scopes`; a `channel:` scope is not a section grant) and handed
|
|
7
|
+
* only the base sections they read (`reads`, R75).
|
|
8
|
+
*
|
|
9
|
+
* A component more than one widget renders gets the union — the most any
|
|
10
|
+
* placement hands it. When any of those widgets leaves `reads` out, it reads
|
|
11
|
+
* every base section and `reads` is left out here too; a component no widget
|
|
12
|
+
* renders gets neither (every base section, no grants). `code` reads a
|
|
13
|
+
* module's `entry` (a path relative to the package root, as the manifest
|
|
14
|
+
* carries it).
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export async function componentsFromManifest(manifest, code) {
|
|
18
|
+
return Promise.all((manifest.components ?? []).map(async (c) => {
|
|
19
|
+
const widgets = (manifest.widgets ?? []).filter((w) => w.component === c.slug);
|
|
20
|
+
const grants = [...new Set(widgets.flatMap((w) => (w.scopes ?? []).filter((s) => !s.startsWith('channel:'))))];
|
|
21
|
+
const everySection = !widgets.length || widgets.some((w) => !Array.isArray(w.reads));
|
|
22
|
+
const reads = everySection ? undefined : [...new Set(widgets.flatMap((w) => w.reads ?? []))];
|
|
23
|
+
return {
|
|
24
|
+
id: c.slug,
|
|
25
|
+
code: await code(c.entry),
|
|
26
|
+
...(grants.length ? { grants } : {}),
|
|
27
|
+
...(reads ? { reads } : {}),
|
|
28
|
+
...(c.basedOn?.component ? { basedOn: c.basedOn.component } : {}),
|
|
29
|
+
};
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A manifest's node definition, back as the descriptor its builder judged.
|
|
34
|
+
*
|
|
35
|
+
* The compiled manifest already carries every definition's declaration
|
|
36
|
+
* verbatim (`nodeDefinitions[].declaration`, D-6b) — port names AND shapes,
|
|
37
|
+
* slot declarations. The top-level `ports`/`slots` stay the names-only audit
|
|
38
|
+
* summary an admin's screen and the install check read; turning them into
|
|
39
|
+
* shapes would change a field every existing manifest reader keys on. So
|
|
40
|
+
* this reads the declaration, and refuses — in a sentence — an entry that
|
|
41
|
+
* has none (a manifest packaged before D-6b: re-package it) or one whose
|
|
42
|
+
* declaration names another definition.
|
|
43
|
+
* @experimental
|
|
44
|
+
*/
|
|
45
|
+
export function definitionFromManifest(entry) {
|
|
46
|
+
const d = entry.declaration;
|
|
47
|
+
if (!d || typeof d !== 'object' || !d.ports)
|
|
48
|
+
throw new Error(`the manifest's node definition '${entry.id}' carries no declaration — its ports are names only, which no ` +
|
|
49
|
+
`fit check can read. Re-package with a current @serene-pub/cli (it records the declaration verbatim, D-6b)`);
|
|
50
|
+
if ((d.id !== undefined && d.id !== entry.id) || (d.kind !== undefined && d.kind !== entry.kind))
|
|
51
|
+
throw new Error(`the manifest's node definition '${entry.id}' (${entry.kind}) carries the declaration of '${String(d.id)}' ` +
|
|
52
|
+
`(${String(d.kind)}) — the manifest was edited by hand or packaged wrong`);
|
|
53
|
+
return { ...d, id: entry.id, kind: entry.kind, slots: d.slots ?? {} };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The swaps a manifest offers, each with the declaration of the definition it
|
|
57
|
+
* seats — `HostUnderTest.swaps` for a package. A swap naming a definition the
|
|
58
|
+
* manifest does not declare carries `definition: undefined` (C32 says so).
|
|
59
|
+
* @experimental
|
|
60
|
+
*/
|
|
61
|
+
export function swapsFromManifest(manifest) {
|
|
62
|
+
return (manifest.swaps ?? []).map((s) => {
|
|
63
|
+
const entry = manifest.nodeDefinitions?.find((n) => n.id === s.definition);
|
|
64
|
+
return {
|
|
65
|
+
spec: s.spec,
|
|
66
|
+
node: s.node,
|
|
67
|
+
definitionId: s.definition,
|
|
68
|
+
definition: entry ? definitionFromManifest(entry) : undefined,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The definition a spec seats at `node`, resolved in this SDK's registry — a
|
|
74
|
+
* host's `pinnedDefinition` over its own compiled spec (for core's, the
|
|
75
|
+
* document `coreSpec(id).build()` returns). Undefined when the spec has no
|
|
76
|
+
* such node or the registry does not know what it seats.
|
|
77
|
+
* @experimental
|
|
78
|
+
*/
|
|
79
|
+
export function pinnedDefinitionIn(doc, node, lookup = getDefinition) {
|
|
80
|
+
const n = doc?.nodes.find((x) => x.key === node);
|
|
81
|
+
return n ? lookup(`${n.definitionId}@${n.definitionVersion}`) : undefined;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The hooks a built handler bundle exports (`module.exports.hooks`), by
|
|
85
|
+
* export name. The bundle is the sandbox's self-contained CommonJS module and
|
|
86
|
+
* is evaluated here with a `require` that refuses every id, as the sandbox
|
|
87
|
+
* gives it none — this is NOT the host's isolation (SES/QuickJS are the
|
|
88
|
+
* app's), only the evaluation a test needs to call the handlers.
|
|
89
|
+
* @experimental
|
|
90
|
+
*/
|
|
91
|
+
export function hooksFromBundle(code) {
|
|
92
|
+
const module = { exports: {} };
|
|
93
|
+
new Function('module', 'exports', 'require', code)(module, module.exports, (id) => {
|
|
94
|
+
throw new Error(`the handler bundle asked for '${id}' — a bundle must be self-contained`);
|
|
95
|
+
});
|
|
96
|
+
return module.exports.hooks ?? {};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The seams a package's BUILT artifact supplies, from its manifest (and
|
|
100
|
+
* handler bundle): what it ships (C28, C29), the swaps it offers (C32) and
|
|
101
|
+
* the handler each definition runs (C33). Spread into a `HostUnderTest`
|
|
102
|
+
* beside the seams only the test can give — `pinnedDefinition` (the host's
|
|
103
|
+
* own specs), `components`/`mountComponent` (its harness).
|
|
104
|
+
* @experimental
|
|
105
|
+
*/
|
|
106
|
+
export function manifestSeams(manifest, bundle) {
|
|
107
|
+
let hooks;
|
|
108
|
+
return {
|
|
109
|
+
shipped: () => ({ genres: manifest.genres ?? [], presets: manifest.presets ?? [] }),
|
|
110
|
+
swaps: () => swapsFromManifest(manifest),
|
|
111
|
+
nodeHandler: (id) => {
|
|
112
|
+
if (bundle === undefined)
|
|
113
|
+
return undefined;
|
|
114
|
+
hooks ??= hooksFromBundle(bundle);
|
|
115
|
+
const name = manifest.hooks?.nodeHandlers?.[id];
|
|
116
|
+
return name ? hooks[name] : undefined;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A sample value per shape, for the binding probes' input (C33): a
|
|
122
|
+
* definition whose every in-port has a sample here is probed with it; the
|
|
123
|
+
* host's `probeInput(d)` answers any other. Turn order's two (a strategy
|
|
124
|
+
* reads candidates and the history) are here because every strategy swap
|
|
125
|
+
* reads them.
|
|
126
|
+
* @experimental
|
|
127
|
+
*/
|
|
128
|
+
export const PROBE_SAMPLES = {
|
|
129
|
+
'core:shape/turn-candidates@1': [
|
|
130
|
+
{ ref: 'character:3', kind: 'character', name: 'Bell', position: 0 },
|
|
131
|
+
{ ref: 'character:9', kind: 'persona', name: 'Pip', position: 1 },
|
|
132
|
+
],
|
|
133
|
+
'core:shape/messages@1': [
|
|
134
|
+
{ id: 1, role: 'user', personaId: 9, characterId: null, content: 'Hello there' },
|
|
135
|
+
{ id: 2, role: 'assistant', characterId: 3, personaId: null, content: 'Hi!\n\nYour go, Pip.' },
|
|
136
|
+
],
|
|
137
|
+
'core:shape/text@1': 'Hello there',
|
|
138
|
+
'core:shape/json@1': {},
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The probe input for `d` from `PROBE_SAMPLES`, one value per in-port, or
|
|
142
|
+
* the shapes it has no sample for.
|
|
143
|
+
* @experimental
|
|
144
|
+
*/
|
|
145
|
+
export function probeSampleFor(d) {
|
|
146
|
+
const input = {};
|
|
147
|
+
const missing = [];
|
|
148
|
+
for (const [port, shape] of Object.entries(d.ports?.in ?? {})) {
|
|
149
|
+
const id = typeof shape === 'string' ? shape : String(shape?.id ?? shape);
|
|
150
|
+
if (Object.hasOwn(PROBE_SAMPLES, id))
|
|
151
|
+
input[port] = structuredClone(PROBE_SAMPLES[id]);
|
|
152
|
+
else
|
|
153
|
+
missing.push(`${port}: ${id}`);
|
|
154
|
+
}
|
|
155
|
+
return missing.length ? { missing } : { input };
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=packages.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@serene-pub/conformance",
|
|
3
|
+
"version": "0.6.0-pr-1",
|
|
4
|
+
"description": "The host conformance kit: thirty-three executable requirements a Serene Pub executor must satisfy. Run by Serene Pub and by any alternate host; its package cases (C28–C33) by plugin authors over a built package.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/SerenePub/serene-pub-sdk/tree/main/conformance#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/SerenePub/serene-pub-sdk/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/SerenePub/serene-pub-sdk.git",
|
|
13
|
+
"directory": "conformance"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=24"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"!dist/**/*.map",
|
|
23
|
+
"README.md",
|
|
24
|
+
"NOTICE"
|
|
25
|
+
],
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@serene-pub/sdk": "^0.6.0-pr-1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.build.json"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@serene-pub/sdk": "0.6.0-pr-1"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"tag": "next"
|
|
47
|
+
}
|
|
48
|
+
}
|