@zhushanwen/subagent-engine-sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/best-effort.cjs +88 -0
- package/dist/best-effort.d.cts +14 -0
- package/dist/best-effort.d.ts +14 -0
- package/dist/best-effort.js +8 -0
- package/dist/chunk-2DIMPZCQ.js +0 -0
- package/dist/chunk-365AUV6N.js +67 -0
- package/dist/chunk-3K2P2CM2.js +127 -0
- package/dist/chunk-75QEMUGV.js +58 -0
- package/dist/chunk-7I4XGL5J.js +95 -0
- package/dist/chunk-A75XDJIC.js +227 -0
- package/dist/chunk-DSQ7JQKM.js +39 -0
- package/dist/chunk-EJMF63R5.js +19 -0
- package/dist/chunk-GT6YLLN4.js +46 -0
- package/dist/chunk-HYES77BR.js +109 -0
- package/dist/chunk-JSBRDJBE.js +30 -0
- package/dist/chunk-LEOBWKRM.js +128 -0
- package/dist/chunk-N3RL6OVM.js +38 -0
- package/dist/chunk-OPMY4G4M.js +27 -0
- package/dist/chunk-PPEPBVCC.js +120 -0
- package/dist/chunk-PYO3YR7W.js +16 -0
- package/dist/chunk-RDH3ZOV6.js +46 -0
- package/dist/chunk-RULLX6C6.js +11 -0
- package/dist/chunk-X24SFZYW.js +6646 -0
- package/dist/chunk-YFSN3D5N.js +216 -0
- package/dist/chunk-ZOFFJNJD.js +136 -0
- package/dist/chunk-ZXEAW25V.js +132 -0
- package/dist/cli-entry.cjs +119 -0
- package/dist/cli-entry.d.cts +24 -0
- package/dist/cli-entry.d.ts +24 -0
- package/dist/cli-entry.js +8 -0
- package/dist/contract-types-sSlgppBC.d.cts +352 -0
- package/dist/contract-types-sSlgppBC.d.ts +352 -0
- package/dist/data-dir.cjs +117 -0
- package/dist/data-dir.d.cts +20 -0
- package/dist/data-dir.d.ts +20 -0
- package/dist/data-dir.js +12 -0
- package/dist/env.cjs +205 -0
- package/dist/env.d.cts +73 -0
- package/dist/env.d.ts +73 -0
- package/dist/env.js +16 -0
- package/dist/error-codes-DHco5-i_.d.cts +118 -0
- package/dist/error-codes-Dhss2Kmk.d.ts +118 -0
- package/dist/error-message.cjs +40 -0
- package/dist/error-message.d.cts +3 -0
- package/dist/error-message.d.ts +3 -0
- package/dist/error-message.js +7 -0
- package/dist/index.cjs +8375 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +268 -0
- package/dist/journal-io.cjs +70 -0
- package/dist/journal-io.d.cts +12 -0
- package/dist/journal-io.d.ts +12 -0
- package/dist/journal-io.js +7 -0
- package/dist/journal-replay.cjs +256 -0
- package/dist/journal-replay.d.cts +45 -0
- package/dist/journal-replay.d.ts +45 -0
- package/dist/journal-replay.js +17 -0
- package/dist/kill-chain.cjs +221 -0
- package/dist/kill-chain.d.cts +74 -0
- package/dist/kill-chain.d.ts +74 -0
- package/dist/kill-chain.js +23 -0
- package/dist/logger.cjs +84 -0
- package/dist/logger.d.cts +24 -0
- package/dist/logger.d.ts +24 -0
- package/dist/logger.js +11 -0
- package/dist/logs/stderr-rotation.cjs +151 -0
- package/dist/logs/stderr-rotation.d.cts +37 -0
- package/dist/logs/stderr-rotation.d.ts +37 -0
- package/dist/logs/stderr-rotation.js +23 -0
- package/dist/nesting-guard.cjs +95 -0
- package/dist/nesting-guard.d.cts +65 -0
- package/dist/nesting-guard.d.ts +65 -0
- package/dist/nesting-guard.js +15 -0
- package/dist/node-executor.cjs +180 -0
- package/dist/node-executor.d.cts +63 -0
- package/dist/node-executor.d.ts +63 -0
- package/dist/node-executor.js +16 -0
- package/dist/paths.cjs +55 -0
- package/dist/paths.d.cts +8 -0
- package/dist/paths.d.ts +8 -0
- package/dist/paths.js +15 -0
- package/dist/port-contract.cjs +35 -0
- package/dist/port-contract.d.cts +88 -0
- package/dist/port-contract.d.ts +88 -0
- package/dist/port-contract.js +7 -0
- package/dist/protocol/index.cjs +400 -0
- package/dist/protocol/index.d.cts +685 -0
- package/dist/protocol/index.d.ts +685 -0
- package/dist/protocol/index.js +89 -0
- package/dist/relay-env.cjs +71 -0
- package/dist/relay-env.d.cts +37 -0
- package/dist/relay-env.d.ts +37 -0
- package/dist/relay-env.js +23 -0
- package/dist/schema-emulation.cjs +6680 -0
- package/dist/schema-emulation.d.cts +39 -0
- package/dist/schema-emulation.d.ts +39 -0
- package/dist/schema-emulation.js +11 -0
- package/dist/spawn.cjs +200 -0
- package/dist/spawn.d.cts +80 -0
- package/dist/spawn.d.ts +80 -0
- package/dist/spawn.js +16 -0
- package/dist/ui-channels.cjs +120 -0
- package/dist/ui-channels.d.cts +60 -0
- package/dist/ui-channels.d.ts +60 -0
- package/dist/ui-channels.js +9 -0
- package/dist/ui-types.cjs +18 -0
- package/dist/ui-types.d.cts +62 -0
- package/dist/ui-types.d.ts +62 -0
- package/dist/ui-types.js +1 -0
- package/package.json +58 -0
- package/src/best-effort.ts +37 -0
- package/src/cli-entry.ts +77 -0
- package/src/data-dir.ts +88 -0
- package/src/env.ts +265 -0
- package/src/error-message.ts +22 -0
- package/src/index.ts +63 -0
- package/src/journal-io.ts +82 -0
- package/src/journal-replay.ts +432 -0
- package/src/kill-chain.ts +265 -0
- package/src/logger.ts +105 -0
- package/src/logs/stderr-rotation.ts +166 -0
- package/src/nesting-guard.ts +140 -0
- package/src/node-executor.ts +272 -0
- package/src/paths.ts +48 -0
- package/src/port-contract.ts +117 -0
- package/src/protocol/contract-types.ts +378 -0
- package/src/protocol/engine-protocol.ts +81 -0
- package/src/protocol/error-codes.ts +179 -0
- package/src/protocol/frames.ts +145 -0
- package/src/protocol/index.ts +12 -0
- package/src/protocol/methods.ts +229 -0
- package/src/protocol/reverse-channels.ts +274 -0
- package/src/protocol/schema.ts +154 -0
- package/src/relay-env.ts +60 -0
- package/src/schema-emulation.ts +192 -0
- package/src/spawn.ts +246 -0
- package/src/ui-channels.ts +219 -0
- package/src/ui-types.ts +84 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, CancelParams, CancelResult, DisposeParams, DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostPermissionParams, HostPermissionResult, HostPoolResolvedParams, HostRoundLifecycleParams, HostStreamDeltaParams, InitializeParams, InitializeResult, InteractParams, ListModelsParams, ListModelsResult, PROTOCOL_METHODS, PingParams, PingResult, ProbeParams, ProtocolMethod, ProtocolParamsMap, ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_NAMES, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReadParams, ReverseChannel, ReverseChannelParamsMap, ReverseChannelResultMap, ReverseRequestTimeoutClass, RoundFailedPhase, RoundIdlePhase, RoundKeyedByRecord, RoundKeyedByRun, RoundLifecyclePhase, RoundSettledPhase, RunChatParams, RunContextParams, RunParams, RunResult, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, ValidateModelParams, ValidateModelResult, errorResponseFrameSchema, isHostRoundLifecycleParams, isHostStreamDeltaParams, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, successResponseFrameSchema } from './protocol/index.cjs';
|
|
2
|
+
export { A as AnyFrame, E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from './error-codes-DHco5-i_.cjs';
|
|
3
|
+
export { A as AgentCallOpts, a as AgentEvent, b as AgentFailureKind, c as AgentOutcome, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, E as EngineCapabilities, h as EngineHandleData, I as InteractAction, i as InteractResult, j as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, k as ResumeAnchor, S as SessionView, T as ToolCall, l as ToolCallEntry, m as ToolCallResult, n as Turn, W as WorktreeHandle } from './contract-types-sSlgppBC.cjs';
|
|
4
|
+
export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.cjs';
|
|
5
|
+
export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.cjs';
|
|
6
|
+
export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.cjs';
|
|
7
|
+
export { DEFAULT_KILL_GRACE_MS, DEFAULT_NATIVE_INTERRUPT_GRACE_MS, HOST_TIMEOUT_ABORT_REASON, KillChainOptions, KillableChild, abortWithFallback, killChain, synthesizeTimeoutOutcome } from './kill-chain.cjs';
|
|
8
|
+
export { ReplayRecordView, aggregateUsage, createReplayRecord, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.cjs';
|
|
9
|
+
export { XYZ_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } from './data-dir.cjs';
|
|
10
|
+
export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg } from './paths.cjs';
|
|
11
|
+
export { UiMethod, UiRequest, UiRequestHandler, UiResponse } from './ui-types.cjs';
|
|
12
|
+
export { ChannelHandler, ExtensionUiRequestLike, ParsedChannel, UiChannelRegistry, createUiChannelRegistry, parseChannel } from './ui-channels.cjs';
|
|
13
|
+
export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, EngineRelayEnv, buildEngineChildEnv, buildOutboundChildEnv } from './env.cjs';
|
|
14
|
+
export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, pumpNdjsonLines, spawnEngineChild } from './spawn.cjs';
|
|
15
|
+
export { ENGINE_NODE_ENV, EngineNodeHostKind, EngineNodeLaunch, EngineNodeLaunchOptions, hostKindOf, probeNodeExecutor, resetEngineNodeProbeCache, resolveEngineNodeLaunch } from './node-executor.cjs';
|
|
16
|
+
export { CleanupResult, DEFAULT_STDERR_KEEP_DAYS, DEFAULT_STDERR_MAX_BYTES, StderrRotationParams, cleanupSiblingStderrLogs, cleanupStaleStderrLogs, isPidAlive, rotateStderrLogIfNeeded, stderrLogPathFor, stderrLogPidOf, stderrRotationParams } from './logs/stderr-rotation.cjs';
|
|
17
|
+
export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive, readRelayForwardEnv } from './relay-env.cjs';
|
|
18
|
+
export { toErrorMessage } from './error-message.cjs';
|
|
19
|
+
export { BestEffortLevel, bestEffort } from './best-effort.cjs';
|
|
20
|
+
export { replayJournal } from './journal-io.cjs';
|
|
21
|
+
export { EngineAgentCallOpts, EngineCtxModel, EngineHandle, EnginePort, EngineRunResult, EngineStream, RunContext, parseCtxModel } from './port-contract.cjs';
|
|
22
|
+
export { CliProtocolServerSink, RunEngineCliEntryOptions, runEngineCliEntry } from './cli-entry.cjs';
|
|
23
|
+
import 'node:child_process';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, CancelParams, CancelResult, DisposeParams, DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostPermissionParams, HostPermissionResult, HostPoolResolvedParams, HostRoundLifecycleParams, HostStreamDeltaParams, InitializeParams, InitializeResult, InteractParams, ListModelsParams, ListModelsResult, PROTOCOL_METHODS, PingParams, PingResult, ProbeParams, ProtocolMethod, ProtocolParamsMap, ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_NAMES, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReadParams, ReverseChannel, ReverseChannelParamsMap, ReverseChannelResultMap, ReverseRequestTimeoutClass, RoundFailedPhase, RoundIdlePhase, RoundKeyedByRecord, RoundKeyedByRun, RoundLifecyclePhase, RoundSettledPhase, RunChatParams, RunContextParams, RunParams, RunResult, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, ValidateModelParams, ValidateModelResult, errorResponseFrameSchema, isHostRoundLifecycleParams, isHostStreamDeltaParams, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, successResponseFrameSchema } from './protocol/index.js';
|
|
2
|
+
export { A as AnyFrame, E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from './error-codes-Dhss2Kmk.js';
|
|
3
|
+
export { A as AgentCallOpts, a as AgentEvent, b as AgentFailureKind, c as AgentOutcome, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, E as EngineCapabilities, h as EngineHandleData, I as InteractAction, i as InteractResult, j as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, k as ResumeAnchor, S as SessionView, T as ToolCall, l as ToolCallEntry, m as ToolCallResult, n as Turn, W as WorktreeHandle } from './contract-types-sSlgppBC.js';
|
|
4
|
+
export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.js';
|
|
5
|
+
export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.js';
|
|
6
|
+
export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.js';
|
|
7
|
+
export { DEFAULT_KILL_GRACE_MS, DEFAULT_NATIVE_INTERRUPT_GRACE_MS, HOST_TIMEOUT_ABORT_REASON, KillChainOptions, KillableChild, abortWithFallback, killChain, synthesizeTimeoutOutcome } from './kill-chain.js';
|
|
8
|
+
export { ReplayRecordView, aggregateUsage, createReplayRecord, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.js';
|
|
9
|
+
export { XYZ_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } from './data-dir.js';
|
|
10
|
+
export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg } from './paths.js';
|
|
11
|
+
export { UiMethod, UiRequest, UiRequestHandler, UiResponse } from './ui-types.js';
|
|
12
|
+
export { ChannelHandler, ExtensionUiRequestLike, ParsedChannel, UiChannelRegistry, createUiChannelRegistry, parseChannel } from './ui-channels.js';
|
|
13
|
+
export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, EngineRelayEnv, buildEngineChildEnv, buildOutboundChildEnv } from './env.js';
|
|
14
|
+
export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, pumpNdjsonLines, spawnEngineChild } from './spawn.js';
|
|
15
|
+
export { ENGINE_NODE_ENV, EngineNodeHostKind, EngineNodeLaunch, EngineNodeLaunchOptions, hostKindOf, probeNodeExecutor, resetEngineNodeProbeCache, resolveEngineNodeLaunch } from './node-executor.js';
|
|
16
|
+
export { CleanupResult, DEFAULT_STDERR_KEEP_DAYS, DEFAULT_STDERR_MAX_BYTES, StderrRotationParams, cleanupSiblingStderrLogs, cleanupStaleStderrLogs, isPidAlive, rotateStderrLogIfNeeded, stderrLogPathFor, stderrLogPidOf, stderrRotationParams } from './logs/stderr-rotation.js';
|
|
17
|
+
export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive, readRelayForwardEnv } from './relay-env.js';
|
|
18
|
+
export { toErrorMessage } from './error-message.js';
|
|
19
|
+
export { BestEffortLevel, bestEffort } from './best-effort.js';
|
|
20
|
+
export { replayJournal } from './journal-io.js';
|
|
21
|
+
export { EngineAgentCallOpts, EngineCtxModel, EngineHandle, EnginePort, EngineRunResult, EngineStream, RunContext, parseCtxModel } from './port-contract.js';
|
|
22
|
+
export { CliProtocolServerSink, RunEngineCliEntryOptions, runEngineCliEntry } from './cli-entry.js';
|
|
23
|
+
import 'node:child_process';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bestEffort
|
|
3
|
+
} from "./chunk-EJMF63R5.js";
|
|
4
|
+
import {
|
|
5
|
+
replayJournal
|
|
6
|
+
} from "./chunk-RDH3ZOV6.js";
|
|
7
|
+
import {
|
|
8
|
+
parseCtxModel
|
|
9
|
+
} from "./chunk-RULLX6C6.js";
|
|
10
|
+
import {
|
|
11
|
+
runEngineCliEntry
|
|
12
|
+
} from "./chunk-N3RL6OVM.js";
|
|
13
|
+
import {
|
|
14
|
+
resolveEngineDir,
|
|
15
|
+
resolveEnginesRoot,
|
|
16
|
+
resolveJournalPath,
|
|
17
|
+
resolvePoolDir,
|
|
18
|
+
sanitizeSeg
|
|
19
|
+
} from "./chunk-OPMY4G4M.js";
|
|
20
|
+
import "./chunk-2DIMPZCQ.js";
|
|
21
|
+
import {
|
|
22
|
+
createUiChannelRegistry,
|
|
23
|
+
parseChannel
|
|
24
|
+
} from "./chunk-7I4XGL5J.js";
|
|
25
|
+
import {
|
|
26
|
+
ENGINE_ENV_DENY_LIST,
|
|
27
|
+
ENGINE_ENV_L0_INFRA_KEYS,
|
|
28
|
+
ENGINE_ENV_PREFIXES,
|
|
29
|
+
buildEngineChildEnv,
|
|
30
|
+
buildOutboundChildEnv
|
|
31
|
+
} from "./chunk-ZXEAW25V.js";
|
|
32
|
+
import {
|
|
33
|
+
DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
|
|
34
|
+
ENGINE_HOST_REQUEST_TIMEOUT_ENV,
|
|
35
|
+
armEngineSelfDestruct,
|
|
36
|
+
pumpNdjsonLines,
|
|
37
|
+
spawnEngineChild
|
|
38
|
+
} from "./chunk-3K2P2CM2.js";
|
|
39
|
+
import {
|
|
40
|
+
ENGINE_NODE_ENV,
|
|
41
|
+
hostKindOf,
|
|
42
|
+
probeNodeExecutor,
|
|
43
|
+
resetEngineNodeProbeCache,
|
|
44
|
+
resolveEngineNodeLaunch
|
|
45
|
+
} from "./chunk-ZOFFJNJD.js";
|
|
46
|
+
import {
|
|
47
|
+
DEFAULT_STDERR_KEEP_DAYS,
|
|
48
|
+
DEFAULT_STDERR_MAX_BYTES,
|
|
49
|
+
cleanupSiblingStderrLogs,
|
|
50
|
+
cleanupStaleStderrLogs,
|
|
51
|
+
isPidAlive,
|
|
52
|
+
rotateStderrLogIfNeeded,
|
|
53
|
+
stderrLogPathFor,
|
|
54
|
+
stderrLogPidOf,
|
|
55
|
+
stderrRotationParams
|
|
56
|
+
} from "./chunk-HYES77BR.js";
|
|
57
|
+
import {
|
|
58
|
+
RELAY_ENV_NODE,
|
|
59
|
+
RELAY_ENV_RECORD_ID,
|
|
60
|
+
RELAY_ENV_SCRIPT,
|
|
61
|
+
RELAY_ENV_SESSION_ID,
|
|
62
|
+
RELAY_ENV_SOCKET,
|
|
63
|
+
RELAY_EXIT_CODES,
|
|
64
|
+
RELAY_PROTOCOL_VERSION,
|
|
65
|
+
isRelayActive,
|
|
66
|
+
readRelayForwardEnv
|
|
67
|
+
} from "./chunk-DSQ7JQKM.js";
|
|
68
|
+
import {
|
|
69
|
+
ENGINE_PROTOCOL_SCHEMAS,
|
|
70
|
+
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
71
|
+
PROTOCOL_METHODS,
|
|
72
|
+
REVERSE_CHANNELS,
|
|
73
|
+
REVERSE_CHANNEL_NAMES,
|
|
74
|
+
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
75
|
+
errorResponseFrameSchema,
|
|
76
|
+
isHostRoundLifecycleParams,
|
|
77
|
+
isHostStreamDeltaParams,
|
|
78
|
+
isNotificationFrame,
|
|
79
|
+
isRequestFrame,
|
|
80
|
+
isResponseFrame,
|
|
81
|
+
isReverseRequestFrame,
|
|
82
|
+
notificationFrameSchema,
|
|
83
|
+
protocolErrorSchema,
|
|
84
|
+
requestFrameSchema,
|
|
85
|
+
reverseRequestFrameSchema,
|
|
86
|
+
successResponseFrameSchema
|
|
87
|
+
} from "./chunk-YFSN3D5N.js";
|
|
88
|
+
import {
|
|
89
|
+
SCHEMA_EMULATION_TAIL_CHARS,
|
|
90
|
+
buildSchemaEmulationSegment,
|
|
91
|
+
extractAndValidateStructuredOutput
|
|
92
|
+
} from "./chunk-X24SFZYW.js";
|
|
93
|
+
import {
|
|
94
|
+
ExecutionNestingContext,
|
|
95
|
+
NESTED_SPAWN_ENV,
|
|
96
|
+
NestedSpawnRejectedError,
|
|
97
|
+
assertNotNestedSpawn,
|
|
98
|
+
buildNestedSpawnEnv
|
|
99
|
+
} from "./chunk-365AUV6N.js";
|
|
100
|
+
import {
|
|
101
|
+
DEFAULT_KILL_GRACE_MS,
|
|
102
|
+
DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
|
|
103
|
+
HOST_TIMEOUT_ABORT_REASON,
|
|
104
|
+
abortWithFallback,
|
|
105
|
+
killChain,
|
|
106
|
+
synthesizeTimeoutOutcome
|
|
107
|
+
} from "./chunk-LEOBWKRM.js";
|
|
108
|
+
import {
|
|
109
|
+
toErrorMessage
|
|
110
|
+
} from "./chunk-PYO3YR7W.js";
|
|
111
|
+
import {
|
|
112
|
+
CANCEL_SETTLE_GRACE_MS,
|
|
113
|
+
CRASH_REBUILD_BACKOFF_MS,
|
|
114
|
+
CRASH_REBUILD_MAX_ATTEMPTS,
|
|
115
|
+
ENGINE_ERROR_CODE_PREFIX,
|
|
116
|
+
ENGINE_EVENT_COALESCE_DEFAULT,
|
|
117
|
+
ENGINE_EVENT_COALESCE_ENV,
|
|
118
|
+
ENGINE_PROTOCOL_ERROR_CODES,
|
|
119
|
+
ENGINE_PROTOCOL_VERSION,
|
|
120
|
+
ENGINE_TIMEOUT_RECOVERY,
|
|
121
|
+
EngineSdkError,
|
|
122
|
+
HANDSHAKE_TIMEOUT_MS,
|
|
123
|
+
REVERSE_REQUEST_TIMEOUT_MS,
|
|
124
|
+
STDERR_TAIL_CHARS,
|
|
125
|
+
STDOUT_TAIL_ECHO_CHARS,
|
|
126
|
+
SUPPORTED_PROTOCOL_RANGE,
|
|
127
|
+
assertChatConversationSupported,
|
|
128
|
+
engineConversationUnsupportedError,
|
|
129
|
+
engineProtocolMismatchError,
|
|
130
|
+
engineTimeoutDetail,
|
|
131
|
+
isEngineErrorPassthroughCode,
|
|
132
|
+
isEngineProtocolErrorCode,
|
|
133
|
+
isProtocolVersionCompatible,
|
|
134
|
+
schemaEmulationFailedDetail
|
|
135
|
+
} from "./chunk-PPEPBVCC.js";
|
|
136
|
+
import {
|
|
137
|
+
aggregateUsage,
|
|
138
|
+
createReplayRecord,
|
|
139
|
+
eventsToSessionView,
|
|
140
|
+
sessionIdFromHandle,
|
|
141
|
+
toReplayedTurn,
|
|
142
|
+
updateFromEvent
|
|
143
|
+
} from "./chunk-A75XDJIC.js";
|
|
144
|
+
import {
|
|
145
|
+
XYZ_DATA_DIR_ENV,
|
|
146
|
+
resetDataDirWarnForTests,
|
|
147
|
+
resolveEngineDataDir
|
|
148
|
+
} from "./chunk-GT6YLLN4.js";
|
|
149
|
+
import {
|
|
150
|
+
configureLoggerSink,
|
|
151
|
+
getLogger,
|
|
152
|
+
resetLoggerSinkForTests
|
|
153
|
+
} from "./chunk-75QEMUGV.js";
|
|
154
|
+
import "./chunk-JSBRDJBE.js";
|
|
155
|
+
export {
|
|
156
|
+
CANCEL_SETTLE_GRACE_MS,
|
|
157
|
+
CRASH_REBUILD_BACKOFF_MS,
|
|
158
|
+
CRASH_REBUILD_MAX_ATTEMPTS,
|
|
159
|
+
DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
|
|
160
|
+
DEFAULT_KILL_GRACE_MS,
|
|
161
|
+
DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
|
|
162
|
+
DEFAULT_STDERR_KEEP_DAYS,
|
|
163
|
+
DEFAULT_STDERR_MAX_BYTES,
|
|
164
|
+
ENGINE_ENV_DENY_LIST,
|
|
165
|
+
ENGINE_ENV_L0_INFRA_KEYS,
|
|
166
|
+
ENGINE_ENV_PREFIXES,
|
|
167
|
+
ENGINE_ERROR_CODE_PREFIX,
|
|
168
|
+
ENGINE_EVENT_COALESCE_DEFAULT,
|
|
169
|
+
ENGINE_EVENT_COALESCE_ENV,
|
|
170
|
+
ENGINE_HOST_REQUEST_TIMEOUT_ENV,
|
|
171
|
+
ENGINE_NODE_ENV,
|
|
172
|
+
ENGINE_PROTOCOL_ERROR_CODES,
|
|
173
|
+
ENGINE_PROTOCOL_SCHEMAS,
|
|
174
|
+
ENGINE_PROTOCOL_VERSION,
|
|
175
|
+
ENGINE_TIMEOUT_RECOVERY,
|
|
176
|
+
EngineSdkError,
|
|
177
|
+
ExecutionNestingContext,
|
|
178
|
+
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
179
|
+
HANDSHAKE_TIMEOUT_MS,
|
|
180
|
+
HOST_TIMEOUT_ABORT_REASON,
|
|
181
|
+
NESTED_SPAWN_ENV,
|
|
182
|
+
NestedSpawnRejectedError,
|
|
183
|
+
PROTOCOL_METHODS,
|
|
184
|
+
RELAY_ENV_NODE,
|
|
185
|
+
RELAY_ENV_RECORD_ID,
|
|
186
|
+
RELAY_ENV_SCRIPT,
|
|
187
|
+
RELAY_ENV_SESSION_ID,
|
|
188
|
+
RELAY_ENV_SOCKET,
|
|
189
|
+
RELAY_EXIT_CODES,
|
|
190
|
+
RELAY_PROTOCOL_VERSION,
|
|
191
|
+
REVERSE_CHANNELS,
|
|
192
|
+
REVERSE_CHANNEL_NAMES,
|
|
193
|
+
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
194
|
+
REVERSE_REQUEST_TIMEOUT_MS,
|
|
195
|
+
SCHEMA_EMULATION_TAIL_CHARS,
|
|
196
|
+
STDERR_TAIL_CHARS,
|
|
197
|
+
STDOUT_TAIL_ECHO_CHARS,
|
|
198
|
+
SUPPORTED_PROTOCOL_RANGE,
|
|
199
|
+
XYZ_DATA_DIR_ENV,
|
|
200
|
+
abortWithFallback,
|
|
201
|
+
aggregateUsage,
|
|
202
|
+
armEngineSelfDestruct,
|
|
203
|
+
assertChatConversationSupported,
|
|
204
|
+
assertNotNestedSpawn,
|
|
205
|
+
bestEffort,
|
|
206
|
+
buildEngineChildEnv,
|
|
207
|
+
buildNestedSpawnEnv,
|
|
208
|
+
buildOutboundChildEnv,
|
|
209
|
+
buildSchemaEmulationSegment,
|
|
210
|
+
cleanupSiblingStderrLogs,
|
|
211
|
+
cleanupStaleStderrLogs,
|
|
212
|
+
configureLoggerSink,
|
|
213
|
+
createReplayRecord,
|
|
214
|
+
createUiChannelRegistry,
|
|
215
|
+
engineConversationUnsupportedError,
|
|
216
|
+
engineProtocolMismatchError,
|
|
217
|
+
engineTimeoutDetail,
|
|
218
|
+
errorResponseFrameSchema,
|
|
219
|
+
eventsToSessionView,
|
|
220
|
+
extractAndValidateStructuredOutput,
|
|
221
|
+
getLogger,
|
|
222
|
+
hostKindOf,
|
|
223
|
+
isEngineErrorPassthroughCode,
|
|
224
|
+
isEngineProtocolErrorCode,
|
|
225
|
+
isHostRoundLifecycleParams,
|
|
226
|
+
isHostStreamDeltaParams,
|
|
227
|
+
isNotificationFrame,
|
|
228
|
+
isPidAlive,
|
|
229
|
+
isProtocolVersionCompatible,
|
|
230
|
+
isRelayActive,
|
|
231
|
+
isRequestFrame,
|
|
232
|
+
isResponseFrame,
|
|
233
|
+
isReverseRequestFrame,
|
|
234
|
+
killChain,
|
|
235
|
+
notificationFrameSchema,
|
|
236
|
+
parseChannel,
|
|
237
|
+
parseCtxModel,
|
|
238
|
+
probeNodeExecutor,
|
|
239
|
+
protocolErrorSchema,
|
|
240
|
+
pumpNdjsonLines,
|
|
241
|
+
readRelayForwardEnv,
|
|
242
|
+
replayJournal,
|
|
243
|
+
requestFrameSchema,
|
|
244
|
+
resetDataDirWarnForTests,
|
|
245
|
+
resetEngineNodeProbeCache,
|
|
246
|
+
resetLoggerSinkForTests,
|
|
247
|
+
resolveEngineDataDir,
|
|
248
|
+
resolveEngineDir,
|
|
249
|
+
resolveEngineNodeLaunch,
|
|
250
|
+
resolveEnginesRoot,
|
|
251
|
+
resolveJournalPath,
|
|
252
|
+
resolvePoolDir,
|
|
253
|
+
reverseRequestFrameSchema,
|
|
254
|
+
rotateStderrLogIfNeeded,
|
|
255
|
+
runEngineCliEntry,
|
|
256
|
+
sanitizeSeg,
|
|
257
|
+
schemaEmulationFailedDetail,
|
|
258
|
+
sessionIdFromHandle,
|
|
259
|
+
spawnEngineChild,
|
|
260
|
+
stderrLogPathFor,
|
|
261
|
+
stderrLogPidOf,
|
|
262
|
+
stderrRotationParams,
|
|
263
|
+
successResponseFrameSchema,
|
|
264
|
+
synthesizeTimeoutOutcome,
|
|
265
|
+
toErrorMessage,
|
|
266
|
+
toReplayedTurn,
|
|
267
|
+
updateFromEvent
|
|
268
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/journal-io.ts
|
|
21
|
+
var journal_io_exports = {};
|
|
22
|
+
__export(journal_io_exports, {
|
|
23
|
+
replayJournal: () => replayJournal
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(journal_io_exports);
|
|
26
|
+
var import_node_fs = require("fs");
|
|
27
|
+
function replayJournal(path) {
|
|
28
|
+
let raw;
|
|
29
|
+
try {
|
|
30
|
+
raw = (0, import_node_fs.readFileSync)(path, "utf8");
|
|
31
|
+
} catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const lines = [];
|
|
35
|
+
for (const row of raw.split("\n")) {
|
|
36
|
+
const trimmed = row.trim();
|
|
37
|
+
if (trimmed === "") continue;
|
|
38
|
+
const parsed = parseLine(trimmed);
|
|
39
|
+
if (parsed !== void 0) lines.push(parsed);
|
|
40
|
+
}
|
|
41
|
+
lines.sort((a, b) => a.seq - b.seq);
|
|
42
|
+
return lines.map((l) => l.event);
|
|
43
|
+
}
|
|
44
|
+
function parseLine(trimmed) {
|
|
45
|
+
let parsed;
|
|
46
|
+
try {
|
|
47
|
+
parsed = JSON.parse(trimmed);
|
|
48
|
+
} catch {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
52
|
+
const rec = parsed;
|
|
53
|
+
const event = rec.event;
|
|
54
|
+
if (rec.v !== 1 || typeof rec.ts !== "number" || typeof rec.seq !== "number") return void 0;
|
|
55
|
+
if (typeof event !== "object" || event === null || typeof event.type !== "string") {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
v: 1,
|
|
60
|
+
ts: rec.ts,
|
|
61
|
+
taskId: typeof rec.taskId === "string" ? rec.taskId : "",
|
|
62
|
+
engineId: typeof rec.engineId === "string" ? rec.engineId : "",
|
|
63
|
+
seq: rec.seq,
|
|
64
|
+
event
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
replayJournal
|
|
70
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as AgentEvent } from './contract-types-sSlgppBC.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 重放 journal:读取路径下全部事件,重放即得 AgentEvent 流(read 第②级)。
|
|
5
|
+
*
|
|
6
|
+
* - 文件不存在 → [](降级链语义:②级不可达不算错误,调用方落 ③级);
|
|
7
|
+
* - 损坏行跳过(追加写产物末行可能截断;跳过优于整体失败——设计 C5「三级都不 throw」);
|
|
8
|
+
* - 按 seq 稳定排序后返回(重放顺序权威是 seq,不依赖文件行序的隐式保证,§3.3.6)。
|
|
9
|
+
*/
|
|
10
|
+
declare function replayJournal(path: string): AgentEvent[];
|
|
11
|
+
|
|
12
|
+
export { replayJournal };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { a as AgentEvent } from './contract-types-sSlgppBC.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 重放 journal:读取路径下全部事件,重放即得 AgentEvent 流(read 第②级)。
|
|
5
|
+
*
|
|
6
|
+
* - 文件不存在 → [](降级链语义:②级不可达不算错误,调用方落 ③级);
|
|
7
|
+
* - 损坏行跳过(追加写产物末行可能截断;跳过优于整体失败——设计 C5「三级都不 throw」);
|
|
8
|
+
* - 按 seq 稳定排序后返回(重放顺序权威是 seq,不依赖文件行序的隐式保证,§3.3.6)。
|
|
9
|
+
*/
|
|
10
|
+
declare function replayJournal(path: string): AgentEvent[];
|
|
11
|
+
|
|
12
|
+
export { replayJournal };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/journal-replay.ts
|
|
21
|
+
var journal_replay_exports = {};
|
|
22
|
+
__export(journal_replay_exports, {
|
|
23
|
+
aggregateUsage: () => aggregateUsage,
|
|
24
|
+
createReplayRecord: () => createReplayRecord,
|
|
25
|
+
eventsToSessionView: () => eventsToSessionView,
|
|
26
|
+
sessionIdFromHandle: () => sessionIdFromHandle,
|
|
27
|
+
toReplayedTurn: () => toReplayedTurn,
|
|
28
|
+
updateFromEvent: () => updateFromEvent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(journal_replay_exports);
|
|
31
|
+
function sumUsageField(a, b) {
|
|
32
|
+
return (a ?? 0) + (b ?? 0);
|
|
33
|
+
}
|
|
34
|
+
function usageFromNext(next) {
|
|
35
|
+
return {
|
|
36
|
+
input: next.input ?? 0,
|
|
37
|
+
output: next.output ?? 0,
|
|
38
|
+
cacheRead: next.cacheRead ?? 0,
|
|
39
|
+
cacheWrite: next.cacheWrite ?? 0,
|
|
40
|
+
cost: next.cost
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function addUsage(prev, next) {
|
|
44
|
+
if (prev === void 0) return usageFromNext(next);
|
|
45
|
+
return {
|
|
46
|
+
input: sumUsageField(prev.input, next.input),
|
|
47
|
+
output: sumUsageField(prev.output, next.output),
|
|
48
|
+
cacheRead: sumUsageField(prev.cacheRead, next.cacheRead),
|
|
49
|
+
cacheWrite: sumUsageField(prev.cacheWrite, next.cacheWrite),
|
|
50
|
+
cost: sumUsageField(prev.cost, next.cost)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function emptyTurn() {
|
|
54
|
+
return { text: "", thinking: "", toolCalls: [], usageDelta: void 0, closed: false };
|
|
55
|
+
}
|
|
56
|
+
function createReplayRecord() {
|
|
57
|
+
return {
|
|
58
|
+
// turns[] 初始化为 [空 turn]——第一个 turn 从创建即存在,
|
|
59
|
+
// updateFromEvent 直接往 turns[last] 累积,无需「无 turn」分支判断。
|
|
60
|
+
turns: [emptyTurn()],
|
|
61
|
+
turnCount: 0,
|
|
62
|
+
totalTokens: 0,
|
|
63
|
+
lastError: void 0
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function currentTurn(record) {
|
|
67
|
+
const last = record.turns[record.turns.length - 1];
|
|
68
|
+
if (last !== void 0 && !last.closed) return last;
|
|
69
|
+
const fresh = emptyTurn();
|
|
70
|
+
record.turns.push(fresh);
|
|
71
|
+
return fresh;
|
|
72
|
+
}
|
|
73
|
+
function findRunningToolCall(record, toolName) {
|
|
74
|
+
for (let t = record.turns.length - 1; t >= 0; t--) {
|
|
75
|
+
const turn = record.turns[t];
|
|
76
|
+
if (turn === void 0) continue;
|
|
77
|
+
for (let i = turn.toolCalls.length - 1; i >= 0; i--) {
|
|
78
|
+
const tc = turn.toolCalls[i];
|
|
79
|
+
if (tc?._status === "running" && tc.toolName === toolName) {
|
|
80
|
+
return [turn, i];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
var runningToolIndex = /* @__PURE__ */ new WeakMap();
|
|
87
|
+
function indexToolStart(record, turn, toolName) {
|
|
88
|
+
let byName = runningToolIndex.get(record);
|
|
89
|
+
if (byName === void 0) {
|
|
90
|
+
byName = /* @__PURE__ */ new Map();
|
|
91
|
+
runningToolIndex.set(record, byName);
|
|
92
|
+
}
|
|
93
|
+
const arr = byName.get(toolName);
|
|
94
|
+
if (arr === void 0) {
|
|
95
|
+
byName.set(toolName, [{ turn, idx: turn.toolCalls.length - 1 }]);
|
|
96
|
+
} else {
|
|
97
|
+
arr.push({ turn, idx: turn.toolCalls.length - 1 });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function applyTextDelta(record, event) {
|
|
101
|
+
currentTurn(record).text += event.delta;
|
|
102
|
+
}
|
|
103
|
+
function applyThinkingDelta(record, event) {
|
|
104
|
+
currentTurn(record).thinking += event.delta;
|
|
105
|
+
}
|
|
106
|
+
function applyToolStart(record, event) {
|
|
107
|
+
const tc = {
|
|
108
|
+
toolName: event.toolName,
|
|
109
|
+
args: event.args,
|
|
110
|
+
result: void 0,
|
|
111
|
+
isError: false,
|
|
112
|
+
_status: "running",
|
|
113
|
+
startedTs: Date.now()
|
|
114
|
+
};
|
|
115
|
+
const turn = currentTurn(record);
|
|
116
|
+
turn.toolCalls.push(tc);
|
|
117
|
+
indexToolStart(record, turn, event.toolName);
|
|
118
|
+
}
|
|
119
|
+
function matchRunningToolCall(record, toolName) {
|
|
120
|
+
const byName = runningToolIndex.get(record);
|
|
121
|
+
const arr = byName?.get(toolName);
|
|
122
|
+
if (arr !== void 0 && arr.length > 0) {
|
|
123
|
+
const item = arr[arr.length - 1];
|
|
124
|
+
arr.pop();
|
|
125
|
+
const tc = item.turn.toolCalls[item.idx];
|
|
126
|
+
if (tc !== void 0 && tc._status === "running") {
|
|
127
|
+
return [item.turn, item.idx];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return findRunningToolCall(record, toolName);
|
|
131
|
+
}
|
|
132
|
+
function applyToolEnd(record, event) {
|
|
133
|
+
const matched = matchRunningToolCall(record, event.toolName);
|
|
134
|
+
if (matched !== void 0) {
|
|
135
|
+
const [turn, i] = matched;
|
|
136
|
+
const tc = turn.toolCalls[i];
|
|
137
|
+
tc.args = event.args ?? tc.args;
|
|
138
|
+
tc.result = event.result;
|
|
139
|
+
tc.isError = event.isError ?? false;
|
|
140
|
+
tc._status = event.isError ? "failed" : "done";
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
currentTurn(record).toolCalls.push({
|
|
144
|
+
toolName: event.toolName,
|
|
145
|
+
args: event.args,
|
|
146
|
+
result: event.result,
|
|
147
|
+
isError: event.isError ?? false,
|
|
148
|
+
_status: event.isError ? "failed" : "done",
|
|
149
|
+
startedTs: Date.now()
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function applyTurnEnd(record) {
|
|
153
|
+
const turn = currentTurn(record);
|
|
154
|
+
turn.closed = true;
|
|
155
|
+
turn.closedTs = Date.now();
|
|
156
|
+
record.turnCount += 1;
|
|
157
|
+
record.lastError = void 0;
|
|
158
|
+
}
|
|
159
|
+
function applyMessageEnd(record, event) {
|
|
160
|
+
if (event.usage) {
|
|
161
|
+
const turn = currentTurn(record);
|
|
162
|
+
turn.usageDelta = addUsage(turn.usageDelta, event.usage);
|
|
163
|
+
record.totalTokens += (event.usage.input ?? 0) + (event.usage.output ?? 0) + (event.usage.cacheRead ?? 0) + (event.usage.cacheWrite ?? 0);
|
|
164
|
+
}
|
|
165
|
+
if (event.error) {
|
|
166
|
+
record.lastError = event.error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function applyErrorEvent(record, event) {
|
|
170
|
+
record.lastError = event.message;
|
|
171
|
+
}
|
|
172
|
+
function updateFromEvent(record, event) {
|
|
173
|
+
switch (event.type) {
|
|
174
|
+
// ── text / thinking:流式累积进当前 turn ──
|
|
175
|
+
case "text_delta":
|
|
176
|
+
return applyTextDelta(record, event);
|
|
177
|
+
case "thinking_delta":
|
|
178
|
+
return applyThinkingDelta(record, event);
|
|
179
|
+
// ── tool_start/end:push 进 currentTurn().toolCalls(含完整 result)──
|
|
180
|
+
case "tool_start":
|
|
181
|
+
return applyToolStart(record, event);
|
|
182
|
+
case "tool_end":
|
|
183
|
+
return applyToolEnd(record, event);
|
|
184
|
+
// ── turn_end:闭合当前 turn ──
|
|
185
|
+
case "turn_end":
|
|
186
|
+
return applyTurnEnd(record);
|
|
187
|
+
// ── message_end:usage 增量累加 + totalTokens 累加 ──
|
|
188
|
+
case "message_end":
|
|
189
|
+
return applyMessageEnd(record, event);
|
|
190
|
+
// ── error:存 record.lastError ──
|
|
191
|
+
case "error":
|
|
192
|
+
return applyErrorEvent(record, event);
|
|
193
|
+
// ── compaction:不产生数据(不变)──
|
|
194
|
+
case "compaction":
|
|
195
|
+
return;
|
|
196
|
+
default: {
|
|
197
|
+
const _exhaustive = event;
|
|
198
|
+
return _exhaustive;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function toExportedToolCall(tc) {
|
|
203
|
+
return {
|
|
204
|
+
toolName: tc.toolName,
|
|
205
|
+
...tc.args !== void 0 ? { args: tc.args } : {},
|
|
206
|
+
...tc.result !== void 0 ? { result: tc.result } : {},
|
|
207
|
+
...tc.isError !== void 0 ? { isError: tc.isError } : {}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function toReplayedTurn(turn) {
|
|
211
|
+
return {
|
|
212
|
+
text: turn.text,
|
|
213
|
+
thinking: turn.thinking,
|
|
214
|
+
toolCalls: turn.toolCalls.map(toExportedToolCall),
|
|
215
|
+
closed: true
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function aggregateUsage(turns) {
|
|
219
|
+
let acc;
|
|
220
|
+
for (const turn of turns) {
|
|
221
|
+
const d = turn.usageDelta;
|
|
222
|
+
if (!d) continue;
|
|
223
|
+
if (!acc) acc = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, total: 0 };
|
|
224
|
+
acc.input += d.input;
|
|
225
|
+
acc.output += d.output;
|
|
226
|
+
acc.cacheRead += d.cacheRead;
|
|
227
|
+
acc.cacheWrite += d.cacheWrite;
|
|
228
|
+
acc.cost += d.cost ?? 0;
|
|
229
|
+
}
|
|
230
|
+
if (acc) acc.total = acc.input + acc.output + acc.cacheRead + acc.cacheWrite;
|
|
231
|
+
return acc;
|
|
232
|
+
}
|
|
233
|
+
function eventsToSessionView(events, engineId, sessionId) {
|
|
234
|
+
const record = createReplayRecord();
|
|
235
|
+
for (const ev of events) updateFromEvent(record, ev);
|
|
236
|
+
return {
|
|
237
|
+
engineId,
|
|
238
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
239
|
+
turns: record.turns.map(toReplayedTurn),
|
|
240
|
+
usage: aggregateUsage(record.turns),
|
|
241
|
+
source: "journal"
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function sessionIdFromHandle(handle) {
|
|
245
|
+
const v = handle.sessionRef["sessionId"];
|
|
246
|
+
return typeof v === "string" ? v : void 0;
|
|
247
|
+
}
|
|
248
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
249
|
+
0 && (module.exports = {
|
|
250
|
+
aggregateUsage,
|
|
251
|
+
createReplayRecord,
|
|
252
|
+
eventsToSessionView,
|
|
253
|
+
sessionIdFromHandle,
|
|
254
|
+
toReplayedTurn,
|
|
255
|
+
updateFromEvent
|
|
256
|
+
});
|