@atbash/atbash-langgraph 0.0.5-dev.2 → 0.0.5-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -5
- package/dist/index.js +18 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _langchain_core_messages from '@langchain/core/messages';
|
|
2
2
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
3
3
|
import { StateGraph } from '@langchain/langgraph';
|
|
4
|
-
import { Atbash
|
|
4
|
+
import { Atbash } from '@atbash/sdk';
|
|
5
5
|
import * as _langchain_core_tools from '@langchain/core/tools';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
|
|
@@ -20,13 +20,11 @@ interface GuardNodeOptions {
|
|
|
20
20
|
declare function createGuardNode(opts: GuardNodeOptions): (state: AtbashState) => Promise<Partial<AtbashState>>;
|
|
21
21
|
|
|
22
22
|
interface AuditNodeOptions {
|
|
23
|
-
|
|
24
|
-
clientOpts?: AtbashOptions;
|
|
23
|
+
client: Atbash;
|
|
25
24
|
}
|
|
26
25
|
declare function createAuditNode(opts: AuditNodeOptions): (state: AtbashState) => Promise<Partial<AtbashState>>;
|
|
27
26
|
|
|
28
27
|
interface AtbashSafetyOptions {
|
|
29
|
-
agent?: AgentAuth;
|
|
30
28
|
privkey?: string;
|
|
31
29
|
endpoint?: string;
|
|
32
30
|
toolsNode?: string;
|
|
@@ -52,7 +50,7 @@ declare function addAtbashSafety(builder: StateGraph<AtbashState>, opts: AtbashS
|
|
|
52
50
|
messages: _langchain_langgraph.BaseChannel<_langchain_core_messages.BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[], _langchain_langgraph.OverwriteValue<_langchain_core_messages.BaseMessage<_langchain_core_messages.MessageStructure<_langchain_core_messages.MessageToolSet>, _langchain_core_messages.MessageType>[]> | _langchain_langgraph.Messages, unknown>;
|
|
53
51
|
}>>, "__start__", _langchain_langgraph.StateDefinition, _langchain_langgraph.StateDefinition, _langchain_langgraph.StateDefinition, unknown, unknown, unknown>;
|
|
54
52
|
|
|
55
|
-
declare function createJudgeTool(
|
|
53
|
+
declare function createJudgeTool(client: Atbash): _langchain_core_tools.DynamicStructuredTool<z.ZodObject<{
|
|
56
54
|
action: z.ZodString;
|
|
57
55
|
context: z.ZodString;
|
|
58
56
|
}, "strip", z.ZodTypeAny, {
|
package/dist/index.js
CHANGED
|
@@ -101,9 +101,6 @@ function createGuardNode(opts) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
// src/nodes/auditNode.ts
|
|
105
|
-
import { Atbash } from "@atbash/sdk";
|
|
106
|
-
|
|
107
104
|
// src/utils.ts
|
|
108
105
|
function truncateText(value, max = 500) {
|
|
109
106
|
return value.length <= max ? value : `${value.slice(0, max - 3)}...`;
|
|
@@ -111,12 +108,12 @@ function truncateText(value, max = 500) {
|
|
|
111
108
|
|
|
112
109
|
// src/nodes/auditNode.ts
|
|
113
110
|
function createAuditNode(opts) {
|
|
111
|
+
const { client } = opts;
|
|
114
112
|
return async (state) => {
|
|
115
113
|
const lastMessage = state.messages[state.messages.length - 1];
|
|
116
114
|
const content = typeof lastMessage?.content === "string" ? lastMessage.content : JSON.stringify(lastMessage?.content ?? "");
|
|
117
115
|
try {
|
|
118
|
-
|
|
119
|
-
await client.judgeAction(
|
|
116
|
+
await client.logToolCall(
|
|
120
117
|
truncateText(content, 500),
|
|
121
118
|
"LangGraph tool execution completed"
|
|
122
119
|
);
|
|
@@ -128,8 +125,7 @@ function createAuditNode(opts) {
|
|
|
128
125
|
|
|
129
126
|
// src/builder.ts
|
|
130
127
|
import {
|
|
131
|
-
Atbash
|
|
132
|
-
loadAgent,
|
|
128
|
+
Atbash,
|
|
133
129
|
setupTelemetry,
|
|
134
130
|
shutdownTelemetry
|
|
135
131
|
} from "@atbash/sdk";
|
|
@@ -138,15 +134,15 @@ function addAtbashSafety(builder, opts) {
|
|
|
138
134
|
process.once("beforeExit", () => shutdownTelemetry());
|
|
139
135
|
process.once("SIGINT", () => shutdownTelemetry().finally(() => process.exit(0)));
|
|
140
136
|
process.once("SIGTERM", () => shutdownTelemetry().finally(() => process.exit(0)));
|
|
141
|
-
const privkey = opts.privkey ?? process.env.ATBASH_AGENT_PRIVKEY;
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
const client = new
|
|
137
|
+
const privkey = opts.privkey ?? process.env.ATBASH_AGENT_PRIVKEY ?? "";
|
|
138
|
+
const clientOpts = {};
|
|
139
|
+
if (opts.endpoint) clientOpts.endpoint = opts.endpoint;
|
|
140
|
+
const client = new Atbash(privkey, clientOpts);
|
|
145
141
|
const graph = builder;
|
|
146
142
|
const toolsNode = opts.toolsNode ?? "tools";
|
|
147
143
|
const agentNode = opts.agentNode ?? "agent";
|
|
148
144
|
graph.addNode("atbash_guard", createGuardNode({ client }));
|
|
149
|
-
graph.addNode("atbash_audit", createAuditNode({
|
|
145
|
+
graph.addNode("atbash_audit", createAuditNode({ client }));
|
|
150
146
|
graph.addConditionalEdges("atbash_guard", (state) => {
|
|
151
147
|
return state.atbashVerdict === "ALLOW" ? toolsNode : agentNode;
|
|
152
148
|
});
|
|
@@ -156,19 +152,21 @@ function addAtbashSafety(builder, opts) {
|
|
|
156
152
|
}
|
|
157
153
|
|
|
158
154
|
// src/tools/judgeTool.ts
|
|
159
|
-
import { Atbash as Atbash3 } from "@atbash/sdk";
|
|
160
155
|
import { tool } from "@langchain/core/tools";
|
|
161
156
|
import { z } from "zod";
|
|
162
|
-
function createJudgeTool(
|
|
157
|
+
function createJudgeTool(client) {
|
|
163
158
|
return tool(
|
|
164
159
|
async ({ action, context }) => {
|
|
165
|
-
const
|
|
166
|
-
|
|
160
|
+
const decision = await client.auditToolCall({
|
|
161
|
+
toolName: "atbash_safety_check",
|
|
162
|
+
args: { action },
|
|
163
|
+
context
|
|
164
|
+
});
|
|
167
165
|
return JSON.stringify({
|
|
168
|
-
verdict:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
tool_call_id:
|
|
166
|
+
verdict: decision.verdict,
|
|
167
|
+
allow: decision.allow,
|
|
168
|
+
reason: decision.reason,
|
|
169
|
+
tool_call_id: decision.toolCallId
|
|
172
170
|
});
|
|
173
171
|
},
|
|
174
172
|
{
|