@tangle-network/agent-app 3.0.31 → 3.0.33
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/chat-routes/default-backend.d.ts +12 -0
- package/dist/chat-routes/index.js +1 -1
- package/dist/chat-routes/redact-values.d.ts +2 -1
- package/dist/chat-routes/turn-route-contracts.d.ts +4 -0
- package/dist/{chunk-HP5KD7ZI.js → chunk-KNVFMTC2.js} +15 -8
- package/dist/chunk-KNVFMTC2.js.map +1 -0
- package/dist/preset-cloudflare/index.js +5 -2
- package/dist/preset-cloudflare/index.js.map +1 -1
- package/dist/preset-cloudflare/native-completion-owner.d.ts +3 -0
- package/dist/public-consultation/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-HP5KD7ZI.js.map +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** The template's backend assembly. Products supply policy; routes own lane selection. */
|
|
2
|
+
import type { SandboxInstance } from '@tangle-network/sandbox';
|
|
1
3
|
import type { Harness } from '../harness/index.js';
|
|
2
4
|
import type { SandboxRuntimeConfig } from '../sandbox/configuration.js';
|
|
3
5
|
import type { ProviderResolutionConfig } from '../sandbox/model.js';
|
|
@@ -38,6 +40,16 @@ export interface ChatTurnDefaultBackend<TContext = unknown, TResource = unknown>
|
|
|
38
40
|
providers?: Readonly<Record<string, ProviderResolutionConfig | ((args: ChatTurnProduceArgs<TContext, TResource>) => ProviderResolutionConfig | Promise<ProviderResolutionConfig>)>>;
|
|
39
41
|
/** Explicitly keep every turn on the sandbox lane. */
|
|
40
42
|
router?: false;
|
|
43
|
+
/** A durable owner for a sandbox turn, so its answer outlives the request (a closed tab, a lost connection): called
|
|
44
|
+
* after the box is resolved and the turn lock is held, before the prompt is dispatched, with the session and execution the dispatch uses.
|
|
45
|
+
* It registers the owner (preset-cloudflare `createNativeCompletionOwner`, as creative-agent does) and then calls
|
|
46
|
+
* `args.handoffCompletion()`. A throw fails the turn before any native work starts. */
|
|
47
|
+
completionOwner?(input: {
|
|
48
|
+
args: ChatTurnProduceArgs<TContext, TResource>;
|
|
49
|
+
box: SandboxInstance;
|
|
50
|
+
sessionId: string;
|
|
51
|
+
executionId: string;
|
|
52
|
+
}): Promise<void>;
|
|
41
53
|
/** Who pays for the Router model call: the turn's key, or a per-turn lease (`createDelegatedTurnKeys`) the
|
|
42
54
|
* producer revokes when the turn settles. Default `TANGLE_API_KEY`. Started before the turn lock, like the call. */
|
|
43
55
|
funding?(args: ChatTurnProduceArgs<TContext, TResource>): RouterTurnKey | Promise<RouterTurnKey>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type ValueRedactor = <T>(value: T) => T;
|
|
2
|
-
/** A redactor for these values, or undefined when none qualifies
|
|
2
|
+
/** A redactor for these values, or undefined when none qualifies: object keys and string values alike. Longest first, so
|
|
3
|
+
* a value that contains another wins. */
|
|
3
4
|
export declare function valueRedactor(values: readonly string[] | undefined): ValueRedactor | undefined;
|
|
4
5
|
/** Every event of a stream, redacted. A value split across two text deltas is caught where the turn is stored, not live. */
|
|
5
6
|
export declare function redactEvents<T>(source: AsyncIterable<T>, redact: ValueRedactor): AsyncGenerator<T>;
|
|
@@ -334,6 +334,10 @@ export interface ChatTurnProduceArgs<TContext, TResource = unknown> {
|
|
|
334
334
|
* `createChatTurnRoutes` invocation supplies it before `produce` runs.
|
|
335
335
|
*/
|
|
336
336
|
handoffCompletion?: (options?: NativeCompletionHandoffOptions) => Promise<void>;
|
|
337
|
+
/** The route's turn-lock handle, read when needed: undefined before the lock is acquired and without a `turnLock`.
|
|
338
|
+
* A durable completion owner releases it when it settles the turn after `handoffCompletion`
|
|
339
|
+
* (preset-cloudflare `NativeCompletionPayload.lock`). */
|
|
340
|
+
lock?: () => unknown;
|
|
337
341
|
/** Serializable observations only; snapshots never predict events after handoff. */
|
|
338
342
|
timingFacts?: () => NativeTurnTimingFacts;
|
|
339
343
|
/** What the route's `prefetch` read for this turn's admitted identity; set only when `prefetch` is configured. */
|
|
@@ -143,7 +143,7 @@ function valueRedactor(values) {
|
|
|
143
143
|
const secrets = [...new Set((values ?? []).filter((v) => typeof v === "string" && v.length >= MIN_SECRET_LENGTH))].sort((a, b) => b.length - a.length);
|
|
144
144
|
if (secrets.length === 0) return void 0;
|
|
145
145
|
const text = (s) => secrets.some((v) => s.includes(v)) ? secrets.reduce((acc, v) => acc.split(v).join(REDACTED), s) : s;
|
|
146
|
-
const walk = (v) => typeof v === "string" ? text(v) : Array.isArray(v) ? v.map(walk) : v !== null && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)])) : v;
|
|
146
|
+
const walk = (v) => typeof v === "string" ? text(v) : Array.isArray(v) ? v.map(walk) : v !== null && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [text(k), walk(x)])) : v;
|
|
147
147
|
return walk;
|
|
148
148
|
}
|
|
149
149
|
async function* redactEvents(source, redact) {
|
|
@@ -2940,6 +2940,7 @@ async function runAdmittedTurn({
|
|
|
2940
2940
|
}));
|
|
2941
2941
|
const { handoffCompletion, releaseLock } = createChatTurnOwnership(state, log, turnStreamId, options);
|
|
2942
2942
|
let produceArgs = {
|
|
2943
|
+
lock: () => state.lockHandle,
|
|
2943
2944
|
request,
|
|
2944
2945
|
waitUntil: ctx?.waitUntil,
|
|
2945
2946
|
earlyResource: early.resource,
|
|
@@ -3691,17 +3692,23 @@ function createDefaultChatBackend(projectId, env, config, bindings, modelPolicy)
|
|
|
3691
3692
|
const own = config.providers?.[model];
|
|
3692
3693
|
const provider = typeof own === "function" ? await own(args) : own;
|
|
3693
3694
|
const box = await acquire(args);
|
|
3695
|
+
const completionOwner = config.completionOwner;
|
|
3696
|
+
const dispatch = (signal) => streamSandboxPrompt(
|
|
3697
|
+
provider ? { ...shell, provider } : shell,
|
|
3698
|
+
box,
|
|
3699
|
+
normalizeChatPromptForSandbox(args.prompt),
|
|
3700
|
+
{ ...promptOptions(args), model, signal }
|
|
3701
|
+
);
|
|
3694
3702
|
return {
|
|
3695
3703
|
model,
|
|
3696
3704
|
modelPolicy,
|
|
3697
3705
|
modelFailover: false,
|
|
3698
3706
|
errorNotice: true,
|
|
3699
|
-
openEvents
|
|
3700
|
-
|
|
3701
|
-
box,
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
)
|
|
3707
|
+
// The route pulls openEvents only after the turn lock, so the durable owner registers holding it.
|
|
3708
|
+
openEvents: ({ signal }) => completionOwner ? (async function* () {
|
|
3709
|
+
await completionOwner({ args, box, sessionId: args.identity.sessionId, executionId: args.executionId });
|
|
3710
|
+
yield* dispatch(signal);
|
|
3711
|
+
})() : dispatch(signal)
|
|
3705
3712
|
};
|
|
3706
3713
|
}
|
|
3707
3714
|
};
|
|
@@ -4220,4 +4227,4 @@ export {
|
|
|
4220
4227
|
createChatTurnRoutes,
|
|
4221
4228
|
streamChatRouteAsSandboxEvents
|
|
4222
4229
|
};
|
|
4223
|
-
//# sourceMappingURL=chunk-
|
|
4230
|
+
//# sourceMappingURL=chunk-KNVFMTC2.js.map
|