agentfootprint 9.6.0 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CLAUDE.md +1 -1
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/adapters/code/agentcore.js +294 -0
- package/dist/adapters/code/agentcore.js.map +1 -0
- package/dist/adapters/code/local.js +200 -0
- package/dist/adapters/code/local.js.map +1 -0
- package/dist/adapters/identity/vault.js +336 -0
- package/dist/adapters/identity/vault.js.map +1 -0
- package/dist/adapters/observability/file.js +307 -0
- package/dist/adapters/observability/file.js.map +1 -0
- package/dist/core/Agent.js +132 -0
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/RunnerBase.js +67 -0
- package/dist/core/RunnerBase.js.map +1 -1
- package/dist/core/agent/stages/toolCalls.js +90 -0
- package/dist/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/core/codeRunnerTool.js +252 -0
- package/dist/core/codeRunnerTool.js.map +1 -0
- package/dist/core/toolSessions.js +396 -0
- package/dist/core/toolSessions.js.map +1 -0
- package/dist/core/tools.js.map +1 -1
- package/dist/doors/providers.js +13 -0
- package/dist/doors/providers.js.map +1 -1
- package/dist/esm/adapters/code/agentcore.d.ts +133 -0
- package/dist/esm/adapters/code/agentcore.js +290 -0
- package/dist/esm/adapters/code/agentcore.js.map +1 -0
- package/dist/esm/adapters/code/local.d.ts +99 -0
- package/dist/esm/adapters/code/local.js +196 -0
- package/dist/esm/adapters/code/local.js.map +1 -0
- package/dist/esm/adapters/identity/vault.d.ts +146 -0
- package/dist/esm/adapters/identity/vault.js +332 -0
- package/dist/esm/adapters/identity/vault.js.map +1 -0
- package/dist/esm/adapters/observability/file.d.ts +145 -0
- package/dist/esm/adapters/observability/file.js +303 -0
- package/dist/esm/adapters/observability/file.js.map +1 -0
- package/dist/esm/adapters/types.d.ts +87 -0
- package/dist/esm/core/Agent.d.ts +65 -0
- package/dist/esm/core/Agent.js +133 -1
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/RunnerBase.d.ts +51 -0
- package/dist/esm/core/RunnerBase.js +67 -0
- package/dist/esm/core/RunnerBase.js.map +1 -1
- package/dist/esm/core/agent/stages/toolCalls.d.ts +31 -0
- package/dist/esm/core/agent/stages/toolCalls.js +90 -0
- package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +23 -2
- package/dist/esm/core/codeRunnerTool.d.ts +120 -0
- package/dist/esm/core/codeRunnerTool.js +247 -0
- package/dist/esm/core/codeRunnerTool.js.map +1 -0
- package/dist/esm/core/toolSessions.d.ts +318 -0
- package/dist/esm/core/toolSessions.js +389 -0
- package/dist/esm/core/toolSessions.js.map +1 -0
- package/dist/esm/core/tools.d.ts +60 -0
- package/dist/esm/core/tools.js.map +1 -1
- package/dist/esm/doors/providers.d.ts +7 -0
- package/dist/esm/doors/providers.js +10 -0
- package/dist/esm/doors/providers.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +50 -0
- package/dist/esm/events/registry.d.ts +9 -1
- package/dist/esm/events/registry.js +8 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/identity.d.ts +1 -0
- package/dist/esm/identity.js +4 -0
- package/dist/esm/identity.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/mcp/mcpServe.js +37 -1
- package/dist/esm/lib/mcp/mcpServe.js.map +1 -1
- package/dist/esm/lib/trace-toolpack/traceToolpack.js +15 -1
- package/dist/esm/lib/trace-toolpack/traceToolpack.js.map +1 -1
- package/dist/esm/observability-providers.d.ts +4 -1
- package/dist/esm/observability-providers.js +7 -1
- package/dist/esm/observability-providers.js.map +1 -1
- package/dist/events/registry.js +8 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/identity.js +6 -1
- package/dist/identity.js.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/mcp/mcpServe.js +37 -1
- package/dist/lib/mcp/mcpServe.js.map +1 -1
- package/dist/lib/trace-toolpack/traceToolpack.js +15 -1
- package/dist/lib/trace-toolpack/traceToolpack.js.map +1 -1
- package/dist/observability-providers.js +9 -2
- package/dist/observability-providers.js.map +1 -1
- package/dist/types/adapters/code/agentcore.d.ts +134 -0
- package/dist/types/adapters/code/agentcore.d.ts.map +1 -0
- package/dist/types/adapters/code/local.d.ts +100 -0
- package/dist/types/adapters/code/local.d.ts.map +1 -0
- package/dist/types/adapters/identity/vault.d.ts +147 -0
- package/dist/types/adapters/identity/vault.d.ts.map +1 -0
- package/dist/types/adapters/observability/file.d.ts +146 -0
- package/dist/types/adapters/observability/file.d.ts.map +1 -0
- package/dist/types/adapters/types.d.ts +87 -0
- package/dist/types/adapters/types.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +65 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/RunnerBase.d.ts +51 -0
- package/dist/types/core/RunnerBase.d.ts.map +1 -1
- package/dist/types/core/agent/stages/toolCalls.d.ts +31 -0
- package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +23 -2
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/codeRunnerTool.d.ts +121 -0
- package/dist/types/core/codeRunnerTool.d.ts.map +1 -0
- package/dist/types/core/toolSessions.d.ts +319 -0
- package/dist/types/core/toolSessions.d.ts.map +1 -0
- package/dist/types/core/tools.d.ts +60 -0
- package/dist/types/core/tools.d.ts.map +1 -1
- package/dist/types/doors/providers.d.ts +7 -0
- package/dist/types/doors/providers.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +50 -0
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +9 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/identity.d.ts +1 -0
- package/dist/types/identity.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -1
- package/dist/types/lib/trace-toolpack/traceToolpack.d.ts.map +1 -1
- package/dist/types/observability-providers.d.ts +4 -1
- package/dist/types/observability-providers.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentCoreCodeRunner — AWS Bedrock AgentCore Code Interpreter behind the
|
|
3
|
+
* {@link CodeRunner} port (peer-dep `@aws-sdk/client-bedrock-agentcore`).
|
|
4
|
+
*
|
|
5
|
+
* import { agentCoreCodeRunner } from 'agentfootprint/providers';
|
|
6
|
+
* const runner = agentCoreCodeRunner({ region: 'us-east-1', identifier: 'aws.codeinterpreter.v1' });
|
|
7
|
+
*
|
|
8
|
+
* A REAL sandbox, which is the point: `localCodeRunner` gives you process
|
|
9
|
+
* isolation on your own machine and says so; this gives you a managed,
|
|
10
|
+
* network-and-filesystem-isolated environment, and the tool code is identical
|
|
11
|
+
* across the swap.
|
|
12
|
+
*
|
|
13
|
+
* ── The three operations, verified against the SDK ──────────────────────────
|
|
14
|
+
* Pinned in `test/adapters/aws/awsCommandPin.ts`, and verified against a real
|
|
15
|
+
* install of `@aws-sdk/client-bedrock-agentcore` 3.1108.0:
|
|
16
|
+
*
|
|
17
|
+
* • `StartCodeInterpreterSessionCommand`
|
|
18
|
+
* in `{ codeInterpreterIdentifier, name?, sessionTimeoutSeconds? }`
|
|
19
|
+
* out `{ codeInterpreterIdentifier, sessionId, createdAt }`
|
|
20
|
+
* • `InvokeCodeInterpreterCommand`
|
|
21
|
+
* in `{ codeInterpreterIdentifier, sessionId, name: 'executeCode',
|
|
22
|
+
* arguments: { code, language } }`
|
|
23
|
+
* out `{ sessionId, stream }` — an **event stream**, not a body (below)
|
|
24
|
+
* • `StopCodeInterpreterSessionCommand`
|
|
25
|
+
* in `{ codeInterpreterIdentifier, sessionId }` ← the session ID, not a URI
|
|
26
|
+
* out `{ codeInterpreterIdentifier, sessionId, lastUpdatedAt }`
|
|
27
|
+
*
|
|
28
|
+
* **`Invoke` answers with an `AsyncIterable`.** `InvokeCodeInterpreterResponse`
|
|
29
|
+
* is `{ sessionId?, stream?: AsyncIterable<CodeInterpreterStreamOutput> }`, and
|
|
30
|
+
* every member of that union is either `{ result }` or a modelled EXCEPTION —
|
|
31
|
+
* `accessDeniedException`, `throttlingException`, `validationException`, and
|
|
32
|
+
* four more. An adapter that read a `body` field would find `undefined` and
|
|
33
|
+
* report an empty success on every call, and one that iterated only for
|
|
34
|
+
* `result` would treat an AccessDenied as "the code printed nothing." So this
|
|
35
|
+
* drains the stream, raises the exception members BY NAME, and folds the
|
|
36
|
+
* result members into one `CodeResult`.
|
|
37
|
+
*
|
|
38
|
+
* The payload lands twice: `structuredContent` carries `{ stdout, stderr,
|
|
39
|
+
* exitCode, executionTime }` and `content[]` carries typed blocks. The
|
|
40
|
+
* structured half is preferred because it is typed; the text blocks are the
|
|
41
|
+
* fallback for a response that only filled the other one.
|
|
42
|
+
*
|
|
43
|
+
* ── How this talks to the SDK (the 9.4.0 law) ───────────────────────────────
|
|
44
|
+
* Through `client.send(new SomeCommand(input))`, never a method on the client.
|
|
45
|
+
* A bare `@aws-sdk/client-*` **Client is command-based**: its prototype carries
|
|
46
|
+
* `send` and `destroy` and nothing else — verified again for this adapter
|
|
47
|
+
* (`BedrockAgentCoreClient.prototype.startCodeInterpreterSession` is
|
|
48
|
+
* `undefined`; the shortcut exists only on the aggregated `BedrockAgentCore`).
|
|
49
|
+
* Three adapters have shipped that bug in this package.
|
|
50
|
+
*
|
|
51
|
+
* ── Credentials ─────────────────────────────────────────────────────────────
|
|
52
|
+
* Standard AWS credential resolution (the SDK's own chain). A tool holding a
|
|
53
|
+
* long-lived session must NOT cache a `Credential` object from `ctx.credential`
|
|
54
|
+
* past the call that produced it — a session outliving a run outlives its
|
|
55
|
+
* token. Re-resolve per execute through `ctx.credentials`.
|
|
56
|
+
*
|
|
57
|
+
* Pattern: Adapter (GoF) + lazy peer-dep load — the SDK is required only when
|
|
58
|
+
* `start()` first runs (or never, if you inject `_client` / `_sdk`).
|
|
59
|
+
*/
|
|
60
|
+
import type { CodeRunner } from '../types.js';
|
|
61
|
+
export interface AgentCoreCodeRunnerOptions {
|
|
62
|
+
readonly region?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The code-interpreter resource to run in — AWS's built-in
|
|
65
|
+
* (`'aws.codeinterpreter.v1'`) or your own custom interpreter's identifier.
|
|
66
|
+
*/
|
|
67
|
+
readonly identifier: string;
|
|
68
|
+
/**
|
|
69
|
+
* Session TTL in seconds. AgentCore terminates the session past it regardless
|
|
70
|
+
* of activity. Service default 900 (15 min); max 28,800 (8 h).
|
|
71
|
+
*
|
|
72
|
+
* **This is why "already gone" is a normal outcome, not an incident**: the
|
|
73
|
+
* far side reaps on its own schedule, so a `Stop` may arrive after AWS has
|
|
74
|
+
* already collected the session. `stop()` treats that as done.
|
|
75
|
+
*/
|
|
76
|
+
readonly sessionTimeoutSeconds?: number;
|
|
77
|
+
/** Default language when a call does not name one. `'python'` (the service
|
|
78
|
+
* accepts `javascript`, `python`, `typescript`). */
|
|
79
|
+
readonly language?: string;
|
|
80
|
+
/** Per-stream output ceiling, in characters. Default 8000; anything cut is
|
|
81
|
+
* REPORTED on `CodeResult.truncated`, never dropped quietly. */
|
|
82
|
+
readonly maxOutputChars?: number;
|
|
83
|
+
/** Stable id (default `'agentcore-code-runner'`). Rides the session events. */
|
|
84
|
+
readonly id?: string;
|
|
85
|
+
/** Test seam — inject a client implementing {@link AgentCoreCodeClientLike}.
|
|
86
|
+
* Bypasses the SDK entirely; the field mapping below is then yours. */
|
|
87
|
+
readonly _client?: AgentCoreCodeClientLike;
|
|
88
|
+
/** @internal Test injection — the AWS SDK module, to exercise the real shim
|
|
89
|
+
* (`send(new Command(...))`) with a fake SDK. */
|
|
90
|
+
readonly _sdk?: BedrockAgentCoreCodeSdkModule;
|
|
91
|
+
}
|
|
92
|
+
/** The operation-semantic surface this adapter calls. */
|
|
93
|
+
export interface AgentCoreCodeClientLike {
|
|
94
|
+
startSession(input: {
|
|
95
|
+
readonly codeInterpreterIdentifier: string;
|
|
96
|
+
readonly name?: string;
|
|
97
|
+
readonly sessionTimeoutSeconds?: number;
|
|
98
|
+
}): Promise<{
|
|
99
|
+
readonly sessionId?: string;
|
|
100
|
+
}>;
|
|
101
|
+
invoke(input: {
|
|
102
|
+
readonly codeInterpreterIdentifier: string;
|
|
103
|
+
readonly sessionId: string;
|
|
104
|
+
readonly name: string;
|
|
105
|
+
readonly arguments: {
|
|
106
|
+
readonly code: string;
|
|
107
|
+
readonly language?: string;
|
|
108
|
+
};
|
|
109
|
+
}): Promise<AgentCoreInvokeAnswer>;
|
|
110
|
+
stopSession(input: {
|
|
111
|
+
readonly codeInterpreterIdentifier: string;
|
|
112
|
+
readonly sessionId: string;
|
|
113
|
+
}): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
/** What `invoke` reports back, already drained of its event stream. */
|
|
116
|
+
export interface AgentCoreInvokeAnswer {
|
|
117
|
+
readonly stdout: string;
|
|
118
|
+
readonly stderr: string;
|
|
119
|
+
readonly exitCode?: number;
|
|
120
|
+
readonly isError?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** The slice of `@aws-sdk/client-bedrock-agentcore` this shim touches. */
|
|
123
|
+
export interface BedrockAgentCoreCodeSdkModule {
|
|
124
|
+
readonly BedrockAgentCoreClient?: new (config: {
|
|
125
|
+
region?: string;
|
|
126
|
+
}) => {
|
|
127
|
+
send(cmd: unknown): Promise<unknown>;
|
|
128
|
+
};
|
|
129
|
+
readonly StartCodeInterpreterSessionCommand?: new (input: unknown) => unknown;
|
|
130
|
+
readonly InvokeCodeInterpreterCommand?: new (input: unknown) => unknown;
|
|
131
|
+
readonly StopCodeInterpreterSessionCommand?: new (input: unknown) => unknown;
|
|
132
|
+
}
|
|
133
|
+
export declare function agentCoreCodeRunner(options: AgentCoreCodeRunnerOptions): CodeRunner;
|
|
134
|
+
//# sourceMappingURL=agentcore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentcore.d.ts","sourceRoot":"","sources":["../../../../src/adapters/code/agentcore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EAAc,UAAU,EAAe,MAAM,aAAa,CAAC;AAGvE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B;;;;;;;OAOG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACxC;yDACqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;qEACiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB;4EACwE;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAC3C;sDACkD;IAClD,QAAQ,CAAC,IAAI,CAAC,EAAE,6BAA6B,CAAC;CAC/C;AAED,yDAAyD;AACzD,MAAM,WAAW,uBAAuB;IACtC,YAAY,CAAC,KAAK,EAAE;QAClB,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;QAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;KACzC,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE;QACZ,QAAQ,CAAC,yBAAyB,EAAE,MA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CAyFnF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* localCodeRunner — run code in a child process, on this machine.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: Adapter (GoF) over `node:child_process`.
|
|
5
|
+
* Role: the dev default behind the {@link CodeRunner} port. `agentCoreCodeRunner`
|
|
6
|
+
* is the production swap; the tool code does not change.
|
|
7
|
+
* Emits: nothing. The tool that owns the session emits.
|
|
8
|
+
*
|
|
9
|
+
* ── ISOLATION, NOT A SANDBOX. Read this before deploying it. ────────────────
|
|
10
|
+
* The name is `localCodeRunner`, never `sandboxedCodeRunner`, and the
|
|
11
|
+
* difference is not modesty — it is the whole security posture.
|
|
12
|
+
*
|
|
13
|
+
* What a child process DOES give you:
|
|
14
|
+
* • a separate process and heap — a crash or an OOM takes the child, not you;
|
|
15
|
+
* • kill on timeout, so runaway code has a ceiling;
|
|
16
|
+
* • no inherited stdin, so nothing can block waiting for a terminal;
|
|
17
|
+
* • an environment ALLOWLIST — `process.env` is not inherited (only `PATH`,
|
|
18
|
+
* so the interpreter can be found), so an `AWS_SECRET_ACCESS_KEY` in your
|
|
19
|
+
* shell is not in the model's reach;
|
|
20
|
+
* • a working directory, by convention.
|
|
21
|
+
*
|
|
22
|
+
* What it does NOT give you, at all:
|
|
23
|
+
* • a filesystem jail — the code can read and write anywhere this process can;
|
|
24
|
+
* • a network jail — it can call out;
|
|
25
|
+
* • CPU or memory limits beyond the timeout;
|
|
26
|
+
* • any protection from code that deletes something outside `cwd`.
|
|
27
|
+
*
|
|
28
|
+
* So: a development loop, a trusted-input pipeline, a machine you would be
|
|
29
|
+
* relaxed about a shell script running on. NOT arbitrary model-written code
|
|
30
|
+
* from an untrusted user, on a host with anything on it. For that, run a real
|
|
31
|
+
* sandbox behind the same port — `agentCoreCodeRunner`, a gVisor container, a
|
|
32
|
+
* Firecracker VM — and keep the tool identical.
|
|
33
|
+
*
|
|
34
|
+
* **In-process `eval` / `node:vm` is refused outright.** Node's own
|
|
35
|
+
* documentation says `vm` is not a security mechanism ("do not use it to run
|
|
36
|
+
* untrusted code"), so shipping it as one would be theater: the same code
|
|
37
|
+
* reaching the same globals, wearing a word that makes a reader stop checking.
|
|
38
|
+
* A subprocess is genuinely a boundary; it is just a smaller one than the word
|
|
39
|
+
* "sandbox" implies. The library teaches refusals for things that are WRONG and
|
|
40
|
+
* honest names for things that are merely LIMITED — running local code in a dev
|
|
41
|
+
* loop is not wrong, and calling it a sandbox is.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const agent = Agent.create({ provider })
|
|
45
|
+
* .tool(codeRunnerTool({ runner: localCodeRunner() }))
|
|
46
|
+
* .build();
|
|
47
|
+
*/
|
|
48
|
+
import type { CodeRunner } from '../types.js';
|
|
49
|
+
export interface LocalCodeRunnerOptions {
|
|
50
|
+
/**
|
|
51
|
+
* How to run a snippet, as `[command, ...args]` — the code is appended as the
|
|
52
|
+
* final argument. Defaults by language: `['node', '-e']` for javascript,
|
|
53
|
+
* `['python3', '-c']` for python.
|
|
54
|
+
*/
|
|
55
|
+
readonly command?: readonly string[];
|
|
56
|
+
/** Working directory for the child. Defaults to `process.cwd()`. */
|
|
57
|
+
readonly cwd?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The child's environment. An ALLOWLIST, never a merge: `process.env` is NOT
|
|
60
|
+
* inherited, so a credential sitting in this process's environment is not
|
|
61
|
+
* handed to model-written code by default. Pass exactly what the code needs.
|
|
62
|
+
*
|
|
63
|
+
* ONE exception, stated because an unstated one is a hole: `PATH` is passed
|
|
64
|
+
* through, because without it the operating system cannot find the
|
|
65
|
+
* interpreter and nothing runs at all. `PATH` names directories, not secrets.
|
|
66
|
+
* Set `env: { PATH: '/usr/bin' }` to narrow it, or `env: { PATH: '' }` to
|
|
67
|
+
* refuse even that — anything you supply here WINS over the inherited value.
|
|
68
|
+
*/
|
|
69
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
70
|
+
/** Per-execution ceiling; the child is killed past it. Default 30s. */
|
|
71
|
+
readonly timeoutMs?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Per-stream output ceiling, in characters. Default 8000.
|
|
74
|
+
*
|
|
75
|
+
* Cutting is allowed; cutting SILENTLY is not — anything cut is reported on
|
|
76
|
+
* `CodeResult.truncated`, and `codeRunnerTool` renders that as a visible
|
|
77
|
+
* marker in the tool result. The model has to know the table it is about to
|
|
78
|
+
* reason over is a fragment.
|
|
79
|
+
*/
|
|
80
|
+
readonly maxOutputChars?: number;
|
|
81
|
+
/** Stable id (default `'local-code-runner'`). Rides the session events. */
|
|
82
|
+
readonly id?: string;
|
|
83
|
+
/** @internal Test seam — the `node:child_process` module. */
|
|
84
|
+
readonly _childProcess?: ChildProcessModuleLike;
|
|
85
|
+
}
|
|
86
|
+
/** The slice of `node:child_process` this adapter touches. */
|
|
87
|
+
export interface ChildProcessModuleLike {
|
|
88
|
+
readonly execFile?: (file: string, args: readonly string[], options: {
|
|
89
|
+
cwd?: string;
|
|
90
|
+
env?: Record<string, string>;
|
|
91
|
+
timeout?: number;
|
|
92
|
+
maxBuffer?: number;
|
|
93
|
+
signal?: AbortSignal;
|
|
94
|
+
}, callback: (error: (Error & {
|
|
95
|
+
code?: number | string;
|
|
96
|
+
killed?: boolean;
|
|
97
|
+
}) | null, stdout: string, stderr: string) => void) => unknown;
|
|
98
|
+
}
|
|
99
|
+
export declare function localCodeRunner(options?: LocalCodeRunnerOptions): CodeRunner;
|
|
100
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../../src/adapters/code/local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,KAAK,EAAc,UAAU,EAAe,MAAM,aAAa,CAAC;AAGvE,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,QAAQ,CAAC,OAAO,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aultCredentials — a {@link CredentialProvider} over a HashiCorp-Vault-compatible
|
|
3
|
+
* KV v2 secret store, spoken as plain HTTP.
|
|
4
|
+
*
|
|
5
|
+
* import { vaultCredentials } from 'agentfootprint/security';
|
|
6
|
+
*
|
|
7
|
+
* const credentials = vaultCredentials({
|
|
8
|
+
* address: 'https://vault.internal:8200', // https, or say `allowHttp` out loud
|
|
9
|
+
* mount: 'secret', // KV v2 mount, default 'secret'
|
|
10
|
+
* paths: { github: 'ci/github' }, // service → path INSIDE the mount
|
|
11
|
+
* }); // token: VAULT_TOKEN, or `token`
|
|
12
|
+
*
|
|
13
|
+
* Zero dependencies and no SDK: one `GET` per resolution through the runtime's
|
|
14
|
+
* own `fetch`. Vault's HTTP API is small, stable and the thing every
|
|
15
|
+
* Vault-compatible store (OpenBao, and the Vault-API modes of several managed
|
|
16
|
+
* stores) implements — so the adapter that speaks HTTP works against more
|
|
17
|
+
* backends than the adapter that imports one vendor's client.
|
|
18
|
+
*
|
|
19
|
+
* ## V1 is deliberately one shape, and says so by name
|
|
20
|
+
*
|
|
21
|
+
* | Axis | V1 | Anything else |
|
|
22
|
+
* |---|---|---|
|
|
23
|
+
* | Auth | a **token** (`token` option, else `VAULT_TOKEN`) | AppRole / Kubernetes / JWT / AWS IAM login are **refused by name**, naming the option that would carry them |
|
|
24
|
+
* | Secret engine | **KV v2** (`<mount>/data/<path>`, the `data.data` envelope) | a KV v1 mount is refused by name once the response shape gives it away |
|
|
25
|
+
* | Leases / renewal | **none** — every `getCredential` re-reads the secret | a lease-aware provider is a different object, and the library's model since 9.7.0 is re-resolve-per-call |
|
|
26
|
+
*
|
|
27
|
+
* That is not modesty, it is the honest edge: an auth method the author cannot
|
|
28
|
+
* exercise against a real cluster would be a guess wearing an adapter's clothes.
|
|
29
|
+
* Each refusal names the option it would arrive on, so "tell us your auth shape"
|
|
30
|
+
* is a field report rather than an issue title.
|
|
31
|
+
*
|
|
32
|
+
* ## Field → credential kind
|
|
33
|
+
*
|
|
34
|
+
* A KV v2 read returns `{ data: { data: { …your fields… }, metadata: {…} } }`.
|
|
35
|
+
* The inner object is mapped to a {@link Credential} by the FIRST rule that
|
|
36
|
+
* matches, so a secret written the ordinary way needs no configuration:
|
|
37
|
+
*
|
|
38
|
+
* | Fields present | Becomes | Header it applies |
|
|
39
|
+
* |---|---|---|
|
|
40
|
+
* | `token` | `bearer(token)` | `authorization: Bearer …` |
|
|
41
|
+
* | `api_key` \| `apiKey` \| `key` | `apiKey(value, header ?? 'x-api-key')` | that header |
|
|
42
|
+
* | `username` + `password` | `basic(username, password)` | `authorization: Basic …` |
|
|
43
|
+
* | `headers` (an object of strings) | `headers(map)` | all of them |
|
|
44
|
+
*
|
|
45
|
+
* A secret matching none of them is refused — naming the PATH and the four
|
|
46
|
+
* shapes, never the secret. `toCredential` is the seam for a shop whose fields
|
|
47
|
+
* are named otherwise; it sees the secret and returns a `Credential`, and
|
|
48
|
+
* returning `undefined` falls back to the table above.
|
|
49
|
+
*
|
|
50
|
+
* ## Secrecy (the 8.6.0 two-clause law, applied here)
|
|
51
|
+
*
|
|
52
|
+
* A thrown message reaches the model as a tool result AND rides
|
|
53
|
+
* `agentfootprint.credential.failed`. So every error this adapter raises names
|
|
54
|
+
* **the service, the path and the HTTP status, and nothing from the response
|
|
55
|
+
* body or the token**. Nothing here logs, and no secret value, no `X-Vault-Token`
|
|
56
|
+
* header and no field name from the payload appears in any message it can throw
|
|
57
|
+
* — pinned by a grep-shaped test over every failure path. The credential it
|
|
58
|
+
* returns hides its own secret fields (non-enumerable) and carries `toHeaders`,
|
|
59
|
+
* so `structuredClone` rejects it and it cannot enter tracked scope by accident.
|
|
60
|
+
*
|
|
61
|
+
* @example Dev → prod is the same two lines
|
|
62
|
+
* ```ts
|
|
63
|
+
* // dev
|
|
64
|
+
* const credentials = staticTokens({ github: 'ghp_dev_xxx' });
|
|
65
|
+
* // prod — the tool code does not change
|
|
66
|
+
* const credentials = vaultCredentials({ address: process.env.VAULT_ADDR! });
|
|
67
|
+
* Agent.create({ provider, model, credentials }).build();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
import type { Credential, CredentialProvider } from '../../identity/types.js';
|
|
71
|
+
/** The base options every form shares. */
|
|
72
|
+
interface VaultCredentialsBase {
|
|
73
|
+
/** Vault's base URL, e.g. `https://vault.internal:8200` — **required**, and
|
|
74
|
+
* **https** unless {@link VaultCredentialsBase.allowHttp} says otherwise. No
|
|
75
|
+
* `VAULT_ADDR` fallback: an agent that silently picks up an address from the
|
|
76
|
+
* environment is an agent that reads a different vault when the environment
|
|
77
|
+
* changes under it. Name it. */
|
|
78
|
+
readonly address: string;
|
|
79
|
+
/** The Vault token. Falls back to `VAULT_TOKEN` (the variable every Vault
|
|
80
|
+
* tool already sets). This is a secret: it is sent as `X-Vault-Token` and
|
|
81
|
+
* appears in no message this adapter can throw. */
|
|
82
|
+
readonly token?: string;
|
|
83
|
+
/** Auth method. **`'token'` is the only one V1 implements.** Anything else is
|
|
84
|
+
* refused at construction, by name, with what it would take — see
|
|
85
|
+
* {@link vaultCredentials}. */
|
|
86
|
+
readonly auth?: 'token';
|
|
87
|
+
/** KV v2 mount point. Default `'secret'` (Vault's own default for the KV v2
|
|
88
|
+
* engine). The read URL is `<address>/v1/<mount>/data/<path>`. */
|
|
89
|
+
readonly mount?: string;
|
|
90
|
+
/** Vault Enterprise / HCP namespace, sent as `X-Vault-Namespace`. Omit for
|
|
91
|
+
* open-source Vault and OpenBao, which have no namespaces. */
|
|
92
|
+
readonly namespace?: string;
|
|
93
|
+
/** Map the secret's fields to a {@link Credential} yourself. Returns
|
|
94
|
+
* `undefined` to fall back to the built-in table (`token` / `api_key` /
|
|
95
|
+
* `username`+`password` / `headers`). The seam for a shop whose field names
|
|
96
|
+
* are its own — and the reason this adapter does not need an option per
|
|
97
|
+
* spelling. **Never log or return the fields from here**; they are the
|
|
98
|
+
* secret. */
|
|
99
|
+
readonly toCredential?: (secret: Readonly<Record<string, unknown>>, service: string) => Credential | undefined;
|
|
100
|
+
/** Header name for the `api_key` shape when the secret does not carry its own
|
|
101
|
+
* `header` field. Default `'x-api-key'`. */
|
|
102
|
+
readonly apiKeyHeader?: string;
|
|
103
|
+
/** Request timeout in ms. Default 5000 — a credential resolution sits in
|
|
104
|
+
* front of a tool call, so a hung vault must fail rather than hang a run. */
|
|
105
|
+
readonly timeoutMs?: number;
|
|
106
|
+
/** Allow a plain-`http://` address. **Refused unless you set this**, because
|
|
107
|
+
* the Vault token travels in a request header: over plaintext HTTP, anyone
|
|
108
|
+
* on the path reads a token that can usually read every secret it can reach.
|
|
109
|
+
* Set it only for a loopback dev server (`http://127.0.0.1:8200`). */
|
|
110
|
+
readonly allowHttp?: boolean;
|
|
111
|
+
/** Stable provider id (default `'vault'`). Shows up in "which provider vended
|
|
112
|
+
* this". */
|
|
113
|
+
readonly id?: string;
|
|
114
|
+
/** Test seam — inject `fetch`. Bypasses the network entirely. */
|
|
115
|
+
readonly _fetch?: typeof fetch;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* How a `service` becomes a path inside the mount. Three arms, and they
|
|
119
|
+
* EXCLUDE each other — two spellings of one rule can disagree, so the type
|
|
120
|
+
* refuses the pair and so does the constructor.
|
|
121
|
+
*/
|
|
122
|
+
type VaultPathMapping = {
|
|
123
|
+
/** `service → path inside the mount`, the {@link staticTokens} shape one
|
|
124
|
+
* level up: the same literal map, holding a path instead of a token. An
|
|
125
|
+
* unknown service is refused by name, listing the known ones. */
|
|
126
|
+
readonly paths: Readonly<Record<string, string>>;
|
|
127
|
+
readonly resolve?: never;
|
|
128
|
+
} | {
|
|
129
|
+
/** `service → path`, computed. Return `undefined` to refuse a service.
|
|
130
|
+
* For the convention-driven shop: ``(s) => `agents/${s}` ``. */
|
|
131
|
+
readonly resolve: (service: string) => string | undefined;
|
|
132
|
+
readonly paths?: never;
|
|
133
|
+
} | {
|
|
134
|
+
/** Neither: the **service id IS the path** under the mount, so
|
|
135
|
+
* `service: 'github'` reads `<mount>/data/github`. */
|
|
136
|
+
readonly paths?: undefined;
|
|
137
|
+
readonly resolve?: undefined;
|
|
138
|
+
};
|
|
139
|
+
export type VaultCredentialsOptions = VaultCredentialsBase & VaultPathMapping;
|
|
140
|
+
/**
|
|
141
|
+
* Build a {@link CredentialProvider} that reads KV v2 secrets from a
|
|
142
|
+
* Vault-compatible store. See {@link VaultCredentialsOptions} for the
|
|
143
|
+
* per-option contract and this module's docstring for the V1 boundary.
|
|
144
|
+
*/
|
|
145
|
+
export declare function vaultCredentials(options: VaultCredentialsOptions): CredentialProvider;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=vault.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../../../../src/adapters/identity/vault.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAGnB,MAAM,yBAAyB,CAAC;AAKjC,0CAA0C;AAC1C,UAAU,oBAAoB;IAC5B;;;;qCAIiC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;wDAEoD;IACpD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;oCAEgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;uEACmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;mEAC+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;;kBAKc;IACd,QAAQ,CAAC,YAAY,CAAC,EAAE,CACtB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,OAAO,EAAE,MAAM,KACZ,UAAU,GAAG,SAAS,CAAC;IAC5B;iDAC6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;kFAC8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;2EAGuE;IACvE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;iBACa;IACb,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,CAAC;CAChC;AAED;;;;GAIG;AACH,KAAK,gBAAgB,GACjB;IACE;;sEAEkE;IAClE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;CAC1B,GACD;IACE;qEACiE;IACjE,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB,GACD;IACE;2DACuD;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC;CAC9B,CAAC;AAEN,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,GAAG,gBAAgB,CAAC;AAmB9E;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,kBAAkB,CAoIrF"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fileObservability — the typed event stream, one JSON line per event, in a
|
|
3
|
+
* local file.
|
|
4
|
+
*
|
|
5
|
+
* The sink for the shop that has no collector. Every other adapter in this
|
|
6
|
+
* folder ships somewhere: CloudWatch, X-Ray, an OTLP endpoint. A great many
|
|
7
|
+
* on-premises deployments have none of those — they have a directory, a log
|
|
8
|
+
* shipper (Filebeat, Fluent Bit, Vector, `promtail`, `journald`, or a person
|
|
9
|
+
* with `grep`), and a rule that nothing leaves the network. NDJSON on disk is
|
|
10
|
+
* the format all of those already read, so the sink is the file.
|
|
11
|
+
*
|
|
12
|
+
* Zero dependencies: `node:fs`, lazily required at construction so merely
|
|
13
|
+
* importing `agentfootprint/observe` stays browser-safe (this factory is
|
|
14
|
+
* Node-only; calling it in a browser throws by name).
|
|
15
|
+
*
|
|
16
|
+
* ## The line
|
|
17
|
+
*
|
|
18
|
+
* One `JSON.stringify(event)` per line, newline-terminated, appended in
|
|
19
|
+
* dispatch order — the SAME envelope `cloudwatchObservability` puts in a log
|
|
20
|
+
* event, so a query written against one reads the other:
|
|
21
|
+
*
|
|
22
|
+
* ```jsonl
|
|
23
|
+
* {"type":"agentfootprint.agent.turn_start","payload":{…},"meta":{"runId":"…","sessionId":"…"}}
|
|
24
|
+
* {"type":"agentfootprint.stream.tool_end","payload":{…},"meta":{…}}
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Nothing is summarized, bounded or redacted on the way out. **A payload that
|
|
28
|
+
* must not be on that disk must not reach this strategy** — narrow it with
|
|
29
|
+
* `eventTypes` / `tier` / `sampleRate`, or apply a footprintjs
|
|
30
|
+
* `RedactionPolicy` upstream, exactly as with every other sink. (For a bounded
|
|
31
|
+
* record by construction, `auditExport({ payloadMode: 'bounded' })` is the
|
|
32
|
+
* adapter that does that job.)
|
|
33
|
+
*
|
|
34
|
+
* ## Buffered, not synchronous
|
|
35
|
+
*
|
|
36
|
+
* `exportEvent` is sync and never touches the disk: it serializes, buffers, and
|
|
37
|
+
* returns. Batches are appended asynchronously on a size trigger
|
|
38
|
+
* (`maxBufferEvents` / `maxBufferBytes`), on a timer (`flushIntervalMs`), and on
|
|
39
|
+
* `flush()`. A hard kill therefore loses at most the buffer — the price of not
|
|
40
|
+
* making telemetry a term in agent-loop latency. Call `flush()` (or
|
|
41
|
+
* `agent.shutdown()`, which does) at process end; see the 8.12.0 lifecycle laws
|
|
42
|
+
* on {@link BaseStrategy.flush}.
|
|
43
|
+
*
|
|
44
|
+
* ## Rotation is ONE generation, and that is deliberate
|
|
45
|
+
*
|
|
46
|
+
* With `maxBytes` set, a batch that would push the file past the ceiling first
|
|
47
|
+
* renames it to `<path>.1` — **replacing any previous `.1`** — and starts a
|
|
48
|
+
* fresh file. That is the whole policy. There is no `.2`, no compression, no
|
|
49
|
+
* time-based schedule, no cross-process coordination (two processes writing one
|
|
50
|
+
* file each keep their own byte count and will both rotate it). It exists so an
|
|
51
|
+
* unattended agent cannot fill a disk, and for nothing else: **retention is a
|
|
52
|
+
* log-management daemon's job**, and `logrotate` with `copytruncate`, Fluent Bit,
|
|
53
|
+
* or a systemd timer will do it properly. Omit `maxBytes` — the default — and
|
|
54
|
+
* this adapter never renames anything, which is the right choice when a real
|
|
55
|
+
* rotator already owns the file.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { fileObservability } from 'agentfootprint/observe';
|
|
60
|
+
*
|
|
61
|
+
* const telemetry = agent.enable.observability({
|
|
62
|
+
* strategy: fileObservability({
|
|
63
|
+
* path: '/var/log/agentfootprint/events.ndjson',
|
|
64
|
+
* maxBytes: 64 * 1024 * 1024, // safety ceiling; logrotate owns retention
|
|
65
|
+
* }),
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // … run …
|
|
69
|
+
* await agent.shutdown(); // flushes + stops everything enabled
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
import type { AgentfootprintEvent, AgentfootprintEventType } from '../../events/registry.js';
|
|
73
|
+
import type { ObservabilityStrategy } from '../../strategies/types.js';
|
|
74
|
+
export interface FileObservabilityOptions {
|
|
75
|
+
/** Absolute or relative path to the NDJSON file. **Required.** Its parent
|
|
76
|
+
* directories are created (`recursive`) and the file itself is claimed at
|
|
77
|
+
* construction, so an unwritable path fails where you wrote it rather than
|
|
78
|
+
* at the first event — the only moment a caller is still watching. */
|
|
79
|
+
readonly path: string;
|
|
80
|
+
/** Rotation ceiling in bytes. Omitted → **never rotates** (the right choice
|
|
81
|
+
* when `logrotate` or a shipper already owns the file). Set → a batch that
|
|
82
|
+
* would cross the ceiling first renames the file to `<path>.1`, replacing
|
|
83
|
+
* any previous `.1`, and starts fresh. ONE generation, no compression, no
|
|
84
|
+
* cross-process coordination — see the note in this module's docstring. */
|
|
85
|
+
readonly maxBytes?: number;
|
|
86
|
+
/** Max events buffered before a forced append. Default 100. */
|
|
87
|
+
readonly maxBufferEvents?: number;
|
|
88
|
+
/** Max buffered payload bytes (UTF-8) before a forced append. Default 65536
|
|
89
|
+
* (64 KB) — a local write is cheap, so this is far larger than the network
|
|
90
|
+
* adapters' 10 KB. */
|
|
91
|
+
readonly maxBufferBytes?: number;
|
|
92
|
+
/** Forced-append interval when traffic is sparse, in ms. Default 1000.
|
|
93
|
+
* `0` disables the timer — only size triggers and `flush()` write. */
|
|
94
|
+
readonly flushIntervalMs?: number;
|
|
95
|
+
/** Narrow what lands on the disk. Becomes the strategy's
|
|
96
|
+
* {@link ObservabilityStrategy.relevantEventTypes}, so the dispatcher does
|
|
97
|
+
* not even forward the rest — the filter costs nothing at the hot path.
|
|
98
|
+
* Omitted → every event the `tier` lets through is written. */
|
|
99
|
+
readonly eventTypes?: readonly AgentfootprintEventType[];
|
|
100
|
+
/**
|
|
101
|
+
* Where delivery failures go — a full disk, a revoked permission, a path
|
|
102
|
+
* whose directory was removed under a long-running process.
|
|
103
|
+
*
|
|
104
|
+
* Same law as the network adapters (8.11.0): **telemetry that fails
|
|
105
|
+
* invisibly is indistinguishable from telemetry that works.** Unhandled,
|
|
106
|
+
* failures reach a rate-limited `console.error`. The batch that failed is
|
|
107
|
+
* dropped, never requeued, so a disk that has been full for an hour cannot
|
|
108
|
+
* grow the buffer without bound.
|
|
109
|
+
*/
|
|
110
|
+
readonly onError?: (error: Error, event?: AgentfootprintEvent) => void;
|
|
111
|
+
/** Test seam — inject a filesystem. Bypasses `node:fs` entirely, which is
|
|
112
|
+
* also what lets the rotation policy be asserted without a real disk. */
|
|
113
|
+
readonly _fs?: FileSinkFs;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The slice of the filesystem this adapter touches — five calls, named by what
|
|
117
|
+
* the adapter uses them FOR rather than by their `node:fs` signatures.
|
|
118
|
+
*
|
|
119
|
+
* Sync members run once, at construction; the append path is async so the agent
|
|
120
|
+
* loop never waits on a disk.
|
|
121
|
+
*/
|
|
122
|
+
export interface FileSinkFs {
|
|
123
|
+
/** Create the log file's parent directory chain. */
|
|
124
|
+
mkdirSync(dir: string, options: {
|
|
125
|
+
readonly recursive: boolean;
|
|
126
|
+
}): void;
|
|
127
|
+
/** Claim the file at construction. This is the writability refusal: an
|
|
128
|
+
* unwritable path throws HERE, with the caller still on the stack. */
|
|
129
|
+
appendFileSync(file: string, data: string): void;
|
|
130
|
+
/** Current size, so the rotation counter starts from what is already there
|
|
131
|
+
* rather than from zero on every restart. */
|
|
132
|
+
statSync(file: string): {
|
|
133
|
+
readonly size: number;
|
|
134
|
+
};
|
|
135
|
+
/** Append one batch of NDJSON lines. */
|
|
136
|
+
appendFile(file: string, data: string): Promise<void>;
|
|
137
|
+
/** Rotate: `<path>` → `<path>.1`, replacing any previous `.1`. */
|
|
138
|
+
rename(from: string, to: string): Promise<void>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* NDJSON-to-a-local-file observability strategy. See
|
|
142
|
+
* {@link FileObservabilityOptions} for the per-option contract, and this
|
|
143
|
+
* module's docstring for the rotation policy and what is NOT bounded.
|
|
144
|
+
*/
|
|
145
|
+
export declare function fileObservability(opts: FileObservabilityOptions): ObservabilityStrategy;
|
|
146
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../../src/adapters/observability/file.ts"],"names":[],"mappings":"AAAA;;;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CAAC;IAClD,wCAAwC;IACxC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,kEAAkE;IAClE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,GAAG,qBAAqB,CA2LvF"}
|
|
@@ -584,4 +584,91 @@ export interface PricingTable {
|
|
|
584
584
|
/** USD per ONE token for the given model+kind. */
|
|
585
585
|
pricePerToken(model: string, kind: TokenKind): number;
|
|
586
586
|
}
|
|
587
|
+
/**
|
|
588
|
+
* A service that runs code in an isolated session — a managed code
|
|
589
|
+
* interpreter, a container pool, a subprocess.
|
|
590
|
+
*
|
|
591
|
+
* **The shape is Start → Execute ×N → Stop**, because that is what every real
|
|
592
|
+
* one is, and the middle is the part a framework has to make possible. Paying
|
|
593
|
+
* session start-up on every call is the honest cheap version; holding the
|
|
594
|
+
* session in a module-level map is the fast version that hands one live sandbox
|
|
595
|
+
* to whoever calls next. `ctx.onTeardown` + {@link ToolExecutionContext.runId}
|
|
596
|
+
* are what let a tool do neither.
|
|
597
|
+
*
|
|
598
|
+
* ── Why this port exists at all: "summarize prose, compute data" ────────────
|
|
599
|
+
* A tool that returns 40MB of rows does not need a bigger context window; it
|
|
600
|
+
* needs to not put the rows in one. The motivating failure is a real production
|
|
601
|
+
* request of 879,073 tokens — a tool result pasted straight into the prompt.
|
|
602
|
+
* With a code runner, the model writes the aggregation, the RUNNER holds the
|
|
603
|
+
* data, and what comes back is the answer. Prose gets summarized; data gets
|
|
604
|
+
* computed. `CodeResult.truncated` exists so the second half of that promise
|
|
605
|
+
* cannot quietly break.
|
|
606
|
+
*
|
|
607
|
+
* Implement it for your own backend; ship it to `codeRunnerTool({ runner })`.
|
|
608
|
+
*/
|
|
609
|
+
export interface CodeRunner {
|
|
610
|
+
/** Stable id — reported on every `agentfootprint.tools.session_*` event so a
|
|
611
|
+
* row names its backend, not just its tool. */
|
|
612
|
+
readonly id: string;
|
|
613
|
+
/**
|
|
614
|
+
* Open a session.
|
|
615
|
+
*
|
|
616
|
+
* `key` is the ISOLATION key the caller derived (see `toolSessionKey`). An
|
|
617
|
+
* adapter may use it to name the remote session; it must never widen it.
|
|
618
|
+
*/
|
|
619
|
+
start(req: {
|
|
620
|
+
readonly key: string;
|
|
621
|
+
readonly language?: string;
|
|
622
|
+
readonly signal?: AbortSignal;
|
|
623
|
+
}): Promise<CodeSession>;
|
|
624
|
+
}
|
|
625
|
+
/** One live session. `stop()` is idempotent and tolerates "already gone". */
|
|
626
|
+
export interface CodeSession {
|
|
627
|
+
/** The backend's own id for this session, when it has one. */
|
|
628
|
+
readonly id: string;
|
|
629
|
+
execute(req: {
|
|
630
|
+
readonly code: string;
|
|
631
|
+
readonly language?: string;
|
|
632
|
+
readonly timeoutMs?: number;
|
|
633
|
+
readonly signal?: AbortSignal;
|
|
634
|
+
}): Promise<CodeResult>;
|
|
635
|
+
/**
|
|
636
|
+
* Release the session.
|
|
637
|
+
*
|
|
638
|
+
* Must tolerate a session the far side already reaped — an idle timeout is
|
|
639
|
+
* the reality on every managed backend, and a `Stop` on a dead session is a
|
|
640
|
+
* no-op, not an error.
|
|
641
|
+
*/
|
|
642
|
+
stop(): Promise<void>;
|
|
643
|
+
}
|
|
644
|
+
/** What one execution produced. */
|
|
645
|
+
export interface CodeResult {
|
|
646
|
+
/** Did the code run to completion without an error exit? */
|
|
647
|
+
readonly ok: boolean;
|
|
648
|
+
readonly stdout: string;
|
|
649
|
+
readonly stderr: string;
|
|
650
|
+
readonly exitCode?: number;
|
|
651
|
+
/** Files the run produced, described rather than inlined — the whole point is
|
|
652
|
+
* that big data does not enter the window. */
|
|
653
|
+
readonly artifacts?: readonly {
|
|
654
|
+
readonly name: string;
|
|
655
|
+
readonly bytes: number;
|
|
656
|
+
readonly uri?: string;
|
|
657
|
+
}[];
|
|
658
|
+
/**
|
|
659
|
+
* Present IFF output was cut, and then it says by how much.
|
|
660
|
+
*
|
|
661
|
+
* Load-bearing, not politeness. A runner exists so big data is computed
|
|
662
|
+
* outside the context window instead of pasted into it; a runner that
|
|
663
|
+
* quietly slices its own output to fit is the same bug wearing a different
|
|
664
|
+
* hat, and the model would go on to reason over a truncated table it was
|
|
665
|
+
* never told was truncated. An unstated slice is a silent success.
|
|
666
|
+
*/
|
|
667
|
+
readonly truncated?: {
|
|
668
|
+
readonly stdout?: boolean;
|
|
669
|
+
readonly stderr?: boolean;
|
|
670
|
+
/** The pre-truncation length, in characters, of whichever stream was cut. */
|
|
671
|
+
readonly ofChars?: number;
|
|
672
|
+
};
|
|
673
|
+
}
|
|
587
674
|
//# sourceMappingURL=types.d.ts.map
|