dsh-lcx-codex 0.5.1-pre.1 → 0.5.2

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.
@@ -73,12 +73,115 @@ function errorFacts(error) {
73
73
  text: texts.join(" | "),
74
74
  };
75
75
  }
76
+ /** @param {unknown} value */
77
+ function safeMachineField(value) {
78
+ if (typeof value !== "string" || value.length === 0 || value.length > 96)
79
+ return undefined;
80
+ return /^[A-Za-z0-9_.:\[\]-]+$/u.test(value) ? value : undefined;
81
+ }
82
+ /**
83
+ * Record the structured facts of a failure the provider reports in-stream. Pi collapses every such
84
+ * event into one `Error("<code>: <message>")` and `response.completed` with status `failed` into a
85
+ * bare "stream ended in failure", so the machine fields are captured here, before that happens.
86
+ */
87
+ function observeUpstreamFailure(event, meta) {
88
+ const type = String(event.type ?? "");
89
+ let source;
90
+ let details;
91
+ let hasError = false;
92
+ let incomplete = false;
93
+ if (type === "error") {
94
+ // OpenAI sends flat `{code, message}`; some gateways nest `{error: {code, type}}`. `type` is only
95
+ // ever the error type when nested, because the flat `type` is the event name itself.
96
+ const nested = isObject(event.error) ? event.error : undefined;
97
+ source = { code: nested?.code ?? event.code, type: nested?.type };
98
+ hasError = true;
99
+ }
100
+ else if (isObject(event.response)) {
101
+ const response = event.response;
102
+ const status = response.status;
103
+ const failedTerminal = type === "response.failed" ||
104
+ (type === "response.completed" && status === "failed");
105
+ const incompleteTerminal = type === "response.incomplete" ||
106
+ (type === "response.completed" && status === "incomplete");
107
+ if (!failedTerminal && !incompleteTerminal)
108
+ return;
109
+ incomplete = incompleteTerminal;
110
+ details = isObject(response.incomplete_details)
111
+ ? response.incomplete_details.reason
112
+ : undefined;
113
+ // max_output_tokens is a length stop that Pi maps to a normal finish, not a failure.
114
+ if (incompleteTerminal && details === "max_output_tokens")
115
+ return;
116
+ source = isObject(response.error) ? response.error : undefined;
117
+ hasError = source !== undefined;
118
+ }
119
+ else
120
+ return;
121
+ const code = safeMachineField(source?.code);
122
+ const errorType = safeMachineField(source?.type);
123
+ const incompleteReason = safeMachineField(details);
124
+ meta.upstreamFailure = {
125
+ event: type,
126
+ ...(code === undefined ? {} : { code }),
127
+ ...(errorType === undefined ? {} : { type: errorType }),
128
+ ...(incompleteReason === undefined ? {} : { incompleteReason }),
129
+ hasError,
130
+ incomplete,
131
+ };
132
+ }
133
+ /** Closed mapping from provider machine identifiers to the DSH failure taxonomy; unknown identifiers return undefined. */
134
+ function classifyProviderIdentifier(value) {
135
+ if (value === undefined)
136
+ return undefined;
137
+ const id = value.toLowerCase();
138
+ if (id === "insufficient_quota" || id === "insufficient_user_quota")
139
+ return "INSUFFICIENT_QUOTA";
140
+ if (/^(?:invalid_api_key|authentication_error|permission_error)$/u.test(id))
141
+ return "AUTH";
142
+ if (/^rate_limit|^too_many_requests$/u.test(id))
143
+ return "RATE_LIMIT";
144
+ if (id === "context_length_exceeded")
145
+ return "CONTEXT_WINDOW_EXCEEDED";
146
+ if (id === "content_filter" ||
147
+ id === "content_policy_violation" ||
148
+ id.startsWith("invalid_"))
149
+ return "INVALID_REQUEST";
150
+ if (/^(?:server_error|internal_error|internal_server_error|api_error|service_unavailable|bad_response_status_code)$/u.test(id) ||
151
+ id.includes("overloaded"))
152
+ return "SERVER";
153
+ return undefined;
154
+ }
155
+ /**
156
+ * Failure class for an in-stream provider failure, from its structured fields only.
157
+ * `definite` classes come from a recognised identifier and outrank everything else. A failed response
158
+ * with no usable `error.code` (no error object, `{}`, a message only, an empty code, or only an unknown
159
+ * type) is still a provider-side failure and defaults to SERVER, but not definitely: wording in the
160
+ * message that clearly names another class (rate limit, context window, timeout) keeps that class.
161
+ * An unrecognised non-empty code is left to the text heuristics and the generic fallback.
162
+ */
163
+ function classifyUpstreamFailure(upstream) {
164
+ if (upstream === undefined)
165
+ return undefined;
166
+ const fromError = classifyProviderIdentifier(upstream.code) ??
167
+ classifyProviderIdentifier(upstream.type);
168
+ if (fromError !== undefined)
169
+ return { code: fromError, definite: true };
170
+ const fromReason = classifyProviderIdentifier(upstream.incompleteReason);
171
+ if (fromReason !== undefined)
172
+ return { code: fromReason, definite: true };
173
+ if (upstream.incomplete)
174
+ return undefined;
175
+ if (upstream.code === undefined)
176
+ return { code: "SERVER", definite: false };
177
+ return undefined;
178
+ }
76
179
  /**
77
180
  * Provider bodies/messages are deliberately not surfaced. Only a stable class and safe facts leave the wire boundary.
78
181
  * @param {unknown} error
79
182
  * @param {AbortSignal} [signal]
80
183
  */
81
- export function managedFailure(error, signal) {
184
+ export function managedFailure(error, signal, upstream) {
82
185
  const facts = errorFacts(error);
83
186
  const sourceCodes = new Set(facts.codes);
84
187
  const text = facts.text;
@@ -87,8 +190,11 @@ export function managedFailure(error, signal) {
87
190
  (signalReason?.name === "TimeoutError" ||
88
191
  signalReason?.code === "TimeoutError" ||
89
192
  /time(?:d)?\s*out|timeout/iu.test(String(signalReason?.message ?? "")));
193
+ const upstreamClass = signal?.aborted ? undefined : classifyUpstreamFailure(upstream);
90
194
  let code = "RESPONSES_ERROR";
91
- if (signalTimedOut ||
195
+ if (upstreamClass?.definite === true)
196
+ code = upstreamClass.code;
197
+ else if (signalTimedOut ||
92
198
  facts.status === 408 ||
93
199
  sourceCodes.has("TimeoutError") ||
94
200
  /time(?:d)?\s*out|timeout/iu.test(text))
@@ -104,8 +210,9 @@ export function managedFailure(error, signal) {
104
210
  else if (sourceCodes.has("LCX_GROK_NATIVE_PROTOCOL_ERROR"))
105
211
  code = "GROK_NATIVE_PROTOCOL_ERROR";
106
212
  else if (sourceCodes.has("LCX_RESPONSES_ROUTE_UNAVAILABLE") ||
107
- sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE") ||
108
- sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN"))
213
+ sourceCodes.has("LCX_RESPONSES_API_UNRESOLVED") ||
214
+ sourceCodes.has("LCX_RESPONSES_MODEL_NOT_CONFIGURED") ||
215
+ sourceCodes.has("LCX_RESPONSES_MODEL_UNAVAILABLE"))
109
216
  code = "NO_ADAPTER";
110
217
  else if (sourceCodes.has("LCX_INSUFFICIENT_QUOTA"))
111
218
  code = "INSUFFICIENT_QUOTA";
@@ -129,6 +236,7 @@ export function managedFailure(error, signal) {
129
236
  facts.status === 422 ||
130
237
  sourceCodes.has("LCX_RESPONSES_INVALID_INPUT") ||
131
238
  sourceCodes.has("LCX_CHECKPOINT_UNSUPPORTED") ||
239
+ sourceCodes.has("LCX_CHECKPOINT_IMAGE_BUDGET") ||
132
240
  /invalid.?request|payload too large|length limit exceeded/iu.test(text))
133
241
  code = "INVALID_REQUEST";
134
242
  else if (sourceCodes.has("LCX_RESPONSE_TOO_LARGE"))
@@ -139,19 +247,26 @@ export function managedFailure(error, signal) {
139
247
  else if (error instanceof TypeError ||
140
248
  /\bnetwork|connection|socket|fetch|ECONN|EAI_AGAIN|terminated|premature close\b/iu.test(text))
141
249
  code = "TRANSPORT";
250
+ // Nothing in the text said otherwise: a failure the provider reported without a usable code is its own.
251
+ if (code === "RESPONSES_ERROR" && upstreamClass !== undefined)
252
+ code = upstreamClass.code;
142
253
  const messages = /** @type {Record<string, string>} */ {
143
254
  ABORTED: "Responses request was aborted",
144
255
  AUTH: "Responses request was rejected by authentication",
145
256
  INSUFFICIENT_QUOTA: "服务商额度不足或未满足请求预留额度,请检查中转额度(并非 API 密钥无效) / Provider quota is insufficient for this request",
146
257
  UNSUPPORTED_OPTION: "LCX Responses does not support this request option",
147
- NO_ADAPTER: sourceCodes.has("LCX_SYSTEM_PROMPT_MODE_UNKNOWN")
148
- ? "LCX could not read the route's model information, so in-history system prompt updates cannot be sent safely; retry once the route is available"
149
- : "LCX could not resolve the selected Responses route",
258
+ NO_ADAPTER: sourceCodes.has("LCX_RESPONSES_MODEL_NOT_CONFIGURED")
259
+ ? "LCX is enabled but the selected model is not configured for this provider (the provider profile lists other models); add it to the profile's models list or select a listed model"
260
+ : sourceCodes.has("LCX_RESPONSES_API_UNRESOLVED")
261
+ ? "LCX could not determine the wire protocol of the selected GPT route (the provider profile sets no api and the model is unknown to the catalog); add api: openai-responses to the provider profile or select a model DSH recognizes"
262
+ : "LCX could not resolve the selected Responses route",
150
263
  RATE_LIMIT: "Responses provider rate limit was reached",
151
264
  SERVER: "Responses provider returned a server failure",
152
265
  INVALID_REQUEST: sourceCodes.has("LCX_CHECKPOINT_UNSUPPORTED")
153
266
  ? "Unsupported or invalid LCX checkpoint; start a new session"
154
- : "Responses provider rejected the request",
267
+ : sourceCodes.has("LCX_CHECKPOINT_IMAGE_BUDGET")
268
+ ? "Images kept in the compaction checkpoint exceed the request image bound; start a new session or raise maxRequestImageBytes"
269
+ : "Responses provider rejected the request",
155
270
  CONTEXT_WINDOW_EXCEEDED: "Responses request exceeded the model context window",
156
271
  UNSUPPORTED_CONTENT: "LCX cannot serialize a DSH content block for this Responses route",
157
272
  GROK_NATIVE_PROTOCOL_ERROR: "Grok returned an unrecognized client tool call while native search was enabled",
@@ -722,6 +837,7 @@ async function* normalizedResponseEvents(source, meta = {}, options = {}) {
722
837
  if (!isObject(raw))
723
838
  continue;
724
839
  const event = /** @type {UnknownRecord} */ raw;
840
+ observeUpstreamFailure(event, meta);
725
841
  if (options.serverToolTypes && ['response.completed', 'response.failed', 'response.incomplete'].includes(String(event.type))) {
726
842
  meta.contextDetails = sanitizeContextDetails(isObject(event.response) && isObject(event.response.usage)
727
843
  ? event.response.usage.context_details : undefined);
@@ -1335,7 +1451,33 @@ async function* toDshChunks(events, signal, wireMeta, nativeReplayRoute) {
1335
1451
  * @param {ReadonlySet<string>} [options.serverToolTypes]
1336
1452
  * @param {(usage: ServerToolUsage) => void} [options.onServerToolUsage]
1337
1453
  */
1338
- export async function* streamResponsesRequest({ baseURL, provider, model, piModel, body, grammarToolInputProperties, headers, signal, timeoutMs, applyDefaultTimeout = true, streamIdleTimeoutMs, maxAttempts = 1, maxResponseBytes, serverToolTypes, isServerToolItem, declaredToolNames, nativeReplayRoute, onServerToolUsage, }) {
1454
+ export async function* streamResponsesRequest({ baseURL, provider, model, piModel, body, grammarToolInputProperties, headers, signal, timeoutMs, applyDefaultTimeout = true, streamIdleTimeoutMs, maxAttempts = 1, maxResponseBytes, serverToolTypes, isServerToolItem, declaredToolNames, nativeReplayRoute, onServerToolUsage, onFailure, }) {
1455
+ let contentEmitted = false;
1456
+ let failureReported = false;
1457
+ /** One redacted report per request; user aborts are not failures. */
1458
+ const reportFailure = (chunk, managed, upstream) => {
1459
+ if (failureReported || onFailure === undefined)
1460
+ return;
1461
+ if (chunk.type !== "finish" || chunk.reason.kind !== "error")
1462
+ return;
1463
+ failureReported = true;
1464
+ const failure = chunk.reason.failure;
1465
+ try {
1466
+ onFailure({
1467
+ code: String(failure.code),
1468
+ ...(typeof failure.status === "number" ? { status: failure.status } : {}),
1469
+ ...(managed?.requestId === undefined ? {} : { requestId: managed.requestId }),
1470
+ ...(upstream?.code === undefined ? {} : { providerCode: upstream.code }),
1471
+ ...(upstream?.type === undefined ? {} : { providerType: upstream.type }),
1472
+ ...(upstream?.incompleteReason === undefined ? {} : { incompleteReason: upstream.incompleteReason }),
1473
+ ...(upstream === undefined ? {} : { event: upstream.event }),
1474
+ contentEmitted,
1475
+ });
1476
+ }
1477
+ catch {
1478
+ // Diagnostics must never change the stream outcome.
1479
+ }
1480
+ };
1339
1481
  const effectiveTimeoutMs = timeoutMs ?? (applyDefaultTimeout ? 300_000 : undefined);
1340
1482
  const deadline = requestDeadline(signal, effectiveTimeoutMs);
1341
1483
  const watchdog = streamIdleWatchdog(deadline.signal, streamIdleTimeoutMs);
@@ -1383,7 +1525,7 @@ export async function* streamResponsesRequest({ baseURL, provider, model, piMode
1383
1525
  output.stopReason = signal?.aborted ? "aborted" : "error";
1384
1526
  output.errorMessage =
1385
1527
  error instanceof Error ? error.message : "Responses stream failed";
1386
- output.__lcxFailure = managedFailure(error, signal);
1528
+ output.__lcxFailure = managedFailure(error, signal, wireMeta.upstreamFailure);
1387
1529
  piEvents.push({
1388
1530
  type: "error",
1389
1531
  reason: /** @type {'aborted' | 'error'} */ output.stopReason,
@@ -1405,7 +1547,13 @@ export async function* streamResponsesRequest({ baseURL, provider, model, piMode
1405
1547
  break;
1406
1548
  }
1407
1549
  watchdog.disarm();
1408
- yield result.value;
1550
+ const value = result.value;
1551
+ if (value.type === "text-delta" ||
1552
+ value.type === "reasoning-delta" ||
1553
+ value.type === "tool-call-delta")
1554
+ contentEmitted = true;
1555
+ reportFailure(value, output.__lcxFailure, wireMeta.upstreamFailure);
1556
+ yield value;
1409
1557
  watchdog.arm();
1410
1558
  }
1411
1559
  }
@@ -1417,7 +1565,9 @@ export async function* streamResponsesRequest({ baseURL, provider, model, piMode
1417
1565
  await parser;
1418
1566
  }
1419
1567
  catch (error) {
1420
- yield managedFailureChunk(error, signal);
1568
+ const chunk = managedFailureChunk(error, signal);
1569
+ reportFailure(chunk, managedFailure(error, signal), undefined);
1570
+ yield chunk;
1421
1571
  }
1422
1572
  finally {
1423
1573
  watchdog.dispose();
package/lib/route.js CHANGED
@@ -3,8 +3,7 @@ import { credentialRef } from "@deepseek-ai/dsh-credentials";
3
3
  import { SessionId } from "@deepseek-ai/dsh-session";
4
4
  import "@deepseek-ai/dsh-settings";
5
5
  import { attributionHeaders, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
6
- import { getBuiltinModels, getBuiltinProviders, } from "./pi-responses-runtime.js";
7
- import { wasPi086ResponsesModel } from "./pi086-responses-allowlist.js";
6
+ import { resolveCatalogModel } from "./model-catalog.js";
8
7
  /** @param {unknown} value */
9
8
  function isRecord(value) {
10
9
  return value !== null && typeof value === "object" && !Array.isArray(value);
@@ -125,17 +124,6 @@ function copyResponsesCompat(target, source) {
125
124
  Object.assign(target, { [field]: value });
126
125
  }
127
126
  }
128
- /** @param {unknown} provider @param {unknown} modelId */
129
- function builtinResponsesModel(provider, modelId) {
130
- const providerName = String(provider ?? "");
131
- // A newer plugin-Pi catalog must not grant LCX a route that Pi 0.86 lacked.
132
- if (!wasPi086ResponsesModel(providerName, String(modelId ?? "")))
133
- return undefined;
134
- const builtinProvider = getBuiltinProviders().find((candidate) => candidate === providerName);
135
- if (builtinProvider === undefined)
136
- return undefined;
137
- return getBuiltinModels(builtinProvider).find((model) => model.id === String(modelId ?? "") && model.api === "openai-responses");
138
- }
139
127
  function modelDescriptorDefaults(model) {
140
128
  if (!model)
141
129
  return undefined;
@@ -144,6 +132,18 @@ function modelDescriptorDefaults(model) {
144
132
  thinkingLevelMap: model.thinkingLevelMap,
145
133
  };
146
134
  }
135
+ /** The profile lists this model in `models`: the one way DSH serves a model its catalog does not describe. */
136
+ function profileDeclaresModel(profile, modelId) {
137
+ return Array.isArray(profile?.models) && profile.models.some((entry) => String(entry?.id ?? "") === String(modelId));
138
+ }
139
+ /**
140
+ * A nonempty `models` list replaces the served catalog: DSH serves exactly the listed models, and LCX answers
141
+ * `llm/stream` before DSH's adapter does, so a claim here would send a request DSH itself refuses.
142
+ */
143
+ function profileExcludesModel(profile, modelId) {
144
+ return Array.isArray(profile?.models) && profile.models.length > 0 &&
145
+ !profile.models.some((entry) => String(entry?.id ?? "") === String(modelId));
146
+ }
147
147
  function configuredModelProfile(profile, modelId) {
148
148
  const configuredModels = Array.isArray(profile?.models) ? profile.models : [];
149
149
  return configuredModels.length > 0
@@ -169,34 +169,48 @@ const MODEL_THINKING_LEVELS = [
169
169
  function profileReasoning(value) {
170
170
  return MODEL_THINKING_LEVELS.find((level) => level === value);
171
171
  }
172
- function configuredModelControls(profile, modelId, base) {
173
- const configured = configuredModelProfile(profile, modelId);
174
- const efforts = configured?.reasoningEfforts;
172
+ /**
173
+ * The reasoning projection of a model whose profile entry declares `reasoningEfforts` (the mapping
174
+ * from DSH levels to wire spellings, or `false` for a non-reasoning model); undefined when the
175
+ * profile says nothing, so the caller falls back to the catalog or to what DSH resolved.
176
+ */
177
+ function declaredReasoningControls(profile, modelId) {
178
+ const efforts = configuredModelProfile(profile, modelId)?.reasoningEfforts;
175
179
  if (efforts === undefined)
176
- return {
177
- reasoning: base?.reasoning ?? false,
178
- ...(base?.thinkingLevelMap === undefined
179
- ? {}
180
- : { thinkingLevelMap: base.thinkingLevelMap }),
181
- };
180
+ return undefined;
182
181
  if (efforts === false)
183
182
  return { reasoning: false };
184
183
  if (!isRecord(efforts))
185
184
  return { reasoning: false };
186
185
  const thinkingLevelMap = {};
186
+ let offOmitsReasoning = false;
187
187
  for (const level of MODEL_THINKING_LEVELS) {
188
188
  const value = efforts[level];
189
189
  if (value === undefined)
190
190
  thinkingLevelMap[level] = null;
191
191
  else if (value === null) {
192
- // DSH permits only off:null: it means supported-off by omitting the wire option.
193
- if (level !== "off")
194
- thinkingLevelMap[level] = null;
192
+ // DSH permits only off:null: it means supported-off by omitting the wire option. Pi 1.1.0 would
193
+ // read an absent `off` as "send none", so the omission is made explicit here.
194
+ thinkingLevelMap[level] = null;
195
+ if (level === "off")
196
+ offOmitsReasoning = true;
195
197
  }
196
198
  else if (typeof value === "string")
197
199
  thinkingLevelMap[level] = value;
198
200
  }
199
- return { reasoning: true, thinkingLevelMap };
201
+ return {
202
+ reasoning: true,
203
+ thinkingLevelMap,
204
+ ...(offOmitsReasoning ? { offOmitsReasoning: true } : {}),
205
+ };
206
+ }
207
+ function configuredModelControls(profile, modelId, base) {
208
+ return (declaredReasoningControls(profile, modelId) ?? {
209
+ reasoning: base?.reasoning ?? false,
210
+ ...(base?.thinkingLevelMap === undefined
211
+ ? {}
212
+ : { thinkingLevelMap: base.thinkingLevelMap }),
213
+ });
200
214
  }
201
215
  function isLcxCapabilityRoute(provider, model) {
202
216
  return provider === "lcx" &&
@@ -213,11 +227,15 @@ export function resolveResponsesRouteConfig(ctx, options, policy) {
213
227
  if (!isRecord(profile))
214
228
  return undefined;
215
229
  const configured = profile;
216
- const builtin = builtinResponsesModel(provider, model);
217
- const api = configured.api ?? builtin?.api;
230
+ if (profileExcludesModel(configured, model))
231
+ return undefined;
232
+ // Protocol and endpoint: the profile, then what DSH resolves for the model (see `resolveCatalogModel`).
233
+ const catalog = resolveCatalogModel(provider, model, profileDeclaresModel(configured, model));
234
+ const builtin = catalog.descriptor;
235
+ const api = configured.api ?? catalog.api;
218
236
  if (api !== "openai-responses")
219
237
  return undefined;
220
- const baseURL = configured.baseURL ?? builtin?.baseUrl;
238
+ const baseURL = configured.baseURL ?? catalog.baseUrl;
221
239
  const apiKeyEnv = configured.apiKeyEnv;
222
240
  if (typeof baseURL !== "string" || !normalizeBaseURL(baseURL) || typeof apiKeyEnv !== "string" || !apiKeyEnv.trim())
223
241
  return undefined;
@@ -225,7 +243,7 @@ export function resolveResponsesRouteConfig(ctx, options, policy) {
225
243
  copyResponsesCompat(responsesCompat, builtin?.compat);
226
244
  copyResponsesCompat(responsesCompat, lcxCapabilityRoute ? policy.responsesCompat : undefined);
227
245
  copyResponsesCompat(responsesCompat, configuredResponsesCompat(configured, model));
228
- const promptCacheModel = lcxCapabilityRoute && policy.supportsExplicitPromptCacheMode === true ? builtinResponsesModel("openai", model) : undefined;
246
+ const promptCacheModel = lcxCapabilityRoute && policy.supportsExplicitPromptCacheMode === true ? resolveCatalogModel("openai", model).descriptor : undefined;
229
247
  const promptCacheRaw = promptCacheModel;
230
248
  const promptCacheCompat = isRecord(promptCacheRaw)
231
249
  ? promptCacheRaw.compat
@@ -241,6 +259,7 @@ export function resolveResponsesRouteConfig(ctx, options, policy) {
241
259
  const fallbackRetention = lcxCapabilityRoute ? policy.cacheRetention : undefined;
242
260
  const requestedRetention = configuredRetention === "none" || configuredRetention === "short" || configuredRetention === "long" ? configuredRetention : fallbackRetention === "none" || fallbackRetention === "short" || fallbackRetention === "long" ? fallbackRetention : undefined;
243
261
  const cacheRetention = requestedRetention === "long" && !supportsLongCacheRetention ? "short" : requestedRetention ?? (supportsLongCacheRetention ? "long" : "short");
262
+ const declaredControls = declaredReasoningControls(configured, model);
244
263
  return {
245
264
  provider,
246
265
  model,
@@ -251,6 +270,9 @@ export function resolveResponsesRouteConfig(ctx, options, policy) {
251
270
  cacheRetention,
252
271
  supportsLongCacheRetention,
253
272
  responsesCompat,
273
+ // Only a declared `reasoningEfforts` is projected here; an undeclared model follows the catalog
274
+ // and what DSH resolved for it (see `gptModelOverride`).
275
+ ...(declaredControls === undefined ? {} : { modelControls: declaredControls }),
254
276
  // These are explicitly LCX-owned transport and request-capability policies.
255
277
  timeoutMs: isPositiveInteger(configured.timeoutMs) ? configured.timeoutMs : policy.timeoutMs,
256
278
  maxAttempts: retryAttempts(configured.retryPolicy, policy.maxAttempts),
@@ -259,6 +281,23 @@ export function resolveResponsesRouteConfig(ctx, options, policy) {
259
281
  requestImageMaxBytes: isPositiveInteger(configured.requestImageMaxBytes) ? configured.requestImageMaxBytes : policy.requestImageMaxBytes,
260
282
  };
261
283
  }
284
+ /**
285
+ * Name the reason `resolveResponsesRouteConfig` returned nothing, so the failure can tell the user what to
286
+ * change: `api-unresolved` means neither the profile nor the model catalog names a protocol for this model.
287
+ */
288
+ export function diagnoseResponsesRoute(ctx, options) {
289
+ const provider = String(options?.provider ?? "");
290
+ const model = String(options?.model ?? "");
291
+ const profile = provider.trim() ? configuredProviderProfile(ctx, provider) : undefined;
292
+ if (!isRecord(profile))
293
+ return "no-profile";
294
+ if (profileExcludesModel(profile, model))
295
+ return "model-not-configured";
296
+ const api = profile.api ?? resolveCatalogModel(provider, model, profileDeclaresModel(profile, model)).api;
297
+ if (api === undefined)
298
+ return "api-unresolved";
299
+ return api === "openai-responses" ? "incomplete" : "api-not-responses";
300
+ }
262
301
  /** Resolve a Grok-prefixed model through its selected DSH Responses profile. */
263
302
  export function resolveGrokResponsesRouteConfig(ctx, options, policy) {
264
303
  const provider = String(options?.provider ?? "");
@@ -268,11 +307,14 @@ export function resolveGrokResponsesRouteConfig(ctx, options, policy) {
268
307
  const configured = configuredProviderProfile(ctx, provider);
269
308
  if (!isRecord(configured))
270
309
  return undefined;
271
- const selectedBuiltin = builtinResponsesModel(provider, model);
272
- const api = configured.api ?? selectedBuiltin?.api;
310
+ if (profileExcludesModel(configured, model))
311
+ return undefined;
312
+ const catalog = resolveCatalogModel(provider, model, profileDeclaresModel(configured, model));
313
+ const selectedBuiltin = catalog.descriptor;
314
+ const api = configured.api ?? catalog.api;
273
315
  if (api !== "openai-responses")
274
316
  return undefined;
275
- const baseURL = configured.baseURL ?? selectedBuiltin?.baseUrl;
317
+ const baseURL = configured.baseURL ?? catalog.baseUrl;
276
318
  const apiKeyEnv = configured.apiKeyEnv;
277
319
  if (typeof baseURL !== "string" ||
278
320
  !normalizeBaseURL(baseURL) ||
@@ -10,15 +10,22 @@ export const searchUsageProjection = {
10
10
  key: 'lcxSearchUsage', stateVersion: 3, stateSchema: schema.extend({ pending: z.record(z.string(), z.string()), headerKey: z.string().optional(), sampleHeaderKey: z.string().optional() }),
11
11
  init: () => ({ auxiliary: zeroBuckets(), aggregateContext: false, pending: {} }),
12
12
  apply(state, event) {
13
- if (event.type === 'request/header')
14
- return { ...state, headerKey: headerKey(event.data.header) };
13
+ // Unit state is checkpointed by the host's projection cache, which refuses any state that is not
14
+ // lossless plain JSON. An optional field is therefore omitted when absent, never set to `undefined`.
15
+ if (event.type === 'request/header') {
16
+ const { headerKey: _previous, ...rest } = state;
17
+ const key = headerKey(event.data.header);
18
+ return key === undefined ? rest : { ...rest, headerKey: key };
19
+ }
15
20
  // DSH measure anchors assistant/message only. Attempts must not transplant a
16
21
  // newer context sample onto an older successful measurement anchor.
17
22
  if (event.type === 'assistant/message' || event.type === 'assistant/attempt') {
18
23
  const contextDetails = event.type === 'assistant/message' ? providerContextOf(event) : undefined;
19
- return { ...state, aggregateContext: aggregateContextOf(event) ?? state.aggregateContext, contextDetails,
20
- contextProvenance: contextDetails ? 'provider-context-details' : undefined,
21
- sampleHeaderKey: contextDetails ? state.headerKey : undefined };
24
+ // The newest reply replaces the whole provider-context sample: drop the old keys, then add the new ones.
25
+ const { contextDetails: _details, contextProvenance: _provenance, sampleHeaderKey: _sample, ...rest } = state;
26
+ return { ...rest, aggregateContext: aggregateContextOf(event) ?? state.aggregateContext,
27
+ ...(contextDetails ? { contextDetails, contextProvenance: 'provider-context-details',
28
+ ...(state.headerKey === undefined ? {} : { sampleHeaderKey: state.headerKey }) } : {}) };
22
29
  }
23
30
  if (event.type === 'tool/call' && isSearchTool(event.data.name))
24
31
  return { ...state, pending: { ...state.pending, [event.data.callId]: event.data.name } };
package/lib/transport.js CHANGED
@@ -279,10 +279,17 @@ export async function consumeSse(response, onEvent, options = {}) {
279
279
  }
280
280
  onEvent(event);
281
281
  };
282
+ // An abort must interrupt a read that never settles, not only be noticed between reads. Cancelling
283
+ // the reader settles the pending read as done, so the abort is re-checked right after every read.
284
+ const onAbort = () => {
285
+ reader.cancel(options.signal?.reason).catch(() => { });
286
+ };
287
+ options.signal?.addEventListener("abort", onAbort, { once: true });
282
288
  try {
283
289
  while (true) {
284
290
  abortIfNeeded(options.signal);
285
291
  const { done, value } = await reader.read();
292
+ abortIfNeeded(options.signal);
286
293
  if (done)
287
294
  break;
288
295
  bytes += value.byteLength;
@@ -305,6 +312,7 @@ export async function consumeSse(response, onEvent, options = {}) {
305
312
  dispatch();
306
313
  }
307
314
  finally {
315
+ options.signal?.removeEventListener("abort", onAbort);
308
316
  try {
309
317
  await reader.cancel();
310
318
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lcx-codex",
3
- "version": "0.5.1-pre.1",
3
+ "version": "0.5.2",
4
4
  "description": "Model-scoped DSH plugin: GPT Responses lifecycle, Native V2 compaction and Hosted/Alpha Search; Grok native Web/X Search",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -62,9 +62,9 @@
62
62
  }
63
63
  },
64
64
  "devDependencies": {
65
- "@deepseek-ai/dsh": "0.2.1-alpha.2",
65
+ "@deepseek-ai/dsh": "0.2.0-rc.2",
66
66
  "@earendil-works/pi-ai": "0.87.1",
67
- "@deepseek-ai/schemastery": "~3.18.5-alpha.1",
67
+ "@deepseek-ai/schemastery": "^3.18.2",
68
68
  "@types/node": "^22.20.0",
69
69
  "@types/react": "~18.3.1",
70
70
  "esbuild": "^0.28.2",
@@ -72,31 +72,31 @@
72
72
  "typescript": "7.0.2"
73
73
  },
74
74
  "peerDependencies": {
75
- "@deepseek-ai/cordis": ">=4.0.5-alpha.1",
76
- "@deepseek-ai/cordis-plugin-loader": ">=1.0.6-alpha.1",
77
- "@deepseek-ai/dsh-agent": ">=0.2.1-alpha.2",
78
- "@deepseek-ai/dsh-attachment": ">=0.2.1-alpha.2",
79
- "@deepseek-ai/dsh-client-locale": ">=0.2.1-alpha.2",
80
- "@deepseek-ai/dsh-client-modules": ">=0.2.1-alpha.2",
81
- "@deepseek-ai/dsh-client-store": ">=0.2.1-alpha.2",
82
- "@deepseek-ai/dsh-client-ui-chat": ">=0.2.1-alpha.2",
83
- "@deepseek-ai/dsh-client-ui-conversation": ">=0.2.1-alpha.2",
84
- "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.1-alpha.2",
85
- "@deepseek-ai/dsh-client-ui-settings": ">=0.2.1-alpha.2",
86
- "@deepseek-ai/dsh-compaction": ">=0.2.1-alpha.2",
87
- "@deepseek-ai/dsh-credentials": ">=0.2.1-alpha.2",
88
- "@deepseek-ai/dsh-fs": ">=0.2.1-alpha.2",
89
- "@deepseek-ai/dsh-llm": ">=0.2.1-alpha.2",
90
- "@deepseek-ai/dsh-session": ">=0.2.1-alpha.2",
91
- "@deepseek-ai/dsh-session-query": ">=0.2.1-alpha.2",
92
- "@deepseek-ai/dsh-settings": ">=0.2.1-alpha.2",
93
- "@deepseek-ai/dsh-tool-web": ">=0.2.1-alpha.2",
94
- "@deepseek-ai/dsh-tools": ">=0.2.1-alpha.2",
95
- "@deepseek-ai/dsh-web": ">=0.2.1-alpha.2",
96
- "@deepseek-ai/schemastery": ">=3.18.5-alpha.1",
75
+ "@deepseek-ai/cordis": "^4.0.2",
76
+ "@deepseek-ai/cordis-plugin-loader": "~1.0.5",
77
+ "@deepseek-ai/dsh-agent": ">=0.2.0-rc.2 <0.2.1",
78
+ "@deepseek-ai/dsh-attachment": ">=0.2.0-rc.2 <0.2.1",
79
+ "@deepseek-ai/dsh-client-locale": ">=0.2.0-rc.2 <0.2.1",
80
+ "@deepseek-ai/dsh-client-modules": ">=0.2.0-rc.2 <0.2.1",
81
+ "@deepseek-ai/dsh-client-store": ">=0.2.0-rc.2 <0.2.1",
82
+ "@deepseek-ai/dsh-client-ui-chat": ">=0.2.0-rc.2 <0.2.1",
83
+ "@deepseek-ai/dsh-client-ui-conversation": ">=0.2.0-rc.2 <0.2.1",
84
+ "@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.0-rc.2 <0.2.1",
85
+ "@deepseek-ai/dsh-client-ui-settings": ">=0.2.0-rc.2 <0.2.1",
86
+ "@deepseek-ai/dsh-compaction": ">=0.2.0-rc.2 <0.2.1",
87
+ "@deepseek-ai/dsh-credentials": ">=0.2.0-rc.2 <0.2.1",
88
+ "@deepseek-ai/dsh-fs": ">=0.2.0-rc.2 <0.2.1",
89
+ "@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.2.1",
90
+ "@deepseek-ai/dsh-session": ">=0.2.0-rc.2 <0.2.1",
91
+ "@deepseek-ai/dsh-session-query": ">=0.2.0-rc.2 <0.2.1",
92
+ "@deepseek-ai/dsh-settings": ">=0.2.0-rc.2 <0.2.1",
93
+ "@deepseek-ai/dsh-tool-web": ">=0.2.0-rc.2 <0.2.1",
94
+ "@deepseek-ai/dsh-tools": ">=0.2.0-rc.2 <0.2.1",
95
+ "@deepseek-ai/dsh-web": ">=0.2.0-rc.2 <0.2.1",
96
+ "@deepseek-ai/schemastery": "^3.18.2",
97
97
  "react": "^18.2.0",
98
- "@deepseek-ai/dsh-token-meter": ">=0.2.1-alpha.2",
99
- "@deepseek-ai/dsh-session-projection": ">=0.2.1-alpha.2",
98
+ "@deepseek-ai/dsh-token-meter": ">=0.2.0-rc.2 <0.2.1",
99
+ "@deepseek-ai/dsh-session-projection": ">=0.2.0-rc.2 <0.2.1",
100
100
  "zod": "^4.5.4"
101
101
  },
102
102
  "peerDependenciesMeta": {
@@ -179,9 +179,9 @@
179
179
  },
180
180
  "license": "MIT",
181
181
  "lcxCompatibility": {
182
- "dshInstallRange": ">=0.2.1-alpha.2",
183
- "verifiedDsh": "0.2.1-alpha.2",
184
- "verifiedHostPi": "1.1.0",
182
+ "dshInstallRange": ">=0.2.0-rc.2 <0.2.1",
183
+ "verifiedDsh": "0.2.0-rc.2",
184
+ "verifiedHostPi": "0.87.1",
185
185
  "verifiedPluginPi": "0.87.1"
186
186
  }
187
187
  }