@sessionbus/dsh 0.1.0-pre.8 → 0.1.0-pre.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugin.cjs +11 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sessionbus/dsh",
3
- "version": "0.1.0-pre.8",
3
+ "version": "0.1.0-pre.9",
4
4
  "type": "commonjs",
5
5
  "main": "plugin.cjs",
6
6
  "exports": "./plugin.cjs",
package/plugin.cjs CHANGED
@@ -268,13 +268,14 @@ class NativeSession {
268
268
  }
269
269
 
270
270
  function identity(ctx, agent, product, groups, title) {
271
- const sessionID = String(agent?.session?.id || agent?.id || "");
271
+ const sessionID = String(agent?.session?.id || "");
272
+ if (!text(sessionID)) return;
272
273
  const cwd = agent?.session?.header?.cwd;
273
- if (!text(sessionID) || !text(cwd)) throw new Error("DSH root identity is incomplete");
274
+ if (!text(cwd)) throw new Error("DSH root identity is incomplete");
274
275
  const current = title === undefined ? ctx.sessionTitle.get(agent.session)?.title : title;
275
276
  const provider = agent.options?.provider;
276
277
  const model = agent.options?.model;
277
- return { product, session_id: sessionID, name: text(current) ? current : sessionID, groups: [...groups], info: { cwd, ...(text(provider) && text(model) ? { model: `${provider}/${model}` } : {}) } };
278
+ return { product, session_id: sessionID, ...(text(current) ? { name: current } : {}), groups: [...groups], info: { cwd, ...(text(provider) && text(model) ? { model: `${provider}/${model}` } : {}) } };
278
279
  }
279
280
 
280
281
  function createRuntime(ctx, config, dependencies, prepared) {
@@ -294,6 +295,7 @@ function createRuntime(ctx, config, dependencies, prepared) {
294
295
  if (values.mode !== "peer" || !ready || !root(agent) || peers.has(agent)) return;
295
296
  try {
296
297
  const current = identity(ctx, agent, values.product, values.groups);
298
+ if (!current) return;
297
299
  const peer = dependencies.connectPeer(current, (cancel, request) => native.deliver(cancel, request, agent), connectionEnvironment(values));
298
300
  peers.set(agent, { peer, identity: current, rehello: Promise.resolve() });
299
301
  } catch (error) { warn(error); }
@@ -307,10 +309,14 @@ function createRuntime(ctx, config, dependencies, prepared) {
307
309
  if (event.type !== "session/title") return;
308
310
  const agent = ctx.agents.get(session.id);
309
311
  const record = peers.get(agent);
310
- if (!record || agent.session !== session) return;
312
+ if (!agent || agent.session !== session) return;
313
+ if (!record) return present(agent);
311
314
  const next = identity(ctx, agent, values.product, values.groups, event.data.title);
315
+ if (!next) return;
316
+ const replace = next.session_id !== record.identity.session_id;
312
317
  record.identity = next;
313
- record.rehello = record.rehello.then(() => record.peer.rehello({ name: next.name, info: next.info })).catch(warn);
318
+ // kit rehello is (signal, name, info); a changed durable id needs a full replacement.
319
+ record.rehello = record.rehello.then(() => replace ? record.peer.replace(next) : record.peer.rehello(undefined, next.name, next.info)).catch(warn);
314
320
  }, { global: true });
315
321
  }
316
322
  const caller = (agent) => worker && native.agent === agent ? worker.caller : peers.get(agent)?.peer.caller;