@quilltap/plugin-utils 1.2.5 → 1.4.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/CHANGELOG.md +22 -0
- package/dist/host-rewrite.d.mts +52 -0
- package/dist/host-rewrite.d.ts +52 -0
- package/dist/host-rewrite.js +210 -0
- package/dist/host-rewrite.js.map +1 -0
- package/dist/host-rewrite.mjs +180 -0
- package/dist/host-rewrite.mjs.map +1 -0
- package/dist/index.d.mts +48 -2
- package/dist/index.d.ts +48 -2
- package/dist/index.js +139 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -1
- package/dist/index.mjs.map +1 -1
- package/dist/tools/index.d.mts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to @quilltap/plugin-utils will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.4.0] - 2026-02-25
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Host URL Rewriting Utilities**
|
|
10
|
+
- `isVMEnvironment()` - Check if running in a VM/container environment (Docker, Lima, WSL2)
|
|
11
|
+
- `resolveHostGateway()` - Resolve the host gateway address with multi-strategy fallback
|
|
12
|
+
- `rewriteLocalhostUrl()` - Transparently rewrite localhost URLs to point at the host gateway
|
|
13
|
+
- Self-contained environment detection (no dependency on Quilltap core `lib/paths`)
|
|
14
|
+
- Uses `createPluginLogger` for consistent logging within the plugin ecosystem
|
|
15
|
+
- New export path: `@quilltap/plugin-utils/host-rewrite`
|
|
16
|
+
|
|
17
|
+
## [1.3.0] - 2026-01-30
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **Built-in Tool Names for Collision Detection**
|
|
22
|
+
- Added `BUILTIN_TOOL_NAMES` constant with names of Quilltap's built-in tools
|
|
23
|
+
- Added `getBuiltinToolNames()` function for dynamic access to the set
|
|
24
|
+
- Enables plugins (like MCP connectors) to avoid shadowing built-in functionality
|
|
25
|
+
- Built-in tools: `generate_image`, `search_memories`, `search_web`, `project_info`, `file_management`, `request_full_context`
|
|
26
|
+
|
|
5
27
|
## [1.2.5] - 2026-01-25
|
|
6
28
|
|
|
7
29
|
### Fixed
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host URL Rewriting for VM/Container Environments
|
|
3
|
+
*
|
|
4
|
+
* When Quilltap runs inside Docker, Lima VMs, or WSL2, `localhost` and
|
|
5
|
+
* `127.0.0.1` resolve to the container/VM's own loopback — not the host
|
|
6
|
+
* machine where services like Ollama or LM Studio are running.
|
|
7
|
+
*
|
|
8
|
+
* This module provides a single function that transparently rewrites
|
|
9
|
+
* localhost URLs to point at the host, so users can configure
|
|
10
|
+
* `http://localhost:11434` and have it Just Work in every environment.
|
|
11
|
+
*
|
|
12
|
+
* Gateway resolution order:
|
|
13
|
+
* 1. `QUILLTAP_HOST_IP` env var (explicit override) → rewrite to that IP
|
|
14
|
+
* 2. In Docker (not Lima): rewrite `localhost` → `host.docker.internal`
|
|
15
|
+
* (Docker Desktop DNS or --add-host on Linux handles the forwarding)
|
|
16
|
+
* 3. Default gateway from /proc/net/route (works in Lima and WSL2 where
|
|
17
|
+
* NAT networking forwards to host loopback)
|
|
18
|
+
* 4. Fallback: try DNS lookup of `host.docker.internal` via /etc/hosts
|
|
19
|
+
* 5. Give up gracefully — return URL unchanged
|
|
20
|
+
*
|
|
21
|
+
* @module @quilltap/plugin-utils/host-rewrite
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Check if running in any VM or container environment that needs URL rewriting.
|
|
25
|
+
*/
|
|
26
|
+
declare function isVMEnvironment(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the host gateway address (IP or hostname).
|
|
29
|
+
*
|
|
30
|
+
* Tries multiple strategies in order; caches the result so file reads
|
|
31
|
+
* only happen once per process lifetime.
|
|
32
|
+
*/
|
|
33
|
+
declare function resolveHostGateway(): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Rewrite a localhost URL to point at the host gateway.
|
|
36
|
+
*
|
|
37
|
+
* No-ops when:
|
|
38
|
+
* - Not running in a VM/container environment
|
|
39
|
+
* - The URL doesn't point to localhost or 127.0.0.1
|
|
40
|
+
* - Gateway resolution fails
|
|
41
|
+
*
|
|
42
|
+
* @param url The URL to potentially rewrite
|
|
43
|
+
* @returns The original URL or a rewritten version with the gateway host
|
|
44
|
+
*/
|
|
45
|
+
declare function rewriteLocalhostUrl(url: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the cached gateway host (for testing).
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
declare function _resetGatewayCache(): void;
|
|
51
|
+
|
|
52
|
+
export { _resetGatewayCache, isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host URL Rewriting for VM/Container Environments
|
|
3
|
+
*
|
|
4
|
+
* When Quilltap runs inside Docker, Lima VMs, or WSL2, `localhost` and
|
|
5
|
+
* `127.0.0.1` resolve to the container/VM's own loopback — not the host
|
|
6
|
+
* machine where services like Ollama or LM Studio are running.
|
|
7
|
+
*
|
|
8
|
+
* This module provides a single function that transparently rewrites
|
|
9
|
+
* localhost URLs to point at the host, so users can configure
|
|
10
|
+
* `http://localhost:11434` and have it Just Work in every environment.
|
|
11
|
+
*
|
|
12
|
+
* Gateway resolution order:
|
|
13
|
+
* 1. `QUILLTAP_HOST_IP` env var (explicit override) → rewrite to that IP
|
|
14
|
+
* 2. In Docker (not Lima): rewrite `localhost` → `host.docker.internal`
|
|
15
|
+
* (Docker Desktop DNS or --add-host on Linux handles the forwarding)
|
|
16
|
+
* 3. Default gateway from /proc/net/route (works in Lima and WSL2 where
|
|
17
|
+
* NAT networking forwards to host loopback)
|
|
18
|
+
* 4. Fallback: try DNS lookup of `host.docker.internal` via /etc/hosts
|
|
19
|
+
* 5. Give up gracefully — return URL unchanged
|
|
20
|
+
*
|
|
21
|
+
* @module @quilltap/plugin-utils/host-rewrite
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Check if running in any VM or container environment that needs URL rewriting.
|
|
25
|
+
*/
|
|
26
|
+
declare function isVMEnvironment(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the host gateway address (IP or hostname).
|
|
29
|
+
*
|
|
30
|
+
* Tries multiple strategies in order; caches the result so file reads
|
|
31
|
+
* only happen once per process lifetime.
|
|
32
|
+
*/
|
|
33
|
+
declare function resolveHostGateway(): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Rewrite a localhost URL to point at the host gateway.
|
|
36
|
+
*
|
|
37
|
+
* No-ops when:
|
|
38
|
+
* - Not running in a VM/container environment
|
|
39
|
+
* - The URL doesn't point to localhost or 127.0.0.1
|
|
40
|
+
* - Gateway resolution fails
|
|
41
|
+
*
|
|
42
|
+
* @param url The URL to potentially rewrite
|
|
43
|
+
* @returns The original URL or a rewritten version with the gateway host
|
|
44
|
+
*/
|
|
45
|
+
declare function rewriteLocalhostUrl(url: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the cached gateway host (for testing).
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
declare function _resetGatewayCache(): void;
|
|
51
|
+
|
|
52
|
+
export { _resetGatewayCache, isVMEnvironment, resolveHostGateway, rewriteLocalhostUrl };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/host-rewrite.ts
|
|
21
|
+
var host_rewrite_exports = {};
|
|
22
|
+
__export(host_rewrite_exports, {
|
|
23
|
+
_resetGatewayCache: () => _resetGatewayCache,
|
|
24
|
+
isVMEnvironment: () => isVMEnvironment,
|
|
25
|
+
resolveHostGateway: () => resolveHostGateway,
|
|
26
|
+
rewriteLocalhostUrl: () => rewriteLocalhostUrl
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(host_rewrite_exports);
|
|
29
|
+
|
|
30
|
+
// src/logging/plugin-logger.ts
|
|
31
|
+
function getCoreLoggerFactory() {
|
|
32
|
+
return globalThis.__quilltap_logger_factory ?? null;
|
|
33
|
+
}
|
|
34
|
+
function createConsoleLoggerWithChild(prefix, minLevel = "debug", baseContext = {}) {
|
|
35
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
36
|
+
const shouldLog = (level) => levels.indexOf(level) >= levels.indexOf(minLevel);
|
|
37
|
+
const formatContext = (context) => {
|
|
38
|
+
const merged = { ...baseContext, ...context };
|
|
39
|
+
const entries = Object.entries(merged).filter(([key]) => key !== "context").map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(" ");
|
|
40
|
+
return entries ? ` ${entries}` : "";
|
|
41
|
+
};
|
|
42
|
+
const logger = {
|
|
43
|
+
debug: (message, context) => {
|
|
44
|
+
if (shouldLog("debug")) {
|
|
45
|
+
console.debug(`[${prefix}] ${message}${formatContext(context)}`);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
info: (message, context) => {
|
|
49
|
+
if (shouldLog("info")) {
|
|
50
|
+
console.info(`[${prefix}] ${message}${formatContext(context)}`);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
warn: (message, context) => {
|
|
54
|
+
if (shouldLog("warn")) {
|
|
55
|
+
console.warn(`[${prefix}] ${message}${formatContext(context)}`);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
error: (message, context, error) => {
|
|
59
|
+
if (shouldLog("error")) {
|
|
60
|
+
console.error(
|
|
61
|
+
`[${prefix}] ${message}${formatContext(context)}`,
|
|
62
|
+
error ? `
|
|
63
|
+
${error.stack || error.message}` : ""
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
child: (additionalContext) => {
|
|
68
|
+
return createConsoleLoggerWithChild(prefix, minLevel, {
|
|
69
|
+
...baseContext,
|
|
70
|
+
...additionalContext
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return logger;
|
|
75
|
+
}
|
|
76
|
+
function createPluginLogger(pluginName, minLevel = "debug") {
|
|
77
|
+
const coreFactory = getCoreLoggerFactory();
|
|
78
|
+
if (coreFactory) {
|
|
79
|
+
return coreFactory(pluginName);
|
|
80
|
+
}
|
|
81
|
+
return createConsoleLoggerWithChild(pluginName, minLevel);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/logging/index.ts
|
|
85
|
+
var import_plugin_types = require("@quilltap/plugin-types");
|
|
86
|
+
|
|
87
|
+
// src/host-rewrite.ts
|
|
88
|
+
var import_node_fs = require("fs");
|
|
89
|
+
var LOCALHOST_HOSTS = /* @__PURE__ */ new Set([
|
|
90
|
+
"localhost",
|
|
91
|
+
"127.0.0.1",
|
|
92
|
+
"[::1]",
|
|
93
|
+
"::1"
|
|
94
|
+
]);
|
|
95
|
+
var cachedGatewayHost;
|
|
96
|
+
var rewriteLogger = createPluginLogger("host-rewrite");
|
|
97
|
+
function isLimaEnvironment() {
|
|
98
|
+
return process.env.LIMA_CONTAINER === "true";
|
|
99
|
+
}
|
|
100
|
+
function isDockerEnvironment() {
|
|
101
|
+
if (process.env.DOCKER_CONTAINER === "true") {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
if ((0, import_node_fs.existsSync)("/.dockerenv")) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
const appStat = (0, import_node_fs.statSync)("/app");
|
|
109
|
+
if (appStat.isDirectory()) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function isVMEnvironment() {
|
|
117
|
+
return isDockerEnvironment() || isLimaEnvironment();
|
|
118
|
+
}
|
|
119
|
+
function resolveHostGateway() {
|
|
120
|
+
if (cachedGatewayHost !== void 0) {
|
|
121
|
+
return cachedGatewayHost;
|
|
122
|
+
}
|
|
123
|
+
const envIP = process.env.QUILLTAP_HOST_IP;
|
|
124
|
+
if (envIP) {
|
|
125
|
+
rewriteLogger.info("Host gateway from QUILLTAP_HOST_IP", { host: envIP });
|
|
126
|
+
cachedGatewayHost = envIP;
|
|
127
|
+
return cachedGatewayHost;
|
|
128
|
+
}
|
|
129
|
+
if (isDockerEnvironment() && !isLimaEnvironment()) {
|
|
130
|
+
rewriteLogger.info("Docker environment detected \u2014 using host.docker.internal as gateway hostname");
|
|
131
|
+
cachedGatewayHost = "host.docker.internal";
|
|
132
|
+
return cachedGatewayHost;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const routeTable = (0, import_node_fs.readFileSync)("/proc/net/route", "utf-8");
|
|
136
|
+
for (const line of routeTable.split("\n").slice(1)) {
|
|
137
|
+
const fields = line.trim().split(" ");
|
|
138
|
+
if (fields.length >= 3 && fields[1] === "00000000") {
|
|
139
|
+
const hexGateway = fields[2];
|
|
140
|
+
const ip = [
|
|
141
|
+
parseInt(hexGateway.substring(6, 8), 16),
|
|
142
|
+
parseInt(hexGateway.substring(4, 6), 16),
|
|
143
|
+
parseInt(hexGateway.substring(2, 4), 16),
|
|
144
|
+
parseInt(hexGateway.substring(0, 2), 16)
|
|
145
|
+
].join(".");
|
|
146
|
+
rewriteLogger.info("Host gateway IP from /proc/net/route", { ip });
|
|
147
|
+
cachedGatewayHost = ip;
|
|
148
|
+
return cachedGatewayHost;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} catch {
|
|
152
|
+
rewriteLogger.debug("Could not read /proc/net/route for default gateway lookup");
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
const hosts = (0, import_node_fs.readFileSync)("/etc/hosts", "utf-8");
|
|
156
|
+
for (const line of hosts.split("\n")) {
|
|
157
|
+
const trimmed = line.trim();
|
|
158
|
+
if (trimmed.startsWith("#") || trimmed === "") continue;
|
|
159
|
+
const parts = trimmed.split(/\s+/);
|
|
160
|
+
if (parts.length >= 2 && parts.slice(1).includes("host.docker.internal")) {
|
|
161
|
+
const ip = parts[0];
|
|
162
|
+
rewriteLogger.info("Host gateway IP from /etc/hosts (host.docker.internal)", { ip });
|
|
163
|
+
cachedGatewayHost = ip;
|
|
164
|
+
return cachedGatewayHost;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
rewriteLogger.debug("Could not read /etc/hosts for host.docker.internal lookup");
|
|
169
|
+
}
|
|
170
|
+
rewriteLogger.warn("Could not resolve host gateway \u2014 localhost URLs will not be rewritten");
|
|
171
|
+
cachedGatewayHost = null;
|
|
172
|
+
return cachedGatewayHost;
|
|
173
|
+
}
|
|
174
|
+
function rewriteLocalhostUrl(url) {
|
|
175
|
+
if (!isVMEnvironment()) {
|
|
176
|
+
return url;
|
|
177
|
+
}
|
|
178
|
+
let parsed;
|
|
179
|
+
try {
|
|
180
|
+
parsed = new URL(url);
|
|
181
|
+
} catch {
|
|
182
|
+
return url;
|
|
183
|
+
}
|
|
184
|
+
if (!LOCALHOST_HOSTS.has(parsed.hostname)) {
|
|
185
|
+
return url;
|
|
186
|
+
}
|
|
187
|
+
const gatewayHost = resolveHostGateway();
|
|
188
|
+
if (!gatewayHost) {
|
|
189
|
+
return url;
|
|
190
|
+
}
|
|
191
|
+
parsed.hostname = gatewayHost;
|
|
192
|
+
const rewritten = parsed.toString();
|
|
193
|
+
rewriteLogger.debug("Rewrote localhost URL", {
|
|
194
|
+
original: url,
|
|
195
|
+
rewritten,
|
|
196
|
+
gatewayHost
|
|
197
|
+
});
|
|
198
|
+
return rewritten;
|
|
199
|
+
}
|
|
200
|
+
function _resetGatewayCache() {
|
|
201
|
+
cachedGatewayHost = void 0;
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
_resetGatewayCache,
|
|
206
|
+
isVMEnvironment,
|
|
207
|
+
resolveHostGateway,
|
|
208
|
+
rewriteLocalhostUrl
|
|
209
|
+
});
|
|
210
|
+
//# sourceMappingURL=host-rewrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host-rewrite.ts","../src/logging/plugin-logger.ts","../src/logging/index.ts"],"sourcesContent":["/**\n * Host URL Rewriting for VM/Container Environments\n *\n * When Quilltap runs inside Docker, Lima VMs, or WSL2, `localhost` and\n * `127.0.0.1` resolve to the container/VM's own loopback — not the host\n * machine where services like Ollama or LM Studio are running.\n *\n * This module provides a single function that transparently rewrites\n * localhost URLs to point at the host, so users can configure\n * `http://localhost:11434` and have it Just Work in every environment.\n *\n * Gateway resolution order:\n * 1. `QUILLTAP_HOST_IP` env var (explicit override) → rewrite to that IP\n * 2. In Docker (not Lima): rewrite `localhost` → `host.docker.internal`\n * (Docker Desktop DNS or --add-host on Linux handles the forwarding)\n * 3. Default gateway from /proc/net/route (works in Lima and WSL2 where\n * NAT networking forwards to host loopback)\n * 4. Fallback: try DNS lookup of `host.docker.internal` via /etc/hosts\n * 5. Give up gracefully — return URL unchanged\n *\n * @module @quilltap/plugin-utils/host-rewrite\n */\n\nimport { createPluginLogger } from './logging';\nimport { readFileSync, existsSync, statSync } from 'node:fs';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Hostnames that refer to the local loopback */\nconst LOCALHOST_HOSTS = new Set([\n 'localhost',\n '127.0.0.1',\n '[::1]',\n '::1',\n]);\n\n// ============================================================================\n// Cached Gateway Host\n// ============================================================================\n\nlet cachedGatewayHost: string | null | undefined; // undefined = not yet resolved\n\nconst rewriteLogger = createPluginLogger('host-rewrite');\n\n// ============================================================================\n// Environment Detection (self-contained)\n// ============================================================================\n\n/**\n * Check if running inside a Lima VM.\n *\n * Lima VMs are provisioned with LIMA_CONTAINER=true in /etc/profile.d/quilltap.sh.\n */\nfunction isLimaEnvironment(): boolean {\n return process.env.LIMA_CONTAINER === 'true';\n}\n\n/**\n * Check if running in a Docker container.\n *\n * Detects Docker by checking:\n * 1. DOCKER_CONTAINER environment variable\n * 2. Existence of /.dockerenv file\n * 3. Existence of /app directory (Quilltap Docker convention)\n */\nfunction isDockerEnvironment(): boolean {\n if (process.env.DOCKER_CONTAINER === 'true') {\n return true;\n }\n\n // Check for Docker-specific markers\n try {\n if (existsSync('/.dockerenv')) {\n return true;\n }\n // Check for /app as a directory (Quilltap Docker convention)\n const appStat = statSync('/app');\n if (appStat.isDirectory()) {\n return true;\n }\n } catch {\n // Not in Docker\n }\n\n return false;\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Check if running in any VM or container environment that needs URL rewriting.\n */\nexport function isVMEnvironment(): boolean {\n return isDockerEnvironment() || isLimaEnvironment();\n}\n\n/**\n * Resolve the host gateway address (IP or hostname).\n *\n * Tries multiple strategies in order; caches the result so file reads\n * only happen once per process lifetime.\n */\nexport function resolveHostGateway(): string | null {\n // Return cached result if already resolved\n if (cachedGatewayHost !== undefined) {\n return cachedGatewayHost;\n }\n\n // Strategy 1: Explicit env var override\n const envIP = process.env.QUILLTAP_HOST_IP;\n if (envIP) {\n rewriteLogger.info('Host gateway from QUILLTAP_HOST_IP', { host: envIP });\n cachedGatewayHost = envIP;\n return cachedGatewayHost;\n }\n\n // Strategy 2: Docker — use host.docker.internal directly as a hostname\n // Docker Desktop (macOS/Windows) provides built-in DNS resolution for\n // host.docker.internal via its DNS server (127.0.0.11). Linux Docker\n // needs --add-host=host.docker.internal:host-gateway (handled by the\n // start scripts). Either way, host.docker.internal correctly forwards\n // to services bound to the host's loopback (127.0.0.1).\n //\n // This MUST run before /proc/net/route for Docker because the bridge\n // gateway IP returned by /proc/net/route (e.g. 172.17.0.1) is just\n // the Docker bridge interface — services listening on the host's\n // localhost are NOT reachable through it.\n //\n // Lima VMs are excluded here: they trigger isDockerEnvironment() (they\n // have /app) but don't have host.docker.internal in DNS. Lima uses\n // VZ NAT networking where the /proc/net/route gateway genuinely\n // forwards to the host loopback.\n if (isDockerEnvironment() && !isLimaEnvironment()) {\n rewriteLogger.info('Docker environment detected — using host.docker.internal as gateway hostname');\n cachedGatewayHost = 'host.docker.internal';\n return cachedGatewayHost;\n }\n\n // Strategy 3: Default gateway from /proc/net/route (Lima/WSL2)\n // Parse the kernel routing table directly instead of shelling out to\n // `ip route`, which is unavailable in Alpine Linux images.\n // The file format is tab-separated with hex-encoded IPs.\n // This works for Lima and WSL2 where NAT networking forwards traffic\n // from the gateway IP to the host's loopback.\n try {\n const routeTable = readFileSync('/proc/net/route', 'utf-8');\n for (const line of routeTable.split('\\n').slice(1)) { // skip header\n const fields = line.trim().split('\\t');\n // fields[1] = Destination, fields[2] = Gateway\n // Default route has destination 00000000\n if (fields.length >= 3 && fields[1] === '00000000') {\n const hexGateway = fields[2];\n // Convert hex gateway to dotted-quad IP (little-endian on Linux)\n const ip = [\n parseInt(hexGateway.substring(6, 8), 16),\n parseInt(hexGateway.substring(4, 6), 16),\n parseInt(hexGateway.substring(2, 4), 16),\n parseInt(hexGateway.substring(0, 2), 16),\n ].join('.');\n rewriteLogger.info('Host gateway IP from /proc/net/route', { ip });\n cachedGatewayHost = ip;\n return cachedGatewayHost;\n }\n }\n } catch {\n rewriteLogger.debug('Could not read /proc/net/route for default gateway lookup');\n }\n\n // Strategy 4: Fallback — resolve host.docker.internal from /etc/hosts\n // Covers edge cases where Docker adds it to /etc/hosts but we're not\n // detected as Docker (e.g., custom container runtimes).\n try {\n const hosts = readFileSync('/etc/hosts', 'utf-8');\n for (const line of hosts.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('#') || trimmed === '') continue;\n // /etc/hosts format: <IP> <hostname1> [hostname2] ...\n const parts = trimmed.split(/\\s+/);\n if (parts.length >= 2 && parts.slice(1).includes('host.docker.internal')) {\n const ip = parts[0];\n rewriteLogger.info('Host gateway IP from /etc/hosts (host.docker.internal)', { ip });\n cachedGatewayHost = ip;\n return cachedGatewayHost;\n }\n }\n } catch {\n rewriteLogger.debug('Could not read /etc/hosts for host.docker.internal lookup');\n }\n\n rewriteLogger.warn('Could not resolve host gateway — localhost URLs will not be rewritten');\n cachedGatewayHost = null;\n return cachedGatewayHost;\n}\n\n/**\n * Rewrite a localhost URL to point at the host gateway.\n *\n * No-ops when:\n * - Not running in a VM/container environment\n * - The URL doesn't point to localhost or 127.0.0.1\n * - Gateway resolution fails\n *\n * @param url The URL to potentially rewrite\n * @returns The original URL or a rewritten version with the gateway host\n */\nexport function rewriteLocalhostUrl(url: string): string {\n // No-op on bare metal\n if (!isVMEnvironment()) {\n return url;\n }\n\n // Parse the URL to check the hostname\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n // Not a valid URL — return unchanged\n return url;\n }\n\n // Check if hostname is a localhost variant\n if (!LOCALHOST_HOSTS.has(parsed.hostname)) {\n return url;\n }\n\n // Resolve the gateway host\n const gatewayHost = resolveHostGateway();\n if (!gatewayHost) {\n return url;\n }\n\n // Rewrite the hostname\n parsed.hostname = gatewayHost;\n const rewritten = parsed.toString();\n\n rewriteLogger.debug('Rewrote localhost URL', {\n original: url,\n rewritten,\n gatewayHost,\n });\n\n return rewritten;\n}\n\n/**\n * Reset the cached gateway host (for testing).\n * @internal\n */\nexport function _resetGatewayCache(): void {\n cachedGatewayHost = undefined;\n}\n","/**\n * Plugin Logger Bridge\n *\n * Provides a logger factory for plugins that automatically bridges\n * to Quilltap's core logging when running inside the host application,\n * or falls back to console logging when running standalone.\n *\n * @module @quilltap/plugin-utils/logging/plugin-logger\n */\n\nimport type { PluginLogger, LogContext, LogLevel } from '@quilltap/plugin-types';\n\n/**\n * Extended logger interface with child logger support\n */\nexport interface PluginLoggerWithChild extends PluginLogger {\n /**\n * Create a child logger with additional context\n * @param additionalContext Context to merge with parent context\n * @returns A new logger with combined context\n */\n child(additionalContext: LogContext): PluginLoggerWithChild;\n}\n\n/**\n * Type for the global Quilltap logger bridge\n * Stored on globalThis to work across different npm package copies\n */\ndeclare global {\n \n var __quilltap_logger_factory:\n | ((pluginName: string) => PluginLoggerWithChild)\n | undefined;\n}\n\n/**\n * Get the core logger factory from global namespace\n *\n * @returns The injected factory or null if not in Quilltap environment\n */\nfunction getCoreLoggerFactory(): ((pluginName: string) => PluginLoggerWithChild) | null {\n return globalThis.__quilltap_logger_factory ?? null;\n}\n\n/**\n * Inject the core logger factory from Quilltap host\n *\n * This is called by Quilltap core when loading plugins to bridge\n * plugin logging into the host's logging system. Uses globalThis\n * to ensure it works even when plugins have their own copy of\n * plugin-utils in their node_modules.\n *\n * **Internal API - not for plugin use**\n *\n * @param factory A function that creates a child logger for a plugin\n */\nexport function __injectCoreLoggerFactory(\n factory: (pluginName: string) => PluginLoggerWithChild\n): void {\n globalThis.__quilltap_logger_factory = factory;\n}\n\n/**\n * Clear the injected core logger factory\n *\n * Useful for testing or when unloading the plugin system.\n *\n * **Internal API - not for plugin use**\n */\nexport function __clearCoreLoggerFactory(): void {\n globalThis.__quilltap_logger_factory = undefined;\n}\n\n/**\n * Check if a core logger has been injected\n *\n * @returns True if running inside Quilltap with core logging available\n */\nexport function hasCoreLogger(): boolean {\n return getCoreLoggerFactory() !== null;\n}\n\n/**\n * Create a console logger with child support\n *\n * @param prefix Logger prefix\n * @param minLevel Minimum log level\n * @param baseContext Base context to include in all logs\n */\nfunction createConsoleLoggerWithChild(\n prefix: string,\n minLevel: LogLevel = 'debug',\n baseContext: LogContext = {}\n): PluginLoggerWithChild {\n const levels: LogLevel[] = ['debug', 'info', 'warn', 'error'];\n const shouldLog = (level: LogLevel): boolean =>\n levels.indexOf(level) >= levels.indexOf(minLevel);\n\n const formatContext = (context?: LogContext): string => {\n const merged = { ...baseContext, ...context };\n const entries = Object.entries(merged)\n .filter(([key]) => key !== 'context')\n .map(([key, value]) => `${key}=${JSON.stringify(value)}`)\n .join(' ');\n return entries ? ` ${entries}` : '';\n };\n\n const logger: PluginLoggerWithChild = {\n debug: (message: string, context?: LogContext): void => {\n if (shouldLog('debug')) {\n console.debug(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n info: (message: string, context?: LogContext): void => {\n if (shouldLog('info')) {\n console.info(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n warn: (message: string, context?: LogContext): void => {\n if (shouldLog('warn')) {\n console.warn(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n error: (message: string, context?: LogContext, error?: Error): void => {\n if (shouldLog('error')) {\n console.error(\n `[${prefix}] ${message}${formatContext(context)}`,\n error ? `\\n${error.stack || error.message}` : ''\n );\n }\n },\n\n child: (additionalContext: LogContext): PluginLoggerWithChild => {\n return createConsoleLoggerWithChild(prefix, minLevel, {\n ...baseContext,\n ...additionalContext,\n });\n },\n };\n\n return logger;\n}\n\n/**\n * Create a plugin logger that bridges to Quilltap core logging\n *\n * When running inside Quilltap:\n * - Routes all logs to the core logger\n * - Tags logs with `{ plugin: pluginName, module: 'plugin' }`\n * - Logs appear in Quilltap's combined.log and console\n *\n * When running standalone:\n * - Falls back to console logging with `[pluginName]` prefix\n * - Respects the specified minimum log level\n *\n * @param pluginName - The plugin identifier (e.g., 'qtap-plugin-openai')\n * @param minLevel - Minimum log level when running standalone (default: 'debug')\n * @returns A logger instance\n *\n * @example\n * ```typescript\n * // In your plugin's provider.ts\n * import { createPluginLogger } from '@quilltap/plugin-utils';\n *\n * const logger = createPluginLogger('qtap-plugin-my-provider');\n *\n * export class MyProvider implements LLMProvider {\n * async sendMessage(params: LLMParams, apiKey: string): Promise<LLMResponse> {\n * logger.debug('Sending message', { model: params.model });\n *\n * try {\n * const response = await this.client.chat({...});\n * logger.info('Received response', { tokens: response.usage?.total_tokens });\n * return response;\n * } catch (error) {\n * logger.error('Failed to send message', { model: params.model }, error as Error);\n * throw error;\n * }\n * }\n * }\n * ```\n */\nexport function createPluginLogger(\n pluginName: string,\n minLevel: LogLevel = 'debug'\n): PluginLoggerWithChild {\n // Check for core logger factory from global namespace\n const coreFactory = getCoreLoggerFactory();\n if (coreFactory) {\n return coreFactory(pluginName);\n }\n\n // Standalone mode: use enhanced console logger\n return createConsoleLoggerWithChild(pluginName, minLevel);\n}\n\n/**\n * Get the minimum log level from environment\n *\n * Checks for LOG_LEVEL or QUILLTAP_LOG_LEVEL environment variables.\n * Useful for configuring standalone plugin logging.\n *\n * @returns The configured log level, or 'info' as default\n */\nexport function getLogLevelFromEnv(): LogLevel {\n if (typeof process !== 'undefined' && process.env) {\n const envLevel = process.env.LOG_LEVEL || process.env.QUILLTAP_LOG_LEVEL;\n if (envLevel && ['debug', 'info', 'warn', 'error'].includes(envLevel)) {\n return envLevel as LogLevel;\n }\n }\n return 'info';\n}\n","/**\n * Logging Utilities\n *\n * Exports the plugin logger bridge and related utilities.\n *\n * @module @quilltap/plugin-utils/logging\n */\n\nexport {\n createPluginLogger,\n hasCoreLogger,\n getLogLevelFromEnv,\n __injectCoreLoggerFactory,\n __clearCoreLoggerFactory,\n} from './plugin-logger';\n\nexport type { PluginLoggerWithChild } from './plugin-logger';\n\n// Re-export logger types from plugin-types\nexport type { PluginLogger, LogContext, LogLevel } from '@quilltap/plugin-types';\n\n// Re-export logger utilities from plugin-types for convenience\nexport { createConsoleLogger, createNoopLogger } from '@quilltap/plugin-types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACwCA,SAAS,uBAA+E;AACtF,SAAO,WAAW,6BAA6B;AACjD;AA+CA,SAAS,6BACP,QACA,WAAqB,SACrB,cAA0B,CAAC,GACJ;AACvB,QAAM,SAAqB,CAAC,SAAS,QAAQ,QAAQ,OAAO;AAC5D,QAAM,YAAY,CAAC,UACjB,OAAO,QAAQ,KAAK,KAAK,OAAO,QAAQ,QAAQ;AAElD,QAAM,gBAAgB,CAAC,YAAiC;AACtD,UAAM,SAAS,EAAE,GAAG,aAAa,GAAG,QAAQ;AAC5C,UAAM,UAAU,OAAO,QAAQ,MAAM,EAClC,OAAO,CAAC,CAAC,GAAG,MAAM,QAAQ,SAAS,EACnC,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,UAAU,KAAK,CAAC,EAAE,EACvD,KAAK,GAAG;AACX,WAAO,UAAU,IAAI,OAAO,KAAK;AAAA,EACnC;AAEA,QAAM,SAAgC;AAAA,IACpC,OAAO,CAAC,SAAiB,YAA+B;AACtD,UAAI,UAAU,OAAO,GAAG;AACtB,gBAAQ,MAAM,IAAI,MAAM,KAAK,OAAO,GAAG,cAAc,OAAO,CAAC,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,IAEA,MAAM,CAAC,SAAiB,YAA+B;AACrD,UAAI,UAAU,MAAM,GAAG;AACrB,gBAAQ,KAAK,IAAI,MAAM,KAAK,OAAO,GAAG,cAAc,OAAO,CAAC,EAAE;AAAA,MAChE;AAAA,IACF;AAAA,IAEA,MAAM,CAAC,SAAiB,YAA+B;AACrD,UAAI,UAAU,MAAM,GAAG;AACrB,gBAAQ,KAAK,IAAI,MAAM,KAAK,OAAO,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AG;AACxE,cAAM,KAAK,MAAM,CAAC;AAClB,sBAAc,KAAK,0DAA0D,EAAE,GAAG,CAAC;AACnF,4BAAoB;AACpB,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF,QAAQ;AACN,kBAAc,MAAM,2DAA2D;AAAA,EACjF;AAEA,gBAAc,KAAK,4EAAuE;AAC1F,sBAAoB;AACpB,SAAO;AACT;AAaO,SAAS,oBAAoB,KAAqB;AAEvD,MAAI,CAAC,gBAAgB,GAAG;AACtB,WAAO;AAAA,EACT;AAGA,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,GAAG;AAAA,EACtB,QAAQ;AAEN,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,gBAAgB,IAAI,OAAO,QAAQ,GAAG;AACzC,WAAO;AAAA,EACT;AAGA,QAAM,cAAc,mBAAmB;AACvC,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAGA,SAAO,WAAW;AAClB,QAAM,YAAY,OAAO,SAAS;AAElC,gBAAc,MAAM,yBAAyB;AAAA,IAC3C,UAAU;AAAA,IACV;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAMO,SAAS,qBAA2B;AACzC,sBAAoB;AACtB;","names":[]}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// src/logging/plugin-logger.ts
|
|
2
|
+
function getCoreLoggerFactory() {
|
|
3
|
+
return globalThis.__quilltap_logger_factory ?? null;
|
|
4
|
+
}
|
|
5
|
+
function createConsoleLoggerWithChild(prefix, minLevel = "debug", baseContext = {}) {
|
|
6
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
7
|
+
const shouldLog = (level) => levels.indexOf(level) >= levels.indexOf(minLevel);
|
|
8
|
+
const formatContext = (context) => {
|
|
9
|
+
const merged = { ...baseContext, ...context };
|
|
10
|
+
const entries = Object.entries(merged).filter(([key]) => key !== "context").map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(" ");
|
|
11
|
+
return entries ? ` ${entries}` : "";
|
|
12
|
+
};
|
|
13
|
+
const logger = {
|
|
14
|
+
debug: (message, context) => {
|
|
15
|
+
if (shouldLog("debug")) {
|
|
16
|
+
console.debug(`[${prefix}] ${message}${formatContext(context)}`);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
info: (message, context) => {
|
|
20
|
+
if (shouldLog("info")) {
|
|
21
|
+
console.info(`[${prefix}] ${message}${formatContext(context)}`);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
warn: (message, context) => {
|
|
25
|
+
if (shouldLog("warn")) {
|
|
26
|
+
console.warn(`[${prefix}] ${message}${formatContext(context)}`);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
error: (message, context, error) => {
|
|
30
|
+
if (shouldLog("error")) {
|
|
31
|
+
console.error(
|
|
32
|
+
`[${prefix}] ${message}${formatContext(context)}`,
|
|
33
|
+
error ? `
|
|
34
|
+
${error.stack || error.message}` : ""
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
child: (additionalContext) => {
|
|
39
|
+
return createConsoleLoggerWithChild(prefix, minLevel, {
|
|
40
|
+
...baseContext,
|
|
41
|
+
...additionalContext
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return logger;
|
|
46
|
+
}
|
|
47
|
+
function createPluginLogger(pluginName, minLevel = "debug") {
|
|
48
|
+
const coreFactory = getCoreLoggerFactory();
|
|
49
|
+
if (coreFactory) {
|
|
50
|
+
return coreFactory(pluginName);
|
|
51
|
+
}
|
|
52
|
+
return createConsoleLoggerWithChild(pluginName, minLevel);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/logging/index.ts
|
|
56
|
+
import { createConsoleLogger, createNoopLogger } from "@quilltap/plugin-types";
|
|
57
|
+
|
|
58
|
+
// src/host-rewrite.ts
|
|
59
|
+
import { readFileSync, existsSync, statSync } from "fs";
|
|
60
|
+
var LOCALHOST_HOSTS = /* @__PURE__ */ new Set([
|
|
61
|
+
"localhost",
|
|
62
|
+
"127.0.0.1",
|
|
63
|
+
"[::1]",
|
|
64
|
+
"::1"
|
|
65
|
+
]);
|
|
66
|
+
var cachedGatewayHost;
|
|
67
|
+
var rewriteLogger = createPluginLogger("host-rewrite");
|
|
68
|
+
function isLimaEnvironment() {
|
|
69
|
+
return process.env.LIMA_CONTAINER === "true";
|
|
70
|
+
}
|
|
71
|
+
function isDockerEnvironment() {
|
|
72
|
+
if (process.env.DOCKER_CONTAINER === "true") {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
if (existsSync("/.dockerenv")) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const appStat = statSync("/app");
|
|
80
|
+
if (appStat.isDirectory()) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
function isVMEnvironment() {
|
|
88
|
+
return isDockerEnvironment() || isLimaEnvironment();
|
|
89
|
+
}
|
|
90
|
+
function resolveHostGateway() {
|
|
91
|
+
if (cachedGatewayHost !== void 0) {
|
|
92
|
+
return cachedGatewayHost;
|
|
93
|
+
}
|
|
94
|
+
const envIP = process.env.QUILLTAP_HOST_IP;
|
|
95
|
+
if (envIP) {
|
|
96
|
+
rewriteLogger.info("Host gateway from QUILLTAP_HOST_IP", { host: envIP });
|
|
97
|
+
cachedGatewayHost = envIP;
|
|
98
|
+
return cachedGatewayHost;
|
|
99
|
+
}
|
|
100
|
+
if (isDockerEnvironment() && !isLimaEnvironment()) {
|
|
101
|
+
rewriteLogger.info("Docker environment detected \u2014 using host.docker.internal as gateway hostname");
|
|
102
|
+
cachedGatewayHost = "host.docker.internal";
|
|
103
|
+
return cachedGatewayHost;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const routeTable = readFileSync("/proc/net/route", "utf-8");
|
|
107
|
+
for (const line of routeTable.split("\n").slice(1)) {
|
|
108
|
+
const fields = line.trim().split(" ");
|
|
109
|
+
if (fields.length >= 3 && fields[1] === "00000000") {
|
|
110
|
+
const hexGateway = fields[2];
|
|
111
|
+
const ip = [
|
|
112
|
+
parseInt(hexGateway.substring(6, 8), 16),
|
|
113
|
+
parseInt(hexGateway.substring(4, 6), 16),
|
|
114
|
+
parseInt(hexGateway.substring(2, 4), 16),
|
|
115
|
+
parseInt(hexGateway.substring(0, 2), 16)
|
|
116
|
+
].join(".");
|
|
117
|
+
rewriteLogger.info("Host gateway IP from /proc/net/route", { ip });
|
|
118
|
+
cachedGatewayHost = ip;
|
|
119
|
+
return cachedGatewayHost;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
rewriteLogger.debug("Could not read /proc/net/route for default gateway lookup");
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const hosts = readFileSync("/etc/hosts", "utf-8");
|
|
127
|
+
for (const line of hosts.split("\n")) {
|
|
128
|
+
const trimmed = line.trim();
|
|
129
|
+
if (trimmed.startsWith("#") || trimmed === "") continue;
|
|
130
|
+
const parts = trimmed.split(/\s+/);
|
|
131
|
+
if (parts.length >= 2 && parts.slice(1).includes("host.docker.internal")) {
|
|
132
|
+
const ip = parts[0];
|
|
133
|
+
rewriteLogger.info("Host gateway IP from /etc/hosts (host.docker.internal)", { ip });
|
|
134
|
+
cachedGatewayHost = ip;
|
|
135
|
+
return cachedGatewayHost;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} catch {
|
|
139
|
+
rewriteLogger.debug("Could not read /etc/hosts for host.docker.internal lookup");
|
|
140
|
+
}
|
|
141
|
+
rewriteLogger.warn("Could not resolve host gateway \u2014 localhost URLs will not be rewritten");
|
|
142
|
+
cachedGatewayHost = null;
|
|
143
|
+
return cachedGatewayHost;
|
|
144
|
+
}
|
|
145
|
+
function rewriteLocalhostUrl(url) {
|
|
146
|
+
if (!isVMEnvironment()) {
|
|
147
|
+
return url;
|
|
148
|
+
}
|
|
149
|
+
let parsed;
|
|
150
|
+
try {
|
|
151
|
+
parsed = new URL(url);
|
|
152
|
+
} catch {
|
|
153
|
+
return url;
|
|
154
|
+
}
|
|
155
|
+
if (!LOCALHOST_HOSTS.has(parsed.hostname)) {
|
|
156
|
+
return url;
|
|
157
|
+
}
|
|
158
|
+
const gatewayHost = resolveHostGateway();
|
|
159
|
+
if (!gatewayHost) {
|
|
160
|
+
return url;
|
|
161
|
+
}
|
|
162
|
+
parsed.hostname = gatewayHost;
|
|
163
|
+
const rewritten = parsed.toString();
|
|
164
|
+
rewriteLogger.debug("Rewrote localhost URL", {
|
|
165
|
+
original: url,
|
|
166
|
+
rewritten,
|
|
167
|
+
gatewayHost
|
|
168
|
+
});
|
|
169
|
+
return rewritten;
|
|
170
|
+
}
|
|
171
|
+
function _resetGatewayCache() {
|
|
172
|
+
cachedGatewayHost = void 0;
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
_resetGatewayCache,
|
|
176
|
+
isVMEnvironment,
|
|
177
|
+
resolveHostGateway,
|
|
178
|
+
rewriteLocalhostUrl
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=host-rewrite.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging/plugin-logger.ts","../src/logging/index.ts","../src/host-rewrite.ts"],"sourcesContent":["/**\n * Plugin Logger Bridge\n *\n * Provides a logger factory for plugins that automatically bridges\n * to Quilltap's core logging when running inside the host application,\n * or falls back to console logging when running standalone.\n *\n * @module @quilltap/plugin-utils/logging/plugin-logger\n */\n\nimport type { PluginLogger, LogContext, LogLevel } from '@quilltap/plugin-types';\n\n/**\n * Extended logger interface with child logger support\n */\nexport interface PluginLoggerWithChild extends PluginLogger {\n /**\n * Create a child logger with additional context\n * @param additionalContext Context to merge with parent context\n * @returns A new logger with combined context\n */\n child(additionalContext: LogContext): PluginLoggerWithChild;\n}\n\n/**\n * Type for the global Quilltap logger bridge\n * Stored on globalThis to work across different npm package copies\n */\ndeclare global {\n \n var __quilltap_logger_factory:\n | ((pluginName: string) => PluginLoggerWithChild)\n | undefined;\n}\n\n/**\n * Get the core logger factory from global namespace\n *\n * @returns The injected factory or null if not in Quilltap environment\n */\nfunction getCoreLoggerFactory(): ((pluginName: string) => PluginLoggerWithChild) | null {\n return globalThis.__quilltap_logger_factory ?? null;\n}\n\n/**\n * Inject the core logger factory from Quilltap host\n *\n * This is called by Quilltap core when loading plugins to bridge\n * plugin logging into the host's logging system. Uses globalThis\n * to ensure it works even when plugins have their own copy of\n * plugin-utils in their node_modules.\n *\n * **Internal API - not for plugin use**\n *\n * @param factory A function that creates a child logger for a plugin\n */\nexport function __injectCoreLoggerFactory(\n factory: (pluginName: string) => PluginLoggerWithChild\n): void {\n globalThis.__quilltap_logger_factory = factory;\n}\n\n/**\n * Clear the injected core logger factory\n *\n * Useful for testing or when unloading the plugin system.\n *\n * **Internal API - not for plugin use**\n */\nexport function __clearCoreLoggerFactory(): void {\n globalThis.__quilltap_logger_factory = undefined;\n}\n\n/**\n * Check if a core logger has been injected\n *\n * @returns True if running inside Quilltap with core logging available\n */\nexport function hasCoreLogger(): boolean {\n return getCoreLoggerFactory() !== null;\n}\n\n/**\n * Create a console logger with child support\n *\n * @param prefix Logger prefix\n * @param minLevel Minimum log level\n * @param baseContext Base context to include in all logs\n */\nfunction createConsoleLoggerWithChild(\n prefix: string,\n minLevel: LogLevel = 'debug',\n baseContext: LogContext = {}\n): PluginLoggerWithChild {\n const levels: LogLevel[] = ['debug', 'info', 'warn', 'error'];\n const shouldLog = (level: LogLevel): boolean =>\n levels.indexOf(level) >= levels.indexOf(minLevel);\n\n const formatContext = (context?: LogContext): string => {\n const merged = { ...baseContext, ...context };\n const entries = Object.entries(merged)\n .filter(([key]) => key !== 'context')\n .map(([key, value]) => `${key}=${JSON.stringify(value)}`)\n .join(' ');\n return entries ? ` ${entries}` : '';\n };\n\n const logger: PluginLoggerWithChild = {\n debug: (message: string, context?: LogContext): void => {\n if (shouldLog('debug')) {\n console.debug(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n info: (message: string, context?: LogContext): void => {\n if (shouldLog('info')) {\n console.info(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n warn: (message: string, context?: LogContext): void => {\n if (shouldLog('warn')) {\n console.warn(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n error: (message: string, context?: LogContext, error?: Error): void => {\n if (shouldLog('error')) {\n console.error(\n `[${prefix}] ${message}${formatContext(context)}`,\n error ? `\\n${error.stack || error.message}` : ''\n );\n }\n },\n\n child: (additionalContext: LogContext): PluginLoggerWithChild => {\n return createConsoleLoggerWithChild(prefix, minLevel, {\n ...baseContext,\n ...additionalContext,\n });\n },\n };\n\n return logger;\n}\n\n/**\n * Create a plugin logger that bridges to Quilltap core logging\n *\n * When running inside Quilltap:\n * - Routes all logs to the core logger\n * - Tags logs with `{ plugin: pluginName, module: 'plugin' }`\n * - Logs appear in Quilltap's combined.log and console\n *\n * When running standalone:\n * - Falls back to console logging with `[pluginName]` prefix\n * - Respects the specified minimum log level\n *\n * @param pluginName - The plugin identifier (e.g., 'qtap-plugin-openai')\n * @param minLevel - Minimum log level when running standalone (default: 'debug')\n * @returns A logger instance\n *\n * @example\n * ```typescript\n * // In your plugin's provider.ts\n * import { createPluginLogger } from '@quilltap/plugin-utils';\n *\n * const logger = createPluginLogger('qtap-plugin-my-provider');\n *\n * export class MyProvider implements LLMProvider {\n * async sendMessage(params: LLMParams, apiKey: string): Promise<LLMResponse> {\n * logger.debug('Sending message', { model: params.model });\n *\n * try {\n * const response = await this.client.chat({...});\n * logger.info('Received response', { tokens: response.usage?.total_tokens });\n * return response;\n * } catch (error) {\n * logger.error('Failed to send message', { model: params.model }, error as Error);\n * throw error;\n * }\n * }\n * }\n * ```\n */\nexport function createPluginLogger(\n pluginName: string,\n minLevel: LogLevel = 'debug'\n): PluginLoggerWithChild {\n // Check for core logger factory from global namespace\n const coreFactory = getCoreLoggerFactory();\n if (coreFactory) {\n return coreFactory(pluginName);\n }\n\n // Standalone mode: use enhanced console logger\n return createConsoleLoggerWithChild(pluginName, minLevel);\n}\n\n/**\n * Get the minimum log level from environment\n *\n * Checks for LOG_LEVEL or QUILLTAP_LOG_LEVEL environment variables.\n * Useful for configuring standalone plugin logging.\n *\n * @returns The configured log level, or 'info' as default\n */\nexport function getLogLevelFromEnv(): LogLevel {\n if (typeof process !== 'undefined' && process.env) {\n const envLevel = process.env.LOG_LEVEL || process.env.QUILLTAP_LOG_LEVEL;\n if (envLevel && ['debug', 'info', 'warn', 'error'].includes(envLevel)) {\n return envLevel as LogLevel;\n }\n }\n return 'info';\n}\n","/**\n * Logging Utilities\n *\n * Exports the plugin logger bridge and related utilities.\n *\n * @module @quilltap/plugin-utils/logging\n */\n\nexport {\n createPluginLogger,\n hasCoreLogger,\n getLogLevelFromEnv,\n __injectCoreLoggerFactory,\n __clearCoreLoggerFactory,\n} from './plugin-logger';\n\nexport type { PluginLoggerWithChild } from './plugin-logger';\n\n// Re-export logger types from plugin-types\nexport type { PluginLogger, LogContext, LogLevel } from '@quilltap/plugin-types';\n\n// Re-export logger utilities from plugin-types for convenience\nexport { createConsoleLogger, createNoopLogger } from '@quilltap/plugin-types';\n","/**\n * Host URL Rewriting for VM/Container Environments\n *\n * When Quilltap runs inside Docker, Lima VMs, or WSL2, `localhost` and\n * `127.0.0.1` resolve to the container/VM's own loopback — not the host\n * machine where services like Ollama or LM Studio are running.\n *\n * This module provides a single function that transparently rewrites\n * localhost URLs to point at the host, so users can configure\n * `http://localhost:11434` and have it Just Work in every environment.\n *\n * Gateway resolution order:\n * 1. `QUILLTAP_HOST_IP` env var (explicit override) → rewrite to that IP\n * 2. In Docker (not Lima): rewrite `localhost` → `host.docker.internal`\n * (Docker Desktop DNS or --add-host on Linux handles the forwarding)\n * 3. Default gateway from /proc/net/route (works in Lima and WSL2 where\n * NAT networking forwards to host loopback)\n * 4. Fallback: try DNS lookup of `host.docker.internal` via /etc/hosts\n * 5. Give up gracefully — return URL unchanged\n *\n * @module @quilltap/plugin-utils/host-rewrite\n */\n\nimport { createPluginLogger } from './logging';\nimport { readFileSync, existsSync, statSync } from 'node:fs';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Hostnames that refer to the local loopback */\nconst LOCALHOST_HOSTS = new Set([\n 'localhost',\n '127.0.0.1',\n '[::1]',\n '::1',\n]);\n\n// ============================================================================\n// Cached Gateway Host\n// ============================================================================\n\nlet cachedGatewayHost: string | null | undefined; // undefined = not yet resolved\n\nconst rewriteLogger = createPluginLogger('host-rewrite');\n\n// ============================================================================\n// Environment Detection (self-contained)\n// ============================================================================\n\n/**\n * Check if running inside a Lima VM.\n *\n * Lima VMs are provisioned with LIMA_CONTAINER=true in /etc/profile.d/quilltap.sh.\n */\nfunction isLimaEnvironment(): boolean {\n return process.env.LIMA_CONTAINER === 'true';\n}\n\n/**\n * Check if running in a Docker container.\n *\n * Detects Docker by checking:\n * 1. DOCKER_CONTAINER environment variable\n * 2. Existence of /.dockerenv file\n * 3. Existence of /app directory (Quilltap Docker convention)\n */\nfunction isDockerEnvironment(): boolean {\n if (process.env.DOCKER_CONTAINER === 'true') {\n return true;\n }\n\n // Check for Docker-specific markers\n try {\n if (existsSync('/.dockerenv')) {\n return true;\n }\n // Check for /app as a directory (Quilltap Docker convention)\n const appStat = statSync('/app');\n if (appStat.isDirectory()) {\n return true;\n }\n } catch {\n // Not in Docker\n }\n\n return false;\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Check if running in any VM or container environment that needs URL rewriting.\n */\nexport function isVMEnvironment(): boolean {\n return isDockerEnvironment() || isLimaEnvironment();\n}\n\n/**\n * Resolve the host gateway address (IP or hostname).\n *\n * Tries multiple strategies in order; caches the result so file reads\n * only happen once per process lifetime.\n */\nexport function resolveHostGateway(): string | null {\n // Return cached result if already resolved\n if (cachedGatewayHost !== undefined) {\n return cachedGatewayHost;\n }\n\n // Strategy 1: Explicit env var override\n const envIP = process.env.QUILLTAP_HOST_IP;\n if (envIP) {\n rewriteLogger.info('Host gateway from QUILLTAP_HOST_IP', { host: envIP });\n cachedGatewayHost = envIP;\n return cachedGatewayHost;\n }\n\n // Strategy 2: Docker — use host.docker.internal directly as a hostname\n // Docker Desktop (macOS/Windows) provides built-in DNS resolution for\n // host.docker.internal via its DNS server (127.0.0.11). Linux Docker\n // needs --add-host=host.docker.internal:host-gateway (handled by the\n // start scripts). Either way, host.docker.internal correctly forwards\n // to services bound to the host's loopback (127.0.0.1).\n //\n // This MUST run before /proc/net/route for Docker because the bridge\n // gateway IP returned by /proc/net/route (e.g. 172.17.0.1) is just\n // the Docker bridge interface — services listening on the host's\n // localhost are NOT reachable through it.\n //\n // Lima VMs are excluded here: they trigger isDockerEnvironment() (they\n // have /app) but don't have host.docker.internal in DNS. Lima uses\n // VZ NAT networking where the /proc/net/route gateway genuinely\n // forwards to the host loopback.\n if (isDockerEnvironment() && !isLimaEnvironment()) {\n rewriteLogger.info('Docker environment detected — using host.docker.internal as gateway hostname');\n cachedGatewayHost = 'host.docker.internal';\n return cachedGatewayHost;\n }\n\n // Strategy 3: Default gateway from /proc/net/route (Lima/WSL2)\n // Parse the kernel routing table directly instead of shelling out to\n // `ip route`, which is unavailable in Alpine Linux images.\n // The file format is tab-separated with hex-encoded IPs.\n // This works for Lima and WSL2 where NAT networking forwards traffic\n // from the gateway IP to the host's loopback.\n try {\n const routeTable = readFileSync('/proc/net/route', 'utf-8');\n for (const line of routeTable.split('\\n').slice(1)) { // skip header\n const fields = line.trim().split('\\t');\n // fields[1] = Destination, fields[2] = Gateway\n // Default route has destination 00000000\n if (fields.length >= 3 && fields[1] === '00000000') {\n const hexGateway = fields[2];\n // Convert hex gateway to dotted-quad IP (little-endian on Linux)\n const ip = [\n parseInt(hexGateway.substring(6, 8), 16),\n parseInt(hexGateway.substring(4, 6), 16),\n parseInt(hexGateway.substring(2, 4), 16),\n parseInt(hexGateway.substring(0, 2), 16),\n ].join('.');\n rewriteLogger.info('Host gateway IP from /proc/net/route', { ip });\n cachedGatewayHost = ip;\n return cachedGatewayHost;\n }\n }\n } catch {\n rewriteLogger.debug('Could not read /proc/net/route for default gateway lookup');\n }\n\n // Strategy 4: Fallback — resolve host.docker.internal from /etc/hosts\n // Covers edge cases where Docker adds it to /etc/hosts but we're not\n // detected as Docker (e.g., custom container runtimes).\n try {\n const hosts = readFileSync('/etc/hosts', 'utf-8');\n for (const line of hosts.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('#') || trimmed === '') continue;\n // /etc/hosts format: <IP> <hostname1> [hostname2] ...\n const parts = trimmed.split(/\\s+/);\n if (parts.length >= 2 && parts.slice(1).includes('host.docker.internal')) {\n const ip = parts[0];\n rewriteLogger.info('Host gateway IP from /etc/hosts (host.docker.internal)', { ip });\n cachedGatewayHost = ip;\n return cachedGatewayHost;\n }\n }\n } catch {\n rewriteLogger.debug('Could not read /etc/hosts for host.docker.internal lookup');\n }\n\n rewriteLogger.warn('Could not resolve host gateway — localhost URLs will not be rewritten');\n cachedGatewayHost = null;\n return cachedGatewayHost;\n}\n\n/**\n * Rewrite a localhost URL to point at the host gateway.\n *\n * No-ops when:\n * - Not running in a VM/container environment\n * - The URL doesn't point to localhost or 127.0.0.1\n * - Gateway resolution fails\n *\n * @param url The URL to potentially rewrite\n * @returns The original URL or a rewritten version with the gateway host\n */\nexport function rewriteLocalhostUrl(url: string): string {\n // No-op on bare metal\n if (!isVMEnvironment()) {\n return url;\n }\n\n // Parse the URL to check the hostname\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n // Not a valid URL — return unchanged\n return url;\n }\n\n // Check if hostname is a localhost variant\n if (!LOCALHOST_HOSTS.has(parsed.hostname)) {\n return url;\n }\n\n // Resolve the gateway host\n const gatewayHost = resolveHostGateway();\n if (!gatewayHost) {\n return url;\n }\n\n // Rewrite the hostname\n parsed.hostname = gatewayHost;\n const rewritten = parsed.toString();\n\n rewriteLogger.debug('Rewrote localhost URL', {\n original: url,\n rewritten,\n gatewayHost,\n });\n\n return rewritten;\n}\n\n/**\n * Reset the cached gateway host (for testing).\n * @internal\n */\nexport function _resetGatewayCache(): void {\n cachedGatewayHost = undefined;\n}\n"],"mappings":";AAwCA,SAAS,uBAA+E;AACtF,SAAO,WAAW,6BAA6B;AACjD;AA+CA,SAAS,6BACP,QACA,WAAqB,SACrB,cAA0B,CAAC,GACJ;AACvB,QAAM,SAAqB,CAAC,SAAS,QAAQ,QAAQ,OAAO;AAC5D,QAAM,YAAY,CAAC,UACjB,OAAO,QAAQ,KAAK,KAAK,OAAO,QAAQ,QAAQ;AAElD,QAAM,gBAAgB,CAAC,YAAiC;AACtD,UAAM,SAAS,EAAE,GAAG,aAAa,GAAG,QAAQ;AAC5C,UAAM,UAAU,OAAO,QAAQ,MAAM,EAClC,OAAO,CAAC,CAAC,GAAG,MAAM,QAAQ,SAAS,EACnC,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,UAAU,KAAK,CAAC,EAAE,EACvD,KAAK,GAAG;AACX,WAAO,UAAU,IAAI,OAAO,KAAK;AAAA,EACnC;AAEA,QAAM,SAAgC;AAAA,IACpC,OAAO,CAAC,SAAiB,YAA+B;AACtD,UAAI,UAAU,OAAO,GAAG;AACtB,gBAAQ,MAAM,IAAI,MAAM,KAAK,OAAO,GAAG,cAAc,OAAO,CAAC,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,IAEA,MAAM,CAAC,SAAiB,YAA+B;AACrD,UAAI,UAAU,MAAM,GAAG;AACrB,gBAAQ,KAAK,IAAI,MAAM,KAAK,OAAO,GAAG,cAAc,OAAO,CAAC,EAAE;AAAA,MAChE;AAAA,IACF;AAAA,IAEA,MAAM,CAAC,SAAiB,YAA+B;AACrD,UAAI,UAAU,MAAM,GAAG;AACrB,gBAAQ,KAAK,IAAI,MAAM,KAAK,OAAO,GAAG,cAAc,OAAO,CAAC,EAAE;AAAA,MAChE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