@activepieces/piece-aws-bedrock 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 +23 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +115 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/generate-content-from-image.d.ts +16 -0
- package/src/lib/actions/generate-content-from-image.js +108 -0
- package/src/lib/actions/generate-content-from-image.js.map +1 -0
- package/src/lib/actions/generate-embeddings.d.ts +15 -0
- package/src/lib/actions/generate-embeddings.js +152 -0
- package/src/lib/actions/generate-embeddings.js.map +1 -0
- package/src/lib/actions/generate-image.d.ts +16 -0
- package/src/lib/actions/generate-image.js +139 -0
- package/src/lib/actions/generate-image.js.map +1 -0
- package/src/lib/actions/send-prompt.d.ts +18 -0
- package/src/lib/actions/send-prompt.js +108 -0
- package/src/lib/actions/send-prompt.js.map +1 -0
- package/src/lib/common.d.ts +33 -0
- package/src/lib/common.js +158 -0
- package/src/lib/common.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@activepieces/piece-aws-bedrock",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@aws-sdk/client-bedrock": "^3.987.0",
|
|
9
|
+
"@aws-sdk/client-bedrock-runtime": "^3.987.0",
|
|
10
|
+
"@sinclair/typebox": "0.34.11",
|
|
11
|
+
"ai": "^6.0.0",
|
|
12
|
+
"deepmerge-ts": "7.1.0",
|
|
13
|
+
"nanoid": "3.3.8",
|
|
14
|
+
"semver": "7.6.0",
|
|
15
|
+
"socket.io-client": "4.8.1",
|
|
16
|
+
"tslib": "^2.3.0",
|
|
17
|
+
"@activepieces/pieces-framework": "0.25.3",
|
|
18
|
+
"@activepieces/shared": "0.36.0"
|
|
19
|
+
},
|
|
20
|
+
"resolutions": {
|
|
21
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const awsBedrockAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const awsBedrock: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
10
|
+
}>>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awsBedrock = exports.awsBedrockAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const shared_1 = require("@activepieces/shared");
|
|
7
|
+
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
8
|
+
const send_prompt_1 = require("./lib/actions/send-prompt");
|
|
9
|
+
const generate_content_from_image_1 = require("./lib/actions/generate-content-from-image");
|
|
10
|
+
const generate_image_1 = require("./lib/actions/generate-image");
|
|
11
|
+
const generate_embeddings_1 = require("./lib/actions/generate-embeddings");
|
|
12
|
+
const common_1 = require("./lib/common");
|
|
13
|
+
exports.awsBedrockAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
14
|
+
description: 'AWS Bedrock authentication using Access Key and Secret Key.',
|
|
15
|
+
props: {
|
|
16
|
+
accessKeyId: pieces_framework_1.Property.ShortText({
|
|
17
|
+
displayName: 'Access Key ID',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
secretAccessKey: pieces_framework_1.PieceAuth.SecretText({
|
|
21
|
+
displayName: 'Secret Access Key',
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
region: pieces_framework_1.Property.StaticDropdown({
|
|
25
|
+
displayName: 'Region',
|
|
26
|
+
required: true,
|
|
27
|
+
options: {
|
|
28
|
+
options: [
|
|
29
|
+
{ label: 'US East (N. Virginia) [us-east-1]', value: 'us-east-1' },
|
|
30
|
+
{ label: 'US East (Ohio) [us-east-2]', value: 'us-east-2' },
|
|
31
|
+
{ label: 'US West (Oregon) [us-west-2]', value: 'us-west-2' },
|
|
32
|
+
{
|
|
33
|
+
label: 'Asia Pacific (Hyderabad) [ap-south-2]',
|
|
34
|
+
value: 'ap-south-2',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: 'Asia Pacific (Mumbai) [ap-south-1]',
|
|
38
|
+
value: 'ap-south-1',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'Asia Pacific (Osaka) [ap-northeast-3]',
|
|
42
|
+
value: 'ap-northeast-3',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Asia Pacific (Seoul) [ap-northeast-2]',
|
|
46
|
+
value: 'ap-northeast-2',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: 'Asia Pacific (Singapore) [ap-southeast-1]',
|
|
50
|
+
value: 'ap-southeast-1',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Asia Pacific (Sydney) [ap-southeast-2]',
|
|
54
|
+
value: 'ap-southeast-2',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: 'Asia Pacific (Tokyo) [ap-northeast-1]',
|
|
58
|
+
value: 'ap-northeast-1',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: 'Canada (Central) [ca-central-1]',
|
|
62
|
+
value: 'ca-central-1',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: 'Europe (Frankfurt) [eu-central-1]',
|
|
66
|
+
value: 'eu-central-1',
|
|
67
|
+
},
|
|
68
|
+
{ label: 'Europe (Ireland) [eu-west-1]', value: 'eu-west-1' },
|
|
69
|
+
{ label: 'Europe (London) [eu-west-2]', value: 'eu-west-2' },
|
|
70
|
+
{ label: 'Europe (Milan) [eu-south-1]', value: 'eu-south-1' },
|
|
71
|
+
{ label: 'Europe (Paris) [eu-west-3]', value: 'eu-west-3' },
|
|
72
|
+
{ label: 'Europe (Spain) [eu-south-2]', value: 'eu-south-2' },
|
|
73
|
+
{
|
|
74
|
+
label: 'Europe (Stockholm) [eu-north-1]',
|
|
75
|
+
value: 'eu-north-1',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
label: 'Europe (Zurich) [eu-central-2]',
|
|
79
|
+
value: 'eu-central-2',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
label: 'South America (São Paulo) [sa-east-1]',
|
|
83
|
+
value: 'sa-east-1',
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
90
|
+
try {
|
|
91
|
+
const client = (0, common_1.createBedrockClient)(auth);
|
|
92
|
+
yield client.send(new client_bedrock_1.ListFoundationModelsCommand({}));
|
|
93
|
+
return { valid: true };
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
return {
|
|
97
|
+
valid: false,
|
|
98
|
+
error: e === null || e === void 0 ? void 0 : e.message,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
required: true,
|
|
103
|
+
});
|
|
104
|
+
exports.awsBedrock = (0, pieces_framework_1.createPiece)({
|
|
105
|
+
displayName: 'AWS Bedrock',
|
|
106
|
+
description: 'Build generative AI applications with foundation models',
|
|
107
|
+
auth: exports.awsBedrockAuth,
|
|
108
|
+
minimumSupportedRelease: '0.36.1',
|
|
109
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/aws-bedrock.png',
|
|
110
|
+
categories: [shared_1.PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
111
|
+
authors: ["onyedikachi-david"],
|
|
112
|
+
actions: [send_prompt_1.sendPrompt, generate_content_from_image_1.generateContentFromImage, generate_image_1.generateImage, generate_embeddings_1.generateEmbeddings],
|
|
113
|
+
triggers: [],
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/aws-bedrock/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,iDAAqD;AACrD,4DAAsE;AACtE,2DAAuD;AACvD,2FAAqF;AACrF,iEAA6D;AAC7D,2EAAuE;AACvE,yCAAmD;AAEtC,QAAA,cAAc,GAAG,4BAAS,CAAC,UAAU,CAAC;IACjD,WAAW,EAAE,6DAA6D;IAC1E,KAAK,EAAE;QACL,WAAW,EAAE,2BAAQ,CAAC,SAAS,CAAC;YAC9B,WAAW,EAAE,eAAe;YAC5B,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,eAAe,EAAE,4BAAS,CAAC,UAAU,CAAC;YACpC,WAAW,EAAE,mBAAmB;YAChC,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAC9B,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP,EAAE,KAAK,EAAE,mC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;wBACE,KAAK,EAAE,uCAAuC;wBAC9C,KAAK,EAAE,WAAW;qBACnB;iBACF;aACF;SACF,CAAC;KACH;IACD,QAAQ,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;QACvB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;YACzC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,4CAA2B,CAAC,EAAE,CAAC,CAAC,CAAC;YACvD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAG,CAAW,aAAX,CAAC,uBAAD,CAAC,CAAY,OAAO;aAC7B,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;IACD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC;AAEU,QAAA,UAAU,GAAG,IAAA,8BAAW,EAAC;IACpC,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,yDAAyD;IACtE,IAAI,EAAE,sBAAc;IACpB,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,qDAAqD;IAC9D,UAAU,EAAE,CAAC,sBAAa,CAAC,uBAAuB,CAAC;IACnD,OAAO,EAAE,CAAC,mBAAmB,CAAC;IAC9B,OAAO,EAAE,CAAC,wBAAU,EAAE,sDAAwB,EAAE,8BAAa,EAAE,wCAAkB,CAAC;IAClF,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const generateContentFromImage: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
10
|
+
}>>;
|
|
11
|
+
image: import("@activepieces/pieces-framework").FileProperty<true>;
|
|
12
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
13
|
+
systemPrompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
14
|
+
temperature: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
15
|
+
maxTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateContentFromImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
7
|
+
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const common_1 = require("../common");
|
|
10
|
+
const EXTENSION_TO_FORMAT = {
|
|
11
|
+
png: client_bedrock_runtime_1.ImageFormat.PNG,
|
|
12
|
+
jpg: client_bedrock_runtime_1.ImageFormat.JPEG,
|
|
13
|
+
jpeg: client_bedrock_runtime_1.ImageFormat.JPEG,
|
|
14
|
+
gif: client_bedrock_runtime_1.ImageFormat.GIF,
|
|
15
|
+
webp: client_bedrock_runtime_1.ImageFormat.WEBP,
|
|
16
|
+
};
|
|
17
|
+
exports.generateContentFromImage = (0, pieces_framework_1.createAction)({
|
|
18
|
+
auth: index_1.awsBedrockAuth,
|
|
19
|
+
name: 'generate_content_from_image',
|
|
20
|
+
displayName: 'Generate Content from Image',
|
|
21
|
+
description: 'Ask a Bedrock model a question about an image.',
|
|
22
|
+
props: {
|
|
23
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
24
|
+
displayName: 'Model',
|
|
25
|
+
required: true,
|
|
26
|
+
auth: index_1.awsBedrockAuth,
|
|
27
|
+
description: 'The foundation model to use. Must support image input.',
|
|
28
|
+
refreshers: [],
|
|
29
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
30
|
+
if (!auth) {
|
|
31
|
+
return {
|
|
32
|
+
disabled: true,
|
|
33
|
+
placeholder: 'Connect your AWS account first',
|
|
34
|
+
options: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return (0, common_1.getBedrockModelOptions)(auth.props, {
|
|
38
|
+
useInferenceProfiles: true,
|
|
39
|
+
inputModality: client_bedrock_1.ModelModality.IMAGE,
|
|
40
|
+
});
|
|
41
|
+
}),
|
|
42
|
+
}),
|
|
43
|
+
image: pieces_framework_1.Property.File({
|
|
44
|
+
displayName: 'Image',
|
|
45
|
+
required: true,
|
|
46
|
+
description: 'The image to analyze (PNG, JPEG, GIF, or WebP).',
|
|
47
|
+
}),
|
|
48
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
49
|
+
displayName: 'Prompt',
|
|
50
|
+
required: true,
|
|
51
|
+
description: 'What do you want the model to tell you about the image?',
|
|
52
|
+
}),
|
|
53
|
+
systemPrompt: pieces_framework_1.Property.LongText({
|
|
54
|
+
displayName: 'System Prompt',
|
|
55
|
+
required: false,
|
|
56
|
+
description: 'Instructions that guide the model behavior.',
|
|
57
|
+
}),
|
|
58
|
+
temperature: pieces_framework_1.Property.Number({
|
|
59
|
+
displayName: 'Temperature',
|
|
60
|
+
required: false,
|
|
61
|
+
description: 'Controls randomness. Lower values produce more deterministic output.',
|
|
62
|
+
defaultValue: 0.7,
|
|
63
|
+
}),
|
|
64
|
+
maxTokens: pieces_framework_1.Property.Number({
|
|
65
|
+
displayName: 'Maximum Tokens',
|
|
66
|
+
required: false,
|
|
67
|
+
description: 'The maximum number of tokens to generate.',
|
|
68
|
+
defaultValue: 2048,
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
run(_a) {
|
|
72
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue }) {
|
|
73
|
+
var _b;
|
|
74
|
+
const client = (0, common_1.createBedrockRuntimeClient)(auth.props);
|
|
75
|
+
const { model, image, prompt, systemPrompt, temperature, maxTokens } = propsValue;
|
|
76
|
+
const ext = ((_b = image.extension) !== null && _b !== void 0 ? _b : 'png').toLowerCase();
|
|
77
|
+
const format = EXTENSION_TO_FORMAT[ext];
|
|
78
|
+
if (!format) {
|
|
79
|
+
throw new Error(`Unsupported image format "${ext}". Supported: png, jpeg, gif, webp.`);
|
|
80
|
+
}
|
|
81
|
+
const imageBytes = Buffer.from(image.base64, 'base64');
|
|
82
|
+
try {
|
|
83
|
+
const response = yield client.send(new client_bedrock_runtime_1.ConverseCommand(Object.assign(Object.assign({ modelId: model, messages: [
|
|
84
|
+
{
|
|
85
|
+
role: client_bedrock_runtime_1.ConversationRole.USER,
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
image: {
|
|
89
|
+
format,
|
|
90
|
+
source: { bytes: imageBytes },
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{ text: prompt },
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
] }, (systemPrompt ? { system: [{ text: systemPrompt }] } : {})), { inferenceConfig: {
|
|
97
|
+
temperature: temperature !== null && temperature !== void 0 ? temperature : undefined,
|
|
98
|
+
maxTokens: maxTokens !== null && maxTokens !== void 0 ? maxTokens : undefined,
|
|
99
|
+
} })));
|
|
100
|
+
return (0, common_1.extractConverseTextResponse)(response);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error((0, common_1.formatBedrockError)(error));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=generate-content-from-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-content-from-image.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/aws-bedrock/src/lib/actions/generate-content-from-image.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,4EAIyC;AACzC,4DAAwD;AACxD,uCAA6C;AAC7C,sCAKmB;AAEnB,MAAM,mBAAmB,GAAgC;IACvD,GAAG,EAAE,oCAAW,CAAC,GAAG;IACpB,GAAG,EAAE,oCAAW,CAAC,IAAI;IACrB,IAAI,EAAE,oCAAW,CAAC,IAAI;IACtB,GAAG,EAAE,oCAAW,CAAC,GAAG;IACpB,IAAI,EAAE,oCAAW,CAAC,IAAI;CACvB,CAAC;AAEW,QAAA,wBAAwB,GAAG,IAAA,+BAAY,EAAC;IACnD,IAAI,EAAE,sBAAc;IACpB,IAAI,EAAE,6BAA6B;IACnC,WAAW,EAAE,6BAA6B;IAC1C,WAAW,EAAE,gDAAgD;IAC7D,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,sBAAc;YACpB,WAAW,EAAE,wDAAwD;YACrE,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;gBACtB,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,WAAW,EAAE,gCAAgC;wBAC7C,OAAO,EAAE,EAAE;qBACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAA,+BAAsB,EAAC,IAAI,CAAC,KAAK,EAAE;oBACxC,oBAAoB,EAAE,IAAI;oBAC1B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IAAI,KAAK,CACb,6BAA6B,GAAG,qCAAqC,CACtE,CAAC;YACJ,CAAC;YAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAEvD,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAChC,IAAI,wCAAe,+BACjB,OAAO,EAAE,KAAK,EACd,QAAQ,EAAE;wBACR;4BACE,IAAI,EAAE,yCAAgB,CAAC,IAAI;4BAC3B,OAAO,EAAE;gCACP;oCACE,KAAK,EAAE;wCACL,MAAM;wCACN,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE;qCAC9B;iCACF;gCACD,EAAE,IAAI,EAAE,MAAM,EAAE;6BACjB;yBACF;qBACF,IACE,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAC7D,eAAe,EAAE;wBACf,WAAW,EAAE,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,SAAS;wBACrC,SAAS,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,SAAS;qBAClC,IACD,CACH,CAAC;gBAEF,OAAO,IAAA,oCAA2B,EAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const generateEmbeddings: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
10
|
+
}>>;
|
|
11
|
+
inputText: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
12
|
+
embeddingPurpose: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
|
|
13
|
+
dimensions: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
14
|
+
normalize: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateEmbeddings = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
7
|
+
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const common_1 = require("../common");
|
|
10
|
+
exports.generateEmbeddings = (0, pieces_framework_1.createAction)({
|
|
11
|
+
auth: index_1.awsBedrockAuth,
|
|
12
|
+
name: 'generate_embeddings',
|
|
13
|
+
displayName: 'Generate Embeddings',
|
|
14
|
+
description: 'Generate vector embeddings from text using Amazon Titan Embed, Cohere Embed, or Amazon Nova Multimodal Embeddings models.',
|
|
15
|
+
props: {
|
|
16
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
17
|
+
displayName: 'Model',
|
|
18
|
+
required: true,
|
|
19
|
+
auth: index_1.awsBedrockAuth,
|
|
20
|
+
description: 'The embedding model to use.',
|
|
21
|
+
refreshers: [],
|
|
22
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
23
|
+
if (!auth) {
|
|
24
|
+
return {
|
|
25
|
+
disabled: true,
|
|
26
|
+
placeholder: 'Connect your AWS account first',
|
|
27
|
+
options: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return (0, common_1.getBedrockModelOptions)(auth.props, {
|
|
31
|
+
outputModality: client_bedrock_1.ModelModality.EMBEDDING,
|
|
32
|
+
});
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
inputText: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'Input Text',
|
|
37
|
+
required: true,
|
|
38
|
+
description: 'The text to generate embeddings for.',
|
|
39
|
+
}),
|
|
40
|
+
embeddingPurpose: pieces_framework_1.Property.StaticDropdown({
|
|
41
|
+
displayName: 'Embedding Purpose',
|
|
42
|
+
required: false,
|
|
43
|
+
description: 'Optimize embeddings for your use case. Only used by Nova Multimodal Embeddings.',
|
|
44
|
+
defaultValue: 'GENERIC_INDEX',
|
|
45
|
+
options: {
|
|
46
|
+
options: [
|
|
47
|
+
{ label: 'Generic Index', value: 'GENERIC_INDEX' },
|
|
48
|
+
{ label: 'Generic Retrieval', value: 'GENERIC_RETRIEVAL' },
|
|
49
|
+
{ label: 'Text Retrieval', value: 'TEXT_RETRIEVAL' },
|
|
50
|
+
{ label: 'Classification', value: 'CLASSIFICATION' },
|
|
51
|
+
{ label: 'Clustering', value: 'CLUSTERING' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
dimensions: pieces_framework_1.Property.Number({
|
|
56
|
+
displayName: 'Dimensions',
|
|
57
|
+
required: false,
|
|
58
|
+
description: 'The number of dimensions for the output embedding vector. Titan Embed v2: 256, 512, 1024. Nova Multimodal: 256, 384, 1024, 3072.',
|
|
59
|
+
}),
|
|
60
|
+
normalize: pieces_framework_1.Property.Checkbox({
|
|
61
|
+
displayName: 'Normalize',
|
|
62
|
+
required: false,
|
|
63
|
+
description: 'Whether to normalize the output embedding vector. Supported by Titan Embed v2.',
|
|
64
|
+
defaultValue: true,
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
run(_a) {
|
|
68
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue }) {
|
|
69
|
+
var _b;
|
|
70
|
+
const client = (0, common_1.createBedrockRuntimeClient)(auth.props);
|
|
71
|
+
const { model, inputText, dimensions, normalize } = propsValue;
|
|
72
|
+
const isTitan = model.startsWith('amazon.titan-embed');
|
|
73
|
+
const isCohere = model.startsWith('cohere.embed');
|
|
74
|
+
const isNova = model.includes('nova') && model.includes('embed');
|
|
75
|
+
const isTwelveLabs = model.startsWith('twelvelabs.');
|
|
76
|
+
let requestBody;
|
|
77
|
+
if (isNova) {
|
|
78
|
+
requestBody = {
|
|
79
|
+
schemaVersion: 'nova-multimodal-embed-v1',
|
|
80
|
+
taskType: 'SINGLE_EMBEDDING',
|
|
81
|
+
singleEmbeddingParams: Object.assign(Object.assign({ embeddingPurpose: (_b = propsValue.embeddingPurpose) !== null && _b !== void 0 ? _b : 'GENERIC_INDEX' }, (dimensions != null ? { embeddingDimension: dimensions } : {})), { text: {
|
|
82
|
+
truncationMode: 'END',
|
|
83
|
+
value: inputText,
|
|
84
|
+
} }),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else if (isTitan) {
|
|
88
|
+
requestBody = Object.assign(Object.assign({ inputText }, (dimensions != null ? { dimensions } : {})), (normalize != null ? { normalize } : {}));
|
|
89
|
+
}
|
|
90
|
+
else if (isCohere) {
|
|
91
|
+
requestBody = {
|
|
92
|
+
texts: [inputText],
|
|
93
|
+
input_type: 'search_document',
|
|
94
|
+
truncate: 'END',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
else if (isTwelveLabs) {
|
|
98
|
+
requestBody = {
|
|
99
|
+
inputType: 'text',
|
|
100
|
+
inputText,
|
|
101
|
+
textTruncate: 'end',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
requestBody = {
|
|
106
|
+
inputText,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const response = yield client.send(new client_bedrock_runtime_1.InvokeModelCommand({
|
|
111
|
+
modelId: model,
|
|
112
|
+
body: Buffer.from(JSON.stringify(requestBody)),
|
|
113
|
+
contentType: 'application/json',
|
|
114
|
+
accept: 'application/json',
|
|
115
|
+
}));
|
|
116
|
+
const responseBody = JSON.parse(new TextDecoder().decode(response.body));
|
|
117
|
+
let embedding;
|
|
118
|
+
if (responseBody.embedding) {
|
|
119
|
+
// Titan Embed / TwelveLabs format: { embedding: [floats] }
|
|
120
|
+
embedding = responseBody.embedding;
|
|
121
|
+
}
|
|
122
|
+
else if (responseBody.embeddings &&
|
|
123
|
+
responseBody.embeddings.length > 0) {
|
|
124
|
+
const first = responseBody.embeddings[0];
|
|
125
|
+
if (Array.isArray(first)) {
|
|
126
|
+
// Cohere v3 format: { embeddings: [[floats]] }
|
|
127
|
+
embedding = first;
|
|
128
|
+
}
|
|
129
|
+
else if (first === null || first === void 0 ? void 0 : first.embedding) {
|
|
130
|
+
// Nova format: { embeddings: [{ embedding: [floats] }] }
|
|
131
|
+
embedding = first.embedding;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!embedding) {
|
|
135
|
+
throw new Error('No embedding was returned by the model. The response format may not be supported.');
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
embedding,
|
|
139
|
+
dimensions: embedding.length,
|
|
140
|
+
model,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error instanceof Error && error.message.includes('No embedding')) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
throw new Error((0, common_1.formatBedrockError)(error));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=generate-embeddings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-embeddings.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/aws-bedrock/src/lib/actions/generate-embeddings.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,4EAAqE;AACrE,4DAAwD;AACxD,uCAA6C;AAC7C,sCAImB;AAEN,QAAA,kBAAkB,GAAG,IAAA,+BAAY,EAAC;IAC7C,IAAI,EAAE,sBAAc;IACpB,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EAAE,qBAAqB;IAClC,WAAW,EACT,2HAA2H;IAC7H,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,sBAAc;YACpB,WAAW,EAAE,6BAA6B;YAC1C,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;gBACtB,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,WAAW,EAAE,gCAAgC;wBAC7C,OAAO,EAAE,EAAE;qBACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAA,+BAAsB,EAAC,IAAI,CAAC,KAAK,EAAE;oBACxC,cAAc,EAAE,8BAAa,CAAC,SAAS;iBACxC,CAAC,CAAC;YACL,CAAC,CAAA;SACF,CAAC;QACF,SAAS,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC3B,WAAW,EAAE,YAAY;YACzB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,sCAAsC;SACpD,CAAC;QACF,gBAAgB,EAAE,2BAAQ,CAAC,cAAc,CAAC;YACxC,WAAW,EAAE,mBAAmB;YAChC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ACD,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const generateImage: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
10
|
+
}>>;
|
|
11
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
12
|
+
negativePrompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
13
|
+
width: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
14
|
+
height: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
15
|
+
seed: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
7
|
+
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const common_1 = require("../common");
|
|
10
|
+
exports.generateImage = (0, pieces_framework_1.createAction)({
|
|
11
|
+
auth: index_1.awsBedrockAuth,
|
|
12
|
+
name: 'generate_image',
|
|
13
|
+
displayName: 'Generate Image',
|
|
14
|
+
description: 'Generate an image from a text prompt using Amazon Titan Image Generator or Stability AI models.',
|
|
15
|
+
props: {
|
|
16
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
17
|
+
displayName: 'Model',
|
|
18
|
+
required: true,
|
|
19
|
+
auth: index_1.awsBedrockAuth,
|
|
20
|
+
description: 'The image generation model to use.',
|
|
21
|
+
refreshers: [],
|
|
22
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
23
|
+
if (!auth) {
|
|
24
|
+
return {
|
|
25
|
+
disabled: true,
|
|
26
|
+
placeholder: 'Connect your AWS account first',
|
|
27
|
+
options: [],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return (0, common_1.getBedrockModelOptions)(auth.props, {
|
|
31
|
+
outputModality: client_bedrock_1.ModelModality.IMAGE,
|
|
32
|
+
});
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'Prompt',
|
|
37
|
+
required: true,
|
|
38
|
+
description: 'A text description of the image you want to generate.',
|
|
39
|
+
}),
|
|
40
|
+
negativePrompt: pieces_framework_1.Property.LongText({
|
|
41
|
+
displayName: 'Negative Prompt',
|
|
42
|
+
required: false,
|
|
43
|
+
description: 'Describe what you do NOT want in the image. Helps refine the output.',
|
|
44
|
+
}),
|
|
45
|
+
width: pieces_framework_1.Property.Number({
|
|
46
|
+
displayName: 'Width',
|
|
47
|
+
required: false,
|
|
48
|
+
description: 'Image width in pixels. Must be supported by the model.',
|
|
49
|
+
defaultValue: 1024,
|
|
50
|
+
}),
|
|
51
|
+
height: pieces_framework_1.Property.Number({
|
|
52
|
+
displayName: 'Height',
|
|
53
|
+
required: false,
|
|
54
|
+
description: 'Image height in pixels. Must be supported by the model.',
|
|
55
|
+
defaultValue: 1024,
|
|
56
|
+
}),
|
|
57
|
+
seed: pieces_framework_1.Property.Number({
|
|
58
|
+
displayName: 'Seed',
|
|
59
|
+
required: false,
|
|
60
|
+
description: 'A seed for reproducible results. Use the same seed and prompt to get the same image.',
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
run(_a) {
|
|
64
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, files }) {
|
|
65
|
+
const client = (0, common_1.createBedrockRuntimeClient)(auth.props);
|
|
66
|
+
const { model, prompt, negativePrompt, width, height, seed } = propsValue;
|
|
67
|
+
const isTitan = model.startsWith('amazon.titan-image');
|
|
68
|
+
const isStability = model.startsWith('stability.');
|
|
69
|
+
const isNovaCanvas = model.startsWith('amazon.nova-canvas');
|
|
70
|
+
let requestBody;
|
|
71
|
+
if (isTitan) {
|
|
72
|
+
requestBody = {
|
|
73
|
+
taskType: 'TEXT_IMAGE',
|
|
74
|
+
textToImageParams: Object.assign({ text: prompt }, (negativePrompt ? { negativeText: negativePrompt } : {})),
|
|
75
|
+
imageGenerationConfig: Object.assign({ numberOfImages: 1, width: width !== null && width !== void 0 ? width : 1024, height: height !== null && height !== void 0 ? height : 1024 }, (seed != null ? { seed: seed } : {})),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
else if (isNovaCanvas) {
|
|
79
|
+
requestBody = {
|
|
80
|
+
taskType: 'TEXT_IMAGE',
|
|
81
|
+
textToImageParams: Object.assign({ text: prompt }, (negativePrompt ? { negativeText: negativePrompt } : {})),
|
|
82
|
+
imageGenerationConfig: Object.assign({ numberOfImages: 1, width: width !== null && width !== void 0 ? width : 1024, height: height !== null && height !== void 0 ? height : 1024 }, (seed != null ? { seed: seed } : {})),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else if (isStability) {
|
|
86
|
+
requestBody = Object.assign({ text_prompts: [
|
|
87
|
+
{ text: prompt, weight: 1 },
|
|
88
|
+
...(negativePrompt
|
|
89
|
+
? [{ text: negativePrompt, weight: -1 }]
|
|
90
|
+
: []),
|
|
91
|
+
], cfg_scale: 7, steps: 30, width: width !== null && width !== void 0 ? width : 1024, height: height !== null && height !== void 0 ? height : 1024 }, (seed != null ? { seed: seed } : {}));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
requestBody = Object.assign({ text_prompts: [
|
|
95
|
+
{ text: prompt, weight: 1 },
|
|
96
|
+
...(negativePrompt
|
|
97
|
+
? [{ text: negativePrompt, weight: -1 }]
|
|
98
|
+
: []),
|
|
99
|
+
], width: width !== null && width !== void 0 ? width : 1024, height: height !== null && height !== void 0 ? height : 1024 }, (seed != null ? { seed: seed } : {}));
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const response = yield client.send(new client_bedrock_runtime_1.InvokeModelCommand({
|
|
103
|
+
modelId: model,
|
|
104
|
+
body: Buffer.from(JSON.stringify(requestBody)),
|
|
105
|
+
contentType: 'application/json',
|
|
106
|
+
accept: 'application/json',
|
|
107
|
+
}));
|
|
108
|
+
const responseBody = JSON.parse(new TextDecoder().decode(response.body));
|
|
109
|
+
let base64Image;
|
|
110
|
+
if (responseBody.images && responseBody.images.length > 0) {
|
|
111
|
+
base64Image = responseBody.images[0];
|
|
112
|
+
}
|
|
113
|
+
else if (responseBody.artifacts &&
|
|
114
|
+
responseBody.artifacts.length > 0) {
|
|
115
|
+
base64Image = responseBody.artifacts[0].base64;
|
|
116
|
+
}
|
|
117
|
+
if (!base64Image) {
|
|
118
|
+
throw new Error('No image was returned by the model. The response format may not be supported.');
|
|
119
|
+
}
|
|
120
|
+
const imageBuffer = Buffer.from(base64Image, 'base64');
|
|
121
|
+
const file = yield files.write({
|
|
122
|
+
fileName: 'generated-image.png',
|
|
123
|
+
data: imageBuffer,
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
image: file,
|
|
127
|
+
model: model,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error instanceof Error && error.message.includes('No image')) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
throw new Error((0, common_1.formatBedrockError)(error));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=generate-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-image.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/aws-bedrock/src/lib/actions/generate-image.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,4EAAqE;AACrE,4DAAwD;AACxD,uCAA6C;AAC7C,sCAImB;AAEN,QAAA,aAAa,GAAG,IAAA,+BAAY,EAAC;IACxC,IAAI,EAAE,sBAAc;IACpB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EACT,iGAAiG;IACnG,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,sBAAc;YACpB,WAAW,EAAE,oCAAoC;YACjD,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;gBACtB,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,WAAW,EAAE,gCAAgC;wBAC7C,OAAO,EAAE,EAAE;qBACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAA,+BAAsB,EAAC,IAAI,CAAC,KAAK,EAAE;oBACxC,cAAc,EAAE,8BAAa,CAAC,KAAK;iBACpC,CAAC,CAAC;YACL,CAAC,CAAA;SACF,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACxB,WAAW,EAAE,QAAQ;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C,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC1D,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBACvC,CAAC;qBAAM,IACL,YAAY,CAAC,SAAS;oBACtB,YAAY,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EACjC,CAAC;oBACD,WAAW,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACjD,CAAC;gBAED,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;gBACJ,CAAC;gBAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;gBAEvD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC;oBAC7B,QAAQ,EAAE,qBAAqB;oBAC/B,IAAI,EAAE,WAAW;iBAClB,CAAC,CAAC;gBAEH,OAAO;oBACL,KAAK,EAAE,IAAI;oBACX,KAAK,EAAE,KAAK;iBACb,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;oBACjE,MAAM,KAAK,CAAC;gBACd,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const sendPrompt: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
3
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
4
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
accessKeyId: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
secretAccessKey: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
9
|
+
region: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
10
|
+
}>>;
|
|
11
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
12
|
+
systemPrompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
13
|
+
temperature: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
14
|
+
maxTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
15
|
+
topP: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
16
|
+
stopSequences: import("@activepieces/pieces-framework").ArrayProperty<false>;
|
|
17
|
+
memoryKey: import("@activepieces/pieces-framework").ShortTextProperty<false>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendPrompt = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
7
|
+
const index_1 = require("../../index");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.sendPrompt = (0, pieces_framework_1.createAction)({
|
|
10
|
+
auth: index_1.awsBedrockAuth,
|
|
11
|
+
name: 'send_prompt',
|
|
12
|
+
displayName: 'Ask Bedrock',
|
|
13
|
+
description: 'Send a text prompt to an Amazon Bedrock model.',
|
|
14
|
+
props: {
|
|
15
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
16
|
+
displayName: 'Model',
|
|
17
|
+
required: true,
|
|
18
|
+
auth: index_1.awsBedrockAuth,
|
|
19
|
+
description: 'The foundation model to use for generation.',
|
|
20
|
+
refreshers: [],
|
|
21
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
22
|
+
if (!auth) {
|
|
23
|
+
return {
|
|
24
|
+
disabled: true,
|
|
25
|
+
placeholder: 'Connect your AWS account first',
|
|
26
|
+
options: [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return (0, common_1.getBedrockModelOptions)(auth.props, { useInferenceProfiles: true });
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
33
|
+
displayName: 'Prompt',
|
|
34
|
+
required: true,
|
|
35
|
+
}),
|
|
36
|
+
systemPrompt: pieces_framework_1.Property.LongText({
|
|
37
|
+
displayName: 'System Prompt',
|
|
38
|
+
required: false,
|
|
39
|
+
description: 'Instructions that guide the model behavior.',
|
|
40
|
+
}),
|
|
41
|
+
temperature: pieces_framework_1.Property.Number({
|
|
42
|
+
displayName: 'Temperature',
|
|
43
|
+
required: false,
|
|
44
|
+
description: 'Controls randomness. Lower values produce more deterministic output.',
|
|
45
|
+
defaultValue: 0.7,
|
|
46
|
+
}),
|
|
47
|
+
maxTokens: pieces_framework_1.Property.Number({
|
|
48
|
+
displayName: 'Maximum Tokens',
|
|
49
|
+
required: false,
|
|
50
|
+
description: 'The maximum number of tokens to generate.',
|
|
51
|
+
defaultValue: 2048,
|
|
52
|
+
}),
|
|
53
|
+
topP: pieces_framework_1.Property.Number({
|
|
54
|
+
displayName: 'Top P',
|
|
55
|
+
required: false,
|
|
56
|
+
description: 'Nucleus sampling: the model considers tokens with top_p probability mass.',
|
|
57
|
+
defaultValue: 1,
|
|
58
|
+
}),
|
|
59
|
+
stopSequences: pieces_framework_1.Property.Array({
|
|
60
|
+
displayName: 'Stop Sequences',
|
|
61
|
+
required: false,
|
|
62
|
+
description: 'Sequences that will cause the model to stop generating. Up to 4 sequences.',
|
|
63
|
+
}),
|
|
64
|
+
memoryKey: pieces_framework_1.Property.ShortText({
|
|
65
|
+
displayName: 'Memory Key',
|
|
66
|
+
required: false,
|
|
67
|
+
description: 'A memory key that will keep the chat history shared across runs and flows. Keep it empty to leave the model without memory of previous messages.',
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
run(_a) {
|
|
71
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, store }) {
|
|
72
|
+
var _b, _c;
|
|
73
|
+
const client = (0, common_1.createBedrockRuntimeClient)(auth.props);
|
|
74
|
+
const { model, prompt, systemPrompt, temperature, maxTokens, topP, stopSequences, memoryKey, } = propsValue;
|
|
75
|
+
let messageHistory = [];
|
|
76
|
+
if (memoryKey) {
|
|
77
|
+
messageHistory =
|
|
78
|
+
(_b = (yield store.get(memoryKey, pieces_framework_1.StoreScope.PROJECT))) !== null && _b !== void 0 ? _b : [];
|
|
79
|
+
}
|
|
80
|
+
messageHistory.push({
|
|
81
|
+
role: client_bedrock_runtime_1.ConversationRole.USER,
|
|
82
|
+
content: [{ text: prompt }],
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
const response = yield client.send(new client_bedrock_runtime_1.ConverseCommand(Object.assign(Object.assign({ modelId: model, messages: messageHistory }, (systemPrompt ? { system: [{ text: systemPrompt }] } : {})), { inferenceConfig: {
|
|
86
|
+
temperature: temperature !== null && temperature !== void 0 ? temperature : undefined,
|
|
87
|
+
maxTokens: maxTokens !== null && maxTokens !== void 0 ? maxTokens : undefined,
|
|
88
|
+
topP: topP !== null && topP !== void 0 ? topP : undefined,
|
|
89
|
+
stopSequences: stopSequences && stopSequences.length > 0
|
|
90
|
+
? stopSequences
|
|
91
|
+
: undefined,
|
|
92
|
+
} })));
|
|
93
|
+
const outputMessage = (_c = response.output) === null || _c === void 0 ? void 0 : _c.message;
|
|
94
|
+
if (outputMessage) {
|
|
95
|
+
messageHistory.push(outputMessage);
|
|
96
|
+
}
|
|
97
|
+
if (memoryKey) {
|
|
98
|
+
yield store.put(memoryKey, messageHistory, pieces_framework_1.StoreScope.PROJECT);
|
|
99
|
+
}
|
|
100
|
+
return (0, common_1.extractConverseTextResponse)(response);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new Error((0, common_1.formatBedrockError)(error));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
//# sourceMappingURL=send-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-prompt.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/aws-bedrock/src/lib/actions/send-prompt.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,4EAIyC;AACzC,uCAA6C;AAC7C,sCAKmB;AAEN,QAAA,UAAU,GAAG,IAAA,+BAAY,EAAC;IACrC,IAAI,EAAE,sBAAc;IACpB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,gDAAgD;IAC7D,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,sBAAc;YACpB,WAAW,EAAE,6CAA6C;YAC1D,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;gBACtB,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,WAAW,EAAE,gCAAgC;wBAC7C,OAAO,EAAE,EAAE;qBACZ,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAA,+BAAsB,EAAC,IAAI,CAAC,KAAK,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5E,CAAC,CAAA;SACF,CAAC;QACF,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,OAAO,CAAC,CAAC;gBACjE,CAAC;gBAED,OAAO,IAAA,oCAA2B,EAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,IAAA,2BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BedrockClient, ModelModality } from '@aws-sdk/client-bedrock';
|
|
2
|
+
import { BedrockRuntimeClient, ConverseResponse } from '@aws-sdk/client-bedrock-runtime';
|
|
3
|
+
export interface BedrockAuth {
|
|
4
|
+
accessKeyId: string;
|
|
5
|
+
secretAccessKey: string;
|
|
6
|
+
region: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createBedrockClient(auth: BedrockAuth): BedrockClient;
|
|
9
|
+
export declare function createBedrockRuntimeClient(auth: BedrockAuth): BedrockRuntimeClient;
|
|
10
|
+
export declare function getBedrockModelOptions(auth: BedrockAuth | undefined, filters?: {
|
|
11
|
+
inputModality?: ModelModality;
|
|
12
|
+
outputModality?: ModelModality;
|
|
13
|
+
showAll?: boolean;
|
|
14
|
+
useInferenceProfiles?: boolean;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
placeholder: string;
|
|
18
|
+
options: never[];
|
|
19
|
+
} | {
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
options: {
|
|
22
|
+
label: string;
|
|
23
|
+
value: string;
|
|
24
|
+
}[];
|
|
25
|
+
placeholder?: undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function extractConverseTextResponse(response: ConverseResponse): {
|
|
28
|
+
text: string;
|
|
29
|
+
stopReason: import("@aws-sdk/client-bedrock-runtime").StopReason | undefined;
|
|
30
|
+
usage: import("@aws-sdk/client-bedrock-runtime").TokenUsage | undefined;
|
|
31
|
+
latencyMs: number | undefined;
|
|
32
|
+
};
|
|
33
|
+
export declare function formatBedrockError(error: unknown): string;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBedrockClient = createBedrockClient;
|
|
4
|
+
exports.createBedrockRuntimeClient = createBedrockRuntimeClient;
|
|
5
|
+
exports.getBedrockModelOptions = getBedrockModelOptions;
|
|
6
|
+
exports.extractConverseTextResponse = extractConverseTextResponse;
|
|
7
|
+
exports.formatBedrockError = formatBedrockError;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
10
|
+
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
11
|
+
function createBedrockClient(auth) {
|
|
12
|
+
return new client_bedrock_1.BedrockClient({
|
|
13
|
+
credentials: {
|
|
14
|
+
accessKeyId: auth.accessKeyId,
|
|
15
|
+
secretAccessKey: auth.secretAccessKey,
|
|
16
|
+
},
|
|
17
|
+
region: auth.region,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function createBedrockRuntimeClient(auth) {
|
|
21
|
+
return new client_bedrock_runtime_1.BedrockRuntimeClient({
|
|
22
|
+
credentials: {
|
|
23
|
+
accessKeyId: auth.accessKeyId,
|
|
24
|
+
secretAccessKey: auth.secretAccessKey,
|
|
25
|
+
},
|
|
26
|
+
region: auth.region,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function getBedrockModelOptions(auth, filters) {
|
|
30
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
if (!auth) {
|
|
33
|
+
return {
|
|
34
|
+
disabled: true,
|
|
35
|
+
placeholder: 'Connect your AWS account first',
|
|
36
|
+
options: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const client = createBedrockClient(auth);
|
|
41
|
+
if (filters === null || filters === void 0 ? void 0 : filters.useInferenceProfiles) {
|
|
42
|
+
const [profileResponse, modelsResponse] = yield Promise.all([
|
|
43
|
+
client.send(new client_bedrock_1.ListInferenceProfilesCommand({
|
|
44
|
+
typeEquals: 'SYSTEM_DEFINED',
|
|
45
|
+
})),
|
|
46
|
+
(filters === null || filters === void 0 ? void 0 : filters.inputModality)
|
|
47
|
+
? client.send(new client_bedrock_1.ListFoundationModelsCommand({}))
|
|
48
|
+
: Promise.resolve(undefined),
|
|
49
|
+
]);
|
|
50
|
+
const profiles = (_a = profileResponse.inferenceProfileSummaries) !== null && _a !== void 0 ? _a : [];
|
|
51
|
+
let allowedModelIds;
|
|
52
|
+
if ((filters === null || filters === void 0 ? void 0 : filters.inputModality) && modelsResponse) {
|
|
53
|
+
const allModels = (_b = modelsResponse.modelSummaries) !== null && _b !== void 0 ? _b : [];
|
|
54
|
+
allowedModelIds = new Set(allModels
|
|
55
|
+
.filter((m) => { var _a; return (_a = m.inputModalities) === null || _a === void 0 ? void 0 : _a.includes(filters.inputModality); })
|
|
56
|
+
.map((m) => m.modelId)
|
|
57
|
+
.filter(Boolean));
|
|
58
|
+
}
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
const deduped = profiles.filter((p) => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
if (!p.inferenceProfileId || p.status !== 'ACTIVE')
|
|
63
|
+
return false;
|
|
64
|
+
if (seen.has(p.inferenceProfileId))
|
|
65
|
+
return false;
|
|
66
|
+
if (allowedModelIds) {
|
|
67
|
+
const profileModelId = (_c = (_b = (_a = p.models) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.modelArn) === null || _c === void 0 ? void 0 : _c.split('/').pop();
|
|
68
|
+
if (!profileModelId || !allowedModelIds.has(profileModelId)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
seen.add(p.inferenceProfileId);
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
disabled: false,
|
|
77
|
+
options: deduped.map((p) => {
|
|
78
|
+
var _a;
|
|
79
|
+
return ({
|
|
80
|
+
label: (_a = p.inferenceProfileName) !== null && _a !== void 0 ? _a : p.inferenceProfileId,
|
|
81
|
+
value: p.inferenceProfileId,
|
|
82
|
+
});
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const response = yield client.send(new client_bedrock_1.ListFoundationModelsCommand({
|
|
87
|
+
byOutputModality: (filters === null || filters === void 0 ? void 0 : filters.showAll)
|
|
88
|
+
? undefined
|
|
89
|
+
: ((_c = filters === null || filters === void 0 ? void 0 : filters.outputModality) !== null && _c !== void 0 ? _c : client_bedrock_1.ModelModality.TEXT),
|
|
90
|
+
}));
|
|
91
|
+
const models = (_d = response.modelSummaries) !== null && _d !== void 0 ? _d : [];
|
|
92
|
+
const filtered = (filters === null || filters === void 0 ? void 0 : filters.inputModality)
|
|
93
|
+
? models.filter((m) => { var _a; return (_a = m.inputModalities) === null || _a === void 0 ? void 0 : _a.includes(filters.inputModality); })
|
|
94
|
+
: models;
|
|
95
|
+
const seen = new Set();
|
|
96
|
+
const deduped = filtered.filter((m) => {
|
|
97
|
+
if (!m.modelId)
|
|
98
|
+
return false;
|
|
99
|
+
const baseId = m.modelId.replace(/:\d+:.*$/, '');
|
|
100
|
+
if (seen.has(baseId))
|
|
101
|
+
return false;
|
|
102
|
+
seen.add(baseId);
|
|
103
|
+
return true;
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
disabled: false,
|
|
107
|
+
options: deduped.map((m) => ({
|
|
108
|
+
label: `${m.providerName} - ${m.modelName}`,
|
|
109
|
+
value: m.modelId,
|
|
110
|
+
})),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
disabled: true,
|
|
116
|
+
options: [],
|
|
117
|
+
placeholder: 'Failed to load models. Check your credentials.',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function extractConverseTextResponse(response) {
|
|
123
|
+
var _a, _b, _c;
|
|
124
|
+
const outputMessage = (_a = response.output) === null || _a === void 0 ? void 0 : _a.message;
|
|
125
|
+
const textContent = (_b = outputMessage === null || outputMessage === void 0 ? void 0 : outputMessage.content) === null || _b === void 0 ? void 0 : _b.filter((block) => 'text' in block).map((block) => block.text).join('');
|
|
126
|
+
return {
|
|
127
|
+
text: textContent !== null && textContent !== void 0 ? textContent : '',
|
|
128
|
+
stopReason: response.stopReason,
|
|
129
|
+
usage: response.usage,
|
|
130
|
+
latencyMs: (_c = response.metrics) === null || _c === void 0 ? void 0 : _c.latencyMs,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function formatBedrockError(error) {
|
|
134
|
+
var _a, _b, _c;
|
|
135
|
+
const err = error;
|
|
136
|
+
const name = (_a = err.name) !== null && _a !== void 0 ? _a : 'UnknownError';
|
|
137
|
+
switch (name) {
|
|
138
|
+
case 'ThrottlingException':
|
|
139
|
+
return 'Request was throttled by AWS Bedrock. Please try again in a moment.';
|
|
140
|
+
case 'ModelNotReadyException':
|
|
141
|
+
return 'The model is not ready. It may still be loading — please try again shortly.';
|
|
142
|
+
case 'ModelTimeoutException':
|
|
143
|
+
return 'The model timed out while processing your request. Try a shorter prompt or a different model.';
|
|
144
|
+
case 'ModelErrorException':
|
|
145
|
+
return 'The model encountered an internal error. Try again or use a different model.';
|
|
146
|
+
case 'AccessDeniedException':
|
|
147
|
+
return 'Access denied. Ensure your AWS credentials have permission to invoke this model and that the model is enabled in your region.';
|
|
148
|
+
case 'ValidationException':
|
|
149
|
+
return `Validation error: ${(_b = err.message) !== null && _b !== void 0 ? _b : 'Check your input parameters.'}`;
|
|
150
|
+
case 'ServiceUnavailableException':
|
|
151
|
+
return 'AWS Bedrock is temporarily unavailable. Please try again later.';
|
|
152
|
+
case 'ServiceQuotaExceededException':
|
|
153
|
+
return 'You have exceeded your AWS Bedrock service quota.';
|
|
154
|
+
default:
|
|
155
|
+
return (_c = err.message) !== null && _c !== void 0 ? _c : 'An unexpected error occurred.';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/community/aws-bedrock/src/lib/common.ts"],"names":[],"mappings":";;AAiBA,kDAQC;AAED,gEAUC;AAED,wDA4GC;AAED,kEAaC;AAED,gDAwBC;;AA5LD,4DAKiC;AACjC,4EAGyC;AAQzC,SAAgB,mBAAmB,CAAC,IAAiB;IACnD,OAAO,IAAI,8BAAa,CAAC;QACvB,WAAW,EAAE;YACX,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC;QACD,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAAiB;IAEjB,OAAO,IAAI,6CAAoB,CAAC;QAC9B,WAAW,EAAE;YACX,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC;QACD,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC;AACL,CAAC;AAED,SAAsB,sBAAsB,CAC1C,IAA6B,EAC7B,OAKC;;;QAED,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,gCAAgC;gBAC7C,OAAO,EAAE,EAAE;aACZ,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAEzC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE,CAAC;gBAClC,MAAM,CAAC,eAAe,EAAE,cAAc,CAAC,GAAG,MA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