@zimtsui/brainswitch 0.0.55 → 0.0.57

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 (272) hide show
  1. package/DEVELOPMENT.md +13 -14
  2. package/README.md +110 -62
  3. package/assets/verbatim/declarations.handlebars +11 -0
  4. package/assets/verbatim/instruction.md +49 -0
  5. package/build/adaptor.d.ts +38 -7
  6. package/build/adaptor.js +35 -37
  7. package/build/adaptor.js.map +1 -1
  8. package/build/api-types/anthropic/billing.d.ts +12 -0
  9. package/build/api-types/anthropic/billing.js +14 -0
  10. package/build/api-types/anthropic/billing.js.map +1 -0
  11. package/build/api-types/anthropic/tool-codec.d.ts +16 -0
  12. package/build/api-types/anthropic/tool-codec.js +58 -0
  13. package/build/api-types/anthropic/tool-codec.js.map +1 -0
  14. package/build/api-types/google/billing.d.ts +12 -0
  15. package/build/api-types/google/billing.js +23 -0
  16. package/build/api-types/google/billing.js.map +1 -0
  17. package/build/api-types/google/restful-request.d.ts +8 -0
  18. package/build/api-types/google/restful-request.js +1 -0
  19. package/build/api-types/google/restful-request.js.map +1 -0
  20. package/build/api-types/google/tool-codec.d.ts +16 -0
  21. package/build/api-types/{google.js → google/tool-codec.js} +32 -29
  22. package/build/api-types/google/tool-codec.js.map +1 -0
  23. package/build/api-types/openai-chatcompletions/billing.d.ts +12 -0
  24. package/build/api-types/openai-chatcompletions/billing.js +14 -0
  25. package/build/api-types/openai-chatcompletions/billing.js.map +1 -0
  26. package/build/api-types/openai-chatcompletions/tool-codec.d.ts +17 -0
  27. package/build/api-types/openai-chatcompletions/tool-codec.js +80 -0
  28. package/build/api-types/openai-chatcompletions/tool-codec.js.map +1 -0
  29. package/build/api-types/openai-responses/billing.d.ts +12 -0
  30. package/build/api-types/openai-responses/billing.js +14 -0
  31. package/build/api-types/openai-responses/billing.js.map +1 -0
  32. package/build/api-types/openai-responses/tool-codec.d.ts +16 -0
  33. package/build/api-types/openai-responses/tool-codec.js +76 -0
  34. package/build/api-types/openai-responses/tool-codec.js.map +1 -0
  35. package/build/assets.d.ts +7 -0
  36. package/build/assets.js +8 -0
  37. package/build/assets.js.map +1 -0
  38. package/build/compatible-engine/session.d.ts +67 -0
  39. package/build/compatible-engine/session.js +92 -0
  40. package/build/compatible-engine/session.js.map +1 -0
  41. package/build/compatible-engine/structuring.d.ts +36 -0
  42. package/build/compatible-engine/structuring.js +34 -0
  43. package/build/compatible-engine/structuring.js.map +1 -0
  44. package/build/compatible-engine/validation.d.ts +21 -0
  45. package/build/compatible-engine/validation.js +82 -0
  46. package/build/compatible-engine/validation.js.map +1 -0
  47. package/build/compatible-engine.d/agentloop.d.ts +12 -0
  48. package/build/compatible-engine.d/agentloop.js +52 -0
  49. package/build/compatible-engine.d/agentloop.js.map +1 -0
  50. package/build/compatible-engine.d/aliyun/transport.d.ts +12 -0
  51. package/build/compatible-engine.d/aliyun/transport.js +7 -0
  52. package/build/compatible-engine.d/aliyun/transport.js.map +1 -0
  53. package/build/compatible-engine.d/aliyun.d.ts +24 -0
  54. package/build/compatible-engine.d/aliyun.js +46 -0
  55. package/build/compatible-engine.d/aliyun.js.map +1 -0
  56. package/build/compatible-engine.d/anthropic/choice-codec.d.ts +5 -0
  57. package/build/compatible-engine.d/anthropic/choice-codec.js +26 -0
  58. package/build/compatible-engine.d/anthropic/choice-codec.js.map +1 -0
  59. package/build/compatible-engine.d/anthropic/message-codec.d.ts +36 -0
  60. package/build/compatible-engine.d/anthropic/message-codec.js +86 -0
  61. package/build/compatible-engine.d/anthropic/message-codec.js.map +1 -0
  62. package/build/compatible-engine.d/anthropic/transport.d.ts +34 -0
  63. package/build/compatible-engine.d/anthropic/transport.js +150 -0
  64. package/build/compatible-engine.d/anthropic/transport.js.map +1 -0
  65. package/build/compatible-engine.d/anthropic.d.ts +26 -0
  66. package/build/compatible-engine.d/anthropic.js +46 -0
  67. package/build/compatible-engine.d/anthropic.js.map +1 -0
  68. package/build/compatible-engine.d/google/choice-codec.d.ts +5 -0
  69. package/build/compatible-engine.d/google/choice-codec.js +27 -0
  70. package/build/compatible-engine.d/google/choice-codec.js.map +1 -0
  71. package/build/compatible-engine.d/google/message-codec.d.ts +36 -0
  72. package/build/compatible-engine.d/google/message-codec.js +94 -0
  73. package/build/compatible-engine.d/google/message-codec.js.map +1 -0
  74. package/build/compatible-engine.d/google/transport.d.ts +30 -0
  75. package/build/compatible-engine.d/google/transport.js +78 -0
  76. package/build/compatible-engine.d/google/transport.js.map +1 -0
  77. package/build/compatible-engine.d/google.d.ts +26 -0
  78. package/build/compatible-engine.d/google.js +50 -0
  79. package/build/compatible-engine.d/google.js.map +1 -0
  80. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.d.ts +5 -0
  81. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js +31 -0
  82. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js.map +1 -0
  83. package/build/compatible-engine.d/openai-chatcompletions/message-codec.d.ts +24 -0
  84. package/build/compatible-engine.d/openai-chatcompletions/message-codec.js +71 -0
  85. package/build/compatible-engine.d/openai-chatcompletions/message-codec.js.map +1 -0
  86. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.d.ts +38 -0
  87. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.js +77 -0
  88. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.js.map +1 -0
  89. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.d.ts +37 -0
  90. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js +190 -0
  91. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js.map +1 -0
  92. package/build/compatible-engine.d/openai-chatcompletions/transport.d.ts +10 -0
  93. package/build/compatible-engine.d/openai-chatcompletions/transport.js +11 -0
  94. package/build/compatible-engine.d/openai-chatcompletions/transport.js.map +1 -0
  95. package/build/compatible-engine.d/openai-chatcompletions.d.ts +17 -0
  96. package/build/compatible-engine.d/openai-chatcompletions.js +14 -0
  97. package/build/compatible-engine.d/openai-chatcompletions.js.map +1 -0
  98. package/build/compatible-engine.d/openai-responses/choice-codec.d.ts +5 -0
  99. package/build/compatible-engine.d/openai-responses/choice-codec.js +30 -0
  100. package/build/compatible-engine.d/openai-responses/choice-codec.js.map +1 -0
  101. package/build/compatible-engine.d/openai-responses/message-codec.d.ts +36 -0
  102. package/build/compatible-engine.d/openai-responses/message-codec.js +96 -0
  103. package/build/compatible-engine.d/openai-responses/message-codec.js.map +1 -0
  104. package/build/compatible-engine.d/openai-responses/transport.d.ts +35 -0
  105. package/build/compatible-engine.d/openai-responses/transport.js +80 -0
  106. package/build/compatible-engine.d/openai-responses/transport.js.map +1 -0
  107. package/build/compatible-engine.d/openai-responses.d.ts +26 -0
  108. package/build/compatible-engine.d/openai-responses.js +46 -0
  109. package/build/compatible-engine.d/openai-responses.js.map +1 -0
  110. package/build/compatible-engine.d.ts +17 -46
  111. package/build/compatible-engine.js +20 -58
  112. package/build/compatible-engine.js.map +1 -1
  113. package/build/config.d.ts +1 -0
  114. package/build/config.js +0 -1
  115. package/build/config.js.map +1 -1
  116. package/build/endpoint-spec.d.ts +1 -0
  117. package/build/endpoint-spec.js +2 -1
  118. package/build/endpoint-spec.js.map +1 -1
  119. package/build/engine/session.d.ts +7 -0
  120. package/build/engine/session.js +1 -0
  121. package/build/engine/session.js.map +1 -0
  122. package/build/engine/transport.d.ts +5 -0
  123. package/build/engine/transport.js +1 -0
  124. package/build/engine/transport.js.map +1 -0
  125. package/build/engine/validation.d.ts +9 -0
  126. package/build/engine/validation.js +1 -0
  127. package/build/engine/validation.js.map +1 -0
  128. package/build/engine.d.ts +60 -29
  129. package/build/engine.js +86 -19
  130. package/build/engine.js.map +1 -1
  131. package/build/exports.d.ts +4 -3
  132. package/build/exports.js +4 -3
  133. package/build/exports.js.map +1 -1
  134. package/build/function.d.ts +79 -54
  135. package/build/function.js +30 -46
  136. package/build/function.js.map +1 -1
  137. package/build/inference-context.d.ts +2 -2
  138. package/build/inference-context.js +0 -1
  139. package/build/inference-context.js.map +1 -1
  140. package/build/native-engines.d/google/message-codec.d.ts +23 -0
  141. package/build/native-engines.d/google/message-codec.js +67 -0
  142. package/build/native-engines.d/google/message-codec.js.map +1 -0
  143. package/build/native-engines.d/google/session.d.ts +45 -51
  144. package/build/native-engines.d/google/session.js +84 -80
  145. package/build/native-engines.d/google/session.js.map +1 -1
  146. package/build/native-engines.d/google/transport.d.ts +34 -0
  147. package/build/native-engines.d/google/transport.js +81 -0
  148. package/build/native-engines.d/google/transport.js.map +1 -0
  149. package/build/native-engines.d/google/validation.d.ts +22 -0
  150. package/build/native-engines.d/google/validation.js +20 -0
  151. package/build/native-engines.d/google/validation.js.map +1 -0
  152. package/build/native-engines.d/google.d/agentloop.d.ts +12 -0
  153. package/build/native-engines.d/google.d/agentloop.js +57 -0
  154. package/build/native-engines.d/google.d/agentloop.js.map +1 -0
  155. package/build/native-engines.d/google.d/exports.d.ts +3 -0
  156. package/build/native-engines.d/google.d/exports.js +4 -0
  157. package/build/native-engines.d/google.d/exports.js.map +1 -0
  158. package/build/native-engines.d/google.d.ts +42 -0
  159. package/build/native-engines.d/google.js +83 -0
  160. package/build/native-engines.d/google.js.map +1 -0
  161. package/build/native-engines.d/openai-responses/choice-codec.d.ts +5 -0
  162. package/build/native-engines.d/openai-responses/choice-codec.js +30 -0
  163. package/build/native-engines.d/openai-responses/choice-codec.js.map +1 -0
  164. package/build/native-engines.d/openai-responses/message-codec.d.ts +23 -0
  165. package/build/native-engines.d/openai-responses/message-codec.js +75 -0
  166. package/build/native-engines.d/openai-responses/message-codec.js.map +1 -0
  167. package/build/native-engines.d/openai-responses/session.d.ts +47 -44
  168. package/build/native-engines.d/openai-responses/session.js +73 -103
  169. package/build/native-engines.d/openai-responses/session.js.map +1 -1
  170. package/build/native-engines.d/openai-responses/structuring.d.ts +19 -0
  171. package/build/native-engines.d/openai-responses/structuring.js +19 -0
  172. package/build/native-engines.d/openai-responses/structuring.js.map +1 -0
  173. package/build/native-engines.d/openai-responses/tool.d.ts +14 -11
  174. package/build/native-engines.d/openai-responses/tool.js +1 -12
  175. package/build/native-engines.d/openai-responses/tool.js.map +1 -1
  176. package/build/native-engines.d/openai-responses/transport.d.ts +35 -0
  177. package/build/native-engines.d/openai-responses/transport.js +84 -0
  178. package/build/native-engines.d/openai-responses/transport.js.map +1 -0
  179. package/build/native-engines.d/openai-responses/validation.d.ts +20 -0
  180. package/build/native-engines.d/openai-responses/validation.js +80 -0
  181. package/build/native-engines.d/openai-responses/validation.js.map +1 -0
  182. package/build/native-engines.d/openai-responses.d/agentloop.d.ts +12 -0
  183. package/build/native-engines.d/openai-responses.d/agentloop.js +61 -0
  184. package/build/native-engines.d/openai-responses.d/agentloop.js.map +1 -0
  185. package/build/native-engines.d/{google → openai-responses.d}/exports.d.ts +1 -2
  186. package/build/native-engines.d/{google → openai-responses.d}/exports.js +1 -2
  187. package/build/native-engines.d/openai-responses.d/exports.js.map +1 -0
  188. package/build/native-engines.d/openai-responses.d.ts +44 -0
  189. package/build/native-engines.d/openai-responses.js +78 -0
  190. package/build/native-engines.d/openai-responses.js.map +1 -0
  191. package/build/throttle.d.ts +5 -4
  192. package/build/throttle.js +17 -14
  193. package/build/throttle.js.map +1 -1
  194. package/build/tsconfig.tsbuildinfo +1 -1
  195. package/build/verbatim/codec/declarations.d.ts +2 -0
  196. package/build/verbatim/codec/declarations.js +22 -0
  197. package/build/verbatim/codec/declarations.js.map +1 -0
  198. package/build/verbatim/codec/request.d.ts +7 -0
  199. package/build/verbatim/codec/request.js +53 -0
  200. package/build/verbatim/codec/request.js.map +1 -0
  201. package/build/verbatim/codec.d.ts +2 -0
  202. package/build/verbatim/codec.js +3 -0
  203. package/build/verbatim/codec.js.map +1 -0
  204. package/build/verbatim.d.ts +74 -0
  205. package/build/verbatim.js +17 -0
  206. package/build/verbatim.js.map +1 -0
  207. package/examples/agent.ts +65 -0
  208. package/examples/chat.ts +24 -0
  209. package/examples/config.ts +24 -0
  210. package/examples/tsconfig.json +34 -0
  211. package/examples/verbatim.ts +44 -0
  212. package/package.json +10 -9
  213. package/build/agentloop.d.ts +0 -12
  214. package/build/agentloop.js +0 -43
  215. package/build/agentloop.js.map +0 -1
  216. package/build/api-types/anthropic.d.ts +0 -29
  217. package/build/api-types/anthropic.js +0 -93
  218. package/build/api-types/anthropic.js.map +0 -1
  219. package/build/api-types/google.d.ts +0 -28
  220. package/build/api-types/google.js.map +0 -1
  221. package/build/api-types/openai-chat-completions.d.ts +0 -31
  222. package/build/api-types/openai-chat-completions.js +0 -113
  223. package/build/api-types/openai-chat-completions.js.map +0 -1
  224. package/build/api-types/openai-responses.d.ts +0 -23
  225. package/build/api-types/openai-responses.js +0 -71
  226. package/build/api-types/openai-responses.js.map +0 -1
  227. package/build/compatible-engines.d/aliyun.d.ts +0 -69
  228. package/build/compatible-engines.d/aliyun.js +0 -149
  229. package/build/compatible-engines.d/aliyun.js.map +0 -1
  230. package/build/compatible-engines.d/anthropic.d.ts +0 -78
  231. package/build/compatible-engines.d/anthropic.js +0 -312
  232. package/build/compatible-engines.d/anthropic.js.map +0 -1
  233. package/build/compatible-engines.d/google.d.ts +0 -83
  234. package/build/compatible-engines.d/google.js +0 -279
  235. package/build/compatible-engines.d/google.js.map +0 -1
  236. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +0 -15
  237. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +0 -75
  238. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +0 -1
  239. package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +0 -21
  240. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js +0 -186
  241. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +0 -1
  242. package/build/compatible-engines.d/openai-chatcompletions.d.ts +0 -27
  243. package/build/compatible-engines.d/openai-chatcompletions.js +0 -76
  244. package/build/compatible-engines.d/openai-chatcompletions.js.map +0 -1
  245. package/build/compatible-engines.d/openai-responses.d.ts +0 -93
  246. package/build/compatible-engines.d/openai-responses.js +0 -300
  247. package/build/compatible-engines.d/openai-responses.js.map +0 -1
  248. package/build/frontmatter.d.ts +0 -5
  249. package/build/frontmatter.js +0 -13
  250. package/build/frontmatter.js.map +0 -1
  251. package/build/native-engines.d/google/agentloop.d.ts +0 -12
  252. package/build/native-engines.d/google/agentloop.js +0 -42
  253. package/build/native-engines.d/google/agentloop.js.map +0 -1
  254. package/build/native-engines.d/google/engine.d.ts +0 -110
  255. package/build/native-engines.d/google/engine.js +0 -314
  256. package/build/native-engines.d/google/engine.js.map +0 -1
  257. package/build/native-engines.d/google/exports.js.map +0 -1
  258. package/build/native-engines.d/openai-responses/agentloop.d.ts +0 -13
  259. package/build/native-engines.d/openai-responses/agentloop.js +0 -53
  260. package/build/native-engines.d/openai-responses/agentloop.js.map +0 -1
  261. package/build/native-engines.d/openai-responses/engine.d.ts +0 -112
  262. package/build/native-engines.d/openai-responses/engine.js +0 -344
  263. package/build/native-engines.d/openai-responses/engine.js.map +0 -1
  264. package/build/native-engines.d/openai-responses/exports.d.ts +0 -7
  265. package/build/native-engines.d/openai-responses/exports.js +0 -8
  266. package/build/native-engines.d/openai-responses/exports.js.map +0 -1
  267. package/build/session.d.ts +0 -77
  268. package/build/session.js +0 -137
  269. package/build/session.js.map +0 -1
  270. package/build/test.d.ts +0 -1
  271. package/build/test.js +0 -198
  272. package/build/test.js.map +0 -1
@@ -0,0 +1,57 @@
1
+ import { Function } from "../../function.js";
2
+ import { GoogleNativeEngine } from "../google.js";
3
+ import * as CompatibleAgentloopModule from "../../compatible-engine.d/agentloop.js";
4
+ /**
5
+ * @param session mutable
6
+ */
7
+ export async function* agentloop(wfctx, session, engine, fnm, limit = Number.POSITIVE_INFINITY) {
8
+ for (let i = 0; i < limit; i++) {
9
+ const response = await engine.stateful(wfctx, session);
10
+ if (response.allChatPart())
11
+ return response.getChatText();
12
+ const pfrs = [];
13
+ for (const part of response.getParts()) {
14
+ if (part instanceof GoogleNativeEngine.RoleMessage.Part.Text) {
15
+ yield GoogleNativeEngine.RoleMessage.Ai.encodeChatPart(part);
16
+ }
17
+ else if (part instanceof Function.Call) {
18
+ const fc = part;
19
+ const f = fnm[fc.name];
20
+ pfrs.push((async () => {
21
+ try {
22
+ return Function.Response.Successful.of({
23
+ id: fc.id,
24
+ name: fc.name,
25
+ text: await f.call(fnm, fc.args),
26
+ });
27
+ }
28
+ catch (e) {
29
+ if (e instanceof Function.Error) { }
30
+ else
31
+ throw e;
32
+ return Function.Response.Failed.of({
33
+ id: fc.id,
34
+ name: fc.name,
35
+ error: e.message,
36
+ });
37
+ }
38
+ })());
39
+ }
40
+ else if (part instanceof GoogleNativeEngine.RoleMessage.Ai.Part.ExecutableCode) {
41
+ yield GoogleNativeEngine.RoleMessage.Ai.encodeChatPart(part);
42
+ }
43
+ else if (part instanceof GoogleNativeEngine.RoleMessage.Ai.Part.CodeExecutionResult) {
44
+ yield GoogleNativeEngine.RoleMessage.Ai.encodeChatPart(part);
45
+ }
46
+ else
47
+ throw new Error();
48
+ }
49
+ const frs = await Promise.all(pfrs);
50
+ engine.pushUserMessage(session, new GoogleNativeEngine.RoleMessage.User(frs));
51
+ }
52
+ throw new agentloop.FunctionCallLimitExceeded('Function call limit exceeded.');
53
+ }
54
+ (function (agentloop) {
55
+ agentloop.FunctionCallLimitExceeded = CompatibleAgentloopModule.agentloop.FunctionCallLimitExceeded;
56
+ })(agentloop || (agentloop = {}));
57
+ //# sourceMappingURL=agentloop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentloop.js","sourceRoot":"","sources":["../../../src/native-engines.d/google.d/agentloop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,yBAAyB,MAAM,wCAAwC,CAAC;AAIpF;;GAEG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAA,SAAS,CAI5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,CAAC,CAAC;wBACjD,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;4BAC/B,EAAE,EAAE,EAAE,CAAC,EAAE;4BACT,IAAI,EAAE,EAAE,CAAC,IAAI;4BACb,KAAK,EAAE,CAAC,CAAC,OAAO;yBAC2B,CAAC,CAAC;oBACrD,CAAC;gBACL,CAAC,CAAC,EAAE,CAAC,CAAC;YACV,CAAC;iBAAM,IAAI,IAAI,YAAY,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC/E,MAAM,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACjE,CAAC;iBAAM,IAAI,IAAI,YAAY,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBACpF,MAAM,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YACjE,CAAC;;gBAAM,MAAM,IAAI,KAAK,EAAE,CAAC;QAC7B,CAAC;QACD,MAAM,GAAG,GAAkC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnE,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,kBAAkB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,+BAA+B,CAAC,CAAC;AACnF,CAAC;AAED,WAAiB,SAAS;IACR,mCAAyB,GAAG,yBAAyB,CAAC,SAAS,CAAC,yBAAyB,CAAC;AAC5G,CAAC,EAFgB,SAAS,KAAT,SAAS,QAEzB"}
@@ -0,0 +1,3 @@
1
+ export * from '../google.ts';
2
+ export * from './agentloop.ts';
3
+ export * from '../../telemetry.ts';
@@ -0,0 +1,4 @@
1
+ export * from "../google.js";
2
+ export * from "./agentloop.js";
3
+ export * from "../../telemetry.js";
4
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../../src/native-engines.d/google.d/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { Function } from '../function.ts';
2
+ import * as SessionModule from './google/session.ts';
3
+ import { Engine } from '../engine.ts';
4
+ import { type InferenceContext } from '../inference-context.ts';
5
+ import { ToolCodec } from '../api-types/google/tool-codec.ts';
6
+ import { Billing } from '../api-types/google/billing.ts';
7
+ import * as ValidationModule from './google/validation.ts';
8
+ import { MessageCodec as CompatibleMessageCodec } from '../compatible-engine.d/google/message-codec.ts';
9
+ import * as MessageCodecModule from './google/message-codec.ts';
10
+ import { GoogleNativeTransport } from './google/transport.ts';
11
+ import type { Verbatim } from '../verbatim.ts';
12
+ import { Structuring } from '../compatible-engine/structuring.ts';
13
+ export type GoogleNativeEngine<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = GoogleNativeEngine.Instance<fdm, vdm>;
14
+ export declare namespace GoogleNativeEngine {
15
+ class Instance<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> extends Engine.Instance<fdm, vdm, GoogleNativeEngine.RoleMessage.User.From<fdm>, GoogleNativeEngine.RoleMessage.Ai.From<fdm, vdm>, GoogleNativeEngine.RoleMessage.Developer, GoogleNativeEngine.Session.From<fdm, vdm>> {
16
+ protected choice: Structuring.Choice.From<fdm, vdm>;
17
+ protected codeExecution: boolean;
18
+ protected urlContext: boolean;
19
+ protected googleSearch: boolean;
20
+ protected toolCodec: ToolCodec<fdm>;
21
+ protected compatibleMessageCodec: CompatibleMessageCodec<fdm, vdm>;
22
+ protected messageCodec: GoogleNativeEngine.MessageCodec<fdm, vdm>;
23
+ protected billing: Billing;
24
+ protected validator: GoogleNativeEngine.Validator.From<fdm, vdm>;
25
+ protected transport: GoogleNativeTransport<fdm, vdm>;
26
+ protected parallelToolCall: boolean;
27
+ constructor(options: GoogleNativeEngine.Options<fdm, vdm>);
28
+ protected infer(wfctx: InferenceContext, session: GoogleNativeEngine.Session.From<fdm, vdm>, signal?: AbortSignal): Promise<GoogleNativeEngine.RoleMessage.Ai.From<fdm, vdm>>;
29
+ appendUserMessage(session: GoogleNativeEngine.Session.From<fdm, vdm>, message: GoogleNativeEngine.RoleMessage.User.From<fdm>): GoogleNativeEngine.Session.From<fdm, vdm>;
30
+ pushUserMessage(session: GoogleNativeEngine.Session.From<fdm, vdm>, message: GoogleNativeEngine.RoleMessage.User.From<fdm>): GoogleNativeEngine.Session.From<fdm, vdm>;
31
+ }
32
+ interface Options<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> extends Engine.Options<fdm, vdm> {
33
+ structuringChoice?: Structuring.Choice.From<fdm, vdm>;
34
+ codeExecution?: boolean;
35
+ urlContext?: boolean;
36
+ googleSearch?: boolean;
37
+ }
38
+ export import Session = SessionModule.Session;
39
+ export import RoleMessage = SessionModule.RoleMessage;
40
+ export import Validator = ValidationModule.Validator;
41
+ export import MessageCodec = MessageCodecModule.MessageCodec;
42
+ }
@@ -0,0 +1,83 @@
1
+ import * as SessionModule from "./google/session.js";
2
+ import { Engine } from "../engine.js";
3
+ import { ToolCodec } from "../api-types/google/tool-codec.js";
4
+ import { Billing } from "../api-types/google/billing.js";
5
+ import * as ValidationModule from "./google/validation.js";
6
+ import { MessageCodec as CompatibleMessageCodec } from "../compatible-engine.d/google/message-codec.js";
7
+ import * as MessageCodecModule from "./google/message-codec.js";
8
+ import { GoogleNativeTransport } from "./google/transport.js";
9
+ import { Structuring } from "../compatible-engine/structuring.js";
10
+ export var GoogleNativeEngine;
11
+ (function (GoogleNativeEngine) {
12
+ class Instance extends Engine.Instance {
13
+ choice;
14
+ codeExecution;
15
+ urlContext;
16
+ googleSearch;
17
+ toolCodec;
18
+ compatibleMessageCodec;
19
+ messageCodec;
20
+ billing;
21
+ validator;
22
+ transport;
23
+ parallelToolCall;
24
+ constructor(options) {
25
+ super(options);
26
+ this.parallelToolCall = options.parallelToolCall ?? true;
27
+ if (this.parallelToolCall) { }
28
+ else
29
+ throw new Error('Parallel tool calling is required by Google engine.');
30
+ this.choice = options.structuringChoice ?? Structuring.Choice.AUTO;
31
+ this.codeExecution = options.codeExecution ?? false;
32
+ this.urlContext = options.urlContext ?? false;
33
+ this.googleSearch = options.googleSearch ?? false;
34
+ this.toolCodec = new ToolCodec({
35
+ fdm: this.fdm,
36
+ });
37
+ this.compatibleMessageCodec = new CompatibleMessageCodec({
38
+ toolCodec: this.toolCodec,
39
+ vdm: this.vdm,
40
+ });
41
+ this.messageCodec = new GoogleNativeEngine.MessageCodec({
42
+ toolCodec: this.toolCodec,
43
+ compatibleMessageCodec: this.compatibleMessageCodec,
44
+ codeExecution: this.codeExecution,
45
+ vdm: this.vdm,
46
+ });
47
+ this.billing = new Billing({ pricing: this.pricing });
48
+ this.validator = new GoogleNativeEngine.Validator({ choice: this.choice });
49
+ this.transport = new GoogleNativeTransport({
50
+ inferenceParams: this.inferenceParams,
51
+ providerSpec: this.providerSpec,
52
+ fdm: this.fdm,
53
+ throttle: this.throttle,
54
+ choice: this.choice,
55
+ codeExecution: this.codeExecution,
56
+ urlContext: this.urlContext,
57
+ googleSearch: this.googleSearch,
58
+ messageCodec: this.messageCodec,
59
+ toolCodec: this.toolCodec,
60
+ billing: this.billing,
61
+ validator: this.validator,
62
+ });
63
+ }
64
+ infer(wfctx, session, signal) {
65
+ return this.transport.fetch(wfctx, session, signal);
66
+ }
67
+ appendUserMessage(session, message) {
68
+ return {
69
+ developerMessage: session.developerMessage,
70
+ chatMessages: [...session.chatMessages, message],
71
+ };
72
+ }
73
+ pushUserMessage(session, message) {
74
+ session.chatMessages.push(message);
75
+ return session;
76
+ }
77
+ }
78
+ GoogleNativeEngine.Instance = Instance;
79
+ GoogleNativeEngine.RoleMessage = SessionModule.RoleMessage;
80
+ GoogleNativeEngine.Validator = ValidationModule.Validator;
81
+ GoogleNativeEngine.MessageCodec = MessageCodecModule.MessageCodec;
82
+ })(GoogleNativeEngine || (GoogleNativeEngine = {}));
83
+ //# sourceMappingURL=google.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/native-engines.d/google.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,YAAY,IAAI,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AACxG,OAAO,KAAK,kBAAkB,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAQlE,MAAM,KAAW,kBAAkB,CAyGlC;AAzGD,WAAiB,kBAAkB;IAC/B,MAAa,QAGX,SAAQ,MAAM,CAAC,QAMhB;QACa,MAAM,CAAoC;QAC1C,aAAa,CAAU;QACvB,UAAU,CAAU;QACpB,YAAY,CAAU;QAEtB,SAAS,CAAiB;QAC1B,sBAAsB,CAAmC;QACzD,YAAY,CAA4C;QACxD,OAAO,CAAU;QACR,SAAS,CAA8C;QACvD,SAAS,CAAkC;QAC3C,gBAAgB,CAAU;QAE7C,YAAmB,OAA6C;YAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,IAAI,CAAC;YACzD,IAAI,IAAI,CAAC,gBAAgB,EAAE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BACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,aAAa,EAAE,IAAI,CAAC,aAAa;gBACjC,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,SAAS,EAAE,IAAI,CAAC,SAAS;aAC5B,CAAC,CAAC;QACP,CAAC;QAEkB,KAAK,CACpB,KAAuB,EACvB,OAAkD,EAClD,MAAoB;YAEpB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACxD,CAAC;QAEe,iBAAiB,CAC7B,OAAkD,EAClD,OAAsD;YAEtD,OAAO;gBACH,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;gBAC1C,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC;aACnD,CAAC;QACN,CAAC;QAEe,eAAe,CAC3B,OAAkD,EAClD,OAAsD;YAEtD,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,OAAO,CAAC;QACnB,CAAC;KACJ;IAxFY,2BAAQ,WAwFpB,CAAA;IAaa,8BAAW,GAAG,aAAa,CAAC,WAAW,CAAC;IACxC,4BAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC;IACvC,+BAAY,GAAG,kBAAkB,CAAC,YAAY,CAAC;AACjE,CAAC,EAzGgB,kBAAkB,KAAlB,kBAAkB,QAyGlC"}
@@ -0,0 +1,5 @@
1
+ import { Structuring } from './structuring.ts';
2
+ import type { Function } from '../../function.ts';
3
+ import type { Verbatim } from '../../verbatim.ts';
4
+ import type { OpenAI } from 'openai';
5
+ export declare function encode<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto>(choice: Structuring.Choice<fdu, vdu>): OpenAI.Responses.ToolChoiceOptions | OpenAI.Responses.ToolChoiceAllowed;
@@ -0,0 +1,30 @@
1
+ import { Structuring } from "./structuring.js";
2
+ export function encode(choice) {
3
+ if (choice === Structuring.Choice.NONE)
4
+ return 'none';
5
+ else if (choice === Structuring.Choice.REQUIRED)
6
+ return 'auto';
7
+ else if (choice === Structuring.Choice.ANYONE)
8
+ return 'auto';
9
+ else if (choice === Structuring.Choice.AUTO)
10
+ return 'auto';
11
+ else if (choice === Structuring.Choice.TCall.REQUIRED)
12
+ return 'required';
13
+ else if (choice === Structuring.Choice.TCall.ANYONE)
14
+ return 'required';
15
+ else if (choice instanceof Structuring.Choice.TCall.FCall)
16
+ return {
17
+ type: 'allowed_tools',
18
+ mode: 'required',
19
+ tools: [{ type: 'function', name: choice.name }],
20
+ };
21
+ else if (choice === Structuring.Choice.VRequest.REQUIRED)
22
+ return 'none';
23
+ else if (choice === Structuring.Choice.VRequest.ANYONE)
24
+ return 'none';
25
+ else if (choice instanceof Structuring.Choice.VRequest)
26
+ return 'none';
27
+ else
28
+ throw new Error();
29
+ }
30
+ //# sourceMappingURL=choice-codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"choice-codec.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/choice-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,UAAU,MAAM,CAIlB,MAAoC;IAEpC,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;SACjD,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,MAAM,CAAC;SAC1D,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;SACxD,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;SAEtD,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ;QAAE,OAAO,UAAU,CAAC;SACpE,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC;SAClE,IAAI,MAAM,YAAY,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK;QACrD,OAAO;YACH,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAiD;SACnG,CAAC;SAED,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ;QAAE,OAAO,MAAM,CAAC;SACnE,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;SACjE,IAAI,MAAM,YAAY,WAAW,CAAC,MAAM,CAAC,QAAQ;QAAE,OAAO,MAAM,CAAC;;QAEjE,MAAM,IAAI,KAAK,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { RoleMessage, type Session } from './session.ts';
2
+ import { Function } from '../../function.ts';
3
+ import OpenAI from 'openai';
4
+ import { MessageCodec as CompatibleMessageCodec } from '../../compatible-engine.d/openai-responses/message-codec.ts';
5
+ import type { ToolCodec } from '../../api-types/openai-responses/tool-codec.ts';
6
+ import type { Verbatim } from '../../verbatim.ts';
7
+ export declare class MessageCodec<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> {
8
+ protected ctx: MessageCodec.Context<fdm, vdm>;
9
+ constructor(ctx: MessageCodec.Context<fdm, vdm>);
10
+ encodeFunctionResponse(fr: Function.Response.From<fdm>): OpenAI.Responses.ResponseInputItem.FunctionCallOutput;
11
+ decodeAiMessage(output: OpenAI.Responses.ResponseOutputItem[]): RoleMessage.Ai.From<fdm, vdm>;
12
+ encodeUserMessage(userMessage: RoleMessage.User.From<fdm>): OpenAI.Responses.ResponseInput;
13
+ encodeAiMessage(aiMessage: RoleMessage.Ai.From<fdm, vdm>): OpenAI.Responses.ResponseInput;
14
+ encodeDeveloperMessage(developerMessage: RoleMessage.Developer): string;
15
+ encodeChatMessage(chatMessage: Session.ChatMessage.From<fdm, vdm>): OpenAI.Responses.ResponseInput;
16
+ }
17
+ export declare namespace MessageCodec {
18
+ interface Context<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> {
19
+ toolCodec: ToolCodec<fdm>;
20
+ compatibleMessageCodec: CompatibleMessageCodec<fdm, vdm>;
21
+ vdm: vdm;
22
+ }
23
+ }
@@ -0,0 +1,75 @@
1
+ import { RoleMessage } from "./session.js";
2
+ import { Function } from "../../function.js";
3
+ import { Tool } from "./tool.js";
4
+ import { ResponseInvalid } from "../../engine.js";
5
+ import * as VerbatimCodec from "../../verbatim/codec.js";
6
+ export class MessageCodec {
7
+ ctx;
8
+ constructor(ctx) {
9
+ this.ctx = ctx;
10
+ }
11
+ encodeFunctionResponse(fr) {
12
+ return this.ctx.toolCodec.encodeFunctionResponse(fr);
13
+ }
14
+ decodeAiMessage(output) {
15
+ const parts = output.flatMap((item) => {
16
+ if (item.type === 'message') {
17
+ if (item.content.every(part => part.type === 'output_text')) { }
18
+ else
19
+ throw new ResponseInvalid('Refusal', { cause: output });
20
+ const text = item.content.map(part => part.text).join('');
21
+ if (text) {
22
+ const vrs = VerbatimCodec.Request.decode(text, this.ctx.vdm);
23
+ return [new RoleMessage.Part.Text(text, vrs)];
24
+ }
25
+ else
26
+ return [];
27
+ }
28
+ else if (item.type === 'function_call')
29
+ return [this.ctx.toolCodec.decodeFunctionCall(item)];
30
+ else if (item.type === 'reasoning')
31
+ return [];
32
+ else if (item.type === 'apply_patch_call')
33
+ return [new Tool.ApplyPatch.Call(item)];
34
+ else
35
+ throw new Error();
36
+ });
37
+ return new RoleMessage.Ai(parts, output);
38
+ }
39
+ encodeUserMessage(userMessage) {
40
+ return userMessage.getParts().map(part => {
41
+ if (part instanceof RoleMessage.Part.Text)
42
+ return {
43
+ type: 'message',
44
+ role: 'user',
45
+ content: part.text,
46
+ };
47
+ else if (part instanceof Function.Response)
48
+ return this.encodeFunctionResponse(part);
49
+ else if (part instanceof Tool.ApplyPatch.Response)
50
+ return {
51
+ type: 'apply_patch_call_output',
52
+ call_id: part.id,
53
+ status: part.failure ? 'failed' : 'completed',
54
+ output: part.failure || undefined,
55
+ };
56
+ else
57
+ throw new Error();
58
+ });
59
+ }
60
+ encodeAiMessage(aiMessage) {
61
+ return aiMessage.getRaw();
62
+ }
63
+ encodeDeveloperMessage(developerMessage) {
64
+ return this.ctx.compatibleMessageCodec.encodeDeveloperMessage(developerMessage);
65
+ }
66
+ encodeChatMessage(chatMessage) {
67
+ if (chatMessage instanceof RoleMessage.User)
68
+ return this.encodeUserMessage(chatMessage);
69
+ else if (chatMessage instanceof RoleMessage.Ai)
70
+ return this.encodeAiMessage(chatMessage);
71
+ else
72
+ throw new Error();
73
+ }
74
+ }
75
+ //# sourceMappingURL=message-codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-codec.js","sourceRoot":"","sources":["../../../src/native-engines.d/openai-responses/message-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKjC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AAIzD,MAAM,OAAO,YAAY;IAIQ;IAA7B,YAA6B,GAAmC;QAAnC,QAAG,GAAH,GAAG,CAAgC;IAAG,CAAC;IAE7D,sB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,CAAC,WAAW,CAAC,CAAC;aAC1C,IAAI,WAAW,YAAY,WAAW,CAAC,EAAE;YAC1C,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;;YACxC,MAAM,IAAI,KAAK,EAAE,CAAC;IAC3B,CAAC;CACJ"}
@@ -1,58 +1,61 @@
1
- import * as Compatible from '../../session.ts';
1
+ import { RoleMessage as CompatibleRoleMessage } from '../../compatible-engine/session.ts';
2
2
  import { Function } from '../../function.ts';
3
3
  import { Tool } from './tool.ts';
4
+ import type { Engine } from '../../engine.ts';
5
+ import type { Verbatim } from '../../verbatim.ts';
4
6
  import OpenAI from 'openai';
5
- export interface Session<out fdu extends Function.Declaration = never> {
6
- developerMessage?: RoleMessage.Developer;
7
- chatMessages: ChatMessage<fdu>[];
7
+ declare const NOMINAL: unique symbol;
8
+ export interface Session<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> extends Engine.Session<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>, RoleMessage.Developer> {
8
9
  }
9
- export type ChatMessage<fdu extends Function.Declaration = never> = RoleMessage.User<fdu> | RoleMessage.Ai<fdu>;
10
- export type RoleMessage = RoleMessage.Instance;
11
- export declare namespace RoleMessage {
12
- const NOMINAL: unique symbol;
13
- abstract class Instance {
14
- private readonly [NOMINAL];
15
- abstract getText(): string;
16
- abstract getOnlyText(): string;
10
+ export declare namespace Session {
11
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Session<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
12
+ type ChatMessage<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = Engine.Session.ChatMessage<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>>;
13
+ namespace ChatMessage {
14
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Session.ChatMessage<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
17
15
  }
16
+ }
17
+ export declare namespace RoleMessage {
18
18
  namespace Part {
19
- export import Text = Compatible.RoleMessage.Part.Text;
19
+ export import Text = CompatibleRoleMessage.Part.Text;
20
+ }
21
+ class Ai<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> {
22
+ protected parts: RoleMessage.Ai.Part<fdu, vdu>[];
23
+ protected raw: OpenAI.Responses.ResponseOutputItem[];
24
+ protected [NOMINAL]: never;
25
+ constructor(parts: RoleMessage.Ai.Part<fdu, vdu>[], raw: OpenAI.Responses.ResponseOutputItem[]);
26
+ getParts(): RoleMessage.Ai.Part<fdu, vdu>[];
27
+ getRaw(): OpenAI.Responses.ResponseOutputItem[];
28
+ allTextPart(): boolean;
29
+ getTextParts(): RoleMessage.Part.Text<vdu>[];
30
+ getText(): string;
31
+ getToolCalls(): Tool.Call.Of<fdu>[];
32
+ getFunctionCalls(): Function.Call.Of<fdu>[];
33
+ getVerbatimRequests(): Verbatim.Request.Of<vdu>[];
34
+ getOnlyFunctionCall(): Function.Call.Of<fdu>;
35
+ getOnlyToolCall(): Tool.Call.Of<fdu>;
36
+ getOnlyVerbatimRequest(): Verbatim.Request.Of<vdu>;
20
37
  }
21
- type Ai<fdu extends Function.Declaration = never> = Ai.Instance<fdu>;
22
38
  namespace Ai {
23
- function create<fdu extends Function.Declaration = never>(parts: RoleMessage.Ai.Part<fdu>[], raw: OpenAI.Responses.ResponseOutputItem[]): RoleMessage.Ai<fdu>;
24
- const NOMINAL: unique symbol;
25
- class Instance<out fdu extends Function.Declaration = never> extends RoleMessage.Instance {
26
- protected parts: RoleMessage.Ai.Part<fdu>[];
27
- protected raw: OpenAI.Responses.ResponseOutputItem[];
28
- readonly [NOMINAL]: void;
29
- constructor(parts: RoleMessage.Ai.Part<fdu>[], raw: OpenAI.Responses.ResponseOutputItem[]);
30
- getParts(): RoleMessage.Ai.Part<fdu>[];
31
- getRaw(): OpenAI.Responses.ResponseOutputItem[];
32
- getText(): string;
33
- getOnlyText(): string;
34
- getOnlyFunctionCall(): Function.Call.Distributive<fdu>;
35
- getOnlyApplyPatchCall(): Tool.ApplyPatch.Call;
36
- getToolCalls(): Tool.Call<fdu>[];
37
- getFunctionCalls(): Function.Call.Distributive<fdu>[];
38
- getOnlyFunctionCalls(): Function.Call.Distributive<fdu>[];
39
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = RoleMessage.Ai<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
40
+ type Part<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = RoleMessage.Part.Text<vdu> | Tool.Call.Of<fdu>;
41
+ namespace Part {
42
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = RoleMessage.Ai.Part<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
39
43
  }
40
- type Part<fdu extends Function.Declaration = never> = RoleMessage.Part.Text | Tool.Call<fdu>;
41
44
  }
42
- type User<fdu extends Function.Declaration = never> = User.Instance<fdu>;
45
+ class User<in out fdu extends Function.Decl.Proto> {
46
+ protected parts: RoleMessage.User.Part<fdu>[];
47
+ protected [NOMINAL]: never;
48
+ constructor(parts: RoleMessage.User.Part<fdu>[]);
49
+ getParts(): RoleMessage.User.Part<fdu>[];
50
+ getToolResponses(): Tool.Response.Of<fdu>[];
51
+ }
43
52
  namespace User {
44
- function create<fdu extends Function.Declaration = never>(parts: User.Part<fdu>[]): User<fdu>;
45
- const NOMINAL: unique symbol;
46
- class Instance<out fdu extends Function.Declaration = never> extends RoleMessage.Instance {
47
- protected parts: RoleMessage.User.Part<fdu>[];
48
- private readonly [NOMINAL];
49
- constructor(parts: RoleMessage.User.Part<fdu>[]);
50
- getParts(): RoleMessage.User.Part<fdu>[];
51
- getText(): string;
52
- getOnlyText(): string;
53
- getToolResponses(): Tool.Response<fdu>[];
53
+ type From<fdm extends Function.Decl.Map.Proto> = RoleMessage.User<Function.Decl.From<fdm>>;
54
+ type Part<fdu extends Function.Decl.Proto> = RoleMessage.Part.Text<never> | Tool.Response.Of<fdu>;
55
+ namespace Part {
56
+ type From<fdm extends Function.Decl.Map.Proto> = RoleMessage.User.Part<Function.Decl.From<fdm>>;
54
57
  }
55
- type Part<fdu extends Function.Declaration = never> = RoleMessage.Part.Text | Tool.Response<fdu>;
56
58
  }
57
- export import Developer = Compatible.RoleMessage.Developer;
59
+ export import Developer = CompatibleRoleMessage.Developer;
58
60
  }
61
+ export {};