@cadraos/sdk 0.3.14-p46.4 → 0.3.15
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/README.md +104 -53
- package/dist/ai-functions/react/index.cjs +176 -0
- package/dist/ai-functions/react/index.cjs.map +1 -0
- package/dist/ai-functions/react/index.d.cts +129 -0
- package/dist/ai-functions/react/index.d.ts +129 -0
- package/dist/ai-functions/react/index.js +153 -0
- package/dist/ai-functions/react/index.js.map +1 -0
- package/dist/ai-functions/server/index.cjs +296 -0
- package/dist/ai-functions/server/index.cjs.map +1 -0
- package/dist/ai-functions/server/index.d.cts +334 -0
- package/dist/ai-functions/server/index.d.ts +334 -0
- package/dist/ai-functions/server/index.js +284 -0
- package/dist/ai-functions/server/index.js.map +1 -0
- package/dist/chat/index.cjs +303 -17
- package/dist/chat/index.cjs.map +1 -1
- package/dist/chat/index.d.cts +211 -0
- package/dist/chat/index.d.ts +211 -0
- package/dist/chat/index.js +303 -17
- package/dist/chat/index.js.map +1 -1
- package/dist/index.cjs +225 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +279 -1
- package/dist/index.d.ts +279 -1
- package/dist/index.js +219 -4
- package/dist/index.js.map +1 -1
- package/dist/kanban/index.cjs +218 -3
- package/dist/kanban/index.cjs.map +1 -1
- package/dist/kanban/index.d.cts +211 -0
- package/dist/kanban/index.d.ts +211 -0
- package/dist/kanban/index.js +218 -3
- package/dist/kanban/index.js.map +1 -1
- package/dist/teams/index.cjs +218 -3
- package/dist/teams/index.cjs.map +1 -1
- package/dist/teams/index.d.cts +211 -0
- package/dist/teams/index.d.ts +211 -0
- package/dist/teams/index.js +218 -3
- package/dist/teams/index.js.map +1 -1
- package/package.json +21 -1
package/dist/chat/index.d.cts
CHANGED
|
@@ -874,6 +874,16 @@ interface ToolResultEvent {
|
|
|
874
874
|
result: unknown;
|
|
875
875
|
/** Duration in milliseconds */
|
|
876
876
|
durationMs: number;
|
|
877
|
+
/**
|
|
878
|
+
* CAD-243: true when the tool call FAILED (the producer stamps
|
|
879
|
+
* `isError: true` + `status: 'failed'` on a thrown tool call). Absent on
|
|
880
|
+
* older producers — consumers then fall back to the result shape.
|
|
881
|
+
*/
|
|
882
|
+
isError?: boolean;
|
|
883
|
+
/** CAD-243: producer verdict, `'failed'` for a failed call. */
|
|
884
|
+
status?: string;
|
|
885
|
+
/** CAD-243: error text for a failed call. */
|
|
886
|
+
error?: string;
|
|
877
887
|
/** See {@link ToolCallEvent.forwardedFrom} */
|
|
878
888
|
forwardedFrom?: string;
|
|
879
889
|
/** See {@link ToolCallEvent.sourceExecutionId} (CAD-87 S1-001). */
|
|
@@ -1863,6 +1873,13 @@ interface RequestOptions {
|
|
|
1863
1873
|
skipRetry?: boolean;
|
|
1864
1874
|
/** Idempotency key */
|
|
1865
1875
|
idempotencyKey?: string;
|
|
1876
|
+
/**
|
|
1877
|
+
* Per-request timeout in milliseconds. Overrides the client-wide
|
|
1878
|
+
* `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
|
|
1879
|
+
* waits for the server's route ceiling while every other call keeps the
|
|
1880
|
+
* 30 s default).
|
|
1881
|
+
*/
|
|
1882
|
+
timeoutMs?: number;
|
|
1866
1883
|
}
|
|
1867
1884
|
/**
|
|
1868
1885
|
* HTTP Client class
|
|
@@ -1872,6 +1889,8 @@ declare class HttpClient {
|
|
|
1872
1889
|
private tokenRefreshAttempts;
|
|
1873
1890
|
private readonly maxTokenRefreshAttempts;
|
|
1874
1891
|
constructor(config: HttpClientConfig);
|
|
1892
|
+
/** The client-wide request timeout (ms) this client was configured with. */
|
|
1893
|
+
get timeoutMs(): number;
|
|
1875
1894
|
/**
|
|
1876
1895
|
* Get authorization header value
|
|
1877
1896
|
*/
|
|
@@ -1894,6 +1913,7 @@ declare class HttpClient {
|
|
|
1894
1913
|
post<T>(path: string, body?: unknown, options?: {
|
|
1895
1914
|
idempotencyKey?: string;
|
|
1896
1915
|
skipRetry?: boolean;
|
|
1916
|
+
timeoutMs?: number;
|
|
1897
1917
|
}): Promise<T>;
|
|
1898
1918
|
/**
|
|
1899
1919
|
* PATCH request
|
|
@@ -2521,6 +2541,133 @@ interface RemoteAgentExecuteResponse {
|
|
|
2521
2541
|
streamUrl: string;
|
|
2522
2542
|
}
|
|
2523
2543
|
|
|
2544
|
+
/**
|
|
2545
|
+
* AI function types (p93 — specs §4 run contract, D27 discovery, §6.5 run reads).
|
|
2546
|
+
*
|
|
2547
|
+
* An AI function is a published prompt in the Cadra Prompts library that makes
|
|
2548
|
+
* ONE direct AI-provider call (never an agent). Callers reference it by its
|
|
2549
|
+
* `functionKey` (unique per org), by prompt uuid, or — for platform features —
|
|
2550
|
+
* by slot key.
|
|
2551
|
+
*/
|
|
2552
|
+
/** Output kind of an AI function. */
|
|
2553
|
+
type AiFunctionOutputKind = 'text' | 'json' | 'image';
|
|
2554
|
+
/** Parameter (prompt variable) types — specs D10 + D26d. */
|
|
2555
|
+
type AiFunctionParameterType = 'string' | 'text' | 'number' | 'boolean' | 'enum' | 'image';
|
|
2556
|
+
/** A value passed for one parameter. `image` parameters take an artifact uuid (string). */
|
|
2557
|
+
type AiFunctionVariableValue = string | number | boolean;
|
|
2558
|
+
/** Parameters (variables) for one run, keyed by parameter name. */
|
|
2559
|
+
type AiFunctionVariables = Record<string, AiFunctionVariableValue>;
|
|
2560
|
+
/** How a run names its function (§4). */
|
|
2561
|
+
type AiFunctionRef = {
|
|
2562
|
+
slot: string;
|
|
2563
|
+
} | {
|
|
2564
|
+
functionKey: string;
|
|
2565
|
+
} | {
|
|
2566
|
+
promptUuid: string;
|
|
2567
|
+
};
|
|
2568
|
+
/** One declared parameter of a function's live (golden) version — D27a. */
|
|
2569
|
+
interface AiFunctionParameter {
|
|
2570
|
+
name: string;
|
|
2571
|
+
type: AiFunctionParameterType;
|
|
2572
|
+
required: boolean;
|
|
2573
|
+
defaultValue?: AiFunctionVariableValue;
|
|
2574
|
+
maxLength?: number;
|
|
2575
|
+
options?: string[];
|
|
2576
|
+
description?: string;
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* The discovery "index" entry for one callable function — D27a. Built from the
|
|
2580
|
+
* golden version snapshot; never carries prompt or system text.
|
|
2581
|
+
*/
|
|
2582
|
+
interface AiFunctionDescriptor {
|
|
2583
|
+
functionKey: string;
|
|
2584
|
+
title: string;
|
|
2585
|
+
description?: string | null;
|
|
2586
|
+
outputKind: AiFunctionOutputKind;
|
|
2587
|
+
/** The live (golden) version number. */
|
|
2588
|
+
liveVersion: number;
|
|
2589
|
+
parameters: AiFunctionParameter[];
|
|
2590
|
+
/** JSON schema of the output, for `json` functions. */
|
|
2591
|
+
outputSchema?: Record<string, unknown> | null;
|
|
2592
|
+
}
|
|
2593
|
+
/** Who paid for a run (D4). */
|
|
2594
|
+
type AiFunctionBilledTo = 'own_key' | 'credits' | 'platform_funded';
|
|
2595
|
+
/** Runtime params a slot may accept per run (D26d3). */
|
|
2596
|
+
interface AiFunctionRuntimeParams {
|
|
2597
|
+
aspect_ratio?: string;
|
|
2598
|
+
image_size?: string;
|
|
2599
|
+
}
|
|
2600
|
+
/** Options for the object form `run(ref, { variables, … })`. */
|
|
2601
|
+
interface AiFunctionRunOptions {
|
|
2602
|
+
/** Parameters for this run (sent as `variables`). */
|
|
2603
|
+
variables: AiFunctionVariables;
|
|
2604
|
+
/** Pin a published version number (D3d). Skips the client-side check. */
|
|
2605
|
+
version?: number;
|
|
2606
|
+
/** Idempotency key (uuid). Generated when omitted (D15). */
|
|
2607
|
+
idempotencyKey?: string;
|
|
2608
|
+
/** Slot runtime params (D26d3). */
|
|
2609
|
+
params?: AiFunctionRuntimeParams;
|
|
2610
|
+
/** `false` skips the client-side parameter check (D27c). Default true. */
|
|
2611
|
+
validate?: boolean;
|
|
2612
|
+
}
|
|
2613
|
+
/** Options for the shorthand `run('function_key', parameters, opts)`. */
|
|
2614
|
+
type AiFunctionRunShorthandOptions = Omit<AiFunctionRunOptions, 'variables'>;
|
|
2615
|
+
/** Image produced by an `image` function. Over HTTP only `url` (presigned, 1 h) is set. */
|
|
2616
|
+
interface AiFunctionImage {
|
|
2617
|
+
mimeType: string;
|
|
2618
|
+
url?: string;
|
|
2619
|
+
bytes?: Uint8Array;
|
|
2620
|
+
}
|
|
2621
|
+
/** Output of a run, by kind (§4). `TOutput` types `json`. */
|
|
2622
|
+
type AiFunctionOutput<TOutput = unknown> = {
|
|
2623
|
+
type: 'text';
|
|
2624
|
+
text: string;
|
|
2625
|
+
} | {
|
|
2626
|
+
type: 'json';
|
|
2627
|
+
json: TOutput;
|
|
2628
|
+
} | {
|
|
2629
|
+
type: 'image';
|
|
2630
|
+
images: AiFunctionImage[];
|
|
2631
|
+
};
|
|
2632
|
+
/** Token and billing usage of a run (§4). */
|
|
2633
|
+
interface AiFunctionUsage {
|
|
2634
|
+
promptTokens: number;
|
|
2635
|
+
completionTokens: number;
|
|
2636
|
+
imageCount: number;
|
|
2637
|
+
billedTo: AiFunctionBilledTo;
|
|
2638
|
+
}
|
|
2639
|
+
/** Result of a successful run (§4). */
|
|
2640
|
+
interface AiFunctionRunResult<TOutput = unknown> {
|
|
2641
|
+
/** = the run's execution uuid (usage-ledger executionUuid). */
|
|
2642
|
+
executionId: string;
|
|
2643
|
+
functionUuid: string;
|
|
2644
|
+
version: number;
|
|
2645
|
+
output: AiFunctionOutput<TOutput>;
|
|
2646
|
+
usage: AiFunctionUsage;
|
|
2647
|
+
latencyMs: number;
|
|
2648
|
+
}
|
|
2649
|
+
/** Run status as reported by run reads (D12; `abandoned` is computed on read). */
|
|
2650
|
+
type AiFunctionRunStatus = 'running' | 'succeeded' | 'failed_provider' | 'failed_timeout' | 'refused_billing' | 'failed_output' | 'failed_delivery' | 'abandoned';
|
|
2651
|
+
/** Safe projection of one of the caller org's own runs (§6.5). */
|
|
2652
|
+
interface AiFunctionRun {
|
|
2653
|
+
executionId: string;
|
|
2654
|
+
ref: {
|
|
2655
|
+
slot?: string;
|
|
2656
|
+
functionKey?: string;
|
|
2657
|
+
promptUuid?: string;
|
|
2658
|
+
};
|
|
2659
|
+
version: number | null;
|
|
2660
|
+
status: AiFunctionRunStatus;
|
|
2661
|
+
errorCode: string | null;
|
|
2662
|
+
promptTokens: number | null;
|
|
2663
|
+
completionTokens: number | null;
|
|
2664
|
+
imageCount: number | null;
|
|
2665
|
+
latencyMs: number | null;
|
|
2666
|
+
billedTo: AiFunctionBilledTo | null;
|
|
2667
|
+
createdAt: string;
|
|
2668
|
+
finishedAt: string | null;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2524
2671
|
/**
|
|
2525
2672
|
* Base Resource API
|
|
2526
2673
|
*
|
|
@@ -2549,6 +2696,7 @@ declare abstract class BaseResourceAPI {
|
|
|
2549
2696
|
protected httpPost<T>(path: string, body?: unknown, options?: {
|
|
2550
2697
|
idempotencyKey?: string;
|
|
2551
2698
|
skipRetry?: boolean;
|
|
2699
|
+
timeoutMs?: number;
|
|
2552
2700
|
}): Promise<T>;
|
|
2553
2701
|
/**
|
|
2554
2702
|
* HTTP PATCH request helper
|
|
@@ -4185,6 +4333,65 @@ declare class RemoteRunnersAPI extends BaseResourceAPI {
|
|
|
4185
4333
|
list(options?: RemoteRunnerListOptions): Promise<PaginatedResponse<RemoteRunner>>;
|
|
4186
4334
|
}
|
|
4187
4335
|
|
|
4336
|
+
/**
|
|
4337
|
+
* AI Functions API (p93 AIF-010 — specs §9, D27).
|
|
4338
|
+
*
|
|
4339
|
+
* @example
|
|
4340
|
+
* ```typescript
|
|
4341
|
+
* // Discover what the org can call, and with which parameters
|
|
4342
|
+
* const functions = await client.aiFunctions.list();
|
|
4343
|
+
* const fn = await client.aiFunctions.get('summarise_ticket');
|
|
4344
|
+
*
|
|
4345
|
+
* // Call it — parameters are checked against the live version before sending
|
|
4346
|
+
* const result = await client.aiFunctions.run('summarise_ticket', { ticket_text: '…' });
|
|
4347
|
+
* if (result.output.type === 'text') console.log(result.output.text);
|
|
4348
|
+
* ```
|
|
4349
|
+
*/
|
|
4350
|
+
|
|
4351
|
+
/**
|
|
4352
|
+
* AI Functions API
|
|
4353
|
+
*/
|
|
4354
|
+
declare class AiFunctionsAPI extends BaseResourceAPI {
|
|
4355
|
+
private readonly descriptorCache;
|
|
4356
|
+
constructor(http: HttpClient);
|
|
4357
|
+
/**
|
|
4358
|
+
* List the functions this org can call — the index (D27a). Each entry carries
|
|
4359
|
+
* the live version's typed parameters; never prompt text.
|
|
4360
|
+
*/
|
|
4361
|
+
list(): Promise<AiFunctionDescriptor[]>;
|
|
4362
|
+
/**
|
|
4363
|
+
* Get one function's descriptor by key (D27a).
|
|
4364
|
+
* `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
|
|
4365
|
+
*/
|
|
4366
|
+
get(functionKey: string): Promise<AiFunctionDescriptor>;
|
|
4367
|
+
/**
|
|
4368
|
+
* Read one of this org's own runs (safe projection, §6.5).
|
|
4369
|
+
*/
|
|
4370
|
+
getRun(executionId: string): Promise<AiFunctionRun>;
|
|
4371
|
+
/** Forget cached descriptors (one key, or all). */
|
|
4372
|
+
clearDescriptorCache(functionKey?: string): void;
|
|
4373
|
+
/**
|
|
4374
|
+
* Run an AI function — one paid provider call.
|
|
4375
|
+
*
|
|
4376
|
+
* - `run('function_key', parameters, opts?)` — shorthand for `{ functionKey }`.
|
|
4377
|
+
* - `run({ functionKey | promptUuid | slot }, { variables, version?, idempotencyKey?, params?, validate? })`.
|
|
4378
|
+
*
|
|
4379
|
+
* For a `functionKey` ref without a pinned `version`, parameters are checked
|
|
4380
|
+
* against the live version first (D27c); a problem throws
|
|
4381
|
+
* `AiFunctionParameterError` and NO run request is sent. Paid runs are never
|
|
4382
|
+
* auto-retried; an idempotency key is generated when omitted.
|
|
4383
|
+
*
|
|
4384
|
+
* @throws AiFunctionParameterError — client-side check failed (nothing sent)
|
|
4385
|
+
* @throws AiFunctionDuplicateError — 409 `DUPLICATE_REQUEST`
|
|
4386
|
+
* @throws AiFunctionChargedError — the run was metered but its output failed (`details.charged`)
|
|
4387
|
+
*/
|
|
4388
|
+
run<TOutput = unknown>(functionKey: string, parameters: AiFunctionVariables, opts?: AiFunctionRunShorthandOptions): Promise<AiFunctionRunResult<TOutput>>;
|
|
4389
|
+
run<TOutput = unknown>(ref: AiFunctionRef, options: AiFunctionRunOptions): Promise<AiFunctionRunResult<TOutput>>;
|
|
4390
|
+
private cacheDescriptor;
|
|
4391
|
+
private getCachedDescriptor;
|
|
4392
|
+
private mapRunError;
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4188
4395
|
/**
|
|
4189
4396
|
* Cadra Client
|
|
4190
4397
|
*
|
|
@@ -4329,6 +4536,10 @@ declare class CadraClient {
|
|
|
4329
4536
|
* Remote runner operations (list)
|
|
4330
4537
|
*/
|
|
4331
4538
|
readonly remoteRunners: RemoteRunnersAPI;
|
|
4539
|
+
/**
|
|
4540
|
+
* AI function operations (list, get, run, getRun) — p93
|
|
4541
|
+
*/
|
|
4542
|
+
readonly aiFunctions: AiFunctionsAPI;
|
|
4332
4543
|
/**
|
|
4333
4544
|
* Create a new AI SaaS client
|
|
4334
4545
|
*
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -874,6 +874,16 @@ interface ToolResultEvent {
|
|
|
874
874
|
result: unknown;
|
|
875
875
|
/** Duration in milliseconds */
|
|
876
876
|
durationMs: number;
|
|
877
|
+
/**
|
|
878
|
+
* CAD-243: true when the tool call FAILED (the producer stamps
|
|
879
|
+
* `isError: true` + `status: 'failed'` on a thrown tool call). Absent on
|
|
880
|
+
* older producers — consumers then fall back to the result shape.
|
|
881
|
+
*/
|
|
882
|
+
isError?: boolean;
|
|
883
|
+
/** CAD-243: producer verdict, `'failed'` for a failed call. */
|
|
884
|
+
status?: string;
|
|
885
|
+
/** CAD-243: error text for a failed call. */
|
|
886
|
+
error?: string;
|
|
877
887
|
/** See {@link ToolCallEvent.forwardedFrom} */
|
|
878
888
|
forwardedFrom?: string;
|
|
879
889
|
/** See {@link ToolCallEvent.sourceExecutionId} (CAD-87 S1-001). */
|
|
@@ -1863,6 +1873,13 @@ interface RequestOptions {
|
|
|
1863
1873
|
skipRetry?: boolean;
|
|
1864
1874
|
/** Idempotency key */
|
|
1865
1875
|
idempotencyKey?: string;
|
|
1876
|
+
/**
|
|
1877
|
+
* Per-request timeout in milliseconds. Overrides the client-wide
|
|
1878
|
+
* `config.timeout` for this call only (p93 AIF-010: a paid AI-function run
|
|
1879
|
+
* waits for the server's route ceiling while every other call keeps the
|
|
1880
|
+
* 30 s default).
|
|
1881
|
+
*/
|
|
1882
|
+
timeoutMs?: number;
|
|
1866
1883
|
}
|
|
1867
1884
|
/**
|
|
1868
1885
|
* HTTP Client class
|
|
@@ -1872,6 +1889,8 @@ declare class HttpClient {
|
|
|
1872
1889
|
private tokenRefreshAttempts;
|
|
1873
1890
|
private readonly maxTokenRefreshAttempts;
|
|
1874
1891
|
constructor(config: HttpClientConfig);
|
|
1892
|
+
/** The client-wide request timeout (ms) this client was configured with. */
|
|
1893
|
+
get timeoutMs(): number;
|
|
1875
1894
|
/**
|
|
1876
1895
|
* Get authorization header value
|
|
1877
1896
|
*/
|
|
@@ -1894,6 +1913,7 @@ declare class HttpClient {
|
|
|
1894
1913
|
post<T>(path: string, body?: unknown, options?: {
|
|
1895
1914
|
idempotencyKey?: string;
|
|
1896
1915
|
skipRetry?: boolean;
|
|
1916
|
+
timeoutMs?: number;
|
|
1897
1917
|
}): Promise<T>;
|
|
1898
1918
|
/**
|
|
1899
1919
|
* PATCH request
|
|
@@ -2521,6 +2541,133 @@ interface RemoteAgentExecuteResponse {
|
|
|
2521
2541
|
streamUrl: string;
|
|
2522
2542
|
}
|
|
2523
2543
|
|
|
2544
|
+
/**
|
|
2545
|
+
* AI function types (p93 — specs §4 run contract, D27 discovery, §6.5 run reads).
|
|
2546
|
+
*
|
|
2547
|
+
* An AI function is a published prompt in the Cadra Prompts library that makes
|
|
2548
|
+
* ONE direct AI-provider call (never an agent). Callers reference it by its
|
|
2549
|
+
* `functionKey` (unique per org), by prompt uuid, or — for platform features —
|
|
2550
|
+
* by slot key.
|
|
2551
|
+
*/
|
|
2552
|
+
/** Output kind of an AI function. */
|
|
2553
|
+
type AiFunctionOutputKind = 'text' | 'json' | 'image';
|
|
2554
|
+
/** Parameter (prompt variable) types — specs D10 + D26d. */
|
|
2555
|
+
type AiFunctionParameterType = 'string' | 'text' | 'number' | 'boolean' | 'enum' | 'image';
|
|
2556
|
+
/** A value passed for one parameter. `image` parameters take an artifact uuid (string). */
|
|
2557
|
+
type AiFunctionVariableValue = string | number | boolean;
|
|
2558
|
+
/** Parameters (variables) for one run, keyed by parameter name. */
|
|
2559
|
+
type AiFunctionVariables = Record<string, AiFunctionVariableValue>;
|
|
2560
|
+
/** How a run names its function (§4). */
|
|
2561
|
+
type AiFunctionRef = {
|
|
2562
|
+
slot: string;
|
|
2563
|
+
} | {
|
|
2564
|
+
functionKey: string;
|
|
2565
|
+
} | {
|
|
2566
|
+
promptUuid: string;
|
|
2567
|
+
};
|
|
2568
|
+
/** One declared parameter of a function's live (golden) version — D27a. */
|
|
2569
|
+
interface AiFunctionParameter {
|
|
2570
|
+
name: string;
|
|
2571
|
+
type: AiFunctionParameterType;
|
|
2572
|
+
required: boolean;
|
|
2573
|
+
defaultValue?: AiFunctionVariableValue;
|
|
2574
|
+
maxLength?: number;
|
|
2575
|
+
options?: string[];
|
|
2576
|
+
description?: string;
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* The discovery "index" entry for one callable function — D27a. Built from the
|
|
2580
|
+
* golden version snapshot; never carries prompt or system text.
|
|
2581
|
+
*/
|
|
2582
|
+
interface AiFunctionDescriptor {
|
|
2583
|
+
functionKey: string;
|
|
2584
|
+
title: string;
|
|
2585
|
+
description?: string | null;
|
|
2586
|
+
outputKind: AiFunctionOutputKind;
|
|
2587
|
+
/** The live (golden) version number. */
|
|
2588
|
+
liveVersion: number;
|
|
2589
|
+
parameters: AiFunctionParameter[];
|
|
2590
|
+
/** JSON schema of the output, for `json` functions. */
|
|
2591
|
+
outputSchema?: Record<string, unknown> | null;
|
|
2592
|
+
}
|
|
2593
|
+
/** Who paid for a run (D4). */
|
|
2594
|
+
type AiFunctionBilledTo = 'own_key' | 'credits' | 'platform_funded';
|
|
2595
|
+
/** Runtime params a slot may accept per run (D26d3). */
|
|
2596
|
+
interface AiFunctionRuntimeParams {
|
|
2597
|
+
aspect_ratio?: string;
|
|
2598
|
+
image_size?: string;
|
|
2599
|
+
}
|
|
2600
|
+
/** Options for the object form `run(ref, { variables, … })`. */
|
|
2601
|
+
interface AiFunctionRunOptions {
|
|
2602
|
+
/** Parameters for this run (sent as `variables`). */
|
|
2603
|
+
variables: AiFunctionVariables;
|
|
2604
|
+
/** Pin a published version number (D3d). Skips the client-side check. */
|
|
2605
|
+
version?: number;
|
|
2606
|
+
/** Idempotency key (uuid). Generated when omitted (D15). */
|
|
2607
|
+
idempotencyKey?: string;
|
|
2608
|
+
/** Slot runtime params (D26d3). */
|
|
2609
|
+
params?: AiFunctionRuntimeParams;
|
|
2610
|
+
/** `false` skips the client-side parameter check (D27c). Default true. */
|
|
2611
|
+
validate?: boolean;
|
|
2612
|
+
}
|
|
2613
|
+
/** Options for the shorthand `run('function_key', parameters, opts)`. */
|
|
2614
|
+
type AiFunctionRunShorthandOptions = Omit<AiFunctionRunOptions, 'variables'>;
|
|
2615
|
+
/** Image produced by an `image` function. Over HTTP only `url` (presigned, 1 h) is set. */
|
|
2616
|
+
interface AiFunctionImage {
|
|
2617
|
+
mimeType: string;
|
|
2618
|
+
url?: string;
|
|
2619
|
+
bytes?: Uint8Array;
|
|
2620
|
+
}
|
|
2621
|
+
/** Output of a run, by kind (§4). `TOutput` types `json`. */
|
|
2622
|
+
type AiFunctionOutput<TOutput = unknown> = {
|
|
2623
|
+
type: 'text';
|
|
2624
|
+
text: string;
|
|
2625
|
+
} | {
|
|
2626
|
+
type: 'json';
|
|
2627
|
+
json: TOutput;
|
|
2628
|
+
} | {
|
|
2629
|
+
type: 'image';
|
|
2630
|
+
images: AiFunctionImage[];
|
|
2631
|
+
};
|
|
2632
|
+
/** Token and billing usage of a run (§4). */
|
|
2633
|
+
interface AiFunctionUsage {
|
|
2634
|
+
promptTokens: number;
|
|
2635
|
+
completionTokens: number;
|
|
2636
|
+
imageCount: number;
|
|
2637
|
+
billedTo: AiFunctionBilledTo;
|
|
2638
|
+
}
|
|
2639
|
+
/** Result of a successful run (§4). */
|
|
2640
|
+
interface AiFunctionRunResult<TOutput = unknown> {
|
|
2641
|
+
/** = the run's execution uuid (usage-ledger executionUuid). */
|
|
2642
|
+
executionId: string;
|
|
2643
|
+
functionUuid: string;
|
|
2644
|
+
version: number;
|
|
2645
|
+
output: AiFunctionOutput<TOutput>;
|
|
2646
|
+
usage: AiFunctionUsage;
|
|
2647
|
+
latencyMs: number;
|
|
2648
|
+
}
|
|
2649
|
+
/** Run status as reported by run reads (D12; `abandoned` is computed on read). */
|
|
2650
|
+
type AiFunctionRunStatus = 'running' | 'succeeded' | 'failed_provider' | 'failed_timeout' | 'refused_billing' | 'failed_output' | 'failed_delivery' | 'abandoned';
|
|
2651
|
+
/** Safe projection of one of the caller org's own runs (§6.5). */
|
|
2652
|
+
interface AiFunctionRun {
|
|
2653
|
+
executionId: string;
|
|
2654
|
+
ref: {
|
|
2655
|
+
slot?: string;
|
|
2656
|
+
functionKey?: string;
|
|
2657
|
+
promptUuid?: string;
|
|
2658
|
+
};
|
|
2659
|
+
version: number | null;
|
|
2660
|
+
status: AiFunctionRunStatus;
|
|
2661
|
+
errorCode: string | null;
|
|
2662
|
+
promptTokens: number | null;
|
|
2663
|
+
completionTokens: number | null;
|
|
2664
|
+
imageCount: number | null;
|
|
2665
|
+
latencyMs: number | null;
|
|
2666
|
+
billedTo: AiFunctionBilledTo | null;
|
|
2667
|
+
createdAt: string;
|
|
2668
|
+
finishedAt: string | null;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2524
2671
|
/**
|
|
2525
2672
|
* Base Resource API
|
|
2526
2673
|
*
|
|
@@ -2549,6 +2696,7 @@ declare abstract class BaseResourceAPI {
|
|
|
2549
2696
|
protected httpPost<T>(path: string, body?: unknown, options?: {
|
|
2550
2697
|
idempotencyKey?: string;
|
|
2551
2698
|
skipRetry?: boolean;
|
|
2699
|
+
timeoutMs?: number;
|
|
2552
2700
|
}): Promise<T>;
|
|
2553
2701
|
/**
|
|
2554
2702
|
* HTTP PATCH request helper
|
|
@@ -4185,6 +4333,65 @@ declare class RemoteRunnersAPI extends BaseResourceAPI {
|
|
|
4185
4333
|
list(options?: RemoteRunnerListOptions): Promise<PaginatedResponse<RemoteRunner>>;
|
|
4186
4334
|
}
|
|
4187
4335
|
|
|
4336
|
+
/**
|
|
4337
|
+
* AI Functions API (p93 AIF-010 — specs §9, D27).
|
|
4338
|
+
*
|
|
4339
|
+
* @example
|
|
4340
|
+
* ```typescript
|
|
4341
|
+
* // Discover what the org can call, and with which parameters
|
|
4342
|
+
* const functions = await client.aiFunctions.list();
|
|
4343
|
+
* const fn = await client.aiFunctions.get('summarise_ticket');
|
|
4344
|
+
*
|
|
4345
|
+
* // Call it — parameters are checked against the live version before sending
|
|
4346
|
+
* const result = await client.aiFunctions.run('summarise_ticket', { ticket_text: '…' });
|
|
4347
|
+
* if (result.output.type === 'text') console.log(result.output.text);
|
|
4348
|
+
* ```
|
|
4349
|
+
*/
|
|
4350
|
+
|
|
4351
|
+
/**
|
|
4352
|
+
* AI Functions API
|
|
4353
|
+
*/
|
|
4354
|
+
declare class AiFunctionsAPI extends BaseResourceAPI {
|
|
4355
|
+
private readonly descriptorCache;
|
|
4356
|
+
constructor(http: HttpClient);
|
|
4357
|
+
/**
|
|
4358
|
+
* List the functions this org can call — the index (D27a). Each entry carries
|
|
4359
|
+
* the live version's typed parameters; never prompt text.
|
|
4360
|
+
*/
|
|
4361
|
+
list(): Promise<AiFunctionDescriptor[]>;
|
|
4362
|
+
/**
|
|
4363
|
+
* Get one function's descriptor by key (D27a).
|
|
4364
|
+
* `NotFoundError` (`FUNCTION_NOT_FOUND`) / `ConflictError` (`FUNCTION_NOT_PUBLISHED`).
|
|
4365
|
+
*/
|
|
4366
|
+
get(functionKey: string): Promise<AiFunctionDescriptor>;
|
|
4367
|
+
/**
|
|
4368
|
+
* Read one of this org's own runs (safe projection, §6.5).
|
|
4369
|
+
*/
|
|
4370
|
+
getRun(executionId: string): Promise<AiFunctionRun>;
|
|
4371
|
+
/** Forget cached descriptors (one key, or all). */
|
|
4372
|
+
clearDescriptorCache(functionKey?: string): void;
|
|
4373
|
+
/**
|
|
4374
|
+
* Run an AI function — one paid provider call.
|
|
4375
|
+
*
|
|
4376
|
+
* - `run('function_key', parameters, opts?)` — shorthand for `{ functionKey }`.
|
|
4377
|
+
* - `run({ functionKey | promptUuid | slot }, { variables, version?, idempotencyKey?, params?, validate? })`.
|
|
4378
|
+
*
|
|
4379
|
+
* For a `functionKey` ref without a pinned `version`, parameters are checked
|
|
4380
|
+
* against the live version first (D27c); a problem throws
|
|
4381
|
+
* `AiFunctionParameterError` and NO run request is sent. Paid runs are never
|
|
4382
|
+
* auto-retried; an idempotency key is generated when omitted.
|
|
4383
|
+
*
|
|
4384
|
+
* @throws AiFunctionParameterError — client-side check failed (nothing sent)
|
|
4385
|
+
* @throws AiFunctionDuplicateError — 409 `DUPLICATE_REQUEST`
|
|
4386
|
+
* @throws AiFunctionChargedError — the run was metered but its output failed (`details.charged`)
|
|
4387
|
+
*/
|
|
4388
|
+
run<TOutput = unknown>(functionKey: string, parameters: AiFunctionVariables, opts?: AiFunctionRunShorthandOptions): Promise<AiFunctionRunResult<TOutput>>;
|
|
4389
|
+
run<TOutput = unknown>(ref: AiFunctionRef, options: AiFunctionRunOptions): Promise<AiFunctionRunResult<TOutput>>;
|
|
4390
|
+
private cacheDescriptor;
|
|
4391
|
+
private getCachedDescriptor;
|
|
4392
|
+
private mapRunError;
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4188
4395
|
/**
|
|
4189
4396
|
* Cadra Client
|
|
4190
4397
|
*
|
|
@@ -4329,6 +4536,10 @@ declare class CadraClient {
|
|
|
4329
4536
|
* Remote runner operations (list)
|
|
4330
4537
|
*/
|
|
4331
4538
|
readonly remoteRunners: RemoteRunnersAPI;
|
|
4539
|
+
/**
|
|
4540
|
+
* AI function operations (list, get, run, getRun) — p93
|
|
4541
|
+
*/
|
|
4542
|
+
readonly aiFunctions: AiFunctionsAPI;
|
|
4332
4543
|
/**
|
|
4333
4544
|
* Create a new AI SaaS client
|
|
4334
4545
|
*
|