@zackbart/connecta 0.24.4 → 0.25.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 (107) hide show
  1. package/AGENTS.md +40 -10
  2. package/CHANGELOG.md +253 -0
  3. package/dist/advertised-schema.js +53 -0
  4. package/dist/auth/downstream-oauth.js +490 -106
  5. package/dist/call-admission.js +139 -113
  6. package/dist/catalog-service.js +141 -105
  7. package/dist/catalog.js +258 -33
  8. package/dist/concurrency.js +24 -23
  9. package/dist/connector-scope.js +6 -37
  10. package/dist/connectors/api.d.ts +2 -2
  11. package/dist/connectors/remote-mcp.d.ts +6 -5
  12. package/dist/connectors/remote-mcp.js +317 -241
  13. package/dist/credential-contract.d.ts +9 -0
  14. package/dist/credential-rules.js +2 -2
  15. package/dist/credentials.d.ts +6 -1
  16. package/dist/credentials.js +45 -3
  17. package/dist/execute.js +363 -257
  18. package/dist/executor-admission.js +67 -50
  19. package/dist/executors/quickjs-runtime.js +4 -2
  20. package/dist/executors/quickjs.js +251 -210
  21. package/dist/fix-prompt.js +37 -0
  22. package/dist/index.d.ts +10 -1
  23. package/dist/index.js +51 -20
  24. package/dist/invocation.js +324 -285
  25. package/dist/meta-tools.js +206 -92
  26. package/dist/oauth-callback-outcome.js +94 -0
  27. package/dist/oauth-sealing.js +29 -0
  28. package/dist/operator-ui/fix-prompts.js +87 -0
  29. package/dist/operator-ui/generated.js +2 -2
  30. package/dist/operator-ui/model.d.ts +46 -1
  31. package/dist/operator-ui/setup-commands.js +53 -0
  32. package/dist/operator-ui/view.js +38 -2
  33. package/dist/program-source.js +205 -0
  34. package/dist/providers/notion.js +2 -2
  35. package/dist/providers/revenuecat.js +32 -5
  36. package/dist/providers/stripe.d.ts +3 -2
  37. package/dist/providers/vercel.js +1 -1
  38. package/dist/registry.d.ts +1 -1
  39. package/dist/registry.js +305 -260
  40. package/dist/routes/activity.js +120 -137
  41. package/dist/routes/credentials.js +174 -163
  42. package/dist/routes/mcp.js +129 -70
  43. package/dist/routes/oauth-management.js +60 -71
  44. package/dist/routes/oauth.js +44 -16
  45. package/dist/routes/operator.js +82 -0
  46. package/dist/routes/shared.d.ts +2 -0
  47. package/dist/routes/ui-data.js +210 -0
  48. package/dist/routes/ui.js +64 -32
  49. package/dist/runtime/admission.js +43 -0
  50. package/dist/runtime/call-admission.js +67 -0
  51. package/dist/runtime/connector-scope.js +72 -0
  52. package/dist/runtime/run.js +174 -0
  53. package/dist/runtime/services.js +130 -0
  54. package/dist/runtime/storage.js +66 -0
  55. package/dist/server.js +111 -89
  56. package/dist/skills.js +1 -1
  57. package/dist/storage/file.js +39 -2
  58. package/dist/storage/memory.js +28 -16
  59. package/dist/timeout.js +17 -47
  60. package/dist/types.d.ts +27 -7
  61. package/dist/ui.d.ts +16 -2
  62. package/dist/ui.js +50 -166
  63. package/dist/url-safety.js +157 -0
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/documentation/architecture.md +184 -10
  67. package/documentation/auth.md +80 -0
  68. package/documentation/code-mode.md +69 -24
  69. package/documentation/meta-tools.md +164 -27
  70. package/ethos.md +44 -47
  71. package/examples/worker/README.md +51 -5
  72. package/examples/worker/src/d1-storage.ts +116 -0
  73. package/examples/worker/src/index.ts +6 -6
  74. package/examples/worker/wrangler.jsonc +16 -4
  75. package/package.json +11 -3
  76. package/templates/node/package.json +1 -1
  77. package/dist/auth/downstream-oauth.d.ts +0 -200
  78. package/dist/catalog-fingerprint.d.ts +0 -19
  79. package/dist/catalog-limits.d.ts +0 -9
  80. package/dist/catalog-service.d.ts +0 -263
  81. package/dist/catalog.d.ts +0 -87
  82. package/dist/concurrency.d.ts +0 -3
  83. package/dist/connectors/guarded-fetch.d.ts +0 -96
  84. package/dist/credential-rules.d.ts +0 -85
  85. package/dist/execute.d.ts +0 -154
  86. package/dist/executor-result.d.ts +0 -10
  87. package/dist/executors/quickjs-child.d.ts +0 -1
  88. package/dist/executors/quickjs-protocol.d.ts +0 -67
  89. package/dist/favicon.d.ts +0 -1
  90. package/dist/identity.d.ts +0 -4
  91. package/dist/invocation.d.ts +0 -74
  92. package/dist/mcp-result.d.ts +0 -8
  93. package/dist/meta-tools.d.ts +0 -129
  94. package/dist/operator-ui/generated.d.ts +0 -2
  95. package/dist/operator-ui/view.d.ts +0 -188
  96. package/dist/result-shapes.d.ts +0 -13
  97. package/dist/retired-toolkits.d.ts +0 -2
  98. package/dist/routes/activity.d.ts +0 -2
  99. package/dist/routes/credentials.d.ts +0 -2
  100. package/dist/routes/mcp.d.ts +0 -10
  101. package/dist/routes/oauth-management.d.ts +0 -2
  102. package/dist/routes/oauth.d.ts +0 -2
  103. package/dist/routes/ui.d.ts +0 -2
  104. package/dist/server.d.ts +0 -9
  105. package/dist/skills.d.ts +0 -44
  106. package/dist/timeout.d.ts +0 -21
  107. package/dist/tool-safety.d.ts +0 -9
@@ -1,188 +0,0 @@
1
- import type { CatalogDriftReport } from "../types.js";
2
- import type { CredentialManagementCapability, UiConnector, UiData } from "./model.js";
3
- /**
4
- * Everything the operator app knows, and every rule for changing it, with no
5
- * DOM in sight. The components render this and nothing else, so the questions
6
- * that matter — what a page shows while it loads, what an identity change
7
- * erases, whether a value may become an href — are answered by functions a test
8
- * can call directly rather than by reading rendered markup back out of a
9
- * browser.
10
- */
11
- export type OperatorPage = "connections" | "activity";
12
- export declare const OPERATOR_PAGES: readonly OperatorPage[];
13
- export declare const PAGE_META: Readonly<Record<OperatorPage, {
14
- path: string;
15
- label: string;
16
- }>>;
17
- export declare function pageForPath(path: string): OperatorPage;
18
- export interface UiActivityActor {
19
- kind?: string;
20
- id?: string;
21
- namespace?: string;
22
- label?: string;
23
- }
24
- export interface UiActivityEvent {
25
- occurredAt: string;
26
- actor?: UiActivityActor;
27
- connectorId: string;
28
- toolName: string;
29
- address: string;
30
- source: string;
31
- outcome: string;
32
- durationMs: number;
33
- attempts: number;
34
- errorCode?: string;
35
- friction?: string;
36
- }
37
- /** A message with the tone that decides its live region: status or alert. */
38
- export interface Notice {
39
- message: string;
40
- tone: "info" | "error";
41
- }
42
- export declare function info(message: string): Notice;
43
- export declare function failure(message: string): Notice;
44
- /**
45
- * A remote collection's four states, named once so every page spells them the
46
- * same way. `idle` is "nobody has asked yet" and is what makes a re-entered
47
- * page fetch again after an identity change.
48
- */
49
- type LoadPhase = "idle" | "loading" | "ready" | "error";
50
- export interface OperatorState {
51
- page: OperatorPage;
52
- /**
53
- * Bumped by every identity change. Async work captures it before awaiting and
54
- * throws its result away if the operator is no longer the one who asked —
55
- * the fence that keeps one identity's data off another identity's screen.
56
- */
57
- generation: number;
58
- /** `loading` until the first /ui/data answer decides gated or ready. */
59
- session: "loading" | "gated" | "ready";
60
- gate: Notice | null;
61
- /** True while a signed-in operator's /ui/data is in flight. */
62
- refreshing: boolean;
63
- /**
64
- * Element id the next render should focus. A rebuilt page has no stable node
65
- * to hand focus to from an event handler, so the request travels through
66
- * state and the shell spends it once the new markup exists.
67
- */
68
- pendingFocus: string | null;
69
- data: UiData | null;
70
- connectorFilter: string;
71
- oauthNotice: Notice | null;
72
- /** Connector id whose OAuth mutation is in flight. */
73
- oauthBusy: string | null;
74
- credentialNotice: Notice | null;
75
- /** Connector id whose credential form is open. */
76
- credentialEditing: string | null;
77
- /** Connector id whose credential mutation is in flight. */
78
- credentialBusy: string | null;
79
- activityPhase: LoadPhase;
80
- activityNotice: Notice | null;
81
- activityEvents: UiActivityEvent[];
82
- activityCursor: string | null;
83
- activitySearch: string;
84
- }
85
- export declare function initialState(page: OperatorPage): OperatorState;
86
- /**
87
- * Drop to the gate and forget the previous operator. Bumping the generation is
88
- * what makes the drop stick: work already in flight for the old identity
89
- * resolves into a state that no longer accepts it.
90
- */
91
- export declare function resetIdentity(state: OperatorState, gate?: Notice | null): OperatorState;
92
- /**
93
- * Leaving a page closes what should not survive it: a one-time secret, a half
94
- * typed credential, and the notices that answered the page just left.
95
- */
96
- export declare function withPage(state: OperatorState, page: OperatorPage): OperatorState;
97
- export declare function credentialUnavailableCopy(capability?: CredentialManagementCapability): string;
98
- export declare function connectorStatusLabel(status: string): string;
99
- export declare function toolCountLabel(count: number): string;
100
- /** The tone a status carries wherever it is rendered as a badge or a tile. */
101
- export type Tone = "ok" | "warn" | "danger" | "neutral";
102
- export declare function connectorStatusTone(status: string): Tone;
103
- /**
104
- * The deployment in four numbers, so the page answers "is anything wrong"
105
- * above the list instead of only inside it. `attention` is what an operator
106
- * can act on now; `unavailable` is what they cannot. A connector still loading
107
- * its catalog counts only toward `total`, since calling it connected or failed
108
- * would be a guess either way.
109
- */
110
- export interface ConnectorSummary {
111
- total: number;
112
- connected: number;
113
- attention: number;
114
- unavailable: number;
115
- tools: number;
116
- /** Connectors whose last observed catalog refresh differed from the manifest. */
117
- drifting: number;
118
- }
119
- export declare function summarizeConnectors(connectors: readonly UiConnector[]): ConnectorSummary;
120
- /**
121
- * The one line above the list. Connected and tool counts are always present;
122
- * the two counts an operator may have to act on appear only when they are not
123
- * zero, so a healthy deployment stays short.
124
- */
125
- export declare function connectorSummaryParts(summary: ConnectorSummary): Array<{
126
- text: string;
127
- tone: Tone;
128
- }>;
129
- /** Who owns this connector's downstream credentials, in two words. */
130
- export declare function authScopeLabel(scope: UiConnector["authScope"]): string;
131
- /**
132
- * What this identity may do with a connector, in one line. Being able to use it
133
- * is implied by seeing it at all, so the sentence covers authentication, which
134
- * is the part that differs between operators.
135
- */
136
- export declare function permissionLabel(connector: UiConnector): string;
137
- /**
138
- * Hosted-provider catalog drift, as an operator reads it
139
- * ([#343](https://github.com/zackbart/connecta/issues/343)).
140
- *
141
- * - `unavailable` — no refresh has been observed in this runtime, so there is
142
- * nothing to report. Deliberately not `clean`: "we have not looked" and "we
143
- * looked and it matches" are different answers, and only one of them is a
144
- * reason to stop worrying.
145
- * - `clean` — a refresh happened and every category counted zero.
146
- * - `warning` — a refresh happened and at least one category did not.
147
- */
148
- export type DriftState = "clean" | "warning" | "unavailable";
149
- export declare function driftTotal(drift?: CatalogDriftReport): number;
150
- export declare function driftState(drift?: CatalogDriftReport): DriftState;
151
- /** Every category with its count, so a clean report still shows its zeros. */
152
- export declare function driftCounts(drift?: CatalogDriftReport): Array<{
153
- key: string;
154
- label: string;
155
- count: number;
156
- }>;
157
- /** One line naming the state and when it was observed. Never what drifted. */
158
- export declare function driftSummary(drift?: CatalogDriftReport): string;
159
- /**
160
- * Only http/https may become a clickable href — the browser half of the gate
161
- * `src/ui.ts` applies before an authorizationUrl is ever serialized. A hostile
162
- * downstream that gets a `javascript:` URL past one of them still meets the
163
- * other, and the caller renders inert text instead of a link.
164
- */
165
- export declare function safeHttpHref(url: string | undefined): string | null;
166
- /** Locale timestamp, or "" for anything that is not a readable date. */
167
- export declare function formatDate(value?: string): string;
168
- export declare function actorLabel(actor?: UiActivityActor): string;
169
- /**
170
- * The stable id behind a friendly label, shown only when a label or namespace
171
- * could otherwise make two different people look like one.
172
- */
173
- export declare function actorStableId(actor?: UiActivityActor): string | null;
174
- export declare function filterActivity(events: UiActivityEvent[], query: string): UiActivityEvent[];
175
- /** Counts only. What the deployment ran, never what it sent or received. */
176
- export declare function activitySummary(events: UiActivityEvent[]): string;
177
- export declare function activityOutcomeClass(outcome: string): string;
178
- /** The one-line detail under an address: source, retries, and friction. */
179
- export declare function activityDetail(event: UiActivityEvent): string;
180
- export declare function credentialStateLabel(credential: {
181
- configured: boolean;
182
- fields?: unknown[];
183
- lastFour?: string;
184
- updatedAt?: string;
185
- }): string;
186
- /** Gate copy for each browser-auth shape, so the sign-in state is never a blank page. */
187
- export declare function gateCopy(kind: string, signedIn: boolean): string;
188
- export {};
@@ -1,13 +0,0 @@
1
- import type { JsonSchema, ToolDef } from "./types.js";
2
- /**
3
- * Passive, process-local output-shape learning. Provider declarations always
4
- * win; observations are an open, optional-field routing aid and never a
5
- * replacement contract.
6
- */
7
- export declare class ObservedOutputSchemas {
8
- private readonly entries;
9
- private cacheKey;
10
- private set;
11
- get(connectorId: string, definition: ToolDef): JsonSchema | undefined;
12
- observe(connectorId: string, definition: ToolDef, value: unknown): void;
13
- }
@@ -1,2 +0,0 @@
1
- /** Fail loudly when JavaScript callers pass the retired audience-scoping keys. */
2
- export declare function assertNoRetiredToolkitOptions(source: string, options: object): void;
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from "./shared.js";
2
- export declare function routeActivity(context: RouteContext): Promise<Response | null>;
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from "./shared.js";
2
- export declare function routeCredentials(context: RouteContext): Promise<Response | null>;
@@ -1,10 +0,0 @@
1
- import { type RouteContext, type ServerOptions } from "./shared.js";
2
- export declare const MCP_CORS_HEADERS: {
3
- "Access-Control-Allow-Origin": string;
4
- "Access-Control-Allow-Methods": string;
5
- "Access-Control-Allow-Headers": string;
6
- };
7
- export declare function createMcpRoute(opts: ServerOptions): {
8
- handle(context: RouteContext): Promise<Response | null>;
9
- rejectOrigin(request: Request): Response | null;
10
- };
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from "./shared.js";
2
- export declare function routeOAuthManagement(context: RouteContext): Promise<Response | null>;
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from "./shared.js";
2
- export declare function routeOAuthCallback(context: RouteContext): Promise<Response | null>;
@@ -1,2 +0,0 @@
1
- import { type RouteContext } from "./shared.js";
2
- export declare function routeUi(context: RouteContext): Promise<Response | null>;
package/dist/server.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { type RuntimeExecutionContext, type ServerOptions } from "./routes/shared.js";
2
- export type { ServerOptions } from "./routes/shared.js";
3
- /**
4
- * Build the Web-standard fetch handler.
5
- *
6
- * Route ordering is the contract: private mutation routes precede wildcard
7
- * OPTIONS, and the security wrapper is applied to every response, including 404s.
8
- */
9
- export declare function createFetchHandler(opts: ServerOptions): (request: Request, runtimeContext?: RuntimeExecutionContext) => Promise<Response>;
package/dist/skills.d.ts DELETED
@@ -1,44 +0,0 @@
1
- import type { Connector } from "./types.js";
2
- export declare const CONNECTA_INSTRUCTIONS = "Choose a route before discovery. A known-address read needs only call_tool. Unknown-address read-only work starts with execute_code to discover, call, and return the answer; use the same route for reduction, multiple or dependent calls, loops, joins, or branches. Keep discovery and calls together when schemas suffice; do not return catalog matches alone. Inspect unfamiliar result shapes with a small sample before proceeding. Only readOnlyHint: true tools run there. Keep catalog inspection and unannotated, write-capable, or destructive work top level: search_tools then call_destructive_tool when a call is needed. After auth_required use authorize_connector. After a truncated direct result use get_result. Guidance is on demand: fetch skills({ name: \"usage\" }) only when these instructions and the tool description are insufficient or a run needs repair.";
3
- /** Shared Connecta routing guidance, byte-identical across deployments. */
4
- export declare const USAGE_SKILL: string;
5
- /** The always-loaded MCP `instructions` string. */
6
- export declare function instructionsFor(): string;
7
- /** True when at least one of `connectors` carries a usage guide. */
8
- export declare function hasConnectorGuides(connectors: readonly Connector[]): boolean;
9
- /** The skill name that fetches `connector`'s guide. */
10
- export declare function connectorSkillName(connectorId: string): string;
11
- /** The connector's guide, or undefined when it declares none (or a blank one). */
12
- export declare function connectorGuide(connector: Connector): string | undefined;
13
- /** Discovery budget for one connector-guide summary, including an ellipsis. */
14
- export declare const GUIDE_SUMMARY_LENGTH = 120;
15
- /** Normalize authored and derived summaries under one construction contract. */
16
- export declare function normalizeGuideSummary(summary: string): string | undefined;
17
- /** Bounded, decision-useful discovery summary for a connector guide. */
18
- export declare function connectorGuideSummary(connector: Connector): string | undefined;
19
- /** Whether correct use always depends on conventions outside the tool schema. */
20
- export declare function connectorGuideRequired(connector: Connector): boolean;
21
- export interface SkillListing {
22
- name: string;
23
- description: string;
24
- }
25
- /**
26
- * Every fetchable skill: the built-in guides plus one entry per connector that
27
- * carries a usage guide. Derived from the connector list passed in — the single
28
- * place guide visibility is decided.
29
- */
30
- export declare function listSkills(connectors: readonly Connector[]): SkillListing[];
31
- export type SkillLookup = {
32
- found: true;
33
- content: string;
34
- } | {
35
- found: false;
36
- message: string;
37
- };
38
- /**
39
- * Resolve one skill name. Built-in names match exactly; connector guides are
40
- * reachable only through the `connector:` prefix. Every miss — unknown name,
41
- * unknown connector, connector without a guide — is an explicit error, never a
42
- * silent fallback to the generic guide.
43
- */
44
- export declare function resolveSkill(name: string, connectors: readonly Connector[]): SkillLookup;
package/dist/timeout.d.ts DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * Generous default bound for a single downstream probe/catalog call. High enough
3
- * to trip only on a pathological hang, not a realistically slow probe.
4
- */
5
- export declare const DEFAULT_PROBE_TIMEOUT_MS = 30000;
6
- /** A finite, positive integer number of milliseconds, or undefined. */
7
- export declare function normalizeTimeoutMs(value: number | undefined): number | undefined;
8
- /** Resolve after `ms`, or false when the caller aborts first. */
9
- export declare function sleep(ms: number, signal?: AbortSignal): Promise<boolean>;
10
- export interface DeadlineOptions {
11
- timeoutMs?: number;
12
- signal?: AbortSignal;
13
- timeoutError: Error;
14
- }
15
- export declare function withDeadline<T>(operation: (signal: AbortSignal) => Promise<T>, options: DeadlineOptions): Promise<T>;
16
- /**
17
- * Give one operation a caller-facing deadline and the matching cancellation
18
- * signal. The timeout rejects with the stable, labelled error while aborting
19
- * any in-flight work that honors the signal.
20
- */
21
- export declare function withAbortableTimeout<T>(operation: (signal: AbortSignal) => Promise<T>, ms: number, label: string): Promise<T>;
@@ -1,9 +0,0 @@
1
- import type { ToolDef } from "./types.js";
2
- /**
3
- * The one fail-closed classification shared by discovery and invocation.
4
- *
5
- * A tool is read-only only when it says so without also saying it is
6
- * destructive. Missing, false, and contradictory annotations all require the
7
- * approval-visible call path.
8
- */
9
- export declare function isExplicitlyReadOnly(definition: ToolDef): boolean;