Skip to content
API reference

delegation

Import
import * as api from "@fungi.computer/shiitake/delegation";
Kind Export Description
class AgentDelegation Host-owned identity and admission around BirdDog’s ordinary envelope.
class AgentDisclosureRefused A current correspondent no longer has disclosure authority.
class AgentMail Recipient-owned replies and receipt-bearing submissions over the host’s one Post lane.
type alias DelegationIdentity Shiitake host-pack identity; core consumes OysterAgents, never this engine.
type alias AgentReplySettlement Undefined is an explicit disclosure refusal; missing facts and read errors must fail.
type alias AgentMailPost The host’s one Post lane, as Agent mail borrows it.
constant machineAgentCodecs The Agent wire decoders a host lends Oyster’s machine-link client, so the device link routes Agent work without owning Shiitake’s grammar.
function agentMailRoute() Current disclosure admission runs at every transport attempt, including frozen retries.
function machineAgentReservations() Machine-homed Agent identities in the ordinary directory over the enrollment’s own store: one Team identity per enrollment receipt, reserved without opening a hosted Agent. The enrolling member is the grant actor.

Host-owned identity and admission around BirdDog’s ordinary envelope.

Signature
new AgentDelegation(deps): AgentDelegation;
Parameter Type
deps Readonly<{ storage: WatchdogSqliteOwner; expiresAt: () => number; identity: () => | DelegationIdentity | null | Promise<DelegationIdentity | null>; directory: () => AgentControlDirectory; deliver: (mail) => Promise<DelegationReceipt>; prepare: (mail) => Promise<void>; stageAcceptedNotice: (mail, scopeId) => void; accept: (mail, reply, stageAcceptedNotice) => Promise<Accepted>; }>

AgentDelegation

Signature
settlement(
sender,
sessionId,
commandId,
host
): Promise<
| Readonly<{
acceptedSender: string | null;
terminal: SessionTerminal;
content: string;
usage: readonly Pick<AssistantMessage, "model" | "provider" | "usage">[];
toolCalls: number;
}>
| undefined>;

Recipient-local disclosure through the public host, never another Agent’s RPC.

Parameter Type
sender DelegationIdentity
sessionId string
commandId string
host Pick<ShiitakeHost, "readSettlement">

Promise< | Readonly<{ acceptedSender: string | null; terminal: SessionTerminal; content: string; usage: readonly Pick<AssistantMessage, "model" | "provider" | "usage">[]; toolCalls: number; }> | undefined>

Signature
send(
input,
sourceSessionId,
signal,
invocation?
): Promise<DelegationReceipt>;

Delegate work to an in-scope Agent: steer its Session, or start fleet correspondence.

Parameter Type
input AgentDelegationInput
sourceSessionId string
signal AbortSignal
invocation? Readonly<{ toolCallId: string; sendIndex: number; commandId?: string; meta?: Json; toolCallCode?: string; }>

Promise<DelegationReceipt>

Signature
recall(
input,
sourceSessionId,
signal
): Promise<CancelResult>;

Resolve this sender’s exact request, then let the recipient guard pending work.

Parameter Type
input AgentRecallInput
sourceSessionId string
signal AbortSignal

Promise<CancelResult>

Signature
receive(raw): Promise<PostDeliveryResult>;

Admit one addressed Agent mail for this Agent, or refuse it.

Parameter Type
raw { key: string; kind: string; address: unknown; event: unknown; }
raw.key string
raw.kind string
raw.address unknown
raw.event unknown

Promise<PostDeliveryResult>

Signature
localUndeliverable(original): Promise<PostDeliveryResult>;

Admit local outbox exhaustion through the same Fleet/system reply gate.

Parameter Type
original BirdDogMail

Promise<PostDeliveryResult>


A current correspondent no longer has disclosure authority.

  • Error
Signature
new AgentDisclosureRefused(): AgentDisclosureRefused;

AgentDisclosureRefused

Signature
Error.constructor;

Recipient-owned replies and receipt-bearing submissions over the host’s one Post lane.

Signature
new AgentMail(deps): AgentMail;
Parameter Type
deps Readonly<{ storage: WatchdogSqliteOwner; post: () => AgentMailPost; identity: () => | DelegationIdentity | null | Promise<DelegationIdentity | null>; replySettlement: AgentReplySettlement; onUndeliverable: (original, reply) => Promise<PostDeliveryResult>; drain: () => Promise<void>; wake: () => Promise<void>; }>

AgentMail

Signature
send(mail): Promise<DelegationReceipt>;

Submit one mail and return recipient acceptance or relay-held custody.

Parameter Type
mail BirdDogMail

Promise<DelegationReceipt>

Signature
stageUndeliverableReplies(): Promise<void>;

Reconcile exhausted original outbox mail into one local system reply.

Promise<void>

Signature
stageAcceptedNotice(mail, scopeId): void;

Stage the acceptance reply through this Post owner without leaving the transaction.

Parameter Type
mail BirdDogMail
scopeId string

void

Signature
mailRoom(): Readonly<{
fanOut: (settlement) => Effect<void, BirdDogError>;
postMail?: (mail) => Effect<void, BirdDogError>;
drainOutbox: () => Effect<void, BirdDogError>;
nextWakeAt: () => Effect<number | undefined, BirdDogError>;
}> & object;

BirdDog’s mail room: disclosed settlement replies fan out over Post.

DelegationIdentitytype alias

Section titled “DelegationIdentity”
Signature
type DelegationIdentity = Readonly<{
scopeId: string;
agentId: string;
}>;

Shiitake host-pack identity; core consumes OysterAgents, never this engine.


AgentReplySettlementtype alias

Section titled “AgentReplySettlement”
Signature
type AgentReplySettlement = (mail) => Promise<CommandSettlement | undefined>;

Undefined is an explicit disclosure refusal; missing facts and read errors must fail.

Parameter Type
mail BirdDogMail

Promise<CommandSettlement | undefined>


AgentMailPosttype alias

Section titled “AgentMailPost”
Signature
type AgentMailPost = Pick<
PostRuntime<{
agentMail: ReturnType<typeof agentMailRoute>;
}>,
"send" | "read" | "nextWake" | "deadLetters"
>;

The host’s one Post lane, as Agent mail borrows it.

machineAgentCodecsconstant

Section titled “machineAgentCodecs”
Signature
const machineAgentCodecs: object;

The Agent wire decoders a host lends Oyster’s machine-link client, so the device link routes Agent work without owning Shiitake’s grammar.

Name Type Description
sessionCreation() (body) => | Readonly<{ requestId: string; }> | null The Session-creation intent, or null when the body is not one.
settlement() (encoded) => CommandSettlement One serialized settlement from a hosted or machine-homed Agent.
accepted() (receipt) => void Throws unless an acknowledgment carries a valid acceptance or Held result.

agentMailRoute()function

Section titled “agentMailRoute()”
Signature
function agentMailRoute(namespace, replySettlement): PostRoute<AgentMailAddress,
| {
from: {
kind: "agent";
agentId: string;
sessionId: string;
};
reply?: | {
commandId: string;
outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown";
diagnostic?: string;
}
| {
outcome: "accepted";
commandId: string;
}
| {
outcome: "undeliverable";
reason: "recipient_left";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}
| {
from: {
kind: "system";
systemId: "hub";
};
reply: {
outcome: "undeliverable";
reason: "recipient_offline";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
},
| {
from: {
kind: "agent";
agentId: string;
sessionId: string;
};
reply?: | {
commandId: string;
outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown";
diagnostic?: string;
}
| {
outcome: "accepted";
commandId: string;
}
| {
outcome: "undeliverable";
reason: "recipient_left";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}
| {
from: {
kind: "system";
systemId: "hub";
};
reply: {
outcome: "undeliverable";
reason: "recipient_offline";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}, AgentMailAddress,
| {
from: {
kind: "agent";
agentId: string;
sessionId: string;
};
reply?: | {
commandId: string;
outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown";
diagnostic?: string;
}
| {
outcome: "accepted";
commandId: string;
}
| {
outcome: "undeliverable";
reason: "recipient_left";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}
| {
from: {
kind: "system";
systemId: "hub";
};
reply: {
outcome: "undeliverable";
reason: "recipient_offline";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
},
| {
from: {
kind: "agent";
agentId: string;
sessionId: string;
};
reply?: | {
commandId: string;
outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown";
diagnostic?: string;
}
| {
outcome: "accepted";
commandId: string;
}
| {
outcome: "undeliverable";
reason: "recipient_left";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}
| {
from: {
kind: "system";
systemId: "hub";
};
reply: {
outcome: "undeliverable";
reason: "recipient_offline";
};
key: string;
to: {
kind: "agent";
agentId: string;
sessionId?: string;
};
replyTo: readonly object[];
content: string;
createdAt: number;
meta?: Json | undefined;
}> & Omit<Readonly<{
addressKind: string;
deadlineMs?: number;
address: Codec<unknown, unknown>;
event: Codec<unknown, unknown>;
encodeEnvelope: (envelope) => object;
parseDelivery: (envelope) => object;
prepareEnvelope?: (envelope, signal) => Promise<{
key: string;
kind: string;
address: unknown;
event: unknown;
}>;
recordDelivered?: (envelope) => void;
nameOf: (envelope) => string;
namespace: Readonly<{
getByName: (name) => Readonly<{
deliver: (envelope) => Promise<...>;
}>;
}>;
recordCursor?: (envelope, cursor) => void;
recordRefused?: (envelope) => void;
}>, "event" | "address">;

Current disclosure admission runs at every transport attempt, including frozen retries.

Parameter Type
namespace Readonly<{ getByName: (name) => Readonly<{ deliver: (envelope) => Promise<PostDeliveryResult>; }>; }>
replySettlement AgentReplySettlement

PostRoute<AgentMailAddress, | { from: { kind: "agent"; agentId: string; sessionId: string; }; reply?: | { commandId: string; outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown"; diagnostic?: string; } | { outcome: "accepted"; commandId: string; } | { outcome: "undeliverable"; reason: "recipient_left"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; } | { from: { kind: "system"; systemId: "hub"; }; reply: { outcome: "undeliverable"; reason: "recipient_offline"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; }, | { from: { kind: "agent"; agentId: string; sessionId: string; }; reply?: | { commandId: string; outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown"; diagnostic?: string; } | { outcome: "accepted"; commandId: string; } | { outcome: "undeliverable"; reason: "recipient_left"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; } | { from: { kind: "system"; systemId: "hub"; }; reply: { outcome: "undeliverable"; reason: "recipient_offline"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; }, AgentMailAddress, | { from: { kind: "agent"; agentId: string; sessionId: string; }; reply?: | { commandId: string; outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown"; diagnostic?: string; } | { outcome: "accepted"; commandId: string; } | { outcome: "undeliverable"; reason: "recipient_left"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; } | { from: { kind: "system"; systemId: "hub"; }; reply: { outcome: "undeliverable"; reason: "recipient_offline"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; }, | { from: { kind: "agent"; agentId: string; sessionId: string; }; reply?: | { commandId: string; outcome: "completed" | "failed" | "cancelled" | "interrupted" | "outcome_unknown"; diagnostic?: string; } | { outcome: "accepted"; commandId: string; } | { outcome: "undeliverable"; reason: "recipient_left"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; } | { from: { kind: "system"; systemId: "hub"; }; reply: { outcome: "undeliverable"; reason: "recipient_offline"; }; key: string; to: { kind: "agent"; agentId: string; sessionId?: string; }; replyTo: readonly object[]; content: string; createdAt: number; meta?: Json | undefined; }> & Omit<Readonly<{ addressKind: string; deadlineMs?: number; address: Codec<unknown, unknown>; event: Codec<unknown, unknown>; encodeEnvelope: (envelope) => object; parseDelivery: (envelope) => object; prepareEnvelope?: (envelope, signal) => Promise<{ key: string; kind: string; address: unknown; event: unknown; }>; recordDelivered?: (envelope) => void; nameOf: (envelope) => string; namespace: Readonly<{ getByName: (name) => Readonly<{ deliver: (envelope) => Promise<…>; }>; }>; recordCursor?: (envelope, cursor) => void; recordRefused?: (envelope) => void; }>, "event" | "address">


machineAgentReservations()function

Section titled “machineAgentReservations()”
Signature
function machineAgentReservations(sql): (reservation) => object;

Machine-homed Agent identities in the ordinary directory over the enrollment’s own store: one Team identity per enrollment receipt, reserved without opening a hosted Agent. The enrolling member is the grant actor.

Parameter Type
sql Readonly<{ exec: (statement, …bindings) => WatchdogSqliteCursor; }>

(reservation) => object