@economic/agents 2.3.20 → 2.3.21
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.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as verifyJwt, i as extractTokenFromConnectRequest, n as createAgentTracer, r as recordFeedbackAnalytics, t as routeAgentRequest } from "./route-agent-request-
|
|
1
|
+
import { a as verifyJwt, i as extractTokenFromConnectRequest, n as createAgentTracer, r as recordFeedbackAnalytics, t as routeAgentRequest } from "./route-agent-request-GWXHyI2L.mjs";
|
|
2
2
|
import { Agent as Agent$1, callable, getCurrentAgent } from "agents";
|
|
3
3
|
import { Think, skills } from "@cloudflare/think";
|
|
4
4
|
import { Output, convertToModelMessages, generateText, jsonSchema, pruneMessages, tool as tool$1 } from "ai";
|
|
@@ -277,6 +277,15 @@ async function handleAuditSpan(span, auditLogs, context) {
|
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/server/features/telemetry/analytics.ts
|
|
280
|
+
const emittedToolCallIds = /* @__PURE__ */ new Set();
|
|
281
|
+
function safeJsonString(value) {
|
|
282
|
+
if (value === void 0) return void 0;
|
|
283
|
+
try {
|
|
284
|
+
return JSON.stringify(value);
|
|
285
|
+
} catch {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
280
289
|
function writeAnalyticsDatapoint(analytics, dataPoint) {
|
|
281
290
|
if (!analytics) return;
|
|
282
291
|
try {
|
|
@@ -308,6 +317,7 @@ function handleAnalyticsSpan(span, analytics, context) {
|
|
|
308
317
|
if (span.name === "ai.streamText.doStream") {
|
|
309
318
|
const promptMessages = parseJson(stringAttribute(span, "ai.prompt.messages"));
|
|
310
319
|
const responseText = stringAttribute(span, "ai.response.text") ?? "";
|
|
320
|
+
const responseToolCalls = parseJson(stringAttribute(span, "ai.response.toolCalls"));
|
|
311
321
|
writeAnalyticsDatapoint(analytics, {
|
|
312
322
|
indexes: [context.actorId],
|
|
313
323
|
blobs: [
|
|
@@ -329,10 +339,48 @@ function handleAnalyticsSpan(span, analytics, context) {
|
|
|
329
339
|
responseText.length
|
|
330
340
|
]
|
|
331
341
|
});
|
|
342
|
+
if (Array.isArray(responseToolCalls)) for (const value of responseToolCalls) {
|
|
343
|
+
if (!value || typeof value !== "object") continue;
|
|
344
|
+
const toolCall = value;
|
|
345
|
+
const toolCallId = typeof toolCall.toolCallId === "string" ? toolCall.toolCallId : void 0;
|
|
346
|
+
if (toolCallId && emittedToolCallIds.has(toolCallId)) continue;
|
|
347
|
+
const toolName = typeof toolCall.toolName === "string" ? toolCall.toolName : void 0;
|
|
348
|
+
if (!toolName) continue;
|
|
349
|
+
const input = toolCall.input;
|
|
350
|
+
const argsRaw = safeJsonString(input);
|
|
351
|
+
const success = span.status.code === 0;
|
|
352
|
+
const activatedSkills = extractSkillNames(toolName, input);
|
|
353
|
+
const skillNames = activatedSkills.length ? activatedSkills : [currentSkillByChat.get(context.durableObjectName) ?? ""];
|
|
354
|
+
if (toolCallId) emittedToolCallIds.add(toolCallId);
|
|
355
|
+
for (const skillName of skillNames) writeAnalyticsDatapoint(analytics, {
|
|
356
|
+
indexes: [context.actorId],
|
|
357
|
+
blobs: [
|
|
358
|
+
"tool_call",
|
|
359
|
+
context.agentName,
|
|
360
|
+
context.durableObjectName,
|
|
361
|
+
toolName,
|
|
362
|
+
skillName,
|
|
363
|
+
success ? "success" : "error"
|
|
364
|
+
],
|
|
365
|
+
doubles: [
|
|
366
|
+
0,
|
|
367
|
+
success ? 1 : 0,
|
|
368
|
+
argsRaw?.length ?? 0,
|
|
369
|
+
0,
|
|
370
|
+
0,
|
|
371
|
+
0,
|
|
372
|
+
0,
|
|
373
|
+
0
|
|
374
|
+
]
|
|
375
|
+
});
|
|
376
|
+
}
|
|
332
377
|
return;
|
|
333
378
|
}
|
|
334
379
|
if (span.name === "ai.toolCall") {
|
|
335
380
|
const toolName = stringAttribute(span, "ai.toolCall.name");
|
|
381
|
+
const toolCallId = stringAttribute(span, "ai.toolCall.id");
|
|
382
|
+
if (toolCallId && emittedToolCallIds.has(toolCallId)) return;
|
|
383
|
+
if (toolCallId) emittedToolCallIds.add(toolCallId);
|
|
336
384
|
const argsRaw = stringAttribute(span, "ai.toolCall.args");
|
|
337
385
|
const toolInput = parseJson(argsRaw);
|
|
338
386
|
const success = span.status.code === 0;
|
package/dist/v1.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as verifyJwt, i as extractTokenFromConnectRequest, n as createAgentTracer, t as routeAgentRequest } from "./route-agent-request-
|
|
1
|
+
import { a as verifyJwt, i as extractTokenFromConnectRequest, n as createAgentTracer, t as routeAgentRequest } from "./route-agent-request-GWXHyI2L.mjs";
|
|
2
2
|
import { Agent as Agent$1, callable, getCurrentAgent } from "agents";
|
|
3
3
|
import { Output, convertToModelMessages, generateText, jsonSchema, stepCountIs, streamText, tool } from "ai";
|
|
4
4
|
import { AIChatAgent } from "@cloudflare/ai-chat";
|