@gaunt-sloth/agent 2.0.0-alpha.3 → 2.0.0-alpha.30

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 (96) hide show
  1. package/README.md +73 -23
  2. package/dist/builtInToolsConfig.d.ts +17 -3
  3. package/dist/builtInToolsConfig.js +40 -41
  4. package/dist/builtInToolsConfig.js.map +1 -1
  5. package/dist/core/GthDeepAgent.d.ts +52 -32
  6. package/dist/core/GthDeepAgent.js +438 -198
  7. package/dist/core/GthDeepAgent.js.map +1 -1
  8. package/dist/core/debugCapture.d.ts +8 -49
  9. package/dist/core/debugCapture.js +1 -1
  10. package/dist/core/debugCapture.js.map +1 -1
  11. package/dist/core/deepAgentPermissions.d.ts +67 -2
  12. package/dist/core/deepAgentPermissions.js +151 -3
  13. package/dist/core/deepAgentPermissions.js.map +1 -1
  14. package/dist/core/gthAcpServer.js +11 -0
  15. package/dist/core/gthAcpServer.js.map +1 -1
  16. package/dist/core/gthDeepAgentFactory.d.ts +3 -0
  17. package/dist/core/gthDeepAgentFactory.js +9 -1
  18. package/dist/core/gthDeepAgentFactory.js.map +1 -1
  19. package/dist/core/resolveAgentFactory.d.ts +14 -0
  20. package/dist/core/resolveAgentFactory.js +18 -0
  21. package/dist/core/resolveAgentFactory.js.map +1 -0
  22. package/dist/core/subagentProfiles.d.ts +50 -0
  23. package/dist/core/subagentProfiles.js +76 -0
  24. package/dist/core/subagentProfiles.js.map +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/mcp/OAuthClientProviderImpl.js.map +1 -1
  29. package/dist/mcp/tlsTrust.d.ts +61 -0
  30. package/dist/mcp/tlsTrust.js +109 -0
  31. package/dist/mcp/tlsTrust.js.map +1 -0
  32. package/dist/middleware/binaryContentInjectionMiddleware.d.ts +8 -1
  33. package/dist/middleware/binaryContentInjectionMiddleware.js +11 -2
  34. package/dist/middleware/binaryContentInjectionMiddleware.js.map +1 -1
  35. package/dist/middleware/frontendImageInjectionMiddleware.d.ts +106 -0
  36. package/dist/middleware/frontendImageInjectionMiddleware.js +166 -0
  37. package/dist/middleware/frontendImageInjectionMiddleware.js.map +1 -0
  38. package/dist/middleware/registry.js +36 -1
  39. package/dist/middleware/registry.js.map +1 -1
  40. package/dist/middleware/types.d.ts +16 -2
  41. package/dist/modules/a2a/A2AClientWrapper.d.ts +56 -1
  42. package/dist/modules/a2a/A2AClientWrapper.js +131 -31
  43. package/dist/modules/a2a/A2AClientWrapper.js.map +1 -1
  44. package/dist/modules/acpModule.js +17 -1
  45. package/dist/modules/acpModule.js.map +1 -1
  46. package/dist/modules/apiAgUiModule.d.ts +87 -0
  47. package/dist/modules/apiAgUiModule.js +229 -28
  48. package/dist/modules/apiAgUiModule.js.map +1 -1
  49. package/dist/modules/interactiveSessionModule.js +501 -41
  50. package/dist/modules/interactiveSessionModule.js.map +1 -1
  51. package/dist/modules/slashCommands.d.ts +576 -0
  52. package/dist/modules/slashCommands.js +995 -0
  53. package/dist/modules/slashCommands.js.map +1 -0
  54. package/dist/resolvers.js +119 -9
  55. package/dist/resolvers.js.map +1 -1
  56. package/dist/tools/GthCustomToolkit.js +95 -11
  57. package/dist/tools/GthCustomToolkit.js.map +1 -1
  58. package/dist/tools/GthDevToolkit.d.ts +11 -3
  59. package/dist/tools/GthDevToolkit.js +120 -34
  60. package/dist/tools/GthDevToolkit.js.map +1 -1
  61. package/dist/tools/GthFileSystemToolkit.d.ts +63 -0
  62. package/dist/tools/GthFileSystemToolkit.js +506 -105
  63. package/dist/tools/GthFileSystemToolkit.js.map +1 -1
  64. package/dist/tools/McpResourceTool.d.ts +31 -0
  65. package/dist/tools/McpResourceTool.js +106 -0
  66. package/dist/tools/McpResourceTool.js.map +1 -0
  67. package/dist/tools/gthChecklistTool.d.ts +30 -0
  68. package/dist/tools/gthChecklistTool.js +81 -0
  69. package/dist/tools/gthChecklistTool.js.map +1 -0
  70. package/dist/tools/gthGrepTool.d.ts +54 -0
  71. package/dist/tools/gthGrepTool.js +482 -0
  72. package/dist/tools/gthGrepTool.js.map +1 -0
  73. package/dist/tools/shell/env.js +1 -1
  74. package/dist/tools/shell/env.js.map +1 -1
  75. package/dist/tools/shell/outputBuffer.js.map +1 -1
  76. package/dist/tools/shell/workDir.d.ts +11 -0
  77. package/dist/tools/shell/workDir.js +45 -0
  78. package/dist/tools/shell/workDir.js.map +1 -0
  79. package/dist/utils/mcpAuthError.d.ts +36 -0
  80. package/dist/utils/mcpAuthError.js +89 -0
  81. package/dist/utils/mcpAuthError.js.map +1 -0
  82. package/dist/utils/mcpUtils.js +16 -0
  83. package/dist/utils/mcpUtils.js.map +1 -1
  84. package/package.json +12 -11
  85. package/dist/tools/shell/allowlist.d.ts +0 -11
  86. package/dist/tools/shell/allowlist.js +0 -12
  87. package/dist/tools/shell/allowlist.js.map +0 -1
  88. package/dist/tools/shell/arity.d.ts +0 -11
  89. package/dist/tools/shell/arity.js +0 -12
  90. package/dist/tools/shell/arity.js.map +0 -1
  91. package/dist/tools/shell/hardline.d.ts +0 -15
  92. package/dist/tools/shell/hardline.js +0 -88
  93. package/dist/tools/shell/hardline.js.map +0 -1
  94. package/dist/tools/shell/normalize.d.ts +0 -10
  95. package/dist/tools/shell/normalize.js +0 -11
  96. package/dist/tools/shell/normalize.js.map +0 -1
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * GS2-33 — the load-bearing capability: run a subagent under a NAMED config profile. When the
4
+ * parent declares `subagents: [{ name, profile }]`, the CHILD resolves THAT profile through the
5
+ * GS2-1 config cascade (`initConfig({ identityProfile: profile })`), so it gets the profile's own
6
+ * model + tools + prompt — e.g. a cheap flash-lite profile for a recall/search subagent while the
7
+ * parent runs on a strong model.
8
+ *
9
+ * This module is the subagent-spawn config-resolution seam. {@link resolveSubagentProfileConfig}
10
+ * threads the profile name through the cascade; {@link buildProfileSubagents} turns each declared
11
+ * spec into a deepagents {@link SubAgent} whose `model`/`tools`/`systemPrompt` come from the child
12
+ * profile. The deep backend wires the result into `createDeepAgent({ subagents })` (see
13
+ * `GthDeepAgent.init`). Resolution mutates process globals (`setProjectDir`/`setConsoleLevel`/
14
+ * `setUseColour`) exactly as a normal run's `initConfig` does — the caller snapshots + restores
15
+ * them around the build so a child profile's console/colour cannot leak into the parent run.
16
+ */
17
+ import { initConfig } from '@gaunt-sloth/core/config.js';
18
+ import { buildSystemMessages, readModePrompt } from '@gaunt-sloth/core/utils/llmUtils.js';
19
+ import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
20
+ /**
21
+ * Resolve a named profile into a fully-merged child {@link GthConfig} by threading the profile name
22
+ * through the GS2-1 cascade as `identityProfile`. Deliberately resolves with ONLY the profile
23
+ * override — no parent `-c` / `--model` — so the child is exactly what that profile's config dir
24
+ * defines (a parent `--model` must not silently retarget the child's profile model). The profile's
25
+ * own `.gsloth/.gsloth-settings/<profile>/` config becomes the project-file layer; global config +
26
+ * `DEFAULT_CONFIG` still underlay.
27
+ *
28
+ * NOTE: an explicitly-named profile that has no config dir makes `initConfig` fail loudly (the
29
+ * GS2-62 guard), so a typo'd subagent profile surfaces as an error rather than silently reusing the
30
+ * parent/global model.
31
+ */
32
+ export async function resolveSubagentProfileConfig(profile) {
33
+ return initConfig({ identityProfile: profile });
34
+ }
35
+ /**
36
+ * Compose the child's system prompt the same way the parent does (backstory + guidelines +
37
+ * per-command mode prompt + system prompt via {@link buildSystemMessages}), so the subagent honours
38
+ * the profile's own prompt files. Returns `undefined` only when no prompt content composes.
39
+ */
40
+ function composeChildSystemPrompt(config, command) {
41
+ const systemMessages = buildSystemMessages(config, readModePrompt(command, config));
42
+ return typeof systemMessages[0]?.content === 'string' ? systemMessages[0].content : undefined;
43
+ }
44
+ /**
45
+ * Turn each {@link SubagentProfileSpec} into a deepagents {@link SubAgent} whose model + tools +
46
+ * prompt come from the named profile's resolved config. The returned specs are handed to
47
+ * `createDeepAgent({ subagents })`; the model — the whole point — is the child profile's `llm`,
48
+ * distinct from the parent's.
49
+ */
50
+ export async function buildProfileSubagents(specs, options) {
51
+ const subagents = [];
52
+ for (const spec of specs) {
53
+ debugLog(`Resolving subagent "${spec.name}" under profile "${spec.profile}"`);
54
+ const childConfig = await resolveSubagentProfileConfig(spec.profile);
55
+ // Resolve the child's tools from ITS profile config, filesystem disabled (deepagents provides
56
+ // fs for the subagent). An empty allowedTools allow-list disables every tool.
57
+ const allowedTools = childConfig.allowedTools;
58
+ const toolsDisabled = Array.isArray(allowedTools) && allowedTools.length === 0;
59
+ let tools = [];
60
+ if (!toolsDisabled && options.resolveTools) {
61
+ const resolved = await options.resolveTools({ ...childConfig, filesystem: 'none' }, options.command);
62
+ tools = resolved;
63
+ }
64
+ const systemPrompt = composeChildSystemPrompt(childConfig, options.command) ??
65
+ `You are the ${spec.name} subagent.`;
66
+ subagents.push({
67
+ name: spec.name,
68
+ description: spec.description ?? `Runs under the "${spec.profile}" config profile.`,
69
+ systemPrompt,
70
+ model: childConfig.llm,
71
+ tools,
72
+ });
73
+ }
74
+ return subagents;
75
+ }
76
+ //# sourceMappingURL=subagentProfiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subagentProfiles.js","sourceRoot":"","sources":["../../src/core/subagentProfiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,UAAU,EAA4C,MAAM,6BAA6B,CAAC;AAEnG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAC1F,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAIjE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,OAAe;IAChE,OAAO,UAAU,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,SAAS,wBAAwB,CAC/B,MAAiB,EACjB,OAA+B;IAE/B,M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I;YACf,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,mBAAmB,IAAI,CAAC,OAAO,mBAAmB;YACnF,YAAY;YACZ,KAAK,EAAE,WAAW,CAAC,GAAG;YACtB,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export { resolveMiddleware } from '#src/middleware/registry.js';
11
11
  export { GthDeepAgent, type GthDeepAgentParams } from '#src/core/GthDeepAgent.js';
12
12
  export * from '#src/core/deepAgentPermissions.js';
13
13
  export { gthDeepAgentFactory } from '#src/core/gthDeepAgentFactory.js';
14
+ export { resolveAgentFactory } from '#src/core/resolveAgentFactory.js';
package/dist/index.js CHANGED
@@ -13,4 +13,5 @@ export { resolveMiddleware } from '#src/middleware/registry.js';
13
13
  export { GthDeepAgent } from '#src/core/GthDeepAgent.js';
14
14
  export * from '#src/core/deepAgentPermissions.js';
15
15
  export { gthDeepAgentFactory } from '#src/core/gthDeepAgentFactory.js';
16
+ export { resolveAgentFactory } from '#src/core/resolveAgentFactory.js';
16
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,mDAAmD;AACnD,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,+EAA+E;AAC/E,OAAO,EAAE,YAAY,EAA2B,MAAM,2BAA2B,CAAC;AAClF,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,mDAAmD;AACnD,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,+EAA+E;AAC/E,OAAO,EAAE,YAAY,EAA2B,MAAM,2BAA2B,CAAC;AAClF,cAAc,mCAAmC,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"OAuthClientProviderImpl.js","sourceRoot":"","sources":["../../src/mcp/OAuthClientProviderImpl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AAMhE,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AAcnF;;GAEG;AACH,MAAM,OAAO,uBAAuB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S trust for outbound HTTPS, driven by the `tls` config block.
4
+ *
5
+ * Motivation: an `http`-transport MCP server behind a private/corporate CA (e.g. a dev monolith
6
+ * with a self-signed cert) makes Node's global `fetch` reject the connection with
7
+ * `TypeError: fetch failed` (`SELF_SIGNED_CERT_IN_CHAIN`). The only pre-existing workaround was to
8
+ * prepend `NODE_EXTRA_CA_CERTS=<ca.crt>` on every invocation — that env var is read ONCE at Node
9
+ * startup, so it can't be set from config after launch.
10
+ *
11
+ * Node's `fetch` runs on undici and ignores `https.globalAgent`, so the CA must be installed via an
12
+ * undici dispatcher. `@langchain/mcp-adapters` forwards only `serverName`/`headers`/`authProvider`
13
+ * to the SDK transport (it drops the SDK's `requestInit`/`fetch` hooks), so a per-server CA is not
14
+ * reachable through the adapter. The trust is therefore installed **process-globally** via
15
+ * `setGlobalDispatcher`. That is acceptable for adding a CA (additive trust weakens nothing) — but
16
+ * note the insecure latch below is global too, and so affects LLM provider calls, not only MCP.
17
+ */
18
+ import type { GthConfig } from '@gaunt-sloth/core/config.js';
19
+ type TlsConfig = GthConfig['tls'];
20
+ /** A cert path that could not be read, with the reason (surfaced by the installer). */
21
+ export interface TlsCertFailure {
22
+ path: string;
23
+ message: string;
24
+ }
25
+ /** The undici `connect` options computed from a `tls` config, plus what happened while reading. */
26
+ export interface BuiltDispatcher {
27
+ /** Node's default roots FIRST, then successfully-read user certs. `connect.ca` REPLACES the */
28
+ /** default store, so the roots must be included or every public-CA fetch breaks. */
29
+ ca: string[];
30
+ /** `false` disables verification entirely (process-global). Defaults to `true`. */
31
+ rejectUnauthorized: boolean;
32
+ /** How many configured certs were read successfully. */
33
+ loadedCount: number;
34
+ /** Configured certs that could not be read (fail-soft: skipped, not fatal). */
35
+ failures: TlsCertFailure[];
36
+ }
37
+ /**
38
+ * Compute the undici dispatcher options from a `tls` config. Pure aside from the injected
39
+ * `readCert` (so unit tests stub file reads): resolves nothing about the environment itself.
40
+ *
41
+ * Returns `null` only when NOTHING is configured — no `tls` block, or an empty `tls` with no cert
42
+ * entries and verification left at its secure default. When certs ARE configured it always returns
43
+ * the object (even if every read failed), so the caller can surface those `failures` rather than
44
+ * silently swallowing a bad cert path. Whether to actually install is the caller's call:
45
+ * `loadedCount > 0 || !rejectUnauthorized`.
46
+ *
47
+ * `readCert` receives each configured path verbatim and must return the PEM contents or throw.
48
+ */
49
+ export declare function buildDispatcherOptions(tls: TlsConfig, readCert: (path: string) => string, baseRoots?: readonly string[]): BuiltDispatcher | null;
50
+ /**
51
+ * Install the process-global undici dispatcher from `config.tls`, if any. Idempotent (installs at
52
+ * most once per process). Fail-soft: an unreadable cert is warned about and skipped, never fatal.
53
+ * Emits a loud security warning when verification is disabled.
54
+ *
55
+ * Wired into `getMcpClient` before the MCP client is created; because it is global it also covers
56
+ * LLM/tool fetches — which is desired for the CA case and is the danger to flag for the latch.
57
+ */
58
+ export declare function installMcpTlsTrust(config: GthConfig): void;
59
+ /** Test-only: reset the install-once guard between cases. */
60
+ export declare function resetMcpTlsTrustForTests(): void;
61
+ export {};
@@ -0,0 +1,109 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Process-global TLS trust for outbound HTTPS, driven by the `tls` config block.
4
+ *
5
+ * Motivation: an `http`-transport MCP server behind a private/corporate CA (e.g. a dev monolith
6
+ * with a self-signed cert) makes Node's global `fetch` reject the connection with
7
+ * `TypeError: fetch failed` (`SELF_SIGNED_CERT_IN_CHAIN`). The only pre-existing workaround was to
8
+ * prepend `NODE_EXTRA_CA_CERTS=<ca.crt>` on every invocation — that env var is read ONCE at Node
9
+ * startup, so it can't be set from config after launch.
10
+ *
11
+ * Node's `fetch` runs on undici and ignores `https.globalAgent`, so the CA must be installed via an
12
+ * undici dispatcher. `@langchain/mcp-adapters` forwards only `serverName`/`headers`/`authProvider`
13
+ * to the SDK transport (it drops the SDK's `requestInit`/`fetch` hooks), so a per-server CA is not
14
+ * reachable through the adapter. The trust is therefore installed **process-globally** via
15
+ * `setGlobalDispatcher`. That is acceptable for adding a CA (additive trust weakens nothing) — but
16
+ * note the insecure latch below is global too, and so affects LLM provider calls, not only MCP.
17
+ */
18
+ import { rootCertificates } from 'node:tls';
19
+ import { readFileSync } from 'node:fs';
20
+ import { homedir } from 'node:os';
21
+ import { resolve } from 'node:path';
22
+ import { Agent, setGlobalDispatcher } from 'undici';
23
+ import { getProjectDir } from '@gaunt-sloth/core/utils/systemUtils.js';
24
+ import { displayWarning } from '@gaunt-sloth/core/utils/consoleUtils.js';
25
+ import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
26
+ /**
27
+ * Compute the undici dispatcher options from a `tls` config. Pure aside from the injected
28
+ * `readCert` (so unit tests stub file reads): resolves nothing about the environment itself.
29
+ *
30
+ * Returns `null` only when NOTHING is configured — no `tls` block, or an empty `tls` with no cert
31
+ * entries and verification left at its secure default. When certs ARE configured it always returns
32
+ * the object (even if every read failed), so the caller can surface those `failures` rather than
33
+ * silently swallowing a bad cert path. Whether to actually install is the caller's call:
34
+ * `loadedCount > 0 || !rejectUnauthorized`.
35
+ *
36
+ * `readCert` receives each configured path verbatim and must return the PEM contents or throw.
37
+ */
38
+ export function buildDispatcherOptions(tls, readCert, baseRoots = rootCertificates) {
39
+ const rejectUnauthorized = tls?.rejectUnauthorized ?? true;
40
+ const certPaths = tls?.extraCaCerts ?? [];
41
+ // Nothing configured at all: no cert entries and verification not being disabled.
42
+ if (certPaths.length === 0 && rejectUnauthorized)
43
+ return null;
44
+ const userCerts = [];
45
+ const failures = [];
46
+ for (const path of certPaths) {
47
+ try {
48
+ userCerts.push(readCert(path));
49
+ }
50
+ catch (error) {
51
+ failures.push({ path, message: error instanceof Error ? error.message : String(error) });
52
+ }
53
+ }
54
+ return {
55
+ // ca REPLACES the trust store — keep the default roots or public-CA fetches (incl. the LLM
56
+ // provider) silently break.
57
+ ca: [...baseRoots, ...userCerts],
58
+ rejectUnauthorized,
59
+ loadedCount: userCerts.length,
60
+ failures,
61
+ };
62
+ }
63
+ // Install-once guard: the trust is process-global and set-once, so re-running resolveTools (re-init)
64
+ // must not re-replace the dispatcher nor re-emit the security warning every time.
65
+ let installed = false;
66
+ /**
67
+ * Install the process-global undici dispatcher from `config.tls`, if any. Idempotent (installs at
68
+ * most once per process). Fail-soft: an unreadable cert is warned about and skipped, never fatal.
69
+ * Emits a loud security warning when verification is disabled.
70
+ *
71
+ * Wired into `getMcpClient` before the MCP client is created; because it is global it also covers
72
+ * LLM/tool fetches — which is desired for the CA case and is the danger to flag for the latch.
73
+ */
74
+ export function installMcpTlsTrust(config) {
75
+ if (installed) {
76
+ debugLog('MCP TLS trust already installed this process; skipping.');
77
+ return;
78
+ }
79
+ const built = buildDispatcherOptions(config.tls, resolveAndReadCert);
80
+ if (!built)
81
+ return;
82
+ // Surface unreadable certs even if we end up installing nothing — a bad cert path must never be
83
+ // swallowed silently. Warn BEFORE the "nothing actionable" bail below.
84
+ for (const failure of built.failures) {
85
+ displayWarning(`TLS: could not read CA certificate '${failure.path}' (${failure.message}); skipping it.`);
86
+ }
87
+ // Nothing left to install: every configured cert failed to read and verification is still on.
88
+ // (Failures were already surfaced above.) Leave Node's default dispatcher untouched.
89
+ if (built.loadedCount === 0 && built.rejectUnauthorized)
90
+ return;
91
+ installed = true;
92
+ if (!built.rejectUnauthorized) {
93
+ displayWarning('TLS: certificate verification is DISABLED (tls.rejectUnauthorized: false). This is INSECURE ' +
94
+ 'and applies to ALL outbound HTTPS this process makes — MCP servers AND LLM provider calls. ' +
95
+ 'Use only against trusted dev endpoints; prefer tls.extraCaCerts to trust a specific CA instead.');
96
+ }
97
+ setGlobalDispatcher(new Agent({ connect: { ca: built.ca, rejectUnauthorized: built.rejectUnauthorized } }));
98
+ debugLog(`MCP TLS trust installed: ${built.loadedCount} extra CA cert(s), rejectUnauthorized=${built.rejectUnauthorized}.`);
99
+ }
100
+ /** Resolve a configured cert path (`~` / relative-to-project / absolute) and read it as UTF-8. */
101
+ function resolveAndReadCert(path) {
102
+ const expanded = path === '~' || path.startsWith('~/') ? homedir() + path.slice(1) : path;
103
+ return readFileSync(resolve(getProjectDir(), expanded), 'utf8');
104
+ }
105
+ /** Test-only: reset the install-once guard between cases. */
106
+ export function resetMcpTlsTrustForTests() {
107
+ installed = false;
108
+ }
109
+ //# sourceMappingURL=tlsTrust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tlsTrust.js","sourceRoot":"","sources":["../../src/mcp/tlsTrust.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAuBjE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CACpC,GAAc,EACd,QAAkC,EAClC,SAAS,GAAsB,gBAAgB;IAE/C,MAAM,kBAAkB,GAAG,GAAG,EAAE,kBAAkB,IAAI,IAAI,CAAC;IAC3D,MAAM,SAAS,GAAG,GAAG,EAAE,YAAY,IAAI,EAAE,CAAC;IAE1C,kFAAkF;IAClF,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAE9D,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,QAAQ,GAAqB,EAAE,CAAC;IAEtC,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAA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;IACJ,CAAC;IAED,mBAAmB,CACjB,IAAI,KAAK,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,EAAE,CAAC,CACvF,CAAC;IACF,QAAQ,CACN,4BAA4B,KAAK,CAAC,WAAW,yCAAyC,KAAK,CAAC,kBAAkB,GAAG,CAClH,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,SAAS,kBAAkB,CAAC,IAAY;IACtC,MAAM,QAAQ,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1F,OAAO,YAAY,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,wBAAwB;IACtC,SAAS,GAAG,KAAK,CAAC;AACpB,CAAC"}
@@ -18,5 +18,12 @@ import { type AgentMiddleware } from 'langchain';
18
18
  import type { GthConfig } from '@gaunt-sloth/core/config.js';
19
19
  export interface BinaryContentInjectionMiddlewareSettings {
20
20
  name?: 'binary-content-injection';
21
+ /**
22
+ * The gth provider string selecting the per-provider image-block shape (see
23
+ * {@link imageBlockFor}). Derived by the registry factory via `resolveVisionProvider(gthConfig)`;
24
+ * may be `''`/absent, in which case the standard base64 image block is emitted. Only affects the
25
+ * `image` format — file/video/audio blocks are provider-agnostic.
26
+ */
27
+ provider?: string;
21
28
  }
22
- export declare function createBinaryContentInjectionMiddleware(_settings: BinaryContentInjectionMiddlewareSettings, _gthConfig: GthConfig): Promise<AgentMiddleware>;
29
+ export declare function createBinaryContentInjectionMiddleware(settings: BinaryContentInjectionMiddlewareSettings, _gthConfig: GthConfig): Promise<AgentMiddleware>;
@@ -18,6 +18,7 @@ import { createMiddleware } from 'langchain';
18
18
  import path from 'node:path';
19
19
  import { debugLog } from '@gaunt-sloth/core/utils/debugUtils.js';
20
20
  import { ToolMessage, HumanMessage } from '@langchain/core/messages';
21
+ import { imageBlockFor } from '#src/middleware/frontendImageInjectionMiddleware.js';
21
22
  /**
22
23
  * Parse the special binary format string returned by gth_read_binary tool.
23
24
  * Format: gth_read_binary;type:${type};path:${encodedPath};data:${media_type};base64,${data}
@@ -73,8 +74,10 @@ function getFormatLabel(formatType) {
73
74
  };
74
75
  return labels[formatType] || 'file';
75
76
  }
76
- export function createBinaryContentInjectionMiddleware(_settings, _gthConfig) {
77
+ export function createBinaryContentInjectionMiddleware(settings, _gthConfig) {
77
78
  debugLog('Creating binary content injection middleware');
79
+ // The provider selecting the image-block shape; '' falls to the standard base64 block.
80
+ const provider = settings.provider ?? '';
78
81
  return Promise.resolve(createMiddleware({
79
82
  name: 'binary-content-injection',
80
83
  // Before next model call, detect and inject HumanMessage with binary content
@@ -100,7 +103,13 @@ export function createBinaryContentInjectionMiddleware(_settings, _gthConfig) {
100
103
  const newMessages = [...messages];
101
104
  for (const { binaryData } of binaryMessages) {
102
105
  const formatLabel = getFormatLabel(binaryData.formatType);
103
- const contentBlock = createContentBlock(binaryData);
106
+ // Images go through the per-provider builder so OpenAI reasoning models (Responses API,
107
+ // GS2-74) get a valid `image_url` block instead of the standard `source_type` data block,
108
+ // which @langchain/openai mis-serialises to an invalid Responses image part (GS2-75).
109
+ // file/video/audio keep the standard block (they already convert correctly).
110
+ const contentBlock = binaryData.formatType === 'image'
111
+ ? imageBlockFor(provider, binaryData.media_type, binaryData.data)
112
+ : createContentBlock(binaryData);
104
113
  const humanMessage = new HumanMessage({
105
114
  content: [
106
115
  {
@@ -1 +1 @@
1
- {"version":3,"file":"binaryContentInjectionMiddleware.js","sourceRoot":"","sources":["../../src/middleware/binaryContentInjectionMiddleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;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IACE,GAAG,YAAY,WAAW;oBAC1B,GAAG,CAAC,IAAI,KAAK,iBAAiB;oBAC9B,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAC/B,CAAC;oBACD,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;oBACtD,IAAI,aAAa,EAAE,CAAC;wBAClB,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC;oBACnE,CAAC;gBACH,CAAC;YACH,CAAC;YAED,qDAAqD;YACrD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9B,QAAQ,CAAC,aAAa,cAAc,CAAC,MAAM,sCAAsC,CAAC,CAAC;gBAEnF,MAAM,WAAW,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC;gBAElC,KAAK,MAAM,EAAE,UAAU,EAAE,IAAI,cAAc,EAAE,CAAC;oBAC5C,MAAM,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;oBAC1D,MAAM,YAAY,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;oBAEpD,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC;wBACpC,OAAO,EAAE;4BACP;gCACE,IAAI,EAAE,MAAM;gCACZ,IAAI,EAAE,eAAe,WAAW,yBAAyB;6BAC1D;4BACD,YAAY;yBACK;qBACpB,CAAC,CAAC;oBAEH,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACjC,CAAC;gBAED,8CAA8C;gBAC9C,OAAO;oBACL,QAAQ,EAAE,WAAW;iBACtB,CAAC;YACJ,CAAC;YAED,kCAAkC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"binaryContentInjectionMiddleware.js","sourceRoot":"","sources":["../../src/middleware/binaryContentInjectionMiddleware.ts"],"names":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WAAW,yBAAyB;6BAC1D;4BACD,YAAY;yBACK;qBACpB,CAAC,CAAC;oBAEH,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACjC,CAAC;gBAED,8CAA8C;gBAC9C,OAAO;oBACL,QAAQ,EAAE,WAAW;iBACtB,CAAC;YACJ,CAAC;YAED,kCAAkC;YAClC,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Opt-in middleware that turns a frontend "capture image" tool result into a vision message the
4
+ * model can actually see.
5
+ *
6
+ * A browser/frontend tool such as CopilotKit's `capture_image` fulfils client-side and posts its
7
+ * result back to gth's AG-UI server as a trailing `tool`-role message whose content is a JSON
8
+ * string `{"mimeType":"image/...","data":"<base64>"}`. gth hands that to the model as a plain-string
9
+ * ToolMessage — no vision block — so the model literally cannot see the photo. This middleware
10
+ * detects that ToolMessage in `beforeModel`, parses the envelope, and injects a `HumanMessage`
11
+ * carrying a provider-appropriate vision block before the next model call.
12
+ *
13
+ * Strictly opt-in: it fires ONLY when referenced by name in `config.middleware`
14
+ * (`"middleware": ["frontend-image-injection"]`), never auto-injected. Promoted from
15
+ * pukeko-robot-controller's proven middleware (RC-21), minus the robot-specific motion-tool coupling.
16
+ */
17
+ import { type AgentMiddleware } from 'langchain';
18
+ /** Default frontend capture tool name. Overridable via the `toolName` middleware setting. */
19
+ export declare const DEFAULT_CAPTURE_TOOL_NAME = "capture_image";
20
+ export interface FrontendImageInjectionOptions {
21
+ /**
22
+ * Provider selecting the vision-block shape. Derived by the registry factory from
23
+ * `gthConfig.modelProviderType` (the raw `llm.type`), falling back to `llm._llmType()`. One of
24
+ * gth's provider strings (`anthropic`, `openai`, `openrouter`, `deepseek`, `xai`, `groq`,
25
+ * `ollama`, `google-genai`, `vertexai`, `huggingface`, …); unknown values fall to the standard
26
+ * base64 block.
27
+ */
28
+ provider: string;
29
+ /**
30
+ * Tool name whose `{mimeType,data}` result is converted into a vision message. Defaults to
31
+ * {@link DEFAULT_CAPTURE_TOOL_NAME} (`capture_image`).
32
+ */
33
+ toolName?: string;
34
+ }
35
+ /**
36
+ * A vision content block the target provider's `@langchain` converter actually decodes. Verified
37
+ * against the installed converters (RC-21):
38
+ * - **ollama** → `{ type:'image_url', image_url:'<data-URL string>' }`. ChatOllama's
39
+ * `convertToOllamaMessages` only handles `image_url` blocks (extractBase64FromDataUrl); the
40
+ * LangChain standard `source_type` block throws "Unsupported content type: image".
41
+ * - **OpenAI-compatible** (`openai`, `openrouter`, `deepseek`, `xai`, `groq` — all extend
42
+ * `ChatOpenAI` / report `_llmType()==='openai'`) → `{ type:'image_url', image_url:{ url:'<data-URL>' } }`.
43
+ * This native OpenAI shape is correct on BOTH the Completions API AND the Responses API (GS2-74
44
+ * flips reasoning-capable openai models to Responses). A raw `source_type` standard block
45
+ * serialises to an *invalid* image part on the Responses path, so we emit the provider-native
46
+ * shape rather than lean on `@langchain/core`'s (deprecated, internal) auto-conversion.
47
+ * - **anthropic** → the provider-native block `{ type:'image', source:{ type:'base64',
48
+ * media_type, data } }`. The LangChain standard block is NOT usable here (RC-32): in
49
+ * `@langchain/anthropic`'s `_formatContentBlocks`, the `isDataContentBlock` branch yields its
50
+ * conversion and then FALLS THROUGH — no `continue` — into the chain below, where
51
+ * `type === 'image'` matches the very same block and yields a SECOND one whose `media_type` is
52
+ * read from camelCase `mimeType` (a key the snake_case standard block never has) and so
53
+ * defaults to the literal `image/jpeg`. Every frame is therefore sent twice, and a non-JPEG
54
+ * capture 400s outright on the mislabelled copy. The native block is recognised earlier by
55
+ * `_isAnthropicImageBlockParam` and passed through untouched, exactly once.
56
+ * - **google-genai / vertexai** (and any unknown/default) → the LangChain standard base64 data
57
+ * content block `{ type:'image', source_type:'base64', mime_type, data }`, which those native
58
+ * converters decode directly and which is the most broadly decodable fallback.
59
+ *
60
+ * The through-line: emit what the target provider's converter consumes natively rather than lean on
61
+ * a generic auto-conversion — the same lesson as GS2-75 on the OpenAI Responses path.
62
+ *
63
+ * Pure and exported so each provider branch can be unit-tested directly.
64
+ */
65
+ export declare function imageBlockFor(provider: string, mimeType: string, data: string): {
66
+ type: 'image_url';
67
+ image_url: string;
68
+ source?: undefined;
69
+ source_type?: undefined;
70
+ mime_type?: undefined;
71
+ data?: undefined;
72
+ } | {
73
+ type: 'image_url';
74
+ image_url: {
75
+ url: string;
76
+ };
77
+ source?: undefined;
78
+ source_type?: undefined;
79
+ mime_type?: undefined;
80
+ data?: undefined;
81
+ } | {
82
+ image_url?: undefined;
83
+ type: 'image';
84
+ source: {
85
+ type: 'base64';
86
+ media_type: string;
87
+ data: string;
88
+ };
89
+ source_type?: undefined;
90
+ mime_type?: undefined;
91
+ data?: undefined;
92
+ } | {
93
+ image_url?: undefined;
94
+ source?: undefined;
95
+ type: 'image';
96
+ source_type: 'base64';
97
+ mime_type: string;
98
+ data: string;
99
+ };
100
+ /**
101
+ * Create the frontend-image-injection middleware.
102
+ *
103
+ * @param opts.provider - provider string selecting the vision-block shape (see {@link imageBlockFor}).
104
+ * @param opts.toolName - capture tool name (default {@link DEFAULT_CAPTURE_TOOL_NAME}).
105
+ */
106
+ export declare function createFrontendImageInjectionMiddleware(opts: FrontendImageInjectionOptions): AgentMiddleware;