@oobe-protocol-labs/sap-mcp-server 0.9.22 → 0.9.35

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 (188) hide show
  1. package/.env.example +10 -0
  2. package/CHANGELOG.md +100 -6
  3. package/README.md +3 -3
  4. package/USER_DOCS/00_START_HERE.md +9 -1
  5. package/USER_DOCS/01_HOSTED_REMOTE_MCP.md +1 -1
  6. package/USER_DOCS/04_CLIENT_CONFIGS.md +3 -3
  7. package/USER_DOCS/06_DESKTOP_GUI_WIZARD.md +5 -5
  8. package/dist/config/env.d.ts +18 -0
  9. package/dist/config/env.d.ts.map +1 -1
  10. package/dist/config/env.js +14 -2
  11. package/dist/config/env.js.map +1 -1
  12. package/dist/config/mcp-client-injection.js +3 -3
  13. package/dist/config/paths.d.ts +9 -1
  14. package/dist/config/paths.d.ts.map +1 -1
  15. package/dist/config/paths.js +15 -1
  16. package/dist/config/paths.js.map +1 -1
  17. package/dist/config/wizard.d.ts.map +1 -1
  18. package/dist/config/wizard.js +3 -1
  19. package/dist/config/wizard.js.map +1 -1
  20. package/dist/core/constants.d.ts +1 -1
  21. package/dist/core/constants.js +1 -1
  22. package/dist/core/logger.js +1 -1
  23. package/dist/memory/async-processor.d.ts +107 -0
  24. package/dist/memory/async-processor.d.ts.map +1 -0
  25. package/dist/memory/async-processor.js +204 -0
  26. package/dist/memory/async-processor.js.map +1 -0
  27. package/dist/memory/auto-record.d.ts +47 -0
  28. package/dist/memory/auto-record.d.ts.map +1 -0
  29. package/dist/memory/auto-record.js +133 -0
  30. package/dist/memory/auto-record.js.map +1 -0
  31. package/dist/memory/database.d.ts +103 -0
  32. package/dist/memory/database.d.ts.map +1 -0
  33. package/dist/memory/database.js +337 -0
  34. package/dist/memory/database.js.map +1 -0
  35. package/dist/memory/hermes-bridge.d.ts +70 -0
  36. package/dist/memory/hermes-bridge.d.ts.map +1 -0
  37. package/dist/memory/hermes-bridge.js +155 -0
  38. package/dist/memory/hermes-bridge.js.map +1 -0
  39. package/dist/memory/index.d.ts +23 -0
  40. package/dist/memory/index.d.ts.map +1 -0
  41. package/dist/memory/index.js +22 -0
  42. package/dist/memory/index.js.map +1 -0
  43. package/dist/memory/memory-store.d.ts +76 -0
  44. package/dist/memory/memory-store.d.ts.map +1 -0
  45. package/dist/memory/memory-store.js +231 -0
  46. package/dist/memory/memory-store.js.map +1 -0
  47. package/dist/memory/stream-buffer-store.d.ts +69 -0
  48. package/dist/memory/stream-buffer-store.d.ts.map +1 -0
  49. package/dist/memory/stream-buffer-store.js +182 -0
  50. package/dist/memory/stream-buffer-store.js.map +1 -0
  51. package/dist/memory/tool-call-store.d.ts +68 -0
  52. package/dist/memory/tool-call-store.d.ts.map +1 -0
  53. package/dist/memory/tool-call-store.js +189 -0
  54. package/dist/memory/tool-call-store.js.map +1 -0
  55. package/dist/memory/types.d.ts +197 -0
  56. package/dist/memory/types.d.ts.map +1 -0
  57. package/dist/memory/types.js +15 -0
  58. package/dist/memory/types.js.map +1 -0
  59. package/dist/memory/utils.d.ts +30 -0
  60. package/dist/memory/utils.d.ts.map +1 -0
  61. package/dist/memory/utils.js +47 -0
  62. package/dist/memory/utils.js.map +1 -0
  63. package/dist/payments/hosted-tool-eligibility.d.ts.map +1 -1
  64. package/dist/payments/hosted-tool-eligibility.js +4 -6
  65. package/dist/payments/hosted-tool-eligibility.js.map +1 -1
  66. package/dist/payments/monetization-gate.d.ts +39 -0
  67. package/dist/payments/monetization-gate.d.ts.map +1 -1
  68. package/dist/payments/monetization-gate.js +165 -11
  69. package/dist/payments/monetization-gate.js.map +1 -1
  70. package/dist/payments/pricing.d.ts.map +1 -1
  71. package/dist/payments/pricing.js +69 -0
  72. package/dist/payments/pricing.js.map +1 -1
  73. package/dist/payments/x402-paid-call.js +1 -1
  74. package/dist/premium/builtin-plugins.d.ts +42 -0
  75. package/dist/premium/builtin-plugins.d.ts.map +1 -1
  76. package/dist/premium/builtin-plugins.js +91 -10
  77. package/dist/premium/builtin-plugins.js.map +1 -1
  78. package/dist/premium/manifest-builder.d.ts.map +1 -1
  79. package/dist/premium/manifest-builder.js +43 -7
  80. package/dist/premium/manifest-builder.js.map +1 -1
  81. package/dist/premium/meme-radar-capabilities.js +9 -9
  82. package/dist/premium/meme-radar-capabilities.js.map +1 -1
  83. package/dist/premium/plugin-validator.d.ts.map +1 -1
  84. package/dist/premium/plugin-validator.js +62 -1
  85. package/dist/premium/plugin-validator.js.map +1 -1
  86. package/dist/premium/provider-bridge.d.ts +25 -1
  87. package/dist/premium/provider-bridge.d.ts.map +1 -1
  88. package/dist/premium/provider-bridge.js +130 -20
  89. package/dist/premium/provider-bridge.js.map +1 -1
  90. package/dist/premium/session-manager.d.ts.map +1 -1
  91. package/dist/premium/session-manager.js +12 -3
  92. package/dist/premium/session-manager.js.map +1 -1
  93. package/dist/premium/tech-fundamentals-capabilities.js +5 -5
  94. package/dist/premium/tech-fundamentals-capabilities.js.map +1 -1
  95. package/dist/premium/trading-capabilities.js +5 -5
  96. package/dist/premium/trading-capabilities.js.map +1 -1
  97. package/dist/premium/webhook-engine.d.ts.map +1 -1
  98. package/dist/premium/webhook-engine.js +7 -1
  99. package/dist/premium/webhook-engine.js.map +1 -1
  100. package/dist/prompts/context/sap-agent-context.prompt.js +1 -1
  101. package/dist/prompts/payments/explain-x402-settlement.prompt.js +1 -1
  102. package/dist/remote/premium-routes.d.ts.map +1 -1
  103. package/dist/remote/premium-routes.js +3 -2
  104. package/dist/remote/premium-routes.js.map +1 -1
  105. package/dist/remote/public-home/sections.d.ts.map +1 -1
  106. package/dist/remote/public-home/sections.js +2 -3
  107. package/dist/remote/public-home/sections.js.map +1 -1
  108. package/dist/remote/public-home/styles.d.ts +1 -1
  109. package/dist/remote/public-home/styles.js +2 -2
  110. package/dist/remote/server.d.ts.map +1 -1
  111. package/dist/remote/server.js +19 -4
  112. package/dist/remote/server.js.map +1 -1
  113. package/dist/server/server-metadata.js +1 -1
  114. package/dist/strategies/strategy-store.d.ts +82 -0
  115. package/dist/strategies/strategy-store.d.ts.map +1 -0
  116. package/dist/strategies/strategy-store.js +165 -0
  117. package/dist/strategies/strategy-store.js.map +1 -0
  118. package/dist/tools/agent-start-tool.d.ts.map +1 -1
  119. package/dist/tools/agent-start-tool.js +97 -10
  120. package/dist/tools/agent-start-tool.js.map +1 -1
  121. package/dist/tools/client-sdk-tools.d.ts.map +1 -1
  122. package/dist/tools/client-sdk-tools.js +152 -9
  123. package/dist/tools/client-sdk-tools.js.map +1 -1
  124. package/dist/tools/estimate-tool-cost.js +1 -1
  125. package/dist/tools/estimate-tool-cost.js.map +1 -1
  126. package/dist/tools/index.d.ts +1 -0
  127. package/dist/tools/index.d.ts.map +1 -1
  128. package/dist/tools/index.js +2 -0
  129. package/dist/tools/index.js.map +1 -1
  130. package/dist/tools/magicblock-tools.js +5 -5
  131. package/dist/tools/magicblock-tools.js.map +1 -1
  132. package/dist/tools/memory-tools.d.ts +26 -0
  133. package/dist/tools/memory-tools.d.ts.map +1 -0
  134. package/dist/tools/memory-tools.js +533 -0
  135. package/dist/tools/memory-tools.js.map +1 -0
  136. package/dist/tools/perp-tools.d.ts +7 -9
  137. package/dist/tools/perp-tools.d.ts.map +1 -1
  138. package/dist/tools/perp-tools.js +386 -367
  139. package/dist/tools/perp-tools.js.map +1 -1
  140. package/dist/tools/premium-tools.d.ts.map +1 -1
  141. package/dist/tools/premium-tools.js +8 -2
  142. package/dist/tools/premium-tools.js.map +1 -1
  143. package/dist/tools/profile-tools.d.ts.map +1 -1
  144. package/dist/tools/profile-tools.js +18 -1
  145. package/dist/tools/profile-tools.js.map +1 -1
  146. package/dist/tools/quick-context-tool.d.ts.map +1 -1
  147. package/dist/tools/quick-context-tool.js +100 -9
  148. package/dist/tools/quick-context-tool.js.map +1 -1
  149. package/dist/tools/register-tools.d.ts.map +1 -1
  150. package/dist/tools/register-tools.js +3 -0
  151. package/dist/tools/register-tools.js.map +1 -1
  152. package/dist/tools/sap-sdk-tools.js +3 -3
  153. package/dist/tools/sap-sdk-tools.js.map +1 -1
  154. package/dist/tools/session-context-packet.d.ts +19 -0
  155. package/dist/tools/session-context-packet.d.ts.map +1 -0
  156. package/dist/tools/session-context-packet.js +256 -0
  157. package/dist/tools/session-context-packet.js.map +1 -0
  158. package/dist/tools/skills-tools.d.ts +10 -0
  159. package/dist/tools/skills-tools.d.ts.map +1 -1
  160. package/dist/tools/skills-tools.js +19 -0
  161. package/dist/tools/skills-tools.js.map +1 -1
  162. package/dist/tools/transaction-tools.d.ts +1 -0
  163. package/dist/tools/transaction-tools.d.ts.map +1 -1
  164. package/dist/tools/transaction-tools.js +248 -9
  165. package/dist/tools/transaction-tools.js.map +1 -1
  166. package/dist/tools/x402-paid-call-tool.d.ts.map +1 -1
  167. package/dist/tools/x402-paid-call-tool.js +55 -21
  168. package/dist/tools/x402-paid-call-tool.js.map +1 -1
  169. package/dist/wizard-core/desktop-flow.d.ts.map +1 -1
  170. package/dist/wizard-core/desktop-flow.js +4 -2
  171. package/dist/wizard-core/desktop-flow.js.map +1 -1
  172. package/docs/06_PAYMENTS_X402_AND_PAYSH.md +14 -5
  173. package/docs/07_ENDPOINTS_AND_CLIENTS.md +1 -1
  174. package/docs/09_TOOLS_SKILLS_AND_AGENT_GUIDE.md +13 -5
  175. package/docs/13_BOUNTY_PROGRAM_PROPOSAL.md +1 -1
  176. package/docs/14_DESKTOP_WIZARD_RELEASE.md +3 -3
  177. package/docs/15_DASHBOARD_SCREENSHARE_SCRIPT.md +1 -1
  178. package/docs/BRANCH_AND_CI.md +2 -2
  179. package/docs/README.md +1 -1
  180. package/package.json +3 -1
  181. package/server.json +3 -3
  182. package/skills/README.md +1 -1
  183. package/skills/sap-agentkit/SKILL.md +1 -2
  184. package/skills/sap-defi/SKILL.md +31 -2
  185. package/skills/sap-mcp/SKILL.md +24 -13
  186. package/skills/sap-mcp/TOOL_REFERENCE.md +2 -4
  187. package/skills/sap-payments-x402/SKILL.md +15 -3
  188. package/assets/logos/drift.svg +0 -12
@@ -0,0 +1,182 @@
1
+ /**
2
+ * @module memory/stream-buffer-store
3
+ * @description Store for buffering stream events locally in SQLite.
4
+ *
5
+ * Premium stream events (Pyth price ticks, meme alerts, volatility signals) are
6
+ * persisted locally so the agent can consume them without paid polls. Events
7
+ * are deduplicated by (streamType, eventId) and consumed in FIFO order.
8
+ */
9
+ import { memoryDatabase } from './database.js';
10
+ /**
11
+ * @name StreamBufferStore
12
+ * @description Manages local stream event buffering with FIFO consumption.
13
+ */
14
+ export class StreamBufferStore {
15
+ /**
16
+ * @name buffer
17
+ * @description Buffers a stream event. Deduplicates by (streamType, eventId).
18
+ * @param record - Event to buffer.
19
+ * @returns The row ID, or -1 if the event was already buffered (dedup).
20
+ */
21
+ buffer(record) {
22
+ if (memoryDatabase.isDegraded())
23
+ return -1;
24
+ memoryDatabase.init();
25
+ const stmt = memoryDatabase.getStatement('insert_stream_event');
26
+ if (!stmt)
27
+ return -1;
28
+ try {
29
+ const result = stmt.run({
30
+ streamType: record.streamType,
31
+ eventId: record.eventId,
32
+ eventType: record.eventType,
33
+ payload: record.payload,
34
+ });
35
+ return result.lastInsertRowid;
36
+ }
37
+ catch {
38
+ // INSERT OR IGNORE — dedup case, event already exists.
39
+ return -1;
40
+ }
41
+ }
42
+ /**
43
+ * @name consume
44
+ * @description Returns unconsumed events for a stream type and marks them consumed.
45
+ * FIFO order (oldest first). Returns up to `limit` events.
46
+ * @param streamType - Stream type to consume (e.g. 'pyth-price').
47
+ * @param limit - Maximum events to consume. Default 20.
48
+ * @returns Consumed events.
49
+ */
50
+ consume(streamType, limit = 20) {
51
+ if (memoryDatabase.isDegraded())
52
+ return [];
53
+ memoryDatabase.init();
54
+ const db = memoryDatabase.getDb();
55
+ try {
56
+ const events = db.prepare(`SELECT * FROM stream_buffers
57
+ WHERE stream_type = ? AND consumed = 0
58
+ ORDER BY id ASC
59
+ LIMIT ?`).all(streamType, limit);
60
+ if (events.length === 0)
61
+ return [];
62
+ // Mark as consumed.
63
+ const lastId = events[events.length - 1].id;
64
+ if (lastId !== undefined) {
65
+ const consumeStmt = memoryDatabase.getStatement('consume_stream_events');
66
+ consumeStmt?.run(streamType, lastId);
67
+ }
68
+ return events;
69
+ }
70
+ catch {
71
+ return [];
72
+ }
73
+ }
74
+ /**
75
+ * @name peek
76
+ * @description Returns unconsumed events without marking them consumed.
77
+ * Used for preview/inspection.
78
+ */
79
+ peek(streamType, limit = 20) {
80
+ if (memoryDatabase.isDegraded())
81
+ return [];
82
+ memoryDatabase.init();
83
+ const db = memoryDatabase.getDb();
84
+ try {
85
+ return db.prepare(`SELECT * FROM stream_buffers
86
+ WHERE stream_type = ? AND consumed = 0
87
+ ORDER BY id ASC
88
+ LIMIT ?`).all(streamType, limit);
89
+ }
90
+ catch {
91
+ return [];
92
+ }
93
+ }
94
+ /**
95
+ * @name replay
96
+ * @description Returns all events (consumed + unconsumed) for a stream type
97
+ * within a time range. Used for backtest/analysis.
98
+ * @param streamType - Stream type to replay.
99
+ * @param since - ISO 8601 timestamp. Events created after this time.
100
+ * @param limit - Maximum events. Default 100.
101
+ */
102
+ replay(streamType, since, limit = 100) {
103
+ if (memoryDatabase.isDegraded())
104
+ return [];
105
+ memoryDatabase.init();
106
+ const db = memoryDatabase.getDb();
107
+ try {
108
+ if (since) {
109
+ return db.prepare(`SELECT * FROM stream_buffers
110
+ WHERE stream_type = ? AND created_at >= ?
111
+ ORDER BY id ASC LIMIT ?`).all(streamType, since, limit);
112
+ }
113
+ return db.prepare(`SELECT * FROM stream_buffers
114
+ WHERE stream_type = ?
115
+ ORDER BY id ASC LIMIT ?`).all(streamType, limit);
116
+ }
117
+ catch {
118
+ return [];
119
+ }
120
+ }
121
+ /**
122
+ * @name pendingCount
123
+ * @description Returns the number of unconsumed events.
124
+ */
125
+ pendingCount() {
126
+ if (memoryDatabase.isDegraded())
127
+ return 0;
128
+ memoryDatabase.init();
129
+ const stmt = memoryDatabase.getStatement('count_pending_streams');
130
+ if (!stmt)
131
+ return 0;
132
+ return stmt.get().count;
133
+ }
134
+ /**
135
+ * @name evict
136
+ * @description Evicts old consumed events to keep the buffer bounded.
137
+ * @param maxPerType - Maximum events per stream type. Default 10000.
138
+ * @returns Number of events evicted.
139
+ */
140
+ evict(maxPerType = 10_000) {
141
+ if (memoryDatabase.isDegraded())
142
+ return 0;
143
+ memoryDatabase.init();
144
+ const db = memoryDatabase.getDb();
145
+ try {
146
+ // Delete oldest consumed events that exceed the per-type limit.
147
+ const result = db.prepare(`DELETE FROM stream_buffers
148
+ WHERE consumed = 1 AND id NOT IN (
149
+ SELECT id FROM stream_buffers
150
+ WHERE stream_type = (SELECT stream_type FROM stream_buffers s2 WHERE s2.id = stream_buffers.id)
151
+ ORDER BY id DESC LIMIT ?
152
+ )`).run(maxPerType);
153
+ return result.changes;
154
+ }
155
+ catch {
156
+ return 0;
157
+ }
158
+ }
159
+ /**
160
+ * @name clear
161
+ * @description Clears all events for a stream type.
162
+ */
163
+ clear(streamType) {
164
+ if (memoryDatabase.isDegraded())
165
+ return 0;
166
+ memoryDatabase.init();
167
+ const db = memoryDatabase.getDb();
168
+ try {
169
+ const result = db.prepare('DELETE FROM stream_buffers WHERE stream_type = ?').run(streamType);
170
+ return result.changes;
171
+ }
172
+ catch {
173
+ return 0;
174
+ }
175
+ }
176
+ }
177
+ /**
178
+ * @name streamBufferStore
179
+ * @description Singleton instance of the stream buffer store.
180
+ */
181
+ export const streamBufferStore = new StreamBufferStore();
182
+ //# sourceMappingURL=stream-buffer-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-buffer-store.js","sourceRoot":"","sources":["../../src/memory/stream-buffer-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,MAAiE;QACtE,IAAI,cAAc,CAAC,UAAU,EAAE;YAAE,OAAO,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tB,MAAM,IAAI,GAAG,cAAc,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC;QACpB,OAAQ,IAAI,CAAC,GAAG,EAAwB,CAAC,KAAK,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,GAAG,MAAM;QACvB,IAAI,cAAc,CAAC,UAAU,EAAE;YAAE,OAAO,CAAC,CAAC;QAC1C,cAAc,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,gEAAgE;YAChE,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CACvB;;;;;WAKG,CACJ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClB,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAkB;QACtB,IAAI,cAAc,CAAC,UAAU,EAAE;YAAE,OAAO,CAAC,CAAC;QAC1C,cAAc,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,EAAE,CAAC,OAAO,CACvB,kDAAkD,CACnD,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAClB,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @module memory/tool-call-store
3
+ * @description Store for recording and searching tool call history.
4
+ *
5
+ * All methods are synchronous (better-sqlite3 is synchronous). FTS5 search
6
+ * returns relevance-ranked results using the inverted index.
7
+ */
8
+ import type { ToolCallRecord, ToolCallOutcome, MemorySearchResult, MemoryQueryOptions } from './types.js';
9
+ /**
10
+ * @name ToolCallStore
11
+ * @description Records and queries tool call execution history.
12
+ *
13
+ * Every tool call (paid or free) is recorded with its input, output, outcome,
14
+ * cost, and latency. The FTS5 index enables full-text search across all
15
+ * recorded calls for pattern detection and failure analysis.
16
+ */
17
+ export declare class ToolCallStore {
18
+ /**
19
+ * @name record
20
+ * @description Records a tool call execution in the memory database.
21
+ * @param record - Tool call data to record.
22
+ * @returns The auto-incremented ID of the inserted record, or -1 if degraded.
23
+ */
24
+ record(record: Omit<ToolCallRecord, 'id' | 'createdAt' | 'updatedAt'>): number;
25
+ /**
26
+ * @name search
27
+ * @description Full-text search across tool call history using FTS5.
28
+ * @param options - Search options including query, filters, and pagination.
29
+ * @returns Search results with relevance ranking.
30
+ */
31
+ search(options: MemoryQueryOptions): MemorySearchResult<ToolCallRecord>;
32
+ /**
33
+ * @name count
34
+ * @description Returns the total number of tool call records.
35
+ */
36
+ count(): number;
37
+ /**
38
+ * @name outcomeBreakdown
39
+ * @description Returns counts grouped by outcome.
40
+ */
41
+ outcomeBreakdown(): Record<ToolCallOutcome, number>;
42
+ /**
43
+ * @name lastToolCallAt
44
+ * @description Returns the timestamp of the most recent tool call.
45
+ */
46
+ lastToolCallAt(): string | null;
47
+ /**
48
+ * @name archive
49
+ * @description Archives tool call records older than the retention period.
50
+ * @param retentionDays - Number of days to keep records. Default 90.
51
+ * @returns Number of records archived.
52
+ */
53
+ archive(retentionDays?: number): number;
54
+ /**
55
+ * @name buildFtsQuery
56
+ * @description Converts a natural language query into a FTS5 MATCH expression.
57
+ * Handles multi-word queries by quoting phrases and prefixing with OR for
58
+ * broader recall.
59
+ * @internal
60
+ */
61
+ private buildFtsQuery;
62
+ }
63
+ /**
64
+ * @name toolCallStore
65
+ * @description Singleton instance of the tool call store.
66
+ */
67
+ export declare const toolCallStore: ToolCallStore;
68
+ //# sourceMappingURL=tool-call-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-call-store.d.ts","sourceRoot":"","sources":["../../src/memory/tool-call-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE1G;;;;;;;GAOG;AACH,qBAAa,aAAa;IACxB;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,MAAM;IAwB9E;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,CAAC,cAAc,CAAC;IA6DvE;;;OAGG;IACH,KAAK,IAAI,MAAM;IAQf;;;OAGG;IACH,gBAAgB,IAAI,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC;IAgBnD;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAS/B;;;;;OAKG;IACH,OAAO,CAAC,aAAa,SAAK,GAAG,MAAM;IAUnC;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;CAUtB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,eAAsB,CAAC"}
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @module memory/tool-call-store
3
+ * @description Store for recording and searching tool call history.
4
+ *
5
+ * All methods are synchronous (better-sqlite3 is synchronous). FTS5 search
6
+ * returns relevance-ranked results using the inverted index.
7
+ */
8
+ import { memoryDatabase } from './database.js';
9
+ import { truncate } from './utils.js';
10
+ /**
11
+ * @name ToolCallStore
12
+ * @description Records and queries tool call execution history.
13
+ *
14
+ * Every tool call (paid or free) is recorded with its input, output, outcome,
15
+ * cost, and latency. The FTS5 index enables full-text search across all
16
+ * recorded calls for pattern detection and failure analysis.
17
+ */
18
+ export class ToolCallStore {
19
+ /**
20
+ * @name record
21
+ * @description Records a tool call execution in the memory database.
22
+ * @param record - Tool call data to record.
23
+ * @returns The auto-incremented ID of the inserted record, or -1 if degraded.
24
+ */
25
+ record(record) {
26
+ if (memoryDatabase.isDegraded())
27
+ return -1;
28
+ memoryDatabase.init();
29
+ const stmt = memoryDatabase.getStatement('insert_tool_call');
30
+ if (!stmt)
31
+ return -1;
32
+ const maxBytes = 8192;
33
+ const result = stmt.run({
34
+ toolName: record.toolName,
35
+ sessionId: record.sessionId,
36
+ callerProfile: record.callerProfile,
37
+ input: truncate(record.input, maxBytes),
38
+ output: truncate(record.output, maxBytes),
39
+ outcome: record.outcome,
40
+ costUsd: record.costUsd ?? null,
41
+ txSignature: record.txSignature ?? null,
42
+ latencyMs: record.latencyMs ?? null,
43
+ });
44
+ return result.lastInsertRowid;
45
+ }
46
+ /**
47
+ * @name search
48
+ * @description Full-text search across tool call history using FTS5.
49
+ * @param options - Search options including query, filters, and pagination.
50
+ * @returns Search results with relevance ranking.
51
+ */
52
+ search(options) {
53
+ if (memoryDatabase.isDegraded()) {
54
+ return { results: [], total: 0, hasMore: false };
55
+ }
56
+ memoryDatabase.init();
57
+ const db = memoryDatabase.getDb();
58
+ const limit = Math.min(options.limit ?? 20, 100);
59
+ const offset = options.offset ?? 0;
60
+ // Build FTS5 query with optional filters.
61
+ let whereClause = '';
62
+ const params = { limit, offset };
63
+ if (options.toolName) {
64
+ whereClause += ' AND t.tool_name = @toolName';
65
+ params['toolName'] = options.toolName;
66
+ }
67
+ if (options.outcome) {
68
+ whereClause += ' AND t.outcome = @outcome';
69
+ params['outcome'] = options.outcome;
70
+ }
71
+ // FTS5 MATCH query — use bm25 ranking for relevance.
72
+ const ftsQuery = this.buildFtsQuery(options.query);
73
+ const sql = `
74
+ SELECT t.id, t.tool_name, t.session_id, t.caller_profile, t.input, t.output,
75
+ t.outcome, t.cost_usd, t.tx_signature, t.latency_ms,
76
+ t.created_at, t.updated_at
77
+ FROM tool_calls_fts fts
78
+ JOIN tool_calls t ON t.id = fts.rowid
79
+ WHERE tool_calls_fts MATCH @ftsQuery
80
+ ${whereClause}
81
+ ORDER BY ${options.sort === 'newest' ? 't.created_at DESC' : options.sort === 'oldest' ? 't.created_at ASC' : 'bm25(tool_calls_fts)'}
82
+ LIMIT @limit OFFSET @offset
83
+ `;
84
+ params['ftsQuery'] = ftsQuery;
85
+ try {
86
+ const results = db.prepare(sql).all(params);
87
+ const countSql = `
88
+ SELECT COUNT(*) as total
89
+ FROM tool_calls_fts fts
90
+ JOIN tool_calls t ON t.id = fts.rowid
91
+ WHERE tool_calls_fts MATCH @ftsQuery ${whereClause}
92
+ `;
93
+ const countResult = db.prepare(countSql).get(params);
94
+ const total = countResult?.total ?? 0;
95
+ return {
96
+ results,
97
+ total,
98
+ hasMore: offset + results.length < total,
99
+ };
100
+ }
101
+ catch {
102
+ return { results: [], total: 0, hasMore: false };
103
+ }
104
+ }
105
+ /**
106
+ * @name count
107
+ * @description Returns the total number of tool call records.
108
+ */
109
+ count() {
110
+ if (memoryDatabase.isDegraded())
111
+ return 0;
112
+ memoryDatabase.init();
113
+ const stmt = memoryDatabase.getStatement('count_tool_calls');
114
+ if (!stmt)
115
+ return 0;
116
+ return stmt.get().count;
117
+ }
118
+ /**
119
+ * @name outcomeBreakdown
120
+ * @description Returns counts grouped by outcome.
121
+ */
122
+ outcomeBreakdown() {
123
+ if (memoryDatabase.isDegraded()) {
124
+ return { success: 0, error: 0, partial: 0 };
125
+ }
126
+ memoryDatabase.init();
127
+ const stmt = memoryDatabase.getStatement('count_tool_calls_by_outcome');
128
+ if (!stmt)
129
+ return { success: 0, error: 0, partial: 0 };
130
+ const rows = stmt.all();
131
+ const result = { success: 0, error: 0, partial: 0 };
132
+ for (const row of rows) {
133
+ result[row.outcome] = row.count;
134
+ }
135
+ return result;
136
+ }
137
+ /**
138
+ * @name lastToolCallAt
139
+ * @description Returns the timestamp of the most recent tool call.
140
+ */
141
+ lastToolCallAt() {
142
+ if (memoryDatabase.isDegraded())
143
+ return null;
144
+ memoryDatabase.init();
145
+ const stmt = memoryDatabase.getStatement('last_tool_call_at');
146
+ if (!stmt)
147
+ return null;
148
+ const row = stmt.get();
149
+ return row?.created_at ?? null;
150
+ }
151
+ /**
152
+ * @name archive
153
+ * @description Archives tool call records older than the retention period.
154
+ * @param retentionDays - Number of days to keep records. Default 90.
155
+ * @returns Number of records archived.
156
+ */
157
+ archive(retentionDays = 90) {
158
+ if (memoryDatabase.isDegraded())
159
+ return 0;
160
+ memoryDatabase.init();
161
+ const db = memoryDatabase.getDb();
162
+ const result = db.prepare(`DELETE FROM tool_calls WHERE created_at < datetime('now', ?)`).run(`-${retentionDays} days`);
163
+ return result.changes;
164
+ }
165
+ /**
166
+ * @name buildFtsQuery
167
+ * @description Converts a natural language query into a FTS5 MATCH expression.
168
+ * Handles multi-word queries by quoting phrases and prefixing with OR for
169
+ * broader recall.
170
+ * @internal
171
+ */
172
+ buildFtsQuery(query) {
173
+ // Escape FTS5 special characters and wrap in quotes for phrase matching.
174
+ const escaped = query.replace(/["'*:]/g, ' ').trim();
175
+ if (!escaped)
176
+ return '*';
177
+ // For multi-word queries, use OR to match any word (broader recall).
178
+ const words = escaped.split(/\s+/).filter(w => w.length > 0);
179
+ if (words.length === 1)
180
+ return `"${words[0]}"*`;
181
+ return words.map(w => `"${w}"*`).join(' OR ');
182
+ }
183
+ }
184
+ /**
185
+ * @name toolCallStore
186
+ * @description Singleton instance of the tool call store.
187
+ */
188
+ export const toolCallStore = new ToolCallStore();
189
+ //# sourceMappingURL=tool-call-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-call-store.js","sourceRoot":"","sources":["../../src/memory/tool-call-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IACxB;;;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C,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @module memory/types
3
+ * @description Type definitions for the SAP MCP local agent memory subsystem.
4
+ *
5
+ * The memory subsystem uses SQLite FTS5 to store and retrieve:
6
+ * - Tool call history (input, output, outcome, cost, latency)
7
+ * - Agent memories (LLM-compressed summaries of past interactions)
8
+ * - Stream buffer events (premium stream data persisted locally)
9
+ *
10
+ * All types are designed for non-custodial, local-only operation — no data
11
+ * leaves the user's machine. The memory DB is stored at
12
+ * ~/.config/mcp-sap/memory/agent-memory.db.
13
+ */
14
+ /**
15
+ * @name ToolCallRecord
16
+ * @description A single tool call execution record stored in the memory DB.
17
+ */
18
+ export interface ToolCallRecord {
19
+ /** Auto-increment primary key. */
20
+ id?: number;
21
+ /** MCP tool name (e.g. 'jupiter_getQuote', 'sap_build_sol_transfer'). */
22
+ toolName: string;
23
+ /** Session identifier from the MCP transport. */
24
+ sessionId: string | null;
25
+ /** Signer profile used for the call, if any. */
26
+ callerProfile: string | null;
27
+ /** JSON-serialized tool input. Truncated to 8KB. */
28
+ input: string;
29
+ /** JSON-serialized tool output. Truncated to 8KB. */
30
+ output: string;
31
+ /** Execution outcome classification. */
32
+ outcome: ToolCallOutcome;
33
+ /** x402 cost in USD, if the tool was paid. */
34
+ costUsd: number | null;
35
+ /** Solana transaction signature, if the tool produced one. */
36
+ txSignature: string | null;
37
+ /** Execution latency in milliseconds. */
38
+ latencyMs: number | null;
39
+ /** ISO 8601 timestamp of when the record was created. */
40
+ createdAt: string;
41
+ /** ISO 8601 timestamp of when the record was last updated. */
42
+ updatedAt: string;
43
+ }
44
+ /**
45
+ * @name ToolCallOutcome
46
+ * @description Classification of a tool call's execution result.
47
+ */
48
+ export type ToolCallOutcome = 'success' | 'error' | 'partial';
49
+ /**
50
+ * @name AgentMemoryRecord
51
+ * @description An LLM-generated summary of past agent interactions.
52
+ *
53
+ * Memories are compressed representations of tool call patterns, failures,
54
+ * successes, and lessons learned. They decay over time via a relevance
55
+ * score that decreases as memories age, ensuring the agent prioritizes
56
+ * recent, high-signal knowledge.
57
+ */
58
+ export interface AgentMemoryRecord {
59
+ /** Auto-increment primary key. */
60
+ id?: number;
61
+ /** Type of memory — determines how it's used in prompt injection. */
62
+ memoryType: MemoryType;
63
+ /** Tool category this memory relates to (e.g. 'jupiter', 'adrena', 'premium'). */
64
+ category: string;
65
+ /** LLM-compressed summary text. Max 4KB. */
66
+ summary: string;
67
+ /** JSON array of tool_call IDs that were the source of this memory. */
68
+ sourceToolCalls: string | null;
69
+ /** Relevance score 0-1. Decays over time. Higher = more relevant. */
70
+ relevanceScore: number;
71
+ /** ISO 8601 timestamp of when the memory was created. */
72
+ createdAt: string;
73
+ /** ISO 8601 timestamp of when the memory expires. NULL = never expires. */
74
+ expiresAt: string | null;
75
+ /** ISO 8601 timestamp of when the memory was last accessed. */
76
+ lastAccessedAt: string;
77
+ }
78
+ /**
79
+ * @name MemoryType
80
+ * @description Classification of agent memory entries.
81
+ * - 'lesson': A learned pattern or rule (e.g. "Jupiter swaps fail when slippage < 50bps on low-liquidity pairs")
82
+ * - 'pattern': A recurring behavior (e.g. "Agent consistently buys when SOL price drops > 2%")
83
+ * - 'failure': A specific failure with root cause (e.g. "BlockhashNotFound after 90s — retry with fresh blockhash")
84
+ * - 'success': A successful outcome worth remembering (e.g. "Arb opportunity on SOL/USDC at block 123456")
85
+ */
86
+ export type MemoryType = 'lesson' | 'pattern' | 'failure' | 'success';
87
+ /**
88
+ * @name StreamBufferRecord
89
+ * @description A buffered stream event persisted locally for offline analysis.
90
+ */
91
+ export interface StreamBufferRecord {
92
+ /** Auto-increment primary key. */
93
+ id?: number;
94
+ /** Stream type identifier (e.g. 'pyth-price', 'meme-alerts', 'volatility'). */
95
+ streamType: string;
96
+ /** Unique event ID from the provider. */
97
+ eventId: string;
98
+ /** Event type from the provider (e.g. 'price.tick', 'volatility.breakout'). */
99
+ eventType: string;
100
+ /** JSON-serialized event payload. */
101
+ payload: string;
102
+ /** Whether the event has been consumed by the agent. */
103
+ consumed: number;
104
+ /** ISO 8601 timestamp of when the event was buffered. */
105
+ createdAt: string;
106
+ }
107
+ /**
108
+ * @name MemorySearchResult
109
+ * @description A result from a full-text search across tool calls or agent memories.
110
+ */
111
+ export interface MemorySearchResult<T = unknown> {
112
+ /** The matching records. */
113
+ results: T[];
114
+ /** Total number of matching records (before pagination). */
115
+ total: number;
116
+ /** Whether there are more results available. */
117
+ hasMore: boolean;
118
+ }
119
+ /**
120
+ * @name MemoryQueryOptions
121
+ * @description Options for searching the memory database.
122
+ */
123
+ export interface MemoryQueryOptions {
124
+ /** FTS5 search query (e.g. 'swap failure', 'jupiter slippage'). */
125
+ query: string;
126
+ /** Filter by tool name (tool_calls only). */
127
+ toolName?: string;
128
+ /** Filter by outcome (tool_calls only). */
129
+ outcome?: ToolCallOutcome;
130
+ /** Filter by memory type (agent_memory only). */
131
+ memoryType?: MemoryType;
132
+ /** Filter by category. */
133
+ category?: string;
134
+ /** Minimum relevance score (agent_memory only). */
135
+ minRelevance?: number;
136
+ /** Maximum number of results to return. Default 20. */
137
+ limit?: number;
138
+ /** Offset for pagination. Default 0. */
139
+ offset?: number;
140
+ /** Sort order. Default 'relevance' for FTS, 'newest' for time-based. */
141
+ sort?: 'relevance' | 'newest' | 'oldest';
142
+ }
143
+ /**
144
+ * @name MemoryStats
145
+ * @description Aggregate statistics about the memory database.
146
+ */
147
+ export interface MemoryStats {
148
+ /** Total number of tool call records. */
149
+ toolCallCount: number;
150
+ /** Total number of agent memory records. */
151
+ memoryCount: number;
152
+ /** Total number of stream buffer records (unconsumed). */
153
+ pendingStreamEvents: number;
154
+ /** Total database size in bytes. */
155
+ dbSizeBytes: number;
156
+ /** Breakdown of tool calls by outcome. */
157
+ outcomeBreakdown: Record<ToolCallOutcome, number>;
158
+ /** Breakdown of agent memories by type. */
159
+ memoryTypeBreakdown: Record<MemoryType, number>;
160
+ /** Most recent tool call timestamp. */
161
+ lastToolCallAt: string | null;
162
+ /** Most recent memory timestamp. */
163
+ lastMemoryAt: string | null;
164
+ }
165
+ /**
166
+ * @name MemoryPruneResult
167
+ * @description Result of pruning old, low-relevance memories.
168
+ */
169
+ export interface MemoryPruneResult {
170
+ /** Number of memories pruned. */
171
+ pruned: number;
172
+ /** Number of tool calls archived (old records). */
173
+ archived: number;
174
+ /** Database size reduction in bytes. */
175
+ freedBytes: number;
176
+ }
177
+ /**
178
+ * @name MemoryConfig
179
+ * @description Configuration for the memory subsystem.
180
+ */
181
+ export interface MemoryConfig {
182
+ /** Path to the SQLite database file. */
183
+ dbPath: string;
184
+ /** Whether to enable WAL mode (recommended for concurrent access). */
185
+ enableWal: boolean;
186
+ /** Maximum size of tool call input/output stored. Default 8192 bytes. */
187
+ maxPayloadBytes: number;
188
+ /** Relevance decay rate per day. Default 0.01 (1% per day). */
189
+ relevanceDecayPerDay: number;
190
+ /** Minimum relevance score to keep a memory. Default 0.05. */
191
+ minRelevanceThreshold: number;
192
+ /** Number of days to keep tool call records. Default 90. */
193
+ toolCallRetentionDays: number;
194
+ /** Maximum number of stream buffer events per type. Default 10000. */
195
+ maxStreamBufferSize: number;
196
+ }
197
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,gDAAgD;IAChD,aAAa,EAAE,MAAM,GAAG,I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