@axlsdk/axl 0.1.1 → 0.2.0

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.
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Axl Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -76,4 +76,4 @@ export {
76
76
  __require,
77
77
  OTelSpanManager
78
78
  };
79
- //# sourceMappingURL=chunk-EE2BCC37.js.map
79
+ //# sourceMappingURL=chunk-JBLQKU6X.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/telemetry/span-manager.ts"],"sourcesContent":["import type { SpanHandle, SpanManager, TelemetryConfig } from './types.js';\n\n/** Minimal interface for an OTel span. */\ninterface OTelSpan {\n setAttribute(key: string, value: string | number | boolean): void;\n addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;\n setStatus(status: { code: unknown; message?: string }): void;\n end(): void;\n}\n\n/** Minimal interface for an OTel tracer. */\ninterface OTelTracer {\n startActiveSpan<T>(\n name: string,\n options: { attributes: Record<string, string | number | boolean> },\n fn: (span: OTelSpan) => Promise<T>,\n ): Promise<T>;\n}\n\n/** Minimal interface for an OTel tracer provider. */\ninterface OTelTracerProvider {\n getTracer(name: string): OTelTracer;\n shutdown?(): Promise<void>;\n}\n\n/** Minimal interface for the @opentelemetry/api module. */\ninterface OTelApi {\n SpanStatusCode: { OK: unknown; ERROR: unknown };\n trace: {\n getTracerProvider(): OTelTracerProvider;\n getActiveSpan?(): OTelSpan | undefined;\n };\n}\n\n/**\n * OpenTelemetry-backed SpanManager.\n * Dynamically imports @opentelemetry/api to avoid hard dependency.\n */\nexport class OTelSpanManager implements SpanManager {\n private tracer: OTelTracer;\n private otelApi: OTelApi;\n private tracerProvider: OTelTracerProvider;\n\n private constructor(otelApi: OTelApi, tracer: OTelTracer, tracerProvider: OTelTracerProvider) {\n this.otelApi = otelApi;\n this.tracer = tracer;\n this.tracerProvider = tracerProvider;\n }\n\n static async create(config: TelemetryConfig): Promise<OTelSpanManager> {\n let otelApi: OTelApi;\n try {\n otelApi = (await import('@opentelemetry/api')) as unknown as OTelApi;\n } catch {\n throw new Error(\n '@opentelemetry/api is required for telemetry. Install it with: npm install @opentelemetry/api',\n );\n }\n\n const tracerProvider =\n (config.tracerProvider as OTelTracerProvider | undefined) ??\n otelApi.trace.getTracerProvider();\n const serviceName = config.serviceName ?? 'axl';\n const tracer = tracerProvider.getTracer(serviceName);\n\n return new OTelSpanManager(otelApi, tracer, tracerProvider);\n }\n\n async withSpanAsync<T>(\n name: string,\n attributes: Record<string, string | number | boolean>,\n fn: (span: SpanHandle) => Promise<T>,\n ): Promise<T> {\n const otelApi = this.otelApi;\n\n return this.tracer.startActiveSpan(name, { attributes }, async (otelSpan: OTelSpan) => {\n const handle: SpanHandle = {\n setAttribute(key: string, value: string | number | boolean) {\n otelSpan.setAttribute(key, value);\n },\n addEvent(eventName: string, attrs?: Record<string, string | number | boolean>) {\n otelSpan.addEvent(eventName, attrs);\n },\n setStatus(code: 'ok' | 'error', message?: string) {\n const statusCode =\n code === 'ok' ? otelApi.SpanStatusCode.OK : otelApi.SpanStatusCode.ERROR;\n otelSpan.setStatus({ code: statusCode, message });\n },\n end() {\n otelSpan.end();\n },\n };\n\n try {\n const result = await fn(handle);\n handle.setStatus('ok');\n return result;\n } catch (err) {\n handle.setStatus('error', err instanceof Error ? err.message : String(err));\n throw err;\n } finally {\n handle.end();\n }\n });\n }\n\n addEventToActiveSpan(name: string, attributes?: Record<string, string | number | boolean>): void {\n const activeSpan = this.otelApi.trace.getActiveSpan?.();\n if (activeSpan) {\n activeSpan.addEvent(name, attributes);\n }\n }\n\n async shutdown(): Promise<void> {\n if (this.tracerProvider && typeof this.tracerProvider.shutdown === 'function') {\n await this.tracerProvider.shutdown();\n }\n }\n}\n"],"mappings":";;;;;;;;AAsCO,IAAM,kBAAN,MAAM,iBAAuC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAAkB,QAAoB,gBAAoC;AAC5F,SAAK,UAAU;AACf,SAAK,SAAS;AACd,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAEA,aAAa,OAAO,QAAmD;AACrE,QAAI;AACJ,QAAI;AACF,gBAAW,MAAM,OAAO,oBAAoB;AAAA,IAC9C,QAAQ;AACN,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,iBACH,OAAO,kBACR,QAAQ,MAAM,kBAAkB;AAClC,UAAM,cAAc,OAAO,eAAe;AAC1C,UAAM,SAAS,eAAe,UAAU,WAAW;AAEnD,WAAO,IAAI,iBAAgB,SAAS,QAAQ,cAAc;AAAA,EAC5D;AAAA,EAEA,MAAM,cACJ,MACA,YACA,IACY;AACZ,UAAM,UAAU,KAAK;AAErB,WAAO,KAAK,OAAO,gBAAgB,MAAM,EAAE,WAAW,GAAG,OAAO,aAAuB;AACrF,YAAM,SAAqB;AAAA,QACzB,aAAa,KAAa,OAAkC;AAC1D,mBAAS,aAAa,KAAK,KAAK;AAAA,QAClC;AAAA,QACA,SAAS,WAAmB,OAAmD;AAC7E,mBAAS,SAAS,WAAW,KAAK;AAAA,QACpC;AAAA,QACA,UAAU,MAAsB,SAAkB;AAChD,gBAAM,aACJ,SAAS,OAAO,QAAQ,eAAe,KAAK,QAAQ,eAAe;AACrE,mBAAS,UAAU,EAAE,MAAM,YAAY,QAAQ,CAAC;AAAA,QAClD;AAAA,QACA,MAAM;AACJ,mBAAS,IAAI;AAAA,QACf;AAAA,MACF;AAEA,UAAI;AACF,cAAM,SAAS,MAAM,GAAG,MAAM;AAC9B,eAAO,UAAU,IAAI;AACrB,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,eAAO,UAAU,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAC1E,cAAM;AAAA,MACR,UAAE;AACA,eAAO,IAAI;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,qBAAqB,MAAc,YAA8D;AAC/F,UAAM,aAAa,KAAK,QAAQ,MAAM,gBAAgB;AACtD,QAAI,YAAY;AACd,iBAAW,SAAS,MAAM,UAAU;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,MAAM,WAA0B;AAC9B,QAAI,KAAK,kBAAkB,OAAO,KAAK,eAAe,aAAa,YAAY;AAC7E,YAAM,KAAK,eAAe,SAAS;AAAA,IACrC;AAAA,EACF;AACF;","names":[]}
package/dist/index.cjs CHANGED
@@ -141,7 +141,8 @@ __export(index_exports, {
141
141
  createSpanManager: () => createSpanManager,
142
142
  defineConfig: () => defineConfig,
143
143
  tool: () => tool,
144
- workflow: () => workflow
144
+ workflow: () => workflow,
145
+ zodToJsonSchema: () => zodToJsonSchema
145
146
  });
146
147
  module.exports = __toCommonJS(index_exports);
147
148
 
@@ -245,6 +246,48 @@ function tool(config) {
245
246
  };
246
247
  }
247
248
 
249
+ // src/providers/retry.ts
250
+ var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429, 503, 529]);
251
+ var MAX_RETRIES = 2;
252
+ var BASE_DELAY_MS = 1e3;
253
+ function sleep2(ms, signal) {
254
+ return new Promise((resolve) => {
255
+ if (signal?.aborted) {
256
+ resolve();
257
+ return;
258
+ }
259
+ const timer = setTimeout(resolve, ms);
260
+ signal?.addEventListener(
261
+ "abort",
262
+ () => {
263
+ clearTimeout(timer);
264
+ resolve();
265
+ },
266
+ { once: true }
267
+ );
268
+ });
269
+ }
270
+ async function fetchWithRetry(input, init, maxRetries = MAX_RETRIES) {
271
+ for (let attempt = 0; ; attempt++) {
272
+ const res = await fetch(input, init);
273
+ if (res.ok || !RETRYABLE_STATUS_CODES.has(res.status) || attempt >= maxRetries) {
274
+ return res;
275
+ }
276
+ if (init?.signal?.aborted) {
277
+ return res;
278
+ }
279
+ const retryAfter = res.headers.get("retry-after");
280
+ let delay;
281
+ if (retryAfter && !isNaN(Number(retryAfter))) {
282
+ delay = Number(retryAfter) * 1e3;
283
+ } else {
284
+ delay = BASE_DELAY_MS * 2 ** attempt;
285
+ }
286
+ delay *= 0.75 + Math.random() * 0.5;
287
+ await sleep2(delay, init?.signal ?? void 0);
288
+ }
289
+ }
290
+
248
291
  // src/providers/openai.ts
249
292
  var OPENAI_PRICING = {
250
293
  "gpt-4o": [25e-7, 1e-5],
@@ -304,7 +347,7 @@ var OpenAIProvider = class {
304
347
  // ---------------------------------------------------------------------------
305
348
  async chat(messages, options) {
306
349
  const body = this.buildRequestBody(messages, options, false);
307
- const res = await fetch(`${this.baseUrl}/chat/completions`, {
350
+ const res = await fetchWithRetry(`${this.baseUrl}/chat/completions`, {
308
351
  method: "POST",
309
352
  headers: {
310
353
  "Content-Type": "application/json",
@@ -352,7 +395,7 @@ var OpenAIProvider = class {
352
395
  // ---------------------------------------------------------------------------
353
396
  async *stream(messages, options) {
354
397
  const body = this.buildRequestBody(messages, options, true);
355
- const res = await fetch(`${this.baseUrl}/chat/completions`, {
398
+ const res = await fetchWithRetry(`${this.baseUrl}/chat/completions`, {
356
399
  method: "POST",
357
400
  headers: {
358
401
  "Content-Type": "application/json",
@@ -511,7 +554,7 @@ var OpenAIResponsesProvider = class {
511
554
  // ---------------------------------------------------------------------------
512
555
  async chat(messages, options) {
513
556
  const body = this.buildRequestBody(messages, options, false);
514
- const res = await fetch(`${this.baseUrl}/responses`, {
557
+ const res = await fetchWithRetry(`${this.baseUrl}/responses`, {
515
558
  method: "POST",
516
559
  headers: {
517
560
  "Content-Type": "application/json",
@@ -533,7 +576,7 @@ var OpenAIResponsesProvider = class {
533
576
  // ---------------------------------------------------------------------------
534
577
  async *stream(messages, options) {
535
578
  const body = this.buildRequestBody(messages, options, true);
536
- const res = await fetch(`${this.baseUrl}/responses`, {
579
+ const res = await fetchWithRetry(`${this.baseUrl}/responses`, {
537
580
  method: "POST",
538
581
  headers: {
539
582
  "Content-Type": "application/json",
@@ -845,7 +888,7 @@ var AnthropicProvider = class {
845
888
  async chat(messages, options) {
846
889
  this.currentModel = options.model;
847
890
  const body = this.buildRequestBody(messages, options, false);
848
- const res = await fetch(`${this.baseUrl}/messages`, {
891
+ const res = await fetchWithRetry(`${this.baseUrl}/messages`, {
849
892
  method: "POST",
850
893
  headers: this.buildHeaders(),
851
894
  body: JSON.stringify(body),
@@ -864,7 +907,7 @@ var AnthropicProvider = class {
864
907
  // ---------------------------------------------------------------------------
865
908
  async *stream(messages, options) {
866
909
  const body = this.buildRequestBody(messages, options, true);
867
- const res = await fetch(`${this.baseUrl}/messages`, {
910
+ const res = await fetchWithRetry(`${this.baseUrl}/messages`, {
868
911
  method: "POST",
869
912
  headers: this.buildHeaders(),
870
913
  body: JSON.stringify(body),
@@ -1215,7 +1258,7 @@ var GeminiProvider = class {
1215
1258
  // ---------------------------------------------------------------------------
1216
1259
  async chat(messages, options) {
1217
1260
  const body = this.buildRequestBody(messages, options);
1218
- const res = await fetch(`${this.baseUrl}/models/${options.model}:generateContent`, {
1261
+ const res = await fetchWithRetry(`${this.baseUrl}/models/${options.model}:generateContent`, {
1219
1262
  method: "POST",
1220
1263
  headers: this.buildHeaders(),
1221
1264
  body: JSON.stringify(body),
@@ -1234,7 +1277,7 @@ var GeminiProvider = class {
1234
1277
  // ---------------------------------------------------------------------------
1235
1278
  async *stream(messages, options) {
1236
1279
  const body = this.buildRequestBody(messages, options);
1237
- const res = await fetch(
1280
+ const res = await fetchWithRetry(
1238
1281
  `${this.baseUrl}/models/${options.model}:streamGenerateContent?alt=sse`,
1239
1282
  {
1240
1283
  method: "POST",
@@ -2316,7 +2359,8 @@ Please fix and try again.`;
2316
2359
  span.setAttribute("axl.tool.duration", Date.now() - toolStart2);
2317
2360
  const isError = r && typeof r === "object" && "error" in r;
2318
2361
  span.setAttribute("axl.tool.success", !isError);
2319
- if (isError) span.setStatus("error", r.error);
2362
+ if (isError)
2363
+ span.setStatus("error", r.error);
2320
2364
  return r;
2321
2365
  }
2322
2366
  ) : await executeOverride();
@@ -2428,7 +2472,9 @@ Please fix and try again.`;
2428
2472
  try {
2429
2473
  const mcpResult = await this.mcpManager.callTool(toolName, toolArgs);
2430
2474
  toolResult2 = mcpResult;
2431
- resultContent2 = mcpResult.content.map((c) => c.type === "text" ? c.text : `[${c.type}]`).join("\n");
2475
+ resultContent2 = mcpResult.content.map(
2476
+ (c) => c.type === "text" ? c.text : `[${c.type}]`
2477
+ ).join("\n");
2432
2478
  if (mcpResult.isError) {
2433
2479
  resultContent2 = `Error: ${resultContent2}`;
2434
2480
  }
@@ -2470,7 +2516,11 @@ Please fix and try again.`;
2470
2516
  span.setAttribute("axl.tool.duration", Date.now() - toolStart);
2471
2517
  const isError = r.toolResult && typeof r.toolResult === "object" && "error" in r.toolResult;
2472
2518
  span.setAttribute("axl.tool.success", !isError);
2473
- if (isError) span.setStatus("error", r.toolResult.error);
2519
+ if (isError)
2520
+ span.setStatus(
2521
+ "error",
2522
+ r.toolResult.error
2523
+ );
2474
2524
  return r;
2475
2525
  }
2476
2526
  ) : await executeTool();
@@ -3449,6 +3499,10 @@ var MemoryStore = class {
3449
3499
  async deleteMemory(scope, key) {
3450
3500
  this.memories.get(scope)?.delete(key);
3451
3501
  }
3502
+ // ── Sessions (Studio introspection) ─────────────────────────────────
3503
+ async listSessions() {
3504
+ return [...this.sessions.keys()];
3505
+ }
3452
3506
  // ── Lifecycle ──────────────────────────────────────────────────────
3453
3507
  async close() {
3454
3508
  }
@@ -3677,6 +3731,11 @@ var SQLiteStore = class {
3677
3731
  const rows = stmt.all();
3678
3732
  return rows.map((r) => r.execution_id);
3679
3733
  }
3734
+ // ── Sessions (Studio introspection) ────────────────────────────────────
3735
+ async listSessions() {
3736
+ const rows = this.db.prepare("SELECT session_id FROM sessions").all();
3737
+ return rows.map((r) => r.session_id);
3738
+ }
3680
3739
  // ── Memory ────────────────────────────────────────────────────────────
3681
3740
  async saveMemory(scope, key, value) {
3682
3741
  this.db.prepare(
@@ -3710,7 +3769,8 @@ var RedisStore = class {
3710
3769
  constructor(url) {
3711
3770
  let Redis;
3712
3771
  try {
3713
- Redis = require("ioredis").default ?? require("ioredis");
3772
+ const mod = require("ioredis");
3773
+ Redis = mod.default ?? mod;
3714
3774
  } catch {
3715
3775
  throw new Error("ioredis is required for RedisStore. Install it with: npm install ioredis");
3716
3776
  }
@@ -3760,6 +3820,7 @@ var RedisStore = class {
3760
3820
  // ── Sessions ─────────────────────────────────────────────────────────
3761
3821
  async saveSession(sessionId, history) {
3762
3822
  await this.client.set(this.sessionKey(sessionId), JSON.stringify(history));
3823
+ await this.client.sadd("axl:session-ids", sessionId);
3763
3824
  }
3764
3825
  async getSession(sessionId) {
3765
3826
  const raw = await this.client.get(this.sessionKey(sessionId));
@@ -3768,6 +3829,7 @@ var RedisStore = class {
3768
3829
  async deleteSession(sessionId) {
3769
3830
  await this.client.del(this.sessionKey(sessionId));
3770
3831
  await this.client.del(this.sessionMetaKey(sessionId));
3832
+ await this.client.srem("axl:session-ids", sessionId);
3771
3833
  }
3772
3834
  async saveSessionMeta(sessionId, key, value) {
3773
3835
  await this.client.hset(this.sessionMetaKey(sessionId), key, JSON.stringify(value));
@@ -3804,6 +3866,10 @@ var RedisStore = class {
3804
3866
  async listPendingExecutions() {
3805
3867
  return this.client.smembers(this.pendingExecSetKey());
3806
3868
  }
3869
+ // ── Sessions (Studio introspection) ────────────────────────────────────
3870
+ async listSessions() {
3871
+ return this.client.smembers("axl:session-ids");
3872
+ }
3807
3873
  /** Close the Redis connection. */
3808
3874
  async close() {
3809
3875
  await this.client.quit();
@@ -4649,6 +4715,8 @@ function hashInput(input) {
4649
4715
  var AxlRuntime = class extends import_node_events2.EventEmitter {
4650
4716
  config;
4651
4717
  workflows = /* @__PURE__ */ new Map();
4718
+ tools = /* @__PURE__ */ new Map();
4719
+ agents = /* @__PURE__ */ new Map();
4652
4720
  providerRegistry;
4653
4721
  stateStore;
4654
4722
  executions = /* @__PURE__ */ new Map();
@@ -4703,9 +4771,56 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
4703
4771
  }
4704
4772
  }
4705
4773
  /** Register a workflow with the runtime. */
4774
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4706
4775
  register(workflow2) {
4707
4776
  this.workflows.set(workflow2.name, workflow2);
4708
4777
  }
4778
+ /** Register standalone tools for Studio introspection and direct testing. */
4779
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4780
+ registerTool(...tools) {
4781
+ for (const t of tools) {
4782
+ this.tools.set(t.name, t);
4783
+ }
4784
+ }
4785
+ /** Register standalone agents for Studio playground and introspection. */
4786
+ registerAgent(...agents) {
4787
+ for (const a of agents) {
4788
+ this.agents.set(a._name, a);
4789
+ }
4790
+ }
4791
+ // ── Introspection (used by Studio) ────────────────────────────────
4792
+ /** Get all registered workflow names. */
4793
+ getWorkflowNames() {
4794
+ return [...this.workflows.keys()];
4795
+ }
4796
+ /** Get a registered workflow by name. */
4797
+ getWorkflow(name) {
4798
+ return this.workflows.get(name);
4799
+ }
4800
+ /** Get all registered workflows. */
4801
+ getWorkflows() {
4802
+ return [...this.workflows.values()];
4803
+ }
4804
+ /** Get all registered standalone tools. */
4805
+ getTools() {
4806
+ return [...this.tools.values()];
4807
+ }
4808
+ /** Get a registered standalone tool by name. */
4809
+ getTool(name) {
4810
+ return this.tools.get(name);
4811
+ }
4812
+ /** Get all registered standalone agents. */
4813
+ getAgents() {
4814
+ return [...this.agents.values()];
4815
+ }
4816
+ /** Get a registered standalone agent by name. */
4817
+ getAgent(name) {
4818
+ return this.agents.get(name);
4819
+ }
4820
+ /** Get all execution info (running + completed). */
4821
+ getExecutions() {
4822
+ return [...this.executions.values()];
4823
+ }
4709
4824
  /** Register a custom provider instance. */
4710
4825
  registerProvider(name, provider) {
4711
4826
  this.providerRegistry.registerInstance(name, provider);
@@ -5405,6 +5520,7 @@ function cosineSimilarity2(a, b) {
5405
5520
  createSpanManager,
5406
5521
  defineConfig,
5407
5522
  tool,
5408
- workflow
5523
+ workflow,
5524
+ zodToJsonSchema
5409
5525
  });
5410
5526
  //# sourceMappingURL=index.cjs.map