@juspay/neurolink 13.8.17 → 13.8.19

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 (214) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/README.md +1 -1
  3. package/dist/action/actionExecutor.d.ts +33 -3
  4. package/dist/action/actionExecutor.js +71 -15
  5. package/dist/action/actionInputs.js +4 -1
  6. package/dist/action/cliVersion.d.ts +25 -0
  7. package/dist/action/cliVersion.js +26 -0
  8. package/dist/action/index.d.ts +2 -1
  9. package/dist/action/index.js +2 -1
  10. package/dist/adapters/video/directorPipeline.js +46 -36
  11. package/dist/adapters/video/ffmpegAdapter.d.ts +17 -0
  12. package/dist/adapters/video/ffmpegAdapter.js +32 -5
  13. package/dist/adapters/video/frameExtractor.js +1 -1
  14. package/dist/adapters/video/videoMerger.js +5 -2
  15. package/dist/agent/arithmeticEvaluator.d.ts +32 -0
  16. package/dist/agent/arithmeticEvaluator.js +349 -0
  17. package/dist/agent/directTools.d.ts +6 -18
  18. package/dist/agent/directTools.js +17 -56
  19. package/dist/artifacts/artifactStore.d.ts +22 -1
  20. package/dist/artifacts/artifactStore.js +66 -6
  21. package/dist/auth/anthropicOAuth.d.ts +26 -1
  22. package/dist/auth/anthropicOAuth.js +81 -5
  23. package/dist/auth/secureFiles.d.ts +37 -0
  24. package/dist/auth/secureFiles.js +95 -0
  25. package/dist/auth/tokenStore.d.ts +43 -6
  26. package/dist/auth/tokenStore.js +260 -79
  27. package/dist/avatar/providers/DIDAvatar.js +49 -45
  28. package/dist/avatar/providers/ReplicateAvatar.js +33 -40
  29. package/dist/browser/neurolink.min.js +485 -558
  30. package/dist/cli/commands/auth.js +112 -70
  31. package/dist/cli/commands/proxy.d.ts +4 -0
  32. package/dist/cli/commands/proxy.js +128 -13
  33. package/dist/cli/commands/serve.d.ts +10 -1
  34. package/dist/cli/commands/serve.js +98 -17
  35. package/dist/cli/commands/server.js +17 -5
  36. package/dist/cli/index.js +146 -5
  37. package/dist/cli/loop/optionsSchema.d.ts +1 -1
  38. package/dist/cli/utils/envManager.js +17 -3
  39. package/dist/cli/utils/serverUtils.d.ts +39 -3
  40. package/dist/cli/utils/serverUtils.js +63 -6
  41. package/dist/core/baseProvider.js +7 -1
  42. package/dist/core/modules/MessageBuilder.js +5 -0
  43. package/dist/core/modules/ToolsManager.d.ts +46 -1
  44. package/dist/core/modules/ToolsManager.js +190 -43
  45. package/dist/files/fileReferenceRegistry.d.ts +2 -23
  46. package/dist/files/fileReferenceRegistry.js +55 -5
  47. package/dist/hitl/hitlManager.js +1 -0
  48. package/dist/index.d.ts +2 -1
  49. package/dist/index.js +6 -1
  50. package/dist/mcp/auth/tokenStorage.d.ts +7 -0
  51. package/dist/mcp/auth/tokenStorage.js +23 -4
  52. package/dist/mcp/externalServerManager.d.ts +13 -3
  53. package/dist/mcp/externalServerManager.js +154 -136
  54. package/dist/mcp/index.d.ts +2 -0
  55. package/dist/mcp/index.js +3 -0
  56. package/dist/mcp/mcpClientFactory.d.ts +14 -0
  57. package/dist/mcp/mcpClientFactory.js +70 -7
  58. package/dist/mcp/projectConfigTrust.d.ts +72 -0
  59. package/dist/mcp/projectConfigTrust.js +237 -0
  60. package/dist/mcp/transportUrlPolicy.d.ts +39 -0
  61. package/dist/mcp/transportUrlPolicy.js +172 -0
  62. package/dist/music/providers/BeatovenMusic.js +35 -46
  63. package/dist/music/providers/ReplicateMusic.js +33 -40
  64. package/dist/neurolink.d.ts +16 -1
  65. package/dist/neurolink.js +64 -11
  66. package/dist/processors/archive/ArchiveProcessor.js +15 -1
  67. package/dist/processors/archive/zipEntryIndex.d.ts +22 -0
  68. package/dist/processors/archive/zipEntryIndex.js +33 -0
  69. package/dist/processors/base/BaseFileProcessor.d.ts +9 -21
  70. package/dist/processors/base/BaseFileProcessor.js +40 -111
  71. package/dist/processors/data/YamlProcessor.d.ts +13 -1
  72. package/dist/processors/data/YamlProcessor.js +93 -2
  73. package/dist/processors/document/OpenDocumentProcessor.js +7 -2
  74. package/dist/processors/document/PptxProcessor.js +12 -7
  75. package/dist/processors/media/VideoProcessor.js +93 -15
  76. package/dist/providers/openaiChatCompletionsClient.js +12 -3
  77. package/dist/proxy/accountLedger.js +6 -8
  78. package/dist/proxy/geminiFormat.d.ts +3 -11
  79. package/dist/proxy/geminiFormat.js +11 -2
  80. package/dist/proxy/inboundAuth.d.ts +89 -0
  81. package/dist/proxy/inboundAuth.js +219 -0
  82. package/dist/proxy/openaiFormat.d.ts +3 -9
  83. package/dist/proxy/openaiFormat.js +21 -15
  84. package/dist/proxy/proxyTranslationEngine.d.ts +2 -6
  85. package/dist/proxy/proxyTranslationEngine.js +25 -14
  86. package/dist/proxy/routingPolicy.d.ts +3 -1
  87. package/dist/proxy/routingPolicy.js +7 -8
  88. package/dist/proxy/tokenRefresh.d.ts +6 -0
  89. package/dist/proxy/tokenRefresh.js +13 -1
  90. package/dist/proxy/updateState.js +4 -4
  91. package/dist/rag/document/loaders.d.ts +0 -6
  92. package/dist/rag/document/loaders.js +16 -10
  93. package/dist/rag/ragIntegration.d.ts +2 -2
  94. package/dist/rag/ragIntegration.js +35 -10
  95. package/dist/rag/retrieval/vectorQueryTool.d.ts +7 -0
  96. package/dist/rag/retrieval/vectorQueryTool.js +54 -17
  97. package/dist/server/abstract/baseServerAdapter.d.ts +43 -0
  98. package/dist/server/abstract/baseServerAdapter.js +119 -6
  99. package/dist/server/adapters/expressAdapter.d.ts +3 -0
  100. package/dist/server/adapters/expressAdapter.js +78 -6
  101. package/dist/server/adapters/fastifyAdapter.d.ts +3 -0
  102. package/dist/server/adapters/fastifyAdapter.js +165 -70
  103. package/dist/server/adapters/honoAdapter.d.ts +9 -1
  104. package/dist/server/adapters/honoAdapter.js +99 -21
  105. package/dist/server/adapters/koaAdapter.d.ts +1 -0
  106. package/dist/server/adapters/koaAdapter.js +153 -74
  107. package/dist/server/index.d.ts +2 -0
  108. package/dist/server/index.js +4 -0
  109. package/dist/server/middleware/auth.js +6 -2
  110. package/dist/server/middleware/cache.js +6 -1
  111. package/dist/server/middleware/rateLimit.js +29 -4
  112. package/dist/server/routes/agentRoutes.js +24 -11
  113. package/dist/server/routes/claudeProxyRoutes.d.ts +1 -0
  114. package/dist/server/routes/claudeProxyRoutes.js +273 -84
  115. package/dist/server/routes/codexProxyRoutes.d.ts +2 -2
  116. package/dist/server/routes/codexProxyRoutes.js +125 -40
  117. package/dist/server/routes/index.d.ts +4 -0
  118. package/dist/server/routes/index.js +35 -4
  119. package/dist/server/routes/mcpRoutes.d.ts +6 -2
  120. package/dist/server/routes/mcpRoutes.js +21 -7
  121. package/dist/server/routes/memoryRoutes.js +7 -6
  122. package/dist/server/routes/toolRoutes.d.ts +12 -2
  123. package/dist/server/routes/toolRoutes.js +33 -3
  124. package/dist/server/routes/transcribeRoutes.js +60 -13
  125. package/dist/server/utils/clientAddress.d.ts +23 -0
  126. package/dist/server/utils/clientAddress.js +65 -0
  127. package/dist/server/utils/clientError.d.ts +35 -0
  128. package/dist/server/utils/clientError.js +129 -0
  129. package/dist/server/utils/pathMatch.d.ts +21 -0
  130. package/dist/server/utils/pathMatch.js +41 -0
  131. package/dist/server/utils/validation.d.ts +9 -0
  132. package/dist/server/utils/validation.js +9 -0
  133. package/dist/server/websocket/WebSocketHandler.js +22 -3
  134. package/dist/server/websocket/frameQueue.d.ts +19 -0
  135. package/dist/server/websocket/frameQueue.js +41 -3
  136. package/dist/server/websocket/transcribeWebSocket.d.ts +8 -1
  137. package/dist/server/websocket/transcribeWebSocket.js +223 -34
  138. package/dist/skills/skillStores.js +5 -0
  139. package/dist/tasks/store/fileTaskStore.d.ts +2 -0
  140. package/dist/tasks/store/fileTaskStore.js +11 -4
  141. package/dist/types/attachments.d.ts +117 -0
  142. package/dist/types/attachments.js +15 -0
  143. package/dist/types/auth.d.ts +6 -0
  144. package/dist/types/cli.d.ts +4 -0
  145. package/dist/types/config.d.ts +56 -0
  146. package/dist/types/file.d.ts +8 -0
  147. package/dist/types/hitl.d.ts +8 -0
  148. package/dist/types/index.d.ts +1 -0
  149. package/dist/types/index.js +1 -0
  150. package/dist/types/mcp.d.ts +98 -0
  151. package/dist/types/multimodal.js +0 -41
  152. package/dist/types/openaiCompatible.d.ts +1 -1
  153. package/dist/types/processor.d.ts +14 -1
  154. package/dist/types/proxy.d.ts +71 -16
  155. package/dist/types/proxyClient.d.ts +2 -0
  156. package/dist/types/rag.d.ts +9 -0
  157. package/dist/types/safeFetch.d.ts +40 -0
  158. package/dist/types/server.d.ts +206 -10
  159. package/dist/types/tools.d.ts +57 -0
  160. package/dist/types/transcribe.d.ts +6 -0
  161. package/dist/utils/attachmentPolicy.d.ts +89 -0
  162. package/dist/utils/attachmentPolicy.js +327 -0
  163. package/dist/utils/dotenvBootstrap.d.ts +48 -19
  164. package/dist/utils/dotenvBootstrap.js +172 -31
  165. package/dist/utils/fileDetector.js +115 -65
  166. package/dist/utils/json/coerce.js +11 -1
  167. package/dist/utils/logSanitize.d.ts +5 -0
  168. package/dist/utils/logSanitize.js +8 -0
  169. package/dist/utils/logger.js +73 -1
  170. package/dist/utils/messageBuilder.d.ts +2 -2
  171. package/dist/utils/messageBuilder.js +118 -105
  172. package/dist/utils/multimodalOptionsBuilder.d.ts +1 -0
  173. package/dist/utils/multimodalOptionsBuilder.js +2 -0
  174. package/dist/utils/redis.d.ts +12 -0
  175. package/dist/utils/redis.js +72 -0
  176. package/dist/utils/retryAfter.d.ts +32 -0
  177. package/dist/utils/retryAfter.js +135 -11
  178. package/dist/utils/safeFetch.d.ts +22 -1
  179. package/dist/utils/safeFetch.js +132 -38
  180. package/dist/utils/safeStoreId.d.ts +19 -0
  181. package/dist/utils/safeStoreId.js +29 -0
  182. package/dist/utils/schemaConversion.d.ts +30 -3
  183. package/dist/utils/schemaConversion.js +457 -84
  184. package/dist/utils/sizeGuard.js +2 -2
  185. package/dist/utils/ssrfGuard.d.ts +3 -3
  186. package/dist/utils/ssrfGuard.js +71 -39
  187. package/dist/voice/eval/sttEvalStore.d.ts +26 -3
  188. package/dist/voice/eval/sttEvalStore.js +77 -12
  189. package/dist/voice/livekit/agentDefinition.d.ts +18 -0
  190. package/dist/voice/livekit/agentDefinition.js +22 -0
  191. package/dist/voice/livekit/realtimeMcpTools.d.ts +1 -1
  192. package/dist/voice/livekit/realtimeMcpTools.js +8 -7
  193. package/dist/voice/livekit/realtimeVoiceAgent.d.ts +2 -4
  194. package/dist/voice/livekit/realtimeVoiceAgent.js +18 -7
  195. package/dist/voice/livekit/voiceAgent.d.ts +2 -2
  196. package/dist/voice/livekit/voiceAgent.js +2 -1
  197. package/dist/voice/livekit/xaiSessionWatch.d.ts +0 -5
  198. package/dist/voice/livekit/xaiSessionWatch.js +30 -0
  199. package/dist/voice/providers/GeminiLive.js +21 -6
  200. package/dist/voice/providers/GoogleSTT.js +8 -5
  201. package/dist/voice/transcribe.d.ts +2 -2
  202. package/dist/voice/transcribe.js +34 -18
  203. package/dist/voice/whistle/audio.js +11 -5
  204. package/dist/workflow/workflows/adaptiveWorkflow.d.ts +2 -2
  205. package/dist/workflow/workflows/adaptiveWorkflow.js +10 -10
  206. package/dist/workflow/workflows/consensusWorkflow.d.ts +4 -4
  207. package/dist/workflow/workflows/consensusWorkflow.js +12 -12
  208. package/dist/workflow/workflows/fallbackWorkflow.d.ts +3 -3
  209. package/dist/workflow/workflows/fallbackWorkflow.js +7 -7
  210. package/dist/workflow/workflows/multiJudgeWorkflow.d.ts +7 -7
  211. package/dist/workflow/workflows/multiJudgeWorkflow.js +31 -31
  212. package/docs-site/static/search-index.json +74 -52
  213. package/package.json +173 -156
  214. package/scripts/observability/import-openobserve-dashboard.mjs +11 -3
@@ -206,6 +206,15 @@ export type NeurolinkConstructorConfig = {
206
206
  * See {@link MiddlewareFactoryOptions}.
207
207
  */
208
208
  middleware?: MiddlewareFactoryOptions;
209
+ /**
210
+ * What this instance may read or fetch when a call names a file path or URL
211
+ * (`input.files`, `input.images`, `rag.files`, `transcribe({ audio })`,
212
+ * Director Mode segment images). Unset: URLs must be HTTPS to a public host
213
+ * (redirects re-checked per hop), local paths are unrestricted but warn once.
214
+ * Set `allowedRoots` whenever the strings come from untrusted callers. See
215
+ * {@link AttachmentsConfig}.
216
+ */
217
+ attachments?: AttachmentsConfig;
209
218
  };
210
219
  /**
211
220
  * Configuration for MCP enhancement modules wired into generate()/stream() paths.
@@ -219,6 +228,20 @@ export type NeurolinkConstructorConfig = {
219
228
  * - middleware: Global tool execution middleware chain (empty by default)
220
229
  */
221
230
  export type MCPEnhancementsConfig = {
231
+ /**
232
+ * Explicit path of a project MCP configuration (`.mcp-config.json` shape)
233
+ * to load when MCP initialises. Relative paths resolve against the
234
+ * working directory. This is the SDK's only way to load a project file:
235
+ * the working directory is never searched implicitly, because a directory
236
+ * is not a trust boundary — a cloned repository's `.mcp-config.json`
237
+ * would otherwise run its servers with your credentials.
238
+ */
239
+ configPath?: string;
240
+ /**
241
+ * Load `<cwd>/.mcp-config.json` without naming it. Set this only when the
242
+ * working directory is one you control. Default: false.
243
+ */
244
+ trustProjectConfig?: boolean;
222
245
  /** Tool result caching. Default: enabled. Set enabled: false to opt out. */
223
246
  cache?: {
224
247
  enabled?: boolean;
@@ -556,6 +579,7 @@ export declare const DEFAULT_CONFIG: NeuroLinkConfig;
556
579
  import { TOOL_TIMEOUTS, BACKOFF_CONFIG, PERFORMANCE_PROFILES, PROVIDER_OPERATION_CONFIGS, MCP_OPERATION_CONFIGS } from "../constants/index.js";
557
580
  import type { ToolMiddleware, CacheStrategy, RoutingStrategy, ToolDedupConfig, ToolRoutingConfig } from "./index.js";
558
581
  import type { ModelAliasConfig } from "./generate.js";
582
+ import type { AttachmentsConfig } from "./attachments.js";
559
583
  /** Timeout category keys from TOOL_TIMEOUTS. */
560
584
  export type TimeoutCategory = keyof typeof TOOL_TIMEOUTS;
561
585
  /** Retry strategy keys from BACKOFF_CONFIG. */
@@ -619,3 +643,35 @@ export type NativeThinkingConfig = {
619
643
  thinkingLevel?: ThinkingLevel;
620
644
  thinkingBudget?: number;
621
645
  };
646
+ export type DotenvBootstrapOptions = {
647
+ /**
648
+ * Who is loading. The CLI prints its notices to stderr; an SDK caller
649
+ * (opted in with `NEUROLINK_DOTENV=1` or by calling `loadDotenv()`) gets
650
+ * the same notices through `notify`, which defaults to stderr as well.
651
+ */
652
+ caller?: "cli" | "sdk";
653
+ /** Receives one human-readable line per notice. Default: `process.stderr`. */
654
+ notify?: (line: string) => void;
655
+ };
656
+ export type DotenvBootstrapResult = {
657
+ /** Whether a `.env` file was read. */
658
+ loaded: boolean;
659
+ /** Absolute path of the file that was (or would have been) read. */
660
+ path?: string;
661
+ /** Variables the file supplied that were absent from the environment. */
662
+ supplied: string[];
663
+ /**
664
+ * The subset of `supplied` that redirects traffic or file access: provider
665
+ * `*_BASE_URL` / `*_ENDPOINT(S)` variables, `NEUROLINK_*_DIR` directories
666
+ * and `DOTENV_CONFIG_PATH`. Still set unless listed under `refused`.
667
+ */
668
+ endpointOverrides: string[];
669
+ /**
670
+ * Endpoint overrides deleted again because the file is not owned by the
671
+ * current user or is group/world-writable. Export them in the shell to use
672
+ * them.
673
+ */
674
+ refused: string[];
675
+ /** Why loading was skipped or overrides were refused, when either happened. */
676
+ reason?: string;
677
+ };
@@ -2,6 +2,7 @@
2
2
  * File detection and processing types for unified file handling
3
3
  */
4
4
  import type { ImageWithAltText } from "./multimodal.js";
5
+ import type { AttachmentPolicy } from "./attachments.js";
5
6
  /**
6
7
  * Supported file types for multimodal input
7
8
  */
@@ -724,6 +725,13 @@ export type FileDetectorOptions = {
724
725
  * filesystem access; SDK callers loading their own files can omit it.
725
726
  */
726
727
  allowedBaseDir?: string;
728
+ /**
729
+ * Instance attachment policy: `allowedRoots` containment (when
730
+ * `allowedBaseDir` is not set), the URL rules (HTTPS-only, public hosts,
731
+ * re-validated redirects) and the global size cap. The environment-derived
732
+ * default applies when absent.
733
+ */
734
+ attachmentPolicy?: AttachmentPolicy;
727
735
  audioOptions?: AudioProcessorOptions;
728
736
  csvOptions?: CSVProcessorOptions;
729
737
  officeOptions?: OfficeProcessorOptions;
@@ -28,6 +28,14 @@ export type HITLConfig = {
28
28
  auditLogging?: boolean;
29
29
  /** Advanced custom rules for complex tool scenarios (default: []) */
30
30
  customRules?: HITLRule[];
31
+ /**
32
+ * Whether the built-in tools that change the machine — `writeFile` and the
33
+ * opt-in `executeBashCommand` — always require confirmation while HITL is
34
+ * enabled, whatever `dangerousActions` says (default: true). Set to `false`
35
+ * to gate built-in tools by `dangerousActions` keywords and `customRules`
36
+ * only, as every other tool is.
37
+ */
38
+ confirmBuiltinTools?: boolean;
31
39
  };
32
40
  /**
33
41
  * Custom rule for advanced HITL scenarios
@@ -8,6 +8,7 @@ export * from "./agentMode.js";
8
8
  export * from "./aliases.js";
9
9
  export * from "./analytics.js";
10
10
  export * from "./artifact.js";
11
+ export * from "./attachments.js";
11
12
  export * from "./auth.js";
12
13
  export * from "./autoresearch.js";
13
14
  export * from "./circuitBreakerErrors.js";
@@ -9,6 +9,7 @@ export * from "./agentMode.js";
9
9
  export * from "./aliases.js";
10
10
  export * from "./analytics.js";
11
11
  export * from "./artifact.js";
12
+ export * from "./attachments.js";
12
13
  export * from "./auth.js";
13
14
  export * from "./autoresearch.js";
14
15
  export * from "./circuitBreakerErrors.js";
@@ -69,6 +69,24 @@ export type MCPServerInfo = {
69
69
  cwd?: string;
70
70
  autoRestart?: boolean;
71
71
  healthCheckInterval?: number;
72
+ /**
73
+ * stdio only. By default a spawned server receives the MCP SDK's minimal
74
+ * default environment (`HOME`, `PATH`, `SHELL`, `TERM`, `USER`, `LOGNAME`
75
+ * on POSIX) plus `env`; the parent's provider keys and tokens are not
76
+ * inherited. Set `true` to restore the previous behaviour of handing the
77
+ * server the whole parent `process.env`. Prefer explicit pass-through:
78
+ * `"env": { "OPENAI_API_KEY": "${OPENAI_API_KEY}" }`.
79
+ */
80
+ inheritParentEnv?: boolean;
81
+ /**
82
+ * http / sse / websocket only. A transport URL must use `https:` or `wss:`
83
+ * unless its host is loopback, and its host must not resolve to a private,
84
+ * link-local, CGNAT or cloud-metadata address. Set `true` for a server on
85
+ * your own network: plaintext `http:` / `ws:` is then accepted for hosts
86
+ * that are (or resolve only to) private addresses. Public hosts still need
87
+ * TLS.
88
+ */
89
+ allowPrivateNetwork?: boolean;
72
90
  /**
73
91
  * Minimum number of tools that must be discovered for this server's
74
92
  * registration to be considered ready (default: 0 — no minimum, so a
@@ -2268,3 +2286,83 @@ export type OptimizeParametersParams = {
2268
2286
  optimizeFor: "speed" | "quality" | "cost" | "tokens";
2269
2287
  iterations: number;
2270
2288
  };
2289
+ /** One recorded acceptance of a project `.mcp-config.json`. */
2290
+ export type ProjectMcpConfigTrustEntry = {
2291
+ /** Lower-case hex SHA-256 of the file's bytes when it was accepted. */
2292
+ sha256: string;
2293
+ /** ISO-8601 timestamp of the acceptance. */
2294
+ trustedAt: string;
2295
+ };
2296
+ /**
2297
+ * On-disk shape of `~/.neurolink/trusted-mcp-configs.json`: absolute config
2298
+ * path → the hash the user accepted. A changed file no longer matches and
2299
+ * has to be accepted again.
2300
+ */
2301
+ export type ProjectMcpConfigTrustStore = {
2302
+ version: 1;
2303
+ entries: Record<string, ProjectMcpConfigTrustEntry>;
2304
+ };
2305
+ /**
2306
+ * What a project config would do, reduced to what a human needs to see
2307
+ * before trusting it. Header and `env` values are deliberately absent: only
2308
+ * the `env` key names are listed, so a summary never echoes a secret.
2309
+ */
2310
+ export type ProjectMcpConfigServerSummary = {
2311
+ id: string;
2312
+ transport: string;
2313
+ command?: string;
2314
+ args?: string[];
2315
+ url?: string;
2316
+ envKeys?: string[];
2317
+ };
2318
+ export type ProjectMcpConfigSummary = {
2319
+ /** Absolute path of the config file. */
2320
+ path: string;
2321
+ /** Lower-case hex SHA-256 of the file's bytes. */
2322
+ sha256: string;
2323
+ servers: ProjectMcpConfigServerSummary[];
2324
+ /** Set when the file is not valid JSON or has no `mcpServers` object. */
2325
+ parseError?: string;
2326
+ };
2327
+ /**
2328
+ * `trusted`: the store holds this path with this hash. `changed`: the store
2329
+ * holds this path with a different hash. `untrusted`: never accepted.
2330
+ */
2331
+ export type ProjectMcpConfigTrustStatus = "trusted" | "changed" | "untrusted";
2332
+ /**
2333
+ * Which rule let a project config be loaded. `configPath` and
2334
+ * `trustProjectConfig` come from the `NeuroLink` constructor's `mcp` option;
2335
+ * `cliTrust` is the CLI's hash-pinned acceptance; `enableManualMCP` is the
2336
+ * `ProviderRegistry` option a host set after construction.
2337
+ */
2338
+ export type ProjectMcpConfigSource = "configPath" | "trustProjectConfig" | "cliTrust" | "enableManualMCP";
2339
+ export type ProjectMcpConfigPathResolution = {
2340
+ path: string;
2341
+ source: ProjectMcpConfigSource;
2342
+ };
2343
+ /**
2344
+ * Registered by the CLI entry point once it has decided what to do about the
2345
+ * working directory's `.mcp-config.json`. Called with the candidate path the
2346
+ * moment a `NeuroLink` instance would load it; returns the path to load or
2347
+ * `null` to load nothing. A hook may also end the process (the CLI's
2348
+ * non-interactive refusal does), which is why it is asynchronous.
2349
+ */
2350
+ export type ProjectMcpConfigTrustHook = (candidatePath: string) => Promise<string | null>;
2351
+ /** Options for the MCP transport URL policy (`assertMcpTransportUrlAllowed`). */
2352
+ export type McpTransportUrlPolicyOptions = {
2353
+ transport: MCPTransportType;
2354
+ /** See {@link MCPServerInfo.allowPrivateNetwork}. */
2355
+ allowPrivateNetwork?: boolean;
2356
+ /**
2357
+ * The host application supplied its own `fetch` (or dispatcher) for this
2358
+ * server, so egress — which addresses are dialled, with which pins — is
2359
+ * decided by that code, not by this policy. Only program code can pass a
2360
+ * function; a config file never can. The scheme allow-list still applies;
2361
+ * the plaintext and address classification is skipped.
2362
+ */
2363
+ hostOwnedEgress?: boolean;
2364
+ /** Used only to name the server in error messages. */
2365
+ serverId?: string;
2366
+ };
2367
+ /** How an address is classified by the MCP transport URL policy. */
2368
+ export type McpTransportAddressClass = "loopback" | "private" | "public";
@@ -1,44 +1,3 @@
1
- /**
2
- * Multimodal Content Types for NeuroLink
3
- *
4
- * Central registry for all multimodal input/output types.
5
- * This file consolidates types from content.ts and conversation.ts
6
- * to provide a single source of truth for multimodal functionality.
7
- *
8
- * @module types/multimodal
9
- *
10
- * @example Basic Multimodal Input
11
- * ```typescript
12
- * import type { MultimodalInput } from './types/multimodal.js';
13
- *
14
- * const input: MultimodalInput = {
15
- * text: "What's in this image?",
16
- * images: [imageBuffer, "https://example.com/image.jpg"],
17
- * pdfFiles: [pdfBuffer]
18
- * };
19
- * ```
20
- *
21
- * @example Audio/Video Input (Future)
22
- * ```typescript
23
- * const avInput: MultimodalInput = {
24
- * text: "Transcribe this audio and analyze this video",
25
- * audioFiles: [audioBuffer],
26
- * videoFiles: ["path/to/video.mp4"]
27
- * };
28
- * ```
29
- *
30
- * @example Advanced Content Array
31
- * ```typescript
32
- * const advanced: MultimodalInput = {
33
- * text: "irrelevant", // ignored when content[] is provided
34
- * content: [
35
- * { type: "text", text: "Analyze these items:" },
36
- * { type: "image", data: imageBuffer, mediaType: "image/jpeg" },
37
- * { type: "pdf", data: pdfBuffer, metadata: { filename: "report.pdf" } }
38
- * ]
39
- * };
40
- * ```
41
- */
42
1
  // ============================================
43
2
  // TYPE GUARDS
44
3
  // ============================================
@@ -129,7 +129,7 @@ export type OpenAICompatStreamDelta = {
129
129
  role?: OpenAICompatChatRole;
130
130
  content?: string | null;
131
131
  tool_calls?: Array<{
132
- index: number;
132
+ index?: number;
133
133
  id?: string;
134
134
  type?: "function";
135
135
  function?: {
@@ -7,6 +7,7 @@
7
7
  * @module processors/base/types
8
8
  */
9
9
  import type { FileErrorCode } from "../processors/errors/FileErrorCode.js";
10
+ import type { AttachmentPolicy } from "./attachments.js";
10
11
  /**
11
12
  * Generic file information - provider agnostic.
12
13
  * Replaces Slack-specific SlackFileInfo with a universal interface.
@@ -145,8 +146,16 @@ export type ProcessorRetryConfig = {
145
146
  * Allows customization of download behavior and retry logic.
146
147
  */
147
148
  export type ProcessOptions = {
148
- /** Authentication headers for download requests */
149
+ /**
150
+ * Authentication headers for download requests. Sent on the first request
151
+ * only — never replayed to a redirect target.
152
+ */
149
153
  authHeaders?: Record<string, string>;
154
+ /**
155
+ * Attachment policy for the download (URL rules, size cap). The
156
+ * environment-derived default applies when absent.
157
+ */
158
+ attachmentPolicy?: AttachmentPolicy;
150
159
  /** Override default timeout (in milliseconds) */
151
160
  timeout?: number;
152
161
  /** Retry configuration for transient failures */
@@ -872,6 +881,10 @@ export type BoundedZipEntry = {
872
881
  crc: number;
873
882
  };
874
883
  };
884
+ /** The minimum an indexable adm-zip entry carries (see `zipEntryIndex.ts`). */
885
+ export type NamedZipEntry = {
886
+ entryName: string;
887
+ };
875
888
  export type ArchiveEntryReadResult = {
876
889
  readonly status: "ok";
877
890
  readonly buffer: Buffer;
@@ -1,5 +1,6 @@
1
1
  import type { ProxyTokenBudgetLease, ProxyTokenBudgetSnapshot } from "./proxyBudget.js";
2
2
  import type { CodexRuntimeAccount } from "./codex.js";
3
+ import type { TokenUsage } from "./analytics.js";
3
4
  import type { JsonObject, JsonValue } from "./common.js";
4
5
  import type { ProxyContextEvidence, ProxyPreparedContext } from "./proxyContext.js";
5
6
  /**
@@ -258,14 +259,7 @@ export type InternalResult = {
258
259
  finishReason?: string;
259
260
  /** Thinking/reasoning text from provider (Anthropic thinking blocks, Gemini thought parts) */
260
261
  reasoning?: string;
261
- usage?: {
262
- input: number;
263
- output: number;
264
- total: number;
265
- cacheCreationTokens?: number;
266
- cacheReadTokens?: number;
267
- reasoning?: number;
268
- };
262
+ usage?: TokenUsage;
269
263
  toolCalls?: Array<{
270
264
  toolCallId: string;
271
265
  toolName: string;
@@ -1307,6 +1301,10 @@ export type PreparedAnthropicAccountAttempt = {
1307
1301
  lastError: unknown;
1308
1302
  authFailureMessage: string | null;
1309
1303
  headers?: Record<string, string>;
1304
+ /** The upstream `anthropic-beta` carries a value the client asked for that
1305
+ * the proxy would not have sent itself. A rejection of it is then the
1306
+ * client's doing, and must not re-rank the pool for everyone. */
1307
+ clientSuppliedBetaForwarded?: boolean;
1310
1308
  buildUpstreamBody?: AnthropicUpstreamBodyBuilder;
1311
1309
  finalBodyStr?: string;
1312
1310
  preparedContext?: ProxyPreparedContext<ClaudeRequest>;
@@ -3242,18 +3240,37 @@ export type ProxyStatusPrimaryAccount = {
3242
3240
  label: string | null;
3243
3241
  source: "configured" | "fallback";
3244
3242
  };
3245
- /** Parsed fields captured from a Claude Code client request body. */
3243
+ /**
3244
+ * Identity tuple captured from a genuine Claude Code client request body.
3245
+ *
3246
+ * Deliberately carries no prompt text. An earlier shape persisted the client's
3247
+ * "agent block" `system` text and replayed it as the system prompt of every
3248
+ * later non-Claude-Code request on the account, so one hostile request could
3249
+ * plant instructions into everyone else's sessions. The agent block is now a
3250
+ * compiled-in constant; `billingHeader` is stored only in its normalised
3251
+ * two-field form.
3252
+ */
3246
3253
  export type ClaudeSnapshotBody = {
3247
3254
  metadataUserId?: string;
3248
3255
  billingHeader?: string;
3249
- agentBlock?: string;
3250
3256
  sessionId?: string;
3251
3257
  };
3258
+ /** The identity tuple plus one request-shape probe that is never persisted. */
3259
+ export type ClaudeSnapshotBodyProbe = ClaudeSnapshotBody & {
3260
+ hasAgentBlock?: boolean;
3261
+ };
3252
3262
  /** Snapshot of headers and body from a Claude Code request, used for polyfill. */
3253
3263
  export type ClaudeSnapshot = {
3254
3264
  accountKey: string;
3255
3265
  capturedAt: string;
3256
3266
  source: "claude-code";
3267
+ /**
3268
+ * Set only by a capture that verified the client was Claude Code itself
3269
+ * (session header and `claude-cli/` user-agent). A snapshot without it was
3270
+ * written by a release whose heuristic any caller could satisfy, so its
3271
+ * identity tuple is not trusted and is dropped on load.
3272
+ */
3273
+ capturedFrom?: "genuine-claude-code";
3257
3274
  headers: Record<string, string>;
3258
3275
  body?: ClaudeSnapshotBody;
3259
3276
  };
@@ -3377,10 +3394,46 @@ export type ProxyRuntimeConfigStoreOptions = {
3377
3394
  };
3378
3395
  /** Runtime configuration provider captured by route factories. */
3379
3396
  export type ProxyRuntimeConfigProvider = () => ProxyRequestRoutingSnapshot;
3397
+ /**
3398
+ * Inbound authentication for a mounted proxy route group.
3399
+ *
3400
+ * `token` is the bearer every caller must present (header
3401
+ * `x-neurolink-inbound-token`, or `Authorization: Bearer <token>`); when
3402
+ * omitted it is read from `NEUROLINK_PROXY_INBOUND_TOKEN`. With neither, the
3403
+ * routes serve any caller that reaches them, and the factory says so loudly
3404
+ * unless `allowUnauthenticated` records that the operator chose that
3405
+ * (loopback-only bind, or an authenticating reverse proxy in front).
3406
+ */
3407
+ export type ProxyInboundAuthOptions = {
3408
+ token?: string;
3409
+ allowUnauthenticated?: boolean;
3410
+ };
3380
3411
  /** Optional runtime configuration wiring for Claude proxy route factories. */
3381
3412
  export type ClaudeProxyRouteRuntimeOptions = {
3382
3413
  accountAllowlist?: AccountAllowlist;
3383
- runtimeConfigProvider: ProxyRuntimeConfigProvider;
3414
+ runtimeConfigProvider?: ProxyRuntimeConfigProvider;
3415
+ inboundAuth?: ProxyInboundAuthOptions;
3416
+ };
3417
+ /**
3418
+ * Whether a listener may bind where it was asked to.
3419
+ *
3420
+ * A non-loopback bind needs something in front of the pooled subscriptions:
3421
+ * the share gate (`NEUROLINK_PROXY_REQUIRE_GRANT`), an inbound token, or the
3422
+ * operator's explicit `allowUnauthenticated`.
3423
+ */
3424
+ export type ProxyBindPolicyDecision = {
3425
+ allowed: true;
3426
+ warning?: string;
3427
+ } | {
3428
+ allowed: false;
3429
+ reason: string;
3430
+ };
3431
+ /** Inputs to the bind policy, resolved from flags and the environment. */
3432
+ export type ProxyBindPolicyInput = {
3433
+ host: string;
3434
+ inboundToken?: string;
3435
+ requireGrant: boolean;
3436
+ allowUnauthenticated: boolean;
3384
3437
  };
3385
3438
  /** Listener invoked after a new configuration generation is published. */
3386
3439
  export type ProxyRuntimeConfigListener = (snapshot: ProxyRuntimeConfigSnapshot) => void;
@@ -3465,11 +3518,7 @@ export type StreamSerializerAdapter = {
3465
3518
  start(): Iterable<string>;
3466
3519
  pushDelta(text: string): Iterable<string>;
3467
3520
  pushToolUse(id: string, name: string, input: unknown): Iterable<string>;
3468
- finish(finishReason: string, usage: {
3469
- input: number;
3470
- output: number;
3471
- total: number;
3472
- }): Iterable<string>;
3521
+ finish(finishReason: string, usage: TokenUsage): Iterable<string>;
3473
3522
  emitError(message: string): Iterable<string>;
3474
3523
  };
3475
3524
  /** OpenAI content part in a user message. */
@@ -3556,6 +3605,12 @@ export type OpenAIUsage = {
3556
3605
  prompt_tokens: number;
3557
3606
  completion_tokens: number;
3558
3607
  total_tokens: number;
3608
+ prompt_tokens_details?: {
3609
+ cached_tokens: number;
3610
+ };
3611
+ completion_tokens_details?: {
3612
+ reasoning_tokens: number;
3613
+ };
3559
3614
  };
3560
3615
  /** OpenAI non-streaming response. */
3561
3616
  export type OpenAICompletionResponse = {
@@ -268,6 +268,8 @@ export type ProxyLedgerEntry = {
268
268
  model: string;
269
269
  provider?: string;
270
270
  inputTokens: number;
271
+ /** Native Codex input includes cache reads and writes. */
272
+ inputIncludesCachedTokens: boolean;
271
273
  outputTokens: number;
272
274
  cacheReadTokens: number;
273
275
  cacheCreationTokens: number;
@@ -1,6 +1,7 @@
1
1
  import type { Tool } from "./tools.js";
2
2
  import type { EmbedInput } from "./providers.js";
3
3
  import type { DecisionCallerFn } from "./decision.js";
4
+ import type { AttachmentPolicy } from "./attachments.js";
4
5
  /**
5
6
  * RAG Type Definitions
6
7
  *
@@ -500,6 +501,14 @@ export type LoaderOptions = {
500
501
  export type WebLoaderOptions = LoaderOptions & {
501
502
  /** Request timeout in milliseconds */
502
503
  timeout?: number;
504
+ /**
505
+ * Attachment policy for the fetch: HTTPS-only and public hosts unless it
506
+ * says otherwise, redirects re-validated per hop. The environment-derived
507
+ * default applies when absent.
508
+ */
509
+ attachmentPolicy?: AttachmentPolicy;
510
+ /** Cap on the fetched document in bytes. Default 25 MiB. */
511
+ maxBytes?: number;
503
512
  /** Custom headers for request */
504
513
  headers?: Record<string, string>;
505
514
  /** Extract only main content (remove navigation, ads, etc.) */
@@ -21,4 +21,44 @@ export type SafeDownloadOptions = {
21
21
  signal?: AbortSignal;
22
22
  /** Optional HTTP transfer timeout (ms), covering headers and body after URL validation. Default: 60_000. */
23
23
  timeoutMs?: number;
24
+ /**
25
+ * Headers for the FIRST request only. Never replayed to a redirect target:
26
+ * a credential meant for one host must not be handed to the host it
27
+ * redirects to. Default: none.
28
+ */
29
+ headers?: Record<string, string>;
30
+ /**
31
+ * How many redirect hops to follow, each re-validated by the SSRF guard and
32
+ * sent without the caller's headers. Default 0: a 3xx is refused, which is
33
+ * the server path's behaviour.
34
+ */
35
+ maxRedirects?: number;
36
+ /** Accept `http:` as well as `https:`. Default false (HTTPS only). */
37
+ allowInsecure?: boolean;
38
+ /**
39
+ * Skip the private/loopback/link-local/metadata range check. The connection
40
+ * is still pinned to the resolved addresses. Default false.
41
+ */
42
+ allowPrivateNetwork?: boolean;
43
+ /** `HEAD` returns the headers with an empty body. Default `GET`. */
44
+ method?: "GET" | "HEAD";
45
+ };
46
+ /** `safeDownloadWithMeta()` — the body plus what the response said about it. */
47
+ export type SafeDownloadResult = {
48
+ buffer: Buffer;
49
+ /** `Content-Type` of the final response, `""` when absent. */
50
+ contentType: string;
51
+ /** `Content-Encoding` of the final response, `""` when absent. */
52
+ contentEncoding: string;
53
+ /** The URL that produced the body — differs from the request URL after a redirect. */
54
+ finalUrl: string;
55
+ /** Redirect hops that were followed. */
56
+ redirects: number;
57
+ };
58
+ /** Per-call switches for `validateAndResolveUrl()` / `assertSafeUrlForProxy()`. */
59
+ export type SsrfGuardOptions = {
60
+ /** Accept `http:` as well as `https:`. Default false. */
61
+ allowInsecure?: boolean;
62
+ /** Skip the blocked-range check (addresses are still resolved and returned). Default false. */
63
+ allowPrivateNetwork?: boolean;
24
64
  };