@router-for-me/pi-cliproxyapi-provider 1.4.16 → 1.4.17

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.
@@ -150,6 +150,44 @@ export function adaptTranscriptContext(context: Context | { messages?: unknown[]
150
150
  };
151
151
  }
152
152
 
153
+ /**
154
+ * Ensure a classic context with top-level systemPrompt/tools is represented as a TranscriptContext.
155
+ * If the context already contains a system message in context.messages, it is returned untouched.
156
+ */
157
+ export function ensureTranscriptContext(context: Context | { messages?: unknown[]; [key: string]: unknown }): Context {
158
+ if (!context || !Array.isArray(context.messages)) return context as Context;
159
+ const hasSystemMessage = (context.messages as Array<{ role?: string }>).some((m) => m && m.role === "system");
160
+ if (hasSystemMessage) return context as Context;
161
+
162
+ const hasSystemPrompt = typeof context.systemPrompt === "string" && context.systemPrompt.length > 0;
163
+ const hasTools = Array.isArray(context.tools) && context.tools.length > 0;
164
+ if (!hasSystemPrompt && !hasTools) return context as Context;
165
+
166
+ return {
167
+ ...(context as Record<string, unknown>),
168
+ messages: [
169
+ {
170
+ role: "system",
171
+ content: context.systemPrompt ?? "",
172
+ ...(hasTools ? { toolsAdded: context.tools } : {}),
173
+ timestamp: 0,
174
+ },
175
+ ...context.messages,
176
+ ] as Context["messages"],
177
+ };
178
+ }
179
+
180
+ export function supportsTranscriptSource(source: string): boolean {
181
+ return source.includes("resolveTranscriptTools") || source.includes("resolveTranscript");
182
+ }
183
+
184
+ export function adaptContextForModule(
185
+ context: Context | { messages?: unknown[]; [key: string]: unknown },
186
+ supportsTranscript: boolean,
187
+ ): Context {
188
+ return supportsTranscript ? ensureTranscriptContext(context) : adaptTranscriptContext(context);
189
+ }
190
+
153
191
  export function withPriorityServiceTier(payload: unknown): unknown {
154
192
  if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
155
193
  return payload;
@@ -176,11 +214,10 @@ export function wrapStreamSimpleForFast(
176
214
  shouldUseFast?: (model: Model<Api>) => boolean,
177
215
  ): CliproxyCodexStreamSimple {
178
216
  return (model, context, streamOptions) => {
179
- const adaptedContext = adaptTranscriptContext(context);
180
217
  if (!shouldUseFast?.(model)) {
181
- return streamSimple(model, adaptedContext, streamOptions);
218
+ return streamSimple(model, context, streamOptions);
182
219
  }
183
- return streamSimple(model, adaptedContext, {
220
+ return streamSimple(model, context, {
184
221
  ...streamOptions,
185
222
  onPayload: (payload, payloadModel) => applyFastPayloadHook(payload, payloadModel, streamOptions?.onPayload),
186
223
  });
@@ -335,6 +372,16 @@ function resolveOriginalCodexModulePath(): { path: string; dir: string } {
335
372
  // dist file next to the resolved package entry.
336
373
  const candidates: string[] = [];
337
374
 
375
+ // pi bundled Node CLI exposes pi-ai as a virtual module to
376
+ // extensions. Resolve its physical nested dependency from the CLI entry so
377
+ // the source-patching transport can still read the installed implementation.
378
+ if (process.argv[1]) {
379
+ const bundledHostModule = resolveCodexModuleFromNodeEntry(process.argv[1]);
380
+ if (bundledHostModule) {
381
+ candidates.push(bundledHostModule);
382
+ }
383
+ }
384
+
338
385
  try {
339
386
  const subpath = import.meta.resolve("@earendil-works/pi-ai/api/openai-codex-responses");
340
387
  candidates.push(fileURLToPath(subpath));
@@ -351,16 +398,6 @@ function resolveOriginalCodexModulePath(): { path: string; dir: string } {
351
398
  // ignore
352
399
  }
353
400
 
354
- // pi 0.84.3's bundled Node CLI exposes pi-ai as a virtual module to
355
- // extensions. Resolve its physical nested dependency from the CLI entry so
356
- // the source-patching transport can still read the installed implementation.
357
- if (process.argv[1]) {
358
- const bundledHostModule = resolveCodexModuleFromNodeEntry(process.argv[1]);
359
- if (bundledHostModule) {
360
- candidates.push(bundledHostModule);
361
- }
362
- }
363
-
364
401
  for (const path of candidates) {
365
402
  if (path && existsSync(path)) {
366
403
  return { path, dir: dirname(path) };
@@ -395,11 +432,14 @@ export async function loadCliproxyCodexStreams(
395
432
  throw new Error("patched openai-codex-responses module missing streamSimple/stream exports");
396
433
  }
397
434
 
435
+ const supportsTranscript = supportsTranscriptSource(originalSource);
436
+ const adaptContext = (context: Context): Context => adaptContextForModule(context, supportsTranscript);
437
+
398
438
  const adaptedStreamSimple: CliproxyCodexStreamSimple = (model, context, streamOptions) => {
399
- return mod.streamSimple(model, adaptTranscriptContext(context), streamOptions);
439
+ return mod.streamSimple(model, adaptContext(context), streamOptions);
400
440
  };
401
441
  const adaptedStream: CliproxyCodexStreamSimple = (model, context, streamOptions) => {
402
- return mod.stream(model, adaptTranscriptContext(context), streamOptions);
442
+ return mod.stream(model, adaptContext(context), streamOptions);
403
443
  };
404
444
 
405
445
  const streamSimple = wrapStreamSimpleForFast(adaptedStreamSimple, options.shouldUseFast);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@router-for-me/pi-cliproxyapi-provider",
3
- "version": "1.4.16",
3
+ "version": "1.4.17",
4
4
  "description": "Pi provider extension that auto-registers CLIProxyAPI models, plus TUI elapsed/TPS status",
5
5
  "type": "module",
6
6
  "keywords": [