@arizeai/phoenix-client 3.1.0 → 4.0.0

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 (120) hide show
  1. package/README.md +22 -1
  2. package/dist/esm/__generated__/api/v1.d.ts +185 -47
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/prompts/sdks/toAI.d.ts +13 -3
  5. package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -1
  6. package/dist/esm/prompts/sdks/toAI.js +23 -15
  7. package/dist/esm/prompts/sdks/toAI.js.map +1 -1
  8. package/dist/esm/prompts/sdks/toSDK.d.ts +1 -1
  9. package/dist/esm/schemas/llm/constants.d.ts +30 -12
  10. package/dist/esm/schemas/llm/constants.d.ts.map +1 -1
  11. package/dist/esm/schemas/llm/converters.d.ts +120 -48
  12. package/dist/esm/schemas/llm/converters.d.ts.map +1 -1
  13. package/dist/esm/schemas/llm/openai/converters.d.ts +6 -3
  14. package/dist/esm/schemas/llm/openai/converters.d.ts.map +1 -1
  15. package/dist/esm/schemas/llm/openai/converters.js +7 -4
  16. package/dist/esm/schemas/llm/openai/converters.js.map +1 -1
  17. package/dist/esm/schemas/llm/schemas.d.ts +37 -16
  18. package/dist/esm/schemas/llm/schemas.d.ts.map +1 -1
  19. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts +42 -12
  20. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -1
  21. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js +5 -2
  22. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js.map +1 -1
  23. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts +31 -10
  24. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts.map +1 -1
  25. package/dist/esm/schemas/llm/vercel/toolSchemas.d.ts +3 -3
  26. package/dist/esm/schemas/llm/vercel/toolSchemas.js +1 -1
  27. package/dist/esm/schemas/llm/vercel/toolSchemas.js.map +1 -1
  28. package/dist/esm/spans/addDocumentAnnotation.d.ts +45 -0
  29. package/dist/esm/spans/addDocumentAnnotation.d.ts.map +1 -0
  30. package/dist/esm/spans/addDocumentAnnotation.js +45 -0
  31. package/dist/esm/spans/addDocumentAnnotation.js.map +1 -0
  32. package/dist/esm/spans/addSpanAnnotation.d.ts +8 -2
  33. package/dist/esm/spans/addSpanAnnotation.d.ts.map +1 -1
  34. package/dist/esm/spans/addSpanAnnotation.js +5 -5
  35. package/dist/esm/spans/addSpanAnnotation.js.map +1 -1
  36. package/dist/esm/spans/index.d.ts +2 -0
  37. package/dist/esm/spans/index.d.ts.map +1 -1
  38. package/dist/esm/spans/index.js +2 -0
  39. package/dist/esm/spans/index.js.map +1 -1
  40. package/dist/esm/spans/logDocumentAnnotations.d.ts +58 -0
  41. package/dist/esm/spans/logDocumentAnnotations.d.ts.map +1 -0
  42. package/dist/esm/spans/logDocumentAnnotations.js +55 -0
  43. package/dist/esm/spans/logDocumentAnnotations.js.map +1 -0
  44. package/dist/esm/spans/logSpanAnnotations.d.ts +7 -1
  45. package/dist/esm/spans/logSpanAnnotations.d.ts.map +1 -1
  46. package/dist/esm/spans/logSpanAnnotations.js +5 -5
  47. package/dist/esm/spans/logSpanAnnotations.js.map +1 -1
  48. package/dist/esm/spans/types.d.ts +48 -0
  49. package/dist/esm/spans/types.d.ts.map +1 -1
  50. package/dist/esm/spans/types.js +41 -8
  51. package/dist/esm/spans/types.js.map +1 -1
  52. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  53. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  54. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  55. package/dist/src/__generated__/api/v1.d.ts +185 -47
  56. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  57. package/dist/src/prompts/sdks/toAI.d.ts +13 -3
  58. package/dist/src/prompts/sdks/toAI.d.ts.map +1 -1
  59. package/dist/src/prompts/sdks/toAI.js +24 -16
  60. package/dist/src/prompts/sdks/toAI.js.map +1 -1
  61. package/dist/src/prompts/sdks/toSDK.d.ts +1 -1
  62. package/dist/src/schemas/llm/constants.d.ts +30 -12
  63. package/dist/src/schemas/llm/constants.d.ts.map +1 -1
  64. package/dist/src/schemas/llm/converters.d.ts +120 -48
  65. package/dist/src/schemas/llm/converters.d.ts.map +1 -1
  66. package/dist/src/schemas/llm/openai/converters.d.ts +6 -3
  67. package/dist/src/schemas/llm/openai/converters.d.ts.map +1 -1
  68. package/dist/src/schemas/llm/openai/converters.js +7 -4
  69. package/dist/src/schemas/llm/openai/converters.js.map +1 -1
  70. package/dist/src/schemas/llm/schemas.d.ts +37 -16
  71. package/dist/src/schemas/llm/schemas.d.ts.map +1 -1
  72. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts +42 -12
  73. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -1
  74. package/dist/src/schemas/llm/vercel/messagePartSchemas.js +5 -2
  75. package/dist/src/schemas/llm/vercel/messagePartSchemas.js.map +1 -1
  76. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts +31 -10
  77. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts.map +1 -1
  78. package/dist/src/schemas/llm/vercel/toolSchemas.d.ts +3 -3
  79. package/dist/src/schemas/llm/vercel/toolSchemas.js +1 -1
  80. package/dist/src/schemas/llm/vercel/toolSchemas.js.map +1 -1
  81. package/dist/src/spans/addDocumentAnnotation.d.ts +45 -0
  82. package/dist/src/spans/addDocumentAnnotation.d.ts.map +1 -0
  83. package/dist/src/spans/addDocumentAnnotation.js +49 -0
  84. package/dist/src/spans/addDocumentAnnotation.js.map +1 -0
  85. package/dist/src/spans/addSpanAnnotation.d.ts +8 -2
  86. package/dist/src/spans/addSpanAnnotation.d.ts.map +1 -1
  87. package/dist/src/spans/addSpanAnnotation.js +6 -6
  88. package/dist/src/spans/addSpanAnnotation.js.map +1 -1
  89. package/dist/src/spans/index.d.ts +2 -0
  90. package/dist/src/spans/index.d.ts.map +1 -1
  91. package/dist/src/spans/index.js +2 -0
  92. package/dist/src/spans/index.js.map +1 -1
  93. package/dist/src/spans/logDocumentAnnotations.d.ts +58 -0
  94. package/dist/src/spans/logDocumentAnnotations.d.ts.map +1 -0
  95. package/dist/src/spans/logDocumentAnnotations.js +58 -0
  96. package/dist/src/spans/logDocumentAnnotations.js.map +1 -0
  97. package/dist/src/spans/logSpanAnnotations.d.ts +7 -1
  98. package/dist/src/spans/logSpanAnnotations.d.ts.map +1 -1
  99. package/dist/src/spans/logSpanAnnotations.js +5 -6
  100. package/dist/src/spans/logSpanAnnotations.js.map +1 -1
  101. package/dist/src/spans/types.d.ts +48 -0
  102. package/dist/src/spans/types.d.ts.map +1 -1
  103. package/dist/src/spans/types.js +45 -10
  104. package/dist/src/spans/types.js.map +1 -1
  105. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  106. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  107. package/dist/tsconfig.tsbuildinfo +1 -1
  108. package/package.json +4 -4
  109. package/src/__generated__/api/v1.d.ts +1240 -1238
  110. package/src/__generated__/api/v1.ts +185 -47
  111. package/src/prompts/sdks/toAI.ts +42 -32
  112. package/src/schemas/llm/openai/converters.ts +7 -4
  113. package/src/schemas/llm/vercel/messagePartSchemas.ts +5 -2
  114. package/src/schemas/llm/vercel/toolSchemas.ts +1 -1
  115. package/src/spans/addDocumentAnnotation.ts +66 -0
  116. package/src/spans/addSpanAnnotation.ts +12 -6
  117. package/src/spans/index.ts +2 -0
  118. package/src/spans/logDocumentAnnotations.ts +79 -0
  119. package/src/spans/logSpanAnnotations.ts +11 -5
  120. package/src/spans/types.ts +112 -8
@@ -290,7 +290,10 @@ export interface paths {
290
290
  path?: never;
291
291
  cookie?: never;
292
292
  };
293
- /** List runs for an experiment */
293
+ /**
294
+ * List runs for an experiment
295
+ * @description Retrieve a paginated list of runs for an experiment
296
+ */
294
297
  get: operations["listExperimentRuns"];
295
298
  put?: never;
296
299
  /** Create run for an experiment */
@@ -633,6 +636,23 @@ export interface paths {
633
636
  patch?: never;
634
637
  trace?: never;
635
638
  };
639
+ "/v1/document_annotations": {
640
+ parameters: {
641
+ query?: never;
642
+ header?: never;
643
+ path?: never;
644
+ cookie?: never;
645
+ };
646
+ get?: never;
647
+ put?: never;
648
+ /** Annotate Span Documents */
649
+ post: operations["annotateSpanDocuments"];
650
+ delete?: never;
651
+ options?: never;
652
+ head?: never;
653
+ patch?: never;
654
+ trace?: never;
655
+ };
636
656
  "/v1/users": {
637
657
  parameters: {
638
658
  query?: never;
@@ -681,6 +701,16 @@ export interface paths {
681
701
  export type webhooks = Record<string, never>;
682
702
  export interface components {
683
703
  schemas: {
704
+ /** AnnotateSpanDocumentsRequestBody */
705
+ AnnotateSpanDocumentsRequestBody: {
706
+ /** Data */
707
+ data: components["schemas"]["SpanDocumentAnnotationData"][];
708
+ };
709
+ /** AnnotateSpanDocumentsResponseBody */
710
+ AnnotateSpanDocumentsResponseBody: {
711
+ /** Data */
712
+ data: components["schemas"]["InsertedSpanDocumentAnnotation"][];
713
+ };
684
714
  /** AnnotateSpansRequestBody */
685
715
  AnnotateSpansRequestBody: {
686
716
  /** Data */
@@ -691,6 +721,24 @@ export interface components {
691
721
  /** Data */
692
722
  data: components["schemas"]["InsertedSpanAnnotation"][];
693
723
  };
724
+ /** AnnotationResult */
725
+ AnnotationResult: {
726
+ /**
727
+ * Label
728
+ * @description The label assigned by the annotation
729
+ */
730
+ label?: string | null;
731
+ /**
732
+ * Score
733
+ * @description The score assigned by the annotation
734
+ */
735
+ score?: number | null;
736
+ /**
737
+ * Explanation
738
+ * @description Explanation of the annotation result
739
+ */
740
+ explanation?: string | null;
741
+ };
694
742
  /** CategoricalAnnotationConfig */
695
743
  CategoricalAnnotationConfig: {
696
744
  /** Name */
@@ -1228,6 +1276,14 @@ export interface components {
1228
1276
  */
1229
1277
  id: string;
1230
1278
  };
1279
+ /** InsertedSpanDocumentAnnotation */
1280
+ InsertedSpanDocumentAnnotation: {
1281
+ /**
1282
+ * Id
1283
+ * @description The ID of the inserted span document annotation
1284
+ */
1285
+ id: string;
1286
+ };
1231
1287
  /** ListDatasetExamplesData */
1232
1288
  ListDatasetExamplesData: {
1233
1289
  /** Dataset Id */
@@ -1259,6 +1315,8 @@ export interface components {
1259
1315
  ListExperimentRunsResponseBody: {
1260
1316
  /** Data */
1261
1317
  data: components["schemas"]["ExperimentRunResponse"][];
1318
+ /** Next Cursor */
1319
+ next_cursor: string | null;
1262
1320
  };
1263
1321
  /** ListExperimentsResponseBody */
1264
1322
  ListExperimentsResponseBody: {
@@ -2097,11 +2155,25 @@ export interface components {
2097
2155
  };
2098
2156
  /** SpanAnnotation */
2099
2157
  SpanAnnotation: {
2158
+ /** Id */
2159
+ id: string;
2100
2160
  /**
2101
- * Span Id
2102
- * @description OpenTelemetry Span ID (hex format w/o 0x prefix)
2161
+ * Created At
2162
+ * Format: date-time
2103
2163
  */
2104
- span_id: string;
2164
+ created_at: string;
2165
+ /**
2166
+ * Updated At
2167
+ * Format: date-time
2168
+ */
2169
+ updated_at: string;
2170
+ /**
2171
+ * Source
2172
+ * @enum {string}
2173
+ */
2174
+ source: "API" | "APP";
2175
+ /** User Id */
2176
+ user_id: string | null;
2105
2177
  /**
2106
2178
  * Name
2107
2179
  * @description The name of the annotation
@@ -2114,7 +2186,7 @@ export interface components {
2114
2186
  */
2115
2187
  annotator_kind: "LLM" | "CODE" | "HUMAN";
2116
2188
  /** @description The result of the annotation */
2117
- result?: components["schemas"]["SpanAnnotationResult"] | null;
2189
+ result?: components["schemas"]["AnnotationResult"] | null;
2118
2190
  /**
2119
2191
  * Metadata
2120
2192
  * @description Metadata for the annotation
@@ -2128,33 +2200,14 @@ export interface components {
2128
2200
  * @default
2129
2201
  */
2130
2202
  identifier?: string;
2131
- /** Id */
2132
- id: string;
2133
- /**
2134
- * Created At
2135
- * Format: date-time
2136
- */
2137
- created_at: string;
2138
- /**
2139
- * Updated At
2140
- * Format: date-time
2141
- */
2142
- updated_at: string;
2143
- /**
2144
- * Source
2145
- * @enum {string}
2146
- */
2147
- source: "API" | "APP";
2148
- /** User Id */
2149
- user_id: string | null;
2150
- };
2151
- /** SpanAnnotationData */
2152
- SpanAnnotationData: {
2153
2203
  /**
2154
2204
  * Span Id
2155
2205
  * @description OpenTelemetry Span ID (hex format w/o 0x prefix)
2156
2206
  */
2157
2207
  span_id: string;
2208
+ };
2209
+ /** SpanAnnotationData */
2210
+ SpanAnnotationData: {
2158
2211
  /**
2159
2212
  * Name
2160
2213
  * @description The name of the annotation
@@ -2167,7 +2220,7 @@ export interface components {
2167
2220
  */
2168
2221
  annotator_kind: "LLM" | "CODE" | "HUMAN";
2169
2222
  /** @description The result of the annotation */
2170
- result?: components["schemas"]["SpanAnnotationResult"] | null;
2223
+ result?: components["schemas"]["AnnotationResult"] | null;
2171
2224
  /**
2172
2225
  * Metadata
2173
2226
  * @description Metadata for the annotation
@@ -2181,24 +2234,11 @@ export interface components {
2181
2234
  * @default
2182
2235
  */
2183
2236
  identifier?: string;
2184
- };
2185
- /** SpanAnnotationResult */
2186
- SpanAnnotationResult: {
2187
- /**
2188
- * Label
2189
- * @description The label assigned by the annotation
2190
- */
2191
- label?: string | null;
2192
2237
  /**
2193
- * Score
2194
- * @description The score assigned by the annotation
2195
- */
2196
- score?: number | null;
2197
- /**
2198
- * Explanation
2199
- * @description Explanation of the annotation result
2238
+ * Span Id
2239
+ * @description OpenTelemetry Span ID (hex format w/o 0x prefix)
2200
2240
  */
2201
- explanation?: string | null;
2241
+ span_id: string;
2202
2242
  };
2203
2243
  /** SpanAnnotationsResponseBody */
2204
2244
  SpanAnnotationsResponseBody: {
@@ -2220,6 +2260,45 @@ export interface components {
2220
2260
  */
2221
2261
  span_id: string;
2222
2262
  };
2263
+ /** SpanDocumentAnnotationData */
2264
+ SpanDocumentAnnotationData: {
2265
+ /**
2266
+ * Name
2267
+ * @description The name of the annotation
2268
+ */
2269
+ name: string;
2270
+ /**
2271
+ * Annotator Kind
2272
+ * @description The kind of annotator used for the annotation
2273
+ * @enum {string}
2274
+ */
2275
+ annotator_kind: "LLM" | "CODE" | "HUMAN";
2276
+ /** @description The result of the annotation */
2277
+ result?: components["schemas"]["AnnotationResult"] | null;
2278
+ /**
2279
+ * Metadata
2280
+ * @description Metadata for the annotation
2281
+ */
2282
+ metadata?: {
2283
+ [key: string]: unknown;
2284
+ } | null;
2285
+ /**
2286
+ * Identifier
2287
+ * @description The identifier of the annotation. If provided, the annotation will be updated if it already exists.
2288
+ * @default
2289
+ */
2290
+ identifier?: string;
2291
+ /**
2292
+ * Span Id
2293
+ * @description OpenTelemetry Span ID (hex format w/o 0x prefix)
2294
+ */
2295
+ span_id: string;
2296
+ /**
2297
+ * Document Position
2298
+ * @description A 0 based index of the document. E.x. the first document during retrieval is 0
2299
+ */
2300
+ document_position: number;
2301
+ };
2223
2302
  /** SpanEvent */
2224
2303
  SpanEvent: {
2225
2304
  /**
@@ -3355,7 +3434,12 @@ export interface operations {
3355
3434
  };
3356
3435
  listExperimentRuns: {
3357
3436
  parameters: {
3358
- query?: never;
3437
+ query?: {
3438
+ /** @description Cursor for pagination (base64-encoded experiment run ID) */
3439
+ cursor?: string | null;
3440
+ /** @description The max number of experiment runs to return at a time. If not specified, returns all results. */
3441
+ limit?: number | null;
3442
+ };
3359
3443
  header?: never;
3360
3444
  path: {
3361
3445
  experiment_id: string;
@@ -3391,13 +3475,13 @@ export interface operations {
3391
3475
  "text/plain": string;
3392
3476
  };
3393
3477
  };
3394
- /** @description Validation Error */
3478
+ /** @description Invalid cursor format */
3395
3479
  422: {
3396
3480
  headers: {
3397
3481
  [name: string]: unknown;
3398
3482
  };
3399
3483
  content: {
3400
- "application/json": components["schemas"]["HTTPValidationError"];
3484
+ "text/plain": string;
3401
3485
  };
3402
3486
  };
3403
3487
  };
@@ -4587,6 +4671,60 @@ export interface operations {
4587
4671
  };
4588
4672
  };
4589
4673
  };
4674
+ annotateSpanDocuments: {
4675
+ parameters: {
4676
+ query?: {
4677
+ /** @description If set to true, the annotations are inserted synchronously. */
4678
+ sync?: boolean;
4679
+ };
4680
+ header?: never;
4681
+ path?: never;
4682
+ cookie?: never;
4683
+ };
4684
+ requestBody: {
4685
+ content: {
4686
+ "application/json": components["schemas"]["AnnotateSpanDocumentsRequestBody"];
4687
+ };
4688
+ };
4689
+ responses: {
4690
+ /** @description Span document annotation inserted successfully */
4691
+ 200: {
4692
+ headers: {
4693
+ [name: string]: unknown;
4694
+ };
4695
+ content: {
4696
+ "application/json": components["schemas"]["AnnotateSpanDocumentsResponseBody"];
4697
+ };
4698
+ };
4699
+ /** @description Forbidden */
4700
+ 403: {
4701
+ headers: {
4702
+ [name: string]: unknown;
4703
+ };
4704
+ content: {
4705
+ "text/plain": string;
4706
+ };
4707
+ };
4708
+ /** @description Span not found */
4709
+ 404: {
4710
+ headers: {
4711
+ [name: string]: unknown;
4712
+ };
4713
+ content: {
4714
+ "text/plain": string;
4715
+ };
4716
+ };
4717
+ /** @description Invalid request - non-empty identifier not supported */
4718
+ 422: {
4719
+ headers: {
4720
+ [name: string]: unknown;
4721
+ };
4722
+ content: {
4723
+ "text/plain": string;
4724
+ };
4725
+ };
4726
+ };
4727
+ };
4590
4728
  getUsers: {
4591
4729
  parameters: {
4592
4730
  query?: {
@@ -2,22 +2,23 @@ import invariant from "tiny-invariant";
2
2
  import {
3
3
  safelyConvertMessageToProvider,
4
4
  safelyConvertToolChoiceToProvider,
5
- safelyConvertToolDefinitionToProvider,
6
5
  } from "../../schemas/llm/converters";
7
6
  import { formatPromptMessages } from "../../utils/formatPromptMessages";
8
7
  import { Variables, toSDKParamsBase } from "./types";
9
- import {
10
- type streamText,
11
- type generateText,
12
- type ToolSet,
13
- type Tool,
14
- } from "ai";
8
+ import { type ToolSet, type ModelMessage, type ToolChoice } from "ai";
15
9
  import { VercelAIToolChoice } from "../../schemas/llm/vercel/toolChoiceSchemas";
16
10
 
17
- export type PartialStreamTextParams = Omit<
18
- Parameters<typeof streamText>[0] | Parameters<typeof generateText>[0],
19
- "model"
20
- >;
11
+ export type PartialAIParams = {
12
+ messages: ModelMessage[];
13
+ /**
14
+ The tools that the model can call. The model needs to support calling tools.
15
+ */
16
+ tools?: ToolSet;
17
+ /**
18
+ The tool choice strategy. Default: 'auto'.
19
+ */
20
+ toolChoice?: ToolChoice<ToolSet>;
21
+ };
21
22
 
22
23
  export type ToAIParams<V extends Variables> = toSDKParamsBase<V>;
23
24
 
@@ -30,16 +31,16 @@ export type ToAIParams<V extends Variables> = toSDKParamsBase<V>;
30
31
  export const toAI = <V extends Variables>({
31
32
  prompt,
32
33
  variables,
33
- }: ToAIParams<V>): PartialStreamTextParams | null => {
34
+ }: ToAIParams<V>): PartialAIParams | null => {
34
35
  // eslint-disable-next-line no-console
35
36
  console.warn(
36
37
  "Prompt invocation parameters not currently supported in AI SDK, falling back to default invocation parameters"
37
38
  );
38
39
  try {
39
40
  // parts of the prompt that can be directly converted to OpenAI params
40
- const baseCompletionParams = {
41
+ const baseCompletionParams: Partial<PartialAIParams> = {
41
42
  // Invocation parameters are validated on the phoenix-side
42
- } satisfies Partial<PartialStreamTextParams>;
43
+ };
43
44
 
44
45
  if (!("messages" in prompt.template)) {
45
46
  return null;
@@ -55,7 +56,7 @@ export const toAI = <V extends Variables>({
55
56
  );
56
57
  }
57
58
 
58
- const messages = formattedMessages.map((message) => {
59
+ const messages: ModelMessage[] = formattedMessages.map((message) => {
59
60
  const vercelAIMessage = safelyConvertMessageToProvider({
60
61
  message,
61
62
  targetProvider: "VERCEL_AI",
@@ -65,21 +66,30 @@ export const toAI = <V extends Variables>({
65
66
  });
66
67
 
67
68
  // convert tools to Vercel AI tool set, which is a map of tool name to tool
68
- let tools: ToolSet | undefined = prompt.tools?.tools.reduce((acc, tool) => {
69
- if (!tool.function.parameters) {
70
- return acc;
71
- }
72
- const vercelAIToolDefinition = safelyConvertToolDefinitionToProvider({
73
- toolDefinition: tool,
74
- targetProvider: "VERCEL_AI",
75
- });
76
- invariant(vercelAIToolDefinition, "Tool definition is not valid");
77
- acc[tool.function.name] = vercelAIToolDefinition satisfies Tool;
78
- return acc;
79
- }, {} as ToolSet);
80
- const hasTools = Object.keys(tools ?? {}).length > 0;
81
- tools = hasTools ? tools : undefined;
82
-
69
+ // TODO: Vercel AI SDK 5 has complex tool schema
70
+ // let tools: ToolSet | undefined = prompt.tools?.tools.reduce((acc, tool) => {
71
+ // if (!tool.function.parameters) {
72
+ // return acc;
73
+ // }
74
+ // const vercelAIToolDefinition = safelyConvertToolDefinitionToProvider({
75
+ // toolDefinition: tool,
76
+ // targetProvider: "VERCEL_AI",
77
+ // });
78
+ // invariant(vercelAIToolDefinition, "Tool definition is not valid");
79
+ // // TODO: get the symbol working here for validators
80
+ // acc[tool.function.name] = vercelAIToolDefinition as unknown as Tool;
81
+ // return acc;
82
+ // }, {} as ToolSet);
83
+ // const hasTools = Object.keys(tools ?? {}).length > 0;
84
+ // tools = hasTools ? tools : undefined;
85
+ const hasTools = false;
86
+ const tools = undefined;
87
+ if (prompt.tools?.tools && prompt.tools?.tools.length) {
88
+ // eslint-disable-next-line no-console
89
+ console.warn(
90
+ "Prompt tools not currently supported in the AI SDK, falling back to no tools"
91
+ );
92
+ }
83
93
  let toolChoice: VercelAIToolChoice | undefined =
84
94
  safelyConvertToolChoiceToProvider({
85
95
  toolChoice: prompt.tools?.tool_choice,
@@ -88,12 +98,12 @@ export const toAI = <V extends Variables>({
88
98
  toolChoice = hasTools ? toolChoice : undefined;
89
99
 
90
100
  // combine base and computed params
91
- const completionParams = {
101
+ const completionParams: PartialAIParams = {
92
102
  ...baseCompletionParams,
93
103
  messages,
94
104
  tools,
95
105
  toolChoice,
96
- } satisfies Partial<PartialStreamTextParams>;
106
+ };
97
107
 
98
108
  return completionParams;
99
109
  } catch (error) {
@@ -272,7 +272,7 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
272
272
  type: "tool-call",
273
273
  toolCallId: tc.id,
274
274
  toolName: tc.function.name,
275
- args: tc.function.arguments,
275
+ input: tc.function.arguments,
276
276
  });
277
277
  });
278
278
  }
@@ -289,7 +289,7 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
289
289
  type: "tool-result",
290
290
  toolCallId: openai.tool_call_id,
291
291
  toolName: "", // We don't have this??
292
- result: openai.content,
292
+ output: { type: "text", value: openai.content },
293
293
  });
294
294
  } else {
295
295
  openai.content.forEach((part) => {
@@ -298,7 +298,10 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
298
298
  type: "tool-result",
299
299
  toolCallId: openai.tool_call_id,
300
300
  toolName: "", // We don't have this??
301
- result: part.text,
301
+ output: {
302
+ type: "text",
303
+ value: part.text,
304
+ },
302
305
  });
303
306
  return;
304
307
  }
@@ -391,7 +394,7 @@ export const openAIToolDefinitionToVercelAI =
391
394
  (openai): VercelAIToolDefinition => ({
392
395
  type: "function",
393
396
  description: openai.function.description,
394
- parameters: {
397
+ inputSchema: {
395
398
  _type: undefined,
396
399
  jsonSchema: openai.function.parameters,
397
400
  validate: undefined,
@@ -26,7 +26,7 @@ export const vercelAIChatPartToolCallSchema = z.object({
26
26
  type: z.literal("tool-call"),
27
27
  toolCallId: z.string(),
28
28
  toolName: z.string(),
29
- args: jsonLiteralSchema, // json serializable parameters
29
+ input: jsonLiteralSchema, // json serializable parameters
30
30
  });
31
31
 
32
32
  export type VercelAIChatPartToolCall = z.infer<
@@ -37,7 +37,10 @@ export const vercelAIChatPartToolResultSchema = z.object({
37
37
  type: z.literal("tool-result"),
38
38
  toolCallId: z.string(),
39
39
  toolName: z.string(),
40
- result: jsonLiteralSchema, // json serializable result
40
+ output: z.object({
41
+ type: z.literal("text"), // TODO: extend to support other output types
42
+ value: z.string(),
43
+ }),
41
44
  });
42
45
 
43
46
  export type VercelAIChatPartToolResult = z.infer<
@@ -9,7 +9,7 @@ import { z } from "zod";
9
9
  export const vercelAIToolDefinitionSchema = z.object({
10
10
  type: z.literal("function"),
11
11
  description: z.string().optional(),
12
- parameters: z.object({
12
+ inputSchema: z.object({
13
13
  _type: z.unknown().optional().default(undefined),
14
14
  validate: z.unknown().optional().default(undefined),
15
15
  jsonSchema: z.record(z.string(), z.unknown()).optional(),
@@ -0,0 +1,66 @@
1
+ import { createClient } from "../client";
2
+ import { ClientFn } from "../types/core";
3
+ import { DocumentAnnotation, toDocumentAnnotationData } from "./types";
4
+
5
+ /**
6
+ * Parameters to add a document annotation
7
+ */
8
+ export interface AddDocumentAnnotationParams extends ClientFn {
9
+ documentAnnotation: DocumentAnnotation;
10
+ /**
11
+ * If true, the request will be fulfilled synchronously and return the annotation ID.
12
+ * If false, the request will be processed asynchronously and return null.
13
+ * @default false
14
+ */
15
+ sync?: boolean;
16
+ }
17
+
18
+ /**
19
+ * Add an annotation to a document within a span.
20
+ *
21
+ * The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
22
+ * At least one of label, score, or explanation must be provided.
23
+ *
24
+ * @param params - The parameters to add a document annotation
25
+ * @returns The ID of the created annotation
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const result = await addDocumentAnnotation({
30
+ * documentAnnotation: {
31
+ * spanId: "123abc",
32
+ * documentPosition: 0,
33
+ * name: "relevance_score",
34
+ * label: "relevant",
35
+ * score: 0.95,
36
+ * annotatorKind: "LLM",
37
+ * explanation: "Document is highly relevant to the query",
38
+ * metadata: {
39
+ * model: "gpt-4"
40
+ * }
41
+ * }
42
+ * });
43
+ * ```
44
+ */
45
+ export async function addDocumentAnnotation({
46
+ client: _client,
47
+ documentAnnotation,
48
+ sync = false,
49
+ }: AddDocumentAnnotationParams): Promise<{ id: string } | null> {
50
+ const client = _client ?? createClient();
51
+
52
+ const { data, error } = await client.POST("/v1/document_annotations", {
53
+ params: {
54
+ query: { sync },
55
+ },
56
+ body: {
57
+ data: [toDocumentAnnotationData(documentAnnotation)],
58
+ },
59
+ });
60
+
61
+ if (error) {
62
+ throw new Error(`Failed to add document annotation: ${error}`);
63
+ }
64
+
65
+ return data?.data?.[0] || null;
66
+ }
@@ -7,6 +7,12 @@ import { SpanAnnotation, toSpanAnnotationData } from "./types";
7
7
  */
8
8
  export interface AddSpanAnnotationParams extends ClientFn {
9
9
  spanAnnotation: SpanAnnotation;
10
+ /**
11
+ * If true, the request will be fulfilled synchronously and return the annotation ID.
12
+ * If false, the request will be processed asynchronously and return null.
13
+ * @default false
14
+ */
15
+ sync?: boolean;
10
16
  }
11
17
 
12
18
  /**
@@ -38,10 +44,14 @@ export interface AddSpanAnnotationParams extends ClientFn {
38
44
  export async function addSpanAnnotation({
39
45
  client: _client,
40
46
  spanAnnotation,
41
- }: AddSpanAnnotationParams): Promise<{ id: string }> {
47
+ sync = false,
48
+ }: AddSpanAnnotationParams): Promise<{ id: string } | null> {
42
49
  const client = _client ?? createClient();
43
50
 
44
51
  const { data, error } = await client.POST("/v1/span_annotations", {
52
+ params: {
53
+ query: { sync },
54
+ },
45
55
  body: {
46
56
  data: [toSpanAnnotationData(spanAnnotation)],
47
57
  },
@@ -51,9 +61,5 @@ export async function addSpanAnnotation({
51
61
  throw new Error(`Failed to add span annotation: ${error}`);
52
62
  }
53
63
 
54
- if (!data?.data?.[0]?.id) {
55
- throw new Error("No annotation ID returned from server");
56
- }
57
-
58
- return data.data[0];
64
+ return data?.data?.[0] || null;
59
65
  }
@@ -1,5 +1,7 @@
1
1
  export * from "./addSpanAnnotation";
2
2
  export * from "./logSpanAnnotations";
3
+ export * from "./addDocumentAnnotation";
4
+ export * from "./logDocumentAnnotations";
3
5
  export * from "./getSpans";
4
6
  export * from "./getSpanAnnotations";
5
7
  export * from "./deleteSpan";