@zihanw/pi-forge 0.3.1 → 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.
Files changed (47) hide show
  1. package/README.md +31 -24
  2. package/README.zh-CN.md +31 -24
  3. package/dist/forge-extensions.d.ts +28 -0
  4. package/dist/forge-extensions.d.ts.map +1 -0
  5. package/dist/forge-extensions.js +182 -0
  6. package/dist/forge-extensions.js.map +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +13 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/lifecycle.d.ts +1 -1
  12. package/dist/lifecycle.d.ts.map +1 -1
  13. package/dist/lifecycle.js +5 -5
  14. package/dist/lifecycle.js.map +1 -1
  15. package/dist/preset-command.d.ts +1 -1
  16. package/dist/preset-command.d.ts.map +1 -1
  17. package/dist/preset-command.js +12 -3
  18. package/dist/preset-command.js.map +1 -1
  19. package/dist/runtime-state.d.ts +2 -0
  20. package/dist/runtime-state.d.ts.map +1 -1
  21. package/dist/runtime-state.js +2 -0
  22. package/dist/runtime-state.js.map +1 -1
  23. package/dist/storage.d.ts +4 -0
  24. package/dist/storage.d.ts.map +1 -1
  25. package/dist/storage.js +13 -0
  26. package/dist/storage.js.map +1 -1
  27. package/dist/web-editor/server.js +4 -4
  28. package/dist/web-editor/server.js.map +1 -1
  29. package/dist/web-editor/types.d.ts +8 -8
  30. package/dist/web-editor/types.d.ts.map +1 -1
  31. package/dist/web-host.d.ts +1 -1
  32. package/dist/web-host.d.ts.map +1 -1
  33. package/dist/web-host.js +9 -9
  34. package/dist/web-host.js.map +1 -1
  35. package/examples/custom-system-status-extension/README.md +34 -27
  36. package/examples/custom-system-status-extension/index.ts +71 -111
  37. package/examples/custom-system-status-extension/prompt-stack.json +1 -1
  38. package/package.json +1 -1
  39. package/src/forge-extensions.ts +223 -0
  40. package/src/index.ts +16 -1
  41. package/src/lifecycle.ts +6 -6
  42. package/src/preset-command.ts +13 -4
  43. package/src/runtime-state.ts +4 -0
  44. package/src/storage.ts +17 -0
  45. package/src/web-editor/server.ts +4 -4
  46. package/src/web-editor/types.ts +4 -4
  47. package/src/web-host.ts +13 -13
@@ -93,7 +93,7 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
93
93
  const options = isPlainObject(body)
94
94
  ? { activate: body.activate === true, overwrite: body.overwrite === true }
95
95
  : {};
96
- const result = host.createStack(parsed.stack, options);
96
+ const result = await host.createStack(parsed.stack, options);
97
97
  if (result.ok && parsed.importFormat) {
98
98
  sendJson(res, 200, { ...result, importFormat: parsed.importFormat, importReport: parsed.importReport });
99
99
  return;
@@ -119,12 +119,12 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
119
119
  sendJson(res, 400, { error: parsed.error });
120
120
  return;
121
121
  }
122
- sendOperation(res, host.saveStack(parts[2]!, parsed.stack));
122
+ sendOperation(res, await host.saveStack(parts[2]!, parsed.stack));
123
123
  return;
124
124
  }
125
125
 
126
126
  if (req.method === "DELETE" && parts[1] === "stacks" && parts.length === 3) {
127
- sendOperation(res, host.deleteStack(parts[2]!));
127
+ sendOperation(res, await host.deleteStack(parts[2]!));
128
128
  return;
129
129
  }
130
130
 
@@ -178,7 +178,7 @@ async function handleRequest(host: WebEditorHost, token: string, req: IncomingMe
178
178
  }
179
179
 
180
180
  if (req.method === "POST" && parts[1] === "reload" && parts.length === 2) {
181
- sendOperation(res, host.reloadStacks());
181
+ sendOperation(res, await host.reloadStacks());
182
182
  return;
183
183
  }
184
184
 
@@ -18,9 +18,9 @@ export interface WebEditorHost {
18
18
  listStacks(): WebEditorStackSummary[];
19
19
  listResources(): WebEditorPolicyResources;
20
20
  getStack(id: string): { stack: PromptStack; filePath: string; diagnostics: PromptStackDiagnostic[] } | undefined;
21
- createStack(stack: PromptStack, options: WebEditorCreateStackOptions): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>;
22
- saveStack(id: string, stack: PromptStack): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>;
23
- 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[] }>>;
24
24
  validateStack(stack: PromptStack): PromptStackDiagnostic[];
25
25
  previewStack(id: string, stack: PromptStack): WebEditorOperationResult<{ text: string; preview?: WebEditorPreview; diagnostics: PromptStackDiagnostic[] }>;
26
26
  getPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
@@ -28,7 +28,7 @@ export interface WebEditorHost {
28
28
  clearPayload(): WebEditorOperationResult<WebEditorPayloadSnapshot>;
29
29
  activateStack(id: string): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>;
30
30
  disableStacks(): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>;
31
- reloadStacks(): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>;
31
+ reloadStacks(): Promise<WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>>;
32
32
  }
33
33
 
34
34
  export interface WebEditorPreviewSection {
package/src/web-host.ts CHANGED
@@ -23,7 +23,7 @@ export interface WebHostRuntime {
23
23
  getActiveId(): string | undefined;
24
24
  getSelectedActiveId(): string | undefined;
25
25
  setActive(id: string | undefined): boolean;
26
- reloadStacks(preferredId?: string): void;
26
+ reloadStacks(preferredId?: string): Promise<void>;
27
27
  buildPreview(target: LoadedPromptStack): {
28
28
  text: string;
29
29
  preview: WebEditorPreview;
@@ -66,8 +66,8 @@ export function createWebEditorHost(ctx: ExtensionCommandContext, runtime: WebHo
66
66
  runtime.setActive("none");
67
67
  return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
68
68
  },
69
- reloadStacks: () => {
70
- runtime.reloadStacks(runtime.getSelectedActiveId());
69
+ reloadStacks: async () => {
70
+ await runtime.reloadStacks(runtime.getSelectedActiveId());
71
71
  return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
72
72
  },
73
73
  };
@@ -131,12 +131,12 @@ export function loadWebEditorSettings(ctx: ExtensionCommandContext): { preferred
131
131
  };
132
132
  }
133
133
 
134
- function saveStackFile(
134
+ async function saveStackFile(
135
135
  ctx: ExtensionCommandContext,
136
136
  runtime: WebHostRuntime,
137
137
  id: string,
138
138
  stack: PromptStack,
139
- ): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }> {
139
+ ): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>> {
140
140
  if (!ctx.isProjectTrusted()) {
141
141
  return { ok: false, status: 403, error: "Project is not trusted; refusing to save prompt stacks." };
142
142
  }
@@ -149,18 +149,18 @@ function saveStackFile(
149
149
 
150
150
  writeFileSync(target.filePath, `${JSON.stringify(stack, null, 2)}\n`, "utf8");
151
151
  const preferredId = runtime.getActive()?.stack.id === id ? stack.id : runtime.getSelectedActiveId();
152
- runtime.reloadStacks(preferredId);
152
+ await runtime.reloadStacks(preferredId);
153
153
  const saved = runtime.getStacks().find((candidate) => candidate.stack.id === stack.id) ?? runtime.getStacks().find((candidate) => candidate.filePath === target.filePath);
154
154
  if (!saved) return { ok: false, status: 500, error: "Saved stack could not be reloaded." };
155
155
  return { ok: true, stack: stackSummary(saved, runtime.getActive()), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
156
156
  }
157
157
 
158
- function createStackFile(
158
+ async function createStackFile(
159
159
  ctx: ExtensionCommandContext,
160
160
  runtime: WebHostRuntime,
161
161
  stack: PromptStack,
162
162
  options: WebEditorCreateStackOptions,
163
- ): WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }> {
163
+ ): Promise<WebEditorOperationResult<{ stack: WebEditorStackSummary; stacks: WebEditorStackSummary[] }>> {
164
164
  if (!ctx.isProjectTrusted()) {
165
165
  return { ok: false, status: 403, error: "Project is not trusted; refusing to create prompt stacks." };
166
166
  }
@@ -185,7 +185,7 @@ function createStackFile(
185
185
  const previousSelection = runtime.getSelectedActiveId();
186
186
  mkdirSync(dirname(targetPath), { recursive: true });
187
187
  writeFileSync(targetPath, `${JSON.stringify(stack, null, 2)}\n`, "utf8");
188
- runtime.reloadStacks(options.activate ? stack.id : (previousSelection ?? "none"));
188
+ await runtime.reloadStacks(options.activate ? stack.id : (previousSelection ?? "none"));
189
189
  if (options.activate) runtime.setActive(stack.id);
190
190
 
191
191
  const created = runtime.getStacks().find((candidate) => candidate.stack.id === stack.id);
@@ -193,11 +193,11 @@ function createStackFile(
193
193
  return { ok: true, stack: stackSummary(created, runtime.getActive()), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
194
194
  }
195
195
 
196
- function deleteStackFile(
196
+ async function deleteStackFile(
197
197
  ctx: ExtensionCommandContext,
198
198
  runtime: WebHostRuntime,
199
199
  id: string,
200
- ): WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }> {
200
+ ): Promise<WebEditorOperationResult<{ activeId?: string; stacks: WebEditorStackSummary[] }>> {
201
201
  if (!ctx.isProjectTrusted()) {
202
202
  return { ok: false, status: 403, error: "Project is not trusted; refusing to delete prompt stacks." };
203
203
  }
@@ -212,9 +212,9 @@ function deleteStackFile(
212
212
  unlinkSync(target.filePath);
213
213
  if (wasActive) {
214
214
  runtime.setActive("none");
215
- runtime.reloadStacks("none");
215
+ await runtime.reloadStacks("none");
216
216
  } else {
217
- runtime.reloadStacks(runtime.getSelectedActiveId());
217
+ await runtime.reloadStacks(runtime.getSelectedActiveId());
218
218
  }
219
219
  return { ok: true, activeId: runtime.getActiveId(), stacks: stackSummaries(runtime.getStacks(), runtime.getActive()) };
220
220
  }