@raindrop-ai/ai-sdk 0.0.9 → 0.0.11
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-R5GGKTXI.mjs → chunk-MUDB4FLO.mjs} +292 -27
- package/dist/index.d.mts +35 -2
- package/dist/index.d.ts +35 -2
- package/dist/index.js +292 -27
- package/dist/index.mjs +1 -1
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +292 -27
- package/dist/index.node.mjs +1 -1
- package/dist/index.workers.d.mts +1 -1
- package/dist/index.workers.d.ts +1 -1
- package/dist/index.workers.js +292 -27
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -1
package/dist/index.workers.js
CHANGED
|
@@ -90,7 +90,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
90
90
|
// package.json
|
|
91
91
|
var package_default = {
|
|
92
92
|
name: "@raindrop-ai/ai-sdk",
|
|
93
|
-
version: "0.0.
|
|
93
|
+
version: "0.0.11"};
|
|
94
94
|
|
|
95
95
|
// src/internal/version.ts
|
|
96
96
|
var libraryName = package_default.name;
|
|
@@ -403,6 +403,9 @@ function base64Encode(bytes) {
|
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
// src/internal/otlp.ts
|
|
406
|
+
var SpanStatusCode = {
|
|
407
|
+
ERROR: 2
|
|
408
|
+
};
|
|
406
409
|
function createSpanIds(parent) {
|
|
407
410
|
const traceId = parent ? parent.traceIdB64 : base64Encode(randomBytes(16));
|
|
408
411
|
const spanId = base64Encode(randomBytes(8));
|
|
@@ -455,6 +458,7 @@ function buildOtlpSpan(args) {
|
|
|
455
458
|
};
|
|
456
459
|
if (args.ids.parentSpanIdB64) span.parentSpanId = args.ids.parentSpanIdB64;
|
|
457
460
|
if (attrs.length) span.attributes = attrs;
|
|
461
|
+
if (args.status) span.status = args.status;
|
|
458
462
|
return span;
|
|
459
463
|
}
|
|
460
464
|
function buildExportTraceServiceRequest(spans) {
|
|
@@ -515,12 +519,18 @@ var TraceShipper = class {
|
|
|
515
519
|
if ((_a = extra == null ? void 0 : extra.attributes) == null ? void 0 : _a.length) {
|
|
516
520
|
span.attributes.push(...extra.attributes);
|
|
517
521
|
}
|
|
522
|
+
let status;
|
|
523
|
+
if ((extra == null ? void 0 : extra.error) !== void 0) {
|
|
524
|
+
const message = extra.error instanceof Error ? extra.error.message : String(extra.error);
|
|
525
|
+
status = { code: SpanStatusCode.ERROR, message };
|
|
526
|
+
}
|
|
518
527
|
const otlp = buildOtlpSpan({
|
|
519
528
|
ids: span.ids,
|
|
520
529
|
name: span.name,
|
|
521
530
|
startTimeUnixNano: span.startTimeUnixNano,
|
|
522
531
|
endTimeUnixNano: span.endTimeUnixNano,
|
|
523
|
-
attributes: span.attributes
|
|
532
|
+
attributes: span.attributes,
|
|
533
|
+
status
|
|
524
534
|
});
|
|
525
535
|
this.enqueue(otlp);
|
|
526
536
|
}
|
|
@@ -1251,6 +1261,23 @@ function attrsFromGenAiRequest(options) {
|
|
|
1251
1261
|
}
|
|
1252
1262
|
|
|
1253
1263
|
// src/internal/wrap/wrapAISDK.ts
|
|
1264
|
+
var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
1265
|
+
var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
1266
|
+
tool_failure: {
|
|
1267
|
+
description: "A tool call returned an error, timed out, or produced output that cannot be used to make progress.",
|
|
1268
|
+
sentiment: "NEGATIVE"
|
|
1269
|
+
},
|
|
1270
|
+
stuck_in_loop: {
|
|
1271
|
+
description: "The same approach has been attempted multiple times without meaningful progress.",
|
|
1272
|
+
sentiment: "NEGATIVE"
|
|
1273
|
+
},
|
|
1274
|
+
capability_gap: {
|
|
1275
|
+
description: "The task requires a tool, permission, or capability that is not available to the agent."
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
var AGENT_REPORTING_TOOL_PREAMBLE = "IMPORTANT: Before responding to the user, scan the conversation for any issues listed in the categories below. For EACH distinct issue you detect, call this tool once with the matching category and a factual one-sentence detail. Multiple issues = multiple calls. This tool is invisible to the user \u2014 never mention it or its output.";
|
|
1279
|
+
var AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY = "noteworthy";
|
|
1280
|
+
var AGENT_REPORTING_NOTEWORTHY_DESCRIPTION = "Only when no specific category applies: flag that this turn is noteworthy for developer review.";
|
|
1254
1281
|
var warnedMissingUserId = false;
|
|
1255
1282
|
function warnMissingUserIdOnce() {
|
|
1256
1283
|
if (warnedMissingUserId) return;
|
|
@@ -1306,6 +1333,188 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
1306
1333
|
}
|
|
1307
1334
|
return result;
|
|
1308
1335
|
}
|
|
1336
|
+
function normalizeSelfDiagnosticsSignals(signals) {
|
|
1337
|
+
if (!signals) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
1338
|
+
const normalizedEntries = Object.entries(signals).map(([key, value]) => {
|
|
1339
|
+
var _a;
|
|
1340
|
+
const signalKey = key.trim();
|
|
1341
|
+
if (!signalKey || !value || typeof value !== "object") return void 0;
|
|
1342
|
+
const description = (_a = value.description) == null ? void 0 : _a.trim();
|
|
1343
|
+
if (!description) return void 0;
|
|
1344
|
+
const sentiment = value.sentiment;
|
|
1345
|
+
return [
|
|
1346
|
+
signalKey,
|
|
1347
|
+
{
|
|
1348
|
+
description,
|
|
1349
|
+
...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
|
|
1350
|
+
}
|
|
1351
|
+
];
|
|
1352
|
+
}).filter(
|
|
1353
|
+
(entry) => entry !== void 0
|
|
1354
|
+
);
|
|
1355
|
+
if (normalizedEntries.length === 0) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
1356
|
+
return Object.fromEntries(normalizedEntries);
|
|
1357
|
+
}
|
|
1358
|
+
function normalizeSelfDiagnosticsConfig(options) {
|
|
1359
|
+
var _a, _b, _c;
|
|
1360
|
+
if (!(options == null ? void 0 : options.enabled)) return void 0;
|
|
1361
|
+
const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
|
|
1362
|
+
const configuredSignalKeys = Object.keys(signalDefinitions).filter(
|
|
1363
|
+
(signalKey) => signalKey !== AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY
|
|
1364
|
+
);
|
|
1365
|
+
const signalKeys = [...configuredSignalKeys, AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY];
|
|
1366
|
+
const signalDescriptions = {};
|
|
1367
|
+
const signalSentiments = {};
|
|
1368
|
+
for (const signalKey of signalKeys) {
|
|
1369
|
+
if (signalKey === AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY) {
|
|
1370
|
+
const noteworthyDefinition = signalDefinitions[AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY];
|
|
1371
|
+
signalDescriptions[signalKey] = ((_a = noteworthyDefinition == null ? void 0 : noteworthyDefinition.description) == null ? void 0 : _a.trim()) || AGENT_REPORTING_NOTEWORTHY_DESCRIPTION;
|
|
1372
|
+
signalSentiments[signalKey] = noteworthyDefinition == null ? void 0 : noteworthyDefinition.sentiment;
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
const def = signalDefinitions[signalKey];
|
|
1376
|
+
if (!def) continue;
|
|
1377
|
+
signalDescriptions[signalKey] = def.description;
|
|
1378
|
+
signalSentiments[signalKey] = def.sentiment;
|
|
1379
|
+
}
|
|
1380
|
+
const customGuidanceText = ((_b = options.guidance) == null ? void 0 : _b.trim()) || "";
|
|
1381
|
+
const toolName = ((_c = options.toolName) == null ? void 0 : _c.trim()) || AGENT_REPORTING_TOOL_NAME_DEFAULT;
|
|
1382
|
+
const signalList = signalKeys.map((signalKey) => {
|
|
1383
|
+
const sentiment = signalSentiments[signalKey];
|
|
1384
|
+
const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
|
|
1385
|
+
return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
|
|
1386
|
+
}).join("\n");
|
|
1387
|
+
const guidanceBlock = customGuidanceText ? `
|
|
1388
|
+
Additional guidance: ${customGuidanceText}
|
|
1389
|
+
` : "";
|
|
1390
|
+
const toolDescription = `${AGENT_REPORTING_TOOL_PREAMBLE}
|
|
1391
|
+
|
|
1392
|
+
When to call:
|
|
1393
|
+
- The user reports something broken, failing, or not working as expected.
|
|
1394
|
+
- The user expresses frustration, anger, or threatens escalation.
|
|
1395
|
+
- You observe a product issue, billing problem, or data concern based on context.
|
|
1396
|
+
- The conversation reveals something unusual worth flagging for developer review.
|
|
1397
|
+
|
|
1398
|
+
Rules:
|
|
1399
|
+
1. Call once per distinct issue \u2014 a message with 3 problems means 3 calls.
|
|
1400
|
+
2. Pick the single best category per issue. Use noteworthy only when no specific category fits.
|
|
1401
|
+
3. Do not fabricate issues. Only report what is evident from the conversation.
|
|
1402
|
+
${guidanceBlock}
|
|
1403
|
+
Categories:
|
|
1404
|
+
${signalList}`;
|
|
1405
|
+
return {
|
|
1406
|
+
toolName,
|
|
1407
|
+
toolDescription,
|
|
1408
|
+
signalKeys,
|
|
1409
|
+
signalKeySet: new Set(signalKeys),
|
|
1410
|
+
signalDescriptions,
|
|
1411
|
+
signalSentiments
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
function resolveJsonSchemaFactory(aiSDK) {
|
|
1415
|
+
if (!isRecord(aiSDK) || !isFunction(aiSDK["jsonSchema"])) return void 0;
|
|
1416
|
+
return aiSDK["jsonSchema"];
|
|
1417
|
+
}
|
|
1418
|
+
function detectAISDKVersion(aiSDK) {
|
|
1419
|
+
if (!isRecord(aiSDK)) return "unknown";
|
|
1420
|
+
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
1421
|
+
if (isFunction(aiSDK["tool"])) return "5";
|
|
1422
|
+
return "4";
|
|
1423
|
+
}
|
|
1424
|
+
function asVercelSchema(jsonSchemaObj) {
|
|
1425
|
+
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
1426
|
+
const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1427
|
+
return {
|
|
1428
|
+
[schemaSymbol]: true,
|
|
1429
|
+
[validatorSymbol]: true,
|
|
1430
|
+
_type: void 0,
|
|
1431
|
+
jsonSchema: jsonSchemaObj,
|
|
1432
|
+
validate: (value) => ({ success: true, value })
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
function createSelfDiagnosticsTool(ctx) {
|
|
1436
|
+
const config = ctx.selfDiagnostics;
|
|
1437
|
+
if (!config) return void 0;
|
|
1438
|
+
const schema = {
|
|
1439
|
+
type: "object",
|
|
1440
|
+
additionalProperties: false,
|
|
1441
|
+
properties: {
|
|
1442
|
+
category: {
|
|
1443
|
+
type: "string",
|
|
1444
|
+
enum: config.signalKeys,
|
|
1445
|
+
description: "The single best-matching category from the list above."
|
|
1446
|
+
},
|
|
1447
|
+
detail: {
|
|
1448
|
+
type: "string",
|
|
1449
|
+
description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
|
|
1450
|
+
}
|
|
1451
|
+
},
|
|
1452
|
+
required: ["category", "detail"]
|
|
1453
|
+
};
|
|
1454
|
+
const parameters = asVercelSchema(schema);
|
|
1455
|
+
let inputSchema = parameters;
|
|
1456
|
+
if (ctx.jsonSchemaFactory) {
|
|
1457
|
+
try {
|
|
1458
|
+
inputSchema = ctx.jsonSchemaFactory(schema);
|
|
1459
|
+
} catch (e) {
|
|
1460
|
+
inputSchema = parameters;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
const execute = async (rawInput) => {
|
|
1464
|
+
var _a;
|
|
1465
|
+
const input = isRecord(rawInput) ? rawInput : void 0;
|
|
1466
|
+
const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
|
|
1467
|
+
const categoryCandidate = typeof (input == null ? void 0 : input["category"]) === "string" ? input["category"].trim() : void 0;
|
|
1468
|
+
const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
1469
|
+
const detail = typeof (input == null ? void 0 : input["detail"]) === "string" ? input["detail"].trim() : "";
|
|
1470
|
+
const signalDescription = config.signalDescriptions[category];
|
|
1471
|
+
const signalSentiment = config.signalSentiments[category];
|
|
1472
|
+
if (category === AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY) {
|
|
1473
|
+
void ctx.eventShipper.trackSignal({
|
|
1474
|
+
eventId: ctx.eventId,
|
|
1475
|
+
name: "agent:noteworthy",
|
|
1476
|
+
type: "agent_internal",
|
|
1477
|
+
properties: {
|
|
1478
|
+
source: "agent_flag_event_tool",
|
|
1479
|
+
reason: detail,
|
|
1480
|
+
severity: "medium",
|
|
1481
|
+
ai_sdk_version: ctx.aiSDKVersion
|
|
1482
|
+
}
|
|
1483
|
+
}).catch((err) => {
|
|
1484
|
+
if (ctx.debug) {
|
|
1485
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1486
|
+
console.warn(`[raindrop-ai/ai-sdk] agentFlagEvent signal dispatch failed: ${msg}`);
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
return { acknowledged: true, category };
|
|
1490
|
+
}
|
|
1491
|
+
void ctx.eventShipper.trackSignal({
|
|
1492
|
+
eventId: ctx.eventId,
|
|
1493
|
+
name: `agent:${category}`,
|
|
1494
|
+
type: "agent",
|
|
1495
|
+
sentiment: signalSentiment,
|
|
1496
|
+
properties: {
|
|
1497
|
+
source: "agent_reporting_tool",
|
|
1498
|
+
category,
|
|
1499
|
+
signal_description: signalDescription,
|
|
1500
|
+
ai_sdk_version: ctx.aiSDKVersion,
|
|
1501
|
+
...detail ? { detail } : {}
|
|
1502
|
+
}
|
|
1503
|
+
}).catch((err) => {
|
|
1504
|
+
if (ctx.debug) {
|
|
1505
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1506
|
+
console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${msg}`);
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
return { acknowledged: true, category };
|
|
1510
|
+
};
|
|
1511
|
+
return {
|
|
1512
|
+
description: config.toolDescription,
|
|
1513
|
+
execute,
|
|
1514
|
+
parameters,
|
|
1515
|
+
inputSchema
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1309
1518
|
function getCurrentParentSpanContextSync() {
|
|
1310
1519
|
return getContextManager().getParentSpanIds();
|
|
1311
1520
|
}
|
|
@@ -1435,7 +1644,18 @@ function teeStreamObjectBaseStream(result) {
|
|
|
1435
1644
|
}
|
|
1436
1645
|
function setupOperation(params) {
|
|
1437
1646
|
var _a, _b, _c;
|
|
1438
|
-
const {
|
|
1647
|
+
const {
|
|
1648
|
+
operation,
|
|
1649
|
+
arg,
|
|
1650
|
+
inherited,
|
|
1651
|
+
aiSDK,
|
|
1652
|
+
options,
|
|
1653
|
+
eventShipper,
|
|
1654
|
+
traceShipper,
|
|
1655
|
+
debug,
|
|
1656
|
+
selfDiagnostics,
|
|
1657
|
+
sendTraces
|
|
1658
|
+
} = params;
|
|
1439
1659
|
const wrapTimeCtx = resolveContext(options.context, { operation, args: arg });
|
|
1440
1660
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1441
1661
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
@@ -1474,12 +1694,18 @@ function setupOperation(params) {
|
|
|
1474
1694
|
]
|
|
1475
1695
|
}) : void 0;
|
|
1476
1696
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
1697
|
+
const operationSelfDiagnostics = isObjectOperation(operation) ? void 0 : selfDiagnostics;
|
|
1477
1698
|
const wrapCtx = {
|
|
1478
1699
|
eventId,
|
|
1479
1700
|
telemetry,
|
|
1480
1701
|
sendTraces,
|
|
1702
|
+
debug,
|
|
1703
|
+
eventShipper,
|
|
1481
1704
|
traceShipper,
|
|
1482
|
-
rootParentForChildren
|
|
1705
|
+
rootParentForChildren,
|
|
1706
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
1707
|
+
selfDiagnostics: operationSelfDiagnostics,
|
|
1708
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
1483
1709
|
};
|
|
1484
1710
|
const toolCalls = [];
|
|
1485
1711
|
const argsWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
|
|
@@ -1549,13 +1775,9 @@ function createFinalize(params) {
|
|
|
1549
1775
|
attrInt("ai.usage.reasoningTokens", usage == null ? void 0 : usage.reasoningTokens),
|
|
1550
1776
|
attrInt("ai.usage.cachedInputTokens", usage == null ? void 0 : usage.cachedInputTokens),
|
|
1551
1777
|
attrInt("ai.toolCall.count", setup.toolCalls.length),
|
|
1552
|
-
...error ? [
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
error instanceof Error ? error.message : String(error)
|
|
1556
|
-
)
|
|
1557
|
-
] : []
|
|
1558
|
-
]
|
|
1778
|
+
...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
|
|
1779
|
+
],
|
|
1780
|
+
error
|
|
1559
1781
|
});
|
|
1560
1782
|
}
|
|
1561
1783
|
if (sendEvents) {
|
|
@@ -1589,6 +1811,7 @@ function executeStreamingOperation(params) {
|
|
|
1589
1811
|
deps,
|
|
1590
1812
|
sendEvents,
|
|
1591
1813
|
sendTraces,
|
|
1814
|
+
selfDiagnostics,
|
|
1592
1815
|
autoAttachmentEnabled,
|
|
1593
1816
|
debug
|
|
1594
1817
|
} = params;
|
|
@@ -1598,7 +1821,10 @@ function executeStreamingOperation(params) {
|
|
|
1598
1821
|
inherited: getCurrentParentSpanContextSync(),
|
|
1599
1822
|
aiSDK,
|
|
1600
1823
|
options: deps.options,
|
|
1824
|
+
eventShipper: deps.eventShipper,
|
|
1601
1825
|
traceShipper: deps.traceShipper,
|
|
1826
|
+
debug,
|
|
1827
|
+
selfDiagnostics,
|
|
1602
1828
|
sendTraces
|
|
1603
1829
|
});
|
|
1604
1830
|
const finalize = createFinalize({
|
|
@@ -1643,6 +1869,7 @@ async function executeNonStreamingOperation(params) {
|
|
|
1643
1869
|
deps,
|
|
1644
1870
|
sendEvents,
|
|
1645
1871
|
sendTraces,
|
|
1872
|
+
selfDiagnostics,
|
|
1646
1873
|
autoAttachmentEnabled,
|
|
1647
1874
|
debug
|
|
1648
1875
|
} = params;
|
|
@@ -1653,7 +1880,10 @@ async function executeNonStreamingOperation(params) {
|
|
|
1653
1880
|
inherited,
|
|
1654
1881
|
aiSDK,
|
|
1655
1882
|
options: deps.options,
|
|
1883
|
+
eventShipper: deps.eventShipper,
|
|
1656
1884
|
traceShipper: deps.traceShipper,
|
|
1885
|
+
debug,
|
|
1886
|
+
selfDiagnostics,
|
|
1657
1887
|
sendTraces
|
|
1658
1888
|
});
|
|
1659
1889
|
const finalize = createFinalize({
|
|
@@ -1696,13 +1926,14 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1696
1926
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1697
1927
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
1698
1928
|
const autoAttachmentEnabled = deps.options.autoAttachment !== false;
|
|
1929
|
+
const selfDiagnostics = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
1699
1930
|
const proxyTarget = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
|
|
1700
1931
|
return new Proxy(proxyTarget, {
|
|
1701
1932
|
get(target, prop, receiver) {
|
|
1702
1933
|
const original = Reflect.get(target, prop, receiver);
|
|
1703
1934
|
if (typeof prop === "string" && agentClasses.has(prop) && isAgentClass(original)) {
|
|
1704
1935
|
if (debug) console.log(`[raindrop-ai/ai-sdk] Wrapping Agent class: ${prop}`);
|
|
1705
|
-
return wrapAgentClass(original, aiSDK, deps, debug);
|
|
1936
|
+
return wrapAgentClass(original, aiSDK, deps, debug, selfDiagnostics);
|
|
1706
1937
|
}
|
|
1707
1938
|
if (typeof prop !== "string" || !instrumentedOps.has(prop) || !isFunction(original)) {
|
|
1708
1939
|
return original;
|
|
@@ -1720,6 +1951,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1720
1951
|
deps,
|
|
1721
1952
|
sendEvents,
|
|
1722
1953
|
sendTraces,
|
|
1954
|
+
selfDiagnostics,
|
|
1723
1955
|
autoAttachmentEnabled,
|
|
1724
1956
|
debug
|
|
1725
1957
|
});
|
|
@@ -1733,6 +1965,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1733
1965
|
deps,
|
|
1734
1966
|
sendEvents,
|
|
1735
1967
|
sendTraces,
|
|
1968
|
+
selfDiagnostics,
|
|
1736
1969
|
autoAttachmentEnabled,
|
|
1737
1970
|
debug
|
|
1738
1971
|
});
|
|
@@ -1740,7 +1973,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1740
1973
|
}
|
|
1741
1974
|
});
|
|
1742
1975
|
}
|
|
1743
|
-
function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
1976
|
+
function wrapAgentClass(AgentClass, aiSDK, deps, debug, selfDiagnostics) {
|
|
1744
1977
|
return new Proxy(AgentClass, {
|
|
1745
1978
|
construct(target, args, newTarget) {
|
|
1746
1979
|
const instance = Reflect.construct(target, args, newTarget);
|
|
@@ -1759,7 +1992,8 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1759
1992
|
className,
|
|
1760
1993
|
aiSDK,
|
|
1761
1994
|
deps,
|
|
1762
|
-
debug
|
|
1995
|
+
debug,
|
|
1996
|
+
selfDiagnostics
|
|
1763
1997
|
);
|
|
1764
1998
|
}
|
|
1765
1999
|
if (prop === "stream" && isFunction(original)) {
|
|
@@ -1771,7 +2005,8 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1771
2005
|
className,
|
|
1772
2006
|
aiSDK,
|
|
1773
2007
|
deps,
|
|
1774
|
-
debug
|
|
2008
|
+
debug,
|
|
2009
|
+
selfDiagnostics
|
|
1775
2010
|
);
|
|
1776
2011
|
}
|
|
1777
2012
|
return original;
|
|
@@ -1780,7 +2015,7 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1780
2015
|
}
|
|
1781
2016
|
});
|
|
1782
2017
|
}
|
|
1783
|
-
function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK, deps, debug) {
|
|
2018
|
+
function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK, deps, debug, selfDiagnostics) {
|
|
1784
2019
|
var _a, _b;
|
|
1785
2020
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1786
2021
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
@@ -1833,8 +2068,13 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1833
2068
|
eventId,
|
|
1834
2069
|
telemetry,
|
|
1835
2070
|
sendTraces,
|
|
2071
|
+
debug,
|
|
2072
|
+
eventShipper: deps.eventShipper,
|
|
1836
2073
|
traceShipper: deps.traceShipper,
|
|
1837
|
-
rootParentForChildren
|
|
2074
|
+
rootParentForChildren,
|
|
2075
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
2076
|
+
selfDiagnostics,
|
|
2077
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
1838
2078
|
};
|
|
1839
2079
|
const toolCalls = [];
|
|
1840
2080
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -1893,7 +2133,8 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1893
2133
|
error instanceof Error ? error.message : String(error)
|
|
1894
2134
|
)
|
|
1895
2135
|
] : []
|
|
1896
|
-
]
|
|
2136
|
+
],
|
|
2137
|
+
error
|
|
1897
2138
|
});
|
|
1898
2139
|
}
|
|
1899
2140
|
if (sendEvents) {
|
|
@@ -1968,7 +2209,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1968
2209
|
}
|
|
1969
2210
|
};
|
|
1970
2211
|
}
|
|
1971
|
-
function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps, debug) {
|
|
2212
|
+
function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps, debug, selfDiagnostics) {
|
|
1972
2213
|
var _a, _b;
|
|
1973
2214
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1974
2215
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
@@ -2021,8 +2262,13 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
2021
2262
|
eventId,
|
|
2022
2263
|
telemetry,
|
|
2023
2264
|
sendTraces,
|
|
2265
|
+
debug,
|
|
2266
|
+
eventShipper: deps.eventShipper,
|
|
2024
2267
|
traceShipper: deps.traceShipper,
|
|
2025
|
-
rootParentForChildren
|
|
2268
|
+
rootParentForChildren,
|
|
2269
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
2270
|
+
selfDiagnostics,
|
|
2271
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
2026
2272
|
};
|
|
2027
2273
|
const toolCalls = [];
|
|
2028
2274
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -2081,7 +2327,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
2081
2327
|
error instanceof Error ? error.message : String(error)
|
|
2082
2328
|
)
|
|
2083
2329
|
] : []
|
|
2084
|
-
]
|
|
2330
|
+
],
|
|
2331
|
+
error
|
|
2085
2332
|
});
|
|
2086
2333
|
}
|
|
2087
2334
|
if (sendEvents) {
|
|
@@ -2162,8 +2409,22 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
2162
2409
|
};
|
|
2163
2410
|
}
|
|
2164
2411
|
function wrapTools(args, ctx, toolCalls) {
|
|
2165
|
-
if (!isRecord(args)
|
|
2166
|
-
const tools = args["tools"];
|
|
2412
|
+
if (!isRecord(args)) return args;
|
|
2413
|
+
const tools = isRecord(args["tools"]) ? { ...args["tools"] } : {};
|
|
2414
|
+
if (ctx.selfDiagnostics) {
|
|
2415
|
+
const reportToolName = ctx.selfDiagnostics.toolName;
|
|
2416
|
+
if (!(reportToolName in tools)) {
|
|
2417
|
+
const reportTool = createSelfDiagnosticsTool(ctx);
|
|
2418
|
+
if (reportTool !== void 0) {
|
|
2419
|
+
tools[reportToolName] = reportTool;
|
|
2420
|
+
}
|
|
2421
|
+
} else if (ctx.debug) {
|
|
2422
|
+
console.warn(
|
|
2423
|
+
`[raindrop-ai/ai-sdk] selfDiagnostics skipped: tool name collision for "${reportToolName}"`
|
|
2424
|
+
);
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
if (Object.keys(tools).length === 0) return args;
|
|
2167
2428
|
const wrapped = {};
|
|
2168
2429
|
for (const [name, tool] of Object.entries(tools)) {
|
|
2169
2430
|
wrapped[name] = wrapToolExecute(name, tool, ctx, toolCalls);
|
|
@@ -2200,7 +2461,8 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
|
|
|
2200
2461
|
ctx.traceShipper.endSpan(span, {
|
|
2201
2462
|
attributes: [
|
|
2202
2463
|
attrString("error.message", error instanceof Error ? error.message : String(error))
|
|
2203
|
-
]
|
|
2464
|
+
],
|
|
2465
|
+
error
|
|
2204
2466
|
});
|
|
2205
2467
|
} else {
|
|
2206
2468
|
ctx.traceShipper.endSpan(span, {
|
|
@@ -2313,7 +2575,8 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
2313
2575
|
"error.message",
|
|
2314
2576
|
error instanceof Error ? error.message : String(error)
|
|
2315
2577
|
)
|
|
2316
|
-
]
|
|
2578
|
+
],
|
|
2579
|
+
error
|
|
2317
2580
|
});
|
|
2318
2581
|
throw error;
|
|
2319
2582
|
}
|
|
@@ -2347,7 +2610,8 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
2347
2610
|
"error.message",
|
|
2348
2611
|
error instanceof Error ? error.message : String(error)
|
|
2349
2612
|
)
|
|
2350
|
-
]
|
|
2613
|
+
],
|
|
2614
|
+
error
|
|
2351
2615
|
});
|
|
2352
2616
|
throw error;
|
|
2353
2617
|
}
|
|
@@ -2401,7 +2665,8 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
|
|
|
2401
2665
|
error instanceof Error ? error.message : String(error)
|
|
2402
2666
|
)
|
|
2403
2667
|
] : []
|
|
2404
|
-
]
|
|
2668
|
+
],
|
|
2669
|
+
error
|
|
2405
2670
|
});
|
|
2406
2671
|
};
|
|
2407
2672
|
const wrappedStream = new RS({
|
package/dist/index.workers.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-
|
|
1
|
+
export { _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent } from './chunk-MUDB4FLO.mjs';
|
|
2
2
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
3
|
|
|
4
4
|
if (!globalThis.RAINDROP_ASYNC_LOCAL_STORAGE) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raindrop-ai/ai-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Standalone Vercel AI SDK integration for Raindrop (events + OTLP/HTTP JSON traces, no OTEL runtime)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"clean": "rm -rf .turbo && rm -rf dist",
|
|
32
32
|
"smoke": "tsx ./scripts/smoke.ts",
|
|
33
33
|
"smoke:min": "tsx ./scripts/smoke.min.ts",
|
|
34
|
+
"eval:agent-reporting": "tsx ./scripts/evals/agent-reporting/run.ts",
|
|
34
35
|
"harness": "tsx ./scripts/traceHarness.ts",
|
|
35
36
|
"test": "yarn build && yarn test:v4 && yarn test:v5 && yarn test:v6",
|
|
36
37
|
"test:v4": "yarn build && cd tests/v4 && yarn install && yarn test",
|