@fungi.computer/oyster 0.15.0 → 0.17.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/dist/agents.d.ts +15 -0
- package/dist/agents.js +10 -1
- package/dist/apps/permissions.js +8 -1
- package/dist/auth.d.ts +2 -0
- package/dist/auth.js +9 -8
- package/dist/boot-host-script.js +1 -1
- package/dist/build/candidate-cli.mjs +4 -0
- package/dist/computer.d.ts +5 -0
- package/dist/computer.js +1 -0
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +2 -2
- package/dist/hello-app-script.js +1 -1
- package/dist/host-page-assets.js +1 -1
- package/dist/host-page.d.ts +5 -1
- package/dist/host-page.js +23 -23
- package/dist/host.js +6 -1
- package/dist/page/app-access.js +23 -1
- package/dist/page/app-rights.d.ts +8 -0
- package/dist/page/app-rights.js +13 -0
- package/dist/page/computer-handles.d.ts +15 -0
- package/dist/page/computer-handles.js +4 -1
- package/dist/page/mount.d.ts +5 -0
- package/dist/page/mount.js +4 -0
- package/dist/page-script.js +3 -3
- package/dist/root-data.d.ts +3 -0
- package/dist/standalone/agents.d.ts +8 -0
- package/dist/standalone/agents.js +61 -12
- package/dist/standalone/cloudflare-account.d.ts +10 -0
- package/dist/standalone/cloudflare-account.js +17 -0
- package/dist/standalone/computer.d.ts +2 -2
- package/dist/standalone/computer.js +16 -1
- package/dist/standalone/media.d.ts +2 -0
- package/dist/standalone/media.js +17 -1
- package/dist/standalone/owner-routes.js +2 -0
- package/dist/standalone/registry.d.ts +16 -0
- package/dist/standalone/registry.js +30 -0
- package/dist/standalone/sign-in-link.d.ts +1 -1
- package/dist/standalone/sign-in-link.js +9 -18
- package/dist/standalone/trial-starters.d.ts +52 -0
- package/dist/standalone/trial-starters.js +67 -0
- package/dist/starter-agent.d.ts +65 -0
- package/dist/starter-agent.js +85 -0
- package/docs/api/agents.md +23 -0
- package/docs/api/auth.md +10 -0
- package/docs/api/computer.md +4 -0
- package/docs/api/host.md +1 -0
- package/docs/api/page/mount.md +2 -0
- package/docs/api/root-data.md +10 -9
- package/docs/api/workers-git.md +14 -9
- package/docs/api/workers.md +28 -20
- package/package.json +25 -21
package/dist/root-data.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Release } from "@fungi.computer/puffball";
|
|
2
2
|
import { createAppStorage } from "./app-storage.js";
|
|
3
3
|
import type { InstallationStore, verifyRelease } from "./host.js";
|
|
4
|
+
import type { InstallingApp } from "@fungi.computer/nacre/workbench-directory";
|
|
4
5
|
import { type AppDirectoryEntry } from "@fungi.computer/nacre/app-directory";
|
|
5
6
|
/**
|
|
6
7
|
* A destination the host offers the dashboard. This is a structural twin of
|
|
@@ -26,6 +27,8 @@ export type OysterRootDirectory = Readonly<{
|
|
|
26
27
|
computerId: string;
|
|
27
28
|
name: string;
|
|
28
29
|
}>;
|
|
30
|
+
/** Trial starter Apps still being set up; the registry adds them. */
|
|
31
|
+
installing?: readonly InstallingApp[];
|
|
29
32
|
}>;
|
|
30
33
|
/** Existing installation, Release and SQLite owners supplied by the root. */
|
|
31
34
|
export type OysterRootDataOptions = Parameters<typeof createAppStorage>[0] & Readonly<{
|
|
@@ -27,6 +27,7 @@ import { type AgentModelChoice, type AgentModelRefusal } from "./agent-model-cho
|
|
|
27
27
|
import * as Schema from "effect/Schema";
|
|
28
28
|
import { type FrameBindingProps } from "../cloudflare.js";
|
|
29
29
|
import { type AppAgentScheduleListInput, type AgentSchedulePage, type AgentScheduleTarget, type AgentScheduleControlReceipt } from "../agent-schedules.js";
|
|
30
|
+
import { type StarterLedgerRow } from "../starter-agent.js";
|
|
30
31
|
import type { Avatar } from "@fungi.computer/sprite/avatar";
|
|
31
32
|
import type { InvocationFrame } from "../invocation.js";
|
|
32
33
|
import type { OysterJson } from "../host.js";
|
|
@@ -445,6 +446,13 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
|
|
|
445
446
|
archived?: boolean;
|
|
446
447
|
}>): readonly AgentEntry[];
|
|
447
448
|
has(agentId: string): boolean;
|
|
449
|
+
private starterLedgerOwner;
|
|
450
|
+
private get starterLedger();
|
|
451
|
+
/** The starter Agent's one-row ledger and the Agent total it reads, for the owner's ensure. */
|
|
452
|
+
readStarter(): StarterLedgerRow | undefined;
|
|
453
|
+
recordStarter(row: StarterLedgerRow): void;
|
|
454
|
+
/** Every Agent in the directory, archived ones included. */
|
|
455
|
+
agentTotal(): number;
|
|
448
456
|
/** Resolve the existing recorded creator for host-side owner admission. */
|
|
449
457
|
readCreator(agentId: string): string | null;
|
|
450
458
|
/** Immutable creating Agent, distinct from the human credential owner. */
|
|
@@ -45,6 +45,7 @@ import { configuredProviderEgress, providerFetch, } from "@fungi.computer/veil/g
|
|
|
45
45
|
import { createAssistantMessageEventStream } from "@earendil-works/pi-ai/utils/event-stream";
|
|
46
46
|
import { agentModelChoice, agentModelChoiceSchema, AgentModelRefused, selectAgentModel, } from "./agent-model-choice.js";
|
|
47
47
|
import { CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL, createAiBindingFetch, } from "@earendil-works/pi-ai/api/cloudflare-ai-binding";
|
|
48
|
+
import { cloudflareAccountReady } from "./cloudflare-account.js";
|
|
48
49
|
import { cloudflareWorkersAIProvider } from "@earendil-works/pi-ai/providers/cloudflare-workers-ai";
|
|
49
50
|
import { getSupportedThinkingLevels } from "@earendil-works/pi-ai/models";
|
|
50
51
|
import { agentModelListSchema } from "@fungi.computer/shiitake/model-list";
|
|
@@ -56,6 +57,7 @@ import { agentScheduleBindingArgs, appAgentScheduleListInputSchema, agentSchedul
|
|
|
56
57
|
import { readAgentSchedulePage, controlAgentSchedule, } from "@fungi.computer/shiitake-extensions/schedules/client";
|
|
57
58
|
import { agentScheduleTargetSchema } from "@fungi.computer/shiitake-extensions/schedules";
|
|
58
59
|
import { createAgentAvatarStore, } from "../agent-avatars.js";
|
|
60
|
+
import { createStarterLedger, ensureStarterAgent, } from "../starter-agent.js";
|
|
59
61
|
import { agentIds, createAgentDirectory, createFleetSessions, commandSettlementSchema, DirectoryError, } from "@fungi.computer/shiitake/fleet";
|
|
60
62
|
import { appToolPolicySchema, } from "../apps/index.js";
|
|
61
63
|
import { oysterPrincipalId } from "../host.js";
|
|
@@ -1688,6 +1690,21 @@ export class AgentDirectory extends DurableObject {
|
|
|
1688
1690
|
const id = agentIds.agent.parse(agentId);
|
|
1689
1691
|
return id.ok && this.directory.read(this.grant(), id.value) !== null;
|
|
1690
1692
|
}
|
|
1693
|
+
starterLedgerOwner;
|
|
1694
|
+
get starterLedger() {
|
|
1695
|
+
return (this.starterLedgerOwner ??= createStarterLedger(this.ctx.storage.sql));
|
|
1696
|
+
}
|
|
1697
|
+
/** The starter Agent's one-row ledger and the Agent total it reads, for the owner's ensure. */
|
|
1698
|
+
readStarter() {
|
|
1699
|
+
return this.starterLedger.read();
|
|
1700
|
+
}
|
|
1701
|
+
recordStarter(row) {
|
|
1702
|
+
this.starterLedger.record(row);
|
|
1703
|
+
}
|
|
1704
|
+
/** Every Agent in the directory, archived ones included. */
|
|
1705
|
+
agentTotal() {
|
|
1706
|
+
return this.directory.list(this.grant()).length;
|
|
1707
|
+
}
|
|
1691
1708
|
/** Resolve the existing recorded creator for host-side owner admission. */
|
|
1692
1709
|
readCreator(agentId) {
|
|
1693
1710
|
return this.directory.readCreator(this.grant(), agentId);
|
|
@@ -1969,6 +1986,20 @@ export function standaloneAgents(env, scope) {
|
|
|
1969
1986
|
avatar: entry.avatar,
|
|
1970
1987
|
sessionOperations: everyOperation,
|
|
1971
1988
|
});
|
|
1989
|
+
const created = async (name, requestId, principal, actor, avatar) => {
|
|
1990
|
+
const entry = await directory().create(name, requestId, principal, actor, avatar);
|
|
1991
|
+
await env.AGENTS.getByName(entry.agentId).usePolicyDirectory({
|
|
1992
|
+
directoryName,
|
|
1993
|
+
tenantId: scope?.tenantId ?? defaultTenant,
|
|
1994
|
+
});
|
|
1995
|
+
if (actor === "owner-direct" && entry.policyRevision !== null) {
|
|
1996
|
+
// Best-effort: a stale membership lookup leaves the Agent pending
|
|
1997
|
+
// rather than failing its creation. Grove's "Allow App tools"
|
|
1998
|
+
// control recovers it through the same approval path.
|
|
1999
|
+
await directory().approveAppToolPolicy(entry.agentId, principal, "write", entry.policyRevision, actor, scope?.tenantId ?? defaultTenant);
|
|
2000
|
+
}
|
|
2001
|
+
return toAgent(entry);
|
|
2002
|
+
};
|
|
1972
2003
|
return {
|
|
1973
2004
|
list: async (options) => (await directory().list(options)).map(toAgent),
|
|
1974
2005
|
setArchived: async (agentId, archived, principal) => {
|
|
@@ -1983,19 +2014,28 @@ export function standaloneAgents(env, scope) {
|
|
|
1983
2014
|
return { error: "not_found" };
|
|
1984
2015
|
return agent.setArchived(archived);
|
|
1985
2016
|
},
|
|
1986
|
-
create:
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2017
|
+
create: created,
|
|
2018
|
+
ensureStarter: (principal) => {
|
|
2019
|
+
const owner = directory();
|
|
2020
|
+
return ensureStarterAgent({
|
|
2021
|
+
ledger: {
|
|
2022
|
+
read: () => owner.readStarter(),
|
|
2023
|
+
record: (row) => owner.recordStarter(row),
|
|
2024
|
+
},
|
|
2025
|
+
isOwner: () => oysterPrincipalIsOwner(principal),
|
|
2026
|
+
agentCount: () => owner.agentTotal(),
|
|
2027
|
+
// The ordinary create: the same Computer-less Agent, policy and approval any owner create gets.
|
|
2028
|
+
create: async (request) => {
|
|
2029
|
+
const agent = await created(request.name, request.requestId, principal, "owner-direct");
|
|
2030
|
+
return { status: "created", agentId: agent.agentId };
|
|
2031
|
+
},
|
|
2032
|
+
report: (cause) => {
|
|
2033
|
+
console.warn(JSON.stringify({
|
|
2034
|
+
event: "starter_agent_failed",
|
|
2035
|
+
cause: String(cause),
|
|
2036
|
+
}));
|
|
2037
|
+
},
|
|
1991
2038
|
});
|
|
1992
|
-
if (actor === "owner-direct" && entry.policyRevision !== null) {
|
|
1993
|
-
// Best-effort: a stale membership lookup leaves the Agent pending
|
|
1994
|
-
// rather than failing its creation. Grove's "Allow App tools"
|
|
1995
|
-
// control recovers it through the same approval path.
|
|
1996
|
-
await directory().approveAppToolPolicy(entry.agentId, principal, "write", entry.policyRevision, actor, scope?.tenantId ?? defaultTenant);
|
|
1997
|
-
}
|
|
1998
|
-
return toAgent(entry);
|
|
1999
2039
|
},
|
|
2000
2040
|
rename: async (agentId, name, principal) => {
|
|
2001
2041
|
const result = await directory().rename(agentId, name, principal);
|
|
@@ -2023,6 +2063,15 @@ export function standaloneAgents(env, scope) {
|
|
|
2023
2063
|
return { error: "not_found" };
|
|
2024
2064
|
return env.AGENTS.getByName(agentId).setModelChoice(choice);
|
|
2025
2065
|
},
|
|
2066
|
+
setup: async () => {
|
|
2067
|
+
const account = cloudflareAccountReady(env);
|
|
2068
|
+
const gateway = configuredProviderEgress(env).baseUrl("ai-gateway") !== null;
|
|
2069
|
+
const stored = (await directory().listModelKeys()).length > 0;
|
|
2070
|
+
return {
|
|
2071
|
+
models: account || gateway || stored ? "ready" : "missing",
|
|
2072
|
+
media: account ? "ready" : "missing",
|
|
2073
|
+
};
|
|
2074
|
+
},
|
|
2026
2075
|
modelKeys: () => directory().listModelKeys(),
|
|
2027
2076
|
sealModelKey: (input) => directory().sealModelKey(input),
|
|
2028
2077
|
removeModelKey: (keyId) => directory().removeModelKey(keyId),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this Worker can reach Workers AI. The AI binding is declared in
|
|
3
|
+
* every Oyster's wrangler config, but a local trial (`oyster try`, served from
|
|
4
|
+
* a loopback origin) has no Cloudflare account behind it: calls through it
|
|
5
|
+
* fail. A deployed Oyster, served from its own origin, does.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cloudflareAccountReady(env: Readonly<{
|
|
8
|
+
AI?: unknown;
|
|
9
|
+
OYSTER_ORIGIN?: string | undefined;
|
|
10
|
+
}>): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this Worker can reach Workers AI. The AI binding is declared in
|
|
3
|
+
* every Oyster's wrangler config, but a local trial (`oyster try`, served from
|
|
4
|
+
* a loopback origin) has no Cloudflare account behind it: calls through it
|
|
5
|
+
* fail. A deployed Oyster, served from its own origin, does.
|
|
6
|
+
*/
|
|
7
|
+
export function cloudflareAccountReady(env) {
|
|
8
|
+
if (env.AI === undefined)
|
|
9
|
+
return false;
|
|
10
|
+
// A host that names no origin has no loopback trial to tell apart.
|
|
11
|
+
if (env.OYSTER_ORIGIN === undefined)
|
|
12
|
+
return true;
|
|
13
|
+
if (!URL.canParse(env.OYSTER_ORIGIN))
|
|
14
|
+
return false;
|
|
15
|
+
const { hostname } = new URL(env.OYSTER_ORIGIN);
|
|
16
|
+
return !["localhost", "127.0.0.1", "[::1]"].includes(hostname);
|
|
17
|
+
}
|
|
@@ -6,7 +6,7 @@ import * as z from "zod";
|
|
|
6
6
|
import { computerProcessSchema, computerToolResultSchema, readOutputSchema } from "@fungi.computer/computer-contract";
|
|
7
7
|
import { ComputerDO as NativeComputerDO, type AttachedBackend, type ComputerEnv, type ComputerFilesRpc } from "@fungi.computer/computer";
|
|
8
8
|
import { patchInputSchema, patchOutputSchema } from "@fungi.computer/knapsack/files-patch";
|
|
9
|
-
import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
|
|
9
|
+
import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
|
|
10
10
|
import { type WorkflowGitCredential, type WorkflowGitPassGrant } from "@fungi.computer/braid/runtime";
|
|
11
11
|
import { type ComputerAction, type ComputerBackendView, type ComputerGrant, type LocalBackendAttachInput, type LocalBackendDetachInput } from "@fungi.computer/computer/fleet";
|
|
12
12
|
import type { InvocationFrame } from "../invocation.js";
|
|
@@ -38,7 +38,7 @@ export type StandaloneComputerResult = z.output<typeof listOutputSchema> | Reado
|
|
|
38
38
|
truncated: boolean;
|
|
39
39
|
}> | Readonly<{
|
|
40
40
|
error: "conflict";
|
|
41
|
-
}> | z.output<typeof writeOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
|
|
41
|
+
}> | z.output<typeof writeOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof processLogsOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
|
|
42
42
|
/**
|
|
43
43
|
* A port-preview listing, or the typed refusal the owner route presents with
|
|
44
44
|
* {@link appMethodRefusalStatus}. A refusal never escapes as a 500.
|
|
@@ -12,7 +12,7 @@ import * as z from "zod";
|
|
|
12
12
|
import { ComputerPortConflictError, computerByteReadReplySchema, computerProcessSchema, installationProcessScope, processStartInputSchema, processStartToolInputSchema, computerCapabilities, computerToolResultSchema, readOutputSchema, } from "@fungi.computer/computer-contract";
|
|
13
13
|
import { ComputerDO as NativeComputerDO, ComputerOperationConflictError, } from "@fungi.computer/computer";
|
|
14
14
|
import { patchInputSchema, patchOutputSchema, } from "@fungi.computer/knapsack/files-patch";
|
|
15
|
-
import { ComputerFileConflict, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
|
|
15
|
+
import { ComputerFileConflict, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsInputSchema, processLogsOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
|
|
16
16
|
import { workflowGitExecutionEnvironment, workflowGitPassGrantSchema, } from "@fungi.computer/braid/runtime";
|
|
17
17
|
import { checkComputerGrant, computerActionSchema, computerGrantSchema, ComputerBackingError, createFleetBacking, FleetGrantRefused, FleetLifecycle, } from "@fungi.computer/computer/fleet";
|
|
18
18
|
import { AppInstanceError, selectionOf } from "../index.js";
|
|
@@ -461,6 +461,8 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
461
461
|
return { error: "conflict" };
|
|
462
462
|
throw cause;
|
|
463
463
|
}
|
|
464
|
+
case "processLogs":
|
|
465
|
+
return this.processLogsAfterAcceptance(processLogsInputSchema.parse(input), accept);
|
|
464
466
|
case "processKill":
|
|
465
467
|
return this.killProcessAfterAcceptance(processIdInputSchema.parse(input), accept);
|
|
466
468
|
case "exec":
|
|
@@ -673,6 +675,19 @@ export function standaloneComputerCapabilities(env, workspace) {
|
|
|
673
675
|
return context.json({ error: "invalid_input" }, 400);
|
|
674
676
|
return Response.json(await computer().value(authority(principal), "processKill", input.data));
|
|
675
677
|
});
|
|
678
|
+
routes.get("/processes/logs", reach, async (context, { principal }) => {
|
|
679
|
+
const query = {
|
|
680
|
+
id: context.req.query("id"),
|
|
681
|
+
lines: context.req.query("lines"),
|
|
682
|
+
};
|
|
683
|
+
const input = processLogsInputSchema.safeParse({
|
|
684
|
+
id: query.id,
|
|
685
|
+
lines: query.lines === undefined ? undefined : Number(query.lines),
|
|
686
|
+
});
|
|
687
|
+
if (!input.success)
|
|
688
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
689
|
+
return Response.json(await computer().value(authority(principal), "processLogs", input.data));
|
|
690
|
+
});
|
|
676
691
|
routes.get("/terminal", reach, async (context, { principal }) => {
|
|
677
692
|
const terminal = authority(principal);
|
|
678
693
|
const url = new URL(context.req.url);
|
|
@@ -10,6 +10,8 @@ import type { FileSource } from "../files.js";
|
|
|
10
10
|
export type OysterMediaEnv = Readonly<{
|
|
11
11
|
/** Workers AI provider, admitted by this Worker. */
|
|
12
12
|
AI: MediaAiPort;
|
|
13
|
+
/** This Worker's own origin; a loopback origin has no Cloudflare account. */
|
|
14
|
+
OYSTER_ORIGIN?: string | undefined;
|
|
13
15
|
/** Darkroom's durable operation namespace. */
|
|
14
16
|
MEDIA_OPERATION: MediaServiceHost["operations"];
|
|
15
17
|
/** Native image decoding and bounded reference fitting. */
|
package/dist/standalone/media.js
CHANGED
|
@@ -12,6 +12,7 @@ import { createMediaService, estimateMediaModel, mediaPendingSchema, mediaResult
|
|
|
12
12
|
import { createWorkersAiMediaProvider, createImagesReferenceFitter, } from "@fungi.computer/darkroom/cloudflare";
|
|
13
13
|
import { oysterPrincipalId, } from "../host.js";
|
|
14
14
|
import { normalizeFilePath } from "../files.js";
|
|
15
|
+
import { cloudflareAccountReady } from "./cloudflare-account.js";
|
|
15
16
|
/** Media capability using Darkroom execution and the existing workspace FileSource. */
|
|
16
17
|
export function workersMedia(env, workspace) {
|
|
17
18
|
const { computerId } = workspace;
|
|
@@ -22,7 +23,7 @@ export function workersMedia(env, workspace) {
|
|
|
22
23
|
const response = await service(principal).request("http://media/models");
|
|
23
24
|
return context.json(Schema.decodeUnknownSync(mediaGenerationDescriptionSchema)({
|
|
24
25
|
computerId,
|
|
25
|
-
canGenerate:
|
|
26
|
+
canGenerate: cloudflareAccountReady(env),
|
|
26
27
|
models: await response.json(),
|
|
27
28
|
}));
|
|
28
29
|
});
|
|
@@ -40,6 +41,8 @@ export function workersMedia(env, workspace) {
|
|
|
40
41
|
}));
|
|
41
42
|
if (references?.some((reference) => reference.path === null || reference.path === "/"))
|
|
42
43
|
return context.json(invalidRequest());
|
|
44
|
+
if (!cloudflareAccountReady(env))
|
|
45
|
+
return context.json(setupRequired());
|
|
43
46
|
const response = await service(principal).request("http://media/generate", {
|
|
44
47
|
method: "POST",
|
|
45
48
|
signal: context.req.raw.signal,
|
|
@@ -104,6 +107,19 @@ export function workersMedia(env, workspace) {
|
|
|
104
107
|
},
|
|
105
108
|
];
|
|
106
109
|
}
|
|
110
|
+
/** A missing provider or account is setup, not a failed generation. */
|
|
111
|
+
function setupRequired() {
|
|
112
|
+
return {
|
|
113
|
+
kind: "failed",
|
|
114
|
+
failure: {
|
|
115
|
+
message: "Media generation needs an image provider",
|
|
116
|
+
stage: "admission",
|
|
117
|
+
code: "SETUP_REQUIRED",
|
|
118
|
+
need: "an image provider",
|
|
119
|
+
retryable: false,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
107
123
|
function invalidRequest() {
|
|
108
124
|
return {
|
|
109
125
|
kind: "failed",
|
|
@@ -3,6 +3,7 @@ import { agentDirectoryForScope } from "./agent-directory.js";
|
|
|
3
3
|
import { standaloneAgentComputerRoutes } from "./agent-computers.js";
|
|
4
4
|
import { appSourceOwnerRoutes, } from "./app-source.js";
|
|
5
5
|
import { standaloneBuildRoutes } from "./builds.js";
|
|
6
|
+
import { trialStarterRoutes } from "./trial-starters.js";
|
|
6
7
|
import { standaloneComputerFleetRoutes } from "./computer-fleet.js";
|
|
7
8
|
import { standaloneWorkflowWebhookControls } from "./workflow-webhooks.js";
|
|
8
9
|
import { standaloneWebsiteControl, standaloneWebsiteRoutes, } from "./website-channels.js";
|
|
@@ -13,6 +14,7 @@ export function standaloneOwnerRoutes(env, scope, hostFor) {
|
|
|
13
14
|
const directory = () => agentDirectoryForScope(env, scope);
|
|
14
15
|
const owned = appSourceOwnerRoutes(env, scope)
|
|
15
16
|
.include(standaloneBuildRoutes(registry))
|
|
17
|
+
.include(trialStarterRoutes(registry))
|
|
16
18
|
.include(standaloneComputerFleetRoutes(registry))
|
|
17
19
|
.include(standaloneAgentComputerRoutes({
|
|
18
20
|
attach: (principal, command) => directory().attachComputer(command, principal, scope.tenantId),
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Release } from "@fungi.computer/puffball";
|
|
2
2
|
import { OysterRegistry, type OysterWorkerEnv } from "../workers.js";
|
|
3
3
|
import { type OysterHost } from "../host.js";
|
|
4
|
+
import type { OysterRootDirectory } from "../root-data.js";
|
|
5
|
+
import type { InstallingApp } from "@fungi.computer/nacre/workbench-directory";
|
|
4
6
|
import { type TenantScope, type TenantId } from "../tenant.js";
|
|
5
7
|
import { type OysterGitEnv } from "../workers-git.js";
|
|
6
8
|
import { type AppSourceForkResult, type TemplateSeedClaim } from "../source/index.js";
|
|
@@ -45,6 +47,20 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
|
|
|
45
47
|
#private;
|
|
46
48
|
protected abstract hostFor(scope: TenantScope): Promise<OysterHost>;
|
|
47
49
|
constructor(state: DurableObjectState, env: StandaloneRegistryEnv, git?: StandaloneRegistryGit);
|
|
50
|
+
/** Starter Apps a trial is still setting up, cleared once each is installed. */
|
|
51
|
+
directory(): Promise<OysterRootDirectory>;
|
|
52
|
+
reportTrialStarters(installing: readonly InstallingApp[]): Promise<void>;
|
|
53
|
+
trialStartersList(): Promise<readonly {
|
|
54
|
+
installationId: string;
|
|
55
|
+
displayName: string;
|
|
56
|
+
state: "failed" | "installing" | "needs-runtime";
|
|
57
|
+
reason?: {
|
|
58
|
+
code: "unknown" | "build_failed" | "network" | "unsupported";
|
|
59
|
+
message: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
}[]>;
|
|
62
|
+
requestTrialRetry(installationId: string): Promise<boolean>;
|
|
63
|
+
takeTrialRetries(): Promise<readonly string[]>;
|
|
48
64
|
/** Whether installations or build jobs were written by Oyster 0.2 or earlier. */
|
|
49
65
|
storeFromOlderOyster(): boolean;
|
|
50
66
|
/** Re-admit the live owner before inventory access or a hosted start. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { canonicalJson } from "@fungi.computer/braid";
|
|
2
2
|
import { OysterRegistry, r2ArtifactStore, } from "../workers.js";
|
|
3
3
|
import { installOrSelect } from "../host.js";
|
|
4
|
+
import { createTrialStarters, pendingStarters } from "./trial-starters.js";
|
|
4
5
|
import { installationOperationsPort } from "../installation-operations.js";
|
|
5
6
|
import { tenantScope } from "../tenant.js";
|
|
6
7
|
import { artifactsOf } from "../workers-git.js";
|
|
@@ -33,11 +34,22 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
33
34
|
#builds;
|
|
34
35
|
#computers;
|
|
35
36
|
#fleetStorage;
|
|
37
|
+
#trial;
|
|
36
38
|
constructor(state, env, git = {}) {
|
|
37
39
|
super(state, env);
|
|
38
40
|
this.#env = env;
|
|
39
41
|
this.#git = git;
|
|
40
42
|
this.#fleetStorage = state.storage;
|
|
43
|
+
this.#trial = createTrialStarters({
|
|
44
|
+
starters: {
|
|
45
|
+
read: () => state.storage.get("trial.starters"),
|
|
46
|
+
write: (value) => state.storage.put("trial.starters", value),
|
|
47
|
+
},
|
|
48
|
+
retries: {
|
|
49
|
+
read: () => state.storage.get("trial.retries"),
|
|
50
|
+
write: (value) => state.storage.put("trial.retries", value),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
41
53
|
// Native hosts own infrastructure capacity. Standalone has no Team quota.
|
|
42
54
|
this.#computers = createFleetComputers(state.storage, {
|
|
43
55
|
limit: Number.MAX_SAFE_INTEGER,
|
|
@@ -45,6 +57,24 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
45
57
|
});
|
|
46
58
|
this.#computers.ensure();
|
|
47
59
|
}
|
|
60
|
+
/** Starter Apps a trial is still setting up, cleared once each is installed. */
|
|
61
|
+
async directory() {
|
|
62
|
+
const base = await super.directory();
|
|
63
|
+
const installing = pendingStarters(await this.#trial.list(), base.apps.flatMap((app) => app.installationId === null ? [] : [app.installationId]));
|
|
64
|
+
return installing.length === 0 ? base : { ...base, installing };
|
|
65
|
+
}
|
|
66
|
+
async reportTrialStarters(installing) {
|
|
67
|
+
await this.#trial.report(installing);
|
|
68
|
+
}
|
|
69
|
+
trialStartersList() {
|
|
70
|
+
return this.#trial.list();
|
|
71
|
+
}
|
|
72
|
+
requestTrialRetry(installationId) {
|
|
73
|
+
return this.#trial.requestRetry(installationId);
|
|
74
|
+
}
|
|
75
|
+
takeTrialRetries() {
|
|
76
|
+
return this.#trial.takeRetries();
|
|
77
|
+
}
|
|
48
78
|
/** Whether installations or build jobs were written by Oyster 0.2 or earlier. */
|
|
49
79
|
storeFromOlderOyster() {
|
|
50
80
|
return (super.storeFromOlderOyster() ||
|
|
@@ -2,7 +2,7 @@ export type SignInLink = Readonly<{
|
|
|
2
2
|
url: string;
|
|
3
3
|
close: () => Promise<void>;
|
|
4
4
|
}>;
|
|
5
|
-
/** Serve one single-use page that signs the owner in to `oysterUrl
|
|
5
|
+
/** Serve one single-use page that signs the owner in to `oysterUrl`, until closed. */
|
|
6
6
|
export declare function startSignInLink(input: Readonly<{
|
|
7
7
|
oysterUrl: string;
|
|
8
8
|
key: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// A one-time sign-in link for `oyster try`. The owner key never goes in a URL:
|
|
2
2
|
// the link opens a page served by this process that posts the key to the local
|
|
3
|
-
// Oyster's own /login form, then the server forgets the
|
|
3
|
+
// Oyster's own /login form, then the server forgets the key. The listener stays
|
|
4
|
+
// up for the whole try session, so a reused link lands on /login with a note.
|
|
4
5
|
import { awaitCleanup } from "../build/process-group.js";
|
|
5
6
|
import { createHash, randomBytes } from "node:crypto";
|
|
6
7
|
import { addAbortListener } from "node:events";
|
|
@@ -9,8 +10,7 @@ import * as z from "zod";
|
|
|
9
10
|
import { hostPage } from "../host-page.js";
|
|
10
11
|
import { loadPageAssets } from "../page-assets.js";
|
|
11
12
|
const addressSchema = z.object({ port: z.number() });
|
|
12
|
-
|
|
13
|
-
/** Serve one single-use page that signs the owner in to `oysterUrl`. */
|
|
13
|
+
/** Serve one single-use page that signs the owner in to `oysterUrl`, until closed. */
|
|
14
14
|
export async function startSignInLink(input) {
|
|
15
15
|
const signal = input.signal ?? new AbortController().signal;
|
|
16
16
|
signal.throwIfAborted();
|
|
@@ -32,10 +32,8 @@ export async function startSignInLink(input) {
|
|
|
32
32
|
key: input.key,
|
|
33
33
|
},
|
|
34
34
|
})).text();
|
|
35
|
-
const expired = await (await hostPage({ ...pageOptions, state: "link-expired", status: 404 })).text();
|
|
36
35
|
const notFound = await (await hostPage({ ...pageOptions, state: "not-found", status: 404 })).text();
|
|
37
36
|
signal.throwIfAborted();
|
|
38
|
-
const timers = new Set();
|
|
39
37
|
const server = createServer((request, response) => {
|
|
40
38
|
const headers = {
|
|
41
39
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -49,21 +47,22 @@ export async function startSignInLink(input) {
|
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
51
49
|
if (used) {
|
|
52
|
-
response
|
|
50
|
+
response
|
|
51
|
+
.writeHead(302, {
|
|
52
|
+
...headers,
|
|
53
|
+
Location: new URL("/login?link=used", input.oysterUrl).href,
|
|
54
|
+
})
|
|
55
|
+
.end();
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
55
58
|
used = true;
|
|
56
59
|
response.writeHead(200, headers).end(page);
|
|
57
60
|
page = "";
|
|
58
|
-
scheduleClose(1_000);
|
|
59
61
|
});
|
|
60
62
|
let closing;
|
|
61
63
|
let abortListener;
|
|
62
64
|
const beginClose = () => (closing ??= Promise.allSettled([
|
|
63
65
|
(async () => {
|
|
64
|
-
for (const timer of timers)
|
|
65
|
-
clearTimeout(timer);
|
|
66
|
-
timers.clear();
|
|
67
66
|
page = "";
|
|
68
67
|
abortListener?.[Symbol.dispose]();
|
|
69
68
|
await new Promise((resolve, reject) => {
|
|
@@ -79,13 +78,6 @@ export async function startSignInLink(input) {
|
|
|
79
78
|
})(),
|
|
80
79
|
]));
|
|
81
80
|
const close = () => awaitCleanup(beginClose());
|
|
82
|
-
function scheduleClose(ms) {
|
|
83
|
-
const timer = setTimeout(() => {
|
|
84
|
-
void beginClose();
|
|
85
|
-
}, ms);
|
|
86
|
-
timer.unref();
|
|
87
|
-
timers.add(timer);
|
|
88
|
-
}
|
|
89
81
|
try {
|
|
90
82
|
await new Promise((done, fail) => {
|
|
91
83
|
server.once("error", fail);
|
|
@@ -100,7 +92,6 @@ export async function startSignInLink(input) {
|
|
|
100
92
|
abortListener = addAbortListener(signal, () => {
|
|
101
93
|
void beginClose();
|
|
102
94
|
});
|
|
103
|
-
scheduleClose(lifetimeMs);
|
|
104
95
|
const { port } = addressSchema.parse(server.address());
|
|
105
96
|
return { url: `http://127.0.0.1:${String(port)}/${nonce}`, close };
|
|
106
97
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { type InstallingApp } from "@fungi.computer/nacre/workbench-directory";
|
|
3
|
+
import { type Routes } from "../authorization.js";
|
|
4
|
+
import type { OysterEnv } from "../host.js";
|
|
5
|
+
import type { StandaloneRegistry } from "./registry.js";
|
|
6
|
+
/** What `oyster try` tells its Oyster about the starter Apps still being set up. */
|
|
7
|
+
export declare const trialStartersBodySchema: z.ZodObject<{
|
|
8
|
+
installing: z.ZodArray<z.ZodObject<{
|
|
9
|
+
installationId: z.ZodString;
|
|
10
|
+
displayName: z.ZodString;
|
|
11
|
+
state: z.ZodEnum<{
|
|
12
|
+
readonly installing: "installing";
|
|
13
|
+
readonly failed: "failed";
|
|
14
|
+
readonly "needs-runtime": "needs-runtime";
|
|
15
|
+
}>;
|
|
16
|
+
reason: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
code: z.ZodEnum<{
|
|
18
|
+
readonly build_failed: "build_failed";
|
|
19
|
+
readonly network: "network";
|
|
20
|
+
readonly unsupported: "unsupported";
|
|
21
|
+
readonly unknown: "unknown";
|
|
22
|
+
}>;
|
|
23
|
+
message: z.ZodString;
|
|
24
|
+
}, z.core.$strict>>;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
}, z.core.$strict>;
|
|
27
|
+
/** One typed record the registry keeps durably. */
|
|
28
|
+
export type TrialPort<T> = Readonly<{
|
|
29
|
+
read(): Promise<T | undefined>;
|
|
30
|
+
write(value: T): Promise<void>;
|
|
31
|
+
}>;
|
|
32
|
+
/** Where the trial's list and retry asks live. */
|
|
33
|
+
export type TrialStarterStorage = Readonly<{
|
|
34
|
+
starters: TrialPort<readonly InstallingApp[]>;
|
|
35
|
+
retries: TrialPort<readonly string[]>;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* The trial's starter-App state. `oyster try` replaces the list as each App
|
|
39
|
+
* settles; the desktop asks for a retry of one App and `try` takes the asks.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTrialStarters(storage: TrialStarterStorage): {
|
|
42
|
+
list(): Promise<readonly InstallingApp[]>;
|
|
43
|
+
report(installing: readonly InstallingApp[]): Promise<readonly InstallingApp[]>;
|
|
44
|
+
/** Only a failed App can be retried; the ask is remembered until taken. */
|
|
45
|
+
requestRetry(installationId: string): Promise<boolean>;
|
|
46
|
+
takeRetries(): Promise<readonly string[]>;
|
|
47
|
+
};
|
|
48
|
+
/** Starters still listed once their App is installed no longer show as pending. */
|
|
49
|
+
export declare function pendingStarters(listed: readonly InstallingApp[], installedIds: readonly string[]): readonly InstallingApp[];
|
|
50
|
+
export type RegistryBinding = () => Pick<StandaloneRegistry, "reportTrialStarters" | "requestTrialRetry" | "takeTrialRetries" | "trialStartersList">;
|
|
51
|
+
/** Owner-key routes `oyster try` and the desktop use; the owner guard is declared per route. */
|
|
52
|
+
export declare function trialStarterRoutes(registry: RegistryBinding): Routes<OysterEnv>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { installingAppSchema, } from "@fungi.computer/nacre/workbench-directory";
|
|
3
|
+
import { owner, routes as routeTable } from "../authorization.js";
|
|
4
|
+
/** What `oyster try` tells its Oyster about the starter Apps still being set up. */
|
|
5
|
+
export const trialStartersBodySchema = z.strictObject({
|
|
6
|
+
installing: z.array(installingAppSchema).max(16),
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* The trial's starter-App state. `oyster try` replaces the list as each App
|
|
10
|
+
* settles; the desktop asks for a retry of one App and `try` takes the asks.
|
|
11
|
+
*/
|
|
12
|
+
export function createTrialStarters(storage) {
|
|
13
|
+
return {
|
|
14
|
+
async list() {
|
|
15
|
+
return (await storage.starters.read()) ?? [];
|
|
16
|
+
},
|
|
17
|
+
async report(installing) {
|
|
18
|
+
const parsed = trialStartersBodySchema.parse({ installing }).installing;
|
|
19
|
+
await storage.starters.write(parsed);
|
|
20
|
+
return parsed;
|
|
21
|
+
},
|
|
22
|
+
/** Only a failed App can be retried; the ask is remembered until taken. */
|
|
23
|
+
async requestRetry(installationId) {
|
|
24
|
+
const current = await this.list();
|
|
25
|
+
if (!current.some((entry) => entry.installationId === installationId && entry.state === "failed"))
|
|
26
|
+
return false;
|
|
27
|
+
const asks = (await storage.retries.read()) ?? [];
|
|
28
|
+
if (!asks.includes(installationId))
|
|
29
|
+
await storage.retries.write([...asks, installationId]);
|
|
30
|
+
return true;
|
|
31
|
+
},
|
|
32
|
+
async takeRetries() {
|
|
33
|
+
const asks = (await storage.retries.read()) ?? [];
|
|
34
|
+
if (asks.length > 0)
|
|
35
|
+
await storage.retries.write([]);
|
|
36
|
+
return asks;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Starters still listed once their App is installed no longer show as pending. */
|
|
41
|
+
export function pendingStarters(listed, installedIds) {
|
|
42
|
+
return listed.filter((entry) => !installedIds.includes(entry.installationId));
|
|
43
|
+
}
|
|
44
|
+
/** Owner-key routes `oyster try` and the desktop use; the owner guard is declared per route. */
|
|
45
|
+
export function trialStarterRoutes(registry) {
|
|
46
|
+
const routes = routeTable();
|
|
47
|
+
routes.put("/api/trial/starters", owner("direct"), async (context) => {
|
|
48
|
+
let body;
|
|
49
|
+
try {
|
|
50
|
+
body = await context.req.json();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return context.json({ kind: "invalid" }, 400);
|
|
54
|
+
}
|
|
55
|
+
const parsed = trialStartersBodySchema.safeParse(body);
|
|
56
|
+
if (!parsed.success)
|
|
57
|
+
return context.json({ kind: "invalid" }, 400);
|
|
58
|
+
await registry().reportTrialStarters(parsed.data.installing);
|
|
59
|
+
return new Response(null, { status: 204 });
|
|
60
|
+
});
|
|
61
|
+
routes.get("/api/trial/starters", owner("direct"), async () => Response.json({ installing: await registry().trialStartersList() }, { headers: { "Cache-Control": "no-store" } }));
|
|
62
|
+
routes.post("/api/trial/starters/:installationId/retry", owner("direct"), async (context) => (await registry().requestTrialRetry(context.req.param("installationId")))
|
|
63
|
+
? new Response(null, { status: 202 })
|
|
64
|
+
: context.json({ kind: "not_retryable" }, 409));
|
|
65
|
+
routes.post("/api/trial/starters/retries", owner("direct"), async () => Response.json({ retries: await registry().takeTrialRetries() }, { headers: { "Cache-Control": "no-store" } }));
|
|
66
|
+
return routes;
|
|
67
|
+
}
|