@workel/mcp 0.1.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/README.md +152 -0
- package/dist/api/client.d.ts +126 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +313 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/errors.d.ts +142 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +262 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/mapping.d.ts +147 -0
- package/dist/api/mapping.d.ts.map +1 -0
- package/dist/api/mapping.js +248 -0
- package/dist/api/mapping.js.map +1 -0
- package/dist/api/redact.d.ts +54 -0
- package/dist/api/redact.d.ts.map +1 -0
- package/dist/api/redact.js +193 -0
- package/dist/api/redact.js.map +1 -0
- package/dist/api/types.d.ts +155 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/api/types.js +18 -0
- package/dist/api/types.js.map +1 -0
- package/dist/boot.d.ts +129 -0
- package/dist/boot.d.ts.map +1 -0
- package/dist/boot.js +245 -0
- package/dist/boot.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +77 -0
- package/dist/config.js.map +1 -0
- package/dist/doctor.d.ts +42 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +94 -0
- package/dist/doctor.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/output.d.ts +48 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +73 -0
- package/dist/output.js.map +1 -0
- package/dist/remote.d.ts +164 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +456 -0
- package/dist/remote.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +59 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/conventions.d.ts +54 -0
- package/dist/tools/conventions.d.ts.map +1 -0
- package/dist/tools/conventions.js +71 -0
- package/dist/tools/conventions.js.map +1 -0
- package/dist/tools/createComment.d.ts +52 -0
- package/dist/tools/createComment.d.ts.map +1 -0
- package/dist/tools/createComment.js +99 -0
- package/dist/tools/createComment.js.map +1 -0
- package/dist/tools/createEvent.d.ts +63 -0
- package/dist/tools/createEvent.d.ts.map +1 -0
- package/dist/tools/createEvent.js +160 -0
- package/dist/tools/createEvent.js.map +1 -0
- package/dist/tools/createTask.d.ts +53 -0
- package/dist/tools/createTask.d.ts.map +1 -0
- package/dist/tools/createTask.js +136 -0
- package/dist/tools/createTask.js.map +1 -0
- package/dist/tools/defineTool.d.ts +76 -0
- package/dist/tools/defineTool.d.ts.map +1 -0
- package/dist/tools/defineTool.js +31 -0
- package/dist/tools/defineTool.js.map +1 -0
- package/dist/tools/index.d.ts +16 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +49 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registration.d.ts +63 -0
- package/dist/tools/registration.d.ts.map +1 -0
- package/dist/tools/registration.js +95 -0
- package/dist/tools/registration.js.map +1 -0
- package/dist/tools/updateTask.d.ts +53 -0
- package/dist/tools/updateTask.d.ts.map +1 -0
- package/dist/tools/updateTask.js +119 -0
- package/dist/tools/updateTask.js.map +1 -0
- package/dist/tools/workel_events.d.ts +23 -0
- package/dist/tools/workel_events.d.ts.map +1 -0
- package/dist/tools/workel_events.js +60 -0
- package/dist/tools/workel_events.js.map +1 -0
- package/dist/tools/workel_members.d.ts +17 -0
- package/dist/tools/workel_members.d.ts.map +1 -0
- package/dist/tools/workel_members.js +46 -0
- package/dist/tools/workel_members.js.map +1 -0
- package/dist/tools/workel_project_columns.d.ts +13 -0
- package/dist/tools/workel_project_columns.d.ts.map +1 -0
- package/dist/tools/workel_project_columns.js +45 -0
- package/dist/tools/workel_project_columns.js.map +1 -0
- package/dist/tools/workel_projects.d.ts +20 -0
- package/dist/tools/workel_projects.d.ts.map +1 -0
- package/dist/tools/workel_projects.js +74 -0
- package/dist/tools/workel_projects.js.map +1 -0
- package/dist/tools/workel_task_comments.d.ts +21 -0
- package/dist/tools/workel_task_comments.d.ts.map +1 -0
- package/dist/tools/workel_task_comments.js +55 -0
- package/dist/tools/workel_task_comments.js.map +1 -0
- package/dist/tools/workel_tasks.d.ts +23 -0
- package/dist/tools/workel_tasks.d.ts.map +1 -0
- package/dist/tools/workel_tasks.js +104 -0
- package/dist/tools/workel_tasks.js.map +1 -0
- package/dist/tools/workel_whoami.d.ts +16 -0
- package/dist/tools/workel_whoami.d.ts.map +1 -0
- package/dist/tools/workel_whoami.js +36 -0
- package/dist/tools/workel_whoami.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +28 -0
- package/dist/version.js.map +1 -0
- package/package.json +42 -0
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `workel-mcp doctor` — a one-shot diagnostic a customer can run when their
|
|
4
|
+
* MCP client says only "server failed to start" and gives no further detail.
|
|
5
|
+
*
|
|
6
|
+
* Runs the EXACT SAME `GET /me` startup probe `boot.ts` runs (`probeMe`),
|
|
7
|
+
* through the exact same scope→tool-selection seam (`toolScopeGates` /
|
|
8
|
+
* `permittedToolNames`) — reused, not re-implemented, so the two can never
|
|
9
|
+
* report a different answer for the same key/config. See `boot.ts` for the
|
|
10
|
+
* probe and selection logic itself; this module only formats the result.
|
|
11
|
+
*
|
|
12
|
+
* Unlike `boot`, this module runs no transport, so there is no stdout/stderr
|
|
13
|
+
* split to preserve — a stdio MCP session never gets far enough to start for
|
|
14
|
+
* a doctor run to interfere with. Every line, success or failure, goes to
|
|
15
|
+
* `deps.stdout`. `deps.stderr` is threaded through only so a caller/test can
|
|
16
|
+
* prove nothing here ever writes to it (mirrors `boot.ts`'s `deps.stdout`
|
|
17
|
+
* convention, inverted).
|
|
18
|
+
*
|
|
19
|
+
* `runDoctor` never calls `process.exit` — it returns a plain exit code
|
|
20
|
+
* (`0` success, `1` failure) and leaves the decision of when/how to exit to
|
|
21
|
+
* its caller (`index.ts`).
|
|
22
|
+
*
|
|
23
|
+
* D6 (the effective-base-URL defense) is surfaced a second time here,
|
|
24
|
+
* deliberately: the base URL prints UNCONDITIONALLY — default or
|
|
25
|
+
* overridden — with an inline `(override)` marker in the overridden case.
|
|
26
|
+
* A doctor run is exactly the moment a tampered `WORKEL_API_BASE_URL` must
|
|
27
|
+
* be visible, so unlike `boot`'s line (which omits the URL when it's the
|
|
28
|
+
* default, to keep the common case terse) doctor never omits it.
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.runDoctor = runDoctor;
|
|
32
|
+
const client_1 = require("./api/client");
|
|
33
|
+
const redact_1 = require("./api/redact");
|
|
34
|
+
const config_1 = require("./config");
|
|
35
|
+
const boot_1 = require("./boot");
|
|
36
|
+
const SUCCESS = 0;
|
|
37
|
+
const FAILURE = 1;
|
|
38
|
+
function formatBaseUrlLine(config) {
|
|
39
|
+
return config.isCustomBaseUrl ? `base URL: ${config.baseUrl} (override)` : `base URL: ${config.baseUrl}`;
|
|
40
|
+
}
|
|
41
|
+
function formatProbeLines(me, toolNames) {
|
|
42
|
+
const scopes = me.key.scopes.map(boot_1.sanitizeForLine);
|
|
43
|
+
return [
|
|
44
|
+
`workspace: ${(0, boot_1.sanitizeForLine)(me.workspace.name)}`,
|
|
45
|
+
`key: ${(0, boot_1.sanitizeForLine)(me.key.name)}`,
|
|
46
|
+
`scopes: ${scopes.length > 0 ? scopes.join(', ') : 'none'}`,
|
|
47
|
+
`${toolNames.length} tools would register: ${toolNames.length > 0 ? toolNames.join(', ') : 'none'}`,
|
|
48
|
+
`write budget: ${me.rate_limit.write.remaining}/${me.rate_limit.write.limit} remaining this minute`,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Runs the diagnostic and writes its report to `deps.stdout`. Returns `0`
|
|
53
|
+
* when the probe succeeded, `1` for any failure (bad config, network error,
|
|
54
|
+
* a non-2xx response, or a malformed 200 body) — never throws.
|
|
55
|
+
*/
|
|
56
|
+
async function runDoctor(deps) {
|
|
57
|
+
const { env, fetch: injectedFetch, stdout } = deps;
|
|
58
|
+
let config;
|
|
59
|
+
try {
|
|
60
|
+
config = (0, config_1.loadConfig)(env);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
stdout(`${(0, redact_1.redact)(err.message)}\n`);
|
|
64
|
+
return FAILURE;
|
|
65
|
+
}
|
|
66
|
+
(0, redact_1.registerSecret)(config.apiKey);
|
|
67
|
+
const client = (0, client_1.createWorkelApiClient)({
|
|
68
|
+
baseUrl: config.baseUrl,
|
|
69
|
+
apiKey: config.apiKey,
|
|
70
|
+
fetch: injectedFetch,
|
|
71
|
+
sleep: boot_1.defaultSleep,
|
|
72
|
+
});
|
|
73
|
+
// Computed before the probe: which tools this key COULD ever register is
|
|
74
|
+
// static per-descriptor and doesn't depend on the probe succeeding, but is
|
|
75
|
+
// only reported alongside a successful probe below (the tool list is
|
|
76
|
+
// gated on real scopes, which only the probe can supply).
|
|
77
|
+
const gates = (0, boot_1.toolScopeGates)(client);
|
|
78
|
+
const lines = [formatBaseUrlLine(config)];
|
|
79
|
+
let me;
|
|
80
|
+
try {
|
|
81
|
+
me = await (0, boot_1.probeMe)(client);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
lines.push((0, redact_1.redact)((0, boot_1.describeFailure)(err)));
|
|
85
|
+
stdout(`${(0, redact_1.redact)(lines.join('\n'))}\n`);
|
|
86
|
+
return FAILURE;
|
|
87
|
+
}
|
|
88
|
+
const caps = { scopes: me.key.scopes };
|
|
89
|
+
const toolNames = (0, boot_1.permittedToolNames)(gates, caps);
|
|
90
|
+
lines.push(...formatProbeLines(me, toolNames));
|
|
91
|
+
stdout(`${(0, redact_1.redact)(lines.join('\n'))}\n`);
|
|
92
|
+
return SUCCESS;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../src/doctor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;AA+CH,8BA2CC;AAxFD,yCAAqD;AACrD,yCAAsD;AACtD,qCAAmD;AACnD,iCASgB;AAUhB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,OAAO,GAAG,CAAC,CAAC;AAElB,SAAS,iBAAiB,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,OAAO,EAAE,CAAC;AAC3G,CAAC;AAED,SAAS,gBAAgB,CAAC,EAAc,EAAE,SAAmB;IAC3D,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAe,CAAC,CAAC;IAClD,OAAO;QACL,cAAc,IAAA,sBAAe,EAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;QAClD,QAAQ,IAAA,sBAAe,EAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACtC,WAAW,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;QAC3D,GAAG,SAAS,CAAC,MAAM,0BAA0B,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;QACnG,iBAAiB,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,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;QACxC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,GAAe,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;IACnD,MAAM,SAAS,GAAG,IAAA,yBAAkB,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAClD,KAAK,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAE/C,MAAM,CAAC,GAAG,IAAA,eAAM,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The stdio entrypoint. Thin by design: every real decision (config
|
|
4
|
+
* validation, the `/me` probe, scope-gated tool registration, what gets
|
|
5
|
+
* written to stderr) lives in `boot.ts`, which is transport-agnostic and
|
|
6
|
+
* fully unit-tested without ever touching a real process or a real
|
|
7
|
+
* transport. This file's only job is to supply `boot` with the real
|
|
8
|
+
* process — real `process.env`, the real global `fetch`, real
|
|
9
|
+
* stdout/stderr writers, real `process.exit` — and, once `boot` hands back
|
|
10
|
+
* a constructed server, connect it to stdio.
|
|
11
|
+
*
|
|
12
|
+
* `doctor` (T12, `doctor.ts`) is checked BEFORE `boot()` runs and instead of
|
|
13
|
+
* it, not in addition to it: doctor diagnoses a misconfigured setup, so it
|
|
14
|
+
* must not itself depend on boot succeeding, and it never constructs or
|
|
15
|
+
* connects a transport — there is no protocol stream to corrupt when the
|
|
16
|
+
* process is about to exit right after printing its report.
|
|
17
|
+
*
|
|
18
|
+
* `main` takes `argv`/`deps` as explicit parameters (rather than reading
|
|
19
|
+
* `process.argv`/`process.env`/etc. directly) purely so it is callable from
|
|
20
|
+
* a test with no real process involved — the bottom-of-file call below is
|
|
21
|
+
* the only place that supplies the real ones.
|
|
22
|
+
*
|
|
23
|
+
* The bottom-of-file call is guarded by `require.main === module` — the
|
|
24
|
+
* standard CommonJS idiom for "only run this when the file is executed
|
|
25
|
+
* directly, not when it's `require()`d". Without it, `doctor.test.ts`
|
|
26
|
+
* importing `main` from this file for the argv-dispatch tests would ALSO
|
|
27
|
+
* re-run the real entrypoint against the real `process.env`/`process.exit`
|
|
28
|
+
* as an import-time side effect — in a test environment with no
|
|
29
|
+
* `WORKEL_API_KEY` set, that calls the real `process.exit`, killing the
|
|
30
|
+
* Jest worker. The guard changes nothing about how `node dist/index.js` (or
|
|
31
|
+
* the `workel-mcp` bin) behaves: `require.main === module` is true on that
|
|
32
|
+
* path, exactly as it always was.
|
|
33
|
+
*/
|
|
34
|
+
import { type BootDeps } from './boot';
|
|
35
|
+
export declare function main(argv: string[], deps: BootDeps): Promise<void>;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAQ,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAI7C,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAaxE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* The stdio entrypoint. Thin by design: every real decision (config
|
|
5
|
+
* validation, the `/me` probe, scope-gated tool registration, what gets
|
|
6
|
+
* written to stderr) lives in `boot.ts`, which is transport-agnostic and
|
|
7
|
+
* fully unit-tested without ever touching a real process or a real
|
|
8
|
+
* transport. This file's only job is to supply `boot` with the real
|
|
9
|
+
* process — real `process.env`, the real global `fetch`, real
|
|
10
|
+
* stdout/stderr writers, real `process.exit` — and, once `boot` hands back
|
|
11
|
+
* a constructed server, connect it to stdio.
|
|
12
|
+
*
|
|
13
|
+
* `doctor` (T12, `doctor.ts`) is checked BEFORE `boot()` runs and instead of
|
|
14
|
+
* it, not in addition to it: doctor diagnoses a misconfigured setup, so it
|
|
15
|
+
* must not itself depend on boot succeeding, and it never constructs or
|
|
16
|
+
* connects a transport — there is no protocol stream to corrupt when the
|
|
17
|
+
* process is about to exit right after printing its report.
|
|
18
|
+
*
|
|
19
|
+
* `main` takes `argv`/`deps` as explicit parameters (rather than reading
|
|
20
|
+
* `process.argv`/`process.env`/etc. directly) purely so it is callable from
|
|
21
|
+
* a test with no real process involved — the bottom-of-file call below is
|
|
22
|
+
* the only place that supplies the real ones.
|
|
23
|
+
*
|
|
24
|
+
* The bottom-of-file call is guarded by `require.main === module` — the
|
|
25
|
+
* standard CommonJS idiom for "only run this when the file is executed
|
|
26
|
+
* directly, not when it's `require()`d". Without it, `doctor.test.ts`
|
|
27
|
+
* importing `main` from this file for the argv-dispatch tests would ALSO
|
|
28
|
+
* re-run the real entrypoint against the real `process.env`/`process.exit`
|
|
29
|
+
* as an import-time side effect — in a test environment with no
|
|
30
|
+
* `WORKEL_API_KEY` set, that calls the real `process.exit`, killing the
|
|
31
|
+
* Jest worker. The guard changes nothing about how `node dist/index.js` (or
|
|
32
|
+
* the `workel-mcp` bin) behaves: `require.main === module` is true on that
|
|
33
|
+
* path, exactly as it always was.
|
|
34
|
+
*/
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.main = main;
|
|
37
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
38
|
+
const boot_1 = require("./boot");
|
|
39
|
+
const doctor_1 = require("./doctor");
|
|
40
|
+
const redact_1 = require("./api/redact");
|
|
41
|
+
async function main(argv, deps) {
|
|
42
|
+
if (argv[2] === 'doctor') {
|
|
43
|
+
const code = await (0, doctor_1.runDoctor)(deps);
|
|
44
|
+
deps.exit(code);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const result = await (0, boot_1.boot)(deps);
|
|
48
|
+
if (result === undefined)
|
|
49
|
+
return;
|
|
50
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
51
|
+
await result.server.connect(transport);
|
|
52
|
+
}
|
|
53
|
+
if (require.main === module) {
|
|
54
|
+
void main(process.argv, {
|
|
55
|
+
env: process.env,
|
|
56
|
+
fetch,
|
|
57
|
+
stdout: (chunk) => process.stdout.write(chunk),
|
|
58
|
+
stderr: (chunk) => process.stderr.write(chunk),
|
|
59
|
+
exit: (code) => process.exit(code),
|
|
60
|
+
// Supplies the exit policy installCrashHandlers deliberately leaves to
|
|
61
|
+
// its caller: an uncaught exception must end the process, not leave a
|
|
62
|
+
// half-dead server attached to a live stdio transport.
|
|
63
|
+
installCrashHandlers: (write) => (0, redact_1.installCrashHandlers)(write, (code) => process.exit(code)),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;AAOH,oBAaC;AAlBD,wEAAiF;AACjF,iCAA6C;AAC7C,qCAAqC;AACrC,yCAAoD;AAE7C,KAAK,UAAU,IAAI,CAAC,IAAc,EAAE,IAAc;IACvD,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,MAAM,IAAA,kBAAS,EAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,WAAI,EAAC,IAAI,CAAC,CAAC;IAEhC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO;IAEjC,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;QACtB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK;QACL,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC9C,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAClC,uEAAuE;QACvE,sEAAsE;QACtE,uDAAuD;QACvD,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,6BAAoB,EAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC3F,CAAC,CAAC;AACL,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token-bounding for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* These are defensive backstops on a single tool result — not the primary
|
|
5
|
+
* pagination mechanism. `next_cursor` (opaque, passed through by
|
|
6
|
+
* `src/api/client.ts` verbatim) is what a caller uses to page through a
|
|
7
|
+
* large list properly; `listEnvelope`'s `MAX_LIST_ITEMS` cap exists in case
|
|
8
|
+
* a single page turns out to be larger than that regardless, and
|
|
9
|
+
* `truncateText`'s `TEXT_CAP` exists so one verbose field can't blow a
|
|
10
|
+
* result on its own. Neither cap decides whether more data exists —
|
|
11
|
+
* `next_cursor` is passed through untouched either way.
|
|
12
|
+
*/
|
|
13
|
+
/** The default character cap `truncateText` applies when no override is given. */
|
|
14
|
+
export declare const TEXT_CAP = 8000;
|
|
15
|
+
/** Appended to a truncated string. The result can therefore run slightly past `cap` — that fixed cost is what makes truncation visible rather than silent. */
|
|
16
|
+
export declare const TRUNCATION_MARKER = "\n\u2026[truncated]";
|
|
17
|
+
/**
|
|
18
|
+
* Returns `text` unchanged when it's within `cap`. Otherwise returns the
|
|
19
|
+
* first `cap` characters followed by `TRUNCATION_MARKER`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function truncateText(text: string, cap?: number): string;
|
|
22
|
+
/** The most items a single `listEnvelope` result carries, regardless of how many were given. */
|
|
23
|
+
export declare const MAX_LIST_ITEMS = 50;
|
|
24
|
+
export interface ListEnvelope<T> {
|
|
25
|
+
items: T[];
|
|
26
|
+
next_cursor: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Caps `items` at `MAX_LIST_ITEMS` and passes `nextCursor` through as
|
|
30
|
+
* `next_cursor` (an omitted or `undefined` cursor becomes `null`, never the
|
|
31
|
+
* literal string `"undefined"`). This function does not decide whether more
|
|
32
|
+
* pages exist — it only bounds what a single response hands back.
|
|
33
|
+
*/
|
|
34
|
+
export declare function listEnvelope<T>(items: T[], nextCursor?: string | null): ListEnvelope<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Field names a LIST view must never carry the full value of — long free
|
|
37
|
+
* text that's only useful once a caller has drilled into a single record.
|
|
38
|
+
* Detail views keep these fields but run them through `truncateText`
|
|
39
|
+
* instead of dropping them; omission is list-only.
|
|
40
|
+
*/
|
|
41
|
+
export declare const LIST_OMITTED_FIELDS: readonly ["description", "content", "body", "notes"];
|
|
42
|
+
/**
|
|
43
|
+
* Shallow-copies `record` with `LIST_OMITTED_FIELDS` removed. Every other
|
|
44
|
+
* field — `id`, `title`, and anything else the caller included — passes
|
|
45
|
+
* through unchanged.
|
|
46
|
+
*/
|
|
47
|
+
export declare function omitLongText<T extends Record<string, unknown>>(record: T): T;
|
|
48
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kFAAkF;AAClF,eAAO,MAAM,QAAQ,OAAO,CAAC;AAE7B,8JAA8J;AAC9J,eAAO,MAAM,iBAAiB,wBAAmB,CAAC;AAElD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAiB,GAAG,MAAM,CAGzE;AAED,gGAAgG;AAChG,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,CAavF;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,sDAAuD,CAAC;AAExF;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAM5E"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Token-bounding for tool outputs.
|
|
4
|
+
*
|
|
5
|
+
* These are defensive backstops on a single tool result — not the primary
|
|
6
|
+
* pagination mechanism. `next_cursor` (opaque, passed through by
|
|
7
|
+
* `src/api/client.ts` verbatim) is what a caller uses to page through a
|
|
8
|
+
* large list properly; `listEnvelope`'s `MAX_LIST_ITEMS` cap exists in case
|
|
9
|
+
* a single page turns out to be larger than that regardless, and
|
|
10
|
+
* `truncateText`'s `TEXT_CAP` exists so one verbose field can't blow a
|
|
11
|
+
* result on its own. Neither cap decides whether more data exists —
|
|
12
|
+
* `next_cursor` is passed through untouched either way.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LIST_OMITTED_FIELDS = exports.MAX_LIST_ITEMS = exports.TRUNCATION_MARKER = exports.TEXT_CAP = void 0;
|
|
16
|
+
exports.truncateText = truncateText;
|
|
17
|
+
exports.listEnvelope = listEnvelope;
|
|
18
|
+
exports.omitLongText = omitLongText;
|
|
19
|
+
/** The default character cap `truncateText` applies when no override is given. */
|
|
20
|
+
exports.TEXT_CAP = 8000;
|
|
21
|
+
/** Appended to a truncated string. The result can therefore run slightly past `cap` — that fixed cost is what makes truncation visible rather than silent. */
|
|
22
|
+
exports.TRUNCATION_MARKER = '\n…[truncated]';
|
|
23
|
+
/**
|
|
24
|
+
* Returns `text` unchanged when it's within `cap`. Otherwise returns the
|
|
25
|
+
* first `cap` characters followed by `TRUNCATION_MARKER`.
|
|
26
|
+
*/
|
|
27
|
+
function truncateText(text, cap = exports.TEXT_CAP) {
|
|
28
|
+
if (text.length <= cap)
|
|
29
|
+
return text;
|
|
30
|
+
return text.slice(0, cap) + exports.TRUNCATION_MARKER;
|
|
31
|
+
}
|
|
32
|
+
/** The most items a single `listEnvelope` result carries, regardless of how many were given. */
|
|
33
|
+
exports.MAX_LIST_ITEMS = 50;
|
|
34
|
+
/**
|
|
35
|
+
* Caps `items` at `MAX_LIST_ITEMS` and passes `nextCursor` through as
|
|
36
|
+
* `next_cursor` (an omitted or `undefined` cursor becomes `null`, never the
|
|
37
|
+
* literal string `"undefined"`). This function does not decide whether more
|
|
38
|
+
* pages exist — it only bounds what a single response hands back.
|
|
39
|
+
*/
|
|
40
|
+
function listEnvelope(items, nextCursor) {
|
|
41
|
+
// Deliberately does NOT slice. Slicing here while forwarding the upstream
|
|
42
|
+
// cursor silently DROPPED rows: the API's cursor is derived from the last
|
|
43
|
+
// row of the page it actually returned, so any page larger than the cap
|
|
44
|
+
// lost the rows between the cap and the cursor — permanently, with no
|
|
45
|
+
// signal. The page is bounded at the request instead (`limitSchema` is
|
|
46
|
+
// capped at MAX_LIST_ITEMS), so a page can never exceed the cap; if a
|
|
47
|
+
// server ever returns more anyway, passing it through is strictly safer
|
|
48
|
+
// than dropping rows the cursor will also skip.
|
|
49
|
+
return {
|
|
50
|
+
items,
|
|
51
|
+
next_cursor: nextCursor ?? null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Field names a LIST view must never carry the full value of — long free
|
|
56
|
+
* text that's only useful once a caller has drilled into a single record.
|
|
57
|
+
* Detail views keep these fields but run them through `truncateText`
|
|
58
|
+
* instead of dropping them; omission is list-only.
|
|
59
|
+
*/
|
|
60
|
+
exports.LIST_OMITTED_FIELDS = ['description', 'content', 'body', 'notes'];
|
|
61
|
+
/**
|
|
62
|
+
* Shallow-copies `record` with `LIST_OMITTED_FIELDS` removed. Every other
|
|
63
|
+
* field — `id`, `title`, and anything else the caller included — passes
|
|
64
|
+
* through unchanged.
|
|
65
|
+
*/
|
|
66
|
+
function omitLongText(record) {
|
|
67
|
+
const copy = { ...record };
|
|
68
|
+
for (const field of exports.LIST_OMITTED_FIELDS) {
|
|
69
|
+
delete copy[field];
|
|
70
|
+
}
|
|
71
|
+
return copy;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAYH,oCAGC;AAgBD,oCAaC;AAeD,oCAMC;AA/DD,kFAAkF;AACrE,QAAA,QAAQ,GAAG,IAAI,CAAC;AAE7B,8JAA8J;AACjJ,QAAA,iBAAiB,GAAG,gBAAgB,CAAC;AAElD;;;GAGG;AACH,SAAgB,YAAY,CAAC,IAAY,EAAE,MAAc,gBAAQ;IAC/D,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,yBAAiB,CAAC;AAChD,CAAC;AAED,gGAAgG;AACnF,QAAA,cAAc,GAAG,EAAE,CAAC;AAOjC;;;;;GAKG;AACH,SAAgB,YAAY,CAAI,KAAU,EAAE,UAA0B;IACpE,0EAA0E;IAC1E,0EAA0E;IAC1E,wEAAwE;IACxE,sEAAsE;IACtE,uEAAuE;IACvE,sEAAsE;IACtE,wEAAwE;IACxE,gDAAgD;IAChD,OAAO;QACL,KAAK;QACL,WAAW,EAAE,UAAU,IAAI,IAAI;KAChC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACU,QAAA,mBAAmB,GAAG,CAAC,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAExF;;;;GAIG;AACH,SAAgB,YAAY,CAAoC,MAAS;IACvE,MAAM,IAAI,GAA4B,EAAE,GAAG,MAAM,EAAE,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,2BAAmB,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAS,CAAC;AACnB,CAAC"}
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stateless Streamable HTTP entry — the v2 remote transport
|
|
3
|
+
* (docs/MCP_SERVER_PLAN.md §"Phase 5 — v2 remote (bearer)"). This is
|
|
4
|
+
* Phase 5 as CODE ONLY: nothing here is deployed, wired into CI, or given a
|
|
5
|
+
* hostname. Its job is to prove `buildServer()` (`./server.ts`) is really
|
|
6
|
+
* transport-independent — this module never edits it, only imports it — and
|
|
7
|
+
* to make the remote-specific risks the stdio transport never had to face
|
|
8
|
+
* concrete and testable: a curl-style `wk_`-only bearer check, a bare
|
|
9
|
+
* `WWW-Authenticate: Bearer` challenge with none of the OAuth metadata that
|
|
10
|
+
* is known to make some MCP clients silently ignore a static header, Origin
|
|
11
|
+
* validation, and a front throttle keyed on a HASH of the bearer rather
|
|
12
|
+
* than the caller's IP — per-IP is worthless here, since claude.ai and the
|
|
13
|
+
* OpenAI Agents SDK both call out from shared provider egress ranges, so
|
|
14
|
+
* every real tenant would collide in one IP-keyed bucket while a hashed-key
|
|
15
|
+
* bucket keeps them apart without ever storing the raw key.
|
|
16
|
+
*
|
|
17
|
+
* Every request pipeline step below runs in a FIXED order and each step is
|
|
18
|
+
* an unconditional early return — that order IS the security property, not
|
|
19
|
+
* an implementation detail:
|
|
20
|
+
*
|
|
21
|
+
* 1. method — only POST is ever handled; everything else is 405.
|
|
22
|
+
* 2. Origin — a PRESENT, disallowed Origin is 403. An ABSENT Origin
|
|
23
|
+
* is allowed: server-to-server connectors (the only
|
|
24
|
+
* caller this endpoint is designed for) send none, and
|
|
25
|
+
* refusing them would break the one caller that matters.
|
|
26
|
+
* 3. auth — no `Authorization` header, or a bearer not shaped like
|
|
27
|
+
* `wk_...`, is 401 with a BARE `WWW-Authenticate: Bearer`
|
|
28
|
+
* challenge — no `realm`, no `resource_metadata`, no
|
|
29
|
+
* parameters at all — and, critically, NO upstream fetch
|
|
30
|
+
* happens for either failure. A `wk_`-shaped bearer that
|
|
31
|
+
* turns out to be wrong is not this module's problem to
|
|
32
|
+
* diagnose: it goes to dispatch and comes back as
|
|
33
|
+
* whatever the real Workel API says.
|
|
34
|
+
* 4. throttle — a fixed window per SHA-256(bearer), sized (see
|
|
35
|
+
* `REQUESTS_ALLOWED_PER_WINDOW` below) to match the
|
|
36
|
+
* Public API v1's own per-key write ceiling
|
|
37
|
+
* (`RouteServiceProvider.php`), so this front door is
|
|
38
|
+
* never the tighter one. Exceeding it is a 429
|
|
39
|
+
* response carrying `Retry-After`.
|
|
40
|
+
* 5. dispatch — a brand-new `WorkelApiClient` bound to THIS request's
|
|
41
|
+
* bearer, a brand-new `buildServer()` result, and a
|
|
42
|
+
* brand-new stateless transport, connected and handed
|
|
43
|
+
* the request. Nothing from one request — client,
|
|
44
|
+
* server, transport, or key — is ever reused by the
|
|
45
|
+
* next one; see `dispatch()` below.
|
|
46
|
+
*
|
|
47
|
+
* No per-request `/me` scope probe (a deliberate scope decision, not an
|
|
48
|
+
* oversight — see the docblock on `computeCaps()` below for why, and the
|
|
49
|
+
* final report's `decisions_outside_brief` for the tradeoff it accepts).
|
|
50
|
+
*
|
|
51
|
+
* Env reads: the ONLY function in this file that ever reads an environment
|
|
52
|
+
* variable is `startRemote()`, and the ONLY way it does so is through
|
|
53
|
+
* `config.ts`'s existing exported `loadConfig()` — see the docblock on
|
|
54
|
+
* `startRemote()` for the one real friction point that decision creates
|
|
55
|
+
* (`loadConfig` requires `WORKEL_API_KEY`, which this transport has no use
|
|
56
|
+
* for) and why it is accepted rather than worked around by touching
|
|
57
|
+
* `config.ts`, which is out of scope for this module.
|
|
58
|
+
*/
|
|
59
|
+
import * as http from 'node:http';
|
|
60
|
+
import { type FetchLike } from './api/client';
|
|
61
|
+
export interface RemoteRequest extends AsyncIterable<Buffer> {
|
|
62
|
+
method?: string;
|
|
63
|
+
headers: Record<string, string | string[] | undefined>;
|
|
64
|
+
}
|
|
65
|
+
export interface RemoteResponse {
|
|
66
|
+
writeHead(statusCode: number, headers?: Record<string, string>): void;
|
|
67
|
+
end(chunk?: string): void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* `message` is always a static string literal at every call site in this
|
|
71
|
+
* file — nothing dynamic (an Origin value, a throttle key, an upstream
|
|
72
|
+
* error) is ever string-interpolated into it. Anything dynamic rides in
|
|
73
|
+
* `meta`, and `log()` below runs `meta` through `redactDeep` before it ever
|
|
74
|
+
* reaches this interface's implementation — see `log()`'s docblock for why
|
|
75
|
+
* that is a real, load-bearing second line of defense and not just
|
|
76
|
+
* decoration.
|
|
77
|
+
*/
|
|
78
|
+
export interface RemoteLogger {
|
|
79
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
80
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
81
|
+
error(message: string, meta?: Record<string, unknown>): void;
|
|
82
|
+
}
|
|
83
|
+
export interface RemoteHandlerDeps {
|
|
84
|
+
fetch: FetchLike;
|
|
85
|
+
logger: RemoteLogger;
|
|
86
|
+
/** Defaults to `[]` when omitted — see the file docblock, step 2: an empty allowlist refuses every PRESENT Origin, but an absent Origin is still allowed regardless of this list's contents. */
|
|
87
|
+
allowedOrigins?: string[];
|
|
88
|
+
now: () => number;
|
|
89
|
+
/** The Public API v1 base URL every per-request `WorkelApiClient` is built against. */
|
|
90
|
+
baseUrl: string;
|
|
91
|
+
/**
|
|
92
|
+
* Gate (b) of D5 ("Read-only by default; writes are a double opt-in",
|
|
93
|
+
* docs/MCP_SERVER_PLAN.md), resolved ONCE by the caller (`startRemote`,
|
|
94
|
+
* from `config.ts`'s `loadConfig().enableWrites`) and passed in as a
|
|
95
|
+
* plain boolean — never re-read from the environment inside the request
|
|
96
|
+
* pipeline itself. `registeredWriteTools(writesEnabled)` (`./tools/registration.ts`)
|
|
97
|
+
* is the same gate (b) `boot.ts` applies for stdio; passing this value
|
|
98
|
+
* explicitly is what keeps this file from needing its own `process.env`
|
|
99
|
+
* read to apply it.
|
|
100
|
+
*/
|
|
101
|
+
writesEnabled: boolean;
|
|
102
|
+
}
|
|
103
|
+
export type RemoteRequestHandler = (req: RemoteRequest, res: RemoteResponse) => Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Sized to match the Public API v1's own per-key write ceiling
|
|
106
|
+
* (`public-api` in `RouteServiceProvider.php`) so this front door is
|
|
107
|
+
* never the tighter one for a legitimately busy key. Exported so
|
|
108
|
+
* `remote.test.ts` can assert against this single source of the number
|
|
109
|
+
* rather than restating it as a second, driftable literal.
|
|
110
|
+
*/
|
|
111
|
+
export declare const REQUESTS_ALLOWED_PER_WINDOW = 120;
|
|
112
|
+
/**
|
|
113
|
+
* The largest request body this server will buffer. JSON-RPC tool calls are
|
|
114
|
+
* kilobytes; this is generous. The cap is load-bearing: the only gate ahead
|
|
115
|
+
* of this read is a `wk_` PREFIX test, never an upstream key verification, so
|
|
116
|
+
* an attacker who has never held a valid key can reach it. Uncapped, a single
|
|
117
|
+
* request buffered 200 MiB off-heap (+915 MB RSS) with zero upstream calls.
|
|
118
|
+
*/
|
|
119
|
+
export declare const MAX_REQUEST_BODY_BYTES: number;
|
|
120
|
+
/** Thrown by `readRawBody` when a body exceeds `MAX_REQUEST_BODY_BYTES`; the handler turns it into a 413. */
|
|
121
|
+
export declare class RequestBodyTooLargeError extends Error {
|
|
122
|
+
constructor();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Builds the stateless request pipeline described in the file docblock.
|
|
126
|
+
* Returns a plain `async (req, res) => void` function with no top-level
|
|
127
|
+
* side effects of its own — constructing it opens no socket and reaches no
|
|
128
|
+
* network; only actually CALLING the returned function (once per real HTTP
|
|
129
|
+
* request, from `startRemote`'s `http.Server`, or directly from a test)
|
|
130
|
+
* does anything.
|
|
131
|
+
*/
|
|
132
|
+
export declare function createRemoteHandler(deps: RemoteHandlerDeps): RemoteRequestHandler;
|
|
133
|
+
export interface StartRemoteOptions {
|
|
134
|
+
env?: NodeJS.ProcessEnv;
|
|
135
|
+
fetch?: FetchLike;
|
|
136
|
+
logger?: RemoteLogger;
|
|
137
|
+
now?: () => number;
|
|
138
|
+
allowedOrigins?: string[];
|
|
139
|
+
port?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Binds `createRemoteHandler`'s pipeline to a real Node `http.Server`. This
|
|
143
|
+
* is the only place in the file that reads `process.env` — and even here,
|
|
144
|
+
* only through `config.ts`'s existing exported `loadConfig()`, never a new
|
|
145
|
+
* `env.SOMETHING` read of this module's own invention.
|
|
146
|
+
*
|
|
147
|
+
* That constraint has one real, honestly-stated cost: `loadConfig` requires
|
|
148
|
+
* `WORKEL_API_KEY` to be set (`config.ts`'s `resolveApiKey`), a requirement
|
|
149
|
+
* that makes sense for the stdio entry (`index.ts`), which serves exactly
|
|
150
|
+
* one configured key for its whole process lifetime, but does NOT describe
|
|
151
|
+
* this transport at all — the remote server's bearer arrives fresh on
|
|
152
|
+
* every request (`dispatch()` above) and `WORKEL_API_KEY`, if set, is never
|
|
153
|
+
* read by any request this process handles. Reusing `loadConfig` here is
|
|
154
|
+
* still the right call for `baseUrl`/`enableWrites` — this file must not
|
|
155
|
+
* re-derive `config.ts`'s own validation (an `https://` scheme check, a
|
|
156
|
+
* boolean-flag parse) a second, drifting time — but it means an operator
|
|
157
|
+
* deploying this entry must still set an (unused-per-request)
|
|
158
|
+
* `WORKEL_API_KEY` purely to satisfy that loader. `config.ts` is out of
|
|
159
|
+
* scope for this change; a follow-up that gives it a remote-shaped loader
|
|
160
|
+
* (or exports its currently-private `resolveBaseUrl`/`parseBooleanFlag`
|
|
161
|
+
* helpers directly) is the honest fix, not a workaround added here.
|
|
162
|
+
*/
|
|
163
|
+
export declare function startRemote(opts?: StartRemoteOptions): http.Server;
|
|
164
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAyB,KAAK,SAAS,EAAwB,MAAM,cAAc,CAAC;AAmB3F,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,MAAM,CAAC;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CACx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