@fitchmultz/pi-subagents 0.47.0 → 0.48.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/CHANGELOG.md +15 -3
- package/dist/extension/build-info.js +1 -1
- package/dist/pi-intercom/bridge-broadcast.js +60 -0
- package/dist/pi-intercom/bridge-catalog.js +372 -0
- package/dist/pi-intercom/bridge-config.js +14 -2
- package/dist/pi-intercom/bridge-control.js +104 -0
- package/dist/pi-intercom/bridge-groups.js +135 -0
- package/dist/pi-intercom/bridge-http.js +8 -1
- package/dist/pi-intercom/bridge-launch-journal.js +84 -0
- package/dist/pi-intercom/bridge-launch-policy.js +71 -5
- package/dist/pi-intercom/bridge-launch.js +186 -76
- package/dist/pi-intercom/bridge-operations.js +127 -0
- package/dist/pi-intercom/bridge-protocol.js +7 -0
- package/dist/pi-intercom/bridge-routes.js +171 -22
- package/dist/pi-intercom/bridge-rpc-process.js +43 -15
- package/dist/pi-intercom/bridge-session.js +24 -22
- package/dist/pi-intercom/bridge-target.js +22 -0
- package/dist/pi-intercom/bridge.js +29 -37
- package/dist/pi-intercom/broker/client.js +1 -0
- package/dist/pi-intercom/connection.js +2 -3
- package/dist/pi-intercom/inbound.js +2 -4
- package/dist/pi-intercom/index.js +7 -1
- package/dist/pi-intercom/native-control-auth.js +80 -0
- package/dist/pi-intercom/native-control-protocol.js +111 -0
- package/dist/pi-intercom/native-control.js +130 -0
- package/dist/pi-intercom/saved-transcript.js +135 -0
- package/dist/pi-intercom/session-targets.js +3 -0
- package/dist/pi-intercom/transcript.js +175 -0
- package/docs/intercom-bridge.md +285 -175
- package/docs/intercom.md +1 -1
- package/docs/reference.md +1 -1
- package/package.json +1 -1
- package/scripts/intercom-remote.mjs +176 -35
- package/src/pi-intercom/bridge-broadcast.ts +70 -0
- package/src/pi-intercom/bridge-catalog.ts +489 -0
- package/src/pi-intercom/bridge-config.ts +19 -2
- package/src/pi-intercom/bridge-control.ts +179 -0
- package/src/pi-intercom/bridge-groups.ts +169 -0
- package/src/pi-intercom/bridge-http.ts +15 -1
- package/src/pi-intercom/bridge-launch-journal.ts +122 -0
- package/src/pi-intercom/bridge-launch-policy.ts +88 -7
- package/src/pi-intercom/bridge-launch.ts +296 -107
- package/src/pi-intercom/bridge-operations.ts +169 -0
- package/src/pi-intercom/bridge-protocol.ts +8 -0
- package/src/pi-intercom/bridge-routes.ts +254 -42
- package/src/pi-intercom/bridge-rpc-process.ts +53 -16
- package/src/pi-intercom/bridge-session.ts +35 -36
- package/src/pi-intercom/bridge-target.ts +35 -0
- package/src/pi-intercom/bridge.ts +30 -47
- package/src/pi-intercom/broker/client.ts +3 -0
- package/src/pi-intercom/connection.ts +2 -3
- package/src/pi-intercom/inbound.ts +2 -4
- package/src/pi-intercom/index.ts +7 -1
- package/src/pi-intercom/native-control-auth.ts +89 -0
- package/src/pi-intercom/native-control-protocol.ts +180 -0
- package/src/pi-intercom/native-control.ts +160 -0
- package/src/pi-intercom/saved-transcript.ts +175 -0
- package/src/pi-intercom/session-targets.ts +4 -0
- package/src/pi-intercom/transcript.ts +226 -0
- package/src/pi-intercom/types.ts +2 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isRecord, isUnknownArray } from "../shared/unknown.js";
|
|
2
|
+
import { Fault, label, object } from "./bridge-protocol.js";
|
|
3
|
+
const SCAN_LIMIT = 1024;
|
|
4
|
+
export function transcriptOptions(value = {}) {
|
|
5
|
+
const input = object(value, ["limit", "maxBytes", "cursor"]);
|
|
6
|
+
const limit = integer(input.limit, 50, 1, 100);
|
|
7
|
+
const maxBytes = integer(input.maxBytes, 65536, 256, 131072);
|
|
8
|
+
const cursor = input.cursor === undefined ? undefined : label(input.cursor, "cursor", 512);
|
|
9
|
+
return { limit, maxBytes, cursor };
|
|
10
|
+
}
|
|
11
|
+
function integer(value, fallback, min, max) {
|
|
12
|
+
const result = value === undefined ? fallback : value;
|
|
13
|
+
if (typeof result !== "number" || !Number.isInteger(result) || result < min || result > max) {
|
|
14
|
+
throw new Fault(400, "invalid_input", `Transcript limit must be an integer from ${min} to ${max}.`);
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function textualContent(content) {
|
|
19
|
+
if (typeof content === "string") {
|
|
20
|
+
return { text: content, truncated: false };
|
|
21
|
+
}
|
|
22
|
+
if (!isUnknownArray(content)) {
|
|
23
|
+
return { text: "", truncated: false };
|
|
24
|
+
}
|
|
25
|
+
const pieces = [];
|
|
26
|
+
let remaining = 131073;
|
|
27
|
+
let truncated = content.length > 4096;
|
|
28
|
+
for (const part of content.slice(0, 4096)) {
|
|
29
|
+
if (remaining <= 0) {
|
|
30
|
+
truncated = true;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (isRecord(part) && part.type === "text" && typeof part.text === "string") {
|
|
34
|
+
const text = part.text.slice(0, remaining);
|
|
35
|
+
pieces.push(text);
|
|
36
|
+
truncated ||= text.length < part.text.length;
|
|
37
|
+
remaining -= text.length + 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { text: pieces.join("\n"), truncated };
|
|
41
|
+
}
|
|
42
|
+
function visible(entry) {
|
|
43
|
+
if (entry.type === "custom_message") {
|
|
44
|
+
return entry.display ? { role: "custom", ...textualContent(entry.content) } : undefined;
|
|
45
|
+
}
|
|
46
|
+
if (entry.type !== "message") {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const message = entry.message;
|
|
50
|
+
if (message.role === "bashExecution") {
|
|
51
|
+
return {
|
|
52
|
+
role: "toolResult",
|
|
53
|
+
text: message.output,
|
|
54
|
+
truncated: nativeTruncation(message.truncated),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (!["user", "assistant", "toolResult", "custom"].includes(message.role)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (message.role === "custom" && !message.display) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return "content" in message
|
|
64
|
+
? { role: message.role, ...textualContent(message.content) }
|
|
65
|
+
: undefined;
|
|
66
|
+
}
|
|
67
|
+
function nativeTruncation(value) {
|
|
68
|
+
// Older saved bash entries may predate the native boolean field.
|
|
69
|
+
return value === true;
|
|
70
|
+
}
|
|
71
|
+
function boundedText(text, budget) {
|
|
72
|
+
// Slice before UTF-8 encoding to avoid copying arbitrarily large live tool output.
|
|
73
|
+
const bytes = Buffer.from(text.slice(0, budget));
|
|
74
|
+
if (bytes.length <= budget) {
|
|
75
|
+
return bytes.toString();
|
|
76
|
+
}
|
|
77
|
+
let end = budget;
|
|
78
|
+
while (end > 0 && (bytes[end] & 0xc0) === 0x80) {
|
|
79
|
+
end -= 1;
|
|
80
|
+
}
|
|
81
|
+
return bytes.subarray(0, end).toString();
|
|
82
|
+
}
|
|
83
|
+
function startId(manager, leaf, cursor) {
|
|
84
|
+
if (cursor === undefined) {
|
|
85
|
+
return { id: leaf, scanned: 0 };
|
|
86
|
+
}
|
|
87
|
+
let raw;
|
|
88
|
+
try {
|
|
89
|
+
raw = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw new Fault(400, "invalid_cursor", "Invalid transcript cursor.");
|
|
93
|
+
}
|
|
94
|
+
const data = object(raw, ["leaf", "before"]);
|
|
95
|
+
if (data.leaf !== leaf) {
|
|
96
|
+
throw new Fault(409, "branch_changed", "Active branch changed; request a new transcript page.");
|
|
97
|
+
}
|
|
98
|
+
const before = label(data.before, "cursor entry", 128);
|
|
99
|
+
let id = leaf;
|
|
100
|
+
for (let scanned = 0; id !== null && scanned < SCAN_LIMIT; scanned += 1) {
|
|
101
|
+
if (id === before) {
|
|
102
|
+
return { id, scanned };
|
|
103
|
+
}
|
|
104
|
+
id = manager.getEntry(id)?.parentId ?? null;
|
|
105
|
+
}
|
|
106
|
+
throw new Fault(400, "invalid_cursor", "Cursor is outside the bounded active branch.");
|
|
107
|
+
}
|
|
108
|
+
/** Finalized textual output on the selected branch; never builds full history/context. */
|
|
109
|
+
export function readLiveTranscript(manager, input = {}) {
|
|
110
|
+
const options = transcriptOptions(input);
|
|
111
|
+
const leaf = manager.getLeafId();
|
|
112
|
+
const start = startId(manager, leaf, options.cursor);
|
|
113
|
+
let id = start.id;
|
|
114
|
+
let scanned = start.scanned;
|
|
115
|
+
const records = [];
|
|
116
|
+
let bytes = 0;
|
|
117
|
+
let textTruncated = false;
|
|
118
|
+
while (id !== null && scanned < SCAN_LIMIT) {
|
|
119
|
+
scanned += 1;
|
|
120
|
+
const entry = manager.getEntry(id);
|
|
121
|
+
if (!entry) {
|
|
122
|
+
textTruncated = true;
|
|
123
|
+
id = null;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
const record = transcriptRecord(entry, options.maxBytes - bytes);
|
|
127
|
+
if (record !== undefined) {
|
|
128
|
+
records.push(record);
|
|
129
|
+
bytes += Buffer.byteLength(record.text);
|
|
130
|
+
textTruncated ||= record.truncated;
|
|
131
|
+
}
|
|
132
|
+
id = entry.parentId;
|
|
133
|
+
if (records.length >= options.limit || bytes >= options.maxBytes) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return transcriptPage(manager, {
|
|
138
|
+
leaf,
|
|
139
|
+
records,
|
|
140
|
+
bytes,
|
|
141
|
+
textTruncated,
|
|
142
|
+
id,
|
|
143
|
+
scanLimitReached: scanned >= SCAN_LIMIT && id !== null,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function transcriptRecord(entry, budget) {
|
|
147
|
+
const output = visible(entry);
|
|
148
|
+
if (output === undefined || output.text.length === 0) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const text = boundedText(output.text, budget);
|
|
152
|
+
return {
|
|
153
|
+
id: entry.id,
|
|
154
|
+
timestamp: entry.timestamp,
|
|
155
|
+
role: output.role,
|
|
156
|
+
text,
|
|
157
|
+
truncated: text !== output.text || output.truncated,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function transcriptPage(manager, state) {
|
|
161
|
+
const { leaf, records, bytes, textTruncated, id, scanLimitReached } = state;
|
|
162
|
+
return {
|
|
163
|
+
sessionId: manager.getSessionId(),
|
|
164
|
+
leafId: leaf,
|
|
165
|
+
records: records.reverse(),
|
|
166
|
+
bytes,
|
|
167
|
+
truncated: id !== null || textTruncated,
|
|
168
|
+
scanLimitReached,
|
|
169
|
+
...(id !== null && !scanLimitReached
|
|
170
|
+
? { cursor: Buffer.from(JSON.stringify({ leaf, before: id })).toString("base64url") }
|
|
171
|
+
: {}),
|
|
172
|
+
finalizedOnly: true,
|
|
173
|
+
streaming: "unavailable",
|
|
174
|
+
};
|
|
175
|
+
}
|