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