@eko-ai/eko 1.0.13 → 1.0.15-alpha.0
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/common/chrome/proxy.d.ts +38 -0
- package/dist/common/tools/cancel_workflow.d.ts +9 -0
- package/dist/common/tools/human.d.ts +30 -0
- package/dist/common/tools/index.d.ts +4 -0
- package/dist/common/tools/summary_workflow.d.ts +9 -0
- package/dist/core/chrome-proxy.d.ts +10 -0
- package/dist/extension/script/build_dom_tree.js +1 -0
- package/dist/extension.cjs.js +64 -31
- package/dist/extension.esm.js +64 -31
- package/dist/extension_content_script.js +1 -1
- package/dist/index.cjs.js +18 -14
- package/dist/index.esm.js +18 -14
- package/dist/nodejs.cjs.js +62 -29
- package/dist/nodejs.esm.js +62 -29
- package/dist/services/chrome/chrome-proxy.d.ts +10 -0
- package/dist/services/llm/deepseek-provider.d.ts +2 -0
- package/dist/types/workflow.types.d.ts +2 -0
- package/dist/web/tools/index.d.ts +1 -0
- package/dist/web.cjs.js +241 -1
- package/dist/web.esm.js +241 -1
- package/package.json +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a proxy for the Chrome API.
|
|
3
|
+
* This function creates a proxy for the Chrome API, allowing for interception and modification of certain methods.
|
|
4
|
+
* The main logic involves creating a proxy for the `chrome` namespaces.
|
|
5
|
+
* If a method exists in the mock implementation (e.g., `a` or `a_b` or `a_b_c` and so on), it will be used; otherwise, the original Chrome API method will be called.
|
|
6
|
+
* @param chromeProxy - An object that provides mock implementations of Chrome API methods.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* class MyChromeProxy {
|
|
10
|
+
* chrome.events.Event<(tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => void>.removeListener(callback: (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => void): void
|
|
11
|
+
* public static tabs_onUpdated_removeListener(callback: (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => void): void {
|
|
12
|
+
* console.log(callback);
|
|
13
|
+
* return chrome.tabs.onUpdated.removeListener(callback);
|
|
14
|
+
* }
|
|
15
|
+
* public static tabs_get(tabId: number): Promise<chrome.tabs.Tab> {
|
|
16
|
+
* console.log(tabId);
|
|
17
|
+
* return chrome.tabs.get(tabId);
|
|
18
|
+
* }
|
|
19
|
+
* public static windows_create(createData: chrome.windows.CreateData): Promise<chrome.windows.Window> {
|
|
20
|
+
* console.log(createData);
|
|
21
|
+
* return chrome.windows.create(createData);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* setChromeProxy(MyChromeProxy);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function setChromeProxy(chromeProxy: any): void;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the current Chrome API proxy.
|
|
30
|
+
* This function returns the proxy object created by `setChromeProxy`, which can be used to access the proxied Chrome API methods.
|
|
31
|
+
* @returns The proxied Chrome API object.
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* getChromeProxy().tabs.get(1).then(tab => console.log(tab));
|
|
35
|
+
* ```
|
|
36
|
+
* In this example, `getChromeProxy` is used to retrieve the proxied Chrome API object, and then `tabs.get` is called on it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getChromeProxy(): any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CancelWorkflowInput } from '../../types/tools.types';
|
|
2
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
3
|
+
export declare class CancelWorkflow implements Tool<CancelWorkflowInput, void> {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
input_schema: InputSchema;
|
|
7
|
+
constructor();
|
|
8
|
+
execute(context: ExecutionContext, params: CancelWorkflowInput): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HumanInputTextInput, HumanInputTextResult, HumanInputSingleChoiceInput, HumanInputSingleChoiceResult, HumanInputMultipleChoiceInput, HumanInputMultipleChoiceResult, HumanOperateInput, HumanOperateResult } from '../../types/tools.types';
|
|
2
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
3
|
+
export declare class HumanInputText implements Tool<HumanInputTextInput, HumanInputTextResult> {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
input_schema: InputSchema;
|
|
7
|
+
constructor();
|
|
8
|
+
execute(context: ExecutionContext, params: HumanInputTextInput): Promise<HumanInputTextResult>;
|
|
9
|
+
}
|
|
10
|
+
export declare class HumanInputSingleChoice implements Tool<HumanInputSingleChoiceInput, HumanInputSingleChoiceResult> {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
input_schema: InputSchema;
|
|
14
|
+
constructor();
|
|
15
|
+
execute(context: ExecutionContext, params: HumanInputSingleChoiceInput): Promise<HumanInputSingleChoiceResult>;
|
|
16
|
+
}
|
|
17
|
+
export declare class HumanInputMultipleChoice implements Tool<HumanInputMultipleChoiceInput, HumanInputMultipleChoiceResult> {
|
|
18
|
+
name: string;
|
|
19
|
+
description: string;
|
|
20
|
+
input_schema: InputSchema;
|
|
21
|
+
constructor();
|
|
22
|
+
execute(context: ExecutionContext, params: HumanInputMultipleChoiceInput): Promise<HumanInputMultipleChoiceResult>;
|
|
23
|
+
}
|
|
24
|
+
export declare class HumanOperate implements Tool<HumanOperateInput, HumanOperateResult> {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
input_schema: InputSchema;
|
|
28
|
+
constructor();
|
|
29
|
+
execute(context: ExecutionContext, params: HumanOperateInput): Promise<HumanOperateResult>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CancelWorkflow } from "./cancel_workflow";
|
|
2
|
+
import { HumanInputText, HumanInputSingleChoice, HumanInputMultipleChoice, HumanOperate } from "./human";
|
|
3
|
+
import { SummaryWorkflow } from "./summary_workflow";
|
|
4
|
+
export { CancelWorkflow, HumanInputText, HumanInputSingleChoice, HumanInputMultipleChoice, HumanOperate, SummaryWorkflow, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SummaryWorkflowInput } from '../../types/tools.types';
|
|
2
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
3
|
+
export declare class SummaryWorkflow implements Tool<SummaryWorkflowInput, any> {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
input_schema: InputSchema;
|
|
7
|
+
constructor();
|
|
8
|
+
execute(context: ExecutionContext, params: SummaryWorkflowInput): Promise<any>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ChromeMock {
|
|
2
|
+
static tabs_create(createProperties: chrome.tabs.CreateProperties): Promise<chrome.tabs.Tab>;
|
|
3
|
+
static tabs_get(tabId: number): Promise<chrome.tabs.Tab>;
|
|
4
|
+
static tabs_remove(tabId: number): Promise<void>;
|
|
5
|
+
static windows_create(createData: chrome.windows.CreateData): Promise<chrome.windows.Window>;
|
|
6
|
+
static windows_get(windowId: number): Promise<chrome.windows.Window>;
|
|
7
|
+
static windows_getCurrent(): Promise<chrome.windows.Window>;
|
|
8
|
+
static windows_remove(windowId: number): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare const ChromeProxy: any;
|
package/dist/extension.cjs.js
CHANGED
|
@@ -1120,10 +1120,11 @@ class ExportFile {
|
|
|
1120
1120
|
* @returns > { success: true }
|
|
1121
1121
|
*/
|
|
1122
1122
|
async execute(context, params) {
|
|
1123
|
-
var _a, _b, _c;
|
|
1123
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1124
1124
|
if (typeof params !== 'object' || params === null || !('content' in params)) {
|
|
1125
1125
|
throw new Error('Invalid parameters. Expected an object with a "content" property.');
|
|
1126
1126
|
}
|
|
1127
|
+
await ((_c = (_b = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks) === null || _b === undefined ? undefined : _b.onExportFile) === null || _c === undefined ? undefined : _c.call(_b, params));
|
|
1127
1128
|
let type = 'text/plain';
|
|
1128
1129
|
switch (params.fileType) {
|
|
1129
1130
|
case 'csv':
|
|
@@ -1172,7 +1173,7 @@ class ExportFile {
|
|
|
1172
1173
|
else {
|
|
1173
1174
|
tab = await open_new_tab(url, true);
|
|
1174
1175
|
}
|
|
1175
|
-
(
|
|
1176
|
+
(_f = (_e = (_d = context.callback) === null || _d === undefined ? undefined : _d.hooks) === null || _e === undefined ? undefined : _e.onTabCreated) === null || _f === undefined ? undefined : _f.call(_e, tab.id);
|
|
1176
1177
|
let tabId = tab.id;
|
|
1177
1178
|
await chrome.scripting.executeScript({
|
|
1178
1179
|
target: { tabId: tabId },
|
|
@@ -2076,21 +2077,29 @@ class HumanInputText {
|
|
|
2076
2077
|
};
|
|
2077
2078
|
}
|
|
2078
2079
|
async execute(context, params) {
|
|
2079
|
-
var _a
|
|
2080
|
+
var _a;
|
|
2080
2081
|
if (typeof params !== 'object' || params === null || !params.question) {
|
|
2081
2082
|
throw new Error('Invalid parameters. Expected an object with a "question" property.');
|
|
2082
2083
|
}
|
|
2083
2084
|
const question = params.question;
|
|
2084
2085
|
console.log("question: " + question);
|
|
2085
|
-
let
|
|
2086
|
-
if (
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2086
|
+
let onHumanInputText = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputText;
|
|
2087
|
+
if (onHumanInputText) {
|
|
2088
|
+
let answer;
|
|
2089
|
+
try {
|
|
2090
|
+
answer = await onHumanInputText(question);
|
|
2091
|
+
}
|
|
2092
|
+
catch (e) {
|
|
2093
|
+
console.error(e);
|
|
2094
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2095
|
+
}
|
|
2091
2096
|
console.log("answer: " + answer);
|
|
2092
2097
|
return { status: "OK", answer: answer };
|
|
2093
2098
|
}
|
|
2099
|
+
else {
|
|
2100
|
+
console.error("`onHumanInputText` not implemented");
|
|
2101
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2102
|
+
}
|
|
2094
2103
|
}
|
|
2095
2104
|
}
|
|
2096
2105
|
class HumanInputSingleChoice {
|
|
@@ -2113,7 +2122,7 @@ class HumanInputSingleChoice {
|
|
|
2113
2122
|
};
|
|
2114
2123
|
}
|
|
2115
2124
|
async execute(context, params) {
|
|
2116
|
-
var _a
|
|
2125
|
+
var _a;
|
|
2117
2126
|
if (typeof params !== 'object' || params === null || !params.question || !params.choices) {
|
|
2118
2127
|
throw new Error('Invalid parameters. Expected an object with a "question" and "choices" property.');
|
|
2119
2128
|
}
|
|
@@ -2121,15 +2130,23 @@ class HumanInputSingleChoice {
|
|
|
2121
2130
|
const choices = params.choices;
|
|
2122
2131
|
console.log("question: " + question);
|
|
2123
2132
|
console.log("choices: " + choices);
|
|
2124
|
-
let
|
|
2125
|
-
if (
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2133
|
+
let onHumanInputSingleChoice = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputSingleChoice;
|
|
2134
|
+
if (onHumanInputSingleChoice) {
|
|
2135
|
+
let answer;
|
|
2136
|
+
try {
|
|
2137
|
+
answer = await onHumanInputSingleChoice(question, choices);
|
|
2138
|
+
}
|
|
2139
|
+
catch (e) {
|
|
2140
|
+
console.error(e);
|
|
2141
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2142
|
+
}
|
|
2130
2143
|
console.log("answer: " + answer);
|
|
2131
2144
|
return { status: "OK", answer: answer };
|
|
2132
2145
|
}
|
|
2146
|
+
else {
|
|
2147
|
+
console.error("`onHumanInputSingleChoice` not implemented");
|
|
2148
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2149
|
+
}
|
|
2133
2150
|
}
|
|
2134
2151
|
}
|
|
2135
2152
|
class HumanInputMultipleChoice {
|
|
@@ -2152,7 +2169,7 @@ class HumanInputMultipleChoice {
|
|
|
2152
2169
|
};
|
|
2153
2170
|
}
|
|
2154
2171
|
async execute(context, params) {
|
|
2155
|
-
var _a
|
|
2172
|
+
var _a;
|
|
2156
2173
|
if (typeof params !== 'object' || params === null || !params.question || !params.choices) {
|
|
2157
2174
|
throw new Error('Invalid parameters. Expected an object with a "question" and "choices" property.');
|
|
2158
2175
|
}
|
|
@@ -2160,15 +2177,23 @@ class HumanInputMultipleChoice {
|
|
|
2160
2177
|
const choices = params.choices;
|
|
2161
2178
|
console.log("question: " + question);
|
|
2162
2179
|
console.log("choices: " + choices);
|
|
2163
|
-
let
|
|
2164
|
-
if (
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2180
|
+
let onHumanInputMultipleChoice = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputMultipleChoice;
|
|
2181
|
+
if (onHumanInputMultipleChoice) {
|
|
2182
|
+
let answer;
|
|
2183
|
+
try {
|
|
2184
|
+
answer = await onHumanInputMultipleChoice(question, choices);
|
|
2185
|
+
}
|
|
2186
|
+
catch (e) {
|
|
2187
|
+
console.error(e);
|
|
2188
|
+
return { status: "`onHumanInputMultipleChoice` not implemented", answer: [] };
|
|
2189
|
+
}
|
|
2169
2190
|
console.log("answer: " + answer);
|
|
2170
2191
|
return { status: "OK", answer: answer };
|
|
2171
2192
|
}
|
|
2193
|
+
else {
|
|
2194
|
+
console.error("Cannot get user's answer.");
|
|
2195
|
+
return { status: "Error: Cannot get user's answer.", answer: [] };
|
|
2196
|
+
}
|
|
2172
2197
|
}
|
|
2173
2198
|
}
|
|
2174
2199
|
class HumanOperate {
|
|
@@ -2187,28 +2212,36 @@ class HumanOperate {
|
|
|
2187
2212
|
};
|
|
2188
2213
|
}
|
|
2189
2214
|
async execute(context, params) {
|
|
2190
|
-
var _a
|
|
2215
|
+
var _a;
|
|
2191
2216
|
if (typeof params !== 'object' || params === null || !params.reason) {
|
|
2192
2217
|
throw new Error('Invalid parameters. Expected an object with a "reason" property.');
|
|
2193
2218
|
}
|
|
2194
2219
|
const reason = params.reason;
|
|
2195
2220
|
console.log("reason: " + reason);
|
|
2196
|
-
let
|
|
2197
|
-
if (
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2221
|
+
let onHumanOperate = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanOperate;
|
|
2222
|
+
if (onHumanOperate) {
|
|
2223
|
+
let userOperation;
|
|
2224
|
+
try {
|
|
2225
|
+
userOperation = await onHumanOperate(reason);
|
|
2226
|
+
}
|
|
2227
|
+
catch (e) {
|
|
2228
|
+
console.error(e);
|
|
2229
|
+
return { status: "`onHumanOperate` not implemented", userOperation: "" };
|
|
2230
|
+
}
|
|
2202
2231
|
console.log("userOperation: " + userOperation);
|
|
2203
2232
|
return { status: "OK", userOperation: userOperation };
|
|
2204
2233
|
}
|
|
2234
|
+
else {
|
|
2235
|
+
console.error("Cannot get user's operation.");
|
|
2236
|
+
return { status: "Error: Cannot get user's operation.", userOperation: "" };
|
|
2237
|
+
}
|
|
2205
2238
|
}
|
|
2206
2239
|
}
|
|
2207
2240
|
|
|
2208
2241
|
class SummaryWorkflow {
|
|
2209
2242
|
constructor() {
|
|
2210
2243
|
this.name = 'summary_workflow';
|
|
2211
|
-
this.description = 'Summarize what this workflow has
|
|
2244
|
+
this.description = 'Summarize briefly what this workflow has accomplished.';
|
|
2212
2245
|
this.input_schema = {
|
|
2213
2246
|
type: 'object',
|
|
2214
2247
|
properties: {
|
package/dist/extension.esm.js
CHANGED
|
@@ -1118,10 +1118,11 @@ class ExportFile {
|
|
|
1118
1118
|
* @returns > { success: true }
|
|
1119
1119
|
*/
|
|
1120
1120
|
async execute(context, params) {
|
|
1121
|
-
var _a, _b, _c;
|
|
1121
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1122
1122
|
if (typeof params !== 'object' || params === null || !('content' in params)) {
|
|
1123
1123
|
throw new Error('Invalid parameters. Expected an object with a "content" property.');
|
|
1124
1124
|
}
|
|
1125
|
+
await ((_c = (_b = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks) === null || _b === undefined ? undefined : _b.onExportFile) === null || _c === undefined ? undefined : _c.call(_b, params));
|
|
1125
1126
|
let type = 'text/plain';
|
|
1126
1127
|
switch (params.fileType) {
|
|
1127
1128
|
case 'csv':
|
|
@@ -1170,7 +1171,7 @@ class ExportFile {
|
|
|
1170
1171
|
else {
|
|
1171
1172
|
tab = await open_new_tab(url, true);
|
|
1172
1173
|
}
|
|
1173
|
-
(
|
|
1174
|
+
(_f = (_e = (_d = context.callback) === null || _d === undefined ? undefined : _d.hooks) === null || _e === undefined ? undefined : _e.onTabCreated) === null || _f === undefined ? undefined : _f.call(_e, tab.id);
|
|
1174
1175
|
let tabId = tab.id;
|
|
1175
1176
|
await chrome.scripting.executeScript({
|
|
1176
1177
|
target: { tabId: tabId },
|
|
@@ -2074,21 +2075,29 @@ class HumanInputText {
|
|
|
2074
2075
|
};
|
|
2075
2076
|
}
|
|
2076
2077
|
async execute(context, params) {
|
|
2077
|
-
var _a
|
|
2078
|
+
var _a;
|
|
2078
2079
|
if (typeof params !== 'object' || params === null || !params.question) {
|
|
2079
2080
|
throw new Error('Invalid parameters. Expected an object with a "question" property.');
|
|
2080
2081
|
}
|
|
2081
2082
|
const question = params.question;
|
|
2082
2083
|
console.log("question: " + question);
|
|
2083
|
-
let
|
|
2084
|
-
if (
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2084
|
+
let onHumanInputText = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputText;
|
|
2085
|
+
if (onHumanInputText) {
|
|
2086
|
+
let answer;
|
|
2087
|
+
try {
|
|
2088
|
+
answer = await onHumanInputText(question);
|
|
2089
|
+
}
|
|
2090
|
+
catch (e) {
|
|
2091
|
+
console.error(e);
|
|
2092
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2093
|
+
}
|
|
2089
2094
|
console.log("answer: " + answer);
|
|
2090
2095
|
return { status: "OK", answer: answer };
|
|
2091
2096
|
}
|
|
2097
|
+
else {
|
|
2098
|
+
console.error("`onHumanInputText` not implemented");
|
|
2099
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2100
|
+
}
|
|
2092
2101
|
}
|
|
2093
2102
|
}
|
|
2094
2103
|
class HumanInputSingleChoice {
|
|
@@ -2111,7 +2120,7 @@ class HumanInputSingleChoice {
|
|
|
2111
2120
|
};
|
|
2112
2121
|
}
|
|
2113
2122
|
async execute(context, params) {
|
|
2114
|
-
var _a
|
|
2123
|
+
var _a;
|
|
2115
2124
|
if (typeof params !== 'object' || params === null || !params.question || !params.choices) {
|
|
2116
2125
|
throw new Error('Invalid parameters. Expected an object with a "question" and "choices" property.');
|
|
2117
2126
|
}
|
|
@@ -2119,15 +2128,23 @@ class HumanInputSingleChoice {
|
|
|
2119
2128
|
const choices = params.choices;
|
|
2120
2129
|
console.log("question: " + question);
|
|
2121
2130
|
console.log("choices: " + choices);
|
|
2122
|
-
let
|
|
2123
|
-
if (
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2131
|
+
let onHumanInputSingleChoice = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputSingleChoice;
|
|
2132
|
+
if (onHumanInputSingleChoice) {
|
|
2133
|
+
let answer;
|
|
2134
|
+
try {
|
|
2135
|
+
answer = await onHumanInputSingleChoice(question, choices);
|
|
2136
|
+
}
|
|
2137
|
+
catch (e) {
|
|
2138
|
+
console.error(e);
|
|
2139
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2140
|
+
}
|
|
2128
2141
|
console.log("answer: " + answer);
|
|
2129
2142
|
return { status: "OK", answer: answer };
|
|
2130
2143
|
}
|
|
2144
|
+
else {
|
|
2145
|
+
console.error("`onHumanInputSingleChoice` not implemented");
|
|
2146
|
+
return { status: "Error: Cannot get user's answer.", answer: "" };
|
|
2147
|
+
}
|
|
2131
2148
|
}
|
|
2132
2149
|
}
|
|
2133
2150
|
class HumanInputMultipleChoice {
|
|
@@ -2150,7 +2167,7 @@ class HumanInputMultipleChoice {
|
|
|
2150
2167
|
};
|
|
2151
2168
|
}
|
|
2152
2169
|
async execute(context, params) {
|
|
2153
|
-
var _a
|
|
2170
|
+
var _a;
|
|
2154
2171
|
if (typeof params !== 'object' || params === null || !params.question || !params.choices) {
|
|
2155
2172
|
throw new Error('Invalid parameters. Expected an object with a "question" and "choices" property.');
|
|
2156
2173
|
}
|
|
@@ -2158,15 +2175,23 @@ class HumanInputMultipleChoice {
|
|
|
2158
2175
|
const choices = params.choices;
|
|
2159
2176
|
console.log("question: " + question);
|
|
2160
2177
|
console.log("choices: " + choices);
|
|
2161
|
-
let
|
|
2162
|
-
if (
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2178
|
+
let onHumanInputMultipleChoice = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanInputMultipleChoice;
|
|
2179
|
+
if (onHumanInputMultipleChoice) {
|
|
2180
|
+
let answer;
|
|
2181
|
+
try {
|
|
2182
|
+
answer = await onHumanInputMultipleChoice(question, choices);
|
|
2183
|
+
}
|
|
2184
|
+
catch (e) {
|
|
2185
|
+
console.error(e);
|
|
2186
|
+
return { status: "`onHumanInputMultipleChoice` not implemented", answer: [] };
|
|
2187
|
+
}
|
|
2167
2188
|
console.log("answer: " + answer);
|
|
2168
2189
|
return { status: "OK", answer: answer };
|
|
2169
2190
|
}
|
|
2191
|
+
else {
|
|
2192
|
+
console.error("Cannot get user's answer.");
|
|
2193
|
+
return { status: "Error: Cannot get user's answer.", answer: [] };
|
|
2194
|
+
}
|
|
2170
2195
|
}
|
|
2171
2196
|
}
|
|
2172
2197
|
class HumanOperate {
|
|
@@ -2185,28 +2210,36 @@ class HumanOperate {
|
|
|
2185
2210
|
};
|
|
2186
2211
|
}
|
|
2187
2212
|
async execute(context, params) {
|
|
2188
|
-
var _a
|
|
2213
|
+
var _a;
|
|
2189
2214
|
if (typeof params !== 'object' || params === null || !params.reason) {
|
|
2190
2215
|
throw new Error('Invalid parameters. Expected an object with a "reason" property.');
|
|
2191
2216
|
}
|
|
2192
2217
|
const reason = params.reason;
|
|
2193
2218
|
console.log("reason: " + reason);
|
|
2194
|
-
let
|
|
2195
|
-
if (
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2219
|
+
let onHumanOperate = (_a = context.callback) === null || _a === undefined ? undefined : _a.hooks.onHumanOperate;
|
|
2220
|
+
if (onHumanOperate) {
|
|
2221
|
+
let userOperation;
|
|
2222
|
+
try {
|
|
2223
|
+
userOperation = await onHumanOperate(reason);
|
|
2224
|
+
}
|
|
2225
|
+
catch (e) {
|
|
2226
|
+
console.error(e);
|
|
2227
|
+
return { status: "`onHumanOperate` not implemented", userOperation: "" };
|
|
2228
|
+
}
|
|
2200
2229
|
console.log("userOperation: " + userOperation);
|
|
2201
2230
|
return { status: "OK", userOperation: userOperation };
|
|
2202
2231
|
}
|
|
2232
|
+
else {
|
|
2233
|
+
console.error("Cannot get user's operation.");
|
|
2234
|
+
return { status: "Error: Cannot get user's operation.", userOperation: "" };
|
|
2235
|
+
}
|
|
2203
2236
|
}
|
|
2204
2237
|
}
|
|
2205
2238
|
|
|
2206
2239
|
class SummaryWorkflow {
|
|
2207
2240
|
constructor() {
|
|
2208
2241
|
this.name = 'summary_workflow';
|
|
2209
|
-
this.description = 'Summarize what this workflow has
|
|
2242
|
+
this.description = 'Summarize briefly what this workflow has accomplished.';
|
|
2210
2243
|
this.input_schema = {
|
|
2211
2244
|
type: 'object',
|
|
2212
2245
|
properties: {
|
package/dist/index.cjs.js
CHANGED
|
@@ -471,15 +471,24 @@ class ActionImpl {
|
|
|
471
471
|
// Store the promise of tool execution
|
|
472
472
|
toolExecutionPromise = (async () => {
|
|
473
473
|
var _a;
|
|
474
|
+
console.log("toolExecutionPromise()...");
|
|
475
|
+
console.log(`context.callback: ${context.callback}`);
|
|
476
|
+
if (context.callback) {
|
|
477
|
+
console.log(`context.callback.hooks.beforeToolUse: ${context.callback.hooks.beforeToolUse}`);
|
|
478
|
+
console.log(`context.callback.hooks.afterToolUse: ${context.callback.hooks.afterToolUse}`);
|
|
479
|
+
}
|
|
474
480
|
try {
|
|
475
481
|
// beforeToolUse
|
|
482
|
+
console.log("beforeToolUse");
|
|
476
483
|
context.__skip = false;
|
|
484
|
+
console.log("if #1");
|
|
477
485
|
if (context.callback && context.callback.hooks.beforeToolUse) {
|
|
478
486
|
let modified_input = await context.callback.hooks.beforeToolUse(tool, context, toolCall.input);
|
|
479
487
|
if (modified_input) {
|
|
480
488
|
toolCall.input = modified_input;
|
|
481
489
|
}
|
|
482
490
|
}
|
|
491
|
+
console.log("if #2");
|
|
483
492
|
if (context.__skip || context.__abort || ((_a = context.signal) === null || _a === void 0 ? void 0 : _a.aborted)) {
|
|
484
493
|
toolResultMessage = {
|
|
485
494
|
role: 'user',
|
|
@@ -494,15 +503,20 @@ class ActionImpl {
|
|
|
494
503
|
return;
|
|
495
504
|
}
|
|
496
505
|
// Execute the tool
|
|
506
|
+
console.log("Execute the tool...");
|
|
497
507
|
let result = await tool.execute(context, toolCall.input);
|
|
508
|
+
console.log("Execute the tool...done");
|
|
498
509
|
// afterToolUse
|
|
510
|
+
console.log("afterToolUse");
|
|
499
511
|
if (context.callback && context.callback.hooks.afterToolUse) {
|
|
500
512
|
let modified_result = await context.callback.hooks.afterToolUse(tool, context, result);
|
|
501
513
|
if (modified_result) {
|
|
502
514
|
result = modified_result;
|
|
503
515
|
}
|
|
504
516
|
}
|
|
505
|
-
|
|
517
|
+
console.log("set result_has_image...");
|
|
518
|
+
const result_has_image = result && result.image;
|
|
519
|
+
console.log("set resultContent...");
|
|
506
520
|
const resultContent = result_has_image
|
|
507
521
|
? {
|
|
508
522
|
type: 'tool_result',
|
|
@@ -519,11 +533,13 @@ class ActionImpl {
|
|
|
519
533
|
tool_use_id: toolCall.id,
|
|
520
534
|
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
521
535
|
};
|
|
536
|
+
console.log("set resultContentText...");
|
|
522
537
|
const resultContentText = result_has_image
|
|
523
538
|
? result.text
|
|
524
539
|
? result.text + ' [Image]'
|
|
525
540
|
: '[Image]'
|
|
526
541
|
: JSON.stringify(result);
|
|
542
|
+
console.log("set resultMessage...");
|
|
527
543
|
const resultMessage = {
|
|
528
544
|
role: 'user',
|
|
529
545
|
content: [resultContent],
|
|
@@ -553,6 +569,7 @@ class ActionImpl {
|
|
|
553
569
|
toolResultMessage = errorResult;
|
|
554
570
|
this.logger.logError(err, context);
|
|
555
571
|
}
|
|
572
|
+
console.log("toolExecutionPromise()...done");
|
|
556
573
|
})();
|
|
557
574
|
},
|
|
558
575
|
onComplete: (llmResponse) => {
|
|
@@ -942,19 +959,6 @@ class WorkflowGenerator {
|
|
|
942
959
|
],
|
|
943
960
|
});
|
|
944
961
|
const workflowData = response.toolCalls[0].input.workflow;
|
|
945
|
-
// Forcibly add special tools
|
|
946
|
-
const specialTools = [
|
|
947
|
-
"cancel_workflow",
|
|
948
|
-
"human_input_text",
|
|
949
|
-
"human_operate",
|
|
950
|
-
];
|
|
951
|
-
for (const node of workflowData.nodes) {
|
|
952
|
-
for (const tool of specialTools) {
|
|
953
|
-
if (!node.action.tools.includes(tool)) {
|
|
954
|
-
node.action.tools.push(tool);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
962
|
// Validate all tools exist
|
|
959
963
|
for (const node of workflowData.nodes) {
|
|
960
964
|
if (!this.toolRegistry.hasTools(node.action.tools)) {
|