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.
- package/dist/node/protocol/appPreferences.js +25 -0
- package/dist/node/protocol/conversationObservation.js +67 -0
- package/dist/node/protocol/v1.js +186 -34
- package/dist/node/protocol/worldExtensions.js +16 -0
- package/dist/node/protocol/worldMaintenance.js +77 -0
- package/dist/node/protocol/worldPromptDiagnostics.js +1 -0
- package/dist/node/runtime/ConversationChanges.js +24 -0
- package/dist/node/runtime/V1Runtime.js +445 -121
- package/dist/node/runtime/artifact/FileNativeArtifactStore.js +326 -12
- package/dist/node/runtime/authoring/AuthoringRequestSnapshot.js +63 -0
- package/dist/node/runtime/authoring/ModelToolConversation.js +218 -0
- package/dist/node/runtime/config/AppPreferencesStore.js +46 -17
- package/dist/node/runtime/content/ContentTreeFingerprint.js +13 -0
- package/dist/node/runtime/content/ContentWorkspace.js +43 -13
- package/dist/node/runtime/content/CurrentTreeContentLibrary.js +128 -46
- package/dist/node/runtime/content/FileNativeContentTree.js +28 -10
- package/dist/node/runtime/content/PackageFollowups.js +80 -0
- package/dist/node/runtime/extension/FrontendExtensionBundle.js +19 -14
- package/dist/node/runtime/extension/PackageScriptPermissions.js +70 -0
- package/dist/node/runtime/extension/WorldExtensionControls.js +205 -0
- package/dist/node/runtime/extension/WorldExtensionRequests.js +64 -0
- package/dist/node/runtime/model/FileNativeModelAdapters.js +21 -466
- package/dist/node/runtime/model/ModelConnectionStore.js +13 -0
- package/dist/node/runtime/model/ModelHost.js +31 -1
- package/dist/node/runtime/model/ModelHostStream.js +51 -5
- package/dist/node/runtime/play/FileNativeContinuityCorrection.js +55 -45
- package/dist/node/runtime/play/FileNativePlayPresetStore.js +256 -238
- package/dist/node/runtime/play/FileNativePlayTimelineStore.js +118 -9
- package/dist/node/runtime/play/OrderedFollowups.js +71 -0
- package/dist/node/runtime/play/OrderedPlayPrompts.js +180 -0
- package/dist/node/runtime/play/PlayCallChain.js +814 -61
- package/dist/node/runtime/play/PlayContinuity.js +88 -0
- package/dist/node/runtime/play/PlayDocumentTools.js +205 -287
- package/dist/node/runtime/play/PlayFollowupRequests.js +34 -3
- package/dist/node/runtime/play/PlayPresetWorkbench.js +45 -54
- package/dist/node/runtime/play/PlayPromptRun.js +86 -0
- package/dist/node/runtime/prompt/FileNativePromptCompiler.js +670 -93
- package/dist/node/runtime/prompt/FileNativeToolRegistry.js +37 -21
- package/dist/node/runtime/prompt/PromptCompilationCodec.js +322 -0
- package/dist/node/runtime/prompt/WorldMaintenanceReport.js +251 -0
- package/dist/node/runtime/prompt/WorldMaterialCoverage.js +83 -0
- package/dist/node/runtime/prompt/WorldPromptDiagnostics.js +185 -0
- package/dist/node/runtime/setting/FileNativeSettingImprovementStore.js +1027 -0
- package/dist/node/runtime/setting/SettingAuthoringTransaction.js +1339 -0
- package/dist/node/runtime/setting/SettingImprovementSession.js +714 -0
- package/dist/node/runtime/world/FileNativeAuthorityV3.js +88 -1
- package/dist/node/runtime/world/FileNativeWorldStore.js +292 -27
- package/dist/node/runtime/world/PlayerViewBindings.js +30 -0
- package/dist/node/runtime/world/PlayerViewRenderer.js +27 -34
- package/dist/node/runtime/world/WorldDocumentMaintenance.js +174 -0
- package/dist/node/runtime/world/WorldDocumentStore.js +166 -96
- package/dist/node/runtime/world/WorldOperationCoordinator.js +103 -2
- package/dist/node/runtime/world-revision/FileNativeWorldRevisionStore.js +696 -0
- package/dist/node/runtime/world-revision/WorldRevisionAuthoringTransaction.js +380 -0
- package/dist/node/runtime/world-revision/WorldRevisionSession.js +709 -0
- package/dist/node/runtime/world-revision/WorldRevisionWorkspace.js +494 -0
- package/dist/node/server/ConversationStream.js +109 -0
- package/dist/node/server/createServer.js +5 -1
- package/dist/node/shared/artifact-payload-contract.js +123 -0
- package/dist/node/shared/default-play-prompts.js +25 -45
- package/dist/node/shared/default-preset-host.js +114 -138
- package/dist/node/shared/default-setting-improvement-prompt.js +52 -38
- package/dist/node/shared/display-regex.js +114 -0
- package/dist/node/shared/first-party-action-choices.js +1 -6
- package/dist/node/shared/first-party-player-view.js +1 -6
- package/dist/node/shared/ordered-author-prompts.js +64 -0
- package/dist/node/shared/ordered-followups.js +42 -0
- package/dist/node/shared/ordered-play-prompts.js +73 -0
- package/dist/web/assets/index-BXfelCi9.js +1207 -0
- package/dist/web/assets/index-BYnhUxlk.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/node/runtime/model/SettingAuthorStream.js +0 -21
- package/dist/node/runtime/setting/DocumentCandidateSettingImprovement.js +0 -1731
- package/dist/web/assets/index-D8YKfmNG.js +0 -1192
- package/dist/web/assets/index-Xa0s35CJ.css +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { listWorldDocuments } from "../prompt/WorldMaintenanceReport.js";
|
|
2
|
+
import { WorldDocumentStore } from "./WorldDocumentStore.js";
|
|
3
|
+
/** Reachable committed bytes only. Cached prefixes are disposable accelerators. */
|
|
4
|
+
export async function readDocumentMaintenanceFacts(authority, head, cache) {
|
|
5
|
+
const exact = cache.get(head);
|
|
6
|
+
if (exact !== undefined)
|
|
7
|
+
return structuredClone(exact.facts);
|
|
8
|
+
const timeline = [];
|
|
9
|
+
let cursor = head;
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
while (cursor !== "genesis" && !cache.has(cursor)) {
|
|
12
|
+
const commit = await authority.commitAt(cursor);
|
|
13
|
+
if (commit === null || seen.has(cursor))
|
|
14
|
+
throw new Error("Document maintenance history is not reachable");
|
|
15
|
+
seen.add(cursor);
|
|
16
|
+
timeline.push(commit);
|
|
17
|
+
cursor = commit.timelineParent.head;
|
|
18
|
+
}
|
|
19
|
+
timeline.reverse();
|
|
20
|
+
const prefix = cache.get(cursor);
|
|
21
|
+
const files = prefix === undefined
|
|
22
|
+
? new Map((await authority.recoverState("genesis")).map(({ path, contents }) => [path, contents]))
|
|
23
|
+
: new Map(prefix.files);
|
|
24
|
+
const snapshot = () => WorldDocumentStore.open({
|
|
25
|
+
layout: "world_state",
|
|
26
|
+
files: [...files].map(([path, contents]) => ({
|
|
27
|
+
path: `state/${path}`,
|
|
28
|
+
contents,
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
let previous = snapshot();
|
|
32
|
+
const facts = structuredClone(prefix?.facts ?? {});
|
|
33
|
+
const bodyContexts = structuredClone(prefix?.bodyContexts ?? new Map());
|
|
34
|
+
const metadataContexts = structuredClone(prefix?.metadataContexts ?? new Map());
|
|
35
|
+
const origin = {
|
|
36
|
+
kind: "world_origin",
|
|
37
|
+
context: null,
|
|
38
|
+
round: 0,
|
|
39
|
+
worldTime: null,
|
|
40
|
+
};
|
|
41
|
+
for (const document of prefix === undefined
|
|
42
|
+
? listWorldDocuments(previous)
|
|
43
|
+
: []) {
|
|
44
|
+
const read = previous.query({
|
|
45
|
+
kind: "read_document",
|
|
46
|
+
document: { shortRef: document.shortRef },
|
|
47
|
+
});
|
|
48
|
+
if (read.kind !== "read_document")
|
|
49
|
+
continue;
|
|
50
|
+
facts[document.shortRef] = {
|
|
51
|
+
baselineKind: "world_origin",
|
|
52
|
+
baselineBytes: Buffer.byteLength(read.body, "utf8"),
|
|
53
|
+
lastBodyWrite: origin,
|
|
54
|
+
lastMetadataWrite: origin,
|
|
55
|
+
bodyChangedContexts: 0,
|
|
56
|
+
metadataChangedContexts: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const contexts = structuredClone(prefix?.contexts ?? new Map());
|
|
60
|
+
let inputPosition = prefix?.inputPosition ?? 0;
|
|
61
|
+
let unassignedPlayer = prefix?.unassignedPlayer ?? false;
|
|
62
|
+
for (const commit of timeline) {
|
|
63
|
+
let context = commit.playContext === undefined
|
|
64
|
+
? undefined
|
|
65
|
+
: contexts.get(commit.playContext);
|
|
66
|
+
if (commit.playContext !== undefined && context === undefined) {
|
|
67
|
+
context = { ordinal: contexts.size + 1, round: 0 };
|
|
68
|
+
contexts.set(commit.playContext, context);
|
|
69
|
+
}
|
|
70
|
+
if (context !== undefined && unassignedPlayer) {
|
|
71
|
+
context.round += 1;
|
|
72
|
+
unassignedPlayer = false;
|
|
73
|
+
}
|
|
74
|
+
for (const message of commit.historyAppend) {
|
|
75
|
+
if (message.role === "player" && message.exactText.trim().length > 0) {
|
|
76
|
+
inputPosition += 1;
|
|
77
|
+
if (context !== undefined)
|
|
78
|
+
context.round += 1;
|
|
79
|
+
else
|
|
80
|
+
unassignedPlayer = true;
|
|
81
|
+
}
|
|
82
|
+
else if (message.role === "narrator")
|
|
83
|
+
unassignedPlayer = false;
|
|
84
|
+
}
|
|
85
|
+
if (commit.stateChanges.length === 0)
|
|
86
|
+
continue;
|
|
87
|
+
const changed = await Promise.all(commit.stateChanges.map(async (change) => ({
|
|
88
|
+
change,
|
|
89
|
+
contents: await authority.readStateChangeContents(change),
|
|
90
|
+
})));
|
|
91
|
+
for (const { change, contents } of changed)
|
|
92
|
+
files.set(change.relativePath, contents);
|
|
93
|
+
const next = snapshot();
|
|
94
|
+
const position = {
|
|
95
|
+
kind: commit.mode === "correction"
|
|
96
|
+
? "correction"
|
|
97
|
+
: context === undefined
|
|
98
|
+
? "history"
|
|
99
|
+
: "play",
|
|
100
|
+
context: context?.ordinal ?? null,
|
|
101
|
+
round: context?.round ?? inputPosition,
|
|
102
|
+
worldTime: commit.worldClock ?? null,
|
|
103
|
+
};
|
|
104
|
+
for (const { change } of changed) {
|
|
105
|
+
const ref = change.stableShortRef;
|
|
106
|
+
const before = previous.query({
|
|
107
|
+
kind: "read_document",
|
|
108
|
+
document: { shortRef: ref },
|
|
109
|
+
});
|
|
110
|
+
const after = next.query({
|
|
111
|
+
kind: "read_document",
|
|
112
|
+
document: { shortRef: ref },
|
|
113
|
+
});
|
|
114
|
+
if (after.kind !== "read_document")
|
|
115
|
+
throw new Error(`Accepted document @${ref} is unreadable`);
|
|
116
|
+
const fact = facts[ref] ?? {
|
|
117
|
+
baselineKind: "document_creation",
|
|
118
|
+
baselineBytes: Buffer.byteLength(after.body, "utf8"),
|
|
119
|
+
lastBodyWrite: null,
|
|
120
|
+
lastMetadataWrite: null,
|
|
121
|
+
bodyChangedContexts: 0,
|
|
122
|
+
metadataChangedContexts: 0,
|
|
123
|
+
};
|
|
124
|
+
const bodyChanged = before.kind !== "read_document" || before.body !== after.body;
|
|
125
|
+
const metadataChanged = before.kind !== "read_document" ||
|
|
126
|
+
JSON.stringify([
|
|
127
|
+
before.document.title,
|
|
128
|
+
before.document.summary,
|
|
129
|
+
before.document.aliases,
|
|
130
|
+
before.document.retired,
|
|
131
|
+
]) !==
|
|
132
|
+
JSON.stringify([
|
|
133
|
+
after.document.title,
|
|
134
|
+
after.document.summary,
|
|
135
|
+
after.document.aliases,
|
|
136
|
+
after.document.retired,
|
|
137
|
+
]);
|
|
138
|
+
if (bodyChanged) {
|
|
139
|
+
fact.lastBodyWrite = structuredClone(position);
|
|
140
|
+
if (commit.playContext !== undefined) {
|
|
141
|
+
const changedContexts = bodyContexts.get(ref) ?? new Set();
|
|
142
|
+
changedContexts.add(commit.playContext);
|
|
143
|
+
bodyContexts.set(ref, changedContexts);
|
|
144
|
+
fact.bodyChangedContexts = changedContexts.size;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (metadataChanged) {
|
|
148
|
+
fact.lastMetadataWrite = structuredClone(position);
|
|
149
|
+
if (commit.playContext !== undefined) {
|
|
150
|
+
const changedContexts = metadataContexts.get(ref) ?? new Set();
|
|
151
|
+
changedContexts.add(commit.playContext);
|
|
152
|
+
metadataContexts.set(ref, changedContexts);
|
|
153
|
+
fact.metadataChangedContexts = changedContexts.size;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
facts[ref] = fact;
|
|
157
|
+
}
|
|
158
|
+
previous = next;
|
|
159
|
+
}
|
|
160
|
+
for (const fact of Object.values(facts))
|
|
161
|
+
fact.observedContexts = contexts.size;
|
|
162
|
+
if (cache.size >= 8)
|
|
163
|
+
cache.delete(cache.keys().next().value);
|
|
164
|
+
cache.set(head, {
|
|
165
|
+
files,
|
|
166
|
+
facts,
|
|
167
|
+
bodyContexts,
|
|
168
|
+
metadataContexts,
|
|
169
|
+
contexts,
|
|
170
|
+
inputPosition,
|
|
171
|
+
unassignedPlayer,
|
|
172
|
+
});
|
|
173
|
+
return structuredClone(facts);
|
|
174
|
+
}
|