@akai-workflow-builder/cli-sdk 0.1.2 → 0.1.3

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 ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@akai-workflow-builder/cli-sdk` are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
+
7
+ ## [0.1.3]
8
+
9
+ ### Added
10
+
11
+ - `AkaiToolError` — a typed, caller-facing tool failure carrying a stable `kind`
12
+ (`not_found` | `forbidden` | `auth_expired` | `invalid_input` | `conflict` |
13
+ `rate_limited` | `unavailable`), `message`, and optional `meta`. Pins
14
+ `name` to `'AkaiToolError'` so the host runtime can brand-check the
15
+ serialized shape (`{ name, kind, message, meta? }`) with no SDK dependency,
16
+ map `kind` to an HTTP status, and surface the message verbatim.
17
+ - Ergonomic static factories on `AkaiToolError`: `notFound`, `forbidden`,
18
+ `authExpired`, `invalidInput`, `conflict`, `rateLimited`, `unavailable`.
19
+ - Exported the `ToolErrorKind` type from the package entrypoint.
package/README.md CHANGED
@@ -346,9 +346,36 @@ Each tool branches on `isJson` and uses the structured logger. The folder includ
346
346
  | `AkaiSecretError` | A `required: true` secret is missing at invocation time — thrown by `buildCtx` |
347
347
  | `AkaiPropertyError`| A `required: true` property is missing at invocation time — thrown by `buildCtx` |
348
348
  | `AkaiEgressError` | `ctx.fetch` rejected the target |
349
+ | `AkaiToolError` | A handler threw a typed, caller-facing failure — the host maps `kind` to an HTTP status and surfaces the message verbatim |
349
350
 
350
351
  Every error extends `AkaiError`; the runtime maps each to a structured error envelope.
351
352
 
353
+ ### Typed tool errors
354
+
355
+ Throw `AkaiToolError` from a handler to give an expected failure a stable classification and author-vetted wording. The host runtime brand-checks the thrown value by its serialized shape — `{ name: 'AkaiToolError', kind, message, meta? }` — with no SDK dependency, maps `kind` to an HTTP status, and returns `message` to the caller **verbatim**. Keep messages secret-free.
356
+
357
+ ```ts
358
+ import { AkaiToolError } from '@akai-workflow-builder/cli-sdk';
359
+
360
+ const res = await ctx.fetch(`https://api.example.com/tickets/${id}`);
361
+ if (res.status === 404) throw AkaiToolError.notFound(`No ticket ${id}`, { id });
362
+ if (res.status === 429) throw AkaiToolError.rateLimited('Slow down', { retryAfterMs: 1000 });
363
+ ```
364
+
365
+ Factories — each sets the matching `kind`:
366
+
367
+ | Factory | `kind` | Host status |
368
+ |---|---|---|
369
+ | `AkaiToolError.notFound(msg, meta?)` | `not_found` | 404 |
370
+ | `AkaiToolError.forbidden(msg, meta?)` | `forbidden` | 403 |
371
+ | `AkaiToolError.authExpired(msg, meta?)` | `auth_expired` | 401 |
372
+ | `AkaiToolError.invalidInput(msg, meta?)` | `invalid_input` | 422 |
373
+ | `AkaiToolError.conflict(msg, meta?)` | `conflict` | 409 |
374
+ | `AkaiToolError.rateLimited(msg, meta?)` | `rate_limited` | 429 (retryable) |
375
+ | `AkaiToolError.unavailable(msg, meta?)` | `unavailable` | 503 (retryable) |
376
+
377
+ Untyped throws are classified generically (a 500 with a derived message).
378
+
352
379
  ---
353
380
 
354
381
  ## Troubleshooting
package/dist/errors.d.ts CHANGED
@@ -25,4 +25,60 @@ export declare class AkaiPropertyError extends AkaiError {
25
25
  /** `ctx.safePath` rejected a path that resolves outside the allowed roots. */
26
26
  export declare class AkaiPathError extends AkaiError {
27
27
  }
28
+ /**
29
+ * Stable, vendor-neutral classification for a caller-facing tool failure.
30
+ *
31
+ * The host runtime maps each `kind` to an HTTP status and surfaces the
32
+ * accompanying `message` to the caller verbatim, so an agent can reason about
33
+ * the failure programmatically (fix the id, ask to be granted access,
34
+ * reconnect, retry) instead of seeing an opaque 500.
35
+ *
36
+ * - `not_found` — host maps to **404**: the entity does not exist or is not
37
+ * visible to this caller. Check the id/URL and that you have access.
38
+ * - `forbidden` — host maps to **403**: the entity exists but the caller lacks
39
+ * permission (not shared, insufficient scope).
40
+ * - `auth_expired` — host maps to **401**: the credential is invalid or expired;
41
+ * reconnect the integration.
42
+ * - `invalid_input` — host maps to **422**: arguments are well-formed but violate
43
+ * a runtime constraint the schema cannot express.
44
+ * - `conflict` — host maps to **409**: the request conflicts with current state
45
+ * (already exists, version mismatch).
46
+ * - `rate_limited` — host maps to **429**: an upstream throttle was hit; retryable.
47
+ * Put a hint in `meta` (e.g. `{ retryAfterMs }`).
48
+ * - `unavailable` — host maps to **503**: upstream is down, timed out, or
49
+ * unreachable; retryable.
50
+ */
51
+ export type ToolErrorKind = 'not_found' | 'forbidden' | 'auth_expired' | 'invalid_input' | 'conflict' | 'rate_limited' | 'unavailable';
52
+ /**
53
+ * Caller-facing tool failure with a stable, vendor-neutral {@link ToolErrorKind}.
54
+ *
55
+ * Throw this from a tool handler when you want bespoke, author-vetted wording
56
+ * for an expected failure. The host runtime brand-checks the thrown value by its
57
+ * serialized shape — `{ name: 'AkaiToolError', kind, message, meta? }` — so the
58
+ * `name` is pinned to `'AkaiToolError'` in the constructor and survives across
59
+ * package-boundary `instanceof` gaps. On a match the host maps `kind` to an HTTP
60
+ * status and returns `message` to the caller **verbatim**, so the message must be
61
+ * secret-free and safe to expose. Untyped throws are classified generically.
62
+ *
63
+ * @example
64
+ * throw AkaiToolError.notFound(`No ticket ${id}`, { id });
65
+ */
66
+ export declare class AkaiToolError extends AkaiError {
67
+ readonly kind: ToolErrorKind;
68
+ constructor(kind: ToolErrorKind, message: string, meta?: Record<string, unknown>);
69
+ /** `invalid_input` → host **422**: args violate a runtime constraint the schema can't express. */
70
+ static invalidInput(message: string, meta?: Record<string, unknown>): AkaiToolError;
71
+ /** `not_found` → host **404**: the entity doesn't exist or isn't visible to this caller. */
72
+ static notFound(message: string, meta?: Record<string, unknown>): AkaiToolError;
73
+ /** `forbidden` → host **403**: the entity exists but the caller lacks permission. */
74
+ static forbidden(message: string, meta?: Record<string, unknown>): AkaiToolError;
75
+ /** `auth_expired` → host **401**: the credential is invalid or expired; reconnect. */
76
+ static authExpired(message: string, meta?: Record<string, unknown>): AkaiToolError;
77
+ /** `conflict` → host **409**: the request conflicts with current state. */
78
+ static conflict(message: string, meta?: Record<string, unknown>): AkaiToolError;
79
+ /** `rate_limited` → host **429**: upstream throttle hit; retryable (e.g. `meta.retryAfterMs`). */
80
+ static rateLimited(message: string, meta?: Record<string, unknown>): AkaiToolError;
81
+ /** `unavailable` → host **503**: upstream down/timed-out/unreachable; retryable. */
82
+ static unavailable(message: string, meta?: Record<string, unknown>): AkaiToolError;
83
+ }
28
84
  //# sourceMappingURL=errors.d.ts.map
@@ -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,+EAA+E;AAC/E,qBAAa,cAAe,SAAQ,SAAS;CAAG;AAEhD,8CAA8C;AAC9C,qBAAa,eAAgB,SAAQ,SAAS;CAAG;AAEjD,sDAAsD;AACtD,qBAAa,eAAgB,SAAQ,SAAS;CAAG;AAEjD,+DAA+D;AAC/D,qBAAa,iBAAkB,SAAQ,SAAS;CAAG;AAGnD,8EAA8E;AAC9E,qBAAa,aAAc,SAAQ,SAAS;CAAG"}
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,CA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C,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAIlF,2EAA2E;IAC3E,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAI/E,kGAAkG;IAClG,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;CAGnF"}
package/dist/errors.js CHANGED
@@ -29,3 +29,53 @@ export class AkaiPropertyError extends AkaiError {
29
29
  /** `ctx.safePath` rejected a path that resolves outside the allowed roots. */
30
30
  export class AkaiPathError extends AkaiError {
31
31
  }
32
+ /**
33
+ * Caller-facing tool failure with a stable, vendor-neutral {@link ToolErrorKind}.
34
+ *
35
+ * Throw this from a tool handler when you want bespoke, author-vetted wording
36
+ * for an expected failure. The host runtime brand-checks the thrown value by its
37
+ * serialized shape — `{ name: 'AkaiToolError', kind, message, meta? }` — so the
38
+ * `name` is pinned to `'AkaiToolError'` in the constructor and survives across
39
+ * package-boundary `instanceof` gaps. On a match the host maps `kind` to an HTTP
40
+ * status and returns `message` to the caller **verbatim**, so the message must be
41
+ * secret-free and safe to expose. Untyped throws are classified generically.
42
+ *
43
+ * @example
44
+ * throw AkaiToolError.notFound(`No ticket ${id}`, { id });
45
+ */
46
+ export class AkaiToolError extends AkaiError {
47
+ kind;
48
+ constructor(kind, message, meta) {
49
+ super(message, meta);
50
+ this.name = 'AkaiToolError';
51
+ this.kind = kind;
52
+ }
53
+ /** `invalid_input` → host **422**: args violate a runtime constraint the schema can't express. */
54
+ static invalidInput(message, meta) {
55
+ return new AkaiToolError('invalid_input', message, meta);
56
+ }
57
+ /** `not_found` → host **404**: the entity doesn't exist or isn't visible to this caller. */
58
+ static notFound(message, meta) {
59
+ return new AkaiToolError('not_found', message, meta);
60
+ }
61
+ /** `forbidden` → host **403**: the entity exists but the caller lacks permission. */
62
+ static forbidden(message, meta) {
63
+ return new AkaiToolError('forbidden', message, meta);
64
+ }
65
+ /** `auth_expired` → host **401**: the credential is invalid or expired; reconnect. */
66
+ static authExpired(message, meta) {
67
+ return new AkaiToolError('auth_expired', message, meta);
68
+ }
69
+ /** `conflict` → host **409**: the request conflicts with current state. */
70
+ static conflict(message, meta) {
71
+ return new AkaiToolError('conflict', message, meta);
72
+ }
73
+ /** `rate_limited` → host **429**: upstream throttle hit; retryable (e.g. `meta.retryAfterMs`). */
74
+ static rateLimited(message, meta) {
75
+ return new AkaiToolError('rate_limited', message, meta);
76
+ }
77
+ /** `unavailable` → host **503**: upstream down/timed-out/unreachable; retryable. */
78
+ static unavailable(message, meta) {
79
+ return new AkaiToolError('unavailable', message, meta);
80
+ }
81
+ }
package/dist/index.d.ts CHANGED
@@ -8,7 +8,8 @@ export type { BuildCtxParams } from './ctx/build-ctx.js';
8
8
  export type { AnyToolDef, CLIDef, CLISpec, DynamicEgress, InputOf, NetworkOptions, OutputOf, PropertiesOf, PropertyDecl, SecretDecl, SecretsOf, ToolCtx, ToolDef, ToolLogger, ToolOptions, ToolSpec, } from './types.js';
9
9
  export { createSafePath } from './ctx/safe-path.js';
10
10
  export type { SafePath } from './ctx/safe-path.js';
11
- export { AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, } from './errors.js';
11
+ export { AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, AkaiToolError, } from './errors.js';
12
+ export type { ToolErrorKind } from './errors.js';
12
13
  export { ConnectionManifestSchema, ManifestJSONSchema, SCHEMA_VERSION, toSchema, validateManifest, } from './manifest/index.js';
13
14
  export type { ConnectionManifest, DynamicEgressManifest, HttpToolManifest, ManifestProperty, ManifestSecret, NativeToolManifest, SchemaVersion, ToolManifest, } from './manifest/index.js';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -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,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAChE,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,aAAa,EACb,OAAO,EACP,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,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,eAAe,EACf,SAAS,EACT,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,c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c,EACd,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -4,5 +4,5 @@ export { filePath, FILE_INPUT_META_KEY } from './file-input.js';
4
4
  export { buildScopedSecrets, buildScopedProperties } from './ctx/secrets.js';
5
5
  export { buildCtx } from './ctx/build-ctx.js';
6
6
  export { createSafePath } from './ctx/safe-path.js';
7
- export { AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, } from './errors.js';
7
+ export { AkaiEgressError, AkaiError, AkaiInputError, AkaiPathError, AkaiPropertyError, AkaiSecretError, AkaiSpecError, AkaiToolError, } from './errors.js';
8
8
  export { ConnectionManifestSchema, ManifestJSONSchema, SCHEMA_VERSION, toSchema, validateManifest, } from './manifest/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akai-workflow-builder/cli-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Authoring SDK for atomic, agent-executable CLIs and tools.",
5
5
  "keywords": [
6
6
  "akai",
@@ -28,6 +28,7 @@
28
28
  "files": [
29
29
  "bin",
30
30
  "dist",
31
+ "CHANGELOG.md",
31
32
  "LICENSE",
32
33
  "README.md"
33
34
  ],