@jsonstudio/llms 0.6.3539 → 0.6.3551

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.
@@ -1,6 +1,7 @@
1
1
  import { buildNativeReqOutboundCompatAdapterContext } from '../../hub/pipeline/compat/native-adapter-context.js';
2
2
  import { loadNativeRouterHotpathBindingForInternalUse } from '../../../router/virtual-router/engine-selection/native-router-hotpath.js';
3
3
  import { isNativeDisabledByEnv, makeNativeRequiredError } from '../../../router/virtual-router/engine-selection/native-router-hotpath-policy.js';
4
+ import { providerErrorCenter } from '../../../router/virtual-router/error-center.js';
4
5
  const CAPABILITY = 'runRespInboundStage3CompatJson';
5
6
  const PROFILE = 'chat:deepseek-web';
6
7
  const DEFAULT_PROVIDER_PROTOCOL = 'openai-chat';
@@ -28,6 +29,44 @@ const readToolProtocol = (value) => {
28
29
  const normalized = value.trim().toLowerCase();
29
30
  return normalized === 'native' || normalized === 'text' ? normalized : undefined;
30
31
  };
32
+ function buildRuntimeMetadata(adapterContext, payload, details) {
33
+ const contextRecord = adapterContext && typeof adapterContext === 'object'
34
+ ? adapterContext
35
+ : undefined;
36
+ const runtime = {};
37
+ const assignString = (key, value) => {
38
+ if (typeof value === 'string' && value.trim()) {
39
+ runtime[key] = value.trim();
40
+ }
41
+ };
42
+ assignString('requestId', contextRecord?.requestId);
43
+ assignString('providerProtocol', contextRecord?.providerProtocol);
44
+ assignString('providerId', contextRecord?.providerId);
45
+ assignString('providerKey', contextRecord?.providerKey);
46
+ assignString('runtimeKey', contextRecord?.runtimeKey);
47
+ assignString('routeName', contextRecord?.routeId);
48
+ assignString('pipelineId', PROFILE);
49
+ if (payload && typeof payload === 'object') {
50
+ assignString('target', payload.model);
51
+ }
52
+ if (details && Object.keys(details).length > 0) {
53
+ runtime.details = details;
54
+ }
55
+ return runtime;
56
+ }
57
+ function emitCompatError(error, adapterContext, payload, details) {
58
+ providerErrorCenter.emit({
59
+ code: 'DEEPSEEK_WEB_COMPAT_ERROR',
60
+ message: error.message,
61
+ stage: 'compat:deepseek-web-response',
62
+ runtime: buildRuntimeMetadata(adapterContext, payload, details),
63
+ details: {
64
+ compatibilityProfile: PROFILE,
65
+ ...(details ?? {})
66
+ }
67
+ });
68
+ throw error;
69
+ }
31
70
  function resolveDeepseekNode(adapterContext, config) {
32
71
  const nativeContext = buildNativeReqOutboundCompatAdapterContext(adapterContext);
33
72
  const baseNode = isRecord(nativeContext.deepseek) ? nativeContext.deepseek : {};
@@ -72,31 +111,49 @@ function parseCompatOutput(raw) {
72
111
  }
73
112
  return parsed;
74
113
  }
75
- function callDeepSeekWebResponseCompat(input) {
114
+ function callDeepSeekWebResponseCompat(input, adapterContext) {
76
115
  if (isNativeDisabledByEnv()) {
77
- throw makeNativeRequiredError(CAPABILITY, 'native disabled');
116
+ emitCompatError(makeNativeRequiredError(CAPABILITY, 'native disabled'), adapterContext, input.payload, {
117
+ reason: 'native disabled'
118
+ });
78
119
  }
79
120
  const binding = loadNativeRouterHotpathBindingForInternalUse();
80
121
  const fn = binding?.[CAPABILITY];
81
122
  if (typeof fn !== 'function') {
82
- throw makeNativeRequiredError(CAPABILITY);
123
+ emitCompatError(makeNativeRequiredError(CAPABILITY), adapterContext, input.payload, {
124
+ reason: 'missing native export'
125
+ });
83
126
  }
84
127
  let inputJson;
85
128
  try {
86
129
  inputJson = JSON.stringify(input);
87
130
  }
88
131
  catch {
89
- throw makeNativeRequiredError(CAPABILITY, 'json stringify failed');
132
+ emitCompatError(makeNativeRequiredError(CAPABILITY, 'json stringify failed'), adapterContext, input.payload, {
133
+ reason: 'json stringify failed'
134
+ });
135
+ }
136
+ try {
137
+ const raw = fn(inputJson);
138
+ if (typeof raw !== 'string' || !raw) {
139
+ emitCompatError(makeNativeRequiredError(CAPABILITY, 'empty result'), adapterContext, input.payload, {
140
+ reason: 'empty result'
141
+ });
142
+ }
143
+ return parseCompatOutput(raw);
90
144
  }
91
- const raw = fn(inputJson);
92
- if (typeof raw !== 'string' || !raw) {
93
- throw makeNativeRequiredError(CAPABILITY, 'empty result');
145
+ catch (error) {
146
+ const compatError = error instanceof Error ? error : new Error(String(error));
147
+ emitCompatError(compatError, adapterContext, input.payload, {
148
+ reason: 'native compat execution failed'
149
+ });
94
150
  }
95
- return parseCompatOutput(raw);
96
151
  }
97
152
  export function applyDeepSeekWebResponseTransform(payload, adapterContext, config) {
98
153
  if (!payload || typeof payload !== 'object') {
99
- return payload;
154
+ emitCompatError(new Error('[deepseek-web] invalid compat payload: expected object'), adapterContext, payload, {
155
+ reason: 'payload is not an object'
156
+ });
100
157
  }
101
- return callDeepSeekWebResponseCompat(buildCompatInput(payload, adapterContext, config)).payload;
158
+ return callDeepSeekWebResponseCompat(buildCompatInput(payload, adapterContext, config), adapterContext).payload;
102
159
  }
@@ -1,10 +1,10 @@
1
- import { Readable } from 'node:stream';
2
- import type { StandardizedRequest, ProcessedRequest } from '../types/standardized.js';
3
- import type { JsonObject } from '../types/json.js';
4
- import type { VirtualRouterConfig, RoutingDecision, RoutingDiagnostics, TargetMetadata, VirtualRouterHealthStore, ProviderQuotaView } from '../../../router/virtual-router/types.js';
5
- import { type HubProcessNodeResult } from '../process/chat-process.js';
6
- import { type HubPolicyConfig } from '../policy/policy-engine.js';
7
- import { type HubToolSurfaceConfig } from '../tool-surface/tool-surface-engine.js';
1
+ import { Readable } from "node:stream";
2
+ import type { StandardizedRequest, ProcessedRequest } from "../types/standardized.js";
3
+ import type { JsonObject } from "../types/json.js";
4
+ import type { VirtualRouterConfig, RoutingDecision, RoutingDiagnostics, TargetMetadata, VirtualRouterHealthStore, ProviderQuotaView } from "../../../router/virtual-router/types.js";
5
+ import { type HubProcessNodeResult } from "../process/chat-process.js";
6
+ import { type HubPolicyConfig } from "../policy/policy-engine.js";
7
+ import { type HubToolSurfaceConfig } from "../tool-surface/tool-surface-engine.js";
8
8
  export interface HubPipelineConfig {
9
9
  virtualRouter: VirtualRouterConfig;
10
10
  /**
@@ -40,9 +40,9 @@ export interface HubPipelineConfig {
40
40
  export interface HubPipelineRequestMetadata extends Record<string, unknown> {
41
41
  entryEndpoint?: string;
42
42
  providerProtocol?: string;
43
- processMode?: 'chat' | 'passthrough';
44
- stage?: 'inbound' | 'outbound';
45
- direction?: 'request' | 'response';
43
+ processMode?: "chat" | "passthrough";
44
+ stage?: "inbound" | "outbound";
45
+ direction?: "request" | "response";
46
46
  stream?: boolean;
47
47
  routeHint?: string;
48
48
  }
@@ -54,7 +54,7 @@ export interface HubPipelineRequest {
54
54
  } | Readable;
55
55
  metadata?: HubPipelineRequestMetadata;
56
56
  }
57
- type HubPipelineNodeMetadata = HubProcessNodeResult['metadata'] | Record<string, unknown>;
57
+ type HubPipelineNodeMetadata = HubProcessNodeResult["metadata"] | Record<string, unknown>;
58
58
  export interface HubPipelineNodeResult {
59
59
  id: string;
60
60
  success: boolean;
@@ -79,9 +79,9 @@ export declare class HubPipeline {
79
79
  private unsubscribeProviderSuccess?;
80
80
  constructor(config: HubPipelineConfig);
81
81
  updateRuntimeDeps(deps: {
82
- healthStore?: HubPipelineConfig['healthStore'] | null;
83
- routingStateStore?: HubPipelineConfig['routingStateStore'] | null;
84
- quotaView?: HubPipelineConfig['quotaView'] | null;
82
+ healthStore?: HubPipelineConfig["healthStore"] | null;
83
+ routingStateStore?: HubPipelineConfig["routingStateStore"] | null;
84
+ quotaView?: HubPipelineConfig["quotaView"] | null;
85
85
  }): void;
86
86
  updateVirtualRouterConfig(nextConfig: VirtualRouterConfig): void;
87
87
  dispose(): void;