@fungi.computer/oyster 0.8.2 → 0.10.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 +34 -17
- package/dist/agents.d.ts +16 -1
- package/dist/agents.js +63 -3
- package/dist/apps/catalog.d.ts +11 -0
- package/dist/apps/catalog.js +1 -0
- package/dist/apps/gate.d.ts +2 -2
- package/dist/apps/installation.d.ts +7 -7
- package/dist/apps/permissions.d.ts +5 -5
- package/dist/boot-host-script.js +1 -1
- package/dist/build/candidate-cli.mjs +1 -0
- package/dist/computer-control-port.d.ts +20 -1
- package/dist/host.js +11 -4
- package/dist/installation-client.d.ts +6 -5
- package/dist/installation-client.js +21 -17
- package/dist/installation-execution.js +41 -8
- package/dist/installation-operations.d.ts +30 -8
- package/dist/installation-operations.js +122 -24
- package/dist/instance-refusal.d.ts +4 -2
- package/dist/instance-refusal.js +5 -1
- package/dist/mcp.d.ts +132 -2
- package/dist/mcp.js +63 -1
- package/dist/page/mount.d.ts +8 -1
- package/dist/page/mount.js +72 -6
- package/dist/page-script.js +3 -3
- package/dist/standalone/agent-computers.d.ts +12 -1
- package/dist/standalone/agent-computers.js +35 -0
- package/dist/standalone/agent-connections.d.ts +47 -0
- package/dist/standalone/agent-connections.js +170 -0
- package/dist/standalone/agent-model-choice.d.ts +7 -3
- package/dist/standalone/agent-model-choice.js +33 -4
- package/dist/standalone/agents.d.ts +70 -9
- package/dist/standalone/agents.js +187 -110
- package/dist/standalone/app-set.js +6 -7
- package/dist/standalone/browser.d.ts +4 -3
- package/dist/standalone/browser.js +4 -3
- package/dist/standalone/computer-control.js +55 -1
- package/dist/standalone/computer-fleet.d.ts +29 -2
- package/dist/standalone/computer-fleet.js +51 -23
- package/dist/standalone/computer.d.ts +20 -1
- package/dist/standalone/computer.js +63 -1
- package/dist/standalone/model-key-vault.d.ts +50 -0
- package/dist/standalone/model-key-vault.js +147 -0
- package/dist/standalone/registry.d.ts +23 -0
- package/dist/standalone/registry.js +39 -0
- package/dist/standalone/web.d.ts +10 -0
- package/dist/standalone/web.js +34 -0
- package/dist/standalone/worker-routes.d.ts +3 -1
- package/dist/standalone/worker-routes.js +1 -0
- package/dist/standalone/worker.js +9 -1
- package/dist/standalone/workflow-host.d.ts +5 -5
- package/dist/standalone/workflow-trigger-host.d.ts +1 -1
- package/dist/web/index.d.ts +3 -0
- package/dist/web/index.js +3 -0
- package/dist/web/search-contract.d.ts +19 -0
- package/dist/web/search-contract.js +14 -0
- package/dist/web/search.d.ts +25 -0
- package/dist/web/search.js +123 -0
- package/dist/web/source.d.ts +46 -0
- package/dist/web/source.js +335 -0
- package/dist/workers-git.js +2 -1
- package/docs/api/agents.md +81 -3
- package/docs/api/apps.md +160 -142
- package/docs/api/build-contract.md +27 -21
- package/docs/api/build.md +55 -54
- package/docs/api/git.md +3 -3
- package/docs/api/host.md +226 -60
- package/docs/api/mcp.md +83 -44
- package/docs/api/page/mount.md +6 -1
- package/docs/api/workers-git.md +6 -6
- package/docs/api/workers.md +53 -47
- package/docs/site/agent-quickstart.mdx +4 -2
- package/package.json +27 -22
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { endTime, startTime } from "hono/timing";
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { computerCreateRequestSchema, computerPageSchema, } from "@fungi.computer/computer/fleet";
|
|
4
|
+
import { computerCreateRequestSchema, computerPageSchema, localBackendAttachSchema, localBackendDetachRequestSchema, localBackendDetachSchema, } from "@fungi.computer/computer/fleet";
|
|
5
5
|
import {} from "../host.js";
|
|
6
6
|
import { oysterPrincipalIsOwner, owner as ownerRoute, routes as routeTable, } from "../authorization.js";
|
|
7
7
|
import { computerTargetParam } from "../computer-target.js";
|
|
@@ -21,11 +21,26 @@ export const standaloneFleetRequestSchema = z.discriminatedUnion("operation", [
|
|
|
21
21
|
computerId: fleetComputerId,
|
|
22
22
|
}),
|
|
23
23
|
z.strictObject({
|
|
24
|
-
operation: z.literal("
|
|
24
|
+
operation: z.literal("backends"),
|
|
25
25
|
computerId: fleetComputerId,
|
|
26
26
|
}),
|
|
27
27
|
z.strictObject({
|
|
28
|
-
operation: z.literal("
|
|
28
|
+
operation: z.literal("attach-local"),
|
|
29
|
+
request: localBackendAttachSchema,
|
|
30
|
+
}),
|
|
31
|
+
z.strictObject({
|
|
32
|
+
operation: z.literal("detach-local"),
|
|
33
|
+
request: z.union([
|
|
34
|
+
localBackendDetachSchema,
|
|
35
|
+
localBackendDetachRequestSchema,
|
|
36
|
+
]),
|
|
37
|
+
}),
|
|
38
|
+
z.strictObject({
|
|
39
|
+
operation: z.enum(["read-internet-access", "read-keep-awake"]),
|
|
40
|
+
computerId: fleetComputerId,
|
|
41
|
+
}),
|
|
42
|
+
z.strictObject({
|
|
43
|
+
operation: z.enum(["set-internet-access", "set-keep-awake"]),
|
|
29
44
|
computerId: fleetComputerId,
|
|
30
45
|
enabled: z.boolean(),
|
|
31
46
|
}),
|
|
@@ -34,11 +49,20 @@ function fleetStatus(result) {
|
|
|
34
49
|
if (result === null)
|
|
35
50
|
return 404;
|
|
36
51
|
if ("error" in result)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
switch (result.error) {
|
|
53
|
+
case "owner_required":
|
|
54
|
+
case "not_owner":
|
|
55
|
+
case "local_limit":
|
|
56
|
+
case "unknown_computer":
|
|
57
|
+
return 403;
|
|
58
|
+
case "invalid":
|
|
59
|
+
case "not_enabled":
|
|
60
|
+
return 400;
|
|
61
|
+
case "partial_init":
|
|
62
|
+
return 503;
|
|
63
|
+
default:
|
|
64
|
+
return 409;
|
|
65
|
+
}
|
|
42
66
|
return 200;
|
|
43
67
|
}
|
|
44
68
|
function fleetResponse(result) {
|
|
@@ -141,22 +165,26 @@ export function standaloneComputerFleetRoutes(registryFor) {
|
|
|
141
165
|
});
|
|
142
166
|
return fleetResponse(result);
|
|
143
167
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
168
|
+
// One owner switch per durable Computer setting, read and written alike.
|
|
169
|
+
for (const [path, read, write] of [
|
|
170
|
+
["internet-access", "read-internet-access", "set-internet-access"],
|
|
171
|
+
["keep-awake", "read-keep-awake", "set-keep-awake"],
|
|
172
|
+
]) {
|
|
173
|
+
routes.get(`/api/computers/:computerId/${path}`, owner, async (context, { principal }) => fleetResponse(await registryFor().computerFleet(principal.actor.memberId, {
|
|
174
|
+
operation: read,
|
|
147
175
|
computerId: context.req.param("computerId"),
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
})
|
|
159
|
-
}
|
|
176
|
+
})));
|
|
177
|
+
routes.put(`/api/computers/:computerId/${path}`, owner, async (context, { principal }) => {
|
|
178
|
+
const input = z
|
|
179
|
+
.strictObject({ enabled: z.boolean() })
|
|
180
|
+
.parse(await context.req.json());
|
|
181
|
+
return fleetResponse(await registryFor().computerFleet(principal.actor.memberId, {
|
|
182
|
+
operation: write,
|
|
183
|
+
computerId: context.req.param("computerId"),
|
|
184
|
+
enabled: input.enabled,
|
|
185
|
+
}));
|
|
186
|
+
});
|
|
187
|
+
}
|
|
160
188
|
routes.get("/api/computers/:computerId", owner, async (context, { principal }) => {
|
|
161
189
|
const result = await registryFor().computerFleet(principal.actor.memberId, {
|
|
162
190
|
operation: "read",
|
|
@@ -8,7 +8,7 @@ import { ComputerDO as NativeComputerDO, type AttachedBackend, type ComputerEnv,
|
|
|
8
8
|
import { patchInputSchema, patchOutputSchema } from "@fungi.computer/knapsack/files-patch";
|
|
9
9
|
import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
|
|
10
10
|
import { type WorkflowGitCredential, type WorkflowGitPassGrant } from "@fungi.computer/braid/runtime";
|
|
11
|
-
import { type ComputerAction, type ComputerGrant } from "@fungi.computer/computer/fleet";
|
|
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";
|
|
13
13
|
import { type OysterCapability } from "../host.js";
|
|
14
14
|
import type { OysterBindingRow, OysterInvocationHost, OysterWorkerEnv, OysterWorkspace } from "../workers.js";
|
|
@@ -71,6 +71,7 @@ export type ComputerFetch = {
|
|
|
71
71
|
export type StandaloneAgentComputerRpc = ComputerFilesRpc & Readonly<{
|
|
72
72
|
tool(authority: ComputerGrant, capabilityId: string, input: ComputerValue): Promise<StandaloneComputerResult>;
|
|
73
73
|
filePatch(authority: ComputerGrant, input: z.output<typeof patchInputSchema>): Promise<z.output<typeof patchOutputSchema>>;
|
|
74
|
+
fileWrite(authority: ComputerGrant, path: string, bytes: Uint8Array): Promise<void>;
|
|
74
75
|
}>;
|
|
75
76
|
/** Durable workspace and existing backings, with fleet checks at native acceptance. */
|
|
76
77
|
export declare class ComputerDO extends NativeComputerDO implements ComputerFetch, StandaloneAgentComputerRpc {
|
|
@@ -79,6 +80,24 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
79
80
|
constructor(state: DurableObjectState, previewBindings: StandaloneComputerOwnerEnv);
|
|
80
81
|
/** Install the fleet's creation projection before exposing its new identity. */
|
|
81
82
|
initializeFleetBackings(backings: readonly AttachedBackend[]): void;
|
|
83
|
+
/** The owner's attached backends with live status. Reads wake nothing. */
|
|
84
|
+
readBackends(authority: ComputerGrant, actor: string): ComputerBackendView[];
|
|
85
|
+
/** Attach the owner's machine; a replay of the same request returns it. */
|
|
86
|
+
attachLocalBackend(authority: ComputerGrant, actor: string, input: LocalBackendAttachInput): {
|
|
87
|
+
backendId: string;
|
|
88
|
+
error?: undefined;
|
|
89
|
+
} | {
|
|
90
|
+
error: "request_conflict" | "invalid" | "not_owner" | "unknown_computer" | "not_enabled" | "local_limit";
|
|
91
|
+
backendId?: undefined;
|
|
92
|
+
};
|
|
93
|
+
/** Detach the owner's machine and close its live connection. */
|
|
94
|
+
detachLocalBackend(authority: ComputerGrant, actor: string, input: LocalBackendDetachInput): {
|
|
95
|
+
detached: boolean;
|
|
96
|
+
error?: undefined;
|
|
97
|
+
} | {
|
|
98
|
+
error: "request_conflict" | "invalid" | "not_owner" | "unknown_computer" | "not_enabled" | "local_limit";
|
|
99
|
+
detached?: undefined;
|
|
100
|
+
};
|
|
82
101
|
/** An admitted fleet control starts exactly this Computer's hosted backend. */
|
|
83
102
|
startHostedComputer(authority: ComputerGrant): Promise<{
|
|
84
103
|
state: "running";
|
|
@@ -14,7 +14,7 @@ import { ComputerDO as NativeComputerDO, ComputerOperationConflictError, } from
|
|
|
14
14
|
import { patchInputSchema, patchOutputSchema, } from "@fungi.computer/knapsack/files-patch";
|
|
15
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";
|
|
16
16
|
import { workflowGitExecutionEnvironment, workflowGitPassGrantSchema, } from "@fungi.computer/braid/runtime";
|
|
17
|
-
import { checkComputerGrant, computerActionSchema, computerGrantSchema, createFleetBacking, FleetGrantRefused, FleetLifecycle, } from "@fungi.computer/computer/fleet";
|
|
17
|
+
import { checkComputerGrant, computerActionSchema, computerGrantSchema, ComputerBackingError, createFleetBacking, FleetGrantRefused, FleetLifecycle, } from "@fungi.computer/computer/fleet";
|
|
18
18
|
import { AppInstanceError, selectionOf } from "../index.js";
|
|
19
19
|
import {} from "../cloudflare.js";
|
|
20
20
|
import { computerSlots } from "../computer.js";
|
|
@@ -160,6 +160,68 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
160
160
|
owner.ensure();
|
|
161
161
|
this.#backends = owner.computerCreated(this.#id(), z.array(hostedBackingSchema).parse(backings)).backends;
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* The attached set changed in storage: rebuild the Workspace now, so a
|
|
165
|
+
* detached machine's live connection closes before the control returns.
|
|
166
|
+
*/
|
|
167
|
+
#attachedSetChanged() {
|
|
168
|
+
this.#backends = undefined;
|
|
169
|
+
this.workspace();
|
|
170
|
+
}
|
|
171
|
+
/** The owner's attached backends with live status. Reads wake nothing. */
|
|
172
|
+
readBackends(authority, actor) {
|
|
173
|
+
this.#accept(authority, "backing");
|
|
174
|
+
// Describing first gives a never-used Computer its creation record.
|
|
175
|
+
const described = this.describeBackends();
|
|
176
|
+
const owners = createFleetBacking(this.state.storage).localOwners(this.#id());
|
|
177
|
+
return described.map((backend) => ({
|
|
178
|
+
id: backend.id,
|
|
179
|
+
kind: backend.kind,
|
|
180
|
+
status: backend.status,
|
|
181
|
+
queuePosition: null,
|
|
182
|
+
hostId: backend.hostId ?? null,
|
|
183
|
+
hostLabel: backend.hostLabel ?? null,
|
|
184
|
+
folderLabel: backend.folderLabel ?? null,
|
|
185
|
+
detachable: owners.get(backend.id) === actor,
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
/** Attach the owner's machine; a replay of the same request returns it. */
|
|
189
|
+
attachLocalBackend(authority, actor, input) {
|
|
190
|
+
this.#accept(authority, "backing");
|
|
191
|
+
// The default Computer gains its creation record on first read.
|
|
192
|
+
this.attachedBackends();
|
|
193
|
+
try {
|
|
194
|
+
const result = createFleetBacking(this.state.storage).attachLocal(actor, {
|
|
195
|
+
...input,
|
|
196
|
+
computerId: this.#id(),
|
|
197
|
+
});
|
|
198
|
+
this.#attachedSetChanged();
|
|
199
|
+
return { backendId: result.backendId };
|
|
200
|
+
}
|
|
201
|
+
catch (cause) {
|
|
202
|
+
if (cause instanceof ComputerBackingError)
|
|
203
|
+
return { error: cause.code };
|
|
204
|
+
throw cause;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/** Detach the owner's machine and close its live connection. */
|
|
208
|
+
detachLocalBackend(authority, actor, input) {
|
|
209
|
+
this.#accept(authority, "backing");
|
|
210
|
+
this.attachedBackends();
|
|
211
|
+
try {
|
|
212
|
+
const result = createFleetBacking(this.state.storage).detachLocal(actor, {
|
|
213
|
+
...input,
|
|
214
|
+
computerId: this.#id(),
|
|
215
|
+
});
|
|
216
|
+
this.#attachedSetChanged();
|
|
217
|
+
return { detached: result.detached };
|
|
218
|
+
}
|
|
219
|
+
catch (cause) {
|
|
220
|
+
if (cause instanceof ComputerBackingError)
|
|
221
|
+
return { error: cause.code };
|
|
222
|
+
throw cause;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
163
225
|
/** An admitted fleet control starts exactly this Computer's hosted backend. */
|
|
164
226
|
async startHostedComputer(authority) {
|
|
165
227
|
this.#accept(authority, "start");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type CredentialRecord, type CredentialStorage } from "@fungi.computer/veil/credential-store";
|
|
2
|
+
import { type ModelKeyRecord, type ModelKeyVault } from "@fungi.computer/veil/model-keys";
|
|
3
|
+
/**
|
|
4
|
+
* This instance's own model-key owner. Provider API keys are sealed (AES-GCM)
|
|
5
|
+
* under a key derived from the instance master secret, a host secret that never
|
|
6
|
+
* enters the repository, storage or a log. A key leaves the vault only inside
|
|
7
|
+
* the request it is sent with; listings carry no secret.
|
|
8
|
+
*/
|
|
9
|
+
/** Why a key could not be stored or used; stable, secret-free. */
|
|
10
|
+
export type ModelKeyRefusal = "invalid_key" | "key_rejected" | "provider_unavailable" | "custody_unavailable" | "key_removed" | "target_denied" | "limit";
|
|
11
|
+
export declare class ModelKeyRefused extends Error {
|
|
12
|
+
readonly reason: ModelKeyRefusal;
|
|
13
|
+
constructor(reason: ModelKeyRefusal);
|
|
14
|
+
}
|
|
15
|
+
export type { ModelKeyRecord };
|
|
16
|
+
/** What the owner submits to seal one provider key. */
|
|
17
|
+
export type ModelKeySealInput = Readonly<{
|
|
18
|
+
provider: string;
|
|
19
|
+
label: string;
|
|
20
|
+
apiKey: string;
|
|
21
|
+
}>;
|
|
22
|
+
export type ModelKeyStorage = CredentialStorage;
|
|
23
|
+
/**
|
|
24
|
+
* The instance's one encrypted credential store. Listing and removal need no
|
|
25
|
+
* key; sealing and opening refuse without one.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createInstanceCredentialStore(options: {
|
|
28
|
+
storage: CredentialStorage;
|
|
29
|
+
credentialKey: string | undefined;
|
|
30
|
+
now?: () => number;
|
|
31
|
+
}): {
|
|
32
|
+
put(input: {
|
|
33
|
+
kind: string;
|
|
34
|
+
label: string;
|
|
35
|
+
secret: string;
|
|
36
|
+
}): Promise<CredentialRecord>;
|
|
37
|
+
list(kind?: string): Promise<readonly CredentialRecord[]>;
|
|
38
|
+
get(credentialId: string): Promise<CredentialRecord | null>;
|
|
39
|
+
remove(credentialId: string): Promise<"deleted" | "absent">;
|
|
40
|
+
withSecret<T>(credentialId: string, action: (secret: string, record: CredentialRecord) => Promise<T> | T): Promise<T>;
|
|
41
|
+
};
|
|
42
|
+
export declare function createModelKeyVault(options: {
|
|
43
|
+
storage: ModelKeyStorage;
|
|
44
|
+
/** The instance credential key (32 bytes, base64url); absent means no custody. */
|
|
45
|
+
credentialKey: string | undefined;
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
now?: () => number;
|
|
48
|
+
}): ModelKeyVault & Readonly<{
|
|
49
|
+
get: (keyId: string) => Promise<ModelKeyRecord | null>;
|
|
50
|
+
}>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { createCredentialSealer, createCredentialStore, CredentialError, } from "@fungi.computer/veil/credential-store";
|
|
2
|
+
import { isModelKeyProvider, modelKeyForwardedHeaders, modelKeyBaseUrl, modelKeyTarget, modelKeyValidationRequest, modelKeyValidationResult, } from "@fungi.computer/veil/model-keys";
|
|
3
|
+
export class ModelKeyRefused extends Error {
|
|
4
|
+
reason;
|
|
5
|
+
constructor(reason) {
|
|
6
|
+
super(reason);
|
|
7
|
+
this.reason = reason;
|
|
8
|
+
this.name = "ModelKeyRefused";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const kindOf = (provider) => `model-key/${provider}`;
|
|
12
|
+
const providerOf = (kind) => {
|
|
13
|
+
const provider = kind.slice("model-key/".length);
|
|
14
|
+
if (!isModelKeyProvider(provider))
|
|
15
|
+
throw new ModelKeyRefused("invalid_key");
|
|
16
|
+
return provider;
|
|
17
|
+
};
|
|
18
|
+
const maxKeyLength = 16_384;
|
|
19
|
+
const publicRecord = (record) => ({
|
|
20
|
+
keyId: record.credentialId,
|
|
21
|
+
provider: providerOf(record.kind),
|
|
22
|
+
label: record.label,
|
|
23
|
+
createdAt: record.createdAt,
|
|
24
|
+
validatedAt: record.validatedAt,
|
|
25
|
+
});
|
|
26
|
+
/** Anthropic authenticates with `x-api-key`; the others take a bearer token. */
|
|
27
|
+
function authenticated(provider, headers, apiKey) {
|
|
28
|
+
const next = new Headers(headers);
|
|
29
|
+
if (provider === "anthropic")
|
|
30
|
+
next.set("x-api-key", apiKey);
|
|
31
|
+
else
|
|
32
|
+
next.set("authorization", `Bearer ${apiKey}`);
|
|
33
|
+
return next;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The instance's one encrypted credential store. Listing and removal need no
|
|
37
|
+
* key; sealing and opening refuse without one.
|
|
38
|
+
*/
|
|
39
|
+
export function createInstanceCredentialStore(options) {
|
|
40
|
+
const unavailable = () => Promise.reject(new CredentialError("unavailable"));
|
|
41
|
+
const sealer = options.credentialKey === undefined
|
|
42
|
+
? { seal: unavailable, open: unavailable }
|
|
43
|
+
: createCredentialSealer({
|
|
44
|
+
activeKeyId: "instance",
|
|
45
|
+
keys: { instance: options.credentialKey },
|
|
46
|
+
}, "fungi.oyster.credentials.v1");
|
|
47
|
+
const storeOptions = {
|
|
48
|
+
storage: options.storage,
|
|
49
|
+
sealer,
|
|
50
|
+
};
|
|
51
|
+
if (options.now !== undefined)
|
|
52
|
+
storeOptions.now = options.now;
|
|
53
|
+
return createCredentialStore(storeOptions);
|
|
54
|
+
}
|
|
55
|
+
export function createModelKeyVault(options) {
|
|
56
|
+
const send = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
57
|
+
const credentialKey = options.credentialKey;
|
|
58
|
+
const credentials = createInstanceCredentialStore(options);
|
|
59
|
+
const store = () => credentials;
|
|
60
|
+
const custody = async (work) => {
|
|
61
|
+
try {
|
|
62
|
+
return await work();
|
|
63
|
+
}
|
|
64
|
+
catch (cause) {
|
|
65
|
+
if (cause instanceof CredentialError)
|
|
66
|
+
throw new ModelKeyRefused(cause.code === "absent"
|
|
67
|
+
? "key_removed"
|
|
68
|
+
: cause.code === "limit"
|
|
69
|
+
? "limit"
|
|
70
|
+
: "custody_unavailable");
|
|
71
|
+
throw cause;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
/** Validate with one cheap authenticated read, then store only the sealed key. */
|
|
76
|
+
async seal(input) {
|
|
77
|
+
const { provider, label, apiKey } = input;
|
|
78
|
+
if (!isModelKeyProvider(provider) ||
|
|
79
|
+
provider === "openai-compatible" ||
|
|
80
|
+
label.length === 0 ||
|
|
81
|
+
label.length > 64 ||
|
|
82
|
+
apiKey.length === 0 ||
|
|
83
|
+
apiKey.length > maxKeyLength)
|
|
84
|
+
throw new ModelKeyRefused("invalid_key");
|
|
85
|
+
if (credentialKey === undefined)
|
|
86
|
+
throw new ModelKeyRefused("custody_unavailable");
|
|
87
|
+
const baseUrl = modelKeyBaseUrl(provider);
|
|
88
|
+
const probe = modelKeyValidationRequest({ provider, baseUrl }, AbortSignal.timeout(15_000));
|
|
89
|
+
let status;
|
|
90
|
+
try {
|
|
91
|
+
const response = await send(new Request(probe, {
|
|
92
|
+
headers: authenticated(provider, probe.headers, apiKey),
|
|
93
|
+
}));
|
|
94
|
+
status = response.status;
|
|
95
|
+
await response.body?.cancel();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Transport text can echo request headers; surface only the typed cause.
|
|
99
|
+
throw new ModelKeyRefused("provider_unavailable");
|
|
100
|
+
}
|
|
101
|
+
const verdict = modelKeyValidationResult(status);
|
|
102
|
+
if (verdict === "rejected")
|
|
103
|
+
throw new ModelKeyRefused("key_rejected");
|
|
104
|
+
if (verdict === "unavailable")
|
|
105
|
+
throw new ModelKeyRefused("provider_unavailable");
|
|
106
|
+
return publicRecord(await custody(() => credentials.put({ kind: kindOf(provider), label, secret: apiKey })));
|
|
107
|
+
},
|
|
108
|
+
async list() {
|
|
109
|
+
return (await custody(() => store().list()))
|
|
110
|
+
.filter((record) => record.kind.startsWith("model-key/"))
|
|
111
|
+
.map(publicRecord);
|
|
112
|
+
},
|
|
113
|
+
async get(keyId) {
|
|
114
|
+
const record = await custody(() => store().get(keyId));
|
|
115
|
+
return record === null ? null : publicRecord(record);
|
|
116
|
+
},
|
|
117
|
+
remove(keyId) {
|
|
118
|
+
return custody(() => store().remove(keyId));
|
|
119
|
+
},
|
|
120
|
+
/** Send one provider request with the key attached; the caller's auth is dropped. */
|
|
121
|
+
send(keyId, request) {
|
|
122
|
+
return custody(() => store().withSecret(keyId, (apiKey, record) => {
|
|
123
|
+
const provider = providerOf(record.kind);
|
|
124
|
+
let target;
|
|
125
|
+
try {
|
|
126
|
+
target = modelKeyTarget({
|
|
127
|
+
locator: record.credentialId,
|
|
128
|
+
provider,
|
|
129
|
+
baseUrl: modelKeyBaseUrl(provider),
|
|
130
|
+
}, request);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw new ModelKeyRefused("target_denied");
|
|
134
|
+
}
|
|
135
|
+
// `duplex` is a Node/Workers extension lib.dom's RequestInit omits.
|
|
136
|
+
const init = {
|
|
137
|
+
method: request.method,
|
|
138
|
+
headers: authenticated(provider, modelKeyForwardedHeaders(request), apiKey),
|
|
139
|
+
body: request.method === "GET" ? null : request.body,
|
|
140
|
+
signal: request.signal,
|
|
141
|
+
duplex: "half",
|
|
142
|
+
};
|
|
143
|
+
return send(new Request(target, init));
|
|
144
|
+
}));
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -60,6 +60,29 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
|
|
|
60
60
|
updatedAt: number;
|
|
61
61
|
}>[];
|
|
62
62
|
readonly nextOffset: number | null;
|
|
63
|
+
} | ({
|
|
64
|
+
backendId: string;
|
|
65
|
+
error?: undefined;
|
|
66
|
+
} & Disposable) | ({
|
|
67
|
+
error: "request_conflict" | "invalid" | "not_owner" | "unknown_computer" | "not_enabled" | "local_limit";
|
|
68
|
+
backendId?: undefined;
|
|
69
|
+
} & Disposable) | ({
|
|
70
|
+
detached: boolean;
|
|
71
|
+
error?: undefined;
|
|
72
|
+
} & Disposable) | ({
|
|
73
|
+
error: "request_conflict" | "invalid" | "not_owner" | "unknown_computer" | "not_enabled" | "local_limit";
|
|
74
|
+
detached?: undefined;
|
|
75
|
+
} & Disposable) | {
|
|
76
|
+
backends: {
|
|
77
|
+
id: string;
|
|
78
|
+
kind: "platform-container" | "on-box-vm" | "local";
|
|
79
|
+
status: "queued" | "ready" | "online" | "offline";
|
|
80
|
+
queuePosition: number | null;
|
|
81
|
+
hostId: string | null;
|
|
82
|
+
hostLabel: string | null;
|
|
83
|
+
folderLabel: string | null;
|
|
84
|
+
detachable: boolean;
|
|
85
|
+
}[];
|
|
63
86
|
} | ({
|
|
64
87
|
state: "queued";
|
|
65
88
|
position: number;
|
|
@@ -122,6 +122,19 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
122
122
|
: undefined),
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
case "read-keep-awake":
|
|
126
|
+
case "set-keep-awake": {
|
|
127
|
+
if (this.#computers.read(input.computerId) === null)
|
|
128
|
+
return null;
|
|
129
|
+
const computer = this.#env.COMPUTER.getByName(input.computerId);
|
|
130
|
+
return {
|
|
131
|
+
enabled: await computer.keepAwake(input.operation === "set-keep-awake" ? input.enabled : undefined),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
case "backends":
|
|
135
|
+
case "attach-local":
|
|
136
|
+
case "detach-local":
|
|
137
|
+
return this.#machines(memberId, input);
|
|
125
138
|
case "select": {
|
|
126
139
|
const computer = this.#computers.read(input.computerId);
|
|
127
140
|
if (computer === null)
|
|
@@ -149,6 +162,32 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
149
162
|
});
|
|
150
163
|
}
|
|
151
164
|
}
|
|
165
|
+
/** Attached machines of one owned Computer; the Computer holds the rows. */
|
|
166
|
+
async #machines(memberId, input) {
|
|
167
|
+
const computerId = input.operation === "backends"
|
|
168
|
+
? input.computerId
|
|
169
|
+
: input.request.computerId;
|
|
170
|
+
if (!this.ownsComputer(computerId))
|
|
171
|
+
return null;
|
|
172
|
+
const computer = this.#env.COMPUTER.getByName(computerId);
|
|
173
|
+
const authority = {
|
|
174
|
+
computerId,
|
|
175
|
+
actions: new Set(["backing"]),
|
|
176
|
+
expiresAt: Date.now() + 60_000,
|
|
177
|
+
provenance: { actor: memberId },
|
|
178
|
+
};
|
|
179
|
+
switch (input.operation) {
|
|
180
|
+
case "backends":
|
|
181
|
+
// The RPC result is disposable; the registry returns plain data.
|
|
182
|
+
return {
|
|
183
|
+
backends: [...(await computer.readBackends(authority, memberId))],
|
|
184
|
+
};
|
|
185
|
+
case "attach-local":
|
|
186
|
+
return await computer.attachLocalBackend(authority, memberId, input.request);
|
|
187
|
+
case "detach-local":
|
|
188
|
+
return await computer.detachLocalBackend(authority, memberId, input.request);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
152
191
|
/** A durable selection snapshot; the configured default remains the App build Computer. */
|
|
153
192
|
async selectedComputer() {
|
|
154
193
|
const selected = await this.#fleetStorage.get("selected-computer");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CapabilitySource } from "@fungi.computer/mycelium";
|
|
2
|
+
import type { VeilBindings } from "@fungi.computer/veil/gatekeeper";
|
|
3
|
+
/**
|
|
4
|
+
* A standalone Oyster's `web` module. Page reads go through Veil's
|
|
5
|
+
* public-fetch door exactly as the Hub's do (one resolve, non-public addresses
|
|
6
|
+
* refused, redirects rechecked). Search is Parallel through Veil's route when
|
|
7
|
+
* the owner configured `PARALLEL_API_KEY`, else an explicit refusal. There is
|
|
8
|
+
* no credit ledger here: the owner's Parallel account pays directly.
|
|
9
|
+
*/
|
|
10
|
+
export declare function standaloneWebSource(env: VeilBindings): CapabilitySource;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { configuredPublicFetch } from "@fungi.computer/veil/public-fetch";
|
|
2
|
+
import { causeClass } from "../cause-class.js";
|
|
3
|
+
import { createWebSource, parallelWebSearch } from "../web/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* A standalone Oyster's `web` module. Page reads go through Veil's
|
|
6
|
+
* public-fetch door exactly as the Hub's do (one resolve, non-public addresses
|
|
7
|
+
* refused, redirects rechecked). Search is Parallel through Veil's route when
|
|
8
|
+
* the owner configured `PARALLEL_API_KEY`, else an explicit refusal. There is
|
|
9
|
+
* no credit ledger here: the owner's Parallel account pays directly.
|
|
10
|
+
*/
|
|
11
|
+
export function standaloneWebSource(env) {
|
|
12
|
+
return createWebSource({
|
|
13
|
+
// The sockets door loads when a page is first read, so hosts that never
|
|
14
|
+
// fetch (and Node test hosts) never resolve the Workers-only module.
|
|
15
|
+
get: async (request) => {
|
|
16
|
+
const { connect } = await import("cloudflare:sockets");
|
|
17
|
+
return configuredPublicFetch({
|
|
18
|
+
connect,
|
|
19
|
+
fetch: (input, init) => fetch(input, init),
|
|
20
|
+
}).get(request);
|
|
21
|
+
},
|
|
22
|
+
search: parallelWebSearch(env, {
|
|
23
|
+
fetch: (input, init) => fetch(input, init),
|
|
24
|
+
report: (event) => {
|
|
25
|
+
// Code-only: never a URL, provider body or key.
|
|
26
|
+
console.warn("Oyster web search", {
|
|
27
|
+
kind: event.kind,
|
|
28
|
+
status: event.status,
|
|
29
|
+
cause: causeClass(event.cause),
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The standalone Worker's top-level table, before any tenant is selected:
|
|
3
|
-
* device enrollment and links, signed Workflow webhook delivery, then the
|
|
3
|
+
* device enrollment and links, attached-machine dials, signed Workflow webhook delivery, then the
|
|
4
4
|
* selected tenant's own declared host table for every other path. The Worker
|
|
5
5
|
* and the authorization law both compose it here.
|
|
6
6
|
*/
|
|
@@ -10,6 +10,8 @@ import { type Routes } from "../authorization.js";
|
|
|
10
10
|
export type StandaloneWorkerRoutePorts = Readonly<{
|
|
11
11
|
/** The machine-link doors' own table, served for this request. */
|
|
12
12
|
machineLink: (request: Request) => Promise<Response>;
|
|
13
|
+
/** A machine's signed dial to its attached Computer, verified by that Computer. */
|
|
14
|
+
localBackendDial: (request: Request) => Promise<Response>;
|
|
13
15
|
/** Signed Workflow webhook delivery, verified by the library's run owner. */
|
|
14
16
|
workflowWebhooks: Routes<BlankEnv>;
|
|
15
17
|
/** The selected tenant's declared host table. */
|
|
@@ -4,6 +4,7 @@ export function standaloneWorkerRoutes(ports) {
|
|
|
4
4
|
return routes()
|
|
5
5
|
.all("/local/mesh/join", door("machine enrollment; the join route verifies its key"), (context) => ports.machineLink(context.req.raw))
|
|
6
6
|
.all("/api/teams/:teamId/local/mesh/:deviceId/connect", door("a machine link; the device's link verifies Seam"), (context) => ports.machineLink(context.req.raw))
|
|
7
|
+
.all("/api/computers/:computerId/backends/:backendId/connect", door("an attached machine's dial; the Computer verifies its Seam signature"), (context) => ports.localBackendDial(context.req.raw))
|
|
7
8
|
.include(ports.workflowWebhooks)
|
|
8
9
|
.all("*", door("the selected tenant's own declared host table"), (context) => ports.tenant(context.req.raw));
|
|
9
10
|
}
|
|
@@ -8,7 +8,7 @@ import { defaultTenant, tenantScope } from "../tenant.js";
|
|
|
8
8
|
import { oysterPrincipalIsOwner } from "../authorization.js";
|
|
9
9
|
import { standaloneComputerControl } from "./computer-control.js";
|
|
10
10
|
import { standalonePermissionResources } from "./permission-resources.js";
|
|
11
|
-
import { onBoxVmIngress } from "@fungi.computer/computer";
|
|
11
|
+
import { onBoxVmIngress, ownerLocalBackendDialPath, } from "@fungi.computer/computer";
|
|
12
12
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
13
13
|
import { installationWorkerEntrypoint } from "../installation-execution.js";
|
|
14
14
|
import { putContentObject } from "../build-contract.js";
|
|
@@ -189,6 +189,14 @@ export default {
|
|
|
189
189
|
// tenant host's own declared table.
|
|
190
190
|
return serveDoors(standaloneWorkerRoutes({
|
|
191
191
|
machineLink: (incoming) => serveDoors(standaloneMachineLinkRoutes(env).onError(standaloneWorkerErrorHandler)).fetch(incoming, env, context),
|
|
192
|
+
localBackendDial: async (incoming) => {
|
|
193
|
+
const dial = ownerLocalBackendDialPath.exec(new URL(incoming.url).pathname);
|
|
194
|
+
// Only a Computer this Oyster owns is addressed; no stray object is made.
|
|
195
|
+
if (dial === null ||
|
|
196
|
+
!(await computerRegistry(env).ownsComputer(dial[1] ?? "")))
|
|
197
|
+
return new Response(null, { status: 404 });
|
|
198
|
+
return env.COMPUTER.getByName(dial[1] ?? "").fetch(incoming);
|
|
199
|
+
},
|
|
192
200
|
workflowWebhooks: standaloneWorkflowWebhookRoutes(env, async (incoming) => {
|
|
193
201
|
const admitted = await oysterRoot.admit(env, incoming);
|
|
194
202
|
return admitted === null
|