@activepieces/piece-ai 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +7 -0
  2. package/package.json +33 -0
  3. package/src/index.d.ts +4 -0
  4. package/src/index.js +29 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/actions/agents/agent-output-builder.d.ts +24 -0
  7. package/src/lib/actions/agents/agent-output-builder.js +81 -0
  8. package/src/lib/actions/agents/agent-output-builder.js.map +1 -0
  9. package/src/lib/actions/agents/run-agent.d.ts +8 -0
  10. package/src/lib/actions/agents/run-agent.js +219 -0
  11. package/src/lib/actions/agents/run-agent.js.map +1 -0
  12. package/src/lib/actions/image/generate-image.d.ts +6 -0
  13. package/src/lib/actions/image/generate-image.js +216 -0
  14. package/src/lib/actions/image/generate-image.js.map +1 -0
  15. package/src/lib/actions/text/ask-ai.d.ts +35 -0
  16. package/src/lib/actions/text/ask-ai.js +238 -0
  17. package/src/lib/actions/text/ask-ai.js.map +1 -0
  18. package/src/lib/actions/text/summarize-text.d.ts +7 -0
  19. package/src/lib/actions/text/summarize-text.js +61 -0
  20. package/src/lib/actions/text/summarize-text.js.map +1 -0
  21. package/src/lib/actions/utility/classify-text.d.ts +6 -0
  22. package/src/lib/actions/utility/classify-text.js +51 -0
  23. package/src/lib/actions/utility/classify-text.js.map +1 -0
  24. package/src/lib/actions/utility/extract-structured-data.d.ts +10 -0
  25. package/src/lib/actions/utility/extract-structured-data.js +247 -0
  26. package/src/lib/actions/utility/extract-structured-data.js.map +1 -0
  27. package/src/lib/common/ai-sdk.d.ts +55 -0
  28. package/src/lib/common/ai-sdk.js +62 -0
  29. package/src/lib/common/ai-sdk.js.map +1 -0
  30. package/src/lib/common/props.d.ts +10 -0
  31. package/src/lib/common/props.js +75 -0
  32. package/src/lib/common/props.js.map +1 -0
  33. package/src/lib/common/types.d.ts +140 -0
  34. package/src/lib/common/types.js +95 -0
  35. package/src/lib/common/types.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # pieces-ai
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build pieces-ai` to build the library.
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@activepieces/piece-ai",
3
+ "version": "0.0.1",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {
8
+ "@ai-sdk/anthropic": "2.0.3",
9
+ "@ai-sdk/azure": "2.0.12",
10
+ "@ai-sdk/google": "2.0.6",
11
+ "@ai-sdk/openai": "2.0.12",
12
+ "@ai-sdk/provider": "2.0.0",
13
+ "@openrouter/ai-sdk-provider": "1.4.1",
14
+ "@sinclair/typebox": "0.34.11",
15
+ "ai": "5.0.104",
16
+ "ajv": "8.17.1",
17
+ "axios": "1.13.1",
18
+ "axios-retry": "4.4.1",
19
+ "deepmerge-ts": "7.1.0",
20
+ "mime-types": "2.1.35",
21
+ "nanoid": "3.3.8",
22
+ "semver": "7.6.0",
23
+ "socket.io-client": "4.8.1",
24
+ "tslib": "^2.3.0",
25
+ "zod": "4.1.13",
26
+ "@activepieces/pieces-common": "0.10.1",
27
+ "@activepieces/pieces-framework": "0.22.2",
28
+ "@activepieces/shared": "0.30.1"
29
+ },
30
+ "resolutions": {
31
+ "rollup": "npm:@rollup/wasm-node"
32
+ }
33
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const ai: import("@activepieces/pieces-framework").Piece<undefined>;
2
+ export * from './lib/common/types';
3
+ export * from './lib/common/props';
4
+ export * from './lib/common/ai-sdk';
package/src/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ai = 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 ask_ai_1 = require("./lib/actions/text/ask-ai");
8
+ const summarize_text_1 = require("./lib/actions/text/summarize-text");
9
+ const generate_image_1 = require("./lib/actions/image/generate-image");
10
+ const classify_text_1 = require("./lib/actions/utility/classify-text");
11
+ const extract_structured_data_1 = require("./lib/actions/utility/extract-structured-data");
12
+ const run_agent_1 = require("./lib/actions/agents/run-agent");
13
+ exports.ai = (0, pieces_framework_1.createPiece)({
14
+ displayName: "AI",
15
+ auth: pieces_framework_1.PieceAuth.None(),
16
+ minimumSupportedRelease: '0.73.0',
17
+ categories: [
18
+ shared_1.PieceCategory.ARTIFICIAL_INTELLIGENCE,
19
+ shared_1.PieceCategory.UNIVERSAL_AI,
20
+ ],
21
+ logoUrl: "https://cdn.activepieces.com/pieces/text-ai.svg",
22
+ authors: ['anasbarg', 'amrdb'],
23
+ actions: [ask_ai_1.askAI, summarize_text_1.summarizeText, generate_image_1.generateImageAction, classify_text_1.classifyText, extract_structured_data_1.extractStructuredData, run_agent_1.runAgent],
24
+ triggers: [],
25
+ });
26
+ tslib_1.__exportStar(require("./lib/common/types"), exports);
27
+ tslib_1.__exportStar(require("./lib/common/props"), exports);
28
+ tslib_1.__exportStar(require("./lib/common/ai-sdk"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/ai/src/index.ts"],"names":[],"mappings":";;;;AACA,qEAAwE;AACxE,iDAAqD;AACrD,sDAAkD;AAClD,sEAAkE;AAClE,uEAAyE;AACzE,uEAAmE;AACnE,2FAAsF;AACtF,8DAA0D;AAG7C,QAAA,EAAE,GAAG,IAAA,8BAAW,EAAC;IAC5B,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,4BAAS,CAAC,IAAI,EAAE;IACtB,uBAAuB,EAAE,QAAQ;IACjC,UAAU,EAAE;QACV,sBAAa,CAAC,uBAAuB;QACrC,sBAAa,CAAC,YAAY;KAC3B;IACD,OAAO,EAAE,iDAAiD;IAC1D,OAAO,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE,CAAC,cAAK,EAAE,8BAAa,EAAE,oCAAmB,EAAE,4BAAY,EAAE,+CAAqB,EAAE,oBAAQ,CAAC;IACnG,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC;AAGH,6DAAmC;AACnC,6DAAmC;AACnC,8DAAoC"}
@@ -0,0 +1,24 @@
1
+ import { AgentResult, AgentTaskStatus, AgentTool } from '@activepieces/shared';
2
+ export declare const agentOutputBuilder: (prompt: string) => {
3
+ fail({ message }: FinishParams): void;
4
+ setStatus(_status: AgentTaskStatus): void;
5
+ setStructuredOutput(output: Record<string, unknown>): void;
6
+ addMarkdown(markdown: string): void;
7
+ startToolCall({ toolName, toolCallId, input, agentTools, }: StartToolCallParams): void;
8
+ finishToolCall({ toolCallId, output }: FinishToolCallParams): void;
9
+ build(): AgentResult;
10
+ };
11
+ type FinishToolCallParams = {
12
+ toolCallId: string;
13
+ output: Record<string, unknown>;
14
+ };
15
+ type StartToolCallParams = {
16
+ toolName: string;
17
+ toolCallId: string;
18
+ input: Record<string, unknown>;
19
+ agentTools: AgentTool[];
20
+ };
21
+ type FinishParams = {
22
+ message?: string;
23
+ };
24
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agentOutputBuilder = void 0;
4
+ const shared_1 = require("@activepieces/shared");
5
+ const agentOutputBuilder = (prompt) => {
6
+ let status = shared_1.AgentTaskStatus.IN_PROGRESS;
7
+ const steps = [];
8
+ let structuredOutput = undefined;
9
+ return {
10
+ fail({ message }) {
11
+ if (!(0, shared_1.isNil)(message)) {
12
+ this.addMarkdown(message);
13
+ }
14
+ status = shared_1.AgentTaskStatus.FAILED;
15
+ },
16
+ setStatus(_status) {
17
+ status = _status;
18
+ },
19
+ setStructuredOutput(output) {
20
+ structuredOutput = output;
21
+ },
22
+ addMarkdown(markdown) {
23
+ if (steps.length === 0 ||
24
+ steps[steps.length - 1].type !== shared_1.ContentBlockType.MARKDOWN) {
25
+ steps.push({
26
+ type: shared_1.ContentBlockType.MARKDOWN,
27
+ markdown: '',
28
+ });
29
+ }
30
+ steps[steps.length - 1].markdown += markdown;
31
+ },
32
+ startToolCall({ toolName, toolCallId, input, agentTools, }) {
33
+ const metadata = getToolMetadata({
34
+ toolName,
35
+ baseTool: {
36
+ toolName,
37
+ toolCallId,
38
+ type: shared_1.ContentBlockType.TOOL_CALL,
39
+ status: shared_1.ToolCallStatus.IN_PROGRESS,
40
+ input,
41
+ output: undefined,
42
+ startTime: new Date().toISOString(),
43
+ },
44
+ tools: agentTools,
45
+ });
46
+ steps.push(metadata);
47
+ },
48
+ finishToolCall({ toolCallId, output }) {
49
+ const toolIdx = steps.findIndex((block) => block.type === shared_1.ContentBlockType.TOOL_CALL &&
50
+ block.toolCallId === toolCallId);
51
+ const tool = steps[toolIdx];
52
+ (0, shared_1.assertNotNullOrUndefined)(tool, 'Last block must be a tool call');
53
+ steps[toolIdx] = Object.assign(Object.assign({}, tool), { status: shared_1.ToolCallStatus.COMPLETED, endTime: new Date().toISOString(), output });
54
+ },
55
+ build() {
56
+ return {
57
+ status,
58
+ steps,
59
+ structuredOutput,
60
+ prompt,
61
+ };
62
+ },
63
+ };
64
+ };
65
+ exports.agentOutputBuilder = agentOutputBuilder;
66
+ function getToolMetadata({ toolName, tools, baseTool, }) {
67
+ const tool = tools.find((tool) => tool.toolName === toolName);
68
+ (0, shared_1.assertNotNullOrUndefined)(tool, `Tool ${toolName} not found`);
69
+ switch (tool.type) {
70
+ case shared_1.AgentToolType.PIECE: {
71
+ const pieceMetadata = tool.pieceMetadata;
72
+ (0, shared_1.assertNotNullOrUndefined)(pieceMetadata, 'Piece metadata is required');
73
+ return Object.assign(Object.assign({}, baseTool), { toolCallType: shared_1.ToolCallType.PIECE, pieceName: pieceMetadata.pieceName, pieceVersion: pieceMetadata.pieceVersion, actionName: tool.pieceMetadata.actionName });
74
+ }
75
+ case shared_1.AgentToolType.FLOW: {
76
+ (0, shared_1.assertNotNullOrUndefined)(tool.flowId, 'Flow ID is required');
77
+ return Object.assign(Object.assign({}, baseTool), { toolCallType: shared_1.ToolCallType.FLOW, displayName: 'Unknown', flowId: tool.flowId });
78
+ }
79
+ }
80
+ }
81
+ //# sourceMappingURL=agent-output-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-output-builder.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/ai/src/lib/actions/agents/agent-output-builder.ts"],"names":[],"mappings":";;;AAAA,iDAc8B;AAEvB,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,EAAE;IACnD,IAAI,MAAM,GAAoB,wBAAe,CAAC,WAAW,CAAC;IAC1D,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,IAAI,gBAAgB,GAAwC,SAAS,CAAC;IAEtE,OAAO;QACL,IAAI,CAAC,EAAE,OAAO,EAAgB;YAC5B,IAAI,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;YACD,MAAM,GAAG,wBAAe,CAAC,MAAM,CAAC;QAClC,CAAC;QACD,SAAS,CAAC,OAAwB;YAChC,MAAM,GAAG,OAAO,CAAC;QACnB,CAAC;QACD,mBAAmB,CAAC,MAA+B;YACjD,gBAAgB,GAAG,MAAM,CAAC;QAC5B,CAAC;QACD,WAAW,CAAC,QAAgB;YAC1B,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;gBAClB,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,yBAAgB,CAAC,QAAQ,EAC1D,CAAC;gBACD,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE,yBAAgB,CAAC,QAAQ;oBAC/B,QAAQ,EAAE,EAAE;iBACb,CAAC,CAAC;YACL,CAAC;YACA,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Q,EACR,KAAK,EACL,QAAQ,GACY;IACpB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC;IAC9D,IAAA,iCAAwB,EAAC,IAAI,EAAE,QAAQ,QAAQ,YAAY,CAAC,CAAC;IAE7D,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,sBAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YACzB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;YACzC,IAAA,iCAAwB,EAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;YACtE,uCACK,QAAQ,KACX,YAAY,EAAE,qBAAY,CAAC,KAAK,EAChC,SAAS,EAAE,aAAa,CAAC,SAAS,EAClC,YAAY,EAAE,aAAa,CAAC,YAAY,EACxC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,UAAU,IACzC;QACJ,CAAC;QACD,KAAK,sBAAa,CAAC,IAAI,CAAC,CAAC,CAAC;YACxB,IAAA,iCAAwB,EAAC,IAAI,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;YAC7D,uCACK,QAAQ,KACX,YAAY,EAAE,qBAAY,CAAC,IAAI,EAC/B,WAAW,EAAE,SAAS,EACtB,MAAM,EAAE,IAAI,CAAC,MAAM,IACnB;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const runAgent: import("@activepieces/pieces-framework").IAction<undefined, {
2
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
3
+ provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
4
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
5
+ agentTools: import("@activepieces/pieces-framework").ArrayProperty<true> | import("@activepieces/pieces-framework").ArrayProperty<false>;
6
+ structuredOutput: import("@activepieces/pieces-framework").ArrayProperty<true> | import("@activepieces/pieces-framework").ArrayProperty<false>;
7
+ maxSteps: import("@activepieces/pieces-framework").NumberProperty<true>;
8
+ }>;
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runAgent = 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 ai_1 = require("ai");
8
+ const zod_1 = require("zod");
9
+ const agent_output_builder_1 = require("./agent-output-builder");
10
+ const ai_sdk_1 = require("../../common/ai-sdk");
11
+ const props_1 = require("../../common/props");
12
+ const util_1 = require("util");
13
+ exports.runAgent = (0, pieces_framework_1.createAction)({
14
+ name: 'run_agent',
15
+ displayName: 'Run Agent',
16
+ description: 'Run the AI assistant to complete your task.',
17
+ auth: pieces_framework_1.PieceAuth.None(),
18
+ props: {
19
+ [shared_1.AgentPieceProps.PROMPT]: pieces_framework_1.Property.LongText({
20
+ displayName: 'Prompt',
21
+ description: 'Describe what you want the assistant to do.',
22
+ required: true,
23
+ }),
24
+ [shared_1.AgentPieceProps.AI_PROVIDER]: (0, props_1.aiProps)({ modelType: 'text' }).provider,
25
+ [shared_1.AgentPieceProps.AI_MODEL]: (0, props_1.aiProps)({ modelType: 'text' }).model,
26
+ [shared_1.AgentPieceProps.AGENT_TOOLS]: pieces_framework_1.Property.Array({
27
+ displayName: 'Agent Tools',
28
+ required: false,
29
+ properties: {
30
+ type: pieces_framework_1.Property.ShortText({
31
+ displayName: 'Tool Type',
32
+ required: true,
33
+ }),
34
+ toolName: pieces_framework_1.Property.ShortText({
35
+ displayName: 'Tool Name',
36
+ required: true,
37
+ }),
38
+ pieceMetadata: pieces_framework_1.Property.Json({
39
+ displayName: 'Piece Metadata',
40
+ required: false,
41
+ }),
42
+ flowId: pieces_framework_1.Property.ShortText({
43
+ displayName: 'Flow Id',
44
+ required: false,
45
+ }),
46
+ },
47
+ }),
48
+ [shared_1.AgentPieceProps.STRUCTURED_OUTPUT]: pieces_framework_1.Property.Array({
49
+ displayName: 'Structured Output',
50
+ defaultValue: undefined,
51
+ required: false,
52
+ properties: {
53
+ displayName: pieces_framework_1.Property.ShortText({
54
+ displayName: 'Display Name',
55
+ required: true,
56
+ }),
57
+ description: pieces_framework_1.Property.ShortText({
58
+ displayName: 'Description',
59
+ required: false,
60
+ }),
61
+ type: pieces_framework_1.Property.ShortText({
62
+ displayName: 'Type',
63
+ required: true,
64
+ }),
65
+ },
66
+ }),
67
+ [shared_1.AgentPieceProps.MAX_STEPS]: pieces_framework_1.Property.Number({
68
+ displayName: 'Max steps',
69
+ description: 'The numbder of interations the agent can do',
70
+ required: true,
71
+ defaultValue: 20,
72
+ }),
73
+ },
74
+ run(context) {
75
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
+ var _a, e_1, _b, _c;
77
+ var _d, _e;
78
+ const { prompt, maxSteps, model: modelId, provider: providerId } = context.propsValue;
79
+ const model = yield (0, ai_sdk_1.createAIModel)({
80
+ modelId,
81
+ providerId,
82
+ engineToken: context.server.token,
83
+ apiUrl: context.server.apiUrl,
84
+ });
85
+ const outputBuilder = (0, agent_output_builder_1.agentOutputBuilder)(prompt);
86
+ const hasStructuredOutput = !(0, shared_1.isNil)(context.propsValue.structuredOutput) &&
87
+ context.propsValue.structuredOutput.length > 0;
88
+ const agentToolsMetadata = context.propsValue.agentTools;
89
+ const agentTools = yield context.agent.tools({
90
+ tools: agentToolsMetadata,
91
+ model: model,
92
+ });
93
+ const stream = (0, ai_1.streamText)({
94
+ model: model,
95
+ prompt: `
96
+ ${prompt}
97
+
98
+ <important_note>
99
+ As your FINAL ACTION, you must call the \`${shared_1.TASK_COMPLETION_TOOL_NAME}\` tool to indicate if the task is complete or not.
100
+ Call this tool only once you have done everything you can to achieve the user's goal, or if you are unable to continue.
101
+ If you do not make this final call, your work will be considered unsuccessful.
102
+ </important_note>
103
+ `,
104
+ system: `
105
+ You are a helpful, proactive AI assistant.
106
+ Today's date is ${new Date().toISOString().split('T')[0]}.
107
+
108
+ Help the user finish their goal quickly and accurately.
109
+ `.trim(),
110
+ stopWhen: [(0, ai_1.stepCountIs)(maxSteps), (0, ai_1.hasToolCall)(shared_1.TASK_COMPLETION_TOOL_NAME)],
111
+ tools: Object.assign(Object.assign({}, agentTools), { [shared_1.TASK_COMPLETION_TOOL_NAME]: (0, ai_1.dynamicTool)({
112
+ description: "This tool must be called as your FINAL ACTION to indicate whether the assigned goal was accomplished. Call it only when you have completed the user's task, or if you are unable to continue. Once you call this tool, you should not take any further actions.",
113
+ inputSchema: zod_1.z.object(Object.assign({ success: zod_1.z
114
+ .boolean()
115
+ .describe('Set to true if the assigned goal was achieved, or false if the task was abandoned or failed.') }, (hasStructuredOutput
116
+ ? {
117
+ output: zod_1.z
118
+ .object((_e = (_d = structuredOutputSchema(context.propsValue
119
+ .structuredOutput)) === null || _d === void 0 ? void 0 : _d.shape) !== null && _e !== void 0 ? _e : {})
120
+ .nullable()
121
+ .describe('The structured output of your task. This is optional and can be omitted if you have not achieved the goal.'),
122
+ }
123
+ : {
124
+ output: zod_1.z
125
+ .string()
126
+ .nullable()
127
+ .describe('The message to the user with the result of your task. This is optional and can be omitted if you have not achieved the goal.'),
128
+ }))),
129
+ execute: (params) => tslib_1.__awaiter(this, void 0, void 0, function* () {
130
+ const { success, output } = params;
131
+ outputBuilder.setStatus(success ? shared_1.AgentTaskStatus.COMPLETED : shared_1.AgentTaskStatus.FAILED);
132
+ if (hasStructuredOutput && !(0, shared_1.isNil)(output)) {
133
+ outputBuilder.setStructuredOutput(output);
134
+ }
135
+ if (!hasStructuredOutput && !(0, shared_1.isNil)(output)) {
136
+ outputBuilder.addMarkdown(output);
137
+ }
138
+ return {};
139
+ }),
140
+ }) }),
141
+ });
142
+ try {
143
+ for (var _f = true, _g = tslib_1.__asyncValues(stream.fullStream), _h; _h = yield _g.next(), _a = _h.done, !_a; _f = true) {
144
+ _c = _h.value;
145
+ _f = false;
146
+ const chuck = _c;
147
+ switch (chuck.type) {
148
+ case 'text-delta': {
149
+ outputBuilder.addMarkdown(chuck.text);
150
+ break;
151
+ }
152
+ case 'tool-call': {
153
+ if (isTaskCompletionToolCall(chuck.toolName)) {
154
+ continue;
155
+ }
156
+ outputBuilder.startToolCall({
157
+ toolName: chuck.toolName,
158
+ toolCallId: chuck.toolCallId,
159
+ input: chuck.input,
160
+ agentTools: agentToolsMetadata,
161
+ });
162
+ break;
163
+ }
164
+ case 'tool-result': {
165
+ if (isTaskCompletionToolCall(chuck.toolName)) {
166
+ continue;
167
+ }
168
+ outputBuilder.finishToolCall({
169
+ toolCallId: chuck.toolCallId,
170
+ output: chuck.output,
171
+ });
172
+ break;
173
+ }
174
+ case 'error': {
175
+ outputBuilder.fail({
176
+ message: 'Error running agent: ' + (0, util_1.inspect)(chuck.error),
177
+ });
178
+ break;
179
+ }
180
+ }
181
+ yield context.output.update({ data: outputBuilder.build() });
182
+ }
183
+ }
184
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
185
+ finally {
186
+ try {
187
+ if (!_f && !_a && (_b = _g.return)) yield _b.call(_g);
188
+ }
189
+ finally { if (e_1) throw e_1.error; }
190
+ }
191
+ const { status } = outputBuilder.build();
192
+ if (status == shared_1.AgentTaskStatus.IN_PROGRESS) {
193
+ outputBuilder.fail({});
194
+ }
195
+ return outputBuilder.build();
196
+ });
197
+ },
198
+ });
199
+ const isTaskCompletionToolCall = (toolName) => toolName === shared_1.TASK_COMPLETION_TOOL_NAME;
200
+ function structuredOutputSchema(outputFields) {
201
+ const shape = {};
202
+ for (const field of outputFields) {
203
+ switch (field.type) {
204
+ case shared_1.AgentOutputFieldType.TEXT:
205
+ shape[field.displayName] = zod_1.z.string();
206
+ break;
207
+ case shared_1.AgentOutputFieldType.NUMBER:
208
+ shape[field.displayName] = zod_1.z.number();
209
+ break;
210
+ case shared_1.AgentOutputFieldType.BOOLEAN:
211
+ shape[field.displayName] = zod_1.z.boolean();
212
+ break;
213
+ default:
214
+ shape[field.displayName] = zod_1.z.any();
215
+ }
216
+ }
217
+ return Object.keys(shape).length > 0 ? zod_1.z.object(shape) : undefined;
218
+ }
219
+ //# sourceMappingURL=run-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-agent.js","sourceRoot":"","sources":["../../../../../../../../../packages/pieces/community/ai/src/lib/actions/agents/run-agent.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,iDAQ8B;AAC9B,2BAAuE;AACvE,6BAAmC;AACnC,iEAA4D;AAC5D,gDAAoD;AACpD,8CAA6C;AAC7C,+BAA+B;AAElB,QAAA,QAAQ,GAAG,IAAA,+BAAY,EAAC;IACnC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,WAAW;IACxB,WAAW,EAAE,6CAA6C;IAC1D,IAAI,EAAE,4BAAS,CAAC,IAAI,EAAE;IACtB,KAAK,EAAE;QACL,CAAC,wBAAe,CAAC,MAAM,CAAC,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1C,WAAW,EAAE,QAAQ;YACrB,WAAW,EAAE,6CAA6C;YAC1D,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,CAAC,wBAAe,CAAC,WAAW,CAAC,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ;QACtE,CAAC,wBAAe,CAAC,QAAQ,CAAC,EAAE,IAAA,eAAO,EAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK;QAChE,CAAC,wBAAe,CAAC,WAAW,CAAC,EAAE,2BAAQ,CAAC,KAAK,CAAC;YAC5C,WAAW,EAAE,aAAa;YAC1B,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE;gBACV,IAAI,EAAE,2BAAQ,CAAC,SAAS,CAAC;oBACvB,WAAW,EAAE,WAAW;oBACxB,QAAQ,EAAE,IAAI;iBACf,CAAC;gBACF,QAAQ,EAAE,2BAAQ,CAAC,SAAS,CAAC;oBAC3B,WAAW,EAAE,WAAW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B,YAAgC;IAEhC,MAAM,KAAK,GAA8B,EAAE,CAAC;IAE5C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QACjC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,6BAAoB,CAAC,IAAI;gBAC5B,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM;YACR,KAAK,6BAAoB,CAAC,MAAM;gBAC9B,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM;YACR,KAAK,6BAAoB,CAAC,OAAO;gBAC/B,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,OAAC,CAAC,OAAO,EAAE,CAAC;gBACvC,MAAM;YACR;gBACE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,OAAC,CAAC,GAAG,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const generateImageAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ provider: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
3
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true, undefined>;
4
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
5
+ advancedOptions: import("@activepieces/pieces-framework").DynamicProperties<false, undefined>;
6
+ }>;