@anhlp/alp-protocol 0.0.0-stage → 0.0.1-beta.3
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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +16 -2
- package/conformance/cases.json +951 -0
- package/conformance/run.d.mts +32 -0
- package/conformance/run.mjs +403 -0
- package/dist/connection.d.ts +9 -0
- package/dist/connection.js +0 -0
- package/dist/contract-v1.d.ts +5113 -0
- package/dist/contract-v1.js +5 -0
- package/dist/contract.d.ts +25 -0
- package/dist/contract.js +28 -0
- package/dist/dto.d.ts +104 -0
- package/dist/dto.js +0 -0
- package/dist/events.d.ts +313 -0
- package/dist/events.js +0 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -0
- package/dist/public.d.ts +1 -0
- package/dist/public.js +2 -0
- package/dist/rpc.d.ts +570 -0
- package/dist/rpc.js +0 -0
- package/dist/session.d.ts +145 -0
- package/dist/session.js +0 -0
- package/dist/validate.d.ts +12 -0
- package/dist/validate.js +151 -0
- package/dist/wire.d.ts +80 -0
- package/dist/wire.js +62 -0
- package/fixtures/ipc-v1.jsonl +4 -0
- package/fixtures/v1/cases.json +3919 -0
- package/package.json +127 -4
- package/schema/ipc-v1.json +2335 -0
- package/schema/methods-v1.json +4757 -0
- package/src/connection.ts +9 -0
- package/src/contract-v1.js +2 -0
- package/src/contract.js +44 -0
- package/src/dto.ts +78 -0
- package/src/events.ts +181 -0
- package/src/index.ts +6 -0
- package/src/public.js +2 -0
- package/src/rpc.ts +113 -0
- package/src/session.ts +97 -0
- package/src/validate.js +115 -0
- package/src/wire.js +87 -0
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import type { RuntimeKind, MailEvent, Pin } from './dto.js';
|
|
2
|
+
/** Provider-neutral session events (plans/reference/ALPD.md §4). Viewers project them; the runtime never imports a viewer. */
|
|
3
|
+
/** `code: 'outcome_unknown'` when the provider may or may not have received the request (ALPD §66). */
|
|
4
|
+
export type AlpError = {
|
|
5
|
+
message: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
};
|
|
8
|
+
export type TimelineItem = {
|
|
9
|
+
kind: 'user_message';
|
|
10
|
+
id: string;
|
|
11
|
+
text: string;
|
|
12
|
+
clientMessageId?: string; /** How many images the message carried; their data is not replayed. */
|
|
13
|
+
images?: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'assistant_message';
|
|
16
|
+
id: string;
|
|
17
|
+
text: string;
|
|
18
|
+
}
|
|
19
|
+
/** Something about ALP as a whole the user should see, such as a usage limit or a pause (ALPD §29). */
|
|
20
|
+
| {
|
|
21
|
+
kind: 'notice';
|
|
22
|
+
id: string;
|
|
23
|
+
level: 'info' | 'warning' | 'error';
|
|
24
|
+
text: string;
|
|
25
|
+
}
|
|
26
|
+
/** The runtime compacting the session's context (ALPD §57). */
|
|
27
|
+
| {
|
|
28
|
+
kind: 'compaction';
|
|
29
|
+
id: string;
|
|
30
|
+
status: 'running' | 'completed' | 'failed';
|
|
31
|
+
trigger?: 'auto' | 'manual';
|
|
32
|
+
preTokens?: number;
|
|
33
|
+
postTokens?: number;
|
|
34
|
+
}
|
|
35
|
+
/** The tasks a root's tree created or worked on (plans/reference/ALPD.md §21). */
|
|
36
|
+
| {
|
|
37
|
+
kind: 'todo';
|
|
38
|
+
id: string;
|
|
39
|
+
items: Array<{
|
|
40
|
+
id: string;
|
|
41
|
+
text: string;
|
|
42
|
+
status: 'pending' | 'in_progress' | 'completed';
|
|
43
|
+
}>;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'tool_call';
|
|
46
|
+
id: string;
|
|
47
|
+
callId: string;
|
|
48
|
+
name: string;
|
|
49
|
+
status: 'running' | 'completed' | 'failed';
|
|
50
|
+
error?: string;
|
|
51
|
+
detail: ToolCallDetail;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What a tool call did, typed by kind (ALPD §4.2), in the shapes of Paseo's ToolCallDetail.
|
|
55
|
+
* `shell` is a command; `unknown` the fallback with the tool's raw input and output. The typed
|
|
56
|
+
* kinds between come from the runtime's own tools; filePath is the path the runtime reported.
|
|
57
|
+
* The runtime clips each string field of a typed detail (not shell, not unknown) to 65,536
|
|
58
|
+
* characters, filePaths to 200 entries and webResults to 50. A receiver shows a detail whose
|
|
59
|
+
* type it does not know as unknown: new types may be added within v1.
|
|
60
|
+
*/
|
|
61
|
+
export type ToolCallDetail = {
|
|
62
|
+
type: 'shell';
|
|
63
|
+
command: string;
|
|
64
|
+
cwd?: string;
|
|
65
|
+
output: string;
|
|
66
|
+
exitCode?: number | null;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'read';
|
|
69
|
+
filePath: string;
|
|
70
|
+
content?: string;
|
|
71
|
+
offset?: number;
|
|
72
|
+
limit?: number;
|
|
73
|
+
} | {
|
|
74
|
+
type: 'edit';
|
|
75
|
+
filePath: string;
|
|
76
|
+
oldString?: string;
|
|
77
|
+
newString?: string;
|
|
78
|
+
unifiedDiff?: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'write';
|
|
81
|
+
filePath: string;
|
|
82
|
+
content?: string;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'search';
|
|
85
|
+
query: string;
|
|
86
|
+
toolName?: 'search' | 'grep' | 'glob' | 'web_search';
|
|
87
|
+
content?: string;
|
|
88
|
+
filePaths?: string[];
|
|
89
|
+
webResults?: Array<{
|
|
90
|
+
title: string;
|
|
91
|
+
url: string;
|
|
92
|
+
}>;
|
|
93
|
+
numFiles?: number;
|
|
94
|
+
numMatches?: number;
|
|
95
|
+
truncated?: boolean;
|
|
96
|
+
} | {
|
|
97
|
+
type: 'fetch';
|
|
98
|
+
url: string;
|
|
99
|
+
prompt?: string;
|
|
100
|
+
result?: string;
|
|
101
|
+
code?: number;
|
|
102
|
+
} | {
|
|
103
|
+
type: 'sub_agent';
|
|
104
|
+
subAgentType?: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
log?: string;
|
|
107
|
+
} | {
|
|
108
|
+
type: 'plan';
|
|
109
|
+
text: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'plain_text';
|
|
112
|
+
label?: string;
|
|
113
|
+
text?: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'unknown';
|
|
116
|
+
input: unknown;
|
|
117
|
+
output: unknown;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* How much a session has used, from its runtime's latest token report (ALPD §57), as Paseo's
|
|
121
|
+
* AgentUsage: the context window's fill, the latest model response's tokens, and the session's
|
|
122
|
+
* cost when the runtime says it. A field the runtime does not report is absent; a later report
|
|
123
|
+
* replaces the fields it carries and keeps the others.
|
|
124
|
+
*/
|
|
125
|
+
export type SessionUsage = {
|
|
126
|
+
/** Tokens the context holds now: the latest model call's input and output. */
|
|
127
|
+
contextWindowUsedTokens?: number;
|
|
128
|
+
/** The context window, once the runtime has said what it is. */
|
|
129
|
+
contextWindowMaxTokens?: number;
|
|
130
|
+
/** The latest model response's input tokens, of which cachedInputTokens came from cache, and output tokens. */
|
|
131
|
+
inputTokens?: number;
|
|
132
|
+
cachedInputTokens?: number;
|
|
133
|
+
outputTokens?: number;
|
|
134
|
+
/** The session's cost in US dollars so far, as the runtime counts it (Claude, or ACP in USD). */
|
|
135
|
+
totalCostUsd?: number;
|
|
136
|
+
};
|
|
137
|
+
export type SessionSnapshot = {
|
|
138
|
+
id: string;
|
|
139
|
+
projectRoot: string;
|
|
140
|
+
agent: string;
|
|
141
|
+
runtime: RuntimeKind;
|
|
142
|
+
model: string;
|
|
143
|
+
mode: string;
|
|
144
|
+
thinking: string;
|
|
145
|
+
workflow: {
|
|
146
|
+
mode: string;
|
|
147
|
+
maxPeers: number;
|
|
148
|
+
supervisor: boolean;
|
|
149
|
+
};
|
|
150
|
+
/** The label of the session's team, such as Phở (ALPD §42); absent for a custom graph. */
|
|
151
|
+
teamLabel?: string;
|
|
152
|
+
threadId: string;
|
|
153
|
+
/** The native thread is kept and the session can be resumed. */
|
|
154
|
+
persistent: boolean;
|
|
155
|
+
parentId?: string;
|
|
156
|
+
/** The requester's tool call that started this assignment. */
|
|
157
|
+
toolCallId?: string;
|
|
158
|
+
activeTurnId?: string;
|
|
159
|
+
/** A turn, an assignment, a child, or undelivered mail keeps the session working. */
|
|
160
|
+
busy: boolean;
|
|
161
|
+
/** Why a usage limit or a pause parked this assignment (ALPD §29). */
|
|
162
|
+
parked?: string;
|
|
163
|
+
/** A digest of the instructions the session runs with (ALPD §34). */
|
|
164
|
+
instructionsSha?: string;
|
|
165
|
+
/** The session's runtime takes images in session.prompt (capability `prompt.images`); absent means it does not. */
|
|
166
|
+
promptImages?: boolean;
|
|
167
|
+
/** The latest usage the session's runtime reported (ALPD §57); absent before its first report. */
|
|
168
|
+
usage?: SessionUsage;
|
|
169
|
+
};
|
|
170
|
+
export type AssignmentSnapshot = {
|
|
171
|
+
id: string;
|
|
172
|
+
agent: string;
|
|
173
|
+
mode: string;
|
|
174
|
+
status: string;
|
|
175
|
+
startedAt: string;
|
|
176
|
+
/** An isolated assignment's branch and working directory. */
|
|
177
|
+
worktree?: {
|
|
178
|
+
branch: string;
|
|
179
|
+
path: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** runtime: a turn the native runtime started by itself, such as Claude after a background task ended. */
|
|
183
|
+
export type TurnOrigin = 'user' | 'wake' | 'assignment' | 'runtime';
|
|
184
|
+
/** A question an agent asked the user with alp_ask to: "user". */
|
|
185
|
+
export type UserQuestion = {
|
|
186
|
+
id: string;
|
|
187
|
+
sessionId: string;
|
|
188
|
+
rootId: string;
|
|
189
|
+
agent: string;
|
|
190
|
+
body: string;
|
|
191
|
+
options?: string[];
|
|
192
|
+
askedAt: string;
|
|
193
|
+
};
|
|
194
|
+
export type SessionState = 'running' | 'waiting' | 'waiting_parent' | 'waiting_user' | 'idle';
|
|
195
|
+
/** A live tree at one moment, for dashboards (plans/reference/ALPD.md §17). */
|
|
196
|
+
export type TreeStatus = {
|
|
197
|
+
rootId: string;
|
|
198
|
+
sessions: Array<SessionSnapshot & {
|
|
199
|
+
state: SessionState;
|
|
200
|
+
idleMs: number;
|
|
201
|
+
workdir: string;
|
|
202
|
+
unreadMail: number;
|
|
203
|
+
}>;
|
|
204
|
+
assignments: Array<AssignmentSnapshot & {
|
|
205
|
+
requester: string;
|
|
206
|
+
isolation: 'shared' | 'worktree';
|
|
207
|
+
idleMs: number;
|
|
208
|
+
}>;
|
|
209
|
+
questions: UserQuestion[];
|
|
210
|
+
/** Finished worktree assignments waiting for alp_merge or alp_discard. */
|
|
211
|
+
worktrees: Array<{
|
|
212
|
+
assignmentId: string;
|
|
213
|
+
requester: string;
|
|
214
|
+
agent: string;
|
|
215
|
+
branch: string;
|
|
216
|
+
files: string[];
|
|
217
|
+
stat: string;
|
|
218
|
+
}>;
|
|
219
|
+
leases: Array<{
|
|
220
|
+
checkout: string;
|
|
221
|
+
assignmentId: string;
|
|
222
|
+
agent: string;
|
|
223
|
+
}>;
|
|
224
|
+
/** Live claims on the project board held by this tree's sessions. */
|
|
225
|
+
claims: Pin[];
|
|
226
|
+
};
|
|
227
|
+
export type AlpEvent = {
|
|
228
|
+
type: 'session.opened';
|
|
229
|
+
session: SessionSnapshot;
|
|
230
|
+
cwd: string;
|
|
231
|
+
effective: {
|
|
232
|
+
model: string;
|
|
233
|
+
thinking: string;
|
|
234
|
+
};
|
|
235
|
+
} | {
|
|
236
|
+
type: 'session.ready';
|
|
237
|
+
}
|
|
238
|
+
/** `title` comes with alpd's announcement of a root's name (its first prompt, or `session.rename`). */
|
|
239
|
+
| {
|
|
240
|
+
type: 'session.updated';
|
|
241
|
+
session: SessionSnapshot & {
|
|
242
|
+
title?: string;
|
|
243
|
+
};
|
|
244
|
+
} | {
|
|
245
|
+
type: 'session.closed';
|
|
246
|
+
} | {
|
|
247
|
+
type: 'session.failed';
|
|
248
|
+
error: AlpError;
|
|
249
|
+
} | {
|
|
250
|
+
type: 'prompt.accepted';
|
|
251
|
+
clientMessageId: string;
|
|
252
|
+
result: 'turn' | 'steer';
|
|
253
|
+
turnId: string;
|
|
254
|
+
} | {
|
|
255
|
+
type: 'prompt.failed';
|
|
256
|
+
clientMessageId: string;
|
|
257
|
+
error: AlpError;
|
|
258
|
+
} | {
|
|
259
|
+
type: 'turn.started';
|
|
260
|
+
turnId: string;
|
|
261
|
+
origin: TurnOrigin;
|
|
262
|
+
} | {
|
|
263
|
+
type: 'turn.ended';
|
|
264
|
+
turnId: string;
|
|
265
|
+
state: 'completed' | 'failed' | 'canceled';
|
|
266
|
+
error?: AlpError;
|
|
267
|
+
} | {
|
|
268
|
+
type: 'item';
|
|
269
|
+
item: TimelineItem;
|
|
270
|
+
}
|
|
271
|
+
/** The session's usage changed: the whole latest SessionUsage, not a delta (ALPD §57). */
|
|
272
|
+
| {
|
|
273
|
+
type: 'usage';
|
|
274
|
+
usage: SessionUsage;
|
|
275
|
+
} | {
|
|
276
|
+
type: 'mail';
|
|
277
|
+
mail: Omit<MailEvent, 'passive' | 'deliveredTurn'>;
|
|
278
|
+
} | {
|
|
279
|
+
type: 'assignment';
|
|
280
|
+
assignment: AssignmentSnapshot;
|
|
281
|
+
} | {
|
|
282
|
+
type: 'question';
|
|
283
|
+
question: UserQuestion;
|
|
284
|
+
} | {
|
|
285
|
+
type: 'question.resolved';
|
|
286
|
+
questionId: string;
|
|
287
|
+
outcome: 'answered' | 'dismissed' | 'timeout' | 'canceled';
|
|
288
|
+
answer?: string;
|
|
289
|
+
}
|
|
290
|
+
/** Emitted on the session that pinned it (plans/reference/ALPD.md §18). */
|
|
291
|
+
| {
|
|
292
|
+
type: 'pin';
|
|
293
|
+
pin: Pin;
|
|
294
|
+
} | {
|
|
295
|
+
type: 'unpin';
|
|
296
|
+
pinId: string;
|
|
297
|
+
reason: 'unpinned' | 'session_ended';
|
|
298
|
+
};
|
|
299
|
+
export type Envelope = {
|
|
300
|
+
sessionId: string;
|
|
301
|
+
/** Random per runtime instance; a cursor from another epoch is stale. */
|
|
302
|
+
epoch: string;
|
|
303
|
+
/** Strictly increasing per session. */
|
|
304
|
+
seq: number;
|
|
305
|
+
/**
|
|
306
|
+
* Position in its tree's stored timeline, set by alpd on the events it keeps: strictly
|
|
307
|
+
* increasing per root across restarts, so `session.attach { after }` replays only what
|
|
308
|
+
* a reconnecting client missed (ALPD §66).
|
|
309
|
+
*/
|
|
310
|
+
cursor?: number;
|
|
311
|
+
ts: string;
|
|
312
|
+
event: AlpEvent;
|
|
313
|
+
};
|
package/dist/events.js
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./wire.js";
|
package/dist/public.js
ADDED