190proof 1.0.6 → 1.0.9

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/index.d.mts CHANGED
@@ -16,30 +16,16 @@ declare enum GroqModel {
16
16
  }
17
17
  interface GenericMessage {
18
18
  role: "user" | "assistant" | "system";
19
- content: string | AnthropicContentBlock[];
19
+ content: string;
20
20
  timestamp?: string;
21
21
  files?: File[];
22
22
  functionCalls?: FunctionCall[];
23
23
  }
24
24
  interface File {
25
- name: string;
26
25
  mimetype: string;
27
26
  url?: string;
28
27
  data?: string;
29
28
  }
30
- type AnthropicContentBlock = AnthropicTextContentBlock | AnthropicImageContentBlock;
31
- interface AnthropicTextContentBlock {
32
- type: "text";
33
- text: string;
34
- }
35
- interface AnthropicImageContentBlock {
36
- type: "image";
37
- source: {
38
- type: "base64";
39
- media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
40
- data: string;
41
- };
42
- }
43
29
  interface ParsedResponseMessage {
44
30
  role: "assistant";
45
31
  content: string | null;
@@ -85,4 +71,4 @@ interface GenericPayload {
85
71
 
86
72
  declare function callWithRetries(identifier: string, aiPayload: GenericPayload, aiConfig?: OpenAIConfig | AnthropicAIConfig, retries?: number, chunkTimeoutMs?: number): Promise<ParsedResponseMessage>;
87
73
 
88
- export { ClaudeModel, type FunctionDefinition, GPTModel, GroqModel, type OpenAIConfig, callWithRetries };
74
+ export { ClaudeModel, type FunctionDefinition, GPTModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, callWithRetries };
package/dist/index.d.ts CHANGED
@@ -16,30 +16,16 @@ declare enum GroqModel {
16
16
  }
17
17
  interface GenericMessage {
18
18
  role: "user" | "assistant" | "system";
19
- content: string | AnthropicContentBlock[];
19
+ content: string;
20
20
  timestamp?: string;
21
21
  files?: File[];
22
22
  functionCalls?: FunctionCall[];
23
23
  }
24
24
  interface File {
25
- name: string;
26
25
  mimetype: string;
27
26
  url?: string;
28
27
  data?: string;
29
28
  }
30
- type AnthropicContentBlock = AnthropicTextContentBlock | AnthropicImageContentBlock;
31
- interface AnthropicTextContentBlock {
32
- type: "text";
33
- text: string;
34
- }
35
- interface AnthropicImageContentBlock {
36
- type: "image";
37
- source: {
38
- type: "base64";
39
- media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
40
- data: string;
41
- };
42
- }
43
29
  interface ParsedResponseMessage {
44
30
  role: "assistant";
45
31
  content: string | null;
@@ -85,4 +71,4 @@ interface GenericPayload {
85
71
 
86
72
  declare function callWithRetries(identifier: string, aiPayload: GenericPayload, aiConfig?: OpenAIConfig | AnthropicAIConfig, retries?: number, chunkTimeoutMs?: number): Promise<ParsedResponseMessage>;
87
73
 
88
- export { ClaudeModel, type FunctionDefinition, GPTModel, GroqModel, type OpenAIConfig, callWithRetries };
74
+ export { ClaudeModel, type FunctionDefinition, GPTModel, type GenericMessage, type GenericPayload, GroqModel, type OpenAIConfig, callWithRetries };
package/dist/index.js CHANGED
@@ -31423,8 +31423,15 @@ var {
31423
31423
  function timeout(ms) {
31424
31424
  return new Promise((resolve) => setTimeout(resolve, ms));
31425
31425
  }
31426
+ function isHeicImage(name, mime) {
31427
+ var _a3;
31428
+ const extension = ((_a3 = name.split(".").pop()) == null ? void 0 : _a3.toLowerCase()) || "";
31429
+ return ["heic", "heif", "heics"].includes(extension) || !!(mime && ["image/heic", "image/heif", "image/heic-sequence"].includes(mime));
31430
+ }
31426
31431
 
31427
31432
  // index.ts
31433
+ var sharp = require("sharp");
31434
+ var decode = require("heic-decode");
31428
31435
  function parseStreamedResponse(identifier, paragraph, functionCallName, functionCallArgs, allowedFunctionNames) {
31429
31436
  let functionCall = null;
31430
31437
  if (functionCallName && functionCallArgs) {
@@ -31538,7 +31545,6 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
31538
31545
  baseUrl: defaultOpenAIBaseUrl
31539
31546
  };
31540
31547
  }
31541
- console.log("payload", openAiPayload);
31542
31548
  let response;
31543
31549
  const controller = new AbortController();
31544
31550
  if (openAiConfig.service === "azure") {
@@ -31869,7 +31875,7 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31869
31875
  console.log(identifier, "Delegating call to Anthropic API");
31870
31876
  return await callAnthropicWithRetries(
31871
31877
  identifier,
31872
- prepareAnthropicPayload(aiPayload),
31878
+ await prepareAnthropicPayload(aiPayload),
31873
31879
  aiConfig,
31874
31880
  retries
31875
31881
  );
@@ -31877,14 +31883,17 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31877
31883
  console.log(identifier, "Delegating call to OpenAI API");
31878
31884
  return await callOpenAiWithRetries(
31879
31885
  identifier,
31880
- prepareOpenAIPayload(aiPayload),
31886
+ await prepareOpenAIPayload(aiPayload),
31881
31887
  aiConfig,
31882
31888
  retries,
31883
31889
  chunkTimeoutMs
31884
31890
  );
31885
31891
  } else if (isGroqPayload(aiPayload)) {
31886
31892
  console.log(identifier, "Delegating call to Groq API");
31887
- return await callGroqWithRetries(identifier, prepareGroqPayload(aiPayload));
31893
+ return await callGroqWithRetries(
31894
+ identifier,
31895
+ await prepareGroqPayload(aiPayload)
31896
+ );
31888
31897
  } else {
31889
31898
  throw new Error("Invalid AI payload: Unknown model type.");
31890
31899
  }
@@ -31892,31 +31901,110 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31892
31901
  function isAnthropicPayload(payload) {
31893
31902
  return Object.values(ClaudeModel).includes(payload.model);
31894
31903
  }
31895
- function prepareAnthropicPayload(payload) {
31896
- return {
31904
+ async function prepareAnthropicPayload(payload) {
31905
+ const preparedPayload = {
31897
31906
  model: payload.model,
31898
- messages: payload.messages.map((message) => ({
31899
- role: message.role,
31900
- content: message.content
31901
- // TODO: Handle files
31902
- })),
31907
+ messages: [],
31903
31908
  functions: payload.functions
31904
31909
  };
31910
+ for (const message of payload.messages) {
31911
+ const anthropicContentBlocks = [];
31912
+ if (message.content) {
31913
+ anthropicContentBlocks.push({
31914
+ type: "text",
31915
+ text: message.content
31916
+ });
31917
+ }
31918
+ for (const file of message.files || []) {
31919
+ if (!file.mimetype.startsWith("image")) {
31920
+ console.warn(
31921
+ "Anthropic API does not support non-image file types. Skipping file."
31922
+ );
31923
+ continue;
31924
+ }
31925
+ if (file.url) {
31926
+ anthropicContentBlocks.push({
31927
+ type: "image",
31928
+ source: {
31929
+ type: "base64",
31930
+ media_type: "image/png",
31931
+ data: await getNormalizedBase64PNG(file.url, file.mimetype)
31932
+ }
31933
+ });
31934
+ } else if (file.data) {
31935
+ if (!["image/png", "image/jpeg", "image/gif", "image/webp"].includes(
31936
+ file.mimetype
31937
+ )) {
31938
+ throw new Error(
31939
+ "Invalid image mimetype. Supported types are: image/png, image/jpeg, image/gif, image/webp"
31940
+ );
31941
+ }
31942
+ anthropicContentBlocks.push({
31943
+ type: "image",
31944
+ source: {
31945
+ type: "base64",
31946
+ media_type: file.mimetype,
31947
+ data: file.data
31948
+ }
31949
+ });
31950
+ }
31951
+ }
31952
+ preparedPayload.messages.push({
31953
+ role: message.role,
31954
+ content: anthropicContentBlocks
31955
+ });
31956
+ }
31957
+ return preparedPayload;
31905
31958
  }
31906
31959
  function isOpenAiPayload(payload) {
31907
31960
  return Object.values(GPTModel).includes(payload.model);
31908
31961
  }
31909
- function prepareOpenAIPayload(payload) {
31910
- return {
31962
+ async function prepareOpenAIPayload(payload) {
31963
+ const preparedPayload = {
31911
31964
  model: payload.model,
31912
- messages: payload.messages.map((message) => ({
31913
- role: message.role,
31914
- content: normalizeMessageContent(message.content)
31915
- // TODO: Handle files
31916
- })),
31917
- functions: payload.functions,
31918
- function_call: payload.function_call
31965
+ messages: [],
31966
+ functions: payload.functions
31919
31967
  };
31968
+ for (const message of payload.messages) {
31969
+ const openAIContentBlocks = [];
31970
+ if (message.content) {
31971
+ openAIContentBlocks.push({
31972
+ type: "text",
31973
+ text: message.content
31974
+ });
31975
+ }
31976
+ for (const file of message.files || []) {
31977
+ if (!file.mimetype.startsWith("image")) {
31978
+ console.warn(
31979
+ "OpenAI API does not support non-image file types. Skipping file."
31980
+ );
31981
+ continue;
31982
+ }
31983
+ if (file.url) {
31984
+ openAIContentBlocks.push({
31985
+ type: "image_url",
31986
+ image_url: {
31987
+ url: `data:image/png;base64,${await getNormalizedBase64PNG(
31988
+ file.url,
31989
+ file.mimetype
31990
+ )}`
31991
+ }
31992
+ });
31993
+ } else if (file.data) {
31994
+ openAIContentBlocks.push({
31995
+ type: "image_url",
31996
+ image_url: {
31997
+ url: `data:${file.mimetype};base64,${file.data}`
31998
+ }
31999
+ });
32000
+ }
32001
+ }
32002
+ preparedPayload.messages.push({
32003
+ role: message.role,
32004
+ content: openAIContentBlocks
32005
+ });
32006
+ }
32007
+ return preparedPayload;
31920
32008
  }
31921
32009
  function isGroqPayload(payload) {
31922
32010
  return Object.values(GroqModel).includes(payload.model);
@@ -31998,6 +32086,25 @@ async function callGroqWithRetries(identifier, payload, retries = 5) {
31998
32086
  error.response = lastResponse;
31999
32087
  throw error;
32000
32088
  }
32089
+ async function getNormalizedBase64PNG(url2, mime) {
32090
+ console.log("Normalizing image", url2);
32091
+ const response = await axios_default.get(url2, { responseType: "arraybuffer" });
32092
+ let imageBuffer = Buffer.from(response.data);
32093
+ let sharpOptions = {};
32094
+ if (isHeicImage(url2, mime)) {
32095
+ const imageData = await decode({ buffer: imageBuffer });
32096
+ imageBuffer = Buffer.from(imageData.data);
32097
+ sharpOptions = {
32098
+ raw: {
32099
+ width: imageData.width,
32100
+ height: imageData.height,
32101
+ channels: 4
32102
+ }
32103
+ };
32104
+ }
32105
+ const resizedBuffer = await sharp(imageBuffer, sharpOptions).withMetadata().resize(1024, 1024, { fit: "inside", withoutEnlargement: true }).png().toBuffer();
32106
+ return resizedBuffer.toString("base64");
32107
+ }
32001
32108
  // Annotate the CommonJS export names for ESM import in node:
32002
32109
  0 && (module.exports = {
32003
32110
  ClaudeModel,