@openclaw/tlon 2026.2.21 → 2026.5.1-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 (63) hide show
  1. package/api.ts +16 -0
  2. package/channel-plugin-api.ts +1 -0
  3. package/doctor-contract-api.ts +1 -0
  4. package/index.ts +177 -11
  5. package/openclaw.plugin.json +189 -1
  6. package/package.json +57 -4
  7. package/runtime-api.ts +17 -0
  8. package/setup-api.ts +2 -0
  9. package/setup-entry.ts +9 -0
  10. package/src/account-fields.ts +9 -3
  11. package/src/channel.runtime.ts +248 -0
  12. package/src/channel.ts +152 -364
  13. package/src/config-schema.ts +22 -16
  14. package/src/core.test.ts +278 -0
  15. package/src/doctor-contract.ts +9 -0
  16. package/src/doctor.test.ts +40 -0
  17. package/src/doctor.ts +10 -0
  18. package/src/logger-runtime.ts +1 -0
  19. package/src/monitor/approval-runtime.ts +363 -0
  20. package/src/monitor/approval.test.ts +33 -0
  21. package/src/monitor/approval.ts +286 -0
  22. package/src/monitor/authorization.ts +30 -0
  23. package/src/monitor/cites.ts +54 -0
  24. package/src/monitor/discovery.ts +44 -54
  25. package/src/monitor/history.ts +155 -21
  26. package/src/monitor/index.ts +1290 -369
  27. package/src/monitor/media.test.ts +91 -0
  28. package/src/monitor/media.ts +172 -0
  29. package/src/monitor/processed-messages.test.ts +36 -1
  30. package/src/monitor/processed-messages.ts +62 -19
  31. package/src/monitor/settings-helpers.test.ts +113 -0
  32. package/src/monitor/settings-helpers.ts +158 -0
  33. package/src/monitor/utils.ts +311 -45
  34. package/src/runtime.ts +8 -13
  35. package/src/security.test.ts +622 -0
  36. package/src/session-route.ts +40 -0
  37. package/src/settings.ts +391 -0
  38. package/src/setup-core.ts +228 -0
  39. package/src/setup-surface.ts +103 -0
  40. package/src/targets.ts +29 -16
  41. package/src/tlon-api.test.ts +589 -0
  42. package/src/tlon-api.ts +402 -0
  43. package/src/types.ts +106 -45
  44. package/src/urbit/auth.ssrf.test.ts +3 -2
  45. package/src/urbit/auth.ts +2 -2
  46. package/src/urbit/base-url.test.ts +18 -11
  47. package/src/urbit/base-url.ts +9 -5
  48. package/src/urbit/channel-ops.ts +40 -59
  49. package/src/urbit/context.ts +13 -10
  50. package/src/urbit/errors.ts +2 -2
  51. package/src/urbit/fetch.ts +6 -3
  52. package/src/urbit/foreigns.ts +49 -0
  53. package/src/urbit/send.ts +59 -2
  54. package/src/urbit/sse-client.test.ts +184 -25
  55. package/src/urbit/sse-client.ts +123 -69
  56. package/src/urbit/story.ts +332 -0
  57. package/src/urbit/upload.test.ts +154 -0
  58. package/src/urbit/upload.ts +60 -0
  59. package/test-api.ts +1 -0
  60. package/tsconfig.json +16 -0
  61. package/src/config-schema.test.ts +0 -31
  62. package/src/onboarding.ts +0 -229
  63. package/src/urbit/channel-client.ts +0 -157
@@ -0,0 +1,103 @@
1
+ import {
2
+ applyTlonSetupConfig,
3
+ createTlonSetupWizardBase,
4
+ resolveTlonSetupConfigured,
5
+ resolveTlonSetupStatusLines,
6
+ } from "./setup-core.js";
7
+ import { normalizeShip } from "./targets.js";
8
+ import { resolveTlonAccount, type TlonResolvedAccount } from "./types.js";
9
+ import { isBlockedUrbitHostname, validateUrbitBaseUrl } from "./urbit/base-url.js";
10
+
11
+ const _channel = "tlon" as const;
12
+
13
+ function _isConfigured(account: TlonResolvedAccount): boolean {
14
+ return Boolean(account.ship && account.url && account.code);
15
+ }
16
+
17
+ function parseList(value: string): string[] {
18
+ return value
19
+ .split(/[\n,;]+/g)
20
+ .map((entry) => entry.trim())
21
+ .filter(Boolean);
22
+ }
23
+
24
+ export const tlonSetupWizard = createTlonSetupWizardBase({
25
+ resolveConfigured: async ({ cfg, accountId }) => await resolveTlonSetupConfigured(cfg, accountId),
26
+ resolveStatusLines: async ({ cfg, accountId }) =>
27
+ await resolveTlonSetupStatusLines(cfg, accountId),
28
+ finalize: async ({ cfg, accountId, prompter }) => {
29
+ let next = cfg;
30
+ const resolved = resolveTlonAccount(next, accountId);
31
+ const validatedUrl = validateUrbitBaseUrl(resolved.url ?? "");
32
+ if (!validatedUrl.ok) {
33
+ throw new Error(`Invalid URL: ${validatedUrl.error}`);
34
+ }
35
+
36
+ let dangerouslyAllowPrivateNetwork = resolved.dangerouslyAllowPrivateNetwork ?? false;
37
+ if (isBlockedUrbitHostname(validatedUrl.hostname)) {
38
+ dangerouslyAllowPrivateNetwork = await prompter.confirm({
39
+ message:
40
+ "Ship URL looks like a private/internal host. Allow private network access? (SSRF risk)",
41
+ initialValue: dangerouslyAllowPrivateNetwork,
42
+ });
43
+ if (!dangerouslyAllowPrivateNetwork) {
44
+ throw new Error("Refusing private/internal ship URL without explicit network opt-in");
45
+ }
46
+ }
47
+ next = applyTlonSetupConfig({
48
+ cfg: next,
49
+ accountId,
50
+ input: { dangerouslyAllowPrivateNetwork },
51
+ });
52
+
53
+ const currentGroups = resolved.groupChannels;
54
+ const wantsGroupChannels = await prompter.confirm({
55
+ message: "Add group channels manually? (optional)",
56
+ initialValue: currentGroups.length > 0,
57
+ });
58
+ if (wantsGroupChannels) {
59
+ const entry = await prompter.text({
60
+ message: "Group channels (comma-separated)",
61
+ placeholder: "chat/~host-ship/general, chat/~host-ship/support",
62
+ initialValue: currentGroups.join(", ") || undefined,
63
+ });
64
+ next = applyTlonSetupConfig({
65
+ cfg: next,
66
+ accountId,
67
+ input: { groupChannels: parseList(entry ?? "") },
68
+ });
69
+ }
70
+
71
+ const currentAllowlist = resolved.dmAllowlist;
72
+ const wantsAllowlist = await prompter.confirm({
73
+ message: "Restrict DMs with an allowlist?",
74
+ initialValue: currentAllowlist.length > 0,
75
+ });
76
+ if (wantsAllowlist) {
77
+ const entry = await prompter.text({
78
+ message: "DM allowlist (comma-separated ship names)",
79
+ placeholder: "~zod, ~nec",
80
+ initialValue: currentAllowlist.join(", ") || undefined,
81
+ });
82
+ next = applyTlonSetupConfig({
83
+ cfg: next,
84
+ accountId,
85
+ input: {
86
+ dmAllowlist: parseList(entry ?? "").map((ship) => normalizeShip(ship)),
87
+ },
88
+ });
89
+ }
90
+
91
+ const autoDiscoverChannels = await prompter.confirm({
92
+ message: "Enable auto-discovery of group channels?",
93
+ initialValue: resolved.autoDiscoverChannels ?? true,
94
+ });
95
+ next = applyTlonSetupConfig({
96
+ cfg: next,
97
+ accountId,
98
+ input: { autoDiscoverChannels },
99
+ });
100
+
101
+ return { cfg: next };
102
+ },
103
+ });
package/src/targets.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type TlonTarget =
2
- | { kind: "direct"; ship: string }
1
+ type TlonTarget =
2
+ | { kind: "dm"; ship: string }
3
3
  | { kind: "group"; nest: string; hostShip: string; channelName: string };
4
4
 
5
5
  const SHIP_RE = /^~?[a-z-]+$/i;
@@ -23,6 +23,15 @@ export function parseChannelNest(raw: string): { hostShip: string; channelName:
23
23
  return { hostShip, channelName };
24
24
  }
25
25
 
26
+ function makeGroupTarget(parsed: { hostShip: string; channelName: string }): TlonTarget {
27
+ return {
28
+ kind: "group",
29
+ nest: `chat/${parsed.hostShip}/${parsed.channelName}`,
30
+ hostShip: parsed.hostShip,
31
+ channelName: parsed.channelName,
32
+ };
33
+ }
34
+
26
35
  export function parseTlonTarget(raw?: string | null): TlonTarget | null {
27
36
  const trimmed = raw?.trim();
28
37
  if (!trimmed) {
@@ -32,7 +41,7 @@ export function parseTlonTarget(raw?: string | null): TlonTarget | null {
32
41
 
33
42
  const dmPrefix = withoutPrefix.match(/^dm[/:](.+)$/i);
34
43
  if (dmPrefix) {
35
- return { kind: "direct", ship: normalizeShip(dmPrefix[1]) };
44
+ return { kind: "dm", ship: normalizeShip(dmPrefix[1]) };
36
45
  }
37
46
 
38
47
  const groupPrefix = withoutPrefix.match(/^(group|room)[/:](.+)$/i);
@@ -43,12 +52,7 @@ export function parseTlonTarget(raw?: string | null): TlonTarget | null {
43
52
  if (!parsed) {
44
53
  return null;
45
54
  }
46
- return {
47
- kind: "group",
48
- nest: `chat/${parsed.hostShip}/${parsed.channelName}`,
49
- hostShip: parsed.hostShip,
50
- channelName: parsed.channelName,
51
- };
55
+ return makeGroupTarget(parsed);
52
56
  }
53
57
  const parts = groupTarget.split("/");
54
58
  if (parts.length === 2) {
@@ -69,21 +73,30 @@ export function parseTlonTarget(raw?: string | null): TlonTarget | null {
69
73
  if (!parsed) {
70
74
  return null;
71
75
  }
72
- return {
73
- kind: "group",
74
- nest: `chat/${parsed.hostShip}/${parsed.channelName}`,
75
- hostShip: parsed.hostShip,
76
- channelName: parsed.channelName,
77
- };
76
+ return makeGroupTarget(parsed);
78
77
  }
79
78
 
80
79
  if (SHIP_RE.test(withoutPrefix)) {
81
- return { kind: "direct", ship: normalizeShip(withoutPrefix) };
80
+ return { kind: "dm", ship: normalizeShip(withoutPrefix) };
82
81
  }
83
82
 
84
83
  return null;
85
84
  }
86
85
 
86
+ export function resolveTlonOutboundTarget(to?: string | null) {
87
+ const parsed = parseTlonTarget(to ?? "");
88
+ if (!parsed) {
89
+ return {
90
+ ok: false as const,
91
+ error: new Error(`Invalid Tlon target. Use ${formatTargetHint()}`),
92
+ };
93
+ }
94
+ if (parsed.kind === "dm") {
95
+ return { ok: true as const, to: parsed.ship };
96
+ }
97
+ return { ok: true as const, to: parsed.nest };
98
+ }
99
+
87
100
  export function formatTargetHint(): string {
88
101
  return "dm/~sampel-palnet | ~sampel-palnet | chat/~host-ship/channel | group:~host-ship/channel";
89
102
  }