@jsonstudio/llms 0.6.795 → 0.6.938

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 (184) hide show
  1. package/dist/bridge/routecodex-adapter.d.ts +74 -0
  2. package/dist/config-unified/enhanced-path-resolver.d.ts +5 -0
  3. package/dist/config-unified/unified-config.d.ts +26 -0
  4. package/dist/conversion/codec-registry.d.ts +10 -0
  5. package/dist/conversion/codecs/gemini-openai-codec.d.ts +16 -0
  6. package/dist/conversion/codecs/openai-openai-codec.d.ts +12 -0
  7. package/dist/conversion/codecs/responses-openai-codec.d.ts +12 -0
  8. package/dist/conversion/compat/profiles/chat-gemini.json +12 -0
  9. package/dist/conversion/config/config-manager.d.ts +212 -0
  10. package/dist/conversion/hub/config/types.d.ts +26 -0
  11. package/dist/conversion/hub/core/detour-registry.d.ts +9 -0
  12. package/dist/conversion/hub/core/hub-context.d.ts +21 -0
  13. package/dist/conversion/hub/core/index.d.ts +3 -0
  14. package/dist/conversion/hub/core/stage-driver.d.ts +30 -0
  15. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.d.ts +16 -0
  16. package/dist/conversion/hub/format-adapters/chat-format-adapter.d.ts +17 -0
  17. package/dist/conversion/hub/format-adapters/gemini-format-adapter.d.ts +16 -0
  18. package/dist/conversion/hub/format-adapters/index.d.ts +21 -0
  19. package/dist/conversion/hub/hub-feature.d.ts +1 -0
  20. package/dist/conversion/hub/node-support.d.ts +19 -0
  21. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +11 -0
  22. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +3 -0
  23. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +7 -0
  24. package/dist/conversion/hub/pipeline/hub-pipeline.js +71 -14
  25. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +4 -0
  26. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +23 -1
  27. package/dist/conversion/hub/pipelines/inbound.d.ts +22 -0
  28. package/dist/conversion/hub/pipelines/outbound.d.ts +22 -0
  29. package/dist/conversion/hub/policy/policy-engine.d.ts +46 -0
  30. package/dist/conversion/hub/policy/policy-engine.js +176 -0
  31. package/dist/conversion/hub/policy/protocol-spec.d.ts +50 -0
  32. package/dist/conversion/hub/policy/protocol-spec.js +105 -0
  33. package/dist/conversion/hub/process/chat-process.d.ts +32 -0
  34. package/dist/conversion/hub/registry.d.ts +28 -0
  35. package/dist/conversion/hub/response/chat-response-utils.d.ts +6 -0
  36. package/dist/conversion/hub/response/provider-response.js +31 -0
  37. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +7 -0
  38. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +87 -1
  39. package/dist/conversion/hub/semantic-mappers/index.d.ts +4 -0
  40. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +21 -0
  41. package/dist/conversion/hub/standardized-bridge.d.ts +12 -0
  42. package/dist/conversion/hub/types/chat-schema.d.ts +112 -0
  43. package/dist/conversion/hub/types/errors.d.ts +5 -0
  44. package/dist/conversion/hub/types/format-envelope.d.ts +7 -0
  45. package/dist/conversion/hub/types/index.d.ts +6 -0
  46. package/dist/conversion/hub/types/json.d.ts +9 -0
  47. package/dist/conversion/hub/types/node.d.ts +31 -0
  48. package/dist/conversion/responses/responses-openai-bridge.js +263 -10
  49. package/dist/conversion/schema-validator.d.ts +7 -0
  50. package/dist/conversion/shared/args-mapping.d.ts +18 -0
  51. package/dist/conversion/shared/chat-request-filters.d.ts +9 -0
  52. package/dist/conversion/shared/errors.d.ts +1 -1
  53. package/dist/conversion/shared/gemini-tool-utils.js +61 -0
  54. package/dist/conversion/shared/jsonish.d.ts +3 -0
  55. package/dist/conversion/shared/mcp-injection.d.ts +2 -0
  56. package/dist/conversion/shared/media.d.ts +1 -0
  57. package/dist/conversion/shared/openai-message-normalize.d.ts +1 -0
  58. package/dist/conversion/shared/payload-budget.d.ts +13 -0
  59. package/dist/conversion/shared/reasoning-mapping.d.ts +5 -0
  60. package/dist/conversion/shared/responses-request-adapter.d.ts +1 -28
  61. package/dist/conversion/shared/responses-request-adapter.js +1 -430
  62. package/dist/conversion/shared/snapshot-hooks.js +112 -4
  63. package/dist/conversion/shared/tool-governor.js +8 -2
  64. package/dist/conversion/shared/tool-harvester.d.ts +31 -0
  65. package/dist/conversion/shared/tool-mapping.js +10 -29
  66. package/dist/conversion/types.d.ts +33 -0
  67. package/dist/filters/builtin/add-fields-filter.d.ts +8 -0
  68. package/dist/filters/builtin/blacklist-filter.d.ts +8 -0
  69. package/dist/filters/builtin/whitelist-filter.d.ts +8 -0
  70. package/dist/filters/engine.d.ts +16 -0
  71. package/dist/filters/special/request-tool-choice-policy.d.ts +11 -0
  72. package/dist/filters/special/response-finish-invariants.d.ts +11 -0
  73. package/dist/filters/special/response-openai-to-responses-bridge.d.ts +13 -0
  74. package/dist/filters/special/response-tool-arguments-blacklist.d.ts +12 -0
  75. package/dist/filters/special/response-tool-arguments-schema-converge.d.ts +13 -0
  76. package/dist/filters/special/response-tool-arguments-stringify.d.ts +9 -0
  77. package/dist/filters/special/response-tool-arguments-whitelist.d.ts +11 -0
  78. package/dist/filters/special/tool-filter-hooks.d.ts +19 -0
  79. package/dist/filters/special/tool-post-constraints.d.ts +31 -0
  80. package/dist/filters/types.d.ts +68 -0
  81. package/dist/filters/utils/fieldmap-loader.d.ts +2 -0
  82. package/dist/filters/utils/snapshot-writer.d.ts +10 -0
  83. package/dist/guidance/index.d.ts +3 -0
  84. package/dist/guidance/index.js +78 -83
  85. package/dist/http/sse-response.d.ts +22 -0
  86. package/dist/router/virtual-router/bootstrap.d.ts +6 -0
  87. package/dist/router/virtual-router/bootstrap.js +49 -5
  88. package/dist/router/virtual-router/classifier.d.ts +10 -0
  89. package/dist/router/virtual-router/engine-selection.js +147 -15
  90. package/dist/router/virtual-router/engine.js +177 -31
  91. package/dist/router/virtual-router/error-center.d.ts +10 -0
  92. package/dist/router/virtual-router/features.d.ts +3 -0
  93. package/dist/router/virtual-router/routing-instructions.d.ts +23 -1
  94. package/dist/router/virtual-router/routing-instructions.js +120 -30
  95. package/dist/router/virtual-router/types.d.ts +11 -0
  96. package/dist/servertool/engine.js +189 -16
  97. package/dist/servertool/handlers/apply-patch-guard.js +269 -0
  98. package/dist/servertool/handlers/exec-command-guard.js +558 -0
  99. package/dist/servertool/handlers/followup-message-trimmer.d.ts +16 -0
  100. package/dist/servertool/handlers/followup-message-trimmer.js +198 -0
  101. package/dist/servertool/handlers/followup-request-builder.d.ts +17 -0
  102. package/dist/servertool/handlers/followup-request-builder.js +122 -0
  103. package/dist/servertool/handlers/gemini-empty-reply-continue.js +252 -51
  104. package/dist/servertool/handlers/iflow-model-error-retry.js +12 -22
  105. package/dist/servertool/handlers/stop-message-auto.js +237 -75
  106. package/dist/servertool/handlers/vision.js +15 -27
  107. package/dist/servertool/handlers/web-search.js +17 -43
  108. package/dist/servertool/server-side-tools.d.ts +3 -0
  109. package/dist/servertool/server-side-tools.js +3 -0
  110. package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +2 -1
  111. package/dist/sse/json-to-sse/chat-json-to-sse-converter.d.ts +80 -0
  112. package/dist/sse/json-to-sse/event-generators/chat.d.ts +55 -0
  113. package/dist/sse/json-to-sse/event-generators/responses.d.ts +99 -0
  114. package/dist/sse/json-to-sse/gemini-json-to-sse-converter.d.ts +2 -1
  115. package/dist/sse/json-to-sse/responses-json-to-sse-converter.d.ts +80 -0
  116. package/dist/sse/json-to-sse/sequencers/anthropic-sequencer.d.ts +1 -1
  117. package/dist/sse/json-to-sse/sequencers/chat-sequencer.d.ts +2 -2
  118. package/dist/sse/json-to-sse/sequencers/gemini-sequencer.d.ts +1 -1
  119. package/dist/sse/json-to-sse/sequencers/responses-sequencer.d.ts +40 -0
  120. package/dist/sse/shared/chat-serializer.d.ts +4 -0
  121. package/dist/sse/shared/constants.d.ts +272 -0
  122. package/dist/sse/shared/serializers/anthropic-event-serializer.d.ts +1 -1
  123. package/dist/sse/shared/serializers/base-serializer.d.ts +158 -0
  124. package/dist/sse/shared/serializers/chat-event-serializer.d.ts +82 -0
  125. package/dist/sse/shared/serializers/gemini-event-serializer.d.ts +1 -1
  126. package/dist/sse/shared/serializers/index.d.ts +2 -1
  127. package/dist/sse/shared/serializers/responses-event-serializer.d.ts +123 -0
  128. package/dist/sse/shared/serializers/types.d.ts +51 -0
  129. package/dist/sse/shared/utils.d.ts +254 -0
  130. package/dist/sse/shared/writer.d.ts +2 -2
  131. package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +1 -1
  132. package/dist/sse/sse-to-json/builders/anthropic-response-builder.d.ts +1 -1
  133. package/dist/sse/sse-to-json/builders/response-builder.d.ts +1 -1
  134. package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +2 -1
  135. package/dist/sse/sse-to-json/gemini-sse-to-json-converter.d.ts +2 -1
  136. package/dist/sse/sse-to-json/parsers/sse-parser.d.ts +73 -0
  137. package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +1 -1
  138. package/dist/sse/types/chat-types.d.ts +1 -1
  139. package/dist/sse/types/responses-types.d.ts +1 -1
  140. package/dist/tools/apply-patch/execution-capturer.d.ts +13 -0
  141. package/dist/tools/apply-patch/execution-capturer.js +158 -0
  142. package/dist/tools/apply-patch/regression-capturer.d.ts +1 -0
  143. package/dist/tools/apply-patch/regression-capturer.js +5 -4
  144. package/dist/tools/apply-patch/structured.js +109 -13
  145. package/dist/tools/apply-patch/validator.js +261 -17
  146. package/dist/tools/tool-registry.d.ts +8 -0
  147. package/dist/tools/tool-registry.js +2 -1
  148. package/package.json +4 -4
  149. package/dist/conversion/compat/actions/apply-patch-format-fixer.js +0 -233
  150. package/dist/conversion/config/compat-profiles.json +0 -38
  151. package/dist/conversion/hub/response/server-side-tools.d.ts +0 -26
  152. package/dist/conversion/hub/response/server-side-tools.js +0 -383
  153. package/dist/conversion/shared/bridge-conversation-store.d.ts +0 -41
  154. package/dist/conversion/shared/bridge-conversation-store.js +0 -279
  155. package/dist/conversion/shared/bridge-request-adapter.d.ts +0 -28
  156. package/dist/conversion/shared/bridge-request-adapter.js +0 -430
  157. package/dist/conversion/shared/responses-id-utils.js +0 -42
  158. package/dist/conversion/shared/responses-instructions.js +0 -113
  159. package/dist/conversion/shared/responses-message-utils.d.ts +0 -15
  160. package/dist/conversion/shared/responses-message-utils.js +0 -206
  161. package/dist/conversion/shared/responses-metadata.js +0 -1
  162. package/dist/conversion/shared/responses-output-utils.d.ts +0 -7
  163. package/dist/conversion/shared/responses-output-utils.js +0 -108
  164. package/dist/conversion/shared/responses-types.d.ts +0 -33
  165. package/dist/conversion/shared/tool-normalizers.d.ts +0 -4
  166. package/dist/conversion/shared/tool-normalizers.js +0 -84
  167. package/dist/filters/special/request-streaming-to-nonstreaming.d.ts +0 -13
  168. package/dist/filters/special/request-streaming-to-nonstreaming.js +0 -39
  169. package/dist/filters/special/response-apply-patch-toon-decode.d.ts +0 -23
  170. package/dist/filters/special/response-apply-patch-toon-decode.js +0 -460
  171. package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +0 -10
  172. package/dist/filters/special/response-tool-arguments-toon-decode.js +0 -154
  173. package/dist/servertool/flow-types.d.ts +0 -40
  174. package/dist/servertool/flow-types.js +0 -1
  175. package/dist/servertool/orchestration-types.d.ts +0 -33
  176. package/dist/servertool/orchestration-types.js +0 -1
  177. package/dist/servertool/vision-tool.d.ts +0 -2
  178. package/dist/servertool/vision-tool.js +0 -185
  179. package/dist/tools/patch-args-normalizer.d.ts +0 -15
  180. package/dist/tools/patch-args-normalizer.js +0 -472
  181. package/dist/utils/toon.d.ts +0 -4
  182. package/dist/utils/toon.js +0 -75
  183. /package/dist/{conversion/compat/actions/apply-patch-format-fixer.d.ts → servertool/handlers/apply-patch-guard.d.ts} +0 -0
  184. /package/dist/{conversion/shared/responses-types.js → servertool/handlers/exec-command-guard.d.ts} +0 -0
@@ -0,0 +1,74 @@
1
+ type JsonPrimitive = string | number | boolean | null;
2
+ type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
3
+ export interface JsonObject {
4
+ [key: string]: JsonValue;
5
+ }
6
+ type Direction = 'request' | 'response';
7
+ type Stage = 'inbound' | 'outbound';
8
+ type ProviderType = 'openai' | 'anthropic' | 'responses' | 'gemini';
9
+ export interface AdapterOptions {
10
+ baseDir?: string;
11
+ processMode?: 'passthrough' | 'chat' | string;
12
+ providerProtocol?: string;
13
+ providerType?: ProviderType;
14
+ entryEndpoint?: string;
15
+ direction?: Direction;
16
+ stage?: Stage;
17
+ }
18
+ export declare function processIncoming(request: JsonObject, options?: AdapterOptions): Promise<{
19
+ data: JsonValue;
20
+ metadata: {
21
+ conversionId: string;
22
+ conversionEndpoint: string;
23
+ conversionStage: Stage;
24
+ };
25
+ }>;
26
+ export declare function processOutgoing(response: JsonObject, options?: AdapterOptions): Promise<{
27
+ data: JsonValue;
28
+ metadata: {
29
+ conversionId: string;
30
+ conversionEndpoint: string;
31
+ conversionStage: Stage;
32
+ };
33
+ }>;
34
+ export declare function processInboundRequest(request: JsonObject, options?: AdapterOptions): Promise<{
35
+ data: JsonValue;
36
+ metadata: {
37
+ conversionId: string;
38
+ conversionEndpoint: string;
39
+ conversionStage: Stage;
40
+ };
41
+ }>;
42
+ export declare function processInboundResponse(response: JsonObject, options?: AdapterOptions): Promise<{
43
+ data: JsonValue;
44
+ metadata: {
45
+ conversionId: string;
46
+ conversionEndpoint: string;
47
+ conversionStage: Stage;
48
+ };
49
+ }>;
50
+ export declare function processOutboundRequest(request: JsonObject, options?: AdapterOptions): Promise<{
51
+ data: JsonValue;
52
+ metadata: {
53
+ conversionId: string;
54
+ conversionEndpoint: string;
55
+ conversionStage: Stage;
56
+ };
57
+ }>;
58
+ export declare function processOutboundResponse(response: JsonObject, options?: AdapterOptions): Promise<{
59
+ data: JsonValue;
60
+ metadata: {
61
+ conversionId: string;
62
+ conversionEndpoint: string;
63
+ conversionStage: Stage;
64
+ };
65
+ }>;
66
+ declare const _default: {
67
+ processIncoming: typeof processIncoming;
68
+ processOutgoing: typeof processOutgoing;
69
+ processInboundRequest: typeof processInboundRequest;
70
+ processInboundResponse: typeof processInboundResponse;
71
+ processOutboundRequest: typeof processOutboundRequest;
72
+ processOutboundResponse: typeof processOutboundResponse;
73
+ };
74
+ export default _default;
@@ -0,0 +1,5 @@
1
+ export interface ResolvedPaths {
2
+ hostRoot: string;
3
+ configDir: string;
4
+ }
5
+ export declare function resolveHostPaths(): ResolvedPaths;
@@ -0,0 +1,26 @@
1
+ export interface ContextBudget {
2
+ maxBytes: number;
3
+ safetyRatio: number;
4
+ allowedBytes: number;
5
+ source: string;
6
+ }
7
+ export declare class UnifiedConfigFacade {
8
+ private static _instance;
9
+ static getInstance(): UnifiedConfigFacade;
10
+ private watchers;
11
+ private fsWatcher;
12
+ getContextBudgetForModel(modelId: string): ContextBudget;
13
+ validateConfig(): {
14
+ ok: boolean;
15
+ issues: string[];
16
+ };
17
+ watchConfig(cb: (ev: {
18
+ file: string;
19
+ event: string;
20
+ }) => void): void;
21
+ unwatchConfig(cb?: (ev: {
22
+ file: string;
23
+ event: string;
24
+ }) => void): void;
25
+ }
26
+ export declare const UnifiedConfig: UnifiedConfigFacade;
@@ -0,0 +1,10 @@
1
+ import type { ConversionCodec } from './types.js';
2
+ export type CodecFactory = () => Promise<ConversionCodec> | ConversionCodec;
3
+ export declare class CodecRegistry {
4
+ private readonly factories;
5
+ private readonly instances;
6
+ constructor(_deps?: unknown);
7
+ register(id: string, factory: CodecFactory): void;
8
+ resolve(id: string): Promise<ConversionCodec>;
9
+ }
10
+ export declare function getDefaultCodecFactories(): Record<string, CodecFactory>;
@@ -0,0 +1,16 @@
1
+ import type { ConversionCodec, ConversionContext, ConversionProfile } from '../types.js';
2
+ export declare function buildOpenAIChatFromGeminiRequest(payload: any): {
3
+ messages: any[];
4
+ };
5
+ export declare function buildOpenAIChatFromGeminiResponse(payload: any): any;
6
+ export declare function buildGeminiFromOpenAIChat(chatResp: any): any;
7
+ export declare class GeminiOpenAIConversionCodec implements ConversionCodec {
8
+ private readonly _dependencies;
9
+ readonly id = "gemini-openai";
10
+ private initialized;
11
+ constructor(_dependencies: any);
12
+ initialize(): Promise<void>;
13
+ private ensureInit;
14
+ convertRequest(payload: any, _profile: ConversionProfile, _context: ConversionContext): Promise<any>;
15
+ convertResponse(payload: any, _profile: ConversionProfile, _context: ConversionContext): Promise<any>;
16
+ }
@@ -0,0 +1,12 @@
1
+ import type { ConversionCodec, ConversionContext, ConversionProfile } from '../types.js';
2
+ export declare class OpenAIOpenAIConversionCodec implements ConversionCodec {
3
+ private readonly dependencies;
4
+ readonly id = "openai-openai";
5
+ private initialized;
6
+ private ctxMap;
7
+ constructor(dependencies: any);
8
+ initialize(): Promise<void>;
9
+ convertRequest(payload: any, profile: ConversionProfile, context: ConversionContext): Promise<any>;
10
+ convertResponse(payload: any, _profile: ConversionProfile, context: ConversionContext): Promise<any>;
11
+ private ensureInit;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { ConversionCodec, ConversionContext, ConversionProfile } from '../types.js';
2
+ export declare class ResponsesOpenAIConversionCodec implements ConversionCodec {
3
+ private readonly dependencies;
4
+ readonly id = "responses-openai";
5
+ private initialized;
6
+ private ctxMap;
7
+ constructor(dependencies: any);
8
+ initialize(): Promise<void>;
9
+ convertRequest(payload: any, profile: ConversionProfile, context: ConversionContext): Promise<any>;
10
+ convertResponse(payload: any, _profile: ConversionProfile, context: ConversionContext): Promise<any>;
11
+ private ensureInit;
12
+ }
@@ -8,6 +8,18 @@
8
8
  {
9
9
  "action": "gemini_web_search_request"
10
10
  },
11
+ {
12
+ "action": "shallow_pick",
13
+ "allowTopLevel": [
14
+ "model",
15
+ "contents",
16
+ "systemInstruction",
17
+ "tools",
18
+ "generationConfig",
19
+ "safetySettings",
20
+ "toolConfig"
21
+ ]
22
+ },
11
23
  { "action": "snapshot", "phase": "compat-post" }
12
24
  ]
13
25
  },
@@ -0,0 +1,212 @@
1
+ /**
2
+ * 配置管理模块
3
+ *
4
+ * 提供统一的配置读取、设置和管理功能
5
+ */
6
+ /**
7
+ * 配置接口定义
8
+ */
9
+ export interface ConversionConfig {
10
+ /** HTTP服务器配置 */
11
+ httpserver?: {
12
+ port: number;
13
+ host: string;
14
+ };
15
+ /** 虚拟路由器配置 */
16
+ virtualrouter?: {
17
+ inputProtocol?: string;
18
+ outputProtocol?: string;
19
+ providers?: Record<string, ProviderConfig>;
20
+ routing?: {
21
+ default?: string[];
22
+ [key: string]: string[];
23
+ };
24
+ };
25
+ /** 服务工具配置 */
26
+ serverTools?: {
27
+ replace?: Record<string, {
28
+ enabled: boolean;
29
+ }>;
30
+ enabled?: boolean;
31
+ };
32
+ /** 转换配置(V2/V3 版本切换相关) */
33
+ conversion?: {
34
+ /** 默认使用的转换版本 */
35
+ defaultVersion?: 'v2' | 'v3' | 'auto';
36
+ /** 允许附加自定义配置字段 */
37
+ [key: string]: unknown;
38
+ };
39
+ }
40
+ /**
41
+ * Provider 配置接口
42
+ */
43
+ export interface ProviderConfig {
44
+ id: string;
45
+ enabled: boolean;
46
+ type: 'openai' | 'anthropic' | 'responses' | 'gemini' | 'custom';
47
+ baseUrl?: string;
48
+ apiKey?: string[];
49
+ auth?: {
50
+ type: 'apikey' | 'oauth';
51
+ apiKey?: string;
52
+ };
53
+ models?: Record<string, ModelConfig>;
54
+ }
55
+ /**
56
+ * 模型配置接口
57
+ */
58
+ export interface ModelConfig {
59
+ supportsStreaming?: boolean;
60
+ compatibility?: {
61
+ type?: string;
62
+ config?: any;
63
+ };
64
+ }
65
+ /**
66
+ * 配置管理器类
67
+ */
68
+ export declare class ConfigManager {
69
+ private static instance;
70
+ private config;
71
+ private constructor();
72
+ /**
73
+ * 获取单例实例
74
+ */
75
+ static getInstance(): ConfigManager;
76
+ /**
77
+ * 设置配置
78
+ *
79
+ * @param config 要设置的配置
80
+ * @param options 选项
81
+ */
82
+ static setConfig(config: Partial<ConversionConfig>, options?: {
83
+ merge?: boolean;
84
+ validate?: boolean;
85
+ save?: boolean;
86
+ source?: string;
87
+ }): void;
88
+ /**
89
+ * 获取配置
90
+ *
91
+ * @param path 指定配置路径(可选)
92
+ * @returns 配置对象
93
+ */
94
+ static getConfig(path?: string): Promise<ConversionConfig>;
95
+ /**
96
+ * 重新加载配置
97
+ */
98
+ static reloadConfig(): Promise<ConversionConfig>;
99
+ /**
100
+ * 验证配置
101
+ */
102
+ private validateConfig;
103
+ /**
104
+ * 深度合并对象(仅在内存中操作,不做任何持久化)
105
+ */
106
+ private deepMerge;
107
+ /**
108
+ * 获取配置摘要
109
+ */
110
+ static getConfigSummary(): {
111
+ totalProviders: number;
112
+ enabledProviders: string[];
113
+ outputProtocol: string;
114
+ inputProtocol: string;
115
+ routingDefaults: string[];
116
+ hasConversionConfig: boolean;
117
+ };
118
+ /**
119
+ * 获取 provider 配置
120
+ */
121
+ static getProviderConfig(providerName: string): ProviderConfig | null;
122
+ /**
123
+ * 检查 provider 是否可用
124
+ */
125
+ static isProviderEnabled(providerName: string): boolean;
126
+ /**
127
+ * 设置 provider 启用状态
128
+ */
129
+ static setProviderEnabled(providerName: string, enabled: boolean): void;
130
+ /**
131
+ /**
132
+ * 获取输出协议
133
+ */
134
+ static getOutputProtocol(): string;
135
+ /**
136
+ * 设置输出协议
137
+ */
138
+ static setOutputProtocol(protocol: string): void;
139
+ /**
140
+ * 获取输入协议
141
+ */
142
+ static getInputProtocol(): string;
143
+ /**
144
+ * 设置输入协议
145
+ */
146
+ static setInputProtocol(protocol: string): void;
147
+ /**
148
+ * 获取路由配置
149
+ */
150
+ static getRoutingConfig(): any;
151
+ /**
152
+ * 设置路由配置
153
+ */
154
+ static setRoutingConfig(routing: any): void;
155
+ /**
156
+ * 获取 V3 转换配置
157
+ */
158
+ static getConversionConfig(): any;
159
+ /**
160
+ * 设置 V3 转换配置
161
+ */
162
+ static setConversionConfig(conversion: any): void;
163
+ }
164
+ /**
165
+ * 便捷函数:设置配置
166
+ */
167
+ export declare function setConfig(config: Partial<ConversionConfig>, options?: {
168
+ merge?: boolean;
169
+ validate?: boolean;
170
+ save?: boolean;
171
+ source?: string;
172
+ }): void;
173
+ /**
174
+ * 便捷函数:获取配置
175
+ */
176
+ export declare function getConfig(path?: string): Promise<ConversionConfig>;
177
+ /**
178
+ * 便捷函数:重新加载配置
179
+ */
180
+ export declare function reloadConfig(): Promise<ConversionConfig>;
181
+ /**
182
+ * 便捷函数:获取配置摘要
183
+ */
184
+ export declare function getConfigSummary(): ReturnType<typeof ConfigManager.getConfigSummary>;
185
+ /**
186
+ * 便捷函数:获取 Provider 配置
187
+ */
188
+ export declare function getProviderConfig(providerName: string): ProviderConfig | null;
189
+ /**
190
+ * 便捷函数:检查 Provider 状态
191
+ */
192
+ export declare function isProviderEnabled(providerName: string): boolean;
193
+ /**
194
+ * 便捷函数:设置 Provider 状态
195
+ */
196
+ export declare function setProviderEnabled(providerName: string, enabled: boolean): void;
197
+ /**
198
+ * 便捷函数:获取输出协议
199
+ */
200
+ export declare function getOutputProtocol(): string;
201
+ /**
202
+ * 便捷函数:设置输出协议
203
+ */
204
+ export declare function setOutputProtocol(protocol: string): void;
205
+ /**
206
+ * 便捷函数:获取输入协议
207
+ */
208
+ export declare function getInputProtocol(): string;
209
+ /**
210
+ * 便捷函数:设置输入协议
211
+ */
212
+ export declare function setInputProtocol(protocol: string): void;
@@ -0,0 +1,26 @@
1
+ export type MappingDirection = 'inbound' | 'outbound';
2
+ export interface FieldMapping {
3
+ readonly id: string;
4
+ readonly target: string;
5
+ readonly path: string;
6
+ readonly description: string;
7
+ readonly required?: boolean;
8
+ readonly transformNotes?: string;
9
+ }
10
+ export interface FormatMappingConfig {
11
+ readonly description: string;
12
+ readonly inbound: readonly FieldMapping[];
13
+ readonly outbound: readonly FieldMapping[];
14
+ }
15
+ export interface SemanticRule {
16
+ readonly id: string;
17
+ readonly appliesTo: MappingDirection | 'both';
18
+ readonly description: string;
19
+ readonly notes?: string;
20
+ }
21
+ export interface ProtocolConfigDocument {
22
+ readonly protocol: string;
23
+ readonly specReference: string;
24
+ readonly format: FormatMappingConfig;
25
+ readonly semanticRules: readonly SemanticRule[];
26
+ }
@@ -0,0 +1,9 @@
1
+ import type { DetourEntry, DetourState } from '../types/chat-schema.js';
2
+ import type { HubDirection } from './hub-context.js';
3
+ export declare class DetourRegistry {
4
+ private readonly inbound;
5
+ private readonly outbound;
6
+ add(direction: HubDirection, entry: DetourEntry): void;
7
+ snapshot(): DetourState;
8
+ drain(direction: HubDirection): readonly DetourEntry[];
9
+ }
@@ -0,0 +1,21 @@
1
+ import type { JsonObject, JsonValue } from '../types/json.js';
2
+ export type HubDirection = 'inbound' | 'outbound';
3
+ export interface HubContext {
4
+ readonly requestId: string;
5
+ readonly protocol: string;
6
+ readonly direction: HubDirection;
7
+ readonly routeId?: string;
8
+ readonly providerId?: string;
9
+ readonly profileId?: string;
10
+ readonly endpoint?: string;
11
+ readonly metadata?: JsonObject;
12
+ }
13
+ export interface StageSnapshot {
14
+ readonly stage: string;
15
+ readonly protocol: string;
16
+ readonly direction: HubDirection;
17
+ readonly payload: JsonValue;
18
+ }
19
+ export interface StageSnapshotRecorder {
20
+ record(snapshot: StageSnapshot): void;
21
+ }
@@ -0,0 +1,3 @@
1
+ export * from './hub-context.js';
2
+ export * from './detour-registry.js';
3
+ export * from './stage-driver.js';
@@ -0,0 +1,30 @@
1
+ import { DetourRegistry } from './detour-registry.js';
2
+ import type { HubContext, HubDirection, StageSnapshotRecorder } from './hub-context.js';
3
+ import type { JsonValue } from '../types/json.js';
4
+ export type HubStageKind = 'format' | 'semantic' | 'config';
5
+ export interface HubStageRuntime {
6
+ readonly context: HubContext;
7
+ readonly detours: DetourRegistry;
8
+ }
9
+ export interface HubStageDefinition {
10
+ readonly name: string;
11
+ readonly kind: HubStageKind;
12
+ readonly direction: HubDirection;
13
+ readonly execute: (input: JsonValue, runtime: HubStageRuntime) => Promise<JsonValue> | JsonValue;
14
+ }
15
+ export interface HubPlan {
16
+ readonly protocol: string;
17
+ readonly direction: HubDirection;
18
+ readonly passthrough?: {
19
+ readonly mode: 'identity' | 'clone';
20
+ };
21
+ readonly stages: readonly HubStageDefinition[];
22
+ }
23
+ export interface RunHubPlanOptions {
24
+ readonly plan: HubPlan;
25
+ readonly context: HubContext;
26
+ readonly initialInput: JsonValue;
27
+ readonly recorder?: StageSnapshotRecorder;
28
+ readonly detours?: DetourRegistry;
29
+ }
30
+ export declare function runHubPlan(options: RunHubPlanOptions): Promise<JsonValue>;
@@ -0,0 +1,16 @@
1
+ import type { FormatAdapter } from './index.js';
2
+ import type { AdapterContext } from '../types/chat-envelope.js';
3
+ import type { FormatEnvelope } from '../types/format-envelope.js';
4
+ import type { JsonObject, JsonValue } from '../types/json.js';
5
+ interface AnthropicFormatPayload extends JsonObject {
6
+ messages?: JsonValue[];
7
+ tools?: JsonValue[];
8
+ }
9
+ export declare class AnthropicFormatAdapter implements FormatAdapter {
10
+ readonly protocol = "anthropic-messages";
11
+ parseRequest(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<AnthropicFormatPayload>>;
12
+ buildRequest(format: FormatEnvelope<AnthropicFormatPayload>, _ctx: AdapterContext): Promise<AnthropicFormatPayload>;
13
+ parseResponse(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<AnthropicFormatPayload>>;
14
+ buildResponse(format: FormatEnvelope<AnthropicFormatPayload>, _ctx: AdapterContext): Promise<AnthropicFormatPayload>;
15
+ }
16
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { FormatAdapter } from './index.js';
2
+ import type { AdapterContext } from '../types/chat-envelope.js';
3
+ import type { FormatEnvelope } from '../types/format-envelope.js';
4
+ import type { JsonObject, JsonValue } from '../types/json.js';
5
+ interface ChatFormatPayload extends JsonObject {
6
+ messages?: JsonValue[];
7
+ tools?: JsonValue[];
8
+ tool_outputs?: JsonValue[];
9
+ }
10
+ export declare class ChatFormatAdapter implements FormatAdapter {
11
+ readonly protocol = "openai-chat";
12
+ parseRequest(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<ChatFormatPayload>>;
13
+ buildRequest(format: FormatEnvelope<ChatFormatPayload>, _ctx: AdapterContext): Promise<ChatFormatPayload>;
14
+ parseResponse(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<ChatFormatPayload>>;
15
+ buildResponse(format: FormatEnvelope<ChatFormatPayload>, _ctx: AdapterContext): Promise<ChatFormatPayload>;
16
+ }
17
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { FormatAdapter } from './index.js';
2
+ import type { AdapterContext } from '../types/chat-envelope.js';
3
+ import type { FormatEnvelope } from '../types/format-envelope.js';
4
+ import type { JsonObject } from '../types/json.js';
5
+ interface GeminiFormatPayload extends JsonObject {
6
+ contents?: JsonObject[];
7
+ tools?: JsonObject[];
8
+ }
9
+ export declare class GeminiFormatAdapter implements FormatAdapter {
10
+ readonly protocol = "gemini-chat";
11
+ parseRequest(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<GeminiFormatPayload>>;
12
+ buildRequest(format: FormatEnvelope<GeminiFormatPayload>, _ctx: AdapterContext): Promise<GeminiFormatPayload>;
13
+ parseResponse(original: JsonObject, _ctx: AdapterContext): Promise<FormatEnvelope<GeminiFormatPayload>>;
14
+ buildResponse(format: FormatEnvelope<GeminiFormatPayload>, _ctx: AdapterContext): Promise<GeminiFormatPayload>;
15
+ }
16
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { AdapterContext, ChatEnvelope } from '../types/chat-envelope.js';
2
+ import type { FormatEnvelope } from '../types/format-envelope.js';
3
+ import type { JsonObject } from '../types/json.js';
4
+ export interface FormatAdapter<TRequestPayload extends JsonObject = JsonObject, TResponsePayload extends JsonObject = JsonObject> {
5
+ readonly protocol: string;
6
+ parseRequest(original: TRequestPayload, ctx: AdapterContext): Promise<FormatEnvelope<TRequestPayload>> | FormatEnvelope<TRequestPayload>;
7
+ buildRequest(format: FormatEnvelope, ctx: AdapterContext): Promise<TRequestPayload> | TRequestPayload;
8
+ parseResponse(original: TResponsePayload, ctx: AdapterContext): Promise<FormatEnvelope<TResponsePayload>> | FormatEnvelope<TResponsePayload>;
9
+ buildResponse(format: FormatEnvelope, ctx: AdapterContext): Promise<TResponsePayload> | TResponsePayload;
10
+ }
11
+ export interface StageRecorder {
12
+ record(stage: string, payload: object): void;
13
+ }
14
+ export interface SemanticMapper {
15
+ toChat(format: FormatEnvelope, ctx: AdapterContext): Promise<ChatEnvelope> | ChatEnvelope;
16
+ fromChat(chat: ChatEnvelope, ctx: AdapterContext): Promise<FormatEnvelope> | FormatEnvelope;
17
+ }
18
+ export { ChatFormatAdapter } from './chat-format-adapter.js';
19
+ export { AnthropicFormatAdapter } from './anthropic-format-adapter.js';
20
+ export { ResponsesFormatAdapter } from './responses-format-adapter.js';
21
+ export { GeminiFormatAdapter } from './gemini-format-adapter.js';
@@ -0,0 +1 @@
1
+ export declare function isHubProtocolEnabled(protocol: string): boolean;
@@ -0,0 +1,19 @@
1
+ import type { StandardizedRequest, ProcessedRequest } from './types/standardized.js';
2
+ import type { HubNodeContext, HubNodeResult } from './types/node.js';
3
+ export interface HubInboundOptions {
4
+ protocol: string;
5
+ rawRequest: Record<string, unknown>;
6
+ nodeContext: HubNodeContext;
7
+ nodeId: string;
8
+ inputFormat: string;
9
+ outputFormat: string;
10
+ startTime: number;
11
+ }
12
+ export interface HubOutboundOptions {
13
+ protocol: string;
14
+ request: StandardizedRequest | ProcessedRequest;
15
+ nodeContext: HubNodeContext;
16
+ }
17
+ export declare function shouldUseHub(protocol: string): boolean;
18
+ export declare function runHubInboundConversion(options: HubInboundOptions): Promise<HubNodeResult>;
19
+ export declare function runHubOutboundConversion(options: HubOutboundOptions): Promise<Record<string, unknown>>;
@@ -95,6 +95,17 @@ function applyMapping(root, mapping, state) {
95
95
  case 'remove':
96
96
  removePath(root, mapping.path);
97
97
  break;
98
+ case 'shallow_pick': {
99
+ const allow = new Set(Array.isArray(mapping.allowTopLevel) ? mapping.allowTopLevel : []);
100
+ const next = {};
101
+ for (const [key, value] of Object.entries(root)) {
102
+ if (allow.has(key)) {
103
+ next[key] = value;
104
+ }
105
+ }
106
+ replaceRoot(root, next);
107
+ break;
108
+ }
98
109
  case 'rename':
99
110
  renamePath(root, mapping.from, mapping.to);
100
111
  break;
@@ -23,6 +23,9 @@ export interface CompatStageConfig {
23
23
  export type MappingInstruction = {
24
24
  action: 'remove';
25
25
  path: string;
26
+ } | {
27
+ action: 'shallow_pick';
28
+ allowTopLevel: string[];
26
29
  } | {
27
30
  action: 'rename';
28
31
  from: string;
@@ -3,8 +3,14 @@ import type { StandardizedRequest, ProcessedRequest } from '../types/standardize
3
3
  import type { JsonObject } from '../types/json.js';
4
4
  import type { VirtualRouterConfig, RoutingDecision, RoutingDiagnostics, TargetMetadata, VirtualRouterHealthStore, ProviderQuotaView } from '../../../router/virtual-router/types.js';
5
5
  import { type HubProcessNodeResult } from '../process/chat-process.js';
6
+ import { type HubPolicyConfig } from '../policy/policy-engine.js';
6
7
  export interface HubPipelineConfig {
7
8
  virtualRouter: VirtualRouterConfig;
9
+ /**
10
+ * Optional: hub-level policy controls (observe-only in V1 Phase 0).
11
+ * Must remain config-driven and default to off.
12
+ */
13
+ policy?: HubPolicyConfig;
8
14
  /**
9
15
  * 可选:供 VirtualRouterEngine 使用的健康状态持久化存储。
10
16
  * 当提供时,VirtualRouterEngine 将在初始化时恢复上一次快照,并在 cooldown/熔断变化时调用 persistSnapshot。
@@ -72,6 +78,7 @@ export declare class HubPipeline {
72
78
  updateVirtualRouterConfig(nextConfig: VirtualRouterConfig): void;
73
79
  dispose(): void;
74
80
  private executeRequestStagePipeline;
81
+ private resolveClientProtocol;
75
82
  execute(request: HubPipelineRequest): Promise<HubPipelineResult>;
76
83
  private captureAnthropicAliasMap;
77
84
  private shouldCaptureAnthropicAlias;