dsh-lcx-codex 0.6.0-pre.2 → 0.7.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -24
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/lib/dsh-compat.js +5 -5
- package/lib/dsh-responses.js +132 -60
- package/lib/index.js +101 -101
- package/lib/native-checkpoint.js +3 -2
- package/lib/pi-responses-runtime.js +621 -131
- package/lib/responses-request.js +26 -3
- package/lib/responses-stream.js +19 -2
- package/lib/route.js +41 -8
- package/lib/search-usage.js +15 -7
- package/lib/tool-surface.js +4 -7
- package/package.json +41 -33
package/lib/responses-request.js
CHANGED
|
@@ -2,6 +2,8 @@ import { clampOpenAIPromptCacheKey } from "./pi-responses-runtime.js";
|
|
|
2
2
|
import { responsesTools } from "./dsh-responses.js";
|
|
3
3
|
import { isRecord } from "./util.js";
|
|
4
4
|
const OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
5
|
+
/** Pi's fixed request effort while the real one travels in `configuration_update` input items. */
|
|
6
|
+
const CONFIGURATION_UPDATE_REQUEST_EFFORT = "medium";
|
|
5
7
|
function modelId(model) {
|
|
6
8
|
return typeof model === "string" ? model : model.id;
|
|
7
9
|
}
|
|
@@ -20,10 +22,28 @@ function normalizeCacheRetention(value) {
|
|
|
20
22
|
? normalized
|
|
21
23
|
: "short";
|
|
22
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The effort Pi 1.3.0 sends as `configuration_update` input items instead of `reasoning.effort`, or undefined
|
|
27
|
+
* to send it as `reasoning.effort` (Pi's `getConfigurationUpdateEffort`): only for a model whose compat states
|
|
28
|
+
* `supportsMidConvoEffort`, only with a requested level, and never for a Sign in with ChatGPT key, which rejects
|
|
29
|
+
* those items. The key is read only when that last rule can apply.
|
|
30
|
+
*/
|
|
31
|
+
export async function configurationUpdateEffort(model, reasoningEffort, apiKey) {
|
|
32
|
+
if (model.compat?.supportsMidConvoEffort !== true || reasoningEffort === undefined || reasoningEffort === "off")
|
|
33
|
+
return undefined;
|
|
34
|
+
const requested = String(reasoningEffort);
|
|
35
|
+
const mapped = model.thinkingLevelMap?.[requested];
|
|
36
|
+
// A level the model maps to null is unsupported; DSH refuses it before dispatch, so it never travels here.
|
|
37
|
+
if (mapped === null)
|
|
38
|
+
return undefined;
|
|
39
|
+
if (model.provider === "openai" && model.baseUrl === "https://api.openai.com/v1" && !(await apiKey()).startsWith("sk-"))
|
|
40
|
+
return undefined;
|
|
41
|
+
return mapped ?? requested;
|
|
42
|
+
}
|
|
23
43
|
/**
|
|
24
44
|
* Pi-parity generation controls for OpenAI Responses.
|
|
25
45
|
*/
|
|
26
|
-
export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort, temperature, maxTokens, includeDefaultReasoning = false, } = {}) {
|
|
46
|
+
export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort, temperature, maxTokens, configurationUpdateEffort, includeDefaultReasoning = false, } = {}) {
|
|
27
47
|
const descriptor = modelRecord(model);
|
|
28
48
|
const result = {};
|
|
29
49
|
if (descriptor.reasoning !== false) {
|
|
@@ -37,7 +57,9 @@ export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort
|
|
|
37
57
|
const mapped = descriptor.thinkingLevelMap?.[requested];
|
|
38
58
|
const wire = mapped === undefined ? requested : mapped;
|
|
39
59
|
if (wire !== null) {
|
|
40
|
-
|
|
60
|
+
// With mid-conversation effort the request carries a fixed effort, so an effort change keeps the
|
|
61
|
+
// cached prefix; the level itself is the last `configuration_update` input item.
|
|
62
|
+
result.reasoning = { effort: configurationUpdateEffort === undefined ? wire : CONFIGURATION_UPDATE_REQUEST_EFFORT, summary: "auto" };
|
|
41
63
|
result.include = ["reasoning.encrypted_content"];
|
|
42
64
|
}
|
|
43
65
|
}
|
|
@@ -66,7 +88,7 @@ export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort
|
|
|
66
88
|
* Build the shared LCX-owned request envelope while retaining Pi 0.86.0 Responses semantics.
|
|
67
89
|
* Production LCX ordinary/compact/replay construction places the DSH system prompt in canonical input.
|
|
68
90
|
*/
|
|
69
|
-
export function buildResponsesBody({ model, input, tools, sessionId, promptCacheKey, promptCacheRetention, cacheRetention, reasoningEffort, temperature, maxTokens, samplingParams, }) {
|
|
91
|
+
export function buildResponsesBody({ model, input, tools, sessionId, promptCacheKey, promptCacheRetention, cacheRetention, reasoningEffort, temperature, maxTokens, configurationUpdateEffort, samplingParams, }) {
|
|
70
92
|
if (!Array.isArray(input))
|
|
71
93
|
throw Object.assign(new Error("Responses input must be an array"), {
|
|
72
94
|
code: "LCX_RESPONSES_INVALID_INPUT",
|
|
@@ -105,6 +127,7 @@ export function buildResponsesBody({ model, input, tools, sessionId, promptCache
|
|
|
105
127
|
reasoningEffort,
|
|
106
128
|
temperature,
|
|
107
129
|
maxTokens,
|
|
130
|
+
configurationUpdateEffort,
|
|
108
131
|
includeDefaultReasoning: true,
|
|
109
132
|
}),
|
|
110
133
|
};
|
package/lib/responses-stream.js
CHANGED
|
@@ -183,7 +183,11 @@ export function managedFailure(error, signal, upstream) {
|
|
|
183
183
|
/time(?:d)?\s*out|timeout/iu.test(String(signalReason?.message ?? "")));
|
|
184
184
|
const upstreamClass = signal?.aborted ? undefined : classifyUpstreamFailure(upstream);
|
|
185
185
|
let code = "RESPONSES_ERROR";
|
|
186
|
-
if (
|
|
186
|
+
if (sourceCodes.has("REQUEST_HEADERS"))
|
|
187
|
+
code = "REQUEST_HEADERS";
|
|
188
|
+
else if (sourceCodes.has("MALFORMED_RESPONSE"))
|
|
189
|
+
code = "MALFORMED_RESPONSE";
|
|
190
|
+
else if (upstreamClass?.definite === true)
|
|
187
191
|
code = upstreamClass.code;
|
|
188
192
|
else if (signalTimedOut ||
|
|
189
193
|
facts.status === 408 ||
|
|
@@ -246,6 +250,8 @@ export function managedFailure(error, signal, upstream) {
|
|
|
246
250
|
if (code === "RESPONSES_ERROR" && upstreamClass !== undefined)
|
|
247
251
|
code = upstreamClass.code;
|
|
248
252
|
const messages = {
|
|
253
|
+
MALFORMED_RESPONSE: "Responses provider completed a tool call with malformed arguments",
|
|
254
|
+
REQUEST_HEADERS: error instanceof Error ? error.message : "Request header preparation failed",
|
|
249
255
|
ABORTED: "Responses request was aborted",
|
|
250
256
|
AUTH: "Responses request was rejected by authentication",
|
|
251
257
|
INSUFFICIENT_QUOTA: "服务商额度不足或未满足请求预留额度,请检查中转额度(并非 API 密钥无效) / Provider quota is insufficient for this request",
|
|
@@ -1138,6 +1144,9 @@ function replayState(message, nativeOutput, nativeReplayRoute, nativeServerSearc
|
|
|
1138
1144
|
...(typeof message.responseId === "string"
|
|
1139
1145
|
? { responseId: message.responseId }
|
|
1140
1146
|
: {}),
|
|
1147
|
+
...(typeof message.providerThinkingLevel === "string"
|
|
1148
|
+
? { providerThinkingLevel: message.providerThinkingLevel }
|
|
1149
|
+
: {}),
|
|
1141
1150
|
stopReason: message.stopReason,
|
|
1142
1151
|
},
|
|
1143
1152
|
blocks: content.map((block) => {
|
|
@@ -1197,6 +1206,7 @@ function successfulFinish(message) {
|
|
|
1197
1206
|
*/
|
|
1198
1207
|
async function* toDshChunks(events, signal, wireMeta, nativeReplayRoute) {
|
|
1199
1208
|
const toolIds = new Map();
|
|
1209
|
+
let argumentsError = false;
|
|
1200
1210
|
for await (const event of events) {
|
|
1201
1211
|
switch (event.type) {
|
|
1202
1212
|
case "start":
|
|
@@ -1279,6 +1289,10 @@ async function* toDshChunks(events, signal, wireMeta, nativeReplayRoute) {
|
|
|
1279
1289
|
const call = isRecord(event.toolCall)
|
|
1280
1290
|
? event.toolCall
|
|
1281
1291
|
: {};
|
|
1292
|
+
if (call.argumentsError !== undefined) {
|
|
1293
|
+
argumentsError = true;
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1282
1296
|
yield {
|
|
1283
1297
|
type: "block-end",
|
|
1284
1298
|
index: Number(event.contentIndex),
|
|
@@ -1296,6 +1310,8 @@ async function* toDshChunks(events, signal, wireMeta, nativeReplayRoute) {
|
|
|
1296
1310
|
? event.message
|
|
1297
1311
|
: {};
|
|
1298
1312
|
yield { type: "usage", usage: dshUsage(message.usage) };
|
|
1313
|
+
if (argumentsError && message.stopReason !== "length")
|
|
1314
|
+
throw codedError("Responses provider completed a tool call with malformed arguments", "MALFORMED_RESPONSE");
|
|
1299
1315
|
const reason = successfulFinish(message);
|
|
1300
1316
|
const replay = reason.kind === "error"
|
|
1301
1317
|
? undefined
|
|
@@ -1349,7 +1365,7 @@ async function* toDshChunks(events, signal, wireMeta, nativeReplayRoute) {
|
|
|
1349
1365
|
* Send one LCX-owned OpenAI Responses request. Ordinary and replay use one provider attempt;
|
|
1350
1366
|
* the DSH agent recovery layer remains the visible retry owner.
|
|
1351
1367
|
*/
|
|
1352
|
-
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, }) {
|
|
1368
|
+
export async function* streamResponsesRequest({ baseURL, provider, model, piModel, body, grammarToolInputProperties, headers, signal, timeoutMs, applyDefaultTimeout = true, streamIdleTimeoutMs, maxAttempts = 1, maxResponseBytes, serverToolTypes, isServerToolItem, declaredToolNames, nativeReplayRoute, providerThinkingLevel, onServerToolUsage, onFailure, }) {
|
|
1353
1369
|
let contentEmitted = false;
|
|
1354
1370
|
let failureReported = false;
|
|
1355
1371
|
/** One redacted report per request; user aborts are not failures. */
|
|
@@ -1390,6 +1406,7 @@ export async function* streamResponsesRequest({ baseURL, provider, model, piMode
|
|
|
1390
1406
|
api: "openai-responses",
|
|
1391
1407
|
provider,
|
|
1392
1408
|
model,
|
|
1409
|
+
...(providerThinkingLevel === undefined ? {} : { providerThinkingLevel }),
|
|
1393
1410
|
usage: emptyUsage(),
|
|
1394
1411
|
stopReason: "pending",
|
|
1395
1412
|
timestamp: Date.now(),
|
package/lib/route.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
3
3
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
4
4
|
import "@deepseek-ai/dsh-settings";
|
|
5
|
-
import { assertUsableApiKey, attributionHeaders, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import { assertUsableApiKey, attributionHeaders, LlmError, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
6
6
|
import { resolveCatalogModel } from "./model-catalog.js";
|
|
7
7
|
import { clampOpenAIPromptCacheKey } from "./pi-responses-runtime.js";
|
|
8
8
|
import { providerSessionHeaders } from "./provider-headers.js";
|
|
@@ -274,7 +274,7 @@ function declaredReasoningControls(profile, modelId) {
|
|
|
274
274
|
if (value === undefined)
|
|
275
275
|
thinkingLevelMap[level] = null;
|
|
276
276
|
else if (value === null) {
|
|
277
|
-
// DSH permits only off:null: it means supported-off by omitting the wire option. Pi 1.
|
|
277
|
+
// DSH permits only off:null: it means supported-off by omitting the wire option. Pi (1.3.0) would
|
|
278
278
|
// read an absent `off` as "send none", so the omission is made explicit here.
|
|
279
279
|
thinkingLevelMap[level] = null;
|
|
280
280
|
if (level === "off")
|
|
@@ -362,6 +362,8 @@ export function resolveResponsesRouteConfig(ctx, options, policy, assumeHostServ
|
|
|
362
362
|
// These are explicitly LCX-owned transport and request-capability policies.
|
|
363
363
|
timeoutMs: isPositiveSafeInteger(configured.timeoutMs) ? configured.timeoutMs : policy.timeoutMs,
|
|
364
364
|
maxAttempts: retryAttempts(configured.retryPolicy, policy.maxAttempts),
|
|
365
|
+
maxRequestImages: isPositiveSafeInteger(configured.maxRequestImages) ? configured.maxRequestImages : 50,
|
|
366
|
+
imageOffloadCountQuantum: isPositiveSafeInteger(configured.imageOffloadCountQuantum) ? configured.imageOffloadCountQuantum : Math.min(10, isPositiveSafeInteger(configured.maxRequestImages) ? configured.maxRequestImages : 50),
|
|
365
367
|
maxRequestImageBytes: isPositiveSafeInteger(configured.maxRequestImageBytes) ? configured.maxRequestImageBytes : policy.maxRequestImageBytes,
|
|
366
368
|
requestImagePixelBudget: isPositiveSafeInteger(configured.requestImagePixelBudget) ? configured.requestImagePixelBudget : policy.requestImagePixelBudget,
|
|
367
369
|
requestImageMaxBytes: isPositiveSafeInteger(configured.requestImageMaxBytes) ? configured.requestImageMaxBytes : policy.requestImageMaxBytes,
|
|
@@ -446,6 +448,8 @@ export function resolveGrokResponsesRouteConfig(ctx, options, policy) {
|
|
|
446
448
|
? configured.streamIdleTimeoutMs
|
|
447
449
|
: DEFAULTS.streamIdleTimeoutMs,
|
|
448
450
|
maxAttempts: retryAttempts(configured.retryPolicy, policy.maxAttempts),
|
|
451
|
+
maxRequestImages: isPositiveSafeInteger(configured.maxRequestImages) ? configured.maxRequestImages : 50,
|
|
452
|
+
imageOffloadCountQuantum: isPositiveSafeInteger(configured.imageOffloadCountQuantum) ? configured.imageOffloadCountQuantum : Math.min(10, isPositiveSafeInteger(configured.maxRequestImages) ? configured.maxRequestImages : 50),
|
|
449
453
|
maxRequestImageBytes: isPositiveSafeInteger(configured.maxRequestImageBytes)
|
|
450
454
|
? configured.maxRequestImageBytes
|
|
451
455
|
: policy.maxRequestImageBytes,
|
|
@@ -503,18 +507,44 @@ function sessionAffinityFormat(config) {
|
|
|
503
507
|
? "openrouter"
|
|
504
508
|
: "openai";
|
|
505
509
|
}
|
|
510
|
+
/** Headers whose owners (credentials, session affinity, correlation) layer them after the contributors. */
|
|
511
|
+
const OWNER_PROTECTED_HEADERS = new Set(["authorization", "session_id", "session-id", "x-session-id", "x-client-request-id", "x-opencode-session"]);
|
|
512
|
+
/** The host exposes profile headers only. Credential and routing headers are layered by their owners later. */
|
|
513
|
+
export function prepareRequestHeaders(ctx, config, options = {}) {
|
|
514
|
+
try {
|
|
515
|
+
const initial = new Headers(config.headers);
|
|
516
|
+
const request = Object.freeze({ provider: config.provider, model: config.model, baseURL: config.baseURL,
|
|
517
|
+
...(options.sessionId === undefined ? {} : { sessionId: options.sessionId }),
|
|
518
|
+
...(options.purpose === undefined ? {} : { purpose: options.purpose }) });
|
|
519
|
+
const waterfall = ctx?.waterfall;
|
|
520
|
+
const headers = waterfall === undefined ? initial : waterfall.call(ctx, "llm-pi-ai/request-headers", request, initial, () => initial);
|
|
521
|
+
for (const [name, value] of Object.entries(attributionHeaders()))
|
|
522
|
+
headers.set(name, value);
|
|
523
|
+
return Object.fromEntries(headers);
|
|
524
|
+
}
|
|
525
|
+
catch (error) {
|
|
526
|
+
const diagnostic = error instanceof TypeError
|
|
527
|
+
? "TypeError during header preparation; check the contributing plugin's header names, values, and configuration"
|
|
528
|
+
: error instanceof Error ? error.message : "the contributing plugin threw a non-Error value; throw an Error with a safe diagnostic";
|
|
529
|
+
throw new LlmError(`pi-ai request header preparation failed for provider "${config.provider}": ${diagnostic}`, "REQUEST_HEADERS", { cause: error });
|
|
530
|
+
}
|
|
531
|
+
}
|
|
506
532
|
/**
|
|
507
533
|
* The headers of one GPT request. `sessionId` is the prompt-cache / affinity session (the root session for a
|
|
508
534
|
* subagent, absent without cache retention); `providerSessionId` is the CURRENT DSH session, which is what Pi's
|
|
509
535
|
* client sends in provider routing headers (`x-opencode-session`) whatever the cache policy is.
|
|
510
536
|
*/
|
|
511
|
-
export async function authenticatedHeaders(ctx, config, sessionId, requestId, dynamicHeaders = {}, providerSessionId) {
|
|
537
|
+
export async function authenticatedHeaders(ctx, config, sessionId, requestId, dynamicHeaders = {}, providerSessionId, request) {
|
|
512
538
|
const explicit = { ...(config.headers ?? {}) };
|
|
539
|
+
const currentSessionId = providerSessionId ?? (sessionId ? String(sessionId) : undefined);
|
|
540
|
+
// As on the host, the credential is resolved before contributors run: a missing one never reaches them.
|
|
541
|
+
const apiKey = await resolveApiKey(ctx, config);
|
|
542
|
+
const prepared = prepareRequestHeaders(ctx, config, request ?? (currentSessionId === undefined ? {} : { sessionId: currentSessionId }));
|
|
513
543
|
const sid = sessionId ? String(sessionId) : undefined;
|
|
514
544
|
const format = sessionAffinityFormat(config);
|
|
515
|
-
//
|
|
516
|
-
//
|
|
517
|
-
const headers = layerHeaders(config.catalogHeaders,
|
|
545
|
+
// Model/provider defaults precede the contributed profile layer. Credentials and session routing
|
|
546
|
+
// are owned by their later layers; attribution is re-applied last.
|
|
547
|
+
const headers = layerHeaders(config.catalogHeaders, dynamicHeaders, prepared, { authorization: `Bearer ${apiKey}` }, providerSessionHeaders(config.provider, providerSessionId ?? sid));
|
|
518
548
|
if (sid && !hasExplicitSessionAffinity(explicit)) {
|
|
519
549
|
if (format === "openai")
|
|
520
550
|
headers.session_id = sid;
|
|
@@ -526,8 +556,11 @@ export async function authenticatedHeaders(ctx, config, sessionId, requestId, dy
|
|
|
526
556
|
if (correlation)
|
|
527
557
|
headers["x-client-request-id"] = correlation;
|
|
528
558
|
}
|
|
529
|
-
//
|
|
530
|
-
|
|
559
|
+
// Ordinary profile headers keep whatever the contributors made of them. The owner-protected ones (credential,
|
|
560
|
+
// session affinity, correlation) are the profile's to set over every default and never a contributor's.
|
|
561
|
+
// Attribution is re-applied last, as on the host.
|
|
562
|
+
const protectedProfile = Object.fromEntries(Object.entries(explicit).filter(([name]) => OWNER_PROTECTED_HEADERS.has(name.toLowerCase())));
|
|
563
|
+
return layerHeaders(headers, protectedProfile, attributionHeaders());
|
|
531
564
|
}
|
|
532
565
|
/** Grok mirrors Pi createClient ordering without changing accepted GPT headers. */
|
|
533
566
|
export async function authenticatedGrokHeaders(ctx, config, sessionId, dynamicHeaders = {}, providerSessionId) {
|
package/lib/search-usage.js
CHANGED
|
@@ -4,10 +4,16 @@ import { addUsage, aggregateContextOf, auxiliaryUsageOf, isSearchTool, providerC
|
|
|
4
4
|
const n = z.number().int().nonnegative();
|
|
5
5
|
const schema = z.object({ auxiliary: z.object({ uncachedInputTokens: n, outputTokens: n, cacheReadTokens: n, cacheWriteTokens: n }).strict(), aggregateContext: z.boolean(),
|
|
6
6
|
contextDetails: z.object({ input_tokens: n, output_tokens: n }).strict().optional(), contextProvenance: z.literal('provider-context-details').optional() }).strict();
|
|
7
|
+
const stateSchema = schema.extend({ pending: z.record(z.string(), z.string()), headerKey: z.string().optional(), sampleHeaderKey: z.string().optional() });
|
|
8
|
+
// DSH (since 0.2.1-alpha.5) pins its own zod, which need not be the one this plugin resolves, and TypeScript
|
|
9
|
+
// cannot relate schemas of two zod copies. The host only calls `parse` on them, so they are checked against
|
|
10
|
+
// the plugin's zod here and handed to the host typed by its own contract.
|
|
11
|
+
const hostStateSchema = stateSchema;
|
|
12
|
+
const hostViewSchema = schema;
|
|
7
13
|
const headerKey = (header) => header === undefined ? undefined : JSON.stringify(canonicalHeader(header));
|
|
8
14
|
/** Separate, durable extension: the host's own usage projection remains primary-call billing. */
|
|
9
15
|
export const searchUsageProjection = {
|
|
10
|
-
key: 'lcxSearchUsage', stateVersion: 3, stateSchema:
|
|
16
|
+
key: 'lcxSearchUsage', stateVersion: 3, stateSchema: hostStateSchema,
|
|
11
17
|
init: () => ({ auxiliary: zeroBuckets(), aggregateContext: false, pending: {} }),
|
|
12
18
|
apply(state, event) {
|
|
13
19
|
// Unit state is checkpointed by the host's projection cache, which refuses any state that is not
|
|
@@ -41,11 +47,11 @@ export const searchUsageProjection = {
|
|
|
41
47
|
return { ...state, auxiliary, aggregateContext, pending: {} };
|
|
42
48
|
return auxiliary === state.auxiliary && aggregateContext === state.aggregateContext ? state : { ...state, auxiliary, aggregateContext };
|
|
43
49
|
},
|
|
44
|
-
wire: { viewSchema:
|
|
50
|
+
wire: { viewSchema: hostViewSchema, view: ({ auxiliary, aggregateContext, contextDetails, contextProvenance }) => ({ auxiliary, aggregateContext, ...(contextDetails ? { contextDetails, contextProvenance } : {}) }) },
|
|
45
51
|
};
|
|
46
52
|
const installed = new WeakMap();
|
|
47
53
|
/** Own a reversible adapter on the public measure method, never a DSH file or private fold. */
|
|
48
|
-
export function installSearchMeasurement(meter,
|
|
54
|
+
export function installSearchMeasurement(meter, projection) {
|
|
49
55
|
const existing = installed.get(meter);
|
|
50
56
|
if (existing) {
|
|
51
57
|
existing.refs++;
|
|
@@ -58,7 +64,7 @@ export function installSearchMeasurement(meter, projections) {
|
|
|
58
64
|
const original = meter.measure, descriptor = Object.getOwnPropertyDescriptor(meter, 'measure');
|
|
59
65
|
function measure(session, header) {
|
|
60
66
|
const value = original.call(this, session, header);
|
|
61
|
-
const state =
|
|
67
|
+
const state = projection.stateOf(session);
|
|
62
68
|
if (!state?.aggregateContext)
|
|
63
69
|
return value;
|
|
64
70
|
const effectiveHeader = header ?? session.requestHeader();
|
|
@@ -100,8 +106,10 @@ function release(meter) {
|
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
export function installSearchUsage(ctx) {
|
|
103
|
-
ctx.inject(['sessionProjections'], c => {
|
|
104
|
-
|
|
105
|
-
c.
|
|
109
|
+
ctx.inject(['sessionProjections'], async (c) => {
|
|
110
|
+
const handle = await c.sessionProjections.register(searchUsageProjection);
|
|
111
|
+
c.inject(['tokenMeter'], c => {
|
|
112
|
+
c.effect(() => installSearchMeasurement(c.tokenMeter, handle), 'lcx search context measurement');
|
|
113
|
+
});
|
|
106
114
|
});
|
|
107
115
|
}
|
package/lib/tool-surface.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getResponsesToolSupport } from "./pi-responses-runtime.js";
|
|
1
2
|
import { projectToolUpdates } from "@deepseek-ai/dsh-llm";
|
|
2
3
|
export const DEFAULT_TOOL_UPDATES = "addition-only";
|
|
3
4
|
/** Reason used when the route compat explicitly declines both declaration kinds; a deliberate configuration. */
|
|
@@ -12,11 +13,8 @@ export const COMPAT_SILENT = "route compat does not say whether the model suppor
|
|
|
12
13
|
* own catalog supports one of the two, but only the compat says which.
|
|
13
14
|
*/
|
|
14
15
|
export function declarationKind(compat) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (compat?.supportsToolSearch === true)
|
|
18
|
-
return "tool_search";
|
|
19
|
-
return undefined;
|
|
16
|
+
const support = getResponsesToolSupport({ ...compat, supportsMidConvoSystemMessages: true });
|
|
17
|
+
return support === "changes" ? "additional_tools" : support === "additions" ? "tool_search" : undefined;
|
|
20
18
|
}
|
|
21
19
|
/** Remove the activation marker; the wire never carries it. */
|
|
22
20
|
export function withoutDeferLoading(tool) {
|
|
@@ -39,7 +37,7 @@ function full(messages, tools, toolHistory, fallbackReason, fallbackUnexpected)
|
|
|
39
37
|
/**
|
|
40
38
|
* Decide the tool surface of one GPT Responses request.
|
|
41
39
|
*
|
|
42
|
-
*
|
|
40
|
+
* DSH history projection is used only when every condition holds; Pi owns the wire tool state:
|
|
43
41
|
* the policy is on, DSH reports `toolUpdate: "addition-only"` with an in-history system prompt, the route
|
|
44
42
|
* compat names a supported declaration shape (`additional_tools` or `tool_search`; silence is not guessed
|
|
45
43
|
* at, see `declarationKind`), and DSH supplied its tool history. The host
|
|
@@ -101,6 +99,5 @@ export function planToolSurface(input) {
|
|
|
101
99
|
messages: projected.messages,
|
|
102
100
|
tools: projectedTools,
|
|
103
101
|
anchored: true,
|
|
104
|
-
compat: kind === "additional_tools" ? { supportsAdditionalTools: true } : { supportsAdditionalTools: false, supportsToolSearch: true },
|
|
105
102
|
};
|
|
106
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lcx-codex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-pre.1",
|
|
4
4
|
"description": "Model-scoped DSH plugin: GPT Responses lifecycle, Native V2 compaction and Hosted/Alpha Search; Grok native Web/X Search",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"keywords": [
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@deepseek-ai/dsh": "0.2.
|
|
70
|
-
"@earendil-works/pi-ai": "1.
|
|
71
|
-
"@deepseek-ai/schemastery": "~3.18.
|
|
69
|
+
"@deepseek-ai/dsh": "0.2.2-alpha.3",
|
|
70
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
71
|
+
"@deepseek-ai/schemastery": "~3.18.6-alpha.2",
|
|
72
72
|
"@types/node": "^22.20.0",
|
|
73
73
|
"@types/react": "~18.3.1",
|
|
74
74
|
"esbuild": "^0.28.2",
|
|
@@ -76,32 +76,34 @@
|
|
|
76
76
|
"typescript": "7.0.2"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@deepseek-ai/cordis": ">=4.0.
|
|
80
|
-
"@deepseek-ai/cordis-plugin-loader": ">=1.0.
|
|
81
|
-
"@deepseek-ai/dsh-agent": ">=0.2.
|
|
82
|
-
"@deepseek-ai/dsh-
|
|
83
|
-
"@deepseek-ai/dsh-
|
|
84
|
-
"@deepseek-ai/dsh-client-
|
|
85
|
-
"@deepseek-ai/dsh-client-
|
|
86
|
-
"@deepseek-ai/dsh-client-
|
|
87
|
-
"@deepseek-ai/dsh-client-ui-
|
|
88
|
-
"@deepseek-ai/dsh-client-ui-
|
|
89
|
-
"@deepseek-ai/dsh-client-ui-
|
|
90
|
-
"@deepseek-ai/dsh-
|
|
91
|
-
"@deepseek-ai/dsh-
|
|
92
|
-
"@deepseek-ai/dsh-
|
|
93
|
-
"@deepseek-ai/dsh-
|
|
94
|
-
"@deepseek-ai/dsh-
|
|
95
|
-
"@deepseek-ai/dsh-session
|
|
96
|
-
"@deepseek-ai/dsh-
|
|
97
|
-
"@deepseek-ai/dsh-
|
|
98
|
-
"@deepseek-ai/dsh-
|
|
99
|
-
"@deepseek-ai/dsh-
|
|
100
|
-
"@deepseek-ai/
|
|
79
|
+
"@deepseek-ai/cordis": ">=4.0.6-alpha.2",
|
|
80
|
+
"@deepseek-ai/cordis-plugin-loader": ">=1.0.7-alpha.2",
|
|
81
|
+
"@deepseek-ai/dsh-agent": ">=0.2.2-alpha.3",
|
|
82
|
+
"@deepseek-ai/dsh-api-session-controller": ">=0.2.2-alpha.3",
|
|
83
|
+
"@deepseek-ai/dsh-attachment": ">=0.2.2-alpha.3",
|
|
84
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-alpha.3",
|
|
85
|
+
"@deepseek-ai/dsh-client-modules": ">=0.2.2-alpha.3",
|
|
86
|
+
"@deepseek-ai/dsh-client-store": ">=0.2.2-alpha.3",
|
|
87
|
+
"@deepseek-ai/dsh-client-ui-chat": ">=0.2.2-alpha.3",
|
|
88
|
+
"@deepseek-ai/dsh-client-ui-conversation": ">=0.2.2-alpha.3",
|
|
89
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.2-alpha.3",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-alpha.3",
|
|
91
|
+
"@deepseek-ai/dsh-compaction": ">=0.2.2-alpha.3",
|
|
92
|
+
"@deepseek-ai/dsh-credentials": ">=0.2.2-alpha.3",
|
|
93
|
+
"@deepseek-ai/dsh-fs": ">=0.2.2-alpha.3",
|
|
94
|
+
"@deepseek-ai/dsh-llm": ">=0.2.2-alpha.3",
|
|
95
|
+
"@deepseek-ai/dsh-session": ">=0.2.2-alpha.3",
|
|
96
|
+
"@deepseek-ai/dsh-session-query": ">=0.2.2-alpha.3",
|
|
97
|
+
"@deepseek-ai/dsh-settings": ">=0.2.2-alpha.3",
|
|
98
|
+
"@deepseek-ai/dsh-tool-web": ">=0.2.2-alpha.3",
|
|
99
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-alpha.3",
|
|
100
|
+
"@deepseek-ai/dsh-web": ">=0.2.2-alpha.3",
|
|
101
|
+
"@deepseek-ai/schemastery": ">=3.18.6-alpha.2",
|
|
101
102
|
"react": "^18.2.0",
|
|
102
|
-
"@deepseek-ai/dsh-token-meter": ">=0.2.
|
|
103
|
-
"@deepseek-ai/dsh-session-projection": ">=0.2.
|
|
104
|
-
"zod": "^4.5.4"
|
|
103
|
+
"@deepseek-ai/dsh-token-meter": ">=0.2.2-alpha.3",
|
|
104
|
+
"@deepseek-ai/dsh-session-projection": ">=0.2.2-alpha.3",
|
|
105
|
+
"zod": "^4.5.4",
|
|
106
|
+
"@deepseek-ai/dsh-tool-executor-ptc": ">=0.2.2-alpha.3"
|
|
105
107
|
},
|
|
106
108
|
"peerDependenciesMeta": {
|
|
107
109
|
"@deepseek-ai/cordis-plugin-loader": {
|
|
@@ -110,6 +112,9 @@
|
|
|
110
112
|
"@deepseek-ai/dsh-client-locale": {
|
|
111
113
|
"optional": true
|
|
112
114
|
},
|
|
115
|
+
"@deepseek-ai/dsh-api-session-controller": {
|
|
116
|
+
"optional": true
|
|
117
|
+
},
|
|
113
118
|
"@deepseek-ai/dsh-agent": {
|
|
114
119
|
"optional": true
|
|
115
120
|
},
|
|
@@ -163,6 +168,9 @@
|
|
|
163
168
|
},
|
|
164
169
|
"@deepseek-ai/dsh-web": {
|
|
165
170
|
"optional": true
|
|
171
|
+
},
|
|
172
|
+
"@deepseek-ai/dsh-tool-executor-ptc": {
|
|
173
|
+
"optional": true
|
|
166
174
|
}
|
|
167
175
|
},
|
|
168
176
|
"scripts": {
|
|
@@ -184,9 +192,9 @@
|
|
|
184
192
|
},
|
|
185
193
|
"license": "MIT",
|
|
186
194
|
"lcxCompatibility": {
|
|
187
|
-
"dshInstallRange": ">=0.2.
|
|
188
|
-
"verifiedDsh": "0.2.
|
|
189
|
-
"verifiedHostPi": "1.
|
|
190
|
-
"verifiedPluginPi": "1.
|
|
195
|
+
"dshInstallRange": ">=0.2.2-alpha.3",
|
|
196
|
+
"verifiedDsh": "0.2.2-alpha.3",
|
|
197
|
+
"verifiedHostPi": "1.5.0",
|
|
198
|
+
"verifiedPluginPi": "1.5.0"
|
|
191
199
|
}
|
|
192
200
|
}
|