@tyvm/knowhow 0.0.64 → 0.0.66
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/package.json +2 -1
- package/src/chat/modules/AgentModule.ts +11 -1
- package/src/cli.ts +5 -4
- package/src/clients/anthropic.ts +86 -65
- package/src/config.ts +7 -0
- package/src/services/AgentSynchronization.ts +27 -10
- package/src/types.ts +11 -0
- package/src/worker.ts +145 -8
- package/src/workers/tools/index.ts +10 -0
- package/src/workers/tools/listAllowedPorts.ts +30 -0
- package/ts_build/package.json +2 -1
- package/ts_build/src/chat/modules/AgentModule.js +7 -1
- package/ts_build/src/chat/modules/AgentModule.js.map +1 -1
- package/ts_build/src/cli.js +5 -4
- package/ts_build/src/cli.js.map +1 -1
- package/ts_build/src/clients/anthropic.d.ts +9 -0
- package/ts_build/src/clients/anthropic.js +47 -31
- package/ts_build/src/clients/anthropic.js.map +1 -1
- package/ts_build/src/config.js +6 -0
- package/ts_build/src/config.js.map +1 -1
- package/ts_build/src/services/AgentSynchronization.d.ts +2 -0
- package/ts_build/src/services/AgentSynchronization.js +20 -10
- package/ts_build/src/services/AgentSynchronization.js.map +1 -1
- package/ts_build/src/types.d.ts +11 -0
- package/ts_build/src/types.js +1 -0
- package/ts_build/src/types.js.map +1 -1
- package/ts_build/src/worker/handlers/proxyHandler.d.ts +2 -0
- package/ts_build/src/worker/handlers/proxyHandler.js +41 -0
- package/ts_build/src/worker/handlers/proxyHandler.js.map +1 -0
- package/ts_build/src/worker/tools/index.d.ts +1 -0
- package/ts_build/src/worker/tools/index.js +18 -0
- package/ts_build/src/worker/tools/index.js.map +1 -0
- package/ts_build/src/worker/tools/portForwarding.d.ts +49 -0
- package/ts_build/src/worker/tools/portForwarding.js +173 -0
- package/ts_build/src/worker/tools/portForwarding.js.map +1 -0
- package/ts_build/src/worker/types/proxy.d.ts +18 -0
- package/ts_build/src/worker/types/proxy.js +3 -0
- package/ts_build/src/worker/types/proxy.js.map +1 -0
- package/ts_build/src/worker.js +119 -3
- package/ts_build/src/worker.js.map +1 -1
- package/ts_build/src/workers/tools/index.d.ts +9 -0
- package/ts_build/src/workers/tools/index.js +23 -0
- package/ts_build/src/workers/tools/index.js.map +1 -0
- package/ts_build/src/workers/tools/listAllowedPorts.d.ts +3 -0
- package/ts_build/src/workers/tools/listAllowedPorts.js +25 -0
- package/ts_build/src/workers/tools/listAllowedPorts.js.map +1 -0
- package/ts_build/src/workers/tools/listForwardedPorts.d.ts +10 -0
- package/ts_build/src/workers/tools/listForwardedPorts.js +22 -0
- package/ts_build/src/workers/tools/listForwardedPorts.js.map +1 -0
- package/ts_build/tests/worker/handlers/proxyHandler.test.d.ts +1 -0
- package/ts_build/tests/worker/handlers/proxyHandler.test.js +170 -0
- package/ts_build/tests/worker/handlers/proxyHandler.test.js.map +1 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleProxyRequest = void 0;
|
|
4
|
+
const portForwarding_1 = require("../tools/portForwarding");
|
|
5
|
+
async function handleProxyRequest(message, sendResponse) {
|
|
6
|
+
try {
|
|
7
|
+
const resultJson = await (0, portForwarding_1.forwardRequest)(message.port, message.method, message.path, message.headers, message.body);
|
|
8
|
+
const result = JSON.parse(resultJson);
|
|
9
|
+
if (result.success) {
|
|
10
|
+
sendResponse({
|
|
11
|
+
type: 'proxy_http_response',
|
|
12
|
+
requestId: message.requestId,
|
|
13
|
+
statusCode: result.statusCode,
|
|
14
|
+
headers: result.headers,
|
|
15
|
+
body: result.body,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
sendResponse({
|
|
20
|
+
type: 'proxy_http_response',
|
|
21
|
+
requestId: message.requestId,
|
|
22
|
+
statusCode: 500,
|
|
23
|
+
headers: { 'content-type': 'application/json' },
|
|
24
|
+
body: JSON.stringify({ error: result.error }),
|
|
25
|
+
error: result.error,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
sendResponse({
|
|
31
|
+
type: 'proxy_http_response',
|
|
32
|
+
requestId: message.requestId,
|
|
33
|
+
statusCode: 500,
|
|
34
|
+
headers: { 'content-type': 'application/json' },
|
|
35
|
+
body: JSON.stringify({ error: error.message }),
|
|
36
|
+
error: error.message,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.handleProxyRequest = handleProxyRequest;
|
|
41
|
+
//# sourceMappingURL=proxyHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxyHandler.js","sourceRoot":"","sources":["../../../../src/worker/handlers/proxyHandler.ts"],"names":[],"mappings":";;;AACA,4DAAyD;AAElD,KAAK,UAAU,kBAAkB,CACtC,OAAyB,EACzB,YAAmD;IAEnD,IAAI;QAEF,MAAM,UAAU,GAAG,MAAM,IAAA,+BAAc,EACrC,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,IAAI,CACb,CAAC;QAGF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAEtC,IAAI,MAAM,CAAC,OAAO,EAAE;YAElB,YAAY,CAAC;gBACX,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,UAAU,EAAE,MAAM,CAAC,UAAU;gBAC7B,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC,CAAC;SACJ;aAAM;YAEL,YAAY,CAAC;gBACX,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,UAAU,EAAE,GAAG;gBACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC7C,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC,CAAC;SACJ;KACF;IAAC,OAAO,KAAK,EAAE;QAEd,YAAY,CAAC;YACX,IAAI,EAAE,qBAAqB;YAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YAC9C,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,CAAC,CAAC;KACJ;AACH,CAAC;AAhDD,gDAgDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./portForwarding";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./portForwarding"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/worker/tools/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAKA,mDAAiC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const portForwardingRequestTool: {
|
|
2
|
+
type: "function";
|
|
3
|
+
function: {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
parameters: {
|
|
7
|
+
type: string;
|
|
8
|
+
positional: boolean;
|
|
9
|
+
properties: {
|
|
10
|
+
port: {
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
method: {
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
path: {
|
|
19
|
+
type: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
headers: {
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
body: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
required: string[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare function forwardRequest(port: number, method: string, path: string, headers?: Record<string, string>, body?: string): Promise<string>;
|
|
36
|
+
export declare const listAllowedPortsTool: {
|
|
37
|
+
type: "function";
|
|
38
|
+
function: {
|
|
39
|
+
name: string;
|
|
40
|
+
description: string;
|
|
41
|
+
parameters: {
|
|
42
|
+
type: string;
|
|
43
|
+
positional: boolean;
|
|
44
|
+
properties: {};
|
|
45
|
+
required: any[];
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export declare function listAllowedPorts(): Promise<string>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.listAllowedPorts = exports.listAllowedPortsTool = exports.forwardRequest = exports.portForwardingRequestTool = void 0;
|
|
27
|
+
const http = __importStar(require("http"));
|
|
28
|
+
const https = __importStar(require("https"));
|
|
29
|
+
const config_1 = require("../../config");
|
|
30
|
+
const forwardingSessions = new Map();
|
|
31
|
+
exports.portForwardingRequestTool = {
|
|
32
|
+
type: "function",
|
|
33
|
+
function: {
|
|
34
|
+
name: "forwardRequest",
|
|
35
|
+
description: "Forward an HTTP request to a local port that is allowed in the worker configuration. This enables remote access to local services running on the worker machine.",
|
|
36
|
+
parameters: {
|
|
37
|
+
type: "object",
|
|
38
|
+
positional: true,
|
|
39
|
+
properties: {
|
|
40
|
+
port: {
|
|
41
|
+
type: "number",
|
|
42
|
+
description: "The local port to forward the request to",
|
|
43
|
+
},
|
|
44
|
+
method: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "HTTP method (GET, POST, PUT, DELETE, etc.)",
|
|
47
|
+
},
|
|
48
|
+
path: {
|
|
49
|
+
type: "string",
|
|
50
|
+
description: "URL path to request (e.g., /api/data)",
|
|
51
|
+
},
|
|
52
|
+
headers: {
|
|
53
|
+
type: "object",
|
|
54
|
+
description: "HTTP headers to include in the request",
|
|
55
|
+
},
|
|
56
|
+
body: {
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "Request body (for POST, PUT, etc.)",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
required: ["port", "method", "path"],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
function isPortAllowed(port, allowedPorts) {
|
|
66
|
+
return allowedPorts.includes(port);
|
|
67
|
+
}
|
|
68
|
+
async function forwardRequest(port, method, path, headers, body) {
|
|
69
|
+
try {
|
|
70
|
+
const config = await (0, config_1.getConfig)();
|
|
71
|
+
const allowedPorts = config.worker?.allowedPorts || [];
|
|
72
|
+
if (!isPortAllowed(port, allowedPorts)) {
|
|
73
|
+
throw new Error(`Port ${port} is not allowed in worker configuration. Allowed ports: ${allowedPorts.join(", ")}`);
|
|
74
|
+
}
|
|
75
|
+
const isInsideDocker = process.env.KNOWHOW_DOCKER === "true";
|
|
76
|
+
let targetPort = port;
|
|
77
|
+
if (isInsideDocker && config.worker?.portMappings) {
|
|
78
|
+
const mapping = config.worker.portMappings.find((m) => {
|
|
79
|
+
const [hostPort, containerPort] = m.split(":").map(Number);
|
|
80
|
+
return containerPort === port;
|
|
81
|
+
});
|
|
82
|
+
if (mapping) {
|
|
83
|
+
const [hostPort, containerPort] = mapping.split(":").map(Number);
|
|
84
|
+
targetPort = containerPort;
|
|
85
|
+
console.log(`Port mapping found: ${hostPort} (host) -> ${containerPort} (container)`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const result = await makeHttpRequest(targetPort, method, path, headers || {}, body);
|
|
89
|
+
return JSON.stringify({
|
|
90
|
+
success: true,
|
|
91
|
+
statusCode: result.statusCode,
|
|
92
|
+
headers: result.headers,
|
|
93
|
+
body: result.body,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return JSON.stringify({
|
|
98
|
+
success: false,
|
|
99
|
+
error: error.message,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.forwardRequest = forwardRequest;
|
|
104
|
+
function makeHttpRequest(port, method, path, headers, body) {
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
const options = {
|
|
107
|
+
hostname: "localhost",
|
|
108
|
+
port,
|
|
109
|
+
path,
|
|
110
|
+
method: method.toUpperCase(),
|
|
111
|
+
headers: {
|
|
112
|
+
...headers,
|
|
113
|
+
"User-Agent": "knowhow-worker-port-forwarder",
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
if (body) {
|
|
117
|
+
options.headers["Content-Length"] = Buffer.byteLength(body);
|
|
118
|
+
}
|
|
119
|
+
const protocol = port === 443 ? https : http;
|
|
120
|
+
const req = protocol.request(options, (res) => {
|
|
121
|
+
let data = "";
|
|
122
|
+
res.on("data", (chunk) => {
|
|
123
|
+
data += chunk;
|
|
124
|
+
});
|
|
125
|
+
res.on("end", () => {
|
|
126
|
+
resolve({
|
|
127
|
+
statusCode: res.statusCode || 0,
|
|
128
|
+
headers: res.headers,
|
|
129
|
+
body: data,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
req.on("error", (error) => {
|
|
134
|
+
reject(error);
|
|
135
|
+
});
|
|
136
|
+
if (body) {
|
|
137
|
+
req.write(body);
|
|
138
|
+
}
|
|
139
|
+
req.end();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
exports.listAllowedPortsTool = {
|
|
143
|
+
type: "function",
|
|
144
|
+
function: {
|
|
145
|
+
name: "listAllowedPorts",
|
|
146
|
+
description: "List all ports that are allowed for port forwarding in the worker configuration",
|
|
147
|
+
parameters: {
|
|
148
|
+
type: "object",
|
|
149
|
+
positional: true,
|
|
150
|
+
properties: {},
|
|
151
|
+
required: [],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
async function listAllowedPorts() {
|
|
156
|
+
try {
|
|
157
|
+
const config = await (0, config_1.getConfig)();
|
|
158
|
+
const allowedPorts = config.worker?.allowedPorts || [];
|
|
159
|
+
const portMappings = config.worker?.portMappings || [];
|
|
160
|
+
return JSON.stringify({
|
|
161
|
+
allowedPorts,
|
|
162
|
+
portMappings,
|
|
163
|
+
isDocker: process.env.KNOWHOW_DOCKER === "true",
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return JSON.stringify({
|
|
168
|
+
error: error.message,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.listAllowedPorts = listAllowedPorts;
|
|
173
|
+
//# sourceMappingURL=portForwarding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portForwarding.js","sourceRoot":"","sources":["../../../../src/worker/tools/portForwarding.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,6CAA+B;AAE/B,yCAAyC;AAQzC,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAe,CAAC;AAKrC,QAAA,yBAAyB,GAAG;IACvC,IAAI,EAAE,UAAmB;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,kKAAkK;QACpK,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oB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AE;SACb;KACF;CACF,CAAC;AAKK,KAAK,UAAU,gBAAgB;IACpC,IAAI;QAEF,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAS,GAAE,CAAC;QACjC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,IAAI,EAAE,CAAC;QACvD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,IAAI,EAAE,CAAC;QAEvD,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,YAAY;YACZ,YAAY;YACZ,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,MAAM;SAChD,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,CAAC,CAAC;KACJ;AACH,CAAC;AAjBD,4CAiBC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ProxyHttpRequest {
|
|
2
|
+
type: 'proxy_http_request';
|
|
3
|
+
requestId: string;
|
|
4
|
+
port: number;
|
|
5
|
+
method: string;
|
|
6
|
+
path: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
body?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ProxyHttpResponse {
|
|
11
|
+
type: 'proxy_http_response';
|
|
12
|
+
requestId: string;
|
|
13
|
+
statusCode: number;
|
|
14
|
+
headers: Record<string, string | string[]>;
|
|
15
|
+
body: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export type ProxyMessage = ProxyHttpRequest | ProxyHttpResponse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../src/worker/types/proxy.ts"],"names":[],"mappings":""}
|
package/ts_build/src/worker.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -6,9 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
29
|
exports.worker = void 0;
|
|
7
30
|
const os_1 = __importDefault(require("os"));
|
|
8
31
|
const ws_1 = require("ws");
|
|
32
|
+
const knowhow_tunnel_1 = require("@tyvm/knowhow-tunnel");
|
|
33
|
+
const list_1 = require("./agents/tools/list");
|
|
9
34
|
const login_1 = require("./login");
|
|
10
35
|
const services_1 = require("./services");
|
|
11
36
|
const Mcp_1 = require("./services/Mcp");
|
|
37
|
+
const allTools = __importStar(require("./agents/tools"));
|
|
38
|
+
const tools_1 = __importDefault(require("./workers/tools"));
|
|
12
39
|
const utils_1 = require("./utils");
|
|
13
40
|
const config_1 = require("./config");
|
|
14
41
|
const KnowhowClient_1 = require("./services/KnowhowClient");
|
|
@@ -111,6 +138,9 @@ async function worker(options) {
|
|
|
111
138
|
return runWorkerInSandbox(options, config);
|
|
112
139
|
}
|
|
113
140
|
const { Tools } = (0, services_1.services)();
|
|
141
|
+
const combinedTools = { ...allTools, ...tools_1.default.tools };
|
|
142
|
+
Tools.defineTools(list_1.includedTools, combinedTools);
|
|
143
|
+
Tools.defineTools(tools_1.default.definitions, tools_1.default.tools);
|
|
114
144
|
const mcpServer = new Mcp_1.McpServerService(Tools);
|
|
115
145
|
const clientName = "knowhow-worker";
|
|
116
146
|
const clientVersion = "1.1.1";
|
|
@@ -133,13 +163,63 @@ async function worker(options) {
|
|
|
133
163
|
const toolsToUse = Tools.getToolsByNames(config.worker.allowedTools);
|
|
134
164
|
mcpServer.createServer(clientName, clientVersion).withTools(toolsToUse);
|
|
135
165
|
let connected = false;
|
|
166
|
+
let tunnelHandler = null;
|
|
167
|
+
let tunnelWs = null;
|
|
168
|
+
const tunnelEnabled = config.worker?.tunnel?.enabled ?? false;
|
|
169
|
+
let tunnelLocalHost = config.worker?.tunnel?.localHost;
|
|
170
|
+
if (!tunnelLocalHost) {
|
|
171
|
+
if (isInsideDocker) {
|
|
172
|
+
tunnelLocalHost = "host.docker.internal";
|
|
173
|
+
console.log("🐳 Docker detected: tunnel will use host.docker.internal to reach host services");
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
tunnelLocalHost = "127.0.0.1";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const portMapping = config.worker?.tunnel?.portMapping || {};
|
|
180
|
+
if (Object.keys(portMapping).length > 0) {
|
|
181
|
+
console.log("🔀 Port mapping configured:");
|
|
182
|
+
for (const [containerPort, hostPort] of Object.entries(portMapping)) {
|
|
183
|
+
console.log(` Container port ${containerPort} → Host port ${hostPort}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (tunnelEnabled) {
|
|
187
|
+
const tunnelPorts = config.worker?.tunnel?.allowedPorts || [];
|
|
188
|
+
if (tunnelPorts.length === 0) {
|
|
189
|
+
console.warn("⚠️ Tunnel enabled but no allowedPorts configured. Add tunnel.allowedPorts to knowhow.json");
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
console.log(`🌐 Tunnel enabled for ports: ${tunnelPorts.join(", ")}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.log("🚫 Tunnel disabled (enable in knowhow.json: worker.tunnel.enabled = true)");
|
|
197
|
+
}
|
|
198
|
+
function extractTunnelDomain(apiUrl) {
|
|
199
|
+
try {
|
|
200
|
+
const url = new URL(apiUrl);
|
|
201
|
+
const useHttps = url.protocol === "https:";
|
|
202
|
+
if (url.hostname === "localhost" || url.hostname === "127.0.0.1") {
|
|
203
|
+
return {
|
|
204
|
+
domain: `worker.${url.hostname}:${url.port || "80"}`,
|
|
205
|
+
useHttps,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return { domain: `worker.${url.hostname}`, useHttps };
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
console.error("Failed to parse API_URL for tunnel domain:", err);
|
|
212
|
+
return { domain: "worker.localhost:4000", useHttps: false };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
136
215
|
async function connectWebSocket() {
|
|
137
216
|
const jwt = await (0, login_1.loadJwt)();
|
|
138
217
|
console.log(`Connecting to ${API_URL}`);
|
|
139
218
|
const dir = process.cwd();
|
|
140
219
|
const homedir = os_1.default.homedir();
|
|
141
220
|
const hostname = process.env.WORKER_HOSTNAME || os_1.default.hostname();
|
|
142
|
-
const root = process.env.WORKER_ROOT ||
|
|
221
|
+
const root = process.env.WORKER_ROOT ||
|
|
222
|
+
(dir === homedir ? "~" : dir.replace(homedir, "~"));
|
|
143
223
|
const headers = {
|
|
144
224
|
Authorization: `Bearer ${jwt}`,
|
|
145
225
|
"User-Agent": `${clientName}/${clientVersion}/${hostname}`,
|
|
@@ -156,23 +236,59 @@ async function worker(options) {
|
|
|
156
236
|
else {
|
|
157
237
|
console.log("🔒 Worker is private (only you can use it)");
|
|
158
238
|
}
|
|
239
|
+
const { domain: tunnelDomain, useHttps: tunnelUseHttps } = extractTunnelDomain(API_URL);
|
|
159
240
|
const ws = new ws_1.WebSocket(`${API_URL}/ws/worker`, {
|
|
160
241
|
headers,
|
|
161
242
|
});
|
|
243
|
+
let tunnelConnection = null;
|
|
244
|
+
if (tunnelEnabled) {
|
|
245
|
+
tunnelConnection = new ws_1.WebSocket(`${API_URL}/ws/tunnel`, {
|
|
246
|
+
headers,
|
|
247
|
+
});
|
|
248
|
+
tunnelConnection.on("open", () => {
|
|
249
|
+
console.log("Tunnel WebSocket connected");
|
|
250
|
+
tunnelHandler = (0, knowhow_tunnel_1.createTunnelHandler)(tunnelConnection, {
|
|
251
|
+
allowedPorts: config.worker?.tunnel?.allowedPorts || [],
|
|
252
|
+
maxConcurrentStreams: config.worker?.tunnel?.maxConcurrentStreams || 50,
|
|
253
|
+
localHost: tunnelLocalHost,
|
|
254
|
+
tunnelDomain,
|
|
255
|
+
tunnelUseHttps,
|
|
256
|
+
enableUrlRewriting: config.worker?.tunnel?.enableUrlRewriting !== false,
|
|
257
|
+
portMapping,
|
|
258
|
+
logLevel: "info",
|
|
259
|
+
});
|
|
260
|
+
console.log("🌐 Tunnel handler initialized");
|
|
261
|
+
});
|
|
262
|
+
tunnelConnection.on("close", (code, reason) => {
|
|
263
|
+
console.log(`Tunnel WebSocket closed. Code: ${code}, Reason: ${reason.toString()}`);
|
|
264
|
+
if (tunnelHandler) {
|
|
265
|
+
tunnelHandler.cleanup();
|
|
266
|
+
tunnelHandler = null;
|
|
267
|
+
}
|
|
268
|
+
tunnelWs = null;
|
|
269
|
+
});
|
|
270
|
+
tunnelConnection.on("error", (error) => {
|
|
271
|
+
console.error("Tunnel WebSocket error:", error);
|
|
272
|
+
});
|
|
273
|
+
tunnelWs = tunnelConnection;
|
|
274
|
+
}
|
|
162
275
|
ws.on("open", () => {
|
|
163
|
-
console.log("
|
|
276
|
+
console.log("Worker WebSocket connected");
|
|
164
277
|
connected = true;
|
|
165
278
|
});
|
|
166
279
|
ws.on("close", async (code, reason) => {
|
|
167
280
|
console.log(`WebSocket closed. Code: ${code}, Reason: ${reason.toString()}`);
|
|
168
281
|
console.log("Attempting to reconnect...");
|
|
282
|
+
if (tunnelHandler) {
|
|
283
|
+
tunnelHandler = null;
|
|
284
|
+
}
|
|
169
285
|
connected = false;
|
|
170
286
|
});
|
|
171
287
|
ws.on("error", (error) => {
|
|
172
288
|
console.error("WebSocket error:", error);
|
|
173
289
|
});
|
|
174
290
|
mcpServer.runWsServer(ws);
|
|
175
|
-
return { ws, mcpServer };
|
|
291
|
+
return { ws, mcpServer, tunnelWs };
|
|
176
292
|
}
|
|
177
293
|
while (true) {
|
|
178
294
|
let connection = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,2BAA+B;AAC/B,yDAA0E;AAC1E,8CAAoD;AACpD,mCAAkC;AAClC,yCAAsC;AACtC,wCAAkD;AAClD,yDAA2C;AAC3C,4DAA0C;AAC1C,mCAA+B;AAC/B,qCAAmD;AACnD,4DAA2D;AAC3D,qDAAsD;AAEtD,MAAM,OAAO,GAAG,+BAAe,CAAC;AAKhC,KAAK,UAAU,kBAAkB,CAC/B,OAAkE,EAClE,MAAW;IAEX,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,mBAAQ,GAAE,CAAC;IAE9B,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;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AArTD,wBAqTC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./listAllowedPorts"), exports);
|
|
18
|
+
const listAllowedPorts_1 = require("./listAllowedPorts");
|
|
19
|
+
exports.default = {
|
|
20
|
+
tools: { listAllowedPorts: listAllowedPorts_1.listAllowedPorts },
|
|
21
|
+
definitions: [listAllowedPorts_1.listAllowedPortsDefinition],
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/workers/tools/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,yDAG4B;AAE5B,kBAAe;IACb,KAAK,EAAE,EAAE,gBAAgB,EAAhB,mCAAgB,EAAE;IAC3B,WAAW,EAAE,CAAC,6CAA0B,CAAC;CAC1C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listAllowedPortsDefinition = exports.listAllowedPorts = void 0;
|
|
4
|
+
const config_1 = require("../../config");
|
|
5
|
+
async function listAllowedPorts() {
|
|
6
|
+
const config = await (0, config_1.getConfig)();
|
|
7
|
+
if (!config.worker?.tunnel?.enabled) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
return config.worker.tunnel.allowedPorts || [];
|
|
11
|
+
}
|
|
12
|
+
exports.listAllowedPorts = listAllowedPorts;
|
|
13
|
+
exports.listAllowedPortsDefinition = {
|
|
14
|
+
type: "function",
|
|
15
|
+
function: {
|
|
16
|
+
name: "listAllowedPorts",
|
|
17
|
+
description: "List all ports that are being forwarded through the worker tunnel. Returns an array of port numbers that can be accessed via the tunnel system.",
|
|
18
|
+
parameters: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {},
|
|
21
|
+
required: [],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=listAllowedPorts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listAllowedPorts.js","sourceRoot":"","sources":["../../../../src/workers/tools/listAllowedPorts.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AAOlC,KAAK,UAAU,gBAAgB;IACpC,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAS,GAAE,CAAC;IAEjC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;QACnC,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;AACjD,CAAC;AARD,4CAQC;AAEY,QAAA,0BAA0B,GAAS;IAC9C,IAAI,EAAE,UAAmB;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,kBAAkB;QACxB,WAAW,EACT,iJAAiJ;QACnJ,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listForwardedPortsDefinition = exports.listAllowedPorts = void 0;
|
|
4
|
+
const config_1 = require("../../config");
|
|
5
|
+
async function listAllowedPorts() {
|
|
6
|
+
const config = await (0, config_1.getConfig)();
|
|
7
|
+
if (!config.worker?.tunnel?.enabled) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
return config.worker.tunnel.allowedPorts || [];
|
|
11
|
+
}
|
|
12
|
+
exports.listAllowedPorts = listAllowedPorts;
|
|
13
|
+
exports.listForwardedPortsDefinition = {
|
|
14
|
+
name: "listAllowedPorts",
|
|
15
|
+
description: "List all ports that are being forwarded through the worker tunnel. Returns an array of port numbers that can be accessed via the tunnel system.",
|
|
16
|
+
parameters: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {},
|
|
19
|
+
required: [],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=listForwardedPorts.js.map
|