@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/concurrency.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const DEFAULT_DISCOVERY_CONCURRENCY = 4;
|
|
2
|
-
|
|
3
|
-
export function resolveDiscoveryConcurrency(
|
|
4
|
-
value: number | undefined,
|
|
5
|
-
): number {
|
|
6
|
-
return value !== undefined && Number.isInteger(value) && value > 0
|
|
7
|
-
? value
|
|
8
|
-
: DEFAULT_DISCOVERY_CONCURRENCY;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** Run `fn` over `items` with at most `limit` operations in flight. */
|
|
12
|
-
export async function mapSettledWithConcurrency<T, R>(
|
|
13
|
-
items: readonly T[],
|
|
14
|
-
limit: number,
|
|
15
|
-
fn: (item: T, index: number) => Promise<R>,
|
|
16
|
-
): Promise<PromiseSettledResult<R>[]> {
|
|
17
|
-
const settled = Array<PromiseSettledResult<R>>(items.length);
|
|
18
|
-
const remaining = items.entries();
|
|
19
|
-
const workers = Array.from(
|
|
20
|
-
{ length: Math.min(limit, items.length) },
|
|
21
|
-
async () => {
|
|
22
|
-
for (;;) {
|
|
23
|
-
const next = remaining.next();
|
|
24
|
-
if (next.done) return;
|
|
25
|
-
const [index, item] = next.value;
|
|
26
|
-
try {
|
|
27
|
-
settled[index] = {
|
|
28
|
-
status: "fulfilled",
|
|
29
|
-
value: await fn(item, index),
|
|
30
|
-
};
|
|
31
|
-
} catch (reason) {
|
|
32
|
-
settled[index] = { status: "rejected", reason };
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
);
|
|
37
|
-
await Promise.all(workers);
|
|
38
|
-
return settled;
|
|
39
|
-
}
|
package/src/connector-scope.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Connector, ConnectorContext } from "./types.js";
|
|
2
|
-
|
|
3
|
-
/** Enough for local transport abort/close without letting cleanup own latency. */
|
|
4
|
-
const CONNECTOR_SCOPE_CLOSE_BUDGET_MS = 100;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Bound on cleanup continued after the caller-facing window expires.
|
|
8
|
-
*
|
|
9
|
-
* `remoteMcp` spends at most one second asking the downstream to terminate its
|
|
10
|
-
* session, leaving another second for the local close. Custom hooks still get a
|
|
11
|
-
* finite background window: handing a never-settling promise to a Worker's
|
|
12
|
-
* `waitUntil` would otherwise keep the invocation alive until the platform cap.
|
|
13
|
-
*/
|
|
14
|
-
const CONNECTOR_SCOPE_DEFER_BUDGET_MS = 2_000;
|
|
15
|
-
|
|
16
|
-
/** Runtime hook for work that may safely continue after a response is ready. */
|
|
17
|
-
export type DeferredWork = (promise: Promise<unknown>) => void;
|
|
18
|
-
|
|
19
|
-
/** Resolve when `work` settles or `budgetMs` expires; never reject. */
|
|
20
|
-
function waitAtMost(work: Promise<void>, budgetMs: number): Promise<void> {
|
|
21
|
-
return new Promise((resolve) => {
|
|
22
|
-
const timer = setTimeout(resolve, budgetMs);
|
|
23
|
-
work.then(() => {
|
|
24
|
-
clearTimeout(timer);
|
|
25
|
-
resolve();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Tell a connector that a scope owned by the core has ended.
|
|
32
|
-
*
|
|
33
|
-
* Scope teardown is deliberately best-effort: a missing hook is a no-op and a
|
|
34
|
-
* rejected hook is swallowed so cleanup can never replace the probe result that
|
|
35
|
-
* caused it. The hook gets a small, fixed completion window so edge runtimes do
|
|
36
|
-
* not cut off a real close as the response ends. When the runtime supplies
|
|
37
|
-
* `defer`, the bounded tail is handed to it without extending the caller-facing
|
|
38
|
-
* window. Callers own the at-most-once guarantee and must not use the scope
|
|
39
|
-
* again after this returns.
|
|
40
|
-
*/
|
|
41
|
-
export async function closeConnectorScope(
|
|
42
|
-
connector: Connector,
|
|
43
|
-
ctx: ConnectorContext,
|
|
44
|
-
defer?: DeferredWork,
|
|
45
|
-
): Promise<void> {
|
|
46
|
-
try {
|
|
47
|
-
const closing = connector.closeScope?.(ctx);
|
|
48
|
-
if (!closing) return;
|
|
49
|
-
// Attach both handlers before either timer can win, so a late rejection is
|
|
50
|
-
// consumed rather than becoming an unhandled rejection.
|
|
51
|
-
const settled = closing.then(
|
|
52
|
-
() => {},
|
|
53
|
-
() => {},
|
|
54
|
-
);
|
|
55
|
-
if (defer) {
|
|
56
|
-
try {
|
|
57
|
-
defer(waitAtMost(settled, CONNECTOR_SCOPE_DEFER_BUDGET_MS));
|
|
58
|
-
} catch {
|
|
59
|
-
// A runtime hook is best-effort too; the caller cap still applies.
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
await waitAtMost(settled, CONNECTOR_SCOPE_CLOSE_BUDGET_MS);
|
|
63
|
-
} catch {
|
|
64
|
-
// The scope is over whether or not the connector managed to clean it up.
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/connectors/api.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { precompileValidator, validateToolInput } from "../validate.js";
|
|
2
|
-
import type {
|
|
3
|
-
Connector,
|
|
4
|
-
ConnectorCallAdmissionPolicy,
|
|
5
|
-
ConnectorCredentialConfig,
|
|
6
|
-
ConnectorCredentialValues,
|
|
7
|
-
ConnectorContext,
|
|
8
|
-
ConnectorUsageGuide,
|
|
9
|
-
CredentialTestResult,
|
|
10
|
-
JsonSchema,
|
|
11
|
-
ToolAnnotations,
|
|
12
|
-
ToolDef,
|
|
13
|
-
} from "../types.js";
|
|
14
|
-
|
|
15
|
-
export interface ApiTool {
|
|
16
|
-
name: string;
|
|
17
|
-
description?: string;
|
|
18
|
-
/** A plain JSON Schema object describing the tool input. */
|
|
19
|
-
inputSchema?: JsonSchema;
|
|
20
|
-
/** A plain JSON Schema object describing the tool's structured output. */
|
|
21
|
-
outputSchema?: JsonSchema;
|
|
22
|
-
/**
|
|
23
|
-
* Standard MCP-style behavior hints. Only an explicit readOnlyHint: true
|
|
24
|
-
* admits the tool to call_tool and execute_code.
|
|
25
|
-
*/
|
|
26
|
-
annotations?: ToolAnnotations;
|
|
27
|
-
handler: (args: any, ctx: ConnectorContext) => Promise<unknown> | unknown;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ApiOptions {
|
|
31
|
-
/** Human-readable display name; the connector id remains the address prefix. */
|
|
32
|
-
title?: string;
|
|
33
|
-
description?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Max inline result size (bytes) for this connector's tools before
|
|
36
|
-
* call_tool truncates and stashes the full text for get_result
|
|
37
|
-
* paging. Overrides the deployment's `calls.maxResultBytes`; omit to inherit
|
|
38
|
-
* it. Must be a whole number of bytes >= 1; anything else warns at startup
|
|
39
|
-
* and is ignored.
|
|
40
|
-
*/
|
|
41
|
-
maxResultBytes?: number;
|
|
42
|
-
/** Optional per-runtime downstream call-admission policy. */
|
|
43
|
-
callAdmission?: ConnectorCallAdmissionPolicy;
|
|
44
|
-
/**
|
|
45
|
-
* Optional agent-facing usage guide served by `skills` as
|
|
46
|
-
* `connector:<id>`. A string is markdown; the structured form adds bounded
|
|
47
|
-
* discovery metadata. See `Connector.usageGuide`.
|
|
48
|
-
*/
|
|
49
|
-
usageGuide?: string | ConnectorUsageGuide;
|
|
50
|
-
/** Optional operator-managed credential exposed through ctx.credential and /credentials. */
|
|
51
|
-
credential?: ConnectorCredentialConfig;
|
|
52
|
-
/** Optional validation behind /credentials' Test action. */
|
|
53
|
-
testCredential?: (
|
|
54
|
-
value: string,
|
|
55
|
-
ctx: ConnectorContext,
|
|
56
|
-
) => Promise<CredentialTestResult>;
|
|
57
|
-
/** Optional validation for named multi-field credentials. */
|
|
58
|
-
testCredentials?: (
|
|
59
|
-
values: ConnectorCredentialValues,
|
|
60
|
-
ctx: ConnectorContext,
|
|
61
|
-
) => Promise<CredentialTestResult>;
|
|
62
|
-
/**
|
|
63
|
-
* Validate call arguments against each tool's `inputSchema` before invoking
|
|
64
|
-
* the handler (default true). Mismatches fail with a non-retryable
|
|
65
|
-
* `invalid_args` ConnectorCallError instead of reaching the handler. Set
|
|
66
|
-
* false to restore the pre-validation pass-through for deployments relying
|
|
67
|
-
* on loose coercion.
|
|
68
|
-
*/
|
|
69
|
-
validateArgs?: boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Fail-closed on a tool whose `inputSchema` the validator cannot evaluate
|
|
72
|
-
* (default false). The default surfaces such a schema as a one-time warning
|
|
73
|
-
* and then passes the raw arguments through, so a broken schema never breaks
|
|
74
|
-
* an otherwise working tool. Set true to instead reject those calls with a
|
|
75
|
-
* non-retryable `invalid_args` ConnectorCallError, so a schema that cannot be
|
|
76
|
-
* enforced never silently admits unvalidated input. Only consulted when
|
|
77
|
-
* `validateArgs` is not false.
|
|
78
|
-
*/
|
|
79
|
-
strictValidation?: boolean;
|
|
80
|
-
tools: ApiTool[];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A connector defined entirely in code: static tool defs + fetch handlers.
|
|
85
|
-
* Tool inputs are plain JSON Schema objects (bring your own zod-to-json-schema
|
|
86
|
-
* conversion if you prefer zod). call_tool JSON-wraps the handler's return.
|
|
87
|
-
*
|
|
88
|
-
* Arguments are validated against `inputSchema` before the handler runs
|
|
89
|
-
* (disable with `validateArgs: false`). Remote MCP inputs are also validated,
|
|
90
|
-
* but in the shared invocation path against the request-local downstream
|
|
91
|
-
* catalog. These API-only controls stay here because hand-written handlers may
|
|
92
|
-
* deliberately accept loose coercion or choose fail-closed schema handling.
|
|
93
|
-
*/
|
|
94
|
-
export function api(id: string, opts: ApiOptions): Connector {
|
|
95
|
-
const defs: ToolDef[] = opts.tools.map((t) => ({
|
|
96
|
-
name: t.name,
|
|
97
|
-
...(t.description !== undefined ? { description: t.description } : {}),
|
|
98
|
-
...(t.inputSchema !== undefined ? { inputSchema: t.inputSchema } : {}),
|
|
99
|
-
...(t.outputSchema !== undefined ? { outputSchema: t.outputSchema } : {}),
|
|
100
|
-
...(t.annotations !== undefined ? { annotations: t.annotations } : {}),
|
|
101
|
-
}));
|
|
102
|
-
const byName = new Map(opts.tools.map((t) => [t.name, t]));
|
|
103
|
-
const validateArgs = opts.validateArgs ?? true;
|
|
104
|
-
const strictValidation = opts.strictValidation ?? false;
|
|
105
|
-
if (validateArgs) {
|
|
106
|
-
// Compile each schema now so a validator-hostile inputSchema surfaces once
|
|
107
|
-
// here rather than silently on its first call. Warning-only; never throws.
|
|
108
|
-
for (const t of opts.tools) {
|
|
109
|
-
if (t.inputSchema)
|
|
110
|
-
precompileValidator(t.inputSchema, { address: `${id}.${t.name}` });
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
id,
|
|
115
|
-
...(opts.title !== undefined ? { title: opts.title } : {}),
|
|
116
|
-
kind: "api",
|
|
117
|
-
...(opts.description !== undefined
|
|
118
|
-
? { description: opts.description }
|
|
119
|
-
: {}),
|
|
120
|
-
...(opts.maxResultBytes !== undefined
|
|
121
|
-
? { maxResultBytes: opts.maxResultBytes }
|
|
122
|
-
: {}),
|
|
123
|
-
...(opts.callAdmission !== undefined
|
|
124
|
-
? { callAdmission: opts.callAdmission }
|
|
125
|
-
: {}),
|
|
126
|
-
...(opts.usageGuide !== undefined ? { usageGuide: opts.usageGuide } : {}),
|
|
127
|
-
...(opts.credential !== undefined ? { credential: opts.credential } : {}),
|
|
128
|
-
...(opts.testCredential !== undefined
|
|
129
|
-
? { testCredential: opts.testCredential }
|
|
130
|
-
: {}),
|
|
131
|
-
...(opts.testCredentials !== undefined
|
|
132
|
-
? { testCredentials: opts.testCredentials }
|
|
133
|
-
: {}),
|
|
134
|
-
staticTools: defs,
|
|
135
|
-
async listTools() {
|
|
136
|
-
return defs;
|
|
137
|
-
},
|
|
138
|
-
async callTool(name, args, ctx) {
|
|
139
|
-
const tool = byName.get(name);
|
|
140
|
-
if (!tool) {
|
|
141
|
-
throw new Error(`Unknown tool "${name}" on connector "${id}"`);
|
|
142
|
-
}
|
|
143
|
-
const input = args ?? {};
|
|
144
|
-
if (validateArgs && tool.inputSchema) {
|
|
145
|
-
const invalid = validateToolInput(tool.inputSchema, input, {
|
|
146
|
-
address: `${id}.${name}`,
|
|
147
|
-
logger: ctx.logger,
|
|
148
|
-
failClosed: strictValidation,
|
|
149
|
-
});
|
|
150
|
-
if (invalid) throw invalid;
|
|
151
|
-
}
|
|
152
|
-
// `await` (not a bare promise return) so a handler that throws before
|
|
153
|
-
// its first await never sits handler-less for the thenable-adoption
|
|
154
|
-
// microtask — workerd and vitest both report that gap as an unhandled
|
|
155
|
-
// rejection even though the caller catches the failure.
|
|
156
|
-
return await tool.handler(input, ctx);
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
}
|