@effect/ai-openai 4.0.0-beta.54 → 4.0.0-beta.56

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.
@@ -1158,13 +1158,17 @@ const makeResponse = Effect.fnUntraced(
1158
1158
  ? (approvalRequests.get(part.approval_request_id) ?? part.id)
1159
1159
  : part.id
1160
1160
 
1161
- const toolName = `mcp.${part.name}`
1161
+ const { toolName, params } = yield* normalizeMcpToolCall({
1162
+ toolNameMapper,
1163
+ toolParams: part.arguments,
1164
+ method: "makeResponse"
1165
+ })
1162
1166
 
1163
1167
  parts.push({
1164
1168
  type: "tool-call",
1165
1169
  id: toolId,
1166
1170
  name: toolName,
1167
- params: part.arguments,
1171
+ params,
1168
1172
  providerExecuted: true
1169
1173
  })
1170
1174
 
@@ -1175,7 +1179,7 @@ const makeResponse = Effect.fnUntraced(
1175
1179
  isFailure: false,
1176
1180
  providerExecuted: true,
1177
1181
  result: {
1178
- type: "call",
1182
+ type: "mcp_call",
1179
1183
  name: part.name,
1180
1184
  arguments: part.arguments,
1181
1185
  server_label: part.server_label,
@@ -1196,25 +1200,11 @@ const makeResponse = Effect.fnUntraced(
1196
1200
  case "mcp_approval_request": {
1197
1201
  const approvalRequestId = (part as any).approval_request_id ?? part.id
1198
1202
  const toolId = yield* idGenerator.generateId()
1199
- const toolName = `mcp.${part.name}`
1200
-
1201
- const params = yield* Effect.try({
1202
- try: () =>
1203
- Tool.unsafeSecureJsonParse(
1204
- typeof part.arguments === "string"
1205
- ? part.arguments
1206
- : JSON.stringify(part.arguments)
1207
- ),
1208
- catch: (cause) =>
1209
- AiError.make({
1210
- module: "OpenAiLanguageModel",
1211
- method: "makeResponse",
1212
- reason: new AiError.ToolParameterValidationError({
1213
- toolName,
1214
- toolParams: {},
1215
- description: `Failed securely JSON parse tool parameters: ${cause}`
1216
- })
1217
- })
1203
+
1204
+ const { toolName, params } = yield* normalizeMcpToolCall({
1205
+ toolNameMapper,
1206
+ toolParams: part.arguments,
1207
+ method: "makeResponse"
1218
1208
  })
1219
1209
 
1220
1210
  parts.push({
@@ -1903,13 +1893,17 @@ const makeStreamResponse = Effect.fnUntraced(
1903
1893
  event.item.id)
1904
1894
  : event.item.id
1905
1895
 
1906
- const toolName = `mcp.${event.item.name}`
1896
+ const { toolName, params } = yield* normalizeMcpToolCall({
1897
+ toolNameMapper,
1898
+ toolParams: event.item.arguments,
1899
+ method: "makeStreamResponse"
1900
+ })
1907
1901
 
1908
1902
  parts.push({
1909
1903
  type: "tool-call",
1910
1904
  id: toolId,
1911
1905
  name: toolName,
1912
- params: event.item.arguments,
1906
+ params,
1913
1907
  providerExecuted: true
1914
1908
  })
1915
1909
 
@@ -1920,7 +1914,7 @@ const makeStreamResponse = Effect.fnUntraced(
1920
1914
  isFailure: false,
1921
1915
  providerExecuted: true,
1922
1916
  result: {
1923
- type: "call",
1917
+ type: "mcp_call",
1924
1918
  name: event.item.name,
1925
1919
  arguments: event.item.arguments,
1926
1920
  server_label: event.item.server_label,
@@ -1942,12 +1936,16 @@ const makeStreamResponse = Effect.fnUntraced(
1942
1936
  const toolId = yield* idGenerator.generateId()
1943
1937
  const approvalRequestId = (event.item as any).approval_request_id ?? event.item.id
1944
1938
  streamApprovalRequests.set(approvalRequestId, toolId)
1945
- const toolName = `mcp.${event.item.name}`
1939
+ const { toolName, params } = yield* normalizeMcpToolCall({
1940
+ toolNameMapper,
1941
+ toolParams: event.item.arguments,
1942
+ method: "makeStreamResponse"
1943
+ })
1946
1944
  parts.push({
1947
1945
  type: "tool-call",
1948
1946
  id: toolId,
1949
1947
  name: toolName,
1950
- params: event.item.arguments,
1948
+ params,
1951
1949
  providerExecuted: true
1952
1950
  })
1953
1951
  parts.push({
@@ -2752,6 +2750,41 @@ const getApprovalRequestIdMapping = (prompt: Prompt.Prompt): ReadonlyMap<string,
2752
2750
  return mapping
2753
2751
  }
2754
2752
 
2753
+ const normalizeMcpToolCall = Effect.fnUntraced(function*<Tools extends ReadonlyArray<Tool.Any>>({
2754
+ toolNameMapper,
2755
+ toolParams,
2756
+ method
2757
+ }: {
2758
+ readonly toolNameMapper: Tool.NameMapper<Tools>
2759
+ readonly toolParams: unknown
2760
+ readonly method: string
2761
+ }): Effect.fn.Return<{
2762
+ readonly toolName: string
2763
+ readonly params: unknown
2764
+ }, AiError.AiError> {
2765
+ const toolName = toolNameMapper.getCustomName("mcp")
2766
+
2767
+ if (typeof toolParams !== "string") {
2768
+ return { toolName, params: toolParams }
2769
+ }
2770
+
2771
+ const params = yield* Effect.try({
2772
+ try: () => Tool.unsafeSecureJsonParse(toolParams),
2773
+ catch: (cause) =>
2774
+ AiError.make({
2775
+ module: "OpenAiLanguageModel",
2776
+ method,
2777
+ reason: new AiError.ToolParameterValidationError({
2778
+ toolName,
2779
+ toolParams,
2780
+ description: `Failed to securely JSON parse tool parameters: ${cause}`
2781
+ })
2782
+ })
2783
+ })
2784
+
2785
+ return { toolName, params }
2786
+ })
2787
+
2755
2788
  const getUsage = (usage: OpenAiSchema.ResponseUsage | null | undefined): Response.Usage => {
2756
2789
  if (Predicate.isNullish(usage)) {
2757
2790
  return {
@@ -40,6 +40,8 @@ export const MessageStatus = Schema.Literals(["in_progress", "completed", "incom
40
40
  */
41
41
  export type MessageStatus = typeof MessageStatus.Type
42
42
 
43
+ const PromptCacheRetention = Schema.Literals(["in-memory", "in_memory", "24h"])
44
+
43
45
  const InputTextContent = Schema.Struct({
44
46
  type: Schema.Literal("input_text"),
45
47
  text: Schema.String
@@ -417,6 +419,7 @@ export const CreateResponse = Schema.Struct({
417
419
  temperature: Schema.optional(Schema.Number),
418
420
  top_p: Schema.optional(Schema.Number),
419
421
  user: Schema.optional(Schema.String),
422
+ prompt_cache_retention: Schema.optional(PromptCacheRetention),
420
423
  service_tier: Schema.optional(Schema.String),
421
424
  previous_response_id: Schema.optional(Schema.String),
422
425
  model: Schema.optional(Schema.String),
@@ -582,6 +585,7 @@ export const Response = Schema.Struct({
582
585
  created_at: Schema.Number,
583
586
  output: Schema.Array(OutputItem),
584
587
  usage: Schema.optionalKey(Schema.NullOr(ResponseUsage)),
588
+ prompt_cache_retention: Schema.optionalKey(Schema.NullOr(PromptCacheRetention)),
585
589
  incomplete_details: Schema.optionalKey(
586
590
  Schema.NullOr(
587
591
  Schema.Struct({
package/src/OpenAiTool.ts CHANGED
@@ -174,6 +174,7 @@ export const Mcp = Tool.providerDefined({
174
174
  server_label: Generated.MCPTool.fields.server_label,
175
175
  server_url: Generated.MCPTool.fields.server_url
176
176
  }),
177
+ parameters: Schema.Unknown,
177
178
  success: Schema.Struct({
178
179
  type: Generated.MCPToolCall.fields.type,
179
180
  name: Generated.MCPToolCall.fields.name,
@@ -203,7 +204,7 @@ export const Shell = Tool.providerDefined({
203
204
  action: Generated.FunctionShellCall.fields.action
204
205
  }),
205
206
  success: Schema.Struct({
206
- output: Generated.FunctionShellCallOutputItemParam.fields.output
207
+ output: Generated.FunctionShellCallOutput.fields.output
207
208
  })
208
209
  })
209
210