@fungi.computer/oyster 0.22.0 → 0.23.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/binding.d.ts +1 -0
- package/dist/channels/binding.js +3 -1
- package/dist/channels/conversations.d.ts +1 -0
- package/dist/channels/conversations.js +15 -1
- package/dist/channels/discord-interactions.d.ts +67 -4
- package/dist/channels/discord-interactions.js +108 -8
- package/dist/channels/discord-replies.d.ts +65 -0
- package/dist/channels/discord-replies.js +182 -0
- package/dist/embed-metafiles.js +1 -1
- package/dist/embed-scripts.js +1 -1
- package/dist/page-script.js +1 -1
- package/dist/standalone/agents.d.ts +28 -9
- package/dist/standalone/agents.js +112 -50
- package/dist/standalone/app-builds-binding.js +1 -1
- package/dist/standalone/discord-channels.d.ts +24 -2
- package/dist/standalone/discord-channels.js +49 -1
- package/dist/standalone/registry.d.ts +5 -2
- package/dist/standalone/registry.js +6 -4
- package/dist/standalone/website-channels.js +2 -2
- package/package.json +10 -10
|
@@ -135,16 +135,34 @@ 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
|
|
139
|
-
*
|
|
140
|
-
*
|
|
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
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
private discordReplyOwner;
|
|
144
|
+
private discordReplies;
|
|
145
|
+
/** The Discord replies this Agent owes; a full option override must run it. */
|
|
146
|
+
protected discordReplyWork(): {
|
|
147
|
+
pending: () => {
|
|
148
|
+
due: boolean;
|
|
149
|
+
nextWakeAt: number | null;
|
|
150
|
+
};
|
|
151
|
+
run: () => Promise<void>;
|
|
152
|
+
};
|
|
153
|
+
/** Replies of one Discord binding that never reached Discord; the host admits the owner first. */
|
|
154
|
+
discordUndelivered(bindingId: string): Promise<readonly Readonly<{
|
|
155
|
+
interactionId: string;
|
|
156
|
+
label: string;
|
|
157
|
+
state: "expired" | "failed";
|
|
158
|
+
closedAt: number;
|
|
159
|
+
}>[]>;
|
|
160
|
+
/** One attempt at one owed reply; intake is idempotent per interaction. */
|
|
161
|
+
private deliverDiscord;
|
|
162
|
+
/** Owner read of one binding's conversations; the host admits the owner first. */
|
|
163
|
+
bindingConversations(bindingId: string): Promise<readonly ChannelConversation[]>;
|
|
164
|
+
/** Owner read of one conversation of a binding, from its Session. */
|
|
165
|
+
bindingTranscript(bindingId: string, sessionId: string): Promise<WebsiteTranscript | null>;
|
|
148
166
|
private channelBinding;
|
|
149
167
|
private channelSessionDoor;
|
|
150
168
|
/**
|
|
@@ -273,7 +291,8 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
273
291
|
invalidateMcpConnections(): void;
|
|
274
292
|
/**
|
|
275
293
|
* A full override must retain channelSource and channelInstructions:
|
|
276
|
-
* dropping them removes a suspended website's run refusal and turn capture
|
|
294
|
+
* dropping them removes a suspended website's run refusal and turn capture,
|
|
295
|
+
* and it must run discordReplyWork or an evicted Discord run never answers.
|
|
277
296
|
*/
|
|
278
297
|
protected shiitakeOptions(): Promise<CloudflareShiitakeOptions>;
|
|
279
298
|
/** Send an installation-admitted message through fleet Session operations. */
|
|
@@ -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 {
|
|
17
|
+
import { DISCORD_SETTLEMENT_WAIT_MS, discordDenial, discordFailureText, patchOriginal, postFollowUp, quoted, 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,124 @@ 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
|
|
378
|
-
*
|
|
379
|
-
*
|
|
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.
|
|
383
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
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
|
+
/** The Discord replies this Agent owes; a full option override must run it. */
|
|
400
|
+
discordReplyWork() {
|
|
401
|
+
return this.discordReplies().work;
|
|
402
|
+
}
|
|
403
|
+
/** Replies of one Discord binding that never reached Discord; the host admits the owner first. */
|
|
404
|
+
async discordUndelivered(bindingId) {
|
|
393
405
|
const binding = await this.loadChannelBinding(bindingId);
|
|
406
|
+
return binding === null ? [] : this.discordReplies().closed(bindingId);
|
|
407
|
+
}
|
|
408
|
+
/** One attempt at one owed reply; intake is idempotent per interaction. */
|
|
409
|
+
async deliverDiscord(reply) {
|
|
410
|
+
const { ask } = reply;
|
|
411
|
+
const sayPart = async (content, first, withReply) => {
|
|
412
|
+
try {
|
|
413
|
+
return await (first ? patchOriginal : postFollowUp)(fetch, {
|
|
414
|
+
applicationId: ask.applicationId,
|
|
415
|
+
interactionToken: ask.interactionToken,
|
|
416
|
+
content,
|
|
417
|
+
withReply,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
catch (cause) {
|
|
421
|
+
console.warn("discord reply delivery failed", cause instanceof Error ? cause.name : "unknown");
|
|
422
|
+
return "retry";
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const say = (content, withReply) => sayPart(content, true, withReply);
|
|
426
|
+
const binding = await this.loadChannelBinding(reply.bindingId);
|
|
394
427
|
if (binding === null ||
|
|
395
428
|
!isDiscordBinding(binding) ||
|
|
396
|
-
binding.lifecycle !== "active")
|
|
397
|
-
|
|
398
|
-
|
|
429
|
+
binding.lifecycle !== "active")
|
|
430
|
+
return say("This Agent is not available right now.", false);
|
|
431
|
+
let accepted = reply.accepted;
|
|
432
|
+
if (accepted === null) {
|
|
433
|
+
const result = await this.channelConversations().receive({
|
|
434
|
+
bindingId: reply.bindingId,
|
|
435
|
+
conversation: `${ask.guildId}:${ask.channelId}:${ask.userId}`,
|
|
436
|
+
eventId: ask.interactionId,
|
|
437
|
+
party: {
|
|
438
|
+
kind: "discord-user",
|
|
439
|
+
guildId: ask.guildId,
|
|
440
|
+
userId: ask.userId,
|
|
441
|
+
displayName: ask.displayName,
|
|
442
|
+
},
|
|
443
|
+
text: ask.text,
|
|
444
|
+
});
|
|
445
|
+
if (result.kind === "denied")
|
|
446
|
+
return say(discordDenial[result.reason], false);
|
|
447
|
+
if (result.kind === "held")
|
|
448
|
+
return say("A person has taken over this conversation.", false);
|
|
449
|
+
accepted = { sessionId: result.sessionId, commandId: result.commandId };
|
|
450
|
+
this.discordReplies().attach(reply.interactionId, accepted);
|
|
399
451
|
}
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
eventId: ask.interactionId,
|
|
404
|
-
party: {
|
|
405
|
-
kind: "discord-user",
|
|
406
|
-
guildId: ask.guildId,
|
|
407
|
-
userId: ask.userId,
|
|
408
|
-
},
|
|
409
|
-
text: ask.text,
|
|
452
|
+
const session = (await this.shiitake()).session(accepted.sessionId);
|
|
453
|
+
const settlement = await session.readSettlement(accepted.commandId, {
|
|
454
|
+
timeoutMs: DISCORD_SETTLEMENT_WAIT_MS,
|
|
410
455
|
});
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
456
|
+
if (settlement === undefined)
|
|
457
|
+
return "waiting";
|
|
458
|
+
const answered = settlement.terminal.outcome === "completed" &&
|
|
459
|
+
settlement.content.trim().length > 0;
|
|
460
|
+
if (!answered) {
|
|
461
|
+
// The host words a model failure on the run's last assistant message;
|
|
462
|
+
// the settlement's own diagnostic only names the runtime's reason.
|
|
463
|
+
const { messages } = await session.read({ limit: 20 });
|
|
464
|
+
const modelFailure = messages
|
|
465
|
+
.toReversed()
|
|
466
|
+
.find(({ value }) => value.role === "assistant" && value.errorMessage !== undefined);
|
|
467
|
+
return say(discordFailureText({
|
|
468
|
+
outcome: settlement.terminal.outcome,
|
|
469
|
+
diagnostic: modelFailure?.value.role === "assistant"
|
|
470
|
+
? (modelFailure.value.errorMessage ?? null)
|
|
471
|
+
: settlement.terminal.diagnostic,
|
|
472
|
+
}), false);
|
|
418
473
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
|
474
|
+
// The member's own quoted words open the first message; the answer follows
|
|
475
|
+
// in as many messages as it takes, in order.
|
|
476
|
+
const parts = splitDiscordMessage(ask.echo === undefined
|
|
428
477
|
? settlement.content
|
|
429
|
-
:
|
|
430
|
-
|
|
478
|
+
: `${quoted(ask.echo)}\n\n${settlement.content}`);
|
|
479
|
+
let done = reply.deliveredParts;
|
|
480
|
+
for (; done < parts.length; done += 1) {
|
|
481
|
+
const last = done === parts.length - 1;
|
|
482
|
+
const outcome = await sayPart(parts[done] ?? "", done === 0, last);
|
|
483
|
+
if (outcome !== "delivered")
|
|
484
|
+
return outcome;
|
|
485
|
+
this.discordReplies().progress(reply.interactionId, done + 1);
|
|
486
|
+
}
|
|
487
|
+
return "delivered";
|
|
431
488
|
}
|
|
432
|
-
/** Owner read of one
|
|
433
|
-
async
|
|
489
|
+
/** Owner read of one binding's conversations; the host admits the owner first. */
|
|
490
|
+
async bindingConversations(bindingId) {
|
|
434
491
|
const binding = await this.loadChannelBinding(bindingId);
|
|
435
492
|
return binding === null ? [] : this.channelConversations().list(bindingId);
|
|
436
493
|
}
|
|
437
|
-
/** Owner read of one conversation of a
|
|
438
|
-
async
|
|
494
|
+
/** Owner read of one conversation of a binding, from its Session. */
|
|
495
|
+
async bindingTranscript(bindingId, sessionId) {
|
|
439
496
|
const binding = await this.loadChannelBinding(bindingId);
|
|
440
497
|
const conversation = this.channelConversations().sessionConversation(sessionId);
|
|
441
498
|
if (binding === null || conversation?.bindingId !== bindingId)
|
|
@@ -1108,7 +1165,8 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
1108
1165
|
}
|
|
1109
1166
|
/**
|
|
1110
1167
|
* A full override must retain channelSource and channelInstructions:
|
|
1111
|
-
* dropping them removes a suspended website's run refusal and turn capture
|
|
1168
|
+
* dropping them removes a suspended website's run refusal and turn capture,
|
|
1169
|
+
* and it must run discordReplyWork or an evicted Discord run never answers.
|
|
1112
1170
|
*/
|
|
1113
1171
|
async shiitakeOptions() {
|
|
1114
1172
|
const [{ oysterAgentExtensions }, { Knapsack }, { agentMcpSourceOptions }, { mcpRequestData },] = await Promise.all([
|
|
@@ -1242,7 +1300,11 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
1242
1300
|
this.archiveControl().assertOpen();
|
|
1243
1301
|
},
|
|
1244
1302
|
},
|
|
1245
|
-
hostWork: [
|
|
1303
|
+
hostWork: [
|
|
1304
|
+
...keeping.hostWork,
|
|
1305
|
+
this.archiveControl().work,
|
|
1306
|
+
this.discordReplyWork(),
|
|
1307
|
+
],
|
|
1246
1308
|
};
|
|
1247
1309
|
}
|
|
1248
1310
|
/** Send an installation-admitted message through fleet Session operations. */
|
|
@@ -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;
|
|
@@ -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: () =>
|
|
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.
|
|
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.
|
|
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.
|
|
3
|
+
"version": "0.23.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,9 +338,9 @@
|
|
|
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.
|
|
341
|
+
"@fungi.computer/agar": "0.10.1",
|
|
342
342
|
"@fungi.computer/bird-dog": "0.3.6",
|
|
343
|
-
"@fungi.computer/braid": "0.4.
|
|
343
|
+
"@fungi.computer/braid": "0.4.10",
|
|
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",
|
|
@@ -348,27 +348,27 @@
|
|
|
348
348
|
"@fungi.computer/carrier": "0.2.4",
|
|
349
349
|
"@fungi.computer/computer": "0.8.8",
|
|
350
350
|
"@fungi.computer/computer-contract": "0.1.0",
|
|
351
|
-
"@fungi.computer/darkroom": "0.5.
|
|
351
|
+
"@fungi.computer/darkroom": "0.5.10",
|
|
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.3",
|
|
359
|
+
"@fungi.computer/parakeet": "0.11.22",
|
|
360
360
|
"@fungi.computer/puffball": "0.5.5",
|
|
361
361
|
"@fungi.computer/seam": "0.2.5",
|
|
362
|
-
"@fungi.computer/shiitake": "0.
|
|
363
|
-
"@fungi.computer/shiitake-extensions": "0.6.
|
|
362
|
+
"@fungi.computer/shiitake": "0.14.0",
|
|
363
|
+
"@fungi.computer/shiitake-extensions": "0.6.14",
|
|
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.10",
|
|
371
|
+
"@fungi.computer/zookeeper": "0.0.21",
|
|
372
372
|
"@modelcontextprotocol/server": "2.0.0",
|
|
373
373
|
"@pnpm/lockfile.fs": "1100.2.13",
|
|
374
374
|
"@pnpm/lockfile.pruner": "1100.0.27",
|