@demicodes/agent 0.7.2 → 0.9.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/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { A as AgentToolContext, B as estimateTranscriptBlockTokens, C as AgentSe
2
2
  import { a as AgentClient, i as AgentActionOptions, n as createWebSocketClientTransport, o as AgentClientListener, r as createWebSocketServerTransport, t as JsonWebSocket } from "./websocket-transport-DrsdY12Z.mjs";
3
3
  import { BashAuditEvent, BashEnvironment, BashEnvironmentOptions, CommandMetadataRecord, Host, ShellCommandStatus, ShellOutputChunk } from "@demicodes/shell";
4
4
  import { AgentProvider, Provider } from "@demicodes/provider";
5
- import { Block, Model, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
5
+ import { Block, Model, ModelMediaKind, ModelSelection, ProviderErrorDiagnostics, QueuedMessage, SessionPhase, UserContentBlock } from "@demicodes/core";
6
6
  //#region src/provider-stream-error.d.ts
7
7
  /** Error carrying a provider stream's normalized code and bounded diagnostics. */
8
8
  declare class ProviderStreamError extends Error {
@@ -272,7 +272,28 @@ interface ShellToolResultOptions {
272
272
  exposeCommandHandle?: boolean;
273
273
  /** Model receiving this result; gates binary-stream media attachment. */
274
274
  model?: Model;
275
+ /** Per-modality byte caps on attached media; unset modalities keep the defaults. */
276
+ maxMediaBytes?: Partial<Record<ModelMediaKind, number>>;
275
277
  }
278
+ /**
279
+ * How many bytes of each modality a tool may hand to the model.
280
+ *
281
+ * One number cannot serve both, because bytes buy wildly different amounts of
282
+ * context per modality — measured against a frontier model, a KiB of video
283
+ * costs ~2 tokens where a KiB of image costs ~50. A cap generous enough to show
284
+ * a five-minute clip would let a single still eat a six-figure token budget.
285
+ *
286
+ * image (4 MiB): well past any sane still — a 4000x3000 PNG lands under it — so
287
+ * crossing this line is a mistake, not a use case.
288
+ * video (16 MiB): roughly ten minutes at a viewing-grade encoding, and
289
+ * deliberately under the ~20 MB inline-payload ceiling the major APIs enforce.
290
+ * A larger cap buys no reach, only a rejection further downstream where the
291
+ * reason is harder to read.
292
+ *
293
+ * Bytes are a proxy, not a budget: for video they track cost reasonably at a
294
+ * fixed encoding, but an image's real driver is its pixel dimensions.
295
+ */
296
+ declare const DEFAULT_MAX_MEDIA_BYTES: Record<ModelMediaKind, number>;
276
297
  declare function shellPreviewBudgetTokens(contextWindow: number): number;
277
298
  declare function toShellToolResult(result: ShellCommandStatus, options?: ShellToolResultOptions): AgentToolInvokeResult;
278
299
  /** Character budget for a shell view's render window (tail-biased). */
@@ -301,4 +322,4 @@ interface ShellToolView {
301
322
  declare function finishShellToolResult<State>(environment: BashEnvironment, result: ShellCommandStatus, ctx: AgentToolInvokeContext<State>): Promise<AgentToolInvokeResult>;
302
323
  declare function shellCommandHandleRequired(result: ShellCommandStatus, budgetTokens: number): boolean;
303
324
  //#endregion
304
- export { AbortResult, AbortTarget, ActiveTurnPhase, AgentActionOptions, AgentClient, AgentClientListener, AgentClientTransport, AgentDisposeContext, AgentHarness, AgentHarnessContext, AgentHarnessRuntime, AgentHostContext, AgentLifecycleEvent, AgentMetadata, AgentPromptContext, AgentReferenceResolveContext, AgentServer, AgentServerOptions, AgentServerSessionOptions, AgentServerTransport, AgentSession, AgentSessionCheckpoint, AgentSessionOptions, AgentSessionParams, AgentSessionRestoreParams, AgentSessionStore, AgentSystemPromptContext, AgentTool, AgentToolContext, AgentToolInvokeContext, AgentToolInvokeResult, AgentTransport, AgentTransportBinding, ClientFrame, ClientSessionEvent, CompactionWindow, ConversationSummary, DEFAULT_TURN_RETRY_POLICY, DrainedTranscriptPatches, ExternalMutationReservation, InProcessTransportPair, JsonWebSocket, PrepareShell, PrepareShellContext, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineOptions, RunCommandLineResult, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, ServerFrame, SessionEvent, SessionEventListener, ShellCommandStatusLike, ShellToolResultOptions, ShellToolView, StandardAgentToolOptions, TranscriptLog, TranscriptOptions, TranscriptPatch, TurnRetryPolicy, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
325
+ export { AbortResult, AbortTarget, ActiveTurnPhase, AgentActionOptions, AgentClient, AgentClientListener, AgentClientTransport, AgentDisposeContext, AgentHarness, AgentHarnessContext, AgentHarnessRuntime, AgentHostContext, AgentLifecycleEvent, AgentMetadata, AgentPromptContext, AgentReferenceResolveContext, AgentServer, AgentServerOptions, AgentServerSessionOptions, AgentServerTransport, AgentSession, AgentSessionCheckpoint, AgentSessionOptions, AgentSessionParams, AgentSessionRestoreParams, AgentSessionStore, AgentSystemPromptContext, AgentTool, AgentToolContext, AgentToolInvokeContext, AgentToolInvokeResult, AgentTransport, AgentTransportBinding, ClientFrame, ClientSessionEvent, CompactionWindow, ConversationSummary, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, DrainedTranscriptPatches, ExternalMutationReservation, InProcessTransportPair, JsonWebSocket, PrepareShell, PrepareShellContext, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineOptions, RunCommandLineResult, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, ServerFrame, SessionEvent, SessionEventListener, ShellCommandStatusLike, ShellToolResultOptions, ShellToolView, StandardAgentToolOptions, TranscriptLog, TranscriptOptions, TranscriptPatch, TurnRetryPolicy, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
package/dist/index.mjs CHANGED
@@ -2271,6 +2271,28 @@ function createStandardAgentTools(options) {
2271
2271
  function resolveEnvironment(source, ctx, handle) {
2272
2272
  return typeof source === "function" ? source(ctx, handle) : source;
2273
2273
  }
2274
+ /**
2275
+ * How many bytes of each modality a tool may hand to the model.
2276
+ *
2277
+ * One number cannot serve both, because bytes buy wildly different amounts of
2278
+ * context per modality — measured against a frontier model, a KiB of video
2279
+ * costs ~2 tokens where a KiB of image costs ~50. A cap generous enough to show
2280
+ * a five-minute clip would let a single still eat a six-figure token budget.
2281
+ *
2282
+ * image (4 MiB): well past any sane still — a 4000x3000 PNG lands under it — so
2283
+ * crossing this line is a mistake, not a use case.
2284
+ * video (16 MiB): roughly ten minutes at a viewing-grade encoding, and
2285
+ * deliberately under the ~20 MB inline-payload ceiling the major APIs enforce.
2286
+ * A larger cap buys no reach, only a rejection further downstream where the
2287
+ * reason is harder to read.
2288
+ *
2289
+ * Bytes are a proxy, not a budget: for video they track cost reasonably at a
2290
+ * fixed encoding, but an image's real driver is its pixel dimensions.
2291
+ */
2292
+ const DEFAULT_MAX_MEDIA_BYTES = {
2293
+ image: 4 * 1024 * 1024,
2294
+ video: 16 * 1024 * 1024
2295
+ };
2274
2296
  function shellPreviewBudgetTokens(contextWindow) {
2275
2297
  return contextWindow >= LARGE_CONTEXT_THRESHOLD_TOKENS ? LARGE_CONTEXT_PREVIEW_TOKENS : SMALL_CONTEXT_PREVIEW_TOKENS;
2276
2298
  }
@@ -2280,7 +2302,10 @@ function toShellToolResult(result, options = {}) {
2280
2302
  text: formatShellToolResult(result, options)
2281
2303
  }];
2282
2304
  if (result.status === "exited" && result.binaryStdout) {
2283
- const verdict = binaryStreamVerdict(result.binaryStdout, result.commandId, options.model);
2305
+ const verdict = binaryStreamVerdict(result.binaryStdout, result.commandId, options.model, {
2306
+ ...DEFAULT_MAX_MEDIA_BYTES,
2307
+ ...options.maxMediaBytes
2308
+ });
2284
2309
  if (verdict.block) output.push(verdict.block);
2285
2310
  if (verdict.note) output.push({
2286
2311
  type: "text",
@@ -2352,12 +2377,14 @@ function tailChunkWindow(chunks, maxChars) {
2352
2377
  * magic matches the closed model-media set, the model accepts the type, and
2353
2378
  * the stream was not truncated; otherwise explain why nothing was attached.
2354
2379
  */
2355
- function binaryStreamVerdict(binary, commandId, model) {
2380
+ function binaryStreamVerdict(binary, commandId, model, maxMediaBytes) {
2356
2381
  const media = sniffModelMediaType(binary.data);
2357
2382
  const binPath = `/@/commands/${commandId}/stdout.bin`;
2358
- if (binary.truncated) return { note: `Binary stdout was truncated at the output limit (${binary.data.length} of ${binary.totalBytes} bytes)${media ? ` and looks like ${media.mediaType}` : ""}; it was not attached. Redirect to a file or raise the output limit and re-run.` };
2383
+ if (binary.truncated) return { note: `Binary stdout (${binary.totalBytes} bytes${media ? `, ${media.mediaType}` : ""}) exceeded the shell's ${binary.limitBytes}-byte binary limit (maxBinaryBytes) and was not attached; the raw bytes remain readable at ${binPath}. Produce a smaller version and re-run.` };
2359
2384
  if (!media) return { note: `Binary stdout does not match any model-viewable media type; the raw bytes remain readable at ${binPath}.` };
2360
2385
  if (!model || !modelAcceptsMediaType(model, media.mediaType)) return { note: `Binary stdout is ${media.mediaType}, which this model does not accept natively; the raw bytes remain readable at ${binPath}.` };
2386
+ const cap = maxMediaBytes[media.kind];
2387
+ if (binary.totalBytes > cap) return { note: `Binary stdout is ${media.mediaType} (${binary.totalBytes} bytes), over the ${cap}-byte ${media.kind} cap; it was not attached and the raw bytes remain readable at ${binPath}. Produce a smaller version — for video, fewer frames or a lower resolution — and re-run.` };
2361
2388
  const source = {
2362
2389
  mediaType: media.mediaType,
2363
2390
  data: bytesToBase64(binary.data)
@@ -3312,4 +3339,4 @@ function createProviderMap(providers) {
3312
3339
  return map;
3313
3340
  }
3314
3341
  //#endregion
3315
- export { AgentClient, AgentServer, AgentSession, DEFAULT_TURN_RETRY_POLICY, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, TranscriptLog, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
3342
+ export { AgentClient, AgentServer, AgentSession, DEFAULT_MAX_MEDIA_BYTES, DEFAULT_TURN_RETRY_POLICY, ProviderStreamError, RunCommandLineCommandNotRegisteredError, RunCommandLineShellNotFoundError, RunCommandLineTimeoutError, SHELL_VIEW_MAX_CHARS, TranscriptLog, applyTranscriptPatches, cloneBlocks, createInProcessTransportPair, createStandardAgentTools, createWebSocketClientTransport, createWebSocketServerTransport, estimateTranscriptBlockTokens, finishShellToolResult, isContextLengthExceeded, isRetryableCode, resolveRetryPolicy, retryDelayMs, shellCommandHandleRequired, shellPreviewBudgetTokens, toShellToolResult };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demicodes/agent",
3
3
  "description": "Session runtime and transport-neutral client and server protocol for Demi.",
4
- "version": "0.7.2",
4
+ "version": "0.9.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "exports": {
@@ -19,10 +19,10 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@demicodes/core": "^0.7.2",
23
- "@demicodes/provider": "^0.7.2",
24
- "@demicodes/shell": "^0.7.2",
25
- "@demicodes/utils": "^0.7.2"
22
+ "@demicodes/core": "^0.9.0",
23
+ "@demicodes/provider": "^0.9.0",
24
+ "@demicodes/shell": "^0.9.0",
25
+ "@demicodes/utils": "^0.9.0"
26
26
  },
27
27
  "license": "Apache-2.0",
28
28
  "main": "./dist/index.mjs",