@omnicross/contracts 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/account-tokens-types.cjs +18 -0
  4. package/dist/account-tokens-types.d.cts +142 -0
  5. package/dist/account-tokens-types.d.ts +142 -0
  6. package/dist/account-tokens-types.js +0 -0
  7. package/dist/canonical-models.cjs +262 -0
  8. package/dist/canonical-models.d.cts +107 -0
  9. package/dist/canonical-models.d.ts +107 -0
  10. package/dist/canonical-models.js +232 -0
  11. package/dist/completion-types.cjs +18 -0
  12. package/dist/completion-types.d.cts +324 -0
  13. package/dist/completion-types.d.ts +324 -0
  14. package/dist/completion-types.js +0 -0
  15. package/dist/endpoint-resolver.cjs +54 -0
  16. package/dist/endpoint-resolver.d.cts +43 -0
  17. package/dist/endpoint-resolver.d.ts +43 -0
  18. package/dist/endpoint-resolver.js +29 -0
  19. package/dist/extended-context.cjs +39 -0
  20. package/dist/extended-context.d.cts +21 -0
  21. package/dist/extended-context.d.ts +21 -0
  22. package/dist/extended-context.js +13 -0
  23. package/dist/index.cjs +2724 -0
  24. package/dist/index.d.cts +14 -0
  25. package/dist/index.d.ts +14 -0
  26. package/dist/index.js +2656 -0
  27. package/dist/llm-config-CQjOimv2.d.cts +390 -0
  28. package/dist/llm-config-D1jKQLVp.d.ts +390 -0
  29. package/dist/llm-config.cjs +18 -0
  30. package/dist/llm-config.d.cts +2 -0
  31. package/dist/llm-config.d.ts +2 -0
  32. package/dist/llm-config.js +0 -0
  33. package/dist/mcp-types.cjs +33 -0
  34. package/dist/mcp-types.d.cts +131 -0
  35. package/dist/mcp-types.d.ts +131 -0
  36. package/dist/mcp-types.js +8 -0
  37. package/dist/message-blocks.cjs +18 -0
  38. package/dist/message-blocks.d.cts +44 -0
  39. package/dist/message-blocks.d.ts +44 -0
  40. package/dist/message-blocks.js +0 -0
  41. package/dist/provider-presets/index.cjs +2183 -0
  42. package/dist/provider-presets/index.d.cts +104 -0
  43. package/dist/provider-presets/index.d.ts +104 -0
  44. package/dist/provider-presets/index.js +2143 -0
  45. package/dist/subscription-types.cjs +48 -0
  46. package/dist/subscription-types.d.cts +149 -0
  47. package/dist/subscription-types.d.ts +149 -0
  48. package/dist/subscription-types.js +22 -0
  49. package/dist/thinking-CBWSLel8.d.cts +33 -0
  50. package/dist/thinking-CBWSLel8.d.ts +33 -0
  51. package/dist/thinking-config.cjs +243 -0
  52. package/dist/thinking-config.d.cts +71 -0
  53. package/dist/thinking-config.d.ts +71 -0
  54. package/dist/thinking-config.js +205 -0
  55. package/dist/usage-types.cjs +18 -0
  56. package/dist/usage-types.d.cts +41 -0
  57. package/dist/usage-types.d.ts +41 -0
  58. package/dist/usage-types.js +0 -0
  59. package/dist/websearch-types.cjs +37 -0
  60. package/dist/websearch-types.d.cts +76 -0
  61. package/dist/websearch-types.d.ts +76 -0
  62. package/dist/websearch-types.js +11 -0
  63. package/package.json +116 -0
@@ -0,0 +1,71 @@
1
+ import { T as ThinkLevel } from './thinking-CBWSLel8.cjs';
2
+ import { M as ModelConfig } from './llm-config-CQjOimv2.cjs';
3
+
4
+ /**
5
+ * thinking-config — dependency-light thinking-budget / reasoning-effort helpers.
6
+ *
7
+ * The PURE budget/effort functions the `@omnicross/*` packages consume
8
+ * (`getOpenAIReasoningEffort`, `buildAnthropicThinking`, `calculateThinkingBudget`,
9
+ * `getClaudeMaxTokens`, `isReasoningModel`, `DEFAULT_MAX_TOKENS`) plus the in-file
10
+ * regex/numeric data they rely on.
11
+ *
12
+ * This module is intentionally import-closed (0 runtime deps): it OMITS any
13
+ * global model-thinking-level cache + its initializing side-effect (which would
14
+ * pull the full canonical-models / provider-presets closure into the import
15
+ * graph) and the cache-fed lookups (`getAvailableThinkLevels` / `validateThinkLevel`),
16
+ * none of which the `@omnicross/*` packages call.
17
+ */
18
+
19
+ /**
20
+ * Thinking effort → budget ratio (budget = (max - min) * ratio + min). Used only
21
+ * by token-budget APIs (Claude budget_tokens, Gemini thinking_budget). OpenAI /
22
+ * DeepSeek discrete reasoning_effort providers pass the level through directly.
23
+ */
24
+ declare const EFFORT_RATIO: Record<ThinkLevel, number>;
25
+ /** Global default max_tokens — used only when an API requires max_tokens set. */
26
+ declare const DEFAULT_MAX_TOKENS = 4096;
27
+ declare const THINKING_TOKEN_MAP: Record<string, {
28
+ min: number;
29
+ max: number;
30
+ }>;
31
+ /** Reasoning-model recognition patterns. */
32
+ declare const REASONING_MODEL_PATTERNS: RegExp[];
33
+ /** Patterns for models that cannot fully disable thinking. */
34
+ declare const CANNOT_DISABLE_THINKING_PATTERNS: RegExp[];
35
+ /** Whether the model supports thinking/reasoning. */
36
+ declare function isReasoningModel(modelId: string): boolean;
37
+ /** Whether the model can disable thinking. */
38
+ declare function canDisableThinking(modelId: string): boolean;
39
+ /**
40
+ * Resolve the model's thinking-token limit. Prefers a declared
41
+ * `ModelConfig.thinkingTokenLimit`, else falls back to a regex match.
42
+ */
43
+ declare function findTokenLimit(modelOrId: string | ModelConfig): {
44
+ min: number;
45
+ max: number;
46
+ } | null;
47
+ /**
48
+ * Calculate the thinking budget for a model + effort level.
49
+ * Returns undefined when no budget can be computed.
50
+ */
51
+ declare function calculateThinkingBudget(modelId: string, level: ThinkLevel, userMaxTokens?: number): number | undefined;
52
+ /** Claude max_tokens after subtracting the thinking budget. */
53
+ declare function getClaudeMaxTokens(userMaxTokens: number | undefined, thinkingBudget: number | undefined): number | undefined;
54
+ /** OpenAI reasoning_effort mapping (pass-through; `max` maps to `high`). */
55
+ declare function getOpenAIReasoningEffort(level: ThinkLevel): string | undefined;
56
+ /** Gemini thinkingConfig builder. */
57
+ declare function buildGeminiThinkingConfig(modelId: string, level: ThinkLevel, userMaxTokens?: number): {
58
+ thinking_budget: number;
59
+ } | undefined;
60
+ /** Anthropic thinking config builder. */
61
+ declare function buildAnthropicThinking(modelId: string, level: ThinkLevel, userMaxTokens?: number): {
62
+ type: 'enabled';
63
+ budget_tokens: number;
64
+ } | undefined;
65
+ /** Qwen/DeepSeek enable_thinking config builder. */
66
+ declare function buildQwenThinkingConfig(level: ThinkLevel, userMaxTokens?: number): {
67
+ enable_thinking: boolean;
68
+ thinking_budget?: number;
69
+ };
70
+
71
+ export { CANNOT_DISABLE_THINKING_PATTERNS, DEFAULT_MAX_TOKENS, EFFORT_RATIO, REASONING_MODEL_PATTERNS, THINKING_TOKEN_MAP, buildAnthropicThinking, buildGeminiThinkingConfig, buildQwenThinkingConfig, calculateThinkingBudget, canDisableThinking, findTokenLimit, getClaudeMaxTokens, getOpenAIReasoningEffort, isReasoningModel };
@@ -0,0 +1,71 @@
1
+ import { T as ThinkLevel } from './thinking-CBWSLel8.js';
2
+ import { M as ModelConfig } from './llm-config-D1jKQLVp.js';
3
+
4
+ /**
5
+ * thinking-config — dependency-light thinking-budget / reasoning-effort helpers.
6
+ *
7
+ * The PURE budget/effort functions the `@omnicross/*` packages consume
8
+ * (`getOpenAIReasoningEffort`, `buildAnthropicThinking`, `calculateThinkingBudget`,
9
+ * `getClaudeMaxTokens`, `isReasoningModel`, `DEFAULT_MAX_TOKENS`) plus the in-file
10
+ * regex/numeric data they rely on.
11
+ *
12
+ * This module is intentionally import-closed (0 runtime deps): it OMITS any
13
+ * global model-thinking-level cache + its initializing side-effect (which would
14
+ * pull the full canonical-models / provider-presets closure into the import
15
+ * graph) and the cache-fed lookups (`getAvailableThinkLevels` / `validateThinkLevel`),
16
+ * none of which the `@omnicross/*` packages call.
17
+ */
18
+
19
+ /**
20
+ * Thinking effort → budget ratio (budget = (max - min) * ratio + min). Used only
21
+ * by token-budget APIs (Claude budget_tokens, Gemini thinking_budget). OpenAI /
22
+ * DeepSeek discrete reasoning_effort providers pass the level through directly.
23
+ */
24
+ declare const EFFORT_RATIO: Record<ThinkLevel, number>;
25
+ /** Global default max_tokens — used only when an API requires max_tokens set. */
26
+ declare const DEFAULT_MAX_TOKENS = 4096;
27
+ declare const THINKING_TOKEN_MAP: Record<string, {
28
+ min: number;
29
+ max: number;
30
+ }>;
31
+ /** Reasoning-model recognition patterns. */
32
+ declare const REASONING_MODEL_PATTERNS: RegExp[];
33
+ /** Patterns for models that cannot fully disable thinking. */
34
+ declare const CANNOT_DISABLE_THINKING_PATTERNS: RegExp[];
35
+ /** Whether the model supports thinking/reasoning. */
36
+ declare function isReasoningModel(modelId: string): boolean;
37
+ /** Whether the model can disable thinking. */
38
+ declare function canDisableThinking(modelId: string): boolean;
39
+ /**
40
+ * Resolve the model's thinking-token limit. Prefers a declared
41
+ * `ModelConfig.thinkingTokenLimit`, else falls back to a regex match.
42
+ */
43
+ declare function findTokenLimit(modelOrId: string | ModelConfig): {
44
+ min: number;
45
+ max: number;
46
+ } | null;
47
+ /**
48
+ * Calculate the thinking budget for a model + effort level.
49
+ * Returns undefined when no budget can be computed.
50
+ */
51
+ declare function calculateThinkingBudget(modelId: string, level: ThinkLevel, userMaxTokens?: number): number | undefined;
52
+ /** Claude max_tokens after subtracting the thinking budget. */
53
+ declare function getClaudeMaxTokens(userMaxTokens: number | undefined, thinkingBudget: number | undefined): number | undefined;
54
+ /** OpenAI reasoning_effort mapping (pass-through; `max` maps to `high`). */
55
+ declare function getOpenAIReasoningEffort(level: ThinkLevel): string | undefined;
56
+ /** Gemini thinkingConfig builder. */
57
+ declare function buildGeminiThinkingConfig(modelId: string, level: ThinkLevel, userMaxTokens?: number): {
58
+ thinking_budget: number;
59
+ } | undefined;
60
+ /** Anthropic thinking config builder. */
61
+ declare function buildAnthropicThinking(modelId: string, level: ThinkLevel, userMaxTokens?: number): {
62
+ type: 'enabled';
63
+ budget_tokens: number;
64
+ } | undefined;
65
+ /** Qwen/DeepSeek enable_thinking config builder. */
66
+ declare function buildQwenThinkingConfig(level: ThinkLevel, userMaxTokens?: number): {
67
+ enable_thinking: boolean;
68
+ thinking_budget?: number;
69
+ };
70
+
71
+ export { CANNOT_DISABLE_THINKING_PATTERNS, DEFAULT_MAX_TOKENS, EFFORT_RATIO, REASONING_MODEL_PATTERNS, THINKING_TOKEN_MAP, buildAnthropicThinking, buildGeminiThinkingConfig, buildQwenThinkingConfig, calculateThinkingBudget, canDisableThinking, findTokenLimit, getClaudeMaxTokens, getOpenAIReasoningEffort, isReasoningModel };
@@ -0,0 +1,205 @@
1
+ // src/thinking-config.ts
2
+ var EFFORT_RATIO = {
3
+ none: 0.01,
4
+ minimal: 0.02,
5
+ low: 0.05,
6
+ medium: 0.5,
7
+ high: 0.8,
8
+ xhigh: 0.92,
9
+ max: 0.95
10
+ };
11
+ var DEFAULT_MAX_TOKENS = 4096;
12
+ var THINKING_TOKEN_MAP = {
13
+ // Gemini
14
+ "gemini-2\\.5-flash-lite": { min: 512, max: 24576 },
15
+ "gemini-.*-flash": { min: 0, max: 24576 },
16
+ "gemini-.*-pro": { min: 128, max: 32768 },
17
+ // Qwen
18
+ "qwen3-235b-a22b-thinking": { min: 0, max: 81920 },
19
+ "qwen3-30b-a3b-thinking": { min: 0, max: 81920 },
20
+ "qwen3-vl-235b-a22b-thinking": { min: 0, max: 81920 },
21
+ "qwen3-vl-30b-a3b-thinking": { min: 0, max: 81920 },
22
+ "qwen-plus-2025": { min: 0, max: 38912 },
23
+ "qwen-plus": { min: 0, max: 81920 },
24
+ "qwen-turbo": { min: 0, max: 38912 },
25
+ "qwen-flash": { min: 0, max: 81920 },
26
+ "qwen3-": { min: 1024, max: 38912 },
27
+ qwq: { min: 1024, max: 38912 },
28
+ // Claude (incl. AWS Bedrock, GCP Vertex AI)
29
+ "claude-opus-4[.-]7": { min: 1024, max: 128e3 },
30
+ "claude-(sonnet|opus)-4[.-]6": { min: 1024, max: 128e3 },
31
+ "claude-3[.-]7.*sonnet": { min: 1024, max: 64e3 },
32
+ "claude-(haiku|sonnet|opus)-4[.-]5": { min: 1024, max: 64e3 },
33
+ "claude-opus-4[.-]1": { min: 1024, max: 32e3 },
34
+ "claude-sonnet-4": { min: 1024, max: 64e3 },
35
+ "claude-opus-4": { min: 1024, max: 32e3 },
36
+ "claude-3[.-]5-sonnet": { min: 1024, max: 64e3 },
37
+ // OpenAI o-series
38
+ "o1-preview": { min: 0, max: 32768 },
39
+ "o1-mini": { min: 0, max: 32768 },
40
+ "o1-pro": { min: 0, max: 32768 },
41
+ "o3-mini": { min: 0, max: 32768 },
42
+ o3: { min: 0, max: 65536 },
43
+ "o4-mini": { min: 0, max: 32768 },
44
+ // GPT-5 series (Response API reasoning models)
45
+ "gpt-5\\.5": { min: 0, max: 128e3 },
46
+ "gpt-5\\.4": { min: 0, max: 128e3 },
47
+ "gpt-5\\.3": { min: 0, max: 128e3 },
48
+ "gpt-5\\.2": { min: 0, max: 65536 },
49
+ "gpt-5\\.1": { min: 0, max: 65536 },
50
+ "gpt-5": { min: 0, max: 65536 },
51
+ // DeepSeek
52
+ "deepseek-v4-pro": { min: 0, max: 32768 },
53
+ "deepseek-v4-flash": { min: 0, max: 32768 },
54
+ "deepseek-r1": { min: 0, max: 32768 },
55
+ "deepseek-reasoner": { min: 0, max: 32768 },
56
+ // Baichuan
57
+ "baichuan-m2": { min: 0, max: 3e4 },
58
+ "baichuan-m3": { min: 0, max: 3e4 },
59
+ // Grok
60
+ "grok-3": { min: 0, max: 32768 },
61
+ // Zhipu GLM
62
+ "glm.*zero": { min: 0, max: 16384 },
63
+ // Hunyuan
64
+ "hunyuan.*t1": { min: 0, max: 16384 },
65
+ // Doubao
66
+ "doubao.*think": { min: 0, max: 16384 }
67
+ };
68
+ var REASONING_MODEL_PATTERNS = [
69
+ /^o[134](-mini|-preview|-pro)?$/i,
70
+ /^gpt-5(\.\d)?(-pro|-codex|-codex-max)?/i,
71
+ /claude.*3[.-]?5.*sonnet|claude.*sonnet.*3[.-]?5|claude-sonnet-4|claude-opus-4|claude-(haiku|sonnet|opus)-4[.-]?5/i,
72
+ /gemini.*(2\.0|2-|2\.5|3).*flash|gemini.*(2\.5|3).*pro|gemini.*think/i,
73
+ /grok-3/i,
74
+ /qwq|qwen.*qwq|qwen.*thinking/i,
75
+ /deepseek-v4|deepseek.*r1|r1.*deepseek|deepseek-reasoner/i,
76
+ /glm.*zero/i,
77
+ /hunyuan.*t1/i,
78
+ /doubao.*think/i,
79
+ /baichuan-m[23]/i
80
+ ];
81
+ var CANNOT_DISABLE_THINKING_PATTERNS = [
82
+ /gemini.*3.*pro/i,
83
+ /gemini.*2\.5.*pro/i,
84
+ /^o1-pro$/i
85
+ ];
86
+ function isReasoningModel(modelId) {
87
+ if (!modelId) return false;
88
+ return REASONING_MODEL_PATTERNS.some((pattern) => pattern.test(modelId));
89
+ }
90
+ function canDisableThinking(modelId) {
91
+ if (!modelId) return true;
92
+ return !CANNOT_DISABLE_THINKING_PATTERNS.some((pattern) => pattern.test(modelId));
93
+ }
94
+ function findTokenLimit(modelOrId) {
95
+ if (!modelOrId) return null;
96
+ if (typeof modelOrId === "object") {
97
+ if (modelOrId.thinkingTokenLimit) return modelOrId.thinkingTokenLimit;
98
+ return findTokenLimit(modelOrId.id);
99
+ }
100
+ const lowerModelId = modelOrId.toLowerCase();
101
+ for (const [pattern, limit] of Object.entries(THINKING_TOKEN_MAP)) {
102
+ const regex = new RegExp(pattern, "i");
103
+ if (regex.test(lowerModelId)) {
104
+ return limit;
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+ function calculateThinkingBudget(modelId, level, userMaxTokens) {
110
+ if (level === "none") {
111
+ const tokenLimit2 = findTokenLimit(modelId);
112
+ if (tokenLimit2 && tokenLimit2.min > 0) {
113
+ return tokenLimit2.min;
114
+ }
115
+ return void 0;
116
+ }
117
+ const tokenLimit = findTokenLimit(modelId);
118
+ const ratio = EFFORT_RATIO[level];
119
+ if (!tokenLimit) {
120
+ if (userMaxTokens) {
121
+ const maxBudget = Math.floor(userMaxTokens * 0.75);
122
+ return Math.floor(Math.min(userMaxTokens * ratio, maxBudget));
123
+ }
124
+ return void 0;
125
+ }
126
+ const formulaResult = Math.floor((tokenLimit.max - tokenLimit.min) * ratio + tokenLimit.min);
127
+ if (userMaxTokens !== void 0) {
128
+ const maxBudgetFromUserTokens = Math.floor(userMaxTokens * Math.min(ratio, 0.75));
129
+ return Math.max(tokenLimit.min, Math.min(formulaResult, maxBudgetFromUserTokens));
130
+ }
131
+ return formulaResult;
132
+ }
133
+ function getClaudeMaxTokens(userMaxTokens, thinkingBudget) {
134
+ if (!userMaxTokens) return void 0;
135
+ if (!thinkingBudget) return userMaxTokens;
136
+ const outputTokens = userMaxTokens - thinkingBudget;
137
+ return outputTokens > 0 ? outputTokens : void 0;
138
+ }
139
+ function getOpenAIReasoningEffort(level) {
140
+ switch (level) {
141
+ case "none":
142
+ return "none";
143
+ case "minimal":
144
+ return "minimal";
145
+ case "low":
146
+ return "low";
147
+ case "medium":
148
+ return "medium";
149
+ case "high":
150
+ return "high";
151
+ case "xhigh":
152
+ return "xhigh";
153
+ case "max":
154
+ return "high";
155
+ default:
156
+ return void 0;
157
+ }
158
+ }
159
+ function buildGeminiThinkingConfig(modelId, level, userMaxTokens) {
160
+ if (!isReasoningModel(modelId)) {
161
+ return void 0;
162
+ }
163
+ const budget = calculateThinkingBudget(modelId, level, userMaxTokens);
164
+ if (budget === void 0) {
165
+ return void 0;
166
+ }
167
+ return { thinking_budget: budget };
168
+ }
169
+ function buildAnthropicThinking(modelId, level, userMaxTokens) {
170
+ if (level === "none") {
171
+ return void 0;
172
+ }
173
+ const budget = calculateThinkingBudget(modelId, level, userMaxTokens);
174
+ if (!budget || budget < 1024) {
175
+ return { type: "enabled", budget_tokens: 1024 };
176
+ }
177
+ return { type: "enabled", budget_tokens: budget };
178
+ }
179
+ function buildQwenThinkingConfig(level, userMaxTokens) {
180
+ if (level === "none") {
181
+ return { enable_thinking: false };
182
+ }
183
+ const ratio = EFFORT_RATIO[level];
184
+ const budget = userMaxTokens ? Math.floor(userMaxTokens * ratio) : void 0;
185
+ return {
186
+ enable_thinking: true,
187
+ thinking_budget: budget
188
+ };
189
+ }
190
+ export {
191
+ CANNOT_DISABLE_THINKING_PATTERNS,
192
+ DEFAULT_MAX_TOKENS,
193
+ EFFORT_RATIO,
194
+ REASONING_MODEL_PATTERNS,
195
+ THINKING_TOKEN_MAP,
196
+ buildAnthropicThinking,
197
+ buildGeminiThinkingConfig,
198
+ buildQwenThinkingConfig,
199
+ calculateThinkingBudget,
200
+ canDisableThinking,
201
+ findTokenLimit,
202
+ getClaudeMaxTokens,
203
+ getOpenAIReasoningEffort,
204
+ isReasoningModel
205
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/usage-types.ts
17
+ var usage_types_exports = {};
18
+ module.exports = __toCommonJS(usage_types_exports);
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Usage statistics types — LLM request token/cost accounting contracts.
3
+ *
4
+ * Provider-neutral; no host/storage coupling. The serving core attributes each
5
+ * captured request with an engine origin + token counts; hosts own their own
6
+ * persistence rows and aggregation views on top of these shapes.
7
+ *
8
+ * @module usage-types
9
+ */
10
+ /**
11
+ * Which engine path produced the request. Used for filtering and to
12
+ * disambiguate duplicate captures from cooperating layers.
13
+ */
14
+ type UsageEngineOrigin =
15
+ /** CompletionService transformer / direct API path. */
16
+ 'completion'
17
+ /** Claude Agent SDK engine when the host's agent proxy ran the request through the transformer chain. */
18
+ | 'claude-sdk'
19
+ /** Claude Agent SDK engine + official Anthropic provider — proxy bypassed the transformer chain. */
20
+ | 'claude-sdk-direct'
21
+ /** Codex CLI run as a model client through the Responses-API ingress. */
22
+ | 'codex-ingress'
23
+ /** Additional engine origins defined by the embedding host's own engines. */
24
+ | (string & {});
25
+ /**
26
+ * Token counts captured from a single LLM response. Names match the union of
27
+ * Anthropic and OpenAI/Gemini terminology — fields default to 0 when the
28
+ * provider does not report them.
29
+ */
30
+ interface UsageTokens {
31
+ inputTokens: number;
32
+ outputTokens: number;
33
+ /** Anthropic prompt-cache hit (charged at the cache_read rate). */
34
+ cacheReadTokens: number;
35
+ /** Anthropic prompt-cache write (charged at the cache_write rate). */
36
+ cacheCreationTokens: number;
37
+ /** OpenAI o1 / Anthropic extended-thinking — already counted into outputTokens by some providers. */
38
+ reasoningTokens: number;
39
+ }
40
+
41
+ export type { UsageEngineOrigin, UsageTokens };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Usage statistics types — LLM request token/cost accounting contracts.
3
+ *
4
+ * Provider-neutral; no host/storage coupling. The serving core attributes each
5
+ * captured request with an engine origin + token counts; hosts own their own
6
+ * persistence rows and aggregation views on top of these shapes.
7
+ *
8
+ * @module usage-types
9
+ */
10
+ /**
11
+ * Which engine path produced the request. Used for filtering and to
12
+ * disambiguate duplicate captures from cooperating layers.
13
+ */
14
+ type UsageEngineOrigin =
15
+ /** CompletionService transformer / direct API path. */
16
+ 'completion'
17
+ /** Claude Agent SDK engine when the host's agent proxy ran the request through the transformer chain. */
18
+ | 'claude-sdk'
19
+ /** Claude Agent SDK engine + official Anthropic provider — proxy bypassed the transformer chain. */
20
+ | 'claude-sdk-direct'
21
+ /** Codex CLI run as a model client through the Responses-API ingress. */
22
+ | 'codex-ingress'
23
+ /** Additional engine origins defined by the embedding host's own engines. */
24
+ | (string & {});
25
+ /**
26
+ * Token counts captured from a single LLM response. Names match the union of
27
+ * Anthropic and OpenAI/Gemini terminology — fields default to 0 when the
28
+ * provider does not report them.
29
+ */
30
+ interface UsageTokens {
31
+ inputTokens: number;
32
+ outputTokens: number;
33
+ /** Anthropic prompt-cache hit (charged at the cache_read rate). */
34
+ cacheReadTokens: number;
35
+ /** Anthropic prompt-cache write (charged at the cache_write rate). */
36
+ cacheCreationTokens: number;
37
+ /** OpenAI o1 / Anthropic extended-thinking — already counted into outputTokens by some providers. */
38
+ reasoningTokens: number;
39
+ }
40
+
41
+ export type { UsageEngineOrigin, UsageTokens };
File without changes
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/websearch-types.ts
21
+ var websearch_types_exports = {};
22
+ __export(websearch_types_exports, {
23
+ isApiProvider: () => isApiProvider,
24
+ isLocalProvider: () => isLocalProvider
25
+ });
26
+ module.exports = __toCommonJS(websearch_types_exports);
27
+ function isApiProvider(id) {
28
+ return !id.startsWith("local-");
29
+ }
30
+ function isLocalProvider(id) {
31
+ return id.startsWith("local-");
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ isApiProvider,
36
+ isLocalProvider
37
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Web Search Types
3
+ *
4
+ * Provider-neutral web-search contract type definitions.
5
+ */
6
+ /** Supported search provider IDs */
7
+ type WebSearchProviderId = 'jina' | 'zhipu' | 'z.ai' | 'tavily' | 'exa' | 'searxng' | 'bocha' | 'claude' | 'grok' | 'local-google' | 'local-bing' | 'local-baidu' | 'local-duckduckgo';
8
+ /** Provider type classification */
9
+ type WebSearchProviderType = 'api' | 'local';
10
+ /** Search provider configuration */
11
+ interface WebSearchProviderConfig {
12
+ /** Unique provider identifier */
13
+ id: WebSearchProviderId;
14
+ /** Whether the provider is enabled */
15
+ enabled: boolean;
16
+ /** API key(s), comma-separated for rotation */
17
+ apiKey?: string;
18
+ /** Custom API host URL */
19
+ apiHost?: string;
20
+ /** HTTP basic auth username (for Searxng) */
21
+ basicAuthUsername?: string;
22
+ /** HTTP basic auth password (for Searxng) */
23
+ basicAuthPassword?: string;
24
+ }
25
+ /** Individual search result item */
26
+ interface WebSearchResult {
27
+ /** Result title */
28
+ title: string;
29
+ /** Result content/snippet */
30
+ content: string;
31
+ /** Source URL */
32
+ url: string;
33
+ }
34
+ /** Search response from a provider */
35
+ interface WebSearchResponse {
36
+ /** Whether the search was successful */
37
+ success: boolean;
38
+ /** The search query used */
39
+ query: string;
40
+ /** Array of search results */
41
+ results: WebSearchResult[];
42
+ /** Provider that performed the search */
43
+ provider?: WebSearchProviderId;
44
+ /** Error message if failed */
45
+ error?: string;
46
+ }
47
+ /** Search options for a single search request */
48
+ interface WebSearchOptions {
49
+ /** Maximum number of results */
50
+ maxResults?: number;
51
+ /** Request timeout in milliseconds */
52
+ timeout?: number;
53
+ /** Abort signal for cancellation */
54
+ signal?: AbortSignal;
55
+ /** Fetch full page content (Jina: uses X-Engine: direct) */
56
+ fetchPageContent?: boolean;
57
+ }
58
+ /** Jina Reader response for fetching URL content */
59
+ interface JinaReaderResponse {
60
+ /** Whether the request was successful */
61
+ success: boolean;
62
+ /** The URL that was read */
63
+ url: string;
64
+ /** Page title */
65
+ title?: string;
66
+ /** Page content in markdown format */
67
+ content?: string;
68
+ /** Error message if failed */
69
+ error?: string;
70
+ }
71
+ /** Check if provider is API type */
72
+ declare function isApiProvider(id: WebSearchProviderId): boolean;
73
+ /** Check if provider is local type */
74
+ declare function isLocalProvider(id: WebSearchProviderId): boolean;
75
+
76
+ export { type JinaReaderResponse, type WebSearchOptions, type WebSearchProviderConfig, type WebSearchProviderId, type WebSearchProviderType, type WebSearchResponse, type WebSearchResult, isApiProvider, isLocalProvider };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Web Search Types
3
+ *
4
+ * Provider-neutral web-search contract type definitions.
5
+ */
6
+ /** Supported search provider IDs */
7
+ type WebSearchProviderId = 'jina' | 'zhipu' | 'z.ai' | 'tavily' | 'exa' | 'searxng' | 'bocha' | 'claude' | 'grok' | 'local-google' | 'local-bing' | 'local-baidu' | 'local-duckduckgo';
8
+ /** Provider type classification */
9
+ type WebSearchProviderType = 'api' | 'local';
10
+ /** Search provider configuration */
11
+ interface WebSearchProviderConfig {
12
+ /** Unique provider identifier */
13
+ id: WebSearchProviderId;
14
+ /** Whether the provider is enabled */
15
+ enabled: boolean;
16
+ /** API key(s), comma-separated for rotation */
17
+ apiKey?: string;
18
+ /** Custom API host URL */
19
+ apiHost?: string;
20
+ /** HTTP basic auth username (for Searxng) */
21
+ basicAuthUsername?: string;
22
+ /** HTTP basic auth password (for Searxng) */
23
+ basicAuthPassword?: string;
24
+ }
25
+ /** Individual search result item */
26
+ interface WebSearchResult {
27
+ /** Result title */
28
+ title: string;
29
+ /** Result content/snippet */
30
+ content: string;
31
+ /** Source URL */
32
+ url: string;
33
+ }
34
+ /** Search response from a provider */
35
+ interface WebSearchResponse {
36
+ /** Whether the search was successful */
37
+ success: boolean;
38
+ /** The search query used */
39
+ query: string;
40
+ /** Array of search results */
41
+ results: WebSearchResult[];
42
+ /** Provider that performed the search */
43
+ provider?: WebSearchProviderId;
44
+ /** Error message if failed */
45
+ error?: string;
46
+ }
47
+ /** Search options for a single search request */
48
+ interface WebSearchOptions {
49
+ /** Maximum number of results */
50
+ maxResults?: number;
51
+ /** Request timeout in milliseconds */
52
+ timeout?: number;
53
+ /** Abort signal for cancellation */
54
+ signal?: AbortSignal;
55
+ /** Fetch full page content (Jina: uses X-Engine: direct) */
56
+ fetchPageContent?: boolean;
57
+ }
58
+ /** Jina Reader response for fetching URL content */
59
+ interface JinaReaderResponse {
60
+ /** Whether the request was successful */
61
+ success: boolean;
62
+ /** The URL that was read */
63
+ url: string;
64
+ /** Page title */
65
+ title?: string;
66
+ /** Page content in markdown format */
67
+ content?: string;
68
+ /** Error message if failed */
69
+ error?: string;
70
+ }
71
+ /** Check if provider is API type */
72
+ declare function isApiProvider(id: WebSearchProviderId): boolean;
73
+ /** Check if provider is local type */
74
+ declare function isLocalProvider(id: WebSearchProviderId): boolean;
75
+
76
+ export { type JinaReaderResponse, type WebSearchOptions, type WebSearchProviderConfig, type WebSearchProviderId, type WebSearchProviderType, type WebSearchResponse, type WebSearchResult, isApiProvider, isLocalProvider };
@@ -0,0 +1,11 @@
1
+ // src/websearch-types.ts
2
+ function isApiProvider(id) {
3
+ return !id.startsWith("local-");
4
+ }
5
+ function isLocalProvider(id) {
6
+ return id.startsWith("local-");
7
+ }
8
+ export {
9
+ isApiProvider,
10
+ isLocalProvider
11
+ };