eve 0.27.1 → 0.27.2
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/CHANGELOG.md +13 -0
- package/dist/src/chunks/{use-eve-agent-PMY2WkAt.js → use-eve-agent-CbF0l_Fp.js} +66 -27
- package/dist/src/chunks/{use-eve-agent-AeQLLhu9.js → use-eve-agent-CgxB9WQv.js} +66 -27
- package/dist/src/client/index.d.ts +1 -1
- package/dist/src/client/open-stream.d.ts +15 -2
- package/dist/src/client/open-stream.js +1 -1
- package/dist/src/client/session.d.ts +3 -2
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/types.d.ts +32 -0
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-module-evaluation-error.d.ts +2 -0
- package/dist/src/internal/authored-module-evaluation-error.js +4 -0
- package/dist/src/internal/authored-module-loader.js +2 -2
- package/dist/src/packages/eve-catalog/src/index.js +1 -1
- package/dist/src/public/channels/eve.js +2 -1
- package/dist/src/public/channels/slack/api.d.ts +26 -2
- package/dist/src/public/channels/slack/api.js +1 -1
- package/dist/src/public/channels/slack/attachments.d.ts +6 -5
- package/dist/src/public/channels/slack/index.d.ts +1 -1
- package/dist/src/public/channels/slack/interactions.d.ts +2 -1
- package/dist/src/public/channels/slack/interactions.js +1 -1
- package/dist/src/public/channels/slack/slackChannel.d.ts +51 -14
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/slack/thread.d.ts +4 -3
- package/dist/src/public/channels/slack/thread.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/channels/slack.mdx +40 -3
- package/docs/guides/client/streaming.mdx +15 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# eve
|
|
2
2
|
|
|
3
|
+
## 0.27.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6c433f4: Expose thread-scoped cancellation in Slack message and interaction contexts, plus target-addressed cancellation in `onEvent`, so authored Slack handlers can stop or replace in-flight turns.
|
|
8
|
+
- 835f076: Emit an initial NDJSON whitespace byte when opening a session event stream so clients and proxies receive the response body before the first durable event.
|
|
9
|
+
- f36f143: Added `thread.listParticipants()` for Slack thread routing based on the unique human participants in first-appearance order.
|
|
10
|
+
- eb92ee3: Allow `session.send()` and `session.stream()` callers to disable automatic stream reconnection with `streamReconnectPolicy: { reconnect: false }`, so relays and proxies can own cursor recovery and retry policy.
|
|
11
|
+
- 4133ffc: Slack thread helpers now reuse messages loaded within the same inbound handler, while overlapping `thread.refresh()` calls share one request and failed refreshes preserve the last successful snapshot.
|
|
12
|
+
- ee72db8: Messages posted by the installed Slack app are now ignored before reaching message hooks to prevent self-reply loops.
|
|
13
|
+
- bd4397b: Fixed Slack `threadContext` with `since: "last-agent-reply"` so only replies from the installed app move the context boundary. Replies from other bots remain part of the incremental thread context, are labeled `bot` instead of `agent` in the injected transcript, and their file uploads are now eligible for mention attachment lookback.
|
|
14
|
+
- 64dbe2b: Add actionable authored-module evaluation errors that identify installed packages and distinguish extensionless ESM from missing package output while preserving the original failure as the cause.
|
|
15
|
+
|
|
3
16
|
## 0.27.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -471,24 +471,58 @@ function formatSearch(searchParams) {
|
|
|
471
471
|
|
|
472
472
|
//#endregion
|
|
473
473
|
//#region src/client/open-stream.ts
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
474
|
+
const DEFAULT_STREAM_RECONNECT_POLICY = {
|
|
475
|
+
retryableErrorStatuses: new Set([
|
|
476
|
+
404,
|
|
477
|
+
409,
|
|
478
|
+
425,
|
|
479
|
+
500,
|
|
480
|
+
502,
|
|
481
|
+
503,
|
|
482
|
+
504
|
|
483
|
+
]),
|
|
484
|
+
streamIdleReconnectPolicy: {
|
|
485
|
+
baseDelayMs: 250,
|
|
486
|
+
maxAttempts: 5,
|
|
487
|
+
maxDelayMs: 4e3
|
|
488
|
+
},
|
|
489
|
+
streamOpenReconnectPolicy: {
|
|
490
|
+
baseDelayMs: 250,
|
|
491
|
+
maxAttempts: 12,
|
|
492
|
+
maxDelayMs: 5e3
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
const NO_STREAM_RECONNECT_POLICY = {
|
|
496
|
+
...DEFAULT_STREAM_RECONNECT_POLICY,
|
|
497
|
+
streamIdleReconnectPolicy: {
|
|
498
|
+
...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
|
|
499
|
+
maxAttempts: 0
|
|
500
|
+
},
|
|
501
|
+
streamOpenReconnectPolicy: {
|
|
502
|
+
...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,
|
|
503
|
+
maxAttempts: 1
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
function resolveRetryPolicy(policy, defaults) {
|
|
507
|
+
return {
|
|
508
|
+
...defaults,
|
|
509
|
+
...policy
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function resolveStreamReconnectPolicy(policy) {
|
|
513
|
+
if (policy && "reconnect" in policy && policy.reconnect === false) return NO_STREAM_RECONNECT_POLICY;
|
|
514
|
+
const configured = policy;
|
|
515
|
+
return {
|
|
516
|
+
retryableErrorStatuses: configured?.retryableErrorStatuses ? new Set(configured.retryableErrorStatuses) : DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,
|
|
517
|
+
streamIdleReconnectPolicy: resolveRetryPolicy(configured?.streamIdleReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy),
|
|
518
|
+
streamOpenReconnectPolicy: resolveRetryPolicy(configured?.streamOpenReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)
|
|
519
|
+
};
|
|
520
|
+
}
|
|
489
521
|
async function* followStreamIterable(input) {
|
|
522
|
+
const retryPolicy = resolveStreamReconnectPolicy(input.streamReconnectPolicy);
|
|
523
|
+
const idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
|
|
490
524
|
let startIndex = input.startIndex;
|
|
491
|
-
let reconnectDelayMs =
|
|
525
|
+
let reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
492
526
|
let idleReconnects = 0;
|
|
493
527
|
let initialConnection = true;
|
|
494
528
|
while (true) {
|
|
@@ -496,6 +530,7 @@ async function* followStreamIterable(input) {
|
|
|
496
530
|
try {
|
|
497
531
|
body = await openStreamBody({
|
|
498
532
|
...input,
|
|
533
|
+
retryPolicy,
|
|
499
534
|
startIndex
|
|
500
535
|
});
|
|
501
536
|
} catch (error) {
|
|
@@ -507,27 +542,29 @@ async function* followStreamIterable(input) {
|
|
|
507
542
|
for await (const event of readNdjsonStream(body)) {
|
|
508
543
|
startIndex += 1;
|
|
509
544
|
deliveredEvent = true;
|
|
510
|
-
reconnectDelayMs =
|
|
545
|
+
reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
511
546
|
idleReconnects = 0;
|
|
512
547
|
yield event;
|
|
513
548
|
}
|
|
514
549
|
} catch (error) {
|
|
515
550
|
if (!isStreamDisconnectError(error)) throw error;
|
|
516
551
|
}
|
|
517
|
-
if (input.signal?.aborted || input.startIndex < 0) return;
|
|
518
|
-
if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >=
|
|
552
|
+
if (input.signal?.aborted || input.startIndex < 0 || idleRetryPolicy.maxAttempts === 0) return;
|
|
553
|
+
if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >= idleRetryPolicy.maxAttempts) return;
|
|
519
554
|
initialConnection = false;
|
|
520
555
|
await sleep$1(reconnectDelayMs, input.signal);
|
|
521
556
|
if (input.signal?.aborted) return;
|
|
522
|
-
reconnectDelayMs = Math.min(reconnectDelayMs * 2,
|
|
557
|
+
reconnectDelayMs = Math.min(reconnectDelayMs * 2, idleRetryPolicy.maxDelayMs);
|
|
523
558
|
}
|
|
524
559
|
}
|
|
525
560
|
async function openStreamBody(input) {
|
|
561
|
+
const retryPolicy = input.retryPolicy ?? DEFAULT_STREAM_RECONNECT_POLICY;
|
|
562
|
+
const openRetryPolicy = retryPolicy.streamOpenReconnectPolicy;
|
|
526
563
|
let lastStatus;
|
|
527
564
|
let lastBody;
|
|
528
565
|
let lastHeaders;
|
|
529
|
-
let retryDelayMs =
|
|
530
|
-
for (let attempt = 0; attempt <
|
|
566
|
+
let retryDelayMs = openRetryPolicy.baseDelayMs;
|
|
567
|
+
for (let attempt = 0; attempt < openRetryPolicy.maxAttempts; attempt += 1) {
|
|
531
568
|
const url = createClientUrl(input.host, createEveMessageStreamRoutePath(input.sessionId), input.startIndex !== 0 ? { startIndex: String(input.startIndex) } : void 0);
|
|
532
569
|
const headers = await input.resolveHeaders();
|
|
533
570
|
let response;
|
|
@@ -538,9 +575,9 @@ async function openStreamBody(input) {
|
|
|
538
575
|
signal: input.signal ?? null
|
|
539
576
|
});
|
|
540
577
|
} catch (error) {
|
|
541
|
-
if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt ===
|
|
578
|
+
if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt === openRetryPolicy.maxAttempts - 1) throw error;
|
|
542
579
|
await sleep$1(retryDelayMs, input.signal);
|
|
543
|
-
retryDelayMs = Math.min(retryDelayMs * 2,
|
|
580
|
+
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
544
581
|
continue;
|
|
545
582
|
}
|
|
546
583
|
if (response.ok) {
|
|
@@ -550,10 +587,10 @@ async function openStreamBody(input) {
|
|
|
550
587
|
lastStatus = response.status;
|
|
551
588
|
lastBody = await response.text();
|
|
552
589
|
lastHeaders = response.headers;
|
|
553
|
-
if (!
|
|
554
|
-
if (attempt <
|
|
590
|
+
if (!retryPolicy.retryableErrorStatuses.has(response.status)) throw new ClientError(response.status, lastBody, response.headers);
|
|
591
|
+
if (attempt < openRetryPolicy.maxAttempts - 1) {
|
|
555
592
|
await sleep$1(retryDelayMs, input.signal);
|
|
556
|
-
retryDelayMs = Math.min(retryDelayMs * 2,
|
|
593
|
+
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
557
594
|
}
|
|
558
595
|
}
|
|
559
596
|
throw new ClientError(lastStatus ?? 0, lastBody ?? "Failed to open message stream.", lastHeaders);
|
|
@@ -734,6 +771,7 @@ var ClientSession = class {
|
|
|
734
771
|
host: this.#context.host,
|
|
735
772
|
resolveHeaders: () => this.#context.resolveHeaders(input.headers),
|
|
736
773
|
redirect: this.#context.redirect,
|
|
774
|
+
streamReconnectPolicy: input.streamReconnectPolicy,
|
|
737
775
|
sessionId,
|
|
738
776
|
signal: input.signal,
|
|
739
777
|
startIndex: initialState.sessionId === sessionId ? initialState.streamIndex : 0
|
|
@@ -761,6 +799,7 @@ var ClientSession = class {
|
|
|
761
799
|
host: this.#context.host,
|
|
762
800
|
resolveHeaders: () => this.#context.resolveHeaders(),
|
|
763
801
|
redirect: this.#context.redirect,
|
|
802
|
+
streamReconnectPolicy: options?.streamReconnectPolicy,
|
|
764
803
|
sessionId,
|
|
765
804
|
signal: options?.signal,
|
|
766
805
|
startIndex: streamIndex
|
|
@@ -471,24 +471,58 @@ function formatSearch(searchParams) {
|
|
|
471
471
|
|
|
472
472
|
//#endregion
|
|
473
473
|
//#region src/client/open-stream.ts
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
474
|
+
const DEFAULT_STREAM_RECONNECT_POLICY = {
|
|
475
|
+
retryableErrorStatuses: new Set([
|
|
476
|
+
404,
|
|
477
|
+
409,
|
|
478
|
+
425,
|
|
479
|
+
500,
|
|
480
|
+
502,
|
|
481
|
+
503,
|
|
482
|
+
504
|
|
483
|
+
]),
|
|
484
|
+
streamIdleReconnectPolicy: {
|
|
485
|
+
baseDelayMs: 250,
|
|
486
|
+
maxAttempts: 5,
|
|
487
|
+
maxDelayMs: 4e3
|
|
488
|
+
},
|
|
489
|
+
streamOpenReconnectPolicy: {
|
|
490
|
+
baseDelayMs: 250,
|
|
491
|
+
maxAttempts: 12,
|
|
492
|
+
maxDelayMs: 5e3
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
const NO_STREAM_RECONNECT_POLICY = {
|
|
496
|
+
...DEFAULT_STREAM_RECONNECT_POLICY,
|
|
497
|
+
streamIdleReconnectPolicy: {
|
|
498
|
+
...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
|
|
499
|
+
maxAttempts: 0
|
|
500
|
+
},
|
|
501
|
+
streamOpenReconnectPolicy: {
|
|
502
|
+
...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,
|
|
503
|
+
maxAttempts: 1
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
function resolveRetryPolicy(policy, defaults) {
|
|
507
|
+
return {
|
|
508
|
+
...defaults,
|
|
509
|
+
...policy
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function resolveStreamReconnectPolicy(policy) {
|
|
513
|
+
if (policy && "reconnect" in policy && policy.reconnect === false) return NO_STREAM_RECONNECT_POLICY;
|
|
514
|
+
const configured = policy;
|
|
515
|
+
return {
|
|
516
|
+
retryableErrorStatuses: configured?.retryableErrorStatuses ? new Set(configured.retryableErrorStatuses) : DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,
|
|
517
|
+
streamIdleReconnectPolicy: resolveRetryPolicy(configured?.streamIdleReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy),
|
|
518
|
+
streamOpenReconnectPolicy: resolveRetryPolicy(configured?.streamOpenReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)
|
|
519
|
+
};
|
|
520
|
+
}
|
|
489
521
|
async function* followStreamIterable(input) {
|
|
522
|
+
const retryPolicy = resolveStreamReconnectPolicy(input.streamReconnectPolicy);
|
|
523
|
+
const idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
|
|
490
524
|
let startIndex = input.startIndex;
|
|
491
|
-
let reconnectDelayMs =
|
|
525
|
+
let reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
492
526
|
let idleReconnects = 0;
|
|
493
527
|
let initialConnection = true;
|
|
494
528
|
while (true) {
|
|
@@ -496,6 +530,7 @@ async function* followStreamIterable(input) {
|
|
|
496
530
|
try {
|
|
497
531
|
body = await openStreamBody({
|
|
498
532
|
...input,
|
|
533
|
+
retryPolicy,
|
|
499
534
|
startIndex
|
|
500
535
|
});
|
|
501
536
|
} catch (error) {
|
|
@@ -507,27 +542,29 @@ async function* followStreamIterable(input) {
|
|
|
507
542
|
for await (const event of readNdjsonStream(body)) {
|
|
508
543
|
startIndex += 1;
|
|
509
544
|
deliveredEvent = true;
|
|
510
|
-
reconnectDelayMs =
|
|
545
|
+
reconnectDelayMs = idleRetryPolicy.baseDelayMs;
|
|
511
546
|
idleReconnects = 0;
|
|
512
547
|
yield event;
|
|
513
548
|
}
|
|
514
549
|
} catch (error) {
|
|
515
550
|
if (!isStreamDisconnectError(error)) throw error;
|
|
516
551
|
}
|
|
517
|
-
if (input.signal?.aborted || input.startIndex < 0) return;
|
|
518
|
-
if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >=
|
|
552
|
+
if (input.signal?.aborted || input.startIndex < 0 || idleRetryPolicy.maxAttempts === 0) return;
|
|
553
|
+
if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >= idleRetryPolicy.maxAttempts) return;
|
|
519
554
|
initialConnection = false;
|
|
520
555
|
await sleep$1(reconnectDelayMs, input.signal);
|
|
521
556
|
if (input.signal?.aborted) return;
|
|
522
|
-
reconnectDelayMs = Math.min(reconnectDelayMs * 2,
|
|
557
|
+
reconnectDelayMs = Math.min(reconnectDelayMs * 2, idleRetryPolicy.maxDelayMs);
|
|
523
558
|
}
|
|
524
559
|
}
|
|
525
560
|
async function openStreamBody(input) {
|
|
561
|
+
const retryPolicy = input.retryPolicy ?? DEFAULT_STREAM_RECONNECT_POLICY;
|
|
562
|
+
const openRetryPolicy = retryPolicy.streamOpenReconnectPolicy;
|
|
526
563
|
let lastStatus;
|
|
527
564
|
let lastBody;
|
|
528
565
|
let lastHeaders;
|
|
529
|
-
let retryDelayMs =
|
|
530
|
-
for (let attempt = 0; attempt <
|
|
566
|
+
let retryDelayMs = openRetryPolicy.baseDelayMs;
|
|
567
|
+
for (let attempt = 0; attempt < openRetryPolicy.maxAttempts; attempt += 1) {
|
|
531
568
|
const url = createClientUrl(input.host, createEveMessageStreamRoutePath(input.sessionId), input.startIndex !== 0 ? { startIndex: String(input.startIndex) } : void 0);
|
|
532
569
|
const headers = await input.resolveHeaders();
|
|
533
570
|
let response;
|
|
@@ -538,9 +575,9 @@ async function openStreamBody(input) {
|
|
|
538
575
|
signal: input.signal ?? null
|
|
539
576
|
});
|
|
540
577
|
} catch (error) {
|
|
541
|
-
if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt ===
|
|
578
|
+
if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt === openRetryPolicy.maxAttempts - 1) throw error;
|
|
542
579
|
await sleep$1(retryDelayMs, input.signal);
|
|
543
|
-
retryDelayMs = Math.min(retryDelayMs * 2,
|
|
580
|
+
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
544
581
|
continue;
|
|
545
582
|
}
|
|
546
583
|
if (response.ok) {
|
|
@@ -550,10 +587,10 @@ async function openStreamBody(input) {
|
|
|
550
587
|
lastStatus = response.status;
|
|
551
588
|
lastBody = await response.text();
|
|
552
589
|
lastHeaders = response.headers;
|
|
553
|
-
if (!
|
|
554
|
-
if (attempt <
|
|
590
|
+
if (!retryPolicy.retryableErrorStatuses.has(response.status)) throw new ClientError(response.status, lastBody, response.headers);
|
|
591
|
+
if (attempt < openRetryPolicy.maxAttempts - 1) {
|
|
555
592
|
await sleep$1(retryDelayMs, input.signal);
|
|
556
|
-
retryDelayMs = Math.min(retryDelayMs * 2,
|
|
593
|
+
retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
|
|
557
594
|
}
|
|
558
595
|
}
|
|
559
596
|
throw new ClientError(lastStatus ?? 0, lastBody ?? "Failed to open message stream.", lastHeaders);
|
|
@@ -734,6 +771,7 @@ var ClientSession = class {
|
|
|
734
771
|
host: this.#context.host,
|
|
735
772
|
resolveHeaders: () => this.#context.resolveHeaders(input.headers),
|
|
736
773
|
redirect: this.#context.redirect,
|
|
774
|
+
streamReconnectPolicy: input.streamReconnectPolicy,
|
|
737
775
|
sessionId,
|
|
738
776
|
signal: input.signal,
|
|
739
777
|
startIndex: initialState.sessionId === sessionId ? initialState.streamIndex : 0
|
|
@@ -761,6 +799,7 @@ var ClientSession = class {
|
|
|
761
799
|
host: this.#context.host,
|
|
762
800
|
resolveHeaders: () => this.#context.resolveHeaders(),
|
|
763
801
|
redirect: this.#context.redirect,
|
|
802
|
+
streamReconnectPolicy: options?.streamReconnectPolicy,
|
|
764
803
|
sessionId,
|
|
765
804
|
signal: options?.signal,
|
|
766
805
|
startIndex: streamIndex
|
|
@@ -7,7 +7,7 @@ export { createDataUrlFilePart, createTextWithFileContent } from "#client/file-p
|
|
|
7
7
|
export { MessageResponse } from "#client/message-response.js";
|
|
8
8
|
export { ClientSession } from "#client/session.js";
|
|
9
9
|
export type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot, EveAgentStoreStatus, PrepareSend, } from "#client/eve-agent-store.js";
|
|
10
|
-
export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, SendTurnInput, SendTurnPayload, SessionState, StreamOptions, TokenValue, } from "#client/types.js";
|
|
10
|
+
export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, ResolvedStreamReconnectPolicy, SendTurnInput, SendTurnPayload, SessionState, StreamOptions, StreamReconnectPolicy, StreamReconnectRetryPolicy, TokenValue, } from "#client/types.js";
|
|
11
11
|
export type { EveAgentReducer, EveAgentReducerEvent, ClientInputRespondedEvent, ClientMessageFailedEvent, ClientMessageSubmittedEvent, } from "#client/reducer.js";
|
|
12
12
|
export type { EveAuthorizationChallenge, EveAuthorizationOutcome, EveAuthorizationPart, EveMessageData, EveDynamicToolPart, EveMessageInputRequest, EveMessage, EveMessageMetadata, EveMessagePart, EveMessageToolMetadata, } from "#client/message-reducer.js";
|
|
13
13
|
export type { ActionResultStreamEvent, ActionsRequestedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, SubagentCalledStreamEvent, SubagentChildEventStreamEvent, SubagentCompletedStreamEvent, SubagentStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, } from "#protocol/message.js";
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
2
|
-
import type { ClientRedirectPolicy } from "#client/types.js";
|
|
2
|
+
import type { ClientRedirectPolicy, StreamReconnectPolicy } from "#client/types.js";
|
|
3
|
+
interface RetryPolicy {
|
|
4
|
+
readonly baseDelayMs: number;
|
|
5
|
+
readonly maxAttempts: number;
|
|
6
|
+
readonly maxDelayMs: number;
|
|
7
|
+
}
|
|
8
|
+
interface ResolvedStreamReconnectPolicy {
|
|
9
|
+
readonly retryableErrorStatuses: ReadonlySet<number>;
|
|
10
|
+
readonly streamIdleReconnectPolicy: RetryPolicy;
|
|
11
|
+
readonly streamOpenReconnectPolicy: RetryPolicy;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Internal configuration for following a durable event stream.
|
|
5
15
|
*/
|
|
6
16
|
interface FollowStreamInput {
|
|
7
17
|
readonly host: string;
|
|
18
|
+
readonly streamReconnectPolicy?: StreamReconnectPolicy;
|
|
8
19
|
readonly resolveHeaders: () => Promise<Headers>;
|
|
9
20
|
readonly redirect?: ClientRedirectPolicy;
|
|
10
21
|
readonly sessionId: string;
|
|
@@ -27,5 +38,7 @@ export declare function followStreamIterable(input: FollowStreamInput): AsyncGen
|
|
|
27
38
|
* propagation window where a just-acknowledged session may not yet be
|
|
28
39
|
* readable from the stream route.
|
|
29
40
|
*/
|
|
30
|
-
export declare function openStreamBody(input: FollowStreamInput
|
|
41
|
+
export declare function openStreamBody(input: FollowStreamInput & {
|
|
42
|
+
readonly retryPolicy?: ResolvedStreamReconnectPolicy;
|
|
43
|
+
}): Promise<ReadableStream<Uint8Array>>;
|
|
31
44
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEveMessageStreamRoutePath}from"#protocol/routes.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{isStreamDisconnectError,readNdjsonStream}from"#client/ndjson.js";const
|
|
1
|
+
import{createEveMessageStreamRoutePath}from"#protocol/routes.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{isStreamDisconnectError,readNdjsonStream}from"#client/ndjson.js";const DEFAULT_STREAM_RECONNECT_POLICY={retryableErrorStatuses:new Set([404,409,425,500,502,503,504]),streamIdleReconnectPolicy:{baseDelayMs:250,maxAttempts:5,maxDelayMs:4e3},streamOpenReconnectPolicy:{baseDelayMs:250,maxAttempts:12,maxDelayMs:5e3}},NO_STREAM_RECONNECT_POLICY={...DEFAULT_STREAM_RECONNECT_POLICY,streamIdleReconnectPolicy:{...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,maxAttempts:0},streamOpenReconnectPolicy:{...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,maxAttempts:1}};function resolveRetryPolicy(e,t){return{...t,...e}}function resolveStreamReconnectPolicy(e){if(e&&`reconnect`in e&&e.reconnect===!1)return NO_STREAM_RECONNECT_POLICY;let t=e;return{retryableErrorStatuses:t?.retryableErrorStatuses?new Set(t.retryableErrorStatuses):DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,streamIdleReconnectPolicy:resolveRetryPolicy(t?.streamIdleReconnectPolicy,DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy),streamOpenReconnectPolicy:resolveRetryPolicy(t?.streamOpenReconnectPolicy,DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)}}async function*followStreamIterable(e){let t=resolveStreamReconnectPolicy(e.streamReconnectPolicy),n=t.streamIdleReconnectPolicy,a=e.startIndex,o=n.baseDelayMs,s=0,c=!0;for(;;){let l;try{l=await openStreamBody({...e,retryPolicy:t,startIndex:a})}catch(t){if(e.signal?.aborted)return;throw t}let u=!1;try{for await(let e of readNdjsonStream(l))a+=1,u=!0,o=n.baseDelayMs,s=0,yield e}catch(e){if(!isStreamDisconnectError(e))throw e}if(e.signal?.aborted||e.startIndex<0||n.maxAttempts===0||!u&&!c&&(s+=1)>=n.maxAttempts||(c=!1,await sleep(o,e.signal),e.signal?.aborted))return;o=Math.min(o*2,n.maxDelayMs)}}async function openStreamBody(i){let o=i.retryPolicy??DEFAULT_STREAM_RECONNECT_POLICY,s=o.streamOpenReconnectPolicy,c,l,u,d=s.baseDelayMs;for(let a=0;a<s.maxAttempts;a+=1){let f=createClientUrl(i.host,createEveMessageStreamRoutePath(i.sessionId),i.startIndex===0?void 0:{startIndex:String(i.startIndex)}),p=await i.resolveHeaders(),m;try{m=await fetch(f,{headers:p,redirect:i.redirect,signal:i.signal??null})}catch(e){if(i.signal?.aborted||!isStreamDisconnectError(e)||a===s.maxAttempts-1)throw e;await sleep(d,i.signal),d=Math.min(d*2,s.maxDelayMs);continue}if(m.ok){if(!m.body)throw new ClientError(m.status,`Response body is null.`,m.headers);return m.body}if(c=m.status,l=await m.text(),u=m.headers,!o.retryableErrorStatuses.has(m.status))throw new ClientError(m.status,l,m.headers);a<s.maxAttempts-1&&(await sleep(d,i.signal),d=Math.min(d*2,s.maxDelayMs))}throw new ClientError(c??0,l??`Failed to open message stream.`,u)}async function sleep(e,t){t?.aborted||await new Promise(n=>{let onAbort=()=>{clearTimeout(r),n()},r=setTimeout(()=>{t?.removeEventListener(`abort`,onAbort),n()},e);t?.addEventListener(`abort`,onAbort,{once:!0})})}export{followStreamIterable,openStreamBody};
|
|
@@ -55,8 +55,9 @@ export declare class ClientSession {
|
|
|
55
55
|
* Opens this session's event stream for the current session ID.
|
|
56
56
|
*
|
|
57
57
|
* Resumes from the session's stored stream cursor unless `options.startIndex`
|
|
58
|
-
* overrides it.
|
|
59
|
-
* ends
|
|
58
|
+
* overrides it. By default, the stream reconnects from its cursor when the
|
|
59
|
+
* connection ends; pass `streamReconnectPolicy: { reconnect: false }` to use
|
|
60
|
+
* one connection. Negative indices read relative to the current tail on one connection
|
|
60
61
|
* and do not advance the stored absolute cursor.
|
|
61
62
|
*
|
|
62
63
|
* @throws {Error} If the session has no session ID (no message has been sent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EVE_CREATE_SESSION_ROUTE_PATH,createEveCancelTurnRoutePath,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{ClientError}from"#client/client-error.js";import{advanceSession}from"#client/session-utils.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{followStreamIterable}from"#client/open-stream.js";import{serializeOutputSchema}from"#shared/tool-schema.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);return this.#t===n&&(this.#t={...n,sessionId:i}),new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}async cancel(e){let n=this.#t.sessionId;if(!n)throw Error(`Session has no session ID. Send a message first.`);let r=createClientUrl(this.#e.host,createEveCancelTurnRoutePath(n)),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let o=await fetch(r,withRedirectPolicy({headers:i,method:`POST`,body:e?JSON.stringify(e):void 0},this.#e.redirect)),c=await o.text();if(!o.ok)throw new ClientError(o.status,c,o.headers);let u;try{u=JSON.parse(c)}catch{throw Error(`Cancel route returned invalid JSON (${o.status}).`)}let d=CancelTurnResponseSchema.safeParse(u);if(!d.success||d.data.sessionId!==n)throw Error(`Cancel route returned an invalid response (${o.status}).`);return{sessionId:d.data.sessionId,status:d.data.status}}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);return this.#i(t,e)}async#n(t,i){let a=i.sessionId?createEveContinueSessionRoutePath(i.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,o=createClientUrl(this.#e.host,a),c=await this.#e.resolveHeaders(t.headers);c.set(`content-type`,`application/json`);let l=createHandleMessageBody({input:t,outputSchema:serializeOutputSchema(t.outputSchema),session:i});if(l===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let u=await postTurnWithRetry({body:JSON.stringify(l),headers:c,mustDeliver:(t.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:t.signal,url:o}),f=await u.json(),p=(typeof f.sessionId==`string`?f.sessionId:void 0)??u.headers.get(EVE_SESSION_ID_HEADER)?.trim()??i.sessionId;if(!p)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof f.continuationToken==`string`?f.continuationToken:void 0,sessionId:p}}async*#r(e,t,n,r){let a=[];try{for await(let t of followStreamIterable({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(r.headers),redirect:this.#e.redirect,sessionId:e,signal:r.signal,startIndex:n.sessionId===e?n.streamIndex:0}))if(a.push(t),yield t,isCurrentTurnBoundaryEvent(t))break}finally{this.#t=advanceSession({continuationToken:t,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async*#i(e,t){let n=this.#t,r=t?.startIndex??n.streamIndex,i=[];try{for await(let n of followStreamIterable({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(),redirect:this.#e.redirect,sessionId:e,signal:t?.signal,startIndex:r}))i.push(n),yield n}finally{r>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:r},sessionId:e}))}}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,n,r,i;for(let o=0;o<t;o+=1){let s=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(s.ok)return s;if(n=s.status,r=await s.text(),i=s.headers,!isRetryableDeliveryFailure(s.status,r))throw new ClientError(s.status,r,s.headers);o<t-1&&await sleep(200)}throw new ClientError(n??0,r??`Failed to deliver session turn.`,i)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{ClientSession};
|
|
1
|
+
import{EVE_CREATE_SESSION_ROUTE_PATH,createEveCancelTurnRoutePath,createEveContinueSessionRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER,isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{ClientError}from"#client/client-error.js";import{advanceSession}from"#client/session-utils.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{followStreamIterable}from"#client/open-stream.js";import{serializeOutputSchema}from"#shared/tool-schema.js";var ClientSession=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get state(){return this.#t}async send(e){let t=normalizeSendTurnInput(e),n=this.#t,{continuationToken:r,sessionId:i}=await this.#n(t,n);return this.#t===n&&(this.#t={...n,sessionId:i}),new MessageResponse({continuationToken:r,createStream:()=>this.#r(i,r,n,t),sessionId:i})}async cancel(e){let n=this.#t.sessionId;if(!n)throw Error(`Session has no session ID. Send a message first.`);let r=createClientUrl(this.#e.host,createEveCancelTurnRoutePath(n)),i=await this.#e.resolveHeaders();i.set(`content-type`,`application/json`);let o=await fetch(r,withRedirectPolicy({headers:i,method:`POST`,body:e?JSON.stringify(e):void 0},this.#e.redirect)),c=await o.text();if(!o.ok)throw new ClientError(o.status,c,o.headers);let u;try{u=JSON.parse(c)}catch{throw Error(`Cancel route returned invalid JSON (${o.status}).`)}let d=CancelTurnResponseSchema.safeParse(u);if(!d.success||d.data.sessionId!==n)throw Error(`Cancel route returned an invalid response (${o.status}).`);return{sessionId:d.data.sessionId,status:d.data.status}}stream(e){let t=this.#t.sessionId;if(!t)throw Error(`Session has no session ID. Send a message first.`);return this.#i(t,e)}async#n(t,i){let a=i.sessionId?createEveContinueSessionRoutePath(i.sessionId):EVE_CREATE_SESSION_ROUTE_PATH,o=createClientUrl(this.#e.host,a),c=await this.#e.resolveHeaders(t.headers);c.set(`content-type`,`application/json`);let l=createHandleMessageBody({input:t,outputSchema:serializeOutputSchema(t.outputSchema),session:i});if(l===null)throw Error(`Session.send requires a non-empty message, inputResponses, or both.`);let u=await postTurnWithRetry({body:JSON.stringify(l),headers:c,mustDeliver:(t.inputResponses?.length??0)>0,redirect:this.#e.redirect,signal:t.signal,url:o}),f=await u.json(),p=(typeof f.sessionId==`string`?f.sessionId:void 0)??u.headers.get(EVE_SESSION_ID_HEADER)?.trim()??i.sessionId;if(!p)throw Error(`Message route did not return a session id.`);return{continuationToken:typeof f.continuationToken==`string`?f.continuationToken:void 0,sessionId:p}}async*#r(e,t,n,r){let a=[];try{for await(let t of followStreamIterable({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(r.headers),redirect:this.#e.redirect,streamReconnectPolicy:r.streamReconnectPolicy,sessionId:e,signal:r.signal,startIndex:n.sessionId===e?n.streamIndex:0}))if(a.push(t),yield t,isCurrentTurnBoundaryEvent(t))break}finally{this.#t=advanceSession({continuationToken:t,events:a,preserveCompletedSessions:this.#e.preserveCompletedSessions,sessionId:e,session:n})}}async*#i(e,t){let n=this.#t,r=t?.startIndex??n.streamIndex,i=[];try{for await(let n of followStreamIterable({host:this.#e.host,resolveHeaders:()=>this.#e.resolveHeaders(),redirect:this.#e.redirect,streamReconnectPolicy:t?.streamReconnectPolicy,sessionId:e,signal:t?.signal,startIndex:r}))i.push(n),yield n}finally{r>=0&&(this.#t=advanceSession({continuationToken:n.continuationToken,events:i,preserveCompletedSessions:this.#e.preserveCompletedSessions,session:{...n,sessionId:e,streamIndex:r},sessionId:e}))}}};async function postTurnWithRetry(e){let t=e.mustDeliver?10:1,n,r,i;for(let o=0;o<t;o+=1){let s=await fetch(e.url,{body:e.body,headers:e.headers,method:`POST`,redirect:e.redirect,signal:e.signal??null});if(s.ok)return s;if(n=s.status,r=await s.text(),i=s.headers,!isRetryableDeliveryFailure(s.status,r))throw new ClientError(s.status,r,s.headers);o<t-1&&await sleep(200)}throw new ClientError(n??0,r??`Failed to deliver session turn.`,i)}function isRetryableDeliveryFailure(e,t){return e===500&&/target session was not found/i.test(t)}async function sleep(e){await new Promise(t=>setTimeout(t,e))}function normalizeSendTurnInput(e){return typeof e==`string`?{message:e}:e}function createHandleMessageBody(e){let t={};return e.input.message!==void 0&&(t.message=e.input.message),e.input.inputResponses!==void 0&&e.input.inputResponses.length>0&&(t.inputResponses=e.input.inputResponses),e.input.clientContext!==void 0&&(t.clientContext=e.input.clientContext),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.session.continuationToken!==void 0&&(t.continuationToken=e.session.continuationToken),Object.keys(t).length===0||e.session.continuationToken===void 0&&t.message===void 0||e.session.continuationToken!==void 0&&t.message===void 0&&t.inputResponses===void 0?null:t}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{ClientSession};
|
|
@@ -118,6 +118,11 @@ export interface SendTurnPayload<TOutput = unknown> {
|
|
|
118
118
|
* schema's output type and is not revalidated client-side.
|
|
119
119
|
*/
|
|
120
120
|
readonly outputSchema?: StandardJSONSchemaV1<unknown, TOutput> | JsonObject;
|
|
121
|
+
/**
|
|
122
|
+
* Reconnection policy for the response event stream. Omit to use the default
|
|
123
|
+
* policy, or pass `{ reconnect: false }` when the caller owns cursor recovery.
|
|
124
|
+
*/
|
|
125
|
+
readonly streamReconnectPolicy?: StreamReconnectPolicy;
|
|
121
126
|
/**
|
|
122
127
|
* Abort signal for cancelling the request.
|
|
123
128
|
*/
|
|
@@ -127,10 +132,37 @@ export interface SendTurnPayload<TOutput = unknown> {
|
|
|
127
132
|
*/
|
|
128
133
|
readonly headers?: Readonly<Record<string, string>>;
|
|
129
134
|
}
|
|
135
|
+
/** Retry and backoff settings for one kind of stream reconnection. */
|
|
136
|
+
export interface StreamReconnectRetryPolicy {
|
|
137
|
+
/** Initial delay before retrying, in milliseconds. */
|
|
138
|
+
readonly baseDelayMs?: number;
|
|
139
|
+
/** Maximum number of attempts governed by this retry policy. */
|
|
140
|
+
readonly maxAttempts?: number;
|
|
141
|
+
/** Maximum delay between retries, in milliseconds. */
|
|
142
|
+
readonly maxDelayMs?: number;
|
|
143
|
+
}
|
|
144
|
+
/** Configurable policy used when automatic stream reconnection is enabled. */
|
|
145
|
+
export interface ResolvedStreamReconnectPolicy {
|
|
146
|
+
/** Retry policy for opening an HTTP stream connection. */
|
|
147
|
+
readonly streamOpenReconnectPolicy?: StreamReconnectRetryPolicy;
|
|
148
|
+
/** Retry policy for reconnecting streams that make no progress. */
|
|
149
|
+
readonly streamIdleReconnectPolicy?: StreamReconnectRetryPolicy;
|
|
150
|
+
/** HTTP response statuses that may be retried while opening a stream. */
|
|
151
|
+
readonly retryableErrorStatuses?: readonly number[];
|
|
152
|
+
}
|
|
153
|
+
/** Automatic stream reconnection configuration. */
|
|
154
|
+
export type StreamReconnectPolicy = ResolvedStreamReconnectPolicy | {
|
|
155
|
+
readonly reconnect: false;
|
|
156
|
+
};
|
|
130
157
|
/**
|
|
131
158
|
* Options for {@link ClientSession.stream}.
|
|
132
159
|
*/
|
|
133
160
|
export interface StreamOptions {
|
|
161
|
+
/**
|
|
162
|
+
* Reconnection policy for the event stream. Omit to use the default policy,
|
|
163
|
+
* or pass `{ reconnect: false }` when the caller owns cursor recovery.
|
|
164
|
+
*/
|
|
165
|
+
readonly streamReconnectPolicy?: StreamReconnectPolicy;
|
|
134
166
|
/**
|
|
135
167
|
* Absolute event index to start from. Negative values read relative to the
|
|
136
168
|
* current tail (`-1` starts at the latest event). Relative-tail streams do
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{basename,dirname,join}from"node:path";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{fileURLToPath}from"node:url";let cachedPackageInfo;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.27.
|
|
1
|
+
import{createRequire}from"node:module";import{existsSync,readFileSync,realpathSync}from"node:fs";import{basename,dirname,join}from"node:path";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";import{fileURLToPath}from"node:url";let cachedPackageInfo;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.27.2`,WORKFLOW_MODULE_ALIASES={"workflow/errors":`src/compiled/@workflow/errors/index.js`,"workflow/internal/private":`src/compiled/@workflow/core/private.js`};function resolveFallbackPackageVersion(){return BUNDLED_FALLBACK_PACKAGE_VERSION.startsWith(`__`)?`0.0.0`:BUNDLED_FALLBACK_PACKAGE_VERSION}const FALLBACK_PACKAGE_INFO={name:EVE_PACKAGE_NAME,version:resolveFallbackPackageVersion()};function resolveCurrentModulePath(){return typeof __filename==`string`?__filename:resolveCurrentModulePathFromStack()}function resolveCurrentModulePathFromStack(){let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(e,t)=>t;let e=Error().stack?.[0]?.getFileName();if(typeof e!=`string`||e.length===0)throw Error(`Failed to resolve the current module path from the stack trace.`);return e.startsWith(`file:`)?fileURLToPath(e):e}finally{Error.prepareStackTrace=e}}const require=createRequire(resolveCurrentModulePath());function isBuildOutputPackageRoot(e){return basename(e)===`dist`&&existsSync(join(dirname(e),`package.json`))}function resolvePackageBuildRoot(){let e=dirname(realpathSync(resolveCurrentModulePath()));for(;;){if(isBuildOutputPackageRoot(e))return e;let t=dirname(e);if(t===e)return null;e=t}}function findNearestPackageRoot(e){let n=e;for(;;){if(existsSync(join(n,`package.json`))&&!isBuildOutputPackageRoot(n))return n;let r=dirname(n);if(r===n)throw Error(`Failed to resolve package root from "${e}".`);n=r}}function resolvePackageRoot(){return findNearestPackageRoot(dirname(realpathSync(resolveCurrentModulePath())))}function tryResolvePackageRoot(){try{return resolvePackageRoot()}catch{return}}function rewriteSourceFilePathForBuild(e){return e.replace(/\.[cm]?tsx?$/,`.js`)}function resolvePackageSourceFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),e):join(t,rewriteSourceFilePathForBuild(e))}function resolvePackageSourceDirectoryPath(e){let t=resolvePackageBuildRoot();return join(t===null?resolvePackageRoot():t,e)}function resolvePackageDependencyPath(e){return require.resolve(e)}function resolvePackageCompiledFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),`.generated`,`compiled`,e.replace(/^src\/compiled\//,``)):join(t,e)}function normalizeInstalledPackageInfo(e){let t=e;if(!(typeof t.name!=`string`||typeof t.version!=`string`))return{name:t.name,version:t.version}}function tryReadInstalledPackageInfo(e,t){let r=normalizeInstalledPackageInfo(JSON.parse(readFileSync(e,`utf8`)));if(r?.name===t)return r}function resolveInstalledPackageInfo(){if(cachedPackageInfo)return cachedPackageInfo;let e=tryResolvePackageRoot(),t=e===void 0?void 0:tryReadInstalledPackageInfo(join(e,`package.json`),EVE_PACKAGE_NAME);if(t)return cachedPackageInfo=t,cachedPackageInfo;try{let e=tryReadInstalledPackageInfo(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),EVE_PACKAGE_NAME);if(e)return cachedPackageInfo=e,cachedPackageInfo}catch{}return cachedPackageInfo={...FALLBACK_PACKAGE_INFO},cachedPackageInfo}function readWorkflowVersionFromManifest(e){let t=e;for(let e of[t.devDependencies,t.dependencies,t.peerDependencies]){let t=e?.[`@workflow/core`];if(typeof t==`string`&&t.trim().length>0)return t}}function resolveExpectedWorkflowVersion(){let e=tryResolvePackageRoot();if(e!==void 0)try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(join(e,`package.json`),`utf8`)))}catch{}try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),`utf8`)))}catch{return}}function resolveWorkflowModulePath(e){if(e===`workflow`)return resolvePackageSourceFilePath(`src/internal/workflow/index.ts`);if(e===`workflow/api`||e===`workflow/runtime`)return resolvePackageSourceFilePath(`src/internal/workflow/runtime.ts`);if(e===`workflow/internal/builtins`)return resolvePackageSourceFilePath(`src/internal/workflow/builtins.ts`);let t=WORKFLOW_MODULE_ALIASES[e];return t===void 0?require.resolve(e):resolvePackageCompiledFilePath(t)}export{resolveExpectedWorkflowVersion,resolveInstalledPackageInfo,resolvePackageCompiledFilePath,resolvePackageDependencyPath,resolvePackageRoot,resolvePackageSourceDirectoryPath,resolvePackageSourceFilePath,resolveWorkflowModulePath};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{existsSync,readFileSync,statSync}from"node:fs";import{dirname,extname,join,relative,resolve}from"node:path";import{fileURLToPath}from"node:url";function createAuthoredModuleEvaluationError(e,t){let n=describeInstalledPackageLoadFailure(t);return Error([`Failed to evaluate authored module:`,` ${e}`,...n===void 0?[]:[``,n]].join(`
|
|
2
|
+
`),{cause:t})}function describeInstalledPackageLoadFailure(e){if(!(e instanceof Error))return;let t=e;if(t.code!==`ERR_MODULE_NOT_FOUND`||typeof t.url!=`string`)return;let n=filePathFromUrl(t.url);if(n===void 0||extname(n)!==``)return;let r=findInstalledPackage(n);if(r===void 0)return;let a=toPackageRelativePath(r.root,n);return findExistingModulePath(n)===void 0?[`Failed to load an installed package:`,` Package: ${r.name} (loaded outside the authored bundle)`,` Missing: ${a}`,` Reason: Package output may be incomplete, incorrectly installed, or incompatible with a standalone Node runtime.`,` Hint: Verify the installed package version and output, use a Node-compatible entrypoint, or report the missing module to the package publisher.`].join(`
|
|
3
|
+
`):[`Failed to load an installed package:`,` Package: ${r.name} (loaded outside the authored bundle)`,` Import: ${a}`,` Reason: Node's ESM loader does not infer file extensions for relative imports.`,` Hint: Use a Node-compatible package or entrypoint, or report the extensionless import to the package publisher.`].join(`
|
|
4
|
+
`)}function findExistingModulePath(e){for(let t of[`.js`,`.mjs`,`.cjs`]){let r=`${e}${t}`;try{if(statSync(r).isFile())return r}catch{}}}function toPackageRelativePath(e,t){return relative(e,t).replaceAll(`\\`,`/`)}function filePathFromUrl(e){try{let t=new URL(e);return t.protocol===`file:`?fileURLToPath(t):void 0}catch{return}}function findInstalledPackage(n){let i=dirname(resolve(n));for(;;){let n=join(i,`package.json`);if(existsSync(n)&&isNodeModulesPath(n))try{let e=JSON.parse(readFileSync(n,`utf8`));if(typeof e.name==`string`&&e.name.length>0)return{name:e.name,root:i}}catch{return}let o=dirname(i);if(o===i)return;i=o}}function isNodeModulesPath(e){return e.replaceAll(`\\`,`/`).includes(`/node_modules/`)}export{createAuthoredModuleEvaluationError};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,realpathSync,statSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{createHash}from"node:crypto";import{createCompiledModuleMapSource}from"#compiler/module-map.js";import{buildSingleRolldownChunk,buildWithNitroRolldown}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createExtensionScopePlugin,createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createDistributionPackageBoundaryPlugin,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,isPathImport,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(t,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)?await loadBundledAuthoredModule(t,n):await import(createFileImportSpecifier(t)),`Expected "${t}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){return removeRolldownModuleRegionComments(await buildAuthoredModuleBundle(e,t,{channelIdentity:!1,packageBoundaryPlugin:createGenerationPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[createAuthoredDirectiveGuardPlugin()],sourcemap:!1}))}async function bundleExtensionDistributionGraph(e){let t=[createAuthoredDirectiveGuardPlugin(),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:e.packageRoot,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createDistributionPackageBoundaryPlugin({packageRoot:e.packageRoot,runtimeDependencies:e.runtimeDependencies})];try{let n=await buildWithNitroRolldown({cwd:e.packageRoot,input:Object.fromEntries(e.entries.map(e=>[e.name,e.path])),platform:`node`,plugins:t,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(e.packageRoot),write:!1,output:{chunkFileNames:`_chunks/[name]-[hash].mjs`,codeSplitting:!0,comments:!1,entryFileNames:`[name].mjs`,format:`esm`,sourcemap:!1}}),r=new Map;for(let e of n.output)e.type===`chunk`&&r.set(e.fileName,removeRolldownModuleRegionComments(e.code));return r}catch(t){throw createAuthoredModuleBundleError(e.packageRoot,t)}}async function bundleAuthoredModuleMapForGeneration(e){let t=resolveAuthoredPackageRoot(e.manifest.agentRoot),n=normalizeExternalDependencies([e.manifest,...e.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[])),r=createCompiledModuleMapSource({manifest:e.manifest,moduleMapPath:e.moduleMapPath}),i=createExtensionScopePlugin(e.manifest.extensionMounts.map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot}))),a=[createVirtualGenerationModuleMapPlugin({id:e.moduleMapPath,source:r}),createAuthoredDirectiveGuardPlugin(),i,createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:t,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createGenerationPackageBoundaryPlugin({externalDependencies:n,packageRoot:t})].filter(e=>e!==null);try{return removeRolldownModuleRegionComments((await buildSingleRolldownChunk(`authored module map`,{cwd:t,input:e.moduleMapPath,platform:`node`,plugins:a,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(t),output:{comments:!1,format:`esm`,sourcemap:!1}})).code)}catch(t){throw createAuthoredModuleBundleError(e.moduleMapPath,t)}}function createVirtualGenerationModuleMapPlugin(e){return{name:`eve-generation-module-map`,resolveId(t){return t===e.id?t:void 0},load(t){return t===e.id?{code:e.source,moduleType:`js`}:void 0}}}async function buildAuthoredModuleBundle(e,t,n){let r=n.channelIdentity?getChannelModuleCache():void 0,i=resolveAuthoredPackageRoot(e),a=resolveAuthoredTsConfigPath(i),o=[r&&r.size>0?{name:`eve-channel-identity`,async resolveId(e,t,n){if(!/channels[/\\]/.test(e)||n.kind!==`import-statement`)return;let i=await this.resolve(e,t,{kind:n.kind,skipSelf:!0});if(i===null||typeof i.id!=`string`)return;let a=resolve(i.id);if(r.has(a))return{id:`${CACHED_CHANNEL_PREFIX}${a}`}},load(e){if(!e.startsWith(CACHED_CHANNEL_PREFIX))return;let t=e.slice(CACHED_CHANNEL_PREFIX.length);return{code:[`const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,`export default cache.get(${JSON.stringify(t)});`].join(`
|
|
1
|
+
import{expectObjectRecord}from"#internal/authored-module.js";import{existsSync,mkdirSync,realpathSync,statSync,writeFileSync}from"node:fs";import{dirname,isAbsolute,join,resolve}from"node:path";import{createHash}from"node:crypto";import{createCompiledModuleMapSource}from"#compiler/module-map.js";import{buildSingleRolldownChunk,buildWithNitroRolldown}from"#internal/bundler/nitro-rolldown.js";import{createAuthoredAssetImportPlugin}from"#internal/authored-asset-import-plugin.js";import{assertNoWorkflowDirectivePrologue}from"#internal/authored-directive-prologue.js";import{createAuthoredModuleBundleError}from"#internal/authored-module-bundle.js";import{createAuthoredModuleEvaluationError}from"#internal/authored-module-evaluation-error.js";import{createAuthoredPackageTsConfigPathsPlugin}from"#internal/authored-package-tsconfig-paths.js";import{createExtensionScopePlugin,createFixedNamespaceScopePlugin}from"#internal/bundler/extension-scope-plugin.js";import{CACHED_CHANNEL_PREFIX,RESOLVE_EXTENSIONS,createDistributionPackageBoundaryPlugin,createGenerationPackageBoundaryPlugin,createRuntimeLoaderPackageBoundaryPlugin,isNodeModulesPath,isPathImport,normalizeExternalDependencies}from"#internal/authored-package-boundary.js";import{createNodeEsmCompatBannerPlugin}from"#internal/node-esm-compat-banner.js";const AUTHORED_BUNDLED_MODULE_EXTENSION=/\.[cm]?[jt]sx?$/,AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH=join(`node_modules`,`.cache`,`eve`,`authored-modules`),CHANNEL_MODULE_CACHE_KEY=`__eveChannelModuleCache__`;function getChannelModuleCache(){return globalThis[CHANNEL_MODULE_CACHE_KEY]}const inFlightModuleLoads=new Map;function loadAuthoredModuleNamespace(e,t={}){let n=createInFlightModuleLoadKey(resolve(e),t),r=inFlightModuleLoads.get(n);if(r!==void 0)return r;let i=(async()=>{try{return await doLoadAuthoredModuleNamespace(e,t)}finally{inFlightModuleLoads.delete(n)}})();return inFlightModuleLoads.set(n,i),i}async function doLoadAuthoredModuleNamespace(t,n){return expectObjectRecord(AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)?await loadBundledAuthoredModule(t,n):await import(createFileImportSpecifier(t)),`Expected "${t}" to export a module namespace object.`)}function createFileImportSpecifier(e){let t=e.replaceAll(`\\`,`/`);return/^[A-Za-z]:\//.test(t)?`file:///${encodeURI(t)}`:t.startsWith(`/`)?`file://${encodeURI(t)}`:t}async function bundleAuthoredModuleCode(e,t={}){return await buildAuthoredModuleBundle(e,t,{channelIdentity:!0,packageBoundaryPlugin:createRuntimeLoaderPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[],sourcemap:`inline`})}async function bundleAuthoredModuleForGeneration(e,t={}){return removeRolldownModuleRegionComments(await buildAuthoredModuleBundle(e,t,{channelIdentity:!1,packageBoundaryPlugin:createGenerationPackageBoundaryPlugin({externalDependencies:normalizeExternalDependencies(t.externalDependencies),packageRoot:resolveAuthoredPackageRoot(e)}),plugins:[createAuthoredDirectiveGuardPlugin()],sourcemap:!1}))}async function bundleExtensionDistributionGraph(e){let t=[createAuthoredDirectiveGuardPlugin(),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:e.packageRoot,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createDistributionPackageBoundaryPlugin({packageRoot:e.packageRoot,runtimeDependencies:e.runtimeDependencies})];try{let n=await buildWithNitroRolldown({cwd:e.packageRoot,input:Object.fromEntries(e.entries.map(e=>[e.name,e.path])),platform:`node`,plugins:t,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(e.packageRoot),write:!1,output:{chunkFileNames:`_chunks/[name]-[hash].mjs`,codeSplitting:!0,comments:!1,entryFileNames:`[name].mjs`,format:`esm`,sourcemap:!1}}),r=new Map;for(let e of n.output)e.type===`chunk`&&r.set(e.fileName,removeRolldownModuleRegionComments(e.code));return r}catch(t){throw createAuthoredModuleBundleError(e.packageRoot,t)}}async function bundleAuthoredModuleMapForGeneration(e){let t=resolveAuthoredPackageRoot(e.manifest.agentRoot),n=normalizeExternalDependencies([e.manifest,...e.manifest.subagents.map(e=>e.agent)].flatMap(e=>e.config.build?.externalDependencies??[])),r=createCompiledModuleMapSource({manifest:e.manifest,moduleMapPath:e.moduleMapPath}),i=createExtensionScopePlugin(e.manifest.extensionMounts.map(e=>({packageNamespace:e.packageNamespace,sourceRoot:e.sourceRoot}))),a=[createVirtualGenerationModuleMapPlugin({id:e.moduleMapPath,source:r}),createAuthoredDirectiveGuardPlugin(),i,createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:t,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),createGenerationPackageBoundaryPlugin({externalDependencies:n,packageRoot:t})].filter(e=>e!==null);try{return removeRolldownModuleRegionComments((await buildSingleRolldownChunk(`authored module map`,{cwd:t,input:e.moduleMapPath,platform:`node`,plugins:a,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:resolveAuthoredTsConfigPath(t),output:{comments:!1,format:`esm`,sourcemap:!1}})).code)}catch(t){throw createAuthoredModuleBundleError(e.moduleMapPath,t)}}function createVirtualGenerationModuleMapPlugin(e){return{name:`eve-generation-module-map`,resolveId(t){return t===e.id?t:void 0},load(t){return t===e.id?{code:e.source,moduleType:`js`}:void 0}}}async function buildAuthoredModuleBundle(e,t,n){let r=n.channelIdentity?getChannelModuleCache():void 0,i=resolveAuthoredPackageRoot(e),a=resolveAuthoredTsConfigPath(i),o=[r&&r.size>0?{name:`eve-channel-identity`,async resolveId(e,t,n){if(!/channels[/\\]/.test(e)||n.kind!==`import-statement`)return;let i=await this.resolve(e,t,{kind:n.kind,skipSelf:!0});if(i===null||typeof i.id!=`string`)return;let a=resolve(i.id);if(r.has(a))return{id:`${CACHED_CHANNEL_PREFIX}${a}`}},load(e){if(!e.startsWith(CACHED_CHANNEL_PREFIX))return;let t=e.slice(CACHED_CHANNEL_PREFIX.length);return{code:[`const cache = globalThis["${CHANNEL_MODULE_CACHE_KEY}"];`,`export default cache.get(${JSON.stringify(t)});`].join(`
|
|
2
2
|
`),moduleType:`js`}}}:null,...n.plugins,t.extensionScopeNamespace===void 0?null:createFixedNamespaceScopePlugin(t.extensionScopeNamespace),createAuthoredRelativeExtensionResolverPlugin({extensions:RESOLVE_EXTENSIONS}),createAuthoredAssetImportPlugin(),createAuthoredPackageTsConfigPathsPlugin({appPackageRoot:i,extensions:RESOLVE_EXTENSIONS}),createNodeEsmCompatBannerPlugin({includeRequire:!0}),n.packageBoundaryPlugin].filter(e=>e!==null);try{return(await buildSingleRolldownChunk(`authored module for "${e}"`,{cwd:i,input:e,platform:`node`,plugins:o,resolve:{extensions:[...RESOLVE_EXTENSIONS]},tsconfig:a,output:{comments:!1,format:`esm`,sourcemap:n.sourcemap}})).code}catch(t){throw createAuthoredModuleBundleError(e,t)}}function createAuthoredDirectiveGuardPlugin(){return{name:`eve-authored-directive-guard`,async transform(e,t){!AUTHORED_BUNDLED_MODULE_EXTENSION.test(t)||isNodeModulesPath(t)||await assertNoWorkflowDirectivePrologue({filePath:t,source:e})}}}function removeRolldownModuleRegionComments(e){return e.split(`
|
|
3
3
|
`).filter(e=>!e.startsWith(`//#region `)&&e!==`//#endregion`).join(`
|
|
4
|
-
`)}async function loadBundledAuthoredModule(e,r){let i=await bundleAuthoredModuleCode(e,r),o=normalizeExternalDependencies(r.externalDependencies),s=createHash(`sha1`).update(e).update(`\0`).update(o.join(`\0`)).update(`\0`).update(r.extensionScopeNamespace??``).update(`\0`).update(i).digest(`hex`),c=join(resolveAuthoredPackageRoot(e),AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH),l=join(c,`${s}.mjs`);
|
|
4
|
+
`)}async function loadBundledAuthoredModule(e,r){let i=await bundleAuthoredModuleCode(e,r),o=normalizeExternalDependencies(r.externalDependencies),s=createHash(`sha1`).update(e).update(`\0`).update(o.join(`\0`)).update(`\0`).update(r.extensionScopeNamespace??``).update(`\0`).update(i).digest(`hex`),c=join(resolveAuthoredPackageRoot(e),AUTHORED_MODULE_BUNDLE_DIRECTORY_PATH),l=join(c,`${s}.mjs`);existsSync(l)||(mkdirSync(c,{recursive:!0}),writeFileSync(l,i));try{return await import(`${createFileImportSpecifier(l)}?v=${s}`)}catch(t){throw createAuthoredModuleEvaluationError(e,t)}}function createAuthoredRelativeExtensionResolverPlugin(e){return{name:`eve-authored-relative-extension-resolver`,resolveId(t,n){if(n===void 0||n.startsWith(`\0`)||n.startsWith(CACHED_CHANNEL_PREFIX)||!isPathImport(t))return;let r=resolveExistingImportPath(isAbsolute(t)?t:resolve(dirname(n),t),e.extensions);if(r!==void 0)return{id:isNodeModulesPath(r)?toRealModulePath(r):r}}}}function toRealModulePath(e){try{return realpathSync(e)}catch{return e}}function createInFlightModuleLoadKey(e,t){return`${e}\0${normalizeExternalDependencies(t.externalDependencies).join(`\0`)}\0${t.extensionScopeNamespace??``}`}function resolveExistingImportPath(e,t){if(isFile(e))return e;for(let n of t){let t=`${e}${n}`;if(isFile(t))return t}for(let n of t){let t=join(e,`index${n}`);if(isFile(t))return t}}function isFile(e){try{return statSync(e).isFile()}catch{return!1}}function resolveAuthoredTsConfigPath(e){for(let n of[`tsconfig.json`,`jsconfig.json`]){let r=join(e,n);if(existsSync(r))return r}return!1}function resolveAuthoredPackageRoot(e){let n=dirname(e);for(;;){if(existsSync(join(n,`package.json`)))return n;let r=dirname(n);if(r===n)throw Error(`Failed to resolve the authored package root for "${e}".`);n=r}}export{bundleAuthoredModuleCode,bundleAuthoredModuleForGeneration,bundleAuthoredModuleMapForGeneration,bundleExtensionDistributionGraph,loadAuthoredModuleNamespace};
|