@truefoundry/assistant-ui-runtime 0.1.10-rc.1 → 0.1.12

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 (33) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{chunk-BRPTG6VA.js → chunk-2NLIAJJX.js} +100 -12
  3. package/dist/chunk-2NLIAJJX.js.map +1 -0
  4. package/dist/index.d.ts +13 -2
  5. package/dist/index.js +70 -66
  6. package/dist/index.js.map +1 -1
  7. package/dist/plugins/truefoundry-agent-server-adapter/index.d.ts +3 -3
  8. package/dist/plugins/truefoundry-agent-server-adapter/index.js +1 -1
  9. package/dist/server/index.d.ts +2 -2
  10. package/dist/{types-CgZUnILu.d.ts → types-CSRQSnHu.d.ts} +148 -80
  11. package/package.json +3 -3
  12. package/src/convertTurnMessages.test.ts +123 -0
  13. package/src/convertTurnMessages.ts +8 -2
  14. package/src/draft/truefoundryDraftThreadListAdapter.test.ts +58 -4
  15. package/src/draft/truefoundryDraftThreadListAdapter.ts +18 -22
  16. package/src/index.ts +27 -0
  17. package/src/plugins/truefoundry-agent-server-adapter/chatServer.ts +1 -1
  18. package/src/plugins/truefoundry-agent-server-adapter/cp.test.ts +169 -6
  19. package/src/plugins/truefoundry-agent-server-adapter/cp.ts +126 -1
  20. package/src/plugins/truefoundry-agent-server-adapter/createTrueFoundryAgentUIServer.ts +7 -0
  21. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.test.ts +34 -0
  22. package/src/plugins/truefoundry-agent-server-adapter/normalizeAgentSpec.ts +12 -5
  23. package/src/plugins/truefoundry-agent-server-adapter/types.ts +2 -2
  24. package/src/server/index.ts +15 -0
  25. package/src/server/types.ts +448 -381
  26. package/src/sessionThreadMetadata.ts +42 -0
  27. package/src/truefoundryOwnedSessionsThreadListAdapter.test.ts +17 -0
  28. package/src/truefoundryOwnedSessionsThreadListAdapter.ts +13 -25
  29. package/src/truefoundryThreadListAdapter.test.ts +17 -9
  30. package/src/truefoundryThreadListAdapter.ts +9 -14
  31. package/src/types.ts +5 -0
  32. package/src/useTrueFoundryAgentRuntime.ts +4 -1
  33. package/dist/chunk-BRPTG6VA.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-BRPTG6VA.js";
14
+ } from "./chunk-2NLIAJJX.js";
15
15
 
16
16
  // src/useTrueFoundryAgentRuntime.ts
17
17
  import {
@@ -1892,9 +1892,11 @@ function projectHistoryTurns(snapshot, options) {
1892
1892
  const messages = [];
1893
1893
  let lastAssistantIndex;
1894
1894
  let groupRootIds = [];
1895
+ let sandboxId;
1895
1896
  for (let turnIndex = 0; turnIndex < snapshot.turns.length; turnIndex++) {
1896
1897
  const record = snapshot.turns[turnIndex];
1897
1898
  const turnRootIds = record.rootModelMessageIds ?? [];
1899
+ sandboxId = record.sandboxId ?? sandboxId;
1898
1900
  if (record.userText) {
1899
1901
  groupRootIds = [...turnRootIds];
1900
1902
  } else {
@@ -1932,7 +1934,7 @@ function projectHistoryTurns(snapshot, options) {
1932
1934
  const custom = {
1933
1935
  ...baseCustom,
1934
1936
  turnId: record.id,
1935
- ...record.sandboxId != null ? { sandboxId: record.sandboxId } : {}
1937
+ ...sandboxId != null ? { sandboxId } : {}
1936
1938
  };
1937
1939
  if (record.userText) {
1938
1940
  messages.push(
@@ -2378,7 +2380,11 @@ function turnStreamUpdateToAssistantMessage(turnId, update, existing, options) {
2378
2380
  unstable_annotations: [],
2379
2381
  unstable_data: [],
2380
2382
  steps: [],
2381
- custom: { ...update.metadata?.custom, turnId }
2383
+ custom: {
2384
+ ...existing?.role === "assistant" ? existing.metadata.custom : {},
2385
+ ...update.metadata?.custom,
2386
+ turnId
2387
+ }
2382
2388
  }
2383
2389
  };
2384
2390
  }
@@ -2415,6 +2421,13 @@ function createDraftSessionBridge(server) {
2415
2421
  };
2416
2422
  }
2417
2423
 
2424
+ // src/sessionListStartTimestamp.ts
2425
+ function sessionListStartTimestamp() {
2426
+ const start = /* @__PURE__ */ new Date();
2427
+ start.setFullYear(start.getFullYear() - 1);
2428
+ return start.toISOString();
2429
+ }
2430
+
2418
2431
  // src/draft/agentSpec.ts
2419
2432
  function mergeAgentSpec(base, update) {
2420
2433
  const { model: modelUpdate, ...rest } = update;
@@ -2436,33 +2449,50 @@ function draftSessionTitle(draft) {
2436
2449
  return draft.title ?? draft.agentSpec.model.name;
2437
2450
  }
2438
2451
 
2439
- // src/sessionListStartTimestamp.ts
2440
- function sessionListStartTimestamp() {
2441
- const start = /* @__PURE__ */ new Date();
2442
- start.setFullYear(start.getFullYear() - 1);
2443
- return start.toISOString();
2452
+ // src/sessionThreadMetadata.ts
2453
+ function sessionDisplayTitle(session, defaultAgentSpec) {
2454
+ if (session.isMutable) {
2455
+ const agentSpec = session.agentSpec ?? defaultAgentSpec;
2456
+ if (agentSpec != null) {
2457
+ return draftSessionTitle({
2458
+ title: session.title,
2459
+ agentSpec
2460
+ });
2461
+ }
2462
+ }
2463
+ return session.title ?? session.agentName ?? session.id;
2464
+ }
2465
+ function sessionToThreadMetadata(session, title) {
2466
+ return {
2467
+ status: "regular",
2468
+ remoteId: session.id,
2469
+ title,
2470
+ lastMessageAt: new Date(session.updatedAt),
2471
+ custom: {
2472
+ isMutable: session.isMutable,
2473
+ ...session.agentName != null ? { agentName: session.agentName } : {}
2474
+ }
2475
+ };
2444
2476
  }
2445
2477
 
2446
2478
  // src/draft/truefoundryDraftThreadListAdapter.ts
2447
2479
  var THREAD_LIST_PAGE_SIZE = 20;
2448
2480
  function createTrueFoundryDraftThreadListAdapter(options) {
2449
- const { server, defaultAgentSpec, getAgentSpec } = options;
2481
+ const { server, defaultAgentSpec, getAgentSpec, listSessionsAgentId } = options;
2450
2482
  return {
2451
2483
  async list({ after } = {}) {
2452
2484
  const page = await server.listSessions({
2485
+ ...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
2453
2486
  limit: THREAD_LIST_PAGE_SIZE,
2454
2487
  pageToken: after,
2455
2488
  startTimestamp: sessionListStartTimestamp()
2456
2489
  });
2457
- const threads = page.data.filter((session) => session.isMutable).map((draft) => ({
2458
- status: "regular",
2459
- remoteId: draft.id,
2460
- title: draftSessionTitle({
2461
- title: draft.title,
2462
- agentSpec: draft.agentSpec ?? defaultAgentSpec
2463
- }),
2464
- lastMessageAt: new Date(draft.updatedAt)
2465
- }));
2490
+ const threads = page.data.map(
2491
+ (session) => sessionToThreadMetadata(
2492
+ session,
2493
+ sessionDisplayTitle(session, defaultAgentSpec)
2494
+ )
2495
+ );
2466
2496
  return {
2467
2497
  threads,
2468
2498
  nextCursor: page.nextPageToken ?? void 0
@@ -2476,15 +2506,10 @@ function createTrueFoundryDraftThreadListAdapter(options) {
2476
2506
  },
2477
2507
  async fetch(remoteId) {
2478
2508
  const draft = await server.getSession({ sessionId: remoteId });
2479
- return {
2480
- status: "regular",
2481
- remoteId: draft.id,
2482
- title: draftSessionTitle({
2483
- title: draft.title,
2484
- agentSpec: draft.agentSpec ?? defaultAgentSpec
2485
- }),
2486
- lastMessageAt: new Date(draft.updatedAt)
2487
- };
2509
+ return sessionToThreadMetadata(
2510
+ draft,
2511
+ sessionDisplayTitle(draft, defaultAgentSpec)
2512
+ );
2488
2513
  },
2489
2514
  async rename() {
2490
2515
  },
@@ -2536,21 +2561,18 @@ function getSession(server, sessionId) {
2536
2561
  // src/truefoundryThreadListAdapter.ts
2537
2562
  var THREAD_LIST_PAGE_SIZE2 = 20;
2538
2563
  function createTrueFoundryThreadListAdapter(options) {
2539
- const { server, agentName } = options;
2564
+ const { server, agentName, listSessionsAgentId } = options;
2540
2565
  return {
2541
2566
  async list({ after } = {}) {
2542
2567
  const page = await server.listSessions({
2543
- agentName,
2568
+ ...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
2544
2569
  limit: THREAD_LIST_PAGE_SIZE2,
2545
2570
  pageToken: after,
2546
2571
  startTimestamp: sessionListStartTimestamp()
2547
2572
  });
2548
- const threads = page.data.map((session) => ({
2549
- status: "regular",
2550
- remoteId: session.id,
2551
- title: session.title ?? void 0,
2552
- lastMessageAt: new Date(session.updatedAt)
2553
- }));
2573
+ const threads = page.data.map(
2574
+ (session) => sessionToThreadMetadata(session, session.title ?? void 0)
2575
+ );
2554
2576
  return {
2555
2577
  threads,
2556
2578
  nextCursor: page.nextPageToken ?? void 0
@@ -2562,12 +2584,7 @@ function createTrueFoundryThreadListAdapter(options) {
2562
2584
  },
2563
2585
  async fetch(remoteId) {
2564
2586
  const session = await getSession(server, remoteId);
2565
- return {
2566
- status: "regular",
2567
- remoteId: session.id,
2568
- title: session.title ?? void 0,
2569
- lastMessageAt: new Date(session.updatedAt)
2570
- };
2587
+ return sessionToThreadMetadata(session, session.title ?? void 0);
2571
2588
  },
2572
2589
  async rename() {
2573
2590
  },
@@ -3926,20 +3943,23 @@ function useTrueFoundryAgentRuntime(options) {
3926
3943
  );
3927
3944
  const agentMode = agent.mode;
3928
3945
  const namedAgentName = agent.mode === "named" ? agent.agentName : void 0;
3946
+ const listSessionsAgentId = resolved.listSessionsAgentId;
3929
3947
  const threadListAdapter = useMemo3(() => {
3930
3948
  if (agentMode === "draft") {
3931
3949
  const draftAgent = agent;
3932
3950
  return createTrueFoundryDraftThreadListAdapter({
3933
3951
  server,
3934
3952
  defaultAgentSpec: draftAgent.defaultAgentSpec,
3935
- getAgentSpec: () => pendingAgentSpecRef.current ?? draftAgent.defaultAgentSpec
3953
+ getAgentSpec: () => pendingAgentSpecRef.current ?? draftAgent.defaultAgentSpec,
3954
+ listSessionsAgentId
3936
3955
  });
3937
3956
  }
3938
3957
  return createTrueFoundryThreadListAdapter({
3939
3958
  server,
3940
- agentName: namedAgentName
3959
+ agentName: namedAgentName,
3960
+ listSessionsAgentId
3941
3961
  });
3942
- }, [agentMode, namedAgentName, server]);
3962
+ }, [agentMode, namedAgentName, listSessionsAgentId, server]);
3943
3963
  return useRemoteThreadListRuntime({
3944
3964
  allowNesting: true,
3945
3965
  adapter: threadListAdapter,
@@ -3952,30 +3972,19 @@ function useTrueFoundryAgentRuntime(options) {
3952
3972
 
3953
3973
  // src/truefoundryOwnedSessionsThreadListAdapter.ts
3954
3974
  var THREAD_LIST_PAGE_SIZE3 = 20;
3955
- function ownedSessionTitle(session) {
3956
- if (session.isMutable && session.agentSpec != null) {
3957
- return draftSessionTitle({
3958
- title: session.title,
3959
- agentSpec: session.agentSpec
3960
- });
3961
- }
3962
- return session.title ?? session.agentName ?? session.id;
3963
- }
3964
3975
  function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
3965
- const { server } = options;
3976
+ const { server, listSessionsAgentId } = options;
3966
3977
  return {
3967
3978
  async list({ after } = {}) {
3968
3979
  const page = await server.listSessions({
3980
+ ...listSessionsAgentId != null ? { agentId: listSessionsAgentId } : {},
3969
3981
  limit: THREAD_LIST_PAGE_SIZE3,
3970
3982
  pageToken: after,
3971
3983
  startTimestamp: sessionListStartTimestamp()
3972
3984
  });
3973
- const threads = page.data.map((session) => ({
3974
- status: "regular",
3975
- remoteId: session.id,
3976
- title: ownedSessionTitle(session),
3977
- lastMessageAt: new Date(session.updatedAt)
3978
- }));
3985
+ const threads = page.data.map(
3986
+ (session) => sessionToThreadMetadata(session, sessionDisplayTitle(session))
3987
+ );
3979
3988
  return {
3980
3989
  threads,
3981
3990
  nextCursor: page.nextPageToken ?? void 0
@@ -3988,12 +3997,7 @@ function createTrueFoundryOwnedSessionsThreadListAdapter(options) {
3988
3997
  },
3989
3998
  async fetch(remoteId) {
3990
3999
  const session = await server.getSession({ sessionId: remoteId });
3991
- return {
3992
- status: "regular",
3993
- remoteId: session.id,
3994
- title: ownedSessionTitle(session),
3995
- lastMessageAt: new Date(session.updatedAt)
3996
- };
4000
+ return sessionToThreadMetadata(session, sessionDisplayTitle(session));
3997
4001
  },
3998
4002
  async rename() {
3999
4003
  },