@rise-x/apps-sdk 0.11.1 → 0.15.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/README.md +903 -19
- package/build/_internal.d.ts +4 -1
- package/build/_internal.js +67 -0
- package/build/cli/index.d.ts +7 -1
- package/build/cli/index.js +68 -14
- package/build/cli/scan.d.ts +60 -0
- package/build/cli/scan.js +725 -0
- package/build/cli/validate.d.ts +33 -0
- package/build/cli/validate.js +169 -0
- package/build/connectors/agents.d.ts +10 -6
- package/build/connectors/agents.js +59 -44
- package/build/connectors/attachments.d.ts +51 -0
- package/build/connectors/attachments.js +76 -0
- package/build/connectors/errors.js +24 -0
- package/build/connectors/flows.d.ts +13 -2
- package/build/connectors/flows.js +64 -19
- package/build/connectors/index.d.ts +5 -1
- package/build/connectors/index.js +14 -2
- package/build/connectors/integrations.d.ts +29 -0
- package/build/connectors/integrations.js +32 -0
- package/build/connectors/offline.d.ts +34 -0
- package/build/connectors/offline.js +135 -0
- package/build/connectors/readPolicy.d.ts +29 -0
- package/build/connectors/readPolicy.js +105 -0
- package/build/connectors/types.d.ts +75 -0
- package/build/connectors/types.js +128 -0
- package/build/connectors/vectorStores.d.ts +45 -0
- package/build/connectors/vectorStores.js +199 -0
- package/build/connectors/work.d.ts +14 -2
- package/build/connectors/work.js +43 -19
- package/build/dependencies/bound.d.ts +87 -0
- package/build/dependencies/bound.js +207 -0
- package/build/dependencies/index.d.ts +2 -0
- package/build/dependencies/index.js +13 -0
- package/build/dependencyRegistry.d.ts +15 -0
- package/build/dependencyRegistry.js +28 -0
- package/build/index.d.ts +2 -1
- package/build/index.js +12 -1
- package/build/lifecycle.d.ts +10 -1
- package/build/manifest.d.ts +69 -0
- package/build/manifest.js +229 -0
- package/build/manifestSource.d.ts +27 -0
- package/build/manifestSource.js +99 -0
- package/build/mockShell.d.ts +2 -0
- package/build/mockShell.js +13 -0
- package/build/query/client.js +9 -1
- package/build/query/dependencies.d.ts +22 -0
- package/build/query/dependencies.js +73 -0
- package/build/query/flows.d.ts +8 -8
- package/build/query/index.d.ts +1 -0
- package/build/query/index.js +4 -2
- package/build/query/layer.d.ts +9 -9
- package/build/query/shared.js +10 -0
- package/build/query/work.d.ts +4 -4
- package/build/rsbuild/index.d.ts +3 -1
- package/build/rsbuild/index.js +35 -1
- package/build/rsbuild/riseAppManifestPlugin.d.ts +19 -0
- package/build/rsbuild/riseAppManifestPlugin.js +79 -0
- package/build/shell/installShellBridge.d.ts +2 -0
- package/build/shell/installShellBridge.js +3 -1
- package/build/shellBridge.d.ts +233 -1
- package/build/shellBridge.js +8 -7
- package/build/ui/components/app-frame.d.ts +1 -1
- package/build/ui/demo.html +365 -360
- package/build/ui/shadcn.css +629 -0
- package/build/ui/standalone.js +16 -15
- package/build/ui/styles.css +1 -1
- package/build/ui/tailwind.css +12 -0
- package/build/ui/theme.css +412 -0
- package/build/ui/tw-animate.css +1 -0
- package/build/webpack/index.d.ts +1 -0
- package/build/webpack/index.js +7 -0
- package/build/webpack/riseAppManifestPlugin.d.ts +61 -0
- package/build/webpack/riseAppManifestPlugin.js +103 -0
- package/dependencies/package.json +8 -0
- package/package.json +17 -4
- package/template/AGENTS.md +34 -4
- package/template/README.md +85 -2
- package/template/package.json +4 -0
- package/template/rise-x-app.json +4 -0
- package/template/src/App.tsx +7 -17
- package/template/src/styles.css +5 -0
- package/webpack/package.json +8 -0
|
@@ -6,6 +6,7 @@ exports.flattenLayoutFields = flattenLayoutFields;
|
|
|
6
6
|
exports.createFlowsConnector = createFlowsConnector;
|
|
7
7
|
const _internal_1 = require("../_internal");
|
|
8
8
|
const errors_1 = require("./errors");
|
|
9
|
+
const readPolicy_1 = require("./readPolicy");
|
|
9
10
|
const types_1 = require("./types");
|
|
10
11
|
const matches = (ref, id, name, displayName) => ref === id || ref === name || displayName.toLowerCase() === ref.toLowerCase();
|
|
11
12
|
// Depth-first search across nested steps for a step action ("task") matching
|
|
@@ -28,8 +29,8 @@ function findTaskIn(flow, taskRef) {
|
|
|
28
29
|
}
|
|
29
30
|
// Container components whose children are the actual form fields.
|
|
30
31
|
const SECTION_TYPES = new Set(["section", "subsection", "section-repeater"]);
|
|
31
|
-
// Flatten a layout's component
|
|
32
|
-
// the work item's data document.
|
|
32
|
+
// Flatten a layout's component list into leaf form fields with data paths into
|
|
33
|
+
// the work item's data document (walks nested components when a node carries any).
|
|
33
34
|
function flattenLayoutFields(layout) {
|
|
34
35
|
const out = [];
|
|
35
36
|
const walk = (nodes) => {
|
|
@@ -49,6 +50,17 @@ function flattenLayoutFields(layout) {
|
|
|
49
50
|
walk(layout.components);
|
|
50
51
|
return out;
|
|
51
52
|
}
|
|
53
|
+
// The origin and version date off a raw cached flow config. `fromDate` is what the server orders
|
|
54
|
+
// versions by — `getFlowVersions` returns them FromDate ascending with the live one last — so
|
|
55
|
+
// ordering on it here answers with the version the network would have resolved to.
|
|
56
|
+
function flowVersionOf(config) {
|
|
57
|
+
const properties = config?.properties;
|
|
58
|
+
if (typeof properties?.originId !== "string")
|
|
59
|
+
return null;
|
|
60
|
+
const fromDate = properties.dianaVersion?.fromDate;
|
|
61
|
+
const from = typeof fromDate === "string" ? Date.parse(fromDate) : NaN;
|
|
62
|
+
return { originId: properties.originId, from: Number.isNaN(from) ? 0 : from };
|
|
63
|
+
}
|
|
52
64
|
function createFlowsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
53
65
|
const list = async (args = {}) => {
|
|
54
66
|
try {
|
|
@@ -142,41 +154,74 @@ function createFlowsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
142
154
|
const flow = await get(summary.id, { signal });
|
|
143
155
|
return findTaskIn(flow, task);
|
|
144
156
|
};
|
|
145
|
-
const getConfig =
|
|
146
|
-
|
|
157
|
+
const getConfig = (flowId, opts = {}) => (0, readPolicy_1.resolveRead)({
|
|
158
|
+
shell: deps.shell,
|
|
159
|
+
signal: opts.signal,
|
|
160
|
+
network: async (signal) => {
|
|
147
161
|
const configApi = deps.shell().getApiV4("config");
|
|
148
162
|
const getForId = (ref) => configApi.get(`/api/v4/config/flow/${ref}`, {
|
|
149
|
-
signal
|
|
163
|
+
signal,
|
|
150
164
|
});
|
|
151
165
|
// v4 flow grains are keyed by concrete version ids and an origin id
|
|
152
166
|
// activates version 1's grain (see resolveLatestFlowId). Resolve in
|
|
153
167
|
// parallel with the optimistic fetch; refetch only when the ref was
|
|
154
168
|
// not already the latest concrete id.
|
|
155
169
|
const [resolvedId, firstResponse] = await Promise.all([
|
|
156
|
-
resolveLatestFlowId(flowId,
|
|
170
|
+
resolveLatestFlowId(flowId, signal),
|
|
157
171
|
getForId(flowId),
|
|
158
172
|
]);
|
|
159
173
|
const { data } = resolvedId !== flowId ? await getForId(resolvedId) : firstResponse;
|
|
160
174
|
return (0, types_1.mapFlowConfig)(resolvedId, data ?? {});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
},
|
|
176
|
+
// Configs are cached under version ids, so an origin id — the stable one an app persists —
|
|
177
|
+
// misses. Each downloaded config names its own origin, so the version is found among them,
|
|
178
|
+
// newest first: several versions of one flow can be downloaded at once and the first match
|
|
179
|
+
// would otherwise be whichever the cache happened to list first. Newest DOWNLOADED, not
|
|
180
|
+
// newest — that needs the versions endpoint, and so a network.
|
|
181
|
+
cache: (api) => {
|
|
182
|
+
const raw = api.readFlow(flowId);
|
|
183
|
+
// An origin id doubles as version 1's document id, so a hit under one can be a stale v1
|
|
184
|
+
// with a newer version downloaded alongside it. Only that case keeps looking.
|
|
185
|
+
const queriedByOriginId = flowVersionOf(raw)?.originId === flowId;
|
|
186
|
+
if (raw && !queriedByOriginId)
|
|
187
|
+
return (0, types_1.mapFlowConfig)(flowId, raw);
|
|
188
|
+
const offline = deps.shell().getOffline?.() ?? null;
|
|
189
|
+
let newest;
|
|
190
|
+
for (const id of offline?.listDownloadedFlowIds() ?? []) {
|
|
191
|
+
const config = api.readFlow(id);
|
|
192
|
+
const version = flowVersionOf(config);
|
|
193
|
+
if (!config || version?.originId !== flowId)
|
|
194
|
+
continue;
|
|
195
|
+
if (newest && version.from <= newest.from)
|
|
196
|
+
continue;
|
|
197
|
+
newest = { id, config, from: version.from };
|
|
198
|
+
}
|
|
199
|
+
if (newest)
|
|
200
|
+
return (0, types_1.mapFlowConfig)(newest.id, newest.config);
|
|
201
|
+
// The scan normally re-finds at least the raw hit; an enumeration the host cannot answer
|
|
202
|
+
// must not turn a config we are holding into "not downloaded".
|
|
203
|
+
return raw ? (0, types_1.mapFlowConfig)(flowId, raw) : null;
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const getLayout = (layoutId, opts = {}) => (0, readPolicy_1.resolveRead)({
|
|
207
|
+
shell: deps.shell,
|
|
208
|
+
signal: opts.signal,
|
|
209
|
+
network: async (signal) => {
|
|
168
210
|
const { data } = await deps
|
|
169
211
|
.shell()
|
|
170
212
|
.getApiV4("config")
|
|
171
213
|
.get(`/api/v4/config/layout/${layoutId}`, {
|
|
172
|
-
signal
|
|
214
|
+
signal,
|
|
173
215
|
});
|
|
174
216
|
return (0, types_1.mapLayout)(layoutId, data ?? {});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
217
|
+
},
|
|
218
|
+
// The cache stores the layout exactly as the API sent it — the same flat list the network
|
|
219
|
+
// returns — and both sources go through the one `mapLayout`, so they cannot disagree.
|
|
220
|
+
cache: (api) => {
|
|
221
|
+
const raw = api.readLayout(layoutId);
|
|
222
|
+
return raw ? (0, types_1.mapLayout)(layoutId, raw) : null;
|
|
223
|
+
},
|
|
224
|
+
});
|
|
180
225
|
return {
|
|
181
226
|
list,
|
|
182
227
|
get,
|
|
@@ -6,4 +6,8 @@ export { DEFAULT_SEARCH_PAGE_SIZE, searchCacheShape, type SearchArgs, type Searc
|
|
|
6
6
|
export { createFlowsConnector, findTaskIn, flattenLayoutFields, flows, type FindTaskArgs, type FindTaskResult, type FlowsConnector, type ListFlowsArgs, } from "./flows";
|
|
7
7
|
export { createWorkConnector, work, type FlowRef, type IterateWorkRowsArgs, type ListRelatedWorkArgs, type ListWorkRowsArgs, type SearchWorkArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkPatchOperation, type WorkRowPage, type WorkSearchPage, } from "./work";
|
|
8
8
|
export { ASSET_TARGET_DATA_TYPES, assets, createAssetsConnector, type AssetRowPage, type AssetSearchPage, type AssetsConnector, type AssetTypeRef, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type ListRelatedAssetsArgs, type QuickSearchAssetsArgs, type SearchAssetsArgs, type StartEditAssetArgs, } from "./assets";
|
|
9
|
-
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";
|
|
9
|
+
export { agentEndReason, agentErrorText, agentMessageText, agents, collectAgentReply, createAgentsConnector, streamAgentReply, type AgentChatSession, type AgentReplyState, type AgentsConnector, type CreateAgentChatArgs, type GetChatMessagesArgs, type ListAgentsArgs, type ListChatsArgs, type RunAgentArgs, type SendChatArgs, } from "./agents";
|
|
10
|
+
export { attachments, createAttachmentsConnector, type AttachmentsConnector, type GetAttachmentBlobArgs, type UploadAttachmentArgs, } from "./attachments";
|
|
11
|
+
export { createIntegrationsConnector, integrations, type IntegrationsConnector, type InvokeIntegrationEndpointArgs, } from "./integrations";
|
|
12
|
+
export { createVectorStoresConnector, vectorStores, type AddVectorStoreFilesArgs, type CreateVectorStoreArgs, type RebuildVectorStoreArgs, type RenewVectorStoreArgs, type VectorStoresConnector, } from "./vectorStores";
|
|
13
|
+
export { createOfflineConnector, offline, type OfflineConnector, } from "./offline";
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// raw API clients so apps stop hand-rolling multi-step API dances.
|
|
4
4
|
//
|
|
5
5
|
// Ready-made singletons (bound to the live bridge): `flows`, `work`, `assets`,
|
|
6
|
-
// `agents`.
|
|
6
|
+
// `agents`, `attachments`, `integrations`, `vectorStores`, `offline`.
|
|
7
7
|
// Factories accept a custom shell resolver for tests/standalone dev.
|
|
8
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
9
|
if (k2 === undefined) k2 = k;
|
|
@@ -20,7 +20,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
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.searchCacheShape = exports.DEFAULT_SEARCH_PAGE_SIZE = exports.iterateSseResponse = exports.createSseParser = exports.toConnectorError = exports.ConnectorError = void 0;
|
|
23
|
+
exports.offline = exports.createOfflineConnector = exports.vectorStores = exports.createVectorStoresConnector = exports.integrations = exports.createIntegrationsConnector = exports.createAttachmentsConnector = exports.attachments = 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.searchCacheShape = exports.DEFAULT_SEARCH_PAGE_SIZE = exports.iterateSseResponse = exports.createSseParser = exports.toConnectorError = exports.ConnectorError = void 0;
|
|
24
24
|
var errors_1 = require("./errors");
|
|
25
25
|
Object.defineProperty(exports, "ConnectorError", { enumerable: true, get: function () { return errors_1.ConnectorError; } });
|
|
26
26
|
Object.defineProperty(exports, "toConnectorError", { enumerable: true, get: function () { return errors_1.toConnectorError; } });
|
|
@@ -51,3 +51,15 @@ Object.defineProperty(exports, "agents", { enumerable: true, get: function () {
|
|
|
51
51
|
Object.defineProperty(exports, "collectAgentReply", { enumerable: true, get: function () { return agents_1.collectAgentReply; } });
|
|
52
52
|
Object.defineProperty(exports, "createAgentsConnector", { enumerable: true, get: function () { return agents_1.createAgentsConnector; } });
|
|
53
53
|
Object.defineProperty(exports, "streamAgentReply", { enumerable: true, get: function () { return agents_1.streamAgentReply; } });
|
|
54
|
+
var attachments_1 = require("./attachments");
|
|
55
|
+
Object.defineProperty(exports, "attachments", { enumerable: true, get: function () { return attachments_1.attachments; } });
|
|
56
|
+
Object.defineProperty(exports, "createAttachmentsConnector", { enumerable: true, get: function () { return attachments_1.createAttachmentsConnector; } });
|
|
57
|
+
var integrations_1 = require("./integrations");
|
|
58
|
+
Object.defineProperty(exports, "createIntegrationsConnector", { enumerable: true, get: function () { return integrations_1.createIntegrationsConnector; } });
|
|
59
|
+
Object.defineProperty(exports, "integrations", { enumerable: true, get: function () { return integrations_1.integrations; } });
|
|
60
|
+
var vectorStores_1 = require("./vectorStores");
|
|
61
|
+
Object.defineProperty(exports, "createVectorStoresConnector", { enumerable: true, get: function () { return vectorStores_1.createVectorStoresConnector; } });
|
|
62
|
+
Object.defineProperty(exports, "vectorStores", { enumerable: true, get: function () { return vectorStores_1.vectorStores; } });
|
|
63
|
+
var offline_1 = require("./offline");
|
|
64
|
+
Object.defineProperty(exports, "createOfflineConnector", { enumerable: true, get: function () { return offline_1.createOfflineConnector; } });
|
|
65
|
+
Object.defineProperty(exports, "offline", { enumerable: true, get: function () { return offline_1.offline; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ConnectorDeps } from "./deps";
|
|
2
|
+
import { type IntegrationInvokeResult } from "./types";
|
|
3
|
+
export interface InvokeIntegrationEndpointArgs {
|
|
4
|
+
integrationId: string;
|
|
5
|
+
endpointId: string;
|
|
6
|
+
data?: Record<string, unknown>;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
export interface IntegrationsConnector {
|
|
10
|
+
/**
|
|
11
|
+
* Invokes a single endpoint on an integration at runtime — whatever HTTP method
|
|
12
|
+
* (GET, POST, PUT, PATCH or DELETE) the endpoint is itself configured with; this
|
|
13
|
+
* call takes no method of its own. Any member of the integration's own
|
|
14
|
+
* environment may call it — no per-integration grant, no per-endpoint opt-in —
|
|
15
|
+
* and a caller in a different environment can still reach it if their company
|
|
16
|
+
* holds a subscription covering the integration. Treat every invocation's
|
|
17
|
+
* response as readable, and a write-method endpoint as invocable, by the whole
|
|
18
|
+
* ecosystem the integration belongs to: a write-method endpoint is a real,
|
|
19
|
+
* credentialed create/update/delete against the third-party system, with no
|
|
20
|
+
* additional permission check beyond the applicable membership or subscription
|
|
21
|
+
* entitlement.
|
|
22
|
+
*
|
|
23
|
+
* Network only, no offline queueing: this is a live outbound call through the
|
|
24
|
+
* integration's own credentials, not a resource this app owns to replay later.
|
|
25
|
+
*/
|
|
26
|
+
invoke(args: InvokeIntegrationEndpointArgs): Promise<IntegrationInvokeResult>;
|
|
27
|
+
}
|
|
28
|
+
export declare function createIntegrationsConnector(deps?: ConnectorDeps): IntegrationsConnector;
|
|
29
|
+
export declare const integrations: IntegrationsConnector;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.integrations = void 0;
|
|
4
|
+
exports.createIntegrationsConnector = createIntegrationsConnector;
|
|
5
|
+
const _internal_1 = require("../_internal");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
// Integration config registry (rise-x-api, v4 'config' scope) — same host as
|
|
9
|
+
// the agent/flow config routes.
|
|
10
|
+
const INTEGRATION_PATH = "/api/v4/config/integration";
|
|
11
|
+
function createIntegrationsConnector(deps = { shell: _internal_1.requireShell }) {
|
|
12
|
+
const configApi = () => deps.shell().getApiV4("config");
|
|
13
|
+
const invoke = async (args) => {
|
|
14
|
+
const { integrationId, endpointId, data, signal } = args;
|
|
15
|
+
if (!integrationId) {
|
|
16
|
+
throw new errors_1.ConnectorError("INVALID_ARG", "integrations.invoke: integrationId is required");
|
|
17
|
+
}
|
|
18
|
+
if (!endpointId) {
|
|
19
|
+
throw new errors_1.ConnectorError("INVALID_ARG", "integrations.invoke: endpointId is required");
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { data: result } = await configApi().post(`${INTEGRATION_PATH}/${integrationId}/endpoint/${endpointId}/invoke`, { data: data ?? {} }, { signal });
|
|
23
|
+
return (0, types_1.mapIntegrationInvokeResult)(result);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return { invoke };
|
|
30
|
+
}
|
|
31
|
+
// Ready-made singleton bound to the live shell bridge.
|
|
32
|
+
exports.integrations = createIntegrationsConnector();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CreateWorkArgs, DeleteWorkAttachmentArgs, DownloadFlowWorksArgs, DownloadFlowWorksResult, ExecuteWorkActionArgs, FlowDownloadInfo, QueuedWorkOperation, QueuedWorkOperationKind, UpdateWorkDataArgs, UploadWorkAttachmentArgs, WorkSyncStatus } from "../shellBridge";
|
|
2
|
+
import type { ConnectorDeps } from "./deps";
|
|
3
|
+
export interface OfflineConnector {
|
|
4
|
+
/** Whether the shell has connectivity. `true` on a host with no offline support. */
|
|
5
|
+
isOnline(): boolean;
|
|
6
|
+
/** Outbox state for one work, including the `writeMode` you route on. */
|
|
7
|
+
getWorkSyncStatus(workId: string): WorkSyncStatus;
|
|
8
|
+
/** Everything still queued, in the order replay will follow. */
|
|
9
|
+
listQueuedWorkOperations(args?: {
|
|
10
|
+
workId?: string;
|
|
11
|
+
kind?: QueuedWorkOperationKind;
|
|
12
|
+
}): QueuedWorkOperation[];
|
|
13
|
+
queueWorkDataUpdate(args: UpdateWorkDataArgs): void;
|
|
14
|
+
queueWorkAction(args: ExecuteWorkActionArgs): void;
|
|
15
|
+
/** Returns the id and code the work was given; it is real under that id immediately. */
|
|
16
|
+
queueWorkCreation(args: CreateWorkArgs): {
|
|
17
|
+
workId: string;
|
|
18
|
+
code: string;
|
|
19
|
+
};
|
|
20
|
+
queueWorkAttachmentUpload(args: UploadWorkAttachmentArgs): Promise<void>;
|
|
21
|
+
queueWorkAttachmentDeletion(args: DeleteWorkAttachmentArgs): void;
|
|
22
|
+
/** Asks the shell to drain the outbox. Resolves on "asked" — poll the sync status for progress. */
|
|
23
|
+
requestSync(args?: {
|
|
24
|
+
workId?: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
/** Ids of the works held locally right now — put there by a download or by ordinary online browsing. */
|
|
27
|
+
listDownloadedWorkIds(flowOriginId?: string): string[];
|
|
28
|
+
/** Ids of every flow config held locally right now — put there by a download or by ordinary online browsing — version ids, which configs are keyed by. */
|
|
29
|
+
listDownloadedFlowIds(): string[];
|
|
30
|
+
downloadFlowWorks(args: DownloadFlowWorksArgs): Promise<DownloadFlowWorksResult>;
|
|
31
|
+
getFlowWorksDownloadInfo(flowOriginId: string): FlowDownloadInfo;
|
|
32
|
+
}
|
|
33
|
+
export declare function createOfflineConnector(deps?: ConnectorDeps): OfflineConnector;
|
|
34
|
+
export declare const offline: OfflineConnector;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.offline = void 0;
|
|
4
|
+
exports.createOfflineConnector = createOfflineConnector;
|
|
5
|
+
/**
|
|
6
|
+
* The offline connector — the queue, as explicit tools. Nothing here inspects connectivity or
|
|
7
|
+
* decides for the caller: the queue methods enqueue, `requestSync` drains, and the caller routes
|
|
8
|
+
* writes on `getWorkSyncStatus().writeMode`. Read-source rules live in readPolicy.ts.
|
|
9
|
+
*/
|
|
10
|
+
const _internal_1 = require("../_internal");
|
|
11
|
+
const errors_1 = require("./errors");
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the host's offline facade, or explains why it cannot.
|
|
14
|
+
*
|
|
15
|
+
* Detects the METHOD, not the accessor. An older host still has `getOffline()`, so an
|
|
16
|
+
* accessor-truthiness check passes there, and a method added in a later bridge version still
|
|
17
|
+
* throws — with a TypeError, at a call site that has no idea what went wrong. A `SHELL_TOO_OLD`
|
|
18
|
+
* ConnectorError is the honest answer, and it matches how every other connector reports an
|
|
19
|
+
* unusable shell.
|
|
20
|
+
*/
|
|
21
|
+
function facade(deps, method) {
|
|
22
|
+
const offline = deps.shell().getOffline?.() ?? null;
|
|
23
|
+
if (!offline) {
|
|
24
|
+
throw new errors_1.ConnectorError("SHELL_TOO_OLD", `offline.${String(method)} needs a shell with offline support; this host has none ` +
|
|
25
|
+
"(standalone dev, or a host that predates it)");
|
|
26
|
+
}
|
|
27
|
+
if (typeof offline[method] !== "function") {
|
|
28
|
+
throw new errors_1.ConnectorError("SHELL_TOO_OLD", `offline.${String(method)} is not available on this host's bridge`);
|
|
29
|
+
}
|
|
30
|
+
return offline;
|
|
31
|
+
}
|
|
32
|
+
function createOfflineConnector(deps = { shell: _internal_1.requireShell }) {
|
|
33
|
+
return {
|
|
34
|
+
// The one method that answers rather than throwing on an offline-less host: a connectivity
|
|
35
|
+
// question has a sensible answer everywhere, and an app asking it should not have to guard.
|
|
36
|
+
isOnline: () => deps.shell().getOffline?.()?.isOnline() ?? true,
|
|
37
|
+
getWorkSyncStatus: (workId) => {
|
|
38
|
+
try {
|
|
39
|
+
return facade(deps, "getWorkSyncStatus").getWorkSyncStatus(workId);
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
listQueuedWorkOperations: (args) => {
|
|
46
|
+
try {
|
|
47
|
+
return facade(deps, "listQueuedWorkOperations").listQueuedWorkOperations(args);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
queueWorkDataUpdate: (args) => {
|
|
54
|
+
try {
|
|
55
|
+
facade(deps, "queueWorkDataUpdate").queueWorkDataUpdate(args);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
queueWorkAction: (args) => {
|
|
62
|
+
try {
|
|
63
|
+
facade(deps, "queueWorkAction").queueWorkAction(args);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
queueWorkCreation: (args) => {
|
|
70
|
+
try {
|
|
71
|
+
return facade(deps, "queueWorkCreation").queueWorkCreation(args);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
queueWorkAttachmentUpload: async (args) => {
|
|
78
|
+
try {
|
|
79
|
+
await facade(deps, "queueWorkAttachmentUpload").queueWorkAttachmentUpload(args);
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
queueWorkAttachmentDeletion: (args) => {
|
|
86
|
+
try {
|
|
87
|
+
facade(deps, "queueWorkAttachmentDeletion").queueWorkAttachmentDeletion(args);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
requestSync: async (args) => {
|
|
94
|
+
try {
|
|
95
|
+
await facade(deps, "requestSync").requestSync(args);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
listDownloadedWorkIds: (flowOriginId) => {
|
|
102
|
+
try {
|
|
103
|
+
return facade(deps, "listDownloadedWorkIds").listDownloadedWorkIds(flowOriginId);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
listDownloadedFlowIds: () => {
|
|
110
|
+
try {
|
|
111
|
+
return facade(deps, "listDownloadedFlowIds").listDownloadedFlowIds();
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
downloadFlowWorks: async (args) => {
|
|
118
|
+
try {
|
|
119
|
+
return await facade(deps, "downloadFlowWorks").downloadFlowWorks(args);
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
getFlowWorksDownloadInfo: (flowOriginId) => {
|
|
126
|
+
try {
|
|
127
|
+
return facade(deps, "getFlowWorksDownloadInfo").getFlowWorksDownloadInfo(flowOriginId);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
exports.offline = createOfflineConnector();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place that decides where a read's bytes come from — every connector read routes through
|
|
3
|
+
* `resolveRead`, so the rule has exactly one implementation and there is no `source` option.
|
|
4
|
+
* Offline reads try the cache first; online reads are network-first with a bounded timeout,
|
|
5
|
+
* falling back to the cache only when the server gave no usable answer.
|
|
6
|
+
*/
|
|
7
|
+
import type { CacheApi, DianaShell } from "../shellBridge";
|
|
8
|
+
/**
|
|
9
|
+
* How long a read waits for the server before falling back to the cache. `isOnline()` lies behind
|
|
10
|
+
* captive portals and hanging hosts — all "online" — so a read gives up on the clock instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare const READ_TIMEOUT_MS = 10000;
|
|
13
|
+
export interface ResolveReadArgs<T> {
|
|
14
|
+
shell: () => DianaShell;
|
|
15
|
+
/** Fetches from the server. Receives a signal already wired to the timeout. */
|
|
16
|
+
network: (signal: AbortSignal) => Promise<T | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Reads the local copy. Returns `null` when nothing was downloaded; must never throw. May be
|
|
19
|
+
* async: attachment bytes live in IndexedDB, which has no synchronous API.
|
|
20
|
+
*/
|
|
21
|
+
cache: (cache: CacheApi) => T | null | Promise<T | null>;
|
|
22
|
+
/** Caller's own AbortSignal, if any — aborting it aborts the read. */
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves one read. `null` means "not there" — absent on the server; an unreachable server with
|
|
27
|
+
* an empty cache throws. The two must never arrive as the same value.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveRead<T>(args: ResolveReadArgs<T>): Promise<T | null>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.READ_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.resolveRead = resolveRead;
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
/**
|
|
7
|
+
* How long a read waits for the server before falling back to the cache. `isOnline()` lies behind
|
|
8
|
+
* captive portals and hanging hosts — all "online" — so a read gives up on the clock instead.
|
|
9
|
+
*/
|
|
10
|
+
exports.READ_TIMEOUT_MS = 10000;
|
|
11
|
+
/** Raised when a request is abandoned at {@link READ_TIMEOUT_MS}; never surfaces to callers. */
|
|
12
|
+
class ReadTimeout extends Error {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves one read. `null` means "not there" — absent on the server; an unreachable server with
|
|
16
|
+
* an empty cache throws. The two must never arrive as the same value.
|
|
17
|
+
*/
|
|
18
|
+
async function resolveRead(args) {
|
|
19
|
+
const { shell, network, cache, signal } = args;
|
|
20
|
+
const readCache = async () => {
|
|
21
|
+
const api = shell().getCache?.() ?? null;
|
|
22
|
+
// A host that never wired the cache is not an error — it simply has no local copy, so the
|
|
23
|
+
// policy degrades to network-only rather than failing every read.
|
|
24
|
+
if (!api)
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
return await cache(api);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// A cache that cannot answer is a miss. Note this swallows the one throw the contract allows
|
|
31
|
+
// — `readWorkData` on a recursive-descent path — so `work.getData` pre-checks it instead.
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// `isOnline()` is `navigator.onLine` — a live interface, not a reachable server — so a cache miss
|
|
36
|
+
// must not become a silent `null`. Fall through and let the network answer.
|
|
37
|
+
if (!isOnline(shell)) {
|
|
38
|
+
const cached = await readCache();
|
|
39
|
+
if (cached !== null)
|
|
40
|
+
return cached;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
return await withTimeout(network, signal);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const failure = (0, errors_1.toConnectorError)(error);
|
|
47
|
+
// The server answered: 404 means it does not exist, and any other 4xx is a refusal — a cached
|
|
48
|
+
// copy would serve a work the user just lost permission to see. An abort wants no substitute.
|
|
49
|
+
if (failure.code === "NOT_FOUND")
|
|
50
|
+
return null;
|
|
51
|
+
if (failure.code === "ABORTED")
|
|
52
|
+
throw failure;
|
|
53
|
+
if (isClientError(failure))
|
|
54
|
+
throw failure;
|
|
55
|
+
// From here the server gave no usable answer — unreachable, timed out, or 5xx — so a
|
|
56
|
+
// downloaded copy is strictly better than nothing.
|
|
57
|
+
const cached = await readCache();
|
|
58
|
+
if (cached !== null)
|
|
59
|
+
return cached;
|
|
60
|
+
// With nothing local, the caller must be told the server was unreachable — `null` here would
|
|
61
|
+
// be indistinguishable from "not downloaded".
|
|
62
|
+
throw failure;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** A 4xx other than 404 — the server refused rather than failed. */
|
|
66
|
+
function isClientError(error) {
|
|
67
|
+
return (error.code === "HTTP_ERROR" &&
|
|
68
|
+
error.status !== undefined &&
|
|
69
|
+
error.status >= 400 &&
|
|
70
|
+
error.status < 500);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Whether the shell reports connectivity. A host with no offline facade is assumed online — it has
|
|
74
|
+
* no cache either, so network-only is the only behaviour available to it.
|
|
75
|
+
*/
|
|
76
|
+
function isOnline(shell) {
|
|
77
|
+
const offline = shell().getOffline?.() ?? null;
|
|
78
|
+
return offline ? offline.isOnline() : true;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Runs the request under both the caller's signal and the timeout. The signal is passed down so an
|
|
82
|
+
* abandoned read actually stops in flight rather than leaving the socket open.
|
|
83
|
+
*/
|
|
84
|
+
async function withTimeout(network, callerSignal) {
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const abortFromCaller = () => controller.abort();
|
|
87
|
+
callerSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
88
|
+
if (callerSignal?.aborted)
|
|
89
|
+
controller.abort();
|
|
90
|
+
let timer;
|
|
91
|
+
const timeout = new Promise((_, reject) => {
|
|
92
|
+
timer = setTimeout(() => {
|
|
93
|
+
controller.abort();
|
|
94
|
+
reject(new ReadTimeout(`read abandoned after ${exports.READ_TIMEOUT_MS}ms`));
|
|
95
|
+
}, exports.READ_TIMEOUT_MS);
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
return await Promise.race([network(controller.signal), timeout]);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
if (timer)
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
callerSignal?.removeEventListener("abort", abortFromCaller);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -75,6 +75,10 @@ export interface WorkRow {
|
|
|
75
75
|
data?: Record<string, unknown>;
|
|
76
76
|
}
|
|
77
77
|
export declare function mapWorkRow(value: unknown): WorkRow;
|
|
78
|
+
export interface WorkAccessInfo {
|
|
79
|
+
roles: string[];
|
|
80
|
+
}
|
|
81
|
+
export declare function mapWorkAccess(value: unknown): WorkAccessInfo;
|
|
78
82
|
export interface WorkAction {
|
|
79
83
|
id?: string;
|
|
80
84
|
name?: string;
|
|
@@ -82,6 +86,16 @@ export interface WorkAction {
|
|
|
82
86
|
eventName?: string;
|
|
83
87
|
canExecute?: boolean;
|
|
84
88
|
}
|
|
89
|
+
export interface WorkAttachment {
|
|
90
|
+
id: string;
|
|
91
|
+
/** The original file name — what the shell's own deletion paths queue, not the storage name. */
|
|
92
|
+
fileName?: string;
|
|
93
|
+
title?: string;
|
|
94
|
+
/** The attachment's folder — Attachments layout components match on this exact string. */
|
|
95
|
+
path?: string;
|
|
96
|
+
/** What `offline.queueWorkAttachmentDeletion` wants as `mimeType`. */
|
|
97
|
+
mimeType?: string;
|
|
98
|
+
}
|
|
85
99
|
export interface WorkDetail {
|
|
86
100
|
id: string;
|
|
87
101
|
code?: string;
|
|
@@ -91,6 +105,7 @@ export interface WorkDetail {
|
|
|
91
105
|
flowOriginId?: string;
|
|
92
106
|
status?: string;
|
|
93
107
|
state?: string;
|
|
108
|
+
attachments: WorkAttachment[];
|
|
94
109
|
actions: WorkAction[];
|
|
95
110
|
}
|
|
96
111
|
export declare function mapWorkDetail(value: unknown): WorkDetail;
|
|
@@ -334,3 +349,63 @@ export declare function mapAgentChatMessagePage(raw: unknown, fallback: {
|
|
|
334
349
|
pageSize: number;
|
|
335
350
|
chatId?: string;
|
|
336
351
|
}): AgentChatMessagePage;
|
|
352
|
+
export interface VectorStoreFileCounts {
|
|
353
|
+
inProgress: number;
|
|
354
|
+
completed: number;
|
|
355
|
+
failed: number;
|
|
356
|
+
cancelled: number;
|
|
357
|
+
total: number;
|
|
358
|
+
}
|
|
359
|
+
export interface VectorStore {
|
|
360
|
+
id: string;
|
|
361
|
+
name: string;
|
|
362
|
+
status: string;
|
|
363
|
+
createdAt?: string;
|
|
364
|
+
lastActiveAt?: string;
|
|
365
|
+
expiresAt?: string;
|
|
366
|
+
expiresAfterDays: number;
|
|
367
|
+
daysUntilExpiry?: number;
|
|
368
|
+
fileCounts: VectorStoreFileCounts;
|
|
369
|
+
usageBytes?: number;
|
|
370
|
+
metadata?: Record<string, unknown>;
|
|
371
|
+
rebuiltFrom?: string;
|
|
372
|
+
expiryNotice?: string;
|
|
373
|
+
}
|
|
374
|
+
export declare function mapVectorStore(value: unknown): VectorStore;
|
|
375
|
+
export interface VectorStoreFileError {
|
|
376
|
+
code: string;
|
|
377
|
+
message: string;
|
|
378
|
+
}
|
|
379
|
+
export interface VectorStoreFile {
|
|
380
|
+
fileId: string;
|
|
381
|
+
filename: string;
|
|
382
|
+
status: string;
|
|
383
|
+
lastError: VectorStoreFileError | null;
|
|
384
|
+
bytes?: number;
|
|
385
|
+
createdAt?: string;
|
|
386
|
+
attributes?: Record<string, string | number | boolean>;
|
|
387
|
+
}
|
|
388
|
+
export declare function mapVectorStoreFile(value: unknown): VectorStoreFile;
|
|
389
|
+
export declare function mapVectorStoreFileList(value: unknown): VectorStoreFile[];
|
|
390
|
+
export type VectorStoreFileIntakeStatus = "accepted" | "converted" | "rejected" | "failed" | "unknown";
|
|
391
|
+
export interface VectorStoreFileIntakeResult {
|
|
392
|
+
filename: string;
|
|
393
|
+
status: VectorStoreFileIntakeStatus;
|
|
394
|
+
reason?: string;
|
|
395
|
+
indexedAs?: string;
|
|
396
|
+
lastError?: VectorStoreFileError | null;
|
|
397
|
+
}
|
|
398
|
+
export interface AddVectorStoreFilesResult {
|
|
399
|
+
store: VectorStore;
|
|
400
|
+
files: VectorStoreFileIntakeResult[];
|
|
401
|
+
}
|
|
402
|
+
export declare function mapAddVectorStoreFilesResult(value: unknown): AddVectorStoreFilesResult;
|
|
403
|
+
export interface IntegrationInvokeResult {
|
|
404
|
+
statusCode: number;
|
|
405
|
+
success: boolean;
|
|
406
|
+
response: Record<string, unknown> | null;
|
|
407
|
+
items: Record<string, unknown>[];
|
|
408
|
+
message: string | null;
|
|
409
|
+
executionTimeMs: number;
|
|
410
|
+
}
|
|
411
|
+
export declare function mapIntegrationInvokeResult(value: unknown): IntegrationInvokeResult;
|