@peer-agent/protocol 0.1.0-beta.2 → 0.1.0-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.
@@ -224,6 +224,18 @@ export declare function createDelegationEvent(input: {
224
224
  * A paused plan has no delegation status of its own; it is queued, and the visible conclusion stays paused.
225
225
  */
226
226
  export declare function projectWorkSession(plan: GoalPlanProjectionSnapshot, conversationMeta: WorkSessionConversationMeta): WorkSession;
227
+ export interface DispositionToolCall {
228
+ readonly name?: string;
229
+ /** Arbitrary tool input. A disposition field here is ignored. */
230
+ readonly input?: Readonly<Record<string, unknown>> | null;
231
+ readonly result?: unknown;
232
+ }
233
+ /**
234
+ * Derive disposition events from one turn's tool calls.
235
+ * Answer is not an event: only post_reply, projected later from the assistant reply.
236
+ * A model-supplied disposition field is ignored.
237
+ */
238
+ export declare function dispositionEventsFromToolCalls(anchorMessageId: string, toolCalls: readonly DispositionToolCall[]): DispositionEvent[];
227
239
  /**
228
240
  * Dispositions are a projection of anchor events plus replies.
229
241
  * The assistant text answers the last user message in the turn unless replyTo says otherwise.
@@ -55,9 +55,12 @@ function delegationStatus(snapshot, meta, projected) {
55
55
  return 'result_ready';
56
56
  return 'accepted';
57
57
  }
58
+ // 复核进行中盖过「需要你」。草稿、待批准、等回答的计划在独立复核时都显示 verifying。
59
+ if (meta.verifying || meta.phase === 'verifying')
60
+ return 'verifying';
58
61
  if (projected.actionRight === 'needs_you')
59
62
  return 'waiting_user';
60
- if (snapshot.runnerStatus === 'exploring' || meta.phase === 'verifying')
63
+ if (snapshot.runnerStatus === 'exploring')
61
64
  return 'verifying';
62
65
  if (meta.phase === 'starting')
63
66
  return 'starting';
@@ -132,6 +135,107 @@ function dispositionFor(message, event) {
132
135
  return { kind: 'parallel', messageId: message.id, sessionIds: event.sessionIds ?? (sessionId ? [sessionId] : []) };
133
136
  }
134
137
  }
138
+ function toolRecord(value) {
139
+ if (!value || typeof value !== 'object' || Array.isArray(value))
140
+ return null;
141
+ return value;
142
+ }
143
+ function toolBody(result) {
144
+ const record = toolRecord(result);
145
+ if (!record)
146
+ return null;
147
+ const nested = toolRecord(record.output);
148
+ if (nested && typeof record.sessionId !== 'string' && (typeof nested.sessionId === 'string' || typeof nested.error === 'string' || nested.ok === false)) {
149
+ return nested;
150
+ }
151
+ return record;
152
+ }
153
+ function toolFailed(body) {
154
+ if (!body)
155
+ return true;
156
+ if (typeof body.error === 'string' && body.error.trim())
157
+ return true;
158
+ return body.ok === false;
159
+ }
160
+ function toolSessionId(body, fallback) {
161
+ if (body && typeof body.sessionId === 'string' && body.sessionId.trim())
162
+ return body.sessionId.trim();
163
+ return typeof fallback === 'string' ? fallback.trim() : '';
164
+ }
165
+ function toolQueued(body) {
166
+ return body.status === 'queued' || body.queued === true;
167
+ }
168
+ /**
169
+ * Derive disposition events from one turn's tool calls.
170
+ * Answer is not an event: only post_reply, projected later from the assistant reply.
171
+ * A model-supplied disposition field is ignored.
172
+ */
173
+ export function dispositionEventsFromToolCalls(anchorMessageId, toolCalls) {
174
+ const anchor = anchorMessageId.trim();
175
+ if (!anchor)
176
+ return [];
177
+ const events = [];
178
+ for (const call of toolCalls) {
179
+ const name = call?.name;
180
+ const input = call?.input ?? null;
181
+ const body = toolBody(call?.result);
182
+ if (toolFailed(body))
183
+ continue;
184
+ if (name === 'message_session' && fieldText(input, 'intent') === 'amend') {
185
+ const sessionId = toolSessionId(body, fieldText(input, 'sessionId'));
186
+ if (!sessionId)
187
+ continue;
188
+ events.push({ kind: 'merge', anchorMessageId: anchor, sessionId });
189
+ continue;
190
+ }
191
+ if (name === 'cancel_session') {
192
+ const sessionId = toolSessionId(body, fieldText(input, 'sessionId'));
193
+ if (!sessionId)
194
+ continue;
195
+ events.push({
196
+ kind: 'stop',
197
+ anchorMessageId: anchor,
198
+ sessionId,
199
+ sessionIds: [sessionId],
200
+ reason: fieldText(input, 'reason'),
201
+ });
202
+ continue;
203
+ }
204
+ if (name !== 'spawn_session')
205
+ continue;
206
+ const sessionId = toolSessionId(body, '');
207
+ if (!sessionId || !body)
208
+ continue;
209
+ const supersedes = fieldText(input, 'supersedes');
210
+ if (supersedes) {
211
+ events.push({
212
+ kind: 'supersede',
213
+ anchorMessageId: anchor,
214
+ sessionId,
215
+ oldSessionId: supersedes,
216
+ newSessionId: sessionId,
217
+ reason: '',
218
+ });
219
+ continue;
220
+ }
221
+ if (toolQueued(body)) {
222
+ const depends = input?.dependsOn;
223
+ events.push({
224
+ kind: 'queue',
225
+ anchorMessageId: anchor,
226
+ sessionId,
227
+ dependsOn: Array.isArray(depends) ? depends.filter((item) => typeof item === 'string') : [],
228
+ });
229
+ continue;
230
+ }
231
+ events.push({ kind: 'parallel', anchorMessageId: anchor, sessionId, sessionIds: [sessionId] });
232
+ }
233
+ return events;
234
+ }
235
+ function fieldText(record, key) {
236
+ const value = record?.[key];
237
+ return typeof value === 'string' ? value.trim() : '';
238
+ }
135
239
  /**
136
240
  * Dispositions are a projection of anchor events plus replies.
137
241
  * The assistant text answers the last user message in the turn unless replyTo says otherwise.
package/dist/memory.d.ts CHANGED
@@ -36,6 +36,88 @@ export interface MemorySnapshot {
36
36
  readonly itemIds: readonly string[];
37
37
  readonly createdAt: string;
38
38
  }
39
+ /** 记忆页跨进程载荷。渲染层不读存储。 */
40
+ export interface ProjectMemoryRecord {
41
+ readonly id: string;
42
+ readonly scope: 'project' | 'user';
43
+ readonly workspaceId?: string;
44
+ readonly kind: MemoryKind;
45
+ readonly text: string;
46
+ readonly trust: MemoryTrust;
47
+ readonly sourceRefs: readonly string[];
48
+ readonly pinned: boolean;
49
+ readonly status: MemoryStatus;
50
+ readonly confirmedCount: number;
51
+ readonly createdAt: string;
52
+ readonly updatedAt: string;
53
+ readonly lastUsedAt?: string;
54
+ readonly anchorMessageId?: string;
55
+ readonly forgetReason?: string;
56
+ }
57
+ export interface ProjectMemorySwitches {
58
+ readonly memoryEnabled: boolean;
59
+ readonly useMemory: boolean;
60
+ readonly learnPreferences: boolean;
61
+ }
62
+ export interface ProjectMemoryListRequest {
63
+ readonly workspaceId: string;
64
+ readonly kind?: MemoryKind;
65
+ readonly trust?: MemoryTrust;
66
+ readonly status?: MemoryStatus;
67
+ readonly ids?: readonly string[];
68
+ }
69
+ export interface ProjectMemoryListResult {
70
+ readonly ok: boolean;
71
+ readonly code?: string;
72
+ readonly items?: readonly ProjectMemoryRecord[];
73
+ readonly switches?: ProjectMemorySwitches;
74
+ }
75
+ export interface ProjectMemoryPinRequest {
76
+ readonly workspaceId: string;
77
+ readonly id: string;
78
+ readonly pinned: boolean;
79
+ }
80
+ export interface ProjectMemoryForgetRequest {
81
+ readonly workspaceId: string;
82
+ readonly id: string;
83
+ readonly reason?: string;
84
+ }
85
+ export interface ProjectMemoryRestoreRequest {
86
+ readonly workspaceId: string;
87
+ readonly id: string;
88
+ }
89
+ export interface ProjectMemoryEditRequest {
90
+ readonly workspaceId: string;
91
+ readonly id: string;
92
+ readonly text: string;
93
+ }
94
+ export interface ProjectMemoryItemResult {
95
+ readonly ok: boolean;
96
+ readonly code?: string;
97
+ readonly item?: ProjectMemoryRecord;
98
+ readonly revokedId?: string;
99
+ }
100
+ export interface ProjectMemoryExportRequest {
101
+ readonly workspaceId: string;
102
+ readonly format: 'json' | 'markdown';
103
+ }
104
+ export interface ProjectMemoryExportResult {
105
+ readonly ok: boolean;
106
+ readonly code?: string;
107
+ readonly path?: string;
108
+ readonly format?: 'json' | 'markdown';
109
+ }
110
+ export interface ProjectMemorySetSwitchesRequest {
111
+ readonly workspaceId: string;
112
+ readonly memoryEnabled?: boolean;
113
+ readonly useMemory?: boolean;
114
+ readonly learnPreferences?: boolean;
115
+ }
116
+ export interface ProjectMemorySetSwitchesResult {
117
+ readonly ok: boolean;
118
+ readonly code?: string;
119
+ readonly switches?: ProjectMemorySwitches;
120
+ }
39
121
  export type MemoryAdmission = {
40
122
  readonly ok: true;
41
123
  } | {
package/dist/project.d.ts CHANGED
@@ -25,6 +25,9 @@ export interface BotProfile {
25
25
  readonly avatar: BotAvatar;
26
26
  readonly managed?: boolean;
27
27
  readonly agentConversationId?: string;
28
+ readonly proactivity?: 'inherit' | 'quiet' | 'low' | 'standard' | 'high' | 'muted';
29
+ /** Absent means this bot uses memory. */
30
+ readonly memoryEnabled?: boolean;
28
31
  readonly updatedAt?: string;
29
32
  }
30
33
  export interface BotRowState {
@@ -54,6 +57,8 @@ export interface BotListMessage {
54
57
  readonly role: 'user' | 'assistant';
55
58
  readonly text: string;
56
59
  readonly at: string;
60
+ /** silent replies stay in the conversation and do not raise the unread badge. */
61
+ readonly countUnread?: boolean;
57
62
  }
58
63
  export declare const BOT_AVATAR_SHAPES: readonly ["circle", "square", "triangle", "diamond", "hex", "pill", "star", "arch"];
59
64
  export declare const BOT_AVATAR_COLORS: readonly ["#2563eb", "#dc2626", "#d97706", "#059669", "#7c3aed", "#db2777", "#0891b2", "#4b5563"];
package/dist/project.js CHANGED
@@ -55,7 +55,10 @@ export function projectBotListItem(input) {
55
55
  const waitingSessions = sessions.filter((item) => NEEDS_YOU_STATUSES.has(item.status)).length;
56
56
  const running = sessions.filter((item) => RUNNING_STATUSES.has(item.status)).length;
57
57
  const lastMessage = input.lastMessage ?? null;
58
- const unread = lastMessage && lastMessage.role === 'assistant' && (!input.readCursor || lastMessage.at > input.readCursor)
58
+ const unread = lastMessage
59
+ && lastMessage.role === 'assistant'
60
+ && lastMessage.countUnread !== false
61
+ && (!input.readCursor || lastMessage.at > input.readCursor)
59
62
  ? 1
60
63
  : 0;
61
64
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peer-agent/protocol",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Shared host-neutral protocol contracts for Peer Agent runtimes and clients.",
5
5
  "type": "module",
6
6
  "license": "MIT",