@crewhaus/target-batch-worker 0.5.4 → 0.5.6

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -6
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -239,22 +239,39 @@ function renderMcpServers(ir) {
239
239
  if (entries.length === 0) {
240
240
  return { imports: [], bootBlock: "", cleanupBlock: "", hasAny: false };
241
241
  }
242
+ // #406 — servers the spec marked `required: false` degrade at boot instead
243
+ // of exiting the worker. The worker is long-lived and the handler re-reads
244
+ // `defaultCatalog.list()` PER JOB, so background retry is the real thing
245
+ // here: a peer that connects an hour in serves every job after that.
246
+ const requiredEntries = entries.filter(([, cfg]) => cfg.required !== false);
247
+ const optionalEntries = entries.filter(([, cfg]) => cfg.required === false);
242
248
  const imports = [
243
249
  `import { McpHost, resolveMcpServerConfig } from "@crewhaus/mcp-host";`,
244
- `import { registerMcpServer } from "@crewhaus/tool-mcp";`,
250
+ `import { ${[
251
+ ...(requiredEntries.length > 0 ? ["registerMcpServer"] : []),
252
+ ...(optionalEntries.length > 0 ? ["registerOptionalMcpServer"] : []),
253
+ ].join(", ")} } from "@crewhaus/tool-mcp";`,
245
254
  ];
246
- const addLines = entries
255
+ // Optional entries are NOT added here: their config resolution + addServer
256
+ // run inside registerOptionalMcpServer's never-throw boundary (an unset env
257
+ // var on an optional peer must degrade, not kill the worker).
258
+ const addLines = requiredEntries
247
259
  .map(([name, cfg]) => `mcpHost.addServer(${escapeJsonString(name)}, resolveMcpServerConfig(${JSON.stringify(cfg)}, { name: ${escapeJsonString(name)} }));`)
248
260
  .join("\n");
249
- const registerLines = entries
261
+ const registerLines = requiredEntries
250
262
  .map(([name]) => ` registerMcpServer(mcpHost, ${escapeJsonString(name)}, defaultCatalog, { onRegister: ({ fullName }) => process.stdout.write(\`[mcp] registered \${fullName}\\n\`) }),`)
251
263
  .join("\n");
264
+ const optionalLines = optionalEntries.map(([name, cfg]) => {
265
+ // The wire config only — `required` is an EMIT-time decision (which
266
+ // registration call), not something mcp-host's config knows.
267
+ const { required: _requiredFlag, ...wireCfg } = cfg;
268
+ return `void registerOptionalMcpServer(mcpHost, ${escapeJsonString(name)}, defaultCatalog, { config: () => resolveMcpServerConfig(${JSON.stringify(wireCfg)}, { name: ${escapeJsonString(name)} }), log: (line) => process.stdout.write(line), onRegister: ({ fullName }) => process.stdout.write(\`[mcp] registered \${fullName}\\n\`) }).firstAttempt;`;
269
+ });
252
270
  const bootBlock = [
253
271
  "const mcpHost = new McpHost();",
254
272
  addLines,
255
- "await Promise.all([",
256
- registerLines,
257
- "]);",
273
+ ...(requiredEntries.length > 0 ? ["await Promise.all([", registerLines, "]);"] : []),
274
+ ...optionalLines,
258
275
  ].join("\n");
259
276
  return {
260
277
  imports,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/target-batch-worker",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "type": "module",
5
5
  "description": "Codegen for the BATCH target — emits a queue-consumer daemon (Section 23 BATCH)",
6
6
  "main": "dist/index.js",
@@ -15,10 +15,10 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.5.4",
19
- "@crewhaus/gateway-protocol": "0.5.4",
20
- "@crewhaus/infra-utils": "0.5.4",
21
- "@crewhaus/ir": "0.5.4"
18
+ "@crewhaus/errors": "0.5.6",
19
+ "@crewhaus/gateway-protocol": "0.5.6",
20
+ "@crewhaus/infra-utils": "0.5.6",
21
+ "@crewhaus/ir": "0.5.6"
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "author": {