@wraith-ai/core 0.1.0 → 0.1.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/README.md +1 -1
- package/dist/{attempt-BeB7EltG.d.mts → attempt-HgararU3.d.mts} +2 -1
- package/dist/attempt-HgararU3.d.mts.map +1 -0
- package/dist/{capabilities-BPb5HSH6.d.mts → capabilities-CNsPrkB7.d.mts} +2 -1
- package/dist/capabilities-CNsPrkB7.d.mts.map +1 -0
- package/dist/index.d.mts +6 -5
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +11 -9
- package/dist/index.mjs.map +1 -0
- package/dist/{methods-CZp6XGn8.mjs → methods-7Ryz6zbd.mjs} +4 -2
- package/dist/methods-7Ryz6zbd.mjs.map +1 -0
- package/dist/{model-B6tJ9kX_.mjs → model-C16NUwXW.mjs} +2 -0
- package/dist/model-C16NUwXW.mjs.map +1 -0
- package/dist/{model-D6LQSveS.d.mts → model-_wqePNTL.d.mts} +4 -3
- package/dist/model-_wqePNTL.d.mts.map +1 -0
- package/dist/{models-dev-Y0ZikMBQ.d.mts → models-dev-DNgymZy3.d.mts} +3 -2
- package/dist/models-dev-DNgymZy3.d.mts.map +1 -0
- package/dist/{openai-codex-BhtZvNpm.mjs → openai-codex-Bz1EFPEi.mjs} +3 -1
- package/dist/openai-codex-Bz1EFPEi.mjs.map +1 -0
- package/dist/{openai-codex-Bk-iG7MZ.mjs → openai-codex-uvjhVoVy.mjs} +6 -4
- package/dist/openai-codex-uvjhVoVy.mjs.map +1 -0
- package/dist/{openai-compatible-hkXv-P74.mjs → openai-compatible-DBppnQ_N.mjs} +4 -2
- package/dist/openai-compatible-DBppnQ_N.mjs.map +1 -0
- package/dist/{openrouter-BflQBug2.mjs → openrouter-D8nTOAQo.mjs} +5 -3
- package/dist/openrouter-D8nTOAQo.mjs.map +1 -0
- package/dist/providers/openai-codex.d.mts +4 -3
- package/dist/providers/openai-codex.d.mts.map +1 -0
- package/dist/providers/openai-codex.mjs +1 -1
- package/dist/providers/openai-compatible.d.mts +3 -2
- package/dist/providers/openai-compatible.d.mts.map +1 -0
- package/dist/providers/openai-compatible.mjs +1 -1
- package/dist/providers/openrouter.d.mts +3 -2
- package/dist/providers/openrouter.d.mts.map +1 -0
- package/dist/providers/openrouter.mjs +1 -1
- package/dist/{shared-8d7RsyPH.mjs → shared-BIJaPhMm.mjs} +3 -1
- package/dist/shared-BIJaPhMm.mjs.map +1 -0
- package/dist/snapshot.d.mts +3 -2
- package/dist/snapshot.d.mts.map +1 -0
- package/dist/snapshot.mjs +4999 -4977
- package/dist/snapshot.mjs.map +1 -0
- package/dist/{turn-effort-DquDDwdE.mjs → turn-effort-C61L4JIt.mjs} +2 -0
- package/dist/turn-effort-C61L4JIt.mjs.map +1 -0
- package/package.json +3 -2
- package/src/agent/agent.ts +90 -0
- package/src/agent/attachments.ts +195 -0
- package/src/agent/classifier.ts +525 -0
- package/src/agent/compact.ts +384 -0
- package/src/agent/conversation.ts +300 -0
- package/src/agent/cost.ts +164 -0
- package/src/agent/inbox.ts +80 -0
- package/src/agent/instructions.ts +62 -0
- package/src/agent/loop.ts +675 -0
- package/src/agent/messages.ts +252 -0
- package/src/agent/on-demand.ts +58 -0
- package/src/agent/prompts.ts +35 -0
- package/src/agent/request-images.ts +94 -0
- package/src/agent/stop.ts +37 -0
- package/src/agent/title.ts +122 -0
- package/src/agent/tool-groups.ts +186 -0
- package/src/agent/tools.ts +106 -0
- package/src/app.ts +67 -0
- package/src/config/credential-file-store.ts +66 -0
- package/src/config/environment.ts +105 -0
- package/src/config/instructions.ts +157 -0
- package/src/config/load.ts +667 -0
- package/src/config/locked-file.ts +85 -0
- package/src/config/paths.ts +368 -0
- package/src/config/schema.ts +363 -0
- package/src/config/subagents.ts +156 -0
- package/src/config/trust.ts +53 -0
- package/src/config/write.ts +241 -0
- package/src/errors.ts +85 -0
- package/src/events/types.ts +258 -0
- package/src/glob.ts +161 -0
- package/src/index.ts +681 -0
- package/src/logger.ts +47 -0
- package/src/paths.ts +143 -0
- package/src/permissions/chain.ts +42 -0
- package/src/permissions/command.ts +233 -0
- package/src/permissions/layered.ts +77 -0
- package/src/permissions/match.ts +80 -0
- package/src/permissions/modes.ts +48 -0
- package/src/permissions/policy.ts +160 -0
- package/src/permissions/types.ts +159 -0
- package/src/providers/cache.ts +107 -0
- package/src/providers/capabilities.ts +77 -0
- package/src/providers/catalog-view.ts +91 -0
- package/src/providers/catalog.ts +65 -0
- package/src/providers/errors.ts +108 -0
- package/src/providers/factories/index.ts +15 -0
- package/src/providers/factories/openai-codex.ts +382 -0
- package/src/providers/factories/openai-compatible.ts +81 -0
- package/src/providers/factories/openrouter.ts +165 -0
- package/src/providers/factories/shared.ts +22 -0
- package/src/providers/model.ts +197 -0
- package/src/providers/models-dev.ts +355 -0
- package/src/providers/oauth/methods.ts +10 -0
- package/src/providers/oauth/openai-codex.ts +228 -0
- package/src/providers/oauth.ts +177 -0
- package/src/providers/openai-codex.ts +7 -0
- package/src/providers/openai-compatible.ts +2 -0
- package/src/providers/openrouter.ts +2 -0
- package/src/providers/registry.ts +464 -0
- package/src/providers/turn-effort.ts +156 -0
- package/src/providers/types.ts +83 -0
- package/src/session/backend.ts +44 -0
- package/src/session/file-store.ts +278 -0
- package/src/session/format.ts +1037 -0
- package/src/session/memory-store.ts +73 -0
- package/src/session/session.ts +153 -0
- package/src/session/store.ts +219 -0
- package/src/sign-in/attempt.ts +166 -0
- package/src/sign-in/loopback.ts +74 -0
- package/src/snapshot/data.json +8936 -0
- package/src/snapshot/index.ts +37 -0
- package/src/tools/bin.ts +364 -0
- package/src/tools/builtin.ts +48 -0
- package/src/tools/change.ts +88 -0
- package/src/tools/define.ts +267 -0
- package/src/tools/describe.ts +96 -0
- package/src/tools/fs/edit-file.ts +129 -0
- package/src/tools/fs/glob.ts +75 -0
- package/src/tools/fs/grep.ts +212 -0
- package/src/tools/fs/line-endings.ts +17 -0
- package/src/tools/fs/list-dir.ts +85 -0
- package/src/tools/fs/read-file.ts +230 -0
- package/src/tools/fs/ripgrep.ts +211 -0
- package/src/tools/fs/write-file.ts +97 -0
- package/src/tools/job.ts +252 -0
- package/src/tools/mcp/auth-store.ts +127 -0
- package/src/tools/mcp/command.ts +151 -0
- package/src/tools/mcp/config.ts +168 -0
- package/src/tools/mcp/servers.ts +463 -0
- package/src/tools/mcp/sign-in.ts +226 -0
- package/src/tools/mcp/stdio.ts +204 -0
- package/src/tools/mcp/tools.ts +173 -0
- package/src/tools/on-demand.ts +184 -0
- package/src/tools/registry.ts +935 -0
- package/src/tools/shell/bash.ts +217 -0
- package/src/tools/shell/find-bash.ts +162 -0
- package/src/tools/source.ts +35 -0
- package/src/tools/spill.ts +127 -0
- package/src/tools/subagents.ts +597 -0
- package/src/tools/tasks.ts +603 -0
- package/src/tools/to-model.ts +33 -0
- package/src/tools/web/address.ts +95 -0
- package/src/tools/web/exa.ts +163 -0
- package/src/tools/web/fetch.ts +373 -0
- package/src/tools/web/html.ts +173 -0
- package/src/tools/web/search.ts +111 -0
- package/src/tools/web/source.ts +51 -0
- package/src/units.ts +18 -0
- package/src/version.ts +23 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.mjs","names":["data"],"sources":["../src/snapshot/data.json","../src/snapshot/index.ts"],"mappings":";AC0BA,MAAM,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA;;AAGb,MAAa,sBAA8B,KAAK;AAEhD,MAAa,gBAAiC;CAAE,YAAY,CAAC;CAAG,SAAS,KAAK;AAAQ;;AAGtF,SAAgB,qBAAkD;CAChE,OAAO,OAAO,KAAK,KAAK,OAAO,CAAC,CAAC,WAAW,IAAI,KAAA,IAAY;AAC9D"}
|
|
@@ -191,3 +191,5 @@ function planTurnEfforts(prompt, current, render) {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
export { envVar as _, planTurnEfforts as a, APP_NAME as c, ENV_PREFIX as d, LOCAL_CONFIG_FILE_NAME as f, defineApp as g, WRAITH as h, explicitEffort as i, CONFIG_FILE_NAME as l, PROMPT_FILE_NAME as m, TURN_OPTIONS_KEY as n, quickestEffort as o, PROJECT_DIR_NAME as p, effortOf as r, stampEffort as s, TURN_EFFORT_MODELS as t, CREDENTIALS_FILE_NAME as u };
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=turn-effort-C61L4JIt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-effort-C61L4JIt.mjs","names":[],"sources":["../src/app.ts","../src/providers/turn-effort.ts"],"mappings":";;;;;;;;;AASA,MAAa,WAAW;;AAGxB,MAAa,aAAa;;AAG1B,MAAa,mBAAmB,IAAI;A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AAO,KAAK;CAE5B;CAEA,MAAM,WAA4B,CAAC;CACnC,OAAO,SAAS,SAAS,UAAU;EACjC,MAAM,SAAS,QAAQ,IAAI,KAAK;EAChC,IAAI,WAAW,KAAA,GAAW,SAAS,KAAK,OAAO,MAAM,CAAC;EACtD,SAAS,KAAK,OAAO;CACvB,CAAC;CAED,OAAO;EAAE,QAAQ;EAAU;CAAK;AAClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wraith-ai/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A general-purpose AI agent as a library: the tool loop, any AI SDK provider, tools, permissions, approvals, sessions and compaction.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
|
-
"dist"
|
|
37
|
+
"dist",
|
|
38
|
+
"src"
|
|
38
39
|
],
|
|
39
40
|
"engines": {
|
|
40
41
|
"node": ">=22"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type Model, toModel } from "../providers/model";
|
|
2
|
+
import type { AgentLanguageModel } from "../providers/types";
|
|
3
|
+
import type { Compactor } from "./compact";
|
|
4
|
+
import type { ModelPrices } from "./cost";
|
|
5
|
+
import { type Logger, noopLogger } from "../logger";
|
|
6
|
+
import { type StopCondition, isStepCount } from "./stop";
|
|
7
|
+
import { type ToolRunner, emptyToolRunner } from "./tools";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Everything the loop needs, assembled once and reused.
|
|
11
|
+
*
|
|
12
|
+
* Clock and id generator are injected rather than reached for, because events
|
|
13
|
+
* carry both — a test that cannot pin them cannot assert on an event stream.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export interface AgentOptions {
|
|
17
|
+
/**
|
|
18
|
+
* A `Model` from a provider or a registry, or a bare AI SDK model. A bare one
|
|
19
|
+
* brings its own ids and nothing else: no prices, no window, no cache fields.
|
|
20
|
+
*/
|
|
21
|
+
model: Model | AgentLanguageModel;
|
|
22
|
+
system?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The user's and the project's instruction files (`loadInstructions`), sent
|
|
25
|
+
* as a message in the conversation, not in `system`: a run sends them when
|
|
26
|
+
* the history does not hold this text, and again after a compaction.
|
|
27
|
+
*/
|
|
28
|
+
instructions?: string | undefined;
|
|
29
|
+
tools?: ToolRunner;
|
|
30
|
+
/**
|
|
31
|
+
* What this model costs, over what the model says. The core owns no catalog,
|
|
32
|
+
* and a host with no prices gets no cost figure rather than an invented one.
|
|
33
|
+
*/
|
|
34
|
+
pricing?: ModelPrices;
|
|
35
|
+
/**
|
|
36
|
+
* Window size, over what the model says, for `run-start`. A remote front end
|
|
37
|
+
* cannot reach the capability catalog, so it draws its meter from this.
|
|
38
|
+
*/
|
|
39
|
+
contextLimit?: number;
|
|
40
|
+
/** Absent means no compaction. */
|
|
41
|
+
compactor?: Compactor;
|
|
42
|
+
/** Absent or undefined: 100. Undefined too, so an unset config limit passes straight in. */
|
|
43
|
+
maxSteps?: number | undefined;
|
|
44
|
+
stopWhen?: StopCondition;
|
|
45
|
+
logger?: Logger;
|
|
46
|
+
now?: () => number;
|
|
47
|
+
newId?: (prefix: string) => string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Agent {
|
|
51
|
+
readonly model: Model;
|
|
52
|
+
readonly system: string | undefined;
|
|
53
|
+
readonly instructions: string | undefined;
|
|
54
|
+
readonly tools: ToolRunner;
|
|
55
|
+
readonly pricing: ModelPrices | undefined;
|
|
56
|
+
readonly contextLimit: number | undefined;
|
|
57
|
+
readonly compactor: Compactor | undefined;
|
|
58
|
+
readonly maxSteps: number;
|
|
59
|
+
readonly stopWhen: StopCondition;
|
|
60
|
+
readonly logger: Logger;
|
|
61
|
+
readonly now: () => number;
|
|
62
|
+
readonly newId: (prefix: string) => string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const DEFAULT_MAX_STEPS = 100;
|
|
66
|
+
|
|
67
|
+
function defaultIdGenerator(): (prefix: string) => string {
|
|
68
|
+
let counter = 0;
|
|
69
|
+
return (prefix) => `${prefix}-${++counter}-${Math.random().toString(36).slice(2, 8)}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createAgent(options: AgentOptions): Agent {
|
|
73
|
+
const model = toModel(options.model);
|
|
74
|
+
const maxSteps = options.maxSteps ?? DEFAULT_MAX_STEPS;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
model,
|
|
78
|
+
system: options.system,
|
|
79
|
+
instructions: options.instructions,
|
|
80
|
+
tools: options.tools ?? emptyToolRunner,
|
|
81
|
+
pricing: options.pricing ?? model.pricing,
|
|
82
|
+
contextLimit: options.contextLimit ?? model.contextLimit,
|
|
83
|
+
compactor: options.compactor,
|
|
84
|
+
maxSteps,
|
|
85
|
+
stopWhen: options.stopWhen ?? isStepCount(maxSteps),
|
|
86
|
+
logger: options.logger ?? noopLogger,
|
|
87
|
+
now: options.now ?? Date.now,
|
|
88
|
+
newId: options.newId ?? defaultIdGenerator(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { AgentError } from "../errors";
|
|
3
|
+
import { formatBytes } from "../units";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Images handed to the model, by the user or by a tool. One form from entry to
|
|
7
|
+
* log: base64 text, because the log is JSON and every vendor takes base64.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface Attachment {
|
|
11
|
+
/** Base64, without a `data:` prefix. */
|
|
12
|
+
data: string;
|
|
13
|
+
/** One of `IMAGE_MEDIA_TYPES`. */
|
|
14
|
+
mediaType: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** What a host sends: text, or text with attachments. No attachments is plain text. */
|
|
18
|
+
export type Prompt = string | { text: string; attachments?: readonly Attachment[] };
|
|
19
|
+
|
|
20
|
+
/** A prompt as the core hands it back: queued, recalled, starting a turn. */
|
|
21
|
+
export interface UserInput {
|
|
22
|
+
text: string;
|
|
23
|
+
attachments: readonly Attachment[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ImageInfo {
|
|
27
|
+
mediaType: string;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
/** Of the image itself, not of its base64. */
|
|
31
|
+
bytes: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const IMAGE_MEDIA_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"] as const;
|
|
35
|
+
|
|
36
|
+
/** Anthropic's, the strictest of the vendors; it counts the base64 text. */
|
|
37
|
+
export const MAX_IMAGE_BASE64 = 5 * 1024 * 1024;
|
|
38
|
+
|
|
39
|
+
/** Anthropic refuses an image with a longer side. */
|
|
40
|
+
export const MAX_IMAGE_SIDE = 8_000;
|
|
41
|
+
|
|
42
|
+
const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
43
|
+
|
|
44
|
+
/** Plain text and an object with no attachments become the same thing. */
|
|
45
|
+
export function toUserInput(prompt: Prompt): UserInput {
|
|
46
|
+
if (typeof prompt === "string") return { text: prompt, attachments: [] };
|
|
47
|
+
const attachments = prompt.attachments ?? [];
|
|
48
|
+
for (const attachment of attachments) imageInfo(attachment);
|
|
49
|
+
return { text: prompt.text, attachments };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Throws `attachment/too-large` for an image of this many bytes, before anybody reads them. */
|
|
53
|
+
export function checkImageSize(bytes: number): void {
|
|
54
|
+
const encoded = 4 * Math.ceil(bytes / 3);
|
|
55
|
+
if (encoded > MAX_IMAGE_BASE64) throw tooLarge(encoded);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Whether a file's first bytes are those of an image `imageFromBytes` takes. */
|
|
59
|
+
export function looksLikeImage(start: Uint8Array): boolean {
|
|
60
|
+
const b = Buffer.from(start.buffer, start.byteOffset, start.byteLength);
|
|
61
|
+
if (b.length >= 8 && b.readUInt32BE(0) === 0x89504e47 && b.readUInt32BE(4) === 0x0d0a1a0a) return true;
|
|
62
|
+
if (b.length >= 6 && (b.toString("latin1", 0, 6) === "GIF87a" || b.toString("latin1", 0, 6) === "GIF89a")) return true;
|
|
63
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return true;
|
|
64
|
+
return b.length >= 12 && b.toString("latin1", 0, 4) === "RIFF" && b.toString("latin1", 8, 12) === "WEBP";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Bytes from a clipboard or a file, checked and turned into an attachment. */
|
|
68
|
+
export function imageFromBytes(bytes: Uint8Array): Attachment {
|
|
69
|
+
checkImageSize(bytes.length);
|
|
70
|
+
const image = sniff(bytes);
|
|
71
|
+
if (image === undefined) throw unsupported();
|
|
72
|
+
checkSides(image);
|
|
73
|
+
return { data: Buffer.from(bytes).toString("base64"), mediaType: image.mediaType };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What an attachment holds, read from its bytes. Throws when it is not an image
|
|
78
|
+
* the vendors take, or when `mediaType` says something else than the bytes do.
|
|
79
|
+
*/
|
|
80
|
+
export function imageInfo(attachment: Attachment): ImageInfo {
|
|
81
|
+
if (attachment.data.length > MAX_IMAGE_BASE64) throw tooLarge(attachment.data.length);
|
|
82
|
+
if (attachment.data.startsWith("data:")) {
|
|
83
|
+
throw new AgentError("attachment/invalid", "Attachment data must be base64 without a `data:` prefix.");
|
|
84
|
+
}
|
|
85
|
+
if (attachment.data.length % 4 !== 0 || !BASE64.test(attachment.data)) {
|
|
86
|
+
throw new AgentError("attachment/invalid", "Attachment data is not base64.");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const bytes = Buffer.from(attachment.data, "base64");
|
|
90
|
+
const image = sniff(bytes);
|
|
91
|
+
if (image === undefined) throw unsupported();
|
|
92
|
+
const said = attachment.mediaType.toLowerCase() === "image/jpg" ? "image/jpeg" : attachment.mediaType.toLowerCase();
|
|
93
|
+
if (said !== image.mediaType) {
|
|
94
|
+
throw new AgentError(
|
|
95
|
+
"attachment/invalid",
|
|
96
|
+
`The attachment says ${attachment.mediaType}, but its data is ${image.mediaType}.`,
|
|
97
|
+
{ details: { mediaType: attachment.mediaType, actual: image.mediaType } },
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
checkSides(image);
|
|
101
|
+
return { ...image, bytes: bytes.length };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** "image/png, 1280×720, 96 KB": how a person or a model is told about one. */
|
|
105
|
+
export function describeImage(info: ImageInfo): string {
|
|
106
|
+
return `${info.mediaType}, ${String(info.width)}×${String(info.height)}, ${formatBytes(info.bytes)}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function tooLarge(encoded: number): AgentError {
|
|
110
|
+
return new AgentError(
|
|
111
|
+
"attachment/too-large",
|
|
112
|
+
`The image is ${formatBytes(encoded)} as base64; the limit is ${formatBytes(MAX_IMAGE_BASE64)}.`,
|
|
113
|
+
{ details: { bytes: encoded, limit: MAX_IMAGE_BASE64 } },
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function unsupported(): AgentError {
|
|
118
|
+
return new AgentError("attachment/unsupported-type", "Only PNG, JPEG, GIF and WebP images can be attached.");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function checkSides(image: { width: number; height: number }): void {
|
|
122
|
+
if (image.width <= MAX_IMAGE_SIDE && image.height <= MAX_IMAGE_SIDE) return;
|
|
123
|
+
throw new AgentError(
|
|
124
|
+
"attachment/too-large",
|
|
125
|
+
`The image is ${String(image.width)}×${String(image.height)}; neither side may exceed ${String(MAX_IMAGE_SIDE)} pixels.`,
|
|
126
|
+
{ details: { width: image.width, height: image.height, limit: MAX_IMAGE_SIDE } },
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type Sniffed = Omit<ImageInfo, "bytes">;
|
|
131
|
+
|
|
132
|
+
/** The type and size from the header, so a renamed file or a wrong label is caught. */
|
|
133
|
+
function sniff(bytes: Uint8Array): Sniffed | undefined {
|
|
134
|
+
const b = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
135
|
+
if (b.length >= 24 && b.readUInt32BE(0) === 0x89504e47 && b.readUInt32BE(4) === 0x0d0a1a0a) {
|
|
136
|
+
return { mediaType: "image/png", width: b.readUInt32BE(16), height: b.readUInt32BE(20) };
|
|
137
|
+
}
|
|
138
|
+
if (b.length >= 10 && (b.toString("latin1", 0, 6) === "GIF87a" || b.toString("latin1", 0, 6) === "GIF89a")) {
|
|
139
|
+
return { mediaType: "image/gif", width: b.readUInt16LE(6), height: b.readUInt16LE(8) };
|
|
140
|
+
}
|
|
141
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return jpeg(b);
|
|
142
|
+
if (b.length >= 30 && b.toString("latin1", 0, 4) === "RIFF" && b.toString("latin1", 8, 12) === "WEBP") {
|
|
143
|
+
return webp(b);
|
|
144
|
+
}
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The size lives in the first start-of-frame segment, after any metadata. */
|
|
149
|
+
function jpeg(b: Buffer): Sniffed | undefined {
|
|
150
|
+
let at = 2;
|
|
151
|
+
while (at + 9 < b.length) {
|
|
152
|
+
if (b[at] !== 0xff) {
|
|
153
|
+
at += 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const marker = b[at + 1] as number;
|
|
157
|
+
// Fill bytes, and markers that carry no length.
|
|
158
|
+
if (marker === 0xff) {
|
|
159
|
+
at += 1;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd8)) {
|
|
163
|
+
at += 2;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const isFrame = marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc;
|
|
167
|
+
if (isFrame) {
|
|
168
|
+
return { mediaType: "image/jpeg", width: b.readUInt16BE(at + 7), height: b.readUInt16BE(at + 5) };
|
|
169
|
+
}
|
|
170
|
+
at += 2 + b.readUInt16BE(at + 2);
|
|
171
|
+
}
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function webp(b: Buffer): Sniffed | undefined {
|
|
176
|
+
const chunk = b.toString("latin1", 12, 16);
|
|
177
|
+
if (chunk === "VP8 ") {
|
|
178
|
+
return { mediaType: "image/webp", width: b.readUInt16LE(26) & 0x3fff, height: b.readUInt16LE(28) & 0x3fff };
|
|
179
|
+
}
|
|
180
|
+
if (chunk === "VP8L") {
|
|
181
|
+
const b1 = b[21] as number;
|
|
182
|
+
const b2 = b[22] as number;
|
|
183
|
+
const b3 = b[23] as number;
|
|
184
|
+
const b4 = b[24] as number;
|
|
185
|
+
return {
|
|
186
|
+
mediaType: "image/webp",
|
|
187
|
+
width: 1 + (((b2 & 0x3f) << 8) | b1),
|
|
188
|
+
height: 1 + (((b4 & 0x0f) << 10) | (b3 << 2) | ((b2 & 0xc0) >> 6)),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (chunk === "VP8X") {
|
|
192
|
+
return { mediaType: "image/webp", width: 1 + b.readUIntLE(24, 3), height: 1 + b.readUIntLE(27, 3) };
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|