@yanzc/claude-pro 0.11.0 → 0.13.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 +56 -36
- package/package.json +1 -1
- package/src/agent.js +4 -3
- package/src/browser/session.js +21 -1
- package/src/commands.js +198 -33
- package/src/config.js +17 -2
- package/src/gateway.js +33 -0
- package/src/live.js +148 -0
- package/src/main.js +5 -3
- package/src/peers.js +41 -4
- package/src/providers.js +25 -6
- package/src/remote.js +82 -268
- package/src/runtime.js +36 -11
- package/src/selfcheck.js +3 -3
- package/src/session.js +128 -8
- package/src/supervisor.js +1 -1
- package/src/tools/bash.js +21 -12
- package/src/tools/browser.js +14 -8
- package/src/tools/code.js +18 -11
- package/src/tools/restart.js +1 -1
- package/src/ui/dialogs.js +23 -30
- package/src/ui/editor.js +65 -169
- package/src/ui/repl.js +467 -474
- package/src/ui/screen.js +47 -674
- package/src/updater.js +5 -4
- package/src/web/api.js +881 -0
- package/src/web/app.css +530 -0
- package/src/web/app.js +2188 -0
- package/src/web/data.js +436 -0
- package/src/web/host.js +332 -0
- package/src/web/login.html +67 -0
- package/src/web/logo.svg +1 -0
- package/src/web/page.html +44 -0
- package/src/web/remote-access.js +232 -0
- package/src/web/server.js +476 -0
package/src/peers.js
CHANGED
|
@@ -80,12 +80,15 @@ export function findPeer(peers, ref) {
|
|
|
80
80
|
export class PeerNode {
|
|
81
81
|
// onMessage(msg): msg = {id, kind: 'task'|'reply', text, inReplyTo, from: {id, name, cwd}}
|
|
82
82
|
// `id`: the id this session had before a restart, so that answers on their way still find it.
|
|
83
|
-
// getStatus(): {busy}, what GET /status answers (an update waits until no session of the machine is busy
|
|
84
|
-
|
|
83
|
+
// getStatus(): {busy, ...}, what GET /status answers (an update waits until no session of the machine is busy; the
|
|
84
|
+
// web console lists the sessions with it). live: {feed: a LiveFeed (GET /events), command(type, body): the web
|
|
85
|
+
// console's commands (POST /command), as the gateway's page sends them}.
|
|
86
|
+
constructor({ cwd, name, id, onMessage, getStatus, live = null }) {
|
|
85
87
|
this.cwd = cwd;
|
|
86
88
|
this.wantedName = name || null;
|
|
87
89
|
this.onMessage = onMessage;
|
|
88
90
|
this.getStatus = getStatus;
|
|
91
|
+
this.live = live;
|
|
89
92
|
this.id = /^[0-9a-f]{12}$/.test(id || '') ? id : crypto.randomBytes(6).toString('hex');
|
|
90
93
|
this.token = crypto.randomBytes(16).toString('hex');
|
|
91
94
|
this.name = null;
|
|
@@ -121,7 +124,9 @@ export class PeerNode {
|
|
|
121
124
|
write() {
|
|
122
125
|
if (!this.port) return;
|
|
123
126
|
fs.mkdirSync(PEERS_DIR, { recursive: true });
|
|
124
|
-
|
|
127
|
+
// sessionClaims: this version marks the conversations it holds (session.js claimSession), so the age cleanup
|
|
128
|
+
// need not keep a whole project for it
|
|
129
|
+
const data = { id: this.id, name: this.name, cwd: this.cwd, pid: process.pid, port: this.port, token: this.token, startedAt: this.startedAt ??= Date.now(), sessionClaims: true };
|
|
125
130
|
const json = JSON.stringify(data);
|
|
126
131
|
if (json === this.written) return;
|
|
127
132
|
// whole or not at all: the other sessions read these files at any time (listPeers)
|
|
@@ -145,7 +150,39 @@ export class PeerNode {
|
|
|
145
150
|
if (req.headers.authorization !== `Bearer ${this.token}`) return reply(401, { error: 'bad token' });
|
|
146
151
|
let status = {};
|
|
147
152
|
try { status = this.getStatus?.() || {}; } catch { /* nothing to say */ }
|
|
148
|
-
return reply(200, { busy: Boolean(status.busy) });
|
|
153
|
+
return reply(200, { ...status, busy: Boolean(status.busy) });
|
|
154
|
+
}
|
|
155
|
+
if (req.method === 'GET' && req.url === '/events' && this.live?.feed) {
|
|
156
|
+
if (req.headers.authorization !== `Bearer ${this.token}`) return reply(401, { error: 'bad token' });
|
|
157
|
+
this.live.feed.attach(res);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const image = /^\/image\/(\d+)$/.exec(req.url || '');
|
|
161
|
+
if (req.method === 'GET' && image && this.live?.image) {
|
|
162
|
+
if (req.headers.authorization !== `Bearer ${this.token}`) return reply(401, { error: 'bad token' });
|
|
163
|
+
let img = null;
|
|
164
|
+
try { img = this.live.image(Number(image[1])); } catch { /* none */ }
|
|
165
|
+
if (!img) return reply(404, { error: 'no such image' });
|
|
166
|
+
res.writeHead(200, { 'content-type': img.mediaType, 'cache-control': 'private, max-age=3600' });
|
|
167
|
+
res.end(img.data);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (req.method === 'POST' && req.url === '/command' && this.live?.command) {
|
|
171
|
+
if (req.headers.authorization !== `Bearer ${this.token}`) return reply(401, { error: 'bad token' });
|
|
172
|
+
let body = '';
|
|
173
|
+
req.setEncoding('utf8');
|
|
174
|
+
req.on('data', (d) => { body += d; if (body.length > 16 * MAX_BODY) req.destroy(); });
|
|
175
|
+
req.on('end', async () => {
|
|
176
|
+
let cmd;
|
|
177
|
+
try { cmd = JSON.parse(body); } catch { return reply(400, { ok: false, error: 'bad json' }); }
|
|
178
|
+
try {
|
|
179
|
+
const result = await this.live.command(String(cmd?.type || ''), cmd?.body && typeof cmd.body === 'object' ? cmd.body : {});
|
|
180
|
+
reply(200, { ...(result || {}), ok: true });
|
|
181
|
+
} catch (e) {
|
|
182
|
+
reply(200, { ok: false, error: e?.message || String(e) });
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
149
186
|
}
|
|
150
187
|
if (req.method !== 'POST' || req.url !== '/message') return reply(404, { error: 'not found' });
|
|
151
188
|
if (req.headers.authorization !== `Bearer ${this.token}`) return reply(401, { error: 'bad token' });
|
package/src/providers.js
CHANGED
|
@@ -60,9 +60,21 @@ export function validBaseUrl(url) {
|
|
|
60
60
|
export const cleanProviderId = (name) => String(name || '').trim().toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 30);
|
|
61
61
|
export const reservedProviderId = (id) => id === GATEWAY_PROVIDER || PRESET_IDS.has(id);
|
|
62
62
|
|
|
63
|
+
// The id of a new connection named after `base` that no other connection, built-in provider or the gateway has: the
|
|
64
|
+
// second DeepSeek is deepseek-2, the next deepseek-3.
|
|
65
|
+
export function nextInstanceId(base, connections = readConnections()) {
|
|
66
|
+
const stem = cleanProviderId(base) || 'provider';
|
|
67
|
+
const free = (id) => !connections[id] && !reservedProviderId(id);
|
|
68
|
+
if (free(stem)) return stem;
|
|
69
|
+
for (let n = 2; ; n++) if (free(`${stem}-${n}`)) return `${stem}-${n}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
63
72
|
// {id: connection}. A connection: {apiKey, authHeader, model?, models: [{id, name?, window?, maxOutput?, price?}],
|
|
64
|
-
// savedAt} (model: the one chosen at /connect
|
|
65
|
-
//
|
|
73
|
+
// savedAt, name?} (model: the one chosen at /connect; name: what the user called it, else the provider's own), and for
|
|
74
|
+
// the user's own providers also {custom: true, name, protocol, baseUrl}. A second account of a built-in provider (or of
|
|
75
|
+
// 7bit.fun) is a connection of its own under another id (deepseek-2, 7bit-2: see nextInstanceId) with {preset: the
|
|
76
|
+
// provider's id}, and for 7bit.fun's also {protocol, baseUrl}; its models are deepseek-2/<model>. The entry "7bit"
|
|
77
|
+
// holds at most the name given to the gateway's own login (gateway.json has its key). Read again at most once a second (the model is resolved at every frame of the footer), and at once after
|
|
66
78
|
// this process changed the file; another window's change is seen within the second. Not to be changed by callers.
|
|
67
79
|
const MEMO_MS = 1000;
|
|
68
80
|
let memo = null; // {at, data}
|
|
@@ -105,7 +117,13 @@ export function removeConnection(id) {
|
|
|
105
117
|
export function providerInfo(id, connections = readConnections()) {
|
|
106
118
|
const connection = connections[id] || null;
|
|
107
119
|
const preset = PRESETS.find((p) => p.id === id);
|
|
108
|
-
if (preset) return { ...preset, connection };
|
|
120
|
+
if (preset) return { ...preset, name: connection?.name || preset.name, connection };
|
|
121
|
+
// another account of a built-in provider, or of 7bit.fun (its address kept in the connection)
|
|
122
|
+
if (connection?.preset) {
|
|
123
|
+
const base = connection.preset === GATEWAY_PROVIDER ? { name: '7bit.fun', protocol: 'anthropic' } : PRESETS.find((p) => p.id === connection.preset);
|
|
124
|
+
const baseUrl = connection.baseUrl || base?.baseUrl;
|
|
125
|
+
if (base && baseUrl) return { ...base, id, name: connection.name || base.name, baseUrl, preset: connection.preset, connection };
|
|
126
|
+
}
|
|
109
127
|
if (connection?.custom && connection.baseUrl) {
|
|
110
128
|
return { id, name: connection.name || id, protocol: connection.protocol === 'openai' ? 'openai' : 'anthropic', baseUrl: connection.baseUrl, custom: true, connection };
|
|
111
129
|
}
|
|
@@ -115,8 +133,8 @@ export function providerInfo(id, connections = readConnections()) {
|
|
|
115
133
|
// The providers that are connected now, in the order /connect lists them (the gateway is not among them: see
|
|
116
134
|
// gatewayLogin).
|
|
117
135
|
export function connectedProviders(connections = readConnections()) {
|
|
118
|
-
const rank = (id) => { const i = PRESETS.findIndex((p) => p.id === id); return i < 0 ? PRESETS.length : i; };
|
|
119
|
-
return Object.keys(connections).sort((a, b) => rank(a) - rank(b))
|
|
136
|
+
const rank = (id) => { const i = PRESETS.findIndex((p) => p.id === (connections[id]?.preset || id)); return i < 0 ? PRESETS.length : i; };
|
|
137
|
+
return Object.keys(connections).sort((a, b) => rank(a) - rank(b) || a.localeCompare(b, 'en', { numeric: true }))
|
|
120
138
|
.map((id) => providerInfo(id, connections)).filter((p) => p?.connection && (p.connection.apiKey || p.keyless || p.custom));
|
|
121
139
|
}
|
|
122
140
|
|
|
@@ -130,7 +148,8 @@ export function splitModelRef(spec, connections = null) {
|
|
|
130
148
|
if (slash > 0) {
|
|
131
149
|
const prefix = name.slice(0, slash).toLowerCase();
|
|
132
150
|
const rest = name.slice(slash + 1);
|
|
133
|
-
|
|
151
|
+
const conn = rest && !(prefix === GATEWAY_PROVIDER || PRESET_IDS.has(prefix)) ? (connections ?? readConnections())[prefix] : null;
|
|
152
|
+
if (rest && (prefix === GATEWAY_PROVIDER || PRESET_IDS.has(prefix) || conn?.custom || conn?.preset)) return { provider: prefix, model: rest };
|
|
134
153
|
}
|
|
135
154
|
return { provider: GATEWAY_PROVIDER, model: name };
|
|
136
155
|
}
|