@acryldev/blends-frame 0.1.6 → 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/README.md +4 -4
- package/cordis.patch.yml +1 -1
- package/lib/app-plugins.d.ts +1 -1
- package/lib/app-share.d.ts +22 -0
- package/lib/auto-save.d.ts +1 -1
- package/lib/client.js +323 -49
- package/lib/client.js.map +1 -1
- package/lib/contract.d.ts +26 -0
- package/lib/git-sync.d.ts +1 -1
- package/lib/index.d.ts +7 -4
- package/lib/index.js +166 -24
- package/lib/index.js.map +1 -1
- package/lib/types/client/SettingsLauncher.d.ts +1 -1
- package/lib/types/client/ShareAppSection.d.ts +20 -0
- package/lib/types/client/ShareChooser.d.ts +10 -0
- package/lib/types/client/canvas/app-canvas.d.ts +1 -1
- package/lib/types/client/chat-draft.d.ts +1 -1
- package/lib/types/client/chats.d.ts +1 -1
- package/lib/types/client/desktop-app.d.ts +1 -1
- package/lib/types/client/frame-state.d.ts +13 -1
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/client/tools.d.ts +1 -1
- package/lib/types/client/versions.d.ts +1 -1
- package/lib/types/contract.d.ts +26 -0
- package/package.json +21 -22
package/lib/contract.d.ts
CHANGED
|
@@ -144,6 +144,32 @@ export declare function parseFrameState(value: unknown): FrameState;
|
|
|
144
144
|
export declare const FRAME_PLUGINS_PATH = "/api/acryl-blends-frame/plugins";
|
|
145
145
|
export declare const FRAME_PLUGINS_SWITCH_PATH = "/api/acryl-blends-frame/plugins/switch";
|
|
146
146
|
/** POST `{ name }`: what sharing this local plugin would do (a {@link SharePlan}); nothing leaves the machine. */
|
|
147
|
+
/** POST `{ owner?, visibility? }`: what sharing the whole app to GitHub would send (Settings > Share); sends nothing. */
|
|
148
|
+
export declare const FRAME_APP_SHARE_PLAN_PATH = "/api/acryl-blends-frame/app/share-plan";
|
|
149
|
+
/** POST `{ owner?, visibility?, confirm }`: share the app exactly as the confirmed plan says, or nothing. */
|
|
150
|
+
export declare const FRAME_APP_SHARE_PATH = "/api/acryl-blends-frame/app/share";
|
|
151
|
+
/** Who may see a shared app, and under which account; both optional (the signed-in account, blend.yaml's visibility). */
|
|
152
|
+
export interface AppShareRequest {
|
|
153
|
+
readonly owner?: string;
|
|
154
|
+
readonly visibility?: 'private' | 'public';
|
|
155
|
+
}
|
|
156
|
+
/** What sharing the app sends: the save plugin's plan, shown before anything leaves the computer. */
|
|
157
|
+
export interface AppSharePlanView {
|
|
158
|
+
/** `owner/name` of a repository the share creates, or the address of the one the app already pushes to. */
|
|
159
|
+
readonly repository: string;
|
|
160
|
+
readonly create: boolean;
|
|
161
|
+
readonly visibility: 'private' | 'public';
|
|
162
|
+
/** Files changed since the last save; the share saves them first. */
|
|
163
|
+
readonly changes: number;
|
|
164
|
+
}
|
|
165
|
+
/** Where the app went. */
|
|
166
|
+
export interface AppSharedView {
|
|
167
|
+
readonly remote: string;
|
|
168
|
+
readonly created: boolean;
|
|
169
|
+
}
|
|
170
|
+
export declare function parseAppSharePlan(value: unknown): AppSharePlanView;
|
|
171
|
+
export declare function parseAppShared(value: unknown): AppSharedView;
|
|
172
|
+
export declare function parseAppShareRequest(value: unknown): AppShareRequest | undefined;
|
|
147
173
|
export declare const FRAME_PLUGINS_SHARE_PLAN_PATH = "/api/acryl-blends-frame/plugins/share-plan";
|
|
148
174
|
/** POST `{ name, confirm }`: publish it, only when `confirm` is the plan the person said yes to and it still holds. */
|
|
149
175
|
export declare const FRAME_PLUGINS_SHARE_PATH = "/api/acryl-blends-frame/plugins/share";
|
package/lib/git-sync.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Push and pull run one at a time: a second click waits for the first to finish rather than racing it.
|
|
13
13
|
*/
|
|
14
14
|
import { type GitRemoteState, type GitSyncResult, type PushPlan } from './contract.ts';
|
|
15
|
-
/** The part of the confined git runner (
|
|
15
|
+
/** The part of the confined git runner (`@acryldev/versions`) this module uses: an argument array, never a shell. */
|
|
16
16
|
export interface SyncGit {
|
|
17
17
|
run(args: readonly string[], cwd: string, acceptExit?: number, timeoutMs?: number): Promise<{
|
|
18
18
|
readonly stdout: string;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
* and its local branches. The frame itself is the client half (`./client`).
|
|
4
4
|
*
|
|
5
5
|
* One effect owns the confined git runner and both registrations; disposal unmounts the route and reaps any git call still running. The right
|
|
6
|
-
* panel's terminals, PTY agents, files and git are the workspace's own Host services (
|
|
6
|
+
* panel's terminals, PTY agents, files and git are the workspace's own Host services (`@acryldev/workspace`), run here as a child plugin: only its
|
|
7
7
|
* Host half, since the frame, not the workbench, owns the page.
|
|
8
8
|
*/
|
|
9
9
|
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
-
import { Acryl } from '
|
|
10
|
+
import { Acryl } from '@acryldev/blends';
|
|
11
11
|
import { GitRunner, Versions } from '@acryldev/versions';
|
|
12
12
|
import { type ShareAppPluginResult } from './app-plugins.ts';
|
|
13
|
+
import { type AppSharePort } from './app-share.ts';
|
|
13
14
|
import { type GraphPort } from './plugin-graph.ts';
|
|
14
15
|
import { type AppRow } from './app-reload.ts';
|
|
15
16
|
import { SelectionInbox } from './selection-context.ts';
|
|
@@ -38,7 +39,7 @@ export interface FrameConfig {
|
|
|
38
39
|
*/
|
|
39
40
|
readonly shareOwner?: string;
|
|
40
41
|
}
|
|
41
|
-
export declare const name = "
|
|
42
|
+
export declare const name = "acryl-blends-frame";
|
|
42
43
|
export declare const inject: string[];
|
|
43
44
|
/** `git for-each-ref` lines `<current marker> <name>`: the checked-out branch first, the rest by name. */
|
|
44
45
|
export declare function parseBranches(stdout: string): FrameBranch[];
|
|
@@ -162,8 +163,10 @@ export interface FrameRoutesDeps {
|
|
|
162
163
|
readonly appReload?: AppReloadPort;
|
|
163
164
|
/** The element picks waiting for the step that reads the message they belong to (./selection-context.ts). */
|
|
164
165
|
readonly selection?: SelectionInbox;
|
|
166
|
+
/** Share the whole app to GitHub (Settings > Share), through the app's own share command. */
|
|
167
|
+
readonly appShare?: AppSharePort;
|
|
165
168
|
}
|
|
166
|
-
export declare function frameRoutes({ state, report, plugins, graph, feedback, branches, branchChats, chatSaves, shared, realChats, gitSync, snapshot, appReload, selection }: FrameRoutesDeps): Acryl;
|
|
169
|
+
export declare function frameRoutes({ state, report, plugins, graph, feedback, branches, branchChats, chatSaves, shared, realChats, gitSync, snapshot, appReload, selection, appShare }: FrameRoutesDeps): Acryl;
|
|
167
170
|
/**
|
|
168
171
|
* The app's rows, plugins first and routes after (the order they start in): each as the reloader drives it. A row's module is imported under the
|
|
169
172
|
* current generation (`./app-generation.ts`) by the loader itself, so `restart` stops the row's plugin and has the loader start the entry again - not
|
package/lib/index.js
CHANGED
|
@@ -4,15 +4,15 @@ import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
|
4
4
|
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
5
5
|
import { mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
6
6
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
-
import { Acryl } from "
|
|
7
|
+
import { Acryl } from "@acryldev/blends";
|
|
8
8
|
import { error } from "@acryldev/loopback-http";
|
|
9
9
|
import { INVALID_JSON, jsonBody, ownPage, privateApi, readJson } from "@acryldev/loopback-http/router";
|
|
10
|
-
import { PluginStore, StoreConflictError, bumpVersion, gitCli, githubCli, parseVersion, savePlugin, sharePlugin, storeRootOf } from "@
|
|
10
|
+
import { PluginStore, StoreConflictError, bumpVersion, gitCli, githubCli, parseVersion, savePlugin, sharePlugin, storeRootOf } from "@acryldev/plugin-hub-core";
|
|
11
11
|
import { GitRunner, Versions } from "@acryldev/versions";
|
|
12
12
|
import * as workspaceHost from "@acryldev/workspace";
|
|
13
13
|
import { promisify } from "node:util";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
|
-
import { digestFolder } from "@
|
|
15
|
+
import { digestFolder } from "@acryldev/blends-core";
|
|
16
16
|
import { parseDocument } from "yaml";
|
|
17
17
|
import { boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
18
18
|
import { randomBytes } from "node:crypto";
|
|
@@ -107,6 +107,33 @@ function parseFrameState(value) {
|
|
|
107
107
|
const FRAME_PLUGINS_PATH = `${FRAME_API_PREFIX}/plugins`;
|
|
108
108
|
const FRAME_PLUGINS_SWITCH_PATH = `${FRAME_API_PREFIX}/plugins/switch`;
|
|
109
109
|
/** POST `{ name }`: what sharing this local plugin would do (a {@link SharePlan}); nothing leaves the machine. */
|
|
110
|
+
/** POST `{ owner?, visibility? }`: what sharing the whole app to GitHub would send (Settings > Share); sends nothing. */
|
|
111
|
+
const FRAME_APP_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/app/share-plan`;
|
|
112
|
+
/** POST `{ owner?, visibility?, confirm }`: share the app exactly as the confirmed plan says, or nothing. */
|
|
113
|
+
const FRAME_APP_SHARE_PATH = `${FRAME_API_PREFIX}/app/share`;
|
|
114
|
+
function parseAppSharePlan(value) {
|
|
115
|
+
if (!isRecord$2(value)) throw new Error("app share plan: not a plan");
|
|
116
|
+
const { repository, create, visibility, changes } = value;
|
|
117
|
+
if (typeof repository !== "string" || repository === "" || typeof create !== "boolean") throw new Error("app share plan: repository");
|
|
118
|
+
if (visibility !== "private" && visibility !== "public") throw new Error("app share plan: visibility");
|
|
119
|
+
if (typeof changes !== "number" || !Number.isSafeInteger(changes) || changes < 0) throw new Error("app share plan: changes");
|
|
120
|
+
return {
|
|
121
|
+
repository,
|
|
122
|
+
create,
|
|
123
|
+
visibility,
|
|
124
|
+
changes
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function parseAppShareRequest(value) {
|
|
128
|
+
if (!isRecord$2(value)) return void 0;
|
|
129
|
+
const { owner, visibility } = value;
|
|
130
|
+
if (owner !== void 0 && (typeof owner !== "string" || !GITHUB_NAME.test(owner))) return void 0;
|
|
131
|
+
if (visibility !== void 0 && visibility !== "private" && visibility !== "public") return void 0;
|
|
132
|
+
return {
|
|
133
|
+
...owner === void 0 ? {} : { owner },
|
|
134
|
+
...visibility === void 0 ? {} : { visibility }
|
|
135
|
+
};
|
|
136
|
+
}
|
|
110
137
|
const FRAME_PLUGINS_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/plugins/share-plan`;
|
|
111
138
|
/** POST `{ name, confirm }`: publish it, only when `confirm` is the plan the person said yes to and it still holds. */
|
|
112
139
|
const FRAME_PLUGINS_SHARE_PATH = `${FRAME_API_PREFIX}/plugins/share`;
|
|
@@ -506,8 +533,8 @@ async function switchAppPlugin(root, kind, name, on) {
|
|
|
506
533
|
}
|
|
507
534
|
/** The frame's own Loader rows the list shows: ACRYL's plugins around the app, not DSH's engine rows nor the rows that run the app. */
|
|
508
535
|
function isFramePlugin(moduleName, entryId) {
|
|
509
|
-
if (entryId.startsWith("app-") || entryId === "
|
|
510
|
-
return moduleName.startsWith("
|
|
536
|
+
if (entryId.startsWith("app-") || entryId === "@acryldev/door") return false;
|
|
537
|
+
return moduleName.startsWith("@acryldev/");
|
|
511
538
|
}
|
|
512
539
|
/** Cordis `FiberState`: PENDING 0, LOADING 1, ACTIVE 2, FAILED 3. */
|
|
513
540
|
function frameRowState(row) {
|
|
@@ -810,6 +837,82 @@ function appNavigationTarget(appBase, url, headers) {
|
|
|
810
837
|
function appFallbackTarget(appBase, url, headers) {
|
|
811
838
|
return fromAppPage(appBase, url, headers) ? appUrlUnderBase(appBase, url) : void 0;
|
|
812
839
|
}
|
|
840
|
+
// src/app-share.ts
|
|
841
|
+
/**
|
|
842
|
+
* Share the whole app to GitHub from Settings > Share, through the app's own share command (`plugins/save/share-cli.ts`, the save plugin): the
|
|
843
|
+
* same command `npm run share` and ACRYL Control Center's Share run, so the rules (a plan first, sent only on the person's yes, refused on a
|
|
844
|
+
* secret, visibility kept in blend.yaml) live in one place. The command runs on the Node.js this host runs on (inside a desktop product that is
|
|
845
|
+
* Electron's, as Node).
|
|
846
|
+
*/
|
|
847
|
+
const SHARE_COMMAND = join("plugins", "save", "share-cli.ts");
|
|
848
|
+
/** A share the app refused, in its own words (not signed in, a secret in a file, the app changed since the plan). */
|
|
849
|
+
var AppShareRefused = class extends Error {};
|
|
850
|
+
function runCommand(root, env) {
|
|
851
|
+
return (args) => new Promise((resolve, reject) => {
|
|
852
|
+
const child = spawn(process.execPath, [SHARE_COMMAND, ...args], {
|
|
853
|
+
cwd: root,
|
|
854
|
+
env: {
|
|
855
|
+
...env,
|
|
856
|
+
ELECTRON_RUN_AS_NODE: "1"
|
|
857
|
+
},
|
|
858
|
+
windowsHide: true
|
|
859
|
+
});
|
|
860
|
+
let stdout = "";
|
|
861
|
+
let stderr = "";
|
|
862
|
+
child.stdout.on("data", (chunk) => {
|
|
863
|
+
stdout += chunk.toString("utf8");
|
|
864
|
+
});
|
|
865
|
+
child.stderr.on("data", (chunk) => {
|
|
866
|
+
stderr += chunk.toString("utf8");
|
|
867
|
+
});
|
|
868
|
+
child.on("error", reject);
|
|
869
|
+
child.on("close", (code) => {
|
|
870
|
+
resolve({
|
|
871
|
+
code,
|
|
872
|
+
stdout,
|
|
873
|
+
stderr
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
/** The last line of the command's output that is a JSON object, or undefined. */
|
|
879
|
+
function lastJson(text) {
|
|
880
|
+
for (const line of text.trim().split(/\r?\n/u).reverse()) try {
|
|
881
|
+
const value = JSON.parse(line);
|
|
882
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) return value;
|
|
883
|
+
} catch {}
|
|
884
|
+
}
|
|
885
|
+
const requestArgs = (request) => [...request.owner === void 0 ? [] : ["--owner", request.owner], ...request.visibility === void 0 ? [] : ["--visibility", request.visibility]];
|
|
886
|
+
function appShareCommand(root, env = process.env, run = runCommand(root, env)) {
|
|
887
|
+
const ask = async (args) => {
|
|
888
|
+
if (!existsSync(join(root, SHARE_COMMAND))) throw new AppShareRefused("This app was made before apps could share themselves. Update it (npx acrylblends@latest update), then try again.");
|
|
889
|
+
const result = await run(["--json", ...args]);
|
|
890
|
+
const answer = lastJson(result.stdout);
|
|
891
|
+
if (answer?.ok === false) throw new AppShareRefused(`Not shared: ${typeof answer.reason === "string" ? answer.reason : "the app refused"}`);
|
|
892
|
+
if (answer === void 0 || result.code !== 0) {
|
|
893
|
+
const said = result.stderr.trim().split(/\r?\n/u).at(-1) ?? "";
|
|
894
|
+
throw new Error(`the app's share command ended with ${String(result.code)}${said === "" ? "" : `: ${said}`}`);
|
|
895
|
+
}
|
|
896
|
+
return answer;
|
|
897
|
+
};
|
|
898
|
+
return {
|
|
899
|
+
async plan(request) {
|
|
900
|
+
return parseAppSharePlan(await ask(requestArgs(request)));
|
|
901
|
+
},
|
|
902
|
+
async share(request, confirmed) {
|
|
903
|
+
const answer = await ask([
|
|
904
|
+
...requestArgs(request),
|
|
905
|
+
"--confirm",
|
|
906
|
+
Buffer.from(JSON.stringify(confirmed), "utf8").toString("base64url")
|
|
907
|
+
]);
|
|
908
|
+
if (answer.ok !== true || typeof answer.remote !== "string") throw new Error("the app did not say where it was shared");
|
|
909
|
+
return {
|
|
910
|
+
remote: answer.remote,
|
|
911
|
+
created: answer.created === true
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
}
|
|
813
916
|
// src/graph-contract.ts
|
|
814
917
|
/**
|
|
815
918
|
* The plugin graph's wire types: what the frame's Host answers and what the browser draws (Settings > Plugins > Graph). Ported from cordis-plugin-graph
|
|
@@ -1398,7 +1501,7 @@ function pluginShareOf(service) {
|
|
|
1398
1501
|
*
|
|
1399
1502
|
* The turn-end signal is DSH's own: its `workspace-changes` plugin diffs the working tree around every turn (the person's earlier unsaved edits never
|
|
1400
1503
|
* enter a turn's list) and appends a `workspace/changes` session event only when files changed, so a turn that changed nothing makes no version here.
|
|
1401
|
-
* The Host hears that event on `session/event`, reads the turn's file list from `ctx.workspaceChanges.summary`, and saves through
|
|
1504
|
+
* The Host hears that event on `session/event`, reads the turn's file list from `ctx.workspaceChanges.summary`, and saves through `@acryldev/versions`.
|
|
1402
1505
|
*/
|
|
1403
1506
|
/** The longest a version's name is, in characters, before it is cut at a word. */
|
|
1404
1507
|
const SUBJECT_LIMIT = 50;
|
|
@@ -2079,7 +2182,7 @@ function guardOutwardCommands(events, report) {
|
|
|
2079
2182
|
if (decided.kind === "deny" || decided.kind === "cancel") return decided;
|
|
2080
2183
|
const needs = outwardApproval(exec);
|
|
2081
2184
|
if (needs === void 0) return decided;
|
|
2082
|
-
report(
|
|
2185
|
+
report(`@acryldev/blends-frame: asked the person before ${needs.action}`);
|
|
2083
2186
|
return {
|
|
2084
2187
|
kind: "ask",
|
|
2085
2188
|
reason: `outward: ${needs.action}`,
|
|
@@ -2297,7 +2400,7 @@ function stopsHost(exec, host) {
|
|
|
2297
2400
|
const { command } = parsed(exec.arguments);
|
|
2298
2401
|
if (typeof command !== "string" || !/\b(?:kill|pkill|killall|Stop-Process|taskkill)\b/iu.test(command)) return false;
|
|
2299
2402
|
const named = host.hostPort === void 0 ? String(host.hostPid) : `${String(host.hostPid)}|${String(host.hostPort)}`;
|
|
2300
|
-
if (new RegExp(`\\b(?:${named})\\b|ide-host
|
|
2403
|
+
if (new RegExp(`\\b(?:${named})\\b|ide-host|@acryldev/node-server`, "iu").test(command)) return true;
|
|
2301
2404
|
for (const invocation of killInvocations(command)) {
|
|
2302
2405
|
if (invocation.verb === "kill" && killTargets(invocation.args, host)) return true;
|
|
2303
2406
|
if (invocation.verb === "pkill" && pkillTargets(invocation.args, host)) return true;
|
|
@@ -2709,7 +2812,7 @@ function createBranchChatsStore(path) {
|
|
|
2709
2812
|
*
|
|
2710
2813
|
* Push and pull run one at a time: a second click waits for the first to finish rather than racing it.
|
|
2711
2814
|
*/
|
|
2712
|
-
/** A fetch or push talks to another machine: as long as the versions' own push (
|
|
2815
|
+
/** A fetch or push talks to another machine: as long as the versions' own push (`@acryldev/versions`). */
|
|
2713
2816
|
const REMOTE_TIMEOUT_MS = 12e4;
|
|
2714
2817
|
/** git's own line for a failure, else the fallback: what a person reads in the Git tab. */
|
|
2715
2818
|
function reason(cause, fallback) {
|
|
@@ -3157,7 +3260,7 @@ var GithubConnect = class {
|
|
|
3157
3260
|
/**
|
|
3158
3261
|
* The app's snapshot verbs as the frame's service `appSnapshot`: every version the frame saves (Save point, the auto-save) is captured first, so
|
|
3159
3262
|
* a version is always a snapshot whose `blend.yaml` names every plugin folder and whose lock matches; the agent's snapshot tools
|
|
3160
|
-
* (
|
|
3263
|
+
* (@acryldev/app-context) run on it too, the same code as `npm run snapshot`. The verbs are the app's own (`plugins/manifest/snapshot.ts`, part of the app's
|
|
3161
3264
|
* folder), so the frame runs the version the app was made with; an app made before them says so instead of guessing. Pushing and pulling are
|
|
3162
3265
|
* not here: they are the person's (the Git tab and the versions header, ./git-sync.ts), and a push sends only a plan they confirmed.
|
|
3163
3266
|
*/
|
|
@@ -3218,10 +3321,10 @@ function createAppSnapshot(root, remote, load = () => loadSnapshotVerbs(root)) {
|
|
|
3218
3321
|
* and its local branches. The frame itself is the client half (`./client`).
|
|
3219
3322
|
*
|
|
3220
3323
|
* One effect owns the confined git runner and both registrations; disposal unmounts the route and reaps any git call still running. The right
|
|
3221
|
-
* panel's terminals, PTY agents, files and git are the workspace's own Host services (
|
|
3324
|
+
* panel's terminals, PTY agents, files and git are the workspace's own Host services (`@acryldev/workspace`), run here as a child plugin: only its
|
|
3222
3325
|
* Host half, since the frame, not the workbench, owns the page.
|
|
3223
3326
|
*/
|
|
3224
|
-
const name = "
|
|
3327
|
+
const name = "acryl-blends-frame";
|
|
3225
3328
|
const inject = [
|
|
3226
3329
|
"router",
|
|
3227
3330
|
"routerHttp",
|
|
@@ -3400,8 +3503,46 @@ function parseBranchName(body) {
|
|
|
3400
3503
|
const problem = branchNameProblem(name);
|
|
3401
3504
|
return problem === void 0 ? { name } : { problem };
|
|
3402
3505
|
}
|
|
3403
|
-
function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branches, branchChats, chatSaves, shared, realChats, gitSync, snapshot, appReload, selection }) {
|
|
3506
|
+
function frameRoutes({ state, report = () => {}, plugins, graph, feedback, branches, branchChats, chatSaves, shared, realChats, gitSync, snapshot, appReload, selection, appShare }) {
|
|
3404
3507
|
const app = new Acryl();
|
|
3508
|
+
if (appShare !== void 0) {
|
|
3509
|
+
const refusal = (cause) => cause instanceof AppShareRefused ? { say: cause.message } : {
|
|
3510
|
+
say: "The app could not be shared. Nothing was sent.",
|
|
3511
|
+
details: cause instanceof Error ? cause.message : String(cause)
|
|
3512
|
+
};
|
|
3513
|
+
app.post(FRAME_APP_SHARE_PLAN_PATH, ownPage, jsonBody(), async (c) => {
|
|
3514
|
+
const body = await readJson(c);
|
|
3515
|
+
const request = body === INVALID_JSON ? void 0 : parseAppShareRequest(body);
|
|
3516
|
+
if (request === void 0) return c.json(error("invalid share request"), 400);
|
|
3517
|
+
try {
|
|
3518
|
+
return c.json(await appShare.plan(request));
|
|
3519
|
+
} catch (cause) {
|
|
3520
|
+
if (!(cause instanceof AppShareRefused)) report(cause);
|
|
3521
|
+
return c.json(plainBody(refusal(cause)), 409);
|
|
3522
|
+
}
|
|
3523
|
+
});
|
|
3524
|
+
app.post(FRAME_APP_SHARE_PATH, ownPage, jsonBody(), async (c) => {
|
|
3525
|
+
const body = await readJson(c);
|
|
3526
|
+
const fields = body === INVALID_JSON || body === null || typeof body !== "object" ? void 0 : body;
|
|
3527
|
+
const request = fields === void 0 ? void 0 : parseAppShareRequest({
|
|
3528
|
+
owner: fields.owner,
|
|
3529
|
+
visibility: fields.visibility
|
|
3530
|
+
});
|
|
3531
|
+
if (request === void 0) return c.json(error("invalid share request"), 400);
|
|
3532
|
+
let confirmed;
|
|
3533
|
+
try {
|
|
3534
|
+
confirmed = parseAppSharePlan(fields?.confirm);
|
|
3535
|
+
} catch {
|
|
3536
|
+
return c.json(error("an app is shared only after the person confirms its plan"), 400);
|
|
3537
|
+
}
|
|
3538
|
+
try {
|
|
3539
|
+
return c.json(await appShare.share(request, confirmed));
|
|
3540
|
+
} catch (cause) {
|
|
3541
|
+
if (!(cause instanceof AppShareRefused)) report(cause);
|
|
3542
|
+
return c.json(plainBody(refusal(cause)), 409);
|
|
3543
|
+
}
|
|
3544
|
+
});
|
|
3545
|
+
}
|
|
3405
3546
|
if (appReload !== void 0) app.get(FRAME_APP_PATH, ownPage, async (c) => {
|
|
3406
3547
|
const after = Number(c.req.query("after"));
|
|
3407
3548
|
return c.json(c.req.query("after") !== void 0 && Number.isInteger(after) ? await appReload.wait(after, APP_POLL_MS) : appReload.view());
|
|
@@ -3802,7 +3943,7 @@ function apply(ctx, config = {}) {
|
|
|
3802
3943
|
const shareOwner = typeof wantedOwner === "string" && /^[A-Za-z0-9-]+$/u.test(wantedOwner) ? wantedOwner : void 0;
|
|
3803
3944
|
const shareTo = shareOwner === void 0 ? {} : { owner: shareOwner };
|
|
3804
3945
|
const root = ctx.appInstance.root;
|
|
3805
|
-
if (typeof root !== "string") throw new Error("
|
|
3946
|
+
if (typeof root !== "string") throw new Error("@acryldev/blends-frame: the app instance has no app folder (root)");
|
|
3806
3947
|
const appBase = appPage === void 0 ? void 0 : appPage.replace(/\/+$/u, "");
|
|
3807
3948
|
if (appBase !== void 0 && appBase !== "" && appBase !== "/") {
|
|
3808
3949
|
ctx.inject(["nodeServer"], (child) => {
|
|
@@ -3817,7 +3958,7 @@ function apply(ctx, config = {}) {
|
|
|
3817
3958
|
});
|
|
3818
3959
|
if (appFallbackTarget(appBase, url, request.headers) === void 0) return void 0;
|
|
3819
3960
|
return server.throughRouter(request, connection);
|
|
3820
|
-
}), "
|
|
3961
|
+
}), "@acryldev/blends-frame: an app page's URLs under the canvas prefix");
|
|
3821
3962
|
});
|
|
3822
3963
|
ctx.effect(() => ctx.router.wrap(async (c, next) => {
|
|
3823
3964
|
const url = new URL(c.req.url);
|
|
@@ -3832,21 +3973,21 @@ function apply(ctx, config = {}) {
|
|
|
3832
3973
|
};
|
|
3833
3974
|
if (copy !== void 0) init.body = await copy.arrayBuffer();
|
|
3834
3975
|
c.res = await ctx.router.fetch(new Request(new URL(target, url.origin), init), c.env?.connection ?? {});
|
|
3835
|
-
}), "
|
|
3976
|
+
}), "@acryldev/blends-frame: app requests under the canvas prefix");
|
|
3836
3977
|
}
|
|
3837
3978
|
ctx.plugin(workspaceHost, appPage === void 0 ? {} : { appPage });
|
|
3838
3979
|
ctx.inject(["workspaceController"], (child) => {
|
|
3839
3980
|
const workspaces = child.workspaceController;
|
|
3840
3981
|
child.effect(() => {
|
|
3841
3982
|
workspaces.create({ path: root }).catch((cause) => {
|
|
3842
|
-
child.logger.error(
|
|
3983
|
+
child.logger.error(`@acryldev/blends-frame: the app folder could not be made a workspace: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
3843
3984
|
});
|
|
3844
3985
|
return () => {};
|
|
3845
|
-
}, "
|
|
3986
|
+
}, "@acryldev/blends-frame: the chat works in the app folder");
|
|
3846
3987
|
});
|
|
3847
3988
|
ctx.effect(() => {
|
|
3848
3989
|
const report = (cause) => {
|
|
3849
|
-
ctx.logger.error(
|
|
3990
|
+
ctx.logger.error(`@acryldev/blends-frame: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
3850
3991
|
};
|
|
3851
3992
|
const git = new GitRunner();
|
|
3852
3993
|
const chatsFile = createBranchChatsStore(branchChatsFile(ctx.appInstance.home));
|
|
@@ -3880,7 +4021,7 @@ function apply(ctx, config = {}) {
|
|
|
3880
4021
|
const githubConnect = new GithubConnect(githubConnectPorts());
|
|
3881
4022
|
ctx.effect(() => () => {
|
|
3882
4023
|
githubConnect.dispose();
|
|
3883
|
-
}, "
|
|
4024
|
+
}, "@acryldev/blends-frame: connecting GitHub");
|
|
3884
4025
|
const plugins = {
|
|
3885
4026
|
read: async () => {
|
|
3886
4027
|
const [app, frame] = await Promise.all([readAppPlugins(root, git, join(ctx.appInstance.home, "shared-plugins.json"), ghRepositoryCheck, storeRootOf(ctx.appInstance.home)), readFramePlugins(root, frameRows())]);
|
|
@@ -3986,16 +4127,17 @@ function apply(ctx, config = {}) {
|
|
|
3986
4127
|
};
|
|
3987
4128
|
const selectionInbox = new SelectionInbox();
|
|
3988
4129
|
ctx.effect(() => installSelectionContext(ctx, selectionInbox, (cause) => {
|
|
3989
|
-
ctx.logger.error(
|
|
3990
|
-
}), "
|
|
4130
|
+
ctx.logger.error(`@acryldev/blends-frame: the selected element did not reach the chat: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
4131
|
+
}), "@acryldev/blends-frame: the picked element as context");
|
|
3991
4132
|
ctx.router.route("/", frameRoutes({
|
|
3992
4133
|
state,
|
|
3993
4134
|
selection: selectionInbox,
|
|
3994
4135
|
report: (cause) => {
|
|
3995
|
-
ctx.logger.error(
|
|
4136
|
+
ctx.logger.error(`@acryldev/blends-frame: request failed: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
3996
4137
|
},
|
|
3997
4138
|
plugins,
|
|
3998
4139
|
graph: graph.port,
|
|
4140
|
+
appShare: appShareCommand(root),
|
|
3999
4141
|
feedback: feedbackPort(() => {
|
|
4000
4142
|
return (ctx.get("loader")?.entries().find((row) => row.options.id === APP_PLUGINS_ROW))?.fiber?.ctx?.get("feedback") ?? ctx.get("feedback");
|
|
4001
4143
|
}),
|
|
@@ -4053,7 +4195,7 @@ function apply(ctx, config = {}) {
|
|
|
4053
4195
|
stopWatching();
|
|
4054
4196
|
autoSave.settled().then(() => git.dispose());
|
|
4055
4197
|
};
|
|
4056
|
-
}, "
|
|
4198
|
+
}, "@acryldev/blends-frame: git runner and state route");
|
|
4057
4199
|
}
|
|
4058
4200
|
export { AutoSave, FRAME_API_PREFIX, FRAME_STATE_PATH, SaveStore, appRowsOf, apply, countChanges, feedbackPort, frameRoutes, inject, messageText, name, parseBranchName, parseBranches, parseFrameState, requestSubject, saveVersion, sharedVersions };
|
|
4059
4201
|
|