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