@botbotgo/agent-harness 0.0.475 → 0.0.476
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/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,179 +1 @@
|
|
|
1
|
-
|
|
2
|
-
"harness",
|
|
3
|
-
"harness-minimal-upstream",
|
|
4
|
-
"raw-langchain-v1",
|
|
5
|
-
"raw-deepagent",
|
|
6
|
-
]);
|
|
7
|
-
export const DEFAULT_UPSTREAM_BENCHMARK_WORKLOAD = "tool";
|
|
8
|
-
export const DEFAULT_UPSTREAM_BENCHMARK_SCENARIOS = Object.freeze([
|
|
9
|
-
"normal",
|
|
10
|
-
"complex",
|
|
11
|
-
"extreme",
|
|
12
|
-
]);
|
|
13
|
-
function average(values) {
|
|
14
|
-
return Number((values.reduce((sum, value) => sum + value, 0) / values.length).toFixed(2));
|
|
15
|
-
}
|
|
16
|
-
function median(values) {
|
|
17
|
-
const sorted = [...values].sort((left, right) => left - right);
|
|
18
|
-
const middle = Math.floor(sorted.length / 2);
|
|
19
|
-
if (sorted.length % 2 === 0) {
|
|
20
|
-
return Number((((sorted[middle - 1] ?? 0) + (sorted[middle] ?? 0)) / 2).toFixed(2));
|
|
21
|
-
}
|
|
22
|
-
return Number((sorted[middle] ?? 0).toFixed(2));
|
|
23
|
-
}
|
|
24
|
-
function percentile(values, quantile) {
|
|
25
|
-
const sorted = [...values].sort((left, right) => left - right);
|
|
26
|
-
const index = Math.max(0, Math.min(sorted.length - 1, Math.ceil(sorted.length * quantile) - 1));
|
|
27
|
-
return Number(sorted[index].toFixed(2));
|
|
28
|
-
}
|
|
29
|
-
function averageOrNull(values) {
|
|
30
|
-
return values.length > 0 ? average(values) : null;
|
|
31
|
-
}
|
|
32
|
-
function medianOrNull(values) {
|
|
33
|
-
return values.length > 0 ? median(values) : null;
|
|
34
|
-
}
|
|
35
|
-
function percentileOrNull(values, quantile) {
|
|
36
|
-
return values.length > 0 ? percentile(values, quantile) : null;
|
|
37
|
-
}
|
|
38
|
-
function trimValues(values, trimFraction) {
|
|
39
|
-
if (values.length <= 2) {
|
|
40
|
-
return [...values];
|
|
41
|
-
}
|
|
42
|
-
const sorted = [...values].sort((left, right) => left - right);
|
|
43
|
-
const trimCount = Math.min(Math.floor(sorted.length * trimFraction), Math.floor((sorted.length - 1) / 2));
|
|
44
|
-
return sorted.slice(trimCount, sorted.length - trimCount);
|
|
45
|
-
}
|
|
46
|
-
function trimmedAverageOrNull(values, trimFraction) {
|
|
47
|
-
return values.length > 0 ? average(trimValues(values, trimFraction)) : null;
|
|
48
|
-
}
|
|
49
|
-
export function resolveUpstreamBenchmarkPaths(rawValue) {
|
|
50
|
-
if (!rawValue) {
|
|
51
|
-
return [...DEFAULT_UPSTREAM_BENCHMARK_PATHS];
|
|
52
|
-
}
|
|
53
|
-
const parsed = rawValue
|
|
54
|
-
.split(",")
|
|
55
|
-
.map((value) => value.trim().toLowerCase())
|
|
56
|
-
.filter((value) => value === "harness" ||
|
|
57
|
-
value === "harness-minimal-upstream" ||
|
|
58
|
-
value === "raw-langchain-v1" ||
|
|
59
|
-
value === "raw-deepagent");
|
|
60
|
-
return parsed.length > 0 ? parsed : [...DEFAULT_UPSTREAM_BENCHMARK_PATHS];
|
|
61
|
-
}
|
|
62
|
-
export function resolveUpstreamBenchmarkWorkload(rawValue) {
|
|
63
|
-
return rawValue?.trim().toLowerCase() === "no-tool" ? "no-tool" : DEFAULT_UPSTREAM_BENCHMARK_WORKLOAD;
|
|
64
|
-
}
|
|
65
|
-
export function resolveUpstreamBenchmarkScenarios(rawValue) {
|
|
66
|
-
if (!rawValue) {
|
|
67
|
-
return [...DEFAULT_UPSTREAM_BENCHMARK_SCENARIOS];
|
|
68
|
-
}
|
|
69
|
-
const parsed = rawValue
|
|
70
|
-
.split(",")
|
|
71
|
-
.map((value) => value.trim().toLowerCase())
|
|
72
|
-
.filter((value) => value === "normal" || value === "complex" || value === "extreme");
|
|
73
|
-
return parsed.length > 0 ? parsed : [...DEFAULT_UPSTREAM_BENCHMARK_SCENARIOS];
|
|
74
|
-
}
|
|
75
|
-
export function extractLastMatchingToken(output, prefixes) {
|
|
76
|
-
const normalized = output.replace(/\s+/g, " ").trim();
|
|
77
|
-
let matched = "";
|
|
78
|
-
for (const prefix of prefixes) {
|
|
79
|
-
let searchIndex = normalized.indexOf(prefix);
|
|
80
|
-
while (searchIndex >= 0) {
|
|
81
|
-
const suffix = normalized.slice(searchIndex);
|
|
82
|
-
const token = (suffix.split(/\s/)[0] ?? suffix).trim();
|
|
83
|
-
if (token.length > 0) {
|
|
84
|
-
matched = token;
|
|
85
|
-
}
|
|
86
|
-
searchIndex = normalized.indexOf(prefix, searchIndex + prefix.length);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return matched || normalized;
|
|
90
|
-
}
|
|
91
|
-
export function aggregateUpstreamBenchmarkRuns(providerLabel, model, scenario, path, runs) {
|
|
92
|
-
const successfulRuns = runs.filter((run) => run.status === "completed");
|
|
93
|
-
const totalValues = successfulRuns.map((run) => run.totalMs);
|
|
94
|
-
const firstTokenValues = successfulRuns
|
|
95
|
-
.map((run) => run.firstTokenMs)
|
|
96
|
-
.filter((value) => value !== null);
|
|
97
|
-
return {
|
|
98
|
-
providerLabel,
|
|
99
|
-
model,
|
|
100
|
-
scenario,
|
|
101
|
-
path,
|
|
102
|
-
repetitions: runs.length,
|
|
103
|
-
successCount: successfulRuns.length,
|
|
104
|
-
failureCount: runs.length - successfulRuns.length,
|
|
105
|
-
avgTotalMs: averageOrNull(totalValues),
|
|
106
|
-
trimmedAvgTotalMs: trimmedAverageOrNull(totalValues, 0.1),
|
|
107
|
-
medianTotalMs: medianOrNull(totalValues),
|
|
108
|
-
p95TotalMs: percentileOrNull(totalValues, 0.95),
|
|
109
|
-
avgFirstTokenMs: averageOrNull(firstTokenValues),
|
|
110
|
-
trimmedAvgFirstTokenMs: trimmedAverageOrNull(firstTokenValues, 0.1),
|
|
111
|
-
medianFirstTokenMs: medianOrNull(firstTokenValues),
|
|
112
|
-
p95FirstTokenMs: percentileOrNull(firstTokenValues, 0.95),
|
|
113
|
-
avgSetupMs: averageOrNull(successfulRuns.map((run) => run.setupMs).filter((value) => value !== null)),
|
|
114
|
-
avgFirstToolMs: averageOrNull(successfulRuns.map((run) => run.firstToolMs).filter((value) => value !== null)),
|
|
115
|
-
avgLastToolMs: averageOrNull(successfulRuns.map((run) => run.lastToolMs).filter((value) => value !== null)),
|
|
116
|
-
avgFinalOutputMs: averageOrNull(successfulRuns.map((run) => run.finalOutputMs).filter((value) => value !== null)),
|
|
117
|
-
avgCleanupMs: averageOrNull(successfulRuns.map((run) => run.cleanupMs).filter((value) => value !== null)),
|
|
118
|
-
avgOutputLength: averageOrNull(successfulRuns.map((run) => run.outputLength)),
|
|
119
|
-
avgNormalizedOutputLength: averageOrNull(successfulRuns.map((run) => run.normalizedOutputLength)),
|
|
120
|
-
avgToolCallCount: averageOrNull(successfulRuns.map((run) => run.toolCallCount)),
|
|
121
|
-
exactOutputMatchCount: successfulRuns.filter((run) => run.exactOutputMatch).length,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
export function withUpstreamBenchmarkCleanup(summary, cleanupMs) {
|
|
125
|
-
return {
|
|
126
|
-
...summary,
|
|
127
|
-
cleanupMs,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
export function summarizeUpstreamBenchmarkPhases(checkpoints) {
|
|
131
|
-
let previousAtMs = 0;
|
|
132
|
-
const durations = {};
|
|
133
|
-
for (const checkpoint of checkpoints) {
|
|
134
|
-
const key = `${checkpoint.label}Ms`;
|
|
135
|
-
if (checkpoint.atMs === null) {
|
|
136
|
-
durations[key] = null;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
durations[key] = Number((checkpoint.atMs - previousAtMs).toFixed(2));
|
|
140
|
-
previousAtMs = checkpoint.atMs;
|
|
141
|
-
}
|
|
142
|
-
return durations;
|
|
143
|
-
}
|
|
144
|
-
export function selectUpstreamBenchmarkRunsByTemperature(runs, temperature) {
|
|
145
|
-
return runs.filter((run) => (temperature === "cold" ? run.runNumber === 1 : run.runNumber > 1));
|
|
146
|
-
}
|
|
147
|
-
export function summarizeUpstreamBenchmarkDurations(values) {
|
|
148
|
-
return {
|
|
149
|
-
count: values.length,
|
|
150
|
-
totalMs: Number(values.reduce((sum, value) => sum + value, 0).toFixed(2)),
|
|
151
|
-
avgMs: values.length > 0 ? average(values) : null,
|
|
152
|
-
maxMs: values.length > 0 ? Number(Math.max(...values).toFixed(2)) : null,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function computeOverhead(candidate, baseline) {
|
|
156
|
-
if (candidate === null || baseline === null) {
|
|
157
|
-
return { delta: null, pct: null };
|
|
158
|
-
}
|
|
159
|
-
const delta = Number((candidate - baseline).toFixed(2));
|
|
160
|
-
if (baseline === 0) {
|
|
161
|
-
return { delta, pct: null };
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
delta,
|
|
165
|
-
pct: Number((((candidate - baseline) / baseline) * 100).toFixed(2)),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
export function compareUpstreamBenchmarkPaths(baseline, candidate) {
|
|
169
|
-
const total = computeOverhead(candidate.avgTotalMs, baseline.avgTotalMs);
|
|
170
|
-
const firstToken = computeOverhead(candidate.avgFirstTokenMs, baseline.avgFirstTokenMs);
|
|
171
|
-
return {
|
|
172
|
-
baselinePath: baseline.path,
|
|
173
|
-
candidatePath: candidate.path,
|
|
174
|
-
avgTotalMsDelta: total.delta,
|
|
175
|
-
avgTotalMsOverheadPct: total.pct,
|
|
176
|
-
avgFirstTokenMsDelta: firstToken.delta,
|
|
177
|
-
avgFirstTokenMsOverheadPct: firstToken.pct,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
1
|
+
const m=Object.freeze(["harness","harness-minimal-upstream","raw-langchain-v1","raw-deepagent"]),d="tool",p=Object.freeze(["normal","complex","extreme"]);function c(t){return Number((t.reduce((n,e)=>n+e,0)/t.length).toFixed(2))}function x(t){const n=[...t].sort((l,a)=>l-a),e=Math.floor(n.length/2);return n.length%2===0?Number((((n[e-1]??0)+(n[e]??0))/2).toFixed(2)):Number((n[e]??0).toFixed(2))}function T(t,n){const e=[...t].sort((a,o)=>a-o),l=Math.max(0,Math.min(e.length-1,Math.ceil(e.length*n)-1));return Number(e[l].toFixed(2))}function s(t){return t.length>0?c(t):null}function h(t){return t.length>0?x(t):null}function g(t,n){return t.length>0?T(t,n):null}function k(t,n){if(t.length<=2)return[...t];const e=[...t].sort((a,o)=>a-o),l=Math.min(Math.floor(e.length*n),Math.floor((e.length-1)/2));return e.slice(l,e.length-l)}function f(t,n){return t.length>0?c(k(t,n)):null}function F(t){if(!t)return[...m];const n=t.split(",").map(e=>e.trim().toLowerCase()).filter(e=>e==="harness"||e==="harness-minimal-upstream"||e==="raw-langchain-v1"||e==="raw-deepagent");return n.length>0?n:[...m]}function O(t){return t?.trim().toLowerCase()==="no-tool"?"no-tool":d}function N(t){if(!t)return[...p];const n=t.split(",").map(e=>e.trim().toLowerCase()).filter(e=>e==="normal"||e==="complex"||e==="extreme");return n.length>0?n:[...p]}function C(t,n){const e=t.replace(/\s+/g," ").trim();let l="";for(const a of n){let o=e.indexOf(a);for(;o>=0;){const u=e.slice(o),i=(u.split(/\s/)[0]??u).trim();i.length>0&&(l=i),o=e.indexOf(a,o+a.length)}}return l||e}function v(t,n,e,l,a){const o=a.filter(r=>r.status==="completed"),u=o.map(r=>r.totalMs),i=o.map(r=>r.firstTokenMs).filter(r=>r!==null);return{providerLabel:t,model:n,scenario:e,path:l,repetitions:a.length,successCount:o.length,failureCount:a.length-o.length,avgTotalMs:s(u),trimmedAvgTotalMs:f(u,.1),medianTotalMs:h(u),p95TotalMs:g(u,.95),avgFirstTokenMs:s(i),trimmedAvgFirstTokenMs:f(i,.1),medianFirstTokenMs:h(i),p95FirstTokenMs:g(i,.95),avgSetupMs:s(o.map(r=>r.setupMs).filter(r=>r!==null)),avgFirstToolMs:s(o.map(r=>r.firstToolMs).filter(r=>r!==null)),avgLastToolMs:s(o.map(r=>r.lastToolMs).filter(r=>r!==null)),avgFinalOutputMs:s(o.map(r=>r.finalOutputMs).filter(r=>r!==null)),avgCleanupMs:s(o.map(r=>r.cleanupMs).filter(r=>r!==null)),avgOutputLength:s(o.map(r=>r.outputLength)),avgNormalizedOutputLength:s(o.map(r=>r.normalizedOutputLength)),avgToolCallCount:s(o.map(r=>r.toolCallCount)),exactOutputMatchCount:o.filter(r=>r.exactOutputMatch).length}}function A(t,n){return{...t,cleanupMs:n}}function U(t){let n=0;const e={};for(const l of t){const a=`${l.label}Ms`;if(l.atMs===null){e[a]=null;continue}e[a]=Number((l.atMs-n).toFixed(2)),n=l.atMs}return e}function B(t,n){return t.filter(e=>n==="cold"?e.runNumber===1:e.runNumber>1)}function L(t){return{count:t.length,totalMs:Number(t.reduce((n,e)=>n+e,0).toFixed(2)),avgMs:t.length>0?c(t):null,maxMs:t.length>0?Number(Math.max(...t).toFixed(2)):null}}function M(t,n){if(t===null||n===null)return{delta:null,pct:null};const e=Number((t-n).toFixed(2));return n===0?{delta:e,pct:null}:{delta:e,pct:Number(((t-n)/n*100).toFixed(2))}}function P(t,n){const e=M(n.avgTotalMs,t.avgTotalMs),l=M(n.avgFirstTokenMs,t.avgFirstTokenMs);return{baselinePath:t.path,candidatePath:n.path,avgTotalMsDelta:e.delta,avgTotalMsOverheadPct:e.pct,avgFirstTokenMsDelta:l.delta,avgFirstTokenMsOverheadPct:l.pct}}export{m as DEFAULT_UPSTREAM_BENCHMARK_PATHS,p as DEFAULT_UPSTREAM_BENCHMARK_SCENARIOS,d as DEFAULT_UPSTREAM_BENCHMARK_WORKLOAD,v as aggregateUpstreamBenchmarkRuns,P as compareUpstreamBenchmarkPaths,C as extractLastMatchingToken,F as resolveUpstreamBenchmarkPaths,N as resolveUpstreamBenchmarkScenarios,O as resolveUpstreamBenchmarkWorkload,B as selectUpstreamBenchmarkRunsByTemperature,L as summarizeUpstreamBenchmarkDurations,U as summarizeUpstreamBenchmarkPhases,A as withUpstreamBenchmarkCleanup};
|
|
@@ -1,244 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const agentId = typeof summary.currentAgentId === "string"
|
|
27
|
-
? summary.currentAgentId
|
|
28
|
-
: typeof summary.entryAgentId === "string"
|
|
29
|
-
? summary.entryAgentId
|
|
30
|
-
: "unknown";
|
|
31
|
-
const state = typeof summary.currentState === "string" ? summary.currentState : "unknown";
|
|
32
|
-
const messageCount = typeof summary.messageCount === "number" ? ` messages=${summary.messageCount}` : "";
|
|
33
|
-
const title = typeof summary.title === "string" ? ` title=${summary.title}` : "";
|
|
34
|
-
const snippet = typeof summary.snippet === "string" ? ` snippet=${summary.snippet}` : "";
|
|
35
|
-
return `${sessionId} agent=${agentId} state=${state}${messageCount}${title}${snippet}`;
|
|
36
|
-
}).join("\n") + "\n";
|
|
37
|
-
}
|
|
38
|
-
function renderRequestTraceItems(traceItems) {
|
|
39
|
-
if (traceItems.length === 0) {
|
|
40
|
-
return "No trace items recorded.\n";
|
|
41
|
-
}
|
|
42
|
-
return traceItems.map((item) => {
|
|
43
|
-
const surfaceItem = isObject(item.surfaceItem) ? item.surfaceItem : {};
|
|
44
|
-
const kind = typeof surfaceItem.kind === "string" ? surfaceItem.kind : "unknown";
|
|
45
|
-
const name = typeof surfaceItem.id === "string" ? surfaceItem.id : typeof surfaceItem.name === "string" ? surfaceItem.name : "unknown";
|
|
46
|
-
const agentId = typeof surfaceItem.agentId === "string" ? ` agent=${surfaceItem.agentId}` : "";
|
|
47
|
-
const status = typeof item.status === "string" ? ` status=${item.status}` : "";
|
|
48
|
-
return `${kind}:${name}${agentId}${status}`;
|
|
49
|
-
}).join("\n") + "\n";
|
|
50
|
-
}
|
|
51
|
-
export async function runInteractiveChatLoop(input) {
|
|
52
|
-
let activeAgentId = input.activeAgentId;
|
|
53
|
-
let activeSessionId = input.activeSessionId;
|
|
54
|
-
let latestRequestId;
|
|
55
|
-
try {
|
|
56
|
-
for await (const raw of iterateChatLines(input.lineReader, () => renderChatPromptLine({
|
|
57
|
-
agentId: activeAgentId,
|
|
58
|
-
sessionId: activeSessionId,
|
|
59
|
-
requestId: latestRequestId,
|
|
60
|
-
color: input.useColor,
|
|
61
|
-
}))) {
|
|
62
|
-
const trimmed = raw.trim();
|
|
63
|
-
if (!trimmed) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const chatCommand = normalizeChatCommand(trimmed);
|
|
67
|
-
if (!chatCommand) {
|
|
68
|
-
const streamed = await streamChatMessage({
|
|
69
|
-
client: input.client,
|
|
70
|
-
stdout: input.stdout,
|
|
71
|
-
stdoutStream: input.stdoutStream,
|
|
72
|
-
stderr: input.stderr,
|
|
73
|
-
stderrStream: input.stderrStream,
|
|
74
|
-
agentId: activeAgentId,
|
|
75
|
-
sessionId: activeSessionId,
|
|
76
|
-
message: trimmed,
|
|
77
|
-
modelInfo: input.workspaceModelInfo,
|
|
78
|
-
requestEvents: input.requestEvents,
|
|
79
|
-
liveRequestTree: input.requestEvents && input.chatIsTty,
|
|
80
|
-
colorRequestTree: input.useColor,
|
|
81
|
-
showToolResults: input.requestEvents,
|
|
82
|
-
showRunningState: false,
|
|
83
|
-
});
|
|
84
|
-
activeSessionId = streamed.sessionId;
|
|
85
|
-
latestRequestId = streamed.requestId;
|
|
86
|
-
activeAgentId = streamed.agentId ?? activeAgentId;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if (chatCommand.name === "exit" || chatCommand.name === "quit") {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
if (chatCommand.name === "help") {
|
|
93
|
-
input.stdout(renderChatHelp());
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (chatCommand.name === "context") {
|
|
97
|
-
input.stdout(renderChatContext({
|
|
98
|
-
agentId: activeAgentId,
|
|
99
|
-
sessionId: activeSessionId,
|
|
100
|
-
requestId: latestRequestId,
|
|
101
|
-
}));
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
if (chatCommand.name === "new") {
|
|
105
|
-
activeSessionId = undefined;
|
|
106
|
-
latestRequestId = undefined;
|
|
107
|
-
input.stdout(renderChatContext({
|
|
108
|
-
agentId: activeAgentId,
|
|
109
|
-
sessionId: activeSessionId,
|
|
110
|
-
requestId: latestRequestId,
|
|
111
|
-
}));
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (chatCommand.name === "agent") {
|
|
115
|
-
if (!chatCommand.arg) {
|
|
116
|
-
input.stdout(activeAgentId ? `${activeAgentId}\n` : "No active agent override.\n");
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
activeAgentId = chatCommand.arg;
|
|
120
|
-
input.stdout(`agent=${activeAgentId}\n`);
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (chatCommand.name === "session") {
|
|
124
|
-
input.stdout(activeSessionId ? `${activeSessionId}\n` : "No active session.\n");
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (chatCommand.name === "request") {
|
|
128
|
-
if (!chatCommand.arg) {
|
|
129
|
-
input.stdout(latestRequestId ? `${latestRequestId}\n` : "No active request.\n");
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
const selected = await input.client.getRequest(chatCommand.arg);
|
|
133
|
-
if (!selected) {
|
|
134
|
-
input.stdout(`Request not found: ${chatCommand.arg}\n`);
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
latestRequestId = selected.requestId;
|
|
138
|
-
activeSessionId = selected.sessionId;
|
|
139
|
-
activeAgentId = selected.agentId;
|
|
140
|
-
input.stdout(`request=${latestRequestId} session=${activeSessionId}\n`);
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (chatCommand.name === "sessions") {
|
|
144
|
-
const summaries = await input.client.listSessionSummaries(input.agentFilter ? { agentId: input.agentFilter } : undefined);
|
|
145
|
-
input.stdout(renderSessionSummaries(summaries));
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (chatCommand.name === "requests") {
|
|
149
|
-
const requests = await input.client.listRequests(activeSessionId
|
|
150
|
-
? { sessionId: activeSessionId }
|
|
151
|
-
: activeAgentId
|
|
152
|
-
? { agentId: activeAgentId }
|
|
153
|
-
: undefined);
|
|
154
|
-
input.stdout(renderRequestList(requests));
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (chatCommand.name === "resume") {
|
|
158
|
-
if (!chatCommand.arg) {
|
|
159
|
-
input.stdout("Usage: /resume <sessionId>\n");
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
const session = await input.client.getSession(chatCommand.arg);
|
|
163
|
-
if (!session) {
|
|
164
|
-
input.stdout(`Session not found: ${chatCommand.arg}\n`);
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
activeSessionId = chatCommand.arg;
|
|
168
|
-
latestRequestId = session.latestRequestId;
|
|
169
|
-
activeAgentId = session.entryAgentId ?? session.currentAgentId ?? activeAgentId;
|
|
170
|
-
input.stdout(`session=${activeSessionId}\n`);
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (chatCommand.name === "cancel") {
|
|
174
|
-
if (!latestRequestId) {
|
|
175
|
-
input.stdout("No active request.\n");
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const result = await input.client.cancelRequest({
|
|
179
|
-
requestId: latestRequestId,
|
|
180
|
-
reason: "Cancelled from chat CLI",
|
|
181
|
-
});
|
|
182
|
-
activeSessionId = result.sessionId;
|
|
183
|
-
latestRequestId = result.requestId;
|
|
184
|
-
input.stdout(`${result.state}: ${result.output}\n`);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (chatCommand.name === "approvals") {
|
|
188
|
-
const approvals = await input.client.listApprovals(activeSessionId ? { sessionId: activeSessionId, status: "pending" } : { status: "pending" });
|
|
189
|
-
input.stdout(renderApprovalList(approvals));
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
if ((chatCommand.name === "approve" || chatCommand.name === "reject") && chatCommand.arg) {
|
|
193
|
-
const result = await input.client.resolveApproval({
|
|
194
|
-
approvalId: chatCommand.arg,
|
|
195
|
-
decision: chatCommand.name === "approve" ? "approve" : "reject",
|
|
196
|
-
...(activeSessionId ? { sessionId: activeSessionId } : {}),
|
|
197
|
-
});
|
|
198
|
-
activeSessionId = result.sessionId;
|
|
199
|
-
latestRequestId = result.requestId;
|
|
200
|
-
input.stdout(`${result.state}: ${result.output}\n`);
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (chatCommand.name === "events") {
|
|
204
|
-
if (!activeSessionId || !latestRequestId) {
|
|
205
|
-
input.stdout("No active request.\n");
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
const events = await input.client.listRequestEvents({
|
|
209
|
-
sessionId: activeSessionId,
|
|
210
|
-
requestId: latestRequestId,
|
|
211
|
-
});
|
|
212
|
-
input.stdout(renderRequestEvents(events));
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (chatCommand.name === "trace") {
|
|
216
|
-
if (!activeSessionId || !latestRequestId) {
|
|
217
|
-
input.stdout("No active request.\n");
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
const traceItems = await input.client.listRequestTraceItems({
|
|
221
|
-
sessionId: activeSessionId,
|
|
222
|
-
requestId: latestRequestId,
|
|
223
|
-
});
|
|
224
|
-
input.stdout(renderRequestTraceItems(traceItems));
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (chatCommand.name === "health") {
|
|
228
|
-
const health = await input.client.getHealth();
|
|
229
|
-
input.stdout(renderHealthSnapshot(health, input.workspacePath));
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (chatCommand.name === "overview") {
|
|
233
|
-
const overview = await input.client.getOperatorOverview({ limit: 5 });
|
|
234
|
-
input.stdout(renderOperatorOverview(overview, input.workspacePath));
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
input.stdout("Unknown chat command. Use /help.\n");
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
finally {
|
|
241
|
-
input.lineReader.close();
|
|
242
|
-
}
|
|
243
|
-
return { activeAgentId, activeSessionId, latestRequestId };
|
|
244
|
-
}
|
|
1
|
+
import{streamChatMessage as c}from"./chat-stream.js";import{renderChatContext as d,renderChatHelp as u,renderChatPromptLine as f,renderRequestEvents as l}from"./chat-ui.js";import{normalizeChatCommand as g}from"./chat-workspace.js";import{renderApprovalList as I,renderHealthSnapshot as m,renderOperatorOverview as q,renderRequestList as v}from"./runtime-output.js";async function*w(e,t){e.setPrompt(t()),e.prompt();for await(const n of e)yield n,e.setPrompt(t()),e.prompt()}function $(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function R(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function h(e){return e.length===0?`No sessions found.
|
|
2
|
+
`:e.map(t=>{const n=typeof t.sessionId=="string"?t.sessionId:"unknown",r=typeof t.currentAgentId=="string"?t.currentAgentId:typeof t.entryAgentId=="string"?t.entryAgentId:"unknown",i=typeof t.currentState=="string"?t.currentState:"unknown",a=typeof t.messageCount=="number"?` messages=${t.messageCount}`:"",o=typeof t.title=="string"?` title=${t.title}`:"",s=typeof t.snippet=="string"?` snippet=${t.snippet}`:"";return`${n} agent=${r} state=${i}${a}${o}${s}`}).join(`
|
|
3
|
+
`)+`
|
|
4
|
+
`}function C(e){return e.length===0?`No trace items recorded.
|
|
5
|
+
`:e.map(t=>{const n=$(t.surfaceItem)?t.surfaceItem:{},r=typeof n.kind=="string"?n.kind:"unknown",i=typeof n.id=="string"?n.id:typeof n.name=="string"?n.name:"unknown",a=typeof n.agentId=="string"?` agent=${n.agentId}`:"",o=typeof t.status=="string"?` status=${t.status}`:"";return`${r}:${i}${a}${o}`}).join(`
|
|
6
|
+
`)+`
|
|
7
|
+
`}async function y(e){let t=e.activeAgentId,n=e.activeSessionId,r;try{for await(const i of w(e.lineReader,()=>f({agentId:t,sessionId:n,requestId:r,color:e.useColor}))){const a=i.trim();if(!a)continue;const o=g(a);if(!o){const s=await c({client:e.client,stdout:e.stdout,stdoutStream:e.stdoutStream,stderr:e.stderr,stderrStream:e.stderrStream,agentId:t,sessionId:n,message:a,modelInfo:e.workspaceModelInfo,requestEvents:e.requestEvents,liveRequestTree:e.requestEvents&&e.chatIsTty,colorRequestTree:e.useColor,showToolResults:e.requestEvents,showRunningState:!1});n=s.sessionId,r=s.requestId,t=s.agentId??t;continue}if(o.name==="exit"||o.name==="quit")break;if(o.name==="help"){e.stdout(u());continue}if(o.name==="context"){e.stdout(d({agentId:t,sessionId:n,requestId:r}));continue}if(o.name==="new"){n=void 0,r=void 0,e.stdout(d({agentId:t,sessionId:n,requestId:r}));continue}if(o.name==="agent"){if(!o.arg){e.stdout(t?`${t}
|
|
8
|
+
`:`No active agent override.
|
|
9
|
+
`);continue}t=o.arg,e.stdout(`agent=${t}
|
|
10
|
+
`);continue}if(o.name==="session"){e.stdout(n?`${n}
|
|
11
|
+
`:`No active session.
|
|
12
|
+
`);continue}if(o.name==="request"){if(!o.arg){e.stdout(r?`${r}
|
|
13
|
+
`:`No active request.
|
|
14
|
+
`);continue}const s=await e.client.getRequest(o.arg);if(!s){e.stdout(`Request not found: ${o.arg}
|
|
15
|
+
`);continue}r=s.requestId,n=s.sessionId,t=s.agentId,e.stdout(`request=${r} session=${n}
|
|
16
|
+
`);continue}if(o.name==="sessions"){const s=await e.client.listSessionSummaries(e.agentFilter?{agentId:e.agentFilter}:void 0);e.stdout(h(s));continue}if(o.name==="requests"){const s=await e.client.listRequests(n?{sessionId:n}:t?{agentId:t}:void 0);e.stdout(v(s));continue}if(o.name==="resume"){if(!o.arg){e.stdout(`Usage: /resume <sessionId>
|
|
17
|
+
`);continue}const s=await e.client.getSession(o.arg);if(!s){e.stdout(`Session not found: ${o.arg}
|
|
18
|
+
`);continue}n=o.arg,r=s.latestRequestId,t=s.entryAgentId??s.currentAgentId??t,e.stdout(`session=${n}
|
|
19
|
+
`);continue}if(o.name==="cancel"){if(!r){e.stdout(`No active request.
|
|
20
|
+
`);continue}const s=await e.client.cancelRequest({requestId:r,reason:"Cancelled from chat CLI"});n=s.sessionId,r=s.requestId,e.stdout(`${s.state}: ${s.output}
|
|
21
|
+
`);continue}if(o.name==="approvals"){const s=await e.client.listApprovals(n?{sessionId:n,status:"pending"}:{status:"pending"});e.stdout(I(s));continue}if((o.name==="approve"||o.name==="reject")&&o.arg){const s=await e.client.resolveApproval({approvalId:o.arg,decision:o.name==="approve"?"approve":"reject",...n?{sessionId:n}:{}});n=s.sessionId,r=s.requestId,e.stdout(`${s.state}: ${s.output}
|
|
22
|
+
`);continue}if(o.name==="events"){if(!n||!r){e.stdout(`No active request.
|
|
23
|
+
`);continue}const s=await e.client.listRequestEvents({sessionId:n,requestId:r});e.stdout(l(s));continue}if(o.name==="trace"){if(!n||!r){e.stdout(`No active request.
|
|
24
|
+
`);continue}const s=await e.client.listRequestTraceItems({sessionId:n,requestId:r});e.stdout(C(s));continue}if(o.name==="health"){const s=await e.client.getHealth();e.stdout(m(s,e.workspacePath));continue}if(o.name==="overview"){const s=await e.client.getOperatorOverview({limit:5});e.stdout(q(s,e.workspacePath));continue}e.stdout(`Unknown chat command. Use /help.
|
|
25
|
+
`)}}finally{e.lineReader.close()}return{activeAgentId:t,activeSessionId:n,latestRequestId:r}}export{y as runInteractiveChatLoop};
|
|
@@ -1,100 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
return markdownToConsole(renderChatRuntimeFailure(text, modelInfo));
|
|
8
|
-
}
|
|
9
|
-
export function renderChatRequestRunning(input) {
|
|
10
|
-
const parts = [
|
|
11
|
-
input.sessionId ? `session=${input.sessionId}` : undefined,
|
|
12
|
-
input.requestId ? `request=${input.requestId}` : undefined,
|
|
13
|
-
input.agentId ? `agent=${input.agentId}` : undefined,
|
|
14
|
-
"running: waiting for model output",
|
|
15
|
-
].filter((part) => typeof part === "string" && part.length > 0);
|
|
16
|
-
return `\n${parts.join(" ")}\n`;
|
|
17
|
-
}
|
|
18
|
-
export function summarizeChatToolResult(output, isError) {
|
|
19
|
-
return isError ? summarizeChatToolOutput(output, "failed") : summarizeChatToolOutput(output, "completed");
|
|
20
|
-
}
|
|
21
|
-
function summarizeChatToolOutput(output, fallback) {
|
|
22
|
-
if (typeof output === "string") {
|
|
23
|
-
const trimmed = output.trim();
|
|
24
|
-
return trimmed.length > 0 ? truncateChatToolPreview(trimmed, 240) : fallback;
|
|
25
|
-
}
|
|
26
|
-
if (typeof output === "number" || typeof output === "boolean") {
|
|
27
|
-
return String(output);
|
|
28
|
-
}
|
|
29
|
-
if (!output || typeof output !== "object") {
|
|
30
|
-
return fallback;
|
|
31
|
-
}
|
|
32
|
-
const typed = output;
|
|
33
|
-
const content = extractChatToolTextContent(output);
|
|
34
|
-
if (content && content.trim().length > 0) {
|
|
35
|
-
return truncateChatToolPreview(content.trim(), 240);
|
|
36
|
-
}
|
|
37
|
-
const summary = typeof typed.summary === "object" && typed.summary !== null ? typed.summary : undefined;
|
|
38
|
-
if (summary) {
|
|
39
|
-
return truncateChatToolPreview(JSON.stringify(summary, null, 2), 240);
|
|
40
|
-
}
|
|
41
|
-
return truncateChatToolPreview(JSON.stringify(output, null, 2), 240);
|
|
42
|
-
}
|
|
43
|
-
function truncateChatToolPreview(value, maxChars = 800) {
|
|
44
|
-
if (value.length <= maxChars) {
|
|
45
|
-
return value;
|
|
46
|
-
}
|
|
47
|
-
return `${value.slice(0, maxChars - 15)}\n...[truncated]`;
|
|
48
|
-
}
|
|
49
|
-
function extractChatToolTextContent(value) {
|
|
50
|
-
if (typeof value === "string") {
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(value)) {
|
|
54
|
-
return value
|
|
55
|
-
.map((item) => extractChatToolTextContent(item))
|
|
56
|
-
.filter((item) => item.trim().length > 0)
|
|
57
|
-
.join("\n");
|
|
58
|
-
}
|
|
59
|
-
if (!value || typeof value !== "object") {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
const typed = value;
|
|
63
|
-
if (typeof typed.text === "string") {
|
|
64
|
-
return typed.text;
|
|
65
|
-
}
|
|
66
|
-
if (typeof typed.content === "string") {
|
|
67
|
-
return typed.content;
|
|
68
|
-
}
|
|
69
|
-
if (typed.content !== undefined) {
|
|
70
|
-
const nestedContent = extractChatToolTextContent(typed.content);
|
|
71
|
-
if (nestedContent.trim().length > 0) {
|
|
72
|
-
return nestedContent;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (typed.kwargs !== undefined) {
|
|
76
|
-
const nestedKwargs = extractChatToolTextContent(typed.kwargs);
|
|
77
|
-
if (nestedKwargs.trim().length > 0) {
|
|
78
|
-
return nestedKwargs;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (typed.message !== undefined) {
|
|
82
|
-
const nestedMessage = extractChatToolTextContent(typed.message);
|
|
83
|
-
if (nestedMessage.trim().length > 0) {
|
|
84
|
-
return nestedMessage;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (typed.body !== undefined) {
|
|
88
|
-
const nestedBody = extractChatToolTextContent(typed.body);
|
|
89
|
-
if (nestedBody.trim().length > 0) {
|
|
90
|
-
return nestedBody;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (typed.answer !== undefined) {
|
|
94
|
-
const nestedAnswer = extractChatToolTextContent(typed.answer);
|
|
95
|
-
if (nestedAnswer.trim().length > 0) {
|
|
96
|
-
return nestedAnswer;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return "";
|
|
100
|
-
}
|
|
1
|
+
import{markdownToConsole as m}from"../projections/presentation.js";import{renderChatRuntimeFailure as u}from"./chat-workspace.js";function a(e){return e.replace(/\n$/,"").split(`
|
|
2
|
+
`).length}function l(e,n){return m(u(e,n))}function y(e){return`
|
|
3
|
+
${[e.sessionId?`session=${e.sessionId}`:void 0,e.requestId?`request=${e.requestId}`:void 0,e.agentId?`agent=${e.agentId}`:void 0,"running: waiting for model output"].filter(t=>typeof t=="string"&&t.length>0).join(" ")}
|
|
4
|
+
`}function h(e,n){return n?d(e,"failed"):d(e,"completed")}function d(e,n){if(typeof e=="string"){const f=e.trim();return f.length>0?i(f,240):n}if(typeof e=="number"||typeof e=="boolean")return String(e);if(!e||typeof e!="object")return n;const t=e,o=r(e);if(o&&o.trim().length>0)return i(o.trim(),240);const s=typeof t.summary=="object"&&t.summary!==null?t.summary:void 0;return i(JSON.stringify(s||e,null,2),240)}function i(e,n=800){return e.length<=n?e:`${e.slice(0,n-15)}
|
|
5
|
+
...[truncated]`}function r(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(t=>r(t)).filter(t=>t.trim().length>0).join(`
|
|
6
|
+
`);if(!e||typeof e!="object")return"";const n=e;if(typeof n.text=="string")return n.text;if(typeof n.content=="string")return n.content;if(n.content!==void 0){const t=r(n.content);if(t.trim().length>0)return t}if(n.kwargs!==void 0){const t=r(n.kwargs);if(t.trim().length>0)return t}if(n.message!==void 0){const t=r(n.message);if(t.trim().length>0)return t}if(n.body!==void 0){const t=r(n.body);if(t.trim().length>0)return t}if(n.answer!==void 0){const t=r(n.answer);if(t.trim().length>0)return t}return""}export{a as countRenderedLines,y as renderChatRequestRunning,l as renderChatTextChunk,h as summarizeChatToolResult};
|