@activepieces/piece-ai 0.1.21 → 0.2.0
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/package.json +2 -2
- package/src/lib/actions/agents/run-agent.d.ts +2 -0
- package/src/lib/actions/agents/run-agent.d.ts.map +1 -1
- package/src/lib/actions/agents/run-agent.js +27 -15
- package/src/lib/actions/agents/run-agent.js.map +1 -1
- package/src/lib/actions/text/ask-ai.d.ts +0 -25
- package/src/lib/actions/text/ask-ai.d.ts.map +1 -1
- package/src/lib/actions/text/ask-ai.js +13 -167
- package/src/lib/actions/text/ask-ai.js.map +1 -1
- package/src/lib/common/web-search.d.ts +37 -0
- package/src/lib/common/web-search.d.ts.map +1 -0
- package/src/lib/common/web-search.js +188 -0
- package/src/lib/common/web-search.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/piece-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@activepieces/pieces-common": "0.12.0",
|
|
9
9
|
"@activepieces/pieces-framework": "0.26.0",
|
|
10
|
-
"@activepieces/shared": "0.
|
|
10
|
+
"@activepieces/shared": "0.45.0",
|
|
11
11
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
12
12
|
"@ai-sdk/azure": "^3.0.0",
|
|
13
13
|
"@ai-sdk/google": "^3.0.0",
|
|
@@ -4,5 +4,7 @@ export declare const runAgent: import("@activepieces/pieces-framework").IAction<
|
|
|
4
4
|
agentTools: import("@activepieces/pieces-framework").ArrayProperty<true> | import("@activepieces/pieces-framework").ArrayProperty<false>;
|
|
5
5
|
structuredOutput: import("@activepieces/pieces-framework").ArrayProperty<true> | import("@activepieces/pieces-framework").ArrayProperty<false>;
|
|
6
6
|
maxSteps: import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
7
|
+
webSearch: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
8
|
+
webSearchOptions: import("@activepieces/pieces-framework").DynamicProperties<false, undefined>;
|
|
7
9
|
}>;
|
|
8
10
|
//# sourceMappingURL=run-agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-agent.d.ts","sourceRoot":"","sources":["../../../../../src/lib/actions/agents/run-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-agent.d.ts","sourceRoot":"","sources":["../../../../../src/lib/actions/agents/run-agent.ts"],"names":[],"mappings":"AA+DA,eAAO,MAAM,QAAQ;;;;;;;;EAwPnB,CAAC"}
|
|
@@ -10,6 +10,7 @@ const ai_sdk_1 = require("../../common/ai-sdk");
|
|
|
10
10
|
const util_1 = require("util");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
const tools_1 = require("./tools");
|
|
13
|
+
const web_search_1 = require("../../common/web-search");
|
|
13
14
|
const agentToolArrayItems = {
|
|
14
15
|
type: pieces_framework_1.Property.ShortText({
|
|
15
16
|
displayName: 'Tool Type',
|
|
@@ -85,21 +86,29 @@ exports.runAgent = (0, pieces_framework_1.createAction)({
|
|
|
85
86
|
required: true,
|
|
86
87
|
defaultValue: 20,
|
|
87
88
|
}),
|
|
89
|
+
[shared_1.AgentPieceProps.WEB_SEARCH]: pieces_framework_1.Property.Checkbox({
|
|
90
|
+
displayName: 'Web Search',
|
|
91
|
+
required: false,
|
|
92
|
+
defaultValue: false,
|
|
93
|
+
description: 'Whether to use web search to find information for the AI to use.',
|
|
94
|
+
}),
|
|
95
|
+
[shared_1.AgentPieceProps.WEB_SEARCH_OPTIONS]: (0, web_search_1.buildWebSearchOptionsProperty)((propsValue) => { var _a; return (_a = propsValue['aiProviderModel']) === null || _a === void 0 ? void 0 : _a.provider; }, ['webSearch', 'aiProviderModel'], { showIncludeSources: false }),
|
|
88
96
|
},
|
|
89
97
|
run(context) {
|
|
90
98
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
91
99
|
var _a, e_1, _b, _c;
|
|
100
|
+
var _d;
|
|
92
101
|
const { prompt, maxSteps, aiProviderModel } = context.propsValue;
|
|
93
102
|
const agentProviderModel = aiProviderModel;
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
runId: context.run.id,
|
|
103
|
+
const provider = agentProviderModel.provider;
|
|
104
|
+
const webSearchEnabled = !!(context.propsValue.webSearch);
|
|
105
|
+
const webSearchOptions = ((_d = context.propsValue.webSearchOptions) !== null && _d !== void 0 ? _d : {});
|
|
106
|
+
const { tools: webSearchTools, providerOptions } = (0, web_search_1.buildWebSearchConfig)({
|
|
107
|
+
provider,
|
|
108
|
+
webSearchEnabled,
|
|
109
|
+
webSearchOptions,
|
|
102
110
|
});
|
|
111
|
+
const model = yield (0, ai_sdk_1.createAIModel)(Object.assign({ modelId: agentProviderModel.model, provider, engineToken: context.server.token, apiUrl: context.server.apiUrl, projectId: context.project.id, flowId: context.flows.current.id, runId: context.run.id }, (0, shared_1.spreadIfDefined)('openaiResponsesModel', webSearchEnabled && provider === shared_1.AIProviderName.OPENAI ? true : undefined)));
|
|
103
112
|
const outputBuilder = (0, agent_output_builder_1.agentOutputBuilder)(prompt);
|
|
104
113
|
const hasStructuredOutput = !(0, shared_1.isNil)(context.propsValue.structuredOutput) &&
|
|
105
114
|
context.propsValue.structuredOutput.length > 0;
|
|
@@ -113,22 +122,25 @@ exports.runAgent = (0, pieces_framework_1.createAction)({
|
|
|
113
122
|
structuredOutput
|
|
114
123
|
});
|
|
115
124
|
outputBuilder.setToolMap(toolKeyToAgentTool);
|
|
125
|
+
const allTools = webSearchTools
|
|
126
|
+
? Object.assign(Object.assign({}, webSearchTools), tools) : tools;
|
|
116
127
|
const errors = [];
|
|
117
128
|
try {
|
|
118
129
|
const stream = (0, ai_1.streamText)({
|
|
119
130
|
model: model,
|
|
120
131
|
system: utils_1.agentUtils.getPrompts(prompt).system,
|
|
121
132
|
prompt: utils_1.agentUtils.getPrompts(prompt).prompt,
|
|
122
|
-
tools,
|
|
133
|
+
tools: allTools,
|
|
123
134
|
stopWhen: [(0, ai_1.stepCountIs)(maxSteps), (0, ai_1.hasToolCall)(shared_1.TASK_COMPLETION_TOOL_NAME)],
|
|
135
|
+
providerOptions,
|
|
124
136
|
onFinish: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
137
|
yield Promise.all(mcpClients.map((client) => tslib_1.__awaiter(this, void 0, void 0, function* () { return client.close(); })));
|
|
126
138
|
}),
|
|
127
139
|
});
|
|
128
140
|
try {
|
|
129
|
-
for (var
|
|
130
|
-
_c =
|
|
131
|
-
|
|
141
|
+
for (var _e = true, _f = tslib_1.__asyncValues(stream.fullStream), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
|
|
142
|
+
_c = _g.value;
|
|
143
|
+
_e = false;
|
|
132
144
|
const chunk = _c;
|
|
133
145
|
try {
|
|
134
146
|
switch (chunk.type) {
|
|
@@ -210,7 +222,7 @@ exports.runAgent = (0, pieces_framework_1.createAction)({
|
|
|
210
222
|
? `${innerError.message}${innerError.stack ? `\n${innerError.stack}` : ''}`
|
|
211
223
|
: (0, util_1.inspect)(innerError);
|
|
212
224
|
}
|
|
213
|
-
catch (
|
|
225
|
+
catch (_h) {
|
|
214
226
|
detailsStr = String(innerError);
|
|
215
227
|
}
|
|
216
228
|
errors.push({
|
|
@@ -224,7 +236,7 @@ exports.runAgent = (0, pieces_framework_1.createAction)({
|
|
|
224
236
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
225
237
|
finally {
|
|
226
238
|
try {
|
|
227
|
-
if (!
|
|
239
|
+
if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
|
|
228
240
|
}
|
|
229
241
|
finally { if (e_1) throw e_1.error; }
|
|
230
242
|
}
|
|
@@ -236,7 +248,7 @@ exports.runAgent = (0, pieces_framework_1.createAction)({
|
|
|
236
248
|
yield context.output.update({ data: outputBuilder.build() });
|
|
237
249
|
}
|
|
238
250
|
}
|
|
239
|
-
catch (
|
|
251
|
+
catch (_j) {
|
|
240
252
|
// ignore
|
|
241
253
|
}
|
|
242
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-agent.js","sourceRoot":"","sources":["../../../../../src/lib/actions/agents/run-agent.ts"],"names":[],"mappings":";;;;AAAA,qEAKwC;AAExC,
|
|
1
|
+
{"version":3,"file":"run-agent.js","sourceRoot":"","sources":["../../../../../src/lib/actions/agents/run-agent.ts"],"names":[],"mappings":";;;;AAAA,qEAKwC;AAExC,iDAY8B;AAC9B,2BAA0D;AAC1D,iEAA4D;AAC5D,gDAAoD;AACpD,+BAA+B;AAC/B,mCAAqC;AACrC,mCAA8C;AAC9C,wDAAgH;AAEhH,MAAM,mBAAmB,GAA2B;IAClD,IAAI,EAAE,2BAAQ,CAAC,SAAS,CAAC;QACvB,WAAW,EAAE,WAAW;QACxB,QAAQ,EAAE,IAAI;KACf,CAAC;IAEF,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;QAC3B,WAAW,EAAE,WAAW;QACxB,QAAQ,EAAE,IAAI;KACf,CAAC;IAEF,aAAa,EAAE,2BAAQ,CAAC,IAAI,CAAC;QAC3B,WAAW,EAAE,gBAAgB;QAC7B,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEF,cAAc,EAAE,2BAAQ,CAAC,SAAS,CAAC;QACjC,WAAW,EAAE,kBAAkB;QAC/B,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEF,SAAS,EAAE,2BAAQ,CAAC,SAAS,CAAC;QAC5B,WAAW,EAAE,gBAAgB;QAC7B,QAAQ,EAAE,KAAK;KAChB,CAAC;IACF,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;QAC3B,WAAW,EAAE,UAAU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").PieceAuthProperty, {
|
|
3
2
|
provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
|
|
4
3
|
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
|
|
@@ -9,28 +8,4 @@ export declare const askAI: import("@activepieces/pieces-framework").IAction<imp
|
|
|
9
8
|
webSearch: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
10
9
|
webSearchOptions: import("@activepieces/pieces-framework").DynamicProperties<false, undefined>;
|
|
11
10
|
}>;
|
|
12
|
-
export declare function createWebSearchTool(provider: string, options?: WebSearchOptions): ToolSet;
|
|
13
|
-
type BaseWebSearchOptions = {
|
|
14
|
-
maxUses?: number;
|
|
15
|
-
includeSources?: boolean;
|
|
16
|
-
};
|
|
17
|
-
type UserLocationOptions = {
|
|
18
|
-
userLocationCity?: string;
|
|
19
|
-
userLocationRegion?: string;
|
|
20
|
-
userLocationCountry?: string;
|
|
21
|
-
userLocationTimezone?: string;
|
|
22
|
-
};
|
|
23
|
-
type AnthropicWebSearchOptions = BaseWebSearchOptions & UserLocationOptions & {
|
|
24
|
-
allowedDomains?: {
|
|
25
|
-
domain: string;
|
|
26
|
-
}[];
|
|
27
|
-
blockedDomains?: {
|
|
28
|
-
domain: string;
|
|
29
|
-
}[];
|
|
30
|
-
};
|
|
31
|
-
type OpenAIWebSearchOptions = BaseWebSearchOptions & UserLocationOptions & {
|
|
32
|
-
searchContextSize?: 'low' | 'medium' | 'high';
|
|
33
|
-
};
|
|
34
|
-
export type WebSearchOptions = AnthropicWebSearchOptions | OpenAIWebSearchOptions;
|
|
35
|
-
export {};
|
|
36
11
|
//# sourceMappingURL=ask-ai.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-ai.d.ts","sourceRoot":"","sources":["../../../../../src/lib/actions/text/ask-ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ask-ai.d.ts","sourceRoot":"","sources":["../../../../../src/lib/actions/text/ask-ai.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,KAAK;;;;;;;;;EAkHhB,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.askAI = void 0;
|
|
4
|
-
exports.createWebSearchTool = createWebSearchTool;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
6
|
const ai_1 = require("ai");
|
|
8
|
-
const shared_1 = require("@activepieces/shared");
|
|
9
7
|
const props_1 = require("../../common/props");
|
|
10
8
|
const ai_sdk_1 = require("../../common/ai-sdk");
|
|
9
|
+
const web_search_1 = require("../../common/web-search");
|
|
11
10
|
exports.askAI = (0, pieces_framework_1.createAction)({
|
|
12
11
|
name: 'askAi',
|
|
13
12
|
displayName: 'Ask AI',
|
|
@@ -40,103 +39,7 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
40
39
|
defaultValue: false,
|
|
41
40
|
description: 'Whether to use web search to find information for the AI to use in its response.',
|
|
42
41
|
}),
|
|
43
|
-
webSearchOptions:
|
|
44
|
-
displayName: 'Web Search Options',
|
|
45
|
-
required: false,
|
|
46
|
-
auth: pieces_framework_1.PieceAuth.None(),
|
|
47
|
-
refreshers: ['webSearch', 'provider', 'model'],
|
|
48
|
-
props: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
const webSearchEnabled = propsValue['webSearch'];
|
|
50
|
-
const provider = propsValue['provider'];
|
|
51
|
-
const isOpenRouterProvider = provider === shared_1.AIProviderName.OPENROUTER ||
|
|
52
|
-
provider === shared_1.AIProviderName.ACTIVEPIECES;
|
|
53
|
-
const supportsToolBasedWebSearch = provider === shared_1.AIProviderName.OPENAI ||
|
|
54
|
-
provider === shared_1.AIProviderName.ANTHROPIC ||
|
|
55
|
-
provider === shared_1.AIProviderName.GOOGLE;
|
|
56
|
-
if (!webSearchEnabled) {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
let options = {
|
|
60
|
-
maxUses: pieces_framework_1.Property.Number({
|
|
61
|
-
displayName: 'Max Web Search Uses',
|
|
62
|
-
required: false,
|
|
63
|
-
defaultValue: 5,
|
|
64
|
-
description: isOpenRouterProvider
|
|
65
|
-
? 'For OpenRouter/Activepieces, this maps to OpenRouter web plugin max_results (1-10). Default is 5.'
|
|
66
|
-
: 'Maximum number of searches to use. Default is 5.',
|
|
67
|
-
}),
|
|
68
|
-
};
|
|
69
|
-
if (supportsToolBasedWebSearch) {
|
|
70
|
-
options = Object.assign(Object.assign({}, options), { includeSources: pieces_framework_1.Property.Checkbox({
|
|
71
|
-
displayName: 'Include Sources',
|
|
72
|
-
description: 'Whether to include the sources in the response. Useful for getting web search details (e.g. search queries, searched URLs, etc).',
|
|
73
|
-
required: false,
|
|
74
|
-
defaultValue: false,
|
|
75
|
-
}) });
|
|
76
|
-
}
|
|
77
|
-
const userLocationOptions = {
|
|
78
|
-
userLocationCity: pieces_framework_1.Property.ShortText({
|
|
79
|
-
displayName: 'User Location - City',
|
|
80
|
-
required: false,
|
|
81
|
-
description: 'The city name for localizing search results (e.g., San Francisco).',
|
|
82
|
-
}),
|
|
83
|
-
userLocationRegion: pieces_framework_1.Property.ShortText({
|
|
84
|
-
displayName: 'User Location - Region',
|
|
85
|
-
required: false,
|
|
86
|
-
description: 'The region or state for localizing search results (e.g., California).',
|
|
87
|
-
}),
|
|
88
|
-
userLocationCountry: pieces_framework_1.Property.ShortText({
|
|
89
|
-
displayName: 'User Location - Country',
|
|
90
|
-
required: false,
|
|
91
|
-
description: 'The country code for localizing search results (e.g., US).',
|
|
92
|
-
}),
|
|
93
|
-
userLocationTimezone: pieces_framework_1.Property.ShortText({
|
|
94
|
-
displayName: 'User Location - Timezone',
|
|
95
|
-
required: false,
|
|
96
|
-
description: 'The IANA timezone ID for localizing search results (e.g., America/Los_Angeles).',
|
|
97
|
-
}),
|
|
98
|
-
};
|
|
99
|
-
if (provider === shared_1.AIProviderName.ANTHROPIC) {
|
|
100
|
-
options = Object.assign(Object.assign(Object.assign({}, options), { allowedDomains: pieces_framework_1.Property.Array({
|
|
101
|
-
displayName: 'Allowed Domains',
|
|
102
|
-
required: false,
|
|
103
|
-
description: 'List of domains to search (e.g., example.com, docs.example.com/blog). Domains should not include HTTP/HTTPS scheme. Subdomains are automatically included unless more specific subpaths are provided. Overrides Blocked Domains if both are provided.',
|
|
104
|
-
properties: {
|
|
105
|
-
domain: pieces_framework_1.Property.ShortText({
|
|
106
|
-
displayName: 'Domain',
|
|
107
|
-
required: true,
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
}), blockedDomains: pieces_framework_1.Property.Array({
|
|
111
|
-
displayName: 'Blocked Domains',
|
|
112
|
-
required: false,
|
|
113
|
-
description: 'List of domains to exclude from search (e.g., example.com, docs.example.com/blog). Domains should not include HTTP/HTTPS scheme. Subdomains are automatically included unless more specific subpaths are provided. Overrided by Allowed Domains if both are provided.',
|
|
114
|
-
properties: {
|
|
115
|
-
domain: pieces_framework_1.Property.ShortText({
|
|
116
|
-
displayName: 'Domain',
|
|
117
|
-
required: true,
|
|
118
|
-
}),
|
|
119
|
-
},
|
|
120
|
-
}) }), userLocationOptions);
|
|
121
|
-
}
|
|
122
|
-
if (provider === shared_1.AIProviderName.OPENAI) {
|
|
123
|
-
options = Object.assign(Object.assign(Object.assign({}, options), { searchContextSize: pieces_framework_1.Property.StaticDropdown({
|
|
124
|
-
displayName: 'Search Context Size',
|
|
125
|
-
required: false,
|
|
126
|
-
defaultValue: 'medium',
|
|
127
|
-
options: {
|
|
128
|
-
options: [
|
|
129
|
-
{ label: 'Low', value: 'low' },
|
|
130
|
-
{ label: 'Medium', value: 'medium' },
|
|
131
|
-
{ label: 'High', value: 'high' },
|
|
132
|
-
],
|
|
133
|
-
},
|
|
134
|
-
description: 'High level guidance for the amount of context window space to use for the search.',
|
|
135
|
-
}) }), userLocationOptions);
|
|
136
|
-
}
|
|
137
|
-
return options;
|
|
138
|
-
}),
|
|
139
|
-
}),
|
|
42
|
+
webSearchOptions: (0, web_search_1.buildWebSearchOptionsProperty)((propsValue) => propsValue['provider'], ['webSearch', 'provider', 'model']),
|
|
140
43
|
},
|
|
141
44
|
run(context) {
|
|
142
45
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -144,10 +47,12 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
144
47
|
const provider = context.propsValue.provider;
|
|
145
48
|
const modelId = context.propsValue.model;
|
|
146
49
|
const storage = context.store;
|
|
147
|
-
const webSearchOptions = context.propsValue.webSearchOptions;
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
50
|
+
const webSearchOptions = ((_a = context.propsValue.webSearchOptions) !== null && _a !== void 0 ? _a : {});
|
|
51
|
+
const { tools: webSearchTools, providerOptions } = (0, web_search_1.buildWebSearchConfig)({
|
|
52
|
+
provider,
|
|
53
|
+
webSearchEnabled: !!context.propsValue.webSearch,
|
|
54
|
+
webSearchOptions,
|
|
55
|
+
});
|
|
151
56
|
const model = yield (0, ai_sdk_1.createAIModel)({
|
|
152
57
|
provider: provider,
|
|
153
58
|
modelId,
|
|
@@ -163,26 +68,13 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
163
68
|
: null;
|
|
164
69
|
let conversation = null;
|
|
165
70
|
if (conversationKey) {
|
|
166
|
-
conversation = (
|
|
71
|
+
conversation = (_b = (yield storage.get(conversationKey))) !== null && _b !== void 0 ? _b : [];
|
|
167
72
|
if (!conversation) {
|
|
168
73
|
yield storage.put(conversationKey, { messages: [] });
|
|
169
74
|
}
|
|
170
75
|
}
|
|
171
|
-
const
|
|
172
|
-
?
|
|
173
|
-
: createWebSearchTool(provider, webSearchOptions);
|
|
174
|
-
const stopWhen = tools
|
|
175
|
-
? (0, ai_1.stepCountIs)((_b = webSearchOptions === null || webSearchOptions === void 0 ? void 0 : webSearchOptions.maxUses) !== null && _b !== void 0 ? _b : 5)
|
|
176
|
-
: undefined;
|
|
177
|
-
const providerOptions = isOpenRouterWebSearch
|
|
178
|
-
? {
|
|
179
|
-
openrouter: {
|
|
180
|
-
plugins: [{
|
|
181
|
-
id: 'web',
|
|
182
|
-
max_results: Math.min(Math.max((_c = webSearchOptions === null || webSearchOptions === void 0 ? void 0 : webSearchOptions.maxUses) !== null && _c !== void 0 ? _c : 5, 1), 10),
|
|
183
|
-
}],
|
|
184
|
-
},
|
|
185
|
-
}
|
|
76
|
+
const stopWhen = webSearchTools
|
|
77
|
+
? (0, ai_1.stepCountIs)((_c = webSearchOptions === null || webSearchOptions === void 0 ? void 0 : webSearchOptions.maxUses) !== null && _c !== void 0 ? _c : 5)
|
|
186
78
|
: undefined;
|
|
187
79
|
const response = yield (0, ai_1.generateText)({
|
|
188
80
|
model,
|
|
@@ -195,7 +87,7 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
195
87
|
],
|
|
196
88
|
maxOutputTokens: context.propsValue.maxOutputTokens,
|
|
197
89
|
temperature: ((_d = context.propsValue.creativity) !== null && _d !== void 0 ? _d : 100) / 100,
|
|
198
|
-
tools,
|
|
90
|
+
tools: webSearchTools,
|
|
199
91
|
stopWhen,
|
|
200
92
|
providerOptions,
|
|
201
93
|
});
|
|
@@ -210,7 +102,7 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
210
102
|
if (conversationKey) {
|
|
211
103
|
yield storage.put(conversationKey, conversation);
|
|
212
104
|
}
|
|
213
|
-
const includeSources =
|
|
105
|
+
const includeSources = webSearchTools && webSearchOptions.includeSources;
|
|
214
106
|
if (includeSources) {
|
|
215
107
|
return { text: response.text, sources: response.sources };
|
|
216
108
|
}
|
|
@@ -218,50 +110,4 @@ exports.askAI = (0, pieces_framework_1.createAction)({
|
|
|
218
110
|
});
|
|
219
111
|
},
|
|
220
112
|
});
|
|
221
|
-
function createWebSearchTool(provider, options = {}) {
|
|
222
|
-
var _a;
|
|
223
|
-
const defaultMaxUses = 5;
|
|
224
|
-
switch (provider) {
|
|
225
|
-
case shared_1.AIProviderName.ANTHROPIC: {
|
|
226
|
-
const anthropicOptions = options;
|
|
227
|
-
let allowedDomains;
|
|
228
|
-
let blockedDomains;
|
|
229
|
-
if (anthropicOptions.allowedDomains &&
|
|
230
|
-
anthropicOptions.allowedDomains.length > 0) {
|
|
231
|
-
allowedDomains = anthropicOptions.allowedDomains.map(({ domain }) => domain);
|
|
232
|
-
}
|
|
233
|
-
if (anthropicOptions.blockedDomains &&
|
|
234
|
-
anthropicOptions.blockedDomains.length > 0 &&
|
|
235
|
-
(!anthropicOptions.allowedDomains ||
|
|
236
|
-
anthropicOptions.allowedDomains.length === 0)) {
|
|
237
|
-
blockedDomains = anthropicOptions.blockedDomains.map(({ domain }) => domain);
|
|
238
|
-
}
|
|
239
|
-
return {
|
|
240
|
-
web_search: (0, ai_sdk_1.anthropicSearchTool)(Object.assign(Object.assign(Object.assign({ maxUses: (_a = anthropicOptions.maxUses) !== null && _a !== void 0 ? _a : defaultMaxUses }, (0, shared_1.spreadIfDefined)('userLocation', buildUserLocation(anthropicOptions))), (0, shared_1.spreadIfDefined)('allowedDomains', allowedDomains)), (0, shared_1.spreadIfDefined)('blockedDomains', blockedDomains))),
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
case shared_1.AIProviderName.OPENAI: {
|
|
244
|
-
const openaiOptions = options;
|
|
245
|
-
return {
|
|
246
|
-
web_search_preview: (0, ai_sdk_1.openaiSearchTool)(Object.assign(Object.assign({}, (0, shared_1.spreadIfDefined)('searchContextSize', openaiOptions.searchContextSize)), (0, shared_1.spreadIfDefined)('userLocation', buildUserLocation(openaiOptions)))),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
case shared_1.AIProviderName.GOOGLE: {
|
|
250
|
-
return {
|
|
251
|
-
google_search: (0, ai_sdk_1.googleSearchTool)({}),
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
default:
|
|
255
|
-
throw new Error(`Provider ${provider} is not supported for web search`);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function buildUserLocation(options) {
|
|
259
|
-
if (!options.userLocationCity &&
|
|
260
|
-
!options.userLocationRegion &&
|
|
261
|
-
!options.userLocationCountry &&
|
|
262
|
-
!options.userLocationTimezone) {
|
|
263
|
-
return undefined;
|
|
264
|
-
}
|
|
265
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({ type: 'approximate' }, (0, shared_1.spreadIfDefined)('city', options.userLocationCity)), (0, shared_1.spreadIfDefined)('region', options.userLocationRegion)), (0, shared_1.spreadIfDefined)('country', options.userLocationCountry)), (0, shared_1.spreadIfDefined)('timezone', options.userLocationTimezone));
|
|
266
|
-
}
|
|
267
113
|
//# sourceMappingURL=ask-ai.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-ai.js","sourceRoot":"","sources":["../../../../../src/lib/actions/text/ask-ai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ask-ai.js","sourceRoot":"","sources":["../../../../../src/lib/actions/text/ask-ai.ts"],"names":[],"mappings":";;;;AAAA,qEAGwC;AACxC,2BAA6D;AAE7D,8CAA6C;AAC7C,gDAAoD;AACpD,wDAAgH;AAEnG,QAAA,KAAK,GAAG,IAAA,+BAAY,EAAC;IAChC,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,QAAQ;IACrB,WAAW,EAAE,mGAAmG;IAChH,KAAK,EAAE;QACL,QAAQ,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ;QACjD,KAAK,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK;QAC3C,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACxB,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,eAAe,EAAE,2BAAQ,CAAC,S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EAAE,OAAO,CAAC,UAAU,CAAC,eAAe;gBACnD,WAAW,EAAE,CAAC,MAAA,OAAO,CAAC,UAAU,CAAC,UAAU,mCAAI,GAAG,CAAC,GAAG,GAAG;gBACzD,KAAK,EAAE,cAAc;gBACrB,QAAQ;gBACR,eAAe;aAChB,CAAC,CAAC;YAEH,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,CAAC;gBACjB,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM;aACnC,CAAC,CAAC;YAEH,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,CAAC;gBACjB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE;aAC7B,CAAC,CAAC;YAEH,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;YACnD,CAAC;YAED,MAAM,cAAc,GAAG,cAAc,IAAI,gBAAgB,CAAC,cAAc,CAAC;YACzE,IAAI,cAAc,EAAE,CAAC;gBACnB,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;YAC5D,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ToolSet } from 'ai';
|
|
2
|
+
import { ProviderOptions } from '@ai-sdk/provider-utils';
|
|
3
|
+
export declare function buildWebSearchOptionsProperty(getProvider: (propsValue: Record<string, unknown>) => string | undefined, refreshers: string[], params?: {
|
|
4
|
+
showIncludeSources?: boolean;
|
|
5
|
+
}): import("@activepieces/pieces-framework").DynamicProperties<false, undefined>;
|
|
6
|
+
export declare function buildWebSearchConfig(params: {
|
|
7
|
+
provider: string;
|
|
8
|
+
webSearchEnabled: boolean;
|
|
9
|
+
webSearchOptions: WebSearchOptions;
|
|
10
|
+
}): {
|
|
11
|
+
tools: ToolSet | undefined;
|
|
12
|
+
providerOptions: ProviderOptions | undefined;
|
|
13
|
+
};
|
|
14
|
+
type BaseWebSearchOptions = {
|
|
15
|
+
maxUses?: number;
|
|
16
|
+
includeSources?: boolean;
|
|
17
|
+
};
|
|
18
|
+
type UserLocationOptions = {
|
|
19
|
+
userLocationCity?: string;
|
|
20
|
+
userLocationRegion?: string;
|
|
21
|
+
userLocationCountry?: string;
|
|
22
|
+
userLocationTimezone?: string;
|
|
23
|
+
};
|
|
24
|
+
type AnthropicWebSearchOptions = BaseWebSearchOptions & UserLocationOptions & {
|
|
25
|
+
allowedDomains?: {
|
|
26
|
+
domain: string;
|
|
27
|
+
}[];
|
|
28
|
+
blockedDomains?: {
|
|
29
|
+
domain: string;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
type OpenAIWebSearchOptions = BaseWebSearchOptions & UserLocationOptions & {
|
|
33
|
+
searchContextSize?: 'low' | 'medium' | 'high';
|
|
34
|
+
};
|
|
35
|
+
export type WebSearchOptions = AnthropicWebSearchOptions | OpenAIWebSearchOptions;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=web-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../../../src/lib/common/web-search.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAoNzD,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,EACxE,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,CAAC,EAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAE,gFAmB1C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,OAAO,CAAA;IACzB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,GAAG;IAAE,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAAC,eAAe,EAAE,eAAe,GAAG,SAAS,CAAA;CAAE,CAgC/E;AAED,KAAK,oBAAoB,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB,CAAA;AAED,KAAK,mBAAmB,GAAG;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,KAAK,yBAAyB,GAAG,oBAAoB,GAAG,mBAAmB,GAAG;IAC5E,cAAc,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACrC,cAAc,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CACtC,CAAA;AAED,KAAK,sBAAsB,GAAG,oBAAoB,GAAG,mBAAmB,GAAG;IACzE,iBAAiB,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;CAC9C,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,GAAG,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildWebSearchOptionsProperty = buildWebSearchOptionsProperty;
|
|
4
|
+
exports.buildWebSearchConfig = buildWebSearchConfig;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
7
|
+
const shared_1 = require("@activepieces/shared");
|
|
8
|
+
const ai_sdk_1 = require("./ai-sdk");
|
|
9
|
+
function buildWebSearchOptionsProps(provider, params) {
|
|
10
|
+
var _a;
|
|
11
|
+
const showIncludeSources = (_a = params === null || params === void 0 ? void 0 : params.showIncludeSources) !== null && _a !== void 0 ? _a : true;
|
|
12
|
+
const isOpenRouterProvider = provider === shared_1.AIProviderName.OPENROUTER ||
|
|
13
|
+
provider === shared_1.AIProviderName.ACTIVEPIECES;
|
|
14
|
+
const supportsToolBasedWebSearch = provider === shared_1.AIProviderName.OPENAI ||
|
|
15
|
+
provider === shared_1.AIProviderName.ANTHROPIC ||
|
|
16
|
+
provider === shared_1.AIProviderName.GOOGLE;
|
|
17
|
+
let options = {
|
|
18
|
+
maxUses: pieces_framework_1.Property.Number({
|
|
19
|
+
displayName: 'Max Web Search Uses',
|
|
20
|
+
required: false,
|
|
21
|
+
defaultValue: 5,
|
|
22
|
+
description: isOpenRouterProvider
|
|
23
|
+
? 'For OpenRouter/Activepieces, this maps to OpenRouter web plugin max_results (1-10). Default is 5.'
|
|
24
|
+
: 'Maximum number of searches to use. Default is 5.',
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
if (supportsToolBasedWebSearch && showIncludeSources) {
|
|
28
|
+
options = Object.assign(Object.assign({}, options), { includeSources: pieces_framework_1.Property.Checkbox({
|
|
29
|
+
displayName: 'Include Sources',
|
|
30
|
+
description: 'Whether to include the sources in the response. Useful for getting web search details (e.g. search queries, searched URLs, etc).',
|
|
31
|
+
required: false,
|
|
32
|
+
defaultValue: false,
|
|
33
|
+
}) });
|
|
34
|
+
}
|
|
35
|
+
const userLocationOptions = {
|
|
36
|
+
userLocationCity: pieces_framework_1.Property.ShortText({
|
|
37
|
+
displayName: 'User Location - City',
|
|
38
|
+
required: false,
|
|
39
|
+
description: 'The city name for localizing search results (e.g., San Francisco).',
|
|
40
|
+
}),
|
|
41
|
+
userLocationRegion: pieces_framework_1.Property.ShortText({
|
|
42
|
+
displayName: 'User Location - Region',
|
|
43
|
+
required: false,
|
|
44
|
+
description: 'The region or state for localizing search results (e.g., California).',
|
|
45
|
+
}),
|
|
46
|
+
userLocationCountry: pieces_framework_1.Property.ShortText({
|
|
47
|
+
displayName: 'User Location - Country',
|
|
48
|
+
required: false,
|
|
49
|
+
description: 'The country code for localizing search results (e.g., US).',
|
|
50
|
+
}),
|
|
51
|
+
userLocationTimezone: pieces_framework_1.Property.ShortText({
|
|
52
|
+
displayName: 'User Location - Timezone',
|
|
53
|
+
required: false,
|
|
54
|
+
description: 'The IANA timezone ID for localizing search results (e.g., America/Los_Angeles).',
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
if (provider === shared_1.AIProviderName.ANTHROPIC) {
|
|
58
|
+
options = Object.assign(Object.assign(Object.assign({}, options), { allowedDomains: pieces_framework_1.Property.Array({
|
|
59
|
+
displayName: 'Allowed Domains',
|
|
60
|
+
required: false,
|
|
61
|
+
description: 'List of domains to search (e.g., example.com, docs.example.com/blog). Domains should not include HTTP/HTTPS scheme. Subdomains are automatically included unless more specific subpaths are provided. Overrides Blocked Domains if both are provided.',
|
|
62
|
+
properties: {
|
|
63
|
+
domain: pieces_framework_1.Property.ShortText({
|
|
64
|
+
displayName: 'Domain',
|
|
65
|
+
required: true,
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
}), blockedDomains: pieces_framework_1.Property.Array({
|
|
69
|
+
displayName: 'Blocked Domains',
|
|
70
|
+
required: false,
|
|
71
|
+
description: 'List of domains to exclude from search (e.g., example.com, docs.example.com/blog). Domains should not include HTTP/HTTPS scheme. Subdomains are automatically included unless more specific subpaths are provided. Overrided by Allowed Domains if both are provided.',
|
|
72
|
+
properties: {
|
|
73
|
+
domain: pieces_framework_1.Property.ShortText({
|
|
74
|
+
displayName: 'Domain',
|
|
75
|
+
required: true,
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
}) }), userLocationOptions);
|
|
79
|
+
}
|
|
80
|
+
if (provider === shared_1.AIProviderName.OPENAI) {
|
|
81
|
+
options = Object.assign(Object.assign(Object.assign({}, options), { searchContextSize: pieces_framework_1.Property.StaticDropdown({
|
|
82
|
+
displayName: 'Search Context Size',
|
|
83
|
+
required: false,
|
|
84
|
+
defaultValue: 'medium',
|
|
85
|
+
options: {
|
|
86
|
+
options: [
|
|
87
|
+
{ label: 'Low', value: 'low' },
|
|
88
|
+
{ label: 'Medium', value: 'medium' },
|
|
89
|
+
{ label: 'High', value: 'high' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
description: 'High level guidance for the amount of context window space to use for the search.',
|
|
93
|
+
}) }), userLocationOptions);
|
|
94
|
+
}
|
|
95
|
+
return options;
|
|
96
|
+
}
|
|
97
|
+
function buildUserLocation(options) {
|
|
98
|
+
if (!options.userLocationCity &&
|
|
99
|
+
!options.userLocationRegion &&
|
|
100
|
+
!options.userLocationCountry &&
|
|
101
|
+
!options.userLocationTimezone) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ type: 'approximate' }, (0, shared_1.spreadIfDefined)('city', options.userLocationCity)), (0, shared_1.spreadIfDefined)('region', options.userLocationRegion)), (0, shared_1.spreadIfDefined)('country', options.userLocationCountry)), (0, shared_1.spreadIfDefined)('timezone', options.userLocationTimezone));
|
|
105
|
+
}
|
|
106
|
+
function createWebSearchTool(provider, options = {}) {
|
|
107
|
+
var _a;
|
|
108
|
+
const defaultMaxUses = 5;
|
|
109
|
+
switch (provider) {
|
|
110
|
+
case shared_1.AIProviderName.ANTHROPIC: {
|
|
111
|
+
const anthropicOptions = options;
|
|
112
|
+
let allowedDomains;
|
|
113
|
+
let blockedDomains;
|
|
114
|
+
if (anthropicOptions.allowedDomains &&
|
|
115
|
+
anthropicOptions.allowedDomains.length > 0) {
|
|
116
|
+
allowedDomains = anthropicOptions.allowedDomains.map(({ domain }) => domain);
|
|
117
|
+
}
|
|
118
|
+
if (anthropicOptions.blockedDomains &&
|
|
119
|
+
anthropicOptions.blockedDomains.length > 0 &&
|
|
120
|
+
(!anthropicOptions.allowedDomains ||
|
|
121
|
+
anthropicOptions.allowedDomains.length === 0)) {
|
|
122
|
+
blockedDomains = anthropicOptions.blockedDomains.map(({ domain }) => domain);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
web_search: (0, ai_sdk_1.anthropicSearchTool)(Object.assign(Object.assign(Object.assign({ maxUses: (_a = anthropicOptions.maxUses) !== null && _a !== void 0 ? _a : defaultMaxUses }, (0, shared_1.spreadIfDefined)('userLocation', buildUserLocation(anthropicOptions))), (0, shared_1.spreadIfDefined)('allowedDomains', allowedDomains)), (0, shared_1.spreadIfDefined)('blockedDomains', blockedDomains))),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
case shared_1.AIProviderName.OPENAI: {
|
|
129
|
+
const openaiOptions = options;
|
|
130
|
+
return {
|
|
131
|
+
web_search_preview: (0, ai_sdk_1.openaiSearchTool)(Object.assign(Object.assign({}, (0, shared_1.spreadIfDefined)('searchContextSize', openaiOptions.searchContextSize)), (0, shared_1.spreadIfDefined)('userLocation', buildUserLocation(openaiOptions)))),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
case shared_1.AIProviderName.GOOGLE: {
|
|
135
|
+
return {
|
|
136
|
+
google_search: (0, ai_sdk_1.googleSearchTool)({}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
default:
|
|
140
|
+
throw new Error(`Provider ${provider} is not supported for web search`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function buildWebSearchOptionsProperty(getProvider, refreshers, params) {
|
|
144
|
+
return pieces_framework_1.Property.DynamicProperties({
|
|
145
|
+
displayName: 'Web Search Options',
|
|
146
|
+
required: false,
|
|
147
|
+
auth: pieces_framework_1.PieceAuth.None(),
|
|
148
|
+
refreshers,
|
|
149
|
+
props: (propsValue) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const webSearchEnabled = propsValue['webSearch'];
|
|
151
|
+
if (!webSearchEnabled) {
|
|
152
|
+
return {};
|
|
153
|
+
}
|
|
154
|
+
const provider = getProvider(propsValue);
|
|
155
|
+
if (!provider) {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
return buildWebSearchOptionsProps(provider, params);
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function buildWebSearchConfig(params) {
|
|
163
|
+
var _a;
|
|
164
|
+
const { provider, webSearchEnabled, webSearchOptions } = params;
|
|
165
|
+
if (!webSearchEnabled) {
|
|
166
|
+
return { tools: undefined, providerOptions: undefined };
|
|
167
|
+
}
|
|
168
|
+
const isOpenRouter = provider === shared_1.AIProviderName.OPENROUTER ||
|
|
169
|
+
provider === shared_1.AIProviderName.ACTIVEPIECES;
|
|
170
|
+
if (isOpenRouter) {
|
|
171
|
+
return {
|
|
172
|
+
tools: undefined,
|
|
173
|
+
providerOptions: {
|
|
174
|
+
openrouter: {
|
|
175
|
+
plugins: [{
|
|
176
|
+
id: 'web',
|
|
177
|
+
max_results: Math.min(Math.max((_a = webSearchOptions === null || webSearchOptions === void 0 ? void 0 : webSearchOptions.maxUses) !== null && _a !== void 0 ? _a : 5, 1), 10),
|
|
178
|
+
}],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
tools: createWebSearchTool(provider, webSearchOptions),
|
|
185
|
+
providerOptions: undefined,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../../src/lib/common/web-search.ts"],"names":[],"mappings":";;AA0NA,sEAsBC;AAED,oDAoCC;;AAtRD,qEAIwC;AAGxC,iDAAuE;AACvE,qCAAmF;AAEnF,SAAS,0BAA0B,C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