@fungi.computer/oyster 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels/discord-interactions.d.ts +15 -0
- package/dist/channels/discord-interactions.js +29 -0
- package/dist/channels/discord-replies.d.ts +9 -1
- package/dist/channels/discord-replies.js +34 -9
- package/dist/embed-metafiles.js +1 -1
- package/dist/machine-link/link.js +3 -1
- package/dist/page/computer-handles.d.ts +4 -0
- package/dist/page-script.js +1 -1
- package/dist/standalone/agents.d.ts +14 -0
- package/dist/standalone/agents.js +61 -11
- package/dist/standalone/computer.js +3 -0
- package/package.json +12 -12
|
@@ -142,6 +142,10 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
142
142
|
askDiscord(bindingId: string, ask: DiscordAsk): void;
|
|
143
143
|
private discordReplyOwner;
|
|
144
144
|
private discordReplies;
|
|
145
|
+
/** How long one pass waits on an unfinished run before looking again. */
|
|
146
|
+
protected discordSettlementWaitMs(): number;
|
|
147
|
+
/** The directory, which holds the sealed bot token and sends with it. */
|
|
148
|
+
private discordDirectory;
|
|
145
149
|
/** The Discord replies this Agent owes; a full option override must run it. */
|
|
146
150
|
protected discordReplyWork(): {
|
|
147
151
|
pending: () => {
|
|
@@ -483,6 +487,16 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
|
|
|
483
487
|
registered: readonly string[];
|
|
484
488
|
failed: readonly string[];
|
|
485
489
|
}> | DiscordRefusal>;
|
|
490
|
+
/**
|
|
491
|
+
* Host-only: post one channel message as this binding's bot, for an answer
|
|
492
|
+
* that outlived its interaction token. The sealed token stays inside this call.
|
|
493
|
+
*/
|
|
494
|
+
discordSend(bindingId: string, message: Readonly<{
|
|
495
|
+
channelId: string;
|
|
496
|
+
content: string;
|
|
497
|
+
withReply: boolean;
|
|
498
|
+
mentionUserId: string | null;
|
|
499
|
+
}>): Promise<"delivered" | "gone" | "retry">;
|
|
486
500
|
/** Host-only: the website or Discord binding an Agent serves, read fresh on every use. */
|
|
487
501
|
channelBinding(bindingId: string): WebsiteBinding | DiscordBinding | null;
|
|
488
502
|
/** Host-only public lookup: a site key resolves to its site, or to nothing. */
|
|
@@ -14,7 +14,7 @@ import { decideChannelRunSafely } from "../channels/run-decision.js";
|
|
|
14
14
|
import { createWebsiteChannelOwner, websiteOutcome, } from "./website-channels.js";
|
|
15
15
|
import { createDiscordReplies, } from "../channels/discord-replies.js";
|
|
16
16
|
import { isDiscordBinding, createDiscordBindings, createDiscordInputSchema, updateDiscordInputSchema, } from "../channels/discord-binding.js";
|
|
17
|
-
import { DISCORD_SETTLEMENT_WAIT_MS, discordDenial, discordFailureText, patchOriginal, postFollowUp, quoted, splitDiscordMessage, registerAskCommand, } from "../channels/discord-interactions.js";
|
|
17
|
+
import { DISCORD_SETTLEMENT_WAIT_MS, discordDenial, discordFailureText, patchOriginal, postChannelMessage, postFollowUp, quoted, STILL_WORKING_TEXT, splitDiscordMessage, registerAskCommand, } from "../channels/discord-interactions.js";
|
|
18
18
|
import { discordOutcome, sealDiscordToken, } from "./discord-channels.js";
|
|
19
19
|
import { channelSessionDoor } from "./channel-session-door.js";
|
|
20
20
|
import { createAuthenticatedVisitorChannel } from "../channels/visitor-channel.js";
|
|
@@ -396,6 +396,14 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
396
396
|
},
|
|
397
397
|
}));
|
|
398
398
|
}
|
|
399
|
+
/** How long one pass waits on an unfinished run before looking again. */
|
|
400
|
+
discordSettlementWaitMs() {
|
|
401
|
+
return DISCORD_SETTLEMENT_WAIT_MS;
|
|
402
|
+
}
|
|
403
|
+
/** The directory, which holds the sealed bot token and sends with it. */
|
|
404
|
+
discordDirectory() {
|
|
405
|
+
return agentDirectoryForScope(this.env, tenantScope(defaultTenant, this.env.OYSTER_ORIGIN));
|
|
406
|
+
}
|
|
399
407
|
/** The Discord replies this Agent owes; a full option override must run it. */
|
|
400
408
|
discordReplyWork() {
|
|
401
409
|
return this.discordReplies().work;
|
|
@@ -408,13 +416,28 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
408
416
|
/** One attempt at one owed reply; intake is idempotent per interaction. */
|
|
409
417
|
async deliverDiscord(reply) {
|
|
410
418
|
const { ask } = reply;
|
|
411
|
-
|
|
419
|
+
// While the interaction token lives the answer fills the original and
|
|
420
|
+
// follows it; once it has lapsed (or Discord says it is gone) the same
|
|
421
|
+
// messages go to the channel as the owner's bot, mentioning the member.
|
|
422
|
+
const sayPart = async (content, index, withReply) => {
|
|
412
423
|
try {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
424
|
+
if (reply.tokenLive) {
|
|
425
|
+
const outcome = await (index === 0 ? patchOriginal : postFollowUp)(fetch, {
|
|
426
|
+
applicationId: ask.applicationId,
|
|
427
|
+
interactionToken: ask.interactionToken,
|
|
428
|
+
content,
|
|
429
|
+
withReply,
|
|
430
|
+
});
|
|
431
|
+
if (outcome !== "gone")
|
|
432
|
+
return outcome;
|
|
433
|
+
this.discordReplies().tokenGone(reply.interactionId);
|
|
434
|
+
return "waiting";
|
|
435
|
+
}
|
|
436
|
+
return await this.discordDirectory().discordSend(reply.bindingId, {
|
|
437
|
+
channelId: ask.channelId,
|
|
438
|
+
content: index === 0 ? `<@${ask.userId}> ${content}` : content,
|
|
417
439
|
withReply,
|
|
440
|
+
mentionUserId: index === 0 ? ask.userId : null,
|
|
418
441
|
});
|
|
419
442
|
}
|
|
420
443
|
catch (cause) {
|
|
@@ -422,7 +445,7 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
422
445
|
return "retry";
|
|
423
446
|
}
|
|
424
447
|
};
|
|
425
|
-
const say = (content, withReply) => sayPart(content,
|
|
448
|
+
const say = (content, withReply) => sayPart(content, 0, withReply);
|
|
426
449
|
const binding = await this.loadChannelBinding(reply.bindingId);
|
|
427
450
|
if (binding === null ||
|
|
428
451
|
!isDiscordBinding(binding) ||
|
|
@@ -451,10 +474,17 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
451
474
|
}
|
|
452
475
|
const session = (await this.shiitake()).session(accepted.sessionId);
|
|
453
476
|
const settlement = await session.readSettlement(accepted.commandId, {
|
|
454
|
-
timeoutMs:
|
|
477
|
+
timeoutMs: this.discordSettlementWaitMs(),
|
|
455
478
|
});
|
|
456
|
-
if (settlement === undefined)
|
|
479
|
+
if (settlement === undefined) {
|
|
480
|
+
if (reply.stillWorkingDue) {
|
|
481
|
+
// The token is about to lapse: say so now; the answer follows in the channel.
|
|
482
|
+
const told = await sayPart(STILL_WORKING_TEXT, 0, false);
|
|
483
|
+
if (told === "delivered")
|
|
484
|
+
this.discordReplies().markStillWorking(reply.interactionId);
|
|
485
|
+
}
|
|
457
486
|
return "waiting";
|
|
487
|
+
}
|
|
458
488
|
const answered = settlement.terminal.outcome === "completed" &&
|
|
459
489
|
settlement.content.trim().length > 0;
|
|
460
490
|
if (!answered) {
|
|
@@ -475,11 +505,13 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
475
505
|
// in as many messages as it takes, in order.
|
|
476
506
|
const parts = splitDiscordMessage(ask.echo === undefined
|
|
477
507
|
? settlement.content
|
|
478
|
-
: `${quoted(ask.echo)}\n\n${settlement.content}
|
|
508
|
+
: `${quoted(ask.echo)}\n\n${settlement.content}`,
|
|
509
|
+
// A channel message opens with a mention of the member.
|
|
510
|
+
reply.tokenLive ? undefined : 1_950);
|
|
479
511
|
let done = reply.deliveredParts;
|
|
480
512
|
for (; done < parts.length; done += 1) {
|
|
481
513
|
const last = done === parts.length - 1;
|
|
482
|
-
const outcome = await sayPart(parts[done] ?? "", done
|
|
514
|
+
const outcome = await sayPart(parts[done] ?? "", done, last);
|
|
483
515
|
if (outcome !== "delivered")
|
|
484
516
|
return outcome;
|
|
485
517
|
this.discordReplies().progress(reply.interactionId, done + 1);
|
|
@@ -1965,6 +1997,24 @@ export class AgentDirectory extends DurableObject {
|
|
|
1965
1997
|
}
|
|
1966
1998
|
return { registered, failed };
|
|
1967
1999
|
}
|
|
2000
|
+
/**
|
|
2001
|
+
* Host-only: post one channel message as this binding's bot, for an answer
|
|
2002
|
+
* that outlived its interaction token. The sealed token stays inside this call.
|
|
2003
|
+
*/
|
|
2004
|
+
async discordSend(bindingId, message) {
|
|
2005
|
+
const credentialId = this.discords().tokenCredentialId(bindingId);
|
|
2006
|
+
if (credentialId === null)
|
|
2007
|
+
return "gone";
|
|
2008
|
+
try {
|
|
2009
|
+
return await this.discordVault().withSecret(credentialId, (botToken) => postChannelMessage(fetch, { ...message, botToken }));
|
|
2010
|
+
}
|
|
2011
|
+
catch (cause) {
|
|
2012
|
+
if (cause instanceof CredentialError)
|
|
2013
|
+
return cause.code === "absent" ? "gone" : "retry";
|
|
2014
|
+
console.warn("discord channel message failed", cause instanceof Error ? cause.name : "unknown");
|
|
2015
|
+
return "retry";
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
1968
2018
|
/** Host-only: the website or Discord binding an Agent serves, read fresh on every use. */
|
|
1969
2019
|
channelBinding(bindingId) {
|
|
1970
2020
|
return (this.websites().bindings.read(bindingId) ??
|
|
@@ -156,6 +156,9 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
156
156
|
describeBackends: () => this.describeBackends(),
|
|
157
157
|
requireHostedRoute: () => this.requireHostedRoute(),
|
|
158
158
|
containerRunning: (backing) => this.containerRunning(backing),
|
|
159
|
+
endedByIdleSleep: (backendId) => {
|
|
160
|
+
this.endedByIdleSleep(backendId);
|
|
161
|
+
},
|
|
159
162
|
// Standalone boots use the native host directly, not Hub's admission queue.
|
|
160
163
|
vmQueuePosition: () => Promise.resolve(null),
|
|
161
164
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/oyster",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Oyster by Fungi: open-source Apps for people and AI agents. Try with one command or run on your own Cloudflare account.",
|
|
6
6
|
"homepage": "https://docs.fungi.computer/oyster",
|
|
@@ -338,37 +338,37 @@
|
|
|
338
338
|
"dependencies": {
|
|
339
339
|
"@cfworker/json-schema": "4.1.1",
|
|
340
340
|
"@earendil-works/pi-ai": "1.3.0",
|
|
341
|
-
"@fungi.computer/agar": "0.
|
|
341
|
+
"@fungi.computer/agar": "0.11.0",
|
|
342
342
|
"@fungi.computer/bird-dog": "0.3.6",
|
|
343
|
-
"@fungi.computer/braid": "0.4.
|
|
343
|
+
"@fungi.computer/braid": "0.4.11",
|
|
344
344
|
"@fungi.computer/burrow": "0.2.1",
|
|
345
345
|
"@fungi.computer/cairn": "0.1.0",
|
|
346
346
|
"@fungi.computer/capnweb": "0.12.0-fungi.0",
|
|
347
347
|
"@fungi.computer/caps": "0.11.3",
|
|
348
348
|
"@fungi.computer/carrier": "0.2.4",
|
|
349
|
-
"@fungi.computer/computer": "0.
|
|
350
|
-
"@fungi.computer/computer-contract": "0.
|
|
351
|
-
"@fungi.computer/darkroom": "0.5.
|
|
349
|
+
"@fungi.computer/computer": "0.9.0",
|
|
350
|
+
"@fungi.computer/computer-contract": "0.2.0",
|
|
351
|
+
"@fungi.computer/darkroom": "0.5.11",
|
|
352
352
|
"@fungi.computer/ear-tag": "0.1.0",
|
|
353
353
|
"@fungi.computer/forage": "0.3.5",
|
|
354
354
|
"@fungi.computer/gills": "0.3.0",
|
|
355
355
|
"@fungi.computer/knapsack": "0.4.9",
|
|
356
356
|
"@fungi.computer/lantern": "0.4.2",
|
|
357
357
|
"@fungi.computer/mycelium": "0.3.8",
|
|
358
|
-
"@fungi.computer/nacre": "0.5.
|
|
359
|
-
"@fungi.computer/parakeet": "0.11.
|
|
358
|
+
"@fungi.computer/nacre": "0.5.4",
|
|
359
|
+
"@fungi.computer/parakeet": "0.11.23",
|
|
360
360
|
"@fungi.computer/puffball": "0.5.5",
|
|
361
361
|
"@fungi.computer/seam": "0.2.5",
|
|
362
|
-
"@fungi.computer/shiitake": "0.14.
|
|
363
|
-
"@fungi.computer/shiitake-extensions": "0.6.
|
|
362
|
+
"@fungi.computer/shiitake": "0.14.1",
|
|
363
|
+
"@fungi.computer/shiitake-extensions": "0.6.15",
|
|
364
364
|
"@fungi.computer/sigils": "0.3.1",
|
|
365
365
|
"@fungi.computer/sprite": "0.2.2",
|
|
366
366
|
"@fungi.computer/sprite-zdog": "0.3.2",
|
|
367
367
|
"@fungi.computer/veil": "0.7.0",
|
|
368
368
|
"@fungi.computer/watchdog": "0.1.3",
|
|
369
369
|
"@fungi.computer/whistle": "0.3.0",
|
|
370
|
-
"@fungi.computer/workflows-wire": "0.4.
|
|
371
|
-
"@fungi.computer/zookeeper": "0.0.
|
|
370
|
+
"@fungi.computer/workflows-wire": "0.4.11",
|
|
371
|
+
"@fungi.computer/zookeeper": "0.0.22",
|
|
372
372
|
"@modelcontextprotocol/server": "2.0.0",
|
|
373
373
|
"@pnpm/lockfile.fs": "1100.2.13",
|
|
374
374
|
"@pnpm/lockfile.pruner": "1100.0.27",
|