@truefoundry/assistant-ui-runtime 0.1.0-rc.1 → 0.1.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.
Files changed (30) hide show
  1. package/README.md +14 -77
  2. package/dist/index.d.ts +4 -1
  3. package/dist/index.js +314 -122
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/agentSessionModule.d.ts +14 -2
  7. package/src/convertTurnMessages.test.ts +362 -0
  8. package/src/convertTurnMessages.ts +193 -28
  9. package/src/createSubAgent.ts +13 -5
  10. package/src/draftAgentConfig.test.ts +1 -1
  11. package/src/foldPeerThreads.test.ts +56 -0
  12. package/src/foldPeerThreads.ts +7 -1
  13. package/src/hooks.ts +6 -0
  14. package/src/index.ts +6 -5
  15. package/src/loadSessionSnapshot.test.ts +21 -6
  16. package/src/loadSessionSnapshot.ts +9 -5
  17. package/src/{truefoundryDraftThreadListAdapter.ts → private/truefoundryDraftThreadListAdapter.ts} +1 -1
  18. package/src/sessionSnapshot.ts +27 -1
  19. package/src/sessions.ts +1 -1
  20. package/src/truefoundryExtras.ts +2 -1
  21. package/src/types.ts +1 -1
  22. package/src/useTrueFoundryAgentMessages.test.tsx +225 -1
  23. package/src/useTrueFoundryAgentMessages.ts +178 -60
  24. package/src/useTrueFoundryAgentRuntime.ts +27 -13
  25. /package/src/{agentSpec.ts → private/agentSpec.ts} +0 -0
  26. /package/src/{bindDraftAgentSession.test.ts → private/bindDraftAgentSession.test.ts} +0 -0
  27. /package/src/{bindDraftAgentSession.ts → private/bindDraftAgentSession.ts} +0 -0
  28. /package/src/{draftSessionBridge.ts → private/draftSessionBridge.ts} +0 -0
  29. /package/src/{truefoundryDraftThreadListAdapter.test.ts → private/truefoundryDraftThreadListAdapter.test.ts} +0 -0
  30. /package/src/{useDraftAgentSpec.ts → private/useDraftAgentSpec.ts} +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @truefoundry/assistant-ui-runtime
1
+ # truefoundry-agents-assistant-ui-runtime
2
2
 
3
3
  TrueFoundry Gateway agent runtime adapter for [assistant-ui](https://www.assistant-ui.com/).
4
4
 
@@ -14,7 +14,7 @@ Connect assistant-ui components (`Thread`, `Composer`, tool UIs, `ThreadList`) t
14
14
  ## Installation
15
15
 
16
16
  ```bash
17
- npm install @assistant-ui/react @truefoundry/assistant-ui-runtime truefoundry-gateway-sdk@^0.2.0
17
+ npm install @assistant-ui/react truefoundry-agents-assistant-ui-runtime truefoundry-gateway-sdk@^0.1.0-rc.1
18
18
  ```
19
19
 
20
20
  ## Quickstart
@@ -40,7 +40,7 @@ For production, point `fetch` or `auth` at your own backend proxy so secrets nev
40
40
  "use client";
41
41
 
42
42
  import { AssistantRuntimeProvider } from "@assistant-ui/react";
43
- import { useTrueFoundryAgentRuntime } from "@truefoundry/assistant-ui-runtime";
43
+ import { useTrueFoundryAgentRuntime } from "truefoundry-agents-assistant-ui-runtime";
44
44
  import { Thread } from "@/components/assistant-ui/thread";
45
45
 
46
46
  const AGENT_NAME = process.env.TFY_AGENT_NAME!;
@@ -85,79 +85,30 @@ See the assistant-ui [Thread UI guide](https://www.assistant-ui.com/docs/ui/thre
85
85
  | Option | Type | Required | Description |
86
86
  |--------|------|----------|-------------|
87
87
  | `client` | `AgentSessionClient` | Yes | Pre-built gateway client. The runtime never reads credentials itself. |
88
- | `agent` | `{ mode: "named", agentName }` \| `{ mode: "draft", defaultAgentSpec }` | Yes* | Discriminated agent source. *Or legacy `agentName` for named mode. |
89
- | `agentName` | `string` | Named only | Legacy shorthand for `agent: { mode: "named", agentName }`. |
90
- | `gateway` | `TrueFoundryGateway` | Draft only | Low-level gateway client for `agents.private.draftSessions` CRUD. |
88
+ | `agentName` | `string` | Yes | Saved agent to run (gateway agent name). |
91
89
  | `initialSessionId` | `string` | No | Pin an existing session once on mount (uncontrolled). |
92
90
  | `threadId` | `string` | No | Controlled active session id; reactive and URL-syncable. |
93
91
  | `onThreadIdChange` | `(threadId: string \| undefined) => void` | No | Fires when the active session changes. |
94
92
  | `onError` | `(error: unknown) => void` | No | Invoked on stream/load/turn errors. |
95
93
  | `adapters` | `{ attachments?, speech?, dictation?, voice?, feedback? }` | No | Optional assistant-ui adapters forwarded to the runtime. See [Unsupported assistant-ui features](#unsupported-assistant-ui-features). |
96
94
 
97
- ### Named agent mode (saved agent)
95
+ ### Specifying the agent
98
96
 
99
- ```tsx
100
- const runtime = useTrueFoundryAgentRuntime({
101
- client,
102
- agent: { mode: "named", agentName: "support-bot" },
103
- });
104
- ```
105
-
106
- Legacy `agentName` shorthand is still supported.
107
-
108
- ### Draft agent mode (inline `AgentSpec`)
109
-
110
- Draft mode lists **draft sessions** (`agents.private.draftSessions.*`) in the thread list. Each thread's `remoteId` is a `DraftSession.id`. The runtime syncs `AgentSpec` edits via `agents.private.draftSessions.update`. Turns and history use `/agents/sessions/{draftSessionId}/turns` after validating the draft via `agents.private.draftSessions.get` — no separate conversation session is created.
97
+ Pass the saved agent name as `agentName`:
111
98
 
112
99
  ```tsx
113
- import { TrueFoundryGateway } from "truefoundry-gateway-sdk";
114
- import { useTrueFoundryAgentRuntime } from "@truefoundry/assistant-ui-runtime";
115
-
116
- const client = new AgentSessionClient({ apiKey, baseUrl });
117
- const gateway = new TrueFoundryGateway({ apiKey, baseUrl });
118
-
119
100
  const runtime = useTrueFoundryAgentRuntime({
120
101
  client,
121
- gateway,
122
- agent: {
123
- mode: "draft",
124
- defaultAgentSpec: {
125
- model: { name: "anthropic/claude-sonnet-4-6" },
126
- instructions: "You are a helpful assistant.",
127
- mcpServers: [],
128
- skills: [],
129
- },
130
- },
102
+ agentName: "support-bot",
131
103
  });
132
104
  ```
133
105
 
134
- Read and update the active draft spec from UI:
135
-
136
- ```tsx
137
- import { useTrueFoundryAgentSpec } from "@truefoundry/assistant-ui-runtime";
138
-
139
- function DraftModelPicker() {
140
- const { agentSpec, updateAgentSpec, isSpecSyncing } = useTrueFoundryAgentSpec();
141
- if (agentSpec == null) return null;
142
-
143
- return (
144
- <select
145
- value={agentSpec.model.name}
146
- disabled={isSpecSyncing}
147
- onChange={(e) => updateAgentSpec({ model: { name: e.target.value } })}
148
- />
149
- );
150
- }
151
- ```
152
-
153
- `AgentSpec` maps the runtime fields from the [Agent manifest reference](https://www.truefoundry.com/docs/agent-platform/agent-harness/sdk/agent-manifest-reference) (`model`, `instructions`, `mcpServers`, `skills`, `config`, etc.). Registry metadata (`name`, `description`, `collaborators`) is not part of `AgentSpec`.
154
-
155
106
  ### Adding adapters
156
107
 
157
108
  Pass optional assistant-ui adapters through `adapters`. Attachments are **opt-in**: wire the built-in adapter when you want composer file pick / previews and gateway forwarding on send.
158
109
 
159
110
  ```tsx
160
- import { trueFoundryAttachmentAdapter, useTrueFoundryAgentRuntime } from "@truefoundry/assistant-ui-runtime";
111
+ import { trueFoundryAttachmentAdapter, useTrueFoundryAgentRuntime } from "truefoundry-agents-assistant-ui-runtime";
161
112
 
162
113
  const runtime = useTrueFoundryAgentRuntime({
163
114
  client,
@@ -215,7 +166,7 @@ Render nested threads with `MessagePartPrimitive.Messages` inside your tool fall
215
166
  ```tsx
216
167
  import { MessagePartPrimitive, MessagePrimitive } from "@assistant-ui/react";
217
168
  import { useAuiState } from "@assistant-ui/store";
218
- import type { TrueFoundryMessageCustomMetadata } from "@truefoundry/assistant-ui-runtime";
169
+ import type { TrueFoundryMessageCustomMetadata } from "truefoundry-agents-assistant-ui-runtime";
219
170
 
220
171
  function NestedSubAgentAssistantMessage() {
221
172
  const custom = useAuiState(
@@ -275,8 +226,6 @@ Do not send partial resumes; the backend rejects incomplete input sets.
275
226
 
276
227
  When MCP OAuth is required, the paused assistant message has `metadata.custom.pendingMcpAuth === true` and structured `metadata.custom.mcpServers` (`{ id, name, authUrl }[]`) — both fields are on `TrueFoundryMessageCustomMetadata`. After the user completes OAuth in the browser, call `resumeMcpAuth()` from extras (or `startRun` with `runConfig.custom.resumeMcpAuth: true`).
277
228
 
278
- This package only exposes the raw pending state and a resume action — the per-server authorize links and the "Continue" button live in `packages/agent-ui-sdk`'s `McpAuthContainer`/`McpAuthPrompt` (see that package's README). Resuming is always a manual user action; there is no background polling or auto-resume.
279
-
280
229
  ## Runtime extras
281
230
 
282
231
  Typed escape hatch for adapter-specific state and actions — same pattern as `@assistant-ui/react-google-adk`. Read pending state with selector hooks; call actions via `trueFoundryExtras.get(aui)` when rendering inside nested sub-agent threads (readonly context).
@@ -288,7 +237,7 @@ import {
288
237
  useTrueFoundryApprovals,
289
238
  useTrueFoundryToolResponses,
290
239
  useTrueFoundryMcpAuth,
291
- } from "@truefoundry/assistant-ui-runtime";
240
+ } from "truefoundry-agents-assistant-ui-runtime";
292
241
 
293
242
  function ApprovalBar() {
294
243
  const { pending, respond } = useTrueFoundryApprovals();
@@ -345,7 +294,7 @@ function McpAuthContinue() {
345
294
  ### Action hooks (any render context, including nested sub-agents)
346
295
 
347
296
  ```tsx
348
- import { useTrueFoundryRespondToToolApproval } from "@truefoundry/assistant-ui-runtime";
297
+ import { useTrueFoundryRespondToToolApproval } from "truefoundry-agents-assistant-ui-runtime";
349
298
 
350
299
  function NestedToolApprovalButton({ approvalId }: { approvalId: string }) {
351
300
  const respond = useTrueFoundryRespondToToolApproval();
@@ -365,7 +314,7 @@ import {
365
314
  useTrueFoundryRespondToToolResponse,
366
315
  useTrueFoundryResumeMcpAuth,
367
316
  useTrueFoundryCancel,
368
- } from "@truefoundry/assistant-ui-runtime";
317
+ } from "truefoundry-agents-assistant-ui-runtime";
369
318
 
370
319
  const respondToApproval = useTrueFoundryRespondToToolApproval();
371
320
  const respondToResponse = useTrueFoundryRespondToToolResponse();
@@ -389,8 +338,6 @@ void cancel();
389
338
  | `useTrueFoundryRespondToToolResponse()` | `(r: RespondToToolResponseOptions) => void` | Respond to an ask-user / `tool.response_required` prompt from any render context. |
390
339
  | `useTrueFoundryResumeMcpAuth()` | `() => Promise<void>` | Resume the paused turn after the user completes MCP OAuth in the browser. |
391
340
  | `useTrueFoundryCancel()` | `() => Promise<void>` | Cancel the active turn. Calls `session.cancel()` and drains the stream to its terminal `turn.done`. |
392
- | `useTrueFoundryAgentSpec()` | `{ agentSpec, draftSessionId, isSpecSyncing, specError, updateAgentSpec }` | Draft mode only — current inline spec and debounced sync state. |
393
- | `useTrueFoundryUpdateAgentSpec()` | `(update: AgentSpecUpdate) => void` | Draft mode only — update spec from any render context. |
394
341
 
395
342
  Where:
396
343
 
@@ -404,7 +351,7 @@ Where:
404
351
  ### Low-level namespace
405
352
 
406
353
  ```tsx
407
- import { trueFoundryExtras, type TrueFoundryRuntimeExtras } from "@truefoundry/assistant-ui-runtime";
354
+ import { trueFoundryExtras, type TrueFoundryRuntimeExtras } from "truefoundry-agents-assistant-ui-runtime";
408
355
 
409
356
  // Throws outside useTrueFoundryAgentRuntime:
410
357
  const extras = trueFoundryExtras.use();
@@ -424,7 +371,6 @@ const pending = trueFoundryExtras.use((e) => e.pendingApprovals, []);
424
371
  | `respondToToolResponse` | `(r: { toolCallId, content }) => void` | Stage answer; batch-send when complete |
425
372
  | `resumeMcpAuth` | `() => Promise<void>` | Resume after OAuth |
426
373
  | `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) |
427
- | `draft` | `TrueFoundryDraftRuntimeExtras \| null` | Draft mode only — inline `AgentSpec`, sync state, and `updateAgentSpec` |
428
374
 
429
375
  Per-part `respondToApproval` from assistant-ui still works for root-thread tool UIs; extras complements that for global chrome and nested renderers.
430
376
 
@@ -444,7 +390,7 @@ Contrast with the [AI SDK resumable streams guide](https://www.assistant-ui.com/
444
390
 
445
391
  ## Public API
446
392
 
447
- Everything below is exported from the package root (`@truefoundry/assistant-ui-runtime`).
393
+ Everything below is exported from the package root (`truefoundry-agents-assistant-ui-runtime`).
448
394
 
449
395
  | Export | Kind | Purpose |
450
396
  |--------|------|---------|
@@ -461,10 +407,6 @@ Everything below is exported from the package root (`@truefoundry/assistant-ui-r
461
407
  | `TrueFoundryRuntimeExtras` | type | Shape provided into the runtime extras slot. |
462
408
  | `PendingApproval`, `PendingToolResponse` | types | Derived pending items for UI rendering. |
463
409
  | `createTrueFoundryThreadListAdapter` | fn | Builds the cursor-paginated `RemoteThreadListAdapter` powering `<ThreadList>` (`list({ after })` → `nextCursor`). Used internally; exported for custom wiring. |
464
- | `createTrueFoundryDraftThreadListAdapter` | fn | Draft-session variant of the thread-list adapter (`agents.private.draftSessions.list/create/get`). |
465
- | `createDraftSessionBridge` | fn | Reads and syncs a draft session's `AgentSpec` (`agents.private.draftSessions.get/update`). |
466
- | `mergeAgentSpec` | fn | Immutable merge helper for partial `AgentSpec` updates. |
467
- | `AgentSpec`, `AgentSpecUpdate`, `DraftSession` | types | Gateway inline agent definition types (re-exported). |
468
410
  | `getSession` | fn | `(client, sessionId) => Promise<AgentSession>` convenience wrapper. |
469
411
  | `convertTurnsToThreadMessages` | fn | Loads a session's turns and folds them into assistant-ui `ThreadMessage[]` (`ConvertTurnsResult`). |
470
412
  | `buildTurnAssistantContent` | fn | Folds a single turn's events into assistant content parts. |
@@ -497,11 +439,6 @@ For contributors and agents working inside this package. Source lives in `src/`;
497
439
  | `collectPending.ts` | Derives `pendingApprovals`, `pendingToolResponses`, `pendingMcpAuth` from messages. |
498
440
  | `requiredActionInputs.ts` | Combined gate + `collectRequiredActionInputs` for batched resume. |
499
441
  | `truefoundryThreadListAdapter.ts` | `RemoteThreadListAdapter` — cursor-paginated session list (`list({ after })` → `nextCursor`), create/fetch sessions. |
500
- | `truefoundryDraftThreadListAdapter.ts` | Draft-session `RemoteThreadListAdapter` backed by `agents.private.draftSessions.*`. |
501
- | `draftSessionBridge.ts` | Reads and syncs a draft session's `AgentSpec` via `agents.private.draftSessions.get/update`. |
502
- | `bindDraftAgentSession.ts` | Validates a draft session via `agents.private.draftSessions.get`, then binds turns to it at `/agents/sessions/{draftSessionId}/turns`. |
503
- | `useDraftAgentSpec.ts` | Debounced draft spec state + `agents.private.draftSessions.update` wiring. |
504
- | `agentSpec.ts` | `AgentSpec` helpers and `mergeAgentSpec`. |
505
442
  | `convertTurnMessages.ts` | `projectSessionMessages` pure projector; `buildSnapshotFromSession` history ingest; `convertTurnsToThreadMessages` wrapper; stream-event aggregation. |
506
443
  | `foldPeerThreads.ts` | `PeerThreadFoldState` — folds peer/sub-agent threads under their spawning tool call. |
507
444
  | `messageCustomMetadata.ts` | `TrueFoundryMessageCustomMetadata` — typed `metadata.custom` keys for this adapter. |
package/dist/index.d.ts CHANGED
@@ -226,6 +226,7 @@ type TrueFoundryRuntimeExtras = {
226
226
  downloadSandboxFile: (path: string) => Promise<Blob>;
227
227
  cancel: () => Promise<void>;
228
228
  resetFromTurn: (turnId: string) => Promise<void>;
229
+ reload: () => void;
229
230
  draft: TrueFoundryDraftRuntimeExtras | null;
230
231
  };
231
232
  declare const trueFoundryExtras: _assistant_ui_core_internal.RuntimeExtras<TrueFoundryRuntimeExtras>;
@@ -259,6 +260,8 @@ declare const useTrueFoundrySandboxId: () => string | undefined;
259
260
  declare const useTrueFoundryDownloadSandboxFile: () => (path: string) => Promise<Blob>;
260
261
  /** Returns a function to cancel the current run from any render context. */
261
262
  declare const useTrueFoundryCancel: () => () => Promise<void>;
263
+ /** Returns a function to reload (retry) the current session from any render context. */
264
+ declare const useTrueFoundryReload: () => () => void;
262
265
  /** Returns a function to reset (re-submit) a user turn from any render context. */
263
266
  declare const useTrueFoundryResetFromTurn: () => (turnId: string) => Promise<void>;
264
267
  /** Current draft agent spec and sync state (draft mode only). */
@@ -297,4 +300,4 @@ declare function getSession(client: AgentSessionClient, sessionId: string, optio
297
300
  */
298
301
  declare const trueFoundryAttachmentAdapter: AttachmentAdapter;
299
302
 
300
- 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, useTrueFoundryResetFromTurn, useTrueFoundryRespondToToolApproval, useTrueFoundryRespondToToolResponse, useTrueFoundryResumeMcpAuth, useTrueFoundrySandboxId, useTrueFoundryToolResponses, useTrueFoundryUpdateAgentSpec };
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 };