@abassey/aid 0.1.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.
Files changed (53) hide show
  1. package/dist/agents/index.cjs +741 -0
  2. package/dist/agents/index.d.cts +78 -0
  3. package/dist/agents/index.d.ts +78 -0
  4. package/dist/agents/index.js +741 -0
  5. package/dist/ai-AWJOUXFM.js +9 -0
  6. package/dist/ai-DOAYJKKI.cjs +9 -0
  7. package/dist/chunk-2TNYBUNK.js +124 -0
  8. package/dist/chunk-3LGKZRGY.cjs +124 -0
  9. package/dist/chunk-AUR2BBB5.cjs +1436 -0
  10. package/dist/chunk-IJLTRQF4.cjs +276 -0
  11. package/dist/chunk-JPD7UBAZ.js +58 -0
  12. package/dist/chunk-M4RQALTT.js +276 -0
  13. package/dist/chunk-NB65IHJE.cjs +58 -0
  14. package/dist/chunk-YNIEOBDF.js +1436 -0
  15. package/dist/client/index.cjs +18 -0
  16. package/dist/client/index.d.cts +8 -0
  17. package/dist/client/index.d.ts +8 -0
  18. package/dist/client/index.js +18 -0
  19. package/dist/errors-CUVTnseb.d.ts +13 -0
  20. package/dist/errors-CgCce4cK.d.cts +158 -0
  21. package/dist/errors-CgCce4cK.d.ts +158 -0
  22. package/dist/errors-zAPbTlpe.d.cts +13 -0
  23. package/dist/eval/index.cjs +308 -0
  24. package/dist/eval/index.d.cts +106 -0
  25. package/dist/eval/index.d.ts +106 -0
  26. package/dist/eval/index.js +308 -0
  27. package/dist/index.cjs +35 -0
  28. package/dist/index.d.cts +107 -0
  29. package/dist/index.d.ts +107 -0
  30. package/dist/index.js +35 -0
  31. package/dist/middleware/index.cjs +201 -0
  32. package/dist/middleware/index.d.cts +36 -0
  33. package/dist/middleware/index.d.ts +36 -0
  34. package/dist/middleware/index.js +201 -0
  35. package/dist/observability/index.cjs +147 -0
  36. package/dist/observability/index.d.cts +30 -0
  37. package/dist/observability/index.d.ts +30 -0
  38. package/dist/observability/index.js +147 -0
  39. package/dist/react/index.cjs +253 -0
  40. package/dist/react/index.d.cts +64 -0
  41. package/dist/react/index.d.ts +64 -0
  42. package/dist/react/index.js +253 -0
  43. package/dist/serve/index.cjs +545 -0
  44. package/dist/serve/index.d.cts +69 -0
  45. package/dist/serve/index.d.ts +69 -0
  46. package/dist/serve/index.js +545 -0
  47. package/dist/types-BJReASS-.d.cts +196 -0
  48. package/dist/types-BJReASS-.d.ts +196 -0
  49. package/dist/types-CguX3F16.d.cts +173 -0
  50. package/dist/types-CrFH-_qp.d.cts +68 -0
  51. package/dist/types-DvdzPmW0.d.ts +173 -0
  52. package/dist/types-qfE32ADy.d.ts +68 -0
  53. package/package.json +144 -0
@@ -0,0 +1,276 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/client/errors.ts
2
+ var AidClientError = class _AidClientError extends Error {
3
+
4
+
5
+ constructor(code, message, status) {
6
+ super(message);
7
+ this.name = "AidClientError";
8
+ this.code = code;
9
+ this.status = status;
10
+ }
11
+ static fromResponse(body, status) {
12
+ const err = _optionalChain([body, 'optionalAccess', _ => _.error]);
13
+ if (err && typeof err.code === "string" && typeof err.message === "string") {
14
+ return new _AidClientError(err.code, err.message, status);
15
+ }
16
+ return new _AidClientError("unknown", `Request failed with status ${status}`, status);
17
+ }
18
+ };
19
+
20
+ // src/client/sse.ts
21
+ async function* parseSSE(response) {
22
+ const body = response.body;
23
+ if (!body) {
24
+ throw new AidClientError("network", "Response body is null", 0);
25
+ }
26
+ const reader = body.getReader();
27
+ const decoder = new TextDecoder();
28
+ let buffer = "";
29
+ try {
30
+ while (true) {
31
+ const { done, value } = await reader.read();
32
+ if (done) break;
33
+ buffer += decoder.decode(value, { stream: true });
34
+ const parts = buffer.split("\n\n");
35
+ buffer = parts.pop();
36
+ for (const part of parts) {
37
+ if (!part.trim()) continue;
38
+ const lines = part.split("\n");
39
+ let data = "";
40
+ for (const line of lines) {
41
+ if (line.startsWith("data: ")) {
42
+ data += line.slice(6);
43
+ }
44
+ }
45
+ if (data) {
46
+ yield JSON.parse(data);
47
+ }
48
+ }
49
+ }
50
+ if (buffer.trim()) {
51
+ const lines = buffer.split("\n");
52
+ let data = "";
53
+ for (const line of lines) {
54
+ if (line.startsWith("data: ")) {
55
+ data += line.slice(6);
56
+ }
57
+ }
58
+ if (data) {
59
+ yield JSON.parse(data);
60
+ }
61
+ }
62
+ } finally {
63
+ reader.releaseLock();
64
+ }
65
+ }
66
+
67
+ // src/client/client.ts
68
+ var AidClient = class {
69
+
70
+
71
+
72
+ constructor(config) {
73
+ this.baseUrl = config.baseUrl.replace(/\/+$/, "");
74
+ this.headers = _nullishCoalesce(config.headers, () => ( {}));
75
+ this.signal = config.signal;
76
+ }
77
+ async request(method, path, body, signal) {
78
+ const res = await fetch(`${this.baseUrl}${path}`, {
79
+ method,
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ ...this.headers
83
+ },
84
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
85
+ signal: _nullishCoalesce(signal, () => ( this.signal))
86
+ });
87
+ if (!res.ok) {
88
+ const errorBody = await res.json().catch(() => ({}));
89
+ throw AidClientError.fromResponse(errorBody, res.status);
90
+ }
91
+ return await res.json();
92
+ }
93
+ async requestSSE(path, body, signal) {
94
+ const res = await fetch(`${this.baseUrl}${path}`, {
95
+ method: "POST",
96
+ headers: {
97
+ "Content-Type": "application/json",
98
+ ...this.headers
99
+ },
100
+ body: JSON.stringify(body),
101
+ signal: _nullishCoalesce(signal, () => ( this.signal))
102
+ });
103
+ if (!res.ok) {
104
+ const errorBody = await res.json().catch(() => ({}));
105
+ throw AidClientError.fromResponse(errorBody, res.status);
106
+ }
107
+ return res;
108
+ }
109
+ // === Core AI ===
110
+ async ai(prompt, options) {
111
+ const { signal, ...rest } = _nullishCoalesce(options, () => ( {}));
112
+ return this.request("POST", "/ai", { prompt, ...rest }, signal);
113
+ }
114
+ async *stream(prompt, options) {
115
+ const { signal, ...rest } = _nullishCoalesce(options, () => ( {}));
116
+ const res = await this.requestSSE("/ai/stream", { prompt, ...rest }, signal);
117
+ let accumulated = "";
118
+ for await (const raw of parseSSE(res)) {
119
+ const type = raw.type;
120
+ if (type === "text") {
121
+ const delta = _nullishCoalesce(raw.text, () => ( ""));
122
+ accumulated += delta;
123
+ yield {
124
+ type: "text",
125
+ text: accumulated,
126
+ delta
127
+ };
128
+ } else if (type === "done") {
129
+ yield {
130
+ type: "done",
131
+ text: _nullishCoalesce(raw.text, () => ( accumulated)),
132
+ delta: "",
133
+ model: raw.model,
134
+ tokens: raw.tokens,
135
+ cost: raw.cost,
136
+ latencyMs: raw.latencyMs
137
+ };
138
+ } else if (type === "error") {
139
+ yield {
140
+ type: "error",
141
+ text: accumulated,
142
+ delta: "",
143
+ code: raw.code,
144
+ message: raw.message
145
+ };
146
+ }
147
+ }
148
+ }
149
+ // === Agents ===
150
+ async agent(name, task, options) {
151
+ return this.request(
152
+ "POST",
153
+ `/agents/${encodeURIComponent(name)}`,
154
+ { task },
155
+ _optionalChain([options, 'optionalAccess', _2 => _2.signal])
156
+ );
157
+ }
158
+ // Design note: The spec mentions AgentEventStream with `.on()` callbacks.
159
+ // We use a plain AsyncGenerator instead — simpler, composable, and the React
160
+ // hook (useAgent) handles the callback-style consumption pattern.
161
+ async *agentStream(name, task, options) {
162
+ const res = await this.requestSSE(
163
+ `/agents/${encodeURIComponent(name)}/stream`,
164
+ { task },
165
+ _optionalChain([options, 'optionalAccess', _3 => _3.signal])
166
+ );
167
+ yield* parseSSE(res);
168
+ }
169
+ // === Chat ===
170
+ chat(options) {
171
+ return new ChatClient(this, options);
172
+ }
173
+ // Internal: used by ChatClient
174
+ /** @internal */
175
+ async _chatCreate(options) {
176
+ return this.request("POST", "/chat", _nullishCoalesce(options, () => ( {})));
177
+ }
178
+ /** @internal */
179
+ async _chatSend(sessionId, message) {
180
+ return this.request("POST", `/chat/${encodeURIComponent(sessionId)}`, { message });
181
+ }
182
+ /** @internal */
183
+ async *_chatStream(sessionId, message, signal) {
184
+ const res = await this.requestSSE(
185
+ `/chat/${encodeURIComponent(sessionId)}/stream`,
186
+ { message },
187
+ signal
188
+ );
189
+ let accumulated = "";
190
+ for await (const raw of parseSSE(res)) {
191
+ const type = raw.type;
192
+ if (type === "text") {
193
+ const delta = _nullishCoalesce(raw.text, () => ( ""));
194
+ accumulated += delta;
195
+ yield { type: "text", text: accumulated, delta };
196
+ } else if (type === "done") {
197
+ yield {
198
+ type: "done",
199
+ text: _nullishCoalesce(raw.text, () => ( accumulated)),
200
+ delta: "",
201
+ model: raw.model,
202
+ tokens: raw.tokens,
203
+ cost: raw.cost,
204
+ latencyMs: raw.latencyMs
205
+ };
206
+ } else if (type === "error") {
207
+ yield { type: "error", text: accumulated, delta: "", code: raw.code, message: raw.message };
208
+ }
209
+ }
210
+ }
211
+ /** @internal */
212
+ async _chatHistory(sessionId) {
213
+ return this.request("GET", `/chat/${encodeURIComponent(sessionId)}`);
214
+ }
215
+ /** @internal */
216
+ async _chatDelete(sessionId) {
217
+ await this.request("DELETE", `/chat/${encodeURIComponent(sessionId)}`);
218
+ }
219
+ // === Utility ===
220
+ async health() {
221
+ return this.request("GET", "/health");
222
+ }
223
+ async models() {
224
+ const result = await this.request(
225
+ "GET",
226
+ "/models"
227
+ );
228
+ return result.models;
229
+ }
230
+ };
231
+ var ChatClient = (_class = class {
232
+ __init() {this._sessionId = null}
233
+
234
+
235
+ constructor(client, options) {;_class.prototype.__init.call(this);
236
+ this.client = client;
237
+ this.chatOptions = options;
238
+ }
239
+ get sessionId() {
240
+ return this._sessionId;
241
+ }
242
+ async ensureSession() {
243
+ if (!this._sessionId) {
244
+ const session = await this.client._chatCreate(this.chatOptions);
245
+ this._sessionId = session.sessionId;
246
+ }
247
+ return this._sessionId;
248
+ }
249
+ async send(message) {
250
+ const sessionId = await this.ensureSession();
251
+ return this.client._chatSend(sessionId, message);
252
+ }
253
+ async *stream(message, signal) {
254
+ const sessionId = await this.ensureSession();
255
+ yield* this.client._chatStream(sessionId, message, signal);
256
+ }
257
+ async history() {
258
+ if (!this._sessionId) {
259
+ return { sessionId: "", messages: [], createdAt: 0, lastActiveAt: 0 };
260
+ }
261
+ return this.client._chatHistory(this._sessionId);
262
+ }
263
+ async destroy() {
264
+ if (this._sessionId) {
265
+ await this.client._chatDelete(this._sessionId);
266
+ this._sessionId = null;
267
+ }
268
+ }
269
+ }, _class);
270
+
271
+
272
+
273
+
274
+
275
+
276
+ exports.AidClientError = AidClientError; exports.parseSSE = parseSSE; exports.AidClient = AidClient; exports.ChatClient = ChatClient;
@@ -0,0 +1,58 @@
1
+ // src/observability/trace-store.ts
2
+ var InMemoryTraceStore = class {
3
+ spans = /* @__PURE__ */ new Map();
4
+ order = [];
5
+ maxSpans;
6
+ constructor(options) {
7
+ this.maxSpans = options?.maxSpans ?? 1e4;
8
+ }
9
+ add(span) {
10
+ this.spans.set(span.id, span);
11
+ this.order.push(span.id);
12
+ while (this.order.length > this.maxSpans) {
13
+ const oldestId = this.order.shift();
14
+ this.spans.delete(oldestId);
15
+ }
16
+ }
17
+ get(id) {
18
+ return this.spans.get(id);
19
+ }
20
+ list(filter) {
21
+ let spans = Array.from(this.spans.values());
22
+ if (!filter) return spans;
23
+ if (filter.name !== void 0) {
24
+ spans = spans.filter((s) => s.name === filter.name);
25
+ }
26
+ if (filter.model !== void 0) {
27
+ spans = spans.filter((s) => s.model === filter.model);
28
+ }
29
+ if (filter.status !== void 0) {
30
+ spans = spans.filter((s) => s.status === filter.status);
31
+ }
32
+ if (filter.from !== void 0) {
33
+ spans = spans.filter((s) => s.startTime >= filter.from);
34
+ }
35
+ if (filter.to !== void 0) {
36
+ spans = spans.filter((s) => s.startTime < filter.to);
37
+ }
38
+ if (filter.parentId !== void 0) {
39
+ spans = spans.filter((s) => s.parentId === filter.parentId);
40
+ }
41
+ return spans;
42
+ }
43
+ clear() {
44
+ this.spans.clear();
45
+ this.order = [];
46
+ }
47
+ };
48
+
49
+ // src/observability/context.ts
50
+ import { AsyncLocalStorage } from "async_hooks";
51
+ var traceContext = new AsyncLocalStorage();
52
+ var globalTraceStore = new InMemoryTraceStore();
53
+
54
+ export {
55
+ InMemoryTraceStore,
56
+ traceContext,
57
+ globalTraceStore
58
+ };
@@ -0,0 +1,276 @@
1
+ // src/client/errors.ts
2
+ var AidClientError = class _AidClientError extends Error {
3
+ code;
4
+ status;
5
+ constructor(code, message, status) {
6
+ super(message);
7
+ this.name = "AidClientError";
8
+ this.code = code;
9
+ this.status = status;
10
+ }
11
+ static fromResponse(body, status) {
12
+ const err = body?.error;
13
+ if (err && typeof err.code === "string" && typeof err.message === "string") {
14
+ return new _AidClientError(err.code, err.message, status);
15
+ }
16
+ return new _AidClientError("unknown", `Request failed with status ${status}`, status);
17
+ }
18
+ };
19
+
20
+ // src/client/sse.ts
21
+ async function* parseSSE(response) {
22
+ const body = response.body;
23
+ if (!body) {
24
+ throw new AidClientError("network", "Response body is null", 0);
25
+ }
26
+ const reader = body.getReader();
27
+ const decoder = new TextDecoder();
28
+ let buffer = "";
29
+ try {
30
+ while (true) {
31
+ const { done, value } = await reader.read();
32
+ if (done) break;
33
+ buffer += decoder.decode(value, { stream: true });
34
+ const parts = buffer.split("\n\n");
35
+ buffer = parts.pop();
36
+ for (const part of parts) {
37
+ if (!part.trim()) continue;
38
+ const lines = part.split("\n");
39
+ let data = "";
40
+ for (const line of lines) {
41
+ if (line.startsWith("data: ")) {
42
+ data += line.slice(6);
43
+ }
44
+ }
45
+ if (data) {
46
+ yield JSON.parse(data);
47
+ }
48
+ }
49
+ }
50
+ if (buffer.trim()) {
51
+ const lines = buffer.split("\n");
52
+ let data = "";
53
+ for (const line of lines) {
54
+ if (line.startsWith("data: ")) {
55
+ data += line.slice(6);
56
+ }
57
+ }
58
+ if (data) {
59
+ yield JSON.parse(data);
60
+ }
61
+ }
62
+ } finally {
63
+ reader.releaseLock();
64
+ }
65
+ }
66
+
67
+ // src/client/client.ts
68
+ var AidClient = class {
69
+ baseUrl;
70
+ headers;
71
+ signal;
72
+ constructor(config) {
73
+ this.baseUrl = config.baseUrl.replace(/\/+$/, "");
74
+ this.headers = config.headers ?? {};
75
+ this.signal = config.signal;
76
+ }
77
+ async request(method, path, body, signal) {
78
+ const res = await fetch(`${this.baseUrl}${path}`, {
79
+ method,
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ ...this.headers
83
+ },
84
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
85
+ signal: signal ?? this.signal
86
+ });
87
+ if (!res.ok) {
88
+ const errorBody = await res.json().catch(() => ({}));
89
+ throw AidClientError.fromResponse(errorBody, res.status);
90
+ }
91
+ return await res.json();
92
+ }
93
+ async requestSSE(path, body, signal) {
94
+ const res = await fetch(`${this.baseUrl}${path}`, {
95
+ method: "POST",
96
+ headers: {
97
+ "Content-Type": "application/json",
98
+ ...this.headers
99
+ },
100
+ body: JSON.stringify(body),
101
+ signal: signal ?? this.signal
102
+ });
103
+ if (!res.ok) {
104
+ const errorBody = await res.json().catch(() => ({}));
105
+ throw AidClientError.fromResponse(errorBody, res.status);
106
+ }
107
+ return res;
108
+ }
109
+ // === Core AI ===
110
+ async ai(prompt, options) {
111
+ const { signal, ...rest } = options ?? {};
112
+ return this.request("POST", "/ai", { prompt, ...rest }, signal);
113
+ }
114
+ async *stream(prompt, options) {
115
+ const { signal, ...rest } = options ?? {};
116
+ const res = await this.requestSSE("/ai/stream", { prompt, ...rest }, signal);
117
+ let accumulated = "";
118
+ for await (const raw of parseSSE(res)) {
119
+ const type = raw.type;
120
+ if (type === "text") {
121
+ const delta = raw.text ?? "";
122
+ accumulated += delta;
123
+ yield {
124
+ type: "text",
125
+ text: accumulated,
126
+ delta
127
+ };
128
+ } else if (type === "done") {
129
+ yield {
130
+ type: "done",
131
+ text: raw.text ?? accumulated,
132
+ delta: "",
133
+ model: raw.model,
134
+ tokens: raw.tokens,
135
+ cost: raw.cost,
136
+ latencyMs: raw.latencyMs
137
+ };
138
+ } else if (type === "error") {
139
+ yield {
140
+ type: "error",
141
+ text: accumulated,
142
+ delta: "",
143
+ code: raw.code,
144
+ message: raw.message
145
+ };
146
+ }
147
+ }
148
+ }
149
+ // === Agents ===
150
+ async agent(name, task, options) {
151
+ return this.request(
152
+ "POST",
153
+ `/agents/${encodeURIComponent(name)}`,
154
+ { task },
155
+ options?.signal
156
+ );
157
+ }
158
+ // Design note: The spec mentions AgentEventStream with `.on()` callbacks.
159
+ // We use a plain AsyncGenerator instead — simpler, composable, and the React
160
+ // hook (useAgent) handles the callback-style consumption pattern.
161
+ async *agentStream(name, task, options) {
162
+ const res = await this.requestSSE(
163
+ `/agents/${encodeURIComponent(name)}/stream`,
164
+ { task },
165
+ options?.signal
166
+ );
167
+ yield* parseSSE(res);
168
+ }
169
+ // === Chat ===
170
+ chat(options) {
171
+ return new ChatClient(this, options);
172
+ }
173
+ // Internal: used by ChatClient
174
+ /** @internal */
175
+ async _chatCreate(options) {
176
+ return this.request("POST", "/chat", options ?? {});
177
+ }
178
+ /** @internal */
179
+ async _chatSend(sessionId, message) {
180
+ return this.request("POST", `/chat/${encodeURIComponent(sessionId)}`, { message });
181
+ }
182
+ /** @internal */
183
+ async *_chatStream(sessionId, message, signal) {
184
+ const res = await this.requestSSE(
185
+ `/chat/${encodeURIComponent(sessionId)}/stream`,
186
+ { message },
187
+ signal
188
+ );
189
+ let accumulated = "";
190
+ for await (const raw of parseSSE(res)) {
191
+ const type = raw.type;
192
+ if (type === "text") {
193
+ const delta = raw.text ?? "";
194
+ accumulated += delta;
195
+ yield { type: "text", text: accumulated, delta };
196
+ } else if (type === "done") {
197
+ yield {
198
+ type: "done",
199
+ text: raw.text ?? accumulated,
200
+ delta: "",
201
+ model: raw.model,
202
+ tokens: raw.tokens,
203
+ cost: raw.cost,
204
+ latencyMs: raw.latencyMs
205
+ };
206
+ } else if (type === "error") {
207
+ yield { type: "error", text: accumulated, delta: "", code: raw.code, message: raw.message };
208
+ }
209
+ }
210
+ }
211
+ /** @internal */
212
+ async _chatHistory(sessionId) {
213
+ return this.request("GET", `/chat/${encodeURIComponent(sessionId)}`);
214
+ }
215
+ /** @internal */
216
+ async _chatDelete(sessionId) {
217
+ await this.request("DELETE", `/chat/${encodeURIComponent(sessionId)}`);
218
+ }
219
+ // === Utility ===
220
+ async health() {
221
+ return this.request("GET", "/health");
222
+ }
223
+ async models() {
224
+ const result = await this.request(
225
+ "GET",
226
+ "/models"
227
+ );
228
+ return result.models;
229
+ }
230
+ };
231
+ var ChatClient = class {
232
+ _sessionId = null;
233
+ chatOptions;
234
+ client;
235
+ constructor(client, options) {
236
+ this.client = client;
237
+ this.chatOptions = options;
238
+ }
239
+ get sessionId() {
240
+ return this._sessionId;
241
+ }
242
+ async ensureSession() {
243
+ if (!this._sessionId) {
244
+ const session = await this.client._chatCreate(this.chatOptions);
245
+ this._sessionId = session.sessionId;
246
+ }
247
+ return this._sessionId;
248
+ }
249
+ async send(message) {
250
+ const sessionId = await this.ensureSession();
251
+ return this.client._chatSend(sessionId, message);
252
+ }
253
+ async *stream(message, signal) {
254
+ const sessionId = await this.ensureSession();
255
+ yield* this.client._chatStream(sessionId, message, signal);
256
+ }
257
+ async history() {
258
+ if (!this._sessionId) {
259
+ return { sessionId: "", messages: [], createdAt: 0, lastActiveAt: 0 };
260
+ }
261
+ return this.client._chatHistory(this._sessionId);
262
+ }
263
+ async destroy() {
264
+ if (this._sessionId) {
265
+ await this.client._chatDelete(this._sessionId);
266
+ this._sessionId = null;
267
+ }
268
+ }
269
+ };
270
+
271
+ export {
272
+ AidClientError,
273
+ parseSSE,
274
+ AidClient,
275
+ ChatClient
276
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/observability/trace-store.ts
2
+ var InMemoryTraceStore = (_class = class {
3
+ __init() {this.spans = /* @__PURE__ */ new Map()}
4
+ __init2() {this.order = []}
5
+
6
+ constructor(options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
7
+ this.maxSpans = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.maxSpans]), () => ( 1e4));
8
+ }
9
+ add(span) {
10
+ this.spans.set(span.id, span);
11
+ this.order.push(span.id);
12
+ while (this.order.length > this.maxSpans) {
13
+ const oldestId = this.order.shift();
14
+ this.spans.delete(oldestId);
15
+ }
16
+ }
17
+ get(id) {
18
+ return this.spans.get(id);
19
+ }
20
+ list(filter) {
21
+ let spans = Array.from(this.spans.values());
22
+ if (!filter) return spans;
23
+ if (filter.name !== void 0) {
24
+ spans = spans.filter((s) => s.name === filter.name);
25
+ }
26
+ if (filter.model !== void 0) {
27
+ spans = spans.filter((s) => s.model === filter.model);
28
+ }
29
+ if (filter.status !== void 0) {
30
+ spans = spans.filter((s) => s.status === filter.status);
31
+ }
32
+ if (filter.from !== void 0) {
33
+ spans = spans.filter((s) => s.startTime >= filter.from);
34
+ }
35
+ if (filter.to !== void 0) {
36
+ spans = spans.filter((s) => s.startTime < filter.to);
37
+ }
38
+ if (filter.parentId !== void 0) {
39
+ spans = spans.filter((s) => s.parentId === filter.parentId);
40
+ }
41
+ return spans;
42
+ }
43
+ clear() {
44
+ this.spans.clear();
45
+ this.order = [];
46
+ }
47
+ }, _class);
48
+
49
+ // src/observability/context.ts
50
+ var _async_hooks = require('async_hooks');
51
+ var traceContext = new (0, _async_hooks.AsyncLocalStorage)();
52
+ var globalTraceStore = new InMemoryTraceStore();
53
+
54
+
55
+
56
+
57
+
58
+ exports.InMemoryTraceStore = InMemoryTraceStore; exports.traceContext = traceContext; exports.globalTraceStore = globalTraceStore;