@tangle-network/agent-app 4.0.5 → 4.0.7
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/billing/identity-bound.d.ts +8 -3
- package/dist/billing/index.js +1 -1
- package/dist/chat-routes/index.js +5 -5
- package/dist/chat-routes/route-storage.d.ts +1 -0
- package/dist/chat-routes/turn-ownership.d.ts +7 -3
- package/dist/chat-routes/turn-route-contracts.d.ts +6 -1
- package/dist/{chunk-ROTSZSYZ.js → chunk-4OR7NNYB.js} +49 -11
- package/dist/chunk-4OR7NNYB.js.map +1 -0
- package/dist/{chunk-JFBJ7MGK.js → chunk-ASWAPIJM.js} +40 -3
- package/dist/chunk-ASWAPIJM.js.map +1 -0
- package/dist/{chunk-63JF23V6.js → chunk-FTGKXM7O.js} +45 -14
- package/dist/chunk-FTGKXM7O.js.map +1 -0
- package/dist/{chunk-ZTGITMYQ.js → chunk-FZOHBYGV.js} +74 -13
- package/dist/chunk-FZOHBYGV.js.map +1 -0
- package/dist/{chunk-2PCNHHN2.js → chunk-WGT32NQ4.js} +2 -2
- package/dist/{chunk-3Q3UEWKK.js → chunk-YQE2CGIO.js} +1 -1
- package/dist/{chunk-3Q3UEWKK.js.map → chunk-YQE2CGIO.js.map} +1 -1
- package/dist/platform/delegated-keys.d.ts +10 -5
- package/dist/platform/index.js +20 -6
- package/dist/platform/index.js.map +1 -1
- package/dist/preset-cloudflare/index.js +4 -4
- package/dist/public-consultation/index.js +5 -5
- package/dist/sandbox/holder-box.d.ts +13 -0
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +7 -3
- package/dist/stream/index.js +2 -2
- package/dist/stream/turn-buffer.d.ts +5 -2
- package/dist/turn-stream/adapters.d.ts +42 -1
- package/dist/turn-stream/index.js +4 -2
- package/dist/turn-stream/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-63JF23V6.js.map +0 -1
- package/dist/chunk-JFBJ7MGK.js.map +0 -1
- package/dist/chunk-ROTSZSYZ.js.map +0 -1
- package/dist/chunk-ZTGITMYQ.js.map +0 -1
- /package/dist/{chunk-2PCNHHN2.js.map → chunk-WGT32NQ4.js.map} +0 -0
|
@@ -70,7 +70,11 @@ export interface DurableWorkspaceKeyProvisioner {
|
|
|
70
70
|
budgetSpent?: number;
|
|
71
71
|
expiresAt?: string | null;
|
|
72
72
|
}>;
|
|
73
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Retire one child. `slot` is the row that minted it: its name, its own source and Platform user, so a child minted
|
|
75
|
+
* under an earlier source is retired through that source's slot. A typed refusal carries `refusal.status`.
|
|
76
|
+
*/
|
|
77
|
+
revokeKey(id: string, slot?: Pick<DurableWorkspaceKeyRecord, 'name' | 'sourceKeyId' | 'platformUserId'>): Promise<unknown>;
|
|
74
78
|
/** Find remote keys for a specific persisted provisioning attempt. */
|
|
75
79
|
findCreatedKeys(input: {
|
|
76
80
|
name: string;
|
|
@@ -220,8 +224,9 @@ export interface DurableWorkspaceKeyManagerOptions {
|
|
|
220
224
|
* Create a product-neutral manager for child-key issuance and cleanup.
|
|
221
225
|
*
|
|
222
226
|
* The provisioner must already be authenticated for the current source
|
|
223
|
-
* credential. The manager persists
|
|
224
|
-
* fingerprint
|
|
227
|
+
* credential. The manager persists the source id and its non-secret
|
|
228
|
+
* fingerprint with each row, reuses an active row for the same workspace,
|
|
229
|
+
* owner, product and Platform user, and cleans each row through its own slot.
|
|
225
230
|
*/
|
|
226
231
|
export declare function createIdentityBoundWorkspaceKeyManager(options: DurableWorkspaceKeyManagerOptions): DurableWorkspaceKeyManager;
|
|
227
232
|
export {};
|
package/dist/billing/index.js
CHANGED
|
@@ -88,14 +88,14 @@ import {
|
|
|
88
88
|
turnPromptText,
|
|
89
89
|
valueRedactor,
|
|
90
90
|
withProducerStream
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-4OR7NNYB.js";
|
|
92
92
|
import "../chunk-SBHFMDR7.js";
|
|
93
93
|
import "../chunk-H6BRJU5M.js";
|
|
94
94
|
import "../chunk-4DBHC63F.js";
|
|
95
95
|
import "../chunk-RN4WPTBH.js";
|
|
96
96
|
import "../chunk-MM6RLOXF.js";
|
|
97
97
|
import "../chunk-M4QITAQV.js";
|
|
98
|
-
import "../chunk-
|
|
98
|
+
import "../chunk-ASWAPIJM.js";
|
|
99
99
|
import "../chunk-F4TUZYMX.js";
|
|
100
100
|
import {
|
|
101
101
|
redactErrorMessage
|
|
@@ -110,7 +110,7 @@ import {
|
|
|
110
110
|
storeSupportsDraftPersistence,
|
|
111
111
|
transformVisibleTextParts
|
|
112
112
|
} from "../chunk-K4YIDNX5.js";
|
|
113
|
-
import "../chunk-
|
|
113
|
+
import "../chunk-WGT32NQ4.js";
|
|
114
114
|
import "../chunk-YG66IHDU.js";
|
|
115
115
|
import {
|
|
116
116
|
attachmentInputToPart,
|
|
@@ -129,11 +129,11 @@ import {
|
|
|
129
129
|
DEFAULT_STALE_TURN_LOCK_GRACE_MS,
|
|
130
130
|
DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS,
|
|
131
131
|
reconcileStaleTurnLock
|
|
132
|
-
} from "../chunk-
|
|
132
|
+
} from "../chunk-FZOHBYGV.js";
|
|
133
133
|
import {
|
|
134
134
|
coalesceDeltas,
|
|
135
135
|
createBufferedTurnTap
|
|
136
|
-
} from "../chunk-
|
|
136
|
+
} from "../chunk-YQE2CGIO.js";
|
|
137
137
|
import {
|
|
138
138
|
AGENT_HANDLE_PATTERN,
|
|
139
139
|
ChatTurnInputError,
|
|
@@ -17,6 +17,7 @@ export declare function createDefaultTurnLock<TContext>(store: Pick<ChatTurnStor
|
|
|
17
17
|
acquire(args: import("../turn-stream/index.js").TurnLockSeamArgs<TContext>): Promise<import("../turn-stream/index.js").TurnLockSeamResult>;
|
|
18
18
|
release(handle: unknown): Promise<void>;
|
|
19
19
|
park(handle: unknown): Promise<boolean>;
|
|
20
|
+
holdForHandoff?(handle: unknown): Promise<boolean>;
|
|
20
21
|
warm(target: {
|
|
21
22
|
tenantId: string;
|
|
22
23
|
threadId?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AssistantDraftWriter } from './draft-persistence.js';
|
|
2
2
|
import type { NativeCompletionHandoffOptions, NativeTimingTransfer } from './native-turn-timing.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type BufferedTurnTap, type TurnEventStore } from '../stream/index.js';
|
|
4
4
|
import type { ChatTurnLock, ChatTurnRouteProducer } from './turn-route-contracts.js';
|
|
5
5
|
interface OwnershipState {
|
|
6
6
|
producer?: ChatTurnRouteProducer;
|
|
@@ -16,9 +16,13 @@ interface OwnershipState {
|
|
|
16
16
|
}
|
|
17
17
|
/** One transfer of terminal authority, retaining the route only as a live projector. */
|
|
18
18
|
export declare function createChatTurnOwnership(state: OwnershipState, log: (message: string, meta?: Record<string, unknown>) => void, turnStreamId: string, options: {
|
|
19
|
-
turnLock?: Pick<ChatTurnLock<unknown>, 'release' | 'park'>;
|
|
20
|
-
|
|
19
|
+
turnLock?: Pick<ChatTurnLock<unknown>, 'release' | 'park' | 'holdForHandoff'>;
|
|
20
|
+
turnStore?: Pick<TurnEventStore, 'setStatus'>;
|
|
21
|
+
}, scopeId?: string): {
|
|
21
22
|
handoffCompletion: (handoff?: NativeCompletionHandoffOptions) => Promise<void>;
|
|
22
23
|
releaseLock: () => Promise<void>;
|
|
24
|
+
markRunning: () => Promise<void>;
|
|
25
|
+
stopRenewal: () => Promise<void>;
|
|
26
|
+
releaseBeforeDrain: (end: 'complete' | 'error' | 'handoff') => Promise<void>;
|
|
23
27
|
};
|
|
24
28
|
export {};
|
|
@@ -425,6 +425,9 @@ export interface ChatTurnLock<TContext, TResource = unknown> {
|
|
|
425
425
|
release(handle: unknown): void | Promise<void>;
|
|
426
426
|
/** Record a release for the durable owner to complete without freeing the lock; absent or false, the lock stays held. */
|
|
427
427
|
park?(handle: unknown): Promise<boolean>;
|
|
428
|
+
/** Keep the lock held for the durable owner a turn hands off to (`handoffCompletion`), for a lock whose stale-lock
|
|
429
|
+
* reclaim would read the turn as dead once the route stops renewing it. The owner's release still frees it. */
|
|
430
|
+
holdForHandoff?(handle: unknown): Promise<boolean>;
|
|
428
431
|
/** Bring up whatever `acquire` will talk to, as soon as the turn is admitted
|
|
429
432
|
* and while `prepareTurn` and the history read run. Never awaited; a failure
|
|
430
433
|
* is logged and the turn goes on to `acquire` as usual. */
|
|
@@ -678,7 +681,9 @@ export interface CreateChatTurnRoutesOptions<TContext = void, TResource = unknow
|
|
|
678
681
|
* - `{proceed:'handoff'}` releases the route-acquired lock, returns the
|
|
679
682
|
* product's accepted `Response`, and transfers execution and lifecycle
|
|
680
683
|
* ownership to the product's durable owner. The route runs no producer
|
|
681
|
-
* or lifecycle hook.
|
|
684
|
+
* or lifecycle hook. With a lock that uses the default reclaim, the route
|
|
685
|
+
* wrote a running row for `args.turnStreamId` at acquire; the owner
|
|
686
|
+
* settles it (or it lapses with its lease).
|
|
682
687
|
* - Always returning `{proceed:true}` is supported, not a misuse: the seam
|
|
683
688
|
* doubles as the one place that runs after the user row exists and before
|
|
684
689
|
* the producer, which is where per-turn analytics and readiness
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
sandboxRunFailureDetail,
|
|
32
32
|
streamSandboxPrompt,
|
|
33
33
|
turnStorageBindings
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-ASWAPIJM.js";
|
|
35
35
|
import {
|
|
36
36
|
redactErrorMessage
|
|
37
37
|
} from "./chunk-MH74DY2I.js";
|
|
@@ -79,11 +79,12 @@ import {
|
|
|
79
79
|
parseJsonObjectBody
|
|
80
80
|
} from "./chunk-ALIWB2P3.js";
|
|
81
81
|
import {
|
|
82
|
+
DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS,
|
|
82
83
|
coalesceDeltas,
|
|
83
84
|
createBufferedTurnTap,
|
|
84
85
|
replayTurnEvents,
|
|
85
86
|
stampReplaySeq
|
|
86
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-YQE2CGIO.js";
|
|
87
88
|
import {
|
|
88
89
|
ChatTurnInputError,
|
|
89
90
|
DISPATCH_MAX_PARTS,
|
|
@@ -2506,7 +2507,7 @@ function createNativeTimingTransfer(read, onError) {
|
|
|
2506
2507
|
}
|
|
2507
2508
|
|
|
2508
2509
|
// src/chat-routes/turn-ownership.ts
|
|
2509
|
-
function createChatTurnOwnership(state, log, turnStreamId, options) {
|
|
2510
|
+
function createChatTurnOwnership(state, log, turnStreamId, options, scopeId) {
|
|
2510
2511
|
const attempt = async (step, run) => {
|
|
2511
2512
|
try {
|
|
2512
2513
|
await run();
|
|
@@ -2514,10 +2515,37 @@ function createChatTurnOwnership(state, log, turnStreamId, options) {
|
|
|
2514
2515
|
log(`[chat-routes] ${step} failed`, { turnId: turnStreamId, error: err instanceof Error ? err.message : String(err) });
|
|
2515
2516
|
}
|
|
2516
2517
|
};
|
|
2518
|
+
const store = options.turnLock?.holdForHandoff ? options.turnStore : void 0;
|
|
2519
|
+
let runningRow;
|
|
2520
|
+
let renewal;
|
|
2521
|
+
const markRunning = async () => {
|
|
2522
|
+
if (!store) return;
|
|
2523
|
+
const write = () => runningRow = (runningRow ?? Promise.resolve()).catch(() => {
|
|
2524
|
+
}).then(() => store.setStatus(turnStreamId, "running", scopeId));
|
|
2525
|
+
const first = write();
|
|
2526
|
+
renewal = setInterval(() => void write().catch(() => {
|
|
2527
|
+
}), DEFAULT_RUNNING_TURN_RENEW_INTERVAL_MS);
|
|
2528
|
+
return first;
|
|
2529
|
+
};
|
|
2530
|
+
const stopRenewal = async () => {
|
|
2531
|
+
clearInterval(renewal);
|
|
2532
|
+
renewal = void 0;
|
|
2533
|
+
await runningRow?.catch(() => {
|
|
2534
|
+
});
|
|
2535
|
+
};
|
|
2517
2536
|
const handoffCompletion = (handoff) => {
|
|
2518
2537
|
if (!state.completionHandoffPromise) {
|
|
2519
2538
|
state.completionHandoffPromise = (async () => {
|
|
2520
2539
|
state.completionHandoff = true;
|
|
2540
|
+
await stopRenewal();
|
|
2541
|
+
if (state.lockAcquired && options.turnLock?.holdForHandoff) {
|
|
2542
|
+
let held;
|
|
2543
|
+
for (let tries = 0; tries < 3 && held === void 0; tries++) {
|
|
2544
|
+
if (tries) await new Promise((resolve) => setTimeout(resolve, 250 * tries));
|
|
2545
|
+
held = await Promise.resolve().then(() => options.turnLock.holdForHandoff(state.lockHandle)).then(Boolean, () => void 0);
|
|
2546
|
+
}
|
|
2547
|
+
if (!held) log("[chat-routes] turn lock hand-off hold failed", { turnId: turnStreamId, class: "turn_lock_handoff_hold_failed" });
|
|
2548
|
+
}
|
|
2521
2549
|
let registrationFailed = false;
|
|
2522
2550
|
try {
|
|
2523
2551
|
await state.nativeTiming?.register(handoff);
|
|
@@ -2553,7 +2581,15 @@ function createChatTurnOwnership(state, log, turnStreamId, options) {
|
|
|
2553
2581
|
await attempt("turn cancellation close", () => state.closeCancellation?.());
|
|
2554
2582
|
await attempt("turnLock.release", () => options.turnLock.release(state.lockHandle));
|
|
2555
2583
|
};
|
|
2556
|
-
|
|
2584
|
+
const releaseBeforeDrain = async (end) => {
|
|
2585
|
+
await stopRenewal();
|
|
2586
|
+
if (end !== "handoff" && !state.completionHandoff) {
|
|
2587
|
+
if (state.tap) await attempt("turn buffer close", () => state.tap.done(end));
|
|
2588
|
+
else if (store && runningRow) await attempt("running row settle", () => store.setStatus(turnStreamId, end, scopeId));
|
|
2589
|
+
}
|
|
2590
|
+
await releaseLock();
|
|
2591
|
+
};
|
|
2592
|
+
return { handoffCompletion, releaseLock, markRunning, stopRenewal, releaseBeforeDrain };
|
|
2557
2593
|
}
|
|
2558
2594
|
|
|
2559
2595
|
// src/chat-routes/route-producer.ts
|
|
@@ -2947,7 +2983,7 @@ async function runAdmittedTurn({
|
|
|
2947
2983
|
turnId: turnStreamId,
|
|
2948
2984
|
error: error instanceof Error ? error.message : String(error)
|
|
2949
2985
|
}));
|
|
2950
|
-
const { handoffCompletion, releaseLock } = createChatTurnOwnership(state, log, turnStreamId, options);
|
|
2986
|
+
const { handoffCompletion, releaseLock, markRunning, stopRenewal, releaseBeforeDrain } = createChatTurnOwnership(state, log, turnStreamId, options, payload.threadId);
|
|
2951
2987
|
let produceArgs = {
|
|
2952
2988
|
lock: () => state.lockHandle,
|
|
2953
2989
|
request,
|
|
@@ -2999,8 +3035,9 @@ async function runAdmittedTurn({
|
|
|
2999
3035
|
progress?.("preparing", progressMessages.preparing);
|
|
3000
3036
|
const { endTrace, exportTraceInBackground, fireTerminalLifecycle, assistantRowId, exportTrace, runAfterSettle } = createTurnSettlement(state, trace, options, executionId, traceSink, identity, traceOptions, context, turnStreamId, log, ctx, () => produceArgs.userMessageId);
|
|
3001
3037
|
try {
|
|
3002
|
-
|
|
3003
|
-
|
|
3038
|
+
const [history] = state.lockAcquired ? await trace.measure("admission.history_recheck", "admission", () => Promise.all([readHistory(), markRunning()])) : [];
|
|
3039
|
+
if (state.lockAcquired && JSON.stringify(history) !== historyBeforeLock) {
|
|
3040
|
+
await releaseBeforeDrain("error");
|
|
3004
3041
|
return Response.json({
|
|
3005
3042
|
code: "chat_history_changed",
|
|
3006
3043
|
error: "The conversation changed while this turn was acquiring its lock. Refresh the conversation before starting new work."
|
|
@@ -3025,14 +3062,14 @@ async function runAdmittedTurn({
|
|
|
3025
3062
|
if (contextGate) {
|
|
3026
3063
|
const gate = await trace.measure("admission.gate", "admission", () => contextGate(produceArgs));
|
|
3027
3064
|
if (gate.proceed === "handoff") {
|
|
3028
|
-
await
|
|
3065
|
+
await releaseBeforeDrain("handoff");
|
|
3029
3066
|
state.legacyHandoff = true;
|
|
3030
3067
|
endTrace(false, void 0);
|
|
3031
3068
|
exportTraceInBackground();
|
|
3032
3069
|
return gate.response;
|
|
3033
3070
|
}
|
|
3034
3071
|
if (!gate.proceed) {
|
|
3035
|
-
await
|
|
3072
|
+
await releaseBeforeDrain("complete");
|
|
3036
3073
|
if (state.completionHandoff) {
|
|
3037
3074
|
endTrace(false, void 0);
|
|
3038
3075
|
exportTraceInBackground();
|
|
@@ -3078,6 +3115,7 @@ async function runAdmittedTurn({
|
|
|
3078
3115
|
});
|
|
3079
3116
|
const turnMarker = { type: "turn", turnId: turnStreamId };
|
|
3080
3117
|
await state.tap.onEvent(turnMarker);
|
|
3118
|
+
await stopRenewal();
|
|
3081
3119
|
if (state.completionHandoff) await state.tap.detach();
|
|
3082
3120
|
if (draftTuning) {
|
|
3083
3121
|
state.draft = createAssistantDraftWriter({
|
|
@@ -3128,7 +3166,7 @@ async function runAdmittedTurn({
|
|
|
3128
3166
|
} catch (err) {
|
|
3129
3167
|
if (!state.completionHandoff) {
|
|
3130
3168
|
if (state.turnStarted) await fireTerminalLifecycle(true, err);
|
|
3131
|
-
await
|
|
3169
|
+
await releaseBeforeDrain("error");
|
|
3132
3170
|
}
|
|
3133
3171
|
endTrace(true, err);
|
|
3134
3172
|
exportTraceInBackground();
|
|
@@ -4232,4 +4270,4 @@ export {
|
|
|
4232
4270
|
createChatTurnRoutes,
|
|
4233
4271
|
streamChatRouteAsSandboxEvents
|
|
4234
4272
|
};
|
|
4235
|
-
//# sourceMappingURL=chunk-
|
|
4273
|
+
//# sourceMappingURL=chunk-4OR7NNYB.js.map
|