@acryldev/blends-frame 0.2.0 → 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/lib/app-share.d.ts +22 -0
- package/lib/client.js +258 -5
- package/lib/client.js.map +1 -1
- package/lib/contract.d.ts +26 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +143 -1
- package/lib/index.js.map +1 -1
- package/lib/types/client/ShareAppSection.d.ts +20 -0
- package/lib/types/client/ShareChooser.d.ts +10 -0
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/contract.d.ts +26 -0
- package/package.json +5 -5
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/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { Context } from '@deepseek-ai/cordis';
|
|
|
10
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';
|
|
@@ -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
|
@@ -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`;
|
|
@@ -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
|
|
@@ -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());
|
|
@@ -3996,6 +4137,7 @@ function apply(ctx, config = {}) {
|
|
|
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
|
}),
|