@axlsdk/axl 0.1.1 → 0.3.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 +190 -0
- package/dist/{chunk-EE2BCC37.js → chunk-JBLQKU6X.js} +1 -1
- package/dist/chunk-JBLQKU6X.js.map +1 -0
- package/dist/index.cjs +181 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -10
- package/dist/index.d.ts +67 -10
- package/dist/index.js +181 -19
- package/dist/index.js.map +1 -1
- package/dist/span-manager-3IKXXUTZ.js +7 -0
- package/package.json +9 -9
- package/dist/chunk-EE2BCC37.js.map +0 -1
- package/dist/span-manager-LGX7QHZ7.js +0 -7
- /package/dist/{span-manager-LGX7QHZ7.js.map → span-manager-3IKXXUTZ.js.map} +0 -0
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.
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
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(
|
|
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)
|
|
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
|
-
|
|
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,11 +4715,14 @@ 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();
|
|
4655
4723
|
pendingDecisionResolvers = /* @__PURE__ */ new Map();
|
|
4656
4724
|
abortControllers = /* @__PURE__ */ new Map();
|
|
4725
|
+
registeredEvals = /* @__PURE__ */ new Map();
|
|
4657
4726
|
mcpManager;
|
|
4658
4727
|
memoryManager;
|
|
4659
4728
|
spanManager = new NoopSpanManager();
|
|
@@ -4703,9 +4772,102 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
|
|
|
4703
4772
|
}
|
|
4704
4773
|
}
|
|
4705
4774
|
/** Register a workflow with the runtime. */
|
|
4775
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4706
4776
|
register(workflow2) {
|
|
4707
4777
|
this.workflows.set(workflow2.name, workflow2);
|
|
4708
4778
|
}
|
|
4779
|
+
/** Register standalone tools for Studio introspection and direct testing. */
|
|
4780
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4781
|
+
registerTool(...tools) {
|
|
4782
|
+
for (const t of tools) {
|
|
4783
|
+
this.tools.set(t.name, t);
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
/** Register standalone agents for Studio playground and introspection. */
|
|
4787
|
+
registerAgent(...agents) {
|
|
4788
|
+
for (const a of agents) {
|
|
4789
|
+
this.agents.set(a._name, a);
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4792
|
+
// ── Introspection (used by Studio) ────────────────────────────────
|
|
4793
|
+
/** Get all registered workflow names. */
|
|
4794
|
+
getWorkflowNames() {
|
|
4795
|
+
return [...this.workflows.keys()];
|
|
4796
|
+
}
|
|
4797
|
+
/** Get a registered workflow by name. */
|
|
4798
|
+
getWorkflow(name) {
|
|
4799
|
+
return this.workflows.get(name);
|
|
4800
|
+
}
|
|
4801
|
+
/** Get all registered workflows. */
|
|
4802
|
+
getWorkflows() {
|
|
4803
|
+
return [...this.workflows.values()];
|
|
4804
|
+
}
|
|
4805
|
+
/** Get all registered standalone tools. */
|
|
4806
|
+
getTools() {
|
|
4807
|
+
return [...this.tools.values()];
|
|
4808
|
+
}
|
|
4809
|
+
/** Get a registered standalone tool by name. */
|
|
4810
|
+
getTool(name) {
|
|
4811
|
+
return this.tools.get(name);
|
|
4812
|
+
}
|
|
4813
|
+
/** Get all registered standalone agents. */
|
|
4814
|
+
getAgents() {
|
|
4815
|
+
return [...this.agents.values()];
|
|
4816
|
+
}
|
|
4817
|
+
/** Get a registered standalone agent by name. */
|
|
4818
|
+
getAgent(name) {
|
|
4819
|
+
return this.agents.get(name);
|
|
4820
|
+
}
|
|
4821
|
+
/**
|
|
4822
|
+
* Register an eval config for Studio introspection and execution.
|
|
4823
|
+
* The config should be the result of `defineEval()` from `@axlsdk/eval`.
|
|
4824
|
+
* An optional `executeWorkflow` function can override the default behavior
|
|
4825
|
+
* of calling `runtime.execute()`.
|
|
4826
|
+
*/
|
|
4827
|
+
registerEval(name, config, executeWorkflow) {
|
|
4828
|
+
this.registeredEvals.set(name, { config, executeWorkflow });
|
|
4829
|
+
}
|
|
4830
|
+
/** Get metadata about all registered evals. */
|
|
4831
|
+
getRegisteredEvals() {
|
|
4832
|
+
const result = [];
|
|
4833
|
+
for (const [name, { config }] of this.registeredEvals) {
|
|
4834
|
+
const cfg = config;
|
|
4835
|
+
result.push({
|
|
4836
|
+
name,
|
|
4837
|
+
workflow: cfg.workflow ?? "unknown",
|
|
4838
|
+
dataset: cfg.dataset?.name ?? "unknown",
|
|
4839
|
+
scorers: (cfg.scorers ?? []).map((s) => s.name ?? "unknown")
|
|
4840
|
+
});
|
|
4841
|
+
}
|
|
4842
|
+
return result;
|
|
4843
|
+
}
|
|
4844
|
+
/** Get a registered eval config by name. */
|
|
4845
|
+
getRegisteredEval(name) {
|
|
4846
|
+
return this.registeredEvals.get(name);
|
|
4847
|
+
}
|
|
4848
|
+
/** Run a registered eval by name. */
|
|
4849
|
+
async runRegisteredEval(name) {
|
|
4850
|
+
const entry = this.registeredEvals.get(name);
|
|
4851
|
+
if (!entry) throw new Error(`Eval "${name}" is not registered`);
|
|
4852
|
+
if (entry.executeWorkflow) {
|
|
4853
|
+
let runEvalFn;
|
|
4854
|
+
try {
|
|
4855
|
+
({ runEval: runEvalFn } = await import("@axlsdk/eval"));
|
|
4856
|
+
} catch {
|
|
4857
|
+
throw new Error(
|
|
4858
|
+
"axl-eval is required for AxlRuntime.runRegisteredEval(). Install it with: npm install @axlsdk/eval"
|
|
4859
|
+
);
|
|
4860
|
+
}
|
|
4861
|
+
return runEvalFn(entry.config, entry.executeWorkflow);
|
|
4862
|
+
}
|
|
4863
|
+
return this.eval(
|
|
4864
|
+
entry.config
|
|
4865
|
+
);
|
|
4866
|
+
}
|
|
4867
|
+
/** Get all execution info (running + completed). */
|
|
4868
|
+
getExecutions() {
|
|
4869
|
+
return [...this.executions.values()];
|
|
4870
|
+
}
|
|
4709
4871
|
/** Register a custom provider instance. */
|
|
4710
4872
|
registerProvider(name, provider) {
|
|
4711
4873
|
this.providerRegistry.registerInstance(name, provider);
|
|
@@ -5085,10 +5247,10 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
|
|
|
5085
5247
|
async eval(config) {
|
|
5086
5248
|
let runEval;
|
|
5087
5249
|
try {
|
|
5088
|
-
({ runEval } = await import("
|
|
5250
|
+
({ runEval } = await import("@axlsdk/eval"));
|
|
5089
5251
|
} catch {
|
|
5090
5252
|
throw new Error(
|
|
5091
|
-
"axl-eval is required for AxlRuntime.eval(). Install it with: npm install
|
|
5253
|
+
"axl-eval is required for AxlRuntime.eval(). Install it with: npm install @axlsdk/eval"
|
|
5092
5254
|
);
|
|
5093
5255
|
}
|
|
5094
5256
|
const executeWorkflow = async (input) => {
|
|
@@ -5115,10 +5277,10 @@ var AxlRuntime = class extends import_node_events2.EventEmitter {
|
|
|
5115
5277
|
async evalCompare(baseline, candidate) {
|
|
5116
5278
|
let evalCompareFn;
|
|
5117
5279
|
try {
|
|
5118
|
-
({ evalCompare: evalCompareFn } = await import("
|
|
5280
|
+
({ evalCompare: evalCompareFn } = await import("@axlsdk/eval"));
|
|
5119
5281
|
} catch {
|
|
5120
5282
|
throw new Error(
|
|
5121
|
-
"axl-eval is required for AxlRuntime.evalCompare(). Install it with: npm install
|
|
5283
|
+
"axl-eval is required for AxlRuntime.evalCompare(). Install it with: npm install @axlsdk/eval"
|
|
5122
5284
|
);
|
|
5123
5285
|
}
|
|
5124
5286
|
return evalCompareFn(baseline, candidate);
|
|
@@ -5405,6 +5567,7 @@ function cosineSimilarity2(a, b) {
|
|
|
5405
5567
|
createSpanManager,
|
|
5406
5568
|
defineConfig,
|
|
5407
5569
|
tool,
|
|
5408
|
-
workflow
|
|
5570
|
+
workflow,
|
|
5571
|
+
zodToJsonSchema
|
|
5409
5572
|
});
|
|
5410
5573
|
//# sourceMappingURL=index.cjs.map
|