@zackbart/connecta 0.4.0 → 0.5.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +252 -0
  2. package/README.md +72 -17
  3. package/SECURITY.md +10 -6
  4. package/dist/activity.d.ts +8 -0
  5. package/dist/activity.d.ts.map +1 -1
  6. package/dist/activity.js +1 -0
  7. package/dist/activity.js.map +1 -1
  8. package/dist/connectors/api.d.ts +23 -0
  9. package/dist/connectors/api.d.ts.map +1 -1
  10. package/dist/connectors/api.js +13 -1
  11. package/dist/connectors/api.js.map +1 -1
  12. package/dist/connectors/remote-mcp.d.ts +27 -1
  13. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  14. package/dist/connectors/remote-mcp.js +31 -0
  15. package/dist/connectors/remote-mcp.js.map +1 -1
  16. package/dist/credentials.d.ts +2 -1
  17. package/dist/credentials.d.ts.map +1 -1
  18. package/dist/credentials.js +4 -2
  19. package/dist/credentials.js.map +1 -1
  20. package/dist/execute.d.ts +4 -4
  21. package/dist/execute.d.ts.map +1 -1
  22. package/dist/execute.js.map +1 -1
  23. package/dist/executors/quickjs.d.ts.map +1 -1
  24. package/dist/executors/quickjs.js +32 -4
  25. package/dist/executors/quickjs.js.map +1 -1
  26. package/dist/index.d.ts +51 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +67 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/meta-tools.d.ts +25 -4
  31. package/dist/meta-tools.d.ts.map +1 -1
  32. package/dist/meta-tools.js +138 -24
  33. package/dist/meta-tools.js.map +1 -1
  34. package/dist/registry.d.ts +183 -2
  35. package/dist/registry.d.ts.map +1 -1
  36. package/dist/registry.js +293 -27
  37. package/dist/registry.js.map +1 -1
  38. package/dist/server.d.ts +9 -1
  39. package/dist/server.d.ts.map +1 -1
  40. package/dist/server.js +96 -12
  41. package/dist/server.js.map +1 -1
  42. package/dist/skills.d.ts +52 -1
  43. package/dist/skills.d.ts.map +1 -1
  44. package/dist/skills.js +161 -1
  45. package/dist/skills.js.map +1 -1
  46. package/dist/storage/file.d.ts.map +1 -1
  47. package/dist/storage/file.js +19 -3
  48. package/dist/storage/file.js.map +1 -1
  49. package/dist/toolkits.d.ts +44 -0
  50. package/dist/toolkits.d.ts.map +1 -0
  51. package/dist/toolkits.js +134 -0
  52. package/dist/toolkits.js.map +1 -0
  53. package/dist/types.d.ts +20 -1
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/ui.d.ts +29 -1
  56. package/dist/ui.d.ts.map +1 -1
  57. package/dist/ui.js +100 -15
  58. package/dist/ui.js.map +1 -1
  59. package/dist/validate.d.ts +33 -1
  60. package/dist/validate.d.ts.map +1 -1
  61. package/dist/validate.js +32 -2
  62. package/dist/validate.js.map +1 -1
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.js +1 -1
  65. package/package.json +5 -2
  66. package/src/activity.ts +9 -0
  67. package/src/connectors/api.ts +36 -1
  68. package/src/connectors/remote-mcp.ts +67 -0
  69. package/src/credentials.ts +6 -3
  70. package/src/execute.ts +4 -4
  71. package/src/executors/quickjs.ts +32 -4
  72. package/src/index.ts +141 -2
  73. package/src/meta-tools.ts +215 -40
  74. package/src/registry.ts +416 -29
  75. package/src/server.ts +130 -12
  76. package/src/skills.ts +184 -1
  77. package/src/storage/file.ts +18 -2
  78. package/src/toolkits.ts +215 -0
  79. package/src/types.ts +20 -1
  80. package/src/ui.ts +103 -14
  81. package/src/validate.ts +60 -2
  82. package/src/version.ts +1 -1
@@ -1,5 +1,36 @@
1
1
  import type { Connector, ConnectorContext, ConnectorStatus, KVStorage, Logger, ToolDef } from "./types.js";
2
2
  import type { CredentialVault } from "./credentials.js";
3
+ import { type Toolkit } from "./toolkits.js";
4
+ export declare const DEFAULT_MAX_RESULT_BYTES = 50000;
5
+ /**
6
+ * Smallest accepted inline-result cap. One byte is pathological but harmless:
7
+ * `alignEndToCharBoundary` widens a window narrower than the codepoint at the
8
+ * offset, so even a 1-byte cap still truncates sanely and still pages. Caps
9
+ * that small already ship in the test suite (4 and 5), so the floor is placed
10
+ * where it excludes only values that are *broken* rather than merely tiny.
11
+ */
12
+ export declare const MIN_MAX_RESULT_BYTES = 1;
13
+ /**
14
+ * The one definition of a usable `maxResultBytes`: a finite whole number of at
15
+ * least {@link MIN_MAX_RESULT_BYTES} bytes. Shared by all three intake points
16
+ * — deployment config, the per-connector override, and `get_result`'s
17
+ * `maxBytes` argument — so a value that is valid at one is valid at all.
18
+ *
19
+ * Everything else is rejected rather than coerced, because each rejected shape
20
+ * silently does something *worse* than the default: `0`/`NaN` serve an empty
21
+ * head (`slice(0, 0)`) and make paging fail to advance, negatives serve a
22
+ * LARGER head than asked for (`slice(0, -1)` counts from the end) while still
23
+ * claiming truncation, and `Infinity` disables the guard with no notice.
24
+ */
25
+ export declare function isValidMaxResultBytes(value: number): boolean;
26
+ /**
27
+ * Resolve a configured cap against the value it inherits, dropping anything
28
+ * `isValidMaxResultBytes` rejects. Operator-facing surfaces pair this with a
29
+ * startup warning (see `Registry.checkResultCaps`) so the fallback is never
30
+ * silent; the resolution itself stays total so no call site has to cope with
31
+ * a broken cap.
32
+ */
33
+ export declare function resolveMaxResultBytes(value: number | undefined, inherited: number): number;
3
34
  export interface HealthObservation {
4
35
  lastSuccessAt?: string;
5
36
  lastFailureAt?: string;
@@ -7,6 +38,23 @@ export interface HealthObservation {
7
38
  consecutiveFailures: number;
8
39
  lastError?: string;
9
40
  }
41
+ /**
42
+ * Recent real-call outcomes per connector, as observed by ONE view.
43
+ *
44
+ * The deployment keeps one log, and each toolkit keeps its own. That split is a
45
+ * scope boundary, not bookkeeping: `lastError` is a downstream error string
46
+ * that routinely names the tool that failed, and `list_connectors` returns the
47
+ * observation verbatim. Sharing one log would let a toolkit read back the tools
48
+ * and failures of a sibling toolkit through a connector they happen to share —
49
+ * and let a sibling's failures flip this view's reported status. A scoped view
50
+ * reads back only the calls it made itself.
51
+ */
52
+ export declare class HealthLog {
53
+ private readonly observations;
54
+ recordSuccess(id: string, latencyMs: number): void;
55
+ recordFailure(id: string, latencyMs: number, error: unknown): void;
56
+ get(id: string): HealthObservation | undefined;
57
+ }
10
58
  export interface RegistryOptions {
11
59
  storage: KVStorage;
12
60
  logger: Logger;
@@ -14,19 +62,60 @@ export interface RegistryOptions {
14
62
  toolCacheTtlSeconds?: number;
15
63
  persistToolCatalog?: boolean;
16
64
  toolCatalogStaleSeconds?: number;
17
- /** Cap on inline result size before truncation + get_result paging. Default 50_000. */
65
+ /**
66
+ * Cap on inline result size before truncation + get_result paging. Must be a
67
+ * whole number of bytes >= 1; anything else warns at startup and falls back
68
+ * to the default 50_000.
69
+ */
18
70
  maxResultBytes?: number;
19
71
  }
72
+ /**
73
+ * The registry surface a per-connection MCP server consumes: every meta-tool
74
+ * (`src/meta-tools.ts`) and the `execute_code` sandbox bridge (`src/execute.ts`)
75
+ * is typed against THIS, never against the concrete `Registry`.
76
+ *
77
+ * That indirection is the toolkit boundary (issue #22): a scoped connection is
78
+ * handed a `ScopedRegistry` instead of the registry, and every meta-tool
79
+ * inherits the scope from one place. Reaching for a registry method that isn't
80
+ * here is a compile error, and adding one here is a compile error until
81
+ * `ScopedRegistry` filters it — so a new meta-tool cannot quietly step around
82
+ * the boundary.
83
+ */
84
+ export interface RegistryView {
85
+ /** Deployment-wide result-size cap threaded to the meta-tools. */
86
+ readonly maxResultBytes: number;
87
+ listConnectors(): Connector[];
88
+ getConnector(id: string): Connector | undefined;
89
+ resolveAddress(address: string): {
90
+ connector: Connector;
91
+ toolName: string;
92
+ } | null;
93
+ getTools(id: string, baseUrl: string, requestScope?: object): Promise<ToolDef[]>;
94
+ refreshTools(id: string, baseUrl: string, requestScope?: object): Promise<ToolDef[]>;
95
+ peekTools(id: string): ToolDef[] | undefined;
96
+ contextFor(id: string, baseUrl: string, requestScope?: object, callOptions?: {
97
+ signal?: AbortSignal;
98
+ timeoutMs?: number;
99
+ }): ConnectorContext;
100
+ resultsStorage(): KVStorage;
101
+ recordSuccess(id: string, latencyMs: number): void;
102
+ recordFailure(id: string, latencyMs: number, error: unknown): void;
103
+ healthFor(id: string): HealthObservation | undefined;
104
+ hasObservedSuccess(id: string): boolean;
105
+ statusFor(id: string, baseUrl: string, requestScope?: object): Promise<ConnectorStatus>;
106
+ invalidateStored(id: string): Promise<void>;
107
+ }
20
108
  /**
21
109
  * Holds the connector set, resolves addresses, and caches per-connector tool
22
110
  * lists in memory with a TTL. Connector failures are isolated: a broken
23
111
  * connector surfaces status "error"; the rest keep working.
24
112
  */
25
- export declare class Registry {
113
+ export declare class Registry implements RegistryView {
26
114
  private readonly opts;
27
115
  private readonly connectors;
28
116
  private readonly cache;
29
117
  private readonly invalidated;
118
+ /** Deployment-wide observations — every call, whatever view made it. */
30
119
  private readonly health;
31
120
  private readonly ttlMs;
32
121
  private readonly staleMs;
@@ -34,6 +123,15 @@ export declare class Registry {
34
123
  /** Result-size guard cap threaded to the meta-tools. */
35
124
  readonly maxResultBytes: number;
36
125
  constructor(connectors: Connector[], opts: RegistryOptions);
126
+ /**
127
+ * Warn once per unusable result cap, at construction time — the same
128
+ * "runs fine but is surely unintended" channel as the insecure-config
129
+ * warnings in `createConnecta`. A rejected cap can't be honoured, and
130
+ * honouring it *approximately* is exactly the inversion issue #32 is about,
131
+ * so the value is dropped in favour of what it inherits and the operator is
132
+ * told which one is actually in force.
133
+ */
134
+ private checkResultCaps;
37
135
  /**
38
136
  * Warn once per convention violation at construction time. Static only —
39
137
  * never calls listTools() (remote connectors are lazy/network); tool-level
@@ -68,6 +166,15 @@ export declare class Registry {
68
166
  recordSuccess(id: string, latencyMs: number): void;
69
167
  recordFailure(id: string, latencyMs: number, error: unknown): void;
70
168
  healthFor(id: string): HealthObservation | undefined;
169
+ /**
170
+ * Whether ANY view of this deployment has seen a successful call to `id` —
171
+ * a bare boolean, never the observation. Connector liveness (reachable,
172
+ * credentials still valid) is a deployment-level fact, not a per-view one, so
173
+ * `list_connectors` may classify a connector as ok/unknown from it. The
174
+ * observation itself — `lastError` above all, which names the tool that
175
+ * failed — stays strictly per view.
176
+ */
177
+ hasObservedSuccess(id: string): boolean;
71
178
  /** Best-effort connector status for list_connectors. */
72
179
  statusFor(id: string, baseUrl: string, requestScope?: object): Promise<ConnectorStatus>;
73
180
  /** Drop a connector's cached tool list (e.g. after auth completes). */
@@ -75,4 +182,78 @@ export declare class Registry {
75
182
  /** Drop both in-memory and persisted tool catalogs. */
76
183
  invalidateStored(id: string): Promise<void>;
77
184
  }
185
+ /**
186
+ * THE toolkit enforcement point (issue #22).
187
+ *
188
+ * A filtered VIEW of one long-lived `Registry`: same connectors, same tool
189
+ * caches, same health — narrowed to the connectors and tool addresses one
190
+ * toolkit selects. `serveMcp` builds it once per scoped connection and hands it
191
+ * to `registerMetaTools`/`registerExecuteTool`, so `list_connectors`,
192
+ * `search_tools`, `describe_tools`, `call_tool`, `call_destructive_tool`,
193
+ * `batch_call`, `authorize_connector`, `get_result`, `skills`, and the
194
+ * `execute_code` host bridge all inherit the boundary from here instead of
195
+ * re-implementing nine checks.
196
+ *
197
+ * Two invariants make it reviewable:
198
+ *
199
+ * 1. **Indistinguishability.** Out-of-scope input fails through the SAME code
200
+ * path, with the same error class and message, as input naming something
201
+ * that does not exist at all. An out-of-scope CONNECTOR disappears from
202
+ * `resolveAddress`/`getConnector` (→ `Unknown address` / `Unknown
203
+ * connector`); an out-of-scope TOOL disappears from the catalog this view
204
+ * returns (→ `Unknown tool "<t>" on connector "<c>"`), which is exactly the
205
+ * error a misspelled tool name already produced. Scoping deliberately does
206
+ * NOT reject at `resolveAddress` for tools: that would answer with the
207
+ * connector-level message and make "hidden here" distinguishable from
208
+ * "never existed".
209
+ * 2. **It filters views, never state.** Every read delegates to the shared
210
+ * registry and filters the returned array, so the tool cache, the persisted
211
+ * catalog, and the health map stay whole and shared across scopes.
212
+ */
213
+ export declare class ScopedRegistry implements RegistryView {
214
+ private readonly base;
215
+ private readonly toolkit;
216
+ /** This toolkit's own health observations — see HealthLog. */
217
+ private readonly health;
218
+ constructor(base: Registry, toolkit: Toolkit);
219
+ get maxResultBytes(): number;
220
+ /** In scope AND actually registered. */
221
+ private visible;
222
+ /** Byte-identical to what the unscoped registry throws for an unknown id. */
223
+ private unknownConnector;
224
+ private inScopeTools;
225
+ listConnectors(): Connector[];
226
+ getConnector(id: string): Connector | undefined;
227
+ resolveAddress(address: string): {
228
+ connector: Connector;
229
+ toolName: string;
230
+ } | null;
231
+ getTools(id: string, baseUrl: string, requestScope?: object): Promise<ToolDef[]>;
232
+ refreshTools(id: string, baseUrl: string, requestScope?: object): Promise<ToolDef[]>;
233
+ peekTools(id: string): ToolDef[] | undefined;
234
+ contextFor(id: string, baseUrl: string, requestScope?: object, callOptions?: {
235
+ signal?: AbortSignal;
236
+ timeoutMs?: number;
237
+ }): ConnectorContext;
238
+ /**
239
+ * Stashed oversized results are bound to the scope that produced them: a
240
+ * scoped session cannot page a result it could not have produced, and an id
241
+ * from another scope reads back as the ordinary "Unknown or expired result
242
+ * id". Unscoped sessions keep the historical `results:` prefix untouched.
243
+ */
244
+ resultsStorage(): KVStorage;
245
+ recordSuccess(id: string, latencyMs: number): void;
246
+ recordFailure(id: string, latencyMs: number, error: unknown): void;
247
+ healthFor(id: string): HealthObservation | undefined;
248
+ /**
249
+ * Deliberately NOT per view: whether the connector has ever answered is a
250
+ * fact about the connector, not about a team's traffic, and withholding it
251
+ * would report every remote connector as "unknown" to a scoped session that
252
+ * has not called it yet. It carries no tool name, error text, or count — the
253
+ * per-view isolation of those, above, is unchanged.
254
+ */
255
+ hasObservedSuccess(id: string): boolean;
256
+ statusFor(id: string, baseUrl: string, requestScope?: object): Promise<ConnectorStatus>;
257
+ invalidateStored(id: string): Promise<void>;
258
+ }
78
259
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,S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AAC,EAAE,MAAM,CAAA;KAAO,GAC7D,gBAAgB;IAQnB;;;;;OAKG;IACH,cAAc,IAAI,SAAS;IAW3B,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMlD,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAMlE,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAIpD;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIjC,SAAS,CACb,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,MAAW,GACxB,OAAO,CAAC,eAAe,CAAC;IAQrB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}
package/dist/registry.js CHANGED
@@ -1,7 +1,81 @@
1
+ import { splitAddress } from "./toolkits.js";
1
2
  const ID_RE = /^[a-z0-9_-]+$/;
2
3
  const DEFAULT_TTL_SECONDS = 300;
3
4
  const DEFAULT_STALE_SECONDS = 3600;
4
- const DEFAULT_MAX_RESULT_BYTES = 50_000;
5
+ export const DEFAULT_MAX_RESULT_BYTES = 50_000;
6
+ /**
7
+ * Smallest accepted inline-result cap. One byte is pathological but harmless:
8
+ * `alignEndToCharBoundary` widens a window narrower than the codepoint at the
9
+ * offset, so even a 1-byte cap still truncates sanely and still pages. Caps
10
+ * that small already ship in the test suite (4 and 5), so the floor is placed
11
+ * where it excludes only values that are *broken* rather than merely tiny.
12
+ */
13
+ export const MIN_MAX_RESULT_BYTES = 1;
14
+ /**
15
+ * The one definition of a usable `maxResultBytes`: a finite whole number of at
16
+ * least {@link MIN_MAX_RESULT_BYTES} bytes. Shared by all three intake points
17
+ * — deployment config, the per-connector override, and `get_result`'s
18
+ * `maxBytes` argument — so a value that is valid at one is valid at all.
19
+ *
20
+ * Everything else is rejected rather than coerced, because each rejected shape
21
+ * silently does something *worse* than the default: `0`/`NaN` serve an empty
22
+ * head (`slice(0, 0)`) and make paging fail to advance, negatives serve a
23
+ * LARGER head than asked for (`slice(0, -1)` counts from the end) while still
24
+ * claiming truncation, and `Infinity` disables the guard with no notice.
25
+ */
26
+ export function isValidMaxResultBytes(value) {
27
+ return Number.isInteger(value) && value >= MIN_MAX_RESULT_BYTES;
28
+ }
29
+ /**
30
+ * Resolve a configured cap against the value it inherits, dropping anything
31
+ * `isValidMaxResultBytes` rejects. Operator-facing surfaces pair this with a
32
+ * startup warning (see `Registry.checkResultCaps`) so the fallback is never
33
+ * silent; the resolution itself stays total so no call site has to cope with
34
+ * a broken cap.
35
+ */
36
+ export function resolveMaxResultBytes(value, inherited) {
37
+ return value !== undefined && isValidMaxResultBytes(value)
38
+ ? value
39
+ : inherited;
40
+ }
41
+ /**
42
+ * Recent real-call outcomes per connector, as observed by ONE view.
43
+ *
44
+ * The deployment keeps one log, and each toolkit keeps its own. That split is a
45
+ * scope boundary, not bookkeeping: `lastError` is a downstream error string
46
+ * that routinely names the tool that failed, and `list_connectors` returns the
47
+ * observation verbatim. Sharing one log would let a toolkit read back the tools
48
+ * and failures of a sibling toolkit through a connector they happen to share —
49
+ * and let a sibling's failures flip this view's reported status. A scoped view
50
+ * reads back only the calls it made itself.
51
+ */
52
+ export class HealthLog {
53
+ observations = new Map();
54
+ recordSuccess(id, latencyMs) {
55
+ const previous = this.observations.get(id);
56
+ this.observations.set(id, {
57
+ ...previous,
58
+ lastSuccessAt: new Date().toISOString(),
59
+ lastLatencyMs: latencyMs,
60
+ consecutiveFailures: 0,
61
+ lastError: undefined,
62
+ });
63
+ }
64
+ recordFailure(id, latencyMs, error) {
65
+ const previous = this.observations.get(id);
66
+ this.observations.set(id, {
67
+ ...previous,
68
+ lastFailureAt: new Date().toISOString(),
69
+ lastLatencyMs: latencyMs,
70
+ consecutiveFailures: (previous?.consecutiveFailures ?? 0) + 1,
71
+ lastError: msg(error),
72
+ });
73
+ }
74
+ get(id) {
75
+ const observation = this.observations.get(id);
76
+ return observation ? { ...observation } : undefined;
77
+ }
78
+ }
5
79
  function namespaced(storage, prefix) {
6
80
  return {
7
81
  get: (k) => storage.get(prefix + k),
@@ -22,7 +96,8 @@ export class Registry {
22
96
  connectors = new Map();
23
97
  cache = new Map();
24
98
  invalidated = new Set();
25
- health = new Map();
99
+ /** Deployment-wide observations — every call, whatever view made it. */
100
+ health = new HealthLog();
26
101
  ttlMs;
27
102
  staleMs;
28
103
  persistToolCatalog;
@@ -35,7 +110,7 @@ export class Registry {
35
110
  this.staleMs =
36
111
  (opts.toolCatalogStaleSeconds ?? DEFAULT_STALE_SECONDS) * 1000;
37
112
  this.persistToolCatalog = opts.persistToolCatalog ?? true;
38
- this.maxResultBytes = opts.maxResultBytes ?? DEFAULT_MAX_RESULT_BYTES;
113
+ this.maxResultBytes = resolveMaxResultBytes(opts.maxResultBytes, DEFAULT_MAX_RESULT_BYTES);
39
114
  for (const c of connectors) {
40
115
  if (!ID_RE.test(c.id)) {
41
116
  throw new Error(`Invalid connector id "${c.id}": must match ${ID_RE.source}`);
@@ -46,6 +121,37 @@ export class Registry {
46
121
  this.connectors.set(c.id, c);
47
122
  }
48
123
  this.checkConventions(opts.logger);
124
+ this.checkResultCaps(opts.logger, opts.maxResultBytes);
125
+ }
126
+ /**
127
+ * Warn once per unusable result cap, at construction time — the same
128
+ * "runs fine but is surely unintended" channel as the insecure-config
129
+ * warnings in `createConnecta`. A rejected cap can't be honoured, and
130
+ * honouring it *approximately* is exactly the inversion issue #32 is about,
131
+ * so the value is dropped in favour of what it inherits and the operator is
132
+ * told which one is actually in force.
133
+ */
134
+ checkResultCaps(logger, configured) {
135
+ if (configured !== undefined && !isValidMaxResultBytes(configured)) {
136
+ logger.warn(`[connecta] maxResultBytes ${configured} is not a whole number of ` +
137
+ `bytes >= ${MIN_MAX_RESULT_BYTES}: it would serve an empty, ` +
138
+ "oversized, or unguarded result instead of truncating. Using the " +
139
+ `default ${DEFAULT_MAX_RESULT_BYTES} instead.`);
140
+ }
141
+ for (const c of this.connectors.values()) {
142
+ if (c.maxResultBytes !== undefined &&
143
+ !isValidMaxResultBytes(c.maxResultBytes)) {
144
+ // The number quoted here is `this.maxResultBytes` because that is
145
+ // literally what a call falls back to: meta-tools reads the inherited
146
+ // cap off `RegistryView.maxResultBytes`, so the warned value and the
147
+ // runtime value are the same field rather than two copies of it.
148
+ logger.warn(`[connecta] connector "${c.id}" sets maxResultBytes ` +
149
+ `${c.maxResultBytes}, which is not a whole number of bytes >= ` +
150
+ `${MIN_MAX_RESULT_BYTES}. Ignoring the override — the connector ` +
151
+ `inherits the deployment-wide cap calls fall back to ` +
152
+ `(${this.maxResultBytes}).`);
153
+ }
154
+ }
49
155
  }
50
156
  /**
51
157
  * Warn once per convention violation at construction time. Static only —
@@ -100,15 +206,13 @@ export class Registry {
100
206
  }
101
207
  /** Resolve "<connectorId>.<toolName>" → connector + tool name. */
102
208
  resolveAddress(address) {
103
- const dot = address.indexOf(".");
104
- if (dot <= 0 || dot === address.length - 1)
209
+ const parts = splitAddress(address);
210
+ if (!parts)
105
211
  return null;
106
- const id = address.slice(0, dot);
107
- const toolName = address.slice(dot + 1);
108
- const connector = this.connectors.get(id);
212
+ const connector = this.connectors.get(parts.connectorId);
109
213
  if (!connector)
110
214
  return null;
111
- return { connector, toolName };
215
+ return { connector, toolName: parts.toolName };
112
216
  }
113
217
  catalogKey(id) {
114
218
  return `catalog:${id}`;
@@ -227,28 +331,24 @@ export class Registry {
227
331
  return hit && hit.staleUntil > Date.now() ? hit.tools : undefined;
228
332
  }
229
333
  recordSuccess(id, latencyMs) {
230
- const previous = this.health.get(id);
231
- this.health.set(id, {
232
- ...previous,
233
- lastSuccessAt: new Date().toISOString(),
234
- lastLatencyMs: latencyMs,
235
- consecutiveFailures: 0,
236
- lastError: undefined,
237
- });
334
+ this.health.recordSuccess(id, latencyMs);
238
335
  }
239
336
  recordFailure(id, latencyMs, error) {
240
- const previous = this.health.get(id);
241
- this.health.set(id, {
242
- ...previous,
243
- lastFailureAt: new Date().toISOString(),
244
- lastLatencyMs: latencyMs,
245
- consecutiveFailures: (previous?.consecutiveFailures ?? 0) + 1,
246
- lastError: msg(error),
247
- });
337
+ this.health.recordFailure(id, latencyMs, error);
248
338
  }
249
339
  healthFor(id) {
250
- const observation = this.health.get(id);
251
- return observation ? { ...observation } : undefined;
340
+ return this.health.get(id);
341
+ }
342
+ /**
343
+ * Whether ANY view of this deployment has seen a successful call to `id` —
344
+ * a bare boolean, never the observation. Connector liveness (reachable,
345
+ * credentials still valid) is a deployment-level fact, not a per-view one, so
346
+ * `list_connectors` may classify a connector as ok/unknown from it. The
347
+ * observation itself — `lastError` above all, which names the tool that
348
+ * failed — stays strictly per view.
349
+ */
350
+ hasObservedSuccess(id) {
351
+ return this.health.get(id)?.lastSuccessAt !== undefined;
252
352
  }
253
353
  /** Best-effort connector status for list_connectors. */
254
354
  async statusFor(id, baseUrl, requestScope = {}) {
@@ -296,4 +396,170 @@ export class Registry {
296
396
  }
297
397
  }
298
398
  }
399
+ /**
400
+ * Per-toolkit HealthLogs, keyed by registry and then by toolkit name.
401
+ *
402
+ * Module-scoped rather than a `Registry` member on purpose: `Registry`'s type
403
+ * is part of the public API surface (`Connecta.registry`), and this is internal
404
+ * factoring only `ScopedRegistry` may touch. The WeakMap keeps the logs alive
405
+ * exactly as long as their registry, and the inner map is bounded by the
406
+ * number of configured toolkits.
407
+ */
408
+ const toolkitHealthLogs = new WeakMap();
409
+ /** The long-lived log one toolkit records into; created on first use. */
410
+ function toolkitHealthLog(base, toolkitName) {
411
+ let logs = toolkitHealthLogs.get(base);
412
+ if (!logs) {
413
+ logs = new Map();
414
+ toolkitHealthLogs.set(base, logs);
415
+ }
416
+ let log = logs.get(toolkitName);
417
+ if (!log) {
418
+ log = new HealthLog();
419
+ logs.set(toolkitName, log);
420
+ }
421
+ return log;
422
+ }
423
+ /**
424
+ * THE toolkit enforcement point (issue #22).
425
+ *
426
+ * A filtered VIEW of one long-lived `Registry`: same connectors, same tool
427
+ * caches, same health — narrowed to the connectors and tool addresses one
428
+ * toolkit selects. `serveMcp` builds it once per scoped connection and hands it
429
+ * to `registerMetaTools`/`registerExecuteTool`, so `list_connectors`,
430
+ * `search_tools`, `describe_tools`, `call_tool`, `call_destructive_tool`,
431
+ * `batch_call`, `authorize_connector`, `get_result`, `skills`, and the
432
+ * `execute_code` host bridge all inherit the boundary from here instead of
433
+ * re-implementing nine checks.
434
+ *
435
+ * Two invariants make it reviewable:
436
+ *
437
+ * 1. **Indistinguishability.** Out-of-scope input fails through the SAME code
438
+ * path, with the same error class and message, as input naming something
439
+ * that does not exist at all. An out-of-scope CONNECTOR disappears from
440
+ * `resolveAddress`/`getConnector` (→ `Unknown address` / `Unknown
441
+ * connector`); an out-of-scope TOOL disappears from the catalog this view
442
+ * returns (→ `Unknown tool "<t>" on connector "<c>"`), which is exactly the
443
+ * error a misspelled tool name already produced. Scoping deliberately does
444
+ * NOT reject at `resolveAddress` for tools: that would answer with the
445
+ * connector-level message and make "hidden here" distinguishable from
446
+ * "never existed".
447
+ * 2. **It filters views, never state.** Every read delegates to the shared
448
+ * registry and filters the returned array, so the tool cache, the persisted
449
+ * catalog, and the health map stay whole and shared across scopes.
450
+ */
451
+ export class ScopedRegistry {
452
+ base;
453
+ toolkit;
454
+ /** This toolkit's own health observations — see HealthLog. */
455
+ health;
456
+ constructor(base, toolkit) {
457
+ this.base = base;
458
+ this.toolkit = toolkit;
459
+ this.health = toolkitHealthLog(base, toolkit.name);
460
+ }
461
+ get maxResultBytes() {
462
+ return this.base.maxResultBytes;
463
+ }
464
+ /** In scope AND actually registered. */
465
+ visible(id) {
466
+ return (this.toolkit.hasConnector(id) && this.base.getConnector(id) !== undefined);
467
+ }
468
+ /** Byte-identical to what the unscoped registry throws for an unknown id. */
469
+ unknownConnector(id) {
470
+ return new Error(`Unknown connector "${id}"`);
471
+ }
472
+ inScopeTools(id, tools) {
473
+ return tools.filter((tool) => this.toolkit.hasTool(id, tool.name));
474
+ }
475
+ listConnectors() {
476
+ return this.base
477
+ .listConnectors()
478
+ .filter((connector) => this.toolkit.hasConnector(connector.id));
479
+ }
480
+ getConnector(id) {
481
+ return this.visible(id) ? this.base.getConnector(id) : undefined;
482
+ }
483
+ resolveAddress(address) {
484
+ const resolved = this.base.resolveAddress(address);
485
+ if (!resolved)
486
+ return null;
487
+ // Connector-level only — see invariant 1 above.
488
+ return this.toolkit.hasConnector(resolved.connector.id) ? resolved : null;
489
+ }
490
+ async getTools(id, baseUrl, requestScope) {
491
+ if (!this.visible(id))
492
+ throw this.unknownConnector(id);
493
+ return this.inScopeTools(id, await this.base.getTools(id, baseUrl, requestScope));
494
+ }
495
+ async refreshTools(id, baseUrl, requestScope) {
496
+ if (!this.visible(id))
497
+ throw this.unknownConnector(id);
498
+ return this.inScopeTools(id, await this.base.refreshTools(id, baseUrl, requestScope));
499
+ }
500
+ peekTools(id) {
501
+ if (!this.visible(id))
502
+ return undefined;
503
+ const tools = this.base.peekTools(id);
504
+ return tools ? this.inScopeTools(id, tools) : undefined;
505
+ }
506
+ contextFor(id, baseUrl, requestScope = {}, callOptions = {}) {
507
+ // Unreachable through the meta-tools (they resolve first), so a throw here
508
+ // is a loud backstop rather than a silent grant of connector storage and
509
+ // credentials to a scope that may not see the connector.
510
+ if (!this.visible(id))
511
+ throw this.unknownConnector(id);
512
+ return this.base.contextFor(id, baseUrl, requestScope, callOptions);
513
+ }
514
+ /**
515
+ * Stashed oversized results are bound to the scope that produced them: a
516
+ * scoped session cannot page a result it could not have produced, and an id
517
+ * from another scope reads back as the ordinary "Unknown or expired result
518
+ * id". Unscoped sessions keep the historical `results:` prefix untouched.
519
+ */
520
+ resultsStorage() {
521
+ return namespaced(this.base.resultsStorage(), `toolkit:${this.toolkit.name}:`);
522
+ }
523
+ // Outcomes are recorded twice on purpose: the deployment-wide log keeps the
524
+ // operator surfaces complete, while the toolkit's own log is the ONLY one
525
+ // this view reads back — so `list_connectors` here never reports a sibling
526
+ // toolkit's failures, or the tool names their error strings carry.
527
+ recordSuccess(id, latencyMs) {
528
+ if (!this.visible(id))
529
+ return;
530
+ this.base.recordSuccess(id, latencyMs);
531
+ this.health.recordSuccess(id, latencyMs);
532
+ }
533
+ recordFailure(id, latencyMs, error) {
534
+ if (!this.visible(id))
535
+ return;
536
+ this.base.recordFailure(id, latencyMs, error);
537
+ this.health.recordFailure(id, latencyMs, error);
538
+ }
539
+ healthFor(id) {
540
+ return this.visible(id) ? this.health.get(id) : undefined;
541
+ }
542
+ /**
543
+ * Deliberately NOT per view: whether the connector has ever answered is a
544
+ * fact about the connector, not about a team's traffic, and withholding it
545
+ * would report every remote connector as "unknown" to a scoped session that
546
+ * has not called it yet. It carries no tool name, error text, or count — the
547
+ * per-view isolation of those, above, is unchanged.
548
+ */
549
+ hasObservedSuccess(id) {
550
+ return this.visible(id) ? this.base.hasObservedSuccess(id) : false;
551
+ }
552
+ async statusFor(id, baseUrl, requestScope = {}) {
553
+ // Same shape the unscoped registry returns for an unregistered id.
554
+ if (!this.visible(id)) {
555
+ return { state: "error", message: "Unknown connector" };
556
+ }
557
+ return this.base.statusFor(id, baseUrl, requestScope);
558
+ }
559
+ async invalidateStored(id) {
560
+ if (!this.visible(id))
561
+ return;
562
+ await this.base.invalidateStored(id);
563
+ }
564
+ }
299
565
  //# sourceMappingURL=registry.js.map