@opencode/ai 2.3.1 → 2.3.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.
@@ -1087,6 +1087,166 @@ export declare const lowerToolChoice: (protocolName: string, toolChoice: NonNull
1087
1087
  type: "custom" | "function";
1088
1088
  name: string;
1089
1089
  }, AIError, never>;
1090
+ export declare const lowerMessages: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
1091
+ readonly [x: string]: unknown;
1092
+ }, import("../route.js").CompactionOperations | undefined>>, adapter: ProviderAdapter) => Effect.Effect<({
1093
+ readonly type: "configuration_update";
1094
+ readonly reasoning: {
1095
+ readonly effort: OpenResponsesOptions.ReasoningEffort;
1096
+ };
1097
+ } | {
1098
+ readonly type: "additional_tools";
1099
+ readonly role: "developer";
1100
+ readonly tools: readonly ({
1101
+ readonly type: "custom";
1102
+ readonly name: string;
1103
+ readonly description: string;
1104
+ readonly format: {
1105
+ readonly type: "text";
1106
+ } | {
1107
+ readonly type: "grammar";
1108
+ readonly syntax: "lark" | "regex";
1109
+ readonly definition: string;
1110
+ };
1111
+ } | {
1112
+ readonly type: "function";
1113
+ readonly name: string;
1114
+ readonly description: string;
1115
+ readonly parameters: {
1116
+ readonly [x: string]: unknown;
1117
+ };
1118
+ readonly strict?: boolean | undefined;
1119
+ } | {
1120
+ readonly [x: string]: unknown;
1121
+ readonly type: string;
1122
+ })[];
1123
+ } | {
1124
+ readonly type: "message";
1125
+ readonly role: "system";
1126
+ readonly content: string;
1127
+ } | {
1128
+ readonly type: "message";
1129
+ readonly role: "developer";
1130
+ readonly content: string;
1131
+ } | {
1132
+ readonly type: "custom_tool_call_output" | "function_call_output";
1133
+ readonly call_id: string;
1134
+ readonly output: string | readonly ({
1135
+ readonly type: "input_text";
1136
+ readonly text: string;
1137
+ } | {
1138
+ readonly type: "input_video";
1139
+ readonly video_url: string;
1140
+ } | {
1141
+ readonly type: "input_image";
1142
+ readonly image_url: string;
1143
+ readonly detail?: string | undefined;
1144
+ } | {
1145
+ readonly type: "input_file";
1146
+ readonly filename?: string | undefined;
1147
+ readonly detail?: string | undefined;
1148
+ readonly file_data?: string | undefined;
1149
+ readonly file_url?: string | undefined;
1150
+ })[];
1151
+ } | {
1152
+ readonly type: "reasoning";
1153
+ readonly id?: string | undefined;
1154
+ readonly summary: readonly {
1155
+ readonly type: "summary_text";
1156
+ readonly text: string;
1157
+ }[];
1158
+ readonly encrypted_content?: string | null | undefined;
1159
+ } | {
1160
+ readonly type: "compaction";
1161
+ readonly id?: string | null | undefined;
1162
+ readonly encrypted_content: string;
1163
+ } | {
1164
+ readonly type: "message";
1165
+ readonly role: "user";
1166
+ readonly content: readonly ({
1167
+ readonly type: "input_text";
1168
+ readonly text: string;
1169
+ } | {
1170
+ readonly type: "input_video";
1171
+ readonly video_url: string;
1172
+ } | {
1173
+ readonly type: "input_image";
1174
+ readonly image_url: string;
1175
+ readonly detail?: string | undefined;
1176
+ } | {
1177
+ readonly type: "input_file";
1178
+ readonly filename?: string | undefined;
1179
+ readonly detail?: string | undefined;
1180
+ readonly file_data?: string | undefined;
1181
+ readonly file_url?: string | undefined;
1182
+ })[];
1183
+ readonly id?: string | undefined;
1184
+ readonly status?: string | undefined;
1185
+ } | {
1186
+ readonly type: "message";
1187
+ readonly id?: string | undefined;
1188
+ readonly role: "assistant";
1189
+ readonly content: readonly {
1190
+ readonly type: "output_text";
1191
+ readonly text: string;
1192
+ }[];
1193
+ readonly phase?: "commentary" | "final_answer" | null | undefined;
1194
+ readonly status?: string | undefined;
1195
+ } | {
1196
+ readonly type: "function_call";
1197
+ readonly id?: string | undefined;
1198
+ readonly call_id: string;
1199
+ readonly name: string;
1200
+ readonly namespace?: string | undefined;
1201
+ readonly arguments: string;
1202
+ } | {
1203
+ readonly type: "custom_tool_call";
1204
+ readonly id?: string | undefined;
1205
+ readonly call_id: string;
1206
+ readonly name: string;
1207
+ readonly input: string;
1208
+ } | {
1209
+ readonly [x: string]: unknown;
1210
+ readonly type: "web_search_call";
1211
+ readonly id: string;
1212
+ readonly status?: string | undefined;
1213
+ readonly action?: {
1214
+ readonly [x: string]: unknown;
1215
+ } | null | undefined;
1216
+ } | {
1217
+ readonly [x: string]: unknown;
1218
+ readonly type: "file_search_call";
1219
+ readonly id: string;
1220
+ readonly status?: string | undefined;
1221
+ readonly queries?: readonly string[] | undefined;
1222
+ readonly results?: readonly {
1223
+ readonly [x: string]: unknown;
1224
+ }[] | null | undefined;
1225
+ } | {
1226
+ readonly [x: string]: unknown;
1227
+ readonly type: "code_interpreter_call";
1228
+ readonly id: string;
1229
+ readonly status?: string | undefined;
1230
+ readonly code?: string | null | undefined;
1231
+ readonly container_id?: string | null | undefined;
1232
+ readonly outputs?: readonly {
1233
+ readonly [x: string]: unknown;
1234
+ }[] | null | undefined;
1235
+ } | {
1236
+ readonly [x: string]: unknown;
1237
+ readonly type: "mcp_call";
1238
+ readonly id: string;
1239
+ readonly status?: string | undefined;
1240
+ readonly server_label?: string | undefined;
1241
+ readonly name?: string | undefined;
1242
+ readonly arguments?: string | undefined;
1243
+ readonly output?: string | null | undefined;
1244
+ readonly error?: unknown;
1245
+ } | {
1246
+ readonly [x: string]: unknown;
1247
+ readonly type: string;
1248
+ readonly id: string;
1249
+ })[], AIError, never>;
1090
1250
  export declare const lowerConversation: (request: LLMRequest<import("../schema/options.js").LanguageModel<{
1091
1251
  readonly [x: string]: unknown;
1092
1252
  }, import("../route.js").CompactionOperations | undefined>>, adapter: ProviderAdapter) => Effect.Effect<{
@@ -1207,49 +1367,11 @@ export declare const lowerConversation: (request: LLMRequest<import("../schema/o
1207
1367
  readonly call_id: string;
1208
1368
  readonly name: string;
1209
1369
  readonly input: string;
1210
- } | {
1211
- readonly [x: string]: unknown;
1212
- readonly type: "web_search_call";
1213
- readonly id: string;
1214
- readonly status?: string | undefined;
1215
- readonly action?: {
1216
- readonly [x: string]: unknown;
1217
- } | null | undefined;
1218
- } | {
1219
- readonly [x: string]: unknown;
1220
- readonly type: "file_search_call";
1221
- readonly id: string;
1222
- readonly status?: string | undefined;
1223
- readonly queries?: readonly string[] | undefined;
1224
- readonly results?: readonly {
1225
- readonly [x: string]: unknown;
1226
- }[] | null | undefined;
1227
- } | {
1228
- readonly [x: string]: unknown;
1229
- readonly type: "code_interpreter_call";
1230
- readonly id: string;
1231
- readonly status?: string | undefined;
1232
- readonly code?: string | null | undefined;
1233
- readonly container_id?: string | null | undefined;
1234
- readonly outputs?: readonly {
1235
- readonly [x: string]: unknown;
1236
- }[] | null | undefined;
1237
- } | {
1238
- readonly [x: string]: unknown;
1239
- readonly type: "mcp_call";
1240
- readonly id: string;
1241
- readonly status?: string | undefined;
1242
- readonly server_label?: string | undefined;
1243
- readonly name?: string | undefined;
1244
- readonly arguments?: string | undefined;
1245
- readonly output?: string | null | undefined;
1246
- readonly error?: unknown;
1247
1370
  } | {
1248
1371
  readonly [x: string]: unknown;
1249
1372
  readonly type: string;
1250
1373
  readonly id: string;
1251
1374
  })[];
1252
- instructions?: string | undefined;
1253
1375
  }, AIError, never>;
1254
1376
  export declare const lowerGeneration: (request: LLMRequest, options?: OpenResponsesOptions.Resolved) => {
1255
1377
  stream: true;
@@ -1410,49 +1532,11 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
1410
1532
  readonly call_id: string;
1411
1533
  readonly name: string;
1412
1534
  readonly input: string;
1413
- } | {
1414
- readonly [x: string]: unknown;
1415
- readonly type: "web_search_call";
1416
- readonly id: string;
1417
- readonly status?: string | undefined;
1418
- readonly action?: {
1419
- readonly [x: string]: unknown;
1420
- } | null | undefined;
1421
- } | {
1422
- readonly [x: string]: unknown;
1423
- readonly type: "file_search_call";
1424
- readonly id: string;
1425
- readonly status?: string | undefined;
1426
- readonly queries?: readonly string[] | undefined;
1427
- readonly results?: readonly {
1428
- readonly [x: string]: unknown;
1429
- }[] | null | undefined;
1430
- } | {
1431
- readonly [x: string]: unknown;
1432
- readonly type: "code_interpreter_call";
1433
- readonly id: string;
1434
- readonly status?: string | undefined;
1435
- readonly code?: string | null | undefined;
1436
- readonly container_id?: string | null | undefined;
1437
- readonly outputs?: readonly {
1438
- readonly [x: string]: unknown;
1439
- }[] | null | undefined;
1440
- } | {
1441
- readonly [x: string]: unknown;
1442
- readonly type: "mcp_call";
1443
- readonly id: string;
1444
- readonly status?: string | undefined;
1445
- readonly server_label?: string | undefined;
1446
- readonly name?: string | undefined;
1447
- readonly arguments?: string | undefined;
1448
- readonly output?: string | null | undefined;
1449
- readonly error?: unknown;
1450
1535
  } | {
1451
1536
  readonly [x: string]: unknown;
1452
1537
  readonly type: string;
1453
1538
  readonly id: string;
1454
1539
  })[];
1455
- instructions?: string | undefined;
1456
1540
  stream: true;
1457
1541
  max_output_tokens: number | undefined;
1458
1542
  temperature: number | undefined;
@@ -1634,49 +1718,11 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1634
1718
  readonly call_id: string;
1635
1719
  readonly name: string;
1636
1720
  readonly input: string;
1637
- } | {
1638
- readonly [x: string]: unknown;
1639
- readonly type: "web_search_call";
1640
- readonly id: string;
1641
- readonly status?: string | undefined;
1642
- readonly action?: {
1643
- readonly [x: string]: unknown;
1644
- } | null | undefined;
1645
- } | {
1646
- readonly [x: string]: unknown;
1647
- readonly type: "file_search_call";
1648
- readonly id: string;
1649
- readonly status?: string | undefined;
1650
- readonly queries?: readonly string[] | undefined;
1651
- readonly results?: readonly {
1652
- readonly [x: string]: unknown;
1653
- }[] | null | undefined;
1654
- } | {
1655
- readonly [x: string]: unknown;
1656
- readonly type: "code_interpreter_call";
1657
- readonly id: string;
1658
- readonly status?: string | undefined;
1659
- readonly code?: string | null | undefined;
1660
- readonly container_id?: string | null | undefined;
1661
- readonly outputs?: readonly {
1662
- readonly [x: string]: unknown;
1663
- }[] | null | undefined;
1664
- } | {
1665
- readonly [x: string]: unknown;
1666
- readonly type: "mcp_call";
1667
- readonly id: string;
1668
- readonly status?: string | undefined;
1669
- readonly server_label?: string | undefined;
1670
- readonly name?: string | undefined;
1671
- readonly arguments?: string | undefined;
1672
- readonly output?: string | null | undefined;
1673
- readonly error?: unknown;
1674
1721
  } | {
1675
1722
  readonly [x: string]: unknown;
1676
1723
  readonly type: string;
1677
1724
  readonly id: string;
1678
1725
  })[];
1679
- instructions?: string | undefined;
1680
1726
  stream: true;
1681
1727
  max_output_tokens: number | undefined;
1682
1728
  temperature: number | undefined;
@@ -450,7 +450,7 @@ const lowerToolResultOutput = Effect.fnUntraced(function* (part, request, adapte
450
450
  return yield* Effect.forEach(content, (item) => lowerToolResultContentItem(item, request, adapter));
451
451
  });
452
452
  const DEFAULT_EFFORT = "medium";
453
- const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
453
+ export const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
454
454
  const input = [];
455
455
  const providerMetadataKey = metadataKey(request.model);
456
456
  const custom = OpenAIFreeform.tools(request);
@@ -613,12 +613,15 @@ const lowerMessages = Effect.fnUntraced(function* (request, adapter) {
613
613
  }
614
614
  return input;
615
615
  });
616
+ // The system prompt leads `input` as a developer message: GPT-6.2 models never cache top-level `instructions`.
616
617
  export const lowerConversation = Effect.fnUntraced(function* (request, adapter) {
617
- const instructions = ProviderShared.joinText(request.system);
618
+ const system = ProviderShared.joinText(request.system);
618
619
  return {
619
620
  model: request.model.id,
620
- input: yield* lowerMessages(request, adapter),
621
- ...(instructions ? { instructions } : {}),
621
+ input: [
622
+ ...(system ? [{ type: "message", role: "developer", content: system }] : []),
623
+ ...(yield* lowerMessages(request, adapter)),
624
+ ],
622
625
  };
623
626
  });
624
627
  export const lowerGeneration = (request, options = OpenResponsesOptions.resolve(request)) => {
@@ -248,7 +248,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
248
248
  lowerToolChanges: toolChangeLowering(layout.head.length > 0, custom),
249
249
  });
250
250
  return {
251
- ...conversation,
251
+ model: conversation.model,
252
252
  input: [...layout.head, ...conversation.input],
253
253
  ...generation,
254
254
  ...Cache.openAIRequestTTL(requestTTL(request)),
@@ -58,6 +58,8 @@ const Response = Schema.Struct({
58
58
  role: Schema.Literal("assistant"),
59
59
  content: Schema.Array(Text).check(Schema.isMinLength(1)),
60
60
  }),
61
+ // The system prompt sent as a developer message, echoed back; the next request leads with its own.
62
+ Schema.Struct({ ...MessageFields, role: Schema.Literal("developer"), content: Schema.Unknown }),
61
63
  ])),
62
64
  usage: Schema.optional(Schema.StructWithRest(OpenResponses.OpenResponsesUsage, [JsonObject])),
63
65
  });
@@ -67,6 +69,8 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
67
69
  // top-level `tools`: after compacting a history whose tools were only in `additional_tools`, small models lost
68
70
  // track of them more often.
69
71
  const folded = foldToolUpdates(stripEffortUpdates(request));
72
+ // The system prompt leads `input` as a developer message, as every step's request does, so `/compact` reads the
73
+ // prefix those requests cached.
70
74
  const native = yield* OpenResponses.lowerConversation(folded, adapter);
71
75
  const generation = OpenResponses.lowerGeneration(request);
72
76
  const tools = folded.tools.length === 0 ? undefined : yield* lowerTools(folded);
@@ -112,7 +116,9 @@ export const make = (adapter, lowerTools) => Effect.fn("ResponsesCompaction.exec
112
116
  if (!result.output.some((item) => item.type === "compaction"))
113
117
  return yield* invalid("Compaction response did not contain a checkpoint");
114
118
  return new CompactionResponse({
115
- replacement: result.output.map((item) => toMessage(item, request.model)),
119
+ replacement: result.output
120
+ .filter((item) => item.type !== "message" || item.role !== "developer")
121
+ .map((item) => toMessage(item, request.model)),
116
122
  usage: OpenResponses.mapUsage(result.usage, OpenResponses.metadataKey(request.model)),
117
123
  });
118
124
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -624,7 +624,7 @@
624
624
  "devDependencies": {
625
625
  "@clack/prompts": "1.0.0-alpha.1",
626
626
  "@effect/platform-node": "4.1.0",
627
- "@opencode/http-recorder": "2.3.1",
627
+ "@opencode/http-recorder": "2.3.2",
628
628
  "@tsconfig/bun": "1.0.9",
629
629
  "@types/bun": "1.4.3",
630
630
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -634,7 +634,7 @@
634
634
  "@aws-sdk/credential-providers": "3.1057.0",
635
635
  "@smithy/eventstream-codec": "4.2.14",
636
636
  "@smithy/util-utf8": "4.2.2",
637
- "@opencode/schema": "2.3.1",
637
+ "@opencode/schema": "2.3.2",
638
638
  "aws4fetch": "1.0.20",
639
639
  "effect": "4.1.0",
640
640
  "google-auth-library": "10.5.0"