@coderifts/agent-guard 4.2.0 → 4.3.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 +162 -35
- package/dist/cjs/adapters/anthropic.d.ts +90 -0
- package/dist/cjs/adapters/anthropic.d.ts.map +1 -0
- package/dist/cjs/adapters/anthropic.js +97 -0
- package/dist/cjs/adapters/anthropic.js.map +1 -0
- package/dist/cjs/adapters/gemini.d.ts +114 -0
- package/dist/cjs/adapters/gemini.d.ts.map +1 -0
- package/dist/cjs/adapters/gemini.js +110 -0
- package/dist/cjs/adapters/gemini.js.map +1 -0
- package/dist/cjs/adapters/langgraph.d.ts +117 -0
- package/dist/cjs/adapters/langgraph.d.ts.map +1 -0
- package/dist/cjs/adapters/langgraph.js +113 -0
- package/dist/cjs/adapters/langgraph.js.map +1 -0
- package/dist/cjs/adapters/openai.d.ts +93 -0
- package/dist/cjs/adapters/openai.d.ts.map +1 -0
- package/dist/cjs/adapters/openai.js +97 -0
- package/dist/cjs/adapters/openai.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +26 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/adapters/anthropic.d.ts +90 -0
- package/dist/esm/adapters/anthropic.d.ts.map +1 -0
- package/dist/esm/adapters/anthropic.js +91 -0
- package/dist/esm/adapters/anthropic.js.map +1 -0
- package/dist/esm/adapters/gemini.d.ts +114 -0
- package/dist/esm/adapters/gemini.d.ts.map +1 -0
- package/dist/esm/adapters/gemini.js +104 -0
- package/dist/esm/adapters/gemini.js.map +1 -0
- package/dist/esm/adapters/langgraph.d.ts +117 -0
- package/dist/esm/adapters/langgraph.d.ts.map +1 -0
- package/dist/esm/adapters/langgraph.js +107 -0
- package/dist/esm/adapters/langgraph.js.map +1 -0
- package/dist/esm/adapters/openai.d.ts +93 -0
- package/dist/esm/adapters/openai.d.ts.map +1 -0
- package/dist/esm/adapters/openai.js +91 -0
- package/dist/esm/adapters/openai.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic tool_use adapter over withCodeRifts (ID632 slice 2 — same thin pattern as OpenAI).
|
|
3
|
+
*
|
|
4
|
+
* Thin SHAPE converter only. Guard logic stays in withCodeRifts; this module:
|
|
5
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
6
|
+
* 2. maps each ProtectedTool → Anthropic Messages API tool definition,
|
|
7
|
+
* 3. returns Anthropic-shaped tools PLUS the untouched assurance objects
|
|
8
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
9
|
+
*
|
|
10
|
+
* Honesty (do not "upgrade" assurance):
|
|
11
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
12
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
13
|
+
* - The adapter converts tool SHAPE for the model API; it does not claim product-level
|
|
14
|
+
* inescapability the core does not claim.
|
|
15
|
+
*
|
|
16
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
17
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
18
|
+
* - Raw tools never appear in the returned Anthropic table. The host may still hold a raw
|
|
19
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
20
|
+
*
|
|
21
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → Anthropic-ready guarded tools.
|
|
22
|
+
* Mirrors src/adapters/openai.ts — only the target tool shape differs.
|
|
23
|
+
*/
|
|
24
|
+
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
25
|
+
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
26
|
+
/**
|
|
27
|
+
* Anthropic Messages API `tools[]` element (tool_use definition).
|
|
28
|
+
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview
|
|
29
|
+
*/
|
|
30
|
+
export type AnthropicTool = {
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
/** JSON Schema object for the tool input (Anthropic `input_schema`). */
|
|
34
|
+
input_schema: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Result of withCodeRiftsAnthropic — Anthropic tool definitions + core assurance, unflattened.
|
|
38
|
+
*
|
|
39
|
+
* `tools` is the ONLY list intended for the model/runtime tool table. `protected_tools` is the
|
|
40
|
+
* same guarded list (with execute) for host dispatch after tool_use blocks — never the raw tools.
|
|
41
|
+
*/
|
|
42
|
+
export type WithCodeRiftsAnthropicResult = {
|
|
43
|
+
/** Anthropic-shaped tools for messages.create — only protected/guarded tools. */
|
|
44
|
+
tools: AnthropicTool[];
|
|
45
|
+
/**
|
|
46
|
+
* Guarded ProtectedTool list from withCodeRifts (same tools as `tools`, with execute).
|
|
47
|
+
* Host dispatches model tool_use through these only. Never raw tools.
|
|
48
|
+
*/
|
|
49
|
+
protected_tools: ProtectedTool[];
|
|
50
|
+
/** Untouched registry report — registry's own truth. */
|
|
51
|
+
registry_report: RegistryCoverageReport;
|
|
52
|
+
/**
|
|
53
|
+
* Product-level assurance — deliberately narrower than the registry.
|
|
54
|
+
* Passed through untouched; may still show inescapable_runtime:false and
|
|
55
|
+
* residual composition_call_policy_incomplete.
|
|
56
|
+
*/
|
|
57
|
+
composition_assurance: CompositionAssurance;
|
|
58
|
+
/** Per-composition receipt cursor — NOT product-truth chain evidence. */
|
|
59
|
+
receipt_thread: ReceiptThreadHandle;
|
|
60
|
+
repository?: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Map one ProtectedTool → Anthropic tool definition (shape only; no execute).
|
|
64
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
65
|
+
*/
|
|
66
|
+
export declare function protectedToolToAnthropic(tool: ProtectedTool): AnthropicTool;
|
|
67
|
+
/**
|
|
68
|
+
* Convert a list of ProtectedTool into Anthropic tool definitions.
|
|
69
|
+
* Does NOT call the guard — pure shape map over an already-protected list.
|
|
70
|
+
*/
|
|
71
|
+
export declare function toAnthropicTools(protectedTools: readonly ProtectedTool[]): AnthropicTool[];
|
|
72
|
+
/**
|
|
73
|
+
* Build Anthropic-ready guarded tools from raw tools + client + operation.
|
|
74
|
+
*
|
|
75
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
76
|
+
* - `tools` — Anthropic messages API shape ({ name, description?, input_schema })
|
|
77
|
+
* - `protected_tools` — same guarded tools for host execute dispatch
|
|
78
|
+
* - assurance objects from the core, passed through untouched
|
|
79
|
+
*
|
|
80
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
81
|
+
*/
|
|
82
|
+
export declare function withCodeRiftsAnthropic(input: WithCodeRiftsInput): WithCodeRiftsAnthropicResult;
|
|
83
|
+
/**
|
|
84
|
+
* Shape-only adapter over an existing WithCodeRiftsResult (composition style).
|
|
85
|
+
* Prefer withCodeRiftsAnthropic when starting from raw tools.
|
|
86
|
+
*
|
|
87
|
+
* Does not re-run the guard; does not invent assurance.
|
|
88
|
+
*/
|
|
89
|
+
export declare function anthropicToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsAnthropicResult;
|
|
90
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +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;AAEjF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,iFAAiF;IACjF,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB;;;OAGG;IACH,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,wDAAwD;IACxD,eAAe,EAAE,sBAAsB,CAAC;IACxC;;;;OAIG;IACH,qBAAqB,EAAE,oBAAoB,CAAC;IAC5C,yEAAyE;IACzE,cAAc,EAAE,mBAAmB,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CAgB3E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,EAAE,CAE1F;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,CAG9F;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,4BAA4B,CAc9F"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic tool_use adapter over withCodeRifts (ID632 slice 2 — same thin pattern as OpenAI).
|
|
3
|
+
*
|
|
4
|
+
* Thin SHAPE converter only. Guard logic stays in withCodeRifts; this module:
|
|
5
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
6
|
+
* 2. maps each ProtectedTool → Anthropic Messages API tool definition,
|
|
7
|
+
* 3. returns Anthropic-shaped tools PLUS the untouched assurance objects
|
|
8
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
9
|
+
*
|
|
10
|
+
* Honesty (do not "upgrade" assurance):
|
|
11
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
12
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
13
|
+
* - The adapter converts tool SHAPE for the model API; it does not claim product-level
|
|
14
|
+
* inescapability the core does not claim.
|
|
15
|
+
*
|
|
16
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
17
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
18
|
+
* - Raw tools never appear in the returned Anthropic table. The host may still hold a raw
|
|
19
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
20
|
+
*
|
|
21
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → Anthropic-ready guarded tools.
|
|
22
|
+
* Mirrors src/adapters/openai.ts — only the target tool shape differs.
|
|
23
|
+
*/
|
|
24
|
+
import { withCodeRifts } from '../with-coderifts.js';
|
|
25
|
+
/** Empty JSON Schema object — used when a ProtectedTool has no inputSchema. */
|
|
26
|
+
const EMPTY_INPUT_SCHEMA = Object.freeze({
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {},
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Map one ProtectedTool → Anthropic tool definition (shape only; no execute).
|
|
32
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
33
|
+
*/
|
|
34
|
+
export function protectedToolToAnthropic(tool) {
|
|
35
|
+
const input_schema = tool.inputSchema != null
|
|
36
|
+
&& typeof tool.inputSchema === 'object'
|
|
37
|
+
&& !Array.isArray(tool.inputSchema)
|
|
38
|
+
? tool.inputSchema
|
|
39
|
+
: { ...EMPTY_INPUT_SCHEMA };
|
|
40
|
+
const out = {
|
|
41
|
+
name: tool.name,
|
|
42
|
+
input_schema,
|
|
43
|
+
};
|
|
44
|
+
if (tool.description != null && tool.description !== '') {
|
|
45
|
+
out.description = tool.description;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Convert a list of ProtectedTool into Anthropic tool definitions.
|
|
51
|
+
* Does NOT call the guard — pure shape map over an already-protected list.
|
|
52
|
+
*/
|
|
53
|
+
export function toAnthropicTools(protectedTools) {
|
|
54
|
+
return protectedTools.map(protectedToolToAnthropic);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build Anthropic-ready guarded tools from raw tools + client + operation.
|
|
58
|
+
*
|
|
59
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
60
|
+
* - `tools` — Anthropic messages API shape ({ name, description?, input_schema })
|
|
61
|
+
* - `protected_tools` — same guarded tools for host execute dispatch
|
|
62
|
+
* - assurance objects from the core, passed through untouched
|
|
63
|
+
*
|
|
64
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
65
|
+
*/
|
|
66
|
+
export function withCodeRiftsAnthropic(input) {
|
|
67
|
+
const core = withCodeRifts(input);
|
|
68
|
+
return anthropicToolAdapter(core);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Shape-only adapter over an existing WithCodeRiftsResult (composition style).
|
|
72
|
+
* Prefer withCodeRiftsAnthropic when starting from raw tools.
|
|
73
|
+
*
|
|
74
|
+
* Does not re-run the guard; does not invent assurance.
|
|
75
|
+
*/
|
|
76
|
+
export function anthropicToolAdapter(result) {
|
|
77
|
+
const protected_tools = result.tools;
|
|
78
|
+
const tools = toAnthropicTools(protected_tools);
|
|
79
|
+
const out = {
|
|
80
|
+
tools,
|
|
81
|
+
protected_tools,
|
|
82
|
+
registry_report: result.registry_report,
|
|
83
|
+
composition_assurance: result.composition_assurance,
|
|
84
|
+
receipt_thread: result.receipt_thread,
|
|
85
|
+
};
|
|
86
|
+
if (result.repository !== undefined) {
|
|
87
|
+
out.repository = result.repository;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/adapters/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AA+CrD,+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,MAAM,UAAU,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,MAAM,UAAU,gBAAgB,CAAC,cAAwC;IACvE,OAAO,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAyB;IAC9D,MAAM,IAAI,GAAwB,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAA2B;IAC9D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,GAAG,GAAiC;QACxC,KAAK;QACL,eAAe;QACf,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;QACnD,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;IACF,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini function-calling adapter over withCodeRifts (ID632 slice 4 —
|
|
3
|
+
* same thin pattern as OpenAI / Anthropic / LangGraph).
|
|
4
|
+
*
|
|
5
|
+
* Thin SHAPE converter only. Guard logic stays in withCodeRifts; this module:
|
|
6
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
7
|
+
* 2. maps ProtectedTool[] → Gemini generateContent tools shape,
|
|
8
|
+
* 3. returns Gemini-shaped tools PLUS the untouched assurance objects
|
|
9
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
10
|
+
*
|
|
11
|
+
* Gemini nesting (differs from OpenAI):
|
|
12
|
+
* tools: [ { functionDeclarations: [ { name, description?, parameters }, … ] } ]
|
|
13
|
+
* One tools entry wraps ALL declarations in a single functionDeclarations array —
|
|
14
|
+
* not one { type: 'function' } object per tool.
|
|
15
|
+
*
|
|
16
|
+
* Honesty (do not "upgrade" assurance):
|
|
17
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
18
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
19
|
+
* - The adapter converts tool SHAPE for the model API; it does not claim product-level
|
|
20
|
+
* inescapability the core does not claim.
|
|
21
|
+
*
|
|
22
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
23
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
24
|
+
* - Raw tools never appear in the returned Gemini table. The host may still hold a raw
|
|
25
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
26
|
+
*
|
|
27
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → Gemini-ready tools.
|
|
28
|
+
* Mirrors src/adapters/openai.ts — only the target tool shape differs.
|
|
29
|
+
*/
|
|
30
|
+
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
31
|
+
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
32
|
+
/**
|
|
33
|
+
* One Gemini function declaration (inside functionDeclarations[]).
|
|
34
|
+
* @see https://ai.google.dev/gemini-api/docs/function-calling
|
|
35
|
+
*/
|
|
36
|
+
export type GeminiFunctionDeclaration = {
|
|
37
|
+
name: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
/**
|
|
40
|
+
* OpenAPI-like JSON Schema for function parameters
|
|
41
|
+
* (Gemini `parameters` — from ProtectedTool.inputSchema).
|
|
42
|
+
*/
|
|
43
|
+
parameters: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Gemini `tools[]` element: a single wrapper holding all functionDeclarations.
|
|
47
|
+
* Unlike OpenAI (one {type:'function'} per tool), Gemini nests every declaration
|
|
48
|
+
* under one functionDeclarations array.
|
|
49
|
+
*/
|
|
50
|
+
export type GeminiTool = {
|
|
51
|
+
functionDeclarations: GeminiFunctionDeclaration[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Result of withCodeRiftsGemini — Gemini tool definitions + core assurance, unflattened.
|
|
55
|
+
*
|
|
56
|
+
* `tools` is typically a one-element array:
|
|
57
|
+
* [ { functionDeclarations: [ …all protected tools… ] } ]
|
|
58
|
+
* `protected_tools` is the same guarded list (with execute) for host dispatch after functionCall.
|
|
59
|
+
*/
|
|
60
|
+
export type WithCodeRiftsGeminiResult = {
|
|
61
|
+
/**
|
|
62
|
+
* Gemini generateContent `tools` array — only protected/guarded tools, nested under
|
|
63
|
+
* functionDeclarations (usually length 1 wrapper).
|
|
64
|
+
*/
|
|
65
|
+
tools: GeminiTool[];
|
|
66
|
+
/**
|
|
67
|
+
* Guarded ProtectedTool list from withCodeRifts.
|
|
68
|
+
* Host dispatches model functionCall through these only. Never raw tools.
|
|
69
|
+
*/
|
|
70
|
+
protected_tools: ProtectedTool[];
|
|
71
|
+
/** Untouched registry report — registry's own truth. */
|
|
72
|
+
registry_report: RegistryCoverageReport;
|
|
73
|
+
/**
|
|
74
|
+
* Product-level assurance — deliberately narrower than the registry.
|
|
75
|
+
* Passed through untouched; may still show inescapable_runtime:false and
|
|
76
|
+
* residual composition_call_policy_incomplete.
|
|
77
|
+
*/
|
|
78
|
+
composition_assurance: CompositionAssurance;
|
|
79
|
+
/** Per-composition receipt cursor — NOT product-truth chain evidence. */
|
|
80
|
+
receipt_thread: ReceiptThreadHandle;
|
|
81
|
+
repository?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Map one ProtectedTool → Gemini functionDeclaration (shape only; no execute).
|
|
85
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
86
|
+
*/
|
|
87
|
+
export declare function protectedToolToFunctionDeclaration(tool: ProtectedTool): GeminiFunctionDeclaration;
|
|
88
|
+
/**
|
|
89
|
+
* Convert ProtectedTool[] into Gemini `tools` array:
|
|
90
|
+
* [ { functionDeclarations: [ … ] } ]
|
|
91
|
+
*
|
|
92
|
+
* Empty protected list → empty tools array (no empty wrapper).
|
|
93
|
+
* Does NOT call the guard — pure shape map over an already-protected list.
|
|
94
|
+
*/
|
|
95
|
+
export declare function toGeminiTools(protectedTools: readonly ProtectedTool[]): GeminiTool[];
|
|
96
|
+
/**
|
|
97
|
+
* Build Gemini-ready guarded tools from raw tools + client + operation.
|
|
98
|
+
*
|
|
99
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
100
|
+
* - `tools` — Gemini shape [ { functionDeclarations: […] } ]
|
|
101
|
+
* - `protected_tools` — same guarded tools for host execute dispatch
|
|
102
|
+
* - assurance objects from the core, passed through untouched
|
|
103
|
+
*
|
|
104
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
105
|
+
*/
|
|
106
|
+
export declare function withCodeRiftsGemini(input: WithCodeRiftsInput): WithCodeRiftsGeminiResult;
|
|
107
|
+
/**
|
|
108
|
+
* Shape-only adapter over an existing WithCodeRiftsResult (composition style).
|
|
109
|
+
* Prefer withCodeRiftsGemini when starting from raw tools.
|
|
110
|
+
*
|
|
111
|
+
* Does not re-run the guard; does not invent assurance.
|
|
112
|
+
*/
|
|
113
|
+
export declare function geminiToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsGeminiResult;
|
|
114
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +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;AAEjF;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,oBAAoB,EAAE,yBAAyB,EAAE,CAAC;CACnD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;OAGG;IACH,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB;;;OAGG;IACH,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,wDAAwD;IACxD,eAAe,EAAE,sBAAsB,CAAC;IACxC;;;;OAIG;IACH,qBAAqB,EAAE,oBAAoB,CAAC;IAC5C,yEAAyE;IACzE,cAAc,EAAE,mBAAmB,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,aAAa,GAAG,yBAAyB,CAgBjG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,UAAU,EAAE,CAKpF;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,yBAAyB,CAGxF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,yBAAyB,CAcxF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Gemini function-calling adapter over withCodeRifts (ID632 slice 4 —
|
|
3
|
+
* same thin pattern as OpenAI / Anthropic / LangGraph).
|
|
4
|
+
*
|
|
5
|
+
* Thin SHAPE converter only. Guard logic stays in withCodeRifts; this module:
|
|
6
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
7
|
+
* 2. maps ProtectedTool[] → Gemini generateContent tools shape,
|
|
8
|
+
* 3. returns Gemini-shaped tools PLUS the untouched assurance objects
|
|
9
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
10
|
+
*
|
|
11
|
+
* Gemini nesting (differs from OpenAI):
|
|
12
|
+
* tools: [ { functionDeclarations: [ { name, description?, parameters }, … ] } ]
|
|
13
|
+
* One tools entry wraps ALL declarations in a single functionDeclarations array —
|
|
14
|
+
* not one { type: 'function' } object per tool.
|
|
15
|
+
*
|
|
16
|
+
* Honesty (do not "upgrade" assurance):
|
|
17
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
18
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
19
|
+
* - The adapter converts tool SHAPE for the model API; it does not claim product-level
|
|
20
|
+
* inescapability the core does not claim.
|
|
21
|
+
*
|
|
22
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
23
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
24
|
+
* - Raw tools never appear in the returned Gemini table. The host may still hold a raw
|
|
25
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
26
|
+
*
|
|
27
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → Gemini-ready tools.
|
|
28
|
+
* Mirrors src/adapters/openai.ts — only the target tool shape differs.
|
|
29
|
+
*/
|
|
30
|
+
import { withCodeRifts } from '../with-coderifts.js';
|
|
31
|
+
/** Empty OpenAPI-like JSON Schema — used when a ProtectedTool has no inputSchema. */
|
|
32
|
+
const EMPTY_PARAMETERS = Object.freeze({
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {},
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Map one ProtectedTool → Gemini functionDeclaration (shape only; no execute).
|
|
38
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
39
|
+
*/
|
|
40
|
+
export function protectedToolToFunctionDeclaration(tool) {
|
|
41
|
+
const parameters = tool.inputSchema != null
|
|
42
|
+
&& typeof tool.inputSchema === 'object'
|
|
43
|
+
&& !Array.isArray(tool.inputSchema)
|
|
44
|
+
? tool.inputSchema
|
|
45
|
+
: { ...EMPTY_PARAMETERS };
|
|
46
|
+
const out = {
|
|
47
|
+
name: tool.name,
|
|
48
|
+
parameters,
|
|
49
|
+
};
|
|
50
|
+
if (tool.description != null && tool.description !== '') {
|
|
51
|
+
out.description = tool.description;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert ProtectedTool[] into Gemini `tools` array:
|
|
57
|
+
* [ { functionDeclarations: [ … ] } ]
|
|
58
|
+
*
|
|
59
|
+
* Empty protected list → empty tools array (no empty wrapper).
|
|
60
|
+
* Does NOT call the guard — pure shape map over an already-protected list.
|
|
61
|
+
*/
|
|
62
|
+
export function toGeminiTools(protectedTools) {
|
|
63
|
+
if (protectedTools.length === 0)
|
|
64
|
+
return [];
|
|
65
|
+
return [{
|
|
66
|
+
functionDeclarations: protectedTools.map(protectedToolToFunctionDeclaration),
|
|
67
|
+
}];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build Gemini-ready guarded tools from raw tools + client + operation.
|
|
71
|
+
*
|
|
72
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
73
|
+
* - `tools` — Gemini shape [ { functionDeclarations: […] } ]
|
|
74
|
+
* - `protected_tools` — same guarded tools for host execute dispatch
|
|
75
|
+
* - assurance objects from the core, passed through untouched
|
|
76
|
+
*
|
|
77
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
78
|
+
*/
|
|
79
|
+
export function withCodeRiftsGemini(input) {
|
|
80
|
+
const core = withCodeRifts(input);
|
|
81
|
+
return geminiToolAdapter(core);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Shape-only adapter over an existing WithCodeRiftsResult (composition style).
|
|
85
|
+
* Prefer withCodeRiftsGemini when starting from raw tools.
|
|
86
|
+
*
|
|
87
|
+
* Does not re-run the guard; does not invent assurance.
|
|
88
|
+
*/
|
|
89
|
+
export function geminiToolAdapter(result) {
|
|
90
|
+
const protected_tools = result.tools;
|
|
91
|
+
const tools = toGeminiTools(protected_tools);
|
|
92
|
+
const out = {
|
|
93
|
+
tools,
|
|
94
|
+
protected_tools,
|
|
95
|
+
registry_report: result.registry_report,
|
|
96
|
+
composition_assurance: result.composition_assurance,
|
|
97
|
+
receipt_thread: result.receipt_thread,
|
|
98
|
+
};
|
|
99
|
+
if (result.repository !== undefined) {
|
|
100
|
+
out.repository = result.repository;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../../src/adapters/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AA+DrD,qFAAqF;AACrF,MAAM,gBAAgB,GAA4B,MAAM,CAAC,MAAM,CAAC;IAC9D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,IAAmB;IACpE,MAAM,UAAU,GACd,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,gBAAgB,EAAE,CAAC;IAE9B,MAAM,GAAG,GAA8B;QACrC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,UAAU;KACX,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;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,cAAwC;IACpE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC3C,OAAO,CAAC;YACN,oBAAoB,EAAE,cAAc,CAAC,GAAG,CAAC,kCAAkC,CAAC;SAC7E,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,MAAM,IAAI,GAAwB,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA2B;IAC3D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,GAAG,GAA8B;QACrC,KAAK;QACL,eAAe;QACf,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;QACnD,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;IACF,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain / LangGraph tool adapter over withCodeRifts (ID632 slice 3 — same thin
|
|
3
|
+
* pattern as OpenAI / Anthropic).
|
|
4
|
+
*
|
|
5
|
+
* Thin converter only. Guard logic stays in withCodeRifts; this module:
|
|
6
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
7
|
+
* 2. maps each ProtectedTool → a framework-agnostic tool descriptor that
|
|
8
|
+
* LangChain's tool()/StructuredTool and LangGraph's ToolNode can accept,
|
|
9
|
+
* 3. returns those descriptors PLUS the untouched assurance objects
|
|
10
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
11
|
+
*
|
|
12
|
+
* NO hard dependency on langchain / @langchain/* / langgraph packages. The host
|
|
13
|
+
* owns the framework import and wires descriptors into tool() / ToolNode /
|
|
14
|
+
* bind_tools / StateGraph themselves.
|
|
15
|
+
*
|
|
16
|
+
* Descriptor shape (dependency-free plain object):
|
|
17
|
+
* { name, description?, schema, func, invoke }
|
|
18
|
+
* - schema = JSON Schema from ProtectedTool.inputSchema (or empty object schema)
|
|
19
|
+
* - func / invoke = the GUARDED execute (same function reference) — never the raw tool
|
|
20
|
+
*
|
|
21
|
+
* Honesty (do not "upgrade" assurance):
|
|
22
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
23
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
24
|
+
* - The adapter converts tool shape + binds guarded execute; it does not claim product-level
|
|
25
|
+
* inescapability the core does not claim.
|
|
26
|
+
*
|
|
27
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
28
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
29
|
+
* - Raw tools never appear in the returned table. The host may still hold a raw
|
|
30
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
31
|
+
*
|
|
32
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → LangGraph-ready descriptors.
|
|
33
|
+
* Mirrors src/adapters/openai.ts and anthropic.ts — only the target tool shape differs.
|
|
34
|
+
*/
|
|
35
|
+
import type { WithCodeRiftsInput, WithCodeRiftsResult, CompositionAssurance, ReceiptThreadHandle } from '../with-coderifts.js';
|
|
36
|
+
import type { ProtectedTool, RegistryCoverageReport } from '../tool-registry.js';
|
|
37
|
+
/**
|
|
38
|
+
* Framework-agnostic LangChain/LangGraph tool descriptor (no package import).
|
|
39
|
+
*
|
|
40
|
+
* Host wiring (illustrative — host supplies the framework packages, e.g.
|
|
41
|
+
* @langchain/core tools + @langchain/langgraph ToolNode):
|
|
42
|
+
* const lcTools = tools.map((d) =>
|
|
43
|
+
* hostTool(d.func, { name: d.name, description: d.description, schema: d.schema }));
|
|
44
|
+
* // then hostToolNode(lcTools) / hostLlm.bindTools(lcTools)
|
|
45
|
+
*/
|
|
46
|
+
export type LangGraphToolDescriptor = {
|
|
47
|
+
name: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
/** JSON Schema for tool args (LangChain `schema` / StructuredTool args). */
|
|
50
|
+
schema: Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Guarded execute — same as ProtectedTool.execute.
|
|
53
|
+
* Pass to LangChain `tool(func, …)` or StructuredTool-style runners.
|
|
54
|
+
*/
|
|
55
|
+
func: (args: unknown) => Promise<unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Alias of `func` for invoke-style APIs (StructuredTool.invoke / ToolNode).
|
|
58
|
+
* Same guarded execute reference as `func`.
|
|
59
|
+
*/
|
|
60
|
+
invoke: (args: unknown) => Promise<unknown>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Result of withCodeRiftsLangGraph — descriptors + core assurance, unflattened.
|
|
64
|
+
*
|
|
65
|
+
* `tools` is the ONLY list intended for the model/runtime tool table. `protected_tools` is the
|
|
66
|
+
* same guarded list for host inspection — never the raw tools.
|
|
67
|
+
*/
|
|
68
|
+
export type WithCodeRiftsLangGraphResult = {
|
|
69
|
+
/** LangGraph/LangChain-compatible descriptors — only protected/guarded tools. */
|
|
70
|
+
tools: LangGraphToolDescriptor[];
|
|
71
|
+
/**
|
|
72
|
+
* Guarded ProtectedTool list from withCodeRifts (same tools as `tools`).
|
|
73
|
+
* Host may use these for dispatch; never raw tools.
|
|
74
|
+
*/
|
|
75
|
+
protected_tools: ProtectedTool[];
|
|
76
|
+
/** Untouched registry report — registry's own truth. */
|
|
77
|
+
registry_report: RegistryCoverageReport;
|
|
78
|
+
/**
|
|
79
|
+
* Product-level assurance — deliberately narrower than the registry.
|
|
80
|
+
* Passed through untouched; may still show inescapable_runtime:false and
|
|
81
|
+
* residual composition_call_policy_incomplete.
|
|
82
|
+
*/
|
|
83
|
+
composition_assurance: CompositionAssurance;
|
|
84
|
+
/** Per-composition receipt cursor — NOT product-truth chain evidence. */
|
|
85
|
+
receipt_thread: ReceiptThreadHandle;
|
|
86
|
+
repository?: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Map one ProtectedTool → LangGraph/LangChain tool descriptor.
|
|
90
|
+
* Binds guarded execute to both `func` and `invoke` (same reference).
|
|
91
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
92
|
+
*/
|
|
93
|
+
export declare function protectedToolToLangGraph(tool: ProtectedTool): LangGraphToolDescriptor;
|
|
94
|
+
/**
|
|
95
|
+
* Convert a list of ProtectedTool into LangGraph/LangChain descriptors.
|
|
96
|
+
* Does NOT call the guard — pure map over an already-protected list.
|
|
97
|
+
*/
|
|
98
|
+
export declare function toLangGraphTools(protectedTools: readonly ProtectedTool[]): LangGraphToolDescriptor[];
|
|
99
|
+
/**
|
|
100
|
+
* Build LangGraph/LangChain-ready guarded tool descriptors from raw tools + client + operation.
|
|
101
|
+
*
|
|
102
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
103
|
+
* - `tools` — plain descriptors { name, description?, schema, func, invoke }
|
|
104
|
+
* - `protected_tools` — same guarded tools
|
|
105
|
+
* - assurance objects from the core, passed through untouched
|
|
106
|
+
*
|
|
107
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
108
|
+
*/
|
|
109
|
+
export declare function withCodeRiftsLangGraph(input: WithCodeRiftsInput): WithCodeRiftsLangGraphResult;
|
|
110
|
+
/**
|
|
111
|
+
* Shape adapter over an existing WithCodeRiftsResult (composition style).
|
|
112
|
+
* Prefer withCodeRiftsLangGraph when starting from raw tools.
|
|
113
|
+
*
|
|
114
|
+
* Does not re-run the guard; does not invent assurance.
|
|
115
|
+
*/
|
|
116
|
+
export declare function langGraphToolAdapter(result: WithCodeRiftsResult): WithCodeRiftsLangGraphResult;
|
|
117
|
+
//# sourceMappingURL=langgraph.d.ts.map
|
|
@@ -0,0 +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;AAEjF;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC;;;OAGG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C;;;OAGG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,iFAAiF;IACjF,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC;;;OAGG;IACH,eAAe,EAAE,aAAa,EAAE,CAAC;IACjC,wDAAwD;IACxD,eAAe,EAAE,sBAAsB,CAAC;IACxC;;;;OAIG;IACH,qBAAqB,EAAE,oBAAoB,CAAC;IAC5C,yEAAyE;IACzE,cAAc,EAAE,mBAAmB,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,uBAAuB,CAqBrF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,uBAAuB,EAAE,CAEpG;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,CAG9F;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,4BAA4B,CAc9F"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangChain / LangGraph tool adapter over withCodeRifts (ID632 slice 3 — same thin
|
|
3
|
+
* pattern as OpenAI / Anthropic).
|
|
4
|
+
*
|
|
5
|
+
* Thin converter only. Guard logic stays in withCodeRifts; this module:
|
|
6
|
+
* 1. calls withCodeRifts with the same input shape,
|
|
7
|
+
* 2. maps each ProtectedTool → a framework-agnostic tool descriptor that
|
|
8
|
+
* LangChain's tool()/StructuredTool and LangGraph's ToolNode can accept,
|
|
9
|
+
* 3. returns those descriptors PLUS the untouched assurance objects
|
|
10
|
+
* (registry_report, composition_assurance, receipt_thread).
|
|
11
|
+
*
|
|
12
|
+
* NO hard dependency on langchain / @langchain/* / langgraph packages. The host
|
|
13
|
+
* owns the framework import and wires descriptors into tool() / ToolNode /
|
|
14
|
+
* bind_tools / StateGraph themselves.
|
|
15
|
+
*
|
|
16
|
+
* Descriptor shape (dependency-free plain object):
|
|
17
|
+
* { name, description?, schema, func, invoke }
|
|
18
|
+
* - schema = JSON Schema from ProtectedTool.inputSchema (or empty object schema)
|
|
19
|
+
* - func / invoke = the GUARDED execute (same function reference) — never the raw tool
|
|
20
|
+
*
|
|
21
|
+
* Honesty (do not "upgrade" assurance):
|
|
22
|
+
* - composition_assurance is passed through EXACTLY as the core reported it
|
|
23
|
+
* (COMPOSITION_CALL_POLICY_COMPLETE may still be false; inescapable_runtime may be false).
|
|
24
|
+
* - The adapter converts tool shape + binds guarded execute; it does not claim product-level
|
|
25
|
+
* inescapability the core does not claim.
|
|
26
|
+
*
|
|
27
|
+
* Only-protected-tools (6/D at the adapter surface):
|
|
28
|
+
* - `tools` is derived ONLY from the frozen registry's ProtectedTool list.
|
|
29
|
+
* - Raw tools never appear in the returned table. The host may still hold a raw
|
|
30
|
+
* reference outside this table; that boundary stays the host's responsibility.
|
|
31
|
+
*
|
|
32
|
+
* Ergonomics (5–10 lines): pass raw tools + client + operation → LangGraph-ready descriptors.
|
|
33
|
+
* Mirrors src/adapters/openai.ts and anthropic.ts — only the target tool shape differs.
|
|
34
|
+
*/
|
|
35
|
+
import { withCodeRifts } from '../with-coderifts.js';
|
|
36
|
+
/** Empty JSON Schema object — used when a ProtectedTool has no inputSchema. */
|
|
37
|
+
const EMPTY_SCHEMA = Object.freeze({
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {},
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Map one ProtectedTool → LangGraph/LangChain tool descriptor.
|
|
43
|
+
* Binds guarded execute to both `func` and `invoke` (same reference).
|
|
44
|
+
* Prefer tool.inputSchema when it is a plain object; otherwise empty object schema.
|
|
45
|
+
*/
|
|
46
|
+
export function protectedToolToLangGraph(tool) {
|
|
47
|
+
const schema = tool.inputSchema != null
|
|
48
|
+
&& typeof tool.inputSchema === 'object'
|
|
49
|
+
&& !Array.isArray(tool.inputSchema)
|
|
50
|
+
? tool.inputSchema
|
|
51
|
+
: { ...EMPTY_SCHEMA };
|
|
52
|
+
// Guarded execute only — never a raw unwrapped executor.
|
|
53
|
+
const guarded = (args) => Promise.resolve(tool.execute(args));
|
|
54
|
+
const out = {
|
|
55
|
+
name: tool.name,
|
|
56
|
+
schema,
|
|
57
|
+
func: guarded,
|
|
58
|
+
invoke: guarded,
|
|
59
|
+
};
|
|
60
|
+
if (tool.description != null && tool.description !== '') {
|
|
61
|
+
out.description = tool.description;
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Convert a list of ProtectedTool into LangGraph/LangChain descriptors.
|
|
67
|
+
* Does NOT call the guard — pure map over an already-protected list.
|
|
68
|
+
*/
|
|
69
|
+
export function toLangGraphTools(protectedTools) {
|
|
70
|
+
return protectedTools.map(protectedToolToLangGraph);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build LangGraph/LangChain-ready guarded tool descriptors from raw tools + client + operation.
|
|
74
|
+
*
|
|
75
|
+
* Calls withCodeRifts internally (guard logic stays in the core). Returns:
|
|
76
|
+
* - `tools` — plain descriptors { name, description?, schema, func, invoke }
|
|
77
|
+
* - `protected_tools` — same guarded tools
|
|
78
|
+
* - assurance objects from the core, passed through untouched
|
|
79
|
+
*
|
|
80
|
+
* @param input Same shape as withCodeRifts (WithCodeRiftsInput).
|
|
81
|
+
*/
|
|
82
|
+
export function withCodeRiftsLangGraph(input) {
|
|
83
|
+
const core = withCodeRifts(input);
|
|
84
|
+
return langGraphToolAdapter(core);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Shape adapter over an existing WithCodeRiftsResult (composition style).
|
|
88
|
+
* Prefer withCodeRiftsLangGraph when starting from raw tools.
|
|
89
|
+
*
|
|
90
|
+
* Does not re-run the guard; does not invent assurance.
|
|
91
|
+
*/
|
|
92
|
+
export function langGraphToolAdapter(result) {
|
|
93
|
+
const protected_tools = result.tools;
|
|
94
|
+
const tools = toLangGraphTools(protected_tools);
|
|
95
|
+
const out = {
|
|
96
|
+
tools,
|
|
97
|
+
protected_tools,
|
|
98
|
+
registry_report: result.registry_report,
|
|
99
|
+
composition_assurance: result.composition_assurance,
|
|
100
|
+
receipt_thread: result.receipt_thread,
|
|
101
|
+
};
|
|
102
|
+
if (result.repository !== undefined) {
|
|
103
|
+
out.repository = result.repository;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=langgraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph.js","sourceRoot":"","sources":["../../../src/adapters/langgraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AA8DrD,+EAA+E;AAC/E,MAAM,YAAY,GAA4B,MAAM,CAAC,MAAM,CAAC;IAC1D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAmB;IAC1D,MAAM,MAAM,GACV,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,YAAY,EAAE,CAAC;IAE1B,yDAAyD;IACzD,MAAM,OAAO,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvE,MAAM,GAAG,GAA4B;QACnC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM;QACN,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,OAAO;KAChB,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,MAAM,UAAU,gBAAgB,CAAC,cAAwC;IACvE,OAAO,cAAc,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAyB;IAC9D,MAAM,IAAI,GAAwB,aAAa,CAAC,KAAK,CAAC,CAAC;IACvD,OAAO,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAA2B;IAC9D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,GAAG,GAAiC;QACxC,KAAK;QACL,eAAe;QACf,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;QACnD,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;IACF,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACpC,GAAG,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|