@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.
@@ -1024,7 +1024,7 @@ globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = async_hooks.AsyncLocalStorage;
1024
1024
  // package.json
1025
1025
  var package_default = {
1026
1026
  name: "@raindrop-ai/ai-sdk",
1027
- version: "0.0.31"};
1027
+ version: "0.0.32"};
1028
1028
 
1029
1029
  // src/internal/version.ts
1030
1030
  var libraryName = package_default.name;
@@ -2091,6 +2091,7 @@ var RaindropTelemetryIntegration = class {
2091
2091
  attrInt("gen_ai.usage.output_tokens", usage.outputTokens)
2092
2092
  );
2093
2093
  }
2094
+ this.emitProviderExecutedToolSpans(event, state);
2094
2095
  this.traceShipper.endSpan(state.stepSpan, { attributes: outputAttrs });
2095
2096
  state.stepSpan = void 0;
2096
2097
  state.stepParent = void 0;
@@ -2367,6 +2368,74 @@ var RaindropTelemetryIntegration = class {
2367
2368
  this.emitLive(state, "tool_result", event.toolCall.toolName);
2368
2369
  state.toolSpans.delete(event.toolCall.toolCallId);
2369
2370
  }
2371
+ // ── provider-executed tool calls ─────────────────────────────────────────
2372
+ //
2373
+ // Provider-executed (server-side) tools — e.g. Anthropic's hosted
2374
+ // `web_search` (`anthropic.web_search_20250305`) — are run by the provider,
2375
+ // not by the AI SDK. They therefore never flow through the client
2376
+ // `onToolExecutionStart`/`onToolExecutionEnd` callbacks that emit our
2377
+ // `ai.toolCall` spans; the SDK only surfaces them as `tool-call` /
2378
+ // `tool-result` content parts on the step (carrying `providerExecuted: true`).
2379
+ // Without this, such calls are invisible in every trace backend.
2380
+ //
2381
+ // At step finish we synthesize the same `ai.toolCall` span shape we emit for
2382
+ // client tools (name `ai.toolCall`, `operationId: "ai.toolCall"`, attrs
2383
+ // `ai.toolCall.name`/`id`/`args`/`result`), parented under the step span, so
2384
+ // downstream ingestion maps them to a tool span with no special-casing.
2385
+ //
2386
+ // Client-executed tools are excluded (`providerExecuted` falsy) — they were
2387
+ // already spanned during execution, so this never double-emits.
2388
+ emitProviderExecutedToolSpans(event, state) {
2389
+ if (!state.stepParent) return;
2390
+ const content = Array.isArray(event.content) ? event.content : [];
2391
+ const providerToolCalls = content.filter(
2392
+ (part) => (part == null ? void 0 : part.type) === "tool-call" && part.providerExecuted === true
2393
+ );
2394
+ if (providerToolCalls.length === 0) return;
2395
+ const resultsByCallId = /* @__PURE__ */ new Map();
2396
+ for (const part of content) {
2397
+ if (((part == null ? void 0 : part.type) === "tool-result" || (part == null ? void 0 : part.type) === "tool-error") && typeof part.toolCallId === "string") {
2398
+ resultsByCallId.set(part.toolCallId, part);
2399
+ }
2400
+ }
2401
+ for (const call of providerToolCalls) {
2402
+ const { operationName, resourceName } = opName(
2403
+ "ai.toolCall",
2404
+ state.functionId
2405
+ );
2406
+ const inputAttrs = state.recordInputs ? [attrString("ai.toolCall.args", safeJsonWithUint8(call.input))] : [];
2407
+ const toolSpan = this.traceShipper.startSpan({
2408
+ name: "ai.toolCall",
2409
+ parent: state.stepParent,
2410
+ eventId: state.eventId,
2411
+ operationId: "ai.toolCall",
2412
+ attributes: [
2413
+ attrString("operation.name", operationName),
2414
+ attrString("resource.name", resourceName),
2415
+ attrString("ai.telemetry.functionId", state.functionId),
2416
+ attrString("ai.toolCall.name", call.toolName),
2417
+ attrString("ai.toolCall.id", call.toolCallId),
2418
+ attrString("ai.toolCall.providerExecuted", "true"),
2419
+ ...inputAttrs
2420
+ ]
2421
+ });
2422
+ state.toolCallCount += 1;
2423
+ this.emitLive(state, "tool_start", call.toolName, { args: call.input });
2424
+ const resultPart = resultsByCallId.get(call.toolCallId);
2425
+ if ((resultPart == null ? void 0 : resultPart.type) === "tool-error") {
2426
+ this.traceShipper.endSpan(toolSpan, { error: resultPart.error });
2427
+ } else {
2428
+ const outputAttrs = state.recordOutputs && resultPart && "output" in resultPart ? [
2429
+ attrString(
2430
+ "ai.toolCall.result",
2431
+ safeJsonWithUint8(resultPart.output)
2432
+ )
2433
+ ] : [];
2434
+ this.traceShipper.endSpan(toolSpan, { attributes: outputAttrs });
2435
+ }
2436
+ this.emitLive(state, "tool_result", call.toolName);
2437
+ }
2438
+ }
2370
2439
  finishGenerate(event, state) {
2371
2440
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2372
2441
  if (state.rootSpan) {
@@ -2472,22 +2541,9 @@ var RaindropTelemetryIntegration = class {
2472
2541
  }
2473
2542
  };
2474
2543
 
2475
- // src/internal/traces.ts
2476
- var TraceShipper2 = class extends TraceShipper {
2477
- constructor(opts) {
2478
- var _a, _b, _c;
2479
- super({
2480
- ...opts,
2481
- sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
2482
- serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
2483
- serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
2484
- });
2485
- }
2486
- };
2487
-
2488
- // src/internal/wrap/wrapAISDK.ts
2489
- var AGENT_REPORTING_TOOL_NAME_DEFAULT = "__raindrop_report";
2490
- var AGENT_REPORTING_SIGNALS_DEFAULT = {
2544
+ // src/internal/self-diagnostics.ts
2545
+ var SELF_DIAGNOSTICS_TOOL_NAME_DEFAULT = "__raindrop_report";
2546
+ var SELF_DIAGNOSTICS_SIGNALS_DEFAULT = {
2491
2547
  missing_context: {
2492
2548
  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.",
2493
2549
  sentiment: "NEGATIVE"
@@ -2505,7 +2561,194 @@ var AGENT_REPORTING_SIGNALS_DEFAULT = {
2505
2561
  sentiment: "NEGATIVE"
2506
2562
  }
2507
2563
  };
2508
- 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.";
2564
+ 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.";
2565
+ function normalizeString(value) {
2566
+ if (typeof value !== "string") return void 0;
2567
+ const trimmed = value.trim();
2568
+ return trimmed || void 0;
2569
+ }
2570
+ function normalizeSelfDiagnosticsSignals(signals) {
2571
+ if (!signals) return SELF_DIAGNOSTICS_SIGNALS_DEFAULT;
2572
+ const normalizedEntries = Object.entries(signals).map(([key, value]) => {
2573
+ var _a;
2574
+ const signalKey = key.trim();
2575
+ if (!signalKey || !value || typeof value !== "object") return void 0;
2576
+ const description = (_a = value.description) == null ? void 0 : _a.trim();
2577
+ if (!description) return void 0;
2578
+ const sentiment = value.sentiment;
2579
+ return [
2580
+ signalKey,
2581
+ {
2582
+ description,
2583
+ ...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
2584
+ }
2585
+ ];
2586
+ }).filter(
2587
+ (entry) => entry !== void 0
2588
+ );
2589
+ if (normalizedEntries.length === 0) return SELF_DIAGNOSTICS_SIGNALS_DEFAULT;
2590
+ return Object.fromEntries(normalizedEntries);
2591
+ }
2592
+ function resolveSelfDiagnosticsConfig(options) {
2593
+ var _a, _b;
2594
+ const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
2595
+ const signalKeys = Object.keys(signalDefinitions);
2596
+ const signalDescriptions = {};
2597
+ const signalSentiments = {};
2598
+ for (const signalKey of signalKeys) {
2599
+ const definition = signalDefinitions[signalKey];
2600
+ if (!definition) continue;
2601
+ signalDescriptions[signalKey] = definition.description;
2602
+ signalSentiments[signalKey] = definition.sentiment;
2603
+ }
2604
+ const customGuidance = ((_a = options.guidance) == null ? void 0 : _a.trim()) || "";
2605
+ const toolName = ((_b = options.toolName) == null ? void 0 : _b.trim()) || SELF_DIAGNOSTICS_TOOL_NAME_DEFAULT;
2606
+ const signalList = signalKeys.map((signalKey) => {
2607
+ const sentiment = signalSentiments[signalKey];
2608
+ const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
2609
+ return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
2610
+ }).join("\n");
2611
+ const guidanceBlock = customGuidance ? `
2612
+ Additional guidance: ${customGuidance}
2613
+ ` : "";
2614
+ const toolDescription = `${SELF_DIAGNOSTICS_TOOL_PREAMBLE}
2615
+
2616
+ When to call:
2617
+ - You are blocked from completing the task due to missing information or access that the user cannot provide.
2618
+ - A tool is persistently failing across multiple attempts, not just a single transient error.
2619
+ - The task requires a tool, permission, or capability you do not have.
2620
+ - You genuinely cannot deliver what the user asked for despite trying.
2621
+
2622
+ When NOT to call:
2623
+ - Normal clarifying questions or back-and-forth with the user.
2624
+ - A single tool error that you can recover from or retry.
2625
+ - You successfully completed the task, even if it was difficult.
2626
+ - Policy refusals or content filtering \u2014 those are working as intended.
2627
+
2628
+ Rules:
2629
+ 1. Pick the single best category.
2630
+ 2. Do not fabricate issues. Only report what is evident from the conversation.
2631
+ 3. Err on the side of NOT calling this tool. When in doubt, help the user instead.
2632
+ ${guidanceBlock}
2633
+ Categories:
2634
+ ` + signalList;
2635
+ return {
2636
+ toolName,
2637
+ toolDescription,
2638
+ signalKeys,
2639
+ signalKeySet: new Set(signalKeys),
2640
+ signalDescriptions,
2641
+ signalSentiments
2642
+ };
2643
+ }
2644
+ function normalizeSelfDiagnosticsConfig(options) {
2645
+ if (!(options == null ? void 0 : options.enabled)) return void 0;
2646
+ return resolveSelfDiagnosticsConfig(options);
2647
+ }
2648
+ function asVercelSchema(inputSchema) {
2649
+ const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
2650
+ const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
2651
+ return {
2652
+ [schemaSymbol]: true,
2653
+ [validatorSymbol]: true,
2654
+ _type: void 0,
2655
+ jsonSchema: inputSchema,
2656
+ validate: (value) => ({ success: true, value })
2657
+ };
2658
+ }
2659
+ function resolveStandaloneEventId(options) {
2660
+ var _a, _b, _c, _d, _e, _f;
2661
+ 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);
2662
+ }
2663
+ function createSelfDiagnosticsToolDefinition(args) {
2664
+ const { config, eventShipper, getEventId, aiSDKVersion, debug } = args;
2665
+ const inputJsonSchema = {
2666
+ type: "object",
2667
+ additionalProperties: false,
2668
+ properties: {
2669
+ category: {
2670
+ type: "string",
2671
+ enum: config.signalKeys,
2672
+ description: "The single best-matching category from the list above."
2673
+ },
2674
+ detail: {
2675
+ type: "string",
2676
+ description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
2677
+ }
2678
+ },
2679
+ required: ["category", "detail"]
2680
+ };
2681
+ const inputSchema = asVercelSchema(inputJsonSchema);
2682
+ const execute = async (rawInput) => {
2683
+ var _a, _b;
2684
+ const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
2685
+ const categoryCandidate = normalizeString(rawInput == null ? void 0 : rawInput.category);
2686
+ const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
2687
+ const detail = normalizeString(rawInput == null ? void 0 : rawInput.detail);
2688
+ const eventId = getEventId();
2689
+ if (!eventId) {
2690
+ const message = "self diagnostics signal skipped: missing eventId. Pass eventId or getEventId when creating the tool.";
2691
+ if (args.onMissingEventId === "throw") {
2692
+ throw new Error(`[raindrop-ai/ai-sdk] ${message}`);
2693
+ }
2694
+ if (((_b = args.onMissingEventId) != null ? _b : "warn") === "warn") {
2695
+ console.warn(`[raindrop-ai/ai-sdk] ${message}`);
2696
+ }
2697
+ return { acknowledged: false, category, reason: "missing_event_id" };
2698
+ }
2699
+ void eventShipper.trackSignal({
2700
+ eventId,
2701
+ name: `self diagnostics - ${category}`,
2702
+ type: "agent",
2703
+ sentiment: config.signalSentiments[category],
2704
+ properties: {
2705
+ source: "agent_reporting_tool",
2706
+ category,
2707
+ signal_description: config.signalDescriptions[category],
2708
+ ...aiSDKVersion ? { ai_sdk_version: aiSDKVersion } : {},
2709
+ ...detail ? { detail } : {}
2710
+ }
2711
+ }).catch((error) => {
2712
+ if (debug) {
2713
+ const message = error instanceof Error ? error.message : String(error);
2714
+ console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${message}`);
2715
+ }
2716
+ });
2717
+ return { acknowledged: true, category };
2718
+ };
2719
+ return {
2720
+ name: config.toolName,
2721
+ description: config.toolDescription,
2722
+ parameters: inputSchema,
2723
+ inputSchema,
2724
+ execute
2725
+ };
2726
+ }
2727
+ function createStandaloneSelfDiagnosticsTool(args) {
2728
+ const config = resolveSelfDiagnosticsConfig(args.options);
2729
+ return createSelfDiagnosticsToolDefinition({
2730
+ config,
2731
+ eventShipper: args.eventShipper,
2732
+ getEventId: () => resolveStandaloneEventId(args.options),
2733
+ onMissingEventId: args.options.onMissingEventId,
2734
+ debug: args.debug
2735
+ });
2736
+ }
2737
+
2738
+ // src/internal/traces.ts
2739
+ var TraceShipper2 = class extends TraceShipper {
2740
+ constructor(opts) {
2741
+ var _a, _b, _c;
2742
+ super({
2743
+ ...opts,
2744
+ sdkName: (_a = opts.sdkName) != null ? _a : "ai-sdk",
2745
+ serviceName: (_b = opts.serviceName) != null ? _b : "raindrop.ai-sdk",
2746
+ serviceVersion: (_c = opts.serviceVersion) != null ? _c : libraryVersion
2747
+ });
2748
+ }
2749
+ };
2750
+
2751
+ // src/internal/wrap/wrapAISDK.ts
2509
2752
  var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
2510
2753
  var PendingToolSpanStore = class _PendingToolSpanStore {
2511
2754
  constructor() {
@@ -2609,85 +2852,6 @@ function mergeContexts(wrapTime, callTime) {
2609
2852
  }
2610
2853
  return result;
2611
2854
  }
2612
- function normalizeSelfDiagnosticsSignals(signals) {
2613
- if (!signals) return AGENT_REPORTING_SIGNALS_DEFAULT;
2614
- const normalizedEntries = Object.entries(signals).map(([key, value]) => {
2615
- var _a;
2616
- const signalKey = key.trim();
2617
- if (!signalKey || !value || typeof value !== "object") return void 0;
2618
- const description = (_a = value.description) == null ? void 0 : _a.trim();
2619
- if (!description) return void 0;
2620
- const sentiment = value.sentiment;
2621
- return [
2622
- signalKey,
2623
- {
2624
- description,
2625
- ...sentiment === "POSITIVE" || sentiment === "NEGATIVE" ? { sentiment } : {}
2626
- }
2627
- ];
2628
- }).filter(
2629
- (entry) => entry !== void 0
2630
- );
2631
- if (normalizedEntries.length === 0) return AGENT_REPORTING_SIGNALS_DEFAULT;
2632
- return Object.fromEntries(normalizedEntries);
2633
- }
2634
- function normalizeSelfDiagnosticsConfig(options) {
2635
- var _a, _b;
2636
- if (!(options == null ? void 0 : options.enabled)) return void 0;
2637
- const signalDefinitions = normalizeSelfDiagnosticsSignals(options.signals);
2638
- const signalKeys = Object.keys(signalDefinitions);
2639
- const signalDescriptions = {};
2640
- const signalSentiments = {};
2641
- for (const signalKey of signalKeys) {
2642
- const def = signalDefinitions[signalKey];
2643
- if (!def) continue;
2644
- signalDescriptions[signalKey] = def.description;
2645
- signalSentiments[signalKey] = def.sentiment;
2646
- }
2647
- const customGuidanceText = ((_a = options.guidance) == null ? void 0 : _a.trim()) || "";
2648
- const toolName = ((_b = options.toolName) == null ? void 0 : _b.trim()) || AGENT_REPORTING_TOOL_NAME_DEFAULT;
2649
- const signalList = signalKeys.map((signalKey) => {
2650
- const sentiment = signalSentiments[signalKey];
2651
- const sentimentTag = sentiment ? ` [${sentiment.toLowerCase()}]` : "";
2652
- return `- ${signalKey}: ${signalDescriptions[signalKey]}${sentimentTag}`;
2653
- }).join("\n");
2654
- const guidanceBlock = customGuidanceText ? `
2655
- Additional guidance: ${customGuidanceText}
2656
- ` : "";
2657
- const toolDescription = `${AGENT_REPORTING_TOOL_PREAMBLE}
2658
-
2659
- When to call:
2660
- - You are blocked from completing the task due to missing information or access that the user cannot provide.
2661
- - A tool is persistently failing across multiple attempts, not just a single transient error.
2662
- - The task requires a tool, permission, or capability you do not have.
2663
- - You genuinely cannot deliver what the user asked for despite trying.
2664
-
2665
- When NOT to call:
2666
- - Normal clarifying questions or back-and-forth with the user.
2667
- - A single tool error that you can recover from or retry.
2668
- - You successfully completed the task, even if it was difficult.
2669
- - Policy refusals or content filtering \u2014 those are working as intended.
2670
-
2671
- Rules:
2672
- 1. Pick the single best category.
2673
- 2. Do not fabricate issues. Only report what is evident from the conversation.
2674
- 3. Err on the side of NOT calling this tool. When in doubt, help the user instead.
2675
- ${guidanceBlock}
2676
- Categories:
2677
- ${signalList}`;
2678
- return {
2679
- toolName,
2680
- toolDescription,
2681
- signalKeys,
2682
- signalKeySet: new Set(signalKeys),
2683
- signalDescriptions,
2684
- signalSentiments
2685
- };
2686
- }
2687
- function resolveJsonSchemaFactory(aiSDK) {
2688
- if (!isRecord(aiSDK) || !isFunction(aiSDK["jsonSchema"])) return void 0;
2689
- return aiSDK["jsonSchema"];
2690
- }
2691
2855
  function detectAISDKVersion(aiSDK) {
2692
2856
  if (!isRecord(aiSDK)) return "unknown";
2693
2857
  if (isFunction(aiSDK["jsonSchema"])) return "6";
@@ -2706,80 +2870,16 @@ function resolveRegisterTelemetry(aiSDK) {
2706
2870
  const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
2707
2871
  return isFunction(fn) ? fn : void 0;
2708
2872
  }
2709
- function asVercelSchema(jsonSchemaObj) {
2710
- const validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
2711
- const schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
2712
- return {
2713
- [schemaSymbol]: true,
2714
- [validatorSymbol]: true,
2715
- _type: void 0,
2716
- jsonSchema: jsonSchemaObj,
2717
- validate: (value) => ({ success: true, value })
2718
- };
2719
- }
2720
2873
  function createSelfDiagnosticsTool(ctx) {
2721
2874
  const config = ctx.selfDiagnostics;
2722
2875
  if (!config) return void 0;
2723
- const schema = {
2724
- type: "object",
2725
- additionalProperties: false,
2726
- properties: {
2727
- category: {
2728
- type: "string",
2729
- enum: config.signalKeys,
2730
- description: "The single best-matching category from the list above."
2731
- },
2732
- detail: {
2733
- type: "string",
2734
- description: "One sentence of factual context: what happened and why it matters. Do not include PII or secrets."
2735
- }
2736
- },
2737
- required: ["category", "detail"]
2738
- };
2739
- const parameters = asVercelSchema(schema);
2740
- let inputSchema = parameters;
2741
- if (ctx.jsonSchemaFactory) {
2742
- try {
2743
- inputSchema = ctx.jsonSchemaFactory(schema);
2744
- } catch (e) {
2745
- inputSchema = parameters;
2746
- }
2747
- }
2748
- const execute = async (rawInput) => {
2749
- var _a;
2750
- const input = isRecord(rawInput) ? rawInput : void 0;
2751
- const fallbackCategory = (_a = config.signalKeys[0]) != null ? _a : "unknown";
2752
- const categoryCandidate = typeof (input == null ? void 0 : input["category"]) === "string" ? input["category"].trim() : void 0;
2753
- const category = categoryCandidate && config.signalKeySet.has(categoryCandidate) ? categoryCandidate : fallbackCategory;
2754
- const detail = typeof (input == null ? void 0 : input["detail"]) === "string" ? input["detail"].trim() : "";
2755
- const signalDescription = config.signalDescriptions[category];
2756
- const signalSentiment = config.signalSentiments[category];
2757
- void ctx.eventShipper.trackSignal({
2758
- eventId: ctx.eventId,
2759
- name: `self diagnostics - ${category}`,
2760
- type: "agent",
2761
- sentiment: signalSentiment,
2762
- properties: {
2763
- source: "agent_reporting_tool",
2764
- category,
2765
- signal_description: signalDescription,
2766
- ai_sdk_version: ctx.aiSDKVersion,
2767
- ...detail ? { detail } : {}
2768
- }
2769
- }).catch((err) => {
2770
- if (ctx.debug) {
2771
- const msg = err instanceof Error ? err.message : String(err);
2772
- console.warn(`[raindrop-ai/ai-sdk] selfDiagnostics signal dispatch failed: ${msg}`);
2773
- }
2774
- });
2775
- return { acknowledged: true, category };
2776
- };
2777
- return {
2778
- description: config.toolDescription,
2779
- execute,
2780
- parameters,
2781
- inputSchema
2782
- };
2876
+ return createSelfDiagnosticsToolDefinition({
2877
+ config,
2878
+ eventShipper: ctx.eventShipper,
2879
+ getEventId: () => ctx.eventId,
2880
+ aiSDKVersion: ctx.aiSDKVersion,
2881
+ debug: ctx.debug
2882
+ });
2783
2883
  }
2784
2884
  function getCurrentParentSpanContextSync() {
2785
2885
  return getContextManager().getParentSpanIds();
@@ -3006,7 +3106,6 @@ function setupOperation(params) {
3006
3106
  eventShipper,
3007
3107
  traceShipper,
3008
3108
  rootParentForChildren,
3009
- jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
3010
3109
  selfDiagnostics: operationSelfDiagnostics,
3011
3110
  aiSDKVersion: detectAISDKVersion(aiSDK)
3012
3111
  };
@@ -3355,7 +3454,6 @@ function wrapAISDK(aiSDK, deps) {
3355
3454
  );
3356
3455
  }
3357
3456
  const selfDiagnostics2 = normalizeSelfDiagnosticsConfig(deps.options.selfDiagnostics);
3358
- const jsonSchemaFactory = selfDiagnostics2 ? resolveJsonSchemaFactory(aiSDK) : void 0;
3359
3457
  const metadataAwareOps = /* @__PURE__ */ new Set([
3360
3458
  "generateText",
3361
3459
  "streamText",
@@ -3387,14 +3485,9 @@ function wrapAISDK(aiSDK, deps) {
3387
3485
  const perCallEventIdGenerated = !perCallEventIdExplicit;
3388
3486
  const perCallCtx = {
3389
3487
  eventId: perCallEventId,
3390
- context: wrapTimeCtx,
3391
- telemetry,
3392
- sendTraces: false,
3393
3488
  debug,
3394
3489
  eventShipper: deps.eventShipper,
3395
3490
  traceShipper: deps.traceShipper,
3396
- rootParentForChildren: void 0,
3397
- jsonSchemaFactory,
3398
3491
  selfDiagnostics: selfDiagnostics2,
3399
3492
  aiSDKVersion: "7"
3400
3493
  };
@@ -3596,7 +3689,6 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
3596
3689
  eventShipper: deps.eventShipper,
3597
3690
  traceShipper: deps.traceShipper,
3598
3691
  rootParentForChildren,
3599
- jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
3600
3692
  selfDiagnostics,
3601
3693
  aiSDKVersion: detectAISDKVersion(aiSDK)
3602
3694
  };
@@ -3804,7 +3896,6 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
3804
3896
  eventShipper: deps.eventShipper,
3805
3897
  traceShipper: deps.traceShipper,
3806
3898
  rootParentForChildren,
3807
- jsonSchemaFactory: resolveJsonSchemaFactory(aiSDK),
3808
3899
  selfDiagnostics,
3809
3900
  aiSDKVersion: detectAISDKVersion(aiSDK)
3810
3901
  };
@@ -4620,6 +4711,14 @@ function createRaindropAISDK(opts) {
4620
4711
  traceShipper
4621
4712
  });
4622
4713
  },
4714
+ createSelfDiagnosticsTool(options = {}) {
4715
+ var _a2;
4716
+ return createStandaloneSelfDiagnosticsTool({
4717
+ options,
4718
+ eventShipper,
4719
+ debug: ((_a2 = opts.events) == null ? void 0 : _a2.debug) === true || envDebug
4720
+ });
4721
+ },
4623
4722
  createTelemetryIntegration(contextOrOptions) {
4624
4723
  const FLAT_CONTEXT_KEYS = [
4625
4724
  "userId",
@@ -1,4 +1,4 @@
1
- export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-7VSCLQIX.mjs';
1
+ export { DEFAULT_REDACT_ATTRIBUTE_KEYS, DEFAULT_SECRET_KEY_NAMES, REDACTED_PLACEHOLDER, RaindropTelemetryIntegration, _resetParentToolContextStorage, _resetRaindropCallMetadataStorage, _resetWarnedMissingUserId, clearParentToolContext, createRaindropAISDK, currentSpan, defaultTransformSpan, enterParentToolContext, eventMetadata, eventMetadataFromChatRequest, getContextManager, getCurrentParentToolContext, getCurrentRaindropCallMetadata, readRaindropCallMetadataFromArgs, redactJsonAttributeValue, redactSecretsInObject, runWithParentToolContext, runWithRaindropCallMetadata, withCurrent } from './chunk-YDMJ6ABM.mjs';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  globalThis.RAINDROP_ASYNC_LOCAL_STORAGE = AsyncLocalStorage;
@@ -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, u as TransformSpanHook, W as WrapAISDKOptions, v as WrappedAI, w as WrappedAISDK, _ as _resetParentToolContextStorage, x as _resetRaindropCallMetadataStorage, y as _resetWarnedMissingUserId, z as clearParentToolContext, F as createRaindropAISDK, G as currentSpan, H as defaultTransformSpan, J as enterParentToolContext, K as eventMetadata, L as eventMetadataFromChatRequest, M as getContextManager, N as getCurrentParentToolContext, Q as getCurrentRaindropCallMetadata, U as readRaindropCallMetadataFromArgs, V as redactJsonAttributeValue, X as redactSecretsInObject, Y as runWithParentToolContext, Z as runWithRaindropCallMetadata, $ as withCurrent } from './index-IMe7ZUXV.mjs';
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>() => {
@@ -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, u as TransformSpanHook, W as WrapAISDKOptions, v as WrappedAI, w as WrappedAISDK, _ as _resetParentToolContextStorage, x as _resetRaindropCallMetadataStorage, y as _resetWarnedMissingUserId, z as clearParentToolContext, F as createRaindropAISDK, G as currentSpan, H as defaultTransformSpan, J as enterParentToolContext, K as eventMetadata, L as eventMetadataFromChatRequest, M as getContextManager, N as getCurrentParentToolContext, Q as getCurrentRaindropCallMetadata, U as readRaindropCallMetadataFromArgs, V as redactJsonAttributeValue, X as redactSecretsInObject, Y as runWithParentToolContext, Z as runWithRaindropCallMetadata, $ as withCurrent } from './index-IMe7ZUXV.js';
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>() => {