@ai-sdk/perplexity 2.1.3 → 2.1.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.
package/dist/index.js CHANGED
@@ -28,11 +28,11 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/perplexity-provider.ts
30
30
  var import_provider3 = require("@ai-sdk/provider");
31
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
31
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/perplexity-language-model.ts
34
34
  var import_provider2 = require("@ai-sdk/provider");
35
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
36
36
 
37
37
  // src/convert-perplexity-usage.ts
38
38
  function convertPerplexityUsage(usage) {
@@ -232,8 +232,9 @@ function mapPerplexityFinishReason({
232
232
  }
233
233
 
234
234
  // src/perplexity-agent-api.ts
235
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
235
236
  var import_v4 = require("zod/v4");
236
- var perplexitySearchResultSchema = import_v4.z.looseObject({
237
+ var perplexitySearchResultSchema = () => import_v4.z.looseObject({
237
238
  id: import_v4.z.number().optional(),
238
239
  title: import_v4.z.string(),
239
240
  url: import_v4.z.string(),
@@ -242,12 +243,12 @@ var perplexitySearchResultSchema = import_v4.z.looseObject({
242
243
  last_updated: import_v4.z.string().nullish(),
243
244
  source: import_v4.z.string().optional()
244
245
  });
245
- var perplexityFetchedContentSchema = import_v4.z.looseObject({
246
+ var perplexityFetchedContentSchema = () => import_v4.z.looseObject({
246
247
  title: import_v4.z.string(),
247
248
  url: import_v4.z.string(),
248
249
  snippet: import_v4.z.string().optional()
249
250
  });
250
- var perplexityContentPartSchema = import_v4.z.looseObject({
251
+ var perplexityContentPartSchema = () => import_v4.z.looseObject({
251
252
  type: import_v4.z.string(),
252
253
  text: import_v4.z.string().optional(),
253
254
  annotations: import_v4.z.array(
@@ -264,19 +265,19 @@ var handledOutputTypes = [
264
265
  "fetch_url_results",
265
266
  "function_call"
266
267
  ];
267
- var perplexityOutputItemSchema = import_v4.z.union([
268
+ var perplexityOutputItemSchema = () => import_v4.z.union([
268
269
  import_v4.z.looseObject({
269
270
  type: import_v4.z.literal("message"),
270
271
  id: import_v4.z.string().nullish(),
271
- content: import_v4.z.array(perplexityContentPartSchema).nullish()
272
+ content: import_v4.z.array(perplexityContentPartSchema()).nullish()
272
273
  }),
273
274
  import_v4.z.looseObject({
274
275
  type: import_v4.z.literal("search_results"),
275
- results: import_v4.z.array(perplexitySearchResultSchema).nullish()
276
+ results: import_v4.z.array(perplexitySearchResultSchema()).nullish()
276
277
  }),
277
278
  import_v4.z.looseObject({
278
279
  type: import_v4.z.literal("fetch_url_results"),
279
- contents: import_v4.z.array(perplexityFetchedContentSchema).nullish()
280
+ contents: import_v4.z.array(perplexityFetchedContentSchema()).nullish()
280
281
  }),
281
282
  import_v4.z.looseObject({
282
283
  type: import_v4.z.literal("function_call"),
@@ -293,7 +294,7 @@ var perplexityOutputItemSchema = import_v4.z.union([
293
294
  type: import_v4.z.string().refine((type) => !handledOutputTypes.includes(type))
294
295
  }).transform(() => ({ type: "unhandled" }))
295
296
  ]);
296
- var perplexityCostSchema = import_v4.z.looseObject({
297
+ var perplexityCostSchema = () => import_v4.z.looseObject({
297
298
  currency: import_v4.z.string().optional(),
298
299
  input_cost: import_v4.z.number().optional(),
299
300
  output_cost: import_v4.z.number().optional(),
@@ -302,7 +303,7 @@ var perplexityCostSchema = import_v4.z.looseObject({
302
303
  cache_read_cost: import_v4.z.number().nullish(),
303
304
  tool_calls_cost: import_v4.z.number().nullish()
304
305
  });
305
- var perplexityUsageSchema = import_v4.z.looseObject({
306
+ var perplexityUsageSchema = () => import_v4.z.looseObject({
306
307
  input_tokens: import_v4.z.number(),
307
308
  output_tokens: import_v4.z.number(),
308
309
  total_tokens: import_v4.z.number(),
@@ -320,14 +321,14 @@ var perplexityUsageSchema = import_v4.z.looseObject({
320
321
  invocation: import_v4.z.number().optional()
321
322
  })
322
323
  ).nullish(),
323
- cost: perplexityCostSchema.nullish()
324
+ cost: perplexityCostSchema().nullish()
324
325
  });
325
- var perplexityAgentResponseSchema = import_v4.z.looseObject({
326
+ var perplexityAgentResponseSchema = () => import_v4.z.looseObject({
326
327
  id: import_v4.z.string(),
327
328
  created_at: import_v4.z.number(),
328
329
  model: import_v4.z.string(),
329
330
  object: import_v4.z.literal("response"),
330
- output: import_v4.z.array(perplexityOutputItemSchema),
331
+ output: import_v4.z.array(perplexityOutputItemSchema()),
331
332
  status: import_v4.z.string(),
332
333
  incomplete_details: import_v4.z.looseObject({
333
334
  reason: import_v4.z.string()
@@ -337,48 +338,59 @@ var perplexityAgentResponseSchema = import_v4.z.looseObject({
337
338
  message: import_v4.z.string(),
338
339
  type: import_v4.z.string().optional()
339
340
  }).nullish(),
340
- usage: perplexityUsageSchema.nullish()
341
+ usage: perplexityUsageSchema().nullish()
341
342
  });
342
- var perplexityAgentChunkSchema = import_v4.z.looseObject({
343
- type: import_v4.z.string(),
344
- sequence_number: import_v4.z.number().nullish(),
345
- response: perplexityAgentResponseSchema.nullish(),
346
- item: perplexityOutputItemSchema.nullish(),
347
- output_index: import_v4.z.number().nullish(),
348
- item_id: import_v4.z.string().nullish(),
349
- content_index: import_v4.z.number().nullish(),
350
- delta: import_v4.z.string().nullish(),
351
- text: import_v4.z.string().nullish(),
352
- thought: import_v4.z.string().nullish(),
353
- queries: import_v4.z.array(import_v4.z.string()).nullish(),
354
- urls: import_v4.z.array(import_v4.z.string()).nullish(),
355
- results: import_v4.z.array(perplexitySearchResultSchema).nullish(),
356
- contents: import_v4.z.array(perplexityFetchedContentSchema).nullish(),
357
- error: import_v4.z.looseObject({
358
- code: import_v4.z.string().nullish(),
359
- message: import_v4.z.string(),
360
- type: import_v4.z.string().nullish()
361
- }).nullish()
362
- });
363
- var perplexityErrorSchema = import_v4.z.looseObject({
364
- error: import_v4.z.union([
365
- import_v4.z.string(),
343
+ var perplexityAgentResponseSchemaValidator = (0, import_provider_utils2.lazySchema)(
344
+ () => (0, import_provider_utils2.zodSchema)(perplexityAgentResponseSchema())
345
+ );
346
+ var perplexityAgentChunkSchema = (0, import_provider_utils2.lazySchema)(
347
+ () => (0, import_provider_utils2.zodSchema)(
366
348
  import_v4.z.looseObject({
367
- code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).optional(),
368
- message: import_v4.z.string().nullish(),
369
- type: import_v4.z.string().nullish()
349
+ type: import_v4.z.string(),
350
+ sequence_number: import_v4.z.number().nullish(),
351
+ response: perplexityAgentResponseSchema().nullish(),
352
+ item: perplexityOutputItemSchema().nullish(),
353
+ output_index: import_v4.z.number().nullish(),
354
+ item_id: import_v4.z.string().nullish(),
355
+ content_index: import_v4.z.number().nullish(),
356
+ delta: import_v4.z.string().nullish(),
357
+ text: import_v4.z.string().nullish(),
358
+ thought: import_v4.z.string().nullish(),
359
+ queries: import_v4.z.array(import_v4.z.string()).nullish(),
360
+ urls: import_v4.z.array(import_v4.z.string()).nullish(),
361
+ results: import_v4.z.array(perplexitySearchResultSchema()).nullish(),
362
+ contents: import_v4.z.array(perplexityFetchedContentSchema()).nullish(),
363
+ error: import_v4.z.looseObject({
364
+ code: import_v4.z.string().nullish(),
365
+ message: import_v4.z.string(),
366
+ type: import_v4.z.string().nullish()
367
+ }).nullish()
370
368
  })
371
- ]).optional(),
372
- detail: import_v4.z.union([
373
- import_v4.z.string(),
374
- import_v4.z.array(
375
- import_v4.z.looseObject({
376
- msg: import_v4.z.string()
377
- })
378
- )
379
- ]).optional(),
380
- message: import_v4.z.string().optional()
381
- });
369
+ )
370
+ );
371
+ var perplexityErrorSchema = (0, import_provider_utils2.lazySchema)(
372
+ () => (0, import_provider_utils2.zodSchema)(
373
+ import_v4.z.looseObject({
374
+ error: import_v4.z.union([
375
+ import_v4.z.string(),
376
+ import_v4.z.looseObject({
377
+ code: import_v4.z.union([import_v4.z.string(), import_v4.z.number()]).optional(),
378
+ message: import_v4.z.string().nullish(),
379
+ type: import_v4.z.string().nullish()
380
+ })
381
+ ]).optional(),
382
+ detail: import_v4.z.union([
383
+ import_v4.z.string(),
384
+ import_v4.z.array(
385
+ import_v4.z.looseObject({
386
+ msg: import_v4.z.string()
387
+ })
388
+ )
389
+ ]).optional(),
390
+ message: import_v4.z.string().optional()
391
+ })
392
+ )
393
+ );
382
394
  function perplexityErrorToMessage(data) {
383
395
  var _a, _b, _c;
384
396
  if (typeof data.error === "string") {
@@ -397,15 +409,16 @@ function perplexityErrorToMessage(data) {
397
409
  }
398
410
 
399
411
  // src/perplexity-language-model-options.ts
412
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
400
413
  var import_v42 = require("zod/v4");
401
- var userLocationSchema = import_v42.z.looseObject({
414
+ var userLocationSchema = () => import_v42.z.looseObject({
402
415
  latitude: import_v42.z.number().optional(),
403
416
  longitude: import_v42.z.number().optional(),
404
417
  country: import_v42.z.string().optional(),
405
418
  city: import_v42.z.string().optional(),
406
419
  region: import_v42.z.string().optional()
407
420
  });
408
- var webSearchFiltersSchema = import_v42.z.looseObject({
421
+ var webSearchFiltersSchema = () => import_v42.z.looseObject({
409
422
  search_domain_filter: import_v42.z.array(import_v42.z.string()).optional(),
410
423
  search_recency_filter: import_v42.z.enum(["hour", "day", "week", "month", "year"]).optional(),
411
424
  search_after_date_filter: import_v42.z.string().optional(),
@@ -413,17 +426,17 @@ var webSearchFiltersSchema = import_v42.z.looseObject({
413
426
  last_updated_after_filter: import_v42.z.string().optional(),
414
427
  last_updated_before_filter: import_v42.z.string().optional()
415
428
  });
416
- var webSearchToolSchema = import_v42.z.looseObject({
429
+ var webSearchToolSchema = () => import_v42.z.looseObject({
417
430
  type: import_v42.z.literal("web_search"),
418
- filters: webSearchFiltersSchema.optional(),
431
+ filters: webSearchFiltersSchema().optional(),
419
432
  max_results: import_v42.z.number().int().positive().optional(),
420
433
  max_tokens: import_v42.z.number().optional(),
421
434
  max_tokens_per_page: import_v42.z.number().optional(),
422
435
  search_context_size: import_v42.z.enum(["low", "medium", "high"]).optional(),
423
- user_location: userLocationSchema.optional()
436
+ user_location: userLocationSchema().optional()
424
437
  });
425
- var nativeToolSchema = import_v42.z.union([
426
- webSearchToolSchema,
438
+ var nativeToolSchema = () => import_v42.z.union([
439
+ webSearchToolSchema(),
427
440
  import_v42.z.looseObject({
428
441
  type: import_v42.z.literal("fetch_url"),
429
442
  max_urls: import_v42.z.number().optional()
@@ -448,55 +461,59 @@ var nativeToolSchema = import_v42.z.union([
448
461
  allowed_tools: import_v42.z.array(import_v42.z.string()).optional()
449
462
  })
450
463
  ]);
451
- var perplexityLanguageModelOptions = import_v42.z.looseObject({
452
- /** Top-level Agent API instructions. */
453
- instructions: import_v42.z.string().optional(),
454
- /**
455
- * Native Agent API tools. AI SDK function tools can also be supplied through
456
- * the top-level `tools` option on `generateText` and `streamText`.
457
- */
458
- tools: import_v42.z.array(nativeToolSchema).optional(),
459
- /** A fallback model list for Agent API routing. */
460
- models: import_v42.z.array(import_v42.z.string()).optional(),
461
- /** Maximum number of agentic steps. */
462
- max_steps: import_v42.z.number().int().positive().optional(),
463
- /** Maximum number of native tool calls. */
464
- max_tool_calls: import_v42.z.number().int().nonnegative().optional(),
465
- /** Continue a conversation from an earlier Agent API response. */
466
- previous_response_id: import_v42.z.string().optional(),
467
- /**
468
- * Whether the response can be retrieved later. Setting this to false does
469
- * not disable persistence or prevent previous_response_id continuations.
470
- */
471
- store: import_v42.z.boolean().optional(),
472
- /** Preferred response language as an ISO 639-1 language code. */
473
- language_preference: import_v42.z.string().optional(),
474
- /** Agent API reasoning configuration. */
475
- reasoning: import_v42.z.looseObject({
476
- effort: import_v42.z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional()
477
- }).optional(),
478
- /** Agent API skill configuration. */
479
- skills: import_v42.z.array(
480
- import_v42.z.union([
481
- import_v42.z.looseObject({
482
- type: import_v42.z.literal("builtin"),
483
- name: import_v42.z.enum([
484
- "office",
485
- "office/docx",
486
- "office/pdf",
487
- "office/pptx",
488
- "office/xlsx"
464
+ var perplexityLanguageModelOptions = (0, import_provider_utils3.lazySchema)(
465
+ () => (0, import_provider_utils3.zodSchema)(
466
+ import_v42.z.looseObject({
467
+ /** Top-level Agent API instructions. */
468
+ instructions: import_v42.z.string().optional(),
469
+ /**
470
+ * Native Agent API tools. AI SDK function tools can also be supplied through
471
+ * the top-level `tools` option on `generateText` and `streamText`.
472
+ */
473
+ tools: import_v42.z.array(nativeToolSchema()).optional(),
474
+ /** A fallback model list for Agent API routing. */
475
+ models: import_v42.z.array(import_v42.z.string()).optional(),
476
+ /** Maximum number of agentic steps. */
477
+ max_steps: import_v42.z.number().int().positive().optional(),
478
+ /** Maximum number of native tool calls. */
479
+ max_tool_calls: import_v42.z.number().int().nonnegative().optional(),
480
+ /** Continue a conversation from an earlier Agent API response. */
481
+ previous_response_id: import_v42.z.string().optional(),
482
+ /**
483
+ * Whether the response can be retrieved later. Setting this to false does
484
+ * not disable persistence or prevent previous_response_id continuations.
485
+ */
486
+ store: import_v42.z.boolean().optional(),
487
+ /** Preferred response language as an ISO 639-1 language code. */
488
+ language_preference: import_v42.z.string().optional(),
489
+ /** Agent API reasoning configuration. */
490
+ reasoning: import_v42.z.looseObject({
491
+ effort: import_v42.z.enum(["minimal", "low", "medium", "high", "xhigh"]).optional()
492
+ }).optional(),
493
+ /** Agent API skill configuration. */
494
+ skills: import_v42.z.array(
495
+ import_v42.z.union([
496
+ import_v42.z.looseObject({
497
+ type: import_v42.z.literal("builtin"),
498
+ name: import_v42.z.enum([
499
+ "office",
500
+ "office/docx",
501
+ "office/pdf",
502
+ "office/pptx",
503
+ "office/xlsx"
504
+ ])
505
+ }),
506
+ import_v42.z.looseObject({
507
+ type: import_v42.z.literal("inline"),
508
+ name: import_v42.z.string(),
509
+ description: import_v42.z.string(),
510
+ instructions: import_v42.z.string()
511
+ })
489
512
  ])
490
- }),
491
- import_v42.z.looseObject({
492
- type: import_v42.z.literal("inline"),
493
- name: import_v42.z.string(),
494
- description: import_v42.z.string(),
495
- instructions: import_v42.z.string()
496
- })
497
- ])
498
- ).optional()
499
- });
513
+ ).optional()
514
+ })
515
+ )
516
+ );
500
517
 
501
518
  // src/perplexity-prepare-tools.ts
502
519
  function preparePerplexityTools({
@@ -645,7 +662,7 @@ var PerplexityLanguageModel = class {
645
662
  }) {
646
663
  var _a, _b;
647
664
  const warnings = [];
648
- const perplexityOptions = (_a = await (0, import_provider_utils2.parseProviderOptions)({
665
+ const perplexityOptions = (_a = await (0, import_provider_utils4.parseProviderOptions)({
649
666
  provider: "perplexity",
650
667
  providerOptions,
651
668
  schema: perplexityLanguageModelOptions
@@ -716,16 +733,16 @@ var PerplexityLanguageModel = class {
716
733
  responseHeaders,
717
734
  value: response,
718
735
  rawValue: rawResponse
719
- } = await (0, import_provider_utils2.postJsonToApi)({
736
+ } = await (0, import_provider_utils4.postJsonToApi)({
720
737
  url,
721
- headers: (0, import_provider_utils2.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
738
+ headers: (0, import_provider_utils4.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
722
739
  body,
723
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
740
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
724
741
  errorSchema: perplexityErrorSchema,
725
742
  errorToMessage: perplexityErrorToMessage
726
743
  }),
727
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
728
- perplexityAgentResponseSchema
744
+ successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
745
+ perplexityAgentResponseSchemaValidator
729
746
  ),
730
747
  abortSignal: options.abortSignal,
731
748
  fetch: this.config.fetch
@@ -828,15 +845,15 @@ var PerplexityLanguageModel = class {
828
845
  var _a, _b;
829
846
  const { args, warnings } = await this.getArgs(options);
830
847
  const body = { ...args, stream: true };
831
- const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
848
+ const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
832
849
  url: `${this.config.baseURL}/v1/agent`,
833
- headers: (0, import_provider_utils2.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
850
+ headers: (0, import_provider_utils4.combineHeaders)((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
834
851
  body,
835
- failedResponseHandler: (0, import_provider_utils2.createJsonErrorResponseHandler)({
852
+ failedResponseHandler: (0, import_provider_utils4.createJsonErrorResponseHandler)({
836
853
  errorSchema: perplexityErrorSchema,
837
854
  errorToMessage: perplexityErrorToMessage
838
855
  }),
839
- successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
856
+ successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
840
857
  perplexityAgentChunkSchema
841
858
  ),
842
859
  abortSignal: options.abortSignal,
@@ -1168,13 +1185,13 @@ var PerplexityLanguageModel = class {
1168
1185
  };
1169
1186
 
1170
1187
  // src/version.ts
1171
- var VERSION = true ? "2.1.3" : "0.0.0-test";
1188
+ var VERSION = true ? "2.1.4" : "0.0.0-test";
1172
1189
 
1173
1190
  // src/perplexity-provider.ts
1174
1191
  function createPerplexity(options = {}) {
1175
- const getHeaders = () => (0, import_provider_utils3.withUserAgentSuffix)(
1192
+ const getHeaders = () => (0, import_provider_utils5.withUserAgentSuffix)(
1176
1193
  {
1177
- Authorization: `Bearer ${(0, import_provider_utils3.loadApiKey)({
1194
+ Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({
1178
1195
  apiKey: options.apiKey,
1179
1196
  environmentVariableName: "PERPLEXITY_API_KEY",
1180
1197
  description: "Perplexity"
@@ -1187,11 +1204,11 @@ function createPerplexity(options = {}) {
1187
1204
  const createLanguageModel = (modelId) => {
1188
1205
  var _a;
1189
1206
  return new PerplexityLanguageModel(modelId, {
1190
- baseURL: (0, import_provider_utils3.withoutTrailingSlash)(
1207
+ baseURL: (0, import_provider_utils5.withoutTrailingSlash)(
1191
1208
  (_a = options.baseURL) != null ? _a : "https://api.perplexity.ai"
1192
1209
  ),
1193
1210
  headers: getHeaders,
1194
- generateId: import_provider_utils3.generateId,
1211
+ generateId: import_provider_utils5.generateId,
1195
1212
  fetch: options.fetch
1196
1213
  });
1197
1214
  };