@tencent-ai/agent-harness 0.2.0-beta.2 → 0.2.0-beta.3
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 +26 -2
- package/cli/CHANGELOG.md +64 -0
- package/cli/dist-server/shared.cjs +379 -315
- package/cli/dist-server/types/node/bash-sandbox/bash-sandbox-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/cli-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/stream-json-protocol.d.ts +8 -1
- package/cli/dist-server/types/node/sensitive-content/sensitive-content-protocol.d.ts +7 -0
- package/cli/dist-server/types/node/server/boot.d.ts +7 -4
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts +1 -1
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-protocol.d.ts +2 -3
- package/cli/dist-server/types/node/server/formats/acp/index.d.ts +12 -0
- package/cli/dist-server/types/node/server/formats/acp/projection.d.ts +10 -0
- package/cli/dist-server/types/node/server/index.d.ts +1 -1
- package/cli/dist-server/types/node/server/sessions.d.ts +3 -2
- package/cli/dist-server/types/node/server/types.d.ts +59 -7
- package/cli/dist-server/types/node/tools/tool-protocol.d.ts +16 -2
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +31 -2
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +26 -3
- package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +3 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +25 -9
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-pattern.d.ts +9 -8
- package/cli/dist-server/types/vendor/cbc-core/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +8 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-response-interceptors.d.ts +15 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +7 -3
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +47 -5
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-run-state-machine-protocol.d.ts +14 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/stream-timeout-retry-budget.d.ts +8 -1
- package/cli/dist-server/types/vendor/cbc-core/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/history-utils.d.ts +4 -4
- package/cli/dist-server/types/vendor/cbc-core/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +30 -2
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/sandbox-rule-context.d.ts +38 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/account-scoped-external-link-authentication-provider.d.ts +3 -3
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +6 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-observation.d.ts +36 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +21 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/external-link-authentication-provider.d.ts +20 -4
- package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-protocol.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-service.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +31 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +26 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +3 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +25 -9
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-pattern.d.ts +9 -8
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +8 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-response-interceptors.d.ts +15 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +7 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +47 -5
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-run-state-machine-protocol.d.ts +14 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts +8 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/history-utils.d.ts +4 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +30 -2
- package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-service.d.ts +5 -0
- package/cli/dist-server/types/workspace/core/lib/common/protocol.d.ts +8 -1
- package/cli/dist-server/types/workspace/product/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/product/lib/common/tencent-docs-endpoint.d.ts +37 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/config.d.ts +12 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +1 -9
- package/cli/dist-server/types/workspace/product/lib/common/types/product.d.ts +15 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/center-protocol.generated.d.ts +5 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/file-policy.d.ts +4 -1
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/http-policy.d.ts +20 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/rule-config.d.ts +10 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +3 -0
- package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +43 -3
- package/cli/package.json +1 -1
- package/cli/product.cloudhosted.json +4 -4
- package/cli/product.internal.json +11 -7
- package/cli/product.ioa.json +32 -24
- package/cli/product.json +45 -17
- package/cli/product.selfhosted.json +2 -2
- package/cli/vendor/shim/brokered-bin/7z +675 -0
- package/cli/vendor/shim/brokered-bin/7za +675 -0
- package/cli/vendor/shim/brokered-bin/7zz +675 -0
- package/cli/vendor/shim/brokered-bin/rar +675 -0
- package/cli/vendor/shim/brokered-bin/tar +675 -0
- package/cli/vendor/shim/brokered-bin/zip +187 -0
- package/docs/in-process.md +26 -2
- package/docs/protocol.md +7 -1
- package/docs/server.md +2 -0
- package/lib/agent/v2.js +1 -1
- package/lib/application/services.js +1 -1
- package/lib/client/client.js +1 -1
- package/lib/client/mcp.d.ts +1 -1
- package/lib/client/mcp.js +1 -1
- package/lib/components/acp-mcp-transport.d.mts +84 -1
- package/lib/components/question-elicitation.d.mts +20 -1
- package/lib/components/{acp/acp-prompt-input.d.ts → session/prompt-input.d.ts} +1 -1
- package/lib/components/session-replay.d.mts +6 -7
- package/lib/components/session-replay.mjs +1 -1
- package/lib/effect-runtime/mcp-lifecycle.mjs +1 -1
- package/lib/harness/create-harness.js +1 -1
- package/lib/integration/agent-integration.d.ts +5 -0
- package/lib/runtime/private-runtime-role.js +1 -1
- package/lib/session/agent-backend.d.ts +3 -0
- package/lib/session/agent-backend.js +1 -1
- package/lib/session/config-defaults.d.ts +4 -0
- package/lib/session/config-defaults.js +1 -0
- package/lib/session/config-store.d.ts +1 -1
- package/lib/session/config-store.js +1 -1
- package/lib/session/replay.d.ts +2 -2
- package/lib/session/replay.js +1 -1
- package/lib/session/server-config.d.ts +11 -2
- package/lib/session/server-config.js +1 -1
- package/lib/session/server-events.d.ts +10 -8
- package/lib/session/server-events.js +1 -1
- package/lib/session/server-mcp.js +1 -1
- package/package.json +20 -19
- package/lib/components/acp/acp-client-channel.d.ts +0 -36
- package/lib/components/acp/acp-mcp-transport.d.ts +0 -84
- package/lib/components/acp/acp-question-elicitation.d.ts +0 -20
|
@@ -33,6 +33,7 @@ export declare function resolveProgramBlacklistForPlatform(configuredPrograms: r
|
|
|
33
33
|
* Bash 沙箱配置接口
|
|
34
34
|
* 基于 SandboxRuntimeConfig,添加了额外的 CLI 特定配置
|
|
35
35
|
*/
|
|
36
|
+
export type MacOSUnlinkPolicy = 'allow' | 'ask' | 'deny';
|
|
36
37
|
export interface SandboxConfig {
|
|
37
38
|
/** 是否启用沙箱 */
|
|
38
39
|
enabled?: boolean;
|
|
@@ -98,6 +99,8 @@ export interface SandboxConfig {
|
|
|
98
99
|
systemToolPolicy?: SystemToolPolicy;
|
|
99
100
|
/** 实验功能:工作空间内文件版本管理 */
|
|
100
101
|
versionControl?: boolean;
|
|
102
|
+
/** macOS 非白名单直接 unlink 的自动兜底动作;历史缺省为 ask。 */
|
|
103
|
+
macosUnlinkPolicy?: MacOSUnlinkPolicy;
|
|
101
104
|
/** 实验功能:工作空间内删除进回收站 */
|
|
102
105
|
deleteProtection?: boolean;
|
|
103
106
|
/** 实验功能:运行时删除回收站保护(Node/Python/Git Bash 注入) */
|
|
@@ -2,6 +2,9 @@ import { Command } from 'commander';
|
|
|
2
2
|
export declare const CliDispatcher: unique symbol;
|
|
3
3
|
export declare const CliProvider: unique symbol;
|
|
4
4
|
export declare const DispatchStrategy: unique symbol;
|
|
5
|
+
/** Request-local controller/view handoff; never part of a wire message or Session. */
|
|
6
|
+
export declare const STREAM_JSON_RUN_RESULT = "codebuddy.streamJsonRunResult";
|
|
7
|
+
export declare const STREAM_JSON_COMPLETED_REQUEST = "codebuddy.streamJsonCompletedRequest";
|
|
5
8
|
export interface CliDispatcher {
|
|
6
9
|
dispatch(): Promise<void>;
|
|
7
10
|
}
|
|
@@ -447,7 +447,14 @@ export type ResultMessage = ({
|
|
|
447
447
|
* - 字段全部可选:`status` (HTTP 状态码)、`code` (SDK/业务码)、`category`
|
|
448
448
|
* (与 acp-agent.ts `classifyErrorAsRequestError` 分类对齐)、`details` (脱敏文案)。
|
|
449
449
|
*
|
|
450
|
-
*
|
|
450
|
+
* 例外(`is_error: true` 的终态):抛出物本身没有文案时(裸 `throw`、空 message 的
|
|
451
|
+
* `Error`、无 message 的对象),该槽位不再是 `null`,而是带
|
|
452
|
+
* `code: 'cbc_empty_error'` + 兜底 `details`。否则 `errors[i]` 与 `errors_info[i]`
|
|
453
|
+
* 同时为空,下游 `BuildErrorMessageFromCLIErrors` 会整条丢掉错误 `_meta`,
|
|
454
|
+
* 终态在观测侧退化为不可归因的 `stop_reason=refusal` + `error=""`。
|
|
455
|
+
*
|
|
456
|
+
* 详见 `result-message-utils.ts` 的 `buildErrorTerminalFields` /
|
|
457
|
+
* `buildErrorsInfo` / `extractStructuredErrorInfo`。
|
|
451
458
|
*/
|
|
452
459
|
errors_info?: Array<{
|
|
453
460
|
status?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SandboxRuleContext } from '../../workspace/agent-client-protocol/lib/common/index.js';
|
|
1
2
|
export declare const SensitiveDecisionMediation: unique symbol;
|
|
2
3
|
export declare const SensitiveContentMediation: unique symbol;
|
|
3
4
|
export declare const SensitiveToolEgressGuard: unique symbol;
|
|
@@ -245,6 +246,11 @@ export type SensitiveDetectionOutcome = {
|
|
|
245
246
|
} | {
|
|
246
247
|
kind: 'detected';
|
|
247
248
|
detectionRef: string;
|
|
249
|
+
ruleContext?: SandboxRuleContext;
|
|
250
|
+
ruleMatches?: Array<{
|
|
251
|
+
plaintext: string;
|
|
252
|
+
ruleContext: SandboxRuleContext;
|
|
253
|
+
}>;
|
|
248
254
|
plaintexts: string[];
|
|
249
255
|
/** 无可用密文条目的命中,仅作疑似提示展示,不参与加密/替换。 */
|
|
250
256
|
unprotectablePlaintexts?: string[];
|
|
@@ -291,6 +297,7 @@ export interface SandboxCenterPort {
|
|
|
291
297
|
export interface SensitiveApprovalPort {
|
|
292
298
|
requestApproval(request: {
|
|
293
299
|
detectionRef: string;
|
|
300
|
+
ruleContext?: SandboxRuleContext;
|
|
294
301
|
direction: SensitiveReviewRequest['direction'];
|
|
295
302
|
source: SensitiveReviewRequest['source'];
|
|
296
303
|
allowedChoices: SensitiveApprovalChoice[];
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { ProductConfiguration } from '../../workspace/product/lib/common/index.js';
|
|
3
|
+
declare module '@celljs/core/lib/common/container/dynamic-container' {
|
|
4
|
+
function createContainer(): Promise<import('@celljs/core').Container>;
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* 每次生命周期内惰性且幂等。首个 start()/verb 驱动(ensureStarted 收口)。
|
|
5
8
|
* boot 失败即出队:best-effort 释放半装配态后清缓存,下一次调用真重试——
|
|
6
9
|
* rejected promise 常驻会把一次瞬时失败固化成进程终身拒绝(lamp 毒 pod
|
|
7
10
|
* 判例:boot 崩一次后每个会话都撞 already-started,pod 成毒丸)。
|
|
8
11
|
*/
|
|
9
12
|
export declare function ensureBoot(product?: ProductConfiguration): Promise<void>;
|
|
10
13
|
/**
|
|
11
|
-
* stop()
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* stop() 收尾:Application.stop() → unbindAllAsync → Effect.dispose。
|
|
15
|
+
* 成功后可由新的显式 start() 构造全新容器;失败仍尝试全部阶段,但拒绝
|
|
16
|
+
* 再次 boot,避免旧 finalizer 与新实例共享进程级适配器。
|
|
14
17
|
*/
|
|
15
18
|
export declare function releaseContainer(): Promise<void>;
|
package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PromptResponse, RequestError } from '@agentclientprotocol/sdk';
|
|
1
|
+
import { type PromptResponse, RequestError } from '@agentclientprotocol/sdk-server';
|
|
2
2
|
export declare const CODEBUDDY_ERROR_META_KEY = "codebuddy.ai/error";
|
|
3
3
|
export declare const CODEBUDDY_ERROR_UPDATE_TYPE = "_codebuddy.ai/error";
|
|
4
4
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export type * from '@agentclientprotocol/sdk';
|
|
2
|
-
export type {
|
|
3
|
-
export type { McpUiBroadcastPayload, ModelInfo } from '../../../cli/dist-server/types/node/acp/acp-protocol.js';
|
|
1
|
+
export type * from '@agentclientprotocol/sdk-server';
|
|
2
|
+
export type { McpUiBroadcastPayload, ModelInfo } from '../../../acp/acp-protocol';
|
|
4
3
|
export interface AcpConnectionProfile {
|
|
5
4
|
endpoint: 'canonical' | 'compatibility';
|
|
6
5
|
compatibilityExtensions: boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FormattedSessionEvent, SessionSourceEvent } from '../../types';
|
|
2
|
+
/** Protocol presentation only. The Server remains the owner of run settlement. */
|
|
3
|
+
export declare class AcpSessionFormatter {
|
|
4
|
+
private readonly version;
|
|
5
|
+
private readonly lanes;
|
|
6
|
+
private readonly compactions;
|
|
7
|
+
private readonly streamedV1Messages;
|
|
8
|
+
constructor(version: 'acp-v1' | 'acp-v2');
|
|
9
|
+
format(source: SessionSourceEvent): Promise<FormattedSessionEvent<'acp-v1' | 'acp-v2'>[]>;
|
|
10
|
+
private wrap;
|
|
11
|
+
private model;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SessionNotification } from '@agentclientprotocol/sdk-server';
|
|
2
|
+
import type { UpdateSessionNotification } from '@agentclientprotocol/sdk-server/experimental/v2';
|
|
3
|
+
import type { AgentInputItem } from '../../../../vendor/cbc-shared/node/index.js';
|
|
4
|
+
import type { AgentEvent } from '../../types';
|
|
5
|
+
export declare function itemNotifications(sessionId: string, item: AgentInputItem, replay: boolean, readFile?: (path: string) => Promise<Uint8Array>): Promise<SessionNotification[]>;
|
|
6
|
+
/** Live complete items and replay share content, tool and identity projection. */
|
|
7
|
+
export declare const projectAgentItem: (sessionId: string, item: AgentInputItem) => Promise<UpdateSessionNotification[]>;
|
|
8
|
+
/** Reuse the CLI's ACP extension vocabulary; the Agent only exports kernel facts. */
|
|
9
|
+
export declare const projectNativeEvent: (frame: AgentEvent) => Promise<SessionNotification[]>;
|
|
10
|
+
export declare function projectAgentEvent(frame: AgentEvent): Promise<UpdateSessionNotification[]>;
|
|
@@ -15,7 +15,7 @@ export { start } from './start';
|
|
|
15
15
|
export { readSession } from './read-session';
|
|
16
16
|
export { readSessionCatalog } from './read-session-catalog';
|
|
17
17
|
export { createSession } from './create-session';
|
|
18
|
-
export type { ReadSessionCatalogOptions, ReloadOptions, CreateSessionOptions, ConfigChange, NotifyConfigChangeOptions, AgentEvent, AgentDefinition, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, QueryHooks, OrphanedExecSettlement, QueryOptions, QueryResult, QueryTicket, QueryInput, ReadSessionOptions, RewindOptions, RewindResult, RunAccount, RunAuth, RunCompletedEvent, RunStartedEvent, Sandbox, SandboxCapabilities, SandboxDriver, SandboxFactory, SandboxFileStat, SandboxShellResult, Server, SessionEvent, SessionCatalog, SessionEventOrigin, SessionEventListener, SessionSubscription, SessionSubscriptionExit, SessionSnapshot, SessionKey, SessionStore, SessionStoreEntry, StartOptions, StopReason, SteerOptions, SteerResult, } from './types';
|
|
18
|
+
export type { ReadSessionCatalogOptions, ReloadOptions, CreateSessionOptions, ConfigChange, NotifyConfigChangeOptions, AgentEvent, AgentDefinition, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, QueryHooks, OrphanedExecSettlement, QueryOptions, QueryResult, QueryTicket, QueryInput, ReadSessionOptions, RewindOptions, RewindResult, RunAccount, RunAuth, RunCompletedEvent, RunStartedEvent, Sandbox, SandboxCapabilities, SandboxDriver, SandboxFactory, SandboxFileStat, SandboxShellResult, Server, SessionEvent, FormattedSessionEvent, SessionOutputFormat, SubscribeOptions, NativeSessionEvent, AgentSdkEvent, AcpSessionEvent, SessionCatalog, SessionEventOrigin, SessionEventListener, SessionSubscription, SessionSubscriptionExit, SessionSnapshot, SessionKey, SessionStore, SessionStoreEntry, StartOptions, StopReason, SteerOptions, SteerResult, } from './types';
|
|
19
19
|
export { InMemorySessionStore } from './in-memory-session-store';
|
|
20
20
|
export { WORKBUDDY_TOOLS } from './tool-presets';
|
|
21
21
|
export { InMemoryFs, MountableFs, OverlayFs, ReadWriteFs } from './fs-kit';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Session } from '../../vendor/cbc-core/node/index.js';
|
|
2
|
-
import type { QueryInput, QueryOptions, QueryTicket, ReloadOptions, RewindOptions, RewindResult,
|
|
2
|
+
import type { FormattedSessionEvent, QueryInput, QueryOptions, QueryTicket, ReloadOptions, RewindOptions, RewindResult, SessionOutputFormat, SessionSubscription, SteerOptions, SteerResult, SubscribeOptions } from './types';
|
|
3
3
|
interface SettleOutcome {
|
|
4
4
|
assistantText: string;
|
|
5
5
|
completedError?: unknown;
|
|
@@ -46,7 +46,8 @@ export declare function interrupt(sessionId: string): Promise<void>;
|
|
|
46
46
|
* whose queue exceeds the high-water mark is evicted — recover by
|
|
47
47
|
* re-subscribing and catching up from the session store.
|
|
48
48
|
*/
|
|
49
|
-
export declare function subscribe(sessionId: string, listener:
|
|
49
|
+
export declare function subscribe(sessionId: string, listener: (event: FormattedSessionEvent) => void | Promise<void>): SessionSubscription;
|
|
50
|
+
export declare function subscribe<F extends SessionOutputFormat>(sessionId: string, listener: (event: FormattedSessionEvent<F>) => void | Promise<void>, options: SubscribeOptions<F>): SessionSubscription;
|
|
50
51
|
/**
|
|
51
52
|
* Passivation hint. Optional, and never a terminal state: closing equals an
|
|
52
53
|
* orderly crash, and any verb reactivates the session from storage.
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
* docs/cloud-native/agent-cli-server.md): the SessionStore
|
|
5
5
|
* adapter contract, the Sandbox family, and the stream-json event union.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { SessionNotification } from '@agentclientprotocol/sdk-server';
|
|
8
|
+
import type { UpdateSessionNotification } from '@agentclientprotocol/sdk-server/experimental/v2';
|
|
9
|
+
import type { AgentPhaseInfo, CanUseTool, CombineEvent, SessionKey, SubagentEventReference, SubagentTokenUsageSnapshot, TranscriptStore as SessionStore } from '../../vendor/cbc-core/node/index.js';
|
|
10
|
+
import type { AgentInputItem, ResponseStreamEvent, RunStreamEvent } from '../../vendor/cbc-shared/node/index.js';
|
|
11
|
+
import type { Command, ProductConfiguration, Skill } from '../../workspace/product/lib/common/index.js';
|
|
9
12
|
import type { RunAccount, RunAuth } from '../authentication/run-context';
|
|
10
13
|
import type { Message } from '../cli/stream-json-protocol';
|
|
11
14
|
import type { FileSystem, InitialFiles } from '../data-fs';
|
|
@@ -39,6 +42,7 @@ export interface StartOptions {
|
|
|
39
42
|
* CODEBUDDY_AUTH_TOKEN / CODEBUDDY_SESSION_SKILL_DIRS)拒绝:凭据只认
|
|
40
43
|
* query options(auth)与 start({ apiKey })。会话级差异走
|
|
41
44
|
* `query({ settings: { env } })`——ALS 会话档,并行 run 各自解析无竞态。
|
|
45
|
+
* stop 或启动失败后恢复本次覆盖的环境值;宿主期间主动修改的值保留。
|
|
42
46
|
*/
|
|
43
47
|
env?: Record<string, string>;
|
|
44
48
|
/** Global SessionStore adapter (SDK shape). Durable events append here on settle. */
|
|
@@ -84,6 +88,7 @@ export interface StartOptions {
|
|
|
84
88
|
* `stop()` drains in-flight work, then disconnects persistence. Supports
|
|
85
89
|
* `await using`; deliberately no synchronous dispose — graceful shutdown is
|
|
86
90
|
* inherently async.
|
|
91
|
+
* Await successful stop before starting a new runtime in the same process.
|
|
87
92
|
*/
|
|
88
93
|
export interface Server {
|
|
89
94
|
stop(): Promise<void>;
|
|
@@ -115,13 +120,15 @@ export interface RewindResult {
|
|
|
115
120
|
}
|
|
116
121
|
/** Durable Agent items, including message identities and conversation facts. */
|
|
117
122
|
export interface SessionSnapshot {
|
|
123
|
+
/** Persisted standing Agent, independent of current Product defaults. */
|
|
124
|
+
mainAgent?: string;
|
|
118
125
|
sessionId: string;
|
|
119
126
|
cwd: string;
|
|
120
|
-
history:
|
|
127
|
+
history: AgentInputItem[];
|
|
121
128
|
/** Store-owned locators. Pass a key to readSession to read that child lazily. */
|
|
122
129
|
subagents?: Array<{
|
|
123
130
|
sessionId: string;
|
|
124
|
-
key:
|
|
131
|
+
key: SessionKey;
|
|
125
132
|
}>;
|
|
126
133
|
}
|
|
127
134
|
/**
|
|
@@ -396,7 +403,7 @@ export type SteerResult = {
|
|
|
396
403
|
*/
|
|
397
404
|
export type SessionEvent = (Message | RunStartedEvent | RunCompletedEvent | AgentEvent) & {
|
|
398
405
|
/** Complete Agent item behind a message frame, shared with readSession(). */
|
|
399
|
-
readonly item?:
|
|
406
|
+
readonly item?: AgentInputItem;
|
|
400
407
|
/** Producer-owned identity. Background and child events retain their original run. */
|
|
401
408
|
readonly origin?: SessionEventOrigin;
|
|
402
409
|
};
|
|
@@ -435,13 +442,19 @@ export interface AgentEvent {
|
|
|
435
442
|
} | {
|
|
436
443
|
readonly type: 'catalog';
|
|
437
444
|
readonly data: SessionCatalog;
|
|
445
|
+
} | {
|
|
446
|
+
readonly type: 'title';
|
|
447
|
+
readonly data: string;
|
|
448
|
+
} | {
|
|
449
|
+
readonly type: 'error';
|
|
450
|
+
readonly data: unknown;
|
|
438
451
|
};
|
|
439
452
|
readonly _requestId?: string;
|
|
440
453
|
readonly _meta?: Record<string, unknown> | null;
|
|
441
454
|
}
|
|
442
455
|
export interface SessionCatalog {
|
|
443
|
-
readonly commands: Array<Pick<
|
|
444
|
-
readonly skills: Array<Pick<
|
|
456
|
+
readonly commands: Array<Pick<Command, 'name' | 'description' | 'argumentHint' | 'tags'>>;
|
|
457
|
+
readonly skills: Array<Pick<Skill, 'name' | 'description' | 'source' | 'userInvocable' | 'disableModelInvocation' | 'pluginInfo'>>;
|
|
445
458
|
readonly skillOverrides?: Settings['skillOverrides'];
|
|
446
459
|
}
|
|
447
460
|
/** Refresh resident components before the next queued turn (including continuations).
|
|
@@ -469,6 +482,45 @@ export interface RunCompletedEvent extends QueryResult {
|
|
|
469
482
|
readonly session_id: string;
|
|
470
483
|
readonly _meta?: Record<string, unknown> | null;
|
|
471
484
|
}
|
|
485
|
+
/** Selects only presentation; query lifecycle and persistence are shared. */
|
|
486
|
+
export type SessionOutputFormat = 'openai' | 'messages' | 'acp-v1' | 'acp-v2';
|
|
487
|
+
export interface SubscribeOptions<F extends SessionOutputFormat = 'messages'> {
|
|
488
|
+
readonly format: F;
|
|
489
|
+
}
|
|
490
|
+
/** All SDK stream event variants, with the original object as data (no JSON conversion). */
|
|
491
|
+
export interface AgentSdkEvent {
|
|
492
|
+
readonly type: 'agent_sdk';
|
|
493
|
+
readonly parentToolUseId?: string;
|
|
494
|
+
readonly session_id: string;
|
|
495
|
+
readonly data: RunStreamEvent;
|
|
496
|
+
readonly origin?: SessionEventOrigin;
|
|
497
|
+
readonly _meta?: Record<string, unknown> | null;
|
|
498
|
+
}
|
|
499
|
+
/** Native model facts used by formatters, never stream-json intermediates. */
|
|
500
|
+
export interface AgentModelEvent {
|
|
501
|
+
readonly type: 'agent_model';
|
|
502
|
+
readonly parentToolUseId?: string;
|
|
503
|
+
readonly session_id: string;
|
|
504
|
+
readonly data: ResponseStreamEvent;
|
|
505
|
+
readonly origin?: SessionEventOrigin;
|
|
506
|
+
readonly _meta?: Record<string, unknown> | null;
|
|
507
|
+
}
|
|
508
|
+
export interface AcpSessionEvent<F extends 'acp-v1' | 'acp-v2'> {
|
|
509
|
+
readonly type: 'acp_update';
|
|
510
|
+
readonly notification: F extends 'acp-v1' ? SessionNotification : UpdateSessionNotification;
|
|
511
|
+
readonly item?: AgentInputItem;
|
|
512
|
+
readonly origin?: SessionEventOrigin;
|
|
513
|
+
readonly _meta?: Record<string, unknown> | null;
|
|
514
|
+
}
|
|
515
|
+
export type NativeSessionEvent = (AgentSdkEvent | AgentEvent | RunStartedEvent | RunCompletedEvent) & {
|
|
516
|
+
readonly origin?: SessionEventOrigin;
|
|
517
|
+
};
|
|
518
|
+
export type FormattedSessionEvent<F extends SessionOutputFormat = 'messages'> = (F extends 'messages' ? SessionEvent : F extends 'acp-v1' | 'acp-v2' ? AcpSessionEvent<F> | AgentEvent | RunStartedEvent | RunCompletedEvent : NativeSessionEvent) & {
|
|
519
|
+
readonly origin?: SessionEventOrigin;
|
|
520
|
+
readonly item?: AgentInputItem;
|
|
521
|
+
};
|
|
522
|
+
/** Internal source union. ACP never consumes stream-json messages. */
|
|
523
|
+
export type SessionSourceEvent = SessionEvent | AgentSdkEvent | AgentModelEvent;
|
|
472
524
|
export type SessionEventListener = (event: SessionEvent) => void | Promise<void>;
|
|
473
525
|
export type SessionSubscriptionExit = {
|
|
474
526
|
readonly reason: 'unsubscribed';
|
|
@@ -21,13 +21,13 @@ export declare const DEFAULT_SLASH_COMMAND_TOOL_CHAR_BUDGET = 8000;
|
|
|
21
21
|
export declare const DEFAULT_SKILL_TOOL_CHAR_BUDGET = 8000;
|
|
22
22
|
export declare const DEFAULT_AGENT_TOOL_CHAR_BUDGET = 30000;
|
|
23
23
|
/** Per-entry hard cap for a single skill's description */
|
|
24
|
-
export declare const MAX_SKILL_DESC_CHARS =
|
|
24
|
+
export declare const MAX_SKILL_DESC_CHARS = 200;
|
|
25
25
|
/** Minimum maxDescLen below which non-protected skills degrade to names-only (aligned with CC MIN_DESC_LENGTH=20) */
|
|
26
26
|
export declare const MIN_SKILL_DESC_LENGTH = 20;
|
|
27
27
|
/**
|
|
28
28
|
* Env name for per-skill description hard-cap overrides.
|
|
29
29
|
*
|
|
30
|
-
* By default every skill's description is hard-capped to {@link MAX_SKILL_DESC_CHARS}(
|
|
30
|
+
* By default every skill's description is hard-capped to {@link MAX_SKILL_DESC_CHARS}(200)
|
|
31
31
|
* per entry. A host can loosen (or tighten) this cap for **specific** skills — identified
|
|
32
32
|
* by skill name — without changing the global default, by exporting this env.
|
|
33
33
|
*
|
|
@@ -377,6 +377,20 @@ export interface ToolManager {
|
|
|
377
377
|
* 仅作用于 toolMap 中的内置工具;MCP 工具不走此路径。
|
|
378
378
|
*/
|
|
379
379
|
ensureBuiltinDeferIndexed(toolName: string): Promise<boolean>;
|
|
380
|
+
/**
|
|
381
|
+
* 在工具执行前创建文件备份(file-history 快照),返回被跟踪的文件路径。
|
|
382
|
+
*
|
|
383
|
+
* 直连路径由 {@link executeToolWithHooks} 内部自动调用;REPL/Code Mode 沙箱
|
|
384
|
+
* 执行路径(DeferExecuteTool.routeToolCall → executeBuiltinTool)绕过该 hook
|
|
385
|
+
* 包装,需在真正执行工具前显式调用本方法,否则沙箱内的 Edit/Write 不产生
|
|
386
|
+
* FileHistorySnapshotItem,rewind 无快照可恢复(#130664)。
|
|
387
|
+
*
|
|
388
|
+
* 依赖 FileTrackService.trackFile 幂等(文件已在当前 checkpoint 即跳过),两条
|
|
389
|
+
* 路径都触达时也只落一次快照。
|
|
390
|
+
*/
|
|
391
|
+
trackFileForToolCall(toolName: string, toolInput: unknown, session: Session, details?: {
|
|
392
|
+
toolCall: FunctionCallItem;
|
|
393
|
+
}): Promise<string | undefined>;
|
|
380
394
|
addBackgroundTask(task: BackgroundTask): void;
|
|
381
395
|
removeBackgroundTask(id: string): void;
|
|
382
396
|
getBackgroundTasks(): BackgroundTask[];
|
|
@@ -550,6 +550,19 @@ export interface AgentServiceRunControlOptions {
|
|
|
550
550
|
bypassMessageQueue?: boolean;
|
|
551
551
|
/** Input is already present in Session history; do not append it again. */
|
|
552
552
|
skipAddHistory?: boolean;
|
|
553
|
+
/** Let an interactive host route external `/compact` before normal run admission. */
|
|
554
|
+
routeManualCompact?: boolean;
|
|
555
|
+
/**
|
|
556
|
+
* Per-call out-signal of `runDefault`: invoked once, synchronously, after
|
|
557
|
+
* this call passed run admission (its startup controller is installed on
|
|
558
|
+
* the Session) and before the agent is resolved. Not invoked when admission
|
|
559
|
+
* throws. It says nothing about the model having started or the run
|
|
560
|
+
* succeeding; without `bypassMessageQueue` the run may still be queued
|
|
561
|
+
* afterwards (see `onEnqueued`). A throwing callback is logged and does not
|
|
562
|
+
* affect the run. Internal re-runs pass fresh options and never carry it; it
|
|
563
|
+
* is stripped before AgentRunRequest and the SDK.
|
|
564
|
+
*/
|
|
565
|
+
onAdmitted?: () => void;
|
|
553
566
|
}
|
|
554
567
|
/** Options for an isolated run or an SDK RunState resume. */
|
|
555
568
|
export type AgentStandardRunOptions<TContext = Session> = AgentSdkRunOptions<TContext> & AgentServiceRunControlOptions & {
|
|
@@ -566,6 +579,8 @@ export type AgentStandardRunOptions<TContext = Session> = AgentSdkRunOptions<TCo
|
|
|
566
579
|
* cannot clobber each other's outcome.
|
|
567
580
|
*/
|
|
568
581
|
onEnqueued?: () => void;
|
|
582
|
+
/** Exact result of this arrival, including execution after a queue drain. */
|
|
583
|
+
onResult?: (result: NonNullable<Session['resultSubject']['value']>) => void;
|
|
569
584
|
};
|
|
570
585
|
/**
|
|
571
586
|
* Explicitly claim the current process-local logical turn.
|
|
@@ -585,12 +600,19 @@ export interface AgentService {
|
|
|
585
600
|
tryCloseTaskSession?(session: Session, result: NonNullable<Session['resultSubject']['value']>): Promise<boolean>;
|
|
586
601
|
/** Stop accepting task work and join its physical runs before releasing dependencies. */
|
|
587
602
|
retireTaskSession?(session: Session): Promise<void>;
|
|
603
|
+
/**
|
|
604
|
+
* 有界等待该 session 上的物理 run 收尾(含它把最终产出写进 history)。
|
|
605
|
+
*
|
|
606
|
+
* `agent_end` 早于 run 的 finalize,所以「上一轮 history 已写完」不能靠 `agent_end`
|
|
607
|
+
* 判定;需要该因果的调用方(队列 drain)join 到这里。超时会放行并告警,不会挂死。
|
|
608
|
+
*/
|
|
609
|
+
waitForRunsSettled?(session: Session): Promise<void>;
|
|
588
610
|
run<TAgent extends Agent<any, any>>(agent: TAgent, input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
589
611
|
run<TAgent extends Agent<any, any>, TContext = Session>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
590
612
|
runDefault<TAgent extends Agent<any, any>>(input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
591
613
|
runDefault<TAgent extends Agent<any, any>, TContext = Session>(input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
592
|
-
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext>): Promise<string>;
|
|
593
|
-
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext>): Promise<string>;
|
|
614
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
615
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
594
616
|
/**
|
|
595
617
|
* Run a one-shot agent call in a forked (isolated) session that inherits
|
|
596
618
|
* the conversation history from the parent session. The forked session is
|
|
@@ -656,6 +678,11 @@ export interface ForkedAgentOptions {
|
|
|
656
678
|
/** Optional cap on number of turns (default: 1 for one-shot) */
|
|
657
679
|
maxTurns?: number;
|
|
658
680
|
}
|
|
681
|
+
/** Options of `runOneTime` on top of the SDK run options. */
|
|
682
|
+
export interface OneTimeRunOptions {
|
|
683
|
+
/** X-Agent-Purpose of the call; defaults to the agent's `AGENT_PURPOSE_MAP` entry, else its name. */
|
|
684
|
+
purpose?: string;
|
|
685
|
+
}
|
|
659
686
|
export interface RunRequest {
|
|
660
687
|
prompt?: string;
|
|
661
688
|
inputFormat?: 'text' | 'stream-json';
|
|
@@ -697,6 +724,8 @@ export interface AgentRunRequest<TContext = Session> extends SessionOptions {
|
|
|
697
724
|
skipAddHistory?: boolean;
|
|
698
725
|
bypassMessageQueue?: boolean;
|
|
699
726
|
inputOrigin?: AgentRunOrigin;
|
|
727
|
+
/** Process-local arrival callback; never passed to the SDK. */
|
|
728
|
+
onResult?: AgentStandardRunOptions['onResult'];
|
|
700
729
|
traceId?: string;
|
|
701
730
|
/**
|
|
702
731
|
* #59319-5: 普通 run 二次裁决发现 session 仍 busy 时由 AgentService 设置。
|
|
@@ -58,7 +58,9 @@ export declare enum AgentPurpose {
|
|
|
58
58
|
/** Auto mode permission risk classification (runOneTime: AUTO_MODE_CLASSIFIER) */
|
|
59
59
|
AutoModeClassifier = "auto_mode_classifier",
|
|
60
60
|
/** Automation scheduled task execution */
|
|
61
|
-
Automation = "automation"
|
|
61
|
+
Automation = "automation",
|
|
62
|
+
/** `/btw` side question on a forked Session (runForked); Claude Code's `side_question` source */
|
|
63
|
+
SideQuestion = "side_question"
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* Dynamic purpose prefix for built-in subagents.
|
|
@@ -127,6 +129,9 @@ export declare const AUXILIARY_PURPOSES: ReadonlySet<string>;
|
|
|
127
129
|
* 时 purpose 可能尚未设置的普通对话仍按原行为发出 MODEL_REQUEST_STARTED。
|
|
128
130
|
*/
|
|
129
131
|
export declare function isAuxiliaryPurpose(purpose?: string): boolean;
|
|
132
|
+
/** Purposes of compaction summary calls (X-Agent-Type `compaction`). */
|
|
133
|
+
export declare const COMPACTION_PURPOSES: ReadonlySet<string>;
|
|
134
|
+
export declare function isCompactionPurpose(purpose?: string): boolean;
|
|
130
135
|
/**
|
|
131
136
|
* 按 purpose 旁路 agent 生命周期事件(agent_start / agent_end / tool / handoff)。
|
|
132
137
|
*
|
|
@@ -145,9 +150,8 @@ export declare function isAuxiliaryPurpose(purpose?: string): boolean;
|
|
|
145
150
|
*
|
|
146
151
|
* 因此这里只收 PreMessage 这一种 purpose。
|
|
147
152
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* 会让**主 run** 也被误旁路,反而放大本要修复的孤儿 run 问题。
|
|
153
|
+
* The purpose is scoped to the summary call (`runOneTime` → `runWithAgentPurpose`), so it
|
|
154
|
+
* cannot leak onto the pending main run.
|
|
151
155
|
*
|
|
152
156
|
* multi-session(#44317)回归时,PreMessage 承载应改回临时子 Session;本名单保留为
|
|
153
157
|
* 冗余防线即可(临时 Session 上旁路是无害的)。
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AgentType } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
2
|
+
interface PurposeCarrier {
|
|
3
|
+
agentPurpose?: string;
|
|
4
|
+
conversationRequestId?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runs an auxiliary model call (title, summary, WebFetch analysis, ...) on a
|
|
8
|
+
* caller-owned Session without writing its purpose / request id onto the shared
|
|
9
|
+
* Session, where a concurrent main run would read and send them as its own.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runWithAgentPurpose<T>(session: object, purpose: string, callback: () => T, options?: {
|
|
12
|
+
conversationRequestId?: string;
|
|
13
|
+
}): T;
|
|
14
|
+
/** True when the current async chain is an auxiliary call scoped to `session`. */
|
|
15
|
+
export declare function isInAgentPurposeScope(session: object | undefined): boolean;
|
|
16
|
+
/** Purpose of the model call running in the current async chain. */
|
|
17
|
+
export declare function getEffectiveAgentPurpose(session: PurposeCarrier | undefined): string | undefined;
|
|
18
|
+
/** Request id of the model call running in the current async chain. */
|
|
19
|
+
export declare function getEffectiveConversationRequestId(session: PurposeCarrier | undefined): string | undefined;
|
|
20
|
+
/** Purposes whose model calls are steps of a Session's own agent loop. */
|
|
21
|
+
export declare function isMainConversationPurpose(purpose: string | undefined): boolean;
|
|
22
|
+
/** True when the model call in the current async chain is a step of `session`'s agent loop. */
|
|
23
|
+
export declare function isMainLoopModelCall(session: PurposeCarrier | undefined): boolean;
|
|
24
|
+
/** True when the model call in the current async chain has an `AUXILIARY_PURPOSES` purpose. */
|
|
25
|
+
export declare function isAuxiliaryPurposeCall(session: PurposeCarrier | undefined): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Runs `callback` outside any purpose scope. A run started from a helper call's async
|
|
28
|
+
* chain (e.g. a queued message drained on its agent_end) is a new agent-loop run.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runOutsideAgentPurposeScope<T>(callback: () => T): T;
|
|
31
|
+
export type ModelCallAgentType = AgentType;
|
|
32
|
+
/** Role of the Session's own agent loop, for request-level events. */
|
|
33
|
+
export declare function resolveSessionAgentType(session: {
|
|
34
|
+
meta?: Record<string, unknown>;
|
|
35
|
+
}): 'main' | 'subagent' | 'team';
|
|
36
|
+
/**
|
|
37
|
+
* Role of the model call in the current async chain (X-Agent-Type / telemetry
|
|
38
|
+
* `agentType`), mirroring Claude Code's `x-claude-code-request-class`: compaction
|
|
39
|
+
* summaries report `compaction`, other one-shot helpers (title, WebFetch analysis,
|
|
40
|
+
* ...) report `auxiliary`, whatever Session they run on. The specific helper
|
|
41
|
+
* stays in X-Agent-Purpose.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveModelCallAgentType(session: PurposeCarrier & {
|
|
44
|
+
meta?: Record<string, unknown>;
|
|
45
|
+
}): ModelCallAgentType;
|
|
46
|
+
export {};
|
|
@@ -3,10 +3,11 @@ import { AuthenticationManager } from '../../../../workspace/authentication/lib/
|
|
|
3
3
|
import { type AbortLinkDisposer, Agent, type AgentInputItem, type NonStreamRunOptions, RunState, type StreamRunOptions } from '../../../cbc-shared/node/index.js';
|
|
4
4
|
import { type LanguageModel } from '../../../../workspace/product/lib/common/index.js';
|
|
5
5
|
import { Logger } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
6
|
+
import { type ManualCompactRequestHandler as ManualCompactRequestHandlerContract } from '../context/context-protocol';
|
|
6
7
|
import { type FileRollbackOperationLock as FileRollbackOperationLockContract } from '../file-rollback/file-rollback-service-protocol';
|
|
7
8
|
import { Session, SessionManager } from '../session/session-protocol';
|
|
8
9
|
import { SessionRunStateMachine } from '../session/session-run-state-machine-protocol';
|
|
9
|
-
import { type AgentCurrentContinuationOptions, AgentManager, AgentRunInterceptor, AgentRunRequest, AgentService, type AgentStandardRunOptions, RunnerProvider } from './agent-protocol';
|
|
10
|
+
import { type AgentCurrentContinuationOptions, AgentManager, AgentRunInterceptor, AgentRunRequest, AgentService, type AgentStandardRunOptions, type OneTimeRunOptions, RunnerProvider } from './agent-protocol';
|
|
10
11
|
import { type AgentRunScope as IAgentRunScope } from './agent-run-scope';
|
|
11
12
|
import { AgentPluginRefresh, AgentRunObserver, AgentRuntimeResolver } from './agent-runtime-protocol';
|
|
12
13
|
export declare class AgentServiceImpl implements AgentService {
|
|
@@ -22,6 +23,7 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
22
23
|
protected readonly agentRunInterceptorProvider: Provider<AgentRunInterceptor>;
|
|
23
24
|
protected readonly fileRollbackOperationLock?: FileRollbackOperationLockContract;
|
|
24
25
|
protected readonly logger: Logger;
|
|
26
|
+
protected readonly manualCompactRequestHandler?: ManualCompactRequestHandlerContract;
|
|
25
27
|
/**
|
|
26
28
|
* Preserve the pre-start cancellation snapshot across runDefault's agent
|
|
27
29
|
* lookup controller and run()'s own controller. This is process-local
|
|
@@ -40,6 +42,20 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
40
42
|
protected getLifecycleOwners(): WeakMap<Session, AbortController>;
|
|
41
43
|
tryCloseTaskSession(session: Session, result: NonNullable<Session['resultSubject']['value']>): Promise<boolean>;
|
|
42
44
|
retireTaskSession(session: Session): Promise<void>;
|
|
45
|
+
waitForRunsSettled(session: Session): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 有界 join:等到该 session 上的物理 run 全部交还 lifecycle owner 与 in-flight 信号。
|
|
48
|
+
*
|
|
49
|
+
* 为什么需要它而不是直接看 `agent_end`:`finalizeRun` 晚于本轮把最终产出写进
|
|
50
|
+
* history,`agent_end` 却早于 `finalizeRun`。任何依赖「上一轮 history 已写完」这个
|
|
51
|
+
* 因果的调用方(如队列 drain)必须 join 到这里。
|
|
52
|
+
*
|
|
53
|
+
* Bounded: `runSettledSubject` is optional, so a session built without
|
|
54
|
+
* one has nothing to observe and would hang the caller's cleanup — which
|
|
55
|
+
* owns hook, MCP and background-shell teardown. `agent_end` 也可能来自没有物理
|
|
56
|
+
* run 的路径(skipRun / 迟到事件),无界等待会把调用方永久挂住。
|
|
57
|
+
*/
|
|
58
|
+
private joinRunsSettled;
|
|
43
59
|
/** compare-and-delete:仅当 token 仍指向本轮 controller 时清除。 */
|
|
44
60
|
private clearLifecycleOwner;
|
|
45
61
|
/** 本轮是否是当前 lifecycle owner。 */
|
|
@@ -156,6 +172,7 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
156
172
|
protected resolveRunOneTimeModel(agentName: string, session?: Session): Promise<LanguageModel>;
|
|
157
173
|
run<TAgent extends Agent<any, any>>(agent: TAgent, input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
158
174
|
run<TAgent extends Agent<any, any>, TContext = Session>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
175
|
+
private runPipeline;
|
|
159
176
|
/**
|
|
160
177
|
* #59319-stream: 抽取的 physical run cleanup 逻辑。
|
|
161
178
|
* 非 stream 路径由 run() finally 同步调用;
|
|
@@ -189,8 +206,14 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
189
206
|
private prepareRunAdmission;
|
|
190
207
|
runDefault<TAgent extends Agent<any, any>>(input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
191
208
|
runDefault<TAgent extends Agent<any, any>, TContext = Session>(input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
192
|
-
|
|
193
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Streams the text of a one-shot run on `session`. A reused caller Session is shared
|
|
211
|
+
* with its in-flight main run, so the call's purpose and request id live in its async
|
|
212
|
+
* scope instead of on the Session.
|
|
213
|
+
*/
|
|
214
|
+
private streamOneTimeText;
|
|
215
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
216
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
194
217
|
/**
|
|
195
218
|
* Enhanced version of runOneTime that supports per-request overrides
|
|
196
219
|
* for temperature, maxTokens, maxTurns, systemPrompt, and bypassPermissions.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export * from './agent-protocol';
|
|
2
2
|
export * from './agent-purpose-protocol';
|
|
3
|
+
export * from './agent-purpose-scope';
|
|
4
|
+
export * from './model-step-sequence';
|
|
5
|
+
export * from './model-call-failure';
|
|
3
6
|
export * from './agent-runtime-protocol';
|
|
4
7
|
export * from './agent-run-scope';
|
|
5
8
|
export * from './agent-service';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModelCallGeneration } from '../session/session-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Marks `error` as the failure of one model call. The call's ids live in the model-call
|
|
4
|
+
* async scope, which does not reach the consumer of the SDK run stream; the error does.
|
|
5
|
+
* An error rethrown through an outer call keeps the innermost call's mark.
|
|
6
|
+
*/
|
|
7
|
+
export declare function markModelCallFailure<T>(error: T, sessionId: string, generation: ModelCallGeneration): T;
|
|
8
|
+
/** The model call of this Session that failed with `error`; undefined when the failure is not one. */
|
|
9
|
+
export declare function getFailedModelCall(error: unknown, sessionId: string): ModelCallGeneration | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Session } from '../session/session-protocol';
|
|
2
|
+
type StepSequenceSession = Pick<Session, 'id' | 'history' | 'agentPurpose' | 'modelStepSeq'>;
|
|
3
|
+
/** Latest step of the Session's agent loop, restored from persisted history after resume. */
|
|
4
|
+
export declare function currentModelStepSeq(session: StepSequenceSession): number;
|
|
5
|
+
/**
|
|
6
|
+
* Step number for the model call in the current async chain. Agent-loop calls
|
|
7
|
+
* advance the counter; auxiliary calls reuse the latest step. The counter never
|
|
8
|
+
* resets across runs, compaction continuations or teammate wake-ups.
|
|
9
|
+
*/
|
|
10
|
+
export declare function allocateModelStepSeq(session: StepSequenceSession): number;
|
|
11
|
+
export {};
|