@codefionn/llmleaf-client 0.4.1 → 0.5.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/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export type {
40
40
  FunctionCall,
41
41
  ToolCall,
42
42
  ReasoningDetail,
43
+ CompactionBlock,
43
44
  ChatMessage,
44
45
  FunctionDef,
45
46
  ToolDef,
@@ -64,6 +65,7 @@ export type {
64
65
  ResponseFunctionCallOutputItem,
65
66
  ResponseReasoningText,
66
67
  ResponseReasoningItem,
68
+ ResponseCompactionItem,
67
69
  ResponseItem,
68
70
  ResponsesInput,
69
71
  ResponsesToolDef,
package/src/types.ts CHANGED
@@ -144,6 +144,15 @@ export interface ReasoningDetail {
144
144
  index?: number;
145
145
  }
146
146
 
147
+ /** Opaque native compaction state. Echo it back unchanged on the next turn. */
148
+ export interface CompactionBlock {
149
+ type: "compaction";
150
+ id?: string;
151
+ content?: string;
152
+ encryptedContent?: string;
153
+ signature?: string;
154
+ }
155
+
147
156
  export interface ChatMessage {
148
157
  role: Role;
149
158
  content?: MessageContent;
@@ -162,6 +171,7 @@ export interface ChatMessage {
162
171
  * signed reasoning across a turn.
163
172
  */
164
173
  reasoningDetails?: ReasoningDetail[];
174
+ compaction?: CompactionBlock[];
165
175
  }
166
176
 
167
177
  export interface FunctionDef {
@@ -257,6 +267,7 @@ export interface Delta {
257
267
  reasoning?: string;
258
268
  /** incremental structured reasoning blocks (open / hidden — see {@link ReasoningDetail}). */
259
269
  reasoningDetails?: ReasoningDetail[];
270
+ compaction?: CompactionBlock[];
260
271
  }
261
272
 
262
273
  export interface ChunkChoice {
@@ -486,6 +497,7 @@ export interface ModelEntry {
486
497
  defaultParameters?: string;
487
498
  /** admin-only */
488
499
  endpoints: ModelEndpoint[];
500
+ supportsCompaction?: boolean;
489
501
  }
490
502
 
491
503
  export interface ListModelsResponse {
@@ -649,6 +661,9 @@ export interface ResponseReasoningItem {
649
661
  encryptedContent?: string;
650
662
  }
651
663
 
664
+ /** A Responses output item carrying opaque context for the next request. */
665
+ export interface ResponseCompactionItem extends CompactionBlock {}
666
+
652
667
  /**
653
668
  * One item of the request `input` array or the response `output` array. The `type`
654
669
  * field is the discriminator (a message item serialises without one — see
@@ -658,7 +673,8 @@ export type ResponseItem =
658
673
  | ResponseMessageItem
659
674
  | ResponseFunctionCallItem
660
675
  | ResponseFunctionCallOutputItem
661
- | ResponseReasoningItem;
676
+ | ResponseReasoningItem
677
+ | ResponseCompactionItem;
662
678
 
663
679
  /** `input`: a bare string (one user message) or an array of items. */
664
680
  export type ResponsesInput = string | ResponseItem[];
package/src/wire.ts CHANGED
@@ -17,6 +17,7 @@ import type {
17
17
  ContentPart,
18
18
  MessageContent,
19
19
  ReasoningDetail,
20
+ CompactionBlock,
20
21
  ToolCall,
21
22
  ToolDef,
22
23
  ToolChoice,
@@ -64,6 +65,7 @@ import type {
64
65
  ResponseFunctionCallItem,
65
66
  ResponseFunctionCallOutputItem,
66
67
  ResponseReasoningItem,
68
+ ResponseCompactionItem,
67
69
  ResponseReasoningText,
68
70
  ResponsesToolDef,
69
71
  ResponsesToolChoice,
@@ -174,6 +176,34 @@ function encodeReasoningDetail(d: ReasoningDetail): Json {
174
176
  return out;
175
177
  }
176
178
 
179
+ function encodeCompactionBlock(block: CompactionBlock): Json {
180
+ const out: Json = { type: "compaction" };
181
+ put(out, "id", block.id);
182
+ put(out, "content", block.content);
183
+ put(out, "encrypted_content", block.encryptedContent);
184
+ put(out, "signature", block.signature);
185
+ return out;
186
+ }
187
+
188
+ function decodeCompactionBlock(value: unknown): CompactionBlock | undefined {
189
+ const o = obj(value);
190
+ if (!o || o["type"] !== "compaction") return undefined;
191
+ const block: CompactionBlock = { type: "compaction" };
192
+ const id = optStr(o["id"]);
193
+ if (id !== undefined) block.id = id;
194
+ const content = optStr(o["content"]);
195
+ if (content !== undefined) block.content = content;
196
+ const encrypted = optStr(o["encrypted_content"]);
197
+ if (encrypted !== undefined) block.encryptedContent = encrypted;
198
+ const signature = optStr(o["signature"]);
199
+ if (signature !== undefined) block.signature = signature;
200
+ return block;
201
+ }
202
+
203
+ function decodeCompactionBlocks(value: unknown): CompactionBlock[] {
204
+ return arr(value).map(decodeCompactionBlock).filter((x): x is CompactionBlock => x !== undefined);
205
+ }
206
+
177
207
  function encodeMessage(m: ChatMessage): Json {
178
208
  const out: Json = { role: roleToWire(m.role) ?? "user" };
179
209
  const content = encodeContent(m.content);
@@ -191,6 +221,9 @@ function encodeMessage(m: ChatMessage): Json {
191
221
  if (m.reasoningDetails && m.reasoningDetails.length > 0) {
192
222
  out["reasoning_details"] = m.reasoningDetails.map(encodeReasoningDetail);
193
223
  }
224
+ if (m.compaction && m.compaction.length > 0) {
225
+ out["compaction"] = m.compaction.map(encodeCompactionBlock);
226
+ }
194
227
  return out;
195
228
  }
196
229
 
@@ -372,6 +405,8 @@ export function decodeMessage(v: unknown): ChatMessage {
372
405
  if (reasoning !== undefined) msg.reasoning = reasoning;
373
406
  const rds = decodeReasoningDetails(o["reasoning_details"]);
374
407
  if (rds.length > 0) msg.reasoningDetails = rds;
408
+ const compaction = decodeCompactionBlocks(o["compaction"]);
409
+ if (compaction.length > 0) msg.compaction = compaction;
375
410
  return msg;
376
411
  }
377
412
 
@@ -434,6 +469,8 @@ function decodeDelta(v: unknown): Delta {
434
469
  if (reasoning !== undefined) delta.reasoning = reasoning;
435
470
  const rds = decodeReasoningDetails(o["reasoning_details"]);
436
471
  if (rds.length > 0) delta.reasoningDetails = rds;
472
+ const compaction = decodeCompactionBlocks(o["compaction"]);
473
+ if (compaction.length > 0) delta.compaction = compaction;
437
474
  return delta;
438
475
  }
439
476
 
@@ -736,6 +773,9 @@ function decodeModelEntry(v: unknown): ModelEntry {
736
773
  };
737
774
  const cl = optNum(o["context_length"]);
738
775
  if (cl !== undefined) entry.contextLength = cl;
776
+ if (typeof o["supports_compaction"] === "boolean") {
777
+ entry.supportsCompaction = o["supports_compaction"];
778
+ }
739
779
  const arch = decodeArchitecture(o["architecture"]);
740
780
  if (arch !== undefined) entry.architecture = arch;
741
781
  const pricing = decodePricing(o["pricing"]);
@@ -895,6 +935,10 @@ function encodeResponseReasoningItem(r: ResponseReasoningItem): Json {
895
935
  return out;
896
936
  }
897
937
 
938
+ function encodeResponseCompactionItem(item: ResponseCompactionItem): Json {
939
+ return encodeCompactionBlock(item);
940
+ }
941
+
898
942
  function encodeResponseItem(item: ResponseItem): Json {
899
943
  switch (item.type) {
900
944
  case "function_call":
@@ -903,6 +947,8 @@ function encodeResponseItem(item: ResponseItem): Json {
903
947
  return encodeResponseFunctionCallOutputItem(item);
904
948
  case "reasoning":
905
949
  return encodeResponseReasoningItem(item);
950
+ case "compaction":
951
+ return encodeResponseCompactionItem(item);
906
952
  case "message":
907
953
  return encodeResponseMessageItem(item);
908
954
  }
@@ -1079,6 +1125,8 @@ function decodeResponseItem(v: unknown): ResponseItem | undefined {
1079
1125
  return decodeResponseFunctionCallOutputItem(o);
1080
1126
  case "reasoning":
1081
1127
  return decodeResponseReasoningItem(o);
1128
+ case "compaction":
1129
+ return decodeCompactionBlock(o);
1082
1130
  default:
1083
1131
  return undefined; // unknown item type — skip
1084
1132
  }