@zackbart/connecta 0.10.0 → 0.10.2

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 (123) hide show
  1. package/AGENTS.md +113 -0
  2. package/CHANGELOG.md +83 -0
  3. package/README.md +62 -12
  4. package/bin/connecta.mjs +272 -0
  5. package/dist/access-tokens.d.ts +32 -0
  6. package/dist/access-tokens.d.ts.map +1 -0
  7. package/dist/access-tokens.js +225 -0
  8. package/dist/access-tokens.js.map +1 -0
  9. package/dist/catalog-service.d.ts +39 -1
  10. package/dist/catalog-service.d.ts.map +1 -1
  11. package/dist/catalog-service.js +133 -11
  12. package/dist/catalog-service.js.map +1 -1
  13. package/dist/catalog.d.ts +17 -0
  14. package/dist/catalog.d.ts.map +1 -1
  15. package/dist/catalog.js +113 -13
  16. package/dist/catalog.js.map +1 -1
  17. package/dist/execute.d.ts +45 -1
  18. package/dist/execute.d.ts.map +1 -1
  19. package/dist/execute.js +265 -68
  20. package/dist/execute.js.map +1 -1
  21. package/dist/index.d.ts +11 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +12 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/invocation.d.ts.map +1 -1
  26. package/dist/invocation.js +1 -5
  27. package/dist/invocation.js.map +1 -1
  28. package/dist/meta-tools.d.ts +1 -0
  29. package/dist/meta-tools.d.ts.map +1 -1
  30. package/dist/meta-tools.js +410 -12
  31. package/dist/meta-tools.js.map +1 -1
  32. package/dist/operator-ui/generated.d.ts +2 -2
  33. package/dist/operator-ui/generated.d.ts.map +1 -1
  34. package/dist/operator-ui/generated.js +2 -2
  35. package/dist/operator-ui/generated.js.map +1 -1
  36. package/dist/operator-ui/model.d.ts +2 -0
  37. package/dist/operator-ui/model.d.ts.map +1 -1
  38. package/dist/operator-ui/model.js.map +1 -1
  39. package/dist/routes/access-tokens.d.ts +7 -0
  40. package/dist/routes/access-tokens.d.ts.map +1 -0
  41. package/dist/routes/access-tokens.js +84 -0
  42. package/dist/routes/access-tokens.js.map +1 -0
  43. package/dist/routes/shared.d.ts +3 -0
  44. package/dist/routes/shared.d.ts.map +1 -1
  45. package/dist/routes/shared.js.map +1 -1
  46. package/dist/routes/ui.d.ts.map +1 -1
  47. package/dist/routes/ui.js +9 -1
  48. package/dist/routes/ui.js.map +1 -1
  49. package/dist/server.d.ts.map +1 -1
  50. package/dist/server.js +5 -0
  51. package/dist/server.js.map +1 -1
  52. package/dist/skills.d.ts +1 -1
  53. package/dist/skills.d.ts.map +1 -1
  54. package/dist/skills.js +1 -1
  55. package/dist/storage/file.d.ts.map +1 -1
  56. package/dist/storage/file.js +5 -0
  57. package/dist/storage/file.js.map +1 -1
  58. package/dist/storage/memory.d.ts.map +1 -1
  59. package/dist/storage/memory.js +8 -0
  60. package/dist/storage/memory.js.map +1 -1
  61. package/dist/tool-safety.d.ts +10 -0
  62. package/dist/tool-safety.d.ts.map +1 -0
  63. package/dist/tool-safety.js +12 -0
  64. package/dist/tool-safety.js.map +1 -0
  65. package/dist/types.d.ts +5 -0
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/ui.d.ts +4 -4
  68. package/dist/ui.d.ts.map +1 -1
  69. package/dist/ui.js +44 -1
  70. package/dist/ui.js.map +1 -1
  71. package/dist/version.d.ts +1 -1
  72. package/dist/version.js +1 -1
  73. package/documentation/architecture.md +7 -0
  74. package/documentation/auth.md +58 -0
  75. package/documentation/call-admission.md +7 -0
  76. package/documentation/code-first-exploration.md +292 -0
  77. package/documentation/code-mode.md +697 -0
  78. package/documentation/connector-guides.md +7 -0
  79. package/documentation/connectors.md +63 -0
  80. package/documentation/mcp-2026-07-28.md +46 -0
  81. package/documentation/meta-tools.md +167 -0
  82. package/documentation/operations.md +7 -0
  83. package/documentation/operator-ui.md +7 -0
  84. package/documentation/request-admission.md +7 -0
  85. package/documentation/storage-and-credentials.md +54 -0
  86. package/ethos.md +132 -0
  87. package/examples/node/README.md +53 -0
  88. package/examples/node/src/index.ts +73 -0
  89. package/examples/worker/README.md +160 -0
  90. package/examples/worker/src/cloudflare-kv.ts +43 -0
  91. package/examples/worker/src/d1-activity-row.ts +100 -0
  92. package/examples/worker/src/d1-activity.ts +144 -0
  93. package/examples/worker/src/index.ts +136 -0
  94. package/examples/worker/wrangler.jsonc +26 -0
  95. package/package.json +11 -1
  96. package/src/access-tokens.ts +289 -0
  97. package/src/catalog-service.ts +177 -15
  98. package/src/catalog.ts +143 -12
  99. package/src/execute.ts +372 -96
  100. package/src/index.ts +33 -1
  101. package/src/invocation.ts +1 -8
  102. package/src/meta-tools.ts +504 -11
  103. package/src/operator-ui/browser.css +63 -0
  104. package/src/operator-ui/browser.ts +288 -2
  105. package/src/operator-ui/generated.ts +2 -2
  106. package/src/operator-ui/model.ts +6 -0
  107. package/src/routes/access-tokens.ts +115 -0
  108. package/src/routes/shared.ts +3 -0
  109. package/src/routes/ui.ts +9 -0
  110. package/src/server.ts +5 -0
  111. package/src/skills.ts +1 -1
  112. package/src/storage/file.ts +5 -0
  113. package/src/storage/memory.ts +8 -0
  114. package/src/tool-safety.ts +15 -0
  115. package/src/types.ts +5 -0
  116. package/src/ui.ts +50 -1
  117. package/src/version.ts +1 -1
  118. package/templates/node/.env.example +5 -0
  119. package/templates/node/AGENTS.md +19 -0
  120. package/templates/node/README.md +33 -0
  121. package/templates/node/package.json +23 -0
  122. package/templates/node/src/index.ts +43 -0
  123. package/templates/node/tsconfig.json +12 -0
package/src/catalog.ts CHANGED
@@ -1,16 +1,35 @@
1
1
  import type { JsonSchema, ToolDef } from "./types.js";
2
2
 
3
3
  const DEFAULT_DESCRIPTION_LENGTH = 240;
4
+ const DISCOVERY_DESCRIPTION_LENGTH = 160;
5
+ export const MAX_COMPACT_DISCOVERY_SCHEMA_BYTES = 1_024;
6
+ const schemaEncoder = new TextEncoder();
7
+ const COMPACT_DISCOVERY_TRUNCATION = " /* truncated */";
4
8
 
5
9
  export function summarizeDescription(
6
10
  text: string | undefined,
7
11
  full: boolean,
12
+ ): string | undefined {
13
+ return summarizeToLength(text, full, DEFAULT_DESCRIPTION_LENGTH);
14
+ }
15
+
16
+ export function summarizeDiscoveryDescription(
17
+ text: string | undefined,
18
+ full: boolean,
19
+ ): string | undefined {
20
+ return summarizeToLength(text, full, DISCOVERY_DESCRIPTION_LENGTH);
21
+ }
22
+
23
+ function summarizeToLength(
24
+ text: string | undefined,
25
+ full: boolean,
26
+ maxLength: number,
8
27
  ): string | undefined {
9
28
  if (!text) return undefined;
10
29
  if (full) return text;
11
30
  const compact = text.replace(/\s+/g, " ").trim();
12
- if (compact.length <= DEFAULT_DESCRIPTION_LENGTH) return compact;
13
- return `${compact.slice(0, DEFAULT_DESCRIPTION_LENGTH - 1).trimEnd()}…`;
31
+ if (compact.length <= maxLength) return compact;
32
+ return `${compact.slice(0, maxLength - 1).trimEnd()}…`;
14
33
  }
15
34
 
16
35
  function lexicalTokens(text: string): string[] {
@@ -28,6 +47,11 @@ function normalized(text: string): string {
28
47
  return lexicalTokens(text).join(" ");
29
48
  }
30
49
 
50
+ /** Distinct normalized terms in query order, shared by ranking and feedback. */
51
+ export function lexicalQueryTerms(query: string): string[] {
52
+ return [...new Set(lexicalTokens(query))];
53
+ }
54
+
31
55
  /**
32
56
  * Conversational framing selected by the #188 research run before the #189
33
57
  * holdout existed. Action-bearing terms such as get/list/search/find/create
@@ -208,7 +232,7 @@ export function lexicalCorpusStatistics(
208
232
  toolSets: ToolDef[][],
209
233
  query: string,
210
234
  ): LexicalCorpusStatistics {
211
- const terms = [...new Set(lexicalTokens(query))];
235
+ const terms = lexicalQueryTerms(query);
212
236
  if (terms.length === 0) {
213
237
  return {
214
238
  documentCount: toolSets.reduce(
@@ -386,6 +410,10 @@ function renderSchema(
386
410
  defs: Record<string, unknown>,
387
411
  seen: Set<string>,
388
412
  depth: number,
413
+ options: {
414
+ propertyDescriptions: boolean;
415
+ requiredFirst: boolean;
416
+ },
389
417
  ): string {
390
418
  if (depth > 4) return "…";
391
419
  if (schema === null || typeof schema !== "object") {
@@ -404,10 +432,10 @@ function renderSchema(
404
432
  if (Array.isArray(s.allOf)) {
405
433
  const { allOf: _members, ...own } = s;
406
434
  const parts = declaresShape(own)
407
- ? [renderSchema(own, defs, seen, depth)]
435
+ ? [renderSchema(own, defs, seen, depth, options)]
408
436
  : [];
409
437
  for (const member of s.allOf) {
410
- parts.push(renderSchema(member, defs, seen, depth + 1));
438
+ parts.push(renderSchema(member, defs, seen, depth + 1, options));
411
439
  }
412
440
  if (parts.length === 0) return "unknown";
413
441
  if (parts.length === 1) return parts[0] as string;
@@ -420,7 +448,7 @@ function renderSchema(
420
448
  const target = defs[name];
421
449
  if (target === undefined) return name;
422
450
  seen.add(name);
423
- const rendered = renderSchema(target, defs, seen, depth);
451
+ const rendered = renderSchema(target, defs, seen, depth, options);
424
452
  seen.delete(name);
425
453
  return rendered;
426
454
  }
@@ -428,7 +456,9 @@ function renderSchema(
428
456
  const union = (s.oneOf ?? s.anyOf) as unknown[] | undefined;
429
457
  if (Array.isArray(union)) {
430
458
  return (
431
- union.map((u) => renderSchema(u, defs, seen, depth + 1)).join(" | ") ||
459
+ union
460
+ .map((u) => renderSchema(u, defs, seen, depth + 1, options))
461
+ .join(" | ") ||
432
462
  "unknown"
433
463
  );
434
464
  }
@@ -444,7 +474,7 @@ function renderSchema(
444
474
  const type = s.type;
445
475
  if (type === "array" || s.items) {
446
476
  const items = s.items
447
- ? renderSchema(s.items, defs, seen, depth + 1)
477
+ ? renderSchema(s.items, defs, seen, depth + 1, options)
448
478
  : "unknown";
449
479
  return `${items}[]`;
450
480
  }
@@ -453,17 +483,31 @@ function renderSchema(
453
483
  const required = new Set(
454
484
  (Array.isArray(s.required) ? s.required : []) as string[],
455
485
  );
456
- const keys = Object.keys(props);
486
+ const declaredKeys = Object.keys(props);
487
+ const keys = options.requiredFirst
488
+ ? [
489
+ ...declaredKeys.filter((key) => required.has(key)),
490
+ ...declaredKeys.filter((key) => !required.has(key)),
491
+ ]
492
+ : declaredKeys;
457
493
  if (keys.length === 0) return "{}";
458
494
  return `{ ${keys
459
495
  .map((key) => {
460
496
  const optional = required.has(key) ? "" : "?";
461
- const rendered = renderSchema(props[key], defs, seen, depth + 1);
497
+ const rendered = renderSchema(
498
+ props[key],
499
+ defs,
500
+ seen,
501
+ depth + 1,
502
+ options,
503
+ );
462
504
  const description = (
463
505
  props[key] as Record<string, unknown> | null
464
506
  )?.description;
465
507
  const comment =
466
- typeof description === "string" ? ` // ${description}` : "";
508
+ options.propertyDescriptions && typeof description === "string"
509
+ ? ` // ${description}`
510
+ : "";
467
511
  return `${key}${optional}: ${rendered}${comment}`;
468
512
  })
469
513
  .join(", ")} }`;
@@ -485,7 +529,10 @@ export function compactSchema(schema: JsonSchema): string {
485
529
  };
486
530
  let rendered: string;
487
531
  try {
488
- rendered = renderSchema(schema, defs, new Set(), 0);
532
+ rendered = renderSchema(schema, defs, new Set(), 0, {
533
+ propertyDescriptions: true,
534
+ requiredFirst: false,
535
+ });
489
536
  } catch {
490
537
  rendered = JSON.stringify(schema);
491
538
  }
@@ -493,6 +540,90 @@ export function compactSchema(schema: JsonSchema): string {
493
540
  return rendered;
494
541
  }
495
542
 
543
+ export interface CompactDiscoverySchema {
544
+ text: string;
545
+ truncated: boolean;
546
+ }
547
+
548
+ const compactDiscoverySchemas = new WeakMap<
549
+ JsonSchema,
550
+ CompactDiscoverySchema
551
+ >();
552
+
553
+ /**
554
+ * A valid, bounded replacement for a discovery shape too large to carry.
555
+ *
556
+ * Required object keys come first and every retained key is JSON-quoted, so
557
+ * arbitrary downstream names remain valid TypeScript property signatures.
558
+ * Types become `unknown`: pretending a severed nested type is exact would be
559
+ * worse than making the existing truncation flag's recovery route explicit.
560
+ */
561
+ function truncatedDiscoverySchema(schema: JsonSchema): string {
562
+ const keys = schemaObjectKeys(schema);
563
+ if (!keys) return `unknown${COMPACT_DISCOVERY_TRUNCATION}`;
564
+ const required = new Set(keys.required);
565
+ const ordered = [
566
+ ...keys.properties.filter((key) => required.has(key)),
567
+ ...keys.properties.filter((key) => !required.has(key)),
568
+ ];
569
+ const parts: string[] = [];
570
+ for (const key of ordered) {
571
+ const part = `${JSON.stringify(key)}${required.has(key) ? "" : "?"}: unknown`;
572
+ const candidate = `{ ${[...parts, part].join(", ")} }${COMPACT_DISCOVERY_TRUNCATION}`;
573
+ if (
574
+ schemaEncoder.encode(candidate).length >
575
+ MAX_COMPACT_DISCOVERY_SCHEMA_BYTES
576
+ ) {
577
+ break;
578
+ }
579
+ parts.push(part);
580
+ }
581
+ if (parts.length === 0 && ordered.length > 0) {
582
+ return `unknown${COMPACT_DISCOVERY_TRUNCATION}`;
583
+ }
584
+ return `{ ${parts.join(", ")} }${COMPACT_DISCOVERY_TRUNCATION}`;
585
+ }
586
+
587
+ /**
588
+ * Render the schema shape carried by search results.
589
+ *
590
+ * Search is a routing step, so repeated property prose does not earn its
591
+ * context cost there. Required inputs render first, and the result has a hard
592
+ * UTF-8 budget; exact JSON and the prose-rich compact rendering remain
593
+ * available through the existing full retrieval paths.
594
+ */
595
+ export function compactDiscoverySchema(
596
+ schema: JsonSchema,
597
+ ): CompactDiscoverySchema {
598
+ const cached = compactDiscoverySchemas.get(schema);
599
+ if (cached) return cached;
600
+ const defs = {
601
+ ...(schema.$defs as Record<string, unknown>),
602
+ ...(schema.definitions as Record<string, unknown>),
603
+ };
604
+ let rendered: string;
605
+ try {
606
+ rendered = renderSchema(schema, defs, new Set(), 0, {
607
+ propertyDescriptions: false,
608
+ requiredFirst: true,
609
+ });
610
+ } catch {
611
+ rendered = JSON.stringify(schema);
612
+ }
613
+ const bytes = schemaEncoder.encode(rendered);
614
+ let result: CompactDiscoverySchema;
615
+ if (bytes.length <= MAX_COMPACT_DISCOVERY_SCHEMA_BYTES) {
616
+ result = { text: rendered, truncated: false };
617
+ } else {
618
+ result = {
619
+ text: truncatedDiscoverySchema(schema),
620
+ truncated: true,
621
+ };
622
+ }
623
+ compactDiscoverySchemas.set(schema, result);
624
+ return result;
625
+ }
626
+
496
627
  /** The property and required names a schema resolves to, or undefined. */
497
628
  export interface SchemaObjectKeys {
498
629
  properties: string[];