@raindrop-ai/ai-sdk 0.0.9 → 0.0.10
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-ZVQRZCBO.mjs} +267 -19
- package/dist/index.d.mts +35 -2
- package/dist/index.d.ts +35 -2
- package/dist/index.js +267 -19
- 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 +267 -19
- 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 +267 -19
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -1
|
@@ -84,7 +84,7 @@ async function postJson(url, body, headers, opts) {
|
|
|
84
84
|
// package.json
|
|
85
85
|
var package_default = {
|
|
86
86
|
name: "@raindrop-ai/ai-sdk",
|
|
87
|
-
version: "0.0.
|
|
87
|
+
version: "0.0.10"};
|
|
88
88
|
|
|
89
89
|
// src/internal/version.ts
|
|
90
90
|
var libraryName = package_default.name;
|
|
@@ -1245,6 +1245,23 @@ function attrsFromGenAiRequest(options) {
|
|
|
1245
1245
|
}
|
|
1246
1246
|
|
|
1247
1247
|
// src/internal/wrap/wrapAISDK.ts
|
|
1248
|
+
var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
1249
|
+
var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
1250
|
+
tool_failure: {
|
|
1251
|
+
description: "A tool call returned an error, timed out, or produced output that cannot be used to make progress.",
|
|
1252
|
+
sentiment: "NEGATIVE"
|
|
1253
|
+
},
|
|
1254
|
+
stuck_in_loop: {
|
|
1255
|
+
description: "The same approach has been attempted multiple times without meaningful progress.",
|
|
1256
|
+
sentiment: "NEGATIVE"
|
|
1257
|
+
},
|
|
1258
|
+
capability_gap: {
|
|
1259
|
+
description: "The task requires a tool, permission, or capability that is not available to the agent."
|
|
1260
|
+
}
|
|
1261
|
+
};
|
|
1262
|
+
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.";
|
|
1263
|
+
var AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY = "noteworthy";
|
|
1264
|
+
var AGENT_REPORTING_NOTEWORTHY_DESCRIPTION = "Only when no specific category applies: flag that this turn is noteworthy for developer review.";
|
|
1248
1265
|
var warnedMissingUserId = false;
|
|
1249
1266
|
function warnMissingUserIdOnce() {
|
|
1250
1267
|
if (warnedMissingUserId) return;
|
|
@@ -1300,6 +1317,188 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
1300
1317
|
}
|
|
1301
1318
|
return result;
|
|
1302
1319
|
}
|
|
1320
|
+
function normalizeSelfDiagnosticsSignals(signals) {
|
|
1321
|
+
if (!signals) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
1322
|
+
const normalizedEntries = Object.entries(signals).map(([key, value]) => {
|
|
1323
|
+
var _a;
|
|
1324
|
+
const signalKey = key.trim();
|
|
1325
|
+
if (!signalKey || !value || typeof value !== "object") return void 0;
|
|
1326
|
+
const description = (_a = value.description) == null ? void 0 : _a.trim();
|
|
1327
|
+
if (!description) return void 0;
|
|
1328
|
+
const sentiment = value.sentiment;
|
|
1329
|
+
return [
|
|
1330
|
+
signalKey,
|
|
1331
|
+
{
|
|
1332
|
+
description,
|
|
1333
|
+
...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
|
|
1334
|
+
}
|
|
1335
|
+
];
|
|
1336
|
+
}).filter(
|
|
1337
|
+
(entry) => entry !== void 0
|
|
1338
|
+
);
|
|
1339
|
+
if (normalizedEntries.length === 0) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
1340
|
+
return Object.fromEntries(normalizedEntries);
|
|
1341
|
+
}
|
|
1342
|
+
function normalizeSelfDiagnosticsConfig(options) {
|
|
1343
|
+
var _a, _b, _c;
|
|
1344
|
+
if (!(options == null ? void 0 : options.enabled)) return void 0;
|
|
1345
|
+
const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
|
|
1346
|
+
const configuredSignalKeys = Object.keys(signalDefinitions).filter(
|
|
1347
|
+
(signalKey) => signalKey !== AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY
|
|
1348
|
+
);
|
|
1349
|
+
const signalKeys = [...configuredSignalKeys, AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY];
|
|
1350
|
+
const signalDescriptions = {};
|
|
1351
|
+
const signalSentiments = {};
|
|
1352
|
+
for (const signalKey of signalKeys) {
|
|
1353
|
+
if (signalKey === AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY) {
|
|
1354
|
+
const noteworthyDefinition = signalDefinitions[AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY];
|
|
1355
|
+
signalDescriptions[signalKey] = ((_a = noteworthyDefinition == null ? void 0 : noteworthyDefinition.description) == null ? void 0 : _a.trim()) || AGENT_REPORTING_NOTEWORTHY_DESCRIPTION;
|
|
1356
|
+
signalSentiments[signalKey] = noteworthyDefinition == null ? void 0 : noteworthyDefinition.sentiment;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
const def = signalDefinitions[signalKey];
|
|
1360
|
+
if (!def) continue;
|
|
1361
|
+
signalDescriptions[signalKey] = def.description;
|
|
1362
|
+
signalSentiments[signalKey] = def.sentiment;
|
|
1363
|
+
}
|
|
1364
|
+
const customGuidanceText = ((_b = options.guidance) == null ? void 0 : _b.trim()) || "";
|
|
1365
|
+
const toolName = ((_c = options.toolName) == null ? void 0 : _c.trim()) || AGENT_REPORTING_TOOL_NAME_DEFAULT;
|
|
1366
|
+
const signalList = signalKeys.map((signalKey) => {
|
|
1367
|
+
const sentiment = signalSentiments[signalKey];
|
|
1368
|
+
const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
|
|
1369
|
+
return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
|
|
1370
|
+
}).join("\n");
|
|
1371
|
+
const guidanceBlock = customGuidanceText ? `
|
|
1372
|
+
Additional guidance: ${customGuidanceText}
|
|
1373
|
+
` : "";
|
|
1374
|
+
const toolDescription = `${AGENT_REPORTING_TOOL_PREAMBLE}
|
|
1375
|
+
|
|
1376
|
+
When to call:
|
|
1377
|
+
- The user reports something broken, failing, or not working as expected.
|
|
1378
|
+
- The user expresses frustration, anger, or threatens escalation.
|
|
1379
|
+
- You observe a product issue, billing problem, or data concern based on context.
|
|
1380
|
+
- The conversation reveals something unusual worth flagging for developer review.
|
|
1381
|
+
|
|
1382
|
+
Rules:
|
|
1383
|
+
1. Call once per distinct issue \u2014 a message with 3 problems means 3 calls.
|
|
1384
|
+
2. Pick the single best category per issue. Use noteworthy only when no specific category fits.
|
|
1385
|
+
3. Do not fabricate issues. Only report what is evident from the conversation.
|
|
1386
|
+
${guidanceBlock}
|
|
1387
|
+
Categories:
|
|
1388
|
+
${signalList}`;
|
|
1389
|
+
return {
|
|
1390
|
+
toolName,
|
|
1391
|
+
toolDescription,
|
|
1392
|
+
signalKeys,
|
|
1393
|
+
signalKeySet: new Set(signalKeys),
|
|
1394
|
+
signalDescriptions,
|
|
1395
|
+
signalSentiments
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
function resolveJsonSchemaFactory(aiSDK) {
|
|
1399
|
+
if (!isRecord(aiSDK) || !isFunction(aiSDK["jsonSchema"])) return void 0;
|
|
1400
|
+
return aiSDK["jsonSchema"];
|
|
1401
|
+
}
|
|
1402
|
+
function detectAISDKVersion(aiSDK) {
|
|
1403
|
+
if (!isRecord(aiSDK)) return "unknown";
|
|
1404
|
+
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
1405
|
+
if (isFunction(aiSDK["tool"])) return "5";
|
|
1406
|
+
return "4";
|
|
1407
|
+
}
|
|
1408
|
+
function asVercelSchema(jsonSchemaObj) {
|
|
1409
|
+
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
1410
|
+
const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1411
|
+
return {
|
|
1412
|
+
[schemaSymbol]: true,
|
|
1413
|
+
[validatorSymbol]: true,
|
|
1414
|
+
_type: void 0,
|
|
1415
|
+
jsonSchema: jsonSchemaObj,
|
|
1416
|
+
validate: (value) => ({ success: true, value })
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
function createSelfDiagnosticsTool(ctx) {
|
|
1420
|
+
const config = ctx.selfDiagnostics;
|
|
1421
|
+
if (!config) return void 0;
|
|
1422
|
+
const schema = {
|
|
1423
|
+
type: "object",
|
|
1424
|
+
additionalProperties: false,
|
|
1425
|
+
properties: {
|
|
1426
|
+
category: {
|
|
1427
|
+
type: "string",
|
|
1428
|
+
enum: config.signalKeys,
|
|
1429
|
+
description: "The single best-matching category from the list above."
|
|
1430
|
+
},
|
|
1431
|
+
detail: {
|
|
1432
|
+
type: "string",
|
|
1433
|
+
description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
|
|
1434
|
+
}
|
|
1435
|
+
},
|
|
1436
|
+
required: ["category", "detail"]
|
|
1437
|
+
};
|
|
1438
|
+
const parameters = asVercelSchema(schema);
|
|
1439
|
+
let inputSchema = parameters;
|
|
1440
|
+
if (ctx.jsonSchemaFactory) {
|
|
1441
|
+
try {
|
|
1442
|
+
inputSchema = ctx.jsonSchemaFactory(schema);
|
|
1443
|
+
} catch (e) {
|
|
1444
|
+
inputSchema = parameters;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
const execute = async (rawInput) => {
|
|
1448
|
+
var _a;
|
|
1449
|
+
const input = isRecord(rawInput) ? rawInput : void 0;
|
|
1450
|
+
const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
|
|
1451
|
+
const categoryCandidate = typeof (input == null ? void 0 : input["category"]) === "string" ? input["category"].trim() : void 0;
|
|
1452
|
+
const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
1453
|
+
const detail = typeof (input == null ? void 0 : input["detail"]) === "string" ? input["detail"].trim() : "";
|
|
1454
|
+
const signalDescription = config.signalDescriptions[category];
|
|
1455
|
+
const signalSentiment = config.signalSentiments[category];
|
|
1456
|
+
if (category === AGENT_REPORTING_NOTEWORTHY_SIGNAL_KEY) {
|
|
1457
|
+
void ctx.eventShipper.trackSignal({
|
|
1458
|
+
eventId: ctx.eventId,
|
|
1459
|
+
name: "agent:noteworthy",
|
|
1460
|
+
type: "agent_internal",
|
|
1461
|
+
properties: {
|
|
1462
|
+
source: "agent_flag_event_tool",
|
|
1463
|
+
reason: detail,
|
|
1464
|
+
severity: "medium",
|
|
1465
|
+
ai_sdk_version: ctx.aiSDKVersion
|
|
1466
|
+
}
|
|
1467
|
+
}).catch((err) => {
|
|
1468
|
+
if (ctx.debug) {
|
|
1469
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1470
|
+
console.warn(`[raindrop-ai/ai-sdk] agentFlagEvent signal dispatch failed: ${msg}`);
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
return { acknowledged: true, category };
|
|
1474
|
+
}
|
|
1475
|
+
void ctx.eventShipper.trackSignal({
|
|
1476
|
+
eventId: ctx.eventId,
|
|
1477
|
+
name: `agent:${category}`,
|
|
1478
|
+
type: "agent",
|
|
1479
|
+
sentiment: signalSentiment,
|
|
1480
|
+
properties: {
|
|
1481
|
+
source: "agent_reporting_tool",
|
|
1482
|
+
category,
|
|
1483
|
+
signal_description: signalDescription,
|
|
1484
|
+
ai_sdk_version: ctx.aiSDKVersion,
|
|
1485
|
+
...detail ? { detail } : {}
|
|
1486
|
+
}
|
|
1487
|
+
}).catch((err) => {
|
|
1488
|
+
if (ctx.debug) {
|
|
1489
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1490
|
+
console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${msg}`);
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
return { acknowledged: true, category };
|
|
1494
|
+
};
|
|
1495
|
+
return {
|
|
1496
|
+
description: config.toolDescription,
|
|
1497
|
+
execute,
|
|
1498
|
+
parameters,
|
|
1499
|
+
inputSchema
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1303
1502
|
function getCurrentParentSpanContextSync() {
|
|
1304
1503
|
return getContextManager().getParentSpanIds();
|
|
1305
1504
|
}
|
|
@@ -1429,7 +1628,18 @@ function teeStreamObjectBaseStream(result) {
|
|
|
1429
1628
|
}
|
|
1430
1629
|
function setupOperation(params) {
|
|
1431
1630
|
var _a, _b, _c;
|
|
1432
|
-
const {
|
|
1631
|
+
const {
|
|
1632
|
+
operation,
|
|
1633
|
+
arg,
|
|
1634
|
+
inherited,
|
|
1635
|
+
aiSDK,
|
|
1636
|
+
options,
|
|
1637
|
+
eventShipper,
|
|
1638
|
+
traceShipper,
|
|
1639
|
+
debug,
|
|
1640
|
+
selfDiagnostics,
|
|
1641
|
+
sendTraces
|
|
1642
|
+
} = params;
|
|
1433
1643
|
const wrapTimeCtx = resolveContext(options.context, { operation, args: arg });
|
|
1434
1644
|
const telemetry = extractExperimentalTelemetry(arg);
|
|
1435
1645
|
const callTimeCtx = extractRaindropMetadata(telemetry == null ? void 0 : telemetry.metadata);
|
|
@@ -1468,12 +1678,18 @@ function setupOperation(params) {
|
|
|
1468
1678
|
]
|
|
1469
1679
|
}) : void 0;
|
|
1470
1680
|
const rootParentForChildren = rootSpan ? { traceIdB64: rootSpan.ids.traceIdB64, spanIdB64: rootSpan.ids.spanIdB64 } : inheritedParent;
|
|
1681
|
+
const operationSelfDiagnostics = isObjectOperation(operation) ? void 0 : selfDiagnostics;
|
|
1471
1682
|
const wrapCtx = {
|
|
1472
1683
|
eventId,
|
|
1473
1684
|
telemetry,
|
|
1474
1685
|
sendTraces,
|
|
1686
|
+
debug,
|
|
1687
|
+
eventShipper,
|
|
1475
1688
|
traceShipper,
|
|
1476
|
-
rootParentForChildren
|
|
1689
|
+
rootParentForChildren,
|
|
1690
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
1691
|
+
selfDiagnostics: operationSelfDiagnostics,
|
|
1692
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
1477
1693
|
};
|
|
1478
1694
|
const toolCalls = [];
|
|
1479
1695
|
const argsWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
|
|
@@ -1543,12 +1759,7 @@ function createFinalize(params) {
|
|
|
1543
1759
|
attrInt("ai.usage.reasoningTokens", usage == null ? void 0 : usage.reasoningTokens),
|
|
1544
1760
|
attrInt("ai.usage.cachedInputTokens", usage == null ? void 0 : usage.cachedInputTokens),
|
|
1545
1761
|
attrInt("ai.toolCall.count", setup.toolCalls.length),
|
|
1546
|
-
...error ? [
|
|
1547
|
-
attrString(
|
|
1548
|
-
"error.message",
|
|
1549
|
-
error instanceof Error ? error.message : String(error)
|
|
1550
|
-
)
|
|
1551
|
-
] : []
|
|
1762
|
+
...error ? [attrString("error.message", error instanceof Error ? error.message : String(error))] : []
|
|
1552
1763
|
]
|
|
1553
1764
|
});
|
|
1554
1765
|
}
|
|
@@ -1583,6 +1794,7 @@ function executeStreamingOperation(params) {
|
|
|
1583
1794
|
deps,
|
|
1584
1795
|
sendEvents,
|
|
1585
1796
|
sendTraces,
|
|
1797
|
+
selfDiagnostics,
|
|
1586
1798
|
autoAttachmentEnabled,
|
|
1587
1799
|
debug
|
|
1588
1800
|
} = params;
|
|
@@ -1592,7 +1804,10 @@ function executeStreamingOperation(params) {
|
|
|
1592
1804
|
inherited: getCurrentParentSpanContextSync(),
|
|
1593
1805
|
aiSDK,
|
|
1594
1806
|
options: deps.options,
|
|
1807
|
+
eventShipper: deps.eventShipper,
|
|
1595
1808
|
traceShipper: deps.traceShipper,
|
|
1809
|
+
debug,
|
|
1810
|
+
selfDiagnostics,
|
|
1596
1811
|
sendTraces
|
|
1597
1812
|
});
|
|
1598
1813
|
const finalize = createFinalize({
|
|
@@ -1637,6 +1852,7 @@ async function executeNonStreamingOperation(params) {
|
|
|
1637
1852
|
deps,
|
|
1638
1853
|
sendEvents,
|
|
1639
1854
|
sendTraces,
|
|
1855
|
+
selfDiagnostics,
|
|
1640
1856
|
autoAttachmentEnabled,
|
|
1641
1857
|
debug
|
|
1642
1858
|
} = params;
|
|
@@ -1647,7 +1863,10 @@ async function executeNonStreamingOperation(params) {
|
|
|
1647
1863
|
inherited,
|
|
1648
1864
|
aiSDK,
|
|
1649
1865
|
options: deps.options,
|
|
1866
|
+
eventShipper: deps.eventShipper,
|
|
1650
1867
|
traceShipper: deps.traceShipper,
|
|
1868
|
+
debug,
|
|
1869
|
+
selfDiagnostics,
|
|
1651
1870
|
sendTraces
|
|
1652
1871
|
});
|
|
1653
1872
|
const finalize = createFinalize({
|
|
@@ -1690,13 +1909,14 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1690
1909
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1691
1910
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
1692
1911
|
const autoAttachmentEnabled = deps.options.autoAttachment !== false;
|
|
1912
|
+
const selfDiagnostics = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
1693
1913
|
const proxyTarget = isModuleNamespace(aiSDK) ? Object.setPrototypeOf({}, aiSDK) : aiSDK;
|
|
1694
1914
|
return new Proxy(proxyTarget, {
|
|
1695
1915
|
get(target, prop, receiver) {
|
|
1696
1916
|
const original = Reflect.get(target, prop, receiver);
|
|
1697
1917
|
if (typeof prop === "string" && agentClasses.has(prop) && isAgentClass(original)) {
|
|
1698
1918
|
if (debug) console.log(`[raindrop-ai/ai-sdk] Wrapping Agent class: ${prop}`);
|
|
1699
|
-
return wrapAgentClass(original, aiSDK, deps, debug);
|
|
1919
|
+
return wrapAgentClass(original, aiSDK, deps, debug, selfDiagnostics);
|
|
1700
1920
|
}
|
|
1701
1921
|
if (typeof prop !== "string" || !instrumentedOps.has(prop) || !isFunction(original)) {
|
|
1702
1922
|
return original;
|
|
@@ -1714,6 +1934,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1714
1934
|
deps,
|
|
1715
1935
|
sendEvents,
|
|
1716
1936
|
sendTraces,
|
|
1937
|
+
selfDiagnostics,
|
|
1717
1938
|
autoAttachmentEnabled,
|
|
1718
1939
|
debug
|
|
1719
1940
|
});
|
|
@@ -1727,6 +1948,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1727
1948
|
deps,
|
|
1728
1949
|
sendEvents,
|
|
1729
1950
|
sendTraces,
|
|
1951
|
+
selfDiagnostics,
|
|
1730
1952
|
autoAttachmentEnabled,
|
|
1731
1953
|
debug
|
|
1732
1954
|
});
|
|
@@ -1734,7 +1956,7 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
1734
1956
|
}
|
|
1735
1957
|
});
|
|
1736
1958
|
}
|
|
1737
|
-
function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
1959
|
+
function wrapAgentClass(AgentClass, aiSDK, deps, debug, selfDiagnostics) {
|
|
1738
1960
|
return new Proxy(AgentClass, {
|
|
1739
1961
|
construct(target, args, newTarget) {
|
|
1740
1962
|
const instance = Reflect.construct(target, args, newTarget);
|
|
@@ -1753,7 +1975,8 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1753
1975
|
className,
|
|
1754
1976
|
aiSDK,
|
|
1755
1977
|
deps,
|
|
1756
|
-
debug
|
|
1978
|
+
debug,
|
|
1979
|
+
selfDiagnostics
|
|
1757
1980
|
);
|
|
1758
1981
|
}
|
|
1759
1982
|
if (prop === "stream" && isFunction(original)) {
|
|
@@ -1765,7 +1988,8 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1765
1988
|
className,
|
|
1766
1989
|
aiSDK,
|
|
1767
1990
|
deps,
|
|
1768
|
-
debug
|
|
1991
|
+
debug,
|
|
1992
|
+
selfDiagnostics
|
|
1769
1993
|
);
|
|
1770
1994
|
}
|
|
1771
1995
|
return original;
|
|
@@ -1774,7 +1998,7 @@ function wrapAgentClass(AgentClass, aiSDK, deps, debug) {
|
|
|
1774
1998
|
}
|
|
1775
1999
|
});
|
|
1776
2000
|
}
|
|
1777
|
-
function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK, deps, debug) {
|
|
2001
|
+
function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK, deps, debug, selfDiagnostics) {
|
|
1778
2002
|
var _a, _b;
|
|
1779
2003
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1780
2004
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
@@ -1827,8 +2051,13 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1827
2051
|
eventId,
|
|
1828
2052
|
telemetry,
|
|
1829
2053
|
sendTraces,
|
|
2054
|
+
debug,
|
|
2055
|
+
eventShipper: deps.eventShipper,
|
|
1830
2056
|
traceShipper: deps.traceShipper,
|
|
1831
|
-
rootParentForChildren
|
|
2057
|
+
rootParentForChildren,
|
|
2058
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
2059
|
+
selfDiagnostics,
|
|
2060
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
1832
2061
|
};
|
|
1833
2062
|
const toolCalls = [];
|
|
1834
2063
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -1962,7 +2191,7 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
1962
2191
|
}
|
|
1963
2192
|
};
|
|
1964
2193
|
}
|
|
1965
|
-
function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps, debug) {
|
|
2194
|
+
function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps, debug, selfDiagnostics) {
|
|
1966
2195
|
var _a, _b;
|
|
1967
2196
|
const sendEvents = ((_a = deps.options.send) == null ? void 0 : _a.events) !== false;
|
|
1968
2197
|
const sendTraces = ((_b = deps.options.send) == null ? void 0 : _b.traces) !== false;
|
|
@@ -2015,8 +2244,13 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
2015
2244
|
eventId,
|
|
2016
2245
|
telemetry,
|
|
2017
2246
|
sendTraces,
|
|
2247
|
+
debug,
|
|
2248
|
+
eventShipper: deps.eventShipper,
|
|
2018
2249
|
traceShipper: deps.traceShipper,
|
|
2019
|
-
rootParentForChildren
|
|
2250
|
+
rootParentForChildren,
|
|
2251
|
+
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
2252
|
+
selfDiagnostics,
|
|
2253
|
+
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
2020
2254
|
};
|
|
2021
2255
|
const toolCalls = [];
|
|
2022
2256
|
const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
|
|
@@ -2156,8 +2390,22 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
2156
2390
|
};
|
|
2157
2391
|
}
|
|
2158
2392
|
function wrapTools(args, ctx, toolCalls) {
|
|
2159
|
-
if (!isRecord(args)
|
|
2160
|
-
const tools = args["tools"];
|
|
2393
|
+
if (!isRecord(args)) return args;
|
|
2394
|
+
const tools = isRecord(args["tools"]) ? { ...args["tools"] } : {};
|
|
2395
|
+
if (ctx.selfDiagnostics) {
|
|
2396
|
+
const reportToolName = ctx.selfDiagnostics.toolName;
|
|
2397
|
+
if (!(reportToolName in tools)) {
|
|
2398
|
+
const reportTool = createSelfDiagnosticsTool(ctx);
|
|
2399
|
+
if (reportTool !== void 0) {
|
|
2400
|
+
tools[reportToolName] = reportTool;
|
|
2401
|
+
}
|
|
2402
|
+
} else if (ctx.debug) {
|
|
2403
|
+
console.warn(
|
|
2404
|
+
`[raindrop-ai/ai-sdk] selfDiagnostics skipped: tool name collision for "${reportToolName}"`
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
if (Object.keys(tools).length === 0) return args;
|
|
2161
2409
|
const wrapped = {};
|
|
2162
2410
|
for (const [name, tool] of Object.entries(tools)) {
|
|
2163
2411
|
wrapped[name] = wrapToolExecute(name, tool, ctx, toolCalls);
|
package/dist/index.d.mts
CHANGED
|
@@ -238,6 +238,38 @@ type AISDKMessage = {
|
|
|
238
238
|
* - at the end with appended response messages (assistant/tool, incl tool-call + tool-result parts)
|
|
239
239
|
*/
|
|
240
240
|
type EventBuilder = (messages: AISDKMessage[]) => void | BuildEventPatch;
|
|
241
|
+
type SelfDiagnosticsSignalDefinition = {
|
|
242
|
+
/**
|
|
243
|
+
* Human-readable meaning of this signal.
|
|
244
|
+
* Used in the injected tool schema and stored in signal properties.
|
|
245
|
+
*/
|
|
246
|
+
description: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional default sentiment for this signal key.
|
|
249
|
+
* This can help dashboards classify negative/positive programmatic signals.
|
|
250
|
+
*/
|
|
251
|
+
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
252
|
+
};
|
|
253
|
+
type SelfDiagnosticsSignalDefinitions = Record<string, SelfDiagnosticsSignalDefinition>;
|
|
254
|
+
type SelfDiagnosticsOptions = {
|
|
255
|
+
/** Enable automatic injection of the self diagnostics tool. Default: false */
|
|
256
|
+
enabled?: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Signal keys and descriptions exposed to the model.
|
|
259
|
+
* Defaults to a built-in set when omitted.
|
|
260
|
+
*/
|
|
261
|
+
signals?: SelfDiagnosticsSignalDefinitions;
|
|
262
|
+
/**
|
|
263
|
+
* Optional extra guidance for when the model should emit self diagnostics.
|
|
264
|
+
* The SDK still generates a full tool prompt from `signals`.
|
|
265
|
+
*/
|
|
266
|
+
guidance?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Optional tool name override for the injected self diagnostics tool.
|
|
269
|
+
* Defaults to "__raindrop_report".
|
|
270
|
+
*/
|
|
271
|
+
toolName?: string;
|
|
272
|
+
};
|
|
241
273
|
type WrapAISDKOptions = {
|
|
242
274
|
context: RaindropAISDKContext | ((info: {
|
|
243
275
|
operation: string;
|
|
@@ -245,6 +277,7 @@ type WrapAISDKOptions = {
|
|
|
245
277
|
}) => RaindropAISDKContext);
|
|
246
278
|
buildEvent?: EventBuilder;
|
|
247
279
|
autoAttachment?: boolean;
|
|
280
|
+
selfDiagnostics?: SelfDiagnosticsOptions;
|
|
248
281
|
send?: {
|
|
249
282
|
events?: boolean;
|
|
250
283
|
traces?: boolean;
|
|
@@ -281,7 +314,7 @@ type RaindropAISDKClient = {
|
|
|
281
314
|
track(signal: {
|
|
282
315
|
eventId: string;
|
|
283
316
|
name: "thumbs_up" | "thumbs_down" | string;
|
|
284
|
-
type?: "default" | "feedback" | "edit";
|
|
317
|
+
type?: "default" | "feedback" | "edit" | "standard" | "agent" | "agent_internal";
|
|
285
318
|
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
286
319
|
timestamp?: string;
|
|
287
320
|
properties?: Record<string, unknown>;
|
|
@@ -295,4 +328,4 @@ type RaindropAISDKClient = {
|
|
|
295
328
|
};
|
|
296
329
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
297
330
|
|
|
298
|
-
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
|
331
|
+
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type SelfDiagnosticsOptions, type SelfDiagnosticsSignalDefinition, type SelfDiagnosticsSignalDefinitions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
package/dist/index.d.ts
CHANGED
|
@@ -238,6 +238,38 @@ type AISDKMessage = {
|
|
|
238
238
|
* - at the end with appended response messages (assistant/tool, incl tool-call + tool-result parts)
|
|
239
239
|
*/
|
|
240
240
|
type EventBuilder = (messages: AISDKMessage[]) => void | BuildEventPatch;
|
|
241
|
+
type SelfDiagnosticsSignalDefinition = {
|
|
242
|
+
/**
|
|
243
|
+
* Human-readable meaning of this signal.
|
|
244
|
+
* Used in the injected tool schema and stored in signal properties.
|
|
245
|
+
*/
|
|
246
|
+
description: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional default sentiment for this signal key.
|
|
249
|
+
* This can help dashboards classify negative/positive programmatic signals.
|
|
250
|
+
*/
|
|
251
|
+
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
252
|
+
};
|
|
253
|
+
type SelfDiagnosticsSignalDefinitions = Record<string, SelfDiagnosticsSignalDefinition>;
|
|
254
|
+
type SelfDiagnosticsOptions = {
|
|
255
|
+
/** Enable automatic injection of the self diagnostics tool. Default: false */
|
|
256
|
+
enabled?: boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Signal keys and descriptions exposed to the model.
|
|
259
|
+
* Defaults to a built-in set when omitted.
|
|
260
|
+
*/
|
|
261
|
+
signals?: SelfDiagnosticsSignalDefinitions;
|
|
262
|
+
/**
|
|
263
|
+
* Optional extra guidance for when the model should emit self diagnostics.
|
|
264
|
+
* The SDK still generates a full tool prompt from `signals`.
|
|
265
|
+
*/
|
|
266
|
+
guidance?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Optional tool name override for the injected self diagnostics tool.
|
|
269
|
+
* Defaults to "__raindrop_report".
|
|
270
|
+
*/
|
|
271
|
+
toolName?: string;
|
|
272
|
+
};
|
|
241
273
|
type WrapAISDKOptions = {
|
|
242
274
|
context: RaindropAISDKContext | ((info: {
|
|
243
275
|
operation: string;
|
|
@@ -245,6 +277,7 @@ type WrapAISDKOptions = {
|
|
|
245
277
|
}) => RaindropAISDKContext);
|
|
246
278
|
buildEvent?: EventBuilder;
|
|
247
279
|
autoAttachment?: boolean;
|
|
280
|
+
selfDiagnostics?: SelfDiagnosticsOptions;
|
|
248
281
|
send?: {
|
|
249
282
|
events?: boolean;
|
|
250
283
|
traces?: boolean;
|
|
@@ -281,7 +314,7 @@ type RaindropAISDKClient = {
|
|
|
281
314
|
track(signal: {
|
|
282
315
|
eventId: string;
|
|
283
316
|
name: "thumbs_up" | "thumbs_down" | string;
|
|
284
|
-
type?: "default" | "feedback" | "edit";
|
|
317
|
+
type?: "default" | "feedback" | "edit" | "standard" | "agent" | "agent_internal";
|
|
285
318
|
sentiment?: "POSITIVE" | "NEGATIVE";
|
|
286
319
|
timestamp?: string;
|
|
287
320
|
properties?: Record<string, unknown>;
|
|
@@ -295,4 +328,4 @@ type RaindropAISDKClient = {
|
|
|
295
328
|
};
|
|
296
329
|
declare function createRaindropAISDK(opts: RaindropAISDKOptions): RaindropAISDKClient;
|
|
297
330
|
|
|
298
|
-
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|
|
331
|
+
export { type AISDKMessage, type AgentCallMetadata, type AgentWithMetadata, type Attachment, type BuildEventPatch, ContextManager, type ContextSpan, type EventBuilder, type EventMetadataOptions, type IdentifyInput, type RaindropAISDKClient, type RaindropAISDKContext, type RaindropAISDKOptions, type SelfDiagnosticsOptions, type SelfDiagnosticsSignalDefinition, type SelfDiagnosticsSignalDefinitions, type WrapAISDKOptions, type WrappedAI, type WrappedAISDK, _resetWarnedMissingUserId, createRaindropAISDK, currentSpan, eventMetadata, getContextManager, withCurrent };
|