@kissflow/lowcode-client-sdk 1.0.49 → 1.0.51

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/dist/lowcode.d.ts CHANGED
@@ -60,6 +60,15 @@ declare module "core/constants" {
60
60
  WINDOW_NDEF_READER_ADD_EVENT_LISTENER: string;
61
61
  WINDOW_NDEF_READER_MAKE_READONLY: string;
62
62
  WINDOW_NDEF_READER_ABORT_SCAN: string;
63
+ CUSTOM_AGENT_GET_CONTRACT: string;
64
+ CUSTOM_AGENT_EXECUTE: string;
65
+ CUSTOM_AGENT_GET_EXECUTION: string;
66
+ CUSTOM_AGENT_WATCH_EXECUTION: string;
67
+ CUSTOM_AGENT_STOP_WATCH: string;
68
+ CUSTOM_FUNCTION_RUN: string;
69
+ CUSTOM_FUNCTION_GET_RUN: string;
70
+ CUSTOM_FUNCTION_ON_RUN_COMPLETE: string;
71
+ CUSTOM_FUNCTION_STOP_WATCH: string;
63
72
  DECISION_TABLE_EXECUTE: string;
64
73
  DATAFORM_IMPORT_CSV: string;
65
74
  DATAFORM_OPEN_FORM: string;
@@ -117,6 +126,8 @@ declare module "core/constants" {
117
126
  COMPONENT_ON_MOUNT: string;
118
127
  CC_ON_PARAMS_CHANGE: string;
119
128
  CC_ON_ROUTE_CHANGE: string;
129
+ CUSTOM_AGENT_EXECUTION_COMPLETE: string;
130
+ CUSTOM_FUNCTION_RUN_COMPLETE: string;
120
131
  };
121
132
  export const DEFAULTS: {
122
133
  POPUP_ID: string;
@@ -135,6 +146,21 @@ declare module "core/index" {
135
146
  }
136
147
  export class BaseSDK extends EventBase {
137
148
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
149
+ /**
150
+ * Like _postMessageAsync, but settles with `timeoutError` when the host does not reply within
151
+ * `timeoutMs` (a host that does not know the command fails loudly instead of hanging), with
152
+ * `sendError` when the message cannot be posted, and can be cancelled. Every path releases the
153
+ * timer and the reply registration; a reply that arrives afterwards finds no entry and is ignored.
154
+ * `cancel()` leaves the promise unsettled: the caller that cancels has stopped waiting for it.
155
+ */
156
+ _postMessageBounded(command: string, args: object, options: {
157
+ timeoutMs: number;
158
+ timeoutError: object;
159
+ sendError: object;
160
+ }): {
161
+ promise: Promise<any>;
162
+ cancel: () => void;
163
+ };
138
164
  _postMessage(command: string, args: any, callBack?: any): void;
139
165
  _postMessageSync(command: string, args: any): any;
140
166
  }
@@ -438,6 +464,134 @@ declare module "types/external" {
438
464
  tableId?: string;
439
465
  tableRowId?: string;
440
466
  };
467
+ /** The terminal states a Custom Function run ends in, plus the two it passes through. */
468
+ export type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
469
+ /**
470
+ * What a Custom Function run looks like from the SDK.
471
+ *
472
+ * An Interactive function resolves with the terminal envelope directly. A
473
+ * Background function resolves with `Queued` and only `RunId`; fetch the rest
474
+ * with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
475
+ */
476
+ export type RunEnvelope = {
477
+ RunId: string;
478
+ Status: RunStatus;
479
+ /** Whatever the function returned. Only constrained when its output contract names properties. */
480
+ Result?: unknown;
481
+ Error?: {
482
+ Code?: string;
483
+ Message: string;
484
+ };
485
+ };
486
+ /**
487
+ * How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
488
+ * code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
489
+ * `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
490
+ * `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
491
+ * and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
492
+ */
493
+ export type RunWatchError = {
494
+ isError: true;
495
+ error?: string;
496
+ errorCode?: string;
497
+ };
498
+ export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
499
+ export type AgentOutputDataType = "string" | "number" | "boolean";
500
+ export type AgentInputField = {
501
+ Key: string;
502
+ Name: string;
503
+ DataType: AgentInputDataType;
504
+ Required: boolean;
505
+ Description?: string;
506
+ };
507
+ export type AgentOutputField = {
508
+ Key: string;
509
+ Name: string;
510
+ DataType: AgentOutputDataType;
511
+ Description?: string;
512
+ };
513
+ /**
514
+ * A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
515
+ * A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
516
+ * `{ Key: file.key, FileName: file.name, Size: file.size }`.
517
+ */
518
+ export type AgentAttachmentValue = {
519
+ Key: string;
520
+ Url?: never;
521
+ FileName: string;
522
+ Size?: number;
523
+ ContentType?: string;
524
+ } | {
525
+ Url: string;
526
+ Key?: never;
527
+ FileName: string;
528
+ Size?: number;
529
+ ContentType?: string;
530
+ };
531
+ export type AgentInputValue = string | number | boolean | AgentAttachmentValue;
532
+ /** The Agent's published invocation contract. */
533
+ export type AgentContract = {
534
+ AgentId: string;
535
+ Definition: {
536
+ Name: string;
537
+ Description?: string;
538
+ Icon?: Record<string, unknown>;
539
+ Inputs: AgentInputField[];
540
+ Outputs: AgentOutputField[];
541
+ MaxOutputItems: number;
542
+ };
543
+ Readiness: {
544
+ Ready: boolean;
545
+ Issues: Array<{
546
+ Code: string;
547
+ Path: string;
548
+ Message: string;
549
+ }>;
550
+ };
551
+ };
552
+ export type AgentExecuteOptions = {
553
+ /** Values keyed by input `Key`, as declared in the contract. */
554
+ inputData: Record<string, AgentInputValue>;
555
+ };
556
+ /** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
557
+ export type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
558
+ /** What `execute` resolves with once the run is accepted, before it has finished. */
559
+ export type AgentExecutionAccepted = {
560
+ ExecutionId: string;
561
+ Status: AgentExecutionStatus;
562
+ };
563
+ export type AgentExecution = {
564
+ ExecutionId: string;
565
+ Status: AgentExecutionStatus;
566
+ Stage?: string;
567
+ /** Present on `Completed`: one row per item, keyed by output `Key`. */
568
+ Output?: {
569
+ items: Array<Record<string, string | number | boolean>>;
570
+ };
571
+ /** Present on `Failed`. */
572
+ Error?: {
573
+ Code: string;
574
+ Retryable: boolean;
575
+ Details?: unknown;
576
+ };
577
+ Warnings?: Array<Record<string, unknown>>;
578
+ CreatedAt?: string;
579
+ StartedAt?: string;
580
+ CompletedAt?: string;
581
+ };
582
+ /**
583
+ * How an Agent call fails: `error` is the message text and `errorCode` either the platform code
584
+ * (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
585
+ * `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
586
+ * `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
587
+ * `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
588
+ * There is no `message`: read `error` for the text.
589
+ */
590
+ export type AgentError = {
591
+ isError: true;
592
+ error?: string;
593
+ errorCode?: string;
594
+ };
441
595
  }
442
596
  declare module "types/internal" {
443
597
  import { userObject, accountObject, environmentObject } from "types/external";
@@ -806,6 +960,67 @@ declare module "app/decisiontable" {
806
960
  evaluate(payload?: object): any;
807
961
  }
808
962
  }
963
+ declare module "app/agent" {
964
+ import { BaseSDK } from "core/index";
965
+ import { AgentContract, AgentError, AgentExecuteOptions, AgentExecution, AgentExecutionAccepted } from "types/external";
966
+ /**
967
+ * A published Custom Agent of the current app.
968
+ *
969
+ * Get one with `kf.app.getAgent(agentId)`. Calls run as the signed-in user, against the Agent's
970
+ * published (Live) definition.
971
+ */
972
+ export class Agent extends BaseSDK {
973
+ private agentId;
974
+ private _id;
975
+ private activeWatches;
976
+ constructor(agentId: string);
977
+ /**
978
+ * Read the Agent's published contract: its inputs, outputs and readiness.
979
+ *
980
+ * @example
981
+ * const { Definition } = await kf.app.getAgent("AgXXXXXXXXXX").getContract();
982
+ */
983
+ getContract(): Promise<AgentContract>;
984
+ /**
985
+ * Start a run. Resolves once the run is accepted (`ExecutionId`, `Status`), not when it finishes;
986
+ * use {@link onExecutionComplete} or {@link getExecution} for the result.
987
+ *
988
+ * Never retried: if the call fails with `AGENT_EXECUTE_OUTCOME_UNKNOWN`, a run may still have
989
+ * started, and app code cannot list runs to find it: tell the user the request may still be in
990
+ * progress instead of starting another. `AGENT_EXECUTE_NOT_SENT` means it was not sent (for
991
+ * example, the user is offline).
992
+ *
993
+ * @example
994
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks", amount: 54000 } });
995
+ */
996
+ execute(options: AgentExecuteOptions): Promise<AgentExecutionAccepted>;
997
+ /**
998
+ * Read a run's current state, with its `Output` once `Completed` or its `Error` once `Failed`.
999
+ * Callers who are not the App's authors can read only their own runs.
1000
+ */
1001
+ getExecution(executionId: string): Promise<AgentExecution>;
1002
+ /**
1003
+ * Be told once when a run finishes. `onComplete` gets the run on `Completed` or `Failed` (read
1004
+ * `Status`: a failed run is a result, not an error). `onWatchError` gets what stopped the
1005
+ * observation instead: an unsupported host, an access or network failure, or the observation limit
1006
+ * (`AGENT_OBSERVATION_STOPPED`, after about six minutes; the run may still finish, so read it later
1007
+ * with {@link getExecution}). At most one of the two is called, at most once.
1008
+ *
1009
+ * Neither is called if the script that registered them stops first: form, field, gallery and
1010
+ * table scripts stop after one minute, and they and page event scripts stop when the next script
1011
+ * starts on the same form, component or page. In those scripts, keep the `ExecutionId` and read
1012
+ * it later with {@link getExecution}.
1013
+ *
1014
+ * Returns a function that stops observing. It never cancels the run.
1015
+ *
1016
+ * @example
1017
+ * const stop = agent.onExecutionComplete(ExecutionId, (run) => show(run), (err) => warn(err));
1018
+ * // later, e.g. on unmount
1019
+ * stop();
1020
+ */
1021
+ onExecutionComplete(executionId: string, onComplete: (execution: AgentExecution) => void, onWatchError?: (error: AgentError) => void): () => void;
1022
+ }
1023
+ }
809
1024
  declare module "dataform/index" {
810
1025
  import { BaseSDK } from "core/index";
811
1026
  import { Form } from "form/index";
@@ -1275,19 +1490,83 @@ declare module "app/index" {
1275
1490
  import { BaseSDK } from "core/index";
1276
1491
  import { Page } from "app/page";
1277
1492
  import { AppContext } from "types/internal";
1278
- import { rolesObject } from "types/external";
1493
+ import { rolesObject, RunEnvelope, RunWatchError } from "types/external";
1279
1494
  import { DecisionTable } from "app/decisiontable";
1495
+ import { Agent } from "app/agent";
1280
1496
  import { Dataform } from "dataform/index";
1281
1497
  import { Board } from "board/index";
1282
1498
  import { Process } from "process/index";
1283
1499
  export class Application extends BaseSDK {
1284
1500
  page: Page;
1285
1501
  _id: string;
1502
+ private activeWatches;
1286
1503
  constructor(props: AppContext, isCustomComponent?: boolean);
1287
1504
  getVariable(key: string): any;
1288
1505
  setVariable(key: string | object, value?: any): any;
1289
1506
  openPage(pageId: string, pageParams?: object): any;
1507
+ /**
1508
+ * Run a published Custom Function by name.
1509
+ *
1510
+ * An Interactive function resolves with its terminal envelope. A Background
1511
+ * function resolves as soon as it is queued, with `Status: "Queued"` and a
1512
+ * `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
1513
+ *
1514
+ * A refused run rejects with the platform's SDK error shape: the message
1515
+ * text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
1516
+ * A host that does not answer within 45 s rejects with
1517
+ * `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
1518
+ * the user instead of starting another.
1519
+ *
1520
+ * Custom Functions are application-scoped: this is reachable from page,
1521
+ * component and flow event scripts that run inside an application, where
1522
+ * `kf.app` exists. There is no `kf.app` outside one.
1523
+ *
1524
+ * @example
1525
+ * const run = await kf.app.runFunction("review_expense_claim", { claimId });
1526
+ */
1527
+ runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
1528
+ /**
1529
+ * Fetch a run's current state, including its `Result` once it has one.
1530
+ *
1531
+ * @example
1532
+ * const run = await kf.app.getFunctionRun(runId);
1533
+ * if (run.Status === "Success") use(run.Result);
1534
+ */
1535
+ getFunctionRun(runId: string): Promise<RunEnvelope>;
1536
+ /**
1537
+ * Be told when a Background run reaches a terminal state.
1538
+ *
1539
+ * Fires `callBack` once with the run's envelope. "Complete" means the run
1540
+ * stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
1541
+ * it does on `Success`, so read `Status` before trusting `Result`. If the
1542
+ * host cannot watch the run at all, `onError` is called instead of
1543
+ * `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
1544
+ * refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
1545
+ * ten minutes; the run may still finish, so read it later with
1546
+ * {@link getFunctionRun}). At most one of the two is called, at most once.
1547
+ *
1548
+ * Returns a function that unsubscribes. The callback lives only as long as
1549
+ * the script that registered it: form events end their script after 60 s
1550
+ * and a page event ends the previous one when it fires again, while a
1551
+ * Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
1552
+ * script that outlives the run, or re-attach after the script restarts.
1553
+ *
1554
+ * @example
1555
+ * const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
1556
+ * // later, e.g. on unmount — the host stops watching the run too
1557
+ * stop();
1558
+ */
1559
+ onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
1290
1560
  getDecisionTable(flowId: string): DecisionTable;
1561
+ /**
1562
+ * Get a published Custom Agent of this app by its id. The handle sends no request until you call one
1563
+ * of its methods; see {@link Agent}.
1564
+ *
1565
+ * @example
1566
+ * const agent = kf.app.getAgent("AgXXXXXXXXXX");
1567
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
1568
+ */
1569
+ getAgent(agentId: string): Agent;
1291
1570
  getDataform(flowId: string): Dataform;
1292
1571
  getBoard(flowId: string): Board;
1293
1572
  getProcess(flowId: string): Process;
@@ -1330,6 +1609,7 @@ declare module "app/index" {
1330
1609
  }): Promise<rolesObject>;
1331
1610
  }
1332
1611
  export * from "app/component";
1612
+ export { Agent };
1333
1613
  export { Page };
1334
1614
  export * from "app/popup";
1335
1615
  }
@@ -255,6 +255,53 @@ declare class Page {
255
255
  declare class DecisionTable {
256
256
  evaluate(payload?: object): any;
257
257
  }
258
+ declare class Agent {
259
+ /**
260
+ * Read the Agent's published contract: its inputs, outputs and readiness.
261
+ *
262
+ * @example
263
+ * const { Definition } = await kf.app.getAgent("AgXXXXXXXXXX").getContract();
264
+ */
265
+ getContract(): Promise<AgentContract>;
266
+ /**
267
+ * Start a run. Resolves once the run is accepted (`ExecutionId`, `Status`), not when it finishes;
268
+ * use {@link onExecutionComplete} or {@link getExecution} for the result.
269
+ *
270
+ * Never retried: if the call fails with `AGENT_EXECUTE_OUTCOME_UNKNOWN`, a run may still have
271
+ * started, and app code cannot list runs to find it: tell the user the request may still be in
272
+ * progress instead of starting another. `AGENT_EXECUTE_NOT_SENT` means it was not sent (for
273
+ * example, the user is offline).
274
+ *
275
+ * @example
276
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks", amount: 54000 } });
277
+ */
278
+ execute(options: AgentExecuteOptions): Promise<AgentExecutionAccepted>;
279
+ /**
280
+ * Read a run's current state, with its `Output` once `Completed` or its `Error` once `Failed`.
281
+ * Callers who are not the App's authors can read only their own runs.
282
+ */
283
+ getExecution(executionId: string): Promise<AgentExecution>;
284
+ /**
285
+ * Be told once when a run finishes. `onComplete` gets the run on `Completed` or `Failed` (read
286
+ * `Status`: a failed run is a result, not an error). `onWatchError` gets what stopped the
287
+ * observation instead: an unsupported host, an access or network failure, or the observation limit
288
+ * (`AGENT_OBSERVATION_STOPPED`, after about six minutes; the run may still finish, so read it later
289
+ * with {@link getExecution}). At most one of the two is called, at most once.
290
+ *
291
+ * Neither is called if the script that registered them stops first: form, field, gallery and
292
+ * table scripts stop after one minute, and they and page event scripts stop when the next script
293
+ * starts on the same form, component or page. In those scripts, keep the `ExecutionId` and read
294
+ * it later with {@link getExecution}.
295
+ *
296
+ * Returns a function that stops observing. It never cancels the run.
297
+ *
298
+ * @example
299
+ * const stop = agent.onExecutionComplete(ExecutionId, (run) => show(run), (err) => warn(err));
300
+ * // later, e.g. on unmount
301
+ * stop();
302
+ */
303
+ onExecutionComplete(executionId: string, onComplete: (execution: AgentExecution) => void, onWatchError?: (error: AgentError) => void): () => void;
304
+ }
258
305
  declare class Dataform {
259
306
  /**
260
307
  * Get all items from this dataform with optional filtering, sorting, and pagination
@@ -705,7 +752,69 @@ declare class Application {
705
752
  getVariable(key: string): any;
706
753
  setVariable(key: string | object, value?: any): any;
707
754
  openPage(pageId: string, pageParams?: object): any;
755
+ /**
756
+ * Run a published Custom Function by name.
757
+ *
758
+ * An Interactive function resolves with its terminal envelope. A Background
759
+ * function resolves as soon as it is queued, with `Status: "Queued"` and a
760
+ * `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
761
+ *
762
+ * A refused run rejects with the platform's SDK error shape: the message
763
+ * text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
764
+ * A host that does not answer within 45 s rejects with
765
+ * `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
766
+ * the user instead of starting another.
767
+ *
768
+ * Custom Functions are application-scoped: this is reachable from page,
769
+ * component and flow event scripts that run inside an application, where
770
+ * `kf.app` exists. There is no `kf.app` outside one.
771
+ *
772
+ * @example
773
+ * const run = await kf.app.runFunction("review_expense_claim", { claimId });
774
+ */
775
+ runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
776
+ /**
777
+ * Fetch a run's current state, including its `Result` once it has one.
778
+ *
779
+ * @example
780
+ * const run = await kf.app.getFunctionRun(runId);
781
+ * if (run.Status === "Success") use(run.Result);
782
+ */
783
+ getFunctionRun(runId: string): Promise<RunEnvelope>;
784
+ /**
785
+ * Be told when a Background run reaches a terminal state.
786
+ *
787
+ * Fires `callBack` once with the run's envelope. "Complete" means the run
788
+ * stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
789
+ * it does on `Success`, so read `Status` before trusting `Result`. If the
790
+ * host cannot watch the run at all, `onError` is called instead of
791
+ * `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
792
+ * refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
793
+ * ten minutes; the run may still finish, so read it later with
794
+ * {@link getFunctionRun}). At most one of the two is called, at most once.
795
+ *
796
+ * Returns a function that unsubscribes. The callback lives only as long as
797
+ * the script that registered it: form events end their script after 60 s
798
+ * and a page event ends the previous one when it fires again, while a
799
+ * Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
800
+ * script that outlives the run, or re-attach after the script restarts.
801
+ *
802
+ * @example
803
+ * const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
804
+ * // later, e.g. on unmount — the host stops watching the run too
805
+ * stop();
806
+ */
807
+ onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
708
808
  getDecisionTable(flowId: string): DecisionTable;
809
+ /**
810
+ * Get a published Custom Agent of this app by its id. The handle sends no request until you call one
811
+ * of its methods; see {@link Agent}.
812
+ *
813
+ * @example
814
+ * const agent = kf.app.getAgent("AgXXXXXXXXXX");
815
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
816
+ */
817
+ getAgent(agentId: string): Agent;
709
818
  getDataform(flowId: string): Dataform;
710
819
  getBoard(flowId: string): Board;
711
820
  getProcess(flowId: string): Process;
@@ -1094,3 +1203,123 @@ declare type BoardFieldOptions = {
1094
1203
  tableId?: string;
1095
1204
  tableRowId?: string;
1096
1205
  };
1206
+
1207
+ /** The terminal states a Custom Function run ends in, plus the two it passes through. */
1208
+ declare type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
1209
+
1210
+ /**
1211
+ * What a Custom Function run looks like from the SDK.
1212
+ *
1213
+ * An Interactive function resolves with the terminal envelope directly. A
1214
+ * Background function resolves with `Queued` and only `RunId`; fetch the rest
1215
+ * with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
1216
+ */
1217
+ declare type RunEnvelope = {
1218
+ RunId: string;
1219
+ Status: RunStatus;
1220
+ /** Whatever the function returned. Only constrained when its output contract names properties. */
1221
+ Result?: unknown;
1222
+ Error?: { Code?: string; Message: string };
1223
+ };
1224
+
1225
+ /**
1226
+ * How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
1227
+ * code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
1228
+ * `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
1229
+ * `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
1230
+ * and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
1231
+ */
1232
+ declare type RunWatchError = { isError: true; error?: string; errorCode?: string };
1233
+
1234
+ // ============================================
1235
+ // Custom Agent Types
1236
+ // ============================================
1237
+
1238
+ declare type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
1239
+
1240
+ declare type AgentOutputDataType = "string" | "number" | "boolean";
1241
+
1242
+ declare type AgentInputField = {
1243
+ Key: string;
1244
+ Name: string;
1245
+ DataType: AgentInputDataType;
1246
+ Required: boolean;
1247
+ Description?: string;
1248
+ };
1249
+
1250
+ declare type AgentOutputField = {
1251
+ Key: string;
1252
+ Name: string;
1253
+ DataType: AgentOutputDataType;
1254
+ Description?: string;
1255
+ };
1256
+
1257
+ /**
1258
+ * A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
1259
+ * A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
1260
+ * `{ Key: file.key, FileName: file.name, Size: file.size }`.
1261
+ */
1262
+ declare type AgentAttachmentValue =
1263
+ | { Key: string; Url?: never; FileName: string; Size?: number; ContentType?: string }
1264
+ | { Url: string; Key?: never; FileName: string; Size?: number; ContentType?: string };
1265
+
1266
+ declare type AgentInputValue = string | number | boolean | AgentAttachmentValue;
1267
+
1268
+ /** The Agent's published invocation contract. */
1269
+ declare type AgentContract = {
1270
+ AgentId: string;
1271
+ Definition: {
1272
+ Name: string;
1273
+ Description?: string;
1274
+ Icon?: Record<string, unknown>;
1275
+ Inputs: AgentInputField[];
1276
+ Outputs: AgentOutputField[];
1277
+ MaxOutputItems: number;
1278
+ };
1279
+ Readiness: {
1280
+ Ready: boolean;
1281
+ Issues: Array<{ Code: string; Path: string; Message: string }>;
1282
+ };
1283
+ };
1284
+
1285
+ declare type AgentExecuteOptions = {
1286
+ /** Values keyed by input `Key`, as declared in the contract. */
1287
+ inputData: Record<string, AgentInputValue>;
1288
+ };
1289
+
1290
+ /** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
1291
+ declare type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
1292
+
1293
+ /** What `execute` resolves with once the run is accepted, before it has finished. */
1294
+ declare type AgentExecutionAccepted = {
1295
+ ExecutionId: string;
1296
+ Status: AgentExecutionStatus;
1297
+ };
1298
+
1299
+ declare type AgentExecution = {
1300
+ ExecutionId: string;
1301
+ Status: AgentExecutionStatus;
1302
+ Stage?: string;
1303
+ /** Present on `Completed`: one row per item, keyed by output `Key`. */
1304
+ Output?: { items: Array<Record<string, string | number | boolean>> };
1305
+ /** Present on `Failed`. */
1306
+ Error?: { Code: string; Retryable: boolean; Details?: unknown };
1307
+ Warnings?: Array<Record<string, unknown>>;
1308
+ CreatedAt?: string;
1309
+ StartedAt?: string;
1310
+ CompletedAt?: string;
1311
+ };
1312
+
1313
+ /**
1314
+ * How an Agent call fails: `error` is the message text and `errorCode` either the platform code
1315
+ * (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
1316
+ * `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
1317
+ * `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
1318
+ * `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
1319
+ * There is no `message`: read `error` for the text.
1320
+ */
1321
+ declare type AgentError = {
1322
+ isError: true;
1323
+ error?: string;
1324
+ errorCode?: string;
1325
+ };