@openfairygui/backend 0.4.0 → 0.5.0-alpha.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/README.md +1 -0
- package/dist/docs.cjs +4776 -845
- package/dist/docs.d.cts +14 -1
- package/dist/docs.d.mts +14 -1
- package/dist/docs.mjs +4776 -845
- package/dist/index.cjs +137 -10
- package/dist/index.d.cts +100 -5
- package/dist/index.d.mts +100 -5
- package/dist/index.mjs +137 -11
- package/dist/node.cjs +135 -9
- package/dist/node.d.cts +67 -4
- package/dist/node.d.mts +67 -4
- package/dist/node.mjs +135 -9
- package/docs/workflow.md +10 -0
- package/package.json +3 -3
- package/src/contracts.ts +1 -1
- package/src/diagnostics.ts +8 -0
- package/src/generated/contracts.ts +8588 -1733
- package/src/generated/docs.ts +3 -3
- package/src/index.ts +10 -0
- package/src/runtime/capabilities.ts +5 -1
- package/src/runtime/contracts.ts +54 -0
- package/src/runtime.ts +14 -0
- package/src/services/read-service.ts +80 -8
package/dist/node.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { UamComponentModel, UamComponentResource, UamComponentSelector, UamControllerModel, UamControllerSelector, UamDisplayNode, UamDisplayNodeKind, UamDisplayNodeSelector, UamGenericAssetResource, UamImageResource, UamMovieClipResource, UamPackageSelector, UamPackageSettings, UamProject, UamResource, UamResourceSelector, UamTransactionOperation, UamTransactionSupportIssueCode, UamTransitionModel, UamTransitionSelector } from "@openfairygui/core/uam";
|
|
1
|
+
import { UamComponentModel, UamComponentResource, UamComponentSelector, UamControllerModel, UamControllerSelector, UamDisplayNode, UamDisplayNodeKind, UamDisplayNodeSelector, UamGenericAssetResource, UamImageResource, UamMovieClipResource, UamPackage, UamPackageSelector, UamPackageSettings, UamProject, UamResource, UamResourceSelector, UamTransactionOperation, UamTransactionSupportIssueCode, UamTransitionModel, UamTransitionSelector } from "@openfairygui/core/uam";
|
|
2
2
|
import { ApplyUamTransactionAppError } from "@openfairygui/functions/uam";
|
|
3
|
+
import * as _$_openfairygui_core0 from "@openfairygui/core";
|
|
3
4
|
import { ProjectDiagnosticCode, ProjectValidationReport } from "@openfairygui/core";
|
|
4
5
|
|
|
5
6
|
//#region src/path-policy.d.ts
|
|
@@ -13,7 +14,7 @@ interface PathPolicyViolationError {
|
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region src/contracts.d.ts
|
|
15
16
|
declare const BACKEND_CONTRACT_VERSION: "2.0.0-p2";
|
|
16
|
-
declare const BACKEND_CAPABILITY_SCHEMA_VERSION:
|
|
17
|
+
declare const BACKEND_CAPABILITY_SCHEMA_VERSION: 11;
|
|
17
18
|
declare const BACKEND_COMPATIBILITY_POLICY: {
|
|
18
19
|
readonly incompatibleChange: "requires contractVersion bump";
|
|
19
20
|
readonly capabilitySchemaChange: "requires capabilitySchemaVersion bump";
|
|
@@ -67,7 +68,7 @@ interface BackendResponseMeta {
|
|
|
67
68
|
}
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region src/runtime/capabilities.d.ts
|
|
70
|
-
declare const BACKEND_METHODS: readonly ["getCapabilities", "openSession", "openProjectSession", "getSession", "getProjectOutline", "queryEntity", "validateSession", "preflightTransaction", "applyTransaction", "saveSession", "materializeSession", "closeSession", "getEvents", "getJob", "listJobs", "cancelJob", "getCacheSnapshot", "refreshCache"];
|
|
71
|
+
declare const BACKEND_METHODS: readonly ["getCapabilities", "openSession", "openProjectSession", "getSession", "getProjectOutline", "queryEntity", "readSessionState", "readResourceBytes", "validateSession", "preflightTransaction", "applyTransaction", "saveSession", "materializeSession", "closeSession", "getEvents", "getJob", "listJobs", "cancelJob", "getCacheSnapshot", "refreshCache"];
|
|
71
72
|
//#endregion
|
|
72
73
|
//#region src/runtime/contracts.d.ts
|
|
73
74
|
declare const BACKEND_ENTITY_QUERY_LIMITS: {
|
|
@@ -75,6 +76,57 @@ declare const BACKEND_ENTITY_QUERY_LIMITS: {
|
|
|
75
76
|
readonly maxDepth: 32;
|
|
76
77
|
readonly maxNodes: 100000;
|
|
77
78
|
};
|
|
79
|
+
declare const BACKEND_SESSION_READ_LIMITS: {
|
|
80
|
+
readonly model: {
|
|
81
|
+
readonly maxBytes: 4194304;
|
|
82
|
+
readonly maxDepth: 64;
|
|
83
|
+
readonly maxNodes: 500000;
|
|
84
|
+
};
|
|
85
|
+
readonly resourceBytes: 1048576;
|
|
86
|
+
};
|
|
87
|
+
/** The public UAM model, excluding only each asset resource's primary sourceBytes. */
|
|
88
|
+
type BackendSessionResourceModel = UamComponentResource | Omit<UamImageResource, 'sourceBytes'> | Omit<UamMovieClipResource, 'sourceBytes'> | Omit<UamGenericAssetResource, 'sourceBytes'>;
|
|
89
|
+
interface BackendSessionPackageModel extends Omit<UamPackage, 'resources'> {
|
|
90
|
+
resources: BackendSessionResourceModel[];
|
|
91
|
+
}
|
|
92
|
+
interface BackendSessionProjectModel extends Omit<UamProject, 'packages'> {
|
|
93
|
+
packages: BackendSessionPackageModel[];
|
|
94
|
+
}
|
|
95
|
+
interface ReadSessionStateInput {
|
|
96
|
+
sessionId: string;
|
|
97
|
+
expectedRevision?: number;
|
|
98
|
+
}
|
|
99
|
+
interface ReadResourceBytesInput {
|
|
100
|
+
sessionId: string;
|
|
101
|
+
expectedRevision: number;
|
|
102
|
+
selector: UamResourceSelector;
|
|
103
|
+
}
|
|
104
|
+
interface BackendSessionStateSnapshot extends Pick<BackendSessionSnapshot, 'sessionId' | 'revision' | 'lastSavedRevision' | 'dirty' | 'uamFidelity'> {
|
|
105
|
+
project: BackendSessionProjectModel;
|
|
106
|
+
readDiagnostics: _$_openfairygui_core0.ProjectDiagnostic[];
|
|
107
|
+
/** Source-read completeness, not a guarantee of resource bytes or downstream usability. */
|
|
108
|
+
readComplete: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface BackendResourceBytesSnapshot {
|
|
111
|
+
sessionId: string;
|
|
112
|
+
revision: number;
|
|
113
|
+
selector: UamResourceSelector;
|
|
114
|
+
/** Only primary bytes already held in this session; no filesystem hydration. */
|
|
115
|
+
sourceBytes: Uint8Array;
|
|
116
|
+
}
|
|
117
|
+
interface SessionReadError {
|
|
118
|
+
code: 'session_read_failed';
|
|
119
|
+
message: string;
|
|
120
|
+
sessionId: string;
|
|
121
|
+
reason: 'invalid_query' | 'not_found' | 'ambiguous' | 'unsupported_resource' | 'bytes_unavailable' | 'response_budget_exceeded' | 'non_json_value';
|
|
122
|
+
}
|
|
123
|
+
interface SessionStaleReadError {
|
|
124
|
+
code: 'stale_read';
|
|
125
|
+
message: string;
|
|
126
|
+
sessionId: string;
|
|
127
|
+
expectedRevision: number;
|
|
128
|
+
actualRevision: number;
|
|
129
|
+
}
|
|
78
130
|
declare const BACKEND_TRANSACTION_PREVIEW_LIMITS: {
|
|
79
131
|
readonly maxBytes: 262144;
|
|
80
132
|
readonly maxEntries: 2000;
|
|
@@ -247,6 +299,15 @@ interface BackendCapabilities {
|
|
|
247
299
|
sourceBytes: false;
|
|
248
300
|
limits: typeof BACKEND_ENTITY_QUERY_LIMITS;
|
|
249
301
|
};
|
|
302
|
+
sessionState: {
|
|
303
|
+
sourceBytes: false;
|
|
304
|
+
limits: typeof BACKEND_SESSION_READ_LIMITS.model;
|
|
305
|
+
};
|
|
306
|
+
resourceBytes: {
|
|
307
|
+
expectedRevisionRequired: true;
|
|
308
|
+
hydration: false;
|
|
309
|
+
maxBytes: typeof BACKEND_SESSION_READ_LIMITS.resourceBytes;
|
|
310
|
+
};
|
|
250
311
|
projectValidation: true;
|
|
251
312
|
};
|
|
252
313
|
authoring: {
|
|
@@ -588,7 +649,7 @@ interface RefreshCacheInput {
|
|
|
588
649
|
sessionId: string;
|
|
589
650
|
reason?: 'manual' | 'session_open' | 'after_save';
|
|
590
651
|
}
|
|
591
|
-
type BackendError = SessionNotFoundError | TransactionPreviewError | EntityQueryError | SessionIdConflictError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | ApplyUamTransactionAppError;
|
|
652
|
+
type BackendError = SessionNotFoundError | TransactionPreviewError | EntityQueryError | SessionReadError | SessionStaleReadError | SessionIdConflictError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | ApplyUamTransactionAppError;
|
|
592
653
|
interface ProjectRootNotAllowedError {
|
|
593
654
|
code: 'project_root_not_allowed';
|
|
594
655
|
message: string;
|
|
@@ -714,6 +775,8 @@ declare class BackendRuntime {
|
|
|
714
775
|
}): BackendResult<BackendSessionSnapshot, SessionNotFoundError>;
|
|
715
776
|
getProjectOutline(input: GetProjectOutlineInput): BackendResult<BackendProjectOutline, SessionNotFoundError>;
|
|
716
777
|
queryEntity(input: QueryEntityInput): BackendResult<BackendEntitySnapshot, SessionNotFoundError | EntityQueryError>;
|
|
778
|
+
readSessionState(input: ReadSessionStateInput): BackendResult<BackendSessionStateSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
|
|
779
|
+
readResourceBytes(input: ReadResourceBytesInput): BackendResult<BackendResourceBytesSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
|
|
717
780
|
validateSession(input: ValidateSessionInput): BackendResult<ProjectValidationReport, SessionNotFoundError>;
|
|
718
781
|
preflightTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendTransactionPreview, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError | TransactionPreviewError>>;
|
|
719
782
|
applyTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError>>;
|
package/dist/node.mjs
CHANGED
|
@@ -144,6 +144,22 @@ const job = {
|
|
|
144
144
|
};
|
|
145
145
|
/** Exhaustiveness and exact ownership are checked against the canonical unions. */
|
|
146
146
|
const BACKEND_DIAGNOSTIC_GUIDES = [
|
|
147
|
+
{
|
|
148
|
+
code: "stale_read",
|
|
149
|
+
owners: ["backend"],
|
|
150
|
+
remediation: {
|
|
151
|
+
kind: "refresh-and-replan",
|
|
152
|
+
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."
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
code: "session_read_failed",
|
|
157
|
+
owners: ["backend"],
|
|
158
|
+
remediation: {
|
|
159
|
+
kind: "host-action",
|
|
160
|
+
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."
|
|
161
|
+
}
|
|
162
|
+
},
|
|
147
163
|
{
|
|
148
164
|
code: "transaction_preview_failed",
|
|
149
165
|
owners: ["backend"],
|
|
@@ -719,7 +735,7 @@ function createMeta(stage, startedAt, options) {
|
|
|
719
735
|
diagnostics: (options?.diagnostics ?? []).map((entry) => enrichBackendDiagnostic(entry, options?.sessionId)),
|
|
720
736
|
stage,
|
|
721
737
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
722
|
-
capabilitySchemaVersion:
|
|
738
|
+
capabilitySchemaVersion: 11
|
|
723
739
|
};
|
|
724
740
|
}
|
|
725
741
|
function success(stage, startedAt, data, options) {
|
|
@@ -841,6 +857,14 @@ const BACKEND_ENTITY_QUERY_LIMITS = {
|
|
|
841
857
|
maxDepth: 32,
|
|
842
858
|
maxNodes: 1e5
|
|
843
859
|
};
|
|
860
|
+
const BACKEND_SESSION_READ_LIMITS = {
|
|
861
|
+
model: {
|
|
862
|
+
maxBytes: 4194304,
|
|
863
|
+
maxDepth: 64,
|
|
864
|
+
maxNodes: 5e5
|
|
865
|
+
},
|
|
866
|
+
resourceBytes: 1048576
|
|
867
|
+
};
|
|
844
868
|
const BACKEND_TRANSACTION_PREVIEW_LIMITS = {
|
|
845
869
|
maxBytes: 262144,
|
|
846
870
|
maxEntries: 2e3
|
|
@@ -1987,7 +2011,7 @@ var JobService = class {
|
|
|
1987
2011
|
//#endregion
|
|
1988
2012
|
//#region src/services/read-service.ts
|
|
1989
2013
|
/** Bound traversal before serialization or cloning, including non-JSON values on a malformed native input. */
|
|
1990
|
-
function queryResponseProblem(value) {
|
|
2014
|
+
function queryResponseProblem(value, limits = BACKEND_ENTITY_QUERY_LIMITS) {
|
|
1991
2015
|
const pending = [{
|
|
1992
2016
|
value,
|
|
1993
2017
|
depth: 0
|
|
@@ -1996,26 +2020,37 @@ function queryResponseProblem(value) {
|
|
|
1996
2020
|
let stringUnits = 0;
|
|
1997
2021
|
while (pending.length) {
|
|
1998
2022
|
const { value, depth } = pending.pop();
|
|
1999
|
-
if (++nodes >
|
|
2000
|
-
if (typeof value === "string" && (stringUnits += value.length) >
|
|
2023
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth) return "response_budget_exceeded";
|
|
2024
|
+
if (typeof value === "string" && (stringUnits += value.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2001
2025
|
if (value === void 0 || value === null || typeof value === "string" || typeof value === "boolean") continue;
|
|
2002
2026
|
if (typeof value === "number") {
|
|
2003
2027
|
if (!Number.isFinite(value)) return "non_json_value";
|
|
2004
2028
|
continue;
|
|
2005
2029
|
}
|
|
2006
2030
|
if (typeof value !== "object" || !Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return "non_json_value";
|
|
2007
|
-
if (Array.isArray(value) && value.length + pending.length + nodes >
|
|
2031
|
+
if (Array.isArray(value) && value.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2008
2032
|
const entries = Object.entries(value);
|
|
2009
|
-
if (entries.length + pending.length + nodes >
|
|
2033
|
+
if (entries.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2010
2034
|
for (const [key, child] of entries) {
|
|
2011
|
-
if (!Array.isArray(value) && (stringUnits += key.length) >
|
|
2035
|
+
if (!Array.isArray(value) && (stringUnits += key.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2012
2036
|
pending.push({
|
|
2013
2037
|
value: child,
|
|
2014
2038
|
depth: depth + 1
|
|
2015
2039
|
});
|
|
2016
2040
|
}
|
|
2017
2041
|
}
|
|
2018
|
-
if (new TextEncoder().encode(JSON.stringify(value)).byteLength >
|
|
2042
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > limits.maxBytes) return "response_budget_exceeded";
|
|
2043
|
+
}
|
|
2044
|
+
function readFailure(startedAt, sessionId, reason, revision) {
|
|
2045
|
+
return failure("read", startedAt, {
|
|
2046
|
+
code: "session_read_failed",
|
|
2047
|
+
sessionId,
|
|
2048
|
+
reason,
|
|
2049
|
+
message: `Session read failed: ${reason}.`
|
|
2050
|
+
}, void 0, {
|
|
2051
|
+
sessionId,
|
|
2052
|
+
revision
|
|
2053
|
+
});
|
|
2019
2054
|
}
|
|
2020
2055
|
function toProjectOutline(session) {
|
|
2021
2056
|
const project = session.project;
|
|
@@ -2199,6 +2234,80 @@ var ReadService = class {
|
|
|
2199
2234
|
}
|
|
2200
2235
|
return respond(entity);
|
|
2201
2236
|
}
|
|
2237
|
+
resolveReadSession(input, startedAt) {
|
|
2238
|
+
if (!input || typeof input.sessionId !== "string" || !input.sessionId.length || input.sessionId.length > 256 || input.expectedRevision !== void 0 && (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 0)) return readFailure(startedAt, typeof input?.sessionId === "string" ? input.sessionId : "", "invalid_query");
|
|
2239
|
+
const session = this.context.sessions.get(input.sessionId);
|
|
2240
|
+
if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(input.sessionId));
|
|
2241
|
+
const meta = {
|
|
2242
|
+
sessionId: session.sessionId,
|
|
2243
|
+
revision: session.revision
|
|
2244
|
+
};
|
|
2245
|
+
if (input.expectedRevision !== void 0 && input.expectedRevision !== session.revision) return failure("read", startedAt, {
|
|
2246
|
+
code: "stale_read",
|
|
2247
|
+
sessionId: session.sessionId,
|
|
2248
|
+
expectedRevision: input.expectedRevision,
|
|
2249
|
+
actualRevision: session.revision,
|
|
2250
|
+
message: "The session edit revision changed. Restart the model and resource read."
|
|
2251
|
+
}, void 0, meta);
|
|
2252
|
+
return success("read", startedAt, session, meta);
|
|
2253
|
+
}
|
|
2254
|
+
readSessionState(input) {
|
|
2255
|
+
const startedAt = Date.now();
|
|
2256
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2257
|
+
if (!resolved.ok) return resolved;
|
|
2258
|
+
const session = resolved.data;
|
|
2259
|
+
const meta = {
|
|
2260
|
+
sessionId: session.sessionId,
|
|
2261
|
+
revision: session.revision
|
|
2262
|
+
};
|
|
2263
|
+
const data = {
|
|
2264
|
+
...meta,
|
|
2265
|
+
dirty: session.dirty,
|
|
2266
|
+
lastSavedRevision: session.lastSavedRevision,
|
|
2267
|
+
uamFidelity: session.uamFidelity,
|
|
2268
|
+
readComplete: session.readComplete,
|
|
2269
|
+
readDiagnostics: session.readDiagnostics,
|
|
2270
|
+
project: {
|
|
2271
|
+
...session.project,
|
|
2272
|
+
packages: session.project.packages.map((pkg) => ({
|
|
2273
|
+
...pkg,
|
|
2274
|
+
resources: pkg.resources.map((resource) => {
|
|
2275
|
+
if (resource.kind === "component") return resource;
|
|
2276
|
+
const { sourceBytes: _sourceBytes, ...model } = resource;
|
|
2277
|
+
return model;
|
|
2278
|
+
})
|
|
2279
|
+
}))
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
const problem = queryResponseProblem(data, BACKEND_SESSION_READ_LIMITS.model);
|
|
2283
|
+
return problem ? readFailure(startedAt, session.sessionId, problem, session.revision) : success("read", startedAt, structuredClone(data), meta);
|
|
2284
|
+
}
|
|
2285
|
+
readResourceBytes(input) {
|
|
2286
|
+
const startedAt = Date.now();
|
|
2287
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2288
|
+
if (!resolved.ok) return resolved;
|
|
2289
|
+
const session = resolved.data;
|
|
2290
|
+
const reject = (reason) => readFailure(startedAt, session.sessionId, reason, session.revision);
|
|
2291
|
+
const selector = input.selector;
|
|
2292
|
+
if (input.expectedRevision === void 0 || !selector || typeof selector !== "object" || Array.isArray(selector) || Object.keys(selector).length !== 2 || ["packageId", "resourceId"].some((key) => !Object.hasOwn(selector, key)) || [selector.packageId, selector.resourceId].some((value) => typeof value !== "string" || !value.length || value.length > 256)) return reject("invalid_query");
|
|
2293
|
+
const packages = session.project.packages.filter((pkg) => pkg.id === selector.packageId);
|
|
2294
|
+
if (packages.length !== 1) return reject(packages.length ? "ambiguous" : "not_found");
|
|
2295
|
+
const resources = packages[0].resources.filter((resource) => resource.id === selector.resourceId);
|
|
2296
|
+
if (resources.length !== 1) return reject(resources.length ? "ambiguous" : "not_found");
|
|
2297
|
+
const resource = resources[0];
|
|
2298
|
+
if (resource.kind === "component") return reject("unsupported_resource");
|
|
2299
|
+
if (!(resource.sourceBytes instanceof Uint8Array)) return reject("bytes_unavailable");
|
|
2300
|
+
if (resource.sourceBytes.byteLength > BACKEND_SESSION_READ_LIMITS.resourceBytes) return reject("response_budget_exceeded");
|
|
2301
|
+
const meta = {
|
|
2302
|
+
sessionId: session.sessionId,
|
|
2303
|
+
revision: session.revision
|
|
2304
|
+
};
|
|
2305
|
+
return success("read", startedAt, {
|
|
2306
|
+
...meta,
|
|
2307
|
+
selector: { ...selector },
|
|
2308
|
+
sourceBytes: new Uint8Array(resource.sourceBytes)
|
|
2309
|
+
}, meta);
|
|
2310
|
+
}
|
|
2202
2311
|
validateSession(input) {
|
|
2203
2312
|
const startedAt = Date.now();
|
|
2204
2313
|
const session = this.context.sessions.get(input.sessionId);
|
|
@@ -2509,6 +2618,8 @@ const BACKEND_METHODS = [
|
|
|
2509
2618
|
"getSession",
|
|
2510
2619
|
"getProjectOutline",
|
|
2511
2620
|
"queryEntity",
|
|
2621
|
+
"readSessionState",
|
|
2622
|
+
"readResourceBytes",
|
|
2512
2623
|
"validateSession",
|
|
2513
2624
|
"preflightTransaction",
|
|
2514
2625
|
"applyTransaction",
|
|
@@ -2532,7 +2643,7 @@ const ARTIFACT_BRIDGE_CAPABILITY = {
|
|
|
2532
2643
|
function createCapabilities(atomicSave = false) {
|
|
2533
2644
|
return {
|
|
2534
2645
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
2535
|
-
capabilitySchemaVersion:
|
|
2646
|
+
capabilitySchemaVersion: 11,
|
|
2536
2647
|
transactionKernelOwner: "@openfairygui/core",
|
|
2537
2648
|
appSeamOwner: "@openfairygui/functions",
|
|
2538
2649
|
runtimeOwner: "@openfairygui/backend",
|
|
@@ -2555,6 +2666,15 @@ function createCapabilities(atomicSave = false) {
|
|
|
2555
2666
|
sourceBytes: false,
|
|
2556
2667
|
limits: BACKEND_ENTITY_QUERY_LIMITS
|
|
2557
2668
|
},
|
|
2669
|
+
sessionState: {
|
|
2670
|
+
sourceBytes: false,
|
|
2671
|
+
limits: BACKEND_SESSION_READ_LIMITS.model
|
|
2672
|
+
},
|
|
2673
|
+
resourceBytes: {
|
|
2674
|
+
expectedRevisionRequired: true,
|
|
2675
|
+
hydration: false,
|
|
2676
|
+
maxBytes: BACKEND_SESSION_READ_LIMITS.resourceBytes
|
|
2677
|
+
},
|
|
2558
2678
|
projectValidation: true
|
|
2559
2679
|
},
|
|
2560
2680
|
authoring: {
|
|
@@ -2719,6 +2839,12 @@ var BackendRuntime = class {
|
|
|
2719
2839
|
queryEntity(input) {
|
|
2720
2840
|
return this.readService.queryEntity(input);
|
|
2721
2841
|
}
|
|
2842
|
+
readSessionState(input) {
|
|
2843
|
+
return this.readService.readSessionState(input);
|
|
2844
|
+
}
|
|
2845
|
+
readResourceBytes(input) {
|
|
2846
|
+
return this.readService.readResourceBytes(input);
|
|
2847
|
+
}
|
|
2722
2848
|
validateSession(input) {
|
|
2723
2849
|
return this.readService.validateSession(input);
|
|
2724
2850
|
}
|
package/docs/workflow.md
CHANGED
|
@@ -30,6 +30,16 @@ updateProjectSettings and updatePackageSettings replace complete settings snapsh
|
|
|
30
30
|
|
|
31
31
|
updateController and updateTransition replace complete snapshots, not partial patches. Copy the queried entity.properties, change only the requested fields, preserve page IDs/remarks/actions, item order/targets, settings and references, and submit the original selector with the queried revision. A stale_write requires refreshing and replanning the full snapshot for all these replacement operations. Querying does not validate references or grant permission to edit them.
|
|
32
32
|
|
|
33
|
+
## Consume the committed session state
|
|
34
|
+
|
|
35
|
+
For complete public UAM consumption, use readSessionState({sessionId, expectedRevision?}); use queryEntity for targeted properties. The detached model excludes only asset resources' primary sourceBytes, retaining sourcePath and JSON extensions. It includes revision, dirty, lastSavedRevision, readComplete, readDiagnostics and uamFidelity. Only this read-model output schema accepts unnamed object fields; transaction input contracts remain unchanged.
|
|
36
|
+
|
|
37
|
+
Read each asset with readResourceBytes({sessionId, expectedRevision: state.revision, selector:{packageId,resourceId}}). Bytes are detached Uint8Array values in the SDK and integer arrays in MCP, limited to the primary file already held in memory. There is no disk hydration or auxiliary-file discovery. Components are unsupported; unavailable bytes produce session_read_failed with reason bytes_unavailable.
|
|
38
|
+
|
|
39
|
+
On stale_read, discard the incomplete model/bytes collection and restart from readSessionState. Reads do not wait for uncommitted transactions, retain historical versions, or reserve revisions. Saving can update sourcePath and dirty without increasing the edit revision; the same revision does not identify permanently identical complete UAM. Completeness/fidelity flags preserve existing meaning and do not guarantee bytes, rendering or saving. Preserve failed reads as failures; never save or repair merely to obtain a read.
|
|
40
|
+
|
|
41
|
+
Capabilities advertise a 4 MiB compact JSON data limit (depth 64, 500000 nodes) for the model and 1 MiB per primary resource. Both new MCP tools additionally limit the complete JSON CallToolResult, including compact text and structuredContent, to 16 MiB; excess returns mcp_response_budget_exceeded. Native model/buffer overflow returns session_read_failed with reason response_budget_exceeded, without truncation. Read the installed methods/readSessionState and methods/readResourceBytes schemas for precise inputs, results and errors.
|
|
42
|
+
|
|
33
43
|
## Diagnose without repair
|
|
34
44
|
|
|
35
45
|
`ofgui doctor --json` checks installed CLI/documentation versions, the Node Backend capability snapshot, in-memory Sharp PNG/JPEG encoding and pixel decoding, and temporary-directory access flags. `ofgui doctor <project-directory-or-fairy-file> --json` additionally runs existing Node project validation, including source reads and available image decoding. Optional `--output-dir <directory>` checks an explicit destination or its nearest existing ancestor, without creating it. Directory checks return the absolute requested `path`, link-resolved `inspectedPath` and `exists` (null when unknown); files, dangling links and access errors fail. The temporary directory must exist. It opens no Backend session, creates no lock, installs nothing, writes no probe files and changes no configuration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfairygui/backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.1",
|
|
4
4
|
"description": "FairyGUI Headless Authoring SDK — stateful backend runtime and session services.",
|
|
5
5
|
"author": "OpenFairyGUI Contributors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"runtime"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@openfairygui/
|
|
70
|
-
"@openfairygui/
|
|
69
|
+
"@openfairygui/core": "0.5.0-alpha.1",
|
|
70
|
+
"@openfairygui/functions": "0.5.0-alpha.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"ava": "^7.0.0",
|
package/src/contracts.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { UamTransactionSupportIssueCode } from '@openfairygui/core/uam';
|
|
|
3
3
|
import type { BackendError } from './runtime.js';
|
|
4
4
|
|
|
5
5
|
export const BACKEND_CONTRACT_VERSION = '2.0.0-p2' as const;
|
|
6
|
-
export const BACKEND_CAPABILITY_SCHEMA_VERSION =
|
|
6
|
+
export const BACKEND_CAPABILITY_SCHEMA_VERSION = 11 as const;
|
|
7
7
|
export const BACKEND_COMPATIBILITY_POLICY = {
|
|
8
8
|
incompatibleChange: 'requires contractVersion bump',
|
|
9
9
|
capabilitySchemaChange: 'requires capabilitySchemaVersion bump',
|
package/src/diagnostics.ts
CHANGED
|
@@ -33,6 +33,14 @@ const job = { kind: 'host-action', message: "Inspect the job ID and status with
|
|
|
33
33
|
|
|
34
34
|
/** Exhaustiveness and exact ownership are checked against the canonical unions. */
|
|
35
35
|
export const BACKEND_DIAGNOSTIC_GUIDES = [
|
|
36
|
+
{ code: 'stale_read', owners: ['backend'], remediation: {
|
|
37
|
+
kind: 'refresh-and-replan',
|
|
38
|
+
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.',
|
|
39
|
+
} },
|
|
40
|
+
{ code: 'session_read_failed', owners: ['backend'], remediation: {
|
|
41
|
+
kind: 'host-action',
|
|
42
|
+
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.',
|
|
43
|
+
} },
|
|
36
44
|
{ code: 'transaction_preview_failed', owners: ['backend'], remediation: {
|
|
37
45
|
kind: 'host-action',
|
|
38
46
|
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.',
|