@ouro.bot/cli 0.1.0-alpha.1464 → 0.1.0-alpha.1466
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/README.md +2 -2
- package/changelog.json +14 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/daemon/cli-commands/mail.js +0 -1
- package/dist/heart/daemon/cli-exec.js +0 -33
- package/dist/heart/daemon/cli-help.js +0 -13
- package/dist/heart/daemon/cli-parse.js +0 -3
- package/dist/heart/daemon/cli-render.js +0 -7
- package/dist/heart/daemon/daemon-entry.js +1 -1
- package/dist/heart/daemon/daemon.js +0 -63
- package/dist/heart/{mailbox/mailbox-supervision.js → shepherd/supervision-read.js} +4 -4
- package/dist/nerves/coverage/file-completeness.js +0 -11
- package/dist/nerves/observation.js +2 -4
- package/dist/repertoire/tools-mail.js +2 -2
- package/dist/senses/cli/ouro-tui.js +2 -2
- package/dist/senses/shepherd/operations.js +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -4
- package/skills/sense-setup.md +1 -1
- package/dist/heart/mailbox/mailbox-http-hooks.js +0 -99
- package/dist/heart/mailbox/mailbox-http-response.js +0 -7
- package/dist/heart/mailbox/mailbox-http-routes.js +0 -406
- package/dist/heart/mailbox/mailbox-http-static.js +0 -103
- package/dist/heart/mailbox/mailbox-http-transport.js +0 -272
- package/dist/heart/mailbox/mailbox-http.js +0 -99
- package/dist/heart/mailbox/mailbox-read.js +0 -41
- package/dist/heart/mailbox/mailbox-types.js +0 -27
- package/dist/heart/mailbox/mailbox-view.js +0 -197
- package/dist/heart/mailbox/readers/agent-machine.js +0 -428
- package/dist/heart/mailbox/readers/continuity-readers.js +0 -329
- package/dist/heart/mailbox/readers/mail.js +0 -375
- package/dist/heart/mailbox/readers/runtime-readers.js +0 -823
- package/dist/heart/mailbox/readers/sessions.js +0 -231
- package/dist/heart/mailbox/readers/shared.js +0 -111
- package/dist/mailbox-ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/mailbox-ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/mailbox-ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/mailbox-ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/mailbox-ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/mailbox-ui/assets/index-BQYBPyiH.js +0 -5
- package/dist/mailbox-ui/assets/index-UZ85Lvxp.css +0 -1
- package/dist/mailbox-ui/assets/vendor-BfcLUM_P.js +0 -65
- package/dist/mailbox-ui/index.html +0 -18
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createMailboxHttpRequestHandler = createMailboxHttpRequestHandler;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
|
-
const mailbox_http_hooks_1 = require("./mailbox-http-hooks");
|
|
40
|
-
const mailbox_http_response_1 = require("./mailbox-http-response");
|
|
41
|
-
const mailbox_http_static_1 = require("./mailbox-http-static");
|
|
42
|
-
function decodePathSegment(value) {
|
|
43
|
-
try {
|
|
44
|
-
return decodeURIComponent(value);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function rawRequestTargetsUnsafeAgent(urlValue = "/") {
|
|
51
|
-
const rawTarget = urlValue.split(/[?#]/, 1)[0];
|
|
52
|
-
const rawPath = rawTarget.replace(/\/+$/, "") || "/";
|
|
53
|
-
const pathname = (0, mailbox_http_static_1.normalizeLegacyMailboxApiPath)(rawPath);
|
|
54
|
-
const rawAgentMatch = /^\/api\/agents\/([^/]+)(?:\/|$)/.exec(pathname);
|
|
55
|
-
if (!rawAgentMatch)
|
|
56
|
-
return false;
|
|
57
|
-
const agent = decodePathSegment(rawAgentMatch[1]);
|
|
58
|
-
return !agent || !(0, mailbox_http_hooks_1.isSafeMailboxAgentName)(agent);
|
|
59
|
-
}
|
|
60
|
-
function parseHabitRunLimit(urlValue) {
|
|
61
|
-
const rawLimit = new URL(urlValue, "http://127.0.0.1").searchParams.get("limit");
|
|
62
|
-
if (rawLimit === null)
|
|
63
|
-
return undefined;
|
|
64
|
-
if (!/^[1-9][0-9]*$/.test(rawLimit))
|
|
65
|
-
return null;
|
|
66
|
-
const limit = Number.parseInt(rawLimit, 10);
|
|
67
|
-
return limit >= 1 && limit <= 100 ? limit : null;
|
|
68
|
-
}
|
|
69
|
-
const VALID_HABIT_SUMMARY_WHICH = new Set(["latest", "previous", "latest-success", "latest-failure"]);
|
|
70
|
-
function firstQueryValue(params, names) {
|
|
71
|
-
for (const name of names) {
|
|
72
|
-
const value = params.get(name);
|
|
73
|
-
if (value !== null && value.trim().length > 0)
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
function parseHabitSummarySelector(urlValue) {
|
|
79
|
-
const params = new URL(urlValue, "http://127.0.0.1").searchParams;
|
|
80
|
-
const runId = firstQueryValue(params, ["runId", "run-id"]);
|
|
81
|
-
const habitName = firstQueryValue(params, ["habitName", "habit"]);
|
|
82
|
-
const operationId = firstQueryValue(params, ["operationId", "operation-id"]);
|
|
83
|
-
const which = firstQueryValue(params, ["which"]);
|
|
84
|
-
if (runId !== undefined && (habitName !== undefined || operationId !== undefined || which !== undefined)) {
|
|
85
|
-
return { ok: false, error: "--run-id cannot be combined with --habit, --operation-id, or --which" };
|
|
86
|
-
}
|
|
87
|
-
if (runId === undefined && habitName === undefined && operationId === undefined) {
|
|
88
|
-
return { ok: false, error: "provide runId, habitName, or operationId" };
|
|
89
|
-
}
|
|
90
|
-
if (which !== undefined && !VALID_HABIT_SUMMARY_WHICH.has(which)) {
|
|
91
|
-
return { ok: false, error: "which must be latest, previous, latest-success, or latest-failure" };
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
ok: true,
|
|
95
|
-
selector: {
|
|
96
|
-
...(runId ? { runId } : {}),
|
|
97
|
-
...(habitName ? { habitName } : {}),
|
|
98
|
-
...(operationId ? { operationId } : {}),
|
|
99
|
-
...(which ? { which } : {}),
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function createMailboxHttpRequestHandler(options) {
|
|
104
|
-
const staticFiles = options.staticFiles ?? { resolveSpaDistDir: mailbox_http_static_1.resolveSpaDistDir, serveStaticFile: mailbox_http_static_1.serveStaticFile };
|
|
105
|
-
return (request, response) => {
|
|
106
|
-
if (rawRequestTargetsUnsafeAgent(request.url)) {
|
|
107
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "agent name must be a safe bundle name" });
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let pathname = (0, mailbox_http_static_1.normalizeMailboxRequestPath)(request.url);
|
|
111
|
-
const origin = `http://${options.host}:${options.getPort()}`;
|
|
112
|
-
if (pathname.startsWith("/assets/")) {
|
|
113
|
-
const spaDir = staticFiles.resolveSpaDistDir();
|
|
114
|
-
if (spaDir) {
|
|
115
|
-
const assetPath = path.join(spaDir, pathname);
|
|
116
|
-
if (staticFiles.serveStaticFile(response, assetPath))
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: "asset not found" });
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (pathname === "/mailbox" || pathname === "/outlook") {
|
|
123
|
-
response.writeHead(301, { location: "/" });
|
|
124
|
-
response.end();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
pathname = (0, mailbox_http_static_1.normalizeLegacyMailboxApiPath)(pathname);
|
|
128
|
-
if (pathname === "/api/events") {
|
|
129
|
-
response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", "connection": "keep-alive", "access-control-allow-origin": "*" });
|
|
130
|
-
response.write(":ok\n\n");
|
|
131
|
-
options.sse.add(response);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (pathname === "/api/machine") {
|
|
135
|
-
const machine = options.readMachineState();
|
|
136
|
-
const machineView = options.readMachineView?.({ origin, machine });
|
|
137
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, machineView ?? machine);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (pathname === "/api/machine/health") {
|
|
141
|
-
const health = options.hooks.readDaemonHealth();
|
|
142
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, health ?? { status: "unavailable" });
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (pathname === "/api/machine/logs") {
|
|
146
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readLogs());
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const agentMatch = /^\/api\/agents\/([^/]+)(?:\/(.+))?$/.exec(pathname);
|
|
150
|
-
if (agentMatch) {
|
|
151
|
-
const agent = decodePathSegment(agentMatch[1]);
|
|
152
|
-
/* v8 ignore next -- rawRequestTargetsUnsafeAgent rejects unsafe/malformed agent segments before normalization @preserve */
|
|
153
|
-
if (!agent || !(0, mailbox_http_hooks_1.isSafeMailboxAgentName)(agent)) {
|
|
154
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "agent name must be a safe bundle name" });
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
void handleAgentRoute(request, response, {
|
|
158
|
-
agent,
|
|
159
|
-
surface: agentMatch[2] ?? null,
|
|
160
|
-
options,
|
|
161
|
-
}).catch((error) => {
|
|
162
|
-
(0, mailbox_http_response_1.writeJson)(response, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const spaDir = staticFiles.resolveSpaDistDir();
|
|
167
|
-
if (spaDir) {
|
|
168
|
-
if (staticFiles.serveStaticFile(response, path.join(spaDir, "index.html")))
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: `not found: ${pathname}` });
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
async function handleAgentRoute(request, response, context) {
|
|
175
|
-
const { agent, surface, options } = context;
|
|
176
|
-
if (surface === "supervision") {
|
|
177
|
-
if (request.method !== "GET") {
|
|
178
|
-
(0, mailbox_http_response_1.writeJson)(response, 405, { ok: false, error: "Supervision is read-only; use the local owner CLI for administration" });
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentSupervision(agent));
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (!surface) {
|
|
185
|
-
const view = options.readAgentView?.(agent);
|
|
186
|
-
if (view) {
|
|
187
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const state = options.readAgentState(agent);
|
|
191
|
-
if (!state) {
|
|
192
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: `unknown agent: ${agent}` });
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, state);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (surface === "sessions") {
|
|
199
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentSessions(agent));
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const transcriptMatch = /^sessions\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(surface);
|
|
203
|
-
if (transcriptMatch) {
|
|
204
|
-
const friendId = decodeURIComponent(transcriptMatch[1]);
|
|
205
|
-
const channel = decodeURIComponent(transcriptMatch[2]);
|
|
206
|
-
const key = decodeURIComponent(transcriptMatch[3]);
|
|
207
|
-
const transcript = options.hooks.readAgentTranscript(agent, friendId, channel, key);
|
|
208
|
-
if (!transcript) {
|
|
209
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: "session not found" });
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, transcript);
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
if (surface === "coding") {
|
|
216
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentCoding(agent));
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (surface === "attention") {
|
|
220
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentAttention(agent));
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (surface === "bridges") {
|
|
224
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentBridges(agent));
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (surface === "notes") {
|
|
228
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentNotes(agent));
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (surface === "friends") {
|
|
232
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentFriends(agent));
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (surface === "continuity") {
|
|
236
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentContinuity(agent));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (surface === "orientation") {
|
|
240
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentOrientation(agent));
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (surface === "obligations") {
|
|
244
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentObligations(agent));
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (surface === "changes") {
|
|
248
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentChanges(agent));
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (surface === "self-fix") {
|
|
252
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentSelfFix(agent));
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (surface === "context-loss-gauntlet") {
|
|
256
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentContextLossGauntlet(agent));
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
if (surface === "sentinel") {
|
|
260
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentSentinel(agent));
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
if (surface === "note-decisions") {
|
|
264
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentNoteDecisions(agent));
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (surface === "dismiss-obligation" && request.method === "POST") {
|
|
268
|
-
handleDismissObligation(request, response, options.hooks.agentRoot(agent));
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (surface === "desk-prefs") {
|
|
272
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readDeskPrefs(agent));
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (surface === "needs-me") {
|
|
276
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readNeedsMe(agent));
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
if (surface === "habits") {
|
|
280
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, options.hooks.readAgentHabits(agent));
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (surface === "habit-runs") {
|
|
284
|
-
const limit = parseHabitRunLimit(request.url);
|
|
285
|
-
if (limit === null) {
|
|
286
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "limit must be an integer between 1 and 100" });
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
const view = limit === undefined
|
|
290
|
-
? options.hooks.readAgentHabitRuns(agent)
|
|
291
|
-
: options.hooks.readAgentHabitRuns(agent, { limit });
|
|
292
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (surface === "habit-run-summaries") {
|
|
296
|
-
const limit = parseHabitRunLimit(request.url);
|
|
297
|
-
if (limit === null) {
|
|
298
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "limit must be an integer between 1 and 100" });
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
const view = limit === undefined
|
|
302
|
-
? options.hooks.readAgentHabitRunSummaries(agent)
|
|
303
|
-
: options.hooks.readAgentHabitRunSummaries(agent, { limit });
|
|
304
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
if (surface === "habit-run-summary") {
|
|
308
|
-
const parsed = parseHabitSummarySelector(request.url);
|
|
309
|
-
if (!parsed.ok) {
|
|
310
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: parsed.error });
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const summary = options.hooks.readAgentHabitRunSummary(agent, parsed.selector);
|
|
314
|
-
if (!summary) {
|
|
315
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: "habit summary not found" });
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, summary);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
if (surface.startsWith("habit-runs/")) {
|
|
322
|
-
const rawRunId = surface.slice("habit-runs/".length);
|
|
323
|
-
const runId = decodePathSegment(rawRunId);
|
|
324
|
-
const view = runId ? options.hooks.readAgentHabitRun(agent, runId) : null;
|
|
325
|
-
if (!view) {
|
|
326
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: `habit run '${rawRunId}' not found` });
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (surface === "context-packets") {
|
|
333
|
-
const limit = parseHabitRunLimit(request.url);
|
|
334
|
-
if (limit === null) {
|
|
335
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "limit must be an integer between 1 and 100" });
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
const view = limit === undefined
|
|
339
|
-
? options.hooks.readAgentContextPackets(agent)
|
|
340
|
-
: options.hooks.readAgentContextPackets(agent, { limit });
|
|
341
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (surface.startsWith("context-packets/")) {
|
|
345
|
-
const rawPacketId = surface.slice("context-packets/".length);
|
|
346
|
-
const packetId = decodePathSegment(rawPacketId);
|
|
347
|
-
const view = packetId ? options.hooks.readAgentContextPacket(agent, packetId) : null;
|
|
348
|
-
if (!view) {
|
|
349
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: `context packet '${rawPacketId}' not found` });
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, view);
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
if (surface === "mail") {
|
|
356
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, await options.hooks.readAgentMail(agent));
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
const mailMessageMatch = /^mail\/([^/]+)$/.exec(surface);
|
|
360
|
-
if (mailMessageMatch) {
|
|
361
|
-
const messageId = decodeURIComponent(mailMessageMatch[1]);
|
|
362
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, await options.hooks.readAgentMailMessage(agent, messageId));
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
if (surface === "inner-transcript") {
|
|
366
|
-
const transcript = options.hooks.readAgentTranscript(agent, "self", "inner", "dialog");
|
|
367
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, transcript ?? { messageCount: 0, messages: [] });
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
(0, mailbox_http_response_1.writeJson)(response, 404, { ok: false, error: `unknown agent surface: ${surface}` });
|
|
371
|
-
}
|
|
372
|
-
function handleDismissObligation(request, response, agentRoot) {
|
|
373
|
-
let body = "";
|
|
374
|
-
request.on("data", (chunk) => {
|
|
375
|
-
body += chunk;
|
|
376
|
-
});
|
|
377
|
-
request.on("end", () => {
|
|
378
|
-
try {
|
|
379
|
-
const { obligationId } = JSON.parse(body);
|
|
380
|
-
if (!obligationId) {
|
|
381
|
-
(0, mailbox_http_response_1.writeJson)(response, 400, { ok: false, error: "obligationId required" });
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const prefsPath = path.join(agentRoot, "state", "mailbox-prefs.json");
|
|
385
|
-
const legacyPrefsPath = path.join(agentRoot, "state", "outlook-prefs.json");
|
|
386
|
-
let prefs = {};
|
|
387
|
-
try {
|
|
388
|
-
const readPath = fs.existsSync(prefsPath) ? prefsPath : legacyPrefsPath;
|
|
389
|
-
prefs = JSON.parse(fs.readFileSync(readPath, "utf-8"));
|
|
390
|
-
}
|
|
391
|
-
catch {
|
|
392
|
-
// Missing or malformed prefs start from a clean preference object.
|
|
393
|
-
}
|
|
394
|
-
const dismissed = Array.isArray(prefs.dismissedObligations) ? prefs.dismissedObligations : [];
|
|
395
|
-
if (!dismissed.includes(obligationId))
|
|
396
|
-
dismissed.push(obligationId);
|
|
397
|
-
prefs.dismissedObligations = dismissed;
|
|
398
|
-
fs.mkdirSync(path.dirname(prefsPath), { recursive: true });
|
|
399
|
-
fs.writeFileSync(prefsPath, `${JSON.stringify(prefs, null, 2)}\n`, "utf-8");
|
|
400
|
-
(0, mailbox_http_response_1.writeJson)(response, 200, { ok: true, dismissed: dismissed.length });
|
|
401
|
-
}
|
|
402
|
-
catch (error) {
|
|
403
|
-
(0, mailbox_http_response_1.writeJson)(response, 500, { ok: false, error: String(error) });
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.normalizeMailboxRequestPath = normalizeMailboxRequestPath;
|
|
37
|
-
exports.normalizeLegacyMailboxApiPath = normalizeLegacyMailboxApiPath;
|
|
38
|
-
exports.resolveSpaDistDir = resolveSpaDistDir;
|
|
39
|
-
exports.serveStaticFile = serveStaticFile;
|
|
40
|
-
const fs = __importStar(require("fs"));
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const MIME_TYPES = {
|
|
43
|
-
".html": "text/html",
|
|
44
|
-
".js": "application/javascript",
|
|
45
|
-
".css": "text/css",
|
|
46
|
-
".json": "application/json",
|
|
47
|
-
".svg": "image/svg+xml",
|
|
48
|
-
".png": "image/png",
|
|
49
|
-
".ico": "image/x-icon",
|
|
50
|
-
".woff2": "font/woff2",
|
|
51
|
-
};
|
|
52
|
-
function normalizeMailboxRequestPath(urlValue = "/") {
|
|
53
|
-
const parsed = new URL(urlValue, "http://127.0.0.1");
|
|
54
|
-
const normalizedPath = parsed.pathname.replace(/\/+$/, "");
|
|
55
|
-
if (normalizedPath.length === 0)
|
|
56
|
-
return "/";
|
|
57
|
-
return normalizedPath;
|
|
58
|
-
}
|
|
59
|
-
function normalizeLegacyMailboxApiPath(pathname) {
|
|
60
|
-
if (pathname.startsWith("/mailbox/api/"))
|
|
61
|
-
return pathname.slice("/mailbox".length);
|
|
62
|
-
if (pathname === "/mailbox/api")
|
|
63
|
-
return "/api";
|
|
64
|
-
if (pathname.startsWith("/outlook/api/"))
|
|
65
|
-
return pathname.slice("/outlook".length);
|
|
66
|
-
if (pathname === "/outlook/api")
|
|
67
|
-
return "/api";
|
|
68
|
-
return pathname;
|
|
69
|
-
}
|
|
70
|
-
function defaultSpaDistCandidates() {
|
|
71
|
-
return [
|
|
72
|
-
path.resolve(__dirname, "..", "..", "..", "packages", "mailbox-ui", "dist"),
|
|
73
|
-
path.resolve(__dirname, "..", "..", "packages", "mailbox-ui", "dist"),
|
|
74
|
-
path.resolve(__dirname, "..", "..", "..", "..", "packages", "mailbox-ui", "dist"),
|
|
75
|
-
path.resolve(__dirname, "..", "..", "mailbox-ui"),
|
|
76
|
-
path.resolve(__dirname, "..", "mailbox-ui"),
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
function resolveSpaDistDir(candidates = defaultSpaDistCandidates()) {
|
|
80
|
-
for (const candidate of candidates) {
|
|
81
|
-
if (fs.existsSync(path.join(candidate, "index.html")))
|
|
82
|
-
return candidate;
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
function serveStaticFile(response, filePath) {
|
|
87
|
-
try {
|
|
88
|
-
if (!fs.existsSync(filePath))
|
|
89
|
-
return false;
|
|
90
|
-
const ext = path.extname(filePath);
|
|
91
|
-
const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
92
|
-
const content = fs.readFileSync(filePath);
|
|
93
|
-
response.writeHead(200, {
|
|
94
|
-
"content-type": contentType,
|
|
95
|
-
"cache-control": ext === ".html" ? "no-cache" : "public, max-age=31536000, immutable",
|
|
96
|
-
});
|
|
97
|
-
response.end(content);
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|