@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.
- package/README.md +7 -0
- package/package.json +33 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +29 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/agents/agent-output-builder.d.ts +24 -0
- package/src/lib/actions/agents/agent-output-builder.js +81 -0
- package/src/lib/actions/agents/agent-output-builder.js.map +1 -0
- package/src/lib/actions/agents/run-agent.d.ts +8 -0
- package/src/lib/actions/agents/run-agent.js +219 -0
- package/src/lib/actions/agents/run-agent.js.map +1 -0
- package/src/lib/actions/image/generate-image.d.ts +6 -0
- package/src/lib/actions/image/generate-image.js +216 -0
- package/src/lib/actions/image/generate-image.js.map +1 -0
- package/src/lib/actions/text/ask-ai.d.ts +35 -0
- package/src/lib/actions/text/ask-ai.js +238 -0
- package/src/lib/actions/text/ask-ai.js.map +1 -0
- package/src/lib/actions/text/summarize-text.d.ts +7 -0
- package/src/lib/actions/text/summarize-text.js +61 -0
- package/src/lib/actions/text/summarize-text.js.map +1 -0
- package/src/lib/actions/utility/classify-text.d.ts +6 -0
- package/src/lib/actions/utility/classify-text.js +51 -0
- package/src/lib/actions/utility/classify-text.js.map +1 -0
- package/src/lib/actions/utility/extract-structured-data.d.ts +10 -0
- package/src/lib/actions/utility/extract-structured-data.js +247 -0
- package/src/lib/actions/utility/extract-structured-data.js.map +1 -0
- package/src/lib/common/ai-sdk.d.ts +55 -0
- package/src/lib/common/ai-sdk.js +62 -0
- package/src/lib/common/ai-sdk.js.map +1 -0
- package/src/lib/common/props.d.ts +10 -0
- package/src/lib/common/props.js +75 -0
- package/src/lib/common/props.js.map +1 -0
- package/src/lib/common/types.d.ts +140 -0
- package/src/lib/common/types.js +95 -0
- package/src/lib/common/types.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify-text.js","sourceRoot":"","sources":["../../../../../../../../../packages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AU,CAAC,IAAI,GAAG;aAChD,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAEpC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const extractStructuredData: 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<false>;
|
|
5
|
+
files: import("@activepieces/pieces-framework").ArrayProperty<false>;
|
|
6
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
7
|
+
mode: import("@activepieces/pieces-framework").StaticDropdownProperty<"simple" | "advanced", false> | import("@activepieces/pieces-framework").StaticDropdownProperty<"simple" | "advanced", true>;
|
|
8
|
+
schema: import("@activepieces/pieces-framework").DynamicProperties<true, undefined>;
|
|
9
|
+
maxOutputTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractStructuredData = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const ai_sdk_1 = require("../../common/ai-sdk");
|
|
7
|
+
const ai_1 = require("ai");
|
|
8
|
+
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
9
|
+
const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
|
10
|
+
const props_1 = require("../../common/props");
|
|
11
|
+
exports.extractStructuredData = (0, pieces_framework_1.createAction)({
|
|
12
|
+
name: 'extractStructuredData',
|
|
13
|
+
displayName: 'Extract Structured Data',
|
|
14
|
+
description: 'Extract structured data from provided text,image or PDF.',
|
|
15
|
+
props: {
|
|
16
|
+
provider: (0, props_1.aiProps)({ modelType: 'text' }).provider,
|
|
17
|
+
model: (0, props_1.aiProps)({ modelType: 'text' }).model,
|
|
18
|
+
text: pieces_framework_1.Property.LongText({
|
|
19
|
+
displayName: 'Text',
|
|
20
|
+
description: 'Text to extract structured data from.',
|
|
21
|
+
required: false,
|
|
22
|
+
}),
|
|
23
|
+
files: pieces_framework_1.Property.Array({
|
|
24
|
+
displayName: 'Files',
|
|
25
|
+
required: false,
|
|
26
|
+
properties: {
|
|
27
|
+
file: pieces_framework_1.Property.File({
|
|
28
|
+
displayName: 'Image/PDF',
|
|
29
|
+
description: 'Image or PDF to extract structured data from.',
|
|
30
|
+
required: false,
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
35
|
+
displayName: 'Guide Prompt',
|
|
36
|
+
description: 'Prompt to guide the AI.',
|
|
37
|
+
defaultValue: 'Extract the following data from the provided data.',
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
mode: pieces_framework_1.Property.StaticDropdown({
|
|
41
|
+
displayName: 'Data Schema Type',
|
|
42
|
+
description: 'For complex schema, you can use advanced mode.',
|
|
43
|
+
required: true,
|
|
44
|
+
defaultValue: 'simple',
|
|
45
|
+
options: {
|
|
46
|
+
disabled: false,
|
|
47
|
+
options: [
|
|
48
|
+
{ label: 'Simple', value: 'simple' },
|
|
49
|
+
{ label: 'Advanced', value: 'advanced' },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
}),
|
|
53
|
+
schema: pieces_framework_1.Property.DynamicProperties({
|
|
54
|
+
auth: pieces_framework_1.PieceAuth.None(),
|
|
55
|
+
displayName: 'Data Definition',
|
|
56
|
+
required: true,
|
|
57
|
+
refreshers: ['mode'],
|
|
58
|
+
props: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const mode = propsValue['mode'];
|
|
60
|
+
if (mode === 'advanced') {
|
|
61
|
+
return {
|
|
62
|
+
fields: pieces_framework_1.Property.Json({
|
|
63
|
+
displayName: 'JSON Schema',
|
|
64
|
+
description: 'Learn more about JSON Schema here: https://json-schema.org/learn/getting-started-step-by-step',
|
|
65
|
+
required: true,
|
|
66
|
+
defaultValue: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
name: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
},
|
|
72
|
+
age: {
|
|
73
|
+
type: 'number',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
required: ['name'],
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
fields: pieces_framework_1.Property.Array({
|
|
83
|
+
displayName: 'Data Definition',
|
|
84
|
+
required: true,
|
|
85
|
+
properties: {
|
|
86
|
+
name: pieces_framework_1.Property.ShortText({
|
|
87
|
+
displayName: 'Name',
|
|
88
|
+
description: 'Provide the name of the value you want to extract from the unstructured text. The name should be unique and short. ',
|
|
89
|
+
required: true,
|
|
90
|
+
}),
|
|
91
|
+
description: pieces_framework_1.Property.LongText({
|
|
92
|
+
displayName: 'Description',
|
|
93
|
+
description: 'Brief description of the data, this hints for the AI on what to look for',
|
|
94
|
+
required: false,
|
|
95
|
+
}),
|
|
96
|
+
type: pieces_framework_1.Property.StaticDropdown({
|
|
97
|
+
displayName: 'Data Type',
|
|
98
|
+
description: 'Type of parameter.',
|
|
99
|
+
required: true,
|
|
100
|
+
defaultValue: 'string',
|
|
101
|
+
options: {
|
|
102
|
+
disabled: false,
|
|
103
|
+
options: [
|
|
104
|
+
{ label: 'Text', value: 'string' },
|
|
105
|
+
{ label: 'Number', value: 'number' },
|
|
106
|
+
{ label: 'Boolean', value: 'boolean' },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
}),
|
|
110
|
+
isRequired: pieces_framework_1.Property.Checkbox({
|
|
111
|
+
displayName: 'Fail if Not present?',
|
|
112
|
+
required: true,
|
|
113
|
+
defaultValue: false,
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
}),
|
|
119
|
+
}),
|
|
120
|
+
maxOutputTokens: pieces_framework_1.Property.Number({
|
|
121
|
+
displayName: 'Max Tokens',
|
|
122
|
+
required: false,
|
|
123
|
+
defaultValue: 2000,
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
run(context) {
|
|
127
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
var _a;
|
|
129
|
+
const providerId = context.propsValue.provider;
|
|
130
|
+
const modelId = context.propsValue.model;
|
|
131
|
+
const text = context.propsValue.text;
|
|
132
|
+
const files = (_a = context.propsValue.files) !== null && _a !== void 0 ? _a : [];
|
|
133
|
+
const prompt = context.propsValue.prompt;
|
|
134
|
+
const schema = context.propsValue.schema;
|
|
135
|
+
const maxOutputTokens = context.propsValue.maxOutputTokens;
|
|
136
|
+
if (!text && !files.length) {
|
|
137
|
+
throw new Error('Please provide text or image/PDF to extract data from.');
|
|
138
|
+
}
|
|
139
|
+
const model = yield (0, ai_sdk_1.createAIModel)({
|
|
140
|
+
providerId,
|
|
141
|
+
modelId,
|
|
142
|
+
engineToken: context.server.token,
|
|
143
|
+
apiUrl: context.server.apiUrl,
|
|
144
|
+
});
|
|
145
|
+
let schemaDefinition;
|
|
146
|
+
if (context.propsValue.mode === 'advanced') {
|
|
147
|
+
const ajv = new ajv_1.default();
|
|
148
|
+
const isValidSchema = ajv.validateSchema(schema['fields']);
|
|
149
|
+
if (!isValidSchema) {
|
|
150
|
+
throw new Error(JSON.stringify({
|
|
151
|
+
message: 'Invalid JSON schema',
|
|
152
|
+
errors: ajv.errors,
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
schemaDefinition = (0, ai_1.jsonSchema)(schema['fields']);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const fields = schema['fields'];
|
|
159
|
+
const properties = {};
|
|
160
|
+
const required = [];
|
|
161
|
+
fields.forEach((field) => {
|
|
162
|
+
if (!/^[a-zA-Z0-9_.-]+$/.test(field.name)) {
|
|
163
|
+
throw new Error(`Invalid field name: ${field.name}. Field names can only contain letters, numbers, underscores, dots and hyphens.`);
|
|
164
|
+
}
|
|
165
|
+
properties[field.name] = {
|
|
166
|
+
type: field.type,
|
|
167
|
+
description: field.description,
|
|
168
|
+
};
|
|
169
|
+
if (field.isRequired) {
|
|
170
|
+
required.push(field.name);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const jsonSchemaObject = {
|
|
174
|
+
type: 'object',
|
|
175
|
+
properties,
|
|
176
|
+
required,
|
|
177
|
+
};
|
|
178
|
+
schemaDefinition = (0, ai_1.jsonSchema)(jsonSchemaObject);
|
|
179
|
+
}
|
|
180
|
+
const extractionTool = (0, ai_1.tool)({
|
|
181
|
+
description: 'Extract structured data from the provided content',
|
|
182
|
+
inputSchema: schemaDefinition,
|
|
183
|
+
execute: (data) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
return data;
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
187
|
+
const messages = [];
|
|
188
|
+
const contentParts = [];
|
|
189
|
+
let textContent = prompt || 'Extract the following data from the provided data.';
|
|
190
|
+
if (text) {
|
|
191
|
+
textContent += `\n\nText to analyze:\n${text}`;
|
|
192
|
+
}
|
|
193
|
+
contentParts.push({
|
|
194
|
+
type: 'text',
|
|
195
|
+
text: textContent,
|
|
196
|
+
});
|
|
197
|
+
if (files.length > 0) {
|
|
198
|
+
for (const fileWrapper of files) {
|
|
199
|
+
const file = fileWrapper.file;
|
|
200
|
+
if (!file) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const fileType = file.extension ? mime_types_1.default.lookup(file.extension) : 'image/jpeg';
|
|
204
|
+
if (fileType && fileType.startsWith('image') && file.base64) {
|
|
205
|
+
contentParts.push({
|
|
206
|
+
type: 'image',
|
|
207
|
+
image: `data:${fileType};base64,${file.base64}`,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else if (fileType && fileType.startsWith('application/pdf') && file.base64) {
|
|
211
|
+
contentParts.push({
|
|
212
|
+
type: 'file',
|
|
213
|
+
data: `data:${fileType};base64,${file.base64}`,
|
|
214
|
+
mediaType: fileType,
|
|
215
|
+
filename: file.filename,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
messages.push({
|
|
221
|
+
role: 'user',
|
|
222
|
+
content: contentParts,
|
|
223
|
+
});
|
|
224
|
+
try {
|
|
225
|
+
const result = yield (0, ai_1.generateText)({
|
|
226
|
+
model,
|
|
227
|
+
maxOutputTokens,
|
|
228
|
+
tools: {
|
|
229
|
+
extractData: extractionTool,
|
|
230
|
+
},
|
|
231
|
+
toolChoice: 'required',
|
|
232
|
+
messages,
|
|
233
|
+
});
|
|
234
|
+
const toolCalls = result.toolCalls;
|
|
235
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
236
|
+
throw new Error('No structured data could be extracted from the input.');
|
|
237
|
+
}
|
|
238
|
+
const extractedData = toolCalls[0].input;
|
|
239
|
+
return extractedData;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
throw new Error(`Failed to extract structured data: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
//# sourceMappingURL=extract-structured-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-structured-data.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/ai/src/lib/actions/utility/extract-structured-data.ts"],"names":[],"mappings":";;;;AAAA,qEAA2F;AAC3F,gDAAoD;AACpD,2BAAoF;AACpF,oEAA8B;AAC9B,sDAAsB;AACtB,8CAA6C;AAEhC,QAAA,qBAAqB,GAAG,IAAA,+BAAY,EAAC;IACjD,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,yBAAyB;IACtC,WAAW,EAAE,0DAA0D;IACvE,KAAK,EAAE;QACN,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;YACvB,WAAW,EAAE,MAAM;YACnB,WAAW,EAAE,uCAAuC;YACpD,QAAQ,EAAE,KAAK;SACf,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,KAAK,CAAC;YACrB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE;gBACX,IAAI,EAAE,2BAAQ,CAAC,IAAI,CAAC;oBACnB,WAAW,EAAE,WAAW;oBACxB,WAAW,EAAE,+CAA+C;oBAC5D,QAAQ,EAAE,KAAK;iBACf,CAAC;aACF;SACD,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACzB,WAAW,EAAE,cAAc;YAC3B,WAAW,EAAE,yBAAyB;YACtC,YAAY,EAAE,oDAAoD;YAClE,QAAQ,EAAE,KAAK;SACf,CAAC;QACF,IAAI,EAAE,2BAAQ,CAAC,cAAc,CAAwB;YACpD,WAAW,EAAE,kBAAkB;YAC/B,WAAW,EAAE,gDAAgD;YAC7D,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,QAAQ;YACtB,OAAO,EAAE;gBACR,QAAQ,EAAE,KAAK;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C,CAAC,CAAC,KAAK,CAAC;gBACzC,OAAO,aAAa,CAAC;YAEtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YACnH,CAAC;QACF,CAAC;KAAA;CACD,CAAC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { LanguageModelV2 } from '@ai-sdk/provider';
|
|
2
|
+
import { ImageModel } from 'ai';
|
|
3
|
+
type CreateAIModelParams<IsImage extends boolean = false> = {
|
|
4
|
+
providerId: string;
|
|
5
|
+
modelId: string;
|
|
6
|
+
engineToken: string;
|
|
7
|
+
apiUrl: string;
|
|
8
|
+
openaiResponsesModel?: boolean;
|
|
9
|
+
isImage?: IsImage;
|
|
10
|
+
};
|
|
11
|
+
export declare function createAIModel(params: CreateAIModelParams<false>): Promise<LanguageModelV2>;
|
|
12
|
+
export declare function createAIModel(params: CreateAIModelParams<true>): Promise<ImageModel>;
|
|
13
|
+
export declare const anthropicSearchTool: (args?: Parameters<import("@ai-sdk/provider-utils").ProviderDefinedToolFactoryWithOutputSchema<{
|
|
14
|
+
query: string;
|
|
15
|
+
}, {
|
|
16
|
+
url: string;
|
|
17
|
+
title: string;
|
|
18
|
+
pageAge: string | null;
|
|
19
|
+
encryptedContent: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}[], {
|
|
22
|
+
maxUses?: number;
|
|
23
|
+
allowedDomains?: string[];
|
|
24
|
+
blockedDomains?: string[];
|
|
25
|
+
userLocation?: {
|
|
26
|
+
type: "approximate";
|
|
27
|
+
city?: string;
|
|
28
|
+
region?: string;
|
|
29
|
+
country?: string;
|
|
30
|
+
timezone?: string;
|
|
31
|
+
};
|
|
32
|
+
}>>[0]) => import("@ai-sdk/provider-utils").Tool<{
|
|
33
|
+
query: string;
|
|
34
|
+
}, {
|
|
35
|
+
url: string;
|
|
36
|
+
title: string;
|
|
37
|
+
pageAge: string | null;
|
|
38
|
+
encryptedContent: string;
|
|
39
|
+
type: string;
|
|
40
|
+
}[]>;
|
|
41
|
+
export declare const openaiSearchTool: import("@ai-sdk/provider-utils").ProviderDefinedToolFactory<{}, {
|
|
42
|
+
searchContextSize?: "low" | "medium" | "high";
|
|
43
|
+
userLocation?: {
|
|
44
|
+
type: "approximate";
|
|
45
|
+
country?: string;
|
|
46
|
+
city?: string;
|
|
47
|
+
region?: string;
|
|
48
|
+
timezone?: string;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
export declare const googleSearchTool: import("@ai-sdk/provider-utils").ProviderDefinedToolFactory<{}, {
|
|
52
|
+
mode?: "MODE_DYNAMIC" | "MODE_UNSPECIFIED";
|
|
53
|
+
dynamicThreshold?: number;
|
|
54
|
+
}>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.googleSearchTool = exports.openaiSearchTool = exports.anthropicSearchTool = void 0;
|
|
4
|
+
exports.createAIModel = createAIModel;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const anthropic_1 = require("@ai-sdk/anthropic");
|
|
7
|
+
const google_1 = require("@ai-sdk/google");
|
|
8
|
+
const openai_1 = require("@ai-sdk/openai");
|
|
9
|
+
const azure_1 = require("@ai-sdk/azure");
|
|
10
|
+
const ai_sdk_provider_1 = require("@openrouter/ai-sdk-provider");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
13
|
+
function createAIModel(_a) {
|
|
14
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ providerId, modelId, engineToken, apiUrl, openaiResponsesModel = false, isImage, }) {
|
|
15
|
+
const { body: config } = yield pieces_common_1.httpClient.sendRequest({
|
|
16
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
17
|
+
url: `${apiUrl}v1/ai-providers/${providerId}/config`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${engineToken}`,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
switch (providerId) {
|
|
23
|
+
case types_1.AIProviderName.OPENAI: {
|
|
24
|
+
const provider = (0, openai_1.createOpenAI)({ apiKey: config.apiKey });
|
|
25
|
+
if (isImage) {
|
|
26
|
+
return provider.imageModel(modelId);
|
|
27
|
+
}
|
|
28
|
+
return (openaiResponsesModel ? provider.responses(modelId) : provider.chat(modelId));
|
|
29
|
+
}
|
|
30
|
+
case types_1.AIProviderName.ANTHROPIC: {
|
|
31
|
+
const provider = (0, anthropic_1.createAnthropic)({ apiKey: config.apiKey });
|
|
32
|
+
if (isImage) {
|
|
33
|
+
throw new Error(`Provider ${providerId} does not support image models`);
|
|
34
|
+
}
|
|
35
|
+
return provider(modelId);
|
|
36
|
+
}
|
|
37
|
+
case types_1.AIProviderName.GOOGLE: {
|
|
38
|
+
const provider = (0, google_1.createGoogleGenerativeAI)({ apiKey: config.apiKey });
|
|
39
|
+
return provider(modelId);
|
|
40
|
+
}
|
|
41
|
+
case types_1.AIProviderName.AZURE: {
|
|
42
|
+
const { apiKey, resourceName } = config;
|
|
43
|
+
const provider = (0, azure_1.createAzure)({ resourceName, apiKey });
|
|
44
|
+
if (isImage) {
|
|
45
|
+
return provider.imageModel(modelId);
|
|
46
|
+
}
|
|
47
|
+
return provider.chat(modelId);
|
|
48
|
+
}
|
|
49
|
+
case types_1.AIProviderName.ACTIVEPIECES:
|
|
50
|
+
case types_1.AIProviderName.OPENROUTER: {
|
|
51
|
+
const provider = (0, ai_sdk_provider_1.createOpenRouter)({ apiKey: config.apiKey });
|
|
52
|
+
return provider.chat(modelId);
|
|
53
|
+
}
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Provider ${providerId} is not supported`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.anthropicSearchTool = anthropic_1.anthropic.tools.webSearch_20250305;
|
|
60
|
+
exports.openaiSearchTool = openai_1.openai.tools.webSearchPreview;
|
|
61
|
+
exports.googleSearchTool = google_1.google.tools.googleSearch;
|
|
62
|
+
//# sourceMappingURL=ai-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/ai/src/lib/common/ai-sdk.ts"],"names":[],"mappings":";;;AAqBA,sCAoDC;;AAzED,iDAA8D;AAC9D,2CAAiE;AACjE,2CAAqD;AAErD,yCAA2C;AAC3C,iEAA8D;AAE9D,mCAA+E;AAC/E,+DAAoE;AAapE,SAAsB,aAAa;iEAAC,EAChC,UAAU,EACV,OAAO,EACP,WAAW,EACX,MAAM,EACN,oBAAoB,GAAG,KAAK,EAC5B,OAAO,GACoB;QAC3B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAmB;YACpE,MAAM,EAAE,0BAAU,CAAC,GAAG;YACtB,GAAG,EAAE,GAAG,MAAM,mBAAmB,UAAU,SAAS;YACpD,OAAO,EAAE;gBACL,aAAa,EAAE,UAAU,WAAW,EAAE;aACzC;SACJ,CAAC,CAAC;QAEH,QAAQ,UAAU,EAAE,CAAC;YACjB,KAAK,sBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;gBACzB,MAAM,QAAQ,GAAG,IAAA,qBAAY,EAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;gBACxD,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;gBACvC,CAAC;gBACD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAA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mB,CAAC,CAAA;QAClE,CAAC;IACL,CAAC;CAAA;AAEY,QAAA,mBAAmB,GAAG,qBAAS,CAAC,KAAK,CAAC,kBAAkB,CAAC;AACzD,QAAA,gBAAgB,GAAG,eAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC;AACjD,QAAA,gBAAgB,GAAG,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AIProviderName } from './types';
|
|
2
|
+
export declare const aiProps: <T extends "text" | "image">({ modelType, allowedProviders }: AIPropsParams<T>) => {
|
|
3
|
+
provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
|
|
4
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
|
|
5
|
+
};
|
|
6
|
+
type AIPropsParams<T extends 'text' | 'image'> = {
|
|
7
|
+
modelType: T;
|
|
8
|
+
allowedProviders?: AIProviderName[];
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aiProps = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
7
|
+
const shared_1 = require("@activepieces/shared");
|
|
8
|
+
const aiProps = ({ modelType, allowedProviders }) => ({
|
|
9
|
+
provider: pieces_framework_1.Property.Dropdown({
|
|
10
|
+
auth: pieces_framework_1.PieceAuth.None(),
|
|
11
|
+
displayName: 'Provider',
|
|
12
|
+
required: true,
|
|
13
|
+
refreshers: [],
|
|
14
|
+
options: (_, ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const { body: supportedProviders } = yield pieces_common_1.httpClient.sendRequest({
|
|
16
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
17
|
+
url: `${ctx.server.apiUrl}v1/ai-providers`,
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${ctx.server.token}`,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const configured = supportedProviders.filter(supportedProvider => supportedProvider.configured);
|
|
23
|
+
if (configured.length === 0) {
|
|
24
|
+
return {
|
|
25
|
+
disabled: true,
|
|
26
|
+
options: [],
|
|
27
|
+
placeholder: 'No AI providers configured by the admin.',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
placeholder: 'Select AI Provider',
|
|
32
|
+
disabled: false,
|
|
33
|
+
options: configured.map(supportedProvider => ({
|
|
34
|
+
label: supportedProvider.name,
|
|
35
|
+
value: supportedProvider.id,
|
|
36
|
+
})).filter(provider => allowedProviders ? allowedProviders.includes(provider.value) : true),
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
41
|
+
auth: pieces_framework_1.PieceAuth.None(),
|
|
42
|
+
displayName: 'Model',
|
|
43
|
+
required: true,
|
|
44
|
+
defaultValue: 'gpt-4o',
|
|
45
|
+
refreshers: ['provider'],
|
|
46
|
+
options: (propsValue, ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const provider = propsValue['provider'];
|
|
48
|
+
if ((0, shared_1.isNil)(provider)) {
|
|
49
|
+
return {
|
|
50
|
+
disabled: true,
|
|
51
|
+
options: [],
|
|
52
|
+
placeholder: 'Select AI Provider',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const { body: allModels } = yield pieces_common_1.httpClient.sendRequest({
|
|
56
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
57
|
+
url: `${ctx.server.apiUrl}v1/ai-providers/${provider}/models`,
|
|
58
|
+
headers: {
|
|
59
|
+
Authorization: `Bearer ${ctx.server.token}`,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const models = allModels.filter(model => model.type === modelType);
|
|
63
|
+
return {
|
|
64
|
+
placeholder: 'Select AI Model',
|
|
65
|
+
disabled: false,
|
|
66
|
+
options: models.map(model => ({
|
|
67
|
+
label: model.name,
|
|
68
|
+
value: model.id,
|
|
69
|
+
})),
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
exports.aiProps = aiProps;
|
|
75
|
+
//# sourceMappingURL=props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/ai/src/lib/common/props.ts"],"names":[],"mappings":";;;;AAAA,qEAAqE;AACrE,+DAAqE;AACrE,iDAA6C;AAGtC,MAAM,OAAO,GAAG,CAA6B,EAAE,SAAS,EAAE,gBAAgB,EAAoB,EAAE,EAAE,CAAC,CAAC;IACvG,QAAQ,EAAE,2BAAQ,CAAC,QAAQ,CAAe;QACtC,IAAI,EAAE,4BAAS,CAAC,IAAI,EAAE;QACtB,WAAW,EAAE,UAAU;QACvB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,CAAO,CAAC,EAAE,GAAG,EAAE,EAAE;YACtB,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,0BAAU,CAAC,WAAW,CAAmC;gBAChG,MAAM,EAAE,0BAAU,CAAC,GAAG;gBACtB,GAAG,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,iBAAiB;gBAC1C,OAAO,EAAE;oBACL,aAAa,EAAE,UAAU,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE;iBAC9C;aACJ,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAChG,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,OAAO;o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,aAAa,EAAE,UAAU,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE;iBAC9C;aACJ,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;YAEnE,OAAO;gBACH,WAAW,EAAE,iBAAiB;gBAC9B,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;oBAC1B,KAAK,EAAE,KAAK,CAAC,IAAI;oBACjB,KAAK,EAAE,KAAK,CAAC,EAAE;iBAClB,CAAC,CAAC;aACN,CAAC;QACN,CAAC,CAAA;KACJ,CAAC;CACL,CAAC,CAAA;AAtEW,QAAA,OAAO,WAsElB"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Static } from '@sinclair/typebox';
|
|
2
|
+
export declare const AnthropicProviderConfig: import("@sinclair/typebox").TObject<{
|
|
3
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
4
|
+
}>;
|
|
5
|
+
export type AnthropicProviderConfig = Static<typeof AnthropicProviderConfig>;
|
|
6
|
+
export declare const AzureProviderConfig: import("@sinclair/typebox").TObject<{
|
|
7
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
8
|
+
resourceName: import("@sinclair/typebox").TString;
|
|
9
|
+
}>;
|
|
10
|
+
export type AzureProviderConfig = Static<typeof AzureProviderConfig>;
|
|
11
|
+
export declare const GoogleProviderConfig: import("@sinclair/typebox").TObject<{
|
|
12
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
13
|
+
}>;
|
|
14
|
+
export type GoogleProviderConfig = Static<typeof GoogleProviderConfig>;
|
|
15
|
+
export declare const OpenAIProviderConfig: import("@sinclair/typebox").TObject<{
|
|
16
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
17
|
+
}>;
|
|
18
|
+
export type OpenAIProviderConfig = Static<typeof OpenAIProviderConfig>;
|
|
19
|
+
export declare const OpenRouterProviderConfig: import("@sinclair/typebox").TObject<{
|
|
20
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
21
|
+
}>;
|
|
22
|
+
export type OpenRouterProviderConfig = Static<typeof OpenRouterProviderConfig>;
|
|
23
|
+
export declare const AIProviderConfig: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
24
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
25
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
26
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
27
|
+
resourceName: import("@sinclair/typebox").TString;
|
|
28
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
29
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
30
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
31
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
32
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
33
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
34
|
+
}>]>;
|
|
35
|
+
export type AIProviderConfig = Static<typeof AIProviderConfig>;
|
|
36
|
+
export declare enum AIProviderName {
|
|
37
|
+
OPENAI = "openai",
|
|
38
|
+
OPENROUTER = "openrouter",
|
|
39
|
+
ANTHROPIC = "anthropic",
|
|
40
|
+
AZURE = "azure",
|
|
41
|
+
GOOGLE = "google",
|
|
42
|
+
ACTIVEPIECES = "activepieces"
|
|
43
|
+
}
|
|
44
|
+
export declare const AIProvider: import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
|
|
45
|
+
id: import("@sinclair/typebox").TString;
|
|
46
|
+
created: import("@sinclair/typebox").TString;
|
|
47
|
+
updated: import("@sinclair/typebox").TString;
|
|
48
|
+
}>, import("@activepieces/shared").TDiscriminatedUnion<[import("@sinclair/typebox").TObject<{
|
|
49
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.OPENAI>;
|
|
50
|
+
config: import("@sinclair/typebox").TObject<{
|
|
51
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
52
|
+
}>;
|
|
53
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
54
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.OPENROUTER>;
|
|
55
|
+
config: import("@sinclair/typebox").TObject<{
|
|
56
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
57
|
+
}>;
|
|
58
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
59
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.ANTHROPIC>;
|
|
60
|
+
config: import("@sinclair/typebox").TObject<{
|
|
61
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
62
|
+
}>;
|
|
63
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
64
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.AZURE>;
|
|
65
|
+
config: import("@sinclair/typebox").TObject<{
|
|
66
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
67
|
+
resourceName: import("@sinclair/typebox").TString;
|
|
68
|
+
}>;
|
|
69
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
70
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.GOOGLE>;
|
|
71
|
+
config: import("@sinclair/typebox").TObject<{
|
|
72
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
73
|
+
}>;
|
|
74
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
75
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.ACTIVEPIECES>;
|
|
76
|
+
config: import("@sinclair/typebox").TObject<{
|
|
77
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
78
|
+
}>;
|
|
79
|
+
}>]>, import("@sinclair/typebox").TObject<{
|
|
80
|
+
displayName: import("@sinclair/typebox").TString;
|
|
81
|
+
platformId: import("@sinclair/typebox").TString;
|
|
82
|
+
}>]>;
|
|
83
|
+
export type AIProvider = Static<typeof AIProvider>;
|
|
84
|
+
export declare const AIProviderWithoutSensitiveData: import("@sinclair/typebox").TObject<{
|
|
85
|
+
id: import("@sinclair/typebox").TString;
|
|
86
|
+
name: import("@sinclair/typebox").TString;
|
|
87
|
+
configured: import("@sinclair/typebox").TBoolean;
|
|
88
|
+
}>;
|
|
89
|
+
export type AIProviderWithoutSensitiveData = Static<typeof AIProviderWithoutSensitiveData>;
|
|
90
|
+
export declare enum AIProviderModelType {
|
|
91
|
+
IMAGE = "image",
|
|
92
|
+
TEXT = "text"
|
|
93
|
+
}
|
|
94
|
+
export declare const AIProviderModel: import("@sinclair/typebox").TObject<{
|
|
95
|
+
id: import("@sinclair/typebox").TString;
|
|
96
|
+
name: import("@sinclair/typebox").TString;
|
|
97
|
+
type: import("@sinclair/typebox").TEnum<typeof AIProviderModelType>;
|
|
98
|
+
}>;
|
|
99
|
+
export type AIProviderModel = Static<typeof AIProviderModel>;
|
|
100
|
+
export declare const CreateAIProviderRequest: import("@activepieces/shared").TDiscriminatedUnion<[import("@sinclair/typebox").TObject<{
|
|
101
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.OPENAI>;
|
|
102
|
+
config: import("@sinclair/typebox").TObject<{
|
|
103
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
104
|
+
}>;
|
|
105
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
106
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.OPENROUTER>;
|
|
107
|
+
config: import("@sinclair/typebox").TObject<{
|
|
108
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
109
|
+
}>;
|
|
110
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
111
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.ANTHROPIC>;
|
|
112
|
+
config: import("@sinclair/typebox").TObject<{
|
|
113
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
114
|
+
}>;
|
|
115
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
116
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.AZURE>;
|
|
117
|
+
config: import("@sinclair/typebox").TObject<{
|
|
118
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
119
|
+
resourceName: import("@sinclair/typebox").TString;
|
|
120
|
+
}>;
|
|
121
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
122
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.GOOGLE>;
|
|
123
|
+
config: import("@sinclair/typebox").TObject<{
|
|
124
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
125
|
+
}>;
|
|
126
|
+
}>, import("@sinclair/typebox").TObject<{
|
|
127
|
+
provider: import("@sinclair/typebox").TLiteral<AIProviderName.ACTIVEPIECES>;
|
|
128
|
+
config: import("@sinclair/typebox").TObject<{
|
|
129
|
+
apiKey: import("@sinclair/typebox").TString;
|
|
130
|
+
}>;
|
|
131
|
+
}>]>;
|
|
132
|
+
export type CreateAIProviderRequest = Static<typeof CreateAIProviderRequest>;
|
|
133
|
+
export declare const AIErrorResponse: import("@sinclair/typebox").TObject<{
|
|
134
|
+
error: import("@sinclair/typebox").TObject<{
|
|
135
|
+
message: import("@sinclair/typebox").TString;
|
|
136
|
+
type: import("@sinclair/typebox").TString;
|
|
137
|
+
code: import("@sinclair/typebox").TString;
|
|
138
|
+
}>;
|
|
139
|
+
}>;
|
|
140
|
+
export type AIErrorResponse = Static<typeof AIErrorResponse>;
|