@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.
Files changed (45) hide show
  1. package/dist/agent-profiles/d1.js +3 -3
  2. package/dist/agent-profiles/index.js +3 -3
  3. package/dist/chat-routes/cancellation.d.ts +12 -1
  4. package/dist/chat-routes/index.d.ts +1 -0
  5. package/dist/chat-routes/index.js +15 -15
  6. package/dist/chat-routes/route-storage.d.ts +21 -1
  7. package/dist/chat-routes/stale-turn-lock.d.ts +17 -1
  8. package/dist/chat-routes/turn-ownership.d.ts +1 -0
  9. package/dist/chat-routes/turn-route-contracts.d.ts +15 -12
  10. package/dist/{chunk-ND5XWLRU.js → chunk-72ASTUPN.js} +83 -24
  11. package/dist/chunk-72ASTUPN.js.map +1 -0
  12. package/dist/{chunk-XEAZWJ3W.js → chunk-7Y7U7U7X.js} +2 -2
  13. package/dist/{chunk-5BJHKQ33.js → chunk-ACB7KOQ6.js} +4 -4
  14. package/dist/{chunk-7TZA2TAM.js → chunk-FCYHDENJ.js} +2 -2
  15. package/dist/{chunk-WSQFNMIA.js → chunk-HRBF4B5L.js} +5 -5
  16. package/dist/{chunk-WSQFNMIA.js.map → chunk-HRBF4B5L.js.map} +1 -1
  17. package/dist/{chunk-SRWQCWLR.js → chunk-IX6UVHXY.js} +3 -3
  18. package/dist/{chunk-A2NQMVMF.js → chunk-MT6ZTQGD.js} +328 -118
  19. package/dist/chunk-MT6ZTQGD.js.map +1 -0
  20. package/dist/{chunk-HG2WVONR.js → chunk-UXK5EBQT.js} +42 -26
  21. package/dist/chunk-UXK5EBQT.js.map +1 -0
  22. package/dist/preset-cloudflare/index.js +8 -8
  23. package/dist/public-consultation/index.d.ts +1 -1
  24. package/dist/public-consultation/index.js +8 -8
  25. package/dist/sandbox/index.js +7 -5
  26. package/dist/sandbox/prewarm-route.d.ts +7 -0
  27. package/dist/stream/index.js +17 -17
  28. package/dist/tools/index.js +4 -4
  29. package/dist/turn-stream/adapters.d.ts +19 -11
  30. package/dist/turn-stream/cancellation-do.d.ts +31 -0
  31. package/dist/turn-stream/cancellation.d.ts +23 -0
  32. package/dist/turn-stream/core.d.ts +23 -4
  33. package/dist/turn-stream/do.d.ts +4 -2
  34. package/dist/turn-stream/index.d.ts +1 -0
  35. package/dist/turn-stream/index.js +188 -14
  36. package/dist/turn-stream/index.js.map +1 -1
  37. package/dist/work-product/index.js +2 -2
  38. package/package.json +3 -2
  39. package/dist/chunk-A2NQMVMF.js.map +0 -1
  40. package/dist/chunk-HG2WVONR.js.map +0 -1
  41. package/dist/chunk-ND5XWLRU.js.map +0 -1
  42. /package/dist/{chunk-XEAZWJ3W.js.map → chunk-7Y7U7U7X.js.map} +0 -0
  43. /package/dist/{chunk-5BJHKQ33.js.map → chunk-ACB7KOQ6.js.map} +0 -0
  44. /package/dist/{chunk-7TZA2TAM.js.map → chunk-FCYHDENJ.js.map} +0 -0
  45. /package/dist/{chunk-SRWQCWLR.js.map → chunk-IX6UVHXY.js.map} +0 -0
@@ -15,12 +15,6 @@ import {
15
15
  } from "../chunk-N6URQ6DM.js";
16
16
  import "../chunk-Z4RD5UF7.js";
17
17
  import "../chunk-YG66IHDU.js";
18
- import {
19
- releaseDurableTurnLock
20
- } from "../chunk-A2NQMVMF.js";
21
- import {
22
- createD1TurnEventStore
23
- } from "../chunk-ISP6ZH3G.js";
24
18
  import "../chunk-RZLCBWGG.js";
25
19
  import "../chunk-ZVEEWGDK.js";
26
20
  import "../chunk-5TSRFF5W.js";
@@ -32,11 +26,17 @@ import {
32
26
  classifySandboxTransientFailure,
33
27
  sandboxTransientBackoffMs
34
28
  } from "../chunk-PK65B6HP.js";
29
+ import {
30
+ releaseDurableTurnLock
31
+ } from "../chunk-MT6ZTQGD.js";
32
+ import {
33
+ createD1TurnEventStore
34
+ } from "../chunk-ISP6ZH3G.js";
35
35
  import {
36
36
  parseRenderUiSchema
37
- } from "../chunk-XEAZWJ3W.js";
37
+ } from "../chunk-7Y7U7U7X.js";
38
38
  import "../chunk-S5SRJJQG.js";
39
- import "../chunk-WSQFNMIA.js";
39
+ import "../chunk-HRBF4B5L.js";
40
40
  import {
41
41
  createTurnTrace
42
42
  } from "../chunk-AVBNS64P.js";
@@ -121,9 +121,9 @@ export declare function createPublicConsultation(options: PublicConsultationOpti
121
121
  executionBudget?: ChatTurnExecutionLimits;
122
122
  maxOutputTokens?: number;
123
123
  }) => Promise<{
124
- start?: undefined;
125
124
  status: 'unsupported';
126
125
  reason: string;
126
+ start?: undefined;
127
127
  } | {
128
128
  reason?: undefined;
129
129
  status: 'prepared';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createChatTurnRoutes,
3
3
  streamChatRouteAsSandboxEvents
4
- } from "../chunk-HG2WVONR.js";
4
+ } from "../chunk-UXK5EBQT.js";
5
5
  import "../chunk-KH4QSBNI.js";
6
6
  import "../chunk-CQGEGPY7.js";
7
7
  import "../chunk-RN4WPTBH.js";
@@ -9,30 +9,30 @@ import "../chunk-WP2GYFZ4.js";
9
9
  import "../chunk-4DBHC63F.js";
10
10
  import "../chunk-MH74DY2I.js";
11
11
  import "../chunk-MM6RLOXF.js";
12
- import "../chunk-ND5XWLRU.js";
12
+ import "../chunk-72ASTUPN.js";
13
13
  import "../chunk-F4TUZYMX.js";
14
14
  import "../chunk-N6URQ6DM.js";
15
15
  import "../chunk-Z4RD5UF7.js";
16
16
  import "../chunk-YG66IHDU.js";
17
- import "../chunk-A2NQMVMF.js";
18
- import "../chunk-ISP6ZH3G.js";
19
17
  import "../chunk-RZLCBWGG.js";
20
18
  import "../chunk-ZVEEWGDK.js";
21
19
  import "../chunk-5TSRFF5W.js";
22
20
  import "../chunk-VUBJZEZB.js";
23
21
  import "../chunk-6VQCFJWP.js";
24
22
  import "../chunk-PK65B6HP.js";
23
+ import "../chunk-MT6ZTQGD.js";
24
+ import "../chunk-ISP6ZH3G.js";
25
25
  import "../chunk-ZLX4BA27.js";
26
26
  import "../chunk-XELWWXJJ.js";
27
27
  import "../chunk-DSMGS4IV.js";
28
- import "../chunk-5BJHKQ33.js";
28
+ import "../chunk-ACB7KOQ6.js";
29
29
  import "../chunk-6A7MYOUI.js";
30
30
  import "../chunk-O7UX55EU.js";
31
- import "../chunk-XEAZWJ3W.js";
31
+ import "../chunk-7Y7U7U7X.js";
32
32
  import "../chunk-S5SRJJQG.js";
33
- import "../chunk-7TZA2TAM.js";
33
+ import "../chunk-FCYHDENJ.js";
34
34
  import "../chunk-UGWQLQDS.js";
35
- import "../chunk-WSQFNMIA.js";
35
+ import "../chunk-HRBF4B5L.js";
36
36
  import "../chunk-IDG2XR5O.js";
37
37
  import "../chunk-D6UJEOZQ.js";
38
38
  import "../chunk-AVBNS64P.js";
@@ -101,7 +101,7 @@ import {
101
101
  warmKey,
102
102
  warmReceiptId,
103
103
  warmWeekdayOf
104
- } from "../chunk-ND5XWLRU.js";
104
+ } from "../chunk-72ASTUPN.js";
105
105
  import {
106
106
  createWarmCache
107
107
  } from "../chunk-F4TUZYMX.js";
@@ -145,15 +145,17 @@ import {
145
145
  workspaceSandboxRecoveryMessage,
146
146
  workspaceSandboxRecoveryRecommendedActions
147
147
  } from "../chunk-PK65B6HP.js";
148
+ import "../chunk-MT6ZTQGD.js";
149
+ import "../chunk-ISP6ZH3G.js";
148
150
  import "../chunk-DSMGS4IV.js";
149
- import "../chunk-5BJHKQ33.js";
151
+ import "../chunk-ACB7KOQ6.js";
150
152
  import "../chunk-6A7MYOUI.js";
151
153
  import "../chunk-O7UX55EU.js";
152
- import "../chunk-XEAZWJ3W.js";
154
+ import "../chunk-7Y7U7U7X.js";
153
155
  import "../chunk-S5SRJJQG.js";
154
- import "../chunk-7TZA2TAM.js";
156
+ import "../chunk-FCYHDENJ.js";
155
157
  import "../chunk-UGWQLQDS.js";
156
- import "../chunk-WSQFNMIA.js";
158
+ import "../chunk-HRBF4B5L.js";
157
159
  import "../chunk-D6UJEOZQ.js";
158
160
  import "../chunk-AVBNS64P.js";
159
161
  import {
@@ -1,4 +1,5 @@
1
1
  import { type WarmReceiptStore } from './warm-receipts';
2
+ import { type ChatTurnStoreBindings } from '../chat-routes/route-storage';
2
3
  /** What the product decided for this request. */
3
4
  export type WorkspacePrewarmAuthorization =
4
5
  /** Not signed in, not a member, or a foreign origin: return this response. */
@@ -19,12 +20,14 @@ export type WorkspacePrewarmAuthorization =
19
20
  */
20
21
  | {
21
22
  status: 'allowed';
23
+ workspaceId?: string;
22
24
  key: string;
23
25
  warm: () => Promise<WorkspacePrewarmReport | void>;
24
26
  }
25
27
  /** Run each step whose key has no unexpired receipt. */
26
28
  | {
27
29
  status: 'allowed';
30
+ workspaceId?: string;
28
31
  steps: readonly WorkspaceWarmStep[];
29
32
  };
30
33
  /** One warm step, keyed by exactly what it depends on. */
@@ -87,6 +90,10 @@ export type WorkspacePrewarmEvent = {
87
90
  error?: string;
88
91
  };
89
92
  export interface CreateWorkspacePrewarmRouteOptions<Context = void> {
93
+ /** The same binding descriptor chat uses. Adds the keyed turn_lock warm by default.
94
+ * An allowed authorization must carry its server-verified workspaceId; request body identity is never used.
95
+ * Receipts default to this database; apply WARM_RECEIPT_TABLE_DDL through the product migration runner. */
96
+ turnStore?: ChatTurnStoreBindings;
90
97
  /** `context` is whatever the caller passed beside the request, such as a
91
98
  * Hono context carrying the Worker's bindings. */
92
99
  /** `threadId` is the thread the composer belongs to, when the browser sent one (composer focus). Check the member's access to it before warming anything for it. */
@@ -12,23 +12,6 @@ import {
12
12
  normalizeClientTurnId,
13
13
  resolveChatTurn
14
14
  } from "../chunk-YG66IHDU.js";
15
- import {
16
- DEFAULT_RUNNING_TURN_LEASE_MS,
17
- DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
18
- TURN_EVENTS_MIGRATION_SQL,
19
- TURN_STATUS_LEASE_MIGRATION_SQL,
20
- TURN_STATUS_RETENTION_MIGRATION_SQL,
21
- TURN_STATUS_SCOPE_MIGRATION_SQL,
22
- coalesceChatStreamEvents,
23
- coalesceDeltas,
24
- createBufferedTurnTap,
25
- createD1TurnEventStore,
26
- createMemoryTurnEventStore,
27
- isLiveProgressEvent,
28
- pumpBufferedTurn,
29
- replayTurnEvents,
30
- stampReplaySeq
31
- } from "../chunk-ISP6ZH3G.js";
32
15
  import {
33
16
  MISSING_TOOL_TERMINAL_ERROR,
34
17
  MISSING_TOOL_TERMINAL_REASON,
@@ -52,6 +35,23 @@ import {
52
35
  terminalizeDanglingToolParts
53
36
  } from "../chunk-VUBJZEZB.js";
54
37
  import "../chunk-6VQCFJWP.js";
38
+ import {
39
+ DEFAULT_RUNNING_TURN_LEASE_MS,
40
+ DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
41
+ TURN_EVENTS_MIGRATION_SQL,
42
+ TURN_STATUS_LEASE_MIGRATION_SQL,
43
+ TURN_STATUS_RETENTION_MIGRATION_SQL,
44
+ TURN_STATUS_SCOPE_MIGRATION_SQL,
45
+ coalesceChatStreamEvents,
46
+ coalesceDeltas,
47
+ createBufferedTurnTap,
48
+ createD1TurnEventStore,
49
+ createMemoryTurnEventStore,
50
+ isLiveProgressEvent,
51
+ pumpBufferedTurn,
52
+ replayTurnEvents,
53
+ stampReplaySeq
54
+ } from "../chunk-ISP6ZH3G.js";
55
55
  import "../chunk-WL7PZK7Q.js";
56
56
  export {
57
57
  DEFAULT_RUNNING_TURN_LEASE_MS,
@@ -5,7 +5,7 @@ import {
5
5
  outcomeStatus,
6
6
  resolveToolCapabilities,
7
7
  restrictTaxonomy
8
- } from "../chunk-5BJHKQ33.js";
8
+ } from "../chunk-ACB7KOQ6.js";
9
9
  import {
10
10
  DEFAULT_APP_TOOL_PATHS,
11
11
  DEFAULT_HEADER_NAMES,
@@ -24,7 +24,7 @@ import {
24
24
  verifyCapabilityToken,
25
25
  verifyExpiringCapabilityToken
26
26
  } from "../chunk-O7UX55EU.js";
27
- import "../chunk-XEAZWJ3W.js";
27
+ import "../chunk-7Y7U7U7X.js";
28
28
  import "../chunk-S5SRJJQG.js";
29
29
  import {
30
30
  APP_TOOL_NAMES,
@@ -33,11 +33,11 @@ import {
33
33
  defineAppTool,
34
34
  findCustomTool,
35
35
  isAppToolName
36
- } from "../chunk-7TZA2TAM.js";
36
+ } from "../chunk-FCYHDENJ.js";
37
37
  import "../chunk-UGWQLQDS.js";
38
38
  import {
39
39
  ToolInputError
40
- } from "../chunk-WSQFNMIA.js";
40
+ } from "../chunk-HRBF4B5L.js";
41
41
  export {
42
42
  APP_TOOL_NAMES,
43
43
  DEFAULT_APP_TOOL_PATHS,
@@ -4,13 +4,18 @@
4
4
  * run the same authenticated request path.
5
5
  * Products provide workspace authorization and their binding's TURN_STREAM_AUTH_SECRET.
6
6
  */
7
- import { type ReconcileStaleTurnLockOptions } from '../chat-routes/stale-turn-lock';
7
+ import { type TurnCancellationConnection, type TurnCancellationIdentity } from './cancellation';
8
+ import { type ReconcileStaleTurnLockOptions, type StaleTurnLockOwnerProbeResult } from '../chat-routes/stale-turn-lock';
8
9
  import type { TurnEventStore } from '../stream/turn-buffer';
9
- import { type DurableTurnLock, type TurnLockAcquireResult, type TurnLockReleaseInput, type TurnLockScope } from './core';
10
+ import { type DurableTurnLock, type TurnLockAcquireResult, type TurnLockReleaseInput, type TurnLockInterruptedReleaseInput, type TurnLockScope } from './core';
10
11
  /** Resolve a stub interface for handling fetch requests with optional initialization parameters */
11
12
  export interface TurnStreamStubLike {
12
13
  fetch(input: Request | string, init?: RequestInit): Promise<Response>;
13
14
  }
15
+ /** Cloudflare placement hints. A hint affects only a channel's first creation, never an existing object's location. */
16
+ export type TurnStreamLocationHint = 'wnam' | 'enam' | 'sam' | 'weur' | 'eeur' | 'apac' | 'apac-ne' | 'apac-se' | 'oc' | 'afr' | 'me';
17
+ /** The default matches the application D1 region unless its binding descriptor names another region. */
18
+ export declare const DEFAULT_TURN_LOCK_LOCATION_HINT: TurnStreamLocationHint;
14
19
  /** The surface of `DurableObjectNamespace` the adapters use. */
15
20
  export interface TurnStreamNamespaceLike {
16
21
  idFromName(name: string): unknown;
@@ -41,6 +46,9 @@ export interface AcquireDurableTurnLockInput {
41
46
  turnId?: string;
42
47
  /** Supply to reclaim/retry with a stable id; default mints a UUID. */
43
48
  lockId?: string;
49
+ cancellation?: {
50
+ turnStreamId: string;
51
+ };
44
52
  }
45
53
  /** Acquire a durable turn lock in the specified namespace with given input parameters */
46
54
  export declare function acquireDurableTurnLock(namespace: TurnStreamNamespaceLike, input: AcquireDurableTurnLockInput, auth: TurnStreamAuth): Promise<TurnLockAcquireResult>;
@@ -68,15 +76,7 @@ export declare function releaseDurableTurnLock(namespace: TurnStreamNamespaceLik
68
76
  deferred?: boolean;
69
77
  }>;
70
78
  /** Define input parameters to release an interrupted durable turn lock in a workspace or thread */
71
- export interface ReleaseInterruptedDurableTurnLockInput {
72
- workspaceId: string;
73
- threadId: string;
74
- /** Try only this scope; omit to try workspace then thread (a stop button
75
- * doesn't know which lane the wedged turn ran on). */
76
- scope?: TurnLockScope;
77
- interruptedAt: number;
78
- turnId?: string;
79
- }
79
+ export type ReleaseInterruptedDurableTurnLockInput = TurnLockInterruptedReleaseInput;
80
80
  /** Fenced out-of-band release — the DO refuses a successor lock (started
81
81
  * after `interruptedAt`) and a turnId mismatch. Returns whether any scope
82
82
  * released. */
@@ -89,6 +89,8 @@ export interface ReconcileStaleDurableTurnLockOptions extends Pick<ReconcileStal
89
89
  threadId: string;
90
90
  /** The lock the acquire attempt was refused on. */
91
91
  active: DurableTurnLock;
92
+ /** Cancellable Router locks require positive exact outer + child quiescence; native-only probes cannot attest it. */
93
+ probeOwner?(identity: TurnCancellationIdentity): Promise<StaleTurnLockOwnerProbeResult>;
92
94
  }
93
95
  /**
94
96
  * `/chat-routes`' `reconcileStaleTurnLock` policy wired to the DO: the
@@ -110,6 +112,7 @@ export interface TurnLockSeamArgs<TContext> {
110
112
  sessionId: string;
111
113
  };
112
114
  executionId: string;
115
+ turnStreamId?: string;
113
116
  context: TContext;
114
117
  body: {
115
118
  turnId?: string;
@@ -119,12 +122,15 @@ export interface TurnLockSeamArgs<TContext> {
119
122
  export type TurnLockSeamResult = {
120
123
  acquired: true;
121
124
  handle?: unknown;
125
+ cancellation?: TurnCancellationConnection;
122
126
  } | {
123
127
  acquired: false;
124
128
  response: Response;
125
129
  };
126
130
  /** Define options for creating a durable turn lock with customizable scope and identification methods */
127
131
  export interface CreateDurableTurnLockOptions<TContext> {
132
+ /** New channels use this hint; existing channel IDs and locations are preserved. */
133
+ locationHint?: TurnStreamLocationHint;
128
134
  namespace: TurnStreamNamespaceLike;
129
135
  /** Capability tokens for the DO; pass the worker's
130
136
  * `env.TURN_STREAM_AUTH_SECRET`. The DO validates every request. */
@@ -132,6 +138,8 @@ export interface CreateDurableTurnLockOptions<TContext> {
132
138
  /** Which lane serializes this turn: `'workspace'` (shared sandbox — one
133
139
  * turn per workspace) or `'thread'` (router lane — one turn per thread). */
134
140
  scopeOf(args: TurnLockSeamArgs<TContext>): TurnLockScope;
141
+ /** Opt the existing lock into durable Stop. Leave native/durable completion lanes on their existing owner. */
142
+ cancellationOf?(args: TurnLockSeamArgs<TContext>): boolean;
135
143
  /** Override the execution id the lock records (e.g. a follow-up reclaiming
136
144
  * the execution it already dispatched). Default: the turn's own. */
137
145
  lockExecutionIdOf?(args: TurnLockSeamArgs<TContext>): string | undefined;
@@ -0,0 +1,31 @@
1
+ import type { DurableTurnLock, TurnLockReleaseInput } from './core';
2
+ import type { TurnStreamDOState, TurnStreamSocket } from './do';
3
+ /** One cancellable turn, including the lock generation that grants its producer authority. */
4
+ export interface TurnCancellationIdentity extends TurnLockReleaseInput {
5
+ turnStreamId: string;
6
+ }
7
+ export interface TurnCancellationSocketMeta {
8
+ sessionId: string;
9
+ scope: 'thread' | 'workspace';
10
+ synced: boolean;
11
+ cancellation?: TurnCancellationIdentity;
12
+ }
13
+ export declare function readTurnCancellationIdentity(value: Record<string, unknown>): TurnCancellationIdentity | null;
14
+ /** Storage and hibernatable sockets belong to the existing lock DO; this helper never schedules or releases work. */
15
+ export declare class DurableTurnCancellation {
16
+ private readonly state;
17
+ private readonly readLock;
18
+ private readonly writeLock;
19
+ constructor(state: TurnStreamDOState, readLock: (input: TurnCancellationIdentity) => Promise<DurableTurnLock | null>, writeLock: (lock: DurableTurnLock) => Promise<void>);
20
+ owns(input: TurnCancellationIdentity): Promise<boolean>;
21
+ permitsRecovery(lock: DurableTurnLock, input: TurnCancellationIdentity): boolean;
22
+ request(input: TurnCancellationIdentity): Promise<{
23
+ requested: boolean;
24
+ reason?: 'stale-owner';
25
+ }>;
26
+ sync(socket: TurnStreamSocket, meta: TurnCancellationSocketMeta): Promise<void>;
27
+ released(lock: DurableTurnLock): void;
28
+ expired(lock: DurableTurnLock): void;
29
+ private close;
30
+ private send;
31
+ }
@@ -0,0 +1,23 @@
1
+ import type { TurnStreamAuth, TurnStreamNamespaceLike } from './adapters';
2
+ import type { TurnCancellationIdentity } from './cancellation-do';
3
+ export type { TurnCancellationIdentity } from './cancellation-do';
4
+ /** Per-owner observation only. Closing it never changes or releases the durable lock. */
5
+ export interface TurnCancellationConnection {
6
+ signal: AbortSignal;
7
+ close(): void;
8
+ }
9
+ export declare class TurnCancellationRequestedError extends Error {
10
+ readonly code = "turn_cancel_requested";
11
+ constructor();
12
+ }
13
+ export declare class TurnControlUnavailableError extends Error {
14
+ readonly code = "turn_control_unavailable";
15
+ constructor(message?: string);
16
+ }
17
+ /** The product authorizes Stop first. This exact fenced request records intent; it never claims work stopped. */
18
+ export declare function requestDurableTurnCancellation(namespace: TurnStreamNamespaceLike, identity: TurnCancellationIdentity, auth: TurnStreamAuth): Promise<{
19
+ requested: boolean;
20
+ reason?: 'stale-owner';
21
+ }>;
22
+ /** One server-owned connection on the existing authenticated DO transport, with retained cancellation replay. */
23
+ export declare function connectDurableTurnCancellation(namespace: TurnStreamNamespaceLike, identity: TurnCancellationIdentity, auth: TurnStreamAuth): Promise<TurnCancellationConnection>;
@@ -20,13 +20,20 @@ export declare const TURN_STREAM_TOKEN_TTL_MS = 60000;
20
20
  /** Request header the adapters attach (and the DO accepts). The worker also
21
21
  * attaches it when forwarding an authorized browser WebSocket handshake. */
22
22
  export declare const TURN_STREAM_TOKEN_HEADER = "x-turn-stream-token";
23
- /** `v1.<base64url-channel>.<exp-ms-36>.<base64url-mac>` — the expiry is inside the signed payload so
24
- * it cannot be extended by editing the token. */
25
- export declare function mintTurnStreamToken(channelName: string, secret: string, now?: () => number, ttlMs?: number): Promise<string>;
23
+ /** Server control authority is separate from the channel capabilities used by existing viewer forwarders. */
24
+ export interface TurnStreamTokenClaims {
25
+ purpose: 'turn-control' | 'turn-cancel' | 'turn-recovery';
26
+ identity: TurnLockReleaseInput & {
27
+ turnStreamId: string;
28
+ };
29
+ }
30
+ /** Legacy v1 channel capabilities remain unchanged. Optional v2 claims bind
31
+ * server-only purpose and exact owner identity inside the same signed payload. */
32
+ export declare function mintTurnStreamToken(channelName: string, secret: string, now?: () => number, ttlMs?: number, claims?: TurnStreamTokenClaims): Promise<string>;
26
33
  /** Verify a token for `channelName`: constant-time MAC compare with the
27
34
  * exact channel name embedded in the signed payload, plus freshness. A
28
35
  * token minted for any other channel — or a tampered expiry — is false. */
29
- export declare function verifyTurnStreamToken(channelName: string, token: string, secret: string, now?: () => number): Promise<boolean>;
36
+ export declare function verifyTurnStreamToken(channelName: string, token: string, secret: string, now?: () => number, claims?: TurnStreamTokenClaims): Promise<boolean>;
30
37
  /** Define the scope level for acquiring a turn lock within thread or workspace contexts */
31
38
  export type TurnLockScope = 'thread' | 'workspace';
32
39
  /** Channel for a thread's viewer signals. */
@@ -75,6 +82,11 @@ export interface DurableTurnLock {
75
82
  * parked on the lock until the task settles. Written only through the DO's
76
83
  * defer seam — the base package never sets it on its own. */
77
84
  releasePending?: boolean;
85
+ /** Optional Router control, owned by this exact lock generation. Stop never releases the lock. */
86
+ cancellation?: {
87
+ turnStreamId: string;
88
+ requestedAt?: number;
89
+ };
78
90
  }
79
91
  /** Define input parameters required to acquire a turn-based lock in a workspace thread */
80
92
  export interface TurnLockAcquireInput {
@@ -84,6 +96,9 @@ export interface TurnLockAcquireInput {
84
96
  executionId: string;
85
97
  lockId: string;
86
98
  turnId?: string;
99
+ cancellation?: {
100
+ turnStreamId: string;
101
+ };
87
102
  }
88
103
  /** Resolve the result of attempting to acquire a turn lock indicating success or active lock status */
89
104
  export type TurnLockAcquireResult = {
@@ -112,6 +127,10 @@ export interface TurnLockInterruptedReleaseInput {
112
127
  scope?: TurnLockScope;
113
128
  interruptedAt: number;
114
129
  turnId?: string;
130
+ /** Only after the existing stale policy positively proves this exact Router owner and its children abandoned. */
131
+ recovery?: TurnLockReleaseInput & {
132
+ turnStreamId: string;
133
+ };
115
134
  }
116
135
  /** `stored` is what the DO read from storage; expired locks are dead. */
117
136
  export declare function activeTurnLock(stored: DurableTurnLock | undefined, now: number): DurableTurnLock | null;
@@ -67,6 +67,7 @@ export declare class TurnStreamDO {
67
67
  protected readonly state: TurnStreamDOState;
68
68
  protected readonly env: unknown;
69
69
  protected readonly options: TurnStreamDOOptions;
70
+ private readonly cancellation;
70
71
  private recentCreated;
71
72
  private activeThreads;
72
73
  constructor(state: TurnStreamDOState, env?: unknown, options?: TurnStreamDOOptions);
@@ -84,6 +85,7 @@ export declare class TurnStreamDO {
84
85
  * secret fails closed with a 500 that names the fix (issue #746).
85
86
  */
86
87
  private authorizeRequest;
88
+ private authorizeControl;
87
89
  fetch(request: Request): Promise<Response>;
88
90
  /** Called for any request no base endpoint claimed (before the 404), so a
89
91
  * subclass adds product endpoints without touching base routing. Return
@@ -120,8 +122,8 @@ export declare class TurnStreamDO {
120
122
  private handleBroadcast;
121
123
  private loadActiveThreads;
122
124
  private persistActiveThreads;
123
- /** The live lock under `key` (default: the workspace-scope lock); an
124
- * expired one is deleted and reads as none. */
125
+ /** The live lock under `key`. Cancellation never extends TTL; an actual
126
+ * product child/persistence obligation still vetoes expiry deletion. */
125
127
  protected loadActiveLock(now?: number, key?: string): Promise<DurableTurnLock | null>;
126
128
  private releaseActiveLock;
127
129
  /** Park a release on the lock itself; {@link completeDeferredLockRelease}
@@ -13,3 +13,4 @@ export * from './core';
13
13
  export * from './do';
14
14
  export * from './adapters';
15
15
  export * from './memory';
16
+ export * from './cancellation';