@avalant/piece-promptx-claude 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 +39 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +87 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/ask-claude.d.ts +15 -0
- package/src/lib/actions/ask-claude.js +254 -0
- package/src/lib/actions/ask-claude.js.map +1 -0
- package/src/lib/actions/extract-structured-data.d.ts +13 -0
- package/src/lib/actions/extract-structured-data.js +279 -0
- package/src/lib/actions/extract-structured-data.js.map +1 -0
- package/src/lib/common/common.d.ts +53 -0
- package/src/lib/common/common.js +133 -0
- package/src/lib/common/common.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@avalant/piece-promptx-claude",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@ai-sdk/anthropic": "1.2.12",
|
|
6
|
+
"@ai-sdk/openai": "1.3.22",
|
|
7
|
+
"@ai-sdk/replicate": "0.2.8",
|
|
8
|
+
"@anthropic-ai/sdk": "0.39.0",
|
|
9
|
+
"@sinclair/typebox": "0.34.11",
|
|
10
|
+
"ai": "4.3.16",
|
|
11
|
+
"ajv": "8.12.0",
|
|
12
|
+
"axios": "1.8.3",
|
|
13
|
+
"axios-retry": "4.4.1",
|
|
14
|
+
"deepmerge-ts": "7.1.0",
|
|
15
|
+
"fast-glob": "3.3.3",
|
|
16
|
+
"mime-types": "2.1.35",
|
|
17
|
+
"nanoid": "3.3.8",
|
|
18
|
+
"semver": "7.6.0",
|
|
19
|
+
"zod": "3.25.53",
|
|
20
|
+
"@activepieces/pieces-common": "0.4.9",
|
|
21
|
+
"@activepieces/pieces-framework": "0.14.0",
|
|
22
|
+
"@activepieces/shared": "0.12.0",
|
|
23
|
+
"tslib": "2.8.1"
|
|
24
|
+
},
|
|
25
|
+
"overrides": {
|
|
26
|
+
"@tryfabric/martian": {
|
|
27
|
+
"@notionhq/client": "$@notionhq/client"
|
|
28
|
+
},
|
|
29
|
+
"vite": {
|
|
30
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"resolutions": {
|
|
34
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
35
|
+
},
|
|
36
|
+
"main": "./src/index.js",
|
|
37
|
+
"type": "commonjs",
|
|
38
|
+
"types": "./src/index.d.ts"
|
|
39
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const promptxAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
3
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const avalantAnthropicClaude: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
7
|
+
server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
8
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
9
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
10
|
+
}>>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.avalantAnthropicClaude = exports.promptxAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const ask_claude_1 = require("./lib/actions/ask-claude");
|
|
7
|
+
const common_1 = require("./lib/common/common");
|
|
8
|
+
const extract_structured_data_1 = require("./lib/actions/extract-structured-data");
|
|
9
|
+
const shared_1 = require("@activepieces/shared");
|
|
10
|
+
exports.promptxAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
11
|
+
required: true,
|
|
12
|
+
props: {
|
|
13
|
+
server: pieces_framework_1.Property.StaticDropdown({
|
|
14
|
+
displayName: 'Server',
|
|
15
|
+
options: {
|
|
16
|
+
options: [
|
|
17
|
+
{
|
|
18
|
+
label: common_1.Production,
|
|
19
|
+
value: common_1.Production,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: common_1.Test,
|
|
23
|
+
value: common_1.Test,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
required: true,
|
|
28
|
+
defaultValue: common_1.Production,
|
|
29
|
+
}),
|
|
30
|
+
username: pieces_framework_1.Property.ShortText({
|
|
31
|
+
displayName: 'Username',
|
|
32
|
+
description: "PromptX username",
|
|
33
|
+
required: true,
|
|
34
|
+
}),
|
|
35
|
+
password: pieces_framework_1.PieceAuth.SecretText({
|
|
36
|
+
displayName: 'Password',
|
|
37
|
+
description: "PromptX password",
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
42
|
+
const { username, password } = auth;
|
|
43
|
+
if (!username || !password) {
|
|
44
|
+
return {
|
|
45
|
+
valid: false,
|
|
46
|
+
error: 'Empty Username or Password',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const response = yield fetch(common_1.baseUrlMap[auth.server]['loginUrl'], {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
body: new URLSearchParams({
|
|
52
|
+
username: username,
|
|
53
|
+
password: password,
|
|
54
|
+
}).toString(),
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (response.status === 200) {
|
|
60
|
+
return {
|
|
61
|
+
valid: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const data = yield response.json();
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
error: (data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.message),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
exports.avalantAnthropicClaude = (0, pieces_framework_1.createPiece)({
|
|
74
|
+
displayName: 'PromptX Claude',
|
|
75
|
+
description: 'Talk to Anthropic Claude AI tweaked for PromptX platform',
|
|
76
|
+
auth: exports.promptxAuth,
|
|
77
|
+
minimumSupportedRelease: '0.36.1',
|
|
78
|
+
logoUrl: 'https://cdn.activepieces.com/pieces/claude.png',
|
|
79
|
+
categories: [shared_1.PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
80
|
+
authors: [],
|
|
81
|
+
actions: [
|
|
82
|
+
ask_claude_1.askClaude,
|
|
83
|
+
extract_structured_data_1.extractStructuredDataAction,
|
|
84
|
+
],
|
|
85
|
+
triggers: [],
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/promptx-claude/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,yDAAqD;AACrD,gDAI6B;AAC7B,mFAAoF;AACpF,iDAAqD;AAExC,QAAA,WAAW,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC9C,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,MAAM,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAC9B,WAAW,EAAE,QAAQ;YACrB,OAAO,EAAE;gBACP,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,mBAAU;wBACjB,KAAK,EAAE,mBAAU;qBAClB;oBACD;wBACE,KAAK,EAAE,aAAI;wBACX,KAAK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KAAK,MAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAA;aACpC,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC;AACU,QAAA,sBAAsB,GAAG,IAAA,8BAAW,EAAC;IAChD,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EAAE,0DAA0D;IACvE,IAAI,EAAE,mBAAW;IACjB,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,gDAAgD;IACzD,UAAU,EAAE,CAAC,sBAAa,CAAC,uBAAuB,CAAC;IACnD,OAAO,EAAE,EAAE;IACX,OAAO,EAAE;QACP,sBAAS;QACT,qDAA2B;KAC5B;IACD,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const askClaude: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
3
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
7
|
+
systemPrompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
8
|
+
temperature: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
9
|
+
maxTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
10
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
11
|
+
image: import("@activepieces/pieces-framework").FileProperty<false>;
|
|
12
|
+
roles: import("@activepieces/pieces-framework").JsonProperty<false>;
|
|
13
|
+
thinkingMode: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
14
|
+
thinkingModeParams: import("@activepieces/pieces-framework").DynamicProperties<false>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.askClaude = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const sdk_1 = tslib_1.__importDefault(require("@anthropic-ai/sdk"));
|
|
7
|
+
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
10
|
+
const common_1 = require("../common/common");
|
|
11
|
+
const index_1 = require("../../index");
|
|
12
|
+
const DEFAULT_TOKENS_FOR_THINKING_MODE = 1024;
|
|
13
|
+
exports.askClaude = (0, pieces_framework_1.createAction)({
|
|
14
|
+
auth: index_1.promptxAuth,
|
|
15
|
+
name: 'ask_claude',
|
|
16
|
+
displayName: 'Ask Claude',
|
|
17
|
+
description: 'Ask Claude anything you want!',
|
|
18
|
+
props: {
|
|
19
|
+
model: pieces_framework_1.Property.StaticDropdown({
|
|
20
|
+
displayName: 'Model',
|
|
21
|
+
required: true,
|
|
22
|
+
description: 'The model which will generate the completion. Some models are suitable for natural language tasks, others specialize in code.',
|
|
23
|
+
defaultValue: 'claude-3-haiku-20240307',
|
|
24
|
+
options: {
|
|
25
|
+
disabled: false,
|
|
26
|
+
options: [
|
|
27
|
+
{ value: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku' },
|
|
28
|
+
{ value: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet' },
|
|
29
|
+
{ value: 'claude-3-opus-20240229', label: 'Claude 3 Opus' },
|
|
30
|
+
{ value: 'claude-3-5-sonnet-latest', label: 'Claude 3.5 Sonnet' },
|
|
31
|
+
{ value: 'claude-3-5-haiku-latest', label: 'Claude 3.5 Haiku' },
|
|
32
|
+
{ value: 'claude-3-7-sonnet-latest', label: 'Claude 3.7 Sonnet' },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
systemPrompt: pieces_framework_1.Property.LongText({
|
|
37
|
+
displayName: 'System Prompt',
|
|
38
|
+
required: false,
|
|
39
|
+
defaultValue: "You're a helpful assistant.",
|
|
40
|
+
}),
|
|
41
|
+
temperature: pieces_framework_1.Property.Number({
|
|
42
|
+
displayName: 'Temperature',
|
|
43
|
+
required: false,
|
|
44
|
+
description: 'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',
|
|
45
|
+
}),
|
|
46
|
+
maxTokens: pieces_framework_1.Property.Number({
|
|
47
|
+
displayName: 'Maximum Tokens',
|
|
48
|
+
required: false,
|
|
49
|
+
description: "The maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion, don't set the value to maximum and leave some tokens for the input. The exact limit varies by model. (One token is roughly 4 characters for normal English text)",
|
|
50
|
+
}),
|
|
51
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
52
|
+
displayName: 'Question',
|
|
53
|
+
required: true,
|
|
54
|
+
}),
|
|
55
|
+
image: pieces_framework_1.Property.File({
|
|
56
|
+
displayName: 'Image (URL)',
|
|
57
|
+
required: false,
|
|
58
|
+
description: 'URL of image to be used as input for the model.',
|
|
59
|
+
}),
|
|
60
|
+
roles: pieces_framework_1.Property.Json({
|
|
61
|
+
displayName: 'Roles',
|
|
62
|
+
required: false,
|
|
63
|
+
description: `Array of roles to specify more accurate response.Please check [guide to Input Messages](https://docs.anthropic.com/en/api/messages-examples#vision).`,
|
|
64
|
+
}),
|
|
65
|
+
thinkingMode: pieces_framework_1.Property.Checkbox({
|
|
66
|
+
displayName: 'Extended Thinking Mode',
|
|
67
|
+
required: false,
|
|
68
|
+
defaultValue: false,
|
|
69
|
+
description: 'Uses claude 3.7 sonnet enhanced reasoning capabilities for complex tasks.',
|
|
70
|
+
}),
|
|
71
|
+
thinkingModeParams: pieces_framework_1.Property.DynamicProperties({
|
|
72
|
+
displayName: '',
|
|
73
|
+
refreshers: ['thinkingMode'],
|
|
74
|
+
required: false,
|
|
75
|
+
props: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, thinkingMode }) {
|
|
76
|
+
if (!auth || !thinkingMode)
|
|
77
|
+
return {};
|
|
78
|
+
const props = {};
|
|
79
|
+
props['budgetTokens'] = pieces_framework_1.Property.Number({
|
|
80
|
+
displayName: 'Budget Tokens',
|
|
81
|
+
required: true,
|
|
82
|
+
defaultValue: DEFAULT_TOKENS_FOR_THINKING_MODE,
|
|
83
|
+
description: 'This parameter determines the maximum number of tokens Claude is allowed to use for its internal reasoning process.Your budget tokens must always be less than the max tokens specified.',
|
|
84
|
+
});
|
|
85
|
+
return props;
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
run(_a) {
|
|
90
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, flows, store, project }) {
|
|
91
|
+
var _b, _c, _d, _e;
|
|
92
|
+
const { server, username, password } = auth;
|
|
93
|
+
const accessToken = yield (0, common_1.getAccessToken)(server, username, password);
|
|
94
|
+
//get store data
|
|
95
|
+
const { userId, apiKey } = yield (0, common_1.getStoreData)(store, server, accessToken);
|
|
96
|
+
const usage = yield (0, common_1.getUsagePlan)(server, accessToken);
|
|
97
|
+
//check token is available
|
|
98
|
+
if (propsValue.maxTokens && propsValue.maxTokens > usage.token_available) {
|
|
99
|
+
throw new Error(common_1.billingIssueMessage);
|
|
100
|
+
}
|
|
101
|
+
yield pieces_common_1.propsValidation.validateZod(propsValue, {
|
|
102
|
+
temperature: zod_1.z.number().min(0).max(1.0).optional(),
|
|
103
|
+
});
|
|
104
|
+
const anthropic = new sdk_1.default({
|
|
105
|
+
apiKey: `${apiKey}`,
|
|
106
|
+
});
|
|
107
|
+
let billingIssue = false;
|
|
108
|
+
let unauthorized = false;
|
|
109
|
+
let model = 'claude-3-haiku-20240307';
|
|
110
|
+
if (propsValue.model) {
|
|
111
|
+
model = propsValue.model;
|
|
112
|
+
}
|
|
113
|
+
let temperature = 0.5;
|
|
114
|
+
if (propsValue.temperature) {
|
|
115
|
+
temperature = Number(propsValue.temperature);
|
|
116
|
+
}
|
|
117
|
+
// is token available less than 1000, will use as maxToken
|
|
118
|
+
let maxTokens = usage.token_available > 1000 ? 1000 : usage.token_available;
|
|
119
|
+
if (propsValue.maxTokens) {
|
|
120
|
+
maxTokens = Number(propsValue.maxTokens);
|
|
121
|
+
}
|
|
122
|
+
let systemPrompt = 'You are a helpful assistant.';
|
|
123
|
+
if (propsValue.systemPrompt) {
|
|
124
|
+
systemPrompt = propsValue.systemPrompt;
|
|
125
|
+
}
|
|
126
|
+
const rolesArray = propsValue.roles
|
|
127
|
+
? propsValue.roles
|
|
128
|
+
: [];
|
|
129
|
+
const rolesEnum = ['user', 'assistant'];
|
|
130
|
+
const roles = rolesArray.map((item) => {
|
|
131
|
+
if (!rolesEnum.includes(item.role)) {
|
|
132
|
+
throw new Error('The only available roles are: [user, assistant]');
|
|
133
|
+
}
|
|
134
|
+
return item;
|
|
135
|
+
});
|
|
136
|
+
const defaultMimeType = 'image/jpeg';
|
|
137
|
+
roles.unshift({
|
|
138
|
+
role: 'user',
|
|
139
|
+
content: [
|
|
140
|
+
{
|
|
141
|
+
type: 'text',
|
|
142
|
+
text: propsValue['prompt'],
|
|
143
|
+
},
|
|
144
|
+
...(propsValue.image
|
|
145
|
+
? [
|
|
146
|
+
{
|
|
147
|
+
type: 'image',
|
|
148
|
+
source: {
|
|
149
|
+
type: 'base64',
|
|
150
|
+
media_type: propsValue.image.extension
|
|
151
|
+
? mime_types_1.default.lookup(propsValue.image.extension) || defaultMimeType
|
|
152
|
+
: defaultMimeType,
|
|
153
|
+
data: propsValue.image.base64,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
]
|
|
157
|
+
: []),
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
const maxRetries = 4;
|
|
161
|
+
let retries = 0;
|
|
162
|
+
let response;
|
|
163
|
+
let responseWithTokens;
|
|
164
|
+
while (retries < maxRetries) {
|
|
165
|
+
try {
|
|
166
|
+
if (propsValue.thinkingMode) {
|
|
167
|
+
const budgetTokens = propsValue.thinkingModeParams
|
|
168
|
+
? propsValue.thinkingModeParams['budgetTokens']
|
|
169
|
+
: 1024;
|
|
170
|
+
const req = yield anthropic.messages.create({
|
|
171
|
+
model: model !== null && model !== void 0 ? model : 'claude-3-7-sonnet-20250219',
|
|
172
|
+
max_tokens: maxTokens,
|
|
173
|
+
system: systemPrompt,
|
|
174
|
+
thinking: {
|
|
175
|
+
type: 'enabled',
|
|
176
|
+
budget_tokens: budgetTokens !== null && budgetTokens !== void 0 ? budgetTokens : DEFAULT_TOKENS_FOR_THINKING_MODE,
|
|
177
|
+
},
|
|
178
|
+
messages: roles,
|
|
179
|
+
});
|
|
180
|
+
responseWithTokens = req;
|
|
181
|
+
response = req.content
|
|
182
|
+
.filter((block) => block.type === 'text')[0]
|
|
183
|
+
.text.trim();
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const req = yield (anthropic === null || anthropic === void 0 ? void 0 : anthropic.messages.create({
|
|
187
|
+
model: model,
|
|
188
|
+
max_tokens: maxTokens,
|
|
189
|
+
temperature: temperature,
|
|
190
|
+
system: systemPrompt,
|
|
191
|
+
messages: roles,
|
|
192
|
+
}));
|
|
193
|
+
responseWithTokens = req;
|
|
194
|
+
response = (_b = (req === null || req === void 0 ? void 0 : req.content[0]).text) === null || _b === void 0 ? void 0 : _b.trim();
|
|
195
|
+
}
|
|
196
|
+
if (responseWithTokens) {
|
|
197
|
+
const inputTokens = responseWithTokens.usage.input_tokens;
|
|
198
|
+
const outputTokens = responseWithTokens.usage.output_tokens;
|
|
199
|
+
const totalTokens = inputTokens + outputTokens;
|
|
200
|
+
yield (0, common_1.addTokenUsage)({
|
|
201
|
+
userId: `${userId}`,
|
|
202
|
+
model: responseWithTokens.model, // 'claude-3-5-sonnet-20240620',
|
|
203
|
+
projectId: project.id,
|
|
204
|
+
flowId: flows.current.id,
|
|
205
|
+
component: 'Automationx',
|
|
206
|
+
usage: {
|
|
207
|
+
inputTokens,
|
|
208
|
+
outputTokens,
|
|
209
|
+
totalTokens,
|
|
210
|
+
},
|
|
211
|
+
}, server, accessToken);
|
|
212
|
+
}
|
|
213
|
+
break; // Break out of the loop if the request is successful
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
if ((_c = e === null || e === void 0 ? void 0 : e.type) === null || _c === void 0 ? void 0 : _c.includes('rate_limit_error')) {
|
|
217
|
+
billingIssue = true;
|
|
218
|
+
if (retries + 1 === maxRetries) {
|
|
219
|
+
throw e;
|
|
220
|
+
}
|
|
221
|
+
// Calculate the time delay for the next retry using exponential backoff
|
|
222
|
+
const delay = Math.pow(6, retries) * 1000;
|
|
223
|
+
console.log(`Retrying in ${delay} milliseconds...`);
|
|
224
|
+
yield sleep(delay); // Wait for the calculated delay
|
|
225
|
+
retries++;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if ((_e = (_d = e === null || e === void 0 ? void 0 : e.error) === null || _d === void 0 ? void 0 : _d.type) === null || _e === void 0 ? void 0 : _e.includes('not_found_error')) {
|
|
230
|
+
unauthorized = true;
|
|
231
|
+
throw e;
|
|
232
|
+
}
|
|
233
|
+
const new_error = e;
|
|
234
|
+
throw e;
|
|
235
|
+
// throw {
|
|
236
|
+
// error: new_error.error.message,
|
|
237
|
+
// };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (billingIssue) {
|
|
242
|
+
throw new Error(common_1.billingIssueMessage);
|
|
243
|
+
}
|
|
244
|
+
if (unauthorized) {
|
|
245
|
+
throw new Error(common_1.unauthorizedMessage);
|
|
246
|
+
}
|
|
247
|
+
return response;
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
function sleep(ms) {
|
|
252
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=ask-claude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-claude.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-claude/src/lib/actions/ask-claude.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,oEAA0C;AAC1C,oEAA8B;AAE9B,6BAAwB;AACxB,+DAA8D;AAC9D,6CAO0B;AAC1B,uCAA0C;AAC1C,MAAM,gCAAgC,GAAG,IAAI,CAAC;AACjC,QAAA,SAAS,GAAG,IAAA,+BAAY,EAAC;IACpC,IAAI,EAAE,mBAAW;IACjB,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,+BAA+B;IAC5C,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAC7B,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,+HAA+H;YACjI,YAAY,EAAE,yBAAyB;YACvC,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACP,EAAE,KAAK,EAAE,yBAAyB,EAAE,KAAK,EAAE,gBAAgB,EAAE;oBAC7D,EAAE,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,iBAAiB,EAAE;oBAC/D,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,eAAe,EAAE;oBAC3D,EAAE,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,mBAAmB,EAAE;oBACjE,EAAE,KAAK,EAAE,yBAAyB,EAAE,KAAK,EAAE,kBAAkB,EAAE;oBAC/D,EAAE,KAAK,EAAE,0BAA0B,EAAE,KAAK,EAAE,mBAAmB,EAAE;iBAClE;aACF;SACF,CAAC;QACF,YAAY,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC9B,WAAW,EAAE,eAAe;YAC5B,QAAQ,EAAE,KAAK;YACf,YAAY,E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@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const extractStructuredDataAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
3
|
+
username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
|
|
4
|
+
password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
|
|
5
|
+
}>, {
|
|
6
|
+
model: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
|
|
7
|
+
text: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
8
|
+
image: import("@activepieces/pieces-framework").FileProperty<false>;
|
|
9
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
10
|
+
mode: import("@activepieces/pieces-framework").StaticDropdownProperty<"simple" | "advanced", false> | import("@activepieces/pieces-framework").StaticDropdownProperty<"simple" | "advanced", true>;
|
|
11
|
+
schema: import("@activepieces/pieces-framework").DynamicProperties<true>;
|
|
12
|
+
maxTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractStructuredDataAction = 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 sdk_1 = tslib_1.__importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
|
10
|
+
const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
11
|
+
const common_1 = require("../common/common");
|
|
12
|
+
exports.extractStructuredDataAction = (0, pieces_framework_1.createAction)({
|
|
13
|
+
auth: index_1.promptxAuth,
|
|
14
|
+
name: 'extract-structured-data',
|
|
15
|
+
displayName: 'Extract Structured Data',
|
|
16
|
+
description: 'Extract structured data from provided text,image or PDF.',
|
|
17
|
+
props: {
|
|
18
|
+
model: pieces_framework_1.Property.StaticDropdown({
|
|
19
|
+
displayName: 'Model',
|
|
20
|
+
required: true,
|
|
21
|
+
description: 'The model which will generate the completion. Some models are suitable for natural language tasks, others specialize in code.',
|
|
22
|
+
defaultValue: 'claude-3-haiku-20240307',
|
|
23
|
+
options: {
|
|
24
|
+
disabled: false,
|
|
25
|
+
options: [
|
|
26
|
+
{ value: 'claude-3-haiku-20240307', label: 'Claude 3 Haiku' },
|
|
27
|
+
{ value: 'claude-3-sonnet-20240229', label: 'Claude 3 Sonnet' },
|
|
28
|
+
{ value: 'claude-3-opus-20240229', label: 'Claude 3 Opus' },
|
|
29
|
+
{ value: 'claude-3-5-sonnet-latest', label: 'Claude 3.5 Sonnet' },
|
|
30
|
+
{ value: 'claude-3-5-haiku-latest', label: 'Claude 3.5 Haiku' },
|
|
31
|
+
{ value: 'claude-3-7-sonnet-latest', label: 'Claude 3.7 Sonnet' },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
text: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'Text',
|
|
37
|
+
description: 'Text to extract structured data from.',
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
image: pieces_framework_1.Property.File({
|
|
41
|
+
displayName: 'Image/PDF',
|
|
42
|
+
description: 'Image or PDF to extract structured data from.',
|
|
43
|
+
required: false,
|
|
44
|
+
}),
|
|
45
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
46
|
+
displayName: 'Guide Prompt',
|
|
47
|
+
description: 'Prompt to guide the AI.',
|
|
48
|
+
defaultValue: 'Extract the following data from the provided data.',
|
|
49
|
+
required: false,
|
|
50
|
+
}),
|
|
51
|
+
mode: pieces_framework_1.Property.StaticDropdown({
|
|
52
|
+
displayName: 'Data Schema Type',
|
|
53
|
+
description: 'For complex schema, you can use advanced mode.',
|
|
54
|
+
required: true,
|
|
55
|
+
defaultValue: 'simple',
|
|
56
|
+
options: {
|
|
57
|
+
disabled: false,
|
|
58
|
+
options: [
|
|
59
|
+
{ label: 'Simple', value: 'simple' },
|
|
60
|
+
{ label: 'Advanced', value: 'advanced' },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
schema: pieces_framework_1.Property.DynamicProperties({
|
|
65
|
+
displayName: 'Data Definition',
|
|
66
|
+
required: true,
|
|
67
|
+
refreshers: ['mode'],
|
|
68
|
+
props: (propsValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const mode = propsValue['mode'];
|
|
70
|
+
if (mode === 'advanced') {
|
|
71
|
+
return {
|
|
72
|
+
fields: pieces_framework_1.Property.Json({
|
|
73
|
+
displayName: 'JSON Schema',
|
|
74
|
+
description: 'Learn more about JSON Schema here: https://json-schema.org/learn/getting-started-step-by-step',
|
|
75
|
+
required: true,
|
|
76
|
+
defaultValue: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
name: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
},
|
|
82
|
+
age: {
|
|
83
|
+
type: 'number',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
required: ['name'],
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
fields: pieces_framework_1.Property.Array({
|
|
93
|
+
displayName: 'Data Definition',
|
|
94
|
+
required: true,
|
|
95
|
+
properties: {
|
|
96
|
+
name: pieces_framework_1.Property.ShortText({
|
|
97
|
+
displayName: 'Name',
|
|
98
|
+
description: 'Provide the name of the value you want to extract from the unstructured text. The name should be unique and short. ',
|
|
99
|
+
required: true,
|
|
100
|
+
}),
|
|
101
|
+
description: pieces_framework_1.Property.LongText({
|
|
102
|
+
displayName: 'Description',
|
|
103
|
+
description: 'Brief description of the data, this hints for the AI on what to look for',
|
|
104
|
+
required: false,
|
|
105
|
+
}),
|
|
106
|
+
type: pieces_framework_1.Property.StaticDropdown({
|
|
107
|
+
displayName: 'Data Type',
|
|
108
|
+
description: 'Type of parameter.',
|
|
109
|
+
required: true,
|
|
110
|
+
defaultValue: 'string',
|
|
111
|
+
options: {
|
|
112
|
+
disabled: false,
|
|
113
|
+
options: [
|
|
114
|
+
{ label: 'Text', value: 'string' },
|
|
115
|
+
{ label: 'Number', value: 'number' },
|
|
116
|
+
{ label: 'Boolean', value: 'boolean' },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
isRequired: pieces_framework_1.Property.Checkbox({
|
|
121
|
+
displayName: 'Fail if Not present?',
|
|
122
|
+
required: true,
|
|
123
|
+
defaultValue: false,
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
}),
|
|
129
|
+
}),
|
|
130
|
+
maxTokens: pieces_framework_1.Property.Number({
|
|
131
|
+
displayName: 'Maximum Tokens',
|
|
132
|
+
required: false,
|
|
133
|
+
description: "The maximum number of tokens to generate. Requests can use up to 2,048 or 4,096 tokens shared between prompt and completion, don't set the value to maximum and leave some tokens for the input. The exact limit varies by model. (One token is roughly 4 characters for normal English text)",
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
run(context) {
|
|
137
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a;
|
|
139
|
+
const { model, text, image, schema, prompt, maxTokens } = context.propsValue;
|
|
140
|
+
const { server, username, password } = context.auth;
|
|
141
|
+
const { current: { id: flowId }, } = context.flows;
|
|
142
|
+
const { id: projectId } = context.project;
|
|
143
|
+
const accessToken = yield (0, common_1.getAccessToken)(server, username, password);
|
|
144
|
+
//get store data
|
|
145
|
+
const { userId, apiKey } = yield (0, common_1.getStoreData)(context.store, server, accessToken);
|
|
146
|
+
const usage = yield (0, common_1.getUsagePlan)(server, accessToken);
|
|
147
|
+
//check token is available
|
|
148
|
+
if (maxTokens && maxTokens > usage.token_available) {
|
|
149
|
+
throw new Error(common_1.billingIssueMessage);
|
|
150
|
+
}
|
|
151
|
+
if (!text && !image) {
|
|
152
|
+
throw new Error('Please provide text or image/PDF to extract data from.');
|
|
153
|
+
}
|
|
154
|
+
let params;
|
|
155
|
+
if (context.propsValue.mode === 'advanced') {
|
|
156
|
+
const ajv = new ajv_1.default();
|
|
157
|
+
const isValidSchema = ajv.validateSchema(schema);
|
|
158
|
+
if (!isValidSchema) {
|
|
159
|
+
throw new Error(JSON.stringify({
|
|
160
|
+
message: 'Invalid JSON schema',
|
|
161
|
+
errors: ajv.errors,
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
params = schema['fields'];
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
params = {
|
|
168
|
+
type: 'object',
|
|
169
|
+
properties: schema['fields'].reduce((acc, field) => {
|
|
170
|
+
acc[field.name] = {
|
|
171
|
+
type: field.type,
|
|
172
|
+
description: field.description,
|
|
173
|
+
};
|
|
174
|
+
return acc;
|
|
175
|
+
}, {}),
|
|
176
|
+
required: schema['fields']
|
|
177
|
+
.filter((field) => field.isRequired)
|
|
178
|
+
.map((field) => field.name),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const anthropic = new sdk_1.default({
|
|
182
|
+
apiKey: `${apiKey}`,
|
|
183
|
+
});
|
|
184
|
+
const messages = [
|
|
185
|
+
{
|
|
186
|
+
role: 'user',
|
|
187
|
+
content: prompt !== null && prompt !== void 0 ? prompt : 'Use optical character recognition (OCR) to extract from provided data.',
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
if (!(0, shared_1.isNil)(text) && text !== '') {
|
|
191
|
+
messages.push({
|
|
192
|
+
role: 'user',
|
|
193
|
+
content: text,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
if (image) {
|
|
197
|
+
const mediaType = image.extension
|
|
198
|
+
? mime_types_1.default.lookup(image.extension)
|
|
199
|
+
: 'image/jpeg';
|
|
200
|
+
if (mediaType === 'application/pdf') {
|
|
201
|
+
messages.push({
|
|
202
|
+
role: 'user',
|
|
203
|
+
content: [
|
|
204
|
+
{
|
|
205
|
+
type: 'document',
|
|
206
|
+
source: {
|
|
207
|
+
type: 'base64',
|
|
208
|
+
media_type: 'application/pdf',
|
|
209
|
+
data: image.base64,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
messages.push({
|
|
217
|
+
role: 'user',
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
type: 'image',
|
|
221
|
+
source: {
|
|
222
|
+
type: 'base64',
|
|
223
|
+
media_type: mediaType,
|
|
224
|
+
data: image.base64,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const response = yield anthropic.messages.create({
|
|
232
|
+
model: model,
|
|
233
|
+
messages,
|
|
234
|
+
tools: [
|
|
235
|
+
{
|
|
236
|
+
name: 'extract_structured_data',
|
|
237
|
+
description: 'Extract the following data from the provided data.',
|
|
238
|
+
input_schema: params,
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
tool_choice: { type: 'tool', name: 'extract_structured_data' },
|
|
242
|
+
max_tokens: maxTokens !== null && maxTokens !== void 0 ? maxTokens : (usage.token_available > 2000 ? 2000 : usage.token_available),
|
|
243
|
+
});
|
|
244
|
+
const toolCallsResponse = response.content.filter((choice) => choice.type === 'tool_use');
|
|
245
|
+
const toolCall = toolCallsResponse[0];
|
|
246
|
+
const choices = response.content
|
|
247
|
+
.filter((choice) => choice.type === 'text')
|
|
248
|
+
.map((choice) => ({
|
|
249
|
+
content: choice.text,
|
|
250
|
+
role: 'assistant',
|
|
251
|
+
}));
|
|
252
|
+
const args = toolCall.input;
|
|
253
|
+
if ((0, shared_1.isNil)(args)) {
|
|
254
|
+
throw new Error(JSON.stringify({
|
|
255
|
+
message: (_a = choices[0].content) !== null && _a !== void 0 ? _a : 'Failed to extract structured data from the input.',
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
if (response) {
|
|
259
|
+
const inputTokens = response.usage.input_tokens;
|
|
260
|
+
const outputTokens = response.usage.output_tokens;
|
|
261
|
+
const totalTokens = inputTokens + outputTokens;
|
|
262
|
+
yield (0, common_1.addTokenUsage)({
|
|
263
|
+
userId: `${userId}`,
|
|
264
|
+
model: response.model, // 'claude-3-5-sonnet-20240620'
|
|
265
|
+
projectId: projectId,
|
|
266
|
+
flowId: flowId,
|
|
267
|
+
component: 'Automationx',
|
|
268
|
+
usage: {
|
|
269
|
+
inputTokens,
|
|
270
|
+
outputTokens,
|
|
271
|
+
totalTokens,
|
|
272
|
+
},
|
|
273
|
+
}, server, accessToken);
|
|
274
|
+
}
|
|
275
|
+
return args;
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
//# sourceMappingURL=extract-structured-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-structured-data.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-claude/src/lib/actions/extract-structured-data.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,iDAA6C;AAC7C,oEAA0C;AAE1C,uCAA0C;AAC1C,sDAAsB;AACtB,oEAA8B;AAC9B,6CAM0B;AAEb,QAAA,2BAA2B,GAAG,IAAA,+BAAY,EAAC;IACtD,IAAI,EAAE,mBAAW;IACjB,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EAAE,yBAAyB;IACtC,WAAW,EAAE,0DAA0D;IACvE,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAC7B,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,+HAA+H;YACjI,YAAY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AI,KAAK,CACb,IAAI,CAAC,SAAS,CAAC;oBACb,OAAO,EACL,MAAA,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,mCAClB,mDAAmD;iBACtD,CAAC,CACH,CAAC;YACJ,CAAC;YACD,IAAI,QAAQ,EAAE,CAAC;gBACb,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC;gBAChD,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC;gBAClD,MAAM,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC;gBAC/C,MAAM,IAAA,sBAAa,EACjB;oBACE,MAAM,EAAE,GAAG,MAAM,EAAE;oBACnB,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,+BAA+B;oBACtD,SAAS,EAAE,SAAS;oBACpB,MAAM,EAAE,MAAM;oBACd,SAAS,EAAE,aAAa;oBACxB,KAAK,EAAE;wBACL,WAAW;wBACX,YAAY;wBACZ,WAAW;qBACZ;iBACF,EACD,MAAM,EACN,WAAqB,CACtB,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Store } from '@activepieces/pieces-framework';
|
|
2
|
+
export declare const baseUrl = "https://api.anthropic.com/v1";
|
|
3
|
+
export declare const billingIssueMessage = "Error Occurred: 429 \n\n\n1. Ensure that you have enough tokens on your Anthropic platform. \n\n2. Top-up the credit in promptX's Billing page. \n\n3. Attempt the process again";
|
|
4
|
+
export declare const unauthorizedMessage = "Error Occurred: 401 \n\n\nEnsure that your API key is valid. \n\n";
|
|
5
|
+
type UrlConfig = {
|
|
6
|
+
loginUrl: string;
|
|
7
|
+
quotaCheckUrl: string;
|
|
8
|
+
addTokenUrl: string;
|
|
9
|
+
myProfileUrl: string;
|
|
10
|
+
getAIKeyUrl: string;
|
|
11
|
+
};
|
|
12
|
+
type UsagePackage = {
|
|
13
|
+
package_name: string;
|
|
14
|
+
total_tokens_used: number;
|
|
15
|
+
limit_token_usage: number;
|
|
16
|
+
token_available: number;
|
|
17
|
+
total_credit_used: number;
|
|
18
|
+
limit_credit_usage: number;
|
|
19
|
+
credit_available: number;
|
|
20
|
+
};
|
|
21
|
+
type UserInfo = {
|
|
22
|
+
userIAM2ID: string;
|
|
23
|
+
email: string;
|
|
24
|
+
username: string;
|
|
25
|
+
};
|
|
26
|
+
interface Usage {
|
|
27
|
+
inputTokens: number;
|
|
28
|
+
outputTokens: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
}
|
|
31
|
+
interface AppUsageData {
|
|
32
|
+
appId?: string;
|
|
33
|
+
userId: string;
|
|
34
|
+
model: string;
|
|
35
|
+
projectId: string;
|
|
36
|
+
flowId: string;
|
|
37
|
+
agentId?: string;
|
|
38
|
+
component: string;
|
|
39
|
+
usage: Usage;
|
|
40
|
+
}
|
|
41
|
+
export declare const Production = "PromptX";
|
|
42
|
+
export declare const Test = "Staging";
|
|
43
|
+
export declare const baseUrlMap: Record<string, UrlConfig>;
|
|
44
|
+
export declare const getAccessToken: (server: string, username: string, password: string) => Promise<string | null>;
|
|
45
|
+
export declare const addTokenUsage: (data: AppUsageData, server: string, access_token: string) => Promise<any>;
|
|
46
|
+
export declare const getUsagePlan: (server: string, access_token: string) => Promise<UsagePackage>;
|
|
47
|
+
export declare const getUserProfile: (server: string, access_token: string) => Promise<UserInfo>;
|
|
48
|
+
export declare const getStoreData: (store: Store, server: string, access_token: string) => Promise<{
|
|
49
|
+
userId: any;
|
|
50
|
+
apiKey: any;
|
|
51
|
+
}>;
|
|
52
|
+
export declare const getAiApiKey: (server: string, access_token: string) => Promise<any>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAiApiKey = exports.getStoreData = exports.getUserProfile = exports.getUsagePlan = exports.addTokenUsage = exports.getAccessToken = exports.baseUrlMap = exports.Test = exports.Production = exports.unauthorizedMessage = exports.billingIssueMessage = exports.baseUrl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.baseUrl = 'https://api.anthropic.com/v1';
|
|
6
|
+
exports.billingIssueMessage = `Error Occurred: 429 \n
|
|
7
|
+
|
|
8
|
+
1. Ensure that you have enough tokens on your Anthropic platform. \n
|
|
9
|
+
2. Top-up the credit in promptX's Billing page. \n
|
|
10
|
+
3. Attempt the process again`;
|
|
11
|
+
exports.unauthorizedMessage = `Error Occurred: 401 \n
|
|
12
|
+
|
|
13
|
+
Ensure that your API key is valid. \n
|
|
14
|
+
`;
|
|
15
|
+
exports.Production = 'PromptX';
|
|
16
|
+
exports.Test = 'Staging';
|
|
17
|
+
exports.baseUrlMap = {
|
|
18
|
+
[exports.Production]: {
|
|
19
|
+
loginUrl: 'https://centerapp.io/center/auth/login',
|
|
20
|
+
quotaCheckUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/quota-check',
|
|
21
|
+
addTokenUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/token-used',
|
|
22
|
+
myProfileUrl: 'https://centerapp.io/center//api/v1/users/me',
|
|
23
|
+
getAIKeyUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/api-key?key=claudeKey',
|
|
24
|
+
},
|
|
25
|
+
[exports.Test]: {
|
|
26
|
+
loginUrl: 'https://test.oneweb.tech/zero-service/pmtx/login',
|
|
27
|
+
quotaCheckUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/quota-check',
|
|
28
|
+
addTokenUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/token-used',
|
|
29
|
+
myProfileUrl: 'https://mocha.centerapp.io/center//api/v1/users/me',
|
|
30
|
+
getAIKeyUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/api-key?key=claudeKey',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const getAccessToken = (server, username, password) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const response = yield fetch(exports.baseUrlMap[server].loginUrl, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
body: new URLSearchParams({
|
|
37
|
+
username: username,
|
|
38
|
+
password: password,
|
|
39
|
+
}).toString(),
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const data = yield response.json();
|
|
45
|
+
if (response.status !== 200) {
|
|
46
|
+
throw new Error((data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.message));
|
|
47
|
+
}
|
|
48
|
+
return data === null || data === void 0 ? void 0 : data.access_token;
|
|
49
|
+
});
|
|
50
|
+
exports.getAccessToken = getAccessToken;
|
|
51
|
+
const addTokenUsage = (data, server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
const response = yield fetch(exports.baseUrlMap[server]['addTokenUrl'], {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
Authorization: `Bearer ${access_token}`,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(data),
|
|
60
|
+
});
|
|
61
|
+
if (response.status !== 200) {
|
|
62
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
const result = yield response.json();
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Failed to send token usage:', error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
exports.addTokenUsage = addTokenUsage;
|
|
73
|
+
const getUsagePlan = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
const response = yield fetch(exports.baseUrlMap[server]['quotaCheckUrl'], {
|
|
75
|
+
headers: {
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
Authorization: `Bearer ${access_token}`,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
if (response.status !== 201) {
|
|
81
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
const result = yield response.json();
|
|
84
|
+
return result;
|
|
85
|
+
});
|
|
86
|
+
exports.getUsagePlan = getUsagePlan;
|
|
87
|
+
const getUserProfile = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const response = yield fetch(exports.baseUrlMap[server]['myProfileUrl'], {
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/json',
|
|
91
|
+
Authorization: `Bearer ${access_token}`,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
if (response.status !== 200) {
|
|
95
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
96
|
+
}
|
|
97
|
+
const result = yield response.json();
|
|
98
|
+
return result;
|
|
99
|
+
});
|
|
100
|
+
exports.getUserProfile = getUserProfile;
|
|
101
|
+
const getStoreData = (store, server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
//get store data
|
|
103
|
+
let userId = yield store.get('userId');
|
|
104
|
+
let apiKey = yield (0, exports.getAiApiKey)(server, access_token);
|
|
105
|
+
if (!userId) {
|
|
106
|
+
const userInfo = yield (0, exports.getUserProfile)(server, access_token);
|
|
107
|
+
store.put('userId', userInfo.userIAM2ID);
|
|
108
|
+
userId = userInfo.userIAM2ID;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
userId,
|
|
112
|
+
apiKey,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
exports.getStoreData = getStoreData;
|
|
116
|
+
const getAiApiKey = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const response = yield fetch(exports.baseUrlMap[server]['getAIKeyUrl'], {
|
|
118
|
+
headers: {
|
|
119
|
+
'Content-Type': 'application/json',
|
|
120
|
+
Authorization: `Bearer ${access_token}`,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
if (response.status !== 201) {
|
|
124
|
+
throw new Error(`API error: ${response.statusText}`);
|
|
125
|
+
}
|
|
126
|
+
const result = yield response.json();
|
|
127
|
+
if (!(result === null || result === void 0 ? void 0 : result.claudeKey)) {
|
|
128
|
+
throw new Error('No AI Api Key found for Avalant Claude');
|
|
129
|
+
}
|
|
130
|
+
return result === null || result === void 0 ? void 0 : result.claudeKey;
|
|
131
|
+
});
|
|
132
|
+
exports.getAiApiKey = getAiApiKey;
|
|
133
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-claude/src/lib/common/common.ts"],"names":[],"mappings":";;;;AAEa,QAAA,OAAO,GAAG,8BAA8B,CAAC;AAEzC,QAAA,mBAAmB,GAAG;;;;6BAIN,CAAC;AAEjB,QAAA,mBAAmB,GAAG;;;CAGlC,CAAC;AAuCW,QAAA,UAAU,GAAG,SAAS,CAAC;AACvB,QAAA,IAAI,GAAG,SAAS,CAAC;AAEjB,QAAA,UAAU,GAA8B;IACnD,CAAC,kBAAU,CAAC,EAAE;QACZ,QAAQ,EAAE,wCAAwC;QAClD,aAAa,EACX,qEAAqE;QACvE,WAAW,EACT,oEAAoE;QACtE,YAAY,EAAE,8CAA8C;QAC5D,WAAW,EACT,+EAA+E;KAClF;IACD,CAAC,YAAI,CAAC,EAAE;QACN,QAAQ,EAAE,kDAAkD;QAC5D,aAAa,EACX,wEAAwE;QAC1E,WAAW,EACT,uEAAuE;QACzE,YAAY,EAAE,oDAAoD;QAClE,WAAW,EACT,kFAAkF;KACrF;CACF,CAAC;AACK,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,QAAgB,EAChB,QAAgB,EACQ,EAAE;IAC1B,MAAM,QAAQ,GAAG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