@codeworksh/aikit 0.9.2 → 0.9.3-canary.10.1.g65d5c167

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/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { C as NamedError, _ as optionsKey, a as KnownProviderEnumSchema, c as calculateCost, d as getModels, f as getProviders, h as modelsAreEqual, i as KnownProviderEnum, l as clampThinkingLevel, m as model_exports, n as APIMethodEnumSchema, r as ActiveThinkingLevel, s as ThinkingBudgets$1, t as APIMethodEnum, u as getModel, v as registry, y as thinkingTokenBudgetField } from "./model-Czo0SKj0.mjs";
3
- import { C as ToolCallSchema, D as transformMessages, E as resolveJsonSchemaConstraint, S as AssistantMessageSchema, T as message_exports, g as shortHash, n as createOpenAICodex, r as openaiCodex, v as openAICodexTools, w as createAssistantMessage$1, x as resolveOpenAICodexToolConstraint } from "./openai-codex-CpaJcE8Q.mjs";
4
- import { r as normalize, t as failure_exports } from "./failure-SAPyG-w2.mjs";
5
- import { i as packageForModel, o as resolveLanguageModel, r as loadProviderFactory } from "./registry-vtzL8QxA.mjs";
3
+ import { C as ToolCallSchema, D as transformMessages, E as resolveJsonSchemaConstraint, S as AssistantMessageSchema, T as message_exports, g as shortHash, n as createOpenAICodex, r as openaiCodex, v as openAICodexTools, w as createAssistantMessage$1, x as resolveOpenAICodexToolConstraint } from "./openai-codex-MpxV35tx.mjs";
4
+ import { r as normalize, t as failure_exports } from "./failure-Bm4tDJMr.mjs";
5
+ import { i as packageForModel, o as resolveLanguageModel, r as loadProviderFactory } from "./registry-CZtcfRPL.mjs";
6
6
  import { i as githubCopilot, r as createGitHubCopilot } from "./github-copilot-eDhLBMfL.mjs";
7
7
  import Type$2, { Type, Type as Type$1 } from "typebox";
8
8
  import { jsonSchema, streamText } from "ai";
@@ -196,6 +196,31 @@ function clearProtocolProviders() {
196
196
  protocolRegistry.clear();
197
197
  }
198
198
  //#endregion
199
+ //#region src/llm/runtime.ts
200
+ function mergeHeaders(...headerSources) {
201
+ const merged = {};
202
+ for (const headers of headerSources) if (headers) Object.assign(merged, headers);
203
+ return merged;
204
+ }
205
+ /** The provider's API key from the environment, checking its `key` then each `env` name. */
206
+ function getEnvApiKey(provider) {
207
+ if (typeof process === "undefined") return;
208
+ const candidates = [provider.key, ...provider.env ?? []].filter((name) => Boolean(name));
209
+ for (const name of candidates) {
210
+ const value = process.env[name];
211
+ if (value) return value;
212
+ }
213
+ }
214
+ function formatThrownError(error) {
215
+ if (error instanceof Error) return error.stack || error.message || error.name;
216
+ if (typeof error === "string") return error;
217
+ try {
218
+ return JSON.stringify(error);
219
+ } catch {
220
+ return String(error);
221
+ }
222
+ }
223
+ //#endregion
199
224
  //#region src/utils/estimate.ts
200
225
  /** Rough characters-per-token ratio across the tokenizers in use. */
201
226
  const CHARS_PER_TOKEN = 4;
@@ -352,7 +377,7 @@ const ThinkingBudgets = ThinkingBudgets$1;
352
377
  const SharedOptions = Type$1.Evaluate(Type$1.Intersect([GenerationOptions, HelperOptions]));
353
378
  /** Headroom left for the prompt when sizing a response against the context window. */
354
379
  const CONTEXT_SAFETY_TOKENS = 4096;
355
- const MIN_MAX_TOKENS = 1;
380
+ const MIN_MAX_TOKENS = 16;
356
381
  /**
357
382
  * The model's own ceiling, unless the caller named a smaller one.
358
383
  *
@@ -558,30 +583,6 @@ function cacheWrite1hTokens(providerMetadata) {
558
583
  }
559
584
  }
560
585
  //#endregion
561
- //#region src/llm/runtime.ts
562
- function mergeHeaders(...headerSources) {
563
- const merged = {};
564
- for (const headers of headerSources) if (headers) Object.assign(merged, headers);
565
- return merged;
566
- }
567
- function getEnvApiKey(provider) {
568
- if (typeof process === "undefined") return;
569
- const candidates = [provider.key, ...provider.env ?? []].filter((name) => Boolean(name));
570
- for (const name of candidates) {
571
- const value = process.env[name];
572
- if (value) return value;
573
- }
574
- }
575
- function formatThrownError(error) {
576
- if (error instanceof Error) return error.stack || error.message || error.name;
577
- if (typeof error === "string") return error;
578
- try {
579
- return JSON.stringify(error);
580
- } catch {
581
- return String(error);
582
- }
583
- }
584
- //#endregion
585
586
  //#region src/llm/provider.ts
586
587
  function cleanHeaders(headers) {
587
588
  const result = {};
@@ -726,7 +727,10 @@ function googleThinkingLevel(mapped) {
726
727
  function disabledProviderOptions(model) {
727
728
  if (!model.reasoning) return {};
728
729
  const key = optionsKey(model);
729
- if (key === "anthropic" || key === "google-vertex-anthropic") return { [key]: { thinking: { type: "disabled" } } };
730
+ if (key === "anthropic" || key === "google-vertex-anthropic") {
731
+ if (model.thinkingLevelMap?.off === null) return {};
732
+ return { [key]: { thinking: { type: "disabled" } } };
733
+ }
730
734
  if (key === "github-copilot") {
731
735
  if (model.api?.method === APIMethodEnum.messages) return { [key]: { thinking: { type: "disabled" } } };
732
736
  return {};
@@ -957,7 +961,7 @@ function createAssistantMessage(model) {
957
961
  }
958
962
  });
959
963
  }
960
- function userContent(parts, supportsImages) {
964
+ function userContent(parts) {
961
965
  const content = [];
962
966
  for (const part of parts) {
963
967
  if (part.type === "text") {
@@ -968,7 +972,7 @@ function userContent(parts, supportsImages) {
968
972
  });
969
973
  continue;
970
974
  }
971
- if (supportsImages) content.push({
975
+ content.push({
972
976
  type: "file",
973
977
  data: part.data,
974
978
  mediaType: part.mimeType
@@ -1030,6 +1034,25 @@ function normalizeOpenAICodexToolCallId(id, model, source) {
1030
1034
  if (!normalizedItemId.startsWith("fc_") && !normalizedItemId.startsWith("ctc_")) normalizedItemId = normalizeOpenAICodexIdPart(`fc_${normalizedItemId}`);
1031
1035
  return `${normalizedCallId}|${normalizedItemId}`;
1032
1036
  }
1037
+ /**
1038
+ * OpenAI (`call_id`, at most 64 characters), Anthropic (`^[a-zA-Z0-9_-]+$`) and
1039
+ * OpenRouter upstreams take a foreign tool call ID verbatim, so a Codex
1040
+ * `call|item` ID keeps only its unique call half.
1041
+ */
1042
+ function normalizeForeignToolCallId(id) {
1043
+ if (/^[a-zA-Z0-9_-]{1,64}$/.test(id)) return id;
1044
+ return normalizeOpenAICodexIdPart(id.split("|")[0] ?? id);
1045
+ }
1046
+ function toolCallIdNormalizer(model) {
1047
+ switch (model.protocol) {
1048
+ case KnownProviderEnum.openaiCodex: return normalizeOpenAICodexToolCallId;
1049
+ case KnownProviderEnum.openai:
1050
+ case KnownProviderEnum.anthropic:
1051
+ case KnownProviderEnum.googleVertexAnthropic:
1052
+ case KnownProviderEnum.openrouter: return normalizeForeignToolCallId;
1053
+ default: return;
1054
+ }
1055
+ }
1033
1056
  function isRecord(value) {
1034
1057
  return typeof value === "object" && value !== null && !Array.isArray(value);
1035
1058
  }
@@ -1151,10 +1174,10 @@ function assistantMessages(message, model) {
1151
1174
  }
1152
1175
  function convertMessages(context, model) {
1153
1176
  const messages = [];
1154
- const transformedMessages = transformMessages(context.messages, model, model.protocol === KnownProviderEnum.openaiCodex ? normalizeOpenAICodexToolCallId : void 0);
1177
+ const transformedMessages = transformMessages(context.messages, model, toolCallIdNormalizer(model));
1155
1178
  for (const msg of transformedMessages) {
1156
1179
  if (msg.role === "user") {
1157
- messages.push(...userContent(msg.parts, model.input.includes("image")));
1180
+ messages.push(...userContent(msg.parts));
1158
1181
  continue;
1159
1182
  }
1160
1183
  messages.push(...assistantMessages(msg, model));
@@ -1668,6 +1691,6 @@ function validateToolArguments(tool, toolExecution) {
1668
1691
  return validateSchema(tool.parameters, toolExecution.rawArgs, `Tool "${toolExecution.name}"`);
1669
1692
  }
1670
1693
  //#endregion
1671
- export { event_exports as Event, EventStream, failure_exports as Failure, message_exports as Message, model_exports as Model, protocol_exports as Protocol, ThinkingBudgets, Type, createAssistantMessageEventStream, createGitHubCopilot, createOpenAICodex, githubCopilot, llm, openAICodexTools, openaiCodex, stream, validateSchema, validateToolArguments, validateToolCall };
1694
+ export { event_exports as Event, EventStream, failure_exports as Failure, message_exports as Message, model_exports as Model, protocol_exports as Protocol, ThinkingBudgets, Type, createAssistantMessageEventStream, createGitHubCopilot, createOpenAICodex, getEnvApiKey, githubCopilot, llm, openAICodexTools, openaiCodex, stream, validateSchema, validateToolArguments, validateToolCall };
1672
1695
 
1673
1696
  //# sourceMappingURL=index.mjs.map