@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/index.d.ts +281 -1
- package/dist/kfsdk.es.js +335 -5
- package/dist/kfsdk.umd.js +1 -1
- package/dist/lowcode.d.ts +281 -1
- package/dist/lowcode.types.d.ts +229 -0
- package/dist/nocode.d.ts +281 -1
- package/dist/nocode.types.d.ts +120 -0
- package/dist/snippets.json +21 -1
- package/package.json +4 -2
- package/dist/kf.lowcodeworkersdk.es.js +0 -1510
package/dist/index.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
|
}
|
|
@@ -390,6 +416,134 @@ declare module "types/external" {
|
|
|
390
416
|
tableId?: string;
|
|
391
417
|
tableRowId?: string;
|
|
392
418
|
};
|
|
419
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
420
|
+
export type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
421
|
+
/**
|
|
422
|
+
* What a Custom Function run looks like from the SDK.
|
|
423
|
+
*
|
|
424
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
425
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
426
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
427
|
+
*/
|
|
428
|
+
export type RunEnvelope = {
|
|
429
|
+
RunId: string;
|
|
430
|
+
Status: RunStatus;
|
|
431
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
432
|
+
Result?: unknown;
|
|
433
|
+
Error?: {
|
|
434
|
+
Code?: string;
|
|
435
|
+
Message: string;
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
440
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
441
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
442
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
443
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
444
|
+
*/
|
|
445
|
+
export type RunWatchError = {
|
|
446
|
+
isError: true;
|
|
447
|
+
error?: string;
|
|
448
|
+
errorCode?: string;
|
|
449
|
+
};
|
|
450
|
+
export type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
|
|
451
|
+
export type AgentOutputDataType = "string" | "number" | "boolean";
|
|
452
|
+
export type AgentInputField = {
|
|
453
|
+
Key: string;
|
|
454
|
+
Name: string;
|
|
455
|
+
DataType: AgentInputDataType;
|
|
456
|
+
Required: boolean;
|
|
457
|
+
Description?: string;
|
|
458
|
+
};
|
|
459
|
+
export type AgentOutputField = {
|
|
460
|
+
Key: string;
|
|
461
|
+
Name: string;
|
|
462
|
+
DataType: AgentOutputDataType;
|
|
463
|
+
Description?: string;
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
|
|
467
|
+
* A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
|
|
468
|
+
* `{ Key: file.key, FileName: file.name, Size: file.size }`.
|
|
469
|
+
*/
|
|
470
|
+
export type AgentAttachmentValue = {
|
|
471
|
+
Key: string;
|
|
472
|
+
Url?: never;
|
|
473
|
+
FileName: string;
|
|
474
|
+
Size?: number;
|
|
475
|
+
ContentType?: string;
|
|
476
|
+
} | {
|
|
477
|
+
Url: string;
|
|
478
|
+
Key?: never;
|
|
479
|
+
FileName: string;
|
|
480
|
+
Size?: number;
|
|
481
|
+
ContentType?: string;
|
|
482
|
+
};
|
|
483
|
+
export type AgentInputValue = string | number | boolean | AgentAttachmentValue;
|
|
484
|
+
/** The Agent's published invocation contract. */
|
|
485
|
+
export type AgentContract = {
|
|
486
|
+
AgentId: string;
|
|
487
|
+
Definition: {
|
|
488
|
+
Name: string;
|
|
489
|
+
Description?: string;
|
|
490
|
+
Icon?: Record<string, unknown>;
|
|
491
|
+
Inputs: AgentInputField[];
|
|
492
|
+
Outputs: AgentOutputField[];
|
|
493
|
+
MaxOutputItems: number;
|
|
494
|
+
};
|
|
495
|
+
Readiness: {
|
|
496
|
+
Ready: boolean;
|
|
497
|
+
Issues: Array<{
|
|
498
|
+
Code: string;
|
|
499
|
+
Path: string;
|
|
500
|
+
Message: string;
|
|
501
|
+
}>;
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
export type AgentExecuteOptions = {
|
|
505
|
+
/** Values keyed by input `Key`, as declared in the contract. */
|
|
506
|
+
inputData: Record<string, AgentInputValue>;
|
|
507
|
+
};
|
|
508
|
+
/** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
|
|
509
|
+
export type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
|
|
510
|
+
/** What `execute` resolves with once the run is accepted, before it has finished. */
|
|
511
|
+
export type AgentExecutionAccepted = {
|
|
512
|
+
ExecutionId: string;
|
|
513
|
+
Status: AgentExecutionStatus;
|
|
514
|
+
};
|
|
515
|
+
export type AgentExecution = {
|
|
516
|
+
ExecutionId: string;
|
|
517
|
+
Status: AgentExecutionStatus;
|
|
518
|
+
Stage?: string;
|
|
519
|
+
/** Present on `Completed`: one row per item, keyed by output `Key`. */
|
|
520
|
+
Output?: {
|
|
521
|
+
items: Array<Record<string, string | number | boolean>>;
|
|
522
|
+
};
|
|
523
|
+
/** Present on `Failed`. */
|
|
524
|
+
Error?: {
|
|
525
|
+
Code: string;
|
|
526
|
+
Retryable: boolean;
|
|
527
|
+
Details?: unknown;
|
|
528
|
+
};
|
|
529
|
+
Warnings?: Array<Record<string, unknown>>;
|
|
530
|
+
CreatedAt?: string;
|
|
531
|
+
StartedAt?: string;
|
|
532
|
+
CompletedAt?: string;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* How an Agent call fails: `error` is the message text and `errorCode` either the platform code
|
|
536
|
+
* (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
|
|
537
|
+
* `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
|
|
538
|
+
* `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
|
|
539
|
+
* `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
|
|
540
|
+
* There is no `message`: read `error` for the text.
|
|
541
|
+
*/
|
|
542
|
+
export type AgentError = {
|
|
543
|
+
isError: true;
|
|
544
|
+
error?: string;
|
|
545
|
+
errorCode?: string;
|
|
546
|
+
};
|
|
393
547
|
}
|
|
394
548
|
declare module "types/internal" {
|
|
395
549
|
import { userObject, accountObject, environmentObject } from "types/external";
|
|
@@ -758,6 +912,67 @@ declare module "app/decisiontable" {
|
|
|
758
912
|
evaluate(payload?: object): any;
|
|
759
913
|
}
|
|
760
914
|
}
|
|
915
|
+
declare module "app/agent" {
|
|
916
|
+
import { BaseSDK } from "core/index";
|
|
917
|
+
import { AgentContract, AgentError, AgentExecuteOptions, AgentExecution, AgentExecutionAccepted } from "types/external";
|
|
918
|
+
/**
|
|
919
|
+
* A published Custom Agent of the current app.
|
|
920
|
+
*
|
|
921
|
+
* Get one with `kf.app.getAgent(agentId)`. Calls run as the signed-in user, against the Agent's
|
|
922
|
+
* published (Live) definition.
|
|
923
|
+
*/
|
|
924
|
+
export class Agent extends BaseSDK {
|
|
925
|
+
private agentId;
|
|
926
|
+
private _id;
|
|
927
|
+
private activeWatches;
|
|
928
|
+
constructor(agentId: string);
|
|
929
|
+
/**
|
|
930
|
+
* Read the Agent's published contract: its inputs, outputs and readiness.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* const { Definition } = await kf.app.getAgent("AgXXXXXXXXXX").getContract();
|
|
934
|
+
*/
|
|
935
|
+
getContract(): Promise<AgentContract>;
|
|
936
|
+
/**
|
|
937
|
+
* Start a run. Resolves once the run is accepted (`ExecutionId`, `Status`), not when it finishes;
|
|
938
|
+
* use {@link onExecutionComplete} or {@link getExecution} for the result.
|
|
939
|
+
*
|
|
940
|
+
* Never retried: if the call fails with `AGENT_EXECUTE_OUTCOME_UNKNOWN`, a run may still have
|
|
941
|
+
* started, and app code cannot list runs to find it: tell the user the request may still be in
|
|
942
|
+
* progress instead of starting another. `AGENT_EXECUTE_NOT_SENT` means it was not sent (for
|
|
943
|
+
* example, the user is offline).
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks", amount: 54000 } });
|
|
947
|
+
*/
|
|
948
|
+
execute(options: AgentExecuteOptions): Promise<AgentExecutionAccepted>;
|
|
949
|
+
/**
|
|
950
|
+
* Read a run's current state, with its `Output` once `Completed` or its `Error` once `Failed`.
|
|
951
|
+
* Callers who are not the App's authors can read only their own runs.
|
|
952
|
+
*/
|
|
953
|
+
getExecution(executionId: string): Promise<AgentExecution>;
|
|
954
|
+
/**
|
|
955
|
+
* Be told once when a run finishes. `onComplete` gets the run on `Completed` or `Failed` (read
|
|
956
|
+
* `Status`: a failed run is a result, not an error). `onWatchError` gets what stopped the
|
|
957
|
+
* observation instead: an unsupported host, an access or network failure, or the observation limit
|
|
958
|
+
* (`AGENT_OBSERVATION_STOPPED`, after about six minutes; the run may still finish, so read it later
|
|
959
|
+
* with {@link getExecution}). At most one of the two is called, at most once.
|
|
960
|
+
*
|
|
961
|
+
* Neither is called if the script that registered them stops first: form, field, gallery and
|
|
962
|
+
* table scripts stop after one minute, and they and page event scripts stop when the next script
|
|
963
|
+
* starts on the same form, component or page. In those scripts, keep the `ExecutionId` and read
|
|
964
|
+
* it later with {@link getExecution}.
|
|
965
|
+
*
|
|
966
|
+
* Returns a function that stops observing. It never cancels the run.
|
|
967
|
+
*
|
|
968
|
+
* @example
|
|
969
|
+
* const stop = agent.onExecutionComplete(ExecutionId, (run) => show(run), (err) => warn(err));
|
|
970
|
+
* // later, e.g. on unmount
|
|
971
|
+
* stop();
|
|
972
|
+
*/
|
|
973
|
+
onExecutionComplete(executionId: string, onComplete: (execution: AgentExecution) => void, onWatchError?: (error: AgentError) => void): () => void;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
761
976
|
declare module "form/index" {
|
|
762
977
|
import { BaseSDK } from "core/index";
|
|
763
978
|
export class Form extends BaseSDK {
|
|
@@ -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
|
}
|