@tangle-network/agent-app 0.63.2 → 0.63.4
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/dist/agent-profiles/d1.js +3 -3
- package/dist/agent-profiles/index.js +3 -3
- package/dist/chat-routes/cancellation.d.ts +12 -1
- package/dist/chat-routes/index.d.ts +1 -0
- package/dist/chat-routes/index.js +15 -15
- package/dist/chat-routes/route-storage.d.ts +21 -1
- package/dist/chat-routes/stale-turn-lock.d.ts +17 -1
- package/dist/chat-routes/turn-ownership.d.ts +1 -0
- package/dist/chat-routes/turn-route-contracts.d.ts +15 -12
- package/dist/{chunk-ND5XWLRU.js → chunk-72ASTUPN.js} +83 -24
- package/dist/chunk-72ASTUPN.js.map +1 -0
- package/dist/{chunk-XEAZWJ3W.js → chunk-7Y7U7U7X.js} +2 -2
- package/dist/{chunk-5BJHKQ33.js → chunk-ACB7KOQ6.js} +4 -4
- package/dist/{chunk-7TZA2TAM.js → chunk-FCYHDENJ.js} +2 -2
- package/dist/{chunk-WSQFNMIA.js → chunk-HRBF4B5L.js} +5 -5
- package/dist/{chunk-WSQFNMIA.js.map → chunk-HRBF4B5L.js.map} +1 -1
- package/dist/{chunk-SRWQCWLR.js → chunk-IX6UVHXY.js} +3 -3
- package/dist/{chunk-A2NQMVMF.js → chunk-MT6ZTQGD.js} +328 -118
- package/dist/chunk-MT6ZTQGD.js.map +1 -0
- package/dist/{chunk-HG2WVONR.js → chunk-UXK5EBQT.js} +42 -26
- package/dist/chunk-UXK5EBQT.js.map +1 -0
- package/dist/preset-cloudflare/index.js +8 -8
- package/dist/public-consultation/index.d.ts +1 -1
- package/dist/public-consultation/index.js +8 -8
- package/dist/sandbox/index.js +7 -5
- package/dist/sandbox/prewarm-route.d.ts +7 -0
- package/dist/stream/index.js +17 -17
- package/dist/tools/index.js +4 -4
- package/dist/turn-stream/adapters.d.ts +19 -11
- package/dist/turn-stream/cancellation-do.d.ts +31 -0
- package/dist/turn-stream/cancellation.d.ts +23 -0
- package/dist/turn-stream/core.d.ts +23 -4
- package/dist/turn-stream/do.d.ts +4 -2
- package/dist/turn-stream/index.d.ts +1 -0
- package/dist/turn-stream/index.js +188 -14
- package/dist/turn-stream/index.js.map +1 -1
- package/dist/work-product/index.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-A2NQMVMF.js.map +0 -1
- package/dist/chunk-HG2WVONR.js.map +0 -1
- package/dist/chunk-ND5XWLRU.js.map +0 -1
- /package/dist/{chunk-XEAZWJ3W.js.map → chunk-7Y7U7U7X.js.map} +0 -0
- /package/dist/{chunk-5BJHKQ33.js.map → chunk-ACB7KOQ6.js.map} +0 -0
- /package/dist/{chunk-7TZA2TAM.js.map → chunk-FCYHDENJ.js.map} +0 -0
- /package/dist/{chunk-SRWQCWLR.js.map → chunk-IX6UVHXY.js.map} +0 -0
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
ProfileConflictError,
|
|
3
3
|
parseProfileRevisionDiff,
|
|
4
4
|
serializeProfileRevisionDiff
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-IX6UVHXY.js";
|
|
6
6
|
import "../chunk-I6BZVIRH.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-FCYHDENJ.js";
|
|
8
8
|
import "../chunk-UGWQLQDS.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-HRBF4B5L.js";
|
|
10
10
|
|
|
11
11
|
// src/agent-profiles/d1.ts
|
|
12
12
|
import { snapshotAgentProfile } from "@tangle-network/agent-interface";
|
|
@@ -21,14 +21,14 @@ import {
|
|
|
21
21
|
readProfileAdmission,
|
|
22
22
|
serializeProfileRevisionDiff,
|
|
23
23
|
switchProfile
|
|
24
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-IX6UVHXY.js";
|
|
25
25
|
import {
|
|
26
26
|
normalizeProfileName,
|
|
27
27
|
parseProfileSwitch
|
|
28
28
|
} from "../chunk-I6BZVIRH.js";
|
|
29
|
-
import "../chunk-
|
|
29
|
+
import "../chunk-FCYHDENJ.js";
|
|
30
30
|
import "../chunk-UGWQLQDS.js";
|
|
31
|
-
import "../chunk-
|
|
31
|
+
import "../chunk-HRBF4B5L.js";
|
|
32
32
|
export {
|
|
33
33
|
PERMITTED_SELF_MOUNT_DIMENSIONS,
|
|
34
34
|
PROFILE_MEMORY_PREFIX,
|
|
@@ -30,12 +30,22 @@ export interface ChatTurnCancelSource {
|
|
|
30
30
|
} | null>;
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
/** Acknowledges durable intent only; the execution owner still reconciles actual completion and side effects. */
|
|
34
|
+
export interface ChatTurnCancelControlResult {
|
|
35
|
+
requested: boolean;
|
|
36
|
+
}
|
|
33
37
|
/** Application fields are projected once; the shared owner never infers OAuth or source-key authority. */
|
|
34
38
|
export interface ChatTurnCancelTarget {
|
|
35
39
|
capturedMetadata: Record<string, unknown>;
|
|
36
40
|
status: string | undefined;
|
|
37
41
|
dispatchToken?: string;
|
|
38
42
|
requiresDispatchToken: boolean;
|
|
43
|
+
/** Server-captured exact owner, never coordinates supplied by the caller.
|
|
44
|
+
* Called after authorization and dispatch-token checks. A positive request
|
|
45
|
+
* acknowledges intent; it must not mark native work stopped. */
|
|
46
|
+
control?: {
|
|
47
|
+
request(capturedMetadata: Record<string, unknown>): Promise<ChatTurnCancelControlResult>;
|
|
48
|
+
};
|
|
39
49
|
native?: {
|
|
40
50
|
state: string | undefined;
|
|
41
51
|
sandboxId?: string;
|
|
@@ -44,7 +54,8 @@ export interface ChatTurnCancelTarget {
|
|
|
44
54
|
/** Resolve the original authorized box only after the dispatch token and receipt are validated. */
|
|
45
55
|
source(): Promise<ChatTurnCancelSource | null>;
|
|
46
56
|
};
|
|
47
|
-
/** Compare the WHOLE captured record atomically, then merge the stopped fields. False changes nothing.
|
|
57
|
+
/** Compare the WHOLE captured record atomically, then merge the stopped fields. False changes nothing.
|
|
58
|
+
* A requested-only control target never calls this; the execution owner confirms its terminal outcome. */
|
|
48
59
|
markStopped(capturedMetadata: Record<string, unknown>, stoppedAt: string): Promise<boolean>;
|
|
49
60
|
}
|
|
50
61
|
export interface ChatTurnCancelOptions<TContext> {
|
|
@@ -71,7 +71,7 @@ import {
|
|
|
71
71
|
turnCarriesFiles,
|
|
72
72
|
turnPromptText,
|
|
73
73
|
withProducerStream
|
|
74
|
-
} from "../chunk-
|
|
74
|
+
} from "../chunk-UXK5EBQT.js";
|
|
75
75
|
import "../chunk-KH4QSBNI.js";
|
|
76
76
|
import {
|
|
77
77
|
sniffMimeFromName
|
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
import "../chunk-MM6RLOXF.js";
|
|
86
86
|
import {
|
|
87
87
|
flattenHistory
|
|
88
|
-
} from "../chunk-
|
|
88
|
+
} from "../chunk-72ASTUPN.js";
|
|
89
89
|
import "../chunk-F4TUZYMX.js";
|
|
90
90
|
import {
|
|
91
91
|
assistantRowIdForTurn,
|
|
@@ -96,15 +96,6 @@ import {
|
|
|
96
96
|
} from "../chunk-N6URQ6DM.js";
|
|
97
97
|
import "../chunk-Z4RD5UF7.js";
|
|
98
98
|
import "../chunk-YG66IHDU.js";
|
|
99
|
-
import {
|
|
100
|
-
DEFAULT_STALE_TURN_LOCK_GRACE_MS,
|
|
101
|
-
DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS,
|
|
102
|
-
reconcileStaleTurnLock
|
|
103
|
-
} from "../chunk-A2NQMVMF.js";
|
|
104
|
-
import {
|
|
105
|
-
coalesceDeltas,
|
|
106
|
-
createBufferedTurnTap
|
|
107
|
-
} from "../chunk-ISP6ZH3G.js";
|
|
108
99
|
import {
|
|
109
100
|
attachmentInputToPart,
|
|
110
101
|
attachmentKindForMime,
|
|
@@ -151,17 +142,26 @@ import {
|
|
|
151
142
|
} from "../chunk-VUBJZEZB.js";
|
|
152
143
|
import "../chunk-6VQCFJWP.js";
|
|
153
144
|
import "../chunk-PK65B6HP.js";
|
|
145
|
+
import {
|
|
146
|
+
DEFAULT_STALE_TURN_LOCK_GRACE_MS,
|
|
147
|
+
DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS,
|
|
148
|
+
reconcileStaleTurnLock
|
|
149
|
+
} from "../chunk-MT6ZTQGD.js";
|
|
150
|
+
import {
|
|
151
|
+
coalesceDeltas,
|
|
152
|
+
createBufferedTurnTap
|
|
153
|
+
} from "../chunk-ISP6ZH3G.js";
|
|
154
154
|
import "../chunk-ZLX4BA27.js";
|
|
155
155
|
import "../chunk-XELWWXJJ.js";
|
|
156
156
|
import "../chunk-DSMGS4IV.js";
|
|
157
|
-
import "../chunk-
|
|
157
|
+
import "../chunk-ACB7KOQ6.js";
|
|
158
158
|
import "../chunk-6A7MYOUI.js";
|
|
159
159
|
import "../chunk-O7UX55EU.js";
|
|
160
|
-
import "../chunk-
|
|
160
|
+
import "../chunk-7Y7U7U7X.js";
|
|
161
161
|
import "../chunk-S5SRJJQG.js";
|
|
162
|
-
import "../chunk-
|
|
162
|
+
import "../chunk-FCYHDENJ.js";
|
|
163
163
|
import "../chunk-UGWQLQDS.js";
|
|
164
|
-
import "../chunk-
|
|
164
|
+
import "../chunk-HRBF4B5L.js";
|
|
165
165
|
import "../chunk-IDG2XR5O.js";
|
|
166
166
|
import "../chunk-D6UJEOZQ.js";
|
|
167
167
|
import "../chunk-AVBNS64P.js";
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
/** Shared D1 replay and authenticated thread locks from the application's bindings. */
|
|
2
|
-
import { type TurnEventStore } from '../stream/turn-buffer';
|
|
2
|
+
import { type TurnEventStore, type D1LikeForTurns } from '../stream/turn-buffer';
|
|
3
|
+
import { type TurnStreamNamespaceLike, type TurnStreamAuth, type TurnStreamLocationHint } from '../turn-stream/adapters';
|
|
3
4
|
import type { CreateChatTurnRoutesOptions } from './turn-route-contracts';
|
|
5
|
+
/** One application binding descriptor, shared by chat admission and workspace prewarm. */
|
|
6
|
+
export interface ChatTurnStoreBindings {
|
|
7
|
+
db: D1LikeForTurns;
|
|
8
|
+
/** The app's D1 region, also used as the placement hint for new lock channels. Default: enam. */
|
|
9
|
+
region?: TurnStreamLocationHint;
|
|
10
|
+
lock: {
|
|
11
|
+
namespace: TurnStreamNamespaceLike;
|
|
12
|
+
auth: TurnStreamAuth;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Keep the workspace-channel identity, authentication and region the same in both routes. */
|
|
16
|
+
export declare function createDefaultTurnLock<TContext>(store: ChatTurnStoreBindings): {
|
|
17
|
+
acquire(args: import("../turn-stream").TurnLockSeamArgs<TContext>): Promise<import("../turn-stream").TurnLockSeamResult>;
|
|
18
|
+
release(handle: unknown): Promise<void>;
|
|
19
|
+
warm(target: {
|
|
20
|
+
tenantId: string;
|
|
21
|
+
threadId?: string;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
};
|
|
4
24
|
export type ResolvedChatTurnRoutesOptions<TContext, TResource = unknown> = Omit<CreateChatTurnRoutesOptions<TContext, TResource>, 'turnStore'> & {
|
|
5
25
|
turnStore: TurnEventStore;
|
|
6
26
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TurnCancellationIdentity } from '../turn-stream/cancellation';
|
|
1
2
|
/**
|
|
2
3
|
* Recovery policy for a `ChatTurnLock` whose holder died.
|
|
3
4
|
*
|
|
@@ -14,7 +15,11 @@
|
|
|
14
15
|
* probes — which box key, which session id, which sidecar endpoint — in the
|
|
15
16
|
* product.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
+
* A supplied exact Router owner probe replaces the native rules: live and
|
|
19
|
+
* unknown hold; positive outer + child abandonment observes the same terminal
|
|
20
|
+
* grace and exact release fence. A native session cannot attest to a Router owner.
|
|
21
|
+
*
|
|
22
|
+
* The native rules, in precedence order:
|
|
18
23
|
*
|
|
19
24
|
* 1. The session probe answered and the execution is TERMINAL ⇒ release, once
|
|
20
25
|
* the lock is past a short grace period. The authority on "is this turn
|
|
@@ -55,6 +60,12 @@ export type StaleTurnLockSessionProbeResult = {
|
|
|
55
60
|
reachable: false;
|
|
56
61
|
reason?: string;
|
|
57
62
|
};
|
|
63
|
+
/** A positive abandoned verdict covers the exact outer producer and every registered child/effect owner. */
|
|
64
|
+
export interface StaleTurnLockOwnerProbeResult {
|
|
65
|
+
identity: TurnCancellationIdentity;
|
|
66
|
+
status: 'live' | 'abandoned' | 'unknown';
|
|
67
|
+
diagnostics?: Record<string, unknown>;
|
|
68
|
+
}
|
|
58
69
|
/**
|
|
59
70
|
* Minimum age a lock must reach before the "sandbox unreachable ⇒ nothing can
|
|
60
71
|
* be running" fallback may force-release it.
|
|
@@ -100,6 +111,11 @@ export interface ReconcileStaleTurnLockOptions {
|
|
|
100
111
|
/** When the held lock was acquired (epoch ms). The grace period is measured
|
|
101
112
|
* from here, so it must be the LOCK's start, not the turn's. */
|
|
102
113
|
lockStartedAt: number;
|
|
114
|
+
/** Router ownership replaces native-only inference. Missing/uncertain outer or child evidence must stay unknown. */
|
|
115
|
+
owner?: {
|
|
116
|
+
identity: TurnCancellationIdentity;
|
|
117
|
+
probe(identity: TurnCancellationIdentity): Promise<StaleTurnLockOwnerProbeResult>;
|
|
118
|
+
};
|
|
103
119
|
/** Is the box there and running? Never provisions — a peek, not an ensure.
|
|
104
120
|
* A throw is treated as unreachable, same as `absent`. */
|
|
105
121
|
probeSandbox(): Promise<StaleTurnLockSandboxProbeResult>;
|
|
@@ -11,6 +11,7 @@ interface OwnershipState {
|
|
|
11
11
|
lockAcquired: boolean;
|
|
12
12
|
lockReleased: boolean;
|
|
13
13
|
lockHandle: unknown;
|
|
14
|
+
closeCancellation?: () => Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
/** One transfer of terminal authority, retaining the route only as a live projector. */
|
|
16
17
|
export declare function createChatTurnOwnership(state: OwnershipState, log: (message: string, meta?: Record<string, unknown>) => void, turnStreamId: string, options: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Public contracts for admission, execution, persistence and chat-route hooks. */
|
|
2
|
+
import type { ChatTurnStoreBindings } from './route-storage';
|
|
2
3
|
import type { NativeCompletionHandoffOptions, NativeTurnTimingFacts } from './native-turn-timing';
|
|
3
4
|
import type { ChatMessageValues } from '../chat-store/core';
|
|
4
5
|
import type { ChatTurnPrefetch, ChatTurnPrefetchIdentity } from './turn-prefetch';
|
|
@@ -8,8 +9,6 @@ import type { InteractionAnswerRoute, InteractionAnswerRouteOptions } from '../i
|
|
|
8
9
|
import type { ModelFailoverAttempt } from '../model-resolution/failover';
|
|
9
10
|
import type { ModelPolicy } from '../policy-filters/index';
|
|
10
11
|
import type { PersistedChatMessageForTurn, TurnEventStore } from '../stream/index';
|
|
11
|
-
import type { D1LikeForTurns } from '../stream/turn-buffer';
|
|
12
|
-
import type { TurnStreamAuth, TurnStreamNamespaceLike } from '../turn-stream/adapters';
|
|
13
12
|
import type { TurnSpan, TurnSpanAttrs, TurnTrace, TurnTraceSink, TurnTraceSummary } from '../turn-trace/recorder';
|
|
14
13
|
import type { TurnRoutePhase } from './turn-progress';
|
|
15
14
|
import type { ChatTurnPartInput, ChatTurnRequestPayload } from './wire';
|
|
@@ -307,9 +306,11 @@ export interface ChatTurnProduceArgs<TContext, TResource = unknown> {
|
|
|
307
306
|
* `TurnAdmissionRefusedError` when the turn is refused. Start the model call at once; write nothing durable,
|
|
308
307
|
* and read nothing `beforeTurn` adds to `context`, until it resolves. */
|
|
309
308
|
admitted?: Promise<ChatTurnProduceArgs<TContext, TResource>>;
|
|
310
|
-
/**
|
|
311
|
-
*
|
|
312
|
-
* Router
|
|
309
|
+
/** Effective execution signal: product Stop/supersession, opted-in durable Stop/control loss,
|
|
310
|
+
* and optional request-disconnect cancellation.
|
|
311
|
+
* A fresh Router backend also aborts on admission refusal or when the route stops reading it.
|
|
312
|
+
* Pass it to producer I/O; Router/Sandbox option data binds it automatically.
|
|
313
|
+
* Early Router handoff waits for `admitted`. */
|
|
313
314
|
admissionSignal?: AbortSignal;
|
|
314
315
|
}
|
|
315
316
|
/** One event as it crosses the route: the producer's own vocabulary, or an
|
|
@@ -357,12 +358,20 @@ export type ChatTurnGateResult = {
|
|
|
357
358
|
proceed: 'handoff';
|
|
358
359
|
response: Response;
|
|
359
360
|
};
|
|
361
|
+
/** This owner's cancellation observation: the signal aborts on Stop or control loss.
|
|
362
|
+
* Closing observation does not release the lock or establish remote completion. */
|
|
363
|
+
export interface ChatTurnCancellation {
|
|
364
|
+
signal: AbortSignal;
|
|
365
|
+
/** Close this owner's observation; never release the durable lock or claim remote work stopped. */
|
|
366
|
+
close(): void | Promise<void>;
|
|
367
|
+
}
|
|
360
368
|
/** Single-flight lock verdict — acquired (with an opaque handle passed back to
|
|
361
369
|
* `release`), or already held (short-circuit with the product's 409-style
|
|
362
370
|
* `Response`). */
|
|
363
371
|
export type ChatTurnLockResult = {
|
|
364
372
|
acquired: true;
|
|
365
373
|
handle?: unknown;
|
|
374
|
+
cancellation?: ChatTurnCancellation;
|
|
366
375
|
} | {
|
|
367
376
|
acquired: false;
|
|
368
377
|
response: Response;
|
|
@@ -570,13 +579,7 @@ export interface CreateChatTurnRoutesOptions<TContext = void, TResource = unknow
|
|
|
570
579
|
* `createDurableObjectTurnEventStore(env.TURN_STREAM_DO)` in production,
|
|
571
580
|
* `createMemoryTurnEventStore()` in tests). Wired by default — every turn
|
|
572
581
|
* is buffered and replayable. */
|
|
573
|
-
turnStore: TurnEventStore |
|
|
574
|
-
db: D1LikeForTurns;
|
|
575
|
-
lock: {
|
|
576
|
-
namespace: TurnStreamNamespaceLike;
|
|
577
|
-
auth: TurnStreamAuth;
|
|
578
|
-
};
|
|
579
|
-
};
|
|
582
|
+
turnStore: TurnEventStore | ChatTurnStoreBindings;
|
|
580
583
|
/** Build the turn stream after admission, or declare its execution backends.
|
|
581
584
|
* Router calls start before the lock by default, after authorize has verified
|
|
582
585
|
* identity/access. The model service enforces spend before paying a provider.
|
|
@@ -11,6 +11,13 @@ import {
|
|
|
11
11
|
sandboxTransientBackoffMs,
|
|
12
12
|
serializeSandboxProvisioningError
|
|
13
13
|
} from "./chunk-PK65B6HP.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_TURN_LOCK_LOCATION_HINT,
|
|
16
|
+
createDurableTurnLock
|
|
17
|
+
} from "./chunk-MT6ZTQGD.js";
|
|
18
|
+
import {
|
|
19
|
+
createD1TurnEventStore
|
|
20
|
+
} from "./chunk-ISP6ZH3G.js";
|
|
14
21
|
import {
|
|
15
22
|
assertProfilePromptWithinBudget,
|
|
16
23
|
fingerprintAgentProfile
|
|
@@ -877,6 +884,20 @@ ON CONFLICT(id) DO UPDATE SET at = ?2, expires_at = ?3, report = ?4`;
|
|
|
877
884
|
};
|
|
878
885
|
}
|
|
879
886
|
|
|
887
|
+
// src/chat-routes/route-storage.ts
|
|
888
|
+
function createDefaultTurnLock(store) {
|
|
889
|
+
return createDurableTurnLock({ ...store.lock, locationHint: store.region, scopeOf: () => "thread" });
|
|
890
|
+
}
|
|
891
|
+
function resolveTurnStorage(options) {
|
|
892
|
+
const store = options.turnStore;
|
|
893
|
+
if ("append" in store) return { ...options, turnStore: store };
|
|
894
|
+
return {
|
|
895
|
+
...options,
|
|
896
|
+
turnStore: createD1TurnEventStore(store.db),
|
|
897
|
+
turnLock: options.turnLock ?? createDefaultTurnLock(store)
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
|
|
880
901
|
// src/sandbox/prewarm-route.ts
|
|
881
902
|
var AUTOMATED_AGENT = /bot\b|crawler|spider|slurp|facebookexternalhit|embedly|preview|whatsapp|curl\/|wget\/|python-requests|go-http-client/i;
|
|
882
903
|
function isAutomatedPrewarmRequest(request) {
|
|
@@ -906,6 +927,8 @@ function reply(body, status = 200) {
|
|
|
906
927
|
return Response.json(body, { status, headers });
|
|
907
928
|
}
|
|
908
929
|
function createWorkspacePrewarmRoute(options) {
|
|
930
|
+
const turnLock = options.turnStore ? createDefaultTurnLock(options.turnStore) : void 0;
|
|
931
|
+
const receipts = options.receipts ?? (options.turnStore ? createD1WarmReceiptStore(options.turnStore.db) : void 0);
|
|
909
932
|
const recentMs = options.recentMs ?? 3e4;
|
|
910
933
|
const now = options.now ?? (() => Date.now());
|
|
911
934
|
const staleMs = options.staleMs ?? 45e3;
|
|
@@ -956,9 +979,9 @@ function createWorkspacePrewarmRoute(options) {
|
|
|
956
979
|
const mark = { at: now() };
|
|
957
980
|
stepsInFlight.set(id, mark);
|
|
958
981
|
try {
|
|
959
|
-
if (
|
|
982
|
+
if (receipts) {
|
|
960
983
|
try {
|
|
961
|
-
const stored = await
|
|
984
|
+
const stored = await receipts.get(id);
|
|
962
985
|
if (stored && now() < stored.expiresAt) {
|
|
963
986
|
remember(id, stored.expiresAt, warmUntil);
|
|
964
987
|
return result("hit");
|
|
@@ -976,8 +999,8 @@ function createWorkspacePrewarmRoute(options) {
|
|
|
976
999
|
const at = now();
|
|
977
1000
|
const expiresAt = at + step.ttlMs;
|
|
978
1001
|
remember(id, expiresAt, warmUntil);
|
|
979
|
-
if (
|
|
980
|
-
await
|
|
1002
|
+
if (receipts) {
|
|
1003
|
+
await receipts.put(id, { at, expiresAt, ...report ? { report } : {} }).catch((err) => {
|
|
981
1004
|
emit({ type: "failed", key: id, ms: now() - started, error: err instanceof Error ? err.message : String(err) });
|
|
982
1005
|
});
|
|
983
1006
|
}
|
|
@@ -986,6 +1009,20 @@ function createWorkspacePrewarmRoute(options) {
|
|
|
986
1009
|
if (stepsInFlight.get(id) === mark) stepsInFlight.delete(id);
|
|
987
1010
|
}
|
|
988
1011
|
}
|
|
1012
|
+
async function runLegacy(key, warm) {
|
|
1013
|
+
const started = now();
|
|
1014
|
+
const running = inFlight.get(key);
|
|
1015
|
+
if (running && now() - running.at < staleMs) return { outcome: "joined", ms: now() - started };
|
|
1016
|
+
const warmedAt = recent.get(key);
|
|
1017
|
+
if (warmedAt !== void 0 && now() - warmedAt < recentMs) return { outcome: "recent", ms: now() - started };
|
|
1018
|
+
const mark = { at: now() };
|
|
1019
|
+
inFlight.set(key, mark);
|
|
1020
|
+
try {
|
|
1021
|
+
return { ...await run(key, warm), ms: now() - started };
|
|
1022
|
+
} finally {
|
|
1023
|
+
if (inFlight.get(key) === mark) inFlight.delete(key);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
989
1026
|
return async function prewarm(request, context) {
|
|
990
1027
|
const started = now();
|
|
991
1028
|
if (request.method !== "POST") {
|
|
@@ -1001,27 +1038,48 @@ function createWorkspacePrewarmRoute(options) {
|
|
|
1001
1038
|
}
|
|
1002
1039
|
if (auth.status === "denied") return auth.response;
|
|
1003
1040
|
if (auth.status === "declined") return reply({ outcome: "declined", ms: now() - started, reason: auth.reason });
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
return reply({ outcome, ms: now() - started,
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1041
|
+
const steps = "steps" in auth ? [...auth.steps] : [];
|
|
1042
|
+
let lockFailure;
|
|
1043
|
+
if (turnLock) {
|
|
1044
|
+
if (!auth.workspaceId?.trim()) return reply({ outcome: "failed", ms: now() - started, reason: "Lock prewarm requires an authorized workspaceId" });
|
|
1045
|
+
const workspaceId = auth.workspaceId;
|
|
1046
|
+
if (steps.some((step) => step.name === "turn_lock")) return reply({ outcome: "failed", ms: now() - started, reason: "turn_lock is owned by the shared prewarm route" });
|
|
1047
|
+
try {
|
|
1048
|
+
steps.push({
|
|
1049
|
+
name: "turn_lock",
|
|
1050
|
+
key: await warmKey({
|
|
1051
|
+
workspaceId,
|
|
1052
|
+
channel: String(options.turnStore.lock.namespace.idFromName(workspaceId)),
|
|
1053
|
+
region: options.turnStore.region ?? DEFAULT_TURN_LOCK_LOCATION_HINT
|
|
1054
|
+
}),
|
|
1055
|
+
ttlMs: 3e4,
|
|
1056
|
+
run: async () => {
|
|
1057
|
+
await turnLock.warm({ tenantId: workspaceId });
|
|
1058
|
+
return { lockReady: true };
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
const ms = now() - started;
|
|
1063
|
+
lockFailure = { name: "turn_lock", outcome: "failed", ms };
|
|
1064
|
+
emit({
|
|
1065
|
+
type: "step",
|
|
1066
|
+
name: "turn_lock",
|
|
1067
|
+
key: workspaceId,
|
|
1068
|
+
outcome: "failed",
|
|
1069
|
+
ms,
|
|
1070
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1017
1073
|
}
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (inFlight.get(key) === mark) inFlight.delete(key);
|
|
1074
|
+
const pendingSteps = Promise.all(steps.map((step) => runStep(step))).then((results2) => lockFailure ? [...results2, lockFailure] : results2);
|
|
1075
|
+
if ("steps" in auth) {
|
|
1076
|
+
const results2 = await pendingSteps;
|
|
1077
|
+
const outcome2 = results2.some((step) => step.outcome === "failed") ? "failed" : results2.some((step) => step.outcome === "miss") ? "warmed" : results2.some((step) => step.outcome === "joined") ? "joined" : "recent";
|
|
1078
|
+
return reply({ outcome: outcome2, ms: now() - started, steps: results2 });
|
|
1024
1079
|
}
|
|
1080
|
+
const [legacy, results] = await Promise.all([runLegacy(auth.key, auth.warm), pendingSteps]);
|
|
1081
|
+
const outcome = legacy.outcome === "failed" || results.some((step) => step.outcome === "failed") ? "failed" : legacy.outcome === "warmed" || results.some((step) => step.outcome === "miss") ? "warmed" : legacy.outcome === "joined" || results.some((step) => step.outcome === "joined") ? "joined" : legacy.outcome;
|
|
1082
|
+
return reply({ ...legacy, outcome, ms: now() - started, ...results.length ? { steps: results } : {} });
|
|
1025
1083
|
};
|
|
1026
1084
|
}
|
|
1027
1085
|
|
|
@@ -3611,6 +3669,7 @@ export {
|
|
|
3611
3669
|
DEFAULT_WARM_RECEIPT_TABLE,
|
|
3612
3670
|
WARM_RECEIPT_TABLE_DDL,
|
|
3613
3671
|
createD1WarmReceiptStore,
|
|
3672
|
+
resolveTurnStorage,
|
|
3614
3673
|
isAutomatedPrewarmRequest,
|
|
3615
3674
|
createWorkspacePrewarmRoute,
|
|
3616
3675
|
DEFAULT_FOREGROUND_PROVISION_CLAIM_TTL_SECONDS,
|
|
@@ -3689,4 +3748,4 @@ export {
|
|
|
3689
3748
|
sandboxPromptRunner,
|
|
3690
3749
|
createSandboxRunTool
|
|
3691
3750
|
};
|
|
3692
|
-
//# sourceMappingURL=chunk-
|
|
3751
|
+
//# sourceMappingURL=chunk-72ASTUPN.js.map
|