@demicodes/agent 0.25.4 → 0.25.6
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.mjs +33 -5
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as cloneBlocks, i as applyTranscriptPatches, n as createWebSocketServerTransport, o as ProviderStreamError, r as AgentClient, s as isContextLengthExceeded, t as createWebSocketClientTransport } from "./websocket-transport-BsKvbXIp.mjs";
|
|
2
|
-
import { AbortError, abortable, asError, asRecord, asString, bytesToBase64, createId, decodeUtf8, delay, errorMessage, isAbortError, isRecord, noop, parseJsonOrString, safeJsonStringify, sliceHead, sliceTail, throwIfAborted, toWellFormedText, truncate, utf8Slice } from "@demicodes/utils";
|
|
2
|
+
import { AbortError, abortable, asError, asRecord, asString, base64ToBytes, bytesToBase64, createId, decodeUtf8, delay, errorMessage, hasImageIntegrity, isAbortError, isRecord, noop, parseJsonOrString, safeJsonStringify, sliceHead, sliceTail, throwIfAborted, toWellFormedText, truncate, utf8Slice } from "@demicodes/utils";
|
|
3
3
|
import { BashEnvironment, CommandRegistry, MAX_TIMEOUT_MS, heredocDelimiter, shellQuote } from "@demicodes/shell";
|
|
4
4
|
import { providerRuntime } from "@demicodes/provider";
|
|
5
5
|
import { modelAcceptsMediaType, sniffModelMediaType } from "@demicodes/core";
|
|
@@ -672,6 +672,32 @@ function findResumePoint(blocks) {
|
|
|
672
672
|
};
|
|
673
673
|
}
|
|
674
674
|
//#endregion
|
|
675
|
+
//#region src/image-integrity.ts
|
|
676
|
+
const CORRUPT_IMAGE_TEXT = "Image data is corrupted.";
|
|
677
|
+
function validBase64(data, mediaType) {
|
|
678
|
+
try {
|
|
679
|
+
return data.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(data) && hasImageIntegrity(base64ToBytes(data), mediaType);
|
|
680
|
+
} catch {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function validUrl(url) {
|
|
685
|
+
if (!/^data:/i.test(url)) return true;
|
|
686
|
+
const match = /^data:([^;,]+);base64,([\s\S]*)$/i.exec(url);
|
|
687
|
+
return !!match && validBase64(match[2], match[1]);
|
|
688
|
+
}
|
|
689
|
+
function validImage(block) {
|
|
690
|
+
const source = block.source;
|
|
691
|
+
if ("type" in source && source.type === "url") return validUrl(source.url);
|
|
692
|
+
return typeof source.data === "string" ? validBase64(source.data, source.mediaType) : hasImageIntegrity(source.data, source.mediaType);
|
|
693
|
+
}
|
|
694
|
+
function filterCorruptImages(blocks) {
|
|
695
|
+
return blocks.map((block) => block.type === "image" && !validImage(block) ? {
|
|
696
|
+
type: "text",
|
|
697
|
+
text: CORRUPT_IMAGE_TEXT
|
|
698
|
+
} : block);
|
|
699
|
+
}
|
|
700
|
+
//#endregion
|
|
675
701
|
//#region src/yield-scheduler.ts
|
|
676
702
|
/**
|
|
677
703
|
* Tracks scheduled `yield` wakeups and their timers. This class owns only the
|
|
@@ -1116,7 +1142,7 @@ var ProviderTurnLoop = class {
|
|
|
1116
1142
|
}
|
|
1117
1143
|
const input = parseJsonOrString(toolCall.input);
|
|
1118
1144
|
const result = await this.invokeToolAsResult(tool, toolCall.toolUseId, input);
|
|
1119
|
-
this.host.transcript.completeToolCall(toolCall.toolUseId, result.output, result.isError ?? false, result.view ?? null);
|
|
1145
|
+
this.host.transcript.completeToolCall(toolCall.toolUseId, filterCorruptImages(result.output), result.isError ?? false, result.view ?? null);
|
|
1120
1146
|
await this.host.runtime.lifecycle?.({
|
|
1121
1147
|
type: "after_tool_call",
|
|
1122
1148
|
agentSessionId: this.host.agentSessionId,
|
|
@@ -1783,6 +1809,7 @@ var AgentSession = class AgentSession {
|
|
|
1783
1809
|
}
|
|
1784
1810
|
}
|
|
1785
1811
|
async steerInternal(content, id, hidden = false) {
|
|
1812
|
+
content = filterCorruptImages(content);
|
|
1786
1813
|
const delivery = this.steerDelivery();
|
|
1787
1814
|
const turnId = this.currentTurnId();
|
|
1788
1815
|
if (delivery.type === "provider") {
|
|
@@ -1995,16 +2022,16 @@ var AgentSession = class AgentSession {
|
|
|
1995
2022
|
}
|
|
1996
2023
|
async resolveReferences(content) {
|
|
1997
2024
|
const resolver = this.runtime.resolveReferences;
|
|
1998
|
-
if (!resolver) return content;
|
|
2025
|
+
if (!resolver) return filterCorruptImages(content);
|
|
1999
2026
|
const signal = this.currentSignal();
|
|
2000
|
-
return await abortable(Promise.resolve(resolver({
|
|
2027
|
+
return filterCorruptImages(await abortable(Promise.resolve(resolver({
|
|
2001
2028
|
state: this.agentState,
|
|
2002
2029
|
agentSessionId: this.agentSessionId,
|
|
2003
2030
|
cwd: this.cwd,
|
|
2004
2031
|
transcript: this.transcriptLog,
|
|
2005
2032
|
signal,
|
|
2006
2033
|
metadata: this.activeMetadata
|
|
2007
|
-
}, content)), signal);
|
|
2034
|
+
}, content)), signal));
|
|
2008
2035
|
}
|
|
2009
2036
|
async executeRetry() {
|
|
2010
2037
|
const userBlock = this.transcriptLog.rewindToLastUserTurn();
|
|
@@ -2554,6 +2581,7 @@ function binaryStreamVerdict(binary, binPath, model, maxMediaBytes) {
|
|
|
2554
2581
|
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}.` };
|
|
2555
2582
|
const cap = maxMediaBytes[media.kind];
|
|
2556
2583
|
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.` };
|
|
2584
|
+
if (media.kind === "image" && !hasImageIntegrity(binary.data, media.mediaType)) return { note: CORRUPT_IMAGE_TEXT };
|
|
2557
2585
|
const source = {
|
|
2558
2586
|
mediaType: media.mediaType,
|
|
2559
2587
|
data: bytesToBase64(binary.data)
|
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.25.
|
|
4
|
+
"version": "0.25.6",
|
|
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.25.
|
|
23
|
-
"@demicodes/provider": "^0.25.
|
|
24
|
-
"@demicodes/shell": "^0.25.
|
|
25
|
-
"@demicodes/utils": "^0.25.
|
|
22
|
+
"@demicodes/core": "^0.25.6",
|
|
23
|
+
"@demicodes/provider": "^0.25.6",
|
|
24
|
+
"@demicodes/shell": "^0.25.6",
|
|
25
|
+
"@demicodes/utils": "^0.25.6",
|
|
26
26
|
"zod": "^4.0.0"
|
|
27
27
|
},
|
|
28
28
|
"license": "Apache-2.0",
|