@activepieces/piece-ai 0.0.1

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.
Files changed (35) hide show
  1. package/README.md +7 -0
  2. package/package.json +33 -0
  3. package/src/index.d.ts +4 -0
  4. package/src/index.js +29 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/actions/agents/agent-output-builder.d.ts +24 -0
  7. package/src/lib/actions/agents/agent-output-builder.js +81 -0
  8. package/src/lib/actions/agents/agent-output-builder.js.map +1 -0
  9. package/src/lib/actions/agents/run-agent.d.ts +8 -0
  10. package/src/lib/actions/agents/run-agent.js +219 -0
  11. package/src/lib/actions/agents/run-agent.js.map +1 -0
  12. package/src/lib/actions/image/generate-image.d.ts +6 -0
  13. package/src/lib/actions/image/generate-image.js +216 -0
  14. package/src/lib/actions/image/generate-image.js.map +1 -0
  15. package/src/lib/actions/text/ask-ai.d.ts +35 -0
  16. package/src/lib/actions/text/ask-ai.js +238 -0
  17. package/src/lib/actions/text/ask-ai.js.map +1 -0
  18. package/src/lib/actions/text/summarize-text.d.ts +7 -0
  19. package/src/lib/actions/text/summarize-text.js +61 -0
  20. package/src/lib/actions/text/summarize-text.js.map +1 -0
  21. package/src/lib/actions/utility/classify-text.d.ts +6 -0
  22. package/src/lib/actions/utility/classify-text.js +51 -0
  23. package/src/lib/actions/utility/classify-text.js.map +1 -0
  24. package/src/lib/actions/utility/extract-structured-data.d.ts +10 -0
  25. package/src/lib/actions/utility/extract-structured-data.js +247 -0
  26. package/src/lib/actions/utility/extract-structured-data.js.map +1 -0
  27. package/src/lib/common/ai-sdk.d.ts +55 -0
  28. package/src/lib/common/ai-sdk.js +62 -0
  29. package/src/lib/common/ai-sdk.js.map +1 -0
  30. package/src/lib/common/props.d.ts +10 -0
  31. package/src/lib/common/props.js +75 -0
  32. package/src/lib/common/props.js.map +1 -0
  33. package/src/lib/common/types.d.ts +140 -0
  34. package/src/lib/common/types.js +95 -0
  35. package/src/lib/common/types.js.map +1 -0
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateImageAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const ai_1 = require("ai");
7
+ const ai_2 = require("ai");
8
+ const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
9
+ const shared_1 = require("@activepieces/shared");
10
+ const ai_sdk_1 = require("../../common/ai-sdk");
11
+ const types_1 = require("../../common/types");
12
+ const props_1 = require("../../common/props");
13
+ exports.generateImageAction = (0, pieces_framework_1.createAction)({
14
+ name: 'generateImage',
15
+ displayName: 'Generate Image',
16
+ description: '',
17
+ props: {
18
+ provider: (0, props_1.aiProps)({ modelType: 'image' }).provider,
19
+ model: (0, props_1.aiProps)({ modelType: 'image' }).model,
20
+ prompt: pieces_framework_1.Property.LongText({
21
+ displayName: 'Prompt',
22
+ required: true,
23
+ }),
24
+ advancedOptions: pieces_framework_1.Property.DynamicProperties({
25
+ displayName: 'Advanced Options',
26
+ required: false,
27
+ auth: pieces_framework_1.PieceAuth.None(),
28
+ refreshers: ['provider', 'model'],
29
+ props: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
30
+ const providerId = propsValue['provider'];
31
+ const modelId = propsValue['model'];
32
+ let options = {};
33
+ if (providerId === types_1.AIProviderName.OPENAI) {
34
+ options = {
35
+ quality: pieces_framework_1.Property.StaticDropdown({
36
+ options: {
37
+ options: modelId === 'dall-e-3'
38
+ ? [
39
+ { label: 'Standard', value: 'standard' },
40
+ { label: 'HD', value: 'hd' },
41
+ ]
42
+ : modelId === 'gpt-image-1'
43
+ ? [
44
+ { label: 'High', value: 'high' },
45
+ { label: 'Medium', value: 'medium' },
46
+ { label: 'Low', value: 'low' },
47
+ ]
48
+ : [],
49
+ disabled: modelId === 'dall-e-2',
50
+ },
51
+ defaultValue: modelId === 'dall-e-3' ? 'standard' : 'high',
52
+ displayName: 'Image Quality',
53
+ required: false,
54
+ }),
55
+ size: pieces_framework_1.Property.StaticDropdown({
56
+ options: {
57
+ options: modelId === 'dall-e-3'
58
+ ? [
59
+ { label: '1024x1024', value: '1024x1024' },
60
+ { label: '1792x1024', value: '1792x1024' },
61
+ { label: '1024x1792', value: '1024x1792' },
62
+ ]
63
+ : modelId === 'gpt-image-1'
64
+ ? [
65
+ { label: '1024x1024', value: '1024x1024' },
66
+ { label: '1536x1024', value: '1536x1024' },
67
+ { label: '1024x1536', value: '1024x1536' },
68
+ ]
69
+ : [
70
+ { label: '256x256', value: '256x256' },
71
+ { label: '512x512', value: '512x512' },
72
+ { label: '1024x1024', value: '1024x1024' },
73
+ ],
74
+ },
75
+ displayName: 'Image Size',
76
+ required: false,
77
+ }),
78
+ };
79
+ if (modelId === 'gpt-image-1') {
80
+ options = Object.assign(Object.assign({}, options), { background: pieces_framework_1.Property.StaticDropdown({
81
+ options: {
82
+ options: [
83
+ { label: 'Auto', value: 'auto' },
84
+ { label: 'Transparent', value: 'transparent' },
85
+ { label: 'Opaque', value: 'opaque' },
86
+ ],
87
+ },
88
+ defaultValue: 'auto',
89
+ description: 'The background of the image.',
90
+ displayName: 'Background',
91
+ required: true,
92
+ }) });
93
+ }
94
+ return options;
95
+ }
96
+ if (providerId === types_1.AIProviderName.GOOGLE &&
97
+ modelId === 'gemini-2.5-flash-image-preview') {
98
+ options = {
99
+ image: pieces_framework_1.Property.Array({
100
+ displayName: 'Images',
101
+ required: false,
102
+ properties: {
103
+ file: pieces_framework_1.Property.File({
104
+ displayName: 'Image File',
105
+ required: true,
106
+ }),
107
+ },
108
+ description: 'The image(s) you want to edit/merge',
109
+ }),
110
+ };
111
+ }
112
+ return options;
113
+ }),
114
+ }),
115
+ },
116
+ run(context) {
117
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
118
+ const providerId = context.propsValue.provider;
119
+ const modelId = context.propsValue.model;
120
+ const image = yield getGeneratedImage({
121
+ providerId,
122
+ modelId,
123
+ engineToken: context.server.token,
124
+ apiUrl: context.server.apiUrl,
125
+ prompt: context.propsValue.prompt,
126
+ advancedOptions: context.propsValue.advancedOptions,
127
+ });
128
+ const imageData = image.base64 && image.base64.length > 0
129
+ ? Buffer.from(image.base64, 'base64')
130
+ : Buffer.from(image.uint8Array);
131
+ return context.files.write({
132
+ data: imageData,
133
+ fileName: 'image.png',
134
+ });
135
+ });
136
+ },
137
+ });
138
+ const getGeneratedImage = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ providerId, modelId, engineToken, apiUrl, prompt, advancedOptions, }) {
139
+ const model = yield (0, ai_sdk_1.createAIModel)({
140
+ providerId,
141
+ modelId,
142
+ engineToken,
143
+ apiUrl,
144
+ isImage: true,
145
+ });
146
+ switch (providerId) {
147
+ case types_1.AIProviderName.GOOGLE:
148
+ case types_1.AIProviderName.ACTIVEPIECES:
149
+ case types_1.AIProviderName.OPENROUTER:
150
+ return generateImageUsingGenerateText({
151
+ model: model,
152
+ prompt,
153
+ advancedOptions,
154
+ });
155
+ default:
156
+ {
157
+ const { image } = yield (0, ai_2.experimental_generateImage)({
158
+ model,
159
+ prompt,
160
+ providerOptions: {
161
+ [providerId]: Object.assign({}, advancedOptions),
162
+ },
163
+ });
164
+ return image;
165
+ }
166
+ ;
167
+ }
168
+ });
169
+ const generateImageUsingGenerateText = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ model, prompt, advancedOptions, }) {
170
+ var _b;
171
+ const images = (_b = advancedOptions === null || advancedOptions === void 0 ? void 0 : advancedOptions['image']) !== null && _b !== void 0 ? _b : [];
172
+ const imageFiles = images.map((image) => {
173
+ const fileType = image.file.extension
174
+ ? mime_types_1.default.lookup(image.file.extension)
175
+ : 'image/jpeg';
176
+ return {
177
+ type: 'image',
178
+ image: `data:${fileType};base64,${image.file.base64}`,
179
+ };
180
+ });
181
+ const result = yield (0, ai_1.generateText)({
182
+ model,
183
+ providerOptions: {
184
+ google: { responseModalities: ['TEXT', 'IMAGE'] },
185
+ openrouter: { modalities: ['image', 'text'] },
186
+ },
187
+ messages: [
188
+ {
189
+ role: 'user',
190
+ content: [{ type: 'text', text: prompt }, ...imageFiles],
191
+ },
192
+ ],
193
+ });
194
+ assertImageGenerationSuccess(result);
195
+ return result.files[0];
196
+ });
197
+ const assertImageGenerationSuccess = (result) => {
198
+ const responseBody = result.response.body &&
199
+ typeof result.response.body === 'object' &&
200
+ 'candidates' in result.response.body
201
+ ? result.response.body
202
+ : { candidates: [] };
203
+ const responseCandidates = Array.isArray(responseBody === null || responseBody === void 0 ? void 0 : responseBody.candidates)
204
+ ? responseBody === null || responseBody === void 0 ? void 0 : responseBody.candidates
205
+ : [];
206
+ responseCandidates.forEach((candidate) => {
207
+ if (candidate.finishReason !== 'STOP') {
208
+ throw new Error('Image generation failed Reason:\n ' +
209
+ JSON.stringify(responseCandidates, null, 2));
210
+ }
211
+ });
212
+ if ((0, shared_1.isNil)(result.files) || result.files.length === 0) {
213
+ throw new Error('No image generated');
214
+ }
215
+ };
216
+ //# sourceMappingURL=generate-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-image.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/ai/src/lib/actions/image/generate-image.ts"],"names":[],"mappings":";;;;AAAA,qEAOwC;AACxC,2BAMY;AACZ,2BAAiE;AAEjE,oEAA8B;AAC9B,iDAA6C;AAC7C,gDAAoD;AACpD,8CAAoD;AACpD,8CAA6C;AAEhC,QAAA,mBAAmB,GAAG,IAAA,+BAAY,EAAC;IAC9C,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,EAAE;IACf,KAAK,EAAE;QACL,QAAQ,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ;QAClD,KAAK,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK;QAC5C,MAAM,EAAE,2BAAQ,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Z,YAAY,uBAAZ,YAAY,CAAE,UAAU,CAAC;QAChE,CAAC,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,UAAU;QAC1B,CAAC,CAAC,EAAE,CAAC;IAEP,kBAAkB,CAAC,OAAO,CAAC,CAAC,SAAmC,EAAE,EAAE;QACjE,IAAI,SAAS,CAAC,YAAY,KAAK,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,oCAAoC;gBACpC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,CAC5C,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,IAAA,cAAK,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { ToolSet } from 'ai';
2
+ export declare const askAI: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
3
+ provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
4
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
5
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
6
+ conversationKey: import("@activepieces/pieces-framework").ShortTextProperty<false>;
7
+ creativity: import("@activepieces/pieces-framework").NumberProperty<false>;
8
+ maxOutputTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
9
+ webSearch: import("@activepieces/pieces-framework").CheckboxProperty<false>;
10
+ webSearchOptions: import("@activepieces/pieces-framework").DynamicProperties<false, undefined>;
11
+ }>;
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 {};
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.askAI = void 0;
4
+ exports.createWebSearchTool = createWebSearchTool;
5
+ const tslib_1 = require("tslib");
6
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
7
+ const ai_1 = require("ai");
8
+ const shared_1 = require("@activepieces/shared");
9
+ const props_1 = require("../../common/props");
10
+ const types_1 = require("../../common/types");
11
+ const ai_sdk_1 = require("../../common/ai-sdk");
12
+ exports.askAI = (0, pieces_framework_1.createAction)({
13
+ name: 'askAi',
14
+ displayName: 'Ask AI',
15
+ description: '',
16
+ props: {
17
+ provider: (0, props_1.aiProps)({ modelType: 'text' }).provider,
18
+ model: (0, props_1.aiProps)({ modelType: 'text' }).model,
19
+ prompt: pieces_framework_1.Property.LongText({
20
+ displayName: 'Prompt',
21
+ required: true,
22
+ }),
23
+ conversationKey: pieces_framework_1.Property.ShortText({
24
+ displayName: 'Conversation Key',
25
+ required: false,
26
+ }),
27
+ creativity: pieces_framework_1.Property.Number({
28
+ displayName: 'Creativity',
29
+ required: false,
30
+ defaultValue: 100,
31
+ description: 'Controls the creativity of the AI response. A higher value will make the AI more creative and a lower value will make it more deterministic.',
32
+ }),
33
+ maxOutputTokens: pieces_framework_1.Property.Number({
34
+ displayName: 'Max Tokens',
35
+ required: false,
36
+ defaultValue: 2000,
37
+ }),
38
+ webSearch: pieces_framework_1.Property.Checkbox({
39
+ displayName: 'Web Search',
40
+ required: false,
41
+ defaultValue: false,
42
+ description: 'Whether to use web search to find information for the AI to use in its response.',
43
+ }),
44
+ webSearchOptions: pieces_framework_1.Property.DynamicProperties({
45
+ displayName: 'Web Search Options',
46
+ required: false,
47
+ auth: pieces_framework_1.PieceAuth.None(),
48
+ refreshers: ['webSearch', 'provider', 'model'],
49
+ props: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
50
+ const webSearchEnabled = propsValue['webSearch'];
51
+ const provider = propsValue['provider'];
52
+ if (!webSearchEnabled) {
53
+ return {};
54
+ }
55
+ let options = {
56
+ maxUses: pieces_framework_1.Property.Number({
57
+ displayName: 'Max Web Search Uses',
58
+ required: false,
59
+ defaultValue: 5,
60
+ description: 'Maximum number of searches to use. Default is 5.',
61
+ }),
62
+ includeSources: pieces_framework_1.Property.Checkbox({
63
+ displayName: 'Include Sources',
64
+ description: 'Whether to include the sources in the response. Useful for getting web search details (e.g. search queries, searched URLs, etc).',
65
+ required: false,
66
+ defaultValue: false,
67
+ }),
68
+ };
69
+ const userLocationOptions = {
70
+ userLocationCity: pieces_framework_1.Property.ShortText({
71
+ displayName: 'User Location - City',
72
+ required: false,
73
+ description: 'The city name for localizing search results (e.g., San Francisco).',
74
+ }),
75
+ userLocationRegion: pieces_framework_1.Property.ShortText({
76
+ displayName: 'User Location - Region',
77
+ required: false,
78
+ description: 'The region or state for localizing search results (e.g., California).',
79
+ }),
80
+ userLocationCountry: pieces_framework_1.Property.ShortText({
81
+ displayName: 'User Location - Country',
82
+ required: false,
83
+ description: 'The country code for localizing search results (e.g., US).',
84
+ }),
85
+ userLocationTimezone: pieces_framework_1.Property.ShortText({
86
+ displayName: 'User Location - Timezone',
87
+ required: false,
88
+ description: 'The IANA timezone ID for localizing search results (e.g., America/Los_Angeles).',
89
+ }),
90
+ };
91
+ if (provider === types_1.AIProviderName.ANTHROPIC) {
92
+ options = Object.assign(Object.assign(Object.assign({}, options), { allowedDomains: pieces_framework_1.Property.Array({
93
+ displayName: 'Allowed Domains',
94
+ required: false,
95
+ 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.',
96
+ properties: {
97
+ domain: pieces_framework_1.Property.ShortText({
98
+ displayName: 'Domain',
99
+ required: true,
100
+ }),
101
+ },
102
+ }), blockedDomains: pieces_framework_1.Property.Array({
103
+ displayName: 'Blocked Domains',
104
+ required: false,
105
+ 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.',
106
+ properties: {
107
+ domain: pieces_framework_1.Property.ShortText({
108
+ displayName: 'Domain',
109
+ required: true,
110
+ }),
111
+ },
112
+ }) }), userLocationOptions);
113
+ }
114
+ if (provider === types_1.AIProviderName.OPENAI) {
115
+ options = Object.assign(Object.assign(Object.assign({}, options), { searchContextSize: pieces_framework_1.Property.StaticDropdown({
116
+ displayName: 'Search Context Size',
117
+ required: false,
118
+ defaultValue: 'medium',
119
+ options: {
120
+ options: [
121
+ { label: 'Low', value: 'low' },
122
+ { label: 'Medium', value: 'medium' },
123
+ { label: 'High', value: 'high' },
124
+ ],
125
+ },
126
+ description: 'High level guidance for the amount of context window space to use for the search.',
127
+ }) }), userLocationOptions);
128
+ }
129
+ return options;
130
+ }),
131
+ }),
132
+ },
133
+ run(context) {
134
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
135
+ var _a, _b, _c, _d;
136
+ const providerId = context.propsValue.provider;
137
+ const modelId = context.propsValue.model;
138
+ const storage = context.store;
139
+ const webSearchOptions = context.propsValue.webSearchOptions;
140
+ const model = yield (0, ai_sdk_1.createAIModel)({
141
+ providerId,
142
+ modelId,
143
+ engineToken: context.server.token,
144
+ apiUrl: context.server.apiUrl,
145
+ openaiResponsesModel: true,
146
+ });
147
+ const conversationKey = context.propsValue.conversationKey
148
+ ? `ask-ai-conversation:${context.propsValue.conversationKey}`
149
+ : null;
150
+ let conversation = null;
151
+ if (conversationKey) {
152
+ conversation = (_a = (yield storage.get(conversationKey))) !== null && _a !== void 0 ? _a : [];
153
+ if (!conversation) {
154
+ yield storage.put(conversationKey, { messages: [] });
155
+ }
156
+ }
157
+ const response = yield (0, ai_1.generateText)({
158
+ model,
159
+ messages: [
160
+ ...(conversation !== null && conversation !== void 0 ? conversation : []),
161
+ {
162
+ role: 'user',
163
+ content: context.propsValue.prompt,
164
+ },
165
+ ],
166
+ maxOutputTokens: context.propsValue.maxOutputTokens,
167
+ temperature: ((_b = context.propsValue.creativity) !== null && _b !== void 0 ? _b : 100) / 100,
168
+ tools: context.propsValue.webSearch
169
+ ? createWebSearchTool(providerId, webSearchOptions)
170
+ : undefined,
171
+ stopWhen: (0, ai_1.stepCountIs)((_c = webSearchOptions === null || webSearchOptions === void 0 ? void 0 : webSearchOptions.maxUses) !== null && _c !== void 0 ? _c : 5),
172
+ });
173
+ conversation === null || conversation === void 0 ? void 0 : conversation.push({
174
+ role: 'user',
175
+ content: context.propsValue.prompt,
176
+ });
177
+ conversation === null || conversation === void 0 ? void 0 : conversation.push({
178
+ role: 'assistant',
179
+ content: (_d = response.text) !== null && _d !== void 0 ? _d : '',
180
+ });
181
+ if (conversationKey) {
182
+ yield storage.put(conversationKey, conversation);
183
+ }
184
+ const includeSources = webSearchOptions.includeSources;
185
+ if (includeSources) {
186
+ return { text: response.text, sources: response.sources };
187
+ }
188
+ return response.text;
189
+ });
190
+ },
191
+ });
192
+ function createWebSearchTool(provider, options = {}) {
193
+ var _a;
194
+ const defaultMaxUses = 5;
195
+ switch (provider) {
196
+ case types_1.AIProviderName.ANTHROPIC: {
197
+ const anthropicOptions = options;
198
+ let allowedDomains;
199
+ let blockedDomains;
200
+ if (anthropicOptions.allowedDomains &&
201
+ anthropicOptions.allowedDomains.length > 0) {
202
+ allowedDomains = anthropicOptions.allowedDomains.map(({ domain }) => domain);
203
+ }
204
+ if (anthropicOptions.blockedDomains &&
205
+ anthropicOptions.blockedDomains.length > 0 &&
206
+ (!anthropicOptions.allowedDomains ||
207
+ anthropicOptions.allowedDomains.length === 0)) {
208
+ blockedDomains = anthropicOptions.blockedDomains.map(({ domain }) => domain);
209
+ }
210
+ return {
211
+ 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))),
212
+ };
213
+ }
214
+ case types_1.AIProviderName.OPENAI: {
215
+ const openaiOptions = options;
216
+ return {
217
+ 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)))),
218
+ };
219
+ }
220
+ case types_1.AIProviderName.GOOGLE: {
221
+ return {
222
+ google_search: (0, ai_sdk_1.googleSearchTool)({}),
223
+ };
224
+ }
225
+ default:
226
+ throw new Error(`Provider ${provider} is not supported for web search`);
227
+ }
228
+ }
229
+ function buildUserLocation(options) {
230
+ if (!options.userLocationCity &&
231
+ !options.userLocationRegion &&
232
+ !options.userLocationCountry &&
233
+ !options.userLocationTimezone) {
234
+ return undefined;
235
+ }
236
+ 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));
237
+ }
238
+ //# sourceMappingURL=ask-ai.js.map
@@ -0,0 +1 @@
1
+ {"version":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,EAChB,mBAAmB,EACnB,aAAa,CAAC,iBAAiB,CAChC,GACE,IAAA,wBAAe,EAAC,cAAc,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,EACpE;aACI,CAAC;QACX,CAAC;QAED,KAAK,sBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,OAAO;gBACL,aAAa,EAAE,IAAA,yBAAgB,EAAC,EAAE,CAAC;aAC7B,CAAC;QACX,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,kCAAkC,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CACxB,OAA4B;IAE5B,IACE,CAAC,OAAO,CAAC,gBAAgB;QACzB,CAAC,OAAO,CAAC,kBAAkB;QAC3B,CAAC,OAAO,CAAC,mBAAmB;QAC5B,CAAC,OAAO,CAAC,oBAAoB,EAC7B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,iEACE,IAAI,EAAE,aAAsB,IACzB,IAAA,wBAAe,EAAC,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACjD,IAAA,wBAAe,EAAC,QAAQ,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACrD,IAAA,wBAAe,EAAC,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC,GACvD,IAAA,wBAAe,EAAC,UAAU,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAC5D;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const summarizeText: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
3
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
4
+ text: import("@activepieces/pieces-framework").LongTextProperty<true>;
5
+ prompt: import("@activepieces/pieces-framework").ShortTextProperty<true>;
6
+ maxOutputTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
7
+ }>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.summarizeText = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const types_1 = require("../../common/types");
6
+ const ai_sdk_1 = require("../../common/ai-sdk");
7
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
8
+ const ai_1 = require("ai");
9
+ const props_1 = require("../../common/props");
10
+ exports.summarizeText = (0, pieces_framework_1.createAction)({
11
+ name: 'summarizeText',
12
+ displayName: 'Summarize Text',
13
+ description: '',
14
+ props: {
15
+ provider: (0, props_1.aiProps)({ modelType: 'text' }).provider,
16
+ model: (0, props_1.aiProps)({ modelType: 'text' }).model,
17
+ text: pieces_framework_1.Property.LongText({
18
+ displayName: 'Text',
19
+ required: true,
20
+ }),
21
+ prompt: pieces_framework_1.Property.ShortText({
22
+ displayName: 'Prompt',
23
+ defaultValue: 'Summarize the following text in a clear and concise manner, capturing the key points and main ideas while keeping the summary brief and informative.',
24
+ required: true,
25
+ }),
26
+ maxOutputTokens: pieces_framework_1.Property.Number({
27
+ displayName: 'Max Tokens',
28
+ required: false,
29
+ defaultValue: 2000,
30
+ }),
31
+ },
32
+ run(context) {
33
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
34
+ var _a;
35
+ const providerId = context.propsValue.provider;
36
+ const modelId = context.propsValue.model;
37
+ const model = yield (0, ai_sdk_1.createAIModel)({
38
+ providerId,
39
+ modelId,
40
+ engineToken: context.server.token,
41
+ apiUrl: context.server.apiUrl,
42
+ });
43
+ const response = yield (0, ai_1.generateText)({
44
+ model,
45
+ messages: [
46
+ {
47
+ role: 'user',
48
+ content: `${context.propsValue.prompt} Summarize the following text : ${context.propsValue.text}`
49
+ },
50
+ ],
51
+ maxOutputTokens: context.propsValue.maxOutputTokens,
52
+ temperature: 1,
53
+ providerOptions: {
54
+ [providerId]: Object.assign({}, (providerId === types_1.AIProviderName.OPENAI ? { reasoning_effort: 'minimal' } : {}))
55
+ }
56
+ });
57
+ return (_a = response.text) !== null && _a !== void 0 ? _a : '';
58
+ });
59
+ },
60
+ });
61
+ //# sourceMappingURL=summarize-text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarize-text.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/ai/src/lib/actions/text/summarize-text.ts"],"names":[],"mappings":";;;;AAAA,8CAAoD;AACpD,gDAAoD;AACpD,qEAAwE;AACxE,2BAAkC;AAClC,8CAA6C;AAEhC,QAAA,aAAa,GAAG,IAAA,+BAAY,EAAC;IACxC,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,EAAE;IACf,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,IAAI,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACtB,WAAW,EAAE,MAAM;YACnB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,SAAS,CAAC;YACzB,WAAW,EAAE,QAAQ;YACrB,YAAY,EACV,sJAAsJ;YACxJ,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,eAAe,EAAE,2BAAQ,CAAC,MAAM,CAAC;YAC/B,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,IAAI;SACnB,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;;YACf,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;YAEzC,MAAM,KAAK,GAAG,MAAM,IAAA,sBAAa,EAAC;gBAChC,UAAU;gBACV,OAAO;gBACP,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK;gBACjC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM;aAC9B,CAAC,CAAC;YAEH,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAY,EAAC;gBAClC,KAAK;gBACL,QAAQ,EAAE;oBACR;wBACE,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,mCAAmC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;qBAClG;iBACF;gBACD,eAAe,EAAE,OAAO,CAAC,UAAU,CAAC,eAAe;gBACnD,WAAW,EAAE,CAAC;gBACd,eAAe,EAAE;oBACf,CAAC,UAAU,CAAC,oBACP,CAAC,UAAU,KAAK,sBAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACjF;iBACF;aACF,CAAC,CAAC;YAEH,OAAO,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE,CAAC;QAC7B,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const classifyText: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
3
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
4
+ text: import("@activepieces/pieces-framework").LongTextProperty<true>;
5
+ categories: import("@activepieces/pieces-framework").ArrayProperty<true>;
6
+ }>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.classifyText = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const ai_1 = require("ai");
7
+ const ai_sdk_1 = require("../../common/ai-sdk");
8
+ const props_1 = require("../../common/props");
9
+ exports.classifyText = (0, pieces_framework_1.createAction)({
10
+ name: 'classifyText',
11
+ displayName: 'Classify Text',
12
+ description: 'Classify your text into one of your provided categories.',
13
+ props: {
14
+ provider: (0, props_1.aiProps)({ modelType: 'text' }).provider,
15
+ model: (0, props_1.aiProps)({ modelType: 'text' }).model,
16
+ text: pieces_framework_1.Property.LongText({
17
+ displayName: 'Text to Classify',
18
+ required: true,
19
+ }),
20
+ categories: pieces_framework_1.Property.Array({
21
+ displayName: 'Categories',
22
+ description: 'Categories to classify text into.',
23
+ required: true,
24
+ }),
25
+ },
26
+ run(context) {
27
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
+ var _a;
29
+ const categories = (_a = context.propsValue.categories) !== null && _a !== void 0 ? _a : [];
30
+ const providerId = context.propsValue.provider;
31
+ const modelId = context.propsValue.model;
32
+ const model = yield (0, ai_sdk_1.createAIModel)({
33
+ providerId,
34
+ modelId,
35
+ engineToken: context.server.token,
36
+ apiUrl: context.server.apiUrl,
37
+ });
38
+ const response = yield (0, ai_1.generateText)({
39
+ model,
40
+ prompt: `As a text classifier, your task is to assign one of the following categories to the provided text: ${categories.join(', ')}. Please respond with only the selected category as a single word, and nothing else.
41
+ Text to classify: "${context.propsValue.text}"`,
42
+ });
43
+ const result = response.text.trim();
44
+ if (!categories.includes(result)) {
45
+ throw new Error('Unable to classify the text into the provided categories.');
46
+ }
47
+ return result;
48
+ });
49
+ },
50
+ });
51
+ //# sourceMappingURL=classify-text.js.map