@rise-x/apps-sdk 0.11.1 → 0.15.1
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 +915 -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/classes.json +2 -2
- package/build/ui/components/app-frame.d.ts +1 -1
- package/build/ui/components/data-table.d.ts +39 -4
- package/build/ui/components/statistic.d.ts +1 -1
- package/build/ui/demo.html +671 -543
- package/build/ui/shadcn.css +629 -0
- package/build/ui/standalone.js +45 -44
- 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
|
@@ -17,6 +17,7 @@ exports.mapFlow = mapFlow;
|
|
|
17
17
|
exports.mapFlowConfig = mapFlowConfig;
|
|
18
18
|
exports.mapLayout = mapLayout;
|
|
19
19
|
exports.mapWorkRow = mapWorkRow;
|
|
20
|
+
exports.mapWorkAccess = mapWorkAccess;
|
|
20
21
|
exports.mapWorkDetail = mapWorkDetail;
|
|
21
22
|
exports.mapWorkSummary = mapWorkSummary;
|
|
22
23
|
exports.mapWorkAuditEvent = mapWorkAuditEvent;
|
|
@@ -31,6 +32,11 @@ exports.mapAgentChat = mapAgentChat;
|
|
|
31
32
|
exports.mapAgentChatPage = mapAgentChatPage;
|
|
32
33
|
exports.mapAgentChatMessage = mapAgentChatMessage;
|
|
33
34
|
exports.mapAgentChatMessagePage = mapAgentChatMessagePage;
|
|
35
|
+
exports.mapVectorStore = mapVectorStore;
|
|
36
|
+
exports.mapVectorStoreFile = mapVectorStoreFile;
|
|
37
|
+
exports.mapVectorStoreFileList = mapVectorStoreFileList;
|
|
38
|
+
exports.mapAddVectorStoreFilesResult = mapAddVectorStoreFilesResult;
|
|
39
|
+
exports.mapIntegrationInvokeResult = mapIntegrationInvokeResult;
|
|
34
40
|
const str = (v) => typeof v === "string" && v !== "" ? v : undefined;
|
|
35
41
|
// Mappers accept `unknown` so call sites can feed raw axios payloads directly;
|
|
36
42
|
// anything non-object maps as an empty record (tolerant by contract).
|
|
@@ -145,10 +151,19 @@ function mapWorkRow(value) {
|
|
|
145
151
|
: undefined,
|
|
146
152
|
};
|
|
147
153
|
}
|
|
154
|
+
function mapWorkAccess(value) {
|
|
155
|
+
// The bare array is wrapped so a server-computed capability can be added without breaking callers.
|
|
156
|
+
return {
|
|
157
|
+
roles: Array.isArray(value) ? value.map((role) => String(role)) : [],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
148
160
|
function mapWorkDetail(value) {
|
|
149
161
|
const raw = asRecord(value);
|
|
150
162
|
const id = String(raw.id ?? "");
|
|
151
163
|
const actions = Array.isArray(raw.actions) ? raw.actions : [];
|
|
164
|
+
const attachments = Array.isArray(raw.attachments)
|
|
165
|
+
? raw.attachments
|
|
166
|
+
: [];
|
|
152
167
|
return {
|
|
153
168
|
id,
|
|
154
169
|
code: str(raw?.code),
|
|
@@ -158,6 +173,15 @@ function mapWorkDetail(value) {
|
|
|
158
173
|
flowOriginId: str(raw?.flowOriginId),
|
|
159
174
|
status: str(raw?.status),
|
|
160
175
|
state: str(raw?.state),
|
|
176
|
+
attachments: attachments.map((a) => ({
|
|
177
|
+
id: String(a?.id ?? ""),
|
|
178
|
+
// The record's `fileName` is the storage name; the original is the one deletions queue.
|
|
179
|
+
fileName: str(a?.unsafeOriginalFileName),
|
|
180
|
+
title: str(a?.title),
|
|
181
|
+
path: str(a?.path),
|
|
182
|
+
// The record stores the mime type as `attachmentType` — the shell's own deletion paths read it.
|
|
183
|
+
mimeType: str(a?.attachmentType),
|
|
184
|
+
})),
|
|
161
185
|
actions: actions.map((a) => ({
|
|
162
186
|
id: str(a?.id),
|
|
163
187
|
name: str(a?.name),
|
|
@@ -488,3 +512,107 @@ function mapAgentChatMessagePage(raw, fallback) {
|
|
|
488
512
|
nextSeq,
|
|
489
513
|
};
|
|
490
514
|
}
|
|
515
|
+
function mapVectorStoreFileCounts(value) {
|
|
516
|
+
const raw = asRecord(value);
|
|
517
|
+
return {
|
|
518
|
+
inProgress: num(raw?.inProgress) ?? 0,
|
|
519
|
+
completed: num(raw?.completed) ?? 0,
|
|
520
|
+
failed: num(raw?.failed) ?? 0,
|
|
521
|
+
cancelled: num(raw?.cancelled) ?? 0,
|
|
522
|
+
total: num(raw?.total) ?? 0,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function mapVectorStore(value) {
|
|
526
|
+
const raw = asRecord(value);
|
|
527
|
+
return {
|
|
528
|
+
id: str(raw?.id) ?? "",
|
|
529
|
+
name: str(raw?.name) ?? "",
|
|
530
|
+
status: str(raw?.status) ?? "",
|
|
531
|
+
createdAt: str(raw?.createdAt),
|
|
532
|
+
lastActiveAt: str(raw?.lastActiveAt),
|
|
533
|
+
expiresAt: str(raw?.expiresAt),
|
|
534
|
+
expiresAfterDays: num(raw?.expiresAfterDays) ?? 0,
|
|
535
|
+
daysUntilExpiry: num(raw?.daysUntilExpiry),
|
|
536
|
+
fileCounts: mapVectorStoreFileCounts(raw?.fileCounts),
|
|
537
|
+
usageBytes: num(raw?.usageBytes),
|
|
538
|
+
metadata: subDoc(raw?.metadata),
|
|
539
|
+
rebuiltFrom: str(raw?.rebuiltFrom),
|
|
540
|
+
expiryNotice: str(raw?.expiryNotice),
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function mapVectorStoreFileError(value) {
|
|
544
|
+
const raw = subDoc(value);
|
|
545
|
+
if (!raw)
|
|
546
|
+
return null;
|
|
547
|
+
return { code: str(raw.code) ?? "", message: str(raw.message) ?? "" };
|
|
548
|
+
}
|
|
549
|
+
function mapVectorStoreFile(value) {
|
|
550
|
+
const raw = asRecord(value);
|
|
551
|
+
return {
|
|
552
|
+
fileId: str(raw?.fileId) ?? "",
|
|
553
|
+
filename: str(raw?.filename) ?? "",
|
|
554
|
+
status: str(raw?.status) ?? "",
|
|
555
|
+
lastError: mapVectorStoreFileError(raw?.lastError),
|
|
556
|
+
bytes: num(raw?.bytes),
|
|
557
|
+
createdAt: str(raw?.createdAt),
|
|
558
|
+
attributes: subDoc(raw?.attributes),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
// GET /{id}/files returns { items: [...] } — tolerate a bare array too, same
|
|
562
|
+
// defensive rule as the paged domains above.
|
|
563
|
+
function mapVectorStoreFileList(value) {
|
|
564
|
+
const record = (value ?? {});
|
|
565
|
+
const items = Array.isArray(value)
|
|
566
|
+
? value
|
|
567
|
+
: Array.isArray(record.items)
|
|
568
|
+
? record.items
|
|
569
|
+
: Array.isArray(record.data)
|
|
570
|
+
? record.data
|
|
571
|
+
: Array.isArray(record.results)
|
|
572
|
+
? record.results
|
|
573
|
+
: [];
|
|
574
|
+
return items.map(mapVectorStoreFile);
|
|
575
|
+
}
|
|
576
|
+
const INTAKE_STATUSES = new Set([
|
|
577
|
+
"accepted",
|
|
578
|
+
"converted",
|
|
579
|
+
"rejected",
|
|
580
|
+
"failed",
|
|
581
|
+
]);
|
|
582
|
+
function toIntakeStatus(value) {
|
|
583
|
+
const status = str(value);
|
|
584
|
+
return status && INTAKE_STATUSES.has(status)
|
|
585
|
+
? status
|
|
586
|
+
: "unknown";
|
|
587
|
+
}
|
|
588
|
+
function mapVectorStoreFileIntakeResult(value) {
|
|
589
|
+
const raw = asRecord(value);
|
|
590
|
+
return {
|
|
591
|
+
filename: str(raw?.filename) ?? "",
|
|
592
|
+
status: toIntakeStatus(raw?.status),
|
|
593
|
+
reason: str(raw?.reason),
|
|
594
|
+
indexedAs: str(raw?.indexedAs),
|
|
595
|
+
lastError: raw?.lastError
|
|
596
|
+
? mapVectorStoreFileError(raw.lastError)
|
|
597
|
+
: undefined,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function mapAddVectorStoreFilesResult(value) {
|
|
601
|
+
const raw = asRecord(value);
|
|
602
|
+
const files = Array.isArray(raw?.files) ? raw.files : [];
|
|
603
|
+
return {
|
|
604
|
+
store: mapVectorStore(raw?.store),
|
|
605
|
+
files: files.map(mapVectorStoreFileIntakeResult),
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function mapIntegrationInvokeResult(value) {
|
|
609
|
+
const raw = asRecord(value);
|
|
610
|
+
return {
|
|
611
|
+
statusCode: num(raw?.statusCode) ?? 0,
|
|
612
|
+
success: raw?.success === true,
|
|
613
|
+
response: subDoc(raw?.response) ?? null,
|
|
614
|
+
items: Array.isArray(raw?.items) ? raw.items : [],
|
|
615
|
+
message: str(raw?.message) ?? null,
|
|
616
|
+
executionTimeMs: num(raw?.executionTimeMs) ?? 0,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ConnectorDeps } from "./deps";
|
|
2
|
+
import { type AddVectorStoreFilesResult, type VectorStore, type VectorStoreFile } from "./types";
|
|
3
|
+
export interface CreateVectorStoreArgs {
|
|
4
|
+
name: string;
|
|
5
|
+
expiresAfterDays?: number;
|
|
6
|
+
purpose?: string;
|
|
7
|
+
resourceType?: string;
|
|
8
|
+
resourceId?: string;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export interface AddVectorStoreFilesArgs {
|
|
12
|
+
files: readonly File[];
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}
|
|
15
|
+
export interface RenewVectorStoreArgs {
|
|
16
|
+
expiresAfterDays: number;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
export interface RebuildVectorStoreArgs {
|
|
20
|
+
expiresAfterDays?: number;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export interface VectorStoresConnector {
|
|
24
|
+
create(args: CreateVectorStoreArgs): Promise<VectorStore>;
|
|
25
|
+
get(id: string, opts?: {
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
}): Promise<VectorStore>;
|
|
28
|
+
addFiles(id: string, args: AddVectorStoreFilesArgs): Promise<AddVectorStoreFilesResult>;
|
|
29
|
+
listFiles(id: string, opts?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<VectorStoreFile[]>;
|
|
32
|
+
renew(id: string, args: RenewVectorStoreArgs): Promise<VectorStore>;
|
|
33
|
+
rename(id: string, name: string, opts?: {
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
}): Promise<VectorStore>;
|
|
36
|
+
rebuild(id: string, args?: RebuildVectorStoreArgs): Promise<VectorStore>;
|
|
37
|
+
deleteFile(id: string, fileId: string, opts?: {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
delete(id: string, opts?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export declare function createVectorStoresConnector(deps?: ConnectorDeps): VectorStoresConnector;
|
|
45
|
+
export declare const vectorStores: VectorStoresConnector;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vectorStores = void 0;
|
|
4
|
+
exports.createVectorStoresConnector = createVectorStoresConnector;
|
|
5
|
+
const _internal_1 = require("../_internal");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
// Gateway prefix for the vector-stores routes, mounted under /api/v1 next to
|
|
9
|
+
// /agent/run — same rise-x-ai host, reached the same way agents.run() is
|
|
10
|
+
// (fetch against ShellAiApi, not the C# API's axios instances).
|
|
11
|
+
const VECTOR_STORES_PATH = "/api/v1/agent/vector-stores";
|
|
12
|
+
function requestHeaders(ai, contentType) {
|
|
13
|
+
const headers = (0, _internal_1.stripContentType)(ai.getHeaders());
|
|
14
|
+
if (contentType)
|
|
15
|
+
headers["Content-Type"] = contentType;
|
|
16
|
+
return headers;
|
|
17
|
+
}
|
|
18
|
+
// X-Rise-App carries the app's MF scope, which the gateway records as the
|
|
19
|
+
// store's `client_app`. Only create and addFiles read it, so only they send it:
|
|
20
|
+
// it is not CORS-safelisted, and every method that sends it needs the gateway's
|
|
21
|
+
// Access-Control-Allow-Headers to cover it.
|
|
22
|
+
function labelledHeaders(ai, contentType) {
|
|
23
|
+
const headers = requestHeaders(ai, contentType);
|
|
24
|
+
if (typeof __APP_SCOPE__ !== "undefined") {
|
|
25
|
+
headers["X-Rise-App"] = __APP_SCOPE__;
|
|
26
|
+
}
|
|
27
|
+
return headers;
|
|
28
|
+
}
|
|
29
|
+
// Ids and names arrive from app-persisted data, where a value the app never
|
|
30
|
+
// saved reads as "". Unguarded, `/${""}` collapses the path to the collection
|
|
31
|
+
// route — a rename or delete then answers 405 off a path the caller never
|
|
32
|
+
// meant, instead of naming the missing argument. Returns the trimmed value so
|
|
33
|
+
// callers send what was validated: a padded id would encode to a %20-padded
|
|
34
|
+
// path and 404 one round-trip later.
|
|
35
|
+
function requireText(action, field, value) {
|
|
36
|
+
const trimmed = value?.trim() ?? "";
|
|
37
|
+
if (!trimmed) {
|
|
38
|
+
throw new errors_1.ConnectorError("INVALID_ARG", `vectorStores.${action}: ${field} is required`);
|
|
39
|
+
}
|
|
40
|
+
return trimmed;
|
|
41
|
+
}
|
|
42
|
+
// The gateway rejects anything below 1 on all three routes that take it, so the
|
|
43
|
+
// bound lives in one place rather than only on the method that requires it.
|
|
44
|
+
// Integer, not just >= 1: JSON.stringify renders Infinity as null, which all
|
|
45
|
+
// three routes read as "unset" — create would silently take the server default
|
|
46
|
+
// and renew would return the store untouched, reporting success either way.
|
|
47
|
+
// The upper bound stays server-side; it is env-configurable, so a constant here
|
|
48
|
+
// would go stale.
|
|
49
|
+
function requireExpiryDays(action, days) {
|
|
50
|
+
if (!Number.isInteger(days) || days < 1) {
|
|
51
|
+
throw new errors_1.ConnectorError("INVALID_ARG", `vectorStores.${action}: expiresAfterDays must be a whole number of 1 or more`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function createVectorStoresConnector(deps = { shell: _internal_1.requireShell }) {
|
|
55
|
+
const resolveAi = () => (0, _internal_1.resolveAi)(deps.shell(), "vectorStores");
|
|
56
|
+
// fetch, not axios: this hits the rise-x-ai gateway directly via
|
|
57
|
+
// ShellAiApi, the same transport agents.run() uses — not the C# API's
|
|
58
|
+
// axios instances the other connectors go through.
|
|
59
|
+
const request = async (ai, path, init, action) => {
|
|
60
|
+
let response;
|
|
61
|
+
try {
|
|
62
|
+
response = await fetch(`${ai.baseUrl}${VECTOR_STORES_PATH}${path}`, init);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
throw (0, errors_1.toConnectorError)(e);
|
|
66
|
+
}
|
|
67
|
+
await (0, _internal_1.ensureOk)(response, action);
|
|
68
|
+
return response;
|
|
69
|
+
};
|
|
70
|
+
// A 2xx carrying a non-JSON body (a proxy interstitial on the /ai route, say)
|
|
71
|
+
// must not reject with a bare SyntaxError: apps classify every other failure
|
|
72
|
+
// off ConnectorError.code.
|
|
73
|
+
const requestJson = async (ai, path, init, action) => {
|
|
74
|
+
const response = await request(ai, path, init, action);
|
|
75
|
+
try {
|
|
76
|
+
return await response.json();
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new errors_1.ConnectorError("PARSE_ERROR", `${action}: response body was not valid JSON`, { cause: e });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const create = async (args) => {
|
|
83
|
+
const name = requireText("create", "name", args.name);
|
|
84
|
+
if (args.expiresAfterDays !== undefined) {
|
|
85
|
+
requireExpiryDays("create", args.expiresAfterDays);
|
|
86
|
+
}
|
|
87
|
+
const ai = resolveAi();
|
|
88
|
+
const body = await requestJson(ai, "", {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: labelledHeaders(ai, "application/json"),
|
|
91
|
+
// camelCase on purpose: this router is alias-generated (to_camel) with
|
|
92
|
+
// extra="forbid", unlike /agent/run's snake_case body. A stray key 422s
|
|
93
|
+
// rather than being dropped — which cuts both ways: a field added here
|
|
94
|
+
// takes create out entirely against a gateway that predates it, so a
|
|
95
|
+
// new optional field needs a gateway floor, not just an SDK bump.
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
name,
|
|
98
|
+
expiresAfterDays: args.expiresAfterDays,
|
|
99
|
+
purpose: args.purpose,
|
|
100
|
+
resourceType: args.resourceType,
|
|
101
|
+
resourceId: args.resourceId,
|
|
102
|
+
}),
|
|
103
|
+
signal: args.signal,
|
|
104
|
+
}, "vectorStores.create");
|
|
105
|
+
return (0, types_1.mapVectorStore)(body);
|
|
106
|
+
};
|
|
107
|
+
const get = async (id, opts = {}) => {
|
|
108
|
+
const storeId = requireText("get", "id", id);
|
|
109
|
+
const ai = resolveAi();
|
|
110
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}`, { method: "GET", headers: requestHeaders(ai), signal: opts.signal }, "vectorStores.get");
|
|
111
|
+
return (0, types_1.mapVectorStore)(body);
|
|
112
|
+
};
|
|
113
|
+
const addFiles = async (id, args) => {
|
|
114
|
+
const storeId = requireText("addFiles", "id", id);
|
|
115
|
+
if (args.files.length === 0) {
|
|
116
|
+
throw new errors_1.ConnectorError("INVALID_ARG", "vectorStores.addFiles: files must not be empty");
|
|
117
|
+
}
|
|
118
|
+
const ai = resolveAi();
|
|
119
|
+
const form = new FormData();
|
|
120
|
+
for (const file of args.files) {
|
|
121
|
+
form.append("files", file, file.name);
|
|
122
|
+
}
|
|
123
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}/files`, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: labelledHeaders(ai),
|
|
126
|
+
body: form,
|
|
127
|
+
signal: args.signal,
|
|
128
|
+
}, "vectorStores.addFiles");
|
|
129
|
+
return (0, types_1.mapAddVectorStoreFilesResult)(body);
|
|
130
|
+
};
|
|
131
|
+
const listFiles = async (id, opts = {}) => {
|
|
132
|
+
const storeId = requireText("listFiles", "id", id);
|
|
133
|
+
const ai = resolveAi();
|
|
134
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}/files`, { method: "GET", headers: requestHeaders(ai), signal: opts.signal }, "vectorStores.listFiles");
|
|
135
|
+
return (0, types_1.mapVectorStoreFileList)(body);
|
|
136
|
+
};
|
|
137
|
+
const renew = async (id, args) => {
|
|
138
|
+
const storeId = requireText("renew", "id", id);
|
|
139
|
+
requireExpiryDays("renew", args.expiresAfterDays);
|
|
140
|
+
const ai = resolveAi();
|
|
141
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}`, {
|
|
142
|
+
method: "PATCH",
|
|
143
|
+
headers: requestHeaders(ai, "application/json"),
|
|
144
|
+
body: JSON.stringify({ expiresAfterDays: args.expiresAfterDays }),
|
|
145
|
+
signal: args.signal,
|
|
146
|
+
}, "vectorStores.renew");
|
|
147
|
+
return (0, types_1.mapVectorStore)(body);
|
|
148
|
+
};
|
|
149
|
+
const rename = async (id, name, opts = {}) => {
|
|
150
|
+
const storeId = requireText("rename", "id", id);
|
|
151
|
+
const newName = requireText("rename", "name", name);
|
|
152
|
+
const ai = resolveAi();
|
|
153
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}`, {
|
|
154
|
+
method: "PATCH",
|
|
155
|
+
headers: requestHeaders(ai, "application/json"),
|
|
156
|
+
body: JSON.stringify({ name: newName }),
|
|
157
|
+
signal: opts.signal,
|
|
158
|
+
}, "vectorStores.rename");
|
|
159
|
+
return (0, types_1.mapVectorStore)(body);
|
|
160
|
+
};
|
|
161
|
+
const rebuild = async (id, args = {}) => {
|
|
162
|
+
const storeId = requireText("rebuild", "id", id);
|
|
163
|
+
if (args.expiresAfterDays !== undefined) {
|
|
164
|
+
requireExpiryDays("rebuild", args.expiresAfterDays);
|
|
165
|
+
}
|
|
166
|
+
const ai = resolveAi();
|
|
167
|
+
const body = await requestJson(ai, `/${encodeURIComponent(storeId)}/rebuild`, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: requestHeaders(ai, "application/json"),
|
|
170
|
+
body: JSON.stringify({ expiresAfterDays: args.expiresAfterDays }),
|
|
171
|
+
signal: args.signal,
|
|
172
|
+
}, "vectorStores.rebuild");
|
|
173
|
+
return (0, types_1.mapVectorStore)(body);
|
|
174
|
+
};
|
|
175
|
+
const deleteFile = async (id, fileId, opts = {}) => {
|
|
176
|
+
const storeId = requireText("deleteFile", "id", id);
|
|
177
|
+
const storeFileId = requireText("deleteFile", "fileId", fileId);
|
|
178
|
+
const ai = resolveAi();
|
|
179
|
+
await request(ai, `/${encodeURIComponent(storeId)}/files/${encodeURIComponent(storeFileId)}`, { method: "DELETE", headers: requestHeaders(ai), signal: opts.signal }, "vectorStores.deleteFile");
|
|
180
|
+
};
|
|
181
|
+
const remove = async (id, opts = {}) => {
|
|
182
|
+
const storeId = requireText("delete", "id", id);
|
|
183
|
+
const ai = resolveAi();
|
|
184
|
+
await request(ai, `/${encodeURIComponent(storeId)}`, { method: "DELETE", headers: requestHeaders(ai), signal: opts.signal }, "vectorStores.delete");
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
create,
|
|
188
|
+
get,
|
|
189
|
+
addFiles,
|
|
190
|
+
listFiles,
|
|
191
|
+
renew,
|
|
192
|
+
rename,
|
|
193
|
+
rebuild,
|
|
194
|
+
deleteFile,
|
|
195
|
+
delete: remove,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// Ready-made singleton bound to the live shell bridge.
|
|
199
|
+
exports.vectorStores = createVectorStoresConnector();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConnectorDeps } from "./deps";
|
|
2
2
|
import { type SearchArgs, type SearchFilter, type SearchPage } from "./search";
|
|
3
|
-
import { type WorkAuditEvent, type WorkDetail, type WorkRow, type WorkSummary } from "./types";
|
|
3
|
+
import { type WorkAccessInfo, type WorkAuditEvent, type WorkDetail, type WorkRow, type WorkSummary } from "./types";
|
|
4
4
|
export interface StartWorkArgs {
|
|
5
5
|
flowId: string;
|
|
6
6
|
stepName?: string;
|
|
@@ -64,13 +64,25 @@ export interface ListRelatedWorkArgs {
|
|
|
64
64
|
}
|
|
65
65
|
export interface WorkConnector {
|
|
66
66
|
start(args: StartWorkArgs): Promise<WorkDetail>;
|
|
67
|
+
/**
|
|
68
|
+
* The work item. Resolves `null` only when it does not exist (a 404); a server that could
|
|
69
|
+
* not be reached with nothing cached throws, so those two are never the same value. See
|
|
70
|
+
* `resolveRead` in readPolicy.ts.
|
|
71
|
+
*/
|
|
67
72
|
get(workId: string, opts?: {
|
|
68
73
|
signal?: AbortSignal;
|
|
69
|
-
}): Promise<WorkDetail>;
|
|
74
|
+
}): Promise<WorkDetail | null>;
|
|
70
75
|
getData(workId: string, opts?: {
|
|
71
76
|
path?: string;
|
|
72
77
|
signal?: AbortSignal;
|
|
73
78
|
}): Promise<unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* The roles the signed-in user holds on this work. Same null/throw rule as `get`; whether the
|
|
81
|
+
* roles permit a given write stays a shell decision — see {@link WorkAccessInfo}.
|
|
82
|
+
*/
|
|
83
|
+
getMyAccess(workId: string, opts?: {
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}): Promise<WorkAccessInfo | null>;
|
|
74
86
|
patchData(workId: string, patch: WorkDataPatch): Promise<unknown>;
|
|
75
87
|
submit(args: SubmitWorkArgs): Promise<WorkDetail>;
|
|
76
88
|
delete(workId: string, opts?: {
|
package/build/connectors/work.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.buildAdditionalProperties = buildAdditionalProperties;
|
|
|
5
5
|
exports.createWorkConnector = createWorkConnector;
|
|
6
6
|
const _internal_1 = require("../_internal");
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
|
+
const readPolicy_1 = require("./readPolicy");
|
|
8
9
|
const search_1 = require("./search");
|
|
9
10
|
const types_1 = require("./types");
|
|
10
11
|
// Wire codes of the platform's PatchOperation enum.
|
|
@@ -55,29 +56,51 @@ function createWorkConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
55
56
|
throw (0, errors_1.toConnectorError)(e);
|
|
56
57
|
}
|
|
57
58
|
};
|
|
58
|
-
const get =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
59
|
+
const get = (workId, opts = {}) => (0, readPolicy_1.resolveRead)({
|
|
60
|
+
shell: deps.shell,
|
|
61
|
+
signal: opts.signal,
|
|
62
|
+
network: async (signal) => {
|
|
63
|
+
const { data } = await workApi().get(`/api/v4/work/${workId}`, { signal });
|
|
63
64
|
return (0, types_1.mapWorkDetail)(data ?? {});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
},
|
|
66
|
+
// Same mapper as the network branch, so the two sources stay shape-identical by construction.
|
|
67
|
+
cache: (api) => {
|
|
68
|
+
const poco = api.readWork(workId);
|
|
69
|
+
return poco ? (0, types_1.mapWorkDetail)(poco) : null;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
// `async` so the path guard below rejects rather than throwing synchronously.
|
|
69
73
|
const getData = async (workId, opts = {}) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
signal: opts.signal,
|
|
74
|
-
});
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
throw (0, errors_1.toConnectorError)(e);
|
|
74
|
+
// Rejected before a source is chosen: resolved locally `..` yields an array, the endpoint a scalar.
|
|
75
|
+
if (opts.path?.includes("..")) {
|
|
76
|
+
throw new errors_1.ConnectorError("INVALID_ARG", `getData does not support recursive-descent paths ('..'): '${opts.path}'.`);
|
|
79
77
|
}
|
|
78
|
+
// Normalised once so both sources receive the same thing (blank = the whole document).
|
|
79
|
+
const path = opts.path?.trim() || undefined;
|
|
80
|
+
return (0, readPolicy_1.resolveRead)({
|
|
81
|
+
shell: deps.shell,
|
|
82
|
+
signal: opts.signal,
|
|
83
|
+
network: async (signal) => {
|
|
84
|
+
const { data } = await workApi().get(`/api/v4/work/${workId}/data`, { params: { path }, signal });
|
|
85
|
+
return data ?? null;
|
|
86
|
+
},
|
|
87
|
+
// The shell resolves `path` with the same jsonpath dialect the server's `?path=` speaks.
|
|
88
|
+
cache: (api) => api.readWorkData(workId, { path }),
|
|
89
|
+
});
|
|
80
90
|
};
|
|
91
|
+
const getMyAccess = (workId, opts = {}) => (0, readPolicy_1.resolveRead)({
|
|
92
|
+
shell: deps.shell,
|
|
93
|
+
signal: opts.signal,
|
|
94
|
+
network: async (signal) => {
|
|
95
|
+
const { data } = await workApi().get(`/api/v4/work/${workId}/my-roles`, { signal });
|
|
96
|
+
return (0, types_1.mapWorkAccess)(data);
|
|
97
|
+
},
|
|
98
|
+
cache: (api) => {
|
|
99
|
+
const roles = api.readMyWorkAccess(workId);
|
|
100
|
+
// `[]` is a real answer (downloaded, no roles); only a genuine miss means "not downloaded".
|
|
101
|
+
return roles === null ? null : (0, types_1.mapWorkAccess)(roles);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
81
104
|
const patchData = async (workId, patch) => {
|
|
82
105
|
try {
|
|
83
106
|
const { data } = await workApi().patch(`/api/v4/work/${workId}/data`, {
|
|
@@ -223,6 +246,7 @@ function createWorkConnector(deps = { shell: _internal_1.requireShell }) {
|
|
|
223
246
|
start,
|
|
224
247
|
get,
|
|
225
248
|
getData,
|
|
249
|
+
getMyAccess,
|
|
226
250
|
patchData,
|
|
227
251
|
submit,
|
|
228
252
|
delete: del,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type AgentChatSession, type AgentsConnector, type CreateAgentChatArgs, type ListChatsArgs, type RunAgentArgs } from "../connectors/agents";
|
|
2
|
+
import { type AssetRowPage, type AssetSearchPage, type AssetsConnector, type CreateAssetArgs, type IterateAssetRowsArgs, type ListAssetRowsArgs, type QuickSearchAssetsArgs } from "../connectors/assets";
|
|
3
|
+
import { type FlowsConnector } from "../connectors/flows";
|
|
4
|
+
import { type IntegrationsConnector, type InvokeIntegrationEndpointArgs } from "../connectors/integrations";
|
|
5
|
+
import type { SearchArgs } from "../connectors/search";
|
|
6
|
+
import type { AgentChatPage, AgentRunEvent, AssetSummary, Flow, FlowConfig, IntegrationInvokeResult, RiseAgent, WorkDetail, WorkRow } from "../connectors/types";
|
|
7
|
+
import { type IterateWorkRowsArgs, type ListWorkRowsArgs, type StartWorkArgs, type WorkConnector, type WorkRowPage, type WorkSearchPage } from "../connectors/work";
|
|
8
|
+
import type { ResolvedAgentDependency, ResolvedAppManifest, ResolvedAssetTypeDependency, ResolvedFlowDependency, ResolvedIntegrationDependency } from "../manifest";
|
|
9
|
+
export interface BoundFlowSurface {
|
|
10
|
+
get(opts?: {
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}): Promise<Flow>;
|
|
13
|
+
getConfig(opts?: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}): Promise<FlowConfig | null>;
|
|
16
|
+
}
|
|
17
|
+
export interface BoundWorkSurface {
|
|
18
|
+
start(args?: Omit<StartWorkArgs, "flowId">): Promise<WorkDetail>;
|
|
19
|
+
list(args?: Omit<ListWorkRowsArgs, "flow">): Promise<WorkRowPage>;
|
|
20
|
+
iterate(args?: Omit<IterateWorkRowsArgs, "flow">): AsyncIterable<WorkRow>;
|
|
21
|
+
search(args?: SearchArgs): Promise<WorkSearchPage>;
|
|
22
|
+
}
|
|
23
|
+
export interface BoundAssetsSurface {
|
|
24
|
+
list(args?: Omit<ListAssetRowsArgs, "type">): Promise<AssetRowPage>;
|
|
25
|
+
iterate(args?: Omit<IterateAssetRowsArgs, "type">): AsyncIterable<AssetSummary>;
|
|
26
|
+
search(args?: SearchArgs): Promise<AssetSearchPage>;
|
|
27
|
+
quickSearch(args?: Omit<QuickSearchAssetsArgs, "typeOriginId">): Promise<AssetSummary[]>;
|
|
28
|
+
create(args?: Omit<CreateAssetArgs, "type">): Promise<WorkDetail>;
|
|
29
|
+
}
|
|
30
|
+
export interface BoundAgentSurface {
|
|
31
|
+
get(opts?: {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}): Promise<RiseAgent>;
|
|
34
|
+
run(args: Omit<RunAgentArgs, "agentId">): AsyncIterable<AgentRunEvent>;
|
|
35
|
+
createChat(args?: Omit<CreateAgentChatArgs, "agentId">): AgentChatSession;
|
|
36
|
+
listChats(args?: Omit<ListChatsArgs, "agentId">): Promise<AgentChatPage>;
|
|
37
|
+
}
|
|
38
|
+
export interface BoundFlowDependency extends ResolvedFlowDependency {
|
|
39
|
+
flow: BoundFlowSurface;
|
|
40
|
+
work: BoundWorkSurface;
|
|
41
|
+
}
|
|
42
|
+
export interface BoundAssetTypeDependency extends ResolvedAssetTypeDependency {
|
|
43
|
+
assets: BoundAssetsSurface;
|
|
44
|
+
}
|
|
45
|
+
export interface BoundAgentDependency extends ResolvedAgentDependency {
|
|
46
|
+
agent: BoundAgentSurface;
|
|
47
|
+
}
|
|
48
|
+
export interface BoundIntegrationSurface {
|
|
49
|
+
invoke(args?: Omit<InvokeIntegrationEndpointArgs, "integrationId" | "endpointId">): Promise<IntegrationInvokeResult>;
|
|
50
|
+
}
|
|
51
|
+
export interface BoundIntegrationDependency extends ResolvedIntegrationDependency {
|
|
52
|
+
integration: BoundIntegrationSurface;
|
|
53
|
+
}
|
|
54
|
+
export type AppDependency = BoundFlowDependency | BoundAssetTypeDependency | BoundAgentDependency | BoundIntegrationDependency;
|
|
55
|
+
export type AppDependencyMap = Record<string, AppDependency>;
|
|
56
|
+
export interface AppDependencyConnectors {
|
|
57
|
+
flows: FlowsConnector;
|
|
58
|
+
work: WorkConnector;
|
|
59
|
+
assets: AssetsConnector;
|
|
60
|
+
agents: AgentsConnector;
|
|
61
|
+
integrations: IntegrationsConnector;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Binds a resolved manifest to the connectors. Internal: the testing seam for
|
|
65
|
+
* the bound delegations, taking injected connectors. Kept off the /dependencies
|
|
66
|
+
* barrel; app code calls getAppDependencies().
|
|
67
|
+
*/
|
|
68
|
+
export declare function bindAppDependencies(manifest: ResolvedAppManifest, connectors?: Partial<AppDependencyConnectors>): AppDependencyMap;
|
|
69
|
+
/**
|
|
70
|
+
* Every dependency the app declared, bound to the connectors. Throws when no
|
|
71
|
+
* manifest is available. The returned map is stable across calls, so it is safe
|
|
72
|
+
* as a hook/effect dependency.
|
|
73
|
+
*
|
|
74
|
+
* Pass your app's alias map as `T` to get the aliases typed:
|
|
75
|
+
* `getAppDependencies<{ riskFlow: BoundFlowDependency }>()`.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getAppDependencies<T extends AppDependencyMap = AppDependencyMap>(): T;
|
|
78
|
+
export declare function tryGetAppDependencies(): AppDependencyMap | null;
|
|
79
|
+
/** One declared dependency by alias. Throws, naming the known aliases, when it
|
|
80
|
+
* is not declared. */
|
|
81
|
+
export declare function getAppDependency(alias: string): AppDependency;
|
|
82
|
+
/**
|
|
83
|
+
* Hook form of getAppDependencies(). The manifest is a build-time constant, so
|
|
84
|
+
* this holds no state and the result is referentially stable — it is a hook for
|
|
85
|
+
* call-site consistency with useShellUser/useShellEnvironment.
|
|
86
|
+
*/
|
|
87
|
+
export declare function useAppDependencies<T extends AppDependencyMap = AppDependencyMap>(): T;
|