@truefoundry/assistant-ui-runtime 0.1.9 → 0.1.10
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 +26 -0
- package/dist/{chunk-CXBZ6WLZ.js → chunk-6ZOGBD7E.js} +99 -17
- package/dist/chunk-6ZOGBD7E.js.map +1 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.js +92 -71
- package/dist/index.js.map +1 -1
- package/dist/plugins/truefoundry-agent-server-adapter/index.d.ts +1 -1
- package/dist/plugins/truefoundry-agent-server-adapter/index.js +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/{types-6yWuWHzK.d.ts → types-Bb8Kaf1h.d.ts} +16 -3
- package/package.json +3 -3
- package/src/convertTurnMessages.test.ts +23 -1
- package/src/convertTurnMessages.ts +9 -3
- package/src/draft/truefoundryDraftThreadListAdapter.test.ts +57 -4
- package/src/draft/truefoundryDraftThreadListAdapter.ts +18 -22
- package/src/hooks.ts +23 -3
- package/src/index.ts +1 -0
- package/src/messageCustomMetadata.ts +2 -0
- package/src/plugins/truefoundry-agent-server-adapter/chatServer.ts +7 -6
- package/src/plugins/truefoundry-agent-server-adapter/cp.test.ts +169 -6
- package/src/plugins/truefoundry-agent-server-adapter/cp.ts +126 -1
- package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.test.ts +34 -0
- package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.ts +12 -5
- package/src/server/types.ts +18 -6
- package/src/sessionThreadMetadata.ts +39 -0
- package/src/truefoundryExtras.ts +1 -1
- package/src/truefoundryOwnedSessionsThreadListAdapter.test.ts +16 -0
- package/src/truefoundryOwnedSessionsThreadListAdapter.ts +13 -25
- package/src/truefoundryThreadListAdapter.test.ts +17 -9
- package/src/truefoundryThreadListAdapter.ts +9 -14
- package/src/types.ts +5 -0
- package/src/useTrueFoundryAgentRuntime.ts +17 -4
- package/dist/chunk-CXBZ6WLZ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
isTfyMcpToolInfo,
|
|
12
12
|
isTfySystemToolInfo,
|
|
13
13
|
isTfyToolInfo
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6ZOGBD7E.js";
|
|
15
15
|
|
|
16
16
|
// src/useTrueFoundryAgentRuntime.ts
|
|
17
17
|
import {
|
|
@@ -1929,7 +1929,11 @@ function projectHistoryTurns(snapshot, options) {
|
|
|
1929
1929
|
content,
|
|
1930
1930
|
record
|
|
1931
1931
|
);
|
|
1932
|
-
const custom =
|
|
1932
|
+
const custom = {
|
|
1933
|
+
...baseCustom,
|
|
1934
|
+
turnId: record.id,
|
|
1935
|
+
...record.sandboxId != null ? { sandboxId: record.sandboxId } : {}
|
|
1936
|
+
};
|
|
1933
1937
|
if (record.userText) {
|
|
1934
1938
|
messages.push(
|
|
1935
1939
|
buildUserMessageFromTurnInput(
|
|
@@ -2374,7 +2378,7 @@ function turnStreamUpdateToAssistantMessage(turnId, update, existing, options) {
|
|
|
2374
2378
|
unstable_annotations: [],
|
|
2375
2379
|
unstable_data: [],
|
|
2376
2380
|
steps: [],
|
|
2377
|
-
custom: update.metadata?.custom
|
|
2381
|
+
custom: { ...update.metadata?.custom, turnId }
|
|
2378
2382
|
}
|
|
2379
2383
|
};
|
|
2380
2384
|
}
|
|
@@ -2411,6 +2415,13 @@ function createDraftSessionBridge(server) {
|
|
|
2411
2415
|
};
|
|
2412
2416
|
}
|
|
2413
2417
|
|
|
2418
|
+
// src/sessionListStartTimestamp.ts
|
|
2419
|
+
function sessionListStartTimestamp() {
|
|
2420
|
+
const start = /* @__PURE__ */ new Date();
|
|
2421
|
+
start.setFullYear(start.getFullYear() - 1);
|
|
2422
|
+
return start.toISOString();
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2414
2425
|
// src/draft/agentSpec.ts
|
|
2415
2426
|
function mergeAgentSpec(base, update) {
|
|
2416
2427
|
const { model: modelUpdate, ...rest } = update;
|
|
@@ -2432,33 +2443,47 @@ function draftSessionTitle(draft) {
|
|
|
2432
2443
|
return draft.title ?? draft.agentSpec.model.name;
|
|
2433
2444
|
}
|
|
2434
2445
|
|
|
2435
|
-
// src/
|
|
2436
|
-
function
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2446
|
+
// src/sessionThreadMetadata.ts
|
|
2447
|
+
function sessionDisplayTitle(session, defaultAgentSpec) {
|
|
2448
|
+
if (session.isMutable) {
|
|
2449
|
+
const agentSpec = session.agentSpec ?? defaultAgentSpec;
|
|
2450
|
+
if (agentSpec != null) {
|
|
2451
|
+
return draftSessionTitle({
|
|
2452
|
+
title: session.title,
|
|
2453
|
+
agentSpec
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
return session.title ?? session.agentName ?? session.id;
|
|
2458
|
+
}
|
|
2459
|
+
function sessionToThreadMetadata(session, title) {
|
|
2460
|
+
return {
|
|
2461
|
+
status: "regular",
|
|
2462
|
+
remoteId: session.id,
|
|
2463
|
+
title,
|
|
2464
|
+
lastMessageAt: new Date(session.updatedAt),
|
|
2465
|
+
...session.agentName != null ? { custom: { agentName: session.agentName } } : {}
|
|
2466
|
+
};
|
|
2440
2467
|
}
|
|
2441
2468
|
|
|
2442
2469
|
// src/draft/truefoundryDraftThreadListAdapter.ts
|
|
2443
2470
|
var THREAD_LIST_PAGE_SIZE = 20;
|
|
2444
2471
|
function createTrueFoundryDraftThreadListAdapter(options) {
|
|
2445
|
-
const { server, defaultAgentSpec, getAgentSpec } = options;
|
|
2472
|
+
const { server, defaultAgentSpec, getAgentSpec, listSessionsAgentId } = options;
|
|
2446
2473
|
return {
|
|
2447
2474
|
async list({ after } = {}) {
|
|
2448
2475
|
const page = await server.listSessions({
|
|
2476
|
+
...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
|
|
2449
2477
|
limit: THREAD_LIST_PAGE_SIZE,
|
|
2450
2478
|
pageToken: after,
|
|
2451
2479
|
startTimestamp: sessionListStartTimestamp()
|
|
2452
2480
|
});
|
|
2453
|
-
const threads = page.data.
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
}),
|
|
2460
|
-
lastMessageAt: new Date(draft.updatedAt)
|
|
2461
|
-
}));
|
|
2481
|
+
const threads = page.data.map(
|
|
2482
|
+
(session) => sessionToThreadMetadata(
|
|
2483
|
+
session,
|
|
2484
|
+
sessionDisplayTitle(session, defaultAgentSpec)
|
|
2485
|
+
)
|
|
2486
|
+
);
|
|
2462
2487
|
return {
|
|
2463
2488
|
threads,
|
|
2464
2489
|
nextCursor: page.nextPageToken ?? void 0
|
|
@@ -2472,15 +2497,10 @@ function createTrueFoundryDraftThreadListAdapter(options) {
|
|
|
2472
2497
|
},
|
|
2473
2498
|
async fetch(remoteId) {
|
|
2474
2499
|
const draft = await server.getSession({ sessionId: remoteId });
|
|
2475
|
-
return
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
title: draft.title,
|
|
2480
|
-
agentSpec: draft.agentSpec ?? defaultAgentSpec
|
|
2481
|
-
}),
|
|
2482
|
-
lastMessageAt: new Date(draft.updatedAt)
|
|
2483
|
-
};
|
|
2500
|
+
return sessionToThreadMetadata(
|
|
2501
|
+
draft,
|
|
2502
|
+
sessionDisplayTitle(draft, defaultAgentSpec)
|
|
2503
|
+
);
|
|
2484
2504
|
},
|
|
2485
2505
|
async rename() {
|
|
2486
2506
|
},
|
|
@@ -2532,21 +2552,18 @@ function getSession(server, sessionId) {
|
|
|
2532
2552
|
// src/truefoundryThreadListAdapter.ts
|
|
2533
2553
|
var THREAD_LIST_PAGE_SIZE2 = 20;
|
|
2534
2554
|
function createTrueFoundryThreadListAdapter(options) {
|
|
2535
|
-
const { server, agentName } = options;
|
|
2555
|
+
const { server, agentName, listSessionsAgentId } = options;
|
|
2536
2556
|
return {
|
|
2537
2557
|
async list({ after } = {}) {
|
|
2538
2558
|
const page = await server.listSessions({
|
|
2539
|
-
|
|
2559
|
+
...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
|
|
2540
2560
|
limit: THREAD_LIST_PAGE_SIZE2,
|
|
2541
2561
|
pageToken: after,
|
|
2542
2562
|
startTimestamp: sessionListStartTimestamp()
|
|
2543
2563
|
});
|
|
2544
|
-
const threads = page.data.map(
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
title: session.title ?? void 0,
|
|
2548
|
-
lastMessageAt: new Date(session.updatedAt)
|
|
2549
|
-
}));
|
|
2564
|
+
const threads = page.data.map(
|
|
2565
|
+
(session) => sessionToThreadMetadata(session, session.title ?? void 0)
|
|
2566
|
+
);
|
|
2550
2567
|
return {
|
|
2551
2568
|
threads,
|
|
2552
2569
|
nextCursor: page.nextPageToken ?? void 0
|
|
@@ -2558,12 +2575,7 @@ function createTrueFoundryThreadListAdapter(options) {
|
|
|
2558
2575
|
},
|
|
2559
2576
|
async fetch(remoteId) {
|
|
2560
2577
|
const session = await getSession(server, remoteId);
|
|
2561
|
-
return
|
|
2562
|
-
status: "regular",
|
|
2563
|
-
remoteId: session.id,
|
|
2564
|
-
title: session.title ?? void 0,
|
|
2565
|
-
lastMessageAt: new Date(session.updatedAt)
|
|
2566
|
-
};
|
|
2578
|
+
return sessionToThreadMetadata(session, session.title ?? void 0);
|
|
2567
2579
|
},
|
|
2568
2580
|
async rename() {
|
|
2569
2581
|
},
|
|
@@ -3803,18 +3815,28 @@ function useTrueFoundryAgentRuntimeImpl(options, pendingAgentSpecRef) {
|
|
|
3803
3815
|
[sendTurn]
|
|
3804
3816
|
);
|
|
3805
3817
|
const downloadSandboxFile = useCallback3(
|
|
3806
|
-
async (path) => {
|
|
3818
|
+
async ({ turnId, path }) => {
|
|
3807
3819
|
if (server.downloadSandboxFile == null) {
|
|
3808
3820
|
throw new Error(
|
|
3809
3821
|
"Downloading a sandbox file requires AgentChatServer.downloadSandboxFile."
|
|
3810
3822
|
);
|
|
3811
3823
|
}
|
|
3824
|
+
if (sessionId == null) {
|
|
3825
|
+
throw new Error(
|
|
3826
|
+
"This session has not been saved yet, so its files cannot be downloaded."
|
|
3827
|
+
);
|
|
3828
|
+
}
|
|
3812
3829
|
if (sandboxId == null) {
|
|
3813
3830
|
throw new Error("No sandbox is available yet for this session.");
|
|
3814
3831
|
}
|
|
3815
|
-
return await server.downloadSandboxFile(
|
|
3832
|
+
return await server.downloadSandboxFile({
|
|
3833
|
+
sessionId,
|
|
3834
|
+
turnId,
|
|
3835
|
+
sandboxId,
|
|
3836
|
+
path
|
|
3837
|
+
});
|
|
3816
3838
|
},
|
|
3817
|
-
[server, sandboxId]
|
|
3839
|
+
[server, sessionId, sandboxId]
|
|
3818
3840
|
);
|
|
3819
3841
|
const draftExtras = useMemo3(() => {
|
|
3820
3842
|
if (agent.mode !== "draft") {
|
|
@@ -3912,20 +3934,23 @@ function useTrueFoundryAgentRuntime(options) {
|
|
|
3912
3934
|
);
|
|
3913
3935
|
const agentMode = agent.mode;
|
|
3914
3936
|
const namedAgentName = agent.mode === "named" ? agent.agentName : void 0;
|
|
3937
|
+
const listSessionsAgentId = resolved.listSessionsAgentId;
|
|
3915
3938
|
const threadListAdapter = useMemo3(() => {
|
|
3916
3939
|
if (agentMode === "draft") {
|
|
3917
3940
|
const draftAgent = agent;
|
|
3918
3941
|
return createTrueFoundryDraftThreadListAdapter({
|
|
3919
3942
|
server,
|
|
3920
3943
|
defaultAgentSpec: draftAgent.defaultAgentSpec,
|
|
3921
|
-
getAgentSpec: () => pendingAgentSpecRef.current ?? draftAgent.defaultAgentSpec
|
|
3944
|
+
getAgentSpec: () => pendingAgentSpecRef.current ?? draftAgent.defaultAgentSpec,
|
|
3945
|
+
listSessionsAgentId
|
|
3922
3946
|
});
|
|
3923
3947
|
}
|
|
3924
3948
|
return createTrueFoundryThreadListAdapter({
|
|
3925
3949
|
server,
|
|
3926
|
-
agentName: namedAgentName
|
|
3950
|
+
agentName: namedAgentName,
|
|
3951
|
+
listSessionsAgentId
|
|
3927
3952
|
});
|
|
3928
|
-
}, [agentMode, namedAgentName, server]);
|
|
3953
|
+
}, [agentMode, namedAgentName, listSessionsAgentId, server]);
|
|
3929
3954
|
return useRemoteThreadListRuntime({
|
|
3930
3955
|
allowNesting: true,
|
|
3931
3956
|
adapter: threadListAdapter,
|
|
@@ -3938,30 +3963,19 @@ function useTrueFoundryAgentRuntime(options) {
|
|
|
3938
3963
|
|
|
3939
3964
|
// src/truefoundryOwnedSessionsThreadListAdapter.ts
|
|
3940
3965
|
var THREAD_LIST_PAGE_SIZE3 = 20;
|
|
3941
|
-
function ownedSessionTitle(session) {
|
|
3942
|
-
if (session.isMutable && session.agentSpec != null) {
|
|
3943
|
-
return draftSessionTitle({
|
|
3944
|
-
title: session.title,
|
|
3945
|
-
agentSpec: session.agentSpec
|
|
3946
|
-
});
|
|
3947
|
-
}
|
|
3948
|
-
return session.title ?? session.agentName ?? session.id;
|
|
3949
|
-
}
|
|
3950
3966
|
function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
|
|
3951
|
-
const { server } = options;
|
|
3967
|
+
const { server, listSessionsAgentId } = options;
|
|
3952
3968
|
return {
|
|
3953
3969
|
async list({ after } = {}) {
|
|
3954
3970
|
const page = await server.listSessions({
|
|
3971
|
+
...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
|
|
3955
3972
|
limit: THREAD_LIST_PAGE_SIZE3,
|
|
3956
3973
|
pageToken: after,
|
|
3957
3974
|
startTimestamp: sessionListStartTimestamp()
|
|
3958
3975
|
});
|
|
3959
|
-
const threads = page.data.map(
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
title: ownedSessionTitle(session),
|
|
3963
|
-
lastMessageAt: new Date(session.updatedAt)
|
|
3964
|
-
}));
|
|
3976
|
+
const threads = page.data.map(
|
|
3977
|
+
(session) => sessionToThreadMetadata(session, sessionDisplayTitle(session))
|
|
3978
|
+
);
|
|
3965
3979
|
return {
|
|
3966
3980
|
threads,
|
|
3967
3981
|
nextCursor: page.nextPageToken ?? void 0
|
|
@@ -3974,12 +3988,7 @@ function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
|
|
|
3974
3988
|
},
|
|
3975
3989
|
async fetch(remoteId) {
|
|
3976
3990
|
const session = await server.getSession({ sessionId: remoteId });
|
|
3977
|
-
return
|
|
3978
|
-
status: "regular",
|
|
3979
|
-
remoteId: session.id,
|
|
3980
|
-
title: ownedSessionTitle(session),
|
|
3981
|
-
lastMessageAt: new Date(session.updatedAt)
|
|
3982
|
-
};
|
|
3991
|
+
return sessionToThreadMetadata(session, sessionDisplayTitle(session));
|
|
3983
3992
|
},
|
|
3984
3993
|
async rename() {
|
|
3985
3994
|
},
|
|
@@ -3999,7 +4008,7 @@ function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
|
|
|
3999
4008
|
|
|
4000
4009
|
// src/hooks.ts
|
|
4001
4010
|
import { useMemo as useMemo4 } from "react";
|
|
4002
|
-
import { useAui as useAui2 } from "@assistant-ui/store";
|
|
4011
|
+
import { useAui as useAui2, useAuiState as useAuiState2 } from "@assistant-ui/store";
|
|
4003
4012
|
var useTrueFoundryApprovals = () => {
|
|
4004
4013
|
const extras = trueFoundryExtras.use((e) => e, void 0);
|
|
4005
4014
|
return useMemo4(
|
|
@@ -4049,9 +4058,20 @@ var useTrueFoundryResumeMcpAuth = () => {
|
|
|
4049
4058
|
return () => trueFoundryExtras.get(aui).resumeMcpAuth();
|
|
4050
4059
|
};
|
|
4051
4060
|
var useTrueFoundrySandboxId = () => trueFoundryExtras.use((e) => e.sandboxId, void 0);
|
|
4061
|
+
var useTrueFoundryTurnId = () => useAuiState2(
|
|
4062
|
+
(state) => state.message.metadata?.custom?.turnId
|
|
4063
|
+
);
|
|
4052
4064
|
var useTrueFoundryDownloadSandboxFile = () => {
|
|
4053
4065
|
const aui = useAui2();
|
|
4054
|
-
|
|
4066
|
+
const turnId = useTrueFoundryTurnId();
|
|
4067
|
+
return (path) => {
|
|
4068
|
+
if (turnId == null) {
|
|
4069
|
+
throw new Error(
|
|
4070
|
+
"Downloading a sandbox file requires a message scope to resolve its turn."
|
|
4071
|
+
);
|
|
4072
|
+
}
|
|
4073
|
+
return trueFoundryExtras.get(aui).downloadSandboxFile({ turnId, path });
|
|
4074
|
+
};
|
|
4055
4075
|
};
|
|
4056
4076
|
var useTrueFoundryCancel = () => {
|
|
4057
4077
|
const aui = useAui2();
|
|
@@ -4191,6 +4211,7 @@ export {
|
|
|
4191
4211
|
useTrueFoundryResumeMcpAuth,
|
|
4192
4212
|
useTrueFoundrySandboxId,
|
|
4193
4213
|
useTrueFoundryToolResponses,
|
|
4214
|
+
useTrueFoundryTurnId,
|
|
4194
4215
|
useTrueFoundryUpdateAgentSpec
|
|
4195
4216
|
};
|
|
4196
4217
|
//# sourceMappingURL=index.js.map
|