@zackbart/connecta 0.10.5 → 0.10.6

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 (67) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/dist/activity.d.ts +11 -1
  3. package/dist/activity.d.ts.map +1 -1
  4. package/dist/activity.js +44 -3
  5. package/dist/activity.js.map +1 -1
  6. package/dist/catalog-service.d.ts +39 -0
  7. package/dist/catalog-service.d.ts.map +1 -1
  8. package/dist/catalog-service.js +72 -11
  9. package/dist/catalog-service.js.map +1 -1
  10. package/dist/errors.d.ts +48 -1
  11. package/dist/errors.d.ts.map +1 -1
  12. package/dist/errors.js +67 -0
  13. package/dist/errors.js.map +1 -1
  14. package/dist/execute.d.ts +72 -0
  15. package/dist/execute.d.ts.map +1 -1
  16. package/dist/execute.js +162 -9
  17. package/dist/execute.js.map +1 -1
  18. package/dist/index.d.ts +15 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +6 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/invocation.d.ts +9 -2
  23. package/dist/invocation.d.ts.map +1 -1
  24. package/dist/invocation.js +59 -29
  25. package/dist/invocation.js.map +1 -1
  26. package/dist/meta-tools.d.ts +5 -1
  27. package/dist/meta-tools.d.ts.map +1 -1
  28. package/dist/meta-tools.js +171 -26
  29. package/dist/meta-tools.js.map +1 -1
  30. package/dist/operator-ui/generated.d.ts +1 -1
  31. package/dist/operator-ui/generated.d.ts.map +1 -1
  32. package/dist/operator-ui/generated.js +1 -1
  33. package/dist/operator-ui/generated.js.map +1 -1
  34. package/dist/registry.d.ts +11 -0
  35. package/dist/registry.d.ts.map +1 -1
  36. package/dist/registry.js +5 -2
  37. package/dist/registry.js.map +1 -1
  38. package/dist/routes/mcp.d.ts.map +1 -1
  39. package/dist/routes/mcp.js +9 -0
  40. package/dist/routes/mcp.js.map +1 -1
  41. package/dist/routes/shared.d.ts +4 -0
  42. package/dist/routes/shared.d.ts.map +1 -1
  43. package/dist/routes/shared.js.map +1 -1
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/documentation/code-mode.md +119 -31
  47. package/documentation/meta-tools.md +79 -3
  48. package/documentation/rich-output-design.md +212 -0
  49. package/ethos.md +17 -19
  50. package/examples/worker/README.md +11 -3
  51. package/examples/worker/src/d1-activity-row.ts +40 -0
  52. package/examples/worker/src/d1-activity.ts +3 -2
  53. package/package.json +1 -1
  54. package/src/activity.ts +64 -3
  55. package/src/catalog-service.ts +135 -22
  56. package/src/errors.ts +102 -1
  57. package/src/execute.ts +238 -9
  58. package/src/index.ts +22 -0
  59. package/src/invocation.ts +59 -17
  60. package/src/meta-tools.ts +211 -30
  61. package/src/operator-ui/browser.ts +10 -2
  62. package/src/operator-ui/generated.ts +1 -1
  63. package/src/registry.ts +5 -2
  64. package/src/routes/mcp.ts +9 -0
  65. package/src/routes/shared.ts +4 -0
  66. package/src/version.ts +1 -1
  67. package/templates/node/package.json +1 -1
package/dist/errors.d.ts CHANGED
@@ -15,6 +15,22 @@ export interface ArgumentValidationDetails {
15
15
  truncated?: true;
16
16
  }
17
17
  export declare const MAX_ARGUMENT_VALIDATION_ISSUES = 3;
18
+ /**
19
+ * Clamp a string to a UTF-8 byte budget, appending `…` when it clipped.
20
+ * Short strings — the common case, and the one that has to stay exact — are
21
+ * returned unchanged and untagged.
22
+ */
23
+ export declare function boundedEchoText(value: string, maxBytes?: number): string;
24
+ /**
25
+ * `{ args }` when the caller's arguments fit {@link MAX_ECHOED_ARGS_BYTES},
26
+ * `{}` when they do not. All or nothing: a clipped echo would be a *different*
27
+ * call than the one that was refused, and the routes this feeds end at a human
28
+ * approving one. Unserializable arguments are treated the same way as oversized
29
+ * ones — there is nothing honest to put in the field.
30
+ */
31
+ export declare function echoedCallArgs(args: unknown): {
32
+ args?: unknown;
33
+ };
18
34
  /** Agent-visible recovery class attached only to `auth_required` failures. */
19
35
  export type AuthRecoveryMode = "oauth" | "operator_config" | "unavailable";
20
36
  /**
@@ -80,10 +96,41 @@ export interface CallErrorDetails {
80
96
  tool: "search_tools";
81
97
  arguments: {
82
98
  query: string;
83
- connector: string;
99
+ connector?: string;
84
100
  includeSchemas: "compact";
85
101
  };
86
102
  purpose: string;
103
+ } | {
104
+ tool: "call_destructive_tool";
105
+ arguments: {
106
+ address: string;
107
+ /**
108
+ * The caller's own arguments, echoed only when they fit
109
+ * {@link MAX_ECHOED_ARGS_BYTES} — and then whole, never clipped. Absent
110
+ * means "re-send exactly what you sent": a half-copied argument object
111
+ * routed into a human approval prompt would describe a call nobody made.
112
+ */
113
+ args?: unknown;
114
+ };
115
+ purpose: string;
116
+ } | {
117
+ /**
118
+ * The same scoped discovery as the `search_tools` route above, addressed to
119
+ * a caller inside `execute_code`, which cannot call a tool. Which of the two
120
+ * a routing failure emits follows the route the caller took, not the
121
+ * deployment's advertised surface.
122
+ */
123
+ function: "connecta.search";
124
+ arguments: {
125
+ query: string;
126
+ connector?: string;
127
+ includeSchemas: "compact";
128
+ };
129
+ purpose: string;
130
+ } | {
131
+ function: "connecta.call";
132
+ addresses: string[];
133
+ purpose: string;
87
134
  };
88
135
  /** Explicit retry guidance; recovery never retries or mutates by itself. */
89
136
  retry?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,eAAe,GACf,cAAc,GACd,aAAa,GACb,cAAc,GACd,4BAA4B,GAC5B,uBAAuB,CAAC;AAE5B,yEAAyE;AACzE,MAAM,WAAW,uBAAuB;IACtC,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAClC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;SAAE,CAAC;QACjC,eAAe,EAAE,MAAM,CAAC;KACzB,GAAG;QACF,IAAI,EAAE,cAAc,CAAC;QACrB,SAAS,EAAE;YACT,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,cAAc,EAAE,SAAS,CAAC;SAC3B,CAAC;QACF,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG;QACF,IAAI,EAAE,uBAAuB,CAAC;QAC9B,SAAS,EAAE;YACT,OAAO,EAAE,MAAM,CAAC;YAChB;;;;;eAKG;YACH,IAAI,CAAC,EAAE,OAAO,CAAC;SAChB,CAAC;QACF,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG;QACF;;;;;WAKG;QACH,QAAQ,EAAE,iBAAiB,CAAC;QAC5B,SAAS,EAAE;YACT,KAAK,EAAE,MAAM,CAAC;YACd,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,cAAc,EAAE,SAAS,CAAC;SAC3B,CAAC;QACF,OAAO,EAAE,MAAM,CAAC;KACjB,GAAG;QACF,QAAQ,EAAE,eAAe,CAAC;QAC1B,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAgBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAQ5E;AAMD,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,OAAO,EACZ,YAAY,SAA0B,GACrC,gBAAgB,CA2BlB"}
package/dist/errors.js CHANGED
@@ -12,6 +12,73 @@ function boundedIssueText(value, maxChars) {
12
12
  truncated: true,
13
13
  };
14
14
  }
15
+ /**
16
+ * How many bytes of the caller's own arguments an error envelope will echo
17
+ * back to it. Small on purpose: an error result is not size-guarded the way a
18
+ * *result* is, so an unbounded echo turns a 50 KB argument object into a 100 KB
19
+ * refusal against a deployment that capped results at 1 KB — twice over, since
20
+ * the payload lands in both the text content and `structuredContent`. The agent
21
+ * already holds what it sent; the echo is a convenience, never the record.
22
+ */
23
+ const MAX_ECHOED_ARGS_BYTES = 512;
24
+ /**
25
+ * The same budget spent on caller-authored *text* — the address it mistyped,
26
+ * the discovery query derived from it — rather than on its arguments.
27
+ *
28
+ * Text is clamped where {@link echoedCallArgs} drops: an address is the thing
29
+ * the refusal exists to correct, so a refusal that named nothing would be
30
+ * useless, while a clipped one still carries the prefix that identifies the
31
+ * mistake. The marker says it was clipped, so nothing reads a clamped address
32
+ * as the address that was sent. Arguments get the opposite rule because they
33
+ * end at a human approving one specific call.
34
+ *
35
+ * The number is not cosmetic. An error result is not size-guarded the way a
36
+ * result is, and every echoed byte lands twice (text content *and*
37
+ * `structuredContent`), so an unbounded address turned a 50 KB typo into a
38
+ * 200 KB refusal against a deployment that capped results at 1 KB.
39
+ */
40
+ const MAX_ECHOED_TEXT_BYTES = 512;
41
+ const echoEncoder = new TextEncoder();
42
+ const echoDecoder = new TextDecoder();
43
+ /**
44
+ * Clamp a string to a UTF-8 byte budget, appending `…` when it clipped.
45
+ * Short strings — the common case, and the one that has to stay exact — are
46
+ * returned unchanged and untagged.
47
+ */
48
+ export function boundedEchoText(value, maxBytes = MAX_ECHOED_TEXT_BYTES) {
49
+ const bytes = echoEncoder.encode(value);
50
+ if (bytes.length <= maxBytes)
51
+ return value;
52
+ // Never split a codepoint: walk back off UTF-8 continuation bytes (10xxxxxx)
53
+ // so the clamp cannot manufacture a replacement character.
54
+ let end = Math.max(0, maxBytes);
55
+ while (end > 0 && ((bytes[end] ?? 0) & 0xc0) === 0x80)
56
+ end--;
57
+ return `${echoDecoder.decode(bytes.slice(0, end))}…`;
58
+ }
59
+ /**
60
+ * `{ args }` when the caller's arguments fit {@link MAX_ECHOED_ARGS_BYTES},
61
+ * `{}` when they do not. All or nothing: a clipped echo would be a *different*
62
+ * call than the one that was refused, and the routes this feeds end at a human
63
+ * approving one. Unserializable arguments are treated the same way as oversized
64
+ * ones — there is nothing honest to put in the field.
65
+ */
66
+ export function echoedCallArgs(args) {
67
+ if (args === undefined)
68
+ return {};
69
+ let text;
70
+ try {
71
+ text = JSON.stringify(args);
72
+ }
73
+ catch {
74
+ return {};
75
+ }
76
+ if (text === undefined)
77
+ return {};
78
+ return echoEncoder.encode(text).length <= MAX_ECHOED_ARGS_BYTES
79
+ ? { args }
80
+ : {};
81
+ }
15
82
  function boundedValidation(details) {
16
83
  if (!details)
17
84
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,gBAAgB;AA4BhB,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAChD,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,iCAAiC,GAAG,GAAG,CAAC;AAE9C,SAAS,gBAAgB,CACvB,KAAa,EACb,QAAgB;IAEhB,IAAI,KAAK,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACjE,OAAO;QACL,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG;QACtD,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CACxB,OAA8C;IAE9C,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,IAAI,SAAS,GACX,OAAO,CAAC,SAAS,KAAK,IAAI;QAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,8BAA8B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QACtC,OAAO;YACL,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,GAAG,CAAC,GAAG,CAAC,YAAY,KAAK,SAAS;gBAChC,CAAC,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE;gBACpC,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1D,CAAC;IACJ,CAAC;IACD,wEAAwE;IACxE,8EAA8E;IAC9E,6EAA6E;IAC7E,wEAAwE;IACxE,8EAA8E;IAC9E,6EAA6E;IAC7E,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACtD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACpE,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO;QACL,IAAI,EAAE,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY;QACjE,OAAO;QACP,SAAS,EAAE,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;KAC9C,CAAC;AACJ,CAAC"}
package/dist/execute.d.ts CHANGED
@@ -5,6 +5,15 @@ import { InvocationFailure } from "./invocation.js";
5
5
  import type { RegistryView } from "./registry.js";
6
6
  import type { ConnectaSurface, Executor, ExecutorProvider, Logger } from "./types.js";
7
7
  export declare const EXECUTE_MAX_BATCH_CALLS = 10;
8
+ /**
9
+ * Default budgets for `connecta.emit`. The byte budget is a transport bound,
10
+ * not a context bound — emitted image/audio blocks reach the model as media,
11
+ * not base64 text — so it sits far above the 24k return-value guard: room for
12
+ * two or three real screenshots after base64's 4/3 inflation, well short of a
13
+ * file-hosting ambition (design record M5).
14
+ */
15
+ export declare const EXECUTE_MAX_EMITTED_BYTES = 4000000;
16
+ export declare const EXECUTE_MAX_EMITTED_BLOCKS = 32;
8
17
  type ExecuteDiagnosticOperation = "search" | "describe" | "call" | "batch";
9
18
  interface ExecuteOperationDiagnostics {
10
19
  operation: ExecuteDiagnosticOperation;
@@ -22,6 +31,10 @@ declare class ExecuteDiagnostics {
22
31
  admissionMs: number;
23
32
  setupMs: number;
24
33
  executorWallMs: number;
34
+ private emitted?;
35
+ /** Numbers only, per R8 — and only once something was emitted, so a
36
+ * non-emitting run's diagnostics stay byte-for-byte what they were. */
37
+ recordEmitted(count: number, bytes: number): void;
25
38
  private stats;
26
39
  recordCatalog(operation: "search" | "describe", durationMs: number, ok: boolean, result?: unknown): void;
27
40
  recordCall(operation: "call" | "batch", outcome: {
@@ -44,8 +57,45 @@ declare class ExecuteDiagnostics {
44
57
  connectorMs: number;
45
58
  };
46
59
  operations: ExecuteOperationDiagnostics[];
60
+ emitted?: {
61
+ count: number;
62
+ bytes: number;
63
+ };
47
64
  };
48
65
  }
66
+ /**
67
+ * One MCP content block a program may emit. The complete set, by design:
68
+ * `resource` and `resource_link` are refused in ethos.md — pointers get
69
+ * followed, and connecta serves no resources for them to point at.
70
+ */
71
+ export type EmittedBlock = {
72
+ type: "text";
73
+ text: string;
74
+ } | {
75
+ type: "image";
76
+ data: string;
77
+ mimeType: string;
78
+ } | {
79
+ type: "audio";
80
+ data: string;
81
+ mimeType: string;
82
+ };
83
+ /**
84
+ * Request-local collection for `connecta.emit`. Budgets fail loudly at the
85
+ * crossing call — the block is not partially accepted and prior blocks are
86
+ * unaffected — so a program learns it is over budget while it can still
87
+ * choose differently (M5). Accepted blocks never ride `ExecuteResult`; the
88
+ * handler that owns this collector appends them to the final tool result.
89
+ */
90
+ export declare class EmitCollector {
91
+ private readonly maxBytes;
92
+ private readonly maxBlocks;
93
+ private readonly diagnostics?;
94
+ readonly blocks: EmittedBlock[];
95
+ bytes: number;
96
+ constructor(maxBytes: number, maxBlocks: number, diagnostics?: ExecuteDiagnostics | undefined);
97
+ accept(raw: unknown): void;
98
+ }
49
99
  /** Convert a connector/tool name into a valid JS identifier. */
50
100
  export declare function sanitizeIdentifier(name: string): string;
51
101
  /**
@@ -58,12 +108,23 @@ export declare function buildSandboxProviders(registry: RegistryView, baseUrl: s
58
108
  maxHostCalls?: number;
59
109
  hostCallTimeoutMs?: number;
60
110
  discoveryConcurrency?: number;
111
+ /** Per-connector deadline for in-program catalog probes. Default 30_000. */
112
+ probeTimeoutMs?: number;
61
113
  onInvocationFailure?: (failure: InvocationFailure) => void;
62
114
  diagnostics?: ExecuteDiagnostics;
115
+ /**
116
+ * Where `connecta.emit` collects. The handler that will deliver the
117
+ * blocks owns it; without one, emit fails loudly rather than accept
118
+ * blocks nobody will ever return.
119
+ */
120
+ emitCollector?: EmitCollector;
63
121
  }): Promise<ExecutorProvider[]>;
64
122
  /** The execute_code handler. Exported for direct testing. */
65
123
  export declare function createExecuteTool(registry: RegistryView, baseUrl: string, executor: Executor, logger: Logger, activity?: ActivityRequestContext, config?: {
66
124
  discoveryConcurrency?: number;
125
+ probeTimeoutMs?: number;
126
+ maxEmittedBytes?: number;
127
+ maxEmittedBlocks?: number;
67
128
  }): ({ code, diagnostics: diagnosticsRequested }: {
68
129
  code: string;
69
130
  diagnostics?: boolean;
@@ -78,6 +139,17 @@ export declare function registerExecuteTool(server: McpServer, registry: Registr
78
139
  activity?: ActivityRequestContext;
79
140
  requestSignal?: AbortSignal;
80
141
  discoveryConcurrency?: number;
142
+ /**
143
+ * The deployment's configured per-connector probe deadline. Programs probe
144
+ * the same downstream catalogs the top-level tools do, so an operator who
145
+ * tightened `discovery.probeTimeoutMs` gets it honored inside the sandbox
146
+ * too rather than silently falling back to the 30s default.
147
+ */
148
+ probeTimeoutMs?: number;
149
+ /** Aggregate serialized-byte budget for connecta.emit. Default 4_000_000. */
150
+ maxEmittedBytes?: number;
151
+ /** Block-count budget for connecta.emit. Default 32. */
152
+ maxEmittedBlocks?: number;
81
153
  /** The advertised surface, which decides this tool's routing copy. */
82
154
  surface?: ConnectaSurface;
83
155
  }): void;
@@ -1 +1 @@
1
- {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAO5D,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAW3E,OAAO,EACL,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACP,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAI1C,KAAK,0BAA0B,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3E,UAAU,2BAA2B;IACnC,SAAS,EAAE,0BAA0B,CAAC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,cAAM,kBAAkB;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAGvB;IACJ,WAAW,SAAK;IAChB,OAAO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M,CAAC,EAAE,WAAW,CAAA;CAAO,KACrC,OAAO,CAAC,UAAU,CAAC,CAsOvB;AAuDD,uFAAuF;AACvF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,YAAY,EACtB,GAAG,EAAE;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B,GACA,IAAI,CAwEN"}
package/dist/execute.js CHANGED
@@ -9,6 +9,15 @@ import { InvocationFailure, InvocationService, } from "./invocation.js";
9
9
  const EXECUTE_MAX_HOST_CALLS = 20;
10
10
  export const EXECUTE_MAX_BATCH_CALLS = 10;
11
11
  const EXECUTE_HOST_CALL_TIMEOUT_MS = 15_000;
12
+ /**
13
+ * Default budgets for `connecta.emit`. The byte budget is a transport bound,
14
+ * not a context bound — emitted image/audio blocks reach the model as media,
15
+ * not base64 text — so it sits far above the 24k return-value guard: room for
16
+ * two or three real screenshots after base64's 4/3 inflation, well short of a
17
+ * file-hosting ambition (design record M5).
18
+ */
19
+ export const EXECUTE_MAX_EMITTED_BYTES = 4_000_000;
20
+ export const EXECUTE_MAX_EMITTED_BLOCKS = 32;
12
21
  const diagnosticsEncoder = new TextEncoder();
13
22
  class ExecuteDiagnostics {
14
23
  started = Date.now();
@@ -16,6 +25,13 @@ class ExecuteDiagnostics {
16
25
  admissionMs = 0;
17
26
  setupMs = 0;
18
27
  executorWallMs = 0;
28
+ emitted;
29
+ /** Numbers only, per R8 — and only once something was emitted, so a
30
+ * non-emitting run's diagnostics stay byte-for-byte what they were. */
31
+ recordEmitted(count, bytes) {
32
+ if (count > 0)
33
+ this.emitted = { count, bytes };
34
+ }
19
35
  stats(operation) {
20
36
  let stats = this.operations.get(operation);
21
37
  if (!stats) {
@@ -83,9 +99,79 @@ class ExecuteDiagnostics {
83
99
  connectorMs: operations.reduce((sum, item) => sum + item.connectorMs, 0),
84
100
  },
85
101
  operations,
102
+ ...(this.emitted ? { emitted: this.emitted } : {}),
86
103
  };
87
104
  }
88
105
  }
106
+ const EMIT_SHAPE_HINT = '{ type: "text", text } or { type: "image" | "audio", data (base64), mimeType }';
107
+ /**
108
+ * Strict M1 validation: required fields present and string-valued, nothing
109
+ * else — no `annotations`, no `_meta`, no sugar forms. Rejected rather than
110
+ * stripped, because silently deleting fields would deliver something the
111
+ * program did not ask to emit.
112
+ */
113
+ function requireEmittedBlock(raw) {
114
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
115
+ throw new Error(`connecta.emit accepts exactly one content block: ${EMIT_SHAPE_HINT}`);
116
+ }
117
+ const block = raw;
118
+ const fields = block.type === "text"
119
+ ? ["type", "text"]
120
+ : block.type === "image" || block.type === "audio"
121
+ ? ["type", "data", "mimeType"]
122
+ : undefined;
123
+ if (!fields) {
124
+ throw new Error(`connecta.emit supports content types "text", "image", and "audio"; got ${JSON.stringify(block.type)}`);
125
+ }
126
+ for (const field of fields) {
127
+ if (typeof block[field] !== "string") {
128
+ throw new Error(`connecta.emit block field "${field}" must be a string: ${EMIT_SHAPE_HINT}`);
129
+ }
130
+ }
131
+ const extra = Object.keys(block).filter((key) => !fields.includes(key));
132
+ if (extra.length > 0) {
133
+ throw new Error(`connecta.emit block carries unsupported field(s) ${extra.map((key) => JSON.stringify(key)).join(", ")}; a "${String(block.type)}" block is exactly { ${fields.join(", ")} }`);
134
+ }
135
+ return raw;
136
+ }
137
+ /**
138
+ * Request-local collection for `connecta.emit`. Budgets fail loudly at the
139
+ * crossing call — the block is not partially accepted and prior blocks are
140
+ * unaffected — so a program learns it is over budget while it can still
141
+ * choose differently (M5). Accepted blocks never ride `ExecuteResult`; the
142
+ * handler that owns this collector appends them to the final tool result.
143
+ */
144
+ export class EmitCollector {
145
+ maxBytes;
146
+ maxBlocks;
147
+ diagnostics;
148
+ blocks = [];
149
+ bytes = 0;
150
+ constructor(maxBytes, maxBlocks, diagnostics) {
151
+ this.maxBytes = maxBytes;
152
+ this.maxBlocks = maxBlocks;
153
+ this.diagnostics = diagnostics;
154
+ }
155
+ accept(raw) {
156
+ const block = requireEmittedBlock(raw);
157
+ if (this.blocks.length >= this.maxBlocks) {
158
+ throw new Error(`connecta.emit block-count budget exceeded: ${this.maxBlocks} block(s) maximum, 0 remaining`);
159
+ }
160
+ const size = diagnosticsEncoder.encode(JSON.stringify(block)).byteLength;
161
+ if (this.bytes + size > this.maxBytes) {
162
+ throw new Error(`connecta.emit byte budget exceeded: block is ${size} serialized bytes with ${this.maxBytes - this.bytes} of ${this.maxBytes} remaining`);
163
+ }
164
+ this.blocks.push(block);
165
+ this.bytes += size;
166
+ this.diagnostics?.recordEmitted(this.blocks.length, this.bytes);
167
+ }
168
+ }
169
+ /** A configured emit budget must be a finite number >= 1; anything else falls back. */
170
+ function resolveEmitBudget(value, fallback) {
171
+ return typeof value === "number" && Number.isFinite(value) && value >= 1
172
+ ? Math.trunc(value)
173
+ : fallback;
174
+ }
89
175
  function serializedDiagnosticBytes(value) {
90
176
  try {
91
177
  const text = JSON.stringify(value);
@@ -205,9 +291,19 @@ export async function buildSandboxProviders(registry, baseUrl, logger, activity,
205
291
  const requestScope = {};
206
292
  const catalog = new CatalogService(registry, baseUrl, {
207
293
  requestScope,
294
+ // Every describe reaching this catalog came from inside a program, on a
295
+ // code-first and a classic-with-executor deployment alike, so the retry
296
+ // advice names connecta.describe regardless of what this server advertises.
297
+ describeRoute: "connecta.describe",
298
+ // Same reasoning for the discovery route a routing failure hands back: the
299
+ // program that just missed an address cannot call search_tools.
300
+ searchRoute: "connecta.search",
208
301
  ...(limits.discoveryConcurrency !== undefined
209
302
  ? { concurrency: limits.discoveryConcurrency }
210
303
  : {}),
304
+ ...(limits.probeTimeoutMs !== undefined
305
+ ? { probeTimeoutMs: limits.probeTimeoutMs }
306
+ : {}),
211
307
  });
212
308
  const invocation = new InvocationService(registry, catalog, activity);
213
309
  const maxHostCalls = Math.max(1, Math.trunc(limits.maxHostCalls ?? EXECUTE_MAX_HOST_CALLS));
@@ -292,6 +388,16 @@ export async function buildSandboxProviders(registry, baseUrl, logger, activity,
292
388
  fns: {
293
389
  __callNamespace: callNamespace,
294
390
  call: (address, args) => callAddress(address, args),
391
+ // Emission is a provider function, never an ExecuteResult field —
392
+ // that is what keeps the Executor contract untouched and parity
393
+ // structural (M8). It spends no host-call budget (M7); its own
394
+ // budgets live in the collector.
395
+ emit: async (block) => {
396
+ if (!limits.emitCollector) {
397
+ throw new Error("connecta.emit is unavailable: no emission collector was configured for this execution");
398
+ }
399
+ limits.emitCollector.accept(block);
400
+ },
295
401
  batch: async (calls) => {
296
402
  const started = Date.now();
297
403
  const callCount = Array.isArray(calls) ? calls.length : 0;
@@ -392,6 +498,7 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
392
498
  let lease;
393
499
  let outcome;
394
500
  const diagnostics = diagnosticsRequested ? new ExecuteDiagnostics() : undefined;
501
+ const emitted = new EmitCollector(resolveEmitBudget(config.maxEmittedBytes, EXECUTE_MAX_EMITTED_BYTES), resolveEmitBudget(config.maxEmittedBlocks, EXECUTE_MAX_EMITTED_BLOCKS), diagnostics);
395
502
  const invocationFailures = [];
396
503
  try {
397
504
  // Admission comes before provider construction: queued calls retain no
@@ -420,10 +527,14 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
420
527
  onInvocationFailure: (failure) => {
421
528
  invocationFailures.push(failure);
422
529
  },
530
+ emitCollector: emitted,
423
531
  ...(diagnostics ? { diagnostics } : {}),
424
532
  ...(config.discoveryConcurrency !== undefined
425
533
  ? { discoveryConcurrency: config.discoveryConcurrency }
426
534
  : {}),
535
+ ...(config.probeTimeoutMs !== undefined
536
+ ? { probeTimeoutMs: config.probeTimeoutMs }
537
+ : {}),
427
538
  });
428
539
  }
429
540
  finally {
@@ -474,12 +585,13 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
474
585
  message: `Executor failed: ${msg(err)}`,
475
586
  retryable: false,
476
587
  },
588
+ ...discardedEmits(emitted),
477
589
  diagnostics: diagnostics.finish(),
478
590
  });
479
591
  result.isError = true;
480
592
  return result;
481
593
  }
482
- return errorResult(`Executor failed: ${msg(err)}`);
594
+ return errorResult(`Executor failed: ${msg(err)}${discardedEmitsText(emitted)}`);
483
595
  }
484
596
  finally {
485
597
  // A sandbox timeout or early return must also release any outstanding
@@ -519,9 +631,14 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
519
631
  break;
520
632
  }
521
633
  if (invocationFailure) {
634
+ // Handed back whole, with no size guard of its own — the failure was
635
+ // framed with bounded caller text (`boundedEchoText`) precisely so
636
+ // this path never needs one. Adding a cap here instead would leave the
637
+ // top-level surfaces, which have the same amplification, uncovered.
522
638
  const result = jsonResult({
523
639
  error: invocationFailure.details,
524
640
  ...(logs ? { logs } : {}),
641
+ ...discardedEmits(emitted),
525
642
  ...(diagnostics ? { diagnostics: diagnostics.finish() } : {}),
526
643
  });
527
644
  result.isError = true;
@@ -536,12 +653,13 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
536
653
  retryable: false,
537
654
  },
538
655
  ...(logs ? { logs } : {}),
656
+ ...discardedEmits(emitted),
539
657
  diagnostics: diagnostics.finish(),
540
658
  });
541
659
  result.isError = true;
542
660
  return result;
543
661
  }
544
- return errorResult(`${message}${logs ? `\n\nLogs:\n${logs}` : ""}`);
662
+ return errorResult(`${message}${logs ? `\n\nLogs:\n${logs}` : ""}${discardedEmitsText(emitted)}`);
545
663
  }
546
664
  // A result crossing back as a host BigInt (or otherwise unserializable
547
665
  // value) makes JSON.stringify throw — keep that inside the structured
@@ -560,20 +678,41 @@ export function createExecuteTool(registry, baseUrl, executor, logger, activity,
560
678
  retryable: false,
561
679
  },
562
680
  ...(logs ? { logs } : {}),
681
+ ...discardedEmits(emitted),
563
682
  diagnostics: diagnostics.finish(),
564
683
  });
565
684
  response.isError = true;
566
685
  return response;
567
686
  }
568
- return errorResult(`${message}${logs ? `\n\nLogs:\n${logs}` : ""}`);
687
+ return errorResult(`${message}${logs ? `\n\nLogs:\n${logs}` : ""}${discardedEmitsText(emitted)}`);
569
688
  }
570
- return jsonResult({
689
+ const response = jsonResult({
571
690
  result,
691
+ ...(emitted.blocks.length > 0 ? { emitted: emitted.blocks.length } : {}),
572
692
  ...(logs ? { logs } : {}),
573
693
  ...(diagnostics ? { diagnostics: diagnostics.finish() } : {}),
574
694
  });
695
+ if (emitted.blocks.length > 0) {
696
+ // Emitted image/audio blocks are valid MCP content that ToolResult's
697
+ // text-only typing does not model — the same acknowledged gap
698
+ // guardContent lives with for downstream block passthrough.
699
+ response.content.push(...emitted.blocks);
700
+ }
701
+ return response;
575
702
  };
576
703
  }
704
+ /** M4: a failed program delivers no blocks, but the discard is visible. */
705
+ function discardedEmits(emitted) {
706
+ return emitted.blocks.length > 0
707
+ ? { emittedDiscarded: emitted.blocks.length }
708
+ : {};
709
+ }
710
+ /** The same visibility for the plain-text error paths. */
711
+ function discardedEmitsText(emitted) {
712
+ return emitted.blocks.length > 0
713
+ ? `\n\nemittedDiscarded: ${emitted.blocks.length}`
714
+ : "";
715
+ }
577
716
  /**
578
717
  * How the tool opens, and where a program's argument schemas come from. Both
579
718
  * differ by surface: on the classic surface `execute_code` is the tool of last
@@ -590,12 +729,13 @@ const EXECUTE_SCHEMA_SOURCE = {
590
729
  classic: "describe_tools",
591
730
  "code-first": "connecta.describe",
592
731
  };
593
- const executeDescription = (surface) => `${EXECUTE_ROUTING[surface]} Only tools explicitly annotated readOnlyHint: true are available. Each run is limited to ${EXECUTE_MAX_HOST_CALLS} host calls; connecta.batch accepts at most ${EXECUTE_MAX_BATCH_CALLS}; each host call has a ${EXECUTE_HOST_CALL_TIMEOUT_MS / 1_000}-second deadline.
732
+ const executeDescription = (surface, emitBudgets) => `${EXECUTE_ROUTING[surface]} Only tools explicitly annotated readOnlyHint: true are available. Each run is limited to ${EXECUTE_MAX_HOST_CALLS} host calls; connecta.batch accepts at most ${EXECUTE_MAX_BATCH_CALLS}; each host call has a ${EXECUTE_HOST_CALL_TIMEOUT_MS / 1_000}-second deadline.
594
733
 
595
734
  Write an async arrow function. It runs with NO network, filesystem, timers, or imports — the only capabilities are:
596
735
  - One global per connector: every address <connectorId>.<toolName> from search_tools is callable as <connectorId>.<toolName>(args) with a single args object matching the schema from ${EXECUTE_SCHEMA_SOURCE[surface]}. Names are sanitized to JS identifiers: characters outside [A-Za-z0-9_$] become "_" (e.g. my-service.get.thing → my_service.get_thing), leading digits get "_" prefixed, reserved words get "_" appended.
597
736
  - connecta.call(address, args) and connecta.batch(calls) — call raw addresses.
598
737
  - connecta.search(args), connecta.describe({ address: "<connectorId>.<toolName>" }), and connecta.describe({ addresses: [...] }) — load and inspect request-local catalogs on demand. Use safety: "readOnly" to avoid advertising calls this sandbox cannot execute; the filter changes results, not authority. Matches carrying schemas also list inputKeys, requiredInputKeys, and outputKeys — the same names the schema shows, ready to check against before building args. They are absent when a schema is not a plain object shape, so read the schema itself rather than assuming a missing list means no fields.
738
+ - connecta.emit(block) — deliver rich MCP content alongside the JSON return: exactly { type: "text", text } or { type: "image" | "audio", data (base64), mimeType }, no other fields. Blocks are appended to the result on success only, spend no host calls, and are budgeted per run (${emitBudgets.maxBlocks} blocks, ${emitBudgets.maxBytes} serialized bytes); an over-budget or invalid emit throws catchably and accepts nothing.
599
739
  - console.log(...) — captured and returned alongside the result.
600
740
 
601
741
  Tool calls return plain values (MCP text content is JSON-parsed when possible) and throw on downstream errors — use try/catch to handle them. A thrown error carries only a message; connecta.batch reports each call as { address, ok: true, data } or { address, ok: false, error, errorDetails: { code, retryable } }, so use it when the program must tell a policy refusal from a transient failure. Never retry a failure whose retryable is false, and never retry a rate_limited one immediately — the sandbox has no timers. Return a JSON-serializable value; large results are truncated, so reduce data in code instead of returning raw payloads.
@@ -604,11 +744,24 @@ Plain JavaScript only — no TypeScript syntax. For unknown-address dependent wo
604
744
  Dependent example (only when the second call requires a value returned by the first): async () => { const { tools } = await connecta.search({ query: "pipeline run job logs", safety: "readOnly", includeSchemas: "compact" }); const pick = (suffix) => { const match = tools.find((tool) => tool.address.endsWith(suffix)); if (!match) throw new Error("no tool matching " + suffix); return match.address; }; const run = await connecta.call(pick(".get_run"), { runId: 42 }); const logs = await connecta.call(pick(".get_job_logs"), { jobId: run.failedJobId }); return [run, logs]; }`;
605
745
  /** Register the execute_code meta-tool. Only called when an executor is configured. */
606
746
  export function registerExecuteTool(server, registry, ctx) {
607
- const handler = createExecuteTool(registry, ctx.baseUrl, ctx.executor, ctx.logger, ctx.activity, ctx.discoveryConcurrency !== undefined
608
- ? { discoveryConcurrency: ctx.discoveryConcurrency }
609
- : {});
747
+ // Resolved once so the description and the collector cannot disagree about
748
+ // the budgets this deployment actually enforces.
749
+ const emitBudgets = {
750
+ maxBytes: resolveEmitBudget(ctx.maxEmittedBytes, EXECUTE_MAX_EMITTED_BYTES),
751
+ maxBlocks: resolveEmitBudget(ctx.maxEmittedBlocks, EXECUTE_MAX_EMITTED_BLOCKS),
752
+ };
753
+ const handler = createExecuteTool(registry, ctx.baseUrl, ctx.executor, ctx.logger, ctx.activity, {
754
+ ...(ctx.discoveryConcurrency !== undefined
755
+ ? { discoveryConcurrency: ctx.discoveryConcurrency }
756
+ : {}),
757
+ ...(ctx.probeTimeoutMs !== undefined
758
+ ? { probeTimeoutMs: ctx.probeTimeoutMs }
759
+ : {}),
760
+ maxEmittedBytes: emitBudgets.maxBytes,
761
+ maxEmittedBlocks: emitBudgets.maxBlocks,
762
+ });
610
763
  server.registerTool("execute_code", {
611
- description: executeDescription(ctx.surface ?? "classic"),
764
+ description: executeDescription(ctx.surface ?? "classic", emitBudgets),
612
765
  inputSchema: z.object({
613
766
  code: z
614
767
  .string()