@schlenkr/ragents 0.1.18 → 0.1.20
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/apps/server/src/host-api.json +6 -2
- package/apps/server/src/host-api.ts +3 -2
- package/apps/server/src/host-web.ts +3 -0
- package/apps/server/src/plugin-support/actor-programs/contract.ts +0 -3
- package/apps/server/src/plugin-support/removed-layout.ts +94 -0
- package/apps/server/src/ragents/engine.ts +2 -1
- package/apps/server/src/title-compactor.ts +5 -7
- package/apps/web/dist/assets/highlighted-body-KPVGNVTW-k67VKdbw.js +1 -0
- package/apps/web/dist/assets/main-CVjIz7BS.js +674 -0
- package/apps/web/dist/help/guide-clients.html +22 -42
- package/apps/web/dist/help/guide-clients.md +24 -45
- package/apps/web/dist/help/guide-functions.html +1 -1
- package/apps/web/dist/help/guide-functions.md +1 -1
- package/apps/web/dist/help/guide-getting-started.html +14 -22
- package/apps/web/dist/help/guide-getting-started.md +17 -24
- package/apps/web/dist/help/guide-ideas.html +1 -1
- package/apps/web/dist/help/guide-ideas.md +1 -1
- package/apps/web/dist/help/guide-plugins.html +1 -1
- package/apps/web/dist/help/guide-plugins.md +1 -1
- package/apps/web/dist/help/guide-programs.html +1 -1
- package/apps/web/dist/help/guide-programs.md +1 -1
- package/apps/web/dist/help/index.html +12 -79
- package/apps/web/dist/help/mini-app.css +8 -502
- package/apps/web/dist/host-web.json +28 -23
- package/apps/web/dist/index.html +2 -3
- package/apps/web/dist/run-panel.html +3 -4
- package/apps/web/src/Overview.tsx +4 -143
- package/apps/web/src/PluginChat.tsx +22 -116
- package/apps/web/src/PluginRegistry.tsx +4 -9
- package/apps/web/src/RunPreparationChat.tsx +4 -1
- package/apps/web/src/host-modules.ts +2 -0
- package/apps/web/src/main.tsx +23 -3
- package/apps/web/src/panel/RunLine.tsx +5 -2
- package/apps/web/src/panel/RunsPage.tsx +6 -6
- package/apps/web/src/panel/StartPage.tsx +6 -5
- package/apps/web/src/panel/contract.ts +3 -0
- package/apps/web/src/panel/page-props.ts +2 -0
- package/apps/web/src/run-apps.ts +34 -0
- package/apps/web/src/run-overview.ts +0 -27
- package/apps/web/src/run-panel/PanelContributions.tsx +41 -0
- package/apps/web/src/run-panel/RunPanelApp.tsx +172 -91
- package/apps/web/src/run-panel/RunPanelMenu.tsx +4 -3
- package/apps/web/src/run-panel/RunPanelWorkspace.tsx +8 -2
- package/apps/web/src/run-panel/clipboard.ts +17 -14
- package/apps/web/src/run-panel/host-contract.ts +8 -9
- package/apps/web/src/run-panel/host.ts +5 -31
- package/apps/web/src/run-panel/input-bridge.ts +15 -7
- package/bundles/ragents.activity/ragents-bundle.json +2 -2
- package/bundles/ragents.actor-programs/prompt.hbs +4 -5
- package/bundles/ragents.actor-programs/ragents-bundle.json +4 -14
- package/bundles/ragents.actor-programs/server/index.js +2 -14
- package/bundles/ragents.actor-programs/server/index.js.map +2 -2
- package/bundles/ragents.actor-programs/web/classes.json +1 -1
- package/bundles/ragents.actor-programs/web/index.js +1 -3
- package/bundles/ragents.actor-programs/web/index.js.map +4 -4
- package/bundles/ragents.ask/ragents-bundle.json +2 -2
- package/bundles/ragents.browser/ragents-bundle.json +2 -2
- package/bundles/ragents.documents/ragents-bundle.json +2 -2
- package/bundles/ragents.lsp-fsharp/ragents-bundle.json +2 -2
- package/bundles/ragents.lsp-roslyn/ragents-bundle.json +2 -2
- package/bundles/ragents.lsp-typescript/ragents-bundle.json +2 -2
- package/bundles/ragents.model-relay/ragents-bundle.json +2 -2
- package/bundles/ragents.orchestration/ragents-bundle.json +15 -41
- package/bundles/ragents.orchestration/server/index.js +10 -249
- package/bundles/ragents.orchestration/server/index.js.map +4 -4
- package/bundles/ragents.orchestration/web/chunks/chunk-KU7O6MEX.js +2 -0
- package/bundles/ragents.orchestration/web/chunks/chunk-KU7O6MEX.js.map +7 -0
- package/bundles/ragents.orchestration/web/classes.json +1 -1
- package/bundles/ragents.orchestration/web/exports/web/program-slot.js +1 -1
- package/bundles/ragents.orchestration/web/index.js +10 -18
- package/bundles/ragents.orchestration/web/index.js.map +4 -4
- package/bundles/ragents.overseer/ragents-bundle.json +3 -3
- package/bundles/ragents.overseer/server/index.js +0 -1
- package/bundles/ragents.overseer/server/index.js.map +2 -2
- package/bundles/ragents.processes/ragents-bundle.json +2 -2
- package/bundles/ragents.product/ragents-bundle.json +2 -2
- package/bundles/ragents.profile-distribution/ragents-bundle.json +2 -2
- package/bundles/ragents.reference/ragents-bundle.json +3 -3
- package/bundles/ragents.reference/run-scripts/balcony-wizard/RUN.md +1 -1
- package/bundles/ragents.reference/run-scripts/balcony-wizard/src/server.ts +1 -2
- package/bundles/ragents.reference/run-scripts/balcony-wizard/tests/program.test.ts +6 -7
- package/bundles/ragents.reference/run-scripts/conversation-circle/RUN.md +3 -3
- package/bundles/ragents.reference/run-scripts/conversation-circle/src/server.ts +3 -13
- package/bundles/ragents.reference/run-scripts/conversation-circle/tests/helpers.ts +1 -1
- package/bundles/ragents.reference/run-scripts/conversation-circle/tests/program.test.ts +1 -6
- package/bundles/ragents.reference/run-scripts/learning-afternoon/src/server.ts +1 -15
- package/bundles/ragents.reference/run-scripts/learning-afternoon/tests/program.test.ts +1 -1
- package/bundles/ragents.reference/run-scripts/moderated-round/tests/helpers.ts +1 -1
- package/bundles/ragents.reference/run-scripts/quick-note/RUN.md +1 -1
- package/bundles/ragents.reference/run-scripts/quick-note/src/server.ts +1 -2
- package/bundles/ragents.reference/run-scripts/quick-note/tests/program.test.ts +0 -2
- package/bundles/ragents.reference/run-scripts/run-roster/RUN.md +2 -2
- package/bundles/ragents.reference/run-scripts/run-roster/src/server.ts +1 -2
- package/bundles/ragents.reference/run-scripts/run-roster/tests/program.test.ts +0 -2
- package/bundles/ragents.reference/run-scripts/shared-actor-list/src/server.ts +1 -1
- package/bundles/ragents.reference/run-scripts/shared-actor-list/tests/helpers.ts +1 -1
- package/bundles/ragents.reference/run-scripts/word-game/src/contract.ts +1 -1
- package/bundles/ragents.reference/run-scripts/word-game/src/server.ts +0 -1
- package/bundles/ragents.reference/run-scripts/word-game/tests/program.test.ts +1 -2
- package/bundles/ragents.reference/skills/80-actor-text-analysis/SKILL.md +1 -1
- package/bundles/ragents.reference/skills/90-actor-notes/SKILL.md +1 -1
- package/bundles/ragents.todo/ragents-bundle.json +2 -2
- package/bundles/ragents.transcript/ragents-bundle.json +2 -2
- package/bundles/ragents.watch/ragents-bundle.json +2 -2
- package/bundles/ragents.workspace/ragents-bundle.json +2 -2
- package/package.json +8 -8
- package/packages/agent/dist/core/agent-settings.d.ts +1 -1
- package/packages/agent/src/core/agent-settings.ts +2 -2
- package/packages/ai/dist/types.d.ts +2 -1
- package/packages/ai/src/api/ai-sdk.ts +15 -2
- package/packages/ai/src/types.ts +2 -1
- package/packages/ragents/src/runtime/journal.ts +4 -0
- package/plugins/ragents.actor-programs/prompt.hbs +4 -5
- package/plugins/ragents.actor-programs/server/access-projections.ts +1 -1
- package/plugins/ragents.actor-programs/server/index.ts +0 -2
- package/plugins/ragents.actor-programs/server/runtime.ts +2 -10
- package/plugins/ragents.actor-programs/web/ActorViewFrame.tsx +5 -20
- package/plugins/ragents.actor-programs/web/AppsPanel.tsx +3 -79
- package/plugins/ragents.actor-programs/web/EmbeddedApps.tsx +0 -9
- package/plugins/ragents.actor-programs/web/api.ts +0 -20
- package/plugins/ragents.actor-programs/web/context.ts +0 -3
- package/plugins/ragents.actor-programs/web/index.tsx +0 -9
- package/plugins/ragents.orchestration/ragents-plugin.json +1 -2
- package/plugins/ragents.orchestration/server/index.ts +1 -11
- package/plugins/ragents.orchestration/web/ActorChat.tsx +1 -1
- package/plugins/ragents.orchestration/web/ActorChatControls.tsx +1 -1
- package/plugins/ragents.orchestration/web/FlowInspector.tsx +2 -4
- package/plugins/ragents.orchestration/web/InspectionPanel.tsx +21 -0
- package/plugins/ragents.orchestration/web/index.tsx +13 -9
- package/plugins/ragents.orchestration/web/program-slot.ts +0 -3
- package/plugins/ragents.orchestration/web/run-panel/AddresseeControl.tsx +15 -36
- package/plugins/ragents.orchestration/web/run-panel/RunPanel.tsx +76 -451
- package/plugins/ragents.orchestration/web/run-panel/run-panel-actors.ts +0 -27
- package/plugins/ragents.orchestration/web/run-panel/run-panel-state.ts +7 -40
- package/plugins/ragents.overseer/server/coordinator-prompt.ts +0 -1
- package/plugins/ragents.reference/examples.ts +1 -2
- package/plugins/ragents.reference/run-scripts/balcony-wizard/RUN.md +1 -1
- package/plugins/ragents.reference/run-scripts/balcony-wizard/src/server.ts +1 -2
- package/plugins/ragents.reference/run-scripts/balcony-wizard/tests/program.test.ts +6 -7
- package/plugins/ragents.reference/run-scripts/conversation-circle/RUN.md +3 -3
- package/plugins/ragents.reference/run-scripts/conversation-circle/src/server.ts +3 -13
- package/plugins/ragents.reference/run-scripts/conversation-circle/tests/helpers.ts +1 -1
- package/plugins/ragents.reference/run-scripts/conversation-circle/tests/program.test.ts +1 -6
- package/plugins/ragents.reference/run-scripts/learning-afternoon/src/server.ts +1 -15
- package/plugins/ragents.reference/run-scripts/learning-afternoon/tests/program.test.ts +1 -1
- package/plugins/ragents.reference/run-scripts/moderated-round/tests/helpers.ts +1 -1
- package/plugins/ragents.reference/run-scripts/quick-note/RUN.md +1 -1
- package/plugins/ragents.reference/run-scripts/quick-note/src/server.ts +1 -2
- package/plugins/ragents.reference/run-scripts/quick-note/tests/program.test.ts +0 -2
- package/plugins/ragents.reference/run-scripts/run-roster/RUN.md +2 -2
- package/plugins/ragents.reference/run-scripts/run-roster/src/server.ts +1 -2
- package/plugins/ragents.reference/run-scripts/run-roster/tests/program.test.ts +0 -2
- package/plugins/ragents.reference/run-scripts/shared-actor-list/src/server.ts +1 -1
- package/plugins/ragents.reference/run-scripts/shared-actor-list/tests/helpers.ts +1 -1
- package/plugins/ragents.reference/run-scripts/word-game/src/contract.ts +1 -1
- package/plugins/ragents.reference/run-scripts/word-game/src/server.ts +0 -1
- package/plugins/ragents.reference/run-scripts/word-game/tests/program.test.ts +1 -2
- package/plugins/ragents.reference/skills/80-actor-text-analysis/SKILL.md +1 -1
- package/plugins/ragents.reference/skills/90-actor-notes/SKILL.md +1 -1
- package/plugins/ragents.reference/walkthroughs.ts +13 -14
- package/apps/web/dist/assets/highlighted-body-KPVGNVTW-BwD4uYEe.js +0 -1
- package/apps/web/dist/assets/main-KBrc5Q77.js +0 -11
- package/apps/web/dist/assets/mermaid-HWGCJPDP-CSCkaArr.js +0 -608
- package/apps/web/dist/assets/runPanel-BjG5NBKm.js +0 -26
- package/apps/web/src/App.tsx +0 -318
- package/apps/web/src/SessionList.tsx +0 -157
- package/apps/web/src/SurfaceShortcuts.tsx +0 -60
- package/apps/web/src/WorkspacePanel.tsx +0 -309
- package/apps/web/src/run-panel.tsx +0 -52
- package/bundles/ragents.orchestration/server/chunks/chunk-QS3WJ3D7.js +0 -11
- package/bundles/ragents.orchestration/server/chunks/chunk-QS3WJ3D7.js.map +0 -7
- package/bundles/ragents.orchestration/server/exports/server/contract.js +0 -9
- package/bundles/ragents.orchestration/server/exports/server/contract.js.map +0 -7
- package/bundles/ragents.orchestration/surface.hbs +0 -39
- package/bundles/ragents.orchestration/web/chunks/chunk-CFMJD5ZI.js +0 -2
- package/bundles/ragents.orchestration/web/chunks/chunk-CFMJD5ZI.js.map +0 -7
- package/bundles/ragents.orchestration/web/chunks/chunk-HOBLI364.js +0 -2
- package/bundles/ragents.orchestration/web/chunks/chunk-HOBLI364.js.map +0 -7
- package/bundles/ragents.orchestration/web/chunks/chunk-UCIMT2R4.js +0 -2
- package/bundles/ragents.orchestration/web/chunks/chunk-UCIMT2R4.js.map +0 -7
- package/bundles/ragents.orchestration/web/chunks/chunk-XGPPQCZR.js +0 -2
- package/bundles/ragents.orchestration/web/chunks/chunk-XGPPQCZR.js.map +0 -7
- package/bundles/ragents.orchestration/web/exports/web/surface-entities.js +0 -2
- package/bundles/ragents.orchestration/web/exports/web/surface-entities.js.map +0 -7
- package/bundles/ragents.orchestration/web/exports/web/tile-docking.js +0 -2
- package/bundles/ragents.orchestration/web/exports/web/tile-docking.js.map +0 -7
- package/plugins/ragents.actor-programs/web/ExpandIcon.tsx +0 -5
- package/plugins/ragents.actor-programs/web/FullscreenHost.tsx +0 -31
- package/plugins/ragents.orchestration/contract.ts +0 -51
- package/plugins/ragents.orchestration/server/contract.ts +0 -14
- package/plugins/ragents.orchestration/server/surface-tool.ts +0 -198
- package/plugins/ragents.orchestration/surface.hbs +0 -39
- package/plugins/ragents.orchestration/tiled-layout.ts +0 -55
- package/plugins/ragents.orchestration/web/ActorChatPreview.tsx +0 -29
- package/plugins/ragents.orchestration/web/ActorShortcut.tsx +0 -74
- package/plugins/ragents.orchestration/web/ActorSurfaceControls.tsx +0 -130
- package/plugins/ragents.orchestration/web/ActorTile.tsx +0 -23
- package/plugins/ragents.orchestration/web/Center.tsx +0 -133
- package/plugins/ragents.orchestration/web/SurfaceTiles.tsx +0 -47
- package/plugins/ragents.orchestration/web/TiledSurface.tsx +0 -280
- package/plugins/ragents.orchestration/web/actor-header-settings.ts +0 -41
- package/plugins/ragents.orchestration/web/run-panel/RunPanelSettings.tsx +0 -50
- package/plugins/ragents.orchestration/web/run-panel/run-panel-settings.ts +0 -47
- package/plugins/ragents.orchestration/web/run-panel/sheet-status.ts +0 -30
- package/plugins/ragents.orchestration/web/surface-entities.ts +0 -21
- package/plugins/ragents.orchestration/web/surface-view-settings.ts +0 -42
- package/plugins/ragents.orchestration/web/tile-docking.ts +0 -105
- package/plugins/ragents.orchestration/web/tiled-view-settings.ts +0 -74
- /package/apps/web/dist/assets/{mermaid-HWGCJPDP-BPn4aV2r.css → main-BPn4aV2r.css} +0 -0
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
|
|
3
|
-
const stages = new Map<string, ReadonlySet<string>>();
|
|
4
|
-
const listeners = new Set<() => void>();
|
|
5
|
-
const empty: ReadonlySet<string> = new Set();
|
|
6
|
-
|
|
7
|
-
const subscribe = (listener: () => void) => {
|
|
8
|
-
listeners.add(listener);
|
|
9
|
-
return () => listeners.delete(listener);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function publishSurfaceEntities(runId: string, entities: ReadonlySet<string> | undefined) {
|
|
13
|
-
if (entities) stages.set(runId, entities);
|
|
14
|
-
else stages.delete(runId);
|
|
15
|
-
listeners.forEach((listener) => listener());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function useSurfaceEntities(runId: string): ReadonlySet<string> {
|
|
19
|
-
const read = () => stages.get(runId) ?? empty;
|
|
20
|
-
return useSyncExternalStore(subscribe, read, read);
|
|
21
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createLocalStorageSetting } from "@ragents/web/lib/local-storage-setting";
|
|
2
|
-
import type { RunActor } from "@ragents/web/run-view";
|
|
3
|
-
|
|
4
|
-
export interface SurfaceViewPreferences {
|
|
5
|
-
actorVisibility: Readonly<Record<string, boolean>>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const DEFAULT_SURFACE_VIEW_PREFERENCES: SurfaceViewPreferences = Object.freeze({ actorVisibility: Object.freeze({}) });
|
|
9
|
-
export const surfaceViewStorageKey = (runId: string) => `ragents.orchestration.actor-visibility:${runId}`;
|
|
10
|
-
|
|
11
|
-
export function parseSurfaceViewPreferences(raw: string | null): SurfaceViewPreferences {
|
|
12
|
-
if (raw === null) return DEFAULT_SURFACE_VIEW_PREFERENCES;
|
|
13
|
-
const value: unknown = JSON.parse(raw);
|
|
14
|
-
if (!value || typeof value !== "object" || Array.isArray(value)
|
|
15
|
-
|| Object.keys(value).some((key) => key !== "actorVisibility")
|
|
16
|
-
|| !("actorVisibility" in value) || !value.actorVisibility || typeof value.actorVisibility !== "object"
|
|
17
|
-
|| Array.isArray(value.actorVisibility) || Object.values(value.actorVisibility).some((visible) => typeof visible !== "boolean")) {
|
|
18
|
-
throw new Error("The stored actor visibility is invalid.");
|
|
19
|
-
}
|
|
20
|
-
return value as SurfaceViewPreferences;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const actorVisibleOnSurface = (actor: RunActor, appActorIds: ReadonlySet<string>, preferences: SurfaceViewPreferences, primaryActorId?: string | null): boolean => {
|
|
24
|
-
if (actor.kind === "human") return false;
|
|
25
|
-
const override = Object.hasOwn(preferences.actorVisibility, actor.id) ? preferences.actorVisibility[actor.id] : undefined;
|
|
26
|
-
return override ?? (actor.id !== primaryActorId && !appActorIds.has(actor.id));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const setting = createLocalStorageSetting({
|
|
30
|
-
changeEvent: "ragents-actor-visibility-change",
|
|
31
|
-
matchesKey: (key) => key.startsWith("ragents.orchestration.actor-visibility:"),
|
|
32
|
-
parse: parseSurfaceViewPreferences,
|
|
33
|
-
serialize: JSON.stringify,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export function useSurfaceViewPreferences(runId: string): SurfaceViewPreferences {
|
|
37
|
-
return setting.useValue(surfaceViewStorageKey(runId));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function saveSurfaceViewPreferences(runId: string, preferences: SurfaceViewPreferences) {
|
|
41
|
-
setting.save(surfaceViewStorageKey(runId), preferences);
|
|
42
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type { SurfaceTileNode } from "../tiled-layout";
|
|
2
|
-
|
|
3
|
-
export const SURFACE_TILE_DRAG_TYPE = "application/x-ragents-surface-tile";
|
|
4
|
-
export const TILE_DIVIDER_SIZE = 8;
|
|
5
|
-
export const TILE_MIN_WIDTH = 220;
|
|
6
|
-
export const TILE_MIN_HEIGHT = 160;
|
|
7
|
-
export type TileDockSide = "left" | "right" | "top" | "bottom";
|
|
8
|
-
export interface TileRect { left: number; top: number; width: number; height: number }
|
|
9
|
-
export interface TileDivider extends TileRect {
|
|
10
|
-
path: readonly number[];
|
|
11
|
-
direction: "horizontal" | "vertical";
|
|
12
|
-
ratio: number;
|
|
13
|
-
minimum: number;
|
|
14
|
-
maximum: number;
|
|
15
|
-
span: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function tileEntities(root: SurfaceTileNode | null): string[] {
|
|
19
|
-
return root === null ? [] : "entity" in root ? [root.entity] : root.children.flatMap(tileEntities);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function tileLeaf(root: SurfaceTileNode | null, entity: string): SurfaceTileNode | undefined {
|
|
23
|
-
if (root === null) return undefined;
|
|
24
|
-
if ("entity" in root) return root.entity === entity ? root : undefined;
|
|
25
|
-
return tileLeaf(root.children[0], entity) ?? tileLeaf(root.children[1], entity);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function removeTile(root: SurfaceTileNode | null, entity: string): SurfaceTileNode | null {
|
|
29
|
-
if (root === null || "entity" in root) return root?.entity === entity ? null : root;
|
|
30
|
-
const first = removeTile(root.children[0], entity);
|
|
31
|
-
const second = removeTile(root.children[1], entity);
|
|
32
|
-
if (!first) return second;
|
|
33
|
-
if (!second) return first;
|
|
34
|
-
return first === root.children[0] && second === root.children[1] ? root : { ...root, children: [first, second] };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function dockTile(root: SurfaceTileNode | null, entity: string, target: string | null, side: TileDockSide): SurfaceTileNode | null {
|
|
38
|
-
if ((root && "entity" in root && root.entity === entity && target === null) || entity === target || (target !== null && !tileEntities(root).includes(target))) return root;
|
|
39
|
-
const remaining = removeTile(root, entity);
|
|
40
|
-
const leaf: SurfaceTileNode = tileLeaf(root, entity) ?? { entity };
|
|
41
|
-
if (!remaining) return leaf;
|
|
42
|
-
const wrap = (node: SurfaceTileNode): SurfaceTileNode => ({
|
|
43
|
-
direction: side === "left" || side === "right" ? "horizontal" : "vertical",
|
|
44
|
-
weights: [1, 1],
|
|
45
|
-
children: side === "left" || side === "top" ? [leaf, node] : [node, leaf],
|
|
46
|
-
});
|
|
47
|
-
if (target === null) return wrap(remaining);
|
|
48
|
-
const insert = (node: SurfaceTileNode): SurfaceTileNode => "entity" in node
|
|
49
|
-
? node.entity === target ? wrap(node) : node
|
|
50
|
-
: { ...node, children: [insert(node.children[0]), insert(node.children[1])] };
|
|
51
|
-
return insert(remaining);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function tileMinimum(root: SurfaceTileNode): { width: number; height: number } {
|
|
55
|
-
if ("entity" in root) return { width: TILE_MIN_WIDTH, height: TILE_MIN_HEIGHT };
|
|
56
|
-
const first = tileMinimum(root.children[0]);
|
|
57
|
-
const second = tileMinimum(root.children[1]);
|
|
58
|
-
return root.direction === "horizontal"
|
|
59
|
-
? { width: first.width + second.width + TILE_DIVIDER_SIZE, height: Math.max(first.height, second.height) }
|
|
60
|
-
: { width: Math.max(first.width, second.width), height: first.height + second.height + TILE_DIVIDER_SIZE };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function resizeTile(root: SurfaceTileNode, path: readonly number[], ratio: number): SurfaceTileNode {
|
|
64
|
-
if ("entity" in root) return root;
|
|
65
|
-
if (path.length === 0) {
|
|
66
|
-
const bounded = Math.max(0.001, Math.min(0.999, ratio));
|
|
67
|
-
return { ...root, weights: [bounded, 1 - bounded] };
|
|
68
|
-
}
|
|
69
|
-
const branch = path[0];
|
|
70
|
-
if (branch !== 0 && branch !== 1) return root;
|
|
71
|
-
const children: [SurfaceTileNode, SurfaceTileNode] = [...root.children];
|
|
72
|
-
children[branch] = resizeTile(children[branch], path.slice(1), ratio);
|
|
73
|
-
return { ...root, children };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function tileGeometry(root: SurfaceTileNode, bounds: TileRect): { leaves: Map<string, TileRect>; dividers: TileDivider[] } {
|
|
77
|
-
const leaves = new Map<string, TileRect>();
|
|
78
|
-
const dividers: TileDivider[] = [];
|
|
79
|
-
const visit = (node: SurfaceTileNode, rect: TileRect, path: readonly number[]) => {
|
|
80
|
-
if ("entity" in node) { leaves.set(node.entity, rect); return; }
|
|
81
|
-
const horizontal = node.direction === "horizontal";
|
|
82
|
-
const span = Math.max(0, (horizontal ? rect.width : rect.height) - TILE_DIVIDER_SIZE);
|
|
83
|
-
const firstMinimum = tileMinimum(node.children[0]);
|
|
84
|
-
const secondMinimum = tileMinimum(node.children[1]);
|
|
85
|
-
const minimum = span > 0 ? (horizontal ? firstMinimum.width : firstMinimum.height) / span : 0.5;
|
|
86
|
-
const maximum = span > 0 ? 1 - (horizontal ? secondMinimum.width : secondMinimum.height) / span : 0.5;
|
|
87
|
-
const scale = Math.max(...node.weights);
|
|
88
|
-
const firstWeight = node.weights[0] / scale;
|
|
89
|
-
const requested = firstWeight / (firstWeight + node.weights[1] / scale);
|
|
90
|
-
const ratio = minimum <= maximum ? Math.max(minimum, Math.min(maximum, requested)) : requested;
|
|
91
|
-
const first = span * ratio;
|
|
92
|
-
dividers.push({
|
|
93
|
-
left: rect.left + (horizontal ? first : 0), top: rect.top + (horizontal ? 0 : first),
|
|
94
|
-
width: horizontal ? TILE_DIVIDER_SIZE : rect.width, height: horizontal ? rect.height : TILE_DIVIDER_SIZE,
|
|
95
|
-
path, direction: node.direction, ratio, minimum, maximum, span,
|
|
96
|
-
});
|
|
97
|
-
visit(node.children[0], { ...rect, width: horizontal ? first : rect.width, height: horizontal ? rect.height : first }, [...path, 0]);
|
|
98
|
-
visit(node.children[1], {
|
|
99
|
-
left: rect.left + (horizontal ? first + TILE_DIVIDER_SIZE : 0), top: rect.top + (horizontal ? 0 : first + TILE_DIVIDER_SIZE),
|
|
100
|
-
width: horizontal ? span - first : rect.width, height: horizontal ? rect.height : span - first,
|
|
101
|
-
}, [...path, 1]);
|
|
102
|
-
};
|
|
103
|
-
visit(root, bounds, []);
|
|
104
|
-
return { leaves, dividers };
|
|
105
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createLocalStorageSetting } from "@ragents/web/lib/local-storage-setting";
|
|
2
|
-
import { useEffect, useMemo } from "react";
|
|
3
|
-
import { ORCHESTRATION_PLUGIN_ID, surfaceLayoutOf } from "../contract";
|
|
4
|
-
import { surfaceTileEntities, surfaceTileNodeOf, type SurfaceTileNode } from "../tiled-layout";
|
|
5
|
-
import type { RunView } from "@ragents/web/run-view";
|
|
6
|
-
|
|
7
|
-
export interface SurfacePresentation {
|
|
8
|
-
root: SurfaceTileNode | null;
|
|
9
|
-
programBasis?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const surfacePresentationStorageKey = (runId: string) => `ragents.orchestration.tile-presentation:${runId}`;
|
|
13
|
-
|
|
14
|
-
export function parseSurfacePresentation(raw: string | null): SurfacePresentation | null {
|
|
15
|
-
if (raw === null || raw === "null") return null;
|
|
16
|
-
const value: unknown = JSON.parse(raw);
|
|
17
|
-
if (!value || typeof value !== "object" || Array.isArray(value)
|
|
18
|
-
|| !("root" in value) || Object.keys(value).some((key) => !["root", "programBasis"].includes(key))
|
|
19
|
-
|| ("programBasis" in value && typeof value.programBasis !== "string")) {
|
|
20
|
-
throw new Error("The stored tile view is invalid.");
|
|
21
|
-
}
|
|
22
|
-
return { root: value.root === null ? null : surfaceTileNodeOf(value.root),
|
|
23
|
-
...("programBasis" in value ? { programBasis: value.programBasis as string } : {}),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const setting = createLocalStorageSetting({
|
|
28
|
-
changeEvent: "ragents-tile-presentation-change",
|
|
29
|
-
matchesKey: (key) => key.startsWith("ragents.orchestration.tile-presentation:"),
|
|
30
|
-
parse: parseSurfacePresentation,
|
|
31
|
-
serialize: JSON.stringify,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const useSurfacePresentationOverride = (runId: string) => setting.useValue(surfacePresentationStorageKey(runId));
|
|
35
|
-
export const saveSurfacePresentation = (runId: string, value: SurfacePresentation | null) =>
|
|
36
|
-
setting.save(surfacePresentationStorageKey(runId), value);
|
|
37
|
-
|
|
38
|
-
export const surfaceProgramBasis = (program: SurfacePresentation): string => JSON.stringify({ root: program.root });
|
|
39
|
-
|
|
40
|
-
export function currentSurfaceOverride(personal: SurfacePresentation | null, program: SurfacePresentation): SurfacePresentation | null {
|
|
41
|
-
if (!personal) return null;
|
|
42
|
-
if (personal.programBasis !== undefined) return personal.programBasis === surfaceProgramBasis(program) ? personal : null;
|
|
43
|
-
const entities = new Set(surfaceTileEntities(personal.root));
|
|
44
|
-
return surfaceTileEntities(program.root).some((entity) => !entities.has(entity)) ? null : personal;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function useSurfacePresentation(runId: string, view: RunView | undefined) {
|
|
48
|
-
const state = view?.pluginStates.find((entry) => entry.pluginId === ORCHESTRATION_PLUGIN_ID && entry.scope.kind === "run")?.state;
|
|
49
|
-
const stateKey = useMemo(() => state === undefined ? undefined : JSON.stringify(state), [state]);
|
|
50
|
-
const programLayout = useMemo(() => {
|
|
51
|
-
try { return { layout: stateKey === undefined ? undefined : surfaceLayoutOf(JSON.parse(stateKey)) }; }
|
|
52
|
-
catch (error) { return { error: error instanceof Error ? error.message : String(error) }; }
|
|
53
|
-
}, [stateKey]);
|
|
54
|
-
const program = useMemo((): SurfacePresentation => ({ root: programLayout.layout?.root ?? null }), [programLayout]);
|
|
55
|
-
const programBasis = useMemo(() => surfaceProgramBasis(program), [program]);
|
|
56
|
-
const storedLayout = useSurfacePresentationOverride(runId);
|
|
57
|
-
const personalLayout = view && !programLayout.error ? currentSurfaceOverride(storedLayout, program) : storedLayout;
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (storedLayout && !personalLayout) saveSurfacePresentation(runId, null);
|
|
60
|
-
}, [runId, storedLayout, personalLayout]);
|
|
61
|
-
return { programLayout, personalLayout, presentation: personalLayout ?? program, programBasis };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function initialTileLayout(entities: readonly string[], direction: "horizontal" | "vertical" = "horizontal"): SurfaceTileNode | null {
|
|
65
|
-
if (entities.length === 0) return null;
|
|
66
|
-
if (entities.length === 1) return { entity: entities[0]! };
|
|
67
|
-
const middle = Math.ceil(entities.length / 2);
|
|
68
|
-
const nextDirection = direction === "horizontal" ? "vertical" : "horizontal";
|
|
69
|
-
return {
|
|
70
|
-
direction,
|
|
71
|
-
weights: [middle, entities.length - middle],
|
|
72
|
-
children: [initialTileLayout(entities.slice(0, middle), nextDirection)!, initialTileLayout(entities.slice(middle), nextDirection)!],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
File without changes
|