@openclaw/tlon 2026.5.2 → 2026.5.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/api.js +4 -0
  2. package/dist/channel-B4LtNGeZ.js +221 -0
  3. package/dist/channel-plugin-api.js +2 -0
  4. package/dist/channel.runtime-v-_0sHkJ.js +3584 -0
  5. package/dist/doctor-contract-W99wMbar.js +7 -0
  6. package/dist/doctor-contract-api.js +2 -0
  7. package/dist/index.js +18 -0
  8. package/dist/runtime-5FiW9E50.js +8 -0
  9. package/dist/runtime-api-C0hr1Rtn.js +4 -0
  10. package/dist/runtime-api.js +2 -0
  11. package/dist/setup-api.js +3 -0
  12. package/dist/setup-core-BUkZJ-MU.js +386 -0
  13. package/dist/setup-entry.js +11 -0
  14. package/dist/setup-surface-FxNMaluC.js +72 -0
  15. package/dist/test-api.js +2 -0
  16. package/package.json +15 -6
  17. package/api.ts +0 -16
  18. package/channel-plugin-api.ts +0 -1
  19. package/doctor-contract-api.ts +0 -1
  20. package/index.ts +0 -183
  21. package/runtime-api.ts +0 -17
  22. package/setup-api.ts +0 -2
  23. package/setup-entry.ts +0 -9
  24. package/src/account-fields.ts +0 -31
  25. package/src/channel.runtime.ts +0 -248
  26. package/src/channel.ts +0 -173
  27. package/src/config-schema.ts +0 -53
  28. package/src/core.test.ts +0 -278
  29. package/src/doctor-contract.ts +0 -9
  30. package/src/doctor.test.ts +0 -40
  31. package/src/doctor.ts +0 -10
  32. package/src/logger-runtime.ts +0 -1
  33. package/src/monitor/approval-runtime.ts +0 -363
  34. package/src/monitor/approval.test.ts +0 -33
  35. package/src/monitor/approval.ts +0 -286
  36. package/src/monitor/authorization.ts +0 -30
  37. package/src/monitor/cites.ts +0 -54
  38. package/src/monitor/discovery.ts +0 -68
  39. package/src/monitor/history.ts +0 -226
  40. package/src/monitor/index.ts +0 -1524
  41. package/src/monitor/media.test.ts +0 -91
  42. package/src/monitor/media.ts +0 -172
  43. package/src/monitor/processed-messages.test.ts +0 -58
  44. package/src/monitor/processed-messages.ts +0 -89
  45. package/src/monitor/settings-helpers.test.ts +0 -113
  46. package/src/monitor/settings-helpers.ts +0 -158
  47. package/src/monitor/utils.ts +0 -372
  48. package/src/runtime.ts +0 -9
  49. package/src/security.test.ts +0 -622
  50. package/src/session-route.ts +0 -40
  51. package/src/settings.ts +0 -391
  52. package/src/setup-core.ts +0 -228
  53. package/src/setup-surface.ts +0 -103
  54. package/src/targets.ts +0 -102
  55. package/src/tlon-api.test.ts +0 -589
  56. package/src/tlon-api.ts +0 -402
  57. package/src/types.ts +0 -160
  58. package/src/urbit/auth.ssrf.test.ts +0 -45
  59. package/src/urbit/auth.ts +0 -48
  60. package/src/urbit/base-url.test.ts +0 -48
  61. package/src/urbit/base-url.ts +0 -61
  62. package/src/urbit/channel-ops.ts +0 -145
  63. package/src/urbit/context.ts +0 -50
  64. package/src/urbit/errors.ts +0 -51
  65. package/src/urbit/fetch.ts +0 -42
  66. package/src/urbit/foreigns.ts +0 -49
  67. package/src/urbit/send.test.ts +0 -38
  68. package/src/urbit/send.ts +0 -176
  69. package/src/urbit/sse-client.test.ts +0 -203
  70. package/src/urbit/sse-client.ts +0 -484
  71. package/src/urbit/story.ts +0 -332
  72. package/src/urbit/upload.test.ts +0 -154
  73. package/src/urbit/upload.ts +0 -60
  74. package/test-api.ts +0 -1
  75. package/tsconfig.json +0 -16
@@ -1,372 +0,0 @@
1
- import { formatErrorMessage as sharedFormatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
2
- import { normalizeShip } from "../targets.js";
3
-
4
- export interface ParsedCite {
5
- type: "chan" | "group" | "desk" | "bait";
6
- nest?: string;
7
- author?: string;
8
- postId?: string;
9
- group?: string;
10
- flag?: string;
11
- where?: string;
12
- }
13
-
14
- // Extract all cites from message content
15
- export function extractCites(content: unknown): ParsedCite[] {
16
- if (!content || !Array.isArray(content)) {
17
- return [];
18
- }
19
-
20
- const cites: ParsedCite[] = [];
21
-
22
- for (const verse of content) {
23
- if (verse?.block?.cite && typeof verse.block.cite === "object") {
24
- const cite = verse.block.cite;
25
-
26
- if (cite.chan && typeof cite.chan === "object") {
27
- const { nest, where } = cite.chan;
28
- const whereMatch = where?.match(/\/msg\/(~[a-z-]+)\/(.+)/);
29
- cites.push({
30
- type: "chan",
31
- nest,
32
- where,
33
- author: whereMatch?.[1],
34
- postId: whereMatch?.[2],
35
- });
36
- } else if (cite.group && typeof cite.group === "string") {
37
- cites.push({ type: "group", group: cite.group });
38
- } else if (cite.desk && typeof cite.desk === "object") {
39
- cites.push({ type: "desk", flag: cite.desk.flag, where: cite.desk.where });
40
- } else if (cite.bait && typeof cite.bait === "object") {
41
- cites.push({
42
- type: "bait",
43
- group: cite.bait.group,
44
- nest: cite.bait.graph,
45
- where: cite.bait.where,
46
- });
47
- }
48
- }
49
- }
50
-
51
- return cites;
52
- }
53
-
54
- export function formatModelName(modelString?: string | null): string {
55
- if (!modelString) {
56
- return "AI";
57
- }
58
- const modelName = modelString.includes("/") ? modelString.split("/")[1] : modelString;
59
- const modelMappings: Record<string, string> = {
60
- "claude-opus-4-5": "Claude Opus 4.5",
61
- "claude-sonnet-4-5": "Claude Sonnet 4.5",
62
- "claude-sonnet-3-5": "Claude Sonnet 3.5",
63
- "gpt-4o": "GPT-4o",
64
- "gpt-4-turbo": "GPT-4 Turbo",
65
- "gpt-4": "GPT-4",
66
- "gemini-2.0-flash": "Gemini 2.0 Flash",
67
- "gemini-pro": "Gemini Pro",
68
- };
69
-
70
- if (modelMappings[modelName]) {
71
- return modelMappings[modelName];
72
- }
73
- return modelName
74
- .replace(/-/g, " ")
75
- .split(" ")
76
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
77
- .join(" ");
78
- }
79
-
80
- export function isBotMentioned(
81
- messageText: string,
82
- botShipName: string,
83
- nickname?: string,
84
- ): boolean {
85
- if (!messageText || !botShipName) {
86
- return false;
87
- }
88
-
89
- // Check for @all mention
90
- if (/@all\b/i.test(messageText)) {
91
- return true;
92
- }
93
-
94
- // Check for ship mention
95
- const normalizedBotShip = normalizeShip(botShipName);
96
- const escapedShip = normalizedBotShip.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
97
- const mentionPattern = new RegExp(`(^|\\s)${escapedShip}(?=\\s|$)`, "i");
98
- if (mentionPattern.test(messageText)) {
99
- return true;
100
- }
101
-
102
- // Check for nickname mention (case-insensitive, word boundary)
103
- if (nickname) {
104
- const escapedNickname = nickname.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
105
- const nicknamePattern = new RegExp(`(^|\\s)${escapedNickname}(?=\\s|$|[,!?.])`, "i");
106
- if (nicknamePattern.test(messageText)) {
107
- return true;
108
- }
109
- }
110
-
111
- return false;
112
- }
113
-
114
- /**
115
- * Strip bot ship mention from message text for command detection.
116
- * "~bot-ship /status" → "/status"
117
- */
118
- export function stripBotMention(messageText: string, botShipName: string): string {
119
- if (!messageText || !botShipName) {
120
- return messageText;
121
- }
122
- return messageText.replace(normalizeShip(botShipName), "").trim();
123
- }
124
-
125
- export function isDmAllowed(senderShip: string, allowlist: string[] | undefined): boolean {
126
- if (!allowlist || allowlist.length === 0) {
127
- return false;
128
- }
129
- const normalizedSender = normalizeShip(senderShip);
130
- return allowlist.map((ship) => normalizeShip(ship)).some((ship) => ship === normalizedSender);
131
- }
132
-
133
- /**
134
- * Check if a group invite from a ship should be auto-accepted.
135
- *
136
- * SECURITY: Fail-safe to deny. If allowlist is empty or undefined,
137
- * ALL invites are rejected - even if autoAcceptGroupInvites is enabled.
138
- * This prevents misconfigured bots from accepting malicious invites.
139
- */
140
- export function isGroupInviteAllowed(
141
- inviterShip: string,
142
- allowlist: string[] | undefined,
143
- ): boolean {
144
- // SECURITY: Fail-safe to deny when no allowlist configured
145
- if (!allowlist || allowlist.length === 0) {
146
- return false;
147
- }
148
- const normalizedInviter = normalizeShip(inviterShip);
149
- return allowlist.map((ship) => normalizeShip(ship)).some((ship) => ship === normalizedInviter);
150
- }
151
-
152
- /**
153
- * Resolve quoted/cited content only after the caller has passed authorization.
154
- * Unauthorized paths must keep raw text and must not trigger cross-channel cite fetches.
155
- */
156
- export async function resolveAuthorizedMessageText(params: {
157
- rawText: string;
158
- content: unknown;
159
- authorizedForCites: boolean;
160
- resolveAllCites: (content: unknown) => Promise<string>;
161
- }): Promise<string> {
162
- const { rawText, content, authorizedForCites, resolveAllCites } = params;
163
- if (!authorizedForCites) {
164
- return rawText;
165
- }
166
- const citedContent = await resolveAllCites(content);
167
- return citedContent + rawText;
168
- }
169
-
170
- export const asRecord = asNullableObjectRecord;
171
- export const formatErrorMessage = sharedFormatErrorMessage;
172
- export const readString = readStringField;
173
-
174
- function asNullableObjectRecord(value: unknown): Record<string, unknown> | null {
175
- return value && typeof value === "object" && !Array.isArray(value)
176
- ? (value as Record<string, unknown>)
177
- : null;
178
- }
179
-
180
- function readStringField(
181
- record: Record<string, unknown> | null | undefined,
182
- field: string,
183
- ): string | undefined {
184
- const value = record?.[field];
185
- return typeof value === "string" ? value : undefined;
186
- }
187
-
188
- // Helper to recursively extract text from inline content
189
- function renderInlineItem(
190
- item: unknown,
191
- options?: {
192
- linkMode?: "content-or-href" | "href";
193
- allowBreak?: boolean;
194
- allowBlockquote?: boolean;
195
- },
196
- ): string {
197
- if (typeof item === "string") {
198
- return item;
199
- }
200
- const record = asRecord(item);
201
- if (!record) {
202
- return "";
203
- }
204
- const ship = readString(record, "ship");
205
- if (ship) {
206
- return ship;
207
- }
208
- if ("sect" in record) {
209
- const sect = record.sect;
210
- if (typeof sect === "string") {
211
- return `@${sect || "all"}`;
212
- }
213
- if (sect === null) {
214
- return "@all";
215
- }
216
- }
217
- if (options?.allowBreak && "break" in record) {
218
- return "\n";
219
- }
220
- const inlineCode = readString(record, "inline-code");
221
- if (inlineCode) {
222
- return `\`${inlineCode}\``;
223
- }
224
- const code = readString(record, "code");
225
- if (code) {
226
- return `\`${code}\``;
227
- }
228
- const link = asRecord(record.link);
229
- const linkHref = link ? readString(link, "href") : undefined;
230
- if (link && linkHref) {
231
- const linkContent = readString(link, "content");
232
- return options?.linkMode === "href" ? linkHref : linkContent || linkHref;
233
- }
234
- if (Array.isArray(record.bold)) {
235
- return `**${extractInlineText(record.bold)}**`;
236
- }
237
- if (Array.isArray(record.italics)) {
238
- return `*${extractInlineText(record.italics)}*`;
239
- }
240
- if (Array.isArray(record.strike)) {
241
- return `~~${extractInlineText(record.strike)}~~`;
242
- }
243
- if (options?.allowBlockquote && Array.isArray(record.blockquote)) {
244
- return `> ${extractInlineText(record.blockquote)}`;
245
- }
246
- return "";
247
- }
248
-
249
- function extractInlineText(items: readonly unknown[]): string {
250
- return items.map((item) => renderInlineItem(item)).join("");
251
- }
252
-
253
- export function extractMessageText(content: unknown): string {
254
- if (!content || !Array.isArray(content)) {
255
- return "";
256
- }
257
-
258
- return content
259
- .map((verse) => {
260
- const verseRecord = asRecord(verse);
261
- if (!verseRecord) {
262
- return "";
263
- }
264
-
265
- // Handle inline content (text, ships, links, etc.)
266
- if (Array.isArray(verseRecord.inline)) {
267
- return verseRecord.inline
268
- .map((item) =>
269
- renderInlineItem(item, {
270
- linkMode: "href",
271
- allowBreak: true,
272
- allowBlockquote: true,
273
- }),
274
- )
275
- .join("");
276
- }
277
-
278
- // Handle block content (images, code blocks, etc.)
279
- const block = asRecord(verseRecord.block);
280
- if (block) {
281
- const image = asRecord(block.image);
282
-
283
- // Image blocks
284
- if (image) {
285
- const imageSrc = readString(image, "src");
286
- if (imageSrc) {
287
- const altText = readString(image, "alt");
288
- const alt = altText ? ` (${altText})` : "";
289
- return `\n${imageSrc}${alt}\n`;
290
- }
291
- }
292
-
293
- // Code blocks
294
- const codeBlock = asRecord(block.code);
295
- if (codeBlock) {
296
- const lang = readString(codeBlock, "lang") ?? "";
297
- const code = readString(codeBlock, "code") ?? "";
298
- return `\n\`\`\`${lang}\n${code}\n\`\`\`\n`;
299
- }
300
-
301
- // Header blocks
302
- const header = asRecord(block.header);
303
- if (header) {
304
- const headerContent = Array.isArray(header.content) ? header.content : [];
305
- const text =
306
- headerContent.map((item) => (typeof item === "string" ? item : "")).join("") || "";
307
- return `\n## ${text}\n`;
308
- }
309
-
310
- // Cite/quote blocks - parse the reference structure
311
- const cite = asRecord(block.cite);
312
- if (cite) {
313
- const chanCite = asRecord(cite.chan);
314
-
315
- // ChanCite - reference to a channel message
316
- if (chanCite) {
317
- const nest = readString(chanCite, "nest");
318
- const where = readString(chanCite, "where");
319
- // where is typically /msg/~author/timestamp
320
- const whereMatch = where?.match(/\/msg\/(~[a-z-]+)\/(.+)/);
321
- if (whereMatch) {
322
- const [, author, _postId] = whereMatch;
323
- return `\n> [quoted: ${author} in ${nest}]\n`;
324
- }
325
- return `\n> [quoted from ${nest}]\n`;
326
- }
327
-
328
- // GroupCite - reference to a group
329
- const group = readString(cite, "group");
330
- if (group) {
331
- return `\n> [ref: group ${group}]\n`;
332
- }
333
-
334
- // DeskCite - reference to an app/desk
335
- const desk = asRecord(cite.desk);
336
- if (desk) {
337
- const flag = readString(desk, "flag");
338
- if (flag) {
339
- return `\n> [ref: ${flag}]\n`;
340
- }
341
- }
342
-
343
- // BaitCite - reference with group+graph context
344
- const bait = asRecord(cite.bait);
345
- if (bait) {
346
- const graph = readString(bait, "graph");
347
- const groupName = readString(bait, "group");
348
- if (graph && groupName) {
349
- return `\n> [ref: ${graph} in ${groupName}]\n`;
350
- }
351
- }
352
-
353
- return `\n> [quoted message]\n`;
354
- }
355
- }
356
-
357
- return "";
358
- })
359
- .join("\n")
360
- .trim();
361
- }
362
-
363
- export function isSummarizationRequest(messageText: string): boolean {
364
- const patterns = [
365
- /summarize\s+(this\s+)?(channel|chat|conversation)/i,
366
- /what\s+did\s+i\s+miss/i,
367
- /catch\s+me\s+up/i,
368
- /channel\s+summary/i,
369
- /tldr/i,
370
- ];
371
- return patterns.some((pattern) => pattern.test(messageText));
372
- }
package/src/runtime.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { PluginRuntime } from "openclaw/plugin-sdk/plugin-runtime";
2
- import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
3
-
4
- const { setRuntime: setTlonRuntime, getRuntime: getTlonRuntime } =
5
- createPluginRuntimeStore<PluginRuntime>({
6
- pluginId: "tlon",
7
- errorMessage: "Tlon runtime not initialized",
8
- });
9
- export { getTlonRuntime, setTlonRuntime };