@palettelab/sdk 0.1.15 → 0.1.16
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 +26 -0
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/{index-Bu5EQGYo.d.mts → index-BGT6xBGD.d.mts} +1 -1
- package/dist/{index-BDVWt7DE.d.ts → index-Beo6F2Fr.d.ts} +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +235 -27
- package/dist/index.mjs +236 -26
- package/dist/{plugin-UV46q1mU.d.mts → plugin-CG6spHKI.d.mts} +3 -1
- package/dist/{plugin-UV46q1mU.d.ts → plugin-CG6spHKI.d.ts} +3 -1
- package/dist/router/index.d.mts +346 -0
- package/dist/router/index.d.ts +346 -0
- package/dist/router/index.js +247 -0
- package/dist/router/index.mjs +225 -0
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -257,6 +257,32 @@ The CLI reads that config in `pltt dev`, `pltt test`, `pltt package`, and
|
|
|
257
257
|
`NEXT_PUBLIC_*` environment variables, and path aliases from
|
|
258
258
|
`frontend/tsconfig.json`.
|
|
259
259
|
|
|
260
|
+
## Palette App Router
|
|
261
|
+
|
|
262
|
+
For OS-native routed apps, set `frontend.framework` to `palette-app` and point
|
|
263
|
+
`frontend.entry` at `frontend/app`. The CLI scans app-directory UI files and
|
|
264
|
+
still publishes one safe browser bundle.
|
|
265
|
+
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"frontend": {
|
|
269
|
+
"entry": "./frontend/app",
|
|
270
|
+
"sandbox": true,
|
|
271
|
+
"framework": "palette-app"
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Supported UI files are `layout.tsx`, `page.tsx`, `loading.tsx`, `error.tsx`,
|
|
277
|
+
and `not-found.tsx`. Static routes, route groups, `[id]`, `[...slug]`, and
|
|
278
|
+
`[[...slug]]` are supported. Use `Link`, `useRouter`, `usePathname`,
|
|
279
|
+
`useSearchParams`, and `useParams` from `@palettelab/sdk`, or use the
|
|
280
|
+
`next/link` and `next/navigation` compatibility imports in `palette-app`
|
|
281
|
+
projects.
|
|
282
|
+
|
|
283
|
+
Server-side Next features are intentionally not part of this mode. Put APIs,
|
|
284
|
+
database access, permissions, and secrets in the plugin backend.
|
|
285
|
+
|
|
260
286
|
## Palette Client
|
|
261
287
|
|
|
262
288
|
Use `createPaletteClient()` when an app needs common Palette OS services without
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import react__default from 'react';
|
|
3
|
-
import { P as PlatformContext } from '../plugin-
|
|
3
|
+
import { P as PlatformContext } from '../plugin-CG6spHKI.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Provider that wraps plugin components with the platform context.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import react__default from 'react';
|
|
3
|
-
import { P as PlatformContext } from '../plugin-
|
|
3
|
+
import { P as PlatformContext } from '../plugin-CG6spHKI.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Provider that wraps plugin components with the platform context.
|
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { P as PlatformCtx, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from '../index-
|
|
1
|
+
export { P as PlatformCtx, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from '../index-BGT6xBGD.mjs';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../plugin-
|
|
3
|
+
import '../plugin-CG6spHKI.mjs';
|
|
4
4
|
import '../data-room-Dtd9LLHf.mjs';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { P as PlatformCtx, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from '../index-
|
|
1
|
+
export { P as PlatformCtx, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from '../index-Beo6F2Fr.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../plugin-
|
|
3
|
+
import '../plugin-CG6spHKI.js';
|
|
4
4
|
import '../data-room-Dtd9LLHf.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { d as PaletteLanguage, P as PlatformContext } from './plugin-
|
|
2
|
+
import { d as PaletteLanguage, P as PlatformContext } from './plugin-CG6spHKI.mjs';
|
|
3
3
|
import { T as Task, i as TaskStats, g as TaskCreatePayload, l as TaskUpdatePayload, D as DataRoom, a as DataRoomFolder, b as DataRoomFile, d as ChatThread, c as ChatMessage } from './data-room-Dtd9LLHf.mjs';
|
|
4
4
|
|
|
5
5
|
type TranslationPrimitive = string | number | boolean | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { d as PaletteLanguage, P as PlatformContext } from './plugin-
|
|
2
|
+
import { d as PaletteLanguage, P as PlatformContext } from './plugin-CG6spHKI.js';
|
|
3
3
|
import { T as Task, i as TaskStats, g as TaskCreatePayload, l as TaskUpdatePayload, D as DataRoom, a as DataRoomFolder, b as DataRoomFile, d as ChatThread, c as ChatMessage } from './data-room-Dtd9LLHf.js';
|
|
4
4
|
|
|
5
5
|
type TranslationPrimitive = string | number | boolean | null;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-
|
|
2
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PaletteLanguage, e as PluginAgentDefinition, f as PluginComponentProps, g as PluginManifest, h as PluginToolDefinition } from './plugin-
|
|
1
|
+
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-CG6spHKI.mjs';
|
|
2
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PaletteLanguage, e as PluginAgentDefinition, f as PluginComponentProps, g as PluginManifest, h as PluginToolDefinition } from './plugin-CG6spHKI.mjs';
|
|
3
3
|
import { D as DataRoom, a as DataRoomFolder, b as DataRoomFile } from './data-room-Dtd9LLHf.mjs';
|
|
4
4
|
export { C as ChatAttachment, c as ChatMessage, d as ChatThread, e as DataRoomPermission, T as Task, f as TaskAgentSnippet, g as TaskCreatePayload, h as TaskPriority, i as TaskStats, j as TaskStatus, k as TaskType, l as TaskUpdatePayload } from './data-room-Dtd9LLHf.mjs';
|
|
5
5
|
export { AgentResource, ResourcesByGroup } from './types/index.mjs';
|
|
6
6
|
import { ReactElement } from 'react';
|
|
7
|
-
export { P as PlatformCtx, T as TranslateOptions, a as TranslationDictionary, b as TranslationPrimitive, c as TranslationResources, d as TranslationValues, U as UsePluginTranslationsOptions, n as normalizePaletteLanguage, t as translate, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from './index-
|
|
7
|
+
export { P as PlatformCtx, T as TranslateOptions, a as TranslationDictionary, b as TranslationPrimitive, c as TranslationResources, d as TranslationValues, U as UsePluginTranslationsOptions, n as normalizePaletteLanguage, t as translate, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from './index-BGT6xBGD.mjs';
|
|
8
|
+
export { Link, PaletteAppRoute, PaletteAppRouter, notFound, useParams, usePathname, useRouter, useSearchParams } from './router/index.mjs';
|
|
8
9
|
export { PluginProvider } from './components/index.mjs';
|
|
9
10
|
import 'react/jsx-runtime';
|
|
10
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-
|
|
2
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PaletteLanguage, e as PluginAgentDefinition, f as PluginComponentProps, g as PluginManifest, h as PluginToolDefinition } from './plugin-
|
|
1
|
+
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-CG6spHKI.js';
|
|
2
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PaletteLanguage, e as PluginAgentDefinition, f as PluginComponentProps, g as PluginManifest, h as PluginToolDefinition } from './plugin-CG6spHKI.js';
|
|
3
3
|
import { D as DataRoom, a as DataRoomFolder, b as DataRoomFile } from './data-room-Dtd9LLHf.js';
|
|
4
4
|
export { C as ChatAttachment, c as ChatMessage, d as ChatThread, e as DataRoomPermission, T as Task, f as TaskAgentSnippet, g as TaskCreatePayload, h as TaskPriority, i as TaskStats, j as TaskStatus, k as TaskType, l as TaskUpdatePayload } from './data-room-Dtd9LLHf.js';
|
|
5
5
|
export { AgentResource, ResourcesByGroup } from './types/index.js';
|
|
6
6
|
import { ReactElement } from 'react';
|
|
7
|
-
export { P as PlatformCtx, T as TranslateOptions, a as TranslationDictionary, b as TranslationPrimitive, c as TranslationResources, d as TranslationValues, U as UsePluginTranslationsOptions, n as normalizePaletteLanguage, t as translate, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from './index-
|
|
7
|
+
export { P as PlatformCtx, T as TranslateOptions, a as TranslationDictionary, b as TranslationPrimitive, c as TranslationResources, d as TranslationValues, U as UsePluginTranslationsOptions, n as normalizePaletteLanguage, t as translate, u as usePlatform, e as usePluginChat, f as usePluginDataRooms, g as usePluginTasks, h as usePluginTranslations } from './index-Beo6F2Fr.js';
|
|
8
|
+
export { Link, PaletteAppRoute, PaletteAppRouter, notFound, useParams, usePathname, useRouter, useSearchParams } from './router/index.js';
|
|
8
9
|
export { PluginProvider } from './components/index.js';
|
|
9
10
|
import 'react/jsx-runtime';
|
|
10
11
|
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
DataRoomClient: () => DataRoomClient,
|
|
24
|
+
Link: () => Link,
|
|
24
25
|
OrganizationClient: () => OrganizationClient,
|
|
25
26
|
PaletteApiError: () => PaletteApiError,
|
|
27
|
+
PaletteAppRouter: () => PaletteAppRouter,
|
|
26
28
|
PlatformCtx: () => PlatformCtx,
|
|
27
29
|
PluginProvider: () => PluginProvider,
|
|
28
30
|
StorageClient: () => StorageClient,
|
|
@@ -42,15 +44,20 @@ __export(src_exports, {
|
|
|
42
44
|
isPaletteApiError: () => isPaletteApiError,
|
|
43
45
|
isSandboxRuntime: () => isSandboxRuntime,
|
|
44
46
|
normalizePaletteLanguage: () => normalizePaletteLanguage,
|
|
47
|
+
notFound: () => notFound,
|
|
45
48
|
setBaseUrl: () => setBaseUrl,
|
|
46
49
|
translate: () => translate,
|
|
47
50
|
updateInstallConfig: () => updateInstallConfig,
|
|
48
51
|
uploadToSignedUrl: () => uploadToSignedUrl,
|
|
52
|
+
useParams: () => useParams,
|
|
53
|
+
usePathname: () => usePathname,
|
|
49
54
|
usePlatform: () => usePlatform,
|
|
50
55
|
usePluginChat: () => usePluginChat,
|
|
51
56
|
usePluginDataRooms: () => usePluginDataRooms,
|
|
52
57
|
usePluginTasks: () => usePluginTasks,
|
|
53
58
|
usePluginTranslations: () => usePluginTranslations,
|
|
59
|
+
useRouter: () => useRouter,
|
|
60
|
+
useSearchParams: () => useSearchParams,
|
|
54
61
|
withPluginProvider: () => withPluginProvider
|
|
55
62
|
});
|
|
56
63
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -228,6 +235,7 @@ function createMockPlatformContext(overrides = {}) {
|
|
|
228
235
|
apiFetch: async () => new Response(JSON.stringify({}), { status: 200 }),
|
|
229
236
|
navigate: () => {
|
|
230
237
|
},
|
|
238
|
+
routePath: "/",
|
|
231
239
|
showToast: () => {
|
|
232
240
|
},
|
|
233
241
|
...overrides
|
|
@@ -717,14 +725,207 @@ function usePluginTranslations(resources, options = {}) {
|
|
|
717
725
|
};
|
|
718
726
|
}
|
|
719
727
|
|
|
720
|
-
// src/
|
|
728
|
+
// src/router.tsx
|
|
721
729
|
var import_react4 = require("react");
|
|
730
|
+
var RouterCtx = (0, import_react4.createContext)(null);
|
|
731
|
+
var NOT_FOUND = /* @__PURE__ */ Symbol.for("palette.router.not-found");
|
|
732
|
+
function notFound() {
|
|
733
|
+
throw Object.assign(new Error("Palette route not found"), { code: NOT_FOUND });
|
|
734
|
+
}
|
|
735
|
+
function normalizePath(path) {
|
|
736
|
+
const clean = String(path || "/").split("#")[0].split("?")[0] || "/";
|
|
737
|
+
return `/${clean.replace(/^\/+/, "").replace(/\/+$/, "")}`.replace(/^\/$/, "/");
|
|
738
|
+
}
|
|
739
|
+
function splitPath(path) {
|
|
740
|
+
return normalizePath(path).split("/").filter(Boolean).map(decodeURIComponent);
|
|
741
|
+
}
|
|
742
|
+
function routeScore(route) {
|
|
743
|
+
if (typeof route.score === "number") return route.score;
|
|
744
|
+
return route.segments.reduce((score, segment) => {
|
|
745
|
+
if (segment.kind === "static") return score + 10;
|
|
746
|
+
if (segment.kind === "dynamic") return score + 5;
|
|
747
|
+
return score + (segment.optional ? 1 : 2);
|
|
748
|
+
}, route.segments.length);
|
|
749
|
+
}
|
|
750
|
+
function matchRoute(route, path) {
|
|
751
|
+
const parts = splitPath(path);
|
|
752
|
+
const params = {};
|
|
753
|
+
let index = 0;
|
|
754
|
+
for (const segment of route.segments) {
|
|
755
|
+
if (segment.kind === "catchAll") {
|
|
756
|
+
const rest = parts.slice(index);
|
|
757
|
+
if (!segment.optional && rest.length === 0) return null;
|
|
758
|
+
params[segment.name] = rest;
|
|
759
|
+
index = parts.length;
|
|
760
|
+
break;
|
|
761
|
+
}
|
|
762
|
+
const value = parts[index];
|
|
763
|
+
if (value === void 0) return null;
|
|
764
|
+
if (segment.kind === "static") {
|
|
765
|
+
if (value !== segment.value) return null;
|
|
766
|
+
} else {
|
|
767
|
+
params[segment.name] = value;
|
|
768
|
+
}
|
|
769
|
+
index += 1;
|
|
770
|
+
}
|
|
771
|
+
return index === parts.length ? params : null;
|
|
772
|
+
}
|
|
773
|
+
function currentPluginPath(pluginId, routePath) {
|
|
774
|
+
if (routePath) return normalizePath(routePath);
|
|
775
|
+
if (typeof window === "undefined") return "/";
|
|
776
|
+
const path = window.location.pathname;
|
|
777
|
+
if (pluginId) {
|
|
778
|
+
const prefix = `/apps/${pluginId}`;
|
|
779
|
+
if (path === prefix) return "/";
|
|
780
|
+
if (path.startsWith(`${prefix}/`)) return normalizePath(path.slice(prefix.length));
|
|
781
|
+
}
|
|
782
|
+
return normalizePath(path);
|
|
783
|
+
}
|
|
784
|
+
function currentSearchParams() {
|
|
785
|
+
if (typeof window === "undefined") return new URLSearchParams();
|
|
786
|
+
return new URLSearchParams(window.location.search);
|
|
787
|
+
}
|
|
788
|
+
var PaletteRouteErrorBoundary = class extends import_react4.Component {
|
|
789
|
+
constructor() {
|
|
790
|
+
super(...arguments);
|
|
791
|
+
this.state = { error: null };
|
|
792
|
+
this.reset = () => this.setState({ error: null });
|
|
793
|
+
}
|
|
794
|
+
static getDerivedStateFromError(error) {
|
|
795
|
+
return { error };
|
|
796
|
+
}
|
|
797
|
+
componentDidCatch(_error, _info) {
|
|
798
|
+
}
|
|
799
|
+
render() {
|
|
800
|
+
const error = this.state.error;
|
|
801
|
+
if (!error) return this.props.children;
|
|
802
|
+
if (error.code === NOT_FOUND && this.props.notFound) {
|
|
803
|
+
return (0, import_react4.createElement)(this.props.notFound);
|
|
804
|
+
}
|
|
805
|
+
if (this.props.fallback) {
|
|
806
|
+
return (0, import_react4.createElement)(this.props.fallback, { error, reset: this.reset });
|
|
807
|
+
}
|
|
808
|
+
throw error;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
function renderRoute(route) {
|
|
812
|
+
const page = (0, import_react4.createElement)(route.page);
|
|
813
|
+
const wrapped = (route.layouts || []).reduceRight(
|
|
814
|
+
(children, Layout) => (0, import_react4.createElement)(Layout, null, children),
|
|
815
|
+
page
|
|
816
|
+
);
|
|
817
|
+
return (0, import_react4.createElement)(
|
|
818
|
+
PaletteRouteErrorBoundary,
|
|
819
|
+
{ fallback: route.error, notFound: route.notFound },
|
|
820
|
+
wrapped
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
function PaletteAppRouter({
|
|
824
|
+
routes,
|
|
825
|
+
notFound: NotFound
|
|
826
|
+
}) {
|
|
827
|
+
const platform = usePlatform();
|
|
828
|
+
const [location, setLocation] = (0, import_react4.useState)(() => ({
|
|
829
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
830
|
+
searchParams: currentSearchParams()
|
|
831
|
+
}));
|
|
832
|
+
(0, import_react4.useEffect)(() => {
|
|
833
|
+
setLocation({
|
|
834
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
835
|
+
searchParams: currentSearchParams()
|
|
836
|
+
});
|
|
837
|
+
}, [platform.pluginId, platform.routePath]);
|
|
838
|
+
(0, import_react4.useEffect)(() => {
|
|
839
|
+
const sync = () => setLocation({
|
|
840
|
+
pathname: currentPluginPath(platform.pluginId, platform.routePath),
|
|
841
|
+
searchParams: currentSearchParams()
|
|
842
|
+
});
|
|
843
|
+
window.addEventListener("popstate", sync);
|
|
844
|
+
return () => window.removeEventListener("popstate", sync);
|
|
845
|
+
}, [platform.pluginId, platform.routePath]);
|
|
846
|
+
const sortedRoutes = (0, import_react4.useMemo)(
|
|
847
|
+
() => [...routes].sort((a, b) => routeScore(b) - routeScore(a)),
|
|
848
|
+
[routes]
|
|
849
|
+
);
|
|
850
|
+
const matched = (0, import_react4.useMemo)(() => {
|
|
851
|
+
for (const route of sortedRoutes) {
|
|
852
|
+
const params = matchRoute(route, location.pathname);
|
|
853
|
+
if (params) return { route, params };
|
|
854
|
+
}
|
|
855
|
+
return null;
|
|
856
|
+
}, [location.pathname, sortedRoutes]);
|
|
857
|
+
const navigate = (0, import_react4.useCallback)((target, replace = false) => {
|
|
858
|
+
const [pathPart, queryPart = ""] = String(target || "/").split("?");
|
|
859
|
+
const pathname = normalizePath(pathPart);
|
|
860
|
+
const next = `${pathname}${queryPart ? `?${queryPart}` : ""}`;
|
|
861
|
+
setLocation({ pathname, searchParams: new URLSearchParams(queryPart) });
|
|
862
|
+
const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
|
|
863
|
+
const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
|
|
864
|
+
const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
|
|
865
|
+
if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
|
|
866
|
+
else platform.navigate(osPath);
|
|
867
|
+
}, [platform]);
|
|
868
|
+
const state = (0, import_react4.useMemo)(() => ({
|
|
869
|
+
pathname: location.pathname,
|
|
870
|
+
searchParams: location.searchParams,
|
|
871
|
+
params: matched?.params || {},
|
|
872
|
+
push: (path) => navigate(path, false),
|
|
873
|
+
replace: (path) => navigate(path, true)
|
|
874
|
+
}), [location.pathname, location.searchParams, matched?.params, navigate]);
|
|
875
|
+
const content = matched ? renderRoute(matched.route) : NotFound ? (0, import_react4.createElement)(NotFound) : (0, import_react4.createElement)("div", null, "Page not found");
|
|
876
|
+
return (0, import_react4.createElement)(RouterCtx.Provider, { value: state }, content);
|
|
877
|
+
}
|
|
878
|
+
function useRouterState() {
|
|
879
|
+
const value = (0, import_react4.useContext)(RouterCtx);
|
|
880
|
+
if (!value) throw new Error("Palette app router hooks must be used inside PaletteAppRouter");
|
|
881
|
+
return value;
|
|
882
|
+
}
|
|
883
|
+
function useRouter() {
|
|
884
|
+
const { push, replace } = useRouterState();
|
|
885
|
+
return { push, replace, back: () => window.history.back(), forward: () => window.history.forward() };
|
|
886
|
+
}
|
|
887
|
+
function usePathname() {
|
|
888
|
+
return useRouterState().pathname;
|
|
889
|
+
}
|
|
890
|
+
function useSearchParams() {
|
|
891
|
+
return useRouterState().searchParams;
|
|
892
|
+
}
|
|
893
|
+
function useParams() {
|
|
894
|
+
return useRouterState().params;
|
|
895
|
+
}
|
|
896
|
+
function Link({
|
|
897
|
+
href,
|
|
898
|
+
replace,
|
|
899
|
+
onClick,
|
|
900
|
+
children,
|
|
901
|
+
...props
|
|
902
|
+
}) {
|
|
903
|
+
const router = useRouter();
|
|
904
|
+
return (0, import_react4.createElement)(
|
|
905
|
+
"a",
|
|
906
|
+
{
|
|
907
|
+
...props,
|
|
908
|
+
href,
|
|
909
|
+
onClick: (event) => {
|
|
910
|
+
onClick?.(event);
|
|
911
|
+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
912
|
+
event.preventDefault();
|
|
913
|
+
if (replace) router.replace(href);
|
|
914
|
+
else router.push(href);
|
|
915
|
+
}
|
|
916
|
+
},
|
|
917
|
+
children
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/hooks/use-plugin-tasks.ts
|
|
922
|
+
var import_react5 = require("react");
|
|
722
923
|
function usePluginTasks(agentId) {
|
|
723
924
|
const { apiFetch: apiFetch2 } = usePlatform();
|
|
724
|
-
const [tasks, setTasks] = (0,
|
|
725
|
-
const [stats, setStats] = (0,
|
|
726
|
-
const [loading, setLoading] = (0,
|
|
727
|
-
const fetchTasks = (0,
|
|
925
|
+
const [tasks, setTasks] = (0, import_react5.useState)([]);
|
|
926
|
+
const [stats, setStats] = (0, import_react5.useState)(null);
|
|
927
|
+
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
928
|
+
const fetchTasks = (0, import_react5.useCallback)(async () => {
|
|
728
929
|
try {
|
|
729
930
|
const params = new URLSearchParams();
|
|
730
931
|
if (agentId) params.set("agent_id", String(agentId));
|
|
@@ -733,18 +934,18 @@ function usePluginTasks(agentId) {
|
|
|
733
934
|
} catch {
|
|
734
935
|
}
|
|
735
936
|
}, [apiFetch2, agentId]);
|
|
736
|
-
const fetchStats = (0,
|
|
937
|
+
const fetchStats = (0, import_react5.useCallback)(async () => {
|
|
737
938
|
try {
|
|
738
939
|
const res = await apiFetch2("/api/v1/tasks/stats");
|
|
739
940
|
setStats(await res.json());
|
|
740
941
|
} catch {
|
|
741
942
|
}
|
|
742
943
|
}, [apiFetch2]);
|
|
743
|
-
(0,
|
|
944
|
+
(0, import_react5.useEffect)(() => {
|
|
744
945
|
setLoading(true);
|
|
745
946
|
Promise.all([fetchTasks(), fetchStats()]).finally(() => setLoading(false));
|
|
746
947
|
}, [fetchTasks, fetchStats]);
|
|
747
|
-
const createTask = (0,
|
|
948
|
+
const createTask = (0, import_react5.useCallback)(async (payload) => {
|
|
748
949
|
const res = await apiFetch2("/api/v1/tasks", {
|
|
749
950
|
method: "POST",
|
|
750
951
|
body: JSON.stringify(payload)
|
|
@@ -753,7 +954,7 @@ function usePluginTasks(agentId) {
|
|
|
753
954
|
await Promise.all([fetchTasks(), fetchStats()]);
|
|
754
955
|
return task;
|
|
755
956
|
}, [apiFetch2, fetchTasks, fetchStats]);
|
|
756
|
-
const updateTask = (0,
|
|
957
|
+
const updateTask = (0, import_react5.useCallback)(async (taskId, payload) => {
|
|
757
958
|
const res = await apiFetch2(`/api/v1/tasks/${taskId}`, {
|
|
758
959
|
method: "PATCH",
|
|
759
960
|
body: JSON.stringify(payload)
|
|
@@ -762,7 +963,7 @@ function usePluginTasks(agentId) {
|
|
|
762
963
|
await Promise.all([fetchTasks(), fetchStats()]);
|
|
763
964
|
return task;
|
|
764
965
|
}, [apiFetch2, fetchTasks, fetchStats]);
|
|
765
|
-
const deleteTask = (0,
|
|
966
|
+
const deleteTask = (0, import_react5.useCallback)(async (taskId) => {
|
|
766
967
|
await apiFetch2(`/api/v1/tasks/${taskId}`, { method: "DELETE" });
|
|
767
968
|
await Promise.all([fetchTasks(), fetchStats()]);
|
|
768
969
|
}, [apiFetch2, fetchTasks, fetchStats]);
|
|
@@ -770,23 +971,23 @@ function usePluginTasks(agentId) {
|
|
|
770
971
|
}
|
|
771
972
|
|
|
772
973
|
// src/hooks/use-plugin-data-rooms.ts
|
|
773
|
-
var
|
|
974
|
+
var import_react6 = require("react");
|
|
774
975
|
function usePluginDataRooms() {
|
|
775
976
|
const { apiFetch: apiFetch2 } = usePlatform();
|
|
776
|
-
const [rooms, setRooms] = (0,
|
|
777
|
-
const [loading, setLoading] = (0,
|
|
778
|
-
const fetchRooms = (0,
|
|
977
|
+
const [rooms, setRooms] = (0, import_react6.useState)([]);
|
|
978
|
+
const [loading, setLoading] = (0, import_react6.useState)(true);
|
|
979
|
+
const fetchRooms = (0, import_react6.useCallback)(async () => {
|
|
779
980
|
try {
|
|
780
981
|
const res = await apiFetch2("/api/v1/data-rooms");
|
|
781
982
|
setRooms(await res.json());
|
|
782
983
|
} catch {
|
|
783
984
|
}
|
|
784
985
|
}, [apiFetch2]);
|
|
785
|
-
(0,
|
|
986
|
+
(0, import_react6.useEffect)(() => {
|
|
786
987
|
setLoading(true);
|
|
787
988
|
fetchRooms().finally(() => setLoading(false));
|
|
788
989
|
}, [fetchRooms]);
|
|
789
|
-
const fetchFolder = (0,
|
|
990
|
+
const fetchFolder = (0, import_react6.useCallback)(async (roomId, folderId) => {
|
|
790
991
|
const path = folderId ? `/api/v1/data-rooms/${roomId}/folders/${folderId}` : `/api/v1/data-rooms/${roomId}`;
|
|
791
992
|
const res = await apiFetch2(path);
|
|
792
993
|
return res.json();
|
|
@@ -795,19 +996,19 @@ function usePluginDataRooms() {
|
|
|
795
996
|
}
|
|
796
997
|
|
|
797
998
|
// src/hooks/use-plugin-chat.ts
|
|
798
|
-
var
|
|
999
|
+
var import_react7 = require("react");
|
|
799
1000
|
function usePluginChat(agentId) {
|
|
800
1001
|
const { apiFetch: apiFetch2 } = usePlatform();
|
|
801
|
-
const [threads, setThreads] = (0,
|
|
802
|
-
const [messages, setMessages] = (0,
|
|
803
|
-
const [streaming, setStreaming] = (0,
|
|
804
|
-
const [activeThreadId, setActiveThreadId] = (0,
|
|
805
|
-
const abortRef = (0,
|
|
806
|
-
const fetchThreads = (0,
|
|
1002
|
+
const [threads, setThreads] = (0, import_react7.useState)([]);
|
|
1003
|
+
const [messages, setMessages] = (0, import_react7.useState)([]);
|
|
1004
|
+
const [streaming, setStreaming] = (0, import_react7.useState)(false);
|
|
1005
|
+
const [activeThreadId, setActiveThreadId] = (0, import_react7.useState)(null);
|
|
1006
|
+
const abortRef = (0, import_react7.useRef)(null);
|
|
1007
|
+
const fetchThreads = (0, import_react7.useCallback)(async () => {
|
|
807
1008
|
const res = await apiFetch2(`/api/v1/chat/${agentId}/threads`);
|
|
808
1009
|
setThreads(await res.json());
|
|
809
1010
|
}, [apiFetch2, agentId]);
|
|
810
|
-
const createThread = (0,
|
|
1011
|
+
const createThread = (0, import_react7.useCallback)(async () => {
|
|
811
1012
|
const res = await apiFetch2(`/api/v1/chat/${agentId}/threads`, { method: "POST" });
|
|
812
1013
|
const thread = await res.json();
|
|
813
1014
|
setActiveThreadId(thread.id);
|
|
@@ -815,13 +1016,13 @@ function usePluginChat(agentId) {
|
|
|
815
1016
|
await fetchThreads();
|
|
816
1017
|
return thread;
|
|
817
1018
|
}, [apiFetch2, agentId, fetchThreads]);
|
|
818
|
-
const fetchMessages = (0,
|
|
1019
|
+
const fetchMessages = (0, import_react7.useCallback)(async (threadId) => {
|
|
819
1020
|
const res = await apiFetch2(`/api/v1/chat/threads/${threadId}/messages`);
|
|
820
1021
|
const msgs = await res.json();
|
|
821
1022
|
setMessages(msgs);
|
|
822
1023
|
setActiveThreadId(threadId);
|
|
823
1024
|
}, [apiFetch2]);
|
|
824
|
-
const sendMessage = (0,
|
|
1025
|
+
const sendMessage = (0, import_react7.useCallback)(async (threadId, content) => {
|
|
825
1026
|
setStreaming(true);
|
|
826
1027
|
abortRef.current = new AbortController();
|
|
827
1028
|
const userMsg = {
|
|
@@ -889,7 +1090,7 @@ function usePluginChat(agentId) {
|
|
|
889
1090
|
abortRef.current = null;
|
|
890
1091
|
}
|
|
891
1092
|
}, []);
|
|
892
|
-
const stopStreaming = (0,
|
|
1093
|
+
const stopStreaming = (0, import_react7.useCallback)(() => {
|
|
893
1094
|
abortRef.current?.abort();
|
|
894
1095
|
}, []);
|
|
895
1096
|
return {
|
|
@@ -907,8 +1108,10 @@ function usePluginChat(agentId) {
|
|
|
907
1108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
908
1109
|
0 && (module.exports = {
|
|
909
1110
|
DataRoomClient,
|
|
1111
|
+
Link,
|
|
910
1112
|
OrganizationClient,
|
|
911
1113
|
PaletteApiError,
|
|
1114
|
+
PaletteAppRouter,
|
|
912
1115
|
PlatformCtx,
|
|
913
1116
|
PluginProvider,
|
|
914
1117
|
StorageClient,
|
|
@@ -928,14 +1131,19 @@ function usePluginChat(agentId) {
|
|
|
928
1131
|
isPaletteApiError,
|
|
929
1132
|
isSandboxRuntime,
|
|
930
1133
|
normalizePaletteLanguage,
|
|
1134
|
+
notFound,
|
|
931
1135
|
setBaseUrl,
|
|
932
1136
|
translate,
|
|
933
1137
|
updateInstallConfig,
|
|
934
1138
|
uploadToSignedUrl,
|
|
1139
|
+
useParams,
|
|
1140
|
+
usePathname,
|
|
935
1141
|
usePlatform,
|
|
936
1142
|
usePluginChat,
|
|
937
1143
|
usePluginDataRooms,
|
|
938
1144
|
usePluginTasks,
|
|
939
1145
|
usePluginTranslations,
|
|
1146
|
+
useRouter,
|
|
1147
|
+
useSearchParams,
|
|
940
1148
|
withPluginProvider
|
|
941
1149
|
});
|