@zackbart/connecta 0.15.1 → 0.16.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/AGENTS.md +40 -20
- package/CHANGELOG.md +653 -0
- package/README.md +25 -5
- package/bin/connecta.mjs +44 -3
- package/dist/access-tokens.d.ts +0 -1
- package/dist/access-tokens.js +0 -1
- package/dist/activity.d.ts +50 -2
- package/dist/activity.js +34 -1
- package/dist/apps-shell.d.ts +0 -1
- package/dist/apps-shell.js +0 -1
- package/dist/auth/bearer.d.ts +0 -1
- package/dist/auth/bearer.js +0 -1
- package/dist/auth/clerk.d.ts +0 -1
- package/dist/auth/clerk.js +45 -9
- package/dist/auth/downstream-oauth.d.ts +0 -1
- package/dist/auth/downstream-oauth.js +0 -1
- package/dist/call-admission.d.ts +0 -1
- package/dist/call-admission.js +0 -1
- package/dist/catalog-drift.d.ts +99 -0
- package/dist/catalog-drift.js +251 -0
- package/dist/catalog-fingerprint.d.ts +0 -1
- package/dist/catalog-fingerprint.js +0 -1
- package/dist/catalog-limits.d.ts +0 -1
- package/dist/catalog-limits.js +0 -1
- package/dist/catalog-service.d.ts +0 -1
- package/dist/catalog-service.js +41 -5
- package/dist/catalog.d.ts +11 -1
- package/dist/catalog.js +20 -1
- package/dist/concurrency.d.ts +0 -1
- package/dist/concurrency.js +0 -1
- package/dist/connector-scope.d.ts +0 -1
- package/dist/connector-scope.js +0 -1
- package/dist/connectors/api.d.ts +29 -21
- package/dist/connectors/api.js +45 -19
- package/dist/connectors/guarded-fetch.d.ts +106 -0
- package/dist/connectors/guarded-fetch.js +289 -0
- package/dist/connectors/remote-mcp.d.ts +0 -1
- package/dist/connectors/remote-mcp.js +0 -1
- package/dist/credentials.d.ts +0 -1
- package/dist/credentials.js +0 -1
- package/dist/errors.d.ts +30 -3
- package/dist/errors.js +1 -1
- package/dist/execute.d.ts +0 -1
- package/dist/execute.js +0 -1
- package/dist/executor-admission.d.ts +11 -1
- package/dist/executor-admission.js +28 -1
- package/dist/executor-result.d.ts +0 -1
- package/dist/executor-result.js +0 -1
- package/dist/executors/quickjs-child.d.ts +0 -1
- package/dist/executors/quickjs-child.js +0 -1
- package/dist/executors/quickjs-protocol.d.ts +0 -1
- package/dist/executors/quickjs-protocol.js +0 -1
- package/dist/executors/quickjs-runtime.d.ts +0 -1
- package/dist/executors/quickjs-runtime.js +0 -1
- package/dist/executors/quickjs.d.ts +0 -1
- package/dist/executors/quickjs.js +2 -1
- package/dist/favicon.d.ts +0 -1
- package/dist/favicon.js +0 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +24 -7
- package/dist/invocation.d.ts +0 -1
- package/dist/invocation.js +0 -1
- package/dist/json-schema.d.ts +0 -1
- package/dist/json-schema.js +0 -1
- package/dist/mcp-result.d.ts +0 -1
- package/dist/mcp-result.js +0 -1
- package/dist/meta-tools.d.ts +0 -1
- package/dist/meta-tools.js +0 -1
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -1
- package/dist/operator-ui/generated.d.ts +2 -3
- package/dist/operator-ui/generated.js +3 -4
- package/dist/operator-ui/model.d.ts +10 -1
- package/dist/operator-ui/model.js +0 -1
- package/dist/operator-ui/view.d.ts +167 -0
- package/dist/operator-ui/view.js +270 -0
- package/dist/providers/cloudflare.d.ts +0 -1
- package/dist/providers/cloudflare.js +261 -299
- package/dist/providers/linear.d.ts +26 -5
- package/dist/providers/linear.js +32 -61
- package/dist/providers/mixpanel.d.ts +35 -4
- package/dist/providers/mixpanel.js +53 -79
- package/dist/providers/notion.d.ts +0 -1
- package/dist/providers/notion.js +87 -42
- package/dist/providers/stripe.d.ts +13 -1
- package/dist/providers/stripe.js +31 -60
- package/dist/registry.d.ts +34 -2
- package/dist/registry.js +85 -5
- package/dist/retired-toolkits.d.ts +0 -1
- package/dist/retired-toolkits.js +0 -1
- package/dist/routes/access-tokens.d.ts +0 -1
- package/dist/routes/access-tokens.js +0 -1
- package/dist/routes/activity.d.ts +0 -1
- package/dist/routes/activity.js +0 -1
- package/dist/routes/credentials.d.ts +0 -1
- package/dist/routes/credentials.js +0 -1
- package/dist/routes/mcp.d.ts +0 -1
- package/dist/routes/mcp.js +0 -1
- package/dist/routes/oauth.d.ts +0 -1
- package/dist/routes/oauth.js +0 -1
- package/dist/routes/shared.d.ts +2 -1
- package/dist/routes/shared.js +0 -1
- package/dist/routes/ui.d.ts +0 -1
- package/dist/routes/ui.js +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +11 -1
- package/dist/skills.d.ts +0 -1
- package/dist/skills.js +0 -1
- package/dist/storage/file.d.ts +0 -1
- package/dist/storage/file.js +0 -1
- package/dist/storage/memory.d.ts +0 -1
- package/dist/storage/memory.js +0 -1
- package/dist/timeout.d.ts +0 -1
- package/dist/timeout.js +0 -1
- package/dist/tool-safety.d.ts +0 -1
- package/dist/tool-safety.js +0 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.js +0 -1
- package/dist/ui.d.ts +0 -1
- package/dist/ui.js +13 -137
- package/dist/validate.d.ts +13 -15
- package/dist/validate.js +24 -11
- package/dist/version.d.ts +1 -2
- package/dist/version.js +1 -2
- package/documentation/architecture.md +186 -5
- package/documentation/auth.md +11 -0
- package/documentation/call-admission.md +142 -6
- package/documentation/cloudflare.md +92 -10
- package/documentation/code-first-exploration.md +2 -2
- package/documentation/code-mode.md +14 -14
- package/documentation/connector-guides.md +172 -5
- package/documentation/connectors.md +89 -0
- package/documentation/linear.md +20 -2
- package/documentation/mcp-ui-design.md +2 -2
- package/documentation/meta-tools.md +7 -1
- package/documentation/mixpanel.md +42 -9
- package/documentation/notion.md +23 -2
- package/documentation/operations.md +325 -5
- package/documentation/operator-ui.md +120 -5
- package/documentation/provider-audit.md +160 -0
- package/documentation/provider-conventions.md +667 -0
- package/documentation/request-admission.md +167 -5
- package/documentation/rich-output-design.md +1 -2
- package/documentation/stripe.md +15 -0
- package/documentation/upgrading.md +454 -0
- package/ethos.md +14 -9
- package/examples/worker/README.md +102 -12
- package/examples/worker/src/index.ts +46 -1
- package/examples/worker/wrangler.jsonc +14 -1
- package/package.json +10 -6
- package/templates/node/.dockerignore +10 -0
- package/templates/node/.env.example +40 -3
- package/templates/node/AGENTS.md +16 -1
- package/templates/node/Dockerfile +49 -0
- package/templates/node/README.md +117 -2
- package/templates/node/docker-compose.yml +39 -0
- package/templates/node/package.json +1 -1
- package/templates/node/src/file-activity.ts +182 -0
- package/templates/node/src/index.ts +80 -4
- package/assets/connecta-clay-hero.png +0 -0
- package/dist/access-tokens.d.ts.map +0 -1
- package/dist/access-tokens.js.map +0 -1
- package/dist/activity.d.ts.map +0 -1
- package/dist/activity.js.map +0 -1
- package/dist/apps-shell.d.ts.map +0 -1
- package/dist/apps-shell.js.map +0 -1
- package/dist/auth/bearer.d.ts.map +0 -1
- package/dist/auth/bearer.js.map +0 -1
- package/dist/auth/clerk.d.ts.map +0 -1
- package/dist/auth/clerk.js.map +0 -1
- package/dist/auth/downstream-oauth.d.ts.map +0 -1
- package/dist/auth/downstream-oauth.js.map +0 -1
- package/dist/call-admission.d.ts.map +0 -1
- package/dist/call-admission.js.map +0 -1
- package/dist/catalog-fingerprint.d.ts.map +0 -1
- package/dist/catalog-fingerprint.js.map +0 -1
- package/dist/catalog-limits.d.ts.map +0 -1
- package/dist/catalog-limits.js.map +0 -1
- package/dist/catalog-service.d.ts.map +0 -1
- package/dist/catalog-service.js.map +0 -1
- package/dist/catalog.d.ts.map +0 -1
- package/dist/catalog.js.map +0 -1
- package/dist/concurrency.d.ts.map +0 -1
- package/dist/concurrency.js.map +0 -1
- package/dist/connector-scope.d.ts.map +0 -1
- package/dist/connector-scope.js.map +0 -1
- package/dist/connectors/api.d.ts.map +0 -1
- package/dist/connectors/api.js.map +0 -1
- package/dist/connectors/remote-mcp.d.ts.map +0 -1
- package/dist/connectors/remote-mcp.js.map +0 -1
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/execute.d.ts.map +0 -1
- package/dist/execute.js.map +0 -1
- package/dist/executor-admission.d.ts.map +0 -1
- package/dist/executor-admission.js.map +0 -1
- package/dist/executor-result.d.ts.map +0 -1
- package/dist/executor-result.js.map +0 -1
- package/dist/executors/quickjs-child.d.ts.map +0 -1
- package/dist/executors/quickjs-child.js.map +0 -1
- package/dist/executors/quickjs-protocol.d.ts.map +0 -1
- package/dist/executors/quickjs-protocol.js.map +0 -1
- package/dist/executors/quickjs-runtime.d.ts.map +0 -1
- package/dist/executors/quickjs-runtime.js.map +0 -1
- package/dist/executors/quickjs.d.ts.map +0 -1
- package/dist/executors/quickjs.js.map +0 -1
- package/dist/favicon.d.ts.map +0 -1
- package/dist/favicon.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/invocation.d.ts.map +0 -1
- package/dist/invocation.js.map +0 -1
- package/dist/json-schema.d.ts.map +0 -1
- package/dist/json-schema.js.map +0 -1
- package/dist/mcp-result.d.ts.map +0 -1
- package/dist/mcp-result.js.map +0 -1
- package/dist/meta-tools.d.ts.map +0 -1
- package/dist/meta-tools.js.map +0 -1
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js.map +0 -1
- package/dist/operator-ui/generated.d.ts.map +0 -1
- package/dist/operator-ui/generated.js.map +0 -1
- package/dist/operator-ui/model.d.ts.map +0 -1
- package/dist/operator-ui/model.js.map +0 -1
- package/dist/providers/cloudflare.d.ts.map +0 -1
- package/dist/providers/cloudflare.js.map +0 -1
- package/dist/providers/linear.d.ts.map +0 -1
- package/dist/providers/linear.js.map +0 -1
- package/dist/providers/mixpanel.d.ts.map +0 -1
- package/dist/providers/mixpanel.js.map +0 -1
- package/dist/providers/notion.d.ts.map +0 -1
- package/dist/providers/notion.js.map +0 -1
- package/dist/providers/stripe.d.ts.map +0 -1
- package/dist/providers/stripe.js.map +0 -1
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js.map +0 -1
- package/dist/retired-toolkits.d.ts.map +0 -1
- package/dist/retired-toolkits.js.map +0 -1
- package/dist/routes/access-tokens.d.ts.map +0 -1
- package/dist/routes/access-tokens.js.map +0 -1
- package/dist/routes/activity.d.ts.map +0 -1
- package/dist/routes/activity.js.map +0 -1
- package/dist/routes/credentials.d.ts.map +0 -1
- package/dist/routes/credentials.js.map +0 -1
- package/dist/routes/mcp.d.ts.map +0 -1
- package/dist/routes/mcp.js.map +0 -1
- package/dist/routes/oauth.d.ts.map +0 -1
- package/dist/routes/oauth.js.map +0 -1
- package/dist/routes/shared.d.ts.map +0 -1
- package/dist/routes/shared.js.map +0 -1
- package/dist/routes/ui.d.ts.map +0 -1
- package/dist/routes/ui.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/skills.d.ts.map +0 -1
- package/dist/skills.js.map +0 -1
- package/dist/storage/file.d.ts.map +0 -1
- package/dist/storage/file.js.map +0 -1
- package/dist/storage/memory.d.ts.map +0 -1
- package/dist/storage/memory.js.map +0 -1
- package/dist/timeout.d.ts.map +0 -1
- package/dist/timeout.js.map +0 -1
- package/dist/tool-safety.d.ts.map +0 -1
- package/dist/tool-safety.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/validate.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
- package/examples/node/README.md +0 -52
- package/examples/node/src/index.ts +0 -71
- package/src/access-tokens.ts +0 -289
- package/src/activity.ts +0 -234
- package/src/apps-shell.ts +0 -370
- package/src/auth/bearer.ts +0 -61
- package/src/auth/clerk.ts +0 -553
- package/src/auth/downstream-oauth.ts +0 -575
- package/src/call-admission.ts +0 -521
- package/src/catalog-fingerprint.ts +0 -52
- package/src/catalog-limits.ts +0 -11
- package/src/catalog-service.ts +0 -1153
- package/src/catalog.ts +0 -790
- package/src/concurrency.ts +0 -39
- package/src/connector-scope.ts +0 -66
- package/src/connectors/api.ts +0 -159
- package/src/connectors/remote-mcp.ts +0 -1090
- package/src/credentials.ts +0 -428
- package/src/errors.ts +0 -364
- package/src/execute.ts +0 -1406
- package/src/executor-admission.ts +0 -328
- package/src/executor-result.ts +0 -107
- package/src/executors/quickjs-child.ts +0 -172
- package/src/executors/quickjs-protocol.ts +0 -99
- package/src/executors/quickjs-runtime.ts +0 -470
- package/src/executors/quickjs.ts +0 -776
- package/src/favicon.ts +0 -53
- package/src/index.ts +0 -666
- package/src/invocation.ts +0 -655
- package/src/json-schema.ts +0 -11
- package/src/mcp-result.ts +0 -43
- package/src/meta-tools.ts +0 -1607
- package/src/node.ts +0 -206
- package/src/operator-ui/browser.css +0 -423
- package/src/operator-ui/browser.ts +0 -1281
- package/src/operator-ui/generated.ts +0 -4
- package/src/operator-ui/model.ts +0 -111
- package/src/providers/cloudflare.ts +0 -3999
- package/src/providers/linear.ts +0 -302
- package/src/providers/mixpanel.ts +0 -229
- package/src/providers/notion.ts +0 -1879
- package/src/providers/stripe.ts +0 -307
- package/src/registry.ts +0 -1085
- package/src/retired-toolkits.ts +0 -14
- package/src/routes/access-tokens.ts +0 -115
- package/src/routes/activity.ts +0 -215
- package/src/routes/credentials.ts +0 -254
- package/src/routes/mcp.ts +0 -429
- package/src/routes/oauth.ts +0 -322
- package/src/routes/shared.ts +0 -247
- package/src/routes/ui.ts +0 -152
- package/src/server.ts +0 -195
- package/src/skills.ts +0 -271
- package/src/storage/file.ts +0 -123
- package/src/storage/memory.ts +0 -44
- package/src/timeout.ts +0 -84
- package/src/tool-safety.ts +0 -15
- package/src/types.ts +0 -523
- package/src/ui.ts +0 -744
- package/src/validate.ts +0 -387
- package/src/version.ts +0 -7
package/src/storage/file.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chmodSync,
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
renameSync,
|
|
7
|
-
writeFileSync,
|
|
8
|
-
} from "node:fs";
|
|
9
|
-
import { dirname } from "node:path";
|
|
10
|
-
import type { KVStorage, Logger } from "../types.js";
|
|
11
|
-
|
|
12
|
-
interface Entry {
|
|
13
|
-
value: string;
|
|
14
|
-
exp?: number; // epoch ms
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface FileStorageOptions {
|
|
18
|
-
/** Destination for the corrupt-state-file recovery report. Default console. */
|
|
19
|
-
logger?: Logger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* JSON-file-backed KVStorage for Node. Loads once, persists on every write via
|
|
24
|
-
* a temp-file + rename (atomic-ish). Only reachable via the "@zackbart/connecta/node"
|
|
25
|
-
* subpath so the main entry stays Workers-clean.
|
|
26
|
-
*/
|
|
27
|
-
export function fileStorage(
|
|
28
|
-
path: string,
|
|
29
|
-
opts: FileStorageOptions = {},
|
|
30
|
-
): KVStorage {
|
|
31
|
-
const logger: Logger = opts.logger ?? console;
|
|
32
|
-
// The state file holds downstream OAuth access/refresh tokens in cleartext,
|
|
33
|
-
// so keep it owner-only. Repair is best-effort: chmod is a no-op or throws on
|
|
34
|
-
// non-POSIX filesystems, and a loose mode must never keep the store from
|
|
35
|
-
// starting.
|
|
36
|
-
const tighten = () => {
|
|
37
|
-
try {
|
|
38
|
-
chmodSync(path, 0o600);
|
|
39
|
-
} catch {
|
|
40
|
-
// Non-POSIX filesystem or a race on the file — leave the mode as-is.
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
let data: Record<string, Entry> = {};
|
|
44
|
-
if (existsSync(path)) {
|
|
45
|
-
tighten();
|
|
46
|
-
try {
|
|
47
|
-
data = JSON.parse(readFileSync(path, "utf8")) as Record<string, Entry>;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
// Never let a damaged state file be silently replaced by an empty one:
|
|
50
|
-
// the next set() would persist {} over irreplaceable downstream OAuth
|
|
51
|
-
// tokens and credential-vault entries. Quarantine the bytes so they
|
|
52
|
-
// survive for manual recovery, and refuse to start if even that fails —
|
|
53
|
-
// losing the file loudly beats losing it quietly.
|
|
54
|
-
const quarantine = `${path}.corrupt-${Date.now()}`;
|
|
55
|
-
try {
|
|
56
|
-
renameSync(path, quarantine);
|
|
57
|
-
} catch (renameError) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`[connecta] state file ${path} is not valid JSON and could not be ` +
|
|
60
|
-
`moved aside (${String(renameError)}). Refusing to start rather ` +
|
|
61
|
-
`than overwrite it. Move or repair the file, then restart.`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
logger.error(
|
|
65
|
-
`[connecta] state file ${path} is not valid JSON ` +
|
|
66
|
-
`(${error instanceof Error ? error.message : String(error)}) — ` +
|
|
67
|
-
`moved to ${quarantine}, starting from empty state. Downstream ` +
|
|
68
|
-
`OAuth connectors must be re-authorized and stored credentials ` +
|
|
69
|
-
`re-entered.`,
|
|
70
|
-
);
|
|
71
|
-
data = {};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const persist = () => {
|
|
75
|
-
// Physical expiry rides on an operation that was already going to write.
|
|
76
|
-
// A read must not flush this instance's load-once snapshot: another live
|
|
77
|
-
// instance may have written newer unrelated values since we loaded it.
|
|
78
|
-
const now = Date.now();
|
|
79
|
-
for (const [key, entry] of Object.entries(data)) {
|
|
80
|
-
if (entry.exp && now > entry.exp) delete data[key];
|
|
81
|
-
}
|
|
82
|
-
const dir = dirname(path);
|
|
83
|
-
if (dir) mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
84
|
-
const tmp = `${path}.tmp`;
|
|
85
|
-
// 0o600 on the tmp file; the atomic rename below preserves it, so the live
|
|
86
|
-
// state file is never briefly world-readable.
|
|
87
|
-
writeFileSync(tmp, JSON.stringify(data), { mode: 0o600 });
|
|
88
|
-
renameSync(tmp, path);
|
|
89
|
-
tighten();
|
|
90
|
-
};
|
|
91
|
-
const fresh = (key: string): Entry | null => {
|
|
92
|
-
const e = data[key];
|
|
93
|
-
if (!e) return null;
|
|
94
|
-
if (e.exp && Date.now() > e.exp) {
|
|
95
|
-
delete data[key];
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
return e;
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
async get(key) {
|
|
102
|
-
return fresh(key)?.value ?? null;
|
|
103
|
-
},
|
|
104
|
-
async set(key, value, opts) {
|
|
105
|
-
data[key] = {
|
|
106
|
-
value,
|
|
107
|
-
...(opts?.ttlSeconds
|
|
108
|
-
? { exp: Date.now() + opts.ttlSeconds * 1000 }
|
|
109
|
-
: {}),
|
|
110
|
-
};
|
|
111
|
-
persist();
|
|
112
|
-
},
|
|
113
|
-
async delete(key) {
|
|
114
|
-
delete data[key];
|
|
115
|
-
persist();
|
|
116
|
-
},
|
|
117
|
-
async list(prefix) {
|
|
118
|
-
return Object.keys(data)
|
|
119
|
-
.filter((key) => Boolean(fresh(key)) && key.startsWith(prefix))
|
|
120
|
-
.sort();
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
package/src/storage/memory.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { KVStorage } from "../types.js";
|
|
2
|
-
|
|
3
|
-
interface Entry {
|
|
4
|
-
value: string;
|
|
5
|
-
exp?: number; // epoch ms
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** In-memory KV store with expiry. The default for dev and Node. */
|
|
9
|
-
export function memoryStorage(): KVStorage {
|
|
10
|
-
const map = new Map<string, Entry>();
|
|
11
|
-
const fresh = (key: string): Entry | null => {
|
|
12
|
-
const e = map.get(key);
|
|
13
|
-
if (!e) return null;
|
|
14
|
-
if (e.exp && Date.now() > e.exp) {
|
|
15
|
-
map.delete(key);
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return e;
|
|
19
|
-
};
|
|
20
|
-
return {
|
|
21
|
-
async get(key) {
|
|
22
|
-
return fresh(key)?.value ?? null;
|
|
23
|
-
},
|
|
24
|
-
async set(key, value, opts) {
|
|
25
|
-
map.set(key, {
|
|
26
|
-
value,
|
|
27
|
-
...(opts?.ttlSeconds
|
|
28
|
-
? { exp: Date.now() + opts.ttlSeconds * 1000 }
|
|
29
|
-
: {}),
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
async delete(key) {
|
|
33
|
-
map.delete(key);
|
|
34
|
-
},
|
|
35
|
-
async list(prefix) {
|
|
36
|
-
return [...map.keys()]
|
|
37
|
-
.filter((key) => {
|
|
38
|
-
fresh(key);
|
|
39
|
-
return key.startsWith(prefix) && map.has(key);
|
|
40
|
-
})
|
|
41
|
-
.sort();
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
package/src/timeout.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// The deadline vocabulary shared by downstream discovery probes and tool calls.
|
|
2
|
-
// One definition keeps those waits bounded consistently.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generous default bound for a single downstream probe/catalog call. High enough
|
|
6
|
-
* to trip only on a pathological hang, not a realistically slow probe.
|
|
7
|
-
*/
|
|
8
|
-
export const DEFAULT_PROBE_TIMEOUT_MS = 30_000;
|
|
9
|
-
|
|
10
|
-
/** A finite, positive integer number of milliseconds, or undefined. */
|
|
11
|
-
export function normalizeTimeoutMs(
|
|
12
|
-
value: number | undefined,
|
|
13
|
-
): number | undefined {
|
|
14
|
-
if (value === undefined || !Number.isFinite(value) || !(value > 0)) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return Math.max(1, Math.trunc(value));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Reject `promise` after `ms` if it has not settled, so one hung downstream
|
|
22
|
-
* cannot stall a whole fan-out. This form bounds only the caller-facing wait;
|
|
23
|
-
* use `withAbortableTimeout` when the operation accepts an AbortSignal and the
|
|
24
|
-
* underlying work must stop too.
|
|
25
|
-
*/
|
|
26
|
-
export function withTimeout<T>(
|
|
27
|
-
promise: Promise<T>,
|
|
28
|
-
ms: number,
|
|
29
|
-
label: string,
|
|
30
|
-
): Promise<T> {
|
|
31
|
-
return new Promise<T>((resolve, reject) => {
|
|
32
|
-
const timer = setTimeout(() => {
|
|
33
|
-
reject(new Error(`${label} timed out after ${ms}ms`));
|
|
34
|
-
}, ms);
|
|
35
|
-
promise.then(
|
|
36
|
-
(value) => {
|
|
37
|
-
clearTimeout(timer);
|
|
38
|
-
resolve(value);
|
|
39
|
-
},
|
|
40
|
-
(err) => {
|
|
41
|
-
clearTimeout(timer);
|
|
42
|
-
reject(err);
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Give one operation a caller-facing deadline and the matching cancellation
|
|
50
|
-
* signal. The timeout rejects with the stable, labelled error while aborting
|
|
51
|
-
* any in-flight work that honors the signal.
|
|
52
|
-
*/
|
|
53
|
-
export function withAbortableTimeout<T>(
|
|
54
|
-
operation: (signal: AbortSignal) => Promise<T>,
|
|
55
|
-
ms: number,
|
|
56
|
-
label: string,
|
|
57
|
-
): Promise<T> {
|
|
58
|
-
const controller = new AbortController();
|
|
59
|
-
return new Promise<T>((resolve, reject) => {
|
|
60
|
-
const timeoutError = new Error(`${label} timed out after ${ms}ms`);
|
|
61
|
-
const timer = setTimeout(() => {
|
|
62
|
-
controller.abort(timeoutError);
|
|
63
|
-
reject(timeoutError);
|
|
64
|
-
}, ms);
|
|
65
|
-
let promise: Promise<T>;
|
|
66
|
-
try {
|
|
67
|
-
promise = operation(controller.signal);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
clearTimeout(timer);
|
|
70
|
-
reject(err);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
promise.then(
|
|
74
|
-
(value) => {
|
|
75
|
-
clearTimeout(timer);
|
|
76
|
-
resolve(value);
|
|
77
|
-
},
|
|
78
|
-
(err) => {
|
|
79
|
-
clearTimeout(timer);
|
|
80
|
-
reject(err);
|
|
81
|
-
},
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
}
|
package/src/tool-safety.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ToolDef } from "./types.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The one fail-closed classification shared by discovery and invocation.
|
|
5
|
-
*
|
|
6
|
-
* A tool is read-only only when it says so without also saying it is
|
|
7
|
-
* destructive. Missing, false, and contradictory annotations all require the
|
|
8
|
-
* approval-visible call path.
|
|
9
|
-
*/
|
|
10
|
-
export function isExplicitlyReadOnly(definition: ToolDef): boolean {
|
|
11
|
-
return (
|
|
12
|
-
definition.annotations?.readOnlyHint === true &&
|
|
13
|
-
definition.annotations?.destructiveHint !== true
|
|
14
|
-
);
|
|
15
|
-
}
|