@bacnh85/pi-subagent 0.10.1 → 0.12.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.
@@ -16,21 +16,21 @@ export type ThreadMode = "single" | "parallel-task" | "chain-step";
16
16
  export type ThreadStatus = "running" | "completed" | "failed" | "aborted";
17
17
 
18
18
  export interface SubagentThread {
19
- id: string;
20
- agentName: string;
21
- task: string;
22
- mode: ThreadMode;
23
- status: ThreadStatus;
24
- result?: SubAgentResult;
25
- toolCallId?: string;
26
- color?: string;
27
- createdAt: number;
28
- updatedAt: number;
29
- lastActivityAt?: number;
30
- lastActivityLabel?: string;
31
- lastHeartbeatAt?: number;
32
- inactivityDeadline?: number;
33
- hardDeadline?: number;
19
+ id: string;
20
+ agentName: string;
21
+ task: string;
22
+ mode: ThreadMode;
23
+ status: ThreadStatus;
24
+ result?: SubAgentResult;
25
+ toolCallId?: string;
26
+ color?: string;
27
+ createdAt: number;
28
+ updatedAt: number;
29
+ lastActivityAt?: number;
30
+ lastActivityLabel?: string;
31
+ lastHeartbeatAt?: number;
32
+ inactivityDeadline?: number;
33
+ hardDeadline?: number;
34
34
  }
35
35
 
36
36
  // ---------------------------------------------------------------------------
@@ -38,90 +38,90 @@ export interface SubagentThread {
38
38
  // ---------------------------------------------------------------------------
39
39
 
40
40
  export class ThreadStore {
41
- private threads = new Map<string, SubagentThread>();
42
- private order: string[] = [];
43
- private listeners = new Set<() => void>();
44
-
45
- /** Subscribe to thread store changes. Returns an unsubscribe function. */
46
- subscribe(listener: () => void): () => void {
47
- this.listeners.add(listener);
48
- return () => { this.listeners.delete(listener); };
49
- }
50
-
51
- private notify(): void {
52
- for (const listener of this.listeners) {
53
- try { listener(); } catch { /* best effort */ }
54
- }
55
- }
56
-
57
- createThread(params: {
58
- agentName: string;
59
- task: string;
60
- mode: ThreadMode;
61
- toolCallId?: string;
62
- color?: string;
63
- }): SubagentThread {
64
- const id = cryptoGenId();
65
- const now = Date.now();
66
- const thread: SubagentThread = {
67
- id,
68
- agentName: params.agentName,
69
- task: params.task,
70
- mode: params.mode,
71
- status: "running",
72
- toolCallId: params.toolCallId,
73
- color: params.color,
74
- createdAt: now,
75
- updatedAt: now,
76
- };
77
- this.threads.set(id, thread);
78
- this.order.push(id);
79
- this.notify();
80
- return thread;
81
- }
82
-
83
- updateThread(id: string, updates: Partial<Pick<SubagentThread, "status" | "result">>): void {
84
- const thread = this.threads.get(id);
85
- if (!thread) return;
86
- if (updates.status) thread.status = updates.status;
87
- if (updates.result) thread.result = updates.result;
88
- thread.updatedAt = Date.now();
89
- this.notify();
90
- }
91
-
92
- updateProgress(id: string, progress: SubAgentProgress): void {
93
- const thread = this.threads.get(id);
94
- if (!thread) return;
95
- thread.result = progress.result;
96
- thread.lastActivityAt = progress.at;
97
- thread.lastActivityLabel = progress.label;
98
- thread.inactivityDeadline = progress.inactivityDeadline;
99
- thread.hardDeadline = progress.hardDeadline;
100
- thread.updatedAt = Date.now();
101
- this.notify();
102
- }
103
-
104
- refreshHeartbeat(id: string): void {
105
- const thread = this.threads.get(id);
106
- if (!thread) return;
107
- thread.lastHeartbeatAt = Date.now();
108
- thread.updatedAt = thread.lastHeartbeatAt;
109
- this.notify();
110
- }
111
-
112
- getThread(id: string): SubagentThread | undefined {
113
- return this.threads.get(id);
114
- }
115
-
116
- getAllThreads(): SubagentThread[] {
117
- return this.order.map((id) => this.threads.get(id)!).filter(Boolean);
118
- }
119
-
120
- clear(): void {
121
- this.threads.clear();
122
- this.order = [];
123
- this.notify();
124
- }
41
+ private threads = new Map<string, SubagentThread>();
42
+ private order: string[] = [];
43
+ private listeners = new Set<() => void>();
44
+
45
+ /** Subscribe to thread store changes. Returns an unsubscribe function. */
46
+ subscribe(listener: () => void): () => void {
47
+ this.listeners.add(listener);
48
+ return () => { this.listeners.delete(listener); };
49
+ }
50
+
51
+ private notify(): void {
52
+ for (const listener of this.listeners) {
53
+ try { listener(); } catch { /* best effort */ }
54
+ }
55
+ }
56
+
57
+ createThread(params: {
58
+ agentName: string;
59
+ task: string;
60
+ mode: ThreadMode;
61
+ toolCallId?: string;
62
+ color?: string;
63
+ }): SubagentThread {
64
+ const id = cryptoGenId();
65
+ const now = Date.now();
66
+ const thread: SubagentThread = {
67
+ id,
68
+ agentName: params.agentName,
69
+ task: params.task,
70
+ mode: params.mode,
71
+ status: "running",
72
+ toolCallId: params.toolCallId,
73
+ color: params.color,
74
+ createdAt: now,
75
+ updatedAt: now,
76
+ };
77
+ this.threads.set(id, thread);
78
+ this.order.push(id);
79
+ this.notify();
80
+ return thread;
81
+ }
82
+
83
+ updateThread(id: string, updates: Partial<Pick<SubagentThread, "status" | "result">>): void {
84
+ const thread = this.threads.get(id);
85
+ if (!thread) return;
86
+ if (updates.status) thread.status = updates.status;
87
+ if (updates.result) thread.result = updates.result;
88
+ thread.updatedAt = Date.now();
89
+ this.notify();
90
+ }
91
+
92
+ updateProgress(id: string, progress: SubAgentProgress): void {
93
+ const thread = this.threads.get(id);
94
+ if (!thread) return;
95
+ thread.result = progress.result;
96
+ thread.lastActivityAt = progress.at;
97
+ thread.lastActivityLabel = progress.label;
98
+ thread.inactivityDeadline = progress.inactivityDeadline;
99
+ thread.hardDeadline = progress.hardDeadline;
100
+ thread.updatedAt = Date.now();
101
+ this.notify();
102
+ }
103
+
104
+ refreshHeartbeat(id: string): void {
105
+ const thread = this.threads.get(id);
106
+ if (!thread) return;
107
+ thread.lastHeartbeatAt = Date.now();
108
+ thread.updatedAt = thread.lastHeartbeatAt;
109
+ this.notify();
110
+ }
111
+
112
+ getThread(id: string): SubagentThread | undefined {
113
+ return this.threads.get(id);
114
+ }
115
+
116
+ getAllThreads(): SubagentThread[] {
117
+ return this.order.map((id) => this.threads.get(id)!).filter(Boolean);
118
+ }
119
+
120
+ clear(): void {
121
+ this.threads.clear();
122
+ this.order = [];
123
+ this.notify();
124
+ }
125
125
  }
126
126
 
127
127
  /** Singleton instance. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bacnh85/pi-subagent",
3
- "version": "0.10.1",
3
+ "version": "0.12.2",
4
4
  "description": "In-process subagents for Pi with isolated SDK sessions, parallel and chained delegation, and inspectable threads.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,17 +48,17 @@
48
48
  "check": "npm run typecheck && npm test"
49
49
  },
50
50
  "peerDependencies": {
51
- "@earendil-works/pi-coding-agent": ">=0.80.0 <0.82.0",
52
- "@earendil-works/pi-ai": ">=0.80.0 <0.82.0",
53
- "@earendil-works/pi-agent-core": ">=0.80.0 <0.82.0",
54
- "@earendil-works/pi-tui": ">=0.80.0 <0.82.0",
51
+ "@earendil-works/pi-coding-agent": ">=0.80.0 <0.83.0",
52
+ "@earendil-works/pi-ai": ">=0.80.0 <0.83.0",
53
+ "@earendil-works/pi-agent-core": ">=0.80.0 <0.83.0",
54
+ "@earendil-works/pi-tui": ">=0.80.0 <0.83.0",
55
55
  "typebox": ">=1.3.0 <2.0.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@earendil-works/pi-agent-core": "^0.81.0",
59
- "@earendil-works/pi-ai": "^0.81.0",
60
- "@earendil-works/pi-coding-agent": "^0.81.0",
61
- "@earendil-works/pi-tui": "^0.81.0",
58
+ "@earendil-works/pi-agent-core": "^0.82.0",
59
+ "@earendil-works/pi-ai": "^0.82.0",
60
+ "@earendil-works/pi-coding-agent": "^0.82.0",
61
+ "@earendil-works/pi-tui": "^0.82.0",
62
62
  "@types/mocha": "^10.0.10",
63
63
  "@types/node": "^20.19.43",
64
64
  "mocha": "^10.8.2",