agentid-sdk 0.1.34 → 0.1.35
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/{agentid-M5I7-YqI.d.mts → agentid-IonlG0NB.d.mts} +23 -2
- package/dist/{agentid-M5I7-YqI.d.ts → agentid-IonlG0NB.d.ts} +23 -2
- package/dist/{chunk-FCOSLPMF.mjs → chunk-XFSIAH3F.mjs} +288 -34
- package/dist/index.d.mts +3 -16
- package/dist/index.d.ts +3 -16
- package/dist/index.js +288 -34
- package/dist/index.mjs +1 -1
- package/dist/langchain.d.mts +1 -1
- package/dist/langchain.d.ts +1 -1
- package/dist/langchain.js +1040 -5
- package/dist/langchain.mjs +102 -5
- package/dist/transparency-badge.d.mts +1 -1
- package/dist/transparency-badge.d.ts +1 -1
- package/package.json +1 -1
package/dist/langchain.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
PIIManager,
|
|
2
3
|
SecurityBlockError
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XFSIAH3F.mjs";
|
|
4
5
|
|
|
5
6
|
// src/langchain.ts
|
|
6
7
|
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
8
|
+
var piiManager = new PIIManager();
|
|
7
9
|
function safeString(val) {
|
|
8
10
|
return typeof val === "string" ? val : "";
|
|
9
11
|
}
|
|
@@ -205,6 +207,83 @@ function extractOutputText(output) {
|
|
|
205
207
|
const text = first?.text ?? first?.message?.content;
|
|
206
208
|
return typeof text === "string" ? text : "";
|
|
207
209
|
}
|
|
210
|
+
function normalizePiiMapping(value) {
|
|
211
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
const entries = Object.entries(value).filter(
|
|
215
|
+
([placeholder, replacement]) => placeholder.length > 0 && typeof replacement === "string"
|
|
216
|
+
);
|
|
217
|
+
if (entries.length === 0) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
return Object.fromEntries(entries);
|
|
221
|
+
}
|
|
222
|
+
function deanonymizeText(text, mapping) {
|
|
223
|
+
if (!text || !mapping) {
|
|
224
|
+
return text;
|
|
225
|
+
}
|
|
226
|
+
return piiManager.deanonymize(text, mapping);
|
|
227
|
+
}
|
|
228
|
+
function deanonymizeContent(content, mapping) {
|
|
229
|
+
if (!mapping) {
|
|
230
|
+
return content;
|
|
231
|
+
}
|
|
232
|
+
if (typeof content === "string") {
|
|
233
|
+
return deanonymizeText(content, mapping);
|
|
234
|
+
}
|
|
235
|
+
if (!Array.isArray(content)) {
|
|
236
|
+
return content;
|
|
237
|
+
}
|
|
238
|
+
return content.map((item) => {
|
|
239
|
+
if (typeof item === "string") {
|
|
240
|
+
return deanonymizeText(item, mapping);
|
|
241
|
+
}
|
|
242
|
+
if (!item || typeof item !== "object") {
|
|
243
|
+
return item;
|
|
244
|
+
}
|
|
245
|
+
const record = { ...item };
|
|
246
|
+
if (typeof record.text === "string") {
|
|
247
|
+
record.text = deanonymizeText(record.text, mapping);
|
|
248
|
+
}
|
|
249
|
+
if (typeof record.content === "string") {
|
|
250
|
+
record.content = deanonymizeText(record.content, mapping);
|
|
251
|
+
}
|
|
252
|
+
return record;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function deanonymizeLangChainOutputForClient(output, mapping) {
|
|
256
|
+
if (!mapping) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const generations = output?.generations;
|
|
260
|
+
if (!Array.isArray(generations)) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
for (const generationGroup of generations) {
|
|
264
|
+
if (!Array.isArray(generationGroup)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
for (const generation of generationGroup) {
|
|
268
|
+
if (!generation || typeof generation !== "object") {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (typeof generation.text === "string") {
|
|
272
|
+
generation.text = deanonymizeText(generation.text, mapping);
|
|
273
|
+
}
|
|
274
|
+
const message = generation.message;
|
|
275
|
+
if (message && typeof message === "object") {
|
|
276
|
+
const typedMessage = message;
|
|
277
|
+
if ("content" in typedMessage) {
|
|
278
|
+
typedMessage.content = deanonymizeContent(typedMessage.content, mapping);
|
|
279
|
+
}
|
|
280
|
+
if (typeof typedMessage.text === "string") {
|
|
281
|
+
typedMessage.text = deanonymizeText(typedMessage.text, mapping);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
208
287
|
function extractTokenUsage(output) {
|
|
209
288
|
const llmOutput = output?.llmOutput ?? output?.llm_output;
|
|
210
289
|
const usage = llmOutput?.tokenUsage ?? llmOutput?.token_usage ?? llmOutput?.usage ?? void 0;
|
|
@@ -369,7 +448,11 @@ var AgentIDCallbackHandler = class extends BaseCallbackHandler {
|
|
|
369
448
|
model: modelName,
|
|
370
449
|
clientEventId: canonicalClientEventId,
|
|
371
450
|
guardEventId,
|
|
372
|
-
transparency
|
|
451
|
+
transparency,
|
|
452
|
+
piiMapping: normalizePiiMapping(prepared.piiMapping),
|
|
453
|
+
shouldDeanonymize: prepared.shouldDeanonymize === true,
|
|
454
|
+
responseStreamed: stream,
|
|
455
|
+
sdkConfigVersion: prepared.capabilityConfig?.version ?? null
|
|
373
456
|
});
|
|
374
457
|
logCallbackDebug("handleLLMStart state_set", {
|
|
375
458
|
runId: id,
|
|
@@ -458,7 +541,11 @@ var AgentIDCallbackHandler = class extends BaseCallbackHandler {
|
|
|
458
541
|
model: modelName,
|
|
459
542
|
clientEventId: canonicalClientEventId,
|
|
460
543
|
guardEventId,
|
|
461
|
-
transparency
|
|
544
|
+
transparency,
|
|
545
|
+
piiMapping: normalizePiiMapping(prepared.piiMapping),
|
|
546
|
+
shouldDeanonymize: prepared.shouldDeanonymize === true,
|
|
547
|
+
responseStreamed: stream,
|
|
548
|
+
sdkConfigVersion: prepared.capabilityConfig?.version ?? null
|
|
462
549
|
});
|
|
463
550
|
logCallbackDebug("handleChatModelStart state_set", {
|
|
464
551
|
runId: id,
|
|
@@ -480,7 +567,11 @@ var AgentIDCallbackHandler = class extends BaseCallbackHandler {
|
|
|
480
567
|
0,
|
|
481
568
|
Date.now() - (state.pipelineStartedAtMs ?? state.startedAtMs)
|
|
482
569
|
);
|
|
483
|
-
const
|
|
570
|
+
const maskedOutputText = extractOutputText(output);
|
|
571
|
+
if (state.shouldDeanonymize && state.piiMapping) {
|
|
572
|
+
deanonymizeLangChainOutputForClient(output, state.piiMapping);
|
|
573
|
+
}
|
|
574
|
+
const clientOutputText = extractOutputText(output);
|
|
484
575
|
const usage = extractTokenUsage(output);
|
|
485
576
|
const metadata = {};
|
|
486
577
|
if (state.clientEventId) {
|
|
@@ -500,13 +591,19 @@ var AgentIDCallbackHandler = class extends BaseCallbackHandler {
|
|
|
500
591
|
if (state.transparency) {
|
|
501
592
|
metadata.transparency = state.transparency;
|
|
502
593
|
}
|
|
594
|
+
if (typeof state.sdkConfigVersion === "number" && Number.isFinite(state.sdkConfigVersion)) {
|
|
595
|
+
metadata.sdk_config_version = Math.trunc(state.sdkConfigVersion);
|
|
596
|
+
}
|
|
597
|
+
metadata.response_streamed = state.responseStreamed === true;
|
|
598
|
+
metadata.transformed_output = maskedOutputText;
|
|
599
|
+
metadata.output_masked = maskedOutputText !== clientOutputText;
|
|
503
600
|
metadata.model_latency_ms = modelLatencyMs;
|
|
504
601
|
metadata.total_pipeline_latency_ms = totalPipelineLatencyMs;
|
|
505
602
|
const resolvedModel = state.model ?? extractModelFromOutput(output) ?? "unknown";
|
|
506
603
|
await this.agent.log({
|
|
507
604
|
system_id: this.systemId,
|
|
508
605
|
input: state.input,
|
|
509
|
-
output:
|
|
606
|
+
output: maskedOutputText,
|
|
510
607
|
event_id: state.clientEventId,
|
|
511
608
|
model: resolvedModel,
|
|
512
609
|
usage,
|