narraeon 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/node/protocol/appPreferences.js +25 -0
  2. package/dist/node/protocol/conversationObservation.js +67 -0
  3. package/dist/node/protocol/v1.js +186 -34
  4. package/dist/node/protocol/worldExtensions.js +16 -0
  5. package/dist/node/protocol/worldMaintenance.js +77 -0
  6. package/dist/node/protocol/worldPromptDiagnostics.js +1 -0
  7. package/dist/node/runtime/ConversationChanges.js +24 -0
  8. package/dist/node/runtime/V1Runtime.js +445 -121
  9. package/dist/node/runtime/artifact/FileNativeArtifactStore.js +326 -12
  10. package/dist/node/runtime/authoring/AuthoringRequestSnapshot.js +63 -0
  11. package/dist/node/runtime/authoring/ModelToolConversation.js +218 -0
  12. package/dist/node/runtime/config/AppPreferencesStore.js +46 -17
  13. package/dist/node/runtime/content/ContentTreeFingerprint.js +13 -0
  14. package/dist/node/runtime/content/ContentWorkspace.js +43 -13
  15. package/dist/node/runtime/content/CurrentTreeContentLibrary.js +128 -46
  16. package/dist/node/runtime/content/FileNativeContentTree.js +28 -10
  17. package/dist/node/runtime/content/PackageFollowups.js +80 -0
  18. package/dist/node/runtime/extension/FrontendExtensionBundle.js +19 -14
  19. package/dist/node/runtime/extension/PackageScriptPermissions.js +70 -0
  20. package/dist/node/runtime/extension/WorldExtensionControls.js +205 -0
  21. package/dist/node/runtime/extension/WorldExtensionRequests.js +64 -0
  22. package/dist/node/runtime/model/FileNativeModelAdapters.js +21 -466
  23. package/dist/node/runtime/model/ModelConnectionStore.js +13 -0
  24. package/dist/node/runtime/model/ModelHost.js +31 -1
  25. package/dist/node/runtime/model/ModelHostStream.js +51 -5
  26. package/dist/node/runtime/play/FileNativeContinuityCorrection.js +55 -45
  27. package/dist/node/runtime/play/FileNativePlayPresetStore.js +256 -238
  28. package/dist/node/runtime/play/FileNativePlayTimelineStore.js +118 -9
  29. package/dist/node/runtime/play/OrderedFollowups.js +71 -0
  30. package/dist/node/runtime/play/OrderedPlayPrompts.js +180 -0
  31. package/dist/node/runtime/play/PlayCallChain.js +814 -61
  32. package/dist/node/runtime/play/PlayContinuity.js +88 -0
  33. package/dist/node/runtime/play/PlayDocumentTools.js +205 -287
  34. package/dist/node/runtime/play/PlayFollowupRequests.js +34 -3
  35. package/dist/node/runtime/play/PlayPresetWorkbench.js +45 -54
  36. package/dist/node/runtime/play/PlayPromptRun.js +86 -0
  37. package/dist/node/runtime/prompt/FileNativePromptCompiler.js +670 -93
  38. package/dist/node/runtime/prompt/FileNativeToolRegistry.js +37 -21
  39. package/dist/node/runtime/prompt/PromptCompilationCodec.js +322 -0
  40. package/dist/node/runtime/prompt/WorldMaintenanceReport.js +251 -0
  41. package/dist/node/runtime/prompt/WorldMaterialCoverage.js +83 -0
  42. package/dist/node/runtime/prompt/WorldPromptDiagnostics.js +185 -0
  43. package/dist/node/runtime/setting/FileNativeSettingImprovementStore.js +1027 -0
  44. package/dist/node/runtime/setting/SettingAuthoringTransaction.js +1339 -0
  45. package/dist/node/runtime/setting/SettingImprovementSession.js +714 -0
  46. package/dist/node/runtime/world/FileNativeAuthorityV3.js +88 -1
  47. package/dist/node/runtime/world/FileNativeWorldStore.js +292 -27
  48. package/dist/node/runtime/world/PlayerViewBindings.js +30 -0
  49. package/dist/node/runtime/world/PlayerViewRenderer.js +27 -34
  50. package/dist/node/runtime/world/WorldDocumentMaintenance.js +174 -0
  51. package/dist/node/runtime/world/WorldDocumentStore.js +166 -96
  52. package/dist/node/runtime/world/WorldOperationCoordinator.js +103 -2
  53. package/dist/node/runtime/world-revision/FileNativeWorldRevisionStore.js +696 -0
  54. package/dist/node/runtime/world-revision/WorldRevisionAuthoringTransaction.js +380 -0
  55. package/dist/node/runtime/world-revision/WorldRevisionSession.js +709 -0
  56. package/dist/node/runtime/world-revision/WorldRevisionWorkspace.js +494 -0
  57. package/dist/node/server/ConversationStream.js +109 -0
  58. package/dist/node/server/createServer.js +5 -1
  59. package/dist/node/shared/artifact-payload-contract.js +123 -0
  60. package/dist/node/shared/default-play-prompts.js +25 -45
  61. package/dist/node/shared/default-preset-host.js +114 -138
  62. package/dist/node/shared/default-setting-improvement-prompt.js +52 -38
  63. package/dist/node/shared/display-regex.js +114 -0
  64. package/dist/node/shared/first-party-action-choices.js +1 -6
  65. package/dist/node/shared/first-party-player-view.js +1 -6
  66. package/dist/node/shared/ordered-author-prompts.js +64 -0
  67. package/dist/node/shared/ordered-followups.js +42 -0
  68. package/dist/node/shared/ordered-play-prompts.js +73 -0
  69. package/dist/web/assets/index-BXfelCi9.js +1207 -0
  70. package/dist/web/assets/index-BYnhUxlk.css +1 -0
  71. package/dist/web/index.html +2 -2
  72. package/package.json +1 -1
  73. package/dist/node/runtime/model/SettingAuthorStream.js +0 -21
  74. package/dist/node/runtime/setting/DocumentCandidateSettingImprovement.js +0 -1731
  75. package/dist/web/assets/index-D8YKfmNG.js +0 -1192
  76. package/dist/web/assets/index-Xa0s35CJ.css +0 -1
@@ -146,6 +146,17 @@ export class FileNativeAuthorityV3 {
146
146
  history,
147
147
  historyLength: basis.historyLength + historyAppend.length,
148
148
  materials,
149
+ ...(input.narrativeCheckpoint === undefined
150
+ ? basis.narrativeCheckpoint === undefined
151
+ ? {}
152
+ : { narrativeCheckpoint: basis.narrativeCheckpoint }
153
+ : {
154
+ narrativeCheckpoint: {
155
+ ...input.narrativeCheckpoint,
156
+ head,
157
+ historyMessageId: historyAppend.at(-1)?.messageId ?? "",
158
+ },
159
+ }),
149
160
  };
150
161
  assertEndpoint(endpointValue);
151
162
  const endpoint = await this.#writeObject(sequence, "endpoint.json", endpointValue);
@@ -169,6 +180,12 @@ export class FileNativeAuthorityV3 {
169
180
  };
170
181
  const timelineParent = await this.#authorityRefAt(basisHead);
171
182
  const commit = {
183
+ ...(input.playContext === undefined
184
+ ? {}
185
+ : { playContext: input.playContext }),
186
+ ...(input.worldClock === undefined
187
+ ? {}
188
+ : { worldClock: input.worldClock }),
172
189
  schemaVersion: 3,
173
190
  type: "file_native_authority_commit",
174
191
  sequence,
@@ -180,6 +197,9 @@ export class FileNativeAuthorityV3 {
180
197
  stateChanges: storedChanges,
181
198
  nextAdditionalMaterials: structuredClone(input.nextMaterials),
182
199
  result: endpoint,
200
+ ...(input.narrativeCheckpoint === undefined
201
+ ? {}
202
+ : { narrativeCheckpoint: structuredClone(input.narrativeCheckpoint) }),
183
203
  ...(input.correctionTargets === undefined
184
204
  ? {}
185
205
  : { correctionTargets: structuredClone(input.correctionTargets) }),
@@ -241,8 +261,20 @@ export class FileNativeAuthorityV3 {
241
261
  history,
242
262
  additionalMaterials: structuredClone([...materials.items]),
243
263
  result,
264
+ ...(endpoint.narrativeCheckpoint === undefined
265
+ ? {}
266
+ : {
267
+ narrativeCheckpoint: structuredClone(endpoint.narrativeCheckpoint),
268
+ }),
244
269
  };
245
270
  }
271
+ async readNarrativeCheckpoint(head) {
272
+ const current = await this.readHead();
273
+ const endpoint = await this.#readEndpoint(head === undefined || head === current.head
274
+ ? current.result
275
+ : await this.#resultRefAt(head));
276
+ return structuredClone(endpoint.narrativeCheckpoint);
277
+ }
246
278
  async recoverState(head) {
247
279
  const current = await this.readHead();
248
280
  const selected = head ?? current.head;
@@ -283,6 +315,18 @@ export class FileNativeAuthorityV3 {
283
315
  throw new FileNativeAuthorityV3Error("corrupt", "Continuity head does not match the immutable Authority chain");
284
316
  return { head: head.head, commits };
285
317
  }
318
+ /** Exact bytes of an accepted state change, with the same digest check as recovery. */
319
+ async readStateChangeContents(change) {
320
+ const blob = change.nextBlob;
321
+ if (!isBlobRef(blob))
322
+ throw corruptShape("State-change blob");
323
+ const contents = await readFile(join(this.#epochRoot(blob.epoch), "blobs", `${blob.digest}.txt`), "utf8");
324
+ if (hashHex(contents) !== blob.digest ||
325
+ hashWithPrefix(contents) !== change.nextHash ||
326
+ blob.sha256 !== change.nextHash)
327
+ throw corruptShape("State-change blob digest");
328
+ return contents;
329
+ }
286
330
  async commitAt(head) {
287
331
  if (head === "genesis")
288
332
  return null;
@@ -572,6 +616,9 @@ function assertEndpoint(value) {
572
616
  "history",
573
617
  "historyLength",
574
618
  "materials",
619
+ ...(value.narrativeCheckpoint === undefined
620
+ ? []
621
+ : ["narrativeCheckpoint"]),
575
622
  ]) ||
576
623
  value.schemaVersion !== 3 ||
577
624
  value.type !== "file_native_authority_endpoint" ||
@@ -579,7 +626,9 @@ function assertEndpoint(value) {
579
626
  (value.history !== null && !isObjectRef(value.history)) ||
580
627
  !Number.isSafeInteger(value.historyLength) ||
581
628
  Number(value.historyLength) < 0 ||
582
- !isObjectRef(value.materials))
629
+ !isObjectRef(value.materials) ||
630
+ (value.narrativeCheckpoint !== undefined &&
631
+ !isNarrativeCheckpoint(value.narrativeCheckpoint, true)))
583
632
  throw corruptShape("Authority endpoint");
584
633
  }
585
634
  function assertStateManifest(value) {
@@ -640,6 +689,16 @@ function assertCommit(value) {
640
689
  throw corruptShape("Authority commit");
641
690
  const correction = value.mode === "correction";
642
691
  const revision = value.mode === "timeline_revision";
692
+ const lastHistory = Array.isArray(value.historyAppend)
693
+ ? value.historyAppend.at(-1)
694
+ : undefined;
695
+ if (value.narrativeCheckpoint !== undefined &&
696
+ (!isNarrativeCheckpoint(value.narrativeCheckpoint, false) ||
697
+ value.mode !== "play" ||
698
+ !Array.isArray(value.historyAppend) ||
699
+ !isRecord(lastHistory) ||
700
+ lastHistory.role !== "narrator"))
701
+ throw corruptShape("Narrative checkpoint declaration");
643
702
  if (!hasExactKeys(value, [
644
703
  "schemaVersion",
645
704
  "type",
@@ -647,6 +706,11 @@ function assertCommit(value) {
647
706
  "head",
648
707
  "auditParent",
649
708
  "timelineParent",
709
+ ...(value.playContext === undefined ? [] : ["playContext"]),
710
+ ...(value.worldClock === undefined ? [] : ["worldClock"]),
711
+ ...(value.narrativeCheckpoint === undefined
712
+ ? []
713
+ : ["narrativeCheckpoint"]),
650
714
  "mode",
651
715
  "historyAppend",
652
716
  "stateChanges",
@@ -657,6 +721,10 @@ function assertCommit(value) {
657
721
  ]) ||
658
722
  value.schemaVersion !== 3 ||
659
723
  value.type !== "file_native_authority_commit" ||
724
+ (value.playContext !== undefined &&
725
+ (typeof value.playContext !== "string" ||
726
+ value.playContext.length === 0)) ||
727
+ (value.worldClock !== undefined && typeof value.worldClock !== "string") ||
660
728
  !Number.isSafeInteger(value.sequence) ||
661
729
  Number(value.sequence) < 1 ||
662
730
  value.head !== `commit:${String(value.sequence)}` ||
@@ -848,6 +916,25 @@ function hasExactKeys(value, keys) {
848
916
  return (Object.keys(value).length === keys.length &&
849
917
  keys.every((key) => Object.hasOwn(value, key)));
850
918
  }
919
+ function isNarrativeCheckpoint(value, effective) {
920
+ if (!isRecord(value) ||
921
+ !hasExactKeys(value, [
922
+ "contextId",
923
+ "completedPlayerRounds",
924
+ ...(effective ? ["head", "historyMessageId"] : []),
925
+ ]) ||
926
+ typeof value.contextId !== "string" ||
927
+ value.contextId.length === 0 ||
928
+ !Number.isSafeInteger(value.completedPlayerRounds) ||
929
+ Number(value.completedPlayerRounds) < 0)
930
+ return false;
931
+ return (!effective ||
932
+ (typeof value.head === "string" &&
933
+ /^commit:[1-9][0-9]*$/u.test(value.head) &&
934
+ typeof value.historyMessageId === "string" &&
935
+ value.historyMessageId.startsWith(`message.${value.head.slice("commit:".length)}.`) &&
936
+ /^message\.[1-9][0-9]*\.[1-9][0-9]*\.narrator$/u.test(value.historyMessageId)));
937
+ }
851
938
  function corruptShape(label) {
852
939
  return new FileNativeAuthorityV3Error("corrupt", `${label} has an invalid shape`);
853
940
  }