@absolutejs/ai 0.2.11 → 0.3.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/dist/ai/index.js CHANGED
@@ -821,18 +821,15 @@ var mapBlockToResponsesFormat = (block) => {
821
821
  }
822
822
  if (block.type === "image") {
823
823
  return {
824
- image_url: {
825
- url: block.source.type === "url" ? block.source.url : `data:${block.source.media_type};base64,${block.source.data}`
826
- },
824
+ detail: "auto",
825
+ image_url: block.source.type === "url" ? block.source.url : `data:${block.source.media_type};base64,${block.source.data}`,
827
826
  type: "input_image"
828
827
  };
829
828
  }
830
829
  if (block.type === "document") {
831
- return {
832
- file: {
833
- file_data: block.source.type === "url" ? block.source.url : `data:${block.source.media_type};base64,${block.source.data}`,
834
- filename: block.name ?? "document.pdf"
835
- },
830
+ return block.source.type === "url" ? { file_url: block.source.url, type: "input_file" } : {
831
+ file_data: `data:${block.source.media_type};base64,${block.source.data}`,
832
+ filename: block.name ?? "document.pdf",
836
833
  type: "input_file"
837
834
  };
838
835
  }
@@ -864,7 +861,7 @@ var convertToolBlock = (block) => {
864
861
  }
865
862
  if (block.type === "tool_use") {
866
863
  if (block.providerData)
867
- return { ...block.providerData };
864
+ return Object.fromEntries(Object.entries(block.providerData).filter(([key]) => key !== "id"));
868
865
  return {
869
866
  arguments: typeof block.input === "string" ? block.input : JSON.stringify(block.input),
870
867
  call_id: block.id,
@@ -902,10 +899,30 @@ var buildInput = (messages) => {
902
899
  }
903
900
  return input;
904
901
  };
902
+ var isStrictCompatible = (schema) => {
903
+ if (Array.isArray(schema))
904
+ return schema.every(isStrictCompatible);
905
+ if (!isRecord(schema))
906
+ return true;
907
+ const { properties } = schema;
908
+ if (isRecord(properties)) {
909
+ const required = Array.isArray(schema.required) ? schema.required : [];
910
+ if (schema.additionalProperties !== false)
911
+ return false;
912
+ if (!Object.keys(properties).every((key) => required.includes(key)))
913
+ return false;
914
+ }
915
+ const nested = [schema.items, schema.anyOf];
916
+ for (const map of [properties, schema.$defs, schema.definitions])
917
+ if (isRecord(map))
918
+ nested.push(...Object.values(map));
919
+ return nested.every(isStrictCompatible);
920
+ };
905
921
  var mapToolDefinition = (tool) => ({
906
922
  description: tool.description,
907
923
  name: tool.name,
908
924
  parameters: tool.input_schema,
925
+ strict: isStrictCompatible(tool.input_schema),
909
926
  type: "function"
910
927
  });
911
928
  var buildTools = (tools, isImageModel) => {
@@ -940,9 +957,10 @@ var buildResponsesRequestBody = (params, isImageModel, capabilityModel = params.
940
957
  body.parallel_tool_calls = params.parallelToolCalls;
941
958
  }
942
959
  }
943
- if (typeof params.temperature === "number")
960
+ const samples = !isOpenAIReasoningModel(capabilityModel);
961
+ if (samples && typeof params.temperature === "number")
944
962
  body.temperature = params.temperature;
945
- if (typeof params.topP === "number")
963
+ if (samples && typeof params.topP === "number")
946
964
  body.top_p = params.topP;
947
965
  if (typeof params.maxTokens === "number")
948
966
  body.max_output_tokens = params.maxTokens;
@@ -5702,6 +5720,7 @@ var generateAI = async (options) => {
5702
5720
  let text = "";
5703
5721
  const toolCalls = [];
5704
5722
  const citations = [];
5723
+ const images = [];
5705
5724
  let usage;
5706
5725
  let metadata;
5707
5726
  for await (const chunk of stream) {
@@ -5737,6 +5756,11 @@ var generateAI = async (options) => {
5737
5756
  });
5738
5757
  } else if (chunk.type === "citation") {
5739
5758
  citations.push(chunk);
5759
+ } else if (chunk.type === "image") {
5760
+ if (!chunk.isPartial) {
5761
+ const { type: _type, ...image } = chunk;
5762
+ images.push(image);
5763
+ }
5740
5764
  } else if (chunk.type === "done") {
5741
5765
  usage = chunk.usage;
5742
5766
  metadata = chunk.metadata;
@@ -5746,6 +5770,7 @@ var generateAI = async (options) => {
5746
5770
  return {
5747
5771
  citations,
5748
5772
  contentBlocks,
5773
+ images,
5749
5774
  requestMessages,
5750
5775
  metadata,
5751
5776
  text,
@@ -5788,6 +5813,7 @@ var generateAIWithTools = async (options) => {
5788
5813
  } = options;
5789
5814
  const providerTools = toProviderTools(tools);
5790
5815
  const toolCalls = [];
5816
+ const images = [];
5791
5817
  let usage;
5792
5818
  let turns = 0;
5793
5819
  const executeCalls = async (messages, result) => {
@@ -5826,8 +5852,10 @@ var generateAIWithTools = async (options) => {
5826
5852
  tools: providerTools
5827
5853
  });
5828
5854
  usage = mergeUsage(usage, result.usage);
5855
+ images.push(...result.images);
5829
5856
  if (result.toolCalls.length === 0) {
5830
5857
  return {
5858
+ images,
5831
5859
  messages: result.requestMessages ?? messages,
5832
5860
  stopReason: "completed",
5833
5861
  text: result.text,
@@ -5846,7 +5874,9 @@ var generateAIWithTools = async (options) => {
5846
5874
  tools: providerTools
5847
5875
  });
5848
5876
  usage = mergeUsage(usage, final.usage);
5877
+ images.push(...final.images);
5849
5878
  return {
5879
+ images,
5850
5880
  messages: final.requestMessages ?? nextMessages,
5851
5881
  stopReason: "max_turns_finalized",
5852
5882
  text: final.text,
@@ -5978,6 +6008,7 @@ var streamAIWithTools = async function* (options) {
5978
6008
  const messages = [...options.messages];
5979
6009
  let usage;
5980
6010
  let fullText = "";
6011
+ const images = [];
5981
6012
  let turn = 0;
5982
6013
  const streamOneTurn = async function* (selectedToolChoice = toolChoice ?? "auto") {
5983
6014
  const request = {
@@ -6022,6 +6053,11 @@ var streamAIWithTools = async function* (options) {
6022
6053
  fullText += chunk.content;
6023
6054
  pushText(blocks, chunk.content);
6024
6055
  yield { content: chunk.content, type: "text" };
6056
+ } else if (chunk.type === "image") {
6057
+ const { type: _type, ...image } = chunk;
6058
+ if (!image.isPartial)
6059
+ images.push(image);
6060
+ yield { ...image, type: "image" };
6025
6061
  } else if (chunk.type === "audio") {
6026
6062
  yield {
6027
6063
  audioId: chunk.audioId,
@@ -6134,6 +6170,7 @@ var streamAIWithTools = async function* (options) {
6134
6170
  }
6135
6171
  }
6136
6172
  const summary = {
6173
+ images,
6137
6174
  text: fullText,
6138
6175
  toolCalls: allToolCalls,
6139
6176
  turns: turn,
@@ -8923,5 +8960,5 @@ export {
8923
8960
  xai
8924
8961
  };
8925
8962
 
8926
- //# debugId=DDEEE4C7832FA25964756E2164756E21
8963
+ //# debugId=76B9C09CA62B3EF264756E2164756E21
8927
8964
  //# sourceMappingURL=index.js.map