@fungi.computer/oyster 0.22.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.
@@ -135,16 +135,38 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
135
135
  protected channelInstructions(source: CloudflareShiitakeOptions["instructions"]): CloudflareShiitakeOptions["instructions"];
136
136
  /**
137
137
  * A verified Discord question for this Agent. The public edge has already
138
- * checked the application's signature and the guild and channel; this
139
- * accepts the work and returns at once, and the answer follows by the
140
- * interaction webhook once the run settles.
138
+ * checked the application's signature and the guild and channel. The reply
139
+ * is recorded as owed before anything else, then paid off by the Agent's
140
+ * durable host work: an Agent evicted mid-run still answers when it wakes.
141
141
  */
142
142
  askDiscord(bindingId: string, ask: DiscordAsk): void;
143
- private answerDiscord;
144
- /** Owner read of one website's conversations; the host admits the owner first. */
145
- websiteConversations(bindingId: string): Promise<readonly ChannelConversation[]>;
146
- /** Owner read of one conversation of a website, from its Session. */
147
- websiteTranscript(bindingId: string, sessionId: string): Promise<WebsiteTranscript | null>;
143
+ private discordReplyOwner;
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;
149
+ /** The Discord replies this Agent owes; a full option override must run it. */
150
+ protected discordReplyWork(): {
151
+ pending: () => {
152
+ due: boolean;
153
+ nextWakeAt: number | null;
154
+ };
155
+ run: () => Promise<void>;
156
+ };
157
+ /** Replies of one Discord binding that never reached Discord; the host admits the owner first. */
158
+ discordUndelivered(bindingId: string): Promise<readonly Readonly<{
159
+ interactionId: string;
160
+ label: string;
161
+ state: "expired" | "failed";
162
+ closedAt: number;
163
+ }>[]>;
164
+ /** One attempt at one owed reply; intake is idempotent per interaction. */
165
+ private deliverDiscord;
166
+ /** Owner read of one binding's conversations; the host admits the owner first. */
167
+ bindingConversations(bindingId: string): Promise<readonly ChannelConversation[]>;
168
+ /** Owner read of one conversation of a binding, from its Session. */
169
+ bindingTranscript(bindingId: string, sessionId: string): Promise<WebsiteTranscript | null>;
148
170
  private channelBinding;
149
171
  private channelSessionDoor;
150
172
  /**
@@ -273,7 +295,8 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
273
295
  invalidateMcpConnections(): void;
274
296
  /**
275
297
  * A full override must retain channelSource and channelInstructions:
276
- * dropping them removes a suspended website's run refusal and turn capture.
298
+ * dropping them removes a suspended website's run refusal and turn capture,
299
+ * and it must run discordReplyWork or an evicted Discord run never answers.
277
300
  */
278
301
  protected shiitakeOptions(): Promise<CloudflareShiitakeOptions>;
279
302
  /** Send an installation-admitted message through fleet Session operations. */
@@ -464,6 +487,16 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
464
487
  registered: readonly string[];
465
488
  failed: readonly string[];
466
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">;
467
500
  /** Host-only: the website or Discord binding an Agent serves, read fresh on every use. */
468
501
  channelBinding(bindingId: string): WebsiteBinding | DiscordBinding | null;
469
502
  /** Host-only public lookup: a site key resolves to its site, or to nothing. */
@@ -12,8 +12,9 @@ import { transcriptLine, } from "@fungi.computer/nacre/website-channels";
12
12
  import { personChannelInstructions, } from "../channels/web-binding.js";
13
13
  import { decideChannelRunSafely } from "../channels/run-decision.js";
14
14
  import { createWebsiteChannelOwner, websiteOutcome, } from "./website-channels.js";
15
+ import { createDiscordReplies, } from "../channels/discord-replies.js";
15
16
  import { isDiscordBinding, createDiscordBindings, createDiscordInputSchema, updateDiscordInputSchema, } from "../channels/discord-binding.js";
16
- import { DISCORD_ANSWER_WINDOW_MS, DISCORD_SETTLEMENT_POLL_MS, discordDenial, patchOriginal, quoted, 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";
17
18
  import { discordOutcome, sealDiscordToken, } from "./discord-channels.js";
18
19
  import { channelSessionDoor } from "./channel-session-door.js";
19
20
  import { createAuthenticatedVisitorChannel } from "../channels/visitor-channel.js";
@@ -374,68 +375,156 @@ export class StandaloneAgentBase extends ShiitakeDO {
374
375
  }
375
376
  /**
376
377
  * A verified Discord question for this Agent. The public edge has already
377
- * checked the application's signature and the guild and channel; this
378
- * accepts the work and returns at once, and the answer follows by the
379
- * interaction webhook once the run settles.
378
+ * checked the application's signature and the guild and channel. The reply
379
+ * is recorded as owed before anything else, then paid off by the Agent's
380
+ * durable host work: an Agent evicted mid-run still answers when it wakes.
380
381
  */
381
382
  askDiscord(bindingId, ask) {
382
- this.ctx.waitUntil(this.answerDiscord(bindingId, ask).catch((cause) => {
383
- console.error("discord answer failed", cause);
383
+ this.discordReplies().record(bindingId, ask);
384
+ this.ctx.waitUntil(this.wakeRuntime().catch((cause) => {
385
+ console.error("discord reply wake failed", cause);
384
386
  }));
385
387
  }
386
- async answerDiscord(bindingId, ask) {
387
- const say = (content, withReply) => patchOriginal(fetch, {
388
- applicationId: ask.applicationId,
389
- interactionToken: ask.interactionToken,
390
- content,
391
- withReply,
392
- });
388
+ discordReplyOwner;
389
+ discordReplies() {
390
+ return (this.discordReplyOwner ??= createDiscordReplies({
391
+ sql: this.ctx.storage.sql,
392
+ now: () => Date.now(),
393
+ deliver: (reply) => this.deliverDiscord(reply),
394
+ onExpired: (interactionId) => {
395
+ console.warn("discord reply expired undelivered", interactionId);
396
+ },
397
+ }));
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
+ }
407
+ /** The Discord replies this Agent owes; a full option override must run it. */
408
+ discordReplyWork() {
409
+ return this.discordReplies().work;
410
+ }
411
+ /** Replies of one Discord binding that never reached Discord; the host admits the owner first. */
412
+ async discordUndelivered(bindingId) {
393
413
  const binding = await this.loadChannelBinding(bindingId);
414
+ return binding === null ? [] : this.discordReplies().closed(bindingId);
415
+ }
416
+ /** One attempt at one owed reply; intake is idempotent per interaction. */
417
+ async deliverDiscord(reply) {
418
+ const { ask } = reply;
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) => {
423
+ try {
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,
439
+ withReply,
440
+ mentionUserId: index === 0 ? ask.userId : null,
441
+ });
442
+ }
443
+ catch (cause) {
444
+ console.warn("discord reply delivery failed", cause instanceof Error ? cause.name : "unknown");
445
+ return "retry";
446
+ }
447
+ };
448
+ const say = (content, withReply) => sayPart(content, 0, withReply);
449
+ const binding = await this.loadChannelBinding(reply.bindingId);
394
450
  if (binding === null ||
395
451
  !isDiscordBinding(binding) ||
396
- binding.lifecycle !== "active") {
397
- await say("This Agent is not available right now.", false);
398
- return;
452
+ binding.lifecycle !== "active")
453
+ return say("This Agent is not available right now.", false);
454
+ let accepted = reply.accepted;
455
+ if (accepted === null) {
456
+ const result = await this.channelConversations().receive({
457
+ bindingId: reply.bindingId,
458
+ conversation: `${ask.guildId}:${ask.channelId}:${ask.userId}`,
459
+ eventId: ask.interactionId,
460
+ party: {
461
+ kind: "discord-user",
462
+ guildId: ask.guildId,
463
+ userId: ask.userId,
464
+ displayName: ask.displayName,
465
+ },
466
+ text: ask.text,
467
+ });
468
+ if (result.kind === "denied")
469
+ return say(discordDenial[result.reason], false);
470
+ if (result.kind === "held")
471
+ return say("A person has taken over this conversation.", false);
472
+ accepted = { sessionId: result.sessionId, commandId: result.commandId };
473
+ this.discordReplies().attach(reply.interactionId, accepted);
399
474
  }
400
- const result = await this.channelConversations().receive({
401
- bindingId,
402
- conversation: `${ask.guildId}:${ask.channelId}:${ask.userId}`,
403
- eventId: ask.interactionId,
404
- party: {
405
- kind: "discord-user",
406
- guildId: ask.guildId,
407
- userId: ask.userId,
408
- },
409
- text: ask.text,
475
+ const session = (await this.shiitake()).session(accepted.sessionId);
476
+ const settlement = await session.readSettlement(accepted.commandId, {
477
+ timeoutMs: this.discordSettlementWaitMs(),
410
478
  });
411
- if (result.kind === "denied") {
412
- await say(discordDenial[result.reason], false);
413
- return;
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
+ }
486
+ return "waiting";
414
487
  }
415
- if (result.kind === "held") {
416
- await say("A person has taken over this conversation.", false);
417
- return;
488
+ const answered = settlement.terminal.outcome === "completed" &&
489
+ settlement.content.trim().length > 0;
490
+ if (!answered) {
491
+ // The host words a model failure on the run's last assistant message;
492
+ // the settlement's own diagnostic only names the runtime's reason.
493
+ const { messages } = await session.read({ limit: 20 });
494
+ const modelFailure = messages
495
+ .toReversed()
496
+ .find(({ value }) => value.role === "assistant" && value.errorMessage !== undefined);
497
+ return say(discordFailureText({
498
+ outcome: settlement.terminal.outcome,
499
+ diagnostic: modelFailure?.value.role === "assistant"
500
+ ? (modelFailure.value.errorMessage ?? null)
501
+ : settlement.terminal.diagnostic,
502
+ }), false);
418
503
  }
419
- const session = (await this.shiitake()).session(result.sessionId);
420
- const deadline = Date.now() + DISCORD_ANSWER_WINDOW_MS;
421
- let settlement;
422
- while (settlement === undefined && Date.now() < deadline)
423
- settlement = await session.readSettlement(result.commandId, {
424
- timeoutMs: DISCORD_SETTLEMENT_POLL_MS,
425
- });
426
- const answer = settlement?.terminal.outcome === "completed" &&
427
- settlement.content.trim().length > 0
504
+ // The member's own quoted words open the first message; the answer follows
505
+ // in as many messages as it takes, in order.
506
+ const parts = splitDiscordMessage(ask.echo === undefined
428
507
  ? settlement.content
429
- : "I could not answer that. Please try again.";
430
- await say(ask.echo === undefined ? answer : `${quoted(ask.echo)}\n\n${answer}`, true);
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);
511
+ let done = reply.deliveredParts;
512
+ for (; done < parts.length; done += 1) {
513
+ const last = done === parts.length - 1;
514
+ const outcome = await sayPart(parts[done] ?? "", done, last);
515
+ if (outcome !== "delivered")
516
+ return outcome;
517
+ this.discordReplies().progress(reply.interactionId, done + 1);
518
+ }
519
+ return "delivered";
431
520
  }
432
- /** Owner read of one website's conversations; the host admits the owner first. */
433
- async websiteConversations(bindingId) {
521
+ /** Owner read of one binding's conversations; the host admits the owner first. */
522
+ async bindingConversations(bindingId) {
434
523
  const binding = await this.loadChannelBinding(bindingId);
435
524
  return binding === null ? [] : this.channelConversations().list(bindingId);
436
525
  }
437
- /** Owner read of one conversation of a website, from its Session. */
438
- async websiteTranscript(bindingId, sessionId) {
526
+ /** Owner read of one conversation of a binding, from its Session. */
527
+ async bindingTranscript(bindingId, sessionId) {
439
528
  const binding = await this.loadChannelBinding(bindingId);
440
529
  const conversation = this.channelConversations().sessionConversation(sessionId);
441
530
  if (binding === null || conversation?.bindingId !== bindingId)
@@ -1108,7 +1197,8 @@ export class StandaloneAgentBase extends ShiitakeDO {
1108
1197
  }
1109
1198
  /**
1110
1199
  * A full override must retain channelSource and channelInstructions:
1111
- * dropping them removes a suspended website's run refusal and turn capture.
1200
+ * dropping them removes a suspended website's run refusal and turn capture,
1201
+ * and it must run discordReplyWork or an evicted Discord run never answers.
1112
1202
  */
1113
1203
  async shiitakeOptions() {
1114
1204
  const [{ oysterAgentExtensions }, { Knapsack }, { agentMcpSourceOptions }, { mcpRequestData },] = await Promise.all([
@@ -1242,7 +1332,11 @@ export class StandaloneAgentBase extends ShiitakeDO {
1242
1332
  this.archiveControl().assertOpen();
1243
1333
  },
1244
1334
  },
1245
- hostWork: [...keeping.hostWork, this.archiveControl().work],
1335
+ hostWork: [
1336
+ ...keeping.hostWork,
1337
+ this.archiveControl().work,
1338
+ this.discordReplyWork(),
1339
+ ],
1246
1340
  };
1247
1341
  }
1248
1342
  /** Send an installation-admitted message through fleet Session operations. */
@@ -1903,6 +1997,24 @@ export class AgentDirectory extends DurableObject {
1903
1997
  }
1904
1998
  return { registered, failed };
1905
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
+ }
1906
2018
  /** Host-only: the website or Discord binding an Agent serves, read fresh on every use. */
1907
2019
  channelBinding(bindingId) {
1908
2020
  return (this.websites().bindings.read(bindingId) ??
@@ -175,13 +175,13 @@ export async function dispatchAppsBuildsBinding(env, scope, frame, props, method
175
175
  appId,
176
176
  sourceRevision: input.sourceRevision,
177
177
  requestedBy,
178
+ callerInstallationId: frame.facts.selection.owner.id,
178
179
  };
179
180
  if (input.installationId !== undefined && workflowRequestId === undefined)
180
181
  throw new AppInstanceError("revoked");
181
182
  if (workflowRequestId !== undefined) {
182
183
  request.workflow = {
183
184
  requestId: workflowRequestId,
184
- callerInstallationId: frame.facts.selection.owner.id,
185
185
  };
186
186
  if (input.installationId !== undefined)
187
187
  request.workflow.installationId = input.installationId;
@@ -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
  },
@@ -1,9 +1,10 @@
1
1
  import { type CredentialStore } from "@fungi.computer/veil/credential-store";
2
2
  import { type Routes } from "../authorization.js";
3
3
  import { type CreateDiscordInput, type DiscordBinding, type UpdateDiscordInput } from "../channels/discord-binding.js";
4
+ import type { WebsiteTranscript } from "@fungi.computer/nacre/website-channels";
5
+ import type { DiscordClosedReply } from "../channels/discord-replies.js";
4
6
  import type { OysterEnv } from "../host.js";
5
7
  import { type TenantPrincipal } from "../tenant.js";
6
- import { agentDirectoryForScope } from "./agent-directory.js";
7
8
  import type { StandaloneAgentsEnv } from "./agents.js";
8
9
  /** Why an owner's Discord command was refused. */
9
10
  export type DiscordRefusal = Readonly<{
@@ -15,6 +16,20 @@ export declare function discordOutcome<T>(command: () => T): T | DiscordRefusal;
15
16
  export declare function sealDiscordToken(vault: CredentialStore, botToken: string): Promise<Readonly<{
16
17
  credentialId: string;
17
18
  }> | DiscordRefusal>;
19
+ /** What the owner's Discord controls call on the directory. */
20
+ export type DiscordDirectoryDoor = Readonly<{
21
+ list: () => Promise<readonly Readonly<{
22
+ agentId: string;
23
+ name: string;
24
+ }>[]>;
25
+ discordList: (principal: TenantPrincipal) => Promise<readonly DiscordBinding[] | DiscordRefusal>;
26
+ discordCreate: (principal: TenantPrincipal, input: CreateDiscordInput, requestId: string) => Promise<DiscordBinding | DiscordRefusal>;
27
+ discordUpdate: (principal: TenantPrincipal, bindingId: string, input: UpdateDiscordInput) => Promise<DiscordBinding | DiscordRefusal>;
28
+ discordRegisterCommands: (principal: TenantPrincipal, bindingId: string) => Promise<Readonly<{
29
+ registered: readonly string[];
30
+ failed: readonly string[];
31
+ }> | DiscordRefusal>;
32
+ }>;
18
33
  /** What the owner's Discord routes need from the directory. */
19
34
  export type StandaloneDiscordControl = Readonly<{
20
35
  read: (principal: TenantPrincipal) => Promise<Readonly<{
@@ -31,9 +46,16 @@ export type StandaloneDiscordControl = Readonly<{
31
46
  registered: readonly string[];
32
47
  failed: readonly string[];
33
48
  }> | DiscordRefusal>;
49
+ conversations: (principal: TenantPrincipal, bindingId: string) => Promise<readonly Readonly<{
50
+ sessionId: string;
51
+ label: string;
52
+ lastEventAt: number;
53
+ }>[]>;
54
+ transcript: (principal: TenantPrincipal, bindingId: string, sessionId: string) => Promise<WebsiteTranscript | null>;
55
+ undelivered: (principal: TenantPrincipal, bindingId: string) => Promise<readonly DiscordClosedReply[]>;
34
56
  }>;
35
57
  /** The owner's Discord controls over the directory. */
36
- export declare function standaloneDiscordControl(env: Pick<StandaloneAgentsEnv, "OYSTER_ORIGIN">, directoryOf: () => ReturnType<typeof agentDirectoryForScope>): StandaloneDiscordControl;
58
+ export declare function standaloneDiscordControl(env: Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN">, directoryOf: () => DiscordDirectoryDoor): StandaloneDiscordControl;
37
59
  /**
38
60
  * The owner's Discord controls. Each route is owner-direct: an App cannot bind
39
61
  * a Discord application, or replace its sealed token, on the owner's behalf.
@@ -12,7 +12,7 @@ import { z } from "zod";
12
12
  import { CredentialError, } from "@fungi.computer/veil/credential-store";
13
13
  import { owner, routes } from "../authorization.js";
14
14
  import { createDiscordInputSchema, DiscordBindingError, updateDiscordInputSchema, discordPlaceAllowed, isDiscordBinding, } from "../channels/discord-binding.js";
15
- import { DISCORD_ASK_LIMIT, ASK_COMMAND, ASK_OPTION, REPLY_ID, REPLY_TEXT_ID, deferredResponse, ephemeralResponse, interactionSchema, pongResponse, replyModalResponse, verifyDiscordRequest, } from "../channels/discord-interactions.js";
15
+ import { DISCORD_ASK_LIMIT, ASK_COMMAND, ASK_OPTION, REPLY_ID, REPLY_TEXT_ID, deferredResponse, discordDisplayName, ephemeralResponse, interactionSchema, pongResponse, replyModalResponse, verifyDiscordRequest, } from "../channels/discord-interactions.js";
16
16
  import { defaultTenant, tenantScope } from "../tenant.js";
17
17
  import { agentDirectoryForScope } from "./agent-directory.js";
18
18
  /** Run one binding command, turning its closed failures into data. */
@@ -46,6 +46,14 @@ export async function sealDiscordToken(vault, botToken) {
46
46
  }
47
47
  /** The owner's Discord controls over the directory. */
48
48
  export function standaloneDiscordControl(env, directoryOf) {
49
+ // Only a binding the directory knows names an Agent whose conversations are read.
50
+ const agentOf = async (principal, bindingId) => {
51
+ const listed = await directoryOf().discordList(principal);
52
+ const binding = "error" in listed
53
+ ? undefined
54
+ : listed.find((item) => item.bindingId === bindingId);
55
+ return binding === undefined ? null : env.AGENTS.getByName(binding.agentId);
56
+ };
49
57
  return {
50
58
  read: async (principal) => {
51
59
  const listed = await directoryOf().discordList(principal);
@@ -61,6 +69,26 @@ export function standaloneDiscordControl(env, directoryOf) {
61
69
  create: (principal, input, requestId) => directoryOf().discordCreate(principal, input, requestId),
62
70
  update: (principal, bindingId, input) => directoryOf().discordUpdate(principal, bindingId, input),
63
71
  registerCommands: (principal, bindingId) => directoryOf().discordRegisterCommands(principal, bindingId),
72
+ conversations: async (principal, bindingId) => {
73
+ const agent = await agentOf(principal, bindingId);
74
+ return agent === null
75
+ ? []
76
+ : (await agent.bindingConversations(bindingId)).map(({ sessionId, label, lastEventAt }) => ({
77
+ sessionId,
78
+ label,
79
+ lastEventAt,
80
+ }));
81
+ },
82
+ transcript: async (principal, bindingId, sessionId) => {
83
+ const agent = await agentOf(principal, bindingId);
84
+ return agent === null
85
+ ? null
86
+ : agent.bindingTranscript(bindingId, sessionId);
87
+ },
88
+ undelivered: async (principal, bindingId) => {
89
+ const agent = await agentOf(principal, bindingId);
90
+ return agent === null ? [] : agent.discordUndelivered(bindingId);
91
+ },
64
92
  };
65
93
  }
66
94
  const refusalStatus = {
@@ -126,6 +154,25 @@ export function standaloneDiscordRoutes(control) {
126
154
  ? context.json(result, refusalStatus[result.error])
127
155
  : context.json(result);
128
156
  });
157
+ table.get("/api/discord/:bindingId/conversations", owner("direct"), async (context, { principal }) => {
158
+ context.header("Cache-Control", "no-store");
159
+ return context.json({
160
+ conversations: await control.conversations(principal, context.req.param("bindingId")),
161
+ });
162
+ });
163
+ table.get("/api/discord/:bindingId/undelivered", owner("direct"), async (context, { principal }) => {
164
+ context.header("Cache-Control", "no-store");
165
+ return context.json({
166
+ undelivered: await control.undelivered(principal, context.req.param("bindingId")),
167
+ });
168
+ });
169
+ table.get("/api/discord/:bindingId/conversations/:sessionId", owner("direct"), async (context, { principal }) => {
170
+ context.header("Cache-Control", "no-store");
171
+ const transcript = await control.transcript(principal, context.req.param("bindingId"), context.req.param("sessionId"));
172
+ return transcript === null
173
+ ? context.json({ error: "not_found" }, 404)
174
+ : context.json(transcript);
175
+ });
129
176
  return table;
130
177
  }
131
178
  /** A request body larger than this is not a Discord interaction. */
@@ -188,6 +235,7 @@ export function standaloneDiscordApp() {
188
235
  channelId,
189
236
  userId,
190
237
  text: trimmed,
238
+ displayName: discordDisplayName(interaction),
191
239
  echo,
192
240
  };
193
241
  // The answer outlives Discord's three seconds; it follows by webhook.
@@ -211,10 +211,13 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
211
211
  appId: string;
212
212
  sourceRevision: string;
213
213
  requestedBy: string;
214
+ /**
215
+ * The installation whose admitted APPS call asks; it must own the source.
216
+ * Omitted only by the host owner's own HTTP build route.
217
+ */
218
+ callerInstallationId?: string;
214
219
  workflow?: {
215
220
  requestId: string;
216
- /** The installation whose admitted Workflow node asks; it must own the source. */
217
- callerInstallationId: string;
218
221
  installationId?: string;
219
222
  };
220
223
  }): Promise<OysterBuildStartResult>;
@@ -416,11 +416,13 @@ export class StandaloneRegistry extends OysterRegistry {
416
416
  sourceRevision: input.sourceRevision,
417
417
  requestedBy: input.requestedBy,
418
418
  };
419
+ // An APPS caller builds only its own installation's registered App. A
420
+ // foreign or template App reads as unregistered, never as another's
421
+ // existence.
422
+ if (input.callerInstallationId !== undefined &&
423
+ !sourceOwnedBy(builds.readSource(input.appId), input.callerInstallationId))
424
+ return { kind: "refused", reason: "no_source" };
419
425
  if (input.workflow !== undefined) {
420
- // A Workflow builds only its own installation's registered App. A
421
- // foreign App reads as unregistered, never as another's existence.
422
- if (!sourceOwnedBy(builds.readSource(input.appId), input.workflow.callerInstallationId))
423
- return { kind: "refused", reason: "no_source" };
424
426
  request.requestId = input.workflow.requestId;
425
427
  if (input.workflow.installationId !== undefined)
426
428
  request.installAt = input.workflow.installationId;
@@ -178,7 +178,7 @@ export function standaloneWebsiteControl(env, directoryOf) {
178
178
  const agent = await agentOf(principal, bindingId);
179
179
  return agent === null
180
180
  ? []
181
- : (await agent.websiteConversations(bindingId)).map(({ sessionId, label, lastEventAt }) => ({
181
+ : (await agent.bindingConversations(bindingId)).map(({ sessionId, label, lastEventAt }) => ({
182
182
  sessionId,
183
183
  label,
184
184
  lastEventAt,
@@ -188,7 +188,7 @@ export function standaloneWebsiteControl(env, directoryOf) {
188
188
  const agent = await agentOf(principal, bindingId);
189
189
  return agent === null
190
190
  ? null
191
- : agent.websiteTranscript(bindingId, sessionId);
191
+ : agent.bindingTranscript(bindingId, sessionId);
192
192
  },
193
193
  };
194
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/oyster",
3
- "version": "0.22.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.10.0",
341
+ "@fungi.computer/agar": "0.11.0",
342
342
  "@fungi.computer/bird-dog": "0.3.6",
343
- "@fungi.computer/braid": "0.4.9",
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.8.8",
350
- "@fungi.computer/computer-contract": "0.1.0",
351
- "@fungi.computer/darkroom": "0.5.9",
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.2",
359
- "@fungi.computer/parakeet": "0.11.21",
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.13.1",
363
- "@fungi.computer/shiitake-extensions": "0.6.13",
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.9",
371
- "@fungi.computer/zookeeper": "0.0.20",
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",