@f5-sales-demo/pi-ai 21.15.0 → 21.16.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5-sales-demo/pi-ai",
4
- "version": "21.15.0",
4
+ "version": "21.16.0",
5
5
  "description": "Unified LLM API with automatic model discovery and provider configuration",
6
6
  "homepage": "https://github.com/f5-sales-demo/xcsh",
7
7
  "author": "Can Boluk",
@@ -46,7 +46,7 @@
46
46
  "@anthropic-ai/sdk": "^0.115",
47
47
  "@aws-sdk/client-bedrock-runtime": "^3",
48
48
  "@bufbuild/protobuf": "^2.11",
49
- "@f5-sales-demo/pi-utils": "21.15.0",
49
+ "@f5-sales-demo/pi-utils": "21.16.0",
50
50
  "@google/genai": "^2.15",
51
51
  "@sinclair/typebox": "^0.34",
52
52
  "@smithy/node-http-handler": "^4.4",
@@ -63,7 +63,12 @@ import {
63
63
  transformRequestBody,
64
64
  } from "./openai-codex/request-transformer";
65
65
  import { parseCodexError } from "./openai-codex/response-handler";
66
- import { encodeTextSignatureV1, mapOpenAIResponsesStopReason, parseTextSignature } from "./openai-responses-shared";
66
+ import {
67
+ encodeTextSignatureV1,
68
+ mapOpenAIResponsesStopReason,
69
+ parseTextSignature,
70
+ resolveAssistantMessagePhase,
71
+ } from "./openai-responses-shared";
67
72
  import { transformMessages } from "./transform-messages";
68
73
 
69
74
  export interface OpenAICodexResponsesOptions extends StreamOptions {
@@ -747,11 +752,21 @@ function handleCodexStreamEvent(args: {
747
752
  runtime.currentBlock = createOutputBlockForItem(item);
748
753
  if (!runtime.currentBlock) return firstTokenTime;
749
754
  output.content.push(runtime.currentBlock);
750
- stream.push({
751
- type: getOutputBlockStartEventType(runtime.currentBlock),
752
- contentIndex: blockIndex(),
753
- partial: output,
754
- });
755
+ if (runtime.currentBlock.type === "text") {
756
+ stream.push({
757
+ type: "text_start",
758
+ contentIndex: blockIndex(),
759
+ phase: runtime.currentBlock.phase ?? "final_answer",
760
+ partial: output,
761
+ });
762
+ } else {
763
+ const type = getOutputBlockStartEventType(runtime.currentBlock);
764
+ if (type === "thinking_start") {
765
+ stream.push({ type, contentIndex: blockIndex(), partial: output });
766
+ } else {
767
+ stream.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
768
+ }
769
+ }
755
770
  return firstTokenTime;
756
771
  }
757
772
 
@@ -838,7 +853,7 @@ function createOutputBlockForItem(item: CodexEventItem): CodexOutputBlock | null
838
853
  return { type: "thinking", thinking: "" };
839
854
  }
840
855
  if (item.type === "message") {
841
- return { type: "text", text: "" };
856
+ return { type: "text", text: "", phase: resolveAssistantMessagePhase(item.phase) };
842
857
  }
843
858
  if (item.type === "function_call") {
844
859
  return {
@@ -986,12 +1001,14 @@ function handleOutputItemDone(
986
1001
  runtime.currentBlock.text = item.content
987
1002
  .map(content => (content.type === "output_text" ? content.text : content.refusal))
988
1003
  .join("");
989
- const phase = item.phase === "commentary" || item.phase === "final_answer" ? item.phase : undefined;
1004
+ const phase = resolveAssistantMessagePhase(item.phase);
1005
+ runtime.currentBlock.phase = phase;
990
1006
  runtime.currentBlock.textSignature = encodeTextSignatureV1(item.id, phase);
991
1007
  stream.push({
992
1008
  type: "text_end",
993
1009
  contentIndex: blockIndex(),
994
1010
  content: runtime.currentBlock.text,
1011
+ phase,
995
1012
  partial: output,
996
1013
  });
997
1014
  runtime.currentBlock = null;
@@ -2175,7 +2192,7 @@ function convertMessages(model: Model<"openai-codex-responses">, context: Contex
2175
2192
  content: [{ type: "output_text", text: textBlock.text.toWellFormed(), annotations: [] }],
2176
2193
  status: "completed",
2177
2194
  id: msgId,
2178
- phase: parsedSignature?.phase,
2195
+ phase: parsedSignature?.phase ?? textBlock.phase,
2179
2196
  } satisfies ResponseOutputMessage);
2180
2197
  continue;
2181
2198
  }
@@ -14,6 +14,7 @@ import { calculateCost } from "../models";
14
14
  import type {
15
15
  Api,
16
16
  AssistantMessage,
17
+ AssistantMessagePhase,
17
18
  ImageContent,
18
19
  Model,
19
20
  StopReason,
@@ -33,6 +34,10 @@ export function encodeTextSignatureV1(id: string, phase?: TextSignatureV1["phase
33
34
  return JSON.stringify(payload);
34
35
  }
35
36
 
37
+ export function resolveAssistantMessagePhase(phase: unknown): AssistantMessagePhase {
38
+ return phase === "commentary" ? "commentary" : "final_answer";
39
+ }
40
+
36
41
  export function parseTextSignature(
37
42
  signature: string | undefined,
38
43
  ): { id: string; phase?: TextSignatureV1["phase"] } | undefined {
@@ -152,7 +157,7 @@ export function convertResponsesAssistantMessage<TApi extends Api>(
152
157
  content: [{ type: "output_text", text: block.text.toWellFormed(), annotations: [] }],
153
158
  status: "completed",
154
159
  id: msgId,
155
- phase: parsedSignature?.phase,
160
+ phase: parsedSignature?.phase ?? block.phase,
156
161
  } satisfies ResponseOutputMessage);
157
162
  continue;
158
163
  }
@@ -262,9 +267,14 @@ export async function processResponsesStream<TApi extends Api>(
262
267
  stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
263
268
  } else if (item.type === "message") {
264
269
  currentItem = item;
265
- currentBlock = { type: "text", text: "" };
270
+ currentBlock = { type: "text", text: "", phase: resolveAssistantMessagePhase(item.phase) };
266
271
  output.content.push(currentBlock);
267
- stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
272
+ stream.push({
273
+ type: "text_start",
274
+ contentIndex: blockIndex(),
275
+ phase: currentBlock.phase ?? "final_answer",
276
+ partial: output,
277
+ });
268
278
  } else if (item.type === "function_call") {
269
279
  currentItem = item;
270
280
  currentBlock = {
@@ -380,11 +390,13 @@ export async function processResponsesStream<TApi extends Api>(
380
390
  currentBlock.text = item.content
381
391
  .map(part => (part.type === "output_text" ? (part.text ?? "") : (part.refusal ?? "")))
382
392
  .join("");
383
- currentBlock.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);
393
+ currentBlock.phase = resolveAssistantMessagePhase(item.phase);
394
+ currentBlock.textSignature = encodeTextSignatureV1(item.id, currentBlock.phase);
384
395
  stream.push({
385
396
  type: "text_end",
386
397
  contentIndex: blockIndex(),
387
398
  content: currentBlock.text,
399
+ phase: currentBlock.phase ?? "final_answer",
388
400
  partial: output,
389
401
  });
390
402
  currentBlock = null;
package/src/types.ts CHANGED
@@ -258,10 +258,12 @@ export type StreamFunction<TApi extends Api> = (
258
258
  options: OptionsForApi<TApi>,
259
259
  ) => AssistantMessageEventStream;
260
260
 
261
+ export type AssistantMessagePhase = "commentary" | "final_answer";
262
+
261
263
  export interface TextSignatureV1 {
262
264
  v: 1;
263
265
  id: string;
264
- phase?: "commentary" | "final_answer";
266
+ phase?: AssistantMessagePhase;
265
267
  }
266
268
 
267
269
  /**
@@ -288,6 +290,8 @@ export interface WebCitation {
288
290
  export interface TextContent {
289
291
  type: "text";
290
292
  text: string;
293
+ /** Semantic role supplied by Responses. Absence has final-answer semantics. */
294
+ phase?: AssistantMessagePhase;
291
295
  textSignature?: string; // e.g., for OpenAI responses, message metadata (legacy id string or TextSignatureV1 JSON)
292
296
  /** Structured citations for this span, when the provider ran a server-side search. */
293
297
  citations?: WebCitation[];
@@ -468,9 +472,15 @@ export interface Context {
468
472
 
469
473
  export type AssistantMessageEvent =
470
474
  | { type: "start"; contentIndex?: undefined; partial: AssistantMessage }
471
- | { type: "text_start"; contentIndex: number; partial: AssistantMessage }
475
+ | { type: "text_start"; contentIndex: number; phase?: AssistantMessagePhase; partial: AssistantMessage }
472
476
  | { type: "text_delta"; contentIndex: number; delta: string; partial: AssistantMessage }
473
- | { type: "text_end"; contentIndex: number; content: string; partial: AssistantMessage }
477
+ | {
478
+ type: "text_end";
479
+ contentIndex: number;
480
+ content: string;
481
+ phase?: AssistantMessagePhase;
482
+ partial: AssistantMessage;
483
+ }
474
484
  | { type: "thinking_start"; contentIndex: number; partial: AssistantMessage }
475
485
  | { type: "thinking_delta"; contentIndex: number; delta: string; partial: AssistantMessage }
476
486
  | { type: "thinking_end"; contentIndex: number; content: string; partial: AssistantMessage }