@peer-agent/protocol 0.1.0-rc.3 → 0.1.0-rc.30

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 (65) 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 +76 -0
  18. package/dist/delegation-coordination.js +1 -0
  19. package/dist/delegation.d.ts +189 -6
  20. package/dist/delegation.js +39 -39
  21. package/dist/document-reference.d.ts +81 -0
  22. package/dist/document-reference.js +1 -0
  23. package/dist/evidence-inspection.d.ts +51 -0
  24. package/dist/evidence-inspection.js +1 -0
  25. package/dist/goal.d.ts +49 -2
  26. package/dist/index.d.ts +46 -5
  27. package/dist/index.js +19 -0
  28. package/dist/local-git.d.ts +44 -0
  29. package/dist/local-git.js +3 -0
  30. package/dist/local-image.d.ts +53 -0
  31. package/dist/local-image.js +5 -0
  32. package/dist/model-reasoning.d.ts +13 -0
  33. package/dist/model-reasoning.js +18 -0
  34. package/dist/model-routing.d.ts +36 -2
  35. package/dist/model-routing.js +30 -5
  36. package/dist/project-agent-failure.d.ts +30 -0
  37. package/dist/project-agent-failure.js +44 -0
  38. package/dist/project-input-recovery.d.ts +65 -0
  39. package/dist/project-input-recovery.js +5 -0
  40. package/dist/project-recovery.d.ts +43 -0
  41. package/dist/project-recovery.js +1 -0
  42. package/dist/project.d.ts +63 -0
  43. package/dist/project.js +2 -5
  44. package/dist/resource-edit-execution.d.ts +68 -0
  45. package/dist/resource-edit-execution.js +96 -0
  46. package/dist/resource-edit.d.ts +237 -0
  47. package/dist/resource-edit.js +134 -0
  48. package/dist/resource-feedback.d.ts +91 -0
  49. package/dist/resource-feedback.js +120 -0
  50. package/dist/resource-file-replace.d.ts +36 -0
  51. package/dist/resource-file-replace.js +40 -0
  52. package/dist/resource-reference-hints.d.ts +3 -0
  53. package/dist/resource-reference-hints.js +58 -0
  54. package/dist/resource-window.d.ts +138 -0
  55. package/dist/resource-window.js +116 -0
  56. package/dist/session-facts.d.ts +29 -0
  57. package/dist/session-facts.js +35 -0
  58. package/dist/system-context.d.ts +6 -0
  59. package/dist/task-overview.d.ts +89 -0
  60. package/dist/task-overview.js +317 -17
  61. package/dist/tool-activity-preview.d.ts +4 -0
  62. package/dist/tool-activity-preview.js +72 -0
  63. package/dist/work-coordination.d.ts +136 -0
  64. package/dist/work-coordination.js +1 -0
  65. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,14 +1,23 @@
1
- export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead } from './selection-reference.ts';
1
+ export type { AttentionCard, BotDecisionSnapshot, BotAttentionItem, BotAttentionRequest, BotAttentionResult } from './attention.ts';
2
+ export type { ProjectWorkBudgetLimits, ProjectWorkBudgetBoundary, ProjectReplyRecoveryAction, ProjectWorkReceipt, ProjectWorkRecovery, ProjectWorkState, ProjectTurnEnd, ProjectReplyFailureStatus, ProjectAgentSilentWait, } from './work-coordination.ts';
3
+ export type { CoordinationAction, CoordinationLifecycle, CoordinationMandate, CoordinationDecision, TaskTransitionPhase, TaskTransition, CoordinationExecutionBinding, CoordinationSessionFacts, } from './delegation-coordination.ts';
4
+ export { deriveSessionFacts, type SessionFactSnapshot } from './session-facts.ts';
5
+ export { projectAgentFailureKind, classifyProjectAgentFailure, type ProjectRecoveryFailureKind, type ProviderRequestRecovery, type ProjectAgentTurnRecovery, type ReplyAnchorCandidate } from './project-agent-failure.ts';
6
+ export type { EvidenceSourceDescription, EvidenceDeliveryBinding, EvidenceDelivery, ProjectAgentEvidenceReadRequest, ProjectAgentEvidenceReadResult } from './evidence-inspection.ts';
7
+ export { toolActivityPreview, toolActivitySummary } from './tool-activity-preview.ts';
8
+ export { isModelReasoningEffort, modelReasoningLevels, modelDefaultReasoningEffort, type ModelReasoningEffort } from './model-reasoning.ts';
9
+ export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead, } from './selection-reference.ts';
2
10
  export { buildModelMenuGroups, modelMenuChannelName, type ModelMenuRow } from './model-menu.ts';
3
11
  export { evaluateUiDelivery } from './ui-delivery-verification.ts';
4
12
  export { DESKTOP_PREVIEW_PROTOCOL, DESKTOP_PREVIEW_CAPABILITY, DESKTOP_PREVIEW_TOOL } from './desktop-preview.ts';
5
13
  export type { DesktopPreviewRequest, DesktopPreviewReply } from './desktop-preview.ts';
6
- export type { UiDeliveryIdentity, UiDeliveryRequirement, UiDeliveryObservation, UiDeliveryJudgment, UiDeliveryGap } from './ui-delivery-verification.ts';
14
+ export type { UiDeliveryIdentity, UiDeliveryRequirement, UiDeliveryObservation, UiDeliveryJudgment, UiDeliveryGap, } from './ui-delivery-verification.ts';
7
15
  export { REMOTE_PROTOCOL_VERSION, parseRemoteReadRequest, admitRemoteRead } from './remote-access.ts';
8
16
  export type { RemoteReadRequest, RemoteReadContext, RemoteReadRejection, RemoteReadAdmission } from './remote-access.ts';
9
17
  export { REMOTE_PROJECT_LIMITS, parseRemoteProjectRequest, admitRemoteProject, parseRemoteDelegationProjection } from './remote-access.ts';
10
- export type { RemoteProjectGrant, RemoteProjectRequest, RemoteProjectContext, RemoteProjectRejection, RemoteProjectAdmission, RemoteDelegationProjection } from './remote-access.ts';
18
+ export type { RemoteProjectGrant, RemoteProjectRequest, RemoteProjectContext, RemoteProjectRejection, RemoteProjectAdmission, RemoteDelegationProjection, } from './remote-access.ts';
11
19
  export type LocalAccessLevel = 'ask_before_local' | 'session_local' | 'restricted_local' | 'full_local';
20
+ export type { BotAccessPolicy, BotAccessPolicyReadRequest, BotAccessPolicyUpdateRequest, BotAccessPolicyResult } from './bot-access-policy.ts';
12
21
  export type { ConversationLifetimeUsage, ProviderRequestUsage, RuntimeTurnUsage, UsageAmounts, UsageScope, } from './usage-accounting.ts';
13
22
  export type CapabilityRiskLevel = 'L0_inert' | 'L1_local_read' | 'L2_local_write' | 'L3_external_write' | 'L4_privileged' | 'L5_destructive';
14
23
  export type DataLevel = 'D0_public' | 'D1_internal' | 'D2_sensitive' | 'D3_private' | 'D4_regulated';
@@ -430,7 +439,7 @@ export interface LlmOAuthStatus {
430
439
  readonly accountId?: string;
431
440
  readonly expiresAt?: string;
432
441
  }
433
- export type { AccountUsageSource, AccountUsageScope, AccountUsageBalance, AccountUsageSpend, AccountUsageUnavailable, AccountUsageLocal } from './account-usage.js';
442
+ export type { AccountUsageSource, AccountUsageScope, AccountUsageBalance, AccountUsageSpend, AccountUsageUnavailable, AccountUsageLocal, } from './account-usage.js';
434
443
  /** 订阅额度窗口(session / weekly / model 等)。 */
435
444
  export interface LlmSubscriptionQuotaWindow {
436
445
  readonly id: string;
@@ -718,6 +727,18 @@ export interface ClientToolCall extends RuntimeToolCall {
718
727
  readonly dataLevel: DataLevel;
719
728
  readonly requestedAt: string;
720
729
  }
730
+ /** Host permission wait events. Requests are presentation, never permission truth. */
731
+ export interface ChatPermissionRequest {
732
+ readonly streamId: string;
733
+ readonly call: ClientToolCall;
734
+ readonly deadlineAt?: string;
735
+ }
736
+ export interface ChatPermissionSettled {
737
+ readonly streamId: string;
738
+ readonly toolCallIds: readonly string[];
739
+ readonly granted?: boolean;
740
+ readonly reason?: string;
741
+ }
721
742
  export interface ClientToolCallPollRequest {
722
743
  readonly sessionId: string;
723
744
  readonly projectionId?: string;
@@ -733,11 +754,13 @@ export interface ClientToolCallPollResult {
733
754
  }
734
755
  export type PermissionDuration = 'once' | 'task' | 'session' | 'scope' | 'persistent' | 'denied';
735
756
  export interface PermissionGrant {
757
+ /** Host-issued policy version; audit provenance, never a client authority token. */
758
+ readonly policyRevision?: string;
736
759
  readonly grantId: string;
737
760
  readonly toolCallId: string;
738
761
  readonly granted: boolean;
739
762
  readonly duration: PermissionDuration;
740
- readonly scope?: string;
763
+ readonly scope?: string | import('./local-image.ts').LocalImagePermissionScope;
741
764
  readonly decidedAt: string;
742
765
  }
743
766
  /** Application-owned shell process snapshot. Source conversation is provenance, not ownership. */
@@ -867,6 +890,24 @@ export * from './task-overview.ts';
867
890
  export * from './skill-marketplace.ts';
868
891
  export * from './delegation.ts';
869
892
  export * from './model-routing.ts';
893
+ export * from './document-reference.ts';
870
894
  export * from './project.ts';
871
895
  export * from './objectives.ts';
872
896
  export * from './remote-access-settings.ts';
897
+ export type { BotModelSelectionUpdateRequest, BotModelSelectionUpdateResult } from './bot-model-selection.ts';
898
+ export * from './local-image.ts';
899
+ export * from './bot-conversation-read.ts';
900
+ export * from './project-recovery.ts';
901
+ export * from './local-git.ts';
902
+ export * from './agent-supervision.ts';
903
+ export type { CapabilityBlocker, DelegationCapabilityAdmission } from './capability-admission.ts';
904
+ export * from './project-input-recovery.ts';
905
+ export { botResourceReferences } from './resource-reference-hints.ts';
906
+ export type { ResourceWindowCheckpointRequest, ResourceWindowCheckpointAck, ResourceWindowCloseBlocked, ResourceWindowReturnRequest, ResourceWindowReturnAck, ResourceWindowHistoryEntry, ResourceWindowHistoryResult, ResourceWindowReadRequest, ResourceWindowReadResult, ResourceWindowResource, ResourceWindowNavigation, ResourceWindowOpenRequest, ResourceWindowOwner, ResourceWindowIdentity, ResourceWindowContext, ResourceWindowStatus, ResourceWindowResult } from './resource-window.ts';
907
+ export { normalizeResourceWindowRequest, normalizeResourceWindowOwner, normalizeResourceWindowNavigation } from './resource-window.ts';
908
+ export * from './browser-window.js';
909
+ export * from './resource-feedback.js';
910
+ export * from './resource-edit.ts';
911
+ export * from './resource-file-replace.ts';
912
+ export * from './resource-edit-execution.ts';
913
+ export { decideFollowUp, type FollowUpOwner, type FollowUpReason, type FollowUpProjection } from './task-overview.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";
@@ -34,6 +38,21 @@ export * from "./task-overview.js";
34
38
  export * from "./skill-marketplace.js";
35
39
  export * from "./delegation.js";
36
40
  export * from "./model-routing.js";
41
+ export * from "./document-reference.js";
37
42
  export * from "./project.js";
38
43
  export * from "./objectives.js";
39
44
  export * from "./remote-access-settings.js";
45
+ export * from "./local-image.js";
46
+ export * from "./bot-conversation-read.js";
47
+ export * from "./project-recovery.js";
48
+ export * from "./local-git.js";
49
+ export * from "./agent-supervision.js";
50
+ export * from "./project-input-recovery.js";
51
+ export { botResourceReferences } from "./resource-reference-hints.js";
52
+ export { normalizeResourceWindowRequest, normalizeResourceWindowOwner, normalizeResourceWindowNavigation } from "./resource-window.js";
53
+ export * from './browser-window.js';
54
+ export * from './resource-feedback.js';
55
+ export * from "./resource-edit.js";
56
+ export * from "./resource-file-replace.js";
57
+ export * from "./resource-edit-execution.js";
58
+ export { decideFollowUp } from "./task-overview.js";
@@ -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
7
  export type ModelRole = 'project_agent' | 'session_worker' | 'explorer' | 'verifier' | 'visual_verifier' | 'memory_curator' | 'objective_probe' | 'compactor';
7
- export type RoleSetting = {
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;
@@ -75,6 +86,10 @@ function inScope(model, policy) {
75
86
  return true;
76
87
  }
77
88
  function missingText(input, reason) {
89
+ if (reason === 'fast_mode')
90
+ return '所选连接不支持快速通道,请选择正常通道或支持的连接';
91
+ if (reason === 'reasoning')
92
+ return '所选模型不支持该推理强度';
78
93
  if (reason === 'auto_pool')
79
94
  return '所选模型不在自动池内';
80
95
  const localOnly = input.projectPolicy?.scope?.localOnly === true;
@@ -226,10 +241,20 @@ export function resolveRoleModel(input) {
226
241
  const chosen = ordered[0];
227
242
  if (!chosen)
228
243
  return fail(input, 'empty');
244
+ const parameters = routingParameters(layer.setting, input.routing.tiers);
245
+ const requestedEffort = parameters.reasoningEffort;
246
+ if (requestedEffort !== undefined && !chosen.reasoningEffortLevels?.includes(requestedEffort))
247
+ return fail(input, 'reasoning');
248
+ if (parameters.fastMode && chosen.supportsFastMode !== true)
249
+ return fail(input, 'fast_mode');
229
250
  const source = layer.setting.mode === 'auto' ? 'auto' : layer.source;
230
251
  return {
231
252
  ok: true,
232
- selection: toSelection(chosen),
253
+ selection: {
254
+ ...toSelection(chosen),
255
+ ...(requestedEffort !== undefined ? { reasoningEffort: requestedEffort } : {}),
256
+ fastMode: parameters.fastMode,
257
+ },
233
258
  source,
234
259
  ...(input.role === 'verifier'
235
260
  ? { 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 {};