@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/CHANGELOG.md +9 -0
- package/dist/index.d.mts +82 -107
- package/dist/index.d.ts +82 -107
- package/dist/index.js +140 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -108
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -222,8 +222,12 @@ function mapPerplexityFinishReason({
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// src/perplexity-agent-api.ts
|
|
225
|
+
import {
|
|
226
|
+
lazySchema,
|
|
227
|
+
zodSchema
|
|
228
|
+
} from "@ai-sdk/provider-utils";
|
|
225
229
|
import { z } from "zod/v4";
|
|
226
|
-
var perplexitySearchResultSchema = z.looseObject({
|
|
230
|
+
var perplexitySearchResultSchema = () => z.looseObject({
|
|
227
231
|
id: z.number().optional(),
|
|
228
232
|
title: z.string(),
|
|
229
233
|
url: z.string(),
|
|
@@ -232,12 +236,12 @@ var perplexitySearchResultSchema = z.looseObject({
|
|
|
232
236
|
last_updated: z.string().nullish(),
|
|
233
237
|
source: z.string().optional()
|
|
234
238
|
});
|
|
235
|
-
var perplexityFetchedContentSchema = z.looseObject({
|
|
239
|
+
var perplexityFetchedContentSchema = () => z.looseObject({
|
|
236
240
|
title: z.string(),
|
|
237
241
|
url: z.string(),
|
|
238
242
|
snippet: z.string().optional()
|
|
239
243
|
});
|
|
240
|
-
var perplexityContentPartSchema = z.looseObject({
|
|
244
|
+
var perplexityContentPartSchema = () => z.looseObject({
|
|
241
245
|
type: z.string(),
|
|
242
246
|
text: z.string().optional(),
|
|
243
247
|
annotations: z.array(
|
|
@@ -254,19 +258,19 @@ var handledOutputTypes = [
|
|
|
254
258
|
"fetch_url_results",
|
|
255
259
|
"function_call"
|
|
256
260
|
];
|
|
257
|
-
var perplexityOutputItemSchema = z.union([
|
|
261
|
+
var perplexityOutputItemSchema = () => z.union([
|
|
258
262
|
z.looseObject({
|
|
259
263
|
type: z.literal("message"),
|
|
260
264
|
id: z.string().nullish(),
|
|
261
|
-
content: z.array(perplexityContentPartSchema).nullish()
|
|
265
|
+
content: z.array(perplexityContentPartSchema()).nullish()
|
|
262
266
|
}),
|
|
263
267
|
z.looseObject({
|
|
264
268
|
type: z.literal("search_results"),
|
|
265
|
-
results: z.array(perplexitySearchResultSchema).nullish()
|
|
269
|
+
results: z.array(perplexitySearchResultSchema()).nullish()
|
|
266
270
|
}),
|
|
267
271
|
z.looseObject({
|
|
268
272
|
type: z.literal("fetch_url_results"),
|
|
269
|
-
contents: z.array(perplexityFetchedContentSchema).nullish()
|
|
273
|
+
contents: z.array(perplexityFetchedContentSchema()).nullish()
|
|
270
274
|
}),
|
|
271
275
|
z.looseObject({
|
|
272
276
|
type: z.literal("function_call"),
|
|
@@ -283,7 +287,7 @@ var perplexityOutputItemSchema = z.union([
|
|
|
283
287
|
type: z.string().refine((type) => !handledOutputTypes.includes(type))
|
|
284
288
|
}).transform(() => ({ type: "unhandled" }))
|
|
285
289
|
]);
|
|
286
|
-
var perplexityCostSchema = z.looseObject({
|
|
290
|
+
var perplexityCostSchema = () => z.looseObject({
|
|
287
291
|
currency: z.string().optional(),
|
|
288
292
|
input_cost: z.number().optional(),
|
|
289
293
|
output_cost: z.number().optional(),
|
|
@@ -292,7 +296,7 @@ var perplexityCostSchema = z.looseObject({
|
|
|
292
296
|
cache_read_cost: z.number().nullish(),
|
|
293
297
|
tool_calls_cost: z.number().nullish()
|
|
294
298
|
});
|
|
295
|
-
var perplexityUsageSchema = z.looseObject({
|
|
299
|
+
var perplexityUsageSchema = () => z.looseObject({
|
|
296
300
|
input_tokens: z.number(),
|
|
297
301
|
output_tokens: z.number(),
|
|
298
302
|
total_tokens: z.number(),
|
|
@@ -310,14 +314,14 @@ var perplexityUsageSchema = z.looseObject({
|
|
|
310
314
|
invocation: z.number().optional()
|
|
311
315
|
})
|
|
312
316
|
).nullish(),
|
|
313
|
-
cost: perplexityCostSchema.nullish()
|
|
317
|
+
cost: perplexityCostSchema().nullish()
|
|
314
318
|
});
|
|
315
|
-
var perplexityAgentResponseSchema = z.looseObject({
|
|
319
|
+
var perplexityAgentResponseSchema = () => z.looseObject({
|
|
316
320
|
id: z.string(),
|
|
317
321
|
created_at: z.number(),
|
|
318
322
|
model: z.string(),
|
|
319
323
|
object: z.literal("response"),
|
|
320
|
-
output: z.array(perplexityOutputItemSchema),
|
|
324
|
+
output: z.array(perplexityOutputItemSchema()),
|
|
321
325
|
status: z.string(),
|
|
322
326
|
incomplete_details: z.looseObject({
|
|
323
327
|
reason: z.string()
|
|
@@ -327,48 +331,59 @@ var perplexityAgentResponseSchema = z.looseObject({
|
|
|
327
331
|
message: z.string(),
|
|
328
332
|
type: z.string().optional()
|
|
329
333
|
}).nullish(),
|
|
330
|
-
usage: perplexityUsageSchema.nullish()
|
|
334
|
+
usage: perplexityUsageSchema().nullish()
|
|
331
335
|
});
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
output_index: z.number().nullish(),
|
|
338
|
-
item_id: z.string().nullish(),
|
|
339
|
-
content_index: z.number().nullish(),
|
|
340
|
-
delta: z.string().nullish(),
|
|
341
|
-
text: z.string().nullish(),
|
|
342
|
-
thought: z.string().nullish(),
|
|
343
|
-
queries: z.array(z.string()).nullish(),
|
|
344
|
-
urls: z.array(z.string()).nullish(),
|
|
345
|
-
results: z.array(perplexitySearchResultSchema).nullish(),
|
|
346
|
-
contents: z.array(perplexityFetchedContentSchema).nullish(),
|
|
347
|
-
error: z.looseObject({
|
|
348
|
-
code: z.string().nullish(),
|
|
349
|
-
message: z.string(),
|
|
350
|
-
type: z.string().nullish()
|
|
351
|
-
}).nullish()
|
|
352
|
-
});
|
|
353
|
-
var perplexityErrorSchema = z.looseObject({
|
|
354
|
-
error: z.union([
|
|
355
|
-
z.string(),
|
|
336
|
+
var perplexityAgentResponseSchemaValidator = lazySchema(
|
|
337
|
+
() => zodSchema(perplexityAgentResponseSchema())
|
|
338
|
+
);
|
|
339
|
+
var perplexityAgentChunkSchema = lazySchema(
|
|
340
|
+
() => zodSchema(
|
|
356
341
|
z.looseObject({
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
342
|
+
type: z.string(),
|
|
343
|
+
sequence_number: z.number().nullish(),
|
|
344
|
+
response: perplexityAgentResponseSchema().nullish(),
|
|
345
|
+
item: perplexityOutputItemSchema().nullish(),
|
|
346
|
+
output_index: z.number().nullish(),
|
|
347
|
+
item_id: z.string().nullish(),
|
|
348
|
+
content_index: z.number().nullish(),
|
|
349
|
+
delta: z.string().nullish(),
|
|
350
|
+
text: z.string().nullish(),
|
|
351
|
+
thought: z.string().nullish(),
|
|
352
|
+
queries: z.array(z.string()).nullish(),
|
|
353
|
+
urls: z.array(z.string()).nullish(),
|
|
354
|
+
results: z.array(perplexitySearchResultSchema()).nullish(),
|
|
355
|
+
contents: z.array(perplexityFetchedContentSchema()).nullish(),
|
|
356
|
+
error: z.looseObject({
|
|
357
|
+
code: z.string().nullish(),
|
|
358
|
+
message: z.string(),
|
|
359
|
+
type: z.string().nullish()
|
|
360
|
+
}).nullish()
|
|
360
361
|
})
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
362
|
+
)
|
|
363
|
+
);
|
|
364
|
+
var perplexityErrorSchema = lazySchema(
|
|
365
|
+
() => zodSchema(
|
|
366
|
+
z.looseObject({
|
|
367
|
+
error: z.union([
|
|
368
|
+
z.string(),
|
|
369
|
+
z.looseObject({
|
|
370
|
+
code: z.union([z.string(), z.number()]).optional(),
|
|
371
|
+
message: z.string().nullish(),
|
|
372
|
+
type: z.string().nullish()
|
|
373
|
+
})
|
|
374
|
+
]).optional(),
|
|
375
|
+
detail: z.union([
|
|
376
|
+
z.string(),
|
|
377
|
+
z.array(
|
|
378
|
+
z.looseObject({
|
|
379
|
+
msg: z.string()
|
|
380
|
+
})
|
|
381
|
+
)
|
|
382
|
+
]).optional(),
|
|
383
|
+
message: z.string().optional()
|
|
384
|
+
})
|
|
385
|
+
)
|
|
386
|
+
);
|
|
372
387
|
function perplexityErrorToMessage(data) {
|
|
373
388
|
var _a, _b, _c;
|
|
374
389
|
if (typeof data.error === "string") {
|
|
@@ -387,15 +402,19 @@ function perplexityErrorToMessage(data) {
|
|
|
387
402
|
}
|
|
388
403
|
|
|
389
404
|
// src/perplexity-language-model-options.ts
|
|
405
|
+
import {
|
|
406
|
+
lazySchema as lazySchema2,
|
|
407
|
+
zodSchema as zodSchema2
|
|
408
|
+
} from "@ai-sdk/provider-utils";
|
|
390
409
|
import { z as z2 } from "zod/v4";
|
|
391
|
-
var userLocationSchema = z2.looseObject({
|
|
410
|
+
var userLocationSchema = () => z2.looseObject({
|
|
392
411
|
latitude: z2.number().optional(),
|
|
393
412
|
longitude: z2.number().optional(),
|
|
394
413
|
country: z2.string().optional(),
|
|
395
414
|
city: z2.string().optional(),
|
|
396
415
|
region: z2.string().optional()
|
|
397
416
|
});
|
|
398
|
-
var webSearchFiltersSchema = z2.looseObject({
|
|
417
|
+
var webSearchFiltersSchema = () => z2.looseObject({
|
|
399
418
|
search_domain_filter: z2.array(z2.string()).optional(),
|
|
400
419
|
search_recency_filter: z2.enum(["hour", "day", "week", "month", "year"]).optional(),
|
|
401
420
|
search_after_date_filter: z2.string().optional(),
|
|
@@ -403,17 +422,17 @@ var webSearchFiltersSchema = z2.looseObject({
|
|
|
403
422
|
last_updated_after_filter: z2.string().optional(),
|
|
404
423
|
last_updated_before_filter: z2.string().optional()
|
|
405
424
|
});
|
|
406
|
-
var webSearchToolSchema = z2.looseObject({
|
|
425
|
+
var webSearchToolSchema = () => z2.looseObject({
|
|
407
426
|
type: z2.literal("web_search"),
|
|
408
|
-
filters: webSearchFiltersSchema.optional(),
|
|
427
|
+
filters: webSearchFiltersSchema().optional(),
|
|
409
428
|
max_results: z2.number().int().positive().optional(),
|
|
410
429
|
max_tokens: z2.number().optional(),
|
|
411
430
|
max_tokens_per_page: z2.number().optional(),
|
|
412
431
|
search_context_size: z2.enum(["low", "medium", "high"]).optional(),
|
|
413
|
-
user_location: userLocationSchema.optional()
|
|
432
|
+
user_location: userLocationSchema().optional()
|
|
414
433
|
});
|
|
415
|
-
var nativeToolSchema = z2.union([
|
|
416
|
-
webSearchToolSchema,
|
|
434
|
+
var nativeToolSchema = () => z2.union([
|
|
435
|
+
webSearchToolSchema(),
|
|
417
436
|
z2.looseObject({
|
|
418
437
|
type: z2.literal("fetch_url"),
|
|
419
438
|
max_urls: z2.number().optional()
|
|
@@ -438,55 +457,59 @@ var nativeToolSchema = z2.union([
|
|
|
438
457
|
allowed_tools: z2.array(z2.string()).optional()
|
|
439
458
|
})
|
|
440
459
|
]);
|
|
441
|
-
var perplexityLanguageModelOptions =
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
z2.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
460
|
+
var perplexityLanguageModelOptions = lazySchema2(
|
|
461
|
+
() => zodSchema2(
|
|
462
|
+
z2.looseObject({
|
|
463
|
+
/** Top-level Agent API instructions. */
|
|
464
|
+
instructions: z2.string().optional(),
|
|
465
|
+
/**
|
|
466
|
+
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
467
|
+
* the top-level `tools` option on `generateText` and `streamText`.
|
|
468
|
+
*/
|
|
469
|
+
tools: z2.array(nativeToolSchema()).optional(),
|
|
470
|
+
/** A fallback model list for Agent API routing. */
|
|
471
|
+
models: z2.array(z2.string()).optional(),
|
|
472
|
+
/** Maximum number of agentic steps. */
|
|
473
|
+
max_steps: z2.number().int().positive().optional(),
|
|
474
|
+
/** Maximum number of native tool calls. */
|
|
475
|
+
max_tool_calls: z2.number().int().nonnegative().optional(),
|
|
476
|
+
/** Continue a conversation from an earlier Agent API response. */
|
|
477
|
+
previous_response_id: z2.string().optional(),
|
|
478
|
+
/**
|
|
479
|
+
* Whether the response can be retrieved later. Setting this to false does
|
|
480
|
+
* not disable persistence or prevent previous_response_id continuations.
|
|
481
|
+
*/
|
|
482
|
+
store: z2.boolean().optional(),
|
|
483
|
+
/** Preferred response language as an ISO 639-1 language code. */
|
|
484
|
+
language_preference: z2.string().optional(),
|
|
485
|
+
/** Agent API reasoning configuration. */
|
|
486
|
+
reasoning: z2.looseObject({
|
|
487
|
+
effort: z2.enum(["minimal", "low", "medium", "high", "xhigh"]).optional()
|
|
488
|
+
}).optional(),
|
|
489
|
+
/** Agent API skill configuration. */
|
|
490
|
+
skills: z2.array(
|
|
491
|
+
z2.union([
|
|
492
|
+
z2.looseObject({
|
|
493
|
+
type: z2.literal("builtin"),
|
|
494
|
+
name: z2.enum([
|
|
495
|
+
"office",
|
|
496
|
+
"office/docx",
|
|
497
|
+
"office/pdf",
|
|
498
|
+
"office/pptx",
|
|
499
|
+
"office/xlsx"
|
|
500
|
+
])
|
|
501
|
+
}),
|
|
502
|
+
z2.looseObject({
|
|
503
|
+
type: z2.literal("inline"),
|
|
504
|
+
name: z2.string(),
|
|
505
|
+
description: z2.string(),
|
|
506
|
+
instructions: z2.string()
|
|
507
|
+
})
|
|
479
508
|
])
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
description: z2.string(),
|
|
485
|
-
instructions: z2.string()
|
|
486
|
-
})
|
|
487
|
-
])
|
|
488
|
-
).optional()
|
|
489
|
-
});
|
|
509
|
+
).optional()
|
|
510
|
+
})
|
|
511
|
+
)
|
|
512
|
+
);
|
|
490
513
|
|
|
491
514
|
// src/perplexity-prepare-tools.ts
|
|
492
515
|
function preparePerplexityTools({
|
|
@@ -715,7 +738,7 @@ var PerplexityLanguageModel = class {
|
|
|
715
738
|
errorToMessage: perplexityErrorToMessage
|
|
716
739
|
}),
|
|
717
740
|
successfulResponseHandler: createJsonResponseHandler(
|
|
718
|
-
|
|
741
|
+
perplexityAgentResponseSchemaValidator
|
|
719
742
|
),
|
|
720
743
|
abortSignal: options.abortSignal,
|
|
721
744
|
fetch: this.config.fetch
|
|
@@ -1158,7 +1181,7 @@ var PerplexityLanguageModel = class {
|
|
|
1158
1181
|
};
|
|
1159
1182
|
|
|
1160
1183
|
// src/version.ts
|
|
1161
|
-
var VERSION = true ? "2.1.
|
|
1184
|
+
var VERSION = true ? "2.1.4" : "0.0.0-test";
|
|
1162
1185
|
|
|
1163
1186
|
// src/perplexity-provider.ts
|
|
1164
1187
|
function createPerplexity(options = {}) {
|