dsh-lcx-codex 0.5.2 → 0.6.0-pre.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.
@@ -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
+ }
@@ -1,24 +1,19 @@
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
- /** @param {unknown} value */
6
- function isObject(value) {
7
- return value !== null && typeof value === "object" && !Array.isArray(value);
8
- }
9
5
  function modelId(model) {
10
6
  return typeof model === "string" ? model : model.id;
11
7
  }
12
8
  function modelRecord(model) {
13
9
  return typeof model === "string"
14
- ? /** @type {PiResponsesModel} */ {
10
+ ? {
15
11
  id: model,
16
12
  provider: "lcx",
17
13
  reasoning: true,
18
14
  }
19
15
  : model;
20
16
  }
21
- /** @param {unknown} value */
22
17
  function normalizeCacheRetention(value) {
23
18
  const normalized = String(value);
24
19
  return normalized === "none" || normalized === "short" || normalized === "long"
@@ -27,7 +22,6 @@ function normalizeCacheRetention(value) {
27
22
  }
28
23
  /**
29
24
  * Pi-parity generation controls for OpenAI Responses.
30
- * @param {GenerationControls & { model?: PiResponsesModel | string, includeDefaultReasoning?: boolean }} [controls]
31
25
  */
32
26
  export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort, temperature, maxTokens, includeDefaultReasoning = false, } = {}) {
33
27
  const descriptor = modelRecord(model);
@@ -71,7 +65,6 @@ export function responsesGenerationEnvelope({ model = "unknown", reasoningEffort
71
65
  /**
72
66
  * Build the shared LCX-owned request envelope while retaining Pi 0.86.0 Responses semantics.
73
67
  * Production LCX ordinary/compact/replay construction places the DSH system prompt in canonical input.
74
- * @param {BuildResponsesBodyOptions} options
75
68
  */
76
69
  export function buildResponsesBody({ model, input, tools, sessionId, promptCacheKey, promptCacheRetention, cacheRetention, reasoningEffort, temperature, maxTokens, samplingParams, }) {
77
70
  if (!Array.isArray(input))
@@ -115,17 +108,16 @@ export function buildResponsesBody({ model, input, tools, sessionId, promptCache
115
108
  includeDefaultReasoning: true,
116
109
  }),
117
110
  };
118
- if (isObject(samplingParams))
111
+ if (isRecord(samplingParams))
119
112
  Object.assign(body, structuredClone(samplingParams));
120
113
  return body;
121
114
  }
122
115
  /**
123
116
  * Compact is the standard request plus the one opaque-history transition patch.
124
- * @param {BuildResponsesBodyOptions} options
125
117
  */
126
118
  export function buildCompactionResponsesBody(options) {
127
119
  const body = buildResponsesBody(options);
128
- if (body.input.some((item) => isObject(item) && item.type === "compaction_trigger")) {
120
+ if (body.input.some((item) => isRecord(item) && item.type === "compaction_trigger")) {
129
121
  throw Object.assign(new Error("native compaction input already contains compaction_trigger"), { code: "LCX_COMPACT_DUPLICATE_TRIGGER" });
130
122
  }
131
123
  body.input = [...body.input, { type: "compaction_trigger" }];