@agentick/kernel 0.0.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.
- package/LICENSE +21 -0
- package/README.md +401 -0
- package/dist/.tsbuildinfo.build +1 -0
- package/dist/channel-helpers.d.ts +32 -0
- package/dist/channel-helpers.d.ts.map +1 -0
- package/dist/channel-helpers.js +62 -0
- package/dist/channel-helpers.js.map +1 -0
- package/dist/channel.d.ts +164 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +199 -0
- package/dist/channel.js.map +1 -0
- package/dist/context.d.ts +412 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +289 -0
- package/dist/context.js.map +1 -0
- package/dist/event-buffer.d.ts +208 -0
- package/dist/event-buffer.d.ts.map +1 -0
- package/dist/event-buffer.js +335 -0
- package/dist/event-buffer.js.map +1 -0
- package/dist/execution-helpers.d.ts +179 -0
- package/dist/execution-helpers.d.ts.map +1 -0
- package/dist/execution-helpers.js +212 -0
- package/dist/execution-helpers.js.map +1 -0
- package/dist/execution-tracker.d.ts +61 -0
- package/dist/execution-tracker.d.ts.map +1 -0
- package/dist/execution-tracker.js +319 -0
- package/dist/execution-tracker.js.map +1 -0
- package/dist/guard.d.ts +65 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +15 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +341 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +346 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics-helpers.d.ts +40 -0
- package/dist/metrics-helpers.d.ts.map +1 -0
- package/dist/metrics-helpers.js +72 -0
- package/dist/metrics-helpers.js.map +1 -0
- package/dist/otel-provider.d.ts +54 -0
- package/dist/otel-provider.d.ts.map +1 -0
- package/dist/otel-provider.js +107 -0
- package/dist/otel-provider.js.map +1 -0
- package/dist/procedure-graph.d.ts +136 -0
- package/dist/procedure-graph.d.ts.map +1 -0
- package/dist/procedure-graph.js +272 -0
- package/dist/procedure-graph.js.map +1 -0
- package/dist/procedure.d.ts +757 -0
- package/dist/procedure.d.ts.map +1 -0
- package/dist/procedure.js +895 -0
- package/dist/procedure.js.map +1 -0
- package/dist/schema.d.ts +153 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +385 -0
- package/dist/schema.js.map +1 -0
- package/dist/stream.d.ts +106 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +186 -0
- package/dist/stream.js.map +1 -0
- package/dist/telemetry.d.ts +182 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +124 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +55 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +96 -0
- package/dist/testing.js.map +1 -0
- package/package.json +48 -0
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard to check if an object is an async iterable.
|
|
3
|
+
*
|
|
4
|
+
* @param obj - Object to check
|
|
5
|
+
* @returns `true` if the object has `Symbol.asyncIterator`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const result = await someFunction();
|
|
10
|
+
* if (isAsyncIterable(result)) {
|
|
11
|
+
* for await (const item of result) {
|
|
12
|
+
* console.log(item);
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export { isAsyncIterable } from "./procedure";
|
|
18
|
+
/**
|
|
19
|
+
* Transform items in an async stream using a mapper function.
|
|
20
|
+
*
|
|
21
|
+
* Preserves the current execution context through all iterations.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam T - Input item type
|
|
24
|
+
* @typeParam R - Output item type
|
|
25
|
+
* @param stream - Source async iterable
|
|
26
|
+
* @param mapper - Function to transform each item
|
|
27
|
+
* @returns Async iterable of transformed items
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const numbers = getNumberStream();
|
|
32
|
+
* const doubled = mapStream(numbers, (n) => n * 2);
|
|
33
|
+
* for await (const n of doubled) {
|
|
34
|
+
* console.log(n);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Async mapper
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const users = mapStream(userIds, async (id) => {
|
|
41
|
+
* return await fetchUser(id);
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function mapStream<T, R>(stream: AsyncIterable<T>, mapper: (item: T) => R | Promise<R>): AsyncIterable<R>;
|
|
46
|
+
/**
|
|
47
|
+
* Perform side effects on each stream item without modifying the stream.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam T - Item type
|
|
50
|
+
* @param stream - Source async iterable
|
|
51
|
+
* @param tapper - Side-effect function called for each item
|
|
52
|
+
* @returns Async iterable yielding the original items
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const logged = tapStream(events, (event) => {
|
|
57
|
+
* console.log('Event:', event.type);
|
|
58
|
+
* });
|
|
59
|
+
* for await (const event of logged) {
|
|
60
|
+
* processEvent(event);
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function tapStream<T>(stream: AsyncIterable<T>, tapper: (item: T) => void | Promise<void>): AsyncIterable<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Tagged stream item from {@link mergeStreams} when using a Record input.
|
|
67
|
+
*
|
|
68
|
+
* @typeParam T - The value type from the stream
|
|
69
|
+
*/
|
|
70
|
+
export interface StreamTag<T> {
|
|
71
|
+
/** The key from the input Record identifying which stream this came from */
|
|
72
|
+
source: string;
|
|
73
|
+
/** The actual value from the stream */
|
|
74
|
+
value: T;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Merge multiple async streams into a single stream, yielding items as they arrive.
|
|
78
|
+
*
|
|
79
|
+
* Supports two input formats:
|
|
80
|
+
* - **Array**: Returns items directly (type `T`)
|
|
81
|
+
* - **Record**: Returns tagged items with source key (type `StreamTag<T>`)
|
|
82
|
+
*
|
|
83
|
+
* Handles context propagation, backpressure, and cleanup of all iterators.
|
|
84
|
+
*
|
|
85
|
+
* @typeParam T - Item type
|
|
86
|
+
* @param input - Array of streams or Record mapping names to streams
|
|
87
|
+
* @returns Merged stream of items (or tagged items for Record input)
|
|
88
|
+
*
|
|
89
|
+
* @example Array of streams (untagged)
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const merged = mergeStreams([stream1, stream2, stream3]);
|
|
92
|
+
* for await (const item of merged) {
|
|
93
|
+
* console.log(item); // Items from any stream, in arrival order
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Record of streams (tagged)
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const tagged = mergeStreams({ a: stream1, b: stream2 });
|
|
100
|
+
* for await (const item of tagged) {
|
|
101
|
+
* console.log(item.source, item.value); // 'a' or 'b', plus the value
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function mergeStreams<T>(input: AsyncIterable<T>[] | Record<string, AsyncIterable<T>>): AsyncIterable<T | StreamTag<T>>;
|
|
106
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAuB,SAAS,CAAC,CAAC,EAAE,CAAC,EACnC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAClC,aAAa,CAAC,CAAC,CAAC,CAuBlB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAuB,SAAS,CAAC,CAAC,EAChC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACxC,aAAa,CAAC,CAAC,CAAC,CAKlB;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAuB,YAAY,CAAC,CAAC,EACnC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,GAC3D,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAmEjC"}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Context } from "./context";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if an object is an async iterable.
|
|
4
|
+
*
|
|
5
|
+
* @param obj - Object to check
|
|
6
|
+
* @returns `true` if the object has `Symbol.asyncIterator`
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = await someFunction();
|
|
11
|
+
* if (isAsyncIterable(result)) {
|
|
12
|
+
* for await (const item of result) {
|
|
13
|
+
* console.log(item);
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export { isAsyncIterable } from "./procedure";
|
|
19
|
+
/**
|
|
20
|
+
* Transform items in an async stream using a mapper function.
|
|
21
|
+
*
|
|
22
|
+
* Preserves the current execution context through all iterations.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam T - Input item type
|
|
25
|
+
* @typeParam R - Output item type
|
|
26
|
+
* @param stream - Source async iterable
|
|
27
|
+
* @param mapper - Function to transform each item
|
|
28
|
+
* @returns Async iterable of transformed items
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const numbers = getNumberStream();
|
|
33
|
+
* const doubled = mapStream(numbers, (n) => n * 2);
|
|
34
|
+
* for await (const n of doubled) {
|
|
35
|
+
* console.log(n);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Async mapper
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const users = mapStream(userIds, async (id) => {
|
|
42
|
+
* return await fetchUser(id);
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export async function* mapStream(stream, mapper) {
|
|
47
|
+
// Ensure we iterate inside the current context
|
|
48
|
+
const ctx = Context.tryGet();
|
|
49
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
50
|
+
try {
|
|
51
|
+
while (true) {
|
|
52
|
+
const next = ctx ? await Context.run(ctx, () => iterator.next()) : await iterator.next();
|
|
53
|
+
if (next.done)
|
|
54
|
+
break;
|
|
55
|
+
const mapped = ctx
|
|
56
|
+
? await Context.run(ctx, async () => mapper(next.value))
|
|
57
|
+
: await mapper(next.value);
|
|
58
|
+
yield mapped;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (iterator.return) {
|
|
63
|
+
if (ctx)
|
|
64
|
+
await Context.run(ctx, () => iterator.return());
|
|
65
|
+
else
|
|
66
|
+
await iterator.return();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Perform side effects on each stream item without modifying the stream.
|
|
72
|
+
*
|
|
73
|
+
* @typeParam T - Item type
|
|
74
|
+
* @param stream - Source async iterable
|
|
75
|
+
* @param tapper - Side-effect function called for each item
|
|
76
|
+
* @returns Async iterable yielding the original items
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const logged = tapStream(events, (event) => {
|
|
81
|
+
* console.log('Event:', event.type);
|
|
82
|
+
* });
|
|
83
|
+
* for await (const event of logged) {
|
|
84
|
+
* processEvent(event);
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export async function* tapStream(stream, tapper) {
|
|
89
|
+
yield* mapStream(stream, async (item) => {
|
|
90
|
+
await tapper(item);
|
|
91
|
+
return item;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Merge multiple async streams into a single stream, yielding items as they arrive.
|
|
96
|
+
*
|
|
97
|
+
* Supports two input formats:
|
|
98
|
+
* - **Array**: Returns items directly (type `T`)
|
|
99
|
+
* - **Record**: Returns tagged items with source key (type `StreamTag<T>`)
|
|
100
|
+
*
|
|
101
|
+
* Handles context propagation, backpressure, and cleanup of all iterators.
|
|
102
|
+
*
|
|
103
|
+
* @typeParam T - Item type
|
|
104
|
+
* @param input - Array of streams or Record mapping names to streams
|
|
105
|
+
* @returns Merged stream of items (or tagged items for Record input)
|
|
106
|
+
*
|
|
107
|
+
* @example Array of streams (untagged)
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const merged = mergeStreams([stream1, stream2, stream3]);
|
|
110
|
+
* for await (const item of merged) {
|
|
111
|
+
* console.log(item); // Items from any stream, in arrival order
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example Record of streams (tagged)
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const tagged = mergeStreams({ a: stream1, b: stream2 });
|
|
118
|
+
* for await (const item of tagged) {
|
|
119
|
+
* console.log(item.source, item.value); // 'a' or 'b', plus the value
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export async function* mergeStreams(input) {
|
|
124
|
+
const ctx = Context.tryGet();
|
|
125
|
+
let streams;
|
|
126
|
+
let tags = null;
|
|
127
|
+
if (Array.isArray(input)) {
|
|
128
|
+
streams = input;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
tags = Object.keys(input);
|
|
132
|
+
streams = Object.values(input);
|
|
133
|
+
}
|
|
134
|
+
// Wrap iterators to run in context
|
|
135
|
+
const iterators = streams.map((s) => {
|
|
136
|
+
const iter = s[Symbol.asyncIterator]();
|
|
137
|
+
return {
|
|
138
|
+
next: () => (ctx ? Context.run(ctx, () => iter.next()) : iter.next()),
|
|
139
|
+
return: () => (ctx && iter.return ? Context.run(ctx, () => iter.return()) : iter.return?.()),
|
|
140
|
+
instance: iter,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
// Map of active promises to their iterator index
|
|
145
|
+
const nextPromises = new Map();
|
|
146
|
+
// Initialize all iterators
|
|
147
|
+
for (let i = 0; i < iterators.length; i++) {
|
|
148
|
+
nextPromises.set(i, iterators[i].next());
|
|
149
|
+
}
|
|
150
|
+
while (nextPromises.size > 0) {
|
|
151
|
+
// Create a race between all active promises
|
|
152
|
+
const racePromises = Array.from(nextPromises.entries()).map(async ([index, promise]) => {
|
|
153
|
+
try {
|
|
154
|
+
const result = await promise;
|
|
155
|
+
return { index, result };
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
return { index, error };
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const { index, result, error } = await Promise.race(racePromises);
|
|
162
|
+
if (error) {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
if (result.done) {
|
|
166
|
+
nextPromises.delete(index);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// If tagged, wrap in tag object. Else yield raw.
|
|
170
|
+
if (tags) {
|
|
171
|
+
yield { source: tags[index], value: result.value };
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
yield result.value;
|
|
175
|
+
}
|
|
176
|
+
// Refill
|
|
177
|
+
nextPromises.set(index, iterators[index].next());
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
// Ensure all iterators are closed
|
|
183
|
+
await Promise.all(iterators.map((iter) => iter.return()));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,CAC9B,MAAwB,EACxB,MAAmC;IAEnC,+CAA+C;IAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAEhD,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEzF,IAAI,IAAI,CAAC,IAAI;gBAAE,MAAM;YAErB,MAAM,MAAM,GAAG,GAAG;gBAChB,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAA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AE,MAAM,EAAE,CAAC;gBAC3B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAElE,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,KAAK,CAAC;YACd,CAAC;YAED,IAAI,MAAO,CAAC,IAAI,EAAE,CAAC;gBACjB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACN,iDAAiD;gBACjD,IAAI,IAAI,EAAE,CAAC;oBACT,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,MAAO,CAAC,KAAK,EAAE,CAAC;gBACtD,CAAC;qBAAM,CAAC;oBACN,MAAM,MAAO,CAAC,KAAK,CAAC;gBACtB,CAAC;gBAED,SAAS;gBACT,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,kCAAkC;QAClC,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A span represents a unit of work or operation within a trace.
|
|
3
|
+
* Spans track timing, attributes, and errors for observability.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const span = Telemetry.startSpan('database-query');
|
|
8
|
+
* try {
|
|
9
|
+
* span.setAttribute('query', 'SELECT * FROM users');
|
|
10
|
+
* const result = await db.query(...);
|
|
11
|
+
* span.setAttribute('rowCount', result.length);
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* span.recordError(error);
|
|
14
|
+
* throw error;
|
|
15
|
+
* } finally {
|
|
16
|
+
* span.end();
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface Span {
|
|
21
|
+
/** End the span, recording its duration. */
|
|
22
|
+
end(): void;
|
|
23
|
+
/** Set an attribute on the span for filtering/analysis. */
|
|
24
|
+
setAttribute(key: string, value: any): void;
|
|
25
|
+
/** Record an error that occurred during this span. */
|
|
26
|
+
recordError(error: any): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Attributes for metrics, used for filtering and grouping.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* counter.add(1, { model: 'gpt-4', status: 'success' });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface MetricAttributes {
|
|
37
|
+
[key: string]: string | number | boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A counter metric that only increases (e.g., request count, error count).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const requestCounter = Telemetry.getCounter('requests', 'count', 'Total requests');
|
|
45
|
+
* requestCounter.add(1, { endpoint: '/api/chat' });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface Counter {
|
|
49
|
+
/** Add a value to the counter. */
|
|
50
|
+
add(value: number, attributes?: MetricAttributes): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A histogram metric for recording distributions (e.g., latency, sizes).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const latencyHistogram = Telemetry.getHistogram('latency', 'ms', 'Request latency');
|
|
58
|
+
* latencyHistogram.record(150, { endpoint: '/api/chat' });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export interface Histogram {
|
|
62
|
+
/** Record a value in the histogram. */
|
|
63
|
+
record(value: number, attributes?: MetricAttributes): void;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Interface for telemetry providers (e.g., OpenTelemetry, DataDog).
|
|
67
|
+
*
|
|
68
|
+
* Implement this interface to integrate with your observability platform.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { trace, metrics } from '@opentelemetry/api';
|
|
73
|
+
*
|
|
74
|
+
* const otelProvider: TelemetryProvider = {
|
|
75
|
+
* startTrace(name) { return trace.getTracer('agentick').startSpan(name).spanContext().traceId; },
|
|
76
|
+
* startSpan(name) { return trace.getTracer('agentick').startSpan(name); },
|
|
77
|
+
* // ... implement other methods
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* Telemetry.setProvider(otelProvider);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export interface TelemetryProvider {
|
|
84
|
+
/** Start a new trace and return its ID. */
|
|
85
|
+
startTrace(name: string): string;
|
|
86
|
+
/** Start a new span within the current trace. */
|
|
87
|
+
startSpan(name: string): Span;
|
|
88
|
+
/** Record an error in the current trace/span. */
|
|
89
|
+
recordError(error: any): void;
|
|
90
|
+
/** End the current trace. */
|
|
91
|
+
endTrace(): void;
|
|
92
|
+
/** Get or create a counter metric. */
|
|
93
|
+
getCounter(name: string, unit?: string, description?: string): Counter;
|
|
94
|
+
/** Get or create a histogram metric. */
|
|
95
|
+
getHistogram(name: string, unit?: string, description?: string): Histogram;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Global telemetry service for tracing, spans, and metrics.
|
|
99
|
+
*
|
|
100
|
+
* By default, uses a no-op provider. Call `Telemetry.setProvider()` to integrate
|
|
101
|
+
* with your observability platform (OpenTelemetry, DataDog, etc.).
|
|
102
|
+
*
|
|
103
|
+
* ## Traces and Spans
|
|
104
|
+
*
|
|
105
|
+
* Traces represent end-to-end operations. Spans are units of work within a trace.
|
|
106
|
+
*
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const traceId = Telemetry.startTrace('agent-execution');
|
|
109
|
+
* const span = Telemetry.startSpan('model-call');
|
|
110
|
+
* try {
|
|
111
|
+
* // ... do work
|
|
112
|
+
* span.setAttribute('model', 'gpt-4');
|
|
113
|
+
* } finally {
|
|
114
|
+
* span.end();
|
|
115
|
+
* }
|
|
116
|
+
* Telemetry.endTrace();
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* ## Metrics
|
|
120
|
+
*
|
|
121
|
+
* Counters track cumulative values. Histograms track distributions.
|
|
122
|
+
*
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const tokenCounter = Telemetry.getCounter('tokens', 'count', 'Token usage');
|
|
125
|
+
* tokenCounter.add(150, { model: 'gpt-4', type: 'input' });
|
|
126
|
+
*
|
|
127
|
+
* const latency = Telemetry.getHistogram('latency', 'ms', 'Response time');
|
|
128
|
+
* latency.record(250);
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @see {@link TelemetryProvider} - Implement this to add a custom provider
|
|
132
|
+
*/
|
|
133
|
+
export declare class Telemetry {
|
|
134
|
+
private static provider;
|
|
135
|
+
/**
|
|
136
|
+
* Set the telemetry provider for all Agentick operations.
|
|
137
|
+
* @param provider - The telemetry provider implementation
|
|
138
|
+
*/
|
|
139
|
+
static setProvider(provider: TelemetryProvider): void;
|
|
140
|
+
/**
|
|
141
|
+
* Reset to the default no-op provider.
|
|
142
|
+
*/
|
|
143
|
+
static resetProvider(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Start a new trace.
|
|
146
|
+
* @param name - Name of the trace (e.g., 'agent-execution')
|
|
147
|
+
* @returns The trace ID
|
|
148
|
+
*/
|
|
149
|
+
static startTrace(name?: string): string;
|
|
150
|
+
/**
|
|
151
|
+
* Start a new span within the current trace.
|
|
152
|
+
* @param name - Name of the span (e.g., 'model-call', 'tool-execution')
|
|
153
|
+
* @returns A Span object to track the operation
|
|
154
|
+
*/
|
|
155
|
+
static startSpan(name: string): Span;
|
|
156
|
+
/**
|
|
157
|
+
* Record an error in the current trace/span.
|
|
158
|
+
* @param error - The error to record
|
|
159
|
+
*/
|
|
160
|
+
static recordError(error: any): void;
|
|
161
|
+
/**
|
|
162
|
+
* End the current trace.
|
|
163
|
+
*/
|
|
164
|
+
static endTrace(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Get or create a counter metric.
|
|
167
|
+
* @param name - Metric name (e.g., 'agentick.tokens')
|
|
168
|
+
* @param unit - Unit of measurement (e.g., 'count', 'bytes')
|
|
169
|
+
* @param description - Human-readable description
|
|
170
|
+
* @returns A Counter instance
|
|
171
|
+
*/
|
|
172
|
+
static getCounter(name: string, unit?: string, description?: string): Counter;
|
|
173
|
+
/**
|
|
174
|
+
* Get or create a histogram metric.
|
|
175
|
+
* @param name - Metric name (e.g., 'agentick.latency')
|
|
176
|
+
* @param unit - Unit of measurement (e.g., 'ms', 'bytes')
|
|
177
|
+
* @param description - Human-readable description
|
|
178
|
+
* @returns A Histogram instance
|
|
179
|
+
*/
|
|
180
|
+
static getHistogram(name: string, unit?: string, description?: string): Histogram;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,IAAI;IACnB,4CAA4C;IAC5C,GAAG,IAAI,IAAI,CAAC;IACZ,2DAA2D;IAC3D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAC5C,sDAAsD;IACtD,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;CAC/B;AAED;;;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,IAAI;IAI5B;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,GAAE,MAAoB,GAAG,MAAM;IAIrD;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIpC;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAIpC;;OAEG;IACH,MAAM,CAAC,QAAQ,IAAI,IAAI;IAIvB;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO;IAI7E;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS;CAGlF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
class NoOpProvider {
|
|
2
|
+
startTrace(_name) {
|
|
3
|
+
return `trace-${crypto.randomUUID()}`;
|
|
4
|
+
}
|
|
5
|
+
startSpan(_name) {
|
|
6
|
+
return {
|
|
7
|
+
end: () => { },
|
|
8
|
+
setAttribute: () => { },
|
|
9
|
+
recordError: () => { },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
recordError(error) {
|
|
13
|
+
console.error("Telemetry Error:", error);
|
|
14
|
+
}
|
|
15
|
+
endTrace() { }
|
|
16
|
+
getCounter(_name) {
|
|
17
|
+
return { add: () => { } };
|
|
18
|
+
}
|
|
19
|
+
getHistogram(_name) {
|
|
20
|
+
return { record: () => { } };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Global telemetry service for tracing, spans, and metrics.
|
|
25
|
+
*
|
|
26
|
+
* By default, uses a no-op provider. Call `Telemetry.setProvider()` to integrate
|
|
27
|
+
* with your observability platform (OpenTelemetry, DataDog, etc.).
|
|
28
|
+
*
|
|
29
|
+
* ## Traces and Spans
|
|
30
|
+
*
|
|
31
|
+
* Traces represent end-to-end operations. Spans are units of work within a trace.
|
|
32
|
+
*
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const traceId = Telemetry.startTrace('agent-execution');
|
|
35
|
+
* const span = Telemetry.startSpan('model-call');
|
|
36
|
+
* try {
|
|
37
|
+
* // ... do work
|
|
38
|
+
* span.setAttribute('model', 'gpt-4');
|
|
39
|
+
* } finally {
|
|
40
|
+
* span.end();
|
|
41
|
+
* }
|
|
42
|
+
* Telemetry.endTrace();
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ## Metrics
|
|
46
|
+
*
|
|
47
|
+
* Counters track cumulative values. Histograms track distributions.
|
|
48
|
+
*
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const tokenCounter = Telemetry.getCounter('tokens', 'count', 'Token usage');
|
|
51
|
+
* tokenCounter.add(150, { model: 'gpt-4', type: 'input' });
|
|
52
|
+
*
|
|
53
|
+
* const latency = Telemetry.getHistogram('latency', 'ms', 'Response time');
|
|
54
|
+
* latency.record(250);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see {@link TelemetryProvider} - Implement this to add a custom provider
|
|
58
|
+
*/
|
|
59
|
+
export class Telemetry {
|
|
60
|
+
static provider = new NoOpProvider();
|
|
61
|
+
/**
|
|
62
|
+
* Set the telemetry provider for all Agentick operations.
|
|
63
|
+
* @param provider - The telemetry provider implementation
|
|
64
|
+
*/
|
|
65
|
+
static setProvider(provider) {
|
|
66
|
+
this.provider = provider;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reset to the default no-op provider.
|
|
70
|
+
*/
|
|
71
|
+
static resetProvider() {
|
|
72
|
+
this.provider = new NoOpProvider();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Start a new trace.
|
|
76
|
+
* @param name - Name of the trace (e.g., 'agent-execution')
|
|
77
|
+
* @returns The trace ID
|
|
78
|
+
*/
|
|
79
|
+
static startTrace(name = "operation") {
|
|
80
|
+
return this.provider.startTrace(name);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Start a new span within the current trace.
|
|
84
|
+
* @param name - Name of the span (e.g., 'model-call', 'tool-execution')
|
|
85
|
+
* @returns A Span object to track the operation
|
|
86
|
+
*/
|
|
87
|
+
static startSpan(name) {
|
|
88
|
+
return this.provider.startSpan(name);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Record an error in the current trace/span.
|
|
92
|
+
* @param error - The error to record
|
|
93
|
+
*/
|
|
94
|
+
static recordError(error) {
|
|
95
|
+
this.provider.recordError(error);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* End the current trace.
|
|
99
|
+
*/
|
|
100
|
+
static endTrace() {
|
|
101
|
+
this.provider.endTrace();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get or create a counter metric.
|
|
105
|
+
* @param name - Metric name (e.g., 'agentick.tokens')
|
|
106
|
+
* @param unit - Unit of measurement (e.g., 'count', 'bytes')
|
|
107
|
+
* @param description - Human-readable description
|
|
108
|
+
* @returns A Counter instance
|
|
109
|
+
*/
|
|
110
|
+
static getCounter(name, unit, description) {
|
|
111
|
+
return this.provider.getCounter(name, unit, description);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get or create a histogram metric.
|
|
115
|
+
* @param name - Metric name (e.g., 'agentick.latency')
|
|
116
|
+
* @param unit - Unit of measurement (e.g., 'ms', 'bytes')
|
|
117
|
+
* @param description - Human-readable description
|
|
118
|
+
* @returns A Histogram instance
|
|
119
|
+
*/
|
|
120
|
+
static getHistogram(name, unit, description) {
|
|
121
|
+
return this.provider.getHistogram(name, unit, description);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"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S,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,KAAU;QAC3B,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ;QACb,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,IAAY,EAAE,IAAa,EAAE,WAAoB;QACjE,OAAO,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,IAAY,EAAE,IAAa,EAAE,WAAoB;QACnE,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC7D,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel Testing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides `createTestProcedure` — a lightweight Procedure stub for testing
|
|
5
|
+
* code that *consumes* procedures without needing real middleware, context
|
|
6
|
+
* propagation, or execution tracking.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createTestProcedure } from "@agentick/kernel/testing";
|
|
11
|
+
*
|
|
12
|
+
* const proc = createTestProcedure({ handler: async (x: number) => x * 2 });
|
|
13
|
+
* const result = await proc(5).result; // 10
|
|
14
|
+
* expect(proc._callCount).toBe(1);
|
|
15
|
+
* expect(proc._lastArgs).toEqual([5]);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @module @agentick/kernel/testing
|
|
19
|
+
*/
|
|
20
|
+
import type { Procedure } from "./procedure";
|
|
21
|
+
export interface TestProcedureOptions<TFn extends (...args: any[]) => any> {
|
|
22
|
+
/** Handler function (default: () => undefined) */
|
|
23
|
+
handler?: TFn;
|
|
24
|
+
/** Name for debugging */
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TestProcedure<TFn extends (...args: any[]) => any> extends Procedure<TFn, true> {
|
|
28
|
+
/** Every call recorded: { args, timestamp } */
|
|
29
|
+
_calls: Array<{
|
|
30
|
+
args: any[];
|
|
31
|
+
timestamp: number;
|
|
32
|
+
}>;
|
|
33
|
+
/** Shorthand for _calls.length */
|
|
34
|
+
readonly _callCount: number;
|
|
35
|
+
/** Shorthand for _calls.at(-1)?.args */
|
|
36
|
+
readonly _lastArgs: any[] | undefined;
|
|
37
|
+
/** Override return value for the NEXT call only (reverts after) */
|
|
38
|
+
respondWith(value: ReturnType<TFn> | (() => ReturnType<TFn>)): void;
|
|
39
|
+
/** Override return value for ALL subsequent calls */
|
|
40
|
+
setResponse(value: ReturnType<TFn> | (() => ReturnType<TFn>)): void;
|
|
41
|
+
/** Clear _calls and all overrides */
|
|
42
|
+
reset(): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a test procedure stub.
|
|
46
|
+
*
|
|
47
|
+
* Callable + branded with `PROCEDURE_SYMBOL` so `isProcedure()` returns true.
|
|
48
|
+
* Returns `ProcedurePromise` so `.result` chaining works.
|
|
49
|
+
*
|
|
50
|
+
* Chainable methods (`.use()`, `.withContext()`, etc.) are no-ops returning self.
|
|
51
|
+
* This is intentional — test procedures are for testing code that *calls*
|
|
52
|
+
* procedures, not for testing middleware.
|
|
53
|
+
*/
|
|
54
|
+
export declare function createTestProcedure<TFn extends (...args: any[]) => any>(options?: TestProcedureOptions<TFn>): TestProcedure<TFn>;
|
|
55
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;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