pi-cloudflare 0.8.2 → 0.9.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/README.md +27 -16
- package/dist/config.d.ts +4 -4
- package/dist/runtime.d.ts +23 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +115 -60
- package/dist/runtime.js.map +1 -1
- package/dist/tool-cache.d.ts +25 -0
- package/dist/tool-cache.d.ts.map +1 -0
- package/dist/tool-cache.js +43 -0
- package/dist/tool-cache.js.map +1 -0
- package/package.json +5 -5
- package/plugin.json +1 -1
package/README.md
CHANGED
|
@@ -76,6 +76,10 @@ you approve, and tokens (with refresh) are stored owner-only in
|
|
|
76
76
|
before expiry, and setup skips servers that are still fresh. If a server
|
|
77
77
|
later rejects its token, rerun setup (with `--only` for just that one).
|
|
78
78
|
|
|
79
|
+
Skip this section entirely when a static API token is configured (see
|
|
80
|
+
Persistent auth below): the token then authenticates every server and
|
|
81
|
+
browser OAuth is never consulted.
|
|
82
|
+
|
|
79
83
|
Agent Plugins clients use their own token file under `${PLUGIN_DATA}`. When
|
|
80
84
|
authentication is missing or rejected, call the generated
|
|
81
85
|
`cf_<server>_reauthenticate` tool and run the exact command it returns; that
|
|
@@ -98,17 +102,24 @@ In `~/.pi/agent/settings.json`:
|
|
|
98
102
|
|
|
99
103
|
## Persistent auth (a month and beyond)
|
|
100
104
|
|
|
105
|
+
Sessions launch without touching the network: tools register from a local
|
|
106
|
+
cache, and each server connects — authenticating as needed — on its first
|
|
107
|
+
tool call. Token checks and re-authentication prompts therefore only ever
|
|
108
|
+
happen when Cloudflare is actually accessed.
|
|
109
|
+
|
|
101
110
|
Browser OAuth access tokens live about an hour; both adapters refresh them
|
|
102
111
|
silently before tool calls, so daily use normally does not re-authenticate.
|
|
103
112
|
When refresh itself is rejected (revoked, rotated away by a parallel login,
|
|
104
|
-
or expired),
|
|
105
|
-
a
|
|
113
|
+
or expired), the tool call fails with an exact recovery command instead of a
|
|
114
|
+
dead end — and if a server could not complete its first-run discovery, a
|
|
115
|
+
`cf_<server>_reauthenticate` tool appears with the same instructions.
|
|
106
116
|
|
|
107
117
|
Two levers for longer-lived credentials:
|
|
108
118
|
|
|
109
119
|
1. **Static API token (recommended for automation).** A Cloudflare API
|
|
110
|
-
token never expires
|
|
111
|
-
|
|
120
|
+
token never expires and works as the bearer for every server —
|
|
121
|
+
`api`, `bindings`, `builds`, and `observability` all accept it (verified
|
|
122
|
+
against each issuer). Set it once and browser OAuth is never consulted:
|
|
112
123
|
|
|
113
124
|
```jsonc
|
|
114
125
|
{
|
|
@@ -124,12 +135,12 @@ Two levers for longer-lived credentials:
|
|
|
124
135
|
|
|
125
136
|
Create one at dash.cloudflare.com → Manage Account → API Tokens with
|
|
126
137
|
the scopes your agents need (exact template, additions, and account
|
|
127
|
-
scoping in `docs/api-token.md`).
|
|
138
|
+
scoping in `docs/api-token.md`).
|
|
128
139
|
|
|
129
|
-
2. **Re-authenticate surgically.** Browser OAuth is the fallback
|
|
130
|
-
|
|
131
|
-
(a scoped approval returned the standard 1-hour access
|
|
132
|
-
no scope knob — refresh behavior is set server-side.
|
|
140
|
+
2. **Re-authenticate surgically.** Browser OAuth is the fallback when no
|
|
141
|
+
API token is configured. Tested 2026-09-06: the issuers ignore
|
|
142
|
+
`offline_access` (a scoped approval returned the standard 1-hour access
|
|
143
|
+
token), so there is no scope knob — refresh behavior is set server-side.
|
|
133
144
|
|
|
134
145
|
Avoid re-running full setup on a schedule: each fresh approval can rotate
|
|
135
146
|
away tokens other sessions still hold. Re-authenticate single servers with
|
|
@@ -155,13 +166,13 @@ closed on scope). They complement; neither replaces the other.
|
|
|
155
166
|
|
|
156
167
|
## Troubleshooting
|
|
157
168
|
|
|
158
|
-
| Symptom
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
| OAuth tab never opens
|
|
162
|
-
| `401` from one server only
|
|
163
|
-
| Tools missing for a server
|
|
164
|
-
| Rate-limited API calls
|
|
169
|
+
| Symptom | Likely cause | Fix |
|
|
170
|
+
| ------------------------------------------ | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
171
|
+
| Launch warning `<server>: unavailable (…)` | First-run tool discovery failed (offline launch, or a rejected token) | Happens once per server; the next successful launch caches the tools and later sessions connect on first use. `pi-cloudflare-setup --only <server>` fixes a rejected token |
|
|
172
|
+
| OAuth tab never opens | Headless environment or blocked popup | Copy the printed URL into any browser; native Pi tokens land in `~/.pi/cloudflare-tokens.json` |
|
|
173
|
+
| `401` from one server only | That server's refresh token was revoked | The tool error carries the exact recovery command; with an API token configured, check the token's scopes instead |
|
|
174
|
+
| Tools missing for a server | Disabled in native Pi settings | Re-enable it; tools register on next session start |
|
|
175
|
+
| Rate-limited API calls | Too many write calls in a loop | Back off and batch; prefer one `cf_api_execute` with a precise query over paginated scans |
|
|
165
176
|
|
|
166
177
|
## Development
|
|
167
178
|
|
package/dist/config.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ export interface PiCloudflareConfig {
|
|
|
5
5
|
/** Connection timeout per server in milliseconds. */
|
|
6
6
|
connectTimeoutMs?: number;
|
|
7
7
|
/**
|
|
8
|
-
* Static bearer token
|
|
9
|
-
* from ${CLOUDFLARE_API_TOKEN}). Never expires, never needs
|
|
10
|
-
* OAuth
|
|
11
|
-
*
|
|
8
|
+
* Static bearer token applied to every enabled server (e.g. a Cloudflare
|
|
9
|
+
* API token from ${CLOUDFLARE_API_TOKEN}). Never expires, never needs
|
|
10
|
+
* browser OAuth — when set, stored OAuth tokens are never consulted — and
|
|
11
|
+
* takes precedence over stored OAuth tokens.
|
|
12
12
|
*/
|
|
13
13
|
apiToken?: string;
|
|
14
14
|
}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { connectServer } from './client.js';
|
|
1
2
|
import { type PiCloudflareConfig } from './config.js';
|
|
2
3
|
import { type ToolRegistration } from './proxy.js';
|
|
3
4
|
import { type CloudflareServerId } from './servers.js';
|
|
@@ -7,10 +8,14 @@ export interface CloudflareRuntimeOptions {
|
|
|
7
8
|
config?: PiCloudflareConfig;
|
|
8
9
|
/** OAuth token file. Defaults to Pi's legacy ~/.pi/cloudflare-tokens.json for compatibility. */
|
|
9
10
|
tokenFile?: string;
|
|
11
|
+
/** Cached upstream tool lists. Defaults to cloudflare-tools-cache.json beside the token file. */
|
|
12
|
+
toolsCache?: string;
|
|
10
13
|
/** Optional local setup script used in portable re-authentication hints. */
|
|
11
14
|
setupScript?: string;
|
|
12
15
|
/** Warning sink. Native Pi uses console.warn; the stdio server uses stderr. */
|
|
13
16
|
warn?: (message: string) => void;
|
|
17
|
+
/** Connection factory; overridable in tests. */
|
|
18
|
+
connect?: typeof connectServer;
|
|
14
19
|
}
|
|
15
20
|
/** Exact command that re-authorizes one server; shown to agents, never guessed. */
|
|
16
21
|
export declare function reauthHint(serverId: string, options?: {
|
|
@@ -33,18 +38,33 @@ export declare class CloudflareRuntime {
|
|
|
33
38
|
private entries;
|
|
34
39
|
private readonly config;
|
|
35
40
|
private readonly tokenFile;
|
|
41
|
+
private readonly toolsCache;
|
|
36
42
|
private readonly setupScript;
|
|
37
43
|
private readonly warn;
|
|
44
|
+
private readonly connect;
|
|
38
45
|
constructor(options?: CloudflareRuntimeOptions);
|
|
39
46
|
private hint;
|
|
40
47
|
private reconnect;
|
|
41
48
|
/** Refresh unconditionally after a credential rejection, persist, and reconnect. */
|
|
42
49
|
private refreshNow;
|
|
43
|
-
/**
|
|
50
|
+
/** Resolve the bearer for a call: static API token, else OAuth refreshed when expired. */
|
|
44
51
|
private ensureFreshToken;
|
|
45
52
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
53
|
+
* Open the connection lazily on first use; a live connection whose token
|
|
54
|
+
* drifted (rotated by a sibling session) reconnects. After connecting,
|
|
55
|
+
* refresh the tool cache in the background so the next session starts
|
|
56
|
+
* without touching the network.
|
|
57
|
+
*/
|
|
58
|
+
private ensureConnection;
|
|
59
|
+
/** Best-effort cache refresh; never blocks or fails the tool call that triggered it. */
|
|
60
|
+
private refreshCachedTools;
|
|
61
|
+
/** Wrap registrations so the connection (and its auth) opens on first call. */
|
|
62
|
+
private registrationsFor;
|
|
63
|
+
/**
|
|
64
|
+
* Register the cf_* tool surface without touching the network: servers with
|
|
65
|
+
* a cached tool list register instantly and connect on their first tool
|
|
66
|
+
* call. Servers without one — first run only — are discovered eagerly so
|
|
67
|
+
* their tools exist from the very first session.
|
|
48
68
|
*/
|
|
49
69
|
start(): Promise<ToolRegistration[]>;
|
|
50
70
|
stop(): Promise<void>;
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAClE,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEpE,OAAO,EAAyB,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAA;AAOrB,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAA;AAazB,MAAM,WAAW,wBAAwB;IACvC,uGAAuG;IACvG,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,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|
|
|
4
4
|
import { refreshAccessToken } from './oauth.js';
|
|
5
5
|
import { buildAllRegistrations } from './proxy.js';
|
|
6
6
|
import { CLOUDFLARE_SERVERS, } from './servers.js';
|
|
7
|
+
import { readToolCacheAt, toolsCachePathNear, updateToolCacheAt, } from './tool-cache.js';
|
|
7
8
|
import { isExpired, readTokenFileAt, tokenFilePath, writeTokenFileAt, } from './token-store.js';
|
|
8
9
|
function quoteArg(value) {
|
|
9
10
|
return JSON.stringify(value);
|
|
@@ -45,17 +46,28 @@ function syncFromTokenFile(entry, path) {
|
|
|
45
46
|
export function syncFromFile(entry, home) {
|
|
46
47
|
syncFromTokenFile(entry, tokenFilePath(home));
|
|
47
48
|
}
|
|
49
|
+
function cacheableTools(tools) {
|
|
50
|
+
return tools.map((tool) => ({
|
|
51
|
+
name: tool.name,
|
|
52
|
+
description: tool.description,
|
|
53
|
+
inputSchema: tool.inputSchema,
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
48
56
|
export class CloudflareRuntime {
|
|
49
57
|
entries = [];
|
|
50
58
|
config;
|
|
51
59
|
tokenFile;
|
|
60
|
+
toolsCache;
|
|
52
61
|
setupScript;
|
|
53
62
|
warn;
|
|
63
|
+
connect;
|
|
54
64
|
constructor(options = {}) {
|
|
55
65
|
this.config = options.config ?? {};
|
|
56
66
|
this.tokenFile = options.tokenFile ?? tokenFilePath();
|
|
67
|
+
this.toolsCache = options.toolsCache ?? toolsCachePathNear(this.tokenFile);
|
|
57
68
|
this.setupScript = options.setupScript;
|
|
58
69
|
this.warn = options.warn ?? (() => undefined);
|
|
70
|
+
this.connect = options.connect ?? connectServer;
|
|
59
71
|
}
|
|
60
72
|
hint(serverId) {
|
|
61
73
|
return reauthHint(serverId, {
|
|
@@ -66,7 +78,7 @@ export class CloudflareRuntime {
|
|
|
66
78
|
async reconnect(entry) {
|
|
67
79
|
await entry.connection?.close().catch(() => undefined);
|
|
68
80
|
const token = entry.staticToken ?? entry.stored?.accessToken;
|
|
69
|
-
entry.connection = await
|
|
81
|
+
entry.connection = await this.connect(entry.definition, {
|
|
70
82
|
apiToken: token,
|
|
71
83
|
timeoutMs: entry.timeoutMs,
|
|
72
84
|
});
|
|
@@ -89,7 +101,7 @@ export class CloudflareRuntime {
|
|
|
89
101
|
writeTokenFileAt(file.servers, this.tokenFile);
|
|
90
102
|
await this.reconnect(entry);
|
|
91
103
|
}
|
|
92
|
-
/**
|
|
104
|
+
/** Resolve the bearer for a call: static API token, else OAuth refreshed when expired. */
|
|
93
105
|
async ensureFreshToken(entry) {
|
|
94
106
|
if (entry.staticToken)
|
|
95
107
|
return entry.staticToken;
|
|
@@ -97,89 +109,132 @@ export class CloudflareRuntime {
|
|
|
97
109
|
const stored = entry.stored;
|
|
98
110
|
if (!stored)
|
|
99
111
|
return undefined;
|
|
100
|
-
if (!isExpired(stored) || !stored.refreshToken)
|
|
101
|
-
if (!entry.connection || entry.connectedToken !== stored.accessToken) {
|
|
102
|
-
await this.reconnect(entry);
|
|
103
|
-
}
|
|
112
|
+
if (!isExpired(stored) || !stored.refreshToken)
|
|
104
113
|
return stored.accessToken;
|
|
105
|
-
}
|
|
106
114
|
await this.refreshNow(entry);
|
|
107
115
|
return entry.stored?.accessToken;
|
|
108
116
|
}
|
|
109
117
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
118
|
+
* Open the connection lazily on first use; a live connection whose token
|
|
119
|
+
* drifted (rotated by a sibling session) reconnects. After connecting,
|
|
120
|
+
* refresh the tool cache in the background so the next session starts
|
|
121
|
+
* without touching the network.
|
|
122
|
+
*/
|
|
123
|
+
async ensureConnection(entry, warmCache = true) {
|
|
124
|
+
const token = await this.ensureFreshToken(entry);
|
|
125
|
+
if (!entry.connection || entry.connectedToken !== token) {
|
|
126
|
+
await this.reconnect(entry);
|
|
127
|
+
if (warmCache)
|
|
128
|
+
this.refreshCachedTools(entry);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Best-effort cache refresh; never blocks or fails the tool call that triggered it. */
|
|
132
|
+
refreshCachedTools(entry) {
|
|
133
|
+
void entry.connection
|
|
134
|
+
?.listTools()
|
|
135
|
+
.then((tools) => updateToolCacheAt(entry.definition.id, cacheableTools(tools), this.toolsCache))
|
|
136
|
+
.catch(() => undefined);
|
|
137
|
+
}
|
|
138
|
+
/** Wrap registrations so the connection (and its auth) opens on first call. */
|
|
139
|
+
registrationsFor(entry, tools) {
|
|
140
|
+
const registrations = buildAllRegistrations([
|
|
141
|
+
{
|
|
142
|
+
prefix: entry.definition.prefix,
|
|
143
|
+
tools,
|
|
144
|
+
callTool: async (name, params) => {
|
|
145
|
+
if (!entry.connection)
|
|
146
|
+
throw new Error(`${entry.definition.id}: not connected`);
|
|
147
|
+
return entry.connection.callTool(name, params);
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
for (const registration of registrations) {
|
|
152
|
+
const callUpstream = registration.execute;
|
|
153
|
+
registration.execute = async (toolCallId, params, signal) => {
|
|
154
|
+
try {
|
|
155
|
+
await this.ensureConnection(entry);
|
|
156
|
+
return await callUpstream(toolCallId, params, signal);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
160
|
+
if (entry.staticToken) {
|
|
161
|
+
if (isAuthFailure(error)) {
|
|
162
|
+
throw new Error(`${entry.definition.id}: request rejected (${detail}). ` +
|
|
163
|
+
`Check the configured API token (CLOUDFLARE_API_TOKEN) and its scopes.`, { cause: error });
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
if (!isAuthFailure(error))
|
|
168
|
+
throw error;
|
|
169
|
+
if (entry.stored?.refreshToken) {
|
|
170
|
+
try {
|
|
171
|
+
await this.refreshNow(entry);
|
|
172
|
+
return await callUpstream(toolCallId, params, signal);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
/* fall through to the recovery hint */
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
throw new Error(`${entry.definition.id}: request rejected (${detail}). ${this.hint(entry.definition.id)}`, { cause: error });
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return registrations;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Register the cf_* tool surface without touching the network: servers with
|
|
186
|
+
* a cached tool list register instantly and connect on their first tool
|
|
187
|
+
* call. Servers without one — first run only — are discovered eagerly so
|
|
188
|
+
* their tools exist from the very first session.
|
|
112
189
|
*/
|
|
113
190
|
async start() {
|
|
114
191
|
await this.stop();
|
|
115
192
|
const registrations = [];
|
|
116
193
|
const config = resolveConfig(this.config);
|
|
117
194
|
const file = readTokenFileAt(this.tokenFile);
|
|
195
|
+
const cache = readToolCacheAt(this.toolsCache);
|
|
118
196
|
const definitions = CLOUDFLARE_SERVERS.filter((server) => config.enabledServerIds.includes(server.id));
|
|
119
197
|
for (const definition of definitions) {
|
|
198
|
+
// A configured API token is the bearer for every server; OAuth is never consulted.
|
|
120
199
|
const entry = {
|
|
121
200
|
definition,
|
|
122
201
|
timeoutMs: config.connectTimeoutMs,
|
|
123
|
-
staticToken:
|
|
202
|
+
staticToken: this.config.apiToken,
|
|
124
203
|
};
|
|
204
|
+
const cached = cache?.servers[definition.id]?.tools;
|
|
205
|
+
if (cached?.length) {
|
|
206
|
+
registrations.push(...this.registrationsFor(entry, cached));
|
|
207
|
+
this.entries.push(entry);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
125
210
|
try {
|
|
126
211
|
entry.stored = file?.servers[definition.id];
|
|
127
|
-
await this.
|
|
128
|
-
if (!entry.connection)
|
|
129
|
-
await this.reconnect(entry);
|
|
212
|
+
await this.ensureConnection(entry, false);
|
|
130
213
|
const tools = (await entry.connection?.listTools()) ?? [];
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
prefix: definition.prefix,
|
|
134
|
-
tools,
|
|
135
|
-
callTool: async (name, params) => {
|
|
136
|
-
if (!entry.connection)
|
|
137
|
-
throw new Error(`${definition.id}: not connected`);
|
|
138
|
-
return entry.connection.callTool(name, params);
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
]);
|
|
142
|
-
for (const registration of serverRegistrations) {
|
|
143
|
-
registrations.push({
|
|
144
|
-
...registration,
|
|
145
|
-
execute: async (toolCallId, params, signal) => {
|
|
146
|
-
try {
|
|
147
|
-
await this.ensureFreshToken(entry);
|
|
148
|
-
return await registration.execute(toolCallId, params, signal);
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
if (!isAuthFailure(error) || entry.staticToken || !entry.stored?.refreshToken) {
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
await this.refreshNow(entry);
|
|
156
|
-
return await registration.execute(toolCallId, params, signal);
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
160
|
-
throw new Error(`${definition.id}: request rejected (${detail}). ${this.hint(definition.id)}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
}
|
|
214
|
+
updateToolCacheAt(definition.id, cacheableTools(tools), this.toolsCache);
|
|
215
|
+
registrations.push(...this.registrationsFor(entry, cacheableTools(tools)));
|
|
166
216
|
this.entries.push(entry);
|
|
167
217
|
}
|
|
168
218
|
catch (error) {
|
|
169
219
|
this.warn(`${definition.id}: unavailable (${error instanceof Error ? error.message : String(error)}).`);
|
|
170
220
|
if (isAuthFailure(error)) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
221
|
+
if (entry.staticToken) {
|
|
222
|
+
this.warn(`${definition.id}: check the configured API token (CLOUDFLARE_API_TOKEN) and its scopes.`);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const hint = this.hint(definition.id);
|
|
226
|
+
registrations.push({
|
|
227
|
+
name: `${definition.prefix}reauthenticate`,
|
|
228
|
+
label: `${definition.prefix}reauthenticate`,
|
|
229
|
+
description: `${definition.id} is not authenticated. Call this tool for exact re-authentication instructions.`,
|
|
230
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
231
|
+
parameters: Type.Object({}),
|
|
232
|
+
execute: async () => ({
|
|
233
|
+
content: [{ type: 'text', text: hint }],
|
|
234
|
+
}),
|
|
235
|
+
});
|
|
236
|
+
this.warn(hint);
|
|
237
|
+
}
|
|
183
238
|
}
|
|
184
239
|
await entry.connection?.close().catch(() => undefined);
|
|
185
240
|
}
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,aAAa,EAA2B,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAyB,MAAM,YAAY,CAAA;AACzE,OAAO,EACL,kBAAkB,GAGnB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,SAAS,EACT,eAAe,EACf,aAAa,EACb,gBAAgB,GAEjB,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,aAAa,EAA2B,MAAM,aAAa,CAAA;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAE,qBAAqB,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C;6BACxC,CAAC;yBACH,CAAC,CAAA;wBACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;oBACjB,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;YACxD,CAAC;QACH,CAAC;QAED,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAChG,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CloudflareServerId } from './servers.js';
|
|
2
|
+
/** The slice of an upstream tool the proxy registers from. */
|
|
3
|
+
export interface CachedTool {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string | undefined;
|
|
6
|
+
inputSchema: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface ToolCacheEntry {
|
|
9
|
+
capturedAt: number;
|
|
10
|
+
tools: CachedTool[];
|
|
11
|
+
}
|
|
12
|
+
export interface ToolCache {
|
|
13
|
+
version: 1;
|
|
14
|
+
servers: Partial<Record<CloudflareServerId, ToolCacheEntry>>;
|
|
15
|
+
}
|
|
16
|
+
/** Cache lives beside the token file so portable hosts keep theirs in plugin data. */
|
|
17
|
+
export declare function toolsCachePathNear(tokenFile: string): string;
|
|
18
|
+
/** Read cached per-server tool lists. A missing or malformed file means no cache. */
|
|
19
|
+
export declare function readToolCacheAt(path: string): ToolCache | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Persist one server's tool list with an atomic replace so concurrent agent
|
|
22
|
+
* sessions cannot leave a partial file.
|
|
23
|
+
*/
|
|
24
|
+
export declare function updateToolCacheAt(id: CloudflareServerId, tools: CachedTool[], path: string): void;
|
|
25
|
+
//# sourceMappingURL=tool-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cache.d.ts","sourceRoot":"","sources":["../src/tool-cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,CAAC,CAAA;IACV,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAAA;CAC7D;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAoBnE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQjG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
/** Cache lives beside the token file so portable hosts keep theirs in plugin data. */
|
|
4
|
+
export function toolsCachePathNear(tokenFile) {
|
|
5
|
+
return join(dirname(tokenFile), 'cloudflare-tools-cache.json');
|
|
6
|
+
}
|
|
7
|
+
/** Read cached per-server tool lists. A missing or malformed file means no cache. */
|
|
8
|
+
export function readToolCacheAt(path) {
|
|
9
|
+
if (!existsSync(path))
|
|
10
|
+
return undefined;
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
13
|
+
if (parsed?.version !== 1 || typeof parsed.servers !== 'object' || parsed.servers === null) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
for (const entry of Object.values(parsed.servers)) {
|
|
17
|
+
if (!entry ||
|
|
18
|
+
!Array.isArray(entry.tools) ||
|
|
19
|
+
entry.tools.some((tool) => !tool || typeof tool.name !== 'string')) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Persist one server's tool list with an atomic replace so concurrent agent
|
|
31
|
+
* sessions cannot leave a partial file.
|
|
32
|
+
*/
|
|
33
|
+
export function updateToolCacheAt(id, tools, path) {
|
|
34
|
+
if (tools.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
const cache = readToolCacheAt(path) ?? { version: 1, servers: {} };
|
|
37
|
+
cache.servers[id] = { capturedAt: Date.now(), tools };
|
|
38
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
39
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
40
|
+
writeFileSync(tmp, JSON.stringify(cache, null, 2) + '\n');
|
|
41
|
+
renameSync(tmp, path);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=tool-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-cache.js","sourceRoot":"","sources":["../src/tool-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE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AAC,MAAM,KAAK,CAAC;QAAE,OAAM;IAC9B,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAU,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IAC3E,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAA;IACrD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAA;IACxC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;IACzD,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Cloudflare Agent Plugin and native Pi extension providing official skills and cf_-prefixed MCP tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-plugin",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"build": "tsc -p tsconfig.json",
|
|
47
47
|
"format:check": "oxfmt --check .",
|
|
48
48
|
"fmt": "oxfmt .",
|
|
49
|
-
"lint": "oxlint",
|
|
49
|
+
"lint": "oxlint --deny-warnings",
|
|
50
50
|
"perf": "node scripts/performance-audit.mjs",
|
|
51
51
|
"perf:check": "node scripts/performance-audit.mjs --check",
|
|
52
52
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
53
53
|
"prepublishOnly": "npm run build",
|
|
54
|
-
"test": "node --test test/config.test.mjs test/servers.test.mjs test/proxy.test.mjs test/oauth.test.mjs test/token-store.test.mjs test/auth-recovery.test.mjs test/api-token.test.mjs test/result-caps.test.mjs test/plugin.test.mjs",
|
|
54
|
+
"test": "node --test test/config.test.mjs test/servers.test.mjs test/proxy.test.mjs test/oauth.test.mjs test/token-store.test.mjs test/tool-cache.test.mjs test/auth-recovery.test.mjs test/runtime-lazy.test.mjs test/api-token.test.mjs test/result-caps.test.mjs test/plugin.test.mjs",
|
|
55
55
|
"pretest": "npm run build"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/node": "^22.0.0",
|
|
63
|
-
"oxfmt": "^0.
|
|
64
|
-
"oxlint": "^1.
|
|
63
|
+
"oxfmt": "^0.68.0",
|
|
64
|
+
"oxlint": "^1.83.0",
|
|
65
65
|
"typescript": "^6.0.3"
|
|
66
66
|
},
|
|
67
67
|
"engines": {
|
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "pi-cloudflare",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"description": "Cloudflare skills and cf_-prefixed MCP tools, with a native Pi adapter and an Agent Plugins 1.0 portable runtime.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "0xPlayerOne",
|