@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/nocode.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";
|
|
@@ -758,6 +912,67 @@ declare module "nocode" {
|
|
|
758
912
|
function initSDK(config: SDKContext): NocodeSDK;
|
|
759
913
|
export { window, initSDK as default };
|
|
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 "app/component" {
|
|
762
977
|
import { BaseSDK } from "core/index";
|
|
763
978
|
import { ComponentProps } from "types/internal";
|
|
@@ -1314,19 +1529,83 @@ declare module "app/index" {
|
|
|
1314
1529
|
import { BaseSDK } from "core/index";
|
|
1315
1530
|
import { Page } from "app/page";
|
|
1316
1531
|
import { AppContext } from "types/internal";
|
|
1317
|
-
import { rolesObject } from "types/external";
|
|
1532
|
+
import { rolesObject, RunEnvelope, RunWatchError } from "types/external";
|
|
1318
1533
|
import { DecisionTable } from "app/decisiontable";
|
|
1534
|
+
import { Agent } from "app/agent";
|
|
1319
1535
|
import { Dataform } from "dataform/index";
|
|
1320
1536
|
import { Board } from "board/index";
|
|
1321
1537
|
import { Process } from "process/index";
|
|
1322
1538
|
export class Application extends BaseSDK {
|
|
1323
1539
|
page: Page;
|
|
1324
1540
|
_id: string;
|
|
1541
|
+
private activeWatches;
|
|
1325
1542
|
constructor(props: AppContext, isCustomComponent?: boolean);
|
|
1326
1543
|
getVariable(key: string): any;
|
|
1327
1544
|
setVariable(key: string | object, value?: any): any;
|
|
1328
1545
|
openPage(pageId: string, pageParams?: object): any;
|
|
1546
|
+
/**
|
|
1547
|
+
* Run a published Custom Function by name.
|
|
1548
|
+
*
|
|
1549
|
+
* An Interactive function resolves with its terminal envelope. A Background
|
|
1550
|
+
* function resolves as soon as it is queued, with `Status: "Queued"` and a
|
|
1551
|
+
* `RunId`; use {@link getFunctionRun} or {@link onFunctionRunComplete} for its result.
|
|
1552
|
+
*
|
|
1553
|
+
* A refused run rejects with the platform's SDK error shape: the message
|
|
1554
|
+
* text is in `error` and the code (`KISSFLOW_ERROR_…`) in `errorCode`.
|
|
1555
|
+
* A host that does not answer within 45 s rejects with
|
|
1556
|
+
* `FUNCTION_RUN_OUTCOME_UNKNOWN`: the run may still have started, so tell
|
|
1557
|
+
* the user instead of starting another.
|
|
1558
|
+
*
|
|
1559
|
+
* Custom Functions are application-scoped: this is reachable from page,
|
|
1560
|
+
* component and flow event scripts that run inside an application, where
|
|
1561
|
+
* `kf.app` exists. There is no `kf.app` outside one.
|
|
1562
|
+
*
|
|
1563
|
+
* @example
|
|
1564
|
+
* const run = await kf.app.runFunction("review_expense_claim", { claimId });
|
|
1565
|
+
*/
|
|
1566
|
+
runFunction(name: string, parameters?: Record<string, unknown>): Promise<RunEnvelope>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Fetch a run's current state, including its `Result` once it has one.
|
|
1569
|
+
*
|
|
1570
|
+
* @example
|
|
1571
|
+
* const run = await kf.app.getFunctionRun(runId);
|
|
1572
|
+
* if (run.Status === "Success") use(run.Result);
|
|
1573
|
+
*/
|
|
1574
|
+
getFunctionRun(runId: string): Promise<RunEnvelope>;
|
|
1575
|
+
/**
|
|
1576
|
+
* Be told when a Background run reaches a terminal state.
|
|
1577
|
+
*
|
|
1578
|
+
* Fires `callBack` once with the run's envelope. "Complete" means the run
|
|
1579
|
+
* stopped, not that it worked: it fires on `Failed` and `TimedOut` just as
|
|
1580
|
+
* it does on `Success`, so read `Status` before trusting `Result`. If the
|
|
1581
|
+
* host cannot watch the run at all, `onError` is called instead of
|
|
1582
|
+
* `callBack` ever firing: an older host (`FUNCTION_HOST_UNSUPPORTED`), a
|
|
1583
|
+
* refusal, or the watch limit (`FUNCTION_OBSERVATION_STOPPED`, after about
|
|
1584
|
+
* ten minutes; the run may still finish, so read it later with
|
|
1585
|
+
* {@link getFunctionRun}). At most one of the two is called, at most once.
|
|
1586
|
+
*
|
|
1587
|
+
* Returns a function that unsubscribes. The callback lives only as long as
|
|
1588
|
+
* the script that registered it: form events end their script after 60 s
|
|
1589
|
+
* and a page event ends the previous one when it fires again, while a
|
|
1590
|
+
* Background run may take up to 600 s. Prefer polling {@link getFunctionRun} from a
|
|
1591
|
+
* script that outlives the run, or re-attach after the script restarts.
|
|
1592
|
+
*
|
|
1593
|
+
* @example
|
|
1594
|
+
* const stop = kf.app.onFunctionRunComplete(run.RunId, (done) => show(done), (err) => warn(err));
|
|
1595
|
+
* // later, e.g. on unmount — the host stops watching the run too
|
|
1596
|
+
* stop();
|
|
1597
|
+
*/
|
|
1598
|
+
onFunctionRunComplete(runId: string, callBack: (run: RunEnvelope) => void, onError?: (error: RunWatchError) => void): () => void;
|
|
1329
1599
|
getDecisionTable(flowId: string): DecisionTable;
|
|
1600
|
+
/**
|
|
1601
|
+
* Get a published Custom Agent of this app by its id. The handle sends no request until you call one
|
|
1602
|
+
* of its methods; see {@link Agent}.
|
|
1603
|
+
*
|
|
1604
|
+
* @example
|
|
1605
|
+
* const agent = kf.app.getAgent("AgXXXXXXXXXX");
|
|
1606
|
+
* const { ExecutionId } = await agent.execute({ inputData: { request: "Two desks" } });
|
|
1607
|
+
*/
|
|
1608
|
+
getAgent(agentId: string): Agent;
|
|
1330
1609
|
getDataform(flowId: string): Dataform;
|
|
1331
1610
|
getBoard(flowId: string): Board;
|
|
1332
1611
|
getProcess(flowId: string): Process;
|
|
@@ -1369,6 +1648,7 @@ declare module "app/index" {
|
|
|
1369
1648
|
}): Promise<rolesObject>;
|
|
1370
1649
|
}
|
|
1371
1650
|
export * from "app/component";
|
|
1651
|
+
export { Agent };
|
|
1372
1652
|
export { Page };
|
|
1373
1653
|
export * from "app/popup";
|
|
1374
1654
|
}
|
package/dist/nocode.types.d.ts
CHANGED
|
@@ -560,3 +560,123 @@ declare type BoardFieldOptions = {
|
|
|
560
560
|
tableId?: string;
|
|
561
561
|
tableRowId?: string;
|
|
562
562
|
};
|
|
563
|
+
|
|
564
|
+
/** The terminal states a Custom Function run ends in, plus the two it passes through. */
|
|
565
|
+
declare type RunStatus = "Queued" | "Running" | "Success" | "Failed" | "TimedOut";
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* What a Custom Function run looks like from the SDK.
|
|
569
|
+
*
|
|
570
|
+
* An Interactive function resolves with the terminal envelope directly. A
|
|
571
|
+
* Background function resolves with `Queued` and only `RunId`; fetch the rest
|
|
572
|
+
* with `getFunctionRun`, or wait for it with `onFunctionRunComplete`.
|
|
573
|
+
*/
|
|
574
|
+
declare type RunEnvelope = {
|
|
575
|
+
RunId: string;
|
|
576
|
+
Status: RunStatus;
|
|
577
|
+
/** Whatever the function returned. Only constrained when its output contract names properties. */
|
|
578
|
+
Result?: unknown;
|
|
579
|
+
Error?: { Code?: string; Message: string };
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* How a Custom Function call fails: `error` is the message text and `errorCode` either the platform
|
|
584
|
+
* code (`KISSFLOW_ERROR_…`) or a `FUNCTION_…` code, including `FUNCTION_HOST_TIMEOUT`,
|
|
585
|
+
* `FUNCTION_REQUEST_NOT_SENT`, `FUNCTION_RUN_OUTCOME_UNKNOWN` (a run may have started),
|
|
586
|
+
* `FUNCTION_RUN_NOT_SENT` (no run started), `FUNCTION_HOST_UNSUPPORTED`, `FUNCTION_WATCH_INVALID_EVENT`
|
|
587
|
+
* and `FUNCTION_OBSERVATION_STOPPED`. The list may grow; fall back to `error` for an unknown code.
|
|
588
|
+
*/
|
|
589
|
+
declare type RunWatchError = { isError: true; error?: string; errorCode?: string };
|
|
590
|
+
|
|
591
|
+
// ============================================
|
|
592
|
+
// Custom Agent Types
|
|
593
|
+
// ============================================
|
|
594
|
+
|
|
595
|
+
declare type AgentInputDataType = "Text" | "Number" | "Boolean" | "Attachment";
|
|
596
|
+
|
|
597
|
+
declare type AgentOutputDataType = "string" | "number" | "boolean";
|
|
598
|
+
|
|
599
|
+
declare type AgentInputField = {
|
|
600
|
+
Key: string;
|
|
601
|
+
Name: string;
|
|
602
|
+
DataType: AgentInputDataType;
|
|
603
|
+
Required: boolean;
|
|
604
|
+
Description?: string;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
declare type AgentOutputField = {
|
|
608
|
+
Key: string;
|
|
609
|
+
Name: string;
|
|
610
|
+
DataType: AgentOutputDataType;
|
|
611
|
+
Description?: string;
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* A file for an `Attachment` input: exactly one of `Key` (a Kissflow attachment) or `Url` (https).
|
|
616
|
+
* A file from `openFilePicker` or `uploadFile` has lowercase keys: pass
|
|
617
|
+
* `{ Key: file.key, FileName: file.name, Size: file.size }`.
|
|
618
|
+
*/
|
|
619
|
+
declare type AgentAttachmentValue =
|
|
620
|
+
| { Key: string; Url?: never; FileName: string; Size?: number; ContentType?: string }
|
|
621
|
+
| { Url: string; Key?: never; FileName: string; Size?: number; ContentType?: string };
|
|
622
|
+
|
|
623
|
+
declare type AgentInputValue = string | number | boolean | AgentAttachmentValue;
|
|
624
|
+
|
|
625
|
+
/** The Agent's published invocation contract. */
|
|
626
|
+
declare type AgentContract = {
|
|
627
|
+
AgentId: string;
|
|
628
|
+
Definition: {
|
|
629
|
+
Name: string;
|
|
630
|
+
Description?: string;
|
|
631
|
+
Icon?: Record<string, unknown>;
|
|
632
|
+
Inputs: AgentInputField[];
|
|
633
|
+
Outputs: AgentOutputField[];
|
|
634
|
+
MaxOutputItems: number;
|
|
635
|
+
};
|
|
636
|
+
Readiness: {
|
|
637
|
+
Ready: boolean;
|
|
638
|
+
Issues: Array<{ Code: string; Path: string; Message: string }>;
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
declare type AgentExecuteOptions = {
|
|
643
|
+
/** Values keyed by input `Key`, as declared in the contract. */
|
|
644
|
+
inputData: Record<string, AgentInputValue>;
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
/** More statuses may be added; treat any status other than `Completed` or `Failed` as still in progress. */
|
|
648
|
+
declare type AgentExecutionStatus = "Queued" | "NotStarted" | "Running" | "Completed" | "Failed" | (string & {});
|
|
649
|
+
|
|
650
|
+
/** What `execute` resolves with once the run is accepted, before it has finished. */
|
|
651
|
+
declare type AgentExecutionAccepted = {
|
|
652
|
+
ExecutionId: string;
|
|
653
|
+
Status: AgentExecutionStatus;
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
declare type AgentExecution = {
|
|
657
|
+
ExecutionId: string;
|
|
658
|
+
Status: AgentExecutionStatus;
|
|
659
|
+
Stage?: string;
|
|
660
|
+
/** Present on `Completed`: one row per item, keyed by output `Key`. */
|
|
661
|
+
Output?: { items: Array<Record<string, string | number | boolean>> };
|
|
662
|
+
/** Present on `Failed`. */
|
|
663
|
+
Error?: { Code: string; Retryable: boolean; Details?: unknown };
|
|
664
|
+
Warnings?: Array<Record<string, unknown>>;
|
|
665
|
+
CreatedAt?: string;
|
|
666
|
+
StartedAt?: string;
|
|
667
|
+
CompletedAt?: string;
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* How an Agent call fails: `error` is the message text and `errorCode` either the platform code
|
|
672
|
+
* (`KISSFLOW_ERROR_…`) or an `AGENT_…` code, including `AGENT_HOST_TIMEOUT`, `AGENT_REQUEST_NOT_SENT`,
|
|
673
|
+
* `AGENT_EXECUTE_OUTCOME_UNKNOWN` (a run may have started), `AGENT_EXECUTE_NOT_SENT` (no run started),
|
|
674
|
+
* `AGENT_HOST_UNSUPPORTED`, `AGENT_WATCH_INVALID_EVENT`, `AGENT_OBSERVATION_STOPPED`, and from the host
|
|
675
|
+
* `AGENT_READ_TIMEOUT` and `AGENT_OFFLINE`. The list may grow; fall back to `error` for an unknown code.
|
|
676
|
+
* There is no `message`: read `error` for the text.
|
|
677
|
+
*/
|
|
678
|
+
declare type AgentError = {
|
|
679
|
+
isError: true;
|
|
680
|
+
error?: string;
|
|
681
|
+
errorCode?: string;
|
|
682
|
+
};
|
package/dist/snippets.json
CHANGED
|
@@ -20,6 +20,26 @@
|
|
|
20
20
|
"documentation": "Evaluates the provided data and returns back the matched output",
|
|
21
21
|
"insertText": "let decisionTableInstance = kf.app.getDecisionTable(\"${1:flowId}\");\n let decisionOutput = await decisionTableInstance.evaluate({ conditionField1: \"value\", conditionField2: \"value\" });"
|
|
22
22
|
},
|
|
23
|
+
{
|
|
24
|
+
"label": "run custom function",
|
|
25
|
+
"documentation": "Run a Custom Function; a Background function returns only RunId and Status: \"Queued\"",
|
|
26
|
+
"insertText": "let run = await kf.app.runFunction(\"${1:functionName}\", { ${2:key}: \"${3:value}\" });"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"label": "get custom function run",
|
|
30
|
+
"documentation": "Fetch a Custom Function run's status, and its Result once it has one",
|
|
31
|
+
"insertText": "let run = await kf.app.getFunctionRun(\"${1:runId}\");"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"label": "on custom function run complete",
|
|
35
|
+
"documentation": "Called once when a Background run reaches Success, Failed or TimedOut; the returned function unsubscribes",
|
|
36
|
+
"insertText": "let stop = kf.app.onFunctionRunComplete(\"${1:runId}\", (run) => {\n\t${2:// run.Status, run.Result}\n}, (err) => {\n\t${3:// err.error}\n});"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"label": "run custom agent",
|
|
40
|
+
"documentation": "Runs a published Custom Agent of this app and handles its result when it finishes",
|
|
41
|
+
"insertText": "let agentInstance = kf.app.getAgent(\"${1:agentId}\");\n let { ExecutionId } = await agentInstance.execute({ inputData: { ${2:inputKey}: ${3:value} } });\n let stopWatching = agentInstance.onExecutionComplete(ExecutionId, (execution) => { let items = execution.Output?.items; }, (error) => console.warn(error.errorCode));"
|
|
42
|
+
},
|
|
23
43
|
{
|
|
24
44
|
"label": "get local variable",
|
|
25
45
|
"documentation": "Get value of the local variable",
|
|
@@ -190,4 +210,4 @@
|
|
|
190
210
|
"insertText": "let payload = {}:\nkf.api(`/process/2/${kf.account._id}/${1:processId}/`, {\n\tmethod: \"POST\",\n\tbody: JSON.stringify(payload)\n})\n.then((resp) => {${2}})\n.catch((err) => {${3}})"
|
|
191
211
|
}
|
|
192
212
|
]
|
|
193
|
-
}
|
|
213
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kissflow/lowcode-client-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.51",
|
|
4
4
|
"description": "JavaScript SDK for developing over the Kissflow lowcode platform",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"customBuild": "node custom.build.mjs",
|
|
45
45
|
"build": "pnpm run customBuild",
|
|
46
46
|
"serve": "http-server -p 8080",
|
|
47
|
-
"publish-canary": "pnpm publish --tag canary"
|
|
47
|
+
"publish-canary": "pnpm publish --tag canary",
|
|
48
|
+
"pretest": "pnpm run build",
|
|
49
|
+
"test": "node --test \"test/*.test.mjs\""
|
|
48
50
|
}
|
|
49
51
|
}
|