@truefoundry/assistant-ui-runtime 0.1.7 → 0.1.8

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 (36) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +19 -15
  3. package/dist/chunk-CXBZ6WLZ.js +636 -0
  4. package/dist/chunk-CXBZ6WLZ.js.map +1 -0
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +14 -5
  7. package/dist/index.js.map +1 -1
  8. package/dist/plugins/truefoundry-agent-server-adapter/index.d.ts +81 -35
  9. package/dist/plugins/truefoundry-agent-server-adapter/index.js +3 -1
  10. package/dist/server/index.d.ts +2 -2
  11. package/dist/{types-DbNsU075.d.ts → types-B_z-FsDS.d.ts} +32 -21
  12. package/package.json +1 -1
  13. package/src/convertTurnMessages.ts +4 -0
  14. package/src/draft/truefoundryDraftThreadListAdapter.ts +4 -1
  15. package/src/harness.temp.ts +85 -0
  16. package/src/index.ts +13 -0
  17. package/src/plugins/truefoundry-agent-server-adapter/README.md +83 -44
  18. package/src/plugins/truefoundry-agent-server-adapter/chatServer.ts +365 -0
  19. package/src/plugins/truefoundry-agent-server-adapter/cp.test.ts +444 -0
  20. package/src/plugins/truefoundry-agent-server-adapter/cp.ts +482 -0
  21. package/src/plugins/truefoundry-agent-server-adapter/createTrueFoundryAgentUIServer.ts +94 -0
  22. package/src/plugins/truefoundry-agent-server-adapter/guards.ts +1 -1
  23. package/src/plugins/truefoundry-agent-server-adapter/index.ts +20 -391
  24. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.test.ts +85 -0
  25. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.ts +84 -0
  26. package/src/plugins/truefoundry-agent-server-adapter/types.ts +1 -1
  27. package/src/server/index.ts +6 -0
  28. package/src/server/types.ts +30 -23
  29. package/src/streamTurn.test.ts +27 -27
  30. package/src/streamTurn.ts +2 -2
  31. package/src/truefoundryOwnedSessionsThreadListAdapter.ts +4 -1
  32. package/src/truefoundryThreadListAdapter.test.ts +22 -0
  33. package/src/truefoundryThreadListAdapter.ts +4 -1
  34. package/src/useTrueFoundryAgentMessages.test.tsx +1 -1
  35. package/dist/chunk-SQDOTGP2.js +0 -292
  36. package/dist/chunk-SQDOTGP2.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { AgentSessionClient } from 'truefoundry-gateway-sdk/agents';
2
2
  import { PrivateAgentSessionClient } from 'truefoundry-gateway-sdk/agents/private';
3
- import { A as AgentSpec, C as CreateSessionRequest, L as ListSessionsParams, S as Session, T as Turn, a as TurnState, b as AgentChatServer, U as UpdateSessionRequest } from '../../types-DbNsU075.js';
3
+ import { A as AgentSpec, w as CreateSessionRequest, y as ListSessionsParams, S as Session, d as Turn, W as TurnState, a as AgentChatServer, a0 as UpdateSessionRequest, a2 as AgentSelectorEntry, a3 as ConnectorSelectorEntry, a4 as ModelSelectorEntry, a5 as SkillSelectorEntry, f as AgentBuilderServer } from '../../types-B_z-FsDS.js';
4
4
  import { TruefoundryGatewayApi } from 'truefoundry-gateway-sdk';
5
5
 
6
6
  /**
@@ -77,11 +77,89 @@ type TfyFinishReason = TruefoundryGatewayApi.FinishReason;
77
77
  type TfyThreadState = TruefoundryGatewayApi.ThreadState;
78
78
  type TfyMcpServerInitInfo = TruefoundryGatewayApi.McpServerInitInfo;
79
79
 
80
+ type CreateTrueFoundryChatServerOptions = {
81
+ apiKey: string;
82
+ baseUrl: string;
83
+ /** Optional override — otherwise constructed from apiKey/baseUrl. */
84
+ client?: AgentSessionClient;
85
+ privateClient?: PrivateAgentSessionClient;
86
+ deleteSession?: (req: {
87
+ sessionId: string;
88
+ }) => Promise<void>;
89
+ };
90
+ /**
91
+ * Only the spec is generic. Session/Turn/list-params are the concrete Tfy*
92
+ * types because the adapter builds them as fixed object literals — a generic
93
+ * there would type fields that nothing ever populates. The spec is safe: the
94
+ * gateway SDK serializes with `unrecognizedObjectKeys: "passthrough"`, so
95
+ * host-added spec fields survive the round trip.
96
+ */
97
+ type TrueFoundryChatServer<TSpec extends TfyAgentSpec = TfyAgentSpec> = AgentChatServer<TSpec, TfySession<TSpec>, TfyCreateSessionRequest<TSpec>, TfyListSessionsParams, UpdateSessionRequest<TSpec>, TfyTurn> & {
98
+ /** Escape hatch for hosts that still need raw gateway clients. */
99
+ getGatewayClients(): {
100
+ client: AgentSessionClient;
101
+ privateClient: PrivateAgentSessionClient;
102
+ };
103
+ };
104
+ /**
105
+ * Wraps TrueFoundry gateway clients into a flat `AgentChatServer`.
106
+ * Named vs draft routing is fully internal — an in-memory session-type cache
107
+ * (populated by createSession/listSessions) determines which gateway client
108
+ * to call, falling back to a one-time probe for ids seen only in a URL.
109
+ */
110
+ declare function createTrueFoundryChatServer<TSpec extends TfyAgentSpec = TfyAgentSpec>(opts: CreateTrueFoundryChatServerOptions): TrueFoundryChatServer<TSpec>;
111
+
112
+ /**
113
+ * Control Plane HTTP for builder catalog lists + gateway URL resolution.
114
+ *
115
+ * Wire shapes are host/CP contracts (not Fern / gateway SDK). Paths match
116
+ * ai.tf cpApi usage — expect drift; keep normalizers defensive.
117
+ */
118
+
119
+ interface TfyModelSelectorEntry extends ModelSelectorEntry {
120
+ /** Write into AgentSpec.model.name (model_fqn). */
121
+ apiModel: string;
122
+ modelId: string;
123
+ providerAccount?: string;
124
+ id?: string;
125
+ }
126
+ interface TfySkillSelectorEntry extends SkillSelectorEntry {
127
+ /** Version FQN — mount as RegisteredSkillMount.fqn. */
128
+ fqn: string;
129
+ }
130
+ interface TfyConnectorSelectorEntry extends ConnectorSelectorEntry {
131
+ /** Mount as RegisteredMcpServer.name. */
132
+ mcpName: string;
133
+ serverId?: string | null;
134
+ authenticated?: boolean;
135
+ }
136
+ type TfyAgentSelectorEntry = AgentSelectorEntry;
137
+
138
+ type CreateTrueFoundryAgentUIServerOptions = {
139
+ apiKey: string;
140
+ /** Control Plane base URL (builder lists + optional /session for gateway resolve). */
141
+ cpURL: string;
142
+ /**
143
+ * Gateway base URL. When omitted, resolved via
144
+ * `GET {cpURL}/api/svc/v1/session` → `{cpURL}{env.LLM_GATEWAY_URL ?? "/api/llm"}/{tenantName}`.
145
+ * Session failure throws (no silent public-gateway fallback).
146
+ */
147
+ gatewayURL?: string;
148
+ };
149
+ type TrueFoundryAgentUIServer<TSpec extends TfyAgentSpec = TfyAgentSpec> = TrueFoundryChatServer<TSpec> & AgentBuilderServer<TSpec, TfyModelSelectorEntry, TfySkillSelectorEntry, TfyConnectorSelectorEntry, TfyAgentSelectorEntry, unknown>;
150
+ /**
151
+ * Full pack: gateway chat + Control Plane builder lists.
152
+ *
153
+ * Same `apiKey` bearer is used for CP and gateway. Concurrent calls with the
154
+ * same credentials share one in-flight promise (React Strict Mode safe).
155
+ */
156
+ declare function createTrueFoundryAgentUIServer<TSpec extends TfyAgentSpec = TfyAgentSpec>(opts: CreateTrueFoundryAgentUIServerOptions): Promise<TrueFoundryAgentUIServer<TSpec>>;
157
+
80
158
  /**
81
159
  * Point-of-use narrowing for the event half of the gateway protocol.
82
160
  *
83
161
  * `AgentChatServer` hardcodes the runtime's event types on listEvents,
84
- * listTurnEvents, subscribeToTurn and prepareAndExecuteTurn — there is no
162
+ * listTurnEvents, subscribeToTurn and createTurn — there is no
85
163
  * generic to override them from here. So instead of typing those channels,
86
164
  * hosts call these guards on the values they receive.
87
165
  *
@@ -124,36 +202,4 @@ declare function getTfyMcpInitServers(event: {
124
202
  mcpServers?: unknown;
125
203
  } | null | undefined): TfyMcpServerInitInfo[] | undefined;
126
204
 
127
- type CreateTrueFoundryChatServerOptions = {
128
- apiKey: string;
129
- baseUrl: string;
130
- /** Optional override — otherwise constructed from apiKey/baseUrl. */
131
- client?: AgentSessionClient;
132
- privateClient?: PrivateAgentSessionClient;
133
- deleteSession?: (req: {
134
- sessionId: string;
135
- }) => Promise<void>;
136
- };
137
- /**
138
- * Only the spec is generic. Session/Turn/list-params are the concrete Tfy*
139
- * types because the adapter builds them as fixed object literals — a generic
140
- * there would type fields that nothing ever populates. The spec is safe: the
141
- * gateway SDK serializes with `unrecognizedObjectKeys: "passthrough"`, so
142
- * host-added spec fields survive the round trip.
143
- */
144
- type TrueFoundryChatServer<TSpec extends TfyAgentSpec = TfyAgentSpec> = AgentChatServer<TSpec, TfySession<TSpec>, TfyCreateSessionRequest<TSpec>, TfyListSessionsParams, UpdateSessionRequest<TSpec>, TfyTurn> & {
145
- /** Escape hatch for hosts that still need raw gateway clients. */
146
- getGatewayClients(): {
147
- client: AgentSessionClient;
148
- privateClient: PrivateAgentSessionClient;
149
- };
150
- };
151
- /**
152
- * Wraps TrueFoundry gateway clients into a flat `AgentChatServer`.
153
- * Named vs draft routing is fully internal — an in-memory session-type cache
154
- * (populated by createSession/listSessions) determines which gateway client
155
- * to call, falling back to a one-time probe for ids seen only in a URL.
156
- */
157
- declare function createTrueFoundryChatServer<TSpec extends TfyAgentSpec = TfyAgentSpec>(opts: CreateTrueFoundryChatServerOptions): TrueFoundryChatServer<TSpec>;
158
-
159
- export { type CreateTrueFoundryChatServerOptions, type RequireApprovalToolSelectorItem, type RequireApprovalToolsSelectorTag, type TfyAgentSpec, type TfyCreateSessionRequest, type TfyFinishReason, type TfyListSessionsParams, type TfyMcpServerInitInfo, type TfyMcpServerMount, type TfyMcpToolInfo, type TfyModelMessageUsage, type TfyModelParams, type TfyResponseFormat, type TfyRuntimeConfig, type TfySession, type TfySkillMount, type TfySubject, type TfySystemToolInfo, type TfyThreadState, type TfyToolInfo, type TfyTurn, type TfyTurnCancelledReason, type TfyTurnState, type TfyTurnStateDoneOutput, type ToolsSelectorItem, type ToolsSelectorTag, type TrueFoundryChatServer, createTrueFoundryChatServer, getTfyMcpInitServers, getTfyThreadState, getTfyUsage, isTfyMcpToolInfo, isTfySystemToolInfo, isTfyToolInfo };
205
+ export { type CreateTrueFoundryAgentUIServerOptions, type CreateTrueFoundryChatServerOptions, type RequireApprovalToolSelectorItem, type RequireApprovalToolsSelectorTag, type TfyAgentSelectorEntry, type TfyAgentSpec, type TfyConnectorSelectorEntry, type TfyCreateSessionRequest, type TfyFinishReason, type TfyListSessionsParams, type TfyMcpServerInitInfo, type TfyMcpServerMount, type TfyMcpToolInfo, type TfyModelMessageUsage, type TfyModelParams, type TfyModelSelectorEntry, type TfyResponseFormat, type TfyRuntimeConfig, type TfySession, type TfySkillMount, type TfySkillSelectorEntry, type TfySubject, type TfySystemToolInfo, type TfyThreadState, type TfyToolInfo, type TfyTurn, type TfyTurnCancelledReason, type TfyTurnState, type TfyTurnStateDoneOutput, type ToolsSelectorItem, type ToolsSelectorTag, type TrueFoundryAgentUIServer, type TrueFoundryChatServer, createTrueFoundryAgentUIServer, createTrueFoundryChatServer, getTfyMcpInitServers, getTfyThreadState, getTfyUsage, isTfyMcpToolInfo, isTfySystemToolInfo, isTfyToolInfo };
@@ -1,4 +1,5 @@
1
1
  import {
2
+ createTrueFoundryAgentUIServer,
2
3
  createTrueFoundryChatServer,
3
4
  getTfyMcpInitServers,
4
5
  getTfyThreadState,
@@ -6,8 +7,9 @@ import {
6
7
  isTfyMcpToolInfo,
7
8
  isTfySystemToolInfo,
8
9
  isTfyToolInfo
9
- } from "../../chunk-SQDOTGP2.js";
10
+ } from "../../chunk-CXBZ6WLZ.js";
10
11
  export {
12
+ createTrueFoundryAgentUIServer,
11
13
  createTrueFoundryChatServer,
12
14
  getTfyMcpInitServers,
13
15
  getTfyThreadState,
@@ -1,5 +1,5 @@
1
- import { R as TurnStreamingEvent, Y as DeltaEvents, c as TurnEvent } from '../types-DbNsU075.js';
2
- export { Z as ActionRequiredEvent, h as AgentBuilderServer, b as AgentChatServer, _ as AgentInfo, $ as AgentParent, a0 as AgentSelectorEntry, A as AgentSpec, i as AgentUIServerPort, a1 as ApprovalDecision, j as CatalogServer, a2 as ChunkDeltaToolCall, k as ConnectorAuth, l as ConnectorAuthPublic, m as ConnectorAuthType, n as ConnectorBase, o as ConnectorCatalogEntry, p as ConnectorCatalogServer, q as ConnectorConfigBase, a3 as ConnectorSelectorEntry, r as CreateConnectorRequest, s as CreateModelProviderRequest, C as CreateSessionRequest, t as CreateSkillRequest, u as ListResult, a4 as ListSessionsOrder, L as ListSessionsParams, M as McpAuthRequiredEvent, a5 as McpInitializeEvent, a6 as McpServerAuthInfo, a7 as McpServerMount, a8 as Model, v as ModelCatalogServer, w as ModelEntry, a9 as ModelMessageContentPart, aa as ModelMessageDeltaEvent, x as ModelMessageEvent, ab as ModelParams, y as ModelProviderBase, z as ModelProviderCatalogEntry, B as ModelProviderConfigBase, ac as ModelSelectorEntry, ad as PageParams, P as PreviousTurnIdInput, D as ProviderType, E as SandboxCreatedEvent, ae as SearchAgentSelectorParams, S as Session, F as SessionEventItem, G as SkillBase, H as SkillCatalogServer, af as SkillMount, ag as SkillSelectorEntry, d as ThreadCreatedEvent, ah as ThreadDoneEvent, I as ToolApprovalRequiredEvent, J as ToolBase, K as ToolCall, ai as ToolCallFunction, aj as ToolCallRef, ak as ToolInfo, al as ToolResponseEvent, N as ToolResponseRequiredEvent, T as Turn, am as TurnCreatedEvent, an as TurnDoneEvent, g as TurnInputItem, a as TurnState, ao as TurnStateCancelled, O as TurnStateDone, ap as TurnStateError, aq as TurnStateRunning, Q as TurnStreamData, V as UpdateConnectorRequest, W as UpdateModelProviderRequest, U as UpdateSessionRequest, X as UserMessage, ar as UserMessageContent, f as UserToolApprovalEvent, e as UserToolResponseEvent } from '../types-DbNsU075.js';
1
+ import { Z as TurnStreamingEvent, a6 as DeltaEvents, T as TurnEvent } from '../types-B_z-FsDS.js';
2
+ export { a7 as ActionRequiredEvent, f as AgentBuilderServer, a as AgentChatServer, a8 as AgentInfo, a9 as AgentParent, a2 as AgentSelectorEntry, A as AgentSpec, g as AgentUIServerPort, aa as ApprovalDecision, C as CatalogServer, ab as ChunkDeltaToolCall, h as ConnectorAuth, i as ConnectorAuthApiKey, j as ConnectorAuthNone, k as ConnectorAuthOAuth, l as ConnectorAuthPublic, m as ConnectorAuthPublicApiKey, n as ConnectorAuthPublicNone, o as ConnectorAuthPublicOAuth, p as ConnectorAuthType, q as ConnectorBase, r as ConnectorCatalogEntry, s as ConnectorCatalogServer, t as ConnectorConfigBase, a3 as ConnectorSelectorEntry, u as CreateConnectorRequest, v as CreateModelProviderRequest, w as CreateSessionRequest, x as CreateSkillRequest, L as ListResult, ac as ListSessionsOrder, y as ListSessionsParams, M as McpAuthRequiredEvent, ad as McpInitializeEvent, ae as McpServerAuthInfo, af as McpServerMount, ag as Model, z as ModelCatalogServer, B as ModelEntry, ah as ModelMessageContentPart, ai as ModelMessageDeltaEvent, D as ModelMessageEvent, aj as ModelParams, E as ModelProviderBase, F as ModelProviderCatalogEntry, G as ModelProviderConfigBase, a4 as ModelSelectorEntry, ak as PageParams, P as PreviousTurnIdInput, H as ProviderType, I as SandboxCreatedEvent, al as SearchAgentSelectorParams, S as Session, J as SessionEventItem, K as SkillBase, N as SkillCatalogServer, am as SkillMount, a5 as SkillSelectorEntry, b as ThreadCreatedEvent, an as ThreadDoneEvent, O as ToolApprovalRequiredEvent, Q as ToolBase, R as ToolCall, ao as ToolCallFunction, ap as ToolCallRef, aq as ToolInfo, ar as ToolResponseEvent, V as ToolResponseRequiredEvent, d as Turn, as as TurnCreatedEvent, at as TurnDoneEvent, e as TurnInputItem, W as TurnState, au as TurnStateCancelled, X as TurnStateDone, av as TurnStateError, aw as TurnStateRunning, Y as TurnStreamData, _ as UpdateConnectorRequest, $ as UpdateModelProviderRequest, a0 as UpdateSessionRequest, a1 as UserMessage, ax as UserMessageContent, c as UserToolApprovalEvent, U as UserToolResponseEvent } from '../types-B_z-FsDS.js';
3
3
 
4
4
  /**
5
5
  * Local implementations of streaming delta helpers.
@@ -398,7 +398,7 @@ interface AgentChatServer<TSpec extends AgentSpec = AgentSpec, TSession extends
398
398
  sessionId: string;
399
399
  }): Promise<TSession>;
400
400
  updateSession(req: TUpdate): Promise<TSession>;
401
- prepareAndExecuteTurn(req: {
401
+ createTurn(req: {
402
402
  sessionId: string;
403
403
  input?: TurnInputItem[];
404
404
  previousTurnId?: PreviousTurnIdInput;
@@ -533,27 +533,33 @@ interface ToolBase {
533
533
  id: string;
534
534
  name: string;
535
535
  }
536
- /**
537
- * Auth type id. Reserved literals: `"None"`, `"OAuth"`, `"API Key"`.
538
- * Stays `string` so hosts can widen (same pattern as `ProviderType`).
539
- */
540
- type ConnectorAuthType = string;
541
- /**
542
- * Write-time connector auth. Host extends / narrows via `TType`.
543
- * For `"API Key"`, pass `apiKey` (and optional `headerName`).
544
- */
545
- interface ConnectorAuth<TType extends ConnectorAuthType = ConnectorAuthType> {
546
- type: TType;
536
+ /** Strict auth type id. Hosts widen branches via intersection + re-union. */
537
+ type ConnectorAuthType = "oauth" | "apiKey" | "none";
538
+ type ConnectorAuthOAuth = {
539
+ type: "oauth";
540
+ authUrl?: string;
541
+ };
542
+ type ConnectorAuthApiKey = {
543
+ type: "apiKey";
547
544
  apiKey?: string;
548
545
  headerName?: string;
549
- }
550
- /**
551
- * Catalog / list auth — no secrets. Host extends / narrows via `TType`.
552
- */
553
- interface ConnectorAuthPublic<TType extends ConnectorAuthType = ConnectorAuthType> {
554
- type: TType;
546
+ };
547
+ type ConnectorAuthNone = {
548
+ type: "none";
549
+ };
550
+ type ConnectorAuth = ConnectorAuthOAuth | ConnectorAuthApiKey | ConnectorAuthNone;
551
+ type ConnectorAuthPublicOAuth = {
552
+ type: "oauth";
553
+ authUrl: string;
554
+ };
555
+ type ConnectorAuthPublicApiKey = {
556
+ type: "apiKey";
555
557
  headerName?: string;
556
- }
558
+ };
559
+ type ConnectorAuthPublicNone = {
560
+ type: "none";
561
+ };
562
+ type ConnectorAuthPublic = ConnectorAuthPublicOAuth | ConnectorAuthPublicApiKey | ConnectorAuthPublicNone;
557
563
  /**
558
564
  * MCP / connector create-edit config. Host extends for extra fields, etc.
559
565
  */
@@ -572,6 +578,8 @@ interface ConnectorBase<TTool extends ToolBase = ToolBase, TAuth extends Connect
572
578
  description: string;
573
579
  url: string;
574
580
  auth: TAuth;
581
+ /** When true, UI should not show Disconnect. */
582
+ requiresAuth: boolean;
575
583
  authenticated: boolean;
576
584
  tools: TTool[];
577
585
  }
@@ -597,7 +605,10 @@ interface ConnectorCatalogServer<TTool extends ToolBase = ToolBase, TAuthWrite e
597
605
  createConnector(req: TCreate): Promise<TConnector>;
598
606
  /** Full replace update keyed by connector `id`. */
599
607
  updateConnector(req: TUpdate): Promise<TConnector>;
600
- /** Start connector auth (e.g. OAuth). Host may widen return with `authUrl`. */
608
+ /**
609
+ * Start connector auth (e.g. OAuth).
610
+ * For oauth, the returned connector's `auth.authUrl` is the authorize URL.
611
+ */
601
612
  authenticateConnector(req: {
602
613
  id: string;
603
614
  }): Promise<TConnector>;
@@ -652,4 +663,4 @@ type AgentUIServerPort<TChat extends AgentChatServer = AgentChatServer, TBuilder
652
663
  catalog?: TCatalog;
653
664
  };
654
665
 
655
- export type { AgentParent as $, AgentSpec as A, ModelProviderConfigBase as B, CreateSessionRequest as C, ProviderType as D, SandboxCreatedEvent as E, SessionEventItem as F, SkillBase as G, SkillCatalogServer as H, ToolApprovalRequiredEvent as I, ToolBase as J, ToolCall as K, ListSessionsParams as L, McpAuthRequiredEvent as M, ToolResponseRequiredEvent as N, TurnStateDone as O, PreviousTurnIdInput as P, TurnStreamData as Q, TurnStreamingEvent as R, Session as S, Turn as T, UpdateSessionRequest as U, UpdateConnectorRequest as V, UpdateModelProviderRequest as W, UserMessage as X, DeltaEvents as Y, ActionRequiredEvent as Z, AgentInfo as _, TurnState as a, AgentSelectorEntry as a0, ApprovalDecision as a1, ChunkDeltaToolCall as a2, ConnectorSelectorEntry as a3, ListSessionsOrder as a4, McpInitializeEvent as a5, McpServerAuthInfo as a6, McpServerMount as a7, Model as a8, ModelMessageContentPart as a9, ModelMessageDeltaEvent as aa, ModelParams as ab, ModelSelectorEntry as ac, PageParams as ad, SearchAgentSelectorParams as ae, SkillMount as af, SkillSelectorEntry as ag, ThreadDoneEvent as ah, ToolCallFunction as ai, ToolCallRef as aj, ToolInfo as ak, ToolResponseEvent as al, TurnCreatedEvent as am, TurnDoneEvent as an, TurnStateCancelled as ao, TurnStateError as ap, TurnStateRunning as aq, UserMessageContent as ar, AgentChatServer as b, TurnEvent as c, ThreadCreatedEvent as d, UserToolResponseEvent as e, UserToolApprovalEvent as f, TurnInputItem as g, AgentBuilderServer as h, AgentUIServerPort as i, CatalogServer as j, ConnectorAuth as k, ConnectorAuthPublic as l, ConnectorAuthType as m, ConnectorBase as n, ConnectorCatalogEntry as o, ConnectorCatalogServer as p, ConnectorConfigBase as q, CreateConnectorRequest as r, CreateModelProviderRequest as s, CreateSkillRequest as t, ListResult as u, ModelCatalogServer as v, ModelEntry as w, ModelMessageEvent as x, ModelProviderBase as y, ModelProviderCatalogEntry as z };
666
+ export type { UpdateModelProviderRequest as $, AgentSpec as A, ModelEntry as B, CatalogServer as C, ModelMessageEvent as D, ModelProviderBase as E, ModelProviderCatalogEntry as F, ModelProviderConfigBase as G, ProviderType as H, SandboxCreatedEvent as I, SessionEventItem as J, SkillBase as K, ListResult as L, McpAuthRequiredEvent as M, SkillCatalogServer as N, ToolApprovalRequiredEvent as O, PreviousTurnIdInput as P, ToolBase as Q, ToolCall as R, Session as S, TurnEvent as T, UserToolResponseEvent as U, ToolResponseRequiredEvent as V, TurnState as W, TurnStateDone as X, TurnStreamData as Y, TurnStreamingEvent as Z, UpdateConnectorRequest as _, AgentChatServer as a, UpdateSessionRequest as a0, UserMessage as a1, AgentSelectorEntry as a2, ConnectorSelectorEntry as a3, ModelSelectorEntry as a4, SkillSelectorEntry as a5, DeltaEvents as a6, ActionRequiredEvent as a7, AgentInfo as a8, AgentParent as a9, ApprovalDecision as aa, ChunkDeltaToolCall as ab, ListSessionsOrder as ac, McpInitializeEvent as ad, McpServerAuthInfo as ae, McpServerMount as af, Model as ag, ModelMessageContentPart as ah, ModelMessageDeltaEvent as ai, ModelParams as aj, PageParams as ak, SearchAgentSelectorParams as al, SkillMount as am, ThreadDoneEvent as an, ToolCallFunction as ao, ToolCallRef as ap, ToolInfo as aq, ToolResponseEvent as ar, TurnCreatedEvent as as, TurnDoneEvent as at, TurnStateCancelled as au, TurnStateError as av, TurnStateRunning as aw, UserMessageContent as ax, ThreadCreatedEvent as b, UserToolApprovalEvent as c, Turn as d, TurnInputItem as e, AgentBuilderServer as f, AgentUIServerPort as g, ConnectorAuth as h, ConnectorAuthApiKey as i, ConnectorAuthNone as j, ConnectorAuthOAuth as k, ConnectorAuthPublic as l, ConnectorAuthPublicApiKey as m, ConnectorAuthPublicNone as n, ConnectorAuthPublicOAuth as o, ConnectorAuthType as p, ConnectorBase as q, ConnectorCatalogEntry as r, ConnectorCatalogServer as s, ConnectorConfigBase as t, CreateConnectorRequest as u, CreateModelProviderRequest as v, CreateSessionRequest as w, CreateSkillRequest as x, ListSessionsParams as y, ModelCatalogServer as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truefoundry/assistant-ui-runtime",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "TrueFoundry Gateway agent runtime adapter for assistant-ui",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -516,6 +516,10 @@ function attachRunningTurn(
516
516
  if (runningTurn == null) {
517
517
  return snapshot;
518
518
  }
519
+ // Session-level history excludes the running turn. Apply continuation inputs
520
+ // from the turn listing so answered approvals / ask-user prompts are not
521
+ // restored as pending while reconnecting to that turn after a refresh.
522
+ applyUserToolResponsesToFold(snapshot.fold, runningTurn.input ?? []);
519
523
  const pendingUserText = extractTurnUserText(runningTurn.input);
520
524
  return replaceSessionSnapshot(snapshot, {
521
525
  runningTurn,
@@ -61,7 +61,10 @@ export function createTrueFoundryDraftThreadListAdapter(options: {
61
61
  async rename() {},
62
62
  async archive() {},
63
63
  async unarchive() {},
64
- async delete() {},
64
+ async delete(remoteId) {
65
+ if (typeof server.deleteSession !== "function") return;
66
+ await server.deleteSession({ sessionId: remoteId });
67
+ },
65
68
 
66
69
  async generateTitle() {
67
70
  return new ReadableStream();
@@ -0,0 +1,85 @@
1
+ /**
2
+ * TEMP — Harness / backend wire shapes for model-provider and MCP catalogs.
3
+ *
4
+ * Not part of the published FE contract. The gateway adapter (and these types)
5
+ * will live outside this repo; keep this file only as a scratch reference for
6
+ * hosts mapping wire → FE `CatalogServer` bases in `server/types.ts`.
7
+ *
8
+ * Do not import from package public exports.
9
+ */
10
+
11
+ import type { ProviderType } from "./server/types.js";
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Models — harness wire
15
+ // ---------------------------------------------------------------------------
16
+
17
+ export interface HarnessModelProperties {
18
+ contextLength: number;
19
+ maxOutputTokens: number;
20
+ reasoningEfforts?: string[];
21
+ }
22
+
23
+ /** Model row as returned/accepted by the harness model-provider APIs. */
24
+ export interface HarnessModelEntry {
25
+ modelId: string;
26
+ name: string;
27
+ properties: HarnessModelProperties;
28
+ }
29
+
30
+ export type HarnessModelProviderAuthWrite = { apiKey: string };
31
+ export type HarnessModelProviderAuthRead = { apiKeySet: true };
32
+
33
+ export interface HarnessModelProviderCatalogEntry {
34
+ /** Builtin catalog type — never `"custom"`. */
35
+ type: ProviderType;
36
+ name: string;
37
+ models: HarnessModelEntry[];
38
+ }
39
+
40
+ export interface HarnessModelProviderBase {
41
+ type: ProviderType;
42
+ name: string;
43
+ /** Present iff `type === "custom"`. */
44
+ baseUrl?: string;
45
+ models: HarnessModelEntry[];
46
+ }
47
+
48
+ export type HarnessUpdateModelProviderRequest = HarnessModelProviderBase & {
49
+ auth: HarnessModelProviderAuthWrite;
50
+ };
51
+
52
+ export type HarnessModelProvider = HarnessModelProviderBase & {
53
+ auth: HarnessModelProviderAuthRead;
54
+ };
55
+
56
+ /** Flat FQN read view for GET /models. */
57
+ export interface HarnessCatalogModel {
58
+ /** `${providerName}/${model.name}` */
59
+ name: string;
60
+ modelId: string;
61
+ properties: HarnessModelProperties;
62
+ }
63
+
64
+ // ---------------------------------------------------------------------------
65
+ // MCP — harness wire
66
+ // ---------------------------------------------------------------------------
67
+
68
+ export type HarnessMcpServerAuth = { type: "dcr" };
69
+
70
+ export interface HarnessMcpServerCatalogEntry {
71
+ provider: string;
72
+ name: string;
73
+ url: string;
74
+ auth?: HarnessMcpServerAuth;
75
+ }
76
+
77
+ export type HarnessMcpServerAuthStatus =
78
+ | { status: "authenticated" }
79
+ | { status: "authRequired"; authorizationUrl: string };
80
+
81
+ export interface HarnessConfiguredMcpServer extends HarnessMcpServerCatalogEntry {
82
+ authStatus: HarnessMcpServerAuthStatus;
83
+ }
84
+
85
+ export type HarnessUpdateMcpServerRequest = HarnessMcpServerCatalogEntry;
package/src/index.ts CHANGED
@@ -101,7 +101,13 @@ export type {
101
101
  ModelCatalogServer,
102
102
  ToolBase,
103
103
  ConnectorAuthType,
104
+ ConnectorAuthOAuth,
105
+ ConnectorAuthApiKey,
106
+ ConnectorAuthNone,
104
107
  ConnectorAuth,
108
+ ConnectorAuthPublicOAuth,
109
+ ConnectorAuthPublicApiKey,
110
+ ConnectorAuthPublicNone,
105
111
  ConnectorAuthPublic,
106
112
  ConnectorConfigBase,
107
113
  ConnectorBase,
@@ -136,8 +142,15 @@ export { isEventDelta, mergeEventDelta } from "./server/index.js";
136
142
 
137
143
  export {
138
144
  createTrueFoundryChatServer,
145
+ createTrueFoundryAgentUIServer,
139
146
  type CreateTrueFoundryChatServerOptions,
140
147
  type TrueFoundryChatServer,
148
+ type CreateTrueFoundryAgentUIServerOptions,
149
+ type TrueFoundryAgentUIServer,
150
+ type TfyModelSelectorEntry,
151
+ type TfySkillSelectorEntry,
152
+ type TfyConnectorSelectorEntry,
153
+ type TfyAgentSelectorEntry,
141
154
  type TfyAgentSpec,
142
155
  type TfySkillMount,
143
156
  type TfyMcpServerMount,
@@ -1,8 +1,11 @@
1
1
  # truefoundry-agent-server-adapter
2
2
 
3
- A gateway plugin that wraps [`truefoundry-gateway-sdk`](https://www.npmjs.com/package/truefoundry-gateway-sdk) into an [`AgentChatServer`](../../README.md#server-port-agentchatserver) for `@truefoundry/assistant-ui-runtime`.
3
+ TrueFoundry **agent UI server** for `@truefoundry/assistant-ui-runtime`: gateway chat + Control Plane builder lists.
4
4
 
5
- Named vs draft session routing is internal you pass `apiKey` / `baseUrl` (or pre-built clients) and get a flat server the runtime can call.
5
+ - **Preferred:** `createTrueFoundryAgentUIServer`chat + builder from `{ apiKey, cpURL, gatewayURL? }`
6
+ - **Chat-only escape hatch:** `createTrueFoundryChatServer` — gateway sessions only (CLI / tests)
7
+
8
+ The same API key bearer is used for Control Plane and gateway.
6
9
 
7
10
  ### Used by the [runtime Quick start](../../README.md#quick-start)
8
11
 
@@ -11,8 +14,11 @@ Named vs draft session routing is internal — you pass `apiKey` / `baseUrl` (or
11
14
  ## Table of contents
12
15
 
13
16
  - [Installation](#installation)
14
- - [Quick start](#quick-start)
15
- - [`createTrueFoundryChatServer` options](#createtruefoundrychatserver-options)
17
+ - [Quick start (full pack)](#quick-start-full-pack)
18
+ - [`createTrueFoundryAgentUIServer` options](#createtruefoundryagentuiserver-options)
19
+ - [Gateway URL resolution](#gateway-url-resolution)
20
+ - [Builder methods](#builder-methods)
21
+ - [Chat-only: `createTrueFoundryChatServer`](#chat-only-createtruefoundrychatserver)
16
22
  - [Named vs draft sessions](#named-vs-draft-sessions)
17
23
  - [Types & guards](#types--guards)
18
24
  - [Extending `TfyAgentSpec`](#extending-tfyagentspec)
@@ -37,44 +43,82 @@ yarn add @truefoundry/assistant-ui-runtime truefoundry-gateway-sdk
37
43
 
38
44
  ---
39
45
 
40
- ## Quick start
46
+ ## Quick start (full pack)
41
47
 
42
48
  ```tsx
43
- import { createTrueFoundryChatServer } from "@truefoundry/assistant-ui-runtime";
49
+ import { createTrueFoundryAgentUIServer } from "@truefoundry/assistant-ui-runtime";
44
50
  // Isolated import (no React):
45
- // import { createTrueFoundryChatServer } from "@truefoundry/assistant-ui-runtime/plugins/truefoundry-agent-server-adapter";
51
+ // import { createTrueFoundryAgentUIServer } from "@truefoundry/assistant-ui-runtime/plugins/truefoundry-agent-server-adapter";
46
52
 
47
- const server = createTrueFoundryChatServer({
53
+ const server = await createTrueFoundryAgentUIServer({
48
54
  apiKey: process.env.TFY_API_KEY!,
49
- baseUrl: process.env.TFY_GATEWAY_URL!,
55
+ cpURL: process.env.TFY_CP_URL!,
56
+ // gatewayURL: process.env.TFY_GATEWAY_URL, // optional
50
57
  });
51
58
 
52
- // Pass `server` to useTrueFoundryAgentRuntime({ server, agentName })
59
+ // Pass `server` to TrueFoundryAssistantUI / useTrueFoundryAgentRuntime
53
60
  ```
54
61
 
55
- That returns a `TrueFoundryChatServer` implementing `AgentChatServer` with concrete `TfySession` / `TfyTurn` types.
62
+ Returns `TrueFoundryAgentUIServer` = `AgentChatServer` & `AgentBuilderServer` (no settings `catalog`). Concurrent calls with the same credentials share one in-flight promise.
56
63
 
57
64
  ---
58
65
 
59
- ## `createTrueFoundryChatServer` options
66
+ ## `createTrueFoundryAgentUIServer` options
60
67
 
61
68
  | Option | Type | Required | Description |
62
69
  | ------ | ---- | -------- | ----------- |
63
- | `apiKey` | `string` | ✅ | TrueFoundry API key |
64
- | `baseUrl` | `string` | ✅ | Gateway base URL |
65
- | `client` | `AgentSessionClient` | — | Override the named-session client (otherwise built from `apiKey` / `baseUrl`) |
66
- | `privateClient` | `PrivateAgentSessionClient` | — | Override the draft/private client |
67
- | `deleteSession` | `(req: { sessionId: string }) => Promise<void>` | — | Optional delete hook — not on the gateway SDK today; pass your own if needed |
70
+ | `apiKey` | `string` | ✅ | Bearer for CP and gateway (same PAT) |
71
+ | `cpURL` | `string` | ✅ | Control Plane base URL (builder lists + optional `/session`) |
72
+ | `gatewayURL` | `string` | — | Gateway base URL; when omitted, resolved via CP session (see below) |
73
+
74
+ ---
75
+
76
+ ## Gateway URL resolution
77
+
78
+ 1. If `gatewayURL` is set → use it (no `/session` call)
79
+ 2. Else `GET {cpURL}/api/svc/v1/session` → `{cpURL}{env.LLM_GATEWAY_URL ?? "/api/llm"}/{tenantName}`
80
+ 3. If session fails or `tenantName` is missing → **throws** (no silent public-gateway fallback)
81
+
82
+ Pass a public gateway explicitly when needed, e.g. `https://gateway.truefoundry.ai/<tenant>`.
83
+
84
+ ---
85
+
86
+ ## Builder methods
87
+
88
+ Implemented against Control Plane HTTP (not the gateway SDK):
89
+
90
+ | Method | CP path |
91
+ | ------ | ------- |
92
+ | `getModels` | `GET /api/svc/v1/llm-gateway/model/enabled` |
93
+ | `getSkills` | `GET /api/ml/v1/agent-skills?include_empty_agent_skills=false` |
94
+ | `getMcp` | `GET /api/svc/v1/mcp-servers` |
95
+ | `searchAgents` | `GET /api/svc/v1/agents?type=truefoundry-agent&…` |
96
+ | `saveAgent` | `PUT /api/svc/v1/agents` (`{ manifest }`, upsert by name) |
97
+
98
+ Selector rows include TFY mount fields (`apiModel`, skill `fqn`, `mcpName`).
99
+
100
+ ---
101
+
102
+ ## Chat-only: `createTrueFoundryChatServer`
103
+
104
+ For CLI / tests that only need sessions:
68
105
 
69
106
  ```tsx
107
+ import { createTrueFoundryChatServer } from "@truefoundry/assistant-ui-runtime";
108
+
70
109
  const server = createTrueFoundryChatServer({
71
- apiKey,
72
- baseUrl,
73
- // client, privateClient, deleteSession — optional overrides
110
+ apiKey: process.env.TFY_API_KEY!,
111
+ baseUrl: process.env.TFY_GATEWAY_URL!,
74
112
  });
75
113
  ```
76
114
 
77
- Escape hatch for hosts that still need raw gateway clients:
115
+ | Option | Type | Required | Description |
116
+ | ------ | ---- | -------- | ----------- |
117
+ | `apiKey` | `string` | ✅ | TrueFoundry API key |
118
+ | `baseUrl` | `string` | ✅ | Gateway base URL |
119
+ | `client` | `AgentSessionClient` | — | Override the named-session client |
120
+ | `privateClient` | `PrivateAgentSessionClient` | — | Override the draft/private client |
121
+ | `deleteSession` | `(req: { sessionId: string }) => Promise<void>` | — | Optional delete hook |
78
122
 
79
123
  ```tsx
80
124
  const { client, privateClient } = server.getGatewayClients();
@@ -93,14 +137,10 @@ Routing is fully internal via an in-memory session-type cache populated by `crea
93
137
 
94
138
  `updateSession` is only allowed when `session.isMutable === true` (draft). Calling it on a named session throws.
95
139
 
96
- > Ensure `createSession` or `listSessions` ran before `getSession` / turn methods for a given id — the adapter must have cached the session type.
97
-
98
140
  ---
99
141
 
100
142
  ## Types & guards
101
143
 
102
- The plugin surfaces concrete gateway types for hosts that need them:
103
-
104
144
  ```tsx
105
145
  import type {
106
146
  TfyAgentSpec,
@@ -108,8 +148,9 @@ import type {
108
148
  TfyMcpServerMount,
109
149
  TfySession,
110
150
  TfyTurn,
111
- TfyTurnState,
112
- TfyToolInfo,
151
+ TfyModelSelectorEntry,
152
+ TfySkillSelectorEntry,
153
+ TfyConnectorSelectorEntry,
113
154
  } from "@truefoundry/assistant-ui-runtime";
114
155
 
115
156
  import {
@@ -122,8 +163,6 @@ import {
122
163
  } from "@truefoundry/assistant-ui-runtime";
123
164
  ```
124
165
 
125
- Use the type guards to narrow event fields typed as `unknown` by the runtime.
126
-
127
166
  ---
128
167
 
129
168
  ## Extending `TfyAgentSpec`
@@ -132,23 +171,20 @@ Only the **spec** is generic. Session / turn / list-params stay as concrete `Tfy
132
171
 
133
172
  ```tsx
134
173
  import {
135
- createTrueFoundryChatServer,
174
+ createTrueFoundryAgentUIServer,
136
175
  type TfyAgentSpec,
137
- type TrueFoundryChatServer,
176
+ type TrueFoundryAgentUIServer,
138
177
  } from "@truefoundry/assistant-ui-runtime";
139
178
 
140
179
  interface MySpec extends TfyAgentSpec {
141
180
  workspaceId: string;
142
- deploymentId: string;
143
181
  }
144
182
 
145
- const server: TrueFoundryChatServer<MySpec> = createTrueFoundryChatServer<MySpec>({
146
- apiKey,
147
- baseUrl,
148
- });
149
-
150
- const session = await server.getSession({ sessionId: "ses_abc" });
151
- console.log(session.agentSpec?.workspaceId); // string | undefined
183
+ const server: TrueFoundryAgentUIServer<MySpec> =
184
+ await createTrueFoundryAgentUIServer<MySpec>({
185
+ apiKey,
186
+ cpURL,
187
+ });
152
188
  ```
153
189
 
154
190
  ---
@@ -157,11 +193,14 @@ console.log(session.agentSpec?.workspaceId); // string | undefined
157
193
 
158
194
  | Export | Kind | Purpose |
159
195
  | ------ | ---- | ------- |
160
- | `createTrueFoundryChatServer` | Function | Build a `TrueFoundryChatServer` from gateway credentials / clients |
161
- | `CreateTrueFoundryChatServerOptions` | Type | Options bag above |
162
- | `TrueFoundryChatServer<TSpec>` | Type | `AgentChatServer` + `getGatewayClients()` |
196
+ | `createTrueFoundryAgentUIServer` | Function | Full pack: chat + builder |
197
+ | `CreateTrueFoundryAgentUIServerOptions` | Type | Options bag |
198
+ | `TrueFoundryAgentUIServer<TSpec>` | Type | Chat + builder result |
199
+ | `createTrueFoundryChatServer` | Function | Chat-only escape hatch |
200
+ | `TrueFoundryChatServer<TSpec>` | Type | Chat-only result |
201
+ | `TfyModelSelectorEntry`, … | Types | Builder selector rows |
163
202
  | `TfyAgentSpec`, `TfySession`, `TfyTurn`, … | Types | Concrete gateway DTOs |
164
- | `isTfyToolInfo`, `getTfyUsage`, … | Guards / helpers | Narrow / extract gateway event fields |
203
+ | `isTfyToolInfo`, `getTfyUsage`, … | Guards | Narrow gateway event fields |
165
204
 
166
205
  Import path:
167
206
 
@@ -169,7 +208,7 @@ Import path:
169
208
  "@truefoundry/assistant-ui-runtime/plugins/truefoundry-agent-server-adapter"
170
209
  ```
171
210
 
172
- (or the main `@truefoundry/assistant-ui-runtime` entry, which re-exports these symbols).
211
+ (or the main `@truefoundry/assistant-ui-runtime` entry).
173
212
 
174
213
  ---
175
214