@peer-agent/protocol 0.1.0-rc.11 → 0.1.0-rc.12
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.
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Coordination authority is issued by the local host, never by model arguments. */
|
|
2
|
+
export type CoordinationAction = 'parallel' | 'augment' | 'revise' | 'query' | 'answer' | 'cancel' | 'replace' | 'handoff';
|
|
3
|
+
export type CoordinationLifecycle = 'active' | 'paused' | 'cancelled' | 'fulfilled';
|
|
4
|
+
export interface CoordinationMandate {
|
|
5
|
+
schemaVersion: 1;
|
|
6
|
+
mandateId: string;
|
|
7
|
+
workId: string;
|
|
8
|
+
workspaceId: string;
|
|
9
|
+
parentConversationId: string;
|
|
10
|
+
rootInputIds: string[];
|
|
11
|
+
revisionInputIds: string[];
|
|
12
|
+
goalRevision: number;
|
|
13
|
+
allowedActions: CoordinationAction[];
|
|
14
|
+
sessionIds: string[];
|
|
15
|
+
revokedSessionIds?: string[];
|
|
16
|
+
executionBindings?: Record<string, CoordinationExecutionBinding>;
|
|
17
|
+
materialRefs: string[];
|
|
18
|
+
policyRevision: string;
|
|
19
|
+
lifecycle: CoordinationLifecycle;
|
|
20
|
+
}
|
|
21
|
+
/** Semantic routing is the model's decision; identity, authority and versions are host facts. */
|
|
22
|
+
export interface CoordinationDecision {
|
|
23
|
+
operationId: string;
|
|
24
|
+
workId: string;
|
|
25
|
+
expectedRevision: number;
|
|
26
|
+
action: CoordinationAction;
|
|
27
|
+
sourceInputIds: string[];
|
|
28
|
+
sourceEventIds: string[];
|
|
29
|
+
sessionId?: string;
|
|
30
|
+
reason: string;
|
|
31
|
+
}
|
|
32
|
+
export type TaskTransitionPhase = 'recorded' | 'stopping' | 'awaiting_outcome' | 'ready' | 'started' | 'completed' | 'blocked';
|
|
33
|
+
export interface TaskTransition {
|
|
34
|
+
schemaVersion: 1;
|
|
35
|
+
operationId: string;
|
|
36
|
+
workId: string;
|
|
37
|
+
mandateId: string;
|
|
38
|
+
expectedGoalRevision: number;
|
|
39
|
+
sourceInputIds: string[];
|
|
40
|
+
sourceEventIds: string[];
|
|
41
|
+
initiator: 'project_agent';
|
|
42
|
+
decisionSource: 'user_revision' | 'execution_repair';
|
|
43
|
+
action: CoordinationAction;
|
|
44
|
+
reason: string;
|
|
45
|
+
oldSessionId?: string;
|
|
46
|
+
replacementSessionId?: string;
|
|
47
|
+
executionEpoch: string;
|
|
48
|
+
phase: TaskTransitionPhase;
|
|
49
|
+
minimumExecutorVersion: 1;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
}
|
|
52
|
+
export interface CoordinationExecutionBinding {
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
workId: string;
|
|
55
|
+
goalRevision: number;
|
|
56
|
+
executionEpoch: string;
|
|
57
|
+
}
|
|
58
|
+
/** Factual view of a durable operation; completed means disposition applied, not task success. */
|
|
59
|
+
export interface CoordinationSessionFacts {
|
|
60
|
+
readonly operationId: string;
|
|
61
|
+
readonly action: CoordinationAction;
|
|
62
|
+
readonly phase: TaskTransitionPhase;
|
|
63
|
+
readonly reason: string;
|
|
64
|
+
readonly goalRevision: number;
|
|
65
|
+
readonly priorSessionId?: string;
|
|
66
|
+
readonly replacementSessionId?: string;
|
|
67
|
+
readonly replacementTitle?: string;
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/delegation.d.ts
CHANGED
|
@@ -4,10 +4,27 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ModelSelectionSnapshot } from './model-routing.ts';
|
|
6
6
|
import { type GoalPlanProjectionSnapshot, type TaskOverviewItem } from './task-overview.ts';
|
|
7
|
-
export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'waiting_agent' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
8
|
-
export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "waiting_agent", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
|
|
7
|
+
export type WorkSessionStatus = 'paused' | 'queued' | 'starting' | 'running' | 'waiting_user' | 'waiting_agent' | 'stopping' | 'awaiting_outcome' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
8
|
+
export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "waiting_agent", "stopping", "awaiting_outcome", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
|
|
9
9
|
export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
|
|
10
10
|
export interface DelegationOrigin {
|
|
11
|
+
readonly takeover?: {
|
|
12
|
+
operationId: string;
|
|
13
|
+
phase: 'stopping' | 'completed';
|
|
14
|
+
text: string;
|
|
15
|
+
binding: import('./delegation-coordination.ts').CoordinationExecutionBinding;
|
|
16
|
+
requestedAt: string;
|
|
17
|
+
completedAt?: string;
|
|
18
|
+
};
|
|
19
|
+
readonly coordinationBinding?: import('./delegation-coordination.ts').CoordinationExecutionBinding;
|
|
20
|
+
readonly cancellation?: {
|
|
21
|
+
readonly operationId: string;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
readonly phase: 'stopping' | 'awaiting_outcome' | 'completed';
|
|
24
|
+
readonly requestedAt: string;
|
|
25
|
+
readonly completedAt?: string;
|
|
26
|
+
readonly evidenceCalls?: readonly string[];
|
|
27
|
+
};
|
|
11
28
|
readonly workId?: string;
|
|
12
29
|
readonly anchorMessageId: string;
|
|
13
30
|
readonly inputId: string;
|
|
@@ -36,6 +53,7 @@ export interface SessionQueueFacts {
|
|
|
36
53
|
readonly queueReason?: 'dependencies' | 'dependency_missing' | 'dependency_failed' | 'read_slot' | 'write_slot' | 'disk_space' | 'isolation_failed' | null;
|
|
37
54
|
}
|
|
38
55
|
export interface WorkSessionConversationMeta extends SessionQueueFacts {
|
|
56
|
+
readonly coordination?: import('./delegation-coordination.ts').CoordinationSessionFacts;
|
|
39
57
|
readonly sessionId?: string;
|
|
40
58
|
readonly conversationId?: string;
|
|
41
59
|
readonly workspaceId: string;
|
|
@@ -48,6 +66,7 @@ export interface WorkSessionConversationMeta extends SessionQueueFacts {
|
|
|
48
66
|
readonly phase?: 'starting' | 'verifying' | 'paused';
|
|
49
67
|
}
|
|
50
68
|
export interface WorkSession extends SessionQueueFacts {
|
|
69
|
+
readonly coordination?: import('./delegation-coordination.ts').CoordinationSessionFacts;
|
|
51
70
|
readonly sessionId: string;
|
|
52
71
|
readonly workspaceId: string;
|
|
53
72
|
readonly title: string;
|
package/dist/delegation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deriveSessionFacts } from "./session-facts.js";
|
|
2
2
|
import { projectGoalPlan, } from "./task-overview.js";
|
|
3
|
-
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'waiting_agent', 'verifying',
|
|
3
|
+
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'waiting_agent', 'stopping', 'awaiting_outcome', 'verifying',
|
|
4
4
|
'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
|
|
5
5
|
function fnv1a(text) {
|
|
6
6
|
let hash = 0x811c9dc5;
|
|
@@ -42,6 +42,8 @@ export function createDelegationEvent(input) {
|
|
|
42
42
|
}
|
|
43
43
|
function delegationStatus(snapshot, meta, projected) {
|
|
44
44
|
return deriveSessionFacts({ status: snapshot.status, runnerStatus: snapshot.runnerStatus,
|
|
45
|
+
cancellationPhase: meta.origin.cancellation?.phase,
|
|
46
|
+
takeoverPhase: meta.coordination?.phase === 'awaiting_outcome' ? 'awaiting_outcome' : meta.origin.takeover?.phase,
|
|
45
47
|
accepted: meta.accepted === true || (snapshot.status === 'completed' && meta.acceptance !== 'confirm'
|
|
46
48
|
&& meta.accepted === undefined && !meta.verifying && !snapshot.runnerStatus),
|
|
47
49
|
superseded: Boolean(meta.supersededBy), phase: meta.phase,
|
|
@@ -56,16 +58,20 @@ function delegationStatus(snapshot, meta, projected) {
|
|
|
56
58
|
*/
|
|
57
59
|
export function projectWorkSession(plan, conversationMeta) {
|
|
58
60
|
const projected = projectGoalPlan(plan);
|
|
61
|
+
const status = delegationStatus(plan, conversationMeta, projected);
|
|
62
|
+
const transitioning = ['stopping', 'awaiting_outcome'].includes(status) || conversationMeta.origin.takeover?.phase === 'stopping';
|
|
59
63
|
return {
|
|
60
64
|
sessionId: conversationMeta.sessionId ?? plan.conversationId ?? plan.planId,
|
|
61
65
|
workspaceId: conversationMeta.workspaceId,
|
|
62
66
|
title: plan.title,
|
|
63
67
|
planId: plan.planId,
|
|
64
|
-
status
|
|
65
|
-
actionRight: projected.actionRight,
|
|
66
|
-
nextAction: projected.nextAction,
|
|
67
|
-
statusLabel:
|
|
68
|
-
|
|
68
|
+
status,
|
|
69
|
+
actionRight: transitioning ? 'peer_advancing' : projected.actionRight,
|
|
70
|
+
nextAction: transitioning ? 'none' : projected.nextAction,
|
|
71
|
+
statusLabel: status === 'stopping' ? '正在停止' : status === 'awaiting_outcome' ? '执行结果待核实'
|
|
72
|
+
: conversationMeta.origin.takeover?.phase === 'stopping' ? '正在接手' : projected.statusLabel,
|
|
73
|
+
...(!transitioning && projected.needsYouReason ? { needsYouReason: projected.needsYouReason } : {}),
|
|
74
|
+
...(conversationMeta.coordination ? { coordination: conversationMeta.coordination } : {}),
|
|
69
75
|
spawnedAt: conversationMeta.spawnedAt ?? plan.updatedAt ?? '',
|
|
70
76
|
...(conversationMeta.conversationId ? { conversationId: conversationMeta.conversationId } : {}),
|
|
71
77
|
origin: conversationMeta.origin,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { ProjectWorkReceipt, ProjectWorkRecovery, ProjectWorkState, ProjectTurnEnd } from './work-coordination.ts';
|
|
2
|
+
export type { CoordinationAction, CoordinationLifecycle, CoordinationMandate, CoordinationDecision, TaskTransitionPhase, TaskTransition, CoordinationExecutionBinding, CoordinationSessionFacts } from './delegation-coordination.ts';
|
|
2
3
|
export { deriveSessionFacts, type SessionFactSnapshot } from './session-facts.ts';
|
|
3
4
|
export { projectAgentFailureKind, classifyProjectAgentFailure, type ProjectRecoveryFailureKind, type ProviderRequestRecovery, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
|
|
4
5
|
export type { EvidenceSourceDescription, ProjectAgentEvidenceReadRequest, ProjectAgentEvidenceReadResult } from './evidence-inspection.ts';
|
package/dist/session-facts.d.ts
CHANGED
package/dist/session-facts.js
CHANGED
|
@@ -7,6 +7,12 @@ export function deriveSessionFacts(input) {
|
|
|
7
7
|
status = 'failed';
|
|
8
8
|
else if (input.accepted)
|
|
9
9
|
status = 'accepted';
|
|
10
|
+
else if (input.cancellationPhase === 'awaiting_outcome' || input.takeoverPhase === 'awaiting_outcome')
|
|
11
|
+
status = 'awaiting_outcome';
|
|
12
|
+
else if (input.cancellationPhase === 'stopping')
|
|
13
|
+
status = 'stopping';
|
|
14
|
+
else if (input.takeoverPhase === 'stopping')
|
|
15
|
+
status = 'starting';
|
|
10
16
|
else if (input.needsUser || input.runnerStatus === 'waiting_user')
|
|
11
17
|
status = 'waiting_user';
|
|
12
18
|
else if (input.blockedReason === 'waiting_parent_agent' && input.phase !== 'paused' && !input.superseded && input.runnerStatus !== 'paused')
|