@effect/ai-anthropic 0.20.0 → 0.21.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/ai-anthropic",
3
- "version": "0.20.0",
3
+ "version": "0.21.1",
4
4
  "description": "Effect modules for working with AI apis",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -14,7 +14,7 @@
14
14
  "@anthropic-ai/tokenizer": "^0.0.4"
15
15
  },
16
16
  "peerDependencies": {
17
- "@effect/ai": "^0.30.0",
17
+ "@effect/ai": "^0.31.1",
18
18
  "@effect/experimental": "^0.56.0",
19
19
  "@effect/platform": "^0.92.1",
20
20
  "effect": "^3.18.4"
@@ -584,13 +584,11 @@ const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect
584
584
  isLastPart ? getCacheControl(message) : undefined
585
585
  )
586
586
 
587
- const result = part.result._tag === "Right" ? part.result.right : part.result.left
588
- const isError = part.result._tag === "Left"
589
587
  content.push({
590
588
  type: "tool_result",
591
589
  tool_use_id: part.id,
592
- content: JSON.stringify(result),
593
- is_error: isError,
590
+ content: JSON.stringify(part.result),
591
+ is_error: part.isFailure,
594
592
  cache_control: cacheControl
595
593
  })
596
594
  }
@@ -689,21 +687,18 @@ const prepareMessages: (options: LanguageModel.ProviderOptions) => Effect.Effect
689
687
  }
690
688
 
691
689
  case "tool-result": {
692
- const result = part.result._tag === "Right"
693
- ? part.result.right
694
- : part.result.left
695
690
  if (part.name === "AnthropicCodeExecution") {
696
691
  content.push({
697
692
  type: "code_execution_tool_result",
698
693
  tool_use_id: part.id,
699
- content: result as any,
694
+ content: part.result as any,
700
695
  cache_control: cacheControl
701
696
  })
702
697
  } else if (part.name === "AnthropicWebSearch") {
703
698
  content.push({
704
699
  type: "web_search_tool_result",
705
700
  tool_use_id: part.id,
706
- content: result as any,
701
+ content: part.result as any,
707
702
  cache_control: cacheControl
708
703
  })
709
704
  } else {
@@ -842,14 +837,13 @@ const makeResponse: (
842
837
  }
843
838
 
844
839
  case "bash_code_execution_tool_result": {
845
- const result = part.content.type === "bash_code_execution_result"
846
- ? { _tag: "Right", right: part.content } as const
847
- : { _tag: "Left", left: part.content } as const
840
+ const isFailure = part.content.type === "bash_code_execution_tool_result_error"
848
841
  parts.push({
849
842
  type: "tool-result",
850
843
  id: part.tool_use_id,
851
844
  name: "AnthropicCodeExecution",
852
- result,
845
+ isFailure,
846
+ result: part.content,
853
847
  providerName: "code_execution",
854
848
  providerExecuted: true
855
849
  })
@@ -857,14 +851,13 @@ const makeResponse: (
857
851
  }
858
852
 
859
853
  case "code_execution_tool_result": {
860
- const result = part.content.type === "code_execution_result"
861
- ? { _tag: "Right", right: part.content } as const
862
- : { _tag: "Left", left: part.content } as const
854
+ const isFailure = part.content.type === "code_execution_tool_result_error"
863
855
  parts.push({
864
856
  type: "tool-result",
865
857
  id: part.tool_use_id,
866
858
  name: "AnthropicCodeExecution",
867
- result,
859
+ isFailure,
860
+ result: part.content,
868
861
  providerName: "code_execution",
869
862
  providerExecuted: true
870
863
  })
@@ -872,14 +865,13 @@ const makeResponse: (
872
865
  }
873
866
 
874
867
  case "text_editor_code_execution_tool_result": {
875
- const result = part.content.type === "text_editor_code_execution_tool_result_error"
876
- ? { _tag: "Left", left: part.content } as const
877
- : { _tag: "Right", right: part.content } as const
868
+ const isFailure = part.content.type === "text_editor_code_execution_tool_result_error"
878
869
  parts.push({
879
870
  type: "tool-result",
880
871
  id: part.tool_use_id,
881
872
  name: "AnthropicCodeExecution",
882
- result,
873
+ isFailure,
874
+ result: part.content,
883
875
  providerName: "code_execution",
884
876
  providerExecuted: true
885
877
  })
@@ -887,14 +879,13 @@ const makeResponse: (
887
879
  }
888
880
 
889
881
  case "web_search_tool_result": {
890
- const result = Array.isArray(part.content)
891
- ? { _tag: "Right", right: part.content } as const
892
- : { _tag: "Left", left: part.content } as const
882
+ const isFailure = !Array.isArray(part.content)
893
883
  parts.push({
894
884
  type: "tool-result",
895
885
  id: part.tool_use_id,
896
886
  name: "AnthropicWebSearch",
897
- result,
887
+ isFailure,
888
+ result: part.content,
898
889
  providerName: "web_search",
899
890
  providerExecuted: true
900
891
  })
@@ -967,6 +958,7 @@ const makeStreamResponse: (
967
958
  | "redacted_thinking"
968
959
  | "tool_use"
969
960
  | "server_tool_use"
961
+ | "web_fetch_tool_result"
970
962
  | "web_search_tool_result"
971
963
  | "code_execution_tool_result"
972
964
  | "bash_code_execution_tool_result"
@@ -1136,14 +1128,13 @@ const makeStreamResponse: (
1136
1128
  case "bash_code_execution_tool_result": {
1137
1129
  const toolUseId = event.content_block.tool_use_id
1138
1130
  const content = event.content_block.content
1139
- const result = content.type === "bash_code_execution_result"
1140
- ? { _tag: "Right", right: content } as const
1141
- : { _tag: "Left", left: content } as const
1131
+ const isFailure = content.type === "bash_code_execution_tool_result_error"
1142
1132
  parts.push({
1143
1133
  type: "tool-result",
1144
1134
  id: toolUseId,
1145
1135
  name: "AnthropicCodeExecution",
1146
- result,
1136
+ isFailure,
1137
+ result: content,
1147
1138
  providerName: "code_execution",
1148
1139
  providerExecuted: true
1149
1140
  })
@@ -1153,14 +1144,13 @@ const makeStreamResponse: (
1153
1144
  case "code_execution_tool_result": {
1154
1145
  const toolUseId = event.content_block.tool_use_id
1155
1146
  const content = event.content_block.content
1156
- const result = content.type === "code_execution_result"
1157
- ? { _tag: "Right", right: content } as const
1158
- : { _tag: "Left", left: content } as const
1147
+ const isFailure = content.type === "code_execution_tool_result_error"
1159
1148
  parts.push({
1160
1149
  type: "tool-result",
1161
1150
  id: toolUseId,
1162
1151
  name: "AnthropicCodeExecution",
1163
- result,
1152
+ isFailure,
1153
+ result: content,
1164
1154
  providerName: "code_execution",
1165
1155
  providerExecuted: true
1166
1156
  })
@@ -1170,14 +1160,13 @@ const makeStreamResponse: (
1170
1160
  case "text_editor_code_execution_tool_result": {
1171
1161
  const toolUseId = event.content_block.tool_use_id
1172
1162
  const content = event.content_block.content
1173
- const result = content.type === "text_editor_code_execution_tool_result_error"
1174
- ? { _tag: "Left", left: content } as const
1175
- : { _tag: "Right", right: content } as const
1163
+ const isFailure = content.type === "text_editor_code_execution_tool_result_error"
1176
1164
  parts.push({
1177
1165
  type: "tool-result",
1178
1166
  id: toolUseId,
1179
1167
  name: "AnthropicCodeExecution",
1180
- result,
1168
+ isFailure,
1169
+ result: content,
1181
1170
  providerName: "code_execution",
1182
1171
  providerExecuted: true
1183
1172
  })
@@ -1187,14 +1176,13 @@ const makeStreamResponse: (
1187
1176
  case "web_search_tool_result": {
1188
1177
  const toolUseId = event.content_block.tool_use_id
1189
1178
  const content = event.content_block.content
1190
- const result = Array.isArray(content)
1191
- ? { _tag: "Right", right: content } as const
1192
- : { _tag: "Left", left: content } as const
1179
+ const isFailure = !Array.isArray(content)
1193
1180
  parts.push({
1194
1181
  type: "tool-result",
1195
1182
  id: toolUseId,
1196
1183
  name: "AnthropicWebSearch",
1197
- result,
1184
+ isFailure,
1185
+ result: content,
1198
1186
  providerName: "web_search",
1199
1187
  providerExecuted: true
1200
1188
  })