@kissflow/lowcode-client-sdk 1.0.49 → 1.0.50

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,11 @@ 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;
63
68
  DECISION_TABLE_EXECUTE: string;
64
69
  DATAFORM_IMPORT_CSV: string;
65
70
  DATAFORM_OPEN_FORM: string;
@@ -117,6 +122,7 @@ declare module "core/constants" {
117
122
  COMPONENT_ON_MOUNT: string;
118
123
  CC_ON_PARAMS_CHANGE: string;
119
124
  CC_ON_ROUTE_CHANGE: string;
125
+ CUSTOM_AGENT_EXECUTION_COMPLETE: string;
120
126
  };
121
127
  export const DEFAULTS: {
122
128
  POPUP_ID: string;
@@ -135,6 +141,21 @@ declare module "core/index" {
135
141
  }
136
142
  export class BaseSDK extends EventBase {
137
143
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
144
+ /**
145
+ * Like _postMessageAsync, but settles with `timeoutError` when the host does not reply within
146
+ * `timeoutMs` (a host that does not know the command fails loudly instead of hanging), with
147
+ * `sendError` when the message cannot be posted, and can be cancelled. Every path releases the
148
+ * timer and the reply registration; a reply that arrives afterwards finds no entry and is ignored.
149
+ * `cancel()` leaves the promise unsettled: the caller that cancels has stopped waiting for it.
150
+ */
151
+ _postMessageBounded(command: string, args: object, options: {
152
+ timeoutMs: number;
153
+ timeoutError: object;
154
+ sendError: object;
155
+ }): {
156
+ promise: Promise<any>;
157
+ cancel: () => void;
158
+ };
138
159
  _postMessage(command: string, args: any, callBack?: any): void;
139
160
  _postMessageSync(command: string, args: any): any;
140
161
  }
@@ -438,6 +459,103 @@ declare module "types/external" {
438
459
  tableId?: string;
439
460
  tableRowId?: string;
440
461
  };
462
+ export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
463
+ export type AgentOutputDataType = "string" | "number" | "boolean";
464
+ export type AgentInputField = {
465
+ Key: string;
466
+ Name: string;
467
+ DataType: AgentInputDataType;
468
+ Required: boolean;
469
+ Description?: string;
470
+ };
471
+ export type AgentOutputField = {
472
+ Key: string;
473
+ Name: string;
474
+ DataType: AgentOutputDataType;
475
+ Description?: string;
476
+ };
477
+ /**
478
+ * A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
479
+ * A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
480
+ * `{ Key: file.key, FileName: file.name, Size: file.size }`.
481
+ */
482
+ export type AgentAttachmentValue = {
483
+ Key: string;
484
+ Url?: never;
485
+ FileName: string;
486
+ Size?: number;
487
+ ContentType?: string;
488
+ } | {
489
+ Url: string;
490
+ Key?: never;
491
+ FileName: string;
492
+ Size?: number;
493
+ ContentType?: string;
494
+ };
495
+ export type AgentInputValue = string | number | boolean | AgentAttachmentValue;
496
+ /** The Agent's published invocation contract. */
497
+ export type AgentContract = {
498
+ AgentId: string;
499
+ Definition: {
500
+ Name: string;
501
+ Description?: string;
502
+ Icon?: Record<string, unknown>;
503
+ Inputs: AgentInputField[];
504
+ Outputs: AgentOutputField[];
505
+ MaxOutputItems: number;
506
+ };
507
+ Readiness: {
508
+ Ready: boolean;
509
+ Issues: Array<{
510
+ Code: string;
511
+ Path: string;
512
+ Message: string;
513
+ }>;
514
+ };
515
+ };
516
+ export type AgentExecuteOptions = {
517
+ /** Values keyed by input `Key`, as declared in the contract. */
518
+ inputData: Record<string, AgentInputValue>;
519
+ };
520
+ /** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
521
+ export type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
522
+ /** What `execute` resolves with once the run is accepted, before it has finished. */
523
+ export type AgentExecutionAccepted = {
524
+ ExecutionId: string;
525
+ Status: AgentExecutionStatus;
526
+ };
527
+ export type AgentExecution = {
528
+ ExecutionId: string;
529
+ Status: AgentExecutionStatus;
530
+ Stage?: string;
531
+ /** Present on `Completed`: one row per item, keyed by output `Key`. */
532
+ Output?: {
533
+ items: Array<Record<string, string | number | boolean>>;
534
+ };
535
+ /** Present on `Failed`. */
536
+ Error?: {
537
+ Code: string;
538
+ Retryable: boolean;
539
+ Details?: unknown;
540
+ };
541
+ Warnings?: Array<Record<string, unknown>>;
542
+ CreatedAt?: string;
543
+ StartedAt?: string;
544
+ CompletedAt?: string;
545
+ };
546
+ /**
547
+ * How an Agent call fails: `error` is the message text and `errorCode` either the platform code
548
+ * (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
549
+ * `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
550
+ * `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
551
+ * `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
552
+ * There is no `message`: read `error` for the text.
553
+ */
554
+ export type AgentError = {
555
+ isError: true;
556
+ error?: string;
557
+ errorCode?: string;
558
+ };
441
559
  }
442
560
  declare module "types/internal" {
443
561
  import { userObject, accountObject, environmentObject } from "types/external";
@@ -806,6 +924,67 @@ declare module "app/decisiontable" {
806
924
  evaluate(payload?: object): any;
807
925
  }
808
926
  }
927
+ declare module "app/agent" {
928
+ import { BaseSDK } from "core/index";
929
+ import { AgentContract, AgentError, AgentExecuteOptions, AgentExecution, AgentExecutionAccepted } from "types/external";
930
+ /**
931
+ * A published Custom Agent of the current app.
932
+ *
933
+ * Get one with `kf.app.getAgent(agentId)`. Calls run as the signed-in user, against the Agent's
934
+ * published (Live) definition.
935
+ */
936
+ export class Agent extends BaseSDK {
937
+ private agentId;
938
+ private _id;
939
+ private activeWatches;
940
+ constructor(agentId: string);
941
+ /**
942
+ * Read the Agent's published contract: its inputs, outputs and readiness.
943
+ *
944
+ * @example
945
+ * const { Definition } = await kf.app.getAgent("AgXXXXXXXXXX").getContract();
946
+ */
947
+ getContract(): Promise<AgentContract>;
948
+ /**
949
+ * Start a run. Resolves once the run is accepted (`ExecutionId`, `Status`), not when it finishes;
950
+ * use {@link onExecutionComplete} or {@link getExecution} for the result.
951
+ *
952
+ * Never retried: if the call fails with `AGENT_EXECUTE_OUTCOME_UNKNOWN`, a run may still have
953
+ * started, and app code cannot list runs to find it: tell the user the request may still be in
954
+ * progress instead of starting another. `AGENT_EXECUTE_NOT_SENT` means it was not sent (for
955
+ * example, the user is offline).
956
+ *
957
+ * @example
958
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks", amount: 54000 } });
959
+ */
960
+ execute(options: AgentExecuteOptions): Promise<AgentExecutionAccepted>;
961
+ /**
962
+ * Read a run's current state, with its `Output` once `Completed` or its `Error` once `Failed`.
963
+ * Callers who are not the App's authors can read only their own runs.
964
+ */
965
+ getExecution(executionId: string): Promise<AgentExecution>;
966
+ /**
967
+ * Be told once when a run finishes. `onComplete` gets the run on `Completed` or `Failed` (read
968
+ * `Status`: a failed run is a result, not an error). `onWatchError` gets what stopped the
969
+ * observation instead: an unsupported host, an access or network failure, or the observation limit
970
+ * (`AGENT_OBSERVATION_STOPPED`, after about six minutes; the run may still finish, so read it later
971
+ * with {@link getExecution}). At most one of the two is called, at most once.
972
+ *
973
+ * Neither is called if the script that registered them stops first: form, field, gallery and
974
+ * table scripts stop after one minute, and they and page event scripts stop when the next script
975
+ * starts on the same form, component or page. In those scripts, keep the `ExecutionId` and read
976
+ * it later with {@link getExecution}.
977
+ *
978
+ * Returns a function that stops observing. It never cancels the run.
979
+ *
980
+ * @example
981
+ * const stop = agent.onExecutionComplete(ExecutionId, (run) => show(run), (err) => warn(err));
982
+ * // later, e.g. on unmount
983
+ * stop();
984
+ */
985
+ onExecutionComplete(executionId: string, onComplete: (execution: AgentExecution) => void, onWatchError?: (error: AgentError) => void): () => void;
986
+ }
987
+ }
809
988
  declare module "dataform/index" {
810
989
  import { BaseSDK } from "core/index";
811
990
  import { Form } from "form/index";
@@ -1277,6 +1456,7 @@ declare module "app/index" {
1277
1456
  import { AppContext } from "types/internal";
1278
1457
  import { rolesObject } from "types/external";
1279
1458
  import { DecisionTable } from "app/decisiontable";
1459
+ import { Agent } from "app/agent";
1280
1460
  import { Dataform } from "dataform/index";
1281
1461
  import { Board } from "board/index";
1282
1462
  import { Process } from "process/index";
@@ -1288,6 +1468,15 @@ declare module "app/index" {
1288
1468
  setVariable(key: string | object, value?: any): any;
1289
1469
  openPage(pageId: string, pageParams?: object): any;
1290
1470
  getDecisionTable(flowId: string): DecisionTable;
1471
+ /**
1472
+ * Get a published Custom Agent of this app by its id. The handle sends no request until you call one
1473
+ * of its methods; see {@link Agent}.
1474
+ *
1475
+ * @example
1476
+ * const agent = kf.app.getAgent("AgXXXXXXXXXX");
1477
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
1478
+ */
1479
+ getAgent(agentId: string): Agent;
1291
1480
  getDataform(flowId: string): Dataform;
1292
1481
  getBoard(flowId: string): Board;
1293
1482
  getProcess(flowId: string): Process;
@@ -1330,6 +1519,7 @@ declare module "app/index" {
1330
1519
  }): Promise<rolesObject>;
1331
1520
  }
1332
1521
  export * from "app/component";
1522
+ export { Agent };
1333
1523
  export { Page };
1334
1524
  export * from "app/popup";
1335
1525
  }
@@ -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
@@ -706,6 +753,15 @@ declare class Application {
706
753
  setVariable(key: string | object, value?: any): any;
707
754
  openPage(pageId: string, pageParams?: object): any;
708
755
  getDecisionTable(flowId: string): DecisionTable;
756
+ /**
757
+ * Get a published Custom Agent of this app by its id. The handle sends no request until you call one
758
+ * of its methods; see {@link Agent}.
759
+ *
760
+ * @example
761
+ * const agent = kf.app.getAgent("AgXXXXXXXXXX");
762
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
763
+ */
764
+ getAgent(agentId: string): Agent;
709
765
  getDataform(flowId: string): Dataform;
710
766
  getBoard(flowId: string): Board;
711
767
  getProcess(flowId: string): Process;
@@ -1094,3 +1150,96 @@ declare type BoardFieldOptions = {
1094
1150
  tableId?: string;
1095
1151
  tableRowId?: string;
1096
1152
  };
1153
+
1154
+ // ============================================
1155
+ // Custom Agent Types
1156
+ // ============================================
1157
+
1158
+ declare type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
1159
+
1160
+ declare type AgentOutputDataType = "string" | "number" | "boolean";
1161
+
1162
+ declare type AgentInputField = {
1163
+ Key: string;
1164
+ Name: string;
1165
+ DataType: AgentInputDataType;
1166
+ Required: boolean;
1167
+ Description?: string;
1168
+ };
1169
+
1170
+ declare type AgentOutputField = {
1171
+ Key: string;
1172
+ Name: string;
1173
+ DataType: AgentOutputDataType;
1174
+ Description?: string;
1175
+ };
1176
+
1177
+ /**
1178
+ * A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
1179
+ * A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
1180
+ * `{ Key: file.key, FileName: file.name, Size: file.size }`.
1181
+ */
1182
+ declare type AgentAttachmentValue =
1183
+ | { Key: string; Url?: never; FileName: string; Size?: number; ContentType?: string }
1184
+ | { Url: string; Key?: never; FileName: string; Size?: number; ContentType?: string };
1185
+
1186
+ declare type AgentInputValue = string | number | boolean | AgentAttachmentValue;
1187
+
1188
+ /** The Agent's published invocation contract. */
1189
+ declare type AgentContract = {
1190
+ AgentId: string;
1191
+ Definition: {
1192
+ Name: string;
1193
+ Description?: string;
1194
+ Icon?: Record<string, unknown>;
1195
+ Inputs: AgentInputField[];
1196
+ Outputs: AgentOutputField[];
1197
+ MaxOutputItems: number;
1198
+ };
1199
+ Readiness: {
1200
+ Ready: boolean;
1201
+ Issues: Array<{ Code: string; Path: string; Message: string }>;
1202
+ };
1203
+ };
1204
+
1205
+ declare type AgentExecuteOptions = {
1206
+ /** Values keyed by input `Key`, as declared in the contract. */
1207
+ inputData: Record<string, AgentInputValue>;
1208
+ };
1209
+
1210
+ /** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
1211
+ declare type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
1212
+
1213
+ /** What `execute` resolves with once the run is accepted, before it has finished. */
1214
+ declare type AgentExecutionAccepted = {
1215
+ ExecutionId: string;
1216
+ Status: AgentExecutionStatus;
1217
+ };
1218
+
1219
+ declare type AgentExecution = {
1220
+ ExecutionId: string;
1221
+ Status: AgentExecutionStatus;
1222
+ Stage?: string;
1223
+ /** Present on `Completed`: one row per item, keyed by output `Key`. */
1224
+ Output?: { items: Array<Record<string, string | number | boolean>> };
1225
+ /** Present on `Failed`. */
1226
+ Error?: { Code: string; Retryable: boolean; Details?: unknown };
1227
+ Warnings?: Array<Record<string, unknown>>;
1228
+ CreatedAt?: string;
1229
+ StartedAt?: string;
1230
+ CompletedAt?: string;
1231
+ };
1232
+
1233
+ /**
1234
+ * How an Agent call fails: `error` is the message text and `errorCode` either the platform code
1235
+ * (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
1236
+ * `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
1237
+ * `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
1238
+ * `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
1239
+ * There is no `message`: read `error` for the text.
1240
+ */
1241
+ declare type AgentError = {
1242
+ isError: true;
1243
+ error?: string;
1244
+ errorCode?: string;
1245
+ };
package/dist/nocode.d.ts CHANGED
@@ -60,6 +60,11 @@ 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;
63
68
  DECISION_TABLE_EXECUTE: string;
64
69
  DATAFORM_IMPORT_CSV: string;
65
70
  DATAFORM_OPEN_FORM: string;
@@ -117,6 +122,7 @@ declare module "core/constants" {
117
122
  COMPONENT_ON_MOUNT: string;
118
123
  CC_ON_PARAMS_CHANGE: string;
119
124
  CC_ON_ROUTE_CHANGE: string;
125
+ CUSTOM_AGENT_EXECUTION_COMPLETE: string;
120
126
  };
121
127
  export const DEFAULTS: {
122
128
  POPUP_ID: string;
@@ -135,6 +141,21 @@ declare module "core/index" {
135
141
  }
136
142
  export class BaseSDK extends EventBase {
137
143
  _postMessageAsync(command: string, args: any, hasCallBack?: boolean, callBack?: (data: any) => {}): object | string | any;
144
+ /**
145
+ * Like _postMessageAsync, but settles with `timeoutError` when the host does not reply within
146
+ * `timeoutMs` (a host that does not know the command fails loudly instead of hanging), with
147
+ * `sendError` when the message cannot be posted, and can be cancelled. Every path releases the
148
+ * timer and the reply registration; a reply that arrives afterwards finds no entry and is ignored.
149
+ * `cancel()` leaves the promise unsettled: the caller that cancels has stopped waiting for it.
150
+ */
151
+ _postMessageBounded(command: string, args: object, options: {
152
+ timeoutMs: number;
153
+ timeoutError: object;
154
+ sendError: object;
155
+ }): {
156
+ promise: Promise<any>;
157
+ cancel: () => void;
158
+ };
138
159
  _postMessage(command: string, args: any, callBack?: any): void;
139
160
  _postMessageSync(command: string, args: any): any;
140
161
  }
@@ -438,6 +459,103 @@ declare module "types/external" {
438
459
  tableId?: string;
439
460
  tableRowId?: string;
440
461
  };
462
+ export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
463
+ export type AgentOutputDataType = "string" | "number" | "boolean";
464
+ export type AgentInputField = {
465
+ Key: string;
466
+ Name: string;
467
+ DataType: AgentInputDataType;
468
+ Required: boolean;
469
+ Description?: string;
470
+ };
471
+ export type AgentOutputField = {
472
+ Key: string;
473
+ Name: string;
474
+ DataType: AgentOutputDataType;
475
+ Description?: string;
476
+ };
477
+ /**
478
+ * A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
479
+ * A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
480
+ * `{ Key: file.key, FileName: file.name, Size: file.size }`.
481
+ */
482
+ export type AgentAttachmentValue = {
483
+ Key: string;
484
+ Url?: never;
485
+ FileName: string;
486
+ Size?: number;
487
+ ContentType?: string;
488
+ } | {
489
+ Url: string;
490
+ Key?: never;
491
+ FileName: string;
492
+ Size?: number;
493
+ ContentType?: string;
494
+ };
495
+ export type AgentInputValue = string | number | boolean | AgentAttachmentValue;
496
+ /** The Agent's published invocation contract. */
497
+ export type AgentContract = {
498
+ AgentId: string;
499
+ Definition: {
500
+ Name: string;
501
+ Description?: string;
502
+ Icon?: Record<string, unknown>;
503
+ Inputs: AgentInputField[];
504
+ Outputs: AgentOutputField[];
505
+ MaxOutputItems: number;
506
+ };
507
+ Readiness: {
508
+ Ready: boolean;
509
+ Issues: Array<{
510
+ Code: string;
511
+ Path: string;
512
+ Message: string;
513
+ }>;
514
+ };
515
+ };
516
+ export type AgentExecuteOptions = {
517
+ /** Values keyed by input `Key`, as declared in the contract. */
518
+ inputData: Record<string, AgentInputValue>;
519
+ };
520
+ /** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
521
+ export type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
522
+ /** What `execute` resolves with once the run is accepted, before it has finished. */
523
+ export type AgentExecutionAccepted = {
524
+ ExecutionId: string;
525
+ Status: AgentExecutionStatus;
526
+ };
527
+ export type AgentExecution = {
528
+ ExecutionId: string;
529
+ Status: AgentExecutionStatus;
530
+ Stage?: string;
531
+ /** Present on `Completed`: one row per item, keyed by output `Key`. */
532
+ Output?: {
533
+ items: Array<Record<string, string | number | boolean>>;
534
+ };
535
+ /** Present on `Failed`. */
536
+ Error?: {
537
+ Code: string;
538
+ Retryable: boolean;
539
+ Details?: unknown;
540
+ };
541
+ Warnings?: Array<Record<string, unknown>>;
542
+ CreatedAt?: string;
543
+ StartedAt?: string;
544
+ CompletedAt?: string;
545
+ };
546
+ /**
547
+ * How an Agent call fails: `error` is the message text and `errorCode` either the platform code
548
+ * (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
549
+ * `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
550
+ * `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
551
+ * `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
552
+ * There is no `message`: read `error` for the text.
553
+ */
554
+ export type AgentError = {
555
+ isError: true;
556
+ error?: string;
557
+ errorCode?: string;
558
+ };
441
559
  }
442
560
  declare module "types/internal" {
443
561
  import { userObject, accountObject, environmentObject } from "types/external";
@@ -758,6 +876,67 @@ declare module "nocode" {
758
876
  function initSDK(config: SDKContext): NocodeSDK;
759
877
  export { window, initSDK as default };
760
878
  }
879
+ declare module "app/agent" {
880
+ import { BaseSDK } from "core/index";
881
+ import { AgentContract, AgentError, AgentExecuteOptions, AgentExecution, AgentExecutionAccepted } from "types/external";
882
+ /**
883
+ * A published Custom Agent of the current app.
884
+ *
885
+ * Get one with `kf.app.getAgent(agentId)`. Calls run as the signed-in user, against the Agent's
886
+ * published (Live) definition.
887
+ */
888
+ export class Agent extends BaseSDK {
889
+ private agentId;
890
+ private _id;
891
+ private activeWatches;
892
+ constructor(agentId: string);
893
+ /**
894
+ * Read the Agent's published contract: its inputs, outputs and readiness.
895
+ *
896
+ * @example
897
+ * const { Definition } = await kf.app.getAgent("AgXXXXXXXXXX").getContract();
898
+ */
899
+ getContract(): Promise<AgentContract>;
900
+ /**
901
+ * Start a run. Resolves once the run is accepted (`ExecutionId`, `Status`), not when it finishes;
902
+ * use {@link onExecutionComplete} or {@link getExecution} for the result.
903
+ *
904
+ * Never retried: if the call fails with `AGENT_EXECUTE_OUTCOME_UNKNOWN`, a run may still have
905
+ * started, and app code cannot list runs to find it: tell the user the request may still be in
906
+ * progress instead of starting another. `AGENT_EXECUTE_NOT_SENT` means it was not sent (for
907
+ * example, the user is offline).
908
+ *
909
+ * @example
910
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks", amount: 54000 } });
911
+ */
912
+ execute(options: AgentExecuteOptions): Promise<AgentExecutionAccepted>;
913
+ /**
914
+ * Read a run's current state, with its `Output` once `Completed` or its `Error` once `Failed`.
915
+ * Callers who are not the App's authors can read only their own runs.
916
+ */
917
+ getExecution(executionId: string): Promise<AgentExecution>;
918
+ /**
919
+ * Be told once when a run finishes. `onComplete` gets the run on `Completed` or `Failed` (read
920
+ * `Status`: a failed run is a result, not an error). `onWatchError` gets what stopped the
921
+ * observation instead: an unsupported host, an access or network failure, or the observation limit
922
+ * (`AGENT_OBSERVATION_STOPPED`, after about six minutes; the run may still finish, so read it later
923
+ * with {@link getExecution}). At most one of the two is called, at most once.
924
+ *
925
+ * Neither is called if the script that registered them stops first: form, field, gallery and
926
+ * table scripts stop after one minute, and they and page event scripts stop when the next script
927
+ * starts on the same form, component or page. In those scripts, keep the `ExecutionId` and read
928
+ * it later with {@link getExecution}.
929
+ *
930
+ * Returns a function that stops observing. It never cancels the run.
931
+ *
932
+ * @example
933
+ * const stop = agent.onExecutionComplete(ExecutionId, (run) => show(run), (err) => warn(err));
934
+ * // later, e.g. on unmount
935
+ * stop();
936
+ */
937
+ onExecutionComplete(executionId: string, onComplete: (execution: AgentExecution) => void, onWatchError?: (error: AgentError) => void): () => void;
938
+ }
939
+ }
761
940
  declare module "app/component" {
762
941
  import { BaseSDK } from "core/index";
763
942
  import { ComponentProps } from "types/internal";
@@ -1316,6 +1495,7 @@ declare module "app/index" {
1316
1495
  import { AppContext } from "types/internal";
1317
1496
  import { rolesObject } from "types/external";
1318
1497
  import { DecisionTable } from "app/decisiontable";
1498
+ import { Agent } from "app/agent";
1319
1499
  import { Dataform } from "dataform/index";
1320
1500
  import { Board } from "board/index";
1321
1501
  import { Process } from "process/index";
@@ -1327,6 +1507,15 @@ declare module "app/index" {
1327
1507
  setVariable(key: string | object, value?: any): any;
1328
1508
  openPage(pageId: string, pageParams?: object): any;
1329
1509
  getDecisionTable(flowId: string): DecisionTable;
1510
+ /**
1511
+ * Get a published Custom Agent of this app by its id. The handle sends no request until you call one
1512
+ * of its methods; see {@link Agent}.
1513
+ *
1514
+ * @example
1515
+ * const agent = kf.app.getAgent("AgXXXXXXXXXX");
1516
+ * const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
1517
+ */
1518
+ getAgent(agentId: string): Agent;
1330
1519
  getDataform(flowId: string): Dataform;
1331
1520
  getBoard(flowId: string): Board;
1332
1521
  getProcess(flowId: string): Process;
@@ -1369,6 +1558,7 @@ declare module "app/index" {
1369
1558
  }): Promise<rolesObject>;
1370
1559
  }
1371
1560
  export * from "app/component";
1561
+ export { Agent };
1372
1562
  export { Page };
1373
1563
  export * from "app/popup";
1374
1564
  }