@timeatlas/openclaw-timeatlas 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -3,20 +3,32 @@
3
3
  Makes Pat, the Time Atlas chat, an agent: the user's chat messages go to
4
4
  their OpenClaw, and its answers come back to the app.
5
5
 
6
- 1. The app asks the proxy for a pairing code (Make Pat an Agent).
7
- 2. The user sets it here, and restarts the gateway:
6
+ 1. The app asks the proxy for a code (Make Pat an Agent).
7
+ 2. The user runs `time-atlas-skills/setup.py CODE` where OpenClaw runs. It
8
+ trades the code at `POST /agent/setup` for a token for the MCP server
9
+ and one for this channel, and configures OpenClaw: the MCP server, this
10
+ plugin, and `channels.timeatlas.token`.
11
+ 3. The plugin long polls `GET /agent/poll` with the token for the user's
12
+ messages, hands each to the agent, and posts typing, text and done to
13
+ `POST /agent/events`.
8
14
 
9
- openclaw plugins install @timeatlas/openclaw-timeatlas
10
- openclaw config set channels.timeatlas.pairingCode ABCD-EFGH
11
- openclaw gateway restart
12
-
13
- 3. The plugin trades the code at `POST /agent/pair` for a token, kept in
14
- OpenClaw's state directory (`timeatlas/<account>.json`).
15
- 4. It long polls `GET /agent/poll` for the user's messages, hands each to
16
- the agent, and posts typing, text and done to `POST /agent/events`.
15
+ Without setup.py, the plugin can pair by itself: set
16
+ `channels.timeatlas.pairingCode` to the code, and it trades it at
17
+ `POST /agent/pair` for a token, kept in OpenClaw's state directory
18
+ (`timeatlas/<account>.json`). This gives no MCP access.
17
19
 
18
20
  `channels.timeatlas.proxyUrl` points it at another proxy, for testing.
19
21
 
20
22
  For development, `openclaw plugins install --link ./openclaw/timeatlas-channel`.
21
23
 
22
24
  Type check with `npm install && npm run typecheck`.
25
+
26
+ OpenClaw loads the TypeScript entries from a checkout, and the JavaScript
27
+ `npm run build` writes to `dist/` from an installed package
28
+ (`runtimeExtensions`). Publishing builds it first:
29
+
30
+ npm version patch
31
+ npm publish
32
+
33
+ OpenClaw installs package names from ClawHub, so the npm package is
34
+ installed with the `npm:` prefix.
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { defineChannelPluginEntry } from "openclaw/plugin-sdk/channel-core";
2
+ import { timeAtlasPlugin } from "./src/channel.js";
3
+ export default defineChannelPluginEntry({
4
+ id: "timeatlas",
5
+ name: "Time Atlas",
6
+ description: "Time Atlas channel: your Time Atlas chat answered by your agent",
7
+ plugin: timeAtlasPlugin,
8
+ });
@@ -0,0 +1,3 @@
1
+ import { defineSetupPluginEntry } from "openclaw/plugin-sdk/channel-core";
2
+ import { timeAtlasPlugin } from "./src/channel.js";
3
+ export default defineSetupPluginEntry(timeAtlasPlugin);
@@ -0,0 +1,92 @@
1
+ import { createChannelPluginBase, createChatChannelPlugin, } from "openclaw/plugin-sdk/channel-core";
2
+ import { CHANNEL_ID, DEFAULT_PROXY_URL, linkFor, ProxyLink, } from "./link.js";
3
+ const DEFAULT_ACCOUNT_ID = "default";
4
+ function section(cfg) {
5
+ return (cfg.channels?.[CHANNEL_ID] ??
6
+ {});
7
+ }
8
+ function resolveAccount(cfg, accountId) {
9
+ const config = section(cfg);
10
+ return {
11
+ accountId: accountId ?? DEFAULT_ACCOUNT_ID,
12
+ token: (config.token ?? "").trim(),
13
+ pairingCode: (config.pairingCode ?? "").trim().toUpperCase(),
14
+ proxyUrl: (config.proxyUrl ?? DEFAULT_PROXY_URL).replace(/\/+$/, ""),
15
+ };
16
+ }
17
+ const config = {
18
+ // One Time Atlas user per OpenClaw.
19
+ listAccountIds: () => [DEFAULT_ACCOUNT_ID],
20
+ resolveAccount,
21
+ inspectAccount(cfg) {
22
+ const config = section(cfg);
23
+ const configured = Boolean(config.token || config.pairingCode);
24
+ return {
25
+ enabled: true,
26
+ // Set up with a token, or about to pair with a code.
27
+ configured,
28
+ tokenStatus: configured ? "available" : "missing",
29
+ };
30
+ },
31
+ };
32
+ const chatPlugin = createChatChannelPlugin({
33
+ base: {
34
+ ...createChannelPluginBase({
35
+ id: CHANNEL_ID,
36
+ setup: {
37
+ applyAccountConfig: ({ cfg, input }) => ({
38
+ ...cfg,
39
+ channels: {
40
+ ...cfg.channels,
41
+ [CHANNEL_ID]: { ...section(cfg), ...input },
42
+ },
43
+ }),
44
+ },
45
+ }),
46
+ // Given here rather than to the base helper, whose result leaves it
47
+ // optional where the plugin needs it.
48
+ config,
49
+ },
50
+ // The proxy only hands over messages of the user who paired, so whoever
51
+ // comes in on this channel is them.
52
+ security: {
53
+ dm: {
54
+ channelKey: CHANNEL_ID,
55
+ resolvePolicy: () => "open",
56
+ resolveAllowFrom: () => ["*"],
57
+ defaultPolicy: "open",
58
+ },
59
+ },
60
+ threading: { topLevelReplyToMode: "reply" },
61
+ outbound: {
62
+ base: { deliveryMode: "direct" },
63
+ attachedResults: {
64
+ channel: CHANNEL_ID,
65
+ // What the agent sends unasked. The proxy adds it to the answer the
66
+ // app is waiting for, if any; there is no way yet to reach the user
67
+ // otherwise.
68
+ sendText: async ({ accountId, text }) => {
69
+ const link = linkFor(accountId);
70
+ if (!link) {
71
+ throw new Error("timeatlas: not connected to Time Atlas");
72
+ }
73
+ await link.post([{ type: "text", text }]);
74
+ return { messageId: `timeatlas-${Date.now()}` };
75
+ },
76
+ },
77
+ },
78
+ });
79
+ export const timeAtlasPlugin = {
80
+ ...chatPlugin,
81
+ gateway: {
82
+ ...chatPlugin.gateway,
83
+ startAccount: async (ctx) => {
84
+ const log = {
85
+ info: (message) => ctx.log?.info?.(message),
86
+ warn: (message) => ctx.log?.warn?.(message),
87
+ error: (message) => ctx.log?.error?.(message),
88
+ };
89
+ await new ProxyLink(ctx.cfg, ctx.account, ctx.abortSignal, log).run();
90
+ },
91
+ },
92
+ };
@@ -0,0 +1,228 @@
1
+ import { dispatchInboundDirectDm } from "openclaw/plugin-sdk/channel-inbound";
2
+ import { forgetToken, loadToken, saveToken } from "./token-store.js";
3
+ export const CHANNEL_ID = "timeatlas";
4
+ export const DEFAULT_PROXY_URL = "https://ai.timeatlas.app";
5
+ /** The one person on the other end: the Time Atlas user who paired. */
6
+ const USER_PEER_ID = "timeatlas-user";
7
+ const MIN_BACKOFF_MS = 1_000;
8
+ const MAX_BACKOFF_MS = 30_000;
9
+ /** Longer than the proxy holds a poll open. */
10
+ const POLL_TIMEOUT_MS = 40_000;
11
+ class Unauthorized extends Error {
12
+ }
13
+ /** The links running, by account, for what the agent sends unasked. */
14
+ const links = new Map();
15
+ export function linkFor(accountId) {
16
+ return links.get(accountId ?? "default");
17
+ }
18
+ /**
19
+ * ProxyLink is one account's connection to the Time Atlas proxy. It pairs
20
+ * with the code from the app, then polls for the user's chat messages,
21
+ * hands each to the agent, and posts back what the agent answers.
22
+ */
23
+ export class ProxyLink {
24
+ cfg;
25
+ account;
26
+ abortSignal;
27
+ log;
28
+ token;
29
+ /** Messages are answered one after another, in the order they came. */
30
+ queue = Promise.resolve();
31
+ constructor(cfg, account, abortSignal, log) {
32
+ this.cfg = cfg;
33
+ this.account = account;
34
+ this.abortSignal = abortSignal;
35
+ this.log = log;
36
+ }
37
+ /** Runs until the account is stopped. */
38
+ async run() {
39
+ links.set(this.account.accountId, this);
40
+ try {
41
+ await this.runUntilStopped();
42
+ }
43
+ finally {
44
+ if (links.get(this.account.accountId) === this) {
45
+ links.delete(this.account.accountId);
46
+ }
47
+ }
48
+ }
49
+ async runUntilStopped() {
50
+ let backoff = MIN_BACKOFF_MS;
51
+ while (!this.abortSignal.aborted) {
52
+ try {
53
+ if (!this.token) {
54
+ this.token = await this.pairedToken();
55
+ if (!this.token) {
56
+ this.log.warn("timeatlas: not set up. Get a code from Make Pat an Agent in " +
57
+ "the Time Atlas app and run Time Atlas setup with it.");
58
+ await this.stopped();
59
+ return;
60
+ }
61
+ }
62
+ const messages = await this.poll();
63
+ backoff = MIN_BACKOFF_MS;
64
+ for (const message of messages) {
65
+ this.queue = this.queue.then(() => this.answer(message));
66
+ }
67
+ }
68
+ catch (err) {
69
+ if (this.abortSignal.aborted) {
70
+ return;
71
+ }
72
+ if (err instanceof Unauthorized) {
73
+ this.log.error("timeatlas: disconnected from Time Atlas. Set up again with a " +
74
+ "new code from the app.");
75
+ this.token = undefined;
76
+ await forgetToken(this.account.accountId);
77
+ await this.stopped();
78
+ return;
79
+ }
80
+ this.log.warn(`timeatlas: ${String(err)}, trying again`);
81
+ await this.sleep(backoff);
82
+ backoff = Math.min(backoff * 2, MAX_BACKOFF_MS);
83
+ }
84
+ }
85
+ }
86
+ /**
87
+ * The token to poll with: the one in the config, given by Time Atlas
88
+ * setup, or else the one kept, unless the config has a code it was not
89
+ * paired with, which is traded for a new one.
90
+ */
91
+ async pairedToken() {
92
+ if (this.account.token) {
93
+ return this.account.token;
94
+ }
95
+ const accountId = this.account.accountId;
96
+ const code = this.account.pairingCode;
97
+ const stored = await loadToken(accountId);
98
+ if (stored && (!code || stored.pairedWithCode === code)) {
99
+ return stored.token;
100
+ }
101
+ if (!code) {
102
+ return undefined;
103
+ }
104
+ const response = await fetch(`${this.account.proxyUrl}/agent/pair`, {
105
+ method: "POST",
106
+ headers: { "Content-Type": "application/json" },
107
+ body: JSON.stringify({ code }),
108
+ signal: this.abortSignal,
109
+ });
110
+ const body = (await response.json().catch(() => ({})));
111
+ if (!response.ok || !body.token) {
112
+ throw new Error(`pairing failed: ${body.error ?? response.statusText}`);
113
+ }
114
+ await saveToken(accountId, { token: body.token, pairedWithCode: code });
115
+ this.log.info("timeatlas: paired with Time Atlas");
116
+ return body.token;
117
+ }
118
+ async poll() {
119
+ const response = await fetch(`${this.account.proxyUrl}/agent/poll`, {
120
+ headers: { Authorization: `Bearer ${this.token}` },
121
+ signal: AbortSignal.any([
122
+ this.abortSignal,
123
+ AbortSignal.timeout(POLL_TIMEOUT_MS),
124
+ ]),
125
+ });
126
+ if (response.status === 401) {
127
+ throw new Unauthorized();
128
+ }
129
+ if (!response.ok) {
130
+ throw new Error(`poll: ${response.status} ${response.statusText}`);
131
+ }
132
+ const body = (await response.json());
133
+ return body.messages ?? [];
134
+ }
135
+ /** Tells the proxy what the agent says. */
136
+ async post(events) {
137
+ if (!this.token) {
138
+ throw new Error("not paired");
139
+ }
140
+ const response = await fetch(`${this.account.proxyUrl}/agent/events`, {
141
+ method: "POST",
142
+ headers: {
143
+ Authorization: `Bearer ${this.token}`,
144
+ "Content-Type": "application/json",
145
+ },
146
+ body: JSON.stringify({ events }),
147
+ signal: this.abortSignal,
148
+ });
149
+ if (response.status === 401) {
150
+ throw new Unauthorized();
151
+ }
152
+ if (!response.ok) {
153
+ throw new Error(`events: ${response.status} ${response.statusText}`);
154
+ }
155
+ }
156
+ /**
157
+ * Has the agent answer the message. It types from when the message comes
158
+ * until the whole turn is over, which is when the proxy hears it is done.
159
+ */
160
+ async answer(message) {
161
+ const replyTo = message.id;
162
+ let said = false;
163
+ try {
164
+ await this.post([{ type: "typing", replyTo, on: true }]);
165
+ await dispatchInboundDirectDm({
166
+ cfg: this.cfg,
167
+ channel: CHANNEL_ID,
168
+ channelLabel: "Time Atlas",
169
+ accountId: this.account.accountId,
170
+ peer: { kind: "direct", id: USER_PEER_ID },
171
+ senderId: USER_PEER_ID,
172
+ senderAddress: `${CHANNEL_ID}:${USER_PEER_ID}`,
173
+ recipientAddress: `${CHANNEL_ID}:pat`,
174
+ conversationLabel: "Time Atlas",
175
+ rawBody: message.text,
176
+ messageId: message.id,
177
+ timestamp: message.timestamp,
178
+ // The proxy only hands over the paired user's messages.
179
+ commandAuthorized: true,
180
+ inboundAccessAuthorized: true,
181
+ channelIngress: "unsupported",
182
+ deliver: async (payload) => {
183
+ const text = payload.text?.trim();
184
+ if (!text) {
185
+ return;
186
+ }
187
+ // Each reply of the turn is a paragraph of one answer.
188
+ await this.post([
189
+ { type: "text", replyTo, text: said ? `\n\n${text}` : text },
190
+ ]);
191
+ said = true;
192
+ },
193
+ onRecordError: (err) => this.log.warn(`timeatlas: could not record the turn: ${String(err)}`),
194
+ onDispatchError: (err, info) => this.log.error(`timeatlas: ${info.kind} failed: ${String(err)}`),
195
+ });
196
+ await this.post([
197
+ { type: "typing", replyTo, on: false },
198
+ { type: "done", replyTo },
199
+ ]);
200
+ }
201
+ catch (err) {
202
+ this.log.error(`timeatlas: could not answer: ${String(err)}`);
203
+ await this.post([
204
+ { type: "error", replyTo, text: "The agent ran into a problem." },
205
+ ]).catch(() => { });
206
+ }
207
+ }
208
+ sleep(ms) {
209
+ return new Promise((resolve) => {
210
+ const timer = setTimeout(resolve, ms);
211
+ this.abortSignal.addEventListener("abort", () => {
212
+ clearTimeout(timer);
213
+ resolve();
214
+ }, { once: true });
215
+ });
216
+ }
217
+ stopped() {
218
+ return new Promise((resolve) => {
219
+ if (this.abortSignal.aborted) {
220
+ resolve();
221
+ return;
222
+ }
223
+ this.abortSignal.addEventListener("abort", () => resolve(), {
224
+ once: true,
225
+ });
226
+ });
227
+ }
228
+ }
@@ -0,0 +1,29 @@
1
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
4
+ function tokenPath(accountId) {
5
+ return path.join(resolveStateDir(), "timeatlas", `${accountId}.json`);
6
+ }
7
+ export async function loadToken(accountId) {
8
+ try {
9
+ const stored = JSON.parse(await readFile(tokenPath(accountId), "utf8"));
10
+ if (typeof stored?.token === "string" && stored.token) {
11
+ return {
12
+ token: stored.token,
13
+ pairedWithCode: String(stored.pairedWithCode ?? ""),
14
+ };
15
+ }
16
+ }
17
+ catch {
18
+ // None yet.
19
+ }
20
+ return undefined;
21
+ }
22
+ export async function saveToken(accountId, stored) {
23
+ const file = tokenPath(accountId);
24
+ await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
25
+ await writeFile(file, JSON.stringify(stored), { mode: 0o600 });
26
+ }
27
+ export async function forgetToken(accountId) {
28
+ await rm(tokenPath(accountId), { force: true });
29
+ }
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "id": "timeatlas",
3
- "channels": ["timeatlas"],
3
+ "channels": [
4
+ "timeatlas"
5
+ ],
4
6
  "name": "Time Atlas",
5
7
  "description": "Time Atlas channel: your Time Atlas chat answered by your agent",
6
8
  "configSchema": {
@@ -14,11 +16,22 @@
14
16
  "type": "object",
15
17
  "additionalProperties": false,
16
18
  "properties": {
17
- "pairingCode": { "type": "string" },
18
- "proxyUrl": { "type": "string" }
19
+ "token": {
20
+ "type": "string"
21
+ },
22
+ "pairingCode": {
23
+ "type": "string"
24
+ },
25
+ "proxyUrl": {
26
+ "type": "string"
27
+ }
19
28
  }
20
29
  },
21
30
  "uiHints": {
31
+ "token": {
32
+ "label": "Token from Time Atlas setup",
33
+ "sensitive": true
34
+ },
22
35
  "pairingCode": {
23
36
  "label": "Pairing code from the Time Atlas app",
24
37
  "sensitive": true
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@timeatlas/openclaw-timeatlas",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Time Atlas channel for OpenClaw: Pat, the Time Atlas chat, as an agent",
5
5
  "type": "module",
6
6
  "openclaw": {
7
- "extensions": ["./index.ts"],
7
+ "extensions": [
8
+ "./index.ts"
9
+ ],
10
+ "runtimeExtensions": [
11
+ "./dist/index.js"
12
+ ],
8
13
  "setupEntry": "./setup-entry.ts",
14
+ "runtimeSetupEntry": "./dist/setup-entry.js",
9
15
  "channel": {
10
16
  "id": "timeatlas",
11
17
  "label": "Time Atlas",
@@ -16,10 +22,24 @@
16
22
  "openclaw": ">=2026.11.10"
17
23
  },
18
24
  "devDependencies": {
25
+ "@types/node": "22.20.7",
19
26
  "openclaw": "2026.11.10",
20
27
  "typescript": "5.9.3"
21
28
  },
22
29
  "scripts": {
23
- "typecheck": "tsc --noEmit"
30
+ "build": "rm -rf dist && tsc",
31
+ "typecheck": "tsc --noEmit",
32
+ "prepublishOnly": "npm run build"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "index.ts",
37
+ "setup-entry.ts",
38
+ "src",
39
+ "openclaw.plugin.json",
40
+ "README.md"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
24
44
  }
25
45
  }
package/src/channel.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  const DEFAULT_ACCOUNT_ID = "default";
15
15
 
16
16
  type TimeAtlasSection = {
17
+ token?: string;
17
18
  pairingCode?: string;
18
19
  proxyUrl?: string;
19
20
  };
@@ -30,6 +31,7 @@ function resolveAccount(
30
31
  const config = section(cfg);
31
32
  return {
32
33
  accountId: accountId ?? DEFAULT_ACCOUNT_ID,
34
+ token: (config.token ?? "").trim(),
33
35
  pairingCode: (config.pairingCode ?? "").trim().toUpperCase(),
34
36
  proxyUrl: (config.proxyUrl ?? DEFAULT_PROXY_URL).replace(/\/+$/, ""),
35
37
  };
@@ -41,11 +43,12 @@ const config = {
41
43
  resolveAccount,
42
44
  inspectAccount(cfg: OpenClawConfig) {
43
45
  const config = section(cfg);
46
+ const configured = Boolean(config.token || config.pairingCode);
44
47
  return {
45
48
  enabled: true,
46
- // Paired already, or about to with a code.
47
- configured: Boolean(config.pairingCode),
48
- tokenStatus: config.pairingCode ? "available" : "missing",
49
+ // Set up with a token, or about to pair with a code.
50
+ configured,
51
+ tokenStatus: configured ? "available" : "missing",
49
52
  };
50
53
  },
51
54
  };
package/src/link.ts CHANGED
@@ -15,6 +15,8 @@ const POLL_TIMEOUT_MS = 40_000;
15
15
 
16
16
  export type ResolvedAccount = {
17
17
  accountId: string;
18
+ /** Given by Time Atlas setup, which paired already. */
19
+ token: string;
18
20
  pairingCode: string;
19
21
  proxyUrl: string;
20
22
  };
@@ -85,8 +87,8 @@ export class ProxyLink {
85
87
  this.token = await this.pairedToken();
86
88
  if (!this.token) {
87
89
  this.log.warn(
88
- "timeatlas: no pairing code. Get one from Make Pat an Agent in " +
89
- "the Time Atlas app and set channels.timeatlas.pairingCode.",
90
+ "timeatlas: not set up. Get a code from Make Pat an Agent in " +
91
+ "the Time Atlas app and run Time Atlas setup with it.",
90
92
  );
91
93
  await this.stopped();
92
94
  return;
@@ -103,8 +105,8 @@ export class ProxyLink {
103
105
  }
104
106
  if (err instanceof Unauthorized) {
105
107
  this.log.error(
106
- "timeatlas: disconnected from Time Atlas. Pair again with a new " +
107
- "code from the app.",
108
+ "timeatlas: disconnected from Time Atlas. Set up again with a " +
109
+ "new code from the app.",
108
110
  );
109
111
  this.token = undefined;
110
112
  await forgetToken(this.account.accountId);
@@ -119,10 +121,14 @@ export class ProxyLink {
119
121
  }
120
122
 
121
123
  /**
122
- * The token to poll with: the one kept, unless the config has a code it
123
- * was not paired with, which is traded for a new one.
124
+ * The token to poll with: the one in the config, given by Time Atlas
125
+ * setup, or else the one kept, unless the config has a code it was not
126
+ * paired with, which is traded for a new one.
124
127
  */
125
128
  private async pairedToken(): Promise<string | undefined> {
129
+ if (this.account.token) {
130
+ return this.account.token;
131
+ }
126
132
  const accountId = this.account.accountId;
127
133
  const code = this.account.pairingCode;
128
134
  const stored = await loadToken(accountId);
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "strict": true,
7
- "skipLibCheck": true,
8
- "noEmit": true,
9
- "allowImportingTsExtensions": false,
10
- "types": ["node"]
11
- },
12
- "include": ["index.ts", "setup-entry.ts", "src/**/*.ts"]
13
- }