deepspace 0.28.2 → 0.29.1
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 +24 -0
- package/dist/{chunk-DMUR67NG.js → chunk-DWSZYN73.js} +2 -2
- package/dist/{chunk-DMUR67NG.js.map → chunk-DWSZYN73.js.map} +1 -1
- package/dist/cli.js +110 -56
- package/dist/cli.js.map +1 -1
- package/dist/documentation-client-core.js +1 -1
- package/dist/documentation-default-renderer.cjs +1 -1
- package/dist/documentation-react.js +1 -1
- package/dist/documentation-runtime.js +1 -1
- package/dist/documentation-server-core.js +1 -1
- package/dist/documentation.js +1 -1
- package/dist/documentation.js.map +1 -1
- package/dist/index.d.ts +56 -67
- package/dist/index.js +97 -129
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +113 -30
- package/dist/server.js.map +1 -1
- package/dist/worker.d.ts +72 -90
- package/dist/worker.js +157 -135
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -72,6 +72,116 @@ var ROLE_DEFAULT = "member";
|
|
|
72
72
|
var ROLE_ADMIN = "admin";
|
|
73
73
|
var RECORD_NOT_FOUND = "Record not found";
|
|
74
74
|
|
|
75
|
+
// src/shared/log-events.ts
|
|
76
|
+
var LOG_LEVELS = ["debug", "log", "info", "warn", "error"];
|
|
77
|
+
var APP_LOG_EVENT_KEYS = [
|
|
78
|
+
"id",
|
|
79
|
+
"timestamp",
|
|
80
|
+
"level",
|
|
81
|
+
"eventType",
|
|
82
|
+
"message",
|
|
83
|
+
"outcome",
|
|
84
|
+
"request",
|
|
85
|
+
"exception"
|
|
86
|
+
];
|
|
87
|
+
function logEventText(e) {
|
|
88
|
+
if (e.eventType === "exception" && e.exception) {
|
|
89
|
+
const where = e.request ? ` \u2014 ${e.request.method} ${e.request.path}` : "";
|
|
90
|
+
return `${e.exception.name}: ${e.exception.message}${where}`;
|
|
91
|
+
}
|
|
92
|
+
if (e.eventType === "request" && e.request) {
|
|
93
|
+
const status = e.request.status !== void 0 ? ` ${e.request.status}` : "";
|
|
94
|
+
const outcome = e.outcome && e.outcome !== "ok" ? ` (${e.outcome})` : "";
|
|
95
|
+
return `${e.request.method} ${e.request.path}${status}${outcome}`;
|
|
96
|
+
}
|
|
97
|
+
return e.message;
|
|
98
|
+
}
|
|
99
|
+
function loggableError(err) {
|
|
100
|
+
try {
|
|
101
|
+
return truncateLogText(renderError(err, 0));
|
|
102
|
+
} catch {
|
|
103
|
+
return tagOf(err);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function truncateLogText(s) {
|
|
107
|
+
if (s.length <= MAX_LOG_TEXT_LENGTH) return s;
|
|
108
|
+
let cut = MAX_LOG_TEXT_LENGTH - TRUNCATION_MARKER.length;
|
|
109
|
+
const last = s.charCodeAt(cut - 1);
|
|
110
|
+
if (last >= 55296 && last <= 56319) cut -= 1;
|
|
111
|
+
return s.slice(0, cut) + TRUNCATION_MARKER;
|
|
112
|
+
}
|
|
113
|
+
var MAX_LOG_TEXT_LENGTH = 8 * 1024;
|
|
114
|
+
var TRUNCATION_MARKER = "\u2026 [truncated]";
|
|
115
|
+
var MAX_CAUSE_DEPTH = 4;
|
|
116
|
+
function tagOf(err) {
|
|
117
|
+
try {
|
|
118
|
+
return Object.prototype.toString.call(err);
|
|
119
|
+
} catch {
|
|
120
|
+
return "[unloggable error]";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function renderError(err, depth) {
|
|
124
|
+
let isError;
|
|
125
|
+
try {
|
|
126
|
+
isError = err instanceof Error;
|
|
127
|
+
} catch {
|
|
128
|
+
return tagOf(err);
|
|
129
|
+
}
|
|
130
|
+
if (!isError) {
|
|
131
|
+
try {
|
|
132
|
+
return String(err).slice(0, MAX_LOG_TEXT_LENGTH + 1);
|
|
133
|
+
} catch {
|
|
134
|
+
return tagOf(err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const e = err;
|
|
138
|
+
let out;
|
|
139
|
+
try {
|
|
140
|
+
const stack = typeof e.stack === "string" ? e.stack : void 0;
|
|
141
|
+
const head = (e.message ? `${e.name}: ${e.message}` : `${e.name}`).slice(
|
|
142
|
+
0,
|
|
143
|
+
MAX_LOG_TEXT_LENGTH + 1
|
|
144
|
+
);
|
|
145
|
+
if (!stack) out = head;
|
|
146
|
+
else if (stack.startsWith(head)) out = stack.slice(0, MAX_LOG_TEXT_LENGTH + 1);
|
|
147
|
+
else out = `${head}
|
|
148
|
+
${stack.slice(0, MAX_LOG_TEXT_LENGTH + 1)}`;
|
|
149
|
+
} catch {
|
|
150
|
+
return tagOf(err);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
if (e instanceof AggregateError && Array.isArray(e.errors)) {
|
|
154
|
+
if (depth < MAX_CAUSE_DEPTH) {
|
|
155
|
+
for (const sub of e.errors.slice(0, MAX_CAUSE_DEPTH)) {
|
|
156
|
+
if (out.length >= MAX_LOG_TEXT_LENGTH) return out + "\n\u2026 [cause chain truncated]";
|
|
157
|
+
out += `
|
|
158
|
+
caused by: ${renderError(sub, depth + 1)}`;
|
|
159
|
+
}
|
|
160
|
+
if (e.errors.length > MAX_CAUSE_DEPTH) {
|
|
161
|
+
out += `
|
|
162
|
+
\u2026 [${e.errors.length - MAX_CAUSE_DEPTH} more errors]`;
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
out += "\n\u2026 [cause chain truncated]";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const cause = e.cause;
|
|
169
|
+
if (cause != null) {
|
|
170
|
+
if (depth >= MAX_CAUSE_DEPTH) {
|
|
171
|
+
if (!out.endsWith("\u2026 [cause chain truncated]")) out += "\n\u2026 [cause chain truncated]";
|
|
172
|
+
} else if (out.length < MAX_LOG_TEXT_LENGTH) {
|
|
173
|
+
out += `
|
|
174
|
+
caused by: ${renderError(cause, depth + 1)}`;
|
|
175
|
+
} else {
|
|
176
|
+
out += "\n\u2026 [cause chain truncated]";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
out += "\n\u2026 [cause chain unrenderable]";
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
75
185
|
// src/shared/room-identity-headers.ts
|
|
76
186
|
var BASE64URL = /^[A-Za-z0-9_-]*$/;
|
|
77
187
|
var IDENTITY_QUERY_PARAMS = ["userId", "userName", "userEmail", "userImageUrl", "role"];
|
|
@@ -215,7 +325,7 @@ var BaseRoom = class {
|
|
|
215
325
|
try {
|
|
216
326
|
await this.onBinaryMessage(ws, attachment, message);
|
|
217
327
|
} catch (e) {
|
|
218
|
-
console.error(`[${this.constructor.name}] Binary message error
|
|
328
|
+
console.error(`[${this.constructor.name}] Binary message error: ${loggableError(e)}`);
|
|
219
329
|
}
|
|
220
330
|
}
|
|
221
331
|
return;
|
|
@@ -224,7 +334,7 @@ var BaseRoom = class {
|
|
|
224
334
|
const msg = JSON.parse(message);
|
|
225
335
|
await this.onMessage(ws, attachment, msg);
|
|
226
336
|
} catch (e) {
|
|
227
|
-
console.error(`[${this.constructor.name}] Message error
|
|
337
|
+
console.error(`[${this.constructor.name}] Message error: ${loggableError(e)}`);
|
|
228
338
|
}
|
|
229
339
|
}
|
|
230
340
|
async webSocketClose(ws, _code, _reason) {
|
|
@@ -237,7 +347,7 @@ var BaseRoom = class {
|
|
|
237
347
|
}
|
|
238
348
|
}
|
|
239
349
|
async webSocketError(_ws, error) {
|
|
240
|
-
console.error(`[${this.constructor.name}] webSocketError
|
|
350
|
+
console.error(`[${this.constructor.name}] webSocketError: ${loggableError(error)}`);
|
|
241
351
|
}
|
|
242
352
|
async alarm() {
|
|
243
353
|
if (this.onAlarm) {
|
|
@@ -1684,7 +1794,7 @@ function getOrCreateYjsDoc(ctx, docKey) {
|
|
|
1684
1794
|
try {
|
|
1685
1795
|
Y2.applyUpdate(doc, new Uint8Array(row.state));
|
|
1686
1796
|
} catch (e) {
|
|
1687
|
-
console.error(`Failed to load Yjs doc ${docKey}
|
|
1797
|
+
console.error(`Failed to load Yjs doc ${docKey}: ${loggableError(e)}`);
|
|
1688
1798
|
}
|
|
1689
1799
|
}
|
|
1690
1800
|
const saveDoc = () => {
|
|
@@ -3198,7 +3308,7 @@ var RecordRoom = class extends BaseRoom {
|
|
|
3198
3308
|
new Uint8Array(message)
|
|
3199
3309
|
);
|
|
3200
3310
|
} catch (e) {
|
|
3201
|
-
console.error(
|
|
3311
|
+
console.error(`[RecordRoom] Yjs binary message error: ${loggableError(e)}`);
|
|
3202
3312
|
}
|
|
3203
3313
|
return;
|
|
3204
3314
|
}
|
|
@@ -3208,7 +3318,9 @@ var RecordRoom = class extends BaseRoom {
|
|
|
3208
3318
|
} catch (e) {
|
|
3209
3319
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
3210
3320
|
const msgPreview = typeof message === "string" ? message.slice(0, 200) : "(non-string)";
|
|
3211
|
-
console.error(`[RecordRoom] Message handler error: ${
|
|
3321
|
+
console.error(`[RecordRoom] Message handler error: ${loggableError(e)}`, {
|
|
3322
|
+
message: msgPreview
|
|
3323
|
+
});
|
|
3212
3324
|
this.send(ws, { type: MSG.ERROR, payload: { error: `Invalid message: ${errMsg}` } });
|
|
3213
3325
|
}
|
|
3214
3326
|
}
|
|
@@ -3222,9 +3334,6 @@ var RecordRoom = class extends BaseRoom {
|
|
|
3222
3334
|
} catch {
|
|
3223
3335
|
}
|
|
3224
3336
|
}
|
|
3225
|
-
async webSocketError(_ws, error) {
|
|
3226
|
-
console.error(`[RecordRoom] webSocketError:`, error);
|
|
3227
|
-
}
|
|
3228
3337
|
// ============================================================================
|
|
3229
3338
|
// Message Routing
|
|
3230
3339
|
// ============================================================================
|
|
@@ -4364,8 +4473,7 @@ var CronRoom = class extends BaseRoom {
|
|
|
4364
4473
|
if (success) {
|
|
4365
4474
|
console.log(`[cron] ${taskName} ok ${durationMs}ms`);
|
|
4366
4475
|
} else {
|
|
4367
|
-
|
|
4368
|
-
console.error(`[cron] ${taskName} failed ${durationMs}ms: ${error}`, ...stack ? [stack] : []);
|
|
4476
|
+
console.error(`[cron] ${taskName} failed ${durationMs}ms: ${loggableError(thrown)}`);
|
|
4369
4477
|
}
|
|
4370
4478
|
this.sql.exec(
|
|
4371
4479
|
`INSERT INTO cron_history (task_name, started_at, completed_at, success, duration_ms, error, created_at)
|
|
@@ -4548,12 +4656,8 @@ var JobRoom = class extends BaseRoom {
|
|
|
4548
4656
|
next_run_at TEXT
|
|
4549
4657
|
)
|
|
4550
4658
|
`);
|
|
4551
|
-
this.sql.exec(
|
|
4552
|
-
|
|
4553
|
-
);
|
|
4554
|
-
this.sql.exec(
|
|
4555
|
-
`CREATE INDEX IF NOT EXISTS jobs_completed_at ON jobs (completed_at)`
|
|
4556
|
-
);
|
|
4659
|
+
this.sql.exec(`CREATE INDEX IF NOT EXISTS jobs_status_next_run ON jobs (status, next_run_at)`);
|
|
4660
|
+
this.sql.exec(`CREATE INDEX IF NOT EXISTS jobs_completed_at ON jobs (completed_at)`);
|
|
4557
4661
|
this.recoverStuckRunning();
|
|
4558
4662
|
this.scheduleNextAlarm();
|
|
4559
4663
|
}
|
|
@@ -4821,8 +4925,7 @@ var JobRoom = class extends BaseRoom {
|
|
|
4821
4925
|
} catch (e) {
|
|
4822
4926
|
outcome = "failed";
|
|
4823
4927
|
errorMessage = e instanceof Error ? e.message : String(e);
|
|
4824
|
-
|
|
4825
|
-
console.error(`[jobs] ${row.type} (${row.id}) failed: ${errorMessage}`, ...stack ? [stack] : []);
|
|
4928
|
+
console.error(`[jobs] ${row.type} (${row.id}) failed: ${loggableError(e)}`);
|
|
4826
4929
|
} finally {
|
|
4827
4930
|
this.inFlight.delete(row.id);
|
|
4828
4931
|
}
|
|
@@ -6169,7 +6272,7 @@ async function measuredAllocationUsage(bucket, storage, prefixes, excludedMarker
|
|
|
6169
6272
|
);
|
|
6170
6273
|
if (budget.staleKeys.length > 0) {
|
|
6171
6274
|
await bucket.delete(budget.staleKeys).catch((error) => {
|
|
6172
|
-
console.error(
|
|
6275
|
+
console.error(`[files:quota] stale marker cleanup: ${loggableError(error)}`);
|
|
6173
6276
|
});
|
|
6174
6277
|
}
|
|
6175
6278
|
return total;
|
|
@@ -6229,7 +6332,7 @@ async function markQuotaDirty(bucket, storage) {
|
|
|
6229
6332
|
}
|
|
6230
6333
|
console.error("[files:quota] could not mark summary reclaimable after concurrent writes");
|
|
6231
6334
|
} catch (error) {
|
|
6232
|
-
console.error(
|
|
6335
|
+
console.error(`[files:quota] could not mark summary reclaimable: ${loggableError(error)}`);
|
|
6233
6336
|
}
|
|
6234
6337
|
}
|
|
6235
6338
|
async function neutralizeMarker(bucket, markerKey) {
|
|
@@ -6269,7 +6372,7 @@ async function releaseQuotaMarker(bucket, storage, markerKey, summaryMayBeStale)
|
|
|
6269
6372
|
}
|
|
6270
6373
|
return true;
|
|
6271
6374
|
} catch (error) {
|
|
6272
|
-
console.error(
|
|
6375
|
+
console.error(`[files:quota] reservation cleanup: ${loggableError(error)}`);
|
|
6273
6376
|
return false;
|
|
6274
6377
|
}
|
|
6275
6378
|
}
|
|
@@ -6299,7 +6402,7 @@ async function readMultipartReservation(bucket, storage, reservationId) {
|
|
|
6299
6402
|
try {
|
|
6300
6403
|
object = await bucket.get(key);
|
|
6301
6404
|
} catch (error) {
|
|
6302
|
-
console.error(
|
|
6405
|
+
console.error(`[files:quota] reservation read: ${loggableError(error)}`);
|
|
6303
6406
|
return "invalid";
|
|
6304
6407
|
}
|
|
6305
6408
|
if (!object) return null;
|
|
@@ -6495,7 +6598,7 @@ async function admitStorage(bucket, storage, incomingBytes, replacedBytes, marke
|
|
|
6495
6598
|
}
|
|
6496
6599
|
return { markerKey: effectiveMarker?.key ?? null };
|
|
6497
6600
|
} catch (error) {
|
|
6498
|
-
console.error(
|
|
6601
|
+
console.error(`[files:quota] admission: ${loggableError(error)}`);
|
|
6499
6602
|
await releaseQuotaMarker(bucket, storage, markerKey, true);
|
|
6500
6603
|
return quotaUnavailable(
|
|
6501
6604
|
"The storage used by this account could not be verified. Retry shortly."
|
|
@@ -6509,7 +6612,7 @@ async function storageUsage(bucket, storage) {
|
|
|
6509
6612
|
const current = await ensureQuotaSummary(bucket, storage, prefixes, "repairDirty");
|
|
6510
6613
|
return current?.summary?.usedBytes ?? null;
|
|
6511
6614
|
} catch (error) {
|
|
6512
|
-
console.error(
|
|
6615
|
+
console.error(`[files:quota] usage: ${loggableError(error)}`);
|
|
6513
6616
|
return null;
|
|
6514
6617
|
}
|
|
6515
6618
|
}
|
|
@@ -7095,7 +7198,7 @@ async function finishCompletedMultipart(bucket, session, reservation, object, au
|
|
|
7095
7198
|
if (current?.etag === object.etag) await bucket.delete(session.key);
|
|
7096
7199
|
remaining = await bucket.head(session.key);
|
|
7097
7200
|
} catch (error) {
|
|
7098
|
-
console.error(
|
|
7201
|
+
console.error(`[files:multipart] invalid object cleanup: ${loggableError(error)}`);
|
|
7099
7202
|
return quotaUnavailable("The invalid assembled file could not be removed. Retry completion.");
|
|
7100
7203
|
}
|
|
7101
7204
|
if (remaining?.etag === object.etag) {
|
|
@@ -8112,8 +8215,7 @@ async function prepareMessagesWithCompaction(messages, config, options) {
|
|
|
8112
8215
|
};
|
|
8113
8216
|
} catch (err) {
|
|
8114
8217
|
console.error(
|
|
8115
|
-
|
|
8116
|
-
err
|
|
8218
|
+
`prepareMessagesWithCompaction: summarizer failed, falling back to sliding window: ${loggableError(err)}`
|
|
8117
8219
|
);
|
|
8118
8220
|
}
|
|
8119
8221
|
} else {
|
|
@@ -9591,7 +9693,7 @@ async function callDocumentationTool(rawRequest, request2, corpus, env, basePath
|
|
|
9591
9693
|
url: new URL(documentationPublicPath(basePath, page.route), origin).toString()
|
|
9592
9694
|
});
|
|
9593
9695
|
} catch (error) {
|
|
9594
|
-
console.error(
|
|
9696
|
+
console.error(`[documentation-mcp] page unavailable: ${loggableError(error)}`);
|
|
9595
9697
|
return toolError(request2.id, "The documentation page could not be read");
|
|
9596
9698
|
}
|
|
9597
9699
|
}
|
|
@@ -10065,7 +10167,9 @@ function createDeepSpaceAuth(config) {
|
|
|
10065
10167
|
try {
|
|
10066
10168
|
return { clientId: apple.clientId, clientSecret: await generateAppleClientSecret(apple) };
|
|
10067
10169
|
} catch (err) {
|
|
10068
|
-
console.error(
|
|
10170
|
+
console.error(
|
|
10171
|
+
`[deepspace] failed to mint Apple client secret; Apple sign-in disabled: ${loggableError(err)}`
|
|
10172
|
+
);
|
|
10069
10173
|
return { clientId: apple.clientId, clientSecret: "" };
|
|
10070
10174
|
}
|
|
10071
10175
|
};
|
|
@@ -10140,7 +10244,9 @@ function buildDatabaseHooks(onUserCreated) {
|
|
|
10140
10244
|
ctx ? { request: ctx.request, headers: ctx.headers ?? void 0 } : null
|
|
10141
10245
|
);
|
|
10142
10246
|
} catch (err) {
|
|
10143
|
-
console.error(
|
|
10247
|
+
console.error(
|
|
10248
|
+
`[deepspace] onUserCreated hook failed (signup unaffected): ${loggableError(err)}`
|
|
10249
|
+
);
|
|
10144
10250
|
}
|
|
10145
10251
|
}
|
|
10146
10252
|
}
|
|
@@ -10161,92 +10267,6 @@ async function generateAppleClientSecret(apple) {
|
|
|
10161
10267
|
return token;
|
|
10162
10268
|
}
|
|
10163
10269
|
|
|
10164
|
-
// src/shared/client-errors.ts
|
|
10165
|
-
var CLIENT_LOG_MARKER = "[deepspace:client-error]";
|
|
10166
|
-
var CLIENT_ERROR_PATH = "/_deepspace/client-errors";
|
|
10167
|
-
var CLIENT_ERROR_CAPS = {
|
|
10168
|
-
message: 1024,
|
|
10169
|
-
stack: 4096,
|
|
10170
|
-
name: 256,
|
|
10171
|
-
url: 512
|
|
10172
|
-
};
|
|
10173
|
-
function capText(value, max) {
|
|
10174
|
-
if (typeof value !== "string") return void 0;
|
|
10175
|
-
return value.length > max ? value.slice(0, max) : value;
|
|
10176
|
-
}
|
|
10177
|
-
function finiteNumber(value) {
|
|
10178
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
10179
|
-
}
|
|
10180
|
-
function normalizeClientErrorReport(raw) {
|
|
10181
|
-
if (typeof raw !== "object" || raw === null) return null;
|
|
10182
|
-
const o = raw;
|
|
10183
|
-
const kind = o.kind === "unhandledrejection" || o.kind === "react" ? o.kind : "error";
|
|
10184
|
-
const message = capText(o.message, CLIENT_ERROR_CAPS.message) ?? "";
|
|
10185
|
-
const name = capText(o.name, CLIENT_ERROR_CAPS.name);
|
|
10186
|
-
const stack = capText(o.stack, CLIENT_ERROR_CAPS.stack);
|
|
10187
|
-
const url = capText(o.url, CLIENT_ERROR_CAPS.url);
|
|
10188
|
-
const line = finiteNumber(o.line);
|
|
10189
|
-
const col = finiteNumber(o.col);
|
|
10190
|
-
if (!message && !stack) return null;
|
|
10191
|
-
const report = { kind, message: message || (name ?? "Error") };
|
|
10192
|
-
if (name) report.name = name;
|
|
10193
|
-
if (stack) report.stack = stack;
|
|
10194
|
-
if (url) report.url = url;
|
|
10195
|
-
if (line !== void 0) report.line = line;
|
|
10196
|
-
if (col !== void 0) report.col = col;
|
|
10197
|
-
return report;
|
|
10198
|
-
}
|
|
10199
|
-
function clientErrorToLogLine(report) {
|
|
10200
|
-
return `${CLIENT_LOG_MARKER} ${JSON.stringify(report)}`;
|
|
10201
|
-
}
|
|
10202
|
-
|
|
10203
|
-
// src/server/client-errors.ts
|
|
10204
|
-
var THROTTLE_WINDOW_MS = 1e3;
|
|
10205
|
-
var THROTTLE_MAX = 20;
|
|
10206
|
-
var windowStart = 0;
|
|
10207
|
-
var windowCount = 0;
|
|
10208
|
-
var MAX_BODY_BYTES = 64 * 1024;
|
|
10209
|
-
function shouldThrottleClientError(now = Date.now()) {
|
|
10210
|
-
if (now - windowStart >= THROTTLE_WINDOW_MS) {
|
|
10211
|
-
windowStart = now;
|
|
10212
|
-
windowCount = 0;
|
|
10213
|
-
}
|
|
10214
|
-
windowCount += 1;
|
|
10215
|
-
return windowCount > THROTTLE_MAX;
|
|
10216
|
-
}
|
|
10217
|
-
function jsonResponse2(body, status) {
|
|
10218
|
-
return new Response(JSON.stringify(body), {
|
|
10219
|
-
status,
|
|
10220
|
-
headers: { "Content-Type": "application/json" }
|
|
10221
|
-
});
|
|
10222
|
-
}
|
|
10223
|
-
async function handleClientErrorReport(request2) {
|
|
10224
|
-
const site = request2.headers.get("sec-fetch-site");
|
|
10225
|
-
if (site && site !== "same-origin" && site !== "none") {
|
|
10226
|
-
return new Response(null, { status: 403 });
|
|
10227
|
-
}
|
|
10228
|
-
if (shouldThrottleClientError()) {
|
|
10229
|
-
return new Response(null, { status: 429, headers: { "Retry-After": "1" } });
|
|
10230
|
-
}
|
|
10231
|
-
const declared = Number(request2.headers.get("content-length"));
|
|
10232
|
-
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) {
|
|
10233
|
-
return jsonResponse2({ error: "payload_too_large" }, 413);
|
|
10234
|
-
}
|
|
10235
|
-
let body;
|
|
10236
|
-
try {
|
|
10237
|
-
body = await request2.json();
|
|
10238
|
-
} catch {
|
|
10239
|
-
return jsonResponse2({ error: "invalid_json" }, 400);
|
|
10240
|
-
}
|
|
10241
|
-
const report = normalizeClientErrorReport(body);
|
|
10242
|
-
if (!report) return jsonResponse2({ error: "invalid_report" }, 400);
|
|
10243
|
-
console.error(clientErrorToLogLine(report));
|
|
10244
|
-
return new Response(null, { status: 204 });
|
|
10245
|
-
}
|
|
10246
|
-
function registerClientErrorRoute(app) {
|
|
10247
|
-
app.post(CLIENT_ERROR_PATH, (c) => handleClientErrorReport(c.req.raw));
|
|
10248
|
-
}
|
|
10249
|
-
|
|
10250
10270
|
// src/server/agent-tools.ts
|
|
10251
10271
|
import { asSchema } from "ai";
|
|
10252
10272
|
|
|
@@ -10255,7 +10275,7 @@ var AGENT_TOOL_REQUEST_BODY_CAP = 64 * 1024;
|
|
|
10255
10275
|
var AGENT_TOOL_RESPONSE_BODY_CAP = 1024 * 1024;
|
|
10256
10276
|
|
|
10257
10277
|
// src/server/agent-tools.ts
|
|
10258
|
-
function
|
|
10278
|
+
function jsonResponse2(body, status = 200) {
|
|
10259
10279
|
return rawJsonResponse(JSON.stringify(body), status);
|
|
10260
10280
|
}
|
|
10261
10281
|
function rawJsonResponse(body, status = 200) {
|
|
@@ -10284,7 +10304,7 @@ function errorResponse(status, code, detail) {
|
|
|
10284
10304
|
tool_result_too_large: "The tool returned a result that is too large."
|
|
10285
10305
|
};
|
|
10286
10306
|
const error = detail ? `${errors[code]} ${detail}` : errors[code];
|
|
10287
|
-
return
|
|
10307
|
+
return jsonResponse2({ ok: false, code, error }, status);
|
|
10288
10308
|
}
|
|
10289
10309
|
function validationDetail(error) {
|
|
10290
10310
|
const issues = error.issues;
|
|
@@ -10521,19 +10541,19 @@ function normalizeAgentTargetOrigin(value, policy) {
|
|
|
10521
10541
|
// src/shared/auth-session.ts
|
|
10522
10542
|
var SESSION_COOKIE = "__Secure-better-auth.session_token";
|
|
10523
10543
|
|
|
10524
|
-
// src/
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
|
|
10544
|
+
// src/server/worker-error.ts
|
|
10545
|
+
function workerErrorHandler(prefix, respond = (c) => c.text("Internal Server Error", 500)) {
|
|
10546
|
+
return (err, c) => {
|
|
10547
|
+
if ("getResponse" in err) {
|
|
10548
|
+
const res = err.getResponse();
|
|
10549
|
+
return c.newResponse(res.body, res);
|
|
10550
|
+
}
|
|
10551
|
+
console.error(
|
|
10552
|
+
`[${prefix}] ${c.req.method} ${new URL(c.req.url).pathname}: ${loggableError(err)}`
|
|
10553
|
+
);
|
|
10554
|
+
return respond(c);
|
|
10555
|
+
};
|
|
10556
|
+
}
|
|
10537
10557
|
export {
|
|
10538
10558
|
ACCOUNT_STORAGE_LIMIT_BYTES,
|
|
10539
10559
|
ACTION_ROUTES_BEARER_GUARD_MIGRATION_ID,
|
|
@@ -10559,7 +10579,6 @@ export {
|
|
|
10559
10579
|
BaseRoom,
|
|
10560
10580
|
CHANNELS_SCHEMA,
|
|
10561
10581
|
CHANNEL_MEMBERS_SCHEMA,
|
|
10562
|
-
CLIENT_LOG_MARKER,
|
|
10563
10582
|
COST_RATES,
|
|
10564
10583
|
CanvasRoom,
|
|
10565
10584
|
CronRoom,
|
|
@@ -10581,6 +10600,7 @@ export {
|
|
|
10581
10600
|
MAX_DELETE_WHERE_LIMIT,
|
|
10582
10601
|
MAX_DEPLOY_ASSET_FILE_BYTES,
|
|
10583
10602
|
MAX_ENV_VAR_BYTES,
|
|
10603
|
+
MAX_LOG_TEXT_LENGTH,
|
|
10584
10604
|
MAX_UPLOAD_PARTS,
|
|
10585
10605
|
MAX_UPLOAD_REQUEST_BYTES,
|
|
10586
10606
|
MESSAGES_SCHEMA,
|
|
@@ -10678,7 +10698,6 @@ export {
|
|
|
10678
10698
|
getMessageType,
|
|
10679
10699
|
getRolePermissions,
|
|
10680
10700
|
handleAwarenessMessage,
|
|
10681
|
-
handleClientErrorReport,
|
|
10682
10701
|
handleSyncMessage,
|
|
10683
10702
|
hasContent,
|
|
10684
10703
|
isAnonymousUserId,
|
|
@@ -10696,6 +10715,8 @@ export {
|
|
|
10696
10715
|
lintSchemas,
|
|
10697
10716
|
listDeepSpaceAgentModels,
|
|
10698
10717
|
loadMessages,
|
|
10718
|
+
logEventText,
|
|
10719
|
+
loggableError,
|
|
10699
10720
|
makeDefaultSummarizer,
|
|
10700
10721
|
matchOrigin,
|
|
10701
10722
|
meterAi,
|
|
@@ -10714,7 +10735,6 @@ export {
|
|
|
10714
10735
|
readVarUint,
|
|
10715
10736
|
readVarUint8Array,
|
|
10716
10737
|
registerAgentToolRoutes,
|
|
10717
|
-
registerClientErrorRoute,
|
|
10718
10738
|
registerDeepSpaceDocumentation,
|
|
10719
10739
|
registryErrorJson,
|
|
10720
10740
|
registryStub,
|
|
@@ -10734,6 +10754,7 @@ export {
|
|
|
10734
10754
|
timingSafeEqualStrings,
|
|
10735
10755
|
toUint8Array,
|
|
10736
10756
|
totalChars,
|
|
10757
|
+
truncateLogText,
|
|
10737
10758
|
truncateOldToolResults,
|
|
10738
10759
|
turnsToCoreMessages,
|
|
10739
10760
|
unwrapToolOutput,
|
|
@@ -10744,6 +10765,7 @@ export {
|
|
|
10744
10765
|
validateDoManifest,
|
|
10745
10766
|
verifyAgentToken,
|
|
10746
10767
|
verifyJwt,
|
|
10768
|
+
workerErrorHandler,
|
|
10747
10769
|
writeVarUint,
|
|
10748
10770
|
writeVarUint8Array
|
|
10749
10771
|
};
|