@raindrop-ai/ai-sdk 0.0.31 → 0.0.32
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/README.md +37 -0
- package/dist/{chunk-7VSCLQIX.mjs → chunk-YDMJ6ABM.mjs} +263 -164
- package/dist/{index-IMe7ZUXV.d.mts → index-CwK0GdEe.d.mts} +42 -1
- package/dist/{index-IMe7ZUXV.d.ts → index-CwK0GdEe.d.ts} +42 -1
- package/dist/index.browser.d.mts +42 -1
- package/dist/index.browser.d.ts +42 -1
- package/dist/index.browser.js +276 -177
- package/dist/index.browser.mjs +276 -177
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +276 -177
- 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 +276 -177
- package/dist/index.workers.mjs +1 -1
- package/package.json +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -1019,7 +1019,7 @@ async function* asyncGeneratorWithCurrent(span, gen) {
|
|
|
1019
1019
|
// package.json
|
|
1020
1020
|
var package_default = {
|
|
1021
1021
|
name: "@raindrop-ai/ai-sdk",
|
|
1022
|
-
version: "0.0.
|
|
1022
|
+
version: "0.0.32"};
|
|
1023
1023
|
|
|
1024
1024
|
// src/internal/version.ts
|
|
1025
1025
|
var libraryName = package_default.name;
|
|
@@ -2086,6 +2086,7 @@ var RaindropTelemetryIntegration = class {
|
|
|
2086
2086
|
attrInt("gen_ai.usage.output_tokens", usage.outputTokens)
|
|
2087
2087
|
);
|
|
2088
2088
|
}
|
|
2089
|
+
this.emitProviderExecutedToolSpans(event, state);
|
|
2089
2090
|
this.traceShipper.endSpan(state.stepSpan, { attributes: outputAttrs });
|
|
2090
2091
|
state.stepSpan = void 0;
|
|
2091
2092
|
state.stepParent = void 0;
|
|
@@ -2362,6 +2363,74 @@ var RaindropTelemetryIntegration = class {
|
|
|
2362
2363
|
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
2363
2364
|
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
2364
2365
|
}
|
|
2366
|
+
// ── provider-executed tool calls ─────────────────────────────────────────
|
|
2367
|
+
//
|
|
2368
|
+
// Provider-executed (server-side) tools — e.g. Anthropic's hosted
|
|
2369
|
+
// `web_search` (`anthropic.web_search_20250305`) — are run by the provider,
|
|
2370
|
+
// not by the AI SDK. They therefore never flow through the client
|
|
2371
|
+
// `onToolExecutionStart`/`onToolExecutionEnd` callbacks that emit our
|
|
2372
|
+
// `ai.toolCall` spans; the SDK only surfaces them as `tool-call` /
|
|
2373
|
+
// `tool-result` content parts on the step (carrying `providerExecuted: true`).
|
|
2374
|
+
// Without this, such calls are invisible in every trace backend.
|
|
2375
|
+
//
|
|
2376
|
+
// At step finish we synthesize the same `ai.toolCall` span shape we emit for
|
|
2377
|
+
// client tools (name `ai.toolCall`, `operationId: "ai.toolCall"`, attrs
|
|
2378
|
+
// `ai.toolCall.name`/`id`/`args`/`result`), parented under the step span, so
|
|
2379
|
+
// downstream ingestion maps them to a tool span with no special-casing.
|
|
2380
|
+
//
|
|
2381
|
+
// Client-executed tools are excluded (`providerExecuted` falsy) — they were
|
|
2382
|
+
// already spanned during execution, so this never double-emits.
|
|
2383
|
+
emitProviderExecutedToolSpans(event, state) {
|
|
2384
|
+
if (!state.stepParent) return;
|
|
2385
|
+
const content = Array.isArray(event.content) ? event.content : [];
|
|
2386
|
+
const providerToolCalls = content.filter(
|
|
2387
|
+
(part) => (part == null ? void 0 : part.type) === "tool-call" && part.providerExecuted === true
|
|
2388
|
+
);
|
|
2389
|
+
if (providerToolCalls.length === 0) return;
|
|
2390
|
+
const resultsByCallId = /* @__PURE__ */ new Map();
|
|
2391
|
+
for (const part of content) {
|
|
2392
|
+
if (((part == null ? void 0 : part.type) === "tool-result" || (part == null ? void 0 : part.type) === "tool-error") && typeof part.toolCallId === "string") {
|
|
2393
|
+
resultsByCallId.set(part.toolCallId, part);
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
for (const call of providerToolCalls) {
|
|
2397
|
+
const { operationName, resourceName } = opName(
|
|
2398
|
+
"ai.toolCall",
|
|
2399
|
+
state.functionId
|
|
2400
|
+
);
|
|
2401
|
+
const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(call.input))] : [];
|
|
2402
|
+
const toolSpan = this.traceShipper.startSpan({
|
|
2403
|
+
name: "ai.toolCall",
|
|
2404
|
+
parent: state.stepParent,
|
|
2405
|
+
eventId: state.eventId,
|
|
2406
|
+
operationId: "ai.toolCall",
|
|
2407
|
+
attributes: [
|
|
2408
|
+
attrString("operation.name", operationName),
|
|
2409
|
+
attrString("resource.name", resourceName),
|
|
2410
|
+
attrString("ai.telemetry.functionId", state.functionId),
|
|
2411
|
+
attrString("ai.toolCall.name", call.toolName),
|
|
2412
|
+
attrString("ai.toolCall.id", call.toolCallId),
|
|
2413
|
+
attrString("ai.toolCall.providerExecuted", "true"),
|
|
2414
|
+
...inputAttrs
|
|
2415
|
+
]
|
|
2416
|
+
});
|
|
2417
|
+
state.toolCallCount += 1;
|
|
2418
|
+
this.emitLive(state, "tool_start", call.toolName, { args: call.input });
|
|
2419
|
+
const resultPart = resultsByCallId.get(call.toolCallId);
|
|
2420
|
+
if ((resultPart == null ? void 0 : resultPart.type) === "tool-error") {
|
|
2421
|
+
this.traceShipper.endSpan(toolSpan, { error: resultPart.error });
|
|
2422
|
+
} else {
|
|
2423
|
+
const outputAttrs = state.recordOutputs && resultPart && "output" in resultPart ? [
|
|
2424
|
+
attrString(
|
|
2425
|
+
"ai.toolCall.result",
|
|
2426
|
+
safeJsonWithUint8(resultPart.output)
|
|
2427
|
+
)
|
|
2428
|
+
] : [];
|
|
2429
|
+
this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
|
|
2430
|
+
}
|
|
2431
|
+
this.emitLive(state, "tool_result", call.toolName);
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2365
2434
|
finishGenerate(event, state) {
|
|
2366
2435
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2367
2436
|
if (state.rootSpan) {
|
|
@@ -2467,22 +2536,9 @@ var RaindropTelemetryIntegration = class {
|
|
|
2467
2536
|
}
|
|
2468
2537
|
};
|
|
2469
2538
|
|
|
2470
|
-
// src/internal/
|
|
2471
|
-
var
|
|
2472
|
-
|
|
2473
|
-
var _a, _b, _c;
|
|
2474
|
-
super({
|
|
2475
|
-
...opts,
|
|
2476
|
-
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
2477
|
-
serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
|
|
2478
|
-
serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
|
|
2479
|
-
});
|
|
2480
|
-
}
|
|
2481
|
-
};
|
|
2482
|
-
|
|
2483
|
-
// src/internal/wrap/wrapAISDK.ts
|
|
2484
|
-
var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
2485
|
-
var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
2539
|
+
// src/internal/self-diagnostics.ts
|
|
2540
|
+
var SELF_DIAGNOSTICS_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
2541
|
+
var SELF_DIAGNOSTICS_SIGNALS_DEFAULT = {
|
|
2486
2542
|
missing_context: {
|
|
2487
2543
|
description: "You cannot complete the task because critical information, credentials, or access is missing and the user cannot provide it. Do NOT report this for normal clarifying questions \u2014 only when you are blocked.",
|
|
2488
2544
|
sentiment: "NEGATIVE"
|
|
@@ -2500,7 +2556,194 @@ var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
|
2500
2556
|
sentiment: "NEGATIVE"
|
|
2501
2557
|
}
|
|
2502
2558
|
};
|
|
2503
|
-
var
|
|
2559
|
+
var SELF_DIAGNOSTICS_TOOL_PREAMBLE = "You have a diagnostic tool for flagging serious failures for developer review. Only call this when you hit a significant, unrecoverable problem \u2014 not for minor hiccups or routine clarifications. If you can still help the user, do that instead of calling this tool. This tool is invisible to the user \u2014 never mention it or its output.";
|
|
2560
|
+
function normalizeString(value) {
|
|
2561
|
+
if (typeof value !== "string") return void 0;
|
|
2562
|
+
const trimmed = value.trim();
|
|
2563
|
+
return trimmed || void 0;
|
|
2564
|
+
}
|
|
2565
|
+
function normalizeSelfDiagnosticsSignals(signals) {
|
|
2566
|
+
if (!signals) return SELF_DIAGNOSTICS_SIGNALS_DEFAULT;
|
|
2567
|
+
const normalizedEntries = Object.entries(signals).map(([key, value]) => {
|
|
2568
|
+
var _a;
|
|
2569
|
+
const signalKey = key.trim();
|
|
2570
|
+
if (!signalKey || !value || typeof value !== "object") return void 0;
|
|
2571
|
+
const description = (_a = value.description) == null ? void 0 : _a.trim();
|
|
2572
|
+
if (!description) return void 0;
|
|
2573
|
+
const sentiment = value.sentiment;
|
|
2574
|
+
return [
|
|
2575
|
+
signalKey,
|
|
2576
|
+
{
|
|
2577
|
+
description,
|
|
2578
|
+
...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
|
|
2579
|
+
}
|
|
2580
|
+
];
|
|
2581
|
+
}).filter(
|
|
2582
|
+
(entry) => entry !== void 0
|
|
2583
|
+
);
|
|
2584
|
+
if (normalizedEntries.length === 0) return SELF_DIAGNOSTICS_SIGNALS_DEFAULT;
|
|
2585
|
+
return Object.fromEntries(normalizedEntries);
|
|
2586
|
+
}
|
|
2587
|
+
function resolveSelfDiagnosticsConfig(options) {
|
|
2588
|
+
var _a, _b;
|
|
2589
|
+
const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
|
|
2590
|
+
const signalKeys = Object.keys(signalDefinitions);
|
|
2591
|
+
const signalDescriptions = {};
|
|
2592
|
+
const signalSentiments = {};
|
|
2593
|
+
for (const signalKey of signalKeys) {
|
|
2594
|
+
const definition = signalDefinitions[signalKey];
|
|
2595
|
+
if (!definition) continue;
|
|
2596
|
+
signalDescriptions[signalKey] = definition.description;
|
|
2597
|
+
signalSentiments[signalKey] = definition.sentiment;
|
|
2598
|
+
}
|
|
2599
|
+
const customGuidance = ((_a = options.guidance) == null ? void 0 : _a.trim()) || "";
|
|
2600
|
+
const toolName = ((_b = options.toolName) == null ? void 0 : _b.trim()) || SELF_DIAGNOSTICS_TOOL_NAME_DEFAULT;
|
|
2601
|
+
const signalList = signalKeys.map((signalKey) => {
|
|
2602
|
+
const sentiment = signalSentiments[signalKey];
|
|
2603
|
+
const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
|
|
2604
|
+
return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
|
|
2605
|
+
}).join("\n");
|
|
2606
|
+
const guidanceBlock = customGuidance ? `
|
|
2607
|
+
Additional guidance: ${customGuidance}
|
|
2608
|
+
` : "";
|
|
2609
|
+
const toolDescription = `${SELF_DIAGNOSTICS_TOOL_PREAMBLE}
|
|
2610
|
+
|
|
2611
|
+
When to call:
|
|
2612
|
+
- You are blocked from completing the task due to missing information or access that the user cannot provide.
|
|
2613
|
+
- A tool is persistently failing across multiple attempts, not just a single transient error.
|
|
2614
|
+
- The task requires a tool, permission, or capability you do not have.
|
|
2615
|
+
- You genuinely cannot deliver what the user asked for despite trying.
|
|
2616
|
+
|
|
2617
|
+
When NOT to call:
|
|
2618
|
+
- Normal clarifying questions or back-and-forth with the user.
|
|
2619
|
+
- A single tool error that you can recover from or retry.
|
|
2620
|
+
- You successfully completed the task, even if it was difficult.
|
|
2621
|
+
- Policy refusals or content filtering \u2014 those are working as intended.
|
|
2622
|
+
|
|
2623
|
+
Rules:
|
|
2624
|
+
1. Pick the single best category.
|
|
2625
|
+
2. Do not fabricate issues. Only report what is evident from the conversation.
|
|
2626
|
+
3. Err on the side of NOT calling this tool. When in doubt, help the user instead.
|
|
2627
|
+
${guidanceBlock}
|
|
2628
|
+
Categories:
|
|
2629
|
+
` + signalList;
|
|
2630
|
+
return {
|
|
2631
|
+
toolName,
|
|
2632
|
+
toolDescription,
|
|
2633
|
+
signalKeys,
|
|
2634
|
+
signalKeySet: new Set(signalKeys),
|
|
2635
|
+
signalDescriptions,
|
|
2636
|
+
signalSentiments
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
function normalizeSelfDiagnosticsConfig(options) {
|
|
2640
|
+
if (!(options == null ? void 0 : options.enabled)) return void 0;
|
|
2641
|
+
return resolveSelfDiagnosticsConfig(options);
|
|
2642
|
+
}
|
|
2643
|
+
function asVercelSchema(inputSchema) {
|
|
2644
|
+
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
2645
|
+
const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2646
|
+
return {
|
|
2647
|
+
[schemaSymbol]: true,
|
|
2648
|
+
[validatorSymbol]: true,
|
|
2649
|
+
_type: void 0,
|
|
2650
|
+
jsonSchema: inputSchema,
|
|
2651
|
+
validate: (value) => ({ success: true, value })
|
|
2652
|
+
};
|
|
2653
|
+
}
|
|
2654
|
+
function resolveStandaloneEventId(options) {
|
|
2655
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2656
|
+
return (_f = (_d = (_b = normalizeString((_a = options.getEventId) == null ? void 0 : _a.call(options))) != null ? _b : normalizeString(options.eventId)) != null ? _d : normalizeString((_c = getContextManager().getParentSpanIds()) == null ? void 0 : _c.eventId)) != null ? _f : normalizeString((_e = getCurrentRaindropCallMetadata()) == null ? void 0 : _e.eventId);
|
|
2657
|
+
}
|
|
2658
|
+
function createSelfDiagnosticsToolDefinition(args) {
|
|
2659
|
+
const { config, eventShipper, getEventId, aiSDKVersion, debug } = args;
|
|
2660
|
+
const inputJsonSchema = {
|
|
2661
|
+
type: "object",
|
|
2662
|
+
additionalProperties: false,
|
|
2663
|
+
properties: {
|
|
2664
|
+
category: {
|
|
2665
|
+
type: "string",
|
|
2666
|
+
enum: config.signalKeys,
|
|
2667
|
+
description: "The single best-matching category from the list above."
|
|
2668
|
+
},
|
|
2669
|
+
detail: {
|
|
2670
|
+
type: "string",
|
|
2671
|
+
description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
|
|
2672
|
+
}
|
|
2673
|
+
},
|
|
2674
|
+
required: ["category", "detail"]
|
|
2675
|
+
};
|
|
2676
|
+
const inputSchema = asVercelSchema(inputJsonSchema);
|
|
2677
|
+
const execute = async (rawInput) => {
|
|
2678
|
+
var _a, _b;
|
|
2679
|
+
const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
|
|
2680
|
+
const categoryCandidate = normalizeString(rawInput == null ? void 0 : rawInput.category);
|
|
2681
|
+
const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
2682
|
+
const detail = normalizeString(rawInput == null ? void 0 : rawInput.detail);
|
|
2683
|
+
const eventId = getEventId();
|
|
2684
|
+
if (!eventId) {
|
|
2685
|
+
const message = "self diagnostics signal skipped: missing eventId. Pass eventId or getEventId when creating the tool.";
|
|
2686
|
+
if (args.onMissingEventId === "throw") {
|
|
2687
|
+
throw new Error(`[raindrop-ai/ai-sdk] ${message}`);
|
|
2688
|
+
}
|
|
2689
|
+
if (((_b = args.onMissingEventId) != null ? _b : "warn") === "warn") {
|
|
2690
|
+
console.warn(`[raindrop-ai/ai-sdk] ${message}`);
|
|
2691
|
+
}
|
|
2692
|
+
return { acknowledged: false, category, reason: "missing_event_id" };
|
|
2693
|
+
}
|
|
2694
|
+
void eventShipper.trackSignal({
|
|
2695
|
+
eventId,
|
|
2696
|
+
name: `self diagnostics - ${category}`,
|
|
2697
|
+
type: "agent",
|
|
2698
|
+
sentiment: config.signalSentiments[category],
|
|
2699
|
+
properties: {
|
|
2700
|
+
source: "agent_reporting_tool",
|
|
2701
|
+
category,
|
|
2702
|
+
signal_description: config.signalDescriptions[category],
|
|
2703
|
+
...aiSDKVersion ? { ai_sdk_version: aiSDKVersion } : {},
|
|
2704
|
+
...detail ? { detail } : {}
|
|
2705
|
+
}
|
|
2706
|
+
}).catch((error) => {
|
|
2707
|
+
if (debug) {
|
|
2708
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2709
|
+
console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${message}`);
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
return { acknowledged: true, category };
|
|
2713
|
+
};
|
|
2714
|
+
return {
|
|
2715
|
+
name: config.toolName,
|
|
2716
|
+
description: config.toolDescription,
|
|
2717
|
+
parameters: inputSchema,
|
|
2718
|
+
inputSchema,
|
|
2719
|
+
execute
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
function createStandaloneSelfDiagnosticsTool(args) {
|
|
2723
|
+
const config = resolveSelfDiagnosticsConfig(args.options);
|
|
2724
|
+
return createSelfDiagnosticsToolDefinition({
|
|
2725
|
+
config,
|
|
2726
|
+
eventShipper: args.eventShipper,
|
|
2727
|
+
getEventId: () => resolveStandaloneEventId(args.options),
|
|
2728
|
+
onMissingEventId: args.options.onMissingEventId,
|
|
2729
|
+
debug: args.debug
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
// src/internal/traces.ts
|
|
2734
|
+
var TraceShipper2 = class extends TraceShipper {
|
|
2735
|
+
constructor(opts) {
|
|
2736
|
+
var _a, _b, _c;
|
|
2737
|
+
super({
|
|
2738
|
+
...opts,
|
|
2739
|
+
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
2740
|
+
serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
|
|
2741
|
+
serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
};
|
|
2745
|
+
|
|
2746
|
+
// src/internal/wrap/wrapAISDK.ts
|
|
2504
2747
|
var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
|
|
2505
2748
|
var PendingToolSpanStore = class _PendingToolSpanStore {
|
|
2506
2749
|
constructor() {
|
|
@@ -2604,85 +2847,6 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
2604
2847
|
}
|
|
2605
2848
|
return result;
|
|
2606
2849
|
}
|
|
2607
|
-
function normalizeSelfDiagnosticsSignals(signals) {
|
|
2608
|
-
if (!signals) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
2609
|
-
const normalizedEntries = Object.entries(signals).map(([key, value]) => {
|
|
2610
|
-
var _a;
|
|
2611
|
-
const signalKey = key.trim();
|
|
2612
|
-
if (!signalKey || !value || typeof value !== "object") return void 0;
|
|
2613
|
-
const description = (_a = value.description) == null ? void 0 : _a.trim();
|
|
2614
|
-
if (!description) return void 0;
|
|
2615
|
-
const sentiment = value.sentiment;
|
|
2616
|
-
return [
|
|
2617
|
-
signalKey,
|
|
2618
|
-
{
|
|
2619
|
-
description,
|
|
2620
|
-
...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
|
|
2621
|
-
}
|
|
2622
|
-
];
|
|
2623
|
-
}).filter(
|
|
2624
|
-
(entry) => entry !== void 0
|
|
2625
|
-
);
|
|
2626
|
-
if (normalizedEntries.length === 0) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
2627
|
-
return Object.fromEntries(normalizedEntries);
|
|
2628
|
-
}
|
|
2629
|
-
function normalizeSelfDiagnosticsConfig(options) {
|
|
2630
|
-
var _a, _b;
|
|
2631
|
-
if (!(options == null ? void 0 : options.enabled)) return void 0;
|
|
2632
|
-
const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
|
|
2633
|
-
const signalKeys = Object.keys(signalDefinitions);
|
|
2634
|
-
const signalDescriptions = {};
|
|
2635
|
-
const signalSentiments = {};
|
|
2636
|
-
for (const signalKey of signalKeys) {
|
|
2637
|
-
const def = signalDefinitions[signalKey];
|
|
2638
|
-
if (!def) continue;
|
|
2639
|
-
signalDescriptions[signalKey] = def.description;
|
|
2640
|
-
signalSentiments[signalKey] = def.sentiment;
|
|
2641
|
-
}
|
|
2642
|
-
const customGuidanceText = ((_a = options.guidance) == null ? void 0 : _a.trim()) || "";
|
|
2643
|
-
const toolName = ((_b = options.toolName) == null ? void 0 : _b.trim()) || AGENT_REPORTING_TOOL_NAME_DEFAULT;
|
|
2644
|
-
const signalList = signalKeys.map((signalKey) => {
|
|
2645
|
-
const sentiment = signalSentiments[signalKey];
|
|
2646
|
-
const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
|
|
2647
|
-
return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
|
|
2648
|
-
}).join("\n");
|
|
2649
|
-
const guidanceBlock = customGuidanceText ? `
|
|
2650
|
-
Additional guidance: ${customGuidanceText}
|
|
2651
|
-
` : "";
|
|
2652
|
-
const toolDescription = `${AGENT_REPORTING_TOOL_PREAMBLE}
|
|
2653
|
-
|
|
2654
|
-
When to call:
|
|
2655
|
-
- You are blocked from completing the task due to missing information or access that the user cannot provide.
|
|
2656
|
-
- A tool is persistently failing across multiple attempts, not just a single transient error.
|
|
2657
|
-
- The task requires a tool, permission, or capability you do not have.
|
|
2658
|
-
- You genuinely cannot deliver what the user asked for despite trying.
|
|
2659
|
-
|
|
2660
|
-
When NOT to call:
|
|
2661
|
-
- Normal clarifying questions or back-and-forth with the user.
|
|
2662
|
-
- A single tool error that you can recover from or retry.
|
|
2663
|
-
- You successfully completed the task, even if it was difficult.
|
|
2664
|
-
- Policy refusals or content filtering \u2014 those are working as intended.
|
|
2665
|
-
|
|
2666
|
-
Rules:
|
|
2667
|
-
1. Pick the single best category.
|
|
2668
|
-
2. Do not fabricate issues. Only report what is evident from the conversation.
|
|
2669
|
-
3. Err on the side of NOT calling this tool. When in doubt, help the user instead.
|
|
2670
|
-
${guidanceBlock}
|
|
2671
|
-
Categories:
|
|
2672
|
-
${signalList}`;
|
|
2673
|
-
return {
|
|
2674
|
-
toolName,
|
|
2675
|
-
toolDescription,
|
|
2676
|
-
signalKeys,
|
|
2677
|
-
signalKeySet: new Set(signalKeys),
|
|
2678
|
-
signalDescriptions,
|
|
2679
|
-
signalSentiments
|
|
2680
|
-
};
|
|
2681
|
-
}
|
|
2682
|
-
function resolveJsonSchemaFactory(aiSDK) {
|
|
2683
|
-
if (!isRecord(aiSDK) || !isFunction(aiSDK["jsonSchema"])) return void 0;
|
|
2684
|
-
return aiSDK["jsonSchema"];
|
|
2685
|
-
}
|
|
2686
2850
|
function detectAISDKVersion(aiSDK) {
|
|
2687
2851
|
if (!isRecord(aiSDK)) return "unknown";
|
|
2688
2852
|
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
@@ -2701,80 +2865,16 @@ function resolveRegisterTelemetry(aiSDK) {
|
|
|
2701
2865
|
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
2702
2866
|
return isFunction(fn) ? fn : void 0;
|
|
2703
2867
|
}
|
|
2704
|
-
function asVercelSchema(jsonSchemaObj) {
|
|
2705
|
-
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
2706
|
-
const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2707
|
-
return {
|
|
2708
|
-
[schemaSymbol]: true,
|
|
2709
|
-
[validatorSymbol]: true,
|
|
2710
|
-
_type: void 0,
|
|
2711
|
-
jsonSchema: jsonSchemaObj,
|
|
2712
|
-
validate: (value) => ({ success: true, value })
|
|
2713
|
-
};
|
|
2714
|
-
}
|
|
2715
2868
|
function createSelfDiagnosticsTool(ctx) {
|
|
2716
2869
|
const config = ctx.selfDiagnostics;
|
|
2717
2870
|
if (!config) return void 0;
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
description: "The single best-matching category from the list above."
|
|
2726
|
-
},
|
|
2727
|
-
detail: {
|
|
2728
|
-
type: "string",
|
|
2729
|
-
description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
|
|
2730
|
-
}
|
|
2731
|
-
},
|
|
2732
|
-
required: ["category", "detail"]
|
|
2733
|
-
};
|
|
2734
|
-
const parameters = asVercelSchema(schema);
|
|
2735
|
-
let inputSchema = parameters;
|
|
2736
|
-
if (ctx.jsonSchemaFactory) {
|
|
2737
|
-
try {
|
|
2738
|
-
inputSchema = ctx.jsonSchemaFactory(schema);
|
|
2739
|
-
} catch (e) {
|
|
2740
|
-
inputSchema = parameters;
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
const execute = async (rawInput) => {
|
|
2744
|
-
var _a;
|
|
2745
|
-
const input = isRecord(rawInput) ? rawInput : void 0;
|
|
2746
|
-
const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
|
|
2747
|
-
const categoryCandidate = typeof (input == null ? void 0 : input["category"]) === "string" ? input["category"].trim() : void 0;
|
|
2748
|
-
const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
2749
|
-
const detail = typeof (input == null ? void 0 : input["detail"]) === "string" ? input["detail"].trim() : "";
|
|
2750
|
-
const signalDescription = config.signalDescriptions[category];
|
|
2751
|
-
const signalSentiment = config.signalSentiments[category];
|
|
2752
|
-
void ctx.eventShipper.trackSignal({
|
|
2753
|
-
eventId: ctx.eventId,
|
|
2754
|
-
name: `self diagnostics - ${category}`,
|
|
2755
|
-
type: "agent",
|
|
2756
|
-
sentiment: signalSentiment,
|
|
2757
|
-
properties: {
|
|
2758
|
-
source: "agent_reporting_tool",
|
|
2759
|
-
category,
|
|
2760
|
-
signal_description: signalDescription,
|
|
2761
|
-
ai_sdk_version: ctx.aiSDKVersion,
|
|
2762
|
-
...detail ? { detail } : {}
|
|
2763
|
-
}
|
|
2764
|
-
}).catch((err) => {
|
|
2765
|
-
if (ctx.debug) {
|
|
2766
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
2767
|
-
console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${msg}`);
|
|
2768
|
-
}
|
|
2769
|
-
});
|
|
2770
|
-
return { acknowledged: true, category };
|
|
2771
|
-
};
|
|
2772
|
-
return {
|
|
2773
|
-
description: config.toolDescription,
|
|
2774
|
-
execute,
|
|
2775
|
-
parameters,
|
|
2776
|
-
inputSchema
|
|
2777
|
-
};
|
|
2871
|
+
return createSelfDiagnosticsToolDefinition({
|
|
2872
|
+
config,
|
|
2873
|
+
eventShipper: ctx.eventShipper,
|
|
2874
|
+
getEventId: () => ctx.eventId,
|
|
2875
|
+
aiSDKVersion: ctx.aiSDKVersion,
|
|
2876
|
+
debug: ctx.debug
|
|
2877
|
+
});
|
|
2778
2878
|
}
|
|
2779
2879
|
function getCurrentParentSpanContextSync() {
|
|
2780
2880
|
return getContextManager().getParentSpanIds();
|
|
@@ -3001,7 +3101,6 @@ function setupOperation(params) {
|
|
|
3001
3101
|
eventShipper,
|
|
3002
3102
|
traceShipper,
|
|
3003
3103
|
rootParentForChildren,
|
|
3004
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
3005
3104
|
selfDiagnostics: operationSelfDiagnostics,
|
|
3006
3105
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
3007
3106
|
};
|
|
@@ -3350,7 +3449,6 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
3350
3449
|
);
|
|
3351
3450
|
}
|
|
3352
3451
|
const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
3353
|
-
const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
|
|
3354
3452
|
const metadataAwareOps = /* @__PURE__ */ new Set([
|
|
3355
3453
|
"generateText",
|
|
3356
3454
|
"streamText",
|
|
@@ -3382,14 +3480,9 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
3382
3480
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
3383
3481
|
const perCallCtx = {
|
|
3384
3482
|
eventId: perCallEventId,
|
|
3385
|
-
context: wrapTimeCtx,
|
|
3386
|
-
telemetry,
|
|
3387
|
-
sendTraces: false,
|
|
3388
3483
|
debug,
|
|
3389
3484
|
eventShipper: deps.eventShipper,
|
|
3390
3485
|
traceShipper: deps.traceShipper,
|
|
3391
|
-
rootParentForChildren: void 0,
|
|
3392
|
-
jsonSchemaFactory,
|
|
3393
3486
|
selfDiagnostics: selfDiagnostics2,
|
|
3394
3487
|
aiSDKVersion: "7"
|
|
3395
3488
|
};
|
|
@@ -3591,7 +3684,6 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
3591
3684
|
eventShipper: deps.eventShipper,
|
|
3592
3685
|
traceShipper: deps.traceShipper,
|
|
3593
3686
|
rootParentForChildren,
|
|
3594
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
3595
3687
|
selfDiagnostics,
|
|
3596
3688
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
3597
3689
|
};
|
|
@@ -3799,7 +3891,6 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3799
3891
|
eventShipper: deps.eventShipper,
|
|
3800
3892
|
traceShipper: deps.traceShipper,
|
|
3801
3893
|
rootParentForChildren,
|
|
3802
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
3803
3894
|
selfDiagnostics,
|
|
3804
3895
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
3805
3896
|
};
|
|
@@ -4615,6 +4706,14 @@ function createRaindropAISDK(opts) {
|
|
|
4615
4706
|
traceShipper
|
|
4616
4707
|
});
|
|
4617
4708
|
},
|
|
4709
|
+
createSelfDiagnosticsTool(options = {}) {
|
|
4710
|
+
var _a2;
|
|
4711
|
+
return createStandaloneSelfDiagnosticsTool({
|
|
4712
|
+
options,
|
|
4713
|
+
eventShipper,
|
|
4714
|
+
debug: ((_a2 = opts.events) == null ? void 0 : _a2.debug) === true || envDebug
|
|
4715
|
+
});
|
|
4716
|
+
},
|
|
4618
4717
|
createTelemetryIntegration(contextOrOptions) {
|
|
4619
4718
|
const FLAT_CONTEXT_KEYS = [
|
|
4620
4719
|
"userId",
|