@agent-link/agent 0.1.79 → 0.1.80
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/dist/claude.d.ts +13 -1
- package/dist/claude.js +32 -5
- package/dist/claude.js.map +1 -1
- package/dist/connection.js +78 -3
- package/dist/connection.js.map +1 -1
- package/dist/sdk.js +2 -0
- package/dist/sdk.js.map +1 -1
- package/dist/team.d.ts +250 -0
- package/dist/team.js +1046 -0
- package/dist/team.js.map +1 -0
- package/package.json +1 -1
package/dist/team.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Team module — manages team state, output stream parsing,
|
|
3
|
+
* and team lifecycle for multi-agent team mode.
|
|
4
|
+
*
|
|
5
|
+
* team.ts is an observer, not an orchestrator: it intercepts the Lead's
|
|
6
|
+
* output stream to extract UI state (agent list, task board, activity feed)
|
|
7
|
+
* while the Lead Claude process drives all planning/execution autonomously.
|
|
8
|
+
*/
|
|
9
|
+
export interface TeamConfig {
|
|
10
|
+
instruction: string;
|
|
11
|
+
template?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AgentRole {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
color: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TaskItem {
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description: string;
|
|
22
|
+
status: 'pending' | 'active' | 'done' | 'failed';
|
|
23
|
+
assignee: string | null;
|
|
24
|
+
toolUseId: string | null;
|
|
25
|
+
agentTaskId: string | null;
|
|
26
|
+
dependencies: string[];
|
|
27
|
+
createdAt: number;
|
|
28
|
+
updatedAt: number;
|
|
29
|
+
}
|
|
30
|
+
export interface TeamState {
|
|
31
|
+
teamId: string;
|
|
32
|
+
title: string;
|
|
33
|
+
config: TeamConfig;
|
|
34
|
+
conversationId: string;
|
|
35
|
+
claudeSessionId: string | null;
|
|
36
|
+
agents: Map<string, AgentTeammate>;
|
|
37
|
+
tasks: TaskItem[];
|
|
38
|
+
feed: TeamFeedEntry[];
|
|
39
|
+
status: 'planning' | 'running' | 'summarizing' | 'completed' | 'failed';
|
|
40
|
+
leadStatus: string;
|
|
41
|
+
summary: string | null;
|
|
42
|
+
totalCost: number;
|
|
43
|
+
durationMs: number;
|
|
44
|
+
createdAt: number;
|
|
45
|
+
}
|
|
46
|
+
export interface AgentTeammate {
|
|
47
|
+
role: AgentRole;
|
|
48
|
+
toolUseId: string | null;
|
|
49
|
+
agentTaskId: string | null;
|
|
50
|
+
status: 'starting' | 'working' | 'done' | 'error';
|
|
51
|
+
currentTaskId: string | null;
|
|
52
|
+
messages: TeamAgentMessage[];
|
|
53
|
+
}
|
|
54
|
+
export interface TeamAgentMessage {
|
|
55
|
+
id: number;
|
|
56
|
+
role: 'assistant' | 'tool' | 'user';
|
|
57
|
+
content?: string;
|
|
58
|
+
toolName?: string;
|
|
59
|
+
toolInput?: string;
|
|
60
|
+
toolOutput?: string;
|
|
61
|
+
hasResult?: boolean;
|
|
62
|
+
timestamp: number;
|
|
63
|
+
}
|
|
64
|
+
export interface TeamFeedEntry {
|
|
65
|
+
timestamp: number;
|
|
66
|
+
agentId: string;
|
|
67
|
+
type: 'task_started' | 'task_completed' | 'task_failed' | 'tool_call' | 'status_change' | 'lead_activity';
|
|
68
|
+
content: string;
|
|
69
|
+
}
|
|
70
|
+
export interface TeamStateSerialized {
|
|
71
|
+
teamId: string;
|
|
72
|
+
title: string;
|
|
73
|
+
config: TeamConfig;
|
|
74
|
+
conversationId: string;
|
|
75
|
+
claudeSessionId: string | null;
|
|
76
|
+
agents: Array<{
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
color: string;
|
|
80
|
+
toolUseId: string | null;
|
|
81
|
+
agentTaskId: string | null;
|
|
82
|
+
status: string;
|
|
83
|
+
currentTaskId: string | null;
|
|
84
|
+
messages?: TeamAgentMessage[];
|
|
85
|
+
}>;
|
|
86
|
+
tasks: TaskItem[];
|
|
87
|
+
feed: TeamFeedEntry[];
|
|
88
|
+
status: string;
|
|
89
|
+
leadStatus: string;
|
|
90
|
+
summary: string | null;
|
|
91
|
+
totalCost: number;
|
|
92
|
+
durationMs: number;
|
|
93
|
+
createdAt: number;
|
|
94
|
+
}
|
|
95
|
+
type SendFn = (msg: Record<string, unknown>) => void;
|
|
96
|
+
type HandleChatFn = (conversationId: string | undefined, prompt: string, workDir: string, options?: {
|
|
97
|
+
resumeSessionId?: string;
|
|
98
|
+
extraArgs?: string[];
|
|
99
|
+
}) => void;
|
|
100
|
+
type CancelExecutionFn = (conversationId?: string) => void;
|
|
101
|
+
type SetOutputObserverFn = (fn: (conversationId: string, msg: Record<string, unknown>) => boolean | void) => void;
|
|
102
|
+
type ClearOutputObserverFn = () => void;
|
|
103
|
+
type SetCloseObserverFn = (fn: (conversationId: string, exitCode: number | null, resultReceived: boolean) => void) => void;
|
|
104
|
+
type ClearCloseObserverFn = () => void;
|
|
105
|
+
export declare function setTeamSendFn(fn: SendFn): void;
|
|
106
|
+
/**
|
|
107
|
+
* Inject claude.ts dependencies to avoid circular imports.
|
|
108
|
+
* Called once during agent startup from connection.ts.
|
|
109
|
+
*/
|
|
110
|
+
export declare function setTeamClaudeFns(fns: {
|
|
111
|
+
handleChat: HandleChatFn;
|
|
112
|
+
cancelExecution: CancelExecutionFn;
|
|
113
|
+
setOutputObserver: SetOutputObserverFn;
|
|
114
|
+
clearOutputObserver: ClearOutputObserverFn;
|
|
115
|
+
setCloseObserver: SetCloseObserverFn;
|
|
116
|
+
clearCloseObserver: ClearCloseObserverFn;
|
|
117
|
+
}): void;
|
|
118
|
+
export declare function getActiveTeam(): TeamState | null;
|
|
119
|
+
export declare function getLastCompletedTeamId(): string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Create a new team. Returns the TeamState.
|
|
122
|
+
* Does NOT start the Lead process — the caller (team lifecycle functions) does that.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createTeamState(config: TeamConfig, conversationId: string): TeamState;
|
|
125
|
+
/**
|
|
126
|
+
* Clear the active team (used on dissolve/complete).
|
|
127
|
+
*/
|
|
128
|
+
export declare function clearActiveTeam(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Get the next color for an agent (based on current count).
|
|
131
|
+
*/
|
|
132
|
+
export declare function getNextAgentColor(team: TeamState): string;
|
|
133
|
+
/**
|
|
134
|
+
* Register a subagent when Lead calls the Agent tool.
|
|
135
|
+
*/
|
|
136
|
+
export declare function registerSubagent(team: TeamState, toolUseId: string, input: {
|
|
137
|
+
name?: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
prompt?: string;
|
|
140
|
+
}): AgentTeammate;
|
|
141
|
+
/**
|
|
142
|
+
* Link a subagent's task_started system message to its tool_use_id.
|
|
143
|
+
*/
|
|
144
|
+
export declare function linkSubagentTaskId(team: TeamState, toolUseId: string, taskId: string): AgentTeammate | null;
|
|
145
|
+
/**
|
|
146
|
+
* Find agent by toolUseId (parent_tool_use_id).
|
|
147
|
+
*/
|
|
148
|
+
export declare function findAgentByToolUseId(team: TeamState, toolUseId: string): AgentTeammate | null;
|
|
149
|
+
/**
|
|
150
|
+
* Find agent by agentTaskId (task_id from system.task_started).
|
|
151
|
+
*/
|
|
152
|
+
export declare function findAgentByTaskId(team: TeamState, agentTaskId: string): AgentTeammate | null;
|
|
153
|
+
/**
|
|
154
|
+
* Add a message to an agent's message list.
|
|
155
|
+
*/
|
|
156
|
+
export declare function addAgentMessage(agent: AgentTeammate, role: 'assistant' | 'tool' | 'user', fields: Partial<Omit<TeamAgentMessage, 'id' | 'role' | 'timestamp'>>): TeamAgentMessage;
|
|
157
|
+
/**
|
|
158
|
+
* Add an entry to the team's activity feed.
|
|
159
|
+
*/
|
|
160
|
+
export declare function addFeedEntry(team: TeamState, agentId: string, type: TeamFeedEntry['type'], content: string): TeamFeedEntry;
|
|
161
|
+
/**
|
|
162
|
+
* Mark a task as done/failed.
|
|
163
|
+
*/
|
|
164
|
+
export declare function updateTaskStatus(team: TeamState, taskId: string, status: 'done' | 'failed'): TaskItem | null;
|
|
165
|
+
/**
|
|
166
|
+
* Check if all subagent tasks are completed.
|
|
167
|
+
*/
|
|
168
|
+
export declare function allSubagentsDone(team: TeamState): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Serialize TeamState for persistence/transmission (Map → array).
|
|
171
|
+
*/
|
|
172
|
+
export declare function serializeTeam(team: TeamState, includeMessages?: boolean): TeamStateSerialized;
|
|
173
|
+
/**
|
|
174
|
+
* Persist team state to disk (atomic write: tmp → rename).
|
|
175
|
+
*/
|
|
176
|
+
export declare function persistTeam(team: TeamState): void;
|
|
177
|
+
/**
|
|
178
|
+
* Debounced persist — coalesces rapid state changes into a single write.
|
|
179
|
+
* Flushes after 500ms of quiet.
|
|
180
|
+
*/
|
|
181
|
+
export declare function persistTeamDebounced(team: TeamState): void;
|
|
182
|
+
/**
|
|
183
|
+
* Flush all pending debounced persists immediately.
|
|
184
|
+
*/
|
|
185
|
+
export declare function flushPendingPersists(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Load a team from disk by teamId.
|
|
188
|
+
*/
|
|
189
|
+
export declare function loadTeam(teamId: string): TeamState | null;
|
|
190
|
+
/**
|
|
191
|
+
* Summary info for listing teams.
|
|
192
|
+
*/
|
|
193
|
+
export interface TeamSummaryInfo {
|
|
194
|
+
teamId: string;
|
|
195
|
+
title: string;
|
|
196
|
+
status: string;
|
|
197
|
+
template: string | undefined;
|
|
198
|
+
agentCount: number;
|
|
199
|
+
taskCount: number;
|
|
200
|
+
totalCost: number;
|
|
201
|
+
createdAt: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* List all persisted teams, sorted by createdAt descending (newest first).
|
|
205
|
+
*/
|
|
206
|
+
export declare function listTeams(): TeamSummaryInfo[];
|
|
207
|
+
/**
|
|
208
|
+
* Delete a persisted team file.
|
|
209
|
+
*/
|
|
210
|
+
export declare function deleteTeam(teamId: string): boolean;
|
|
211
|
+
interface AgentDef {
|
|
212
|
+
description: string;
|
|
213
|
+
prompt: string;
|
|
214
|
+
tools: string[];
|
|
215
|
+
}
|
|
216
|
+
type AgentsDefMap = Record<string, AgentDef>;
|
|
217
|
+
/**
|
|
218
|
+
* Build the agents definition JSON for the --agents CLI flag.
|
|
219
|
+
*/
|
|
220
|
+
export declare function buildAgentsDef(template?: string): AgentsDefMap;
|
|
221
|
+
/**
|
|
222
|
+
* Build the lead prompt that instructs the Lead to use Agent tool.
|
|
223
|
+
*/
|
|
224
|
+
export declare function buildLeadPrompt(config: TeamConfig, agentsDef: AgentsDefMap): string;
|
|
225
|
+
/**
|
|
226
|
+
* Output observer callback for the Lead's stdout stream.
|
|
227
|
+
* Registered via setOutputObserver() when a team is active.
|
|
228
|
+
* Returns true to suppress the message from normal web client forwarding.
|
|
229
|
+
*/
|
|
230
|
+
export declare function onLeadOutput(conversationId: string, msg: Record<string, unknown>): boolean;
|
|
231
|
+
/**
|
|
232
|
+
* Close observer callback for the Lead's process exit.
|
|
233
|
+
* Detects Lead crash (process exited without a result message) and dissolves the team.
|
|
234
|
+
*/
|
|
235
|
+
export declare function onLeadClose(conversationId: string, _exitCode: number | null, resultReceived: boolean): void;
|
|
236
|
+
/**
|
|
237
|
+
* Create and launch a team. Returns the TeamState.
|
|
238
|
+
* Spawns the Lead Claude process with --agents flag and attaches the output observer.
|
|
239
|
+
*/
|
|
240
|
+
export declare function createTeam(config: TeamConfig, workDir: string): TeamState;
|
|
241
|
+
/**
|
|
242
|
+
* Dissolve (cancel) the active team.
|
|
243
|
+
*/
|
|
244
|
+
export declare function dissolveTeam(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Called when the Lead's result message arrives (from onLeadOutput).
|
|
247
|
+
* Marks the team as completed, persists state, and notifies clients.
|
|
248
|
+
*/
|
|
249
|
+
export declare function completeTeam(summary?: string): void;
|
|
250
|
+
export {};
|