narraeon 0.1.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/LICENSE +201 -0
- package/README.md +164 -0
- package/README.zh-CN.md +164 -0
- package/dist/node/cli/NarraeonCli.js +163 -0
- package/dist/node/cli/main.js +38 -0
- package/dist/node/protocol/appPreferences.js +5 -0
- package/dist/node/protocol/contentTree.js +14 -0
- package/dist/node/protocol/modelConnections.js +110 -0
- package/dist/node/protocol/playerViews.js +1 -0
- package/dist/node/protocol/v1.js +278 -0
- package/dist/node/runtime/V1Runtime.js +625 -0
- package/dist/node/runtime/artifact/FileNativeArtifactStore.js +1914 -0
- package/dist/node/runtime/config/AppPreferencesStore.js +92 -0
- package/dist/node/runtime/config/appPaths.js +19 -0
- package/dist/node/runtime/content/ContentLimits.js +1 -0
- package/dist/node/runtime/content/ContentTreeFile.js +1 -0
- package/dist/node/runtime/content/ContentWorkspace.js +601 -0
- package/dist/node/runtime/content/CurrentTreeContentLibrary.js +721 -0
- package/dist/node/runtime/content/FileNativeContentTree.js +512 -0
- package/dist/node/runtime/extension/FrontendExtensionBundle.js +229 -0
- package/dist/node/runtime/extension/PlayerViewPanelProjector.js +121 -0
- package/dist/node/runtime/model/AiFailureLog.js +332 -0
- package/dist/node/runtime/model/FileNativeModelAdapters.js +1246 -0
- package/dist/node/runtime/model/ModelConnectionStore.js +378 -0
- package/dist/node/runtime/model/ModelHost.js +89 -0
- package/dist/node/runtime/model/ModelHostStream.js +367 -0
- package/dist/node/runtime/model/ProviderExchangeState.js +1 -0
- package/dist/node/runtime/model/ProviderStream.js +90 -0
- package/dist/node/runtime/model/SettingAuthorStream.js +118 -0
- package/dist/node/runtime/play/FileNativeContinuityCorrection.js +304 -0
- package/dist/node/runtime/play/FileNativePlayPresetStore.js +1856 -0
- package/dist/node/runtime/play/PlayCallChain.js +1280 -0
- package/dist/node/runtime/play/PlayDocumentTools.js +1121 -0
- package/dist/node/runtime/play/PlayFollowupRequests.js +183 -0
- package/dist/node/runtime/play/PlayPresetWorkbench.js +185 -0
- package/dist/node/runtime/prompt/FileNativePromptCompiler.js +1425 -0
- package/dist/node/runtime/prompt/FileNativeToolRegistry.js +192 -0
- package/dist/node/runtime/prompt/MaterialSelection.js +95 -0
- package/dist/node/runtime/setting/DocumentCandidateSettingImprovement.js +1726 -0
- package/dist/node/runtime/world/FileNativeWorldStore.js +2028 -0
- package/dist/node/runtime/world/PlayerViewRenderer.js +322 -0
- package/dist/node/runtime/world/WorldDocumentStore.js +2808 -0
- package/dist/node/runtime/world/WorldOperationCoordinator.js +490 -0
- package/dist/node/runtime/world/WorldStateRevision.js +75 -0
- package/dist/node/server/createRuntime.js +6 -0
- package/dist/node/server/createServer.js +218 -0
- package/dist/node/server/main.js +25 -0
- package/dist/node/server/startWebServer.js +28 -0
- package/dist/node/shared/default-play-prompts.js +85 -0
- package/dist/node/shared/default-preset-host.js +538 -0
- package/dist/node/shared/default-setting-improvement-prompt.js +77 -0
- package/dist/node/shared/first-party-action-choices.js +164 -0
- package/dist/node/shared/first-party-generic-panels.js +105 -0
- package/dist/node/shared/first-party-play-preset-templates.js +41 -0
- package/dist/node/shared/first-party-player-view.js +179 -0
- package/dist/node/shared/play-preset-prompt-roles.js +4 -0
- package/dist/web/assets/index-CRGTZ9Ak.css +1 -0
- package/dist/web/assets/index-DDx1itzT.js +1192 -0
- package/dist/web/index.html +14 -0
- package/package.json +86 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { chmod, mkdir, open, readFile, rename, stat, unlink, } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { defaultAppLocale, isAppLocale, } from "../../protocol/appPreferences.js";
|
|
5
|
+
const preferencesFileName = "preferences-v1.json";
|
|
6
|
+
export class AppPreferencesStore {
|
|
7
|
+
#configRoot;
|
|
8
|
+
#path;
|
|
9
|
+
#mutationTail = Promise.resolve();
|
|
10
|
+
constructor(configRoot) {
|
|
11
|
+
this.#configRoot = configRoot;
|
|
12
|
+
this.#path = join(configRoot, preferencesFileName);
|
|
13
|
+
}
|
|
14
|
+
async view() {
|
|
15
|
+
await this.#mutationTail;
|
|
16
|
+
return toView(await this.#readDocument());
|
|
17
|
+
}
|
|
18
|
+
save(locale) {
|
|
19
|
+
return this.#mutate(async () => {
|
|
20
|
+
if (!isAppLocale(locale))
|
|
21
|
+
throw new Error("Unsupported app locale");
|
|
22
|
+
const document = { schemaVersion: 1, locale };
|
|
23
|
+
await this.#writeDocument(document);
|
|
24
|
+
return toView(document);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async #mutate(operation) {
|
|
28
|
+
const previous = this.#mutationTail;
|
|
29
|
+
let release = () => undefined;
|
|
30
|
+
this.#mutationTail = new Promise((resolve) => {
|
|
31
|
+
release = resolve;
|
|
32
|
+
});
|
|
33
|
+
await previous;
|
|
34
|
+
try {
|
|
35
|
+
return await operation();
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
release();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async #readDocument() {
|
|
42
|
+
try {
|
|
43
|
+
const info = await stat(this.#path);
|
|
44
|
+
if (!info.isFile())
|
|
45
|
+
throw new Error("App preferences path is not a file");
|
|
46
|
+
return validateDocument(JSON.parse(await readFile(this.#path, "utf8")));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (!isMissingFile(error))
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
return { schemaVersion: 1, locale: defaultAppLocale };
|
|
53
|
+
}
|
|
54
|
+
async #writeDocument(document) {
|
|
55
|
+
await mkdir(this.#configRoot, { recursive: true, mode: 0o700 });
|
|
56
|
+
const temporary = join(this.#configRoot, `.${preferencesFileName}.${randomUUID()}.tmp`);
|
|
57
|
+
let handle;
|
|
58
|
+
try {
|
|
59
|
+
handle = await open(temporary, "wx", 0o600);
|
|
60
|
+
await handle.writeFile(`${JSON.stringify(document, null, 2)}\n`, "utf8");
|
|
61
|
+
await handle.sync();
|
|
62
|
+
await handle.close();
|
|
63
|
+
handle = undefined;
|
|
64
|
+
await chmod(temporary, 0o600);
|
|
65
|
+
await rename(temporary, this.#path);
|
|
66
|
+
await chmod(this.#path, 0o600);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
await handle?.close().catch(() => undefined);
|
|
70
|
+
await unlink(temporary).catch(() => undefined);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function validateDocument(value) {
|
|
76
|
+
if (typeof value !== "object" ||
|
|
77
|
+
value === null ||
|
|
78
|
+
Array.isArray(value) ||
|
|
79
|
+
!("schemaVersion" in value) ||
|
|
80
|
+
value.schemaVersion !== 1 ||
|
|
81
|
+
!("locale" in value) ||
|
|
82
|
+
!isAppLocale(value.locale) ||
|
|
83
|
+
Object.keys(value).some((key) => key !== "schemaVersion" && key !== "locale"))
|
|
84
|
+
throw new Error("App preferences file does not match the v1 schema");
|
|
85
|
+
return { schemaVersion: 1, locale: value.locale };
|
|
86
|
+
}
|
|
87
|
+
function toView(document) {
|
|
88
|
+
return { locale: document.locale };
|
|
89
|
+
}
|
|
90
|
+
function isMissingFile(error) {
|
|
91
|
+
return error.code === "ENOENT";
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import envPaths from "env-paths";
|
|
3
|
+
export function resolveAppPaths(environment) {
|
|
4
|
+
const defaults = envPaths("narraeon", { suffix: "" });
|
|
5
|
+
const configuredDataRoot = environment.NARRAEON_DATA_ROOT?.trim();
|
|
6
|
+
const configuredConfigRoot = environment.NARRAEON_CONFIG_ROOT?.trim();
|
|
7
|
+
const configuredLogRoot = environment.NARRAEON_LOG_ROOT?.trim();
|
|
8
|
+
return {
|
|
9
|
+
configRoot: configuredConfigRoot !== undefined && configuredConfigRoot.length > 0
|
|
10
|
+
? resolve(configuredConfigRoot)
|
|
11
|
+
: defaults.config,
|
|
12
|
+
dataRoot: configuredDataRoot !== undefined && configuredDataRoot.length > 0
|
|
13
|
+
? resolve(configuredDataRoot)
|
|
14
|
+
: defaults.data,
|
|
15
|
+
logRoot: configuredLogRoot !== undefined && configuredLogRoot.length > 0
|
|
16
|
+
? resolve(configuredLogRoot)
|
|
17
|
+
: defaults.log,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defaultPortableContentTreeLimits as defaultContentWorkspaceLimits, maximumPortableContentArchiveBytes, } from "../../protocol/contentTree.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|