@truefoundry/assistant-ui-runtime 0.1.7 → 0.1.9
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/CHANGELOG.md +31 -0
- package/README.md +19 -15
- package/dist/chunk-CXBZ6WLZ.js +636 -0
- package/dist/chunk-CXBZ6WLZ.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/plugins/truefoundry-agent-server-adapter/index.d.ts +81 -35
- package/dist/plugins/truefoundry-agent-server-adapter/index.js +3 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/{types-DbNsU075.d.ts → types-6yWuWHzK.d.ts} +109 -28
- package/package.json +1 -1
- package/src/convertTurnMessages.ts +4 -0
- package/src/draft/truefoundryDraftThreadListAdapter.ts +4 -1
- package/src/harness.temp.ts +85 -0
- package/src/index.ts +27 -0
- package/src/plugins/truefoundry-agent-server-adapter/README.md +83 -44
- package/src/plugins/truefoundry-agent-server-adapter/chatServer.ts +365 -0
- package/src/plugins/truefoundry-agent-server-adapter/cp.test.ts +444 -0
- package/src/plugins/truefoundry-agent-server-adapter/cp.ts +482 -0
- package/src/plugins/truefoundry-agent-server-adapter/createTrueFoundryAgentUIServer.ts +94 -0
- package/src/plugins/truefoundry-agent-server-adapter/guards.ts +1 -1
- package/src/plugins/truefoundry-agent-server-adapter/index.ts +20 -391
- package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.test.ts +85 -0
- package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.ts +84 -0
- package/src/plugins/truefoundry-agent-server-adapter/types.ts +1 -1
- package/src/server/index.ts +20 -0
- package/src/server/types.ts +125 -28
- package/src/streamTurn.test.ts +27 -27
- package/src/streamTurn.ts +2 -2
- package/src/truefoundryOwnedSessionsThreadListAdapter.ts +4 -1
- package/src/truefoundryThreadListAdapter.test.ts +22 -0
- package/src/truefoundryThreadListAdapter.ts +4 -1
- package/src/useTrueFoundryAgentMessages.test.tsx +1 -1
- package/dist/chunk-SQDOTGP2.js +0 -292
- package/dist/chunk-SQDOTGP2.js.map +0 -1
|
@@ -1,399 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from "
|
|
17
|
-
import type {
|
|
18
|
-
TfyAgentSpec,
|
|
19
|
-
TfyCreateSessionRequest,
|
|
20
|
-
TfyListSessionsParams,
|
|
21
|
-
TfySession,
|
|
22
|
-
TfyTurn,
|
|
23
|
-
TfyTurnState,
|
|
24
|
-
} from "./types.js";
|
|
1
|
+
export {
|
|
2
|
+
createTrueFoundryChatServer,
|
|
3
|
+
type CreateTrueFoundryChatServerOptions,
|
|
4
|
+
type TrueFoundryChatServer
|
|
5
|
+
} from "./chatServer.js";
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
createTrueFoundryAgentUIServer,
|
|
9
|
+
type CreateTrueFoundryAgentUIServerOptions,
|
|
10
|
+
type TrueFoundryAgentUIServer
|
|
11
|
+
} from "./createTrueFoundryAgentUIServer.js";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
type TfyAgentSelectorEntry, type TfyConnectorSelectorEntry, type TfyModelSelectorEntry,
|
|
15
|
+
type TfySkillSelectorEntry
|
|
16
|
+
} from "./cp.js";
|
|
25
17
|
|
|
26
18
|
export {
|
|
27
|
-
type TfyAgentSpec,
|
|
28
|
-
type TfySkillMount,
|
|
29
|
-
type TfyMcpServerMount,
|
|
30
|
-
type TfyModelParams,
|
|
31
|
-
type TfyRuntimeConfig,
|
|
32
|
-
type TfyResponseFormat,
|
|
33
|
-
type TfySubject,
|
|
34
|
-
type ToolsSelectorItem,
|
|
35
|
-
type ToolsSelectorTag,
|
|
36
19
|
type RequireApprovalToolSelectorItem,
|
|
37
|
-
type RequireApprovalToolsSelectorTag,
|
|
38
|
-
type TfyTurn,
|
|
39
|
-
type
|
|
40
|
-
type TfyTurnCancelledReason,
|
|
41
|
-
type TfyTurnStateDoneOutput,
|
|
42
|
-
type TfySession,
|
|
43
|
-
type TfyCreateSessionRequest,
|
|
44
|
-
type TfyListSessionsParams,
|
|
45
|
-
type TfyToolInfo,
|
|
46
|
-
type TfySystemToolInfo,
|
|
47
|
-
type TfyMcpToolInfo,
|
|
48
|
-
type TfyModelMessageUsage,
|
|
49
|
-
type TfyFinishReason,
|
|
50
|
-
type TfyThreadState,
|
|
51
|
-
type TfyMcpServerInitInfo,
|
|
20
|
+
type RequireApprovalToolsSelectorTag, type TfyAgentSpec, type TfyCreateSessionRequest, type TfyFinishReason, type TfyListSessionsParams, type TfyMcpServerInitInfo, type TfyMcpServerMount, type TfyMcpToolInfo,
|
|
21
|
+
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,
|
|
22
|
+
type ToolsSelectorTag
|
|
52
23
|
} from "./types.js";
|
|
53
24
|
|
|
54
25
|
export {
|
|
55
|
-
isTfyToolInfo
|
|
56
|
-
isTfySystemToolInfo,
|
|
57
|
-
isTfyMcpToolInfo,
|
|
58
|
-
getTfyUsage,
|
|
59
|
-
getTfyThreadState,
|
|
60
|
-
getTfyMcpInitServers,
|
|
26
|
+
getTfyMcpInitServers, getTfyThreadState, getTfyUsage, isTfyMcpToolInfo, isTfySystemToolInfo, isTfyToolInfo
|
|
61
27
|
} from "./guards.js";
|
|
62
28
|
|
|
63
|
-
type GwSession = AgentSession | AgentDraftSession;
|
|
64
|
-
|
|
65
|
-
export type CreateTrueFoundryChatServerOptions = {
|
|
66
|
-
apiKey: string;
|
|
67
|
-
baseUrl: string;
|
|
68
|
-
/** Optional override — otherwise constructed from apiKey/baseUrl. */
|
|
69
|
-
client?: AgentSessionClient;
|
|
70
|
-
privateClient?: PrivateAgentSessionClient;
|
|
71
|
-
deleteSession?: (req: { sessionId: string }) => Promise<void>;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Only the spec is generic. Session/Turn/list-params are the concrete Tfy*
|
|
76
|
-
* types because the adapter builds them as fixed object literals — a generic
|
|
77
|
-
* there would type fields that nothing ever populates. The spec is safe: the
|
|
78
|
-
* gateway SDK serializes with `unrecognizedObjectKeys: "passthrough"`, so
|
|
79
|
-
* host-added spec fields survive the round trip.
|
|
80
|
-
*/
|
|
81
|
-
export type TrueFoundryChatServer<TSpec extends TfyAgentSpec = TfyAgentSpec> =
|
|
82
|
-
AgentChatServer<
|
|
83
|
-
TSpec,
|
|
84
|
-
TfySession<TSpec>,
|
|
85
|
-
TfyCreateSessionRequest<TSpec>,
|
|
86
|
-
TfyListSessionsParams,
|
|
87
|
-
UpdateSessionRequest<TSpec>,
|
|
88
|
-
TfyTurn
|
|
89
|
-
> & {
|
|
90
|
-
/** Escape hatch for hosts that still need raw gateway clients. */
|
|
91
|
-
getGatewayClients(): {
|
|
92
|
-
client: AgentSessionClient;
|
|
93
|
-
privateClient: PrivateAgentSessionClient;
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/** Gateway SDK errors carry the HTTP status as `statusCode`. */
|
|
98
|
-
function isNotFound(error: unknown): boolean {
|
|
99
|
-
return (
|
|
100
|
-
typeof error === "object" &&
|
|
101
|
-
error !== null &&
|
|
102
|
-
(error as { statusCode?: unknown }).statusCode === 404
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function isDraft(session: GwSession): session is AgentDraftSession {
|
|
107
|
-
return (session as AgentDraftSession).type === "session/draft";
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function toSession<TSpec extends TfyAgentSpec>(raw: GwSession): TfySession<TSpec> {
|
|
111
|
-
const mutable = isDraft(raw);
|
|
112
|
-
return {
|
|
113
|
-
id: raw.id,
|
|
114
|
-
title: raw.title,
|
|
115
|
-
agentName: raw.agentName,
|
|
116
|
-
...(mutable ? { agentSpec: raw.agentSpec as TSpec } : {}),
|
|
117
|
-
isMutable: mutable,
|
|
118
|
-
createdBySubject: raw.createdBySubject,
|
|
119
|
-
createdAt: raw.createdAt,
|
|
120
|
-
updatedAt: raw.updatedAt,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function toTurn(raw: {
|
|
125
|
-
id: string;
|
|
126
|
-
sessionId: string;
|
|
127
|
-
previousTurnId?: string | null;
|
|
128
|
-
input?: TurnInputItem[];
|
|
129
|
-
state: unknown;
|
|
130
|
-
createdBySubject: TfyTurn["createdBySubject"];
|
|
131
|
-
createdAt: string;
|
|
132
|
-
}): TfyTurn {
|
|
133
|
-
return {
|
|
134
|
-
id: raw.id,
|
|
135
|
-
sessionId: raw.sessionId,
|
|
136
|
-
previousTurnId: raw.previousTurnId,
|
|
137
|
-
input: raw.input,
|
|
138
|
-
state: raw.state as TfyTurnState,
|
|
139
|
-
createdBySubject: raw.createdBySubject,
|
|
140
|
-
createdAt: raw.createdAt,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function toListResult<TIn, TOut>(
|
|
145
|
-
page: {
|
|
146
|
-
data: TIn[];
|
|
147
|
-
response?: { pagination?: { nextPageToken?: string } };
|
|
148
|
-
hasNextPage?: () => boolean;
|
|
149
|
-
},
|
|
150
|
-
map: (item: TIn) => TOut,
|
|
151
|
-
): Promise<ListResult<TOut>> {
|
|
152
|
-
const nextPageToken = page.response?.pagination?.nextPageToken;
|
|
153
|
-
return {
|
|
154
|
-
data: page.data.map(map),
|
|
155
|
-
...(nextPageToken != null && nextPageToken !== ""
|
|
156
|
-
? { nextPageToken }
|
|
157
|
-
: {}),
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Wraps TrueFoundry gateway clients into a flat `AgentChatServer`.
|
|
163
|
-
* Named vs draft routing is fully internal — an in-memory session-type cache
|
|
164
|
-
* (populated by createSession/listSessions) determines which gateway client
|
|
165
|
-
* to call, falling back to a one-time probe for ids seen only in a URL.
|
|
166
|
-
*/
|
|
167
|
-
export function createTrueFoundryChatServer<
|
|
168
|
-
TSpec extends TfyAgentSpec = TfyAgentSpec,
|
|
169
|
-
>(
|
|
170
|
-
opts: CreateTrueFoundryChatServerOptions,
|
|
171
|
-
): TrueFoundryChatServer<TSpec> {
|
|
172
|
-
const gatewayOpts = { apiKey: opts.apiKey, baseUrl: opts.baseUrl };
|
|
173
|
-
const client = opts.client ?? new AgentSessionClient(gatewayOpts);
|
|
174
|
-
const privateClient =
|
|
175
|
-
opts.privateClient ?? new PrivateAgentSessionClient(gatewayOpts);
|
|
176
|
-
|
|
177
|
-
const sessionTypeCache = new Map<string, boolean>();
|
|
178
|
-
const sessionTypeProbes = new Map<string, Promise<boolean>>();
|
|
179
|
-
|
|
180
|
-
function cacheSessionType(session: {
|
|
181
|
-
id: string;
|
|
182
|
-
isMutable: boolean;
|
|
183
|
-
}): void {
|
|
184
|
-
sessionTypeCache.set(session.id, session.isMutable);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Resolving a session id straight from a URL (page reload / shared link)
|
|
189
|
-
* reaches the gateway before createSession or listSessions has cached the
|
|
190
|
-
* type, so discover it by probing the draft endpoint and falling back to
|
|
191
|
-
* the conversation endpoint. Concurrent callers share one probe.
|
|
192
|
-
*/
|
|
193
|
-
async function probeSessionType(sessionId: string): Promise<boolean> {
|
|
194
|
-
const inflight = sessionTypeProbes.get(sessionId);
|
|
195
|
-
if (inflight != null) {
|
|
196
|
-
return inflight;
|
|
197
|
-
}
|
|
198
|
-
const probe = (async () => {
|
|
199
|
-
try {
|
|
200
|
-
await privateClient.getDraftSession({ draftSessionId: sessionId });
|
|
201
|
-
return true;
|
|
202
|
-
} catch (error) {
|
|
203
|
-
// Only a miss proves the id isn't a draft. Auth or transient
|
|
204
|
-
// failures would otherwise be retried as a conversation session
|
|
205
|
-
// and mislabel a real draft as named.
|
|
206
|
-
if (!isNotFound(error)) {
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
await client.getSession({ sessionId });
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
})();
|
|
213
|
-
sessionTypeProbes.set(sessionId, probe);
|
|
214
|
-
try {
|
|
215
|
-
const isMutable = await probe;
|
|
216
|
-
sessionTypeCache.set(sessionId, isMutable);
|
|
217
|
-
return isMutable;
|
|
218
|
-
} finally {
|
|
219
|
-
sessionTypeProbes.delete(sessionId);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async function getSessionObj(sessionId: string): Promise<GwSession> {
|
|
224
|
-
const isMutable =
|
|
225
|
-
sessionTypeCache.get(sessionId) ?? (await probeSessionType(sessionId));
|
|
226
|
-
return isMutable
|
|
227
|
-
? privateClient.getDraftSession({ draftSessionId: sessionId })
|
|
228
|
-
: client.getSession({ sessionId });
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const server: TrueFoundryChatServer<TSpec> = {
|
|
232
|
-
async createSession(req) {
|
|
233
|
-
if (req.agentSpec != null) {
|
|
234
|
-
const draft = await privateClient.createDraftSession({
|
|
235
|
-
agentSpec: req.agentSpec,
|
|
236
|
-
...(req.agentName != null ? { agentName: req.agentName } : {}),
|
|
237
|
-
...(req.tfyMetadata != null
|
|
238
|
-
? { tfyMetadata: req.tfyMetadata }
|
|
239
|
-
: {}),
|
|
240
|
-
});
|
|
241
|
-
const session = toSession<TSpec>(draft);
|
|
242
|
-
cacheSessionType(session);
|
|
243
|
-
return session;
|
|
244
|
-
}
|
|
245
|
-
if (req.agentName != null) {
|
|
246
|
-
const named = await client.createSession({
|
|
247
|
-
agentName: req.agentName,
|
|
248
|
-
...(req.tfyMetadata != null
|
|
249
|
-
? { tfyMetadata: req.tfyMetadata }
|
|
250
|
-
: {}),
|
|
251
|
-
});
|
|
252
|
-
const session = toSession<TSpec>(named);
|
|
253
|
-
cacheSessionType(session);
|
|
254
|
-
return session;
|
|
255
|
-
}
|
|
256
|
-
throw new Error("createSession requires agentName and/or agentSpec");
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
async listSessions(req) {
|
|
260
|
-
const page = await privateClient.listOwnedSessions({
|
|
261
|
-
limit: req?.limit,
|
|
262
|
-
order: req?.order,
|
|
263
|
-
pageToken: req?.pageToken,
|
|
264
|
-
startTimestamp: req?.startTimestamp,
|
|
265
|
-
endTimestamp: req?.endTimestamp,
|
|
266
|
-
...(req?.agentName != null ? { agentName: req.agentName } : {}),
|
|
267
|
-
});
|
|
268
|
-
const result = await toListResult(page, (s) => toSession<TSpec>(s));
|
|
269
|
-
for (const session of result.data) {
|
|
270
|
-
cacheSessionType(session);
|
|
271
|
-
}
|
|
272
|
-
return result;
|
|
273
|
-
},
|
|
274
|
-
|
|
275
|
-
async getSession({ sessionId }) {
|
|
276
|
-
const raw = await getSessionObj(sessionId);
|
|
277
|
-
const session = toSession<TSpec>(raw);
|
|
278
|
-
cacheSessionType(session);
|
|
279
|
-
return session;
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
async updateSession(req) {
|
|
283
|
-
const raw = await getSessionObj(req.sessionId);
|
|
284
|
-
if (!isDraft(raw)) {
|
|
285
|
-
throw new Error(
|
|
286
|
-
"updateSession: session is not mutable (isMutable=false)",
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
if (req.agentSpec != null) {
|
|
290
|
-
await raw.update({ agentSpec: req.agentSpec });
|
|
291
|
-
}
|
|
292
|
-
return toSession<TSpec>(raw);
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
prepareAndExecuteTurn(req: {
|
|
296
|
-
sessionId: string;
|
|
297
|
-
input?: TurnInputItem[];
|
|
298
|
-
previousTurnId?: PreviousTurnIdInput;
|
|
299
|
-
abortSignal?: AbortSignal;
|
|
300
|
-
headers?: Record<string, string>;
|
|
301
|
-
}): AsyncIterable<TurnStreamData> {
|
|
302
|
-
return (async function* () {
|
|
303
|
-
const session = await getSessionObj(req.sessionId);
|
|
304
|
-
const prepared = session.prepareTurn({
|
|
305
|
-
input: req.input,
|
|
306
|
-
previousTurnId: req.previousTurnId ?? "auto",
|
|
307
|
-
});
|
|
308
|
-
yield* prepared.execute(
|
|
309
|
-
{ stream: true },
|
|
310
|
-
{
|
|
311
|
-
...(req.abortSignal != null
|
|
312
|
-
? { abortSignal: req.abortSignal }
|
|
313
|
-
: {}),
|
|
314
|
-
...(req.headers != null ? { headers: req.headers } : {}),
|
|
315
|
-
},
|
|
316
|
-
) as AsyncIterable<TurnStreamData>;
|
|
317
|
-
})();
|
|
318
|
-
},
|
|
319
|
-
|
|
320
|
-
async cancelSession({ sessionId }) {
|
|
321
|
-
await (await getSessionObj(sessionId)).cancel();
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
async deleteSession({ sessionId }) {
|
|
325
|
-
if (opts.deleteSession == null) {
|
|
326
|
-
throw new Error(
|
|
327
|
-
"deleteSession is not on the gateway SDK. Pass deleteSession to createTrueFoundryChatServer.",
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
await opts.deleteSession({ sessionId });
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
// The runtime's signature offers `order`, but the gateway's listTurns
|
|
334
|
-
// takes no such param — forwarding it silently did nothing.
|
|
335
|
-
async listTurns({ sessionId, limit, pageToken }) {
|
|
336
|
-
const raw = await getSessionObj(sessionId);
|
|
337
|
-
const page = await raw.listTurns({
|
|
338
|
-
...(limit != null ? { limit } : {}),
|
|
339
|
-
...(pageToken != null ? { pageToken } : {}),
|
|
340
|
-
});
|
|
341
|
-
return toListResult(page, (turn) => toTurn(turn));
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
async getTurn({ sessionId, turnId }) {
|
|
345
|
-
const raw = await getSessionObj(sessionId);
|
|
346
|
-
return toTurn(await raw.getTurn({ turnId }));
|
|
347
|
-
},
|
|
348
|
-
|
|
349
|
-
async listEvents({ sessionId, pageToken, lastTurnId, limit }) {
|
|
350
|
-
const raw = await getSessionObj(sessionId);
|
|
351
|
-
const page = await raw.listEvents({
|
|
352
|
-
...(limit != null ? { limit } : {}),
|
|
353
|
-
...(pageToken != null ? { pageToken } : {}),
|
|
354
|
-
...(lastTurnId != null ? { lastTurnId } : {}),
|
|
355
|
-
});
|
|
356
|
-
return toListResult(
|
|
357
|
-
page,
|
|
358
|
-
(item) => item as SessionEventItem,
|
|
359
|
-
);
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
async listTurnEvents({ sessionId, turnId, limit, pageToken, order }) {
|
|
363
|
-
const raw = await getSessionObj(sessionId);
|
|
364
|
-
const turn = await raw.getTurn({ turnId });
|
|
365
|
-
const page = await turn.listEvents({
|
|
366
|
-
...(limit != null ? { limit } : {}),
|
|
367
|
-
...(pageToken != null ? { pageToken } : {}),
|
|
368
|
-
...(order != null ? { order } : {}),
|
|
369
|
-
});
|
|
370
|
-
return toListResult(page, (event) => event as TurnEvent);
|
|
371
|
-
},
|
|
372
|
-
|
|
373
|
-
async *subscribeToTurn({
|
|
374
|
-
sessionId,
|
|
375
|
-
turnId,
|
|
376
|
-
afterSequenceNumber,
|
|
377
|
-
abortSignal,
|
|
378
|
-
}) {
|
|
379
|
-
const raw = await getSessionObj(sessionId);
|
|
380
|
-
const turn = await raw.getTurn({ turnId });
|
|
381
|
-
yield* turn.stream(
|
|
382
|
-
afterSequenceNumber != null ? { afterSequenceNumber } : {},
|
|
383
|
-
abortSignal != null ? { abortSignal } : {},
|
|
384
|
-
) as AsyncIterable<TurnStreamData>;
|
|
385
|
-
},
|
|
386
|
-
|
|
387
|
-
async downloadSandboxFile(sandboxId, req) {
|
|
388
|
-
const response = await privateClient.downloadSandboxFile(
|
|
389
|
-
sandboxId,
|
|
390
|
-
req,
|
|
391
|
-
);
|
|
392
|
-
return await response.blob();
|
|
393
|
-
},
|
|
394
|
-
|
|
395
|
-
getGatewayClients: () => ({ client, privateClient }),
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
return server;
|
|
399
|
-
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
normalizeAgentSpecForGateway,
|
|
5
|
+
normalizeMcpMount,
|
|
6
|
+
normalizeSkillMount,
|
|
7
|
+
} from "./normalizeAgentSpec.js";
|
|
8
|
+
|
|
9
|
+
describe("normalizeMcpMount", () => {
|
|
10
|
+
it("passes through registry mounts", () => {
|
|
11
|
+
expect(
|
|
12
|
+
normalizeMcpMount({
|
|
13
|
+
type: "truefoundry-mcp-registry",
|
|
14
|
+
name: "g-calendar",
|
|
15
|
+
enableTools: ["@all"],
|
|
16
|
+
}),
|
|
17
|
+
).toEqual({
|
|
18
|
+
type: "truefoundry-mcp-registry",
|
|
19
|
+
name: "g-calendar",
|
|
20
|
+
enableTools: ["@all"],
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("maps UI {id,name} catalog rows to registry mounts", () => {
|
|
25
|
+
expect(
|
|
26
|
+
normalizeMcpMount({ id: "deepwiki-mcp", name: "deepwiki-mcp" }),
|
|
27
|
+
).toEqual({
|
|
28
|
+
type: "truefoundry-mcp-registry",
|
|
29
|
+
name: "deepwiki-mcp",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("normalizeSkillMount", () => {
|
|
35
|
+
it("passes through registry mounts", () => {
|
|
36
|
+
expect(
|
|
37
|
+
normalizeSkillMount({
|
|
38
|
+
type: "truefoundry-skills-registry",
|
|
39
|
+
fqn: "agent-skill:truefoundry/skills/web:1",
|
|
40
|
+
preload: false,
|
|
41
|
+
}),
|
|
42
|
+
).toEqual({
|
|
43
|
+
type: "truefoundry-skills-registry",
|
|
44
|
+
fqn: "agent-skill:truefoundry/skills/web:1",
|
|
45
|
+
preload: false,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("maps UI {id,name} rows (id = fqn from CP catalog) to registry mounts", () => {
|
|
50
|
+
expect(
|
|
51
|
+
normalizeSkillMount({
|
|
52
|
+
id: "agent-skill:truefoundry/skills/web:1",
|
|
53
|
+
name: "web",
|
|
54
|
+
}),
|
|
55
|
+
).toEqual({
|
|
56
|
+
type: "truefoundry-skills-registry",
|
|
57
|
+
fqn: "agent-skill:truefoundry/skills/web:1",
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("normalizeAgentSpecForGateway", () => {
|
|
63
|
+
it("rewrites UI mount rows so gateway serialization can succeed", () => {
|
|
64
|
+
const next = normalizeAgentSpecForGateway({
|
|
65
|
+
model: { name: "openai-main/gpt-4.1" },
|
|
66
|
+
mcpServers: [{ id: "gmail", name: "gmail" }] as never[],
|
|
67
|
+
skills: [
|
|
68
|
+
{
|
|
69
|
+
id: "agent-skill:truefoundry/skills/web:1",
|
|
70
|
+
name: "web",
|
|
71
|
+
},
|
|
72
|
+
] as never[],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(next.mcpServers).toEqual([
|
|
76
|
+
{ type: "truefoundry-mcp-registry", name: "gmail" },
|
|
77
|
+
]);
|
|
78
|
+
expect(next.skills).toEqual([
|
|
79
|
+
{
|
|
80
|
+
type: "truefoundry-skills-registry",
|
|
81
|
+
fqn: "agent-skill:truefoundry/skills/web:1",
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { TruefoundryGatewayApi } from "truefoundry-gateway-sdk";
|
|
2
|
+
|
|
3
|
+
import type { TfyAgentSpec } from "./types.js";
|
|
4
|
+
|
|
5
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
6
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* agent-ui-sdk DraftCompositeSelector writes catalog rows as `{ id, name }`.
|
|
11
|
+
* Gateway AgentSpec mounts need discriminated registry shapes — without
|
|
12
|
+
* `type` (and skill `fqn`), Fern serialization throws JsonError before PATCH.
|
|
13
|
+
*
|
|
14
|
+
* Our CP catalog sets skill `id` = version fqn and MCP `id` = server name.
|
|
15
|
+
*/
|
|
16
|
+
export function normalizeMcpMount(
|
|
17
|
+
raw: unknown,
|
|
18
|
+
): TruefoundryGatewayApi.McpServer {
|
|
19
|
+
if (!isRecord(raw)) {
|
|
20
|
+
throw new Error("mcpServers entry must be an object");
|
|
21
|
+
}
|
|
22
|
+
if (raw.type === "truefoundry-mcp-registry" || raw.type === "inline") {
|
|
23
|
+
return raw as TruefoundryGatewayApi.McpServer;
|
|
24
|
+
}
|
|
25
|
+
const name =
|
|
26
|
+
(typeof raw.name === "string" && raw.name !== "" ? raw.name : null) ??
|
|
27
|
+
(typeof raw.mcpName === "string" && raw.mcpName !== ""
|
|
28
|
+
? raw.mcpName
|
|
29
|
+
: null) ??
|
|
30
|
+
(typeof raw.id === "string" && raw.id !== "" ? raw.id : null);
|
|
31
|
+
if (name == null) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"mcpServers entry needs name, mcpName, or id to mount as registry MCP",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return { type: "truefoundry-mcp-registry", name };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function normalizeSkillMount(
|
|
40
|
+
raw: unknown,
|
|
41
|
+
): TruefoundryGatewayApi.SkillMount {
|
|
42
|
+
if (!isRecord(raw)) {
|
|
43
|
+
throw new Error("skills entry must be an object");
|
|
44
|
+
}
|
|
45
|
+
if (raw.type === "truefoundry-skills-registry" || raw.type === "git") {
|
|
46
|
+
return raw as TruefoundryGatewayApi.SkillMount;
|
|
47
|
+
}
|
|
48
|
+
const fqn =
|
|
49
|
+
(typeof raw.fqn === "string" && raw.fqn !== "" ? raw.fqn : null) ??
|
|
50
|
+
(typeof raw.id === "string" && raw.id !== "" ? raw.id : null);
|
|
51
|
+
if (fqn == null) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"skills entry needs fqn or id to mount as registry skill",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
type: "truefoundry-skills-registry",
|
|
58
|
+
fqn,
|
|
59
|
+
...(raw.preload === true ? { preload: true } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Rewrite UI `{id,name}` mounts so create/update draft session can serialize. */
|
|
64
|
+
export function normalizeAgentSpecForGateway<TSpec extends TfyAgentSpec>(
|
|
65
|
+
spec: TSpec,
|
|
66
|
+
): TSpec {
|
|
67
|
+
return {
|
|
68
|
+
...spec,
|
|
69
|
+
...(spec.mcpServers != null
|
|
70
|
+
? {
|
|
71
|
+
mcpServers: spec.mcpServers.map(
|
|
72
|
+
normalizeMcpMount,
|
|
73
|
+
) as TSpec["mcpServers"],
|
|
74
|
+
}
|
|
75
|
+
: {}),
|
|
76
|
+
...(spec.skills != null
|
|
77
|
+
? {
|
|
78
|
+
skills: spec.skills.map(
|
|
79
|
+
normalizeSkillMount,
|
|
80
|
+
) as TSpec["skills"],
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -123,7 +123,7 @@ export interface TfyListSessionsParams extends ListSessionsParams {
|
|
|
123
123
|
// Event-side types.
|
|
124
124
|
//
|
|
125
125
|
// These do NOT flow through AgentChatServer — its listEvents / listTurnEvents /
|
|
126
|
-
// subscribeToTurn /
|
|
126
|
+
// subscribeToTurn / createTurn signatures hardcode the runtime's
|
|
127
127
|
// event types with no generic to override. Hosts narrow at the point of use
|
|
128
128
|
// with the guards in `guards.ts`.
|
|
129
129
|
// ---------------------------------------------------------------------------
|
package/src/server/index.ts
CHANGED
|
@@ -41,7 +41,13 @@ export type {
|
|
|
41
41
|
ModelCatalogServer,
|
|
42
42
|
ToolBase,
|
|
43
43
|
ConnectorAuthType,
|
|
44
|
+
ConnectorAuthOAuth,
|
|
45
|
+
ConnectorAuthApiKey,
|
|
46
|
+
ConnectorAuthNone,
|
|
44
47
|
ConnectorAuth,
|
|
48
|
+
ConnectorAuthPublicOAuth,
|
|
49
|
+
ConnectorAuthPublicApiKey,
|
|
50
|
+
ConnectorAuthPublicNone,
|
|
45
51
|
ConnectorAuthPublic,
|
|
46
52
|
ConnectorConfigBase,
|
|
47
53
|
ConnectorBase,
|
|
@@ -50,8 +56,22 @@ export type {
|
|
|
50
56
|
UpdateConnectorRequest,
|
|
51
57
|
ConnectorCatalogServer,
|
|
52
58
|
SkillBase,
|
|
59
|
+
RegistrySkill,
|
|
60
|
+
GithubSkill,
|
|
61
|
+
DefinedSkill,
|
|
62
|
+
SkillConfigBase,
|
|
63
|
+
SkillCatalogEntry,
|
|
64
|
+
CreateSkillRequestBase,
|
|
65
|
+
SelectRegistrySkillRequest,
|
|
66
|
+
ImportGithubSkillRequest,
|
|
53
67
|
CreateSkillRequest,
|
|
54
68
|
SkillCatalogServer,
|
|
69
|
+
SandboxConfig,
|
|
70
|
+
SandboxCatalogEntry,
|
|
71
|
+
SandboxBase,
|
|
72
|
+
CreateSandboxRequest,
|
|
73
|
+
UpdateSandboxRequest,
|
|
74
|
+
SandboxCatalogServer,
|
|
55
75
|
CatalogServer,
|
|
56
76
|
AgentUIServerPort,
|
|
57
77
|
} from "./types.js";
|