@mgamadeus/ddd-agent-sandbox 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/i18n/hints.json +140 -0
- package/dist/i18n-keys.json +1201 -0
- package/dist/index.d.ts +377 -0
- package/dist/index.js +140 -0
- package/dist/index.js.map +1 -0
- package/dist/screen/index.d.ts +177 -0
- package/dist/screen/index.js +1053 -0
- package/dist/screen/index.js.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as _mgamadeus_ddd_admin_ui_logic from '@mgamadeus/ddd-admin-ui/logic';
|
|
2
|
+
import { SandboxActionOutcome, SandboxCommandStatus, SandboxState, SandboxCommand, SandboxWorkspace, SandboxesApi, SandboxConversation, SandboxFileEntry } from '../index.js';
|
|
3
|
+
import * as react from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { PdfJsLoader } from '@mgamadeus/ddd-admin-ui/files';
|
|
6
|
+
import '@mgamadeus/ddd-admin-ui/logic/pure';
|
|
7
|
+
|
|
8
|
+
/** `SandboxWorkspace.state`. */
|
|
9
|
+
declare const SANDBOX_STATE: Readonly<Record<SandboxState, _mgamadeus_ddd_admin_ui_logic.StatusDefinition>>;
|
|
10
|
+
/** `SandboxActionLogEntry.outcome`. */
|
|
11
|
+
declare const SANDBOX_ACTION_OUTCOME: Readonly<Record<SandboxActionOutcome, _mgamadeus_ddd_admin_ui_logic.StatusDefinition>>;
|
|
12
|
+
/**
|
|
13
|
+
* The state of a command: the server's `status`, else derived from the exit code — an exit code
|
|
14
|
+
* is EXITED, none is UNKNOWN (a killed or timed-out command has none either, so it is never shown as running).
|
|
15
|
+
*/
|
|
16
|
+
type SandboxCommandState = SandboxCommandStatus | 'UNKNOWN';
|
|
17
|
+
declare const sandboxCommandStateOf: (command: Pick<SandboxCommand, "status" | "exitCode">) => SandboxCommandState;
|
|
18
|
+
/** `SandboxCommand.status` as a badge (EXITED carries the exit code next to it). */
|
|
19
|
+
declare const SANDBOX_COMMAND_STATE: Readonly<Record<SandboxCommandState, _mgamadeus_ddd_admin_ui_logic.StatusDefinition>>;
|
|
20
|
+
/** The translation context of `SANDBOX_ACTION_LABELS`. */
|
|
21
|
+
declare const SANDBOX_ACTION_LABEL_CONTEXT = "sandbox-action";
|
|
22
|
+
/** The translation context of `SANDBOX_CHANGE_LABELS`. */
|
|
23
|
+
declare const SANDBOX_CHANGE_LABEL_CONTEXT = "sandbox-change";
|
|
24
|
+
/** The actions of the audit, as the screen names them. */
|
|
25
|
+
declare const SANDBOX_ACTION_LABELS: Readonly<Record<string, string>>;
|
|
26
|
+
/** How a drive change of the workspace is named. */
|
|
27
|
+
declare const SANDBOX_CHANGE_LABELS: Readonly<Record<string, string>>;
|
|
28
|
+
/** `1.5 GB` in the UI language; `—` for unknown. */
|
|
29
|
+
declare const formatSandboxBytes: (bytes: number | null | undefined) => string;
|
|
30
|
+
/** `850 ms`, `12.4 s`, `3 min 5 s`; `—` for unknown. */
|
|
31
|
+
declare const formatSandboxDuration: (milliseconds: number | null | undefined) => string;
|
|
32
|
+
/** The share of a limit in percent (0–100, rounded), `null` without a limit. */
|
|
33
|
+
declare const usagePercentOf: (used: number | null | undefined, limit: number | null | undefined) => number | null;
|
|
34
|
+
/** The name a workspace is shown with: its display name, else its key. */
|
|
35
|
+
declare const sandboxNameOf: (workspace: Pick<SandboxWorkspace, "displayName" | "workspaceKey">) => string;
|
|
36
|
+
/** What a reset asks the reader to type: the display name, or the key without one (the server checks the same). */
|
|
37
|
+
declare const sandboxResetPhraseOf: (workspace: Pick<SandboxWorkspace, "displayName" | "workspaceKey">) => string;
|
|
38
|
+
/** Whether an error is the server's "a turn is running" refusal (409): the action may be forced with a reason. */
|
|
39
|
+
declare const isSandboxTurnRunningRefusal: (error: unknown) => boolean;
|
|
40
|
+
/** The parent of a workspace path (`a/b/c` → `a/b`, `a` → `''`). */
|
|
41
|
+
declare const sandboxParentPathOf: (path: string) => string;
|
|
42
|
+
/** The crumbs of a workspace directory: root first. */
|
|
43
|
+
declare const sandboxPathCrumbs: (path: string) => {
|
|
44
|
+
name: string;
|
|
45
|
+
path: string;
|
|
46
|
+
}[];
|
|
47
|
+
/** How a file is previewed, from the type the server sent with its bytes. */
|
|
48
|
+
type SandboxPreviewKind = 'image' | 'pdf' | 'text' | 'none';
|
|
49
|
+
declare const sandboxPreviewKindOf: (contentType: string) => SandboxPreviewKind;
|
|
50
|
+
/** The inline text preview of the server stops here; a larger answer was cut. */
|
|
51
|
+
declare const SANDBOX_TEXT_PREVIEW_BYTES: number;
|
|
52
|
+
|
|
53
|
+
/** A used / limit pair as a thin bar with its numbers (no bar without a limit). */
|
|
54
|
+
declare const SandboxUsageBar: ({ used, limit, peak }: {
|
|
55
|
+
used: number | null | undefined;
|
|
56
|
+
limit: number | null | undefined;
|
|
57
|
+
peak?: number | null;
|
|
58
|
+
}) => react.JSX.Element;
|
|
59
|
+
/** The mount mode and why (FUSE: the drive is mounted; PLAIN: files are copied). */
|
|
60
|
+
declare const SandboxMountMode: ({ workspace }: {
|
|
61
|
+
workspace: SandboxWorkspace;
|
|
62
|
+
}) => react.JSX.Element;
|
|
63
|
+
/** The actions of one workspace as a menu (start, offload, end). */
|
|
64
|
+
declare const SandboxActionsMenu: ({ workspace, onAction, disabled, }: {
|
|
65
|
+
workspace: SandboxWorkspace;
|
|
66
|
+
onAction: (kind: "start" | "offload" | "end") => void;
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
}) => react.JSX.Element;
|
|
69
|
+
interface SandboxesScreenProps {
|
|
70
|
+
/** `createSandboxesApi(…)` of the host. */
|
|
71
|
+
api: SandboxesApi;
|
|
72
|
+
/** Default "Sandboxes". */
|
|
73
|
+
title?: ReactNode;
|
|
74
|
+
description?: ReactNode;
|
|
75
|
+
headerActions?: ReactNode;
|
|
76
|
+
/** Opens a workspace's details (the host's route, e.g. `router.push(…)`). */
|
|
77
|
+
onOpenWorkspace?: (workspaceKey: string) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Every agent workspace of the host (one per agent space): state, last activity, disk and memory against their limits,
|
|
81
|
+
* mount mode, runner pod, owner and conversations; start, offload and end per row (audited, refused while a turn runs
|
|
82
|
+
* unless forced with a reason). Needs the Composer package mgamadeus/ddd-agent-sandbox (`SandboxesControllerTrait`).
|
|
83
|
+
*/
|
|
84
|
+
declare const SandboxesScreen: ({ api, title, description, headerActions, onOpenWorkspace }: SandboxesScreenProps) => react.JSX.Element;
|
|
85
|
+
|
|
86
|
+
/** The tabs of a workspace. */
|
|
87
|
+
declare const SANDBOX_DETAIL_TABS: readonly [{
|
|
88
|
+
readonly id: "files";
|
|
89
|
+
readonly label: "Files";
|
|
90
|
+
readonly context: "sandbox-tab";
|
|
91
|
+
}, {
|
|
92
|
+
readonly id: "changes";
|
|
93
|
+
readonly label: "Unsaved changes";
|
|
94
|
+
readonly context: "sandbox-tab";
|
|
95
|
+
}, {
|
|
96
|
+
readonly id: "processes";
|
|
97
|
+
readonly label: "Processes & jobs";
|
|
98
|
+
readonly context: "sandbox-tab";
|
|
99
|
+
}, {
|
|
100
|
+
readonly id: "commands";
|
|
101
|
+
readonly label: "Commands";
|
|
102
|
+
readonly context: "sandbox-tab";
|
|
103
|
+
}, {
|
|
104
|
+
readonly id: "conversations";
|
|
105
|
+
readonly label: "Conversations";
|
|
106
|
+
readonly context: "sandbox-tab";
|
|
107
|
+
}, {
|
|
108
|
+
readonly id: "events";
|
|
109
|
+
readonly label: "Session log";
|
|
110
|
+
readonly context: "sandbox-tab";
|
|
111
|
+
}, {
|
|
112
|
+
readonly id: "audit";
|
|
113
|
+
readonly label: "Audit";
|
|
114
|
+
readonly context: "sandbox-tab";
|
|
115
|
+
}];
|
|
116
|
+
type SandboxDetailTab = (typeof SANDBOX_DETAIL_TABS)[number]['id'];
|
|
117
|
+
interface SandboxDetailScreenProps {
|
|
118
|
+
api: SandboxesApi;
|
|
119
|
+
workspaceKey: string;
|
|
120
|
+
/** The open tab (controlled, e.g. from the URL); without it the screen keeps it. */
|
|
121
|
+
tab?: SandboxDetailTab;
|
|
122
|
+
onTabChange?: (tab: SandboxDetailTab) => void;
|
|
123
|
+
/** A link back (the list), drawn left of the title. */
|
|
124
|
+
backLink?: ReactNode;
|
|
125
|
+
headerActions?: ReactNode;
|
|
126
|
+
/** The link of a conversation in the host's agent screens; `null` = no link. */
|
|
127
|
+
buildConversationHref?: (conversation: SandboxConversation) => string | null;
|
|
128
|
+
/** pdf.js of the host for the PDF preview. */
|
|
129
|
+
loadPdfJs?: PdfJsLoader;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* One workspace: its facts (state, disk and memory against their limits, mount mode, runner pod, owner) and the tabs
|
|
133
|
+
* Files (read only, the safe preview), Unsaved changes, Processes & jobs (kill), Commands (exit code, duration, output
|
|
134
|
+
* tails), Conversations, Session log and Audit. Start, offload, end and reset (typed name) are audited and refused
|
|
135
|
+
* while a turn runs on the space unless forced with a reason. Everything from the sandbox is shown as text.
|
|
136
|
+
*/
|
|
137
|
+
declare const SandboxDetailScreen: ({ api, workspaceKey, tab: controlledTab, onTabChange, backLink, headerActions, buildConversationHref, loadPdfJs, }: SandboxDetailScreenProps) => react.JSX.Element;
|
|
138
|
+
|
|
139
|
+
interface SandboxFilePreviewProps {
|
|
140
|
+
api: SandboxesApi;
|
|
141
|
+
workspaceKey: string;
|
|
142
|
+
file: SandboxFileEntry;
|
|
143
|
+
/** pdf.js of the host (without it a PDF offers its download only). */
|
|
144
|
+
loadPdfJs?: PdfJsLoader;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A file of a workspace, read only, as untrusted content: the server picks the type from the bytes; JPEG, PNG, GIF
|
|
148
|
+
* and WebP draw as `<img>`, PDF on canvases through the host's pdf.js, text as text nodes (the first 256 KB); anything
|
|
149
|
+
* else only downloads. Nothing is ever rendered as HTML.
|
|
150
|
+
*/
|
|
151
|
+
declare const SandboxFilePreview: ({ api, workspaceKey, file, loadPdfJs }: SandboxFilePreviewProps) => react.JSX.Element;
|
|
152
|
+
|
|
153
|
+
/** One action of the sandbox screens. */
|
|
154
|
+
type SandboxActionRequest = {
|
|
155
|
+
kind: 'start' | 'offload' | 'end' | 'reset';
|
|
156
|
+
workspace: SandboxWorkspace;
|
|
157
|
+
} | {
|
|
158
|
+
kind: 'kill';
|
|
159
|
+
workspace: SandboxWorkspace;
|
|
160
|
+
jobId: string;
|
|
161
|
+
};
|
|
162
|
+
interface SandboxActions {
|
|
163
|
+
/** Asks (confirmation, typed name for a reset, a reason while a turn runs), runs it and reports the outcome. */
|
|
164
|
+
run: (request: SandboxActionRequest) => Promise<boolean>;
|
|
165
|
+
/** An action is running. */
|
|
166
|
+
isPending: boolean;
|
|
167
|
+
/** The "force with a reason" dialog; render it once in the screen. */
|
|
168
|
+
dialog: ReactNode;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The actions of the sandbox screens: start, offload, end, reset (typed name) and kill a job. A running turn on the
|
|
172
|
+
* space (`hasLiveTurn`, or the server's 409) asks for a reason and sends the action with `force`; the server audits it.
|
|
173
|
+
*/
|
|
174
|
+
declare const useSandboxActions: (api: SandboxesApi) => SandboxActions;
|
|
175
|
+
|
|
176
|
+
export { SANDBOX_ACTION_LABELS, SANDBOX_ACTION_LABEL_CONTEXT, SANDBOX_ACTION_OUTCOME, SANDBOX_CHANGE_LABELS, SANDBOX_CHANGE_LABEL_CONTEXT, SANDBOX_COMMAND_STATE, SANDBOX_DETAIL_TABS, SANDBOX_STATE, SANDBOX_TEXT_PREVIEW_BYTES, SandboxActionsMenu, SandboxDetailScreen, SandboxFilePreview, SandboxMountMode, SandboxUsageBar, SandboxesScreen, formatSandboxBytes, formatSandboxDuration, isSandboxTurnRunningRefusal, sandboxCommandStateOf, sandboxNameOf, sandboxParentPathOf, sandboxPathCrumbs, sandboxPreviewKindOf, sandboxResetPhraseOf, usagePercentOf, useSandboxActions };
|
|
177
|
+
export type { SandboxActionRequest, SandboxActions, SandboxCommandState, SandboxDetailScreenProps, SandboxDetailTab, SandboxFilePreviewProps, SandboxPreviewKind, SandboxesScreenProps };
|