@raindrop-ai/ai-sdk 0.3.3 → 0.3.4

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.
@@ -68,7 +68,7 @@ function evalScopeAttributes() {
68
68
  return { [EVAL_CORRELATION_ID_ATTRIBUTE]: scope.correlationId };
69
69
  }
70
70
 
71
- // ../core/dist/chunk-WJOR6M7H.js
71
+ // ../core/dist/chunk-I6TVJQEC.js
72
72
  var STATE_KEY = /* @__PURE__ */ Symbol.for("raindrop.tracing.replayTraceRoutingState");
73
73
  function state() {
74
74
  const holder = globalThis;
@@ -2504,6 +2504,158 @@ var TraceShipper = class {
2504
2504
  }
2505
2505
  }
2506
2506
  };
2507
+ var PROMPT_TOOLS_ATTRIBUTE = "ai.prompt.tools";
2508
+ function isRecord(value) {
2509
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2510
+ }
2511
+ var JSON_SCHEMA_KEYS = [
2512
+ "type",
2513
+ "properties",
2514
+ "$schema",
2515
+ "$ref",
2516
+ "anyOf",
2517
+ "oneOf",
2518
+ "allOf",
2519
+ "enum",
2520
+ "const",
2521
+ "items",
2522
+ "additionalProperties",
2523
+ "required"
2524
+ ];
2525
+ function isJsonSchema(value) {
2526
+ if (!isRecord(value)) return false;
2527
+ if (typeof value["~standard"] === "object") return false;
2528
+ if (isRecord(value._def) || isRecord(value._zod)) return false;
2529
+ if (Object.keys(value).length === 0) return true;
2530
+ return JSON_SCHEMA_KEYS.some((key) => key in value);
2531
+ }
2532
+ function toJsonSchema(value, options) {
2533
+ if (value === void 0 || value === null) return void 0;
2534
+ if (isJsonSchema(value)) return value;
2535
+ if (isRecord(value) && isJsonSchema(value.jsonSchema)) return value.jsonSchema;
2536
+ if (isRecord(value) && isJsonSchema(value.json)) return value.json;
2537
+ if (options == null ? void 0 : options.schema) {
2538
+ try {
2539
+ return options.schema(value);
2540
+ } catch (e) {
2541
+ return void 0;
2542
+ }
2543
+ }
2544
+ return void 0;
2545
+ }
2546
+ function pickString(value) {
2547
+ return typeof value === "string" && value.length > 0 ? value : void 0;
2548
+ }
2549
+ function functionTool(name, description, schema, options) {
2550
+ const tool = { type: "function", name };
2551
+ const desc = pickString(description);
2552
+ if (desc !== void 0) tool.description = desc;
2553
+ const inputSchema = toJsonSchema(schema, options);
2554
+ if (inputSchema !== void 0) tool.inputSchema = inputSchema;
2555
+ return tool;
2556
+ }
2557
+ function normalizeToolDeclaration(tool, options, fallbackName) {
2558
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2559
+ if (!isRecord(tool)) return void 0;
2560
+ if (tool.type === "provider-defined" || tool.type === "provider") {
2561
+ const name2 = (_b = (_a = pickString(tool.name)) != null ? _a : pickString(tool.id)) != null ? _b : fallbackName;
2562
+ if (name2 === void 0) return void 0;
2563
+ const declaration = { type: "provider-defined", name: name2 };
2564
+ const id = pickString(tool.id);
2565
+ if (id !== void 0) declaration.id = id;
2566
+ if (isRecord(tool.args)) declaration.args = tool.args;
2567
+ return declaration;
2568
+ }
2569
+ if (isRecord(tool.toolSpec)) {
2570
+ const spec = tool.toolSpec;
2571
+ const name2 = (_c = pickString(spec.name)) != null ? _c : fallbackName;
2572
+ if (name2 === void 0) return void 0;
2573
+ return functionTool(name2, spec.description, spec.inputSchema, options);
2574
+ }
2575
+ if (isRecord(tool.function)) {
2576
+ const fn = tool.function;
2577
+ const name2 = (_d = pickString(fn.name)) != null ? _d : fallbackName;
2578
+ if (name2 === void 0) return void 0;
2579
+ return functionTool(name2, fn.description, (_e = fn.parameters) != null ? _e : fn.input_schema, options);
2580
+ }
2581
+ const name = (_g = (_f = pickString(tool.name)) != null ? _f : pickString(tool.id)) != null ? _g : fallbackName;
2582
+ if (name === void 0) return void 0;
2583
+ const type = pickString(tool.type);
2584
+ if (type !== void 0 && type !== "function" && type !== "dynamic" && type !== "custom") {
2585
+ if (!("input_schema" in tool) && !("inputSchema" in tool) && !("parameters" in tool)) {
2586
+ return { type: "provider-defined", id: type, name };
2587
+ }
2588
+ }
2589
+ return functionTool(
2590
+ name,
2591
+ tool.description,
2592
+ (_j = (_i = (_h = tool.inputSchema) != null ? _h : tool.input_schema) != null ? _i : tool.parameters) != null ? _j : tool.schema,
2593
+ options
2594
+ );
2595
+ }
2596
+ var NOT_A_GEMINI_GROUP_KEYS = ["name", "id", "type", "function", "toolSpec", "cachePoint"];
2597
+ function isGeminiToolGroup(tool) {
2598
+ if (Array.isArray(tool.functionDeclarations)) return true;
2599
+ const keys = Object.keys(tool);
2600
+ if (keys.length === 0 || NOT_A_GEMINI_GROUP_KEYS.some((key) => key in tool)) return false;
2601
+ return keys.every((key) => isRecord(tool[key]));
2602
+ }
2603
+ function expandGeminiTool(tool, options) {
2604
+ const declarations = [];
2605
+ for (const [key, value] of Object.entries(tool)) {
2606
+ if (key === "functionDeclarations" && Array.isArray(value)) {
2607
+ for (const declaration of value) {
2608
+ const normalized = normalizeToolDeclaration(declaration, options);
2609
+ if (normalized) declarations.push(normalized);
2610
+ }
2611
+ } else if (isRecord(value)) {
2612
+ declarations.push({ type: "provider-defined", id: key, name: key, args: value });
2613
+ }
2614
+ }
2615
+ return declarations;
2616
+ }
2617
+ function normalizeToolDeclarations(tools, options) {
2618
+ if (tools === void 0 || tools === null) return void 0;
2619
+ if (Array.isArray(tools)) {
2620
+ return tools.flatMap((tool) => {
2621
+ if (isRecord(tool) && isGeminiToolGroup(tool)) {
2622
+ return expandGeminiTool(tool, options);
2623
+ }
2624
+ const declaration = normalizeToolDeclaration(tool, options);
2625
+ return declaration ? [declaration] : [];
2626
+ });
2627
+ }
2628
+ if (!isRecord(tools)) return void 0;
2629
+ return Object.entries(tools).flatMap(([key, tool]) => {
2630
+ const declaration = normalizeToolDeclaration(tool, options, key);
2631
+ return declaration ? [declaration] : [];
2632
+ });
2633
+ }
2634
+ function resolvePromptTools(args) {
2635
+ var _a;
2636
+ if (args.override !== void 0) {
2637
+ return (_a = normalizeToolDeclarations(args.override, args.options)) != null ? _a : [];
2638
+ }
2639
+ return normalizeToolDeclarations(args.inferred, args.options);
2640
+ }
2641
+ function promptToolsAttribute(tools) {
2642
+ const values = promptToolsAttributeValue(tools);
2643
+ if (values === void 0) return void 0;
2644
+ return {
2645
+ key: PROMPT_TOOLS_ATTRIBUTE,
2646
+ value: { arrayValue: { values: values.map((stringValue) => ({ stringValue })) } }
2647
+ };
2648
+ }
2649
+ function promptToolsAttributeValue(tools) {
2650
+ if (tools === void 0) return void 0;
2651
+ return tools.map((tool) => {
2652
+ try {
2653
+ return JSON.stringify(tool);
2654
+ } catch (e) {
2655
+ return JSON.stringify({ type: tool.type, name: tool.name });
2656
+ }
2657
+ });
2658
+ }
2507
2659
  var resolveLocal = (sourceDirectory, detectBranch, completed) => {
2508
2660
  const cwd = sourceDirectory ? path.resolve(sourceDirectory) : process.cwd();
2509
2661
  let cancelled = false;
@@ -2677,7 +2829,7 @@ installTracingSuppressionHook();
2677
2829
  // package.json
2678
2830
  var package_default = {
2679
2831
  name: "@raindrop-ai/ai-sdk",
2680
- version: "0.3.3"};
2832
+ version: "0.3.4"};
2681
2833
 
2682
2834
  // src/internal/version.ts
2683
2835
  var libraryName = package_default.name;
@@ -2824,7 +2976,7 @@ function boundedStringify(value, limit) {
2824
2976
  }
2825
2977
 
2826
2978
  // src/internal/wrap/helpers.ts
2827
- function isRecord(value) {
2979
+ function isRecord2(value) {
2828
2980
  return typeof value === "object" && value !== null;
2829
2981
  }
2830
2982
  function isFunction(value) {
@@ -2863,7 +3015,7 @@ function extractModelInfo(model) {
2863
3015
  }
2864
3016
  return { modelId: model };
2865
3017
  }
2866
- if (!isRecord(model)) return {};
3018
+ if (!isRecord2(model)) return {};
2867
3019
  const provider = typeof model["provider"] === "string" ? model["provider"] : void 0;
2868
3020
  let modelIdRaw;
2869
3021
  if (typeof model["modelId"] === "string") {
@@ -2884,13 +3036,13 @@ function extractModelInfo(model) {
2884
3036
  return { provider, modelId: modelIdRaw };
2885
3037
  }
2886
3038
  function extractTextOutput(result) {
2887
- if (!isRecord(result)) return void 0;
3039
+ if (!isRecord2(result)) return void 0;
2888
3040
  const text = result["text"];
2889
3041
  return typeof text === "string" ? text : void 0;
2890
3042
  }
2891
3043
  function extractObjectOutput(result) {
2892
3044
  var _a;
2893
- if (!isRecord(result)) return void 0;
3045
+ if (!isRecord2(result)) return void 0;
2894
3046
  const obj = result["object"];
2895
3047
  if (obj === void 0) return void 0;
2896
3048
  return (_a = safeJson(obj)) != null ? _a : String(obj);
@@ -2898,24 +3050,24 @@ function extractObjectOutput(result) {
2898
3050
  function isAgentClass(value) {
2899
3051
  if (typeof value !== "function") return false;
2900
3052
  const proto = value.prototype;
2901
- if (!isRecord(proto)) return false;
3053
+ if (!isRecord2(proto)) return false;
2902
3054
  return typeof proto["generate"] === "function" && typeof proto["stream"] === "function";
2903
3055
  }
2904
3056
  function extractModel(result) {
2905
- if (!isRecord(result)) return void 0;
3057
+ if (!isRecord2(result)) return void 0;
2906
3058
  const model = result["model"];
2907
3059
  if (typeof model === "string" && model.length) return model;
2908
3060
  const response = result["response"];
2909
- if (isRecord(response)) {
3061
+ if (isRecord2(response)) {
2910
3062
  const modelId = response["modelId"];
2911
3063
  if (typeof modelId === "string" && modelId.length) return modelId;
2912
3064
  }
2913
3065
  return void 0;
2914
3066
  }
2915
3067
  function extractFinishReason(result) {
2916
- if (!isRecord(result)) return void 0;
3068
+ if (!isRecord2(result)) return void 0;
2917
3069
  if (typeof result["finishReason"] === "string") return result["finishReason"];
2918
- if (isRecord(result["finishReason"]) && typeof result["finishReason"]["unified"] === "string") {
3070
+ if (isRecord2(result["finishReason"]) && typeof result["finishReason"]["unified"] === "string") {
2919
3071
  return result["finishReason"]["unified"];
2920
3072
  }
2921
3073
  return void 0;
@@ -2959,7 +3111,7 @@ function attachmentMediaType(part) {
2959
3111
  if (typeof part["mediaType"] === "string") return part["mediaType"];
2960
3112
  if (typeof part["mimeType"] === "string") return part["mimeType"];
2961
3113
  const file = part["file"];
2962
- if (isRecord(file)) {
3114
+ if (isRecord2(file)) {
2963
3115
  if (typeof file["mediaType"] === "string") return file["mediaType"];
2964
3116
  if (typeof file["mimeType"] === "string") return file["mimeType"];
2965
3117
  }
@@ -2969,7 +3121,7 @@ function attachmentName(part) {
2969
3121
  if (typeof part["filename"] === "string") return part["filename"];
2970
3122
  if (typeof part["name"] === "string") return part["name"];
2971
3123
  const file = part["file"];
2972
- if (isRecord(file)) {
3124
+ if (isRecord2(file)) {
2973
3125
  if (typeof file["filename"] === "string") return file["filename"];
2974
3126
  if (typeof file["name"] === "string") return file["name"];
2975
3127
  }
@@ -2978,7 +3130,7 @@ function attachmentName(part) {
2978
3130
  function attachmentData(part) {
2979
3131
  if ("data" in part) return part["data"];
2980
3132
  const file = part["file"];
2981
- if (isRecord(file)) {
3133
+ if (isRecord2(file)) {
2982
3134
  if ("file_data" in file) return file["file_data"];
2983
3135
  if ("data" in file) return file["data"];
2984
3136
  }
@@ -2996,7 +3148,7 @@ function contentPartToAttachment(part, role) {
2996
3148
  }
2997
3149
  if (partType === "image_url") {
2998
3150
  const imageUrlPart = part["image_url"];
2999
- const imageUrlValue = isRecord(imageUrlPart) ? imageUrlPart["url"] : imageUrlPart;
3151
+ const imageUrlValue = isRecord2(imageUrlPart) ? imageUrlPart["url"] : imageUrlPart;
3000
3152
  const value = asDataUrl(imageUrlValue, "image/png");
3001
3153
  if (!value) return void 0;
3002
3154
  return { type: "image", role, value };
@@ -3016,7 +3168,7 @@ function attachmentsFromContent(content, role) {
3016
3168
  if (!Array.isArray(content)) return void 0;
3017
3169
  const attachments = [];
3018
3170
  for (const part of content) {
3019
- if (!isRecord(part)) continue;
3171
+ if (!isRecord2(part)) continue;
3020
3172
  const attachment = contentPartToAttachment(part, role);
3021
3173
  if (attachment) attachments.push(attachment);
3022
3174
  }
@@ -3049,7 +3201,7 @@ async function outputAttachmentsFromFiles(files) {
3049
3201
  if (!Array.isArray(resolvedFiles)) return void 0;
3050
3202
  const attachments = [];
3051
3203
  for (const file of resolvedFiles) {
3052
- if (!isRecord(file)) continue;
3204
+ if (!isRecord2(file)) continue;
3053
3205
  const attachment = generatedFileToAttachment(file);
3054
3206
  if (attachment) attachments.push(attachment);
3055
3207
  }
@@ -3060,7 +3212,7 @@ function extractTextFromMessageContent(content) {
3060
3212
  if (!Array.isArray(content)) return void 0;
3061
3213
  let result = "";
3062
3214
  for (const part of content) {
3063
- if (!isRecord(part) || part["type"] !== "text" || typeof part["text"] !== "string") continue;
3215
+ if (!isRecord2(part) || part["type"] !== "text" || typeof part["text"] !== "string") continue;
3064
3216
  result += part["text"];
3065
3217
  }
3066
3218
  return result.length ? result : void 0;
@@ -3077,7 +3229,7 @@ function lastUserMessageFromArgs(args) {
3077
3229
  if (!messages) return void 0;
3078
3230
  for (let i = messages.length - 1; i >= 0; i--) {
3079
3231
  const message = messages[i];
3080
- if (isRecord(message) && message["role"] === "user") {
3232
+ if (isRecord2(message) && message["role"] === "user") {
3081
3233
  return message;
3082
3234
  }
3083
3235
  }
@@ -3085,24 +3237,24 @@ function lastUserMessageFromArgs(args) {
3085
3237
  }
3086
3238
  function extractInputAttachmentsFromArgs(args) {
3087
3239
  var _a;
3088
- if (!isRecord(args)) return void 0;
3240
+ if (!isRecord2(args)) return void 0;
3089
3241
  return attachmentsFromContent((_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"], "input");
3090
3242
  }
3091
3243
  async function extractOutputAttachmentsFromResult(result) {
3092
- if (!isRecord(result)) return void 0;
3244
+ if (!isRecord2(result)) return void 0;
3093
3245
  const fileAttachments = await outputAttachmentsFromFiles(result["files"]);
3094
3246
  if (fileAttachments == null ? void 0 : fileAttachments.length) return fileAttachments;
3095
3247
  const responseMessages = extractResponseMessages(result);
3096
3248
  for (let i = responseMessages.length - 1; i >= 0; i--) {
3097
3249
  const message = responseMessages[i];
3098
- if (!isRecord(message) || message["role"] !== "assistant") continue;
3250
+ if (!isRecord2(message) || message["role"] !== "assistant") continue;
3099
3251
  return attachmentsFromContent(message["content"], "output");
3100
3252
  }
3101
3253
  return attachmentsFromContent(result["content"], "output");
3102
3254
  }
3103
3255
  function lastUserMessageTextFromArgs(args) {
3104
3256
  var _a, _b;
3105
- if (!isRecord(args)) return void 0;
3257
+ if (!isRecord2(args)) return void 0;
3106
3258
  const content = (_a = lastUserMessageFromArgs(args)) == null ? void 0 : _a["content"];
3107
3259
  if (content === void 0) return void 0;
3108
3260
  const text = extractTextFromMessageContent(content);
@@ -3111,13 +3263,13 @@ function lastUserMessageTextFromArgs(args) {
3111
3263
  }
3112
3264
  function extractInputFromArgs(args) {
3113
3265
  var _a;
3114
- if (!isRecord(args)) return void 0;
3266
+ if (!isRecord2(args)) return void 0;
3115
3267
  const prompt = args["prompt"];
3116
3268
  if (typeof prompt === "string") return prompt;
3117
3269
  const messages = messagesFromArgs(args);
3118
3270
  if (Array.isArray(messages) && messages.length > 0) {
3119
3271
  const last = messages[messages.length - 1];
3120
- if (isRecord(last)) {
3272
+ if (isRecord2(last)) {
3121
3273
  const content = last["content"];
3122
3274
  const text = extractTextFromMessageContent(content);
3123
3275
  if (text !== void 0) return text;
@@ -3131,7 +3283,7 @@ function extractInputFromArgs(args) {
3131
3283
  return safeJson(args);
3132
3284
  }
3133
3285
  function coerceMessagesFromArgs(args) {
3134
- if (!isRecord(args)) return [];
3286
+ if (!isRecord2(args)) return [];
3135
3287
  const result = [];
3136
3288
  if (typeof args["system"] === "string" && args["system"]) {
3137
3289
  result.push({ role: "system", content: args["system"] });
@@ -3139,7 +3291,7 @@ function coerceMessagesFromArgs(args) {
3139
3291
  const messages = messagesFromArgs(args);
3140
3292
  if (Array.isArray(messages)) {
3141
3293
  for (const message of messages) {
3142
- if (isRecord(message) && typeof message["role"] === "string") {
3294
+ if (isRecord2(message) && typeof message["role"] === "string") {
3143
3295
  result.push(message);
3144
3296
  }
3145
3297
  }
@@ -3151,21 +3303,21 @@ function coerceMessagesFromArgs(args) {
3151
3303
  return result;
3152
3304
  }
3153
3305
  function extractResponseMessages(result) {
3154
- if (!isRecord(result)) return [];
3306
+ if (!isRecord2(result)) return [];
3155
3307
  const response = result["response"];
3156
- if (isRecord(response) && Array.isArray(response["messages"])) {
3308
+ if (isRecord2(response) && Array.isArray(response["messages"])) {
3157
3309
  return response["messages"].filter(
3158
- (message) => isRecord(message) && typeof message["role"] === "string" && "content" in message
3310
+ (message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
3159
3311
  ).map((message) => message);
3160
3312
  }
3161
3313
  const steps = result["steps"];
3162
3314
  if (Array.isArray(steps) && steps.length > 0) {
3163
3315
  const lastStep = steps[steps.length - 1];
3164
- if (isRecord(lastStep) && isRecord(lastStep["response"])) {
3316
+ if (isRecord2(lastStep) && isRecord2(lastStep["response"])) {
3165
3317
  const responseMessages = lastStep["response"]["messages"];
3166
3318
  if (Array.isArray(responseMessages)) {
3167
3319
  return responseMessages.filter(
3168
- (message) => isRecord(message) && typeof message["role"] === "string" && "content" in message
3320
+ (message) => isRecord2(message) && typeof message["role"] === "string" && "content" in message
3169
3321
  ).map((message) => message);
3170
3322
  }
3171
3323
  }
@@ -3186,7 +3338,7 @@ function isTranscriptToolResultError(part, result) {
3186
3338
  if (part["isError"] === true || part["type"] === "tool-error") {
3187
3339
  return true;
3188
3340
  }
3189
- if (isRecord(result) && typeof result["type"] === "string") {
3341
+ if (isRecord2(result) && typeof result["type"] === "string") {
3190
3342
  return result["type"].startsWith("error") || result["type"] === "execution-denied";
3191
3343
  }
3192
3344
  return false;
@@ -3195,7 +3347,7 @@ function getTranscriptToolErrorMessage(result) {
3195
3347
  if (typeof result === "string" && result.length > 0) {
3196
3348
  return result;
3197
3349
  }
3198
- if (isRecord(result)) {
3350
+ if (isRecord2(result)) {
3199
3351
  if (typeof result["value"] === "string" && result["value"].length > 0) {
3200
3352
  return result["value"];
3201
3353
  }
@@ -3209,12 +3361,12 @@ function getTranscriptToolErrorMessage(result) {
3209
3361
  return safeJsonWithUint8(result);
3210
3362
  }
3211
3363
  function getTranscriptMessageParts(message) {
3212
- if (!isRecord(message)) return [];
3364
+ if (!isRecord2(message)) return [];
3213
3365
  const content = message["content"];
3214
3366
  if (Array.isArray(content)) {
3215
- return content.filter(isRecord);
3367
+ return content.filter(isRecord2);
3216
3368
  }
3217
- return isRecord(content) ? [content] : [];
3369
+ return isRecord2(content) ? [content] : [];
3218
3370
  }
3219
3371
  function getTranscriptToolCallInput(part) {
3220
3372
  return "input" in part ? part["input"] : "args" in part ? part["args"] : void 0;
@@ -3315,7 +3467,7 @@ function extractTextFromLmContent(content) {
3315
3467
  if (!Array.isArray(content)) return void 0;
3316
3468
  let result = "";
3317
3469
  for (const part of content) {
3318
- if (isRecord(part) && part["type"] === "text" && typeof part["text"] === "string") {
3470
+ if (isRecord2(part) && part["type"] === "text" && typeof part["text"] === "string") {
3319
3471
  result += part["text"];
3320
3472
  }
3321
3473
  }
@@ -3325,7 +3477,7 @@ function extractToolCallsFromLmContent(content) {
3325
3477
  if (!Array.isArray(content)) return void 0;
3326
3478
  const calls = [];
3327
3479
  for (const part of content) {
3328
- if (!isRecord(part) || part["type"] !== "tool-call") continue;
3480
+ if (!isRecord2(part) || part["type"] !== "tool-call") continue;
3329
3481
  const toolCallId = getTranscriptToolCallId(part);
3330
3482
  const toolName = typeof part["toolName"] === "string" ? part["toolName"] : void 0;
3331
3483
  if (toolCallId || toolName) {
@@ -3335,15 +3487,15 @@ function extractToolCallsFromLmContent(content) {
3335
3487
  return calls.length ? calls : void 0;
3336
3488
  }
3337
3489
  function extractExperimentalTelemetry(args) {
3338
- if (!isRecord(args)) return void 0;
3490
+ if (!isRecord2(args)) return void 0;
3339
3491
  const telemetryConfig = args["experimental_telemetry"];
3340
- if (!isRecord(telemetryConfig)) return void 0;
3492
+ if (!isRecord2(telemetryConfig)) return void 0;
3341
3493
  return {
3342
3494
  functionId: typeof telemetryConfig["functionId"] === "string" ? telemetryConfig["functionId"] : void 0,
3343
3495
  isEnabled: typeof telemetryConfig["isEnabled"] === "boolean" ? telemetryConfig["isEnabled"] : void 0,
3344
3496
  recordInputs: typeof telemetryConfig["recordInputs"] === "boolean" ? telemetryConfig["recordInputs"] : void 0,
3345
3497
  recordOutputs: typeof telemetryConfig["recordOutputs"] === "boolean" ? telemetryConfig["recordOutputs"] : void 0,
3346
- metadata: isRecord(telemetryConfig["metadata"]) ? telemetryConfig["metadata"] : void 0
3498
+ metadata: isRecord2(telemetryConfig["metadata"]) ? telemetryConfig["metadata"] : void 0
3347
3499
  };
3348
3500
  }
3349
3501
  function opName(operationId, functionId) {
@@ -3371,7 +3523,7 @@ function attrsFromTelemetryMetadata(metadata) {
3371
3523
  });
3372
3524
  }
3373
3525
  function attrsFromHeaders(headers) {
3374
- if (!isRecord(headers)) return [];
3526
+ if (!isRecord2(headers)) return [];
3375
3527
  return Object.entries(headers).filter(([, v]) => typeof v === "string").map(([k, v]) => attrString(`ai.request.headers.${k}`, v));
3376
3528
  }
3377
3529
  function attrsFromModelProvider(provider) {
@@ -3384,7 +3536,7 @@ function attrsFromModelProvider(provider) {
3384
3536
  ];
3385
3537
  }
3386
3538
  function attrsFromSettings(args) {
3387
- if (!isRecord(args)) return [];
3539
+ if (!isRecord2(args)) return [];
3388
3540
  const result = [];
3389
3541
  const settingKeys = [
3390
3542
  "maxRetries",
@@ -3412,7 +3564,7 @@ function attrsFromSettings(args) {
3412
3564
  return result;
3413
3565
  }
3414
3566
  function attrsFromGenAiRequest(options) {
3415
- if (!isRecord(options)) return [];
3567
+ if (!isRecord2(options)) return [];
3416
3568
  return [
3417
3569
  attrDouble(
3418
3570
  "gen_ai.request.frequency_penalty",
@@ -3442,7 +3594,7 @@ function attrsFromGenAiRequest(options) {
3442
3594
  ];
3443
3595
  }
3444
3596
  function attrProviderOptions(options) {
3445
- if (!isRecord(options) || !isRecord(options["providerOptions"])) return void 0;
3597
+ if (!isRecord2(options) || !isRecord2(options["providerOptions"])) return void 0;
3446
3598
  const json = safeJsonWithUint8(options["providerOptions"]);
3447
3599
  return json ? attrString("ai.request.providerOptions", json) : void 0;
3448
3600
  }
@@ -3484,10 +3636,10 @@ function readRaindropCallMetadataFromArgs(args) {
3484
3636
  var _a;
3485
3637
  if (args.length === 0) return void 0;
3486
3638
  const first = args[0];
3487
- if (!isRecord(first)) return void 0;
3488
- const topLevel = isRecord(first["metadata"]) ? first["metadata"] : void 0;
3489
- const stable = isRecord(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
3490
- const stableMetadata = isRecord(stable) ? stable : void 0;
3639
+ if (!isRecord2(first)) return void 0;
3640
+ const topLevel = isRecord2(first["metadata"]) ? first["metadata"] : void 0;
3641
+ const stable = isRecord2(first["telemetry"]) ? first["telemetry"]["metadata"] : void 0;
3642
+ const stableMetadata = isRecord2(stable) ? stable : void 0;
3491
3643
  const exp = extractExperimentalTelemetry(first);
3492
3644
  const expMetadata = (exp == null ? void 0 : exp.metadata) && typeof exp.metadata === "object" ? exp.metadata : void 0;
3493
3645
  const raw = (_a = topLevel != null ? topLevel : stableMetadata) != null ? _a : expMetadata;
@@ -3927,38 +4079,38 @@ var CACHE_WRITE_METADATA_KEYS = [
3927
4079
  ["bedrock", "cacheWriteInputTokens"]
3928
4080
  ];
3929
4081
  function cacheWriteTokensFromProviderMetadata(providerMetadata) {
3930
- if (!isRecord(providerMetadata)) return void 0;
4082
+ if (!isRecord2(providerMetadata)) return void 0;
3931
4083
  return firstTokenCount(
3932
4084
  ...CACHE_WRITE_METADATA_KEYS.flatMap(([namespace, key]) => {
3933
4085
  const scope = providerMetadata[namespace];
3934
- if (!isRecord(scope)) return [];
4086
+ if (!isRecord2(scope)) return [];
3935
4087
  const usage = scope["usage"];
3936
- return [scope[key], isRecord(usage) ? usage[key] : void 0];
4088
+ return [scope[key], isRecord2(usage) ? usage[key] : void 0];
3937
4089
  })
3938
4090
  );
3939
4091
  }
3940
4092
  function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
3941
- if (!isRecord(usage)) return {};
4093
+ if (!isRecord2(usage)) return {};
3942
4094
  const inputTokenValue = usage["inputTokens"];
3943
4095
  const outputTokenValue = usage["outputTokens"];
3944
4096
  const inputTokenDetails = usage["inputTokenDetails"];
3945
4097
  const outputTokenDetails = usage["outputTokenDetails"];
3946
- const hasStructuredUsage = isRecord(inputTokenValue) || isRecord(outputTokenValue) || isRecord(inputTokenDetails) || isRecord(outputTokenDetails);
4098
+ const hasStructuredUsage = isRecord2(inputTokenValue) || isRecord2(outputTokenValue) || isRecord2(inputTokenDetails) || isRecord2(outputTokenDetails);
3947
4099
  const inputTokens = firstTokenCount(
3948
- isRecord(inputTokenValue) ? inputTokenValue["total"] : void 0,
4100
+ isRecord2(inputTokenValue) ? inputTokenValue["total"] : void 0,
3949
4101
  inputTokenValue,
3950
4102
  usage["promptTokens"],
3951
4103
  usage["prompt_tokens"]
3952
4104
  );
3953
4105
  const outputTokens = firstTokenCount(
3954
- isRecord(outputTokenValue) ? outputTokenValue["total"] : void 0,
4106
+ isRecord2(outputTokenValue) ? outputTokenValue["total"] : void 0,
3955
4107
  outputTokenValue,
3956
4108
  usage["completionTokens"],
3957
4109
  usage["completion_tokens"]
3958
4110
  );
3959
4111
  const reasoningTokens = firstTokenCount(
3960
- isRecord(outputTokenValue) ? outputTokenValue["reasoning"] : void 0,
3961
- isRecord(outputTokenDetails) ? outputTokenDetails["reasoningTokens"] : void 0,
4112
+ isRecord2(outputTokenValue) ? outputTokenValue["reasoning"] : void 0,
4113
+ isRecord2(outputTokenDetails) ? outputTokenDetails["reasoningTokens"] : void 0,
3962
4114
  usage["reasoningTokens"],
3963
4115
  usage["completionReasoningTokens"],
3964
4116
  usage["completion_reasoning_tokens"],
@@ -3967,27 +4119,27 @@ function extractUsageMetricsFromUsage(usage, _provider, providerMetadata) {
3967
4119
  usage["thinking_tokens"]
3968
4120
  );
3969
4121
  const cacheReadInputTokens = firstTokenCount(
3970
- isRecord(inputTokenValue) ? inputTokenValue["cacheRead"] : void 0,
3971
- isRecord(inputTokenDetails) ? inputTokenDetails["cacheReadTokens"] : void 0,
4122
+ isRecord2(inputTokenValue) ? inputTokenValue["cacheRead"] : void 0,
4123
+ isRecord2(inputTokenDetails) ? inputTokenDetails["cacheReadTokens"] : void 0,
3972
4124
  usage["cachedInputTokens"],
3973
4125
  usage["promptCachedTokens"],
3974
4126
  usage["prompt_cached_tokens"]
3975
4127
  );
3976
4128
  const cacheWriteInputTokens = firstTokenCount(
3977
- isRecord(inputTokenValue) ? inputTokenValue["cacheWrite"] : void 0,
3978
- isRecord(inputTokenDetails) ? inputTokenDetails["cacheWriteTokens"] : void 0,
4129
+ isRecord2(inputTokenValue) ? inputTokenValue["cacheWrite"] : void 0,
4130
+ isRecord2(inputTokenDetails) ? inputTokenDetails["cacheWriteTokens"] : void 0,
3979
4131
  usage["cacheWriteInputTokens"],
3980
4132
  usage["cacheCreationInputTokens"],
3981
4133
  usage["cache_creation_input_tokens"],
3982
4134
  cacheWriteTokensFromProviderMetadata(providerMetadata)
3983
4135
  );
3984
4136
  const nonCachedInputTokens = firstTokenCount(
3985
- isRecord(inputTokenValue) ? inputTokenValue["noCache"] : void 0,
3986
- isRecord(inputTokenDetails) ? inputTokenDetails["noCacheTokens"] : void 0
4137
+ isRecord2(inputTokenValue) ? inputTokenValue["noCache"] : void 0,
4138
+ isRecord2(inputTokenDetails) ? inputTokenDetails["noCacheTokens"] : void 0
3987
4139
  );
3988
4140
  const nonReasoningOutputTokens = firstTokenCount(
3989
- isRecord(outputTokenValue) ? outputTokenValue["text"] : void 0,
3990
- isRecord(outputTokenDetails) ? outputTokenDetails["textTokens"] : void 0
4141
+ isRecord2(outputTokenValue) ? outputTokenValue["text"] : void 0,
4142
+ isRecord2(outputTokenDetails) ? outputTokenDetails["textTokens"] : void 0
3991
4143
  );
3992
4144
  const totalTokens = firstTokenCount(
3993
4145
  usage["totalTokens"],
@@ -4213,17 +4365,10 @@ var RaindropTelemetryIntegration = class {
4213
4365
  if (event.promptMessages) {
4214
4366
  inputAttrs.push(attrString("ai.prompt.messages", safeJsonWithUint8(event.promptMessages)));
4215
4367
  }
4216
- if (event.stepTools) {
4217
- inputAttrs.push(
4218
- attrStringArray(
4219
- "ai.prompt.tools",
4220
- event.stepTools.map((t) => {
4221
- var _a;
4222
- return (_a = safeJsonWithUint8(t)) != null ? _a : "";
4223
- })
4224
- )
4225
- );
4226
- }
4368
+ const promptTools = promptToolsAttribute(
4369
+ resolvePromptTools({ override: this.promptTools, inferred: event.stepTools })
4370
+ );
4371
+ if (promptTools) inputAttrs.push(promptTools);
4227
4372
  if (event.stepToolChoice != null) {
4228
4373
  inputAttrs.push(
4229
4374
  attrString("ai.prompt.toolChoice", safeJsonWithUint8(event.stepToolChoice))
@@ -4571,6 +4716,7 @@ var RaindropTelemetryIntegration = class {
4571
4716
  this.subagentWrapping = opts.subagentWrapping !== false;
4572
4717
  this.debug = opts.debug === true;
4573
4718
  this.defaultContext = opts.context;
4719
+ this.promptTools = opts.tools;
4574
4720
  this.subagents = new SubagentApi({
4575
4721
  traceShipper: this.traceShipper,
4576
4722
  eventShipper: this.eventShipper,
@@ -5209,6 +5355,18 @@ var TraceShipper3 = class extends TraceShipper2 {
5209
5355
  };
5210
5356
 
5211
5357
  // src/internal/wrap/wrapAISDK.ts
5358
+ function promptToolsOptionsFrom(aiSDK) {
5359
+ if (!isRecord2(aiSDK)) return void 0;
5360
+ const asSchema = aiSDK["asSchema"];
5361
+ if (!isFunction(asSchema)) return void 0;
5362
+ return {
5363
+ schema: (schema) => {
5364
+ const converted = asSchema(schema);
5365
+ const json = isRecord2(converted) ? converted["jsonSchema"] : void 0;
5366
+ return isRecord2(json) ? json : void 0;
5367
+ }
5368
+ };
5369
+ }
5212
5370
  var pendingStoresByShipper = /* @__PURE__ */ new WeakMap();
5213
5371
  var PendingToolSpanStore = class _PendingToolSpanStore {
5214
5372
  constructor() {
@@ -5265,9 +5423,9 @@ function _resetWarnedMissingUserId() {
5265
5423
  warnedMissingUserId = false;
5266
5424
  }
5267
5425
  function extractRaindropCallOptions(options) {
5268
- if (!isRecord(options)) return {};
5426
+ if (!isRecord2(options)) return {};
5269
5427
  const em = options["metadata"];
5270
- if (isRecord(em)) return extractRaindropMetadata(em);
5428
+ if (isRecord2(em)) return extractRaindropMetadata(em);
5271
5429
  const telemetry = extractExperimentalTelemetry(options);
5272
5430
  if (telemetry == null ? void 0 : telemetry.metadata) return extractRaindropMetadata(telemetry.metadata);
5273
5431
  return {};
@@ -5329,20 +5487,20 @@ function mergeContexts(wrapTime, callTime) {
5329
5487
  return result;
5330
5488
  }
5331
5489
  function detectAISDKVersion(aiSDK) {
5332
- if (!isRecord(aiSDK)) return "unknown";
5490
+ if (!isRecord2(aiSDK)) return "unknown";
5333
5491
  if (isFunction(aiSDK["jsonSchema"])) return "6";
5334
5492
  if (isFunction(aiSDK["tool"])) return "5";
5335
5493
  return "4";
5336
5494
  }
5337
5495
  function hasStructuredTelemetryEvents(aiSDK) {
5338
- if (!isRecord(aiSDK)) return false;
5496
+ if (!isRecord2(aiSDK)) return false;
5339
5497
  const hasRegister = isFunction(aiSDK["registerTelemetry"]) || isFunction(aiSDK["registerTelemetryIntegration"]);
5340
5498
  const hasV7Marker = isFunction(aiSDK["experimental_streamLanguageModelCall"]) || isFunction(aiSDK["experimental_streamModelCall"]);
5341
5499
  return hasRegister && hasV7Marker;
5342
5500
  }
5343
5501
  function resolveRegisterTelemetry(aiSDK) {
5344
5502
  var _a;
5345
- if (!isRecord(aiSDK)) return void 0;
5503
+ if (!isRecord2(aiSDK)) return void 0;
5346
5504
  const fn = (_a = aiSDK["registerTelemetry"]) != null ? _a : aiSDK["registerTelemetryIntegration"];
5347
5505
  return isFunction(fn) ? fn : void 0;
5348
5506
  }
@@ -5373,18 +5531,18 @@ function isAsyncIterable(value) {
5373
5531
  return value !== null && typeof value === "object" && Symbol.asyncIterator in value;
5374
5532
  }
5375
5533
  function resolveUsageRecord(result) {
5376
- if (!isRecord(result)) return void 0;
5534
+ if (!isRecord2(result)) return void 0;
5377
5535
  let usage;
5378
5536
  try {
5379
- if (isRecord(result["totalUsage"])) {
5537
+ if (isRecord2(result["totalUsage"])) {
5380
5538
  usage = result["totalUsage"];
5381
- } else if (isRecord(result["usage"])) {
5539
+ } else if (isRecord2(result["usage"])) {
5382
5540
  usage = result["usage"];
5383
5541
  }
5384
5542
  } catch (e) {
5385
5543
  return void 0;
5386
5544
  }
5387
- return isRecord(usage) ? usage : void 0;
5545
+ return isRecord2(usage) ? usage : void 0;
5388
5546
  }
5389
5547
  function extractUsageMetrics(result) {
5390
5548
  return extractUsageMetricsFromUsage(resolveUsageRecord(result));
@@ -5405,7 +5563,7 @@ function shouldKeepEventPending(params) {
5405
5563
  }
5406
5564
  function normalizePromptAttr(arg) {
5407
5565
  var _a, _b;
5408
- if (!isRecord(arg)) return arg;
5566
+ if (!isRecord2(arg)) return arg;
5409
5567
  const system = arg["system"];
5410
5568
  const prompt = arg["prompt"];
5411
5569
  const messages = arg["messages"];
@@ -5459,7 +5617,7 @@ async function runWithRootContextAsync(rootSpan, eventId, fn) {
5459
5617
  );
5460
5618
  }
5461
5619
  function teeStreamObjectBaseStream(result) {
5462
- if (!result || !isRecord(result)) return;
5620
+ if (!result || !isRecord2(result)) return;
5463
5621
  const baseStream = result["baseStream"];
5464
5622
  if (!(baseStream && typeof baseStream === "object" && "tee" in baseStream)) return;
5465
5623
  try {
@@ -5500,7 +5658,7 @@ function setupOperation(params) {
5500
5658
  const inheritedParent = inherited && inherited.eventId === eventId ? { traceIdB64: inherited.traceIdB64, spanIdB64: inherited.spanIdB64 } : void 0;
5501
5659
  const outerOperationId = `ai.${operation}`;
5502
5660
  const { operationName, resourceName } = opName(outerOperationId, telemetry == null ? void 0 : telemetry.functionId);
5503
- const modelInfoFromArgs = isRecord(arg) ? extractModelInfo(arg["model"]) : {};
5661
+ const modelInfoFromArgs = isRecord2(arg) ? extractModelInfo(arg["model"]) : {};
5504
5662
  const rootSpan = sendTraces ? traceShipper.startSpan({
5505
5663
  name: outerOperationId,
5506
5664
  parent: inheritedParent,
@@ -5515,7 +5673,7 @@ function setupOperation(params) {
5515
5673
  attrString("ai.model.id", modelInfoFromArgs.modelId),
5516
5674
  attrString("ai.telemetry.metadata.raindrop.eventId", eventId),
5517
5675
  ...attrsFromTelemetryMetadata(telemetry == null ? void 0 : telemetry.metadata),
5518
- ...attrsFromHeaders(isRecord(arg) ? arg["headers"] : void 0),
5676
+ ...attrsFromHeaders(isRecord2(arg) ? arg["headers"] : void 0),
5519
5677
  ...attrsFromSettings(arg),
5520
5678
  ...(telemetry == null ? void 0 : telemetry.recordInputs) === false ? [] : [attrString("ai.prompt", safeJsonWithUint8(normalizePromptAttr(arg)))]
5521
5679
  ]
@@ -5532,7 +5690,9 @@ function setupOperation(params) {
5532
5690
  traceShipper,
5533
5691
  rootParentForChildren,
5534
5692
  selfDiagnostics: operationSelfDiagnostics,
5535
- aiSDKVersion: detectAISDKVersion(aiSDK)
5693
+ aiSDKVersion: detectAISDKVersion(aiSDK),
5694
+ promptTools: options.tools,
5695
+ promptToolsOptions: promptToolsOptionsFrom(aiSDK)
5536
5696
  };
5537
5697
  const toolCalls = [];
5538
5698
  const argsWithWrappedTools = wrapTools(arg, wrapCtx, toolCalls);
@@ -5605,8 +5765,8 @@ function createFinalize(params) {
5605
5765
  endTimeUnixNano: spanEndTimeUnixNano,
5606
5766
  keepEventPending
5607
5767
  });
5608
- const providerMetadata = isRecord(result) ? result["providerMetadata"] : void 0;
5609
- const resultToolCalls = isRecord(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : setup.toolCalls.length ? safeJsonWithUint8(setup.toolCalls) : void 0;
5768
+ const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
5769
+ const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : setup.toolCalls.length ? safeJsonWithUint8(setup.toolCalls) : void 0;
5610
5770
  traceShipper.endSpan(setup.rootSpan, {
5611
5771
  attributes: [
5612
5772
  ...((_d = setup.telemetry) == null ? void 0 : _d.recordOutputs) === false ? [] : [
@@ -5878,6 +6038,7 @@ function wrapAISDK(aiSDK, deps) {
5878
6038
  sendEvents: ((_b = deps.options.send) == null ? void 0 : _b.events) !== false,
5879
6039
  debug,
5880
6040
  settledEventIds: deps.settledEventIds,
6041
+ tools: deps.options.tools,
5881
6042
  context: {
5882
6043
  userId: wrapTimeCtx.userId,
5883
6044
  eventId: wrapTimeCtx.eventId,
@@ -5920,7 +6081,7 @@ function wrapAISDK(aiSDK, deps) {
5920
6081
  const arg = callArgs[0];
5921
6082
  const callMetadata = readRaindropCallMetadataFromArgs(callArgs);
5922
6083
  const callOriginal = () => original.call(aiSDK, ...callArgs);
5923
- if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord(arg)) {
6084
+ if (selfDiagnostics2 && selfDiagnosticsOps.has(propName) && isRecord2(arg)) {
5924
6085
  const telemetry = extractExperimentalTelemetry(arg);
5925
6086
  const callMeta = (telemetry == null ? void 0 : telemetry.metadata) ? extractRaindropMetadata(telemetry.metadata) : {};
5926
6087
  const perCallEventIdExplicit = (_b2 = (_a2 = callMetadata == null ? void 0 : callMetadata.eventId) != null ? _a2 : callMeta.eventId) != null ? _b2 : wrapTimeCtx.eventId;
@@ -5932,16 +6093,18 @@ function wrapAISDK(aiSDK, deps) {
5932
6093
  eventShipper: deps.eventShipper,
5933
6094
  traceShipper: deps.traceShipper,
5934
6095
  selfDiagnostics: selfDiagnostics2,
5935
- aiSDKVersion: "7"
6096
+ aiSDKVersion: "7",
6097
+ promptTools: deps.options.tools,
6098
+ promptToolsOptions: promptToolsOptionsFrom(aiSDK)
5936
6099
  };
5937
- const tools = isRecord(arg["tools"]) ? { ...arg["tools"] } : {};
6100
+ const tools = isRecord2(arg["tools"]) ? { ...arg["tools"] } : {};
5938
6101
  const toolName = selfDiagnostics2.toolName;
5939
6102
  if (!(toolName in tools)) {
5940
6103
  const reportTool = createSelfDiagnosticsTool(perCallCtx);
5941
6104
  if (reportTool) tools[toolName] = reportTool;
5942
6105
  }
5943
- const existingTelemetry = isRecord(arg["experimental_telemetry"]) ? arg["experimental_telemetry"] : {};
5944
- const existingMetadata = isRecord(existingTelemetry["metadata"]) ? existingTelemetry["metadata"] : {};
6106
+ const existingTelemetry = isRecord2(arg["experimental_telemetry"]) ? arg["experimental_telemetry"] : {};
6107
+ const existingMetadata = isRecord2(existingTelemetry["metadata"]) ? existingTelemetry["metadata"] : {};
5945
6108
  const mergedMetadata = existingMetadata["raindrop.eventId"] ? existingMetadata : {
5946
6109
  ...existingMetadata,
5947
6110
  "raindrop.eventId": perCallEventId,
@@ -6137,7 +6300,9 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
6137
6300
  traceShipper: deps.traceShipper,
6138
6301
  rootParentForChildren,
6139
6302
  selfDiagnostics,
6140
- aiSDKVersion: detectAISDKVersion(aiSDK)
6303
+ aiSDKVersion: detectAISDKVersion(aiSDK),
6304
+ promptTools: deps.options.tools,
6305
+ promptToolsOptions: promptToolsOptionsFrom(aiSDK)
6141
6306
  };
6142
6307
  const toolCalls = [];
6143
6308
  const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
@@ -6187,8 +6352,8 @@ function wrapAgentGenerate(generate, instance, agentSettings, className, aiSDK,
6187
6352
  keepEventPending: false
6188
6353
  });
6189
6354
  const finishReason = extractFinishReason(result);
6190
- const providerMetadata = isRecord(result) ? result["providerMetadata"] : void 0;
6191
- const resultToolCalls = isRecord(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
6355
+ const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
6356
+ const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
6192
6357
  deps.traceShipper.endSpan(rootSpan, {
6193
6358
  attributes: [
6194
6359
  ...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
@@ -6357,7 +6522,9 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
6357
6522
  traceShipper: deps.traceShipper,
6358
6523
  rootParentForChildren,
6359
6524
  selfDiagnostics,
6360
- aiSDKVersion: detectAISDKVersion(aiSDK)
6525
+ aiSDKVersion: detectAISDKVersion(aiSDK),
6526
+ promptTools: deps.options.tools,
6527
+ promptToolsOptions: promptToolsOptionsFrom(aiSDK)
6361
6528
  };
6362
6529
  const toolCalls = [];
6363
6530
  const mergedArgsWithWrappedTools = wrapTools(mergedArgs, wrapCtx, toolCalls);
@@ -6407,8 +6574,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
6407
6574
  keepEventPending: false
6408
6575
  });
6409
6576
  const finishReason = extractFinishReason(result);
6410
- const providerMetadata = isRecord(result) ? result["providerMetadata"] : void 0;
6411
- const resultToolCalls = isRecord(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
6577
+ const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
6578
+ const resultToolCalls = isRecord2(result) && Array.isArray(result["toolCalls"]) ? safeJsonWithUint8(result["toolCalls"]) : toolCalls.length ? safeJsonWithUint8(toolCalls) : void 0;
6412
6579
  deps.traceShipper.endSpan(rootSpan, {
6413
6580
  attributes: [
6414
6581
  ...(telemetry == null ? void 0 : telemetry.recordOutputs) === false ? [] : [
@@ -6520,8 +6687,8 @@ function wrapAgentStream(stream, instance, agentSettings, className, aiSDK, deps
6520
6687
  };
6521
6688
  }
6522
6689
  function wrapTools(args, ctx, toolCalls) {
6523
- if (!isRecord(args)) return args;
6524
- const tools = isRecord(args["tools"]) ? { ...args["tools"] } : {};
6690
+ if (!isRecord2(args)) return args;
6691
+ const tools = isRecord2(args["tools"]) ? { ...args["tools"] } : {};
6525
6692
  if (ctx.selfDiagnostics) {
6526
6693
  const reportToolName = ctx.selfDiagnostics.toolName;
6527
6694
  if (!(reportToolName in tools)) {
@@ -6544,7 +6711,7 @@ function wrapTools(args, ctx, toolCalls) {
6544
6711
  }
6545
6712
  function wrapToolExecute(name, tool, ctx, toolCalls) {
6546
6713
  var _a;
6547
- if (!isRecord(tool) || !isFunction(tool["execute"])) return tool;
6714
+ if (!isRecord2(tool) || !isFunction(tool["execute"])) return tool;
6548
6715
  const originalExecute = tool["execute"];
6549
6716
  const { operationName, resourceName } = opName("ai.toolCall", (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
6550
6717
  const createToolSpan = (toolCallId, toolArgs, parent) => {
@@ -6605,7 +6772,7 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
6605
6772
  const wrappedExecute = function(...execArgs) {
6606
6773
  const toolArgs = execArgs[0];
6607
6774
  const execOptions = execArgs.length > 1 ? execArgs[1] : void 0;
6608
- const toolCallId = isRecord(execOptions) && typeof execOptions["toolCallId"] === "string" ? execOptions["toolCallId"] : randomUUID();
6775
+ const toolCallId = isRecord2(execOptions) && typeof execOptions["toolCallId"] === "string" ? execOptions["toolCallId"] : randomUUID();
6609
6776
  const result = originalExecute.apply(this, execArgs);
6610
6777
  if (isAsyncIterable(result)) {
6611
6778
  return (async function* () {
@@ -6680,20 +6847,20 @@ function wrapToolExecute(name, tool, ctx, toolCalls) {
6680
6847
  return { ...tool, execute: wrappedExecute };
6681
6848
  }
6682
6849
  function wrapModel(args, aiSDK, outerOperationId, ctx) {
6683
- if (!isRecord(args) || !("model" in args)) return args;
6850
+ if (!isRecord2(args) || !("model" in args)) return args;
6684
6851
  let model = args["model"];
6685
6852
  if (typeof model === "string") {
6686
6853
  const maybeProvider = globalThis.AI_SDK_DEFAULT_PROVIDER;
6687
- const gateway = isRecord(aiSDK) ? aiSDK["gateway"] : void 0;
6854
+ const gateway = isRecord2(aiSDK) ? aiSDK["gateway"] : void 0;
6688
6855
  const provider = maybeProvider != null ? maybeProvider : gateway;
6689
- if (isRecord(provider) && isFunction(provider["languageModel"])) {
6856
+ if (isRecord2(provider) && isFunction(provider["languageModel"])) {
6690
6857
  try {
6691
6858
  model = provider["languageModel"](model);
6692
6859
  } catch (e) {
6693
6860
  }
6694
6861
  }
6695
6862
  }
6696
- if (!isRecord(model)) return args;
6863
+ if (!isRecord2(model)) return args;
6697
6864
  const modelInfo = extractModelInfo(model);
6698
6865
  const doGenerateOpId = `${outerOperationId}.doGenerate`;
6699
6866
  const doStreamOpId = `${outerOperationId}.doStream`;
@@ -6710,13 +6877,13 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
6710
6877
  try {
6711
6878
  const result = await original.apply(target, callArgs);
6712
6879
  if (span) endDoGenerateSpan(span, result, modelInfo, ctx);
6713
- if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord(result)) {
6880
+ if (localDebuggerEnabled() && ctx.rootParentForChildren && isRecord2(result)) {
6714
6881
  const traceId = ctx.rootParentForChildren.traceIdB64;
6715
6882
  const liveMeta = getLocalDebuggerMetadata({ ...ctx.context, eventId: ctx.eventId });
6716
6883
  const content = result["content"];
6717
6884
  if (Array.isArray(content)) {
6718
6885
  for (const part of content) {
6719
- if (isRecord(part)) {
6886
+ if (isRecord2(part)) {
6720
6887
  if ((part["type"] === "reasoning" || part["type"] === "thinking") && typeof ((_a = part["text"]) != null ? _a : part["thinking"]) === "string") {
6721
6888
  sendLocalDebuggerLiveEvent({
6722
6889
  traceId,
@@ -6785,7 +6952,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
6785
6952
  });
6786
6953
  throw error;
6787
6954
  }
6788
- const stream = isRecord(result) ? result["stream"] : void 0;
6955
+ const stream = isRecord2(result) ? result["stream"] : void 0;
6789
6956
  const RS = globalThis.ReadableStream;
6790
6957
  if (!RS || !(stream instanceof RS)) {
6791
6958
  if (span) ctx.traceShipper.endSpan(span);
@@ -6858,7 +7025,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
6858
7025
  return;
6859
7026
  }
6860
7027
  if (firstChunkMs === void 0) firstChunkMs = Date.now();
6861
- if (isRecord(value)) {
7028
+ if (isRecord2(value)) {
6862
7029
  const type = value["type"];
6863
7030
  if (type === "text-delta") {
6864
7031
  let textDelta;
@@ -6873,7 +7040,7 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
6873
7040
  }
6874
7041
  if (type === "finish") finishReason = extractFinishReason(value);
6875
7042
  if (type === "tool-call") toolCallsLocal.push(value);
6876
- if ("response" in value && isRecord(value["response"])) {
7043
+ if ("response" in value && isRecord2(value["response"])) {
6877
7044
  const response = value["response"];
6878
7045
  if (typeof response["id"] === "string") responseId = response["id"];
6879
7046
  if (typeof response["modelId"] === "string")
@@ -6950,10 +7117,15 @@ function wrapModel(args, aiSDK, outerOperationId, ctx) {
6950
7117
  function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
6951
7118
  var _a, _b, _c;
6952
7119
  const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
6953
- const tools = isRecord(options) ? options["tools"] : void 0;
6954
- const toolsJson = Array.isArray(tools) && tools.length ? tools.map((tool) => safeJsonWithUint8(tool)).filter((json) => typeof json === "string" && json.length > 0) : void 0;
6955
- const toolChoiceJson = isRecord(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
6956
- const promptJson = isRecord(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
7120
+ const promptTools = promptToolsAttribute(
7121
+ resolvePromptTools({
7122
+ override: ctx.promptTools,
7123
+ inferred: isRecord2(options) ? options["tools"] : void 0,
7124
+ options: ctx.promptToolsOptions
7125
+ })
7126
+ );
7127
+ const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
7128
+ const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
6957
7129
  return ctx.traceShipper.startSpan({
6958
7130
  name: operationId,
6959
7131
  parent,
@@ -6968,7 +7140,7 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
6968
7140
  attrString("ai.model.id", modelInfo.modelId),
6969
7141
  ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
6970
7142
  attrString("ai.prompt.messages", promptJson),
6971
- attrStringArray("ai.prompt.tools", toolsJson),
7143
+ promptTools,
6972
7144
  attrString("ai.prompt.toolChoice", toolChoiceJson)
6973
7145
  ],
6974
7146
  attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
@@ -6980,26 +7152,26 @@ function startDoGenerateSpan(operationId, options, modelInfo, parent, ctx) {
6980
7152
  function endDoGenerateSpan(span, result, modelInfo, ctx) {
6981
7153
  var _a;
6982
7154
  const finishReason = extractFinishReason(result);
6983
- const content = isRecord(result) ? result["content"] : void 0;
6984
- const response = isRecord(result) ? result["response"] : void 0;
6985
- const usage = isRecord(result) ? result["usage"] : void 0;
6986
- const providerMetadata = isRecord(result) ? result["providerMetadata"] : void 0;
7155
+ const content = isRecord2(result) ? result["content"] : void 0;
7156
+ const response = isRecord2(result) ? result["response"] : void 0;
7157
+ const usage = isRecord2(result) ? result["usage"] : void 0;
7158
+ const providerMetadata = isRecord2(result) ? result["providerMetadata"] : void 0;
6987
7159
  let responseId;
6988
- if (isRecord(response) && typeof response["id"] === "string") {
7160
+ if (isRecord2(response) && typeof response["id"] === "string") {
6989
7161
  responseId = response["id"];
6990
7162
  } else {
6991
7163
  responseId = randomUUID();
6992
7164
  }
6993
7165
  let responseModelId;
6994
- if (isRecord(response) && typeof response["modelId"] === "string") {
7166
+ if (isRecord2(response) && typeof response["modelId"] === "string") {
6995
7167
  responseModelId = response["modelId"];
6996
7168
  } else {
6997
7169
  responseModelId = modelInfo.modelId;
6998
7170
  }
6999
7171
  let responseTimestampIso;
7000
- if (isRecord(response) && response["timestamp"] instanceof Date) {
7172
+ if (isRecord2(response) && response["timestamp"] instanceof Date) {
7001
7173
  responseTimestampIso = response["timestamp"].toISOString();
7002
- } else if (isRecord(response) && typeof response["timestamp"] === "string") {
7174
+ } else if (isRecord2(response) && typeof response["timestamp"] === "string") {
7003
7175
  responseTimestampIso = response["timestamp"];
7004
7176
  } else {
7005
7177
  responseTimestampIso = (/* @__PURE__ */ new Date()).toISOString();
@@ -7033,10 +7205,15 @@ function endDoGenerateSpan(span, result, modelInfo, ctx) {
7033
7205
  function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
7034
7206
  var _a, _b, _c;
7035
7207
  const { operationName, resourceName } = opName(operationId, (_a = ctx.telemetry) == null ? void 0 : _a.functionId);
7036
- const tools = isRecord(options) ? options["tools"] : void 0;
7037
- const toolsJson = Array.isArray(tools) && tools.length ? tools.map((tool) => safeJsonWithUint8(tool)).filter((json) => typeof json === "string" && json.length > 0) : void 0;
7038
- const toolChoiceJson = isRecord(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
7039
- const promptJson = isRecord(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
7208
+ const promptTools = promptToolsAttribute(
7209
+ resolvePromptTools({
7210
+ override: ctx.promptTools,
7211
+ inferred: isRecord2(options) ? options["tools"] : void 0,
7212
+ options: ctx.promptToolsOptions
7213
+ })
7214
+ );
7215
+ const toolChoiceJson = isRecord2(options) ? safeJsonWithUint8(options["toolChoice"]) : void 0;
7216
+ const promptJson = isRecord2(options) ? safeJsonWithUint8(options["prompt"]) : safeJsonWithUint8(options);
7040
7217
  return ctx.traceShipper.startSpan({
7041
7218
  name: operationId,
7042
7219
  parent,
@@ -7051,7 +7228,7 @@ function startDoStreamSpan(operationId, options, modelInfo, parent, ctx) {
7051
7228
  attrString("ai.model.id", modelInfo.modelId),
7052
7229
  ...((_c = ctx.telemetry) == null ? void 0 : _c.recordInputs) === false ? [] : [
7053
7230
  attrString("ai.prompt.messages", promptJson),
7054
- attrStringArray("ai.prompt.tools", toolsJson),
7231
+ promptTools,
7055
7232
  attrString("ai.prompt.toolChoice", toolChoiceJson)
7056
7233
  ],
7057
7234
  attrString(MODEL_USAGE_ATTRIBUTES.requestModel, modelInfo.modelId),
@@ -7065,7 +7242,7 @@ function resolveContext(context, info) {
7065
7242
  return typeof context === "function" ? context(info) : context;
7066
7243
  }
7067
7244
  function wrapOnFinish(args, onFinish) {
7068
- if (!isRecord(args)) return args;
7245
+ if (!isRecord2(args)) return args;
7069
7246
  const existing = args["onFinish"];
7070
7247
  if (existing === void 0) {
7071
7248
  return { ...args, onFinish: async (result) => onFinish(result) };
@@ -7272,11 +7449,16 @@ function createRaindropAISDK(opts) {
7272
7449
  ];
7273
7450
  let context;
7274
7451
  let subagentWrapping;
7452
+ let tools;
7275
7453
  if (contextOrOptions === void 0) ; else if ("context" in contextOrOptions) {
7276
- context = contextOrOptions.context;
7277
- subagentWrapping = contextOrOptions.subagentWrapping;
7278
- } else if ("subagentWrapping" in contextOrOptions && !FLAT_CONTEXT_KEYS.some((k) => k in contextOrOptions)) {
7279
- subagentWrapping = contextOrOptions.subagentWrapping;
7454
+ const shaped = contextOrOptions;
7455
+ context = shaped.context;
7456
+ subagentWrapping = shaped.subagentWrapping;
7457
+ tools = shaped.tools;
7458
+ } else if (("subagentWrapping" in contextOrOptions || "tools" in contextOrOptions) && !FLAT_CONTEXT_KEYS.some((k) => k in contextOrOptions)) {
7459
+ const shaped = contextOrOptions;
7460
+ subagentWrapping = shaped.subagentWrapping;
7461
+ tools = shaped.tools;
7280
7462
  } else {
7281
7463
  context = contextOrOptions;
7282
7464
  }
@@ -7288,7 +7470,8 @@ function createRaindropAISDK(opts) {
7288
7470
  subagentWrapping,
7289
7471
  debug: envDebug,
7290
7472
  settledEventIds,
7291
- context
7473
+ context,
7474
+ tools
7292
7475
  });
7293
7476
  },
7294
7477
  subagents: subagentApi,
@@ -7415,10 +7598,10 @@ function createRaindropAISDK(opts) {
7415
7598
  }
7416
7599
  function raindrop(options = {}) {
7417
7600
  var _a;
7418
- const { context, subagentWrapping, writeKey, ...rest } = options;
7601
+ const { context, subagentWrapping, tools, writeKey, ...rest } = options;
7419
7602
  const resolvedWriteKey = writeKey != null ? writeKey : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.RAINDROP_WRITE_KEY : void 0;
7420
7603
  const client = createRaindropAISDK({ ...rest, writeKey: resolvedWriteKey });
7421
- return client.createTelemetryIntegration({ context, subagentWrapping });
7604
+ return client.createTelemetryIntegration({ context, subagentWrapping, tools });
7422
7605
  }
7423
7606
 
7424
7607
  // src/index.node.ts
@@ -7432,6 +7615,7 @@ exports.HANDOFF_ATTRIBUTE_PREFIXES = HANDOFF_ATTRIBUTE_PREFIXES;
7432
7615
  exports.HANDOFF_ATTRIBUTE_SUFFIXES = HANDOFF_ATTRIBUTE_SUFFIXES;
7433
7616
  exports.HANDOFF_TERMINAL_CANCELLED = HANDOFF_TERMINAL_CANCELLED;
7434
7617
  exports.HANDOFF_TERMINAL_PROPERTY_KEY = HANDOFF_TERMINAL_PROPERTY_KEY;
7618
+ exports.PROMPT_TOOLS_ATTRIBUTE = PROMPT_TOOLS_ATTRIBUTE;
7435
7619
  exports.REDACTED_PLACEHOLDER = REDACTED_PLACEHOLDER;
7436
7620
  exports.RaindropTelemetryIntegration = RaindropTelemetryIntegration;
7437
7621
  exports.SUBAGENT_ABORTED_OUTPUT = SUBAGENT_ABORTED_OUTPUT;