@rise-x/apps-sdk 0.6.0
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/LICENSE +1 -0
- package/README.md +553 -0
- package/build/_internal.d.ts +2 -0
- package/build/_internal.js +23 -0
- package/build/accessors.d.ts +8 -0
- package/build/accessors.js +40 -0
- package/build/cli/index.d.ts +13 -0
- package/build/cli/index.js +54 -0
- package/build/cli/init.d.ts +6 -0
- package/build/cli/init.js +179 -0
- package/build/cli/templating.d.ts +2 -0
- package/build/cli/templating.js +84 -0
- package/build/connectors/agents.d.ts +85 -0
- package/build/connectors/agents.js +404 -0
- package/build/connectors/assets.d.ts +76 -0
- package/build/connectors/assets.js +204 -0
- package/build/connectors/deps.d.ts +4 -0
- package/build/connectors/deps.js +2 -0
- package/build/connectors/errors.d.ts +11 -0
- package/build/connectors/errors.js +67 -0
- package/build/connectors/flows.d.ts +37 -0
- package/build/connectors/flows.js +191 -0
- package/build/connectors/index.d.ts +8 -0
- package/build/connectors/index.js +50 -0
- package/build/connectors/sse.d.ts +12 -0
- package/build/connectors/sse.js +157 -0
- package/build/connectors/types.d.ts +285 -0
- package/build/connectors/types.js +419 -0
- package/build/connectors/work.d.ts +84 -0
- package/build/connectors/work.js +224 -0
- package/build/hooks.d.ts +4 -0
- package/build/hooks.js +28 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +34 -0
- package/build/lifecycle.d.ts +23 -0
- package/build/lifecycle.js +6 -0
- package/build/mockShell.d.ts +10 -0
- package/build/mockShell.js +55 -0
- package/build/query/agents.d.ts +80 -0
- package/build/query/agents.js +143 -0
- package/build/query/assets.d.ts +73 -0
- package/build/query/assets.js +152 -0
- package/build/query/client.d.ts +5 -0
- package/build/query/client.js +68 -0
- package/build/query/context.d.ts +2 -0
- package/build/query/context.js +34 -0
- package/build/query/flows.d.ts +54 -0
- package/build/query/flows.js +81 -0
- package/build/query/index.d.ts +10 -0
- package/build/query/index.js +85 -0
- package/build/query/keys.d.ts +51 -0
- package/build/query/keys.js +79 -0
- package/build/query/layer.d.ts +175 -0
- package/build/query/layer.js +35 -0
- package/build/query/shared.d.ts +43 -0
- package/build/query/shared.js +116 -0
- package/build/query/work.d.ts +75 -0
- package/build/query/work.js +172 -0
- package/build/shell/index.d.ts +1 -0
- package/build/shell/index.js +6 -0
- package/build/shell/installShellBridge.d.ts +11 -0
- package/build/shell/installShellBridge.js +104 -0
- package/build/shellBridge.d.ts +36 -0
- package/build/shellBridge.js +10 -0
- package/build/topBar.d.ts +25 -0
- package/build/topBar.js +17 -0
- package/build/ui/components/ai.d.ts +49 -0
- package/build/ui/components/alert-dialog.d.ts +27 -0
- package/build/ui/components/alert.d.ts +14 -0
- package/build/ui/components/avatar.d.ts +17 -0
- package/build/ui/components/badge.d.ts +19 -0
- package/build/ui/components/button.d.ts +13 -0
- package/build/ui/components/calendar.d.ts +21 -0
- package/build/ui/components/card.d.ts +16 -0
- package/build/ui/components/chart.d.ts +124 -0
- package/build/ui/components/checkbox.d.ts +4 -0
- package/build/ui/components/data-table.d.ts +70 -0
- package/build/ui/components/dialog.d.ts +17 -0
- package/build/ui/components/dropdown-menu.d.ts +29 -0
- package/build/ui/components/empty-state.d.ts +7 -0
- package/build/ui/components/file-upload.d.ts +17 -0
- package/build/ui/components/input.d.ts +8 -0
- package/build/ui/components/label.d.ts +4 -0
- package/build/ui/components/list.d.ts +24 -0
- package/build/ui/components/map.d.ts +26 -0
- package/build/ui/components/message.d.ts +24 -0
- package/build/ui/components/nav.d.ts +12 -0
- package/build/ui/components/page-header.d.ts +27 -0
- package/build/ui/components/popover.d.ts +10 -0
- package/build/ui/components/progress.d.ts +4 -0
- package/build/ui/components/radio.d.ts +6 -0
- package/build/ui/components/resizable.d.ts +7 -0
- package/build/ui/components/scroll-area.d.ts +5 -0
- package/build/ui/components/segmented.d.ts +6 -0
- package/build/ui/components/select.d.ts +15 -0
- package/build/ui/components/separator.d.ts +4 -0
- package/build/ui/components/sheet.d.ts +14 -0
- package/build/ui/components/skeleton.d.ts +3 -0
- package/build/ui/components/slider.d.ts +15 -0
- package/build/ui/components/snackbar.d.ts +3 -0
- package/build/ui/components/sonner.d.ts +4 -0
- package/build/ui/components/spinner.d.ts +5 -0
- package/build/ui/components/statistic.d.ts +19 -0
- package/build/ui/components/stepper.d.ts +12 -0
- package/build/ui/components/switch.d.ts +6 -0
- package/build/ui/components/table.d.ts +24 -0
- package/build/ui/components/textarea.d.ts +3 -0
- package/build/ui/components/timeline.d.ts +15 -0
- package/build/ui/components/toggle-group.d.ts +10 -0
- package/build/ui/components/toggle.d.ts +9 -0
- package/build/ui/components/tooltip.d.ts +7 -0
- package/build/ui/index.d.ts +46 -0
- package/build/ui/index.js +8 -0
- package/build/ui/lib/utils.d.ts +2 -0
- package/build/ui/reference/README.md +11 -0
- package/build/ui/reference/components/ai.tsx +291 -0
- package/build/ui/reference/components/alert-dialog.tsx +208 -0
- package/build/ui/reference/components/alert.tsx +112 -0
- package/build/ui/reference/components/avatar.tsx +158 -0
- package/build/ui/reference/components/badge.tsx +160 -0
- package/build/ui/reference/components/button.tsx +100 -0
- package/build/ui/reference/components/calendar.tsx +119 -0
- package/build/ui/reference/components/card.tsx +144 -0
- package/build/ui/reference/components/chart.tsx +1394 -0
- package/build/ui/reference/components/checkbox.tsx +44 -0
- package/build/ui/reference/components/data-table.tsx +480 -0
- package/build/ui/reference/components/dialog.tsx +172 -0
- package/build/ui/reference/components/dropdown-menu.tsx +245 -0
- package/build/ui/reference/components/empty-state.tsx +63 -0
- package/build/ui/reference/components/file-upload.tsx +116 -0
- package/build/ui/reference/components/input.tsx +114 -0
- package/build/ui/reference/components/label.tsx +19 -0
- package/build/ui/reference/components/list.tsx +191 -0
- package/build/ui/reference/components/map.css +251 -0
- package/build/ui/reference/components/map.tsx +294 -0
- package/build/ui/reference/components/message.tsx +171 -0
- package/build/ui/reference/components/nav.tsx +113 -0
- package/build/ui/reference/components/page-header.tsx +213 -0
- package/build/ui/reference/components/popover.tsx +76 -0
- package/build/ui/reference/components/progress.tsx +31 -0
- package/build/ui/reference/components/radio.tsx +65 -0
- package/build/ui/reference/components/resizable.tsx +40 -0
- package/build/ui/reference/components/scroll-area.tsx +55 -0
- package/build/ui/reference/components/segmented.tsx +45 -0
- package/build/ui/reference/components/select.tsx +185 -0
- package/build/ui/reference/components/separator.tsx +26 -0
- package/build/ui/reference/components/sheet.tsx +173 -0
- package/build/ui/reference/components/skeleton.tsx +15 -0
- package/build/ui/reference/components/slider.tsx +161 -0
- package/build/ui/reference/components/snackbar.tsx +27 -0
- package/build/ui/reference/components/sonner.tsx +43 -0
- package/build/ui/reference/components/spinner.tsx +27 -0
- package/build/ui/reference/components/statistic.tsx +122 -0
- package/build/ui/reference/components/stepper.tsx +138 -0
- package/build/ui/reference/components/switch.tsx +47 -0
- package/build/ui/reference/components/table.tsx +233 -0
- package/build/ui/reference/components/textarea.tsx +28 -0
- package/build/ui/reference/components/timeline.tsx +94 -0
- package/build/ui/reference/components/toggle-group.tsx +86 -0
- package/build/ui/reference/components/toggle.tsx +46 -0
- package/build/ui/reference/components/tooltip.tsx +53 -0
- package/build/ui/reference/index.ts +49 -0
- package/build/ui/reference/lib/utils.ts +34 -0
- package/build/ui/standalone-stub.js +5 -0
- package/build/ui/standalone.js +135 -0
- package/build/ui/styles.css +3 -0
- package/connectors/package.json +8 -0
- package/package.json +114 -0
- package/query/package.json +8 -0
- package/shell/package.json +8 -0
- package/template/AGENTS.md +70 -0
- package/template/CLAUDE.md +4 -0
- package/template/README.md +102 -0
- package/template/_gitignore +6 -0
- package/template/commitlint.config.js +12 -0
- package/template/package.json +31 -0
- package/template/public/index.html +13 -0
- package/template/src/App.tsx +171 -0
- package/template/src/bootstrap.tsx +13 -0
- package/template/src/index.tsx +1 -0
- package/template/src/lifecycle.ts +20 -0
- package/template/tsconfig.json +31 -0
- package/template/webpack.config.js +112 -0
- package/template/webpack.local.config.js +68 -0
- package/ui/package.json +8 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ConnectorErrorCode = "SHELL_UNAVAILABLE" | "SHELL_TOO_OLD" | "AI_UNAVAILABLE" | "HTTP_ERROR" | "NOT_FOUND" | "ABORTED" | "NETWORK_ERROR" | "PARSE_ERROR" | "INVALID_ARG";
|
|
2
|
+
export declare class ConnectorError extends Error {
|
|
3
|
+
readonly code: ConnectorErrorCode;
|
|
4
|
+
readonly status?: number;
|
|
5
|
+
readonly cause?: unknown;
|
|
6
|
+
constructor(code: ConnectorErrorCode, message: string, opts?: {
|
|
7
|
+
status?: number;
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export declare function toConnectorError(e: unknown): ConnectorError;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectorError = void 0;
|
|
4
|
+
exports.toConnectorError = toConnectorError;
|
|
5
|
+
class ConnectorError extends Error {
|
|
6
|
+
constructor(code, message, opts = {}) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "ConnectorError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = opts.status;
|
|
11
|
+
this.cause = opts.cause;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ConnectorError = ConnectorError;
|
|
15
|
+
function isAxiosErrorLike(e) {
|
|
16
|
+
return (typeof e === "object" &&
|
|
17
|
+
e !== null &&
|
|
18
|
+
e.isAxiosError === true);
|
|
19
|
+
}
|
|
20
|
+
function isAbortLike(e) {
|
|
21
|
+
if (typeof e !== "object" || e === null)
|
|
22
|
+
return false;
|
|
23
|
+
const name = e.name;
|
|
24
|
+
// fetch/axios abort both surface as DOMException-style AbortError/CanceledError.
|
|
25
|
+
return name === "AbortError" || name === "CanceledError";
|
|
26
|
+
}
|
|
27
|
+
// Pull a human-readable message out of an HTTP error body without trusting its
|
|
28
|
+
// shape — API error envelopes vary between v3 and v4.
|
|
29
|
+
function httpMessage(e) {
|
|
30
|
+
const data = e.response?.data;
|
|
31
|
+
if (typeof data?.message === "string" && data.message)
|
|
32
|
+
return data.message;
|
|
33
|
+
if (typeof data?.error === "string" && data.error)
|
|
34
|
+
return data.error;
|
|
35
|
+
return (e.response?.statusText ||
|
|
36
|
+
e.message ||
|
|
37
|
+
`request failed with status ${e.response?.status}`);
|
|
38
|
+
}
|
|
39
|
+
// Normalize anything thrown while talking to the platform into a ConnectorError.
|
|
40
|
+
// ConnectorError instances pass through unchanged; the original error is always
|
|
41
|
+
// preserved on `cause`.
|
|
42
|
+
function toConnectorError(e) {
|
|
43
|
+
if (e instanceof ConnectorError)
|
|
44
|
+
return e;
|
|
45
|
+
if (isAxiosErrorLike(e)) {
|
|
46
|
+
if (e.code === "ERR_CANCELED" || isAbortLike(e)) {
|
|
47
|
+
return new ConnectorError("ABORTED", "request aborted", { cause: e });
|
|
48
|
+
}
|
|
49
|
+
const status = e.response?.status;
|
|
50
|
+
if (status !== undefined) {
|
|
51
|
+
return new ConnectorError(status === 404 ? "NOT_FOUND" : "HTTP_ERROR", httpMessage(e), {
|
|
52
|
+
status,
|
|
53
|
+
cause: e,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return new ConnectorError("NETWORK_ERROR", e.message || "request failed without a response", {
|
|
57
|
+
cause: e,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (isAbortLike(e)) {
|
|
61
|
+
return new ConnectorError("ABORTED", "request aborted", { cause: e });
|
|
62
|
+
}
|
|
63
|
+
// Anything else thrown mid-request (e.g. fetch's TypeError on network
|
|
64
|
+
// failure) — the request did not produce a response.
|
|
65
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
66
|
+
return new ConnectorError("NETWORK_ERROR", message, { cause: e });
|
|
67
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ConnectorDeps } from "./deps";
|
|
2
|
+
import { type Flow, type FlowAction, type FlowConfig, type FlowStatus, type FlowStep, type FlowSummary, type Layout, type LayoutField } from "./types";
|
|
3
|
+
export interface ListFlowsArgs {
|
|
4
|
+
search?: string;
|
|
5
|
+
statuses?: FlowStatus[];
|
|
6
|
+
flowType?: string;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
export interface FindTaskArgs {
|
|
10
|
+
flow: string;
|
|
11
|
+
task: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface FindTaskResult {
|
|
15
|
+
flow: Flow;
|
|
16
|
+
step: FlowStep;
|
|
17
|
+
task: FlowAction;
|
|
18
|
+
}
|
|
19
|
+
export interface FlowsConnector {
|
|
20
|
+
list(args?: ListFlowsArgs): Promise<FlowSummary[]>;
|
|
21
|
+
get(flowId: string, opts?: {
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}): Promise<Flow>;
|
|
24
|
+
findTask(args: FindTaskArgs): Promise<FindTaskResult | null>;
|
|
25
|
+
findTaskIn(flow: Flow, taskRef: string): FindTaskResult | null;
|
|
26
|
+
flattenLayoutFields(layout: Layout): LayoutField[];
|
|
27
|
+
getConfig(flowId: string, opts?: {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}): Promise<FlowConfig>;
|
|
30
|
+
getLayout(layoutId: string, opts?: {
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): Promise<Layout>;
|
|
33
|
+
}
|
|
34
|
+
export declare function findTaskIn(flow: Flow, taskRef: string): FindTaskResult | null;
|
|
35
|
+
export declare function flattenLayoutFields(layout: Layout): LayoutField[];
|
|
36
|
+
export declare function createFlowsConnector(deps?: ConnectorDeps): FlowsConnector;
|
|
37
|
+
export declare const flows: FlowsConnector;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flows = void 0;
|
|
4
|
+
exports.findTaskIn = findTaskIn;
|
|
5
|
+
exports.flattenLayoutFields = flattenLayoutFields;
|
|
6
|
+
exports.createFlowsConnector = createFlowsConnector;
|
|
7
|
+
const _internal_1 = require("../_internal");
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const matches = (ref, id, name, displayName) => ref === id || ref === name || displayName.toLowerCase() === ref.toLowerCase();
|
|
11
|
+
// Depth-first search across nested steps for a step action ("task") matching
|
|
12
|
+
// by id, exact name, or case-insensitive displayName.
|
|
13
|
+
function findTaskIn(flow, taskRef) {
|
|
14
|
+
const walk = (steps) => {
|
|
15
|
+
for (const step of steps) {
|
|
16
|
+
for (const action of step.actions) {
|
|
17
|
+
if (matches(taskRef, action.id, action.name, action.displayName)) {
|
|
18
|
+
return { flow, step, task: action };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const nested = walk(step.steps);
|
|
22
|
+
if (nested)
|
|
23
|
+
return nested;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
return walk(flow.steps);
|
|
28
|
+
}
|
|
29
|
+
// Container components whose children are the actual form fields.
|
|
30
|
+
const SECTION_TYPES = new Set(["section", "subsection", "section-repeater"]);
|
|
31
|
+
// Flatten a layout's component tree into leaf form fields with data paths into
|
|
32
|
+
// the work item's data document.
|
|
33
|
+
function flattenLayoutFields(layout) {
|
|
34
|
+
const out = [];
|
|
35
|
+
const walk = (nodes) => {
|
|
36
|
+
for (const component of nodes ?? []) {
|
|
37
|
+
if (SECTION_TYPES.has(component.component)) {
|
|
38
|
+
walk(component.components);
|
|
39
|
+
}
|
|
40
|
+
else if (component.dataPath) {
|
|
41
|
+
out.push({
|
|
42
|
+
label: component.label || component.name || component.dataPath,
|
|
43
|
+
type: component.component,
|
|
44
|
+
dataPath: component.dataPath,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
walk(layout.components);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function createFlowsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
53
|
+
const list = async (args = {}) => {
|
|
54
|
+
try {
|
|
55
|
+
const shell = deps.shell();
|
|
56
|
+
const flowType = args.flowType ?? shell.getEnvironment()?.slug;
|
|
57
|
+
if (!flowType) {
|
|
58
|
+
throw new errors_1.ConnectorError("SHELL_UNAVAILABLE", "environment is not ready yet — pass flowType explicitly or retry after the shell reports an environment");
|
|
59
|
+
}
|
|
60
|
+
const statuses = args.statuses ?? ["Active"];
|
|
61
|
+
const { data } = await shell
|
|
62
|
+
.getApi()
|
|
63
|
+
.get("/api/v3/flow/search", {
|
|
64
|
+
params: { flowType, flowStatuses: statuses.join(",") },
|
|
65
|
+
signal: args.signal,
|
|
66
|
+
});
|
|
67
|
+
let result = (Array.isArray(data) ? data : []).map(types_1.mapFlowSummary);
|
|
68
|
+
if (args.search) {
|
|
69
|
+
const needle = args.search.toLowerCase();
|
|
70
|
+
result = result.filter((f) => f.name.toLowerCase().includes(needle) ||
|
|
71
|
+
f.displayName.toLowerCase().includes(needle));
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
// Resolve a flow ref (flowOriginId, or any version's concrete id) to the
|
|
80
|
+
// latest published version's concrete id. `GET /flow/{ref}?v=latest` is the
|
|
81
|
+
// one v3 endpoint that re-resolves through the flow's origin id; the steps
|
|
82
|
+
// and v4 config endpoints instead read their ref as a concrete document id
|
|
83
|
+
// first — and an origin id equals version 1's document id, so they silently
|
|
84
|
+
// serve version 1 for flows with later versions.
|
|
85
|
+
const resolveLatestFlowId = async (flowRef, signal) => {
|
|
86
|
+
const { data } = await deps
|
|
87
|
+
.shell()
|
|
88
|
+
.getApi()
|
|
89
|
+
.get(`/api/v3/flow/${flowRef}`, {
|
|
90
|
+
params: { v: "latest" },
|
|
91
|
+
signal,
|
|
92
|
+
});
|
|
93
|
+
const id = data?.id;
|
|
94
|
+
return typeof id === "string" && id !== "" ? id : flowRef;
|
|
95
|
+
};
|
|
96
|
+
const get = async (flowId, opts = {}) => {
|
|
97
|
+
try {
|
|
98
|
+
const api = deps.shell().getApi();
|
|
99
|
+
const getSteps = (ref) => api.get("/api/v3/flow/steps", {
|
|
100
|
+
params: { flowReference: ref },
|
|
101
|
+
signal: opts.signal,
|
|
102
|
+
});
|
|
103
|
+
const [flowResponse, stepsResponse] = await Promise.all([
|
|
104
|
+
api.get(`/api/v3/flow/${flowId}`, {
|
|
105
|
+
params: { v: "latest" },
|
|
106
|
+
signal: opts.signal,
|
|
107
|
+
}),
|
|
108
|
+
getSteps(flowId),
|
|
109
|
+
]);
|
|
110
|
+
const raw = flowResponse.data ?? {};
|
|
111
|
+
// The flow fetch resolved the ref to the latest version; the steps
|
|
112
|
+
// fetch did not (see resolveLatestFlowId). When the resolved id
|
|
113
|
+
// differs from the ref, refetch steps so the step tree matches the
|
|
114
|
+
// flow version we return.
|
|
115
|
+
const resolvedId = typeof raw.id === "string" ? raw.id : "";
|
|
116
|
+
const stepsData = resolvedId && resolvedId !== flowId
|
|
117
|
+
? (await getSteps(resolvedId)).data
|
|
118
|
+
: stepsResponse.data;
|
|
119
|
+
const steps = Array.isArray(stepsData) ? stepsData : [];
|
|
120
|
+
return (0, types_1.mapFlow)(raw, steps);
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const findTask = async ({ flow: flowRef, task, signal, }) => {
|
|
127
|
+
const all = await list({ signal });
|
|
128
|
+
let summary = all.find((f) => matches(flowRef, f.id, f.name, f.displayName));
|
|
129
|
+
if (!summary) {
|
|
130
|
+
// Not in the active listing — the ref may still be a valid flow id
|
|
131
|
+
// (archived flow, different flowType). Try a direct fetch.
|
|
132
|
+
try {
|
|
133
|
+
const direct = await get(flowRef, { signal });
|
|
134
|
+
return findTaskIn(direct, task);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
if (e instanceof errors_1.ConnectorError && e.code === "NOT_FOUND")
|
|
138
|
+
return null;
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const flow = await get(summary.id, { signal });
|
|
143
|
+
return findTaskIn(flow, task);
|
|
144
|
+
};
|
|
145
|
+
const getConfig = async (flowId, opts = {}) => {
|
|
146
|
+
try {
|
|
147
|
+
const configApi = deps.shell().getApiV4("config");
|
|
148
|
+
const getForId = (ref) => configApi.get(`/api/v4/config/flow/${ref}`, {
|
|
149
|
+
signal: opts.signal,
|
|
150
|
+
});
|
|
151
|
+
// v4 flow grains are keyed by concrete version ids and an origin id
|
|
152
|
+
// activates version 1's grain (see resolveLatestFlowId). Resolve in
|
|
153
|
+
// parallel with the optimistic fetch; refetch only when the ref was
|
|
154
|
+
// not already the latest concrete id.
|
|
155
|
+
const [resolvedId, firstResponse] = await Promise.all([
|
|
156
|
+
resolveLatestFlowId(flowId, opts.signal),
|
|
157
|
+
getForId(flowId),
|
|
158
|
+
]);
|
|
159
|
+
const { data } = resolvedId !== flowId ? await getForId(resolvedId) : firstResponse;
|
|
160
|
+
return (0, types_1.mapFlowConfig)(resolvedId, data ?? {});
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const getLayout = async (layoutId, opts = {}) => {
|
|
167
|
+
try {
|
|
168
|
+
const { data } = await deps
|
|
169
|
+
.shell()
|
|
170
|
+
.getApiV4("config")
|
|
171
|
+
.get(`/api/v4/config/layout/${layoutId}`, {
|
|
172
|
+
signal: opts.signal,
|
|
173
|
+
});
|
|
174
|
+
return (0, types_1.mapLayout)(layoutId, data ?? {});
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
list,
|
|
182
|
+
get,
|
|
183
|
+
findTask,
|
|
184
|
+
findTaskIn,
|
|
185
|
+
flattenLayoutFields,
|
|
186
|
+
getConfig,
|
|
187
|
+
getLayout,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// Ready-made singleton bound to the live shell bridge.
|
|
191
|
+
exports.flows = createFlowsConnector();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { ConnectorDeps } from "./deps";
|
|
2
|
+
export { ConnectorError, toConnectorError, type ConnectorErrorCode, } from "./errors";
|
|
3
|
+
export { createSseParser, iterateSseResponse, type SseEvent, type SseParser, } from "./sse";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export { createFlowsConnector, findTaskIn, flattenLayoutFields, flows, type FindTaskArgs, type FindTaskResult, type FlowsConnector, type ListFlowsArgs, } from "./flows";
|
|
6
|
+
export { createWorkConnector, work, type FlowRef, type IterateWorkRowsArgs, type ListRelatedWorkArgs, type ListWorkRowsArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkPatchOperation, type WorkRowPage, } from "./work";
|
|
7
|
+
export { ASSET_TARGET_DATA_TYPES, assets, createAssetsConnector, type AssetRowPage, type AssetsConnector, type AssetTypeRef, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type ListRelatedAssetsArgs, type SearchAssetsArgs, type StartEditAssetArgs, } from "./assets";
|
|
8
|
+
export { agentEndReason, agentErrorText, agentMessageText, agents, collectAgentReply, createAgentsConnector, streamAgentReply, type AgentChatSession, type AgentReplyState, type AgentsConnector, type GetChatMessagesArgs, type ListAgentsArgs, type ListChatsArgs, type RunAgentArgs, type SendChatArgs, } from "./agents";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @rise-x/apps-sdk/connectors — typed, higher-level wrappers over the shell's
|
|
3
|
+
// raw API clients so apps stop hand-rolling multi-step API dances.
|
|
4
|
+
//
|
|
5
|
+
// Ready-made singletons (bound to the live bridge): `flows`, `work`, `assets`,
|
|
6
|
+
// `agents`.
|
|
7
|
+
// Factories accept a custom shell resolver for tests/standalone dev.
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.streamAgentReply = exports.createAgentsConnector = exports.collectAgentReply = exports.agents = exports.agentMessageText = exports.agentErrorText = exports.agentEndReason = exports.createAssetsConnector = exports.assets = exports.ASSET_TARGET_DATA_TYPES = exports.work = exports.createWorkConnector = exports.flows = exports.flattenLayoutFields = exports.findTaskIn = exports.createFlowsConnector = exports.iterateSseResponse = exports.createSseParser = exports.toConnectorError = exports.ConnectorError = void 0;
|
|
24
|
+
var errors_1 = require("./errors");
|
|
25
|
+
Object.defineProperty(exports, "ConnectorError", { enumerable: true, get: function () { return errors_1.ConnectorError; } });
|
|
26
|
+
Object.defineProperty(exports, "toConnectorError", { enumerable: true, get: function () { return errors_1.toConnectorError; } });
|
|
27
|
+
var sse_1 = require("./sse");
|
|
28
|
+
Object.defineProperty(exports, "createSseParser", { enumerable: true, get: function () { return sse_1.createSseParser; } });
|
|
29
|
+
Object.defineProperty(exports, "iterateSseResponse", { enumerable: true, get: function () { return sse_1.iterateSseResponse; } });
|
|
30
|
+
__exportStar(require("./types"), exports);
|
|
31
|
+
var flows_1 = require("./flows");
|
|
32
|
+
Object.defineProperty(exports, "createFlowsConnector", { enumerable: true, get: function () { return flows_1.createFlowsConnector; } });
|
|
33
|
+
Object.defineProperty(exports, "findTaskIn", { enumerable: true, get: function () { return flows_1.findTaskIn; } });
|
|
34
|
+
Object.defineProperty(exports, "flattenLayoutFields", { enumerable: true, get: function () { return flows_1.flattenLayoutFields; } });
|
|
35
|
+
Object.defineProperty(exports, "flows", { enumerable: true, get: function () { return flows_1.flows; } });
|
|
36
|
+
var work_1 = require("./work");
|
|
37
|
+
Object.defineProperty(exports, "createWorkConnector", { enumerable: true, get: function () { return work_1.createWorkConnector; } });
|
|
38
|
+
Object.defineProperty(exports, "work", { enumerable: true, get: function () { return work_1.work; } });
|
|
39
|
+
var assets_1 = require("./assets");
|
|
40
|
+
Object.defineProperty(exports, "ASSET_TARGET_DATA_TYPES", { enumerable: true, get: function () { return assets_1.ASSET_TARGET_DATA_TYPES; } });
|
|
41
|
+
Object.defineProperty(exports, "assets", { enumerable: true, get: function () { return assets_1.assets; } });
|
|
42
|
+
Object.defineProperty(exports, "createAssetsConnector", { enumerable: true, get: function () { return assets_1.createAssetsConnector; } });
|
|
43
|
+
var agents_1 = require("./agents");
|
|
44
|
+
Object.defineProperty(exports, "agentEndReason", { enumerable: true, get: function () { return agents_1.agentEndReason; } });
|
|
45
|
+
Object.defineProperty(exports, "agentErrorText", { enumerable: true, get: function () { return agents_1.agentErrorText; } });
|
|
46
|
+
Object.defineProperty(exports, "agentMessageText", { enumerable: true, get: function () { return agents_1.agentMessageText; } });
|
|
47
|
+
Object.defineProperty(exports, "agents", { enumerable: true, get: function () { return agents_1.agents; } });
|
|
48
|
+
Object.defineProperty(exports, "collectAgentReply", { enumerable: true, get: function () { return agents_1.collectAgentReply; } });
|
|
49
|
+
Object.defineProperty(exports, "createAgentsConnector", { enumerable: true, get: function () { return agents_1.createAgentsConnector; } });
|
|
50
|
+
Object.defineProperty(exports, "streamAgentReply", { enumerable: true, get: function () { return agents_1.streamAgentReply; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SseEvent {
|
|
2
|
+
event?: string;
|
|
3
|
+
id?: string;
|
|
4
|
+
data: string;
|
|
5
|
+
retry?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SseParser {
|
|
8
|
+
feed(chunk: string): void;
|
|
9
|
+
end(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createSseParser(onEvent: (event: SseEvent) => void): SseParser;
|
|
12
|
+
export declare function iterateSseResponse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseEvent, void, unknown>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSseParser = createSseParser;
|
|
4
|
+
exports.iterateSseResponse = iterateSseResponse;
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
// Incremental SSE parser per the WHATWG EventSource framing rules (minus the
|
|
7
|
+
// reconnect machinery). Unlike a per-chunk regex, this survives events split
|
|
8
|
+
// across network chunks, multi-line `data:` payloads, CRLF / lone-CR framing,
|
|
9
|
+
// arbitrary field order, and comment lines.
|
|
10
|
+
function createSseParser(onEvent) {
|
|
11
|
+
let buffer = "";
|
|
12
|
+
// A CR at a chunk boundary terminates its line immediately (spec tokenizer);
|
|
13
|
+
// when the next chunk starts with LF, that LF is the second half of a CRLF
|
|
14
|
+
// pair and must be swallowed, not treated as another terminator.
|
|
15
|
+
let skipNextLf = false;
|
|
16
|
+
let dataLines = [];
|
|
17
|
+
let eventType;
|
|
18
|
+
// Per spec the last seen id persists across events until overwritten.
|
|
19
|
+
let lastId;
|
|
20
|
+
let retry;
|
|
21
|
+
const dispatch = () => {
|
|
22
|
+
// A block with no data lines dispatches nothing (spec) — reset type only.
|
|
23
|
+
if (dataLines.length === 0) {
|
|
24
|
+
eventType = undefined;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const evt = { data: dataLines.join("\n") };
|
|
28
|
+
if (eventType)
|
|
29
|
+
evt.event = eventType;
|
|
30
|
+
if (lastId !== undefined)
|
|
31
|
+
evt.id = lastId;
|
|
32
|
+
if (retry !== undefined)
|
|
33
|
+
evt.retry = retry;
|
|
34
|
+
dataLines = [];
|
|
35
|
+
eventType = undefined;
|
|
36
|
+
onEvent(evt);
|
|
37
|
+
};
|
|
38
|
+
const processLine = (line) => {
|
|
39
|
+
if (line === "") {
|
|
40
|
+
dispatch();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (line.startsWith(":"))
|
|
44
|
+
return; // comment
|
|
45
|
+
let field;
|
|
46
|
+
let value;
|
|
47
|
+
const colon = line.indexOf(":");
|
|
48
|
+
if (colon === -1) {
|
|
49
|
+
field = line;
|
|
50
|
+
value = "";
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
field = line.slice(0, colon);
|
|
54
|
+
value = line.slice(colon + 1);
|
|
55
|
+
if (value.startsWith(" "))
|
|
56
|
+
value = value.slice(1);
|
|
57
|
+
}
|
|
58
|
+
switch (field) {
|
|
59
|
+
case "data":
|
|
60
|
+
dataLines.push(value);
|
|
61
|
+
break;
|
|
62
|
+
case "event":
|
|
63
|
+
eventType = value;
|
|
64
|
+
break;
|
|
65
|
+
case "id":
|
|
66
|
+
if (!value.includes("\0"))
|
|
67
|
+
lastId = value;
|
|
68
|
+
break;
|
|
69
|
+
case "retry":
|
|
70
|
+
if (/^\d+$/.test(value))
|
|
71
|
+
retry = parseInt(value, 10);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
break; // unknown fields are ignored per spec
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
feed(chunk) {
|
|
79
|
+
// An empty chunk carries no framing; it must be a no-op that preserves a
|
|
80
|
+
// pending skipNextLf. Handling it before the skip block keeps a
|
|
81
|
+
// zero-length chunk arriving between a CR and its LF from consuming the
|
|
82
|
+
// skip flag and splitting one event into two.
|
|
83
|
+
if (chunk === "")
|
|
84
|
+
return;
|
|
85
|
+
let s = chunk;
|
|
86
|
+
if (skipNextLf) {
|
|
87
|
+
skipNextLf = false;
|
|
88
|
+
if (s.startsWith("\n"))
|
|
89
|
+
s = s.slice(1);
|
|
90
|
+
}
|
|
91
|
+
if (s === "")
|
|
92
|
+
return;
|
|
93
|
+
if (s.endsWith("\r"))
|
|
94
|
+
skipNextLf = true;
|
|
95
|
+
// buffer never contains CR/LF (it's the trailing unterminated line of the
|
|
96
|
+
// previous normalized chunk), so normalizing the new chunk alone is safe.
|
|
97
|
+
const normalized = s.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
98
|
+
const lines = (buffer + normalized).split("\n");
|
|
99
|
+
buffer = lines.pop();
|
|
100
|
+
for (const line of lines)
|
|
101
|
+
processLine(line);
|
|
102
|
+
},
|
|
103
|
+
end() {
|
|
104
|
+
// Flush servers that close without a final blank line: treat the pending
|
|
105
|
+
// buffer as a complete line, then dispatch whatever accumulated.
|
|
106
|
+
skipNextLf = false;
|
|
107
|
+
const remaining = buffer;
|
|
108
|
+
buffer = "";
|
|
109
|
+
if (remaining !== "")
|
|
110
|
+
processLine(remaining);
|
|
111
|
+
dispatch();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Async iteration over an SSE response body. Cancels the underlying reader when
|
|
116
|
+
// the consumer exits early (break / return / throw) and maps aborts to
|
|
117
|
+
// ConnectorError('ABORTED').
|
|
118
|
+
async function* iterateSseResponse(body, signal) {
|
|
119
|
+
const reader = body.getReader();
|
|
120
|
+
const decoder = new TextDecoder("utf-8");
|
|
121
|
+
const events = [];
|
|
122
|
+
const parser = createSseParser((e) => events.push(e));
|
|
123
|
+
try {
|
|
124
|
+
for (;;) {
|
|
125
|
+
if (signal?.aborted) {
|
|
126
|
+
throw new errors_1.ConnectorError("ABORTED", "stream aborted");
|
|
127
|
+
}
|
|
128
|
+
const { done, value } = await reader.read();
|
|
129
|
+
if (done) {
|
|
130
|
+
const tail = decoder.decode(); // flush a dangling multi-byte sequence
|
|
131
|
+
if (tail)
|
|
132
|
+
parser.feed(tail);
|
|
133
|
+
parser.end();
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
parser.feed(decoder.decode(value, { stream: true }));
|
|
137
|
+
}
|
|
138
|
+
while (events.length > 0)
|
|
139
|
+
yield events.shift();
|
|
140
|
+
if (done)
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
// Reached on early consumer exit as well — tear the connection down rather
|
|
149
|
+
// than leaving the reader (and the HTTP response) dangling.
|
|
150
|
+
try {
|
|
151
|
+
await reader.cancel();
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// already closed/errored — nothing to release
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|