@womp/spark-agent 1.0.0 → 1.0.1
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/agent.js +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js +6 -4
- package/package.json +1 -1
package/dist/agent.js
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type SparkContextPolicy = {
|
|
|
6
6
|
export declare class SparkContextLimitError extends Error {
|
|
7
7
|
constructor();
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
9
|
+
/** Heuristic, not provider tokenization. Encoded media bytes are not text tokens. */
|
|
10
10
|
export declare function estimateSparkContextTokens(value: unknown): number;
|
|
11
11
|
/**
|
|
12
12
|
* Project model input only. Never mutate persisted messages, remove call/result
|
package/dist/context.js
CHANGED
|
@@ -9,19 +9,21 @@ function record(value) {
|
|
|
9
9
|
? value
|
|
10
10
|
: undefined;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/** Heuristic, not provider tokenization. Encoded media bytes are not text tokens. */
|
|
13
13
|
export function estimateSparkContextTokens(value) {
|
|
14
|
-
let
|
|
14
|
+
let mediaTokens = 0;
|
|
15
15
|
const json = JSON.stringify(value, (_key, item) => {
|
|
16
16
|
const part = record(item);
|
|
17
17
|
if (part &&
|
|
18
18
|
(part.type === "image" || part.type === "file" || part.type === "reasoning-file")) {
|
|
19
|
-
|
|
19
|
+
const isImage = part.type === "image" ||
|
|
20
|
+
(typeof part.mediaType === "string" && part.mediaType.startsWith("image/"));
|
|
21
|
+
mediaTokens += isImage ? 512 : 8192;
|
|
20
22
|
return { type: part.type, mediaType: part.mediaType };
|
|
21
23
|
}
|
|
22
24
|
return item;
|
|
23
25
|
}) ?? "";
|
|
24
|
-
return Math.ceil(new TextEncoder().encode(json).byteLength / 3) +
|
|
26
|
+
return Math.ceil(new TextEncoder().encode(json).byteLength / 3) + mediaTokens;
|
|
25
27
|
}
|
|
26
28
|
function executionOutput(part) {
|
|
27
29
|
if (part.toolName !== "execute_javascript" || part.output.type !== "content")
|