@cadraos/sdk 0.3.14-p46.3 → 0.3.14

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 (52) hide show
  1. package/README.md +104 -53
  2. package/dist/ai-functions/react/index.cjs +176 -0
  3. package/dist/ai-functions/react/index.cjs.map +1 -0
  4. package/dist/ai-functions/react/index.d.cts +129 -0
  5. package/dist/ai-functions/react/index.d.ts +129 -0
  6. package/dist/ai-functions/react/index.js +153 -0
  7. package/dist/ai-functions/react/index.js.map +1 -0
  8. package/dist/ai-functions/server/index.cjs +296 -0
  9. package/dist/ai-functions/server/index.cjs.map +1 -0
  10. package/dist/ai-functions/server/index.d.cts +334 -0
  11. package/dist/ai-functions/server/index.d.ts +334 -0
  12. package/dist/ai-functions/server/index.js +284 -0
  13. package/dist/ai-functions/server/index.js.map +1 -0
  14. package/dist/board-host/index.cjs +217 -129
  15. package/dist/board-host/index.cjs.map +1 -1
  16. package/dist/board-host/index.d.cts +96 -1
  17. package/dist/board-host/index.d.ts +96 -1
  18. package/dist/board-host/index.js +218 -131
  19. package/dist/board-host/index.js.map +1 -1
  20. package/dist/board-host/server/index.d.cts +44 -0
  21. package/dist/board-host/server/index.d.ts +44 -0
  22. package/dist/chat/index.cjs +299 -17
  23. package/dist/chat/index.cjs.map +1 -1
  24. package/dist/chat/index.d.cts +225 -0
  25. package/dist/chat/index.d.ts +225 -0
  26. package/dist/chat/index.js +299 -17
  27. package/dist/chat/index.js.map +1 -1
  28. package/dist/index.cjs +221 -3
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +286 -1
  31. package/dist/index.d.ts +286 -1
  32. package/dist/index.js +215 -4
  33. package/dist/index.js.map +1 -1
  34. package/dist/kanban/engine/index.cjs +774 -683
  35. package/dist/kanban/engine/index.cjs.map +1 -1
  36. package/dist/kanban/engine/index.d.cts +90 -1
  37. package/dist/kanban/engine/index.d.ts +90 -1
  38. package/dist/kanban/engine/index.js +774 -684
  39. package/dist/kanban/engine/index.js.map +1 -1
  40. package/dist/kanban/index.cjs +214 -3
  41. package/dist/kanban/index.cjs.map +1 -1
  42. package/dist/kanban/index.d.cts +252 -0
  43. package/dist/kanban/index.d.ts +252 -0
  44. package/dist/kanban/index.js +214 -3
  45. package/dist/kanban/index.js.map +1 -1
  46. package/dist/teams/index.cjs +214 -3
  47. package/dist/teams/index.cjs.map +1 -1
  48. package/dist/teams/index.d.cts +225 -0
  49. package/dist/teams/index.d.ts +225 -0
  50. package/dist/teams/index.js +214 -3
  51. package/dist/teams/index.js.map +1 -1
  52. package/package.json +21 -1
@@ -319,6 +319,11 @@ interface KanbanCard$1 {
319
319
  configVersion?: number;
320
320
  /** Arbitrary shared context carried across transitions. */
321
321
  sharedContext?: Record<string, unknown>;
322
+ /**
323
+ * p46 (P46-002): the card's id in an external host (a Jira issue key).
324
+ * Absent on native / crm / yobo cards.
325
+ */
326
+ externalRef?: string;
322
327
  /**
323
328
  * Execution UUID of the card's current/last run, if any.
324
329
  *
@@ -381,6 +386,18 @@ interface CreateCardInput {
381
386
  * in the lifecycle's initial lane.
382
387
  */
383
388
  lane?: string;
389
+ /**
390
+ * p46 (P46-002): the card's id in an EXTERNAL host (a Jira issue key, e.g.
391
+ * `CAD-231`). Optional. When set, a card is created at most ONCE per
392
+ * `(boardConfigUuid, externalRef)`: a repeat create returns the existing card
393
+ * and dispatches nothing. Hosts that don't store it simply ignore it.
394
+ */
395
+ externalRef?: string;
396
+ /**
397
+ * p46 (P46-002): opaque host facts stored with the card (Jira `statusId`,
398
+ * `mover`, `detached`, …). Passed through to `adapter.createCard` untouched.
399
+ */
400
+ externalMeta?: Record<string, unknown>;
384
401
  }
385
402
  /**
386
403
  * Input for transitioning a card to another lane.
@@ -540,6 +557,23 @@ interface ApplyTransitionInput {
540
557
  contextPatch?: Record<string, unknown>;
541
558
  /** Execution UUID to stamp on the card (handler advances). */
542
559
  executionUuid?: string;
560
+ /**
561
+ * p46 (P46-002, F8): set ONLY by `engine.hostMove` (a move the external host
562
+ * made — e.g. a Jira drag mirrored by the sync). A host-aware adapter, inside
563
+ * the same card lock as the `fromLane` CAS, (1) refuses the move with a
564
+ * `HostFenceError` while the card has any `host.*` op `pending` (D19 — never
565
+ * mistake our own half-done move for a human one), (2) writes `externalMeta`,
566
+ * then (3) moves. Adapters that don't know it ignore it (optional, additive).
567
+ */
568
+ hostObservation?: {
569
+ externalMeta?: Record<string, unknown>;
570
+ /**
571
+ * ISO time the host state was READ. The fence also refuses the move when a
572
+ * `host.*` op for the card settled (done/failed) after this instant — the
573
+ * read may predate our own write landing in the host.
574
+ */
575
+ observedAt?: string;
576
+ };
543
577
  }
544
578
 
545
579
  /**
@@ -1238,6 +1272,16 @@ interface ToolResultEvent {
1238
1272
  result: unknown;
1239
1273
  /** Duration in milliseconds */
1240
1274
  durationMs: number;
1275
+ /**
1276
+ * CAD-243: true when the tool call FAILED (the producer stamps
1277
+ * `isError: true` + `status: 'failed'` on a thrown tool call). Absent on
1278
+ * older producers — consumers then fall back to the result shape.
1279
+ */
1280
+ isError?: boolean;
1281
+ /** CAD-243: producer verdict, `'failed'` for a failed call. */
1282
+ status?: string;
1283
+ /** CAD-243: error text for a failed call. */
1284
+ error?: string;
1241
1285
  /** See {@link ToolCallEvent.forwardedFrom} */
1242
1286
  forwardedFrom?: string;
1243
1287
  /** See {@link ToolCallEvent.sourceExecutionId} (CAD-87 S1-001). */
@@ -2825,6 +2869,12 @@ interface RequestOptions {
2825
2869
  skipRetry?: boolean;
2826
2870
  /** Idempotency key */
2827
2871
  idempotencyKey?: string;
2872
+ /**
2873
+ * Per-request timeout in milliseconds. Overrides the client-wide
2874
+ * `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
2875
+ * may take up to 60 s while every other call keeps the 30 s default).
2876
+ */
2877
+ timeoutMs?: number;
2828
2878
  }
2829
2879
  /**
2830
2880
  * HTTP Client class
@@ -2856,6 +2906,7 @@ declare class HttpClient {
2856
2906
  post<T>(path: string, body?: unknown, options?: {
2857
2907
  idempotencyKey?: string;
2858
2908
  skipRetry?: boolean;
2909
+ timeoutMs?: number;
2859
2910
  }): Promise<T>;
2860
2911
  /**
2861
2912
  * PATCH request
@@ -3483,6 +3534,133 @@ interface RemoteAgentExecuteResponse {
3483
3534
  streamUrl: string;
3484
3535
  }
3485
3536
 
3537
+ /**
3538
+ * AI function types (p93 — specs §4 run contract, D27 discovery, §6.5 run reads).
3539
+ *
3540
+ * An AI function is a published prompt in the Cadra Prompts library that makes
3541
+ * ONE direct AI-provider call (never an agent). Callers reference it by its
3542
+ * `functionKey` (unique per org), by prompt uuid, or — for platform features —
3543
+ * by slot key.
3544
+ */
3545
+ /** Output kind of an AI function. */
3546
+ type AiFunctionOutputKind = 'text' | 'json' | 'image';
3547
+ /** Parameter (prompt variable) types — specs D10 + D26d. */
3548
+ type AiFunctionParameterType = 'string' | 'text' | 'number' | 'boolean' | 'enum' | 'image';
3549
+ /** A value passed for one parameter. `image` parameters take an artifact uuid (string). */
3550
+ type AiFunctionVariableValue = string | number | boolean;
3551
+ /** Parameters (variables) for one run, keyed by parameter name. */
3552
+ type AiFunctionVariables = Record<string, AiFunctionVariableValue>;
3553
+ /** How a run names its function (§4). */
3554
+ type AiFunctionRef = {
3555
+ slot: string;
3556
+ } | {
3557
+ functionKey: string;
3558
+ } | {
3559
+ promptUuid: string;
3560
+ };
3561
+ /** One declared parameter of a function's live (golden) version — D27a. */
3562
+ interface AiFunctionParameter {
3563
+ name: string;
3564
+ type: AiFunctionParameterType;
3565
+ required: boolean;
3566
+ defaultValue?: AiFunctionVariableValue;
3567
+ maxLength?: number;
3568
+ options?: string[];
3569
+ description?: string;
3570
+ }
3571
+ /**
3572
+ * The discovery "index" entry for one callable function — D27a. Built from the
3573
+ * golden version snapshot; never carries prompt or system text.
3574
+ */
3575
+ interface AiFunctionDescriptor {
3576
+ functionKey: string;
3577
+ title: string;
3578
+ description?: string | null;
3579
+ outputKind: AiFunctionOutputKind;
3580
+ /** The live (golden) version number. */
3581
+ liveVersion: number;
3582
+ parameters: AiFunctionParameter[];
3583
+ /** JSON schema of the output, for `json` functions. */
3584
+ outputSchema?: Record<string, unknown> | null;
3585
+ }
3586
+ /** Who paid for a run (D4). */
3587
+ type AiFunctionBilledTo = 'own_key' | 'credits' | 'platform_funded';
3588
+ /** Runtime params a slot may accept per run (D26d3). */
3589
+ interface AiFunctionRuntimeParams {
3590
+ aspect_ratio?: string;
3591
+ image_size?: string;
3592
+ }
3593
+ /** Options for the object form `run(ref, { variables, … })`. */
3594
+ interface AiFunctionRunOptions {
3595
+ /** Parameters for this run (sent as `variables`). */
3596
+ variables: AiFunctionVariables;
3597
+ /** Pin a published version number (D3d). Skips the client-side check. */
3598
+ version?: number;
3599
+ /** Idempotency key (uuid). Generated when omitted (D15). */
3600
+ idempotencyKey?: string;
3601
+ /** Slot runtime params (D26d3). */
3602
+ params?: AiFunctionRuntimeParams;
3603
+ /** `false` skips the client-side parameter check (D27c). Default true. */
3604
+ validate?: boolean;
3605
+ }
3606
+ /** Options for the shorthand `run('function_key', parameters, opts)`. */
3607
+ type AiFunctionRunShorthandOptions = Omit<AiFunctionRunOptions, 'variables'>;
3608
+ /** Image produced by an `image` function. Over HTTP only `url` (presigned, 1 h) is set. */
3609
+ interface AiFunctionImage {
3610
+ mimeType: string;
3611
+ url?: string;
3612
+ bytes?: Uint8Array;
3613
+ }
3614
+ /** Output of a run, by kind (§4). `TOutput` types `json`. */
3615
+ type AiFunctionOutput<TOutput = unknown> = {
3616
+ type: 'text';
3617
+ text: string;
3618
+ } | {
3619
+ type: 'json';
3620
+ json: TOutput;
3621
+ } | {
3622
+ type: 'image';
3623
+ images: AiFunctionImage[];
3624
+ };
3625
+ /** Token and billing usage of a run (§4). */
3626
+ interface AiFunctionUsage {
3627
+ promptTokens: number;
3628
+ completionTokens: number;
3629
+ imageCount: number;
3630
+ billedTo: AiFunctionBilledTo;
3631
+ }
3632
+ /** Result of a successful run (§4). */
3633
+ interface AiFunctionRunResult<TOutput = unknown> {
3634
+ /** = the run's execution uuid (usage-ledger executionUuid). */
3635
+ executionId: string;
3636
+ functionUuid: string;
3637
+ version: number;
3638
+ output: AiFunctionOutput<TOutput>;
3639
+ usage: AiFunctionUsage;
3640
+ latencyMs: number;
3641
+ }
3642
+ /** Run status as reported by run reads (D12; `abandoned` is computed on read). */
3643
+ type AiFunctionRunStatus = 'running' | 'succeeded' | 'failed_provider' | 'failed_timeout' | 'refused_billing' | 'failed_output' | 'failed_delivery' | 'abandoned';
3644
+ /** Safe projection of one of the caller org's own runs (§6.5). */
3645
+ interface AiFunctionRun {
3646
+ executionId: string;
3647
+ ref: {
3648
+ slot?: string;
3649
+ functionKey?: string;
3650
+ promptUuid?: string;
3651
+ };
3652
+ version: number | null;
3653
+ status: AiFunctionRunStatus;
3654
+ errorCode: string | null;
3655
+ promptTokens: number | null;
3656
+ completionTokens: number | null;
3657
+ imageCount: number | null;
3658
+ latencyMs: number | null;
3659
+ billedTo: AiFunctionBilledTo | null;
3660
+ createdAt: string;
3661
+ finishedAt: string | null;
3662
+ }
3663
+
3486
3664
  /**
3487
3665
  * Base Resource API
3488
3666
  *
@@ -3511,6 +3689,7 @@ declare abstract class BaseResourceAPI {
3511
3689
  protected httpPost<T>(path: string, body?: unknown, options?: {
3512
3690
  idempotencyKey?: string;
3513
3691
  skipRetry?: boolean;
3692
+ timeoutMs?: number;
3514
3693
  }): Promise<T>;
3515
3694
  /**
3516
3695
  * HTTP PATCH request helper
@@ -4710,6 +4889,65 @@ declare class RemoteRunnersAPI extends BaseResourceAPI {
4710
4889
  list(options?: RemoteRunnerListOptions): Promise<PaginatedResponse<RemoteRunner>>;
4711
4890
  }
4712
4891
 
4892
+ /**
4893
+ * AI Functions API (p93 AIF-010 — specs §9, D27).
4894
+ *
4895
+ * @example
4896
+ * ```typescript
4897
+ * // Discover what the org can call, and with which parameters
4898
+ * const functions = await client.aiFunctions.list();
4899
+ * const fn = await client.aiFunctions.get('summarise_ticket');
4900
+ *
4901
+ * // Call it — parameters are checked against the live version before sending
4902
+ * const result = await client.aiFunctions.run('summarise_ticket', { ticket_text: '…' });
4903
+ * if (result.output.type === 'text') console.log(result.output.text);
4904
+ * ```
4905
+ */
4906
+
4907
+ /**
4908
+ * AI Functions API
4909
+ */
4910
+ declare class AiFunctionsAPI extends BaseResourceAPI {
4911
+ private readonly descriptorCache;
4912
+ constructor(http: HttpClient);
4913
+ /**
4914
+ * List the functions this org can call — the index (D27a). Each entry carries
4915
+ * the live version's typed parameters; never prompt text.
4916
+ */
4917
+ list(): Promise<AiFunctionDescriptor[]>;
4918
+ /**
4919
+ * Get one function's descriptor by key (D27a).
4920
+ * `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
4921
+ */
4922
+ get(functionKey: string): Promise<AiFunctionDescriptor>;
4923
+ /**
4924
+ * Read one of this org's own runs (safe projection, §6.5).
4925
+ */
4926
+ getRun(executionId: string): Promise<AiFunctionRun>;
4927
+ /** Forget cached descriptors (one key, or all). */
4928
+ clearDescriptorCache(functionKey?: string): void;
4929
+ /**
4930
+ * Run an AI function — one paid provider call.
4931
+ *
4932
+ * - `run('function_key', parameters, opts?)` — shorthand for `{ functionKey }`.
4933
+ * - `run({ functionKey | promptUuid | slot }, { variables, version?, idempotencyKey?, params?, validate? })`.
4934
+ *
4935
+ * For a `functionKey` ref without a pinned `version`, parameters are checked
4936
+ * against the live version first (D27c); a problem throws
4937
+ * `AiFunctionParameterError` and NO run request is sent. Paid runs are never
4938
+ * auto-retried; an idempotency key is generated when omitted.
4939
+ *
4940
+ * @throws AiFunctionParameterError — client-side check failed (nothing sent)
4941
+ * @throws AiFunctionDuplicateError — 409 `DUPLICATE_REQUEST`
4942
+ * @throws AiFunctionChargedError — the run was metered but its output failed (`details.charged`)
4943
+ */
4944
+ run<TOutput = unknown>(functionKey: string, parameters: AiFunctionVariables, opts?: AiFunctionRunShorthandOptions): Promise<AiFunctionRunResult<TOutput>>;
4945
+ run<TOutput = unknown>(ref: AiFunctionRef, options: AiFunctionRunOptions): Promise<AiFunctionRunResult<TOutput>>;
4946
+ private cacheDescriptor;
4947
+ private getCachedDescriptor;
4948
+ private mapRunError;
4949
+ }
4950
+
4713
4951
  /**
4714
4952
  * Cadra Client
4715
4953
  *
@@ -4854,6 +5092,10 @@ declare class CadraClient {
4854
5092
  * Remote runner operations (list)
4855
5093
  */
4856
5094
  readonly remoteRunners: RemoteRunnersAPI;
5095
+ /**
5096
+ * AI function operations (list, get, run, getRun) — p93
5097
+ */
5098
+ readonly aiFunctions: AiFunctionsAPI;
4857
5099
  /**
4858
5100
  * Create a new AI SaaS client
4859
5101
  *
@@ -5024,6 +5266,16 @@ interface KanbanStorageAdapter {
5024
5266
  * config and passes it as `initialLane`.
5025
5267
  */
5026
5268
  createCard(input: CreateCardServerInput): Promise<KanbanCard$1>;
5269
+ /**
5270
+ * p46 (P46-002) OPTIONAL: the card with this `externalRef` on this board, or
5271
+ * null. When present, `engine.createCard({externalRef})` looks it up first and
5272
+ * returns an existing card WITHOUT dispatching (exactly-once create per issue
5273
+ * key). A host that stores `externalRef` SHOULD also make `createCard` itself
5274
+ * idempotent on `(boardConfigUuid, externalRef)` (unique index + `ON CONFLICT
5275
+ * DO NOTHING` → return the existing row) for the lookup/insert race. Hosts
5276
+ * without external refs (crm/yobo) omit it.
5277
+ */
5278
+ getCardByExternalRef?(boardConfigUuid: string, externalRef: string): Promise<KanbanCard$1 | null>;
5027
5279
  /**
5028
5280
  * Patch a card's mutable fields.
5029
5281
  */
@@ -319,6 +319,11 @@ interface KanbanCard$1 {
319
319
  configVersion?: number;
320
320
  /** Arbitrary shared context carried across transitions. */
321
321
  sharedContext?: Record<string, unknown>;
322
+ /**
323
+ * p46 (P46-002): the card's id in an external host (a Jira issue key).
324
+ * Absent on native / crm / yobo cards.
325
+ */
326
+ externalRef?: string;
322
327
  /**
323
328
  * Execution UUID of the card's current/last run, if any.
324
329
  *
@@ -381,6 +386,18 @@ interface CreateCardInput {
381
386
  * in the lifecycle's initial lane.
382
387
  */
383
388
  lane?: string;
389
+ /**
390
+ * p46 (P46-002): the card's id in an EXTERNAL host (a Jira issue key, e.g.
391
+ * `CAD-231`). Optional. When set, a card is created at most ONCE per
392
+ * `(boardConfigUuid, externalRef)`: a repeat create returns the existing card
393
+ * and dispatches nothing. Hosts that don't store it simply ignore it.
394
+ */
395
+ externalRef?: string;
396
+ /**
397
+ * p46 (P46-002): opaque host facts stored with the card (Jira `statusId`,
398
+ * `mover`, `detached`, …). Passed through to `adapter.createCard` untouched.
399
+ */
400
+ externalMeta?: Record<string, unknown>;
384
401
  }
385
402
  /**
386
403
  * Input for transitioning a card to another lane.
@@ -540,6 +557,23 @@ interface ApplyTransitionInput {
540
557
  contextPatch?: Record<string, unknown>;
541
558
  /** Execution UUID to stamp on the card (handler advances). */
542
559
  executionUuid?: string;
560
+ /**
561
+ * p46 (P46-002, F8): set ONLY by `engine.hostMove` (a move the external host
562
+ * made — e.g. a Jira drag mirrored by the sync). A host-aware adapter, inside
563
+ * the same card lock as the `fromLane` CAS, (1) refuses the move with a
564
+ * `HostFenceError` while the card has any `host.*` op `pending` (D19 — never
565
+ * mistake our own half-done move for a human one), (2) writes `externalMeta`,
566
+ * then (3) moves. Adapters that don't know it ignore it (optional, additive).
567
+ */
568
+ hostObservation?: {
569
+ externalMeta?: Record<string, unknown>;
570
+ /**
571
+ * ISO time the host state was READ. The fence also refuses the move when a
572
+ * `host.*` op for the card settled (done/failed) after this instant — the
573
+ * read may predate our own write landing in the host.
574
+ */
575
+ observedAt?: string;
576
+ };
543
577
  }
544
578
 
545
579
  /**
@@ -1238,6 +1272,16 @@ interface ToolResultEvent {
1238
1272
  result: unknown;
1239
1273
  /** Duration in milliseconds */
1240
1274
  durationMs: number;
1275
+ /**
1276
+ * CAD-243: true when the tool call FAILED (the producer stamps
1277
+ * `isError: true` + `status: 'failed'` on a thrown tool call). Absent on
1278
+ * older producers — consumers then fall back to the result shape.
1279
+ */
1280
+ isError?: boolean;
1281
+ /** CAD-243: producer verdict, `'failed'` for a failed call. */
1282
+ status?: string;
1283
+ /** CAD-243: error text for a failed call. */
1284
+ error?: string;
1241
1285
  /** See {@link ToolCallEvent.forwardedFrom} */
1242
1286
  forwardedFrom?: string;
1243
1287
  /** See {@link ToolCallEvent.sourceExecutionId} (CAD-87 S1-001). */
@@ -2825,6 +2869,12 @@ interface RequestOptions {
2825
2869
  skipRetry?: boolean;
2826
2870
  /** Idempotency key */
2827
2871
  idempotencyKey?: string;
2872
+ /**
2873
+ * Per-request timeout in milliseconds. Overrides the client-wide
2874
+ * `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
2875
+ * may take up to 60 s while every other call keeps the 30 s default).
2876
+ */
2877
+ timeoutMs?: number;
2828
2878
  }
2829
2879
  /**
2830
2880
  * HTTP Client class
@@ -2856,6 +2906,7 @@ declare class HttpClient {
2856
2906
  post<T>(path: string, body?: unknown, options?: {
2857
2907
  idempotencyKey?: string;
2858
2908
  skipRetry?: boolean;
2909
+ timeoutMs?: number;
2859
2910
  }): Promise<T>;
2860
2911
  /**
2861
2912
  * PATCH request
@@ -3483,6 +3534,133 @@ interface RemoteAgentExecuteResponse {
3483
3534
  streamUrl: string;
3484
3535
  }
3485
3536
 
3537
+ /**
3538
+ * AI function types (p93 — specs §4 run contract, D27 discovery, §6.5 run reads).
3539
+ *
3540
+ * An AI function is a published prompt in the Cadra Prompts library that makes
3541
+ * ONE direct AI-provider call (never an agent). Callers reference it by its
3542
+ * `functionKey` (unique per org), by prompt uuid, or — for platform features —
3543
+ * by slot key.
3544
+ */
3545
+ /** Output kind of an AI function. */
3546
+ type AiFunctionOutputKind = 'text' | 'json' | 'image';
3547
+ /** Parameter (prompt variable) types — specs D10 + D26d. */
3548
+ type AiFunctionParameterType = 'string' | 'text' | 'number' | 'boolean' | 'enum' | 'image';
3549
+ /** A value passed for one parameter. `image` parameters take an artifact uuid (string). */
3550
+ type AiFunctionVariableValue = string | number | boolean;
3551
+ /** Parameters (variables) for one run, keyed by parameter name. */
3552
+ type AiFunctionVariables = Record<string, AiFunctionVariableValue>;
3553
+ /** How a run names its function (§4). */
3554
+ type AiFunctionRef = {
3555
+ slot: string;
3556
+ } | {
3557
+ functionKey: string;
3558
+ } | {
3559
+ promptUuid: string;
3560
+ };
3561
+ /** One declared parameter of a function's live (golden) version — D27a. */
3562
+ interface AiFunctionParameter {
3563
+ name: string;
3564
+ type: AiFunctionParameterType;
3565
+ required: boolean;
3566
+ defaultValue?: AiFunctionVariableValue;
3567
+ maxLength?: number;
3568
+ options?: string[];
3569
+ description?: string;
3570
+ }
3571
+ /**
3572
+ * The discovery "index" entry for one callable function — D27a. Built from the
3573
+ * golden version snapshot; never carries prompt or system text.
3574
+ */
3575
+ interface AiFunctionDescriptor {
3576
+ functionKey: string;
3577
+ title: string;
3578
+ description?: string | null;
3579
+ outputKind: AiFunctionOutputKind;
3580
+ /** The live (golden) version number. */
3581
+ liveVersion: number;
3582
+ parameters: AiFunctionParameter[];
3583
+ /** JSON schema of the output, for `json` functions. */
3584
+ outputSchema?: Record<string, unknown> | null;
3585
+ }
3586
+ /** Who paid for a run (D4). */
3587
+ type AiFunctionBilledTo = 'own_key' | 'credits' | 'platform_funded';
3588
+ /** Runtime params a slot may accept per run (D26d3). */
3589
+ interface AiFunctionRuntimeParams {
3590
+ aspect_ratio?: string;
3591
+ image_size?: string;
3592
+ }
3593
+ /** Options for the object form `run(ref, { variables, … })`. */
3594
+ interface AiFunctionRunOptions {
3595
+ /** Parameters for this run (sent as `variables`). */
3596
+ variables: AiFunctionVariables;
3597
+ /** Pin a published version number (D3d). Skips the client-side check. */
3598
+ version?: number;
3599
+ /** Idempotency key (uuid). Generated when omitted (D15). */
3600
+ idempotencyKey?: string;
3601
+ /** Slot runtime params (D26d3). */
3602
+ params?: AiFunctionRuntimeParams;
3603
+ /** `false` skips the client-side parameter check (D27c). Default true. */
3604
+ validate?: boolean;
3605
+ }
3606
+ /** Options for the shorthand `run('function_key', parameters, opts)`. */
3607
+ type AiFunctionRunShorthandOptions = Omit<AiFunctionRunOptions, 'variables'>;
3608
+ /** Image produced by an `image` function. Over HTTP only `url` (presigned, 1 h) is set. */
3609
+ interface AiFunctionImage {
3610
+ mimeType: string;
3611
+ url?: string;
3612
+ bytes?: Uint8Array;
3613
+ }
3614
+ /** Output of a run, by kind (§4). `TOutput` types `json`. */
3615
+ type AiFunctionOutput<TOutput = unknown> = {
3616
+ type: 'text';
3617
+ text: string;
3618
+ } | {
3619
+ type: 'json';
3620
+ json: TOutput;
3621
+ } | {
3622
+ type: 'image';
3623
+ images: AiFunctionImage[];
3624
+ };
3625
+ /** Token and billing usage of a run (§4). */
3626
+ interface AiFunctionUsage {
3627
+ promptTokens: number;
3628
+ completionTokens: number;
3629
+ imageCount: number;
3630
+ billedTo: AiFunctionBilledTo;
3631
+ }
3632
+ /** Result of a successful run (§4). */
3633
+ interface AiFunctionRunResult<TOutput = unknown> {
3634
+ /** = the run's execution uuid (usage-ledger executionUuid). */
3635
+ executionId: string;
3636
+ functionUuid: string;
3637
+ version: number;
3638
+ output: AiFunctionOutput<TOutput>;
3639
+ usage: AiFunctionUsage;
3640
+ latencyMs: number;
3641
+ }
3642
+ /** Run status as reported by run reads (D12; `abandoned` is computed on read). */
3643
+ type AiFunctionRunStatus = 'running' | 'succeeded' | 'failed_provider' | 'failed_timeout' | 'refused_billing' | 'failed_output' | 'failed_delivery' | 'abandoned';
3644
+ /** Safe projection of one of the caller org's own runs (§6.5). */
3645
+ interface AiFunctionRun {
3646
+ executionId: string;
3647
+ ref: {
3648
+ slot?: string;
3649
+ functionKey?: string;
3650
+ promptUuid?: string;
3651
+ };
3652
+ version: number | null;
3653
+ status: AiFunctionRunStatus;
3654
+ errorCode: string | null;
3655
+ promptTokens: number | null;
3656
+ completionTokens: number | null;
3657
+ imageCount: number | null;
3658
+ latencyMs: number | null;
3659
+ billedTo: AiFunctionBilledTo | null;
3660
+ createdAt: string;
3661
+ finishedAt: string | null;
3662
+ }
3663
+
3486
3664
  /**
3487
3665
  * Base Resource API
3488
3666
  *
@@ -3511,6 +3689,7 @@ declare abstract class BaseResourceAPI {
3511
3689
  protected httpPost<T>(path: string, body?: unknown, options?: {
3512
3690
  idempotencyKey?: string;
3513
3691
  skipRetry?: boolean;
3692
+ timeoutMs?: number;
3514
3693
  }): Promise<T>;
3515
3694
  /**
3516
3695
  * HTTP PATCH request helper
@@ -4710,6 +4889,65 @@ declare class RemoteRunnersAPI extends BaseResourceAPI {
4710
4889
  list(options?: RemoteRunnerListOptions): Promise<PaginatedResponse<RemoteRunner>>;
4711
4890
  }
4712
4891
 
4892
+ /**
4893
+ * AI Functions API (p93 AIF-010 — specs §9, D27).
4894
+ *
4895
+ * @example
4896
+ * ```typescript
4897
+ * // Discover what the org can call, and with which parameters
4898
+ * const functions = await client.aiFunctions.list();
4899
+ * const fn = await client.aiFunctions.get('summarise_ticket');
4900
+ *
4901
+ * // Call it — parameters are checked against the live version before sending
4902
+ * const result = await client.aiFunctions.run('summarise_ticket', { ticket_text: '…' });
4903
+ * if (result.output.type === 'text') console.log(result.output.text);
4904
+ * ```
4905
+ */
4906
+
4907
+ /**
4908
+ * AI Functions API
4909
+ */
4910
+ declare class AiFunctionsAPI extends BaseResourceAPI {
4911
+ private readonly descriptorCache;
4912
+ constructor(http: HttpClient);
4913
+ /**
4914
+ * List the functions this org can call — the index (D27a). Each entry carries
4915
+ * the live version's typed parameters; never prompt text.
4916
+ */
4917
+ list(): Promise<AiFunctionDescriptor[]>;
4918
+ /**
4919
+ * Get one function's descriptor by key (D27a).
4920
+ * `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
4921
+ */
4922
+ get(functionKey: string): Promise<AiFunctionDescriptor>;
4923
+ /**
4924
+ * Read one of this org's own runs (safe projection, §6.5).
4925
+ */
4926
+ getRun(executionId: string): Promise<AiFunctionRun>;
4927
+ /** Forget cached descriptors (one key, or all). */
4928
+ clearDescriptorCache(functionKey?: string): void;
4929
+ /**
4930
+ * Run an AI function — one paid provider call.
4931
+ *
4932
+ * - `run('function_key', parameters, opts?)` — shorthand for `{ functionKey }`.
4933
+ * - `run({ functionKey | promptUuid | slot }, { variables, version?, idempotencyKey?, params?, validate? })`.
4934
+ *
4935
+ * For a `functionKey` ref without a pinned `version`, parameters are checked
4936
+ * against the live version first (D27c); a problem throws
4937
+ * `AiFunctionParameterError` and NO run request is sent. Paid runs are never
4938
+ * auto-retried; an idempotency key is generated when omitted.
4939
+ *
4940
+ * @throws AiFunctionParameterError — client-side check failed (nothing sent)
4941
+ * @throws AiFunctionDuplicateError — 409 `DUPLICATE_REQUEST`
4942
+ * @throws AiFunctionChargedError — the run was metered but its output failed (`details.charged`)
4943
+ */
4944
+ run<TOutput = unknown>(functionKey: string, parameters: AiFunctionVariables, opts?: AiFunctionRunShorthandOptions): Promise<AiFunctionRunResult<TOutput>>;
4945
+ run<TOutput = unknown>(ref: AiFunctionRef, options: AiFunctionRunOptions): Promise<AiFunctionRunResult<TOutput>>;
4946
+ private cacheDescriptor;
4947
+ private getCachedDescriptor;
4948
+ private mapRunError;
4949
+ }
4950
+
4713
4951
  /**
4714
4952
  * Cadra Client
4715
4953
  *
@@ -4854,6 +5092,10 @@ declare class CadraClient {
4854
5092
  * Remote runner operations (list)
4855
5093
  */
4856
5094
  readonly remoteRunners: RemoteRunnersAPI;
5095
+ /**
5096
+ * AI function operations (list, get, run, getRun) — p93
5097
+ */
5098
+ readonly aiFunctions: AiFunctionsAPI;
4857
5099
  /**
4858
5100
  * Create a new AI SaaS client
4859
5101
  *
@@ -5024,6 +5266,16 @@ interface KanbanStorageAdapter {
5024
5266
  * config and passes it as `initialLane`.
5025
5267
  */
5026
5268
  createCard(input: CreateCardServerInput): Promise<KanbanCard$1>;
5269
+ /**
5270
+ * p46 (P46-002) OPTIONAL: the card with this `externalRef` on this board, or
5271
+ * null. When present, `engine.createCard({externalRef})` looks it up first and
5272
+ * returns an existing card WITHOUT dispatching (exactly-once create per issue
5273
+ * key). A host that stores `externalRef` SHOULD also make `createCard` itself
5274
+ * idempotent on `(boardConfigUuid, externalRef)` (unique index + `ON CONFLICT
5275
+ * DO NOTHING` → return the existing row) for the lookup/insert race. Hosts
5276
+ * without external refs (crm/yobo) omit it.
5277
+ */
5278
+ getCardByExternalRef?(boardConfigUuid: string, externalRef: string): Promise<KanbanCard$1 | null>;
5027
5279
  /**
5028
5280
  * Patch a card's mutable fields.
5029
5281
  */