@hiper2d/ai-agents 0.31.1 → 0.33.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 +21 -12
- package/dist/index.d.ts +21 -12
- package/dist/index.js +50 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -902,7 +902,7 @@ var SupportedAiModels = {
|
|
|
902
902
|
apiKeyName: API_KEY_CONSTANTS.ANTHROPIC,
|
|
903
903
|
hasThinking: true,
|
|
904
904
|
reasoningEffort: "high",
|
|
905
|
-
tags: ["expensive"]
|
|
905
|
+
tags: ["fast", "expensive"]
|
|
906
906
|
},
|
|
907
907
|
// Haiku moved 4.5 → 5.5 on 2026-10-08 (`claude-haiku-5-5`, verified live with the platform
|
|
908
908
|
// key). 10x cheaper ($0.10/$0.50 up to 100K-token prompts), 1M context / 128K output.
|
|
@@ -916,7 +916,7 @@ var SupportedAiModels = {
|
|
|
916
916
|
apiKeyName: API_KEY_CONSTANTS.ANTHROPIC,
|
|
917
917
|
hasThinking: true,
|
|
918
918
|
reasoningEffort: "high",
|
|
919
|
-
tags: ["cheap"]
|
|
919
|
+
tags: ["fast", "cheap"]
|
|
920
920
|
},
|
|
921
921
|
// DeepSeek V4 models — thinking-only entries (non-thinking variants retired 2026-08-05).
|
|
922
922
|
// reasoningEffort pinned to 'low' 2026-08-30: at the provider default ('high', no budget
|
|
@@ -933,7 +933,7 @@ var SupportedAiModels = {
|
|
|
933
933
|
reasoningEffort: "low",
|
|
934
934
|
// Reasoning tokens share the output budget, so leave room for both CoT and answer.
|
|
935
935
|
maxOutputTokens: 65536,
|
|
936
|
-
tags: ["cheap"]
|
|
936
|
+
tags: ["very-fast", "cheap"]
|
|
937
937
|
},
|
|
938
938
|
[LLM_CONSTANTS.DEEPSEEK_PRO]: {
|
|
939
939
|
displayName: "DeepSeek V4 Pro",
|
|
@@ -1052,8 +1052,7 @@ var SupportedAiModels = {
|
|
|
1052
1052
|
modelApiName: "gemini-3.8-flash",
|
|
1053
1053
|
apiKeyName: API_KEY_CONSTANTS.GOOGLE,
|
|
1054
1054
|
hasThinking: true,
|
|
1055
|
-
reasoningEffort: "medium"
|
|
1056
|
-
tags: ["fast"]
|
|
1055
|
+
reasoningEffort: "medium"
|
|
1057
1056
|
},
|
|
1058
1057
|
[LLM_CONSTANTS.GEMINI_LITE]: {
|
|
1059
1058
|
displayName: "Gemini 3.5 Flash Lite",
|
|
@@ -1063,7 +1062,7 @@ var SupportedAiModels = {
|
|
|
1063
1062
|
reasoningEffort: "minimal",
|
|
1064
1063
|
// Pre-3.6, same as Pro: keeps the 0.2 it always had.
|
|
1065
1064
|
temperature: 0.2,
|
|
1066
|
-
tags: ["fast", "cheap"]
|
|
1065
|
+
tags: ["very-fast", "cheap"]
|
|
1067
1066
|
},
|
|
1068
1067
|
// Always-on reasoning — no non-thinking sibling. Bumped 4.6 → 4.7 on 2026-09-22 (id verified
|
|
1069
1068
|
// against GET /v1/models). Same price, same 200K extended-context boundary; the context
|
|
@@ -1118,7 +1117,7 @@ var SupportedAiModels = {
|
|
|
1118
1117
|
// model reasons when the field is omitted. The API now takes low|medium|high on Large 4
|
|
1119
1118
|
// (the 400 for `none` lists exactly those; Small still takes only high|none); the level
|
|
1120
1119
|
// barely moved latency or trace size (4-12k chars at every level), so it stays on the
|
|
1121
|
-
// documented 'high' default. Model list: 1M context. Tagged `slow`:
|
|
1120
|
+
// documented 'high' default. Model list: 1M context. Tagged `slow`: prod p90 27.8s (2026-11-03).
|
|
1122
1121
|
[LLM_CONSTANTS.MISTRAL_LARGE]: {
|
|
1123
1122
|
displayName: "Mistral Large 4",
|
|
1124
1123
|
// `mistral-large-latest` still points at Large 3 (no reasoning); use the explicit id.
|
|
@@ -1135,7 +1134,7 @@ var SupportedAiModels = {
|
|
|
1135
1134
|
apiKeyName: API_KEY_CONSTANTS.MISTRAL,
|
|
1136
1135
|
hasThinking: true,
|
|
1137
1136
|
reasoningEffort: "high",
|
|
1138
|
-
tags: ["
|
|
1137
|
+
tags: ["fast", "cheap"]
|
|
1139
1138
|
},
|
|
1140
1139
|
// Kimi models. Always-reasoning entries: K3-series models reason by default and the only way
|
|
1141
1140
|
// to stop it is the undocumented K2-era `thinking: disabled` toggle, which we no longer rely on.
|
|
@@ -1146,7 +1145,7 @@ var SupportedAiModels = {
|
|
|
1146
1145
|
// 15-character story pipeline) to Kimi K3.1 Pro ($2/$10, 1M context, same low|high|max
|
|
1147
1146
|
// effort levels, default max). Live at high effort 2026-10-23: 3-sentence schema ask
|
|
1148
1147
|
// 4.2-4.5s, 8-character scene (476-845 output tokens) 9.7-14.9s = 49-57 tok/s — the same
|
|
1149
|
-
// output speed as K3
|
|
1148
|
+
// output speed as K3. Prod 2026-11-03: p90 34.1s, so `very-slow`.
|
|
1150
1149
|
// Consumer policy (werewolf): 1 bot per free game (opt-in) until 100 turns are measured.
|
|
1151
1150
|
[LLM_CONSTANTS.KIMI]: {
|
|
1152
1151
|
displayName: "Kimi K3.1 Pro",
|
|
@@ -1157,7 +1156,7 @@ var SupportedAiModels = {
|
|
|
1157
1156
|
// Pinned 'high' 2026-09-22, down from Moonshot's 'max' default: K3 had no levels at
|
|
1158
1157
|
// launch and the agent hardcoded max, so this is the first time the knob exists.
|
|
1159
1158
|
reasoningEffort: "high",
|
|
1160
|
-
tags: ["slow", "expensive"]
|
|
1159
|
+
tags: ["very-slow", "expensive"]
|
|
1161
1160
|
},
|
|
1162
1161
|
// Same model, Moonshot's high-speed serving tier ("roughly two to three times faster",
|
|
1163
1162
|
// platform.kimi.ai K3.1 Pro quickstart, read 2026-10-23) at 2x the price ($4/$20 — Opus 5.5
|
|
@@ -1187,8 +1186,7 @@ var SupportedAiModels = {
|
|
|
1187
1186
|
reasoningEffort: "high",
|
|
1188
1187
|
// Headroom for the shared reasoning+answer budget (like the DeepSeek entries), sized
|
|
1189
1188
|
// at 2x default rather than DeepSeek's 65536 to bound worst-case latency on a slow model.
|
|
1190
|
-
maxOutputTokens: 16384
|
|
1191
|
-
tags: ["slow"]
|
|
1189
|
+
maxOutputTokens: 16384
|
|
1192
1190
|
},
|
|
1193
1191
|
// GLM-5.3-Flash (added 2026-08-30): the cheap sibling. Same API contract as GLM-5.3 —
|
|
1194
1192
|
// thinking cannot be disabled and reasoning_effort takes low|high|max only
|
|
@@ -1269,7 +1267,7 @@ var SupportedAiModels = {
|
|
|
1269
1267
|
// the 3.7 models (verified live) — add it to their entries if they ever need taming.
|
|
1270
1268
|
thinkingBudgetTokens: 1024,
|
|
1271
1269
|
// Capped it measures 25-26s → the >25s tier.
|
|
1272
|
-
tags: ["
|
|
1270
|
+
tags: ["slow"]
|
|
1273
1271
|
},
|
|
1274
1272
|
// qwen3.8-flash replaced qwen3.7-flash on 2026-08-30 (same 1M context, 128k max output);
|
|
1275
1273
|
// qwen3.7-plus was retired the same day — persisted 'qwen-plus' ids resolve to this entry
|
|
@@ -1297,8 +1295,8 @@ var SupportedAiModels = {
|
|
|
1297
1295
|
// 1.7s and the 8-character scene (363 output tokens) in 2.4s — ~150 tok/s, the fastest
|
|
1298
1296
|
// provider in the sweep that day (Kimi Highspeed's scene takes 8s); a 3.2k-token game
|
|
1299
1297
|
// prompt with a two-sentence JSON reply took 1.9-2.1s at every effort level vs 3.5s for M3.
|
|
1300
|
-
//
|
|
1301
|
-
//
|
|
1298
|
+
// Production 2026-11-03 (1,271 bot turns): p50 4.8s but p90 16.0s, so no speed tag (see
|
|
1299
|
+
// the grading above; it was `fast` on the sweep). Launched 2026-09-27 as Token-Plan-only (the
|
|
1302
1300
|
// 2026-10-02 probe got `unknown model` on the pay-as-you-go key); on the key since at
|
|
1303
1301
|
// least 2026-10-27.
|
|
1304
1302
|
[LLM_CONSTANTS.MINIMAX]: {
|
|
@@ -1307,7 +1305,7 @@ var SupportedAiModels = {
|
|
|
1307
1305
|
apiKeyName: API_KEY_CONSTANTS.MINIMAX,
|
|
1308
1306
|
hasThinking: true,
|
|
1309
1307
|
reasoningEffort: "medium",
|
|
1310
|
-
tags: ["
|
|
1308
|
+
tags: ["cheap"]
|
|
1311
1309
|
},
|
|
1312
1310
|
// Meta Muse Spark 1.3 (added 2026-09-12) on Meta's own Model API — Standard tier, i.e.
|
|
1313
1311
|
// the private model id (the `-contributor` id is a quarter of the price but Meta trains
|
|
@@ -1317,8 +1315,8 @@ var SupportedAiModels = {
|
|
|
1317
1315
|
// game default: turns are short and every reasoning token bills as output.
|
|
1318
1316
|
// Temperature: Meta documents the model as tuned to its 1.0 default.
|
|
1319
1317
|
// Speed: measured 2026-09-12 at medium effort — 9.6s on a full-context day-2 vote, 4-8s on
|
|
1320
|
-
// short turns (reasoning ≈ 90% of output tokens).
|
|
1321
|
-
//
|
|
1318
|
+
// short turns (reasoning ≈ 90% of output tokens). Prod 2026-11-03: p50 10.5s, p90 24.6s,
|
|
1319
|
+
// which is `slow` by the grading above. Price-wise it
|
|
1322
1320
|
// is neither cheap nor expensive.
|
|
1323
1321
|
[LLM_CONSTANTS.MUSE_SPARK]: {
|
|
1324
1322
|
displayName: "Muse Spark 1.3",
|
|
@@ -2874,22 +2872,29 @@ ${instruction}`);
|
|
|
2874
2872
|
|
|
2875
2873
|
// src/agents/anthropic-agent.ts
|
|
2876
2874
|
import { Anthropic } from "@anthropic-ai/sdk";
|
|
2875
|
+
var CACHE_WRITE_MULTIPLIER = { "5m": 1.25, "1h": 2 };
|
|
2877
2876
|
var rejectsDisabledThinking = (model) => model.includes("fable") || model.includes("opus-5-5");
|
|
2878
2877
|
var usesBetweenToolsForOff = (model) => model.includes("sonnet-5-5");
|
|
2879
2878
|
var usesAdaptiveThinking = (model) => !model.includes("haiku-4");
|
|
2880
2879
|
var ClaudeAgent = class extends AbstractAgent {
|
|
2881
2880
|
client;
|
|
2882
2881
|
/**
|
|
2883
|
-
* TTL for every breakpoint this agent places (system tiers and the message anchor)
|
|
2884
|
-
* Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads
|
|
2885
|
-
* refreshes the timer on either TTL
|
|
2886
|
-
*
|
|
2887
|
-
*
|
|
2888
|
-
*
|
|
2889
|
-
*
|
|
2882
|
+
* TTL for every breakpoint this agent places (system tiers and the message anchor), or
|
|
2883
|
+
* 'off' to place none. Anthropic bills a 5m write at 1.25x input, a 1h write at 2x, reads
|
|
2884
|
+
* at 0.1x, and a read refreshes the timer on either TTL; with no breakpoint every token is
|
|
2885
|
+
* plain 1x input (Claude has no implicit caching). Caching pays only when enough of what
|
|
2886
|
+
* is written gets read back: break-even is ~22% of the prompt read at 5m and ~53% at 1h.
|
|
2887
|
+
* Measured on Werewolf (human-paced, consecutive calls for one bot 12-78 minutes apart):
|
|
2888
|
+
* 5m read 0-16% back, 1h 42-43% over 30 days of production bot turns (2026-11-06) — both
|
|
2889
|
+
* cost more than no cache, so that host sets 'off'. Default '1h' for continuous traffic
|
|
2890
|
+
* where calls land inside the window. One knob for all breakpoints on purpose: Anthropic
|
|
2890
2891
|
* requires 1h entries to precede 5m ones, and a single TTL keeps that trivially true.
|
|
2891
2892
|
*/
|
|
2892
2893
|
cacheTtl = "1h";
|
|
2894
|
+
/** The cache_control to attach to a breakpoint, or none when caching is off. */
|
|
2895
|
+
get cacheControl() {
|
|
2896
|
+
return this.cacheTtl === "off" ? {} : { cache_control: { type: "ephemeral", ttl: this.cacheTtl } };
|
|
2897
|
+
}
|
|
2893
2898
|
// System-prompt breakpoints, one per cache tier (see CACHE_TIER_MARKER):
|
|
2894
2899
|
// block 1 - shared static rules, byte-identical across all bots and games with the
|
|
2895
2900
|
// same rule set. Caches are scoped per model, so one entry serves every bot
|
|
@@ -2905,7 +2910,7 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
2905
2910
|
get defaultParams() {
|
|
2906
2911
|
return {
|
|
2907
2912
|
max_tokens: this.maxOutputTokens,
|
|
2908
|
-
system: this.instructionParts.map((part) => ({ type: "text", text: part,
|
|
2913
|
+
system: this.instructionParts.map((part) => ({ type: "text", text: part, ...this.cacheControl })),
|
|
2909
2914
|
model: this.model
|
|
2910
2915
|
};
|
|
2911
2916
|
}
|
|
@@ -3004,6 +3009,9 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3004
3009
|
* which for us is exactly the never-repeated tail — every entry it wrote would be dead.
|
|
3005
3010
|
*/
|
|
3006
3011
|
applyCacheBreakpoint(messages) {
|
|
3012
|
+
if (this.cacheTtl === "off") {
|
|
3013
|
+
return;
|
|
3014
|
+
}
|
|
3007
3015
|
if (messages.length < 2) {
|
|
3008
3016
|
return;
|
|
3009
3017
|
}
|
|
@@ -3026,9 +3034,11 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3026
3034
|
* Builds TokenUsage from the response. Anthropic's input_tokens EXCLUDES cached tokens
|
|
3027
3035
|
* (total prompt = input_tokens + cache_read + cache_creation), unlike the OpenAI-shaped
|
|
3028
3036
|
* providers whose prompt_tokens include them — so reconstruct the full prompt size here
|
|
3029
|
-
* before pricing. Cache reads bill at the cacheHitPrice (~0.1x)
|
|
3030
|
-
* 1.25x
|
|
3031
|
-
*
|
|
3037
|
+
* before pricing. Cache reads bill at the cacheHitPrice (~0.1x). Cache writes bill at a
|
|
3038
|
+
* multiple of input by TTL (1.25x for 5m, 2x for 1h); MODEL_PRICING has no write rate, so
|
|
3039
|
+
* the premium is added on top at the call's effective input rate (which keeps any
|
|
3040
|
+
* long-context tier). Until 0.33.0 writes were priced at plain input, under-reporting
|
|
3041
|
+
* every 1h write by half.
|
|
3032
3042
|
*/
|
|
3033
3043
|
buildTokenUsage(usage) {
|
|
3034
3044
|
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
@@ -3036,7 +3046,14 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3036
3046
|
const uncachedInputTokens = usage.input_tokens || 0;
|
|
3037
3047
|
const inputTokens = uncachedInputTokens + cacheReadTokens + cacheWriteTokens;
|
|
3038
3048
|
const outputTokens = usage.output_tokens || 0;
|
|
3039
|
-
|
|
3049
|
+
let cost = calculateAnthropicCost(this.model, inputTokens, outputTokens, cacheReadTokens);
|
|
3050
|
+
if (cacheWriteTokens > 0) {
|
|
3051
|
+
const byTtl = usage.cache_creation;
|
|
3052
|
+
const written1h = byTtl ? byTtl.ephemeral_1h_input_tokens ?? 0 : this.cacheTtl === "1h" ? cacheWriteTokens : 0;
|
|
3053
|
+
const written5m = byTtl ? byTtl.ephemeral_5m_input_tokens ?? 0 : cacheWriteTokens - written1h;
|
|
3054
|
+
const inputRate = inputTokens > 0 ? calculateAnthropicCost(this.model, inputTokens, 0, 0) / inputTokens : 0;
|
|
3055
|
+
cost += inputRate * (written1h * (CACHE_WRITE_MULTIPLIER["1h"] - 1) + written5m * (CACHE_WRITE_MULTIPLIER["5m"] - 1));
|
|
3056
|
+
}
|
|
3040
3057
|
if (cacheReadTokens > 0 || cacheWriteTokens > 0) {
|
|
3041
3058
|
this.logger(`\u{1F4BE} Prompt cache: ${cacheReadTokens} read, ${cacheWriteTokens} written, ${uncachedInputTokens} uncached`);
|
|
3042
3059
|
}
|
|
@@ -3045,8 +3062,9 @@ var ClaudeAgent = class extends AbstractAgent {
|
|
|
3045
3062
|
outputTokens,
|
|
3046
3063
|
totalTokens: inputTokens + outputTokens,
|
|
3047
3064
|
costUSD: cost,
|
|
3048
|
-
//
|
|
3049
|
-
...cacheReadTokens > 0 ? { cachedInputTokens: cacheReadTokens } : {}
|
|
3065
|
+
// Breakdowns of inputTokens, omitted when zero (Firestore rejects undefined).
|
|
3066
|
+
...cacheReadTokens > 0 ? { cachedInputTokens: cacheReadTokens } : {},
|
|
3067
|
+
...cacheWriteTokens > 0 ? { cacheWriteTokens } : {}
|
|
3050
3068
|
};
|
|
3051
3069
|
}
|
|
3052
3070
|
convertRole(role) {
|