@tangle-network/agent-app 0.60.59 → 0.60.61
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 +2 -2
- package/dist/brand-extraction/index.js +89 -2
- package/dist/brand-extraction/index.js.map +1 -1
- package/dist/chat-react/index.js +1 -1
- package/dist/chat-routes/index.js +2 -2
- package/dist/chat-routes/turn-routes.d.ts +9 -0
- package/dist/{chunk-6LPQRKH7.js → chunk-4WJREKXX.js} +222 -190
- package/dist/chunk-4WJREKXX.js.map +1 -0
- package/dist/{chunk-CZ7KLS7N.js → chunk-FWLCPAST.js} +10 -1
- package/dist/chunk-FWLCPAST.js.map +1 -0
- package/dist/{chunk-EQ6CGOZK.js → chunk-GNA5I5NM.js} +3 -1
- package/dist/chunk-GNA5I5NM.js.map +1 -0
- package/dist/{chunk-WMCROSA4.js → chunk-TZD35SBQ.js} +82 -1
- package/dist/chunk-TZD35SBQ.js.map +1 -0
- package/dist/platform/index.d.ts +1 -0
- package/dist/platform/index.js +155 -5
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/sso-identity-store.d.ts +69 -0
- package/dist/public-consultation/index.d.ts +2 -2
- package/dist/public-consultation/index.js +1 -1
- package/dist/sandbox/index.d.ts +1 -0
- package/dist/sandbox/index.js +5 -1
- package/dist/sandbox/prewarm-route.d.ts +100 -0
- package/dist/turn-stream/adapters.d.ts +17 -0
- package/dist/turn-stream/core.d.ts +2 -0
- package/dist/turn-stream/index.js +16 -0
- package/dist/turn-stream/index.js.map +1 -1
- package/dist/web-react/chat-composer.d.ts +5 -1
- package/dist/web-react/command-palette.d.ts +6 -3
- package/dist/web-react/index.d.ts +1 -0
- package/dist/web-react/index.js +6 -2
- package/dist/web-react/workspace-prewarm.d.ts +36 -0
- package/package.json +1 -1
- package/dist/chunk-6LPQRKH7.js.map +0 -1
- package/dist/chunk-CZ7KLS7N.js.map +0 -1
- package/dist/chunk-EQ6CGOZK.js.map +0 -1
- package/dist/chunk-WMCROSA4.js.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Better Auth `account`-table store for first-party Tangle identity sign-in
|
|
3
|
+
* (`protocol: 'identity'`) on D1 / SQLite.
|
|
4
|
+
*
|
|
5
|
+
* The platform link is Better Auth's own external-identity row:
|
|
6
|
+
* `account(providerId = 'tangle', accountId = <platform user id>, userId)`.
|
|
7
|
+
* Run {@link TANGLE_IDENTITY_ACCOUNT_INDEXES_SQL} in a product migration; its
|
|
8
|
+
* two partial unique indexes make the link one-per-user and
|
|
9
|
+
* one-per-platform-user, which the write path relies on.
|
|
10
|
+
*
|
|
11
|
+
* Schema expectations are Better Auth's default SQLite model with camelCase
|
|
12
|
+
* columns: `user(id, name, email, emailVerified, createdAt, updatedAt)`,
|
|
13
|
+
* `session(id, userId, token, expiresAt, ipAddress, userAgent, createdAt,
|
|
14
|
+
* updatedAt)` and `account(id, userId, accountId, providerId, createdAt,
|
|
15
|
+
* updatedAt)`, with unix-second integer timestamps (Drizzle `mode:
|
|
16
|
+
* 'timestamp'`). D1 is structural: Cloudflare `D1Database` satisfies
|
|
17
|
+
* {@link TangleIdentityD1Like}.
|
|
18
|
+
*/
|
|
19
|
+
import { type TangleIdentitySsoAccountStore } from './sso';
|
|
20
|
+
/** Better Auth `account.providerId` for the Tangle platform link. */
|
|
21
|
+
export declare const TANGLE_IDENTITY_PROVIDER_ID = "tangle";
|
|
22
|
+
/** Partial unique indexes the store requires on Better Auth's `account` table. */
|
|
23
|
+
export declare const TANGLE_IDENTITY_ACCOUNT_INDEXES_SQL: readonly ["CREATE UNIQUE INDEX IF NOT EXISTS account_tangle_platform_user ON account(accountId) WHERE providerId = 'tangle'", "CREATE UNIQUE INDEX IF NOT EXISTS account_tangle_user ON account(userId) WHERE providerId = 'tangle'"];
|
|
24
|
+
/** A prepared D1 statement; Cloudflare `D1PreparedStatement` satisfies it. */
|
|
25
|
+
export interface TangleIdentityD1Statement {
|
|
26
|
+
bind(...values: unknown[]): TangleIdentityD1Statement;
|
|
27
|
+
first<T = Record<string, unknown>>(): Promise<T | null>;
|
|
28
|
+
all<T = Record<string, unknown>>(): Promise<{
|
|
29
|
+
results: T[];
|
|
30
|
+
}>;
|
|
31
|
+
run(): Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
/** The D1 surface the store needs. `batch` must be atomic, as D1's is. */
|
|
34
|
+
export interface TangleIdentityD1Like {
|
|
35
|
+
prepare(query: string): TangleIdentityD1Statement;
|
|
36
|
+
batch(statements: TangleIdentityD1Statement[]): Promise<Array<{
|
|
37
|
+
meta?: {
|
|
38
|
+
changes?: number;
|
|
39
|
+
};
|
|
40
|
+
}>>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A link table the product used before this store. During migration the store
|
|
44
|
+
* reads it after `account` and mirrors new links into it, so a link that
|
|
45
|
+
* exists in either place still signs in and a rollback still finds new links.
|
|
46
|
+
* Remove the option once a reconcile query proves every legacy row has an
|
|
47
|
+
* equal `account` row.
|
|
48
|
+
*/
|
|
49
|
+
export interface TangleIdentityLegacyLinkTable {
|
|
50
|
+
table: string;
|
|
51
|
+
/** Column holding the local `user.id`; must be unique. */
|
|
52
|
+
userIdColumn: string;
|
|
53
|
+
/** Column holding the platform user id; must be unique. */
|
|
54
|
+
platformUserIdColumn: string;
|
|
55
|
+
}
|
|
56
|
+
export interface D1TangleIdentityStoreOptions {
|
|
57
|
+
db: TangleIdentityD1Like;
|
|
58
|
+
/**
|
|
59
|
+
* The signed-in local user for an explicit "connect Tangle" flow. A live
|
|
60
|
+
* local session plus a verified platform exchange jointly authorize linking
|
|
61
|
+
* that user, even when its local email is unverified or differs. The host
|
|
62
|
+
* must prove the session started this flow (for example with a signed,
|
|
63
|
+
* session-bound cookie).
|
|
64
|
+
*/
|
|
65
|
+
linkingUserId?: string;
|
|
66
|
+
legacyLinkTable?: TangleIdentityLegacyLinkTable;
|
|
67
|
+
}
|
|
68
|
+
/** Create the identity-protocol account store for one request. */
|
|
69
|
+
export declare function createD1TangleIdentityStore(options: D1TangleIdentityStoreOptions): TangleIdentitySsoAccountStore;
|
|
@@ -102,8 +102,8 @@ interface GatewayConsultationContext {
|
|
|
102
102
|
/** Compose gateway admission, scoped knowledge and the maintained persisted chat route. */
|
|
103
103
|
export declare function createPublicConsultation(options: PublicConsultationOptions): {
|
|
104
104
|
authorizeConsumer(agent: ConsultationAgent, consumer: ConsultationConsumer): Promise<{
|
|
105
|
-
reason?: undefined;
|
|
106
105
|
allow: true;
|
|
106
|
+
reason?: undefined;
|
|
107
107
|
code?: undefined;
|
|
108
108
|
} | {
|
|
109
109
|
allow: false;
|
|
@@ -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';
|
package/dist/sandbox/index.d.ts
CHANGED
package/dist/sandbox/index.js
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
createD1PrewarmClaimStore,
|
|
34
34
|
createSandboxPrewarmer,
|
|
35
35
|
createSandboxTerminalConnectionRoute,
|
|
36
|
+
createWorkspacePrewarmRoute,
|
|
36
37
|
createWorkspaceSandboxManager,
|
|
37
38
|
deferredCorpusHash,
|
|
38
39
|
deleteSecret,
|
|
@@ -42,6 +43,7 @@ import {
|
|
|
42
43
|
ensureWorkspaceSandbox,
|
|
43
44
|
flattenHistory,
|
|
44
45
|
getClient,
|
|
46
|
+
isAutomatedPrewarmRequest,
|
|
45
47
|
isTerminalPromptEvent,
|
|
46
48
|
mergeExtraMcp,
|
|
47
49
|
mergeHistoryIntoParts,
|
|
@@ -71,7 +73,7 @@ import {
|
|
|
71
73
|
syncSandboxMemberRemove,
|
|
72
74
|
syncSandboxMemberRole,
|
|
73
75
|
writeProfileFilesToBox
|
|
74
|
-
} from "../chunk-
|
|
76
|
+
} from "../chunk-TZD35SBQ.js";
|
|
75
77
|
import {
|
|
76
78
|
EGRESS_PROXY_RECOVERY_PHASE,
|
|
77
79
|
EGRESS_PROXY_RECOVERY_REQUIRED,
|
|
@@ -169,6 +171,7 @@ export {
|
|
|
169
171
|
createD1PrewarmClaimStore,
|
|
170
172
|
createSandboxPrewarmer,
|
|
171
173
|
createSandboxTerminalConnectionRoute,
|
|
174
|
+
createWorkspacePrewarmRoute,
|
|
172
175
|
createWorkspaceSandboxManager,
|
|
173
176
|
createWorkspaceSandboxRecoveryManager,
|
|
174
177
|
deferredCorpusHash,
|
|
@@ -181,6 +184,7 @@ export {
|
|
|
181
184
|
formatSandboxProvisioningSupportDetails,
|
|
182
185
|
formatSandboxProvisioningUserMessage,
|
|
183
186
|
getClient,
|
|
187
|
+
isAutomatedPrewarmRequest,
|
|
184
188
|
isEgressProxyRecoveryRequiredError,
|
|
185
189
|
isSandboxApiBearerAuthFailure,
|
|
186
190
|
isSandboxApiSandboxMissingFailure,
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createWorkspacePrewarmRoute`: the HTTP face of prewarm-on-open, so every
|
|
3
|
+
* agent-app product warms the same way. The browser half is
|
|
4
|
+
* `useWorkspacePrewarm` in `/web-react`: it POSTs here when a member opens a
|
|
5
|
+
* workspace page in a visible tab, and again when they focus the composer.
|
|
6
|
+
*
|
|
7
|
+
* WHAT THE PRODUCT SUPPLIES. Only `authorize`. It authenticates the member
|
|
8
|
+
* from the request exactly as the product's other routes do and returns the
|
|
9
|
+
* warm to run: a box resume, a profile preparation, or `createSandboxPrewarmer`
|
|
10
|
+
* from this subpath. The route owns everything shared: bot and prefetch
|
|
11
|
+
* refusal, per-key single-flight, a short success memory, timing, and the rule
|
|
12
|
+
* that a warm never reaches the member as an error.
|
|
13
|
+
*
|
|
14
|
+
* WHY THE WARM RUNS INSIDE THE REQUEST. A suspended box takes ~31 s to resume
|
|
15
|
+
* (Hospitality production, 2026-10-10), past the 30 s that Cloudflare's
|
|
16
|
+
* `waitUntil` grants after a response. Awaiting the warm keeps the request
|
|
17
|
+
* open for as long as the member's tab is, which is exactly as long as a warm
|
|
18
|
+
* is useful. The browser never awaits it for UI.
|
|
19
|
+
*
|
|
20
|
+
* IDEMPOTENCE. The in-process map only collapses concurrent calls within one
|
|
21
|
+
* isolate. Two isolates can both run the warm, so the product's warm must be
|
|
22
|
+
* safe to repeat: a resume of a running box is a no-op, and a creation needs a
|
|
23
|
+
* claim store (see `createSandboxPrewarmer`).
|
|
24
|
+
*
|
|
25
|
+
* FAILURE. A thrown warm answers 200 `{ outcome: 'failed' }` without the error
|
|
26
|
+
* text, which can name internal hosts. `onEvent` receives the error so the
|
|
27
|
+
* product can log it. The next real turn takes its normal placement path.
|
|
28
|
+
*/
|
|
29
|
+
/** What the product decided for this request. */
|
|
30
|
+
export type WorkspacePrewarmAuthorization =
|
|
31
|
+
/** Not signed in, not a member, or a foreign origin: return this response. */
|
|
32
|
+
{
|
|
33
|
+
status: 'denied';
|
|
34
|
+
response: Response;
|
|
35
|
+
}
|
|
36
|
+
/** A signed-in member the product does not warm for (a role that cannot
|
|
37
|
+
* chat, a box mid-upgrade). Answers 200 so the browser stays quiet. */
|
|
38
|
+
| {
|
|
39
|
+
status: 'declined';
|
|
40
|
+
reason: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Run `warm` once per `key` at a time. `key` names what is warmed, such as
|
|
44
|
+
* the box; members who share a box share a key. `warm` may return a small
|
|
45
|
+
* JSON-safe report for the response and `onEvent`.
|
|
46
|
+
*/
|
|
47
|
+
| {
|
|
48
|
+
status: 'allowed';
|
|
49
|
+
key: string;
|
|
50
|
+
warm: () => Promise<WorkspacePrewarmReport | void>;
|
|
51
|
+
};
|
|
52
|
+
export type WorkspacePrewarmReport = Record<string, string | number | boolean | null>;
|
|
53
|
+
export type WorkspacePrewarmOutcome =
|
|
54
|
+
/** This request ran the warm to completion. */
|
|
55
|
+
'warmed'
|
|
56
|
+
/** Another request in this isolate was already running it; this one waited for it. */
|
|
57
|
+
| 'joined'
|
|
58
|
+
/** The same key warmed successfully within `recentMs`; nothing ran. */
|
|
59
|
+
| 'recent' | 'declined'
|
|
60
|
+
/** A crawler, link preview, or speculative prefetch; nothing ran. */
|
|
61
|
+
| 'automated' | 'failed';
|
|
62
|
+
export interface WorkspacePrewarmResponse {
|
|
63
|
+
outcome: WorkspacePrewarmOutcome;
|
|
64
|
+
/** Time this request spent, including any warm it ran or joined. */
|
|
65
|
+
ms: number;
|
|
66
|
+
reason?: string;
|
|
67
|
+
report?: WorkspacePrewarmReport;
|
|
68
|
+
}
|
|
69
|
+
export type WorkspacePrewarmEvent = {
|
|
70
|
+
type: 'warmed';
|
|
71
|
+
key: string;
|
|
72
|
+
ms: number;
|
|
73
|
+
report?: WorkspacePrewarmReport;
|
|
74
|
+
} | {
|
|
75
|
+
type: 'failed';
|
|
76
|
+
key: string;
|
|
77
|
+
ms: number;
|
|
78
|
+
error: string;
|
|
79
|
+
};
|
|
80
|
+
export interface CreateWorkspacePrewarmRouteOptions<Context = void> {
|
|
81
|
+
/** `context` is whatever the caller passed beside the request, such as a
|
|
82
|
+
* Hono context carrying the Worker's bindings. */
|
|
83
|
+
authorize(input: {
|
|
84
|
+
request: Request;
|
|
85
|
+
context: Context;
|
|
86
|
+
}): Promise<WorkspacePrewarmAuthorization>;
|
|
87
|
+
/** After a successful warm, answer `recent` for this long. Default 30 000 ms. */
|
|
88
|
+
recentMs?: number;
|
|
89
|
+
/** Observability for warms this route ran. Errors thrown here are ignored. */
|
|
90
|
+
onEvent?(event: WorkspacePrewarmEvent): void;
|
|
91
|
+
/** Clock seam for tests. */
|
|
92
|
+
now?(): number;
|
|
93
|
+
}
|
|
94
|
+
/** True for crawler user agents and browser speculative prefetch or prerender. */
|
|
95
|
+
export declare function isAutomatedPrewarmRequest(request: Request): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Build the handler once per isolate, not per request: its single-flight and
|
|
98
|
+
* success memory live in the returned closure.
|
|
99
|
+
*/
|
|
100
|
+
export declare function createWorkspacePrewarmRoute<Context = void>(options: CreateWorkspacePrewarmRouteOptions<Context>): (request: Request, context: Context) => Promise<Response>;
|
|
@@ -42,6 +42,19 @@ export interface AcquireDurableTurnLockInput {
|
|
|
42
42
|
}
|
|
43
43
|
/** Acquire a durable turn lock in the specified namespace with given input parameters */
|
|
44
44
|
export declare function acquireDurableTurnLock(namespace: TurnStreamNamespaceLike, input: AcquireDurableTurnLockInput, auth: TurnStreamAuth): Promise<TurnLockAcquireResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Read a channel's active turn lock without changing it.
|
|
47
|
+
*
|
|
48
|
+
* The first request to a Durable Object that has never been used creates it,
|
|
49
|
+
* which measured 1.3-2.4 s for a thread's first turn in GTM production
|
|
50
|
+
* (2026-10-10) against 0.05-0.33 s once it exists. A peek sent as soon as a
|
|
51
|
+
* turn is admitted lets that creation overlap the turn's other pre-lock work.
|
|
52
|
+
*/
|
|
53
|
+
export declare function peekDurableTurnLock(namespace: TurnStreamNamespaceLike, input: {
|
|
54
|
+
workspaceId: string;
|
|
55
|
+
threadId: string;
|
|
56
|
+
scope: TurnLockScope;
|
|
57
|
+
}, auth: TurnStreamAuth): Promise<DurableTurnLock | null>;
|
|
45
58
|
/** Release a durable turn lock and indicate if the release was successful or deferred */
|
|
46
59
|
export declare function releaseDurableTurnLock(namespace: TurnStreamNamespaceLike, input: TurnLockReleaseInput, auth: TurnStreamAuth): Promise<{
|
|
47
60
|
released: boolean;
|
|
@@ -142,6 +155,10 @@ export interface CreateDurableTurnLockOptions<TContext> {
|
|
|
142
155
|
export declare function createDurableTurnLock<TContext>(options: CreateDurableTurnLockOptions<TContext>): {
|
|
143
156
|
acquire(args: TurnLockSeamArgs<TContext>): Promise<TurnLockSeamResult>;
|
|
144
157
|
release(handle: unknown): Promise<void>;
|
|
158
|
+
warm(target: {
|
|
159
|
+
tenantId: string;
|
|
160
|
+
threadId: string;
|
|
161
|
+
}): Promise<void>;
|
|
145
162
|
};
|
|
146
163
|
/** Coarse per-workspace marker that a thread's turn started / ended — drives
|
|
147
164
|
* a sidebar "agent responding" indicator subscribed once per workspace. */
|
|
@@ -132,6 +132,8 @@ export declare function interruptedReleaseApplies(active: DurableTurnLock, input
|
|
|
132
132
|
export declare const TURN_STREAM_PATHS: {
|
|
133
133
|
readonly broadcast: '/broadcast';
|
|
134
134
|
readonly lockAcquire: '/chat-turn-lock/acquire';
|
|
135
|
+
/** Read the active lock without changing it; also brings the object up before a turn needs it. */
|
|
136
|
+
readonly lockPeek: '/chat-turn-lock/peek';
|
|
135
137
|
readonly lockRelease: '/chat-turn-lock/release';
|
|
136
138
|
readonly lockReleaseInterrupted: '/chat-turn-lock/release-interrupted';
|
|
137
139
|
readonly turnEventsAppend: '/turn-events/append';
|
|
@@ -94,6 +94,8 @@ function interruptedReleaseApplies(active, input) {
|
|
|
94
94
|
var TURN_STREAM_PATHS = {
|
|
95
95
|
broadcast: "/broadcast",
|
|
96
96
|
lockAcquire: "/chat-turn-lock/acquire",
|
|
97
|
+
/** Read the active lock without changing it; also brings the object up before a turn needs it. */
|
|
98
|
+
lockPeek: "/chat-turn-lock/peek",
|
|
97
99
|
lockRelease: "/chat-turn-lock/release",
|
|
98
100
|
lockReleaseInterrupted: "/chat-turn-lock/release-interrupted",
|
|
99
101
|
turnEventsAppend: "/turn-events/append",
|
|
@@ -192,6 +194,8 @@ var TurnStreamDO = class {
|
|
|
192
194
|
return this.handleBroadcast(request);
|
|
193
195
|
case TURN_STREAM_PATHS.lockAcquire:
|
|
194
196
|
return this.handleLockAcquire(request);
|
|
197
|
+
case TURN_STREAM_PATHS.lockPeek:
|
|
198
|
+
return jsonResponse({ active: await this.loadActiveLock() });
|
|
195
199
|
case TURN_STREAM_PATHS.lockRelease:
|
|
196
200
|
return this.handleLockRelease(request);
|
|
197
201
|
case TURN_STREAM_PATHS.lockReleaseInterrupted:
|
|
@@ -588,6 +592,12 @@ async function acquireDurableTurnLock(namespace, input, auth) {
|
|
|
588
592
|
}
|
|
589
593
|
return result.body;
|
|
590
594
|
}
|
|
595
|
+
async function peekDurableTurnLock(namespace, input, auth) {
|
|
596
|
+
const key = turnLockChannelKey(input.workspaceId, input.threadId, input.scope);
|
|
597
|
+
const result = await postJson(namespace, key, TURN_STREAM_PATHS.lockPeek, {}, auth);
|
|
598
|
+
if (result.status !== 200) throw new Error(`turn-stream lock peek failed with status ${result.status}`);
|
|
599
|
+
return result.body.active ?? null;
|
|
600
|
+
}
|
|
591
601
|
async function releaseDurableTurnLock(namespace, input, auth) {
|
|
592
602
|
const key = turnLockChannelKey(input.workspaceId, input.threadId, input.scope);
|
|
593
603
|
return postJsonOk(namespace, key, TURN_STREAM_PATHS.lockRelease, input, auth);
|
|
@@ -639,6 +649,11 @@ function defaultRefusalResponse(active, diagnostics) {
|
|
|
639
649
|
}
|
|
640
650
|
function createDurableTurnLock(options) {
|
|
641
651
|
return {
|
|
652
|
+
// The thread channel is the one a thread's first turn creates; the
|
|
653
|
+
// workspace channel is shared by every thread and its broadcasts keep it up.
|
|
654
|
+
async warm(target) {
|
|
655
|
+
await peekDurableTurnLock(options.namespace, { workspaceId: target.tenantId, threadId: target.threadId, scope: "thread" }, options.auth);
|
|
656
|
+
},
|
|
642
657
|
async acquire(args) {
|
|
643
658
|
const workspaceId = args.identity.tenantId;
|
|
644
659
|
const threadId = args.identity.sessionId;
|
|
@@ -838,6 +853,7 @@ export {
|
|
|
838
853
|
createTurnStreamUpgradeHandler,
|
|
839
854
|
interruptedReleaseApplies,
|
|
840
855
|
mintTurnStreamToken,
|
|
856
|
+
peekDurableTurnLock,
|
|
841
857
|
pruneStaleThreads,
|
|
842
858
|
reconcileStaleDurableTurnLock,
|
|
843
859
|
releaseDurableTurnLock,
|