@truefoundry/assistant-ui-runtime 0.1.6 → 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 (46) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +22 -17
  3. package/dist/chunk-CXBZ6WLZ.js +636 -0
  4. package/dist/chunk-CXBZ6WLZ.js.map +1 -0
  5. package/dist/index.d.ts +20 -24
  6. package/dist/index.js +269 -166
  7. package/dist/index.js.map +1 -1
  8. package/dist/plugins/truefoundry-agent-server-adapter/index.d.ts +82 -39
  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-BfiFf8O1.d.ts → types-B_z-FsDS.d.ts} +208 -10
  12. package/package.json +1 -1
  13. package/src/convertTurnMessages.ts +4 -0
  14. package/src/{private → draft}/agentSpec.ts +14 -17
  15. package/src/{private → draft}/draftSessionBridge.ts +1 -2
  16. package/src/{private → draft}/truefoundryDraftThreadListAdapter.test.ts +1 -1
  17. package/src/{private → draft}/truefoundryDraftThreadListAdapter.ts +6 -2
  18. package/src/{private → draft}/useDraftAgentSpec.ts +16 -5
  19. package/src/draftAgentConfig.test.ts +2 -1
  20. package/src/harness.temp.ts +85 -0
  21. package/src/index.ts +43 -7
  22. package/src/plugins/truefoundry-agent-server-adapter/README.md +83 -44
  23. package/src/plugins/truefoundry-agent-server-adapter/chatServer.ts +365 -0
  24. package/src/plugins/truefoundry-agent-server-adapter/cp.test.ts +444 -0
  25. package/src/plugins/truefoundry-agent-server-adapter/cp.ts +482 -0
  26. package/src/plugins/truefoundry-agent-server-adapter/createTrueFoundryAgentUIServer.ts +94 -0
  27. package/src/plugins/truefoundry-agent-server-adapter/guards.ts +1 -1
  28. package/src/plugins/truefoundry-agent-server-adapter/index.ts +20 -351
  29. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.test.ts +85 -0
  30. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.ts +84 -0
  31. package/src/plugins/truefoundry-agent-server-adapter/types.ts +7 -5
  32. package/src/server/index.ts +29 -0
  33. package/src/server/types.ts +264 -12
  34. package/src/streamTurn.test.ts +27 -27
  35. package/src/streamTurn.ts +2 -2
  36. package/src/truefoundryExtras.ts +4 -1
  37. package/src/truefoundryOwnedSessionsThreadListAdapter.ts +5 -2
  38. package/src/truefoundryThreadListAdapter.test.ts +22 -0
  39. package/src/truefoundryThreadListAdapter.ts +4 -1
  40. package/src/types.ts +1 -2
  41. package/src/useTrueFoundryAgentMessages.test.tsx +262 -2
  42. package/src/useTrueFoundryAgentMessages.ts +284 -176
  43. package/src/useTrueFoundryAgentRuntime.ts +31 -21
  44. package/dist/chunk-Q2SHKMLM.js +0 -270
  45. package/dist/chunk-Q2SHKMLM.js.map +0 -1
  46. /package/src/{private → draft}/useDraftAgentSpec.test.tsx +0 -0
@@ -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
@@ -13,17 +13,17 @@ export {
13
13
  export type { ConvertTurnsResult, UserMessageContent } from "./convertTurnMessages.js";
14
14
  export { ROOT_THREAD_ID } from "./constants.js";
15
15
  export type {
16
- UseTrueFoundryAgentRuntimeOptions,
17
16
  NamedAgentConfig,
18
17
  DraftAgentConfig,
19
18
  TrueFoundryAgentConfig,
19
+ UseTrueFoundryAgentRuntimeOptions,
20
20
  } from "./types.js";
21
- export type { AgentSpec, AgentSpecUpdate, DraftSession } from "./private/agentSpec.js";
22
- export { mergeAgentSpec, draftSessionTitle } from "./private/agentSpec.js";
23
- export { createTrueFoundryDraftThreadListAdapter } from "./private/truefoundryDraftThreadListAdapter.js";
21
+ export type { AgentSpecUpdate, DraftSession } from "./draft/agentSpec.js";
22
+ export { mergeAgentSpec, draftSessionTitle } from "./draft/agentSpec.js";
23
+ export { createTrueFoundryDraftThreadListAdapter } from "./draft/truefoundryDraftThreadListAdapter.js";
24
24
  export { createTrueFoundryOwnedSessionsThreadListAdapter } from "./truefoundryOwnedSessionsThreadListAdapter.js";
25
- export { createDraftSessionBridge } from "./private/draftSessionBridge.js";
26
- export type { DraftSessionBridge } from "./private/draftSessionBridge.js";
25
+ export { createDraftSessionBridge } from "./draft/draftSessionBridge.js";
26
+ export type { DraftSessionBridge } from "./draft/draftSessionBridge.js";
27
27
  export {
28
28
  useTrueFoundryAgentSpec,
29
29
  useTrueFoundryUpdateAgentSpec,
@@ -82,7 +82,7 @@ export type {
82
82
  TurnState,
83
83
  TurnStateDone,
84
84
  TurnInputItem,
85
- AgentSpec as ServerAgentSpec,
85
+ AgentSpec,
86
86
  ListResult,
87
87
  CreateSessionRequest,
88
88
  UpdateSessionRequest,
@@ -91,6 +91,35 @@ export type {
91
91
  UserToolApprovalEvent,
92
92
  UserToolResponseEvent,
93
93
  PreviousTurnIdInput,
94
+ ProviderType,
95
+ ModelEntry,
96
+ ModelProviderConfigBase,
97
+ ModelProviderBase,
98
+ ModelProviderCatalogEntry,
99
+ CreateModelProviderRequest,
100
+ UpdateModelProviderRequest,
101
+ ModelCatalogServer,
102
+ ToolBase,
103
+ ConnectorAuthType,
104
+ ConnectorAuthOAuth,
105
+ ConnectorAuthApiKey,
106
+ ConnectorAuthNone,
107
+ ConnectorAuth,
108
+ ConnectorAuthPublicOAuth,
109
+ ConnectorAuthPublicApiKey,
110
+ ConnectorAuthPublicNone,
111
+ ConnectorAuthPublic,
112
+ ConnectorConfigBase,
113
+ ConnectorBase,
114
+ ConnectorCatalogEntry,
115
+ CreateConnectorRequest,
116
+ UpdateConnectorRequest,
117
+ ConnectorCatalogServer,
118
+ SkillBase,
119
+ CreateSkillRequest,
120
+ SkillCatalogServer,
121
+ CatalogServer,
122
+ AgentUIServerPort,
94
123
  } from "./server/index.js";
95
124
  export type {
96
125
  SandboxCreatedEvent,
@@ -113,8 +142,15 @@ export { isEventDelta, mergeEventDelta } from "./server/index.js";
113
142
 
114
143
  export {
115
144
  createTrueFoundryChatServer,
145
+ createTrueFoundryAgentUIServer,
116
146
  type CreateTrueFoundryChatServerOptions,
117
147
  type TrueFoundryChatServer,
148
+ type CreateTrueFoundryAgentUIServerOptions,
149
+ type TrueFoundryAgentUIServer,
150
+ type TfyModelSelectorEntry,
151
+ type TfySkillSelectorEntry,
152
+ type TfyConnectorSelectorEntry,
153
+ type TfyAgentSelectorEntry,
118
154
  type TfyAgentSpec,
119
155
  type TfySkillMount,
120
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