@fungi.computer/oyster 0.47.5 → 0.48.0
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 -0
- package/dist/apps/index.d.ts +1 -0
- package/dist/apps/index.js +1 -0
- package/dist/apps/install-confirmation.d.ts +26 -0
- package/dist/apps/install-confirmation.js +28 -0
- package/dist/apps/installation.d.ts +6 -0
- package/dist/apps/installation.js +12 -7
- package/dist/host.js +42 -2
- package/dist/install-release-cli.d.ts +1 -1
- package/dist/install-release-cli.js +73 -24
- package/dist/pack.d.ts +52 -1
- package/dist/pack.js +54 -11
- package/dist/page/app-permissions.js +2 -5
- package/dist/page-script.js +1 -1
- package/dist/standalone/agents.js +1 -4
- package/dist/standalone/computer.d.ts +10 -0
- package/dist/standalone/computer.js +43 -1
- package/dist/starter-agent.d.ts +1 -3
- package/dist/starter-agent.js +4 -8
- package/docs/api/apps.md +53 -0
- package/docs/api/pack.md +131 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -275,6 +275,10 @@ Install an App Release that `packRelease` produced with the `oyster` command:
|
|
|
275
275
|
oyster install ./notes-release --installation-id notes
|
|
276
276
|
```
|
|
277
277
|
|
|
278
|
+
It lists what the App asks for and asks you to confirm once. Several Releases
|
|
279
|
+
may be given, and then one list covers them all. Add `--yes` to confirm without
|
|
280
|
+
asking; a run with no terminal and no `--yes` installs nothing.
|
|
281
|
+
|
|
278
282
|
When you need more, add one layer at a time:
|
|
279
283
|
|
|
280
284
|
- `@fungi.computer/oyster/workers-git`: `oysterGitRoot` adds the git door, keys,
|
package/dist/apps/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { permissionPinsSchema, permissionSaveSchema, type PermissionPins, appPer
|
|
|
4
4
|
export { admits, admitMethodMetadata, appInvocationCeiling, approvedBindingGrants, scopedBindings, grantsFor, gateRefusalSchema, gateRequestSchema, invocationGrantsSchema, type AppMethodDeclaration, type AppMethodMetadataDecision, type GateDecision, type GateFacts, type GateRequest, type HostPrincipal, type InvocationGrants, } from "./gate.js";
|
|
5
5
|
export { deriveDeclaredOperations, appCallOperation } from "./operations.js";
|
|
6
6
|
export { appToolPolicySchema, type AppToolAccess, type AppToolEntry, type AppToolPolicy, } from "./tools.js";
|
|
7
|
+
export { installConfirmation, type InstallConfirmation, type InstallConfirmationLine, } from "./install-confirmation.js";
|
|
7
8
|
export { permissionCatalog, type PermissionCatalogEntry } from "./catalog.js";
|
package/dist/apps/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { permissionPinsSchema, permissionSaveSchema, appPermissionsWireSchema, a
|
|
|
4
4
|
export { admits, admitMethodMetadata, appInvocationCeiling, approvedBindingGrants, scopedBindings, grantsFor, gateRefusalSchema, gateRequestSchema, invocationGrantsSchema, } from "./gate.js";
|
|
5
5
|
export { deriveDeclaredOperations, appCallOperation } from "./operations.js";
|
|
6
6
|
export { appToolPolicySchema, } from "./tools.js";
|
|
7
|
+
export { installConfirmation, } from "./install-confirmation.js";
|
|
7
8
|
export { permissionCatalog } from "./catalog.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AppCapabilityId } from "@fungi.computer/puffball/app";
|
|
2
|
+
import type { TeamRole } from "@fungi.computer/cairn/team-role";
|
|
3
|
+
/** One declared permission as the install confirmation words it. */
|
|
4
|
+
export type InstallConfirmationLine = Readonly<{
|
|
5
|
+
capability: AppCapabilityId;
|
|
6
|
+
label: string;
|
|
7
|
+
description: string;
|
|
8
|
+
warning: string | null;
|
|
9
|
+
/** The Apps in this install that declare it. */
|
|
10
|
+
apps: readonly string[];
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Every permission an install declares, once, for one confirmation. `granted`
|
|
14
|
+
* is what confirming approves; `needsApproval` is what stays refused until an
|
|
15
|
+
* owner approves it. Both come from the rule the install reducer applies, so
|
|
16
|
+
* the list cannot promise more or less than the install does.
|
|
17
|
+
*/
|
|
18
|
+
export type InstallConfirmation = Readonly<{
|
|
19
|
+
granted: readonly InstallConfirmationLine[];
|
|
20
|
+
needsApproval: readonly InstallConfirmationLine[];
|
|
21
|
+
}>;
|
|
22
|
+
/** Merge any number of Apps into one combined, once-per-permission list. */
|
|
23
|
+
export declare function installConfirmation(role: TeamRole | null, apps: readonly Readonly<{
|
|
24
|
+
name: string;
|
|
25
|
+
capabilities: readonly AppCapabilityId[];
|
|
26
|
+
}>[]): InstallConfirmation;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { permissionCatalog } from "./catalog.js";
|
|
2
|
+
import { installApprovedCapabilities } from "./installation.js";
|
|
3
|
+
/** Merge any number of Apps into one combined, once-per-permission list. */
|
|
4
|
+
export function installConfirmation(role, apps) {
|
|
5
|
+
const granted = new Map();
|
|
6
|
+
const waiting = new Map();
|
|
7
|
+
for (const { name, capabilities } of apps) {
|
|
8
|
+
const approved = new Set(installApprovedCapabilities(role, capabilities));
|
|
9
|
+
for (const capability of capabilities) {
|
|
10
|
+
// Affordances grant nothing and need no consent, so they are not listed.
|
|
11
|
+
if (permissionCatalog[capability].consent === "affordance")
|
|
12
|
+
continue;
|
|
13
|
+
const into = approved.has(capability) ? granted : waiting;
|
|
14
|
+
into.set(capability, [...(into.get(capability) ?? []), name]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const lines = (rows) => [...rows].map(([capability, names]) => {
|
|
18
|
+
const entry = permissionCatalog[capability];
|
|
19
|
+
return {
|
|
20
|
+
capability,
|
|
21
|
+
label: entry.label,
|
|
22
|
+
description: entry.description,
|
|
23
|
+
warning: entry.warning,
|
|
24
|
+
apps: [...new Set(names)],
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
return { granted: lines(granted), needsApproval: lines(waiting) };
|
|
28
|
+
}
|
|
@@ -130,6 +130,12 @@ export type GrantRefusal = Readonly<{
|
|
|
130
130
|
kind: "refused";
|
|
131
131
|
code: "stale_authority" | "not_approver" | "not_declared" | "invalid_command";
|
|
132
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* What an install approves, for the reducer and for the confirmation shown
|
|
135
|
+
* before it. An approver's install approves the install-class set; a member's
|
|
136
|
+
* approves only the App's own storage, so every other capability waits.
|
|
137
|
+
*/
|
|
138
|
+
export declare function installApprovedCapabilities<Capability extends ApprovedGrant["capability"]>(role: TeamRole | null, capabilities: readonly Capability[], builtInShell?: boolean): Capability[];
|
|
133
139
|
/**
|
|
134
140
|
* The part of a stored approval the current declaration still covers: an
|
|
135
141
|
* operation carries only when it is declared and its stored fingerprint equals
|
|
@@ -129,6 +129,17 @@ export const grantCommandSchema = z.discriminatedUnion("kind", [
|
|
|
129
129
|
]);
|
|
130
130
|
/** Owners and admins approve App permissions; members manage installs only. */
|
|
131
131
|
const approves = (role) => role !== null && teamRoleAtLeast(role, "admin");
|
|
132
|
+
/**
|
|
133
|
+
* What an install approves, for the reducer and for the confirmation shown
|
|
134
|
+
* before it. An approver's install approves the install-class set; a member's
|
|
135
|
+
* approves only the App's own storage, so every other capability waits.
|
|
136
|
+
*/
|
|
137
|
+
export function installApprovedCapabilities(role, capabilities, builtInShell = false) {
|
|
138
|
+
return capabilities.filter((capability) => capability === "app.storage" ||
|
|
139
|
+
(approves(role) &&
|
|
140
|
+
(permissionCatalog[capability].consent === "install" ||
|
|
141
|
+
(capability === "team.workbenchHost" && builtInShell))));
|
|
142
|
+
}
|
|
132
143
|
const declaredRow = (declared, capability) => declared.capabilities.find((row) => row.capability === capability);
|
|
133
144
|
/** Fingerprints the declaration currently assigns to these operations. */
|
|
134
145
|
function fingerprintsOf(declared, capability, operations) {
|
|
@@ -181,13 +192,7 @@ export function applyGrantCommand(current, rawCommand, context) {
|
|
|
181
192
|
// An approver's install approves the install-class set. A member's
|
|
182
193
|
// install approves only the App's own storage, which touches nothing
|
|
183
194
|
// beyond the App's own data; every other capability waits for an approver.
|
|
184
|
-
grants = context.declaration.capabilities
|
|
185
|
-
.filter((capability) => capability === "app.storage" ||
|
|
186
|
-
(approves(context.principal.role) &&
|
|
187
|
-
(permissionCatalog[capability].consent === "install" ||
|
|
188
|
-
(capability === "team.workbenchHost" &&
|
|
189
|
-
context.builtInShell === true))))
|
|
190
|
-
.map((capability) => ({
|
|
195
|
+
grants = installApprovedCapabilities(context.principal.role, context.declaration.capabilities, context.builtInShell === true).map((capability) => ({
|
|
191
196
|
capability,
|
|
192
197
|
capabilityApproved: true,
|
|
193
198
|
operations: declared(capability),
|
package/dist/host.js
CHANGED
|
@@ -24,14 +24,14 @@ import * as Result from "effect/Result";
|
|
|
24
24
|
import { emptyAppDeclaration } from "@fungi.computer/puffball/app";
|
|
25
25
|
import { applyInstallationCommand, carryGrant, installationIdSchema, } from "./apps/installation.js";
|
|
26
26
|
import { admits, scopedBindings, grantsFor } from "./apps/gate.js";
|
|
27
|
-
import { appCallTargetName, appPermissionPageSchema, permissionSaveSchema, } from "./apps/permissions.js";
|
|
27
|
+
import { appCallTargetName, appPermissionPageSchema, pendingCapabilities, permissionSaveSchema, } from "./apps/permissions.js";
|
|
28
28
|
import { app as appRoute, apps as appsRoute, door, member, oysterPrincipalIsOwner, owner, publicRoute, authorityOf, hostAuthorityPorts, reachesInstallation, routes, serveCapability, serveHost, } from "./authorization.js";
|
|
29
29
|
import { deriveDeclaredOperations, appCallOperation, } from "./apps/operations.js";
|
|
30
30
|
import { appMethodRefusalStatus, } from "@fungi.computer/agar/backend";
|
|
31
31
|
import { appCallsDescriptor, } from "./capability-descriptor.js";
|
|
32
32
|
export { capabilityDescriptorSchema, capabilityMethodKindSchema, capabilityMethodSchema, } from "./capability-descriptor.js";
|
|
33
33
|
import { selectionOf, } from "./index.js";
|
|
34
|
-
import { parseRelease, readCachedVerified, sha256, } from "./release.js";
|
|
34
|
+
import { parseRelease, readCachedVerified, ReleaseError, sha256, verifyRelease, } from "./release.js";
|
|
35
35
|
import { createGitDoor } from "./git.js";
|
|
36
36
|
import { maxStorageWatches, storageWatchSchema } from "./storage-watch-wire.js";
|
|
37
37
|
import { getCookie } from "hono/cookie";
|
|
@@ -676,6 +676,46 @@ export function oysterRouteTable(host) {
|
|
|
676
676
|
.apply({ ...selectionOf(installation), status: installation.status }, installation.release);
|
|
677
677
|
return result.ok ? null : instanceRefusal(result);
|
|
678
678
|
};
|
|
679
|
+
// What installing this Release would ask for, before anything is installed;
|
|
680
|
+
// the CLI shows it once and the owner confirms. The artifacts are already
|
|
681
|
+
// uploaded, and verification is the same one install runs. Over an existing
|
|
682
|
+
// installation the install keeps its current grants, so `update` names only
|
|
683
|
+
// what would newly wait for approval.
|
|
684
|
+
table.post("/api/installations/preview", owner("direct"), async (context) => {
|
|
685
|
+
let release;
|
|
686
|
+
let installationId;
|
|
687
|
+
try {
|
|
688
|
+
const request = Schema.decodeUnknownSync(installRequestSchema)(await context.req.json());
|
|
689
|
+
release = parseRelease(request.release);
|
|
690
|
+
installationId =
|
|
691
|
+
request.installationId ?? release.appId.replaceAll("_", "-");
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
return refusal(400, "Invalid install request");
|
|
695
|
+
}
|
|
696
|
+
try {
|
|
697
|
+
const verified = await verifyRelease(host.artifacts, release);
|
|
698
|
+
const declaration = verified.declaration ?? emptyAppDeclaration;
|
|
699
|
+
const existing = await host.installations.get(installationId);
|
|
700
|
+
return Response.json({
|
|
701
|
+
name: release.appId,
|
|
702
|
+
capabilities: declaration.capabilities,
|
|
703
|
+
update:
|
|
704
|
+
// A deleted id is retired: installing it again is a fresh install.
|
|
705
|
+
existing === null || existing.status === "deleted"
|
|
706
|
+
? null
|
|
707
|
+
: {
|
|
708
|
+
installationId,
|
|
709
|
+
needsApproval: pendingCapabilities(existing.authority, declaration, await deriveDeclaredOperations(verified.release, declaration, host.capabilities ?? [])),
|
|
710
|
+
},
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
catch (cause) {
|
|
714
|
+
if (cause instanceof ReleaseError)
|
|
715
|
+
return refusal(422, cause.code);
|
|
716
|
+
throw cause;
|
|
717
|
+
}
|
|
718
|
+
});
|
|
679
719
|
table.post("/api/installations", owner("direct-or-app"), async (context, { origin, principal }) => {
|
|
680
720
|
let request;
|
|
681
721
|
let release;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Cli } from "@fungi.computer/lantern";
|
|
2
|
-
export declare const installReleaseUsage = "Usage: oyster install <directory|release.json
|
|
2
|
+
export declare const installReleaseUsage = "Usage: oyster install <directory|release.json>... [--installation-id <name>] [--yes]";
|
|
3
3
|
export declare function installReleaseCommand(args: readonly string[], ui?: Cli): Promise<void>;
|
|
@@ -4,8 +4,9 @@ import { basename, dirname, resolve } from "node:path";
|
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { Cli } from "@fungi.computer/lantern";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { installConfirmation, permissionCatalog } from "./apps/index.js";
|
|
8
|
+
import { installRelease, previewRelease } from "./pack.js";
|
|
9
|
+
export const installReleaseUsage = "Usage: oyster install <directory|release.json>... [--installation-id <name>] [--yes]";
|
|
9
10
|
export async function installReleaseCommand(args,
|
|
10
11
|
// Progress goes to stderr so stdout stays the installation result.
|
|
11
12
|
ui = new Cli({ brand: "fungi", output: process.stderr })) {
|
|
@@ -15,40 +16,88 @@ ui = new Cli({ brand: "fungi", output: process.stderr })) {
|
|
|
15
16
|
strict: true,
|
|
16
17
|
options: {
|
|
17
18
|
"installation-id": { type: "string" },
|
|
19
|
+
yes: { type: "boolean", short: "y" },
|
|
18
20
|
help: { type: "boolean", short: "h" },
|
|
19
21
|
},
|
|
20
22
|
});
|
|
21
23
|
if (values.help) {
|
|
22
24
|
process.stdout.write(installReleaseUsage +
|
|
23
|
-
"\nUpload
|
|
25
|
+
"\nUpload built Releases and install them using OYSTER_URL and OYSTER_OWNER_KEY.\nYou confirm the Apps' permissions once for the whole install; --yes confirms without asking.\n");
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
if (positionals.length === 0 ||
|
|
29
|
+
(positionals.length > 1 && values["installation-id"] !== undefined))
|
|
28
30
|
throw new Error(installReleaseUsage);
|
|
29
31
|
const url = process.env.OYSTER_URL;
|
|
30
32
|
const key = process.env.OYSTER_OWNER_KEY;
|
|
31
33
|
if (!url || !key)
|
|
32
34
|
throw new Error("Set OYSTER_URL and OYSTER_OWNER_KEY for the target Oyster. " +
|
|
33
35
|
installReleaseUsage);
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(!info.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
const directories = await Promise.all(positionals.map(async (source) => {
|
|
37
|
+
const path = resolve(source);
|
|
38
|
+
const info = await stat(path);
|
|
39
|
+
if (!info.isDirectory() &&
|
|
40
|
+
(!info.isFile() || basename(path) !== "release.json"))
|
|
41
|
+
throw new Error("Expected a Release directory or release.json");
|
|
42
|
+
return info.isDirectory() ? path : dirname(path);
|
|
43
|
+
}));
|
|
44
|
+
ui.welcome("Oyster: install Releases");
|
|
45
|
+
// One list for the whole install, from the rule the install itself applies.
|
|
46
|
+
const previews = await ui.task("Checking what the Apps ask for", async () => {
|
|
47
|
+
const found = [];
|
|
48
|
+
for (const directory of directories)
|
|
49
|
+
found.push({
|
|
50
|
+
directory,
|
|
51
|
+
...(await previewRelease({
|
|
52
|
+
directory,
|
|
53
|
+
url,
|
|
54
|
+
key,
|
|
55
|
+
installationId: values["installation-id"],
|
|
56
|
+
})),
|
|
57
|
+
});
|
|
58
|
+
return found;
|
|
51
59
|
});
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
// A fresh install grants by the shared rule; an update keeps its current
|
|
61
|
+
// grants, so it lists only what newly waits for approval.
|
|
62
|
+
const confirmation = installConfirmation("owner", previews.filter(({ update }) => update === null));
|
|
63
|
+
const lines = (rows) => rows.map((row) => `${row.label}: ${row.description}${row.warning === null ? "" : ` ${row.warning}`} (${row.apps.join(", ")})`);
|
|
64
|
+
if (confirmation.granted.length > 0)
|
|
65
|
+
ui.note(`Installing ${previews
|
|
66
|
+
.filter(({ update }) => update === null)
|
|
67
|
+
.map(({ name }) => name)
|
|
68
|
+
.join(", ")} lets them:`, lines(confirmation.granted));
|
|
69
|
+
if (confirmation.needsApproval.length > 0)
|
|
70
|
+
ui.note("Not granted by installing; approve in Settings > Permissions:", lines(confirmation.needsApproval));
|
|
71
|
+
for (const { name, update } of previews)
|
|
72
|
+
if (update !== null)
|
|
73
|
+
ui.note(`Updating ${update.installationId} (${name}) keeps its current permissions:`, update.needsApproval.length === 0
|
|
74
|
+
? ["Nothing new is requested."]
|
|
75
|
+
: [
|
|
76
|
+
"Newly requested, waiting for approval in Settings > Permissions:",
|
|
77
|
+
...update.needsApproval.map((capability) => permissionCatalog[capability].label),
|
|
78
|
+
]);
|
|
79
|
+
if (values.yes !== true) {
|
|
80
|
+
const answer = await ui.confirm({
|
|
81
|
+
message: `Install ${String(previews.length)} App${previews.length === 1 ? "" : "s"} with these permissions?`,
|
|
82
|
+
});
|
|
83
|
+
if (answer !== true)
|
|
84
|
+
throw new Error("Install cancelled; nothing was installed. Run with --yes to confirm without asking.");
|
|
85
|
+
}
|
|
86
|
+
for (const { directory, release } of previews) {
|
|
87
|
+
const body = await ui.task(`Installing ${basename(directory)}`, async () => {
|
|
88
|
+
const response = await installRelease({
|
|
89
|
+
directory,
|
|
90
|
+
uploaded: release,
|
|
91
|
+
url,
|
|
92
|
+
key,
|
|
93
|
+
installationId: values["installation-id"],
|
|
94
|
+
});
|
|
95
|
+
const text = await response.text();
|
|
96
|
+
if (!response.ok)
|
|
97
|
+
throw new Error("Installation failed (" + String(response.status) + "): " + text);
|
|
98
|
+
return text;
|
|
99
|
+
});
|
|
100
|
+
process.stdout.write(body.trim() + "\n");
|
|
101
|
+
}
|
|
102
|
+
ui.outro(`Open ${url}/ to use ${directories.length === 1 ? "it" : "them"}.`);
|
|
54
103
|
}
|
package/dist/pack.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type InstallationCompletion, type InstallationObservationBudget } from "./installation-client.js";
|
|
2
|
-
import { type ArtifactRef, type Release } from "@fungi.computer/puffball";
|
|
2
|
+
import { type ArtifactRef, type Release, type Sha256Digest } from "@fungi.computer/puffball";
|
|
3
3
|
import { type AppPublisherCoreConfigInput } from "./build.js";
|
|
4
4
|
import type { InstallationOperation } from "./installation-operations.js";
|
|
5
5
|
export { InstallationObservationError, type InstallationCompletion, } from "./installation-client.js";
|
|
@@ -58,6 +58,55 @@ export declare function installFromSource(input: Readonly<{
|
|
|
58
58
|
key: string;
|
|
59
59
|
installationId: string;
|
|
60
60
|
}> & InstallationObservationBudget): Promise<Response>;
|
|
61
|
+
/** Read a built Release directory and upload its artifacts; uploads are idempotent. */
|
|
62
|
+
declare function uploadRelease(input: Readonly<{
|
|
63
|
+
directory: string;
|
|
64
|
+
url: string;
|
|
65
|
+
key: string;
|
|
66
|
+
signal: AbortSignal;
|
|
67
|
+
}>): Promise<{
|
|
68
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
69
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
70
|
+
readonly artifact: {
|
|
71
|
+
readonly artifactRef: ArtifactRef;
|
|
72
|
+
readonly artifactDigest: Sha256Digest;
|
|
73
|
+
readonly provenance: {
|
|
74
|
+
readonly sourceRevision: import("@fungi.computer/puffball").SourceRevision;
|
|
75
|
+
readonly sourceTreeDigest: Sha256Digest;
|
|
76
|
+
readonly buildRecipeDigest: Sha256Digest;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Upload one built Release and ask the Oyster what installing it would
|
|
82
|
+
* request, so an owner can confirm several Releases once before any install.
|
|
83
|
+
*/
|
|
84
|
+
export declare function previewRelease(input: Readonly<{
|
|
85
|
+
directory: string;
|
|
86
|
+
url: string;
|
|
87
|
+
key: string;
|
|
88
|
+
installationId?: string | undefined;
|
|
89
|
+
}>): Promise<{
|
|
90
|
+
release: {
|
|
91
|
+
readonly releaseId: import("@fungi.computer/puffball").ReleaseId;
|
|
92
|
+
readonly appId: import("@fungi.computer/puffball").AppId;
|
|
93
|
+
readonly artifact: {
|
|
94
|
+
readonly artifactRef: ArtifactRef;
|
|
95
|
+
readonly artifactDigest: Sha256Digest;
|
|
96
|
+
readonly provenance: {
|
|
97
|
+
readonly sourceRevision: import("@fungi.computer/puffball").SourceRevision;
|
|
98
|
+
readonly sourceTreeDigest: Sha256Digest;
|
|
99
|
+
readonly buildRecipeDigest: Sha256Digest;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
name: string;
|
|
104
|
+
capabilities: readonly ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage")[];
|
|
105
|
+
update: {
|
|
106
|
+
readonly installationId: string;
|
|
107
|
+
readonly needsApproval: readonly ("computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "approvals" | "agent.list" | "agent.manage" | "agent.rename" | "agent.avatar" | "agent.instructions" | "agent.toolPolicy" | "agent.read" | "agent.send" | "llm.generation" | "media.generation" | "media.share" | "games:servers" | "git.repository" | "apps.open" | "apps.call" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage")[];
|
|
108
|
+
} | null;
|
|
109
|
+
}>;
|
|
61
110
|
/**
|
|
62
111
|
* Upload a packed Release to an Oyster and install it. The host installs a
|
|
63
112
|
* new installation (201) or switches an existing one to this Release (200),
|
|
@@ -73,6 +122,8 @@ export declare function installRelease(input: Readonly<{
|
|
|
73
122
|
/** The Oyster owner key. */
|
|
74
123
|
key: string;
|
|
75
124
|
installationId?: string;
|
|
125
|
+
/** The Release `previewRelease` already read and uploaded; skips both. */
|
|
126
|
+
uploaded?: Awaited<ReturnType<typeof uploadRelease>>;
|
|
76
127
|
/** Report owner-correlated admission without shortening the completion wait. */
|
|
77
128
|
onAdmitted?: (operation: InstallationOperation) => void;
|
|
78
129
|
/** Runs once with the completed operation, before the response is made. */
|
package/dist/pack.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import * as Cause from "effect/Cause";
|
|
6
6
|
import * as Exit from "effect/Exit";
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
8
|
+
import { appCapabilityIdSchema } from "@fungi.computer/puffball/app";
|
|
8
9
|
import { releaseSchema } from "@fungi.computer/puffball/effect";
|
|
9
10
|
import { installOnOyster, installationObservationSignal, completedInstallationResponse, } from "./installation-client.js";
|
|
10
11
|
import { parseArtifactRef, parseReleaseId, parseSha256Digest, parseSourceRevision, } from "@fungi.computer/puffball";
|
|
@@ -115,6 +116,58 @@ export async function installFromSource(input) {
|
|
|
115
116
|
await rm(outDirectory, { recursive: true, force: true });
|
|
116
117
|
}
|
|
117
118
|
}
|
|
119
|
+
/** Read a built Release directory and upload its artifacts; uploads are idempotent. */
|
|
120
|
+
async function uploadRelease(input) {
|
|
121
|
+
const directory = resolve(input.directory);
|
|
122
|
+
const release = Schema.decodeUnknownSync(Schema.fromJsonString(releaseSchema))(await readFile(join(directory, "release.json"), "utf8"));
|
|
123
|
+
const authorization = { Authorization: `Bearer ${input.key}` };
|
|
124
|
+
for (const file of await filesUnder(join(directory, "artifacts"))) {
|
|
125
|
+
const bytes = new Uint8Array(await readFile(file));
|
|
126
|
+
const artifactRef = `artifact:${relative(join(directory, "artifacts"), file)}`;
|
|
127
|
+
const digest = parseSha256Digest(await sha256(bytes));
|
|
128
|
+
const response = await fetch(new URL(`/api/artifacts/${encodeURIComponent(artifactRef)}?digest=${digest}`, input.url), {
|
|
129
|
+
method: "PUT",
|
|
130
|
+
headers: authorization,
|
|
131
|
+
body: bytes,
|
|
132
|
+
signal: input.signal,
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok)
|
|
135
|
+
throw new Error(`Artifact upload failed (${String(response.status)}): ${artifactRef}`);
|
|
136
|
+
}
|
|
137
|
+
return release;
|
|
138
|
+
}
|
|
139
|
+
const releasePreviewSchema = Schema.Struct({
|
|
140
|
+
name: Schema.String,
|
|
141
|
+
capabilities: Schema.Array(appCapabilityIdSchema),
|
|
142
|
+
/** Set when this Release would update an existing installation. */
|
|
143
|
+
update: Schema.NullOr(Schema.Struct({
|
|
144
|
+
installationId: Schema.String,
|
|
145
|
+
needsApproval: Schema.Array(appCapabilityIdSchema),
|
|
146
|
+
})),
|
|
147
|
+
});
|
|
148
|
+
/**
|
|
149
|
+
* Upload one built Release and ask the Oyster what installing it would
|
|
150
|
+
* request, so an owner can confirm several Releases once before any install.
|
|
151
|
+
*/
|
|
152
|
+
export async function previewRelease(input) {
|
|
153
|
+
const signal = installationObservationSignal({});
|
|
154
|
+
const release = await uploadRelease({ ...input, signal });
|
|
155
|
+
const response = await fetch(new URL("/api/installations/preview", input.url), {
|
|
156
|
+
method: "POST",
|
|
157
|
+
headers: {
|
|
158
|
+
Authorization: `Bearer ${input.key}`,
|
|
159
|
+
"Content-Type": "application/json",
|
|
160
|
+
},
|
|
161
|
+
body: JSON.stringify({ release }),
|
|
162
|
+
signal,
|
|
163
|
+
});
|
|
164
|
+
if (!response.ok)
|
|
165
|
+
throw new Error(`Install preview failed (${String(response.status)}): ${await response.text()}`);
|
|
166
|
+
return {
|
|
167
|
+
...Schema.decodeUnknownSync(releasePreviewSchema)(await response.json()),
|
|
168
|
+
release,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
118
171
|
/**
|
|
119
172
|
* Upload a packed Release to an Oyster and install it. The host installs a
|
|
120
173
|
* new installation (201) or switches an existing one to this Release (200),
|
|
@@ -128,17 +181,7 @@ export async function installRelease(input) {
|
|
|
128
181
|
// One installer budget for uploads + observation, not an App authority grant.
|
|
129
182
|
const signal = installationObservationSignal(input);
|
|
130
183
|
signal.throwIfAborted();
|
|
131
|
-
const
|
|
132
|
-
const release = Schema.decodeUnknownSync(Schema.fromJsonString(releaseSchema))(await readFile(join(directory, "release.json"), "utf8"));
|
|
133
|
-
const authorization = { Authorization: `Bearer ${input.key}` };
|
|
134
|
-
for (const file of await filesUnder(join(directory, "artifacts"))) {
|
|
135
|
-
const bytes = new Uint8Array(await readFile(file));
|
|
136
|
-
const artifactRef = `artifact:${relative(join(directory, "artifacts"), file)}`;
|
|
137
|
-
const digest = parseSha256Digest(await sha256(bytes));
|
|
138
|
-
const response = await fetch(new URL(`/api/artifacts/${encodeURIComponent(artifactRef)}?digest=${digest}`, input.url), { method: "PUT", headers: authorization, body: bytes, signal });
|
|
139
|
-
if (!response.ok)
|
|
140
|
-
throw new Error(`Artifact upload failed (${String(response.status)}): ${artifactRef}`);
|
|
141
|
-
}
|
|
184
|
+
const release = input.uploaded ?? (await uploadRelease({ ...input, signal }));
|
|
142
185
|
let installation = {
|
|
143
186
|
url: input.url,
|
|
144
187
|
key: input.key,
|
|
@@ -152,7 +152,6 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
|
|
|
152
152
|
const [retired, setRetired] = useState(false);
|
|
153
153
|
const [refreshNeeded, setRefreshNeeded] = useState(false);
|
|
154
154
|
const [message, setMessage] = useState(null);
|
|
155
|
-
const [saved, setSaved] = useState(false);
|
|
156
155
|
const [loadError, setLoadError] = useState(false);
|
|
157
156
|
const [reload, setReload] = useState(0);
|
|
158
157
|
const [otherOpen, setOtherOpen] = useState(false);
|
|
@@ -205,8 +204,7 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
|
|
|
205
204
|
if (!mounted.current)
|
|
206
205
|
return;
|
|
207
206
|
setRefreshNeeded(false);
|
|
208
|
-
|
|
209
|
-
setMessage("Permissions saved");
|
|
207
|
+
toast.success("Permissions saved", { toasterId: describeId });
|
|
210
208
|
}
|
|
211
209
|
catch (cause) {
|
|
212
210
|
console.error("App permissions surrounding-screen refresh failed", cause);
|
|
@@ -232,7 +230,6 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
|
|
|
232
230
|
return;
|
|
233
231
|
setSaving(true);
|
|
234
232
|
setRefreshNeeded(false);
|
|
235
|
-
setSaved(false);
|
|
236
233
|
setMessage(null);
|
|
237
234
|
try {
|
|
238
235
|
if (!uncertain) {
|
|
@@ -386,7 +383,7 @@ function PermissionEditor({ port, appKey, onAccepted, onStateChange, }) {
|
|
|
386
383
|
? `${view.appName} asks for`
|
|
387
384
|
: `${view.appName} permissions`, headings: gridHeadings, rows: first })), later.length > 0 && (_jsx(Disclosure, { open: otherOpen, onOpenChange: setOtherOpen, summary: `Other permissions · ${String(later.length)}`, children: _jsx(PermissionGrid, { caption: "Already decided", headings: gridHeadings, rows: later }) })), _jsx("div", { className: "sr-only", children: groups
|
|
388
385
|
.flatMap((group) => [...group.columns, ...group.switches])
|
|
389
|
-
.map((column) => (_jsxs("p", { id: `${describeId}-${column.capability}`, children: [column.description, column.warning === null ? "" : ` ${column.warning}`] }, column.capability))) }), screen.groups.length === 0 && _jsx("p", { children: "This App requests no permissions." }), message !== null && !showFooter && (_jsx("p", { role: "status", "aria-live": "polite", children: message })), showFooter && (_jsxs(FormFooter, { divider: false, children: [
|
|
386
|
+
.map((column) => (_jsxs("p", { id: `${describeId}-${column.capability}`, children: [column.description, column.warning === null ? "" : ` ${column.warning}`] }, column.capability))) }), screen.groups.length === 0 && _jsx("p", { children: "This App requests no permissions." }), message !== null && !showFooter && (_jsx("p", { role: "status", "aria-live": "polite", children: message })), showFooter && (_jsxs(FormFooter, { divider: false, children: [refreshNeeded && (_jsx(Button, { type: "button", size: "xs", variant: "outline", disabled: saving, onClick: () => void retryRefresh(), children: "Retry screen refresh" })), (changes.length > 0 || saving || uncertain) && (_jsx(Button, { type: "submit", variant: "primary", disabled: saving || retired || !screen.canEdit, children: saving
|
|
390
387
|
? "Saving…"
|
|
391
388
|
: uncertain
|
|
392
389
|
? "Review current permissions"
|