@skaile/transform-proxy 0.3.0 → 0.3.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/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as createTransformProxy, o as resolveProxyConfig, v as errorMessage } from "./config-PKHxejC8.mjs";
2
+ import { d as createTransformProxy, o as resolveProxyConfig, v as errorMessage } from "./config-BZsthgP-.mjs";
3
3
  import { realpathSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { homedir } from "node:os";
@@ -323,8 +323,8 @@ async function outbound$2(transform, text, leaf) {
323
323
  return text === "" ? text : transform.outbound(text, leaf);
324
324
  }
325
325
  /** A string, or an array of blocks whose `text` blocks are rewritten; anything else is refused. */
326
- async function rewriteText(content, slot, leaf, transform) {
327
- if (typeof content === "string") return outbound$2(transform, content, leaf);
326
+ async function rewriteText(content, slot, rewrite) {
327
+ if (typeof content === "string") return rewrite(content);
328
328
  if (!Array.isArray(content)) return malformed$2(slot);
329
329
  const out = [];
330
330
  for (const block of content) {
@@ -337,11 +337,30 @@ async function rewriteText(content, slot, leaf, transform) {
337
337
  if (typeof block.text !== "string") return malformed$2(`${slot} text block`);
338
338
  out.push({
339
339
  ...block,
340
- text: await outbound$2(transform, block.text, leaf)
340
+ text: await rewrite(block.text)
341
341
  });
342
342
  }
343
343
  return out;
344
344
  }
345
+ /**
346
+ * Host-written system text that Anthropic's Claude subscription (OAuth) check reads verbatim: the
347
+ * billing header line and the Claude Code identity sentence. Rewritten ("CLI for <NAME_…>",
348
+ * "cc_version=<CONTACT_IP_…>"), the request is answered 429 `rate_limit_error` "Error". Neither
349
+ * carries user data.
350
+ */
351
+ const BILLING_HEADER = "x-anthropic-billing-header:";
352
+ const CLAUDE_CODE_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude.";
353
+ /** The leading part of a system text that passes untransformed; `''` when there is none. */
354
+ function gatePrefix(text) {
355
+ if (text.startsWith(CLAUDE_CODE_IDENTITY)) return CLAUDE_CODE_IDENTITY;
356
+ if (!text.startsWith(BILLING_HEADER)) return "";
357
+ const end = text.indexOf("\n");
358
+ return end === -1 ? text : text.slice(0, end);
359
+ }
360
+ async function rewriteSystemText(text, transform) {
361
+ const kept = gatePrefix(text);
362
+ return kept + await outbound$2(transform, text.slice(kept.length), { kind: "system" });
363
+ }
345
364
  /** Every string leaf of a JSON value (tool-call input); keys stay as they are. */
346
365
  async function rewriteStrings$2(value, leaf, transform) {
347
366
  if (typeof value === "string") return outbound$2(transform, value, leaf);
@@ -421,10 +440,10 @@ async function rewriteContent$2(content, role, toolNames, ctx) {
421
440
  const toolName = typeof block.tool_use_id === "string" ? toolNames.get(block.tool_use_id) : void 0;
422
441
  out.push({
423
442
  ...block,
424
- content: await rewriteText(block.content, "tool_result content", {
443
+ content: await rewriteText(block.content, "tool_result content", (text) => outbound$2(ctx.transform, text, {
425
444
  kind: "toolResult",
426
445
  toolName
427
- }, ctx.transform)
446
+ }))
428
447
  });
429
448
  break;
430
449
  }
@@ -567,7 +586,7 @@ const anthropicWalker = {
567
586
  async request(body, ctx) {
568
587
  if (!isObj$2(body)) return malformed$2("request body");
569
588
  const out = { ...body };
570
- if (body.system !== void 0) out.system = await rewriteText(body.system, "system", { kind: "system" }, ctx.transform);
589
+ if (body.system !== void 0) out.system = await rewriteText(body.system, "system", (text) => rewriteSystemText(text, ctx.transform));
571
590
  if (ctx.transform.instruction !== void 0) out.system = withInstruction(out.system, ctx.transform.instruction);
572
591
  if (body.messages !== void 0) {
573
592
  if (!Array.isArray(body.messages)) return malformed$2("messages");
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { t as CONFIG_FILE_NAME, s as PIPELINE_HEADER, c as SESSION_HEADER, l as TOKEN_HEADER, u as UPSTREAM_HEADER, h as UnsupportedContentError, m as anthropicWalker, _ as composeTransforms, n as configCandidates, g as createSessionFacts, d as createTransformProxy, r as findProxyConfig, i as loadProxyConfig, p as openaiChatWalker, f as openaiResponsesWalker, a as parseProxyConfig, o as resolveProxyConfig, y as silentLogger } from "./config-PKHxejC8.mjs";
1
+ export { t as CONFIG_FILE_NAME, s as PIPELINE_HEADER, c as SESSION_HEADER, l as TOKEN_HEADER, u as UPSTREAM_HEADER, h as UnsupportedContentError, m as anthropicWalker, _ as composeTransforms, n as configCandidates, g as createSessionFacts, d as createTransformProxy, r as findProxyConfig, i as loadProxyConfig, p as openaiChatWalker, f as openaiResponsesWalker, a as parseProxyConfig, o as resolveProxyConfig, y as silentLogger } from "./config-BZsthgP-.mjs";
@@ -1,4 +1,4 @@
1
- import { c as SESSION_HEADER, i as loadProxyConfig, l as TOKEN_HEADER, n as configCandidates, r as findProxyConfig, u as UPSTREAM_HEADER, v as errorMessage } from "../config-PKHxejC8.mjs";
1
+ import { c as SESSION_HEADER, i as loadProxyConfig, l as TOKEN_HEADER, n as configCandidates, r as findProxyConfig, u as UPSTREAM_HEADER, v as errorMessage } from "../config-BZsthgP-.mjs";
2
2
  import { randomBytes, randomUUID } from "node:crypto";
3
3
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skaile/transform-proxy",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Same-protocol passthrough proxy that runs model requests and replies through a chain of text transforms (Anthropic Messages, OpenAI chat, OpenAI responses)",
6
6
  "license": "MIT",