@fungi.computer/oyster 0.9.0 → 0.11.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 +46 -2
- package/dist/agents.d.ts +82 -23
- package/dist/agents.js +187 -40
- package/dist/authorization.d.ts +25 -3
- package/dist/authorization.js +47 -14
- package/dist/browser/capability-source.d.ts +23 -5
- package/dist/browser/capability-source.js +19 -22
- package/dist/browser/index.d.ts +2 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/live-view.d.ts +38 -0
- package/dist/browser/live-view.js +179 -0
- package/dist/channels/binding.d.ts +2 -0
- package/dist/channels/run-decision.d.ts +33 -0
- package/dist/channels/run-decision.js +25 -0
- package/dist/channels/visitor-channel.d.ts +84 -14
- package/dist/channels/visitor-channel.js +55 -32
- package/dist/channels/visitor-edge.d.ts +18 -2
- package/dist/channels/visitor-edge.js +67 -5
- package/dist/channels/visitors.d.ts +4 -0
- package/dist/channels/visitors.js +22 -1
- package/dist/channels/web-binding.d.ts +117 -0
- package/dist/channels/web-binding.js +227 -0
- package/dist/computer-control-port.d.ts +20 -1
- package/dist/embed-metafiles.d.ts +8 -0
- package/dist/embed-metafiles.js +2 -0
- package/dist/embed-scripts.d.ts +8 -0
- package/dist/embed-scripts.js +3 -0
- package/dist/host.d.ts +3 -1
- package/dist/host.js +6 -1
- package/dist/mcp.d.ts +128 -0
- package/dist/mcp.js +63 -1
- package/dist/page/embed-challenge.d.ts +19 -0
- package/dist/page/embed-challenge.js +45 -0
- package/dist/page/embed-error.d.ts +2 -0
- package/dist/page/embed-error.js +16 -0
- package/dist/page/embed-loader-protocol.d.ts +12 -0
- package/dist/page/embed-loader-protocol.js +29 -0
- package/dist/standalone/agent-computers.d.ts +12 -1
- package/dist/standalone/agent-computers.js +35 -0
- package/dist/standalone/agent-connections.d.ts +50 -0
- package/dist/standalone/agent-connections.js +214 -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 +224 -9
- package/dist/standalone/agents.js +485 -115
- package/dist/standalone/browser.d.ts +16 -3
- package/dist/standalone/browser.js +54 -5
- package/dist/standalone/channel-session-door.d.ts +4 -0
- package/dist/standalone/channel-session-door.js +72 -0
- package/dist/standalone/computer-control.js +55 -1
- package/dist/standalone/computer-fleet.d.ts +21 -0
- package/dist/standalone/computer-fleet.js +30 -6
- 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/owner-routes.d.ts +4 -3
- package/dist/standalone/owner-routes.js +7 -1
- package/dist/standalone/registry.d.ts +23 -0
- package/dist/standalone/registry.js +30 -0
- package/dist/standalone/visitor-edge.d.ts +36 -0
- package/dist/standalone/visitor-edge.js +67 -0
- package/dist/standalone/visitor-proof.d.ts +23 -0
- package/dist/standalone/visitor-proof.js +67 -0
- package/dist/standalone/web.d.ts +10 -0
- package/dist/standalone/web.js +34 -0
- package/dist/standalone/website-channels.d.ts +134 -0
- package/dist/standalone/website-channels.js +262 -0
- package/dist/standalone/worker-routes.d.ts +6 -1
- package/dist/standalone/worker-routes.js +4 -0
- package/dist/standalone/worker.d.ts +2 -1
- package/dist/standalone/worker.js +13 -1
- package/dist/testing/capabilities.d.ts +3 -0
- package/dist/testing/capabilities.js +1 -0
- package/dist/testing/installation.d.ts +4 -2
- package/dist/testing/installation.js +7 -2
- 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 +3 -2
- package/docs/api/agents.md +184 -39
- package/docs/api/apps.md +129 -111
- package/docs/api/browser.md +115 -8
- 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 +69 -60
- package/docs/api/mcp.md +81 -44
- package/docs/api/workers-git.md +6 -6
- package/docs/api/workers.md +53 -47
- package/package.json +52 -22
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The standalone root's owner routes: App source seeding, builds, the Computer
|
|
3
|
-
* fleet, Agent Computer attachment and Workflow webhook
|
|
3
|
+
* fleet, Agent Computer attachment, website channels and Workflow webhook
|
|
4
|
+
* controls. The Worker
|
|
4
5
|
* and the authorization law both compose them from this one function.
|
|
5
6
|
*/
|
|
6
7
|
import type { OysterEnv, OysterHost } from "../host.js";
|
|
7
8
|
import type { Routes } from "../authorization.js";
|
|
8
|
-
import type
|
|
9
|
+
import { type TenantScope } from "../tenant.js";
|
|
9
10
|
import type { StandaloneAgentsEnv } from "./agents.js";
|
|
10
11
|
import { type AppSourceBindingEnv } from "./app-source.js";
|
|
11
12
|
import type { StandaloneComputerEnv } from "./computer.js";
|
|
12
13
|
import type { StandaloneWorkflowEnv } from "./workflows.js";
|
|
13
14
|
/** The bindings the standalone owner routes reach, resolved per request. */
|
|
14
|
-
export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneComputerEnv, "REGISTRY"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
|
|
15
|
+
export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN"> & Pick<StandaloneComputerEnv, "REGISTRY"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
|
|
15
16
|
/** Every owner route the standalone root adds to its tenant host. */
|
|
16
17
|
export declare function standaloneOwnerRoutes(env: StandaloneOwnerRoutesEnv, scope: TenantScope, hostFor: () => Promise<Pick<OysterHost, "installations">>): Routes<OysterEnv>;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { defaultTenant } from "../tenant.js";
|
|
1
2
|
import { agentDirectoryForScope } from "./agent-directory.js";
|
|
2
3
|
import { standaloneAgentComputerRoutes } from "./agent-computers.js";
|
|
3
4
|
import { appSourceOwnerRoutes, } from "./app-source.js";
|
|
4
5
|
import { standaloneBuildRoutes } from "./builds.js";
|
|
5
6
|
import { standaloneComputerFleetRoutes } from "./computer-fleet.js";
|
|
6
7
|
import { standaloneWorkflowWebhookControls } from "./workflow-webhooks.js";
|
|
8
|
+
import { standaloneWebsiteControl, standaloneWebsiteRoutes, } from "./website-channels.js";
|
|
7
9
|
/** Every owner route the standalone root adds to its tenant host. */
|
|
8
10
|
export function standaloneOwnerRoutes(env, scope, hostFor) {
|
|
9
11
|
// A tenant's registry owns its installations, builds and Computer fleet.
|
|
10
12
|
const registry = () => env.REGISTRY.getByName(scope.durableName("registry"));
|
|
11
13
|
const directory = () => agentDirectoryForScope(env, scope);
|
|
12
|
-
|
|
14
|
+
const owned = appSourceOwnerRoutes(env, scope)
|
|
13
15
|
.include(standaloneBuildRoutes(registry))
|
|
14
16
|
.include(standaloneComputerFleetRoutes(registry))
|
|
15
17
|
.include(standaloneAgentComputerRoutes({
|
|
@@ -18,4 +20,8 @@ export function standaloneOwnerRoutes(env, scope, hostFor) {
|
|
|
18
20
|
read: (principal, agentId) => directory().readAgentComputers(agentId, principal, scope.tenantId),
|
|
19
21
|
}))
|
|
20
22
|
.include(standaloneWorkflowWebhookControls(env, hostFor));
|
|
23
|
+
// A website is served from the default tenant's directory, which owns it.
|
|
24
|
+
return scope.tenantId === defaultTenant
|
|
25
|
+
? owned.include(standaloneWebsiteRoutes(standaloneWebsiteControl(env, directory)))
|
|
26
|
+
: owned;
|
|
21
27
|
}
|
|
@@ -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;
|
|
@@ -131,6 +131,10 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
131
131
|
enabled: await computer.keepAwake(input.operation === "set-keep-awake" ? input.enabled : undefined),
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
|
+
case "backends":
|
|
135
|
+
case "attach-local":
|
|
136
|
+
case "detach-local":
|
|
137
|
+
return this.#machines(memberId, input);
|
|
134
138
|
case "select": {
|
|
135
139
|
const computer = this.#computers.read(input.computerId);
|
|
136
140
|
if (computer === null)
|
|
@@ -158,6 +162,32 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
158
162
|
});
|
|
159
163
|
}
|
|
160
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
|
+
}
|
|
161
191
|
/** A durable selection snapshot; the configured default remains the App build Computer. */
|
|
162
192
|
async selectedComputer() {
|
|
163
193
|
const selected = await this.#fleetStorage.get("selected-computer");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context, Env as HonoEnv } from "hono";
|
|
2
|
+
import type { ConversationBinding } from "../channels/binding.js";
|
|
3
|
+
import { type EdgeVerifiedVisitor, type VisitorSiteFacts, type VisitorTurnstile } from "../channels/visitor-edge.js";
|
|
4
|
+
import type { AuthenticatedChannelVisitor } from "../channels/visitor-channel.js";
|
|
5
|
+
import type { ChannelVisitors } from "../channels/visitors.js";
|
|
6
|
+
import type { StandaloneAgentBase } from "./agents.js";
|
|
7
|
+
/** The central owner keeps every binding's visitor families and address caps.
|
|
8
|
+
* A Durable Object can supply these four RPCs; no token store lives in Agents. */
|
|
9
|
+
export type StandaloneVisitorIdentity = Pick<ChannelVisitors, "mint" | "refresh" | "rotate" | "authenticate">;
|
|
10
|
+
export type StandaloneVisitorAgent = Pick<StandaloneAgentBase, "sendChannelVisitor" | "withdrawChannelVisitor" | "latestPendingChannelVisitor" | "openChannelVisitor" | "watchChannelVisitor">;
|
|
11
|
+
/** A web binding and the Agent it puts in front of visitors. */
|
|
12
|
+
export type StandaloneVisitorBinding = ConversationBinding & Readonly<{
|
|
13
|
+
agentId: string;
|
|
14
|
+
}>;
|
|
15
|
+
/** A resolved site: the binding the edge enforces and the chrome it serves. */
|
|
16
|
+
export type StandaloneVisitorSite = Readonly<{
|
|
17
|
+
binding: StandaloneVisitorBinding;
|
|
18
|
+
facts: VisitorSiteFacts;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Web sites with central identity and one dedicated Agent per site. The host
|
|
22
|
+
* supplies the address salt, the site lookup and the Agent; the edge
|
|
23
|
+
* authenticates before selecting an Agent and never sends a bearer into it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function standaloneVisitorEdge<E extends HonoEnv>(host: {
|
|
26
|
+
/** Re-read on every request and stream beat; suspension never freezes. */
|
|
27
|
+
site: (context: Context<E>, siteKey: string) => StandaloneVisitorSite | null | Promise<StandaloneVisitorSite | null>;
|
|
28
|
+
visitors: (context: Context<E>) => StandaloneVisitorIdentity;
|
|
29
|
+
agent: (context: Context<E>, binding: StandaloneVisitorBinding, visitor: EdgeVerifiedVisitor<AuthenticatedChannelVisitor>) => StandaloneVisitorAgent | Promise<StandaloneVisitorAgent>;
|
|
30
|
+
/** Private host secret shared with the Agent subclass, never the browser. */
|
|
31
|
+
proofKey: (context: Context<E>) => string;
|
|
32
|
+
addressHash: (context: Context<E>) => Promise<string>;
|
|
33
|
+
turnstile: (context: Context<E>) => VisitorTurnstile;
|
|
34
|
+
assetPath: (kind: "widget" | "styles") => string;
|
|
35
|
+
onError: (error: Error, context: Context<E>) => Response | Promise<Response>;
|
|
36
|
+
}): import("hono").Hono<E, import("hono/types").BlankSchema, "/">;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createVisitorEdge, } from "../channels/visitor-edge.js";
|
|
2
|
+
import { proveVisitor } from "./visitor-proof.js";
|
|
3
|
+
/**
|
|
4
|
+
* Web sites with central identity and one dedicated Agent per site. The host
|
|
5
|
+
* supplies the address salt, the site lookup and the Agent; the edge
|
|
6
|
+
* authenticates before selecting an Agent and never sends a bearer into it.
|
|
7
|
+
*/
|
|
8
|
+
export function standaloneVisitorEdge(host) {
|
|
9
|
+
const identityDoor = (context, site) => ({
|
|
10
|
+
[Symbol.dispose]: () => undefined,
|
|
11
|
+
readChannelSite: ({ bindingId, siteKey: key }) => Promise.resolve(bindingId === site.bindingId &&
|
|
12
|
+
site.binding.selector.provider === "web" &&
|
|
13
|
+
key === site.binding.selector.siteKey &&
|
|
14
|
+
site.binding.lifecycle === "active"
|
|
15
|
+
? site.facts
|
|
16
|
+
: null),
|
|
17
|
+
mintChannelVisitor: ({ siteKey: key, addressHash }) => host.visitors(context).mint(site.binding, key, addressHash),
|
|
18
|
+
refreshChannelVisitor: ({ refreshSecret }) => host.visitors(context).refresh(site.binding, refreshSecret),
|
|
19
|
+
rotateChannelVisitor: ({ siteKey: key, accessToken, addressHash }) => host
|
|
20
|
+
.visitors(context)
|
|
21
|
+
.rotate(site.binding, key, accessToken, addressHash),
|
|
22
|
+
sendAsChannelVisitor: () => Promise.resolve({ kind: "unauthorized" }),
|
|
23
|
+
withdrawAsChannelVisitor: () => Promise.resolve({ kind: "unauthorized" }),
|
|
24
|
+
latestPendingAsChannelVisitor: () => Promise.resolve({ kind: "unauthorized" }),
|
|
25
|
+
openVisitorSession: () => Promise.resolve({ kind: "unauthorized" }),
|
|
26
|
+
watchAsChannelVisitor: () => Promise.resolve({ kind: "unauthorized" }),
|
|
27
|
+
// The old GET /conversation has no standalone caller. Do not invent an
|
|
28
|
+
// unauthenticated site-wide transcript for a per-visitor Agent directory.
|
|
29
|
+
readAsChannelVisitor: () => Promise.resolve({ kind: "unauthorized" }),
|
|
30
|
+
});
|
|
31
|
+
return createVisitorEdge({
|
|
32
|
+
resolveSite: async (context, key) => {
|
|
33
|
+
const resolved = await host.site(context, key);
|
|
34
|
+
if (resolved === null)
|
|
35
|
+
return null;
|
|
36
|
+
const { binding, facts } = resolved;
|
|
37
|
+
return binding.selector.provider === "web" &&
|
|
38
|
+
binding.selector.siteKey === key
|
|
39
|
+
? { bindingId: binding.bindingId, binding, facts }
|
|
40
|
+
: null;
|
|
41
|
+
},
|
|
42
|
+
openSite: (context, site) => Promise.resolve(identityDoor(context, site)),
|
|
43
|
+
authenticateVisitor: (context, site, token) => host.visitors(context).authenticate(site.bindingId, token),
|
|
44
|
+
openChannel: async (context, site, visitor) => {
|
|
45
|
+
const proven = await proveVisitor(site.bindingId, visitor, host.proofKey(context));
|
|
46
|
+
const agent = await host.agent(context, site.binding, visitor);
|
|
47
|
+
const identity = identityDoor(context, site);
|
|
48
|
+
return {
|
|
49
|
+
[Symbol.dispose]: () => undefined,
|
|
50
|
+
readChannelSite: identity.readChannelSite,
|
|
51
|
+
mintChannelVisitor: identity.mintChannelVisitor,
|
|
52
|
+
refreshChannelVisitor: identity.refreshChannelVisitor,
|
|
53
|
+
rotateChannelVisitor: identity.rotateChannelVisitor,
|
|
54
|
+
readAsChannelVisitor: identity.readAsChannelVisitor,
|
|
55
|
+
sendAsChannelVisitor: ({ requestId, text }) => agent.sendChannelVisitor(site.bindingId, proven, requestId, text),
|
|
56
|
+
withdrawAsChannelVisitor: ({ requestId }) => agent.withdrawChannelVisitor(site.bindingId, proven, requestId),
|
|
57
|
+
latestPendingAsChannelVisitor: () => agent.latestPendingChannelVisitor(site.bindingId, proven),
|
|
58
|
+
openVisitorSession: ({ options }) => agent.openChannelVisitor(site.bindingId, proven, options),
|
|
59
|
+
watchAsChannelVisitor: () => agent.watchChannelVisitor(site.bindingId, proven),
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
addressHash: host.addressHash,
|
|
63
|
+
turnstile: host.turnstile,
|
|
64
|
+
assetPath: host.assetPath,
|
|
65
|
+
onError: host.onError,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AuthenticatedChannelVisitor } from "../channels/visitor-channel.js";
|
|
3
|
+
import type { EdgeVerifiedVisitor } from "../channels/visitor-edge.js";
|
|
4
|
+
/** An internal, short-lived assertion, not the visitor's bearer. The Worker
|
|
5
|
+
* and its Agent owner receive the same host secret; no public route reads it.
|
|
6
|
+
* This is required because a TypeScript brand disappears over DO RPC. */
|
|
7
|
+
declare const proofSchema: z.ZodObject<{
|
|
8
|
+
visitorId: z.ZodString;
|
|
9
|
+
addressHash: z.ZodString;
|
|
10
|
+
bindingId: z.ZodString;
|
|
11
|
+
expiresAt: z.ZodNumber;
|
|
12
|
+
signature: z.ZodBase64URL;
|
|
13
|
+
}, z.core.$strict>;
|
|
14
|
+
export type ProvenVisitor = AuthenticatedChannelVisitor & Readonly<{
|
|
15
|
+
edgeProof: z.infer<typeof proofSchema>;
|
|
16
|
+
}>;
|
|
17
|
+
/** The edge calls this only after the central visitor owner authenticated
|
|
18
|
+
* this request. Neither bearer nor proof key crosses to the public client. */
|
|
19
|
+
export declare function proveVisitor(bindingId: string, visitor: EdgeVerifiedVisitor<AuthenticatedChannelVisitor>, secret: string, now?: number): Promise<ProvenVisitor>;
|
|
20
|
+
/** Every public Agent RPC must verify before accessing a conversation or
|
|
21
|
+
* running a model. A forged or stale identity cannot cross the DO boundary. */
|
|
22
|
+
export declare function verifyVisitor(bindingId: string, value: unknown, secret: string | null, now?: number): Promise<ProvenVisitor>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** An internal, short-lived assertion, not the visitor's bearer. The Worker
|
|
3
|
+
* and its Agent owner receive the same host secret; no public route reads it.
|
|
4
|
+
* This is required because a TypeScript brand disappears over DO RPC. */
|
|
5
|
+
const proofSchema = z.strictObject({
|
|
6
|
+
visitorId: z.string().min(1).max(160),
|
|
7
|
+
addressHash: z.string().min(1).max(160),
|
|
8
|
+
bindingId: z.string().min(1).max(160),
|
|
9
|
+
expiresAt: z.number().int().nonnegative(),
|
|
10
|
+
signature: z.base64url().length(43),
|
|
11
|
+
});
|
|
12
|
+
const encoder = new TextEncoder();
|
|
13
|
+
const maxAge = 30_000;
|
|
14
|
+
const input = (proof) => JSON.stringify([
|
|
15
|
+
"oyster:website-visitor:v1",
|
|
16
|
+
proof.bindingId,
|
|
17
|
+
proof.visitorId,
|
|
18
|
+
proof.addressHash,
|
|
19
|
+
proof.expiresAt,
|
|
20
|
+
]);
|
|
21
|
+
async function keyFor(secret) {
|
|
22
|
+
if (encoder.encode(secret).length < 32)
|
|
23
|
+
throw new Error("Website channel proof key is unavailable");
|
|
24
|
+
return crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign", "verify"]);
|
|
25
|
+
}
|
|
26
|
+
/** The edge calls this only after the central visitor owner authenticated
|
|
27
|
+
* this request. Neither bearer nor proof key crosses to the public client. */
|
|
28
|
+
export async function proveVisitor(bindingId, visitor, secret, now = Date.now()) {
|
|
29
|
+
const fields = {
|
|
30
|
+
bindingId,
|
|
31
|
+
visitorId: visitor.visitorId,
|
|
32
|
+
addressHash: visitor.addressHash,
|
|
33
|
+
expiresAt: now + maxAge,
|
|
34
|
+
};
|
|
35
|
+
const bytes = new Uint8Array(await crypto.subtle.sign("HMAC", await keyFor(secret), encoder.encode(input(fields))));
|
|
36
|
+
const signature = btoa(String.fromCharCode(...bytes))
|
|
37
|
+
.replaceAll("+", "-")
|
|
38
|
+
.replaceAll("/", "_")
|
|
39
|
+
.replace(/=+$/u, "");
|
|
40
|
+
return { ...visitor, edgeProof: { ...fields, signature } };
|
|
41
|
+
}
|
|
42
|
+
/** Every public Agent RPC must verify before accessing a conversation or
|
|
43
|
+
* running a model. A forged or stale identity cannot cross the DO boundary. */
|
|
44
|
+
export async function verifyVisitor(bindingId, value, secret, now = Date.now()) {
|
|
45
|
+
const visitor = z
|
|
46
|
+
.strictObject({
|
|
47
|
+
visitorId: z.string().min(1).max(160),
|
|
48
|
+
addressHash: z.string().min(1).max(160),
|
|
49
|
+
expiresAt: z.number().int().nonnegative(),
|
|
50
|
+
edgeProof: proofSchema,
|
|
51
|
+
})
|
|
52
|
+
.safeParse(value);
|
|
53
|
+
if (!visitor.success ||
|
|
54
|
+
secret === null ||
|
|
55
|
+
visitor.data.edgeProof.bindingId !== bindingId ||
|
|
56
|
+
visitor.data.edgeProof.visitorId !== visitor.data.visitorId ||
|
|
57
|
+
visitor.data.edgeProof.addressHash !== visitor.data.addressHash ||
|
|
58
|
+
visitor.data.expiresAt < now ||
|
|
59
|
+
visitor.data.edgeProof.expiresAt < now ||
|
|
60
|
+
visitor.data.edgeProof.expiresAt > now + maxAge)
|
|
61
|
+
throw new Error("Website channel identity is unauthorized");
|
|
62
|
+
const { signature, ...fields } = visitor.data.edgeProof;
|
|
63
|
+
const bytes = Uint8Array.from(atob(signature.replaceAll("-", "+").replaceAll("_", "/") + "="), (char) => char.charCodeAt(0));
|
|
64
|
+
if (!(await crypto.subtle.verify("HMAC", await keyFor(secret), bytes, encoder.encode(input(fields)))))
|
|
65
|
+
throw new Error("Website channel identity is unauthorized");
|
|
66
|
+
return visitor.data;
|
|
67
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Avatar } from "@fungi.computer/sprite/avatar";
|
|
2
|
+
import { type Routes } from "../authorization.js";
|
|
3
|
+
import { type CreateWebsiteInput, type UpdateWebsiteInput, type WebsiteBinding } from "../channels/web-binding.js";
|
|
4
|
+
import type { VisitorSql } from "../channels/visitors.js";
|
|
5
|
+
import type { VisitorSiteFacts } from "../channels/visitor-edge.js";
|
|
6
|
+
import type { WebsiteTranscript } from "@fungi.computer/nacre/website-channels";
|
|
7
|
+
import type { OysterEnv } from "../host.js";
|
|
8
|
+
import { type TenantPrincipal } from "../tenant.js";
|
|
9
|
+
import { agentDirectoryForScope } from "./agent-directory.js";
|
|
10
|
+
import type { StandaloneAgentsEnv } from "./agents.js";
|
|
11
|
+
/** A public site: its binding and the chrome a visitor sees. */
|
|
12
|
+
export type WebsiteSite = Readonly<{
|
|
13
|
+
binding: WebsiteBinding;
|
|
14
|
+
facts: VisitorSiteFacts;
|
|
15
|
+
}>;
|
|
16
|
+
/** The chosen Agent's public face, or null when it is no longer in the directory. */
|
|
17
|
+
export type WebsiteAgentIdentity = Readonly<{
|
|
18
|
+
name: string;
|
|
19
|
+
avatar: Avatar;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* The directory's website owner: bindings and visitor identities on its own
|
|
23
|
+
* store, with the chosen Agent's identity read from the directory itself.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createWebsiteChannelOwner(options: Readonly<{
|
|
26
|
+
sql: VisitorSql;
|
|
27
|
+
transactionSync: <T>(body: () => T) => T;
|
|
28
|
+
agentExists: (agentId: string) => boolean;
|
|
29
|
+
agentIdentity: (agentId: string) => WebsiteAgentIdentity | null;
|
|
30
|
+
}>): {
|
|
31
|
+
bindings: {
|
|
32
|
+
read: (bindingId: string) => WebsiteBinding | null;
|
|
33
|
+
readBySiteKey: (siteKey: string) => WebsiteBinding | null;
|
|
34
|
+
list: () => readonly WebsiteBinding[];
|
|
35
|
+
create: (rawInput: CreateWebsiteInput, requestId: string) => WebsiteBinding;
|
|
36
|
+
update: (bindingId: string, rawInput: UpdateWebsiteInput) => WebsiteBinding;
|
|
37
|
+
};
|
|
38
|
+
visitors: {
|
|
39
|
+
ensure: () => void;
|
|
40
|
+
mint: (binding: import("../channels/binding.js").ConversationBinding | null, siteKey: string, addressHash: string) => Promise<import("../channels/visitors.js").VisitorGrant>;
|
|
41
|
+
refresh: (binding: import("../channels/binding.js").ConversationBinding | null, refreshSecret: string) => Promise<import("../channels/visitors.js").VisitorGrant>;
|
|
42
|
+
authenticate: (bindingId: string, accessToken: string) => Promise<Readonly<{
|
|
43
|
+
visitorId: string;
|
|
44
|
+
expiresAt: number;
|
|
45
|
+
addressHash: string;
|
|
46
|
+
}> | null>;
|
|
47
|
+
live: (bindingId: string, visitorId: string) => boolean;
|
|
48
|
+
forget: (visitorId: string) => void;
|
|
49
|
+
rotate: (binding: import("../channels/binding.js").ConversationBinding | null, siteKey: string, token: string, addressHash: string) => Promise<import("../channels/visitors.js").VisitorGrant | Readonly<{
|
|
50
|
+
kind: "unauthorized";
|
|
51
|
+
}>>;
|
|
52
|
+
};
|
|
53
|
+
/** A public site key resolves only to an active site with a live Agent. */
|
|
54
|
+
site: (siteKey: string) => WebsiteSite | null;
|
|
55
|
+
};
|
|
56
|
+
/** The directory's website owner. */
|
|
57
|
+
export type WebsiteChannelOwner = ReturnType<typeof createWebsiteChannelOwner>;
|
|
58
|
+
/** Why an owner's website command was refused. */
|
|
59
|
+
export type WebsiteRefusal = Readonly<{
|
|
60
|
+
error: "not_granted" | "not_found" | "version_conflict" | "request_conflict" | "invalid_input";
|
|
61
|
+
}>;
|
|
62
|
+
/** Run one binding command, turning its closed failures into data. */
|
|
63
|
+
export declare function websiteOutcome<T>(command: () => T): T | WebsiteRefusal;
|
|
64
|
+
/** The host secrets a website needs; absent or short means the edge is closed. */
|
|
65
|
+
export type StandaloneWebsiteEnv = Pick<StandaloneAgentsEnv, "AGENTS" | "AGENT_DIRECTORY" | "OYSTER_ORIGIN" | "OYSTER_WEBSITE_PROOF_KEY"> & Readonly<{
|
|
66
|
+
/** Host secret (at least 32 bytes) salting the visitor address hash. */
|
|
67
|
+
OYSTER_WEBSITE_ADDRESS_KEY?: string;
|
|
68
|
+
TURNSTILE?: string;
|
|
69
|
+
TURNSTILE_SITE_KEY?: string;
|
|
70
|
+
TURNSTILE_SECRET_KEY?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* The public website surface, on the same paths as Hub's: the launcher, the
|
|
74
|
+
* visitor document and the visitor API. Every visitor request authenticates
|
|
75
|
+
* once here; Agents receive only a signed, short-lived assertion.
|
|
76
|
+
*/
|
|
77
|
+
export declare function standaloneWebsiteApp(): import("hono/hono-base").HonoBase<{
|
|
78
|
+
Bindings: StandaloneWebsiteEnv;
|
|
79
|
+
}, import("hono/types").MergeSchemaPath<import("hono/types").BlankSchema, "/"> | ({
|
|
80
|
+
"/embed/v1.js": {
|
|
81
|
+
$get: {
|
|
82
|
+
input: {};
|
|
83
|
+
output: {};
|
|
84
|
+
outputFormat: string;
|
|
85
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
} & {
|
|
89
|
+
"/embed/widget.js": {
|
|
90
|
+
$get: {
|
|
91
|
+
input: {};
|
|
92
|
+
output: {};
|
|
93
|
+
outputFormat: string;
|
|
94
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
} & {
|
|
98
|
+
"/styles.css": {
|
|
99
|
+
$get: {
|
|
100
|
+
input: {};
|
|
101
|
+
output: {};
|
|
102
|
+
outputFormat: string;
|
|
103
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
}), "/", "/styles.css">;
|
|
107
|
+
/** What the owner's website routes need from the directory and the Agents. */
|
|
108
|
+
export type StandaloneWebsiteControl = Readonly<{
|
|
109
|
+
read: (principal: TenantPrincipal) => Promise<Readonly<{
|
|
110
|
+
embedOrigin: string;
|
|
111
|
+
agents: readonly Readonly<{
|
|
112
|
+
agentId: string;
|
|
113
|
+
name: string;
|
|
114
|
+
}>[];
|
|
115
|
+
websites: readonly WebsiteBinding[];
|
|
116
|
+
}>>;
|
|
117
|
+
create: (principal: TenantPrincipal, input: CreateWebsiteInput, requestId: string) => Promise<WebsiteBinding | WebsiteRefusal>;
|
|
118
|
+
update: (principal: TenantPrincipal, bindingId: string, input: UpdateWebsiteInput) => Promise<WebsiteBinding | WebsiteRefusal>;
|
|
119
|
+
conversations: (principal: TenantPrincipal, bindingId: string) => Promise<readonly Readonly<{
|
|
120
|
+
sessionId: string;
|
|
121
|
+
label: string;
|
|
122
|
+
lastEventAt: number;
|
|
123
|
+
}>[]>;
|
|
124
|
+
transcript: (principal: TenantPrincipal, bindingId: string, sessionId: string) => Promise<WebsiteTranscript | null>;
|
|
125
|
+
}>;
|
|
126
|
+
/** What the owner's website controls need from their host. */
|
|
127
|
+
export type StandaloneWebsiteControlEnv = Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN">;
|
|
128
|
+
/** The owner's website controls over the directory and each website's Agent. */
|
|
129
|
+
export declare function standaloneWebsiteControl(env: StandaloneWebsiteControlEnv, directoryOf: () => ReturnType<typeof agentDirectoryForScope>): StandaloneWebsiteControl;
|
|
130
|
+
/**
|
|
131
|
+
* The owner's website controls. Each route is owner-direct: an App cannot
|
|
132
|
+
* create a public surface, or read what its visitors said, on the owner's behalf.
|
|
133
|
+
*/
|
|
134
|
+
export declare function standaloneWebsiteRoutes(control: StandaloneWebsiteControl): Routes<OysterEnv>;
|