@sjts/ai-shared 31.1.2 → 31.2.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 (192) hide show
  1. package/backend/LICENCE +5 -0
  2. package/backend/dist/_/amazon/_/getAmazonClient.d.ts +4 -0
  3. package/backend/dist/_/amazon/_/getAmazonClient.d.ts.map +1 -0
  4. package/backend/dist/_/amazon/_/getAmazonClient.js +10 -0
  5. package/backend/dist/_/amazon/_/index.d.ts +2 -0
  6. package/backend/dist/_/amazon/_/index.d.ts.map +1 -0
  7. package/backend/dist/_/amazon/_/index.js +1 -0
  8. package/backend/dist/_/amazon/index.d.ts +2 -0
  9. package/backend/dist/_/amazon/index.d.ts.map +1 -0
  10. package/backend/dist/_/amazon/index.js +1 -0
  11. package/backend/dist/_/amazon/makeAmazonQuickie.d.ts +3 -0
  12. package/backend/dist/_/amazon/makeAmazonQuickie.d.ts.map +1 -0
  13. package/backend/dist/_/amazon/makeAmazonQuickie.js +65 -0
  14. package/backend/dist/_/anthropic/_/aiEvent2AnthropicMessage.d.ts +4 -0
  15. package/backend/dist/_/anthropic/_/aiEvent2AnthropicMessage.d.ts.map +1 -0
  16. package/backend/dist/_/anthropic/_/aiEvent2AnthropicMessage.js +59 -0
  17. package/backend/dist/_/anthropic/_/aiTool2AnthropicTool.d.ts +4 -0
  18. package/backend/dist/_/anthropic/_/aiTool2AnthropicTool.d.ts.map +1 -0
  19. package/backend/dist/_/anthropic/_/aiTool2AnthropicTool.js +11 -0
  20. package/backend/dist/_/anthropic/_/compileAnthropicThought.d.ts +7 -0
  21. package/backend/dist/_/anthropic/_/compileAnthropicThought.d.ts.map +1 -0
  22. package/backend/dist/_/anthropic/_/compileAnthropicThought.js +17 -0
  23. package/backend/dist/_/anthropic/_/getAnthropicClient.d.ts +4 -0
  24. package/backend/dist/_/anthropic/_/getAnthropicClient.d.ts.map +1 -0
  25. package/backend/dist/_/anthropic/_/getAnthropicClient.js +13 -0
  26. package/backend/dist/_/anthropic/_/index.d.ts +5 -0
  27. package/backend/dist/_/anthropic/_/index.d.ts.map +1 -0
  28. package/backend/dist/_/anthropic/_/index.js +4 -0
  29. package/backend/dist/_/anthropic/index.d.ts +4 -0
  30. package/backend/dist/_/anthropic/index.d.ts.map +1 -0
  31. package/backend/dist/_/anthropic/index.js +3 -0
  32. package/backend/dist/_/anthropic/makeAnthropicQuickie.d.ts +3 -0
  33. package/backend/dist/_/anthropic/makeAnthropicQuickie.d.ts.map +1 -0
  34. package/backend/dist/_/anthropic/makeAnthropicQuickie.js +53 -0
  35. package/backend/dist/_/anthropic/makeAnthropicStream.d.ts +3 -0
  36. package/backend/dist/_/anthropic/makeAnthropicStream.d.ts.map +1 -0
  37. package/backend/dist/_/anthropic/makeAnthropicStream.js +35 -0
  38. package/backend/dist/_/anthropic/makeAnthropicThink.d.ts +3 -0
  39. package/backend/dist/_/anthropic/makeAnthropicThink.d.ts.map +1 -0
  40. package/backend/dist/_/anthropic/makeAnthropicThink.js +84 -0
  41. package/backend/dist/_/callAI.d.ts +2 -0
  42. package/backend/dist/_/callAI.d.ts.map +1 -0
  43. package/backend/dist/_/callAI.js +10 -0
  44. package/backend/dist/_/cerebras/_/aiEvent2CerebrasMessage.d.ts +3 -0
  45. package/backend/dist/_/cerebras/_/aiEvent2CerebrasMessage.d.ts.map +1 -0
  46. package/backend/dist/_/cerebras/_/aiEvent2CerebrasMessage.js +47 -0
  47. package/backend/dist/_/cerebras/_/getCerebrasClient.d.ts +4 -0
  48. package/backend/dist/_/cerebras/_/getCerebrasClient.d.ts.map +1 -0
  49. package/backend/dist/_/cerebras/_/getCerebrasClient.js +8 -0
  50. package/backend/dist/_/cerebras/_/index.d.ts +3 -0
  51. package/backend/dist/_/cerebras/_/index.d.ts.map +1 -0
  52. package/backend/dist/_/cerebras/_/index.js +2 -0
  53. package/backend/dist/_/cerebras/index.d.ts +3 -0
  54. package/backend/dist/_/cerebras/index.d.ts.map +1 -0
  55. package/backend/dist/_/cerebras/index.js +2 -0
  56. package/backend/dist/_/cerebras/makeCerebrasQuickie.d.ts +3 -0
  57. package/backend/dist/_/cerebras/makeCerebrasQuickie.d.ts.map +1 -0
  58. package/backend/dist/_/cerebras/makeCerebrasQuickie.js +44 -0
  59. package/backend/dist/_/cerebras/makeCerebrasThink.d.ts +3 -0
  60. package/backend/dist/_/cerebras/makeCerebrasThink.d.ts.map +1 -0
  61. package/backend/dist/_/cerebras/makeCerebrasThink.js +32 -0
  62. package/backend/dist/_/compileObject.d.ts +12 -0
  63. package/backend/dist/_/compileObject.d.ts.map +1 -0
  64. package/backend/dist/_/compileObject.js +13 -0
  65. package/backend/dist/_/compileParam.d.ts +4 -0
  66. package/backend/dist/_/compileParam.d.ts.map +1 -0
  67. package/backend/dist/_/compileParam.js +80 -0
  68. package/backend/dist/_/google/_/aiEvent2GoogleContent.d.ts +4 -0
  69. package/backend/dist/_/google/_/aiEvent2GoogleContent.d.ts.map +1 -0
  70. package/backend/dist/_/google/_/aiEvent2GoogleContent.js +56 -0
  71. package/backend/dist/_/google/_/aiTool2GoogleFunctionDeclaration.d.ts +4 -0
  72. package/backend/dist/_/google/_/aiTool2GoogleFunctionDeclaration.d.ts.map +1 -0
  73. package/backend/dist/_/google/_/aiTool2GoogleFunctionDeclaration.js +12 -0
  74. package/backend/dist/_/google/_/compileGoogleThought.d.ts +8 -0
  75. package/backend/dist/_/google/_/compileGoogleThought.d.ts.map +1 -0
  76. package/backend/dist/_/google/_/compileGoogleThought.js +22 -0
  77. package/backend/dist/_/google/_/getGoogleClient.d.ts +4 -0
  78. package/backend/dist/_/google/_/getGoogleClient.d.ts.map +1 -0
  79. package/backend/dist/_/google/_/getGoogleClient.js +8 -0
  80. package/backend/dist/_/google/_/getGoogleToolMode.d.ts +3 -0
  81. package/backend/dist/_/google/_/getGoogleToolMode.d.ts.map +1 -0
  82. package/backend/dist/_/google/_/getGoogleToolMode.js +11 -0
  83. package/backend/dist/_/google/_/index.d.ts +6 -0
  84. package/backend/dist/_/google/_/index.d.ts.map +1 -0
  85. package/backend/dist/_/google/_/index.js +5 -0
  86. package/backend/dist/_/google/index.d.ts +3 -0
  87. package/backend/dist/_/google/index.d.ts.map +1 -0
  88. package/backend/dist/_/google/index.js +2 -0
  89. package/backend/dist/_/google/makeGoogleQuickie.d.ts +3 -0
  90. package/backend/dist/_/google/makeGoogleQuickie.d.ts.map +1 -0
  91. package/backend/dist/_/google/makeGoogleQuickie.js +52 -0
  92. package/backend/dist/_/google/makeGoogleThink.d.ts +3 -0
  93. package/backend/dist/_/google/makeGoogleThink.d.ts.map +1 -0
  94. package/backend/dist/_/google/makeGoogleThink.js +93 -0
  95. package/backend/dist/_/index.d.ts +13 -0
  96. package/backend/dist/_/index.d.ts.map +1 -0
  97. package/backend/dist/_/index.js +12 -0
  98. package/backend/dist/_/logAI.d.ts +3 -0
  99. package/backend/dist/_/logAI.d.ts.map +1 -0
  100. package/backend/dist/_/logAI.js +7 -0
  101. package/backend/dist/_/mistral/_/aiEvent2MistralAIMessage.d.ts +3 -0
  102. package/backend/dist/_/mistral/_/aiEvent2MistralAIMessage.d.ts.map +1 -0
  103. package/backend/dist/_/mistral/_/aiEvent2MistralAIMessage.js +47 -0
  104. package/backend/dist/_/mistral/_/aiTool2MistralAITool.d.ts +3 -0
  105. package/backend/dist/_/mistral/_/aiTool2MistralAITool.d.ts.map +1 -0
  106. package/backend/dist/_/mistral/_/aiTool2MistralAITool.js +14 -0
  107. package/backend/dist/_/mistral/_/compileMistralAIThought.d.ts +6 -0
  108. package/backend/dist/_/mistral/_/compileMistralAIThought.d.ts.map +1 -0
  109. package/backend/dist/_/mistral/_/compileMistralAIThought.js +15 -0
  110. package/backend/dist/_/mistral/_/getMistralAIClient.d.ts +4 -0
  111. package/backend/dist/_/mistral/_/getMistralAIClient.d.ts.map +1 -0
  112. package/backend/dist/_/mistral/_/getMistralAIClient.js +8 -0
  113. package/backend/dist/_/mistral/_/index.d.ts +5 -0
  114. package/backend/dist/_/mistral/_/index.d.ts.map +1 -0
  115. package/backend/dist/_/mistral/_/index.js +4 -0
  116. package/backend/dist/_/mistral/index.d.ts +3 -0
  117. package/backend/dist/_/mistral/index.d.ts.map +1 -0
  118. package/backend/dist/_/mistral/index.js +2 -0
  119. package/backend/dist/_/mistral/makeMistralAIQuickie.d.ts +3 -0
  120. package/backend/dist/_/mistral/makeMistralAIQuickie.d.ts.map +1 -0
  121. package/backend/dist/_/mistral/makeMistralAIQuickie.js +45 -0
  122. package/backend/dist/_/mistral/makeMistralAIThink.d.ts +3 -0
  123. package/backend/dist/_/mistral/makeMistralAIThink.d.ts.map +1 -0
  124. package/backend/dist/_/mistral/makeMistralAIThink.js +74 -0
  125. package/backend/dist/_/openai/_/aiEvent2OpenAIMessage.d.ts +4 -0
  126. package/backend/dist/_/openai/_/aiEvent2OpenAIMessage.d.ts.map +1 -0
  127. package/backend/dist/_/openai/_/aiEvent2OpenAIMessage.js +47 -0
  128. package/backend/dist/_/openai/_/aiTool2OpenAITool.d.ts +4 -0
  129. package/backend/dist/_/openai/_/aiTool2OpenAITool.d.ts.map +1 -0
  130. package/backend/dist/_/openai/_/aiTool2OpenAITool.js +14 -0
  131. package/backend/dist/_/openai/_/compileOpenAIThought.d.ts +7 -0
  132. package/backend/dist/_/openai/_/compileOpenAIThought.d.ts.map +1 -0
  133. package/backend/dist/_/openai/_/compileOpenAIThought.js +17 -0
  134. package/backend/dist/_/openai/_/getOpenAIClient.d.ts +4 -0
  135. package/backend/dist/_/openai/_/getOpenAIClient.d.ts.map +1 -0
  136. package/backend/dist/_/openai/_/getOpenAIClient.js +12 -0
  137. package/backend/dist/_/openai/_/index.d.ts +5 -0
  138. package/backend/dist/_/openai/_/index.d.ts.map +1 -0
  139. package/backend/dist/_/openai/_/index.js +4 -0
  140. package/backend/dist/_/openai/index.d.ts +4 -0
  141. package/backend/dist/_/openai/index.d.ts.map +1 -0
  142. package/backend/dist/_/openai/index.js +3 -0
  143. package/backend/dist/_/openai/makeOpenAIEmbed.d.ts +3 -0
  144. package/backend/dist/_/openai/makeOpenAIEmbed.d.ts.map +1 -0
  145. package/backend/dist/_/openai/makeOpenAIEmbed.js +15 -0
  146. package/backend/dist/_/openai/makeOpenAIQuickie.d.ts +3 -0
  147. package/backend/dist/_/openai/makeOpenAIQuickie.d.ts.map +1 -0
  148. package/backend/dist/_/openai/makeOpenAIQuickie.js +47 -0
  149. package/backend/dist/_/openai/makeOpenAIThink.d.ts +3 -0
  150. package/backend/dist/_/openai/makeOpenAIThink.d.ts.map +1 -0
  151. package/backend/dist/_/openai/makeOpenAIThink.js +75 -0
  152. package/backend/dist/_/types/errors.d.ts +4 -0
  153. package/backend/dist/_/types/errors.d.ts.map +1 -0
  154. package/backend/dist/_/types/errors.js +3 -0
  155. package/backend/dist/_/types/index.d.ts +2 -0
  156. package/backend/dist/_/types/index.d.ts.map +1 -0
  157. package/backend/dist/_/types/index.js +1 -0
  158. package/backend/dist/_/voyageai/_/getVoyageAIClient.d.ts +4 -0
  159. package/backend/dist/_/voyageai/_/getVoyageAIClient.d.ts.map +1 -0
  160. package/backend/dist/_/voyageai/_/getVoyageAIClient.js +7 -0
  161. package/backend/dist/_/voyageai/_/index.d.ts +2 -0
  162. package/backend/dist/_/voyageai/_/index.d.ts.map +1 -0
  163. package/backend/dist/_/voyageai/_/index.js +1 -0
  164. package/backend/dist/_/voyageai/index.d.ts +2 -0
  165. package/backend/dist/_/voyageai/index.d.ts.map +1 -0
  166. package/backend/dist/_/voyageai/index.js +1 -0
  167. package/backend/dist/_/voyageai/makeVoyageAIEmbed.d.ts +3 -0
  168. package/backend/dist/_/voyageai/makeVoyageAIEmbed.d.ts.map +1 -0
  169. package/backend/dist/_/voyageai/makeVoyageAIEmbed.js +13 -0
  170. package/backend/dist/doEmbed.d.ts +5 -0
  171. package/backend/dist/doEmbed.d.ts.map +1 -0
  172. package/backend/dist/doEmbed.js +17 -0
  173. package/backend/dist/doQuickie.d.ts +5 -0
  174. package/backend/dist/doQuickie.d.ts.map +1 -0
  175. package/backend/dist/doQuickie.js +39 -0
  176. package/backend/dist/doStream.d.ts +5 -0
  177. package/backend/dist/doStream.d.ts.map +1 -0
  178. package/backend/dist/doStream.js +14 -0
  179. package/backend/dist/doThink.d.ts +4 -0
  180. package/backend/dist/doThink.d.ts.map +1 -0
  181. package/backend/dist/doThink.js +33 -0
  182. package/backend/dist/index.d.ts +5 -0
  183. package/backend/dist/index.d.ts.map +1 -0
  184. package/backend/dist/index.js +4 -0
  185. package/backend/package.json +46 -0
  186. package/dist/utils/indent.d.ts +1 -1
  187. package/dist/utils/indent.d.ts.map +1 -1
  188. package/dist/utils/indent.js +2 -2
  189. package/dist/utils/trimdent.d.ts +1 -1
  190. package/dist/utils/trimdent.d.ts.map +1 -1
  191. package/dist/utils/trimdent.js +4 -3
  192. package/package.json +4 -4
@@ -0,0 +1,44 @@
1
+ import { AIEventType, defaultAIConfig } from '@sjts/ai-shared';
2
+ import { Logger } from '@sjts/lib-log';
3
+ import { callAI } from '../callAI.js';
4
+ import { aiEvent2CerebrasMessage, getCerebrasClient } from './_/index.js';
5
+ export function makeCerebrasQuickie() {
6
+ return async (ai, content, images = []) => {
7
+ const response = await handleRequest(ai, content, images);
8
+ return handleResponse(response);
9
+ };
10
+ }
11
+ // ---------------
12
+ // HANDLE REQUEST
13
+ // ---------------
14
+ async function handleRequest(ai, content, images = []) {
15
+ try {
16
+ const client = getCerebrasClient(ai.api);
17
+ const c = { ...defaultAIConfig, ...ai };
18
+ const request = {
19
+ messages: [aiEvent2CerebrasMessage({ type: AIEventType.USER_CHAT, content, images })],
20
+ model: c.llm.model,
21
+ max_tokens: c.max_tokens,
22
+ // temperature: c.temperature,
23
+ // frequency_penalty: c.frequency_penalty,
24
+ response_format: ai.jsonMode ? { type: 'json_object' } : undefined,
25
+ };
26
+ return callAI(r => client.chat.completions.create(r), request, c.timeout);
27
+ }
28
+ catch (e) {
29
+ Logger.error('Problem processing AI Request', { message: e.message });
30
+ throw e;
31
+ }
32
+ }
33
+ // ---------------
34
+ // HANDLE RESPONSE
35
+ // ---------------
36
+ async function handleResponse(response) {
37
+ try {
38
+ return response.choices[0].message.content;
39
+ }
40
+ catch (e) {
41
+ Logger.error('Problem processing AI response', { message: e.message });
42
+ throw e;
43
+ }
44
+ }
@@ -0,0 +1,3 @@
1
+ import { AIConfig, AIThoughtInput, AIThoughtOutput } from '@sjts/ai-shared';
2
+ export declare function makeCerebrasThink(): (ai: AIConfig, input: AIThoughtInput) => Promise<AIThoughtOutput>;
3
+ //# sourceMappingURL=makeCerebrasThink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeCerebrasThink.d.ts","sourceRoot":"","sources":["../../../src/_/cerebras/makeCerebrasThink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAG3E,wBAAgB,iBAAiB,KAClB,IAAI,QAAQ,EAAE,OAAO,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC,CAI5E"}
@@ -0,0 +1,32 @@
1
+ import { Logger } from '@sjts/lib-log';
2
+ export function makeCerebrasThink() {
3
+ return async (ai, input) => {
4
+ const response = await handleRequest(ai, input);
5
+ return handleResponse(response);
6
+ };
7
+ }
8
+ // ---------------
9
+ // HANDLE REQUEST
10
+ // ---------------
11
+ async function handleRequest(ai, input) {
12
+ try {
13
+ throw new Error('Cerebras thinking is not supported yet');
14
+ }
15
+ catch (e) {
16
+ Logger.error('Problem processing AI Request', { message: e.message });
17
+ throw e;
18
+ }
19
+ }
20
+ // ---------------
21
+ // HANDLE RESPONSE
22
+ // ---------------
23
+ async function handleResponse(response) {
24
+ try {
25
+ // TODO
26
+ throw new Error('Cerebras thinking is not supported yet');
27
+ }
28
+ catch (e) {
29
+ Logger.error('Problem processing AI response', { message: e.message });
30
+ throw e;
31
+ }
32
+ }
@@ -0,0 +1,12 @@
1
+ import { Param, Params } from '@sjts/ai-shared';
2
+ export declare function compileObject(params: Params, rootParam?: Param): {
3
+ properties: {};
4
+ required: string[];
5
+ type: string;
6
+ } | {
7
+ properties: {};
8
+ required: string[];
9
+ description: string;
10
+ type: string;
11
+ };
12
+ //# sourceMappingURL=compileObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileObject.d.ts","sourceRoot":"","sources":["../../src/_/compileObject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAI/C,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;;;;;;;;;EAa9D"}
@@ -0,0 +1,13 @@
1
+ import { ifVal } from '@sjts/lib-utils';
2
+ import { compileParam } from './compileParam.js';
3
+ export function compileObject(params, rootParam) {
4
+ return {
5
+ type: 'object',
6
+ ...ifVal('description', rootParam?.description),
7
+ properties: Object.keys(params).reduce((p, key) => ({
8
+ ...p,
9
+ [key]: compileParam(params[key]),
10
+ }), {}),
11
+ required: Object.keys(params).filter(key => params[key].required),
12
+ };
13
+ }
@@ -0,0 +1,4 @@
1
+ import { Param } from '@sjts/ai-shared';
2
+ import { JSONSchema7Object } from 'json-schema';
3
+ export declare function compileParam(param: Param): JSONSchema7Object;
4
+ //# sourceMappingURL=compileParam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileParam.d.ts","sourceRoot":"","sources":["../../src/_/compileParam.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAG/C,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,iBAAiB,CAyE5D"}
@@ -0,0 +1,80 @@
1
+ import { ParamType } from '@sjts/ai-shared';
2
+ import { ifVal } from '@sjts/lib-utils';
3
+ import { compileObject } from './compileObject.js';
4
+ export function compileParam(param) {
5
+ switch (param.type) {
6
+ // ------------------------------
7
+ // Strings
8
+ case ParamType.STRING:
9
+ return {
10
+ type: 'string',
11
+ ...ifVal('minLength', param.min),
12
+ ...ifVal('maxLength', param.max),
13
+ ...ifVal('description', param.description),
14
+ };
15
+ case ParamType.STRING_ARRAY:
16
+ return compileArrayParam(param, { type: 'string' });
17
+ // ------------------------------
18
+ // Numbers
19
+ case ParamType.NUMBER:
20
+ return {
21
+ type: 'number',
22
+ ...ifVal('minimum', param.min),
23
+ ...ifVal('exclusiveMaximum', param.max),
24
+ ...ifVal('description', param.description),
25
+ };
26
+ case ParamType.NUMBER_ARRAY:
27
+ return compileArrayParam(param, { type: 'number' });
28
+ // ------------------------------
29
+ // Booleans
30
+ case ParamType.BOOLEAN:
31
+ return {
32
+ type: 'boolean',
33
+ ...ifVal('description', param.description),
34
+ };
35
+ case ParamType.BOOLEAN_ARRAY:
36
+ return compileArrayParam(param, { type: 'boolean' });
37
+ // ------------------------------
38
+ // Dates
39
+ case ParamType.DATE:
40
+ return {
41
+ type: 'string',
42
+ format: 'date',
43
+ ...ifVal('description', param.description),
44
+ };
45
+ case ParamType.DATE_ARRAY:
46
+ return compileArrayParam(param, { type: 'string', format: 'date' });
47
+ // ------------------------------
48
+ // Date Times
49
+ case ParamType.DATE_TIME:
50
+ return {
51
+ type: 'string',
52
+ format: 'date-time',
53
+ ...ifVal('description', param.description),
54
+ };
55
+ case ParamType.DATE_TIME_ARRAY:
56
+ return compileArrayParam(param, { type: 'string', format: 'date-time' });
57
+ // ------------------------------
58
+ // Objects
59
+ case ParamType.OBJECT:
60
+ if (!param.properties)
61
+ throw new Error('Missing properties for OBJECT');
62
+ return compileObject(param.properties, param);
63
+ case ParamType.OBJECT_ARRAY:
64
+ if (!param.properties)
65
+ throw new Error('Missing properties for OBJECT_ARRAY');
66
+ return {
67
+ type: 'array',
68
+ description: param.description ?? '',
69
+ items: compileObject(param.properties, param),
70
+ };
71
+ }
72
+ throw new Error('Unhandled Param type');
73
+ }
74
+ function compileArrayParam(param, items) {
75
+ return {
76
+ type: 'array',
77
+ description: param.description ?? '',
78
+ items,
79
+ };
80
+ }
@@ -0,0 +1,4 @@
1
+ import { Content } from '@google/generative-ai';
2
+ import { AIEvent } from '@sjts/ai-shared';
3
+ export declare function aiEvent2GoogleContent(e: AIEvent): Content;
4
+ //# sourceMappingURL=aiEvent2GoogleContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiEvent2GoogleContent.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/aiEvent2GoogleContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAe,MAAM,iBAAiB,CAAA;AAEtD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAwDzD"}
@@ -0,0 +1,56 @@
1
+ import { AIEventType } from '@sjts/ai-shared';
2
+ export function aiEvent2GoogleContent(e) {
3
+ switch (e.type) {
4
+ case AIEventType.USER_CHAT:
5
+ // Include Images
6
+ if (e.images?.length) {
7
+ return {
8
+ role: 'user',
9
+ parts: [
10
+ { text: e.content },
11
+ ...e.images.map(image => ({
12
+ fileData: {
13
+ fileUri: image.data,
14
+ mimeType: image.mime,
15
+ },
16
+ })),
17
+ ],
18
+ };
19
+ }
20
+ // Plain Text
21
+ return {
22
+ role: 'user',
23
+ parts: [{ text: e.content }],
24
+ };
25
+ case AIEventType.AI_CHAT:
26
+ return {
27
+ role: 'model',
28
+ parts: [{ text: e.content }],
29
+ };
30
+ case AIEventType.TOOL_REQUEST:
31
+ return {
32
+ role: 'model',
33
+ parts: e.toolCalls.map(tc => ({
34
+ functionCall: {
35
+ name: tc.tool,
36
+ args: tc.params,
37
+ },
38
+ })),
39
+ };
40
+ case AIEventType.TOOL_RESPONSE:
41
+ return {
42
+ role: 'function',
43
+ parts: [
44
+ {
45
+ functionResponse: {
46
+ name: e.tool,
47
+ response: {
48
+ name: e.tool,
49
+ content: e.content,
50
+ },
51
+ },
52
+ },
53
+ ],
54
+ };
55
+ }
56
+ }
@@ -0,0 +1,4 @@
1
+ import { FunctionDeclaration } from '@google/generative-ai';
2
+ import { AITool } from '@sjts/ai-shared';
3
+ export declare function aiTool2GoogleFunctionDeclaration(tool: AITool): FunctionDeclaration;
4
+ //# sourceMappingURL=aiTool2GoogleFunctionDeclaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiTool2GoogleFunctionDeclaration.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/aiTool2GoogleFunctionDeclaration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAiC,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CASlF"}
@@ -0,0 +1,12 @@
1
+ import { FunctionDeclarationSchemaType } from '@google/generative-ai';
2
+ import { compileObject } from '../../compileObject.js';
3
+ export function aiTool2GoogleFunctionDeclaration(tool) {
4
+ return {
5
+ name: tool.key,
6
+ description: tool.description,
7
+ parameters: {
8
+ ...compileObject(tool.params),
9
+ type: FunctionDeclarationSchemaType.OBJECT,
10
+ },
11
+ };
12
+ }
@@ -0,0 +1,8 @@
1
+ import { Content, FunctionDeclaration } from '@google/generative-ai';
2
+ import { AIThoughtInput } from '@sjts/ai-shared';
3
+ export declare function compileGoogleThought(input: AIThoughtInput): {
4
+ systemInstruction: string | undefined;
5
+ contents: Content[];
6
+ functionDeclarations: FunctionDeclaration[];
7
+ };
8
+ //# sourceMappingURL=compileGoogleThought.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileGoogleThought.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/compileGoogleThought.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAI7D,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG;IAC5D,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,oBAAoB,EAAE,mBAAmB,EAAE,CAAA;CAC3C,CAqBA"}
@@ -0,0 +1,22 @@
1
+ import { AIEventType } from '@sjts/ai-shared';
2
+ import { aiEvent2GoogleContent } from './aiEvent2GoogleContent.js';
3
+ import { aiTool2GoogleFunctionDeclaration } from './aiTool2GoogleFunctionDeclaration.js';
4
+ export function compileGoogleThought(input) {
5
+ let systemInstruction = input.context ?? undefined;
6
+ let contents = input.history?.map(aiEvent2GoogleContent) ?? [];
7
+ // MUST have contents - if only a system prompt, turn it into a user prompt
8
+ if (!contents.length && systemInstruction) {
9
+ contents = [
10
+ aiEvent2GoogleContent({
11
+ type: AIEventType.USER_CHAT,
12
+ content: systemInstruction,
13
+ }),
14
+ ];
15
+ systemInstruction = undefined;
16
+ }
17
+ // MUST have contents - if still no contents, throw an error
18
+ if (!contents.length)
19
+ throw new Error('No content to process');
20
+ const functionDeclarations = input.tools?.map(aiTool2GoogleFunctionDeclaration) ?? [];
21
+ return { systemInstruction, contents, functionDeclarations };
22
+ }
@@ -0,0 +1,4 @@
1
+ import { GoogleGenerativeAI } from '@google/generative-ai';
2
+ import { APIConfig } from '@sjts/lib-utils';
3
+ export declare function getGoogleClient(cfg: APIConfig): GoogleGenerativeAI;
4
+ //# sourceMappingURL=getGoogleClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGoogleClient.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/getGoogleClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAI3C,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,kBAAkB,CAKlE"}
@@ -0,0 +1,8 @@
1
+ import { GoogleGenerativeAI } from '@google/generative-ai';
2
+ const _cache = { current: undefined };
3
+ export function getGoogleClient(cfg) {
4
+ if (!_cache.current) {
5
+ _cache.current = new GoogleGenerativeAI(cfg.apiKey ?? '');
6
+ }
7
+ return _cache.current;
8
+ }
@@ -0,0 +1,3 @@
1
+ import { AIToolChoice } from '@sjts/ai-shared';
2
+ export declare function getGoogleToolMode(toolChoice: AIToolChoice): "NONE" | "ANY" | "AUTO";
3
+ //# sourceMappingURL=getGoogleToolMode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getGoogleToolMode.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/getGoogleToolMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,YAAY,2BASzD"}
@@ -0,0 +1,11 @@
1
+ import { AIToolChoice } from '@sjts/ai-shared';
2
+ export function getGoogleToolMode(toolChoice) {
3
+ switch (toolChoice) {
4
+ case AIToolChoice.NONE:
5
+ return 'NONE';
6
+ case AIToolChoice.REQUIRED:
7
+ return 'ANY';
8
+ default:
9
+ return 'AUTO';
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ export * from './aiEvent2GoogleContent.js';
2
+ export * from './aiTool2GoogleFunctionDeclaration.js';
3
+ export * from './compileGoogleThought.js';
4
+ export * from './getGoogleClient.js';
5
+ export * from './getGoogleToolMode.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/_/google/_/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,uCAAuC,CAAA;AACrD,cAAc,2BAA2B,CAAA;AACzC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './aiEvent2GoogleContent.js';
2
+ export * from './aiTool2GoogleFunctionDeclaration.js';
3
+ export * from './compileGoogleThought.js';
4
+ export * from './getGoogleClient.js';
5
+ export * from './getGoogleToolMode.js';
@@ -0,0 +1,3 @@
1
+ export * from './makeGoogleQuickie.js';
2
+ export * from './makeGoogleThink.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_/google/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './makeGoogleQuickie.js';
2
+ export * from './makeGoogleThink.js';
@@ -0,0 +1,3 @@
1
+ import { AIConfig, AIImage } from '@sjts/ai-shared';
2
+ export declare function makeGoogleQuickie(): (ai: AIConfig, content: string, images?: AIImage[]) => Promise<string>;
3
+ //# sourceMappingURL=makeGoogleQuickie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeGoogleQuickie.d.ts","sourceRoot":"","sources":["../../../src/_/google/makeGoogleQuickie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,OAAO,EAAmB,MAAM,iBAAiB,CAAA;AAMjF,wBAAgB,iBAAiB,KAClB,IAAI,QAAQ,EAAE,SAAS,MAAM,EAAE,SAAQ,OAAO,EAAO,KAAG,OAAO,CAAC,MAAM,CAAC,CAIrF"}
@@ -0,0 +1,52 @@
1
+ import { AIEventType, defaultAIConfig } from '@sjts/ai-shared';
2
+ import { Logger } from '@sjts/lib-log';
3
+ import { callAI } from '../callAI.js';
4
+ import { getGoogleClient } from './_/getGoogleClient.js';
5
+ import { aiEvent2GoogleContent } from './_/index.js';
6
+ export function makeGoogleQuickie() {
7
+ return async (ai, content, images = []) => {
8
+ const response = await handleRequest(ai, content, images);
9
+ return handleResponse(response);
10
+ };
11
+ }
12
+ // ---------------
13
+ // HANDLE REQUEST
14
+ // ---------------
15
+ async function handleRequest(ai, content, images = []) {
16
+ try {
17
+ const client = getGoogleClient(ai.api);
18
+ const c = { ...defaultAIConfig, ...ai };
19
+ const generationConfig = {
20
+ maxOutputTokens: c.max_tokens,
21
+ // temperature: c.temperature,
22
+ // topP: c.top_p,
23
+ };
24
+ const genModel = client.getGenerativeModel({ model: c.llm.model, generationConfig });
25
+ if (ai.jsonMode)
26
+ generationConfig.responseMimeType = 'application/json';
27
+ const request = {
28
+ contents: [aiEvent2GoogleContent({ type: AIEventType.USER_CHAT, content, images })],
29
+ generationConfig,
30
+ };
31
+ return callAI(async (r) => {
32
+ const rsp = await genModel.generateContent(r);
33
+ return rsp.response;
34
+ }, request, c.timeout);
35
+ }
36
+ catch (e) {
37
+ Logger.error('Problem processing AI Request', { message: e.message });
38
+ throw e;
39
+ }
40
+ }
41
+ // ---------------
42
+ // HANDLE RESPONSE
43
+ // ---------------
44
+ async function handleResponse(response) {
45
+ try {
46
+ return response.candidates[0].content.parts[0].text;
47
+ }
48
+ catch (e) {
49
+ Logger.error('Problem processing AI response', { message: e.message });
50
+ throw e;
51
+ }
52
+ }
@@ -0,0 +1,3 @@
1
+ import { AIConfig, AIThoughtInput, AIThoughtOutput } from '@sjts/ai-shared';
2
+ export declare function makeGoogleThink(): (ai: AIConfig, input: AIThoughtInput) => Promise<AIThoughtOutput>;
3
+ //# sourceMappingURL=makeGoogleThink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeGoogleThink.d.ts","sourceRoot":"","sources":["../../../src/_/google/makeGoogleThink.ts"],"names":[],"mappings":"AACA,OAAO,EACN,QAAQ,EAER,cAAc,EACd,eAAe,EAEf,MAAM,iBAAiB,CAAA;AAOxB,wBAAgB,eAAe,KAChB,IAAI,QAAQ,EAAE,OAAO,cAAc,KAAG,OAAO,CAAC,eAAe,CAAC,CAI5E"}
@@ -0,0 +1,93 @@
1
+ import { AIEventType, defaultAIConfig, } from '@sjts/ai-shared';
2
+ import { Logger } from '@sjts/lib-log';
3
+ import * as uuid from 'uuid';
4
+ import { callAI } from '../callAI.js';
5
+ import { compileGoogleThought } from './_/compileGoogleThought.js';
6
+ import { getGoogleClient } from './_/getGoogleClient.js';
7
+ export function makeGoogleThink() {
8
+ return async (ai, input) => {
9
+ const response = await handleRequest(ai, input);
10
+ return handleResponse(response);
11
+ };
12
+ }
13
+ // ---------------
14
+ // HANDLE REQUEST
15
+ // ---------------
16
+ async function handleRequest(ai, input) {
17
+ try {
18
+ // Initialize Gemini client
19
+ const client = getGoogleClient(ai.api);
20
+ const c = { ...defaultAIConfig, ...ai };
21
+ const generationConfig = {
22
+ maxOutputTokens: c.max_tokens,
23
+ // temperature: c.temperature,
24
+ // topP: c.top_p,
25
+ };
26
+ // Compile Gemini thought
27
+ const v = await compileGoogleThought(input);
28
+ const { contents, systemInstruction, functionDeclarations } = v;
29
+ // Handle tools
30
+ const hasFncs = !!functionDeclarations?.length;
31
+ const tools = hasFncs ? [{ functionDeclarations }] : undefined;
32
+ const toolConfig = !hasFncs
33
+ ? undefined
34
+ : {
35
+ function_calling_config: { mode: 'ANY' },
36
+ };
37
+ const genModel = client.getGenerativeModel({ model: ai.llm.model });
38
+ if (ai.jsonMode)
39
+ generationConfig.responseMimeType = 'application/json';
40
+ const request = {
41
+ contents,
42
+ systemInstruction,
43
+ tools,
44
+ toolConfig,
45
+ generationConfig,
46
+ };
47
+ return callAI(async (r) => {
48
+ const rsp = await genModel.generateContent(r);
49
+ return rsp.response;
50
+ }, request, c.timeout);
51
+ }
52
+ catch (e) {
53
+ Logger.error('Problem processing AI Request', { message: e.message });
54
+ throw e;
55
+ }
56
+ }
57
+ // ---------------
58
+ // HANDLE RESPONSE
59
+ // ---------------
60
+ async function handleResponse(response) {
61
+ try {
62
+ const parts = response.candidates?.[0].content.parts ?? [];
63
+ const textParts = parts.map(p => p.text).filter(Boolean);
64
+ const toolParts = parts.map(p => p.functionCall).filter(Boolean);
65
+ //----------------
66
+ // AI TOOL CALL MESSAGE
67
+ //----------------
68
+ if (toolParts?.length) {
69
+ return {
70
+ type: AIEventType.TOOL_REQUEST,
71
+ content: textParts.join('\n\n'),
72
+ toolCalls: toolParts.map(t => ({
73
+ callId: uuid.v4(),
74
+ tool: t?.name ?? '',
75
+ params: t?.args ?? '',
76
+ })),
77
+ };
78
+ }
79
+ //----------------
80
+ // AI CHAT MESSAGE
81
+ //---------------
82
+ else {
83
+ return {
84
+ type: AIEventType.AI_CHAT,
85
+ content: textParts.join('\n\n'),
86
+ };
87
+ }
88
+ }
89
+ catch (e) {
90
+ Logger.error('Problem processing AI response', { message: e.message });
91
+ throw e;
92
+ }
93
+ }
@@ -0,0 +1,13 @@
1
+ export * from './amazon/index.js';
2
+ export * from './anthropic/index.js';
3
+ export * from './callAI.js';
4
+ export * from './cerebras/index.js';
5
+ export * from './compileObject.js';
6
+ export * from './compileParam.js';
7
+ export * from './google/index.js';
8
+ export * from './logAI.js';
9
+ export * from './mistral/index.js';
10
+ export * from './openai/index.js';
11
+ export * from './types/index.js';
12
+ export * from './voyageai/index.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/_/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,12 @@
1
+ export * from './amazon/index.js';
2
+ export * from './anthropic/index.js';
3
+ export * from './callAI.js';
4
+ export * from './cerebras/index.js';
5
+ export * from './compileObject.js';
6
+ export * from './compileParam.js';
7
+ export * from './google/index.js';
8
+ export * from './logAI.js';
9
+ export * from './mistral/index.js';
10
+ export * from './openai/index.js';
11
+ export * from './types/index.js';
12
+ export * from './voyageai/index.js';
@@ -0,0 +1,3 @@
1
+ export declare function logAIRequest(request: any): void;
2
+ export declare function logAIResponse(response: any): void;
3
+ //# sourceMappingURL=logAI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logAI.d.ts","sourceRoot":"","sources":["../../src/_/logAI.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,OAAO,EAAE,GAAG,QAExC;AACD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,GAAG,QAE1C"}
@@ -0,0 +1,7 @@
1
+ import { Logger } from '@sjts/lib-log';
2
+ export function logAIRequest(request) {
3
+ Logger.debug('Request', JSON.stringify(request, null, 4));
4
+ }
5
+ export function logAIResponse(response) {
6
+ Logger.debug('Response', JSON.stringify(response, null, 4));
7
+ }
@@ -0,0 +1,3 @@
1
+ import { AIEvent } from '@sjts/ai-shared';
2
+ export declare function aiEvent2MistralAIMessage(event: AIEvent): any;
3
+ //# sourceMappingURL=aiEvent2MistralAIMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aiEvent2MistralAIMessage.d.ts","sourceRoot":"","sources":["../../../../src/_/mistral/_/aiEvent2MistralAIMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,iBAAiB,CAAA;AAEtD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,CAmD5D"}