@ai-sdk/perplexity 3.1.7 → 3.1.8
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 +87 -115
- package/dist/index.d.ts +87 -115
- package/dist/index.js +184 -158
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -134
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/perplexity-agent-api.ts +184 -161
- package/src/perplexity-embedding-model-options.ts +25 -16
- package/src/perplexity-embedding-model.ts +18 -12
- package/src/perplexity-language-model-options.ts +120 -105
- package/src/perplexity-language-model.ts +11 -5
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
TooManyEmbeddingValuesForCallError
|
|
15
15
|
} from "@ai-sdk/provider";
|
|
16
16
|
import {
|
|
17
|
+
lazySchema as lazySchema4,
|
|
18
|
+
zodSchema as zodSchema4,
|
|
17
19
|
combineHeaders as combineHeaders2,
|
|
18
20
|
convertBase64ToUint8Array,
|
|
19
21
|
createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
|
|
@@ -24,22 +26,30 @@ import {
|
|
|
24
26
|
import { z as z4 } from "zod/v4";
|
|
25
27
|
|
|
26
28
|
// src/perplexity-embedding-model-options.ts
|
|
29
|
+
import {
|
|
30
|
+
lazySchema,
|
|
31
|
+
zodSchema
|
|
32
|
+
} from "@ai-sdk/provider-utils";
|
|
27
33
|
import { z } from "zod/v4";
|
|
28
|
-
var perplexityEmbeddingModelOptions =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
var perplexityEmbeddingModelOptions = lazySchema(
|
|
35
|
+
() => zodSchema(
|
|
36
|
+
z.object({
|
|
37
|
+
/**
|
|
38
|
+
* The number of dimensions the resulting output embeddings should have
|
|
39
|
+
* (Matryoshka truncation). Ranges from 128 up to the model's full size
|
|
40
|
+
* (1024 for 0.6b models, 2560 for 4b models).
|
|
41
|
+
*/
|
|
42
|
+
dimensions: z.number().int().positive().optional(),
|
|
43
|
+
/**
|
|
44
|
+
* The quantized encoding format returned by the API. Perplexity does not
|
|
45
|
+
* return floating point embeddings; values are decoded to numbers:
|
|
46
|
+
* - `base64_int8` (default): signed int8 values, compare via cosine similarity.
|
|
47
|
+
* - `base64_binary`: packed bits per byte (0-255), compare via Hamming distance.
|
|
48
|
+
*/
|
|
49
|
+
encodingFormat: z.enum(["base64_int8", "base64_binary"]).optional()
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
);
|
|
43
53
|
|
|
44
54
|
// src/perplexity-language-model.ts
|
|
45
55
|
import {
|
|
@@ -281,8 +291,12 @@ function mapPerplexityFinishReason({
|
|
|
281
291
|
}
|
|
282
292
|
|
|
283
293
|
// src/perplexity-agent-api.ts
|
|
294
|
+
import {
|
|
295
|
+
lazySchema as lazySchema2,
|
|
296
|
+
zodSchema as zodSchema2
|
|
297
|
+
} from "@ai-sdk/provider-utils";
|
|
284
298
|
import { z as z2 } from "zod/v4";
|
|
285
|
-
var perplexitySearchResultSchema = z2.looseObject({
|
|
299
|
+
var perplexitySearchResultSchema = () => z2.looseObject({
|
|
286
300
|
id: z2.number().optional(),
|
|
287
301
|
title: z2.string(),
|
|
288
302
|
url: z2.string(),
|
|
@@ -291,12 +305,12 @@ var perplexitySearchResultSchema = z2.looseObject({
|
|
|
291
305
|
last_updated: z2.string().nullish(),
|
|
292
306
|
source: z2.string().optional()
|
|
293
307
|
});
|
|
294
|
-
var perplexityFetchedContentSchema = z2.looseObject({
|
|
308
|
+
var perplexityFetchedContentSchema = () => z2.looseObject({
|
|
295
309
|
title: z2.string(),
|
|
296
310
|
url: z2.string(),
|
|
297
311
|
snippet: z2.string().optional()
|
|
298
312
|
});
|
|
299
|
-
var perplexityContentPartSchema = z2.looseObject({
|
|
313
|
+
var perplexityContentPartSchema = () => z2.looseObject({
|
|
300
314
|
type: z2.string(),
|
|
301
315
|
text: z2.string().optional(),
|
|
302
316
|
annotations: z2.array(
|
|
@@ -313,19 +327,19 @@ var handledOutputTypes = [
|
|
|
313
327
|
"fetch_url_results",
|
|
314
328
|
"function_call"
|
|
315
329
|
];
|
|
316
|
-
var perplexityOutputItemSchema = z2.union([
|
|
330
|
+
var perplexityOutputItemSchema = () => z2.union([
|
|
317
331
|
z2.looseObject({
|
|
318
332
|
type: z2.literal("message"),
|
|
319
333
|
id: z2.string().nullish(),
|
|
320
|
-
content: z2.array(perplexityContentPartSchema).nullish()
|
|
334
|
+
content: z2.array(perplexityContentPartSchema()).nullish()
|
|
321
335
|
}),
|
|
322
336
|
z2.looseObject({
|
|
323
337
|
type: z2.literal("search_results"),
|
|
324
|
-
results: z2.array(perplexitySearchResultSchema).nullish()
|
|
338
|
+
results: z2.array(perplexitySearchResultSchema()).nullish()
|
|
325
339
|
}),
|
|
326
340
|
z2.looseObject({
|
|
327
341
|
type: z2.literal("fetch_url_results"),
|
|
328
|
-
contents: z2.array(perplexityFetchedContentSchema).nullish()
|
|
342
|
+
contents: z2.array(perplexityFetchedContentSchema()).nullish()
|
|
329
343
|
}),
|
|
330
344
|
z2.looseObject({
|
|
331
345
|
type: z2.literal("function_call"),
|
|
@@ -342,7 +356,7 @@ var perplexityOutputItemSchema = z2.union([
|
|
|
342
356
|
type: z2.string().refine((type) => !handledOutputTypes.includes(type))
|
|
343
357
|
}).transform(() => ({ type: "unhandled" }))
|
|
344
358
|
]);
|
|
345
|
-
var perplexityCostSchema = z2.looseObject({
|
|
359
|
+
var perplexityCostSchema = () => z2.looseObject({
|
|
346
360
|
currency: z2.string().optional(),
|
|
347
361
|
input_cost: z2.number().optional(),
|
|
348
362
|
output_cost: z2.number().optional(),
|
|
@@ -351,7 +365,7 @@ var perplexityCostSchema = z2.looseObject({
|
|
|
351
365
|
cache_read_cost: z2.number().nullish(),
|
|
352
366
|
tool_calls_cost: z2.number().nullish()
|
|
353
367
|
});
|
|
354
|
-
var perplexityUsageSchema = z2.looseObject({
|
|
368
|
+
var perplexityUsageSchema = () => z2.looseObject({
|
|
355
369
|
input_tokens: z2.number(),
|
|
356
370
|
output_tokens: z2.number(),
|
|
357
371
|
total_tokens: z2.number(),
|
|
@@ -369,14 +383,14 @@ var perplexityUsageSchema = z2.looseObject({
|
|
|
369
383
|
invocation: z2.number().optional()
|
|
370
384
|
})
|
|
371
385
|
).nullish(),
|
|
372
|
-
cost: perplexityCostSchema.nullish()
|
|
386
|
+
cost: perplexityCostSchema().nullish()
|
|
373
387
|
});
|
|
374
|
-
var perplexityAgentResponseSchema = z2.looseObject({
|
|
388
|
+
var perplexityAgentResponseSchema = () => z2.looseObject({
|
|
375
389
|
id: z2.string(),
|
|
376
390
|
created_at: z2.number(),
|
|
377
391
|
model: z2.string(),
|
|
378
392
|
object: z2.literal("response"),
|
|
379
|
-
output: z2.array(perplexityOutputItemSchema),
|
|
393
|
+
output: z2.array(perplexityOutputItemSchema()),
|
|
380
394
|
status: z2.string(),
|
|
381
395
|
incomplete_details: z2.looseObject({
|
|
382
396
|
reason: z2.string()
|
|
@@ -386,48 +400,59 @@ var perplexityAgentResponseSchema = z2.looseObject({
|
|
|
386
400
|
message: z2.string(),
|
|
387
401
|
type: z2.string().optional()
|
|
388
402
|
}).nullish(),
|
|
389
|
-
usage: perplexityUsageSchema.nullish()
|
|
403
|
+
usage: perplexityUsageSchema().nullish()
|
|
390
404
|
});
|
|
391
|
-
var
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
output_index: z2.number().nullish(),
|
|
397
|
-
item_id: z2.string().nullish(),
|
|
398
|
-
content_index: z2.number().nullish(),
|
|
399
|
-
delta: z2.string().nullish(),
|
|
400
|
-
text: z2.string().nullish(),
|
|
401
|
-
thought: z2.string().nullish(),
|
|
402
|
-
queries: z2.array(z2.string()).nullish(),
|
|
403
|
-
urls: z2.array(z2.string()).nullish(),
|
|
404
|
-
results: z2.array(perplexitySearchResultSchema).nullish(),
|
|
405
|
-
contents: z2.array(perplexityFetchedContentSchema).nullish(),
|
|
406
|
-
error: z2.looseObject({
|
|
407
|
-
code: z2.string().nullish(),
|
|
408
|
-
message: z2.string(),
|
|
409
|
-
type: z2.string().nullish()
|
|
410
|
-
}).nullish()
|
|
411
|
-
});
|
|
412
|
-
var perplexityErrorSchema = z2.looseObject({
|
|
413
|
-
error: z2.union([
|
|
414
|
-
z2.string(),
|
|
405
|
+
var perplexityAgentResponseSchemaValidator = lazySchema2(
|
|
406
|
+
() => zodSchema2(perplexityAgentResponseSchema())
|
|
407
|
+
);
|
|
408
|
+
var perplexityAgentChunkSchema = lazySchema2(
|
|
409
|
+
() => zodSchema2(
|
|
415
410
|
z2.looseObject({
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
411
|
+
type: z2.string(),
|
|
412
|
+
sequence_number: z2.number().nullish(),
|
|
413
|
+
response: perplexityAgentResponseSchema().nullish(),
|
|
414
|
+
item: perplexityOutputItemSchema().nullish(),
|
|
415
|
+
output_index: z2.number().nullish(),
|
|
416
|
+
item_id: z2.string().nullish(),
|
|
417
|
+
content_index: z2.number().nullish(),
|
|
418
|
+
delta: z2.string().nullish(),
|
|
419
|
+
text: z2.string().nullish(),
|
|
420
|
+
thought: z2.string().nullish(),
|
|
421
|
+
queries: z2.array(z2.string()).nullish(),
|
|
422
|
+
urls: z2.array(z2.string()).nullish(),
|
|
423
|
+
results: z2.array(perplexitySearchResultSchema()).nullish(),
|
|
424
|
+
contents: z2.array(perplexityFetchedContentSchema()).nullish(),
|
|
425
|
+
error: z2.looseObject({
|
|
426
|
+
code: z2.string().nullish(),
|
|
427
|
+
message: z2.string(),
|
|
428
|
+
type: z2.string().nullish()
|
|
429
|
+
}).nullish()
|
|
419
430
|
})
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
+
)
|
|
432
|
+
);
|
|
433
|
+
var perplexityErrorSchema = lazySchema2(
|
|
434
|
+
() => zodSchema2(
|
|
435
|
+
z2.looseObject({
|
|
436
|
+
error: z2.union([
|
|
437
|
+
z2.string(),
|
|
438
|
+
z2.looseObject({
|
|
439
|
+
code: z2.union([z2.string(), z2.number()]).optional(),
|
|
440
|
+
message: z2.string().nullish(),
|
|
441
|
+
type: z2.string().nullish()
|
|
442
|
+
})
|
|
443
|
+
]).optional(),
|
|
444
|
+
detail: z2.union([
|
|
445
|
+
z2.string(),
|
|
446
|
+
z2.array(
|
|
447
|
+
z2.looseObject({
|
|
448
|
+
msg: z2.string()
|
|
449
|
+
})
|
|
450
|
+
)
|
|
451
|
+
]).optional(),
|
|
452
|
+
message: z2.string().optional()
|
|
453
|
+
})
|
|
454
|
+
)
|
|
455
|
+
);
|
|
431
456
|
function perplexityErrorToMessage(data) {
|
|
432
457
|
var _a, _b, _c;
|
|
433
458
|
if (typeof data.error === "string") {
|
|
@@ -446,15 +471,19 @@ function perplexityErrorToMessage(data) {
|
|
|
446
471
|
}
|
|
447
472
|
|
|
448
473
|
// src/perplexity-language-model-options.ts
|
|
474
|
+
import {
|
|
475
|
+
lazySchema as lazySchema3,
|
|
476
|
+
zodSchema as zodSchema3
|
|
477
|
+
} from "@ai-sdk/provider-utils";
|
|
449
478
|
import { z as z3 } from "zod/v4";
|
|
450
|
-
var userLocationSchema = z3.looseObject({
|
|
479
|
+
var userLocationSchema = () => z3.looseObject({
|
|
451
480
|
latitude: z3.number().optional(),
|
|
452
481
|
longitude: z3.number().optional(),
|
|
453
482
|
country: z3.string().optional(),
|
|
454
483
|
city: z3.string().optional(),
|
|
455
484
|
region: z3.string().optional()
|
|
456
485
|
});
|
|
457
|
-
var webSearchFiltersSchema = z3.looseObject({
|
|
486
|
+
var webSearchFiltersSchema = () => z3.looseObject({
|
|
458
487
|
search_domain_filter: z3.array(z3.string()).optional(),
|
|
459
488
|
search_recency_filter: z3.enum(["hour", "day", "week", "month", "year"]).optional(),
|
|
460
489
|
search_after_date_filter: z3.string().optional(),
|
|
@@ -462,17 +491,17 @@ var webSearchFiltersSchema = z3.looseObject({
|
|
|
462
491
|
last_updated_after_filter: z3.string().optional(),
|
|
463
492
|
last_updated_before_filter: z3.string().optional()
|
|
464
493
|
});
|
|
465
|
-
var webSearchToolSchema = z3.looseObject({
|
|
494
|
+
var webSearchToolSchema = () => z3.looseObject({
|
|
466
495
|
type: z3.literal("web_search"),
|
|
467
|
-
filters: webSearchFiltersSchema.optional(),
|
|
496
|
+
filters: webSearchFiltersSchema().optional(),
|
|
468
497
|
max_results: z3.number().int().positive().optional(),
|
|
469
498
|
max_tokens: z3.number().optional(),
|
|
470
499
|
max_tokens_per_page: z3.number().optional(),
|
|
471
500
|
search_context_size: z3.enum(["low", "medium", "high"]).optional(),
|
|
472
|
-
user_location: userLocationSchema.optional()
|
|
501
|
+
user_location: userLocationSchema().optional()
|
|
473
502
|
});
|
|
474
|
-
var nativeToolSchema = z3.union([
|
|
475
|
-
webSearchToolSchema,
|
|
503
|
+
var nativeToolSchema = () => z3.union([
|
|
504
|
+
webSearchToolSchema(),
|
|
476
505
|
z3.looseObject({
|
|
477
506
|
type: z3.literal("fetch_url"),
|
|
478
507
|
max_urls: z3.number().optional()
|
|
@@ -497,55 +526,59 @@ var nativeToolSchema = z3.union([
|
|
|
497
526
|
allowed_tools: z3.array(z3.string()).optional()
|
|
498
527
|
})
|
|
499
528
|
]);
|
|
500
|
-
var perplexityLanguageModelOptions =
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
z3.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
529
|
+
var perplexityLanguageModelOptions = lazySchema3(
|
|
530
|
+
() => zodSchema3(
|
|
531
|
+
z3.looseObject({
|
|
532
|
+
/** Top-level Agent API instructions. */
|
|
533
|
+
instructions: z3.string().optional(),
|
|
534
|
+
/**
|
|
535
|
+
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
536
|
+
* the top-level `tools` option on `generateText` and `streamText`.
|
|
537
|
+
*/
|
|
538
|
+
tools: z3.array(nativeToolSchema()).optional(),
|
|
539
|
+
/** A fallback model list for Agent API routing. */
|
|
540
|
+
models: z3.array(z3.string()).optional(),
|
|
541
|
+
/** Maximum number of agentic steps. */
|
|
542
|
+
max_steps: z3.number().int().positive().optional(),
|
|
543
|
+
/** Maximum number of native tool calls. */
|
|
544
|
+
max_tool_calls: z3.number().int().nonnegative().optional(),
|
|
545
|
+
/** Continue a conversation from an earlier Agent API response. */
|
|
546
|
+
previous_response_id: z3.string().optional(),
|
|
547
|
+
/**
|
|
548
|
+
* Whether the response can be retrieved later. Setting this to false does
|
|
549
|
+
* not disable persistence or prevent previous_response_id continuations.
|
|
550
|
+
*/
|
|
551
|
+
store: z3.boolean().optional(),
|
|
552
|
+
/** Preferred response language as an ISO 639-1 language code. */
|
|
553
|
+
language_preference: z3.string().optional(),
|
|
554
|
+
/** Agent API reasoning configuration. */
|
|
555
|
+
reasoning: z3.looseObject({
|
|
556
|
+
effort: z3.enum(["minimal", "low", "medium", "high", "xhigh"]).optional()
|
|
557
|
+
}).optional(),
|
|
558
|
+
/** Agent API skill configuration. */
|
|
559
|
+
skills: z3.array(
|
|
560
|
+
z3.union([
|
|
561
|
+
z3.looseObject({
|
|
562
|
+
type: z3.literal("builtin"),
|
|
563
|
+
name: z3.enum([
|
|
564
|
+
"office",
|
|
565
|
+
"office/docx",
|
|
566
|
+
"office/pdf",
|
|
567
|
+
"office/pptx",
|
|
568
|
+
"office/xlsx"
|
|
569
|
+
])
|
|
570
|
+
}),
|
|
571
|
+
z3.looseObject({
|
|
572
|
+
type: z3.literal("inline"),
|
|
573
|
+
name: z3.string(),
|
|
574
|
+
description: z3.string(),
|
|
575
|
+
instructions: z3.string()
|
|
576
|
+
})
|
|
538
577
|
])
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
description: z3.string(),
|
|
544
|
-
instructions: z3.string()
|
|
545
|
-
})
|
|
546
|
-
])
|
|
547
|
-
).optional()
|
|
548
|
-
});
|
|
578
|
+
).optional()
|
|
579
|
+
})
|
|
580
|
+
)
|
|
581
|
+
);
|
|
549
582
|
|
|
550
583
|
// src/perplexity-prepare-tools.ts
|
|
551
584
|
function preparePerplexityTools({
|
|
@@ -771,7 +804,7 @@ var PerplexityLanguageModel = class {
|
|
|
771
804
|
errorToMessage: perplexityErrorToMessage
|
|
772
805
|
}),
|
|
773
806
|
successfulResponseHandler: createJsonResponseHandler(
|
|
774
|
-
|
|
807
|
+
perplexityAgentResponseSchemaValidator
|
|
775
808
|
),
|
|
776
809
|
abortSignal: options.abortSignal,
|
|
777
810
|
fetch: this.config.fetch
|
|
@@ -1313,20 +1346,24 @@ function decodeEmbedding(base64, encodingFormat) {
|
|
|
1313
1346
|
}
|
|
1314
1347
|
return Array.from(bytes);
|
|
1315
1348
|
}
|
|
1316
|
-
var perplexityEmbeddingResponseSchema =
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
})
|
|
1349
|
+
var perplexityEmbeddingResponseSchema = lazySchema4(
|
|
1350
|
+
() => zodSchema4(
|
|
1351
|
+
z4.object({
|
|
1352
|
+
data: z4.array(z4.object({ embedding: z4.string() })),
|
|
1353
|
+
usage: z4.object({
|
|
1354
|
+
prompt_tokens: z4.number(),
|
|
1355
|
+
cost: z4.object({
|
|
1356
|
+
input_cost: z4.number().nullish(),
|
|
1357
|
+
total_cost: z4.number().nullish(),
|
|
1358
|
+
currency: z4.string().nullish()
|
|
1359
|
+
}).nullish()
|
|
1360
|
+
}).nullish()
|
|
1361
|
+
})
|
|
1362
|
+
)
|
|
1363
|
+
);
|
|
1327
1364
|
|
|
1328
1365
|
// src/version.ts
|
|
1329
|
-
var VERSION = true ? "3.1.
|
|
1366
|
+
var VERSION = true ? "3.1.8" : "0.0.0-test";
|
|
1330
1367
|
|
|
1331
1368
|
// src/perplexity-provider.ts
|
|
1332
1369
|
function createPerplexity(options = {}) {
|