@celljs/ta-channels 4.7.0 → 4.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-channels",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "description": "A pi package for Ta: agents with roles of their own and channels where the user, Ta and the agents talk; Ta builds the team for what the user wants",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -27,8 +27,8 @@
27
27
  "watch": "tsc -b -w --preserveWatchOutput"
28
28
  },
29
29
  "devDependencies": {
30
- "@celljs/ta-protocol": "4.7.0",
31
- "@celljs/ta-web": "4.7.0",
30
+ "@celljs/ta-protocol": "4.8.0",
31
+ "@celljs/ta-web": "4.8.0",
32
32
  "@types/react": "^19.3.0"
33
33
  },
34
34
  "publishConfig": {
package/web/index.js CHANGED
@@ -1331,10 +1331,14 @@ var ChannelViews;
1331
1331
  return error instanceof Error ? error.message : String(error);
1332
1332
  }
1333
1333
  ChannelViews.message = message;
1334
+ let latest;
1334
1335
  async function openAgent(context, agentId) {
1336
+ latest = agentId;
1335
1337
  const sessionId = await context.service.openAgent(agentId);
1336
1338
  context.sessions.set(agentId, sessionId);
1337
- await context.pi.switchSession(sessionId);
1339
+ if (latest === agentId) {
1340
+ await context.pi.switchSession(sessionId);
1341
+ }
1338
1342
  }
1339
1343
  ChannelViews.openAgent = openAgent;
1340
1344
  })(ChannelViews ||= {});
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
2
  import { type Agent, type ChannelMessage, ChannelsUtil, SYSTEM, USER } from './channels-util';
3
3
  import { RoomUtil } from './room';
4
- import { SidebarUtil } from './views';
4
+ import { type ChannelsContext, ChannelViews, SidebarUtil } from './views';
5
5
 
6
6
  const agent = (name: string, cwd?: string): Agent => ({ id: name, name, role: 'x', mark: 'X', cwd, createdAt: 0 });
7
7
 
@@ -25,6 +25,29 @@ describe('SidebarUtil', () => {
25
25
  expect(SidebarUtil.matches('', 'anything')).toBe(true);
26
26
  });
27
27
  });
28
+ describe('ChannelViews.openAgent', () => {
29
+ it('shows the agent clicked last, whichever session opens first', async () => {
30
+ const opening = new Map<string, (sessionId: string) => void>();
31
+ const shown: string[] = [];
32
+ const context = {
33
+ service: { openAgent: (agentId: string) => new Promise<string>(resolve => opening.set(agentId, resolve)) },
34
+ sessions: new Map<string, string>(),
35
+ pi: { switchSession: async (sessionId: string) => void shown.push(sessionId) },
36
+ } as unknown as ChannelsContext;
37
+ const first = ChannelViews.openAgent(context, 'a');
38
+ const second = ChannelViews.openAgent(context, 'b');
39
+ opening.get('b')?.('sb');
40
+ await second;
41
+ opening.get('a')?.('sa');
42
+ await first;
43
+ expect(shown).toEqual(['sb']);
44
+ expect([...context.sessions]).toEqual([
45
+ ['b', 'sb'],
46
+ ['a', 'sa'],
47
+ ]);
48
+ });
49
+ });
50
+
28
51
  describe('RoomUtil', () => {
29
52
  const at = (minutes: number) => Date.UTC(2026, 10, 10, 9) + minutes * 60000;
30
53
  const say = (id: string, author: string, minutes: number): ChannelMessage => ({ id, author, text: id, at: at(minutes) });
package/web-src/views.tsx CHANGED
@@ -93,11 +93,17 @@ export namespace ChannelViews {
93
93
  return error instanceof Error ? error.message : String(error);
94
94
  }
95
95
 
96
+ /** The agent asked for last: sessions open in any order, the last asked for is shown. */
97
+ let latest: string | undefined;
98
+
96
99
  /** Shows the session of an agent as the conversation, opened on the server if it is not. */
97
100
  export async function openAgent(context: ChannelsContext, agentId: string): Promise<void> {
101
+ latest = agentId;
98
102
  const sessionId = await context.service.openAgent(agentId);
99
103
  context.sessions.set(agentId, sessionId);
100
- await context.pi.switchSession(sessionId);
104
+ if (latest === agentId) {
105
+ await context.pi.switchSession(sessionId);
106
+ }
101
107
  }
102
108
  }
103
109