@zhushanwen/pi-pending-notifications 0.2.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-pending-notifications",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Cross-extension async operation registration/query mechanism for Pi — prevents message injection during long-running operations.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@earendil-works/pi-coding-agent": "*",
29
- "@sinclair/typebox": "*"
29
+ "typebox": "*"
30
30
  },
31
31
  "scripts": {
32
32
  "typecheck": "npx tsc --noEmit",
@@ -90,9 +90,15 @@ async function runTool(
90
90
  params: Record<string, unknown>,
91
91
  ): Promise<{ content: Array<{ type: string; text: string }>; details: unknown }> {
92
92
  const tool = setup.registerToolMock.mock.calls[0][0] as {
93
- execute: (p: unknown) => Promise<{ content: Array<{ type: string; text: string }>; details: unknown }>;
93
+ execute: (
94
+ toolCallId: string,
95
+ p: unknown,
96
+ signal: AbortSignal | undefined,
97
+ onUpdate: unknown,
98
+ ctx: ExtensionContext,
99
+ ) => Promise<{ content: Array<{ type: string; text: string }>; details: unknown }>;
94
100
  };
95
- return tool.execute(params);
101
+ return tool.execute("test-call-id", params, undefined, undefined, createMockCtx([]));
96
102
  }
97
103
 
98
104
  async function getCount(setup: MockSetup): Promise<number> {
package/src/index.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
26
- import { Type } from "@sinclair/typebox";
26
+ import { Type } from "typebox";
27
27
 
28
28
  import {
29
29
  createRegistry,
@@ -46,9 +46,12 @@ const PendingNotificationsParams = Type.Object({
46
46
  ]),
47
47
  });
48
48
 
49
- /** tool 入参形状 */
50
- interface ToolParams {
51
- action: "count" | "list";
49
+ /** pending_notifications 工具的 details 形状。两个分支共用同一结构(items 缺省时 undefined),
50
+ * 让 registerTool 泛型对 TDetails 推断一致,避免 union 细节冲突。 */
51
+ interface PendingToolDetails {
52
+ action: string;
53
+ count: number;
54
+ items?: PendingEntry[];
52
55
  }
53
56
 
54
57
  /**
@@ -218,13 +221,12 @@ export default function pendingNotificationsExtension(pi: ExtensionAPI): void {
218
221
  description:
219
222
  "查询当前活跃的异步操作(workflow/subagent)。action=count 返回数量;action=list 返回列表。状态由 EventBus + session entries 维护,无需手动注册。",
220
223
  parameters: PendingNotificationsParams,
221
- execute: async (params: unknown) => {
222
- const p = params as ToolParams;
224
+ execute: async (_toolCallId: string, params: { action: "count" | "list" }, _signal: AbortSignal | undefined, _onUpdate: unknown, _ctx: ExtensionContext): Promise<{ content: { type: "text"; text: string }[]; details: PendingToolDetails }> => {
223
225
  const active = getActive(registry);
224
226
 
225
- debugLog("debug", `tool ${p.action} requested`, { action: p.action, activeCount: active.length });
227
+ debugLog("debug", `tool ${params.action} requested`, { action: params.action, activeCount: active.length });
226
228
 
227
- if (p.action === "count") {
229
+ if (params.action === "count") {
228
230
  return {
229
231
  content: [{ type: "text" as const, text: `${active.length} pending operation(s)` }],
230
232
  details: { action: "count", count: active.length },