@tencent-ai/agent-harness 0.2.0-beta.10 → 0.2.0-beta.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/CHANGELOG.md +9 -0
- package/cli/CHANGELOG.md +42 -0
- package/cli/dist-server/shared.cjs +316 -315
- package/cli/dist-server/types/node/agent/agent-controller.d.ts +1 -0
- package/cli/dist-server/types/node/agent/index.d.ts +1 -0
- package/cli/dist-server/types/node/agent/interceptors/image-interceptors.d.ts +1 -2
- package/cli/dist-server/types/node/agent/interceptors/sandbox-interceptor.d.ts +1 -0
- package/cli/dist-server/types/node/agent/steer-model-input-preparer.d.ts +11 -0
- package/cli/dist-server/types/node/agent-task/agent-task.d.ts +12 -0
- package/cli/dist-server/types/node/agent-team/backends/teammate-backend-protocol.d.ts +2 -0
- package/cli/dist-server/types/node/agent-view/session-handoff.d.ts +7 -0
- package/cli/dist-server/types/node/channel/channel-protocol.d.ts +8 -8
- package/cli/dist-server/types/node/cli/cli-runtime-options.d.ts +24 -1
- package/cli/dist-server/types/node/command/clear-command-executor.d.ts +2 -0
- package/cli/dist-server/types/node/hooks/hook-protocol.d.ts +3 -67
- package/cli/dist-server/types/node/loopback/endpoint-provider.d.ts +3 -0
- package/cli/dist-server/types/node/loopback/server-protocol.d.ts +7 -0
- package/cli/dist-server/types/node/memory/memory-relevance-protocol.d.ts +6 -1
- package/cli/dist-server/types/node/memory/memory-relevance-service.d.ts +3 -2
- package/cli/dist-server/types/node/model/model-protocol.d.ts +4 -0
- package/cli/dist-server/types/node/security-review/gate.d.ts +1 -0
- package/cli/dist-server/types/node/security-review/protocol.d.ts +2 -0
- package/cli/dist-server/types/node/session/session-hook-host-adapter.d.ts +2 -2
- package/cli/dist-server/types/node/settings/current-session-model-transition.d.ts +5 -4
- package/cli/dist-server/types/node/settings/settings-protocol.d.ts +2 -0
- package/cli/dist-server/types/node/tools/a2a-cancel-task-tool.d.ts +4 -4
- package/cli/dist-server/types/node/tools/a2a-get-task-tool.d.ts +4 -4
- package/cli/dist-server/types/node/tools/audio-transcribe-tool.d.ts +1 -2
- package/cli/dist-server/types/node/tools/grep-tool.d.ts +2 -0
- package/cli/dist-server/types/node/tools/image-service.d.ts +3 -1
- package/cli/dist-server/types/node/tools/index.d.ts +1 -0
- package/cli/dist-server/types/node/tools/media-file-writer.d.ts +12 -0
- package/cli/dist-server/types/node/tools/multi-edit-tool.d.ts +4 -4
- package/cli/dist-server/types/node/tools/powershell-tool.d.ts +2 -0
- package/cli/dist-server/types/node/tools/send-message-tool.d.ts +2 -2
- package/cli/dist-server/types/node/tools/tool-hook-manager.d.ts +2 -2
- package/cli/dist-server/types/node/tools/tool-manager.d.ts +1 -0
- package/cli/dist-server/types/node/tools/tool-protocol.d.ts +2 -2
- package/cli/dist-server/types/node/tools/video-service.d.ts +2 -0
- package/cli/dist-server/types/node/tools/wecom-reply-tool.d.ts +2 -2
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +12 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +11 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +6 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/compact-strategy-base.d.ts +17 -5
- package/cli/dist-server/types/vendor/cbc-core/node/context/pre-switch-model.d.ts +34 -0
- package/cli/dist-server/types/vendor/cbc-core/node/hooks/hook-protocol.d.ts +118 -3
- package/cli/dist-server/types/vendor/cbc-core/node/message-queue/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/message-queue/injectable-content.d.ts +15 -18
- package/cli/dist-server/types/vendor/cbc-core/node/message-queue/steer-input-buffer-protocol.d.ts +12 -13
- package/cli/dist-server/types/vendor/cbc-core/node/message-queue/steer-input-buffer.d.ts +1 -2
- package/cli/dist-server/types/vendor/cbc-core/node/message-queue/steer-model-input-preparer-protocol.d.ts +13 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +11 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-fork-guard.d.ts +2 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-hook-manager.d.ts +2 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +9 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +9 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-store.d.ts +3 -3
- package/cli/dist-server/types/vendor/cbc-core/node/trace/trace-turn-gate.d.ts +13 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/error-utils.d.ts +7 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/index.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/markdown-code-utils.d.ts +15 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/message-content-utils.d.ts +3 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/responses-api-utils.d.ts +21 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/session-utils.d.ts +20 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/usage-utils.d.ts +18 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +3 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/logging/structured-event-log.d.ts +64 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +10 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-http-interceptor.d.ts +1 -15
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +13 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +7 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-refresh-bypass.d.ts +9 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +12 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +11 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +6 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compact-strategy-base.d.ts +17 -5
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-switch-model.d.ts +34 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/hook-protocol.d.ts +118 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/injectable-content.d.ts +15 -18
- package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/steer-input-buffer-protocol.d.ts +12 -13
- package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/steer-input-buffer.d.ts +1 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/steer-model-input-preparer-protocol.d.ts +13 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +11 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-fork-guard.d.ts +2 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-hook-manager.d.ts +2 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +9 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +9 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-store.d.ts +3 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/trace-turn-gate.d.ts +13 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/error-utils.d.ts +7 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/markdown-code-utils.d.ts +15 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/message-content-utils.d.ts +3 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/responses-api-utils.d.ts +21 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/session-utils.d.ts +20 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/usage-utils.d.ts +18 -0
- package/cli/dist-server/types/workspace/cbc-daemon/lib/node/daemon/daemon-auto-restart.d.ts +2 -2
- package/cli/dist-server/types/workspace/cbc-daemon/lib/node/daemon/daemon-protocol.d.ts +17 -1
- package/cli/dist-server/types/workspace/cbc-plugins/lib/node/mods/engine/enable-flag.d.ts +28 -24
- package/cli/dist-server/types/workspace/cbc-plugins/lib/node/mods/loader/bootstrap.d.ts +2 -2
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +3 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/logging/structured-event-log.d.ts +64 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +10 -0
- package/cli/dist-server/types/workspace/core/lib/common/utils/env-utils.d.ts +12 -1
- package/cli/dist-server/types/workspace/product/lib/common/model-catalog/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +36 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/language-model.d.ts +7 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +1 -1
- package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +2 -1
- package/cli/dist-server/types/workspace/telemetry/lib/common/tracing/index.d.ts +2 -2
- package/cli/dist-server/types/workspace/telemetry/lib/common/tracing/otel-env.d.ts +16 -5
- package/cli/dist-server/types/workspace/telemetry/lib/common/tracing/trace-protocol.d.ts +9 -0
- package/cli/package.json +1 -1
- package/cli/product.cloudhosted.json +1 -1
- package/cli/product.internal.json +1 -1
- package/cli/product.ioa.json +1 -1
- package/cli/product.json +1 -1
- package/cli/product.selfhosted.json +1 -1
- package/cli/vendor/shim/node-safe-delete-shim.cjs +20 -3
- package/cli/vendor/shim/sitecustomize.py +17 -4
- package/docs/acp-v2.md +21 -2
- package/docs/client.md +44 -0
- package/docs/errors.md +1 -0
- package/docs/in-process.md +1 -0
- package/lib/agent/v2.js +1 -1
- package/lib/application/services.d.ts +1 -0
- package/lib/application/services.js +1 -1
- package/lib/cli/main.js +3 -3
- package/lib/cli/options.d.ts +2 -1
- package/lib/cli/options.js +4 -2
- package/lib/harness/runtime.js +1 -1
- package/lib/harness/types.d.ts +2 -0
- package/lib/runtime/component-protocol.js +1 -1
- package/package.json +9 -9
|
@@ -1,5 +1,120 @@
|
|
|
1
|
-
import type { BackgroundTaskInfo, CronTaskInfo, FinalStopReason, HookEvent, HookExecutionOptions, HookExecutionResult, HookPermissionMode, NotificationType, SessionEndReason, SessionStartSource } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
|
-
import type { Session } from '../session/session-protocol.js';
|
|
1
|
+
import type { AgentInputItem, BackgroundTaskInfo, CronTaskInfo, FinalStopReason, HookEvent, HookExecutionOptions, HookExecutionResult, HookPermissionMode, NotificationType, SessionEndReason, SessionStartSource } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
|
+
import type { InterceptorGate, Session } from '../session/session-protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal Hook Provider interface
|
|
5
|
+
*
|
|
6
|
+
* Use @Component(Hook) to register internal hooks that execute
|
|
7
|
+
* alongside external shell hooks in HookManager.executeHooks().
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @Component(Hook)
|
|
12
|
+
* export class MyStopHook implements Hook {
|
|
13
|
+
* readonly event = HookEvent.STOP;
|
|
14
|
+
* readonly priority = HookPriority.Normal;
|
|
15
|
+
*
|
|
16
|
+
* async execute(input: HookInput): Promise<HookExecutionResult | undefined> {
|
|
17
|
+
* // Return undefined to skip, or HookExecutionResult to participate
|
|
18
|
+
* return undefined;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const Hook: unique symbol;
|
|
24
|
+
/**
|
|
25
|
+
* Data available only to in-process hooks.
|
|
26
|
+
*
|
|
27
|
+
* This context is never forwarded to command, HTTP, prompt, agent, or SDK hooks.
|
|
28
|
+
* It can therefore carry process-local data that must not become part of the
|
|
29
|
+
* serializable hook input contract.
|
|
30
|
+
*/
|
|
31
|
+
export interface InternalHookContext {
|
|
32
|
+
/** Structured input items for the current user prompt. */
|
|
33
|
+
inputItems?: readonly AgentInputItem[];
|
|
34
|
+
/** Files declared by the tool invocation of a PostToolUse hook (`ToolResult.producedArtifacts`). */
|
|
35
|
+
producedArtifacts?: ReadonlyArray<{
|
|
36
|
+
/** Artifact URI or process-local path. */
|
|
37
|
+
uri: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Set by the hook executor: resolves with the aggregated `allowed` verdict of
|
|
41
|
+
* every hook in this dispatch, internal ones included. A hook must not await
|
|
42
|
+
* it inside `execute` (that would wait on itself); chain work onto it instead.
|
|
43
|
+
*/
|
|
44
|
+
decision?: Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* FinalStop only: the interceptor gate stamped on the run result that reached
|
|
47
|
+
* FinalStop. Unlike `session.interceptorGate`, a later result cannot replace it.
|
|
48
|
+
*/
|
|
49
|
+
interceptorGate?: InterceptorGate;
|
|
50
|
+
}
|
|
51
|
+
/** Associate local attachment paths with an input item without mutating serializable message data. */
|
|
52
|
+
export declare function setInternalInputAttachmentPaths(item: AgentInputItem, paths: readonly string[]): void;
|
|
53
|
+
/** Read process-local attachment paths associated with an input item. */
|
|
54
|
+
export declare function getInternalInputAttachmentPaths(item: unknown): readonly string[];
|
|
55
|
+
/** Carry attachment paths onto a clone or merge of input items; WeakMap entries do not survive copying. */
|
|
56
|
+
export declare function copyInternalInputAttachmentPaths(from: readonly unknown[], to: AgentInputItem): void;
|
|
57
|
+
/**
|
|
58
|
+
* Optional in-process service that keeps a private copy of a local input
|
|
59
|
+
* attachment the host deletes right after submission (TUI paste cleanup).
|
|
60
|
+
* `data` is the file content the host already read, so the copy needs no second read.
|
|
61
|
+
* Returns the copy's path, or undefined to keep the original path.
|
|
62
|
+
*/
|
|
63
|
+
export declare const InputAttachmentRetainer: unique symbol;
|
|
64
|
+
export interface InputAttachmentRetainer {
|
|
65
|
+
retain(filePath: string, data?: Uint8Array): Promise<string | undefined>;
|
|
66
|
+
}
|
|
67
|
+
export interface InputAttachmentSource {
|
|
68
|
+
path: string;
|
|
69
|
+
/** Content the host already read from `path`, if any. */
|
|
70
|
+
data?: Uint8Array;
|
|
71
|
+
}
|
|
72
|
+
/** Like {@link setInternalInputAttachmentPaths}, but lets a registered retainer copy the files first. */
|
|
73
|
+
export declare function retainInternalInputAttachmentPaths(item: AgentInputItem, attachments: readonly InputAttachmentSource[]): Promise<void>;
|
|
74
|
+
export interface Hook {
|
|
75
|
+
/**
|
|
76
|
+
* Hook event type this hook responds to
|
|
77
|
+
*/
|
|
78
|
+
readonly event: HookEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Priority for execution order (lower = earlier)
|
|
81
|
+
*/
|
|
82
|
+
readonly priority: number;
|
|
83
|
+
/**
|
|
84
|
+
* Optional matcher pattern (regex) for filtering
|
|
85
|
+
* - PreToolUse/PostToolUse: matches tool_name
|
|
86
|
+
* - SessionStart: matches source
|
|
87
|
+
* - SessionEnd: matches reason
|
|
88
|
+
* - Other events: not used
|
|
89
|
+
*/
|
|
90
|
+
readonly matcher?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Execute the hook logic
|
|
93
|
+
*
|
|
94
|
+
* @param input - Serializable hook input data
|
|
95
|
+
* @param context - Optional process-local data available only to internal hooks
|
|
96
|
+
* @returns HookExecutionResult or undefined to skip
|
|
97
|
+
*/
|
|
98
|
+
execute(input: HookInput, context?: InternalHookContext): Promise<HookExecutionResult | undefined>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Priority levels for internal hooks
|
|
102
|
+
* Lower values execute first
|
|
103
|
+
*/
|
|
104
|
+
export declare enum HookPriority {
|
|
105
|
+
/** Highest priority - runs first */
|
|
106
|
+
Highest = 0,
|
|
107
|
+
/** High priority */
|
|
108
|
+
High = 100,
|
|
109
|
+
/** Structured output processing */
|
|
110
|
+
StructuredOutput = 200,
|
|
111
|
+
/** Normal priority - default */
|
|
112
|
+
Normal = 500,
|
|
113
|
+
/** Low priority */
|
|
114
|
+
Low = 800,
|
|
115
|
+
/** Lowest priority - runs last */
|
|
116
|
+
Lowest = 1000
|
|
117
|
+
}
|
|
3
118
|
export interface HookInput {
|
|
4
119
|
/**
|
|
5
120
|
* Session identifier
|
|
@@ -312,6 +427,6 @@ export interface HookInput {
|
|
|
312
427
|
}
|
|
313
428
|
export declare const CoreHookExecutor: unique symbol;
|
|
314
429
|
export interface CoreHookExecutor {
|
|
315
|
-
executeHooks(event: HookEvent, input: HookInput, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
430
|
+
executeHooks(event: HookEvent, input: HookInput, options?: HookExecutionOptions, internalContext?: InternalHookContext): Promise<HookExecutionResult>;
|
|
316
431
|
hasHooks(event: HookEvent, toolName?: string): Promise<boolean>;
|
|
317
432
|
}
|
|
@@ -7,6 +7,7 @@ export * from './prompt-mid-turn-buffer.js';
|
|
|
7
7
|
export * from './rich-queue-manager-protocol.js';
|
|
8
8
|
export * from './rich-queue-manager.js';
|
|
9
9
|
export * from './steer-input-buffer-protocol.js';
|
|
10
|
+
export * from './steer-model-input-preparer-protocol.js';
|
|
10
11
|
export * from './steer-input-buffer.js';
|
|
11
12
|
export * from './followup-queue-protocol.js';
|
|
12
13
|
export * from './followup-queue.js';
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/injectable-content.d.ts
CHANGED
|
@@ -4,13 +4,11 @@ import type { SteerDrainedGroup } from './steer-input-buffer-protocol.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* 待插入内容的文本抽取与可注入性判定(#85193)。
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* - `
|
|
9
|
-
*
|
|
7
|
+
* - `isInjectableContent`:只承载文本的 mid-turn 注入(acp-view 后台 drain 轮)。
|
|
8
|
+
* - `isSteerableContent`:steer 入口(ACP `session/steer` / `send_followup_now`)。steer 与普通 prompt
|
|
9
|
+
* 使用同一套用户输入转换,图片随消息进入模型(#140576),因此有文本**或有图片**即可。
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* Server 的完整 user message 入口单独完成入队校验,保留图片与文件内容。
|
|
13
|
-
* 兼容 `<channel>` 包裹(channel 消息里的斜杠命令同样识别)。
|
|
11
|
+
* 两者都拒绝斜杠命令,兼容 `<channel>` 包裹(channel 消息里的斜杠命令同样识别)。
|
|
14
12
|
*/
|
|
15
13
|
/** 把一组 contentBlock 里的文本抽出并用换行拼接(string 块与 {type:'text'} 块都算,非文本块忽略)。 */
|
|
16
14
|
export declare function contentBlocksToText(contentBlocks: unknown[]): string;
|
|
@@ -18,20 +16,19 @@ export declare function contentBlocksToText(contentBlocks: unknown[]): string;
|
|
|
18
16
|
export declare function isSlashCommandText(text: string): boolean;
|
|
19
17
|
/** 一组 contentBlocks 是否可作为普通文本注入(有文本且非斜杠命令)。 */
|
|
20
18
|
export declare function isInjectableContent(contentBlocks: unknown[]): boolean;
|
|
19
|
+
/** 一组 ACP contentBlocks 是否可 steer 进当前一轮:非斜杠命令,且有文本或有图片。 */
|
|
20
|
+
export declare function isSteerableContent(contentBlocks: unknown[]): boolean;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* 可注入的组合并进同一个 reminder(多条按顺序保留、`\n\n` 分隔)。全部不可注入返回 undefined。
|
|
22
|
+
* 把若干组已准入的 steer 消息拼成模型输入 + 历史项 + 实时回执(#87145 / #95921 / #140576)。
|
|
24
23
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* - **实时事件 `emitInfos`**(#95921 Phase 2):仅带 `clientUserMessageId` 的组产出一条;
|
|
34
|
-
* 该 id 控制注入完成后的 pending 对账,`clientMeta` 只作为独立的不透明 metadata 随事件携带。
|
|
24
|
+
* 每组的 `messages` 与普通 prompt 一样是完整 user message(可含 `input_image`),本函数只做
|
|
25
|
+
* steer 独有的三件事,不再改写内容:
|
|
26
|
+
* - **注入项 `items`**(喂模型):每条消息原样放进 `<system-reminder data-role="message-queue">`
|
|
27
|
+
* 包装(包装文本在内容前后各一个 input_text),图片随之进入模型。
|
|
28
|
+
* - **历史项 `historyItems`**(落盘):消息对象本身(按引用,保留准入标记)。带 `clientUserMessageId`
|
|
29
|
+
* 的单消息组把它落为 item.id,保证 CLI 回放的 `user_message_chunk.messageId` 与实时回执一致;
|
|
30
|
+
* 带 `clientMeta` 时原样挂进 `providerData.clientMeta`(CLI 不解读,WorkBuddy 据此识别 steer)。
|
|
31
|
+
* - **实时回执 `emitInfos`**:仅带 `clientUserMessageId` 的组产出一条,`clientMeta` 随事件携带。
|
|
35
32
|
*/
|
|
36
33
|
export declare function buildSteerInjectionInput(groups: readonly SteerDrainedGroup[]): {
|
|
37
34
|
items: AgentInputItem[];
|
|
@@ -32,9 +32,11 @@ export type SteerInputDisposition = 'consumed' | 'cancelled' | 'discarded';
|
|
|
32
32
|
export interface SteerDrainedGroup {
|
|
33
33
|
/** Set only after the host validates a one-time mod prompt receipt. */
|
|
34
34
|
readonly modsPromptSubmitted?: true;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* 待插入的用户消息,与普通 prompt 同构(可含 `input_image`,#140576)。
|
|
37
|
+
* 按引用保留,内存中的准入标记(WeakMap)随对象传递。
|
|
38
|
+
*/
|
|
39
|
+
readonly messages: readonly UserMessageItem[];
|
|
38
40
|
/**
|
|
39
41
|
* 客户端为本条用户消息提供的不透明对账 id。存在时,CLI 在真正注入后原样回贴;
|
|
40
42
|
* 同时落为历史 user item.id,保证回放身份一致;不存在时不产生实时回执。
|
|
@@ -50,7 +52,7 @@ export interface SteerDrainedGroup {
|
|
|
50
52
|
readonly clientMeta?: unknown;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
55
|
+
* pushMessages 的归属 + 客户端不透明 metadata 入参(合并为一个对象,避免参数过多)。
|
|
54
56
|
*/
|
|
55
57
|
export interface SteerPushInput {
|
|
56
58
|
/** Server-only provenance, independent of untrusted clientMeta. */
|
|
@@ -72,16 +74,13 @@ export interface SteerPushInput {
|
|
|
72
74
|
}
|
|
73
75
|
export interface SteerInputBuffer {
|
|
74
76
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* Transfer reviewed native messages. Aborting withdraws only this submission while buffered.
|
|
81
|
-
* Drain and cancellation are synchronous, so exactly one wins. Once consumed, cancellation
|
|
82
|
-
* cannot retract the input. Clear or a stale owner discards it. The promise never rejects.
|
|
77
|
+
* 暂存一组待插入的用户消息(一次 steer 一组)。同一次请求执行里可被调用多次(用户连发多条)。
|
|
78
|
+
* 转移所有权:调用方必须先 clone / 审查,交出后不得再修改。
|
|
79
|
+
* Aborting withdraws only this submission while buffered. Drain and cancellation are
|
|
80
|
+
* synchronous, so exactly one wins. Once consumed, cancellation cannot retract the input.
|
|
81
|
+
* Clear or a stale owner discards it. The consumption promise never rejects.
|
|
83
82
|
*/
|
|
84
|
-
pushMessages(sessionId: string, messages: readonly UserMessageItem[],
|
|
83
|
+
pushMessages(sessionId: string, messages: readonly UserMessageItem[], input: SteerPushInput, signal?: AbortSignal): Promise<SteerInputDisposition>;
|
|
85
84
|
/**
|
|
86
85
|
* 取出并清空当前会话的全部待插入消息(取出即视为已消费)。
|
|
87
86
|
* 只返回归属 `currentRequestId` 的消息;归属其它请求的陈旧残留一并丢弃、不注入。
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/steer-input-buffer.d.ts
CHANGED
|
@@ -9,9 +9,8 @@ import { type SteerDrainedGroup, type SteerInputBuffer, type SteerInputDispositi
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class SteerInputBufferImpl implements SteerInputBuffer {
|
|
11
11
|
private readonly store;
|
|
12
|
-
|
|
12
|
+
pushMessages(sessionId: string, messages: readonly UserMessageItem[], input: SteerPushInput, signal?: AbortSignal): Promise<SteerInputDisposition>;
|
|
13
13
|
drain(sessionId: string, currentRequestId: string | undefined): SteerDrainedGroup[];
|
|
14
|
-
pushMessages(sessionId: string, messages: readonly UserMessageItem[], ownerRequestId: string, signal?: AbortSignal): Promise<SteerInputDisposition>;
|
|
15
14
|
has(sessionId: string, currentRequestId: string | undefined): boolean;
|
|
16
15
|
clear(sessionId: string): void;
|
|
17
16
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AgentInputItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
|
+
import type { Session } from '../session/session-protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* steer 插入点对**模型输入副本**的加工(#140576),由宿主(agent-cli)实现。
|
|
5
|
+
*
|
|
6
|
+
* 普通 prompt 在 run 起点由图片压缩 / 模型能力过滤拦截器处理,且只改发给模型的副本、历史保留原图;
|
|
7
|
+
* steer 在 run 中途进入 RunState,不经过这些拦截器,因此在插入点用同一份实现处理,语义保持一致。
|
|
8
|
+
*/
|
|
9
|
+
export declare const SteerModelInputPreparer: unique symbol;
|
|
10
|
+
export interface SteerModelInputPreparer {
|
|
11
|
+
/** 就地加工模型输入副本:按当前模型能力过滤图片、压缩超限图片。不得修改历史项。 */
|
|
12
|
+
prepare(session: Session, items: AgentInputItem[]): Promise<void>;
|
|
13
|
+
}
|
|
@@ -448,6 +448,17 @@ export declare class InterruptionServiceImpl implements InterruptionService {
|
|
|
448
448
|
* 此时不退回额度——新请求边界已经清零,再减一次会扣掉新链的额度。
|
|
449
449
|
*/
|
|
450
450
|
private prepareRecoveryAttempt;
|
|
451
|
+
/**
|
|
452
|
+
* reasoning-only 空流的续写前置:把模型层随错误交出的思考落史,续写请求才带得上它,
|
|
453
|
+
* 模型可以接着已有思考往下写,而不是从头审题。
|
|
454
|
+
*
|
|
455
|
+
* 只在重试已经确定发起时调用:不重试(预算耗尽、跑满上游时限、退避期间取消)时历史保持原样。
|
|
456
|
+
* 返回 `false` 时调用方退回原样重发——没有思考可接,就不能让提示说「从中断处继续」。
|
|
457
|
+
*
|
|
458
|
+
* 落史形状与 AbortedStreamDraftStore 的中途取消半成品一致(status=incomplete +
|
|
459
|
+
* isPartialAborted);发请求时由 attachOrphanedReasoningCarriers 补承载项回传给模型。
|
|
460
|
+
*/
|
|
461
|
+
private persistEmptyStreamReasoning;
|
|
451
462
|
/**
|
|
452
463
|
* CLI TUI 手打 `/compact` 裸跑成功后补发 SessionStart('compact')。
|
|
453
464
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AgentInputItem, FinalStopReason, NotificationType, RunResult, SessionEndReason, SessionStartSource, StreamedRunResult } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
2
|
import { Logger } from '../../../../telemetry/lib/common/index.js';
|
|
3
|
-
import { CoreHookExecutor as HookManager } from '../hooks/hook-protocol.js';
|
|
3
|
+
import { CoreHookExecutor as HookManager, type InternalHookContext } from '../hooks/hook-protocol.js';
|
|
4
4
|
import { SessionHookHost } from './session-hook-host-protocol.js';
|
|
5
5
|
import { Session, SessionHookManager, SessionStore } from './session-protocol.js';
|
|
6
6
|
/**
|
|
@@ -207,7 +207,7 @@ export declare class SessionHookManagerImpl implements SessionHookManager {
|
|
|
207
207
|
* final terminal state and will not continue via the current Stop hook.
|
|
208
208
|
* Does NOT support continueRequest.
|
|
209
209
|
*/
|
|
210
|
-
executeFinalStopHooks(session: Session, reason?: FinalStopReason): Promise<void>;
|
|
210
|
+
executeFinalStopHooks(session: Session, reason?: FinalStopReason, internalContext?: Pick<InternalHookContext, 'interceptorGate'>): Promise<void>;
|
|
211
211
|
/**
|
|
212
212
|
* UserPromptExpansion — Claude Code 官方事件:任何用户输入的命令/skill 展开成
|
|
213
213
|
* prompt、送进模型之前统一从这里触发,可阻断展开。`command_args` / `prompt` 按
|
|
@@ -176,6 +176,15 @@ export declare class SessionManagerImpl implements SessionManager, ApplicationLi
|
|
|
176
176
|
initRunResultHandler(session: Session): void;
|
|
177
177
|
protected handleRunResult(session: Session): Promise<void>;
|
|
178
178
|
protected handleStreamRunResult(session: Session, result: StreamedRunResult<any, any>, modelResponseMetadata: ModelResponseMetadata): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Issue #65246:把 API 实际响应的物理模型 id 存到 session.meta,
|
|
181
|
+
* 供 ACP injectMeta 透传给前端,用于 auto 模式展示「推荐模型(xxx)」。
|
|
182
|
+
*/
|
|
183
|
+
private recordResponseModel;
|
|
184
|
+
/**
|
|
185
|
+
* 记录一次模型响应的 finish_reason(Chat Completions 的 choice 与 Responses API 终态事件共用)。
|
|
186
|
+
*/
|
|
187
|
+
private recordModelFinishReason;
|
|
179
188
|
/**
|
|
180
189
|
* content_filter 安全审查终止处理。
|
|
181
190
|
*
|
|
@@ -3,6 +3,7 @@ import { type AgentInputItem, ApprovalOptions, type Checkpoint, FinalStopReason,
|
|
|
3
3
|
import { Command } from '../../../../product/lib/common/index.js';
|
|
4
4
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
5
5
|
import type { CompactionLineage } from '../context/compaction-lineage.js';
|
|
6
|
+
import type { InternalHookContext } from '../hooks/hook-protocol.js';
|
|
6
7
|
import { BackgroundTask } from './background-task-protocol.js';
|
|
7
8
|
import type { SessionRunStateSnapshot } from './session-run-state-machine-protocol.js';
|
|
8
9
|
import type { Lane, LanePointer, SessionKey, SessionStoreEntry } from './session-store-contract.js';
|
|
@@ -516,6 +517,11 @@ export interface Session {
|
|
|
516
517
|
telemetryClientInfo?: TelemetryClientInfo;
|
|
517
518
|
/** Root span for current conversation request, used to extract B3 trace headers */
|
|
518
519
|
conversationRequestRootSpan?: import('../../../../telemetry/lib/common/index.js').Span;
|
|
520
|
+
/**
|
|
521
|
+
* 释放 tracing 重初始化闸门(见 trace/trace-reinit-gate.ts)。TraceStartHook 建
|
|
522
|
+
* root span 时置入,TraceStopHook / 强制收尾旧 root 时调用一次(幂等)。genie#113158。
|
|
523
|
+
*/
|
|
524
|
+
_traceTurnRelease?: () => void;
|
|
519
525
|
messageId?: string;
|
|
520
526
|
/**
|
|
521
527
|
* @deprecated Hooks 的 `generation_id` 现直接取 `conversationRequestId`(Request ID),
|
|
@@ -1239,7 +1245,8 @@ export interface SessionManager {
|
|
|
1239
1245
|
* 拦截器/ModelUtils 的权威优先级是 requestOptions.model > options.model > agent 默认;
|
|
1240
1246
|
* --model 启动参数固化在 options.model,仅写 settings/cli 无法覆盖它。override map
|
|
1241
1247
|
* 供 applyOverrideModel 每轮重建 requestOptions(Issue #82146)。/model 命令与模型面板
|
|
1242
|
-
* 共用此入口;ACP set_model
|
|
1248
|
+
* 共用此入口;ACP set_model 经 applyRuntimeSessionModel 调用。
|
|
1249
|
+
* 切换前模型不在这里记录,压缩路径从会话历史里最近一次用量推导。
|
|
1243
1250
|
*/
|
|
1244
1251
|
setRuntimeModel(session: Session | undefined, modelId: string, source?: OverrideModelSource): void;
|
|
1245
1252
|
/**
|
|
@@ -1476,7 +1483,7 @@ export interface SessionHookManager {
|
|
|
1476
1483
|
* final terminal state and will not continue via the current Stop hook.
|
|
1477
1484
|
* Does NOT support continueRequest.
|
|
1478
1485
|
*/
|
|
1479
|
-
executeFinalStopHooks(session: Session, reason?: FinalStopReason): Promise<void>;
|
|
1486
|
+
executeFinalStopHooks(session: Session, reason?: FinalStopReason, internalContext?: Pick<InternalHookContext, 'interceptorGate'>): Promise<void>;
|
|
1480
1487
|
/**
|
|
1481
1488
|
* UserPromptExpansion — Claude Code 官方事件(非 cbc 专属扩展):任何用户输入的
|
|
1482
1489
|
* 命令/skill 在展开成 prompt、送进模型之前统一从这里触发,可阻断展开。适用于
|
|
@@ -61,12 +61,13 @@ export declare const SESSION_TITLE_META_KEY = "codebuddy.ai/sessionTitle";
|
|
|
61
61
|
* never lands on disk. Literals kept in sync with MAIN_AGENT_META_KEY /
|
|
62
62
|
* MAIN_AGENT_HOST_KIND_KEY (agent/main-agent-session.ts, #97166) and
|
|
63
63
|
* MULTITASK_MODE_META_KEY (multitask overlay) and A2A_CONTEXTS_META_KEY
|
|
64
|
-
* (a2a/a2a-context-store.ts), plus SESSION_TITLE_META_KEY above (#138181)
|
|
64
|
+
* (a2a/a2a-context-store.ts), plus SESSION_TITLE_META_KEY above (#138181) and
|
|
65
|
+
* PRIVATE_DATA_STICKY_META_KEY above (#127752).
|
|
65
66
|
* The spec asserts the sync. Growing this list is a review decision, not a
|
|
66
67
|
* side effect of putting a key on session.meta.
|
|
67
68
|
* Role / locks / parentSessionId stay runtime-only.
|
|
68
69
|
*/
|
|
69
|
-
export declare const PERSISTED_SESSION_META_KEYS: readonly ['codebuddy.ai/mainAgent', 'codebuddy.ai/hostKind', 'multitaskMode', 'codebuddy.ai/a2aContexts', "codebuddy.ai/sessionTitle"];
|
|
70
|
+
export declare const PERSISTED_SESSION_META_KEYS: readonly ['codebuddy.ai/mainAgent', 'codebuddy.ai/hostKind', 'multitaskMode', 'codebuddy.ai/a2aContexts', "codebuddy.ai/sessionTitle", "codebuddy.ai/privateDataSticky"];
|
|
70
71
|
/**
|
|
71
72
|
* Meta a fork inherits from its source: the persisted whitelist minus title
|
|
72
73
|
* facts, which describe the source conversation and must not label the child
|
|
@@ -481,7 +482,6 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
481
482
|
*/
|
|
482
483
|
private deserializeForkSubagentSession;
|
|
483
484
|
private assertForkGraphAcyclic;
|
|
484
|
-
private assertForkChildSupported;
|
|
485
485
|
private resolveForkChildPrefixEnd;
|
|
486
486
|
private readForkRuntimeSessionId;
|
|
487
487
|
private assertForkChildMetaLineage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Session } from '../session/session-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* 归还本轮 turn 持有的 tracing 重初始化闸门(genie#113158)。
|
|
4
|
+
*
|
|
5
|
+
* 闸门计数只能由持有 release 的那一轮归还,且 session 上只存一个 release 槽位。
|
|
6
|
+
* 因此**每一个结束本轮 root span 的出口**都必须调用本函数:正常 Stop、PTL 无
|
|
7
|
+
* 续跑的兜底清理、下一轮开始时对残留 root span 的强制收尾。任一出口漏掉,
|
|
8
|
+
* 下一轮的 markTraceTurnOpen 就会覆盖掉未归还的 release,计数从此单调递增、
|
|
9
|
+
* 永不归零——后续 re-init 被无限推迟,auth/product 配置变更再也不生效。
|
|
10
|
+
*
|
|
11
|
+
* release 自身幂等,重复调用安全。
|
|
12
|
+
*/
|
|
13
|
+
export declare function releaseTraceTurnGate(session: Session): void;
|
|
@@ -2,6 +2,8 @@ export interface ErrorInfo {
|
|
|
2
2
|
status?: number;
|
|
3
3
|
code?: number;
|
|
4
4
|
message?: string;
|
|
5
|
+
/** 会话层是否会自动重试本次错误;未知时按会重试处理,沿用流超时文案的既有口径。 */
|
|
6
|
+
isRetryable?: boolean;
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
9
|
* 后端业务错误码枚举
|
|
@@ -157,6 +159,11 @@ export declare namespace ErrorUtils {
|
|
|
157
159
|
* 避免 acp-agent 分类时静默退化为通用 "Network error" 文案。对齐 isStreamTimeoutError 风格。
|
|
158
160
|
*/
|
|
159
161
|
function isEmptyStreamError(error: unknown): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* 空流里已经流出过思考、但没有正文或工具调用就 `finish_reason=error`。
|
|
164
|
+
* 只认 instanceof:与 `isRetryableEmptyStreamError` 同口径,丢了 prototype 的空流本就不会被重试。
|
|
165
|
+
*/
|
|
166
|
+
function isReasoningOnlyEmptyStreamError(error: unknown): boolean;
|
|
160
167
|
/**
|
|
161
168
|
* 将错误信息序列化为 JSON 字符串,用于 ACP 协议传输
|
|
162
169
|
* ACP SDK 会尝试解析这个 JSON 字符串并将其放到 error.data 中
|
|
@@ -3,6 +3,7 @@ export * from '../session-title/session-title-utils.js';
|
|
|
3
3
|
export * from './command-message-utils.js';
|
|
4
4
|
export * from './content-block-sanitizer.js';
|
|
5
5
|
export * from './conversation-request-id.js';
|
|
6
|
+
export * from './markdown-code-utils.js';
|
|
6
7
|
export * from './error-message-host-protocol.js';
|
|
7
8
|
export * from './error-utils.js';
|
|
8
9
|
export * from './failure-classifier.js';
|
|
@@ -20,6 +21,7 @@ export * from './message-utils.js';
|
|
|
20
21
|
export * from './model-utils.js';
|
|
21
22
|
export * from './number-utils.js';
|
|
22
23
|
export * from './queue-dispatch-utils.js';
|
|
24
|
+
export * from './responses-api-utils.js';
|
|
23
25
|
export * from './run-result-utils.js';
|
|
24
26
|
export * from './session-utils.js';
|
|
25
27
|
export * from './summary-utils.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown code-span detection shared by `@path` reference scanners
|
|
3
|
+
* (agent-cli `ImportUtils` and resource reporting), so both agree on which
|
|
4
|
+
* mentions are real references.
|
|
5
|
+
*
|
|
6
|
+
* Rule: a position is inside code when an odd number of ``` fences, or of lone
|
|
7
|
+
* ` ticks (not part of a ``` run), precedes it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isInMarkdownCode(text: string, position: number): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Same rule as {@link isInMarkdownCode}, with the counts accumulated in one
|
|
12
|
+
* forward pass. Query positions in ascending order; a text with many mentions
|
|
13
|
+
* is then scanned once instead of once per mention.
|
|
14
|
+
*/
|
|
15
|
+
export declare function markdownCodeTester(text: string): (position: number) => boolean;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type AgentInputItem, type UserMessageItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
2
|
export declare abstract class MessageContentUtils {
|
|
3
|
+
/** 用户消息是否携带图片/文件附件块(无文本的纯附件提问也算用户输入)。 */
|
|
4
|
+
static hasAttachmentContent(item: UserMessageItem): boolean;
|
|
3
5
|
/**
|
|
4
6
|
* 检查用户消息是否有可见的内容
|
|
5
7
|
*/
|
|
@@ -18,7 +20,7 @@ export declare abstract class MessageContentUtils {
|
|
|
18
20
|
/** 移除文本中的 system-reminder 标签及其内容 */
|
|
19
21
|
private static stripSystemReminder;
|
|
20
22
|
/** 检测 input_text 块是否为 image_local_path 标记 */
|
|
21
|
-
|
|
23
|
+
static isImageLocalPathBlock(text: string | undefined): boolean;
|
|
22
24
|
/**
|
|
23
25
|
* 将 <teammate-message> 标签替换为友好的摘要文本
|
|
24
26
|
* 优先使用 summary 属性,否则提取标签内容
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat-completions-style finish reason of a terminal OpenAI Responses API stream event
|
|
3
|
+
* (`response.completed` / `response.incomplete` / `response.failed` / `error`);
|
|
4
|
+
* `undefined` for every other event.
|
|
5
|
+
*/
|
|
6
|
+
export declare function responsesFinishReason(event: unknown): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* The terminal Responses event behind an SDK `response_done` event: the SDK keeps the event
|
|
9
|
+
* type in `providerData` and the rest of the response (status, model, incomplete_details) in
|
|
10
|
+
* `response.providerData`. `undefined` for chat-completions responses.
|
|
11
|
+
*/
|
|
12
|
+
export declare function responsesTerminalEventOf(done: {
|
|
13
|
+
providerData?: Record<string, any>;
|
|
14
|
+
response?: {
|
|
15
|
+
output?: unknown;
|
|
16
|
+
providerData?: Record<string, any>;
|
|
17
|
+
};
|
|
18
|
+
}): {
|
|
19
|
+
type: string;
|
|
20
|
+
response: Record<string, any>;
|
|
21
|
+
} | undefined;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { AgentInputItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
2
|
import type { Session } from '../session/session-protocol.js';
|
|
3
3
|
export declare const ENV_KEY_CODEBUDDY_TASK_LIST_ID = "CODEBUDDY_TASK_LIST_ID";
|
|
4
|
+
/**
|
|
5
|
+
* Runtime meta on a session that runs on behalf of another one (one-off helper runs, `/btw`,
|
|
6
|
+
* subagents): the owner's {@link SessionUtils.resolveRootSessionId}.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ROOT_SESSION_META_KEY = "codebuddy.ai/rootSessionId";
|
|
4
9
|
export declare abstract class SessionUtils {
|
|
5
10
|
static is(session?: any): session is Session;
|
|
6
11
|
/**
|
|
@@ -60,6 +65,21 @@ export declare abstract class SessionUtils {
|
|
|
60
65
|
};
|
|
61
66
|
id?: string;
|
|
62
67
|
} | undefined, teamName?: string): string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Root of a session's lineage: the id behind `${CODEBUDDY_SESSION_ID}` in model credentials,
|
|
70
|
+
* which aihub uses as `cache_task_id` to pin every call of a task to one upstream account.
|
|
71
|
+
* A history replaying Responses items keeps the root they were produced under
|
|
72
|
+
* (`providerData.upstream.rootSessionId`), so forks stay on the account that can decrypt
|
|
73
|
+
* the replayed reasoning. Unlike {@link resolveTaskSessionId}, which picks task-list storage.
|
|
74
|
+
*/
|
|
75
|
+
static resolveRootSessionId(session: {
|
|
76
|
+
id: string;
|
|
77
|
+
history?: readonly unknown[];
|
|
78
|
+
meta?: Record<string, unknown>;
|
|
79
|
+
}): string;
|
|
80
|
+
/** Marks `session` as running on behalf of `owner`, sharing its lineage root. */
|
|
81
|
+
static adoptRootSession(session: Session, owner: Session | undefined): void;
|
|
82
|
+
private static replayedRootSessionId;
|
|
63
83
|
static resolveTaskSessionId(session?: {
|
|
64
84
|
meta?: {
|
|
65
85
|
parentSessionId?: string;
|
|
@@ -7,6 +7,11 @@ export interface LatestUsageSnapshot {
|
|
|
7
7
|
rawUsage: unknown;
|
|
8
8
|
/** Completion time of the history item carrying this usage. */
|
|
9
9
|
timestamp?: number;
|
|
10
|
+
/**
|
|
11
|
+
* 这条用量对应的执行模型。优先 requestModelId(用户选中的模型),
|
|
12
|
+
* 没有时回退到响应里的 model。Auto 路由下两者可能不同。
|
|
13
|
+
*/
|
|
14
|
+
model?: string;
|
|
10
15
|
}
|
|
11
16
|
export declare abstract class UsageUtils {
|
|
12
17
|
/** Normalize persisted records and per-response stream usage for SDK aggregation. */
|
|
@@ -22,6 +27,19 @@ export declare abstract class UsageUtils {
|
|
|
22
27
|
* cache fields and response timestamp.
|
|
23
28
|
*/
|
|
24
29
|
static getLatestUsageSnapshot(session: Session): LatestUsageSnapshot | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* 最近一个压缩边界之后,最后一条带 usage 的消息上的执行模型。
|
|
32
|
+
* 和 currentModelId 相同、或边界之后没有用量时返回 undefined。
|
|
33
|
+
*
|
|
34
|
+
* 压缩边界之前的用量不算:压缩完成后旧模型自动失效,不必再清一份内存记录。
|
|
35
|
+
* A→B→C 且 B 没跑过时,最后一条用量仍是 A。
|
|
36
|
+
*/
|
|
37
|
+
static resolvePreSwitchModelId(session: {
|
|
38
|
+
history?: AgentInputItem[];
|
|
39
|
+
}, currentModelId: string | undefined): string | undefined;
|
|
40
|
+
private static findLatestUsageSnapshot;
|
|
41
|
+
/** 用户选中的模型优先于响应里的实际路由模型。 */
|
|
42
|
+
private static readExecutedModelId;
|
|
25
43
|
static getTotalUsage(items: AgentInputItem[]): Usage;
|
|
26
44
|
/**
|
|
27
45
|
* 从单个 item 的 rawUsage/usage 提取 cache_read_input_tokens(命中缓存的输入 token)。
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { ServerAware } from '@celljs/web/lib/node';
|
|
9
9
|
import type { Server } from 'http';
|
|
10
|
-
import { type DaemonConfig, type IDaemonAutoRestart } from './daemon-protocol.js';
|
|
10
|
+
import { type DaemonConfig, type DaemonRestartNowResult, type IDaemonAutoRestart } from './daemon-protocol.js';
|
|
11
11
|
export declare class DaemonAutoRestartImpl implements IDaemonAutoRestart, ServerAware {
|
|
12
12
|
private readonly logger;
|
|
13
13
|
private readonly registry;
|
|
@@ -34,7 +34,7 @@ export declare class DaemonAutoRestartImpl implements IDaemonAutoRestart, Server
|
|
|
34
34
|
* 入口(覆盖 auto-update idle 路径与本路径的交叉竞态);这里的检查只是
|
|
35
35
|
* 提前挡掉明显重复的调用。
|
|
36
36
|
*/
|
|
37
|
-
restartNow(config?: Partial<DaemonConfig>):
|
|
37
|
+
restartNow(config?: Partial<DaemonConfig>): DaemonRestartNowResult;
|
|
38
38
|
private startIdleCheck;
|
|
39
39
|
private clearIdleCheck;
|
|
40
40
|
/**
|
|
@@ -289,8 +289,24 @@ export interface IDaemonAutoRestart {
|
|
|
289
289
|
* issue #72979):本进程不能 stop() 自己(sendSignal 的自身 PID 守卫,#73790),
|
|
290
290
|
* 必须先让当前 HTTP 响应发出,再在后台完成换进程。
|
|
291
291
|
* config 为显式覆盖项(port/host/startupArgs),未提供的字段从 PID 文件快照恢复。
|
|
292
|
+
* 返回是否已受理:被安全拒绝(如旧式 systemd unit)时 started=false 并带原因。
|
|
292
293
|
*/
|
|
293
|
-
restartNow(config?: Partial<DaemonConfig>):
|
|
294
|
+
restartNow(config?: Partial<DaemonConfig>): DaemonRestartNowResult;
|
|
295
|
+
}
|
|
296
|
+
/** restartNow 受理结果;in-flight 的重复调用视为已受理(重启已在进行)。 */
|
|
297
|
+
export type DaemonRestartNowResult = {
|
|
298
|
+
started: true;
|
|
299
|
+
} | {
|
|
300
|
+
started: false;
|
|
301
|
+
reason: DaemonRestartRefusedReason;
|
|
302
|
+
message: string;
|
|
303
|
+
};
|
|
304
|
+
export type DaemonRestartRefusedReason = 'legacy-systemd-unit';
|
|
305
|
+
/** daemon 自重启被安全拒绝;调用方可按 code 识别并映射为 409。 */
|
|
306
|
+
export declare class DaemonRestartRefusedError extends Error {
|
|
307
|
+
readonly reason: DaemonRestartRefusedReason;
|
|
308
|
+
readonly code = "DAEMON_RESTART_REFUSED";
|
|
309
|
+
constructor(reason: DaemonRestartRefusedReason, message: string);
|
|
294
310
|
}
|
|
295
311
|
/** Channel 自动连接与恢复 */
|
|
296
312
|
export interface IDaemonChannelAutoConnect {
|