@akai-workflow-builder/cli-sdk 0.4.0 → 0.4.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/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to `@akai-workflow-builder/cli-sdk` are documented here.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
+ ## [0.4.1](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.4.0...cli-sdk-v0.4.1) (2026-08-13)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * cap ctx.fetch response size (AKAI-2325) ([#78](https://github.com/akai-workflow-builder/akai-cli-sdk/issues/78)) ([22dc513](https://github.com/akai-workflow-builder/akai-cli-sdk/commit/22dc5130dfb1dea7eb1e5663a66da64041b29a18))
13
+
7
14
  ## [0.4.0](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.3.0...cli-sdk-v0.4.0) (2026-08-03)
8
15
 
9
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"build-ctx.d.ts","sourceRoot":"","sources":["../../src/ctx/build-ctx.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAc,MAAM,EAAiB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG1F;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6GAA6G;IAC7G,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,sGAAsG;IACtG,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,W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AC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,8CAA8C;IAC9C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CACvC;AA4ED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAmExD"}
@@ -1,5 +1,5 @@
1
1
  import { tmpdir } from 'node:os';
2
- import { createSafeFetch } from './safe-fetch.js';
2
+ import { createSafeFetch, DEFAULT_MAX_RESPONSE_BYTES, PRODUCES_FILES_MAX_RESPONSE_BYTES, } from './safe-fetch.js';
3
3
  import { createSafePath } from './safe-path.js';
4
4
  import { buildScopedProperties, buildScopedSecrets, } from './secrets.js';
5
5
  import { createReadFile } from './read-file.js';
@@ -89,6 +89,11 @@ export function buildCtx(params) {
89
89
  cliId: params.cli.id,
90
90
  toolName: params.toolName,
91
91
  sdkVersion: params.sdkVersion,
92
+ // producesFiles tools stream the response to disk rather than
93
+ // parsing it into JS objects, so a much larger response is safe —
94
+ // see the constants' doc comments in safe-fetch.ts for the prod
95
+ // data behind both numbers.
96
+ maxResponseBytes: tool.options.producesFiles === true ? PRODUCES_FILES_MAX_RESPONSE_BYTES : DEFAULT_MAX_RESPONSE_BYTES,
92
97
  ...(params.tenantId !== undefined ? { tenantId: params.tenantId } : {}),
93
98
  ...(clientCert !== undefined ? { clientCert } : {}),
94
99
  });
@@ -1,3 +1,25 @@
1
+ /**
2
+ * Default per-response byte cap for JSON/text `ctx.fetch` calls (override via
3
+ * {@link SafeFetchBinding.maxResponseBytes}). Grounded in prod trace data
4
+ * (Tempo, `akai-cli-service`, 6h window): typical tool responses are tiny
5
+ * (p50 ~90B, p99 ~230KB, observed max ~0.94MB). 8MB gives ~8x headroom above
6
+ * that observed max while still catching the class of bug this cap exists
7
+ * for — e.g. the >10MB unfiltered `employee-navigator` census report that
8
+ * wedged the executor (it parses the whole body into JS objects, so the
9
+ * *raw* bytes plus V8's per-object overhead is what exhausts memory, not
10
+ * just the wire size).
11
+ */
12
+ export declare const DEFAULT_MAX_RESPONSE_BYTES: number;
13
+ /**
14
+ * Cap for tools that declare `options.producesFiles` — they stream the
15
+ * response to a file rather than parsing it into JS objects, so the same
16
+ * memory risk doesn't apply at the same byte count. Grounded in the same
17
+ * prod trace data: real `gdrive download` files up to 46MB were seen
18
+ * succeeding in a single day. 150MB gives >3x headroom above that observed
19
+ * max while still bounding a single call to a small fraction of the
20
+ * executor pod's 1Gi memory limit.
21
+ */
22
+ export declare const PRODUCES_FILES_MAX_RESPONSE_BYTES: number;
1
23
  /**
2
24
  * Resolved mutual-TLS client identity — PEM values, not secret-key
3
25
  * references. `buildCtx()` resolves `NetworkOptions.clientCert` key refs
@@ -15,6 +37,8 @@ export interface SafeFetchBinding {
15
37
  readonly sdkVersion: string;
16
38
  readonly tenantId?: string;
17
39
  readonly clientCert?: ResolvedClientCert;
40
+ /** Overrides {@link DEFAULT_MAX_RESPONSE_BYTES} for this tool. */
41
+ readonly maxResponseBytes?: number;
18
42
  }
19
43
  export type SafeFetch = (url: string, init?: RequestInit) => Promise<Response>;
20
44
  export declare function createSafeFetch(binding: SafeFetchBinding): SafeFetch;
@@ -1 +1 @@
1
- {"version":3,"file":"safe-fetch.d.ts","sourceRoot":"","sources":["../../src/ctx/safe-fetch.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM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M,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAyG/E,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAoGpE"}
@@ -3,7 +3,29 @@ import { request as httpsRequest } from 'node:https';
3
3
  import { isIPv4, isIPv6 } from 'node:net';
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { Readable } from 'node:stream';
6
- import { AkaiEgressError } from '../errors.js';
6
+ import { AkaiEgressError, AkaiResponseTooLargeError } from '../errors.js';
7
+ /**
8
+ * Default per-response byte cap for JSON/text `ctx.fetch` calls (override via
9
+ * {@link SafeFetchBinding.maxResponseBytes}). Grounded in prod trace data
10
+ * (Tempo, `akai-cli-service`, 6h window): typical tool responses are tiny
11
+ * (p50 ~90B, p99 ~230KB, observed max ~0.94MB). 8MB gives ~8x headroom above
12
+ * that observed max while still catching the class of bug this cap exists
13
+ * for — e.g. the >10MB unfiltered `employee-navigator` census report that
14
+ * wedged the executor (it parses the whole body into JS objects, so the
15
+ * *raw* bytes plus V8's per-object overhead is what exhausts memory, not
16
+ * just the wire size).
17
+ */
18
+ export const DEFAULT_MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
19
+ /**
20
+ * Cap for tools that declare `options.producesFiles` — they stream the
21
+ * response to a file rather than parsing it into JS objects, so the same
22
+ * memory risk doesn't apply at the same byte count. Grounded in the same
23
+ * prod trace data: real `gdrive download` files up to 46MB were seen
24
+ * succeeding in a single day. 150MB gives >3x headroom above that observed
25
+ * max while still bounding a single call to a small fraction of the
26
+ * executor pod's 1Gi memory limit.
27
+ */
28
+ export const PRODUCES_FILES_MAX_RESPONSE_BYTES = 150 * 1024 * 1024;
7
29
  // Collapse expanded / partially compressed / leading-zero IPv6 forms to
8
30
  // RFC 5952 via WHATWG URL (Ada in Node 24). `dns.lookup` passes numeric
9
31
  // literals through verbatim, so an attacker-controlled URL like
@@ -103,7 +125,8 @@ const FORWARDED_INIT_FIELDS = [
103
125
  'referrerPolicy',
104
126
  ];
105
127
  export function createSafeFetch(binding) {
106
- const { egress, cliId, toolName, sdkVersion, tenantId, clientCert } = binding;
128
+ const { egress, cliId, toolName, sdkVersion, tenantId, clientCert, maxResponseBytes } = binding;
129
+ const maxBytes = maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
107
130
  return async function safeFetch(rawUrl, init = {}) {
108
131
  // Coerce once. Otherwise `new URL(rawUrl)` (for validation) and
109
132
  // `fetch(rawUrl, …)` would invoke `Symbol.toPrimitive`/`toString` twice,
@@ -187,12 +210,49 @@ export function createSafeFetch(binding) {
187
210
  // this path rides `node:https` — same TLS stack, zero dependencies —
188
211
  // and adapts back to a standard `Response`. Dev-mode `http:` URLs fall
189
212
  // through to plain fetch: there is no TLS handshake to present a cert on.
190
- if (clientCert !== undefined && u.protocol === 'https:') {
191
- return mtlsFetch(u, sanitized, clientCert);
192
- }
193
- return fetch(url, sanitized);
213
+ const response = clientCert !== undefined && u.protocol === 'https:'
214
+ ? await mtlsFetch(u, sanitized, clientCert)
215
+ : await fetch(url, sanitized);
216
+ return capResponseBody(response, maxBytes, { hostname: u.hostname, cliId, toolName });
194
217
  };
195
218
  }
219
+ /**
220
+ * Wrap a `Response` body so it errors with {@link AkaiResponseTooLargeError}
221
+ * — instead of continuing to buffer — the moment the byte count crosses
222
+ * `maxBytes`. Streaming (not a post-hoc `content-length`/buffered check) so a
223
+ * chunked upstream that never declares its size is still bounded, and the
224
+ * source connection is cancelled on trip so the executor stops paying for a
225
+ * download nothing will read.
226
+ */
227
+ function capResponseBody(res, maxBytes, info) {
228
+ if (res.body === null)
229
+ return res;
230
+ const reader = res.body.getReader();
231
+ let received = 0;
232
+ const tooLarge = () => new AkaiResponseTooLargeError(`Response from ${info.hostname} was too large (over ${Math.round(maxBytes / (1024 * 1024))}MB). ` +
233
+ `Narrow the request — add a filter, a date/id range, or a pagination/limit parameter — ` +
234
+ `and retry with a smaller result set.`, { hostname: info.hostname, cliId: info.cliId, toolName: info.toolName, maxBytes });
235
+ const body = new ReadableStream({
236
+ async pull(controller) {
237
+ const { done, value } = await reader.read();
238
+ if (done) {
239
+ controller.close();
240
+ return;
241
+ }
242
+ received += value.byteLength;
243
+ if (received > maxBytes) {
244
+ controller.error(tooLarge());
245
+ await reader.cancel(tooLarge()).catch(() => { });
246
+ return;
247
+ }
248
+ controller.enqueue(value);
249
+ },
250
+ cancel(reason) {
251
+ return reader.cancel(reason);
252
+ },
253
+ });
254
+ return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
255
+ }
196
256
  /** Response statuses that must not carry a body (Response ctor throws otherwise). */
197
257
  const NULL_BODY_STATUSES = new Set([204, 205, 304]);
198
258
  /**
package/dist/errors.d.ts CHANGED
@@ -19,6 +19,13 @@ export declare class AkaiInputError extends AkaiError {
19
19
  /** `ctx.fetch` egress allowlist violation. */
20
20
  export declare class AkaiEgressError extends AkaiError {
21
21
  }
22
+ /**
23
+ * `ctx.fetch` response exceeded the SDK's per-call byte cap. Thrown once the
24
+ * cap is crossed mid-stream — the underlying connection is cancelled, so the
25
+ * cap bounds memory even when the upstream never sends `content-length`.
26
+ */
27
+ export declare class AkaiResponseTooLargeError extends AkaiError {
28
+ }
22
29
  /** Required secret is missing or empty at runtime. */
23
30
  export declare class AkaiSecretError extends AkaiError {
24
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAK5D;AAED,2EAA2E;AAC3E,qBAAa,aAAc,SAAQ,SAAS;CAAG;AAE/C,2EAA2E;AAC3E,qBAAa,mBAAoB,SAAQ,aAAa;CA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MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAIlF,oFAAoF;IACpF,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAIlF;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,cAAc,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,aAAa;CA4BjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,SAAM,GAAG,MAAM,CAmBnE"}
package/dist/errors.js CHANGED
@@ -23,6 +23,13 @@ export class AkaiInputError extends AkaiError {
23
23
  /** `ctx.fetch` egress allowlist violation. */
24
24
  export class AkaiEgressError extends AkaiError {
25
25
  }
26
+ /**
27
+ * `ctx.fetch` response exceeded the SDK's per-call byte cap. Thrown once the
28
+ * cap is crossed mid-stream — the underlying connection is cancelled, so the
29
+ * cap bounds memory even when the upstream never sends `content-length`.
30
+ */
31
+ export class AkaiResponseTooLargeError extends AkaiError {
32
+ }
26
33
  /** Required secret is missing or empty at runtime. */
27
34
  export class AkaiSecretError extends AkaiError {
28
35
  }
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export type { BuildCtxParams } from './ctx/build-ctx.js';
9
9
  export type { AnyToolDef, CLIDef, CLISpec, ClientCertOptions, ConnectionAuthKind, ConnectionDef, ConnectionOAuthConfig, ConnectionSpec, DynamicEgress, InputOf, NetworkOptions, OAuthAdminField, OutputOf, PropertiesOf, PropertyDecl, RefreshStrategy, SecretDecl, SecretsOf, TokenEndpointAuthMethod, ToolCtx, ToolDef, ToolLogger, ToolOptions, ToolSpec, } from './types.js';
10
10
  export { createSafePath } from './ctx/safe-path.js';
11
11
  export type { SafePath } from './ctx/safe-path.js';
12
- export { AkaiConnectionError, AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, AkaiToolError, describeError, } from './errors.js';
12
+ export { AkaiConnectionError, AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiResponseTooLargeError, AkaiSecretError, AkaiSpecError, AkaiToolError, describeError, } from './errors.js';
13
13
  export type { ToolErrorKind } from './errors.js';
14
14
  export { ConnectionManifestSchema, ManifestJSONSchema, SCHEMA_VERSION, toSchema, validateManifest, } from './manifest/index.js';
15
15
  export type { ClientCertManifest, ConnectionManifest, DynamicEgressManifest, HttpToolManifest, ManifestProperty, ManifestSecret, NativeToolManifest, SchemaVersion, ToolManifest, } from './manifest/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EACV,UAAU,EACV,MAAM,EACN,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,aAA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EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,YAAY,EACV,UAAU,EACV,MAAM,EACN,OAAO,EACP,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,OAAO,EACP,cAAc,EACd,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,yBAAyB,EACzB,eAAe,EACf,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -5,5 +5,5 @@ export { defineConnection, isAkaiConnection } from './define-connection.js';
5
5
  export { buildScopedSecrets, buildScopedProperties } from './ctx/secrets.js';
6
6
  export { buildCtx } from './ctx/build-ctx.js';
7
7
  export { createSafePath } from './ctx/safe-path.js';
8
- export { AkaiConnectionError, AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, AkaiToolError, describeError, } from './errors.js';
8
+ export { AkaiConnectionError, AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiResponseTooLargeError, AkaiSecretError, AkaiSpecError, AkaiToolError, describeError, } from './errors.js';
9
9
  export { ConnectionManifestSchema, ManifestJSONSchema, SCHEMA_VERSION, toSchema, validateManifest, } from './manifest/index.js';
@@ -2,7 +2,7 @@ import type { ToolLogger } from '../../types.js';
2
2
  import { type ConvertedFile } from './image-compress.js';
3
3
  import type { Registry } from '../registry/index.js';
4
4
  import type { ExecuteRequestBody } from '../execute-request.js';
5
- export type ExecuteErrorCode = 'unknown_tool' | 'invalid_input' | 'secret_unknown_key' | 'secret_missing' | 'property_unknown_key' | 'property_missing' | 'write_not_confirmed' | 'output_channel_missing' | 'egress_blocked' | 'spec_error' | 'handler_error' | 'upstream_not_found' | 'upstream_forbidden' | 'upstream_auth_expired' | 'upstream_invalid_input' | 'upstream_conflict' | 'upstream_rate_limited' | 'upstream_unavailable';
5
+ export type ExecuteErrorCode = 'unknown_tool' | 'invalid_input' | 'secret_unknown_key' | 'secret_missing' | 'property_unknown_key' | 'property_missing' | 'write_not_confirmed' | 'output_channel_missing' | 'egress_blocked' | 'response_too_large' | 'spec_error' | 'handler_error' | 'upstream_not_found' | 'upstream_forbidden' | 'upstream_auth_expired' | 'upstream_invalid_input' | 'upstream_conflict' | 'upstream_rate_limited' | 'upstream_unavailable';
6
6
  export interface ExecuteSuccess {
7
7
  readonly ok: true;
8
8
  readonly result: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/executor/index.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAqC,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKpF,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,qBAAqB,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E;QACd,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACzC,CAAC;CACH;AAED,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,cAAc,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;OAMG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CA2Q/E"}
@@ -15,7 +15,7 @@ import os from 'node:os';
15
15
  import path from 'node:path';
16
16
  import { createRequire } from 'node:module';
17
17
  import { buildCtx } from '../../ctx/build-ctx.js';
18
- import { AkaiError, AkaiEgressError, AkaiPropertyError, AkaiSecretError, AkaiSpecError } from '../../errors.js';
18
+ import { AkaiError, AkaiEgressError, AkaiPropertyError, AkaiResponseTooLargeError, AkaiSecretError, AkaiSpecError, } from '../../errors.js';
19
19
  import { DYNAMIC_EGRESS_PREFIXES } from '../../tool.js';
20
20
  import { create as tarCreate } from 'tar';
21
21
  import { z } from 'zod';
@@ -162,6 +162,9 @@ export async function executeTool(params) {
162
162
  if (err instanceof AkaiEgressError) {
163
163
  return failure('egress_blocked', err.message, err.meta);
164
164
  }
165
+ if (err instanceof AkaiResponseTooLargeError) {
166
+ return failure('response_too_large', err.message, err.meta);
167
+ }
165
168
  if (err instanceof AkaiSecretError) {
166
169
  return failure('secret_missing', err.message, err.meta);
167
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akai-workflow-builder/cli-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Authoring SDK for atomic, agent-executable CLIs and tools.",
5
5
  "keywords": [
6
6
  "akai",