@zackbart/connecta 0.7.8 → 0.8.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 (187) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +67 -144
  3. package/dist/activity.d.ts +1 -1
  4. package/dist/activity.d.ts.map +1 -1
  5. package/dist/activity.js.map +1 -1
  6. package/dist/auth/bearer.d.ts +1 -1
  7. package/dist/auth/bearer.js +4 -4
  8. package/dist/auth/bearer.js.map +1 -1
  9. package/dist/auth/clerk.d.ts +1 -1
  10. package/dist/auth/clerk.js +1 -1
  11. package/dist/call-admission.d.ts +81 -0
  12. package/dist/call-admission.d.ts.map +1 -0
  13. package/dist/call-admission.js +345 -0
  14. package/dist/call-admission.js.map +1 -0
  15. package/dist/catalog-fingerprint.d.ts +20 -0
  16. package/dist/catalog-fingerprint.d.ts.map +1 -0
  17. package/dist/catalog-fingerprint.js +34 -0
  18. package/dist/catalog-fingerprint.js.map +1 -0
  19. package/dist/catalog-limits.d.ts +10 -0
  20. package/dist/catalog-limits.d.ts.map +1 -0
  21. package/dist/catalog-limits.js +10 -0
  22. package/dist/catalog-limits.js.map +1 -0
  23. package/dist/catalog-service.d.ts +138 -0
  24. package/dist/catalog-service.d.ts.map +1 -0
  25. package/dist/catalog-service.js +407 -0
  26. package/dist/catalog-service.js.map +1 -0
  27. package/dist/catalog.js +2 -2
  28. package/dist/catalog.js.map +1 -1
  29. package/dist/concurrency.d.ts +4 -0
  30. package/dist/concurrency.d.ts.map +1 -0
  31. package/dist/concurrency.js +31 -0
  32. package/dist/concurrency.js.map +1 -0
  33. package/dist/connectors/api.d.ts +3 -1
  34. package/dist/connectors/api.d.ts.map +1 -1
  35. package/dist/connectors/api.js +22 -11
  36. package/dist/connectors/api.js.map +1 -1
  37. package/dist/connectors/remote-mcp.d.ts +3 -1
  38. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  39. package/dist/connectors/remote-mcp.js +44 -18
  40. package/dist/connectors/remote-mcp.js.map +1 -1
  41. package/dist/credential-health.d.ts +0 -22
  42. package/dist/credential-health.d.ts.map +1 -1
  43. package/dist/credential-health.js +14 -10
  44. package/dist/credential-health.js.map +1 -1
  45. package/dist/credentials.d.ts +3 -2
  46. package/dist/credentials.d.ts.map +1 -1
  47. package/dist/errors.d.ts +1 -1
  48. package/dist/errors.d.ts.map +1 -1
  49. package/dist/errors.js.map +1 -1
  50. package/dist/execute.d.ts +9 -8
  51. package/dist/execute.d.ts.map +1 -1
  52. package/dist/execute.js +144 -291
  53. package/dist/execute.js.map +1 -1
  54. package/dist/executor-result.d.ts +0 -3
  55. package/dist/executor-result.d.ts.map +1 -1
  56. package/dist/executor-result.js +2 -2
  57. package/dist/executor-result.js.map +1 -1
  58. package/dist/executors/quickjs-child.js +3 -3
  59. package/dist/executors/quickjs-child.js.map +1 -1
  60. package/dist/executors/quickjs-protocol.d.ts +4 -1
  61. package/dist/executors/quickjs-protocol.d.ts.map +1 -1
  62. package/dist/executors/quickjs-runtime.d.ts.map +1 -1
  63. package/dist/executors/quickjs-runtime.js +7 -2
  64. package/dist/executors/quickjs-runtime.js.map +1 -1
  65. package/dist/executors/quickjs.d.ts.map +1 -1
  66. package/dist/executors/quickjs.js +4 -1
  67. package/dist/executors/quickjs.js.map +1 -1
  68. package/dist/favicon.js +2 -2
  69. package/dist/favicon.js.map +1 -1
  70. package/dist/index.d.ts +6 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +45 -17
  73. package/dist/index.js.map +1 -1
  74. package/dist/invocation.d.ts +96 -0
  75. package/dist/invocation.d.ts.map +1 -0
  76. package/dist/invocation.js +369 -0
  77. package/dist/invocation.js.map +1 -0
  78. package/dist/meta-tools.d.ts +11 -86
  79. package/dist/meta-tools.d.ts.map +1 -1
  80. package/dist/meta-tools.js +145 -485
  81. package/dist/meta-tools.js.map +1 -1
  82. package/dist/operator-ui/generated.d.ts +3 -0
  83. package/dist/operator-ui/generated.d.ts.map +1 -0
  84. package/dist/operator-ui/generated.js +5 -0
  85. package/dist/operator-ui/generated.js.map +1 -0
  86. package/dist/operator-ui/model.d.ts +94 -0
  87. package/dist/operator-ui/model.d.ts.map +1 -0
  88. package/dist/operator-ui/model.js +28 -0
  89. package/dist/operator-ui/model.js.map +1 -0
  90. package/dist/registry.d.ts +47 -6
  91. package/dist/registry.d.ts.map +1 -1
  92. package/dist/registry.js +356 -35
  93. package/dist/registry.js.map +1 -1
  94. package/dist/routes/activity.d.ts +3 -0
  95. package/dist/routes/activity.d.ts.map +1 -0
  96. package/dist/routes/activity.js +173 -0
  97. package/dist/routes/activity.js.map +1 -0
  98. package/dist/routes/credentials.d.ts +3 -0
  99. package/dist/routes/credentials.d.ts.map +1 -0
  100. package/dist/routes/credentials.js +181 -0
  101. package/dist/routes/credentials.js.map +1 -0
  102. package/dist/routes/mcp.d.ts +8 -0
  103. package/dist/routes/mcp.d.ts.map +1 -0
  104. package/dist/routes/mcp.js +383 -0
  105. package/dist/routes/mcp.js.map +1 -0
  106. package/dist/routes/oauth.d.ts +4 -0
  107. package/dist/routes/oauth.d.ts.map +1 -0
  108. package/dist/routes/oauth.js +268 -0
  109. package/dist/routes/oauth.js.map +1 -0
  110. package/dist/routes/shared.d.ts +97 -0
  111. package/dist/routes/shared.d.ts.map +1 -0
  112. package/dist/routes/shared.js +199 -0
  113. package/dist/routes/shared.js.map +1 -0
  114. package/dist/routes/ui.d.ts +3 -0
  115. package/dist/routes/ui.d.ts.map +1 -0
  116. package/dist/routes/ui.js +122 -0
  117. package/dist/routes/ui.js.map +1 -0
  118. package/dist/server.d.ts +9 -40
  119. package/dist/server.d.ts.map +1 -1
  120. package/dist/server.js +67 -1292
  121. package/dist/server.js.map +1 -1
  122. package/dist/skills.d.ts +0 -15
  123. package/dist/skills.d.ts.map +1 -1
  124. package/dist/skills.js +6 -5
  125. package/dist/skills.js.map +1 -1
  126. package/dist/storage/file.d.ts.map +1 -1
  127. package/dist/storage/file.js +3 -1
  128. package/dist/storage/file.js.map +1 -1
  129. package/dist/storage/memory.d.ts.map +1 -1
  130. package/dist/storage/memory.js +3 -1
  131. package/dist/storage/memory.js.map +1 -1
  132. package/dist/toolkits.d.ts +0 -22
  133. package/dist/toolkits.d.ts.map +1 -1
  134. package/dist/toolkits.js +2 -2
  135. package/dist/toolkits.js.map +1 -1
  136. package/dist/types.d.ts +64 -2
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/ui.d.ts +3 -93
  139. package/dist/ui.d.ts.map +1 -1
  140. package/dist/ui.js +26 -1389
  141. package/dist/ui.js.map +1 -1
  142. package/dist/version.d.ts +1 -1
  143. package/dist/version.js +1 -1
  144. package/package.json +15 -8
  145. package/src/activity.ts +5 -1
  146. package/src/auth/bearer.ts +4 -4
  147. package/src/auth/clerk.ts +1 -1
  148. package/src/call-admission.ts +522 -0
  149. package/src/catalog-fingerprint.ts +52 -0
  150. package/src/catalog-limits.ts +11 -0
  151. package/src/catalog-service.ts +601 -0
  152. package/src/catalog.ts +2 -2
  153. package/src/concurrency.ts +39 -0
  154. package/src/connectors/api.ts +25 -11
  155. package/src/connectors/remote-mcp.ts +55 -21
  156. package/src/credential-health.ts +13 -10
  157. package/src/credentials.ts +2 -2
  158. package/src/errors.ts +1 -1
  159. package/src/execute.ts +194 -377
  160. package/src/executor-result.ts +2 -2
  161. package/src/executors/quickjs-child.ts +8 -4
  162. package/src/executors/quickjs-protocol.ts +1 -1
  163. package/src/executors/quickjs-runtime.ts +5 -1
  164. package/src/executors/quickjs.ts +11 -8
  165. package/src/favicon.ts +2 -2
  166. package/src/index.ts +54 -17
  167. package/src/invocation.ts +527 -0
  168. package/src/meta-tools.ts +369 -797
  169. package/src/operator-ui/browser.css +413 -0
  170. package/src/operator-ui/browser.ts +1121 -0
  171. package/src/operator-ui/generated.ts +4 -0
  172. package/src/operator-ui/model.ts +127 -0
  173. package/src/registry.ts +489 -44
  174. package/src/routes/activity.ts +220 -0
  175. package/src/routes/credentials.ts +266 -0
  176. package/src/routes/mcp.ts +485 -0
  177. package/src/routes/oauth.ts +328 -0
  178. package/src/routes/shared.ts +330 -0
  179. package/src/routes/ui.ts +153 -0
  180. package/src/server.ts +70 -1702
  181. package/src/skills.ts +6 -5
  182. package/src/storage/file.ts +3 -1
  183. package/src/storage/memory.ts +3 -1
  184. package/src/toolkits.ts +2 -2
  185. package/src/types.ts +70 -2
  186. package/src/ui.ts +52 -1489
  187. package/src/version.ts +1 -1
@@ -1,14 +1,14 @@
1
1
  import type { ExecuteResult } from "./types.js";
2
2
 
3
3
  /** ~6k tokens. Sandbox code should filter data down before returning. */
4
- export const MAX_EXECUTE_RESULT_CHARS = 24_000;
4
+ const MAX_EXECUTE_RESULT_CHARS = 24_000;
5
5
  export const MAX_EXECUTE_LOG_CHARS = 4_000;
6
6
 
7
7
  function msg(err: unknown): string {
8
8
  return err instanceof Error ? err.message : String(err);
9
9
  }
10
10
 
11
- export function serializeExecuteValue(value: unknown): string {
11
+ function serializeExecuteValue(value: unknown): string {
12
12
  const serialized = JSON.stringify(value, null, 2);
13
13
  return serialized === undefined ? String(value) : serialized;
14
14
  }
@@ -37,7 +37,11 @@ function send(message: ChildToParentMessage): void {
37
37
  process.send(message);
38
38
  }
39
39
 
40
- function provider(name: string, jobId: number): ExecutorProvider {
40
+ function provider(
41
+ name: string,
42
+ jobId: number,
43
+ prelude?: string,
44
+ ): ExecutorProvider {
41
45
  const functions = new Proxy(
42
46
  Object.create(null) as ExecutorProvider["fns"],
43
47
  {
@@ -72,7 +76,7 @@ function provider(name: string, jobId: number): ExecutorProvider {
72
76
  : undefined,
73
77
  },
74
78
  );
75
- return { name, fns: functions };
79
+ return { name, fns: functions, ...(prelude ? { prelude } : {}) };
76
80
  }
77
81
 
78
82
  function fixedTransportFailure(message: string): ExecutionPayload {
@@ -90,8 +94,8 @@ async function run(payload: RunPayload): Promise<void> {
90
94
  }
91
95
  activeJobId = payload.id;
92
96
  try {
93
- const providers = payload.providerNames.map((name) =>
94
- provider(name, payload.id),
97
+ const providers = payload.providers.map(({ name, prelude }) =>
98
+ provider(name, payload.id, prelude),
95
99
  );
96
100
  const raw = await executeQuickJs(
97
101
  payload.code,
@@ -15,7 +15,7 @@ export const MAX_QUICKJS_HOST_RPC_BYTES = 256 * 1024;
15
15
  export interface RunPayload {
16
16
  id: number;
17
17
  code: string;
18
- providerNames: string[];
18
+ providers: Array<{ name: string; prelude?: string }>;
19
19
  options: QuickJsRuntimeOptions;
20
20
  }
21
21
 
@@ -88,7 +88,8 @@ function exceedsUtf8ByteLimit(value: string, limit: number): boolean {
88
88
  export function normalizeCode(code: string): string {
89
89
  let c = code.trim();
90
90
  const fence = /^```[\w-]*\s*\n([\s\S]*?)\n?```$/.exec(c);
91
- if (fence) c = fence[1].trim();
91
+ const fencedCode = fence?.[1];
92
+ if (fencedCode !== undefined) c = fencedCode.trim();
92
93
  // Sniff for an existing function expression past any leading comments/blank
93
94
  // lines — models routinely prefix their code with a `//` or `/* */` note,
94
95
  // which would otherwise defeat the detection and wrap the whole thing.
@@ -122,6 +123,9 @@ function setupScript(providers: ExecutorProvider[]): string {
122
123
  const ns = JSON.stringify(p.name);
123
124
  lines.push(`globalThis[${ns}] = __namespace(${ns});`);
124
125
  }
126
+ for (const p of providers) {
127
+ if (p.prelude) lines.push(p.prelude);
128
+ }
125
129
  lines.push(`delete globalThis.__namespace;`);
126
130
  return lines.join("\n");
127
131
  }
@@ -67,13 +67,13 @@ interface ActiveRun {
67
67
  }
68
68
 
69
69
  interface ChildSlot {
70
- child?: ChildProcess;
71
- ready?: Promise<void>;
72
- resolveReady?: () => void;
73
- rejectReady?: (error: Error) => void;
74
- readyTimer?: ReturnType<typeof setTimeout>;
75
- active?: ActiveRun;
76
- expectedExit?: ChildProcess;
70
+ child?: ChildProcess | undefined;
71
+ ready?: Promise<void> | undefined;
72
+ resolveReady?: (() => void) | undefined;
73
+ rejectReady?: ((error: Error) => void) | undefined;
74
+ readyTimer?: ReturnType<typeof setTimeout> | undefined;
75
+ active?: ActiveRun | undefined;
76
+ expectedExit?: ChildProcess | undefined;
77
77
  consecutiveCrashes: number;
78
78
  notBefore: number;
79
79
  }
@@ -360,7 +360,10 @@ class QuickJsChildPool implements AdmittingExecutor {
360
360
  {
361
361
  id,
362
362
  code,
363
- providerNames: providers.map((item) => item.name),
363
+ providers: providers.map((item) => ({
364
+ name: item.name,
365
+ ...(item.prelude ? { prelude: item.prelude } : {}),
366
+ })),
364
367
  options: this.runtimeOptions,
365
368
  } satisfies RunPayload,
366
369
  "QuickJS run payload",
package/src/favicon.ts CHANGED
@@ -41,8 +41,8 @@ function buildIco(): Uint8Array {
41
41
  const pixel = pixels + (row * size + x) * 4;
42
42
  ico[pixel + 3] = opaque ? 255 : 0;
43
43
  if (!opaque) {
44
- ico[mask + row * maskRowLength + Math.floor(x / 8)] |=
45
- 0x80 >> (x % 8);
44
+ const maskIndex = mask + row * maskRowLength + Math.floor(x / 8);
45
+ ico[maskIndex] = (ico[maskIndex] ?? 0) | (0x80 >> (x % 8));
46
46
  }
47
47
  }
48
48
  }
package/src/index.ts CHANGED
@@ -72,6 +72,11 @@ export interface ConnectaCredentialsConfig {
72
72
 
73
73
  /** Tool-catalog caching, persistence, stale fallback, and probe deadlines. */
74
74
  export interface ConnectaDiscoveryConfig {
75
+ /**
76
+ * Maximum connector catalogs/status probes fetched at once by discovery
77
+ * operations. Default 4.
78
+ */
79
+ concurrency?: number;
75
80
  /** Tool-list cache TTL (seconds). Default 300. */
76
81
  catalogTtlSeconds?: number;
77
82
  /**
@@ -546,13 +551,25 @@ export function createConnecta(config: ConnectaConfig): Connecta {
546
551
  const registry = new Registry(config.connectors, {
547
552
  storage,
548
553
  logger,
549
- credentialVault,
550
- toolCacheTtlSeconds: config.discovery?.catalogTtlSeconds,
551
- persistToolCatalog: config.discovery?.persistCatalog,
552
- toolCatalogStaleSeconds: config.discovery?.staleCatalogSeconds,
553
- maxResultBytes: config.calls?.maxResultBytes,
554
- maxBatchResultBytes: config.calls?.maxBatchResultBytes,
555
- credentialHealth: config.credentials?.health,
554
+ ...(credentialVault !== undefined ? { credentialVault } : {}),
555
+ ...(config.discovery?.catalogTtlSeconds !== undefined
556
+ ? { toolCacheTtlSeconds: config.discovery.catalogTtlSeconds }
557
+ : {}),
558
+ ...(config.discovery?.persistCatalog !== undefined
559
+ ? { persistToolCatalog: config.discovery.persistCatalog }
560
+ : {}),
561
+ ...(config.discovery?.staleCatalogSeconds !== undefined
562
+ ? { toolCatalogStaleSeconds: config.discovery.staleCatalogSeconds }
563
+ : {}),
564
+ ...(config.calls?.maxResultBytes !== undefined
565
+ ? { maxResultBytes: config.calls.maxResultBytes }
566
+ : {}),
567
+ ...(config.calls?.maxBatchResultBytes !== undefined
568
+ ? { maxBatchResultBytes: config.calls.maxBatchResultBytes }
569
+ : {}),
570
+ ...(config.credentials?.health !== undefined
571
+ ? { credentialHealth: config.credentials.health }
572
+ : {}),
556
573
  });
557
574
  // Throws on every structural mistake it can see (see resolveToolkits): a
558
575
  // typo must not become a scope the operator never wrote. Note this is about
@@ -588,23 +605,38 @@ export function createConnecta(config: ConnectaConfig): Connecta {
588
605
  const handler = createFetchHandler({
589
606
  registry,
590
607
  auth: inboundAuth,
591
- publicUrl: config.publicUrl,
608
+ ...(config.publicUrl !== undefined ? { publicUrl: config.publicUrl } : {}),
592
609
  serverInfo: {
593
610
  ...config.serverInfo,
594
611
  name: config.serverInfo?.name ?? "connecta",
595
612
  version: config.serverInfo?.version ?? CONNECTA_VERSION,
596
613
  },
597
614
  logger,
598
- activity: config.activity?.store,
599
- activityReadGate: config.activity?.readGate,
600
- activityDeploymentId: config.activity?.deploymentId,
601
- executor,
615
+ ...(config.activity?.store !== undefined
616
+ ? { activity: config.activity.store }
617
+ : {}),
618
+ ...(config.activity?.readGate !== undefined
619
+ ? { activityReadGate: config.activity.readGate }
620
+ : {}),
621
+ ...(config.activity?.deploymentId !== undefined
622
+ ? { activityDeploymentId: config.activity.deploymentId }
623
+ : {}),
624
+ ...(executor !== undefined ? { executor } : {}),
602
625
  requestAdmission,
603
- defaultToolTimeoutMs: config.calls?.defaultTimeoutMs,
604
- probeTimeoutMs: config.discovery?.probeTimeoutMs,
605
- credentialVault,
606
- deploymentInfo: config.deploymentInfo,
607
- branding: config.branding,
626
+ ...(config.calls?.defaultTimeoutMs !== undefined
627
+ ? { defaultToolTimeoutMs: config.calls.defaultTimeoutMs }
628
+ : {}),
629
+ ...(config.discovery?.probeTimeoutMs !== undefined
630
+ ? { probeTimeoutMs: config.discovery.probeTimeoutMs }
631
+ : {}),
632
+ ...(config.discovery?.concurrency !== undefined
633
+ ? { discoveryConcurrency: config.discovery.concurrency }
634
+ : {}),
635
+ ...(credentialVault !== undefined ? { credentialVault } : {}),
636
+ ...(config.deploymentInfo !== undefined
637
+ ? { deploymentInfo: config.deploymentInfo }
638
+ : {}),
639
+ ...(config.branding !== undefined ? { branding: config.branding } : {}),
608
640
  ...(toolkits ? { toolkits } : {}),
609
641
  });
610
642
  let closePromise: Promise<void> | undefined;
@@ -648,6 +680,7 @@ export function createConnecta(config: ConnectaConfig): Connecta {
648
680
  closePromise ??= Promise.resolve().then(async () => {
649
681
  requestAdmission.close();
650
682
  codeAdmission?.close();
683
+ registry.closeCallAdmission();
651
684
  await config.executor?.close?.();
652
685
  });
653
686
  await closePromise;
@@ -698,6 +731,10 @@ export type {
698
731
  export type { ApiOptions, ApiTool } from "./connectors/api.js";
699
732
  export type {
700
733
  Connector,
734
+ ConnectorCallAdmissionInput,
735
+ ConnectorCallAdmissionPolicy,
736
+ ConnectorCallAdmissionRule,
737
+ ConnectorRollingWindowBudget,
701
738
  ConnectaBranding,
702
739
  ConnectorCredentialAccess,
703
740
  ConnectorCredentialConfig,