@openfairygui/backend 0.6.3 → 0.7.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.
Files changed (48) hide show
  1. package/dist/contracts-Bx8HUr7I.d.cts +756 -0
  2. package/dist/contracts-CMQiPEyz.d.mts +756 -0
  3. package/dist/diagnostics-CIe7S-RW.cjs +670 -0
  4. package/dist/diagnostics-CZ12H1Mx.d.cts +1679 -0
  5. package/dist/diagnostics-CpJ8cAP6.d.mts +1679 -0
  6. package/dist/diagnostics-DTnLXQGs.mjs +641 -0
  7. package/dist/docs.cjs +11530 -5940
  8. package/dist/docs.d.cts +5 -185
  9. package/dist/docs.d.mts +5 -185
  10. package/dist/docs.mjs +11528 -5939
  11. package/dist/index.cjs +16 -2703
  12. package/dist/index.d.cts +5 -2362
  13. package/dist/index.d.mts +5 -2362
  14. package/dist/index.mjs +4 -2691
  15. package/dist/node.cjs +367 -2779
  16. package/dist/node.d.cts +4 -724
  17. package/dist/node.d.mts +4 -724
  18. package/dist/node.mjs +359 -2751
  19. package/dist/rolldown-runtime-BJqNVkSG.cjs +28 -0
  20. package/dist/runtime-DYqG77ak.cjs +2249 -0
  21. package/dist/runtime-gStewf1p.mjs +2189 -0
  22. package/package.json +4 -5
  23. package/src/contracts.ts +0 -58
  24. package/src/diagnostics.ts +0 -188
  25. package/src/docs.ts +0 -109
  26. package/src/generated/contracts.ts +0 -24207
  27. package/src/generated/docs.ts +0 -12
  28. package/src/index.ts +0 -99
  29. package/src/node.ts +0 -317
  30. package/src/path-policy.ts +0 -123
  31. package/src/runtime/capabilities.ts +0 -131
  32. package/src/runtime/contracts.ts +0 -672
  33. package/src/runtime.ts +0 -231
  34. package/src/services/artifact-service.ts +0 -19
  35. package/src/services/authoring-service.ts +0 -229
  36. package/src/services/cache-service.ts +0 -81
  37. package/src/services/capture-project.ts +0 -75
  38. package/src/services/context.ts +0 -150
  39. package/src/services/event-service.ts +0 -86
  40. package/src/services/persistence-service.ts +0 -550
  41. package/src/services/read-service.ts +0 -274
  42. package/src/services/runtime-service.ts +0 -342
  43. package/src/services/session-operation-queue.ts +0 -21
  44. package/src/services/session-project-writer.ts +0 -89
  45. package/src/services/session-registry.ts +0 -70
  46. package/src/services/session-utils.ts +0 -45
  47. package/src/services/transaction-preview.ts +0 -116
  48. package/src/storage.ts +0 -232
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfairygui/backend",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "FairyGUI Headless Authoring SDK — stateful backend runtime and session services.",
5
5
  "author": "OpenFairyGUI Contributors",
6
6
  "license": "MIT",
@@ -55,8 +55,7 @@
55
55
  },
56
56
  "files": [
57
57
  "docs/",
58
- "dist/",
59
- "src/"
58
+ "dist/"
60
59
  ],
61
60
  "keywords": [
62
61
  "fairygui",
@@ -66,8 +65,8 @@
66
65
  "runtime"
67
66
  ],
68
67
  "dependencies": {
69
- "@openfairygui/core": "0.6.3",
70
- "@openfairygui/functions": "0.6.3"
68
+ "@openfairygui/functions": "0.7.1",
69
+ "@openfairygui/core": "0.7.1"
71
70
  },
72
71
  "devDependencies": {
73
72
  "ava": "^7.0.0",
package/src/contracts.ts DELETED
@@ -1,58 +0,0 @@
1
- import type { ProjectDiagnosticCode } from '@openfairygui/core';
2
- import type { UamTransactionSupportIssueCode } from '@openfairygui/core/uam';
3
- import type { BackendError } from './runtime.js';
4
-
5
- export const BACKEND_CONTRACT_VERSION = '3.0.0' as const;
6
- export const BACKEND_CAPABILITY_SCHEMA_VERSION = 12 as const;
7
- export const BACKEND_COMPATIBILITY_POLICY = {
8
- incompatibleChange: 'requires contractVersion bump',
9
- capabilitySchemaChange: 'requires capabilitySchemaVersion bump',
10
- additiveChange: 'allowed without breaking existing consumers',
11
- } as const;
12
-
13
- export type BackendStage = 'read' | 'authoring' | 'runtime';
14
-
15
- export interface BackendMessage {
16
- code: string;
17
- message: string;
18
- }
19
-
20
- export type BackendDiagnosticCode = BackendError['code'] | UamTransactionSupportIssueCode | ProjectDiagnosticCode;
21
- export type BackendDiagnosticOwner = 'backend' | 'core.transaction' | 'core.validation';
22
-
23
- export interface BackendDiagnostic {
24
- code: BackendDiagnosticCode;
25
- message: string;
26
- severity: 'info' | 'warning' | 'error';
27
- path?: string;
28
- nodeKind?: string;
29
- resourceKind?: string;
30
- gearKind?: string;
31
- field?: string;
32
- operationKind?: string;
33
- opIndex?: number;
34
- opId?: string;
35
- /** Present for catalogued diagnostics only; original codes and classification are preserved. */
36
- owner?: BackendDiagnosticOwner;
37
- docsUri?: string;
38
- remediation?: BackendDiagnosticRemediation;
39
- }
40
-
41
- export interface BackendDiagnosticRemediation {
42
- kind: 'refresh-and-replan' | 'revise-selector' | 'revise-operation' | 'host-action';
43
- message: string;
44
- /** A read-only starting point, never permission to retry or mutate. */
45
- read?: { method: 'getProjectOutline'; input: { sessionId: string } };
46
- }
47
-
48
- export interface BackendResponseMeta {
49
- requestId: string;
50
- sessionId?: string;
51
- revision?: number;
52
- durationMs: number;
53
- warnings: BackendMessage[];
54
- diagnostics: BackendDiagnostic[];
55
- stage: BackendStage;
56
- contractVersion: typeof BACKEND_CONTRACT_VERSION;
57
- capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
58
- }
@@ -1,188 +0,0 @@
1
- import type { BackendDiagnostic, BackendDiagnosticCode, BackendDiagnosticOwner, BackendDiagnosticRemediation } from './contracts.js';
2
-
3
- /** Shared codes list all canonical owners; responses preserve the actual reporting owner. */
4
- export interface BackendDiagnosticGuide {
5
- code: BackendDiagnosticCode;
6
- owners: readonly BackendDiagnosticOwner[];
7
- remediation: Omit<BackendDiagnosticRemediation, 'read'>;
8
- }
9
-
10
- const selector = {
11
- kind: 'revise-selector',
12
- message: 'Read the current outline and query the relevant entity. Use its exact identifiers, inspect the reported selector path, then rebuild and preflight the transaction. Do not guess identifiers or retry the unchanged transaction.',
13
- } as const;
14
- const source = {
15
- kind: 'host-action',
16
- message: 'Ask the host to inspect the reported source and hydrate its bytes through project I/O or import. Preserve unsaved work; reopening disk state can discard it. No session hydration/repair API is exposed. Revalidate and replan after the host has supplied a complete project.',
17
- } as const;
18
- const path = {
19
- kind: 'host-action',
20
- message: 'Ask the host to review the attempted path and authorized project root. saveSession only writes the original project; it is not Save As. Do not widen allowed roots or bypass path checks. A separately authorized export may use materializeSession.',
21
- } as const;
22
-
23
- const unsupported = { kind: 'revise-operation', message: "Read the operation schema, capabilities and reported target kind/field. Stop unsupported work or replan using supported operations with equivalent intended semantics. Never silently drop fields or objects to make a transaction pass." } as const;
24
- const payload = { kind: 'revise-operation', message: "Inspect the diagnostic path and current operation schema or UAM issues. Correct values, required fields and indices against exact queried entities, then preflight. Do not invent defaults or coerce away invalid data." } as const;
25
- const unchanged = { kind: 'refresh-and-replan', message: "Query current settings/entity and compare with the request. If already satisfied, report no change; otherwise replan from the current revision. Do not manufacture a mutation or resubmit the same no-op." } as const;
26
- const duplicate = { kind: 'revise-operation', message: "Query current entities and resolve the conflicting ID, name or page explicitly. Choose an unused value only when authorized by the intended edit, then preflight. Never overwrite or delete an existing entity to clear the conflict." } as const;
27
- const references = { kind: 'revise-operation', message: "Query affected entities and references before editing, moving or removing anything. Replan intended dependent changes together and preflight. Do not delete dependent objects or strip references without authorization." } as const;
28
- const project = { kind: 'host-action', message: "Inspect the project path and validation diagnostics with the host. Correct source XML/settings or unsupported geometry using authoritative project data; preserve originals and unsaved work before reopening or validating. Do not guess missing structure or discard rejected content." } as const;
29
- const capability = { kind: 'host-action', message: "Read capability/error details. Ask the host to provide the required filesystem, decoder or complete UAM adapter. Preserve the session and unsaved work; do not substitute a lossy path or bypass checks." } as const;
30
- const write = { kind: 'host-action', message: "Preserve the dirty session and inspect the error, actual target files and permissions with the host. Partial writes may have changed files: verify or recover them before a newly authorized save. Do not clear dirty state, discard memory or blindly retry." } as const;
31
- const execution = { kind: 'host-action', message: "Inspect the execution/cache failure and current session/revision. Preserve sources and unsaved work and report the cause to the host. Replan after resolution; failed execution or cache work is not a completed edit." } as const;
32
-
33
- /** Exhaustiveness and exact ownership are checked against the canonical unions. */
34
- export const BACKEND_DIAGNOSTIC_GUIDES = [
35
- { code: 'stale_read', owners: ['backend'], remediation: {
36
- kind: 'refresh-and-replan',
37
- message: 'Discard the incomplete model/bytes read and restart with readSessionState. Use its revision for every readResourceBytes call. No historical state is retained or reserved; do not combine resources from different edit revisions.',
38
- } },
39
- { code: 'session_read_failed', owners: ['backend'], remediation: {
40
- kind: 'host-action',
41
- message: 'Inspect error.reason: invalid_query requires valid inputs; not_found/ambiguous requires exact current resource identifiers; unsupported_resource/bytes_unavailable means primary bytes cannot be read from this session. Budget or non-JSON failures require host inspection. Preserve unsaved work; do not save, reopen, repair or mutate the model merely to obtain a read.',
42
- } },
43
- { code: 'transaction_preview_failed', owners: ['backend'], remediation: {
44
- kind: 'host-action',
45
- message: 'No complete preview is available. Inspect error.reason with the host: response_budget_exceeded requires a smaller independently meaningful authorized batch; projection_failed requires inspecting the project serialization failure. Preserve the session and never treat a missing or truncated impact as approval to apply or save.',
46
- } },
47
- { code: 'stale_write', owners: ['backend'], remediation: {
48
- kind: 'refresh-and-replan',
49
- message: 'Refresh the outline and affected entities, then replan from their current revision and preflight again. A preview reserves no revision. Never replace expectedRevision and blindly retry the original transaction or save.',
50
- } },
51
- { code: 'entity_query_failed', owners: ['backend'], remediation: {
52
- kind: 'host-action',
53
- message: 'Inspect error.reason: invalid_query requires correcting the target; not_found/ambiguous requires current exact identifiers; response_budget_exceeded/non_json_value requires host inspection of the entity. Do not broaden queries or mutate data to evade the response limits.',
54
- } },
55
- { code: 'session_not_found', owners: ['backend'], remediation: {
56
- kind: 'host-action',
57
- message: 'Ask the host to confirm the runtime and project, recover any unsaved state, then explicitly open a new session if appropriate. Session IDs are runtime-local. Read its new revision and replan; never reuse an expired session or assume disk contains unsaved changes.',
58
- } },
59
- { code: 'session_close_failed', owners: ['backend'], remediation: {
60
- kind: 'host-action',
61
- message: 'The session and lock ownership remain registered. Inspect the reported lock release failure, correct the storage problem, then retry closeSession with the same session ID. Do not remove the lock file or open a replacement session to bypass the owner.',
62
- } },
63
- { code: 'path_policy_violation', owners: ['backend'], remediation: path },
64
- { code: 'project_root_not_allowed', owners: ['backend'], remediation: path },
65
- { code: 'invalid_package_selector', owners: ['core.transaction'], remediation: selector },
66
- { code: 'invalid_component_selector', owners: ['core.transaction'], remediation: selector },
67
- { code: 'invalid_resource_selector', owners: ['core.transaction'], remediation: selector },
68
- { code: 'invalid_display_node_selector', owners: ['core.transaction'], remediation: selector },
69
- { code: 'invalid_resource_folder_selector', owners: ['core.transaction'], remediation: selector },
70
- { code: 'invalid_branch_selector', owners: ['core.transaction'], remediation: selector },
71
- { code: 'invalid_gear_selector', owners: ['core.transaction'], remediation: selector },
72
- { code: 'invalid_look_gear_selector', owners: ['core.transaction'], remediation: selector },
73
- { code: 'selector_ambiguity', owners: ['core.transaction'], remediation: selector },
74
- { code: 'unavailable_resource_source_bytes', owners: ['core.transaction'], remediation: source },
75
- { code: 'missing_source', owners: ['core.validation'], remediation: source },
76
- { code: 'unreadable_source', owners: ['core.validation'], remediation: source },
77
- { code: 'decode_capability_unavailable', owners: ['core.validation'], remediation: {
78
- kind: 'host-action',
79
- message: 'Validation is incomplete, not passed. Inspect whether source bytes are unloaded or a decoder is unavailable. Ask the host to hydrate sources or provide the required decoder (Node image validation uses optional Sharp), then validate again. Do not install dependencies or change the project automatically.',
80
- } },
81
- { code: 'session_id_conflict', owners: ['backend'], remediation: { kind: 'host-action', message: "Use getSession to inspect the existing session. Reuse it only for the intended project, or choose a new session ID; do not close another owner\\u0027s session to make room." } },
82
- { code: 'lock_conflict', owners: ['backend'], remediation: { kind: 'host-action', message: "Another owner holds the project lock. Preserve unsaved work and ask that owner to close its session, then explicitly reopen. Never remove a live lock, force-close a peer, or bypass locking." } },
83
- { code: 'event_cursor_invalid', owners: ['backend'], remediation: { kind: 'refresh-and-replan', message: "Read the error and getEvents cursor bounds. Request a fresh bounded event page without the invalid cursor and refresh the current outline before replanning; missing retained history is not evidence that nothing changed." } },
84
- { code: 'corrupt_source', owners: ["core.validation"], remediation: source },
85
- { code: 'unsupported_operation', owners: ["core.transaction"], remediation: unsupported },
86
- { code: 'transaction_unsupported', owners: ["core.transaction"], remediation: unsupported },
87
- { code: 'unsupported_display_node_kind', owners: ["core.transaction"], remediation: unsupported },
88
- { code: 'unsupported_cross_package_image_ref', owners: ["core.transaction"], remediation: unsupported },
89
- { code: 'unsupported_gear_kind', owners: ["core.transaction"], remediation: unsupported },
90
- { code: 'unsupported_resource_mutation', owners: ["core.transaction"], remediation: unsupported },
91
- { code: 'unsupported_display_node_mutation', owners: ["core.transaction"], remediation: unsupported },
92
- { code: 'unsupported_text_field_target', owners: ["core.transaction"], remediation: unsupported },
93
- { code: 'unsupported_display_node_field', owners: ["core.transaction"], remediation: unsupported },
94
- { code: 'unsupported_operation_batch', owners: ["core.transaction"], remediation: unsupported },
95
- { code: 'unsupported_resource_kind', owners: ["core.transaction","core.validation"], remediation: unsupported },
96
- { code: 'invalid_project_settings', owners: ["core.transaction"], remediation: payload },
97
- { code: 'invalid_package_settings', owners: ["core.transaction"], remediation: payload },
98
- { code: 'invalid_display_node_payload', owners: ["core.transaction"], remediation: payload },
99
- { code: 'invalid_resource_name', owners: ["core.transaction"], remediation: payload },
100
- { code: 'invalid_resource_path', owners: ["core.transaction"], remediation: payload },
101
- { code: 'invalid_resource_folder_path', owners: ["core.transaction"], remediation: payload },
102
- { code: 'invalid_resource_folder_atlas', owners: ["core.transaction"], remediation: payload },
103
- { code: 'invalid_attach_index', owners: ["core.transaction"], remediation: payload },
104
- { code: 'invalid_controller_payload', owners: ["core.transaction"], remediation: payload },
105
- { code: 'invalid_transition_payload', owners: ["core.transaction"], remediation: payload },
106
- { code: 'invalid_look_gear_payload', owners: ["core.transaction"], remediation: payload },
107
- { code: 'invalid_gear_payload', owners: ["core.transaction"], remediation: payload },
108
- { code: 'invalid_resource_payload', owners: ["core.transaction"], remediation: payload },
109
- { code: 'invalid_resource_bytes', owners: ["core.transaction"], remediation: payload },
110
- { code: 'invalid_movie_clip_jta', owners: ["core.transaction"], remediation: payload },
111
- { code: 'invalid_resource_index', owners: ["core.transaction"], remediation: payload },
112
- { code: 'invalid_branch_name', owners: ["core.transaction"], remediation: payload },
113
- { code: 'invalid_package_payload', owners: ["core.transaction"], remediation: payload },
114
- { code: 'invalid_package_index', owners: ["core.transaction"], remediation: payload },
115
- { code: 'invalid_component_payload', owners: ["core.transaction"], remediation: payload },
116
- { code: 'invalid_component_index', owners: ["core.transaction"], remediation: payload },
117
- { code: 'invalid_component_move', owners: ["core.transaction"], remediation: payload },
118
- { code: 'invalid_uam', owners: ["core.transaction","core.validation"], remediation: payload },
119
- { code: 'project_settings_unchanged', owners: ["core.transaction"], remediation: unchanged },
120
- { code: 'package_settings_unchanged', owners: ["core.transaction"], remediation: unchanged },
121
- { code: 'display_node_props_unchanged', owners: ["core.transaction"], remediation: unchanged },
122
- { code: 'resource_folder_atlas_unchanged', owners: ["core.transaction"], remediation: unchanged },
123
- { code: 'duplicate_look_gear_controller', owners: ["core.transaction"], remediation: duplicate },
124
- { code: 'duplicate_transition_name', owners: ["core.transaction"], remediation: duplicate },
125
- { code: 'duplicate_look_gear_state_page', owners: ["core.transaction"], remediation: duplicate },
126
- { code: 'duplicate_gear_controller', owners: ["core.transaction"], remediation: duplicate },
127
- { code: 'duplicate_gear_state_page', owners: ["core.transaction"], remediation: duplicate },
128
- { code: 'duplicate_branch_name', owners: ["core.transaction"], remediation: duplicate },
129
- { code: 'duplicate_component_id', owners: ["core.transaction"], remediation: duplicate },
130
- { code: 'resource_folder_conflict', owners: ["core.transaction"], remediation: duplicate },
131
- { code: 'duplicate_resource_id', owners: ["core.transaction","core.validation"], remediation: duplicate },
132
- { code: 'duplicate_package_id', owners: ["core.transaction","core.validation"], remediation: duplicate },
133
- { code: 'duplicate_package_name', owners: ["core.transaction","core.validation"], remediation: duplicate },
134
- { code: 'resource_folder_not_empty', owners: ["core.transaction"], remediation: references },
135
- { code: 'branch_not_empty', owners: ["core.transaction"], remediation: references },
136
- { code: 'branch_referenced', owners: ["core.transaction"], remediation: references },
137
- { code: 'invalid_resource_reference', owners: ["core.transaction"], remediation: references },
138
- { code: 'invalid_component_reference', owners: ["core.transaction"], remediation: references },
139
- { code: 'invalid_group_reference', owners: ["core.transaction"], remediation: references },
140
- { code: 'package_referenced', owners: ["core.transaction"], remediation: references },
141
- { code: 'component_referenced', owners: ["core.transaction"], remediation: references },
142
- { code: 'component_has_package_dependencies', owners: ["core.transaction"], remediation: references },
143
- { code: 'dangling_resource_reference', owners: ["core.validation"], remediation: references },
144
- { code: 'invalid_project_xml', owners: ["core.validation"], remediation: project },
145
- { code: 'invalid_package_xml', owners: ["core.validation"], remediation: project },
146
- { code: 'invalid_branch_package_xml', owners: ["core.validation"], remediation: project },
147
- { code: 'invalid_component_xml', owners: ["core.validation"], remediation: project },
148
- { code: 'invalid_project_value', owners: ["core.validation"], remediation: project },
149
- { code: 'desktop_incompatible_geometry', owners: ["core.validation"], remediation: project },
150
- { code: 'invalid_settings_json', owners: ["core.validation"], remediation: project },
151
- { code: 'path_collision', owners: ["core.validation"], remediation: path },
152
- { code: 'unsafe_path', owners: ["core.validation"], remediation: path },
153
- { code: 'capability_unavailable', owners: ["backend"], remediation: capability },
154
- { code: 'uam_fidelity_unsupported', owners: ["backend"], remediation: capability },
155
- { code: 'save_partial_failure', owners: ["backend"], remediation: write },
156
- { code: 'write_failed', owners: ["backend"], remediation: write },
157
- { code: 'project_open_failed', owners: ["backend"], remediation: project },
158
- { code: 'materialize_validation_failed', owners: ["backend"], remediation: project },
159
- { code: 'execution_failure', owners: ["core.transaction"], remediation: execution },
160
- ] as const satisfies readonly BackendDiagnosticGuide[];
161
-
162
- export const BACKEND_DIAGNOSTICS_URI = 'openfairygui://docs/diagnostics';
163
- export const BACKEND_DIAGNOSTIC_TEMPLATE = `${BACKEND_DIAGNOSTICS_URI}/{code}`;
164
-
165
- export function getBackendDiagnosticCatalog() {
166
- return BACKEND_DIAGNOSTIC_GUIDES.map((guide) => ({ ...structuredClone(guide), docsUri: `${BACKEND_DIAGNOSTICS_URI}/${guide.code}` }));
167
- }
168
-
169
- export function getBackendDiagnosticGuide(code: string) {
170
- const guide = getBackendDiagnosticCatalog().find((entry) => entry.code === code);
171
- if (!guide) throw new RangeError(`No recovery guide for diagnostic: ${code}`);
172
- return guide;
173
- }
174
-
175
- export function enrichBackendDiagnostic(diagnostic: BackendDiagnostic, sessionId?: string): BackendDiagnostic {
176
- const guide = BACKEND_DIAGNOSTIC_GUIDES.find((entry) => entry.code === diagnostic.code);
177
- if (!guide) return { ...diagnostic };
178
- return {
179
- ...diagnostic,
180
- owner: diagnostic.owner ?? guide.owners[0],
181
- docsUri: `${BACKEND_DIAGNOSTICS_URI}/${guide.code}`,
182
- remediation: {
183
- ...guide.remediation,
184
- ...(sessionId && guide.remediation.kind !== 'host-action'
185
- ? { read: { method: 'getProjectOutline' as const, input: { sessionId } } } : {}),
186
- },
187
- };
188
- }
package/src/docs.ts DELETED
@@ -1,109 +0,0 @@
1
- import { getBackendDiagnosticCatalog, getBackendDiagnosticGuide, type BackendDiagnosticGuide } from './diagnostics.js';
2
- import { CONTRACT_SNAPSHOT } from './generated/contracts.js';
3
- import { INSTALLED_DOCS } from './generated/docs.js';
4
-
5
- /** JSON Schema data, not another validator or operation grammar. */
6
- export interface ContractSchema { $ref?: string; [keyword: string]: unknown }
7
- export interface ContractSnapshot {
8
- digest: string;
9
- schemaVersion: number;
10
- versions: { BACKEND_CONTRACT_VERSION: string; BACKEND_CAPABILITY_SCHEMA_VERSION: number };
11
- operations: Record<string, ContractSchema>;
12
- tools: Record<string, { input: ContractSchema; output: ContractSchema; bytePaths: string[][]; [metadata: string]: unknown }>;
13
- cli: Record<string, ContractSchema>;
14
- $defs: Record<string, ContractSchema>;
15
- diagnostics: BackendDiagnosticGuide[];
16
- }
17
-
18
- export const OPENFAIRYGUI_DOCS_INDEX_URI = 'openfairygui://docs/index';
19
- export const OPENFAIRYGUI_OPERATION_CATALOG_URI = 'openfairygui://contracts/operations';
20
- export const OPENFAIRYGUI_OPERATION_SCHEMA_TEMPLATE = `${OPENFAIRYGUI_OPERATION_CATALOG_URI}/{kind}`;
21
-
22
- /** Detached copy for wire adapters; documentation and adapters share one generated snapshot. */
23
- export function getInstalledContractSnapshot(): ContractSnapshot { return structuredClone(CONTRACT_SNAPSHOT); }
24
-
25
- export function getInstalledDocumentationVersion() {
26
- return { ...INSTALLED_DOCS.version, ...CONTRACT_SNAPSHOT.versions, contractDigest: CONTRACT_SNAPSHOT.digest };
27
- }
28
-
29
- export function getOpenFairyGuiOperationCatalog() {
30
- return {
31
- digest: CONTRACT_SNAPSHOT.digest, schemaVersion: CONTRACT_SNAPSHOT.schemaVersion,
32
- ...CONTRACT_SNAPSHOT.versions,
33
- operations: Object.keys(CONTRACT_SNAPSHOT.operations).map((kind) => ({ kind, schemaUri: `${OPENFAIRYGUI_OPERATION_CATALOG_URI}/${kind}` })),
34
- };
35
- }
36
-
37
- /** Include only reachable definitions, so an individual schema works fully offline. */
38
- function standaloneSchema(schema: ContractSchema): ContractSchema {
39
- const definitions: Record<string, ContractSchema> = {};
40
- function visit(value: unknown): void {
41
- if (!value || typeof value !== 'object') return;
42
- const ref = (value as ContractSchema).$ref;
43
- if (ref) {
44
- const key = ref.slice('#/$defs/'.length);
45
- if (Object.hasOwn(definitions, key)) return;
46
- definitions[key] = CONTRACT_SNAPSHOT.$defs[key];
47
- visit(definitions[key]);
48
- } else for (const child of Object.values(value)) visit(child);
49
- }
50
- visit(schema);
51
- return structuredClone({ $schema: 'https://json-schema.org/draft/2020-12/schema', ...schema, $defs: definitions });
52
- }
53
-
54
- export function getOpenFairyGuiOperationSchema(kind: string): ContractSchema {
55
- if (!Object.hasOwn(CONTRACT_SNAPSHOT.operations, kind)) throw new RangeError(`Unknown UAM operation: ${kind}`);
56
- return standaloneSchema(CONTRACT_SNAPSHOT.operations[kind]);
57
- }
58
-
59
- export function getInstalledDocumentationIndex() {
60
- return {
61
- ...getInstalledDocumentationVersion(),
62
- documents: [
63
- { id: 'workflow', title: 'Safe editing workflow and installation checks', uri: 'openfairygui://docs/workflow' },
64
- { id: 'restore-limits', title: 'Trusted artifact recovery scope and unrecoverable editor information', uri: 'openfairygui://docs/restore-limits' },
65
- { id: 'skill', title: 'Thin installed-version navigation skill', uri: 'openfairygui://docs/skill' },
66
- { id: 'contracts', title: 'Operation catalog and Backend/MCP method mapping', uri: 'openfairygui://docs/contracts' },
67
- ...Object.keys(CONTRACT_SNAPSHOT.operations).map((kind) => ({ id: `operations/${kind}`, title: `UAM operation: ${kind}`, uri: `${OPENFAIRYGUI_OPERATION_CATALOG_URI}/${kind}` })),
68
- ...Object.keys(CONTRACT_SNAPSHOT.tools).map((method) => ({ id: `methods/${method}`, title: `Backend/MCP wire method: ${method}`, uri: `openfairygui://docs/methods/${method}` })),
69
- ...Object.keys(CONTRACT_SNAPSHOT.cli).map((command) => ({ id: `cli/${command}`, title: `CLI JSON output: ${command}`, uri: `openfairygui://docs/cli/${encodeURIComponent(command)}` })),
70
- ...getBackendDiagnosticCatalog().map((guide) => ({ id: `diagnostics/${guide.code}`, title: `Recovery: ${guide.code}`, uri: guide.docsUri })),
71
- ],
72
- };
73
- }
74
-
75
- /** IDs come from the index, never filesystem paths or remote URLs. */
76
- export function readInstalledDocumentation(id: string) {
77
- const entry = getInstalledDocumentationIndex().documents.find((document) => document.id === id);
78
- if (!entry) throw new RangeError(`Unknown installed documentation ID: ${id}`);
79
- let content: unknown;
80
- if (id === 'workflow') content = INSTALLED_DOCS.workflow;
81
- else if (id === 'restore-limits') content = INSTALLED_DOCS.restoreLimits;
82
- else if (id === 'skill') content = INSTALLED_DOCS.skill;
83
- else if (id === 'contracts') content = {
84
- ...getOpenFairyGuiOperationCatalog(),
85
- methods: Object.entries(CONTRACT_SNAPSHOT.tools).map(([method, { input, output, bytePaths, ...metadata }]) => ({ method, ...metadata, docsUri: `openfairygui://docs/methods/${method}` })),
86
- cli: Object.keys(CONTRACT_SNAPSHOT.cli).map((command) => ({ command, docsUri: `openfairygui://docs/cli/${encodeURIComponent(command)}` })),
87
- };
88
- else if (id.startsWith('operations/')) content = getOpenFairyGuiOperationSchema(id.slice('operations/'.length));
89
- else if (id.startsWith('diagnostics/')) content = getBackendDiagnosticGuide(id.slice('diagnostics/'.length));
90
- else if (id.startsWith('cli/')) content = standaloneSchema(CONTRACT_SNAPSHOT.cli[id.slice('cli/'.length)]);
91
- else {
92
- const tool = CONTRACT_SNAPSHOT.tools[id.slice('methods/'.length)];
93
- content = { ...tool, input: standaloneSchema(tool.input), output: standaloneSchema(tool.output) };
94
- }
95
- return {
96
- ...getInstalledDocumentationVersion(), ...entry,
97
- mimeType: typeof content === 'string' ? 'text/markdown' : 'application/json',
98
- text: typeof content === 'string' ? content : JSON.stringify(content, null, 2),
99
- };
100
- }
101
-
102
- export function findInstalledDocumentation(query: string) {
103
- const term = query.trim().toLowerCase();
104
- if (!term) throw new RangeError('Documentation search must not be empty');
105
- const index = getInstalledDocumentationIndex();
106
- // ponytail: linear search is sufficient for this small installed corpus; index only if it grows materially.
107
- return { ...index, documents: index.documents.filter((entry) =>
108
- `${entry.id}\n${entry.title}\n${readInstalledDocumentation(entry.id).text}`.toLowerCase().includes(term)) };
109
- }