narraeon 0.7.4 → 0.7.6
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/v1.js +4 -0
- package/dist/node/runtime/V1Runtime.js +13 -1
- package/dist/node/runtime/content/CurrentTreeContentLibrary.js +64 -163
- package/dist/node/runtime/content/FileNativeContentTree.js +16 -13
- package/dist/node/runtime/model/ToolArgumentCoercion.js +138 -0
- package/dist/node/runtime/play/FileNativePlayAdvanceStore.js +34 -18
- package/dist/node/runtime/play/FileNativePlayTimelineStore.js +6 -2
- package/dist/node/runtime/play/OrderedPlayPrompts.js +3 -6
- package/dist/node/runtime/play/PlayAdvanceLifecycle.js +211 -0
- package/dist/node/runtime/play/PlayCallChain.js +276 -398
- package/dist/node/runtime/play/PlayDocumentTools.js +19 -0
- package/dist/node/runtime/prompt/FileNativePromptCompiler.js +3 -3
- package/dist/node/runtime/prompt/FileNativeToolRegistry.js +15 -0
- package/dist/node/runtime/prompt/ToolNameAlias.js +14 -0
- package/dist/node/runtime/setting/SettingAuthoringTransaction.js +370 -169
- package/dist/node/runtime/world/FileNativeWorldStore.js +151 -109
- package/dist/node/runtime/world/WorldDocumentMaintenance.js +2 -1
- package/dist/node/runtime/world/WorldDocumentStore.js +1 -1
- package/dist/node/runtime/world/WorldLedgerAuthority.js +37 -3
- package/dist/node/runtime/world/WorldTurnLedger.js +17 -4
- package/dist/node/runtime/world-revision/FileNativeWorldRevisionStore.js +2 -4
- package/dist/node/runtime/world-revision/WorldRevisionAuthoringTransaction.js +19 -241
- package/dist/node/runtime/world-revision/WorldRevisionWorkspace.js +8 -27
- package/dist/node/server/createServer.js +1 -4
- package/dist/node/shared/ordered-play-prompts.js +5 -0
- package/dist/node/shared/turn-guide.js +27 -2
- package/dist/web/assets/index-Cj2JYCia.js +1408 -0
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-9N9kO8kY.js +0 -1408
|
@@ -5,6 +5,8 @@ import { stateDirectoryHandle, parseStateDirectoryHandle, } from "../world/State
|
|
|
5
5
|
import { renderDocumentWritePosition } from "../prompt/WorldMaintenanceReport.js";
|
|
6
6
|
import { stringify } from "yaml";
|
|
7
7
|
import { renderPlayerViewBindings } from "../world/PlayerViewBindings.js";
|
|
8
|
+
import { coerceToolArguments, renderCoercionNote, } from "../model/ToolArgumentCoercion.js";
|
|
9
|
+
import { runtimeToolInputSchema } from "../prompt/FileNativeToolRegistry.js";
|
|
8
10
|
import { PromptCompilationError, } from "../prompt/FileNativePromptCompiler.js";
|
|
9
11
|
import {} from "../world/WorldDocumentStore.js";
|
|
10
12
|
import { acceptWorldStateRevision, beginWorldStateRevision, fileNativeStateChanges, worldDocumentRevisionFailureMessage, } from "../world/WorldStateRevision.js";
|
|
@@ -76,6 +78,19 @@ export class FileNativePlayDocuments {
|
|
|
76
78
|
return authorizeResolvedRead(this.#reads, this.#candidate.snapshot, shortRef, locator);
|
|
77
79
|
}
|
|
78
80
|
execute(call, history, options = {}) {
|
|
81
|
+
const schema = runtimeToolInputSchema(call.name);
|
|
82
|
+
if (schema === null)
|
|
83
|
+
return this.#dispatch(call, history, options);
|
|
84
|
+
const repaired = coerceToolArguments(schema, call.arguments);
|
|
85
|
+
const result = this.#dispatch({ ...call, arguments: repaired.arguments }, history, options);
|
|
86
|
+
if (repaired.coerced.length === 0 || result.markdown === undefined)
|
|
87
|
+
return result;
|
|
88
|
+
return {
|
|
89
|
+
...result,
|
|
90
|
+
markdown: `${result.markdown}\n\n${renderCoercionNote(repaired.coerced, options.locale ?? "en")}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
#dispatch(call, history, options) {
|
|
79
94
|
let historyQuery;
|
|
80
95
|
const query = () => (historyQuery ??= new HistoryQuery(options.historyScope ?? "local-document-context", historyInputs(history)));
|
|
81
96
|
const render = (result) => renderHistoryResult(result, options.locale ?? "en");
|
|
@@ -232,6 +247,8 @@ function documentDescriptorByRef(snapshot, ref) {
|
|
|
232
247
|
return result.kind === "read_document" && result.ok ? result.document : null;
|
|
233
248
|
}
|
|
234
249
|
function applyPlayCandidatePatch(candidate, reads, args) {
|
|
250
|
+
if (record(args) && typeof args.edits === "string")
|
|
251
|
+
return toolFailure("world_patch.edits must be a JSON array of 1 to 32 edits, not a string.");
|
|
235
252
|
if (!record(args) ||
|
|
236
253
|
typeof args.target !== "string" ||
|
|
237
254
|
!Array.isArray(args.edits) ||
|
|
@@ -419,6 +436,8 @@ function applyPlayCandidateCreate(candidate, authorizations, args, declaredDirec
|
|
|
419
436
|
const parentDirectory = record(args) && typeof args.parent === "string"
|
|
420
437
|
? parseStateDirectoryHandle(args.parent)
|
|
421
438
|
: null;
|
|
439
|
+
if (record(args) && typeof args.aliases === "string")
|
|
440
|
+
throw new PlayDocumentToolFailure("world_create.aliases must be a JSON array of strings, not a string");
|
|
422
441
|
if (!record(args) ||
|
|
423
442
|
typeof args.parent !== "string" ||
|
|
424
443
|
parentDirectory === null ||
|
|
@@ -6,7 +6,7 @@ import { effectiveFollowupDefinitions } from "../play/OrderedFollowups.js";
|
|
|
6
6
|
import { legacyAuthorPrompts } from "../play/FileNativePlayPresetStore.js";
|
|
7
7
|
import { builtinAuthorPrompts, authoringMechanics, } from "../../shared/ordered-author-prompts.js";
|
|
8
8
|
import { builtinPlayPrompts, orderedPromptScope, orderedPromptTurnGuide, promptScopeApplies, } from "../../shared/ordered-play-prompts.js";
|
|
9
|
-
import { turnGuideHeader, turnGuideText, } from "../../shared/turn-guide.js";
|
|
9
|
+
import { turnGuideHeader, turnGuideText, turnGuideWithTurnNote, } from "../../shared/turn-guide.js";
|
|
10
10
|
import { parseOrderedPlayPrompts } from "../play/OrderedPlayPrompts.js";
|
|
11
11
|
import { renderDocumentWritePosition } from "./WorldMaintenanceReport.js";
|
|
12
12
|
import { parseDocument } from "yaml";
|
|
@@ -568,12 +568,12 @@ export class FileNativePromptCompiler {
|
|
|
568
568
|
append("player_input", [
|
|
569
569
|
{ source: "player:input", markdown: effective.playerInput },
|
|
570
570
|
]);
|
|
571
|
-
const turnGuide = turnGuideLines.length === 0
|
|
571
|
+
const turnGuide = turnGuideWithTurnNote(this.#locale, turnGuideLines.length === 0
|
|
572
572
|
? undefined
|
|
573
573
|
: {
|
|
574
574
|
text: turnGuideText(this.#locale, turnGuideLines),
|
|
575
575
|
lines: turnGuideLines,
|
|
576
|
-
};
|
|
576
|
+
}, effective.turnNote);
|
|
577
577
|
scanRuntimeLeakage([
|
|
578
578
|
...logicalMessages,
|
|
579
579
|
...(turnGuide === undefined
|
|
@@ -11,6 +11,11 @@ import { resolutionCheckToolForScheme, resolutionToolDefinition, resolutionToolN
|
|
|
11
11
|
* Tools that every current play and authoring surface may expose. Resolution
|
|
12
12
|
* tools are registered below but never enter a surface until a per-world
|
|
13
13
|
* selection (Phase 2) includes them.
|
|
14
|
+
*
|
|
15
|
+
* No declared name may end in `_<another declared name>`: a provider-mangled
|
|
16
|
+
* `mcp__<server>__<word>_<name>` is restored by that suffix (see
|
|
17
|
+
* ToolNameAlias.ts), so such a pair would make the restoration ambiguous.
|
|
18
|
+
* tests/runtime/tool-name-alias.test.ts enforces this across all surfaces.
|
|
14
19
|
*/
|
|
15
20
|
export const baseRuntimeToolNames = [
|
|
16
21
|
"state_list",
|
|
@@ -70,6 +75,16 @@ export function runtimeToolsForNames(names, locale = defaultAppLocale) {
|
|
|
70
75
|
inputSchema: toolDefinitions[name].inputSchema,
|
|
71
76
|
}));
|
|
72
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The original Runtime input schema of a registered tool. Argument repair reads
|
|
80
|
+
* this, not the portable wire projection, so every array or object position is
|
|
81
|
+
* exactly what Runtime validates.
|
|
82
|
+
*/
|
|
83
|
+
export function runtimeToolInputSchema(name, locale = defaultAppLocale) {
|
|
84
|
+
if (!isRegisteredRuntimeToolName(name))
|
|
85
|
+
return null;
|
|
86
|
+
return createToolDefinitions(locale)[name].inputSchema;
|
|
87
|
+
}
|
|
73
88
|
/**
|
|
74
89
|
* Return a Provider-portable root-object schema for a Runtime-owned tool.
|
|
75
90
|
*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function resolveToolName(called, provided) {
|
|
2
|
+
if (provided.includes(called))
|
|
3
|
+
return { kind: "exact", name: called };
|
|
4
|
+
const candidates = provided.filter((name) => called.length > name.length && called.endsWith(`_${name}`));
|
|
5
|
+
if (candidates.length === 1)
|
|
6
|
+
return { kind: "alias", name: candidates[0], declared: called };
|
|
7
|
+
return { kind: "rejected", candidates };
|
|
8
|
+
}
|
|
9
|
+
/** The Runtime note appended to a result whose call was restored by alias. */
|
|
10
|
+
export function renderToolAliasNote(declared, name, locale) {
|
|
11
|
+
return locale === "zh-CN"
|
|
12
|
+
? `Runtime 说明:"${declared}" 不是本次提供的工具,已按 "${name}" 执行。请使用声明的工具名。`
|
|
13
|
+
: `Runtime note: "${declared}" is not a declared tool; it was executed as "${name}". Call tools by their declared names.`;
|
|
14
|
+
}
|