@tangle-network/agent-app 0.60.270 → 0.60.272
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/assistant/index.js +5 -5
- package/dist/chat-react/index.js +3 -3
- package/dist/chat-routes/index.d.ts +1 -0
- package/dist/chat-routes/index.js +6 -5
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/minted-thread.d.ts +63 -0
- package/dist/chat-routes/turn-route-contracts.d.ts +12 -3
- package/dist/chat-routes/turn-routes.d.ts +1 -1
- package/dist/chat-routes/wire.d.ts +7 -0
- package/dist/chat-store/index.js +2 -2
- package/dist/{chunk-UJKWM4UY.js → chunk-DJIN3YUJ.js} +1 -59
- package/dist/chunk-DJIN3YUJ.js.map +1 -0
- package/dist/chunk-F4TUZYMX.js +63 -0
- package/dist/chunk-F4TUZYMX.js.map +1 -0
- package/dist/{chunk-RZLCBWGG.js → chunk-FAXSYC2C.js} +2 -2
- package/dist/{chunk-5TSRFF5W.js → chunk-G7M2C72Q.js} +1 -1
- package/dist/chunk-G7M2C72Q.js.map +1 -0
- package/dist/{chunk-NHVSO47Q.js → chunk-IUVDR3KJ.js} +2 -2
- package/dist/{chunk-CNBVWPQC.js → chunk-LXYQOOXU.js} +2 -2
- package/dist/{chunk-3RRYI24K.js → chunk-S2IEOSN3.js} +22 -4
- package/dist/chunk-S2IEOSN3.js.map +1 -0
- package/dist/{chunk-O2RCDK5D.js → chunk-SKI2F3NL.js} +7 -3
- package/dist/chunk-SKI2F3NL.js.map +1 -0
- package/dist/operator/index.js +2 -2
- package/dist/platform/billable-turn-admission.d.ts +83 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +49 -0
- package/dist/platform/index.js.map +1 -1
- package/dist/public-consultation/index.d.ts +2 -2
- package/dist/public-consultation/index.js +3 -3
- package/dist/sandbox/index.js +4 -2
- package/dist/web-react/chat-stream.d.ts +7 -0
- package/dist/web-react/index.js +7 -5
- package/package.json +1 -1
- package/dist/chunk-3RRYI24K.js.map +0 -1
- package/dist/chunk-5TSRFF5W.js.map +0 -1
- package/dist/chunk-O2RCDK5D.js.map +0 -1
- package/dist/chunk-UJKWM4UY.js.map +0 -1
- /package/dist/{chunk-RZLCBWGG.js.map → chunk-FAXSYC2C.js.map} +0 -0
- /package/dist/{chunk-NHVSO47Q.js.map → chunk-IUVDR3KJ.js.map} +0 -0
- /package/dist/{chunk-CNBVWPQC.js.map → chunk-LXYQOOXU.js.map} +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A new chat's first turn creates its thread from an id the browser minted
|
|
3
|
+
* (`mintThreadId` in `/web-react`), so the client skips the separate thread
|
|
4
|
+
* POST before its first turn. Lifted from Creative (creative-agent#709).
|
|
5
|
+
*
|
|
6
|
+
* The rules are the route's, not the product's:
|
|
7
|
+
* - the body's `newThread.id` equals the route's `threadId` and is 32 lowercase
|
|
8
|
+
* hex (the server's own id format), else the turn is the 404 it always was;
|
|
9
|
+
* - an id that exists anywhere, or that any turn ever used, is refused with
|
|
10
|
+
* 409 and never adopted, so a guessed or remembered id cannot reach another
|
|
11
|
+
* tenant's thread or a deleted thread's turns, and nothing is written (the
|
|
12
|
+
* product's insert does nothing on conflict and checks its turn records);
|
|
13
|
+
* - the title is trimmed and cut to 200 characters; blank is `null`;
|
|
14
|
+
* - `arm` admits members one by one, so a product can roll it out by percent.
|
|
15
|
+
*
|
|
16
|
+
* The product keeps its own thread read inside `authorize` and calls
|
|
17
|
+
* `args.createThread` only where that read missed, so a known thread is never
|
|
18
|
+
* created and its access check stays the product's.
|
|
19
|
+
*/
|
|
20
|
+
/** The body field a minted first turn carries. */
|
|
21
|
+
export interface ChatTurnNewThread {
|
|
22
|
+
id: string;
|
|
23
|
+
title?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The `createThread` route option: who may create a thread from a minted id, and how the row is written. */
|
|
26
|
+
export interface ChatTurnCreateThreadOptions<TThread = unknown> {
|
|
27
|
+
/** Per-member arm. Omit → every member. */
|
|
28
|
+
arm?(owner: ChatTurnThreadOwner): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Insert the thread and return the written row, or `null`/`undefined` (409)
|
|
31
|
+
* when the id exists or was ever used:
|
|
32
|
+
* - the thread id column must be unique on its own, not per tenant, and the
|
|
33
|
+
* insert must do nothing on conflict (drizzle's
|
|
34
|
+
* `.onConflictDoNothing().returning()`);
|
|
35
|
+
* - refuse an id any turn ever used (for example a `turn_status` row whose
|
|
36
|
+
* `scopeId` is the id): turn records keyed by thread id outlive a deleted
|
|
37
|
+
* thread, and a re-created id would hand them to its new owner through
|
|
38
|
+
* replay and running-turn discovery.
|
|
39
|
+
* `title` is `null` when the client sent none; the product names the fallback.
|
|
40
|
+
*/
|
|
41
|
+
insert(thread: {
|
|
42
|
+
id: string;
|
|
43
|
+
title: string | null;
|
|
44
|
+
} & ChatTurnThreadOwner): Promise<TThread | null | undefined>;
|
|
45
|
+
}
|
|
46
|
+
/** Who a created thread belongs to: the tenant (workspace) and member `authorize` resolved. */
|
|
47
|
+
export interface ChatTurnThreadOwner {
|
|
48
|
+
tenantId: string;
|
|
49
|
+
userId: string;
|
|
50
|
+
}
|
|
51
|
+
/** What `args.createThread` answers: the created row, or the response refusing the turn (404 or 409). */
|
|
52
|
+
export type ChatTurnCreateThreadResult<TThread = unknown> = {
|
|
53
|
+
ok: true;
|
|
54
|
+
thread: TThread;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
response: Response;
|
|
58
|
+
};
|
|
59
|
+
/** Bind the route option to one turn's body; `authorize` receives the result as `args.createThread`. */
|
|
60
|
+
export declare function bindTurnThreadCreation<TThread>(options: ChatTurnCreateThreadOptions<TThread>, body: {
|
|
61
|
+
threadId: string;
|
|
62
|
+
newThread?: unknown;
|
|
63
|
+
}): (owner: ChatTurnThreadOwner) => Promise<ChatTurnCreateThreadResult<TThread>>;
|
|
@@ -7,6 +7,7 @@ import type { ModelPolicy } from '../policy-filters/index';
|
|
|
7
7
|
import type { PersistedChatMessageForTurn, TurnEventStore } from '../stream/index';
|
|
8
8
|
import type { TurnSpan, TurnSpanAttrs, TurnTrace, TurnTraceSink, TurnTraceSummary } from '../turn-trace/recorder';
|
|
9
9
|
import type { DraftPersistenceTuning } from './draft-persistence';
|
|
10
|
+
import type { ChatTurnCreateThreadOptions, ChatTurnCreateThreadResult, ChatTurnThreadOwner } from './minted-thread';
|
|
10
11
|
import type { TurnRoutePhase } from './turn-progress';
|
|
11
12
|
import type { ChatTurnPartInput, ChatTurnRequestPayload } from './wire';
|
|
12
13
|
/** Usage receipt persisted onto the assistant message (the flattened
|
|
@@ -145,7 +146,7 @@ export type ChatTurnAuthorization<TContext> = {
|
|
|
145
146
|
response: Response;
|
|
146
147
|
};
|
|
147
148
|
/** Define arguments required to authorize a chat turn based on intent and request details */
|
|
148
|
-
export interface ChatTurnAuthorizeArgs {
|
|
149
|
+
export interface ChatTurnAuthorizeArgs<TThread = unknown> {
|
|
149
150
|
request: Request;
|
|
150
151
|
intent: 'turn' | 'replay' | 'running';
|
|
151
152
|
/** Parsed, validated POST body (turn intent only). */
|
|
@@ -159,6 +160,10 @@ export interface ChatTurnAuthorizeArgs {
|
|
|
159
160
|
trace?: TurnTrace;
|
|
160
161
|
/** The `admission.authorize` span (turn intent only): the parent for those child spans, so they nest under it. */
|
|
161
162
|
span?: TurnSpan;
|
|
163
|
+
/** Turn intent with the route's `createThread` option set: create the turn's thread from the id the client minted.
|
|
164
|
+
* Call it only where the product's own thread read missed; it answers 404 when the body names no valid minted
|
|
165
|
+
* thread or the member is outside the arm, and 409 when the id already exists anywhere (see `./minted-thread`). */
|
|
166
|
+
createThread?(owner: ChatTurnThreadOwner): Promise<ChatTurnCreateThreadResult<TThread>>;
|
|
162
167
|
}
|
|
163
168
|
/** What `prepareTurn` receives: the admitted turn, before the conversation loads. */
|
|
164
169
|
export interface ChatTurnPrepareArgs<TContext> {
|
|
@@ -475,14 +480,18 @@ export interface ChatTurnTraceOptions<TContext> {
|
|
|
475
480
|
}): TurnSpanAttrs;
|
|
476
481
|
}
|
|
477
482
|
/** Define options to configure chat turn routes including authorization, storage, and event buffering */
|
|
478
|
-
export interface CreateChatTurnRoutesOptions<TContext = void> {
|
|
483
|
+
export interface CreateChatTurnRoutesOptions<TContext = void, TThread = unknown> {
|
|
479
484
|
/** Names the product in `deriveExecutionId` so retries land on the same
|
|
480
485
|
* substrate execution. */
|
|
481
486
|
projectId: string;
|
|
482
487
|
/** Authenticate + authorize the caller for a turn or a replay. The only
|
|
483
488
|
* product-supplied access step: session auth, thread/workspace access,
|
|
484
489
|
* seat/balance gates, rate limits all live here. */
|
|
485
|
-
authorize(args: ChatTurnAuthorizeArgs): Promise<ChatTurnAuthorization<TContext>>;
|
|
490
|
+
authorize(args: ChatTurnAuthorizeArgs<TThread>): Promise<ChatTurnAuthorization<TContext>>;
|
|
491
|
+
/** A new chat's first turn creates its thread from an id the client minted (`mintThreadId` in `/web-react`), so the
|
|
492
|
+
* client skips the thread POST: `authorize` receives `args.createThread` and calls it where its thread read missed.
|
|
493
|
+
* Omit → an unknown thread stays the product's 404. */
|
|
494
|
+
createThread?: ChatTurnCreateThreadOptions<TThread>;
|
|
486
495
|
/** Finish the turn's context after `authorize` has admitted the caller and
|
|
487
496
|
* before the conversation loads or the lock is taken: resolve the profile,
|
|
488
497
|
* the model, anything that reads or writes product state. Keep `authorize`
|
|
@@ -53,4 +53,4 @@
|
|
|
53
53
|
import { type ChatTurnRoutes, type CreateChatTurnRoutesOptions } from './turn-route-contracts';
|
|
54
54
|
export * from './turn-route-contracts';
|
|
55
55
|
/** Build chat turn routes to handle and validate incoming chat requests with optional logging */
|
|
56
|
-
export declare function createChatTurnRoutes<TContext = void>(options: CreateChatTurnRoutesOptions<TContext>): ChatTurnRoutes;
|
|
56
|
+
export declare function createChatTurnRoutes<TContext = void, TThread = unknown>(options: CreateChatTurnRoutesOptions<TContext, TThread>): ChatTurnRoutes;
|
|
@@ -158,6 +158,13 @@ export interface ChatTurnRequestPayload {
|
|
|
158
158
|
turnId?: string;
|
|
159
159
|
/** New token for a deliberate retry; reuse it for transport retries of that attempt. */
|
|
160
160
|
retryAttemptId?: string;
|
|
161
|
+
/** A new chat's first turn: the thread to create, `id` equal to `threadId` (`mintThreadId` in `/web-react`).
|
|
162
|
+
* Send it on every turn of a minted thread until one is admitted, so a refused first turn retries as a creating one;
|
|
163
|
+
* once the thread exists the server finds it first and creates nothing. */
|
|
164
|
+
newThread?: {
|
|
165
|
+
id: string;
|
|
166
|
+
title?: string;
|
|
167
|
+
};
|
|
161
168
|
[key: string]: unknown;
|
|
162
169
|
}
|
|
163
170
|
/** `fetch` init for the turn route — the one place the client wire shape is
|
package/dist/chat-store/index.js
CHANGED
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
mentionInputToPart,
|
|
16
16
|
mentionPartsFromMessageParts,
|
|
17
17
|
toChatMessageParts
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-FAXSYC2C.js";
|
|
19
19
|
import "../chunk-ZVEEWGDK.js";
|
|
20
|
-
import "../chunk-
|
|
20
|
+
import "../chunk-G7M2C72Q.js";
|
|
21
21
|
import {
|
|
22
22
|
attachmentPartKey
|
|
23
23
|
} from "../chunk-VUBJZEZB.js";
|
|
@@ -222,63 +222,6 @@ function workersReuseStore() {
|
|
|
222
222
|
return createCacheReuseStore(() => storage.open(CACHE_NAME));
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
// src/sandbox/warm-cache.ts
|
|
226
|
-
var MAX_ENTRIES = 500;
|
|
227
|
-
function coloCache() {
|
|
228
|
-
return typeof caches === "undefined" ? void 0 : caches.default;
|
|
229
|
-
}
|
|
230
|
-
function createWarmCache(namespace, options = {}) {
|
|
231
|
-
const useIsolate = options.isolate ?? true;
|
|
232
|
-
const env = options.env;
|
|
233
|
-
const entries = /* @__PURE__ */ new Map();
|
|
234
|
-
const coloKey = (key) => {
|
|
235
|
-
const scope = (typeof env === "function" ? env() : env) ?? "production";
|
|
236
|
-
return new Request(`https://${namespace}/${encodeURIComponent(scope)}/${encodeURIComponent(key)}`);
|
|
237
|
-
};
|
|
238
|
-
const remember = (key, value, expiresAt) => {
|
|
239
|
-
entries.delete(key);
|
|
240
|
-
if (!useIsolate) return;
|
|
241
|
-
const now = Date.now();
|
|
242
|
-
for (const [k, entry] of entries) if (entry.expiresAt <= now) entries.delete(k);
|
|
243
|
-
if (entries.size >= MAX_ENTRIES) {
|
|
244
|
-
const oldest = entries.keys().next().value;
|
|
245
|
-
if (oldest !== void 0) entries.delete(oldest);
|
|
246
|
-
}
|
|
247
|
-
entries.set(key, { value, expiresAt });
|
|
248
|
-
};
|
|
249
|
-
return {
|
|
250
|
-
async read(key) {
|
|
251
|
-
const local = entries.get(key);
|
|
252
|
-
if (local && local.expiresAt > Date.now()) return { value: local.value, source: "isolate" };
|
|
253
|
-
const hit = await coloCache()?.match(coloKey(key)).catch(() => void 0);
|
|
254
|
-
if (!hit) return null;
|
|
255
|
-
const expiresAt = Number(hit.headers.get("x-expires-at"));
|
|
256
|
-
if (!(expiresAt > Date.now())) return null;
|
|
257
|
-
const value = await hit.json().catch(() => void 0);
|
|
258
|
-
if (typeof value !== "object" || value === null || !("v" in value)) return null;
|
|
259
|
-
const stored = value.v;
|
|
260
|
-
remember(key, stored, expiresAt);
|
|
261
|
-
return { value: stored, source: "colo" };
|
|
262
|
-
},
|
|
263
|
-
async write(key, value, ttlMs) {
|
|
264
|
-
const expiresAt = Date.now() + ttlMs;
|
|
265
|
-
remember(key, value, expiresAt);
|
|
266
|
-
await coloCache()?.put(coloKey(key), new Response(JSON.stringify({ v: value }), { headers: {
|
|
267
|
-
"cache-control": `max-age=${Math.max(1, Math.ceil(ttlMs / 1e3))}`,
|
|
268
|
-
"x-expires-at": String(expiresAt)
|
|
269
|
-
} })).catch(() => {
|
|
270
|
-
});
|
|
271
|
-
},
|
|
272
|
-
async forget(key) {
|
|
273
|
-
entries.delete(key);
|
|
274
|
-
await coloCache()?.delete(coloKey(key)).catch(() => false);
|
|
275
|
-
},
|
|
276
|
-
clearIsolate() {
|
|
277
|
-
entries.clear();
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
|
|
282
225
|
// src/sandbox/model.ts
|
|
283
226
|
function backendModelFields(model) {
|
|
284
227
|
return {
|
|
@@ -3618,7 +3561,6 @@ async function mintSandboxScopedToken(box, options) {
|
|
|
3618
3561
|
export {
|
|
3619
3562
|
traceSandboxPromptEvents,
|
|
3620
3563
|
createCacheReuseStore,
|
|
3621
|
-
createWarmCache,
|
|
3622
3564
|
backendModelFields,
|
|
3623
3565
|
resolveModelSelection,
|
|
3624
3566
|
resolveModel,
|
|
@@ -3720,4 +3662,4 @@ export {
|
|
|
3720
3662
|
deleteSecret,
|
|
3721
3663
|
mintSandboxScopedToken
|
|
3722
3664
|
};
|
|
3723
|
-
//# sourceMappingURL=chunk-
|
|
3665
|
+
//# sourceMappingURL=chunk-DJIN3YUJ.js.map
|