@juspay/neurolink 9.51.2 → 9.51.4

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 (54) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/artifacts/artifactStore.d.ts +56 -0
  3. package/dist/artifacts/artifactStore.js +143 -0
  4. package/dist/browser/neurolink.min.js +314 -303
  5. package/dist/cli/commands/mcp.d.ts +6 -0
  6. package/dist/cli/commands/mcp.js +128 -86
  7. package/dist/cli/factories/commandFactory.js +3 -2
  8. package/dist/cli/utils/typewriter.d.ts +18 -0
  9. package/dist/cli/utils/typewriter.js +42 -0
  10. package/dist/core/modules/ToolsManager.d.ts +10 -0
  11. package/dist/core/modules/ToolsManager.js +108 -32
  12. package/dist/core/redisConversationMemoryManager.js +20 -0
  13. package/dist/lib/artifacts/artifactStore.d.ts +56 -0
  14. package/dist/lib/artifacts/artifactStore.js +144 -0
  15. package/dist/lib/core/modules/ToolsManager.d.ts +10 -0
  16. package/dist/lib/core/modules/ToolsManager.js +108 -32
  17. package/dist/lib/core/redisConversationMemoryManager.js +20 -0
  18. package/dist/lib/mcp/externalServerManager.d.ts +6 -0
  19. package/dist/lib/mcp/externalServerManager.js +9 -0
  20. package/dist/lib/mcp/mcpOutputNormalizer.d.ts +49 -0
  21. package/dist/lib/mcp/mcpOutputNormalizer.js +182 -0
  22. package/dist/lib/mcp/toolDiscoveryService.d.ts +10 -0
  23. package/dist/lib/mcp/toolDiscoveryService.js +32 -1
  24. package/dist/lib/memory/memoryRetrievalTools.d.ts +64 -9
  25. package/dist/lib/memory/memoryRetrievalTools.js +77 -9
  26. package/dist/lib/neurolink.d.ts +2 -0
  27. package/dist/lib/neurolink.js +97 -88
  28. package/dist/lib/session/globalSessionState.js +44 -1
  29. package/dist/lib/types/artifactTypes.d.ts +63 -0
  30. package/dist/lib/types/artifactTypes.js +11 -0
  31. package/dist/lib/types/configTypes.d.ts +34 -2
  32. package/dist/lib/types/conversation.d.ts +7 -0
  33. package/dist/lib/types/index.d.ts +2 -0
  34. package/dist/lib/types/mcpOutputTypes.d.ts +40 -0
  35. package/dist/lib/types/mcpOutputTypes.js +9 -0
  36. package/dist/mcp/externalServerManager.d.ts +6 -0
  37. package/dist/mcp/externalServerManager.js +9 -0
  38. package/dist/mcp/mcpOutputNormalizer.d.ts +49 -0
  39. package/dist/mcp/mcpOutputNormalizer.js +181 -0
  40. package/dist/mcp/toolDiscoveryService.d.ts +10 -0
  41. package/dist/mcp/toolDiscoveryService.js +32 -1
  42. package/dist/memory/memoryRetrievalTools.d.ts +64 -9
  43. package/dist/memory/memoryRetrievalTools.js +77 -9
  44. package/dist/neurolink.d.ts +2 -0
  45. package/dist/neurolink.js +97 -88
  46. package/dist/session/globalSessionState.js +44 -1
  47. package/dist/types/artifactTypes.d.ts +63 -0
  48. package/dist/types/artifactTypes.js +10 -0
  49. package/dist/types/configTypes.d.ts +34 -2
  50. package/dist/types/conversation.d.ts +7 -0
  51. package/dist/types/index.d.ts +2 -0
  52. package/dist/types/mcpOutputTypes.d.ts +40 -0
  53. package/dist/types/mcpOutputTypes.js +8 -0
  54. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [9.51.4](https://github.com/juspay/neurolink/compare/v9.51.3...v9.51.4) (2026-04-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **(mcp):** large-response externalization, retrieve_context tool, and exec cleanup ([8e802d9](https://github.com/juspay/neurolink/commit/8e802d99782b7c365557fbaeeb67bc77a8aab9f1))
6
+
7
+ ## [9.51.3](https://github.com/juspay/neurolink/compare/v9.51.2...v9.51.3) (2026-04-12)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **(sdk):** prevent tool result context overflow, dedupe tool calls, animate CLI stream output ([211ea9d](https://github.com/juspay/neurolink/commit/211ea9d56beaf87219185f21df554b6d22fd1240))
12
+
1
13
  ## [9.51.2](https://github.com/juspay/neurolink/compare/v9.51.1...v9.51.2) (2026-04-11)
2
14
 
3
15
  ### Bug Fixes
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Artifact Store
3
+ *
4
+ * Pluggable storage for externalized MCP tool outputs.
5
+ *
6
+ * When `mcp.outputLimits.strategy = "externalize"` the full tool payload is
7
+ * written here instead of being sent inline to the LLM. The model receives a
8
+ * compact surrogate with a preview and an artifact ID. The full payload can be
9
+ * retrieved on demand via the `retrieve_context` tool.
10
+ *
11
+ * Architecture:
12
+ * ArtifactStore (interface) — canonical types in src/lib/types/artifactTypes.ts
13
+ * LocalTempArtifactStore — single-process, filesystem-backed implementation
14
+ *
15
+ * Distributed backends (S3, Redis blobs) can be added later by implementing
16
+ * ArtifactStore from types/artifactTypes.ts.
17
+ *
18
+ * @module artifacts/artifactStore
19
+ */
20
+ import type { ArtifactMeta, ArtifactRef, ArtifactStore } from "../types/artifactTypes.js";
21
+ export type { ArtifactMeta, ArtifactRef, ArtifactStore, } from "../types/artifactTypes.js";
22
+ /**
23
+ * Filesystem-backed artifact store using the OS temp directory.
24
+ *
25
+ * Files are written with mode 0o600 (owner read/write only).
26
+ * An in-memory index tracks metadata without a separate index file.
27
+ *
28
+ * Suitable for:
29
+ * - CLI usage
30
+ * - Single-process SDK deployments
31
+ * - Multi-process deployments where each process manages its own artifacts
32
+ * (artifacts created in one process are not visible to others)
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const store = new LocalTempArtifactStore();
37
+ * const ref = await store.store(largeJson, {
38
+ * toolName: "list_files",
39
+ * serverId: "filesystem-server",
40
+ * sizeBytes: Buffer.byteLength(largeJson),
41
+ * contentType: "json",
42
+ * });
43
+ * // Later, via retrieve_context:
44
+ * const full = await store.retrieve(ref.id);
45
+ * ```
46
+ */
47
+ export declare class LocalTempArtifactStore implements ArtifactStore {
48
+ private readonly dir;
49
+ private readonly index;
50
+ constructor(dir?: string);
51
+ generatePreview(payload: string): string;
52
+ store(payload: string, meta: Omit<ArtifactMeta, "createdAt">): Promise<ArtifactRef>;
53
+ retrieve(id: string): Promise<string | null>;
54
+ delete(id: string): Promise<void>;
55
+ cleanup(olderThanMs: number): Promise<number>;
56
+ }
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Artifact Store
3
+ *
4
+ * Pluggable storage for externalized MCP tool outputs.
5
+ *
6
+ * When `mcp.outputLimits.strategy = "externalize"` the full tool payload is
7
+ * written here instead of being sent inline to the LLM. The model receives a
8
+ * compact surrogate with a preview and an artifact ID. The full payload can be
9
+ * retrieved on demand via the `retrieve_context` tool.
10
+ *
11
+ * Architecture:
12
+ * ArtifactStore (interface) — canonical types in src/lib/types/artifactTypes.ts
13
+ * LocalTempArtifactStore — single-process, filesystem-backed implementation
14
+ *
15
+ * Distributed backends (S3, Redis blobs) can be added later by implementing
16
+ * ArtifactStore from types/artifactTypes.ts.
17
+ *
18
+ * @module artifacts/artifactStore
19
+ */
20
+ import { randomUUID } from "node:crypto";
21
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
22
+ import { tmpdir } from "node:os";
23
+ import { join } from "node:path";
24
+ import { logger } from "../utils/logger.js";
25
+ // ---------------------------------------------------------------------------
26
+ // LocalTempArtifactStore
27
+ // ---------------------------------------------------------------------------
28
+ /** Characters used for the quick preview embedded in surrogate results. */
29
+ const DEFAULT_PREVIEW_CHARS = 500;
30
+ /**
31
+ * Filesystem-backed artifact store using the OS temp directory.
32
+ *
33
+ * Files are written with mode 0o600 (owner read/write only).
34
+ * An in-memory index tracks metadata without a separate index file.
35
+ *
36
+ * Suitable for:
37
+ * - CLI usage
38
+ * - Single-process SDK deployments
39
+ * - Multi-process deployments where each process manages its own artifacts
40
+ * (artifacts created in one process are not visible to others)
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const store = new LocalTempArtifactStore();
45
+ * const ref = await store.store(largeJson, {
46
+ * toolName: "list_files",
47
+ * serverId: "filesystem-server",
48
+ * sizeBytes: Buffer.byteLength(largeJson),
49
+ * contentType: "json",
50
+ * });
51
+ * // Later, via retrieve_context:
52
+ * const full = await store.retrieve(ref.id);
53
+ * ```
54
+ */
55
+ export class LocalTempArtifactStore {
56
+ dir;
57
+ index = new Map();
58
+ constructor(dir) {
59
+ this.dir = dir ?? join(tmpdir(), "neurolink-artifacts");
60
+ }
61
+ generatePreview(payload) {
62
+ if (payload.length <= DEFAULT_PREVIEW_CHARS) {
63
+ return payload;
64
+ }
65
+ return `${payload.slice(0, DEFAULT_PREVIEW_CHARS)}…`;
66
+ }
67
+ async store(payload, meta) {
68
+ await mkdir(this.dir, { recursive: true, mode: 0o700 });
69
+ const id = randomUUID();
70
+ const ext = meta.contentType === "json" ? ".json" : ".txt";
71
+ const filePath = join(this.dir, `${id}${ext}`);
72
+ await writeFile(filePath, payload, { encoding: "utf-8", mode: 0o600 });
73
+ const fullMeta = {
74
+ ...meta,
75
+ createdAt: Date.now(),
76
+ path: filePath,
77
+ };
78
+ this.index.set(id, fullMeta);
79
+ logger.debug(`[ArtifactStore] Stored artifact ${id} for tool "${meta.toolName}" ` +
80
+ `(${formatBytes(meta.sizeBytes)})`);
81
+ return {
82
+ id,
83
+ preview: this.generatePreview(payload),
84
+ sizeBytes: meta.sizeBytes,
85
+ meta: { ...meta, createdAt: fullMeta.createdAt },
86
+ };
87
+ }
88
+ async retrieve(id) {
89
+ const entry = this.index.get(id);
90
+ if (!entry) {
91
+ logger.debug(`[ArtifactStore] Artifact ${id} not in index`);
92
+ return null;
93
+ }
94
+ try {
95
+ const content = await readFile(entry.path, "utf-8");
96
+ logger.debug(`[ArtifactStore] Retrieved artifact ${id} (${formatBytes(entry.sizeBytes)})`);
97
+ return content;
98
+ }
99
+ catch (err) {
100
+ logger.warn(`[ArtifactStore] Failed to read artifact ${id}: ${err instanceof Error ? err.message : String(err)}`);
101
+ return null;
102
+ }
103
+ }
104
+ async delete(id) {
105
+ const entry = this.index.get(id);
106
+ if (!entry) {
107
+ return;
108
+ }
109
+ try {
110
+ await rm(entry.path, { force: true });
111
+ }
112
+ catch {
113
+ // Suppress — file may already be gone
114
+ }
115
+ this.index.delete(id);
116
+ }
117
+ async cleanup(olderThanMs) {
118
+ const cutoff = Date.now() - olderThanMs;
119
+ let count = 0;
120
+ for (const [id, entry] of this.index.entries()) {
121
+ if (entry.createdAt < cutoff) {
122
+ await this.delete(id);
123
+ count++;
124
+ }
125
+ }
126
+ if (count > 0) {
127
+ logger.debug(`[ArtifactStore] Cleaned up ${count} expired artifact(s)`);
128
+ }
129
+ return count;
130
+ }
131
+ }
132
+ // ---------------------------------------------------------------------------
133
+ // Helpers
134
+ // ---------------------------------------------------------------------------
135
+ function formatBytes(bytes) {
136
+ if (bytes < 1024) {
137
+ return `${bytes} B`;
138
+ }
139
+ if (bytes < 1024 * 1024) {
140
+ return `${(bytes / 1024).toFixed(1)} KB`;
141
+ }
142
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
143
+ }