@arizeai/phoenix-client 6.9.1 → 6.9.2

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.
Files changed (72) hide show
  1. package/dist/esm/__generated__/api/v1.d.ts +313 -4
  2. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  3. package/dist/esm/client.d.ts +1 -0
  4. package/dist/esm/client.d.ts.map +1 -1
  5. package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -1
  6. package/dist/esm/prompts/sdks/toAI.js +31 -11
  7. package/dist/esm/prompts/sdks/toAI.js.map +1 -1
  8. package/dist/esm/prompts/sdks/toAnthropic.d.ts.map +1 -1
  9. package/dist/esm/prompts/sdks/toAnthropic.js +23 -13
  10. package/dist/esm/prompts/sdks/toAnthropic.js.map +1 -1
  11. package/dist/esm/prompts/sdks/toOpenAI.d.ts.map +1 -1
  12. package/dist/esm/prompts/sdks/toOpenAI.js +23 -13
  13. package/dist/esm/prompts/sdks/toOpenAI.js.map +1 -1
  14. package/dist/esm/schemas/llm/phoenixPrompt/converters.js +2 -2
  15. package/dist/esm/schemas/llm/phoenixPrompt/converters.js.map +1 -1
  16. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts +2 -2
  17. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -1
  18. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js +1 -1
  19. package/dist/esm/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -1
  20. package/dist/esm/schemas/llm/schemas.js +2 -2
  21. package/dist/esm/schemas/llm/schemas.js.map +1 -1
  22. package/dist/esm/schemas/llm/utils.js +2 -2
  23. package/dist/esm/schemas/llm/utils.js.map +1 -1
  24. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  25. package/dist/esm/types/prompts.d.ts +4 -0
  26. package/dist/esm/types/prompts.d.ts.map +1 -1
  27. package/dist/esm/types/prompts.js +6 -1
  28. package/dist/esm/types/prompts.js.map +1 -1
  29. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  30. package/dist/esm/utils/getPromptBySelector.d.ts +294 -5
  31. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  32. package/dist/src/__generated__/api/v1.d.ts +313 -4
  33. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  34. package/dist/src/client.d.ts +11 -10
  35. package/dist/src/client.d.ts.map +1 -1
  36. package/dist/src/prompts/sdks/toAI.d.ts.map +1 -1
  37. package/dist/src/prompts/sdks/toAI.js +35 -15
  38. package/dist/src/prompts/sdks/toAI.js.map +1 -1
  39. package/dist/src/prompts/sdks/toAnthropic.d.ts.map +1 -1
  40. package/dist/src/prompts/sdks/toAnthropic.js +24 -14
  41. package/dist/src/prompts/sdks/toAnthropic.js.map +1 -1
  42. package/dist/src/prompts/sdks/toOpenAI.d.ts.map +1 -1
  43. package/dist/src/prompts/sdks/toOpenAI.js +24 -14
  44. package/dist/src/prompts/sdks/toOpenAI.js.map +1 -1
  45. package/dist/src/schemas/llm/phoenixPrompt/converters.js +1 -1
  46. package/dist/src/schemas/llm/phoenixPrompt/converters.js.map +1 -1
  47. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts +2 -2
  48. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.d.ts.map +1 -1
  49. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js +2 -2
  50. package/dist/src/schemas/llm/phoenixPrompt/toolSchemas.js.map +1 -1
  51. package/dist/src/schemas/llm/schemas.js +1 -1
  52. package/dist/src/schemas/llm/schemas.js.map +1 -1
  53. package/dist/src/schemas/llm/utils.js +1 -1
  54. package/dist/src/schemas/llm/utils.js.map +1 -1
  55. package/dist/src/types/prompts.d.ts +4 -0
  56. package/dist/src/types/prompts.d.ts.map +1 -1
  57. package/dist/src/types/prompts.js +8 -0
  58. package/dist/src/types/prompts.js.map +1 -1
  59. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  60. package/dist/src/utils/getPromptBySelector.d.ts +294 -5
  61. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  62. package/dist/tsconfig.tsbuildinfo +1 -1
  63. package/package.json +2 -2
  64. package/src/__generated__/api/v1.ts +313 -4
  65. package/src/prompts/sdks/toAI.ts +33 -11
  66. package/src/prompts/sdks/toAnthropic.ts +26 -15
  67. package/src/prompts/sdks/toOpenAI.ts +25 -15
  68. package/src/schemas/llm/phoenixPrompt/converters.ts +2 -2
  69. package/src/schemas/llm/phoenixPrompt/toolSchemas.ts +16 -13
  70. package/src/schemas/llm/schemas.ts +2 -2
  71. package/src/schemas/llm/utils.ts +2 -2
  72. package/src/types/prompts.ts +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "6.9.1",
3
+ "version": "6.9.2",
4
4
  "description": "A client for the Phoenix API",
5
5
  "keywords": [
6
6
  "arize",
@@ -76,7 +76,7 @@
76
76
  "@arizeai/openinference-semantic-conventions": "^2.1.7",
77
77
  "@arizeai/openinference-vercel": "^2.7.0",
78
78
  "async": "^3.2.6",
79
- "openapi-fetch": "^0.12.5",
79
+ "openapi-fetch": "^0.17.0",
80
80
  "tiny-invariant": "^1.3.3",
81
81
  "zod": "^4.0.14",
82
82
  "@arizeai/phoenix-config": "0.1.4",
@@ -74,7 +74,33 @@ export interface paths {
74
74
  get: operations["listSpanAnnotationsBySpanIds"];
75
75
  put?: never;
76
76
  post?: never;
77
- delete?: never;
77
+ /**
78
+ * Delete span annotations in a project that match the supplied filter.
79
+ * @description Hard-delete span annotations within the named project that match the
80
+ * supplied filter.
81
+ *
82
+ * - The request must either supply both `start_time` AND `end_time`
83
+ * to bound the delete to a `[start_time, end_time)` time window,
84
+ * OR set `delete_all=true` to acknowledge an unbounded sweep. A request
85
+ * that satisfies neither is rejected with 422.
86
+ * - `name`, `identifier`, and `annotator_kind` are optional narrowing
87
+ * filters; on their own they do NOT authorize the request — they only
88
+ * narrow within an already-authorized request (bounded time range or
89
+ * `delete_all=true`).
90
+ * - All supplied filters are combined with AND. `name` and `identifier`,
91
+ * when present, must be non-empty.
92
+ * - `start_time` is inclusive (`>=`); `end_time` is exclusive
93
+ * (`<`). When both are supplied, `start_time` must be strictly earlier
94
+ * than `end_time` (else 422). A half-bounded range (only one of
95
+ * the two) does NOT satisfy the gate and is rejected unless
96
+ * `delete_all=true` is also set. Naive datetimes are interpreted as UTC.
97
+ * - The endpoint is idempotent: a request that matches no rows still
98
+ * returns 204.
99
+ * - When authentication is enabled, non-admin callers can only delete rows
100
+ * they own (`user_id == current_user.id`); admins delete all matching
101
+ * rows.
102
+ */
103
+ delete: operations["deleteSpanAnnotations"];
78
104
  options?: never;
79
105
  head?: never;
80
106
  patch?: never;
@@ -94,7 +120,33 @@ export interface paths {
94
120
  get: operations["listTraceAnnotationsByTraceIds"];
95
121
  put?: never;
96
122
  post?: never;
97
- delete?: never;
123
+ /**
124
+ * Delete trace annotations in a project that match the supplied filter.
125
+ * @description Hard-delete trace annotations within the named project that match the
126
+ * supplied filter.
127
+ *
128
+ * - The request must either supply both `start_time` AND `end_time`
129
+ * to bound the delete to a `[start_time, end_time)` time window,
130
+ * OR set `delete_all=true` to acknowledge an unbounded sweep. A request
131
+ * that satisfies neither is rejected with 422.
132
+ * - `name`, `identifier`, and `annotator_kind` are optional narrowing
133
+ * filters; on their own they do NOT authorize the request — they only
134
+ * narrow within an already-authorized request (bounded time range or
135
+ * `delete_all=true`).
136
+ * - All supplied filters are combined with AND. `name` and `identifier`,
137
+ * when present, must be non-empty.
138
+ * - `start_time` is inclusive (`>=`); `end_time` is exclusive
139
+ * (`<`). When both are supplied, `start_time` must be strictly earlier
140
+ * than `end_time` (else 422). A half-bounded range (only one of
141
+ * the two) does NOT satisfy the gate and is rejected unless
142
+ * `delete_all=true` is also set. Naive datetimes are interpreted as UTC.
143
+ * - The endpoint is idempotent: a request that matches no rows still
144
+ * returns 204.
145
+ * - When authentication is enabled, non-admin callers can only delete rows
146
+ * they own (`user_id == current_user.id`); admins delete all matching
147
+ * rows.
148
+ */
149
+ delete: operations["deleteTraceAnnotations"];
98
150
  options?: never;
99
151
  head?: never;
100
152
  patch?: never;
@@ -114,7 +166,33 @@ export interface paths {
114
166
  get: operations["listSessionAnnotationsBySessionIds"];
115
167
  put?: never;
116
168
  post?: never;
117
- delete?: never;
169
+ /**
170
+ * Delete session annotations in a project that match the supplied filter.
171
+ * @description Hard-delete session annotations within the named project that match the
172
+ * supplied filter.
173
+ *
174
+ * - The request must either supply both `start_time` AND `end_time`
175
+ * to bound the delete to a `[start_time, end_time)` time window,
176
+ * OR set `delete_all=true` to acknowledge an unbounded sweep. A request
177
+ * that satisfies neither is rejected with 422.
178
+ * - `name`, `identifier`, and `annotator_kind` are optional narrowing
179
+ * filters; on their own they do NOT authorize the request — they only
180
+ * narrow within an already-authorized request (bounded time range or
181
+ * `delete_all=true`).
182
+ * - All supplied filters are combined with AND. `name` and `identifier`,
183
+ * when present, must be non-empty.
184
+ * - `start_time` is inclusive (`>=`); `end_time` is exclusive
185
+ * (`<`). When both are supplied, `start_time` must be strictly earlier
186
+ * than `end_time` (else 422). A half-bounded range (only one of
187
+ * the two) does NOT satisfy the gate and is rejected unless
188
+ * `delete_all=true` is also set. Naive datetimes are interpreted as UTC.
189
+ * - The endpoint is idempotent: a request that matches no rows still
190
+ * returns 204.
191
+ * - When authentication is enabled, non-admin callers can only delete rows
192
+ * they own (`user_id == current_user.id`); admins delete all matching
193
+ * rows.
194
+ */
195
+ delete: operations["deleteSessionAnnotations"];
118
196
  options?: never;
119
197
  head?: never;
120
198
  patch?: never;
@@ -2882,6 +2960,18 @@ export interface components {
2882
2960
  /** Strict */
2883
2961
  strict?: boolean;
2884
2962
  };
2963
+ /** PromptToolRaw */
2964
+ PromptToolRaw: {
2965
+ /**
2966
+ * @description discriminator enum property added by openapi-typescript
2967
+ * @enum {string}
2968
+ */
2969
+ type: "raw";
2970
+ /** Raw */
2971
+ raw: {
2972
+ [key: string]: unknown;
2973
+ };
2974
+ };
2885
2975
  /** PromptTools */
2886
2976
  PromptTools: {
2887
2977
  /**
@@ -2890,7 +2980,7 @@ export interface components {
2890
2980
  */
2891
2981
  type: "tools";
2892
2982
  /** Tools */
2893
- tools: components["schemas"]["PromptToolFunction"][];
2983
+ tools: (components["schemas"]["PromptToolFunction"] | components["schemas"]["PromptToolRaw"])[];
2894
2984
  /** Tool Choice */
2895
2985
  tool_choice?: components["schemas"]["PromptToolChoiceNone"] | components["schemas"]["PromptToolChoiceZeroOrMore"] | components["schemas"]["PromptToolChoiceOneOrMore"] | components["schemas"]["PromptToolChoiceSpecificFunctionTool"];
2896
2986
  /** Disable Parallel Tool Calls */
@@ -3114,6 +3204,24 @@ export interface components {
3114
3204
  end_time: string;
3115
3205
  /** Traces */
3116
3206
  traces: components["schemas"]["SessionTraceData"][];
3207
+ /**
3208
+ * Token Count Prompt
3209
+ * @description Cumulative prompt token count across all spans in the session.
3210
+ * @default 0
3211
+ */
3212
+ token_count_prompt?: number;
3213
+ /**
3214
+ * Token Count Completion
3215
+ * @description Cumulative completion token count across all spans in the session.
3216
+ * @default 0
3217
+ */
3218
+ token_count_completion?: number;
3219
+ /**
3220
+ * Token Count Total
3221
+ * @description Cumulative total token count across all spans in the session (prompt + completion).
3222
+ * @default 0
3223
+ */
3224
+ token_count_total?: number;
3117
3225
  };
3118
3226
  /** SessionNoteData */
3119
3227
  SessionNoteData: {
@@ -3588,6 +3696,24 @@ export interface components {
3588
3696
  * Format: date-time
3589
3697
  */
3590
3698
  end_time: string;
3699
+ /**
3700
+ * Token Count Prompt
3701
+ * @description Cumulative prompt token count across all spans in the trace.
3702
+ * @default 0
3703
+ */
3704
+ token_count_prompt?: number;
3705
+ /**
3706
+ * Token Count Completion
3707
+ * @description Cumulative completion token count across all spans in the trace.
3708
+ * @default 0
3709
+ */
3710
+ token_count_completion?: number;
3711
+ /**
3712
+ * Token Count Total
3713
+ * @description Cumulative total token count across all spans in the trace (prompt + completion).
3714
+ * @default 0
3715
+ */
3716
+ token_count_total?: number;
3591
3717
  /** Spans */
3592
3718
  spans?: components["schemas"]["TraceSpanData"][] | null;
3593
3719
  };
@@ -4037,6 +4163,67 @@ export interface operations {
4037
4163
  };
4038
4164
  };
4039
4165
  };
4166
+ deleteSpanAnnotations: {
4167
+ parameters: {
4168
+ query?: {
4169
+ /** @description Optional annotation name. When provided, must be non-empty and narrows the delete to annotations of that name. */
4170
+ name?: string | null;
4171
+ /** @description Optional annotation identifier. When provided, must be non-empty and narrows the delete to annotations with that identifier. */
4172
+ identifier?: string | null;
4173
+ /** @description Optional annotator kind. When provided, narrows the delete to annotations produced by this annotator kind. */
4174
+ annotator_kind?: ("LLM" | "CODE" | "HUMAN") | null;
4175
+ /** @description Optional inclusive lower bound on `created_at` (>=). Naive datetimes are interpreted as UTC. */
4176
+ start_time?: string | null;
4177
+ /** @description Optional exclusive upper bound on `created_at` (<). Naive datetimes are interpreted as UTC. */
4178
+ end_time?: string | null;
4179
+ /** @description Opt-in flag that authorizes the request without a bounded `[start_time, end_time)` time window. When `false` (default) or absent, the request must supply both `start_time` AND `end_time` to bound the delete. When `true`, the time-range bound is waived and any other filters (`name`, `identifier`, `annotator_kind`) still narrow the delete within the project — e.g. `delete_all=true&name=X` deletes all annotations named X regardless of time. */
4180
+ delete_all?: boolean;
4181
+ };
4182
+ header?: never;
4183
+ path: {
4184
+ /** @description The project identifier: either project ID or project name. If using a project name as the identifier, it cannot contain slash (/), question mark (?), or pound sign (#) characters. */
4185
+ project_identifier: string;
4186
+ };
4187
+ cookie?: never;
4188
+ };
4189
+ requestBody?: never;
4190
+ responses: {
4191
+ /** @description Successful Response */
4192
+ 204: {
4193
+ headers: {
4194
+ [name: string]: unknown;
4195
+ };
4196
+ content?: never;
4197
+ };
4198
+ /** @description Forbidden */
4199
+ 403: {
4200
+ headers: {
4201
+ [name: string]: unknown;
4202
+ };
4203
+ content: {
4204
+ "text/plain": string;
4205
+ };
4206
+ };
4207
+ /** @description Project not found */
4208
+ 404: {
4209
+ headers: {
4210
+ [name: string]: unknown;
4211
+ };
4212
+ content: {
4213
+ "text/plain": string;
4214
+ };
4215
+ };
4216
+ /** @description Invalid parameters */
4217
+ 422: {
4218
+ headers: {
4219
+ [name: string]: unknown;
4220
+ };
4221
+ content: {
4222
+ "text/plain": string;
4223
+ };
4224
+ };
4225
+ };
4226
+ };
4040
4227
  listTraceAnnotationsByTraceIds: {
4041
4228
  parameters: {
4042
4229
  query?: {
@@ -4100,6 +4287,67 @@ export interface operations {
4100
4287
  };
4101
4288
  };
4102
4289
  };
4290
+ deleteTraceAnnotations: {
4291
+ parameters: {
4292
+ query?: {
4293
+ /** @description Optional annotation name. When provided, must be non-empty and narrows the delete to annotations of that name. */
4294
+ name?: string | null;
4295
+ /** @description Optional annotation identifier. When provided, must be non-empty and narrows the delete to annotations with that identifier. */
4296
+ identifier?: string | null;
4297
+ /** @description Optional annotator kind. When provided, narrows the delete to annotations produced by this annotator kind. */
4298
+ annotator_kind?: ("LLM" | "CODE" | "HUMAN") | null;
4299
+ /** @description Optional inclusive lower bound on `created_at` (>=). Naive datetimes are interpreted as UTC. */
4300
+ start_time?: string | null;
4301
+ /** @description Optional exclusive upper bound on `created_at` (<). Naive datetimes are interpreted as UTC. */
4302
+ end_time?: string | null;
4303
+ /** @description Opt-in flag that authorizes the request without a bounded `[start_time, end_time)` time window. When `false` (default) or absent, the request must supply both `start_time` AND `end_time` to bound the delete. When `true`, the time-range bound is waived and any other filters (`name`, `identifier`, `annotator_kind`) still narrow the delete within the project — e.g. `delete_all=true&name=X` deletes all annotations named X regardless of time. */
4304
+ delete_all?: boolean;
4305
+ };
4306
+ header?: never;
4307
+ path: {
4308
+ /** @description The project identifier: either project ID or project name. If using a project name as the identifier, it cannot contain slash (/), question mark (?), or pound sign (#) characters. */
4309
+ project_identifier: string;
4310
+ };
4311
+ cookie?: never;
4312
+ };
4313
+ requestBody?: never;
4314
+ responses: {
4315
+ /** @description Successful Response */
4316
+ 204: {
4317
+ headers: {
4318
+ [name: string]: unknown;
4319
+ };
4320
+ content?: never;
4321
+ };
4322
+ /** @description Forbidden */
4323
+ 403: {
4324
+ headers: {
4325
+ [name: string]: unknown;
4326
+ };
4327
+ content: {
4328
+ "text/plain": string;
4329
+ };
4330
+ };
4331
+ /** @description Project not found */
4332
+ 404: {
4333
+ headers: {
4334
+ [name: string]: unknown;
4335
+ };
4336
+ content: {
4337
+ "text/plain": string;
4338
+ };
4339
+ };
4340
+ /** @description Invalid parameters */
4341
+ 422: {
4342
+ headers: {
4343
+ [name: string]: unknown;
4344
+ };
4345
+ content: {
4346
+ "text/plain": string;
4347
+ };
4348
+ };
4349
+ };
4350
+ };
4103
4351
  listSessionAnnotationsBySessionIds: {
4104
4352
  parameters: {
4105
4353
  query?: {
@@ -4163,6 +4411,67 @@ export interface operations {
4163
4411
  };
4164
4412
  };
4165
4413
  };
4414
+ deleteSessionAnnotations: {
4415
+ parameters: {
4416
+ query?: {
4417
+ /** @description Optional annotation name. When provided, must be non-empty and narrows the delete to annotations of that name. */
4418
+ name?: string | null;
4419
+ /** @description Optional annotation identifier. When provided, must be non-empty and narrows the delete to annotations with that identifier. */
4420
+ identifier?: string | null;
4421
+ /** @description Optional annotator kind. When provided, narrows the delete to annotations produced by this annotator kind. */
4422
+ annotator_kind?: ("LLM" | "CODE" | "HUMAN") | null;
4423
+ /** @description Optional inclusive lower bound on `created_at` (>=). Naive datetimes are interpreted as UTC. */
4424
+ start_time?: string | null;
4425
+ /** @description Optional exclusive upper bound on `created_at` (<). Naive datetimes are interpreted as UTC. */
4426
+ end_time?: string | null;
4427
+ /** @description Opt-in flag that authorizes the request without a bounded `[start_time, end_time)` time window. When `false` (default) or absent, the request must supply both `start_time` AND `end_time` to bound the delete. When `true`, the time-range bound is waived and any other filters (`name`, `identifier`, `annotator_kind`) still narrow the delete within the project — e.g. `delete_all=true&name=X` deletes all annotations named X regardless of time. */
4428
+ delete_all?: boolean;
4429
+ };
4430
+ header?: never;
4431
+ path: {
4432
+ /** @description The project identifier: either project ID or project name. If using a project name as the identifier, it cannot contain slash (/), question mark (?), or pound sign (#) characters. */
4433
+ project_identifier: string;
4434
+ };
4435
+ cookie?: never;
4436
+ };
4437
+ requestBody?: never;
4438
+ responses: {
4439
+ /** @description Successful Response */
4440
+ 204: {
4441
+ headers: {
4442
+ [name: string]: unknown;
4443
+ };
4444
+ content?: never;
4445
+ };
4446
+ /** @description Forbidden */
4447
+ 403: {
4448
+ headers: {
4449
+ [name: string]: unknown;
4450
+ };
4451
+ content: {
4452
+ "text/plain": string;
4453
+ };
4454
+ };
4455
+ /** @description Project not found */
4456
+ 404: {
4457
+ headers: {
4458
+ [name: string]: unknown;
4459
+ };
4460
+ content: {
4461
+ "text/plain": string;
4462
+ };
4463
+ };
4464
+ /** @description Invalid parameters */
4465
+ 422: {
4466
+ headers: {
4467
+ [name: string]: unknown;
4468
+ };
4469
+ content: {
4470
+ "text/plain": string;
4471
+ };
4472
+ };
4473
+ };
4474
+ };
4166
4475
  listDatasets: {
4167
4476
  parameters: {
4168
4477
  query?: {
@@ -7,9 +7,27 @@ import {
7
7
  safelyConvertToolDefinitionToProvider,
8
8
  } from "../../schemas/llm/converters";
9
9
  import { findToolDefinitionName } from "../../schemas/llm/utils";
10
+ import type { PromptToolRaw } from "../../types/prompts";
11
+ import { isPromptToolRaw } from "../../types/prompts";
10
12
  import { formatPromptMessages } from "../../utils/formatPromptMessages";
11
13
  import type { Variables, toSDKParamsBase } from "./types";
12
14
 
15
+ /**
16
+ * Best-effort name for a vendor-passthrough (raw) tool. Vercel AI SDK keys its
17
+ * `tools` record by tool name, so we need a stable string identifier even when
18
+ * the raw payload doesn't carry a conventional `name` field — fall back to
19
+ * `type` (e.g. "web_search") which the Responses-style SDKs use as the key.
20
+ */
21
+ const getRawToolName = (tool: PromptToolRaw): string | null => {
22
+ if (typeof tool.raw.name === "string") {
23
+ return tool.raw.name;
24
+ }
25
+ if (typeof tool.raw.type === "string") {
26
+ return tool.raw.type;
27
+ }
28
+ return null;
29
+ };
30
+
13
31
  export type PartialAIParams = {
14
32
  messages: ModelMessage[];
15
33
  /**
@@ -67,23 +85,27 @@ export const toAI = <V extends Variables>({
67
85
  return vercelAIMessage;
68
86
  });
69
87
 
88
+ const toolsList = prompt.tools?.tools ?? [];
70
89
  let tools: ToolSet | undefined;
71
- if (prompt.tools?.tools && prompt.tools.tools.length > 0) {
90
+ if (toolsList.length > 0) {
72
91
  const toolsRecord: Record<string, unknown> = {};
73
- for (const tool of prompt.tools.tools) {
74
- const name = findToolDefinitionName(tool);
92
+ for (const tool of toolsList) {
93
+ const name = isPromptToolRaw(tool)
94
+ ? getRawToolName(tool)
95
+ : findToolDefinitionName(tool);
75
96
  invariant(name, "Tool definition name is not valid");
76
- const converted = safelyConvertToolDefinitionToProvider({
77
- toolDefinition: tool,
78
- targetProvider: "VERCEL_AI",
79
- });
97
+ const converted = isPromptToolRaw(tool)
98
+ ? tool.raw
99
+ : safelyConvertToolDefinitionToProvider({
100
+ toolDefinition: tool,
101
+ targetProvider: "VERCEL_AI",
102
+ });
80
103
  invariant(converted, "Tool definition is not valid");
81
104
  toolsRecord[name] = converted;
82
105
  }
83
- tools =
84
- Object.keys(toolsRecord).length > 0
85
- ? (toolsRecord as ToolSet)
86
- : undefined;
106
+ if (Object.keys(toolsRecord).length > 0) {
107
+ tools = toolsRecord as ToolSet;
108
+ }
87
109
  }
88
110
 
89
111
  let toolChoice: PartialAIParams["toolChoice"];
@@ -7,6 +7,7 @@ import {
7
7
  safelyConvertToolChoiceToProvider,
8
8
  safelyConvertToolDefinitionToProvider,
9
9
  } from "../../schemas/llm/converters";
10
+ import { isPromptToolRaw } from "../../types/prompts";
10
11
  import { formatPromptMessages } from "../../utils/formatPromptMessages";
11
12
  import type { toSDKParamsBase, Variables } from "./types";
12
13
 
@@ -62,22 +63,32 @@ export const toAnthropic = <V extends Variables = Variables>({
62
63
  return anthropicMessage;
63
64
  });
64
65
 
65
- let tools = prompt.tools?.tools.map((tool) => {
66
- const anthropicToolDefinition = safelyConvertToolDefinitionToProvider({
67
- toolDefinition: tool,
68
- targetProvider: "ANTHROPIC",
69
- });
70
- invariant(anthropicToolDefinition, "Tool definition is not valid");
71
- return anthropicToolDefinition;
72
- });
73
- tools = (tools?.length ?? 0) > 0 ? tools : undefined;
66
+ const toolsList = prompt.tools?.tools ?? [];
67
+ // Cast: raw tools are `Record<string, unknown>` straight from the prompt
68
+ // store. We trust the upstream caller to have stored a shape Anthropic's
69
+ // SDK accepts; no validation here.
70
+ const tools =
71
+ toolsList.length === 0
72
+ ? undefined
73
+ : (toolsList.map((tool) => {
74
+ if (isPromptToolRaw(tool)) {
75
+ return tool.raw;
76
+ }
77
+ const anthropicToolDefinition =
78
+ safelyConvertToolDefinitionToProvider({
79
+ toolDefinition: tool,
80
+ targetProvider: "ANTHROPIC",
81
+ });
82
+ invariant(anthropicToolDefinition, "Tool definition is not valid");
83
+ return anthropicToolDefinition;
84
+ }) as MessageCreateParams["tools"]);
74
85
 
75
- let tool_choice: AnthropicToolChoice | undefined =
76
- safelyConvertToolChoiceToProvider({
77
- toolChoice: prompt?.tools?.tool_choice,
78
- targetProvider: "ANTHROPIC",
79
- }) || undefined;
80
- tool_choice = tools?.length ? tool_choice : undefined;
86
+ const tool_choice: AnthropicToolChoice | undefined = tools
87
+ ? (safelyConvertToolChoiceToProvider({
88
+ toolChoice: prompt?.tools?.tool_choice,
89
+ targetProvider: "ANTHROPIC",
90
+ }) ?? undefined)
91
+ : undefined;
81
92
 
82
93
  // combine base and computed params
83
94
  const completionParams = {
@@ -12,6 +12,7 @@ import {
12
12
  } from "../../schemas/llm/converters";
13
13
  import type { OpenaiToolChoice } from "../../schemas/llm/openai/toolChoiceSchemas";
14
14
  import { phoenixResponseFormatToOpenAI } from "../../schemas/llm/phoenixPrompt/converters";
15
+ import { isPromptToolRaw } from "../../types/prompts";
15
16
  import { formatPromptMessages } from "../../utils/formatPromptMessages";
16
17
  import type { toSDKParamsBase, Variables } from "./types";
17
18
 
@@ -74,22 +75,31 @@ export const toOpenAI = <V extends Variables = Variables>({
74
75
  return openAIMessage;
75
76
  });
76
77
 
77
- let tools = prompt.tools?.tools.map((tool) => {
78
- const openAIToolDefinition = safelyConvertToolDefinitionToProvider({
79
- toolDefinition: tool,
80
- targetProvider: "OPENAI",
81
- });
82
- invariant(openAIToolDefinition, "Tool definition is not valid");
83
- return openAIToolDefinition;
84
- });
85
- tools = (tools?.length ?? 0) > 0 ? tools : undefined;
78
+ const toolsList = prompt.tools?.tools ?? [];
79
+ // Cast: raw tools are `Record<string, unknown>` straight from the prompt
80
+ // store. We trust the upstream caller to have stored a shape OpenAI's
81
+ // SDK accepts; no validation here.
82
+ const tools =
83
+ toolsList.length === 0
84
+ ? undefined
85
+ : (toolsList.map((tool) => {
86
+ if (isPromptToolRaw(tool)) {
87
+ return tool.raw;
88
+ }
89
+ const openAIToolDefinition = safelyConvertToolDefinitionToProvider({
90
+ toolDefinition: tool,
91
+ targetProvider: "OPENAI",
92
+ });
93
+ invariant(openAIToolDefinition, "Tool definition is not valid");
94
+ return openAIToolDefinition;
95
+ }) as unknown as ChatCompletionCreateParams["tools"]);
86
96
 
87
- let tool_choice: OpenaiToolChoice | undefined =
88
- safelyConvertToolChoiceToProvider({
89
- toolChoice: prompt?.tools?.tool_choice,
90
- targetProvider: "OPENAI",
91
- }) || undefined;
92
- tool_choice = tools?.length ? tool_choice : undefined;
97
+ const tool_choice: OpenaiToolChoice | undefined = tools
98
+ ? (safelyConvertToolChoiceToProvider({
99
+ toolChoice: prompt?.tools?.tool_choice,
100
+ targetProvider: "OPENAI",
101
+ }) ?? undefined)
102
+ : undefined;
93
103
 
94
104
  const response_format = prompt.response_format
95
105
  ? phoenixResponseFormatToOpenAI.parse(prompt.response_format)
@@ -16,7 +16,7 @@ import { phoenixMessageSchema } from "./messageSchemas";
16
16
  import { phoenixResponseFormatSchema } from "./responseFormatSchema";
17
17
  import { phoenixToolCallSchema } from "./toolCallSchemas";
18
18
  import { phoenixToolChoiceSchema } from "./toolChoiceSchemas";
19
- import { phoenixToolDefinitionSchema } from "./toolSchemas";
19
+ import { phoenixToolFunctionDefinitionSchema } from "./toolSchemas";
20
20
 
21
21
  /*
22
22
  * Conversion Functions
@@ -150,7 +150,7 @@ export const phoenixToolCallToOpenAI = phoenixToolCallSchema.transform(
150
150
  );
151
151
 
152
152
  export const phoenixToolDefinitionToOpenAI =
153
- phoenixToolDefinitionSchema.transform(
153
+ phoenixToolFunctionDefinitionSchema.transform(
154
154
  (phoenix): OpenAIToolDefinition => ({
155
155
  type: "function",
156
156
  function: {
@@ -1,21 +1,24 @@
1
1
  import z from "zod";
2
2
 
3
- import type { PromptTool } from "../../../types/prompts";
3
+ import type { PromptToolFunction } from "../../../types/prompts";
4
4
  import { schemaMatches } from "../../../utils/schemaMatches";
5
5
 
6
6
  /**
7
7
  * The Phoenix tool definition schema
8
8
  */
9
- export const phoenixToolDefinitionSchema = schemaMatches<PromptTool>()(
10
- z.object({
11
- type: z.literal("function"),
12
- function: z.object({
13
- name: z.string(),
14
- description: z.string().optional(),
15
- parameters: z.record(z.string(), z.unknown()).optional(),
16
- strict: z.boolean().optional(),
17
- }),
18
- })
19
- );
9
+ export const phoenixToolFunctionDefinitionSchema =
10
+ schemaMatches<PromptToolFunction>()(
11
+ z.object({
12
+ type: z.literal("function"),
13
+ function: z.object({
14
+ name: z.string(),
15
+ description: z.string().optional(),
16
+ parameters: z.record(z.string(), z.unknown()).optional(),
17
+ strict: z.boolean().optional(),
18
+ }),
19
+ })
20
+ );
20
21
 
21
- export type PhoenixToolDefinition = z.infer<typeof phoenixToolDefinitionSchema>;
22
+ export type PhoenixToolDefinition = z.infer<
23
+ typeof phoenixToolFunctionDefinitionSchema
24
+ >;
@@ -11,7 +11,7 @@ import { openAIToolDefinitionSchema } from "./openai/toolSchemas";
11
11
  import { phoenixMessageSchema } from "./phoenixPrompt/messageSchemas";
12
12
  import { phoenixToolCallSchema } from "./phoenixPrompt/toolCallSchemas";
13
13
  import { phoenixToolChoiceSchema } from "./phoenixPrompt/toolChoiceSchemas";
14
- import { phoenixToolDefinitionSchema } from "./phoenixPrompt/toolSchemas";
14
+ import { phoenixToolFunctionDefinitionSchema } from "./phoenixPrompt/toolSchemas";
15
15
  import { vercelAIChatPartToolCallSchema } from "./vercel/messagePartSchemas";
16
16
  import { vercelAIMessageSchema } from "./vercel/messageSchemas";
17
17
  import { vercelAIToolChoiceSchema } from "./vercel/toolChoiceSchemas";
@@ -87,7 +87,7 @@ export type LlmProviderToolChoice = z.infer<typeof llmProviderToolChoiceSchema>;
87
87
  export const llmProviderToolDefinitionSchema = z.union([
88
88
  openAIToolDefinitionSchema,
89
89
  anthropicToolDefinitionSchema,
90
- phoenixToolDefinitionSchema,
90
+ phoenixToolFunctionDefinitionSchema,
91
91
  ]);
92
92
 
93
93
  export type LlmProviderToolDefinition = z.infer<