copilotoffice 1.0.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.
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // electron/terminal/events-watcher.ts
31
+ var events_watcher_exports = {};
32
+ __export(events_watcher_exports, {
33
+ EventsWatcher: () => EventsWatcher,
34
+ formatToolStatus: () => formatToolStatus
35
+ });
36
+ module.exports = __toCommonJS(events_watcher_exports);
37
+ var fs = __toESM(require("fs"));
38
+ var path = __toESM(require("path"));
39
+ var os = __toESM(require("os"));
40
+ var EventsWatcher = class _EventsWatcher {
41
+ constructor(sessionId) {
42
+ this.fileOffset = 0;
43
+ this.lineBuffer = "";
44
+ this.watcher = null;
45
+ this.pollTimer = null;
46
+ this.fileExistsTimer = null;
47
+ this.heartbeatTimer = null;
48
+ this.callback = null;
49
+ this.stopped = false;
50
+ this.watchingFile = false;
51
+ this.initialReadComplete = false;
52
+ this.sessionId = sessionId;
53
+ this.filePath = path.join(
54
+ os.homedir(),
55
+ ".copilot",
56
+ "session-state",
57
+ sessionId,
58
+ "events.jsonl"
59
+ );
60
+ }
61
+ static {
62
+ this.POLL_INTERVAL_MS = 500;
63
+ }
64
+ static {
65
+ this.FILE_CHECK_INTERVAL_MS = 200;
66
+ }
67
+ static {
68
+ this.MAX_FILE_WAIT_MS = 6e4;
69
+ }
70
+ getSessionId() {
71
+ return this.sessionId;
72
+ }
73
+ getFilePath() {
74
+ return this.filePath;
75
+ }
76
+ start(onEvent) {
77
+ this.callback = onEvent;
78
+ this.stopped = false;
79
+ try {
80
+ fs.accessSync(this.filePath, fs.constants.F_OK);
81
+ this.startWatching();
82
+ } catch {
83
+ console.log(`[EventsWatcher] Waiting for events.jsonl: ${this.filePath}`);
84
+ const startTime = Date.now();
85
+ this.fileExistsTimer = setInterval(() => {
86
+ if (this.stopped) {
87
+ if (this.fileExistsTimer) clearInterval(this.fileExistsTimer);
88
+ return;
89
+ }
90
+ if (Date.now() - startTime > _EventsWatcher.MAX_FILE_WAIT_MS) {
91
+ console.warn(`[EventsWatcher] Timed out waiting for events.jsonl after ${_EventsWatcher.MAX_FILE_WAIT_MS / 1e3}s`);
92
+ if (this.fileExistsTimer) clearInterval(this.fileExistsTimer);
93
+ this.fileExistsTimer = null;
94
+ return;
95
+ }
96
+ try {
97
+ fs.accessSync(this.filePath, fs.constants.F_OK);
98
+ console.log(`[EventsWatcher] Found events.jsonl`);
99
+ if (this.fileExistsTimer) clearInterval(this.fileExistsTimer);
100
+ this.fileExistsTimer = null;
101
+ this.startWatching();
102
+ } catch {
103
+ }
104
+ }, _EventsWatcher.FILE_CHECK_INTERVAL_MS);
105
+ }
106
+ }
107
+ startWatching() {
108
+ console.log(`[EventsWatcher] Started watching: ${this.filePath}`);
109
+ this.readNewLines();
110
+ this.initialReadComplete = true;
111
+ try {
112
+ this.watcher = fs.watch(this.filePath, () => {
113
+ if (!this.stopped) this.readNewLines();
114
+ });
115
+ } catch (e) {
116
+ console.log(`[EventsWatcher] fs.watch failed: ${e}`);
117
+ }
118
+ try {
119
+ fs.watchFile(this.filePath, { interval: _EventsWatcher.POLL_INTERVAL_MS }, () => {
120
+ if (!this.stopped) this.readNewLines();
121
+ });
122
+ this.watchingFile = true;
123
+ } catch (e) {
124
+ console.log(`[EventsWatcher] fs.watchFile failed: ${e}`);
125
+ }
126
+ this.pollTimer = setInterval(() => {
127
+ if (!this.stopped) this.readNewLines();
128
+ }, _EventsWatcher.POLL_INTERVAL_MS);
129
+ this.heartbeatTimer = setInterval(() => {
130
+ if (!this.stopped) {
131
+ console.log(`[EventsWatcher] Heartbeat \u2014 alive, watching ${this.filePath} (offset: ${this.fileOffset})`);
132
+ }
133
+ }, 6e4);
134
+ }
135
+ /** Synchronous read — no reading guard needed, every trigger processes immediately. */
136
+ readNewLines() {
137
+ try {
138
+ const stat = fs.statSync(this.filePath);
139
+ if (stat.size <= this.fileOffset) return;
140
+ const bytesToRead = stat.size - this.fileOffset;
141
+ const buf = Buffer.alloc(bytesToRead);
142
+ const fd = fs.openSync(this.filePath, "r");
143
+ fs.readSync(fd, buf, 0, buf.length, this.fileOffset);
144
+ fs.closeSync(fd);
145
+ this.fileOffset = stat.size;
146
+ const text = this.lineBuffer + buf.toString("utf-8");
147
+ const lines = text.split("\n");
148
+ this.lineBuffer = lines.pop() || "";
149
+ let eventCount = 0;
150
+ for (const line of lines) {
151
+ if (!line.trim()) continue;
152
+ try {
153
+ const event = JSON.parse(line);
154
+ eventCount++;
155
+ if (this.callback) {
156
+ this.callback(event, !this.initialReadComplete);
157
+ }
158
+ } catch (e) {
159
+ console.log(`[EventsWatcher] Failed to parse line: ${e}`);
160
+ }
161
+ }
162
+ if (eventCount > 0) {
163
+ console.log(`[EventsWatcher] Read ${eventCount} event(s), +${bytesToRead}B, offset now ${this.fileOffset}`);
164
+ }
165
+ } catch (e) {
166
+ }
167
+ }
168
+ stop() {
169
+ this.stopped = true;
170
+ if (this.fileExistsTimer) {
171
+ clearInterval(this.fileExistsTimer);
172
+ this.fileExistsTimer = null;
173
+ }
174
+ if (this.watcher) {
175
+ this.watcher.close();
176
+ this.watcher = null;
177
+ }
178
+ if (this.watchingFile) {
179
+ try {
180
+ fs.unwatchFile(this.filePath);
181
+ } catch {
182
+ }
183
+ this.watchingFile = false;
184
+ }
185
+ if (this.pollTimer) {
186
+ clearInterval(this.pollTimer);
187
+ this.pollTimer = null;
188
+ }
189
+ if (this.heartbeatTimer) {
190
+ clearInterval(this.heartbeatTimer);
191
+ this.heartbeatTimer = null;
192
+ }
193
+ this.callback = null;
194
+ }
195
+ };
196
+ function formatToolStatus(toolName, args) {
197
+ const base = (p) => typeof p === "string" ? path.basename(p) : "";
198
+ switch (toolName) {
199
+ case "view":
200
+ return `Reading ${base(args.path)}`;
201
+ case "edit":
202
+ return `Editing ${base(args.path)}`;
203
+ case "create":
204
+ return `Creating ${base(args.path)}`;
205
+ case "powershell":
206
+ const cmd = args.command || "";
207
+ return `Running: ${cmd.length > 40 ? cmd.slice(0, 40) + "\u2026" : cmd}`;
208
+ case "glob":
209
+ return `Finding files: ${args.pattern || ""}`;
210
+ case "grep":
211
+ return `Searching: ${args.pattern || ""}`;
212
+ case "web_fetch":
213
+ return `Fetching: ${args.url || ""}`;
214
+ case "task":
215
+ return `Subtask: ${args.description || "running"}`;
216
+ case "ask_user":
217
+ return "Waiting for your answer";
218
+ case "report_intent":
219
+ return `${args.intent || "Working"}`;
220
+ case "sql":
221
+ return `Query: ${args.description || "running"}`;
222
+ default:
223
+ return `Using ${toolName}`;
224
+ }
225
+ }
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ EventsWatcher,
229
+ formatToolStatus
230
+ });
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // electron/terminal/ipc-relay.ts
31
+ var ipc_relay_exports = {};
32
+ __export(ipc_relay_exports, {
33
+ TerminalRelay: () => TerminalRelay
34
+ });
35
+ module.exports = __toCommonJS(ipc_relay_exports);
36
+ var import_electron = require("electron");
37
+ var import_child_process = require("child_process");
38
+ var crypto = __toESM(require("crypto"));
39
+ var path = __toESM(require("path"));
40
+ var TerminalRelay = class {
41
+ constructor(getWindow) {
42
+ this.server = null;
43
+ this.pendingRequests = /* @__PURE__ */ new Map();
44
+ /** True while a deliberate shutdown→respawn is in progress (prevents double-spawn). */
45
+ this.shuttingDown = false;
46
+ /** Requests that arrived while the server was not connected. Flushed on ready. */
47
+ this.queuedRequests = [];
48
+ this.getWindow = getWindow;
49
+ }
50
+ // ── Server Lifecycle ──────────────────────────────────────────
51
+ spawnServer(distDir) {
52
+ return new Promise((resolve, reject) => {
53
+ const serverPath = path.join(distDir, "terminal", "server.js");
54
+ console.log("[Relay] Forking terminal server:", serverPath);
55
+ this.server = (0, import_child_process.fork)(serverPath, [], {
56
+ cwd: process.cwd(),
57
+ stdio: ["pipe", "inherit", "inherit", "ipc"]
58
+ });
59
+ const readyTimeout = setTimeout(() => {
60
+ reject(new Error("Terminal server did not send ready in time"));
61
+ }, 15e3);
62
+ this.server.on("message", (msg) => {
63
+ this.handleServerMessage(msg, readyTimeout, resolve);
64
+ });
65
+ this.server.on("exit", (code, signal) => {
66
+ console.error(`[Relay] Terminal server exited (code=${code}, signal=${signal})`);
67
+ clearTimeout(readyTimeout);
68
+ this.pendingRequests.forEach(
69
+ (cb) => cb({ success: false, error: "Terminal server crashed" })
70
+ );
71
+ this.pendingRequests.clear();
72
+ this.server = null;
73
+ if (this.shuttingDown) {
74
+ console.log("[Relay] Deliberate shutdown \u2014 skipping auto-respawn");
75
+ return;
76
+ }
77
+ const win = this.getWindow();
78
+ if (win && !win.isDestroyed()) {
79
+ console.log("[Relay] Respawning terminal server...");
80
+ this.spawnServer(distDir).catch(
81
+ (e) => console.error("[Relay] Failed to respawn:", e)
82
+ );
83
+ }
84
+ });
85
+ });
86
+ }
87
+ shutdown() {
88
+ this.shuttingDown = true;
89
+ const oldServer = this.server;
90
+ this.server = null;
91
+ if (!oldServer) {
92
+ this.pendingRequests.clear();
93
+ this.queuedRequests = [];
94
+ return Promise.resolve();
95
+ }
96
+ oldServer.removeAllListeners("exit");
97
+ oldServer.removeAllListeners("message");
98
+ if (oldServer.connected) {
99
+ try {
100
+ oldServer.send({ type: "shutdown" });
101
+ } catch {
102
+ }
103
+ }
104
+ this.pendingRequests.forEach(
105
+ (cb) => cb({ success: false, error: "Terminal server shut down" })
106
+ );
107
+ this.pendingRequests.clear();
108
+ this.queuedRequests = [];
109
+ const oldPid = oldServer.pid;
110
+ return new Promise((resolve) => {
111
+ const onExit = () => {
112
+ clearTimeout(timeout);
113
+ resolve();
114
+ };
115
+ oldServer.once("exit", onExit);
116
+ const timeout = setTimeout(() => {
117
+ oldServer.removeListener("exit", onExit);
118
+ if (oldPid) {
119
+ try {
120
+ process.kill(oldPid, 0);
121
+ console.log(`[Relay] Server PID ${oldPid} still alive after timeout \u2014 force killing`);
122
+ if (process.platform === "win32") {
123
+ (0, import_child_process.execSync)(`taskkill /T /F /PID ${oldPid}`, { stdio: "ignore" });
124
+ } else {
125
+ process.kill(oldPid, "SIGKILL");
126
+ }
127
+ } catch {
128
+ }
129
+ }
130
+ resolve();
131
+ }, 3e3);
132
+ });
133
+ }
134
+ // ── Internal Helpers ─────────────────────────────────────────
135
+ send(msg) {
136
+ if (this.server?.connected) {
137
+ this.server.send(msg);
138
+ }
139
+ }
140
+ request(msg) {
141
+ if (!this.server?.connected) {
142
+ console.log(`[Relay] Server not connected \u2014 queuing request ${msg.type} (${msg.requestId})`);
143
+ return new Promise((resolve) => {
144
+ this.queuedRequests.push({ msg, resolve });
145
+ });
146
+ }
147
+ return new Promise((resolve) => {
148
+ this.pendingRequests.set(msg.requestId, resolve);
149
+ this.send(msg);
150
+ });
151
+ }
152
+ id() {
153
+ return crypto.randomUUID();
154
+ }
155
+ handleServerMessage(msg, readyTimeout, onReady) {
156
+ if (msg.type === "ready") {
157
+ clearTimeout(readyTimeout);
158
+ this.shuttingDown = false;
159
+ console.log("[Relay] Terminal server ready");
160
+ if (this.queuedRequests.length > 0) {
161
+ console.log(`[Relay] Flushing ${this.queuedRequests.length} queued request(s)`);
162
+ for (const queued of this.queuedRequests) {
163
+ this.pendingRequests.set(queued.msg.requestId, queued.resolve);
164
+ this.send(queued.msg);
165
+ }
166
+ this.queuedRequests = [];
167
+ }
168
+ onReady();
169
+ return;
170
+ }
171
+ if (msg.type === "response") {
172
+ const cb = this.pendingRequests.get(msg.requestId);
173
+ if (cb) {
174
+ this.pendingRequests.delete(msg.requestId);
175
+ cb(msg.result);
176
+ }
177
+ return;
178
+ }
179
+ const win = this.getWindow();
180
+ if (!win || win.isDestroyed()) return;
181
+ switch (msg.type) {
182
+ case "terminal-data":
183
+ win.webContents.send("terminal-data", msg.agentId, msg.data);
184
+ break;
185
+ case "terminal-exit":
186
+ win.webContents.send("terminal-exit", msg.agentId, msg.exitCode);
187
+ break;
188
+ case "copilot-event":
189
+ win.webContents.send("copilot-event", msg.agentId, msg.event);
190
+ break;
191
+ case "copilot-tool-start":
192
+ win.webContents.send("copilot-tool-start", msg.agentId, msg.toolName, msg.toolId, msg.status);
193
+ break;
194
+ case "copilot-tool-complete":
195
+ win.webContents.send("copilot-tool-complete", msg.agentId, msg.toolId, msg.success);
196
+ break;
197
+ case "copilot-turn-end":
198
+ win.webContents.send("copilot-turn-end", msg.agentId);
199
+ break;
200
+ case "copilot-turn-start":
201
+ win.webContents.send("copilot-turn-start", msg.agentId);
202
+ break;
203
+ case "copilot-user-message":
204
+ win.webContents.send("copilot-user-message", msg.agentId);
205
+ break;
206
+ case "session-meta-updated":
207
+ win.webContents.send("session-meta-updated", msg.agentId, msg.meta);
208
+ break;
209
+ case "terminal-preload-status":
210
+ win.webContents.send("terminal-preload-status", msg.agentId, msg.status);
211
+ break;
212
+ }
213
+ }
214
+ // ── IPC Handler Registration ──────────────────────────────────
215
+ registerIpc() {
216
+ import_electron.ipcMain.handle(
217
+ "terminal-start",
218
+ (_event, officeId, agentId, workingDir, cols, rows, preseededPrompt) => this.request({ type: "start", requestId: this.id(), officeId, agentId, workingDir, cols, rows, preseededPrompt })
219
+ );
220
+ import_electron.ipcMain.handle(
221
+ "terminal-attach",
222
+ (_event, officeId, agentId) => this.request({ type: "attach", requestId: this.id(), officeId, agentId })
223
+ );
224
+ import_electron.ipcMain.handle("terminal-detach", (_event, officeId, agentId) => {
225
+ this.send({ type: "detach", officeId, agentId });
226
+ return { success: true };
227
+ });
228
+ import_electron.ipcMain.handle(
229
+ "terminal-write",
230
+ (_event, officeId, agentId, data) => this.request({ type: "write", requestId: this.id(), officeId, agentId, data })
231
+ );
232
+ import_electron.ipcMain.handle("terminal-resize", (_event, officeId, agentId, cols, rows) => {
233
+ this.send({ type: "resize", officeId, agentId, cols, rows });
234
+ return { success: true };
235
+ });
236
+ import_electron.ipcMain.handle(
237
+ "terminal-kill",
238
+ (_event, officeId, agentId) => this.request({ type: "kill", requestId: this.id(), officeId, agentId })
239
+ );
240
+ import_electron.ipcMain.handle(
241
+ "terminal-exists",
242
+ (_event, officeId, agentId) => this.request({ type: "exists", requestId: this.id(), officeId, agentId })
243
+ );
244
+ import_electron.ipcMain.handle(
245
+ "terminal-pop-out",
246
+ (_event, officeId, agentId) => this.request({ type: "pop-out", requestId: this.id(), officeId, agentId })
247
+ );
248
+ import_electron.ipcMain.handle(
249
+ "get-session-id",
250
+ (_event, officeId, agentId) => this.request({ type: "get-session-id", requestId: this.id(), officeId, agentId })
251
+ );
252
+ import_electron.ipcMain.handle(
253
+ "reset-all-sessions",
254
+ (_event, officeId) => this.request({ type: "reset-all-sessions", requestId: this.id(), officeId })
255
+ );
256
+ import_electron.ipcMain.handle(
257
+ "terminal-reset-session",
258
+ (_event, officeId, agentId) => this.request({ type: "reset-session", requestId: this.id(), officeId, agentId })
259
+ );
260
+ import_electron.ipcMain.handle(
261
+ "terminal-get-session-history",
262
+ (_event, officeId, agentId) => this.request({ type: "get-session-history", requestId: this.id(), officeId, agentId })
263
+ );
264
+ import_electron.ipcMain.handle(
265
+ "terminal-clear-session-history",
266
+ (_event, officeId, agentId) => this.request({ type: "clear-session-history", requestId: this.id(), officeId, agentId })
267
+ );
268
+ import_electron.ipcMain.handle(
269
+ "list-active-terminals",
270
+ () => this.request({ type: "list-active", requestId: this.id() })
271
+ );
272
+ import_electron.ipcMain.handle(
273
+ "query-agent-statuses",
274
+ (_event, officeId) => this.request({ type: "query-agent-statuses", requestId: this.id(), officeId })
275
+ );
276
+ import_electron.ipcMain.handle(
277
+ "set-session-meta",
278
+ (_event, officeId, agentId, meta) => this.request({ type: "set-session-meta", requestId: this.id(), officeId, agentId, meta })
279
+ );
280
+ import_electron.ipcMain.handle(
281
+ "get-session-meta",
282
+ (_event, officeId, agentId) => this.request({ type: "get-session-meta", requestId: this.id(), officeId, agentId })
283
+ );
284
+ import_electron.ipcMain.handle(
285
+ "get-all-session-meta",
286
+ (_event, officeId) => this.request({ type: "get-all-session-meta", requestId: this.id(), officeId })
287
+ );
288
+ import_electron.ipcMain.handle(
289
+ "create-office-session",
290
+ (_event, officeId) => this.request({ type: "create-office-session", requestId: this.id(), officeId })
291
+ );
292
+ import_electron.ipcMain.handle(
293
+ "delete-office-session",
294
+ (_event, officeId) => this.request({ type: "delete-office-session", requestId: this.id(), officeId })
295
+ );
296
+ import_electron.ipcMain.handle(
297
+ "transfer-session",
298
+ (_event, fromOfficeId, toOfficeId, agentId) => this.request({ type: "transfer-session", requestId: this.id(), fromOfficeId, toOfficeId, agentId })
299
+ );
300
+ }
301
+ };
302
+ // Annotate the CommonJS export names for ESM import in node:
303
+ 0 && (module.exports = {
304
+ TerminalRelay
305
+ });
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // electron/terminal/preload.ts
17
+ var preload_exports = {};
18
+ module.exports = __toCommonJS(preload_exports);
19
+ var import_electron = require("electron");
20
+ import_electron.contextBridge.exposeInMainWorld("copilotBridge", {
21
+ // Terminal management
22
+ terminalStart: (officeId, agentId, workingDir, cols, rows, preseededPrompt) => {
23
+ return import_electron.ipcRenderer.invoke("terminal-start", officeId, agentId, workingDir, cols, rows, preseededPrompt);
24
+ },
25
+ terminalWrite: (officeId, agentId, data) => {
26
+ return import_electron.ipcRenderer.invoke("terminal-write", officeId, agentId, data);
27
+ },
28
+ terminalResize: (officeId, agentId, cols, rows) => {
29
+ return import_electron.ipcRenderer.invoke("terminal-resize", officeId, agentId, cols, rows);
30
+ },
31
+ terminalKill: (officeId, agentId) => {
32
+ return import_electron.ipcRenderer.invoke("terminal-kill", officeId, agentId);
33
+ },
34
+ terminalExists: (officeId, agentId) => {
35
+ return import_electron.ipcRenderer.invoke("terminal-exists", officeId, agentId);
36
+ },
37
+ terminalAttach: (officeId, agentId) => {
38
+ return import_electron.ipcRenderer.invoke("terminal-attach", officeId, agentId);
39
+ },
40
+ terminalDetach: (officeId, agentId) => {
41
+ return import_electron.ipcRenderer.invoke("terminal-detach", officeId, agentId);
42
+ },
43
+ terminalPopOut: (officeId, agentId) => {
44
+ return import_electron.ipcRenderer.invoke("terminal-pop-out", officeId, agentId);
45
+ },
46
+ // Session persistence (server is the single source of truth for session IDs)
47
+ getSessionId: (officeId, agentId) => {
48
+ return import_electron.ipcRenderer.invoke("get-session-id", officeId, agentId);
49
+ },
50
+ resetAllSessions: (officeId) => {
51
+ return import_electron.ipcRenderer.invoke("reset-all-sessions", officeId);
52
+ },
53
+ resetSession: (officeId, agentId) => {
54
+ return import_electron.ipcRenderer.invoke("terminal-reset-session", officeId, agentId);
55
+ },
56
+ getSessionHistory: (officeId, agentId) => {
57
+ return import_electron.ipcRenderer.invoke("terminal-get-session-history", officeId, agentId);
58
+ },
59
+ clearSessionHistory: (officeId, agentId) => {
60
+ return import_electron.ipcRenderer.invoke("terminal-clear-session-history", officeId, agentId);
61
+ },
62
+ listActiveTerminals: () => {
63
+ return import_electron.ipcRenderer.invoke("list-active-terminals");
64
+ },
65
+ queryAgentStatuses: (officeId) => {
66
+ return import_electron.ipcRenderer.invoke("query-agent-statuses", officeId);
67
+ },
68
+ // Session metadata
69
+ setSessionMeta: (officeId, agentId, meta) => {
70
+ return import_electron.ipcRenderer.invoke("set-session-meta", officeId, agentId, meta);
71
+ },
72
+ getSessionMeta: (officeId, agentId) => {
73
+ return import_electron.ipcRenderer.invoke("get-session-meta", officeId, agentId);
74
+ },
75
+ getAllSessionMeta: (officeId) => {
76
+ return import_electron.ipcRenderer.invoke("get-all-session-meta", officeId);
77
+ },
78
+ // Office session file management
79
+ createOfficeSession: (officeId) => {
80
+ return import_electron.ipcRenderer.invoke("create-office-session", officeId);
81
+ },
82
+ deleteOfficeSession: (officeId) => {
83
+ return import_electron.ipcRenderer.invoke("delete-office-session", officeId);
84
+ },
85
+ // Transfer a session (ID, metadata, PTY alias) from one office to another
86
+ transferSession: (fromOfficeId, toOfficeId, agentId) => {
87
+ return import_electron.ipcRenderer.invoke("transfer-session", fromOfficeId, toOfficeId, agentId);
88
+ },
89
+ // Office file persistence
90
+ saveOffices: (data) => {
91
+ return import_electron.ipcRenderer.invoke("save-offices", data);
92
+ },
93
+ loadOffices: () => {
94
+ return import_electron.ipcRenderer.invoke("load-offices");
95
+ },
96
+ // Terminal event listeners
97
+ onTerminalData: (callback) => {
98
+ import_electron.ipcRenderer.on("terminal-data", (_event, agentId, data) => callback(agentId, data));
99
+ },
100
+ onTerminalExit: (callback) => {
101
+ import_electron.ipcRenderer.on("terminal-exit", (_event, agentId, exitCode) => callback(agentId, exitCode));
102
+ },
103
+ onTerminalPreloadStatus: (callback) => {
104
+ import_electron.ipcRenderer.on("terminal-preload-status", (_event, agentId, status) => callback(agentId, status));
105
+ },
106
+ // Copilot activity event listeners
107
+ onCopilotEvent: (callback) => {
108
+ import_electron.ipcRenderer.on("copilot-event", (_event, agentId, copilotEvent) => callback(agentId, copilotEvent));
109
+ },
110
+ onCopilotToolStart: (callback) => {
111
+ import_electron.ipcRenderer.on("copilot-tool-start", (_event, agentId, toolName, toolId, status) => callback(agentId, toolName, toolId, status));
112
+ },
113
+ onCopilotToolComplete: (callback) => {
114
+ import_electron.ipcRenderer.on("copilot-tool-complete", (_event, agentId, toolId, success) => callback(agentId, toolId, success));
115
+ },
116
+ onCopilotTurnEnd: (callback) => {
117
+ import_electron.ipcRenderer.on("copilot-turn-end", (_event, agentId) => callback(agentId));
118
+ },
119
+ onCopilotTurnStart: (callback) => {
120
+ import_electron.ipcRenderer.on("copilot-turn-start", (_event, agentId) => callback(agentId));
121
+ },
122
+ onCopilotUserMessage: (callback) => {
123
+ import_electron.ipcRenderer.on("copilot-user-message", (_event, agentId) => callback(agentId));
124
+ },
125
+ onSessionMetaUpdated: (callback) => {
126
+ import_electron.ipcRenderer.on("session-meta-updated", (_event, agentId, meta) => callback(agentId, meta));
127
+ },
128
+ removeTerminalListeners: () => {
129
+ import_electron.ipcRenderer.removeAllListeners("terminal-data");
130
+ import_electron.ipcRenderer.removeAllListeners("terminal-exit");
131
+ },
132
+ removeCopilotListeners: () => {
133
+ import_electron.ipcRenderer.removeAllListeners("copilot-event");
134
+ import_electron.ipcRenderer.removeAllListeners("copilot-tool-start");
135
+ import_electron.ipcRenderer.removeAllListeners("copilot-tool-complete");
136
+ import_electron.ipcRenderer.removeAllListeners("copilot-turn-end");
137
+ import_electron.ipcRenderer.removeAllListeners("copilot-turn-start");
138
+ import_electron.ipcRenderer.removeAllListeners("copilot-user-message");
139
+ import_electron.ipcRenderer.removeAllListeners("session-meta-updated");
140
+ },
141
+ // Signal the main process that the next reload should restart the terminal server
142
+ requestHardReload: () => {
143
+ return import_electron.ipcRenderer.invoke("request-hard-reload");
144
+ },
145
+ // Native OS notifications
146
+ showNativeNotification: (title, body) => {
147
+ return import_electron.ipcRenderer.invoke("show-native-notification", title, body);
148
+ }
149
+ });