@open-artifacts/bus 0.133.0 → 0.134.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/assets/oa-bus.ts +48 -2
- package/dist/index.js +1348 -760
- package/package.json +1 -1
package/assets/oa-bus.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { StringDecoder } from "node:string_decoder";
|
|
|
11
11
|
type Json = Record<string, unknown>;
|
|
12
12
|
|
|
13
13
|
/** The IPC marker (CONTRACT.md): the package version, stamped by the CLI's bundler. */
|
|
14
|
-
const CLIENT_VERSION = "0.
|
|
14
|
+
const CLIENT_VERSION = "0.134.0";
|
|
15
15
|
|
|
16
16
|
type Frame = Json & { type: string; id: string };
|
|
17
17
|
type Ctx = {
|
|
@@ -750,6 +750,8 @@ type Link = {
|
|
|
750
750
|
welcome: Frame;
|
|
751
751
|
request: (frame: Json, timeoutMs?: number) => Promise<Frame>;
|
|
752
752
|
ack: (msgId: string) => void;
|
|
753
|
+
/** #1635: tell the daemon the session's new name; false when this daemon does not take it. */
|
|
754
|
+
rename: (name: string) => boolean;
|
|
753
755
|
closed: () => boolean;
|
|
754
756
|
close: () => void;
|
|
755
757
|
};
|
|
@@ -809,6 +811,14 @@ function open(
|
|
|
809
811
|
}),
|
|
810
812
|
// Fire-and-forget: the daemon answers an ack with nothing.
|
|
811
813
|
ack: (msgId) => write({ type: "ack", id: `ack-${++seq}`, msg_id: msgId }),
|
|
814
|
+
// Only to a daemon whose welcome listed `rename`: an older one has no such frame.
|
|
815
|
+
rename: (name) => {
|
|
816
|
+
const caps = link.welcome.caps;
|
|
817
|
+
if (ended || !Array.isArray(caps) || !caps.includes("rename"))
|
|
818
|
+
return false;
|
|
819
|
+
write({ type: "rename", id: `rename-${++seq}`, name });
|
|
820
|
+
return true;
|
|
821
|
+
},
|
|
812
822
|
closed: () => ended,
|
|
813
823
|
close: () => {
|
|
814
824
|
ended = true;
|
|
@@ -892,7 +902,8 @@ function open(
|
|
|
892
902
|
proposed_name: id.name,
|
|
893
903
|
// #1295: this asset decodes away rows and the new refusals.
|
|
894
904
|
// #1525: and a config file that is pending approval.
|
|
895
|
-
|
|
905
|
+
// #1635: and may send a rename.
|
|
906
|
+
caps: ["mailbox", "pending", "rename"],
|
|
896
907
|
attest: start ? { proc_start: start } : {},
|
|
897
908
|
}),
|
|
898
909
|
);
|
|
@@ -1015,6 +1026,13 @@ export default function oaBus(pi: Pi): void {
|
|
|
1015
1026
|
}
|
|
1016
1027
|
current = l;
|
|
1017
1028
|
refusals = 0;
|
|
1029
|
+
// Renamed while this hello was in flight (#1635).
|
|
1030
|
+
if (
|
|
1031
|
+
identity.kind !== "omp" &&
|
|
1032
|
+
identity.name !== id.name &&
|
|
1033
|
+
identity.name !== identity.kind
|
|
1034
|
+
)
|
|
1035
|
+
l.rename(identity.name);
|
|
1018
1036
|
return l;
|
|
1019
1037
|
},
|
|
1020
1038
|
(e: unknown) => {
|
|
@@ -1043,6 +1061,34 @@ export default function oaBus(pi: Pi): void {
|
|
|
1043
1061
|
*/
|
|
1044
1062
|
const subagent = (ctx: Ctx | undefined) => ctx?.agent?.kind === "sub";
|
|
1045
1063
|
|
|
1064
|
+
/**
|
|
1065
|
+
* #1635: the session was renamed (/name, --name, setSessionName). One frame
|
|
1066
|
+
* per change; nothing for the fallback name. The identity carries the name,
|
|
1067
|
+
* so a reconnect's hello proposes the new one.
|
|
1068
|
+
*/
|
|
1069
|
+
const renamed = (ctx: Ctx) => {
|
|
1070
|
+
if (stopped || !identity) return;
|
|
1071
|
+
// omp titles a session itself ("auto") after its first message, and its
|
|
1072
|
+
// extension context does not say whether a name was typed by the user:
|
|
1073
|
+
// so omp never renames on the hub. (pi has no auto titles.)
|
|
1074
|
+
if (identity.kind === "omp") return;
|
|
1075
|
+
const id = identityOf(ctx);
|
|
1076
|
+
if (id.ref !== identity.ref || id.name === identity.name) return;
|
|
1077
|
+
identity = { ...identity, name: id.name };
|
|
1078
|
+
if (id.name === id.kind) return;
|
|
1079
|
+
// An open link tells the daemon now; a daemon without the cap, or no
|
|
1080
|
+
// link, learns it from the next hello.
|
|
1081
|
+
if (current && !current.closed() && current.ref === id.ref)
|
|
1082
|
+
current.rename(id.name);
|
|
1083
|
+
};
|
|
1084
|
+
pi.on("session_info_changed", (_event, ctx) => {
|
|
1085
|
+
if (!subagent(ctx)) renamed(ctx);
|
|
1086
|
+
});
|
|
1087
|
+
// A turn start checks too (cheap when unchanged); omp is skipped in renamed().
|
|
1088
|
+
pi.on("turn_start", (_event, ctx) => {
|
|
1089
|
+
if (!subagent(ctx)) renamed(ctx);
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1046
1092
|
pi.on("session_start", async (_event, ctx) => {
|
|
1047
1093
|
if (subagent(ctx)) return;
|
|
1048
1094
|
stopped = false;
|