modelfusion 0.66.1 → 0.68.0

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.
Files changed (102) hide show
  1. package/browser/invokeFlow.cjs +1 -1
  2. package/browser/invokeFlow.js +1 -1
  3. package/browser/readEventSource.cjs +2 -2
  4. package/browser/readEventSource.d.ts +1 -1
  5. package/browser/readEventSource.js +2 -2
  6. package/browser/readEventSourceStream.cjs +2 -2
  7. package/browser/readEventSourceStream.d.ts +1 -1
  8. package/browser/readEventSourceStream.js +2 -2
  9. package/core/index.cjs +1 -1
  10. package/core/index.d.ts +1 -1
  11. package/core/index.js +1 -1
  12. package/{util → core/schema}/JSONParseError.cjs +6 -6
  13. package/{util → core/schema}/JSONParseError.d.ts +3 -3
  14. package/{util → core/schema}/JSONParseError.js +6 -6
  15. package/core/{structure → schema}/ZodStructureDefinition.cjs +1 -1
  16. package/core/{structure → schema}/ZodStructureDefinition.d.ts +1 -1
  17. package/core/{structure → schema}/ZodStructureDefinition.js +1 -1
  18. package/core/{structure → schema}/index.cjs +2 -0
  19. package/core/{structure → schema}/index.d.ts +2 -0
  20. package/core/{structure → schema}/index.js +2 -0
  21. package/core/schema/parseJSON.cjs +56 -0
  22. package/core/schema/parseJSON.d.ts +58 -0
  23. package/core/schema/parseJSON.js +48 -0
  24. package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +1 -1
  25. package/model-function/generate-structure/StructureGenerationModel.d.ts +1 -1
  26. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +1 -1
  27. package/model-function/generate-structure/generateStructure.d.ts +1 -1
  28. package/model-function/generate-structure/generateStructureOrText.d.ts +1 -1
  29. package/model-function/generate-structure/streamStructure.d.ts +1 -1
  30. package/model-provider/anthropic/AnthropicError.cjs +8 -4
  31. package/model-provider/anthropic/AnthropicError.d.ts +3 -19
  32. package/model-provider/anthropic/AnthropicError.js +8 -4
  33. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +8 -4
  34. package/model-provider/anthropic/AnthropicTextGenerationModel.js +8 -4
  35. package/model-provider/automatic1111/Automatic1111Error.cjs +8 -4
  36. package/model-provider/automatic1111/Automatic1111Error.d.ts +3 -13
  37. package/model-provider/automatic1111/Automatic1111Error.js +8 -4
  38. package/model-provider/cohere/CohereError.cjs +8 -4
  39. package/model-provider/cohere/CohereError.d.ts +3 -7
  40. package/model-provider/cohere/CohereError.js +8 -4
  41. package/model-provider/cohere/CohereTextGenerationModel.cjs +3 -2
  42. package/model-provider/cohere/CohereTextGenerationModel.js +3 -2
  43. package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +28 -24
  44. package/model-provider/elevenlabs/ElevenLabsSpeechModel.d.ts +1 -1
  45. package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +28 -24
  46. package/model-provider/huggingface/HuggingFaceError.cjs +8 -4
  47. package/model-provider/huggingface/HuggingFaceError.d.ts +3 -7
  48. package/model-provider/huggingface/HuggingFaceError.js +8 -4
  49. package/model-provider/llamacpp/LlamaCppError.cjs +8 -4
  50. package/model-provider/llamacpp/LlamaCppError.d.ts +3 -7
  51. package/model-provider/llamacpp/LlamaCppError.js +8 -4
  52. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +10 -6
  53. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +10 -6
  54. package/model-provider/ollama/OllamaTextGenerationModel.cjs +8 -3
  55. package/model-provider/ollama/OllamaTextGenerationModel.d.ts +78 -1
  56. package/model-provider/ollama/OllamaTextGenerationModel.js +8 -3
  57. package/model-provider/openai/OpenAICompletionModel.cjs +8 -4
  58. package/model-provider/openai/OpenAICompletionModel.js +8 -4
  59. package/model-provider/openai/OpenAIError.cjs +8 -4
  60. package/model-provider/openai/OpenAIError.d.ts +3 -27
  61. package/model-provider/openai/OpenAIError.js +8 -4
  62. package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
  63. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +8 -4
  64. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +8 -4
  65. package/model-provider/stability/StabilityError.cjs +8 -4
  66. package/model-provider/stability/StabilityError.d.ts +3 -7
  67. package/model-provider/stability/StabilityError.js +8 -4
  68. package/package.json +1 -1
  69. package/tool/Tool.d.ts +3 -3
  70. package/tool/WebSearchTool.cjs +1 -1
  71. package/tool/WebSearchTool.d.ts +1 -1
  72. package/tool/WebSearchTool.js +1 -1
  73. package/util/index.cjs +0 -2
  74. package/util/index.d.ts +0 -2
  75. package/util/index.js +0 -2
  76. package/util/streaming/parseJsonStream.cjs +5 -5
  77. package/util/streaming/parseJsonStream.d.ts +2 -1
  78. package/util/streaming/parseJsonStream.js +5 -5
  79. package/vector-index/memory/MemoryVectorIndex.cjs +5 -4
  80. package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
  81. package/vector-index/memory/MemoryVectorIndex.js +5 -4
  82. package/util/parseJSON.cjs +0 -67
  83. package/util/parseJSON.d.ts +0 -18
  84. package/util/parseJSON.js +0 -58
  85. /package/core/{structure → schema}/JsonSchemaProducer.cjs +0 -0
  86. /package/core/{structure → schema}/JsonSchemaProducer.d.ts +0 -0
  87. /package/core/{structure → schema}/JsonSchemaProducer.js +0 -0
  88. /package/core/{structure → schema}/Schema.cjs +0 -0
  89. /package/core/{structure → schema}/Schema.d.ts +0 -0
  90. /package/core/{structure → schema}/Schema.js +0 -0
  91. /package/core/{structure → schema}/StructureDefinition.cjs +0 -0
  92. /package/core/{structure → schema}/StructureDefinition.d.ts +0 -0
  93. /package/core/{structure → schema}/StructureDefinition.js +0 -0
  94. /package/core/{structure → schema}/UncheckedSchema.cjs +0 -0
  95. /package/core/{structure → schema}/UncheckedSchema.d.ts +0 -0
  96. /package/core/{structure → schema}/UncheckedSchema.js +0 -0
  97. /package/core/{structure → schema}/UncheckedStructureDefinition.cjs +0 -0
  98. /package/core/{structure → schema}/UncheckedStructureDefinition.d.ts +0 -0
  99. /package/core/{structure → schema}/UncheckedStructureDefinition.js +0 -0
  100. /package/core/{structure → schema}/ZodSchema.cjs +0 -0
  101. /package/core/{structure → schema}/ZodSchema.d.ts +0 -0
  102. /package/core/{structure → schema}/ZodSchema.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { ZodSchema } from "../core/structure/ZodSchema.js";
2
+ import { ZodSchema } from "../core/schema/ZodSchema.js";
3
3
  import { Tool } from "./Tool.js";
4
4
  const OUTPUT_SCHEMA = new ZodSchema(z.object({
5
5
  results: z.array(z.object({
package/util/index.cjs CHANGED
@@ -15,9 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AsyncQueue.cjs"), exports);
18
- __exportStar(require("./JSONParseError.cjs"), exports);
19
18
  __exportStar(require("./cosineSimilarity.cjs"), exports);
20
19
  __exportStar(require("./delay.cjs"), exports);
21
20
  __exportStar(require("./getAudioFileExtension.cjs"), exports);
22
- __exportStar(require("./parseJSON.cjs"), exports);
23
21
  __exportStar(require("./streaming/index.cjs"), exports);
package/util/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from "./AsyncQueue.js";
2
- export * from "./JSONParseError.js";
3
2
  export * from "./cosineSimilarity.js";
4
3
  export * from "./delay.js";
5
4
  export * from "./getAudioFileExtension.js";
6
- export * from "./parseJSON.js";
7
5
  export * from "./streaming/index.js";
package/util/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from "./AsyncQueue.js";
2
- export * from "./JSONParseError.js";
3
2
  export * from "./cosineSimilarity.js";
4
3
  export * from "./delay.js";
5
4
  export * from "./getAudioFileExtension.js";
6
- export * from "./parseJSON.js";
7
5
  export * from "./streaming/index.js";
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseJsonStream = void 0;
4
- const parseJSON_js_1 = require("../parseJSON.cjs");
4
+ const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
5
5
  function parseJsonStream({ schema, stream, process, onDone, }) {
6
6
  function processLine(line) {
7
- process((0, parseJSON_js_1.parseJsonWithZod)(line, schema));
7
+ process((0, parseJSON_js_1.parseJSON)({ text: line, schema }));
8
8
  }
9
9
  return (async () => {
10
10
  try {
11
- let unprocessedText = "";
12
11
  const reader = new ReadableStreamDefaultReader(stream);
13
12
  const utf8Decoder = new TextDecoder("utf-8");
13
+ let unprocessedText = "";
14
14
  // eslint-disable-next-line no-constant-condition
15
15
  while (true) {
16
16
  const { value: chunk, done } = await reader.read();
@@ -18,8 +18,8 @@ function parseJsonStream({ schema, stream, process, onDone, }) {
18
18
  break;
19
19
  }
20
20
  unprocessedText += utf8Decoder.decode(chunk, { stream: true });
21
- const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
22
- unprocessedText = processableLines.pop() || "";
21
+ const processableLines = unprocessedText.split("\n");
22
+ unprocessedText = processableLines.pop() ?? "";
23
23
  processableLines.forEach(processLine);
24
24
  }
25
25
  // processing remaining text:
@@ -1,5 +1,6 @@
1
+ import { Schema } from "../../core/schema/Schema.js";
1
2
  export declare function parseJsonStream<T>({ schema, stream, process, onDone, }: {
2
- schema: Zod.Schema<T>;
3
+ schema: Schema<T>;
3
4
  stream: ReadableStream<Uint8Array>;
4
5
  process: (event: T) => void;
5
6
  onDone?: () => void;
@@ -1,13 +1,13 @@
1
- import { parseJsonWithZod } from "../parseJSON.js";
1
+ import { parseJSON } from "../../core/schema/parseJSON.js";
2
2
  export function parseJsonStream({ schema, stream, process, onDone, }) {
3
3
  function processLine(line) {
4
- process(parseJsonWithZod(line, schema));
4
+ process(parseJSON({ text: line, schema }));
5
5
  }
6
6
  return (async () => {
7
7
  try {
8
- let unprocessedText = "";
9
8
  const reader = new ReadableStreamDefaultReader(stream);
10
9
  const utf8Decoder = new TextDecoder("utf-8");
10
+ let unprocessedText = "";
11
11
  // eslint-disable-next-line no-constant-condition
12
12
  while (true) {
13
13
  const { value: chunk, done } = await reader.read();
@@ -15,8 +15,8 @@ export function parseJsonStream({ schema, stream, process, onDone, }) {
15
15
  break;
16
16
  }
17
17
  unprocessedText += utf8Decoder.decode(chunk, { stream: true });
18
- const processableLines = unprocessedText.split(/\r\n|\n|\r/g);
19
- unprocessedText = processableLines.pop() || "";
18
+ const processableLines = unprocessedText.split("\n");
19
+ unprocessedText = processableLines.pop() ?? "";
20
20
  processableLines.forEach(processLine);
21
21
  }
22
22
  // processing remaining text:
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MemoryVectorIndex = void 0;
4
4
  const zod_1 = require("zod");
5
+ const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
5
6
  const cosineSimilarity_js_1 = require("../../util/cosineSimilarity.cjs");
6
- const parseJSON_js_1 = require("../../util/parseJSON.cjs");
7
- const jsonDataSchema = zod_1.z.array(zod_1.z.object({
7
+ const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
8
+ const jsonDataSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.array(zod_1.z.object({
8
9
  id: zod_1.z.string(),
9
10
  vector: zod_1.z.array(zod_1.z.number()),
10
11
  data: zod_1.z.unknown(),
11
- }));
12
+ })));
12
13
  /**
13
14
  * A very simple vector index that stores all entries in memory. Useful when you only have
14
15
  * a small number of entries and don't want to set up a real database, e.g. for conversational memory
@@ -25,7 +26,7 @@ class MemoryVectorIndex {
25
26
  }
26
27
  static async deserialize({ serializedData, schema, }) {
27
28
  // validate the outer structure:
28
- const json = (0, parseJSON_js_1.parseJsonWithZod)(serializedData, jsonDataSchema);
29
+ const json = (0, parseJSON_js_1.parseJSON)({ text: serializedData, schema: jsonDataSchema });
29
30
  if (schema != null) {
30
31
  // when a schema is provided, validate all entries:
31
32
  for (const entry of json) {
@@ -1,5 +1,5 @@
1
1
  import { Vector } from "../../core/Vector.js";
2
- import { Schema } from "../../core/structure/Schema.js";
2
+ import { Schema } from "../../core/schema/Schema.js";
3
3
  import { VectorIndex } from "../VectorIndex.js";
4
4
  /**
5
5
  * A very simple vector index that stores all entries in memory. Useful when you only have
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
+ import { ZodSchema } from "../../core/schema/ZodSchema.js";
2
3
  import { cosineSimilarity } from "../../util/cosineSimilarity.js";
3
- import { parseJsonWithZod } from "../../util/parseJSON.js";
4
- const jsonDataSchema = z.array(z.object({
4
+ import { parseJSON } from "../../core/schema/parseJSON.js";
5
+ const jsonDataSchema = new ZodSchema(z.array(z.object({
5
6
  id: z.string(),
6
7
  vector: z.array(z.number()),
7
8
  data: z.unknown(),
8
- }));
9
+ })));
9
10
  /**
10
11
  * A very simple vector index that stores all entries in memory. Useful when you only have
11
12
  * a small number of entries and don't want to set up a real database, e.g. for conversational memory
@@ -22,7 +23,7 @@ export class MemoryVectorIndex {
22
23
  }
23
24
  static async deserialize({ serializedData, schema, }) {
24
25
  // validate the outer structure:
25
- const json = parseJsonWithZod(serializedData, jsonDataSchema);
26
+ const json = parseJSON({ text: serializedData, schema: jsonDataSchema });
26
27
  if (schema != null) {
27
28
  // when a schema is provided, validate all entries:
28
29
  for (const entry of json) {
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.safeParseJsonWithSchema = exports.safeParseJsonWithZod = exports.parseJsonWithZod = void 0;
7
- const secure_json_parse_1 = __importDefault(require("secure-json-parse"));
8
- const JSONParseError_js_1 = require("./JSONParseError.cjs");
9
- function parseJsonWithZod(json, schema) {
10
- try {
11
- const parsedJson = secure_json_parse_1.default.parse(json);
12
- return schema.parse(parsedJson);
13
- }
14
- catch (error) {
15
- throw new JSONParseError_js_1.JSONParseError({
16
- valueText: json,
17
- cause: error,
18
- });
19
- }
20
- }
21
- exports.parseJsonWithZod = parseJsonWithZod;
22
- function safeParseJsonWithZod(json, schema) {
23
- try {
24
- const parsedJson = secure_json_parse_1.default.parse(json);
25
- const validationResult = schema.safeParse(parsedJson);
26
- if (validationResult.success) {
27
- return validationResult;
28
- }
29
- return {
30
- success: false,
31
- error: new JSONParseError_js_1.JSONParseError({
32
- valueText: json,
33
- cause: validationResult.error,
34
- }),
35
- };
36
- }
37
- catch (error) {
38
- throw new JSONParseError_js_1.JSONParseError({
39
- valueText: json,
40
- cause: error,
41
- });
42
- }
43
- }
44
- exports.safeParseJsonWithZod = safeParseJsonWithZod;
45
- function safeParseJsonWithSchema(json, schema) {
46
- try {
47
- const parsedJson = secure_json_parse_1.default.parse(json);
48
- const validationResult = schema.validate(parsedJson);
49
- if (validationResult.success) {
50
- return validationResult;
51
- }
52
- return {
53
- success: false,
54
- error: new JSONParseError_js_1.JSONParseError({
55
- valueText: json,
56
- cause: validationResult.error,
57
- }),
58
- };
59
- }
60
- catch (error) {
61
- throw new JSONParseError_js_1.JSONParseError({
62
- valueText: json,
63
- cause: error,
64
- });
65
- }
66
- }
67
- exports.safeParseJsonWithSchema = safeParseJsonWithSchema;
@@ -1,18 +0,0 @@
1
- import { z } from "zod";
2
- import { Schema } from "../core/structure/Schema.js";
3
- import { JSONParseError } from "./JSONParseError.js";
4
- export declare function parseJsonWithZod<T>(json: string, schema: z.Schema<T>): T;
5
- export declare function safeParseJsonWithZod<T>(json: string, schema: z.Schema<T>): {
6
- success: true;
7
- data: T;
8
- } | {
9
- success: false;
10
- error: JSONParseError;
11
- };
12
- export declare function safeParseJsonWithSchema<T>(json: string, schema: Schema<T>): {
13
- success: true;
14
- data: T;
15
- } | {
16
- success: false;
17
- error: JSONParseError;
18
- };
package/util/parseJSON.js DELETED
@@ -1,58 +0,0 @@
1
- import SecureJSON from "secure-json-parse";
2
- import { JSONParseError } from "./JSONParseError.js";
3
- export function parseJsonWithZod(json, schema) {
4
- try {
5
- const parsedJson = SecureJSON.parse(json);
6
- return schema.parse(parsedJson);
7
- }
8
- catch (error) {
9
- throw new JSONParseError({
10
- valueText: json,
11
- cause: error,
12
- });
13
- }
14
- }
15
- export function safeParseJsonWithZod(json, schema) {
16
- try {
17
- const parsedJson = SecureJSON.parse(json);
18
- const validationResult = schema.safeParse(parsedJson);
19
- if (validationResult.success) {
20
- return validationResult;
21
- }
22
- return {
23
- success: false,
24
- error: new JSONParseError({
25
- valueText: json,
26
- cause: validationResult.error,
27
- }),
28
- };
29
- }
30
- catch (error) {
31
- throw new JSONParseError({
32
- valueText: json,
33
- cause: error,
34
- });
35
- }
36
- }
37
- export function safeParseJsonWithSchema(json, schema) {
38
- try {
39
- const parsedJson = SecureJSON.parse(json);
40
- const validationResult = schema.validate(parsedJson);
41
- if (validationResult.success) {
42
- return validationResult;
43
- }
44
- return {
45
- success: false,
46
- error: new JSONParseError({
47
- valueText: json,
48
- cause: validationResult.error,
49
- }),
50
- };
51
- }
52
- catch (error) {
53
- throw new JSONParseError({
54
- valueText: json,
55
- cause: error,
56
- });
57
- }
58
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes