@openfairygui/backend 0.2.0-alpha.0 → 0.2.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.
@@ -0,0 +1,1192 @@
1
+ import { ProjectReader, ProjectWriter, UAM_SUPPORTED_MATERIALIZATION_SCOPE, liftDocumentToUamProject, materializeUamProject, normalizeUamProject } from "@openfairygui/core";
2
+ import { applyUamTransactionApp } from "@openfairygui/functions";
3
+ //#region src/contracts.ts
4
+ const BACKEND_CONTRACT_VERSION = "1.1.0-p2";
5
+ const BACKEND_CAPABILITY_SCHEMA_VERSION = 2;
6
+ const BACKEND_COMPATIBILITY_POLICY = {
7
+ incompatibleChange: "requires contractVersion bump",
8
+ capabilitySchemaChange: "requires capabilitySchemaVersion bump",
9
+ additiveChange: "allowed without breaking existing consumers"
10
+ };
11
+ //#endregion
12
+ //#region src/path-policy.ts
13
+ function normalizeComparablePath(value) {
14
+ const normalized = value.replace(/[/\\]+$/, "").replace(/\\/g, "/");
15
+ const driveMatch = normalized.match(/^([a-z]:)(?:\/(.*))?$/i);
16
+ const drivePrefix = driveMatch?.[1].toLowerCase() ?? "";
17
+ const remainder = driveMatch ? driveMatch[2] ?? "" : normalized;
18
+ const hasRoot = driveMatch ? true : remainder.startsWith("/");
19
+ const rawSegments = remainder.split("/").filter((segment) => segment.length > 0);
20
+ const segments = [];
21
+ for (const segment of rawSegments) {
22
+ if (segment === ".") continue;
23
+ if (segment === "..") {
24
+ if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
25
+ else if (!hasRoot) segments.push("..");
26
+ continue;
27
+ }
28
+ segments.push(segment);
29
+ }
30
+ const joined = segments.join("/");
31
+ return (drivePrefix ? `${drivePrefix}/${joined}`.replace(/\/$/, "") : hasRoot ? `/${joined}`.replace(/\/$/, "") : joined || ".").toLowerCase();
32
+ }
33
+ function createRuntimePathPolicy() {
34
+ return {
35
+ canonicalization: "realpath+normalized-casefold",
36
+ sessionIdentity: "project-root",
37
+ saveTarget: "opened-project-only",
38
+ outputTargets: "deferred",
39
+ workspaceBoundary: "project-root-only"
40
+ };
41
+ }
42
+ async function resolveFairyPath(fileSystem, input) {
43
+ const resolvedInput = fileSystem.resolve(input);
44
+ const stat = await fileSystem.stat(resolvedInput);
45
+ if (stat.isFile() && resolvedInput.endsWith(".fairy")) return await fileSystem.resolvePath(resolvedInput);
46
+ if (stat.isDirectory()) {
47
+ const fairyFiles = (await fileSystem.readdir(resolvedInput)).filter((entry) => entry.endsWith(".fairy"));
48
+ if (fairyFiles.length === 1) return await fileSystem.resolvePath(fileSystem.join(resolvedInput, fairyFiles[0]));
49
+ if (fairyFiles.length > 1) throw new Error(`Multiple .fairy files found in ${resolvedInput}: ${fairyFiles.join(", ")}`);
50
+ throw new Error(`No .fairy file found in ${resolvedInput}`);
51
+ }
52
+ throw new Error(`Input is not a .fairy file or directory: ${resolvedInput}`);
53
+ }
54
+ async function resolveCanonicalProjectRoot(fileSystem, input) {
55
+ const fairyPath = await resolveFairyPath(fileSystem, input);
56
+ const canonicalProjectPath = await fileSystem.resolvePath(fileSystem.dirname(fairyPath));
57
+ return {
58
+ fairyPath,
59
+ canonicalProjectPath,
60
+ canonicalPathKey: normalizeComparablePath(canonicalProjectPath)
61
+ };
62
+ }
63
+ async function validateSaveTarget(fileSystem, openedFairyPath, targetPath) {
64
+ if (!targetPath) return null;
65
+ const attemptedPath = await fileSystem.resolvePath(fileSystem.resolve(targetPath));
66
+ const allowedPath = await fileSystem.resolvePath(openedFairyPath);
67
+ if (normalizeComparablePath(attemptedPath) === normalizeComparablePath(allowedPath)) return null;
68
+ return {
69
+ code: "path_policy_violation",
70
+ message: `Save target is restricted to the originally opened project file: ${allowedPath}`,
71
+ policy: "save_target",
72
+ attemptedPath,
73
+ allowedPath
74
+ };
75
+ }
76
+ //#endregion
77
+ //#region src/services/artifact-service.ts
78
+ function createArtifactCapabilities() {
79
+ const bridge = {
80
+ available: false,
81
+ requiredHost: "node",
82
+ executionBoundary: "external-bridge",
83
+ bridgeEntrypoint: "@openfairygui/backend/node",
84
+ reason: "publish/restore require explicit Node-hosted filesystem and artifact execution."
85
+ };
86
+ return {
87
+ publish: false,
88
+ restore: false,
89
+ status: "bridge-required",
90
+ publishBridge: bridge,
91
+ restoreBridge: bridge
92
+ };
93
+ }
94
+ //#endregion
95
+ //#region src/services/context.ts
96
+ function diagnosticFromError(error) {
97
+ return {
98
+ code: error.code,
99
+ message: error.message,
100
+ severity: "error"
101
+ };
102
+ }
103
+ function randomId$1() {
104
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
105
+ }
106
+ function createMeta(stage, startedAt, options) {
107
+ return {
108
+ requestId: options?.requestId ?? randomId$1(),
109
+ sessionId: options?.sessionId,
110
+ revision: options?.revision,
111
+ durationMs: Math.max(0, Date.now() - startedAt),
112
+ warnings: options?.warnings ?? [],
113
+ diagnostics: options?.diagnostics ?? [],
114
+ stage,
115
+ contractVersion: BACKEND_CONTRACT_VERSION,
116
+ capabilitySchemaVersion: 2
117
+ };
118
+ }
119
+ function success(stage, startedAt, data, options) {
120
+ return {
121
+ ok: true,
122
+ meta: createMeta(stage, startedAt, options),
123
+ data
124
+ };
125
+ }
126
+ function failure(stage, startedAt, error, session, options) {
127
+ const diagnostics = options?.diagnostics ?? [diagnosticFromError(error)];
128
+ return {
129
+ ok: false,
130
+ meta: createMeta(stage, startedAt, {
131
+ ...options,
132
+ diagnostics
133
+ }),
134
+ error,
135
+ session
136
+ };
137
+ }
138
+ //#endregion
139
+ //#region src/services/snapshot-utils.ts
140
+ function cloneJsonValue(value) {
141
+ if (value === void 0 || value === null) return value;
142
+ return JSON.parse(JSON.stringify(value));
143
+ }
144
+ function cloneEventSnapshot(event) {
145
+ return {
146
+ ...event,
147
+ diagnostics: event.diagnostics.map((diagnostic) => ({ ...diagnostic })),
148
+ payload: cloneJsonValue(event.payload)
149
+ };
150
+ }
151
+ function cloneJobSnapshot(job) {
152
+ return {
153
+ ...job,
154
+ diagnostics: job.diagnostics.map((diagnostic) => ({ ...diagnostic })),
155
+ progress: job.progress ? { ...job.progress } : void 0,
156
+ result: cloneJsonValue(job.result),
157
+ error: cloneJsonValue(job.error)
158
+ };
159
+ }
160
+ function cloneCacheEntrySnapshot(entry) {
161
+ return {
162
+ ...entry,
163
+ summary: {
164
+ ...entry.summary,
165
+ diagnostics: entry.summary.diagnostics.map((diagnostic) => ({ ...diagnostic }))
166
+ }
167
+ };
168
+ }
169
+ function cloneCapabilitiesSnapshot(capabilities) {
170
+ return cloneJsonValue(capabilities);
171
+ }
172
+ //#endregion
173
+ //#region src/services/session-utils.ts
174
+ function toSessionSnapshot(session, capabilities) {
175
+ return {
176
+ sessionId: session.sessionId,
177
+ canonicalProjectPath: session.canonicalProjectPath,
178
+ revision: session.revision,
179
+ lastSavedRevision: session.lastSavedRevision,
180
+ dirty: session.dirty,
181
+ lockHeld: session.lockHeld,
182
+ capabilities: cloneCapabilitiesSnapshot(capabilities)
183
+ };
184
+ }
185
+ function createSessionNotFoundError(sessionId) {
186
+ return {
187
+ code: "session_not_found",
188
+ message: `Session was not found: ${sessionId}`,
189
+ sessionId
190
+ };
191
+ }
192
+ function createStaleWriteError(session, expectedRevision) {
193
+ return {
194
+ code: "stale_write",
195
+ message: `Expected revision ${expectedRevision} does not match current revision ${session.revision}.`,
196
+ sessionId: session.sessionId,
197
+ canonicalPathKey: session.canonicalPathKey,
198
+ expectedRevision,
199
+ actualRevision: session.revision
200
+ };
201
+ }
202
+ //#endregion
203
+ //#region src/services/authoring-service.ts
204
+ function createWriterFileSystem(fileSystem, committedPaths, failedPaths) {
205
+ async function trackWrite(targetPath, fn) {
206
+ try {
207
+ const result = await fn();
208
+ committedPaths.push(targetPath);
209
+ return result;
210
+ } catch (error) {
211
+ failedPaths.push(targetPath);
212
+ throw error;
213
+ }
214
+ }
215
+ return {
216
+ async readFile(filePath) {
217
+ return fileSystem.readFile(filePath);
218
+ },
219
+ async readFileRaw(filePath) {
220
+ return fileSystem.readFileRaw(filePath);
221
+ },
222
+ async writeFile(filePath, content) {
223
+ await trackWrite(filePath, async () => {
224
+ await fileSystem.mkdir(fileSystem.dirname(filePath), { recursive: true });
225
+ await fileSystem.writeFile(filePath, content);
226
+ });
227
+ },
228
+ async writeFileRaw(filePath, data) {
229
+ await trackWrite(filePath, async () => {
230
+ await fileSystem.mkdir(fileSystem.dirname(filePath), { recursive: true });
231
+ await fileSystem.writeFileRaw(filePath, data);
232
+ });
233
+ },
234
+ async mkdir(dirPath) {
235
+ await fileSystem.mkdir(dirPath, { recursive: true });
236
+ },
237
+ async readdir(dirPath) {
238
+ return fileSystem.readdir(dirPath);
239
+ },
240
+ async exists(filePath) {
241
+ try {
242
+ await fileSystem.stat(filePath);
243
+ return true;
244
+ } catch {
245
+ return false;
246
+ }
247
+ },
248
+ join(...paths) {
249
+ return fileSystem.join(...paths);
250
+ },
251
+ dirname(filePath) {
252
+ return fileSystem.dirname(filePath);
253
+ }
254
+ };
255
+ }
256
+ var AuthoringService = class {
257
+ constructor(context, cacheService, eventService) {
258
+ this.context = context;
259
+ this.cacheService = cacheService;
260
+ this.eventService = eventService;
261
+ }
262
+ async applyTransaction(input) {
263
+ const startedAt = Date.now();
264
+ const session = this.context.sessions.get(input.sessionId);
265
+ if (!session || session.closed) return failure("authoring", startedAt, createSessionNotFoundError(input.sessionId));
266
+ if (input.expectedRevision !== session.revision) {
267
+ this.eventService.emit({
268
+ kind: "transaction.rejected",
269
+ sessionId: session.sessionId,
270
+ canonicalPathKey: session.canonicalPathKey,
271
+ revision: session.revision
272
+ });
273
+ return failure("authoring", startedAt, createStaleWriteError(session, input.expectedRevision), toSessionSnapshot(session, this.context.capabilities), {
274
+ sessionId: session.sessionId,
275
+ revision: session.revision
276
+ });
277
+ }
278
+ const result = applyUamTransactionApp({
279
+ project: session.project,
280
+ operations: input.operations
281
+ });
282
+ if (result.ok === false) {
283
+ this.eventService.emit({
284
+ kind: "transaction.rejected",
285
+ sessionId: session.sessionId,
286
+ canonicalPathKey: session.canonicalPathKey,
287
+ revision: session.revision,
288
+ diagnostics: result.error.issues?.map((issue) => ({
289
+ code: result.error.code,
290
+ message: issue.message,
291
+ severity: "error"
292
+ })) ?? []
293
+ });
294
+ return failure("authoring", startedAt, result.error, toSessionSnapshot(session, this.context.capabilities), {
295
+ sessionId: session.sessionId,
296
+ revision: session.revision
297
+ });
298
+ }
299
+ session.project = result.project;
300
+ session.revision += 1;
301
+ session.dirty = true;
302
+ const cacheEntry = this.cacheService.invalidateSession(session);
303
+ this.eventService.emit({
304
+ kind: "transaction.applied",
305
+ sessionId: session.sessionId,
306
+ canonicalPathKey: session.canonicalPathKey,
307
+ revision: session.revision
308
+ });
309
+ this.eventService.emit({
310
+ kind: "cache.invalidated",
311
+ sessionId: session.sessionId,
312
+ canonicalPathKey: session.canonicalPathKey,
313
+ revision: session.revision,
314
+ cacheRevision: cacheEntry.revision
315
+ });
316
+ return success("authoring", startedAt, toSessionSnapshot(session, this.context.capabilities), {
317
+ sessionId: session.sessionId,
318
+ revision: session.revision
319
+ });
320
+ }
321
+ async saveSession(input) {
322
+ const startedAt = Date.now();
323
+ const session = this.context.sessions.get(input.sessionId);
324
+ if (!session || session.closed) return failure("authoring", startedAt, createSessionNotFoundError(input.sessionId));
325
+ if (!this.context.fileSystem) return failure("authoring", startedAt, {
326
+ code: "capability_unavailable",
327
+ message: "saveSession requires an injected BackendFileSystem adapter.",
328
+ capability: "fileSystem",
329
+ requiredAdapter: "BackendFileSystem"
330
+ }, toSessionSnapshot(session, this.context.capabilities), {
331
+ sessionId: session.sessionId,
332
+ revision: session.revision
333
+ });
334
+ if (input.expectedRevision !== void 0 && input.expectedRevision !== session.revision) return failure("authoring", startedAt, createStaleWriteError(session, input.expectedRevision), toSessionSnapshot(session, this.context.capabilities), {
335
+ sessionId: session.sessionId,
336
+ revision: session.revision
337
+ });
338
+ const fileSystem = this.context.fileSystem;
339
+ const targetViolation = await validateSaveTarget(fileSystem, session.fairyPath, input.targetPath);
340
+ if (targetViolation) return failure("authoring", startedAt, targetViolation, toSessionSnapshot(session, this.context.capabilities), {
341
+ sessionId: session.sessionId,
342
+ revision: session.revision
343
+ });
344
+ if (!session.dirty) return success("authoring", startedAt, toSessionSnapshot(session, this.context.capabilities), {
345
+ sessionId: session.sessionId,
346
+ revision: session.revision
347
+ });
348
+ const committedPaths = [];
349
+ const failedPaths = [];
350
+ this.eventService.emit({
351
+ kind: "save.started",
352
+ sessionId: session.sessionId,
353
+ canonicalPathKey: session.canonicalPathKey,
354
+ revision: session.revision
355
+ });
356
+ try {
357
+ await new ProjectWriter(createWriterFileSystem(fileSystem, committedPaths, failedPaths)).write(materializeUamProject(session.project), session.fairyPath);
358
+ session.lastSavedRevision = session.revision;
359
+ session.dirty = false;
360
+ const cacheEntry = this.cacheService.refreshSession(session);
361
+ this.eventService.emit({
362
+ kind: "save.completed",
363
+ sessionId: session.sessionId,
364
+ canonicalPathKey: session.canonicalPathKey,
365
+ revision: session.revision
366
+ });
367
+ this.eventService.emit({
368
+ kind: "cache.updated",
369
+ sessionId: session.sessionId,
370
+ canonicalPathKey: session.canonicalPathKey,
371
+ revision: session.revision,
372
+ cacheRevision: cacheEntry.revision
373
+ });
374
+ return success("authoring", startedAt, toSessionSnapshot(session, this.context.capabilities), {
375
+ sessionId: session.sessionId,
376
+ revision: session.revision
377
+ });
378
+ } catch (error) {
379
+ this.cacheService.invalidateSession(session);
380
+ this.eventService.emit({
381
+ kind: "save.failed",
382
+ sessionId: session.sessionId,
383
+ canonicalPathKey: session.canonicalPathKey,
384
+ revision: session.revision
385
+ });
386
+ return failure("authoring", startedAt, {
387
+ code: "save_partial_failure",
388
+ message: error instanceof Error ? error.message : String(error),
389
+ sessionId: session.sessionId,
390
+ canonicalPathKey: session.canonicalPathKey,
391
+ attemptedRevision: session.revision,
392
+ lastSavedRevision: session.lastSavedRevision,
393
+ committedPaths,
394
+ failedPaths,
395
+ diskMayBePartiallyUpdated: true
396
+ }, toSessionSnapshot(session, this.context.capabilities), {
397
+ sessionId: session.sessionId,
398
+ revision: session.revision
399
+ });
400
+ }
401
+ }
402
+ };
403
+ //#endregion
404
+ //#region src/services/cache-service.ts
405
+ function createCacheEntry(session, valid) {
406
+ return {
407
+ canonicalPathKey: session.canonicalPathKey,
408
+ sessionId: session.sessionId,
409
+ revision: session.revision,
410
+ lastSavedRevision: session.lastSavedRevision,
411
+ dirty: session.dirty,
412
+ valid,
413
+ indexedAt: (/* @__PURE__ */ new Date()).toISOString(),
414
+ summary: {
415
+ packageCount: session.project.packages.length,
416
+ resourceCount: session.project.packages.reduce((total, pkg) => total + pkg.resources.length, 0),
417
+ diagnostics: []
418
+ }
419
+ };
420
+ }
421
+ var CacheService = class {
422
+ constructor(context) {
423
+ this.context = context;
424
+ }
425
+ getCacheSnapshot(input) {
426
+ const startedAt = Date.now();
427
+ const session = this.context.sessions.get(input.sessionId);
428
+ if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(input.sessionId));
429
+ const entry = this.context.cacheBySession.get(input.sessionId);
430
+ return success("read", startedAt, {
431
+ cacheRevision: entry?.revision ?? session.revision,
432
+ entries: entry ? [cloneCacheEntrySnapshot(entry)] : []
433
+ }, {
434
+ sessionId: session.sessionId,
435
+ revision: session.revision
436
+ });
437
+ }
438
+ refreshSession(session) {
439
+ const entry = createCacheEntry(session, true);
440
+ this.context.cacheBySession.set(session.sessionId, entry);
441
+ return entry;
442
+ }
443
+ invalidateSession(session) {
444
+ const entry = createCacheEntry(session, false);
445
+ this.context.cacheBySession.set(session.sessionId, entry);
446
+ return entry;
447
+ }
448
+ removeSession(sessionId) {
449
+ this.context.cacheBySession.delete(sessionId);
450
+ }
451
+ };
452
+ //#endregion
453
+ //#region src/services/event-service.ts
454
+ const DEFAULT_EVENT_RETENTION_LIMIT = 1e3;
455
+ var EventService = class {
456
+ constructor(context) {
457
+ this.context = context;
458
+ }
459
+ emit(event) {
460
+ const emitted = {
461
+ ...event,
462
+ sequence: this.context.nextEventSequence(),
463
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
464
+ diagnostics: event.diagnostics ?? []
465
+ };
466
+ const sessionId = event.sessionId;
467
+ if (!sessionId) return emitted;
468
+ const events = this.context.eventsBySession.get(sessionId) ?? [];
469
+ events.push(emitted);
470
+ while (events.length > DEFAULT_EVENT_RETENTION_LIMIT) events.shift();
471
+ this.context.eventsBySession.set(sessionId, events);
472
+ return emitted;
473
+ }
474
+ getEvents(input) {
475
+ const startedAt = Date.now();
476
+ const session = this.context.sessions.get(input.sessionId);
477
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
478
+ const events = this.context.eventsBySession.get(input.sessionId) ?? [];
479
+ const oldestSequence = events[0]?.sequence ?? (events.length === 0 ? 1 : 0);
480
+ const currentSequence = events.at(-1)?.sequence ?? 0;
481
+ const after = input.after === void 0 ? 0 : Number(input.after);
482
+ if (!Number.isInteger(after) || after < 0) return failure("runtime", startedAt, {
483
+ code: "event_cursor_invalid",
484
+ message: `Invalid event cursor: ${input.after}`,
485
+ sessionId: input.sessionId,
486
+ after: String(input.after)
487
+ });
488
+ if (events.length > 0 && after !== 0 && after < oldestSequence - 1) return failure("runtime", startedAt, {
489
+ code: "event_cursor_invalid",
490
+ message: `Event cursor has expired: ${after}`,
491
+ sessionId: input.sessionId,
492
+ after: String(input.after)
493
+ });
494
+ if (after > currentSequence) return failure("runtime", startedAt, {
495
+ code: "event_cursor_invalid",
496
+ message: `Unknown event cursor: ${after}`,
497
+ sessionId: input.sessionId,
498
+ after: String(input.after)
499
+ });
500
+ const filtered = events.filter((event) => event.sequence > after);
501
+ const limit = input.limit === void 0 ? filtered.length : Math.max(0, input.limit);
502
+ return success("runtime", startedAt, {
503
+ events: filtered.slice(0, limit).map(cloneEventSnapshot),
504
+ oldestSequence,
505
+ currentSequence,
506
+ cursorExpired: false
507
+ }, {
508
+ sessionId: session.sessionId,
509
+ revision: session.revision
510
+ });
511
+ }
512
+ removeSession(sessionId) {
513
+ this.context.eventsBySession.delete(sessionId);
514
+ }
515
+ };
516
+ //#endregion
517
+ //#region src/services/job-service.ts
518
+ const COMPLETED_JOB_RETENTION_LIMIT = 100;
519
+ const REFRESH_START_DELAY_MS = 0;
520
+ const REFRESH_COMPLETE_DELAY_MS = 50;
521
+ function isTerminal(status) {
522
+ return status === "completed" || status === "failed" || status === "cancelled";
523
+ }
524
+ var JobService = class {
525
+ constructor(context, cacheService, eventService) {
526
+ this.context = context;
527
+ this.cacheService = cacheService;
528
+ this.eventService = eventService;
529
+ }
530
+ cancellationRequests = /* @__PURE__ */ new Set();
531
+ getJobs(sessionId) {
532
+ return this.context.jobsBySession.get(sessionId) ?? [];
533
+ }
534
+ setJobs(sessionId, jobs) {
535
+ const retained = [];
536
+ let terminalCount = 0;
537
+ for (let index = jobs.length - 1; index >= 0; index -= 1) {
538
+ const job = jobs[index];
539
+ if (isTerminal(job.status)) {
540
+ if (terminalCount >= COMPLETED_JOB_RETENTION_LIMIT) continue;
541
+ terminalCount += 1;
542
+ }
543
+ retained.push(job);
544
+ }
545
+ this.context.jobsBySession.set(sessionId, retained.reverse());
546
+ }
547
+ refreshCache(input) {
548
+ const startedAt = Date.now();
549
+ const session = this.context.sessions.get(input.sessionId);
550
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
551
+ const jobId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
552
+ const job = {
553
+ jobId,
554
+ kind: "cache.refresh",
555
+ status: "queued",
556
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
557
+ sessionId: session.sessionId,
558
+ canonicalPathKey: session.canonicalPathKey,
559
+ revision: session.revision,
560
+ diagnostics: [],
561
+ progress: {
562
+ completed: 0,
563
+ total: 1,
564
+ message: input.reason ?? "manual"
565
+ }
566
+ };
567
+ const jobs = this.getJobs(session.sessionId);
568
+ jobs.push(job);
569
+ this.setJobs(session.sessionId, jobs);
570
+ this.eventService.emit({
571
+ kind: "job.created",
572
+ sessionId: session.sessionId,
573
+ canonicalPathKey: session.canonicalPathKey,
574
+ revision: session.revision,
575
+ jobId
576
+ });
577
+ this.scheduleRefreshJob(session.sessionId, jobId);
578
+ return success("runtime", startedAt, cloneJobSnapshot(job), {
579
+ sessionId: session.sessionId,
580
+ revision: session.revision
581
+ });
582
+ }
583
+ getJob(input) {
584
+ const startedAt = Date.now();
585
+ const session = this.context.sessions.get(input.sessionId);
586
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
587
+ const job = this.getJobs(input.sessionId).find((item) => item.jobId === input.jobId);
588
+ if (!job) return failure("runtime", startedAt, {
589
+ code: "job_not_found",
590
+ message: `Job was not found: ${input.jobId}`,
591
+ sessionId: input.sessionId,
592
+ jobId: input.jobId
593
+ }, void 0, {
594
+ sessionId: session.sessionId,
595
+ revision: session.revision
596
+ });
597
+ return success("runtime", startedAt, cloneJobSnapshot(job), {
598
+ sessionId: session.sessionId,
599
+ revision: session.revision
600
+ });
601
+ }
602
+ listJobs(input) {
603
+ const startedAt = Date.now();
604
+ const session = this.context.sessions.get(input.sessionId);
605
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
606
+ let jobs = [...this.getJobs(input.sessionId)];
607
+ if (input.kind) jobs = jobs.filter((job) => job.kind === input.kind);
608
+ if (input.status) if (input.status === "active") jobs = jobs.filter((job) => !isTerminal(job.status));
609
+ else if (input.status === "terminal") jobs = jobs.filter((job) => isTerminal(job.status));
610
+ else jobs = jobs.filter((job) => job.status === input.status);
611
+ if (input.limit !== void 0) jobs = jobs.slice(0, Math.max(0, input.limit));
612
+ return success("runtime", startedAt, { jobs: jobs.map(cloneJobSnapshot) }, {
613
+ sessionId: session.sessionId,
614
+ revision: session.revision
615
+ });
616
+ }
617
+ cancelJob(input) {
618
+ const startedAt = Date.now();
619
+ const session = this.context.sessions.get(input.sessionId);
620
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
621
+ const job = this.getJobs(input.sessionId).find((item) => item.jobId === input.jobId);
622
+ if (!job) return failure("runtime", startedAt, {
623
+ code: "job_not_found",
624
+ message: `Job was not found: ${input.jobId}`,
625
+ sessionId: input.sessionId,
626
+ jobId: input.jobId
627
+ }, void 0, {
628
+ sessionId: session.sessionId,
629
+ revision: session.revision
630
+ });
631
+ if (isTerminal(job.status)) return failure("runtime", startedAt, {
632
+ code: "job_not_cancellable",
633
+ message: `Job is already terminal: ${input.jobId}`,
634
+ sessionId: input.sessionId,
635
+ jobId: input.jobId,
636
+ status: job.status
637
+ }, void 0, {
638
+ sessionId: session.sessionId,
639
+ revision: session.revision
640
+ });
641
+ this.cancellationRequests.add(job.jobId);
642
+ this.eventService.emit({
643
+ kind: "job.cancelRequested",
644
+ sessionId: input.sessionId,
645
+ canonicalPathKey: session.canonicalPathKey,
646
+ revision: session.revision,
647
+ jobId: job.jobId
648
+ });
649
+ return success("runtime", startedAt, cloneJobSnapshot(this.cancelRefreshJob(session.sessionId, job)), {
650
+ sessionId: session.sessionId,
651
+ revision: session.revision
652
+ });
653
+ }
654
+ removeSession(sessionId) {
655
+ for (const job of this.getJobs(sessionId)) this.cancellationRequests.delete(job.jobId);
656
+ this.context.jobsBySession.delete(sessionId);
657
+ }
658
+ replaceJob(sessionId, nextJob) {
659
+ const jobs = this.getJobs(sessionId).map((job) => job.jobId === nextJob.jobId ? nextJob : job);
660
+ this.setJobs(sessionId, jobs);
661
+ }
662
+ scheduleRefreshJob(sessionId, jobId) {
663
+ setTimeout(() => this.startRefreshJob(sessionId, jobId), REFRESH_START_DELAY_MS);
664
+ }
665
+ startRefreshJob(sessionId, jobId) {
666
+ const session = this.context.sessions.get(sessionId);
667
+ if (!session || session.closed) return;
668
+ const job = this.getJobs(sessionId).find((item) => item.jobId === jobId);
669
+ if (!job || isTerminal(job.status)) return;
670
+ if (this.cancellationRequests.has(jobId)) {
671
+ this.cancelRefreshJob(sessionId, job);
672
+ return;
673
+ }
674
+ const running = {
675
+ ...job,
676
+ status: "running",
677
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
678
+ progress: {
679
+ completed: 0,
680
+ total: 1,
681
+ message: "refreshing cache"
682
+ }
683
+ };
684
+ this.replaceJob(sessionId, running);
685
+ this.eventService.emit({
686
+ kind: "job.started",
687
+ sessionId,
688
+ canonicalPathKey: session.canonicalPathKey,
689
+ revision: session.revision,
690
+ jobId
691
+ });
692
+ this.eventService.emit({
693
+ kind: "job.progress",
694
+ sessionId,
695
+ canonicalPathKey: session.canonicalPathKey,
696
+ revision: session.revision,
697
+ jobId,
698
+ payload: running.progress
699
+ });
700
+ setTimeout(() => this.completeRefreshJob(sessionId, jobId), REFRESH_COMPLETE_DELAY_MS);
701
+ }
702
+ completeRefreshJob(sessionId, jobId) {
703
+ const session = this.context.sessions.get(sessionId);
704
+ if (!session || session.closed) return;
705
+ const job = this.getJobs(sessionId).find((item) => item.jobId === jobId);
706
+ if (!job || isTerminal(job.status)) return;
707
+ if (this.cancellationRequests.has(jobId)) {
708
+ this.cancelRefreshJob(sessionId, job);
709
+ return;
710
+ }
711
+ try {
712
+ const entry = this.cacheService.refreshSession(session);
713
+ const completed = {
714
+ ...job,
715
+ status: "completed",
716
+ finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
717
+ cacheRevision: entry.revision,
718
+ progress: {
719
+ completed: 1,
720
+ total: 1,
721
+ message: "cache refreshed"
722
+ },
723
+ result: { cacheRevision: entry.revision }
724
+ };
725
+ this.replaceJob(sessionId, completed);
726
+ this.eventService.emit({
727
+ kind: "job.completed",
728
+ sessionId,
729
+ canonicalPathKey: session.canonicalPathKey,
730
+ revision: session.revision,
731
+ cacheRevision: entry.revision,
732
+ jobId
733
+ });
734
+ this.eventService.emit({
735
+ kind: "cache.updated",
736
+ sessionId,
737
+ canonicalPathKey: session.canonicalPathKey,
738
+ revision: session.revision,
739
+ cacheRevision: entry.revision
740
+ });
741
+ } catch (error) {
742
+ const failed = {
743
+ ...job,
744
+ status: "failed",
745
+ finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
746
+ error: {
747
+ code: "cache_refresh_failed",
748
+ message: error instanceof Error ? error.message : "Cache refresh failed",
749
+ sessionId,
750
+ jobId
751
+ }
752
+ };
753
+ this.replaceJob(sessionId, failed);
754
+ this.eventService.emit({
755
+ kind: "job.failed",
756
+ sessionId,
757
+ canonicalPathKey: session.canonicalPathKey,
758
+ revision: session.revision,
759
+ jobId,
760
+ diagnostics: failed.diagnostics
761
+ });
762
+ }
763
+ }
764
+ cancelRefreshJob(sessionId, job) {
765
+ const session = this.context.sessions.get(sessionId);
766
+ const cancelled = {
767
+ ...job,
768
+ status: "cancelled",
769
+ finishedAt: (/* @__PURE__ */ new Date()).toISOString(),
770
+ error: {
771
+ code: "job_cancelled",
772
+ message: `Job was cancelled: ${job.jobId}`,
773
+ sessionId,
774
+ jobId: job.jobId
775
+ }
776
+ };
777
+ this.replaceJob(sessionId, cancelled);
778
+ this.cancellationRequests.delete(job.jobId);
779
+ this.eventService.emit({
780
+ kind: "job.cancelled",
781
+ sessionId,
782
+ canonicalPathKey: session?.canonicalPathKey ?? job.canonicalPathKey,
783
+ revision: session?.revision ?? job.revision,
784
+ jobId: job.jobId
785
+ });
786
+ return cancelled;
787
+ }
788
+ };
789
+ //#endregion
790
+ //#region src/services/read-service.ts
791
+ var ReadService = class {
792
+ constructor(context) {
793
+ this.context = context;
794
+ }
795
+ getCapabilities() {
796
+ return success("read", Date.now(), cloneCapabilitiesSnapshot(this.context.capabilities));
797
+ }
798
+ getSession(input) {
799
+ const startedAt = Date.now();
800
+ const session = this.context.sessions.get(input.sessionId);
801
+ if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(input.sessionId));
802
+ return success("read", startedAt, toSessionSnapshot(session, this.context.capabilities), {
803
+ sessionId: session.sessionId,
804
+ revision: session.revision
805
+ });
806
+ }
807
+ };
808
+ //#endregion
809
+ //#region src/services/runtime-service.ts
810
+ function randomId() {
811
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
812
+ }
813
+ function createCapabilityUnavailableError(capability) {
814
+ const artifactCapability = capability === "artifact.publish" || capability === "artifact.restore";
815
+ return {
816
+ code: "capability_unavailable",
817
+ message: artifactCapability ? `${capability} requires the Node bridge boundary exposed by @openfairygui/backend/node.` : `${capability} requires an injected BackendFileSystem adapter.`,
818
+ capability,
819
+ requiredAdapter: capability === "fileSystem" ? "BackendFileSystem" : void 0,
820
+ requiredHost: artifactCapability ? "node" : void 0,
821
+ bridgeBoundary: artifactCapability ? "external-bridge" : void 0
822
+ };
823
+ }
824
+ function createProjectReaderFileSystem(fileSystem) {
825
+ return {
826
+ readFile(filePath) {
827
+ return fileSystem.readFile(filePath);
828
+ },
829
+ readFileRaw(filePath) {
830
+ return fileSystem.readFileRaw(filePath);
831
+ },
832
+ writeFile(filePath, content) {
833
+ return fileSystem.writeFile(filePath, content);
834
+ },
835
+ writeFileRaw(filePath, data) {
836
+ return fileSystem.writeFileRaw(filePath, data);
837
+ },
838
+ async mkdir(dirPath) {
839
+ await fileSystem.mkdir(dirPath, { recursive: true });
840
+ },
841
+ readdir(dirPath) {
842
+ return fileSystem.readdir(dirPath);
843
+ },
844
+ async exists(filePath) {
845
+ try {
846
+ await fileSystem.stat(filePath);
847
+ return true;
848
+ } catch {
849
+ return false;
850
+ }
851
+ },
852
+ join(...paths) {
853
+ return fileSystem.join(...paths);
854
+ },
855
+ dirname(filePath) {
856
+ return fileSystem.dirname(filePath);
857
+ }
858
+ };
859
+ }
860
+ var RuntimeService = class {
861
+ constructor(context, cacheService, eventService, jobService) {
862
+ this.context = context;
863
+ this.cacheService = cacheService;
864
+ this.eventService = eventService;
865
+ this.jobService = jobService;
866
+ }
867
+ async openSession(input) {
868
+ const startedAt = Date.now();
869
+ if (!this.context.fileSystem) return failure("runtime", startedAt, createCapabilityUnavailableError("fileSystem"));
870
+ const fileSystem = this.context.fileSystem;
871
+ const { fairyPath, canonicalProjectPath, canonicalPathKey } = await resolveCanonicalProjectRoot(fileSystem, input.projectPath);
872
+ const existingSessionId = this.context.sessionsByPath.get(canonicalPathKey);
873
+ const lockFilePath = fileSystem.join(canonicalProjectPath, ".openfairygui.backend.lock");
874
+ if (existingSessionId) return failure("runtime", startedAt, {
875
+ code: "lock_conflict",
876
+ kind: "in_process_session_exists",
877
+ message: `Project is already open in this backend runtime: ${canonicalProjectPath}`,
878
+ canonicalPathKey,
879
+ holderSessionId: existingSessionId,
880
+ lockFilePath
881
+ });
882
+ let advisoryLock = null;
883
+ try {
884
+ advisoryLock = await fileSystem.openExclusive(lockFilePath);
885
+ await advisoryLock.writeFile(JSON.stringify(this.context.host?.lockMetadata?.({
886
+ canonicalPathKey,
887
+ canonicalProjectPath,
888
+ lockFilePath
889
+ }) ?? {
890
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
891
+ canonicalPathKey
892
+ }));
893
+ await advisoryLock.close();
894
+ const project = liftDocumentToUamProject(await new ProjectReader(createProjectReaderFileSystem(fileSystem)).read(fairyPath));
895
+ const sessionId = randomId();
896
+ const session = {
897
+ sessionId,
898
+ fairyPath,
899
+ canonicalProjectPath,
900
+ canonicalPathKey,
901
+ lockFilePath,
902
+ project,
903
+ revision: 0,
904
+ lastSavedRevision: 0,
905
+ dirty: false,
906
+ lockHeld: true,
907
+ closed: false
908
+ };
909
+ this.context.sessions.set(sessionId, session);
910
+ this.context.sessionsByPath.set(canonicalPathKey, sessionId);
911
+ this.cacheService.refreshSession(session);
912
+ this.eventService.emit({
913
+ kind: "session.opened",
914
+ sessionId,
915
+ canonicalPathKey,
916
+ revision: session.revision
917
+ });
918
+ return success("runtime", startedAt, toSessionSnapshot(session, this.context.capabilities), {
919
+ sessionId: session.sessionId,
920
+ revision: session.revision
921
+ });
922
+ } catch (error) {
923
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST") return failure("runtime", startedAt, {
924
+ code: "lock_conflict",
925
+ kind: "advisory_lock_conflict",
926
+ message: `Advisory lock already exists for project: ${canonicalProjectPath}`,
927
+ canonicalPathKey,
928
+ lockFilePath
929
+ });
930
+ if (advisoryLock) {
931
+ await advisoryLock.close().catch(() => void 0);
932
+ await fileSystem.unlink(lockFilePath).catch(() => void 0);
933
+ }
934
+ throw error;
935
+ }
936
+ }
937
+ openProjectSession(input) {
938
+ const startedAt = Date.now();
939
+ const sessionId = input.sessionId ?? randomId();
940
+ const canonicalProjectPath = input.canonicalProjectPath ?? `memory://${sessionId}`;
941
+ const canonicalPathKey = input.canonicalPathKey ?? canonicalProjectPath.toLowerCase();
942
+ const existingSessionId = this.context.sessionsByPath.get(canonicalPathKey);
943
+ if (existingSessionId) return failure("runtime", startedAt, {
944
+ code: "lock_conflict",
945
+ kind: "in_process_session_exists",
946
+ message: `Project is already open in this backend runtime: ${canonicalProjectPath}`,
947
+ canonicalPathKey,
948
+ holderSessionId: existingSessionId
949
+ });
950
+ const session = {
951
+ sessionId,
952
+ fairyPath: canonicalProjectPath,
953
+ canonicalProjectPath,
954
+ canonicalPathKey,
955
+ lockFilePath: "",
956
+ project: normalizeUamProject(input.project),
957
+ revision: 0,
958
+ lastSavedRevision: 0,
959
+ dirty: false,
960
+ lockHeld: false,
961
+ closed: false
962
+ };
963
+ this.context.sessions.set(sessionId, session);
964
+ this.context.sessionsByPath.set(canonicalPathKey, sessionId);
965
+ this.cacheService.refreshSession(session);
966
+ this.eventService.emit({
967
+ kind: "session.opened",
968
+ sessionId,
969
+ canonicalPathKey,
970
+ revision: session.revision
971
+ });
972
+ return success("runtime", startedAt, toSessionSnapshot(session, this.context.capabilities), {
973
+ sessionId: session.sessionId,
974
+ revision: session.revision
975
+ });
976
+ }
977
+ async closeSession(input) {
978
+ const startedAt = Date.now();
979
+ const session = this.context.sessions.get(input.sessionId);
980
+ if (!session || session.closed) return failure("runtime", startedAt, createSessionNotFoundError(input.sessionId));
981
+ this.eventService.emit({
982
+ kind: "session.closeRequested",
983
+ sessionId: session.sessionId,
984
+ canonicalPathKey: session.canonicalPathKey,
985
+ revision: session.revision
986
+ });
987
+ if (this.context.fileSystem && session.lockFilePath) await this.context.fileSystem.unlink(session.lockFilePath).catch(() => void 0);
988
+ session.lockHeld = false;
989
+ session.closed = true;
990
+ this.context.sessions.delete(session.sessionId);
991
+ this.context.sessionsByPath.delete(session.canonicalPathKey);
992
+ this.cacheService.removeSession(session.sessionId);
993
+ this.jobService.removeSession(session.sessionId);
994
+ this.eventService.emit({
995
+ kind: "session.closed",
996
+ sessionId: session.sessionId,
997
+ canonicalPathKey: session.canonicalPathKey,
998
+ revision: session.revision
999
+ });
1000
+ this.eventService.removeSession(session.sessionId);
1001
+ return success("runtime", startedAt, {
1002
+ sessionId: session.sessionId,
1003
+ closed: true
1004
+ }, {
1005
+ sessionId: session.sessionId,
1006
+ revision: session.revision
1007
+ });
1008
+ }
1009
+ };
1010
+ //#endregion
1011
+ //#region src/runtime.ts
1012
+ const BACKEND_METHODS = [
1013
+ "getCapabilities",
1014
+ "openSession",
1015
+ "openProjectSession",
1016
+ "getSession",
1017
+ "applyTransaction",
1018
+ "saveSession",
1019
+ "closeSession",
1020
+ "getEvents",
1021
+ "getJob",
1022
+ "listJobs",
1023
+ "cancelJob",
1024
+ "getCacheSnapshot",
1025
+ "refreshCache"
1026
+ ];
1027
+ const ARTIFACT_BRIDGE_CAPABILITY = {
1028
+ available: false,
1029
+ requiredHost: "node",
1030
+ executionBoundary: "external-bridge",
1031
+ bridgeEntrypoint: "@openfairygui/backend/node",
1032
+ reason: "publish/restore require explicit Node-hosted filesystem and artifact execution."
1033
+ };
1034
+ function createCapabilities() {
1035
+ return {
1036
+ contractVersion: BACKEND_CONTRACT_VERSION,
1037
+ capabilitySchemaVersion: 2,
1038
+ transactionKernelOwner: "@openfairygui/core",
1039
+ appSeamOwner: "@openfairygui/functions",
1040
+ runtimeOwner: "@openfairygui/backend",
1041
+ methods: BACKEND_METHODS,
1042
+ read: {
1043
+ capabilitySnapshot: true,
1044
+ sessionSnapshot: true
1045
+ },
1046
+ authoring: {
1047
+ applyTransaction: true,
1048
+ saveSession: true,
1049
+ resourceKinds: [...UAM_SUPPORTED_MATERIALIZATION_SCOPE.resourceKinds],
1050
+ nodeKinds: [...UAM_SUPPORTED_MATERIALIZATION_SCOPE.nodeKinds],
1051
+ gearKinds: [...UAM_SUPPORTED_MATERIALIZATION_SCOPE.gearKinds],
1052
+ unsupported: ["artifact.publish", "artifact.restore"]
1053
+ },
1054
+ artifact: createArtifactCapabilities(),
1055
+ manifest: {
1056
+ browserSafe: true,
1057
+ rootEntrypoint: "@openfairygui/backend",
1058
+ nodeEntrypoint: "@openfairygui/backend/node",
1059
+ adapters: {
1060
+ fileSystem: {
1061
+ injected: true,
1062
+ requiredFor: ["openSession", "saveSession"]
1063
+ },
1064
+ host: {
1065
+ injected: true,
1066
+ requiredFor: ["advisoryLockMetadata"]
1067
+ }
1068
+ },
1069
+ executionBoundaries: {
1070
+ projectSession: "in-process-browser-safe",
1071
+ fileBackedSession: "adapter-backed",
1072
+ artifactPublish: ARTIFACT_BRIDGE_CAPABILITY,
1073
+ artifactRestore: ARTIFACT_BRIDGE_CAPABILITY
1074
+ },
1075
+ diagnostics: {
1076
+ stableCodes: true,
1077
+ errorDiagnosticMirror: true
1078
+ }
1079
+ },
1080
+ compatibilityPolicy: BACKEND_COMPATIBILITY_POLICY,
1081
+ runtime: {
1082
+ sessionRuntime: true,
1083
+ advisoryLocking: true,
1084
+ coordinatedSave: true,
1085
+ atomicSave: false,
1086
+ staleRevisionProtection: true,
1087
+ pathPolicy: createRuntimePathPolicy(),
1088
+ events: {
1089
+ polling: true,
1090
+ subscriptions: false,
1091
+ retentionLimit: 1e3,
1092
+ sequenceScope: "runtime"
1093
+ },
1094
+ jobs: {
1095
+ inMemory: true,
1096
+ cooperativeCancel: true,
1097
+ persistent: false,
1098
+ supportedKinds: ["cache.refresh"],
1099
+ artifactJobs: false,
1100
+ completedRetentionLimit: 100
1101
+ },
1102
+ cache: {
1103
+ derivedReadOnly: true,
1104
+ keyedBy: "canonicalPathKey",
1105
+ sourceOfTruth: false,
1106
+ refreshMethod: "refreshCache"
1107
+ }
1108
+ }
1109
+ };
1110
+ }
1111
+ var BackendRuntime = class {
1112
+ fileSystem;
1113
+ capabilities;
1114
+ sessions = /* @__PURE__ */ new Map();
1115
+ sessionsByPath = /* @__PURE__ */ new Map();
1116
+ eventsBySession = /* @__PURE__ */ new Map();
1117
+ jobsBySession = /* @__PURE__ */ new Map();
1118
+ cacheBySession = /* @__PURE__ */ new Map();
1119
+ eventSequence = 0;
1120
+ context;
1121
+ readService;
1122
+ runtimeService;
1123
+ authoringService;
1124
+ cacheService;
1125
+ eventService;
1126
+ jobService;
1127
+ constructor(options = {}) {
1128
+ this.fileSystem = options.fileSystem;
1129
+ this.capabilities = createCapabilities();
1130
+ this.context = {
1131
+ fileSystem: this.fileSystem,
1132
+ host: options.host,
1133
+ capabilities: this.capabilities,
1134
+ sessions: this.sessions,
1135
+ sessionsByPath: this.sessionsByPath,
1136
+ eventsBySession: this.eventsBySession,
1137
+ jobsBySession: this.jobsBySession,
1138
+ cacheBySession: this.cacheBySession,
1139
+ nextEventSequence: () => {
1140
+ this.eventSequence += 1;
1141
+ return this.eventSequence;
1142
+ }
1143
+ };
1144
+ this.readService = new ReadService(this.context);
1145
+ this.eventService = new EventService(this.context);
1146
+ this.cacheService = new CacheService(this.context);
1147
+ this.jobService = new JobService(this.context, this.cacheService, this.eventService);
1148
+ this.runtimeService = new RuntimeService(this.context, this.cacheService, this.eventService, this.jobService);
1149
+ this.authoringService = new AuthoringService(this.context, this.cacheService, this.eventService);
1150
+ }
1151
+ getCapabilities() {
1152
+ return this.readService.getCapabilities();
1153
+ }
1154
+ async openSession(input) {
1155
+ return this.runtimeService.openSession(input);
1156
+ }
1157
+ openProjectSession(input) {
1158
+ return this.runtimeService.openProjectSession(input);
1159
+ }
1160
+ getSession(input) {
1161
+ return this.readService.getSession(input);
1162
+ }
1163
+ async applyTransaction(input) {
1164
+ return this.authoringService.applyTransaction(input);
1165
+ }
1166
+ async saveSession(input) {
1167
+ return this.authoringService.saveSession(input);
1168
+ }
1169
+ async closeSession(input) {
1170
+ return this.runtimeService.closeSession(input);
1171
+ }
1172
+ getEvents(input) {
1173
+ return this.eventService.getEvents(input);
1174
+ }
1175
+ getJob(input) {
1176
+ return this.jobService.getJob(input);
1177
+ }
1178
+ listJobs(input) {
1179
+ return this.jobService.listJobs(input);
1180
+ }
1181
+ cancelJob(input) {
1182
+ return this.jobService.cancelJob(input);
1183
+ }
1184
+ getCacheSnapshot(input) {
1185
+ return this.cacheService.getCacheSnapshot(input);
1186
+ }
1187
+ refreshCache(input) {
1188
+ return this.jobService.refreshCache(input);
1189
+ }
1190
+ };
1191
+ //#endregion
1192
+ export { BACKEND_CONTRACT_VERSION as i, BACKEND_CAPABILITY_SCHEMA_VERSION as n, BACKEND_COMPATIBILITY_POLICY as r, BackendRuntime as t };