@mongodb-js/agent-engine-runner-shared 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/LICENSE.md +201 -0
- package/README.md +29 -0
- package/dist/agent_config.d.ts +167 -0
- package/dist/agent_config.d.ts.map +1 -0
- package/dist/agent_config.js +544 -0
- package/dist/call_interrupted.d.ts +12 -0
- package/dist/call_interrupted.d.ts.map +1 -0
- package/dist/call_interrupted.js +11 -0
- package/dist/checkpoint_workspace.d.ts +25 -0
- package/dist/checkpoint_workspace.d.ts.map +1 -0
- package/dist/checkpoint_workspace.js +44 -0
- package/dist/context.d.ts +235 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +322 -0
- package/dist/db_config.d.ts +28 -0
- package/dist/db_config.d.ts.map +1 -0
- package/dist/db_config.js +66 -0
- package/dist/db_naming.d.ts +54 -0
- package/dist/db_naming.d.ts.map +1 -0
- package/dist/db_naming.js +94 -0
- package/dist/error_reporting.d.ts +67 -0
- package/dist/error_reporting.d.ts.map +1 -0
- package/dist/error_reporting.js +311 -0
- package/dist/generated/workflow/v1/activity_pb.d.ts +342 -0
- package/dist/generated/workflow/v1/activity_pb.d.ts.map +1 -0
- package/dist/generated/workflow/v1/activity_pb.js +115 -0
- package/dist/generated/workflow/v1/common_pb.d.ts +184 -0
- package/dist/generated/workflow/v1/common_pb.d.ts.map +1 -0
- package/dist/generated/workflow/v1/common_pb.js +86 -0
- package/dist/generated/workflow/v1/runtime_pb.d.ts +200 -0
- package/dist/generated/workflow/v1/runtime_pb.d.ts.map +1 -0
- package/dist/generated/workflow/v1/runtime_pb.js +40 -0
- package/dist/generated/workflow/v1/state_pb.d.ts +254 -0
- package/dist/generated/workflow/v1/state_pb.d.ts.map +1 -0
- package/dist/generated/workflow/v1/state_pb.js +68 -0
- package/dist/guardrails_evaluator/core.d.ts +23 -0
- package/dist/guardrails_evaluator/core.d.ts.map +1 -0
- package/dist/guardrails_evaluator/core.js +122 -0
- package/dist/guardrails_evaluator/index.d.ts +10 -0
- package/dist/guardrails_evaluator/index.d.ts.map +1 -0
- package/dist/guardrails_evaluator/index.js +11 -0
- package/dist/guardrails_evaluator/regex.d.ts +20 -0
- package/dist/guardrails_evaluator/regex.d.ts.map +1 -0
- package/dist/guardrails_evaluator/regex.js +233 -0
- package/dist/hooks.d.ts +109 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +216 -0
- package/dist/http_path.d.ts +18 -0
- package/dist/http_path.d.ts.map +1 -0
- package/dist/http_path.js +53 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/launcher.d.ts +130 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +325 -0
- package/dist/logger.d.ts +96 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +204 -0
- package/dist/mcp_oauth.d.ts +51 -0
- package/dist/mcp_oauth.d.ts.map +1 -0
- package/dist/mcp_oauth.js +389 -0
- package/dist/mcp_oauth_secret.d.ts +21 -0
- package/dist/mcp_oauth_secret.d.ts.map +1 -0
- package/dist/mcp_oauth_secret.js +122 -0
- package/dist/mcp_tools.d.ts +71 -0
- package/dist/mcp_tools.d.ts.map +1 -0
- package/dist/mcp_tools.js +301 -0
- package/dist/memory_appbound.d.ts +42 -0
- package/dist/memory_appbound.d.ts.map +1 -0
- package/dist/memory_appbound.js +159 -0
- package/dist/memory_writer.d.ts +49 -0
- package/dist/memory_writer.d.ts.map +1 -0
- package/dist/memory_writer.js +171 -0
- package/dist/metrics.d.ts +84 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +205 -0
- package/dist/models.d.ts +1458 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +1726 -0
- package/dist/node_logger.d.ts +43 -0
- package/dist/node_logger.d.ts.map +1 -0
- package/dist/node_logger.js +158 -0
- package/dist/owner_callback.d.ts +16 -0
- package/dist/owner_callback.d.ts.map +1 -0
- package/dist/owner_callback.js +40 -0
- package/dist/progress.d.ts +57 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +140 -0
- package/dist/runtime.d.ts +131 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +351 -0
- package/dist/secure_llm_proxy.d.ts +115 -0
- package/dist/secure_llm_proxy.d.ts.map +1 -0
- package/dist/secure_llm_proxy.js +922 -0
- package/dist/secure_wrapper.d.ts +332 -0
- package/dist/secure_wrapper.d.ts.map +1 -0
- package/dist/secure_wrapper.js +1249 -0
- package/dist/server/aer.d.ts +61 -0
- package/dist/server/aer.d.ts.map +1 -0
- package/dist/server/aer.js +1124 -0
- package/dist/server/auth.d.ts +56 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +132 -0
- package/dist/server/base.d.ts +104 -0
- package/dist/server/base.d.ts.map +1 -0
- package/dist/server/base.js +150 -0
- package/dist/server/callInterrupt.d.ts +49 -0
- package/dist/server/callInterrupt.d.ts.map +1 -0
- package/dist/server/callInterrupt.js +68 -0
- package/dist/server/callback_delivery.d.ts +14 -0
- package/dist/server/callback_delivery.d.ts.map +1 -0
- package/dist/server/callback_delivery.js +141 -0
- package/dist/server/chunk_types.d.ts +50 -0
- package/dist/server/chunk_types.d.ts.map +1 -0
- package/dist/server/chunk_types.js +62 -0
- package/dist/server/cors.d.ts +52 -0
- package/dist/server/cors.d.ts.map +1 -0
- package/dist/server/cors.js +107 -0
- package/dist/server/drain.d.ts +169 -0
- package/dist/server/drain.d.ts.map +1 -0
- package/dist/server/drain.js +455 -0
- package/dist/server/function.d.ts +77 -0
- package/dist/server/function.d.ts.map +1 -0
- package/dist/server/function.js +337 -0
- package/dist/server/http_retry.d.ts +37 -0
- package/dist/server/http_retry.d.ts.map +1 -0
- package/dist/server/http_retry.js +157 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +5 -0
- package/dist/server/metadata.d.ts +50 -0
- package/dist/server/metadata.d.ts.map +1 -0
- package/dist/server/metadata.js +193 -0
- package/dist/server/oe_url.d.ts +36 -0
- package/dist/server/oe_url.d.ts.map +1 -0
- package/dist/server/oe_url.js +50 -0
- package/dist/server/owner_url.d.ts +35 -0
- package/dist/server/owner_url.d.ts.map +1 -0
- package/dist/server/owner_url.js +146 -0
- package/dist/server/query.d.ts +42 -0
- package/dist/server/query.d.ts.map +1 -0
- package/dist/server/query.js +28 -0
- package/dist/server/tool.d.ts +138 -0
- package/dist/server/tool.d.ts.map +1 -0
- package/dist/server/tool.js +1017 -0
- package/dist/span_names.d.ts +21 -0
- package/dist/span_names.d.ts.map +1 -0
- package/dist/span_names.js +31 -0
- package/dist/structured_logging/constants.d.ts +17 -0
- package/dist/structured_logging/constants.d.ts.map +1 -0
- package/dist/structured_logging/constants.js +71 -0
- package/dist/structured_logging/env.d.ts +18 -0
- package/dist/structured_logging/env.d.ts.map +1 -0
- package/dist/structured_logging/env.js +39 -0
- package/dist/structured_logging/install.d.ts +56 -0
- package/dist/structured_logging/install.d.ts.map +1 -0
- package/dist/structured_logging/install.js +107 -0
- package/dist/structured_logging/layout.d.ts +9 -0
- package/dist/structured_logging/layout.d.ts.map +1 -0
- package/dist/structured_logging/layout.js +144 -0
- package/dist/structured_logging/serialize.d.ts +27 -0
- package/dist/structured_logging/serialize.d.ts.map +1 -0
- package/dist/structured_logging/serialize.js +61 -0
- package/dist/structured_logging/stdio_capture.d.ts +59 -0
- package/dist/structured_logging/stdio_capture.d.ts.map +1 -0
- package/dist/structured_logging/stdio_capture.js +164 -0
- package/dist/structured_logging/uncaught.d.ts +14 -0
- package/dist/structured_logging/uncaught.d.ts.map +1 -0
- package/dist/structured_logging/uncaught.js +58 -0
- package/dist/structured_logging.d.ts +48 -0
- package/dist/structured_logging.d.ts.map +1 -0
- package/dist/structured_logging.js +47 -0
- package/dist/tls_client.d.ts +61 -0
- package/dist/tls_client.d.ts.map +1 -0
- package/dist/tls_client.js +298 -0
- package/dist/tool_api_error.d.ts +62 -0
- package/dist/tool_api_error.d.ts.map +1 -0
- package/dist/tool_api_error.js +399 -0
- package/dist/tool_memory_ownership.d.ts +10 -0
- package/dist/tool_memory_ownership.d.ts.map +1 -0
- package/dist/tool_memory_ownership.js +36 -0
- package/dist/toolpod_handlers.d.ts +126 -0
- package/dist/toolpod_handlers.d.ts.map +1 -0
- package/dist/toolpod_handlers.js +1016 -0
- package/dist/tracing/exporters.d.ts +51 -0
- package/dist/tracing/exporters.d.ts.map +1 -0
- package/dist/tracing/exporters.js +327 -0
- package/dist/tracing/index.d.ts +3 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +2 -0
- package/dist/tracing/setup.d.ts +76 -0
- package/dist/tracing/setup.d.ts.map +1 -0
- package/dist/tracing/setup.js +436 -0
- package/dist/utils.d.ts +204 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +867 -0
- package/dist/workflow/activity.d.ts +71 -0
- package/dist/workflow/activity.d.ts.map +1 -0
- package/dist/workflow/activity.js +357 -0
- package/dist/workflow/attempt.d.ts +12 -0
- package/dist/workflow/attempt.d.ts.map +1 -0
- package/dist/workflow/attempt.js +96 -0
- package/dist/workflow/client.d.ts +46 -0
- package/dist/workflow/client.d.ts.map +1 -0
- package/dist/workflow/client.js +299 -0
- package/dist/workflow/context.d.ts +37 -0
- package/dist/workflow/context.d.ts.map +1 -0
- package/dist/workflow/context.js +350 -0
- package/dist/workflow/heartbeat.d.ts +15 -0
- package/dist/workflow/heartbeat.d.ts.map +1 -0
- package/dist/workflow/heartbeat.js +78 -0
- package/dist/workflow/index.d.ts +14 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +10 -0
- package/dist/workflow/memory.d.ts +17 -0
- package/dist/workflow/memory.d.ts.map +1 -0
- package/dist/workflow/memory.js +184 -0
- package/package.json +73 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node execution logger — framework-neutral.
|
|
3
|
+
*
|
|
4
|
+
* Logs graph node traversals to the OE for observability. The OE writes them
|
|
5
|
+
* to MongoDB so persistence stays centralized.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors Python `agent_engine_runner_shared/node_logger.py`. Extends `NullExecutionCallback`
|
|
8
|
+
* (from agent-engine-sdk) so future protocol additions don't break implementations
|
|
9
|
+
* that didn't override the new method.
|
|
10
|
+
*/
|
|
11
|
+
import { NullExecutionCallback } from "@mongodb-js/agent-engine-sdk";
|
|
12
|
+
interface NodeCallbackOpts {
|
|
13
|
+
runId: string;
|
|
14
|
+
parentRunId?: string;
|
|
15
|
+
metadata?: Record<string, unknown>;
|
|
16
|
+
durationMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface NodeExecutionLoggerOpts {
|
|
19
|
+
oeUrl: string;
|
|
20
|
+
executionId: string;
|
|
21
|
+
sessionId?: string | null;
|
|
22
|
+
userId?: string | null;
|
|
23
|
+
orgId?: string | null;
|
|
24
|
+
projectId?: string | null;
|
|
25
|
+
}
|
|
26
|
+
export declare class NodeExecutionLogger extends NullExecutionCallback {
|
|
27
|
+
private readonly oeUrl;
|
|
28
|
+
private readonly executionId;
|
|
29
|
+
private readonly sessionId;
|
|
30
|
+
private readonly userId;
|
|
31
|
+
private readonly orgId;
|
|
32
|
+
private readonly projectId;
|
|
33
|
+
private readonly nodeStartTimes;
|
|
34
|
+
constructor(opts: NodeExecutionLoggerOpts);
|
|
35
|
+
onNodeStart(nodeName: string, inputs: Record<string, unknown>, opts: NodeCallbackOpts): void;
|
|
36
|
+
onNodeEnd(nodeName: string, outputs: Record<string, unknown>, opts: NodeCallbackOpts): void;
|
|
37
|
+
onNodeError(nodeName: string, error: string, opts: NodeCallbackOpts): void;
|
|
38
|
+
onNodeSuspend(nodeName: string, opts: NodeCallbackOpts): void;
|
|
39
|
+
private serializeForJson;
|
|
40
|
+
private sendNodeEvent;
|
|
41
|
+
}
|
|
42
|
+
export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AAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,EAAE,gBAAgB,GACrB,IAAI;IAkBE,WAAW,CAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,gBAAgB,GACrB,IAAI;IAYE,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAgBtE,OAAO,CAAC,gBAAgB;YAwBV,aAAa;CA4D5B"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node execution logger — framework-neutral.
|
|
3
|
+
*
|
|
4
|
+
* Logs graph node traversals to the OE for observability. The OE writes them
|
|
5
|
+
* to MongoDB so persistence stays centralized.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors Python `agent_engine_runner_shared/node_logger.py`. Extends `NullExecutionCallback`
|
|
8
|
+
* (from agent-engine-sdk) so future protocol additions don't break implementations
|
|
9
|
+
* that didn't override the new method.
|
|
10
|
+
*/
|
|
11
|
+
import { NullExecutionCallback } from "@mongodb-js/agent-engine-sdk";
|
|
12
|
+
import { getLogger } from "./logger.js";
|
|
13
|
+
import { fetchPlatform, getFetchOptionsWithTLS } from "./tls_client.js";
|
|
14
|
+
const logger = getLogger("agent_engine_runner_shared.node_logger");
|
|
15
|
+
export class NodeExecutionLogger extends NullExecutionCallback {
|
|
16
|
+
oeUrl;
|
|
17
|
+
executionId;
|
|
18
|
+
sessionId;
|
|
19
|
+
userId;
|
|
20
|
+
orgId;
|
|
21
|
+
projectId;
|
|
22
|
+
nodeStartTimes = new Map();
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
super();
|
|
25
|
+
this.oeUrl = opts.oeUrl;
|
|
26
|
+
this.executionId = opts.executionId;
|
|
27
|
+
this.sessionId = opts.sessionId ?? null;
|
|
28
|
+
this.userId = opts.userId ?? null;
|
|
29
|
+
this.orgId = opts.orgId ?? null;
|
|
30
|
+
this.projectId = opts.projectId ?? null;
|
|
31
|
+
}
|
|
32
|
+
onNodeStart(nodeName, inputs, opts) {
|
|
33
|
+
const start = new Date();
|
|
34
|
+
this.nodeStartTimes.set(opts.runId, start);
|
|
35
|
+
void this.sendNodeEvent({
|
|
36
|
+
nodeName,
|
|
37
|
+
status: "started",
|
|
38
|
+
timestamp: start,
|
|
39
|
+
runId: opts.runId,
|
|
40
|
+
parentRunId: opts.parentRunId,
|
|
41
|
+
inputs,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
onNodeEnd(nodeName, outputs, opts) {
|
|
45
|
+
const start = this.nodeStartTimes.get(opts.runId);
|
|
46
|
+
this.nodeStartTimes.delete(opts.runId);
|
|
47
|
+
const end = new Date();
|
|
48
|
+
const durationMs = opts.durationMs ??
|
|
49
|
+
(start !== undefined ? end.getTime() - start.getTime() : undefined);
|
|
50
|
+
void this.sendNodeEvent({
|
|
51
|
+
nodeName,
|
|
52
|
+
status: "success",
|
|
53
|
+
timestamp: end,
|
|
54
|
+
runId: opts.runId,
|
|
55
|
+
parentRunId: opts.parentRunId,
|
|
56
|
+
outputs,
|
|
57
|
+
durationMs,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
onNodeError(nodeName, error, opts) {
|
|
61
|
+
this.nodeStartTimes.delete(opts.runId);
|
|
62
|
+
void this.sendNodeEvent({
|
|
63
|
+
nodeName,
|
|
64
|
+
status: "error",
|
|
65
|
+
timestamp: new Date(),
|
|
66
|
+
runId: opts.runId,
|
|
67
|
+
parentRunId: opts.parentRunId,
|
|
68
|
+
error,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
onNodeSuspend(nodeName, opts) {
|
|
72
|
+
const start = this.nodeStartTimes.get(opts.runId);
|
|
73
|
+
this.nodeStartTimes.delete(opts.runId);
|
|
74
|
+
const end = new Date();
|
|
75
|
+
const durationMs = start !== undefined ? end.getTime() - start.getTime() : undefined;
|
|
76
|
+
void this.sendNodeEvent({
|
|
77
|
+
nodeName,
|
|
78
|
+
status: "suspend",
|
|
79
|
+
timestamp: end,
|
|
80
|
+
runId: opts.runId,
|
|
81
|
+
parentRunId: opts.parentRunId,
|
|
82
|
+
durationMs,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
serializeForJson(obj) {
|
|
86
|
+
if (obj === null || obj === undefined)
|
|
87
|
+
return obj;
|
|
88
|
+
const t = typeof obj;
|
|
89
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
90
|
+
return obj;
|
|
91
|
+
if (Array.isArray(obj))
|
|
92
|
+
return obj.map((v) => this.serializeForJson(v));
|
|
93
|
+
if (t === "object") {
|
|
94
|
+
// Pydantic .dict() equivalent: if a custom toJSON exists, use it.
|
|
95
|
+
const maybeToJson = obj.toJSON;
|
|
96
|
+
if (typeof maybeToJson === "function") {
|
|
97
|
+
try {
|
|
98
|
+
return maybeToJson.call(obj);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
/* fall through */
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
106
|
+
out[k] = this.serializeForJson(v);
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
return String(obj);
|
|
111
|
+
}
|
|
112
|
+
async sendNodeEvent(event) {
|
|
113
|
+
const payload = {
|
|
114
|
+
execution_id: this.executionId,
|
|
115
|
+
node_name: event.nodeName,
|
|
116
|
+
status: event.status,
|
|
117
|
+
timestamp: event.timestamp.toISOString(),
|
|
118
|
+
run_id: event.runId,
|
|
119
|
+
parent_run_id: event.parentRunId ?? null,
|
|
120
|
+
session_id: this.sessionId,
|
|
121
|
+
user_id: this.userId,
|
|
122
|
+
org_id: this.orgId,
|
|
123
|
+
project_id: this.projectId,
|
|
124
|
+
};
|
|
125
|
+
if (event.inputs !== undefined)
|
|
126
|
+
payload["inputs"] = this.serializeForJson(event.inputs);
|
|
127
|
+
if (event.outputs !== undefined)
|
|
128
|
+
payload["outputs"] = this.serializeForJson(event.outputs);
|
|
129
|
+
if (event.error !== undefined)
|
|
130
|
+
payload["error"] = event.error;
|
|
131
|
+
if (event.durationMs !== undefined)
|
|
132
|
+
payload["duration_ms"] = event.durationMs;
|
|
133
|
+
const controller = new AbortController();
|
|
134
|
+
const timer = setTimeout(() => controller.abort(), 2000);
|
|
135
|
+
try {
|
|
136
|
+
const tlsOptions = getFetchOptionsWithTLS(this.oeUrl);
|
|
137
|
+
const response = await fetchPlatform(`${this.oeUrl}/node/execution`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: { "content-type": "application/json" },
|
|
140
|
+
body: JSON.stringify(payload),
|
|
141
|
+
signal: controller.signal,
|
|
142
|
+
...tlsOptions,
|
|
143
|
+
});
|
|
144
|
+
// `fetch` only rejects on network/abort errors, not on HTTP error
|
|
145
|
+
// statuses — surface a non-2xx so an OE-side failure isn't silently
|
|
146
|
+
// swallowed. Stays non-fatal: node events are best-effort observability.
|
|
147
|
+
if (!response.ok) {
|
|
148
|
+
logger.debug({ status: response.status, node: event.nodeName }, "OE rejected node event");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
logger.debug({ err: err.message }, "Failed to send node event to OE");
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-callback pre-attempt shared by every owner-preferred OE POST.
|
|
3
|
+
*
|
|
4
|
+
* Policy (mirrored by `agent_engine_runner_shared/owner_callback.py` and the async
|
|
5
|
+
* `_owner_delivered` in `agent_engine_runner_shared/server/http_retry.py` — keep in sync):
|
|
6
|
+
* the replica-specific owner URL gets exactly one best-effort POST before the
|
|
7
|
+
* trusted service URL. Any owner failure — a transport error, a redirect
|
|
8
|
+
* (never followed: the owner URL is only validated as a headless replica of
|
|
9
|
+
* the service origin, so a 3xx could forward the body elsewhere), or any
|
|
10
|
+
* other non-2xx — falls back to the service path. The owner is never retried
|
|
11
|
+
* and this helper never throws. Response bodies are never read or logged
|
|
12
|
+
* (externally influenced) and are cancelled so undici can reuse the
|
|
13
|
+
* connection.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ownerDelivered(ownerUrl: string, init: RequestInit | (() => RequestInit), log: (message: string) => void): Promise<boolean>;
|
|
16
|
+
//# sourceMappingURL=owner_callback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owner_callback.d.ts","sourceRoot":"","sources":["../src/owner_callback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,CAAC,EACvC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC,OAAO,CAAC,CAqBlB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owner-callback pre-attempt shared by every owner-preferred OE POST.
|
|
3
|
+
*
|
|
4
|
+
* Policy (mirrored by `agent_engine_runner_shared/owner_callback.py` and the async
|
|
5
|
+
* `_owner_delivered` in `agent_engine_runner_shared/server/http_retry.py` — keep in sync):
|
|
6
|
+
* the replica-specific owner URL gets exactly one best-effort POST before the
|
|
7
|
+
* trusted service URL. Any owner failure — a transport error, a redirect
|
|
8
|
+
* (never followed: the owner URL is only validated as a headless replica of
|
|
9
|
+
* the service origin, so a 3xx could forward the body elsewhere), or any
|
|
10
|
+
* other non-2xx — falls back to the service path. The owner is never retried
|
|
11
|
+
* and this helper never throws. Response bodies are never read or logged
|
|
12
|
+
* (externally influenced) and are cancelled so undici can reuse the
|
|
13
|
+
* connection.
|
|
14
|
+
*/
|
|
15
|
+
import { fetchPlatform } from "./tls_client.js";
|
|
16
|
+
import { discardResponseBody } from "./server/http_retry.js";
|
|
17
|
+
export async function ownerDelivered(ownerUrl, init, log) {
|
|
18
|
+
let failure;
|
|
19
|
+
try {
|
|
20
|
+
// Build URL-specific TLS options inside the best-effort boundary. Reading
|
|
21
|
+
// rotated certificate files can fail before fetch starts and must still
|
|
22
|
+
// degrade to the trusted service path.
|
|
23
|
+
const requestInit = typeof init === "function" ? init() : init;
|
|
24
|
+
// fetchPlatform, not bare fetch: the owner attempt must carry the same
|
|
25
|
+
// W3C trace-context headers and tracing suppression as the service path.
|
|
26
|
+
const response = await fetchPlatform(ownerUrl, {
|
|
27
|
+
...requestInit,
|
|
28
|
+
redirect: "manual",
|
|
29
|
+
});
|
|
30
|
+
await discardResponseBody(response);
|
|
31
|
+
if (response.ok)
|
|
32
|
+
return true;
|
|
33
|
+
failure = `HTTP ${response.status}`;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
failure = e instanceof Error ? e.message : String(e);
|
|
37
|
+
}
|
|
38
|
+
log(`owner URL ${ownerUrl} unusable (${failure}); falling back to service`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emit / emitStep — send a mid-execution chunk from within a tool function.
|
|
3
|
+
*
|
|
4
|
+
* Tool functions running inside a Tool Pod call these to stream events to the
|
|
5
|
+
* client while the tool is still executing. Both executionId and oeUrl are
|
|
6
|
+
* injected into the execution context by the Tool Pod server before the tool
|
|
7
|
+
* runs (see `server/tool.ts`).
|
|
8
|
+
*
|
|
9
|
+
* The call is best-effort: network errors are logged and swallowed so a failed
|
|
10
|
+
* chunk emit never aborts the tool. Mirrors `agent_engine_runner_shared/progress.py`.
|
|
11
|
+
*
|
|
12
|
+
* Unlike the Python port there is no module-level client to pool: TLS agent
|
|
13
|
+
* reuse and cert-rotation invalidation are already handled by
|
|
14
|
+
* `getFetchOptionsWithTLS` (tls_client.ts), which caches one keep-alive agent
|
|
15
|
+
* per origin — so a plain `fetch` here reuses the same pooled connection the
|
|
16
|
+
* Python `_get_client` machinery provides.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Emit a chunk of the given event type to the client stream.
|
|
20
|
+
*
|
|
21
|
+
* General-purpose API. For the common textual-step case, prefer
|
|
22
|
+
* {@link emitStep}.
|
|
23
|
+
*
|
|
24
|
+
* @param event Chunk type identifier (e.g. `"step"`). Reserved infrastructure
|
|
25
|
+
* event types (`done`, `error`, `text`, `subagent_start`, `subagent_end`)
|
|
26
|
+
* reject with an `Error` to prevent tool code from prematurely closing or
|
|
27
|
+
* spoofing the stream. The reserved-event check fires even outside an
|
|
28
|
+
* execution context — a programmer error wins over the no-op.
|
|
29
|
+
* `"custom_event"` is not Atlas Agent Engine custom events; those require
|
|
30
|
+
* `emit_custom_event` and `features.use_custom_parser` in `agent.yaml`.
|
|
31
|
+
* Gateway drops `chunk_type: "custom_event"` unless that feature is on.
|
|
32
|
+
* @param data Payload string for the event.
|
|
33
|
+
*
|
|
34
|
+
* Transport failures (including a non-2xx response) are logged at debug and
|
|
35
|
+
* swallowed — best-effort delivery must never abort the tool function. No-op
|
|
36
|
+
* outside an execution context.
|
|
37
|
+
*/
|
|
38
|
+
export declare function emit(event: string, data: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Emit a textual progress step from within a running tool function.
|
|
41
|
+
*
|
|
42
|
+
* Convenience wrapper around `emit("step", message)`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { emitStep } from "@mongodb-js/agent-engine-runner-shared";
|
|
47
|
+
*
|
|
48
|
+
* app.tool({ isLocal: false })(async function crawlWebsite(url: string) {
|
|
49
|
+
* await emitStep("Fetching page...");
|
|
50
|
+
* const html = await fetch(url);
|
|
51
|
+
* await emitStep(`Parsing links from ${url}...`);
|
|
52
|
+
* return parse(html);
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function emitStep(message: string): Promise<void>;
|
|
57
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../src/progress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA6EH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CrE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
|
package/dist/progress.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* emit / emitStep — send a mid-execution chunk from within a tool function.
|
|
3
|
+
*
|
|
4
|
+
* Tool functions running inside a Tool Pod call these to stream events to the
|
|
5
|
+
* client while the tool is still executing. Both executionId and oeUrl are
|
|
6
|
+
* injected into the execution context by the Tool Pod server before the tool
|
|
7
|
+
* runs (see `server/tool.ts`).
|
|
8
|
+
*
|
|
9
|
+
* The call is best-effort: network errors are logged and swallowed so a failed
|
|
10
|
+
* chunk emit never aborts the tool. Mirrors `agent_engine_runner_shared/progress.py`.
|
|
11
|
+
*
|
|
12
|
+
* Unlike the Python port there is no module-level client to pool: TLS agent
|
|
13
|
+
* reuse and cert-rotation invalidation are already handled by
|
|
14
|
+
* `getFetchOptionsWithTLS` (tls_client.ts), which caches one keep-alive agent
|
|
15
|
+
* per origin — so a plain `fetch` here reuses the same pooled connection the
|
|
16
|
+
* Python `_get_client` machinery provides.
|
|
17
|
+
*/
|
|
18
|
+
import { getCurrentExecutionId, getCurrentOeOwnerUrl, getCurrentOeUrl, reportOeOwnerUrlFailure, withExecutionSignal, } from "./context.js";
|
|
19
|
+
import { getLogger } from "./logger.js";
|
|
20
|
+
import { ownerDelivered } from "./owner_callback.js";
|
|
21
|
+
import { DONE, ERROR, STEP, SUBAGENT_END, SUBAGENT_START, TEXT, } from "./server/chunk_types.js";
|
|
22
|
+
import { fetchPlatform, getFetchOptionsWithTLS } from "./tls_client.js";
|
|
23
|
+
const logger = getLogger("agent_engine_runner_shared.progress");
|
|
24
|
+
// Short timeout: chunk emits are best-effort fire-and-forget. A slow or
|
|
25
|
+
// unreachable OE must not delay the tool function itself.
|
|
26
|
+
const PROGRESS_TIMEOUT_SECS = 5.0;
|
|
27
|
+
// Chunk types reserved for infrastructure use. Tool code emitting these would
|
|
28
|
+
// either close the SSE stream prematurely (DONE/ERROR are terminal) or spoof
|
|
29
|
+
// infrastructure-only chunk types (TEXT/SUBAGENT_*).
|
|
30
|
+
const RESERVED_EVENTS = new Set([
|
|
31
|
+
DONE,
|
|
32
|
+
ERROR,
|
|
33
|
+
TEXT,
|
|
34
|
+
SUBAGENT_START,
|
|
35
|
+
SUBAGENT_END,
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* POST `body` to `ownerUrl` first, falling back to `serviceUrl`.
|
|
39
|
+
*
|
|
40
|
+
* Owner preference per {@link ownerDelivered}: one best-effort attempt against
|
|
41
|
+
* the replica-specific owner URL; any owner failure falls back to the trusted
|
|
42
|
+
* service URL and latches via {@link reportOeOwnerUrlFailure} so later emits
|
|
43
|
+
* in this execution skip the owner instead of re-paying its timeout. Returns
|
|
44
|
+
* `null` when the owner delivered (nothing left to inspect), else the service
|
|
45
|
+
* response. Best-effort: the caller inspects `resp.ok` and swallows failures.
|
|
46
|
+
*/
|
|
47
|
+
async function postChunkOwnerFirst(serviceUrl, ownerUrl, body) {
|
|
48
|
+
const init = (url) => ({
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body,
|
|
52
|
+
signal: withExecutionSignal(AbortSignal.timeout(PROGRESS_TIMEOUT_SECS * 1000)),
|
|
53
|
+
...getFetchOptionsWithTLS(url),
|
|
54
|
+
});
|
|
55
|
+
if (ownerUrl !== null) {
|
|
56
|
+
if (await ownerDelivered(ownerUrl, () => init(ownerUrl), (msg) => logger.debug(`emit: ${msg}`))) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
reportOeOwnerUrlFailure();
|
|
60
|
+
}
|
|
61
|
+
return await fetchPlatform(serviceUrl, init(serviceUrl));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Emit a chunk of the given event type to the client stream.
|
|
65
|
+
*
|
|
66
|
+
* General-purpose API. For the common textual-step case, prefer
|
|
67
|
+
* {@link emitStep}.
|
|
68
|
+
*
|
|
69
|
+
* @param event Chunk type identifier (e.g. `"step"`). Reserved infrastructure
|
|
70
|
+
* event types (`done`, `error`, `text`, `subagent_start`, `subagent_end`)
|
|
71
|
+
* reject with an `Error` to prevent tool code from prematurely closing or
|
|
72
|
+
* spoofing the stream. The reserved-event check fires even outside an
|
|
73
|
+
* execution context — a programmer error wins over the no-op.
|
|
74
|
+
* `"custom_event"` is not Atlas Agent Engine custom events; those require
|
|
75
|
+
* `emit_custom_event` and `features.use_custom_parser` in `agent.yaml`.
|
|
76
|
+
* Gateway drops `chunk_type: "custom_event"` unless that feature is on.
|
|
77
|
+
* @param data Payload string for the event.
|
|
78
|
+
*
|
|
79
|
+
* Transport failures (including a non-2xx response) are logged at debug and
|
|
80
|
+
* swallowed — best-effort delivery must never abort the tool function. No-op
|
|
81
|
+
* outside an execution context.
|
|
82
|
+
*/
|
|
83
|
+
export async function emit(event, data) {
|
|
84
|
+
if (RESERVED_EVENTS.has(event)) {
|
|
85
|
+
throw new Error(`emit: event '${event}' is reserved for infrastructure use; ` +
|
|
86
|
+
`choose a non-terminal event type such as 'step'`);
|
|
87
|
+
}
|
|
88
|
+
const executionId = getCurrentExecutionId();
|
|
89
|
+
const oeUrl = getCurrentOeUrl();
|
|
90
|
+
const ownerUrl = getCurrentOeOwnerUrl();
|
|
91
|
+
if (!executionId || !oeUrl)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
const body = JSON.stringify({
|
|
95
|
+
execution_id: executionId,
|
|
96
|
+
chunk_type: event,
|
|
97
|
+
content: data,
|
|
98
|
+
metadata: {},
|
|
99
|
+
});
|
|
100
|
+
// Owner preference: the owner URL is already validated against oeUrl by the
|
|
101
|
+
// tool-pod server, so trust it as-is. Each request gets its own timeout
|
|
102
|
+
// signal combined with the execution-wide abort signal so an owner timeout
|
|
103
|
+
// cannot pre-abort the service fallback.
|
|
104
|
+
const resp = await postChunkOwnerFirst(`${oeUrl.replace(/\/$/, "")}/stream/chunk`, ownerUrl ? `${ownerUrl.replace(/\/$/, "")}/stream/chunk` : null, body);
|
|
105
|
+
if (resp !== null) {
|
|
106
|
+
// A non-2xx is surfaced at debug but not thrown — emit is fire-and-forget.
|
|
107
|
+
if (!resp.ok) {
|
|
108
|
+
logger.debug(`emit: OE returned HTTP ${resp.status} for chunk`);
|
|
109
|
+
}
|
|
110
|
+
// We never read the body; cancel it so undici can release/reuse the
|
|
111
|
+
// connection instead of leaking it under frequent emits.
|
|
112
|
+
await resp.body?.cancel();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (exc) {
|
|
116
|
+
// Best-effort: a failed chunk must never abort the tool function. Debug so
|
|
117
|
+
// operators can diagnose OE connectivity without noise.
|
|
118
|
+
logger.debug(`emit: failed to send chunk: ${String(exc)}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Emit a textual progress step from within a running tool function.
|
|
123
|
+
*
|
|
124
|
+
* Convenience wrapper around `emit("step", message)`.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { emitStep } from "@mongodb-js/agent-engine-runner-shared";
|
|
129
|
+
*
|
|
130
|
+
* app.tool({ isLocal: false })(async function crawlWebsite(url: string) {
|
|
131
|
+
* await emitStep("Fetching page...");
|
|
132
|
+
* const html = await fetch(url);
|
|
133
|
+
* await emitStep(`Parsing links from ${url}...`);
|
|
134
|
+
* return parse(html);
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export async function emitStep(message) {
|
|
139
|
+
await emit(STEP, message);
|
|
140
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TenantRuntime — framework-agnostic platform runtime for tenant agent
|
|
3
|
+
* applications.
|
|
4
|
+
*
|
|
5
|
+
* Port of `agent_engine_runner_shared/runtime.py`. Same Python class shape: the runtime
|
|
6
|
+
* discovers its role from `RUNNER_MODE`, wires logging / tracing / tools,
|
|
7
|
+
* and delegates to a framework SDK's `App` (the `GraphBuilderLike`) for
|
|
8
|
+
* graph construction.
|
|
9
|
+
*
|
|
10
|
+
* Scope deltas vs. Python (see `AGENTS.md` for rationale):
|
|
11
|
+
* - No memory-server mode (`RuntimeMode` has `AER`, `TOOL`, and `TOOL_FUNCTION`).
|
|
12
|
+
* - `setupTracing` owns the MongoClient build (async). Python builds it
|
|
13
|
+
* inline in `_setup_tracing` (sync pymongo).
|
|
14
|
+
* - `shutdown()` and SIGTERM/SIGINT wiring are TS additions — Python's
|
|
15
|
+
* uvicorn handles signals itself; here we explicitly close the tracing
|
|
16
|
+
* MongoClient before exit.
|
|
17
|
+
*/
|
|
18
|
+
import type { RuntimeAgentConfig } from "./agent_config.js";
|
|
19
|
+
import { MemoryWriter } from "./memory_writer.js";
|
|
20
|
+
import { type GraphBuilderLike, type ITenantRuntime, type ServerToolFn } from "./server/base.js";
|
|
21
|
+
import { RuntimeMode } from "./utils.js";
|
|
22
|
+
import type { BaseAgent, BaseExecutionCallback } from "@mongodb-js/agent-engine-sdk";
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the listen host from `APP_HOST`, defaulting to `"0.0.0.0"`.
|
|
25
|
+
*
|
|
26
|
+
* Matches Python's `_resolve_listen_host`: ECP stamps `APP_HOST` per
|
|
27
|
+
* executor type at deploy time (`"::"` for vm-mode, `"0.0.0.0"` for
|
|
28
|
+
* container-mode). Empty string normalises to the default — a shell that
|
|
29
|
+
* exports `APP_HOST=""` must not bind to `""`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveListenHost(): string;
|
|
32
|
+
/** Resolve the server drain budget without changing the existing Tool policy. */
|
|
33
|
+
export declare function shutdownGracePeriodMs(mode: RuntimeMode): number;
|
|
34
|
+
export interface TenantRuntimeOptions {
|
|
35
|
+
/** Application name. Defaults to `"Agent"`. */
|
|
36
|
+
appName?: string;
|
|
37
|
+
/** Application version. Defaults to `"1.0.0"`. */
|
|
38
|
+
appVersion?: string;
|
|
39
|
+
/** MongoDB URI used for trace persistence. Falls back to `MONGODB_URI`. */
|
|
40
|
+
mongodbUri?: string | null;
|
|
41
|
+
/** Explicit database name for trace storage. Defaults to the platform store. */
|
|
42
|
+
databaseName?: string | null;
|
|
43
|
+
/** Collection name for trace storage. Defaults to `"traces"`. */
|
|
44
|
+
tracesCollectionName?: string;
|
|
45
|
+
/** @deprecated Ignored. The org is taken from the `ORG_ID` env var, which the platform injects. */
|
|
46
|
+
orgId?: string | null;
|
|
47
|
+
/** @deprecated Ignored. The project is taken from the `PROJECT_ID` env var, which the platform injects. */
|
|
48
|
+
projectId?: string | null;
|
|
49
|
+
}
|
|
50
|
+
/** Public options for `registerAndRun`. */
|
|
51
|
+
export interface RegisterAndRunOptions {
|
|
52
|
+
/** Log level passed through to the underlying server. */
|
|
53
|
+
logLevel?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Tenant Runtime SDK.
|
|
57
|
+
*
|
|
58
|
+
* Constructed once per process. `registerAndRun` wires the framework SDK's
|
|
59
|
+
* graph builder and starts the per-mode Fastify server.
|
|
60
|
+
*/
|
|
61
|
+
export declare class TenantRuntime implements ITenantRuntime {
|
|
62
|
+
readonly appName: string;
|
|
63
|
+
readonly appVersion: string;
|
|
64
|
+
readonly mode: RuntimeMode;
|
|
65
|
+
readonly orgId: string | null;
|
|
66
|
+
readonly projectId: string | null;
|
|
67
|
+
readonly memoryWriter: MemoryWriter | null;
|
|
68
|
+
graphBuilder: GraphBuilderLike | null;
|
|
69
|
+
tools: Record<string, ServerToolFn>;
|
|
70
|
+
toolDefinitions: Record<string, Record<string, unknown>>;
|
|
71
|
+
private readonly agentConfig;
|
|
72
|
+
private readonly mongodbUri;
|
|
73
|
+
private readonly databaseNameOverride;
|
|
74
|
+
private readonly tracesCollectionName;
|
|
75
|
+
private shutdownStarted;
|
|
76
|
+
private tracingReady;
|
|
77
|
+
constructor(opts?: TenantRuntimeOptions);
|
|
78
|
+
/** Parsed `agent.yaml` configuration. */
|
|
79
|
+
getAgentConfig(): RuntimeAgentConfig;
|
|
80
|
+
/** Resolved MongoDB URI: constructor option > `MONGODB_URI` env var > null. */
|
|
81
|
+
getMongodbUri(): string | null;
|
|
82
|
+
private initTracing;
|
|
83
|
+
getAgent(opts?: {
|
|
84
|
+
callbacks?: BaseExecutionCallback[];
|
|
85
|
+
}): BaseAgent;
|
|
86
|
+
warmUpAgent(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get the current user_id from execution context.
|
|
89
|
+
*
|
|
90
|
+
* @returns User ID from the current execution context, or null if not available
|
|
91
|
+
*/
|
|
92
|
+
getCurrentUserId(): string | null;
|
|
93
|
+
getCurrentSessionId(): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Register a raw tool function and its metadata.
|
|
96
|
+
*
|
|
97
|
+
* This stores the function for Tool Pod execution and the metadata
|
|
98
|
+
* for routing decisions. It does NOT create any framework-specific
|
|
99
|
+
* tool objects — that is the responsibility of the framework SDK.
|
|
100
|
+
*
|
|
101
|
+
* @param name Tool name
|
|
102
|
+
* @param func Raw tool function
|
|
103
|
+
* @param metadata Tool metadata (is_local, network, timeout, etc.)
|
|
104
|
+
*/
|
|
105
|
+
registerTool(name: string, func: ServerToolFn, metadata: Record<string, unknown>): void;
|
|
106
|
+
/**
|
|
107
|
+
* Get metadata for a registered tool.
|
|
108
|
+
*
|
|
109
|
+
* @param name Tool name
|
|
110
|
+
* @returns Tool metadata object (is_local, network, timeout, etc.)
|
|
111
|
+
* or empty object if tool not found.
|
|
112
|
+
*/
|
|
113
|
+
getToolMetadata(name: string): Record<string, unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Close the tracing MongoClient. Idempotent — safe to call from multiple
|
|
116
|
+
* signal handlers. TS-only addition: Python's uvicorn handles SIGTERM
|
|
117
|
+
* itself, so the Python `TenantRuntime` has no equivalent method.
|
|
118
|
+
*/
|
|
119
|
+
shutdown(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Register the graph builder and start the mode-specific server.
|
|
122
|
+
*
|
|
123
|
+
* Resolves once Fastify is listening — the open socket keeps the Node
|
|
124
|
+
* event loop alive, matching the practical effect of Python's
|
|
125
|
+
* `asyncio.run(uvicorn.serve())` blocking until shutdown.
|
|
126
|
+
*/
|
|
127
|
+
registerAndRun(graphBuilder?: GraphBuilderLike | null, options?: RegisterAndRunOptions): Promise<void>;
|
|
128
|
+
private normalizeRunKwargs;
|
|
129
|
+
private runAsync;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAIL,WAAW,EAEZ,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAItC;;;;;;;GAO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