agent-framework-js 0.3.0 → 0.4.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 (49) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +50 -0
  3. package/dist/agents/index.cjs +4 -4
  4. package/dist/agents/index.js +1 -1
  5. package/dist/{chunk-PYIZ4PT3.js → chunk-3KU76DCP.js} +3 -3
  6. package/dist/{chunk-PYIZ4PT3.js.map → chunk-3KU76DCP.js.map} +1 -1
  7. package/dist/{chunk-FDCTSJMB.cjs → chunk-4RGMZII7.cjs} +60 -23
  8. package/dist/chunk-4RGMZII7.cjs.map +1 -0
  9. package/dist/{chunk-IHMPSELC.cjs → chunk-5KC6X2T5.cjs} +5 -5
  10. package/dist/{chunk-IHMPSELC.cjs.map → chunk-5KC6X2T5.cjs.map} +1 -1
  11. package/dist/{chunk-55NB43FN.js → chunk-7S75TBCI.js} +3 -3
  12. package/dist/{chunk-55NB43FN.js.map → chunk-7S75TBCI.js.map} +1 -1
  13. package/dist/{chunk-2WBJEXNY.cjs → chunk-IIANZWIQ.cjs} +4 -4
  14. package/dist/{chunk-2WBJEXNY.cjs.map → chunk-IIANZWIQ.cjs.map} +1 -1
  15. package/dist/{chunk-XMDGLQFL.cjs → chunk-JLPLGU7O.cjs} +15 -3
  16. package/dist/chunk-JLPLGU7O.cjs.map +1 -0
  17. package/dist/{chunk-FOTCUNP5.cjs → chunk-N64ZFATA.cjs} +5 -2
  18. package/dist/chunk-N64ZFATA.cjs.map +1 -0
  19. package/dist/{chunk-ACBIHS5H.js → chunk-QXAJ4DUJ.js} +5 -2
  20. package/dist/chunk-QXAJ4DUJ.js.map +1 -0
  21. package/dist/{chunk-YH5746OF.js → chunk-QYG4HLIC.js} +3 -3
  22. package/dist/{chunk-YH5746OF.js.map → chunk-QYG4HLIC.js.map} +1 -1
  23. package/dist/{chunk-GYDY3KX5.cjs → chunk-U3ULJMNH.cjs} +4 -4
  24. package/dist/{chunk-GYDY3KX5.cjs.map → chunk-U3ULJMNH.cjs.map} +1 -1
  25. package/dist/{chunk-KOPGBIES.js → chunk-YSJG2MHD.js} +60 -23
  26. package/dist/chunk-YSJG2MHD.js.map +1 -0
  27. package/dist/{chunk-QD2FFISV.js → chunk-YVJGF4HQ.js} +16 -4
  28. package/dist/chunk-YVJGF4HQ.js.map +1 -0
  29. package/dist/declarative/index.cjs +3 -3
  30. package/dist/declarative/index.js +2 -2
  31. package/dist/index.cjs +38 -38
  32. package/dist/index.d.cts +5 -0
  33. package/dist/index.d.ts +5 -0
  34. package/dist/index.js +7 -7
  35. package/dist/mcp/index.cjs +4 -4
  36. package/dist/mcp/index.js +2 -2
  37. package/dist/persistence/index.cjs +5 -5
  38. package/dist/persistence/index.js +2 -2
  39. package/dist/providers/index.cjs +7 -6
  40. package/dist/providers/index.d.cts +10 -0
  41. package/dist/providers/index.d.ts +10 -0
  42. package/dist/providers/index.js +2 -1
  43. package/package.json +7 -7
  44. package/dist/chunk-ACBIHS5H.js.map +0 -1
  45. package/dist/chunk-FDCTSJMB.cjs.map +0 -1
  46. package/dist/chunk-FOTCUNP5.cjs.map +0 -1
  47. package/dist/chunk-KOPGBIES.js.map +0 -1
  48. package/dist/chunk-QD2FFISV.js.map +0 -1
  49. package/dist/chunk-XMDGLQFL.cjs.map +0 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk2WBJEXNY_cjs = require('../chunk-2WBJEXNY.cjs');
4
- require('../chunk-FDCTSJMB.cjs');
3
+ var chunkIIANZWIQ_cjs = require('../chunk-IIANZWIQ.cjs');
4
+ require('../chunk-4RGMZII7.cjs');
5
5
  require('../chunk-WSMYH2IN.cjs');
6
6
  require('../chunk-TAMJ5HSR.cjs');
7
7
  require('../chunk-FSDMBWQV.cjs');
@@ -13,7 +13,7 @@ require('../chunk-IJASUMIQ.cjs');
13
13
 
14
14
  Object.defineProperty(exports, "loadAgentDefinition", {
15
15
  enumerable: true,
16
- get: function () { return chunk2WBJEXNY_cjs.loadAgentDefinition; }
16
+ get: function () { return chunkIIANZWIQ_cjs.loadAgentDefinition; }
17
17
  });
18
18
  //# sourceMappingURL=index.cjs.map
19
19
  //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
- export { loadAgentDefinition } from '../chunk-55NB43FN.js';
2
- import '../chunk-KOPGBIES.js';
1
+ export { loadAgentDefinition } from '../chunk-7S75TBCI.js';
2
+ import '../chunk-YSJG2MHD.js';
3
3
  import '../chunk-YCBDEEAV.js';
4
4
  import '../chunk-HGEPXJDG.js';
5
5
  import '../chunk-7ZXUIHLH.js';
package/dist/index.cjs CHANGED
@@ -3,18 +3,18 @@
3
3
  var chunkIU3LS5FC_cjs = require('./chunk-IU3LS5FC.cjs');
4
4
  var chunkRZP2ZUUX_cjs = require('./chunk-RZP2ZUUX.cjs');
5
5
  require('./chunk-5M6ER4ZX.cjs');
6
- var chunk2WBJEXNY_cjs = require('./chunk-2WBJEXNY.cjs');
7
- var chunkFDCTSJMB_cjs = require('./chunk-FDCTSJMB.cjs');
6
+ var chunkIIANZWIQ_cjs = require('./chunk-IIANZWIQ.cjs');
7
+ var chunk4RGMZII7_cjs = require('./chunk-4RGMZII7.cjs');
8
8
  var chunkWSMYH2IN_cjs = require('./chunk-WSMYH2IN.cjs');
9
9
  var chunkTAMJ5HSR_cjs = require('./chunk-TAMJ5HSR.cjs');
10
+ var chunkU3ULJMNH_cjs = require('./chunk-U3ULJMNH.cjs');
11
+ var chunkV6O6SYAN_cjs = require('./chunk-V6O6SYAN.cjs');
10
12
  var chunkKEI3EALJ_cjs = require('./chunk-KEI3EALJ.cjs');
11
13
  var chunkFSDMBWQV_cjs = require('./chunk-FSDMBWQV.cjs');
12
- var chunkV6O6SYAN_cjs = require('./chunk-V6O6SYAN.cjs');
13
- var chunkGYDY3KX5_cjs = require('./chunk-GYDY3KX5.cjs');
14
- var chunkIHMPSELC_cjs = require('./chunk-IHMPSELC.cjs');
14
+ var chunk5KC6X2T5_cjs = require('./chunk-5KC6X2T5.cjs');
15
15
  var chunkI55OVD23_cjs = require('./chunk-I55OVD23.cjs');
16
- var chunkFOTCUNP5_cjs = require('./chunk-FOTCUNP5.cjs');
17
- var chunkXMDGLQFL_cjs = require('./chunk-XMDGLQFL.cjs');
16
+ var chunkJLPLGU7O_cjs = require('./chunk-JLPLGU7O.cjs');
17
+ var chunkN64ZFATA_cjs = require('./chunk-N64ZFATA.cjs');
18
18
  var chunkMQ2XTH3S_cjs = require('./chunk-MQ2XTH3S.cjs');
19
19
  var chunkIJASUMIQ_cjs = require('./chunk-IJASUMIQ.cjs');
20
20
 
@@ -66,19 +66,19 @@ Object.defineProperty(exports, "stepSequential", {
66
66
  });
67
67
  Object.defineProperty(exports, "loadAgentDefinition", {
68
68
  enumerable: true,
69
- get: function () { return chunk2WBJEXNY_cjs.loadAgentDefinition; }
69
+ get: function () { return chunkIIANZWIQ_cjs.loadAgentDefinition; }
70
70
  });
71
71
  Object.defineProperty(exports, "buildMessages", {
72
72
  enumerable: true,
73
- get: function () { return chunkFDCTSJMB_cjs.buildMessages; }
73
+ get: function () { return chunk4RGMZII7_cjs.buildMessages; }
74
74
  });
75
75
  Object.defineProperty(exports, "createAgent", {
76
76
  enumerable: true,
77
- get: function () { return chunkFDCTSJMB_cjs.createAgent; }
77
+ get: function () { return chunk4RGMZII7_cjs.createAgent; }
78
78
  });
79
79
  Object.defineProperty(exports, "runLoop", {
80
80
  enumerable: true,
81
- get: function () { return chunkFDCTSJMB_cjs.runLoop; }
81
+ get: function () { return chunk4RGMZII7_cjs.runLoop; }
82
82
  });
83
83
  Object.defineProperty(exports, "SkillIndex", {
84
84
  enumerable: true,
@@ -104,13 +104,13 @@ Object.defineProperty(exports, "validateArgs", {
104
104
  enumerable: true,
105
105
  get: function () { return chunkTAMJ5HSR_cjs.validateArgs; }
106
106
  });
107
- Object.defineProperty(exports, "useMiddleware", {
107
+ Object.defineProperty(exports, "connectMCP", {
108
108
  enumerable: true,
109
- get: function () { return chunkKEI3EALJ_cjs.useMiddleware; }
109
+ get: function () { return chunkU3ULJMNH_cjs.connectMCP; }
110
110
  });
111
- Object.defineProperty(exports, "composeMiddleware", {
111
+ Object.defineProperty(exports, "mcpToolToTool", {
112
112
  enumerable: true,
113
- get: function () { return chunkFSDMBWQV_cjs.composeMiddleware; }
113
+ get: function () { return chunkU3ULJMNH_cjs.mcpToolToTool; }
114
114
  });
115
115
  Object.defineProperty(exports, "configureObservability", {
116
116
  enumerable: true,
@@ -128,25 +128,25 @@ Object.defineProperty(exports, "withSpan", {
128
128
  enumerable: true,
129
129
  get: function () { return chunkV6O6SYAN_cjs.withSpan; }
130
130
  });
131
- Object.defineProperty(exports, "connectMCP", {
131
+ Object.defineProperty(exports, "useMiddleware", {
132
132
  enumerable: true,
133
- get: function () { return chunkGYDY3KX5_cjs.connectMCP; }
133
+ get: function () { return chunkKEI3EALJ_cjs.useMiddleware; }
134
134
  });
135
- Object.defineProperty(exports, "mcpToolToTool", {
135
+ Object.defineProperty(exports, "composeMiddleware", {
136
136
  enumerable: true,
137
- get: function () { return chunkGYDY3KX5_cjs.mcpToolToTool; }
137
+ get: function () { return chunkFSDMBWQV_cjs.composeMiddleware; }
138
138
  });
139
139
  Object.defineProperty(exports, "ThreadPersistence", {
140
140
  enumerable: true,
141
- get: function () { return chunkIHMPSELC_cjs.ThreadPersistence; }
141
+ get: function () { return chunk5KC6X2T5_cjs.ThreadPersistence; }
142
142
  });
143
143
  Object.defineProperty(exports, "createBrowserStore", {
144
144
  enumerable: true,
145
- get: function () { return chunkIHMPSELC_cjs.createBrowserStore; }
145
+ get: function () { return chunk5KC6X2T5_cjs.createBrowserStore; }
146
146
  });
147
147
  Object.defineProperty(exports, "createMemoryStore", {
148
148
  enumerable: true,
149
- get: function () { return chunkIHMPSELC_cjs.createMemoryStore; }
149
+ get: function () { return chunk5KC6X2T5_cjs.createMemoryStore; }
150
150
  });
151
151
  Object.defineProperty(exports, "Thread", {
152
152
  enumerable: true,
@@ -168,37 +168,37 @@ Object.defineProperty(exports, "textMessage", {
168
168
  enumerable: true,
169
169
  get: function () { return chunkI55OVD23_cjs.textMessage; }
170
170
  });
171
- Object.defineProperty(exports, "detectRuntime", {
171
+ Object.defineProperty(exports, "createCopilotProvider", {
172
172
  enumerable: true,
173
- get: function () { return chunkFOTCUNP5_cjs.detectRuntime; }
173
+ get: function () { return chunkJLPLGU7O_cjs.createCopilotProvider; }
174
174
  });
175
- Object.defineProperty(exports, "requireCapability", {
175
+ Object.defineProperty(exports, "createOpenAICompatibleProvider", {
176
176
  enumerable: true,
177
- get: function () { return chunkFOTCUNP5_cjs.requireCapability; }
177
+ get: function () { return chunkJLPLGU7O_cjs.createOpenAICompatibleProvider; }
178
178
  });
179
- Object.defineProperty(exports, "resetRuntimeCache", {
179
+ Object.defineProperty(exports, "providerErrorFromStatus", {
180
180
  enumerable: true,
181
- get: function () { return chunkFOTCUNP5_cjs.resetRuntimeCache; }
181
+ get: function () { return chunkJLPLGU7O_cjs.providerErrorFromStatus; }
182
182
  });
183
- Object.defineProperty(exports, "createCopilotProvider", {
183
+ Object.defineProperty(exports, "resolveModels", {
184
184
  enumerable: true,
185
- get: function () { return chunkXMDGLQFL_cjs.createCopilotProvider; }
185
+ get: function () { return chunkJLPLGU7O_cjs.resolveModels; }
186
186
  });
187
- Object.defineProperty(exports, "createOpenAICompatibleProvider", {
187
+ Object.defineProperty(exports, "withRetry", {
188
188
  enumerable: true,
189
- get: function () { return chunkXMDGLQFL_cjs.createOpenAICompatibleProvider; }
189
+ get: function () { return chunkJLPLGU7O_cjs.withRetry; }
190
190
  });
191
- Object.defineProperty(exports, "providerErrorFromStatus", {
191
+ Object.defineProperty(exports, "detectRuntime", {
192
192
  enumerable: true,
193
- get: function () { return chunkXMDGLQFL_cjs.providerErrorFromStatus; }
193
+ get: function () { return chunkN64ZFATA_cjs.detectRuntime; }
194
194
  });
195
- Object.defineProperty(exports, "resolveModels", {
195
+ Object.defineProperty(exports, "requireCapability", {
196
196
  enumerable: true,
197
- get: function () { return chunkXMDGLQFL_cjs.resolveModels; }
197
+ get: function () { return chunkN64ZFATA_cjs.requireCapability; }
198
198
  });
199
- Object.defineProperty(exports, "withRetry", {
199
+ Object.defineProperty(exports, "resetRuntimeCache", {
200
200
  enumerable: true,
201
- get: function () { return chunkXMDGLQFL_cjs.withRetry; }
201
+ get: function () { return chunkN64ZFATA_cjs.resetRuntimeCache; }
202
202
  });
203
203
  Object.defineProperty(exports, "CheckpointError", {
204
204
  enumerable: true,
package/dist/index.d.cts CHANGED
@@ -34,6 +34,11 @@ interface RuntimeCapabilities {
34
34
  hasIndexedDB: boolean;
35
35
  /** Running under Node.js. */
36
36
  isNode: boolean;
37
+ /**
38
+ * Running inside a web browser (has `window`/`document`). Distinguished from
39
+ * edge runtimes, which also lack Node but make server-side (CORS-free) requests.
40
+ */
41
+ isBrowser: boolean;
37
42
  }
38
43
  /** Detect the current runtime's capabilities (memoized). */
39
44
  declare function detectRuntime(): RuntimeCapabilities;
package/dist/index.d.ts CHANGED
@@ -34,6 +34,11 @@ interface RuntimeCapabilities {
34
34
  hasIndexedDB: boolean;
35
35
  /** Running under Node.js. */
36
36
  isNode: boolean;
37
+ /**
38
+ * Running inside a web browser (has `window`/`document`). Distinguished from
39
+ * edge runtimes, which also lack Node but make server-side (CORS-free) requests.
40
+ */
41
+ isBrowser: boolean;
37
42
  }
38
43
  /** Detect the current runtime's capabilities (memoized). */
39
44
  declare function detectRuntime(): RuntimeCapabilities;
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  export { defineTool } from './chunk-RZ43WNHR.js';
2
2
  export { CHECKPOINT_VERSION, createCheckpoint, createWorkflow, restoreCheckpoint, runBounded, serializeCheckpoint, stepConcurrent, stepGroup, stepHandoff, stepSequential } from './chunk-T2GHJ5R4.js';
3
3
  import './chunk-MCLVWCOB.js';
4
- export { loadAgentDefinition } from './chunk-55NB43FN.js';
5
- export { buildMessages, createAgent, runLoop } from './chunk-KOPGBIES.js';
4
+ export { loadAgentDefinition } from './chunk-7S75TBCI.js';
5
+ export { buildMessages, createAgent, runLoop } from './chunk-YSJG2MHD.js';
6
6
  export { SkillIndex, defineSkill, loadSource } from './chunk-YCBDEEAV.js';
7
7
  export { ToolRegistry, namespacedName, validateArgs } from './chunk-HGEPXJDG.js';
8
+ export { connectMCP, mcpToolToTool } from './chunk-QYG4HLIC.js';
9
+ export { configureObservability, isObservabilityEnabled, resetObservability, withSpan } from './chunk-5PDJOBTD.js';
8
10
  export { useMiddleware } from './chunk-IUKD54F7.js';
9
11
  export { composeMiddleware } from './chunk-7ZXUIHLH.js';
10
- export { configureObservability, isObservabilityEnabled, resetObservability, withSpan } from './chunk-5PDJOBTD.js';
11
- export { connectMCP, mcpToolToTool } from './chunk-YH5746OF.js';
12
- export { ThreadPersistence, createBrowserStore, createMemoryStore } from './chunk-PYIZ4PT3.js';
12
+ export { ThreadPersistence, createBrowserStore, createMemoryStore } from './chunk-3KU76DCP.js';
13
13
  export { Thread, estimateTokens, hasImage, messageText, textMessage } from './chunk-LC54DGGR.js';
14
- export { detectRuntime, requireCapability, resetRuntimeCache } from './chunk-ACBIHS5H.js';
15
- export { createCopilotProvider, createOpenAICompatibleProvider, providerErrorFromStatus, resolveModels, withRetry } from './chunk-QD2FFISV.js';
14
+ export { createCopilotProvider, createOpenAICompatibleProvider, providerErrorFromStatus, resolveModels, withRetry } from './chunk-YVJGF4HQ.js';
15
+ export { detectRuntime, requireCapability, resetRuntimeCache } from './chunk-QXAJ4DUJ.js';
16
16
  export { CheckpointError, FrameworkError, MCPError, ProviderError, RuntimeUnsupportedError, ToolError, ValidationError } from './chunk-IXV4UIF5.js';
17
17
  export { REDACTED, redact } from './chunk-DEABART4.js';
18
18
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkGYDY3KX5_cjs = require('../chunk-GYDY3KX5.cjs');
4
- require('../chunk-FOTCUNP5.cjs');
3
+ var chunkU3ULJMNH_cjs = require('../chunk-U3ULJMNH.cjs');
4
+ require('../chunk-N64ZFATA.cjs');
5
5
  require('../chunk-MQ2XTH3S.cjs');
6
6
  require('../chunk-IJASUMIQ.cjs');
7
7
 
@@ -9,11 +9,11 @@ require('../chunk-IJASUMIQ.cjs');
9
9
 
10
10
  Object.defineProperty(exports, "connectMCP", {
11
11
  enumerable: true,
12
- get: function () { return chunkGYDY3KX5_cjs.connectMCP; }
12
+ get: function () { return chunkU3ULJMNH_cjs.connectMCP; }
13
13
  });
14
14
  Object.defineProperty(exports, "mcpToolToTool", {
15
15
  enumerable: true,
16
- get: function () { return chunkGYDY3KX5_cjs.mcpToolToTool; }
16
+ get: function () { return chunkU3ULJMNH_cjs.mcpToolToTool; }
17
17
  });
18
18
  //# sourceMappingURL=index.cjs.map
19
19
  //# sourceMappingURL=index.cjs.map
package/dist/mcp/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { connectMCP, mcpToolToTool } from '../chunk-YH5746OF.js';
2
- import '../chunk-ACBIHS5H.js';
1
+ export { connectMCP, mcpToolToTool } from '../chunk-QYG4HLIC.js';
2
+ import '../chunk-QXAJ4DUJ.js';
3
3
  import '../chunk-IXV4UIF5.js';
4
4
  import '../chunk-DEABART4.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkIHMPSELC_cjs = require('../chunk-IHMPSELC.cjs');
3
+ var chunk5KC6X2T5_cjs = require('../chunk-5KC6X2T5.cjs');
4
4
  require('../chunk-I55OVD23.cjs');
5
- require('../chunk-FOTCUNP5.cjs');
5
+ require('../chunk-N64ZFATA.cjs');
6
6
  require('../chunk-MQ2XTH3S.cjs');
7
7
  require('../chunk-IJASUMIQ.cjs');
8
8
 
@@ -10,15 +10,15 @@ require('../chunk-IJASUMIQ.cjs');
10
10
 
11
11
  Object.defineProperty(exports, "ThreadPersistence", {
12
12
  enumerable: true,
13
- get: function () { return chunkIHMPSELC_cjs.ThreadPersistence; }
13
+ get: function () { return chunk5KC6X2T5_cjs.ThreadPersistence; }
14
14
  });
15
15
  Object.defineProperty(exports, "createBrowserStore", {
16
16
  enumerable: true,
17
- get: function () { return chunkIHMPSELC_cjs.createBrowserStore; }
17
+ get: function () { return chunk5KC6X2T5_cjs.createBrowserStore; }
18
18
  });
19
19
  Object.defineProperty(exports, "createMemoryStore", {
20
20
  enumerable: true,
21
- get: function () { return chunkIHMPSELC_cjs.createMemoryStore; }
21
+ get: function () { return chunk5KC6X2T5_cjs.createMemoryStore; }
22
22
  });
23
23
  //# sourceMappingURL=index.cjs.map
24
24
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,6 @@
1
- export { ThreadPersistence, createBrowserStore, createMemoryStore } from '../chunk-PYIZ4PT3.js';
1
+ export { ThreadPersistence, createBrowserStore, createMemoryStore } from '../chunk-3KU76DCP.js';
2
2
  import '../chunk-LC54DGGR.js';
3
- import '../chunk-ACBIHS5H.js';
3
+ import '../chunk-QXAJ4DUJ.js';
4
4
  import '../chunk-IXV4UIF5.js';
5
5
  import '../chunk-DEABART4.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkXMDGLQFL_cjs = require('../chunk-XMDGLQFL.cjs');
3
+ var chunkJLPLGU7O_cjs = require('../chunk-JLPLGU7O.cjs');
4
+ require('../chunk-N64ZFATA.cjs');
4
5
  require('../chunk-MQ2XTH3S.cjs');
5
6
  require('../chunk-IJASUMIQ.cjs');
6
7
 
@@ -8,23 +9,23 @@ require('../chunk-IJASUMIQ.cjs');
8
9
 
9
10
  Object.defineProperty(exports, "createCopilotProvider", {
10
11
  enumerable: true,
11
- get: function () { return chunkXMDGLQFL_cjs.createCopilotProvider; }
12
+ get: function () { return chunkJLPLGU7O_cjs.createCopilotProvider; }
12
13
  });
13
14
  Object.defineProperty(exports, "createOpenAICompatibleProvider", {
14
15
  enumerable: true,
15
- get: function () { return chunkXMDGLQFL_cjs.createOpenAICompatibleProvider; }
16
+ get: function () { return chunkJLPLGU7O_cjs.createOpenAICompatibleProvider; }
16
17
  });
17
18
  Object.defineProperty(exports, "providerErrorFromStatus", {
18
19
  enumerable: true,
19
- get: function () { return chunkXMDGLQFL_cjs.providerErrorFromStatus; }
20
+ get: function () { return chunkJLPLGU7O_cjs.providerErrorFromStatus; }
20
21
  });
21
22
  Object.defineProperty(exports, "resolveModels", {
22
23
  enumerable: true,
23
- get: function () { return chunkXMDGLQFL_cjs.resolveModels; }
24
+ get: function () { return chunkJLPLGU7O_cjs.resolveModels; }
24
25
  });
25
26
  Object.defineProperty(exports, "withRetry", {
26
27
  enumerable: true,
27
- get: function () { return chunkXMDGLQFL_cjs.withRetry; }
28
+ get: function () { return chunkJLPLGU7O_cjs.withRetry; }
28
29
  });
29
30
  //# sourceMappingURL=index.cjs.map
30
31
  //# sourceMappingURL=index.cjs.map
@@ -99,6 +99,11 @@ declare function createOpenAICompatibleProvider(options: OpenAICompatibleProvide
99
99
  * client-side); in a backend deployment the developer may supply it, or the user
100
100
  * sends it per request over SSL/TLS and the backend must not log or persist it.
101
101
  *
102
+ * Note: the Copilot API (`api.githubcopilot.com`) sends no CORS headers, so it
103
+ * cannot be called directly from a browser. A browser deployment must route through
104
+ * a backend/proxy (set `baseUrl` to it); constructing this provider in a browser
105
+ * against the default host throws {@link RuntimeUnsupportedError}.
106
+ *
102
107
  * @packageDocumentation
103
108
  */
104
109
 
@@ -145,6 +150,11 @@ interface CopilotProviderOptions extends CredentialSource, ModelSelectionOptions
145
150
  * });
146
151
  * // Pick a model per request: provider.generate({ messages, model: "o3-mini" })
147
152
  * ```
153
+ *
154
+ * @throws {RuntimeUnsupportedError} when constructed in a browser against the
155
+ * default Copilot host. `api.githubcopilot.com` does not send CORS headers, so a
156
+ * browser cannot call it directly — host a small backend/proxy and point `baseUrl`
157
+ * at it (which lifts this guard), or run the provider server-side (Node/edge).
148
158
  */
149
159
  declare function createCopilotProvider(options: CopilotProviderOptions): Provider;
150
160
 
@@ -99,6 +99,11 @@ declare function createOpenAICompatibleProvider(options: OpenAICompatibleProvide
99
99
  * client-side); in a backend deployment the developer may supply it, or the user
100
100
  * sends it per request over SSL/TLS and the backend must not log or persist it.
101
101
  *
102
+ * Note: the Copilot API (`api.githubcopilot.com`) sends no CORS headers, so it
103
+ * cannot be called directly from a browser. A browser deployment must route through
104
+ * a backend/proxy (set `baseUrl` to it); constructing this provider in a browser
105
+ * against the default host throws {@link RuntimeUnsupportedError}.
106
+ *
102
107
  * @packageDocumentation
103
108
  */
104
109
 
@@ -145,6 +150,11 @@ interface CopilotProviderOptions extends CredentialSource, ModelSelectionOptions
145
150
  * });
146
151
  * // Pick a model per request: provider.generate({ messages, model: "o3-mini" })
147
152
  * ```
153
+ *
154
+ * @throws {RuntimeUnsupportedError} when constructed in a browser against the
155
+ * default Copilot host. `api.githubcopilot.com` does not send CORS headers, so a
156
+ * browser cannot call it directly — host a small backend/proxy and point `baseUrl`
157
+ * at it (which lifts this guard), or run the provider server-side (Node/edge).
148
158
  */
149
159
  declare function createCopilotProvider(options: CopilotProviderOptions): Provider;
150
160
 
@@ -1,4 +1,5 @@
1
- export { createCopilotProvider, createOpenAICompatibleProvider, providerErrorFromStatus, resolveModels, withRetry } from '../chunk-QD2FFISV.js';
1
+ export { createCopilotProvider, createOpenAICompatibleProvider, providerErrorFromStatus, resolveModels, withRetry } from '../chunk-YVJGF4HQ.js';
2
+ import '../chunk-QXAJ4DUJ.js';
2
3
  import '../chunk-IXV4UIF5.js';
3
4
  import '../chunk-DEABART4.js';
4
5
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-framework-js",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Modular, tree-shakeable JavaScript/TypeScript agent framework for no-backend deployments (browser, edge, Node). Agents, tools, MCP, skills, multi-agent workflows, middleware, persistence, and OpenTelemetry observability.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -130,16 +130,16 @@
130
130
  }
131
131
  },
132
132
  "devDependencies": {
133
+ "@eslint/js": "^10.0.0",
133
134
  "@modelcontextprotocol/sdk": "^1.0.0",
134
135
  "@opentelemetry/api": "^1.9.0",
135
- "@types/node": "^20.14.0",
136
- "@typescript-eslint/eslint-plugin": "^7.16.0",
137
- "@typescript-eslint/parser": "^7.16.0",
138
- "eslint": "^8.57.0",
136
+ "@types/node": "^25.0.0",
137
+ "eslint": "^10.0.0",
139
138
  "prettier": "^3.3.0",
140
139
  "tsup": "^8.2.0",
141
- "typescript": "^5.5.0",
142
- "vitest": "^2.0.0",
140
+ "typescript": "^6.0.0",
141
+ "typescript-eslint": "^8.61.0",
142
+ "vitest": "^4.0.0",
143
143
  "yaml": "^2.5.0"
144
144
  }
145
145
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/runtime.ts"],"names":[],"mappings":";;;AAuBA,IAAI,MAAA;AAGG,SAAS,aAAA,GAAqC;AACpD,EAAA,IAAI,QAAQ,OAAO,MAAA;AAEnB,EAAA,MAAM,CAAA,GAAI,UAAA;AACV,EAAA,MAAM,IAAA,GAAO,EAAE,SAAS,CAAA;AACxB,EAAA,MAAM,SAAS,OAAO,IAAA,KAAS,eAAe,CAAC,CAAC,KAAK,QAAA,EAAU,IAAA;AAE/D,EAAA,MAAA,GAAS;AAAA,IACR,MAAA;AAAA;AAAA,IAEA,eAAA,EAAiB,MAAA;AAAA,IACjB,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,CAAA,KAAM,WAAA;AAAA,IAC9C,YAAA,EAAc,OAAO,CAAA,CAAE,WAAW,CAAA,KAAM;AAAA,GACzC;AACA,EAAA,OAAO,MAAA;AACR;AASO,SAAS,iBAAA,CACf,YACA,OAAA,EACO;AACP,EAAA,IAAI,CAAC,aAAA,EAAc,CAAE,UAAU,CAAA,EAAG;AACjC,IAAA,MAAM,IAAI,uBAAA,CAAwB,OAAA,EAAS,EAAE,YAAY,CAAA;AAAA,EAC1D;AACD;AAGO,SAAS,iBAAA,GAA0B;AACzC,EAAA,MAAA,GAAS,MAAA;AACV","file":"chunk-ACBIHS5H.js","sourcesContent":["/**\n * Runtime capability detection. The framework runs in browsers, edge runtimes,\n * and Node. Features that need Node-only APIs (process spawning, filesystem) are\n * gated behind these checks and throw {@link RuntimeUnsupportedError} when used\n * in a runtime that cannot support them. (FR-030, FR-030a)\n *\n * @packageDocumentation\n */\n\nimport { RuntimeUnsupportedError } from \"./errors.js\";\n\n/** Describes which optional capabilities the current runtime supports. */\nexport interface RuntimeCapabilities {\n\t/** Can spawn child processes (Node only) — required for stdio MCP transport. */\n\tcanSpawnProcess: boolean;\n\t/** Has `localStorage` available (browsers). */\n\thasLocalStorage: boolean;\n\t/** Has `indexedDB` available (browsers). */\n\thasIndexedDB: boolean;\n\t/** Running under Node.js. */\n\tisNode: boolean;\n}\n\nlet cached: RuntimeCapabilities | undefined;\n\n/** Detect the current runtime's capabilities (memoized). */\nexport function detectRuntime(): RuntimeCapabilities {\n\tif (cached) return cached;\n\n\tconst g = globalThis as Record<string, unknown>;\n\tconst proc = g[\"process\"] as { versions?: { node?: string } } | undefined;\n\tconst isNode = typeof proc !== \"undefined\" && !!proc.versions?.node;\n\n\tcached = {\n\t\tisNode,\n\t\t// Process spawning requires Node's child_process; treat Node as capable.\n\t\tcanSpawnProcess: isNode,\n\t\thasLocalStorage: typeof g[\"localStorage\"] !== \"undefined\",\n\t\thasIndexedDB: typeof g[\"indexedDB\"] !== \"undefined\",\n\t};\n\treturn cached;\n}\n\n/**\n * Assert that a runtime capability is present, throwing a typed error otherwise.\n *\n * @param capability - The capability key to require.\n * @param feature - Human-readable feature name used in the error message.\n * @throws {RuntimeUnsupportedError} when the capability is unavailable.\n */\nexport function requireCapability(\n\tcapability: keyof RuntimeCapabilities,\n\tfeature: string,\n): void {\n\tif (!detectRuntime()[capability]) {\n\t\tthrow new RuntimeUnsupportedError(feature, { capability });\n\t}\n}\n\n/** Reset the memoized detection — intended for tests only. */\nexport function resetRuntimeCache(): void {\n\tcached = undefined;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/agents/loop.ts","../src/agents/agent.ts"],"names":["textMessage","ToolRegistry","SkillIndex","hasImage","ProviderError","composeMiddleware","Thread"],"mappings":";;;;;;;;;AA4CA,eAAsB,OAAA,CACrB,QAAA,EACA,QAAA,EACA,QAAA,EACA,OAAA,EACsB;AACtB,EAAA,MAAM,aAAA,GAAgB,SAAS,aAAA,IAAiB,EAAA;AAChD,EAAA,MAAM,OAAA,GAAU,CAAC,GAAG,QAAQ,CAAA;AAC5B,EAAA,IAAI,SAAA,GAAY,CAAA;AAEhB,EAAA,WAAU;AACT,IAAA,IAAI,aAAA,KAAkB,EAAA,IAAM,SAAA,IAAa,aAAA,EAAe;AACvD,MAAA,OAAO;AAAA,QACN,QAAA,EAAU,OAAA;AAAA,QACV,KAAA,EAAO,EAAE,IAAA,EAAM,EAAA,EAAG;AAAA,QAClB,MAAA,EAAQ;AAAA,OACT;AAAA,IACD;AACA,IAAA,SAAA,EAAA;AAEA,IAAA,MAAM,KAAA,GAAQ,SAAS,KAAA,EAAM;AAC7B,IAAA,MAAM,QAAA,GAAW,MAAM,QAAA,CAAS;AAAA,MAC/B,QAAA,EAAU,OAAA;AAAA,MACV,KAAA,EAAO,KAAA,CAAM,MAAA,GAAS,CAAA,GAAI,KAAA,GAAQ,MAAA;AAAA,MAClC,QAAQ,OAAA,EAAS;AAAA,KACjB,CAAA;AAED,IAAA,IAAI,CAAC,QAAA,CAAS,SAAA,IAAa,QAAA,CAAS,SAAA,CAAU,WAAW,CAAA,EAAG;AAC3D,MAAA,OAAO,EAAE,QAAA,EAAU,OAAA,EAAS,KAAA,EAAO,QAAA,EAAU,QAAQ,WAAA,EAAY;AAAA,IAClE;AAKA,IAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,MACZ,IAAA,EAAM,WAAA;AAAA,MACN,KAAA,EAAO,QAAA,CAAS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AA,EAAU;AAC5C","file":"chunk-FDCTSJMB.cjs","sourcesContent":["/**\n * The agent run loop: drives provider calls, executes requested tool calls,\n * feeds typed results (including errors, for self-correction) back to the model,\n * and stops on a final answer, the iteration cap, or an abort. (FR-011a, FR-012b)\n *\n * @packageDocumentation\n */\n\nimport type { Message } from \"../core/types.js\";\nimport { textMessage } from \"../core/types.js\";\nimport type { GenerateRequest, GenerateResponse } from \"../providers/provider.js\";\nimport type { ToolRegistry } from \"../tools/registry.js\";\n\n/** Outcome status of a run. */\nexport type RunStatus = \"completed\" | \"failed\" | \"incomplete\" | \"limit-exceeded\";\n\n/** A function that produces a model response (optionally through middleware). */\nexport type GenerateFn = (req: GenerateRequest) => Promise<GenerateResponse>;\n\n/** Settings controlling the loop. */\nexport interface LoopOptions {\n\t/** Maximum iterations; -1 means unlimited. Default 10. (FR-012b) */\n\tmaxIterations?: number;\n\t/** Per-tool-call timeout in ms. (FR-012c) */\n\ttoolTimeoutMs?: number;\n\t/** Abort signal. */\n\tsignal?: AbortSignal;\n}\n\n/** Result of running the loop. */\nexport interface LoopResult {\n\tmessages: Message[];\n\tfinal: GenerateResponse;\n\tstatus: RunStatus;\n}\n\n/**\n * Execute the tool-call loop against a generate function and tool registry.\n *\n * @param generate - Produces a model response (typically the middleware pipeline).\n * @param registry - Tools available to the agent (may be empty).\n * @param messages - Initial conversation (system + user, etc.).\n * @param options - Loop tuning.\n */\nexport async function runLoop(\n\tgenerate: GenerateFn,\n\tregistry: ToolRegistry,\n\tmessages: Message[],\n\toptions?: LoopOptions,\n): Promise<LoopResult> {\n\tconst maxIterations = options?.maxIterations ?? 10;\n\tconst working = [...messages];\n\tlet iteration = 0;\n\n\tfor (; ;) {\n\t\tif (maxIterations !== -1 && iteration >= maxIterations) {\n\t\t\treturn {\n\t\t\t\tmessages: working,\n\t\t\t\tfinal: { text: \"\" },\n\t\t\t\tstatus: \"limit-exceeded\",\n\t\t\t};\n\t\t}\n\t\titeration++;\n\n\t\tconst specs = registry.specs();\n\t\tconst response = await generate({\n\t\t\tmessages: working,\n\t\t\ttools: specs.length > 0 ? specs : undefined,\n\t\t\tsignal: options?.signal,\n\t\t});\n\n\t\tif (!response.toolCalls || response.toolCalls.length === 0) {\n\t\t\treturn { messages: working, final: response, status: \"completed\" };\n\t\t}\n\n\t\t// Record the assistant's tool-call turn, preserving the tool calls (so strict\n\t\t// providers can pair each result with its call) and any opaque reasoning blob\n\t\t// (for thinking continuity across turns).\n\t\tworking.push({\n\t\t\trole: \"assistant\",\n\t\t\tparts: response.text ? [{ type: \"text\", text: response.text }] : [],\n\t\t\ttoolCalls: response.toolCalls,\n\t\t\t...(response.reasoningOpaque ? { reasoningOpaque: response.reasoningOpaque } : {}),\n\t\t});\n\n\t\t// Execute each requested tool and feed results (or typed errors) back.\n\t\tfor (const call of response.toolCalls) {\n\t\t\tconst result = await registry.invoke(call.name, call.arguments, options?.toolTimeoutMs);\n\t\t\tconst payload = result.error\n\t\t\t\t? `ERROR (${result.error.reason}): ${result.error.message}`\n\t\t\t\t: JSON.stringify(result.value ?? null);\n\t\t\tworking.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tname: call.name,\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\tparts: [{ type: \"text\", text: payload }],\n\t\t\t});\n\t\t}\n\t}\n}\n\n/** Build the initial message list from instructions + input. */\nexport function buildMessages(instructions: string, input: Message[]): Message[] {\n\treturn [textMessage(\"system\", instructions), ...input];\n}\n","/**\n * The agent: a configured actor that runs against a provider, optionally using\n * tools and skills, with streaming, reasoning output, multimodal input gating,\n * conversation threads with compaction, and a middleware pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { Message, ContentPart } from \"../core/types.js\";\nimport { hasImage, textMessage } from \"../core/types.js\";\nimport { ProviderError } from \"../core/errors.js\";\nimport type { Provider, GenerateResponse, GenerateRequest } from \"../providers/provider.js\";\nimport { ToolRegistry } from \"../tools/registry.js\";\nimport type { Tool } from \"../tools/tool.js\";\nimport type { Skill } from \"../skills/skill.js\";\nimport { SkillIndex } from \"../skills/index.js\";\nimport type { Middleware, MiddlewareContext } from \"../middleware/middleware.js\";\nimport { composeMiddleware } from \"../middleware/middleware.js\";\nimport { Thread, type ThreadOptions } from \"./thread.js\";\nimport { runLoop, type RunStatus } from \"./loop.js\";\n\n/** Configuration for {@link createAgent}. */\nexport interface AgentConfig {\n\tname: string;\n\tinstructions: string;\n\tprovider: Provider;\n\t/** Which of the provider's models to use; defaults to the provider's default model. */\n\tmodel?: string;\n\ttools?: Tool[];\n\tskills?: Skill[];\n\t/** Max tool-call iterations per run; -1 = unlimited. Default 10. (FR-012b) */\n\tmaxIterations?: number;\n\t/** Per-tool-call timeout in ms. (FR-012c) */\n\ttoolTimeoutMs?: number;\n\t/** Compaction threshold as a fraction of maxInputTokens. Default 0.9. (FR-004a) */\n\tcompactionThreshold?: number;\n\t/** Optional override model for compaction summaries. (FR-004b) */\n\tcompactionModel?: Provider;\n\t/** Middleware applied around provider calls. (FR-023) */\n\tmiddleware?: Middleware[];\n}\n\n/** Options for a single run. */\nexport interface RunOptions {\n\t/** Continue an existing conversation. (FR-004) */\n\tthread?: Thread;\n\t/** Abort signal. */\n\tsignal?: AbortSignal;\n}\n\n/** The result of a non-streaming run. */\nexport interface RunResult {\n\toutput: string;\n\t/** Reasoning content — only for reasoning-capable models. (FR-003a) */\n\treasoning?: string;\n\tstatus: RunStatus;\n\t/** True when the run was interrupted before completing. (FR-003b) */\n\tpartial: boolean;\n\terror?: ProviderError;\n\t/** The thread used/updated by this run. */\n\tthread: Thread;\n}\n\n/** Streamed run chunk. */\nexport type RunChunk =\n\t| { type: \"text\"; text: string }\n\t| { type: \"reasoning\"; text: string }\n\t| { type: \"done\"; result: RunResult };\n\n/** Agent input: plain text or structured (multimodal) messages. (FR-002) */\nexport type AgentInput = string | Message | Message[];\n\n/** A runnable agent. */\nexport interface Agent {\n\treadonly name: string;\n\trun(input: AgentInput, opts?: RunOptions): Promise<RunResult>;\n\trunStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk>;\n}\n\nfunction normalizeInput(input: AgentInput): Message[] {\n\tif (typeof input === \"string\") return [textMessage(\"user\", input)];\n\treturn Array.isArray(input) ? input : [input];\n}\n\nfunction promptText(messages: Message[]): string {\n\treturn messages\n\t\t.flatMap((m) => m.parts)\n\t\t.filter((p): p is { type: \"text\"; text: string } => p.type === \"text\")\n\t\t.map((p) => p.text)\n\t\t.join(\" \");\n}\n\n/**\n * Create an agent.\n *\n * @example\n * ```ts\n * const agent = createAgent({ name: \"Helper\", instructions: \"Be concise.\", provider });\n * const res = await agent.run(\"Say hello.\");\n * console.log(res.status, res.output);\n * ```\n */\nexport function createAgent(config: AgentConfig): Agent {\n\tconst registry = new ToolRegistry(config.tools ?? []);\n\tconst skillIndex = new SkillIndex(config.skills ?? []);\n\tconst middleware = config.middleware ?? [];\n\t/** Capabilities of the model this agent uses (selected from the provider). */\n\tconst modelCaps = () => config.provider.model(config.model);\n\n\tfunction gateVision(messages: Message[]): void {\n\t\tif (!modelCaps().supportsVision && messages.some(hasImage)) {\n\t\t\tthrow new ProviderError(\n\t\t\t\t\"Image input was provided but the configured model does not support vision\",\n\t\t\t\t\"client\",\n\t\t\t);\n\t\t}\n\t}\n\n\tasync function injectSkills(userMessages: Message[]): Promise<Message[]> {\n\t\tif ((config.skills ?? []).length === 0) return userMessages;\n\t\tconst selected = skillIndex.select(promptText(userMessages));\n\t\tif (selected.length === 0) return userMessages;\n\t\tconst contents = await Promise.all(selected.map((s) => skillIndex.load(s)));\n\t\tconst skillBlock = textMessage(\n\t\t\t\"system\",\n\t\t\t`Relevant skill knowledge:\\n${contents.join(\"\\n\\n\")}`,\n\t\t);\n\t\treturn [skillBlock, ...userMessages];\n\t}\n\n\tasync function callProvider(req: GenerateRequest): Promise<GenerateResponse> {\n\t\tconst ctx: MiddlewareContext = {\n\t\t\tagentName: config.name,\n\t\t\trequest: { ...req, model: req.model ?? config.model },\n\t\t};\n\t\tconst pipeline = composeMiddleware(middleware, (c) => config.provider.generate(c.request));\n\t\treturn pipeline(ctx);\n\t}\n\n\tasync function prepare(input: AgentInput, opts?: RunOptions): Promise<Thread> {\n\t\tconst userMessages = normalizeInput(input);\n\t\tgateVision(userMessages);\n\t\tconst thread =\n\t\t\topts?.thread ??\n\t\t\tnew Thread(undefined, [textMessage(\"system\", config.instructions)]);\n\t\tconst withSkills = await injectSkills(userMessages);\n\t\tfor (const m of withSkills) thread.add(m);\n\t\tawait thread.maybeCompact(config.provider, {\n\t\t\tcompactionThreshold: config.compactionThreshold,\n\t\t\tcompactionModel: config.compactionModel,\n\t\t\tmodelCapabilities: modelCaps(),\n\t\t} satisfies ThreadOptions);\n\t\treturn thread;\n\t}\n\n\tasync function run(input: AgentInput, opts?: RunOptions): Promise<RunResult> {\n\t\tlet thread: Thread;\n\t\ttry {\n\t\t\tthread = await prepare(input, opts);\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\treturn { output: \"\", status: \"failed\", partial: false, error: e, thread: opts?.thread ?? new Thread() };\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\ttry {\n\t\t\tconst loop = await runLoop(callProvider, registry, thread.messages, {\n\t\t\t\tmaxIterations: config.maxIterations,\n\t\t\t\ttoolTimeoutMs: config.toolTimeoutMs,\n\t\t\t\tsignal: opts?.signal,\n\t\t\t});\n\t\t\tif (loop.final.text) {\n\t\t\t\tthread.add({ role: \"assistant\", parts: [{ type: \"text\", text: loop.final.text }] });\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toutput: loop.final.text,\n\t\t\t\treasoning: modelCaps().supportsReasoning ? loop.final.reasoning : undefined,\n\t\t\t\tstatus: loop.status,\n\t\t\t\tpartial: loop.status === \"incomplete\",\n\t\t\t\tthread,\n\t\t\t};\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\treturn { output: \"\", status: \"failed\", partial: false, error: e, thread };\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tasync function* runStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk> {\n\t\t// Streaming path: single provider streaming call (tool loops use non-streaming\n\t\t// internally). Suitable for the common single-turn streaming case.\n\t\tlet thread: Thread;\n\t\ttry {\n\t\t\tthread = await prepare(input, opts);\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\tyield { type: \"done\", result: { output: \"\", status: \"failed\", partial: false, error: e, thread: opts?.thread ?? new Thread() } };\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\tlet text = \"\";\n\t\tlet reasoning = \"\";\n\t\ttry {\n\t\t\tfor await (const chunk of config.provider.generateStream({\n\t\t\t\tmessages: thread.messages,\n\t\t\t\ttools: registry.specs(),\n\t\t\t\tmodel: config.model,\n\t\t\t\tsignal: opts?.signal,\n\t\t\t})) {\n\t\t\t\tif (chunk.type === \"text\") {\n\t\t\t\t\ttext += chunk.text;\n\t\t\t\t\tyield { type: \"text\", text: chunk.text };\n\t\t\t\t} else if (chunk.type === \"reasoning\" && modelCaps().supportsReasoning) {\n\t\t\t\t\treasoning += chunk.text;\n\t\t\t\t\tyield { type: \"reasoning\", text: chunk.text };\n\t\t\t\t} else if (chunk.type === \"done\") {\n\t\t\t\t\ttext = chunk.response.text || text;\n\t\t\t\t\treasoning = chunk.response.reasoning || reasoning;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconst error = e instanceof ProviderError ? e : new ProviderError((e as Error).message, \"transient\");\n\t\t\tyield {\n\t\t\t\ttype: \"done\",\n\t\t\t\tresult: { output: text, status: \"incomplete\", partial: true, error, thread },\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\n\t\tif (text) thread.add({ role: \"assistant\", parts: [{ type: \"text\", text }] });\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: {\n\t\t\t\toutput: text,\n\t\t\t\treasoning: modelCaps().supportsReasoning ? reasoning || undefined : undefined,\n\t\t\t\tstatus: \"completed\",\n\t\t\t\tpartial: false,\n\t\t\t\tthread,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn { name: config.name, run, runStream };\n}\n\nexport type { ContentPart };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/runtime.ts"],"names":["RuntimeUnsupportedError"],"mappings":";;;;;AAuBA,IAAI,MAAA;AAGG,SAAS,aAAA,GAAqC;AACpD,EAAA,IAAI,QAAQ,OAAO,MAAA;AAEnB,EAAA,MAAM,CAAA,GAAI,UAAA;AACV,EAAA,MAAM,IAAA,GAAO,EAAE,SAAS,CAAA;AACxB,EAAA,MAAM,SAAS,OAAO,IAAA,KAAS,eAAe,CAAC,CAAC,KAAK,QAAA,EAAU,IAAA;AAE/D,EAAA,MAAA,GAAS;AAAA,IACR,MAAA;AAAA;AAAA,IAEA,eAAA,EAAiB,MAAA;AAAA,IACjB,eAAA,EAAiB,OAAO,CAAA,CAAE,cAAc,CAAA,KAAM,WAAA;AAAA,IAC9C,YAAA,EAAc,OAAO,CAAA,CAAE,WAAW,CAAA,KAAM;AAAA,GACzC;AACA,EAAA,OAAO,MAAA;AACR;AASO,SAAS,iBAAA,CACf,YACA,OAAA,EACO;AACP,EAAA,IAAI,CAAC,aAAA,EAAc,CAAE,UAAU,CAAA,EAAG;AACjC,IAAA,MAAM,IAAIA,yCAAA,CAAwB,OAAA,EAAS,EAAE,YAAY,CAAA;AAAA,EAC1D;AACD;AAGO,SAAS,iBAAA,GAA0B;AACzC,EAAA,MAAA,GAAS,MAAA;AACV","file":"chunk-FOTCUNP5.cjs","sourcesContent":["/**\n * Runtime capability detection. The framework runs in browsers, edge runtimes,\n * and Node. Features that need Node-only APIs (process spawning, filesystem) are\n * gated behind these checks and throw {@link RuntimeUnsupportedError} when used\n * in a runtime that cannot support them. (FR-030, FR-030a)\n *\n * @packageDocumentation\n */\n\nimport { RuntimeUnsupportedError } from \"./errors.js\";\n\n/** Describes which optional capabilities the current runtime supports. */\nexport interface RuntimeCapabilities {\n\t/** Can spawn child processes (Node only) — required for stdio MCP transport. */\n\tcanSpawnProcess: boolean;\n\t/** Has `localStorage` available (browsers). */\n\thasLocalStorage: boolean;\n\t/** Has `indexedDB` available (browsers). */\n\thasIndexedDB: boolean;\n\t/** Running under Node.js. */\n\tisNode: boolean;\n}\n\nlet cached: RuntimeCapabilities | undefined;\n\n/** Detect the current runtime's capabilities (memoized). */\nexport function detectRuntime(): RuntimeCapabilities {\n\tif (cached) return cached;\n\n\tconst g = globalThis as Record<string, unknown>;\n\tconst proc = g[\"process\"] as { versions?: { node?: string } } | undefined;\n\tconst isNode = typeof proc !== \"undefined\" && !!proc.versions?.node;\n\n\tcached = {\n\t\tisNode,\n\t\t// Process spawning requires Node's child_process; treat Node as capable.\n\t\tcanSpawnProcess: isNode,\n\t\thasLocalStorage: typeof g[\"localStorage\"] !== \"undefined\",\n\t\thasIndexedDB: typeof g[\"indexedDB\"] !== \"undefined\",\n\t};\n\treturn cached;\n}\n\n/**\n * Assert that a runtime capability is present, throwing a typed error otherwise.\n *\n * @param capability - The capability key to require.\n * @param feature - Human-readable feature name used in the error message.\n * @throws {RuntimeUnsupportedError} when the capability is unavailable.\n */\nexport function requireCapability(\n\tcapability: keyof RuntimeCapabilities,\n\tfeature: string,\n): void {\n\tif (!detectRuntime()[capability]) {\n\t\tthrow new RuntimeUnsupportedError(feature, { capability });\n\t}\n}\n\n/** Reset the memoized detection — intended for tests only. */\nexport function resetRuntimeCache(): void {\n\tcached = undefined;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/agents/loop.ts","../src/agents/agent.ts"],"names":[],"mappings":";;;;;;;AA4CA,eAAsB,OAAA,CACrB,QAAA,EACA,QAAA,EACA,QAAA,EACA,OAAA,EACsB;AACtB,EAAA,MAAM,aAAA,GAAgB,SAAS,aAAA,IAAiB,EAAA;AAChD,EAAA,MAAM,OAAA,GAAU,CAAC,GAAG,QAAQ,CAAA;AAC5B,EAAA,IAAI,SA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,GAAQ,aAAa,aAAA,GAAgB,CAAA,GAAI,IAAI,aAAA,CAAe,CAAA,CAAY,SAAS,WAAW,CAAA;AAClG,MAAA,MAAM;AAAA,QACL,IAAA,EAAM,MAAA;AAAA,QACN,MAAA,EAAQ,EAAE,MAAA,EAAQ,IAAA,EAAM,QAAQ,YAAA,EAAc,OAAA,EAAS,IAAA,EAAM,KAAA,EAAO,MAAA;AAAO,OAC5E;AACA,MAAA;AAAA,IACD;AAEA,IAAA,IAAI,IAAA,EAAM,MAAA,CAAO,GAAA,CAAI,EAAE,MAAM,WAAA,EAAa,KAAA,EAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,GAAG,CAAA;AAC3E,IAAA,MAAM;AAAA,MACL,IAAA,EAAM,MAAA;AAAA,MACN,MAAA,EAAQ;AAAA,QACP,MAAA,EAAQ,IAAA;AAAA,QACR,SAAA,EAAW,SAAA,EAAU,CAAE,iBAAA,GAAoB,aAAa,MAAA,GAAY,MAAA;AAAA,QACpE,MAAA,EAAQ,WAAA;AAAA,QACR,OAAA,EAAS,KAAA;AAAA,QACT;AAAA;AACD,KACD;AAAA,EACD;AAEA,EAAA,OAAO,EAAE,IAAA,EAAM,MAAA,CAAO,IAAA,EAAM,KAAK,SAAA,EAAU;AAC5C","file":"chunk-KOPGBIES.js","sourcesContent":["/**\n * The agent run loop: drives provider calls, executes requested tool calls,\n * feeds typed results (including errors, for self-correction) back to the model,\n * and stops on a final answer, the iteration cap, or an abort. (FR-011a, FR-012b)\n *\n * @packageDocumentation\n */\n\nimport type { Message } from \"../core/types.js\";\nimport { textMessage } from \"../core/types.js\";\nimport type { GenerateRequest, GenerateResponse } from \"../providers/provider.js\";\nimport type { ToolRegistry } from \"../tools/registry.js\";\n\n/** Outcome status of a run. */\nexport type RunStatus = \"completed\" | \"failed\" | \"incomplete\" | \"limit-exceeded\";\n\n/** A function that produces a model response (optionally through middleware). */\nexport type GenerateFn = (req: GenerateRequest) => Promise<GenerateResponse>;\n\n/** Settings controlling the loop. */\nexport interface LoopOptions {\n\t/** Maximum iterations; -1 means unlimited. Default 10. (FR-012b) */\n\tmaxIterations?: number;\n\t/** Per-tool-call timeout in ms. (FR-012c) */\n\ttoolTimeoutMs?: number;\n\t/** Abort signal. */\n\tsignal?: AbortSignal;\n}\n\n/** Result of running the loop. */\nexport interface LoopResult {\n\tmessages: Message[];\n\tfinal: GenerateResponse;\n\tstatus: RunStatus;\n}\n\n/**\n * Execute the tool-call loop against a generate function and tool registry.\n *\n * @param generate - Produces a model response (typically the middleware pipeline).\n * @param registry - Tools available to the agent (may be empty).\n * @param messages - Initial conversation (system + user, etc.).\n * @param options - Loop tuning.\n */\nexport async function runLoop(\n\tgenerate: GenerateFn,\n\tregistry: ToolRegistry,\n\tmessages: Message[],\n\toptions?: LoopOptions,\n): Promise<LoopResult> {\n\tconst maxIterations = options?.maxIterations ?? 10;\n\tconst working = [...messages];\n\tlet iteration = 0;\n\n\tfor (; ;) {\n\t\tif (maxIterations !== -1 && iteration >= maxIterations) {\n\t\t\treturn {\n\t\t\t\tmessages: working,\n\t\t\t\tfinal: { text: \"\" },\n\t\t\t\tstatus: \"limit-exceeded\",\n\t\t\t};\n\t\t}\n\t\titeration++;\n\n\t\tconst specs = registry.specs();\n\t\tconst response = await generate({\n\t\t\tmessages: working,\n\t\t\ttools: specs.length > 0 ? specs : undefined,\n\t\t\tsignal: options?.signal,\n\t\t});\n\n\t\tif (!response.toolCalls || response.toolCalls.length === 0) {\n\t\t\treturn { messages: working, final: response, status: \"completed\" };\n\t\t}\n\n\t\t// Record the assistant's tool-call turn, preserving the tool calls (so strict\n\t\t// providers can pair each result with its call) and any opaque reasoning blob\n\t\t// (for thinking continuity across turns).\n\t\tworking.push({\n\t\t\trole: \"assistant\",\n\t\t\tparts: response.text ? [{ type: \"text\", text: response.text }] : [],\n\t\t\ttoolCalls: response.toolCalls,\n\t\t\t...(response.reasoningOpaque ? { reasoningOpaque: response.reasoningOpaque } : {}),\n\t\t});\n\n\t\t// Execute each requested tool and feed results (or typed errors) back.\n\t\tfor (const call of response.toolCalls) {\n\t\t\tconst result = await registry.invoke(call.name, call.arguments, options?.toolTimeoutMs);\n\t\t\tconst payload = result.error\n\t\t\t\t? `ERROR (${result.error.reason}): ${result.error.message}`\n\t\t\t\t: JSON.stringify(result.value ?? null);\n\t\t\tworking.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tname: call.name,\n\t\t\t\ttoolCallId: call.id,\n\t\t\t\tparts: [{ type: \"text\", text: payload }],\n\t\t\t});\n\t\t}\n\t}\n}\n\n/** Build the initial message list from instructions + input. */\nexport function buildMessages(instructions: string, input: Message[]): Message[] {\n\treturn [textMessage(\"system\", instructions), ...input];\n}\n","/**\n * The agent: a configured actor that runs against a provider, optionally using\n * tools and skills, with streaming, reasoning output, multimodal input gating,\n * conversation threads with compaction, and a middleware pipeline.\n *\n * @packageDocumentation\n */\n\nimport type { Message, ContentPart } from \"../core/types.js\";\nimport { hasImage, textMessage } from \"../core/types.js\";\nimport { ProviderError } from \"../core/errors.js\";\nimport type { Provider, GenerateResponse, GenerateRequest } from \"../providers/provider.js\";\nimport { ToolRegistry } from \"../tools/registry.js\";\nimport type { Tool } from \"../tools/tool.js\";\nimport type { Skill } from \"../skills/skill.js\";\nimport { SkillIndex } from \"../skills/index.js\";\nimport type { Middleware, MiddlewareContext } from \"../middleware/middleware.js\";\nimport { composeMiddleware } from \"../middleware/middleware.js\";\nimport { Thread, type ThreadOptions } from \"./thread.js\";\nimport { runLoop, type RunStatus } from \"./loop.js\";\n\n/** Configuration for {@link createAgent}. */\nexport interface AgentConfig {\n\tname: string;\n\tinstructions: string;\n\tprovider: Provider;\n\t/** Which of the provider's models to use; defaults to the provider's default model. */\n\tmodel?: string;\n\ttools?: Tool[];\n\tskills?: Skill[];\n\t/** Max tool-call iterations per run; -1 = unlimited. Default 10. (FR-012b) */\n\tmaxIterations?: number;\n\t/** Per-tool-call timeout in ms. (FR-012c) */\n\ttoolTimeoutMs?: number;\n\t/** Compaction threshold as a fraction of maxInputTokens. Default 0.9. (FR-004a) */\n\tcompactionThreshold?: number;\n\t/** Optional override model for compaction summaries. (FR-004b) */\n\tcompactionModel?: Provider;\n\t/** Middleware applied around provider calls. (FR-023) */\n\tmiddleware?: Middleware[];\n}\n\n/** Options for a single run. */\nexport interface RunOptions {\n\t/** Continue an existing conversation. (FR-004) */\n\tthread?: Thread;\n\t/** Abort signal. */\n\tsignal?: AbortSignal;\n}\n\n/** The result of a non-streaming run. */\nexport interface RunResult {\n\toutput: string;\n\t/** Reasoning content — only for reasoning-capable models. (FR-003a) */\n\treasoning?: string;\n\tstatus: RunStatus;\n\t/** True when the run was interrupted before completing. (FR-003b) */\n\tpartial: boolean;\n\terror?: ProviderError;\n\t/** The thread used/updated by this run. */\n\tthread: Thread;\n}\n\n/** Streamed run chunk. */\nexport type RunChunk =\n\t| { type: \"text\"; text: string }\n\t| { type: \"reasoning\"; text: string }\n\t| { type: \"done\"; result: RunResult };\n\n/** Agent input: plain text or structured (multimodal) messages. (FR-002) */\nexport type AgentInput = string | Message | Message[];\n\n/** A runnable agent. */\nexport interface Agent {\n\treadonly name: string;\n\trun(input: AgentInput, opts?: RunOptions): Promise<RunResult>;\n\trunStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk>;\n}\n\nfunction normalizeInput(input: AgentInput): Message[] {\n\tif (typeof input === \"string\") return [textMessage(\"user\", input)];\n\treturn Array.isArray(input) ? input : [input];\n}\n\nfunction promptText(messages: Message[]): string {\n\treturn messages\n\t\t.flatMap((m) => m.parts)\n\t\t.filter((p): p is { type: \"text\"; text: string } => p.type === \"text\")\n\t\t.map((p) => p.text)\n\t\t.join(\" \");\n}\n\n/**\n * Create an agent.\n *\n * @example\n * ```ts\n * const agent = createAgent({ name: \"Helper\", instructions: \"Be concise.\", provider });\n * const res = await agent.run(\"Say hello.\");\n * console.log(res.status, res.output);\n * ```\n */\nexport function createAgent(config: AgentConfig): Agent {\n\tconst registry = new ToolRegistry(config.tools ?? []);\n\tconst skillIndex = new SkillIndex(config.skills ?? []);\n\tconst middleware = config.middleware ?? [];\n\t/** Capabilities of the model this agent uses (selected from the provider). */\n\tconst modelCaps = () => config.provider.model(config.model);\n\n\tfunction gateVision(messages: Message[]): void {\n\t\tif (!modelCaps().supportsVision && messages.some(hasImage)) {\n\t\t\tthrow new ProviderError(\n\t\t\t\t\"Image input was provided but the configured model does not support vision\",\n\t\t\t\t\"client\",\n\t\t\t);\n\t\t}\n\t}\n\n\tasync function injectSkills(userMessages: Message[]): Promise<Message[]> {\n\t\tif ((config.skills ?? []).length === 0) return userMessages;\n\t\tconst selected = skillIndex.select(promptText(userMessages));\n\t\tif (selected.length === 0) return userMessages;\n\t\tconst contents = await Promise.all(selected.map((s) => skillIndex.load(s)));\n\t\tconst skillBlock = textMessage(\n\t\t\t\"system\",\n\t\t\t`Relevant skill knowledge:\\n${contents.join(\"\\n\\n\")}`,\n\t\t);\n\t\treturn [skillBlock, ...userMessages];\n\t}\n\n\tasync function callProvider(req: GenerateRequest): Promise<GenerateResponse> {\n\t\tconst ctx: MiddlewareContext = {\n\t\t\tagentName: config.name,\n\t\t\trequest: { ...req, model: req.model ?? config.model },\n\t\t};\n\t\tconst pipeline = composeMiddleware(middleware, (c) => config.provider.generate(c.request));\n\t\treturn pipeline(ctx);\n\t}\n\n\tasync function prepare(input: AgentInput, opts?: RunOptions): Promise<Thread> {\n\t\tconst userMessages = normalizeInput(input);\n\t\tgateVision(userMessages);\n\t\tconst thread =\n\t\t\topts?.thread ??\n\t\t\tnew Thread(undefined, [textMessage(\"system\", config.instructions)]);\n\t\tconst withSkills = await injectSkills(userMessages);\n\t\tfor (const m of withSkills) thread.add(m);\n\t\tawait thread.maybeCompact(config.provider, {\n\t\t\tcompactionThreshold: config.compactionThreshold,\n\t\t\tcompactionModel: config.compactionModel,\n\t\t\tmodelCapabilities: modelCaps(),\n\t\t} satisfies ThreadOptions);\n\t\treturn thread;\n\t}\n\n\tasync function run(input: AgentInput, opts?: RunOptions): Promise<RunResult> {\n\t\tlet thread: Thread;\n\t\ttry {\n\t\t\tthread = await prepare(input, opts);\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\treturn { output: \"\", status: \"failed\", partial: false, error: e, thread: opts?.thread ?? new Thread() };\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\ttry {\n\t\t\tconst loop = await runLoop(callProvider, registry, thread.messages, {\n\t\t\t\tmaxIterations: config.maxIterations,\n\t\t\t\ttoolTimeoutMs: config.toolTimeoutMs,\n\t\t\t\tsignal: opts?.signal,\n\t\t\t});\n\t\t\tif (loop.final.text) {\n\t\t\t\tthread.add({ role: \"assistant\", parts: [{ type: \"text\", text: loop.final.text }] });\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toutput: loop.final.text,\n\t\t\t\treasoning: modelCaps().supportsReasoning ? loop.final.reasoning : undefined,\n\t\t\t\tstatus: loop.status,\n\t\t\t\tpartial: loop.status === \"incomplete\",\n\t\t\t\tthread,\n\t\t\t};\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\treturn { output: \"\", status: \"failed\", partial: false, error: e, thread };\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\tasync function* runStream(input: AgentInput, opts?: RunOptions): AsyncIterable<RunChunk> {\n\t\t// Streaming path: single provider streaming call (tool loops use non-streaming\n\t\t// internally). Suitable for the common single-turn streaming case.\n\t\tlet thread: Thread;\n\t\ttry {\n\t\t\tthread = await prepare(input, opts);\n\t\t} catch (e) {\n\t\t\tif (e instanceof ProviderError) {\n\t\t\t\tyield { type: \"done\", result: { output: \"\", status: \"failed\", partial: false, error: e, thread: opts?.thread ?? new Thread() } };\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\n\t\tlet text = \"\";\n\t\tlet reasoning = \"\";\n\t\ttry {\n\t\t\tfor await (const chunk of config.provider.generateStream({\n\t\t\t\tmessages: thread.messages,\n\t\t\t\ttools: registry.specs(),\n\t\t\t\tmodel: config.model,\n\t\t\t\tsignal: opts?.signal,\n\t\t\t})) {\n\t\t\t\tif (chunk.type === \"text\") {\n\t\t\t\t\ttext += chunk.text;\n\t\t\t\t\tyield { type: \"text\", text: chunk.text };\n\t\t\t\t} else if (chunk.type === \"reasoning\" && modelCaps().supportsReasoning) {\n\t\t\t\t\treasoning += chunk.text;\n\t\t\t\t\tyield { type: \"reasoning\", text: chunk.text };\n\t\t\t\t} else if (chunk.type === \"done\") {\n\t\t\t\t\ttext = chunk.response.text || text;\n\t\t\t\t\treasoning = chunk.response.reasoning || reasoning;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (e) {\n\t\t\tconst error = e instanceof ProviderError ? e : new ProviderError((e as Error).message, \"transient\");\n\t\t\tyield {\n\t\t\t\ttype: \"done\",\n\t\t\t\tresult: { output: text, status: \"incomplete\", partial: true, error, thread },\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\n\t\tif (text) thread.add({ role: \"assistant\", parts: [{ type: \"text\", text }] });\n\t\tyield {\n\t\t\ttype: \"done\",\n\t\t\tresult: {\n\t\t\t\toutput: text,\n\t\t\t\treasoning: modelCaps().supportsReasoning ? reasoning || undefined : undefined,\n\t\t\t\tstatus: \"completed\",\n\t\t\t\tpartial: false,\n\t\t\t\tthread,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn { name: config.name, run, runStream };\n}\n\nexport type { ContentPart };\n"]}