@animalabs/agent-framework 0.22.4 → 0.23.1

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 (234) hide show
  1. package/README.md +105 -3
  2. package/dist/src/agent.d.ts +36 -10
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +76 -32
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/code-execution/index.d.ts +1 -1
  7. package/dist/src/code-execution/index.d.ts.map +1 -1
  8. package/dist/src/code-execution/index.js.map +1 -1
  9. package/dist/src/code-execution/py-runner.d.ts +34 -2
  10. package/dist/src/code-execution/py-runner.d.ts.map +1 -1
  11. package/dist/src/code-execution/py-runner.js +72 -16
  12. package/dist/src/code-execution/py-runner.js.map +1 -1
  13. package/dist/src/code-execution/runtime-py.d.ts +3 -2
  14. package/dist/src/code-execution/runtime-py.d.ts.map +1 -1
  15. package/dist/src/code-execution/runtime-py.js +47 -7
  16. package/dist/src/code-execution/runtime-py.js.map +1 -1
  17. package/dist/src/code-execution/tool-definition.d.ts +12 -7
  18. package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
  19. package/dist/src/code-execution/tool-definition.js +59 -11
  20. package/dist/src/code-execution/tool-definition.js.map +1 -1
  21. package/dist/src/config-checks.d.ts +2 -2
  22. package/dist/src/config-checks.d.ts.map +1 -1
  23. package/dist/src/config-checks.js +6 -2
  24. package/dist/src/config-checks.js.map +1 -1
  25. package/dist/src/framework.d.ts +744 -120
  26. package/dist/src/framework.d.ts.map +1 -1
  27. package/dist/src/framework.js +3546 -906
  28. package/dist/src/framework.js.map +1 -1
  29. package/dist/src/gate/event-gate.d.ts.map +1 -1
  30. package/dist/src/gate/event-gate.js +13 -6
  31. package/dist/src/gate/event-gate.js.map +1 -1
  32. package/dist/src/held-writes.d.ts +16 -0
  33. package/dist/src/held-writes.d.ts.map +1 -0
  34. package/dist/src/held-writes.js +56 -0
  35. package/dist/src/held-writes.js.map +1 -0
  36. package/dist/src/index.d.ts +7 -3
  37. package/dist/src/index.d.ts.map +1 -1
  38. package/dist/src/index.js +8 -4
  39. package/dist/src/index.js.map +1 -1
  40. package/dist/src/mcpl/capability-grant.d.ts +4 -0
  41. package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
  42. package/dist/src/mcpl/capability-grant.js +1 -1
  43. package/dist/src/mcpl/capability-grant.js.map +1 -1
  44. package/dist/src/mcpl/channel-registry.d.ts +95 -18
  45. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  46. package/dist/src/mcpl/channel-registry.js +578 -150
  47. package/dist/src/mcpl/channel-registry.js.map +1 -1
  48. package/dist/src/mcpl/convert-block.d.ts +2 -2
  49. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  50. package/dist/src/mcpl/convert-block.js +6 -7
  51. package/dist/src/mcpl/convert-block.js.map +1 -1
  52. package/dist/src/mcpl/index.d.ts +5 -1
  53. package/dist/src/mcpl/index.d.ts.map +1 -1
  54. package/dist/src/mcpl/index.js +3 -1
  55. package/dist/src/mcpl/index.js.map +1 -1
  56. package/dist/src/mcpl/inference-router.d.ts +4 -2
  57. package/dist/src/mcpl/inference-router.d.ts.map +1 -1
  58. package/dist/src/mcpl/inference-router.js +6 -7
  59. package/dist/src/mcpl/inference-router.js.map +1 -1
  60. package/dist/src/mcpl/log-value.d.ts +7 -0
  61. package/dist/src/mcpl/log-value.d.ts.map +1 -1
  62. package/dist/src/mcpl/log-value.js +9 -0
  63. package/dist/src/mcpl/log-value.js.map +1 -1
  64. package/dist/src/mcpl/modern-connection.d.ts +227 -0
  65. package/dist/src/mcpl/modern-connection.d.ts.map +1 -0
  66. package/dist/src/mcpl/modern-connection.js +1088 -0
  67. package/dist/src/mcpl/modern-connection.js.map +1 -0
  68. package/dist/src/mcpl/prefix-rule.d.ts +18 -0
  69. package/dist/src/mcpl/prefix-rule.d.ts.map +1 -0
  70. package/dist/src/mcpl/prefix-rule.js +25 -0
  71. package/dist/src/mcpl/prefix-rule.js.map +1 -0
  72. package/dist/src/mcpl/protocol-family.d.ts +179 -0
  73. package/dist/src/mcpl/protocol-family.d.ts.map +1 -0
  74. package/dist/src/mcpl/protocol-family.js +697 -0
  75. package/dist/src/mcpl/protocol-family.js.map +1 -0
  76. package/dist/src/mcpl/push-coalescer.d.ts +38 -19
  77. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  78. package/dist/src/mcpl/push-coalescer.js +52 -23
  79. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  80. package/dist/src/mcpl/reference-fetcher.d.ts +66 -15
  81. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  82. package/dist/src/mcpl/reference-fetcher.js +243 -76
  83. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  84. package/dist/src/mcpl/references.d.ts +63 -18
  85. package/dist/src/mcpl/references.d.ts.map +1 -1
  86. package/dist/src/mcpl/references.js +117 -32
  87. package/dist/src/mcpl/references.js.map +1 -1
  88. package/dist/src/mcpl/server-connection.d.ts +326 -30
  89. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  90. package/dist/src/mcpl/server-connection.js +995 -212
  91. package/dist/src/mcpl/server-connection.js.map +1 -1
  92. package/dist/src/mcpl/server-registry.d.ts +25 -5
  93. package/dist/src/mcpl/server-registry.d.ts.map +1 -1
  94. package/dist/src/mcpl/server-registry.js +51 -12
  95. package/dist/src/mcpl/server-registry.js.map +1 -1
  96. package/dist/src/mcpl/tool-result-normalize.d.ts +54 -0
  97. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -0
  98. package/dist/src/mcpl/tool-result-normalize.js +232 -0
  99. package/dist/src/mcpl/tool-result-normalize.js.map +1 -0
  100. package/dist/src/mcpl/transport.d.ts +56 -13
  101. package/dist/src/mcpl/transport.d.ts.map +1 -1
  102. package/dist/src/mcpl/transport.js +206 -70
  103. package/dist/src/mcpl/transport.js.map +1 -1
  104. package/dist/src/mcpl/types.d.ts +66 -20
  105. package/dist/src/mcpl/types.d.ts.map +1 -1
  106. package/dist/src/mcpl/types.js.map +1 -1
  107. package/dist/src/mcpl/visible-content.d.ts +2 -1
  108. package/dist/src/mcpl/visible-content.d.ts.map +1 -1
  109. package/dist/src/mcpl/visible-content.js +2 -1
  110. package/dist/src/mcpl/visible-content.js.map +1 -1
  111. package/dist/src/module-registry.d.ts +16 -6
  112. package/dist/src/module-registry.d.ts.map +1 -1
  113. package/dist/src/module-registry.js +65 -6
  114. package/dist/src/module-registry.js.map +1 -1
  115. package/dist/src/modules/api/index.d.ts +1 -1
  116. package/dist/src/modules/api/index.d.ts.map +1 -1
  117. package/dist/src/modules/api/index.js +3 -2
  118. package/dist/src/modules/api/index.js.map +1 -1
  119. package/dist/src/modules/discord/discord-js-client.d.ts +42 -2
  120. package/dist/src/modules/discord/discord-js-client.d.ts.map +1 -1
  121. package/dist/src/modules/discord/discord-js-client.js +268 -65
  122. package/dist/src/modules/discord/discord-js-client.js.map +1 -1
  123. package/dist/src/modules/discord/index.d.ts +27 -5
  124. package/dist/src/modules/discord/index.d.ts.map +1 -1
  125. package/dist/src/modules/discord/index.js +366 -76
  126. package/dist/src/modules/discord/index.js.map +1 -1
  127. package/dist/src/modules/discord/refusal.d.ts +14 -0
  128. package/dist/src/modules/discord/refusal.d.ts.map +1 -0
  129. package/dist/src/modules/discord/refusal.js +14 -0
  130. package/dist/src/modules/discord/refusal.js.map +1 -0
  131. package/dist/src/modules/discord/types.d.ts +17 -7
  132. package/dist/src/modules/discord/types.d.ts.map +1 -1
  133. package/dist/src/modules/health/index.d.ts.map +1 -1
  134. package/dist/src/modules/health/index.js +6 -2
  135. package/dist/src/modules/health/index.js.map +1 -1
  136. package/dist/src/modules/index.d.ts +1 -1
  137. package/dist/src/modules/index.d.ts.map +1 -1
  138. package/dist/src/modules/index.js +1 -1
  139. package/dist/src/modules/index.js.map +1 -1
  140. package/dist/src/modules/workspace/disk-agreement.d.ts +25 -2
  141. package/dist/src/modules/workspace/disk-agreement.d.ts.map +1 -1
  142. package/dist/src/modules/workspace/disk-agreement.js +45 -5
  143. package/dist/src/modules/workspace/disk-agreement.js.map +1 -1
  144. package/dist/src/modules/workspace/effects.d.ts +2 -1
  145. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  146. package/dist/src/modules/workspace/effects.js +19 -9
  147. package/dist/src/modules/workspace/effects.js.map +1 -1
  148. package/dist/src/modules/workspace/index.d.ts +214 -42
  149. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  150. package/dist/src/modules/workspace/index.js +667 -113
  151. package/dist/src/modules/workspace/index.js.map +1 -1
  152. package/dist/src/modules/workspace/observe.d.ts +240 -8
  153. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  154. package/dist/src/modules/workspace/observe.js +554 -24
  155. package/dist/src/modules/workspace/observe.js.map +1 -1
  156. package/dist/src/modules/workspace/types.d.ts +10 -1
  157. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  158. package/dist/src/modules/workspace/types.js.map +1 -1
  159. package/dist/src/modules/workspace/watcher.d.ts +42 -0
  160. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  161. package/dist/src/modules/workspace/watcher.js +130 -25
  162. package/dist/src/modules/workspace/watcher.js.map +1 -1
  163. package/dist/src/silent-heartbeat.d.ts +112 -39
  164. package/dist/src/silent-heartbeat.d.ts.map +1 -1
  165. package/dist/src/silent-heartbeat.js +100 -29
  166. package/dist/src/silent-heartbeat.js.map +1 -1
  167. package/dist/src/tool-args.d.ts +40 -0
  168. package/dist/src/tool-args.d.ts.map +1 -0
  169. package/dist/src/tool-args.js +207 -0
  170. package/dist/src/tool-args.js.map +1 -0
  171. package/dist/src/tool-presentation.d.ts.map +1 -1
  172. package/dist/src/tool-presentation.js +9 -2
  173. package/dist/src/tool-presentation.js.map +1 -1
  174. package/dist/src/types/agent.d.ts +27 -17
  175. package/dist/src/types/agent.d.ts.map +1 -1
  176. package/dist/src/types/events.d.ts +8 -0
  177. package/dist/src/types/events.d.ts.map +1 -1
  178. package/dist/src/types/framework.d.ts +17 -2
  179. package/dist/src/types/framework.d.ts.map +1 -1
  180. package/dist/src/types/module.d.ts +54 -10
  181. package/dist/src/types/module.d.ts.map +1 -1
  182. package/dist/src/types/trace.d.ts +2 -2
  183. package/dist/src/types/trace.d.ts.map +1 -1
  184. package/package.json +3 -4
  185. package/src/agent.ts +99 -36
  186. package/src/code-execution/index.ts +1 -0
  187. package/src/code-execution/py-runner.ts +104 -17
  188. package/src/code-execution/runtime-py.ts +47 -7
  189. package/src/code-execution/tool-definition.ts +65 -11
  190. package/src/config-checks.ts +4 -2
  191. package/src/framework.ts +3633 -956
  192. package/src/gate/event-gate.ts +14 -6
  193. package/src/held-writes.ts +59 -0
  194. package/src/index.ts +19 -4
  195. package/src/mcpl/capability-grant.ts +1 -1
  196. package/src/mcpl/channel-registry.ts +613 -160
  197. package/src/mcpl/convert-block.ts +15 -7
  198. package/src/mcpl/index.ts +14 -1
  199. package/src/mcpl/inference-router.ts +8 -7
  200. package/src/mcpl/log-value.ts +10 -0
  201. package/src/mcpl/modern-connection.ts +1182 -0
  202. package/src/mcpl/prefix-rule.ts +32 -0
  203. package/src/mcpl/protocol-family.ts +691 -0
  204. package/src/mcpl/push-coalescer.ts +67 -29
  205. package/src/mcpl/reference-fetcher.ts +288 -82
  206. package/src/mcpl/references.ts +123 -33
  207. package/src/mcpl/server-connection.ts +1050 -221
  208. package/src/mcpl/server-registry.ts +50 -12
  209. package/src/mcpl/tool-result-normalize.ts +294 -0
  210. package/src/mcpl/transport.ts +204 -62
  211. package/src/mcpl/types.ts +67 -20
  212. package/src/mcpl/visible-content.ts +2 -1
  213. package/src/module-registry.ts +68 -13
  214. package/src/modules/api/index.ts +3 -2
  215. package/src/modules/discord/discord-js-client.ts +288 -72
  216. package/src/modules/discord/index.ts +380 -77
  217. package/src/modules/discord/refusal.ts +13 -0
  218. package/src/modules/discord/types.ts +17 -9
  219. package/src/modules/health/index.ts +6 -2
  220. package/src/modules/index.ts +1 -1
  221. package/src/modules/workspace/disk-agreement.ts +46 -5
  222. package/src/modules/workspace/effects.ts +18 -7
  223. package/src/modules/workspace/index.ts +722 -124
  224. package/src/modules/workspace/observe.ts +591 -22
  225. package/src/modules/workspace/types.ts +10 -1
  226. package/src/modules/workspace/watcher.ts +126 -25
  227. package/src/silent-heartbeat.ts +184 -59
  228. package/src/tool-args.ts +213 -0
  229. package/src/tool-presentation.ts +9 -2
  230. package/src/types/agent.ts +27 -17
  231. package/src/types/events.ts +8 -0
  232. package/src/types/framework.ts +17 -2
  233. package/src/types/module.ts +55 -10
  234. package/src/types/trace.ts +2 -2
@@ -5,7 +5,16 @@
5
5
  */
6
6
 
7
7
  import type { ContentBlock } from '@animalabs/membrane';
8
- import { INLINE_WITHHELD_TEXT, isInlineContradiction, referenceStubOrNull } from './references.js';
8
+ import {
9
+ AUDIO_NO_DATA_TEXT,
10
+ AUDIO_NO_MEDIA_TYPE_TEXT,
11
+ IMAGE_NO_DATA_TEXT,
12
+ IMAGE_NO_MEDIA_TYPE_TEXT,
13
+ INLINE_WITHHELD_TEXT,
14
+ isInlineContradiction,
15
+ referenceStubOrNull,
16
+ unknownBlockText,
17
+ } from './references.js';
9
18
  import { NON_STRING_TEXT_PLACEHOLDER } from './visible-content.js';
10
19
  import type { McplContentBlock } from './types.js';
11
20
 
@@ -17,8 +26,8 @@ import type { McplContentBlock } from './types.js';
17
26
  * shows as NON_STRING_TEXT_PLACEHOLDER. `provenance` is what a reference stub
18
27
  * says the reference came on, such as 'attachment on push event'. `serverId`
19
28
  * is the server that sent the content: a reference is registered with it, as
20
- * a tool result's references are, so fetch_reference can fetch it from that
21
- * server.
29
+ * a tool result's references are, so fetch_reference can fetch it through that
30
+ * server's address, where it has one.
22
31
  */
23
32
  export function convertBlock(block: McplContentBlock, provenance: string, serverId: string): ContentBlock {
24
33
  switch (block.type) {
@@ -51,7 +60,7 @@ export function convertBlock(block: McplContentBlock, provenance: string, server
51
60
  source: { type: 'url', url: block.uri },
52
61
  } as ContentBlock;
53
62
  }
54
- return { type: 'text', text: isFilledString(block.data) ? '[Image: no media type]' : '[Image: no data]' };
63
+ return { type: 'text', text: isFilledString(block.data) ? IMAGE_NO_MEDIA_TYPE_TEXT : IMAGE_NO_DATA_TEXT };
55
64
 
56
65
  case 'audio':
57
66
  if (isInlineContradiction(block)) {
@@ -70,7 +79,7 @@ export function convertBlock(block: McplContentBlock, provenance: string, server
70
79
  source: { type: 'base64', data: block.data, mediaType: block.mimeType },
71
80
  } as ContentBlock;
72
81
  }
73
- return { type: 'text', text: isFilledString(block.data) ? '[Audio: no media type]' : '[Audio: no data]' };
82
+ return { type: 'text', text: isFilledString(block.data) ? AUDIO_NO_MEDIA_TYPE_TEXT : AUDIO_NO_DATA_TEXT };
74
83
 
75
84
  case 'resource':
76
85
  // RFC-005: reference blocks become bounded stubs — never raw URIs
@@ -82,8 +91,7 @@ export function convertBlock(block: McplContentBlock, provenance: string, server
82
91
  // and propagated `undefined` into ContentBlock[]. Fail visibly. A type
83
92
  // that isn't a string is no type, and is never converted to one: an
84
93
  // object can throw when it is.
85
- const type: unknown = (block as { type?: unknown }).type;
86
- return { type: 'text', text: `[unrecognized content block: ${typeof type === 'string' ? type : 'untyped'}]` };
94
+ return { type: 'text', text: unknownBlockText(block) };
87
95
  }
88
96
  }
89
97
  }
package/src/mcpl/index.ts CHANGED
@@ -106,9 +106,22 @@ export {
106
106
  } from './errors.js';
107
107
 
108
108
  // Server connection and registry
109
- export { McplServerConnection, McplRequestError } from './server-connection.js';
109
+ export { McplServerConnection, McplRequestError, McplProtocolVersionError, McplUnreapedLaunchError } from './server-connection.js';
110
110
  export type { McplConnectionCloseInfo } from './server-connection.js';
111
111
  export type { TransportCloseInfo } from './transport.js';
112
+ export { ModernMcpConnection } from './modern-connection.js';
113
+ export type { ModernToolCallResult } from './modern-connection.js';
114
+ export {
115
+ LEGACY_MCP_PROTOCOL_VERSION,
116
+ MODERN_MCP_PROTOCOL_VERSION,
117
+ MAX_TIMER_MS,
118
+ mcplPolicyGrants,
119
+ resolveServerBinding,
120
+ serverConfigProblems,
121
+ serverConfigWarnings,
122
+ checkServerConfig,
123
+ } from './protocol-family.js';
124
+ export type { McpProtocolFamily, McpTransportKind, ServerBinding } from './protocol-family.js';
112
125
  export { McplServerRegistry, type McplCapabilityQuery } from './server-registry.js';
113
126
 
114
127
  // Feature set management (permission layer)
@@ -37,6 +37,9 @@ interface Responder {
37
37
  respondError(code: number, message: string, data?: unknown): void;
38
38
  /** The JSON-RPC request ID, used for streaming chunk correlation. */
39
39
  requestId?: string | number;
40
+ /** Sends a streamed chunk on the transport the request came on, as its
41
+ * answer is sent. */
42
+ sendChunk?(params: InferenceChunkParams): void;
40
43
  }
41
44
 
42
45
  // ============================================================================
@@ -178,7 +181,6 @@ export class InferenceRouter {
178
181
  private featureSetManager: FeatureSetManager;
179
182
  private routingPolicy: InferenceRoutingPolicy | null;
180
183
  private emitTraceFn: (event: { type: string; [key: string]: unknown }) => void;
181
- private sendChunkFn?: (serverId: string, params: InferenceChunkParams) => void;
182
184
 
183
185
  constructor(
184
186
  membrane: Membrane,
@@ -186,14 +188,12 @@ export class InferenceRouter {
186
188
  featureSetManager: FeatureSetManager,
187
189
  routingPolicy: InferenceRoutingPolicy | null,
188
190
  emitTraceFn: (event: { type: string; [key: string]: unknown }) => void,
189
- sendChunkFn?: (serverId: string, params: InferenceChunkParams) => void,
190
191
  ) {
191
192
  this.membrane = membrane;
192
193
  this.hookOrchestrator = hookOrchestrator;
193
194
  this.featureSetManager = featureSetManager;
194
195
  this.routingPolicy = routingPolicy;
195
196
  this.emitTraceFn = emitTraceFn;
196
- this.sendChunkFn = sendChunkFn;
197
197
  }
198
198
 
199
199
  /**
@@ -265,14 +265,15 @@ export class InferenceRouter {
265
265
 
266
266
  // Streaming needs a way to send chunks and an id to tag them with;
267
267
  // without either, the request is answered whole.
268
- const chunkRequestId = params.stream && this.sendChunkFn ? responder.requestId : undefined;
268
+ const sendChunk = params.stream ? responder.sendChunk?.bind(responder) : undefined;
269
+ const chunkRequestId = sendChunk ? responder.requestId : undefined;
269
270
  const streamed = chunkRequestId != null;
270
271
 
271
272
  try {
272
273
  // 5. Run inference. Both modes end in membrane's response, and one
273
274
  // builder makes the result from it.
274
275
  const response = chunkRequestId != null
275
- ? await this.streamResponse(serverId, request, chunkRequestId)
276
+ ? await this.streamResponse(request, chunkRequestId, sendChunk!)
276
277
  : await this.membrane.complete(request);
277
278
 
278
279
  // 6. Answer
@@ -375,9 +376,9 @@ export class InferenceRouter {
375
376
  * so nothing keeps running once the request is answered.
376
377
  */
377
378
  private async streamResponse(
378
- serverId: string,
379
379
  request: NormalizedRequest,
380
380
  requestId: string | number,
381
+ sendChunk: (params: InferenceChunkParams) => void,
381
382
  ): Promise<NormalizedResponse> {
382
383
  const stream = this.membrane.streamYielding(request);
383
384
  let index = 0;
@@ -392,7 +393,7 @@ export class InferenceRouter {
392
393
  // naming a tag the stream parser opens a block for, or a thinking
393
394
  // block cut off before its close tag.
394
395
  if (event.meta.visible) {
395
- this.sendChunkFn!(serverId, { requestId, index: index++, delta: event.content });
396
+ sendChunk({ requestId, index: index++, delta: event.content });
396
397
  }
397
398
  break;
398
399
  case 'tool-calls':
@@ -45,6 +45,16 @@ export function logValue(value: unknown): string {
45
45
  return printed(textOf(value), FIELD);
46
46
  }
47
47
 
48
+ /**
49
+ * `logValue` of a value a server chose whose text may hold a credential:
50
+ * its text, as logValue reads it (a JSON value as its JSON text), with
51
+ * `redact` applied, then printed as logValue prints a field. A value whose
52
+ * text holds nothing `redact` replaces prints exactly as logValue prints it.
53
+ */
54
+ export function logValueRedacted(value: unknown, redact: (text: string) => string): string {
55
+ return printed(redact(textOf(value)), FIELD);
56
+ }
57
+
48
58
  /**
49
59
  * The host's own message, as the free text that ends a log line after its
50
60
  * fields: `reason=coalesce-invalid field=payload.content: "content must be an