@fungi.computer/oyster 0.10.0 → 0.12.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 +103 -12
- package/dist/agents.d.ts +66 -22
- package/dist/agents.js +128 -38
- package/dist/app-builds.d.ts +2 -0
- package/dist/app-builds.js +17 -6
- 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/build/artifact-writer.d.ts +11 -2
- package/dist/build/artifact-writer.js +42 -24
- package/dist/build/candidate-cli.mjs +26 -18
- package/dist/build/content-objects.d.ts +29 -14
- package/dist/build/content-objects.js +57 -19
- package/dist/build/local-build.js +3 -0
- package/dist/build/submission-contract.d.ts +1 -1
- package/dist/build/submission-contract.js +5 -5
- package/dist/build-egress.d.ts +8 -7
- package/dist/build-egress.js +4 -3
- package/dist/build.d.ts +1 -1
- package/dist/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/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/install-release-cli.d.ts +2 -1
- package/dist/install-release-cli.js +18 -10
- package/dist/installation-client.d.ts +1 -0
- package/dist/installation-operations.d.ts +2 -0
- package/dist/installation-operations.js +1 -0
- package/dist/pack.d.ts +5 -2
- package/dist/pack.js +3 -1
- package/dist/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-connections.d.ts +22 -19
- package/dist/standalone/agent-connections.js +150 -106
- package/dist/standalone/agents.d.ts +174 -16
- package/dist/standalone/agents.js +331 -21
- package/dist/standalone/browser.d.ts +14 -2
- package/dist/standalone/browser.js +52 -4
- package/dist/standalone/channel-session-door.d.ts +4 -0
- package/dist/standalone/channel-session-door.js +72 -0
- package/dist/standalone/computer-egress.d.ts +5 -3
- package/dist/standalone/computer-egress.js +1 -1
- package/dist/standalone/hello-app.d.ts +9 -0
- package/dist/standalone/hello-app.js +78 -0
- package/dist/standalone/install-apps-cli.d.ts +2 -1
- package/dist/standalone/install-apps-cli.js +36 -14
- package/dist/standalone/instance.js +2 -2
- package/dist/standalone/local-desktop.d.ts +11 -0
- package/dist/standalone/local-desktop.js +75 -0
- package/dist/standalone/owner-routes.d.ts +4 -3
- package/dist/standalone/owner-routes.js +7 -1
- package/dist/standalone/registry.d.ts +2 -0
- package/dist/standalone/sign-in-link.d.ts +9 -0
- package/dist/standalone/sign-in-link.js +49 -0
- package/dist/standalone/try-cli.d.ts +52 -0
- package/dist/standalone/try-cli.js +404 -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/website-channels.d.ts +134 -0
- package/dist/standalone/website-channels.js +262 -0
- package/dist/standalone/worker-routes.d.ts +4 -1
- package/dist/standalone/worker-routes.js +3 -0
- package/dist/standalone/worker.d.ts +2 -1
- package/dist/standalone/worker.js +5 -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/webhook-abuse.d.ts +7 -1
- package/dist/webhook-abuse.js +8 -2
- package/dist/workers-git.js +2 -2
- package/dist/workers.d.ts +7 -2
- package/dist/workers.js +1 -1
- package/docs/api/agents.md +103 -36
- package/docs/api/authorization.md +56 -11
- package/docs/api/browser.md +115 -8
- package/docs/api/build-contract.md +52 -10
- package/docs/api/build.md +16 -2
- package/docs/api/host.md +1 -0
- package/docs/api/pack.md +179 -3
- package/docs/api/workers-git.md +6 -6
- package/docs/site/agent-quickstart.mdx +8 -0
- package/package.json +34 -8
|
@@ -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>;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standalone website channel: an owner puts a chat with one of their
|
|
3
|
+
* Agents on a separate website. The directory owns the bindings and the
|
|
4
|
+
* anonymous visitor identities; each website is served by a dedicated Agent
|
|
5
|
+
* instance (never the owner's own Agent), and the public edge authenticates a
|
|
6
|
+
* visitor once before any Agent is selected.
|
|
7
|
+
*/
|
|
8
|
+
import { Hono } from "hono";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { owner, routes } from "../authorization.js";
|
|
13
|
+
import { createWebsiteBindings, createWebsiteInputSchema, updateWebsiteInputSchema, WebsiteBindingError, } from "../channels/web-binding.js";
|
|
14
|
+
import { createChannelVisitors } from "../channels/visitors.js";
|
|
15
|
+
import { readTurnstileConfiguration } from "../turnstile.js";
|
|
16
|
+
import { tenantScope, defaultTenant } from "../tenant.js";
|
|
17
|
+
import { agentDirectoryForScope } from "./agent-directory.js";
|
|
18
|
+
import { standaloneVisitorEdge } from "./visitor-edge.js";
|
|
19
|
+
/**
|
|
20
|
+
* The directory's website owner: bindings and visitor identities on its own
|
|
21
|
+
* store, with the chosen Agent's identity read from the directory itself.
|
|
22
|
+
*/
|
|
23
|
+
export function createWebsiteChannelOwner(options) {
|
|
24
|
+
const bindings = createWebsiteBindings(options);
|
|
25
|
+
const visitors = createChannelVisitors({
|
|
26
|
+
sql: options.sql,
|
|
27
|
+
transactionSync: options.transactionSync,
|
|
28
|
+
now: () => Date.now(),
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
bindings,
|
|
32
|
+
visitors,
|
|
33
|
+
/** A public site key resolves only to an active site with a live Agent. */
|
|
34
|
+
site: (siteKey) => {
|
|
35
|
+
const binding = bindings.readBySiteKey(siteKey);
|
|
36
|
+
if (binding === null)
|
|
37
|
+
return null;
|
|
38
|
+
const agent = options.agentIdentity(binding.agentId);
|
|
39
|
+
if (agent === null)
|
|
40
|
+
return null;
|
|
41
|
+
const { origins, accent, turnstile } = binding.selector;
|
|
42
|
+
const facts = { ...agent, origins };
|
|
43
|
+
if (accent !== undefined)
|
|
44
|
+
facts.accent = accent;
|
|
45
|
+
if (turnstile === true)
|
|
46
|
+
facts.turnstile = true;
|
|
47
|
+
return { binding, facts };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Run one binding command, turning its closed failures into data. */
|
|
52
|
+
export function websiteOutcome(command) {
|
|
53
|
+
try {
|
|
54
|
+
return command();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof WebsiteBindingError)
|
|
58
|
+
return { error: error.code };
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The website channel is not configured on this Oyster. */
|
|
63
|
+
class WebsiteConfigurationError extends Error {
|
|
64
|
+
constructor() {
|
|
65
|
+
super("Website channel host secrets are unavailable or invalid");
|
|
66
|
+
this.name = "WebsiteConfigurationError";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const hostKeySchema = z
|
|
70
|
+
.string()
|
|
71
|
+
.refine((value) => new TextEncoder().encode(value).byteLength >= 32);
|
|
72
|
+
function hostKey(value) {
|
|
73
|
+
const parsed = hostKeySchema.safeParse(value);
|
|
74
|
+
if (!parsed.success)
|
|
75
|
+
throw new WebsiteConfigurationError();
|
|
76
|
+
return parsed.data;
|
|
77
|
+
}
|
|
78
|
+
/** Rate-limit key: the client address hashed under a daily-rotating salt. */
|
|
79
|
+
async function addressHash(env, address) {
|
|
80
|
+
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(hostKey(env.OYSTER_WEBSITE_ADDRESS_KEY)), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
81
|
+
const day = new Date().toISOString().slice(0, 10);
|
|
82
|
+
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${day}:${address ?? "unknown"}`));
|
|
83
|
+
return Array.from(new Uint8Array(signature).slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
84
|
+
}
|
|
85
|
+
const defaultDirectory = (env) => agentDirectoryForScope(env, tenantScope(defaultTenant, env.OYSTER_ORIGIN));
|
|
86
|
+
const embedAssets = async () => import("#embed-scripts");
|
|
87
|
+
const scriptHeaders = {
|
|
88
|
+
"content-type": "text/javascript; charset=utf-8",
|
|
89
|
+
"cache-control": "public, max-age=300",
|
|
90
|
+
"x-content-type-options": "nosniff",
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The public website surface, on the same paths as Hub's: the launcher, the
|
|
94
|
+
* visitor document and the visitor API. Every visitor request authenticates
|
|
95
|
+
* once here; Agents receive only a signed, short-lived assertion.
|
|
96
|
+
*/
|
|
97
|
+
export function standaloneWebsiteApp() {
|
|
98
|
+
const resolve = (context) => context.env;
|
|
99
|
+
const edge = standaloneVisitorEdge({
|
|
100
|
+
site: (context, siteKey) => defaultDirectory(resolve(context)).websiteSite(siteKey),
|
|
101
|
+
visitors: (context) => {
|
|
102
|
+
const directory = defaultDirectory(resolve(context));
|
|
103
|
+
return {
|
|
104
|
+
mint: (site, siteKey, address) => directory.websiteMint(site?.bindingId ?? "", siteKey, address),
|
|
105
|
+
refresh: (site, secret) => directory.websiteRefresh(site?.bindingId ?? "", secret),
|
|
106
|
+
rotate: (site, siteKey, token, address) => directory.websiteRotate(site?.bindingId ?? "", siteKey, token, address),
|
|
107
|
+
authenticate: (bindingId, token) => directory.websiteAuthenticate(bindingId, token),
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
// Visitors reach the chosen Agent itself, with its own tools.
|
|
111
|
+
agent: (context, binding) => resolve(context).AGENTS.getByName(binding.agentId),
|
|
112
|
+
proofKey: (context) => hostKey(resolve(context).OYSTER_WEBSITE_PROOF_KEY),
|
|
113
|
+
addressHash: (context) => addressHash(resolve(context), context.req.header("cf-connecting-ip")),
|
|
114
|
+
turnstile: (context) => {
|
|
115
|
+
const env = resolve(context);
|
|
116
|
+
return {
|
|
117
|
+
configuration: readTurnstileConfiguration(env, env.OYSTER_ORIGIN),
|
|
118
|
+
timeoutMs: 5_000,
|
|
119
|
+
onError: (cause) => {
|
|
120
|
+
console.error("website turnstile verification failed", cause);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
assetPath: (kind) => kind === "widget" ? "/embed/widget.js" : "/styles.css",
|
|
125
|
+
onError: (error, context) => {
|
|
126
|
+
if (error instanceof WebsiteConfigurationError)
|
|
127
|
+
return context.json({ error: "website_unavailable" }, 503);
|
|
128
|
+
console.error(error);
|
|
129
|
+
return context.json({ error: "internal" }, 500);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return new Hono()
|
|
133
|
+
.get("/embed/v1.js", async () => {
|
|
134
|
+
const { embedLoaderScript } = await embedAssets();
|
|
135
|
+
return new Response(embedLoaderScript, { headers: scriptHeaders });
|
|
136
|
+
})
|
|
137
|
+
.get("/embed/widget.js", async () => {
|
|
138
|
+
const { embedWidgetScript } = await embedAssets();
|
|
139
|
+
return new Response(embedWidgetScript, { headers: scriptHeaders });
|
|
140
|
+
})
|
|
141
|
+
.get("/styles.css", async () => {
|
|
142
|
+
const { embedStyles } = await embedAssets();
|
|
143
|
+
return new Response(embedStyles, {
|
|
144
|
+
headers: {
|
|
145
|
+
"content-type": "text/css; charset=utf-8",
|
|
146
|
+
"cache-control": "public, max-age=300",
|
|
147
|
+
"x-content-type-options": "nosniff",
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
})
|
|
151
|
+
.route("/", edge);
|
|
152
|
+
}
|
|
153
|
+
/** The owner's website controls over the directory and each website's Agent. */
|
|
154
|
+
export function standaloneWebsiteControl(env, directoryOf) {
|
|
155
|
+
// Only a binding the directory knows names an Agent whose conversations are read.
|
|
156
|
+
const agentOf = async (principal, bindingId) => {
|
|
157
|
+
const listed = await directoryOf().websiteList(principal);
|
|
158
|
+
const binding = "error" in listed
|
|
159
|
+
? undefined
|
|
160
|
+
: listed.find((item) => item.bindingId === bindingId);
|
|
161
|
+
return binding === undefined ? null : env.AGENTS.getByName(binding.agentId);
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
read: async (principal) => {
|
|
165
|
+
const listed = await directoryOf().websiteList(principal);
|
|
166
|
+
return {
|
|
167
|
+
embedOrigin: env.OYSTER_ORIGIN,
|
|
168
|
+
agents: (await directoryOf().list()).map(({ agentId, name }) => ({
|
|
169
|
+
agentId,
|
|
170
|
+
name,
|
|
171
|
+
})),
|
|
172
|
+
websites: "error" in listed ? [] : listed,
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
create: (principal, input, requestId) => directoryOf().websiteCreate(principal, input, requestId),
|
|
176
|
+
update: (principal, bindingId, input) => directoryOf().websiteUpdate(principal, bindingId, input),
|
|
177
|
+
conversations: async (principal, bindingId) => {
|
|
178
|
+
const agent = await agentOf(principal, bindingId);
|
|
179
|
+
return agent === null
|
|
180
|
+
? []
|
|
181
|
+
: (await agent.websiteConversations(bindingId)).map(({ sessionId, label, lastEventAt }) => ({
|
|
182
|
+
sessionId,
|
|
183
|
+
label,
|
|
184
|
+
lastEventAt,
|
|
185
|
+
}));
|
|
186
|
+
},
|
|
187
|
+
transcript: async (principal, bindingId, sessionId) => {
|
|
188
|
+
const agent = await agentOf(principal, bindingId);
|
|
189
|
+
return agent === null
|
|
190
|
+
? null
|
|
191
|
+
: agent.websiteTranscript(bindingId, sessionId);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const refusalStatus = {
|
|
196
|
+
not_granted: 403,
|
|
197
|
+
not_found: 404,
|
|
198
|
+
version_conflict: 409,
|
|
199
|
+
request_conflict: 409,
|
|
200
|
+
invalid_input: 400,
|
|
201
|
+
};
|
|
202
|
+
function refused(value) {
|
|
203
|
+
return "error" in value;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The owner's website controls. Each route is owner-direct: an App cannot
|
|
207
|
+
* create a public surface, or read what its visitors said, on the owner's behalf.
|
|
208
|
+
*/
|
|
209
|
+
export function standaloneWebsiteRoutes(control) {
|
|
210
|
+
const table = routes();
|
|
211
|
+
// A body that is not JSON is a malformed request, not a thrown failure.
|
|
212
|
+
const parseBody = async (context) => {
|
|
213
|
+
const decoded = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json))(await context.req.text());
|
|
214
|
+
return Option.isSome(decoded)
|
|
215
|
+
? { ok: true, value: decoded.value }
|
|
216
|
+
: { ok: false };
|
|
217
|
+
};
|
|
218
|
+
table.get("/api/websites", owner("direct"), async (context, { principal }) => {
|
|
219
|
+
context.header("Cache-Control", "no-store");
|
|
220
|
+
return context.json(await control.read(principal));
|
|
221
|
+
});
|
|
222
|
+
table.post("/api/websites", owner("direct"), async (context, { principal }) => {
|
|
223
|
+
context.header("Cache-Control", "no-store");
|
|
224
|
+
const body = await parseBody(context);
|
|
225
|
+
if (!body.ok)
|
|
226
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
227
|
+
const parsed = createWebsiteInputSchema.safeParse(body.value);
|
|
228
|
+
if (!parsed.success)
|
|
229
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
230
|
+
const result = await control.create(principal, parsed.data, context.req.header("x-request-id") ?? "");
|
|
231
|
+
return refused(result)
|
|
232
|
+
? context.json(result, refusalStatus[result.error])
|
|
233
|
+
: context.json({ binding: result }, 201);
|
|
234
|
+
});
|
|
235
|
+
table.put("/api/websites/:bindingId", owner("direct"), async (context, { principal }) => {
|
|
236
|
+
context.header("Cache-Control", "no-store");
|
|
237
|
+
const body = await parseBody(context);
|
|
238
|
+
if (!body.ok)
|
|
239
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
240
|
+
const parsed = updateWebsiteInputSchema.safeParse(body.value);
|
|
241
|
+
if (!parsed.success)
|
|
242
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
243
|
+
const result = await control.update(principal, context.req.param("bindingId"), parsed.data);
|
|
244
|
+
return refused(result)
|
|
245
|
+
? context.json(result, refusalStatus[result.error])
|
|
246
|
+
: context.json({ binding: result });
|
|
247
|
+
});
|
|
248
|
+
table.get("/api/websites/:bindingId/conversations", owner("direct"), async (context, { principal }) => {
|
|
249
|
+
context.header("Cache-Control", "no-store");
|
|
250
|
+
return context.json({
|
|
251
|
+
conversations: await control.conversations(principal, context.req.param("bindingId")),
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
table.get("/api/websites/:bindingId/conversations/:sessionId", owner("direct"), async (context, { principal }) => {
|
|
255
|
+
context.header("Cache-Control", "no-store");
|
|
256
|
+
const transcript = await control.transcript(principal, context.req.param("bindingId"), context.req.param("sessionId"));
|
|
257
|
+
return transcript === null
|
|
258
|
+
? context.json({ error: "not_found" }, 404)
|
|
259
|
+
: context.json(transcript);
|
|
260
|
+
});
|
|
261
|
+
return table;
|
|
262
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The standalone Worker's top-level table, before any tenant is selected:
|
|
3
|
-
* device enrollment and links,
|
|
3
|
+
* device enrollment and links, the public website visitor surface, attached-machine
|
|
4
|
+
* dials, signed Workflow webhook delivery, then the
|
|
4
5
|
* selected tenant's own declared host table for every other path. The Worker
|
|
5
6
|
* and the authorization law both compose it here.
|
|
6
7
|
*/
|
|
@@ -10,6 +11,8 @@ import { type Routes } from "../authorization.js";
|
|
|
10
11
|
export type StandaloneWorkerRoutePorts = Readonly<{
|
|
11
12
|
/** The machine-link doors' own table, served for this request. */
|
|
12
13
|
machineLink: (request: Request) => Promise<Response>;
|
|
14
|
+
/** The public website channel: launcher, visitor document and visitor API. */
|
|
15
|
+
website: (request: Request) => Promise<Response>;
|
|
13
16
|
/** A machine's signed dial to its attached Computer, verified by that Computer. */
|
|
14
17
|
localBackendDial: (request: Request) => Promise<Response>;
|
|
15
18
|
/** Signed Workflow webhook delivery, verified by the library's run owner. */
|
|
@@ -4,6 +4,9 @@ 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("/embed/*", door("a website visitor; the edge checks the site key and origin"), (context) => ports.website(context.req.raw))
|
|
8
|
+
.all("/styles.css", door("the website chat's public stylesheet"), (context) => ports.website(context.req.raw))
|
|
9
|
+
.all("/api/embed/*", door("a website visitor; the edge checks the site key, origin and bearer"), (context) => ports.website(context.req.raw))
|
|
7
10
|
.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))
|
|
8
11
|
.include(ports.workflowWebhooks)
|
|
9
12
|
.all("*", door("the selected tenant's own declared host table"), (context) => ports.tenant(context.req.raw));
|
|
@@ -16,12 +16,13 @@ import { type StandaloneTenancyEnv } from "./tenancy.js";
|
|
|
16
16
|
export { StandaloneTenants } from "./tenancy.js";
|
|
17
17
|
import { type StandaloneMachineLinkBindings } from "./machine-link.js";
|
|
18
18
|
export { MachineLinkDO } from "./machine-link.js";
|
|
19
|
+
import { type StandaloneWebsiteEnv } from "./website-channels.js";
|
|
19
20
|
import { type OysterComputerEgressProps } from "./computer-egress.js";
|
|
20
21
|
import type { AppSourceBindingEnv } from "./app-source.js";
|
|
21
22
|
export { StandaloneGraphWorkflow } from "./workflows.js";
|
|
22
23
|
export { MediaOperationDO } from "@fungi.computer/darkroom/cloudflare";
|
|
23
24
|
/** Every binding the standalone Bonsai root receives. */
|
|
24
|
-
export type StandaloneEnv = OysterGitWorkerEnv & StandaloneTenancyEnv & StandaloneComputerEnv & StandaloneAgentsEnv & StandaloneMachineLinkBindings & OysterMediaEnv & StandaloneWorkflowEnv & AppSourceBindingEnv & {
|
|
25
|
+
export type StandaloneEnv = OysterGitWorkerEnv & StandaloneTenancyEnv & StandaloneComputerEnv & StandaloneAgentsEnv & StandaloneWebsiteEnv & StandaloneMachineLinkBindings & OysterMediaEnv & StandaloneWorkflowEnv & AppSourceBindingEnv & {
|
|
25
26
|
OYSTER_HOME_INSTALLATION: string;
|
|
26
27
|
/** `disabled` closes the Computer's public download lane. */
|
|
27
28
|
COMPUTER_PUBLIC_EGRESS?: string;
|
|
@@ -31,6 +31,7 @@ import { serveDoors } from "../authorization.js";
|
|
|
31
31
|
import { standaloneWorkerRoutes } from "./worker-routes.js";
|
|
32
32
|
import { HTTPException } from "hono/http-exception";
|
|
33
33
|
import { standaloneOwnerRoutes } from "./owner-routes.js";
|
|
34
|
+
import { standaloneWebsiteApp, } from "./website-channels.js";
|
|
34
35
|
import { standaloneComputerSelection } from "./computer-fleet.js";
|
|
35
36
|
import { serveOysterComputerEgress, } from "./computer-egress.js";
|
|
36
37
|
export { StandaloneGraphWorkflow } from "./workflows.js";
|
|
@@ -150,7 +151,7 @@ export class OysterComputerEgress extends WorkerEntrypoint {
|
|
|
150
151
|
admitObject: (jobId, grant) => registry.admitBuildObject(jobId, computerObjectId, grant),
|
|
151
152
|
// The bytes stream from the Computer to R2, which checks the digest;
|
|
152
153
|
// the registry only admits the upload and later reads the facts.
|
|
153
|
-
storeObject: (object, body, mediaType) => putContentObject(this.env.RELEASES, object,
|
|
154
|
+
storeObject: (object, body, mediaType, owner) => putContentObject(this.env.RELEASES, owner, object,
|
|
154
155
|
// R2 takes a stream of known length; the stated length is exact.
|
|
155
156
|
body?.pipeThrough(new FixedLengthStream(object.byteLength)) ?? null, mediaType),
|
|
156
157
|
submitCandidate: (jobId, manifest, grant, credentialId) => registry.submitBuildCandidate(jobId, manifest, grant, credentialId),
|
|
@@ -161,6 +162,8 @@ export class OysterComputerEgress extends WorkerEntrypoint {
|
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
/** The public website channel: one edge, authenticated per request. */
|
|
166
|
+
const website = standaloneWebsiteApp();
|
|
164
167
|
const standaloneWorkerErrorHandler = (error, context) => {
|
|
165
168
|
if (error instanceof StandaloneSeedConfigurationChanged) {
|
|
166
169
|
const { refusal } = error;
|
|
@@ -189,6 +192,7 @@ export default {
|
|
|
189
192
|
// tenant host's own declared table.
|
|
190
193
|
return serveDoors(standaloneWorkerRoutes({
|
|
191
194
|
machineLink: (incoming) => serveDoors(standaloneMachineLinkRoutes(env).onError(standaloneWorkerErrorHandler)).fetch(incoming, env, context),
|
|
195
|
+
website: (incoming) => Promise.resolve(website.fetch(incoming, env, context)),
|
|
192
196
|
localBackendDial: async (incoming) => {
|
|
193
197
|
const dial = ownerLocalBackendDialPath.exec(new URL(incoming.url).pathname);
|
|
194
198
|
// Only a Computer this Oyster owns is addressed; no stray object is made.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AppCapabilityId } from "@fungi.computer/puffball/app";
|
|
2
2
|
import { type OysterAgents } from "../agents.js";
|
|
3
3
|
import type { LiveOysterKey } from "../keys.js";
|
|
4
|
+
import type { ResourceRef } from "../apps/index.js";
|
|
4
5
|
import { type FileSource } from "../files.js";
|
|
5
6
|
import { type OysterAuthResult, type OysterCapability } from "../host.js";
|
|
6
7
|
/** How one capability fixture host admits its single installation. */
|
|
@@ -13,6 +14,8 @@ export type CapabilityFixtureOptions = Readonly<{
|
|
|
13
14
|
adapters?: readonly OysterCapability[];
|
|
14
15
|
/** Grant the file adapters over this source instead of the probe. */
|
|
15
16
|
fileSource?: FileSource;
|
|
17
|
+
/** Capabilities the owner narrowed to exactly these resources. */
|
|
18
|
+
selected?: Partial<Record<AppCapabilityId, readonly ResourceRef[]>>;
|
|
16
19
|
/** `false` clears the owner's approval after install. */
|
|
17
20
|
admitted?: boolean;
|
|
18
21
|
authenticate?: (request: Request) => Promise<OysterAuthResult>;
|
|
@@ -70,6 +70,7 @@ export async function capabilityFixture(options = {}) {
|
|
|
70
70
|
release: declaredRelease,
|
|
71
71
|
declaration: declaration ?? emptyAppDeclaration,
|
|
72
72
|
descriptors: capabilities,
|
|
73
|
+
selected: options.selected ?? {},
|
|
73
74
|
});
|
|
74
75
|
if (options.admitted === false)
|
|
75
76
|
installation = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppDeclaration } from "@fungi.computer/puffball/app";
|
|
2
|
-
import { type CapabilityOperationDescriptor, type Installation } from "../apps/index.js";
|
|
1
|
+
import type { AppCapabilityId, AppDeclaration } from "@fungi.computer/puffball/app";
|
|
2
|
+
import { type CapabilityOperationDescriptor, type Installation, type ResourceRef } from "../apps/index.js";
|
|
3
3
|
/** Build fixture state through the same approval owner used by installation routes. */
|
|
4
4
|
export declare function approvedInstallation(input: Readonly<{
|
|
5
5
|
release: Installation["release"];
|
|
@@ -7,4 +7,6 @@ export declare function approvedInstallation(input: Readonly<{
|
|
|
7
7
|
installationId: string;
|
|
8
8
|
instanceId: Installation["instanceId"];
|
|
9
9
|
descriptors?: readonly CapabilityOperationDescriptor[];
|
|
10
|
+
/** Narrow these capabilities to exactly these resources, as the owner's picker does. */
|
|
11
|
+
selected?: Partial<Record<AppCapabilityId, readonly ResourceRef[]>>;
|
|
10
12
|
}>): Promise<Installation>;
|
|
@@ -23,11 +23,16 @@ export async function approvedInstallation(input) {
|
|
|
23
23
|
throw new Error(result.failure.code);
|
|
24
24
|
const installed = result.success.next;
|
|
25
25
|
const declaredOperations = await deriveDeclaredOperations(input.release, input.declaration, input.descriptors ?? []);
|
|
26
|
+
const selected = input.selected ?? {};
|
|
26
27
|
const changes = declaredOperations.capabilities
|
|
27
|
-
.filter(({ capability }) => permissionCatalog[capability].consent === "ask"
|
|
28
|
+
.filter(({ capability }) => permissionCatalog[capability].consent === "ask" ||
|
|
29
|
+
selected[capability] !== undefined)
|
|
28
30
|
.map(({ capability, operations }) => ({
|
|
29
31
|
capability,
|
|
30
|
-
grant: {
|
|
32
|
+
grant: {
|
|
33
|
+
operations,
|
|
34
|
+
resources: selected[capability] ?? "tenant-scope",
|
|
35
|
+
},
|
|
31
36
|
}));
|
|
32
37
|
if (changes.length === 0)
|
|
33
38
|
return installed;
|
package/dist/webhook-abuse.d.ts
CHANGED
|
@@ -18,7 +18,13 @@ export declare function workflowWebhookAbuse(options: {
|
|
|
18
18
|
hostConcurrency: number;
|
|
19
19
|
bindingConcurrency: number;
|
|
20
20
|
};
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Per-instance streaming bound; durable run concurrency belongs to Braid.
|
|
23
|
+
* The rate key carries the tenant: a multi-tenant host (the Hub) serves
|
|
24
|
+
* every Team on one origin, and this lease is spent before any signature
|
|
25
|
+
* check, so a shared key would let one tenant's unauthenticated traffic
|
|
26
|
+
* refuse every other tenant's deliveries.
|
|
27
|
+
*/
|
|
22
28
|
hostLease(): Promise<null | (() => void)>;
|
|
23
29
|
bindingAdmission(bindingId: string): Promise<boolean>;
|
|
24
30
|
};
|
package/dist/webhook-abuse.js
CHANGED
|
@@ -21,12 +21,18 @@ export function workflowWebhookAbuse(options) {
|
|
|
21
21
|
let active = 0;
|
|
22
22
|
return {
|
|
23
23
|
concurrency,
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Per-instance streaming bound; durable run concurrency belongs to Braid.
|
|
26
|
+
* The rate key carries the tenant: a multi-tenant host (the Hub) serves
|
|
27
|
+
* every Team on one origin, and this lease is spent before any signature
|
|
28
|
+
* check, so a shared key would let one tenant's unauthenticated traffic
|
|
29
|
+
* refuse every other tenant's deliveries.
|
|
30
|
+
*/
|
|
25
31
|
async hostLease() {
|
|
26
32
|
if (active >= concurrency.hostConcurrency)
|
|
27
33
|
return null;
|
|
28
34
|
const { success } = await options.hostRate.limit({
|
|
29
|
-
key: rateKey([
|
|
35
|
+
key: rateKey([...prefix, "host"]),
|
|
30
36
|
});
|
|
31
37
|
// Native admission awaits I/O; simultaneous successful replies still
|
|
32
38
|
// cannot overbook the local streaming ceiling.
|
package/dist/workers-git.js
CHANGED
|
@@ -21,7 +21,7 @@ import { parseAppMethodCallContext, workflowAttestationSchema, } from "@fungi.co
|
|
|
21
21
|
import { lsRefsRequest, parseLsRefs, } from "./git.js";
|
|
22
22
|
import { createKeyStore, keyWire, } from "@fungi.computer/ear-tag/keys";
|
|
23
23
|
import { oysterKeyVocabulary, } from "./keys.js";
|
|
24
|
-
import { agentCapabilities, agentApprovalRoutes,
|
|
24
|
+
import { agentCapabilities, agentApprovalRoutes, connectionRoutes, modelKeyRoutes, } from "./agents.js";
|
|
25
25
|
import { createArtifactsRestNamespace, } from "@fungi.computer/burrow";
|
|
26
26
|
import { attemptWebhook } from "./webhook-delivery.js";
|
|
27
27
|
import { createRecipientDeliveries, } from "./event-recipients.js";
|
|
@@ -1169,7 +1169,7 @@ export function oysterGitOwnerRoutes(env, scope, hostOwnerRoutes, agents) {
|
|
|
1169
1169
|
ownerRoutes.include(hostOwnerRoutes);
|
|
1170
1170
|
if (agents !== undefined) {
|
|
1171
1171
|
ownerRoutes.include(agentApprovalRoutes(agents));
|
|
1172
|
-
ownerRoutes.include(
|
|
1172
|
+
ownerRoutes.include(connectionRoutes(agents));
|
|
1173
1173
|
ownerRoutes.include(modelKeyRoutes(agents));
|
|
1174
1174
|
}
|
|
1175
1175
|
return ownerRoutes;
|
package/dist/workers.d.ts
CHANGED
|
@@ -260,8 +260,13 @@ export type OysterBindingContext<Env> = Readonly<{
|
|
|
260
260
|
*/
|
|
261
261
|
export type OysterBindingRow<Env> = Readonly<{
|
|
262
262
|
methods: Readonly<Record<string, FrameBindingMethod<OysterBindingResult>>>;
|
|
263
|
-
/**
|
|
264
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Serve one decoded packet; the Instance has already admitted its frame and
|
|
265
|
+
* grant. `admitted` is the installation that packet's one Registry read
|
|
266
|
+
* re-admitted: its approved grants are the resource ceiling a row applies
|
|
267
|
+
* to results no single `requestedResource` selects.
|
|
268
|
+
*/
|
|
269
|
+
dispatch(context: OysterBindingContext<Env>, frame: InvocationFrame<OysterInvocationHost>, props: FrameBindingProps, method: string, args: readonly unknown[], admitted: Installation): Promise<OysterBindingResult>;
|
|
265
270
|
}>;
|
|
266
271
|
/**
|
|
267
272
|
* The bindings an Instance serves, keyed by the closed App binding vocabulary;
|
package/dist/workers.js
CHANGED
|
@@ -807,7 +807,7 @@ export class OysterInstance extends DurableObject {
|
|
|
807
807
|
if (!required.every((operation) => selected.includes(operation)))
|
|
808
808
|
throw new AppInstanceError("binding_not_granted");
|
|
809
809
|
}
|
|
810
|
-
const result = await row.dispatch(this.#bindingContext, frame, props, method, args);
|
|
810
|
+
const result = await row.dispatch(this.#bindingContext, frame, props, method, args, current);
|
|
811
811
|
if (this.frames.active(props.frameId) !== frame)
|
|
812
812
|
throw new AppInstanceError("revoked");
|
|
813
813
|
assertBackgroundBinding(frame, props.binding);
|