@ai-sdk/perplexity 3.1.6 → 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 +16 -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
|
@@ -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 SharedV3Warning,
|
|
12
12
|
} from '@ai-sdk/provider';
|
|
13
13
|
import {
|
|
14
|
+
type InferSchema,
|
|
14
15
|
combineHeaders,
|
|
15
16
|
createEventSourceResponseHandler,
|
|
16
17
|
createJsonErrorResponseHandler,
|
|
@@ -26,6 +27,7 @@ import { convertToPerplexityInput } from './convert-to-perplexity-input';
|
|
|
26
27
|
import { mapPerplexityFinishReason } from './map-perplexity-finish-reason';
|
|
27
28
|
import {
|
|
28
29
|
perplexityAgentChunkSchema,
|
|
30
|
+
perplexityAgentResponseSchemaValidator,
|
|
29
31
|
perplexityAgentResponseSchema,
|
|
30
32
|
perplexityErrorSchema,
|
|
31
33
|
perplexityErrorToMessage,
|
|
@@ -48,9 +50,13 @@ type PerplexityAgentConfig = {
|
|
|
48
50
|
fetch?: FetchFunction;
|
|
49
51
|
};
|
|
50
52
|
|
|
51
|
-
type PerplexityOutputItem = z.infer<
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
type PerplexityOutputItem = z.infer<
|
|
54
|
+
ReturnType<typeof perplexityOutputItemSchema>
|
|
55
|
+
>;
|
|
56
|
+
type PerplexitySearchResult = z.infer<
|
|
57
|
+
ReturnType<typeof perplexitySearchResultSchema>
|
|
58
|
+
>;
|
|
59
|
+
type PerplexityUsage = z.infer<ReturnType<typeof perplexityUsageSchema>>;
|
|
54
60
|
type PerplexityUrlSource = Extract<
|
|
55
61
|
LanguageModelV3Content,
|
|
56
62
|
{ type: 'source'; sourceType: 'url' }
|
|
@@ -296,7 +302,7 @@ export class PerplexityLanguageModel implements LanguageModelV3 {
|
|
|
296
302
|
errorToMessage: perplexityErrorToMessage,
|
|
297
303
|
}),
|
|
298
304
|
successfulResponseHandler: createJsonResponseHandler(
|
|
299
|
-
|
|
305
|
+
perplexityAgentResponseSchemaValidator,
|
|
300
306
|
),
|
|
301
307
|
abortSignal: options.abortSignal,
|
|
302
308
|
fetch: this.config.fetch,
|
|
@@ -452,7 +458,7 @@ export class PerplexityLanguageModel implements LanguageModelV3 {
|
|
|
452
458
|
return {
|
|
453
459
|
stream: response.pipeThrough(
|
|
454
460
|
new TransformStream<
|
|
455
|
-
ParseResult<
|
|
461
|
+
ParseResult<InferSchema<typeof perplexityAgentChunkSchema>>,
|
|
456
462
|
LanguageModelV3StreamPart
|
|
457
463
|
>({
|
|
458
464
|
start(controller) {
|