dsh-lcx-codex 0.6.0-pre.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -26
- package/THIRD_PARTY_NOTICES.md +3 -2
- package/lib/abort-error.js +12 -1
- package/lib/client.js +73 -39
- package/lib/compact-v2.js +16 -56
- package/lib/defaults.js +15 -0
- package/lib/dsh-compat.js +15 -76
- package/lib/dsh-responses.js +178 -120
- package/lib/grok-native-search.js +1 -3
- package/lib/index.js +219 -149
- package/lib/model-catalog.js +46 -0
- package/lib/native-checkpoint.js +23 -185
- package/lib/pi-responses-runtime.js +749 -165
- package/lib/provider-headers.js +31 -0
- package/lib/responses-request.js +30 -15
- package/lib/responses-stream.js +120 -215
- package/lib/route.js +206 -88
- package/lib/search-accounting.js +1 -16
- package/lib/search-usage.js +8 -2
- package/lib/token-budget.js +6 -41
- package/lib/tool-surface.js +14 -18
- package/lib/transport.js +89 -107
- package/lib/types/client/search-media.d.ts +0 -2
- package/lib/util.js +21 -0
- package/lib/web-run-output.js +0 -3
- package/lib/web-search-alpha.js +22 -27
- package/lib/web-search-capability.js +1 -3
- package/lib/web-search-hosted.js +2 -2
- package/lib/web-search-ref-store.js +1 -3
- package/package.json +36 -32
- package/lib/pi086-responses-allowlist.js +0 -131
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildCopilotDynamicHeaders, hasCopilotVisionInput, withOpenCodeSessionHeader, } from "./pi-responses-runtime.js";
|
|
2
|
+
/** The user / assistant / toolResult view of a DSH request that Pi's Copilot helpers read. */
|
|
3
|
+
function piMessages(messages) {
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const message of messages) {
|
|
6
|
+
if (message.role === "user" || message.role === "assistant")
|
|
7
|
+
result.push({ role: message.role, content: message.content });
|
|
8
|
+
else if (message.role === "tool")
|
|
9
|
+
result.push({ role: "toolResult", content: message.content });
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
/** GitHub Copilot: `X-Initiator`, `Openai-Intent` and, when images are sent, `Copilot-Vision-Request`. */
|
|
14
|
+
export function providerDynamicHeaders(provider, messages) {
|
|
15
|
+
if (provider !== "github-copilot")
|
|
16
|
+
return {};
|
|
17
|
+
const pi = piMessages(messages);
|
|
18
|
+
return buildCopilotDynamicHeaders({ messages: pi, hasImages: hasCopilotVisionInput(pi) });
|
|
19
|
+
}
|
|
20
|
+
/** OpenCode Zen / Go: the per-conversation routing header Pi adds before dispatch. */
|
|
21
|
+
export function providerSessionHeaders(provider, sessionId) {
|
|
22
|
+
if ((provider !== "opencode" && provider !== "opencode-go") || sessionId === undefined)
|
|
23
|
+
return {};
|
|
24
|
+
let captured = {};
|
|
25
|
+
const capture = (_model, _context, options) => {
|
|
26
|
+
captured = { ...options?.headers };
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
withOpenCodeSessionHeader({ stream: capture, streamSimple: capture }).stream(undefined, undefined, { sessionId });
|
|
30
|
+
return captured;
|
|
31
|
+
}
|
package/lib/responses-request.js
CHANGED
|
@@ -1,35 +1,49 @@
|
|
|
1
|
-
// @ts-check
|
|
2
1
|
import { clampOpenAIPromptCacheKey } from "./pi-responses-runtime.js";
|
|
3
2
|
import { responsesTools } from "./dsh-responses.js";
|
|
3
|
+
import { isRecord } from "./util.js";
|
|
4
4
|
const OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8
|
-
}
|
|
5
|
+
/** Pi's fixed request effort while the real one travels in `configuration_update` input items. */
|
|
6
|
+
const CONFIGURATION_UPDATE_REQUEST_EFFORT = "medium";
|
|
9
7
|
function modelId(model) {
|
|
10
8
|
return typeof model === "string" ? model : model.id;
|
|
11
9
|
}
|
|
12
10
|
function modelRecord(model) {
|
|
13
11
|
return typeof model === "string"
|
|
14
|
-
?
|
|
12
|
+
? {
|
|
15
13
|
id: model,
|
|
16
14
|
provider: "lcx",
|
|
17
15
|
reasoning: true,
|
|
18
16
|
}
|
|
19
17
|
: model;
|
|
20
18
|
}
|
|
21
|
-
/** @param {unknown} value */
|
|
22
19
|
function normalizeCacheRetention(value) {
|
|
23
20
|
const normalized = String(value);
|
|
24
21
|
return normalized === "none" || normalized === "short" || normalized === "long"
|
|
25
22
|
? normalized
|
|
26
23
|
: "short";
|
|
27
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
|
+
}
|
|
28
43
|
/**
|
|
29
44
|
* Pi-parity generation controls for OpenAI Responses.
|
|
30
|
-
* @param {GenerationControls & { model?: PiResponsesModel | string, includeDefaultReasoning?: boolean }} [controls]
|
|
31
45
|
*/
|
|
32
|
-
export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort, temperature, maxTokens, includeDefaultReasoning = false, } = {}) {
|
|
46
|
+
export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort, temperature, maxTokens, configurationUpdateEffort, includeDefaultReasoning = false, } = {}) {
|
|
33
47
|
const descriptor = modelRecord(model);
|
|
34
48
|
const result = {};
|
|
35
49
|
if (descriptor.reasoning !== false) {
|
|
@@ -43,7 +57,9 @@ export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort
|
|
|
43
57
|
const mapped = descriptor.thinkingLevelMap?.[requested];
|
|
44
58
|
const wire = mapped === undefined ? requested : mapped;
|
|
45
59
|
if (wire !== null) {
|
|
46
|
-
|
|
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" };
|
|
47
63
|
result.include = ["reasoning.encrypted_content"];
|
|
48
64
|
}
|
|
49
65
|
}
|
|
@@ -71,9 +87,8 @@ export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort
|
|
|
71
87
|
/**
|
|
72
88
|
* Build the shared LCX-owned request envelope while retaining Pi 0.86.0 Responses semantics.
|
|
73
89
|
* Production LCX ordinary/compact/replay construction places the DSH system prompt in canonical input.
|
|
74
|
-
* @param {BuildResponsesBodyOptions} options
|
|
75
90
|
*/
|
|
76
|
-
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, }) {
|
|
77
92
|
if (!Array.isArray(input))
|
|
78
93
|
throw Object.assign(new Error("Responses input must be an array"), {
|
|
79
94
|
code: "LCX_RESPONSES_INVALID_INPUT",
|
|
@@ -112,20 +127,20 @@ export function buildResponsesBody({ model, input, tools, sessionId, promptCache
|
|
|
112
127
|
reasoningEffort,
|
|
113
128
|
temperature,
|
|
114
129
|
maxTokens,
|
|
130
|
+
configurationUpdateEffort,
|
|
115
131
|
includeDefaultReasoning: true,
|
|
116
132
|
}),
|
|
117
133
|
};
|
|
118
|
-
if (
|
|
134
|
+
if (isRecord(samplingParams))
|
|
119
135
|
Object.assign(body, structuredClone(samplingParams));
|
|
120
136
|
return body;
|
|
121
137
|
}
|
|
122
138
|
/**
|
|
123
139
|
* Compact is the standard request plus the one opaque-history transition patch.
|
|
124
|
-
* @param {BuildResponsesBodyOptions} options
|
|
125
140
|
*/
|
|
126
141
|
export function buildCompactionResponsesBody(options) {
|
|
127
142
|
const body = buildResponsesBody(options);
|
|
128
|
-
if (body.input.some((item) =>
|
|
143
|
+
if (body.input.some((item) => isRecord(item) && item.type === "compaction_trigger")) {
|
|
129
144
|
throw Object.assign(new Error("native compaction input already contains compaction_trigger"), { code: "LCX_COMPACT_DUPLICATE_TRIGGER" });
|
|
130
145
|
}
|
|
131
146
|
body.input = [...body.input, { type: "compaction_trigger" }];
|