@truefoundry/assistant-ui-runtime 0.1.1 → 0.1.3-rc.1
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/README.md +31 -0
- package/dist/index.d.ts +31 -9
- package/dist/index.js +711 -1306
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/convertTurnMessages.test.ts +146 -7
- package/src/convertTurnMessages.ts +442 -164
- package/src/draftAgentConfig.test.ts +30 -1
- package/src/hooks.ts +18 -0
- package/src/index.ts +4 -0
- package/src/loadSessionSnapshot.ts +1 -1
- package/src/private/bindDraftAgentSession.test.ts +20 -21
- package/src/private/bindDraftAgentSession.ts +14 -52
- package/src/private/draftSessionBridge.ts +14 -10
- package/src/private/getGatewayFromPrivateClient.ts +13 -0
- package/src/private/truefoundryDraftThreadListAdapter.test.ts +41 -31
- package/src/private/truefoundryDraftThreadListAdapter.ts +8 -8
- package/src/private/useDraftAgentSpec.test.tsx +153 -0
- package/src/private/useDraftAgentSpec.ts +80 -3
- package/src/sessionSnapshot.ts +21 -1
- package/src/sessions.ts +5 -5
- package/src/streamTurn.test.ts +34 -0
- package/src/streamTurn.ts +9 -1
- package/src/truefoundryExtras.ts +3 -0
- package/src/truefoundryOwnedSessionsThreadListAdapter.test.ts +100 -0
- package/src/truefoundryOwnedSessionsThreadListAdapter.ts +77 -0
- package/src/types.ts +10 -7
- package/src/useTrueFoundryAgentMessages.test.tsx +55 -5
- package/src/useTrueFoundryAgentMessages.ts +91 -16
- package/src/useTrueFoundryAgentRuntime.ts +40 -13
- package/src/agentSessionModule.d.ts +0 -37
package/README.md
CHANGED
|
@@ -338,6 +338,7 @@ void cancel();
|
|
|
338
338
|
| `useTrueFoundryRespondToToolResponse()` | `(r: RespondToToolResponseOptions) => void` | Respond to an ask-user / `tool.response_required` prompt from any render context. |
|
|
339
339
|
| `useTrueFoundryResumeMcpAuth()` | `() => Promise<void>` | Resume the paused turn after the user completes MCP OAuth in the browser. |
|
|
340
340
|
| `useTrueFoundryCancel()` | `() => Promise<void>` | Cancel the active turn. Calls `session.cancel()` and drains the stream to its terminal `turn.done`. |
|
|
341
|
+
| `useTrueFoundryHistoryPagination()` | `{ hasOlderHistory, isLoadingOlderHistory, loadOlderHistory }` | Scroll-up older history: call `loadOlderHistory()` when the user nears the top of the thread. |
|
|
341
342
|
|
|
342
343
|
Where:
|
|
343
344
|
|
|
@@ -371,6 +372,13 @@ const pending = trueFoundryExtras.use((e) => e.pendingApprovals, []);
|
|
|
371
372
|
| `respondToToolResponse` | `(r: { toolCallId, content }) => void` | Stage answer; batch-send when complete |
|
|
372
373
|
| `resumeMcpAuth` | `() => Promise<void>` | Resume after OAuth |
|
|
373
374
|
| `cancel` | `() => Promise<void>` | Cancel the active turn: calls `session.cancel()` and lets the stream drain to its terminal `turn.done` (reconciles on next session load) |
|
|
375
|
+
| `resetFromTurn` | `(turnId: string) => Promise<void>` | Re-submit a user turn (branch/reset) |
|
|
376
|
+
| `reload` | `() => void` | Retry the current session load |
|
|
377
|
+
| `downloadSandboxFile` | `(path: string) => Promise<Blob>` | Download a file from the session sandbox |
|
|
378
|
+
| `hasOlderHistory` | `boolean` | True when another older `listEvents` page is available |
|
|
379
|
+
| `isLoadingOlderHistory` | `boolean` | True while `loadOlderHistory` is in flight |
|
|
380
|
+
| `loadOlderHistory` | `() => Promise<void>` | Prepend the next older history window (scroll-up) |
|
|
381
|
+
| `draft` | `TrueFoundryDraftRuntimeExtras \| null` | Draft-mode agent spec sync extras |
|
|
374
382
|
|
|
375
383
|
Per-part `respondToApproval` from assistant-ui still works for root-thread tool UIs; extras complements that for global chrome and nested renderers.
|
|
376
384
|
|
|
@@ -388,6 +396,28 @@ Works out of the box — no server route or Redis store. TrueFoundry persists ev
|
|
|
388
396
|
|
|
389
397
|
Contrast with the [AI SDK resumable streams guide](https://www.assistant-ui.com/docs/guides/resumable-streams), which requires a separate encoded-byte store.
|
|
390
398
|
|
|
399
|
+
## History pagination
|
|
400
|
+
|
|
401
|
+
Thread open no longer drains every turn. Initial load:
|
|
402
|
+
|
|
403
|
+
1. `listTurns({ limit: 1 })` once — detect a running turn (does **not** walk `page_token`).
|
|
404
|
+
2. One (or a few) `listEvents` page(s) for the newest complete user-message group.
|
|
405
|
+
3. Clears `isLoading`, then resumes a running turn via subscribe if needed.
|
|
406
|
+
|
|
407
|
+
Older history is opt-in via extras / `useTrueFoundryHistoryPagination()`:
|
|
408
|
+
|
|
409
|
+
```tsx
|
|
410
|
+
const { hasOlderHistory, isLoadingOlderHistory, loadOlderHistory } =
|
|
411
|
+
useTrueFoundryHistoryPagination();
|
|
412
|
+
|
|
413
|
+
// e.g. IntersectionObserver at the top of the message list
|
|
414
|
+
if (hasOlderHistory && !isLoadingOlderHistory) {
|
|
415
|
+
void loadOlderHistory();
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
`loadOlderHistory` prepends older turns without aborting an active stream.
|
|
420
|
+
|
|
391
421
|
## Public API
|
|
392
422
|
|
|
393
423
|
Everything below is exported from the package root (`truefoundry-agents-assistant-ui-runtime`).
|
|
@@ -403,6 +433,7 @@ Everything below is exported from the package root (`truefoundry-agents-assistan
|
|
|
403
433
|
| `useTrueFoundryRespondToToolResponse` | hook | Same pattern for tool responses. |
|
|
404
434
|
| `useTrueFoundryResumeMcpAuth` | hook | Same pattern for MCP resume. |
|
|
405
435
|
| `useTrueFoundryCancel` | hook | Same pattern for cancel. |
|
|
436
|
+
| `useTrueFoundryHistoryPagination` | hook | `{ hasOlderHistory, isLoadingOlderHistory, loadOlderHistory }` for scroll-up history. |
|
|
406
437
|
| `trueFoundryExtras` | namespace | `createRuntimeExtras` channel — `.use()`, `.get(aui)`, `.provide()`. |
|
|
407
438
|
| `TrueFoundryRuntimeExtras` | type | Shape provided into the runtime extras slot. |
|
|
408
439
|
| `PendingApproval`, `PendingToolResponse` | types | Derived pending items for UI rendering. |
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { ExternalStoreSharedOptions, AttachmentAdapter, SpeechSynthesisAdapter,
|
|
|
3
3
|
import * as truefoundry_gateway_sdk_agents from 'truefoundry-gateway-sdk/agents';
|
|
4
4
|
import { AgentSessionClient, TurnEvent, ThreadCreatedEvent, UserToolResponseEvent, McpAuthRequiredEvent, UserToolApprovalEvent, Turn, TurnInputItem, AgentSession } from 'truefoundry-gateway-sdk/agents';
|
|
5
5
|
export { SandboxCreatedEvent } from 'truefoundry-gateway-sdk/agents';
|
|
6
|
-
import {
|
|
6
|
+
import { PrivateAgentSessionClient } from 'truefoundry-gateway-sdk/agents/private';
|
|
7
|
+
export { AgentDraftSession, PrivateAgentSessionClient } from 'truefoundry-gateway-sdk/agents/private';
|
|
8
|
+
import { TruefoundryGatewayApi } from 'truefoundry-gateway-sdk';
|
|
7
9
|
import * as _assistant_ui_core_internal from '@assistant-ui/core/internal';
|
|
8
10
|
|
|
9
11
|
type AgentSpec = TruefoundryGatewayApi.AgentSpec;
|
|
@@ -53,8 +55,11 @@ type UseTrueFoundryAgentRuntimeOptions = TrueFoundryAgentRuntimeBaseOptions & {
|
|
|
53
55
|
agent?: TrueFoundryAgentConfig | undefined;
|
|
54
56
|
/** Legacy named-agent shorthand. Prefer `agent: { mode: "named", agentName }`. */
|
|
55
57
|
agentName?: string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Required when `agent.mode === "draft"`. Also used for sandbox file downloads
|
|
60
|
+
* (named or draft).
|
|
61
|
+
*/
|
|
62
|
+
privateClient?: PrivateAgentSessionClient | undefined;
|
|
58
63
|
};
|
|
59
64
|
|
|
60
65
|
declare function useTrueFoundryAgentRuntime(options: UseTrueFoundryAgentRuntimeOptions): _assistant_ui_core.AssistantRuntime;
|
|
@@ -178,16 +183,24 @@ declare function buildEditedUserMessageContent(editedText: string, originalInput
|
|
|
178
183
|
declare function repositoryItemsFromMessages(messages: readonly ThreadMessage[]): ExportedMessageRepositoryItem[];
|
|
179
184
|
|
|
180
185
|
declare function createTrueFoundryDraftThreadListAdapter(options: {
|
|
181
|
-
|
|
186
|
+
privateClient: PrivateAgentSessionClient;
|
|
182
187
|
defaultAgentSpec: AgentSpec;
|
|
183
188
|
getAgentSpec?: () => AgentSpec;
|
|
184
189
|
}): RemoteThreadListAdapter;
|
|
185
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Read-only thread-list adapter backed by `PrivateAgentSessionClient.listOwnedSessions`.
|
|
193
|
+
* Returns every session the caller owns (named + draft), newest first.
|
|
194
|
+
*/
|
|
195
|
+
declare function createTrueFoundryOwnedSessionsThreadListAdapter(options: {
|
|
196
|
+
privateClient: PrivateAgentSessionClient;
|
|
197
|
+
}): RemoteThreadListAdapter;
|
|
198
|
+
|
|
186
199
|
type DraftSessionBridge = {
|
|
187
|
-
syncAgentSpec: (draftSessionId: string, agentSpec: AgentSpec) => Promise<
|
|
200
|
+
syncAgentSpec: (draftSessionId: string, agentSpec: AgentSpec) => Promise<string>;
|
|
188
201
|
getDraftAgentSpec: (draftSessionId: string) => Promise<AgentSpec>;
|
|
189
202
|
};
|
|
190
|
-
declare function createDraftSessionBridge(
|
|
203
|
+
declare function createDraftSessionBridge(privateClient: PrivateAgentSessionClient): DraftSessionBridge;
|
|
191
204
|
|
|
192
205
|
type PendingApproval = {
|
|
193
206
|
approvalId: string;
|
|
@@ -227,6 +240,9 @@ type TrueFoundryRuntimeExtras = {
|
|
|
227
240
|
cancel: () => Promise<void>;
|
|
228
241
|
resetFromTurn: (turnId: string) => Promise<void>;
|
|
229
242
|
reload: () => void;
|
|
243
|
+
hasOlderHistory: boolean;
|
|
244
|
+
isLoadingOlderHistory: boolean;
|
|
245
|
+
loadOlderHistory: () => Promise<void>;
|
|
230
246
|
draft: TrueFoundryDraftRuntimeExtras | null;
|
|
231
247
|
};
|
|
232
248
|
declare const trueFoundryExtras: _assistant_ui_core_internal.RuntimeExtras<TrueFoundryRuntimeExtras>;
|
|
@@ -262,6 +278,12 @@ declare const useTrueFoundryDownloadSandboxFile: () => (path: string) => Promise
|
|
|
262
278
|
declare const useTrueFoundryCancel: () => () => Promise<void>;
|
|
263
279
|
/** Returns a function to reload (retry) the current session from any render context. */
|
|
264
280
|
declare const useTrueFoundryReload: () => () => void;
|
|
281
|
+
/** Older history pagination state plus a load-more action for scroll-up. */
|
|
282
|
+
declare const useTrueFoundryHistoryPagination: () => {
|
|
283
|
+
hasOlderHistory: boolean;
|
|
284
|
+
isLoadingOlderHistory: boolean;
|
|
285
|
+
loadOlderHistory: () => Promise<void>;
|
|
286
|
+
};
|
|
265
287
|
/** Returns a function to reset (re-submit) a user turn from any render context. */
|
|
266
288
|
declare const useTrueFoundryResetFromTurn: () => (turnId: string) => Promise<void>;
|
|
267
289
|
/** Current draft agent spec and sync state (draft mode only). */
|
|
@@ -288,8 +310,8 @@ declare function createTrueFoundryThreadListAdapter(options: {
|
|
|
288
310
|
}): RemoteThreadListAdapter;
|
|
289
311
|
|
|
290
312
|
type GetSessionOptions = {
|
|
291
|
-
/** When set, validates the draft and binds turns
|
|
292
|
-
|
|
313
|
+
/** When set, validates the draft and binds turns via PrivateAgentSessionClient. */
|
|
314
|
+
privateClient?: PrivateAgentSessionClient;
|
|
293
315
|
};
|
|
294
316
|
/** `sessionId` is the assistant-ui thread `remoteId` from `RemoteThreadListAdapter.initialize`. */
|
|
295
317
|
declare function getSession(client: AgentSessionClient, sessionId: string, options?: GetSessionOptions): Promise<AgentSession>;
|
|
@@ -300,4 +322,4 @@ declare function getSession(client: AgentSessionClient, sessionId: string, optio
|
|
|
300
322
|
*/
|
|
301
323
|
declare const trueFoundryAttachmentAdapter: AttachmentAdapter;
|
|
302
324
|
|
|
303
|
-
export { type AgentSpec, type AgentSpecUpdate, type ConvertTurnsResult, type DraftAgentConfig, type DraftSession, type DraftSessionBridge, type McpAuthMessageCustomMetadata, type NamedAgentConfig, type PendingApproval, type PendingToolResponse, ROOT_THREAD_ID, type SandboxMessageCustomMetadata, type SubAgentArtifact, type SubAgentCustomMetadata, type SubAgentMessageCustomMetadata, TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY, type ToolApprovalMessageCustomMetadata, type ToolResponseMessageCustomMetadata, type TrueFoundryAgentConfig, type TrueFoundryDraftRuntimeExtras, type TrueFoundryMessageCustomMetadata, type TrueFoundryRuntimeExtras, type UseTrueFoundryAgentRuntimeOptions, type UserMessageContent, buildEditedUserMessageContent, buildTurnAssistantContent, buildUserMessageContent, collectApprovalInputs, collectRequiredActionInputs, collectResponseInputs, convertTurnsToThreadMessages, createDraftSessionBridge, createTrueFoundryDraftThreadListAdapter, createTrueFoundryThreadListAdapter, draftSessionTitle, findPausedAssistantMessage, getSession, getTurnMessageContent, mergeAgentSpec, messageHasPendingApprovals, messageHasPendingRequiredActions, messageHasPendingResponses, parseTurnIdFromMessageId, repositoryItemsFromMessages, toTrueFoundryApprovalInputs, trueFoundryAttachmentAdapter, trueFoundryExtras, useTrueFoundryAgentRuntime, useTrueFoundryAgentSpec, useTrueFoundryApprovals, useTrueFoundryCancel, useTrueFoundryDownloadSandboxFile, useTrueFoundryMcpAuth, useTrueFoundryReload, useTrueFoundryResetFromTurn, useTrueFoundryRespondToToolApproval, useTrueFoundryRespondToToolResponse, useTrueFoundryResumeMcpAuth, useTrueFoundrySandboxId, useTrueFoundryToolResponses, useTrueFoundryUpdateAgentSpec };
|
|
325
|
+
export { type AgentSpec, type AgentSpecUpdate, type ConvertTurnsResult, type DraftAgentConfig, type DraftSession, type DraftSessionBridge, type McpAuthMessageCustomMetadata, type NamedAgentConfig, type PendingApproval, type PendingToolResponse, ROOT_THREAD_ID, type SandboxMessageCustomMetadata, type SubAgentArtifact, type SubAgentCustomMetadata, type SubAgentMessageCustomMetadata, TOOL_RESPONSE_THREAD_ID_CUSTOM_KEY, type ToolApprovalMessageCustomMetadata, type ToolResponseMessageCustomMetadata, type TrueFoundryAgentConfig, type TrueFoundryDraftRuntimeExtras, type TrueFoundryMessageCustomMetadata, type TrueFoundryRuntimeExtras, type UseTrueFoundryAgentRuntimeOptions, type UserMessageContent, buildEditedUserMessageContent, buildTurnAssistantContent, buildUserMessageContent, collectApprovalInputs, collectRequiredActionInputs, collectResponseInputs, convertTurnsToThreadMessages, createDraftSessionBridge, createTrueFoundryDraftThreadListAdapter, createTrueFoundryOwnedSessionsThreadListAdapter, createTrueFoundryThreadListAdapter, draftSessionTitle, findPausedAssistantMessage, getSession, getTurnMessageContent, mergeAgentSpec, messageHasPendingApprovals, messageHasPendingRequiredActions, messageHasPendingResponses, parseTurnIdFromMessageId, repositoryItemsFromMessages, toTrueFoundryApprovalInputs, trueFoundryAttachmentAdapter, trueFoundryExtras, useTrueFoundryAgentRuntime, useTrueFoundryAgentSpec, useTrueFoundryApprovals, useTrueFoundryCancel, useTrueFoundryDownloadSandboxFile, useTrueFoundryHistoryPagination, useTrueFoundryMcpAuth, useTrueFoundryReload, useTrueFoundryResetFromTurn, useTrueFoundryRespondToToolApproval, useTrueFoundryRespondToToolResponse, useTrueFoundryResumeMcpAuth, useTrueFoundrySandboxId, useTrueFoundryToolResponses, useTrueFoundryUpdateAgentSpec };
|