@fungi.computer/oyster 0.26.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents.d.ts +24 -8
- package/dist/agents.js +12 -5
- package/dist/apps/catalog.js +1 -1
- package/dist/boot-host-script.js +1 -1
- package/dist/build/candidate-cli.mjs +6 -0
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +1 -1
- package/dist/hello-app-script.js +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1 -0
- package/dist/page-script.js +2 -2
- package/dist/standalone/agent-computers.js +17 -1
- package/dist/standalone/agents.d.ts +16 -8
- package/dist/standalone/agents.js +77 -24
- package/dist/standalone/app-set.d.ts +7 -0
- package/dist/standalone/app-set.js +17 -3
- package/dist/standalone/computer-fleet.d.ts +1 -0
- package/dist/standalone/computer-fleet.js +9 -1
- package/dist/standalone/computer.d.ts +26 -3
- package/dist/standalone/computer.js +32 -1
- package/dist/standalone/install-apps-cli.js +8 -2
- package/dist/standalone/media.d.ts +8 -3
- package/dist/standalone/media.js +76 -7
- package/dist/standalone/registry.d.ts +5 -1
- package/dist/standalone/registry.js +9 -0
- package/docs/api/agents.md +204 -214
- package/docs/api/apps.md +33 -33
- package/docs/api/media.md +4 -0
- package/docs/api/workers-git.md +7 -7
- package/examples/standalone/wrangler.jsonc +3 -0
- package/package.json +19 -23
- package/dist/agent-instructions.d.ts +0 -35
- package/dist/agent-instructions.js +0 -42
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createComputerFilesPort } from "@fungi.computer/computer";
|
|
2
2
|
import { checkComputerGrant, FleetGrantRefused, } from "@fungi.computer/computer/fleet";
|
|
3
|
-
import { computerCapabilities, computerValueSchema, } from "@fungi.computer/computer-contract";
|
|
3
|
+
import { ComputerCommandTooLongError, computerCapabilities, computerValueSchema, parseComputerExecInput, } from "@fungi.computer/computer-contract";
|
|
4
|
+
import { CapabilityFailed, } from "@fungi.computer/mycelium";
|
|
4
5
|
import { attachComputerInputSchema, detachComputerInputSchema, readAgentComputersInputSchema, } from "../agent-computers.js";
|
|
5
6
|
import {} from "../host.js";
|
|
6
7
|
import { owner, routes as routeTable } from "../authorization.js";
|
|
@@ -80,6 +81,21 @@ export function standaloneAgentComputerPorts(access, connection) {
|
|
|
80
81
|
},
|
|
81
82
|
call: async (capabilityId, input, context) => {
|
|
82
83
|
context.signal.throwIfAborted();
|
|
84
|
+
if (capabilityId === "bash" || capabilityId === "exec") {
|
|
85
|
+
try {
|
|
86
|
+
parseComputerExecInput(input);
|
|
87
|
+
}
|
|
88
|
+
catch (cause) {
|
|
89
|
+
// The refusal is the owner's own words to the person and the model.
|
|
90
|
+
if (cause instanceof ComputerCommandTooLongError)
|
|
91
|
+
throw new CapabilityFailed({
|
|
92
|
+
namespace: "computer",
|
|
93
|
+
operation: capabilityId,
|
|
94
|
+
cause: { kind: "OperationFailed", message: cause.message },
|
|
95
|
+
});
|
|
96
|
+
throw cause;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
83
99
|
// tool() retains the native advertised-operation/action mapping and decoders.
|
|
84
100
|
const grant = await access.admit(connection);
|
|
85
101
|
context.signal.throwIfAborted();
|
|
@@ -22,7 +22,7 @@ import { type AgentComputerSnapshot, type AgentComputerConnection } from "../age
|
|
|
22
22
|
import { type StandaloneAgentComputerReply } from "./agent-computers.js";
|
|
23
23
|
import { type ComputerGrant } from "@fungi.computer/computer/fleet";
|
|
24
24
|
import { DurableObject } from "cloudflare:workers";
|
|
25
|
-
import type
|
|
25
|
+
import { type StandaloneComputerEnv } from "./computer.js";
|
|
26
26
|
import { ShiitakeDO } from "@fungi.computer/shiitake/cloudflare";
|
|
27
27
|
import { type ModelKeyRecord, type ModelKeyRefusal, type ModelKeySealInput } from "./model-key-vault.js";
|
|
28
28
|
import type { CloudflareShiitakeOptions } from "@fungi.computer/shiitake/cloudflare";
|
|
@@ -43,7 +43,7 @@ import type { HostActor } from "@fungi.computer/puffball/app";
|
|
|
43
43
|
import type { OysterWorkerEnv } from "../workers.js";
|
|
44
44
|
import type { ConnectionAccess, ConnectionInput } from "../agents.js";
|
|
45
45
|
import type { EgressRef, McpRequestData } from "@fungi.computer/veil/connections";
|
|
46
|
-
import type { AgentPolicyActor, OysterAgents, OysterSessionRow } from "../agents.js";
|
|
46
|
+
import type { OysterAgentInstructions, AgentPolicyActor, OysterAgents, OysterSessionRow } from "../agents.js";
|
|
47
47
|
/** The model door an agent runs on; Shiitake's own contract. */
|
|
48
48
|
export type StandaloneModelSource = CloudflareShiitakeOptions["model"];
|
|
49
49
|
/** One directory entry: an agent's id, display name and own avatar. */
|
|
@@ -268,12 +268,20 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
268
268
|
/** A byok choice must name a stored key of the chosen provider. */
|
|
269
269
|
private admitKey;
|
|
270
270
|
private choice;
|
|
271
|
-
|
|
272
|
-
private
|
|
273
|
-
/**
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
271
|
+
/** Which Home this Agent uses: its recorded choice, else its only attachment. */
|
|
272
|
+
private homeComputer;
|
|
273
|
+
/**
|
|
274
|
+
* The AGENTS.md on this Agent's Home Computer. The host admits the owner
|
|
275
|
+
* first; `actor` names who the Computer's grant records.
|
|
276
|
+
*/
|
|
277
|
+
readInstructions(actor: string): Promise<OysterAgentInstructions>;
|
|
278
|
+
/**
|
|
279
|
+
* Replace it only if it still holds what the owner read; null creates it only
|
|
280
|
+
* while absent. The next run follows the new text; a run already going does not.
|
|
281
|
+
*/
|
|
282
|
+
replaceInstructions(actor: string, expectedContent: string | null, content: string): Promise<OysterAgentInstructions | Readonly<{
|
|
283
|
+
error: "conflict" | "too_large" | "no_home";
|
|
284
|
+
}>>;
|
|
277
285
|
/** Secret-free default of this Agent; stored separately from Session history. */
|
|
278
286
|
readModelChoice(): Promise<AgentModelChoice>;
|
|
279
287
|
setModelChoice(input: AgentModelChoice): Promise<AgentModelChoice | Readonly<{
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { agentCodeExecutionTimeoutMs } from "@fungi.computer/computer-contract";
|
|
1
2
|
import { isRetryableProviderRejection, normalizeModel, observeProviderStatus, streamModel, } from "@fungi.computer/mule/effect";
|
|
2
3
|
import { standaloneTenancy, } from "./tenancy.js";
|
|
3
|
-
import { AcceptedSchema } from "@fungi.computer/shiitake/client";
|
|
4
|
+
import { AcceptedSchema, bindSessionExtension, } from "@fungi.computer/shiitake/client";
|
|
4
5
|
import { createShiitakeClient } from "@fungi.computer/shiitake/client";
|
|
5
6
|
import { ShiitakeError } from "@fungi.computer/shiitake";
|
|
6
7
|
import { AgentArchiveRefused, AgentCreateRefused, } from "@fungi.computer/shiitake/agent-control";
|
|
@@ -16,7 +17,6 @@ import { createDiscordReplies, } from "../channels/discord-replies.js";
|
|
|
16
17
|
import { isDiscordBinding, createDiscordBindings, createDiscordInputSchema, updateDiscordInputSchema, } from "../channels/discord-binding.js";
|
|
17
18
|
import { DISCORD_SETTLEMENT_WAIT_MS, discordDenial, discordFailureText, patchOriginal, postChannelMessage, postFollowUp, quoted, STILL_WORKING_TEXT, splitDiscordMessage, registerAskCommand, } from "../channels/discord-interactions.js";
|
|
18
19
|
import { discordOutcome, sealDiscordToken, } from "./discord-channels.js";
|
|
19
|
-
import { createAgentInstructions, withOwnerInstructions, } from "../agent-instructions.js";
|
|
20
20
|
import { computerSkillsEmpty, createComputerSkillSource, } from "./computer-skill-source.js";
|
|
21
21
|
import { channelSessionDoor } from "./channel-session-door.js";
|
|
22
22
|
import { createAuthenticatedVisitorChannel } from "../channels/visitor-channel.js";
|
|
@@ -38,8 +38,10 @@ import { createAgentComputerSource, readAgentComputerConnections, } from "../age
|
|
|
38
38
|
import { standaloneAgentComputerPorts, standaloneBrowserSave, } from "./agent-computers.js";
|
|
39
39
|
import { FleetGrantRefused, } from "@fungi.computer/computer/fleet";
|
|
40
40
|
import { homeExtension, homeGrant, } from "@fungi.computer/shiitake-extensions/home/host";
|
|
41
|
-
import { homeContract } from "@fungi.computer/shiitake-extensions/home";
|
|
41
|
+
import { homeContract, homeInstructionsLimit, } from "@fungi.computer/shiitake-extensions/home";
|
|
42
|
+
import { resolveHome } from "@fungi.computer/shiitake-extensions/home/host";
|
|
42
43
|
import { DurableObject } from "cloudflare:workers";
|
|
44
|
+
import { standaloneHomeInstructionsFile, } from "./computer.js";
|
|
43
45
|
import { ShiitakeDO } from "@fungi.computer/shiitake/cloudflare";
|
|
44
46
|
import { agentStoreKeeping } from "./agent-store.js";
|
|
45
47
|
import { CredentialError, } from "@fungi.computer/veil/credential-store";
|
|
@@ -72,8 +74,24 @@ import { agentCeiling, oysterPrincipalIsOwner } from "../authorization.js";
|
|
|
72
74
|
import { defaultTenant, tenantIdSchema, tenantScope, } from "../tenant.js";
|
|
73
75
|
import { createCodemodeSandbox } from "@fungi.computer/mycelium/workers";
|
|
74
76
|
import { forageDiscoveryInstructions } from "@fungi.computer/mycelium/effect";
|
|
77
|
+
const noHomeInstructions = {
|
|
78
|
+
home: null,
|
|
79
|
+
content: null,
|
|
80
|
+
bytes: 0,
|
|
81
|
+
limit: homeInstructionsLimit,
|
|
82
|
+
};
|
|
83
|
+
function homeInstructions(home, content) {
|
|
84
|
+
return {
|
|
85
|
+
home: { name: home },
|
|
86
|
+
content,
|
|
87
|
+
bytes: content === null ? 0 : new TextEncoder().encode(content).byteLength,
|
|
88
|
+
limit: homeInstructionsLimit,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Shown when the AI Gateway spend limit blocks a model call; same sentence as media. */
|
|
92
|
+
const DAILY_LIMIT_COPY = "Today's spending limit for this Oyster is used up. It resets at 00:00 UTC.";
|
|
75
93
|
/** Own transport evidence and exact-message decisions for one model lease. */
|
|
76
|
-
function observedModels(model, defaults) {
|
|
94
|
+
function observedModels(model, defaults, gatewaySpendLimit = false) {
|
|
77
95
|
return {
|
|
78
96
|
acquire: ({ signal }) => {
|
|
79
97
|
const retryableMessages = new WeakSet();
|
|
@@ -81,7 +99,13 @@ function observedModels(model, defaults) {
|
|
|
81
99
|
const failure = (message, rejection) => {
|
|
82
100
|
// Pi can include raw response bodies in errorMessage. No provider
|
|
83
101
|
// prose enters a Session, retry journal, model context or diagnostics.
|
|
84
|
-
|
|
102
|
+
// The gateway publishes no body code for a spend-limit block, only 429,
|
|
103
|
+
// and Oyster configures no gateway rate-limit rule. A 429 through the
|
|
104
|
+
// gateway therefore means the daily spend limit; retrying cannot help.
|
|
105
|
+
const spendLimit = gatewaySpendLimit && rejection?.code === "rate-limit";
|
|
106
|
+
const safe = spendLimit
|
|
107
|
+
? DAILY_LIMIT_COPY
|
|
108
|
+
: `Model request failed (${rejection?.code ?? "provider_rejected"}). Retry the request.`;
|
|
85
109
|
const terminal = {
|
|
86
110
|
role: "assistant",
|
|
87
111
|
content: [],
|
|
@@ -94,7 +118,7 @@ function observedModels(model, defaults) {
|
|
|
94
118
|
timestamp: message.timestamp,
|
|
95
119
|
};
|
|
96
120
|
safeFailures.set(terminal, safe);
|
|
97
|
-
if (isRetryableProviderRejection(rejection))
|
|
121
|
+
if (!spendLimit && isRetryableProviderRejection(rejection))
|
|
98
122
|
retryableMessages.add(terminal);
|
|
99
123
|
return terminal;
|
|
100
124
|
};
|
|
@@ -255,7 +279,7 @@ function workersAiModels(ai, options) {
|
|
|
255
279
|
};
|
|
256
280
|
if (options.reasoning !== undefined)
|
|
257
281
|
streamOptions.reasoning = options.reasoning;
|
|
258
|
-
return observedModels(normalizeModel(model), streamOptions);
|
|
282
|
+
return observedModels(normalizeModel(model), streamOptions, true);
|
|
259
283
|
}
|
|
260
284
|
const policyDirectorySchema = Schema.Struct({
|
|
261
285
|
directoryName: Schema.NonEmptyString,
|
|
@@ -1040,17 +1064,40 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
1040
1064
|
});
|
|
1041
1065
|
});
|
|
1042
1066
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1067
|
+
/** Which Home this Agent uses: its recorded choice, else its only attachment. */
|
|
1068
|
+
async homeComputer() {
|
|
1069
|
+
const attachments = (await this.preparedComputerSnapshot())?.projection.attachments ?? [];
|
|
1070
|
+
// Home's choice is Agent state; any Session id projects it, run or not.
|
|
1071
|
+
const session = (await this.shiitake()).session("home-choice");
|
|
1072
|
+
const view = bindSessionExtension(session, homeContract).view(await session.read());
|
|
1073
|
+
const chosen = resolveHome(view.status === "running" ? view.value : null, attachments);
|
|
1074
|
+
return attachments.find(({ attachmentId }) => attachmentId === chosen?.attachmentId);
|
|
1046
1075
|
}
|
|
1047
|
-
/**
|
|
1048
|
-
|
|
1049
|
-
|
|
1076
|
+
/**
|
|
1077
|
+
* The AGENTS.md on this Agent's Home Computer. The host admits the owner
|
|
1078
|
+
* first; `actor` names who the Computer's grant records.
|
|
1079
|
+
*/
|
|
1080
|
+
async readInstructions(actor) {
|
|
1081
|
+
const home = await this.homeComputer();
|
|
1082
|
+
if (home === undefined)
|
|
1083
|
+
return noHomeInstructions;
|
|
1084
|
+
const content = await standaloneHomeInstructionsFile(this.env.COMPUTER.getByName(home.computerId), home.computerId, actor).read();
|
|
1085
|
+
return homeInstructions(home.name, content);
|
|
1050
1086
|
}
|
|
1051
|
-
/**
|
|
1052
|
-
|
|
1053
|
-
|
|
1087
|
+
/**
|
|
1088
|
+
* Replace it only if it still holds what the owner read; null creates it only
|
|
1089
|
+
* while absent. The next run follows the new text; a run already going does not.
|
|
1090
|
+
*/
|
|
1091
|
+
async replaceInstructions(actor, expectedContent, content) {
|
|
1092
|
+
if (new TextEncoder().encode(content).byteLength > homeInstructionsLimit)
|
|
1093
|
+
return { error: "too_large" };
|
|
1094
|
+
const home = await this.homeComputer();
|
|
1095
|
+
if (home === undefined)
|
|
1096
|
+
return { error: "no_home" };
|
|
1097
|
+
const result = await standaloneHomeInstructionsFile(this.env.COMPUTER.getByName(home.computerId), home.computerId, actor).replace(expectedContent, content);
|
|
1098
|
+
return result.kind === "conflict"
|
|
1099
|
+
? { error: "conflict" }
|
|
1100
|
+
: homeInstructions(home.name, content);
|
|
1054
1101
|
}
|
|
1055
1102
|
/** Secret-free default of this Agent; stored separately from Session history. */
|
|
1056
1103
|
async readModelChoice() {
|
|
@@ -1259,13 +1306,19 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
1259
1306
|
instructions: this.channelInstructions({
|
|
1260
1307
|
load: async () => {
|
|
1261
1308
|
const { appApprovalInstructions } = await import("../mcp.js");
|
|
1262
|
-
return
|
|
1309
|
+
return {
|
|
1263
1310
|
revision: "oyster-7",
|
|
1264
1311
|
text: instructions + "\n" + appApprovalInstructions,
|
|
1265
|
-
}
|
|
1312
|
+
};
|
|
1266
1313
|
},
|
|
1267
1314
|
}),
|
|
1268
1315
|
tools: {
|
|
1316
|
+
// A run outlasts one ten-minute Computer command; waiting for a
|
|
1317
|
+
// sandbox slot keeps its shorter bound.
|
|
1318
|
+
execution: {
|
|
1319
|
+
timeoutMs: agentCodeExecutionTimeoutMs,
|
|
1320
|
+
admissionWaitMs: 180_000,
|
|
1321
|
+
},
|
|
1269
1322
|
sources: [
|
|
1270
1323
|
{
|
|
1271
1324
|
id: "oyster-apps",
|
|
@@ -1693,6 +1746,8 @@ export class AgentDirectory extends DurableObject {
|
|
|
1693
1746
|
}
|
|
1694
1747
|
constructor(ctx, env) {
|
|
1695
1748
|
super(ctx, env);
|
|
1749
|
+
// 0.33.0 kept owner text here; instructions now live in Home's AGENTS.md.
|
|
1750
|
+
ctx.storage.sql.exec("DROP TABLE IF EXISTS agent_instructions");
|
|
1696
1751
|
this.directory = createAgentDirectory(ctx.storage.sql);
|
|
1697
1752
|
this.avatars = createAgentAvatarStore(ctx.storage.sql);
|
|
1698
1753
|
this.computers = createAgentComputers({
|
|
@@ -2450,18 +2505,16 @@ export function standaloneAgents(env, scope) {
|
|
|
2450
2505
|
return { error: "not_found" };
|
|
2451
2506
|
return {
|
|
2452
2507
|
agentId,
|
|
2453
|
-
|
|
2508
|
+
...(await env.AGENTS.getByName(agentId).readInstructions(JSON.stringify(principal))),
|
|
2454
2509
|
};
|
|
2455
2510
|
},
|
|
2456
|
-
setInstructions: async (agentId,
|
|
2511
|
+
setInstructions: async (agentId, edit, principal) => {
|
|
2457
2512
|
if (!oysterPrincipalIsOwner(principal))
|
|
2458
2513
|
return { error: "not_granted" };
|
|
2459
2514
|
if (!(await directory().has(agentId)))
|
|
2460
2515
|
return { error: "not_found" };
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
instructions: await env.AGENTS.getByName(agentId).writeInstructions(instructions),
|
|
2464
|
-
};
|
|
2516
|
+
const result = await env.AGENTS.getByName(agentId).replaceInstructions(JSON.stringify(principal), edit.expectedContent, edit.content);
|
|
2517
|
+
return "error" in result ? result : { agentId, ...result };
|
|
2465
2518
|
},
|
|
2466
2519
|
setModelChoice: async (agentId, choice, principal) => {
|
|
2467
2520
|
if (!oysterPrincipalIsOwner(principal))
|
|
@@ -19,6 +19,11 @@ export type StarterApp = Readonly<{
|
|
|
19
19
|
trial: "local" | "needs-runtime";
|
|
20
20
|
}>;
|
|
21
21
|
export declare const standaloneAppSet: readonly StarterApp[];
|
|
22
|
+
/**
|
|
23
|
+
* The starter Apps to install: all of them, or only the named installation ids,
|
|
24
|
+
* in the starter order. An unknown name is refused with the valid names.
|
|
25
|
+
*/
|
|
26
|
+
export declare function selectStarterApps(only?: readonly string[]): readonly StarterApp[];
|
|
22
27
|
/** The Apps `oyster try` installs after the desktop, in the order it reports them. */
|
|
23
28
|
export declare const trialStarterOrder: readonly ["grove", "prints", "inkcap", "trellis", "bonsai", "shed"];
|
|
24
29
|
/** The plain refusal for an Oyster without a Computer to build on. */
|
|
@@ -100,6 +105,8 @@ export declare function installStandaloneAppSet(options: Readonly<{
|
|
|
100
105
|
report: (message: string) => void;
|
|
101
106
|
/** Builds at once on the Computer, 1 to 3; one by default. */
|
|
102
107
|
concurrency?: number;
|
|
108
|
+
/** Install only these starter installation ids; every starter by default. */
|
|
109
|
+
only?: readonly string[];
|
|
103
110
|
/** Publishes one App's source; the real installer uses `publishSource`. */
|
|
104
111
|
publish?: (app: StarterApp, located: Readonly<{
|
|
105
112
|
repositoryPath: string;
|
|
@@ -72,6 +72,19 @@ export const standaloneAppSet = [
|
|
|
72
72
|
trial: "local",
|
|
73
73
|
},
|
|
74
74
|
];
|
|
75
|
+
/**
|
|
76
|
+
* The starter Apps to install: all of them, or only the named installation ids,
|
|
77
|
+
* in the starter order. An unknown name is refused with the valid names.
|
|
78
|
+
*/
|
|
79
|
+
export function selectStarterApps(only) {
|
|
80
|
+
if (only === undefined)
|
|
81
|
+
return standaloneAppSet;
|
|
82
|
+
const known = standaloneAppSet.map((app) => app.installationId);
|
|
83
|
+
const unknown = only.filter((name) => !known.includes(name));
|
|
84
|
+
if (unknown.length > 0 || only.length === 0)
|
|
85
|
+
throw new Error(`Unknown starter App ${unknown.join(", ") || "(none named)"}. Choose from: ${known.join(", ")}.`);
|
|
86
|
+
return standaloneAppSet.filter((app) => only.includes(app.installationId));
|
|
87
|
+
}
|
|
75
88
|
/** The Apps `oyster try` installs after the desktop, in the order it reports them. */
|
|
76
89
|
export const trialStarterOrder = [
|
|
77
90
|
"grove",
|
|
@@ -173,6 +186,7 @@ const run = (command, args, cwd) => new Promise((resolveRun, reject) => {
|
|
|
173
186
|
* is compiled on this machine and no installed App is needed to build.
|
|
174
187
|
*/
|
|
175
188
|
export async function installStandaloneAppSet(options) {
|
|
189
|
+
const apps = selectStarterApps(options.only);
|
|
176
190
|
const concurrency = options.concurrency ?? defaultStarterBuildConcurrency();
|
|
177
191
|
if (!Number.isInteger(concurrency) ||
|
|
178
192
|
concurrency < 1 ||
|
|
@@ -331,7 +345,7 @@ export async function installStandaloneAppSet(options) {
|
|
|
331
345
|
};
|
|
332
346
|
const seedAll = async () => {
|
|
333
347
|
try {
|
|
334
|
-
for (const app of
|
|
348
|
+
for (const app of apps) {
|
|
335
349
|
try {
|
|
336
350
|
const seeded = await seedApp(app);
|
|
337
351
|
const waiter = waiting.shift();
|
|
@@ -441,11 +455,11 @@ export async function installStandaloneAppSet(options) {
|
|
|
441
455
|
if (outcome.status === "rejected")
|
|
442
456
|
throw outcome.reason;
|
|
443
457
|
return {
|
|
444
|
-
installed:
|
|
458
|
+
installed: apps.flatMap((app) => {
|
|
445
459
|
const result = installed.get(app.installationId);
|
|
446
460
|
return result === undefined ? [] : [result];
|
|
447
461
|
}),
|
|
448
|
-
failed:
|
|
462
|
+
failed: apps.flatMap((app) => {
|
|
449
463
|
const reason = failures.get(app.installationId);
|
|
450
464
|
return reason === undefined
|
|
451
465
|
? []
|
|
@@ -17,7 +17,7 @@ export const standaloneFleetRequestSchema = z.discriminatedUnion("operation", [
|
|
|
17
17
|
page: computerPageSchema,
|
|
18
18
|
}),
|
|
19
19
|
z.strictObject({
|
|
20
|
-
operation: z.enum(["read", "resolve", "state", "start", "select"]),
|
|
20
|
+
operation: z.enum(["read", "resolve", "state", "start", "stop", "select"]),
|
|
21
21
|
computerId: fleetComputerId,
|
|
22
22
|
}),
|
|
23
23
|
z.strictObject({
|
|
@@ -166,6 +166,14 @@ export function standaloneComputerFleetRoutes(registryFor) {
|
|
|
166
166
|
});
|
|
167
167
|
return fleetResponse(result);
|
|
168
168
|
});
|
|
169
|
+
routes.get("/api/computers/:computerId/state", owner, async (context, { principal }) => fleetResponse(await registryFor().computerFleet(principal.actor.memberId, {
|
|
170
|
+
operation: "state",
|
|
171
|
+
computerId: context.req.param("computerId"),
|
|
172
|
+
})));
|
|
173
|
+
routes.post("/api/computers/:computerId/stop", owner, async (context, { principal }) => fleetResponse(await registryFor().computerFleet(principal.actor.memberId, {
|
|
174
|
+
operation: "stop",
|
|
175
|
+
computerId: context.req.param("computerId"),
|
|
176
|
+
})));
|
|
169
177
|
// One owner switch per durable Computer setting, read and written alike.
|
|
170
178
|
for (const [path, read, write] of [
|
|
171
179
|
["internet-access", "read-internet-access", "set-internet-access"],
|
|
@@ -7,7 +7,7 @@ import * as z from "zod";
|
|
|
7
7
|
import { computerProcessSchema, computerToolResultSchema, readOutputSchema } from "@fungi.computer/computer-contract";
|
|
8
8
|
import { ComputerDO as NativeComputerDO, type AttachedBackend, type ComputerEnv, type ComputerFilesRpc } from "@fungi.computer/computer";
|
|
9
9
|
import { patchInputSchema, patchOutputSchema } from "@fungi.computer/knapsack/files-patch";
|
|
10
|
-
import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, moveOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
|
|
10
|
+
import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, moveOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsOutputSchema, processWaitOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
|
|
11
11
|
import { type WorkflowGitCredential, type WorkflowGitPassGrant } from "@fungi.computer/braid/runtime";
|
|
12
12
|
import { type ComputerAction, type ComputerBackendView, type ComputerGrant, type LocalBackendAttachInput, type LocalBackendDetachInput } from "@fungi.computer/computer/fleet";
|
|
13
13
|
import type { InvocationFrame } from "../invocation.js";
|
|
@@ -41,7 +41,7 @@ export type StandaloneComputerResult = z.output<typeof listOutputSchema> | Reado
|
|
|
41
41
|
truncated: boolean;
|
|
42
42
|
}> | Readonly<{
|
|
43
43
|
error: "conflict" | "no_runtime" | "not_found" | "invalid";
|
|
44
|
-
}> | z.output<typeof writeOutputSchema> | z.output<typeof moveOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof processLogsOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
|
|
44
|
+
}> | z.output<typeof writeOutputSchema> | z.output<typeof moveOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof processLogsOutputSchema> | z.output<typeof processWaitOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
|
|
45
45
|
/**
|
|
46
46
|
* A port-preview listing, or the typed refusal the owner route presents with
|
|
47
47
|
* {@link appMethodRefusalStatus}. A refusal never escapes as a 500.
|
|
@@ -121,6 +121,14 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
121
121
|
} | {
|
|
122
122
|
error: "no_runtime";
|
|
123
123
|
}>;
|
|
124
|
+
/** An admitted fleet control stops exactly this Computer's hosted backend. */
|
|
125
|
+
stopHostedComputer(authority: ComputerGrant): Promise<{
|
|
126
|
+
state: "sleeping";
|
|
127
|
+
} | {
|
|
128
|
+
error: "busy";
|
|
129
|
+
} | {
|
|
130
|
+
error: "no_runtime";
|
|
131
|
+
}>;
|
|
124
132
|
/** Runtime facts for the host's owner-admitted setup read. */
|
|
125
133
|
runtimeSetup(): {
|
|
126
134
|
terminal: "exec-only";
|
|
@@ -194,7 +202,7 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
194
202
|
fileWrite(authority: ComputerGrant, path: string, bytes: Uint8Array): Promise<void>;
|
|
195
203
|
/** Patch is handled by the Computer's pinned native engine, not by the Agent. */
|
|
196
204
|
filePatch(authority: ComputerGrant, input: z.output<typeof patchInputSchema>): Promise<z.output<typeof patchOutputSchema>>;
|
|
197
|
-
fileReplace(authority: ComputerGrant, path: string, expectedContent: string, content: string): Promise<{
|
|
205
|
+
fileReplace(authority: ComputerGrant, path: string, expectedContent: string | null, content: string): Promise<{
|
|
198
206
|
path: string;
|
|
199
207
|
bytes: number;
|
|
200
208
|
kind: "replaced";
|
|
@@ -213,6 +221,21 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
213
221
|
* Computer, rather than reading `env.KEYS` directly and skipping the check.
|
|
214
222
|
*/
|
|
215
223
|
export declare function standaloneWorkspace(env: StandaloneComputerEnv, keysLive?: OysterKeysLivePort, selectedComputerId?: string): OysterWorkspace;
|
|
224
|
+
/**
|
|
225
|
+
* One Computer's AGENTS.md as the principal behind `actor`: the Computer's
|
|
226
|
+
* grant names that person or key. A missing file reads as null.
|
|
227
|
+
*/
|
|
228
|
+
export declare function standaloneHomeInstructionsFile(computer: Pick<ComputerDO, "fileRead" | "fileReplace">, computerId: string, actor: string): {
|
|
229
|
+
read: () => Promise<string | null>;
|
|
230
|
+
/** Replace what the owner last read, or with null create it only while absent. */
|
|
231
|
+
replace: (expectedContent: string | null, content: string) => Promise<{
|
|
232
|
+
path: string;
|
|
233
|
+
bytes: number;
|
|
234
|
+
kind: "replaced";
|
|
235
|
+
} | {
|
|
236
|
+
kind: "conflict";
|
|
237
|
+
}>;
|
|
238
|
+
};
|
|
216
239
|
/**
|
|
217
240
|
* Owner/key capability routes over the selected Computer's native
|
|
218
241
|
* namespace. Each route declares the Computer requirement, so a key reaches
|
|
@@ -12,7 +12,7 @@ import * as z from "zod";
|
|
|
12
12
|
import { ComputerPortConflictError, computerByteReadReplySchema, computerProcessSchema, installationProcessScope, processStartInputSchema, processStartToolInputSchema, computerCapabilities, computerToolResultSchema, readOutputSchema, } from "@fungi.computer/computer-contract";
|
|
13
13
|
import { ComputerDO as NativeComputerDO, ComputerOperationConflictError, ComputerBackendUnavailableError, } from "@fungi.computer/computer";
|
|
14
14
|
import { patchInputSchema, patchOutputSchema, } from "@fungi.computer/knapsack/files-patch";
|
|
15
|
-
import { ComputerFileConflict, ComputerFileMoveError, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, moveInputSchema, moveOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsInputSchema, processLogsOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
|
|
15
|
+
import { ComputerFileConflict, ComputerFileMoveError, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, moveInputSchema, moveOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsInputSchema, processWaitInputSchema, processLogsOutputSchema, processWaitOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
|
|
16
16
|
import { workflowGitExecutionEnvironment, workflowGitPassGrantSchema, } from "@fungi.computer/braid/runtime";
|
|
17
17
|
import { checkComputerGrant, computerActionSchema, computerGrantSchema, ComputerBackingError, createFleetBacking, FleetGrantRefused, FleetLifecycle, } from "@fungi.computer/computer/fleet";
|
|
18
18
|
import { AppInstanceError, selectionOf } from "../index.js";
|
|
@@ -92,6 +92,8 @@ const computerTools = {
|
|
|
92
92
|
start_process: { action: "processStart", output: computerProcessSchema },
|
|
93
93
|
list_processes: { action: "processList", output: processListOutputSchema },
|
|
94
94
|
kill_process: { action: "processKill", output: processKillOutputSchema },
|
|
95
|
+
process_logs: { action: "processLogs", output: processLogsOutputSchema },
|
|
96
|
+
wait_process: { action: "processWait", output: processWaitOutputSchema },
|
|
95
97
|
};
|
|
96
98
|
const computerTool = z.enum([
|
|
97
99
|
"read",
|
|
@@ -104,6 +106,8 @@ const computerTool = z.enum([
|
|
|
104
106
|
"start_process",
|
|
105
107
|
"list_processes",
|
|
106
108
|
"kill_process",
|
|
109
|
+
"process_logs",
|
|
110
|
+
"wait_process",
|
|
107
111
|
]);
|
|
108
112
|
const previewRefusal = appMethodRefusedReplySchema.parse({
|
|
109
113
|
kind: "refused",
|
|
@@ -264,6 +268,13 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
264
268
|
await run();
|
|
265
269
|
});
|
|
266
270
|
}
|
|
271
|
+
/** An admitted fleet control stops exactly this Computer's hosted backend. */
|
|
272
|
+
async stopHostedComputer(authority) {
|
|
273
|
+
this.#accept(authority, "stop");
|
|
274
|
+
if (this.previewBindings.OYSTER_COMPUTER_BACKEND === "local")
|
|
275
|
+
return { error: "no_runtime" };
|
|
276
|
+
return this.#fleetLifecycle().stopHostedComputer();
|
|
277
|
+
}
|
|
267
278
|
/** Runtime facts for the host's owner-admitted setup read. */
|
|
268
279
|
runtimeSetup() {
|
|
269
280
|
const backends = this.describeBackends();
|
|
@@ -520,6 +531,8 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
520
531
|
}
|
|
521
532
|
case "processLogs":
|
|
522
533
|
return this.processLogsAfterAcceptance(processLogsInputSchema.parse(input), accept);
|
|
534
|
+
case "processWait":
|
|
535
|
+
return this.waitProcessAfterAcceptance(processWaitInputSchema.parse(input), accept);
|
|
523
536
|
case "processKill":
|
|
524
537
|
return this.killProcessAfterAcceptance(processIdInputSchema.parse(input), accept);
|
|
525
538
|
case "exec":
|
|
@@ -683,6 +696,24 @@ export function standaloneWorkspace(env, keysLive, selectedComputerId = env.OYST
|
|
|
683
696
|
},
|
|
684
697
|
};
|
|
685
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* One Computer's AGENTS.md as the principal behind `actor`: the Computer's
|
|
701
|
+
* grant names that person or key. A missing file reads as null.
|
|
702
|
+
*/
|
|
703
|
+
export function standaloneHomeInstructionsFile(computer, computerId, actor) {
|
|
704
|
+
const authority = grant(computerId, actor);
|
|
705
|
+
const path = "/AGENTS.md";
|
|
706
|
+
return {
|
|
707
|
+
read: async () => {
|
|
708
|
+
const bytes = await computer.fileRead(authority, path);
|
|
709
|
+
return bytes === null
|
|
710
|
+
? null
|
|
711
|
+
: new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
712
|
+
},
|
|
713
|
+
/** Replace what the owner last read, or with null create it only while absent. */
|
|
714
|
+
replace: (expectedContent, content) => computer.fileReplace(authority, path, expectedContent, content),
|
|
715
|
+
};
|
|
716
|
+
}
|
|
686
717
|
/**
|
|
687
718
|
* Owner/key capability routes over the selected Computer's native
|
|
688
719
|
* namespace. Each route declares the Computer requirement, so a key reaches
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
// OYSTER_URL=https://… OYSTER_OWNER_KEY=… oyster install-apps
|
|
8
8
|
// [--repositories <base URL>] [--ref <branch or tag>]
|
|
9
|
-
// [--from <checkout directory>] [--concurrency 1-3] [--timings <file>]
|
|
9
|
+
// [--from <checkout directory>] [--concurrency 1-3] [--timings <file>] [--only <app>[,<app>]]
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
11
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
@@ -19,7 +19,7 @@ import { installReleaseCommand, installReleaseUsage, } from "../install-release-
|
|
|
19
19
|
import { defaultStarterBuildConcurrency, installStandaloneAppSet, } from "./app-set.js";
|
|
20
20
|
/** The starter Apps' public source repositories. */
|
|
21
21
|
const defaultRepositories = "https://github.com/fungi-computer";
|
|
22
|
-
const usage = "Usage: oyster install-apps [--repositories <base URL>] [--ref <ref>] [--from <checkout>] [--concurrency 1-3] [--timings <file>]";
|
|
22
|
+
const usage = "Usage: oyster install-apps [--repositories <base URL>] [--ref <ref>] [--from <checkout>] [--concurrency 1-3] [--timings <file>] [--only <app>[,<app>]]";
|
|
23
23
|
const urlSource = "OYSTER_URL is the address of your deployed Oyster Worker, such as https://oyster.<your-subdomain>.workers.dev. You set it when you deploy. For a local trial, run `oyster try`; it sets up its Computer and starter Apps.";
|
|
24
24
|
const keySource = "OYSTER_OWNER_KEY is the owner key you chose for that Oyster: export OYSTER_OWNER_KEY=$(openssl rand -hex 24), then store it with `wrangler secret put OYSTER_OWNER_KEY`.";
|
|
25
25
|
const helpText = `${usage}
|
|
@@ -36,6 +36,7 @@ Options:
|
|
|
36
36
|
--ref <ref> branch or tag to build (default main)
|
|
37
37
|
--from <checkout> install from a Botanical checkout directory
|
|
38
38
|
--concurrency 1-3 Apps to build at once
|
|
39
|
+
--only <app>[,<app>] install only these Apps, such as --only prints
|
|
39
40
|
--timings <file> write the build timings as JSON
|
|
40
41
|
-h, --help show this help
|
|
41
42
|
`;
|
|
@@ -92,6 +93,7 @@ export async function installApps(args, install = installStandaloneAppSet, ui =
|
|
|
92
93
|
from: { type: "string" },
|
|
93
94
|
concurrency: { type: "string" },
|
|
94
95
|
timings: { type: "string" },
|
|
96
|
+
only: { type: "string" },
|
|
95
97
|
help: { type: "boolean", short: "h" },
|
|
96
98
|
},
|
|
97
99
|
strict: true,
|
|
@@ -110,6 +112,9 @@ export async function installApps(args, install = installStandaloneAppSet, ui =
|
|
|
110
112
|
const concurrency = values.concurrency === undefined
|
|
111
113
|
? defaultStarterBuildConcurrency()
|
|
112
114
|
: Number(values.concurrency);
|
|
115
|
+
const only = values.only === undefined
|
|
116
|
+
? undefined
|
|
117
|
+
: values.only.split(",").map((name) => name.trim());
|
|
113
118
|
const scratch = await mkdtemp(join(tmpdir(), "oyster-install-apps-"));
|
|
114
119
|
try {
|
|
115
120
|
let source;
|
|
@@ -134,6 +139,7 @@ export async function installApps(args, install = installStandaloneAppSet, ui =
|
|
|
134
139
|
url,
|
|
135
140
|
key,
|
|
136
141
|
concurrency,
|
|
142
|
+
only,
|
|
137
143
|
// Builds run side by side, so each report is its own line, not a spinner.
|
|
138
144
|
report: (message) => {
|
|
139
145
|
ui.step(message);
|
|
@@ -2,7 +2,7 @@ import type { FrameBindingProps } from "../cloudflare.js";
|
|
|
2
2
|
import type { InvocationFrame } from "../invocation.js";
|
|
3
3
|
import type { OysterBindingResult } from "../workers.js";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
|
-
import { type MediaServiceHost } from "@fungi.computer/darkroom/server";
|
|
5
|
+
import { type DailyMediaMeterPort, type MediaServiceHost } from "@fungi.computer/darkroom/server";
|
|
6
6
|
import { type MediaAiPort, type MediaImagePort } from "@fungi.computer/darkroom/cloudflare";
|
|
7
7
|
import { type OysterCapability } from "../host.js";
|
|
8
8
|
import type { FileSource } from "../files.js";
|
|
@@ -12,8 +12,13 @@ export type OysterMediaEnv = Readonly<{
|
|
|
12
12
|
AI: MediaAiPort;
|
|
13
13
|
/** This Worker's own origin; a loopback origin has no Cloudflare account. */
|
|
14
14
|
OYSTER_ORIGIN?: string | undefined;
|
|
15
|
-
/** Darkroom's durable operation namespace. */
|
|
16
|
-
MEDIA_OPERATION:
|
|
15
|
+
/** Darkroom's durable operation namespace; the named daily-meter object lives here too. */
|
|
16
|
+
MEDIA_OPERATION: Readonly<{
|
|
17
|
+
getByName(name: string): ReturnType<MediaServiceHost["operations"]["getByName"]> & Partial<DailyMediaMeterPort>;
|
|
18
|
+
}>;
|
|
19
|
+
/** Hard stop on one UTC day's media spend, in US dollars (for example `100`).
|
|
20
|
+
* Unset leaves media unmetered. A set but invalid value refuses all media. */
|
|
21
|
+
OYSTER_DAILY_MEDIA_LIMIT_USD?: string | undefined;
|
|
17
22
|
/** Native image decoding and bounded reference fitting. */
|
|
18
23
|
IMAGES?: MediaImagePort;
|
|
19
24
|
/** The AI Gateway third-party models (GPT Image 2, Seedance, Veo) route
|