@fungi.computer/oyster 0.11.0 → 0.12.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 +70 -10
- package/dist/app-builds.d.ts +2 -0
- package/dist/app-builds.js +17 -6
- package/dist/authorization.d.ts +1 -1
- package/dist/build/artifact-writer.d.ts +11 -2
- package/dist/build/artifact-writer.js +42 -24
- package/dist/build/candidate-cli.mjs +33 -19
- package/dist/build/content-objects.d.ts +29 -14
- package/dist/build/content-objects.js +57 -19
- package/dist/build/local-build.js +7 -1
- package/dist/build/submission-contract.d.ts +1 -1
- package/dist/build/submission-contract.js +5 -5
- package/dist/build-egress.d.ts +8 -7
- package/dist/build-egress.js +4 -3
- package/dist/build.d.ts +1 -1
- package/dist/hello-app-script.d.ts +2 -0
- package/dist/hello-app-script.js +1 -0
- package/dist/install-release-cli.d.ts +2 -1
- package/dist/install-release-cli.js +18 -10
- package/dist/installation-client.d.ts +1 -0
- package/dist/installation-operations.d.ts +2 -0
- package/dist/installation-operations.js +1 -0
- package/dist/pack.d.ts +5 -2
- package/dist/pack.js +3 -1
- package/dist/standalone/agents.d.ts +6 -2
- package/dist/standalone/agents.js +21 -4
- package/dist/standalone/computer-egress.d.ts +5 -3
- package/dist/standalone/computer-egress.js +1 -1
- package/dist/standalone/hello-app.d.ts +10 -0
- package/dist/standalone/hello-app.js +81 -0
- package/dist/standalone/install-apps-cli.d.ts +2 -1
- package/dist/standalone/install-apps-cli.js +36 -14
- package/dist/standalone/instance.js +2 -2
- package/dist/standalone/local-desktop.d.ts +11 -0
- package/dist/standalone/local-desktop.js +75 -0
- package/dist/standalone/registry.d.ts +2 -0
- package/dist/standalone/sign-in-link.d.ts +9 -0
- package/dist/standalone/sign-in-link.js +49 -0
- package/dist/standalone/try-cli.d.ts +52 -0
- package/dist/standalone/try-cli.js +427 -0
- package/dist/standalone/worker.js +1 -1
- package/dist/webhook-abuse.d.ts +7 -1
- package/dist/webhook-abuse.js +8 -2
- package/dist/workers.d.ts +7 -2
- package/dist/workers.js +1 -1
- package/docs/api/authorization.md +56 -11
- package/docs/api/build-contract.md +52 -10
- package/docs/api/build.md +16 -2
- package/docs/api/host.md +1 -0
- package/docs/api/pack.md +179 -3
- package/docs/site/agent-quickstart.mdx +8 -0
- package/package.json +13 -8
package/README.md
CHANGED
|
@@ -18,6 +18,70 @@ raw bytes; if output exceeds 2 MiB it retains the head and tail and reports
|
|
|
18
18
|
Deploy one Worker, run `npx oyster install-apps`, and your Oyster builds seven
|
|
19
19
|
Apps on its own Computer and opens on the Tourtois desktop.
|
|
20
20
|
|
|
21
|
+
## Quick start: try it on your computer
|
|
22
|
+
|
|
23
|
+
No Cloudflare account, Docker or payment. You need Node 24 or newer and Git.
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npx @fungi.computer/oyster try
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
That creates `./my-oyster`, installs it, starts Oyster at
|
|
30
|
+
`http://127.0.0.1:8787`, builds the Oyster desktop (Tourtois) from its public
|
|
31
|
+
source, installs a one-page Hello App and opens your browser through a one-time
|
|
32
|
+
sign-in link (the key is never put in a URL). You land on the desktop with Hello
|
|
33
|
+
in the launcher; the page it opens reads **Hello from my first Oyster App**. The
|
|
34
|
+
owner key is saved in `my-oyster/.oyster-owner` and never printed. Press Ctrl-C
|
|
35
|
+
to stop, and run the same command again in `my-oyster` to restart. Use
|
|
36
|
+
`--port <number>` for another port and `--no-open` to keep the browser closed.
|
|
37
|
+
Output is quiet: install and server logs go to `my-oyster/.oyster/`, and
|
|
38
|
+
`--verbose` streams them instead. Piped or CI output is plain lines.
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary>What it does under the hood</summary>
|
|
42
|
+
|
|
43
|
+
`try` runs these steps (shown for pnpm 11; with npm, skip the
|
|
44
|
+
`pnpm-workspace.yaml`). Wrangler is an ordinary dependency; nothing is hidden.
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
mkdir my-oyster && cd my-oyster
|
|
48
|
+
cat > pnpm-workspace.yaml <<'YAML'
|
|
49
|
+
allowBuilds:
|
|
50
|
+
"@google/genai": false
|
|
51
|
+
"@mongodb-js/zstd": false
|
|
52
|
+
esbuild: true
|
|
53
|
+
exifreader: false
|
|
54
|
+
node-liblzma: false
|
|
55
|
+
protobufjs: false
|
|
56
|
+
workerd: true
|
|
57
|
+
YAML
|
|
58
|
+
pnpm add @fungi.computer/oyster @fungi.computer/computer react@^19.2.0 react-dom@^19.2.0
|
|
59
|
+
pnpm add -D wrangler
|
|
60
|
+
cp node_modules/@fungi.computer/oyster/examples/standalone/{worker.ts,wrangler.jsonc} .
|
|
61
|
+
export OYSTER_OWNER_KEY=$(openssl rand -hex 24)
|
|
62
|
+
echo "$OYSTER_OWNER_KEY" > .oyster-owner
|
|
63
|
+
npx wrangler dev --local --enable-containers=false --ip 127.0.0.1 --port 8787 \
|
|
64
|
+
--local-upstream oyster.test --upstream-protocol https \
|
|
65
|
+
--var OYSTER_OWNER_KEY:$OYSTER_OWNER_KEY --var OYSTER_ORIGIN:https://oyster.test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then it builds Tourtois from `github.com/fungi-computer/tourtois` the same way
|
|
69
|
+
(`src/standalone/local-desktop.ts`), and packs a committed one-page
|
|
70
|
+
`bundled-html` App with `packRelease` and installs it as `hello` with
|
|
71
|
+
`installRelease` (both from `@fungi.computer/oyster/pack`) against
|
|
72
|
+
`OYSTER_URL=http://127.0.0.1:8787`; the source is `src/standalone/hello-app.ts`
|
|
73
|
+
in this package.
|
|
74
|
+
|
|
75
|
+
</details>
|
|
76
|
+
|
|
77
|
+
Locally there is no Computer, git storage or Workers AI, so you install your own
|
|
78
|
+
App rather than the seven starter Apps below. The
|
|
79
|
+
[short quick start](https://docs.fungi.computer/oyster-quickstart/) walks the
|
|
80
|
+
same path; the
|
|
81
|
+
[agent quick start](https://docs.fungi.computer/oyster/agent-quickstart/) adds
|
|
82
|
+
MCP and deployment. For the full desktop, continue to the
|
|
83
|
+
[guide to running your own Oyster](https://docs.fungi.computer/guides/run-your-own-oyster/#deploy-it).
|
|
84
|
+
|
|
21
85
|
## What you get
|
|
22
86
|
|
|
23
87
|
`oyster install-apps` installs these Apps. Each one lives in its own repository
|
|
@@ -63,7 +127,7 @@ git through Cloudflare Artifacts, a Computer (a Linux workspace in a Cloudflare
|
|
|
63
127
|
Container) that builds Apps and runs their terminals and files, Agents on
|
|
64
128
|
Workers AI, Workflows and media.
|
|
65
129
|
|
|
66
|
-
##
|
|
130
|
+
## Deploy to Cloudflare
|
|
67
131
|
|
|
68
132
|
Deciding what to run?
|
|
69
133
|
[Is Oyster for you?](https://docs.fungi.computer/is-oyster-for-you/) compares
|
|
@@ -183,16 +247,12 @@ Wrangler version rather than silently adding unrelated token permissions.
|
|
|
183
247
|
|
|
184
248
|
### Upgrading Oyster
|
|
185
249
|
|
|
186
|
-
Oyster's version is not Fungi's
|
|
187
|
-
|
|
188
|
-
the
|
|
250
|
+
Oyster's version is not Fungi's. Find the Oyster and Computer versions for your
|
|
251
|
+
Fungi release on the
|
|
189
252
|
[Open source page](https://docs.fungi.computer/reference/packages/#package-versions-in-each-fungi-release),
|
|
190
|
-
then run the upgrade in
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
```sh
|
|
194
|
-
pnpm add @fungi.computer/oyster@0.8.2 @fungi.computer/computer@0.4.2
|
|
195
|
-
```
|
|
253
|
+
then run the upgrade command in
|
|
254
|
+
[Upgrade Oyster](https://docs.fungi.computer/guides/run-your-own-oyster/#upgrade-oyster)
|
|
255
|
+
in your Oyster project, with the same pnpm and store that installed it.
|
|
196
256
|
|
|
197
257
|
Redeploy with the same `npx wrangler deploy` command you deployed with, then run
|
|
198
258
|
`npx oyster install-apps`. If pnpm stops with `ERR_PNPM_UNEXPECTED_STORE`, rerun
|
package/dist/app-builds.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { type BuildJobLog } from "./build/job-log.js";
|
|
|
22
22
|
import { type Release } from "@fungi.computer/puffball";
|
|
23
23
|
import { type AppPublisherCoreConfigInput } from "./build/effect.js";
|
|
24
24
|
import { type TeamAppCandidateManifest } from "./build/submission-contract.js";
|
|
25
|
+
import { type ContentObjectOwner } from "./build/content-objects.js";
|
|
25
26
|
import { type ArtifactHeads, type ArtifactStore } from "./release.js";
|
|
26
27
|
import type { PublisherTemplateSeedReceipts } from "./source/seed-receipt.js";
|
|
27
28
|
/** A Computer's whole-build budget: a cold build on a 6 GiB Computer measured 185-270 s. */
|
|
@@ -273,6 +274,7 @@ export declare function createOysterAppBuilds(options: OysterAppBuildOptions): R
|
|
|
273
274
|
*/
|
|
274
275
|
admitObjectUpload(jobId: string, computerObjectId: string, grant: string): Promise<Readonly<{
|
|
275
276
|
maxObjectBytes: number;
|
|
277
|
+
owner: ContentObjectOwner;
|
|
276
278
|
}> | null>;
|
|
277
279
|
/**
|
|
278
280
|
* The Computer's candidate manifest for a live job: checked against the
|
package/dist/app-builds.js
CHANGED
|
@@ -25,7 +25,7 @@ import { parseArtifactRef, parseReleaseId, } from "@fungi.computer/puffball";
|
|
|
25
25
|
import { appIdSchema, releaseSchema, sha256DigestSchema, sourceRevisionSchema, } from "@fungi.computer/puffball/effect";
|
|
26
26
|
import { capturedPinnedRecipeSchema, normalizeAppPublisherRecipe, digestPinnedRecipe, fitsPinnedRecipe, pinnedRecipeObjectBound, } from "./build/effect.js";
|
|
27
27
|
import { candidateManifestObjects, decodeCandidateBackend, digestTeamAppCandidateManifest, } from "./build/submission-contract.js";
|
|
28
|
-
import { contentObjectRef } from "./build/content-objects.js";
|
|
28
|
+
import { contentObjectOwner, contentObjectRef, } from "./build/content-objects.js";
|
|
29
29
|
import { createTeamBuildPublisher, teamAppBuildCommand, } from "./build/build-jobs.js";
|
|
30
30
|
import { writeArtifactRoot, } from "./build/artifact-writer.js";
|
|
31
31
|
import { buildGitPassPrefix } from "./git-auth.js";
|
|
@@ -191,6 +191,8 @@ export function createOysterAppBuilds(options) {
|
|
|
191
191
|
read: (artifactRef) => options.artifacts.get(artifactRef),
|
|
192
192
|
};
|
|
193
193
|
migrateOysterAppBuilds(owner);
|
|
194
|
+
// This tenant's uploads, keyed apart from every other tenant's.
|
|
195
|
+
const objectOwner = contentObjectOwner(options.tenantId);
|
|
194
196
|
// A job outlives the owner instance that started it: the Computer keeps
|
|
195
197
|
// building and its own reports (objects, candidate, status) settle the
|
|
196
198
|
// job, so an owner restart must not fail it. A job that reaches its expiry
|
|
@@ -611,6 +613,7 @@ export function createOysterAppBuilds(options) {
|
|
|
611
613
|
return null;
|
|
612
614
|
return {
|
|
613
615
|
maxObjectBytes: pinnedRecipeObjectBound(decodeRecipe(job.recipe)),
|
|
616
|
+
owner: objectOwner,
|
|
614
617
|
};
|
|
615
618
|
},
|
|
616
619
|
/**
|
|
@@ -639,15 +642,23 @@ export function createOysterAppBuilds(options) {
|
|
|
639
642
|
if (!fitsPinnedRecipe(manifest.output, recipe))
|
|
640
643
|
throw new Error("Candidate exceeds its pinned recipe");
|
|
641
644
|
for (const object of candidateManifestObjects(manifest.output)) {
|
|
642
|
-
const
|
|
645
|
+
const artifactRef = contentObjectRef(objectOwner, object.digest, object.mediaType);
|
|
646
|
+
const head = await options.artifacts.head(artifactRef);
|
|
643
647
|
if (head?.byteLength !== object.byteLength ||
|
|
644
|
-
head.digest !== object.digest)
|
|
648
|
+
(head.digest !== null && head.digest !== object.digest))
|
|
645
649
|
throw new Error("Candidate object is not stored as named");
|
|
650
|
+
// Bytes the store never checksummed (a packed upload's plain
|
|
651
|
+
// object) are read and hashed, one object at a time.
|
|
652
|
+
if (head.digest === null)
|
|
653
|
+
await readVerified(options.artifacts, artifactRef, object.digest);
|
|
646
654
|
}
|
|
647
655
|
if (manifest.output.kind !== "ui")
|
|
648
|
-
decodeCandidateBackend(await readVerified(options.artifacts, contentObjectRef(manifest.output.backend.digest), manifest.output.backend.digest));
|
|
656
|
+
decodeCandidateBackend(await readVerified(options.artifacts, contentObjectRef(objectOwner, manifest.output.backend.digest, "application/vnd.fungi.app-backend+json"), manifest.output.backend.digest));
|
|
657
|
+
// The root is named by the manifest (one candidate, one root),
|
|
658
|
+
// outside the namespace uploads are stored in.
|
|
649
659
|
const root = await writeArtifactRoot(manifest.output, storeObjects, {
|
|
650
|
-
|
|
660
|
+
owner: objectOwner,
|
|
661
|
+
rootArtifactRef: parseArtifactRef(`artifact:${await digestTeamAppCandidateManifest(manifest)}`),
|
|
651
662
|
assetPolicy: recipe.assets,
|
|
652
663
|
});
|
|
653
664
|
release = Schema.decodeUnknownSync(releaseSchema)({
|
|
@@ -659,7 +670,7 @@ export function createOysterAppBuilds(options) {
|
|
|
659
670
|
provenance: manifest.provenance,
|
|
660
671
|
},
|
|
661
672
|
});
|
|
662
|
-
// Each object was checked by its
|
|
673
|
+
// Each object was checked by its digest above.
|
|
663
674
|
await verifyRelease(options.artifacts, release, defaultAssetPolicy, false);
|
|
664
675
|
}
|
|
665
676
|
catch {
|
package/dist/authorization.d.ts
CHANGED
|
@@ -217,7 +217,7 @@ export type AgentAdmission = Readonly<{
|
|
|
217
217
|
export declare function agent(id?: (facts: RequestFacts) => Promise<string | null>): Requirement<AgentAdmission>;
|
|
218
218
|
/** What an Agent collection route receives. */
|
|
219
219
|
export type AgentCollectionAdmission = CollectionAdmission<string> & Readonly<{
|
|
220
|
-
/** Whether
|
|
220
|
+
/** Whether `reaches` admits every Agent, so nothing needs filtering. */
|
|
221
221
|
everyAgent: boolean;
|
|
222
222
|
}>;
|
|
223
223
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type AssetBuildPolicy } from "@fungi.computer/puffball/assets";
|
|
2
2
|
import { type ArtifactRef, type Sha256Digest } from "@fungi.computer/puffball";
|
|
3
3
|
import type { BuildOutput, StoredArtifact } from "./effect.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type ContentObjectOwner } from "./content-objects.js";
|
|
5
|
+
import type { CandidateObjectMediaType, CandidateOutputManifest } from "./submission-contract.js";
|
|
5
6
|
/** Write-once object storage for one artifact root. */
|
|
6
7
|
export type ImmutableArtifactObjects = Readonly<{
|
|
7
8
|
/** Create the object, or answer `exists` when the reference is taken. */
|
|
@@ -15,10 +16,16 @@ export type StagedArtifactObject = Readonly<{
|
|
|
15
16
|
bytes: Uint8Array;
|
|
16
17
|
digest: Sha256Digest;
|
|
17
18
|
}>;
|
|
19
|
+
/** One distinct object a build's output manifest names, before it has an owner. */
|
|
20
|
+
export type StagedCandidateObject = Readonly<{
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
digest: Sha256Digest;
|
|
23
|
+
mediaType: CandidateObjectMediaType;
|
|
24
|
+
}>;
|
|
18
25
|
/** A build's output manifest and each distinct object it names. */
|
|
19
26
|
export type StagedBuildOutput = Readonly<{
|
|
20
27
|
manifest: CandidateOutputManifest;
|
|
21
|
-
objects: readonly
|
|
28
|
+
objects: readonly StagedCandidateObject[];
|
|
22
29
|
}>;
|
|
23
30
|
/**
|
|
24
31
|
* Stage a build's bytes: the output manifest that names each object by its
|
|
@@ -30,11 +37,13 @@ export declare function stageBuildOutput(output: BuildOutput): StagedBuildOutput
|
|
|
30
37
|
* objects it names are already stored, and checked, by the caller.
|
|
31
38
|
*/
|
|
32
39
|
export declare function writeArtifactRoot(manifest: CandidateOutputManifest, objects: ImmutableArtifactObjects, options: Readonly<{
|
|
40
|
+
owner: ContentObjectOwner;
|
|
33
41
|
rootArtifactRef: ArtifactRef;
|
|
34
42
|
assetPolicy: AssetBuildPolicy | undefined;
|
|
35
43
|
}>): Promise<StoredArtifact>;
|
|
36
44
|
/** Persist one build's UI, backend and root; an existing object must hold the same bytes. */
|
|
37
45
|
export declare function writeImmutableArtifact(output: BuildOutput, objects: ImmutableArtifactObjects, options: Readonly<{
|
|
46
|
+
owner: ContentObjectOwner;
|
|
38
47
|
rootArtifactRef: ArtifactRef;
|
|
39
48
|
assetPolicy: AssetBuildPolicy | undefined;
|
|
40
49
|
}>): Promise<StoredArtifact>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Oyster's one immutable artifact representation:
|
|
2
|
+
* Oyster's one immutable artifact representation: content-addressed bytes
|
|
3
3
|
* keyed by artifact reference, with media types carried by the App build
|
|
4
|
-
* and asset manifests
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* and asset manifests. A build's own objects are named as uploads are
|
|
5
|
+
* (`contentObjectRef`: owner, digest and stored media type); the objects only
|
|
6
|
+
* the store's owner derives are named outside that namespace. The local packer
|
|
7
|
+
* writes it to a directory, and a host's build owner writes it to that host's
|
|
8
|
+
* artifact store under the building Team's or tenant's namespace.
|
|
7
9
|
*
|
|
8
10
|
* It has two halves. Staging turns a build's bytes into content-addressed
|
|
9
11
|
* objects and the output manifest that names them by digest and size. The
|
|
@@ -21,11 +23,12 @@ import * as Schema from "effect/Schema";
|
|
|
21
23
|
import { assetBuildJsonSchema, assetPathSchema, decodeAssetBuild, } from "@fungi.computer/puffball/assets";
|
|
22
24
|
import { appBuildJsonSchema, createAppBuild, } from "@fungi.computer/puffball/app";
|
|
23
25
|
import { parseArtifactRef, parseSha256Digest, } from "@fungi.computer/puffball";
|
|
26
|
+
import { contentObjectRef, } from "./content-objects.js";
|
|
24
27
|
function sha256(bytes) {
|
|
25
28
|
return parseSha256Digest(`sha256:${createHash("sha256").update(bytes).digest("hex")}`);
|
|
26
29
|
}
|
|
27
|
-
/** The
|
|
28
|
-
function
|
|
30
|
+
/** The address of a derived object: `artifact:sha256-<hex>`, which no upload can name. */
|
|
31
|
+
function derivedArtifactRef(digest) {
|
|
29
32
|
return parseArtifactRef(`artifact:sha256-${digest.slice("sha256:".length)}`);
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
@@ -40,21 +43,20 @@ const fallbackRootBytes = 1024 * 1024;
|
|
|
40
43
|
*/
|
|
41
44
|
export function stageBuildOutput(output) {
|
|
42
45
|
const objects = [];
|
|
43
|
-
const stage = (bytes) => {
|
|
46
|
+
const stage = (bytes, mediaType) => {
|
|
44
47
|
const digest = sha256(bytes);
|
|
45
|
-
if (!objects.some((object) => object.digest === digest))
|
|
46
|
-
objects.push({
|
|
47
|
-
artifactRef: contentArtifactRef(digest),
|
|
48
|
-
bytes: bytes.slice(),
|
|
49
|
-
digest,
|
|
50
|
-
});
|
|
48
|
+
if (!objects.some((object) => object.digest === digest && object.mediaType === mediaType))
|
|
49
|
+
objects.push({ bytes: bytes.slice(), digest, mediaType });
|
|
51
50
|
return { digest, byteLength: bytes.byteLength };
|
|
52
51
|
};
|
|
53
52
|
const declared = output.declaration === undefined ? {} : { declaration: output.declaration };
|
|
54
53
|
const ui = (prepared) => prepared.content.kind === "html"
|
|
55
54
|
? {
|
|
56
55
|
mediaType: "text/html; charset=utf-8",
|
|
57
|
-
content: {
|
|
56
|
+
content: {
|
|
57
|
+
kind: "html",
|
|
58
|
+
...stage(prepared.content.bytes, "text/html; charset=utf-8"),
|
|
59
|
+
},
|
|
58
60
|
}
|
|
59
61
|
: {
|
|
60
62
|
mediaType: "application/vnd.fungi.app-assets+json",
|
|
@@ -63,18 +65,22 @@ export function stageBuildOutput(output) {
|
|
|
63
65
|
base: prepared.content.base,
|
|
64
66
|
assets: prepared.content.assets.map((asset) => ({
|
|
65
67
|
path: asset.path,
|
|
66
|
-
...stage(asset.bytes),
|
|
68
|
+
...stage(asset.bytes, "application/octet-stream"),
|
|
67
69
|
})),
|
|
68
70
|
},
|
|
69
71
|
};
|
|
70
72
|
const manifest = output.kind === "ui"
|
|
71
73
|
? { kind: "ui", ui: ui(output.ui), ...declared }
|
|
72
74
|
: output.kind === "backend"
|
|
73
|
-
? {
|
|
75
|
+
? {
|
|
76
|
+
kind: "backend",
|
|
77
|
+
backend: stage(output.backend, "application/vnd.fungi.app-backend+json"),
|
|
78
|
+
...declared,
|
|
79
|
+
}
|
|
74
80
|
: {
|
|
75
81
|
kind: "app",
|
|
76
82
|
ui: ui(output.ui),
|
|
77
|
-
backend: stage(output.backend),
|
|
83
|
+
backend: stage(output.backend, "application/vnd.fungi.app-backend+json"),
|
|
78
84
|
...declared,
|
|
79
85
|
};
|
|
80
86
|
return { manifest, objects };
|
|
@@ -85,15 +91,15 @@ export function stageBuildOutput(output) {
|
|
|
85
91
|
*/
|
|
86
92
|
function artifactRootObjects(manifest, options) {
|
|
87
93
|
const objects = [];
|
|
88
|
-
const referenced = (object) => ({
|
|
89
|
-
artifactRef:
|
|
94
|
+
const referenced = (object, mediaType) => ({
|
|
95
|
+
artifactRef: contentObjectRef(options.owner, object.digest, mediaType),
|
|
90
96
|
digest: object.digest,
|
|
91
97
|
version: object.digest,
|
|
92
98
|
byteLength: object.byteLength,
|
|
93
99
|
});
|
|
94
100
|
const stage = (bytes, ref) => {
|
|
95
101
|
const digest = sha256(bytes);
|
|
96
|
-
const artifactRef = ref ??
|
|
102
|
+
const artifactRef = ref ?? derivedArtifactRef(digest);
|
|
97
103
|
objects.push({ artifactRef, bytes, digest });
|
|
98
104
|
return {
|
|
99
105
|
artifactRef,
|
|
@@ -107,7 +113,10 @@ function artifactRootObjects(manifest, options) {
|
|
|
107
113
|
if (ui === null)
|
|
108
114
|
return null;
|
|
109
115
|
if (ui.content.kind === "html")
|
|
110
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
...referenced(ui.content, "text/html; charset=utf-8"),
|
|
118
|
+
mediaType: ui.mediaType,
|
|
119
|
+
};
|
|
111
120
|
if (!options.assetPolicy)
|
|
112
121
|
throw new Error("Asset writer requires explicit policy");
|
|
113
122
|
const byPath = new Map();
|
|
@@ -125,7 +134,11 @@ function artifactRootObjects(manifest, options) {
|
|
|
125
134
|
: mediaType;
|
|
126
135
|
if (!contentType)
|
|
127
136
|
throw new Error("Build asset has no maintained content type");
|
|
128
|
-
assets.push({
|
|
137
|
+
assets.push({
|
|
138
|
+
path,
|
|
139
|
+
...referenced(asset, "application/octet-stream"),
|
|
140
|
+
contentType,
|
|
141
|
+
});
|
|
129
142
|
}
|
|
130
143
|
const assetManifest = new TextEncoder().encode(Schema.encodeUnknownSync(assetBuildJsonSchema)({
|
|
131
144
|
format: "fungi-assets-v1",
|
|
@@ -138,7 +151,7 @@ function artifactRootObjects(manifest, options) {
|
|
|
138
151
|
const storedBackend = manifest.kind === "ui"
|
|
139
152
|
? null
|
|
140
153
|
: {
|
|
141
|
-
...referenced(manifest.backend),
|
|
154
|
+
...referenced(manifest.backend, "application/vnd.fungi.app-backend+json"),
|
|
142
155
|
mediaType: "application/vnd.fungi.app-backend+json",
|
|
143
156
|
};
|
|
144
157
|
const rootBytes = new TextEncoder().encode(Schema.encodeUnknownSync(appBuildJsonSchema)(createAppBuild(storedUi, storedBackend, manifest.declaration)));
|
|
@@ -176,6 +189,11 @@ export async function writeArtifactRoot(manifest, objects, options) {
|
|
|
176
189
|
export async function writeImmutableArtifact(output, objects, options) {
|
|
177
190
|
const staged = stageBuildOutput(output);
|
|
178
191
|
const derived = artifactRootObjects(staged.manifest, options);
|
|
179
|
-
|
|
192
|
+
const owned = staged.objects.map(({ bytes, digest, mediaType }) => ({
|
|
193
|
+
artifactRef: contentObjectRef(options.owner, digest, mediaType),
|
|
194
|
+
bytes,
|
|
195
|
+
digest,
|
|
196
|
+
}));
|
|
197
|
+
await storeObjects([...owned, ...derived.objects], objects);
|
|
180
198
|
return derived.root;
|
|
181
199
|
}
|
|
@@ -22548,15 +22548,15 @@ function encodeTeamAppCandidateManifest(manifest) {
|
|
|
22548
22548
|
function candidateManifestObjects(output) {
|
|
22549
22549
|
const objects = [];
|
|
22550
22550
|
const add2 = (object3, mediaType) => {
|
|
22551
|
-
const
|
|
22552
|
-
if (
|
|
22551
|
+
const named = objects.filter(({ digest }) => digest === object3.digest);
|
|
22552
|
+
if (named.some(({ byteLength }) => byteLength !== object3.byteLength))
|
|
22553
|
+
throw new Error("One object digest names two sizes");
|
|
22554
|
+
if (!named.some((seen) => seen.mediaType === mediaType))
|
|
22553
22555
|
objects.push({
|
|
22554
22556
|
digest: object3.digest,
|
|
22555
22557
|
byteLength: object3.byteLength,
|
|
22556
22558
|
mediaType
|
|
22557
22559
|
});
|
|
22558
|
-
else if (seen.byteLength !== object3.byteLength)
|
|
22559
|
-
throw new Error("One object digest names two sizes");
|
|
22560
22560
|
};
|
|
22561
22561
|
if (output.kind !== "backend") {
|
|
22562
22562
|
const { content } = output.ui;
|
|
@@ -24034,26 +24034,24 @@ function sha256(bytes) {
|
|
|
24034
24034
|
`sha256:${createHash2("sha256").update(bytes).digest("hex")}`
|
|
24035
24035
|
);
|
|
24036
24036
|
}
|
|
24037
|
-
function contentArtifactRef(digest) {
|
|
24038
|
-
return parseArtifactRef(`artifact:sha256-${digest.slice("sha256:".length)}`);
|
|
24039
|
-
}
|
|
24040
24037
|
var fallbackRootBytes = 1024 * 1024;
|
|
24041
24038
|
function stageBuildOutput(output) {
|
|
24042
24039
|
const objects = [];
|
|
24043
|
-
const stage = (bytes) => {
|
|
24040
|
+
const stage = (bytes, mediaType) => {
|
|
24044
24041
|
const digest = sha256(bytes);
|
|
24045
|
-
if (!objects.some(
|
|
24046
|
-
|
|
24047
|
-
|
|
24048
|
-
|
|
24049
|
-
digest
|
|
24050
|
-
});
|
|
24042
|
+
if (!objects.some(
|
|
24043
|
+
(object3) => object3.digest === digest && object3.mediaType === mediaType
|
|
24044
|
+
))
|
|
24045
|
+
objects.push({ bytes: bytes.slice(), digest, mediaType });
|
|
24051
24046
|
return { digest, byteLength: bytes.byteLength };
|
|
24052
24047
|
};
|
|
24053
24048
|
const declared = output.declaration === void 0 ? {} : { declaration: output.declaration };
|
|
24054
24049
|
const ui = (prepared) => prepared.content.kind === "html" ? {
|
|
24055
24050
|
mediaType: "text/html; charset=utf-8",
|
|
24056
|
-
content: {
|
|
24051
|
+
content: {
|
|
24052
|
+
kind: "html",
|
|
24053
|
+
...stage(prepared.content.bytes, "text/html; charset=utf-8")
|
|
24054
|
+
}
|
|
24057
24055
|
} : {
|
|
24058
24056
|
mediaType: "application/vnd.fungi.app-assets+json",
|
|
24059
24057
|
content: {
|
|
@@ -24061,14 +24059,24 @@ function stageBuildOutput(output) {
|
|
|
24061
24059
|
base: prepared.content.base,
|
|
24062
24060
|
assets: prepared.content.assets.map((asset) => ({
|
|
24063
24061
|
path: asset.path,
|
|
24064
|
-
...stage(asset.bytes)
|
|
24062
|
+
...stage(asset.bytes, "application/octet-stream")
|
|
24065
24063
|
}))
|
|
24066
24064
|
}
|
|
24067
24065
|
};
|
|
24068
|
-
const manifest = output.kind === "ui" ? { kind: "ui", ui: ui(output.ui), ...declared } : output.kind === "backend" ? {
|
|
24066
|
+
const manifest = output.kind === "ui" ? { kind: "ui", ui: ui(output.ui), ...declared } : output.kind === "backend" ? {
|
|
24067
|
+
kind: "backend",
|
|
24068
|
+
backend: stage(
|
|
24069
|
+
output.backend,
|
|
24070
|
+
"application/vnd.fungi.app-backend+json"
|
|
24071
|
+
),
|
|
24072
|
+
...declared
|
|
24073
|
+
} : {
|
|
24069
24074
|
kind: "app",
|
|
24070
24075
|
ui: ui(output.ui),
|
|
24071
|
-
backend: stage(
|
|
24076
|
+
backend: stage(
|
|
24077
|
+
output.backend,
|
|
24078
|
+
"application/vnd.fungi.app-backend+json"
|
|
24079
|
+
),
|
|
24072
24080
|
...declared
|
|
24073
24081
|
};
|
|
24074
24082
|
return { manifest, objects };
|
|
@@ -35598,7 +35606,13 @@ async function captureCommit(workdir, repositoryPath2, sourceRevision, signal) {
|
|
|
35598
35606
|
function scopedSourceCapture(capture, failureMessage) {
|
|
35599
35607
|
return {
|
|
35600
35608
|
capture: () => acquireRelease2(
|
|
35601
|
-
sync2(
|
|
35609
|
+
sync2(
|
|
35610
|
+
() => (
|
|
35611
|
+
// Canonical, so every path derived from the scratch matches the
|
|
35612
|
+
// realpaths pnpm reports (macOS tmpdir is a symlink).
|
|
35613
|
+
realpathSync(mkdtempSync(join5(tmpdir(), "app-publisher-")))
|
|
35614
|
+
)
|
|
35615
|
+
),
|
|
35602
35616
|
(workdir) => tryPromise2({
|
|
35603
35617
|
try: () => rm(workdir, { recursive: true, force: true }),
|
|
35604
35618
|
catch: () => new Error("Local source cleanup failed")
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A build's uploaded objects in an R2-shaped store: content addressed
|
|
3
|
-
* (`artifact:sha256-<hex>`), written once from a stream with the store
|
|
4
|
-
* itself verifying the digest, and described by `head()` without a read.
|
|
5
|
-
* The bytes never pass through an isolate's memory as a whole.
|
|
6
|
-
*/
|
|
7
1
|
import { type ArtifactRef, type Sha256Digest } from "@fungi.computer/puffball";
|
|
8
2
|
import type { ArtifactHead } from "../release.js";
|
|
9
3
|
import type { CandidateObject, CandidateObjectMediaType } from "./submission-contract.js";
|
|
@@ -16,22 +10,43 @@ export type ContentObjectBucket = Readonly<{
|
|
|
16
10
|
sha256?: ArrayBuffer;
|
|
17
11
|
}>;
|
|
18
12
|
}> | null>;
|
|
19
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Store `value` at `key`; the bucket refuses bytes whose SHA-256 differs.
|
|
15
|
+
* As in R2, `onlyIf: { etagDoesNotMatch: "*" }` makes the put conditional
|
|
16
|
+
* on `key` being absent: an existing object is kept and the put resolves
|
|
17
|
+
* `null` instead.
|
|
18
|
+
*/
|
|
20
19
|
put(key: string, value: ReadableStream<Uint8Array> | Uint8Array, options: Readonly<{
|
|
21
20
|
sha256: string;
|
|
22
21
|
httpMetadata: Readonly<{
|
|
23
22
|
contentType: CandidateObjectMediaType;
|
|
24
23
|
}>;
|
|
24
|
+
onlyIf?: Readonly<{
|
|
25
|
+
etagDoesNotMatch: string;
|
|
26
|
+
}>;
|
|
25
27
|
}>): Promise<object | null>;
|
|
26
28
|
}>;
|
|
27
|
-
/** The
|
|
28
|
-
export
|
|
29
|
+
/** The one Team or tenant whose uploads share a key namespace. */
|
|
30
|
+
export type ContentObjectOwner = Readonly<{
|
|
31
|
+
namespace: string;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Name the upload namespace of a Team or tenant id. Ids are opaque to the
|
|
35
|
+
* store, so the namespace is a fixed-length digest of the id.
|
|
36
|
+
*/
|
|
37
|
+
export declare function contentObjectOwner(id: string): ContentObjectOwner;
|
|
38
|
+
/** The store key of one uploaded object: its owner, digest and stored media type. */
|
|
39
|
+
export declare function contentObjectRef(owner: ContentObjectOwner, digest: Sha256Digest, mediaType: CandidateObjectMediaType): ArtifactRef;
|
|
29
40
|
/** Describe a stored object by its size and the SHA-256 the store verified. */
|
|
30
41
|
export declare function headContentObject(bucket: ContentObjectBucket, artifactRef: ArtifactRef): Promise<ArtifactHead | null>;
|
|
31
42
|
/**
|
|
32
|
-
* Stream one object into the store under its digest. The store refuses a
|
|
33
|
-
* body whose SHA-256 differs
|
|
34
|
-
*
|
|
35
|
-
*
|
|
43
|
+
* Stream one object into the store under its owner, digest and media type. The store refuses a
|
|
44
|
+
* body whose SHA-256 differs. The key is write-once (a stored version may be
|
|
45
|
+
* pinned by a Release): the put is conditional on the key being absent, and
|
|
46
|
+
* an existing object is never replaced. When the key already holds an object
|
|
47
|
+
* of the named size whose store-verified digest is the named one, or that the
|
|
48
|
+
* store never checksummed (a packed upload's plain bytes, which the candidate
|
|
49
|
+
* check reads and hashes), the body is discarded and the object kept; any
|
|
50
|
+
* other existing object refuses the upload.
|
|
36
51
|
*/
|
|
37
|
-
export declare function putContentObject(bucket: ContentObjectBucket, object: CandidateObject, body: ReadableStream<Uint8Array> | null, mediaType: CandidateObjectMediaType): Promise<"stored" | "refused">;
|
|
52
|
+
export declare function putContentObject(bucket: ContentObjectBucket, owner: ContentObjectOwner, object: CandidateObject, body: ReadableStream<Uint8Array> | null, mediaType: CandidateObjectMediaType): Promise<"stored" | "refused">;
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A build's uploaded objects in an R2-shaped store:
|
|
3
|
-
* (`artifact:sha256-<hex>`),
|
|
4
|
-
* itself verifying the digest, and
|
|
5
|
-
* The bytes never pass through an
|
|
2
|
+
* A build's uploaded objects in an R2-shaped store: addressed by their owner,
|
|
3
|
+
* content and stored media type (`artifact:o<owner>-sha256-<hex>.<type>`),
|
|
4
|
+
* written once from a stream with the store itself verifying the digest, and
|
|
5
|
+
* described by `head()` without a read. The bytes never pass through an
|
|
6
|
+
* isolate's memory as a whole.
|
|
7
|
+
*
|
|
8
|
+
* The owner (one Team or tenant) is part of the key, so no upload ever leans
|
|
9
|
+
* on an object another owner stored: erasing one owner's Apps cannot take
|
|
10
|
+
* bytes from under another owner's unreleased upload. The media type is part
|
|
11
|
+
* of the key because a reader (the Publisher's) checks the stored type.
|
|
12
|
+
* Objects a host derives itself (asset manifests, roots) are named outside
|
|
13
|
+
* this namespace, so no upload can address them.
|
|
6
14
|
*/
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
7
16
|
import { parseArtifactRef, parseSha256Digest, } from "@fungi.computer/puffball";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
const mediaTypeKeys = {
|
|
18
|
+
"text/html; charset=utf-8": "html",
|
|
19
|
+
"application/vnd.fungi.app-backend+json": "backend",
|
|
20
|
+
"application/octet-stream": "octets",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Name the upload namespace of a Team or tenant id. Ids are opaque to the
|
|
24
|
+
* store, so the namespace is a fixed-length digest of the id.
|
|
25
|
+
*/
|
|
26
|
+
export function contentObjectOwner(id) {
|
|
27
|
+
if (id.length === 0)
|
|
28
|
+
throw new Error("Content object owner id is empty");
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
namespace: createHash("sha256")
|
|
31
|
+
.update(`fungi.content-object-owner\0${id}`)
|
|
32
|
+
.digest("hex")
|
|
33
|
+
.slice(0, 32),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** The store key of one uploaded object: its owner, digest and stored media type. */
|
|
37
|
+
export function contentObjectRef(owner, digest, mediaType) {
|
|
38
|
+
return parseArtifactRef(`artifact:o${owner.namespace}-sha256-${digest.slice("sha256:".length)}.${mediaTypeKeys[mediaType]}`);
|
|
11
39
|
}
|
|
12
40
|
function hex(bytes) {
|
|
13
41
|
return Array.from(new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
@@ -24,30 +52,40 @@ export async function headContentObject(bucket, artifactRef) {
|
|
|
24
52
|
};
|
|
25
53
|
}
|
|
26
54
|
/**
|
|
27
|
-
* Stream one object into the store under its digest. The store refuses a
|
|
28
|
-
* body whose SHA-256 differs
|
|
29
|
-
*
|
|
30
|
-
*
|
|
55
|
+
* Stream one object into the store under its owner, digest and media type. The store refuses a
|
|
56
|
+
* body whose SHA-256 differs. The key is write-once (a stored version may be
|
|
57
|
+
* pinned by a Release): the put is conditional on the key being absent, and
|
|
58
|
+
* an existing object is never replaced. When the key already holds an object
|
|
59
|
+
* of the named size whose store-verified digest is the named one, or that the
|
|
60
|
+
* store never checksummed (a packed upload's plain bytes, which the candidate
|
|
61
|
+
* check reads and hashes), the body is discarded and the object kept; any
|
|
62
|
+
* other existing object refuses the upload.
|
|
31
63
|
*/
|
|
32
|
-
export async function putContentObject(bucket, object, body, mediaType) {
|
|
33
|
-
const artifactRef = contentObjectRef(object.digest);
|
|
64
|
+
export async function putContentObject(bucket, owner, object, body, mediaType) {
|
|
65
|
+
const artifactRef = contentObjectRef(owner, object.digest, mediaType);
|
|
66
|
+
const kept = (existing) => existing.byteLength === object.byteLength &&
|
|
67
|
+
(existing.digest === null || existing.digest === object.digest);
|
|
34
68
|
const existing = await headContentObject(bucket, artifactRef);
|
|
35
|
-
if (existing !== null
|
|
36
|
-
existing.digest === object.digest &&
|
|
37
|
-
existing.byteLength === object.byteLength) {
|
|
69
|
+
if (existing !== null) {
|
|
38
70
|
// Read the body through (discarding it) rather than cancel it: a
|
|
39
71
|
// cancelled request body resets the uploader's connection mid-send.
|
|
40
72
|
await body?.pipeTo(new WritableStream());
|
|
41
|
-
return "stored";
|
|
73
|
+
return kept(existing) ? "stored" : "refused";
|
|
42
74
|
}
|
|
75
|
+
let written;
|
|
43
76
|
try {
|
|
44
|
-
await bucket.put(artifactRef, body ?? new Uint8Array(0), {
|
|
77
|
+
written = await bucket.put(artifactRef, body ?? new Uint8Array(0), {
|
|
45
78
|
sha256: object.digest.slice("sha256:".length),
|
|
46
79
|
httpMetadata: { contentType: mediaType },
|
|
80
|
+
onlyIf: { etagDoesNotMatch: "*" },
|
|
47
81
|
});
|
|
48
82
|
}
|
|
49
83
|
catch {
|
|
50
84
|
return "refused";
|
|
51
85
|
}
|
|
52
|
-
|
|
86
|
+
if (written !== null)
|
|
87
|
+
return "stored";
|
|
88
|
+
// Another writer took the key after the head above; its object is kept.
|
|
89
|
+
const taken = await headContentObject(bucket, artifactRef);
|
|
90
|
+
return taken !== null && kept(taken) ? "stored" : "refused";
|
|
53
91
|
}
|