@agent-relay/events 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.
- package/README.md +108 -0
- package/dist/envelope.d.ts +124 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +447 -0
- package/dist/envelope.js.map +1 -0
- package/dist/expand.d.ts +16 -0
- package/dist/expand.d.ts.map +1 -0
- package/dist/expand.js +71 -0
- package/dist/expand.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +29 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +93 -0
- package/dist/logger.js.map +1 -0
- package/dist/otel.d.ts +28 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +234 -0
- package/dist/otel.js.map +1 -0
- package/dist/retry.d.ts +17 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +53 -0
- package/dist/retry.js.map +1 -0
- package/dist/transport.d.ts +6 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +781 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +526 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/package.json +76 -0
package/dist/retry.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NoRetry } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default delivery retry delays from the runtime spec.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000, 1_800_000];
|
|
6
|
+
/**
|
|
7
|
+
* Sleeps for the provided duration.
|
|
8
|
+
*/
|
|
9
|
+
export async function delay(ms, signal) {
|
|
10
|
+
if (signal?.aborted) {
|
|
11
|
+
throw signal.reason instanceof Error ? signal.reason : new Error('Retry delay aborted');
|
|
12
|
+
}
|
|
13
|
+
await new Promise((resolve, reject) => {
|
|
14
|
+
const timeout = setTimeout(resolve, ms);
|
|
15
|
+
const onAbort = () => {
|
|
16
|
+
clearTimeout(timeout);
|
|
17
|
+
reject(signal?.reason instanceof Error ? signal.reason : new Error('Retry delay aborted'));
|
|
18
|
+
};
|
|
19
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Computes the jittered retry delay for a delivery attempt.
|
|
24
|
+
*/
|
|
25
|
+
export function computeRetryDelayMs(attempt, random = Math.random) {
|
|
26
|
+
const index = Math.max(0, Math.min(attempt - 1, DEFAULT_RETRY_DELAYS_MS.length - 1));
|
|
27
|
+
const base = DEFAULT_RETRY_DELAYS_MS[index];
|
|
28
|
+
const jitter = Math.round(base * 0.2 * random());
|
|
29
|
+
return base + jitter;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Runs an async operation with the default runtime retry policy.
|
|
33
|
+
*/
|
|
34
|
+
export async function withRetry(fn, maxAttempts = DEFAULT_RETRY_DELAYS_MS.length, signal) {
|
|
35
|
+
let lastError;
|
|
36
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
37
|
+
try {
|
|
38
|
+
return await fn(attempt);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof NoRetry) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
lastError = error;
|
|
45
|
+
if (attempt >= maxAttempts) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
await delay(computeRetryDelayMs(attempt), signal);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw lastError instanceof Error ? lastError : new Error('Event delivery failed');
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"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KAAK,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,MAAM,EAAE,CAAC,CAAC;IACjD,OAAO,IAAI,GAAG,MAAM,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,EAAmC,EACnC,WAAW,GAAG,uBAAuB,CAAC,MAAM,EAC5C,MAAoB;IAEpB,IAAI,SAAkB,CAAC;IAEvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,WAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;gBAC7B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,SAAS,GAAG,KAAK,CAAC;YAClB,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;gBAC3B,MAAM;YACR,CAAC;YAED,MAAM,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,MAAM,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EventStreamHandle, EventStreamOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Opens a normalized event stream over the runtime gateway websocket.
|
|
4
|
+
*/
|
|
5
|
+
export declare function events(options: EventStreamOptions): EventStreamHandle;
|
|
6
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEV,iBAAiB,EACjB,kBAAkB,EASnB,MAAM,YAAY,CAAC;AAwCpB;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CA6vBrE"}
|