@zihanw/pi-forge 0.3.0 → 0.3.2
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/README.md +87 -2
- package/README.zh-CN.md +72 -2
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +490 -0
- package/dist/compiler.js.map +1 -0
- package/dist/extension-registry.d.ts +25 -0
- package/dist/extension-registry.d.ts.map +1 -0
- package/dist/extension-registry.js +6 -0
- package/dist/extension-registry.js.map +1 -0
- package/dist/forge-extensions.d.ts +28 -0
- package/dist/forge-extensions.d.ts.map +1 -0
- package/dist/forge-extensions.js +182 -0
- package/dist/forge-extensions.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +376 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +14 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +139 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/loader.d.ts +8 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +345 -0
- package/dist/loader.js.map +1 -0
- package/dist/macro-engine.d.ts +23 -0
- package/dist/macro-engine.d.ts.map +1 -0
- package/dist/macro-engine.js +262 -0
- package/dist/macro-engine.js.map +1 -0
- package/dist/payload-capture.d.ts +15 -0
- package/dist/payload-capture.d.ts.map +1 -0
- package/dist/payload-capture.js +86 -0
- package/dist/payload-capture.js.map +1 -0
- package/dist/payload-command.d.ts +10 -0
- package/dist/payload-command.d.ts.map +1 -0
- package/dist/payload-command.js +112 -0
- package/dist/payload-command.js.map +1 -0
- package/dist/policy.d.ts +6 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +38 -0
- package/dist/policy.js.map +1 -0
- package/dist/preset-command.d.ts +14 -0
- package/dist/preset-command.d.ts.map +1 -0
- package/dist/preset-command.js +232 -0
- package/dist/preset-command.js.map +1 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +179 -0
- package/dist/preview.js.map +1 -0
- package/dist/regex.d.ts +7 -0
- package/dist/regex.d.ts.map +1 -0
- package/dist/regex.js +432 -0
- package/dist/regex.js.map +1 -0
- package/dist/render-helpers.d.ts +44 -0
- package/dist/render-helpers.d.ts.map +1 -0
- package/dist/render-helpers.js +128 -0
- package/dist/render-helpers.js.map +1 -0
- package/dist/runtime-state.d.ts +26 -0
- package/dist/runtime-state.d.ts.map +1 -0
- package/dist/runtime-state.js +15 -0
- package/dist/runtime-state.js.map +1 -0
- package/dist/sillytavern-importer/items.d.ts +3 -0
- package/dist/sillytavern-importer/items.d.ts.map +1 -0
- package/dist/sillytavern-importer/items.js +88 -0
- package/dist/sillytavern-importer/items.js.map +1 -0
- package/dist/sillytavern-importer/macros.d.ts +15 -0
- package/dist/sillytavern-importer/macros.d.ts.map +1 -0
- package/dist/sillytavern-importer/macros.js +141 -0
- package/dist/sillytavern-importer/macros.js.map +1 -0
- package/dist/sillytavern-importer/prompt-order.d.ts +6 -0
- package/dist/sillytavern-importer/prompt-order.d.ts.map +1 -0
- package/dist/sillytavern-importer/prompt-order.js +38 -0
- package/dist/sillytavern-importer/prompt-order.js.map +1 -0
- package/dist/sillytavern-importer/regex.d.ts +3 -0
- package/dist/sillytavern-importer/regex.d.ts.map +1 -0
- package/dist/sillytavern-importer/regex.js +275 -0
- package/dist/sillytavern-importer/regex.js.map +1 -0
- package/dist/sillytavern-importer/report.d.ts +21 -0
- package/dist/sillytavern-importer/report.d.ts.map +1 -0
- package/dist/sillytavern-importer/report.js +166 -0
- package/dist/sillytavern-importer/report.js.map +1 -0
- package/dist/sillytavern-importer/types.d.ts +106 -0
- package/dist/sillytavern-importer/types.d.ts.map +1 -0
- package/dist/sillytavern-importer/types.js +2 -0
- package/dist/sillytavern-importer/types.js.map +1 -0
- package/dist/sillytavern-importer.d.ts +5 -0
- package/dist/sillytavern-importer.d.ts.map +1 -0
- package/dist/sillytavern-importer.js +117 -0
- package/dist/sillytavern-importer.js.map +1 -0
- package/dist/slot-renderers.d.ts +25 -0
- package/dist/slot-renderers.d.ts.map +1 -0
- package/dist/slot-renderers.js +334 -0
- package/dist/slot-renderers.js.map +1 -0
- package/dist/stack-migration.d.ts +29 -0
- package/dist/stack-migration.d.ts.map +1 -0
- package/dist/stack-migration.js +126 -0
- package/dist/stack-migration.js.map +1 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +36 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +173 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/web-editor/index.d.ts +3 -0
- package/dist/web-editor/index.d.ts.map +1 -0
- package/dist/web-editor/index.js +2 -0
- package/dist/web-editor/index.js.map +1 -0
- package/dist/web-editor/page.d.ts +2 -0
- package/dist/web-editor/page.d.ts.map +1 -0
- package/dist/web-editor/page.js +3331 -0
- package/dist/web-editor/page.js.map +1 -0
- package/dist/web-editor/server.d.ts +4 -0
- package/dist/web-editor/server.d.ts.map +1 -0
- package/dist/web-editor/server.js +263 -0
- package/dist/web-editor/server.js.map +1 -0
- package/dist/web-editor/types.d.ts +125 -0
- package/dist/web-editor/types.d.ts.map +1 -0
- package/dist/web-editor/types.js +2 -0
- package/dist/web-editor/types.js.map +1 -0
- package/dist/web-host.d.ts +29 -0
- package/dist/web-host.d.ts.map +1 -0
- package/dist/web-host.js +174 -0
- package/dist/web-host.js.map +1 -0
- package/examples/custom-system-status-extension/README.md +85 -0
- package/examples/custom-system-status-extension/index.ts +136 -0
- package/examples/custom-system-status-extension/prompt-stack.json +39 -0
- package/examples/image-reader-prompt-stack.json +124 -0
- package/package.json +28 -2
- package/src/compiler.ts +2 -472
- package/src/extension-registry.ts +33 -0
- package/src/forge-extensions.ts +223 -0
- package/src/index.ts +208 -653
- package/src/lifecycle.ts +171 -0
- package/src/macro-engine.ts +358 -0
- package/src/payload-command.ts +138 -0
- package/src/preset-command.ts +280 -0
- package/src/preview.ts +226 -0
- package/src/render-helpers.ts +169 -0
- package/src/runtime-state.ts +40 -0
- package/src/sillytavern-importer/items.ts +98 -0
- package/src/sillytavern-importer/macros.ts +159 -0
- package/src/sillytavern-importer/prompt-order.ts +54 -0
- package/src/sillytavern-importer/regex.ts +270 -0
- package/src/sillytavern-importer/report.ts +202 -0
- package/src/sillytavern-importer/types.ts +120 -0
- package/src/sillytavern-importer.ts +55 -865
- package/src/slot-renderers.ts +414 -0
- package/src/storage.ts +17 -0
- package/src/types.ts +3 -14
- package/src/web-editor/page.ts +516 -30
- package/src/web-editor/server.ts +9 -4
- package/src/web-editor/types.ts +18 -4
- package/src/web-host.ts +16 -13
package/src/web-editor/server.ts
CHANGED
|
@@ -78,6 +78,11 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
|
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
if (req.method === "GET" && parts[1] === "resources" && parts.length === 2) {
|
|
82
|
+
sendJson(res, 200, host.listResources());
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
81
86
|
if (req.method === "POST" && parts[1] === "stacks" && parts.length === 2) {
|
|
82
87
|
const body = await readJsonBody(req);
|
|
83
88
|
const parsed = readStackPayload(body);
|
|
@@ -88,7 +93,7 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
|
|
|
88
93
|
const options = isPlainObject(body)
|
|
89
94
|
? { activate: body.activate === true, overwrite: body.overwrite === true }
|
|
90
95
|
: {};
|
|
91
|
-
const result = host.createStack(parsed.stack, options);
|
|
96
|
+
const result = await host.createStack(parsed.stack, options);
|
|
92
97
|
if (result.ok && parsed.importFormat) {
|
|
93
98
|
sendJson(res, 200, { ...result, importFormat: parsed.importFormat, importReport: parsed.importReport });
|
|
94
99
|
return;
|
|
@@ -114,12 +119,12 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
|
|
|
114
119
|
sendJson(res, 400, { error: parsed.error });
|
|
115
120
|
return;
|
|
116
121
|
}
|
|
117
|
-
sendOperation(res, host.saveStack(parts[2]!, parsed.stack));
|
|
122
|
+
sendOperation(res, await host.saveStack(parts[2]!, parsed.stack));
|
|
118
123
|
return;
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
if (req.method === "DELETE" && parts[1] === "stacks" && parts.length === 3) {
|
|
122
|
-
sendOperation(res, host.deleteStack(parts[2]!));
|
|
127
|
+
sendOperation(res, await host.deleteStack(parts[2]!));
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -173,7 +178,7 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
|
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
if (req.method === "POST" && parts[1] === "reload" && parts.length === 2) {
|
|
176
|
-
sendOperation(res, host.reloadStacks());
|
|
181
|
+
sendOperation(res, await host.reloadStacks());
|
|
177
182
|
return;
|
|
178
183
|
}
|
|
179
184
|
|
package/src/web-editor/types.ts
CHANGED
|
@@ -16,10 +16,11 @@ export interface WebEditorStackSummary {
|
|
|
16
16
|
export interface WebEditorHost {
|
|
17
17
|
cwd: string;
|
|
18
18
|
listStacks(): WebEditorStackSummary[];
|
|
19
|
+
listResources(): WebEditorPolicyResources;
|
|
19
20
|
getStack(id: string): { stack: PromptStack; filePath: string; diagnostics: PromptStackDiagnostic[] } | undefined;
|
|
20
|
-
createStack(stack: PromptStack, options: WebEditorCreateStackOptions): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }
|
|
21
|
-
saveStack(id: string, stack: PromptStack): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }
|
|
22
|
-
deleteStack(id: string): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }
|
|
21
|
+
createStack(stack: PromptStack, options: WebEditorCreateStackOptions): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>>;
|
|
22
|
+
saveStack(id: string, stack: PromptStack): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>>;
|
|
23
|
+
deleteStack(id: string): Promise<WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>>;
|
|
23
24
|
validateStack(stack: PromptStack): PromptStackDiagnostic[];
|
|
24
25
|
previewStack(id: string, stack: PromptStack): WebEditorOperationResult<{ text: string; preview?: WebEditorPreview; diagnostics: PromptStackDiagnostic[] }>;
|
|
25
26
|
getPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
|
|
@@ -27,7 +28,7 @@ export interface WebEditorHost {
|
|
|
27
28
|
clearPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
|
|
28
29
|
activateStack(id: string): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>;
|
|
29
30
|
disableStacks(): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>;
|
|
30
|
-
reloadStacks(): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }
|
|
31
|
+
reloadStacks(): Promise<WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>>;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export interface WebEditorPreviewSection {
|
|
@@ -70,6 +71,19 @@ export interface WebEditorCreateStackOptions {
|
|
|
70
71
|
overwrite?: boolean;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
export interface WebEditorPolicyResource {
|
|
75
|
+
name: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
source?: string;
|
|
78
|
+
active?: boolean;
|
|
79
|
+
hidden?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface WebEditorPolicyResources {
|
|
83
|
+
tools: WebEditorPolicyResource[];
|
|
84
|
+
skills: WebEditorPolicyResource[];
|
|
85
|
+
}
|
|
86
|
+
|
|
73
87
|
export type WebEditorOperationResult<T> = ({ ok: true } & T) | { ok: false; status?: number; error: string };
|
|
74
88
|
|
|
75
89
|
export interface WebEditorServer {
|
package/src/web-host.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
WebEditorHost,
|
|
13
13
|
WebEditorOperationResult,
|
|
14
14
|
WebEditorPayloadSnapshot,
|
|
15
|
+
WebEditorPolicyResources,
|
|
15
16
|
WebEditorPreview,
|
|
16
17
|
WebEditorStackSummary,
|
|
17
18
|
} from "./web-editor/index.ts";
|
|
@@ -22,12 +23,13 @@ export interface WebHostRuntime {
|
|
|
22
23
|
getActiveId(): string | undefined;
|
|
23
24
|
getSelectedActiveId(): string | undefined;
|
|
24
25
|
setActive(id: string | undefined): boolean;
|
|
25
|
-
reloadStacks(preferredId?: string): void
|
|
26
|
+
reloadStacks(preferredId?: string): Promise<void>;
|
|
26
27
|
buildPreview(target: LoadedPromptStack): {
|
|
27
28
|
text: string;
|
|
28
29
|
preview: WebEditorPreview;
|
|
29
30
|
diagnostics: PromptStackDiagnostic[];
|
|
30
31
|
};
|
|
32
|
+
getPolicyResources(): WebEditorPolicyResources;
|
|
31
33
|
getPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
|
|
32
34
|
armPayload(savePath?: string): WebEditorOperationResult<WebEditorPayloadSnapshot>;
|
|
33
35
|
clearPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
|
|
@@ -37,6 +39,7 @@ export function createWebEditorHost(ctx: ExtensionCommandContext, runtime: WebHo
|
|
|
37
39
|
return {
|
|
38
40
|
cwd: ctx.cwd,
|
|
39
41
|
listStacks: () => stackSummaries(runtime.getStacks(), runtime.getActive()),
|
|
42
|
+
listResources: () => runtime.getPolicyResources(),
|
|
40
43
|
getStack: (id) => {
|
|
41
44
|
const loaded = runtime.getStacks().find((candidate) => candidate.stack.id === id);
|
|
42
45
|
return loaded ? { stack: loaded.stack, filePath: loaded.filePath, diagnostics: loaded.diagnostics } : undefined;
|
|
@@ -63,8 +66,8 @@ export function createWebEditorHost(ctx: ExtensionCommandContext, runtime: WebHo
|
|
|
63
66
|
runtime.setActive("none");
|
|
64
67
|
return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
|
|
65
68
|
},
|
|
66
|
-
reloadStacks: () => {
|
|
67
|
-
runtime.reloadStacks(runtime.getSelectedActiveId());
|
|
69
|
+
reloadStacks: async () => {
|
|
70
|
+
await runtime.reloadStacks(runtime.getSelectedActiveId());
|
|
68
71
|
return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
|
|
69
72
|
},
|
|
70
73
|
};
|
|
@@ -128,12 +131,12 @@ export function loadWebEditorSettings(ctx: ExtensionCommandContext): { preferred
|
|
|
128
131
|
};
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
function saveStackFile(
|
|
134
|
+
async function saveStackFile(
|
|
132
135
|
ctx: ExtensionCommandContext,
|
|
133
136
|
runtime: WebHostRuntime,
|
|
134
137
|
id: string,
|
|
135
138
|
stack: PromptStack,
|
|
136
|
-
): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }
|
|
139
|
+
): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>> {
|
|
137
140
|
if (!ctx.isProjectTrusted()) {
|
|
138
141
|
return { ok: false, status: 403, error: "Project is not trusted; refusing to save prompt stacks." };
|
|
139
142
|
}
|
|
@@ -146,18 +149,18 @@ function saveStackFile(
|
|
|
146
149
|
|
|
147
150
|
writeFileSync(target.filePath, `${JSON.stringify(stack, null, 2)}\n`, "utf8");
|
|
148
151
|
const preferredId = runtime.getActive()?.stack.id === id ? stack.id : runtime.getSelectedActiveId();
|
|
149
|
-
runtime.reloadStacks(preferredId);
|
|
152
|
+
await runtime.reloadStacks(preferredId);
|
|
150
153
|
const saved = runtime.getStacks().find((candidate) => candidate.stack.id === stack.id) ?? runtime.getStacks().find((candidate) => candidate.filePath === target.filePath);
|
|
151
154
|
if (!saved) return { ok: false, status: 500, error: "Saved stack could not be reloaded." };
|
|
152
155
|
return { ok: true, stack: stackSummary(saved, runtime.getActive()), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
|
|
153
156
|
}
|
|
154
157
|
|
|
155
|
-
function createStackFile(
|
|
158
|
+
async function createStackFile(
|
|
156
159
|
ctx: ExtensionCommandContext,
|
|
157
160
|
runtime: WebHostRuntime,
|
|
158
161
|
stack: PromptStack,
|
|
159
162
|
options: WebEditorCreateStackOptions,
|
|
160
|
-
): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }
|
|
163
|
+
): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>> {
|
|
161
164
|
if (!ctx.isProjectTrusted()) {
|
|
162
165
|
return { ok: false, status: 403, error: "Project is not trusted; refusing to create prompt stacks." };
|
|
163
166
|
}
|
|
@@ -182,7 +185,7 @@ function createStackFile(
|
|
|
182
185
|
const previousSelection = runtime.getSelectedActiveId();
|
|
183
186
|
mkdirSync(dirname(targetPath), { recursive: true });
|
|
184
187
|
writeFileSync(targetPath, `${JSON.stringify(stack, null, 2)}\n`, "utf8");
|
|
185
|
-
runtime.reloadStacks(options.activate ? stack.id : (previousSelection ?? "none"));
|
|
188
|
+
await runtime.reloadStacks(options.activate ? stack.id : (previousSelection ?? "none"));
|
|
186
189
|
if (options.activate) runtime.setActive(stack.id);
|
|
187
190
|
|
|
188
191
|
const created = runtime.getStacks().find((candidate) => candidate.stack.id === stack.id);
|
|
@@ -190,11 +193,11 @@ function createStackFile(
|
|
|
190
193
|
return { ok: true, stack: stackSummary(created, runtime.getActive()), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
|
|
191
194
|
}
|
|
192
195
|
|
|
193
|
-
function deleteStackFile(
|
|
196
|
+
async function deleteStackFile(
|
|
194
197
|
ctx: ExtensionCommandContext,
|
|
195
198
|
runtime: WebHostRuntime,
|
|
196
199
|
id: string,
|
|
197
|
-
): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }
|
|
200
|
+
): Promise<WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>> {
|
|
198
201
|
if (!ctx.isProjectTrusted()) {
|
|
199
202
|
return { ok: false, status: 403, error: "Project is not trusted; refusing to delete prompt stacks." };
|
|
200
203
|
}
|
|
@@ -209,9 +212,9 @@ function deleteStackFile(
|
|
|
209
212
|
unlinkSync(target.filePath);
|
|
210
213
|
if (wasActive) {
|
|
211
214
|
runtime.setActive("none");
|
|
212
|
-
runtime.reloadStacks("none");
|
|
215
|
+
await runtime.reloadStacks("none");
|
|
213
216
|
} else {
|
|
214
|
-
runtime.reloadStacks(runtime.getSelectedActiveId());
|
|
217
|
+
await runtime.reloadStacks(runtime.getSelectedActiveId());
|
|
215
218
|
}
|
|
216
219
|
return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
|
|
217
220
|
}
|