@openclaw/tlon 2026.5.2-beta.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
package/index.ts DELETED
@@ -1,183 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
6
- import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
7
-
8
- const __dirname = dirname(fileURLToPath(import.meta.url));
9
-
10
- const ALLOWED_TLON_COMMANDS = new Set([
11
- "activity",
12
- "channels",
13
- "contacts",
14
- "groups",
15
- "messages",
16
- "dms",
17
- "posts",
18
- "notebook",
19
- "settings",
20
- "help",
21
- "version",
22
- ]);
23
-
24
- let cachedTlonBinary: string | undefined;
25
-
26
- function findTlonBinary(): string {
27
- if (cachedTlonBinary) {
28
- return cachedTlonBinary;
29
- }
30
- const skillBin = join(__dirname, "node_modules", ".bin", "tlon");
31
- if (existsSync(skillBin)) {
32
- cachedTlonBinary = skillBin;
33
- return skillBin;
34
- }
35
-
36
- const platformPkg = `@tloncorp/tlon-skill-${process.platform}-${process.arch}`;
37
- const platformBin = join(__dirname, "node_modules", platformPkg, "tlon");
38
- if (existsSync(platformBin)) {
39
- cachedTlonBinary = platformBin;
40
- return platformBin;
41
- }
42
-
43
- cachedTlonBinary = "tlon";
44
- return cachedTlonBinary;
45
- }
46
-
47
- function shellSplit(str: string): string[] {
48
- const args: string[] = [];
49
- let cur = "";
50
- let inDouble = false;
51
- let inSingle = false;
52
- let escape = false;
53
-
54
- for (const ch of str) {
55
- if (escape) {
56
- cur += ch;
57
- escape = false;
58
- continue;
59
- }
60
- if (ch === "\\" && !inSingle) {
61
- escape = true;
62
- continue;
63
- }
64
- if (ch === '"' && !inSingle) {
65
- inDouble = !inDouble;
66
- continue;
67
- }
68
- if (ch === "'" && !inDouble) {
69
- inSingle = !inSingle;
70
- continue;
71
- }
72
- if (/\s/.test(ch) && !inDouble && !inSingle) {
73
- if (cur) {
74
- args.push(cur);
75
- cur = "";
76
- }
77
- continue;
78
- }
79
- cur += ch;
80
- }
81
- if (cur) {
82
- args.push(cur);
83
- }
84
- return args;
85
- }
86
-
87
- function runTlonCommand(binary: string, args: string[]): Promise<string> {
88
- return new Promise((resolve, reject) => {
89
- const child = spawn(binary, args, { env: process.env });
90
-
91
- let stdout = "";
92
- let stderr = "";
93
-
94
- child.stdout.on("data", (data) => {
95
- stdout += data.toString();
96
- });
97
-
98
- child.stderr.on("data", (data) => {
99
- stderr += data.toString();
100
- });
101
-
102
- child.on("error", (err) => {
103
- reject(new Error(`Failed to run tlon: ${err.message}`));
104
- });
105
-
106
- child.on("close", (code) => {
107
- if (code !== 0) {
108
- reject(new Error(stderr || `tlon exited with code ${code}`));
109
- return;
110
- }
111
- resolve(stdout);
112
- });
113
- });
114
- }
115
-
116
- export default defineBundledChannelEntry({
117
- id: "tlon",
118
- name: "Tlon",
119
- description: "Tlon/Urbit channel plugin",
120
- importMetaUrl: import.meta.url,
121
- plugin: {
122
- specifier: "./channel-plugin-api.js",
123
- exportName: "tlonPlugin",
124
- },
125
- runtime: {
126
- specifier: "./api.js",
127
- exportName: "setTlonRuntime",
128
- },
129
- registerFull(api) {
130
- api.registerTool({
131
- name: "tlon",
132
- label: "Tlon CLI",
133
- description:
134
- "Tlon/Urbit API operations: activity, channels, contacts, groups, messages, dms, posts, notebook, settings. " +
135
- "Examples: 'activity mentions --limit 10', 'channels groups', 'contacts self', 'groups list'",
136
- parameters: {
137
- type: "object",
138
- properties: {
139
- command: {
140
- type: "string",
141
- description:
142
- "The tlon command and arguments. " +
143
- "Examples: 'activity mentions --limit 10', 'contacts get ~sampel-palnet', 'groups list'",
144
- },
145
- },
146
- required: ["command"],
147
- },
148
- async execute(_id: string, params: { command: string }) {
149
- try {
150
- const args = shellSplit(params.command);
151
- const subcommand = args[0];
152
- if (!ALLOWED_TLON_COMMANDS.has(subcommand)) {
153
- return {
154
- content: [
155
- {
156
- type: "text" as const,
157
- text: `Error: Unknown tlon subcommand '${subcommand}'. Allowed: ${[...ALLOWED_TLON_COMMANDS].join(", ")}`,
158
- },
159
- ],
160
- details: { error: true },
161
- };
162
- }
163
-
164
- const output = await runTlonCommand(findTlonBinary(), args);
165
- return {
166
- content: [{ type: "text" as const, text: output }],
167
- details: undefined,
168
- };
169
- } catch (error: unknown) {
170
- return {
171
- content: [
172
- {
173
- type: "text" as const,
174
- text: `Error: ${formatErrorMessage(error)}`,
175
- },
176
- ],
177
- details: { error: true },
178
- };
179
- }
180
- },
181
- });
182
- },
183
- });
package/runtime-api.ts DELETED
@@ -1,17 +0,0 @@
1
- // Private runtime barrel for the bundled Tlon extension.
2
- // Keep this barrel thin and aligned with the local extension surface.
3
-
4
- export type { ReplyPayload } from "openclaw/plugin-sdk/reply-runtime";
5
- export type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
6
- export type { RuntimeEnv } from "openclaw/plugin-sdk/runtime";
7
- export { createDedupeCache } from "openclaw/plugin-sdk/core";
8
- export { createLoggerBackedRuntime } from "./src/logger-runtime.js";
9
- export {
10
- fetchWithSsrFGuard,
11
- isBlockedHostnameOrIp,
12
- ssrfPolicyFromAllowPrivateNetwork,
13
- ssrfPolicyFromDangerouslyAllowPrivateNetwork,
14
- type LookupFn,
15
- type SsrFPolicy,
16
- } from "openclaw/plugin-sdk/ssrf-runtime";
17
- export { SsrFBlockedError } from "openclaw/plugin-sdk/ssrf-runtime";
package/setup-api.ts DELETED
@@ -1,2 +0,0 @@
1
- export { tlonSetupAdapter } from "./src/setup-core.js";
2
- export { tlonSetupWizard } from "./src/setup-surface.js";
package/setup-entry.ts DELETED
@@ -1,9 +0,0 @@
1
- import { defineBundledChannelSetupEntry } from "openclaw/plugin-sdk/channel-entry-contract";
2
-
3
- export default defineBundledChannelSetupEntry({
4
- importMetaUrl: import.meta.url,
5
- plugin: {
6
- specifier: "./api.js",
7
- exportName: "tlonPlugin",
8
- },
9
- });
@@ -1,31 +0,0 @@
1
- export type TlonAccountFieldsInput = {
2
- ship?: string;
3
- url?: string;
4
- code?: string;
5
- dangerouslyAllowPrivateNetwork?: boolean;
6
- groupChannels?: string[];
7
- dmAllowlist?: string[];
8
- autoDiscoverChannels?: boolean;
9
- ownerShip?: string;
10
- };
11
-
12
- export function buildTlonAccountFields(input: TlonAccountFieldsInput) {
13
- return {
14
- ...(input.ship ? { ship: input.ship } : {}),
15
- ...(input.url ? { url: input.url } : {}),
16
- ...(input.code ? { code: input.code } : {}),
17
- ...(typeof input.dangerouslyAllowPrivateNetwork === "boolean"
18
- ? {
19
- network: {
20
- dangerouslyAllowPrivateNetwork: input.dangerouslyAllowPrivateNetwork,
21
- },
22
- }
23
- : {}),
24
- ...(input.groupChannels ? { groupChannels: input.groupChannels } : {}),
25
- ...(input.dmAllowlist ? { dmAllowlist: input.dmAllowlist } : {}),
26
- ...(typeof input.autoDiscoverChannels === "boolean"
27
- ? { autoDiscoverChannels: input.autoDiscoverChannels }
28
- : {}),
29
- ...(input.ownerShip ? { ownerShip: input.ownerShip } : {}),
30
- };
31
- }
@@ -1,248 +0,0 @@
1
- import crypto from "node:crypto";
2
- import type { ChannelAccountSnapshot } from "openclaw/plugin-sdk/channel-contract";
3
- import type { ChannelOutboundAdapter } from "openclaw/plugin-sdk/channel-send-result";
4
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
5
- import type { ChannelPlugin } from "openclaw/plugin-sdk/core";
6
- import { monitorTlonProvider } from "./monitor/index.js";
7
- import { tlonSetupWizard } from "./setup-surface.js";
8
- import {
9
- formatTargetHint,
10
- normalizeShip,
11
- parseTlonTarget,
12
- resolveTlonOutboundTarget,
13
- } from "./targets.js";
14
- import { configureClient } from "./tlon-api.js";
15
- import { resolveTlonAccount } from "./types.js";
16
- import { authenticate } from "./urbit/auth.js";
17
- import { ssrfPolicyFromDangerouslyAllowPrivateNetwork } from "./urbit/context.js";
18
- import { urbitFetch } from "./urbit/fetch.js";
19
- import {
20
- buildMediaStory,
21
- sendDm,
22
- sendDmWithStory,
23
- sendGroupMessage,
24
- sendGroupMessageWithStory,
25
- } from "./urbit/send.js";
26
- import { uploadImageFromUrl } from "./urbit/upload.js";
27
-
28
- type ResolvedTlonAccount = ReturnType<typeof resolveTlonAccount>;
29
- type ConfiguredTlonAccount = ResolvedTlonAccount & {
30
- ship: string;
31
- url: string;
32
- code: string;
33
- };
34
-
35
- async function createHttpPokeApi(params: {
36
- url: string;
37
- code: string;
38
- ship: string;
39
- dangerouslyAllowPrivateNetwork?: boolean;
40
- }) {
41
- const ssrfPolicy = ssrfPolicyFromDangerouslyAllowPrivateNetwork(
42
- params.dangerouslyAllowPrivateNetwork,
43
- );
44
- const cookie = await authenticate(params.url, params.code, { ssrfPolicy });
45
- const channelId = `${Math.floor(Date.now() / 1000)}-${crypto.randomUUID()}`;
46
- const channelPath = `/~/channel/${channelId}`;
47
- const shipName = params.ship.replace(/^~/, "");
48
-
49
- return {
50
- poke: async (pokeParams: { app: string; mark: string; json: unknown }) => {
51
- const pokeId = Date.now();
52
- const pokeData = {
53
- id: pokeId,
54
- action: "poke",
55
- ship: shipName,
56
- app: pokeParams.app,
57
- mark: pokeParams.mark,
58
- json: pokeParams.json,
59
- };
60
-
61
- const { response, release } = await urbitFetch({
62
- baseUrl: params.url,
63
- path: channelPath,
64
- init: {
65
- method: "PUT",
66
- headers: {
67
- "Content-Type": "application/json",
68
- Cookie: cookie.split(";")[0],
69
- },
70
- body: JSON.stringify([pokeData]),
71
- },
72
- ssrfPolicy,
73
- auditContext: "tlon-poke",
74
- });
75
-
76
- try {
77
- if (!response.ok && response.status !== 204) {
78
- const errorText = await response.text();
79
- throw new Error(`Poke failed: ${response.status} - ${errorText}`);
80
- }
81
-
82
- return pokeId;
83
- } finally {
84
- await release();
85
- }
86
- },
87
- delete: async () => {
88
- // No-op for HTTP-only client
89
- },
90
- };
91
- }
92
-
93
- function resolveOutboundContext(params: {
94
- cfg: OpenClawConfig;
95
- accountId?: string | null;
96
- to: string;
97
- }) {
98
- const account = resolveTlonAccount(params.cfg, params.accountId ?? undefined);
99
- if (!account.configured || !account.ship || !account.url || !account.code) {
100
- throw new Error("Tlon account not configured");
101
- }
102
-
103
- const parsed = parseTlonTarget(params.to);
104
- if (!parsed) {
105
- throw new Error(`Invalid Tlon target. Use ${formatTargetHint()}`);
106
- }
107
-
108
- return { account: account as ConfiguredTlonAccount, parsed };
109
- }
110
-
111
- function resolveReplyId(replyToId?: string | null, threadId?: string | number | null) {
112
- return (replyToId ?? threadId) ? String(replyToId ?? threadId) : undefined;
113
- }
114
-
115
- async function withHttpPokeAccountApi<T>(
116
- account: ConfiguredTlonAccount,
117
- run: (api: Awaited<ReturnType<typeof createHttpPokeApi>>) => Promise<T>,
118
- ) {
119
- const api = await createHttpPokeApi({
120
- url: account.url,
121
- ship: account.ship,
122
- code: account.code,
123
- dangerouslyAllowPrivateNetwork: account.dangerouslyAllowPrivateNetwork ?? undefined,
124
- });
125
-
126
- try {
127
- return await run(api);
128
- } finally {
129
- try {
130
- await api.delete();
131
- } catch {
132
- // ignore cleanup errors
133
- }
134
- }
135
- }
136
-
137
- export const tlonRuntimeOutbound: ChannelOutboundAdapter = {
138
- deliveryMode: "direct",
139
- textChunkLimit: 10000,
140
- resolveTarget: ({ to }) => resolveTlonOutboundTarget(to),
141
- sendText: async ({ cfg, to, text, accountId, replyToId, threadId }) => {
142
- const { account, parsed } = resolveOutboundContext({ cfg, accountId, to });
143
- return withHttpPokeAccountApi(account, async (api) => {
144
- const fromShip = normalizeShip(account.ship);
145
- if (parsed.kind === "dm") {
146
- return await sendDm({
147
- api,
148
- fromShip,
149
- toShip: parsed.ship,
150
- text,
151
- });
152
- }
153
- return await sendGroupMessage({
154
- api,
155
- fromShip,
156
- hostShip: parsed.hostShip,
157
- channelName: parsed.channelName,
158
- text,
159
- replyToId: resolveReplyId(replyToId, threadId),
160
- });
161
- });
162
- },
163
- sendMedia: async ({ cfg, to, text, mediaUrl, accountId, replyToId, threadId }) => {
164
- const { account, parsed } = resolveOutboundContext({ cfg, accountId, to });
165
-
166
- configureClient({
167
- shipUrl: account.url,
168
- shipName: account.ship.replace(/^~/, ""),
169
- verbose: false,
170
- getCode: async () => account.code,
171
- dangerouslyAllowPrivateNetwork: account.dangerouslyAllowPrivateNetwork ?? undefined,
172
- });
173
-
174
- const uploadedUrl = mediaUrl ? await uploadImageFromUrl(mediaUrl) : undefined;
175
- return withHttpPokeAccountApi(account, async (api) => {
176
- const fromShip = normalizeShip(account.ship);
177
- const story = buildMediaStory(text, uploadedUrl);
178
-
179
- if (parsed.kind === "dm") {
180
- return await sendDmWithStory({
181
- api,
182
- fromShip,
183
- toShip: parsed.ship,
184
- story,
185
- });
186
- }
187
- return await sendGroupMessageWithStory({
188
- api,
189
- fromShip,
190
- hostShip: parsed.hostShip,
191
- channelName: parsed.channelName,
192
- story,
193
- replyToId: resolveReplyId(replyToId, threadId),
194
- });
195
- });
196
- },
197
- };
198
-
199
- export async function probeTlonAccount(account: ConfiguredTlonAccount) {
200
- try {
201
- const ssrfPolicy = ssrfPolicyFromDangerouslyAllowPrivateNetwork(
202
- account.dangerouslyAllowPrivateNetwork,
203
- );
204
- const cookie = await authenticate(account.url, account.code, { ssrfPolicy });
205
- const { response, release } = await urbitFetch({
206
- baseUrl: account.url,
207
- path: "/~/name",
208
- init: {
209
- method: "GET",
210
- headers: { Cookie: cookie },
211
- },
212
- ssrfPolicy,
213
- timeoutMs: 30_000,
214
- auditContext: "tlon-probe-account",
215
- });
216
- try {
217
- if (!response.ok) {
218
- return { ok: false, error: `Name request failed: ${response.status}` };
219
- }
220
- return { ok: true };
221
- } finally {
222
- await release();
223
- }
224
- } catch (error) {
225
- return { ok: false, error: (error as { message?: string })?.message ?? String(error) };
226
- }
227
- }
228
-
229
- export async function startTlonGatewayAccount(
230
- ctx: Parameters<
231
- NonNullable<NonNullable<ChannelPlugin<ResolvedTlonAccount>["gateway"]>["startAccount"]>
232
- >[0],
233
- ) {
234
- const account = ctx.account;
235
- ctx.setStatus({
236
- accountId: account.accountId,
237
- ship: account.ship,
238
- url: account.url,
239
- } as ChannelAccountSnapshot);
240
- ctx.log?.info(`[${account.accountId}] starting Tlon provider for ${account.ship ?? "tlon"}`);
241
- return monitorTlonProvider({
242
- runtime: ctx.runtime,
243
- abortSignal: ctx.abortSignal,
244
- accountId: account.accountId,
245
- });
246
- }
247
-
248
- export { tlonSetupWizard };
package/src/channel.ts DELETED
@@ -1,173 +0,0 @@
1
- import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
2
- import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
3
- import { createHybridChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
4
- import { createChatChannelPlugin, type ChannelPlugin } from "openclaw/plugin-sdk/channel-core";
5
- import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
6
- import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
7
- import {
8
- createComputedAccountStatusAdapter,
9
- createDefaultChannelRuntimeState,
10
- } from "openclaw/plugin-sdk/status-helpers";
11
- import { tlonChannelConfigSchema } from "./config-schema.js";
12
- import { tlonDoctor } from "./doctor.js";
13
- import { resolveTlonOutboundSessionRoute } from "./session-route.js";
14
- import { createTlonSetupWizardBase, tlonSetupAdapter } from "./setup-core.js";
15
- import {
16
- formatTargetHint,
17
- normalizeShip,
18
- parseTlonTarget,
19
- resolveTlonOutboundTarget,
20
- } from "./targets.js";
21
- import { listTlonAccountIds, resolveTlonAccount } from "./types.js";
22
-
23
- const TLON_CHANNEL_ID = "tlon" as const;
24
-
25
- const loadTlonChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
26
-
27
- const tlonSetupWizardProxy = createTlonSetupWizardBase({
28
- resolveConfigured: async ({ cfg, accountId }) =>
29
- await (
30
- await loadTlonChannelRuntime()
31
- ).tlonSetupWizard.status.resolveConfigured({
32
- cfg,
33
- accountId,
34
- }),
35
- resolveStatusLines: async ({ cfg, accountId, configured }) =>
36
- (await (
37
- await loadTlonChannelRuntime()
38
- ).tlonSetupWizard.status.resolveStatusLines?.({
39
- cfg,
40
- accountId,
41
- configured,
42
- })) ?? [],
43
- finalize: async (params) =>
44
- await (
45
- await loadTlonChannelRuntime()
46
- ).tlonSetupWizard.finalize!(params),
47
- }) satisfies NonNullable<ChannelPlugin["setupWizard"]>;
48
-
49
- const tlonConfigAdapter = createHybridChannelConfigAdapter({
50
- sectionKey: TLON_CHANNEL_ID,
51
- listAccountIds: listTlonAccountIds,
52
- resolveAccount: resolveTlonAccount,
53
- defaultAccountId: () => DEFAULT_ACCOUNT_ID,
54
- clearBaseFields: ["ship", "code", "url", "name"],
55
- preserveSectionOnDefaultDelete: true,
56
- resolveAllowFrom: (account) => account.dmAllowlist,
57
- formatAllowFrom: (allowFrom) =>
58
- allowFrom.map((entry) => normalizeShip(String(entry))).filter(Boolean),
59
- });
60
-
61
- export const tlonPlugin = createChatChannelPlugin({
62
- base: {
63
- id: TLON_CHANNEL_ID,
64
- meta: {
65
- id: TLON_CHANNEL_ID,
66
- label: "Tlon",
67
- selectionLabel: "Tlon (Urbit)",
68
- docsPath: "/channels/tlon",
69
- docsLabel: "tlon",
70
- blurb: "Decentralized messaging on Urbit",
71
- aliases: ["urbit"],
72
- order: 90,
73
- },
74
- capabilities: {
75
- chatTypes: ["direct", "group", "thread"],
76
- media: true,
77
- reply: true,
78
- threads: true,
79
- },
80
- setup: tlonSetupAdapter,
81
- setupWizard: tlonSetupWizardProxy,
82
- reload: { configPrefixes: ["channels.tlon"] },
83
- configSchema: tlonChannelConfigSchema,
84
- config: {
85
- ...tlonConfigAdapter,
86
- isConfigured: (account) => account.configured,
87
- describeAccount: (account) =>
88
- describeAccountSnapshot({
89
- account,
90
- configured: account.configured,
91
- extra: {
92
- ship: account.ship,
93
- url: account.url,
94
- },
95
- }),
96
- },
97
- doctor: tlonDoctor,
98
- messaging: {
99
- targetPrefixes: ["tlon"],
100
- normalizeTarget: (target) => {
101
- const parsed = parseTlonTarget(target);
102
- if (!parsed) {
103
- return target.trim();
104
- }
105
- if (parsed.kind === "dm") {
106
- return parsed.ship;
107
- }
108
- return parsed.nest;
109
- },
110
- targetResolver: {
111
- looksLikeId: (target) => Boolean(parseTlonTarget(target)),
112
- hint: formatTargetHint(),
113
- },
114
- resolveOutboundSessionRoute: (params) => resolveTlonOutboundSessionRoute(params),
115
- },
116
- status: createComputedAccountStatusAdapter<ReturnType<typeof resolveTlonAccount>>({
117
- defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
118
- collectStatusIssues: (accounts) => {
119
- return accounts.flatMap((account) => {
120
- if (!account.configured) {
121
- return [
122
- {
123
- channel: TLON_CHANNEL_ID,
124
- accountId: account.accountId,
125
- kind: "config",
126
- message: "Account not configured (missing ship, code, or url)",
127
- },
128
- ];
129
- }
130
- return [];
131
- });
132
- },
133
- buildChannelSummary: ({ snapshot }) => {
134
- const s = snapshot as { configured?: boolean; ship?: string; url?: string };
135
- return {
136
- configured: s.configured ?? false,
137
- ship: s.ship ?? null,
138
- url: s.url ?? null,
139
- };
140
- },
141
- probeAccount: async ({ account }) => {
142
- if (!account.configured || !account.ship || !account.url || !account.code) {
143
- return { ok: false, error: "Not configured" };
144
- }
145
- return await (await loadTlonChannelRuntime()).probeTlonAccount(account as never);
146
- },
147
- resolveAccountSnapshot: ({ account }) => ({
148
- accountId: account.accountId,
149
- name: account.name ?? undefined,
150
- enabled: account.enabled,
151
- configured: account.configured,
152
- extra: {
153
- ship: account.ship,
154
- url: account.url,
155
- },
156
- }),
157
- }),
158
- gateway: {
159
- startAccount: async (ctx) =>
160
- await (await loadTlonChannelRuntime()).startTlonGatewayAccount(ctx),
161
- },
162
- },
163
- outbound: {
164
- deliveryMode: "direct",
165
- textChunkLimit: 10000,
166
- resolveTarget: ({ to }) => resolveTlonOutboundTarget(to),
167
- ...createRuntimeOutboundDelegates({
168
- getRuntime: loadTlonChannelRuntime,
169
- sendText: { resolve: (runtime) => runtime.tlonRuntimeOutbound.sendText },
170
- sendMedia: { resolve: (runtime) => runtime.tlonRuntimeOutbound.sendMedia },
171
- }),
172
- },
173
- });