@fungi.computer/shiitake 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +454 -2
- package/dist/agar-extension.d.ts +9 -0
- package/dist/agar-extension.js +38 -0
- package/dist/agent-control.d.ts +77 -0
- package/dist/agent-control.js +434 -0
- package/dist/client-entry.d.ts +211 -0
- package/dist/client-entry.js +101 -0
- package/dist/client-wire.d.ts +199 -0
- package/dist/client-wire.js +271 -0
- package/dist/client.d.ts +439 -0
- package/dist/client.js +4 -0
- package/dist/cloudflare.d.ts +220 -0
- package/dist/cloudflare.js +531 -0
- package/dist/effect.d.ts +42 -0
- package/dist/effect.js +20 -0
- package/dist/errors.d.ts +50 -0
- package/dist/errors.js +81 -0
- package/dist/extension-client.d.ts +38 -0
- package/dist/extension-client.js +56 -0
- package/dist/extension-contract.d.ts +73 -0
- package/dist/extension-contract.js +11 -0
- package/dist/extensions.d.ts +589 -0
- package/dist/extensions.js +263 -0
- package/dist/fleet.d.ts +313 -0
- package/dist/fleet.js +540 -0
- package/dist/hosted.d.ts +133 -0
- package/dist/hosted.js +265 -0
- package/dist/http-routes.d.ts +772 -0
- package/dist/http-routes.js +242 -0
- package/dist/http.d.ts +1 -0
- package/dist/http.js +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +13 -0
- package/dist/internal/accepted-run-executor.d.ts +23 -0
- package/dist/internal/accepted-run-executor.js +129 -0
- package/dist/internal/admission-door.d.ts +75 -0
- package/dist/internal/admission-door.js +105 -0
- package/dist/internal/agent-close.d.ts +4 -0
- package/dist/internal/agent-close.js +42 -0
- package/dist/internal/browser-sessions.d.ts +31 -0
- package/dist/internal/browser-sessions.js +173 -0
- package/dist/internal/client-boundary.d.ts +262 -0
- package/dist/internal/client-boundary.js +202 -0
- package/dist/internal/compaction/compaction.d.ts +54 -0
- package/dist/internal/compaction/compaction.js +291 -0
- package/dist/internal/compaction/session-compaction.d.ts +69 -0
- package/dist/internal/compaction/session-compaction.js +330 -0
- package/dist/internal/compaction/settings.d.ts +11 -0
- package/dist/internal/compaction/settings.js +40 -0
- package/dist/internal/compaction/utils.d.ts +45 -0
- package/dist/internal/compaction/utils.js +319 -0
- package/dist/internal/contracts.d.ts +235 -0
- package/dist/internal/contracts.js +1 -0
- package/dist/internal/coordinator.d.ts +18 -0
- package/dist/internal/coordinator.js +362 -0
- package/dist/internal/document-codec.d.ts +11 -0
- package/dist/internal/document-codec.js +39 -0
- package/dist/internal/effect-client.d.ts +13 -0
- package/dist/internal/effect-client.js +102 -0
- package/dist/internal/effect-contracts.d.ts +236 -0
- package/dist/internal/effect-contracts.js +2 -0
- package/dist/internal/extension-command-registry.d.ts +11 -0
- package/dist/internal/extension-command-registry.js +29 -0
- package/dist/internal/extension-command-tools.d.ts +17 -0
- package/dist/internal/extension-command-tools.js +50 -0
- package/dist/internal/extension-context.d.ts +25 -0
- package/dist/internal/extension-context.js +35 -0
- package/dist/internal/extension-definitions.d.ts +5 -0
- package/dist/internal/extension-definitions.js +6 -0
- package/dist/internal/extension-hook.d.ts +25 -0
- package/dist/internal/extension-hook.js +46 -0
- package/dist/internal/extension-roster.d.ts +23 -0
- package/dist/internal/extension-roster.js +228 -0
- package/dist/internal/extension-runtime.d.ts +63 -0
- package/dist/internal/extension-runtime.js +1004 -0
- package/dist/internal/failure.d.ts +2 -0
- package/dist/internal/failure.js +9 -0
- package/dist/internal/host-meta.d.ts +41 -0
- package/dist/internal/host-meta.js +39 -0
- package/dist/internal/json-value.d.ts +4 -0
- package/dist/internal/json-value.js +3 -0
- package/dist/internal/model-acquisition.d.ts +21 -0
- package/dist/internal/model-acquisition.js +98 -0
- package/dist/internal/model-preference.d.ts +21 -0
- package/dist/internal/model-preference.js +20 -0
- package/dist/internal/observation-kernel.d.ts +28 -0
- package/dist/internal/observation-kernel.js +169 -0
- package/dist/internal/promise-facade.d.ts +18 -0
- package/dist/internal/promise-facade.js +172 -0
- package/dist/internal/run-scope.d.ts +27 -0
- package/dist/internal/run-scope.js +214 -0
- package/dist/internal/runtime-coordinator.d.ts +34 -0
- package/dist/internal/runtime-coordinator.js +233 -0
- package/dist/internal/runtime-core.d.ts +19 -0
- package/dist/internal/runtime-core.js +39 -0
- package/dist/internal/runtime-reconciliation.d.ts +18 -0
- package/dist/internal/runtime-reconciliation.js +162 -0
- package/dist/internal/session-context.d.ts +11 -0
- package/dist/internal/session-context.js +67 -0
- package/dist/internal/session-status.d.ts +10 -0
- package/dist/internal/session-status.js +52 -0
- package/dist/internal/woodstock/agent-reply.d.ts +25 -0
- package/dist/internal/woodstock/agent-reply.js +67 -0
- package/dist/internal/woodstock/client-projection.d.ts +29 -0
- package/dist/internal/woodstock/client-projection.js +512 -0
- package/dist/internal/woodstock/compaction-activity.d.ts +17 -0
- package/dist/internal/woodstock/compaction-activity.js +32 -0
- package/dist/internal/woodstock/cursor.d.ts +9 -0
- package/dist/internal/woodstock/cursor.js +44 -0
- package/dist/internal/woodstock/extension-store.d.ts +72 -0
- package/dist/internal/woodstock/extension-store.js +262 -0
- package/dist/internal/woodstock/fleet-store.d.ts +36 -0
- package/dist/internal/woodstock/fleet-store.js +100 -0
- package/dist/internal/woodstock/identities.d.ts +6 -0
- package/dist/internal/woodstock/identities.js +11 -0
- package/dist/internal/woodstock/index.d.ts +170 -0
- package/dist/internal/woodstock/index.js +546 -0
- package/dist/internal/woodstock/progress.d.ts +32 -0
- package/dist/internal/woodstock/progress.js +89 -0
- package/dist/internal/woodstock/run-recovery.d.ts +8 -0
- package/dist/internal/woodstock/run-recovery.js +95 -0
- package/dist/internal/woodstock/session-attention.d.ts +16 -0
- package/dist/internal/woodstock/session-attention.js +88 -0
- package/dist/internal/woodstock/session-documents.d.ts +18 -0
- package/dist/internal/woodstock/session-documents.js +51 -0
- package/dist/internal/woodstock/session-entry.d.ts +478 -0
- package/dist/internal/woodstock/session-entry.js +484 -0
- package/dist/internal/woodstock/session-grants.d.ts +24 -0
- package/dist/internal/woodstock/session-grants.js +84 -0
- package/dist/internal/woodstock/session-inbox.d.ts +56 -0
- package/dist/internal/woodstock/session-inbox.js +307 -0
- package/dist/internal/woodstock/session-store.d.ts +432 -0
- package/dist/internal/woodstock/session-store.js +2006 -0
- package/dist/internal/woodstock/storage-admission.d.ts +14 -0
- package/dist/internal/woodstock/storage-admission.js +44 -0
- package/dist/model-preference.d.ts +20 -0
- package/dist/model-preference.js +30 -0
- package/dist/node.d.ts +64 -0
- package/dist/node.js +256 -0
- package/dist/remote-client.d.ts +11 -0
- package/dist/remote-client.js +298 -0
- package/dist/session-attention.d.ts +35 -0
- package/dist/session-attention.js +22 -0
- package/dist/session-documents.d.ts +28 -0
- package/dist/session-documents.js +1 -0
- package/dist/testing.d.ts +54 -0
- package/dist/testing.js +215 -0
- package/docs/api/README.md +26 -0
- package/docs/api/agar-extension.md +40 -0
- package/docs/api/agent-control.md +151 -0
- package/docs/api/client-entry.md +344 -0
- package/docs/api/client.md +1112 -0
- package/docs/api/cloudflare.md +500 -0
- package/docs/api/effect.md +884 -0
- package/docs/api/extensions.md +2003 -0
- package/docs/api/fleet.md +734 -0
- package/docs/api/hosted.md +382 -0
- package/docs/api/http.md +111 -0
- package/docs/api/index.md +1116 -0
- package/docs/api/model-preference.md +151 -0
- package/docs/api/node.md +142 -0
- package/docs/api/testing.md +250 -0
- package/package.json +130 -3
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import type { SessionAttention } from "./session-attention.js";
|
|
2
|
+
export { type SessionAttention } from "./session-attention.js";
|
|
3
|
+
import type { SandboxFailureEvent } from "@fungi.computer/mycelium";
|
|
4
|
+
import type { ModelPreference } from "./internal/model-preference.js";
|
|
5
|
+
import type { Message } from "@fungi.computer/mule/effect";
|
|
6
|
+
import type { ExtensionSlotV0, ExtensionStatusV0, Json } from "./extensions.js";
|
|
7
|
+
import type { AbortCommand, BranchCommand, CompactCommand, OperatorCommand, TitleCommand, CancelCommand, ForkCommand, PromptCommand, PromptDelivery, SessionCommand } from "./internal/client-boundary.js";
|
|
8
|
+
export { createShiitakeClient, type ShiitakeClientOptions, } from "./remote-client.js";
|
|
9
|
+
export { bindAgentExtension, bindSessionExtension, type BoundAgentExtensionV0, type BoundCallV0, type BoundSessionExtensionV0, type ExtensionViewV0, type ScopedCommandsV0, } from "./extension-client.js";
|
|
10
|
+
export { AcceptedSchema, parseAccepted, parseCancelResult, parseForkedSession, parseSessionFrame, parseSessionSnapshot, parseSessionSummaryPage, parseShiitakeError, } from "./client-wire.js";
|
|
11
|
+
export type { AbortCommand, BranchCommand, CompactCommand, CancelCommand, ForkCommand, OperatorCommand, PromptCommand, PromptDelivery, SessionCommand, TitleCommand, } from "./internal/client-boundary.js";
|
|
12
|
+
/** Semantic acknowledgement returned after one durable acceptance commit. */
|
|
13
|
+
export type Accepted = Readonly<{
|
|
14
|
+
/** Indicates that the owner transaction committed. */
|
|
15
|
+
status: "accepted";
|
|
16
|
+
/** Owner-issued durable identity for the accepted work. */
|
|
17
|
+
commandId: string;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Cancelling found nothing left to cancel: the command is unknown to this
|
|
21
|
+
* Session, has already started (for an `onlyIfPending` cancel) or has already
|
|
22
|
+
* settled. It is an ordinary outcome, never an error.
|
|
23
|
+
*/
|
|
24
|
+
export type TooLate = Readonly<{
|
|
25
|
+
status: "too_late";
|
|
26
|
+
/** The command the caller tried to cancel. */
|
|
27
|
+
commandId: string;
|
|
28
|
+
}>;
|
|
29
|
+
/** Outcome of one cancel command. */
|
|
30
|
+
export type CancelResult = Accepted | TooLate;
|
|
31
|
+
/** Result returned after a fork commits a new cold-readable Session. */
|
|
32
|
+
export type ForkedSession = Readonly<{
|
|
33
|
+
/** Identity of the newly created Session. */
|
|
34
|
+
sessionId: string;
|
|
35
|
+
}>;
|
|
36
|
+
/** Execute one retained type-discriminated Session command. */
|
|
37
|
+
export type SessionCommandHandler = {
|
|
38
|
+
/** Accept a prompt or a compaction request as queued Session work. */
|
|
39
|
+
(input: PromptCommand | CompactCommand): Promise<Accepted>;
|
|
40
|
+
/** Cancel one accepted command, or report that it is too late. */
|
|
41
|
+
(input: CancelCommand): Promise<CancelResult>;
|
|
42
|
+
/** Abort the active run, select a lineage leaf, record an operator line, or set the title. */
|
|
43
|
+
(input: AbortCommand | BranchCommand | OperatorCommand | TitleCommand): Promise<undefined>;
|
|
44
|
+
/** Fork one complete entry lineage into a new Session. */
|
|
45
|
+
(input: ForkCommand): Promise<ForkedSession>;
|
|
46
|
+
/** Execute an already-decoded command union. */
|
|
47
|
+
(input: SessionCommand): Promise<Accepted | CancelResult | ForkedSession | undefined>;
|
|
48
|
+
};
|
|
49
|
+
/** Optional controls for the Promise-friendly text sender. */
|
|
50
|
+
export type SendOptions = Readonly<{
|
|
51
|
+
/** Images retained alongside text in the accepted user message. */
|
|
52
|
+
images?: PromptCommand["images"];
|
|
53
|
+
/** Deliver at the next safe active-run boundary or after the current run. */
|
|
54
|
+
delivery?: PromptDelivery;
|
|
55
|
+
/** Private retry key, generated once when omitted; not the admitted command ID. */
|
|
56
|
+
requestId?: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** One exact completed Pi message on the selected Session lineage. */
|
|
59
|
+
export type SessionMessage = Readonly<{
|
|
60
|
+
/**
|
|
61
|
+
* Opaque metadata the in-process host attached; Shiitake never reads it.
|
|
62
|
+
* Decode it with the host's own schema.
|
|
63
|
+
*/
|
|
64
|
+
meta?: Json;
|
|
65
|
+
/** Durable extension producer of this user message; absent for human prompts. */
|
|
66
|
+
origin?: Readonly<{
|
|
67
|
+
extensionId: string;
|
|
68
|
+
correlation: string | null;
|
|
69
|
+
}>;
|
|
70
|
+
/** Stable conversation identity; live progress completes under this value. */
|
|
71
|
+
id: string;
|
|
72
|
+
/** Woodstock order of the durable entry carrying this message. */
|
|
73
|
+
sequence: number;
|
|
74
|
+
/** Owner-issued accepted work correlation for this message, otherwise null. */
|
|
75
|
+
commandId: string | null;
|
|
76
|
+
/** Exact Pi message; Shiitake does not normalize provider replay metadata. */
|
|
77
|
+
value: Message;
|
|
78
|
+
}>;
|
|
79
|
+
/** Minimal constructor seam for runtimes without a global EventSource. */
|
|
80
|
+
export type ShiitakeEventSourceConstructor = new (url: string) => Pick<EventTarget, "addEventListener"> & Pick<EventSource, "close"> & {
|
|
81
|
+
readonly readyState: number;
|
|
82
|
+
};
|
|
83
|
+
/** Durable outcome for one accepted work item on the selected Session lineage. */
|
|
84
|
+
export type SessionTerminal = Readonly<{
|
|
85
|
+
/** Accepted work correlated through the command's Woodstock work_id. */
|
|
86
|
+
commandId: string;
|
|
87
|
+
/** Durable terminal outcome; this is the settlement authority. */
|
|
88
|
+
outcome: "completed" | "cancelled" | "failed" | "interrupted";
|
|
89
|
+
/** Woodstock order of the durable terminal entry. */
|
|
90
|
+
sequence: number;
|
|
91
|
+
/**
|
|
92
|
+
* The newest failure message the work recorded (an assistant error or a
|
|
93
|
+
* final retry error), exactly as stored; null when it recorded none.
|
|
94
|
+
*/
|
|
95
|
+
diagnostic: string | null;
|
|
96
|
+
/**
|
|
97
|
+
* Opaque host metadata of the command that ended this work: the
|
|
98
|
+
* cancellation's, when a host-attributed cancel ended it. Shiitake never
|
|
99
|
+
* reads it.
|
|
100
|
+
*/
|
|
101
|
+
meta?: Json;
|
|
102
|
+
}>;
|
|
103
|
+
/** Work occupying the executor partition that this queued command requires, without message or provider data. */
|
|
104
|
+
export type AgentRunningWork = Readonly<{
|
|
105
|
+
kind: "session";
|
|
106
|
+
sessionId: string;
|
|
107
|
+
commandId: string;
|
|
108
|
+
}> | Readonly<{
|
|
109
|
+
kind: "host";
|
|
110
|
+
lane: string;
|
|
111
|
+
jobId: string;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Raw facts about what a Session is doing now. Shiitake publishes facts only;
|
|
115
|
+
* a client decides what they mean (see Parakeet's `sessionViewState`).
|
|
116
|
+
*/
|
|
117
|
+
export type SessionActivity = Readonly<{
|
|
118
|
+
/**
|
|
119
|
+
* The Session's place in the Agent's queue. The command id is the accepted
|
|
120
|
+
* work's identity, the one a person may cancel with `onlyIfPending`.
|
|
121
|
+
*/
|
|
122
|
+
queue: Readonly<{
|
|
123
|
+
state: "idle";
|
|
124
|
+
}> | Readonly<{
|
|
125
|
+
state: "queued";
|
|
126
|
+
commandId: string;
|
|
127
|
+
/** Live work ahead of this command; null means no executor work is active. */
|
|
128
|
+
runningWork: AgentRunningWork | null;
|
|
129
|
+
}> | Readonly<{
|
|
130
|
+
state: "running";
|
|
131
|
+
commandId: string;
|
|
132
|
+
}>;
|
|
133
|
+
/** A cancellation of the head work was requested but has not settled. */
|
|
134
|
+
cancellationRequested: boolean;
|
|
135
|
+
/** The running work's latest retry is waiting to be attempted, else null. */
|
|
136
|
+
retry: Readonly<{
|
|
137
|
+
attempt: number;
|
|
138
|
+
maxAttempts: number;
|
|
139
|
+
delayMs: number;
|
|
140
|
+
errorMessage: string;
|
|
141
|
+
/** When the retry was scheduled, in milliseconds since the epoch. */
|
|
142
|
+
scheduledAt: number;
|
|
143
|
+
}> | null;
|
|
144
|
+
/** Tool with an intent but no outcome yet for the running work, else null. */
|
|
145
|
+
activeTool: string | null;
|
|
146
|
+
/** Woodstock order of the newest model choice on the Session, else null. */
|
|
147
|
+
lastModelChoiceSequence: number | null;
|
|
148
|
+
/** A compaction is running now, started by this trigger; else null. */
|
|
149
|
+
compaction: Readonly<{
|
|
150
|
+
trigger: SessionCompactionTrigger;
|
|
151
|
+
}> | null;
|
|
152
|
+
}>;
|
|
153
|
+
/** Encoded extension slots keyed by extension identity; absent means unavailable. */
|
|
154
|
+
export type SessionExtensionSlots = Readonly<Record<string, ExtensionSlotV0>>;
|
|
155
|
+
/** Generic Session-scope extension commands. */
|
|
156
|
+
export type SessionExtensionControls = Readonly<{
|
|
157
|
+
/** Call one Session-scope command with its encoded input; resolves the encoded output. */
|
|
158
|
+
call: (command: string, input: Json) => Promise<Json>;
|
|
159
|
+
}>;
|
|
160
|
+
/** Generic Agent-scope extension controls. */
|
|
161
|
+
export type AgentExtensionControls = Readonly<{
|
|
162
|
+
/** Every rostered extension and whether it is running. */
|
|
163
|
+
list: () => Promise<readonly ExtensionStatusV0[]>;
|
|
164
|
+
/** Resume a stopped extension; it replays its settled backlog once. */
|
|
165
|
+
resume: (extensionId: string) => Promise<ExtensionStatusV0>;
|
|
166
|
+
/** Call one Agent-scope command with its encoded input; resolves the encoded output. */
|
|
167
|
+
call: (extensionId: string, command: string, input: Json) => Promise<Json>;
|
|
168
|
+
}>;
|
|
169
|
+
/** Process-local assistant progress; never a durable Session fact. */
|
|
170
|
+
export type SessionProgress = Readonly<{
|
|
171
|
+
/** Stable message identity shared with the eventual completed Pi message. */
|
|
172
|
+
messageId: string;
|
|
173
|
+
revision: number;
|
|
174
|
+
text: string;
|
|
175
|
+
thinking: string;
|
|
176
|
+
textTruncated: boolean;
|
|
177
|
+
thinkingTruncated: boolean;
|
|
178
|
+
}>;
|
|
179
|
+
/** Accepted prompt waiting to enter the conversation, not a scheduling command. */
|
|
180
|
+
export type SessionPendingPrompt = Readonly<{
|
|
181
|
+
/** Host-admitted metadata, retained opaquely before execution. */
|
|
182
|
+
meta?: SessionMessage["meta"];
|
|
183
|
+
/** Durable extension producer, absent for human prompts. */
|
|
184
|
+
origin?: SessionMessage["origin"];
|
|
185
|
+
/** Owner-issued identity of the waiting accepted work. */
|
|
186
|
+
commandId: string;
|
|
187
|
+
text: string;
|
|
188
|
+
images?: PromptCommand["images"];
|
|
189
|
+
delivery: PromptDelivery;
|
|
190
|
+
}>;
|
|
191
|
+
/** Bounded current admission view, in acceptance order rather than execution order. */
|
|
192
|
+
export type SessionPendingPrompts = Readonly<{
|
|
193
|
+
/** Exact number of waiting admissions, including those outside this page. */
|
|
194
|
+
total: number;
|
|
195
|
+
prompts: readonly SessionPendingPrompt[];
|
|
196
|
+
/** Additional waiting admissions did not fit this view. */
|
|
197
|
+
hasMore: boolean;
|
|
198
|
+
}>;
|
|
199
|
+
/**
|
|
200
|
+
* Minimal full-history compaction boundary marker. `sequence` is the
|
|
201
|
+
* Woodstock order of the row this marker precedes (ties sort the marker
|
|
202
|
+
* first); `at` is when the compaction ran. The agent's model context is
|
|
203
|
+
* unaffected by this marker; it exists only for the client timeline.
|
|
204
|
+
*/
|
|
205
|
+
export type SessionCompactionMarker = Readonly<{
|
|
206
|
+
/** Stable identity of the durable compaction entry. */
|
|
207
|
+
id: string;
|
|
208
|
+
/** Woodstock order of the row this marker immediately precedes. */
|
|
209
|
+
sequence: number;
|
|
210
|
+
/** When the compaction ran, in milliseconds since the epoch. */
|
|
211
|
+
at: number;
|
|
212
|
+
/** Estimated context tokens the compaction started from. */
|
|
213
|
+
tokensBefore: number;
|
|
214
|
+
/** Estimated context tokens right after it; null for older compactions. */
|
|
215
|
+
tokensAfter: number | null;
|
|
216
|
+
/** What started it; null for compactions recorded before triggers were. */
|
|
217
|
+
trigger: SessionCompactionTrigger | null;
|
|
218
|
+
}>;
|
|
219
|
+
/** What started a compaction: the user, the context threshold, or an overflow. */
|
|
220
|
+
export type SessionCompactionTrigger = "manual" | "threshold" | "overflow";
|
|
221
|
+
/**
|
|
222
|
+
* A compaction that changed nothing: a manual request with nothing to
|
|
223
|
+
* summarize yet, or a compaction that failed. Automatic failures are never
|
|
224
|
+
* silent; each one is a notice at its own place in the timeline.
|
|
225
|
+
*/
|
|
226
|
+
export type SessionCompactionNotice = Readonly<{
|
|
227
|
+
/** Stable identity of the durable notice entry. */
|
|
228
|
+
id: string;
|
|
229
|
+
/** Woodstock order of the notice entry. */
|
|
230
|
+
sequence: number;
|
|
231
|
+
/** When it was recorded, in milliseconds since the epoch. */
|
|
232
|
+
at: number;
|
|
233
|
+
trigger: SessionCompactionTrigger;
|
|
234
|
+
result: "nothing_to_compact" | "failed";
|
|
235
|
+
/** A failure's bounded reason; null for "nothing to compact". */
|
|
236
|
+
diagnostic: string | null;
|
|
237
|
+
}>;
|
|
238
|
+
/**
|
|
239
|
+
* The Session's context use as compaction measures it, against the window of
|
|
240
|
+
* the model a run would select now; the window is null when that model
|
|
241
|
+
* reports none.
|
|
242
|
+
*/
|
|
243
|
+
export type SessionContext = Readonly<{
|
|
244
|
+
tokens: number;
|
|
245
|
+
window: number | null;
|
|
246
|
+
}>;
|
|
247
|
+
/** Bounded Session baseline at one opaque owner cursor. */
|
|
248
|
+
export type SessionSnapshot = Readonly<{
|
|
249
|
+
/** Session represented by the snapshot. */
|
|
250
|
+
sessionId: string;
|
|
251
|
+
/** Opaque owner cursor at the snapshot boundary, or null when empty. */
|
|
252
|
+
cursor: string | null;
|
|
253
|
+
/** Whether an older durable entry exists before this bounded page. */
|
|
254
|
+
hasMore: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Opaque cursor naming the oldest row in this page; pass as `before` on
|
|
257
|
+
* `read()` to page further back. Null once no older history remains.
|
|
258
|
+
*/
|
|
259
|
+
oldestCursor?: string | null;
|
|
260
|
+
/** Bounded exact Pi messages visible at the cursor. */
|
|
261
|
+
messages: readonly SessionMessage[];
|
|
262
|
+
/** Durable run_terminal facts visible at the cursor. */
|
|
263
|
+
terminals: readonly SessionTerminal[];
|
|
264
|
+
/** Every compaction boundary marker carried by this bounded page. */
|
|
265
|
+
compactions?: readonly SessionCompactionMarker[];
|
|
266
|
+
/** Every compaction notice carried by this bounded page. */
|
|
267
|
+
compactionNotices?: readonly SessionCompactionNotice[];
|
|
268
|
+
/** Operator diagnostics, excluded from the model conversation. */
|
|
269
|
+
sandboxFailures?: readonly SandboxFailureEvent[];
|
|
270
|
+
/** Current accepted prompts not yet entered or settled. */
|
|
271
|
+
pending: SessionPendingPrompts;
|
|
272
|
+
/** Raw facts about the Session's current activity. */
|
|
273
|
+
activity: SessionActivity;
|
|
274
|
+
/** Latest replaceable progress snapshot, if an assistant message is live. */
|
|
275
|
+
progress: SessionProgress | null;
|
|
276
|
+
/** Encoded projection slot of each extension granted one. */
|
|
277
|
+
extensions: SessionExtensionSlots;
|
|
278
|
+
/** Open requests for human attention from extensions. */
|
|
279
|
+
attention: readonly SessionAttention[];
|
|
280
|
+
/** Context use at the cursor; absent until the Session has context. */
|
|
281
|
+
context?: SessionContext;
|
|
282
|
+
}>;
|
|
283
|
+
/** One bounded replay or live frame. */
|
|
284
|
+
export type SessionFrame = Readonly<{
|
|
285
|
+
/** Bounded Session-projection update discriminator. */
|
|
286
|
+
kind: "update";
|
|
287
|
+
/** Whether replay or a post-commit hint discovered the update. */
|
|
288
|
+
delivery: "replay" | "live";
|
|
289
|
+
/** Opaque cursor naming the last consumed private entry. */
|
|
290
|
+
cursor: string | null;
|
|
291
|
+
/** Current accepted prompts, replaced even when the history cursor is unchanged. */
|
|
292
|
+
pending: SessionPendingPrompts;
|
|
293
|
+
/** Newly visible exact Pi messages, possibly empty for status changes. */
|
|
294
|
+
messages: readonly SessionMessage[];
|
|
295
|
+
/** Durable run_terminal facts carried by this bounded update. */
|
|
296
|
+
terminals: readonly SessionTerminal[];
|
|
297
|
+
/** Compaction markers whose durable entry landed in this bounded update. */
|
|
298
|
+
compactions?: readonly SessionCompactionMarker[];
|
|
299
|
+
/** Compaction notices whose durable entry landed in this bounded update. */
|
|
300
|
+
compactionNotices?: readonly SessionCompactionNotice[];
|
|
301
|
+
/** Operator diagnostics, excluded from the model conversation. */
|
|
302
|
+
sandboxFailures?: readonly SandboxFailureEvent[];
|
|
303
|
+
/** Raw facts about the Session's activity at this cursor. */
|
|
304
|
+
activity: SessionActivity;
|
|
305
|
+
/** Encoded projection slot of each extension granted one. */
|
|
306
|
+
extensions: SessionExtensionSlots;
|
|
307
|
+
/** Open requests for human attention from extensions. */
|
|
308
|
+
attention: readonly SessionAttention[];
|
|
309
|
+
/** Context use at this cursor; absent until the Session has context. */
|
|
310
|
+
context?: SessionContext;
|
|
311
|
+
}> | Readonly<{
|
|
312
|
+
/** Bounded process-local assistant progress. */
|
|
313
|
+
kind: "progress";
|
|
314
|
+
progress: SessionProgress;
|
|
315
|
+
/** Raw facts about the Session's activity read with this progress. */
|
|
316
|
+
activity: SessionActivity;
|
|
317
|
+
}> | Readonly<{
|
|
318
|
+
/** History-reset frame discriminator. */
|
|
319
|
+
kind: "reset";
|
|
320
|
+
/** Stable neutral reason for unavailable continuity. */
|
|
321
|
+
reason: "history_unavailable";
|
|
322
|
+
/** Opaque cursor at the replacement baseline boundary. */
|
|
323
|
+
cursor: string | null;
|
|
324
|
+
/** Fresh owner-atomic replacement baseline. */
|
|
325
|
+
baseline: SessionSnapshot;
|
|
326
|
+
}>;
|
|
327
|
+
/** Strict-after replay request. */
|
|
328
|
+
export type SubscribeOptions = Readonly<{
|
|
329
|
+
/** Explicit operator inspection; never enable for a model capability. */
|
|
330
|
+
includeSandboxFailures?: boolean;
|
|
331
|
+
/** Resume strictly after this opaque cursor when present. */
|
|
332
|
+
after?: string;
|
|
333
|
+
}>;
|
|
334
|
+
/** Bounded baseline request. */
|
|
335
|
+
export type ReadOptions = Readonly<{
|
|
336
|
+
/** Explicit operator inspection; ordinary reads omit private diagnostics. */
|
|
337
|
+
includeSandboxFailures?: boolean;
|
|
338
|
+
/** Maximum number of messages to include in the bounded baseline. */
|
|
339
|
+
limit?: number;
|
|
340
|
+
/**
|
|
341
|
+
* Page strictly before this opaque cursor (from a snapshot's
|
|
342
|
+
* `oldestCursor`) instead of reading the latest page.
|
|
343
|
+
*/
|
|
344
|
+
before?: string;
|
|
345
|
+
}>;
|
|
346
|
+
/** Race-safe observation request. */
|
|
347
|
+
export type WatchOptions = ReadOptions;
|
|
348
|
+
/** Race-safe baseline plus live changes resource. */
|
|
349
|
+
export type SessionWatch = Readonly<{
|
|
350
|
+
/** Race-safe baseline observed before live changes. */
|
|
351
|
+
snapshot: SessionSnapshot;
|
|
352
|
+
/** Live frames after the baseline boundary. */
|
|
353
|
+
changes: AsyncIterable<SessionFrame>;
|
|
354
|
+
/** Release the live observation resources. */
|
|
355
|
+
close: () => Promise<void>;
|
|
356
|
+
}>;
|
|
357
|
+
/** Addressable Session interface. Addressing itself performs no I/O. */
|
|
358
|
+
export type ShiitakeSession = Readonly<{
|
|
359
|
+
/** Stable logical address used to share observation across client mounts. */
|
|
360
|
+
address: string;
|
|
361
|
+
/** Execute one retained type-discriminated Session command. */
|
|
362
|
+
command: SessionCommandHandler;
|
|
363
|
+
/** Cancel the running turn and all queued prompts, retaining their text. */
|
|
364
|
+
abort: () => Promise<void>;
|
|
365
|
+
/** Send text with an optional private caller idempotency identity. */
|
|
366
|
+
send: (text: string, options?: SendOptions) => Promise<Accepted>;
|
|
367
|
+
/** Cancel exactly the accepted work named by its owner-issued identity. */
|
|
368
|
+
cancel: (input: Readonly<{
|
|
369
|
+
commandId: string;
|
|
370
|
+
onlyIfPending?: boolean;
|
|
371
|
+
}>) => Promise<CancelResult>;
|
|
372
|
+
/** Address one rostered extension's Session-scope commands. */
|
|
373
|
+
extension: (extensionId: string) => SessionExtensionControls;
|
|
374
|
+
/** Lineage-local request for later runs; null inherits the Agent default. */
|
|
375
|
+
modelPreference: Readonly<{
|
|
376
|
+
/** Read the saved override; null selects the Agent default. */
|
|
377
|
+
read: () => Promise<ModelPreference | null>;
|
|
378
|
+
/** Save an override for later acquisition without starting a provider call. */
|
|
379
|
+
set: (preference: ModelPreference | null) => Promise<void>;
|
|
380
|
+
}>;
|
|
381
|
+
/** Read a bounded durable baseline. */
|
|
382
|
+
read: (input?: ReadOptions) => Promise<SessionSnapshot>;
|
|
383
|
+
/** Subscribe to strict-after replay and live frames. */
|
|
384
|
+
subscribe: (input: SubscribeOptions) => AsyncIterable<SessionFrame>;
|
|
385
|
+
/** Open a race-safe baseline plus live changes resource. */
|
|
386
|
+
watch: (input?: WatchOptions) => Promise<SessionWatch>;
|
|
387
|
+
}>;
|
|
388
|
+
/**
|
|
389
|
+
* Owner-decided inbox state, from Watchdog's queue head and latest outcome.
|
|
390
|
+
* `running` covers queued, thinking, streaming, retrying and cancelling;
|
|
391
|
+
* `errored` covers failed, interrupted and `outcome_unknown`; `done` covers
|
|
392
|
+
* completed, cancelled and never run. Any open extension attention produces
|
|
393
|
+
* `needs_you`, taking priority over live and settled work.
|
|
394
|
+
*/
|
|
395
|
+
export type SessionInboxState = "needs_you" | "running" | "errored" | "done";
|
|
396
|
+
/** Read-only saved conversation projection; opening does not update recency. */
|
|
397
|
+
export type SessionSummary = Readonly<{
|
|
398
|
+
createdAt: number;
|
|
399
|
+
/** Latest durable conversation change or run transition. */
|
|
400
|
+
lastActivityAt: number;
|
|
401
|
+
/** When the latest run settled; absent until one settles. */
|
|
402
|
+
settledAt?: number;
|
|
403
|
+
title: string;
|
|
404
|
+
state: SessionInboxState;
|
|
405
|
+
}>;
|
|
406
|
+
/** One listed conversation, or a saved Session its owner could not read. */
|
|
407
|
+
export type SessionSummaryRow = (SessionSummary & Readonly<{
|
|
408
|
+
sessionId: string;
|
|
409
|
+
}>) | Readonly<{
|
|
410
|
+
sessionId: string;
|
|
411
|
+
state: "unavailable";
|
|
412
|
+
}>;
|
|
413
|
+
/**
|
|
414
|
+
* One owner-bounded page: `needs_you`, then `running`, then settled rows, each
|
|
415
|
+
* newest activity first. `next` is an opaque owner cursor.
|
|
416
|
+
*/
|
|
417
|
+
export type SessionSummaryPage = Readonly<{
|
|
418
|
+
sessions: readonly SessionSummaryRow[];
|
|
419
|
+
next: string | undefined;
|
|
420
|
+
}>;
|
|
421
|
+
/** Constructed durable harness. */
|
|
422
|
+
export type ShiitakeAgent = Readonly<{
|
|
423
|
+
/** Return the same address when creation is retried with this request ID. */
|
|
424
|
+
createSession: (requestId: string) => Promise<string>;
|
|
425
|
+
/**
|
|
426
|
+
* Permanently delete one idle Session and its history; resolves false when
|
|
427
|
+
* it does not exist. A Session with queued or running work is a conflict.
|
|
428
|
+
*/
|
|
429
|
+
deleteSession: (sessionId: string) => Promise<boolean>;
|
|
430
|
+
/** Enumerate existing conversations without creating or touching them. */
|
|
431
|
+
listSessions: (after?: string) => Promise<SessionSummaryPage>;
|
|
432
|
+
/** List, resume and call rostered extensions. */
|
|
433
|
+
extensions: AgentExtensionControls;
|
|
434
|
+
/** Address a session without performing I/O. */
|
|
435
|
+
session: (sessionId: string) => ShiitakeSession;
|
|
436
|
+
/** Close the owned harness and release resources. */
|
|
437
|
+
close: () => Promise<void>;
|
|
438
|
+
}>;
|
|
439
|
+
export type { ModelPreference } from "./internal/model-preference.js";
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export {} from "./session-attention.js";
|
|
2
|
+
export { createShiitakeClient, } from "./remote-client.js";
|
|
3
|
+
export { bindAgentExtension, bindSessionExtension, } from "./extension-client.js";
|
|
4
|
+
export { AcceptedSchema, parseAccepted, parseCancelResult, parseForkedSession, parseSessionFrame, parseSessionSnapshot, parseSessionSummaryPage, parseShiitakeError, } from "./client-wire.js";
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { CommandSettlement } from "./internal/contracts.js";
|
|
2
|
+
import type { BirdDogMail } from "@fungi.computer/bird-dog";
|
|
3
|
+
import type { VerifiedAgentReply } from "./internal/woodstock/index.js";
|
|
4
|
+
import type { BirdDogEffect } from "@fungi.computer/bird-dog/effect";
|
|
5
|
+
import type { Accepted } from "./client.js";
|
|
6
|
+
import type { HostMetaOptions } from "./internal/host-meta.js";
|
|
7
|
+
import { DurableObject } from "cloudflare:workers";
|
|
8
|
+
import type { CapabilitySource, ModuleRegistration, Sandbox } from "@fungi.computer/mycelium";
|
|
9
|
+
import { type WatchdogExecutionDecision, type WatchdogReadResult, type WatchdogRunningJob, type WatchdogTransactionalProjection, type WatchdogTickResult } from "@fungi.computer/watchdog";
|
|
10
|
+
import type { ExtensionRosterV0, Json } from "./extensions.js";
|
|
11
|
+
import { type ShiitakeHttpEnv } from "./http-routes.js";
|
|
12
|
+
import { Hono } from "hono";
|
|
13
|
+
import type { InstructionSource, ModelSource, GrantsDelivery, GrantsDeliveryResult, ShiitakeOwnerAgent, SqliteOwner, StorageBudget, CompactionOptions, ToolAccess } from "./internal/contracts.js";
|
|
14
|
+
import { type SessionInboxChanges } from "./internal/woodstock/index.js";
|
|
15
|
+
import { type BrowserHost } from "./internal/browser-sessions.js";
|
|
16
|
+
export type { SessionInboxChanges } from "./internal/woodstock/index.js";
|
|
17
|
+
export type { BrowserHost } from "./internal/browser-sessions.js";
|
|
18
|
+
export type { GrantsDelivery, GrantsDeliveryResult, ShiitakeOwnerAgent, ToolAccess, } from "./internal/contracts.js";
|
|
19
|
+
/**
|
|
20
|
+
* Deliver one Session's grants into a Cloudflare owner's own storage,
|
|
21
|
+
* synchronously, whether or not its runtime is open; the very next tool call
|
|
22
|
+
* reads it. A plain function, not a Durable Object method, so no other
|
|
23
|
+
* Durable Object can call it over RPC: only code running inside the owner,
|
|
24
|
+
* holding its storage, delivers grants.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deliverSessionGrantsToStorage(storage: SqliteOwner, sessionId: string, delivery: GrantsDelivery): GrantsDeliveryResult;
|
|
27
|
+
/** Native Durable Object capabilities used by the Cloudflare adapter. */
|
|
28
|
+
export type CloudflareShiitakeState = Readonly<{
|
|
29
|
+
/** Native owner-local SQLite used by Woodstock and Watchdog. */
|
|
30
|
+
storage: SqliteOwner & Pick<DurableObjectStorage, "getAlarm" | "setAlarm" | "deleteAlarm"> & {
|
|
31
|
+
/** Commit an asynchronous owner mutation through native storage. */
|
|
32
|
+
transaction<A>(body: () => Promise<A>): Promise<A>;
|
|
33
|
+
};
|
|
34
|
+
/** Extend the Durable Object event lifetime through runtime reconciliation. */
|
|
35
|
+
waitUntil: (task: Promise<unknown>) => void;
|
|
36
|
+
}>;
|
|
37
|
+
/** Non-empty Mycelium capabilities supplied by a Cloudflare host. */
|
|
38
|
+
export type CloudflareShiitakeTools = Readonly<{
|
|
39
|
+
modules?: readonly ModuleRegistration[];
|
|
40
|
+
sources?: readonly CapabilitySource[];
|
|
41
|
+
sandbox: Sandbox;
|
|
42
|
+
/**
|
|
43
|
+
* The Agent-wide access defaults for every tool of the run, as data. A
|
|
44
|
+
* Session's grants the host delivered with the owner's `grants.deliver` override
|
|
45
|
+
* the default key by key. Mycelium reads them at every call; Shiitake never
|
|
46
|
+
* interprets them. Absent is full access.
|
|
47
|
+
*/
|
|
48
|
+
access?: ToolAccess;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Durable host work that shares Shiitake's one native alarm, such as a
|
|
52
|
+
* host-owned delivery outbox. Shiitake never interprets it.
|
|
53
|
+
*/
|
|
54
|
+
export type CloudflareHostWork = Readonly<{
|
|
55
|
+
/** Read synchronously inside the alarm transaction. */
|
|
56
|
+
pending: () => Readonly<{
|
|
57
|
+
due: boolean;
|
|
58
|
+
nextWakeAt: number | null;
|
|
59
|
+
}>;
|
|
60
|
+
/** One bounded pass, requested independently on every durable wake. */
|
|
61
|
+
run: () => Promise<void>;
|
|
62
|
+
}>;
|
|
63
|
+
/** Host jobs use a separate slot in Shiitake's one Watchdog and native alarm. */
|
|
64
|
+
export type CloudflareHostJobs = Readonly<{
|
|
65
|
+
lane: string;
|
|
66
|
+
/** Open the host executor on the shared transactional job store. */
|
|
67
|
+
open: (runtime: Readonly<{
|
|
68
|
+
transactional: WatchdogTransactionalProjection;
|
|
69
|
+
readJob: (jobId: string) => Promise<WatchdogReadResult>;
|
|
70
|
+
/** Execute one job in the construction-time host partition. */
|
|
71
|
+
tickConcurrent: () => Promise<WatchdogTickResult>;
|
|
72
|
+
}>) => Readonly<{
|
|
73
|
+
/** Execute one job claimed for this host lane. */
|
|
74
|
+
execute: (job: WatchdogRunningJob) => Promise<WatchdogExecutionDecision>;
|
|
75
|
+
}>;
|
|
76
|
+
}>;
|
|
77
|
+
/** ACP's maintained transport, supplied by the host without a package cycle. */
|
|
78
|
+
export type CloudflareShiitakeAcpServer = Readonly<{
|
|
79
|
+
/**
|
|
80
|
+
* Forward an authenticated ACP HTTP request to the maintained SDK server,
|
|
81
|
+
* with the metadata the host's middleware attached to it.
|
|
82
|
+
*/
|
|
83
|
+
handleRequest: (request: Request, meta: Json | undefined) => Promise<Response>;
|
|
84
|
+
}>;
|
|
85
|
+
/** Cloudflare host inputs; the model owner resolves one frozen run selection. */
|
|
86
|
+
export type CloudflareShiitakeOptions = Readonly<{
|
|
87
|
+
/**
|
|
88
|
+
* The schema of the opaque metadata this host attaches to prompts and
|
|
89
|
+
* operator lines. Shiitake checks, stores and returns it; it never reads it.
|
|
90
|
+
*/
|
|
91
|
+
meta?: HostMetaOptions;
|
|
92
|
+
model: ModelSource;
|
|
93
|
+
instructions: InstructionSource;
|
|
94
|
+
tools?: readonly [] | CloudflareShiitakeTools;
|
|
95
|
+
/**
|
|
96
|
+
* Disk budget for this Durable Object's SQLite, measured with
|
|
97
|
+
* `ctx.storage.sql.databaseSize`; absent never refuses for storage pressure.
|
|
98
|
+
*/
|
|
99
|
+
storageBudget?: StorageBudget;
|
|
100
|
+
/** Compaction budgets; absent uses Pi's defaults for every model. */
|
|
101
|
+
compaction?: CompactionOptions;
|
|
102
|
+
/** The host's explicit extension roster and grants; there is no default. */
|
|
103
|
+
extensions: ExtensionRosterV0;
|
|
104
|
+
/**
|
|
105
|
+
* Owner startup work, such as extension commands or storing Session grants,
|
|
106
|
+
* finishes before any durable run or host work is recovered.
|
|
107
|
+
*/
|
|
108
|
+
initialize?: (agent: ShiitakeOwnerAgent) => Promise<void>;
|
|
109
|
+
/** Independent host work kept alive by the same alarm; absent means none. */
|
|
110
|
+
hostWork?: readonly CloudflareHostWork[];
|
|
111
|
+
/** Optional host lane in the same Watchdog; use hostWork for due retries. */
|
|
112
|
+
hostJobs?: CloudflareHostJobs;
|
|
113
|
+
/** Host-owned addressed mail and settlement replies; absent disables mail. */
|
|
114
|
+
mailRoom?: BirdDogEffect;
|
|
115
|
+
/** Session-scoped browser tools and maintained HTTP transport; absent disables it. */
|
|
116
|
+
browser?: (sessionId: string) => BrowserHost;
|
|
117
|
+
/**
|
|
118
|
+
* Lazily open ACP over the owned in-process handle. The host authorizes
|
|
119
|
+
* ingress and supplies its context policy. ACP borrows this handle: closing
|
|
120
|
+
* a protocol connection must release its watches, never close the runtime.
|
|
121
|
+
* Absent means `/acp` is unavailable.
|
|
122
|
+
*/
|
|
123
|
+
acp?: (agent: ShiitakeOwnerAgent) => Promise<CloudflareShiitakeAcpServer>;
|
|
124
|
+
}>;
|
|
125
|
+
/** Cloudflare host lifecycle; alarm forwarding stays outside the neutral client. */
|
|
126
|
+
export type CloudflareShiitake = ShiitakeOwnerAgent & Readonly<{
|
|
127
|
+
/** Exact settled command facts, outside the neutral Session transport. */
|
|
128
|
+
readSettlement: (sessionId: string, commandId: string) => Promise<CommandSettlement | undefined>;
|
|
129
|
+
/**
|
|
130
|
+
* Admit host-authorized mail, preserving its parent address and opaque
|
|
131
|
+
* metadata. `reply` is the host's authentication of a delegated reply.
|
|
132
|
+
*/
|
|
133
|
+
acceptMail: (mail: BirdDogMail, meta?: Json, reply?: VerifiedAgentReply) => Promise<Accepted>;
|
|
134
|
+
/** Deliver the native owner alarm to the bound runtime. */
|
|
135
|
+
alarm: () => Promise<void>;
|
|
136
|
+
/** Snapshot actual live executors, independent of instruction or browser leases. */
|
|
137
|
+
activeSessions: () => Promise<readonly string[]>;
|
|
138
|
+
/** Abort each currently executing Session through its ordinary cancellation door. */
|
|
139
|
+
abortActive: () => Promise<void>;
|
|
140
|
+
/** Session-scoped browser transport and teardown, owned by this host. */
|
|
141
|
+
browser: Readonly<{
|
|
142
|
+
/** Serve a Session browser request after host ingress authorization. */
|
|
143
|
+
fetch: (request: Request) => Promise<Response>;
|
|
144
|
+
/** Cancel browser connections and release the current ephemeral hosts. */
|
|
145
|
+
clear: () => Promise<void>;
|
|
146
|
+
}>;
|
|
147
|
+
}>;
|
|
148
|
+
/** Construct Shiitake over one Durable Object's SQLite and lifetime. */
|
|
149
|
+
export declare function makeCloudflareShiitake(state: CloudflareShiitakeState, options: CloudflareShiitakeOptions): Promise<CloudflareShiitake>;
|
|
150
|
+
/** Owns runtime opening, HTTP/ACP transport, inbox observation and alarm recovery. */
|
|
151
|
+
export declare abstract class ShiitakeOwner<Env, State extends CloudflareShiitakeState = CloudflareShiitakeState> {
|
|
152
|
+
protected readonly ctx: State;
|
|
153
|
+
protected readonly env: Env;
|
|
154
|
+
constructor(ctx: State, env: Env);
|
|
155
|
+
private agentPromise;
|
|
156
|
+
private openAcp;
|
|
157
|
+
private acpServer;
|
|
158
|
+
/** Consecutive native alarm failures; reset on the next successful alarm. */
|
|
159
|
+
private alarmFailures;
|
|
160
|
+
private readonly routes;
|
|
161
|
+
/** Supply this agent's model, instructions, and optional capabilities. */
|
|
162
|
+
protected abstract shiitakeOptions(): CloudflareShiitakeOptions;
|
|
163
|
+
/** Borrow this owner's runtime directly; only the host owns its lifetime. */
|
|
164
|
+
shiitake(): Promise<CloudflareShiitake>;
|
|
165
|
+
/** Stop live execution without constructing a cold owner's runtime. */
|
|
166
|
+
abortActiveSessions(): Promise<void>;
|
|
167
|
+
/** Close owned resources before storage erasure; a cold owner has none. */
|
|
168
|
+
closeShiitake(): Promise<void>;
|
|
169
|
+
/** Indexed owner-local existence check; corrupt stored Sessions remain unavailable. */
|
|
170
|
+
protected hasStoredSession(sessionId: string): Promise<boolean>;
|
|
171
|
+
/** Bounded strict-after read of this Agent's changed inbox rows. */
|
|
172
|
+
readInboxChanges(after: number, limit: number): Promise<SessionInboxChanges>;
|
|
173
|
+
/** Latest inbox revision; read only after the owner has opened. */
|
|
174
|
+
readInboxRevision(): number;
|
|
175
|
+
/** Prune deletion deltas after every current member inbox has acknowledged them. */
|
|
176
|
+
pruneInboxTombstones(through: number): void;
|
|
177
|
+
/** Persist a wake and run one reconciliation pass, including host work. */
|
|
178
|
+
wakeRuntime(): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Native alarms reconstruct the owner without an incoming user request.
|
|
181
|
+
* A construction or wake failure must not strand the claimed work on
|
|
182
|
+
* platform alarm retries: it is caught, logged, and explicitly re-armed
|
|
183
|
+
* with bounded backoff instead.
|
|
184
|
+
*/
|
|
185
|
+
alarm(): Promise<void>;
|
|
186
|
+
/** Serve Shiitake's complete transport without subclass routing. */
|
|
187
|
+
private app;
|
|
188
|
+
/**
|
|
189
|
+
* Shiitake's whole HTTP surface (Session routes, browser and ACP) as one
|
|
190
|
+
* Hono app. A host mounts it behind its own middleware, which alone may
|
|
191
|
+
* set the `shiitakeMeta` variable.
|
|
192
|
+
*/
|
|
193
|
+
protected shiitakeApp(): Hono<ShiitakeHttpEnv>;
|
|
194
|
+
/** Serve one request through Shiitake's whole HTTP surface. */
|
|
195
|
+
fetch(request: Request): Promise<Response>;
|
|
196
|
+
}
|
|
197
|
+
/** Native Cloudflare entry points; all runtime lifetime belongs to the owner. */
|
|
198
|
+
export declare abstract class ShiitakeDO<Env> extends DurableObject<Env> {
|
|
199
|
+
#private;
|
|
200
|
+
protected abstract shiitakeOptions(): CloudflareShiitakeOptions;
|
|
201
|
+
protected runtimeOwner(): ShiitakeOwner<Env>;
|
|
202
|
+
protected shiitake(): Promise<CloudflareShiitake>;
|
|
203
|
+
protected abortActiveSessions(): Promise<void>;
|
|
204
|
+
protected closeShiitake(): Promise<void>;
|
|
205
|
+
protected readInboxChanges(after: number, limit: number): Promise<Readonly<{
|
|
206
|
+
rows: readonly (import("./client.js").SessionSummaryRow | Readonly<{
|
|
207
|
+
sessionId: string;
|
|
208
|
+
deleted: true;
|
|
209
|
+
}>)[];
|
|
210
|
+
through: number;
|
|
211
|
+
latest: number;
|
|
212
|
+
}>>;
|
|
213
|
+
protected readInboxRevision(): number;
|
|
214
|
+
protected pruneInboxTombstones(through: number): void;
|
|
215
|
+
protected wakeRuntime(): Promise<void>;
|
|
216
|
+
/** Reconcile due runtime and host work through the owner. */
|
|
217
|
+
alarm(): Promise<void>;
|
|
218
|
+
/** Route an authenticated client request through the owner. */
|
|
219
|
+
fetch(request: Request): Promise<Response>;
|
|
220
|
+
}
|