@palettelab/sdk 0.1.8 → 0.1.10
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 +83 -0
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/{data-room-BP0PjYoe.d.mts → data-room-Dtd9LLHf.d.mts} +1 -1
- package/dist/{data-room-BP0PjYoe.d.ts → data-room-Dtd9LLHf.d.ts} +1 -1
- package/dist/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/index.d.mts +104 -4
- package/dist/index.d.ts +104 -4
- package/dist/index.js +227 -0
- package/dist/index.mjs +217 -0
- package/dist/{plugin-DzSTKgkz.d.mts → plugin-o-qmdCBl.d.mts} +4 -0
- package/dist/{plugin-DzSTKgkz.d.ts → plugin-o-qmdCBl.d.ts} +4 -0
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,7 @@ the developer can immediately test the app inside the OS preview URL.
|
|
|
121
121
|
import {
|
|
122
122
|
PluginProvider,
|
|
123
123
|
usePlatform,
|
|
124
|
+
createPaletteClient,
|
|
124
125
|
usePluginTasks,
|
|
125
126
|
usePluginDataRooms,
|
|
126
127
|
usePluginChat,
|
|
@@ -168,6 +169,88 @@ export default function PluginRoot(props: PluginComponentProps) {
|
|
|
168
169
|
}
|
|
169
170
|
```
|
|
170
171
|
|
|
172
|
+
## Palette Client
|
|
173
|
+
|
|
174
|
+
Use `createPaletteClient()` when an app needs common Palette OS services without
|
|
175
|
+
remembering raw API routes.
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import { createPaletteClient, usePlatform } from "@palettelab/sdk"
|
|
179
|
+
|
|
180
|
+
function App() {
|
|
181
|
+
const platform = usePlatform()
|
|
182
|
+
const palette = createPaletteClient(platform)
|
|
183
|
+
|
|
184
|
+
async function upload(file: File) {
|
|
185
|
+
const rooms = await palette.dataRooms.list()
|
|
186
|
+
await palette.dataRooms.uploadFile(rooms[0].id, file)
|
|
187
|
+
palette.toast.success("Uploaded")
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return <button onClick={() => palette.user.current()}>Load profile</button>
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Included clients:
|
|
195
|
+
|
|
196
|
+
- `palette.user.current()` and `palette.user.updateProfile()`
|
|
197
|
+
- `palette.organization.currentId()`, `currentRole()`, and `listMine()`
|
|
198
|
+
- `palette.dataRooms.list()`, `create()`, `get()`, `folder()`, `createFolder()`, `ensureFolder()`, `findRoomByName()`, `findFolderByName()`, `resolveFolderPath()`, `findFileByName()`, and `uploadFile()`
|
|
199
|
+
- `palette.config.get()` and `palette.config.update(values)`, with optional plugin ID override
|
|
200
|
+
- `palette.permissions.has()`, `hasAny()`, and `hasAll()`
|
|
201
|
+
- `palette.storage.uploadToSignedUrl()`
|
|
202
|
+
- `palette.toast.success()`, `error()`, and `info()`
|
|
203
|
+
|
|
204
|
+
These helpers are intentionally thin wrappers over platform APIs. Apps can still
|
|
205
|
+
use `apiFetch()` directly for custom backend routes.
|
|
206
|
+
|
|
207
|
+
### Data Room Folders By Name
|
|
208
|
+
|
|
209
|
+
Apps can create or reuse custom Data Room folders by name:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
const palette = createPaletteClient(usePlatform())
|
|
213
|
+
|
|
214
|
+
const room = await palette.dataRooms.ensureRoom("Finance")
|
|
215
|
+
const invoices = await palette.dataRooms.ensureFolder(room.id, "Invoices")
|
|
216
|
+
|
|
217
|
+
await palette.dataRooms.uploadFile(room.id, file, {
|
|
218
|
+
folderId: invoices.id,
|
|
219
|
+
})
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Apps can also resolve nested folders:
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
const folder = await palette.dataRooms.resolveFolderPath(
|
|
226
|
+
room.id,
|
|
227
|
+
"Clients/Acme/Invoices",
|
|
228
|
+
{ create: true },
|
|
229
|
+
)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
To read existing files by name:
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
const room = await palette.dataRooms.requireRoomByName("Finance")
|
|
236
|
+
const folder = await palette.dataRooms.resolveFolderPath(room.id, "Clients/Acme/Invoices")
|
|
237
|
+
const file = folder
|
|
238
|
+
? await palette.dataRooms.findFileByName(room.id, "jan.pdf", { folderId: folder.id })
|
|
239
|
+
: null
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Permissions
|
|
243
|
+
|
|
244
|
+
Use permission helpers to keep UI actions aligned with backend permission gates.
|
|
245
|
+
|
|
246
|
+
```tsx
|
|
247
|
+
const palette = createPaletteClient(usePlatform())
|
|
248
|
+
const canWrite = palette.permissions.has("resources:write")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Backend routes should still enforce permissions with the Python SDK. Frontend
|
|
252
|
+
permission checks are for UX only.
|
|
253
|
+
|
|
171
254
|
## API Helpers
|
|
172
255
|
|
|
173
256
|
Use `apiFetch` for authenticated platform API calls. It includes credentials and performs the platform refresh flow for normal portal runtime.
|
|
@@ -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-o-qmdCBl.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-o-qmdCBl.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Provider that wraps plugin components with the platform context.
|
|
@@ -122,4 +122,4 @@ interface DataRoomFile {
|
|
|
122
122
|
updated_at: string;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export type { ChatAttachment as C, DataRoom as D, Task as T,
|
|
125
|
+
export type { ChatAttachment as C, DataRoom as D, Task as T, DataRoomFolder as a, DataRoomFile as b, ChatMessage as c, ChatThread as d, DataRoomPermission as e, TaskAgentSnippet as f, TaskCreatePayload as g, TaskPriority as h, TaskStats as i, TaskStatus as j, TaskType as k, TaskUpdatePayload as l };
|
|
@@ -122,4 +122,4 @@ interface DataRoomFile {
|
|
|
122
122
|
updated_at: string;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export type { ChatAttachment as C, DataRoom as D, Task as T,
|
|
125
|
+
export type { ChatAttachment as C, DataRoom as D, Task as T, DataRoomFolder as a, DataRoomFile as b, ChatMessage as c, ChatThread as d, DataRoomPermission as e, TaskAgentSnippet as f, TaskCreatePayload as g, TaskPriority as h, TaskStats as i, TaskStatus as j, TaskType as k, TaskUpdatePayload as l };
|
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { P as PlatformContext } from '../plugin-
|
|
3
|
-
import { T as Task, i as TaskStats, g as TaskCreatePayload, l as TaskUpdatePayload, D as DataRoom,
|
|
2
|
+
import { P as PlatformContext } from '../plugin-o-qmdCBl.mjs';
|
|
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
|
/**
|
|
6
6
|
* React context for platform services.
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { P as PlatformContext } from '../plugin-
|
|
3
|
-
import { T as Task, i as TaskStats, g as TaskCreatePayload, l as TaskUpdatePayload, D as DataRoom,
|
|
2
|
+
import { P as PlatformContext } from '../plugin-o-qmdCBl.js';
|
|
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
|
/**
|
|
6
6
|
* React context for platform services.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PlatformContext } from './plugin-
|
|
2
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue,
|
|
3
|
-
|
|
1
|
+
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-o-qmdCBl.mjs';
|
|
2
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition } from './plugin-o-qmdCBl.mjs';
|
|
3
|
+
import { D as DataRoom, a as DataRoomFolder, b as DataRoomFile } from './data-room-Dtd9LLHf.mjs';
|
|
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';
|
|
4
5
|
export { AgentResource, ResourcesByGroup } from './types/index.mjs';
|
|
5
6
|
import { ReactElement } from 'react';
|
|
6
7
|
export { PlatformCtx, usePlatform, usePluginChat, usePluginDataRooms, usePluginTasks } from './hooks/index.mjs';
|
|
@@ -53,4 +54,103 @@ declare function updateInstallConfig(pluginId: string, config: InstallConfig): P
|
|
|
53
54
|
declare function createMockPlatformContext(overrides?: Partial<PlatformContext>): PlatformContext;
|
|
54
55
|
declare function withPluginProvider(element: ReactElement, platform?: Partial<PlatformContext>): ReactElement;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
interface DataRoomContents {
|
|
58
|
+
room?: DataRoom;
|
|
59
|
+
folders: DataRoomFolder[];
|
|
60
|
+
files: DataRoomFile[];
|
|
61
|
+
}
|
|
62
|
+
interface DataRoomUploadOptions {
|
|
63
|
+
folderId?: number | null;
|
|
64
|
+
contentType?: string;
|
|
65
|
+
}
|
|
66
|
+
interface FindByNameOptions {
|
|
67
|
+
caseSensitive?: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface EnsureFolderOptions extends FindByNameOptions {
|
|
70
|
+
parentFolderId?: number | null;
|
|
71
|
+
}
|
|
72
|
+
declare class DataRoomClient {
|
|
73
|
+
private matchesName;
|
|
74
|
+
list(): Promise<DataRoom[]>;
|
|
75
|
+
create(input: {
|
|
76
|
+
name: string;
|
|
77
|
+
description?: string | null;
|
|
78
|
+
}): Promise<DataRoom>;
|
|
79
|
+
get(roomId: number): Promise<DataRoomContents>;
|
|
80
|
+
folder(roomId: number, folderId: number): Promise<DataRoomContents>;
|
|
81
|
+
findRoomByName(name: string, options?: FindByNameOptions): Promise<DataRoom | null>;
|
|
82
|
+
requireRoomByName(name: string, options?: FindByNameOptions): Promise<DataRoom>;
|
|
83
|
+
ensureRoom(name: string, description?: string | null): Promise<DataRoom>;
|
|
84
|
+
createFolder(roomId: number, input: {
|
|
85
|
+
name: string;
|
|
86
|
+
parentFolderId?: number | null;
|
|
87
|
+
}): Promise<DataRoomFolder>;
|
|
88
|
+
findFolderByName(roomId: number, name: string, options?: EnsureFolderOptions): Promise<DataRoomFolder | null>;
|
|
89
|
+
ensureFolder(roomId: number, name: string, options?: EnsureFolderOptions): Promise<DataRoomFolder>;
|
|
90
|
+
resolveFolderPath(roomId: number, path: string | string[], options?: FindByNameOptions & {
|
|
91
|
+
create?: boolean;
|
|
92
|
+
}): Promise<DataRoomFolder | null>;
|
|
93
|
+
findFileByName(roomId: number, name: string, options?: FindByNameOptions & {
|
|
94
|
+
folderId?: number | null;
|
|
95
|
+
}): Promise<DataRoomFile | null>;
|
|
96
|
+
requestUpload(roomId: number, file: File, options?: DataRoomUploadOptions): Promise<{
|
|
97
|
+
upload_url: string;
|
|
98
|
+
blob_path: string;
|
|
99
|
+
file_url: string;
|
|
100
|
+
}>;
|
|
101
|
+
confirmUpload(roomId: number, file: File, upload: {
|
|
102
|
+
blob_path: string;
|
|
103
|
+
}, options?: DataRoomUploadOptions): Promise<DataRoomFile>;
|
|
104
|
+
uploadFile(roomId: number, file: File, options?: DataRoomUploadOptions): Promise<DataRoomFile>;
|
|
105
|
+
}
|
|
106
|
+
declare const dataRooms: DataRoomClient;
|
|
107
|
+
|
|
108
|
+
declare function uploadToSignedUrl(uploadUrl: string, file: Blob, contentType?: string): Promise<void>;
|
|
109
|
+
declare class StorageClient {
|
|
110
|
+
uploadToSignedUrl: typeof uploadToSignedUrl;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare class UserClient {
|
|
114
|
+
private readonly ctx?;
|
|
115
|
+
constructor(ctx?: PlatformContext | undefined);
|
|
116
|
+
current(): Promise<User>;
|
|
117
|
+
updateProfile(input: {
|
|
118
|
+
name?: string;
|
|
119
|
+
company_name?: string | null;
|
|
120
|
+
}): Promise<User>;
|
|
121
|
+
}
|
|
122
|
+
declare class OrganizationClient {
|
|
123
|
+
private readonly ctx?;
|
|
124
|
+
constructor(ctx?: PlatformContext | undefined);
|
|
125
|
+
currentId(): number | null;
|
|
126
|
+
currentRole(): string | null;
|
|
127
|
+
listMine(): Promise<OrgSummary[]>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare function createPaletteClient(ctx?: PlatformContext): {
|
|
131
|
+
user: UserClient;
|
|
132
|
+
organization: OrganizationClient;
|
|
133
|
+
dataRooms: DataRoomClient;
|
|
134
|
+
storage: StorageClient;
|
|
135
|
+
config: {
|
|
136
|
+
get: (pluginId?: string) => Promise<InstallConfig>;
|
|
137
|
+
update: (values: Record<string, unknown>, pluginId?: string) => Promise<InstallConfig>;
|
|
138
|
+
};
|
|
139
|
+
permissions: {
|
|
140
|
+
has: (permission: string) => boolean;
|
|
141
|
+
hasAny: (permissions: string[]) => boolean;
|
|
142
|
+
hasAll: (permissions: string[]) => boolean;
|
|
143
|
+
};
|
|
144
|
+
toast: {
|
|
145
|
+
success: (message: string) => void | undefined;
|
|
146
|
+
error: (message: string) => void | undefined;
|
|
147
|
+
info: (message: string) => void | undefined;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
type PaletteClient = ReturnType<typeof createPaletteClient>;
|
|
151
|
+
|
|
152
|
+
declare function hasPermission(ctx: PlatformContext, permission: string): boolean;
|
|
153
|
+
declare function hasAnyPermission(ctx: PlatformContext, permissions: string[]): boolean;
|
|
154
|
+
declare function hasAllPermissions(ctx: PlatformContext, permissions: string[]): boolean;
|
|
155
|
+
|
|
156
|
+
export { DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type InstallConfig, OrgSummary, OrganizationClient, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, StorageClient, User, UserClient, apiFetch, apiUpload, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, errorFromResponse, getBaseUrl, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, setBaseUrl, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { P as PlatformContext } from './plugin-
|
|
2
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue,
|
|
3
|
-
|
|
1
|
+
import { P as PlatformContext, O as OrgSummary, U as User } from './plugin-o-qmdCBl.js';
|
|
2
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition } from './plugin-o-qmdCBl.js';
|
|
3
|
+
import { D as DataRoom, a as DataRoomFolder, b as DataRoomFile } from './data-room-Dtd9LLHf.js';
|
|
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';
|
|
4
5
|
export { AgentResource, ResourcesByGroup } from './types/index.js';
|
|
5
6
|
import { ReactElement } from 'react';
|
|
6
7
|
export { PlatformCtx, usePlatform, usePluginChat, usePluginDataRooms, usePluginTasks } from './hooks/index.js';
|
|
@@ -53,4 +54,103 @@ declare function updateInstallConfig(pluginId: string, config: InstallConfig): P
|
|
|
53
54
|
declare function createMockPlatformContext(overrides?: Partial<PlatformContext>): PlatformContext;
|
|
54
55
|
declare function withPluginProvider(element: ReactElement, platform?: Partial<PlatformContext>): ReactElement;
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
interface DataRoomContents {
|
|
58
|
+
room?: DataRoom;
|
|
59
|
+
folders: DataRoomFolder[];
|
|
60
|
+
files: DataRoomFile[];
|
|
61
|
+
}
|
|
62
|
+
interface DataRoomUploadOptions {
|
|
63
|
+
folderId?: number | null;
|
|
64
|
+
contentType?: string;
|
|
65
|
+
}
|
|
66
|
+
interface FindByNameOptions {
|
|
67
|
+
caseSensitive?: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface EnsureFolderOptions extends FindByNameOptions {
|
|
70
|
+
parentFolderId?: number | null;
|
|
71
|
+
}
|
|
72
|
+
declare class DataRoomClient {
|
|
73
|
+
private matchesName;
|
|
74
|
+
list(): Promise<DataRoom[]>;
|
|
75
|
+
create(input: {
|
|
76
|
+
name: string;
|
|
77
|
+
description?: string | null;
|
|
78
|
+
}): Promise<DataRoom>;
|
|
79
|
+
get(roomId: number): Promise<DataRoomContents>;
|
|
80
|
+
folder(roomId: number, folderId: number): Promise<DataRoomContents>;
|
|
81
|
+
findRoomByName(name: string, options?: FindByNameOptions): Promise<DataRoom | null>;
|
|
82
|
+
requireRoomByName(name: string, options?: FindByNameOptions): Promise<DataRoom>;
|
|
83
|
+
ensureRoom(name: string, description?: string | null): Promise<DataRoom>;
|
|
84
|
+
createFolder(roomId: number, input: {
|
|
85
|
+
name: string;
|
|
86
|
+
parentFolderId?: number | null;
|
|
87
|
+
}): Promise<DataRoomFolder>;
|
|
88
|
+
findFolderByName(roomId: number, name: string, options?: EnsureFolderOptions): Promise<DataRoomFolder | null>;
|
|
89
|
+
ensureFolder(roomId: number, name: string, options?: EnsureFolderOptions): Promise<DataRoomFolder>;
|
|
90
|
+
resolveFolderPath(roomId: number, path: string | string[], options?: FindByNameOptions & {
|
|
91
|
+
create?: boolean;
|
|
92
|
+
}): Promise<DataRoomFolder | null>;
|
|
93
|
+
findFileByName(roomId: number, name: string, options?: FindByNameOptions & {
|
|
94
|
+
folderId?: number | null;
|
|
95
|
+
}): Promise<DataRoomFile | null>;
|
|
96
|
+
requestUpload(roomId: number, file: File, options?: DataRoomUploadOptions): Promise<{
|
|
97
|
+
upload_url: string;
|
|
98
|
+
blob_path: string;
|
|
99
|
+
file_url: string;
|
|
100
|
+
}>;
|
|
101
|
+
confirmUpload(roomId: number, file: File, upload: {
|
|
102
|
+
blob_path: string;
|
|
103
|
+
}, options?: DataRoomUploadOptions): Promise<DataRoomFile>;
|
|
104
|
+
uploadFile(roomId: number, file: File, options?: DataRoomUploadOptions): Promise<DataRoomFile>;
|
|
105
|
+
}
|
|
106
|
+
declare const dataRooms: DataRoomClient;
|
|
107
|
+
|
|
108
|
+
declare function uploadToSignedUrl(uploadUrl: string, file: Blob, contentType?: string): Promise<void>;
|
|
109
|
+
declare class StorageClient {
|
|
110
|
+
uploadToSignedUrl: typeof uploadToSignedUrl;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
declare class UserClient {
|
|
114
|
+
private readonly ctx?;
|
|
115
|
+
constructor(ctx?: PlatformContext | undefined);
|
|
116
|
+
current(): Promise<User>;
|
|
117
|
+
updateProfile(input: {
|
|
118
|
+
name?: string;
|
|
119
|
+
company_name?: string | null;
|
|
120
|
+
}): Promise<User>;
|
|
121
|
+
}
|
|
122
|
+
declare class OrganizationClient {
|
|
123
|
+
private readonly ctx?;
|
|
124
|
+
constructor(ctx?: PlatformContext | undefined);
|
|
125
|
+
currentId(): number | null;
|
|
126
|
+
currentRole(): string | null;
|
|
127
|
+
listMine(): Promise<OrgSummary[]>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare function createPaletteClient(ctx?: PlatformContext): {
|
|
131
|
+
user: UserClient;
|
|
132
|
+
organization: OrganizationClient;
|
|
133
|
+
dataRooms: DataRoomClient;
|
|
134
|
+
storage: StorageClient;
|
|
135
|
+
config: {
|
|
136
|
+
get: (pluginId?: string) => Promise<InstallConfig>;
|
|
137
|
+
update: (values: Record<string, unknown>, pluginId?: string) => Promise<InstallConfig>;
|
|
138
|
+
};
|
|
139
|
+
permissions: {
|
|
140
|
+
has: (permission: string) => boolean;
|
|
141
|
+
hasAny: (permissions: string[]) => boolean;
|
|
142
|
+
hasAll: (permissions: string[]) => boolean;
|
|
143
|
+
};
|
|
144
|
+
toast: {
|
|
145
|
+
success: (message: string) => void | undefined;
|
|
146
|
+
error: (message: string) => void | undefined;
|
|
147
|
+
info: (message: string) => void | undefined;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
type PaletteClient = ReturnType<typeof createPaletteClient>;
|
|
151
|
+
|
|
152
|
+
declare function hasPermission(ctx: PlatformContext, permission: string): boolean;
|
|
153
|
+
declare function hasAnyPermission(ctx: PlatformContext, permissions: string[]): boolean;
|
|
154
|
+
declare function hasAllPermissions(ctx: PlatformContext, permissions: string[]): boolean;
|
|
155
|
+
|
|
156
|
+
export { DataRoom, DataRoomClient, type DataRoomContents, DataRoomFile, DataRoomFolder, type DataRoomUploadOptions, type InstallConfig, OrgSummary, OrganizationClient, PaletteApiError, type PaletteClient, PlatformContext, type SandboxBridge, StorageClient, User, UserClient, apiFetch, apiUpload, createMockPlatformContext, createPaletteClient, createSandboxBridge, dataRooms, errorFromResponse, getBaseUrl, getInstallConfig, hasAllPermissions, hasAnyPermission, hasPermission, isPaletteApiError, isSandboxRuntime, setBaseUrl, updateInstallConfig, uploadToSignedUrl, withPluginProvider };
|
package/dist/index.js
CHANGED
|
@@ -20,20 +20,30 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
DataRoomClient: () => DataRoomClient,
|
|
24
|
+
OrganizationClient: () => OrganizationClient,
|
|
23
25
|
PaletteApiError: () => PaletteApiError,
|
|
24
26
|
PlatformCtx: () => PlatformCtx,
|
|
25
27
|
PluginProvider: () => PluginProvider,
|
|
28
|
+
StorageClient: () => StorageClient,
|
|
29
|
+
UserClient: () => UserClient,
|
|
26
30
|
apiFetch: () => apiFetch,
|
|
27
31
|
apiUpload: () => apiUpload,
|
|
28
32
|
createMockPlatformContext: () => createMockPlatformContext,
|
|
33
|
+
createPaletteClient: () => createPaletteClient,
|
|
29
34
|
createSandboxBridge: () => createSandboxBridge,
|
|
35
|
+
dataRooms: () => dataRooms,
|
|
30
36
|
errorFromResponse: () => errorFromResponse,
|
|
31
37
|
getBaseUrl: () => getBaseUrl,
|
|
32
38
|
getInstallConfig: () => getInstallConfig,
|
|
39
|
+
hasAllPermissions: () => hasAllPermissions,
|
|
40
|
+
hasAnyPermission: () => hasAnyPermission,
|
|
41
|
+
hasPermission: () => hasPermission,
|
|
33
42
|
isPaletteApiError: () => isPaletteApiError,
|
|
34
43
|
isSandboxRuntime: () => isSandboxRuntime,
|
|
35
44
|
setBaseUrl: () => setBaseUrl,
|
|
36
45
|
updateInstallConfig: () => updateInstallConfig,
|
|
46
|
+
uploadToSignedUrl: () => uploadToSignedUrl,
|
|
37
47
|
usePlatform: () => usePlatform,
|
|
38
48
|
usePluginChat: () => usePluginChat,
|
|
39
49
|
usePluginDataRooms: () => usePluginDataRooms,
|
|
@@ -203,6 +213,7 @@ function createMockPlatformContext(overrides = {}) {
|
|
|
203
213
|
orgRole: "owner",
|
|
204
214
|
orgs: [],
|
|
205
215
|
agents: [],
|
|
216
|
+
permissions: [],
|
|
206
217
|
apiFetch: async () => new Response(JSON.stringify({}), { status: 200 }),
|
|
207
218
|
navigate: () => {
|
|
208
219
|
},
|
|
@@ -218,6 +229,212 @@ function withPluginProvider(element, platform = {}) {
|
|
|
218
229
|
);
|
|
219
230
|
}
|
|
220
231
|
|
|
232
|
+
// src/data-rooms.ts
|
|
233
|
+
var DataRoomClient = class {
|
|
234
|
+
matchesName(actual, expected, options = {}) {
|
|
235
|
+
if (options.caseSensitive) return actual === expected;
|
|
236
|
+
return actual.localeCompare(expected, void 0, { sensitivity: "accent" }) === 0;
|
|
237
|
+
}
|
|
238
|
+
async list() {
|
|
239
|
+
const res = await apiFetch("/api/v1/data-rooms");
|
|
240
|
+
return res.json();
|
|
241
|
+
}
|
|
242
|
+
async create(input) {
|
|
243
|
+
const res = await apiFetch("/api/v1/data-rooms", {
|
|
244
|
+
method: "POST",
|
|
245
|
+
body: JSON.stringify(input)
|
|
246
|
+
});
|
|
247
|
+
return res.json();
|
|
248
|
+
}
|
|
249
|
+
async get(roomId) {
|
|
250
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}`);
|
|
251
|
+
return res.json();
|
|
252
|
+
}
|
|
253
|
+
async folder(roomId, folderId) {
|
|
254
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/folders/${folderId}`);
|
|
255
|
+
return res.json();
|
|
256
|
+
}
|
|
257
|
+
async findRoomByName(name, options = {}) {
|
|
258
|
+
const rooms = await this.list();
|
|
259
|
+
return rooms.find((room) => this.matchesName(room.name, name, options)) ?? null;
|
|
260
|
+
}
|
|
261
|
+
async requireRoomByName(name, options = {}) {
|
|
262
|
+
const room = await this.findRoomByName(name, options);
|
|
263
|
+
if (!room) throw new Error(`Data Room not found: ${name}`);
|
|
264
|
+
return room;
|
|
265
|
+
}
|
|
266
|
+
async ensureRoom(name, description) {
|
|
267
|
+
return await this.findRoomByName(name) ?? this.create({ name, description });
|
|
268
|
+
}
|
|
269
|
+
async createFolder(roomId, input) {
|
|
270
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/folders`, {
|
|
271
|
+
method: "POST",
|
|
272
|
+
body: JSON.stringify({
|
|
273
|
+
name: input.name,
|
|
274
|
+
parent_folder_id: input.parentFolderId ?? null
|
|
275
|
+
})
|
|
276
|
+
});
|
|
277
|
+
return res.json();
|
|
278
|
+
}
|
|
279
|
+
async findFolderByName(roomId, name, options = {}) {
|
|
280
|
+
const contents = options.parentFolderId ? await this.folder(roomId, options.parentFolderId) : await this.get(roomId);
|
|
281
|
+
return contents.folders.find((folder) => this.matchesName(folder.name, name, options)) ?? null;
|
|
282
|
+
}
|
|
283
|
+
async ensureFolder(roomId, name, options = {}) {
|
|
284
|
+
return await this.findFolderByName(roomId, name, options) ?? this.createFolder(roomId, { name, parentFolderId: options.parentFolderId ?? null });
|
|
285
|
+
}
|
|
286
|
+
async resolveFolderPath(roomId, path, options = {}) {
|
|
287
|
+
const parts = Array.isArray(path) ? path : path.split("/").map((part) => part.trim()).filter(Boolean);
|
|
288
|
+
let parentFolderId = null;
|
|
289
|
+
let current = null;
|
|
290
|
+
for (const part of parts) {
|
|
291
|
+
current = options.create ? await this.ensureFolder(roomId, part, { ...options, parentFolderId }) : await this.findFolderByName(roomId, part, { ...options, parentFolderId });
|
|
292
|
+
if (!current) return null;
|
|
293
|
+
parentFolderId = current.id;
|
|
294
|
+
}
|
|
295
|
+
return current;
|
|
296
|
+
}
|
|
297
|
+
async findFileByName(roomId, name, options = {}) {
|
|
298
|
+
const contents = options.folderId ? await this.folder(roomId, options.folderId) : await this.get(roomId);
|
|
299
|
+
return contents.files.find((file) => this.matchesName(file.original_filename, name, options)) ?? null;
|
|
300
|
+
}
|
|
301
|
+
async requestUpload(roomId, file, options = {}) {
|
|
302
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/files/request-upload`, {
|
|
303
|
+
method: "POST",
|
|
304
|
+
body: JSON.stringify({
|
|
305
|
+
filename: file.name,
|
|
306
|
+
content_type: options.contentType ?? file.type ?? "application/octet-stream",
|
|
307
|
+
file_size: file.size,
|
|
308
|
+
folder_id: options.folderId ?? null
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
return res.json();
|
|
312
|
+
}
|
|
313
|
+
async confirmUpload(roomId, file, upload, options = {}) {
|
|
314
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/files/confirm-upload`, {
|
|
315
|
+
method: "POST",
|
|
316
|
+
body: JSON.stringify({
|
|
317
|
+
blob_path: upload.blob_path,
|
|
318
|
+
original_filename: file.name,
|
|
319
|
+
file_size: file.size,
|
|
320
|
+
mime_type: options.contentType ?? file.type ?? "application/octet-stream",
|
|
321
|
+
folder_id: options.folderId ?? null
|
|
322
|
+
})
|
|
323
|
+
});
|
|
324
|
+
return res.json();
|
|
325
|
+
}
|
|
326
|
+
async uploadFile(roomId, file, options = {}) {
|
|
327
|
+
const upload = await this.requestUpload(roomId, file, options);
|
|
328
|
+
const put = await fetch(upload.upload_url, {
|
|
329
|
+
method: "PUT",
|
|
330
|
+
headers: { "Content-Type": options.contentType ?? file.type ?? "application/octet-stream" },
|
|
331
|
+
body: file
|
|
332
|
+
});
|
|
333
|
+
if (!put.ok) throw new Error(`Upload failed: ${put.statusText}`);
|
|
334
|
+
return this.confirmUpload(roomId, file, upload, options);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var dataRooms = new DataRoomClient();
|
|
338
|
+
|
|
339
|
+
// src/permissions.ts
|
|
340
|
+
function hasPermission(ctx, permission) {
|
|
341
|
+
return ctx.permissions?.includes(permission) ?? false;
|
|
342
|
+
}
|
|
343
|
+
function hasAnyPermission(ctx, permissions) {
|
|
344
|
+
return permissions.some((permission) => hasPermission(ctx, permission));
|
|
345
|
+
}
|
|
346
|
+
function hasAllPermissions(ctx, permissions) {
|
|
347
|
+
return permissions.every((permission) => hasPermission(ctx, permission));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/storage.ts
|
|
351
|
+
async function uploadToSignedUrl(uploadUrl, file, contentType = "application/octet-stream") {
|
|
352
|
+
const res = await fetch(uploadUrl, {
|
|
353
|
+
method: "PUT",
|
|
354
|
+
headers: { "Content-Type": contentType },
|
|
355
|
+
body: file
|
|
356
|
+
});
|
|
357
|
+
if (!res.ok) throw new Error(`Upload failed: ${res.statusText}`);
|
|
358
|
+
}
|
|
359
|
+
var StorageClient = class {
|
|
360
|
+
constructor() {
|
|
361
|
+
this.uploadToSignedUrl = uploadToSignedUrl;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// src/user-org.ts
|
|
366
|
+
var UserClient = class {
|
|
367
|
+
constructor(ctx) {
|
|
368
|
+
this.ctx = ctx;
|
|
369
|
+
}
|
|
370
|
+
async current() {
|
|
371
|
+
if (this.ctx?.user) return this.ctx.user;
|
|
372
|
+
const res = await apiFetch("/api/v1/auth/me");
|
|
373
|
+
return res.json();
|
|
374
|
+
}
|
|
375
|
+
async updateProfile(input) {
|
|
376
|
+
const res = await apiFetch("/api/v1/auth/profile", {
|
|
377
|
+
method: "PATCH",
|
|
378
|
+
body: JSON.stringify(input)
|
|
379
|
+
});
|
|
380
|
+
return res.json();
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
var OrganizationClient = class {
|
|
384
|
+
constructor(ctx) {
|
|
385
|
+
this.ctx = ctx;
|
|
386
|
+
}
|
|
387
|
+
currentId() {
|
|
388
|
+
return this.ctx?.organizationId ?? null;
|
|
389
|
+
}
|
|
390
|
+
currentRole() {
|
|
391
|
+
return this.ctx?.orgRole ?? null;
|
|
392
|
+
}
|
|
393
|
+
async listMine() {
|
|
394
|
+
if (this.ctx?.orgs?.length) return this.ctx.orgs;
|
|
395
|
+
const res = await apiFetch("/api/v1/auth/my-orgs");
|
|
396
|
+
return res.json();
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/palette-client.ts
|
|
401
|
+
function createPaletteClient(ctx) {
|
|
402
|
+
const defaultPluginId = () => {
|
|
403
|
+
if (ctx?.pluginId) return ctx.pluginId;
|
|
404
|
+
if (typeof window === "undefined") return "";
|
|
405
|
+
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
406
|
+
return match ? decodeURIComponent(match[1]) : "";
|
|
407
|
+
};
|
|
408
|
+
return {
|
|
409
|
+
user: new UserClient(ctx),
|
|
410
|
+
organization: new OrganizationClient(ctx),
|
|
411
|
+
dataRooms: new DataRoomClient(),
|
|
412
|
+
storage: new StorageClient(),
|
|
413
|
+
config: {
|
|
414
|
+
get: (pluginId = ctx?.pluginId ?? "") => {
|
|
415
|
+
const resolved = pluginId || defaultPluginId();
|
|
416
|
+
if (!resolved) throw new Error("pluginId is required to read install config");
|
|
417
|
+
return getInstallConfig(resolved);
|
|
418
|
+
},
|
|
419
|
+
update: (values, pluginId = ctx?.pluginId ?? "") => {
|
|
420
|
+
const resolved = pluginId || defaultPluginId();
|
|
421
|
+
if (!resolved) throw new Error("pluginId is required to update install config");
|
|
422
|
+
return updateInstallConfig(resolved, values);
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
permissions: {
|
|
426
|
+
has: (permission) => ctx ? hasPermission(ctx, permission) : false,
|
|
427
|
+
hasAny: (permissions) => ctx ? hasAnyPermission(ctx, permissions) : false,
|
|
428
|
+
hasAll: (permissions) => ctx ? hasAllPermissions(ctx, permissions) : false
|
|
429
|
+
},
|
|
430
|
+
toast: {
|
|
431
|
+
success: (message) => ctx?.showToast(message, "success"),
|
|
432
|
+
error: (message) => ctx?.showToast(message, "error"),
|
|
433
|
+
info: (message) => ctx?.showToast(message, "info")
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
221
438
|
// src/hooks/use-plugin-tasks.ts
|
|
222
439
|
var import_react3 = require("react");
|
|
223
440
|
function usePluginTasks(agentId) {
|
|
@@ -407,20 +624,30 @@ function usePluginChat(agentId) {
|
|
|
407
624
|
}
|
|
408
625
|
// Annotate the CommonJS export names for ESM import in node:
|
|
409
626
|
0 && (module.exports = {
|
|
627
|
+
DataRoomClient,
|
|
628
|
+
OrganizationClient,
|
|
410
629
|
PaletteApiError,
|
|
411
630
|
PlatformCtx,
|
|
412
631
|
PluginProvider,
|
|
632
|
+
StorageClient,
|
|
633
|
+
UserClient,
|
|
413
634
|
apiFetch,
|
|
414
635
|
apiUpload,
|
|
415
636
|
createMockPlatformContext,
|
|
637
|
+
createPaletteClient,
|
|
416
638
|
createSandboxBridge,
|
|
639
|
+
dataRooms,
|
|
417
640
|
errorFromResponse,
|
|
418
641
|
getBaseUrl,
|
|
419
642
|
getInstallConfig,
|
|
643
|
+
hasAllPermissions,
|
|
644
|
+
hasAnyPermission,
|
|
645
|
+
hasPermission,
|
|
420
646
|
isPaletteApiError,
|
|
421
647
|
isSandboxRuntime,
|
|
422
648
|
setBaseUrl,
|
|
423
649
|
updateInstallConfig,
|
|
650
|
+
uploadToSignedUrl,
|
|
424
651
|
usePlatform,
|
|
425
652
|
usePluginChat,
|
|
426
653
|
usePluginDataRooms,
|
package/dist/index.mjs
CHANGED
|
@@ -159,6 +159,7 @@ function createMockPlatformContext(overrides = {}) {
|
|
|
159
159
|
orgRole: "owner",
|
|
160
160
|
orgs: [],
|
|
161
161
|
agents: [],
|
|
162
|
+
permissions: [],
|
|
162
163
|
apiFetch: async () => new Response(JSON.stringify({}), { status: 200 }),
|
|
163
164
|
navigate: () => {
|
|
164
165
|
},
|
|
@@ -174,6 +175,212 @@ function withPluginProvider(element, platform = {}) {
|
|
|
174
175
|
);
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
// src/data-rooms.ts
|
|
179
|
+
var DataRoomClient = class {
|
|
180
|
+
matchesName(actual, expected, options = {}) {
|
|
181
|
+
if (options.caseSensitive) return actual === expected;
|
|
182
|
+
return actual.localeCompare(expected, void 0, { sensitivity: "accent" }) === 0;
|
|
183
|
+
}
|
|
184
|
+
async list() {
|
|
185
|
+
const res = await apiFetch("/api/v1/data-rooms");
|
|
186
|
+
return res.json();
|
|
187
|
+
}
|
|
188
|
+
async create(input) {
|
|
189
|
+
const res = await apiFetch("/api/v1/data-rooms", {
|
|
190
|
+
method: "POST",
|
|
191
|
+
body: JSON.stringify(input)
|
|
192
|
+
});
|
|
193
|
+
return res.json();
|
|
194
|
+
}
|
|
195
|
+
async get(roomId) {
|
|
196
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}`);
|
|
197
|
+
return res.json();
|
|
198
|
+
}
|
|
199
|
+
async folder(roomId, folderId) {
|
|
200
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/folders/${folderId}`);
|
|
201
|
+
return res.json();
|
|
202
|
+
}
|
|
203
|
+
async findRoomByName(name, options = {}) {
|
|
204
|
+
const rooms = await this.list();
|
|
205
|
+
return rooms.find((room) => this.matchesName(room.name, name, options)) ?? null;
|
|
206
|
+
}
|
|
207
|
+
async requireRoomByName(name, options = {}) {
|
|
208
|
+
const room = await this.findRoomByName(name, options);
|
|
209
|
+
if (!room) throw new Error(`Data Room not found: ${name}`);
|
|
210
|
+
return room;
|
|
211
|
+
}
|
|
212
|
+
async ensureRoom(name, description) {
|
|
213
|
+
return await this.findRoomByName(name) ?? this.create({ name, description });
|
|
214
|
+
}
|
|
215
|
+
async createFolder(roomId, input) {
|
|
216
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/folders`, {
|
|
217
|
+
method: "POST",
|
|
218
|
+
body: JSON.stringify({
|
|
219
|
+
name: input.name,
|
|
220
|
+
parent_folder_id: input.parentFolderId ?? null
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
return res.json();
|
|
224
|
+
}
|
|
225
|
+
async findFolderByName(roomId, name, options = {}) {
|
|
226
|
+
const contents = options.parentFolderId ? await this.folder(roomId, options.parentFolderId) : await this.get(roomId);
|
|
227
|
+
return contents.folders.find((folder) => this.matchesName(folder.name, name, options)) ?? null;
|
|
228
|
+
}
|
|
229
|
+
async ensureFolder(roomId, name, options = {}) {
|
|
230
|
+
return await this.findFolderByName(roomId, name, options) ?? this.createFolder(roomId, { name, parentFolderId: options.parentFolderId ?? null });
|
|
231
|
+
}
|
|
232
|
+
async resolveFolderPath(roomId, path, options = {}) {
|
|
233
|
+
const parts = Array.isArray(path) ? path : path.split("/").map((part) => part.trim()).filter(Boolean);
|
|
234
|
+
let parentFolderId = null;
|
|
235
|
+
let current = null;
|
|
236
|
+
for (const part of parts) {
|
|
237
|
+
current = options.create ? await this.ensureFolder(roomId, part, { ...options, parentFolderId }) : await this.findFolderByName(roomId, part, { ...options, parentFolderId });
|
|
238
|
+
if (!current) return null;
|
|
239
|
+
parentFolderId = current.id;
|
|
240
|
+
}
|
|
241
|
+
return current;
|
|
242
|
+
}
|
|
243
|
+
async findFileByName(roomId, name, options = {}) {
|
|
244
|
+
const contents = options.folderId ? await this.folder(roomId, options.folderId) : await this.get(roomId);
|
|
245
|
+
return contents.files.find((file) => this.matchesName(file.original_filename, name, options)) ?? null;
|
|
246
|
+
}
|
|
247
|
+
async requestUpload(roomId, file, options = {}) {
|
|
248
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/files/request-upload`, {
|
|
249
|
+
method: "POST",
|
|
250
|
+
body: JSON.stringify({
|
|
251
|
+
filename: file.name,
|
|
252
|
+
content_type: options.contentType ?? file.type ?? "application/octet-stream",
|
|
253
|
+
file_size: file.size,
|
|
254
|
+
folder_id: options.folderId ?? null
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
return res.json();
|
|
258
|
+
}
|
|
259
|
+
async confirmUpload(roomId, file, upload, options = {}) {
|
|
260
|
+
const res = await apiFetch(`/api/v1/data-rooms/${roomId}/files/confirm-upload`, {
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: JSON.stringify({
|
|
263
|
+
blob_path: upload.blob_path,
|
|
264
|
+
original_filename: file.name,
|
|
265
|
+
file_size: file.size,
|
|
266
|
+
mime_type: options.contentType ?? file.type ?? "application/octet-stream",
|
|
267
|
+
folder_id: options.folderId ?? null
|
|
268
|
+
})
|
|
269
|
+
});
|
|
270
|
+
return res.json();
|
|
271
|
+
}
|
|
272
|
+
async uploadFile(roomId, file, options = {}) {
|
|
273
|
+
const upload = await this.requestUpload(roomId, file, options);
|
|
274
|
+
const put = await fetch(upload.upload_url, {
|
|
275
|
+
method: "PUT",
|
|
276
|
+
headers: { "Content-Type": options.contentType ?? file.type ?? "application/octet-stream" },
|
|
277
|
+
body: file
|
|
278
|
+
});
|
|
279
|
+
if (!put.ok) throw new Error(`Upload failed: ${put.statusText}`);
|
|
280
|
+
return this.confirmUpload(roomId, file, upload, options);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
var dataRooms = new DataRoomClient();
|
|
284
|
+
|
|
285
|
+
// src/permissions.ts
|
|
286
|
+
function hasPermission(ctx, permission) {
|
|
287
|
+
return ctx.permissions?.includes(permission) ?? false;
|
|
288
|
+
}
|
|
289
|
+
function hasAnyPermission(ctx, permissions) {
|
|
290
|
+
return permissions.some((permission) => hasPermission(ctx, permission));
|
|
291
|
+
}
|
|
292
|
+
function hasAllPermissions(ctx, permissions) {
|
|
293
|
+
return permissions.every((permission) => hasPermission(ctx, permission));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/storage.ts
|
|
297
|
+
async function uploadToSignedUrl(uploadUrl, file, contentType = "application/octet-stream") {
|
|
298
|
+
const res = await fetch(uploadUrl, {
|
|
299
|
+
method: "PUT",
|
|
300
|
+
headers: { "Content-Type": contentType },
|
|
301
|
+
body: file
|
|
302
|
+
});
|
|
303
|
+
if (!res.ok) throw new Error(`Upload failed: ${res.statusText}`);
|
|
304
|
+
}
|
|
305
|
+
var StorageClient = class {
|
|
306
|
+
constructor() {
|
|
307
|
+
this.uploadToSignedUrl = uploadToSignedUrl;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/user-org.ts
|
|
312
|
+
var UserClient = class {
|
|
313
|
+
constructor(ctx) {
|
|
314
|
+
this.ctx = ctx;
|
|
315
|
+
}
|
|
316
|
+
async current() {
|
|
317
|
+
if (this.ctx?.user) return this.ctx.user;
|
|
318
|
+
const res = await apiFetch("/api/v1/auth/me");
|
|
319
|
+
return res.json();
|
|
320
|
+
}
|
|
321
|
+
async updateProfile(input) {
|
|
322
|
+
const res = await apiFetch("/api/v1/auth/profile", {
|
|
323
|
+
method: "PATCH",
|
|
324
|
+
body: JSON.stringify(input)
|
|
325
|
+
});
|
|
326
|
+
return res.json();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var OrganizationClient = class {
|
|
330
|
+
constructor(ctx) {
|
|
331
|
+
this.ctx = ctx;
|
|
332
|
+
}
|
|
333
|
+
currentId() {
|
|
334
|
+
return this.ctx?.organizationId ?? null;
|
|
335
|
+
}
|
|
336
|
+
currentRole() {
|
|
337
|
+
return this.ctx?.orgRole ?? null;
|
|
338
|
+
}
|
|
339
|
+
async listMine() {
|
|
340
|
+
if (this.ctx?.orgs?.length) return this.ctx.orgs;
|
|
341
|
+
const res = await apiFetch("/api/v1/auth/my-orgs");
|
|
342
|
+
return res.json();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/palette-client.ts
|
|
347
|
+
function createPaletteClient(ctx) {
|
|
348
|
+
const defaultPluginId = () => {
|
|
349
|
+
if (ctx?.pluginId) return ctx.pluginId;
|
|
350
|
+
if (typeof window === "undefined") return "";
|
|
351
|
+
const match = window.location.pathname.match(/\/apps\/([^/?#]+)/);
|
|
352
|
+
return match ? decodeURIComponent(match[1]) : "";
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
user: new UserClient(ctx),
|
|
356
|
+
organization: new OrganizationClient(ctx),
|
|
357
|
+
dataRooms: new DataRoomClient(),
|
|
358
|
+
storage: new StorageClient(),
|
|
359
|
+
config: {
|
|
360
|
+
get: (pluginId = ctx?.pluginId ?? "") => {
|
|
361
|
+
const resolved = pluginId || defaultPluginId();
|
|
362
|
+
if (!resolved) throw new Error("pluginId is required to read install config");
|
|
363
|
+
return getInstallConfig(resolved);
|
|
364
|
+
},
|
|
365
|
+
update: (values, pluginId = ctx?.pluginId ?? "") => {
|
|
366
|
+
const resolved = pluginId || defaultPluginId();
|
|
367
|
+
if (!resolved) throw new Error("pluginId is required to update install config");
|
|
368
|
+
return updateInstallConfig(resolved, values);
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
permissions: {
|
|
372
|
+
has: (permission) => ctx ? hasPermission(ctx, permission) : false,
|
|
373
|
+
hasAny: (permissions) => ctx ? hasAnyPermission(ctx, permissions) : false,
|
|
374
|
+
hasAll: (permissions) => ctx ? hasAllPermissions(ctx, permissions) : false
|
|
375
|
+
},
|
|
376
|
+
toast: {
|
|
377
|
+
success: (message) => ctx?.showToast(message, "success"),
|
|
378
|
+
error: (message) => ctx?.showToast(message, "error"),
|
|
379
|
+
info: (message) => ctx?.showToast(message, "info")
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
177
384
|
// src/hooks/use-plugin-tasks.ts
|
|
178
385
|
import { useCallback, useEffect, useState } from "react";
|
|
179
386
|
function usePluginTasks(agentId) {
|
|
@@ -362,20 +569,30 @@ function usePluginChat(agentId) {
|
|
|
362
569
|
};
|
|
363
570
|
}
|
|
364
571
|
export {
|
|
572
|
+
DataRoomClient,
|
|
573
|
+
OrganizationClient,
|
|
365
574
|
PaletteApiError,
|
|
366
575
|
PlatformCtx,
|
|
367
576
|
PluginProvider,
|
|
577
|
+
StorageClient,
|
|
578
|
+
UserClient,
|
|
368
579
|
apiFetch,
|
|
369
580
|
apiUpload,
|
|
370
581
|
createMockPlatformContext,
|
|
582
|
+
createPaletteClient,
|
|
371
583
|
createSandboxBridge,
|
|
584
|
+
dataRooms,
|
|
372
585
|
errorFromResponse,
|
|
373
586
|
getBaseUrl,
|
|
374
587
|
getInstallConfig,
|
|
588
|
+
hasAllPermissions,
|
|
589
|
+
hasAnyPermission,
|
|
590
|
+
hasPermission,
|
|
375
591
|
isPaletteApiError,
|
|
376
592
|
isSandboxRuntime,
|
|
377
593
|
setBaseUrl,
|
|
378
594
|
updateInstallConfig,
|
|
595
|
+
uploadToSignedUrl,
|
|
379
596
|
usePlatform,
|
|
380
597
|
usePluginChat,
|
|
381
598
|
usePluginDataRooms,
|
|
@@ -141,6 +141,8 @@ interface PlatformContext {
|
|
|
141
141
|
user: User;
|
|
142
142
|
/** Current organization ID */
|
|
143
143
|
organizationId: number;
|
|
144
|
+
/** Current plugin ID */
|
|
145
|
+
pluginId?: string;
|
|
144
146
|
/** User's org role */
|
|
145
147
|
orgRole: string | null;
|
|
146
148
|
/** Available orgs */
|
|
@@ -153,6 +155,8 @@ interface PlatformContext {
|
|
|
153
155
|
navigate: (path: string) => void;
|
|
154
156
|
/** Show a toast notification */
|
|
155
157
|
showToast: (message: string, type?: "success" | "error" | "info") => void;
|
|
158
|
+
/** Permissions declared for the current plugin install/runtime */
|
|
159
|
+
permissions?: string[];
|
|
156
160
|
}
|
|
157
161
|
/** Props passed to a plugin's root component */
|
|
158
162
|
interface PluginComponentProps {
|
|
@@ -141,6 +141,8 @@ interface PlatformContext {
|
|
|
141
141
|
user: User;
|
|
142
142
|
/** Current organization ID */
|
|
143
143
|
organizationId: number;
|
|
144
|
+
/** Current plugin ID */
|
|
145
|
+
pluginId?: string;
|
|
144
146
|
/** User's org role */
|
|
145
147
|
orgRole: string | null;
|
|
146
148
|
/** Available orgs */
|
|
@@ -153,6 +155,8 @@ interface PlatformContext {
|
|
|
153
155
|
navigate: (path: string) => void;
|
|
154
156
|
/** Show a toast notification */
|
|
155
157
|
showToast: (message: string, type?: "success" | "error" | "info") => void;
|
|
158
|
+
/** Permissions declared for the current plugin install/runtime */
|
|
159
|
+
permissions?: string[];
|
|
156
160
|
}
|
|
157
161
|
/** Props passed to a plugin's root component */
|
|
158
162
|
interface PluginComponentProps {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, O as OrgSummary, P as PlatformContext, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition, U as User } from '../plugin-
|
|
2
|
-
export { C as ChatAttachment,
|
|
1
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, O as OrgSummary, P as PlatformContext, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition, U as User } from '../plugin-o-qmdCBl.mjs';
|
|
2
|
+
export { C as ChatAttachment, c as ChatMessage, d as ChatThread, D as DataRoom, b as DataRoomFile, a as DataRoomFolder, 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';
|
|
3
3
|
|
|
4
4
|
interface AgentResource {
|
|
5
5
|
id: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, O as OrgSummary, P as PlatformContext, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition, U as User } from '../plugin-
|
|
2
|
-
export { C as ChatAttachment,
|
|
1
|
+
export { A as Agent, a as AgentConfig, b as AppCategory, c as AuthContextValue, O as OrgSummary, P as PlatformContext, d as PluginAgentDefinition, e as PluginComponentProps, f as PluginManifest, g as PluginToolDefinition, U as User } from '../plugin-o-qmdCBl.js';
|
|
2
|
+
export { C as ChatAttachment, c as ChatMessage, d as ChatThread, D as DataRoom, b as DataRoomFile, a as DataRoomFolder, 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';
|
|
3
3
|
|
|
4
4
|
interface AgentResource {
|
|
5
5
|
id: number;
|