@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/apps-shell.ts
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The one MCP Apps template connecta serves (`U5`, `U6`).
|
|
3
|
-
*
|
|
4
|
-
* A build-time string constant, not a file read at startup: the core is
|
|
5
|
-
* Web-API-only so it runs unchanged on Workers, and the same bytes have to
|
|
6
|
-
* serve everywhere. It renders whatever HTML a program handed `connecta.ui`
|
|
7
|
-
* inside a nested `srcdoc` frame. The one-argument form forwards no channel;
|
|
8
|
-
* an explicitly bound view gets only named read calls through the trusted
|
|
9
|
-
* shell, never a raw host channel.
|
|
10
|
-
*
|
|
11
|
-
* The address carries a version segment because hosts are permitted to
|
|
12
|
-
* prefetch and cache templates by URI: change these bytes, bump the version.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/** The only `ui://` URI in the system. No program input reaches it. */
|
|
16
|
-
export const PROGRAM_UI_RESOURCE_URI = "ui://connecta/program-ui/v2";
|
|
17
|
-
|
|
18
|
-
/** The mimeType the Apps spec requires of an HTML template. */
|
|
19
|
-
export const PROGRAM_UI_MIME_TYPE = "text/html;profile=mcp-app";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The result `_meta` key carrying the payload (`U3`). A plain single-label
|
|
23
|
-
* prefix rather than the reverse-DNS form MCP's SHOULD prefers: connecta has
|
|
24
|
-
* no domain to reverse, and fabricating one to satisfy a SHOULD is a worse
|
|
25
|
-
* answer than the shape the key format's MUST already permits.
|
|
26
|
-
*/
|
|
27
|
-
export const PROGRAM_UI_META_KEY = "connecta/ui";
|
|
28
|
-
|
|
29
|
-
/** The one extension identifier connecta advertises (`U11`). */
|
|
30
|
-
export const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The shell document. Dependency-free and deliberately small: it speaks the
|
|
34
|
-
* Apps postMessage dialect (`ui/initialize`, `ui/notifications/initialized`,
|
|
35
|
-
* `ui/notifications/tool-result`, `ui/notifications/size-changed`,
|
|
36
|
-
* `ui/resource-teardown`), lifts `_meta["connecta/ui"].html` out of the
|
|
37
|
-
* delivered tool result, and puts it in a frame. An optional read manifest
|
|
38
|
-
* installs one narrow `connecta.read(name, args)` bridge in that inner frame;
|
|
39
|
-
* the outer shell maps declared names to the existing `call_tool` meta-tool.
|
|
40
|
-
* It declares no CSP domains, so the host applies its restrictive default and
|
|
41
|
-
* the `srcdoc` frame inherits `default-src 'none'` — program markup still gets
|
|
42
|
-
* no direct network.
|
|
43
|
-
*/
|
|
44
|
-
export const PROGRAM_UI_SHELL_HTML = `<!doctype html>
|
|
45
|
-
<html lang="en">
|
|
46
|
-
<head>
|
|
47
|
-
<meta charset="utf-8" />
|
|
48
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
49
|
-
<title>connecta program view</title>
|
|
50
|
-
<style>
|
|
51
|
-
html,
|
|
52
|
-
body {
|
|
53
|
-
margin: 0;
|
|
54
|
-
padding: 0;
|
|
55
|
-
background: transparent;
|
|
56
|
-
}
|
|
57
|
-
#program-view {
|
|
58
|
-
display: block;
|
|
59
|
-
width: 100%;
|
|
60
|
-
min-height: 480px;
|
|
61
|
-
border: 0;
|
|
62
|
-
}
|
|
63
|
-
</style>
|
|
64
|
-
</head>
|
|
65
|
-
<body>
|
|
66
|
-
<iframe
|
|
67
|
-
id="program-view"
|
|
68
|
-
title="Program-rendered view"
|
|
69
|
-
sandbox="allow-scripts"
|
|
70
|
-
srcdoc=""
|
|
71
|
-
></iframe>
|
|
72
|
-
<script>
|
|
73
|
-
(function () {
|
|
74
|
-
"use strict";
|
|
75
|
-
// The outer shell is the only host peer. The payload frame is
|
|
76
|
-
// sandboxed to scripts alone, with no same-origin escape. Its one
|
|
77
|
-
// optional message dialect is handled below and translated into
|
|
78
|
-
// bounded call_tool requests; raw JSON-RPC is never forwarded.
|
|
79
|
-
var host = window.parent;
|
|
80
|
-
var view = document.getElementById("program-view");
|
|
81
|
-
var initializeId = "connecta-ui-initialize";
|
|
82
|
-
var lastWidth = 0;
|
|
83
|
-
var lastHeight = 0;
|
|
84
|
-
var reads = null;
|
|
85
|
-
var hostCanCallTools = false;
|
|
86
|
-
var nextHostRequestId = 0;
|
|
87
|
-
var pendingHostReads = Object.create(null);
|
|
88
|
-
var activeHostReads = 0;
|
|
89
|
-
var maxActiveHostReads = 8;
|
|
90
|
-
|
|
91
|
-
function send(message) {
|
|
92
|
-
if (!host || host === window) return;
|
|
93
|
-
host.postMessage(message, "*");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function notify(method, params) {
|
|
97
|
-
send({ jsonrpc: "2.0", method: method, params: params });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Program views are fixed-height by construction. The shell has no
|
|
101
|
-
// content-height bridge to the payload frame, so it can never learn
|
|
102
|
-
// the payload's content height, and
|
|
103
|
-
// what it reports here is its own box: the min-height above, unless
|
|
104
|
-
// the host has given it more. Taller content scrolls inside the inner
|
|
105
|
-
// frame rather than growing the view. Raising the min-height is the
|
|
106
|
-
// only lever; a content-height signal would cost the isolation.
|
|
107
|
-
function reportSize() {
|
|
108
|
-
var width = Math.ceil(document.documentElement.clientWidth);
|
|
109
|
-
var height = Math.ceil(document.documentElement.scrollHeight);
|
|
110
|
-
if (width === lastWidth && height === lastHeight) return;
|
|
111
|
-
lastWidth = width;
|
|
112
|
-
lastHeight = height;
|
|
113
|
-
notify("ui/notifications/size-changed", {
|
|
114
|
-
width: width,
|
|
115
|
-
height: height
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function payload(result) {
|
|
120
|
-
if (!result || typeof result !== "object") return null;
|
|
121
|
-
var meta = result._meta;
|
|
122
|
-
if (!meta || typeof meta !== "object") return null;
|
|
123
|
-
var value = meta["connecta/ui"];
|
|
124
|
-
if (!value || typeof value !== "object") return null;
|
|
125
|
-
return typeof value.html === "string" && value.html.length > 0
|
|
126
|
-
? value
|
|
127
|
-
: null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// This function is serialized into the opaque-origin payload frame.
|
|
131
|
-
// It knows no addresses and has no host channel of its own: one named
|
|
132
|
-
// read request goes to the trusted outer shell and one correlated
|
|
133
|
-
// result comes back.
|
|
134
|
-
function payloadReadBridge() {
|
|
135
|
-
"use strict";
|
|
136
|
-
var pending = Object.create(null);
|
|
137
|
-
var nextId = 0;
|
|
138
|
-
|
|
139
|
-
function read(name, args) {
|
|
140
|
-
return new Promise(function (resolve, reject) {
|
|
141
|
-
var id = String(++nextId);
|
|
142
|
-
pending[id] = { resolve: resolve, reject: reject };
|
|
143
|
-
try {
|
|
144
|
-
window.parent.postMessage({
|
|
145
|
-
type: "connecta/read",
|
|
146
|
-
id: id,
|
|
147
|
-
name: name,
|
|
148
|
-
args: args === undefined ? {} : args
|
|
149
|
-
}, "*");
|
|
150
|
-
} catch (error) {
|
|
151
|
-
delete pending[id];
|
|
152
|
-
reject(error);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
Object.defineProperty(globalThis, "connecta", {
|
|
158
|
-
value: Object.freeze({ read: read }),
|
|
159
|
-
configurable: false,
|
|
160
|
-
enumerable: true,
|
|
161
|
-
writable: false
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
window.addEventListener("message", function (event) {
|
|
165
|
-
if (event.source !== window.parent) return;
|
|
166
|
-
var message = event.data;
|
|
167
|
-
if (!message || message.type !== "connecta/read-result") return;
|
|
168
|
-
var waiter = pending[message.id];
|
|
169
|
-
if (!waiter) return;
|
|
170
|
-
delete pending[message.id];
|
|
171
|
-
if (message.ok) waiter.resolve(message.value);
|
|
172
|
-
else waiter.reject(new Error(message.error || "Read failed"));
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function htmlWithReadBridge(html) {
|
|
177
|
-
var script =
|
|
178
|
-
"<scr" + "ipt>(" + payloadReadBridge.toString() + ")();</scr" + "ipt>";
|
|
179
|
-
var head = /<head(?:\\s[^>]*)?>/i.exec(html);
|
|
180
|
-
if (head) {
|
|
181
|
-
var at = (head.index || 0) + head[0].length;
|
|
182
|
-
return html.slice(0, at) + script + html.slice(at);
|
|
183
|
-
}
|
|
184
|
-
var document = /<html(?:\\s[^>]*)?>/i.exec(html);
|
|
185
|
-
if (document) {
|
|
186
|
-
var afterHtml = (document.index || 0) + document[0].length;
|
|
187
|
-
return html.slice(0, afterHtml) + "<head>" + script + "</head>" + html.slice(afterHtml);
|
|
188
|
-
}
|
|
189
|
-
return script + html;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function render(params) {
|
|
193
|
-
var value =
|
|
194
|
-
payload(params) ||
|
|
195
|
-
payload(params && params.result) ||
|
|
196
|
-
payload(params && params.toolResult);
|
|
197
|
-
if (value === null) return;
|
|
198
|
-
reads = value.reads && typeof value.reads === "object"
|
|
199
|
-
? value.reads
|
|
200
|
-
: null;
|
|
201
|
-
view.srcdoc = reads
|
|
202
|
-
? htmlWithReadBridge(value.html)
|
|
203
|
-
: value.html;
|
|
204
|
-
reportSize();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function readError(message, fallback) {
|
|
208
|
-
if (message && typeof message.message === "string") return message.message;
|
|
209
|
-
if (message && message.data && typeof message.data.message === "string") {
|
|
210
|
-
return message.data.message;
|
|
211
|
-
}
|
|
212
|
-
return fallback;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function finishInnerRead(innerId, ok, value) {
|
|
216
|
-
if (!view.contentWindow) return;
|
|
217
|
-
view.contentWindow.postMessage(ok
|
|
218
|
-
? { type: "connecta/read-result", id: innerId, ok: true, value: value }
|
|
219
|
-
: { type: "connecta/read-result", id: innerId, ok: false, error: value }, "*");
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function beginInnerRead(message) {
|
|
223
|
-
if (!hostCanCallTools) {
|
|
224
|
-
finishInnerRead(message && message.id, false, "This host does not support app-initiated server tool calls");
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (!message || typeof message.id !== "string" || typeof message.name !== "string") return;
|
|
228
|
-
if (!reads || !Object.prototype.hasOwnProperty.call(reads, message.name)) {
|
|
229
|
-
finishInnerRead(message.id, false, "Unknown read binding");
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (activeHostReads >= maxActiveHostReads) {
|
|
233
|
-
finishInnerRead(message.id, false, "Too many concurrent reads");
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
var binding = reads[message.name];
|
|
237
|
-
if (!binding || typeof binding !== "object" || typeof binding.address !== "string") {
|
|
238
|
-
finishInnerRead(message.id, false, "Invalid read binding");
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
var supplied = message.args;
|
|
242
|
-
if (!supplied || typeof supplied !== "object" || Array.isArray(supplied)) {
|
|
243
|
-
finishInnerRead(message.id, false, "Read arguments must be an object");
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
var allowed = Array.isArray(binding.viewArgs) ? binding.viewArgs : [];
|
|
247
|
-
var suppliedKeys = Object.keys(supplied);
|
|
248
|
-
for (var i = 0; i < suppliedKeys.length; i++) {
|
|
249
|
-
var key = suppliedKeys[i];
|
|
250
|
-
if (allowed.indexOf(key) === -1) {
|
|
251
|
-
finishInnerRead(message.id, false, "Undeclared read argument " + JSON.stringify(key));
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
var args = Object.create(null);
|
|
256
|
-
var fixed = binding.fixedArgs && typeof binding.fixedArgs === "object"
|
|
257
|
-
? binding.fixedArgs
|
|
258
|
-
: {};
|
|
259
|
-
Object.keys(fixed).forEach(function (key) { args[key] = fixed[key]; });
|
|
260
|
-
suppliedKeys.forEach(function (key) { args[key] = supplied[key]; });
|
|
261
|
-
|
|
262
|
-
var hostId = "connecta-ui-read-" + String(++nextHostRequestId);
|
|
263
|
-
pendingHostReads[hostId] = { innerId: message.id };
|
|
264
|
-
activeHostReads++;
|
|
265
|
-
send({
|
|
266
|
-
jsonrpc: "2.0",
|
|
267
|
-
id: hostId,
|
|
268
|
-
method: "tools/call",
|
|
269
|
-
params: {
|
|
270
|
-
name: "call_tool",
|
|
271
|
-
arguments: {
|
|
272
|
-
address: binding.address,
|
|
273
|
-
args: args,
|
|
274
|
-
resultMode: "value"
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function finishHostRead(message) {
|
|
281
|
-
var pending = pendingHostReads[message.id];
|
|
282
|
-
if (!pending) return false;
|
|
283
|
-
delete pendingHostReads[message.id];
|
|
284
|
-
activeHostReads--;
|
|
285
|
-
if (message.error) {
|
|
286
|
-
finishInnerRead(pending.innerId, false, readError(message.error, "Host rejected read"));
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
var toolResult = message.result;
|
|
290
|
-
if (!toolResult || typeof toolResult !== "object") {
|
|
291
|
-
finishInnerRead(pending.innerId, false, "Host returned an invalid tool result");
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
var structured = toolResult.structuredContent;
|
|
295
|
-
if (toolResult.isError || (structured && structured.ok === false)) {
|
|
296
|
-
var detail = structured && structured.error;
|
|
297
|
-
var content = Array.isArray(toolResult.content)
|
|
298
|
-
? toolResult.content.find(function (block) { return block && block.type === "text"; })
|
|
299
|
-
: null;
|
|
300
|
-
finishInnerRead(
|
|
301
|
-
pending.innerId,
|
|
302
|
-
false,
|
|
303
|
-
readError(detail, content && content.text ? content.text : "Read failed")
|
|
304
|
-
);
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
var value = structured && structured.ok === true &&
|
|
308
|
-
Object.prototype.hasOwnProperty.call(structured, "data")
|
|
309
|
-
? structured.data
|
|
310
|
-
: structured !== undefined
|
|
311
|
-
? structured
|
|
312
|
-
: toolResult;
|
|
313
|
-
finishInnerRead(pending.innerId, true, value);
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
window.addEventListener("message", function (event) {
|
|
318
|
-
var message = event.data;
|
|
319
|
-
if (event.source === view.contentWindow) {
|
|
320
|
-
if (message && message.type === "connecta/read") beginInnerRead(message);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (event.source !== host) return;
|
|
324
|
-
if (!message || message.jsonrpc !== "2.0") return;
|
|
325
|
-
if (message.id !== undefined && finishHostRead(message)) return;
|
|
326
|
-
if (message.method === "ui/notifications/tool-result") {
|
|
327
|
-
render(message.params);
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
if (message.method === "ui/resource-teardown") {
|
|
331
|
-
// A host->view request, not a notification: the host waits for
|
|
332
|
-
// this reply before it tears the view down. There is nothing to
|
|
333
|
-
// release, so answer immediately rather than make it time out.
|
|
334
|
-
if (message.id !== undefined && message.id !== null) {
|
|
335
|
-
send({ jsonrpc: "2.0", id: message.id, result: {} });
|
|
336
|
-
}
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
// Only a completed handshake earns "initialized". A JSON-RPC error
|
|
340
|
-
// response carries the same id, and announcing initialization on one
|
|
341
|
-
// would assert a handshake that never happened.
|
|
342
|
-
if (message.id === initializeId && message.result !== undefined) {
|
|
343
|
-
var capabilities = message.result.hostCapabilities;
|
|
344
|
-
hostCanCallTools = Boolean(capabilities && capabilities.serverTools);
|
|
345
|
-
notify("ui/notifications/initialized", {});
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
window.addEventListener("resize", reportSize);
|
|
350
|
-
view.addEventListener("load", reportSize);
|
|
351
|
-
|
|
352
|
-
// Every field here is required by the Apps initialize schema, and a
|
|
353
|
-
// conforming host rejects the request outright when one is missing —
|
|
354
|
-
// which would strand the shell before any tool result arrives.
|
|
355
|
-
send({
|
|
356
|
-
jsonrpc: "2.0",
|
|
357
|
-
id: initializeId,
|
|
358
|
-
method: "ui/initialize",
|
|
359
|
-
params: {
|
|
360
|
-
appInfo: { name: "connecta program view", version: "1" },
|
|
361
|
-
appCapabilities: {},
|
|
362
|
-
protocolVersion: "2026-01-26"
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
reportSize();
|
|
366
|
-
})();
|
|
367
|
-
</script>
|
|
368
|
-
</body>
|
|
369
|
-
</html>
|
|
370
|
-
`;
|
package/src/auth/bearer.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { assertNoRetiredToolkitOptions } from "../retired-toolkits.js";
|
|
2
|
-
import type { AuthResult, InboundAuth } from "../types.js";
|
|
3
|
-
|
|
4
|
-
const encoder = new TextEncoder();
|
|
5
|
-
|
|
6
|
-
/** Constant-time byte comparison. Differing lengths still iterate to reduce leak. */
|
|
7
|
-
function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {
|
|
8
|
-
if (a.length !== b.length) {
|
|
9
|
-
let r = 1;
|
|
10
|
-
const n = Math.max(a.length, b.length);
|
|
11
|
-
for (let i = 0; i < n; i++) r |= (a[i] ?? 0) ^ (b[i] ?? 0);
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
let r = 0;
|
|
15
|
-
for (let i = 0; i < a.length; i++) r |= (a[i] ?? 0) ^ (b[i] ?? 0);
|
|
16
|
-
return r === 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface BearerTokenOptions {
|
|
20
|
-
/** Stable identity for this credential, used on activity events. */
|
|
21
|
-
subjectId?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Static bearer-token inbound auth. Constant-time compares the Bearer token
|
|
26
|
-
* against `secret`. Checked BEFORE the Clerk gate in the server; a mismatch
|
|
27
|
-
* falls through so a co-configured Clerk provider can still admit the request.
|
|
28
|
-
*/
|
|
29
|
-
export function bearerToken(
|
|
30
|
-
secret: string,
|
|
31
|
-
options: BearerTokenOptions = {},
|
|
32
|
-
): InboundAuth {
|
|
33
|
-
assertNoRetiredToolkitOptions("bearerToken", options);
|
|
34
|
-
const secretBytes = encoder.encode(secret);
|
|
35
|
-
return {
|
|
36
|
-
kind: "bearer",
|
|
37
|
-
authorize(request): AuthResult {
|
|
38
|
-
const header = request.headers.get("authorization") ?? "";
|
|
39
|
-
const match = /^Bearer\s+(.+)$/i.exec(header);
|
|
40
|
-
if (match && timingSafeEqual(encoder.encode(match[1]), secretBytes)) {
|
|
41
|
-
return {
|
|
42
|
-
ok: true,
|
|
43
|
-
...(options.subjectId ? { subjectId: options.subjectId } : {}),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
ok: false,
|
|
48
|
-
response: new Response(
|
|
49
|
-
JSON.stringify({ error: "unauthorized" }),
|
|
50
|
-
{
|
|
51
|
-
status: 401,
|
|
52
|
-
headers: {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
"WWW-Authenticate": "Bearer",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
),
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|