@coderifts/agent-guard 5.0.0 → 6.1.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/README.md +53 -4
- package/dist/cjs/adapters/anthropic.d.ts +26 -0
- package/dist/cjs/adapters/anthropic.d.ts.map +1 -1
- package/dist/cjs/adapters/anthropic.js +68 -0
- package/dist/cjs/adapters/anthropic.js.map +1 -1
- package/dist/cjs/adapters/gemini.d.ts +39 -0
- package/dist/cjs/adapters/gemini.d.ts.map +1 -1
- package/dist/cjs/adapters/gemini.js +83 -0
- package/dist/cjs/adapters/gemini.js.map +1 -1
- package/dist/cjs/adapters/langgraph.d.ts +29 -0
- package/dist/cjs/adapters/langgraph.d.ts.map +1 -1
- package/dist/cjs/adapters/langgraph.js +70 -0
- package/dist/cjs/adapters/langgraph.js.map +1 -1
- package/dist/cjs/adapters/openai.d.ts +44 -0
- package/dist/cjs/adapters/openai.d.ts.map +1 -1
- package/dist/cjs/adapters/openai.js +86 -0
- package/dist/cjs/adapters/openai.js.map +1 -1
- package/dist/cjs/execution-proof.d.ts +7 -0
- package/dist/cjs/execution-proof.d.ts.map +1 -1
- package/dist/cjs/execution-proof.js +1 -0
- package/dist/cjs/execution-proof.js.map +1 -1
- package/dist/cjs/execution-time-fingerprint.d.ts +65 -0
- package/dist/cjs/execution-time-fingerprint.d.ts.map +1 -0
- package/dist/cjs/execution-time-fingerprint.js +129 -0
- package/dist/cjs/execution-time-fingerprint.js.map +1 -0
- package/dist/cjs/final-answer-proof.d.ts +2 -7
- package/dist/cjs/final-answer-proof.d.ts.map +1 -1
- package/dist/cjs/final-answer-proof.js +14 -11
- package/dist/cjs/final-answer-proof.js.map +1 -1
- package/dist/cjs/freshness.d.ts +6 -1
- package/dist/cjs/freshness.d.ts.map +1 -1
- package/dist/cjs/freshness.js +6 -1
- package/dist/cjs/freshness.js.map +1 -1
- package/dist/cjs/guard.d.ts.map +1 -1
- package/dist/cjs/guard.js +35 -0
- package/dist/cjs/guard.js.map +1 -1
- package/dist/cjs/index.d.ts +10 -8
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +20 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types.d.ts +26 -2
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +3 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/adapters/anthropic.d.ts +26 -0
- package/dist/esm/adapters/anthropic.d.ts.map +1 -1
- package/dist/esm/adapters/anthropic.js +66 -0
- package/dist/esm/adapters/anthropic.js.map +1 -1
- package/dist/esm/adapters/gemini.d.ts +39 -0
- package/dist/esm/adapters/gemini.d.ts.map +1 -1
- package/dist/esm/adapters/gemini.js +81 -0
- package/dist/esm/adapters/gemini.js.map +1 -1
- package/dist/esm/adapters/langgraph.d.ts +29 -0
- package/dist/esm/adapters/langgraph.d.ts.map +1 -1
- package/dist/esm/adapters/langgraph.js +68 -0
- package/dist/esm/adapters/langgraph.js.map +1 -1
- package/dist/esm/adapters/openai.d.ts +44 -0
- package/dist/esm/adapters/openai.d.ts.map +1 -1
- package/dist/esm/adapters/openai.js +84 -0
- package/dist/esm/adapters/openai.js.map +1 -1
- package/dist/esm/execution-proof.d.ts +7 -0
- package/dist/esm/execution-proof.d.ts.map +1 -1
- package/dist/esm/execution-proof.js +1 -0
- package/dist/esm/execution-proof.js.map +1 -1
- package/dist/esm/execution-time-fingerprint.d.ts +65 -0
- package/dist/esm/execution-time-fingerprint.d.ts.map +1 -0
- package/dist/esm/execution-time-fingerprint.js +123 -0
- package/dist/esm/execution-time-fingerprint.js.map +1 -0
- package/dist/esm/final-answer-proof.d.ts +2 -7
- package/dist/esm/final-answer-proof.d.ts.map +1 -1
- package/dist/esm/final-answer-proof.js +14 -11
- package/dist/esm/final-answer-proof.js.map +1 -1
- package/dist/esm/freshness.d.ts +6 -1
- package/dist/esm/freshness.d.ts.map +1 -1
- package/dist/esm/freshness.js +6 -1
- package/dist/esm/freshness.js.map +1 -1
- package/dist/esm/guard.d.ts.map +1 -1
- package/dist/esm/guard.js +35 -0
- package/dist/esm/guard.js.map +1 -1
- package/dist/esm/index.d.ts +10 -8
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +10 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +26 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +3 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,9 @@ const outcome = await guardToolCall(
|
|
|
38
38
|
// server preflights. `id`/`type`/`before`/`after` are all required for each artifact.
|
|
39
39
|
artifacts: [{ id: 'public-api', type: 'openapi', before: baseSpec, after: proposedSpec }],
|
|
40
40
|
},
|
|
41
|
-
// The mutating work is created ONLY here, after the verdict — never eagerly
|
|
41
|
+
// The mutating work is created ONLY here, after the verdict — never eagerly. That closes the
|
|
42
|
+
// EAGER-EXECUTION ORDERING hazard (work is built after the verdict, not before). It does NOT
|
|
43
|
+
// close the measurement-to-commit race: see "TOCTOU is unclosed" above.
|
|
42
44
|
async (envelope, redactedCall) => applyEdit(redactedCall),
|
|
43
45
|
{ client, operation: 'merge', environment: 'production' },
|
|
44
46
|
);
|
|
@@ -107,6 +109,44 @@ const answer = attachProofToAgentResponse('I applied the authorized edit.', outc
|
|
|
107
109
|
|
|
108
110
|
See `examples/final-answer-proof.mjs` for verified vs skipped side by side.
|
|
109
111
|
|
|
112
|
+
### Framework proof-binders (ID827, guard@6.1)
|
|
113
|
+
|
|
114
|
+
After `guardToolCall` returns a `GuardOutcome`, the binders map that **whole outcome** into the
|
|
115
|
+
framework’s **tool-result** shape so the execution proof travels back to the model in the tool
|
|
116
|
+
message — not only in a human final answer.
|
|
117
|
+
|
|
118
|
+
| Function | Id arg | Target field |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `bindOpenAIGuardOutcome(outcome, { tool_call_id })` | `tool_call_id` | OpenAI tool message `content` (string) |
|
|
121
|
+
| `bindAnthropicGuardOutcome(outcome, { tool_use_id })` | `tool_use_id` | Anthropic `tool_result` `content` (string) |
|
|
122
|
+
| `bindGeminiGuardOutcome(outcome, { name })` | function `name` | Gemini `functionResponse.response` — a **structured object** `{ result, final_answer_proof, … }` (not a text field) |
|
|
123
|
+
| `bindLangGraphGuardOutcome(outcome, { tool_call_id, name? })` | `tool_call_id` (+ optional `name`) | LangGraph/LangChain ToolMessage `content` (string) |
|
|
124
|
+
|
|
125
|
+
**Behaviour (all four):** take the full `GuardOutcome` (ALLOW / BLOCK / APPROVAL / SKIPPED / error
|
|
126
|
+
arms); always embed `outcome.proof` (present on every arm); on a blocked arm state that the gate
|
|
127
|
+
did not permit execution with **no fabricated tool result**; on factory-error arms report the
|
|
128
|
+
failure + proof. Pure and non-mutating. No framework SDK dependency — minimal local types only.
|
|
129
|
+
Return types are type-level branded (`ProofBoundOpenAIToolMessage`, etc.) so the compiler can
|
|
130
|
+
distinguish a proof-bound tool result from a raw one (proof-forgotten *detection*, not
|
|
131
|
+
prevention). Proof formatting reuses `attachProofToAgentResponse` / `renderFinalAnswerProof`.
|
|
132
|
+
|
|
133
|
+
OpenAI-compatible providers (Grok, Kimi, Qwen, DeepSeek, …) use **`bindOpenAIGuardOutcome`** for
|
|
134
|
+
their tool-results — same ChatCompletions tool-message shape.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { guardToolCall, bindOpenAIGuardOutcome } from '@coderifts/agent-guard';
|
|
138
|
+
|
|
139
|
+
const outcome = await guardToolCall(
|
|
140
|
+
{ toolName: 'edit_file', arguments: args, filesTouched: [path] },
|
|
141
|
+
async (_envelope, redacted) => doEdit(redacted),
|
|
142
|
+
{ client },
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// Send this tool message back to the model (chat.completions messages[]).
|
|
146
|
+
const toolMessage = bindOpenAIGuardOutcome(outcome, { tool_call_id: toolCall.id });
|
|
147
|
+
// { role: 'tool', tool_call_id, content: '<result or gate message> + rendered proof' }
|
|
148
|
+
```
|
|
149
|
+
|
|
110
150
|
**OpenAI tool-calling (ID632 reference adapter).** Same input; OpenAI-shaped `tools` for
|
|
111
151
|
`chat.completions`, plus the same unflattened assurance objects. Shape conversion only — does
|
|
112
152
|
**not** claim product-level inescapability the core does not:
|
|
@@ -128,10 +168,14 @@ const {
|
|
|
128
168
|
|
|
129
169
|
See also `examples/openai-adapter.mjs` (not published in the npm tarball).
|
|
130
170
|
|
|
131
|
-
**OpenAI-compatible models (no extra adapter).** DeepSeek
|
|
132
|
-
|
|
171
|
+
**OpenAI-compatible models (no extra adapter).** DeepSeek and Kimi (Moonshot) use the same
|
|
172
|
+
ChatCompletions tool-calling format as OpenAI (`{ type: 'function', function: { name,
|
|
133
173
|
description, parameters } }`). Use **`withCodeRiftsOpenAI`** and point your client `baseURL`
|
|
134
174
|
(and API key) at their endpoint — zero new adapters, same guarded tools + unflattened assurance.
|
|
175
|
+
Tool-results use **`bindOpenAIGuardOutcome`** the same way as OpenAI.
|
|
176
|
+
|
|
177
|
+
**Qwen (Alibaba DashScope).** OpenAI-compatible via Model Studio compatible-mode — use
|
|
178
|
+
**`withCodeRiftsOpenAI`**, point `baseURL` at the DashScope compatible endpoint. Zero new adapters.
|
|
135
179
|
|
|
136
180
|
**Grok (xAI).** Also OpenAI-compatible tool calling — use **`withCodeRiftsOpenAI`** with the xAI `baseURL`.
|
|
137
181
|
|
|
@@ -633,7 +677,12 @@ Pass both on `withCodeRifts({ …, onEvent, monitoringSinkWired: true })`, or on
|
|
|
633
677
|
## Guarantees (tsc-verified)
|
|
634
678
|
|
|
635
679
|
- **Fail-closed by default** — any ambiguity, integrity failure, or unknown state resolves to `STOP`.
|
|
636
|
-
- **
|
|
680
|
+
- **Eager-execution ordering closed (TOCTOU proper is NOT closed)** — the factory creates the
|
|
681
|
+
mutating work *after* the verdict, so no mutation is built before authorization. The
|
|
682
|
+
measurement-to-commit race remains: content resolved at measurement time can change before the
|
|
683
|
+
host commits. Closing that needs a host-side conditional write (compare-and-swap on a version
|
|
684
|
+
token) — this package never writes, and reports `conditional_write` as a host assertion it
|
|
685
|
+
cannot verify.
|
|
637
686
|
- **Retry-safe** — `executionAttempted` is the only safe-to-retry signal; a post-authorization throw
|
|
638
687
|
is `executionAttempted:true` (the remote side effect may have landed).
|
|
639
688
|
- **`enforced:true` only on a LIVE, receipt-verified `ALLOW`/`MONITOR`** — never on cached/LKG,
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
25
25
|
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
26
|
+
import type { GuardOutcome } from '../types.js';
|
|
26
27
|
/**
|
|
27
28
|
* Anthropic Messages API `tools[]` element (tool_use definition).
|
|
28
29
|
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview
|
|
@@ -87,4 +88,29 @@ export declare function withCodeRiftsAnthropic(input: WithCodeRiftsInput): WithC
|
|
|
87
88
|
* Does not re-run the guard; does not invent assurance.
|
|
88
89
|
*/
|
|
89
90
|
export declare function anthropicToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsAnthropicResult;
|
|
91
|
+
/**
|
|
92
|
+
* Minimal Anthropic tool_result content block. No @anthropic-ai/sdk dependency.
|
|
93
|
+
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview
|
|
94
|
+
*/
|
|
95
|
+
export type AnthropicToolResult = {
|
|
96
|
+
type: 'tool_result';
|
|
97
|
+
tool_use_id: string;
|
|
98
|
+
content: string;
|
|
99
|
+
};
|
|
100
|
+
declare const __proofBoundAnthropicBrand: unique symbol;
|
|
101
|
+
export type ProofBoundAnthropicToolResult = AnthropicToolResult & {
|
|
102
|
+
readonly __proofBound: typeof __proofBoundAnthropicBrand;
|
|
103
|
+
};
|
|
104
|
+
export type BindAnthropicGuardOutcomeArgs<T> = {
|
|
105
|
+
/** Anthropic tool_use block id this tool_result answers. */
|
|
106
|
+
tool_use_id: string;
|
|
107
|
+
serialize?: (result: T) => string;
|
|
108
|
+
};
|
|
109
|
+
export declare function defaultSerializeAnthropicToolResult<T>(result: T): string;
|
|
110
|
+
/**
|
|
111
|
+
* Map a full GuardOutcome into an Anthropic tool_result block with proof embedded.
|
|
112
|
+
* Same arm mapping as bindOpenAIGuardOutcome; id field is tool_use_id.
|
|
113
|
+
*/
|
|
114
|
+
export declare function bindAnthropicGuardOutcome<T>(outcome: GuardOutcome<T>, args: BindAnthropicGuardOutcomeArgs<T>): ProofBoundAnthropicToolResult;
|
|
115
|
+
export {};
|
|
90
116
|
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,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,EAAE,CAAC,KAAK,MAAM,CAAC;CACnC,CAAC;AAEF,wBAAgB,mCAAmC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAgBxE;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,6BAA6B,CAAC,CAAC,CAAC,GACrC,6BAA6B,CA0B/B"}
|
|
@@ -27,7 +27,10 @@ exports.protectedToolToAnthropic = protectedToolToAnthropic;
|
|
|
27
27
|
exports.toAnthropicTools = toAnthropicTools;
|
|
28
28
|
exports.withCodeRiftsAnthropic = withCodeRiftsAnthropic;
|
|
29
29
|
exports.anthropicToolAdapter = anthropicToolAdapter;
|
|
30
|
+
exports.defaultSerializeAnthropicToolResult = defaultSerializeAnthropicToolResult;
|
|
31
|
+
exports.bindAnthropicGuardOutcome = bindAnthropicGuardOutcome;
|
|
30
32
|
const with_coderifts_js_1 = require("../with-coderifts.js");
|
|
33
|
+
const final_answer_proof_js_1 = require("../final-answer-proof.js");
|
|
31
34
|
/** Empty JSON Schema object — used when a ProtectedTool has no inputSchema. */
|
|
32
35
|
const EMPTY_INPUT_SCHEMA = Object.freeze({
|
|
33
36
|
type: 'object',
|
|
@@ -94,4 +97,69 @@ function anthropicToolAdapter(result) {
|
|
|
94
97
|
}
|
|
95
98
|
return out;
|
|
96
99
|
}
|
|
100
|
+
function defaultSerializeAnthropicToolResult(result) {
|
|
101
|
+
if (typeof result === 'string')
|
|
102
|
+
return result;
|
|
103
|
+
if (typeof result === 'number'
|
|
104
|
+
|| typeof result === 'boolean'
|
|
105
|
+
|| typeof result === 'bigint'
|
|
106
|
+
|| result === null
|
|
107
|
+
|| result === undefined) {
|
|
108
|
+
return String(result);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
return JSON.stringify(result);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return String(result);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Map a full GuardOutcome into an Anthropic tool_result block with proof embedded.
|
|
119
|
+
* Same arm mapping as bindOpenAIGuardOutcome; id field is tool_use_id.
|
|
120
|
+
*/
|
|
121
|
+
function bindAnthropicGuardOutcome(outcome, args) {
|
|
122
|
+
const tool_use_id = args.tool_use_id;
|
|
123
|
+
const serialize = args.serialize ?? defaultSerializeAnthropicToolResult;
|
|
124
|
+
let body;
|
|
125
|
+
if (outcome.executed === true) {
|
|
126
|
+
body = serialize(outcome.result);
|
|
127
|
+
}
|
|
128
|
+
else if (outcome.executionAttempted === false) {
|
|
129
|
+
const kind = verdictKind(outcome);
|
|
130
|
+
body =
|
|
131
|
+
`CodeRifts gate did not permit execution (verdict: ${kind}). `
|
|
132
|
+
+ 'No tool result was produced.';
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const err = 'error' in outcome ? outcome.error : undefined;
|
|
136
|
+
const kind = verdictKind(outcome);
|
|
137
|
+
body =
|
|
138
|
+
`Tool execution failed after gate decision (verdict: ${kind}): ${formatGuardError(err)}`;
|
|
139
|
+
}
|
|
140
|
+
const content = (0, final_answer_proof_js_1.attachProofToAgentResponse)(body, outcome.proof);
|
|
141
|
+
const block = {
|
|
142
|
+
type: 'tool_result',
|
|
143
|
+
tool_use_id,
|
|
144
|
+
content,
|
|
145
|
+
};
|
|
146
|
+
return block;
|
|
147
|
+
}
|
|
148
|
+
function verdictKind(outcome) {
|
|
149
|
+
return outcome.verdict && typeof outcome.verdict === 'object' && 'kind' in outcome.verdict
|
|
150
|
+
? String(outcome.verdict.kind)
|
|
151
|
+
: 'UNKNOWN';
|
|
152
|
+
}
|
|
153
|
+
function formatGuardError(err) {
|
|
154
|
+
if (err instanceof Error)
|
|
155
|
+
return err.message || err.name || 'Error';
|
|
156
|
+
if (typeof err === 'string')
|
|
157
|
+
return err;
|
|
158
|
+
try {
|
|
159
|
+
return JSON.stringify(err);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return String(err);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
97
165
|
//# sourceMappingURL=anthropic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/adapters/anthropic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/adapters/anthropic.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AA6DH,4DAgBC;AAMD,4CAEC;AAYD,wDAGC;AAQD,oDAcC;AAyBD,kFAgBC;AAMD,8DA6BC;AApMD,4DAAqD;AASrD,oEAAsE;AAwCtE,+EAA+E;AAC/E,MAAM,kBAAkB,GAA4B,MAAM,CAAC,MAAM,CAAC;IAChE,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,IAAmB;IAC1D,MAAM,YAAY,GAChB,IAAI,CAAC,WAAW,IAAI,IAAI;WACrB,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ;WACpC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC;QACjC,CAAC,CAAE,IAAI,CAAC,WAAuC;QAC/C,CAAC,CAAC,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAEhC,MAAM,GAAG,GAAkB;QACzB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,YAAY;KACb,CAAC;IACF,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,IAAI,IAAI,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;QACxD,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,cAAwC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I,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC;IACpE,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
31
31
|
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
32
|
+
import type { GuardOutcome } from '../types.js';
|
|
32
33
|
/**
|
|
33
34
|
* One Gemini function declaration (inside functionDeclarations[]).
|
|
34
35
|
* @see https://ai.google.dev/gemini-api/docs/function-calling
|
|
@@ -111,4 +112,42 @@ export declare function withCodeRiftsGemini(input: WithCodeRiftsInput): WithCode
|
|
|
111
112
|
* Does not re-run the guard; does not invent assurance.
|
|
112
113
|
*/
|
|
113
114
|
export declare function geminiToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsGeminiResult;
|
|
115
|
+
/**
|
|
116
|
+
* Minimal Gemini functionResponse part. No @google/generative-ai dependency.
|
|
117
|
+
* `response` is a structured object (not a text string).
|
|
118
|
+
* @see https://ai.google.dev/gemini-api/docs/function-calling
|
|
119
|
+
*/
|
|
120
|
+
export type GeminiFunctionResponse = {
|
|
121
|
+
functionResponse: {
|
|
122
|
+
name: string;
|
|
123
|
+
response: Record<string, unknown>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
declare const __proofBoundGeminiBrand: unique symbol;
|
|
127
|
+
export type ProofBoundGeminiFunctionResponse = GeminiFunctionResponse & {
|
|
128
|
+
readonly __proofBound: typeof __proofBoundGeminiBrand;
|
|
129
|
+
};
|
|
130
|
+
export type BindGeminiGuardOutcomeArgs<T> = {
|
|
131
|
+
/** Gemini function name this functionResponse answers. */
|
|
132
|
+
name: string;
|
|
133
|
+
/**
|
|
134
|
+
* Optional result projector into the response.result field.
|
|
135
|
+
* Default keeps JSON-friendly values as-is (objects/arrays/primitives);
|
|
136
|
+
* non-JSON values fall back to String().
|
|
137
|
+
*/
|
|
138
|
+
serialize?: (result: T) => unknown;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Default Gemini result payload value (structured, not forced through JSON.stringify).
|
|
142
|
+
*/
|
|
143
|
+
export declare function defaultSerializeGeminiToolResult<T>(result: T): unknown;
|
|
144
|
+
/**
|
|
145
|
+
* Map a full GuardOutcome into a Gemini functionResponse part with proof embedded.
|
|
146
|
+
*
|
|
147
|
+
* GEMINI SPECIAL: response is an OBJECT (not a text field):
|
|
148
|
+
* - executed: { result, final_answer_proof, final_answer_proof_text } via attachProofToAgentResponse
|
|
149
|
+
* - blocked/error: { gate_message, final_answer_proof, … } — no fabricated `result` key
|
|
150
|
+
*/
|
|
151
|
+
export declare function bindGeminiGuardOutcome<T>(outcome: GuardOutcome<T>, args: BindGeminiGuardOutcomeArgs<T>): ProofBoundGeminiFunctionResponse;
|
|
152
|
+
export {};
|
|
114
153
|
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../../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AAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,yBAAyB,CAcxF;AAID;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;CACH,CAAC;AAEF,OAAO,CAAC,MAAM,uBAAuB,EAAE,OAAO,MAAM,CAAC;AACrD,MAAM,MAAM,gCAAgC,GAAG,sBAAsB,GAAG;IACtE,QAAQ,CAAC,YAAY,EAAE,OAAO,uBAAuB,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI;IAC1C,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;CACpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAqBtE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,0BAA0B,CAAC,CAAC,CAAC,GAClC,gCAAgC,CAoClC"}
|
|
@@ -33,7 +33,10 @@ exports.protectedToolToFunctionDeclaration = protectedToolToFunctionDeclaration;
|
|
|
33
33
|
exports.toGeminiTools = toGeminiTools;
|
|
34
34
|
exports.withCodeRiftsGemini = withCodeRiftsGemini;
|
|
35
35
|
exports.geminiToolAdapter = geminiToolAdapter;
|
|
36
|
+
exports.defaultSerializeGeminiToolResult = defaultSerializeGeminiToolResult;
|
|
37
|
+
exports.bindGeminiGuardOutcome = bindGeminiGuardOutcome;
|
|
36
38
|
const with_coderifts_js_1 = require("../with-coderifts.js");
|
|
39
|
+
const final_answer_proof_js_1 = require("../final-answer-proof.js");
|
|
37
40
|
/** Empty OpenAPI-like JSON Schema — used when a ProtectedTool has no inputSchema. */
|
|
38
41
|
const EMPTY_PARAMETERS = Object.freeze({
|
|
39
42
|
type: 'object',
|
|
@@ -107,4 +110,84 @@ function geminiToolAdapter(result) {
|
|
|
107
110
|
}
|
|
108
111
|
return out;
|
|
109
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Default Gemini result payload value (structured, not forced through JSON.stringify).
|
|
115
|
+
*/
|
|
116
|
+
function defaultSerializeGeminiToolResult(result) {
|
|
117
|
+
if (result === null
|
|
118
|
+
|| result === undefined
|
|
119
|
+
|| typeof result === 'string'
|
|
120
|
+
|| typeof result === 'number'
|
|
121
|
+
|| typeof result === 'boolean') {
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
if (typeof result === 'bigint')
|
|
125
|
+
return String(result);
|
|
126
|
+
if (typeof result === 'object') {
|
|
127
|
+
try {
|
|
128
|
+
// Ensure JSON-serializable by round-trip when possible; on failure keep shallow.
|
|
129
|
+
JSON.stringify(result);
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return String(result);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return String(result);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Map a full GuardOutcome into a Gemini functionResponse part with proof embedded.
|
|
140
|
+
*
|
|
141
|
+
* GEMINI SPECIAL: response is an OBJECT (not a text field):
|
|
142
|
+
* - executed: { result, final_answer_proof, final_answer_proof_text } via attachProofToAgentResponse
|
|
143
|
+
* - blocked/error: { gate_message, final_answer_proof, … } — no fabricated `result` key
|
|
144
|
+
*/
|
|
145
|
+
function bindGeminiGuardOutcome(outcome, args) {
|
|
146
|
+
const name = args.name;
|
|
147
|
+
const serialize = args.serialize ?? defaultSerializeGeminiToolResult;
|
|
148
|
+
let base;
|
|
149
|
+
if (outcome.executed === true) {
|
|
150
|
+
base = { result: serialize(outcome.result) };
|
|
151
|
+
}
|
|
152
|
+
else if (outcome.executionAttempted === false) {
|
|
153
|
+
const kind = verdictKind(outcome);
|
|
154
|
+
base = {
|
|
155
|
+
gate_message: `CodeRifts gate did not permit execution (verdict: ${kind}). `
|
|
156
|
+
+ 'No tool result was produced.',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const err = 'error' in outcome ? outcome.error : undefined;
|
|
161
|
+
const kind = verdictKind(outcome);
|
|
162
|
+
base = {
|
|
163
|
+
gate_message: `Tool execution failed after gate decision (verdict: ${kind}): ${formatGuardError(err)}`,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// Reuse attachProofToAgentResponse object path → adds final_answer_proof + final_answer_proof_text.
|
|
167
|
+
const bound = (0, final_answer_proof_js_1.attachProofToAgentResponse)(base, outcome.proof);
|
|
168
|
+
const part = {
|
|
169
|
+
functionResponse: {
|
|
170
|
+
name,
|
|
171
|
+
response: bound,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
return part;
|
|
175
|
+
}
|
|
176
|
+
function verdictKind(outcome) {
|
|
177
|
+
return outcome.verdict && typeof outcome.verdict === 'object' && 'kind' in outcome.verdict
|
|
178
|
+
? String(outcome.verdict.kind)
|
|
179
|
+
: 'UNKNOWN';
|
|
180
|
+
}
|
|
181
|
+
function formatGuardError(err) {
|
|
182
|
+
if (err instanceof Error)
|
|
183
|
+
return err.message || err.name || 'Error';
|
|
184
|
+
if (typeof err === 'string')
|
|
185
|
+
return err;
|
|
186
|
+
try {
|
|
187
|
+
return JSON.stringify(err);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return String(err);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
110
193
|
//# sourceMappingURL=gemini.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;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AAO,CAAC,OAA4B,CAAC,IAAI,CAAC;QACpD,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAY;IACpC,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC;IACpE,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
36
36
|
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
37
|
+
import type { GuardOutcome } from '../types.js';
|
|
37
38
|
/**
|
|
38
39
|
* Framework-agnostic LangChain/LangGraph tool descriptor (no package import).
|
|
39
40
|
*
|
|
@@ -114,4 +115,32 @@ export declare function withCodeRiftsLangGraph(input: WithCodeRiftsInput): WithC
|
|
|
114
115
|
* Does not re-run the guard; does not invent assurance.
|
|
115
116
|
*/
|
|
116
117
|
export declare function langGraphToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsLangGraphResult;
|
|
118
|
+
/**
|
|
119
|
+
* Minimal LangChain ToolMessage-shaped plain object (no @langchain/* dependency).
|
|
120
|
+
* Host may wrap into ToolMessage: new ToolMessage({ content, tool_call_id, name? }).
|
|
121
|
+
* @see https://js.langchain.com/docs/concepts/messages
|
|
122
|
+
*/
|
|
123
|
+
export type LangGraphToolMessage = {
|
|
124
|
+
content: string;
|
|
125
|
+
tool_call_id: string;
|
|
126
|
+
name?: string;
|
|
127
|
+
};
|
|
128
|
+
declare const __proofBoundLangGraphBrand: unique symbol;
|
|
129
|
+
export type ProofBoundLangGraphToolMessage = LangGraphToolMessage & {
|
|
130
|
+
readonly __proofBound: typeof __proofBoundLangGraphBrand;
|
|
131
|
+
};
|
|
132
|
+
export type BindLangGraphGuardOutcomeArgs<T> = {
|
|
133
|
+
/** LangChain/LangGraph tool_call_id this ToolMessage answers. */
|
|
134
|
+
tool_call_id: string;
|
|
135
|
+
/** Optional tool name (ToolMessage.name). */
|
|
136
|
+
name?: string;
|
|
137
|
+
serialize?: (result: T) => string;
|
|
138
|
+
};
|
|
139
|
+
export declare function defaultSerializeLangGraphToolResult<T>(result: T): string;
|
|
140
|
+
/**
|
|
141
|
+
* Map a full GuardOutcome into a LangGraph/LangChain ToolMessage shape with proof embedded.
|
|
142
|
+
* Same arm mapping as bindOpenAIGuardOutcome; id field is tool_call_id.
|
|
143
|
+
*/
|
|
144
|
+
export declare function bindLangGraphGuardOutcome<T>(outcome: GuardOutcome<T>, args: BindLangGraphGuardOutcomeArgs<T>): ProofBoundLangGraphToolMessage;
|
|
145
|
+
export {};
|
|
117
146
|
//# sourceMappingURL=langgraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langgraph.d.ts","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"langgraph.d.ts","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB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EAAE,mBAAmB,GAAG,4BAA4B,CAc9F;AAID;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,OAAO,CAAC,MAAM,0BAA0B,EAAE,OAAO,MAAM,CAAC;AACxD,MAAM,MAAM,8BAA8B,GAAG,oBAAoB,GAAG;IAClE,QAAQ,CAAC,YAAY,EAAE,OAAO,0BAA0B,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,6BAA6B,CAAC,CAAC,IAAI;IAC7C,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;CACnC,CAAC;AAEF,wBAAgB,mCAAmC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAgBxE;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACzC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,6BAA6B,CAAC,CAAC,CAAC,GACrC,8BAA8B,CA4BhC"}
|
|
@@ -38,7 +38,10 @@ exports.protectedToolToLangGraph = protectedToolToLangGraph;
|
|
|
38
38
|
exports.toLangGraphTools = toLangGraphTools;
|
|
39
39
|
exports.withCodeRiftsLangGraph = withCodeRiftsLangGraph;
|
|
40
40
|
exports.langGraphToolAdapter = langGraphToolAdapter;
|
|
41
|
+
exports.defaultSerializeLangGraphToolResult = defaultSerializeLangGraphToolResult;
|
|
42
|
+
exports.bindLangGraphGuardOutcome = bindLangGraphGuardOutcome;
|
|
41
43
|
const with_coderifts_js_1 = require("../with-coderifts.js");
|
|
44
|
+
const final_answer_proof_js_1 = require("../final-answer-proof.js");
|
|
42
45
|
/** Empty JSON Schema object — used when a ProtectedTool has no inputSchema. */
|
|
43
46
|
const EMPTY_SCHEMA = Object.freeze({
|
|
44
47
|
type: 'object',
|
|
@@ -110,4 +113,71 @@ function langGraphToolAdapter(result) {
|
|
|
110
113
|
}
|
|
111
114
|
return out;
|
|
112
115
|
}
|
|
116
|
+
function defaultSerializeLangGraphToolResult(result) {
|
|
117
|
+
if (typeof result === 'string')
|
|
118
|
+
return result;
|
|
119
|
+
if (typeof result === 'number'
|
|
120
|
+
|| typeof result === 'boolean'
|
|
121
|
+
|| typeof result === 'bigint'
|
|
122
|
+
|| result === null
|
|
123
|
+
|| result === undefined) {
|
|
124
|
+
return String(result);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return JSON.stringify(result);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return String(result);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Map a full GuardOutcome into a LangGraph/LangChain ToolMessage shape with proof embedded.
|
|
135
|
+
* Same arm mapping as bindOpenAIGuardOutcome; id field is tool_call_id.
|
|
136
|
+
*/
|
|
137
|
+
function bindLangGraphGuardOutcome(outcome, args) {
|
|
138
|
+
const tool_call_id = args.tool_call_id;
|
|
139
|
+
const serialize = args.serialize ?? defaultSerializeLangGraphToolResult;
|
|
140
|
+
let body;
|
|
141
|
+
if (outcome.executed === true) {
|
|
142
|
+
body = serialize(outcome.result);
|
|
143
|
+
}
|
|
144
|
+
else if (outcome.executionAttempted === false) {
|
|
145
|
+
const kind = verdictKind(outcome);
|
|
146
|
+
body =
|
|
147
|
+
`CodeRifts gate did not permit execution (verdict: ${kind}). `
|
|
148
|
+
+ 'No tool result was produced.';
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const err = 'error' in outcome ? outcome.error : undefined;
|
|
152
|
+
const kind = verdictKind(outcome);
|
|
153
|
+
body =
|
|
154
|
+
`Tool execution failed after gate decision (verdict: ${kind}): ${formatGuardError(err)}`;
|
|
155
|
+
}
|
|
156
|
+
const content = (0, final_answer_proof_js_1.attachProofToAgentResponse)(body, outcome.proof);
|
|
157
|
+
const msg = {
|
|
158
|
+
content,
|
|
159
|
+
tool_call_id,
|
|
160
|
+
};
|
|
161
|
+
if (args.name != null && args.name !== '') {
|
|
162
|
+
msg.name = args.name;
|
|
163
|
+
}
|
|
164
|
+
return msg;
|
|
165
|
+
}
|
|
166
|
+
function verdictKind(outcome) {
|
|
167
|
+
return outcome.verdict && typeof outcome.verdict === 'object' && 'kind' in outcome.verdict
|
|
168
|
+
? String(outcome.verdict.kind)
|
|
169
|
+
: 'UNKNOWN';
|
|
170
|
+
}
|
|
171
|
+
function formatGuardError(err) {
|
|
172
|
+
if (err instanceof Error)
|
|
173
|
+
return err.message || err.name || 'Error';
|
|
174
|
+
if (typeof err === 'string')
|
|
175
|
+
return err;
|
|
176
|
+
try {
|
|
177
|
+
return JSON.stringify(err);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return String(err);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
113
183
|
//# sourceMappingURL=langgraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"langgraph.js","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;
|
|
1
|
+
{"version":3,"file":"langgraph.js","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;AA6EH,4DAqBC;AAMD,4CAEC;AAYD,wDAGC;AAQD,oDAcC;AA4BD,kFAgBC;AAMD,8DA+BC;AA9ND,4DAAqD;AASrD,oEAAsE;AAuDtE,+EAA+E;AAC/E,MAAM,YAAY,GAA4B,MAAM,CAAC,MAAM,CAAC;IAC1D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AA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rB,CAAC;AACH,CAAC"}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
25
25
|
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
26
|
+
import type { GuardOutcome } from '../types.js';
|
|
26
27
|
/**
|
|
27
28
|
* OpenAI chat.completions `tools[]` element (function tool).
|
|
28
29
|
* @see https://platform.openai.com/docs/guides/function-calling
|
|
@@ -90,4 +91,47 @@ export declare function withCodeRiftsOpenAI(input: WithCodeRiftsInput): WithCode
|
|
|
90
91
|
* Does not re-run the guard; does not invent assurance.
|
|
91
92
|
*/
|
|
92
93
|
export declare function openAIToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsOpenAIResult;
|
|
94
|
+
/**
|
|
95
|
+
* Minimal OpenAI chat tool-message (role tool). No openai SDK dependency.
|
|
96
|
+
* @see https://platform.openai.com/docs/guides/function-calling
|
|
97
|
+
*/
|
|
98
|
+
export type OpenAIToolMessage = {
|
|
99
|
+
role: 'tool';
|
|
100
|
+
tool_call_id: string;
|
|
101
|
+
content: string;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Brand for proof-bound OpenAI tool messages (compile-time detection of proof-forgotten paths).
|
|
105
|
+
* Type-level only — same pattern as ReceiptVerifiedEnvelope; not a runtime wire field.
|
|
106
|
+
*/
|
|
107
|
+
declare const __proofBoundBrand: unique symbol;
|
|
108
|
+
export type ProofBoundOpenAIToolMessage = OpenAIToolMessage & {
|
|
109
|
+
readonly __proofBound: typeof __proofBoundBrand;
|
|
110
|
+
};
|
|
111
|
+
export type BindOpenAIGuardOutcomeArgs<T> = {
|
|
112
|
+
/** OpenAI tool_call_id this message answers. */
|
|
113
|
+
tool_call_id: string;
|
|
114
|
+
/** Override result serialization (default: JSON.stringify objects, String() primitives). */
|
|
115
|
+
serialize?: (result: T) => string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Default result → content body serializer (pure).
|
|
119
|
+
* Objects/arrays → JSON.stringify; strings unchanged; other primitives → String().
|
|
120
|
+
*/
|
|
121
|
+
export declare function defaultSerializeOpenAIToolResult<T>(result: T): string;
|
|
122
|
+
/**
|
|
123
|
+
* Map a full GuardOutcome into an OpenAI tool message with the execution proof embedded.
|
|
124
|
+
*
|
|
125
|
+
* Option B (proof-binding helper): host still calls guardToolCall; this only binds
|
|
126
|
+
* outcome → framework tool-result. Pure and non-mutating. Always embeds outcome.proof
|
|
127
|
+
* (present on every arm) via attachProofToAgentResponse / renderFinalAnswerProof —
|
|
128
|
+
* does not reinvent proof formatting.
|
|
129
|
+
*
|
|
130
|
+
* Arms:
|
|
131
|
+
* - executed (result): serialized result + rendered proof
|
|
132
|
+
* - blocked before factory: gate-denied text (no fabricated result) + proof
|
|
133
|
+
* - factory threw: error indication + proof
|
|
134
|
+
*/
|
|
135
|
+
export declare function bindOpenAIGuardOutcome<T>(outcome: GuardOutcome<T>, args: BindOpenAIGuardOutcomeArgs<T>): ProofBoundOpenAIToolMessage;
|
|
136
|
+
export {};
|
|
93
137
|
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,E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