@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
@@ -1,61 +0,0 @@
1
- import { isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
2
-
3
- type UrbitBaseUrlValidation =
4
- | { ok: true; baseUrl: string; hostname: string }
5
- | { ok: false; error: string };
6
-
7
- function hasScheme(value: string): boolean {
8
- return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(value);
9
- }
10
-
11
- export function normalizeUrbitHostname(hostname: string | undefined): string {
12
- return (hostname ?? "").trim().toLowerCase().replace(/\.$/, "");
13
- }
14
-
15
- export function validateUrbitBaseUrl(raw: string): UrbitBaseUrlValidation {
16
- const trimmed = raw.trim();
17
- if (!trimmed) {
18
- return { ok: false, error: "Required" };
19
- }
20
-
21
- const candidate = hasScheme(trimmed) ? trimmed : `https://${trimmed}`;
22
-
23
- let parsed: URL;
24
- try {
25
- parsed = new URL(candidate);
26
- } catch {
27
- return { ok: false, error: "Invalid URL" };
28
- }
29
-
30
- if (!["http:", "https:"].includes(parsed.protocol)) {
31
- return { ok: false, error: "URL must use http:// or https://" };
32
- }
33
-
34
- if (parsed.username || parsed.password) {
35
- return { ok: false, error: "URL must not include credentials" };
36
- }
37
-
38
- const hostname = normalizeUrbitHostname(parsed.hostname);
39
- if (!hostname) {
40
- return { ok: false, error: "Invalid hostname" };
41
- }
42
-
43
- // Normalize to origin so callers can't smuggle paths/query fragments into the base URL,
44
- // and strip a trailing dot from the hostname (DNS root label).
45
- const isIpv6 = hostname.includes(":");
46
- const host = parsed.port
47
- ? `${isIpv6 ? `[${hostname}]` : hostname}:${parsed.port}`
48
- : isIpv6
49
- ? `[${hostname}]`
50
- : hostname;
51
-
52
- return { ok: true, baseUrl: `${parsed.protocol}//${host}`, hostname };
53
- }
54
-
55
- export function isBlockedUrbitHostname(hostname: string): boolean {
56
- const normalized = normalizeUrbitHostname(hostname);
57
- if (!normalized) {
58
- return false;
59
- }
60
- return isBlockedHostnameOrIp(normalized);
61
- }
@@ -1,145 +0,0 @@
1
- import type { LookupFn, SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
2
- import { UrbitHttpError } from "./errors.js";
3
- import { urbitFetch } from "./fetch.js";
4
-
5
- type UrbitChannelDeps = {
6
- baseUrl: string;
7
- cookie: string;
8
- ship: string;
9
- channelId: string;
10
- ssrfPolicy?: SsrFPolicy;
11
- lookupFn?: LookupFn;
12
- fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
13
- };
14
-
15
- async function putUrbitChannel(
16
- deps: UrbitChannelDeps,
17
- params: { body: unknown; auditContext: string },
18
- ) {
19
- return await urbitFetch({
20
- baseUrl: deps.baseUrl,
21
- path: `/~/channel/${deps.channelId}`,
22
- init: {
23
- method: "PUT",
24
- headers: {
25
- "Content-Type": "application/json",
26
- Cookie: deps.cookie,
27
- },
28
- body: JSON.stringify(params.body),
29
- },
30
- ssrfPolicy: deps.ssrfPolicy,
31
- lookupFn: deps.lookupFn,
32
- fetchImpl: deps.fetchImpl,
33
- timeoutMs: 30_000,
34
- auditContext: params.auditContext,
35
- });
36
- }
37
-
38
- export async function pokeUrbitChannel(
39
- deps: UrbitChannelDeps,
40
- params: { app: string; mark: string; json: unknown; auditContext: string },
41
- ): Promise<number> {
42
- const pokeId = Date.now();
43
- const pokeData = {
44
- id: pokeId,
45
- action: "poke",
46
- ship: deps.ship,
47
- app: params.app,
48
- mark: params.mark,
49
- json: params.json,
50
- };
51
-
52
- const { response, release } = await putUrbitChannel(deps, {
53
- body: [pokeData],
54
- auditContext: params.auditContext,
55
- });
56
-
57
- try {
58
- if (!response.ok && response.status !== 204) {
59
- const errorText = await response.text().catch(() => "");
60
- throw new Error(`Poke failed: ${response.status}${errorText ? ` - ${errorText}` : ""}`);
61
- }
62
- return pokeId;
63
- } finally {
64
- await release();
65
- }
66
- }
67
-
68
- export async function scryUrbitPath(
69
- deps: Pick<UrbitChannelDeps, "baseUrl" | "cookie" | "ssrfPolicy" | "lookupFn" | "fetchImpl">,
70
- params: { path: string; auditContext: string },
71
- ): Promise<unknown> {
72
- const scryPath = `/~/scry${params.path}`;
73
- const { response, release } = await urbitFetch({
74
- baseUrl: deps.baseUrl,
75
- path: scryPath,
76
- init: {
77
- method: "GET",
78
- headers: { Cookie: deps.cookie },
79
- },
80
- ssrfPolicy: deps.ssrfPolicy,
81
- lookupFn: deps.lookupFn,
82
- fetchImpl: deps.fetchImpl,
83
- timeoutMs: 30_000,
84
- auditContext: params.auditContext,
85
- });
86
-
87
- try {
88
- if (!response.ok) {
89
- throw new Error(`Scry failed: ${response.status} for path ${params.path}`);
90
- }
91
- return await response.json();
92
- } finally {
93
- await release();
94
- }
95
- }
96
-
97
- async function createUrbitChannel(
98
- deps: UrbitChannelDeps,
99
- params: { body: unknown; auditContext: string },
100
- ): Promise<void> {
101
- const { response, release } = await putUrbitChannel(deps, params);
102
-
103
- try {
104
- if (!response.ok && response.status !== 204) {
105
- throw new UrbitHttpError({ operation: "Channel creation", status: response.status });
106
- }
107
- } finally {
108
- await release();
109
- }
110
- }
111
-
112
- async function wakeUrbitChannel(deps: UrbitChannelDeps): Promise<void> {
113
- const { response, release } = await putUrbitChannel(deps, {
114
- body: [
115
- {
116
- id: Date.now(),
117
- action: "poke",
118
- ship: deps.ship,
119
- app: "hood",
120
- mark: "helm-hi",
121
- json: "Opening API channel",
122
- },
123
- ],
124
- auditContext: "tlon-urbit-channel-wake",
125
- });
126
-
127
- try {
128
- if (!response.ok && response.status !== 204) {
129
- throw new UrbitHttpError({ operation: "Channel activation", status: response.status });
130
- }
131
- } finally {
132
- await release();
133
- }
134
- }
135
-
136
- export async function ensureUrbitChannelOpen(
137
- deps: UrbitChannelDeps,
138
- params: { createBody: unknown; createAuditContext: string },
139
- ): Promise<void> {
140
- await createUrbitChannel(deps, {
141
- body: params.createBody,
142
- auditContext: params.createAuditContext,
143
- });
144
- await wakeUrbitChannel(deps);
145
- }
@@ -1,50 +0,0 @@
1
- export { ssrfPolicyFromDangerouslyAllowPrivateNetwork } from "openclaw/plugin-sdk/ssrf-runtime";
2
- import { normalizeUrbitHostname, validateUrbitBaseUrl } from "./base-url.js";
3
- import { UrbitUrlError } from "./errors.js";
4
-
5
- type UrbitContext = {
6
- baseUrl: string;
7
- hostname: string;
8
- ship: string;
9
- };
10
-
11
- function resolveShipFromHostname(hostname: string): string {
12
- const trimmed = normalizeUrbitHostname(hostname);
13
- if (!trimmed) {
14
- return "";
15
- }
16
- if (trimmed.includes(".")) {
17
- return trimmed.split(".")[0] ?? trimmed;
18
- }
19
- return trimmed;
20
- }
21
-
22
- function normalizeUrbitShip(ship: string | undefined, hostname: string): string {
23
- const raw = ship?.replace(/^~/, "") ?? resolveShipFromHostname(hostname);
24
- return raw.trim();
25
- }
26
-
27
- export function normalizeUrbitCookie(cookie: string): string {
28
- return cookie.split(";")[0] ?? cookie;
29
- }
30
-
31
- export function getUrbitContext(url: string, ship?: string): UrbitContext {
32
- const validated = validateUrbitBaseUrl(url);
33
- if (!validated.ok) {
34
- throw new UrbitUrlError(validated.error);
35
- }
36
- return {
37
- baseUrl: validated.baseUrl,
38
- hostname: validated.hostname,
39
- ship: normalizeUrbitShip(ship, validated.hostname),
40
- };
41
- }
42
-
43
- /**
44
- * Get the default SSRF policy for image uploads.
45
- * Uses a restrictive policy that blocks private networks by default.
46
- */
47
- export function getDefaultSsrFPolicy(): undefined {
48
- // Default: block private networks for image uploads (safer default)
49
- return undefined;
50
- }
@@ -1,51 +0,0 @@
1
- type UrbitErrorCode =
2
- | "invalid_url"
3
- | "http_error"
4
- | "auth_failed"
5
- | "missing_cookie"
6
- | "channel_not_open";
7
-
8
- class UrbitError extends Error {
9
- readonly code: UrbitErrorCode;
10
-
11
- constructor(code: UrbitErrorCode, message: string, options?: { cause?: unknown }) {
12
- super(message, options);
13
- this.name = "UrbitError";
14
- this.code = code;
15
- }
16
- }
17
-
18
- export class UrbitUrlError extends UrbitError {
19
- constructor(message: string, options?: { cause?: unknown }) {
20
- super("invalid_url", message, options);
21
- this.name = "UrbitUrlError";
22
- }
23
- }
24
-
25
- export class UrbitHttpError extends UrbitError {
26
- readonly status: number;
27
- readonly operation: string;
28
- readonly bodyText?: string;
29
-
30
- constructor(params: { operation: string; status: number; bodyText?: string; cause?: unknown }) {
31
- const suffix = params.bodyText ? ` - ${params.bodyText}` : "";
32
- super("http_error", `${params.operation} failed: ${params.status}${suffix}`, {
33
- cause: params.cause,
34
- });
35
- this.name = "UrbitHttpError";
36
- this.status = params.status;
37
- this.operation = params.operation;
38
- this.bodyText = params.bodyText;
39
- }
40
- }
41
-
42
- export class UrbitAuthError extends UrbitError {
43
- constructor(
44
- code: "auth_failed" | "missing_cookie",
45
- message: string,
46
- options?: { cause?: unknown },
47
- ) {
48
- super(code, message, options);
49
- this.name = "UrbitAuthError";
50
- }
51
- }
@@ -1,42 +0,0 @@
1
- import {
2
- fetchWithSsrFGuard,
3
- type LookupFn,
4
- type SsrFPolicy,
5
- } from "openclaw/plugin-sdk/ssrf-runtime";
6
- import { validateUrbitBaseUrl } from "./base-url.js";
7
- import { UrbitUrlError } from "./errors.js";
8
-
9
- type UrbitFetchOptions = {
10
- baseUrl: string;
11
- path: string;
12
- init?: RequestInit;
13
- ssrfPolicy?: SsrFPolicy;
14
- lookupFn?: LookupFn;
15
- fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
16
- timeoutMs?: number;
17
- maxRedirects?: number;
18
- signal?: AbortSignal;
19
- auditContext?: string;
20
- pinDns?: boolean;
21
- };
22
-
23
- export async function urbitFetch(params: UrbitFetchOptions) {
24
- const validated = validateUrbitBaseUrl(params.baseUrl);
25
- if (!validated.ok) {
26
- throw new UrbitUrlError(validated.error);
27
- }
28
-
29
- const url = new URL(params.path, validated.baseUrl).toString();
30
- return await fetchWithSsrFGuard({
31
- url,
32
- fetchImpl: params.fetchImpl,
33
- init: params.init,
34
- timeoutMs: params.timeoutMs,
35
- maxRedirects: params.maxRedirects,
36
- signal: params.signal,
37
- policy: params.ssrfPolicy,
38
- lookupFn: params.lookupFn,
39
- auditContext: params.auditContext,
40
- pinDns: params.pinDns,
41
- });
42
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Types for Urbit groups foreigns (group invites)
3
- * Based on packages/shared/src/urbit/groups.ts from homestead
4
- */
5
-
6
- interface GroupPreviewV7 {
7
- meta: {
8
- title: string;
9
- description: string;
10
- image: string;
11
- cover: string;
12
- };
13
- "channel-count": number;
14
- "member-count": number;
15
- admissions: {
16
- privacy: "public" | "private" | "secret";
17
- };
18
- }
19
-
20
- interface ForeignInvite {
21
- flag: string; // group flag e.g. "~host/group-name"
22
- time: number; // timestamp
23
- from: string; // ship that sent invite
24
- token: string | null;
25
- note: string | null;
26
- preview: GroupPreviewV7;
27
- valid: boolean; // tracks if invite has been revoked
28
- }
29
-
30
- type Lookup = "preview" | "done" | "error";
31
- type Progress = "ask" | "join" | "watch" | "done" | "error";
32
-
33
- interface Foreign {
34
- invites: ForeignInvite[];
35
- lookup: Lookup | null;
36
- preview: GroupPreviewV7 | null;
37
- progress: Progress | null;
38
- token: string | null;
39
- }
40
-
41
- export interface Foreigns {
42
- [flag: string]: Foreign;
43
- }
44
-
45
- // DM invite structure from chat /v3 firehose
46
- export interface DmInvite {
47
- ship: string;
48
- // Additional fields may be present
49
- }
@@ -1,38 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
-
3
- vi.mock("@urbit/aura", () => ({
4
- scot: vi.fn(() => "mocked-ud"),
5
- da: {
6
- fromUnix: vi.fn(() => 123n),
7
- },
8
- }));
9
-
10
- describe("sendDm", () => {
11
- afterEach(() => {
12
- vi.restoreAllMocks();
13
- });
14
-
15
- it("uses aura v3 helpers for the DM id", async () => {
16
- const { sendDm } = await import("./send.js");
17
- const aura = await import("@urbit/aura");
18
- const scot = vi.mocked(aura.scot);
19
- const fromUnix = vi.mocked(aura.da.fromUnix);
20
-
21
- const sentAt = 1_700_000_000_000;
22
- vi.spyOn(Date, "now").mockReturnValue(sentAt);
23
-
24
- const poke = vi.fn(async () => ({}));
25
-
26
- const result = await sendDm({
27
- api: { poke },
28
- fromShip: "~zod",
29
- toShip: "~nec",
30
- text: "hi",
31
- });
32
-
33
- expect(fromUnix).toHaveBeenCalledWith(sentAt);
34
- expect(scot).toHaveBeenCalledWith("ud", 123n);
35
- expect(poke).toHaveBeenCalledTimes(1);
36
- expect(result.messageId).toBe("~zod/mocked-ud");
37
- });
38
- });
package/src/urbit/send.ts DELETED
@@ -1,176 +0,0 @@
1
- import { scot, da } from "@urbit/aura";
2
- import { markdownToStory, createImageBlock, isImageUrl, type Story } from "./story.js";
3
-
4
- export type TlonPokeApi = {
5
- poke: (params: { app: string; mark: string; json: unknown }) => Promise<unknown>;
6
- };
7
-
8
- type SendTextParams = {
9
- api: TlonPokeApi;
10
- fromShip: string;
11
- toShip: string;
12
- text: string;
13
- };
14
-
15
- type SendStoryParams = {
16
- api: TlonPokeApi;
17
- fromShip: string;
18
- toShip: string;
19
- story: Story;
20
- };
21
-
22
- export async function sendDm({ api, fromShip, toShip, text }: SendTextParams) {
23
- const story: Story = markdownToStory(text);
24
- return sendDmWithStory({ api, fromShip, toShip, story });
25
- }
26
-
27
- export async function sendDmWithStory({ api, fromShip, toShip, story }: SendStoryParams) {
28
- const sentAt = Date.now();
29
- const idUd = scot("ud", da.fromUnix(sentAt));
30
- const id = `${fromShip}/${idUd}`;
31
-
32
- const delta = {
33
- add: {
34
- memo: {
35
- content: story,
36
- author: fromShip,
37
- sent: sentAt,
38
- },
39
- kind: null,
40
- time: null,
41
- },
42
- };
43
-
44
- const action = {
45
- ship: toShip,
46
- diff: { id, delta },
47
- };
48
-
49
- await api.poke({
50
- app: "chat",
51
- mark: "chat-dm-action",
52
- json: action,
53
- });
54
-
55
- return { channel: "tlon", messageId: id };
56
- }
57
-
58
- type SendGroupParams = {
59
- api: TlonPokeApi;
60
- fromShip: string;
61
- hostShip: string;
62
- channelName: string;
63
- text: string;
64
- replyToId?: string | null;
65
- };
66
-
67
- type SendGroupStoryParams = {
68
- api: TlonPokeApi;
69
- fromShip: string;
70
- hostShip: string;
71
- channelName: string;
72
- story: Story;
73
- replyToId?: string | null;
74
- };
75
-
76
- export async function sendGroupMessage({
77
- api,
78
- fromShip,
79
- hostShip,
80
- channelName,
81
- text,
82
- replyToId,
83
- }: SendGroupParams) {
84
- const story: Story = markdownToStory(text);
85
- return sendGroupMessageWithStory({ api, fromShip, hostShip, channelName, story, replyToId });
86
- }
87
-
88
- export async function sendGroupMessageWithStory({
89
- api,
90
- fromShip,
91
- hostShip,
92
- channelName,
93
- story,
94
- replyToId,
95
- }: SendGroupStoryParams) {
96
- const sentAt = Date.now();
97
-
98
- // Format reply ID as @ud (with dots) - required for Tlon to recognize thread replies
99
- let formattedReplyId = replyToId;
100
- if (replyToId && /^\d+$/.test(replyToId)) {
101
- try {
102
- // scot('ud', n) formats a number as @ud with dots
103
- formattedReplyId = scot("ud", BigInt(replyToId));
104
- } catch {
105
- // Fall back to raw ID if formatting fails
106
- }
107
- }
108
-
109
- const action = {
110
- channel: {
111
- nest: `chat/${hostShip}/${channelName}`,
112
- action: formattedReplyId
113
- ? {
114
- // Thread reply - needs post wrapper around reply action
115
- // ReplyActionAdd takes Memo: {content, author, sent} - no kind/blob/meta
116
- post: {
117
- reply: {
118
- id: formattedReplyId,
119
- action: {
120
- add: {
121
- content: story,
122
- author: fromShip,
123
- sent: sentAt,
124
- },
125
- },
126
- },
127
- },
128
- }
129
- : {
130
- // Regular post
131
- post: {
132
- add: {
133
- content: story,
134
- author: fromShip,
135
- sent: sentAt,
136
- kind: "/chat",
137
- blob: null,
138
- meta: null,
139
- },
140
- },
141
- },
142
- },
143
- };
144
-
145
- await api.poke({
146
- app: "channels",
147
- mark: "channel-action-1",
148
- json: action,
149
- });
150
-
151
- return { channel: "tlon", messageId: `${fromShip}/${sentAt}` };
152
- }
153
-
154
- /**
155
- * Build a story with text and optional media (image)
156
- */
157
- export function buildMediaStory(text: string | undefined, mediaUrl: string | undefined): Story {
158
- const story: Story = [];
159
- const cleanText = text?.trim() ?? "";
160
- const cleanUrl = mediaUrl?.trim() ?? "";
161
-
162
- // Add text content if present
163
- if (cleanText) {
164
- story.push(...markdownToStory(cleanText));
165
- }
166
-
167
- // Add image block if URL looks like an image
168
- if (cleanUrl && isImageUrl(cleanUrl)) {
169
- story.push(createImageBlock(cleanUrl, ""));
170
- } else if (cleanUrl) {
171
- // For non-image URLs, add as a link
172
- story.push({ inline: [{ link: { href: cleanUrl, content: cleanUrl } }] });
173
- }
174
-
175
- return story.length > 0 ? story : [{ inline: [""] }];
176
- }