Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/compress-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const SEARCH_CONTEXT_TOOL_NAME = "search_context";
export const ACP_STATUS_TOOL_NAME = "acp_status";
export const ACP_CACHE_TOOL_NAME = "acp_cache";
export const ABSORB_TOOL_NAME = "absorb";
export const IMAGE_FULL_TOOL_NAME = "image_full";

/** Text-protocol trigger tags. The model emits these in its text output to
* request compression (used when host client tools cannot coexist with a
Expand Down Expand Up @@ -696,3 +697,43 @@ export const ABSORB_TOOL_GOOGLE = {
description: ABSORB_TOOL_DESCRIPTION,
parameters: ABSORB_PARAMETERS,
};

/** Opt-in image_full tool (restore original-resolution images for a previously
* downscaled message). Inject/register only when
* config.imageCompression.enabled — NOT part of ACP_TOOLS_* arrays. */
export const IMAGE_FULL_TOOL_DESCRIPTION =
'Restore original-resolution images for a previously downscaled message. Call when you cannot read details (text, colors, alignment) in a reduced image: pass the message ref ("mNNNNN") from the [Downscaled screenshots] note. Full resolution applies for the rest of this session.';

const IMAGE_FULL_PARAMETERS = {
type: "object" as const,
properties: {
ref: {
type: "string",
description:
"mNNNNN ref of the message whose image(s) should be restored to full resolution",
},
},
required: ["ref"],
};

export const IMAGE_FULL_TOOL = {
name: IMAGE_FULL_TOOL_NAME,
description: IMAGE_FULL_TOOL_DESCRIPTION,
input_schema: IMAGE_FULL_PARAMETERS,
};

export const IMAGE_FULL_TOOL_OPENAI = {
type: "function" as const,
function: {
name: IMAGE_FULL_TOOL_NAME,
description: IMAGE_FULL_TOOL_DESCRIPTION,
parameters: IMAGE_FULL_PARAMETERS,
},
};

export const IMAGE_FULL_TOOL_RESPONSES = {
type: "function" as const,
name: IMAGE_FULL_TOOL_OPENAI.function.name,
description: IMAGE_FULL_TOOL_OPENAI.function.description,
parameters: IMAGE_FULL_TOOL_OPENAI.function.parameters,
};
30 changes: 30 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export function defaultConfig(
enabled: false,
minReduction: 0.1,
},
imageCompression: {
enabled: false,
minTokens: 512,
maxDimension: 1280,
quality: 80,
format: "webp",
},
};
return {
...base,
Expand All @@ -55,6 +62,9 @@ export function defaultConfig(
? { ...base.absorb, ...overrides.absorb }
: base.absorb,
crush: overrides.crush ? { ...base.crush, ...overrides.crush } : base.crush,
imageCompression: overrides.imageCompression
? { ...base.imageCompression, ...overrides.imageCompression }
: base.imageCompression,
};
}

Expand Down Expand Up @@ -163,5 +173,25 @@ export function validateConfig(config: Config): string[] {
}
}
}
if (config.imageCompression) {
const ic = config.imageCompression;
if (ic.minTokens !== undefined && (!Number.isFinite(ic.minTokens) || ic.minTokens < 0)) {
errors.push("imageCompression.minTokens must be finite and >= 0");
}
if (ic.maxDimension !== undefined && (!Number.isInteger(ic.maxDimension) || ic.maxDimension < 16)) {
errors.push("imageCompression.maxDimension must be an integer >= 16");
}
if (ic.quality !== undefined && (!Number.isFinite(ic.quality) || ic.quality < 1 || ic.quality > 100)) {
errors.push("imageCompression.quality must be in [1, 100]");
}
if (
ic.format !== undefined &&
ic.format !== "webp" &&
ic.format !== "jpeg" &&
ic.format !== "png"
) {
errors.push('imageCompression.format must be "webp", "jpeg", or "png"');
}
}
return errors;
}
Loading
Loading