190proof 1.0.8 → 1.0.10

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
- mimetype: string;
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
- mimetype: string;
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) {
@@ -31868,7 +31875,7 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31868
31875
  console.log(identifier, "Delegating call to Anthropic API");
31869
31876
  return await callAnthropicWithRetries(
31870
31877
  identifier,
31871
- prepareAnthropicPayload(aiPayload),
31878
+ await prepareAnthropicPayload(aiPayload),
31872
31879
  aiConfig,
31873
31880
  retries
31874
31881
  );
@@ -31876,14 +31883,17 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31876
31883
  console.log(identifier, "Delegating call to OpenAI API");
31877
31884
  return await callOpenAiWithRetries(
31878
31885
  identifier,
31879
- prepareOpenAIPayload(aiPayload),
31886
+ await prepareOpenAIPayload(aiPayload),
31880
31887
  aiConfig,
31881
31888
  retries,
31882
31889
  chunkTimeoutMs
31883
31890
  );
31884
31891
  } else if (isGroqPayload(aiPayload)) {
31885
31892
  console.log(identifier, "Delegating call to Groq API");
31886
- return await callGroqWithRetries(identifier, prepareGroqPayload(aiPayload));
31893
+ return await callGroqWithRetries(
31894
+ identifier,
31895
+ await prepareGroqPayload(aiPayload)
31896
+ );
31887
31897
  } else {
31888
31898
  throw new Error("Invalid AI payload: Unknown model type.");
31889
31899
  }
@@ -31891,31 +31901,110 @@ async function callWithRetries(identifier, aiPayload, aiConfig, retries = 5, chu
31891
31901
  function isAnthropicPayload(payload) {
31892
31902
  return Object.values(ClaudeModel).includes(payload.model);
31893
31903
  }
31894
- function prepareAnthropicPayload(payload) {
31895
- return {
31904
+ async function prepareAnthropicPayload(payload) {
31905
+ const preparedPayload = {
31896
31906
  model: payload.model,
31897
- messages: payload.messages.map((message) => ({
31898
- role: message.role,
31899
- content: message.content
31900
- // TODO: Handle files
31901
- })),
31907
+ messages: [],
31902
31908
  functions: payload.functions
31903
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;
31904
31958
  }
31905
31959
  function isOpenAiPayload(payload) {
31906
31960
  return Object.values(GPTModel).includes(payload.model);
31907
31961
  }
31908
- function prepareOpenAIPayload(payload) {
31909
- return {
31962
+ async function prepareOpenAIPayload(payload) {
31963
+ const preparedPayload = {
31910
31964
  model: payload.model,
31911
- messages: payload.messages.map((message) => ({
31912
- role: message.role,
31913
- content: normalizeMessageContent(message.content)
31914
- // TODO: Handle files
31915
- })),
31916
- functions: payload.functions,
31917
- function_call: payload.function_call
31965
+ messages: [],
31966
+ functions: payload.functions
31918
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;
31919
32008
  }
31920
32009
  function isGroqPayload(payload) {
31921
32010
  return Object.values(GroqModel).includes(payload.model);
@@ -31997,6 +32086,25 @@ async function callGroqWithRetries(identifier, payload, retries = 5) {
31997
32086
  error.response = lastResponse;
31998
32087
  throw error;
31999
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
+ }
32000
32108
  // Annotate the CommonJS export names for ESM import in node:
32001
32109
  0 && (module.exports = {
32002
32110
  ClaudeModel,