donobu 2.12.2 → 2.13.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/dist/assets/generated/parameter-schemas.json +2 -2
- package/dist/assets/generated/version +1 -1
- package/dist/envVars.d.ts +26 -1
- package/dist/envVars.d.ts.map +1 -1
- package/dist/envVars.js +26 -1
- package/dist/envVars.js.map +1 -1
- package/dist/esm/assets/generated/parameter-schemas.json +2 -2
- package/dist/esm/assets/generated/version +1 -1
- package/dist/esm/envVars.d.ts +26 -1
- package/dist/esm/envVars.d.ts.map +1 -1
- package/dist/esm/envVars.js +26 -1
- package/dist/esm/envVars.js.map +1 -1
- package/dist/esm/managers/CodeGenerator.d.ts +0 -5
- package/dist/esm/managers/CodeGenerator.d.ts.map +1 -1
- package/dist/esm/managers/CodeGenerator.js +4 -48
- package/dist/esm/managers/CodeGenerator.js.map +1 -1
- package/dist/esm/managers/DonobuFlowsManager.d.ts +13 -0
- package/dist/esm/managers/DonobuFlowsManager.d.ts.map +1 -1
- package/dist/esm/managers/DonobuFlowsManager.js +85 -14
- package/dist/esm/managers/DonobuFlowsManager.js.map +1 -1
- package/dist/esm/managers/TemplateInterpolator.d.ts +19 -0
- package/dist/esm/managers/TemplateInterpolator.d.ts.map +1 -0
- package/dist/esm/managers/TemplateInterpolator.js +86 -0
- package/dist/esm/managers/TemplateInterpolator.js.map +1 -0
- package/dist/esm/managers/ToolManager.d.ts +17 -1
- package/dist/esm/managers/ToolManager.d.ts.map +1 -1
- package/dist/esm/managers/ToolManager.js +53 -43
- package/dist/esm/managers/ToolManager.js.map +1 -1
- package/dist/esm/models/GptConfig.d.ts +2 -2
- package/dist/esm/models/GptConfig.d.ts.map +1 -1
- package/dist/esm/models/ResolverContext.d.ts +7 -0
- package/dist/esm/models/ResolverContext.d.ts.map +1 -0
- package/dist/esm/models/ResolverContext.js +3 -0
- package/dist/esm/models/ResolverContext.js.map +1 -0
- package/dist/esm/models/ToolCall.d.ts +4 -3
- package/dist/esm/models/ToolCall.d.ts.map +1 -1
- package/dist/esm/models/ToolTemplateDataSource.d.ts +36 -0
- package/dist/esm/models/ToolTemplateDataSource.d.ts.map +1 -0
- package/dist/esm/models/ToolTemplateDataSource.js +3 -0
- package/dist/esm/models/ToolTemplateDataSource.js.map +1 -0
- package/dist/esm/persistence/FlowsPersistenceFactoryImpl.d.ts.map +1 -1
- package/dist/esm/persistence/FlowsPersistenceFactoryImpl.js +2 -2
- package/dist/esm/persistence/FlowsPersistenceFactoryImpl.js.map +1 -1
- package/dist/esm/playwrightTestExtensions.d.ts +15 -8
- package/dist/esm/playwrightTestExtensions.d.ts.map +1 -1
- package/dist/esm/playwrightTestExtensions.js +85 -45
- package/dist/esm/playwrightTestExtensions.js.map +1 -1
- package/dist/esm/tools/AssertTool.d.ts +14 -0
- package/dist/esm/tools/AssertTool.d.ts.map +1 -1
- package/dist/esm/tools/AssertTool.js.map +1 -1
- package/dist/esm/utils/TemplateInterpolator.d.ts +29 -0
- package/dist/esm/utils/TemplateInterpolator.d.ts.map +1 -0
- package/dist/esm/utils/TemplateInterpolator.js +206 -0
- package/dist/esm/utils/TemplateInterpolator.js.map +1 -0
- package/dist/managers/CodeGenerator.d.ts +0 -5
- package/dist/managers/CodeGenerator.d.ts.map +1 -1
- package/dist/managers/CodeGenerator.js +4 -48
- package/dist/managers/CodeGenerator.js.map +1 -1
- package/dist/managers/DonobuFlowsManager.d.ts +13 -0
- package/dist/managers/DonobuFlowsManager.d.ts.map +1 -1
- package/dist/managers/DonobuFlowsManager.js +85 -14
- package/dist/managers/DonobuFlowsManager.js.map +1 -1
- package/dist/managers/TemplateInterpolator.d.ts +19 -0
- package/dist/managers/TemplateInterpolator.d.ts.map +1 -0
- package/dist/managers/TemplateInterpolator.js +86 -0
- package/dist/managers/TemplateInterpolator.js.map +1 -0
- package/dist/managers/ToolManager.d.ts +17 -1
- package/dist/managers/ToolManager.d.ts.map +1 -1
- package/dist/managers/ToolManager.js +53 -43
- package/dist/managers/ToolManager.js.map +1 -1
- package/dist/models/GptConfig.d.ts +2 -2
- package/dist/models/GptConfig.d.ts.map +1 -1
- package/dist/models/ResolverContext.d.ts +7 -0
- package/dist/models/ResolverContext.d.ts.map +1 -0
- package/dist/models/ResolverContext.js +3 -0
- package/dist/models/ResolverContext.js.map +1 -0
- package/dist/models/ToolCall.d.ts +4 -3
- package/dist/models/ToolCall.d.ts.map +1 -1
- package/dist/models/ToolTemplateDataSource.d.ts +36 -0
- package/dist/models/ToolTemplateDataSource.d.ts.map +1 -0
- package/dist/models/ToolTemplateDataSource.js +3 -0
- package/dist/models/ToolTemplateDataSource.js.map +1 -0
- package/dist/persistence/FlowsPersistenceFactoryImpl.d.ts.map +1 -1
- package/dist/persistence/FlowsPersistenceFactoryImpl.js +2 -2
- package/dist/persistence/FlowsPersistenceFactoryImpl.js.map +1 -1
- package/dist/playwrightTestExtensions.d.ts +15 -8
- package/dist/playwrightTestExtensions.d.ts.map +1 -1
- package/dist/playwrightTestExtensions.js +85 -45
- package/dist/playwrightTestExtensions.js.map +1 -1
- package/dist/tools/AssertTool.d.ts +14 -0
- package/dist/tools/AssertTool.d.ts.map +1 -1
- package/dist/tools/AssertTool.js.map +1 -1
- package/dist/utils/TemplateInterpolator.d.ts +29 -0
- package/dist/utils/TemplateInterpolator.d.ts.map +1 -0
- package/dist/utils/TemplateInterpolator.js +211 -0
- package/dist/utils/TemplateInterpolator.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TEMPLATE_DATA_PATTERN = void 0;
|
|
7
|
+
exports.resolveExpression = resolveExpression;
|
|
8
|
+
exports.interpolateString = interpolateString;
|
|
9
|
+
exports.interpolateObject = interpolateObject;
|
|
10
|
+
const Logger_1 = require("./Logger");
|
|
11
|
+
const jsonpath_1 = __importDefault(require("jsonpath"));
|
|
12
|
+
/**
|
|
13
|
+
* Regular expression to match template JSON-path expressions inside of {{...}}
|
|
14
|
+
*/
|
|
15
|
+
exports.TEMPLATE_DATA_PATTERN = /\{\{([^}]+)\}\}/g;
|
|
16
|
+
/**
|
|
17
|
+
* Regular expression to detect expressions that need to be handled specially
|
|
18
|
+
* Matches patterns like: $..path[?(@.condition)][0] or $..path[?(@.condition)][index] or $..path[?(@.condition)][n:m]
|
|
19
|
+
*/
|
|
20
|
+
const FILTER_WITH_INDEX_PATTERN = /(\[\?\(.*\)\])(\[-?\d+(\:\d+)?\])/;
|
|
21
|
+
const STANDALONE_NEGATIVE_INDEX_PATTERN = /(\$\.calls)\[(-\d+)\](?!\:)/;
|
|
22
|
+
/**
|
|
23
|
+
* Parse and modify JSONPath expressions to handle indexing after filter expressions
|
|
24
|
+
* @param expression - The JSONPath expression to process
|
|
25
|
+
* @returns A processed expression that works with the jsonpath library
|
|
26
|
+
*/
|
|
27
|
+
function processJSONPathExpression(expression) {
|
|
28
|
+
// First check for filter followed by index pattern
|
|
29
|
+
const filterMatch = expression.match(FILTER_WITH_INDEX_PATTERN);
|
|
30
|
+
if (filterMatch) {
|
|
31
|
+
// Extract just the number from indexPart (remove the brackets)
|
|
32
|
+
const indexMatch = filterMatch[2].match(/\[(-?\d+)(\:\d+)?\]/);
|
|
33
|
+
if (indexMatch) {
|
|
34
|
+
// If it's a simple index (not a slice)
|
|
35
|
+
if (!indexMatch[2]) {
|
|
36
|
+
// Remove the index part from the expression
|
|
37
|
+
const baseExpression = expression.replace(filterMatch[2], '');
|
|
38
|
+
// Return the modified expression
|
|
39
|
+
return baseExpression;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check for standalone negative index pattern and convert it to slice notation
|
|
44
|
+
// since the jsonpath library doesn't support negative indices directly.
|
|
45
|
+
const negativeIndexMatch = expression.match(STANDALONE_NEGATIVE_INDEX_PATTERN);
|
|
46
|
+
if (negativeIndexMatch && negativeIndexMatch[2].startsWith('-')) {
|
|
47
|
+
// Convert the standalone negative index to slice notation
|
|
48
|
+
// For example: $.calls[-1] becomes $.calls[-1:]
|
|
49
|
+
const convertedExpression = expression.replace(`[${negativeIndexMatch[2]}]`, `[${negativeIndexMatch[2]}:]`);
|
|
50
|
+
return convertedExpression;
|
|
51
|
+
}
|
|
52
|
+
// If it doesn't match our patterns, return the original expression
|
|
53
|
+
return expression;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Format a value to string with special handling for objects and arrays
|
|
57
|
+
* @param value - The value to format
|
|
58
|
+
* @returns A string representation of the value
|
|
59
|
+
*/
|
|
60
|
+
function formatValue(value) {
|
|
61
|
+
if (value === undefined || value === null) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
// Handle arrays by joining their string representations
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
return value.map(formatValue).join(',');
|
|
67
|
+
}
|
|
68
|
+
// Handle objects with proper JSON formatting
|
|
69
|
+
if (typeof value === 'object' && value !== null) {
|
|
70
|
+
return JSON.stringify(value);
|
|
71
|
+
}
|
|
72
|
+
// Default case
|
|
73
|
+
return String(value);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve a JSONPath expression against the context
|
|
77
|
+
* @param expression - The JSONPath expression to evaluate
|
|
78
|
+
* @param dataSource - The data context to evaluate against
|
|
79
|
+
* @returns The resolved value or undefined if not found
|
|
80
|
+
*/
|
|
81
|
+
function resolveExpression(expression, dataSource) {
|
|
82
|
+
try {
|
|
83
|
+
// Process the expression to handle special cases
|
|
84
|
+
const processedExpression = processJSONPathExpression(expression);
|
|
85
|
+
// Handle expressions with wildcards or recursive searches that might return arrays
|
|
86
|
+
const isWildcardOrRecursive = expression.includes('..') ||
|
|
87
|
+
expression.includes('*') ||
|
|
88
|
+
expression.includes('[:]');
|
|
89
|
+
// Use JSONPath to evaluate the expression against the context
|
|
90
|
+
const results = jsonpath_1.default.query(dataSource, processedExpression);
|
|
91
|
+
// Handle the indexing ourselves if needed
|
|
92
|
+
if (expression !== processedExpression) {
|
|
93
|
+
const match = expression.match(FILTER_WITH_INDEX_PATTERN);
|
|
94
|
+
if (match) {
|
|
95
|
+
const indexMatch = match[2].match(/\[(-?\d+)(\:\d+)?\]/);
|
|
96
|
+
if (indexMatch) {
|
|
97
|
+
const index = parseInt(indexMatch[1], 10);
|
|
98
|
+
// If we have results, handle both positive and negative indices
|
|
99
|
+
if (results && results.length > 0) {
|
|
100
|
+
// For negative indices, count from the end of the array
|
|
101
|
+
const actualIndex = index < 0 ? results.length + index : index;
|
|
102
|
+
// Return the result if the calculated index is valid
|
|
103
|
+
if (actualIndex >= 0 && actualIndex < results.length) {
|
|
104
|
+
return results[actualIndex];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Return the entire array for expressions that clearly want multiple values
|
|
112
|
+
if (isWildcardOrRecursive && results.length > 1) {
|
|
113
|
+
return results;
|
|
114
|
+
}
|
|
115
|
+
// Default case - return the first result if available
|
|
116
|
+
if (results && results.length > 0) {
|
|
117
|
+
return results[0];
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
throw new Error(`Failed to evaluate JSONPath expression: ${expression}. Error: ${error}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Interpolate template strings using JSONPath expressions
|
|
127
|
+
* @param template - The template string with {{...}} expressions
|
|
128
|
+
* @param dataSource - The data context to interpolate from
|
|
129
|
+
* @returns The interpolated string
|
|
130
|
+
*/
|
|
131
|
+
function interpolateString(template, dataSource) {
|
|
132
|
+
return template.replace(exports.TEMPLATE_DATA_PATTERN, (match, expression) => {
|
|
133
|
+
try {
|
|
134
|
+
const value = resolveExpression(expression.trim(), dataSource);
|
|
135
|
+
// If the value is undefined or null, keep the original expression
|
|
136
|
+
if (value === undefined) {
|
|
137
|
+
return match; // Return the original {{expression}} string
|
|
138
|
+
}
|
|
139
|
+
return formatValue(value);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
Logger_1.appLogger.warn(`Error interpolating template: ${template}, expression: ${expression}, error: ${error}`);
|
|
143
|
+
return match; // Return the original {{expression}} string on error
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Interpolate the parameters object using JSONPath expressions. Any string values
|
|
149
|
+
* and keys in the object will be replaced with the corresponding values from the data source.
|
|
150
|
+
* Nested objects and arrays will be processed recursively.
|
|
151
|
+
*
|
|
152
|
+
* @param parameters - The original parameters object
|
|
153
|
+
* @param dataSource - The data context to interpolate from
|
|
154
|
+
* @returns A new parameters object with interpolated string values and keys
|
|
155
|
+
*/
|
|
156
|
+
function interpolateObject(parameters, dataSource) {
|
|
157
|
+
if (!parameters || typeof parameters !== 'object') {
|
|
158
|
+
return parameters;
|
|
159
|
+
}
|
|
160
|
+
// Create appropriate result container
|
|
161
|
+
const result = Array.isArray(parameters) ? [] : {};
|
|
162
|
+
// Process each key-value pair
|
|
163
|
+
if (Array.isArray(parameters)) {
|
|
164
|
+
// Handle array case
|
|
165
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
166
|
+
const value = parameters[i];
|
|
167
|
+
if (typeof value === 'string') {
|
|
168
|
+
// Interpolate string values
|
|
169
|
+
result[i] = interpolateString(value, dataSource);
|
|
170
|
+
}
|
|
171
|
+
else if (typeof value === 'object' && value !== null) {
|
|
172
|
+
// Recursively process nested objects
|
|
173
|
+
result[i] = interpolateObject(value, dataSource);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// Keep non-string values as is
|
|
177
|
+
result[i] = value;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// Handle object case
|
|
183
|
+
for (const key in parameters) {
|
|
184
|
+
const value = parameters[key];
|
|
185
|
+
// Interpolate the key if it's a string and contains a template pattern
|
|
186
|
+
let processedKey = key;
|
|
187
|
+
if (typeof key === 'string' && exports.TEMPLATE_DATA_PATTERN.test(key)) {
|
|
188
|
+
processedKey = interpolateString(key, dataSource);
|
|
189
|
+
}
|
|
190
|
+
if (typeof value === 'string') {
|
|
191
|
+
// Interpolate string values
|
|
192
|
+
result[processedKey] = interpolateString(value, dataSource);
|
|
193
|
+
}
|
|
194
|
+
else if (typeof value === 'object' && value !== null) {
|
|
195
|
+
// Recursively process nested objects
|
|
196
|
+
result[processedKey] = interpolateObject(value, dataSource);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Keep non-string values as is
|
|
200
|
+
result[processedKey] = value;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=TemplateInterpolator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateInterpolator.js","sourceRoot":"","sources":["../../../src/utils/TemplateInterpolator.ts"],"names":[],"mappings":";;;;;;AAyFA,8CAsDC;AAQD,8CAqBC;AAWD,8CAoDC;AA3OD,qCAAqC;AACrC,wDAAgC;AAEhC;;GAEG;AACU,QAAA,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;GAGG;AACH,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;AACtE,MAAM,iCAAiC,GAAG,6BAA6B,CAAC;AAExE;;;;GAIG;AACH,SAAS,yBAAyB,CAAC,UAAkB;IACnD,mDAAmD;IACnD,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAEhE,IAAI,WAAW,EAAE,CAAC;QAChB,+DAA+D;QAC/D,MAAM,UAAU,GAAG,WAAW,CAAC,C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AAG,EAAE,UAAU,CAAC,CAAC;YACpD,CAAC;YAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,4BAA4B;gBAC5B,MAAM,CAAC,YAAY,CAAC,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACvD,qCAAqC;gBACrC,MAAM,CAAC,YAAY,CAAC,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAC9D,CAAC;iBAAM,CAAC;gBACN,+BAA+B;gBAC/B,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { FlowMetadata } from '../models/FlowMetadata';
|
|
2
2
|
import { ProposedToolCall } from '../models/ProposedToolCall';
|
|
3
|
-
import { AgentsManager } from './AgentsManager';
|
|
4
|
-
import { GptConfigsManager } from './GptConfigsManager';
|
|
5
3
|
export declare class CodeGenerator {
|
|
6
|
-
private readonly gptConfigsManager;
|
|
7
|
-
private readonly agentsManager;
|
|
8
|
-
constructor(gptConfigsManager: GptConfigsManager, agentsManager: AgentsManager);
|
|
9
4
|
/** Creates a Node.js Microsoft Playwright script to replay the given flow. */
|
|
10
5
|
getFlowAsPlaywrightScript(flowMetadata: FlowMetadata, toolCalls: ProposedToolCall<any>[]): Promise<string>;
|
|
11
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeGenerator.d.ts","sourceRoot":"","sources":["../../src/managers/CodeGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeGenerator.d.ts","sourceRoot":"","sources":["../../src/managers/CodeGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAyB9D,qBAAa,aAAa;IACxB,8EAA8E;IACjE,yBAAyB,CACpC,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,gBAAgB,CAAC,GAAG,CAAC,EAAE,GACjC,OAAO,CAAC,MAAM,CAAC;IA0FlB;;;OAGG;WACW,uCAAuC,CACnD,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,CAAC,GACtC,MAAM;YAmEK,YAAY;IAY1B;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;CASnC"}
|
|
@@ -25,10 +25,6 @@ const WaitTool_1 = require("../tools/WaitTool");
|
|
|
25
25
|
const JsonUtils_1 = require("../utils/JsonUtils");
|
|
26
26
|
const ToolManager_1 = require("./ToolManager");
|
|
27
27
|
class CodeGenerator {
|
|
28
|
-
constructor(gptConfigsManager, agentsManager) {
|
|
29
|
-
this.gptConfigsManager = gptConfigsManager;
|
|
30
|
-
this.agentsManager = agentsManager;
|
|
31
|
-
}
|
|
32
28
|
/** Creates a Node.js Microsoft Playwright script to replay the given flow. */
|
|
33
29
|
async getFlowAsPlaywrightScript(flowMetadata, toolCalls) {
|
|
34
30
|
// These tools are not supported in the generated script because they have
|
|
@@ -51,38 +47,11 @@ class CodeGenerator {
|
|
|
51
47
|
.filter((tool) => {
|
|
52
48
|
return tool?.requiresGpt;
|
|
53
49
|
}).length > 0;
|
|
54
|
-
let gptConfig = null;
|
|
55
|
-
// Check if the flow metadata has a specific GPT config name.
|
|
56
|
-
// If it does, try to get it from the GptConfigsManager.
|
|
57
|
-
// If it doesn't, try to get the default GPT config from the AgentsManager.
|
|
58
|
-
//
|
|
59
|
-
// This is done so that we can generate code using the preferred GPT client.
|
|
60
|
-
if (isGptClientRequired) {
|
|
61
|
-
try {
|
|
62
|
-
if (flowMetadata.gptConfigName) {
|
|
63
|
-
gptConfig = await this.gptConfigsManager.get(flowMetadata.gptConfigName);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
catch (_error) {
|
|
67
|
-
// This is expected if the config does not exist.
|
|
68
|
-
}
|
|
69
|
-
if (!gptConfig) {
|
|
70
|
-
const gptConfigName = await this.agentsManager.get('flow-runner');
|
|
71
|
-
if (gptConfigName) {
|
|
72
|
-
try {
|
|
73
|
-
gptConfig = await this.gptConfigsManager.get(gptConfigName);
|
|
74
|
-
}
|
|
75
|
-
catch (_error) {
|
|
76
|
-
// This is expected if the config does not exist.
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
50
|
const gptSetupNote = isGptClientRequired
|
|
82
51
|
? ` *
|
|
83
52
|
* Also, since this test is using tools that require the usage of an LLM, be
|
|
84
53
|
* sure to have an appropriate LLM API key available as an environment variable
|
|
85
|
-
* (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY,
|
|
54
|
+
* (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, or GOOGLE_GENERATIVE_AI_API_KEY).
|
|
86
55
|
`
|
|
87
56
|
: ' ';
|
|
88
57
|
const hasObjective = (flowMetadata.overallObjective?.trim().length ?? 0) > 0;
|
|
@@ -108,22 +77,9 @@ class CodeGenerator {
|
|
|
108
77
|
const useStorageState = flowMetadata.browser && flowMetadata.browser.initialState
|
|
109
78
|
? `storageState: getBrowserStorageStateFixture(${JSON.stringify(flowMetadata.browser.initialState, null, 2)}),`
|
|
110
79
|
: undefined;
|
|
111
|
-
let useGptClientImport = undefined;
|
|
112
|
-
let useGptClient = undefined;
|
|
113
|
-
if (isGptClientRequired) {
|
|
114
|
-
if (gptConfig && gptConfig.type === 'ANTHROPIC_AWS_BEDROCK') {
|
|
115
|
-
useGptClientImport =
|
|
116
|
-
"import { anthropicAwsBedrockClientFixture } from 'donobu';";
|
|
117
|
-
useGptClient = `gptClient: anthropicAwsBedrockClientFixture('${gptConfig.modelName}', '${gptConfig.region}'),`;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
useGptClientImport = "import { gptClientFixture } from 'donobu';";
|
|
121
|
-
useGptClient = `gptClient: gptClientFixture(),`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
80
|
let testExtension = '';
|
|
125
|
-
if (useStorageState
|
|
126
|
-
testExtension = `.extend({${useStorageState
|
|
81
|
+
if (useStorageState) {
|
|
82
|
+
testExtension = `.extend({${useStorageState}})`;
|
|
127
83
|
}
|
|
128
84
|
const scriptedToolCalls = toolCalls
|
|
129
85
|
.filter((toolCall) => !unsupportedToolsByName.has(toolCall.name))
|
|
@@ -143,7 +99,7 @@ testInfo.attach('extracted-object', { body: JSON.stringify(extractedObject), con
|
|
|
143
99
|
* Also, be sure that Playwright's browsers are installed...
|
|
144
100
|
* 'npx playwright install'
|
|
145
101
|
${gptSetupNote}*/
|
|
146
|
-
import { test } from 'donobu';${
|
|
102
|
+
import { test } from 'donobu';${useStorageState ? "\nimport { getBrowserStorageStateFixture } from 'donobu';" : ''}
|
|
147
103
|
|
|
148
104
|
const testTitle = '${testName}';
|
|
149
105
|
const testDetails = ${testDetails};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeGenerator.js","sourceRoot":"","sources":["../../src/managers/CodeGenerator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CodeGenerator.js","sourceRoot":"","sources":["../../src/managers/CodeGenerator.ts"],"names":[],"mappings":";;;AAEA,sEAAmE;AACnE,oEAAiE;AACjE,oDAAiD;AACjD,8EAA2E;AAC3E,4EAAyE;AACzE,kDAA+C;AAC/C,0FAAuF;AACvF,sEAAmE;AACnE,8DAA2D;AAC3D,wEAAqE;AACrE,8FAA2F;AAC3F,0DAAuD;AACvD,8DAA2D;AAC3D,kFAA+E;AAC/E,8FAA2F;AAC3F,wDAAqD;AACrD,4DAAyD;AACzD,gFAA6E;AAC7E,4DAAyD;AACzD,4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IAAI,CAAC;YAC1C,KAAK,6BAAa,CAAC,IAAI,CAAC;YACxB,KAAK,2BAAY,CAAC,IAAI,CAAC;YACvB,KAAK,mDAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnC,OAAO,GAAG,SAAS,cAAc,gBAAgB,CAAC,IAAI,IAAI,qBAAqB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;YAC9G,CAAC;YACD;gBACE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC;gBACvC,MAAM,cAAc,GAAG,qBAAqB;oBAC1C,CAAC,CAAC,GAAG,SAAS,mBAAmB,QAAQ,MAAM,gBAAgB,IAAI;oBACnE,CAAC,CAAC,GAAG,SAAS,mBAAmB,QAAQ,KAAK,CAAC;gBACjD,OAAO,cAAc,CAAC;QAC1B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,IAAY;QACrC,iEAAiE;QACjE,kDAAkD;QAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;YAC1C,MAAM,EAAE,YAAY;YACpB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACK,0BAA0B,CAAC,UAAkB;QACnD,OAAO,CACL,UAAU;YACR,2DAA2D;aAC1D,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;YACrB,yDAAyD;aACxD,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAC3B,CAAC;IACJ,CAAC;CACF;AApMD,sCAoMC"}
|
|
@@ -106,8 +106,21 @@ export declare class DonobuFlowsManager {
|
|
|
106
106
|
private validateFlowParams;
|
|
107
107
|
private setupAllowedTools;
|
|
108
108
|
private prepareInitialToolCalls;
|
|
109
|
+
/**
|
|
110
|
+
* This method creates a temporary directory for the flow with the given ID,
|
|
111
|
+
* returning the path to the directory.
|
|
112
|
+
*/
|
|
109
113
|
private createTempDirectoryForFlow;
|
|
114
|
+
/**
|
|
115
|
+
* Searches the given directory for the largest video file and sets it as the
|
|
116
|
+
* flow's video. This should be called after the flow has completed.
|
|
117
|
+
*/
|
|
118
|
+
private setFlowVideo;
|
|
110
119
|
private runFlow;
|
|
120
|
+
/**
|
|
121
|
+
* Returns the largest video file in the given directory, or null if no
|
|
122
|
+
* video files are found.
|
|
123
|
+
*/
|
|
111
124
|
private findLargestVideo;
|
|
112
125
|
private isLocallyRunning;
|
|
113
126
|
private checkIfAnyToolsRequireGpt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DonobuFlowsManager.d.ts","sourceRoot":"","sources":["../../src/managers/DonobuFlowsManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AASjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAuB,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAQ9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAEL,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AAUzC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAIpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAA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,IAAI,CAAC;IAwB1D;;;;OAIG;IACU,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAmB9D,8EAA8E;IACjE,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAavE;;;;;;;QAOI;IACS,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;QAClE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,SAAS,EAAE,WAAW,GAAG,IAAI,CAAC;QAC9B,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;KAC7B,CAAC;IAmGF;;;OAGG;IACU,sBAAsB,CACjC,eAAe,EAAE,qBAAqB,GACrC,OAAO,CAAC,mBAAmB,CAAC;IAsC/B,OAAO,CAAC,kBAAkB;IA8F1B,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,uBAAuB;IAsB/B;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IAMlC;;;OAGG;YACW,YAAY;YAaZ,OAAO;IA2BrB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,yBAAyB;IAyBjC,OAAO,CAAC,wBAAwB;IA0DhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;IAYvB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAGjC"}
|
|
@@ -63,6 +63,7 @@ const DonobuDeploymentEnvironment_1 = require("../models/DonobuDeploymentEnviron
|
|
|
63
63
|
const Logger_1 = require("../utils/Logger");
|
|
64
64
|
const CodeGenerator_1 = require("./CodeGenerator");
|
|
65
65
|
const uuid_1 = require("uuid");
|
|
66
|
+
const envVars_1 = require("../envVars");
|
|
66
67
|
class DonobuFlowsManager {
|
|
67
68
|
constructor(deploymentEnvironment, gptConfigsManager, agentsManager, flowsPersistenceFactory) {
|
|
68
69
|
this.deploymentEnvironment = deploymentEnvironment;
|
|
@@ -70,7 +71,7 @@ class DonobuFlowsManager {
|
|
|
70
71
|
this.agentsManager = agentsManager;
|
|
71
72
|
this.flowsPersistenceFactory = flowsPersistenceFactory;
|
|
72
73
|
this.activeFlows = new Map();
|
|
73
|
-
this.codeGenerator = new CodeGenerator_1.CodeGenerator(
|
|
74
|
+
this.codeGenerator = new CodeGenerator_1.CodeGenerator();
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
77
|
* Create a flow with the given parameters and invoke its `DonobuFlow#run`
|
|
@@ -132,18 +133,18 @@ class DonobuFlowsManager {
|
|
|
132
133
|
state: 'UNSTARTED',
|
|
133
134
|
nextState: null,
|
|
134
135
|
};
|
|
135
|
-
const
|
|
136
|
+
const flowTempDir = this.createTempDirectoryForFlow(flowMetadata.id);
|
|
136
137
|
const flowsPersistence = await this.flowsPersistenceFactory.createPersistenceLayer();
|
|
137
138
|
const browserStorageState = flowParams.browser?.initialState
|
|
138
139
|
? await this.getBrowserStorageState(flowParams.browser.initialState)
|
|
139
140
|
: undefined;
|
|
140
|
-
const browserFramework = await BrowserFramework_1.BrowserFramework.create(browserConfig,
|
|
141
|
+
const browserFramework = await BrowserFramework_1.BrowserFramework.create(browserConfig, flowTempDir, browserStorageState);
|
|
141
142
|
try {
|
|
142
143
|
const donobuFlow = new DonobuFlow_1.DonobuFlow(this, browserFramework, flowsPersistence, gptClientData.gptClient, toolManager, tooltipper, toolCallsOnStart, [], [], {
|
|
143
144
|
current: null,
|
|
144
145
|
}, flowMetadata);
|
|
145
146
|
await flowsPersistence.saveMetadata(flowMetadata);
|
|
146
|
-
const job = this.runFlow(donobuFlow,
|
|
147
|
+
const job = this.runFlow(donobuFlow, flowTempDir, flowsPersistence);
|
|
147
148
|
const flowHandle = { donobuFlow, job };
|
|
148
149
|
this.activeFlows.set(flowMetadata.id, flowHandle);
|
|
149
150
|
return flowHandle;
|
|
@@ -424,6 +425,51 @@ class DonobuFlowsManager {
|
|
|
424
425
|
Logger_1.appLogger.warn(`Failed to find GPT configuration: ${gptConfigName}, will default to the 'flow-runner' agent config (if it exists).`);
|
|
425
426
|
}
|
|
426
427
|
}
|
|
428
|
+
let gptConfigFromEnv = null;
|
|
429
|
+
if (process.env[envVars_1.ENV_VAR_NAMES.AWS_BEDROCK_MODEL_NAME]) {
|
|
430
|
+
gptConfigFromEnv = {
|
|
431
|
+
type: 'ANTHROPIC_AWS_BEDROCK',
|
|
432
|
+
modelName: process.env[envVars_1.ENV_VAR_NAMES.AWS_BEDROCK_MODEL_NAME],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
else if (process.env[envVars_1.ENV_VAR_NAMES.ANTHROPIC_MODEL_NAME]) {
|
|
436
|
+
if (!process.env[envVars_1.ENV_VAR_NAMES.ANTHROPIC_API_KEY]) {
|
|
437
|
+
throw new InvalidParamValueException_1.InvalidParamValueException(envVars_1.ENV_VAR_NAMES.ANTHROPIC_API_KEY, undefined, `the ${envVars_1.ENV_VAR_NAMES.ANTHROPIC_MODEL_NAME} environment variable is set but the ${envVars_1.ENV_VAR_NAMES.ANTHROPIC_API_KEY} is not`);
|
|
438
|
+
}
|
|
439
|
+
gptConfigFromEnv = {
|
|
440
|
+
type: 'ANTHROPIC',
|
|
441
|
+
modelName: process.env[envVars_1.ENV_VAR_NAMES.ANTHROPIC_MODEL_NAME],
|
|
442
|
+
apiKey: process.env[envVars_1.ENV_VAR_NAMES.ANTHROPIC_API_KEY],
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
else if (process.env[envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_MODEL_NAME]) {
|
|
446
|
+
if (!process.env[envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_API_KEY]) {
|
|
447
|
+
throw new InvalidParamValueException_1.InvalidParamValueException(envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_API_KEY, undefined, `the ${envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_MODEL_NAME} environment variable is set but the ${envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_API_KEY} is not`);
|
|
448
|
+
}
|
|
449
|
+
gptConfigFromEnv = {
|
|
450
|
+
type: 'GOOGLE_GEMINI',
|
|
451
|
+
modelName: process.env[envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_MODEL_NAME],
|
|
452
|
+
apiKey: process.env[envVars_1.ENV_VAR_NAMES.GOOGLE_GENERATIVE_AI_API_KEY],
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
else if (process.env[envVars_1.ENV_VAR_NAMES.OPENAI_API_MODEL_NAME]) {
|
|
456
|
+
if (!process.env[envVars_1.ENV_VAR_NAMES.OPENAI_API_KEY]) {
|
|
457
|
+
throw new InvalidParamValueException_1.InvalidParamValueException(envVars_1.ENV_VAR_NAMES.OPENAI_API_KEY, undefined, `the ${envVars_1.ENV_VAR_NAMES.OPENAI_API_MODEL_NAME} environment variable is set but the ${envVars_1.ENV_VAR_NAMES.OPENAI_API_KEY} is not`);
|
|
458
|
+
}
|
|
459
|
+
gptConfigFromEnv = {
|
|
460
|
+
type: 'OPENAI',
|
|
461
|
+
modelName: process.env[envVars_1.ENV_VAR_NAMES.OPENAI_API_MODEL_NAME],
|
|
462
|
+
apiKey: process.env[envVars_1.ENV_VAR_NAMES.OPENAI_API_KEY],
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
if (gptConfigFromEnv) {
|
|
466
|
+
const gptClient = await GptClientFactory_1.GptClientFactory.createFromGptConfig(gptConfigFromEnv);
|
|
467
|
+
return {
|
|
468
|
+
gptConfigName: null,
|
|
469
|
+
agentName: null,
|
|
470
|
+
gptClient: gptClient,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
427
473
|
const defaultGptConfigName = await this.agentsManager.get('flow-runner');
|
|
428
474
|
if (!defaultGptConfigName) {
|
|
429
475
|
return {
|
|
@@ -432,8 +478,8 @@ class DonobuFlowsManager {
|
|
|
432
478
|
gptClient: null,
|
|
433
479
|
};
|
|
434
480
|
}
|
|
435
|
-
const
|
|
436
|
-
const gptClient = await GptClientFactory_1.GptClientFactory.createFromGptConfig(
|
|
481
|
+
const defaultGptConfig = await this.gptConfigsManager.get(defaultGptConfigName);
|
|
482
|
+
const gptClient = await GptClientFactory_1.GptClientFactory.createFromGptConfig(defaultGptConfig);
|
|
437
483
|
return {
|
|
438
484
|
gptConfigName: defaultGptConfigName,
|
|
439
485
|
agentName: 'flow-runner',
|
|
@@ -561,25 +607,50 @@ class DonobuFlowsManager {
|
|
|
561
607
|
return [];
|
|
562
608
|
}
|
|
563
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* This method creates a temporary directory for the flow with the given ID,
|
|
612
|
+
* returning the path to the directory.
|
|
613
|
+
*/
|
|
564
614
|
createTempDirectoryForFlow(flowId) {
|
|
565
615
|
const tempDir = path.join((0, os_1.tmpdir)(), flowId);
|
|
566
616
|
fs.mkdirSync(tempDir);
|
|
567
617
|
return tempDir;
|
|
568
618
|
}
|
|
569
|
-
|
|
619
|
+
/**
|
|
620
|
+
* Searches the given directory for the largest video file and sets it as the
|
|
621
|
+
* flow's video. This should be called after the flow has completed.
|
|
622
|
+
*/
|
|
623
|
+
async setFlowVideo(flowId, flowTempDir, flowsPersistence) {
|
|
624
|
+
const videoPath = this.findLargestVideo(flowTempDir);
|
|
625
|
+
if (videoPath) {
|
|
626
|
+
const videoBytes = fs.readFileSync(videoPath);
|
|
627
|
+
await flowsPersistence.setVideo(flowId, videoBytes);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async runFlow(donobuFlow, flowTempDir, flowsPersistence) {
|
|
570
631
|
try {
|
|
571
632
|
await donobuFlow.run();
|
|
572
|
-
this.
|
|
573
|
-
const videoPath = this.findLargestVideo(tempDirectoryForVideos);
|
|
574
|
-
if (videoPath) {
|
|
575
|
-
const videoBytes = fs.readFileSync(videoPath);
|
|
576
|
-
await flowsPersistence.setVideo(donobuFlow.metadata.id, videoBytes);
|
|
577
|
-
}
|
|
633
|
+
await this.setFlowVideo(donobuFlow.metadata.id, flowTempDir, flowsPersistence);
|
|
578
634
|
}
|
|
579
635
|
finally {
|
|
580
|
-
|
|
636
|
+
try {
|
|
637
|
+
this.activeFlows.delete(donobuFlow.metadata.id);
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
Logger_1.appLogger.error('Failed to delete active flow:', error);
|
|
641
|
+
}
|
|
642
|
+
try {
|
|
643
|
+
fs.rmSync(flowTempDir, { recursive: true, force: true });
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
Logger_1.appLogger.error('Failed to remove temporary directory:', error);
|
|
647
|
+
}
|
|
581
648
|
}
|
|
582
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* Returns the largest video file in the given directory, or null if no
|
|
652
|
+
* video files are found.
|
|
653
|
+
*/
|
|
583
654
|
findLargestVideo(directory) {
|
|
584
655
|
const files = fs
|
|
585
656
|
.readdirSync(directory)
|