@axiastudio/aioc 0.1.0-alpha.4 → 0.1.0-beta.1
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 +60 -1
- package/dist/agent.d.ts +2 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/json.d.ts +7 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +40 -0
- package/dist/run-record.d.ts +28 -0
- package/dist/run-record.d.ts.map +1 -1
- package/dist/run-recorder-runtime.d.ts +19 -1
- package/dist/run-recorder-runtime.d.ts.map +1 -1
- package/dist/run-recorder-runtime.js +145 -2
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +42 -4
- package/package.json +10 -5
- package/dist/examples/basic/hello-world.d.ts +0 -2
- package/dist/examples/basic/hello-world.d.ts.map +0 -1
- package/dist/examples/basic/hello-world.js +0 -20
- package/dist/examples/basic/run-record-sink.d.ts +0 -2
- package/dist/examples/basic/run-record-sink.d.ts.map +0 -1
- package/dist/examples/basic/run-record-sink.js +0 -103
- package/dist/examples/basic/tools.d.ts +0 -2
- package/dist/examples/basic/tools.d.ts.map +0 -1
- package/dist/examples/basic/tools.js +0 -84
- package/dist/examples/guardrail-smoke.d.ts +0 -2
- package/dist/examples/guardrail-smoke.d.ts.map +0 -1
- package/dist/examples/guardrail-smoke.js +0 -110
- package/dist/examples/hello-run.d.ts +0 -2
- package/dist/examples/hello-run.d.ts.map +0 -1
- package/dist/examples/hello-run.js +0 -20
- package/dist/examples/learn-01-hello-run.d.ts +0 -2
- package/dist/examples/learn-01-hello-run.d.ts.map +0 -1
- package/dist/examples/learn-01-hello-run.js +0 -29
- package/dist/examples/learn-02-tool-policy.d.ts +0 -2
- package/dist/examples/learn-02-tool-policy.d.ts.map +0 -1
- package/dist/examples/learn-02-tool-policy.js +0 -87
- package/dist/examples/learn-03-controlled-handoff.d.ts +0 -2
- package/dist/examples/learn-03-controlled-handoff.d.ts.map +0 -1
- package/dist/examples/learn-03-controlled-handoff.js +0 -84
- package/dist/examples/learn-04-output-guardrail.d.ts +0 -2
- package/dist/examples/learn-04-output-guardrail.d.ts.map +0 -1
- package/dist/examples/learn-04-output-guardrail.js +0 -61
- package/dist/examples/learn-05-run-record-audit.d.ts +0 -2
- package/dist/examples/learn-05-run-record-audit.d.ts.map +0 -1
- package/dist/examples/learn-05-run-record-audit.js +0 -135
- package/dist/examples/mistral-smoke.d.ts +0 -2
- package/dist/examples/mistral-smoke.d.ts.map +0 -1
- package/dist/examples/mistral-smoke.js +0 -63
- package/dist/examples/onboarding-governance-smoke.d.ts +0 -2
- package/dist/examples/onboarding-governance-smoke.d.ts.map +0 -1
- package/dist/examples/onboarding-governance-smoke.js +0 -477
- package/dist/examples/onboarding-governance-tutorial.d.ts +0 -2
- package/dist/examples/onboarding-governance-tutorial.d.ts.map +0 -1
- package/dist/examples/onboarding-governance-tutorial.js +0 -342
- package/dist/examples/policy-smoke.d.ts +0 -2
- package/dist/examples/policy-smoke.d.ts.map +0 -1
- package/dist/examples/policy-smoke.js +0 -137
- package/dist/examples/support/scripted-provider.d.ts +0 -8
- package/dist/examples/support/scripted-provider.d.ts.map +0 -1
- package/dist/examples/support/scripted-provider.js +0 -21
- package/dist/examples/tool-policy-finance.d.ts +0 -2
- package/dist/examples/tool-policy-finance.d.ts.map +0 -1
- package/dist/examples/tool-policy-finance.js +0 -77
- package/dist/examples/tool-run.d.ts +0 -2
- package/dist/examples/tool-run.d.ts.map +0 -1
- package/dist/examples/tool-run.js +0 -70
- package/dist/tests/integration/chat-completions.integration.d.ts +0 -2
- package/dist/tests/integration/chat-completions.integration.d.ts.map +0 -1
- package/dist/tests/integration/chat-completions.integration.js +0 -110
- package/dist/tests/integration/index.d.ts +0 -2
- package/dist/tests/integration/index.d.ts.map +0 -1
- package/dist/tests/integration/index.js +0 -12
- package/dist/tests/regression/handoff-policy-trace.regression.d.ts +0 -2
- package/dist/tests/regression/handoff-policy-trace.regression.d.ts.map +0 -1
- package/dist/tests/regression/handoff-policy-trace.regression.js +0 -92
- package/dist/tests/regression/handoff-transition.regression.d.ts +0 -2
- package/dist/tests/regression/handoff-transition.regression.d.ts.map +0 -1
- package/dist/tests/regression/handoff-transition.regression.js +0 -62
- package/dist/tests/regression/index.d.ts +0 -2
- package/dist/tests/regression/index.d.ts.map +0 -1
- package/dist/tests/regression/index.js +0 -14
- package/dist/tests/regression/policy-default-deny.regression.d.ts +0 -2
- package/dist/tests/regression/policy-default-deny.regression.d.ts.map +0 -1
- package/dist/tests/regression/policy-default-deny.regression.js +0 -106
- package/dist/tests/support/handoff-name.d.ts +0 -2
- package/dist/tests/support/handoff-name.d.ts.map +0 -1
- package/dist/tests/support/handoff-name.js +0 -14
- package/dist/tests/support/scripted-provider.d.ts +0 -8
- package/dist/tests/support/scripted-provider.d.ts.map +0 -1
- package/dist/tests/support/scripted-provider.js +0 -19
- package/dist/tests/unit/guardrail.unit.d.ts +0 -2
- package/dist/tests/unit/guardrail.unit.d.ts.map +0 -1
- package/dist/tests/unit/guardrail.unit.js +0 -48
- package/dist/tests/unit/handoff.unit.d.ts +0 -2
- package/dist/tests/unit/handoff.unit.d.ts.map +0 -1
- package/dist/tests/unit/handoff.unit.js +0 -178
- package/dist/tests/unit/index.d.ts +0 -2
- package/dist/tests/unit/index.d.ts.map +0 -1
- package/dist/tests/unit/index.js +0 -24
- package/dist/tests/unit/logger.unit.d.ts +0 -2
- package/dist/tests/unit/logger.unit.d.ts.map +0 -1
- package/dist/tests/unit/logger.unit.js +0 -65
- package/dist/tests/unit/policy.unit.d.ts +0 -2
- package/dist/tests/unit/policy.unit.d.ts.map +0 -1
- package/dist/tests/unit/policy.unit.js +0 -167
- package/dist/tests/unit/provider-setup.unit.d.ts +0 -2
- package/dist/tests/unit/provider-setup.unit.d.ts.map +0 -1
- package/dist/tests/unit/provider-setup.unit.js +0 -75
- package/dist/tests/unit/run-record.unit.d.ts +0 -2
- package/dist/tests/unit/run-record.unit.d.ts.map +0 -1
- package/dist/tests/unit/run-record.unit.js +0 -118
- package/dist/tests/unit/run.unit.d.ts +0 -2
- package/dist/tests/unit/run.unit.d.ts.map +0 -1
- package/dist/tests/unit/run.unit.js +0 -30
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @axiastudio/aioc
|
|
2
2
|
|
|
3
|
-
AIOC is a
|
|
3
|
+
AIOC is a governance-first SDK for LLM agents: models can propose actions, while deterministic policies and runtime controls enforce decisions.
|
|
4
|
+
It provides default-deny gates for tools and handoffs, end-to-end auditability (run records, prompt snapshots, request fingerprints), and a foundation for verifiable iteration on prompts and policies.
|
|
5
|
+
AIOC is designed for enterprise and public-sector contexts with privacy-by-design and AI Act-aligned governance requirements.
|
|
4
6
|
|
|
5
7
|
Project home: [https://github.com/axiastudio/aioc](https://github.com/axiastudio/aioc)
|
|
6
8
|
|
|
@@ -8,6 +10,9 @@ Project home: [https://github.com/axiastudio/aioc](https://github.com/axiastudio
|
|
|
8
10
|
|
|
9
11
|
This package is currently in alpha and is not production-ready.
|
|
10
12
|
Breaking changes may occur before a stable release.
|
|
13
|
+
Alpha contract reference: `docs/ALPHA-CONTRACT.md`.
|
|
14
|
+
Pre-beta contract freeze reference: `docs/BETA-CONTRACT.md`.
|
|
15
|
+
Privacy baseline reference: `docs/PRIVACY-BASELINE.md`.
|
|
11
16
|
|
|
12
17
|
## Contact
|
|
13
18
|
|
|
@@ -29,6 +34,13 @@ Governance implementation reference:
|
|
|
29
34
|
- `docs/RFC-0001-governance-first-runtime.md`
|
|
30
35
|
- `docs/RFC-0002-policy-gates-for-tools-and-handoffs.md`
|
|
31
36
|
- `docs/RFC-0003-run-record-audit-trail-and-persistence.md`
|
|
37
|
+
- `docs/ALPHA-CONTRACT.md`
|
|
38
|
+
- `docs/BETA-CONTRACT.md`
|
|
39
|
+
- `docs/PRIVACY-BASELINE.md`
|
|
40
|
+
|
|
41
|
+
Canonical examples reference:
|
|
42
|
+
|
|
43
|
+
- `docs/CANONICAL-EXAMPLES.md`
|
|
32
44
|
|
|
33
45
|
## Goals of this first scaffold
|
|
34
46
|
|
|
@@ -39,6 +51,7 @@ Governance implementation reference:
|
|
|
39
51
|
## Exposed primitives (v0 scaffold)
|
|
40
52
|
|
|
41
53
|
- `Agent`, `RunContext`
|
|
54
|
+
- optional `Agent.promptVersion` to version resolved instructions
|
|
42
55
|
- `Tool`, `tool(...)`
|
|
43
56
|
- agent handoffs via `Agent({ handoffs: [...] })`
|
|
44
57
|
- `run(...)` with streaming support
|
|
@@ -49,6 +62,9 @@ Governance implementation reference:
|
|
|
49
62
|
- provider setup helpers `setupMistral(...)`, `setupOpenAI(...)`, `setupProvider(...)`
|
|
50
63
|
- stdout logger helper `createStdoutLogger(...)` (opt-in)
|
|
51
64
|
- run record hook via `run(..., { record })` for external persistence/audit adapters
|
|
65
|
+
- run record prompt snapshots per turn (`turn`, `agentName`, `promptVersion`, `promptHash`, optional `promptText`)
|
|
66
|
+
- run record request fingerprints per turn (`requestHash`, segment hashes, `runtimeVersion`, `fingerprintSchemaVersion`)
|
|
67
|
+
- JSON helper `toJsonValue(...)` to map runtime artifacts (for example `RunRecord.items`) into JSON-safe values for storage adapters
|
|
52
68
|
- message helpers `user(...)`, `assistant(...)`, `system(...)`
|
|
53
69
|
- `setDefaultProvider(...)`
|
|
54
70
|
- error classes including `OutputGuardrailTripwireTriggered`
|
|
@@ -66,6 +82,16 @@ Policy deny notes:
|
|
|
66
82
|
- Default deny behavior raises typed runtime errors (`ToolCallPolicyDeniedError` / `HandoffPolicyDeniedError`).
|
|
67
83
|
- Policies can choose `denyMode: "tool_result"` to return a denied tool result to the model without throwing.
|
|
68
84
|
|
|
85
|
+
Run record metadata convention:
|
|
86
|
+
|
|
87
|
+
- `record.metadata.appBuildVersion` is a recommended field to correlate run drift with application-layer source/build changes.
|
|
88
|
+
|
|
89
|
+
Privacy baseline highlights:
|
|
90
|
+
|
|
91
|
+
- `record.includePromptText` defaults to `false` and should remain disabled unless explicitly required.
|
|
92
|
+
- `record.contextRedactor` should be considered mandatory for production run-record persistence.
|
|
93
|
+
- sink adapters should implement encryption, access controls, retention, and deletion policies.
|
|
94
|
+
|
|
69
95
|
## Test Commands
|
|
70
96
|
|
|
71
97
|
- `npm run test:unit`
|
|
@@ -73,6 +99,39 @@ Policy deny notes:
|
|
|
73
99
|
- `npm run test:regression`
|
|
74
100
|
- `npm run test:ci`
|
|
75
101
|
|
|
102
|
+
## Canonical Examples
|
|
103
|
+
|
|
104
|
+
- `npm run example:hello` (minimal single-agent run)
|
|
105
|
+
- `npm run example:tool-policy` (tool calls with deterministic policy gate)
|
|
106
|
+
- `npm run example:run-record` (run record persistence with redaction + audit)
|
|
107
|
+
- `npm run example:non-regression` (advanced v1/v2 run-record diff)
|
|
108
|
+
|
|
109
|
+
## Python Alpha Port
|
|
110
|
+
|
|
111
|
+
Python runtime is available under `py/` (Python 3.11+), with governance-first parity against core TS semantics:
|
|
112
|
+
|
|
113
|
+
- `Agent`, `RunContext`, `run(...)` (stream/non-stream), tool registration, handoff
|
|
114
|
+
- deterministic default-deny policy gates for tool/handoff
|
|
115
|
+
- unified tool/handoff output envelope `{ status, code, publicReason, data }`
|
|
116
|
+
- typed runtime errors for deny/guardrail/max-turns
|
|
117
|
+
- run record sink adapter + context redaction + policy/guardrail decision capture
|
|
118
|
+
- provider setup helpers: `setup_mistral()`, `setup_openai()`, `setup_provider()`
|
|
119
|
+
- JSON-safe helper `to_json_value(...)`
|
|
120
|
+
|
|
121
|
+
Python test command:
|
|
122
|
+
|
|
123
|
+
- `cd py && python3 -m unittest discover -s tests -p 'test_*.py'`
|
|
124
|
+
|
|
125
|
+
Python examples:
|
|
126
|
+
|
|
127
|
+
- `cd py && python3 examples/basic/hello_world.py`
|
|
128
|
+
- `cd py && python3 examples/basic/tool_policy_allow_deny.py`
|
|
129
|
+
- `cd py && python3 examples/basic/run_record_sink.py`
|
|
130
|
+
|
|
131
|
+
Migration mapping reference:
|
|
132
|
+
|
|
133
|
+
- `docs/TS-PY-MIGRATION.md`
|
|
134
|
+
|
|
76
135
|
## License
|
|
77
136
|
|
|
78
137
|
- Project license: `MIT` (`LICENSE`)
|
package/dist/agent.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface AgentConfiguration<TContext = unknown> {
|
|
|
7
7
|
name: string;
|
|
8
8
|
handoffDescription?: string;
|
|
9
9
|
instructions?: AgentInstructions<TContext>;
|
|
10
|
+
promptVersion?: string;
|
|
10
11
|
model?: string;
|
|
11
12
|
modelSettings?: ModelSettings;
|
|
12
13
|
tools?: Tool<TContext>[];
|
|
@@ -17,6 +18,7 @@ export declare class Agent<TContext = unknown> {
|
|
|
17
18
|
name: string;
|
|
18
19
|
handoffDescription: string;
|
|
19
20
|
instructions?: AgentInstructions<TContext>;
|
|
21
|
+
promptVersion?: string;
|
|
20
22
|
model?: string;
|
|
21
23
|
modelSettings?: ModelSettings;
|
|
22
24
|
tools: Tool<TContext>[];
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,MAAM,iBAAiB,CAAC,QAAQ,GAAG,OAAO,IAC5C,MAAM,GACN,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAErE,MAAM,WAAW,kBAAkB,CAAC,QAAQ,GAAG,OAAO;IACpD,IAAI,EAA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,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAS/B"}
|
package/dist/agent.js
CHANGED
|
@@ -5,6 +5,7 @@ class Agent {
|
|
|
5
5
|
name;
|
|
6
6
|
handoffDescription;
|
|
7
7
|
instructions;
|
|
8
|
+
promptVersion;
|
|
8
9
|
model;
|
|
9
10
|
modelSettings;
|
|
10
11
|
tools;
|
|
@@ -14,6 +15,7 @@ class Agent {
|
|
|
14
15
|
this.name = config.name;
|
|
15
16
|
this.handoffDescription = config.handoffDescription ?? "";
|
|
16
17
|
this.instructions = config.instructions;
|
|
18
|
+
this.promptVersion = config.promptVersion;
|
|
17
19
|
this.model = config.model;
|
|
18
20
|
this.modelSettings = config.modelSettings;
|
|
19
21
|
this.tools = config.tools ?? [];
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./agent"), exports);
|
|
|
18
18
|
__exportStar(require("./config"), exports);
|
|
19
19
|
__exportStar(require("./errors"), exports);
|
|
20
20
|
__exportStar(require("./guardrails"), exports);
|
|
21
|
+
__exportStar(require("./json"), exports);
|
|
21
22
|
__exportStar(require("./logger"), exports);
|
|
22
23
|
__exportStar(require("./messages"), exports);
|
|
23
24
|
__exportStar(require("./policy"), exports);
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export declare function toJsonValue(value: unknown): JsonValue;
|
|
7
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,SAAS,EAAE,CAAC;AAEjE,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAmCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAMrD"}
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJsonValue = toJsonValue;
|
|
4
|
+
function createJsonReplacer() {
|
|
5
|
+
const seen = new WeakSet();
|
|
6
|
+
return (_key, value) => {
|
|
7
|
+
if (typeof value === "bigint") {
|
|
8
|
+
return value.toString();
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === "function" || typeof value === "symbol") {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (value instanceof Map) {
|
|
14
|
+
return Object.fromEntries(value.entries());
|
|
15
|
+
}
|
|
16
|
+
if (value instanceof Set) {
|
|
17
|
+
return Array.from(value.values());
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof Error) {
|
|
20
|
+
return {
|
|
21
|
+
name: value.name,
|
|
22
|
+
message: value.message,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (value && typeof value === "object") {
|
|
26
|
+
if (seen.has(value)) {
|
|
27
|
+
return "[Circular]";
|
|
28
|
+
}
|
|
29
|
+
seen.add(value);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function toJsonValue(value) {
|
|
35
|
+
const serialized = JSON.stringify(value, createJsonReplacer());
|
|
36
|
+
if (typeof serialized === "undefined") {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return JSON.parse(serialized);
|
|
40
|
+
}
|
package/dist/run-record.d.ts
CHANGED
|
@@ -24,6 +24,31 @@ export interface GuardrailDecisionRecord {
|
|
|
24
24
|
reason?: string;
|
|
25
25
|
metadata?: Record<string, unknown>;
|
|
26
26
|
}
|
|
27
|
+
export interface PromptSnapshotRecord {
|
|
28
|
+
timestamp: string;
|
|
29
|
+
turn: number;
|
|
30
|
+
agentName: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
promptVersion?: string;
|
|
33
|
+
promptHash: string;
|
|
34
|
+
promptText?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface RequestFingerprintRecord {
|
|
37
|
+
timestamp: string;
|
|
38
|
+
turn: number;
|
|
39
|
+
agentName: string;
|
|
40
|
+
providerName: string;
|
|
41
|
+
model: string;
|
|
42
|
+
runtimeVersion: string;
|
|
43
|
+
fingerprintSchemaVersion: string;
|
|
44
|
+
requestHash: string;
|
|
45
|
+
systemPromptHash: string;
|
|
46
|
+
messagesHash: string;
|
|
47
|
+
toolsHash: string;
|
|
48
|
+
modelSettingsHash: string;
|
|
49
|
+
messageCount: number;
|
|
50
|
+
toolCount: number;
|
|
51
|
+
}
|
|
27
52
|
export interface RunRecord<TContext = unknown> {
|
|
28
53
|
runId: string;
|
|
29
54
|
startedAt: string;
|
|
@@ -37,6 +62,8 @@ export interface RunRecord<TContext = unknown> {
|
|
|
37
62
|
contextSnapshot: TContext;
|
|
38
63
|
contextRedacted?: boolean;
|
|
39
64
|
items: AgentInputItem[];
|
|
65
|
+
promptSnapshots: PromptSnapshotRecord[];
|
|
66
|
+
requestFingerprints: RequestFingerprintRecord[];
|
|
40
67
|
policyDecisions: PolicyDecisionRecord[];
|
|
41
68
|
guardrailDecisions?: GuardrailDecisionRecord[];
|
|
42
69
|
errorName?: string;
|
|
@@ -56,6 +83,7 @@ export interface RunRecordOptions<TContext = unknown> {
|
|
|
56
83
|
runId?: string;
|
|
57
84
|
metadata?: Record<string, unknown>;
|
|
58
85
|
contextRedactor?: RunRecordContextRedactor<TContext>;
|
|
86
|
+
includePromptText?: boolean;
|
|
59
87
|
sink?: RunRecordSink<TContext> | RunRecordWriter<TContext>;
|
|
60
88
|
}
|
|
61
89
|
//# sourceMappingURL=run-record.d.ts.map
|
package/dist/run-record.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-record.d.ts","sourceR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E,eAAe,EAAE,QAAQ,CAAC;IAC1B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,MAAM,wBAAwB,CAAC,QAAQ,GAAG,OAAO,IAAI,CACzD,OAAO,EAAE,QAAQ,KAEf,+BAA+B,CAAC,QAAQ,CAAC,GACzC,OAAO,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEvD,MAAM,MAAM,eAAe,CAAC,QAAQ,GAAG,OAAO,IAAI,CAChD,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,KACxB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE1B,MAAM,WAAW,aAAa,CAAC,QAAQ,GAAG,OAAO;IAC/C,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,OAAO;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,eAAe,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;CAC5D"}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import type { GuardrailDecisionRecord, PolicyDecisionRecord, RunRecordOptions } from "./run-record";
|
|
1
|
+
import type { GuardrailDecisionRecord, PolicyDecisionRecord, PromptSnapshotRecord, RequestFingerprintRecord, RunRecordOptions } from "./run-record";
|
|
2
2
|
import type { AgentInputItem } from "./types";
|
|
3
3
|
export type PendingPolicyDecisionRecord = Omit<PolicyDecisionRecord, "timestamp">;
|
|
4
4
|
export type PendingGuardrailDecisionRecord = Omit<GuardrailDecisionRecord, "timestamp">;
|
|
5
|
+
export type PendingPromptSnapshotRecord = Omit<PromptSnapshotRecord, "timestamp" | "promptHash" | "promptText"> & {
|
|
6
|
+
promptText?: string;
|
|
7
|
+
};
|
|
8
|
+
export type PendingRequestFingerprintRecord = Omit<RequestFingerprintRecord, "timestamp" | "runtimeVersion" | "fingerprintSchemaVersion" | "requestHash" | "systemPromptHash" | "messagesHash" | "toolsHash" | "modelSettingsHash" | "messageCount" | "toolCount"> & {
|
|
9
|
+
systemPrompt?: string;
|
|
10
|
+
messages: AgentInputItem[];
|
|
11
|
+
tools: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
parameters: unknown;
|
|
15
|
+
}>;
|
|
16
|
+
modelSettings?: Record<string, unknown>;
|
|
17
|
+
};
|
|
5
18
|
interface RunRecorderCreateOptions<TContext> {
|
|
6
19
|
input: string | AgentInputItem[];
|
|
7
20
|
context: TContext;
|
|
@@ -21,14 +34,19 @@ export declare class RunRecorder<TContext = unknown> {
|
|
|
21
34
|
private readonly providerName;
|
|
22
35
|
private readonly metadata?;
|
|
23
36
|
private readonly contextSnapshot;
|
|
37
|
+
private readonly includePromptText;
|
|
24
38
|
private readonly policyDecisions;
|
|
25
39
|
private readonly guardrailDecisions;
|
|
40
|
+
private readonly promptSnapshots;
|
|
41
|
+
private readonly requestFingerprints;
|
|
26
42
|
private observedFinalOutput;
|
|
27
43
|
private runRecordWritten;
|
|
28
44
|
private constructor();
|
|
29
45
|
static create<TContext = unknown>(options: RunRecorderCreateOptions<TContext>): Promise<RunRecorder<TContext>>;
|
|
30
46
|
onPolicyDecision: (decision: PendingPolicyDecisionRecord) => void;
|
|
31
47
|
onGuardrailDecision: (decision: PendingGuardrailDecisionRecord) => void;
|
|
48
|
+
onPromptSnapshot: (snapshot: PendingPromptSnapshotRecord) => void;
|
|
49
|
+
onRequestFingerprint: (fingerprint: PendingRequestFingerprintRecord) => void;
|
|
32
50
|
onMessageOutput: (content: string) => void;
|
|
33
51
|
emitCompleted(options: RunRecorderFinalizeOptions): Promise<void>;
|
|
34
52
|
emitFailed(options: RunRecorderFinalizeOptions, error: unknown): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-recorder-runtime.d.ts","sourceRoot":"","sources":["../src/run-recorder-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-recorder-runtime.d.ts","sourceRoot":"","sources":["../src/run-recorder-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAGxB,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,oBAAoB,EACpB,WAAW,CACZ,CAAC;AACF,MAAM,MAAM,8BAA8B,GAAG,IAAI,CAC/C,uBAAuB,EACvB,WAAW,CACZ,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,oBAAoB,EACpB,WAAW,GAAG,YAAY,GAAG,YAAY,CAC1C,GAAG;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAChD,wBAAwB,EACtB,WAAW,GACX,gBAAgB,GAChB,0BAA0B,GAC1B,aAAa,GACb,kBAAkB,GAClB,cAAc,GACd,WAAW,GACX,mBAAmB,GACnB,cAAc,GACd,WAAW,CACd,GAAG;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC,CAAC;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC,CAAC;AAiIF,UAAU,wBAAwB,CAAC,QAAQ;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,GAAI,UAAU,2BAA2B,KAAG,IAAI,CAW9D;IAEF,oBAAoB,GAClB,aAAa,+BAA+B,KAC3C,IAAI,CAgCL;IAEF,eAAe,GAAI,SAAS,MAAM,KAAG,IAAI,CAEvC;IAEI,aAAa,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CACd,OAAO,EAAE,0BAA0B,EACnC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC;YAIF,IAAI;CA0CnB"}
|
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunRecorder = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const REQUEST_FINGERPRINT_SCHEMA_VERSION = "request-fingerprint.v1";
|
|
8
|
+
function resolveRuntimeVersion() {
|
|
9
|
+
const envVersion = process.env.AIOC_RUNTIME_VERSION?.trim() ??
|
|
10
|
+
process.env.npm_package_version?.trim();
|
|
11
|
+
if (envVersion) {
|
|
12
|
+
return envVersion;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const packageJsonPath = (0, node_path_1.resolve)(__dirname, "..", "package.json");
|
|
16
|
+
const packageJsonRaw = (0, node_fs_1.readFileSync)(packageJsonPath, "utf8");
|
|
17
|
+
const packageJson = JSON.parse(packageJsonRaw);
|
|
18
|
+
if (typeof packageJson.version === "string" &&
|
|
19
|
+
packageJson.version.trim().length > 0) {
|
|
20
|
+
return packageJson.version.trim();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Fallback handled below.
|
|
25
|
+
}
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
const RUNTIME_VERSION = resolveRuntimeVersion();
|
|
29
|
+
function normalizeForHash(value, seen = new WeakSet()) {
|
|
30
|
+
if (value === null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const valueType = typeof value;
|
|
34
|
+
if (valueType === "string" ||
|
|
35
|
+
valueType === "number" ||
|
|
36
|
+
valueType === "boolean") {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
if (valueType === "undefined") {
|
|
40
|
+
return "[undefined]";
|
|
41
|
+
}
|
|
42
|
+
if (valueType === "bigint") {
|
|
43
|
+
return `[bigint:${String(value)}]`;
|
|
44
|
+
}
|
|
45
|
+
if (valueType === "symbol") {
|
|
46
|
+
return `[symbol:${String(value)}]`;
|
|
47
|
+
}
|
|
48
|
+
if (valueType === "function") {
|
|
49
|
+
return "[function]";
|
|
50
|
+
}
|
|
51
|
+
if (value instanceof Date) {
|
|
52
|
+
return value.toISOString();
|
|
53
|
+
}
|
|
54
|
+
if (value instanceof RegExp) {
|
|
55
|
+
return value.toString();
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
return value.map((item) => normalizeForHash(item, seen));
|
|
59
|
+
}
|
|
60
|
+
if (value instanceof Set) {
|
|
61
|
+
const entries = [...value].map((entry) => normalizeForHash(entry, seen));
|
|
62
|
+
entries.sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
63
|
+
return entries;
|
|
64
|
+
}
|
|
65
|
+
if (value instanceof Map) {
|
|
66
|
+
const entries = [...value.entries()].map(([key, entry]) => [
|
|
67
|
+
normalizeForHash(key, seen),
|
|
68
|
+
normalizeForHash(entry, seen),
|
|
69
|
+
]);
|
|
70
|
+
entries.sort((left, right) => JSON.stringify(left[0]).localeCompare(JSON.stringify(right[0])));
|
|
71
|
+
return entries;
|
|
72
|
+
}
|
|
73
|
+
if (value && typeof value === "object") {
|
|
74
|
+
const objectValue = value;
|
|
75
|
+
if (seen.has(objectValue)) {
|
|
76
|
+
return "[circular]";
|
|
77
|
+
}
|
|
78
|
+
seen.add(objectValue);
|
|
79
|
+
const normalized = {};
|
|
80
|
+
const keys = Object.keys(objectValue).sort();
|
|
81
|
+
for (const key of keys) {
|
|
82
|
+
normalized[key] = normalizeForHash(objectValue[key], seen);
|
|
83
|
+
}
|
|
84
|
+
seen.delete(objectValue);
|
|
85
|
+
return normalized;
|
|
86
|
+
}
|
|
87
|
+
return String(value);
|
|
88
|
+
}
|
|
89
|
+
function hashForFingerprint(value) {
|
|
90
|
+
return (0, node_crypto_1.createHash)("sha256")
|
|
91
|
+
.update(JSON.stringify(normalizeForHash(value)))
|
|
92
|
+
.digest("hex");
|
|
93
|
+
}
|
|
4
94
|
function extractQuestion(input) {
|
|
5
95
|
if (typeof input === "string") {
|
|
6
96
|
return input;
|
|
@@ -60,6 +150,9 @@ function toErrorSummary(error) {
|
|
|
60
150
|
errorMessage: String(error),
|
|
61
151
|
};
|
|
62
152
|
}
|
|
153
|
+
function hashPrompt(promptText) {
|
|
154
|
+
return (0, node_crypto_1.createHash)("sha256").update(promptText).digest("hex");
|
|
155
|
+
}
|
|
63
156
|
class RunRecorder {
|
|
64
157
|
runRecordWriter;
|
|
65
158
|
runRecordId;
|
|
@@ -68,11 +161,14 @@ class RunRecorder {
|
|
|
68
161
|
providerName;
|
|
69
162
|
metadata;
|
|
70
163
|
contextSnapshot;
|
|
164
|
+
includePromptText;
|
|
71
165
|
policyDecisions = [];
|
|
72
166
|
guardrailDecisions = [];
|
|
167
|
+
promptSnapshots = [];
|
|
168
|
+
requestFingerprints = [];
|
|
73
169
|
observedFinalOutput = "";
|
|
74
170
|
runRecordWritten = false;
|
|
75
|
-
constructor(runRecordWriter, runRecordId, startedAt, question, providerName, metadata, contextSnapshot) {
|
|
171
|
+
constructor(runRecordWriter, runRecordId, startedAt, question, providerName, metadata, contextSnapshot, includePromptText) {
|
|
76
172
|
this.runRecordWriter = runRecordWriter;
|
|
77
173
|
this.runRecordId = runRecordId;
|
|
78
174
|
this.startedAt = startedAt;
|
|
@@ -80,6 +176,7 @@ class RunRecorder {
|
|
|
80
176
|
this.providerName = providerName;
|
|
81
177
|
this.metadata = metadata;
|
|
82
178
|
this.contextSnapshot = contextSnapshot;
|
|
179
|
+
this.includePromptText = includePromptText;
|
|
83
180
|
}
|
|
84
181
|
static async create(options) {
|
|
85
182
|
const runRecordWriter = resolveRunRecordWriter(options.recordOptions);
|
|
@@ -87,7 +184,7 @@ class RunRecorder {
|
|
|
87
184
|
const startedAt = new Date().toISOString();
|
|
88
185
|
const question = extractQuestion(options.input);
|
|
89
186
|
const contextSnapshot = await resolveContextSnapshot(options.context, options.recordOptions);
|
|
90
|
-
return new RunRecorder(runRecordWriter, runRecordId, startedAt, question, options.providerName, options.recordOptions?.metadata, contextSnapshot);
|
|
187
|
+
return new RunRecorder(runRecordWriter, runRecordId, startedAt, question, options.providerName, options.recordOptions?.metadata, contextSnapshot, options.recordOptions?.includePromptText ?? false);
|
|
91
188
|
}
|
|
92
189
|
onPolicyDecision = (decision) => {
|
|
93
190
|
this.policyDecisions.push({
|
|
@@ -101,6 +198,50 @@ class RunRecorder {
|
|
|
101
198
|
...decision,
|
|
102
199
|
});
|
|
103
200
|
};
|
|
201
|
+
onPromptSnapshot = (snapshot) => {
|
|
202
|
+
const normalizedPrompt = snapshot.promptText ?? "";
|
|
203
|
+
this.promptSnapshots.push({
|
|
204
|
+
timestamp: new Date().toISOString(),
|
|
205
|
+
turn: snapshot.turn,
|
|
206
|
+
agentName: snapshot.agentName,
|
|
207
|
+
model: snapshot.model,
|
|
208
|
+
promptVersion: snapshot.promptVersion,
|
|
209
|
+
promptHash: hashPrompt(normalizedPrompt),
|
|
210
|
+
promptText: this.includePromptText ? normalizedPrompt : undefined,
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
onRequestFingerprint = (fingerprint) => {
|
|
214
|
+
const normalizedSystemPrompt = fingerprint.systemPrompt ?? "";
|
|
215
|
+
const normalizedModelSettings = fingerprint.modelSettings ?? {};
|
|
216
|
+
const normalizedTools = fingerprint.tools.map((tool) => ({
|
|
217
|
+
name: tool.name,
|
|
218
|
+
description: tool.description,
|
|
219
|
+
parameters: tool.parameters,
|
|
220
|
+
}));
|
|
221
|
+
const requestPayload = {
|
|
222
|
+
model: fingerprint.model,
|
|
223
|
+
systemPrompt: normalizedSystemPrompt,
|
|
224
|
+
messages: fingerprint.messages,
|
|
225
|
+
tools: normalizedTools,
|
|
226
|
+
modelSettings: normalizedModelSettings,
|
|
227
|
+
};
|
|
228
|
+
this.requestFingerprints.push({
|
|
229
|
+
timestamp: new Date().toISOString(),
|
|
230
|
+
turn: fingerprint.turn,
|
|
231
|
+
agentName: fingerprint.agentName,
|
|
232
|
+
providerName: fingerprint.providerName,
|
|
233
|
+
model: fingerprint.model,
|
|
234
|
+
runtimeVersion: RUNTIME_VERSION,
|
|
235
|
+
fingerprintSchemaVersion: REQUEST_FINGERPRINT_SCHEMA_VERSION,
|
|
236
|
+
requestHash: hashForFingerprint(requestPayload),
|
|
237
|
+
systemPromptHash: hashForFingerprint(normalizedSystemPrompt),
|
|
238
|
+
messagesHash: hashForFingerprint(fingerprint.messages),
|
|
239
|
+
toolsHash: hashForFingerprint(normalizedTools),
|
|
240
|
+
modelSettingsHash: hashForFingerprint(normalizedModelSettings),
|
|
241
|
+
messageCount: fingerprint.messages.length,
|
|
242
|
+
toolCount: normalizedTools.length,
|
|
243
|
+
});
|
|
244
|
+
};
|
|
104
245
|
onMessageOutput = (content) => {
|
|
105
246
|
this.observedFinalOutput = content;
|
|
106
247
|
};
|
|
@@ -129,6 +270,8 @@ class RunRecorder {
|
|
|
129
270
|
contextSnapshot: this.contextSnapshot.contextSnapshot,
|
|
130
271
|
contextRedacted: this.contextSnapshot.contextRedacted,
|
|
131
272
|
items: [...options.items],
|
|
273
|
+
promptSnapshots: [...this.promptSnapshots],
|
|
274
|
+
requestFingerprints: [...this.requestFingerprints],
|
|
132
275
|
policyDecisions: [...this.policyDecisions],
|
|
133
276
|
guardrailDecisions: this.guardrailDecisions.length > 0
|
|
134
277
|
? [...this.guardrailDecisions]
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAuBhC,OAAO,EACL,cAAc,EAEd,mBAAmB,EAGnB,SAAS,EACT,cAAc,EACd,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAUjB,KAAK,eAAe,CAAC,QAAQ,IAAI;IAC/B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC5B,CAAC;AAwpBF,qBAAa,iBAAiB,CAAC,QAAQ,GAAG,OAAO;IAC/C,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,KAAK,CAA4B;gBAGvC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAC/C,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC;IAMlC,QAAQ,IAAI,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAQnD,IAAI,OAAO,IAAI,cAAc,EAAE,CAE9B;IAED,IAAI,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,CAE/B;CACF;AAED,wBAAsB,GAAG,CAAC,QAAQ,GAAG,OAAO,EAC1C,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,EAC9B,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,EAChC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GAClC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAExC,wBAAsB,GAAG,CAAC,QAAQ,GAAG,OAAO,EAC1C,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,EAC9B,KAAK,EAAE,MAAM,GAAG,cAAc,EAAE,EAChC,OAAO,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,GACtC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
package/dist/run.js
CHANGED
|
@@ -9,6 +9,21 @@ const run_log_emitter_1 = require("./run-log-emitter");
|
|
|
9
9
|
const run_recorder_runtime_1 = require("./run-recorder-runtime");
|
|
10
10
|
const run_context_1 = require("./run-context");
|
|
11
11
|
const zod_1 = require("zod");
|
|
12
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
13
|
+
function toToolParameterSchema(schema) {
|
|
14
|
+
try {
|
|
15
|
+
const convert = zod_to_json_schema_1.zodToJsonSchema;
|
|
16
|
+
const rawSchema = convert(schema, { $refStrategy: "none" });
|
|
17
|
+
const normalized = { ...rawSchema };
|
|
18
|
+
delete normalized.$schema;
|
|
19
|
+
return normalized;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return {
|
|
23
|
+
type: "unserializable_tool_schema",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
12
27
|
function normalizeInput(input) {
|
|
13
28
|
if (typeof input === "string") {
|
|
14
29
|
return [(0, messages_1.user)(input)];
|
|
@@ -238,7 +253,7 @@ async function evaluateOutputGuardrails(agent, runContext, history, outputText,
|
|
|
238
253
|
await logEmitter.outputGuardrailPassed(agent.name, turn, guardrail.name);
|
|
239
254
|
}
|
|
240
255
|
}
|
|
241
|
-
async function* runLoop(state, provider, runContext, maxTurns, logger, policies, onPolicyDecision, onGuardrailDecision) {
|
|
256
|
+
async function* runLoop(state, provider, runContext, maxTurns, logger, policies, onPolicyDecision, onGuardrailDecision, onPromptSnapshot, onRequestFingerprint) {
|
|
242
257
|
const logEmitter = new run_log_emitter_1.RunLogEmitter(logger);
|
|
243
258
|
await logEmitter.runStarted(state.lastAgent.name, maxTurns, state.history.length);
|
|
244
259
|
yield {
|
|
@@ -253,9 +268,32 @@ async function* runLoop(state, provider, runContext, maxTurns, logger, policies,
|
|
|
253
268
|
const currentAgent = state.lastAgent;
|
|
254
269
|
await logEmitter.turnStarted(currentAgent.name, activeTurn);
|
|
255
270
|
const { providerTools, handoffRegistry } = buildTurnTools(currentAgent);
|
|
271
|
+
const model = resolveAgentModel(currentAgent);
|
|
272
|
+
const systemPrompt = await currentAgent.resolveInstructions(runContext);
|
|
273
|
+
onPromptSnapshot?.({
|
|
274
|
+
turn: activeTurn,
|
|
275
|
+
agentName: currentAgent.name,
|
|
276
|
+
model,
|
|
277
|
+
promptVersion: currentAgent.promptVersion,
|
|
278
|
+
promptText: systemPrompt,
|
|
279
|
+
});
|
|
280
|
+
onRequestFingerprint?.({
|
|
281
|
+
turn: activeTurn,
|
|
282
|
+
agentName: currentAgent.name,
|
|
283
|
+
providerName: provider.constructor.name,
|
|
284
|
+
model,
|
|
285
|
+
systemPrompt,
|
|
286
|
+
messages: state.history,
|
|
287
|
+
tools: providerTools.map((toolDefinition) => ({
|
|
288
|
+
name: toolDefinition.name,
|
|
289
|
+
description: toolDefinition.description,
|
|
290
|
+
parameters: toToolParameterSchema(toolDefinition.parameters),
|
|
291
|
+
})),
|
|
292
|
+
modelSettings: currentAgent.modelSettings,
|
|
293
|
+
});
|
|
256
294
|
const providerStream = provider.stream({
|
|
257
|
-
model
|
|
258
|
-
systemPrompt
|
|
295
|
+
model,
|
|
296
|
+
systemPrompt,
|
|
259
297
|
messages: state.history,
|
|
260
298
|
tools: providerTools,
|
|
261
299
|
modelSettings: currentAgent.modelSettings,
|
|
@@ -457,7 +495,7 @@ async function run(startingAgent, input, options = {}) {
|
|
|
457
495
|
providerName: provider.constructor.name,
|
|
458
496
|
recordOptions: options.record,
|
|
459
497
|
});
|
|
460
|
-
const rawStream = runLoop(state, provider, runContext, maxTurns, options.logger, options.policies, runRecorder.onPolicyDecision, runRecorder.onGuardrailDecision);
|
|
498
|
+
const rawStream = runLoop(state, provider, runContext, maxTurns, options.logger, options.policies, runRecorder.onPolicyDecision, runRecorder.onGuardrailDecision, runRecorder.onPromptSnapshot, runRecorder.onRequestFingerprint);
|
|
461
499
|
const runRecordSnapshot = () => ({
|
|
462
500
|
agentName: state.lastAgent.name,
|
|
463
501
|
model: state.lastAgent.model,
|