@workerdeck/server 3.0.1 → 3.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/build/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IncomingMessage, Server, ServerResponse } from "node:http";
2
2
  import { AttachmentInput, BridgeAnswer, BrowserBridgeExecutor, ClaudeAuthProbe, CostLedgerState, EngineAdapter, EngineSessionOptions, HostToolDefinition, LanguageModel, LocalShellSource, McpConnection, ParkedExecution, Runner, RunnerSnapshot, SHELL_REFUSAL, SessionInstructions, SessionRunnerConfig, ShellDirectory, ToolExecutionCall, ToolExecutionResult, ToolExecutor, ToolSet } from "@workerdeck/core";
3
3
  import { JobQueue, QueueAdapter } from "@workerdeck/queue";
4
- import { ByModel, CreateSessionRequest, JobEvent, MessageAttachment, ModelRate, ProfileEngine, ProfileInfo, ProfileSpend, ProfileUsage, ProviderConfig, SdkSessionSummary, ServerFrame, SessionCapability, SessionInfo, SessionNotification, SessionWebhookConfig, ShellEndReason, ShellInfo, ShellOwner } from "@workerdeck/protocol";
4
+ import { ByModel, CreateSessionRequest, JobEvent, MessageAttachment, ModelRate, PricingTable, ProfileEngine, ProfileInfo, ProfileSpend, ProfileUsage, ProviderConfig, SdkSessionSummary, ServerFrame, SessionCapability, SessionInfo, SessionNotification, SessionWebhookConfig, ShellEndReason, ShellInfo, ShellOwner } from "@workerdeck/protocol";
5
5
  //#region src/services/bridge.d.ts
6
6
  type BridgeHubOptions = {
7
7
  timeoutMs?: number;
@@ -24,6 +24,11 @@ type SessionNotificationOptions = {
24
24
  attempts?: number;
25
25
  retryDelayMs?: number;
26
26
  decorateInfo?: (info: SessionInfo) => SessionInfo;
27
+ onError?: (error: unknown, context: NotificationErrorContext) => void;
28
+ };
29
+ type NotificationErrorContext = {
30
+ op: 'hook' | 'webhook';
31
+ sessionId: string;
27
32
  };
28
33
  declare class SessionNotifier {
29
34
  #private;
@@ -102,7 +107,7 @@ declare function createFileSessionStore(options?: FileSessionStoreOptions): Sess
102
107
  //#region src/services/parking.d.ts
103
108
  type ParkErrorContext = {
104
109
  sessionId: string;
105
- phase: 'park' | 'remember' | 'resume';
110
+ phase: 'park' | 'remember' | 'resume' | 'discard';
106
111
  };
107
112
  type SessionParkOptions = {
108
113
  registry: SessionRegistry;
@@ -113,6 +118,7 @@ type SessionParkOptions = {
113
118
  persistLive?: boolean;
114
119
  expiredGraceMs?: number;
115
120
  onParking?: (sessionId: string, executionId: string) => boolean;
121
+ onParked?: (sessionId: string, executionId: string) => void;
116
122
  onResumed?: (sessionId: string, runner: Runner) => void;
117
123
  onError?: (error: unknown, context: ParkErrorContext) => void;
118
124
  };
@@ -129,6 +135,7 @@ declare class SessionParkManager {
129
135
  onDetach(sessionId: string): void;
130
136
  sessionFor(executionId: string): string | undefined;
131
137
  get(id: string): Promise<StoredSessionRecord | null>;
138
+ retitle(id: string, title: string | undefined): Promise<SessionInfo | undefined>;
132
139
  listInfo(): Promise<SessionInfo[]>;
133
140
  ensureLive(id: string): Promise<Runner | undefined>;
134
141
  submitResult(executionId: string, result: ToolExecutionResult): Promise<{
@@ -164,7 +171,17 @@ type ProcessRow = {
164
171
  };
165
172
  type ProcessTable = () => ProcessRow[] | null;
166
173
  //#endregion
167
- //#region src/services/shells.d.ts
174
+ //#region src/lib/atomic-file.d.ts
175
+ type JsonWriteOptions = {
176
+ indent?: number;
177
+ trailingNewline?: boolean;
178
+ };
179
+ declare function isMissing(error: unknown): boolean;
180
+ declare function writeFileAtomic(path: string, data: string | Uint8Array): Promise<void>;
181
+ declare function writeJsonAtomic(path: string, value: unknown, options?: JsonWriteOptions): Promise<void>;
182
+ declare function readJsonOr(path: string, fallback: unknown): Promise<unknown>;
183
+ //#endregion
184
+ //#region src/services/shell-types.d.ts
168
185
  type ShellSize = {
169
186
  cols: number;
170
187
  rows: number;
@@ -196,9 +213,7 @@ type ShellErrorContext = {
196
213
  sessionId?: string;
197
214
  shellId?: string;
198
215
  };
199
- type ShellDirectoryDeps = {
200
- runnerFor?: (sessionId: string) => Runner | undefined;
201
- };
216
+ type ShellErrorReporter = (error: unknown, context: ShellErrorContext) => void;
202
217
  type ShellRegistryOptions = {
203
218
  generation: string;
204
219
  artifactDir: string | null;
@@ -212,7 +227,7 @@ type ShellRegistryOptions = {
212
227
  tailFlushMs?: number;
213
228
  sweepIntervalMs?: number;
214
229
  processTable?: ProcessTable;
215
- onError?: (error: unknown, context: ShellErrorContext) => void;
230
+ onError?: ShellErrorReporter;
216
231
  };
217
232
  type StoredShellRecord = ShellInfo & {
218
233
  generation: string;
@@ -246,7 +261,14 @@ type ShellRegistry = {
246
261
  decorate: (info: SessionInfo) => SessionInfo;
247
262
  watch: (runner: Runner) => () => void;
248
263
  };
264
+ //#endregion
265
+ //#region src/services/shell-directory.d.ts
266
+ type ShellDirectoryDeps = {
267
+ runnerFor?: (sessionId: string) => Runner | undefined;
268
+ };
249
269
  declare function createShellDirectory(registry: ShellRegistry, deps?: ShellDirectoryDeps): ShellDirectory;
270
+ //#endregion
271
+ //#region src/services/shells.d.ts
250
272
  declare function shellPermitted(shells: ShellRegistry | null, runner: Runner, operator: boolean): boolean;
251
273
  declare function createShellRegistry(options: ShellRegistryOptions): ShellRegistry;
252
274
  //#endregion
@@ -259,6 +281,7 @@ type SpendStore = {
259
281
  save(record: SpendRecord): Promise<void>;
260
282
  };
261
283
  type SpendLedgerOptions = {
284
+ pricing?: PricingTable;
262
285
  store?: SpendStore;
263
286
  monthlySubscriptionUsd?: (profile: string) => number | undefined;
264
287
  retentionDays?: number;
@@ -350,7 +373,9 @@ type WorkerServerOptions = {
350
373
  };
351
374
  createEngineRunner?: (context: EngineRunnerContext) => Runner | Promise<Runner>;
352
375
  engines?: Partial<Record<ProfileEngine, EngineAdapter>>;
376
+ onDiagnostic?: DiagnosticSink;
353
377
  };
378
+ type DiagnosticSink = (error: unknown, where: string) => void;
354
379
  type EngineRunnerContext = {
355
380
  config: SessionRunnerConfig;
356
381
  profile: ProfileInfo;
@@ -511,5 +536,5 @@ declare class ProfileUsageTracker {
511
536
  usage(profile: string, now?: number): ProfileUsage | undefined;
512
537
  }
513
538
  //#endregion
514
- export { AttachmentStore, type AttachmentStoreOptions, type Authenticator, BridgeHub, type BridgeHubOptions, type CarriedSession, type EngineRunnerContext, type FileSessionStoreOptions, MemorySessionStore, type ParkedSessionRecord, type ProcessRow, type ProcessTable, type ProducedFile, ProducedFileStore, type ProfileStore, ProfileUsageTracker, type ProviderRunnerOptions, type QueueServerOptions, type ReloadPlan, SHELL_REFUSAL, type SdkSessionLister, type SessionNotificationOptions, SessionNotifier, SessionParkManager, type SessionParkOptions, SessionRegistry, type SessionRegistryOptions, type SessionStore, type ShellAgentWriteOption, type ShellDirectoryDeps, type ShellRegistry, type ShellRegistryOptions, type ShellSink, SpendLedger, type SpendRecord, type SpendStore, type StoredSessionRecord, type StoredShellIndex, type StoredShellRecord, type WorkerServer, type WorkerServerOptions, createFileProfileStore, createFileSessionStore, createFileSpendStore, createMemoryProfileStore, createProviderRunner, createShellDirectory, createShellRegistry, createWorkerServer, dayKey, isDormant, reloadPlan, sandboxedProviderProfile, shellPermitted, toDurableRecord };
539
+ export { AttachmentStore, type AttachmentStoreOptions, type Authenticator, BridgeHub, type BridgeHubOptions, type CarriedSession, type DiagnosticSink, type EngineRunnerContext, type FileSessionStoreOptions, type JsonWriteOptions, MemorySessionStore, type NotificationErrorContext, type ParkedSessionRecord, type ProcessRow, type ProcessTable, type ProducedFile, ProducedFileStore, type ProfileStore, ProfileUsageTracker, type ProviderRunnerOptions, type QueueServerOptions, type ReloadPlan, SHELL_REFUSAL, type SdkSessionLister, type SessionNotificationOptions, SessionNotifier, SessionParkManager, type SessionParkOptions, SessionRegistry, type SessionRegistryOptions, type SessionStore, type ShellAgentWriteOption, type ShellDirectoryDeps, type ShellRegistry, type ShellRegistryOptions, type ShellSink, SpendLedger, type SpendRecord, type SpendStore, type StoredSessionRecord, type StoredShellIndex, type StoredShellRecord, type WorkerServer, type WorkerServerOptions, createFileProfileStore, createFileSessionStore, createFileSpendStore, createMemoryProfileStore, createProviderRunner, createShellDirectory, createShellRegistry, createWorkerServer, dayKey, isDormant, isMissing, readJsonOr, reloadPlan, sandboxedProviderProfile, shellPermitted, toDurableRecord, writeFileAtomic, writeJsonAtomic };
515
540
  //# sourceMappingURL=index.d.mts.map