@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.
- package/api.ts +16 -0
- package/channel-plugin-api.ts +1 -0
- package/doctor-contract-api.ts +1 -0
- package/index.ts +177 -11
- package/openclaw.plugin.json +189 -1
- package/package.json +57 -4
- package/runtime-api.ts +17 -0
- package/setup-api.ts +2 -0
- package/setup-entry.ts +9 -0
- package/src/account-fields.ts +9 -3
- package/src/channel.runtime.ts +248 -0
- package/src/channel.ts +152 -364
- package/src/config-schema.ts +22 -16
- package/src/core.test.ts +278 -0
- package/src/doctor-contract.ts +9 -0
- package/src/doctor.test.ts +40 -0
- package/src/doctor.ts +10 -0
- package/src/logger-runtime.ts +1 -0
- package/src/monitor/approval-runtime.ts +363 -0
- package/src/monitor/approval.test.ts +33 -0
- package/src/monitor/approval.ts +286 -0
- package/src/monitor/authorization.ts +30 -0
- package/src/monitor/cites.ts +54 -0
- package/src/monitor/discovery.ts +44 -54
- package/src/monitor/history.ts +155 -21
- package/src/monitor/index.ts +1290 -369
- package/src/monitor/media.test.ts +91 -0
- package/src/monitor/media.ts +172 -0
- package/src/monitor/processed-messages.test.ts +36 -1
- package/src/monitor/processed-messages.ts +62 -19
- package/src/monitor/settings-helpers.test.ts +113 -0
- package/src/monitor/settings-helpers.ts +158 -0
- package/src/monitor/utils.ts +311 -45
- package/src/runtime.ts +8 -13
- package/src/security.test.ts +622 -0
- package/src/session-route.ts +40 -0
- package/src/settings.ts +391 -0
- package/src/setup-core.ts +228 -0
- package/src/setup-surface.ts +103 -0
- package/src/targets.ts +29 -16
- package/src/tlon-api.test.ts +589 -0
- package/src/tlon-api.ts +402 -0
- package/src/types.ts +106 -45
- package/src/urbit/auth.ssrf.test.ts +3 -2
- package/src/urbit/auth.ts +2 -2
- package/src/urbit/base-url.test.ts +18 -11
- package/src/urbit/base-url.ts +9 -5
- package/src/urbit/channel-ops.ts +40 -59
- package/src/urbit/context.ts +13 -10
- package/src/urbit/errors.ts +2 -2
- package/src/urbit/fetch.ts +6 -3
- package/src/urbit/foreigns.ts +49 -0
- package/src/urbit/send.ts +59 -2
- package/src/urbit/sse-client.test.ts +184 -25
- package/src/urbit/sse-client.ts +123 -69
- package/src/urbit/story.ts +332 -0
- package/src/urbit/upload.test.ts +154 -0
- package/src/urbit/upload.ts +60 -0
- package/test-api.ts +1 -0
- package/tsconfig.json +16 -0
- package/src/config-schema.test.ts +0 -31
- package/src/onboarding.ts +0 -229
- package/src/urbit/channel-client.ts +0 -157
package/src/monitor/history.ts
CHANGED
|
@@ -1,13 +1,51 @@
|
|
|
1
|
-
import type { RuntimeEnv } from "openclaw/plugin-sdk";
|
|
2
|
-
import { extractMessageText } from "./utils.js";
|
|
1
|
+
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime";
|
|
2
|
+
import { asRecord, extractMessageText, formatErrorMessage } from "./utils.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Format a number as @ud (with dots every 3 digits from the right)
|
|
6
|
+
* e.g., 170141184507799509469114119040828178432 -> 170.141.184.507.799.509.469.114.119.040.828.178.432
|
|
7
|
+
*/
|
|
8
|
+
function formatUd(id: string | number): string {
|
|
9
|
+
const str = String(id).replace(/\./g, ""); // Remove any existing dots
|
|
10
|
+
const reversed = str.split("").toReversed();
|
|
11
|
+
const chunks: string[] = [];
|
|
12
|
+
for (let i = 0; i < reversed.length; i += 3) {
|
|
13
|
+
chunks.push(
|
|
14
|
+
reversed
|
|
15
|
+
.slice(i, i + 3)
|
|
16
|
+
.toReversed()
|
|
17
|
+
.join(""),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return chunks.toReversed().join(".");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type TlonHistoryEntry = {
|
|
5
24
|
author: string;
|
|
6
25
|
content: string;
|
|
7
26
|
timestamp: number;
|
|
8
27
|
id?: string;
|
|
9
28
|
};
|
|
10
29
|
|
|
30
|
+
function createHistoryEntryFromMemo(params: {
|
|
31
|
+
memo?: Record<string, unknown> | null;
|
|
32
|
+
seal?: Record<string, unknown> | null;
|
|
33
|
+
fallbackId?: unknown;
|
|
34
|
+
}): TlonHistoryEntry {
|
|
35
|
+
const { memo, seal, fallbackId } = params;
|
|
36
|
+
return {
|
|
37
|
+
author: typeof memo?.author === "string" ? memo.author : "unknown",
|
|
38
|
+
content: extractMessageText(memo?.content || []),
|
|
39
|
+
timestamp: typeof memo?.sent === "number" ? memo.sent : Date.now(),
|
|
40
|
+
id:
|
|
41
|
+
typeof seal?.id === "string"
|
|
42
|
+
? seal.id
|
|
43
|
+
: typeof fallbackId === "string"
|
|
44
|
+
? fallbackId
|
|
45
|
+
: undefined,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
11
49
|
const messageCache = new Map<string, TlonHistoryEntry[]>();
|
|
12
50
|
const MAX_CACHED_MESSAGES = 100;
|
|
13
51
|
|
|
@@ -25,7 +63,7 @@ export function cacheMessage(channelNest: string, message: TlonHistoryEntry) {
|
|
|
25
63
|
}
|
|
26
64
|
}
|
|
27
65
|
|
|
28
|
-
|
|
66
|
+
async function fetchChannelHistory(
|
|
29
67
|
api: { scry: (path: string) => Promise<unknown> },
|
|
30
68
|
channelNest: string,
|
|
31
69
|
count = 50,
|
|
@@ -35,42 +73,45 @@ export async function fetchChannelHistory(
|
|
|
35
73
|
const scryPath = `/channels/v4/${channelNest}/posts/newest/${count}/outline.json`;
|
|
36
74
|
runtime?.log?.(`[tlon] Fetching history: ${scryPath}`);
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
const data: any = await api.scry(scryPath);
|
|
76
|
+
const data: unknown = await api.scry(scryPath);
|
|
40
77
|
if (!data) {
|
|
41
78
|
return [];
|
|
42
79
|
}
|
|
43
80
|
|
|
44
|
-
|
|
45
|
-
let posts: any[] = [];
|
|
81
|
+
let posts: unknown[] = [];
|
|
46
82
|
if (Array.isArray(data)) {
|
|
47
83
|
posts = data;
|
|
48
|
-
} else
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
} else {
|
|
85
|
+
const dataRecord = asRecord(data);
|
|
86
|
+
const postMap = asRecord(dataRecord?.posts);
|
|
87
|
+
if (postMap) {
|
|
88
|
+
posts = Object.values(postMap);
|
|
89
|
+
} else if (dataRecord) {
|
|
90
|
+
posts = Object.values(dataRecord);
|
|
91
|
+
}
|
|
52
92
|
}
|
|
53
93
|
|
|
54
94
|
const messages = posts
|
|
55
95
|
.map((item) => {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
96
|
+
const itemRecord = asRecord(item);
|
|
97
|
+
const replyPost = asRecord(itemRecord?.["r-post"]);
|
|
98
|
+
const replyPostSet = asRecord(replyPost?.set);
|
|
99
|
+
const essay = asRecord(itemRecord?.essay) ?? asRecord(replyPostSet?.essay);
|
|
100
|
+
const seal = asRecord(itemRecord?.seal) ?? asRecord(replyPostSet?.seal);
|
|
58
101
|
|
|
59
102
|
return {
|
|
60
|
-
author: essay?.author
|
|
103
|
+
author: typeof essay?.author === "string" ? essay.author : "unknown",
|
|
61
104
|
content: extractMessageText(essay?.content || []),
|
|
62
|
-
timestamp: essay?.sent
|
|
63
|
-
id: seal?.id,
|
|
105
|
+
timestamp: typeof essay?.sent === "number" ? essay.sent : Date.now(),
|
|
106
|
+
id: typeof seal?.id === "string" ? seal.id : undefined,
|
|
64
107
|
} as TlonHistoryEntry;
|
|
65
108
|
})
|
|
66
109
|
.filter((msg) => msg.content);
|
|
67
110
|
|
|
68
111
|
runtime?.log?.(`[tlon] Extracted ${messages.length} messages from history`);
|
|
69
112
|
return messages;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
runtime?.log?.(
|
|
72
|
-
`[tlon] Error fetching channel history: ${(error as { message?: string })?.message ?? String(error)}`,
|
|
73
|
-
);
|
|
113
|
+
} catch (error: unknown) {
|
|
114
|
+
runtime?.log?.(`[tlon] Error fetching channel history: ${formatErrorMessage(error)}`);
|
|
74
115
|
return [];
|
|
75
116
|
}
|
|
76
117
|
}
|
|
@@ -90,3 +131,96 @@ export async function getChannelHistory(
|
|
|
90
131
|
runtime?.log?.(`[tlon] Cache has ${cache.length} messages, need ${count}, fetching from scry...`);
|
|
91
132
|
return await fetchChannelHistory(api, channelNest, count, runtime);
|
|
92
133
|
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Fetch thread/reply history for a specific parent post.
|
|
137
|
+
* Used to get context when entering a thread conversation.
|
|
138
|
+
*/
|
|
139
|
+
export async function fetchThreadHistory(
|
|
140
|
+
api: { scry: (path: string) => Promise<unknown> },
|
|
141
|
+
channelNest: string,
|
|
142
|
+
parentId: string,
|
|
143
|
+
count = 50,
|
|
144
|
+
runtime?: RuntimeEnv,
|
|
145
|
+
): Promise<TlonHistoryEntry[]> {
|
|
146
|
+
try {
|
|
147
|
+
// Tlon API: fetch replies to a specific post
|
|
148
|
+
// Format: /channels/v4/{nest}/posts/post/{parentId}/replies/newest/{count}.json
|
|
149
|
+
// parentId needs @ud formatting (dots every 3 digits)
|
|
150
|
+
const formattedParentId = formatUd(parentId);
|
|
151
|
+
runtime?.log?.(
|
|
152
|
+
`[tlon] Thread history - parentId: ${parentId} -> formatted: ${formattedParentId}`,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const scryPath = `/channels/v4/${channelNest}/posts/post/id/${formattedParentId}/replies/newest/${count}.json`;
|
|
156
|
+
runtime?.log?.(`[tlon] Fetching thread history: ${scryPath}`);
|
|
157
|
+
|
|
158
|
+
const data: unknown = await api.scry(scryPath);
|
|
159
|
+
if (!data) {
|
|
160
|
+
runtime?.log?.(`[tlon] No thread history data returned`);
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let replies: unknown[] = [];
|
|
165
|
+
if (Array.isArray(data)) {
|
|
166
|
+
replies = data;
|
|
167
|
+
} else {
|
|
168
|
+
const dataRecord = asRecord(data);
|
|
169
|
+
const replyValue = dataRecord?.replies;
|
|
170
|
+
if (Array.isArray(replyValue)) {
|
|
171
|
+
replies = replyValue;
|
|
172
|
+
} else if (typeof replyValue === "object" && replyValue) {
|
|
173
|
+
replies = Object.values(replyValue as Record<string, unknown>);
|
|
174
|
+
} else if (dataRecord) {
|
|
175
|
+
replies = Object.values(dataRecord);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const messages = replies
|
|
180
|
+
.map((item) => {
|
|
181
|
+
// Thread replies use 'memo' structure
|
|
182
|
+
const itemRecord = asRecord(item);
|
|
183
|
+
const replyRecord = asRecord(itemRecord?.["r-reply"]);
|
|
184
|
+
const replySet = asRecord(replyRecord?.set);
|
|
185
|
+
const memo = asRecord(itemRecord?.memo) ?? asRecord(replySet?.memo) ?? itemRecord;
|
|
186
|
+
const seal = asRecord(itemRecord?.seal) ?? asRecord(replySet?.seal);
|
|
187
|
+
|
|
188
|
+
return createHistoryEntryFromMemo({ memo, seal, fallbackId: itemRecord?.id });
|
|
189
|
+
})
|
|
190
|
+
.filter((msg) => msg.content);
|
|
191
|
+
|
|
192
|
+
runtime?.log?.(`[tlon] Extracted ${messages.length} thread replies from history`);
|
|
193
|
+
return messages;
|
|
194
|
+
} catch (error: unknown) {
|
|
195
|
+
runtime?.log?.(`[tlon] Error fetching thread history: ${formatErrorMessage(error)}`);
|
|
196
|
+
// Fall back to trying alternate path structure
|
|
197
|
+
try {
|
|
198
|
+
const altPath = `/channels/v4/${channelNest}/posts/post/id/${formatUd(parentId)}.json`;
|
|
199
|
+
runtime?.log?.(`[tlon] Trying alternate path: ${altPath}`);
|
|
200
|
+
const data = asRecord(await api.scry(altPath));
|
|
201
|
+
const dataSeal = asRecord(data?.seal);
|
|
202
|
+
const dataMeta = asRecord(dataSeal?.meta);
|
|
203
|
+
const repliesValue = data?.replies;
|
|
204
|
+
|
|
205
|
+
if (typeof dataMeta?.replyCount === "number" && dataMeta.replyCount > 0 && repliesValue) {
|
|
206
|
+
const replies = Array.isArray(repliesValue)
|
|
207
|
+
? repliesValue
|
|
208
|
+
: Object.values(repliesValue as Record<string, unknown>);
|
|
209
|
+
const messages = replies
|
|
210
|
+
.map((reply: unknown) => {
|
|
211
|
+
const replyRecord = asRecord(reply);
|
|
212
|
+
const memo = asRecord(replyRecord?.memo);
|
|
213
|
+
const seal = asRecord(replyRecord?.seal);
|
|
214
|
+
return createHistoryEntryFromMemo({ memo, seal });
|
|
215
|
+
})
|
|
216
|
+
.filter((msg: TlonHistoryEntry) => msg.content);
|
|
217
|
+
|
|
218
|
+
runtime?.log?.(`[tlon] Extracted ${messages.length} replies from post data`);
|
|
219
|
+
return messages;
|
|
220
|
+
}
|
|
221
|
+
} catch (altError: unknown) {
|
|
222
|
+
runtime?.log?.(`[tlon] Alternate path also failed: ${formatErrorMessage(altError)}`);
|
|
223
|
+
}
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
}
|