@peer-agent/protocol 0.1.0-rc.4 → 0.1.0-rc.41

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.
Files changed (86) hide show
  1. package/dist/acceptance-close-gate.d.ts +10 -1
  2. package/dist/acceptance-close-gate.js +12 -0
  3. package/dist/agent-supervision.d.ts +81 -0
  4. package/dist/agent-supervision.js +1 -0
  5. package/dist/attention.d.ts +44 -0
  6. package/dist/attention.js +1 -0
  7. package/dist/bot-access-policy.d.ts +29 -0
  8. package/dist/bot-access-policy.js +1 -0
  9. package/dist/bot-conversation-read.d.ts +25 -0
  10. package/dist/bot-conversation-read.js +9 -0
  11. package/dist/bot-model-selection.d.ts +13 -0
  12. package/dist/bot-model-selection.js +1 -0
  13. package/dist/browser-window.d.ts +48 -0
  14. package/dist/browser-window.js +23 -0
  15. package/dist/capability-admission.d.ts +20 -0
  16. package/dist/capability-admission.js +1 -0
  17. package/dist/delegation-coordination.d.ts +81 -0
  18. package/dist/delegation-coordination.js +1 -0
  19. package/dist/delegation.d.ts +216 -7
  20. package/dist/delegation.js +43 -39
  21. package/dist/document-reference.d.ts +83 -0
  22. package/dist/document-reference.js +1 -0
  23. package/dist/evidence-inspection.d.ts +64 -0
  24. package/dist/evidence-inspection.js +1 -0
  25. package/dist/goal.d.ts +50 -2
  26. package/dist/index.d.ts +56 -5
  27. package/dist/index.js +25 -0
  28. package/dist/input-prediction.d.ts +86 -0
  29. package/dist/input-prediction.js +48 -0
  30. package/dist/intent-coordination.d.ts +201 -0
  31. package/dist/intent-coordination.js +1 -0
  32. package/dist/interactive-result.d.ts +363 -0
  33. package/dist/interactive-result.js +215 -0
  34. package/dist/interactive-verification.d.ts +41 -0
  35. package/dist/interactive-verification.js +65 -0
  36. package/dist/local-git.d.ts +44 -0
  37. package/dist/local-git.js +3 -0
  38. package/dist/local-image.d.ts +53 -0
  39. package/dist/local-image.js +5 -0
  40. package/dist/model-reasoning.d.ts +13 -0
  41. package/dist/model-reasoning.js +18 -0
  42. package/dist/model-routing.d.ts +37 -3
  43. package/dist/model-routing.js +31 -5
  44. package/dist/project-agent-failure.d.ts +30 -0
  45. package/dist/project-agent-failure.js +44 -0
  46. package/dist/project-input-recovery.d.ts +65 -0
  47. package/dist/project-input-recovery.js +5 -0
  48. package/dist/project-recovery.d.ts +43 -0
  49. package/dist/project-recovery.js +1 -0
  50. package/dist/project.d.ts +81 -0
  51. package/dist/project.js +8 -5
  52. package/dist/remote-access.d.ts +15 -0
  53. package/dist/remote-access.js +1 -1
  54. package/dist/reply-delivery.d.ts +28 -0
  55. package/dist/reply-delivery.js +1 -0
  56. package/dist/resource-edit-execution.d.ts +68 -0
  57. package/dist/resource-edit-execution.js +96 -0
  58. package/dist/resource-edit.d.ts +237 -0
  59. package/dist/resource-edit.js +134 -0
  60. package/dist/resource-feedback-transport.d.ts +25 -0
  61. package/dist/resource-feedback-transport.js +93 -0
  62. package/dist/resource-feedback.d.ts +98 -0
  63. package/dist/resource-feedback.js +151 -0
  64. package/dist/resource-file-replace.d.ts +36 -0
  65. package/dist/resource-file-replace.js +40 -0
  66. package/dist/resource-reference-hints.d.ts +3 -0
  67. package/dist/resource-reference-hints.js +58 -0
  68. package/dist/resource-window.d.ts +222 -0
  69. package/dist/resource-window.js +252 -0
  70. package/dist/runtime-session-facts.d.ts +58 -0
  71. package/dist/runtime-session-facts.js +55 -0
  72. package/dist/session-control.d.ts +196 -0
  73. package/dist/session-control.js +48 -0
  74. package/dist/session-facts.d.ts +29 -0
  75. package/dist/session-facts.js +35 -0
  76. package/dist/system-context.d.ts +6 -0
  77. package/dist/task-overview.d.ts +90 -0
  78. package/dist/task-overview.js +322 -17
  79. package/dist/tool-activity-preview.d.ts +4 -0
  80. package/dist/tool-activity-preview.js +72 -0
  81. package/dist/usage-accounting.d.ts +1 -1
  82. package/dist/user-anchor.d.ts +17 -0
  83. package/dist/user-anchor.js +1 -0
  84. package/dist/work-coordination.d.ts +165 -0
  85. package/dist/work-coordination.js +1 -0
  86. package/package.json +1 -1
@@ -0,0 +1,65 @@
1
+ import { interactiveDigest, interactiveToken, normalizeInteractiveInspect, normalizeInteractiveOwner } from "./interactive-result.js";
2
+ import { normalizeSessionExecutionIdentity } from "./session-control.js";
3
+ const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v)
4
+ && [Object.prototype, null].includes(Object.getPrototypeOf(v)) && Object.values(Object.getOwnPropertyDescriptors(v)).every(d => 'value' in d);
5
+ const keys = (v, allowed) => Object.keys(v).every(key => allowed.includes(key));
6
+ const integer = (v) => Number.isSafeInteger(v) && Number(v) >= 0 && Number(v) <= 512 * 1024;
7
+ export function normalizeInteractiveReviewBinding(raw) {
8
+ return object(raw) && keys(raw, ['token']) && interactiveToken(raw.token) ? { token: raw.token } : undefined;
9
+ }
10
+ const INSPECTION_REF_PREFIX = 'interactive-inspection://';
11
+ export function interactiveInspectionEvidenceRef(evidenceId) {
12
+ if (!interactiveToken(evidenceId))
13
+ throw TypeError('invalid inspection evidence ID');
14
+ return `${INSPECTION_REF_PREFIX}${evidenceId}`;
15
+ }
16
+ export function isInteractiveInspectionEvidenceRef(raw) {
17
+ return typeof raw === 'string' && raw.startsWith(INSPECTION_REF_PREFIX) && interactiveToken(raw.slice(INSPECTION_REF_PREFIX.length));
18
+ }
19
+ export function normalizeInteractiveInspectionReceipt(raw) {
20
+ if (!object(raw) || !keys(raw, ['schemaVersion', 'evidenceId', 'owner', 'execution', 'conversationId', 'toolCallId', 'specHash', 'request', 'review', 'range', 'stateSource', 'computationTruncated', 'outputDigest', 'observedAt'])
21
+ || raw.schemaVersion !== 1 || !interactiveToken(raw.evidenceId) || !interactiveToken(raw.conversationId) || !interactiveToken(raw.toolCallId)
22
+ || !interactiveDigest(raw.specHash) || !interactiveDigest(raw.outputDigest) || typeof raw.observedAt !== 'string' || raw.observedAt.length > 40 || !Number.isFinite(Date.parse(raw.observedAt))
23
+ || !object(raw.review) || !keys(raw.review, ['verifierRunId', 'sourceRevision', 'targetsDigest']) || !interactiveToken(raw.review.verifierRunId)
24
+ || typeof raw.review.sourceRevision !== 'string' || !/^[a-f0-9]{64}$/.test(raw.review.sourceRevision) || !interactiveDigest(raw.review.targetsDigest)
25
+ || raw.computationTruncated !== undefined && typeof raw.computationTruncated !== 'boolean')
26
+ return;
27
+ const owner = normalizeInteractiveOwner(raw.owner), execution = normalizeSessionExecutionIdentity(raw.execution), request = normalizeInteractiveInspect(raw.request);
28
+ if (!owner || !execution || !request || request.target.kind !== 'result'
29
+ || owner.workspaceId !== request.target.reference.owner.workspaceId || owner.conversationId !== request.target.reference.owner.conversationId)
30
+ return;
31
+ let range;
32
+ if (raw.range !== undefined) {
33
+ const r = raw.range;
34
+ if (!object(r) || !keys(r, ['offset', 'returned', 'total', 'truncated']) || ![r.offset, r.returned, r.total].every(integer)
35
+ || Number(r.returned) > (request.limit ?? 4000) || Number(r.offset) + Number(r.returned) > Number(r.total) || typeof r.truncated !== 'boolean'
36
+ || r.offset !== (request.offset ?? 0) || r.truncated !== (Number(r.offset) + Number(r.returned) < Number(r.total)))
37
+ return;
38
+ range = { offset: Number(r.offset), returned: Number(r.returned), total: Number(r.total), truncated: r.truncated };
39
+ }
40
+ if ((request.view === 'metadata') === !!range)
41
+ return;
42
+ let stateSource;
43
+ if (raw.stateSource !== undefined) {
44
+ const s = raw.stateSource;
45
+ if (!object(s) || !keys(s, ['kind', 'stateDigest', 'followupId', 'stateRevision', 'selectionDigest']) || !interactiveDigest(s.stateDigest))
46
+ return;
47
+ if (s.kind === 'initial' && keys(s, ['kind', 'stateDigest']) && request.followupId === undefined)
48
+ stateSource = { kind: 'initial', stateDigest: s.stateDigest };
49
+ else if (s.kind === 'frozen-followup' && interactiveToken(s.followupId) && s.followupId === request.followupId
50
+ && Number.isSafeInteger(s.stateRevision) && Number(s.stateRevision) >= 0 && interactiveDigest(s.selectionDigest))
51
+ stateSource = {
52
+ kind: 'frozen-followup', followupId: s.followupId, stateRevision: Number(s.stateRevision), stateDigest: s.stateDigest, selectionDigest: s.selectionDigest
53
+ };
54
+ else
55
+ return;
56
+ }
57
+ if ((request.view === 'evaluate') !== !!stateSource || (request.view === 'evaluate'
58
+ ? typeof raw.computationTruncated !== 'boolean' : raw.computationTruncated !== undefined))
59
+ return;
60
+ const result = { schemaVersion: 1, evidenceId: raw.evidenceId, owner, execution, conversationId: raw.conversationId,
61
+ toolCallId: raw.toolCallId, specHash: raw.specHash, request, review: { verifierRunId: raw.review.verifierRunId,
62
+ sourceRevision: raw.review.sourceRevision, targetsDigest: raw.review.targetsDigest }, ...(range ? { range } : {}), ...(stateSource ? { stateSource } : {}),
63
+ ...(raw.computationTruncated !== undefined ? { computationTruncated: raw.computationTruncated } : {}), outputDigest: raw.outputDigest, observedAt: new Date(raw.observedAt).toISOString() };
64
+ return new TextEncoder().encode(JSON.stringify(result)).byteLength <= 16 * 1024 ? result : undefined;
65
+ }
@@ -0,0 +1,44 @@
1
+ /** ADR106: bounded repository observations; never arbitrary commands. */
2
+ export declare const LOCAL_GIT_CAPABILITY: "local.git.query";
3
+ export declare const LOCAL_GIT_TOOL: "git_query";
4
+ export type GitReadOperation = 'snapshot' | 'status' | 'log';
5
+ export interface GitReadQuery {
6
+ readonly path: string;
7
+ readonly operation?: GitReadOperation;
8
+ readonly limit?: number;
9
+ }
10
+ export interface GitReadObservation {
11
+ readonly repositoryPath: string;
12
+ readonly gitDirectory: string;
13
+ readonly commonDirectory: string;
14
+ readonly configurationSources: readonly string[];
15
+ readonly operation: GitReadOperation;
16
+ readonly startedAt: string;
17
+ readonly finishedAt: string;
18
+ readonly head: string | null;
19
+ readonly branch: string | null;
20
+ readonly unborn: boolean;
21
+ readonly origin: readonly string[];
22
+ readonly consistent: boolean;
23
+ readonly atomic: false;
24
+ readonly status?: {
25
+ readonly clean: boolean | null;
26
+ readonly submoduleCount: number;
27
+ readonly submodulesInspected: false;
28
+ readonly filtersDisabled: boolean;
29
+ readonly changed: number;
30
+ readonly untracked: number;
31
+ readonly entries: readonly {
32
+ readonly index: string;
33
+ readonly worktree: string;
34
+ readonly path: string;
35
+ readonly from?: string;
36
+ }[];
37
+ readonly truncated: boolean;
38
+ };
39
+ readonly commits: readonly {
40
+ readonly hash: string;
41
+ readonly committedAt: string;
42
+ readonly subject: string;
43
+ }[];
44
+ }
@@ -0,0 +1,3 @@
1
+ /** ADR106: bounded repository observations; never arbitrary commands. */
2
+ export const LOCAL_GIT_CAPABILITY = 'local.git.query';
3
+ export const LOCAL_GIT_TOOL = 'git_query';
@@ -0,0 +1,53 @@
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
+ fileIdentity?: {
28
+ dev: number;
29
+ ino: number;
30
+ size: number;
31
+ mtimeMs: number;
32
+ ctimeMs: number;
33
+ };
34
+ }
35
+ /** Local host-issued exact-image read authority; no pixels are persisted. */
36
+ export interface ImageReadGrant {
37
+ policyRevision?: string;
38
+ schemaVersion: 1;
39
+ grantId: string;
40
+ workspaceId: string | null;
41
+ conversationId: string;
42
+ expiresAt: number;
43
+ scope: LocalImagePermissionScope;
44
+ }
45
+ /** Concrete image grant; legacy grant scopes remain unchanged. */
46
+ export interface LocalImagePermissionGrant extends PermissionGrant {
47
+ scope: LocalImagePermissionScope | typeof LOCAL_IMAGE_CAPABILITY;
48
+ }
49
+ export interface LocalImageToolResult extends ClientToolResult {
50
+ modelContext?: {
51
+ visualObservations: readonly LocalImageObservation[];
52
+ };
53
+ }
@@ -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
+ }
@@ -1,10 +1,11 @@
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.
4
5
  */
5
6
  export type ModelTier = 'strong' | 'fast' | 'economy' | 'vision';
6
- export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor';
7
- export type RoleSetting = {
7
+ export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor' | 'input_predictor';
8
+ export type RoleSetting = ({
8
9
  readonly mode: 'tier';
9
10
  readonly tier: ModelTier;
10
11
  } | {
@@ -13,11 +14,26 @@ export type RoleSetting = {
13
14
  } | {
14
15
  readonly mode: 'auto';
15
16
  readonly pool: readonly string[];
17
+ }) & {
18
+ /** Undefined inherits the tier; null explicitly uses the model default. */
19
+ readonly reasoningEffort?: ModelReasoningEffort | null;
20
+ /** Undefined inherits the tier; false explicitly selects the normal channel. */
21
+ readonly fastMode?: boolean;
16
22
  };
17
23
  export interface ModelTierBinding {
18
24
  readonly primary: string;
19
25
  readonly fallbacks?: readonly string[];
26
+ readonly reasoningEffort?: ModelReasoningEffort;
27
+ readonly fastMode?: boolean;
20
28
  }
29
+ /** Admission matches the existing priority request encoders, never a model-name guess. */
30
+ export declare function modelSupportsFastMode(provider: {
31
+ readonly authMethod?: unknown;
32
+ }): boolean;
33
+ export declare function routingParameters(setting: RoleSetting, tiers: Partial<Record<ModelTier, ModelTierBinding>>): {
34
+ reasoningEffort: ModelReasoningEffort | undefined;
35
+ fastMode: boolean;
36
+ };
21
37
  export interface ModelRoutingSettings {
22
38
  readonly tiers: Partial<Record<ModelTier, ModelTierBinding>>;
23
39
  readonly roles: Partial<Record<ModelRole, RoleSetting>>;
@@ -40,6 +56,8 @@ export interface RuntimeModelSelection {
40
56
  readonly modelId: string;
41
57
  readonly modelProviderId: string;
42
58
  readonly reasoningEffort?: string;
59
+ /** Subscription priority channel. Encoding still admits only ChatGPT and Grok OAuth. */
60
+ readonly fastMode?: boolean;
43
61
  readonly family: string;
44
62
  }
45
63
  export interface ModelSelectionSnapshot {
@@ -65,7 +83,15 @@ export interface ModelRoutingMenuOption {
65
83
  readonly supportsTools: boolean;
66
84
  readonly supportsStructured: boolean;
67
85
  readonly contextTokens: number;
86
+ readonly available?: boolean;
87
+ readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
88
+ readonly defaultReasoningEffort?: ModelReasoningEffort;
89
+ }
90
+ export interface BotRoleModelView {
91
+ readonly resolution: ModelResolution;
92
+ readonly eligibleModelIds: readonly string[];
68
93
  }
94
+ export type BotModelViews = Partial<Record<ModelRole, BotRoleModelView>>;
69
95
  /** Project one configured provider into the routing menu contract. */
70
96
  export declare function projectModelRoutingMenuOption(provider: {
71
97
  readonly id?: unknown;
@@ -81,6 +107,12 @@ export declare function projectModelRoutingMenuOption(provider: {
81
107
  readonly toolUse?: unknown;
82
108
  } | null;
83
109
  readonly contextWindow?: unknown;
110
+ readonly apiKeyConfigured?: unknown;
111
+ readonly enabled?: unknown;
112
+ readonly supportsReasoning?: unknown;
113
+ readonly reasoningEffortLevels?: unknown;
114
+ readonly reasoningEffort?: unknown;
115
+ readonly defaultEffort?: unknown;
84
116
  } | null | undefined): ModelRoutingMenuOption | null;
85
117
  export interface CatalogModel {
86
118
  readonly modelProviderId: string;
@@ -93,6 +125,8 @@ export interface CatalogModel {
93
125
  readonly contextTokens?: number;
94
126
  readonly local?: boolean;
95
127
  readonly reasoningEffort?: string;
128
+ readonly reasoningEffortLevels?: readonly ModelReasoningEffort[];
129
+ readonly supportsFastMode?: boolean;
96
130
  }
97
131
  export type ModelResolution = {
98
132
  readonly ok: true;
@@ -101,7 +135,7 @@ export type ModelResolution = {
101
135
  readonly sameFamilyAsWorker?: boolean;
102
136
  } | {
103
137
  readonly ok: false;
104
- readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty';
138
+ readonly reason: 'capability' | 'scope' | 'auto_pool' | 'empty' | 'reasoning' | 'fast_mode';
105
139
  readonly missing: string;
106
140
  };
107
141
  export interface RoleModelRequest {
@@ -1,7 +1,15 @@
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";
2
+ /** Admission matches the existing priority request encoders, never a model-name guess. */
3
+ export function modelSupportsFastMode(provider) {
4
+ return provider.authMethod === 'oauth_chatgpt' || provider.authMethod === 'oauth_grok';
5
+ }
6
+ export function routingParameters(setting, tiers) {
7
+ const tier = setting.mode === 'tier' ? tiers[setting.tier] : undefined;
8
+ return {
9
+ reasoningEffort: (setting.reasoningEffort === undefined ? tier?.reasoningEffort : setting.reasoningEffort) ?? undefined,
10
+ fastMode: setting.fastMode ?? tier?.fastMode ?? false,
11
+ };
12
+ }
5
13
  /** Project one configured provider into the routing menu contract. */
6
14
  export function projectModelRoutingMenuOption(provider) {
7
15
  if (!provider || typeof provider.id !== 'string' || !provider.id.trim())
@@ -24,6 +32,9 @@ export function projectModelRoutingMenuOption(provider) {
24
32
  supportsTools: provider.supportsTools !== false && provider.capabilities?.toolUse !== false,
25
33
  supportsStructured: provider.supportsStructured !== false,
26
34
  contextTokens: Number.isFinite(context) && context > 0 ? context : 128_000,
35
+ available: provider.enabled !== false && provider.apiKeyConfigured === true,
36
+ reasoningEffortLevels: modelReasoningLevels(provider),
37
+ defaultReasoningEffort: modelDefaultReasoningEffort(provider),
27
38
  };
28
39
  }
29
40
  const EXPLORER_MIN_CONTEXT = 8_000;
@@ -45,6 +56,7 @@ function roleNeeds(input) {
45
56
  case 'objective_probe':
46
57
  return { tools: true, vision: false, structured: false, minContext: 0 };
47
58
  case 'compactor':
59
+ case 'input_predictor':
48
60
  return { tools: false, vision: false, structured: false, minContext: Math.max(context, 1) };
49
61
  default:
50
62
  return { tools: false, vision: false, structured: false, minContext: 0 };
@@ -75,6 +87,10 @@ function inScope(model, policy) {
75
87
  return true;
76
88
  }
77
89
  function missingText(input, reason) {
90
+ if (reason === 'fast_mode')
91
+ return '所选连接不支持快速通道,请选择正常通道或支持的连接';
92
+ if (reason === 'reasoning')
93
+ return '所选模型不支持该推理强度';
78
94
  if (reason === 'auto_pool')
79
95
  return '所选模型不在自动池内';
80
96
  const localOnly = input.projectPolicy?.scope?.localOnly === true;
@@ -226,10 +242,20 @@ export function resolveRoleModel(input) {
226
242
  const chosen = ordered[0];
227
243
  if (!chosen)
228
244
  return fail(input, 'empty');
245
+ const parameters = routingParameters(layer.setting, input.routing.tiers);
246
+ const requestedEffort = parameters.reasoningEffort;
247
+ if (requestedEffort !== undefined && !chosen.reasoningEffortLevels?.includes(requestedEffort))
248
+ return fail(input, 'reasoning');
249
+ if (parameters.fastMode && chosen.supportsFastMode !== true)
250
+ return fail(input, 'fast_mode');
229
251
  const source = layer.setting.mode === 'auto' ? 'auto' : layer.source;
230
252
  return {
231
253
  ok: true,
232
- selection: toSelection(chosen),
254
+ selection: {
255
+ ...toSelection(chosen),
256
+ ...(requestedEffort !== undefined ? { reasoningEffort: requestedEffort } : {}),
257
+ fastMode: parameters.fastMode,
258
+ },
233
259
  source,
234
260
  ...(input.role === 'verifier'
235
261
  ? { 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
+ }
@@ -0,0 +1,65 @@
1
+ import type { ResourceFeedback } from './resource-feedback.ts';
2
+ import type { ProjectInputAttachment, ProjectAgentSubmitInputResult } from './delegation.ts';
3
+ export type LocalInputSurface = 'desktop' | 'quick_chat' | 'tui';
4
+ export interface InputDraftQuote {
5
+ readonly messageId: string;
6
+ readonly text: string;
7
+ }
8
+ export interface InputDraftValue {
9
+ readonly text: string;
10
+ readonly quote: InputDraftQuote | null;
11
+ readonly attachments: readonly ProjectInputAttachment[];
12
+ readonly resourceFeedback?: readonly ResourceFeedback[];
13
+ }
14
+ /** User intent only. Presence here never means the input was received or executed. */
15
+ export interface UnconfirmedProjectInput {
16
+ readonly inputId: string;
17
+ readonly text: string;
18
+ readonly quoteRefs: readonly string[];
19
+ readonly answerTo?: string;
20
+ readonly attachments: readonly ProjectInputAttachment[];
21
+ readonly resourceFeedback?: readonly ResourceFeedback[];
22
+ readonly createdAt: string;
23
+ }
24
+ export interface ProjectInputDraftSnapshot {
25
+ readonly revision: number;
26
+ readonly draft: InputDraftValue;
27
+ readonly pending: readonly UnconfirmedProjectInput[];
28
+ }
29
+ export interface ProjectInputDraftReadRequest {
30
+ readonly workspaceId: string;
31
+ readonly surface: LocalInputSurface;
32
+ }
33
+ export type ProjectInputDraftReadResult = {
34
+ readonly ok: true;
35
+ readonly snapshot: ProjectInputDraftSnapshot;
36
+ } | {
37
+ readonly ok: false;
38
+ readonly code: string;
39
+ };
40
+ export interface ProjectInputDraftWriteRequest extends ProjectInputDraftReadRequest {
41
+ readonly revision: number;
42
+ readonly draft: Omit<InputDraftValue, 'attachments'> & {
43
+ readonly attachmentIds: readonly string[];
44
+ };
45
+ readonly pending: readonly (Omit<UnconfirmedProjectInput, 'attachments'> & {
46
+ readonly attachmentIds: readonly string[];
47
+ })[];
48
+ /** Already-stored attachments are referred to by ID; large bytes are sent only once. */
49
+ readonly uploads: readonly ProjectInputAttachment[];
50
+ }
51
+ export type ProjectInputDraftWriteResult = {
52
+ readonly ok: true;
53
+ readonly revision: number;
54
+ } | {
55
+ readonly ok: false;
56
+ readonly code: string;
57
+ };
58
+ export interface ProjectInputRecoveryPort {
59
+ read(request: ProjectInputDraftReadRequest): Promise<ProjectInputDraftReadResult>;
60
+ write(request: ProjectInputDraftWriteRequest): Promise<ProjectInputDraftWriteResult>;
61
+ submit(request: UnconfirmedProjectInput & ProjectInputDraftReadRequest): Promise<ProjectAgentSubmitInputResult>;
62
+ }
63
+ export declare function emptyInputDraft(): InputDraftValue;
64
+ /** A handoff failure may follow a durable receipt. Generic ok alone proves nothing. */
65
+ export declare function projectInputWasReceived(result: ProjectAgentSubmitInputResult | null | undefined, workspaceId: string, inputId: string): boolean;
@@ -0,0 +1,5 @@
1
+ export function emptyInputDraft() { return { text: '', quote: null, attachments: [] }; }
2
+ /** A handoff failure may follow a durable receipt. Generic ok alone proves nothing. */
3
+ export function projectInputWasReceived(result, workspaceId, inputId) {
4
+ return result?.input?.workspaceId === workspaceId && result.input.inputId === inputId;
5
+ }
@@ -0,0 +1,43 @@
1
+ /** Local maintenance controls. These commands never accept an execution verdict or a filesystem path. */
2
+ export interface ProjectRecoveryRequest {
3
+ readonly workspaceId: string;
4
+ /** `retain_all` ends every held work and child task in the plan bound by `planToken`; it never accepts ids. */
5
+ readonly action: 'inspect' | 'restore' | 'retain' | 'retain_all';
6
+ readonly planToken?: string;
7
+ readonly workId?: string;
8
+ readonly sessionId?: string;
9
+ }
10
+ export interface ProjectRecoveryWork {
11
+ readonly workId: string;
12
+ readonly title: string;
13
+ readonly disposition: 'held' | 'resume';
14
+ readonly reason: string;
15
+ }
16
+ export interface ProjectRecoveryView {
17
+ readonly phase: 'occupied' | 'inspection' | 'stopping' | 'backing_up' | 'restoring' | 'reconciling' | 'ready' | 'failed';
18
+ readonly planToken?: string;
19
+ readonly restored: boolean;
20
+ readonly canContinue: boolean;
21
+ readonly runtimeReady: boolean;
22
+ readonly completedCount: number;
23
+ readonly works: readonly ProjectRecoveryWork[];
24
+ readonly sessions: readonly {
25
+ readonly sessionId: string;
26
+ readonly title: string;
27
+ }[];
28
+ readonly holder?: {
29
+ readonly surface: 'desktop' | 'tui';
30
+ readonly version: string;
31
+ };
32
+ readonly backupAvailable: boolean;
33
+ readonly backupLocation?: string;
34
+ readonly code?: string;
35
+ }
36
+ export type ProjectRecoveryResult = {
37
+ readonly ok: true;
38
+ readonly view: ProjectRecoveryView;
39
+ } | {
40
+ readonly ok: false;
41
+ readonly code: string;
42
+ readonly view?: ProjectRecoveryView;
43
+ };
@@ -0,0 +1 @@
1
+ export {};