@peer-agent/protocol 0.1.0-rc.1 → 0.1.0-rc.11
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/acceptance-close-gate.d.ts +10 -1
- package/dist/acceptance-close-gate.js +12 -0
- package/dist/bot-model-selection.d.ts +13 -0
- package/dist/bot-model-selection.js +1 -0
- package/dist/delegation.d.ts +69 -3
- package/dist/delegation.js +9 -37
- package/dist/evidence-inspection.d.ts +22 -0
- package/dist/evidence-inspection.js +1 -0
- package/dist/goal.d.ts +21 -3
- package/dist/index.d.ts +9 -1
- package/dist/index.js +5 -0
- package/dist/local-image.d.ts +36 -0
- package/dist/local-image.js +5 -0
- package/dist/model-reasoning.d.ts +13 -0
- package/dist/model-reasoning.js +18 -0
- package/dist/model-routing.d.ts +18 -1
- package/dist/model-routing.js +10 -5
- package/dist/project-agent-failure.d.ts +30 -0
- package/dist/project-agent-failure.js +44 -0
- package/dist/project.d.ts +52 -0
- package/dist/session-facts.d.ts +17 -0
- package/dist/session-facts.js +34 -0
- package/dist/task-overview.d.ts +2 -0
- package/dist/task-overview.js +3 -0
- package/dist/tool-activity-preview.d.ts +4 -0
- package/dist/tool-activity-preview.js +69 -0
- package/dist/work-coordination.d.ts +71 -0
- package/dist/work-coordination.js +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GoalCriterionResult, GoalManualConfirmation, GoalSuccessCriterion } from './goal.ts';
|
|
1
|
+
import type { GoalCriterionResult, GoalManualConfirmation, GoalSuccessCriterion, GoalModelReview } from './goal.ts';
|
|
2
2
|
export declare const ACCEPTANCE_CLOSE_GATE_CODE = "acceptance_evidence_incomplete";
|
|
3
3
|
export type AcceptanceCloseGapReason = 'missing' | 'failed' | 'unresolved';
|
|
4
4
|
export interface AcceptanceCloseGap {
|
|
@@ -17,6 +17,15 @@ export interface AcceptanceCloseTaskLike {
|
|
|
17
17
|
}
|
|
18
18
|
export interface AcceptanceClosePlanLike {
|
|
19
19
|
readonly successCriteria?: readonly GoalSuccessCriterion[] | null;
|
|
20
|
+
/** Current content revision derived by the host store, never admitted from a model patch. */
|
|
21
|
+
readonly modelReviewSourceRevision?: string;
|
|
22
|
+
readonly modelReviews?: readonly GoalModelReview[];
|
|
23
|
+
readonly runner?: {
|
|
24
|
+
readonly verifierRuns?: readonly {
|
|
25
|
+
readonly verifierRunId: string;
|
|
26
|
+
readonly status: string;
|
|
27
|
+
}[];
|
|
28
|
+
};
|
|
20
29
|
readonly criterionResults?: readonly GoalCriterionResult[] | null;
|
|
21
30
|
readonly manualConfirmations?: readonly GoalManualConfirmation[] | null;
|
|
22
31
|
readonly evidenceRefs?: readonly string[] | null;
|
|
@@ -85,6 +85,18 @@ export function evaluateAcceptanceCloseGate(plan, options = {}) {
|
|
|
85
85
|
const description = criterion.description?.trim() || id;
|
|
86
86
|
const isAuto = AUTO_CRITERION_KINDS.has(criterion.kind);
|
|
87
87
|
const result = results.get(id) ?? null;
|
|
88
|
+
if (criterion.kind === 'model_review') {
|
|
89
|
+
const review = plan?.modelReviews?.slice().reverse().find(row => row.criterionId === id);
|
|
90
|
+
const current = review && plan?.modelReviewSourceRevision && review.sourceRevision === plan.modelReviewSourceRevision;
|
|
91
|
+
const verified = current && plan?.runner?.verifierRuns?.some(run => run.verifierRunId === review.verifierRunId && run.status === 'passed');
|
|
92
|
+
if (!current || !verified)
|
|
93
|
+
gaps.push({ criterionId: id, description, reason: 'missing' });
|
|
94
|
+
else if (!review.passed)
|
|
95
|
+
gaps.push({ criterionId: id, description, reason: 'failed' });
|
|
96
|
+
else if (!review.evidenceRefs.length || !review.evidenceRefs.every(ref => known.has(ref)))
|
|
97
|
+
gaps.push({ criterionId: id, description, reason: 'unresolved' });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
88
100
|
if (!isAuto && latestManualApproval(plan ?? {}, id))
|
|
89
101
|
continue;
|
|
90
102
|
if (!result) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BotProfile } from './project.ts';
|
|
2
|
+
import type { ModelReasoningEffort } from './model-reasoning.ts';
|
|
3
|
+
/** A user choice for the Bot's future replies; never a per-input runtime override. */
|
|
4
|
+
export interface BotModelSelectionUpdateRequest {
|
|
5
|
+
readonly workspaceId: string;
|
|
6
|
+
readonly modelProviderId: string;
|
|
7
|
+
readonly reasoningEffort?: ModelReasoningEffort;
|
|
8
|
+
}
|
|
9
|
+
export interface BotModelSelectionUpdateResult {
|
|
10
|
+
readonly ok: boolean;
|
|
11
|
+
readonly code?: string;
|
|
12
|
+
readonly profile?: BotProfile;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/delegation.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
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' | 'verifying' | 'result_ready' | 'accepted' | 'failed' | 'cancelled' | 'superseded';
|
|
8
|
-
export declare const WORK_SESSION_STATUSES: readonly ["paused", "queued", "starting", "running", "waiting_user", "verifying", "result_ready", "accepted", "failed", "cancelled", "superseded"];
|
|
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"];
|
|
9
9
|
export type InputSurface = 'desktop' | 'quick_chat' | 'tui' | 'remote';
|
|
10
10
|
export interface DelegationOrigin {
|
|
11
|
+
readonly workId?: string;
|
|
11
12
|
readonly anchorMessageId: string;
|
|
12
13
|
readonly inputId: string;
|
|
13
14
|
readonly surface: InputSurface;
|
|
@@ -66,14 +67,41 @@ export interface SessionReport {
|
|
|
66
67
|
readonly planId: string | null;
|
|
67
68
|
readonly status: WorkSessionStatus;
|
|
68
69
|
readonly summary: string;
|
|
70
|
+
readonly taskBrief?: string;
|
|
69
71
|
readonly keyFindings: readonly string[];
|
|
70
72
|
readonly changedFiles: readonly {
|
|
71
73
|
readonly path: string;
|
|
72
74
|
readonly summary: string;
|
|
73
75
|
}[];
|
|
74
76
|
readonly evidenceRefs: readonly string[];
|
|
77
|
+
/** Persisted worker output is a claim; verification still comes from host Evidence. */
|
|
78
|
+
readonly contentSource?: {
|
|
79
|
+
readonly kind: 'worker_message' | 'task_results';
|
|
80
|
+
readonly conversationId?: string;
|
|
81
|
+
readonly messageId?: string;
|
|
82
|
+
readonly verification: 'unverified';
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export type DelegationEventKind = 'agent_message' | 'session_running' | 'session_spawned' | 'session_progress' | 'session_needs_user' | 'report_available' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
|
|
86
|
+
/** Local orchestration facts; never a human authorization or a verified result. */
|
|
87
|
+
export interface AgentMessage {
|
|
88
|
+
readonly replyTo?: string;
|
|
89
|
+
readonly messageId: string;
|
|
90
|
+
readonly workspaceId: string;
|
|
91
|
+
readonly sessionId: string;
|
|
92
|
+
readonly senderConversationId: string;
|
|
93
|
+
readonly recipientConversationId: string;
|
|
94
|
+
readonly direction: 'parent_to_child' | 'child_to_parent';
|
|
95
|
+
readonly purpose: 'update' | 'question' | 'answer';
|
|
96
|
+
readonly text: string;
|
|
97
|
+
readonly at: string;
|
|
98
|
+
}
|
|
99
|
+
export interface AgentActivity {
|
|
100
|
+
readonly eventId: string;
|
|
101
|
+
readonly sessionId: string;
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly state: 'queued' | 'started' | 'update' | 'question' | 'answer' | 'reported' | 'verified' | 'ended' | 'cancelled' | 'blocked';
|
|
75
104
|
}
|
|
76
|
-
export type DelegationEventKind = 'session_spawned' | 'session_progress' | 'session_needs_user' | 'session_verified' | 'session_ended' | 'user_intervened' | 'objective_signal' | 'digest_due';
|
|
77
105
|
export type JsonValue = null | string | number | boolean | readonly JsonValue[] | {
|
|
78
106
|
readonly [key: string]: JsonValue;
|
|
79
107
|
};
|
|
@@ -101,6 +129,7 @@ export interface AgentReplyMeta {
|
|
|
101
129
|
readonly surfacing: 'interrupt' | 'message' | 'digest' | 'silent';
|
|
102
130
|
}
|
|
103
131
|
export interface ReplySessionState {
|
|
132
|
+
readonly sourceRevision?: string;
|
|
104
133
|
readonly sessionId: string;
|
|
105
134
|
readonly status: WorkSessionStatus;
|
|
106
135
|
}
|
|
@@ -155,6 +184,26 @@ export interface DispositionEvent {
|
|
|
155
184
|
readonly replyMessageId?: string;
|
|
156
185
|
}
|
|
157
186
|
export type VerificationOutcome = 'passed' | 'failed' | 'partial' | 'unverifiable';
|
|
187
|
+
/** Host-bound manual completion review; distinct from acceptance of a completed result. */
|
|
188
|
+
export interface SessionCompletionReview {
|
|
189
|
+
readonly sessionId: string;
|
|
190
|
+
readonly reviewToken: string;
|
|
191
|
+
readonly criteria: readonly {
|
|
192
|
+
readonly id: string;
|
|
193
|
+
readonly description: string;
|
|
194
|
+
}[];
|
|
195
|
+
readonly report: string;
|
|
196
|
+
readonly confirmed?: boolean;
|
|
197
|
+
}
|
|
198
|
+
export type SessionConfirmationInput = {
|
|
199
|
+
readonly workspaceId: string;
|
|
200
|
+
readonly sessionId: string;
|
|
201
|
+
} & ({
|
|
202
|
+
readonly stage?: 'result_acceptance';
|
|
203
|
+
} | {
|
|
204
|
+
readonly stage: 'manual_completion';
|
|
205
|
+
readonly reviewToken: string;
|
|
206
|
+
});
|
|
158
207
|
export type IndependentVerifierState = 'passed' | 'failed' | 'not_required' | 'missing';
|
|
159
208
|
export interface VerificationCheck {
|
|
160
209
|
readonly name: string;
|
|
@@ -200,6 +249,22 @@ export interface SurfacingEvent {
|
|
|
200
249
|
readonly severity: 'info' | 'notable' | 'urgent';
|
|
201
250
|
readonly deadlineImminent?: boolean;
|
|
202
251
|
}
|
|
252
|
+
/** Explicit user uploads are factual user context, never execution authority. */
|
|
253
|
+
export type ProjectInputAttachment = {
|
|
254
|
+
readonly id: string;
|
|
255
|
+
readonly name: string;
|
|
256
|
+
readonly mimeType: string;
|
|
257
|
+
readonly size: number;
|
|
258
|
+
readonly sourceKind: 'user_upload';
|
|
259
|
+
} & ({
|
|
260
|
+
readonly kind: 'image';
|
|
261
|
+
readonly dataUrl: string;
|
|
262
|
+
} | {
|
|
263
|
+
readonly kind: 'text';
|
|
264
|
+
readonly text: string;
|
|
265
|
+
} | {
|
|
266
|
+
readonly kind: 'unsupported';
|
|
267
|
+
});
|
|
203
268
|
export interface ProjectInput {
|
|
204
269
|
readonly inputId: string;
|
|
205
270
|
readonly workspaceId: string;
|
|
@@ -208,6 +273,7 @@ export interface ProjectInput {
|
|
|
208
273
|
readonly anchorRefs: readonly string[];
|
|
209
274
|
readonly quoteRefs: readonly string[];
|
|
210
275
|
readonly attachmentRefs: readonly string[];
|
|
276
|
+
readonly attachments?: readonly ProjectInputAttachment[];
|
|
211
277
|
readonly createdAt: string;
|
|
212
278
|
}
|
|
213
279
|
export type PendingApprovalState = 'open' | 'approved' | 'denied' | 'expired' | 'stale';
|
package/dist/delegation.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* Project-agent delegation contracts. Pure projections only; nothing here runs a tool.
|
|
3
|
-
* The user-visible conclusion of a work session is projectGoalPlan's conclusion.
|
|
4
|
-
*/
|
|
1
|
+
import { deriveSessionFacts } from "./session-facts.js";
|
|
5
2
|
import { projectGoalPlan, } from "./task-overview.js";
|
|
6
|
-
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'verifying',
|
|
3
|
+
export const WORK_SESSION_STATUSES = ['paused', 'queued', 'starting', 'running', 'waiting_user', 'waiting_agent', 'verifying',
|
|
7
4
|
'result_ready', 'accepted', 'failed', 'cancelled', 'superseded'];
|
|
8
5
|
function fnv1a(text) {
|
|
9
6
|
let hash = 0x811c9dc5;
|
|
@@ -44,38 +41,13 @@ export function createDelegationEvent(input) {
|
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
43
|
function delegationStatus(snapshot, meta, projected) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (meta.acceptance === 'confirm' && meta.accepted !== true)
|
|
55
|
-
return 'result_ready';
|
|
56
|
-
return 'accepted';
|
|
57
|
-
}
|
|
58
|
-
if (meta.supersededBy)
|
|
59
|
-
return 'superseded';
|
|
60
|
-
if (meta.phase === 'paused')
|
|
61
|
-
return 'paused';
|
|
62
|
-
// 复核进行中盖过「需要你」。草稿、待批准、等回答的计划在独立复核时都显示 verifying。
|
|
63
|
-
if (meta.verifying || meta.phase === 'verifying')
|
|
64
|
-
return 'verifying';
|
|
65
|
-
if (projected.actionRight === 'needs_you')
|
|
66
|
-
return 'waiting_user';
|
|
67
|
-
if (snapshot.runnerStatus === 'exploring')
|
|
68
|
-
return 'verifying';
|
|
69
|
-
if (meta.phase === 'starting')
|
|
70
|
-
return 'starting';
|
|
71
|
-
if (snapshot.status === 'approved'
|
|
72
|
-
|| snapshot.status === 'accepted'
|
|
73
|
-
|| snapshot.status === 'paused'
|
|
74
|
-
|| snapshot.status === 'interrupted'
|
|
75
|
-
|| projected.actionRight === 'paused') {
|
|
76
|
-
return 'queued';
|
|
77
|
-
}
|
|
78
|
-
return 'running';
|
|
44
|
+
return deriveSessionFacts({ status: snapshot.status, runnerStatus: snapshot.runnerStatus,
|
|
45
|
+
accepted: meta.accepted === true || (snapshot.status === 'completed' && meta.acceptance !== 'confirm'
|
|
46
|
+
&& meta.accepted === undefined && !meta.verifying && !snapshot.runnerStatus),
|
|
47
|
+
superseded: Boolean(meta.supersededBy), phase: meta.phase,
|
|
48
|
+
needsUser: snapshot.status === 'awaiting_approval', verificationActive: meta.verifying === true,
|
|
49
|
+
...(snapshot.agentWaiting ? { blockedReason: 'waiting_parent_agent' } : {}),
|
|
50
|
+
}).status;
|
|
79
51
|
}
|
|
80
52
|
/**
|
|
81
53
|
* Project a GoalPlan snapshot into a work session.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Read-only display facts. A saved operation is not proof that its task completed. */
|
|
2
|
+
export interface EvidenceSourceDescription {
|
|
3
|
+
readonly evidenceRef: string;
|
|
4
|
+
readonly toolName?: string;
|
|
5
|
+
readonly createdAt?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ProjectAgentEvidenceReadRequest {
|
|
8
|
+
readonly evidenceRef?: string;
|
|
9
|
+
/** Source descriptions only; at most 100 unique references, no body or artifact reads. */
|
|
10
|
+
readonly evidenceRefs?: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ProjectAgentEvidenceReadResult {
|
|
13
|
+
readonly ok: boolean;
|
|
14
|
+
readonly code?: string;
|
|
15
|
+
readonly evidenceRef?: string;
|
|
16
|
+
readonly kind?: 'file' | 'command' | 'diff' | 'screenshot' | 'observation';
|
|
17
|
+
readonly summary?: string;
|
|
18
|
+
readonly truncated?: boolean;
|
|
19
|
+
readonly availability?: 'available' | 'metadata_only' | 'not_found' | 'unavailable';
|
|
20
|
+
readonly source?: EvidenceSourceDescription;
|
|
21
|
+
readonly items?: readonly EvidenceSourceDescription[];
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/goal.d.ts
CHANGED
|
@@ -164,9 +164,9 @@ export interface EvidenceIndexRecord {
|
|
|
164
164
|
readonly toolName?: string;
|
|
165
165
|
readonly createdAt: string;
|
|
166
166
|
readonly artifactRefs?: readonly string[];
|
|
167
|
-
/** Redacted, bounded execution-time snapshot of a successful
|
|
167
|
+
/** Redacted, bounded execution-time snapshot of a successful local Tool Result. */
|
|
168
168
|
readonly bodyPreview?: {
|
|
169
|
-
readonly kind: 'file';
|
|
169
|
+
readonly kind: 'file' | 'command';
|
|
170
170
|
readonly text: string;
|
|
171
171
|
readonly truncated: boolean;
|
|
172
172
|
};
|
|
@@ -444,7 +444,7 @@ export interface GoalRunTrace {
|
|
|
444
444
|
readonly lastCheckpointNodeId?: string;
|
|
445
445
|
readonly events: readonly GoalRunEvent[];
|
|
446
446
|
}
|
|
447
|
-
export type GoalSuccessCriterionKind = 'command' | 'test' | 'file-contains' | 'file-exists' | 'manual';
|
|
447
|
+
export type GoalSuccessCriterionKind = 'command' | 'test' | 'file-contains' | 'file-exists' | 'model_review' | 'manual';
|
|
448
448
|
export interface GoalSuccessCriterion {
|
|
449
449
|
readonly id: string;
|
|
450
450
|
readonly kind: GoalSuccessCriterionKind;
|
|
@@ -452,6 +452,21 @@ export interface GoalSuccessCriterion {
|
|
|
452
452
|
readonly command?: string;
|
|
453
453
|
readonly path?: string;
|
|
454
454
|
readonly expect?: string;
|
|
455
|
+
readonly authority?: {
|
|
456
|
+
readonly source: 'model' | 'user' | 'project_policy' | 'legacy_unknown';
|
|
457
|
+
readonly sourceRef?: string;
|
|
458
|
+
readonly version: number;
|
|
459
|
+
readonly verifier: 'mechanical' | 'host_model' | 'human';
|
|
460
|
+
readonly rationale: string;
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
export interface GoalModelReview {
|
|
464
|
+
readonly criterionId: string;
|
|
465
|
+
readonly sourceRevision: string;
|
|
466
|
+
readonly verifierRunId: string;
|
|
467
|
+
readonly passed: boolean;
|
|
468
|
+
readonly evidenceRefs: readonly string[];
|
|
469
|
+
readonly checkedAt: string;
|
|
455
470
|
}
|
|
456
471
|
export interface GoalCriterionResult {
|
|
457
472
|
readonly criterionId: string;
|
|
@@ -678,6 +693,9 @@ export interface GoalPlan {
|
|
|
678
693
|
readonly successCriteria: readonly GoalSuccessCriterion[];
|
|
679
694
|
readonly criterionResults: readonly GoalCriterionResult[];
|
|
680
695
|
readonly manualConfirmations?: readonly GoalManualConfirmation[];
|
|
696
|
+
readonly modelReviews?: readonly GoalModelReview[];
|
|
697
|
+
/** Host-derived current revision for checking semantic review freshness. */
|
|
698
|
+
readonly modelReviewSourceRevision?: string;
|
|
681
699
|
readonly boundaries: GoalBoundaries;
|
|
682
700
|
readonly exceptionPolicies: ExceptionPolicy[];
|
|
683
701
|
/** 顶层汇总(来源于子任务) */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export type { ProjectWorkReceipt, ProjectWorkRecovery, ProjectWorkState, ProjectTurnEnd } from './work-coordination.ts';
|
|
2
|
+
export { deriveSessionFacts, type SessionFactSnapshot } from './session-facts.ts';
|
|
3
|
+
export { projectAgentFailureKind, classifyProjectAgentFailure, type ProjectRecoveryFailureKind, type ProviderRequestRecovery, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
|
|
4
|
+
export type { EvidenceSourceDescription, ProjectAgentEvidenceReadRequest, ProjectAgentEvidenceReadResult } from './evidence-inspection.ts';
|
|
5
|
+
export { toolActivityPreview, toolActivitySummary } from './tool-activity-preview.ts';
|
|
6
|
+
export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort, type ModelReasoningEffort } from './model-reasoning.ts';
|
|
1
7
|
export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead } from './selection-reference.ts';
|
|
2
8
|
export { buildModelMenuGroups, modelMenuChannelName, type ModelMenuRow } from './model-menu.ts';
|
|
3
9
|
export { evaluateUiDelivery } from './ui-delivery-verification.ts';
|
|
@@ -737,7 +743,7 @@ export interface PermissionGrant {
|
|
|
737
743
|
readonly toolCallId: string;
|
|
738
744
|
readonly granted: boolean;
|
|
739
745
|
readonly duration: PermissionDuration;
|
|
740
|
-
readonly scope?: string;
|
|
746
|
+
readonly scope?: string | import('./local-image.ts').LocalImagePermissionScope;
|
|
741
747
|
readonly decidedAt: string;
|
|
742
748
|
}
|
|
743
749
|
/** Application-owned shell process snapshot. Source conversation is provenance, not ownership. */
|
|
@@ -870,3 +876,5 @@ export * from './model-routing.ts';
|
|
|
870
876
|
export * from './project.ts';
|
|
871
877
|
export * from './objectives.ts';
|
|
872
878
|
export * from './remote-access-settings.ts';
|
|
879
|
+
export type { BotModelSelectionUpdateRequest, BotModelSelectionUpdateResult } from './bot-model-selection.ts';
|
|
880
|
+
export * from './local-image.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { deriveSessionFacts } from "./session-facts.js";
|
|
2
|
+
export { projectAgentFailureKind, classifyProjectAgentFailure } from "./project-agent-failure.js";
|
|
3
|
+
export { toolActivityPreview, toolActivitySummary } from "./tool-activity-preview.js";
|
|
4
|
+
export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort } from "./model-reasoning.js";
|
|
1
5
|
export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
|
|
2
6
|
export { evaluateUiDelivery } from "./ui-delivery-verification.js";
|
|
3
7
|
export { DESKTOP_PREVIEW_PROTOCOL, DESKTOP_PREVIEW_CAPABILITY, DESKTOP_PREVIEW_TOOL } from "./desktop-preview.js";
|
|
@@ -37,3 +41,4 @@ export * from "./model-routing.js";
|
|
|
37
41
|
export * from "./project.js";
|
|
38
42
|
export * from "./objectives.js";
|
|
39
43
|
export * from "./remote-access-settings.js";
|
|
44
|
+
export * from "./local-image.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** ADR 90: local images are factual context, never instructions or persisted pixels. */
|
|
2
|
+
export declare const LOCAL_IMAGE_CAPABILITY: "local.image.read";
|
|
3
|
+
export declare const LOCAL_IMAGE_TOOL: "view_image";
|
|
4
|
+
export declare const LOCAL_IMAGE_MAX_BYTES: number;
|
|
5
|
+
export declare const LOCAL_IMAGE_MAX_PIXELS = 24000000;
|
|
6
|
+
export type LocalImageMediaType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
|
7
|
+
export interface LocalImageMetadata {
|
|
8
|
+
path: string;
|
|
9
|
+
mediaType: LocalImageMediaType;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
byteLength: number;
|
|
13
|
+
sha256: string;
|
|
14
|
+
artifactRef: string;
|
|
15
|
+
}
|
|
16
|
+
/** Ephemeral host sideband. Object identity must also be validated by its Provider. */
|
|
17
|
+
export interface LocalImageObservation extends LocalImageMetadata {
|
|
18
|
+
kind: 'local_image';
|
|
19
|
+
dataUrl: string;
|
|
20
|
+
}
|
|
21
|
+
import type { ClientToolResult, PermissionGrant } from './index.ts';
|
|
22
|
+
export interface LocalImagePermissionScope {
|
|
23
|
+
capabilityId: typeof LOCAL_IMAGE_CAPABILITY;
|
|
24
|
+
path: string;
|
|
25
|
+
workspacePath: string | null;
|
|
26
|
+
action: 'read_image_for_model';
|
|
27
|
+
}
|
|
28
|
+
/** Concrete image grant; legacy grant scopes remain unchanged. */
|
|
29
|
+
export interface LocalImagePermissionGrant extends PermissionGrant {
|
|
30
|
+
scope: LocalImagePermissionScope | typeof LOCAL_IMAGE_CAPABILITY;
|
|
31
|
+
}
|
|
32
|
+
export interface LocalImageToolResult extends ClientToolResult {
|
|
33
|
+
modelContext?: {
|
|
34
|
+
visualObservations: readonly LocalImageObservation[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** ADR 90: local images are factual context, never instructions or persisted pixels. */
|
|
2
|
+
export const LOCAL_IMAGE_CAPABILITY = 'local.image.read';
|
|
3
|
+
export const LOCAL_IMAGE_TOOL = 'view_image';
|
|
4
|
+
export const LOCAL_IMAGE_MAX_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
export const LOCAL_IMAGE_MAX_PIXELS = 24_000_000;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Provider-declared effort values. Unknown capabilities do not create UI choices. */
|
|
2
|
+
export type ModelReasoningEffort = 'off' | 'low' | 'medium' | 'default' | 'high' | 'xhigh' | 'max';
|
|
3
|
+
export declare function isModelReasoningEffort(value: unknown): value is ModelReasoningEffort;
|
|
4
|
+
export declare function modelReasoningLevels(provider: {
|
|
5
|
+
readonly supportsReasoning?: unknown;
|
|
6
|
+
readonly reasoningEffortLevels?: unknown;
|
|
7
|
+
}): readonly ModelReasoningEffort[];
|
|
8
|
+
export declare function modelDefaultReasoningEffort(provider: {
|
|
9
|
+
readonly supportsReasoning?: unknown;
|
|
10
|
+
readonly reasoningEffortLevels?: unknown;
|
|
11
|
+
readonly reasoningEffort?: unknown;
|
|
12
|
+
readonly defaultEffort?: unknown;
|
|
13
|
+
}): ModelReasoningEffort | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const ORDER = ['off', 'low', 'medium', 'default', 'high', 'xhigh', 'max'];
|
|
2
|
+
export function isModelReasoningEffort(value) {
|
|
3
|
+
return ORDER.includes(value);
|
|
4
|
+
}
|
|
5
|
+
export function modelReasoningLevels(provider) {
|
|
6
|
+
if (provider.supportsReasoning === false || !Array.isArray(provider.reasoningEffortLevels))
|
|
7
|
+
return [];
|
|
8
|
+
const declared = provider.reasoningEffortLevels;
|
|
9
|
+
return ORDER.filter(value => declared.includes(value));
|
|
10
|
+
}
|
|
11
|
+
export function modelDefaultReasoningEffort(provider) {
|
|
12
|
+
const levels = modelReasoningLevels(provider);
|
|
13
|
+
for (const value of [provider.reasoningEffort, provider.defaultEffort, 'default', 'medium', 'high', 'low', ...levels]) {
|
|
14
|
+
if (isModelReasoningEffort(value) && levels.includes(value))
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
package/dist/model-routing.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ModelReasoningEffort } from './model-reasoning.ts';
|
|
1
2
|
/**
|
|
2
3
|
* Role and tier model routing. Resolution is pure; hosts apply the result.
|
|
3
4
|
* Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
|
|
@@ -10,6 +11,7 @@ export type RoleSetting = {
|
|
|
10
11
|
} | {
|
|
11
12
|
readonly mode: 'fixed';
|
|
12
13
|
readonly modelProviderId: string;
|
|
14
|
+
readonly reasoningEffort?: ModelReasoningEffort;
|
|
13
15
|
} | {
|
|
14
16
|
readonly mode: 'auto';
|
|
15
17
|
readonly pool: readonly string[];
|
|
@@ -65,7 +67,15 @@ export interface ModelRoutingMenuOption {
|
|
|
65
67
|
readonly supportsTools: boolean;
|
|
66
68
|
readonly supportsStructured: boolean;
|
|
67
69
|
readonly contextTokens: number;
|
|
70
|
+
readonly available?: boolean;
|
|
71
|
+
readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
|
|
72
|
+
readonly defaultReasoningEffort?: ModelReasoningEffort;
|
|
68
73
|
}
|
|
74
|
+
export interface BotRoleModelView {
|
|
75
|
+
readonly resolution: ModelResolution;
|
|
76
|
+
readonly eligibleModelIds: readonly string[];
|
|
77
|
+
}
|
|
78
|
+
export type BotModelViews = Partial<Record<ModelRole, BotRoleModelView>>;
|
|
69
79
|
/** Project one configured provider into the routing menu contract. */
|
|
70
80
|
export declare function projectModelRoutingMenuOption(provider: {
|
|
71
81
|
readonly id?: unknown;
|
|
@@ -81,6 +91,12 @@ export declare function projectModelRoutingMenuOption(provider: {
|
|
|
81
91
|
readonly toolUse?: unknown;
|
|
82
92
|
} | null;
|
|
83
93
|
readonly contextWindow?: unknown;
|
|
94
|
+
readonly apiKeyConfigured?: unknown;
|
|
95
|
+
readonly enabled?: unknown;
|
|
96
|
+
readonly supportsReasoning?: unknown;
|
|
97
|
+
readonly reasoningEffortLevels?: unknown;
|
|
98
|
+
readonly reasoningEffort?: unknown;
|
|
99
|
+
readonly defaultEffort?: unknown;
|
|
84
100
|
} | null | undefined): ModelRoutingMenuOption | null;
|
|
85
101
|
export interface CatalogModel {
|
|
86
102
|
readonly modelProviderId: string;
|
|
@@ -93,6 +109,7 @@ export interface CatalogModel {
|
|
|
93
109
|
readonly contextTokens?: number;
|
|
94
110
|
readonly local?: boolean;
|
|
95
111
|
readonly reasoningEffort?: string;
|
|
112
|
+
readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
|
|
96
113
|
}
|
|
97
114
|
export type ModelResolution = {
|
|
98
115
|
readonly ok: true;
|
|
@@ -101,7 +118,7 @@ export type ModelResolution = {
|
|
|
101
118
|
readonly sameFamilyAsWorker?: boolean;
|
|
102
119
|
} | {
|
|
103
120
|
readonly ok: false;
|
|
104
|
-
readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty';
|
|
121
|
+
readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty' | 'reasoning';
|
|
105
122
|
readonly missing: string;
|
|
106
123
|
};
|
|
107
124
|
export interface RoleModelRequest {
|
package/dist/model-routing.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Role and tier model routing. Resolution is pure; hosts apply the result.
|
|
3
|
-
* Order and filters follow ADR 83. An empty candidate set is an error, not a silent downgrade.
|
|
4
|
-
*/
|
|
1
|
+
import { modelDefaultReasoningEffort, modelReasoningLevels } from "./model-reasoning.js";
|
|
5
2
|
/** Project one configured provider into the routing menu contract. */
|
|
6
3
|
export function projectModelRoutingMenuOption(provider) {
|
|
7
4
|
if (!provider || typeof provider.id !== 'string' || !provider.id.trim())
|
|
@@ -24,6 +21,9 @@ export function projectModelRoutingMenuOption(provider) {
|
|
|
24
21
|
supportsTools: provider.supportsTools !== false && provider.capabilities?.toolUse !== false,
|
|
25
22
|
supportsStructured: provider.supportsStructured !== false,
|
|
26
23
|
contextTokens: Number.isFinite(context) && context > 0 ? context : 128_000,
|
|
24
|
+
available: provider.enabled !== false && provider.apiKeyConfigured === true,
|
|
25
|
+
reasoningEffortLevels: modelReasoningLevels(provider),
|
|
26
|
+
defaultReasoningEffort: modelDefaultReasoningEffort(provider),
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
const EXPLORER_MIN_CONTEXT = 8_000;
|
|
@@ -75,6 +75,8 @@ function inScope(model, policy) {
|
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
function missingText(input, reason) {
|
|
78
|
+
if (reason === 'reasoning')
|
|
79
|
+
return '所选模型不支持该推理强度';
|
|
78
80
|
if (reason === 'auto_pool')
|
|
79
81
|
return '所选模型不在自动池内';
|
|
80
82
|
const localOnly = input.projectPolicy?.scope?.localOnly === true;
|
|
@@ -226,10 +228,13 @@ export function resolveRoleModel(input) {
|
|
|
226
228
|
const chosen = ordered[0];
|
|
227
229
|
if (!chosen)
|
|
228
230
|
return fail(input, 'empty');
|
|
231
|
+
const requestedEffort = layer.setting.mode === 'fixed' ? layer.setting.reasoningEffort : undefined;
|
|
232
|
+
if (requestedEffort !== undefined && !chosen.reasoningEffortLevels?.includes(requestedEffort))
|
|
233
|
+
return fail(input, 'reasoning');
|
|
229
234
|
const source = layer.setting.mode === 'auto' ? 'auto' : layer.source;
|
|
230
235
|
return {
|
|
231
236
|
ok: true,
|
|
232
|
-
selection: toSelection(chosen),
|
|
237
|
+
selection: { ...toSelection(chosen), ...(requestedEffort !== undefined ? { reasoningEffort: requestedEffort } : {}) },
|
|
233
238
|
source,
|
|
234
239
|
...(input.role === 'verifier'
|
|
235
240
|
? { sameFamilyAsWorker: sameFamily(chosen, input.workerModel) }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DelegationEvent } from './delegation.ts';
|
|
2
|
+
export type ProjectRecoveryFailureKind = 'response_headers_timeout' | 'network' | 'stream_interrupted' | 'provider_transient' | 'rate_limited' | 'authentication' | 'invalid_request' | 'configuration' | 'permission' | 'budget_exhausted' | 'execution_outcome_unknown' | 'cancelled' | 'fatal';
|
|
3
|
+
/** Produced by the host request boundary; never inferred from assistant prose. */
|
|
4
|
+
export interface ProviderRequestRecovery {
|
|
5
|
+
readonly kind: ProjectRecoveryFailureKind;
|
|
6
|
+
readonly phase?: 'response_headers' | 'stream' | 'request';
|
|
7
|
+
readonly requestId?: string;
|
|
8
|
+
readonly attempts?: number;
|
|
9
|
+
readonly maxAttempts?: number;
|
|
10
|
+
readonly exhausted?: boolean;
|
|
11
|
+
readonly replaySafe?: boolean;
|
|
12
|
+
readonly retryable: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Legacy diagnostics are admitted only at this seam; structured host failure takes precedence. */
|
|
15
|
+
export declare function classifyProjectAgentFailure(reason: unknown, detail?: unknown): {
|
|
16
|
+
kind: ProjectRecoveryFailureKind;
|
|
17
|
+
retryable: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Host failure classification, including the persisted diagnostic prefix used by older cards. */
|
|
20
|
+
export declare function projectAgentFailureKind(reason: unknown): 'budget_exhausted' | 'unavailable';
|
|
21
|
+
/** Durable host facts for an explicit retry; never a new user authorization. */
|
|
22
|
+
export interface ProjectAgentTurnRecovery {
|
|
23
|
+
readonly events: readonly DelegationEvent[];
|
|
24
|
+
readonly throughSeq: number;
|
|
25
|
+
}
|
|
26
|
+
/** Factual recovery data returned by post_reply after anchor validation fails. */
|
|
27
|
+
export interface ReplyAnchorCandidate {
|
|
28
|
+
readonly messageId: string;
|
|
29
|
+
readonly text: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const RECOVERABLE = new Set(['response_headers_timeout', 'network', 'stream_interrupted', 'provider_transient', 'rate_limited']);
|
|
2
|
+
const FAILURE_KINDS = new Set([...RECOVERABLE, 'authentication', 'invalid_request', 'configuration', 'permission', 'budget_exhausted', 'execution_outcome_unknown', 'cancelled', 'fatal']);
|
|
3
|
+
/** Legacy diagnostics are admitted only at this seam; structured host failure takes precedence. */
|
|
4
|
+
export function classifyProjectAgentFailure(reason, detail) {
|
|
5
|
+
if (detail && typeof detail === 'object' && 'kind' in detail && FAILURE_KINDS.has(detail.kind)) {
|
|
6
|
+
const kind = detail.kind;
|
|
7
|
+
return { kind, retryable: RECOVERABLE.has(kind) && !('retryable' in detail && detail.retryable === false) };
|
|
8
|
+
}
|
|
9
|
+
const code = typeof reason === 'string' ? reason.trim().replace(/^代理暂时不可用:\s*/, '') : '';
|
|
10
|
+
let kind = 'fatal';
|
|
11
|
+
if (/^(agent_tool_budget_exhausted|agent_loop_exhausted|work_budget_limited)(?:\s*:|$)/.test(code))
|
|
12
|
+
kind = 'budget_exhausted';
|
|
13
|
+
else if (/^(execution_outcome_unknown|checkpoint_persistence_failed)(?:\s*:|$)/.test(code))
|
|
14
|
+
kind = 'execution_outcome_unknown';
|
|
15
|
+
else if (/^(work_execution_stopped|aborted|AbortError|user_stopped)(?:\s*:|$)/i.test(code))
|
|
16
|
+
kind = 'cancelled';
|
|
17
|
+
else if (/^(permission_denied|permission_revoked|authorization_denied)(?:\s*:|$)/i.test(code))
|
|
18
|
+
kind = 'permission';
|
|
19
|
+
else if (/^(connect timeout after|response_headers_timeout)|ConnectTimeoutError/.test(code))
|
|
20
|
+
kind = 'response_headers_timeout';
|
|
21
|
+
else if (/^(provider_stream_idle_timeout|provider_stream_interrupted)(?:\s*:|$)/.test(code))
|
|
22
|
+
kind = 'stream_interrupted';
|
|
23
|
+
else if (/^(HTTP\s*)?(401|403)(?:\s|:|$)|^(authentication_error|invalid_api_key|credential_unavailable)(?:\s*:|$)/i.test(code))
|
|
24
|
+
kind = 'authentication';
|
|
25
|
+
else if (/^(HTTP\s*)?429(?:\s|:|$)/i.test(code))
|
|
26
|
+
kind = 'rate_limited';
|
|
27
|
+
else if (/^(HTTP\s*)?(500|502|503|504)(?:\s|:|$)|^(server_error|server_is_overloaded)(?:\s*:|$)/i.test(code))
|
|
28
|
+
kind = 'provider_transient';
|
|
29
|
+
else if (/^(HTTP\s*)?(400|404|422)(?:\s|:|$)|^(invalid_request|provider_checkpoint_mismatch)(?:\s*:|$)/i.test(code))
|
|
30
|
+
kind = 'invalid_request';
|
|
31
|
+
else if (/^(CERT_|ERR_CERT_|UNABLE_TO_VERIFY|SELF_SIGNED|DEPTH_ZERO_SELF_SIGNED_CERT|provider_not_configured|work_budget_host_unavailable)/i.test(code))
|
|
32
|
+
kind = 'configuration';
|
|
33
|
+
else if (/^(fetch failed|network|ECONNRESET|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|EAI_AGAIN|UND_ERR_(SOCKET|CONNECT_TIMEOUT)|(?:net::)?ERR_(CONNECTION|NETWORK|TIMED_OUT|NAME_NOT_RESOLVED|PROXY_CONNECTION_FAILED|TUNNEL_CONNECTION_FAILED|SOCKS_CONNECTION_FAILED|INTERNET_DISCONNECTED))/i.test(code))
|
|
34
|
+
kind = 'network';
|
|
35
|
+
return { kind, retryable: RECOVERABLE.has(kind) };
|
|
36
|
+
}
|
|
37
|
+
/** Host failure classification, including the persisted diagnostic prefix used by older cards. */
|
|
38
|
+
export function projectAgentFailureKind(reason) {
|
|
39
|
+
if (typeof reason !== 'string')
|
|
40
|
+
return 'unavailable';
|
|
41
|
+
const code = reason.trim().replace(/^代理暂时不可用:\s*/, '');
|
|
42
|
+
return /^(agent_tool_budget_exhausted|agent_loop_exhausted|work_budget_limited)(?:\s*:|$)/.test(code)
|
|
43
|
+
? 'budget_exhausted' : 'unavailable';
|
|
44
|
+
}
|
package/dist/project.d.ts
CHANGED
|
@@ -189,6 +189,58 @@ export interface BotListFilter {
|
|
|
189
189
|
readonly query?: string;
|
|
190
190
|
readonly needsYouOnly?: boolean;
|
|
191
191
|
}
|
|
192
|
+
/** Bounded, redacted display preview; never an execution or Evidence object. */
|
|
193
|
+
export interface ProjectAgentToolPreview {
|
|
194
|
+
readonly text: string;
|
|
195
|
+
readonly truncated: boolean;
|
|
196
|
+
readonly redacted: boolean;
|
|
197
|
+
}
|
|
198
|
+
export interface ProjectAgentToolActivity {
|
|
199
|
+
readonly kind: 'tool';
|
|
200
|
+
readonly id: string;
|
|
201
|
+
readonly name: string;
|
|
202
|
+
readonly status: 'preparing' | 'running' | 'done' | 'error' | 'stopped';
|
|
203
|
+
readonly startedAt?: string;
|
|
204
|
+
readonly finishedAt?: string;
|
|
205
|
+
readonly summary?: string;
|
|
206
|
+
readonly input?: ProjectAgentToolPreview;
|
|
207
|
+
readonly result?: ProjectAgentToolPreview;
|
|
208
|
+
readonly receivedChars?: number;
|
|
209
|
+
}
|
|
210
|
+
/** Public conversation update, never hidden reasoning, Tool Result or Evidence.
|
|
211
|
+
* User agent_turn records may persist these as publicUpdates (100 / 32000 chars).
|
|
212
|
+
* Legacy rounds[].text is not a public-update source.
|
|
213
|
+
*/
|
|
214
|
+
export interface ProjectAgentPublicUpdate {
|
|
215
|
+
readonly id: string;
|
|
216
|
+
readonly text: string;
|
|
217
|
+
}
|
|
218
|
+
/** Ephemeral interactive-turn presentation, including explicit wake retries. No hidden reasoning or Evidence. */
|
|
219
|
+
export interface ProjectAgentActivity {
|
|
220
|
+
readonly workspaceId: string;
|
|
221
|
+
readonly conversationId: string;
|
|
222
|
+
readonly turnId: string;
|
|
223
|
+
readonly revision: number;
|
|
224
|
+
readonly startedAt: string;
|
|
225
|
+
readonly finishedAt?: string;
|
|
226
|
+
readonly modelSelection?: Pick<import('./model-routing.ts').RuntimeModelSelection, 'modelProviderId' | 'reasoningEffort'>;
|
|
227
|
+
readonly replyTo: readonly string[];
|
|
228
|
+
readonly phase: 'waiting' | 'thinking' | 'responding' | 'tool' | 'settling' | 'done' | 'error' | 'stopped' | 'disposed';
|
|
229
|
+
readonly replyText: string;
|
|
230
|
+
readonly segments: readonly (({
|
|
231
|
+
readonly kind: 'text';
|
|
232
|
+
} & ProjectAgentPublicUpdate) | ProjectAgentToolActivity)[];
|
|
233
|
+
}
|
|
234
|
+
export interface ProjectAgentStopResponseRequest {
|
|
235
|
+
readonly workspaceId: string;
|
|
236
|
+
readonly turnId: string;
|
|
237
|
+
}
|
|
238
|
+
export type ProjectAgentStopResponseResult = {
|
|
239
|
+
readonly ok: true;
|
|
240
|
+
} | {
|
|
241
|
+
readonly ok: false;
|
|
242
|
+
readonly code: 'PROJECT_AGENT_DISABLED' | 'NOT_FOUND' | 'HOST_OFFLINE' | 'STALE_TURN' | 'INVALID_INPUT';
|
|
243
|
+
};
|
|
192
244
|
export interface BotListSession {
|
|
193
245
|
readonly status: WorkSessionStatus;
|
|
194
246
|
readonly updatedAt?: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WorkSessionStatus } from './delegation.ts';
|
|
2
|
+
export interface SessionFactSnapshot {
|
|
3
|
+
readonly status: WorkSessionStatus;
|
|
4
|
+
readonly verificationActive: boolean;
|
|
5
|
+
readonly needsUser: boolean;
|
|
6
|
+
readonly blockedReason?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function deriveSessionFacts(input: {
|
|
9
|
+
status?: string;
|
|
10
|
+
phase?: string;
|
|
11
|
+
runnerStatus?: string;
|
|
12
|
+
accepted?: boolean;
|
|
13
|
+
superseded?: boolean;
|
|
14
|
+
needsUser?: boolean;
|
|
15
|
+
blockedReason?: string;
|
|
16
|
+
verificationActive?: boolean;
|
|
17
|
+
}): SessionFactSnapshot;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function deriveSessionFacts(input) {
|
|
2
|
+
const verificationActive = input.verificationActive === true;
|
|
3
|
+
let status;
|
|
4
|
+
if (input.status === 'cancelled')
|
|
5
|
+
status = 'cancelled';
|
|
6
|
+
else if (input.status === 'failed')
|
|
7
|
+
status = 'failed';
|
|
8
|
+
else if (input.accepted)
|
|
9
|
+
status = 'accepted';
|
|
10
|
+
else if (input.needsUser || input.runnerStatus === 'waiting_user')
|
|
11
|
+
status = 'waiting_user';
|
|
12
|
+
else if (input.blockedReason === 'waiting_parent_agent' && input.phase !== 'paused' && !input.superseded && input.runnerStatus !== 'paused')
|
|
13
|
+
status = 'waiting_agent';
|
|
14
|
+
else if (input.runnerStatus === 'blocked')
|
|
15
|
+
status = 'waiting_user';
|
|
16
|
+
else if (verificationActive)
|
|
17
|
+
status = 'verifying';
|
|
18
|
+
else if (input.status === 'completed' && ['running', 'starting', 'waiting_provider', 'resuming_after_compaction'].includes(input.runnerStatus || ''))
|
|
19
|
+
status = 'running';
|
|
20
|
+
else if (input.status === 'completed')
|
|
21
|
+
status = 'result_ready';
|
|
22
|
+
else if (input.superseded)
|
|
23
|
+
status = 'superseded';
|
|
24
|
+
else if (input.phase === 'paused')
|
|
25
|
+
status = 'paused';
|
|
26
|
+
else if (input.phase === 'starting')
|
|
27
|
+
status = 'starting';
|
|
28
|
+
else if (['approved', 'accepted', 'paused', 'interrupted'].includes(input.status || '') || input.phase === 'queued')
|
|
29
|
+
status = 'queued';
|
|
30
|
+
else
|
|
31
|
+
status = 'running';
|
|
32
|
+
return { status, verificationActive: status === 'verifying', needsUser: status === 'waiting_user',
|
|
33
|
+
...(input.blockedReason ? { blockedReason: input.blockedReason } : {}) };
|
|
34
|
+
}
|
package/dist/task-overview.d.ts
CHANGED
|
@@ -246,6 +246,8 @@ export interface GoalPlanProjectionSnapshot {
|
|
|
246
246
|
readonly runnerStatus?: GoalRunnerStatus;
|
|
247
247
|
/** Runner 阻塞是否由系统基础设施持有,而不是用户行动权。 */
|
|
248
248
|
readonly systemBlocked?: boolean;
|
|
249
|
+
/** A delegated worker is coordinating with its parent, not asking the human. */
|
|
250
|
+
readonly agentWaiting?: boolean;
|
|
249
251
|
/**
|
|
250
252
|
* 同一会话此刻是否有前台活流(正在输出 / 调工具 / compact)。
|
|
251
253
|
* 由聚合层从 listActiveStreams 写入;协议层只认这个布尔事实。
|
package/dist/task-overview.js
CHANGED
|
@@ -271,6 +271,9 @@ function decideGoalPlan(snapshot) {
|
|
|
271
271
|
}
|
|
272
272
|
const planStillActive = status === 'executing' || status === 'accepted' || status === 'approved';
|
|
273
273
|
const conversationLive = snapshot.conversationLive === true;
|
|
274
|
+
if (snapshot.agentWaiting && runnerStatus !== 'waiting_user' && ['executing', 'completed'].includes(status)) {
|
|
275
|
+
return { actionRight: 'peer_advancing', nextAction: 'none', statusLabel: '等待主 Bot 答复', actionLabel: '' };
|
|
276
|
+
}
|
|
274
277
|
const recoverableSystemBlocked = runnerStatus === 'blocked'
|
|
275
278
|
&& snapshot.systemBlocked === true;
|
|
276
279
|
// System infrastructure failures are not user decisions. A foreground turn may
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProjectAgentToolPreview } from './project.ts';
|
|
2
|
+
/** One bounded display seam for tool parameters/results in live and historical presentation. It never executes a tool. */
|
|
3
|
+
export declare function toolActivityPreview(value: unknown, limit: number): ProjectAgentToolPreview;
|
|
4
|
+
export declare function toolActivitySummary(input: Readonly<Record<string, unknown>> | null | undefined): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const PRIVATE_FIELD = /(?:api.?key|token|secret|password|credential|authorization|cookie|private.?key|reasoning|thinking)/i;
|
|
2
|
+
/** One bounded display seam for tool parameters/results in live and historical presentation. It never executes a tool. */
|
|
3
|
+
export function toolActivityPreview(value, limit) {
|
|
4
|
+
if (typeof value === 'string' && value.length > 64_000)
|
|
5
|
+
return { text: '', truncated: true, redacted: true };
|
|
6
|
+
let redacted = false, truncated = false, nodes = 0;
|
|
7
|
+
const cleanText = (text) => {
|
|
8
|
+
const bounded = text.slice(0, 6000);
|
|
9
|
+
if (bounded.length < text.length)
|
|
10
|
+
truncated = true;
|
|
11
|
+
const clean = bounded
|
|
12
|
+
.replace(/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g, '[redacted]')
|
|
13
|
+
.replace(/AKIA[0-9A-Z]{16}/g, '[redacted]')
|
|
14
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi, 'Bearer [redacted]')
|
|
15
|
+
.replace(/((?:api[_-]?key|token|secret|password|authorization|cookie)\s*["']?\s*[:=]\s*["']?)[^\s,"';}]+/gi, '$1[redacted]')
|
|
16
|
+
.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*/g, '[redacted]');
|
|
17
|
+
if (clean !== bounded)
|
|
18
|
+
redacted = true;
|
|
19
|
+
return clean;
|
|
20
|
+
};
|
|
21
|
+
const visit = (item, depth = 0) => {
|
|
22
|
+
if (++nodes > 160 || depth > 6) {
|
|
23
|
+
truncated = true;
|
|
24
|
+
return '[truncated]';
|
|
25
|
+
}
|
|
26
|
+
if (typeof item === 'string')
|
|
27
|
+
return cleanText(item);
|
|
28
|
+
if (item == null || typeof item === 'boolean' || typeof item === 'number')
|
|
29
|
+
return item;
|
|
30
|
+
if (Array.isArray(item)) {
|
|
31
|
+
if (item.length > 40)
|
|
32
|
+
truncated = true;
|
|
33
|
+
return item.slice(0, 40).map(child => visit(child, depth + 1));
|
|
34
|
+
}
|
|
35
|
+
if (typeof item === 'object') {
|
|
36
|
+
const fields = [];
|
|
37
|
+
for (const key in item) {
|
|
38
|
+
if (!Object.hasOwn(item, key))
|
|
39
|
+
continue;
|
|
40
|
+
if (fields.length >= 40) {
|
|
41
|
+
truncated = true;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
if (PRIVATE_FIELD.test(key)) {
|
|
45
|
+
redacted = true;
|
|
46
|
+
fields.push([key, '[redacted]']);
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
fields.push([cleanText(key), visit(item[key], depth + 1)]);
|
|
50
|
+
}
|
|
51
|
+
return Object.fromEntries(fields);
|
|
52
|
+
}
|
|
53
|
+
return String(item);
|
|
54
|
+
};
|
|
55
|
+
let parsed = value;
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
try {
|
|
58
|
+
parsed = JSON.parse(value);
|
|
59
|
+
}
|
|
60
|
+
catch { /* Plain terminal/file output. */ }
|
|
61
|
+
}
|
|
62
|
+
const clean = visit(parsed);
|
|
63
|
+
const text = typeof clean === 'string' ? clean : JSON.stringify(clean ?? null, null, 2);
|
|
64
|
+
return { text: text.slice(0, limit), truncated: truncated || text.length > limit, redacted };
|
|
65
|
+
}
|
|
66
|
+
export function toolActivitySummary(input) {
|
|
67
|
+
const value = input?.path ?? input?.command ?? input?.cmd ?? input?.query ?? input?.title;
|
|
68
|
+
return typeof value === 'string' ? toolActivityPreview(value.replace(/\s+/g, ' ').trim(), 160).text : '';
|
|
69
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ProjectRecoveryFailureKind } from './project-agent-failure.ts';
|
|
2
|
+
/** Local host reservation; neither model text nor a UI timer owns recovery. */
|
|
3
|
+
export interface ProjectWorkRecovery {
|
|
4
|
+
readonly failureKind: ProjectRecoveryFailureKind;
|
|
5
|
+
readonly retryable: boolean;
|
|
6
|
+
readonly autoAttempts: number;
|
|
7
|
+
readonly failedTurnId: string;
|
|
8
|
+
readonly retryAt?: string;
|
|
9
|
+
readonly reservationId?: string;
|
|
10
|
+
readonly deadlineAt?: string;
|
|
11
|
+
readonly blockedCode?: 'RECOVERY_CHECKPOINT_UNAVAILABLE';
|
|
12
|
+
}
|
|
13
|
+
export type ProjectWorkState = 'runnable' | 'waiting_children' | 'waiting_user' | 'retry_wait' | 'paused' | 'budget_limited' | 'blocked_system' | 'delivered' | 'cancelled';
|
|
14
|
+
export type ProjectTurnEnd = 'reply_committed' | 'awaiting_children' | 'yielded' | 'awaiting_user' | 'budget_limited' | 'provider_retryable' | 'no_progress' | 'user_stopped' | 'fatal';
|
|
15
|
+
export interface ProjectWorkReceipt {
|
|
16
|
+
readonly schemaVersion: 1;
|
|
17
|
+
readonly workId: string;
|
|
18
|
+
readonly workspaceId: string;
|
|
19
|
+
readonly parentConversationId: string;
|
|
20
|
+
readonly anchorInputIds: readonly string[];
|
|
21
|
+
readonly sessionIds: readonly string[];
|
|
22
|
+
readonly state: ProjectWorkState;
|
|
23
|
+
readonly revision: number;
|
|
24
|
+
readonly checkpointRef?: string;
|
|
25
|
+
readonly nativeCheckpointRef?: string;
|
|
26
|
+
readonly recovery?: ProjectWorkRecovery;
|
|
27
|
+
readonly end?: ProjectTurnEnd;
|
|
28
|
+
readonly attemptId?: string;
|
|
29
|
+
readonly pendingEventIds?: readonly string[];
|
|
30
|
+
readonly waitFor: readonly {
|
|
31
|
+
readonly kind: 'session' | 'approval' | 'question' | 'retry_timer';
|
|
32
|
+
readonly id: string;
|
|
33
|
+
}[];
|
|
34
|
+
readonly consumedEventIds: readonly string[];
|
|
35
|
+
readonly pendingResultRefs: readonly string[];
|
|
36
|
+
readonly lastDeliveredFactKey?: string;
|
|
37
|
+
readonly budgetRef?: string;
|
|
38
|
+
readonly budget?: {
|
|
39
|
+
readonly modelRequests: number;
|
|
40
|
+
readonly toolCalls: number;
|
|
41
|
+
readonly tokens: number;
|
|
42
|
+
readonly costUsd: number;
|
|
43
|
+
readonly unknownUsage: boolean;
|
|
44
|
+
readonly unknownCost: boolean;
|
|
45
|
+
readonly limits: {
|
|
46
|
+
readonly maxModelRequests: number;
|
|
47
|
+
readonly maxToolCalls: number;
|
|
48
|
+
readonly maxTokens?: number;
|
|
49
|
+
readonly maxCostUsd?: number;
|
|
50
|
+
readonly source: string;
|
|
51
|
+
};
|
|
52
|
+
readonly attempts: Readonly<Record<string, {
|
|
53
|
+
readonly role: string;
|
|
54
|
+
readonly requests?: number;
|
|
55
|
+
readonly modelProviderId?: string;
|
|
56
|
+
readonly checkpointRef?: string;
|
|
57
|
+
readonly pendingTools?: readonly {
|
|
58
|
+
readonly toolCallId: string | null;
|
|
59
|
+
readonly capabilityId: string | null;
|
|
60
|
+
}[];
|
|
61
|
+
}>>;
|
|
62
|
+
readonly uncertainDispatches?: readonly {
|
|
63
|
+
readonly attemptId: string;
|
|
64
|
+
readonly role: string;
|
|
65
|
+
readonly toolCallId: string | null;
|
|
66
|
+
readonly capabilityId: string | null;
|
|
67
|
+
}[];
|
|
68
|
+
};
|
|
69
|
+
readonly stopScope: 'reply' | 'work';
|
|
70
|
+
readonly updatedAt: string;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|