@raindrop-ai/ai-sdk 0.0.30 → 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-LM3XO4KR.mjs → chunk-YDMJ6ABM.mjs} +273 -164
- package/dist/{index-Ba_ZzUH4.d.mts → index-CwK0GdEe.d.mts} +46 -1
- package/dist/{index-Ba_ZzUH4.d.ts → index-CwK0GdEe.d.ts} +46 -1
- package/dist/index.browser.d.mts +46 -1
- package/dist/index.browser.d.ts +46 -1
- package/dist/index.browser.js +286 -177
- package/dist/index.browser.mjs +286 -177
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/index.node.js +286 -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 +286 -177
- package/dist/index.workers.mjs +1 -1
- package/package.json +2 -2
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;
|
|
@@ -2138,6 +2139,10 @@ var RaindropTelemetryIntegration = class {
|
|
|
2138
2139
|
this.traceShipper.endSpan(embedSpan, { attributes: outputAttrs });
|
|
2139
2140
|
state.embedSpans.delete(event.embedCallId);
|
|
2140
2141
|
};
|
|
2142
|
+
// v7 canary.159 renamed `onEmbedFinish` -> `onEmbedEnd`. Both names forward
|
|
2143
|
+
// to the same implementation; the installed SDK only wires up whichever it
|
|
2144
|
+
// knows about, so there is no double dispatch.
|
|
2145
|
+
this.onEmbedEnd = (event) => this.onEmbedFinish(event);
|
|
2141
2146
|
// ── onFinish ────────────────────────────────────────────────────────────
|
|
2142
2147
|
this.onFinish = (event) => {
|
|
2143
2148
|
const state = this.getState(event.callId);
|
|
@@ -2153,6 +2158,12 @@ var RaindropTelemetryIntegration = class {
|
|
|
2153
2158
|
}
|
|
2154
2159
|
this.cleanup(event.callId);
|
|
2155
2160
|
};
|
|
2161
|
+
// v7 < canary.159 dispatched `onFinish` as the operation finalizer; canary.159
|
|
2162
|
+
// renamed it to `onEnd` (the same change renamed onEmbedFinish -> onEmbedEnd
|
|
2163
|
+
// and onRerankFinish -> onRerankEnd). The event shape is unchanged, so this
|
|
2164
|
+
// is a thin alias to one implementation. The installed SDK wires up whichever
|
|
2165
|
+
// name it knows about, so old and new names never double dispatch.
|
|
2166
|
+
this.onEnd = (event) => this.onFinish(event);
|
|
2156
2167
|
// ── onError ─────────────────────────────────────────────────────────────
|
|
2157
2168
|
this.onError = (error) => {
|
|
2158
2169
|
var _a;
|
|
@@ -2350,6 +2361,74 @@ var RaindropTelemetryIntegration = class {
|
|
|
2350
2361
|
this.emitLive(state, "tool_result", event.toolCall.toolName);
|
|
2351
2362
|
state.toolSpans.delete(event.toolCall.toolCallId);
|
|
2352
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
|
+
}
|
|
2353
2432
|
finishGenerate(event, state) {
|
|
2354
2433
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
2355
2434
|
if (state.rootSpan) {
|
|
@@ -2455,22 +2534,9 @@ var RaindropTelemetryIntegration = class {
|
|
|
2455
2534
|
}
|
|
2456
2535
|
};
|
|
2457
2536
|
|
|
2458
|
-
// src/internal/
|
|
2459
|
-
var
|
|
2460
|
-
|
|
2461
|
-
var _a, _b, _c;
|
|
2462
|
-
super({
|
|
2463
|
-
...opts,
|
|
2464
|
-
sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
|
|
2465
|
-
serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
|
|
2466
|
-
serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
};
|
|
2470
|
-
|
|
2471
|
-
// src/internal/wrap/wrapAISDK.ts
|
|
2472
|
-
var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
|
|
2473
|
-
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 = {
|
|
2474
2540
|
missing_context: {
|
|
2475
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.",
|
|
2476
2542
|
sentiment: "NEGATIVE"
|
|
@@ -2488,7 +2554,194 @@ var AGENT_REPORTING_SIGNALS_DEFAULT = {
|
|
|
2488
2554
|
sentiment: "NEGATIVE"
|
|
2489
2555
|
}
|
|
2490
2556
|
};
|
|
2491
|
-
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
|
|
2492
2745
|
var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
|
|
2493
2746
|
var PendingToolSpanStore = class _PendingToolSpanStore {
|
|
2494
2747
|
constructor() {
|
|
@@ -2592,85 +2845,6 @@ function mergeContexts(wrapTime, callTime) {
|
|
|
2592
2845
|
}
|
|
2593
2846
|
return result;
|
|
2594
2847
|
}
|
|
2595
|
-
function normalizeSelfDiagnosticsSignals(signals) {
|
|
2596
|
-
if (!signals) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
2597
|
-
const normalizedEntries = Object.entries(signals).map(([key, value]) => {
|
|
2598
|
-
var _a;
|
|
2599
|
-
const signalKey = key.trim();
|
|
2600
|
-
if (!signalKey || !value || typeof value !== "object") return void 0;
|
|
2601
|
-
const description = (_a = value.description) == null ? void 0 : _a.trim();
|
|
2602
|
-
if (!description) return void 0;
|
|
2603
|
-
const sentiment = value.sentiment;
|
|
2604
|
-
return [
|
|
2605
|
-
signalKey,
|
|
2606
|
-
{
|
|
2607
|
-
description,
|
|
2608
|
-
...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
|
|
2609
|
-
}
|
|
2610
|
-
];
|
|
2611
|
-
}).filter(
|
|
2612
|
-
(entry) => entry !== void 0
|
|
2613
|
-
);
|
|
2614
|
-
if (normalizedEntries.length === 0) return AGENT_REPORTING_SIGNALS_DEFAULT;
|
|
2615
|
-
return Object.fromEntries(normalizedEntries);
|
|
2616
|
-
}
|
|
2617
|
-
function normalizeSelfDiagnosticsConfig(options) {
|
|
2618
|
-
var _a, _b;
|
|
2619
|
-
if (!(options == null ? void 0 : options.enabled)) return void 0;
|
|
2620
|
-
const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
|
|
2621
|
-
const signalKeys = Object.keys(signalDefinitions);
|
|
2622
|
-
const signalDescriptions = {};
|
|
2623
|
-
const signalSentiments = {};
|
|
2624
|
-
for (const signalKey of signalKeys) {
|
|
2625
|
-
const def = signalDefinitions[signalKey];
|
|
2626
|
-
if (!def) continue;
|
|
2627
|
-
signalDescriptions[signalKey] = def.description;
|
|
2628
|
-
signalSentiments[signalKey] = def.sentiment;
|
|
2629
|
-
}
|
|
2630
|
-
const customGuidanceText = ((_a = options.guidance) == null ? void 0 : _a.trim()) || "";
|
|
2631
|
-
const toolName = ((_b = options.toolName) == null ? void 0 : _b.trim()) || AGENT_REPORTING_TOOL_NAME_DEFAULT;
|
|
2632
|
-
const signalList = signalKeys.map((signalKey) => {
|
|
2633
|
-
const sentiment = signalSentiments[signalKey];
|
|
2634
|
-
const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
|
|
2635
|
-
return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
|
|
2636
|
-
}).join("\n");
|
|
2637
|
-
const guidanceBlock = customGuidanceText ? `
|
|
2638
|
-
Additional guidance: ${customGuidanceText}
|
|
2639
|
-
` : "";
|
|
2640
|
-
const toolDescription = `${AGENT_REPORTING_TOOL_PREAMBLE}
|
|
2641
|
-
|
|
2642
|
-
When to call:
|
|
2643
|
-
- You are blocked from completing the task due to missing information or access that the user cannot provide.
|
|
2644
|
-
- A tool is persistently failing across multiple attempts, not just a single transient error.
|
|
2645
|
-
- The task requires a tool, permission, or capability you do not have.
|
|
2646
|
-
- You genuinely cannot deliver what the user asked for despite trying.
|
|
2647
|
-
|
|
2648
|
-
When NOT to call:
|
|
2649
|
-
- Normal clarifying questions or back-and-forth with the user.
|
|
2650
|
-
- A single tool error that you can recover from or retry.
|
|
2651
|
-
- You successfully completed the task, even if it was difficult.
|
|
2652
|
-
- Policy refusals or content filtering \u2014 those are working as intended.
|
|
2653
|
-
|
|
2654
|
-
Rules:
|
|
2655
|
-
1. Pick the single best category.
|
|
2656
|
-
2. Do not fabricate issues. Only report what is evident from the conversation.
|
|
2657
|
-
3. Err on the side of NOT calling this tool. When in doubt, help the user instead.
|
|
2658
|
-
${guidanceBlock}
|
|
2659
|
-
Categories:
|
|
2660
|
-
${signalList}`;
|
|
2661
|
-
return {
|
|
2662
|
-
toolName,
|
|
2663
|
-
toolDescription,
|
|
2664
|
-
signalKeys,
|
|
2665
|
-
signalKeySet: new Set(signalKeys),
|
|
2666
|
-
signalDescriptions,
|
|
2667
|
-
signalSentiments
|
|
2668
|
-
};
|
|
2669
|
-
}
|
|
2670
|
-
function resolveJsonSchemaFactory(aiSDK) {
|
|
2671
|
-
if (!isRecord(aiSDK) || !isFunction(aiSDK["jsonSchema"])) return void 0;
|
|
2672
|
-
return aiSDK["jsonSchema"];
|
|
2673
|
-
}
|
|
2674
2848
|
function detectAISDKVersion(aiSDK) {
|
|
2675
2849
|
if (!isRecord(aiSDK)) return "unknown";
|
|
2676
2850
|
if (isFunction(aiSDK["jsonSchema"])) return "6";
|
|
@@ -2689,80 +2863,16 @@ function resolveRegisterTelemetry(aiSDK) {
|
|
|
2689
2863
|
const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
|
|
2690
2864
|
return isFunction(fn) ? fn : void 0;
|
|
2691
2865
|
}
|
|
2692
|
-
function asVercelSchema(jsonSchemaObj) {
|
|
2693
|
-
const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
2694
|
-
const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2695
|
-
return {
|
|
2696
|
-
[schemaSymbol]: true,
|
|
2697
|
-
[validatorSymbol]: true,
|
|
2698
|
-
_type: void 0,
|
|
2699
|
-
jsonSchema: jsonSchemaObj,
|
|
2700
|
-
validate: (value) => ({ success: true, value })
|
|
2701
|
-
};
|
|
2702
|
-
}
|
|
2703
2866
|
function createSelfDiagnosticsTool(ctx) {
|
|
2704
2867
|
const config = ctx.selfDiagnostics;
|
|
2705
2868
|
if (!config) return void 0;
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
description: "The single best-matching category from the list above."
|
|
2714
|
-
},
|
|
2715
|
-
detail: {
|
|
2716
|
-
type: "string",
|
|
2717
|
-
description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
|
|
2718
|
-
}
|
|
2719
|
-
},
|
|
2720
|
-
required: ["category", "detail"]
|
|
2721
|
-
};
|
|
2722
|
-
const parameters = asVercelSchema(schema);
|
|
2723
|
-
let inputSchema = parameters;
|
|
2724
|
-
if (ctx.jsonSchemaFactory) {
|
|
2725
|
-
try {
|
|
2726
|
-
inputSchema = ctx.jsonSchemaFactory(schema);
|
|
2727
|
-
} catch (e) {
|
|
2728
|
-
inputSchema = parameters;
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
const execute = async (rawInput) => {
|
|
2732
|
-
var _a;
|
|
2733
|
-
const input = isRecord(rawInput) ? rawInput : void 0;
|
|
2734
|
-
const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
|
|
2735
|
-
const categoryCandidate = typeof (input == null ? void 0 : input["category"]) === "string" ? input["category"].trim() : void 0;
|
|
2736
|
-
const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
|
|
2737
|
-
const detail = typeof (input == null ? void 0 : input["detail"]) === "string" ? input["detail"].trim() : "";
|
|
2738
|
-
const signalDescription = config.signalDescriptions[category];
|
|
2739
|
-
const signalSentiment = config.signalSentiments[category];
|
|
2740
|
-
void ctx.eventShipper.trackSignal({
|
|
2741
|
-
eventId: ctx.eventId,
|
|
2742
|
-
name: `self diagnostics - ${category}`,
|
|
2743
|
-
type: "agent",
|
|
2744
|
-
sentiment: signalSentiment,
|
|
2745
|
-
properties: {
|
|
2746
|
-
source: "agent_reporting_tool",
|
|
2747
|
-
category,
|
|
2748
|
-
signal_description: signalDescription,
|
|
2749
|
-
ai_sdk_version: ctx.aiSDKVersion,
|
|
2750
|
-
...detail ? { detail } : {}
|
|
2751
|
-
}
|
|
2752
|
-
}).catch((err) => {
|
|
2753
|
-
if (ctx.debug) {
|
|
2754
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
2755
|
-
console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${msg}`);
|
|
2756
|
-
}
|
|
2757
|
-
});
|
|
2758
|
-
return { acknowledged: true, category };
|
|
2759
|
-
};
|
|
2760
|
-
return {
|
|
2761
|
-
description: config.toolDescription,
|
|
2762
|
-
execute,
|
|
2763
|
-
parameters,
|
|
2764
|
-
inputSchema
|
|
2765
|
-
};
|
|
2869
|
+
return createSelfDiagnosticsToolDefinition({
|
|
2870
|
+
config,
|
|
2871
|
+
eventShipper: ctx.eventShipper,
|
|
2872
|
+
getEventId: () => ctx.eventId,
|
|
2873
|
+
aiSDKVersion: ctx.aiSDKVersion,
|
|
2874
|
+
debug: ctx.debug
|
|
2875
|
+
});
|
|
2766
2876
|
}
|
|
2767
2877
|
function getCurrentParentSpanContextSync() {
|
|
2768
2878
|
return getContextManager().getParentSpanIds();
|
|
@@ -2989,7 +3099,6 @@ function setupOperation(params) {
|
|
|
2989
3099
|
eventShipper,
|
|
2990
3100
|
traceShipper,
|
|
2991
3101
|
rootParentForChildren,
|
|
2992
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
2993
3102
|
selfDiagnostics: operationSelfDiagnostics,
|
|
2994
3103
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
2995
3104
|
};
|
|
@@ -3338,7 +3447,6 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
3338
3447
|
);
|
|
3339
3448
|
}
|
|
3340
3449
|
const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
|
|
3341
|
-
const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
|
|
3342
3450
|
const metadataAwareOps = /* @__PURE__ */ new Set([
|
|
3343
3451
|
"generateText",
|
|
3344
3452
|
"streamText",
|
|
@@ -3370,14 +3478,9 @@ function wrapAISDK(aiSDK, deps) {
|
|
|
3370
3478
|
const perCallEventIdGenerated = !perCallEventIdExplicit;
|
|
3371
3479
|
const perCallCtx = {
|
|
3372
3480
|
eventId: perCallEventId,
|
|
3373
|
-
context: wrapTimeCtx,
|
|
3374
|
-
telemetry,
|
|
3375
|
-
sendTraces: false,
|
|
3376
3481
|
debug,
|
|
3377
3482
|
eventShipper: deps.eventShipper,
|
|
3378
3483
|
traceShipper: deps.traceShipper,
|
|
3379
|
-
rootParentForChildren: void 0,
|
|
3380
|
-
jsonSchemaFactory,
|
|
3381
3484
|
selfDiagnostics: selfDiagnostics2,
|
|
3382
3485
|
aiSDKVersion: "7"
|
|
3383
3486
|
};
|
|
@@ -3579,7 +3682,6 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
|
|
|
3579
3682
|
eventShipper: deps.eventShipper,
|
|
3580
3683
|
traceShipper: deps.traceShipper,
|
|
3581
3684
|
rootParentForChildren,
|
|
3582
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
3583
3685
|
selfDiagnostics,
|
|
3584
3686
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
3585
3687
|
};
|
|
@@ -3787,7 +3889,6 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
|
|
|
3787
3889
|
eventShipper: deps.eventShipper,
|
|
3788
3890
|
traceShipper: deps.traceShipper,
|
|
3789
3891
|
rootParentForChildren,
|
|
3790
|
-
jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
|
|
3791
3892
|
selfDiagnostics,
|
|
3792
3893
|
aiSDKVersion: detectAISDKVersion(aiSDK)
|
|
3793
3894
|
};
|
|
@@ -4603,6 +4704,14 @@ function createRaindropAISDK(opts) {
|
|
|
4603
4704
|
traceShipper
|
|
4604
4705
|
});
|
|
4605
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
|
+
},
|
|
4606
4715
|
createTelemetryIntegration(contextOrOptions) {
|
|
4607
4716
|
const FLAT_CONTEXT_KEYS = [
|
|
4608
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>() => {
|