@truefoundry/assistant-ui-runtime 0.1.1 → 0.1.2
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 +11 -2
- package/dist/index.js +470 -112
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/convertTurnMessages.test.ts +146 -7
- package/src/convertTurnMessages.ts +442 -164
- package/src/hooks.ts +18 -0
- package/src/index.ts +1 -0
- package/src/private/bindDraftAgentSession.test.ts +3 -2
- package/src/private/draftSessionBridge.ts +8 -2
- package/src/private/useDraftAgentSpec.test.tsx +153 -0
- package/src/private/useDraftAgentSpec.ts +80 -3
- package/src/sessionSnapshot.ts +21 -1
- package/src/streamTurn.test.ts +34 -0
- package/src/streamTurn.ts +9 -1
- package/src/truefoundryExtras.ts +3 -0
- package/src/useTrueFoundryAgentMessages.test.tsx +50 -0
- package/src/useTrueFoundryAgentMessages.ts +85 -10
- package/src/useTrueFoundryAgentRuntime.ts +25 -1
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
|
@@ -184,7 +184,7 @@ declare function createTrueFoundryDraftThreadListAdapter(options: {
|
|
|
184
184
|
}): RemoteThreadListAdapter;
|
|
185
185
|
|
|
186
186
|
type DraftSessionBridge = {
|
|
187
|
-
syncAgentSpec: (draftSessionId: string, agentSpec: AgentSpec) => Promise<
|
|
187
|
+
syncAgentSpec: (draftSessionId: string, agentSpec: AgentSpec) => Promise<string>;
|
|
188
188
|
getDraftAgentSpec: (draftSessionId: string) => Promise<AgentSpec>;
|
|
189
189
|
};
|
|
190
190
|
declare function createDraftSessionBridge(gateway: TrueFoundryGateway): DraftSessionBridge;
|
|
@@ -227,6 +227,9 @@ type TrueFoundryRuntimeExtras = {
|
|
|
227
227
|
cancel: () => Promise<void>;
|
|
228
228
|
resetFromTurn: (turnId: string) => Promise<void>;
|
|
229
229
|
reload: () => void;
|
|
230
|
+
hasOlderHistory: boolean;
|
|
231
|
+
isLoadingOlderHistory: boolean;
|
|
232
|
+
loadOlderHistory: () => Promise<void>;
|
|
230
233
|
draft: TrueFoundryDraftRuntimeExtras | null;
|
|
231
234
|
};
|
|
232
235
|
declare const trueFoundryExtras: _assistant_ui_core_internal.RuntimeExtras<TrueFoundryRuntimeExtras>;
|
|
@@ -262,6 +265,12 @@ declare const useTrueFoundryDownloadSandboxFile: () => (path: string) => Promise
|
|
|
262
265
|
declare const useTrueFoundryCancel: () => () => Promise<void>;
|
|
263
266
|
/** Returns a function to reload (retry) the current session from any render context. */
|
|
264
267
|
declare const useTrueFoundryReload: () => () => void;
|
|
268
|
+
/** Older history pagination state plus a load-more action for scroll-up. */
|
|
269
|
+
declare const useTrueFoundryHistoryPagination: () => {
|
|
270
|
+
hasOlderHistory: boolean;
|
|
271
|
+
isLoadingOlderHistory: boolean;
|
|
272
|
+
loadOlderHistory: () => Promise<void>;
|
|
273
|
+
};
|
|
265
274
|
/** Returns a function to reset (re-submit) a user turn from any render context. */
|
|
266
275
|
declare const useTrueFoundryResetFromTurn: () => (turnId: string) => Promise<void>;
|
|
267
276
|
/** Current draft agent spec and sync state (draft mode only). */
|
|
@@ -300,4 +309,4 @@ declare function getSession(client: AgentSessionClient, sessionId: string, optio
|
|
|
300
309
|
*/
|
|
301
310
|
declare const trueFoundryAttachmentAdapter: AttachmentAdapter;
|
|
302
311
|
|
|
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 };
|
|
312
|
+
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, useTrueFoundryHistoryPagination, useTrueFoundryMcpAuth, useTrueFoundryReload, useTrueFoundryResetFromTurn, useTrueFoundryRespondToToolApproval, useTrueFoundryRespondToToolResponse, useTrueFoundryResumeMcpAuth, useTrueFoundrySandboxId, useTrueFoundryToolResponses, useTrueFoundryUpdateAgentSpec };
|