@hallohuman/hightea 0.1.15 → 0.1.17
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/dist/bin.js +1 -1
- package/dist/plugin/plugin.json +1 -1
- package/dist/plugin/plugin.mjs +103 -16
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
// package.json
|
|
6
6
|
var package_default = {
|
|
7
7
|
name: "@hallohuman/hightea",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.17",
|
|
9
9
|
description: "The Hightea command line: join this machine to a Hightea workspace as a host.",
|
|
10
10
|
publishConfig: {
|
|
11
11
|
access: "public"
|
package/dist/plugin/plugin.json
CHANGED
package/dist/plugin/plugin.mjs
CHANGED
|
@@ -10172,7 +10172,7 @@ async function listHostServices(options) {
|
|
|
10172
10172
|
} finally {
|
|
10173
10173
|
if (subscribed) {
|
|
10174
10174
|
try {
|
|
10175
|
-
|
|
10175
|
+
options.peer.notify("unsubscribe", { channel: SERVICES_CHANNEL });
|
|
10176
10176
|
} catch (error) {
|
|
10177
10177
|
options.log.error(`hightea-pipe: dropping the services subscription failed: ${error instanceof Error ? error.name : typeof error}`);
|
|
10178
10178
|
}
|
|
@@ -10219,7 +10219,7 @@ async function listHostAgents(options) {
|
|
|
10219
10219
|
const shown = rows.filter((row) => typeof row.id === "string" && providers.has(row.id));
|
|
10220
10220
|
shown.sort((left, right) => String(left.id) < String(right.id) ? -1 : String(left.id) > String(right.id) ? 1 : 0);
|
|
10221
10221
|
try {
|
|
10222
|
-
|
|
10222
|
+
options.peer.notify("unsubscribe", { channel: AGENTS_CHANNEL });
|
|
10223
10223
|
} catch (error) {
|
|
10224
10224
|
options.log.error(`hightea-pipe: dropping the agents subscription failed: ${error instanceof Error ? error.name : typeof error}`);
|
|
10225
10225
|
}
|
|
@@ -10710,6 +10710,98 @@ var PipeStateSchema = object({
|
|
|
10710
10710
|
dispatched: array(tuple([string2().min(1), array(string2().min(1))])),
|
|
10711
10711
|
lastStatus: array(tuple([string2().min(1), HostToCloudFrameSchema]))
|
|
10712
10712
|
}).strict();
|
|
10713
|
+
var LegacyHostToCloudFrameSchema = object({
|
|
10714
|
+
event: _enum(["session.created", "turn.started", "turn.finished", "turn.error"]),
|
|
10715
|
+
houseId: string2().min(1),
|
|
10716
|
+
deliveryId: string2().min(1),
|
|
10717
|
+
sessionId: string2().min(1),
|
|
10718
|
+
chatId: string2().min(1),
|
|
10719
|
+
turnId: string2().min(1).optional(),
|
|
10720
|
+
turnState: _enum(["created", "running", "finished", "error"]),
|
|
10721
|
+
statusCode: string2().min(1).max(64),
|
|
10722
|
+
errorCode: _enum(BOUNDED_ERROR_CODES).optional(),
|
|
10723
|
+
errorDetail: string2().max(256).optional()
|
|
10724
|
+
}).strict();
|
|
10725
|
+
var LEGACY_EVENTS = {
|
|
10726
|
+
"session.created": "session/ready",
|
|
10727
|
+
"turn.started": "chat/turnStarted",
|
|
10728
|
+
"turn.finished": "chat/turnComplete",
|
|
10729
|
+
"turn.error": "x-hh/turnFailed"
|
|
10730
|
+
};
|
|
10731
|
+
function upgradeLegacyFrame(frame) {
|
|
10732
|
+
return {
|
|
10733
|
+
event: LEGACY_EVENTS[frame.event],
|
|
10734
|
+
channel: frame.event === "session.created" ? frame.sessionId : frame.chatId,
|
|
10735
|
+
workspaceId: frame.houseId,
|
|
10736
|
+
deliveryId: frame.deliveryId,
|
|
10737
|
+
session: frame.sessionId,
|
|
10738
|
+
chat: frame.chatId,
|
|
10739
|
+
...frame.turnId === undefined ? {} : { turnId: frame.turnId },
|
|
10740
|
+
turnState: frame.turnState,
|
|
10741
|
+
statusCode: frame.statusCode,
|
|
10742
|
+
...frame.errorCode === undefined ? {} : { errorCode: frame.errorCode },
|
|
10743
|
+
...frame.errorDetail === undefined ? {} : { errorDetail: frame.errorDetail }
|
|
10744
|
+
};
|
|
10745
|
+
}
|
|
10746
|
+
var PipeStateRecordSchema = object({
|
|
10747
|
+
sessions: array(tuple([string2().min(1), object({ sessionUri: string2().min(1), chatUri: string2().min(1).optional() }).strict()])),
|
|
10748
|
+
dispatched: array(tuple([string2().min(1), array(string2().min(1))])),
|
|
10749
|
+
lastStatus: array(unknown())
|
|
10750
|
+
}).strict();
|
|
10751
|
+
var statusKey = (frame) => frame.turnId === undefined ? frame.deliveryId : attemptKey(frame.deliveryId, frame.turnId);
|
|
10752
|
+
function describeIssues(error) {
|
|
10753
|
+
const shown = error.issues.slice(0, 3).map((issue) => `${issue.path.join(".") || "(record)"} ${issue.message}`);
|
|
10754
|
+
return `${shown.join("; ")}${error.issues.length > 3 ? `; and ${error.issues.length - 3} more` : ""}`;
|
|
10755
|
+
}
|
|
10756
|
+
function frameKind(entry) {
|
|
10757
|
+
const frame = Array.isArray(entry) ? entry[1] : entry;
|
|
10758
|
+
if (typeof frame === "object" && frame !== null) {
|
|
10759
|
+
const event = frame.event;
|
|
10760
|
+
if (typeof event === "string")
|
|
10761
|
+
return `event=${event}`;
|
|
10762
|
+
}
|
|
10763
|
+
return Array.isArray(entry) ? `a frame of ${typeof frame}` : `${entry === null ? "null" : typeof entry}`;
|
|
10764
|
+
}
|
|
10765
|
+
function readPipeState(loaded, log) {
|
|
10766
|
+
const record = PipeStateRecordSchema.safeParse(loaded);
|
|
10767
|
+
if (!record.success)
|
|
10768
|
+
throw new Error(`ahp-host: invalid durable state: ${describeIssues(record.error)}`);
|
|
10769
|
+
const lastStatus = [];
|
|
10770
|
+
let upgraded = 0;
|
|
10771
|
+
let dropped = 0;
|
|
10772
|
+
record.data.lastStatus.forEach((entry, index) => {
|
|
10773
|
+
const pair = tuple([string2().min(1), unknown()]).safeParse(entry);
|
|
10774
|
+
const key = pair.success ? pair.data[0] : "";
|
|
10775
|
+
const asCurrent = pair.success ? HostToCloudFrameSchema.safeParse(pair.data[1]) : undefined;
|
|
10776
|
+
const legacy = pair.success && asCurrent?.success === false ? LegacyHostToCloudFrameSchema.safeParse(pair.data[1]) : undefined;
|
|
10777
|
+
const frame = asCurrent?.success === true ? asCurrent.data : legacy?.success === true ? upgradeLegacyFrame(legacy.data) : undefined;
|
|
10778
|
+
if (frame === undefined) {
|
|
10779
|
+
dropped += 1;
|
|
10780
|
+
const legacyShaped = pair.success && typeof pair.data[1] === "object" && pair.data[1] !== null && "houseId" in pair.data[1];
|
|
10781
|
+
const reason = legacy?.success === false && legacyShaped ? `pre-0.1.11 shape: ${describeIssues(legacy.error)}` : asCurrent?.success === false ? describeIssues(asCurrent.error) : "not a [key, frame] entry";
|
|
10782
|
+
log.error(`ahp-host: dropped durable status frame lastStatus[${index}] (${frameKind(entry)}): ${reason}`);
|
|
10783
|
+
return;
|
|
10784
|
+
}
|
|
10785
|
+
if (statusKey(frame) !== key) {
|
|
10786
|
+
dropped += 1;
|
|
10787
|
+
log.error(`ahp-host: dropped durable status frame lastStatus[${index}] (event=${frame.event}): its key names a different delivery or turn`);
|
|
10788
|
+
return;
|
|
10789
|
+
}
|
|
10790
|
+
if (asCurrent?.success !== true) {
|
|
10791
|
+
upgraded += 1;
|
|
10792
|
+
log.error(`ahp-host: upgraded durable status frame lastStatus[${index}] (${frameKind(entry)} -> event=${frame.event}) from the pre-0.1.11 shape`);
|
|
10793
|
+
}
|
|
10794
|
+
lastStatus.push([key, frame]);
|
|
10795
|
+
});
|
|
10796
|
+
if (upgraded > 0 || dropped > 0) {
|
|
10797
|
+
log.error(`ahp-host: durable state repaired: ${upgraded} status frame(s) upgraded from the pre-0.1.11 shape, ${dropped} dropped; the pipe starts and rewrites the state`);
|
|
10798
|
+
}
|
|
10799
|
+
const sessions = record.data.sessions.map(([key, session]) => [key, {
|
|
10800
|
+
sessionUri: session.sessionUri,
|
|
10801
|
+
...session.chatUri === undefined ? {} : { chatUri: session.chatUri }
|
|
10802
|
+
}]);
|
|
10803
|
+
return { sessions, dispatched: record.data.dispatched, lastStatus };
|
|
10804
|
+
}
|
|
10713
10805
|
|
|
10714
10806
|
class WakePipe {
|
|
10715
10807
|
vault = new ActiveTurnTokenVault;
|
|
@@ -10753,10 +10845,7 @@ class WakePipe {
|
|
|
10753
10845
|
this.#ready();
|
|
10754
10846
|
return;
|
|
10755
10847
|
}
|
|
10756
|
-
const
|
|
10757
|
-
if (!parsed.success)
|
|
10758
|
-
throw new Error("ahp-host: invalid durable state");
|
|
10759
|
-
const saved = parsed.data;
|
|
10848
|
+
const saved = readPipeState(loaded, this.options.log);
|
|
10760
10849
|
for (const [key, session] of saved.sessions) {
|
|
10761
10850
|
let chatUri;
|
|
10762
10851
|
try {
|
|
@@ -11103,6 +11192,7 @@ class WakePipe {
|
|
|
11103
11192
|
sessionUri: mapped.sessionUri,
|
|
11104
11193
|
chatUri: mapped.chatUri,
|
|
11105
11194
|
turnId,
|
|
11195
|
+
startedAtMs: Date.now(),
|
|
11106
11196
|
clientSeq: dispatchClientSeq(frame),
|
|
11107
11197
|
cancelled: false,
|
|
11108
11198
|
stopReason: undefined,
|
|
@@ -11223,7 +11313,7 @@ class WakePipe {
|
|
|
11223
11313
|
this.peer.notify("dispatchAction", {
|
|
11224
11314
|
channel: turn.chatUri,
|
|
11225
11315
|
clientSeq: ++this.#seq,
|
|
11226
|
-
action: { type: "chat/turnCancelled", turnId: turn.turnId }
|
|
11316
|
+
action: { type: "chat/turnCancelled", turnId: turn.turnId, duration: Math.max(0, Date.now() - turn.startedAtMs) }
|
|
11227
11317
|
});
|
|
11228
11318
|
return;
|
|
11229
11319
|
}
|
|
@@ -11322,7 +11412,7 @@ var mappingSchema = object({
|
|
|
11322
11412
|
sessionUri: string2().regex(SESSION_URI)
|
|
11323
11413
|
}).strict();
|
|
11324
11414
|
var mappingId = (key) => `session-${createHash2("sha256").update(key).digest("hex").slice(0, 32)}`;
|
|
11325
|
-
function recordsPipeStore(records, owner, sessionOwner) {
|
|
11415
|
+
function recordsPipeStore(records, owner, sessionOwner, log) {
|
|
11326
11416
|
const known = new Map;
|
|
11327
11417
|
const readMapping = (raw) => {
|
|
11328
11418
|
const parsed = mappingSchema.safeParse(raw);
|
|
@@ -11382,13 +11472,10 @@ function recordsPipeStore(records, owner, sessionOwner) {
|
|
|
11382
11472
|
throw new Error("ahp-host: invalid durable state record");
|
|
11383
11473
|
}
|
|
11384
11474
|
const raw = record.version === 1 ? record.state : typeof record.state === "object" && record.state !== null ? { sessions: [], ...record.state } : record.state;
|
|
11385
|
-
const
|
|
11386
|
-
if (
|
|
11387
|
-
throw new Error("ahp-host: invalid durable state");
|
|
11388
|
-
state =
|
|
11389
|
-
sessionUri: session.sessionUri,
|
|
11390
|
-
...session.chatUri === undefined ? {} : { chatUri: session.chatUri }
|
|
11391
|
-
}]) };
|
|
11475
|
+
const read = readPipeState(raw, log);
|
|
11476
|
+
if (record.version === 2 && read.sessions.length !== 0)
|
|
11477
|
+
throw new Error("ahp-host: invalid durable state: a version 2 record holds no session mappings");
|
|
11478
|
+
state = read;
|
|
11392
11479
|
}
|
|
11393
11480
|
const mappings = new Map;
|
|
11394
11481
|
for (const raw of await records.list()) {
|
|
@@ -13727,7 +13814,7 @@ function applyWith(host, options, seams) {
|
|
|
13727
13814
|
tools: options.mcpUrl === undefined ? [] : hostTools,
|
|
13728
13815
|
startSession: (wanted, named) => host.startSession(wanted, named),
|
|
13729
13816
|
log: host.log,
|
|
13730
|
-
store: recordsPipeStore(host.records("hightea"), owner, (uri) => host.sessionOwner(uri)),
|
|
13817
|
+
store: recordsPipeStore(host.records("hightea"), owner, (uri) => host.sessionOwner(uri), host.log),
|
|
13731
13818
|
admitTurn: (meta, token) => checks.admit(meta, token),
|
|
13732
13819
|
...pluginVersion === undefined ? {} : {
|
|
13733
13820
|
handshake: { plugin: { name, version: pluginVersion }, ahpd: options.ahpdVersion }
|