@nocobase/plugin-ai 2.0.0-beta.6 → 2.0.0-beta.7

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 (65) hide show
  1. package/dist/client/6a4c1ee12f864e38.js +10 -0
  2. package/dist/client/index.js +1 -1
  3. package/dist/collections/ai-employees.d.ts +1 -0
  4. package/dist/collections/ai-employees.js +4 -0
  5. package/dist/externalVersion.js +11 -11
  6. package/dist/locale/en-US.json +2 -0
  7. package/dist/locale/zh-CN.json +2 -0
  8. package/dist/node_modules/@langchain/anthropic/package.json +1 -1
  9. package/dist/node_modules/@langchain/core/package.json +1 -1
  10. package/dist/node_modules/@langchain/deepseek/package.json +1 -1
  11. package/dist/node_modules/@langchain/google-genai/LICENSE +6 -6
  12. package/dist/node_modules/@langchain/google-genai/dist/_virtual/rolldown_runtime.cjs +25 -0
  13. package/dist/node_modules/@langchain/google-genai/dist/chat_models.cjs +680 -842
  14. package/dist/node_modules/@langchain/google-genai/dist/chat_models.d.cts +581 -0
  15. package/dist/node_modules/@langchain/google-genai/dist/chat_models.d.ts +196 -157
  16. package/dist/node_modules/@langchain/google-genai/dist/chat_models.js +678 -837
  17. package/dist/node_modules/@langchain/google-genai/dist/embeddings.cjs +97 -151
  18. package/dist/node_modules/@langchain/google-genai/dist/embeddings.d.cts +104 -0
  19. package/dist/node_modules/@langchain/google-genai/dist/embeddings.d.ts +76 -70
  20. package/dist/node_modules/@langchain/google-genai/dist/embeddings.js +93 -144
  21. package/dist/node_modules/@langchain/google-genai/dist/index.cjs +252 -18
  22. package/dist/node_modules/@langchain/google-genai/dist/index.d.cts +3 -0
  23. package/dist/node_modules/@langchain/google-genai/dist/index.d.ts +3 -2
  24. package/dist/node_modules/@langchain/google-genai/dist/index.js +4 -2
  25. package/dist/node_modules/@langchain/google-genai/dist/output_parsers.cjs +47 -75
  26. package/dist/node_modules/@langchain/google-genai/dist/output_parsers.js +47 -72
  27. package/dist/node_modules/@langchain/google-genai/dist/profiles.cjs +345 -0
  28. package/dist/node_modules/@langchain/google-genai/dist/profiles.js +344 -0
  29. package/dist/node_modules/@langchain/google-genai/dist/types.d.cts +17 -0
  30. package/dist/node_modules/@langchain/google-genai/dist/types.d.ts +16 -2
  31. package/dist/node_modules/@langchain/google-genai/dist/utils/common.cjs +419 -551
  32. package/dist/node_modules/@langchain/google-genai/dist/utils/common.js +417 -545
  33. package/dist/node_modules/@langchain/google-genai/dist/utils/tools.cjs +65 -102
  34. package/dist/node_modules/@langchain/google-genai/dist/utils/tools.js +64 -99
  35. package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.cjs +31 -49
  36. package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.js +29 -45
  37. package/dist/node_modules/@langchain/google-genai/package.json +1 -1
  38. package/dist/node_modules/@langchain/ollama/package.json +1 -1
  39. package/dist/node_modules/@langchain/openai/package.json +1 -1
  40. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  41. package/dist/node_modules/zod/package.json +1 -1
  42. package/dist/node_modules/zod-to-json-schema/package.json +1 -1
  43. package/dist/server/ai-employees/ai-employee.js +5 -2
  44. package/dist/server/llm-providers/anthropic.js +4 -5
  45. package/dist/server/llm-providers/provider.js +5 -1
  46. package/dist/server/manager/ai-chat-conversation.js +3 -2
  47. package/dist/server/manager/built-in-manager.js +3 -3
  48. package/dist/server/migrations/20260107000000-reset-builtin-about.d.ts +14 -0
  49. package/dist/server/migrations/20260107000000-reset-builtin-about.js +48 -0
  50. package/dist/server/resource/ai.js +8 -2
  51. package/dist/server/resource/aiEmployees.d.ts +0 -1
  52. package/dist/server/resource/aiEmployees.js +0 -15
  53. package/dist/server/types/ai-message.type.d.ts +2 -0
  54. package/package.json +3 -3
  55. package/dist/client/a7f0550514128d80.js +0 -10
  56. package/dist/node_modules/@langchain/google-genai/dist/output_parsers.d.ts +0 -20
  57. package/dist/node_modules/@langchain/google-genai/dist/types.cjs +0 -2
  58. package/dist/node_modules/@langchain/google-genai/dist/types.js +0 -1
  59. package/dist/node_modules/@langchain/google-genai/dist/utils/common.d.ts +0 -22
  60. package/dist/node_modules/@langchain/google-genai/dist/utils/tools.d.ts +0 -10
  61. package/dist/node_modules/@langchain/google-genai/dist/utils/zod_to_genai_parameters.d.ts +0 -14
  62. package/dist/node_modules/@langchain/google-genai/index.cjs +0 -252
  63. package/dist/node_modules/@langchain/google-genai/index.d.cts +0 -1
  64. package/dist/node_modules/@langchain/google-genai/index.d.ts +0 -1
  65. package/dist/node_modules/@langchain/google-genai/index.js +0 -1
@@ -2,148 +2,97 @@ import { GoogleGenerativeAI } from "@google/generative-ai";
2
2
  import { getEnvironmentVariable } from "@langchain/core/utils/env";
3
3
  import { Embeddings } from "@langchain/core/embeddings";
4
4
  import { chunkArray } from "@langchain/core/utils/chunk_array";
5
+
6
+ //#region src/embeddings.ts
5
7
  /**
6
- * Class that extends the Embeddings class and provides methods for
7
- * generating embeddings using the Google Palm API.
8
- * @example
9
- * ```typescript
10
- * const model = new GoogleGenerativeAIEmbeddings({
11
- * apiKey: "<YOUR API KEY>",
12
- * modelName: "embedding-001",
13
- * });
14
- *
15
- * // Embed a single query
16
- * const res = await model.embedQuery(
17
- * "What would be a good company name for a company that makes colorful socks?"
18
- * );
19
- * console.log({ res });
20
- *
21
- * // Embed multiple documents
22
- * const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
23
- * console.log({ documentRes });
24
- * ```
25
- */
26
- export class GoogleGenerativeAIEmbeddings extends Embeddings {
27
- constructor(fields) {
28
- super(fields ?? {});
29
- Object.defineProperty(this, "apiKey", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: void 0
34
- });
35
- Object.defineProperty(this, "modelName", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: "embedding-001"
40
- });
41
- Object.defineProperty(this, "model", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: "embedding-001"
46
- });
47
- Object.defineProperty(this, "taskType", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: void 0
52
- });
53
- Object.defineProperty(this, "title", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: void 0
58
- });
59
- Object.defineProperty(this, "stripNewLines", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: true
64
- });
65
- Object.defineProperty(this, "maxBatchSize", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: 100
70
- }); // Max batch size for embedDocuments set by GenerativeModel client's batchEmbedContents call
71
- Object.defineProperty(this, "client", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: void 0
76
- });
77
- this.modelName =
78
- fields?.model?.replace(/^models\//, "") ??
79
- fields?.modelName?.replace(/^models\//, "") ??
80
- this.modelName;
81
- this.model = this.modelName;
82
- this.taskType = fields?.taskType ?? this.taskType;
83
- this.title = fields?.title ?? this.title;
84
- if (this.title && this.taskType !== "RETRIEVAL_DOCUMENT") {
85
- throw new Error("title can only be sepcified with TaskType.RETRIEVAL_DOCUMENT");
86
- }
87
- this.apiKey = fields?.apiKey ?? getEnvironmentVariable("GOOGLE_API_KEY");
88
- if (!this.apiKey) {
89
- throw new Error("Please set an API key for Google GenerativeAI " +
90
- "in the environmentb variable GOOGLE_API_KEY " +
91
- "or in the `apiKey` field of the " +
92
- "GoogleGenerativeAIEmbeddings constructor");
93
- }
94
- this.client = new GoogleGenerativeAI(this.apiKey).getGenerativeModel({
95
- model: this.model,
96
- }, {
97
- baseUrl: fields?.baseUrl,
98
- });
99
- }
100
- _convertToContent(text) {
101
- const cleanedText = this.stripNewLines ? text.replace(/\n/g, " ") : text;
102
- return {
103
- content: { role: "user", parts: [{ text: cleanedText }] },
104
- taskType: this.taskType,
105
- title: this.title,
106
- };
107
- }
108
- async _embedQueryContent(text) {
109
- const req = this._convertToContent(text);
110
- const res = await this.client.embedContent(req);
111
- return res.embedding.values ?? [];
112
- }
113
- async _embedDocumentsContent(documents) {
114
- const batchEmbedChunks = chunkArray(documents, this.maxBatchSize);
115
- const batchEmbedRequests = batchEmbedChunks.map((chunk) => ({
116
- requests: chunk.map((doc) => this._convertToContent(doc)),
117
- }));
118
- const responses = await Promise.allSettled(batchEmbedRequests.map((req) => this.client.batchEmbedContents(req)));
119
- const embeddings = responses.flatMap((res, idx) => {
120
- if (res.status === "fulfilled") {
121
- return res.value.embeddings.map((e) => e.values || []);
122
- }
123
- else {
124
- return Array(batchEmbedChunks[idx].length).fill([]);
125
- }
126
- });
127
- return embeddings;
128
- }
129
- /**
130
- * Method that takes a document as input and returns a promise that
131
- * resolves to an embedding for the document. It calls the _embedText
132
- * method with the document as the input.
133
- * @param document Document for which to generate an embedding.
134
- * @returns Promise that resolves to an embedding for the input document.
135
- */
136
- embedQuery(document) {
137
- return this.caller.call(this._embedQueryContent.bind(this), document);
138
- }
139
- /**
140
- * Method that takes an array of documents as input and returns a promise
141
- * that resolves to a 2D array of embeddings for each document. It calls
142
- * the _embedText method for each document in the array.
143
- * @param documents Array of documents for which to generate embeddings.
144
- * @returns Promise that resolves to a 2D array of embeddings for each input document.
145
- */
146
- embedDocuments(documents) {
147
- return this.caller.call(this._embedDocumentsContent.bind(this), documents);
148
- }
149
- }
8
+ * Class that extends the Embeddings class and provides methods for
9
+ * generating embeddings using the Google Palm API.
10
+ * @example
11
+ * ```typescript
12
+ * const model = new GoogleGenerativeAIEmbeddings({
13
+ * apiKey: "<YOUR API KEY>",
14
+ * modelName: "embedding-001",
15
+ * });
16
+ *
17
+ * // Embed a single query
18
+ * const res = await model.embedQuery(
19
+ * "What would be a good company name for a company that makes colorful socks?"
20
+ * );
21
+ * console.log({ res });
22
+ *
23
+ * // Embed multiple documents
24
+ * const documentRes = await model.embedDocuments(["Hello world", "Bye bye"]);
25
+ * console.log({ documentRes });
26
+ * ```
27
+ */
28
+ var GoogleGenerativeAIEmbeddings = class extends Embeddings {
29
+ apiKey;
30
+ modelName = "embedding-001";
31
+ model = "embedding-001";
32
+ taskType;
33
+ title;
34
+ stripNewLines = true;
35
+ maxBatchSize = 100;
36
+ client;
37
+ constructor(fields) {
38
+ super(fields ?? {});
39
+ this.modelName = fields?.model?.replace(/^models\//, "") ?? fields?.modelName?.replace(/^models\//, "") ?? this.modelName;
40
+ this.model = this.modelName;
41
+ this.taskType = fields?.taskType ?? this.taskType;
42
+ this.title = fields?.title ?? this.title;
43
+ if (this.title && this.taskType !== "RETRIEVAL_DOCUMENT") throw new Error("title can only be sepcified with TaskType.RETRIEVAL_DOCUMENT");
44
+ this.apiKey = fields?.apiKey ?? getEnvironmentVariable("GOOGLE_API_KEY");
45
+ if (!this.apiKey) throw new Error("Please set an API key for Google GenerativeAI in the environmentb variable GOOGLE_API_KEY or in the `apiKey` field of the GoogleGenerativeAIEmbeddings constructor");
46
+ this.client = new GoogleGenerativeAI(this.apiKey).getGenerativeModel({ model: this.model }, { baseUrl: fields?.baseUrl });
47
+ }
48
+ _convertToContent(text) {
49
+ const cleanedText = this.stripNewLines ? text.replace(/\n/g, " ") : text;
50
+ return {
51
+ content: {
52
+ role: "user",
53
+ parts: [{ text: cleanedText }]
54
+ },
55
+ taskType: this.taskType,
56
+ title: this.title
57
+ };
58
+ }
59
+ async _embedQueryContent(text) {
60
+ const req = this._convertToContent(text);
61
+ const res = await this.client.embedContent(req);
62
+ return res.embedding.values ?? [];
63
+ }
64
+ async _embedDocumentsContent(documents) {
65
+ const batchEmbedChunks = chunkArray(documents, this.maxBatchSize);
66
+ const batchEmbedRequests = batchEmbedChunks.map((chunk) => ({ requests: chunk.map((doc) => this._convertToContent(doc)) }));
67
+ const responses = await Promise.allSettled(batchEmbedRequests.map((req) => this.client.batchEmbedContents(req)));
68
+ const embeddings = responses.flatMap((res, idx) => {
69
+ if (res.status === "fulfilled") return res.value.embeddings.map((e) => e.values || []);
70
+ else return Array(batchEmbedChunks[idx].length).fill([]);
71
+ });
72
+ return embeddings;
73
+ }
74
+ /**
75
+ * Method that takes a document as input and returns a promise that
76
+ * resolves to an embedding for the document. It calls the _embedText
77
+ * method with the document as the input.
78
+ * @param document Document for which to generate an embedding.
79
+ * @returns Promise that resolves to an embedding for the input document.
80
+ */
81
+ embedQuery(document) {
82
+ return this.caller.call(this._embedQueryContent.bind(this), document);
83
+ }
84
+ /**
85
+ * Method that takes an array of documents as input and returns a promise
86
+ * that resolves to a 2D array of embeddings for each document. It calls
87
+ * the _embedText method for each document in the array.
88
+ * @param documents Array of documents for which to generate embeddings.
89
+ * @returns Promise that resolves to a 2D array of embeddings for each input document.
90
+ */
91
+ embedDocuments(documents) {
92
+ return this.caller.call(this._embedDocumentsContent.bind(this), documents);
93
+ }
94
+ };
95
+
96
+ //#endregion
97
+ export { GoogleGenerativeAIEmbeddings };
98
+ //# sourceMappingURL=embeddings.js.map