@workerdeck/server 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/build/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IncomingMessage, Server, ServerResponse } from "node:http";
2
- import { AttachmentInput, BridgeAnswer, BrowserBridgeExecutor, ClaudeAuthProbe, EngineAdapter, EngineSessionOptions, HostToolDefinition, LanguageModel, McpConnection, ParkedExecution, Runner, RunnerSnapshot, SessionRunnerConfig, ToolExecutionResult, ToolExecutor, ToolSet } from "@workerdeck/core";
2
+ import { AttachmentInput, BridgeAnswer, BrowserBridgeExecutor, ClaudeAuthProbe, EngineAdapter, EngineSessionOptions, HostToolDefinition, LanguageModel, McpConnection, ParkedExecution, Runner, RunnerSnapshot, SessionRunnerConfig, ToolExecutionCall, ToolExecutionResult, ToolExecutor, ToolSet } from "@workerdeck/core";
3
3
  import { JobQueue, QueueAdapter } from "@workerdeck/queue";
4
4
  import { CreateSessionRequest, JobEvent, MessageAttachment, ProfileEngine, ProfileInfo, ProfileUsage, ProviderConfig, SdkSessionSummary, ServerFrame, SessionCapability, SessionInfo, SessionNotification, SessionWebhookConfig } from "@workerdeck/protocol";
5
5
 
@@ -907,8 +907,11 @@ type ProviderRunnerOptions = {
907
907
  * when the data is *there* (a document the user is editing) and it should
908
908
  * not travel to the gateway at all. Note the trade: it hands an executor to
909
909
  * the party being sandboxed against, so its results are untrusted input.
910
+ * - a **function** — selects per call, so `eval_script` can run in-process
911
+ * while a custom tool goes to the browser. The function receives the
912
+ * {@link ToolExecutionCall} and returns an executor or `'browser'`.
910
913
  */
911
- executor: ToolExecutor | 'browser';
914
+ executor: ToolExecutor | 'browser' | ((call: ToolExecutionCall) => ToolExecutor | 'browser');
912
915
  /** Capability backends — the same shape {@link createEngineSession} takes.
913
916
  * Wiring one only offers it; the profile and request decide the grant. */
914
917
  capabilities?: EngineSessionOptions['capabilities']; /** Host tools at explicit trust levels (`@workerdeck/core`'s `withHostTools`). */
@@ -926,6 +929,15 @@ type ProviderRunnerOptions = {
926
929
  /** Scratch-filesystem seed for a new session. Ignored on a rehydration, so a
927
930
  * parked turn's files are never overwritten. */
928
931
  seedVfs?: Record<string, string>;
932
+ /**
933
+ * Gate tool execution behind user approval. See
934
+ * {@link EngineSessionOptions.shouldApprove} — this is a straight pass-through.
935
+ */
936
+ shouldApprove?: (call: {
937
+ toolName: string;
938
+ input: unknown;
939
+ }) => boolean; /** Timeout for permission prompts (ms). Default 120 000. */
940
+ approvalTimeoutMs?: number;
929
941
  /** Release per-session resources: the MCP connection, an issued token, a
930
942
  * watcher. Runs on close **and on park** — parking releases the same things. */
931
943
  onClose?: () => void | Promise<void>;
package/build/index.mjs CHANGED
@@ -4147,7 +4147,13 @@ function sandboxedProviderProfile(name, provider, options = {}) {
4147
4147
  async function createProviderRunner(ctx, options) {
4148
4148
  const { config, profile, bridge, restore, id } = ctx;
4149
4149
  const resolveModel = (modelId) => typeof options.model === "function" ? options.model(modelId) : options.model;
4150
- const executor = options.executor === "browser" ? { dispatch: (call) => bridge.executorFor(call.sessionId).dispatch(call) } : options.executor;
4150
+ const resolveBridged = () => ({ dispatch: (call) => bridge.executorFor(call.sessionId).dispatch(call) });
4151
+ const resolveExecutor = (raw) => raw === "browser" ? resolveBridged() : raw;
4152
+ const isPerCall = typeof options.executor === "function";
4153
+ const selectExecutor = isPerCall ? (call) => resolveExecutor(options.executor(call)) : () => resolveExecutor(options.executor);
4154
+ const backend = isPerCall ? (call) => {
4155
+ return options.executor(call) === "browser" ? "browser" : "server";
4156
+ } : options.executor === "browser" ? "browser" : "server";
4151
4157
  return createEngineSession({
4152
4158
  config: {
4153
4159
  ...config,
@@ -4158,14 +4164,16 @@ async function createProviderRunner(ctx, options) {
4158
4164
  id,
4159
4165
  profile,
4160
4166
  resolveModel: (_profile, c) => resolveModel(c.model),
4161
- selectExecutor: () => executor,
4162
- backend: options.executor === "browser" ? "browser" : "server",
4167
+ selectExecutor,
4168
+ backend,
4163
4169
  capabilities: options.capabilities,
4164
4170
  tools: options.tools,
4165
4171
  mcp: options.mcp,
4166
4172
  mcpTools: options.mcpTools,
4167
4173
  instructions: options.instructions,
4168
4174
  executionLimits: options.executionLimits,
4175
+ shouldApprove: options.shouldApprove,
4176
+ approvalTimeoutMs: options.approvalTimeoutMs,
4169
4177
  seedVfs: options.seedVfs
4170
4178
  });
4171
4179
  }