@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,409 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createUpstreamTimelineReducer } from "../../../projections/upstream-events.js";
|
|
3
|
-
import { formatAgentName } from "../../../utils/agent-display.js";
|
|
4
|
-
import { getBindingBuiltinToolsConfig, getBindingMemorySources, getBindingPrimaryModel, getBindingPrimaryTools, getBindingSkills, getBindingSubagents, isDeepAgentBinding, } from "../../support/compiled-binding.js";
|
|
5
|
-
import { buildRuntimeGovernanceBundles } from "./governance.js";
|
|
6
|
-
import { filterBuiltinMiddlewareToolDescriptors } from "../../adapter/tool/builtin-middleware-tools.js";
|
|
7
|
-
import { buildSurfaceId, resolveSurfaceAction, resolveSurfaceDisplayName, } from "./surface-semantics.js";
|
|
8
|
-
function asObject(value) {
|
|
9
|
-
return typeof value === "object" && value !== null ? value : null;
|
|
10
|
-
}
|
|
11
|
-
function readStringArray(value) {
|
|
12
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.trim().length > 0) : [];
|
|
13
|
-
}
|
|
14
|
-
const MODEL_EXPOSED_BUILTIN_TOOL_NAMES = new Set([
|
|
15
|
-
"fetch_url",
|
|
16
|
-
"http_request",
|
|
17
|
-
"send_message",
|
|
18
|
-
"request_approval",
|
|
19
|
-
"schedule_task",
|
|
20
|
-
]);
|
|
21
|
-
function getBindingSkillNames(binding) {
|
|
22
|
-
if (!binding) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
return getBindingSkills(binding)
|
|
26
|
-
.map((skillPath) => readSkillMetadata(skillPath).name)
|
|
27
|
-
.filter((name) => typeof name === "string" && name.trim().length > 0);
|
|
28
|
-
}
|
|
29
|
-
function isTaskDelegationCompletionEvent(event) {
|
|
30
|
-
const eventName = typeof event.event === "string" ? event.event : "";
|
|
31
|
-
const name = typeof event.name === "string" ? event.name : "";
|
|
32
|
-
const runType = typeof event.run_type === "string" ? event.run_type : "";
|
|
33
|
-
return ((eventName === "on_tool_end" && name === "task")
|
|
34
|
-
|| (eventName === "on_chain_end" && runType === "tool" && name === "task"));
|
|
35
|
-
}
|
|
36
|
-
function isTaskDelegationFailureEvent(event) {
|
|
37
|
-
const eventName = typeof event.event === "string" ? event.event : "";
|
|
38
|
-
const name = typeof event.name === "string" ? event.name : "";
|
|
39
|
-
const runType = typeof event.run_type === "string" ? event.run_type : "";
|
|
40
|
-
return ((eventName === "on_tool_error" && name === "task")
|
|
41
|
-
|| (eventName === "on_chain_error" && runType === "tool" && name === "task"));
|
|
42
|
-
}
|
|
43
|
-
function isTaskDelegationTerminalEvent(event) {
|
|
44
|
-
return isTaskDelegationCompletionEvent(event) || isTaskDelegationFailureEvent(event);
|
|
45
|
-
}
|
|
46
|
-
function readTracingConfig(binding) {
|
|
47
|
-
const deepAgentTracing = asObject(binding.harnessRuntime?.deepagent?.passthrough)?.tracing;
|
|
48
|
-
const langchainTracing = asObject(binding.harnessRuntime?.langchain?.passthrough)?.tracing;
|
|
49
|
-
const legacyDeepAgentTracing = asObject(binding.deepAgentParams?.passthrough)?.tracing;
|
|
50
|
-
const legacyLangChainTracing = asObject(binding.langchainAgentParams?.passthrough)?.tracing;
|
|
51
|
-
return (asObject(langchainTracing) ??
|
|
52
|
-
asObject(deepAgentTracing) ??
|
|
53
|
-
asObject(legacyLangChainTracing) ??
|
|
54
|
-
asObject(legacyDeepAgentTracing) ??
|
|
55
|
-
null);
|
|
56
|
-
}
|
|
57
|
-
function buildRuntimeSnapshotTracing(binding, requestId) {
|
|
58
|
-
const tracing = readTracingConfig(binding);
|
|
59
|
-
const observability = asObject(binding.harnessRuntime.observability);
|
|
60
|
-
const runtimeTracing = asObject(observability?.tracing);
|
|
61
|
-
const exporters = Array.isArray(runtimeTracing?.exporters)
|
|
62
|
-
? runtimeTracing.exporters
|
|
63
|
-
.filter((item) => typeof item === "object" && item !== null && !Array.isArray(item))
|
|
64
|
-
.map((item) => ({
|
|
65
|
-
type: typeof item.type === "string" ? item.type : "custom",
|
|
66
|
-
...(typeof item.endpoint === "string" ? { endpoint: item.endpoint } : {}),
|
|
67
|
-
}))
|
|
68
|
-
: [];
|
|
69
|
-
if (!tracing) {
|
|
70
|
-
if (!runtimeTracing || requestId === undefined || runtimeTracing.enabled === false) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
enabled: true,
|
|
75
|
-
correlationId: requestId,
|
|
76
|
-
metadata: {
|
|
77
|
-
...(typeof runtimeTracing.propagation === "string" ? { propagation: runtimeTracing.propagation } : {}),
|
|
78
|
-
...(exporters.length > 0 ? { exporters } : {}),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
const enabled = tracing.enabled !== false;
|
|
83
|
-
if (!enabled || !requestId) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
const tags = readStringArray(tracing.tags);
|
|
87
|
-
const metadata = asObject(tracing.metadata);
|
|
88
|
-
return {
|
|
89
|
-
enabled: true,
|
|
90
|
-
correlationId: requestId,
|
|
91
|
-
...(tags.length > 0 ? { tags } : {}),
|
|
92
|
-
...((metadata && Object.keys(metadata).length > 0) || exporters.length > 0 || typeof runtimeTracing?.propagation === "string"
|
|
93
|
-
? {
|
|
94
|
-
metadata: {
|
|
95
|
-
...(metadata ? { ...metadata } : {}),
|
|
96
|
-
...(typeof runtimeTracing?.propagation === "string" ? { propagation: runtimeTracing.propagation } : {}),
|
|
97
|
-
...(exporters.length > 0 ? { exporters } : {}),
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
: {}),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
export function buildRequestRuntimeSnapshot(binding, options) {
|
|
104
|
-
const model = getBindingPrimaryModel(binding);
|
|
105
|
-
const tracing = buildRuntimeSnapshotTracing(binding, options?.requestId ?? options?.legacyRequestId);
|
|
106
|
-
const init = typeof model?.init === "object" && model.init ? model.init : {};
|
|
107
|
-
const baseUrl = typeof init.baseUrl === "string" && init.baseUrl.trim().length > 0
|
|
108
|
-
? init.baseUrl.trim()
|
|
109
|
-
: typeof init.baseURL === "string" && init.baseURL.trim().length > 0
|
|
110
|
-
? init.baseURL.trim()
|
|
111
|
-
: undefined;
|
|
112
|
-
const declaredTools = getBindingPrimaryTools(binding).map((tool) => ({
|
|
113
|
-
name: tool.name,
|
|
114
|
-
description: tool.description,
|
|
115
|
-
}));
|
|
116
|
-
const builtinToolsConfig = getBindingBuiltinToolsConfig(binding);
|
|
117
|
-
const effectiveBuiltinToolsConfig = builtinToolsConfig === undefined
|
|
118
|
-
? isDeepAgentBinding(binding)
|
|
119
|
-
? { modelExposed: false }
|
|
120
|
-
: undefined
|
|
121
|
-
: {
|
|
122
|
-
...builtinToolsConfig,
|
|
123
|
-
modelExposed: builtinToolsConfig.modelExposed ?? false,
|
|
124
|
-
};
|
|
125
|
-
const builtinToolDescriptors = filterBuiltinMiddlewareToolDescriptors(effectiveBuiltinToolsConfig)
|
|
126
|
-
.filter((descriptor) => !declaredTools.some((tool) => tool.name === descriptor.name));
|
|
127
|
-
const tools = isDeepAgentBinding(binding)
|
|
128
|
-
? [
|
|
129
|
-
...declaredTools,
|
|
130
|
-
...builtinToolDescriptors,
|
|
131
|
-
]
|
|
132
|
-
: builtinToolsConfig !== undefined
|
|
133
|
-
? [
|
|
134
|
-
...declaredTools,
|
|
135
|
-
...builtinToolDescriptors.filter((descriptor) => MODEL_EXPOSED_BUILTIN_TOOL_NAMES.has(descriptor.name)),
|
|
136
|
-
]
|
|
137
|
-
: declaredTools;
|
|
138
|
-
return {
|
|
139
|
-
agentId: binding.agent.id,
|
|
140
|
-
...(model ? {
|
|
141
|
-
model: {
|
|
142
|
-
id: model.id,
|
|
143
|
-
provider: model.provider,
|
|
144
|
-
model: model.model,
|
|
145
|
-
...(baseUrl ? { baseUrl } : {}),
|
|
146
|
-
},
|
|
147
|
-
} : {}),
|
|
148
|
-
tools,
|
|
149
|
-
skills: getBindingSkills(binding).map((skillPath) => {
|
|
150
|
-
const metadata = readSkillMetadata(skillPath);
|
|
151
|
-
return {
|
|
152
|
-
name: metadata.name,
|
|
153
|
-
path: skillPath,
|
|
154
|
-
...(metadata.description ? { description: metadata.description } : {}),
|
|
155
|
-
};
|
|
156
|
-
}),
|
|
157
|
-
memory: getBindingMemorySources(binding),
|
|
158
|
-
governance: {
|
|
159
|
-
bundles: buildRuntimeGovernanceBundles(binding),
|
|
160
|
-
},
|
|
161
|
-
...(tracing ? { tracing } : {}),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
function maybeAppendAgent(chain, agentId) {
|
|
165
|
-
if (!agentId) {
|
|
166
|
-
return chain;
|
|
167
|
-
}
|
|
168
|
-
if (chain[chain.length - 1] === agentId) {
|
|
169
|
-
return chain;
|
|
170
|
-
}
|
|
171
|
-
if (chain.includes(agentId)) {
|
|
172
|
-
return [...chain.filter((entry) => entry !== agentId), agentId];
|
|
173
|
-
}
|
|
174
|
-
return [...chain, agentId];
|
|
175
|
-
}
|
|
176
|
-
function extractSubagentFromTaskToolEvent(event) {
|
|
177
|
-
const eventName = typeof event.event === "string" ? event.event : "";
|
|
178
|
-
const toolName = typeof event.name === "string" ? event.name : "";
|
|
179
|
-
if (toolName !== "task" || (eventName !== "on_tool_start" && !(eventName === "on_chain_start" && event.run_type === "tool"))) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
const data = asObject(event.data);
|
|
183
|
-
const input = asObject(data?.input);
|
|
184
|
-
const subagentType = typeof input?.subagent_type === "string"
|
|
185
|
-
? input.subagent_type
|
|
186
|
-
: null;
|
|
187
|
-
return subagentType && subagentType.trim().length > 0 ? subagentType.trim() : null;
|
|
188
|
-
}
|
|
189
|
-
function extractKnownSubagentFromEvent(event, knownSubagentIds) {
|
|
190
|
-
const names = [
|
|
191
|
-
typeof event.name === "string" ? event.name : "",
|
|
192
|
-
...readStringArray(event.tags),
|
|
193
|
-
...readStringArray(event.ns),
|
|
194
|
-
];
|
|
195
|
-
return names.find((name) => knownSubagentIds.has(name)) ?? null;
|
|
196
|
-
}
|
|
197
|
-
export function consumeRunInspectionUpstreamEvent(input) {
|
|
198
|
-
const typed = asObject(input.event);
|
|
199
|
-
if (!typed) {
|
|
200
|
-
return {
|
|
201
|
-
currentAgentId: input.currentAgentId,
|
|
202
|
-
delegationChain: input.delegationChain,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
const knownSubagentIds = new Set(getBindingSubagents(input.binding).map((subagent) => subagent.name));
|
|
206
|
-
const delegatedAgentId = extractSubagentFromTaskToolEvent(typed) ?? extractKnownSubagentFromEvent(typed, knownSubagentIds);
|
|
207
|
-
if (isTaskDelegationTerminalEvent(typed) && input.delegationChain.length > 1) {
|
|
208
|
-
const nextDelegationChain = input.delegationChain.slice(0, -1);
|
|
209
|
-
const nextAgentId = nextDelegationChain.at(-1) ?? input.currentAgentId;
|
|
210
|
-
return {
|
|
211
|
-
currentAgentId: nextAgentId,
|
|
212
|
-
delegationChain: nextDelegationChain,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
if (!delegatedAgentId) {
|
|
216
|
-
return {
|
|
217
|
-
currentAgentId: input.currentAgentId,
|
|
218
|
-
delegationChain: input.delegationChain,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
currentAgentId: delegatedAgentId,
|
|
223
|
-
delegationChain: maybeAppendAgent(input.delegationChain, delegatedAgentId),
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
function unwrapUpstreamEvent(event) {
|
|
227
|
-
const typed = asObject(event);
|
|
228
|
-
if (!typed) {
|
|
229
|
-
return { event };
|
|
230
|
-
}
|
|
231
|
-
const nestedEvent = asObject(typed.event);
|
|
232
|
-
if (nestedEvent) {
|
|
233
|
-
return {
|
|
234
|
-
event: nestedEvent,
|
|
235
|
-
...(typeof typed.agentId === "string" ? { agentId: typed.agentId } : {}),
|
|
236
|
-
...(typeof typed.agentName === "string" ? { agentName: typed.agentName } : {}),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
return { event };
|
|
240
|
-
}
|
|
241
|
-
function toSurfaceKind(category) {
|
|
242
|
-
switch (category) {
|
|
243
|
-
case "llm":
|
|
244
|
-
case "memory":
|
|
245
|
-
case "skill":
|
|
246
|
-
case "tool":
|
|
247
|
-
return category;
|
|
248
|
-
default:
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
export function projectRuntimeSurfaceFromUpstreamEvents(input) {
|
|
253
|
-
const items = [];
|
|
254
|
-
let currentAgentId = input.initialAgentId;
|
|
255
|
-
let currentAgentName = formatAgentName(currentAgentId);
|
|
256
|
-
let delegationChain = [input.initialAgentId];
|
|
257
|
-
for (const [index, rawEvent] of input.upstreamEvents.entries()) {
|
|
258
|
-
const projected = projectRuntimeSurfaceFromSingleUpstreamEvent({
|
|
259
|
-
event: rawEvent,
|
|
260
|
-
binding: input.binding,
|
|
261
|
-
currentAgentId,
|
|
262
|
-
currentAgentName,
|
|
263
|
-
delegationChain,
|
|
264
|
-
sourceEventId: `upstream:${index + 1}`,
|
|
265
|
-
});
|
|
266
|
-
currentAgentId = projected.currentAgentId;
|
|
267
|
-
currentAgentName = projected.currentAgentName;
|
|
268
|
-
delegationChain = projected.delegationChain;
|
|
269
|
-
items.push(...projected.items);
|
|
270
|
-
}
|
|
271
|
-
return items;
|
|
272
|
-
}
|
|
273
|
-
export function projectRuntimeSurfaceFromSingleUpstreamEvent(input) {
|
|
274
|
-
const reducer = createUpstreamTimelineReducer();
|
|
275
|
-
const items = [];
|
|
276
|
-
let currentAgentId = input.currentAgentId;
|
|
277
|
-
let currentAgentName = input.currentAgentName ?? formatAgentName(currentAgentId);
|
|
278
|
-
let delegationChain = input.delegationChain ?? [input.currentAgentId];
|
|
279
|
-
const unwrapped = unwrapUpstreamEvent(input.event);
|
|
280
|
-
if (unwrapped.agentId) {
|
|
281
|
-
currentAgentId = unwrapped.agentId;
|
|
282
|
-
currentAgentName = unwrapped.agentName ?? formatAgentName(currentAgentId);
|
|
283
|
-
if (unwrapped.agentId !== input.currentAgentId) {
|
|
284
|
-
items.push({
|
|
285
|
-
kind: "agent",
|
|
286
|
-
id: buildSurfaceId("agent", unwrapped.agentId),
|
|
287
|
-
name: currentAgentName,
|
|
288
|
-
action: "handoff",
|
|
289
|
-
status: "started",
|
|
290
|
-
agentId: unwrapped.agentId,
|
|
291
|
-
agentName: currentAgentName,
|
|
292
|
-
ownerAgentId: input.currentAgentId,
|
|
293
|
-
ownerAgentName: input.currentAgentName ?? formatAgentName(input.currentAgentId),
|
|
294
|
-
sourceEventId: input.sourceEventId,
|
|
295
|
-
detail: {
|
|
296
|
-
fromAgentId: input.currentAgentId,
|
|
297
|
-
fromAgentName: input.currentAgentName ?? formatAgentName(input.currentAgentId),
|
|
298
|
-
toAgentId: unwrapped.agentId,
|
|
299
|
-
toAgentName: currentAgentName,
|
|
300
|
-
},
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
else if (unwrapped.agentName) {
|
|
305
|
-
currentAgentName = unwrapped.agentName;
|
|
306
|
-
}
|
|
307
|
-
const typed = asObject(unwrapped.event);
|
|
308
|
-
if (typed && input.binding) {
|
|
309
|
-
const previousAgentId = currentAgentId;
|
|
310
|
-
const previousDelegationChain = delegationChain;
|
|
311
|
-
const next = consumeRunInspectionUpstreamEvent({
|
|
312
|
-
event: typed,
|
|
313
|
-
currentAgentId,
|
|
314
|
-
delegationChain,
|
|
315
|
-
binding: input.binding,
|
|
316
|
-
});
|
|
317
|
-
if (next.delegationChain.length > previousDelegationChain.length) {
|
|
318
|
-
const delegatedAgentName = formatAgentName(next.currentAgentId);
|
|
319
|
-
const ownerAgentId = previousDelegationChain.at(-1) ?? previousAgentId;
|
|
320
|
-
items.push({
|
|
321
|
-
kind: "agent",
|
|
322
|
-
id: buildSurfaceId("agent", next.currentAgentId),
|
|
323
|
-
name: delegatedAgentName,
|
|
324
|
-
action: "handoff",
|
|
325
|
-
status: "started",
|
|
326
|
-
agentId: next.currentAgentId,
|
|
327
|
-
agentName: delegatedAgentName,
|
|
328
|
-
ownerAgentId,
|
|
329
|
-
ownerAgentName: formatAgentName(ownerAgentId),
|
|
330
|
-
sourceEventId: input.sourceEventId,
|
|
331
|
-
detail: {
|
|
332
|
-
fromAgentId: ownerAgentId,
|
|
333
|
-
fromAgentName: formatAgentName(ownerAgentId),
|
|
334
|
-
toAgentId: next.currentAgentId,
|
|
335
|
-
toAgentName: delegatedAgentName,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
if (isTaskDelegationTerminalEvent(typed) && previousDelegationChain.length > 1) {
|
|
340
|
-
const delegatedAgentId = previousDelegationChain.at(-1);
|
|
341
|
-
const ownerAgentId = previousDelegationChain.at(-2);
|
|
342
|
-
const delegatedAgentName = formatAgentName(delegatedAgentId);
|
|
343
|
-
items.push({
|
|
344
|
-
kind: "agent",
|
|
345
|
-
id: buildSurfaceId("agent", delegatedAgentId),
|
|
346
|
-
name: delegatedAgentName,
|
|
347
|
-
action: "handoff",
|
|
348
|
-
status: isTaskDelegationFailureEvent(typed) ? "failed" : "completed",
|
|
349
|
-
agentId: delegatedAgentId,
|
|
350
|
-
agentName: delegatedAgentName,
|
|
351
|
-
...(ownerAgentId ? { ownerAgentId, ownerAgentName: formatAgentName(ownerAgentId) } : {}),
|
|
352
|
-
sourceEventId: input.sourceEventId,
|
|
353
|
-
detail: {
|
|
354
|
-
...(ownerAgentId
|
|
355
|
-
? { fromAgentId: ownerAgentId, fromAgentName: formatAgentName(ownerAgentId) }
|
|
356
|
-
: {}),
|
|
357
|
-
toAgentId: delegatedAgentId,
|
|
358
|
-
toAgentName: delegatedAgentName,
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
currentAgentId = next.currentAgentId;
|
|
363
|
-
currentAgentName = formatAgentName(currentAgentId);
|
|
364
|
-
delegationChain = next.delegationChain;
|
|
365
|
-
}
|
|
366
|
-
for (const projection of reducer.consume(unwrapped.event)) {
|
|
367
|
-
if (projection.type !== "step") {
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
const kind = toSurfaceKind(projection.category);
|
|
371
|
-
if (!kind) {
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
const displayName = resolveSurfaceDisplayName({
|
|
375
|
-
kind,
|
|
376
|
-
step: projection.step,
|
|
377
|
-
binding: input.binding,
|
|
378
|
-
});
|
|
379
|
-
items.push({
|
|
380
|
-
kind,
|
|
381
|
-
id: buildSurfaceId(kind, displayName || projection.step),
|
|
382
|
-
name: displayName,
|
|
383
|
-
action: resolveSurfaceAction({
|
|
384
|
-
kind,
|
|
385
|
-
step: projection.step,
|
|
386
|
-
event: unwrapped.event,
|
|
387
|
-
}),
|
|
388
|
-
status: projection.status,
|
|
389
|
-
agentId: currentAgentId,
|
|
390
|
-
agentName: currentAgentName,
|
|
391
|
-
ownerAgentId: currentAgentId,
|
|
392
|
-
ownerAgentName: currentAgentName,
|
|
393
|
-
sourceEventId: input.sourceEventId,
|
|
394
|
-
detail: {
|
|
395
|
-
step: projection.step,
|
|
396
|
-
category: projection.category,
|
|
397
|
-
...(kind === "skill" && getBindingSkillNames(input.binding).length > 0
|
|
398
|
-
? { skillNames: getBindingSkillNames(input.binding) }
|
|
399
|
-
: {}),
|
|
400
|
-
},
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return {
|
|
404
|
-
currentAgentId,
|
|
405
|
-
currentAgentName,
|
|
406
|
-
delegationChain,
|
|
407
|
-
items,
|
|
408
|
-
};
|
|
409
|
-
}
|
|
1
|
+
import{readSkillMetadata as I}from"../../skills/skill-metadata.js";import{createUpstreamTimelineReducer as _}from"../../../projections/upstream-events.js";import{formatAgentName as f}from"../../../utils/agent-display.js";import{getBindingBuiltinToolsConfig as T,getBindingMemorySources as C,getBindingPrimaryModel as k,getBindingPrimaryTools as S,getBindingSkills as h,getBindingSubagents as w,isDeepAgentBinding as N}from"../../support/compiled-binding.js";import{buildRuntimeGovernanceBundles as x}from"./governance.js";import{filterBuiltinMiddlewareToolDescriptors as R}from"../../adapter/tool/builtin-middleware-tools.js";import{buildSurfaceId as p,resolveSurfaceAction as B,resolveSurfaceDisplayName as U}from"./surface-semantics.js";function u(e){return typeof e=="object"&&e!==null?e:null}function y(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0):[]}const D=new Set(["fetch_url","http_request","send_message","request_approval","schedule_task"]);function b(e){return e?h(e).map(t=>I(t).name).filter(t=>typeof t=="string"&&t.trim().length>0):[]}function j(e){const t=typeof e.event=="string"?e.event:"",n=typeof e.name=="string"?e.name:"",a=typeof e.run_type=="string"?e.run_type:"";return t==="on_tool_end"&&n==="task"||t==="on_chain_end"&&a==="tool"&&n==="task"}function v(e){const t=typeof e.event=="string"?e.event:"",n=typeof e.name=="string"?e.name:"",a=typeof e.run_type=="string"?e.run_type:"";return t==="on_tool_error"&&n==="task"||t==="on_chain_error"&&a==="tool"&&n==="task"}function E(e){return j(e)||v(e)}function L(e){const t=u(e.harnessRuntime?.deepagent?.passthrough)?.tracing,n=u(e.harnessRuntime?.langchain?.passthrough)?.tracing,a=u(e.deepAgentParams?.passthrough)?.tracing,r=u(e.langchainAgentParams?.passthrough)?.tracing;return u(n)??u(t)??u(r)??u(a)??null}function M(e,t){const n=L(e),a=u(e.harnessRuntime.observability),r=u(a?.tracing),s=Array.isArray(r?.exporters)?r.exporters.filter(o=>typeof o=="object"&&o!==null&&!Array.isArray(o)).map(o=>({type:typeof o.type=="string"?o.type:"custom",...typeof o.endpoint=="string"?{endpoint:o.endpoint}:{}})):[];if(!n)return!r||t===void 0||r.enabled===!1?void 0:{enabled:!0,correlationId:t,metadata:{...typeof r.propagation=="string"?{propagation:r.propagation}:{},...s.length>0?{exporters:s}:{}}};if(!(n.enabled!==!1)||!t)return;const d=y(n.tags),c=u(n.metadata);return{enabled:!0,correlationId:t,...d.length>0?{tags:d}:{},...c&&Object.keys(c).length>0||s.length>0||typeof r?.propagation=="string"?{metadata:{...c?{...c}:{},...typeof r?.propagation=="string"?{propagation:r.propagation}:{},...s.length>0?{exporters:s}:{}}}:{}}}function Y(e,t){const n=k(e),a=M(e,t?.requestId??t?.legacyRequestId),r=typeof n?.init=="object"&&n.init?n.init:{},s=typeof r.baseUrl=="string"&&r.baseUrl.trim().length>0?r.baseUrl.trim():typeof r.baseURL=="string"&&r.baseURL.trim().length>0?r.baseURL.trim():void 0,i=S(e).map(g=>({name:g.name,description:g.description})),d=T(e),c=d===void 0?N(e)?{modelExposed:!1}:void 0:{...d,modelExposed:d.modelExposed??!1},o=R(c).filter(g=>!i.some(l=>l.name===g.name)),m=N(e)?[...i,...o]:d!==void 0?[...i,...o.filter(g=>D.has(g.name))]:i;return{agentId:e.agent.id,...n?{model:{id:n.id,provider:n.provider,model:n.model,...s?{baseUrl:s}:{}}}:{},tools:m,skills:h(e).map(g=>{const l=I(g);return{name:l.name,path:g,...l.description?{description:l.description}:{}}}),memory:C(e),governance:{bundles:x(e)},...a?{tracing:a}:{}}}function O(e,t){return!t||e[e.length-1]===t?e:e.includes(t)?[...e.filter(n=>n!==t),t]:[...e,t]}function F(e){const t=typeof e.event=="string"?e.event:"";if((typeof e.name=="string"?e.name:"")!=="task"||t!=="on_tool_start"&&!(t==="on_chain_start"&&e.run_type==="tool"))return null;const a=u(e.data),r=u(a?.input),s=typeof r?.subagent_type=="string"?r.subagent_type:null;return s&&s.trim().length>0?s.trim():null}function P(e,t){return[typeof e.name=="string"?e.name:"",...y(e.tags),...y(e.ns)].find(a=>t.has(a))??null}function q(e){const t=u(e.event);if(!t)return{currentAgentId:e.currentAgentId,delegationChain:e.delegationChain};const n=new Set(w(e.binding).map(r=>r.name)),a=F(t)??P(t,n);if(E(t)&&e.delegationChain.length>1){const r=e.delegationChain.slice(0,-1);return{currentAgentId:r.at(-1)??e.currentAgentId,delegationChain:r}}return a?{currentAgentId:a,delegationChain:O(e.delegationChain,a)}:{currentAgentId:e.currentAgentId,delegationChain:e.delegationChain}}function K(e){const t=u(e);if(!t)return{event:e};const n=u(t.event);return n?{event:n,...typeof t.agentId=="string"?{agentId:t.agentId}:{},...typeof t.agentName=="string"?{agentName:t.agentName}:{}}:{event:e}}function G(e){switch(e){case"llm":case"memory":case"skill":case"tool":return e;default:return null}}function Z(e){const t=[];let n=e.initialAgentId,a=f(n),r=[e.initialAgentId];for(const[s,i]of e.upstreamEvents.entries()){const d=X({event:i,binding:e.binding,currentAgentId:n,currentAgentName:a,delegationChain:r,sourceEventId:`upstream:${s+1}`});n=d.currentAgentId,a=d.currentAgentName,r=d.delegationChain,t.push(...d.items)}return t}function X(e){const t=_(),n=[];let a=e.currentAgentId,r=e.currentAgentName??f(a),s=e.delegationChain??[e.currentAgentId];const i=K(e.event);i.agentId?(a=i.agentId,r=i.agentName??f(a),i.agentId!==e.currentAgentId&&n.push({kind:"agent",id:p("agent",i.agentId),name:r,action:"handoff",status:"started",agentId:i.agentId,agentName:r,ownerAgentId:e.currentAgentId,ownerAgentName:e.currentAgentName??f(e.currentAgentId),sourceEventId:e.sourceEventId,detail:{fromAgentId:e.currentAgentId,fromAgentName:e.currentAgentName??f(e.currentAgentId),toAgentId:i.agentId,toAgentName:r}})):i.agentName&&(r=i.agentName);const d=u(i.event);if(d&&e.binding){const c=a,o=s,m=q({event:d,currentAgentId:a,delegationChain:s,binding:e.binding});if(m.delegationChain.length>o.length){const g=f(m.currentAgentId),l=o.at(-1)??c;n.push({kind:"agent",id:p("agent",m.currentAgentId),name:g,action:"handoff",status:"started",agentId:m.currentAgentId,agentName:g,ownerAgentId:l,ownerAgentName:f(l),sourceEventId:e.sourceEventId,detail:{fromAgentId:l,fromAgentName:f(l),toAgentId:m.currentAgentId,toAgentName:g}})}if(E(d)&&o.length>1){const g=o.at(-1),l=o.at(-2),A=f(g);n.push({kind:"agent",id:p("agent",g),name:A,action:"handoff",status:v(d)?"failed":"completed",agentId:g,agentName:A,...l?{ownerAgentId:l,ownerAgentName:f(l)}:{},sourceEventId:e.sourceEventId,detail:{...l?{fromAgentId:l,fromAgentName:f(l)}:{},toAgentId:g,toAgentName:A}})}a=m.currentAgentId,r=f(a),s=m.delegationChain}for(const c of t.consume(i.event)){if(c.type!=="step")continue;const o=G(c.category);if(!o)continue;const m=U({kind:o,step:c.step,binding:e.binding});n.push({kind:o,id:p(o,m||c.step),name:m,action:B({kind:o,step:c.step,event:i.event}),status:c.status,agentId:a,agentName:r,ownerAgentId:a,ownerAgentName:r,sourceEventId:e.sourceEventId,detail:{step:c.step,category:c.category,...o==="skill"&&b(e.binding).length>0?{skillNames:b(e.binding)}:{}}})}return{currentAgentId:a,currentAgentName:r,delegationChain:s,items:n}}export{Y as buildRequestRuntimeSnapshot,q as consumeRunInspectionUpstreamEvent,X as projectRuntimeSurfaceFromSingleUpstreamEvent,Z as projectRuntimeSurfaceFromUpstreamEvents};
|
|
@@ -1,80 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
const ACTIVE_REQUEST_STATES = new Set([
|
|
3
|
-
"queued",
|
|
4
|
-
"claimed",
|
|
5
|
-
"running",
|
|
6
|
-
"waiting_for_approval",
|
|
7
|
-
"resuming",
|
|
8
|
-
"cancelling",
|
|
9
|
-
]);
|
|
10
|
-
function sortNewestFirst(items, selectTimestamp) {
|
|
11
|
-
return [...items].sort((left, right) => {
|
|
12
|
-
const leftTs = selectTimestamp(left) ?? "";
|
|
13
|
-
const rightTs = selectTimestamp(right) ?? "";
|
|
14
|
-
return rightTs.localeCompare(leftTs);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function summarizeRequestStates(requests) {
|
|
18
|
-
const states = {};
|
|
19
|
-
for (const request of requests) {
|
|
20
|
-
states[request.state] = (states[request.state] ?? 0) + 1;
|
|
21
|
-
}
|
|
22
|
-
return states;
|
|
23
|
-
}
|
|
24
|
-
function collectGovernanceToolPolicies(requests) {
|
|
25
|
-
return requests.flatMap((request) => request.runtimeSnapshot?.governance?.bundles ?? [])
|
|
26
|
-
.flatMap((bundle) => bundle.toolPolicies);
|
|
27
|
-
}
|
|
28
|
-
function projectGovernanceDiagnostics(requests) {
|
|
29
|
-
const toolPolicies = collectGovernanceToolPolicies(requests);
|
|
30
|
-
const highRiskTools = toolPolicies.filter((tool) => tool.risk === "high").length;
|
|
31
|
-
const approvalRequiredTools = toolPolicies.filter((tool) => tool.requiresApproval).length;
|
|
32
|
-
const autoApprovedTools = toolPolicies.filter((tool) => tool.decisionMode === "auto-approve").length;
|
|
33
|
-
const autoRejectedTools = toolPolicies.filter((tool) => tool.decisionMode === "auto-reject" || tool.decisionMode === "deny-and-continue").length;
|
|
34
|
-
const untrustedMcpTools = toolPolicies.filter((tool) => tool.mcpTrustTier === "untrusted").length;
|
|
35
|
-
const crossTenantTools = toolPolicies.filter((tool) => tool.tenantScope === "cross-tenant").length;
|
|
36
|
-
const writeAccessMcpTools = toolPolicies.filter((tool) => tool.category === "mcp" && tool.mcpAccess === "read-write").length;
|
|
37
|
-
return {
|
|
38
|
-
runsWithGovernance: requests.filter((request) => (request.runtimeSnapshot?.governance?.bundles?.length ?? 0) > 0).length,
|
|
39
|
-
highRiskTools,
|
|
40
|
-
approvalRequiredTools,
|
|
41
|
-
autoApprovedTools,
|
|
42
|
-
autoRejectedTools,
|
|
43
|
-
untrustedMcpTools,
|
|
44
|
-
crossTenantTools,
|
|
45
|
-
writeAccessMcpTools,
|
|
46
|
-
summary: `highRisk=${highRiskTools} ` +
|
|
47
|
-
`approvalRequired=${approvalRequiredTools} ` +
|
|
48
|
-
`autoApproved=${autoApprovedTools} ` +
|
|
49
|
-
`autoRejected=${autoRejectedTools} ` +
|
|
50
|
-
`untrusted=${untrustedMcpTools} ` +
|
|
51
|
-
`crossTenant=${crossTenantTools}`,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export function projectOperatorOverview(input) {
|
|
55
|
-
const limit = typeof input.limit === "number" && Number.isFinite(input.limit) && input.limit > 0 ? Math.floor(input.limit) : 5;
|
|
56
|
-
const activeRequests = sortNewestFirst(input.requests.filter((request) => ACTIVE_REQUEST_STATES.has(request.state)), (request) => request.lastActivityAt ?? request.updatedAt);
|
|
57
|
-
const pendingApprovals = sortNewestFirst(input.approvals.filter((approval) => approval.status === "pending"), (approval) => approval.requestedAt);
|
|
58
|
-
const queue = projectQueueDiagnostics(input.health, []);
|
|
59
|
-
const governance = projectGovernanceDiagnostics(activeRequests);
|
|
60
|
-
const requestOverview = {
|
|
61
|
-
total: activeRequests.length,
|
|
62
|
-
states: summarizeRequestStates(activeRequests),
|
|
63
|
-
items: activeRequests.slice(0, limit),
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
updatedAt: input.health.updatedAt,
|
|
67
|
-
summary: `${queue.summary} ` +
|
|
68
|
-
`pendingApprovals=${pendingApprovals.length} ` +
|
|
69
|
-
`activeRequests=${activeRequests.length} ` +
|
|
70
|
-
`${governance.summary}`,
|
|
71
|
-
health: input.health,
|
|
72
|
-
queue,
|
|
73
|
-
approvals: {
|
|
74
|
-
total: pendingApprovals.length,
|
|
75
|
-
items: pendingApprovals.slice(0, limit),
|
|
76
|
-
},
|
|
77
|
-
requests: requestOverview,
|
|
78
|
-
governance,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
1
|
+
import{projectQueueDiagnostics as p}from"./queue-diagnostics.js";const h=new Set(["queued","claimed","running","waiting_for_approval","resuming","cancelling"]);function l(t,e){return[...t].sort((s,r)=>{const i=e(s)??"";return(e(r)??"").localeCompare(i)})}function d(t){const e={};for(const s of t)e[s.state]=(e[s.state]??0)+1;return e}function g(t){return t.flatMap(e=>e.runtimeSnapshot?.governance?.bundles??[]).flatMap(e=>e.toolPolicies)}function m(t){const e=g(t),s=e.filter(o=>o.risk==="high").length,r=e.filter(o=>o.requiresApproval).length,i=e.filter(o=>o.decisionMode==="auto-approve").length,a=e.filter(o=>o.decisionMode==="auto-reject"||o.decisionMode==="deny-and-continue").length,c=e.filter(o=>o.mcpTrustTier==="untrusted").length,n=e.filter(o=>o.tenantScope==="cross-tenant").length,u=e.filter(o=>o.category==="mcp"&&o.mcpAccess==="read-write").length;return{runsWithGovernance:t.filter(o=>(o.runtimeSnapshot?.governance?.bundles?.length??0)>0).length,highRiskTools:s,approvalRequiredTools:r,autoApprovedTools:i,autoRejectedTools:a,untrustedMcpTools:c,crossTenantTools:n,writeAccessMcpTools:u,summary:`highRisk=${s} approvalRequired=${r} autoApproved=${i} autoRejected=${a} untrusted=${c} crossTenant=${n}`}}function v(t){const e=typeof t.limit=="number"&&Number.isFinite(t.limit)&&t.limit>0?Math.floor(t.limit):5,s=l(t.requests.filter(n=>h.has(n.state)),n=>n.lastActivityAt??n.updatedAt),r=l(t.approvals.filter(n=>n.status==="pending"),n=>n.requestedAt),i=p(t.health,[]),a=m(s),c={total:s.length,states:d(s),items:s.slice(0,e)};return{updatedAt:t.health.updatedAt,summary:`${i.summary} pendingApprovals=${r.length} activeRequests=${s.length} ${a.summary}`,health:t.health,queue:i,approvals:{total:r.length,items:r.slice(0,e)},requests:c,governance:a}}export{v as projectOperatorOverview};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const queueEvents = timeline.filter((item) => item.kind === "queue" || item.kind === "recovery");
|
|
3
|
-
const summary = `active=${snapshot.stats.activeRequestSlots} ` +
|
|
4
|
-
`pending=${snapshot.stats.pendingRequestSlots} ` +
|
|
5
|
-
`stuck=${snapshot.stats.stuckRequests} ` +
|
|
6
|
-
`workload=${snapshot.checks.workload.status}`;
|
|
7
|
-
return {
|
|
8
|
-
status: snapshot.checks.workload.status,
|
|
9
|
-
activeRequestSlots: snapshot.stats.activeRequestSlots,
|
|
10
|
-
pendingRequestSlots: snapshot.stats.pendingRequestSlots,
|
|
11
|
-
stuckRequests: snapshot.stats.stuckRequests,
|
|
12
|
-
queueEvents,
|
|
13
|
-
summary,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
1
|
+
function i(t,s){const u=s.filter(e=>e.kind==="queue"||e.kind==="recovery"),c=`active=${t.stats.activeRequestSlots} pending=${t.stats.pendingRequestSlots} stuck=${t.stats.stuckRequests} workload=${t.checks.workload.status}`;return{status:t.checks.workload.status,activeRequestSlots:t.stats.activeRequestSlots,pendingRequestSlots:t.stats.pendingRequestSlots,stuckRequests:t.stats.stuckRequests,queueEvents:u,summary:c}}export{i as projectQueueDiagnostics};
|