@ai-sdk/perplexity 5.0.16 → 5.0.17
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.ts +86 -115
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -46
- package/dist/index.js.map +1 -1
- package/docs/70-perplexity.mdx +50 -5
- package/package.json +2 -2
- package/src/perplexity-agent-api.ts +184 -161
- package/src/perplexity-decision-model.ts +34 -28
- 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 -6
|
@@ -1,124 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
|
-
const userLocationSchema =
|
|
4
|
-
latitude: z.number().optional(),
|
|
5
|
-
longitude: z.number().optional(),
|
|
6
|
-
country: z.string().optional(),
|
|
7
|
-
city: z.string().optional(),
|
|
8
|
-
region: z.string().optional(),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const webSearchFiltersSchema = z.looseObject({
|
|
12
|
-
search_domain_filter: z.array(z.string()).optional(),
|
|
13
|
-
search_recency_filter: z
|
|
14
|
-
.enum(['hour', 'day', 'week', 'month', 'year'])
|
|
15
|
-
.optional(),
|
|
16
|
-
search_after_date_filter: z.string().optional(),
|
|
17
|
-
search_before_date_filter: z.string().optional(),
|
|
18
|
-
last_updated_after_filter: z.string().optional(),
|
|
19
|
-
last_updated_before_filter: z.string().optional(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const webSearchToolSchema = z.looseObject({
|
|
23
|
-
type: z.literal('web_search'),
|
|
24
|
-
filters: webSearchFiltersSchema.optional(),
|
|
25
|
-
max_results: z.number().int().positive().optional(),
|
|
26
|
-
max_tokens: z.number().optional(),
|
|
27
|
-
max_tokens_per_page: z.number().optional(),
|
|
28
|
-
search_context_size: z.enum(['low', 'medium', 'high']).optional(),
|
|
29
|
-
user_location: userLocationSchema.optional(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const nativeToolSchema = z.union([
|
|
33
|
-
webSearchToolSchema,
|
|
8
|
+
const userLocationSchema = () =>
|
|
34
9
|
z.looseObject({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
10
|
+
latitude: z.number().optional(),
|
|
11
|
+
longitude: z.number().optional(),
|
|
12
|
+
country: z.string().optional(),
|
|
13
|
+
city: z.string().optional(),
|
|
14
|
+
region: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const webSearchFiltersSchema = () =>
|
|
41
18
|
z.looseObject({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
19
|
+
search_domain_filter: z.array(z.string()).optional(),
|
|
20
|
+
search_recency_filter: z
|
|
21
|
+
.enum(['hour', 'day', 'week', 'month', 'year'])
|
|
22
|
+
.optional(),
|
|
23
|
+
search_after_date_filter: z.string().optional(),
|
|
24
|
+
search_before_date_filter: z.string().optional(),
|
|
25
|
+
last_updated_after_filter: z.string().optional(),
|
|
26
|
+
last_updated_before_filter: z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const webSearchToolSchema = () =>
|
|
50
30
|
z.looseObject({
|
|
51
|
-
type: z.literal('
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
31
|
+
type: z.literal('web_search'),
|
|
32
|
+
filters: webSearchFiltersSchema().optional(),
|
|
33
|
+
max_results: z.number().int().positive().optional(),
|
|
34
|
+
max_tokens: z.number().optional(),
|
|
35
|
+
max_tokens_per_page: z.number().optional(),
|
|
36
|
+
search_context_size: z.enum(['low', 'medium', 'high']).optional(),
|
|
37
|
+
user_location: userLocationSchema().optional(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const nativeToolSchema = () =>
|
|
41
|
+
z.union([
|
|
42
|
+
webSearchToolSchema(),
|
|
43
|
+
z.looseObject({
|
|
44
|
+
type: z.literal('fetch_url'),
|
|
45
|
+
max_urls: z.number().optional(),
|
|
46
|
+
}),
|
|
47
|
+
z.looseObject({ type: z.literal('people_search') }),
|
|
48
|
+
z.looseObject({ type: z.literal('finance_search') }),
|
|
49
|
+
z.looseObject({ type: z.literal('sandbox') }),
|
|
50
|
+
z.looseObject({
|
|
51
|
+
type: z.literal('mcp'),
|
|
52
|
+
server_label: z.string(),
|
|
53
|
+
server_url: z.string(),
|
|
54
|
+
allowed_tools: z.array(z.string()).optional(),
|
|
55
|
+
authorization: z.string().optional(),
|
|
56
|
+
defer_loading: z.boolean().optional(),
|
|
57
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
58
|
+
}),
|
|
59
|
+
z.looseObject({
|
|
60
|
+
type: z.literal('connector'),
|
|
61
|
+
id: z.string(),
|
|
62
|
+
server_label: z.string(),
|
|
63
|
+
server_description: z.string().optional(),
|
|
64
|
+
allowed_tools: z.array(z.string()).optional(),
|
|
65
|
+
}),
|
|
66
|
+
]);
|
|
58
67
|
|
|
59
|
-
export const perplexityLanguageModelOptions =
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
export const perplexityLanguageModelOptions = lazySchema(() =>
|
|
69
|
+
zodSchema(
|
|
70
|
+
z.looseObject({
|
|
71
|
+
/** Top-level Agent API instructions. */
|
|
72
|
+
instructions: z.string().optional(),
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Native Agent API tools. AI SDK function tools can also be supplied through
|
|
76
|
+
* the top-level `tools` option on `generateText` and `streamText`.
|
|
77
|
+
*/
|
|
78
|
+
tools: z.array(nativeToolSchema()).optional(),
|
|
68
79
|
|
|
69
|
-
|
|
70
|
-
|
|
80
|
+
/** A fallback model list for Agent API routing. */
|
|
81
|
+
models: z.array(z.string()).optional(),
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
/** Maximum number of agentic steps. */
|
|
84
|
+
max_steps: z.number().int().positive().optional(),
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
/** Maximum number of native tool calls. */
|
|
87
|
+
max_tool_calls: z.number().int().nonnegative().optional(),
|
|
77
88
|
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
/** Continue a conversation from an earlier Agent API response. */
|
|
90
|
+
previous_response_id: z.string().optional(),
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Whether the response can be retrieved later. Setting this to false does
|
|
94
|
+
* not disable persistence or prevent previous_response_id continuations.
|
|
95
|
+
*/
|
|
96
|
+
store: z.boolean().optional(),
|
|
86
97
|
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
/** Preferred response language as an ISO 639-1 language code. */
|
|
99
|
+
language_preference: z.string().optional(),
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
/** Agent API reasoning configuration. */
|
|
102
|
+
reasoning: z
|
|
103
|
+
.looseObject({
|
|
104
|
+
effort: z
|
|
105
|
+
.enum(['minimal', 'low', 'medium', 'high', 'xhigh'])
|
|
106
|
+
.optional(),
|
|
107
|
+
})
|
|
108
|
+
.optional(),
|
|
96
109
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
/** Agent API skill configuration. */
|
|
111
|
+
skills: z
|
|
112
|
+
.array(
|
|
113
|
+
z.union([
|
|
114
|
+
z.looseObject({
|
|
115
|
+
type: z.literal('builtin'),
|
|
116
|
+
name: z.enum([
|
|
117
|
+
'office',
|
|
118
|
+
'office/docx',
|
|
119
|
+
'office/pdf',
|
|
120
|
+
'office/pptx',
|
|
121
|
+
'office/xlsx',
|
|
122
|
+
]),
|
|
123
|
+
}),
|
|
124
|
+
z.looseObject({
|
|
125
|
+
type: z.literal('inline'),
|
|
126
|
+
name: z.string(),
|
|
127
|
+
description: z.string(),
|
|
128
|
+
instructions: z.string(),
|
|
129
|
+
}),
|
|
109
130
|
]),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
instructions: z.string(),
|
|
116
|
-
}),
|
|
117
|
-
]),
|
|
118
|
-
)
|
|
119
|
-
.optional(),
|
|
120
|
-
});
|
|
131
|
+
)
|
|
132
|
+
.optional(),
|
|
133
|
+
}),
|
|
134
|
+
),
|
|
135
|
+
);
|
|
121
136
|
|
|
122
|
-
export type PerplexityLanguageModelOptions =
|
|
137
|
+
export type PerplexityLanguageModelOptions = InferSchema<
|
|
123
138
|
typeof perplexityLanguageModelOptions
|
|
124
139
|
>;
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type SharedV4Warning,
|
|
12
12
|
} from '@ai-sdk/provider';
|
|
13
13
|
import {
|
|
14
|
+
type InferSchema,
|
|
14
15
|
combineHeaders,
|
|
15
16
|
createEventSourceResponseHandler,
|
|
16
17
|
createJsonErrorResponseHandler,
|
|
@@ -32,7 +33,7 @@ import { convertToPerplexityInput } from './convert-to-perplexity-input';
|
|
|
32
33
|
import { mapPerplexityFinishReason } from './map-perplexity-finish-reason';
|
|
33
34
|
import {
|
|
34
35
|
perplexityAgentChunkSchema,
|
|
35
|
-
|
|
36
|
+
perplexityAgentResponseSchemaValidator,
|
|
36
37
|
perplexityErrorSchema,
|
|
37
38
|
perplexityErrorToMessage,
|
|
38
39
|
type PerplexityAgentTool,
|
|
@@ -54,9 +55,13 @@ type PerplexityAgentConfig = {
|
|
|
54
55
|
fetch?: FetchFunction;
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
type PerplexityOutputItem = z.infer<
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
type PerplexityOutputItem = z.infer<
|
|
59
|
+
ReturnType<typeof perplexityOutputItemSchema>
|
|
60
|
+
>;
|
|
61
|
+
type PerplexitySearchResult = z.infer<
|
|
62
|
+
ReturnType<typeof perplexitySearchResultSchema>
|
|
63
|
+
>;
|
|
64
|
+
type PerplexityUsage = z.infer<ReturnType<typeof perplexityUsageSchema>>;
|
|
60
65
|
type PerplexityUrlSource = Extract<
|
|
61
66
|
LanguageModelV4Content,
|
|
62
67
|
{ type: 'source'; sourceType: 'url' }
|
|
@@ -339,7 +344,7 @@ export class PerplexityLanguageModel implements LanguageModelV4 {
|
|
|
339
344
|
errorToMessage: perplexityErrorToMessage,
|
|
340
345
|
}),
|
|
341
346
|
successfulResponseHandler: createJsonResponseHandler(
|
|
342
|
-
|
|
347
|
+
perplexityAgentResponseSchemaValidator,
|
|
343
348
|
),
|
|
344
349
|
abortSignal: options.abortSignal,
|
|
345
350
|
fetch: this.config.fetch,
|
|
@@ -495,7 +500,7 @@ export class PerplexityLanguageModel implements LanguageModelV4 {
|
|
|
495
500
|
return {
|
|
496
501
|
stream: response.pipeThrough(
|
|
497
502
|
new TransformStream<
|
|
498
|
-
ParseResult<
|
|
503
|
+
ParseResult<InferSchema<typeof perplexityAgentChunkSchema>>,
|
|
499
504
|
LanguageModelV4StreamPart
|
|
500
505
|
>({
|
|
501
506
|
start(controller) {
|