@alook/daemon 0.1.19 → 0.1.21
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/cli/index.js +172 -13
- package/dist/index.js +2301 -72
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,6 +12,85 @@ var __export = (target, all) => {
|
|
|
12
12
|
set: __exportSetter.bind(all, name)
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/url-alphabet/index.js
|
|
18
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
19
|
+
|
|
20
|
+
// ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/index.js
|
|
21
|
+
import { webcrypto as crypto2 } from "node:crypto";
|
|
22
|
+
function fillPool(bytes) {
|
|
23
|
+
if (bytes < 0)
|
|
24
|
+
throw new RangeError("Wrong ID size");
|
|
25
|
+
try {
|
|
26
|
+
if (!pool || pool.length < bytes) {
|
|
27
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
28
|
+
crypto2.getRandomValues(pool);
|
|
29
|
+
poolOffset = 0;
|
|
30
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
31
|
+
crypto2.getRandomValues(pool);
|
|
32
|
+
poolOffset = 0;
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
pool = undefined;
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
poolOffset += bytes;
|
|
39
|
+
}
|
|
40
|
+
function random(bytes) {
|
|
41
|
+
fillPool(bytes |= 0);
|
|
42
|
+
return pool.subarray(poolOffset - bytes, poolOffset);
|
|
43
|
+
}
|
|
44
|
+
function customRandom(alphabet, defaultSize, getRandom) {
|
|
45
|
+
let safeByteCutoff = 256 - 256 % alphabet.length;
|
|
46
|
+
if (safeByteCutoff === 256) {
|
|
47
|
+
let mask = alphabet.length - 1;
|
|
48
|
+
return (size = defaultSize) => {
|
|
49
|
+
if (!size)
|
|
50
|
+
return "";
|
|
51
|
+
let id = "";
|
|
52
|
+
while (true) {
|
|
53
|
+
let bytes = getRandom(size);
|
|
54
|
+
let i = size;
|
|
55
|
+
while (i--) {
|
|
56
|
+
id += alphabet[bytes[i] & mask];
|
|
57
|
+
if (id.length >= size)
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
let step = Math.ceil(1.6 * 256 * defaultSize / safeByteCutoff);
|
|
64
|
+
return (size = defaultSize) => {
|
|
65
|
+
if (!size)
|
|
66
|
+
return "";
|
|
67
|
+
let id = "";
|
|
68
|
+
while (true) {
|
|
69
|
+
let bytes = getRandom(step);
|
|
70
|
+
let i = step;
|
|
71
|
+
while (i--) {
|
|
72
|
+
if (bytes[i] < safeByteCutoff) {
|
|
73
|
+
id += alphabet[bytes[i] % alphabet.length];
|
|
74
|
+
if (id.length >= size)
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function customAlphabet(alphabet, size = 21) {
|
|
82
|
+
return customRandom(alphabet, size, random);
|
|
83
|
+
}
|
|
84
|
+
function nanoid3(size = 21) {
|
|
85
|
+
fillPool(size |= 0);
|
|
86
|
+
let id = "";
|
|
87
|
+
for (let i = poolOffset - size;i < poolOffset; i++) {
|
|
88
|
+
id += urlAlphabet[pool[i] & 63];
|
|
89
|
+
}
|
|
90
|
+
return id;
|
|
91
|
+
}
|
|
92
|
+
var POOL_SIZE_MULTIPLIER = 128, pool, poolOffset;
|
|
93
|
+
var init_nanoid = () => {};
|
|
15
94
|
// agent-driver/dist/host/default-host.js
|
|
16
95
|
import { randomUUID } from "node:crypto";
|
|
17
96
|
function createDefaultAgentDriverHost(options = {}) {
|
|
@@ -7914,14 +7993,14 @@ class AgentProcessManager {
|
|
|
7914
7993
|
const effects = this.dispatch({ type: "wake", agentId, message: normalized, nowMs: this.now() });
|
|
7915
7994
|
return effects.length > 0;
|
|
7916
7995
|
}
|
|
7917
|
-
forgetSession(agentId, barrierType = "reset_session", forgottenSessionId) {
|
|
7918
|
-
if (!this.forgetSessionSources(agentId, barrierType, forgottenSessionId))
|
|
7996
|
+
forgetSession(agentId, barrierType = "reset_session", forgottenSessionId, pendingIdleResetEvent) {
|
|
7997
|
+
if (!this.forgetSessionSources(agentId, barrierType, forgottenSessionId, pendingIdleResetEvent))
|
|
7919
7998
|
return false;
|
|
7920
7999
|
this.dispatch({ type: "reset_session", agentId });
|
|
7921
8000
|
return true;
|
|
7922
8001
|
}
|
|
7923
|
-
forgetSessionSources(agentId, barrierType, forgottenSessionId) {
|
|
7924
|
-
const persisted = this.opts.timeline?.forgetSession(agentId, barrierType, forgottenSessionId);
|
|
8002
|
+
forgetSessionSources(agentId, barrierType, forgottenSessionId, pendingIdleResetEvent) {
|
|
8003
|
+
const persisted = pendingIdleResetEvent ? this.opts.timeline?.forgetSession(agentId, barrierType, forgottenSessionId, pendingIdleResetEvent) : this.opts.timeline?.forgetSession(agentId, barrierType, forgottenSessionId);
|
|
7925
8004
|
if (persisted === false)
|
|
7926
8005
|
return false;
|
|
7927
8006
|
this.resumeSessions.delete(agentId);
|
|
@@ -8500,7 +8579,11 @@ ${this.opts.wakePromptFooter}` : text;
|
|
|
8500
8579
|
break;
|
|
8501
8580
|
case "reset_idle_session": {
|
|
8502
8581
|
const spawnState = this.activeSpawnState.get(effect.agentId);
|
|
8503
|
-
const
|
|
8582
|
+
const completion = {
|
|
8583
|
+
eventId: `bae_${randomUUID5()}`,
|
|
8584
|
+
occurredAt: new Date(this.now()).toISOString()
|
|
8585
|
+
};
|
|
8586
|
+
const persisted = this.forgetSession(effect.agentId, "reset_session", effect.sessionId, completion);
|
|
8504
8587
|
if (!persisted) {
|
|
8505
8588
|
this.log.error("idle session reset barrier was not persisted; reset deferred", {
|
|
8506
8589
|
agentId: effect.agentId,
|
|
@@ -8512,6 +8595,23 @@ ${this.opts.wakePromptFooter}` : text;
|
|
|
8512
8595
|
if (spawnState)
|
|
8513
8596
|
spawnState.discardEvents = true;
|
|
8514
8597
|
this.dispatch({ type: "idle_reset_committed", agentId: effect.agentId, nowMs: this.now() });
|
|
8598
|
+
if (this.opts.onBotAuditEvent) {
|
|
8599
|
+
try {
|
|
8600
|
+
this.opts.onBotAuditEvent(effect.agentId, {
|
|
8601
|
+
kind: "session_reset",
|
|
8602
|
+
payload: { trigger: "idle_timeout" }
|
|
8603
|
+
}, {
|
|
8604
|
+
sessionId: null,
|
|
8605
|
+
launchId: null,
|
|
8606
|
+
...completion
|
|
8607
|
+
});
|
|
8608
|
+
} catch (err) {
|
|
8609
|
+
this.log.debug("audit emit failed (idle session reset)", {
|
|
8610
|
+
agentId: effect.agentId,
|
|
8611
|
+
err: String(err)
|
|
8612
|
+
});
|
|
8613
|
+
}
|
|
8614
|
+
}
|
|
8515
8615
|
this.log.info("idle agent session reset", {
|
|
8516
8616
|
agentId: effect.agentId,
|
|
8517
8617
|
sessionId: effect.sessionId
|
|
@@ -23384,6 +23484,18 @@ function formatHandle(name, discriminator) {
|
|
|
23384
23484
|
return `${name}#${discriminator}`;
|
|
23385
23485
|
}
|
|
23386
23486
|
|
|
23487
|
+
// ../shared/src/db/community-machine-schema.ts
|
|
23488
|
+
var exports_community_machine_schema = {};
|
|
23489
|
+
__export(exports_community_machine_schema, {
|
|
23490
|
+
communityMachineToken: () => communityMachineToken,
|
|
23491
|
+
communityMachineCredential: () => communityMachineCredential,
|
|
23492
|
+
communityMachine: () => communityMachine,
|
|
23493
|
+
communityDiagnosticReport: () => communityDiagnosticReport,
|
|
23494
|
+
communityBotBinding: () => communityBotBinding,
|
|
23495
|
+
communityAgentRunnerKey: () => communityAgentRunnerKey,
|
|
23496
|
+
DIAGNOSTIC_REPORT_FAILURE_CODES: () => DIAGNOSTIC_REPORT_FAILURE_CODES
|
|
23497
|
+
});
|
|
23498
|
+
|
|
23387
23499
|
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/entity.js
|
|
23388
23500
|
var entityKind = Symbol.for("drizzle:entityKind");
|
|
23389
23501
|
var hasOwnEntityKind = Symbol.for("drizzle:hasOwnEntityKind");
|
|
@@ -23925,6 +24037,9 @@ class Name {
|
|
|
23925
24037
|
return new SQL([this]);
|
|
23926
24038
|
}
|
|
23927
24039
|
}
|
|
24040
|
+
function isDriverValueEncoder(value) {
|
|
24041
|
+
return typeof value === "object" && value !== null && "mapToDriverValue" in value && typeof value.mapToDriverValue === "function";
|
|
24042
|
+
}
|
|
23928
24043
|
var noopDecoder = {
|
|
23929
24044
|
mapFromDriverValue: (value) => value
|
|
23930
24045
|
};
|
|
@@ -24053,6 +24168,67 @@ Subquery.prototype.getSQL = function() {
|
|
|
24053
24168
|
return new SQL([this]);
|
|
24054
24169
|
};
|
|
24055
24170
|
|
|
24171
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/alias.js
|
|
24172
|
+
class ColumnAliasProxyHandler {
|
|
24173
|
+
constructor(table) {
|
|
24174
|
+
this.table = table;
|
|
24175
|
+
}
|
|
24176
|
+
static [entityKind] = "ColumnAliasProxyHandler";
|
|
24177
|
+
get(columnObj, prop) {
|
|
24178
|
+
if (prop === "table") {
|
|
24179
|
+
return this.table;
|
|
24180
|
+
}
|
|
24181
|
+
return columnObj[prop];
|
|
24182
|
+
}
|
|
24183
|
+
}
|
|
24184
|
+
|
|
24185
|
+
class TableAliasProxyHandler {
|
|
24186
|
+
constructor(alias, replaceOriginalName) {
|
|
24187
|
+
this.alias = alias;
|
|
24188
|
+
this.replaceOriginalName = replaceOriginalName;
|
|
24189
|
+
}
|
|
24190
|
+
static [entityKind] = "TableAliasProxyHandler";
|
|
24191
|
+
get(target, prop) {
|
|
24192
|
+
if (prop === Table.Symbol.IsAlias) {
|
|
24193
|
+
return true;
|
|
24194
|
+
}
|
|
24195
|
+
if (prop === Table.Symbol.Name) {
|
|
24196
|
+
return this.alias;
|
|
24197
|
+
}
|
|
24198
|
+
if (this.replaceOriginalName && prop === Table.Symbol.OriginalName) {
|
|
24199
|
+
return this.alias;
|
|
24200
|
+
}
|
|
24201
|
+
if (prop === ViewBaseConfig) {
|
|
24202
|
+
return {
|
|
24203
|
+
...target[ViewBaseConfig],
|
|
24204
|
+
name: this.alias,
|
|
24205
|
+
isAlias: true
|
|
24206
|
+
};
|
|
24207
|
+
}
|
|
24208
|
+
if (prop === Table.Symbol.Columns) {
|
|
24209
|
+
const columns = target[Table.Symbol.Columns];
|
|
24210
|
+
if (!columns) {
|
|
24211
|
+
return columns;
|
|
24212
|
+
}
|
|
24213
|
+
const proxiedColumns = {};
|
|
24214
|
+
Object.keys(columns).map((key) => {
|
|
24215
|
+
proxiedColumns[key] = new Proxy(columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
24216
|
+
});
|
|
24217
|
+
return proxiedColumns;
|
|
24218
|
+
}
|
|
24219
|
+
const value = target[prop];
|
|
24220
|
+
if (is(value, Column)) {
|
|
24221
|
+
return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this)));
|
|
24222
|
+
}
|
|
24223
|
+
return value;
|
|
24224
|
+
}
|
|
24225
|
+
}
|
|
24226
|
+
|
|
24227
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/sqlite-core/alias.js
|
|
24228
|
+
function alias(table, alias2) {
|
|
24229
|
+
return new Proxy(table, new TableAliasProxyHandler(alias2, false));
|
|
24230
|
+
}
|
|
24231
|
+
|
|
24056
24232
|
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/sqlite-core/checks.js
|
|
24057
24233
|
class CheckBuilder {
|
|
24058
24234
|
constructor(name, value) {
|
|
@@ -24757,42 +24933,81 @@ class PrimaryKey {
|
|
|
24757
24933
|
}
|
|
24758
24934
|
}
|
|
24759
24935
|
|
|
24760
|
-
// ../../node_modules/.pnpm/
|
|
24761
|
-
|
|
24762
|
-
|
|
24763
|
-
|
|
24764
|
-
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
24765
|
-
|
|
24766
|
-
// ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/index.js
|
|
24767
|
-
var POOL_SIZE_MULTIPLIER = 128;
|
|
24768
|
-
var pool;
|
|
24769
|
-
var poolOffset;
|
|
24770
|
-
function fillPool(bytes) {
|
|
24771
|
-
if (bytes < 0)
|
|
24772
|
-
throw new RangeError("Wrong ID size");
|
|
24773
|
-
try {
|
|
24774
|
-
if (!pool || pool.length < bytes) {
|
|
24775
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
24776
|
-
crypto.getRandomValues(pool);
|
|
24777
|
-
poolOffset = 0;
|
|
24778
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
24779
|
-
crypto.getRandomValues(pool);
|
|
24780
|
-
poolOffset = 0;
|
|
24781
|
-
}
|
|
24782
|
-
} catch (e) {
|
|
24783
|
-
pool = undefined;
|
|
24784
|
-
throw e;
|
|
24936
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/sql/expressions/conditions.js
|
|
24937
|
+
function bindIfParam(value, column) {
|
|
24938
|
+
if (isDriverValueEncoder(column) && !isSQLWrapper(value) && !is(value, Param) && !is(value, Placeholder) && !is(value, Column) && !is(value, Table) && !is(value, View)) {
|
|
24939
|
+
return new Param(value, column);
|
|
24785
24940
|
}
|
|
24786
|
-
|
|
24941
|
+
return value;
|
|
24787
24942
|
}
|
|
24788
|
-
|
|
24789
|
-
|
|
24790
|
-
|
|
24791
|
-
|
|
24792
|
-
|
|
24943
|
+
var eq = (left, right) => {
|
|
24944
|
+
return sql`${left} = ${bindIfParam(right, left)}`;
|
|
24945
|
+
};
|
|
24946
|
+
function and(...unfilteredConditions) {
|
|
24947
|
+
const conditions = unfilteredConditions.filter((c) => c !== undefined);
|
|
24948
|
+
if (conditions.length === 0) {
|
|
24949
|
+
return;
|
|
24793
24950
|
}
|
|
24794
|
-
|
|
24951
|
+
if (conditions.length === 1) {
|
|
24952
|
+
return new SQL(conditions);
|
|
24953
|
+
}
|
|
24954
|
+
return new SQL([
|
|
24955
|
+
new StringChunk("("),
|
|
24956
|
+
sql.join(conditions, new StringChunk(" and ")),
|
|
24957
|
+
new StringChunk(")")
|
|
24958
|
+
]);
|
|
24795
24959
|
}
|
|
24960
|
+
function isNotNull(value) {
|
|
24961
|
+
return sql`${value} is not null`;
|
|
24962
|
+
}
|
|
24963
|
+
|
|
24964
|
+
// ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@4.20260702.1_@opentelemetry+api@1.9.1_@typ_5aa9492b131e5fac58fa98e88e5c0ad3/node_modules/drizzle-orm/sql/expressions/select.js
|
|
24965
|
+
function desc(column) {
|
|
24966
|
+
return sql`${column} desc`;
|
|
24967
|
+
}
|
|
24968
|
+
|
|
24969
|
+
// ../shared/src/db/community-machine-schema.ts
|
|
24970
|
+
init_nanoid();
|
|
24971
|
+
|
|
24972
|
+
// ../shared/src/db/schema.ts
|
|
24973
|
+
var exports_schema = {};
|
|
24974
|
+
__export(exports_schema, {
|
|
24975
|
+
workspaceInvite: () => workspaceInvite,
|
|
24976
|
+
workspaceFileRequest: () => workspaceFileRequest,
|
|
24977
|
+
workspace: () => workspace,
|
|
24978
|
+
verification: () => verification,
|
|
24979
|
+
user: () => user,
|
|
24980
|
+
taskMessage: () => taskMessage,
|
|
24981
|
+
session: () => session,
|
|
24982
|
+
messageFlag: () => messageFlag,
|
|
24983
|
+
message: () => message,
|
|
24984
|
+
member: () => member,
|
|
24985
|
+
meetingSession: () => meetingSession,
|
|
24986
|
+
machineToken: () => machineToken,
|
|
24987
|
+
machine: () => machine,
|
|
24988
|
+
issueComment: () => issueComment,
|
|
24989
|
+
issue: () => issue2,
|
|
24990
|
+
inboxUnread: () => inboxUnread,
|
|
24991
|
+
emails: () => emails,
|
|
24992
|
+
conversationReadState: () => conversationReadState,
|
|
24993
|
+
conversationMap: () => conversationMap,
|
|
24994
|
+
conversation: () => conversation,
|
|
24995
|
+
channel: () => channel,
|
|
24996
|
+
calendarEvent: () => calendarEvent,
|
|
24997
|
+
artifact: () => artifact,
|
|
24998
|
+
agentWhitelist: () => agentWhitelist,
|
|
24999
|
+
agentTaskQueue: () => agentTaskQueue,
|
|
25000
|
+
agentSkill: () => agentSkill,
|
|
25001
|
+
agentSidebarOrder: () => agentSidebarOrder,
|
|
25002
|
+
agentRuntime: () => agentRuntime,
|
|
25003
|
+
agentPin: () => agentPin,
|
|
25004
|
+
agentLink: () => agentLink,
|
|
25005
|
+
agentEmailAccount: () => agentEmailAccount,
|
|
25006
|
+
agentAccess: () => agentAccess,
|
|
25007
|
+
agent: () => agent,
|
|
25008
|
+
account: () => account
|
|
25009
|
+
});
|
|
25010
|
+
init_nanoid();
|
|
24796
25011
|
|
|
24797
25012
|
// ../shared/src/constants.ts
|
|
24798
25013
|
var TaskStatus = {
|
|
@@ -24855,6 +25070,10 @@ var TERMINAL_MEETING_STATUSES = [
|
|
|
24855
25070
|
MeetingStatus.COMPLETED,
|
|
24856
25071
|
MeetingStatus.FAILED
|
|
24857
25072
|
];
|
|
25073
|
+
var COMMUNITY_BOT_NAME_MIN = 1;
|
|
25074
|
+
var COMMUNITY_BOT_NAME_MAX = 32;
|
|
25075
|
+
var COMMUNITY_BOT_DESCRIPTION_MAX = 1024;
|
|
25076
|
+
var COMMUNITY_BOT_IMAGE_URL_MAX = 2048;
|
|
24858
25077
|
var DEV_PORTS = {
|
|
24859
25078
|
web: 3000,
|
|
24860
25079
|
emailWorker: 8787,
|
|
@@ -26132,7 +26351,7 @@ function createTypingScopeTracker() {
|
|
|
26132
26351
|
};
|
|
26133
26352
|
}
|
|
26134
26353
|
// src/credentials/credentialProxy.ts
|
|
26135
|
-
import * as
|
|
26354
|
+
import * as crypto3 from "crypto";
|
|
26136
26355
|
import * as fs5 from "fs";
|
|
26137
26356
|
import * as http from "http";
|
|
26138
26357
|
import * as https from "https";
|
|
@@ -26149,7 +26368,7 @@ var DEFAULT_HEADER_NAMES = {
|
|
|
26149
26368
|
capabilities: "X-Agent-Active-Capabilities"
|
|
26150
26369
|
};
|
|
26151
26370
|
function randomVoucher(prefix) {
|
|
26152
|
-
return prefix +
|
|
26371
|
+
return prefix + crypto3.randomBytes(32).toString("base64url");
|
|
26153
26372
|
}
|
|
26154
26373
|
function sanitizeIdSegment(id) {
|
|
26155
26374
|
return id.replace(/[^A-Za-z0-9._-]/g, "_") || "_";
|
|
@@ -26828,7 +27047,1902 @@ function writeStatusFile(path9, snapshot) {
|
|
|
26828
27047
|
renameSync2(tmp, path9);
|
|
26829
27048
|
} catch {}
|
|
26830
27049
|
}
|
|
27050
|
+
// ../shared/src/constants/community.ts
|
|
27051
|
+
var MAX_PROFILE_NAME_LENGTH = 100;
|
|
27052
|
+
var MAX_PROFILE_ABOUT_LENGTH = 1000;
|
|
27053
|
+
var MAX_MESSAGE_CONTENT_LENGTH = 4000;
|
|
27054
|
+
var MAX_ATTACHMENTS_PER_MESSAGE = 10;
|
|
27055
|
+
var MAX_ATTACHMENT_SIZE_BYTES = 25 * 1024 * 1024;
|
|
27056
|
+
var MAX_ATTACHMENT_THUMBNAIL_SIZE_BYTES = 50 * 1024;
|
|
27057
|
+
var MAX_SERVER_ICON_SIZE_BYTES = 5 * 1024 * 1024;
|
|
27058
|
+
var ALLOWED_ICON_MIME_TYPES = [
|
|
27059
|
+
"image/png",
|
|
27060
|
+
"image/jpeg",
|
|
27061
|
+
"image/webp",
|
|
27062
|
+
"image/gif"
|
|
27063
|
+
];
|
|
27064
|
+
var MAX_ICON_SOURCE_FILE_SIZE_BYTES = 15 * 1024 * 1024;
|
|
27065
|
+
// ../shared/src/utils/slug.ts
|
|
27066
|
+
init_nanoid();
|
|
27067
|
+
var slugId = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz");
|
|
27068
|
+
function sanitizeSlug(input) {
|
|
27069
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/g, "");
|
|
27070
|
+
}
|
|
27071
|
+
|
|
27072
|
+
// ../shared/src/lib/community-name.ts
|
|
27073
|
+
var FORBIDDEN_NAME_CHARS = /[#@\x00-\x1f\x7f-\x9f]/;
|
|
27074
|
+
function validateCommunityName(name) {
|
|
27075
|
+
const trimmed = name.trim();
|
|
27076
|
+
if (!trimmed)
|
|
27077
|
+
return { ok: false, reason: "name cannot be empty" };
|
|
27078
|
+
if (trimmed.length > MAX_PROFILE_NAME_LENGTH) {
|
|
27079
|
+
return { ok: false, reason: `name must be ≤ ${MAX_PROFILE_NAME_LENGTH} characters` };
|
|
27080
|
+
}
|
|
27081
|
+
if (FORBIDDEN_NAME_CHARS.test(trimmed)) {
|
|
27082
|
+
return { ok: false, reason: "name cannot contain #, @, or line breaks" };
|
|
27083
|
+
}
|
|
27084
|
+
return { ok: true };
|
|
27085
|
+
}
|
|
26831
27086
|
|
|
27087
|
+
// ../shared/src/schemas.ts
|
|
27088
|
+
var TaskStatusSchema = exports_external.enum([
|
|
27089
|
+
"queued",
|
|
27090
|
+
"dispatched",
|
|
27091
|
+
"running",
|
|
27092
|
+
"completed",
|
|
27093
|
+
"failed",
|
|
27094
|
+
"cancelled",
|
|
27095
|
+
"superseded"
|
|
27096
|
+
]);
|
|
27097
|
+
var ClaimedTaskRowSchema = exports_external.object({
|
|
27098
|
+
id: exports_external.string(),
|
|
27099
|
+
agentId: exports_external.string(),
|
|
27100
|
+
runtimeId: exports_external.string(),
|
|
27101
|
+
workspaceId: exports_external.string(),
|
|
27102
|
+
conversationId: exports_external.string(),
|
|
27103
|
+
prompt: exports_external.string(),
|
|
27104
|
+
status: exports_external.string(),
|
|
27105
|
+
priority: exports_external.coerce.number(),
|
|
27106
|
+
result: exports_external.unknown().nullable(),
|
|
27107
|
+
context: exports_external.unknown().nullable(),
|
|
27108
|
+
type: exports_external.string().default(TASK_TYPES.USER_DM_MESSAGE),
|
|
27109
|
+
contextKey: exports_external.string().nullable().optional(),
|
|
27110
|
+
sessionId: exports_external.string().nullable(),
|
|
27111
|
+
createdAt: exports_external.coerce.date(),
|
|
27112
|
+
dispatchedAt: exports_external.coerce.date().nullable(),
|
|
27113
|
+
startedAt: exports_external.coerce.date().nullable(),
|
|
27114
|
+
completedAt: exports_external.coerce.date().nullable(),
|
|
27115
|
+
error: exports_external.string().nullable(),
|
|
27116
|
+
traceId: exports_external.string().nullable().optional(),
|
|
27117
|
+
parentTaskId: exports_external.string().nullable().optional()
|
|
27118
|
+
});
|
|
27119
|
+
var ColleagueDataApiSchema = exports_external.object({
|
|
27120
|
+
name: exports_external.string(),
|
|
27121
|
+
email: exports_external.string(),
|
|
27122
|
+
description: exports_external.string(),
|
|
27123
|
+
instruction: exports_external.string()
|
|
27124
|
+
});
|
|
27125
|
+
var TaskAgentDataApiSchema = exports_external.object({
|
|
27126
|
+
instructions: exports_external.string(),
|
|
27127
|
+
name: exports_external.string(),
|
|
27128
|
+
runtime_config: exports_external.record(exports_external.string(), exports_external.unknown()).default({}),
|
|
27129
|
+
email_handle: exports_external.string().nullable().optional(),
|
|
27130
|
+
email_addresses: exports_external.array(exports_external.string()).default([]),
|
|
27131
|
+
user_email: exports_external.string().nullable().optional(),
|
|
27132
|
+
user_name: exports_external.string().nullable().optional(),
|
|
27133
|
+
colleagues: exports_external.array(ColleagueDataApiSchema).default([])
|
|
27134
|
+
});
|
|
27135
|
+
var TaskApiBaseSchema = exports_external.object({
|
|
27136
|
+
id: exports_external.string(),
|
|
27137
|
+
agent_id: exports_external.string(),
|
|
27138
|
+
runtime_id: exports_external.string(),
|
|
27139
|
+
conversation_id: exports_external.string(),
|
|
27140
|
+
workspace_id: exports_external.string(),
|
|
27141
|
+
prompt: exports_external.string(),
|
|
27142
|
+
status: exports_external.string(),
|
|
27143
|
+
priority: exports_external.number(),
|
|
27144
|
+
dispatched_at: exports_external.string().nullable(),
|
|
27145
|
+
started_at: exports_external.string().nullable(),
|
|
27146
|
+
completed_at: exports_external.string().nullable(),
|
|
27147
|
+
result: exports_external.unknown().nullable(),
|
|
27148
|
+
error: exports_external.string().nullable(),
|
|
27149
|
+
created_at: exports_external.string(),
|
|
27150
|
+
type: exports_external.string(),
|
|
27151
|
+
context_key: exports_external.string().nullable().optional(),
|
|
27152
|
+
context: exports_external.unknown().nullable().optional(),
|
|
27153
|
+
trace_id: exports_external.string().nullable().optional(),
|
|
27154
|
+
parent_task_id: exports_external.string().nullable().optional(),
|
|
27155
|
+
channel: exports_external.string().nullable().optional()
|
|
27156
|
+
});
|
|
27157
|
+
var TaskSenderApiSchema = exports_external.object({
|
|
27158
|
+
name: exports_external.string(),
|
|
27159
|
+
email: exports_external.string(),
|
|
27160
|
+
is_owner: exports_external.boolean()
|
|
27161
|
+
});
|
|
27162
|
+
var TaskApiSchema = TaskApiBaseSchema.extend({
|
|
27163
|
+
agent: TaskAgentDataApiSchema.nullable().optional(),
|
|
27164
|
+
sender: TaskSenderApiSchema.nullable().optional()
|
|
27165
|
+
});
|
|
27166
|
+
var HeartbeatRequestSchema = exports_external.object({
|
|
27167
|
+
daemon_id: exports_external.string().min(1)
|
|
27168
|
+
});
|
|
27169
|
+
var PollRequestSchema = exports_external.object({
|
|
27170
|
+
daemon_id: exports_external.string().min(1),
|
|
27171
|
+
max_tasks: exports_external.number().int().min(1).default(1),
|
|
27172
|
+
cli_version: exports_external.string().optional()
|
|
27173
|
+
});
|
|
27174
|
+
var FileRequestItemSchema = exports_external.object({
|
|
27175
|
+
id: exports_external.string(),
|
|
27176
|
+
agent_id: exports_external.string(),
|
|
27177
|
+
request_type: exports_external.enum(["tree", "read"]),
|
|
27178
|
+
path: exports_external.string()
|
|
27179
|
+
});
|
|
27180
|
+
var PollMeetingItemSchema = exports_external.object({
|
|
27181
|
+
id: exports_external.string(),
|
|
27182
|
+
meeting_url: exports_external.string(),
|
|
27183
|
+
participants: exports_external.array(exports_external.string()),
|
|
27184
|
+
workspace_id: exports_external.string(),
|
|
27185
|
+
agent_id: exports_external.string(),
|
|
27186
|
+
agent_name: exports_external.string(),
|
|
27187
|
+
title: exports_external.string().optional()
|
|
27188
|
+
});
|
|
27189
|
+
var PollResponseSchema = exports_external.object({
|
|
27190
|
+
tasks: exports_external.array(TaskApiSchema),
|
|
27191
|
+
evicted: exports_external.boolean().optional(),
|
|
27192
|
+
pending_update: exports_external.object({ version: exports_external.string() }).optional(),
|
|
27193
|
+
pending_rescan: exports_external.boolean().optional(),
|
|
27194
|
+
file_requests: exports_external.array(FileRequestItemSchema).optional(),
|
|
27195
|
+
meetings: exports_external.array(PollMeetingItemSchema).optional()
|
|
27196
|
+
});
|
|
27197
|
+
var DaemonPushMessageSchema = exports_external.discriminatedUnion("type", [
|
|
27198
|
+
exports_external.object({ type: exports_external.literal("daemon.tasks"), tasks: exports_external.array(TaskApiSchema) }),
|
|
27199
|
+
exports_external.object({ type: exports_external.literal("daemon.file_requests"), workspaceId: exports_external.string(), requests: exports_external.array(FileRequestItemSchema) }),
|
|
27200
|
+
exports_external.object({ type: exports_external.literal("daemon.meetings"), meetings: exports_external.array(PollMeetingItemSchema) }),
|
|
27201
|
+
exports_external.object({ type: exports_external.literal("daemon.evict"), workspaceId: exports_external.string() }),
|
|
27202
|
+
exports_external.object({ type: exports_external.literal("daemon.update"), version: exports_external.string() }),
|
|
27203
|
+
exports_external.object({ type: exports_external.literal("daemon.rescan") }),
|
|
27204
|
+
exports_external.object({ type: exports_external.literal("daemon.kill"), workspaceId: exports_external.string(), agentId: exports_external.string().min(1), taskId: exports_external.string(), targetTaskId: exports_external.string() })
|
|
27205
|
+
]);
|
|
27206
|
+
var RegisterResponseSchema = exports_external.object({
|
|
27207
|
+
runtimes: exports_external.array(exports_external.object({ id: exports_external.string() }))
|
|
27208
|
+
});
|
|
27209
|
+
var DaemonRuntimeItemSchema = exports_external.object({
|
|
27210
|
+
type: exports_external.string().optional(),
|
|
27211
|
+
provider: exports_external.string().optional(),
|
|
27212
|
+
runtime_mode: exports_external.string().optional(),
|
|
27213
|
+
version: exports_external.string().optional(),
|
|
27214
|
+
status: exports_external.string().optional(),
|
|
27215
|
+
model: exports_external.string().optional()
|
|
27216
|
+
});
|
|
27217
|
+
var ActivateTokenRuntimeSchema = exports_external.object({
|
|
27218
|
+
type: exports_external.string().min(1),
|
|
27219
|
+
version: exports_external.string().optional().default("")
|
|
27220
|
+
});
|
|
27221
|
+
var ActivateTokenRequestSchema = exports_external.object({
|
|
27222
|
+
token: exports_external.string().min(1),
|
|
27223
|
+
hostname: exports_external.string().min(1),
|
|
27224
|
+
runtimes: exports_external.array(ActivateTokenRuntimeSchema).min(1)
|
|
27225
|
+
});
|
|
27226
|
+
var RegisterDaemonRequestSchema = exports_external.object({
|
|
27227
|
+
workspace_id: exports_external.string().min(1).optional(),
|
|
27228
|
+
daemon_id: exports_external.string().min(1),
|
|
27229
|
+
device_name: exports_external.string().optional().default(""),
|
|
27230
|
+
cli_version: exports_external.string().optional().default(""),
|
|
27231
|
+
workspaces_root: exports_external.string().optional().default(""),
|
|
27232
|
+
runtimes: exports_external.array(DaemonRuntimeItemSchema).min(1)
|
|
27233
|
+
});
|
|
27234
|
+
var DeregisterRequestSchema = exports_external.object({
|
|
27235
|
+
daemon_id: exports_external.string().min(1)
|
|
27236
|
+
});
|
|
27237
|
+
var CompleteTaskRequestSchema = exports_external.object({
|
|
27238
|
+
output: exports_external.string().optional(),
|
|
27239
|
+
session_id: exports_external.string().optional(),
|
|
27240
|
+
branch_name: exports_external.string().optional()
|
|
27241
|
+
});
|
|
27242
|
+
var FailTaskRequestSchema = exports_external.object({
|
|
27243
|
+
error: exports_external.string().optional().default("")
|
|
27244
|
+
});
|
|
27245
|
+
var MessageItemSchema = exports_external.object({
|
|
27246
|
+
seq: exports_external.number(),
|
|
27247
|
+
type: exports_external.string(),
|
|
27248
|
+
tool: exports_external.string().optional(),
|
|
27249
|
+
call_id: exports_external.string().optional(),
|
|
27250
|
+
content: exports_external.string().optional(),
|
|
27251
|
+
input: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
|
|
27252
|
+
output: exports_external.string().optional()
|
|
27253
|
+
});
|
|
27254
|
+
var ReportMessagesRequestSchema = exports_external.object({
|
|
27255
|
+
messages: exports_external.array(MessageItemSchema)
|
|
27256
|
+
});
|
|
27257
|
+
var RepeatIntervalSchema = exports_external.string().regex(/^\d+(min|hour|day|week|month)$/, {
|
|
27258
|
+
message: "repeat_interval must match <positive_integer><min|hour|day|week|month>"
|
|
27259
|
+
});
|
|
27260
|
+
var CreateCalendarEventRequestSchema = exports_external.object({
|
|
27261
|
+
agent_id: exports_external.string().min(1),
|
|
27262
|
+
title: exports_external.string().min(1),
|
|
27263
|
+
description: exports_external.string().max(20000).optional(),
|
|
27264
|
+
scheduled_at: exports_external.string().min(1).refine((s) => !Number.isNaN(Date.parse(s)), {
|
|
27265
|
+
message: "scheduled_at must be a valid ISO datetime"
|
|
27266
|
+
}),
|
|
27267
|
+
repeat_interval: RepeatIntervalSchema.optional(),
|
|
27268
|
+
repeat_stop_date: exports_external.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
27269
|
+
conversation_id: exports_external.string().optional()
|
|
27270
|
+
}).refine((data) => !data.repeat_stop_date || !!data.repeat_interval, {
|
|
27271
|
+
message: "repeat_stop_date requires repeat_interval",
|
|
27272
|
+
path: ["repeat_stop_date"]
|
|
27273
|
+
});
|
|
27274
|
+
var UpdateCalendarEventRequestSchema = exports_external.object({
|
|
27275
|
+
title: exports_external.string().min(1).optional(),
|
|
27276
|
+
description: exports_external.string().max(20000).nullable().optional(),
|
|
27277
|
+
agent_id: exports_external.string().min(1).optional(),
|
|
27278
|
+
scheduled_at: exports_external.string().min(1).refine((s) => !Number.isNaN(Date.parse(s)), {
|
|
27279
|
+
message: "scheduled_at must be a valid ISO datetime"
|
|
27280
|
+
}).optional(),
|
|
27281
|
+
repeat_interval: RepeatIntervalSchema.nullable().optional(),
|
|
27282
|
+
repeat_stop_date: exports_external.string().regex(/^\d{4}-\d{2}-\d{2}$/).nullable().optional(),
|
|
27283
|
+
scope: exports_external.enum(["this", "following"]).optional(),
|
|
27284
|
+
occurrence_at: exports_external.string().min(1).refine((s) => !Number.isNaN(Date.parse(s)), {
|
|
27285
|
+
message: "occurrence_at must be a valid ISO datetime"
|
|
27286
|
+
}).optional()
|
|
27287
|
+
}).refine((v) => v.title !== undefined || v.description !== undefined || v.agent_id !== undefined || v.scheduled_at !== undefined || v.repeat_interval !== undefined || v.repeat_stop_date !== undefined, { message: "at least one field is required" });
|
|
27288
|
+
var DeleteCalendarEventRequestSchema = exports_external.object({
|
|
27289
|
+
scope: exports_external.enum(["this", "following"]).optional(),
|
|
27290
|
+
occurrence_at: exports_external.string().min(1).refine((s) => !Number.isNaN(Date.parse(s)), {
|
|
27291
|
+
message: "occurrence_at must be a valid ISO datetime"
|
|
27292
|
+
}).optional()
|
|
27293
|
+
});
|
|
27294
|
+
var CalendarEventApiSchema = exports_external.object({
|
|
27295
|
+
id: exports_external.string(),
|
|
27296
|
+
agent_id: exports_external.string(),
|
|
27297
|
+
workspace_id: exports_external.string(),
|
|
27298
|
+
title: exports_external.string(),
|
|
27299
|
+
description: exports_external.string().nullable(),
|
|
27300
|
+
scheduled_at: exports_external.string(),
|
|
27301
|
+
occurrence_at: exports_external.string(),
|
|
27302
|
+
collapsed_count: exports_external.number().nullable().optional(),
|
|
27303
|
+
repeat_interval: exports_external.string().nullable(),
|
|
27304
|
+
repeat_stop_at: exports_external.string().nullable(),
|
|
27305
|
+
last_triggered_at: exports_external.string().nullable(),
|
|
27306
|
+
created_at: exports_external.string(),
|
|
27307
|
+
updated_at: exports_external.string()
|
|
27308
|
+
});
|
|
27309
|
+
var IssueStatusSchema = exports_external.enum([
|
|
27310
|
+
IssueStatus.TODO,
|
|
27311
|
+
IssueStatus.IN_PROGRESS,
|
|
27312
|
+
IssueStatus.REVIEW,
|
|
27313
|
+
IssueStatus.DONE,
|
|
27314
|
+
IssueStatus.CLOSED,
|
|
27315
|
+
IssueStatus.CANCELED,
|
|
27316
|
+
IssueStatus.FAILED
|
|
27317
|
+
]);
|
|
27318
|
+
var CreateIssueRequestSchema = exports_external.object({
|
|
27319
|
+
agent_id: exports_external.string().min(1).optional(),
|
|
27320
|
+
title: exports_external.string().min(1, "title is required").max(200),
|
|
27321
|
+
description: exports_external.string().max(20000).optional().default("")
|
|
27322
|
+
});
|
|
27323
|
+
var UpdateIssueRequestSchema = exports_external.object({
|
|
27324
|
+
title: exports_external.string().min(1).max(200).optional(),
|
|
27325
|
+
description: exports_external.string().max(20000).optional(),
|
|
27326
|
+
status: IssueStatusSchema.optional(),
|
|
27327
|
+
agent_id: exports_external.string().min(1).optional()
|
|
27328
|
+
}).refine((v) => v.title !== undefined || v.description !== undefined || v.status !== undefined || v.agent_id !== undefined, { message: "at least one field is required" });
|
|
27329
|
+
var CreateIssueCommentBodySchema = exports_external.object({
|
|
27330
|
+
content: exports_external.string().min(1, "content is required").max(20000)
|
|
27331
|
+
});
|
|
27332
|
+
var IssueCommentApiSchema = exports_external.object({
|
|
27333
|
+
id: exports_external.string(),
|
|
27334
|
+
issue_id: exports_external.string(),
|
|
27335
|
+
workspace_id: exports_external.string(),
|
|
27336
|
+
author_type: exports_external.enum(["user", "agent"]),
|
|
27337
|
+
author_id: exports_external.string(),
|
|
27338
|
+
content: exports_external.string(),
|
|
27339
|
+
created_at: exports_external.string()
|
|
27340
|
+
});
|
|
27341
|
+
var IssueApiSchema = exports_external.object({
|
|
27342
|
+
id: exports_external.string(),
|
|
27343
|
+
workspace_id: exports_external.string(),
|
|
27344
|
+
agent_id: exports_external.string().nullable(),
|
|
27345
|
+
creator_user_id: exports_external.string(),
|
|
27346
|
+
conversation_id: exports_external.string().nullable(),
|
|
27347
|
+
latest_task_id: exports_external.string().nullable(),
|
|
27348
|
+
title: exports_external.string(),
|
|
27349
|
+
description: exports_external.string(),
|
|
27350
|
+
status: IssueStatusSchema,
|
|
27351
|
+
created_at: exports_external.string(),
|
|
27352
|
+
updated_at: exports_external.string(),
|
|
27353
|
+
completed_at: exports_external.string().nullable()
|
|
27354
|
+
});
|
|
27355
|
+
var CreateAgentLinkRequestSchema = exports_external.object({
|
|
27356
|
+
source_agent_id: exports_external.string().min(1, "source_agent_id is required"),
|
|
27357
|
+
target_agent_id: exports_external.string().min(1, "target_agent_id is required"),
|
|
27358
|
+
instruction: exports_external.string().optional().default("")
|
|
27359
|
+
});
|
|
27360
|
+
var UpdateAgentLinkRequestSchema = exports_external.object({
|
|
27361
|
+
instruction: exports_external.string()
|
|
27362
|
+
});
|
|
27363
|
+
var UpsertAgentLinkRequestSchema = exports_external.object({
|
|
27364
|
+
target_agent_id: exports_external.string().min(1, "target_agent_id is required"),
|
|
27365
|
+
instruction: exports_external.string()
|
|
27366
|
+
});
|
|
27367
|
+
var AddWhitelistRequestSchema = exports_external.object({
|
|
27368
|
+
email: exports_external.string().email()
|
|
27369
|
+
});
|
|
27370
|
+
var RuntimeConfigSchema = exports_external.object({ model: exports_external.string().max(100).optional() }).passthrough().optional();
|
|
27371
|
+
var CreateAgentRequestSchema = exports_external.object({
|
|
27372
|
+
name: exports_external.string().min(1, "name is required"),
|
|
27373
|
+
description: exports_external.string().optional().default(""),
|
|
27374
|
+
instructions: exports_external.string().optional().default(""),
|
|
27375
|
+
runtime_id: exports_external.string().min(1, "runtime_id is required"),
|
|
27376
|
+
runtime_config: RuntimeConfigSchema,
|
|
27377
|
+
max_concurrent_tasks: exports_external.number().int().optional(),
|
|
27378
|
+
email_handle: exports_external.string().optional(),
|
|
27379
|
+
avatar_url: exports_external.string().max(2000).nullable().optional()
|
|
27380
|
+
});
|
|
27381
|
+
var UpdateAgentRequestSchema = exports_external.object({
|
|
27382
|
+
name: exports_external.string().min(1).optional(),
|
|
27383
|
+
description: exports_external.string().optional(),
|
|
27384
|
+
instructions: exports_external.string().optional(),
|
|
27385
|
+
runtime_id: exports_external.string().min(1).optional(),
|
|
27386
|
+
runtime_config: RuntimeConfigSchema,
|
|
27387
|
+
visibility: exports_external.enum(["public", "private"]).optional(),
|
|
27388
|
+
avatar_url: exports_external.string().max(2000).nullable().optional()
|
|
27389
|
+
}).refine((v) => v.name !== undefined || v.description !== undefined || v.instructions !== undefined || v.runtime_id !== undefined || v.runtime_config !== undefined || v.visibility !== undefined || v.avatar_url !== undefined, { message: "at least one field is required" });
|
|
27390
|
+
var CreateConversationRequestSchema = exports_external.object({
|
|
27391
|
+
agent_id: exports_external.string().min(1, "agent_id is required"),
|
|
27392
|
+
channel: exports_external.string().optional()
|
|
27393
|
+
});
|
|
27394
|
+
var CreateMessageRequestSchema = exports_external.object({
|
|
27395
|
+
content: exports_external.string().min(1, "content is required"),
|
|
27396
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
27397
|
+
});
|
|
27398
|
+
var AgentDmRequestSchema = exports_external.object({
|
|
27399
|
+
content: exports_external.string().min(1, "content is required"),
|
|
27400
|
+
task_id: exports_external.string().min(1).optional()
|
|
27401
|
+
});
|
|
27402
|
+
var EmailAttachmentSchema = exports_external.object({
|
|
27403
|
+
key: exports_external.string().min(1),
|
|
27404
|
+
filename: exports_external.string().min(1),
|
|
27405
|
+
size: exports_external.number().int().nonnegative().optional(),
|
|
27406
|
+
contentType: exports_external.string().min(1)
|
|
27407
|
+
});
|
|
27408
|
+
var SendEmailRequestSchema = exports_external.object({
|
|
27409
|
+
agentId: exports_external.string().min(1, "agentId is required"),
|
|
27410
|
+
to: exports_external.string().min(1, "to is required"),
|
|
27411
|
+
subject: exports_external.string().min(1, "subject is required"),
|
|
27412
|
+
htmlBody: exports_external.string().default(""),
|
|
27413
|
+
inReplyTo: exports_external.string().optional(),
|
|
27414
|
+
references: exports_external.string().optional(),
|
|
27415
|
+
attachments: exports_external.array(EmailAttachmentSchema).optional(),
|
|
27416
|
+
customAccountId: exports_external.string().optional(),
|
|
27417
|
+
from: exports_external.string().email().optional(),
|
|
27418
|
+
conversationId: exports_external.string().optional(),
|
|
27419
|
+
traceId: exports_external.string().optional(),
|
|
27420
|
+
sourceTaskId: exports_external.string().optional()
|
|
27421
|
+
});
|
|
27422
|
+
var UpdateEmailStatusRequestSchema = exports_external.object({
|
|
27423
|
+
status: exports_external.enum(["unread", "read", "archived", "sent"])
|
|
27424
|
+
});
|
|
27425
|
+
var MeetingInfoSchema = exports_external.object({
|
|
27426
|
+
title: exports_external.string(),
|
|
27427
|
+
meetingUrl: exports_external.string(),
|
|
27428
|
+
startTime: exports_external.string().nullable(),
|
|
27429
|
+
endTime: exports_external.string().nullable(),
|
|
27430
|
+
attendees: exports_external.array(exports_external.object({ name: exports_external.string(), email: exports_external.string() }))
|
|
27431
|
+
});
|
|
27432
|
+
var EmailNotifyRequestSchema = exports_external.object({
|
|
27433
|
+
agentId: exports_external.string().min(1),
|
|
27434
|
+
workspaceId: exports_external.string().min(1),
|
|
27435
|
+
r2Key: exports_external.string().min(1),
|
|
27436
|
+
from: exports_external.string().min(1),
|
|
27437
|
+
to: exports_external.string().optional(),
|
|
27438
|
+
subject: exports_external.string(),
|
|
27439
|
+
isWhitelisted: exports_external.boolean(),
|
|
27440
|
+
forwarded: exports_external.boolean().optional().default(false),
|
|
27441
|
+
messageId: exports_external.string().optional().default(""),
|
|
27442
|
+
inReplyTo: exports_external.string().optional().default(""),
|
|
27443
|
+
references: exports_external.string().optional().default(""),
|
|
27444
|
+
meetingInfo: MeetingInfoSchema.nullable().optional(),
|
|
27445
|
+
attachments: exports_external.string().optional(),
|
|
27446
|
+
traceId: exports_external.string().optional(),
|
|
27447
|
+
sourceTaskId: exports_external.string().optional(),
|
|
27448
|
+
isInternal: exports_external.boolean().optional().default(false),
|
|
27449
|
+
senderConversationId: exports_external.string().optional(),
|
|
27450
|
+
senderAgentId: exports_external.string().optional()
|
|
27451
|
+
});
|
|
27452
|
+
var CreateEmailAccountSchema = exports_external.object({
|
|
27453
|
+
emailAddress: exports_external.string().email("valid email required"),
|
|
27454
|
+
displayName: exports_external.string().default(""),
|
|
27455
|
+
imapHost: exports_external.string().min(1, "IMAP host is required"),
|
|
27456
|
+
imapPort: exports_external.number().int().min(1).max(65535).default(993),
|
|
27457
|
+
imapUsername: exports_external.string().min(1, "IMAP username is required"),
|
|
27458
|
+
imapPassword: exports_external.string().min(1, "IMAP password is required"),
|
|
27459
|
+
imapTls: exports_external.boolean().default(true),
|
|
27460
|
+
smtpHost: exports_external.string().min(1, "SMTP host is required"),
|
|
27461
|
+
smtpPort: exports_external.number().int().min(1).max(65535).default(587),
|
|
27462
|
+
smtpUsername: exports_external.string().min(1, "SMTP username is required"),
|
|
27463
|
+
smtpPassword: exports_external.string().min(1, "SMTP password is required"),
|
|
27464
|
+
smtpTls: exports_external.number().int().min(0).max(2).default(1),
|
|
27465
|
+
pollIntervalSeconds: exports_external.number().int().min(30).max(3600).default(60)
|
|
27466
|
+
});
|
|
27467
|
+
var UpdateEmailAccountSchema = exports_external.object({
|
|
27468
|
+
emailAddress: exports_external.string().email().optional(),
|
|
27469
|
+
displayName: exports_external.string().optional(),
|
|
27470
|
+
imapHost: exports_external.string().min(1).optional(),
|
|
27471
|
+
imapPort: exports_external.number().int().min(1).max(65535).optional(),
|
|
27472
|
+
imapUsername: exports_external.string().min(1).optional(),
|
|
27473
|
+
imapPassword: exports_external.string().min(1).optional(),
|
|
27474
|
+
imapTls: exports_external.boolean().optional(),
|
|
27475
|
+
smtpHost: exports_external.string().min(1).optional(),
|
|
27476
|
+
smtpPort: exports_external.number().int().min(1).max(65535).optional(),
|
|
27477
|
+
smtpUsername: exports_external.string().min(1).optional(),
|
|
27478
|
+
smtpPassword: exports_external.string().min(1).optional(),
|
|
27479
|
+
smtpTls: exports_external.number().int().min(0).max(2).optional(),
|
|
27480
|
+
pollIntervalSeconds: exports_external.number().int().min(30).max(3600).optional()
|
|
27481
|
+
});
|
|
27482
|
+
var TestEmailConnectionSchema = exports_external.object({
|
|
27483
|
+
imapHost: exports_external.string().min(1),
|
|
27484
|
+
imapPort: exports_external.number().int().min(1).max(65535).default(993),
|
|
27485
|
+
imapUsername: exports_external.string().min(1),
|
|
27486
|
+
imapPassword: exports_external.string().min(1),
|
|
27487
|
+
imapTls: exports_external.boolean().default(true),
|
|
27488
|
+
smtpHost: exports_external.string().min(1),
|
|
27489
|
+
smtpPort: exports_external.number().int().min(1).max(65535).default(587),
|
|
27490
|
+
smtpUsername: exports_external.string().min(1),
|
|
27491
|
+
smtpPassword: exports_external.string().min(1),
|
|
27492
|
+
smtpTls: exports_external.number().int().min(0).max(2).default(1)
|
|
27493
|
+
});
|
|
27494
|
+
var UpdateMemberRequestSchema = exports_external.object({
|
|
27495
|
+
global_instruction: exports_external.string().max(50000).trim()
|
|
27496
|
+
});
|
|
27497
|
+
var CreateWorkspaceRequestSchema = exports_external.object({
|
|
27498
|
+
name: exports_external.string().min(1, "name is required"),
|
|
27499
|
+
slug: exports_external.string().optional().default("").transform(sanitizeSlug)
|
|
27500
|
+
});
|
|
27501
|
+
var UpdateWorkspaceRequestSchema = exports_external.object({
|
|
27502
|
+
name: exports_external.string().min(1, "name is required").max(100).trim().optional(),
|
|
27503
|
+
slug: exports_external.string().min(1, "slug is required").trim().toLowerCase().transform(sanitizeSlug).optional()
|
|
27504
|
+
});
|
|
27505
|
+
var DeleteWorkspaceRequestSchema = exports_external.object({
|
|
27506
|
+
confirm_name: exports_external.string().min(1, "confirm_name is required")
|
|
27507
|
+
});
|
|
27508
|
+
var GrantAgentAccessRequestSchema = exports_external.object({
|
|
27509
|
+
user_id: exports_external.string().min(1, "user_id is required")
|
|
27510
|
+
});
|
|
27511
|
+
var WorkspaceFileBrowseRequestSchema = exports_external.object({
|
|
27512
|
+
request_type: exports_external.enum(["tree", "read"]),
|
|
27513
|
+
path: exports_external.string().default(".")
|
|
27514
|
+
});
|
|
27515
|
+
var WorkspaceFileEntrySchema = exports_external.object({
|
|
27516
|
+
name: exports_external.string(),
|
|
27517
|
+
path: exports_external.string(),
|
|
27518
|
+
isDirectory: exports_external.boolean(),
|
|
27519
|
+
size: exports_external.number(),
|
|
27520
|
+
modifiedAt: exports_external.string()
|
|
27521
|
+
});
|
|
27522
|
+
var WorkspaceFileReportSchema = exports_external.object({
|
|
27523
|
+
request_id: exports_external.string().min(1),
|
|
27524
|
+
entries: exports_external.array(WorkspaceFileEntrySchema).optional(),
|
|
27525
|
+
content: exports_external.string().nullable().optional(),
|
|
27526
|
+
isBinary: exports_external.boolean().optional(),
|
|
27527
|
+
error: exports_external.string().optional(),
|
|
27528
|
+
path: exports_external.string()
|
|
27529
|
+
});
|
|
27530
|
+
var SkillEntrySchema = exports_external.object({
|
|
27531
|
+
name: exports_external.string(),
|
|
27532
|
+
description: exports_external.string(),
|
|
27533
|
+
isGlobal: exports_external.boolean().optional()
|
|
27534
|
+
});
|
|
27535
|
+
var SkillItemSchema = exports_external.object({
|
|
27536
|
+
name: exports_external.string(),
|
|
27537
|
+
description: exports_external.string()
|
|
27538
|
+
});
|
|
27539
|
+
var SkillSyncRequestSchema = exports_external.object({
|
|
27540
|
+
scope: exports_external.enum(["global", "agent"]),
|
|
27541
|
+
agent_id: exports_external.string().min(1).optional(),
|
|
27542
|
+
daemon_id: exports_external.string().min(1).optional(),
|
|
27543
|
+
runtime: exports_external.enum(["claude", "codex", "opencode"]),
|
|
27544
|
+
skills: exports_external.array(SkillItemSchema)
|
|
27545
|
+
});
|
|
27546
|
+
var StudioMemberSchema = exports_external.object({
|
|
27547
|
+
name: exports_external.string().optional(),
|
|
27548
|
+
role: exports_external.enum(["leader", "researcher", "engineer", "assistant"]),
|
|
27549
|
+
runtime_id: exports_external.string().min(1, "runtime_id is required"),
|
|
27550
|
+
runtime_config: exports_external.object({ model: exports_external.string().max(100).optional() }).passthrough().optional(),
|
|
27551
|
+
description: exports_external.string().optional().default(""),
|
|
27552
|
+
instructions: exports_external.string().optional().default(""),
|
|
27553
|
+
avatar_url: exports_external.string().max(2000).nullable().optional(),
|
|
27554
|
+
email_handle: exports_external.string().max(30).optional(),
|
|
27555
|
+
relationship: exports_external.string().optional()
|
|
27556
|
+
});
|
|
27557
|
+
var CreateStudioRequestSchema = exports_external.object({
|
|
27558
|
+
name: exports_external.string().max(100).optional(),
|
|
27559
|
+
scenario: exports_external.string().max(50).optional(),
|
|
27560
|
+
members: exports_external.array(StudioMemberSchema).min(1).max(4)
|
|
27561
|
+
}).refine((v) => v.members.some((m) => m.role === "leader"), { message: "at least one member must have the leader role" });
|
|
27562
|
+
var RecruitAgentRequestSchema = exports_external.object({
|
|
27563
|
+
instructions: exports_external.string().min(1, "instructions is required"),
|
|
27564
|
+
relationship: exports_external.string().min(1, "relationship is required"),
|
|
27565
|
+
name: exports_external.string().optional(),
|
|
27566
|
+
description: exports_external.string().optional().default(""),
|
|
27567
|
+
model: exports_external.string().max(100).optional(),
|
|
27568
|
+
context_key: exports_external.string().optional()
|
|
27569
|
+
});
|
|
27570
|
+
var CreateThreadRequestSchema = exports_external.object({
|
|
27571
|
+
parent_message_id: exports_external.string().min(1),
|
|
27572
|
+
content: exports_external.string().optional().default(""),
|
|
27573
|
+
attachment_ids: exports_external.array(exports_external.string()).optional()
|
|
27574
|
+
});
|
|
27575
|
+
var COMMUNITY_RUNTIME_ID_MAX = 64;
|
|
27576
|
+
var COMMUNITY_RUNTIME_VERSION_MAX = 64;
|
|
27577
|
+
var COMMUNITY_RUNTIME_LIST_MAX = 64;
|
|
27578
|
+
var RUNTIME_ID_RE = /^[A-Za-z0-9._@/-]+$/;
|
|
27579
|
+
var CommunityMachineRuntimeSchema = exports_external.object({
|
|
27580
|
+
id: exports_external.string().min(1).max(COMMUNITY_RUNTIME_ID_MAX).regex(RUNTIME_ID_RE, "invalid runtime id charset"),
|
|
27581
|
+
version: exports_external.string().max(COMMUNITY_RUNTIME_VERSION_MAX).optional(),
|
|
27582
|
+
status: exports_external.enum(["healthy", "unhealthy"]).catch("healthy").default("healthy"),
|
|
27583
|
+
lastError: exports_external.string().max(128).optional(),
|
|
27584
|
+
lastErrorAt: exports_external.string().optional()
|
|
27585
|
+
});
|
|
27586
|
+
var CommunityMachineRuntimeListSchema = exports_external.array(CommunityMachineRuntimeSchema).max(COMMUNITY_RUNTIME_LIST_MAX).transform((list) => {
|
|
27587
|
+
const seen = new Set;
|
|
27588
|
+
const out = [];
|
|
27589
|
+
for (const r of list) {
|
|
27590
|
+
if (seen.has(r.id))
|
|
27591
|
+
continue;
|
|
27592
|
+
seen.add(r.id);
|
|
27593
|
+
out.push(r);
|
|
27594
|
+
}
|
|
27595
|
+
return out;
|
|
27596
|
+
});
|
|
27597
|
+
var CommunityMachineSummarySchema = exports_external.object({
|
|
27598
|
+
id: exports_external.string(),
|
|
27599
|
+
hostname: exports_external.string(),
|
|
27600
|
+
displayName: exports_external.string(),
|
|
27601
|
+
platform: exports_external.string(),
|
|
27602
|
+
arch: exports_external.string(),
|
|
27603
|
+
osRelease: exports_external.string(),
|
|
27604
|
+
daemonVersion: exports_external.string(),
|
|
27605
|
+
lastSeenAt: exports_external.string().nullable(),
|
|
27606
|
+
status: exports_external.enum(["online", "offline"]),
|
|
27607
|
+
availableRuntimes: exports_external.array(CommunityMachineRuntimeSchema).default([]),
|
|
27608
|
+
lastRuntimeError: exports_external.object({
|
|
27609
|
+
requested: exports_external.string(),
|
|
27610
|
+
available: exports_external.array(exports_external.string()),
|
|
27611
|
+
at: exports_external.string()
|
|
27612
|
+
}).optional(),
|
|
27613
|
+
createdAt: exports_external.string(),
|
|
27614
|
+
updatedAt: exports_external.string()
|
|
27615
|
+
});
|
|
27616
|
+
var HostReadyMessageSchema = exports_external.object({
|
|
27617
|
+
type: exports_external.literal("ready"),
|
|
27618
|
+
runtimeReport: CommunityMachineRuntimeListSchema,
|
|
27619
|
+
capabilities: exports_external.array(exports_external.string().min(1).max(64)).max(16).optional().default([]),
|
|
27620
|
+
runningAgents: exports_external.array(exports_external.string()).default([]),
|
|
27621
|
+
hostname: exports_external.string().optional(),
|
|
27622
|
+
platform: exports_external.string().optional(),
|
|
27623
|
+
arch: exports_external.string().optional(),
|
|
27624
|
+
osRelease: exports_external.string().optional(),
|
|
27625
|
+
daemonVersion: exports_external.string().optional()
|
|
27626
|
+
});
|
|
27627
|
+
var CommunityDaemonReadySchema = exports_external.object({
|
|
27628
|
+
runtimeReport: CommunityMachineRuntimeListSchema.optional(),
|
|
27629
|
+
runningAgents: exports_external.array(exports_external.string()).default([]),
|
|
27630
|
+
hostname: exports_external.string().optional(),
|
|
27631
|
+
os: exports_external.string().optional(),
|
|
27632
|
+
arch: exports_external.string().optional(),
|
|
27633
|
+
osRelease: exports_external.string().optional(),
|
|
27634
|
+
daemonVersion: exports_external.string().optional()
|
|
27635
|
+
});
|
|
27636
|
+
var SessionErrorFrameSchema = exports_external.object({
|
|
27637
|
+
type: exports_external.literal("session.error"),
|
|
27638
|
+
code: exports_external.enum(["runtime_not_available"]),
|
|
27639
|
+
agentId: exports_external.string().optional(),
|
|
27640
|
+
launchId: exports_external.string().optional(),
|
|
27641
|
+
payload: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
27642
|
+
});
|
|
27643
|
+
var AgentActivityMessageSchema = exports_external.object({
|
|
27644
|
+
type: exports_external.literal("agent_activity"),
|
|
27645
|
+
agentId: exports_external.string(),
|
|
27646
|
+
state: exports_external.enum(["idle", "starting", "running", "stopping"])
|
|
27647
|
+
});
|
|
27648
|
+
var AgentTypingMessageSchema = exports_external.object({
|
|
27649
|
+
type: exports_external.literal("agent_typing"),
|
|
27650
|
+
agentId: exports_external.string(),
|
|
27651
|
+
channelId: exports_external.string().min(1)
|
|
27652
|
+
});
|
|
27653
|
+
var AgentTypingStopMessageSchema = exports_external.object({
|
|
27654
|
+
type: exports_external.literal("agent_typing_stop"),
|
|
27655
|
+
agentId: exports_external.string(),
|
|
27656
|
+
channelId: exports_external.string().min(1)
|
|
27657
|
+
});
|
|
27658
|
+
var AgentSessionMessageSchema = exports_external.object({
|
|
27659
|
+
type: exports_external.literal("agent_session"),
|
|
27660
|
+
agentId: exports_external.string().min(1),
|
|
27661
|
+
sessionId: exports_external.string().min(1),
|
|
27662
|
+
launchId: exports_external.string().min(1)
|
|
27663
|
+
});
|
|
27664
|
+
var AgentWakeAckMessageSchema = exports_external.object({
|
|
27665
|
+
type: exports_external.literal("agent_wake_ack"),
|
|
27666
|
+
agentId: exports_external.string().min(1),
|
|
27667
|
+
launchId: exports_external.string().min(1),
|
|
27668
|
+
status: exports_external.enum(["ok", "error"]),
|
|
27669
|
+
error: exports_external.object({ code: exports_external.string().optional(), message: exports_external.string().optional() }).optional()
|
|
27670
|
+
});
|
|
27671
|
+
var MachineHeartbeatAckMessageSchema = exports_external.strictObject({
|
|
27672
|
+
type: exports_external.literal("machine_heartbeat_ack"),
|
|
27673
|
+
nonce: exports_external.string().min(1).max(128)
|
|
27674
|
+
});
|
|
27675
|
+
var DiagnosticCommandAckMessageSchema = exports_external.strictObject({
|
|
27676
|
+
type: exports_external.literal("diagnostics_ack"),
|
|
27677
|
+
reportId: DiagnosticReportIdSchema
|
|
27678
|
+
});
|
|
27679
|
+
var CommunityPairTokenResponseSchema = exports_external.object({
|
|
27680
|
+
tokenId: exports_external.string(),
|
|
27681
|
+
expiresAt: exports_external.string()
|
|
27682
|
+
});
|
|
27683
|
+
var CommunityDaemonActivateRequestSchema = exports_external.object({
|
|
27684
|
+
hostname: exports_external.string(),
|
|
27685
|
+
platform: exports_external.string(),
|
|
27686
|
+
arch: exports_external.string(),
|
|
27687
|
+
expectedMachineId: exports_external.string().min(1).optional(),
|
|
27688
|
+
osRelease: exports_external.string().optional(),
|
|
27689
|
+
daemonVersion: exports_external.string().optional(),
|
|
27690
|
+
runtimeReport: CommunityMachineRuntimeListSchema.optional()
|
|
27691
|
+
});
|
|
27692
|
+
var CommunityDaemonActivateResponseSchema = exports_external.object({
|
|
27693
|
+
credential: exports_external.string(),
|
|
27694
|
+
machineId: exports_external.string(),
|
|
27695
|
+
expiresAt: exports_external.string().nullable(),
|
|
27696
|
+
sessionOutcome: exports_external.literal("committed")
|
|
27697
|
+
});
|
|
27698
|
+
var CommunityDaemonActivateErrorResponseSchema = exports_external.object({
|
|
27699
|
+
error: exports_external.string(),
|
|
27700
|
+
sessionOutcome: exports_external.enum(["not_committed", "unknown"])
|
|
27701
|
+
});
|
|
27702
|
+
var CommunityDaemonEnrollAgentRequestSchema = exports_external.object({
|
|
27703
|
+
agentId: exports_external.string().min(1).max(128)
|
|
27704
|
+
});
|
|
27705
|
+
var CommunityDaemonEnrollAgentResponseSchema = exports_external.object({
|
|
27706
|
+
runnerKey: exports_external.string(),
|
|
27707
|
+
expiresAt: exports_external.string().nullable()
|
|
27708
|
+
});
|
|
27709
|
+
var isMentionSafeName = (name) => validateCommunityName(name).ok;
|
|
27710
|
+
var MENTION_SAFE_NAME_MSG = "name cannot contain #, @, or line breaks";
|
|
27711
|
+
var BOT_AVATAR_ROUTE_PATTERN = /^\/api\/community\/bots\/[A-Za-z0-9_-]+\/avatar$/;
|
|
27712
|
+
var BotImageUrlSchema = exports_external.string().max(COMMUNITY_BOT_IMAGE_URL_MAX).refine((v) => v.startsWith("https://") || v.startsWith("avatar:") || BOT_AVATAR_ROUTE_PATTERN.test(v), {
|
|
27713
|
+
message: "image must be an https URL, the bot avatar route, or an avatar: config"
|
|
27714
|
+
});
|
|
27715
|
+
var CommunityBotCreateRequestSchema = exports_external.object({
|
|
27716
|
+
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, { message: MENTION_SAFE_NAME_MSG }),
|
|
27717
|
+
description: exports_external.string().max(COMMUNITY_BOT_DESCRIPTION_MAX).optional(),
|
|
27718
|
+
machineId: exports_external.string().min(1),
|
|
27719
|
+
runtime: exports_external.string().min(1),
|
|
27720
|
+
image: BotImageUrlSchema.optional(),
|
|
27721
|
+
model: exports_external.string().trim().min(1).max(100).nullable().optional()
|
|
27722
|
+
});
|
|
27723
|
+
var CommunityBotPatchRequestSchema = exports_external.object({
|
|
27724
|
+
name: exports_external.string().trim().min(COMMUNITY_BOT_NAME_MIN).max(COMMUNITY_BOT_NAME_MAX).refine(isMentionSafeName, { message: MENTION_SAFE_NAME_MSG }).optional(),
|
|
27725
|
+
description: exports_external.string().max(COMMUNITY_BOT_DESCRIPTION_MAX).optional(),
|
|
27726
|
+
image: BotImageUrlSchema.nullable().optional(),
|
|
27727
|
+
model: exports_external.string().trim().min(1).max(100).nullable().optional(),
|
|
27728
|
+
runtime: exports_external.string().trim().min(1).max(COMMUNITY_RUNTIME_ID_MAX).optional()
|
|
27729
|
+
}).refine((v) => v.name !== undefined || v.description !== undefined || v.image !== undefined || v.runtime !== undefined || ("model" in v), {
|
|
27730
|
+
message: "at least one field must be provided"
|
|
27731
|
+
});
|
|
27732
|
+
var CommunityBotAddToServerRequestSchema = exports_external.object({
|
|
27733
|
+
botId: exports_external.string().min(1)
|
|
27734
|
+
});
|
|
27735
|
+
var CommunityAgentMessageContentSchema = exports_external.object({ text: exports_external.string().max(MAX_MESSAGE_CONTENT_LENGTH).default("") }).catchall(exports_external.unknown());
|
|
27736
|
+
var CommunityAgentSeqSchema = exports_external.number().int().min(0);
|
|
27737
|
+
var CommunityAgentPositiveSeqSchema = exports_external.number().int().min(1);
|
|
27738
|
+
var CommunityAgentCursorSchema = exports_external.object({
|
|
27739
|
+
channel: exports_external.string().min(1),
|
|
27740
|
+
seq: CommunityAgentPositiveSeqSchema
|
|
27741
|
+
});
|
|
27742
|
+
var CommunityAgentSendRequestSchema = exports_external.object({
|
|
27743
|
+
channel: exports_external.string().min(1),
|
|
27744
|
+
content: CommunityAgentMessageContentSchema,
|
|
27745
|
+
attachments: exports_external.array(exports_external.string().min(1)).max(MAX_ATTACHMENTS_PER_MESSAGE).default([]),
|
|
27746
|
+
seenUpToSeq: CommunityAgentSeqSchema.optional(),
|
|
27747
|
+
replyToSeq: CommunityAgentPositiveSeqSchema.optional(),
|
|
27748
|
+
nonce: exports_external.string().min(1).max(128).optional()
|
|
27749
|
+
}).refine((d) => d.content.text.trim().length > 0 || d.attachments.length > 0, { message: "message must have text or attachments" });
|
|
27750
|
+
var CommunityAgentAttachmentUploadResponseSchema = exports_external.object({
|
|
27751
|
+
id: exports_external.string(),
|
|
27752
|
+
filename: exports_external.string(),
|
|
27753
|
+
contentType: exports_external.string(),
|
|
27754
|
+
size: exports_external.number(),
|
|
27755
|
+
hasThumbnail: exports_external.boolean().optional()
|
|
27756
|
+
});
|
|
27757
|
+
var CommunityAgentAttachmentDownloadRequestSchema = exports_external.object({
|
|
27758
|
+
id: exports_external.string().min(1)
|
|
27759
|
+
});
|
|
27760
|
+
var CommunityAgentUpdateProfileRequestSchema = exports_external.object({
|
|
27761
|
+
bio: exports_external.string().max(MAX_PROFILE_ABOUT_LENGTH).optional(),
|
|
27762
|
+
avatar: exports_external.object({
|
|
27763
|
+
filename: exports_external.string().min(1),
|
|
27764
|
+
contentType: exports_external.enum(ALLOWED_ICON_MIME_TYPES),
|
|
27765
|
+
data: exports_external.instanceof(Uint8Array).refine((value) => value.byteLength > 0, "avatar must not be empty").refine((value) => value.byteLength <= MAX_SERVER_ICON_SIZE_BYTES, `avatar must be ≤ ${MAX_SERVER_ICON_SIZE_BYTES} bytes`)
|
|
27766
|
+
}).optional()
|
|
27767
|
+
}).refine((value) => value.bio !== undefined || value.avatar !== undefined, {
|
|
27768
|
+
message: "bio or avatar is required"
|
|
27769
|
+
});
|
|
27770
|
+
var CommunityAgentInboxPullRequestSchema = exports_external.object({
|
|
27771
|
+
max: exports_external.number().int().min(1).max(200).optional()
|
|
27772
|
+
});
|
|
27773
|
+
var CommunityAgentAckRequestSchema = exports_external.object({
|
|
27774
|
+
cursors: exports_external.array(CommunityAgentCursorSchema).min(1)
|
|
27775
|
+
});
|
|
27776
|
+
var CommunityAgentReadRequestSchema = exports_external.object({
|
|
27777
|
+
channel: exports_external.string().min(1),
|
|
27778
|
+
before: CommunityAgentSeqSchema.optional(),
|
|
27779
|
+
after: CommunityAgentSeqSchema.optional(),
|
|
27780
|
+
around: CommunityAgentSeqSchema.optional(),
|
|
27781
|
+
limit: exports_external.number().int().min(1).max(200).optional()
|
|
27782
|
+
}).refine((v) => [v.before, v.after, v.around].filter((x) => x !== undefined).length <= 1, { message: "at most one of before/after/around may be supplied" });
|
|
27783
|
+
var CommunityAgentResolveRequestSchema = exports_external.object({
|
|
27784
|
+
channel: exports_external.string().min(1),
|
|
27785
|
+
seq: CommunityAgentSeqSchema
|
|
27786
|
+
});
|
|
27787
|
+
var CommunityAgentListChannelsRequestSchema = exports_external.object({
|
|
27788
|
+
server: exports_external.string().min(1).optional()
|
|
27789
|
+
});
|
|
27790
|
+
var CommunityAgentListMembersRequestSchema = exports_external.object({
|
|
27791
|
+
server: exports_external.string().min(1),
|
|
27792
|
+
limit: exports_external.number().int().positive().optional(),
|
|
27793
|
+
cursor: exports_external.string().min(1).optional()
|
|
27794
|
+
});
|
|
27795
|
+
var CommunityAgentChannelMemberRequestSchema = exports_external.object({
|
|
27796
|
+
channel: exports_external.string().min(1),
|
|
27797
|
+
agentId: exports_external.string().optional()
|
|
27798
|
+
});
|
|
27799
|
+
var CommunityAgentJoinServerRequestSchema = exports_external.object({
|
|
27800
|
+
invite: exports_external.string().min(1)
|
|
27801
|
+
});
|
|
27802
|
+
var CommunityAgentNapRequestSchema = exports_external.object({
|
|
27803
|
+
handoff: exports_external.string().refine((value) => value.trim().length > 0, {
|
|
27804
|
+
message: "handoff is required"
|
|
27805
|
+
})
|
|
27806
|
+
});
|
|
27807
|
+
var CommunityAgentReactAddRequestSchema = exports_external.object({
|
|
27808
|
+
channel: exports_external.string().min(1),
|
|
27809
|
+
seq: CommunityAgentPositiveSeqSchema,
|
|
27810
|
+
emoji: exports_external.string().min(1)
|
|
27811
|
+
});
|
|
27812
|
+
var CommunityAgentFriendRequestSchema = exports_external.object({
|
|
27813
|
+
username: exports_external.string().min(1)
|
|
27814
|
+
});
|
|
27815
|
+
var CommunityAgentListFriendsSchema = exports_external.object({});
|
|
27816
|
+
var AuditLogCliInvocationPayloadSchema = exports_external.object({
|
|
27817
|
+
subcommand: exports_external.string().min(1)
|
|
27818
|
+
});
|
|
27819
|
+
var AuditLogToolCallPayloadSchema = exports_external.object({
|
|
27820
|
+
name: exports_external.string().min(1),
|
|
27821
|
+
target: exports_external.string().max(240).optional()
|
|
27822
|
+
});
|
|
27823
|
+
var AuditLogThinkingPayloadSchema = exports_external.object({
|
|
27824
|
+
text: exports_external.string(),
|
|
27825
|
+
truncated: exports_external.boolean(),
|
|
27826
|
+
chars: exports_external.number().int().nonnegative()
|
|
27827
|
+
});
|
|
27828
|
+
var AuditLogWakeTriggerPayloadSchema = exports_external.object({
|
|
27829
|
+
messageId: exports_external.string().min(1),
|
|
27830
|
+
channel: exports_external.string().min(1),
|
|
27831
|
+
seq: CommunityAgentPositiveSeqSchema,
|
|
27832
|
+
senderId: exports_external.string().min(1),
|
|
27833
|
+
senderHandle: exports_external.string().min(1),
|
|
27834
|
+
reason: exports_external.enum(["unread", "mention"])
|
|
27835
|
+
});
|
|
27836
|
+
var AuditLogSessionResetPayloadSchema = exports_external.object({
|
|
27837
|
+
trigger: exports_external.enum(["single", "reset_all", "idle_timeout"])
|
|
27838
|
+
});
|
|
27839
|
+
var AuditLogNapPayloadSchema = exports_external.object({
|
|
27840
|
+
trigger: exports_external.literal("nap")
|
|
27841
|
+
});
|
|
27842
|
+
var AuditLogModelChangedPayloadSchema = exports_external.object({
|
|
27843
|
+
from: exports_external.string().nullable(),
|
|
27844
|
+
to: exports_external.string().nullable()
|
|
27845
|
+
});
|
|
27846
|
+
var AuditLogProviderChangedPayloadSchema = exports_external.object({
|
|
27847
|
+
from: exports_external.string().min(1),
|
|
27848
|
+
to: exports_external.string().min(1)
|
|
27849
|
+
});
|
|
27850
|
+
var AuditLogErrorPayloadSchema = exports_external.object({
|
|
27851
|
+
scope: exports_external.enum(["spawn", "runtime", "exit", "handshake_timeout", "model_switch", "reset"]),
|
|
27852
|
+
code: exports_external.string().min(1).max(120),
|
|
27853
|
+
message: exports_external.string().max(2048),
|
|
27854
|
+
model: exports_external.string().nullable()
|
|
27855
|
+
});
|
|
27856
|
+
var BotAuditEventSchema = exports_external.discriminatedUnion("kind", [
|
|
27857
|
+
exports_external.object({ kind: exports_external.literal("cli_invocation"), payload: AuditLogCliInvocationPayloadSchema }),
|
|
27858
|
+
exports_external.object({ kind: exports_external.literal("tool_call"), payload: AuditLogToolCallPayloadSchema }),
|
|
27859
|
+
exports_external.object({ kind: exports_external.literal("thinking"), payload: AuditLogThinkingPayloadSchema }),
|
|
27860
|
+
exports_external.object({ kind: exports_external.literal("wake_trigger"), payload: AuditLogWakeTriggerPayloadSchema }),
|
|
27861
|
+
exports_external.object({ kind: exports_external.literal("session_reset"), payload: AuditLogSessionResetPayloadSchema }),
|
|
27862
|
+
exports_external.object({ kind: exports_external.literal("nap"), payload: AuditLogNapPayloadSchema }),
|
|
27863
|
+
exports_external.object({ kind: exports_external.literal("model_changed"), payload: AuditLogModelChangedPayloadSchema }),
|
|
27864
|
+
exports_external.object({ kind: exports_external.literal("provider_changed"), payload: AuditLogProviderChangedPayloadSchema }),
|
|
27865
|
+
exports_external.object({ kind: exports_external.literal("error"), payload: AuditLogErrorPayloadSchema })
|
|
27866
|
+
]);
|
|
27867
|
+
var BotAuditEventKindSchema = exports_external.enum([
|
|
27868
|
+
"cli_invocation",
|
|
27869
|
+
"tool_call",
|
|
27870
|
+
"thinking",
|
|
27871
|
+
"wake_trigger",
|
|
27872
|
+
"session_reset",
|
|
27873
|
+
"nap",
|
|
27874
|
+
"model_changed",
|
|
27875
|
+
"provider_changed",
|
|
27876
|
+
"error"
|
|
27877
|
+
]);
|
|
27878
|
+
var HostBotAuditEventFrameSchema = exports_external.object({
|
|
27879
|
+
type: exports_external.literal("bot_audit_event"),
|
|
27880
|
+
eventId: exports_external.string().min(1).max(128).optional(),
|
|
27881
|
+
occurredAt: exports_external.string().datetime({ offset: true }).optional(),
|
|
27882
|
+
agentId: exports_external.string().min(1),
|
|
27883
|
+
sessionId: exports_external.string().nullable().optional(),
|
|
27884
|
+
launchId: exports_external.string().nullable().optional(),
|
|
27885
|
+
event: BotAuditEventSchema
|
|
27886
|
+
}).superRefine((frame, ctx) => {
|
|
27887
|
+
if (frame.event.kind === "session_reset" && frame.event.payload.trigger === "idle_timeout" && (!frame.eventId || !frame.occurredAt)) {
|
|
27888
|
+
if (!frame.eventId) {
|
|
27889
|
+
ctx.addIssue({
|
|
27890
|
+
code: "custom",
|
|
27891
|
+
path: ["eventId"],
|
|
27892
|
+
message: "eventId is required for idle_timeout session_reset"
|
|
27893
|
+
});
|
|
27894
|
+
}
|
|
27895
|
+
if (!frame.occurredAt) {
|
|
27896
|
+
ctx.addIssue({
|
|
27897
|
+
code: "custom",
|
|
27898
|
+
path: ["occurredAt"],
|
|
27899
|
+
message: "occurredAt is required for idle_timeout session_reset"
|
|
27900
|
+
});
|
|
27901
|
+
}
|
|
27902
|
+
}
|
|
27903
|
+
});
|
|
27904
|
+
var BotAuditEventAckFrameSchema = exports_external.strictObject({
|
|
27905
|
+
type: exports_external.literal("bot_audit_event_ack"),
|
|
27906
|
+
eventId: exports_external.string().min(1).max(128)
|
|
27907
|
+
});
|
|
27908
|
+
// ../shared/src/db/community-schema.ts
|
|
27909
|
+
var exports_community_schema = {};
|
|
27910
|
+
__export(exports_community_schema, {
|
|
27911
|
+
communityUserProfile: () => communityUserProfile,
|
|
27912
|
+
communityServerMember: () => communityServerMember,
|
|
27913
|
+
communityServerInvite: () => communityServerInvite,
|
|
27914
|
+
communityServerFolderItem: () => communityServerFolderItem,
|
|
27915
|
+
communityServerFolder: () => communityServerFolder,
|
|
27916
|
+
communityServer: () => communityServer,
|
|
27917
|
+
communityReadStateRevision: () => communityReadStateRevision,
|
|
27918
|
+
communityReadState: () => communityReadState,
|
|
27919
|
+
communityReaction: () => communityReaction,
|
|
27920
|
+
communityPin: () => communityPin,
|
|
27921
|
+
communityNotificationSetting: () => communityNotificationSetting,
|
|
27922
|
+
communityMessageTag: () => communityMessageTag,
|
|
27923
|
+
communityMessageSeq: () => communityMessageSeq,
|
|
27924
|
+
communityMessageMark: () => communityMessageMark,
|
|
27925
|
+
communityMessage: () => communityMessage,
|
|
27926
|
+
communityMention: () => communityMention,
|
|
27927
|
+
communityFriendship: () => communityFriendship,
|
|
27928
|
+
communityChannelMember: () => communityChannelMember,
|
|
27929
|
+
communityChannel: () => communityChannel,
|
|
27930
|
+
communityCategory: () => communityCategory,
|
|
27931
|
+
communityBotDailyActivity: () => communityBotDailyActivity,
|
|
27932
|
+
communityBotApprovalRequest: () => communityBotApprovalRequest,
|
|
27933
|
+
communityBotActivityEvent: () => communityBotActivityEvent,
|
|
27934
|
+
communityAttachment: () => communityAttachment
|
|
27935
|
+
});
|
|
27936
|
+
init_nanoid();
|
|
27937
|
+
var communityServer = sqliteTable("community_server", {
|
|
27938
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
27939
|
+
name: text("name").notNull(),
|
|
27940
|
+
discriminator: text("discriminator").notNull().default("0000"),
|
|
27941
|
+
description: text("description").default(""),
|
|
27942
|
+
icon: text("icon"),
|
|
27943
|
+
ownerId: text("owner_id").notNull().references(() => user.id, { onDelete: "restrict" }),
|
|
27944
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
27945
|
+
}, (t) => [
|
|
27946
|
+
uniqueIndex("idx_community_server_name_discriminator").on(t.name, t.discriminator)
|
|
27947
|
+
]);
|
|
27948
|
+
var communityCategory = sqliteTable("community_category", {
|
|
27949
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
27950
|
+
serverId: text("server_id").notNull().references(() => communityServer.id, { onDelete: "cascade" }),
|
|
27951
|
+
name: text("name").notNull(),
|
|
27952
|
+
position: integer2("position").default(0),
|
|
27953
|
+
private: integer2("private").default(0),
|
|
27954
|
+
creatorId: text("creator_id").references(() => user.id, { onDelete: "set null" })
|
|
27955
|
+
}, (t) => [unique("uq_category_server_name").on(t.serverId, t.name)]);
|
|
27956
|
+
var communityChannel = sqliteTable("community_channel", {
|
|
27957
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
27958
|
+
serverId: text("server_id").references(() => communityServer.id, {
|
|
27959
|
+
onDelete: "cascade"
|
|
27960
|
+
}),
|
|
27961
|
+
categoryId: text("category_id").references(() => communityCategory.id, {
|
|
27962
|
+
onDelete: "set null"
|
|
27963
|
+
}),
|
|
27964
|
+
name: text("name"),
|
|
27965
|
+
type: text("type").notNull().default("text"),
|
|
27966
|
+
topic: text("topic").default(""),
|
|
27967
|
+
position: integer2("position").default(0),
|
|
27968
|
+
parentChannelId: text("parent_channel_id").references(() => communityChannel.id, {
|
|
27969
|
+
onDelete: "cascade"
|
|
27970
|
+
}),
|
|
27971
|
+
creatorId: text("creator_id").references(() => user.id, { onDelete: "set null" }),
|
|
27972
|
+
messageCount: integer2("message_count").default(0),
|
|
27973
|
+
archived: integer2("archived").default(0),
|
|
27974
|
+
parentMessageId: text("parent_message_id").references(() => communityMessage.id, {
|
|
27975
|
+
onDelete: "cascade"
|
|
27976
|
+
}),
|
|
27977
|
+
lastMessageAt: text("last_message_at"),
|
|
27978
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
27979
|
+
}, (t) => [
|
|
27980
|
+
index("idx_channel_server_position").on(t.serverId, t.position),
|
|
27981
|
+
index("idx_channel_server_last_message").on(t.serverId, t.lastMessageAt),
|
|
27982
|
+
index("idx_channel_parent").on(t.parentChannelId),
|
|
27983
|
+
index("idx_channel_forum_created").on(t.parentChannelId, desc(t.createdAt), desc(t.id)).where(and(eq(t.type, "thread"), eq(t.archived, 0), isNotNull(t.parentMessageId))),
|
|
27984
|
+
uniqueIndex("idx_channel_server_name").on(t.serverId, t.name).where(sql`parent_channel_id IS NULL`)
|
|
27985
|
+
]);
|
|
27986
|
+
var communityChannelMember = sqliteTable("community_channel_member", {
|
|
27987
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
27988
|
+
channelId: text("channel_id").notNull().references(() => communityChannel.id, { onDelete: "cascade" }),
|
|
27989
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
27990
|
+
relation: text("relation").notNull().default("access"),
|
|
27991
|
+
source: text("source").notNull().default("added"),
|
|
27992
|
+
addedBy: text("added_by").references(() => user.id, { onDelete: "set null" }),
|
|
27993
|
+
addedAt: text("added_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
27994
|
+
}, (t) => [
|
|
27995
|
+
unique("uq_channel_member").on(t.channelId, t.userId, t.relation),
|
|
27996
|
+
index("idx_channel_member_user").on(t.userId)
|
|
27997
|
+
]);
|
|
27998
|
+
var communityMessage = sqliteTable("community_message", {
|
|
27999
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28000
|
+
authorId: text("author_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28001
|
+
content: text("content").notNull().default(""),
|
|
28002
|
+
type: text("type").notNull().default("default"),
|
|
28003
|
+
mentionType: text("mention_type"),
|
|
28004
|
+
replyToId: text("reply_to_id"),
|
|
28005
|
+
embeds: text("embeds"),
|
|
28006
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
|
|
28007
|
+
channelId: text("channel_id").notNull().references(() => communityChannel.id, {
|
|
28008
|
+
onDelete: "cascade"
|
|
28009
|
+
}),
|
|
28010
|
+
seq: integer2("seq").notNull().default(0),
|
|
28011
|
+
friendshipId: text("friendship_id").references(() => communityFriendship.id, { onDelete: "set null" }),
|
|
28012
|
+
clientNonce: text("client_nonce")
|
|
28013
|
+
}, (t) => [
|
|
28014
|
+
index("idx_message_channel_created").on(t.channelId, t.createdAt),
|
|
28015
|
+
index("idx_message_channel_mention_created").on(t.channelId, t.mentionType, t.createdAt)
|
|
28016
|
+
]);
|
|
28017
|
+
var communityMessageSeq = sqliteTable("community_message_seq", {
|
|
28018
|
+
channelId: text("channel_id").primaryKey().references(() => communityChannel.id, { onDelete: "cascade" }),
|
|
28019
|
+
nextSeq: integer2("next_seq").notNull()
|
|
28020
|
+
});
|
|
28021
|
+
var communityServerMember = sqliteTable("community_server_member", {
|
|
28022
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28023
|
+
serverId: text("server_id").notNull().references(() => communityServer.id, { onDelete: "cascade" }),
|
|
28024
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28025
|
+
role: text("role").default("member"),
|
|
28026
|
+
railOrder: integer2("rail_order").default(0),
|
|
28027
|
+
joinedAt: text("joined_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28028
|
+
}, (t) => [
|
|
28029
|
+
unique("uq_server_member_server_user").on(t.serverId, t.userId),
|
|
28030
|
+
index("idx_server_member_user").on(t.userId),
|
|
28031
|
+
index("idx_server_member_user_rail_order").on(t.userId, t.railOrder),
|
|
28032
|
+
index("idx_server_member_server_joined").on(t.serverId, t.joinedAt)
|
|
28033
|
+
]);
|
|
28034
|
+
var communityServerFolder = sqliteTable("community_server_folder", {
|
|
28035
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28036
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28037
|
+
name: text("name").notNull(),
|
|
28038
|
+
position: integer2("position").default(0)
|
|
28039
|
+
}, (t) => [index("idx_server_folder_user_position").on(t.userId, t.position)]);
|
|
28040
|
+
var communityServerFolderItem = sqliteTable("community_server_folder_item", {
|
|
28041
|
+
folderId: text("folder_id").notNull().references(() => communityServerFolder.id, { onDelete: "cascade" }),
|
|
28042
|
+
serverId: text("server_id").notNull().references(() => communityServer.id, { onDelete: "cascade" }),
|
|
28043
|
+
position: integer2("position").default(0)
|
|
28044
|
+
}, (t) => [
|
|
28045
|
+
primaryKey({ columns: [t.folderId, t.serverId] }),
|
|
28046
|
+
index("idx_server_folder_item_folder_position").on(t.folderId, t.position)
|
|
28047
|
+
]);
|
|
28048
|
+
var communityServerInvite = sqliteTable("community_server_invite", {
|
|
28049
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28050
|
+
serverId: text("server_id").notNull().references(() => communityServer.id, { onDelete: "cascade" }),
|
|
28051
|
+
createdBy: text("created_by").references(() => user.id, { onDelete: "set null" }),
|
|
28052
|
+
token: text("token").unique().notNull().$defaultFn(() => nanoid3(10)),
|
|
28053
|
+
maxUses: integer2("max_uses"),
|
|
28054
|
+
uses: integer2("uses").default(0),
|
|
28055
|
+
expiresAt: text("expires_at"),
|
|
28056
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28057
|
+
}, (t) => [index("idx_server_invite_server").on(t.serverId)]);
|
|
28058
|
+
var communityFriendship = sqliteTable("community_friendship", {
|
|
28059
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28060
|
+
requesterId: text("requester_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28061
|
+
addresseeId: text("addressee_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28062
|
+
status: text("status").notNull().default("pending"),
|
|
28063
|
+
needsOwnerApproval: text("needs_owner_approval").references(() => user.id),
|
|
28064
|
+
blockerId: text("blocker_id"),
|
|
28065
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
|
|
28066
|
+
updatedAt: text("updated_at").notNull().$defaultFn(() => new Date().toISOString()),
|
|
28067
|
+
resolvedAt: text("resolved_at")
|
|
28068
|
+
}, (t) => [
|
|
28069
|
+
index("idx_friendship_addressee_status").on(t.addresseeId, t.status),
|
|
28070
|
+
index("idx_friendship_requester_status").on(t.requesterId, t.status)
|
|
28071
|
+
]);
|
|
28072
|
+
var communityReadState = sqliteTable("community_read_state", {
|
|
28073
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28074
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28075
|
+
channelId: text("channel_id").notNull().references(() => communityChannel.id, {
|
|
28076
|
+
onDelete: "cascade"
|
|
28077
|
+
}),
|
|
28078
|
+
lastReadAt: text("last_read_at").notNull(),
|
|
28079
|
+
lastReadMessageId: text("last_read_message_id"),
|
|
28080
|
+
lastReadSeq: integer2("last_read_seq").notNull().default(0)
|
|
28081
|
+
}, (t) => [index("idx_read_state_user").on(t.userId)]);
|
|
28082
|
+
var communityReadStateRevision = sqliteTable("community_read_state_revision", {
|
|
28083
|
+
userId: text("user_id").primaryKey().references(() => user.id, { onDelete: "cascade" }),
|
|
28084
|
+
revision: integer2("revision").notNull().default(0)
|
|
28085
|
+
});
|
|
28086
|
+
var communityReaction = sqliteTable("community_reaction", {
|
|
28087
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28088
|
+
messageId: text("message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28089
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28090
|
+
emoji: text("emoji").notNull(),
|
|
28091
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28092
|
+
}, (t) => [
|
|
28093
|
+
unique("uq_reaction_message_user_emoji").on(t.messageId, t.userId, t.emoji),
|
|
28094
|
+
index("idx_reaction_message").on(t.messageId)
|
|
28095
|
+
]);
|
|
28096
|
+
var communityAttachment = sqliteTable("community_attachment", {
|
|
28097
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28098
|
+
messageId: text("message_id").references(() => communityMessage.id, {
|
|
28099
|
+
onDelete: "cascade"
|
|
28100
|
+
}),
|
|
28101
|
+
uploaderId: text("uploader_id").notNull(),
|
|
28102
|
+
targetId: text("target_id").notNull(),
|
|
28103
|
+
r2Key: text("r2_key").notNull(),
|
|
28104
|
+
thumbnailR2Key: text("thumbnail_r2_key"),
|
|
28105
|
+
filename: text("filename").notNull(),
|
|
28106
|
+
contentType: text("content_type"),
|
|
28107
|
+
size: integer2("size"),
|
|
28108
|
+
width: integer2("width"),
|
|
28109
|
+
height: integer2("height"),
|
|
28110
|
+
position: integer2("position"),
|
|
28111
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28112
|
+
}, (t) => [
|
|
28113
|
+
index("idx_attachment_message").on(t.messageId, t.position)
|
|
28114
|
+
]);
|
|
28115
|
+
var communityPin = sqliteTable("community_pin", {
|
|
28116
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28117
|
+
channelId: text("channel_id").notNull().references(() => communityChannel.id, { onDelete: "cascade" }),
|
|
28118
|
+
messageId: text("message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28119
|
+
pinnedBy: text("pinned_by").references(() => user.id, { onDelete: "set null" }),
|
|
28120
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28121
|
+
}, (t) => [
|
|
28122
|
+
unique("uq_pin_channel_message").on(t.channelId, t.messageId),
|
|
28123
|
+
index("idx_pin_channel").on(t.channelId)
|
|
28124
|
+
]);
|
|
28125
|
+
var communityMention = sqliteTable("community_mention", {
|
|
28126
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28127
|
+
messageId: text("message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28128
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28129
|
+
kind: text("kind").notNull().default("mention"),
|
|
28130
|
+
read: integer2("read").default(0)
|
|
28131
|
+
}, (t) => [
|
|
28132
|
+
index("idx_mention_user_read").on(t.userId, t.read),
|
|
28133
|
+
index("idx_mention_message").on(t.messageId)
|
|
28134
|
+
]);
|
|
28135
|
+
var communityUserProfile = sqliteTable("community_user_profile", {
|
|
28136
|
+
userId: text("user_id").primaryKey().references(() => user.id, { onDelete: "cascade" }),
|
|
28137
|
+
aboutMe: text("about_me").default(""),
|
|
28138
|
+
bannerColor: text("banner_color"),
|
|
28139
|
+
statusEmoji: text("status_emoji"),
|
|
28140
|
+
statusText: text("status_text").default("")
|
|
28141
|
+
});
|
|
28142
|
+
var communityNotificationSetting = sqliteTable("community_notification_setting", {
|
|
28143
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28144
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28145
|
+
serverId: text("server_id").references(() => communityServer.id, {
|
|
28146
|
+
onDelete: "cascade"
|
|
28147
|
+
}),
|
|
28148
|
+
channelId: text("channel_id").references(() => communityChannel.id, {
|
|
28149
|
+
onDelete: "cascade"
|
|
28150
|
+
}),
|
|
28151
|
+
level: text("level").notNull().default("all")
|
|
28152
|
+
}, (t) => [index("idx_notification_setting_user").on(t.userId)]);
|
|
28153
|
+
var communityBotApprovalRequest = sqliteTable("community_bot_approval_request", {
|
|
28154
|
+
id: text("id").primaryKey().$defaultFn(() => "bar_" + nanoid3()),
|
|
28155
|
+
botId: text("bot_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28156
|
+
kind: text("kind").notNull(),
|
|
28157
|
+
serverId: text("server_id").references(() => communityServer.id, {
|
|
28158
|
+
onDelete: "cascade"
|
|
28159
|
+
}),
|
|
28160
|
+
requestedByUserId: text("requested_by_user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28161
|
+
dmMessageId: text("dm_message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28162
|
+
status: text("status").notNull().default("pending"),
|
|
28163
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString()),
|
|
28164
|
+
resolvedAt: text("resolved_at")
|
|
28165
|
+
}, (t) => [index("idx_community_bot_approval_bot").on(t.botId, t.status)]);
|
|
28166
|
+
var communityBotActivityEvent = sqliteTable("community_bot_activity_event", {
|
|
28167
|
+
id: text("id").primaryKey().$defaultFn(() => "bae_" + nanoid3()),
|
|
28168
|
+
botId: text("bot_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28169
|
+
sessionId: text("session_id"),
|
|
28170
|
+
launchId: text("launch_id"),
|
|
28171
|
+
kind: text("kind").notNull(),
|
|
28172
|
+
payload: text("payload").notNull(),
|
|
28173
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28174
|
+
}, (t) => [
|
|
28175
|
+
index("idx_bot_activity_event_bot_created").on(t.botId, t.createdAt, t.id)
|
|
28176
|
+
]);
|
|
28177
|
+
var communityBotDailyActivity = sqliteTable("community_bot_daily_activity", {
|
|
28178
|
+
botId: text("bot_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28179
|
+
day: text("day").notNull(),
|
|
28180
|
+
handledCount: integer2("handled_count").notNull().default(0),
|
|
28181
|
+
sentCount: integer2("sent_count").notNull().default(0)
|
|
28182
|
+
}, (t) => [primaryKey({ columns: [t.botId, t.day] })]);
|
|
28183
|
+
var communityMessageMark = sqliteTable("community_message_mark", {
|
|
28184
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28185
|
+
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
|
28186
|
+
channelId: text("channel_id").notNull().references(() => communityChannel.id, { onDelete: "cascade" }),
|
|
28187
|
+
messageId: text("message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28188
|
+
createdAt: text("created_at").notNull().$defaultFn(() => new Date().toISOString())
|
|
28189
|
+
}, (t) => [
|
|
28190
|
+
unique("uq_mark_user_message").on(t.userId, t.messageId),
|
|
28191
|
+
index("idx_mark_user_created").on(t.userId, t.createdAt)
|
|
28192
|
+
]);
|
|
28193
|
+
var communityMessageTag = sqliteTable("community_message_tag", {
|
|
28194
|
+
id: text("id").primaryKey().$defaultFn(() => nanoid3()),
|
|
28195
|
+
messageId: text("message_id").notNull().references(() => communityMessage.id, { onDelete: "cascade" }),
|
|
28196
|
+
tag: text("tag").notNull()
|
|
28197
|
+
}, (t) => [
|
|
28198
|
+
unique("uq_message_tag").on(t.messageId, t.tag),
|
|
28199
|
+
index("idx_message_tag_tag").on(t.tag, t.messageId)
|
|
28200
|
+
]);
|
|
28201
|
+
|
|
28202
|
+
// ../shared/src/logger.ts
|
|
28203
|
+
var LEVELS = {
|
|
28204
|
+
debug: 0,
|
|
28205
|
+
info: 1,
|
|
28206
|
+
warn: 2,
|
|
28207
|
+
error: 3,
|
|
28208
|
+
silent: 4
|
|
28209
|
+
};
|
|
28210
|
+
|
|
28211
|
+
class Logger {
|
|
28212
|
+
service;
|
|
28213
|
+
level;
|
|
28214
|
+
pretty;
|
|
28215
|
+
fields;
|
|
28216
|
+
constructor(opts, fields) {
|
|
28217
|
+
this.service = opts.service;
|
|
28218
|
+
this.level = LEVELS[opts.level ?? "info"];
|
|
28219
|
+
this.pretty = opts.pretty ?? false;
|
|
28220
|
+
this.fields = fields ?? {};
|
|
28221
|
+
}
|
|
28222
|
+
debug(msg, ctx) {
|
|
28223
|
+
this.write("debug", msg, ctx);
|
|
28224
|
+
}
|
|
28225
|
+
info(msg, ctx) {
|
|
28226
|
+
this.write("info", msg, ctx);
|
|
28227
|
+
}
|
|
28228
|
+
warn(msg, ctx) {
|
|
28229
|
+
this.write("warn", msg, ctx);
|
|
28230
|
+
}
|
|
28231
|
+
error(msg, ctx) {
|
|
28232
|
+
this.write("error", msg, ctx);
|
|
28233
|
+
}
|
|
28234
|
+
child(fields) {
|
|
28235
|
+
const merged = { ...this.fields, ...fields };
|
|
28236
|
+
const child = new Logger({ service: this.service, level: this.levelName(), pretty: this.pretty }, merged);
|
|
28237
|
+
return child;
|
|
28238
|
+
}
|
|
28239
|
+
levelName() {
|
|
28240
|
+
for (const [name, num] of Object.entries(LEVELS)) {
|
|
28241
|
+
if (num === this.level)
|
|
28242
|
+
return name;
|
|
28243
|
+
}
|
|
28244
|
+
return "info";
|
|
28245
|
+
}
|
|
28246
|
+
write(level, msg, ctx) {
|
|
28247
|
+
if (LEVELS[level] < this.level)
|
|
28248
|
+
return;
|
|
28249
|
+
const entry = {
|
|
28250
|
+
level,
|
|
28251
|
+
msg,
|
|
28252
|
+
service: this.service,
|
|
28253
|
+
...this.fields,
|
|
28254
|
+
...ctx,
|
|
28255
|
+
ts: new Date().toISOString()
|
|
28256
|
+
};
|
|
28257
|
+
for (const [k, v] of Object.entries(entry)) {
|
|
28258
|
+
if (v instanceof Error) {
|
|
28259
|
+
entry[k] = { message: v.message, stack: v.stack };
|
|
28260
|
+
}
|
|
28261
|
+
}
|
|
28262
|
+
let line;
|
|
28263
|
+
if (this.pretty) {
|
|
28264
|
+
const ts = entry.ts.replace("T", " ").replace("Z", "");
|
|
28265
|
+
const lvl = entry.level.toUpperCase().padEnd(5);
|
|
28266
|
+
const pairs = Object.entries(entry).filter(([k]) => k !== "level" && k !== "msg" && k !== "service" && k !== "ts").map(([k, v]) => `${k}=${typeof v === "object" ? JSON.stringify(v) : v}`).join(" ");
|
|
28267
|
+
line = `${ts} ${lvl} [${entry.service}] ${entry.msg}${pairs ? " " + pairs : ""}`;
|
|
28268
|
+
} else {
|
|
28269
|
+
line = JSON.stringify(entry);
|
|
28270
|
+
}
|
|
28271
|
+
if (level === "error") {
|
|
28272
|
+
console.error(line);
|
|
28273
|
+
} else {
|
|
28274
|
+
console.log(line);
|
|
28275
|
+
}
|
|
28276
|
+
}
|
|
28277
|
+
}
|
|
28278
|
+
function createLogger2(opts) {
|
|
28279
|
+
return new Logger(opts);
|
|
28280
|
+
}
|
|
28281
|
+
|
|
28282
|
+
// ../shared/src/db/queries/_chunk.ts
|
|
28283
|
+
var D1_MAX_BIND_PARAMS = 100;
|
|
28284
|
+
function maxRowsPerInsert(paramsPerRow) {
|
|
28285
|
+
if (paramsPerRow < 1)
|
|
28286
|
+
throw new Error("paramsPerRow must be >= 1");
|
|
28287
|
+
return Math.floor(D1_MAX_BIND_PARAMS / paramsPerRow);
|
|
28288
|
+
}
|
|
28289
|
+
|
|
28290
|
+
// ../shared/src/db/queries/community/message.ts
|
|
28291
|
+
var log = createLogger2({ service: "community-queries" });
|
|
28292
|
+
var listedMessageProjection = {
|
|
28293
|
+
id: communityMessage.id,
|
|
28294
|
+
authorId: communityMessage.authorId,
|
|
28295
|
+
content: communityMessage.content,
|
|
28296
|
+
type: communityMessage.type,
|
|
28297
|
+
mentionType: communityMessage.mentionType,
|
|
28298
|
+
replyToId: communityMessage.replyToId,
|
|
28299
|
+
embeds: communityMessage.embeds,
|
|
28300
|
+
seq: communityMessage.seq,
|
|
28301
|
+
createdAt: communityMessage.createdAt,
|
|
28302
|
+
channelId: communityMessage.channelId,
|
|
28303
|
+
friendshipId: communityMessage.friendshipId,
|
|
28304
|
+
clientNonce: communityMessage.clientNonce,
|
|
28305
|
+
authorName: user.name,
|
|
28306
|
+
authorEmail: user.email,
|
|
28307
|
+
authorImage: user.image
|
|
28308
|
+
};
|
|
28309
|
+
|
|
28310
|
+
// ../shared/src/db/queries/user.ts
|
|
28311
|
+
var publicUserColumns = {
|
|
28312
|
+
id: user.id,
|
|
28313
|
+
name: user.name,
|
|
28314
|
+
email: user.email,
|
|
28315
|
+
emailVerified: user.emailVerified,
|
|
28316
|
+
image: user.image,
|
|
28317
|
+
createdAt: user.createdAt,
|
|
28318
|
+
updatedAt: user.updatedAt,
|
|
28319
|
+
discriminator: user.discriminator
|
|
28320
|
+
};
|
|
28321
|
+
var internalUserColumns = {
|
|
28322
|
+
...publicUserColumns,
|
|
28323
|
+
isBot: user.isBot,
|
|
28324
|
+
ownerUserId: user.ownerUserId,
|
|
28325
|
+
deletedAt: user.deletedAt
|
|
28326
|
+
};
|
|
28327
|
+
|
|
28328
|
+
// ../shared/src/db/queries/community/channel.ts
|
|
28329
|
+
var CHANNEL_COLUMNS = {
|
|
28330
|
+
id: communityChannel.id,
|
|
28331
|
+
serverId: communityChannel.serverId,
|
|
28332
|
+
categoryId: communityChannel.categoryId,
|
|
28333
|
+
name: communityChannel.name,
|
|
28334
|
+
type: communityChannel.type,
|
|
28335
|
+
topic: communityChannel.topic,
|
|
28336
|
+
position: communityChannel.position,
|
|
28337
|
+
parentChannelId: communityChannel.parentChannelId,
|
|
28338
|
+
creatorId: communityChannel.creatorId,
|
|
28339
|
+
messageCount: communityChannel.messageCount,
|
|
28340
|
+
archived: communityChannel.archived,
|
|
28341
|
+
parentMessageId: communityChannel.parentMessageId,
|
|
28342
|
+
lastMessageAt: communityChannel.lastMessageAt,
|
|
28343
|
+
createdAt: communityChannel.createdAt
|
|
28344
|
+
};
|
|
28345
|
+
|
|
28346
|
+
// ../shared/src/db/queries/community/thread.ts
|
|
28347
|
+
var NOTIFY_CONFLICT_TARGET = [
|
|
28348
|
+
communityChannelMember.channelId,
|
|
28349
|
+
communityChannelMember.userId,
|
|
28350
|
+
communityChannelMember.relation
|
|
28351
|
+
];
|
|
28352
|
+
|
|
28353
|
+
// ../shared/src/db/resilience.ts
|
|
28354
|
+
var defaultLogger = createLogger2({ service: "d1-resilience" });
|
|
28355
|
+
|
|
28356
|
+
// ../shared/src/db/queries/community/agent-inbox.ts
|
|
28357
|
+
var AGENT_MESSAGE_COLUMNS = {
|
|
28358
|
+
id: communityMessage.id,
|
|
28359
|
+
authorId: communityMessage.authorId,
|
|
28360
|
+
content: communityMessage.content,
|
|
28361
|
+
createdAt: communityMessage.createdAt,
|
|
28362
|
+
channelId: communityMessage.channelId,
|
|
28363
|
+
seq: communityMessage.seq,
|
|
28364
|
+
replyToId: communityMessage.replyToId
|
|
28365
|
+
};
|
|
28366
|
+
var channelJoinBaselineGuard = sql`${communityMessage.createdAt} > COALESCE(${communityChannelMember.addedAt}, ${communityServerMember.joinedAt}, '')`;
|
|
28367
|
+
|
|
28368
|
+
// ../shared/src/db/queries/community/mention.ts
|
|
28369
|
+
var MENTION_INSERT_MAX_ROWS = maxRowsPerInsert(5);
|
|
28370
|
+
// ../shared/src/community-ws-events.ts
|
|
28371
|
+
var string4 = exports_external.string();
|
|
28372
|
+
var nullableString = string4.nullable();
|
|
28373
|
+
var channelTypeSchema = exports_external.enum(["text", "forum"]);
|
|
28374
|
+
var mentionTypeSchema = exports_external.literal("everyone");
|
|
28375
|
+
var friendApprovalProfileSchema = exports_external.strictObject({
|
|
28376
|
+
id: string4,
|
|
28377
|
+
name: string4,
|
|
28378
|
+
discriminator: string4,
|
|
28379
|
+
image: nullableString
|
|
28380
|
+
});
|
|
28381
|
+
var FriendApprovalPayloadSchema = exports_external.strictObject({
|
|
28382
|
+
friendshipId: string4,
|
|
28383
|
+
status: exports_external.enum(["pending", "approved", "denied", "superseded", "cancelled"]),
|
|
28384
|
+
waitingOn: exports_external.enum(["you", "other-owner", "addressee"]).nullable(),
|
|
28385
|
+
otherProfile: friendApprovalProfileSchema,
|
|
28386
|
+
botProfile: friendApprovalProfileSchema,
|
|
28387
|
+
waitingOnProfile: friendApprovalProfileSchema.nullable().optional()
|
|
28388
|
+
});
|
|
28389
|
+
var messageAttachmentSchema = exports_external.strictObject({
|
|
28390
|
+
id: string4,
|
|
28391
|
+
filename: string4,
|
|
28392
|
+
url: string4,
|
|
28393
|
+
thumbnailUrl: string4.optional(),
|
|
28394
|
+
contentType: string4.optional(),
|
|
28395
|
+
size: exports_external.number().optional(),
|
|
28396
|
+
width: exports_external.number().nullable().optional(),
|
|
28397
|
+
height: exports_external.number().nullable().optional()
|
|
28398
|
+
});
|
|
28399
|
+
var messageSchema = exports_external.strictObject({
|
|
28400
|
+
id: string4,
|
|
28401
|
+
seq: exports_external.number(),
|
|
28402
|
+
authorId: string4,
|
|
28403
|
+
authorName: string4,
|
|
28404
|
+
authorAvatar: string4.optional(),
|
|
28405
|
+
content: string4,
|
|
28406
|
+
type: exports_external.enum(["chat", "system"]),
|
|
28407
|
+
systemKind: exports_external.literal("thread").optional(),
|
|
28408
|
+
mentionType: mentionTypeSchema.nullable().optional(),
|
|
28409
|
+
replyToId: nullableString.optional(),
|
|
28410
|
+
replyTo: exports_external.strictObject({
|
|
28411
|
+
id: string4,
|
|
28412
|
+
authorName: string4,
|
|
28413
|
+
text: string4,
|
|
28414
|
+
deleted: exports_external.boolean().optional()
|
|
28415
|
+
}).optional(),
|
|
28416
|
+
embeds: exports_external.array(exports_external.unknown()).optional(),
|
|
28417
|
+
attachments: exports_external.array(messageAttachmentSchema).optional(),
|
|
28418
|
+
createdAt: string4,
|
|
28419
|
+
clientNonce: string4.optional(),
|
|
28420
|
+
approval: FriendApprovalPayloadSchema.optional()
|
|
28421
|
+
});
|
|
28422
|
+
var communityMessageCreateSchema = exports_external.strictObject({
|
|
28423
|
+
type: exports_external.literal("community:message.create"),
|
|
28424
|
+
channelId: string4,
|
|
28425
|
+
serverId: string4.optional(),
|
|
28426
|
+
parentChannelId: string4.optional(),
|
|
28427
|
+
message: messageSchema
|
|
28428
|
+
});
|
|
28429
|
+
var communityMessageUpdatedSchema = exports_external.strictObject({
|
|
28430
|
+
type: exports_external.literal("community:message.updated"),
|
|
28431
|
+
channelId: string4,
|
|
28432
|
+
messageId: string4,
|
|
28433
|
+
approval: FriendApprovalPayloadSchema
|
|
28434
|
+
});
|
|
28435
|
+
var communityMessageEditedSchema = exports_external.strictObject({
|
|
28436
|
+
type: exports_external.literal("community:message.edited"),
|
|
28437
|
+
channelId: string4,
|
|
28438
|
+
messageId: string4,
|
|
28439
|
+
content: string4,
|
|
28440
|
+
parentChannelId: string4.optional(),
|
|
28441
|
+
serverId: string4.optional()
|
|
28442
|
+
}).refine((event) => event.parentChannelId === undefined || event.serverId !== undefined);
|
|
28443
|
+
var communityReactionAddSchema = exports_external.strictObject({
|
|
28444
|
+
type: exports_external.literal("community:reaction.add"),
|
|
28445
|
+
channelId: string4,
|
|
28446
|
+
messageId: string4,
|
|
28447
|
+
userId: string4,
|
|
28448
|
+
emoji: string4
|
|
28449
|
+
});
|
|
28450
|
+
var communityReactionRemoveSchema = exports_external.strictObject({
|
|
28451
|
+
type: exports_external.literal("community:reaction.remove"),
|
|
28452
|
+
channelId: string4,
|
|
28453
|
+
messageId: string4,
|
|
28454
|
+
userId: string4,
|
|
28455
|
+
emoji: string4
|
|
28456
|
+
});
|
|
28457
|
+
var communityPinAddSchema = exports_external.strictObject({
|
|
28458
|
+
type: exports_external.literal("community:pin.add"),
|
|
28459
|
+
channelId: string4,
|
|
28460
|
+
messageId: string4
|
|
28461
|
+
});
|
|
28462
|
+
var communityPinRemoveSchema = exports_external.strictObject({
|
|
28463
|
+
type: exports_external.literal("community:pin.remove"),
|
|
28464
|
+
channelId: string4,
|
|
28465
|
+
messageId: string4
|
|
28466
|
+
});
|
|
28467
|
+
var typingFields = {
|
|
28468
|
+
channelId: string4,
|
|
28469
|
+
userId: string4,
|
|
28470
|
+
name: string4.optional(),
|
|
28471
|
+
discriminator: string4.optional()
|
|
28472
|
+
};
|
|
28473
|
+
var communityTypingStartSchema = exports_external.strictObject({
|
|
28474
|
+
type: exports_external.literal("community:typing.start"),
|
|
28475
|
+
...typingFields
|
|
28476
|
+
});
|
|
28477
|
+
var communityTypingStopSchema = exports_external.strictObject({
|
|
28478
|
+
type: exports_external.literal("community:typing.stop"),
|
|
28479
|
+
...typingFields
|
|
28480
|
+
});
|
|
28481
|
+
var communityChildChannelCreateSchema = exports_external.strictObject({
|
|
28482
|
+
type: exports_external.literal("community:channel.child_create"),
|
|
28483
|
+
parentChannelId: string4,
|
|
28484
|
+
channel: exports_external.strictObject({
|
|
28485
|
+
id: string4,
|
|
28486
|
+
name: string4,
|
|
28487
|
+
type: exports_external.literal("thread"),
|
|
28488
|
+
creatorId: string4.optional(),
|
|
28489
|
+
createdAt: string4
|
|
28490
|
+
}),
|
|
28491
|
+
parentMessageId: string4.optional()
|
|
28492
|
+
});
|
|
28493
|
+
var communityChildChannelUpdateSchema = exports_external.strictObject({
|
|
28494
|
+
type: exports_external.literal("community:channel.child_update"),
|
|
28495
|
+
parentChannelId: string4,
|
|
28496
|
+
channelId: string4,
|
|
28497
|
+
changes: exports_external.strictObject({
|
|
28498
|
+
name: string4.optional(),
|
|
28499
|
+
archived: exports_external.boolean().optional(),
|
|
28500
|
+
tags: exports_external.array(string4).nullable().optional(),
|
|
28501
|
+
lastMessageAt: string4.optional(),
|
|
28502
|
+
messageCount: exports_external.number().optional()
|
|
28503
|
+
})
|
|
28504
|
+
});
|
|
28505
|
+
var communityServerUpdateSchema = exports_external.strictObject({
|
|
28506
|
+
type: exports_external.literal("community:server.update"),
|
|
28507
|
+
serverId: string4,
|
|
28508
|
+
changes: exports_external.strictObject({
|
|
28509
|
+
name: string4.optional(),
|
|
28510
|
+
description: string4.optional(),
|
|
28511
|
+
icon: nullableString.optional()
|
|
28512
|
+
})
|
|
28513
|
+
});
|
|
28514
|
+
var communityServerDeleteSchema = exports_external.strictObject({
|
|
28515
|
+
type: exports_external.literal("community:server.delete"),
|
|
28516
|
+
serverId: string4
|
|
28517
|
+
});
|
|
28518
|
+
var communityChannelCreateSchema = exports_external.strictObject({
|
|
28519
|
+
type: exports_external.literal("community:channel.create"),
|
|
28520
|
+
serverId: string4,
|
|
28521
|
+
channel: exports_external.strictObject({
|
|
28522
|
+
id: string4,
|
|
28523
|
+
name: string4,
|
|
28524
|
+
type: channelTypeSchema,
|
|
28525
|
+
categoryId: nullableString.optional(),
|
|
28526
|
+
topic: string4.optional(),
|
|
28527
|
+
position: exports_external.number(),
|
|
28528
|
+
createdAt: string4
|
|
28529
|
+
})
|
|
28530
|
+
});
|
|
28531
|
+
var communityChannelUpdateSchema = exports_external.strictObject({
|
|
28532
|
+
type: exports_external.literal("community:channel.update"),
|
|
28533
|
+
serverId: string4,
|
|
28534
|
+
channelId: string4,
|
|
28535
|
+
changes: exports_external.strictObject({
|
|
28536
|
+
name: string4.optional(),
|
|
28537
|
+
topic: string4.optional(),
|
|
28538
|
+
categoryId: nullableString.optional(),
|
|
28539
|
+
type: channelTypeSchema.optional()
|
|
28540
|
+
})
|
|
28541
|
+
});
|
|
28542
|
+
var communityChannelDeleteSchema = exports_external.strictObject({
|
|
28543
|
+
type: exports_external.literal("community:channel.delete"),
|
|
28544
|
+
serverId: string4,
|
|
28545
|
+
channelId: string4,
|
|
28546
|
+
parentChannelId: nullableString.optional(),
|
|
28547
|
+
parentMessageId: string4.optional()
|
|
28548
|
+
}).refine((event) => event.parentMessageId === undefined || typeof event.parentChannelId === "string" && event.parentChannelId.length > 0, { message: "parentMessageId requires parentChannelId" });
|
|
28549
|
+
var positionedIdSchema = exports_external.strictObject({ id: string4, position: exports_external.number() });
|
|
28550
|
+
var communityChannelReorderSchema = exports_external.strictObject({
|
|
28551
|
+
type: exports_external.literal("community:channel.reorder"),
|
|
28552
|
+
serverId: string4,
|
|
28553
|
+
channels: exports_external.array(positionedIdSchema)
|
|
28554
|
+
});
|
|
28555
|
+
var communityChannelMemberAddSchema = exports_external.strictObject({
|
|
28556
|
+
type: exports_external.literal("community:channel.member_add"),
|
|
28557
|
+
serverId: string4,
|
|
28558
|
+
channelId: string4,
|
|
28559
|
+
userId: string4
|
|
28560
|
+
});
|
|
28561
|
+
var communityChannelMemberRemoveSchema = exports_external.strictObject({
|
|
28562
|
+
type: exports_external.literal("community:channel.member_remove"),
|
|
28563
|
+
serverId: string4,
|
|
28564
|
+
channelId: string4,
|
|
28565
|
+
userId: string4
|
|
28566
|
+
});
|
|
28567
|
+
var communityCategoryCreateSchema = exports_external.strictObject({
|
|
28568
|
+
type: exports_external.literal("community:category.create"),
|
|
28569
|
+
serverId: string4,
|
|
28570
|
+
category: exports_external.strictObject({
|
|
28571
|
+
id: string4,
|
|
28572
|
+
name: string4,
|
|
28573
|
+
position: exports_external.number(),
|
|
28574
|
+
private: exports_external.boolean()
|
|
28575
|
+
})
|
|
28576
|
+
});
|
|
28577
|
+
var communityCategoryUpdateSchema = exports_external.strictObject({
|
|
28578
|
+
type: exports_external.literal("community:category.update"),
|
|
28579
|
+
serverId: string4,
|
|
28580
|
+
categoryId: string4,
|
|
28581
|
+
changes: exports_external.strictObject({
|
|
28582
|
+
name: string4.optional(),
|
|
28583
|
+
position: exports_external.number().optional(),
|
|
28584
|
+
private: exports_external.boolean().optional()
|
|
28585
|
+
})
|
|
28586
|
+
});
|
|
28587
|
+
var communityCategoryDeleteSchema = exports_external.strictObject({
|
|
28588
|
+
type: exports_external.literal("community:category.delete"),
|
|
28589
|
+
serverId: string4,
|
|
28590
|
+
categoryId: string4
|
|
28591
|
+
});
|
|
28592
|
+
var communityCategoryReorderSchema = exports_external.strictObject({
|
|
28593
|
+
type: exports_external.literal("community:category.reorder"),
|
|
28594
|
+
serverId: string4,
|
|
28595
|
+
categories: exports_external.array(positionedIdSchema)
|
|
28596
|
+
});
|
|
28597
|
+
var communityMemberJoinSchema = exports_external.strictObject({
|
|
28598
|
+
type: exports_external.literal("community:member.join"),
|
|
28599
|
+
serverId: string4,
|
|
28600
|
+
member: exports_external.strictObject({
|
|
28601
|
+
id: string4,
|
|
28602
|
+
userId: string4,
|
|
28603
|
+
name: string4,
|
|
28604
|
+
discriminator: string4,
|
|
28605
|
+
avatar: string4.optional(),
|
|
28606
|
+
role: string4,
|
|
28607
|
+
joinedAt: string4
|
|
28608
|
+
})
|
|
28609
|
+
});
|
|
28610
|
+
var communityMemberLeaveSchema = exports_external.strictObject({
|
|
28611
|
+
type: exports_external.literal("community:member.leave"),
|
|
28612
|
+
serverId: string4,
|
|
28613
|
+
userId: string4
|
|
28614
|
+
});
|
|
28615
|
+
var communityMemberUpdateSchema = exports_external.strictObject({
|
|
28616
|
+
type: exports_external.literal("community:member.update"),
|
|
28617
|
+
serverId: string4,
|
|
28618
|
+
memberId: string4,
|
|
28619
|
+
userId: string4.optional(),
|
|
28620
|
+
changes: exports_external.strictObject({
|
|
28621
|
+
role: string4.optional(),
|
|
28622
|
+
nickname: nullableString.optional()
|
|
28623
|
+
})
|
|
28624
|
+
});
|
|
28625
|
+
var communityFriendRequestSchema = exports_external.strictObject({
|
|
28626
|
+
type: exports_external.literal("community:friend.request"),
|
|
28627
|
+
friendship: exports_external.strictObject({
|
|
28628
|
+
id: string4,
|
|
28629
|
+
requesterId: string4,
|
|
28630
|
+
addresseeId: string4,
|
|
28631
|
+
status: exports_external.literal("pending"),
|
|
28632
|
+
createdAt: string4
|
|
28633
|
+
})
|
|
28634
|
+
});
|
|
28635
|
+
var friendshipIdFields = { friendshipId: string4 };
|
|
28636
|
+
var communityFriendAcceptSchema = exports_external.strictObject({
|
|
28637
|
+
type: exports_external.literal("community:friend.accept"),
|
|
28638
|
+
...friendshipIdFields
|
|
28639
|
+
});
|
|
28640
|
+
var communityFriendRejectSchema = exports_external.strictObject({
|
|
28641
|
+
type: exports_external.literal("community:friend.reject"),
|
|
28642
|
+
...friendshipIdFields
|
|
28643
|
+
});
|
|
28644
|
+
var communityFriendRemoveSchema = exports_external.strictObject({
|
|
28645
|
+
type: exports_external.literal("community:friend.remove"),
|
|
28646
|
+
...friendshipIdFields
|
|
28647
|
+
});
|
|
28648
|
+
var communityFriendBlockSchema = exports_external.strictObject({
|
|
28649
|
+
type: exports_external.literal("community:friend.block"),
|
|
28650
|
+
userId: string4
|
|
28651
|
+
});
|
|
28652
|
+
var communityInviteCreateSchema = exports_external.strictObject({
|
|
28653
|
+
type: exports_external.literal("community:invite.create"),
|
|
28654
|
+
serverId: string4,
|
|
28655
|
+
invite: exports_external.strictObject({
|
|
28656
|
+
id: string4,
|
|
28657
|
+
token: string4,
|
|
28658
|
+
maxUses: exports_external.number().nullable().optional(),
|
|
28659
|
+
uses: exports_external.number().nullable().optional(),
|
|
28660
|
+
expiresAt: nullableString.optional(),
|
|
28661
|
+
createdAt: string4
|
|
28662
|
+
})
|
|
28663
|
+
});
|
|
28664
|
+
var communityMentionCreateSchema = exports_external.strictObject({
|
|
28665
|
+
type: exports_external.literal("community:mention.create"),
|
|
28666
|
+
userId: string4,
|
|
28667
|
+
messageId: string4,
|
|
28668
|
+
channelId: string4.optional(),
|
|
28669
|
+
authorName: string4
|
|
28670
|
+
});
|
|
28671
|
+
var communityUnreadBumpSchema = exports_external.strictObject({
|
|
28672
|
+
type: exports_external.literal("community:unread.bump"),
|
|
28673
|
+
userId: string4,
|
|
28674
|
+
channelId: string4,
|
|
28675
|
+
serverId: string4.optional(),
|
|
28676
|
+
railChannelId: string4.optional(),
|
|
28677
|
+
isMention: exports_external.boolean().optional()
|
|
28678
|
+
});
|
|
28679
|
+
var readStateEnvelopeFields = {
|
|
28680
|
+
revision: exports_external.number().int().positive(),
|
|
28681
|
+
inboxChanged: exports_external.literal(true)
|
|
28682
|
+
};
|
|
28683
|
+
var communityReadStateAdvancedSchema = exports_external.strictObject({
|
|
28684
|
+
type: exports_external.literal("community:read_state.advanced"),
|
|
28685
|
+
...readStateEnvelopeFields
|
|
28686
|
+
});
|
|
28687
|
+
var communityInboxChangedSchema = exports_external.strictObject({
|
|
28688
|
+
type: exports_external.literal("community:inbox.changed"),
|
|
28689
|
+
...readStateEnvelopeFields,
|
|
28690
|
+
reason: exports_external.enum([
|
|
28691
|
+
"read_all",
|
|
28692
|
+
"mention_read_all",
|
|
28693
|
+
"mention_dismiss",
|
|
28694
|
+
"notification_policy"
|
|
28695
|
+
])
|
|
28696
|
+
});
|
|
28697
|
+
var communityPresenceUpdateSchema = exports_external.strictObject({
|
|
28698
|
+
type: exports_external.literal("community:presence.update"),
|
|
28699
|
+
userId: string4,
|
|
28700
|
+
online: exports_external.boolean()
|
|
28701
|
+
});
|
|
28702
|
+
var communityStatusUpdateSchema = exports_external.strictObject({
|
|
28703
|
+
type: exports_external.literal("community:status.update"),
|
|
28704
|
+
userId: string4,
|
|
28705
|
+
statusEmoji: nullableString,
|
|
28706
|
+
statusText: nullableString
|
|
28707
|
+
});
|
|
28708
|
+
var machineRuntimeSchema = CommunityMachineRuntimeSchema.strict();
|
|
28709
|
+
var CommunityMachineSummarySchema2 = exports_external.strictObject({
|
|
28710
|
+
id: string4,
|
|
28711
|
+
hostname: string4,
|
|
28712
|
+
displayName: string4,
|
|
28713
|
+
platform: string4,
|
|
28714
|
+
arch: string4,
|
|
28715
|
+
osRelease: string4,
|
|
28716
|
+
daemonVersion: string4,
|
|
28717
|
+
lastSeenAt: nullableString,
|
|
28718
|
+
status: exports_external.enum(["online", "offline"]),
|
|
28719
|
+
availableRuntimes: exports_external.array(machineRuntimeSchema),
|
|
28720
|
+
lastRuntimeError: exports_external.strictObject({
|
|
28721
|
+
requested: string4,
|
|
28722
|
+
available: exports_external.array(string4),
|
|
28723
|
+
at: string4
|
|
28724
|
+
}).optional(),
|
|
28725
|
+
createdAt: string4,
|
|
28726
|
+
updatedAt: string4
|
|
28727
|
+
});
|
|
28728
|
+
var communityMachineCreatedSchema = exports_external.strictObject({
|
|
28729
|
+
type: exports_external.literal("community:machine.created"),
|
|
28730
|
+
machine: CommunityMachineSummarySchema2,
|
|
28731
|
+
tokenId: string4
|
|
28732
|
+
});
|
|
28733
|
+
var communityMachineStatusSchema = exports_external.strictObject({
|
|
28734
|
+
type: exports_external.literal("community:machine.status"),
|
|
28735
|
+
machineId: string4,
|
|
28736
|
+
status: exports_external.enum(["online", "offline"]),
|
|
28737
|
+
lastSeenAt: string4
|
|
28738
|
+
});
|
|
28739
|
+
var communityMachineUpdatedSchema = exports_external.strictObject({
|
|
28740
|
+
type: exports_external.literal("community:machine.updated"),
|
|
28741
|
+
machine: CommunityMachineSummarySchema2
|
|
28742
|
+
});
|
|
28743
|
+
var communityMachineRemovedSchema = exports_external.strictObject({
|
|
28744
|
+
type: exports_external.literal("community:machine.removed"),
|
|
28745
|
+
machineId: string4
|
|
28746
|
+
});
|
|
28747
|
+
var communityBotAuditEventSchema = exports_external.strictObject({
|
|
28748
|
+
type: exports_external.literal("community:bot.audit_event"),
|
|
28749
|
+
botId: string4,
|
|
28750
|
+
id: string4,
|
|
28751
|
+
kind: exports_external.enum(["cli_invocation", "tool_call", "thinking", "wake_trigger", "session_reset", "nap", "model_changed", "provider_changed", "error"]),
|
|
28752
|
+
payload: exports_external.unknown(),
|
|
28753
|
+
sessionId: nullableString.optional(),
|
|
28754
|
+
launchId: nullableString.optional(),
|
|
28755
|
+
createdAt: string4
|
|
28756
|
+
}).refine((event) => Object.prototype.hasOwnProperty.call(event, "payload"));
|
|
28757
|
+
var CommunityWsEventDiscriminatedSchema = exports_external.discriminatedUnion("type", [
|
|
28758
|
+
communityMessageCreateSchema,
|
|
28759
|
+
communityMessageUpdatedSchema,
|
|
28760
|
+
communityMessageEditedSchema,
|
|
28761
|
+
communityReactionAddSchema,
|
|
28762
|
+
communityReactionRemoveSchema,
|
|
28763
|
+
communityPinAddSchema,
|
|
28764
|
+
communityPinRemoveSchema,
|
|
28765
|
+
communityTypingStartSchema,
|
|
28766
|
+
communityTypingStopSchema,
|
|
28767
|
+
communityChildChannelCreateSchema,
|
|
28768
|
+
communityChildChannelUpdateSchema,
|
|
28769
|
+
communityServerUpdateSchema,
|
|
28770
|
+
communityServerDeleteSchema,
|
|
28771
|
+
communityChannelCreateSchema,
|
|
28772
|
+
communityChannelUpdateSchema,
|
|
28773
|
+
communityChannelDeleteSchema,
|
|
28774
|
+
communityChannelReorderSchema,
|
|
28775
|
+
communityChannelMemberAddSchema,
|
|
28776
|
+
communityChannelMemberRemoveSchema,
|
|
28777
|
+
communityCategoryCreateSchema,
|
|
28778
|
+
communityCategoryUpdateSchema,
|
|
28779
|
+
communityCategoryDeleteSchema,
|
|
28780
|
+
communityCategoryReorderSchema,
|
|
28781
|
+
communityMemberJoinSchema,
|
|
28782
|
+
communityMemberLeaveSchema,
|
|
28783
|
+
communityMemberUpdateSchema,
|
|
28784
|
+
communityFriendRequestSchema,
|
|
28785
|
+
communityFriendAcceptSchema,
|
|
28786
|
+
communityFriendRejectSchema,
|
|
28787
|
+
communityFriendRemoveSchema,
|
|
28788
|
+
communityFriendBlockSchema,
|
|
28789
|
+
communityInviteCreateSchema,
|
|
28790
|
+
communityMentionCreateSchema,
|
|
28791
|
+
communityUnreadBumpSchema,
|
|
28792
|
+
communityReadStateAdvancedSchema,
|
|
28793
|
+
communityInboxChangedSchema,
|
|
28794
|
+
communityPresenceUpdateSchema,
|
|
28795
|
+
communityStatusUpdateSchema,
|
|
28796
|
+
communityMachineCreatedSchema,
|
|
28797
|
+
communityMachineStatusSchema,
|
|
28798
|
+
communityMachineUpdatedSchema,
|
|
28799
|
+
communityMachineRemovedSchema,
|
|
28800
|
+
communityBotAuditEventSchema
|
|
28801
|
+
]);
|
|
28802
|
+
var CommunityWsEventSchema = CommunityWsEventDiscriminatedSchema.transform((event) => event);
|
|
28803
|
+
var WS_EVENTS = {
|
|
28804
|
+
MESSAGE_CREATE: "community:message.create",
|
|
28805
|
+
MESSAGE_UPDATED: "community:message.updated",
|
|
28806
|
+
MESSAGE_EDITED: "community:message.edited",
|
|
28807
|
+
REACTION_ADD: "community:reaction.add",
|
|
28808
|
+
REACTION_REMOVE: "community:reaction.remove",
|
|
28809
|
+
PIN_ADD: "community:pin.add",
|
|
28810
|
+
PIN_REMOVE: "community:pin.remove",
|
|
28811
|
+
TYPING_START: "community:typing.start",
|
|
28812
|
+
TYPING_STOP: "community:typing.stop",
|
|
28813
|
+
CHILD_CHANNEL_CREATE: "community:channel.child_create",
|
|
28814
|
+
CHILD_CHANNEL_UPDATE: "community:channel.child_update",
|
|
28815
|
+
SERVER_UPDATE: "community:server.update",
|
|
28816
|
+
SERVER_DELETE: "community:server.delete",
|
|
28817
|
+
CHANNEL_CREATE: "community:channel.create",
|
|
28818
|
+
CHANNEL_UPDATE: "community:channel.update",
|
|
28819
|
+
CHANNEL_DELETE: "community:channel.delete",
|
|
28820
|
+
CHANNEL_REORDER: "community:channel.reorder",
|
|
28821
|
+
CHANNEL_MEMBER_ADD: "community:channel.member_add",
|
|
28822
|
+
CHANNEL_MEMBER_REMOVE: "community:channel.member_remove",
|
|
28823
|
+
CATEGORY_CREATE: "community:category.create",
|
|
28824
|
+
CATEGORY_UPDATE: "community:category.update",
|
|
28825
|
+
CATEGORY_DELETE: "community:category.delete",
|
|
28826
|
+
CATEGORY_REORDER: "community:category.reorder",
|
|
28827
|
+
MEMBER_JOIN: "community:member.join",
|
|
28828
|
+
MEMBER_LEAVE: "community:member.leave",
|
|
28829
|
+
MEMBER_UPDATE: "community:member.update",
|
|
28830
|
+
FRIEND_REQUEST: "community:friend.request",
|
|
28831
|
+
FRIEND_ACCEPT: "community:friend.accept",
|
|
28832
|
+
FRIEND_REJECT: "community:friend.reject",
|
|
28833
|
+
FRIEND_REMOVE: "community:friend.remove",
|
|
28834
|
+
FRIEND_BLOCK: "community:friend.block",
|
|
28835
|
+
INVITE_CREATE: "community:invite.create",
|
|
28836
|
+
MENTION_CREATE: "community:mention.create",
|
|
28837
|
+
UNREAD_BUMP: "community:unread.bump",
|
|
28838
|
+
READ_STATE_ADVANCED: "community:read_state.advanced",
|
|
28839
|
+
INBOX_CHANGED: "community:inbox.changed",
|
|
28840
|
+
PRESENCE_UPDATE: "community:presence.update",
|
|
28841
|
+
STATUS_UPDATE: "community:status.update",
|
|
28842
|
+
MACHINE_CREATED: "community:machine.created",
|
|
28843
|
+
MACHINE_STATUS: "community:machine.status",
|
|
28844
|
+
MACHINE_UPDATED: "community:machine.updated",
|
|
28845
|
+
MACHINE_REMOVED: "community:machine.removed",
|
|
28846
|
+
BOT_AUDIT_EVENT: "community:bot.audit_event"
|
|
28847
|
+
};
|
|
28848
|
+
var COMMUNITY_EVENT_TYPES = new Set(Object.values(WS_EVENTS));
|
|
28849
|
+
var COMMUNITY_BROWSER_EVENT_MAX_BYTES = 65536;
|
|
28850
|
+
var COMMUNITY_USER_TARGET_MAX_BYTES = 128;
|
|
28851
|
+
function utf8ByteLength(value) {
|
|
28852
|
+
return new TextEncoder().encode(value).byteLength;
|
|
28853
|
+
}
|
|
28854
|
+
function isWellFormedUnicode(value) {
|
|
28855
|
+
for (let index2 = 0;index2 < value.length; index2 += 1) {
|
|
28856
|
+
const codeUnit = value.charCodeAt(index2);
|
|
28857
|
+
if (codeUnit >= 55296 && codeUnit <= 56319) {
|
|
28858
|
+
const next = value.charCodeAt(index2 + 1);
|
|
28859
|
+
if (!Number.isInteger(next) || next < 56320 || next > 57343)
|
|
28860
|
+
return false;
|
|
28861
|
+
index2 += 1;
|
|
28862
|
+
} else if (codeUnit >= 56320 && codeUnit <= 57343) {
|
|
28863
|
+
return false;
|
|
28864
|
+
}
|
|
28865
|
+
}
|
|
28866
|
+
return true;
|
|
28867
|
+
}
|
|
28868
|
+
function isValidCommunityUserTarget(value) {
|
|
28869
|
+
return typeof value === "string" && value.length > 0 && isWellFormedUnicode(value) && utf8ByteLength(value) <= COMMUNITY_USER_TARGET_MAX_BYTES;
|
|
28870
|
+
}
|
|
28871
|
+
|
|
28872
|
+
// ../shared/src/community-message-delivery.ts
|
|
28873
|
+
var MESSAGE_DELIVERY_MAX_USERS = 1000;
|
|
28874
|
+
var MESSAGE_DELIVERY_MAX_EVENTS_PER_USER = 5;
|
|
28875
|
+
var target = exports_external.string().refine(isValidCommunityUserTarget);
|
|
28876
|
+
var targetList = exports_external.array(target).max(MESSAGE_DELIVERY_MAX_USERS);
|
|
28877
|
+
var memberAddedSchema = exports_external.strictObject({
|
|
28878
|
+
userId: target,
|
|
28879
|
+
serverId: exports_external.string().min(1),
|
|
28880
|
+
channelId: exports_external.string().min(1)
|
|
28881
|
+
});
|
|
28882
|
+
var batchShape = exports_external.strictObject({
|
|
28883
|
+
messageId: exports_external.string().min(1),
|
|
28884
|
+
messageEvent: exports_external.unknown(),
|
|
28885
|
+
contentUserIds: targetList,
|
|
28886
|
+
unreadPlainUserIds: targetList,
|
|
28887
|
+
unreadMentionUserIds: targetList,
|
|
28888
|
+
mentionUserIds: targetList,
|
|
28889
|
+
memberAdded: memberAddedSchema.optional(),
|
|
28890
|
+
parentProjection: exports_external.unknown().optional(),
|
|
28891
|
+
parentProjectionUserIds: targetList.optional()
|
|
28892
|
+
});
|
|
28893
|
+
// ../shared/src/community/bot-activity-presets.ts
|
|
28894
|
+
var BOT_ACTIVITY_PRESETS = {
|
|
28895
|
+
idle: { emoji: "\uD83D\uDCA4", text: "Idle" },
|
|
28896
|
+
starting: { emoji: "\uD83C\uDF00", text: "Waking up" },
|
|
28897
|
+
stopping: { emoji: "\uD83C\uDF19", text: "Wrapping up" }
|
|
28898
|
+
};
|
|
28899
|
+
var RUNNING_PRESETS = [
|
|
28900
|
+
{ emoji: "⚡", text: "Working on it" },
|
|
28901
|
+
{ emoji: "\uD83D\uDEE0️", text: "Cooking" },
|
|
28902
|
+
{ emoji: "\uD83E\uDDE0", text: "Thinking hard" },
|
|
28903
|
+
{ emoji: "\uD83D\uDD27", text: "Tinkering" },
|
|
28904
|
+
{ emoji: "\uD83D\uDE80", text: "On it" },
|
|
28905
|
+
{ emoji: "\uD83D\uDD25", text: "In the zone" }
|
|
28906
|
+
];
|
|
28907
|
+
var BOT_ACTIVITY_STATUS_PAIRS = [
|
|
28908
|
+
BOT_ACTIVITY_PRESETS.idle,
|
|
28909
|
+
BOT_ACTIVITY_PRESETS.starting,
|
|
28910
|
+
BOT_ACTIVITY_PRESETS.stopping,
|
|
28911
|
+
...RUNNING_PRESETS
|
|
28912
|
+
];
|
|
28913
|
+
// ../shared/src/community-ws-bundle.ts
|
|
28914
|
+
var COMMUNITY_BROWSER_EVENT_BATCH_ENVELOPE_BYTES = 1024;
|
|
28915
|
+
var COMMUNITY_BROWSER_EVENT_BATCH_MAX_BYTES = MESSAGE_DELIVERY_MAX_EVENTS_PER_USER * COMMUNITY_BROWSER_EVENT_MAX_BYTES + COMMUNITY_BROWSER_EVENT_BATCH_ENVELOPE_BYTES;
|
|
28916
|
+
// ../shared/src/db/index.ts
|
|
28917
|
+
var allSchema = { ...exports_schema, ...exports_community_schema, ...exports_community_machine_schema };
|
|
28918
|
+
// ../shared/src/db/queries/task.ts
|
|
28919
|
+
var DEFAULT_STALE_SECONDS = Number(process.env.ALOOK_STALE_DISPATCH_TIMEOUT_S) || 20;
|
|
28920
|
+
var DEFAULT_STALE_RUNNING_SECONDS = Number(process.env.ALOOK_STALE_RUNNING_TIMEOUT_S) || 3600;
|
|
28921
|
+
// ../shared/src/utils/email.ts
|
|
28922
|
+
var DOMAIN = `@${process.env.ALOOK_DOMAIN || "alook.ai"}`;
|
|
28923
|
+
var RESERVED_HANDLES = new Set([
|
|
28924
|
+
"no-reply",
|
|
28925
|
+
"noreply",
|
|
28926
|
+
"admin",
|
|
28927
|
+
"support",
|
|
28928
|
+
"help",
|
|
28929
|
+
"info",
|
|
28930
|
+
"postmaster",
|
|
28931
|
+
"abuse",
|
|
28932
|
+
"security",
|
|
28933
|
+
"mailer-daemon",
|
|
28934
|
+
"root",
|
|
28935
|
+
"webmaster",
|
|
28936
|
+
"hostmaster",
|
|
28937
|
+
"system",
|
|
28938
|
+
"alook"
|
|
28939
|
+
]);
|
|
28940
|
+
// ../shared/src/db/queries/community/search.ts
|
|
28941
|
+
var FTS_KEYWORDS = new Set(["and", "or", "not", "near"]);
|
|
28942
|
+
// ../shared/src/db/queries/community/server-folder.ts
|
|
28943
|
+
var FOLDER_ITEM_INSERT_MAX_ROWS = maxRowsPerInsert(3);
|
|
28944
|
+
// ../shared/src/db/queries/community/diagnostic-report.ts
|
|
28945
|
+
var diagnosticOwner = alias(user, "diagnostic_owner");
|
|
26832
28946
|
// src/manager/wakeCoordinator.ts
|
|
26833
28947
|
class WakeCoordinator {
|
|
26834
28948
|
agents = new Map;
|
|
@@ -27114,6 +29228,7 @@ var DEFAULT_PING_INTERVAL_MS = 15000;
|
|
|
27114
29228
|
var DEFAULT_PONG_TIMEOUT_MS = 30000;
|
|
27115
29229
|
var DEFAULT_RECONNECT_BASE_MS = 500;
|
|
27116
29230
|
var DEFAULT_RECONNECT_MAX_MS = 30000;
|
|
29231
|
+
var DEFAULT_AUDIT_ACK_RETRY_MS = 5000;
|
|
27117
29232
|
function describeErr(err) {
|
|
27118
29233
|
return err instanceof Error ? err.message : String(err);
|
|
27119
29234
|
}
|
|
@@ -27129,8 +29244,10 @@ class WsControlChannel {
|
|
|
27129
29244
|
closedByUser = false;
|
|
27130
29245
|
authRejected = false;
|
|
27131
29246
|
pingTimer = null;
|
|
29247
|
+
auditRetryTimer = null;
|
|
27132
29248
|
pongDeadline = 0;
|
|
27133
29249
|
resyncProvider = null;
|
|
29250
|
+
pendingBotAuditEvents = new Map;
|
|
27134
29251
|
log;
|
|
27135
29252
|
wakeCoordinator = new WakeCoordinator;
|
|
27136
29253
|
constructor(opts) {
|
|
@@ -27148,6 +29265,7 @@ class WsControlChannel {
|
|
|
27148
29265
|
close() {
|
|
27149
29266
|
this.closedByUser = true;
|
|
27150
29267
|
this.clearHeartbeat();
|
|
29268
|
+
this.clearAuditRetry();
|
|
27151
29269
|
this.ws?.close();
|
|
27152
29270
|
this.ws = null;
|
|
27153
29271
|
this.statusValue = "closed";
|
|
@@ -27205,7 +29323,26 @@ class WsControlChannel {
|
|
|
27205
29323
|
this.sendFrame({ type: "agent_typing_stop", ...info });
|
|
27206
29324
|
}
|
|
27207
29325
|
async reportBotAuditEvent(frame) {
|
|
29326
|
+
if (frame.event.kind === "session_reset" && frame.event.payload.trigger === "idle_timeout") {
|
|
29327
|
+
if (!frame.eventId || !frame.occurredAt) {
|
|
29328
|
+
this.log.error("durable idle-reset audit missing local receipt", {
|
|
29329
|
+
agentId: frame.agentId
|
|
29330
|
+
});
|
|
29331
|
+
return;
|
|
29332
|
+
}
|
|
29333
|
+
this.pendingBotAuditEvents.set(frame.eventId, frame);
|
|
29334
|
+
this.sendFrame(frame);
|
|
29335
|
+
this.scheduleAuditRetry();
|
|
29336
|
+
return;
|
|
29337
|
+
}
|
|
29338
|
+
this.sendFrame(frame);
|
|
29339
|
+
}
|
|
29340
|
+
restorePendingBotAuditEvent(frame) {
|
|
29341
|
+
if (!frame.eventId || !frame.occurredAt)
|
|
29342
|
+
return;
|
|
29343
|
+
this.pendingBotAuditEvents.set(frame.eventId, frame);
|
|
27208
29344
|
this.sendFrame(frame);
|
|
29345
|
+
this.scheduleAuditRetry();
|
|
27209
29346
|
}
|
|
27210
29347
|
async reportWakeAck(info) {
|
|
27211
29348
|
this.wakeCoordinator.recordDeliveryAck(info.agentId, info.launchId, info.status);
|
|
@@ -27233,10 +29370,14 @@ class WsControlChannel {
|
|
|
27233
29370
|
const liveActivities = activities ?? [];
|
|
27234
29371
|
for (const a of liveActivities)
|
|
27235
29372
|
this.sendFrame({ type: "agent_activity", ...a });
|
|
29373
|
+
for (const frame of this.pendingBotAuditEvents.values())
|
|
29374
|
+
this.sendFrame(frame);
|
|
29375
|
+
this.scheduleAuditRetry();
|
|
27236
29376
|
this.log.info("resync sent", {
|
|
27237
29377
|
ready: ready.runtimeReport.length,
|
|
27238
29378
|
sessions: sessions.length,
|
|
27239
|
-
activities: liveActivities.length
|
|
29379
|
+
activities: liveActivities.length,
|
|
29380
|
+
pendingAuditEvents: this.pendingBotAuditEvents.size
|
|
27240
29381
|
});
|
|
27241
29382
|
}
|
|
27242
29383
|
for (const hook of this.resyncHooks) {
|
|
@@ -27279,6 +29420,34 @@ class WsControlChannel {
|
|
|
27279
29420
|
this.opts.onAuthRejected?.();
|
|
27280
29421
|
return;
|
|
27281
29422
|
}
|
|
29423
|
+
const auditAck = BotAuditEventAckFrameSchema.safeParse(frame);
|
|
29424
|
+
if (auditAck.success) {
|
|
29425
|
+
this.attempt = 0;
|
|
29426
|
+
const pending = this.pendingBotAuditEvents.get(auditAck.data.eventId);
|
|
29427
|
+
if (!pending)
|
|
29428
|
+
return;
|
|
29429
|
+
let durableCleared = this.opts.onBotAuditEventAck === undefined;
|
|
29430
|
+
try {
|
|
29431
|
+
durableCleared = this.opts.onBotAuditEventAck?.({
|
|
29432
|
+
agentId: pending.agentId,
|
|
29433
|
+
eventId: auditAck.data.eventId
|
|
29434
|
+
}) ?? true;
|
|
29435
|
+
} catch (err) {
|
|
29436
|
+
this.log.warn("bot audit ack local clear threw", {
|
|
29437
|
+
eventId: auditAck.data.eventId,
|
|
29438
|
+
err: describeErr(err)
|
|
29439
|
+
});
|
|
29440
|
+
}
|
|
29441
|
+
if (durableCleared)
|
|
29442
|
+
this.pendingBotAuditEvents.delete(auditAck.data.eventId);
|
|
29443
|
+
else
|
|
29444
|
+
this.log.warn("bot audit ack local clear deferred", { eventId: auditAck.data.eventId });
|
|
29445
|
+
if (this.pendingBotAuditEvents.size === 0)
|
|
29446
|
+
this.clearAuditRetry();
|
|
29447
|
+
else
|
|
29448
|
+
this.scheduleAuditRetry();
|
|
29449
|
+
return;
|
|
29450
|
+
}
|
|
27282
29451
|
this.attempt = 0;
|
|
27283
29452
|
this.ingestCommand(frame).catch((err) => {
|
|
27284
29453
|
this.log.warn("command ingress failed", { type: frame.type, err: describeErr(err) });
|
|
@@ -27353,6 +29522,7 @@ class WsControlChannel {
|
|
|
27353
29522
|
onSocketClosed(code, reason) {
|
|
27354
29523
|
this.log.warn("control channel closed", { code, reason: reason ? String(reason) : "" });
|
|
27355
29524
|
this.clearHeartbeat();
|
|
29525
|
+
this.clearAuditRetry();
|
|
27356
29526
|
this.ws = null;
|
|
27357
29527
|
if (this.closedByUser)
|
|
27358
29528
|
return;
|
|
@@ -27400,6 +29570,26 @@ class WsControlChannel {
|
|
|
27400
29570
|
this.pingTimer = null;
|
|
27401
29571
|
}
|
|
27402
29572
|
}
|
|
29573
|
+
scheduleAuditRetry() {
|
|
29574
|
+
if (this.auditRetryTimer || this.pendingBotAuditEvents.size === 0)
|
|
29575
|
+
return;
|
|
29576
|
+
const delayMs = this.opts.auditAckRetryMs ?? DEFAULT_AUDIT_ACK_RETRY_MS;
|
|
29577
|
+
this.auditRetryTimer = setTimeout(() => {
|
|
29578
|
+
this.auditRetryTimer = null;
|
|
29579
|
+
if (this.statusValue === "open") {
|
|
29580
|
+
for (const frame of this.pendingBotAuditEvents.values())
|
|
29581
|
+
this.sendFrame(frame);
|
|
29582
|
+
}
|
|
29583
|
+
this.scheduleAuditRetry();
|
|
29584
|
+
}, delayMs);
|
|
29585
|
+
this.auditRetryTimer.unref?.();
|
|
29586
|
+
}
|
|
29587
|
+
clearAuditRetry() {
|
|
29588
|
+
if (!this.auditRetryTimer)
|
|
29589
|
+
return;
|
|
29590
|
+
clearTimeout(this.auditRetryTimer);
|
|
29591
|
+
this.auditRetryTimer = null;
|
|
29592
|
+
}
|
|
27403
29593
|
now() {
|
|
27404
29594
|
return this.opts.now ? this.opts.now() : Date.now();
|
|
27405
29595
|
}
|
|
@@ -27475,11 +29665,13 @@ var TIMELINE_READ_CHUNK_BYTES = 65536;
|
|
|
27475
29665
|
var DATE_FILENAME_PATTERN = /^\d{4}-\d{2}-\d{2}\.jsonl$/;
|
|
27476
29666
|
var RESUME_CONTROL_FILENAME = ".resume-control.json";
|
|
27477
29667
|
var RESUME_CONTROL_MAX_BYTES = 4096;
|
|
29668
|
+
var MAX_PENDING_IDLE_RESET_EVENTS = 32;
|
|
27478
29669
|
var EMPTY_RESUME_CONTROL = {
|
|
27479
29670
|
version: 1,
|
|
27480
29671
|
attemptedSessionId: null,
|
|
27481
29672
|
fencedSessionId: null,
|
|
27482
|
-
fullBarrier: null
|
|
29673
|
+
fullBarrier: null,
|
|
29674
|
+
pendingIdleResetEvents: []
|
|
27483
29675
|
};
|
|
27484
29676
|
function isBarrier(entry) {
|
|
27485
29677
|
return entry.system !== undefined;
|
|
@@ -27628,7 +29820,7 @@ function scanTimelineFile(filePath) {
|
|
|
27628
29820
|
const stat = fs7.fstatSync(fd);
|
|
27629
29821
|
if (!stat.isFile())
|
|
27630
29822
|
return null;
|
|
27631
|
-
const
|
|
29823
|
+
const chunk2 = Buffer.allocUnsafe(TIMELINE_READ_CHUNK_BYTES);
|
|
27632
29824
|
const newest = [];
|
|
27633
29825
|
let retainedBytes = 0;
|
|
27634
29826
|
let overflowed = false;
|
|
@@ -27702,11 +29894,11 @@ function scanTimelineFile(filePath) {
|
|
|
27702
29894
|
};
|
|
27703
29895
|
let position = stat.size;
|
|
27704
29896
|
while (position > 0 && !stop) {
|
|
27705
|
-
const start = Math.max(0, position -
|
|
29897
|
+
const start = Math.max(0, position - chunk2.length);
|
|
27706
29898
|
const requested = position - start;
|
|
27707
29899
|
let count = 0;
|
|
27708
29900
|
while (count < requested) {
|
|
27709
|
-
const read = fs7.readSync(fd,
|
|
29901
|
+
const read = fs7.readSync(fd, chunk2, count, requested - count, start + count);
|
|
27710
29902
|
if (read <= 0)
|
|
27711
29903
|
break;
|
|
27712
29904
|
count += read;
|
|
@@ -27715,15 +29907,15 @@ function scanTimelineFile(filePath) {
|
|
|
27715
29907
|
return null;
|
|
27716
29908
|
let segmentEnd = count;
|
|
27717
29909
|
for (let index2 = count - 1;index2 >= 0; index2--) {
|
|
27718
|
-
if (
|
|
29910
|
+
if (chunk2[index2] !== 10)
|
|
27719
29911
|
continue;
|
|
27720
|
-
finishPhysicalLine(
|
|
29912
|
+
finishPhysicalLine(chunk2.subarray(index2 + 1, segmentEnd));
|
|
27721
29913
|
segmentEnd = index2;
|
|
27722
29914
|
if (stop)
|
|
27723
29915
|
break;
|
|
27724
29916
|
}
|
|
27725
29917
|
if (!stop && segmentEnd > 0)
|
|
27726
|
-
addPart(
|
|
29918
|
+
addPart(chunk2.subarray(0, segmentEnd));
|
|
27727
29919
|
position = start;
|
|
27728
29920
|
}
|
|
27729
29921
|
if (!stop && position === 0 && (parts.length > 0 || oversized) && !discardIncompleteTail) {
|
|
@@ -27869,7 +30061,8 @@ function readResumeControlState(timelineDir) {
|
|
|
27869
30061
|
const raw = bounded.subarray(0, bytesRead).toString("utf8");
|
|
27870
30062
|
const value = JSON.parse(raw);
|
|
27871
30063
|
const validSessionId = (candidate) => candidate === null || typeof candidate === "string" && candidate.length > 0 && candidate.length <= 512;
|
|
27872
|
-
|
|
30064
|
+
const pendingIdleResetEvents = value.pendingIdleResetEvents === undefined ? [] : value.pendingIdleResetEvents;
|
|
30065
|
+
if (value.version !== 1 || !validSessionId(value.attemptedSessionId) || !validSessionId(value.fencedSessionId) || !Array.isArray(pendingIdleResetEvents) || pendingIdleResetEvents.length > MAX_PENDING_IDLE_RESET_EVENTS || pendingIdleResetEvents.some((event) => !event || typeof event !== "object" || typeof event.eventId !== "string" || event.eventId.length < 1 || event.eventId.length > 128 || typeof event.occurredAt !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(event.occurredAt) || !Number.isFinite(Date.parse(event.occurredAt))) || new Set(pendingIdleResetEvents.map((event) => event.eventId)).size !== pendingIdleResetEvents.length || value.fullBarrier !== null && value.fullBarrier !== "reset_session" && value.fullBarrier !== "nap")
|
|
27873
30066
|
return { kind: "invalid" };
|
|
27874
30067
|
return {
|
|
27875
30068
|
kind: "state",
|
|
@@ -27877,7 +30070,8 @@ function readResumeControlState(timelineDir) {
|
|
|
27877
30070
|
version: 1,
|
|
27878
30071
|
attemptedSessionId: value.attemptedSessionId,
|
|
27879
30072
|
fencedSessionId: value.fencedSessionId,
|
|
27880
|
-
fullBarrier: value.fullBarrier
|
|
30073
|
+
fullBarrier: value.fullBarrier,
|
|
30074
|
+
pendingIdleResetEvents
|
|
27881
30075
|
}
|
|
27882
30076
|
};
|
|
27883
30077
|
} catch {
|
|
@@ -27900,11 +30094,14 @@ function updateResumeControlState(timelineDir, update) {
|
|
|
27900
30094
|
const current = readResumeControlState(timelineDir);
|
|
27901
30095
|
const base = current.kind === "state" ? current.state : EMPTY_RESUME_CONTROL;
|
|
27902
30096
|
const next = update({ ...base });
|
|
30097
|
+
if (!Array.isArray(next.pendingIdleResetEvents) || next.pendingIdleResetEvents.length > MAX_PENDING_IDLE_RESET_EVENTS || next.pendingIdleResetEvents.some((event) => !event || typeof event !== "object" || typeof event.eventId !== "string" || event.eventId.length < 1 || event.eventId.length > 128 || typeof event.occurredAt !== "string" || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(event.occurredAt) || !Number.isFinite(Date.parse(event.occurredAt))) || new Set(next.pendingIdleResetEvents.map((event) => event.eventId)).size !== next.pendingIdleResetEvents.length)
|
|
30098
|
+
return false;
|
|
27903
30099
|
const canonical = {
|
|
27904
30100
|
version: 1,
|
|
27905
30101
|
attemptedSessionId: next.attemptedSessionId,
|
|
27906
30102
|
fencedSessionId: next.fencedSessionId,
|
|
27907
|
-
fullBarrier: next.fullBarrier
|
|
30103
|
+
fullBarrier: next.fullBarrier,
|
|
30104
|
+
pendingIdleResetEvents: next.pendingIdleResetEvents
|
|
27908
30105
|
};
|
|
27909
30106
|
const body = JSON.stringify(canonical) + `
|
|
27910
30107
|
`;
|
|
@@ -28568,7 +30765,7 @@ function createTimelineRecorder(opts) {
|
|
|
28568
30765
|
clearSessionStall(agentId, sessionId) {
|
|
28569
30766
|
return appendStallMarker(agentId, "stall_recovery_clear", sessionId);
|
|
28570
30767
|
},
|
|
28571
|
-
forgetSession(agentId, barrierType = "reset_session", forgottenSessionId) {
|
|
30768
|
+
forgetSession(agentId, barrierType = "reset_session", forgottenSessionId, pendingIdleResetEvent) {
|
|
28572
30769
|
retryPending(agentId);
|
|
28573
30770
|
const dir = dirFor(agentId);
|
|
28574
30771
|
if (!prepareTimelineDirectory(dir))
|
|
@@ -28580,7 +30777,8 @@ function createTimelineRecorder(opts) {
|
|
|
28580
30777
|
...state,
|
|
28581
30778
|
attemptedSessionId: null,
|
|
28582
30779
|
fencedSessionId: null,
|
|
28583
|
-
fullBarrier: barrierType
|
|
30780
|
+
fullBarrier: barrierType,
|
|
30781
|
+
pendingIdleResetEvents: pendingIdleResetEvent && !state.pendingIdleResetEvents.some(({ eventId }) => eventId === pendingIdleResetEvent.eventId) ? [...state.pendingIdleResetEvents, pendingIdleResetEvent] : state.pendingIdleResetEvents
|
|
28584
30782
|
}));
|
|
28585
30783
|
} else if (barrierType === "stall_recovery") {
|
|
28586
30784
|
persisted = updateResumeControlState(dir, (state) => ({
|
|
@@ -28611,6 +30809,19 @@ function createTimelineRecorder(opts) {
|
|
|
28611
30809
|
const result = appendTrackedEntry(dir, createSystemEntry(barrierType, stamp.toISOString(), forgottenSessionId), stamp);
|
|
28612
30810
|
handleTrackedResult(agentId, null, result);
|
|
28613
30811
|
return true;
|
|
30812
|
+
},
|
|
30813
|
+
pendingIdleResetEvents(agentId) {
|
|
30814
|
+
const state = readResumeControlState(dirFor(agentId));
|
|
30815
|
+
return state.kind === "state" ? state.state.pendingIdleResetEvents.map((event) => ({ ...event })) : [];
|
|
30816
|
+
},
|
|
30817
|
+
acknowledgeIdleResetEvent(agentId, eventId) {
|
|
30818
|
+
const dir = dirFor(agentId);
|
|
30819
|
+
if (!prepareTimelineDirectory(dir))
|
|
30820
|
+
return false;
|
|
30821
|
+
return updateResumeControlState(dir, (state) => ({
|
|
30822
|
+
...state,
|
|
30823
|
+
pendingIdleResetEvents: state.pendingIdleResetEvents.filter((event) => event.eventId !== eventId)
|
|
30824
|
+
}));
|
|
28614
30825
|
}
|
|
28615
30826
|
};
|
|
28616
30827
|
function appendStallMarker(agentId, type, sessionId) {
|
|
@@ -28637,8 +30848,8 @@ import * as fs8 from "fs";
|
|
|
28637
30848
|
import { fileURLToPath } from "url";
|
|
28638
30849
|
function resolveAlookCliPath(moduleDir) {
|
|
28639
30850
|
const thisDir = moduleDir ?? path9.dirname(fileURLToPath(import.meta.url));
|
|
28640
|
-
const
|
|
28641
|
-
return fs8.existsSync(
|
|
30851
|
+
const target2 = path9.basename(thisDir) === "dist" ? path9.resolve(thisDir, "cli", "index.js") : path9.resolve(thisDir, "..", "scripts", "alook-shim.mjs");
|
|
30852
|
+
return fs8.existsSync(target2) ? target2 : null;
|
|
28642
30853
|
}
|
|
28643
30854
|
function deriveCliFallbackCandidates(cliPath) {
|
|
28644
30855
|
if (!cliPath)
|
|
@@ -29208,18 +31419,18 @@ function createBuiltinDaemonSessionFactory(onRuntimeRawLine) {
|
|
|
29208
31419
|
};
|
|
29209
31420
|
}
|
|
29210
31421
|
async function createDaemon(opts) {
|
|
29211
|
-
const
|
|
31422
|
+
const log2 = opts.logger ?? createLogger({ header: "@alook/daemon" });
|
|
29212
31423
|
const fallbackBase = (process.env.ALOOK_PROJECT_ROOT || `${homedir4()}/.alook`) + "/daemon";
|
|
29213
31424
|
const workingDirectoryBase = opts.workingDirectoryBase ?? fallbackBase;
|
|
29214
31425
|
const workdirFor = (agentId) => `${workingDirectoryBase}/${agentId}`;
|
|
29215
31426
|
sweepTimelineHistory(workingDirectoryBase).catch(() => {
|
|
29216
|
-
|
|
31427
|
+
log2.warn("timeline startup sweep failed");
|
|
29217
31428
|
});
|
|
29218
31429
|
const resolvedCliPath = resolveAlookCliPathWithFallback(opts.agentCliPath);
|
|
29219
31430
|
const onRuntimeRawLine = createRuntimeRawLineTap({
|
|
29220
31431
|
traceDir: opts.fsmTraceDir,
|
|
29221
31432
|
enabledAgentIds: parseRuntimeRawTraceAgentIds(process.env[RUNTIME_RAW_TRACE_AGENT_IDS_ENV]),
|
|
29222
|
-
logger:
|
|
31433
|
+
logger: log2
|
|
29223
31434
|
});
|
|
29224
31435
|
const timeline2 = createTimelineRecorder({
|
|
29225
31436
|
timelineDirFor: (agentId) => `${workdirFor(agentId)}/.context_timeline`,
|
|
@@ -29235,6 +31446,8 @@ async function createDaemon(opts) {
|
|
|
29235
31446
|
const emitBotAuditEvent = (agentId, event, context) => {
|
|
29236
31447
|
channelRef?.reportBotAuditEvent?.({
|
|
29237
31448
|
type: "bot_audit_event",
|
|
31449
|
+
...context?.eventId ? { eventId: context.eventId } : {},
|
|
31450
|
+
...context?.occurredAt ? { occurredAt: context.occurredAt } : {},
|
|
29238
31451
|
agentId,
|
|
29239
31452
|
sessionId: context?.sessionId ?? null,
|
|
29240
31453
|
launchId: context?.launchId ?? null,
|
|
@@ -29256,7 +31469,7 @@ async function createDaemon(opts) {
|
|
|
29256
31469
|
}
|
|
29257
31470
|
},
|
|
29258
31471
|
onInboxPullObservationError: ({ agentId, reason, contentEncoding }) => {
|
|
29259
|
-
|
|
31472
|
+
log2.warn("inbox pull timeline observation failed", { agentId, reason, contentEncoding });
|
|
29260
31473
|
},
|
|
29261
31474
|
onMessageReminderArm: (input) => reminderSchedulerRef?.arm(input) ?? { armed: false, reason: "reminder_scheduler_unavailable" },
|
|
29262
31475
|
onProxyRequest: (agentId, method, pathname) => {
|
|
@@ -29334,6 +31547,7 @@ async function createDaemon(opts) {
|
|
|
29334
31547
|
ownerName: b.ownerName,
|
|
29335
31548
|
ownerDiscriminator: b.ownerDiscriminator
|
|
29336
31549
|
});
|
|
31550
|
+
restorePendingIdleResetEvents(b.id);
|
|
29337
31551
|
}
|
|
29338
31552
|
botCacheReady = true;
|
|
29339
31553
|
}
|
|
@@ -29344,7 +31558,7 @@ async function createDaemon(opts) {
|
|
|
29344
31558
|
try {
|
|
29345
31559
|
const bots = await listMyBotsHttp();
|
|
29346
31560
|
replaceBotCache(bots);
|
|
29347
|
-
|
|
31561
|
+
log2.info("cold-start bot-cache warmup succeeded", { bots: bots.length, attempt });
|
|
29348
31562
|
return;
|
|
29349
31563
|
} catch {
|
|
29350
31564
|
const delay3 = WARMUP_BACKOFF_MS[Math.min(attempt, WARMUP_BACKOFF_MS.length - 1)];
|
|
@@ -29352,7 +31566,7 @@ async function createDaemon(opts) {
|
|
|
29352
31566
|
attempt++;
|
|
29353
31567
|
}
|
|
29354
31568
|
}
|
|
29355
|
-
|
|
31569
|
+
log2.warn("cold-start bot-cache warmup exhausted its ceiling", { ceilingMs: WARMUP_CEILING_MS, attempts: attempt });
|
|
29356
31570
|
}
|
|
29357
31571
|
async function resyncPendingWakes() {
|
|
29358
31572
|
try {
|
|
@@ -29363,9 +31577,9 @@ async function createDaemon(opts) {
|
|
|
29363
31577
|
if (!res.ok)
|
|
29364
31578
|
throw new Error(`resync-wakes ${res.status}`);
|
|
29365
31579
|
const json2 = await res.json();
|
|
29366
|
-
|
|
31580
|
+
log2.info("wake resync completed", { attempted: json2.attempted ?? 0 });
|
|
29367
31581
|
} catch (err) {
|
|
29368
|
-
|
|
31582
|
+
log2.warn("wake resync failed", { err: err instanceof Error ? err.message : String(err) });
|
|
29369
31583
|
}
|
|
29370
31584
|
}
|
|
29371
31585
|
async function resyncPendingDiagnostics() {
|
|
@@ -29377,13 +31591,13 @@ async function createDaemon(opts) {
|
|
|
29377
31591
|
if (!res.ok)
|
|
29378
31592
|
throw new Error(`resync-diagnostics ${res.status}`);
|
|
29379
31593
|
const json2 = await res.json();
|
|
29380
|
-
|
|
31594
|
+
log2.info("diagnostics resync completed", {
|
|
29381
31595
|
pending: json2.pending ?? 0,
|
|
29382
31596
|
attempted: json2.attempted ?? 0,
|
|
29383
31597
|
ambiguous: json2.ambiguous ?? 0
|
|
29384
31598
|
});
|
|
29385
31599
|
} catch (err) {
|
|
29386
|
-
|
|
31600
|
+
log2.warn("diagnostics resync failed", { err: err instanceof Error ? err.message : String(err) });
|
|
29387
31601
|
}
|
|
29388
31602
|
}
|
|
29389
31603
|
const enrollAgent = async (agentId) => {
|
|
@@ -29415,11 +31629,11 @@ async function createDaemon(opts) {
|
|
|
29415
31629
|
return json2.runnerKey;
|
|
29416
31630
|
} catch (err) {
|
|
29417
31631
|
if (err instanceof UnknownBotError || err instanceof BotEnrollFailedError) {
|
|
29418
|
-
|
|
31632
|
+
log2.warn("agent enroll failed", { agentId, err: err.message });
|
|
29419
31633
|
throw err;
|
|
29420
31634
|
}
|
|
29421
31635
|
const wrapped = new BotEnrollFailedError(agentId, err);
|
|
29422
|
-
|
|
31636
|
+
log2.warn("agent enroll failed", { agentId, err: wrapped.message });
|
|
29423
31637
|
throw wrapped;
|
|
29424
31638
|
}
|
|
29425
31639
|
};
|
|
@@ -29428,9 +31642,23 @@ async function createDaemon(opts) {
|
|
|
29428
31642
|
headers: { Authorization: `Bearer ${opts.machineKey}` },
|
|
29429
31643
|
webSocketFactory: opts.webSocketFactory,
|
|
29430
31644
|
onAuthRejected: opts.onAuthRejected,
|
|
29431
|
-
|
|
31645
|
+
onBotAuditEventAck: ({ agentId, eventId }) => timeline2.acknowledgeIdleResetEvent(agentId, eventId),
|
|
31646
|
+
logger: log2.child("ws")
|
|
29432
31647
|
});
|
|
29433
31648
|
channelRef = channel2;
|
|
31649
|
+
function restorePendingIdleResetEvents(agentId) {
|
|
31650
|
+
for (const pending of timeline2.pendingIdleResetEvents(agentId)) {
|
|
31651
|
+
channel2.restorePendingBotAuditEvent({
|
|
31652
|
+
type: "bot_audit_event",
|
|
31653
|
+
eventId: pending.eventId,
|
|
31654
|
+
occurredAt: pending.occurredAt,
|
|
31655
|
+
agentId,
|
|
31656
|
+
sessionId: null,
|
|
31657
|
+
launchId: null,
|
|
31658
|
+
event: { kind: "session_reset", payload: { trigger: "idle_timeout" } }
|
|
31659
|
+
});
|
|
31660
|
+
}
|
|
31661
|
+
}
|
|
29434
31662
|
function handleBotFrame(cmd) {
|
|
29435
31663
|
switch (cmd.type) {
|
|
29436
31664
|
case "bot:added":
|
|
@@ -29441,7 +31669,8 @@ async function createDaemon(opts) {
|
|
|
29441
31669
|
ownerName: cmd.ownerName,
|
|
29442
31670
|
ownerDiscriminator: cmd.ownerDiscriminator
|
|
29443
31671
|
});
|
|
29444
|
-
|
|
31672
|
+
restorePendingIdleResetEvents(cmd.botId);
|
|
31673
|
+
log2.debug("bot:added", { botId: cmd.botId, name: cmd.name });
|
|
29445
31674
|
break;
|
|
29446
31675
|
case "bot:updated": {
|
|
29447
31676
|
const prev = botsById.get(cmd.botId);
|
|
@@ -29454,7 +31683,7 @@ async function createDaemon(opts) {
|
|
|
29454
31683
|
});
|
|
29455
31684
|
const nameChanged = prev && prev.name !== cmd.name;
|
|
29456
31685
|
const descChanged = prev && (prev.description ?? "") !== (cmd.description ?? "");
|
|
29457
|
-
|
|
31686
|
+
log2.debug("bot:updated", { botId: cmd.botId, name: cmd.name });
|
|
29458
31687
|
if (nameChanged || descChanged) {
|
|
29459
31688
|
manager.stop(cmd.botId);
|
|
29460
31689
|
}
|
|
@@ -29463,7 +31692,7 @@ async function createDaemon(opts) {
|
|
|
29463
31692
|
case "bot:removed":
|
|
29464
31693
|
botsById.delete(cmd.botId);
|
|
29465
31694
|
enrolledKeys.delete(cmd.botId);
|
|
29466
|
-
|
|
31695
|
+
log2.debug("bot:removed", { botId: cmd.botId });
|
|
29467
31696
|
manager.stop(cmd.botId);
|
|
29468
31697
|
break;
|
|
29469
31698
|
default:
|
|
@@ -29551,7 +31780,7 @@ async function createDaemon(opts) {
|
|
|
29551
31780
|
timeline: timeline2,
|
|
29552
31781
|
wakePromptFooter: "Use `alook inbox pull` to read your messages.",
|
|
29553
31782
|
stampWakePromptTime: true,
|
|
29554
|
-
logger:
|
|
31783
|
+
logger: log2.child("manager")
|
|
29555
31784
|
});
|
|
29556
31785
|
managerRef = manager;
|
|
29557
31786
|
manager.start();
|
|
@@ -29591,7 +31820,7 @@ async function createDaemon(opts) {
|
|
|
29591
31820
|
osRelease: opts.osRelease,
|
|
29592
31821
|
daemonVersion: opts.daemonVersion,
|
|
29593
31822
|
typingTracker,
|
|
29594
|
-
logger:
|
|
31823
|
+
logger: log2.child("router"),
|
|
29595
31824
|
onBeforeAgent: async (agentId) => {
|
|
29596
31825
|
if (!botsById.has(agentId)) {
|
|
29597
31826
|
try {
|