agentid-sdk 0.1.17 → 0.1.18
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/chunk-6YR4ECGB.mjs +424 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +206 -49
- package/dist/index.mjs +24 -25
- package/dist/{langchain-CWHTxef0.d.mts → langchain-BykeB2WB.d.mts} +8 -5
- package/dist/{langchain-CWHTxef0.d.ts → langchain-BykeB2WB.d.ts} +8 -5
- package/dist/langchain.d.mts +2 -1
- package/dist/langchain.d.ts +2 -1
- package/dist/langchain.js +183 -25
- package/dist/langchain.mjs +1 -1
- package/package.json +6 -2
- package/dist/chunk-DXUA5DKG.mjs +0 -266
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
// src/langchain.ts
|
|
2
|
+
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
3
|
+
function safeString(val) {
|
|
4
|
+
return typeof val === "string" ? val : "";
|
|
5
|
+
}
|
|
6
|
+
function callbackDebugEnabled() {
|
|
7
|
+
try {
|
|
8
|
+
return typeof process !== "undefined" && process?.env?.AGENTID_DEBUG_CALLBACK === "1";
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function logCallbackDebug(message, details) {
|
|
14
|
+
if (!callbackDebugEnabled()) return;
|
|
15
|
+
if (details) {
|
|
16
|
+
console.log(`[AgentID][LC] ${message}`, details);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
console.log(`[AgentID][LC] ${message}`);
|
|
20
|
+
}
|
|
21
|
+
function extractTextFromContent(content) {
|
|
22
|
+
if (typeof content === "string") {
|
|
23
|
+
return content;
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(content)) {
|
|
26
|
+
const parts = content.map((item) => {
|
|
27
|
+
if (typeof item === "string") return item;
|
|
28
|
+
if (!item || typeof item !== "object") return "";
|
|
29
|
+
const record = item;
|
|
30
|
+
if (typeof record.text === "string") return record.text;
|
|
31
|
+
if (typeof record.content === "string") return record.content;
|
|
32
|
+
return "";
|
|
33
|
+
}).filter((part) => part.length > 0);
|
|
34
|
+
return parts.join("\n");
|
|
35
|
+
}
|
|
36
|
+
if (content && typeof content === "object") {
|
|
37
|
+
const record = content;
|
|
38
|
+
if (typeof record.text === "string") return record.text;
|
|
39
|
+
if (typeof record.content === "string") return record.content;
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
function getMessageRole(msg) {
|
|
44
|
+
if (!msg || typeof msg !== "object") return null;
|
|
45
|
+
const typed = msg;
|
|
46
|
+
if (typeof typed.role === "string") return typed.role;
|
|
47
|
+
if (typeof typed.type === "string") return typed.type;
|
|
48
|
+
if (typeof typed._getType === "function") {
|
|
49
|
+
try {
|
|
50
|
+
const role = typed._getType();
|
|
51
|
+
if (typeof role === "string") return role;
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (typeof typed.getType === "function") {
|
|
56
|
+
try {
|
|
57
|
+
const role = typed.getType();
|
|
58
|
+
if (typeof role === "string") return role;
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function extractPromptFromPrompts(prompts) {
|
|
65
|
+
if (Array.isArray(prompts) && prompts.length > 0) {
|
|
66
|
+
return safeString(prompts[prompts.length - 1]);
|
|
67
|
+
}
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
70
|
+
function extractPromptFromMessages(messages) {
|
|
71
|
+
const flat = [];
|
|
72
|
+
if (Array.isArray(messages)) {
|
|
73
|
+
for (const item of messages) {
|
|
74
|
+
if (Array.isArray(item)) {
|
|
75
|
+
flat.push(...item);
|
|
76
|
+
} else {
|
|
77
|
+
flat.push(item);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let last = null;
|
|
82
|
+
for (const msg of flat) {
|
|
83
|
+
const typed = msg;
|
|
84
|
+
const role = getMessageRole(msg);
|
|
85
|
+
if (role === "user" || role === "human") {
|
|
86
|
+
last = typed;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!last || typeof last !== "object") {
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
const typedLast = last;
|
|
93
|
+
return extractTextFromContent(typedLast.content ?? typedLast.text);
|
|
94
|
+
}
|
|
95
|
+
function setPromptInPrompts(prompts, sanitizedInput) {
|
|
96
|
+
if (!Array.isArray(prompts) || prompts.length === 0) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
prompts[prompts.length - 1] = sanitizedInput;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
function setPromptInMessages(messages, sanitizedInput) {
|
|
103
|
+
if (!Array.isArray(messages)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const flat = [];
|
|
107
|
+
for (const item of messages) {
|
|
108
|
+
if (Array.isArray(item)) {
|
|
109
|
+
flat.push(...item);
|
|
110
|
+
} else {
|
|
111
|
+
flat.push(item);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (let i = flat.length - 1; i >= 0; i -= 1) {
|
|
115
|
+
const candidate = flat[i];
|
|
116
|
+
if (!candidate || typeof candidate !== "object") {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const typed = candidate;
|
|
120
|
+
const role = typed.role ?? typed.type;
|
|
121
|
+
if (role !== "user" && role !== "human") {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if ("content" in typed) {
|
|
125
|
+
typed.content = sanitizedInput;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if ("text" in typed) {
|
|
129
|
+
typed.text = sanitizedInput;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
typed.content = sanitizedInput;
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
function extractModel(serialized, kwargs) {
|
|
138
|
+
const kw = (kwargs && typeof kwargs === "object" ? kwargs : null) ?? null;
|
|
139
|
+
const directModel = kw?.model ?? kw?.model_name ?? kw?.modelName;
|
|
140
|
+
if (typeof directModel === "string" && directModel) return directModel;
|
|
141
|
+
const invocationModel = kw?.invocation_params?.model ?? kw?.invocation_params?.model_name ?? kw?.invocation_params?.modelName;
|
|
142
|
+
if (typeof invocationModel === "string" && invocationModel) return invocationModel;
|
|
143
|
+
const nestedModel = kw?.options?.model ?? kw?.options?.model_name ?? kw?.options?.modelName ?? kw?.kwargs?.model ?? kw?.kwargs?.model_name ?? kw?.kwargs?.modelName;
|
|
144
|
+
if (typeof nestedModel === "string" && nestedModel) return nestedModel;
|
|
145
|
+
const ser = (serialized && typeof serialized === "object" ? serialized : null) ?? null;
|
|
146
|
+
const serKw = (ser?.kwargs && typeof ser.kwargs === "object" ? ser.kwargs : null) ?? null;
|
|
147
|
+
const serModel = serKw?.model ?? serKw?.model_name ?? serKw?.modelName;
|
|
148
|
+
if (typeof serModel === "string" && serModel) return serModel;
|
|
149
|
+
const name = ser?.name ?? ser?.id;
|
|
150
|
+
if (typeof name === "string" && name) return name;
|
|
151
|
+
return void 0;
|
|
152
|
+
}
|
|
153
|
+
function extractModelFromOutput(output) {
|
|
154
|
+
const llmOutput = output?.llmOutput ?? output?.llm_output;
|
|
155
|
+
const llmModel = llmOutput?.model ?? llmOutput?.model_name ?? llmOutput?.modelName;
|
|
156
|
+
if (typeof llmModel === "string" && llmModel) return llmModel;
|
|
157
|
+
const first = output?.generations?.[0]?.[0];
|
|
158
|
+
const responseMeta = first?.message?.response_metadata ?? first?.message?.responseMetadata;
|
|
159
|
+
const responseModel = responseMeta?.model_name ?? responseMeta?.model ?? responseMeta?.modelName;
|
|
160
|
+
if (typeof responseModel === "string" && responseModel) return responseModel;
|
|
161
|
+
const generationInfo = first?.generation_info ?? first?.generationInfo;
|
|
162
|
+
const genModel = generationInfo?.model_name ?? generationInfo?.model ?? generationInfo?.modelName;
|
|
163
|
+
if (typeof genModel === "string" && genModel) return genModel;
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
function extractOutputText(output) {
|
|
167
|
+
const gens = output?.generations;
|
|
168
|
+
const first = gens?.[0]?.[0];
|
|
169
|
+
const text = first?.text ?? first?.message?.content;
|
|
170
|
+
return typeof text === "string" ? text : "";
|
|
171
|
+
}
|
|
172
|
+
function extractTokenUsage(output) {
|
|
173
|
+
const llmOutput = output?.llmOutput ?? output?.llm_output;
|
|
174
|
+
const usage = llmOutput?.tokenUsage ?? llmOutput?.token_usage ?? llmOutput?.usage ?? void 0;
|
|
175
|
+
if (usage && typeof usage === "object") {
|
|
176
|
+
return usage;
|
|
177
|
+
}
|
|
178
|
+
const first = output?.generations?.[0]?.[0];
|
|
179
|
+
const usageMetadata = first?.message?.usage_metadata;
|
|
180
|
+
if (usageMetadata && typeof usageMetadata === "object") {
|
|
181
|
+
return usageMetadata;
|
|
182
|
+
}
|
|
183
|
+
const responseTokenUsage = first?.message?.response_metadata?.token_usage ?? first?.message?.response_metadata?.tokenUsage ?? void 0;
|
|
184
|
+
if (responseTokenUsage && typeof responseTokenUsage === "object") {
|
|
185
|
+
return responseTokenUsage;
|
|
186
|
+
}
|
|
187
|
+
const generationTokenUsage = first?.generation_info?.token_usage ?? first?.generation_info?.tokenUsage ?? void 0;
|
|
188
|
+
if (generationTokenUsage && typeof generationTokenUsage === "object") {
|
|
189
|
+
return generationTokenUsage;
|
|
190
|
+
}
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
function isUuidLike(value) {
|
|
194
|
+
return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value.trim());
|
|
195
|
+
}
|
|
196
|
+
function createClientEventId() {
|
|
197
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
198
|
+
return crypto.randomUUID();
|
|
199
|
+
}
|
|
200
|
+
const segment = () => Math.floor((1 + Math.random()) * 65536).toString(16).slice(1);
|
|
201
|
+
return `${segment()}${segment()}-${segment()}-4${segment().slice(1)}-a${segment().slice(1)}-${segment()}${segment()}${segment()}`;
|
|
202
|
+
}
|
|
203
|
+
function readBooleanField(value) {
|
|
204
|
+
return typeof value === "boolean" ? value : null;
|
|
205
|
+
}
|
|
206
|
+
function extractStreamFlag(serialized, extraParams) {
|
|
207
|
+
const extras = extraParams && typeof extraParams === "object" ? extraParams : null;
|
|
208
|
+
const direct = readBooleanField(extras?.stream) ?? readBooleanField(extras?.streaming);
|
|
209
|
+
if (direct !== null) {
|
|
210
|
+
return direct;
|
|
211
|
+
}
|
|
212
|
+
const invocation = extras?.invocation_params && typeof extras.invocation_params === "object" ? extras.invocation_params : null;
|
|
213
|
+
const invocationStream = readBooleanField(invocation?.stream) ?? readBooleanField(invocation?.streaming);
|
|
214
|
+
if (invocationStream !== null) {
|
|
215
|
+
return invocationStream;
|
|
216
|
+
}
|
|
217
|
+
const serializedRecord = serialized && typeof serialized === "object" ? serialized : null;
|
|
218
|
+
const kwargs = serializedRecord?.kwargs && typeof serializedRecord.kwargs === "object" ? serializedRecord.kwargs : null;
|
|
219
|
+
return readBooleanField(kwargs?.stream) ?? readBooleanField(kwargs?.streaming) ?? false;
|
|
220
|
+
}
|
|
221
|
+
var AgentIDCallbackHandler = class extends BaseCallbackHandler {
|
|
222
|
+
constructor(agent, options) {
|
|
223
|
+
super();
|
|
224
|
+
this.name = "agentid_callback_handler";
|
|
225
|
+
this.runs = /* @__PURE__ */ new Map();
|
|
226
|
+
this.agent = agent;
|
|
227
|
+
this.systemId = options.system_id;
|
|
228
|
+
this.apiKeyOverride = options.apiKey?.trim() || options.api_key?.trim() || void 0;
|
|
229
|
+
}
|
|
230
|
+
get requestOptions() {
|
|
231
|
+
return this.apiKeyOverride ? { apiKey: this.apiKeyOverride } : void 0;
|
|
232
|
+
}
|
|
233
|
+
getLangchainCapabilities() {
|
|
234
|
+
const piiMaskingEnabled = Boolean(
|
|
235
|
+
this.agent.piiMasking
|
|
236
|
+
);
|
|
237
|
+
return {
|
|
238
|
+
capabilities: {
|
|
239
|
+
has_feedback_handler: true,
|
|
240
|
+
pii_masking_enabled: piiMaskingEnabled,
|
|
241
|
+
framework: "langchain"
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
async preflight(input, stream) {
|
|
246
|
+
await this.agent.scanPromptInjection(input, this.requestOptions);
|
|
247
|
+
const prepared = await this.agent.prepareInputForDispatch({
|
|
248
|
+
input,
|
|
249
|
+
systemId: this.systemId,
|
|
250
|
+
stream,
|
|
251
|
+
skipInjectionScan: true
|
|
252
|
+
}, this.requestOptions);
|
|
253
|
+
return prepared.sanitizedInput;
|
|
254
|
+
}
|
|
255
|
+
async handleLLMStart(serialized, prompts, runId, _parentRunId, extraParams) {
|
|
256
|
+
const input = extractPromptFromPrompts(prompts);
|
|
257
|
+
const id = String(runId ?? "");
|
|
258
|
+
logCallbackDebug("handleLLMStart", { runId: id, hasInput: input.length > 0 });
|
|
259
|
+
if (!input) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const stream = extractStreamFlag(serialized, extraParams);
|
|
263
|
+
const sanitizedInput = await this.preflight(input, stream);
|
|
264
|
+
if (sanitizedInput !== input) {
|
|
265
|
+
const mutated = setPromptInPrompts(prompts, sanitizedInput);
|
|
266
|
+
if (!mutated) {
|
|
267
|
+
throw new Error(
|
|
268
|
+
"AgentID: Strict PII mode requires mutable LangChain prompt payload."
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const requestedClientEventId = isUuidLike(id) ? id.trim() : createClientEventId();
|
|
273
|
+
const modelName = extractModel(serialized, extraParams);
|
|
274
|
+
const verdict = await this.agent.guard({
|
|
275
|
+
input: sanitizedInput,
|
|
276
|
+
system_id: this.systemId,
|
|
277
|
+
model: modelName,
|
|
278
|
+
client_event_id: requestedClientEventId,
|
|
279
|
+
client_capabilities: this.getLangchainCapabilities()
|
|
280
|
+
}, this.requestOptions);
|
|
281
|
+
if (!verdict.allowed) {
|
|
282
|
+
throw new Error(`AgentID: Security Blocked (${verdict.reason ?? "guard_denied"})`);
|
|
283
|
+
}
|
|
284
|
+
const canonicalClientEventId = isUuidLike(verdict.client_event_id) ? verdict.client_event_id.trim() : requestedClientEventId;
|
|
285
|
+
const guardEventId = typeof verdict.guard_event_id === "string" && verdict.guard_event_id.length > 0 ? verdict.guard_event_id : void 0;
|
|
286
|
+
let transformedInput = typeof verdict.transformed_input === "string" && verdict.transformed_input.length > 0 ? verdict.transformed_input : sanitizedInput;
|
|
287
|
+
if (transformedInput !== sanitizedInput) {
|
|
288
|
+
const mutated = setPromptInPrompts(prompts, transformedInput);
|
|
289
|
+
if (!mutated) {
|
|
290
|
+
transformedInput = sanitizedInput;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
this.runs.set(id, {
|
|
294
|
+
input: transformedInput,
|
|
295
|
+
startedAtMs: Date.now(),
|
|
296
|
+
model: modelName,
|
|
297
|
+
clientEventId: canonicalClientEventId,
|
|
298
|
+
guardEventId
|
|
299
|
+
});
|
|
300
|
+
logCallbackDebug("handleLLMStart state_set", {
|
|
301
|
+
runId: id,
|
|
302
|
+
clientEventId: canonicalClientEventId,
|
|
303
|
+
guardEventId: guardEventId ?? null
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async handleChatModelStart(serialized, messages, runId, _parentRunId, extraParams) {
|
|
307
|
+
const input = extractPromptFromMessages(messages);
|
|
308
|
+
const id = String(runId ?? "");
|
|
309
|
+
logCallbackDebug("handleChatModelStart", { runId: id, hasInput: input.length > 0 });
|
|
310
|
+
if (!input) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const stream = extractStreamFlag(serialized, extraParams);
|
|
314
|
+
const sanitizedInput = await this.preflight(input, stream);
|
|
315
|
+
if (sanitizedInput !== input) {
|
|
316
|
+
const mutated = setPromptInMessages(messages, sanitizedInput);
|
|
317
|
+
if (!mutated) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
"AgentID: Strict PII mode requires mutable LangChain message payload."
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const requestedClientEventId = isUuidLike(id) ? id.trim() : createClientEventId();
|
|
324
|
+
const modelName = extractModel(serialized, extraParams);
|
|
325
|
+
const verdict = await this.agent.guard({
|
|
326
|
+
input: sanitizedInput,
|
|
327
|
+
system_id: this.systemId,
|
|
328
|
+
model: modelName,
|
|
329
|
+
client_event_id: requestedClientEventId,
|
|
330
|
+
client_capabilities: this.getLangchainCapabilities()
|
|
331
|
+
}, this.requestOptions);
|
|
332
|
+
if (!verdict.allowed) {
|
|
333
|
+
throw new Error(`AgentID: Security Blocked (${verdict.reason ?? "guard_denied"})`);
|
|
334
|
+
}
|
|
335
|
+
const canonicalClientEventId = isUuidLike(verdict.client_event_id) ? verdict.client_event_id.trim() : requestedClientEventId;
|
|
336
|
+
const guardEventId = typeof verdict.guard_event_id === "string" && verdict.guard_event_id.length > 0 ? verdict.guard_event_id : void 0;
|
|
337
|
+
let transformedInput = typeof verdict.transformed_input === "string" && verdict.transformed_input.length > 0 ? verdict.transformed_input : sanitizedInput;
|
|
338
|
+
if (transformedInput !== sanitizedInput) {
|
|
339
|
+
const mutated = setPromptInMessages(messages, transformedInput);
|
|
340
|
+
if (!mutated) {
|
|
341
|
+
transformedInput = sanitizedInput;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
this.runs.set(id, {
|
|
345
|
+
input: transformedInput,
|
|
346
|
+
startedAtMs: Date.now(),
|
|
347
|
+
model: modelName,
|
|
348
|
+
clientEventId: canonicalClientEventId,
|
|
349
|
+
guardEventId
|
|
350
|
+
});
|
|
351
|
+
logCallbackDebug("handleChatModelStart state_set", {
|
|
352
|
+
runId: id,
|
|
353
|
+
clientEventId: canonicalClientEventId,
|
|
354
|
+
guardEventId: guardEventId ?? null
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async handleLLMEnd(output, runId) {
|
|
358
|
+
const id = String(runId ?? "");
|
|
359
|
+
logCallbackDebug("handleLLMEnd", { runId: id });
|
|
360
|
+
const state = this.runs.get(id);
|
|
361
|
+
if (!state) {
|
|
362
|
+
logCallbackDebug("handleLLMEnd missing_state", { runId: id });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
this.runs.delete(id);
|
|
366
|
+
const latency = Date.now() - state.startedAtMs;
|
|
367
|
+
const outText = extractOutputText(output);
|
|
368
|
+
const usage = extractTokenUsage(output);
|
|
369
|
+
const metadata = {};
|
|
370
|
+
if (state.clientEventId) {
|
|
371
|
+
metadata.client_event_id = state.clientEventId;
|
|
372
|
+
}
|
|
373
|
+
if (state.guardEventId) {
|
|
374
|
+
metadata.guard_event_id = state.guardEventId;
|
|
375
|
+
}
|
|
376
|
+
const resolvedModel = state.model ?? extractModelFromOutput(output) ?? "unknown";
|
|
377
|
+
await this.agent.log({
|
|
378
|
+
system_id: this.systemId,
|
|
379
|
+
input: state.input,
|
|
380
|
+
output: outText,
|
|
381
|
+
event_id: state.clientEventId,
|
|
382
|
+
model: resolvedModel,
|
|
383
|
+
usage,
|
|
384
|
+
latency,
|
|
385
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : void 0,
|
|
386
|
+
client_capabilities: this.getLangchainCapabilities()
|
|
387
|
+
}, this.requestOptions);
|
|
388
|
+
logCallbackDebug("handleLLMEnd logged", {
|
|
389
|
+
runId: id,
|
|
390
|
+
clientEventId: state.clientEventId ?? null
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
async handleLLMError(err, runId) {
|
|
394
|
+
const id = String(runId ?? "");
|
|
395
|
+
logCallbackDebug("handleLLMError", { runId: id });
|
|
396
|
+
const state = this.runs.get(id);
|
|
397
|
+
if (state) this.runs.delete(id);
|
|
398
|
+
const message = err && typeof err === "object" && "message" in err ? String(err.message) : String(err ?? "");
|
|
399
|
+
const metadata = {
|
|
400
|
+
error_message: message
|
|
401
|
+
};
|
|
402
|
+
if (state?.clientEventId) {
|
|
403
|
+
metadata.client_event_id = state.clientEventId;
|
|
404
|
+
}
|
|
405
|
+
if (state?.guardEventId) {
|
|
406
|
+
metadata.guard_event_id = state.guardEventId;
|
|
407
|
+
}
|
|
408
|
+
await this.agent.log({
|
|
409
|
+
system_id: this.systemId,
|
|
410
|
+
input: state?.input ?? "",
|
|
411
|
+
output: "",
|
|
412
|
+
event_id: state?.clientEventId,
|
|
413
|
+
model: state?.model ?? "unknown",
|
|
414
|
+
event_type: "error",
|
|
415
|
+
severity: "error",
|
|
416
|
+
metadata,
|
|
417
|
+
client_capabilities: this.getLangchainCapabilities()
|
|
418
|
+
}, this.requestOptions);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
export {
|
|
423
|
+
AgentIDCallbackHandler
|
|
424
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-
|
|
1
|
+
export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-BykeB2WB.mjs';
|
|
2
|
+
import '@langchain/core/callbacks/base';
|
|
2
3
|
|
|
3
4
|
type PIIMapping = Record<string, string>;
|
|
4
5
|
declare class PIIManager {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-
|
|
1
|
+
export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-BykeB2WB.js';
|
|
2
|
+
import '@langchain/core/callbacks/base';
|
|
2
3
|
|
|
3
4
|
type PIIMapping = Record<string, string>;
|
|
4
5
|
declare class PIIManager {
|