@zimtsui/typechat 0.0.61

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 (216) hide show
  1. package/DEVELOPMENT.md +22 -0
  2. package/LICENSE +165 -0
  3. package/README.md +202 -0
  4. package/assets/verbatim/declarations.handlebars +11 -0
  5. package/assets/verbatim/instruction.md +49 -0
  6. package/build/adaptor.d.ts +45 -0
  7. package/build/adaptor.js +90 -0
  8. package/build/adaptor.js.map +1 -0
  9. package/build/api-types/anthropic/billing.d.ts +12 -0
  10. package/build/api-types/anthropic/billing.js +14 -0
  11. package/build/api-types/anthropic/billing.js.map +1 -0
  12. package/build/api-types/anthropic/tool-codec.d.ts +16 -0
  13. package/build/api-types/anthropic/tool-codec.js +58 -0
  14. package/build/api-types/anthropic/tool-codec.js.map +1 -0
  15. package/build/api-types/google/billing.d.ts +12 -0
  16. package/build/api-types/google/billing.js +23 -0
  17. package/build/api-types/google/billing.js.map +1 -0
  18. package/build/api-types/google/restful-request.d.ts +8 -0
  19. package/build/api-types/google/restful-request.js +1 -0
  20. package/build/api-types/google/restful-request.js.map +1 -0
  21. package/build/api-types/google/tool-codec.d.ts +16 -0
  22. package/build/api-types/google/tool-codec.js +80 -0
  23. package/build/api-types/google/tool-codec.js.map +1 -0
  24. package/build/api-types/openai-chatcompletions/billing.d.ts +12 -0
  25. package/build/api-types/openai-chatcompletions/billing.js +14 -0
  26. package/build/api-types/openai-chatcompletions/billing.js.map +1 -0
  27. package/build/api-types/openai-chatcompletions/tool-codec.d.ts +17 -0
  28. package/build/api-types/openai-chatcompletions/tool-codec.js +80 -0
  29. package/build/api-types/openai-chatcompletions/tool-codec.js.map +1 -0
  30. package/build/api-types/openai-responses/billing.d.ts +12 -0
  31. package/build/api-types/openai-responses/billing.js +14 -0
  32. package/build/api-types/openai-responses/billing.js.map +1 -0
  33. package/build/api-types/openai-responses/tool-codec.d.ts +16 -0
  34. package/build/api-types/openai-responses/tool-codec.js +76 -0
  35. package/build/api-types/openai-responses/tool-codec.js.map +1 -0
  36. package/build/assets.d.ts +7 -0
  37. package/build/assets.js +8 -0
  38. package/build/assets.js.map +1 -0
  39. package/build/compatible-engine/session.d.ts +67 -0
  40. package/build/compatible-engine/session.js +92 -0
  41. package/build/compatible-engine/session.js.map +1 -0
  42. package/build/compatible-engine/structuring.d.ts +36 -0
  43. package/build/compatible-engine/structuring.js +34 -0
  44. package/build/compatible-engine/structuring.js.map +1 -0
  45. package/build/compatible-engine/validation.d.ts +21 -0
  46. package/build/compatible-engine/validation.js +82 -0
  47. package/build/compatible-engine/validation.js.map +1 -0
  48. package/build/compatible-engine.d/agentloop.d.ts +12 -0
  49. package/build/compatible-engine.d/agentloop.js +52 -0
  50. package/build/compatible-engine.d/agentloop.js.map +1 -0
  51. package/build/compatible-engine.d/aliyun/transport.d.ts +12 -0
  52. package/build/compatible-engine.d/aliyun/transport.js +7 -0
  53. package/build/compatible-engine.d/aliyun/transport.js.map +1 -0
  54. package/build/compatible-engine.d/aliyun.d.ts +24 -0
  55. package/build/compatible-engine.d/aliyun.js +46 -0
  56. package/build/compatible-engine.d/aliyun.js.map +1 -0
  57. package/build/compatible-engine.d/anthropic/choice-codec.d.ts +5 -0
  58. package/build/compatible-engine.d/anthropic/choice-codec.js +26 -0
  59. package/build/compatible-engine.d/anthropic/choice-codec.js.map +1 -0
  60. package/build/compatible-engine.d/anthropic/message-codec.d.ts +36 -0
  61. package/build/compatible-engine.d/anthropic/message-codec.js +86 -0
  62. package/build/compatible-engine.d/anthropic/message-codec.js.map +1 -0
  63. package/build/compatible-engine.d/anthropic/transport.d.ts +34 -0
  64. package/build/compatible-engine.d/anthropic/transport.js +150 -0
  65. package/build/compatible-engine.d/anthropic/transport.js.map +1 -0
  66. package/build/compatible-engine.d/anthropic.d.ts +26 -0
  67. package/build/compatible-engine.d/anthropic.js +46 -0
  68. package/build/compatible-engine.d/anthropic.js.map +1 -0
  69. package/build/compatible-engine.d/google/choice-codec.d.ts +5 -0
  70. package/build/compatible-engine.d/google/choice-codec.js +27 -0
  71. package/build/compatible-engine.d/google/choice-codec.js.map +1 -0
  72. package/build/compatible-engine.d/google/message-codec.d.ts +36 -0
  73. package/build/compatible-engine.d/google/message-codec.js +94 -0
  74. package/build/compatible-engine.d/google/message-codec.js.map +1 -0
  75. package/build/compatible-engine.d/google/transport.d.ts +30 -0
  76. package/build/compatible-engine.d/google/transport.js +78 -0
  77. package/build/compatible-engine.d/google/transport.js.map +1 -0
  78. package/build/compatible-engine.d/google.d.ts +26 -0
  79. package/build/compatible-engine.d/google.js +50 -0
  80. package/build/compatible-engine.d/google.js.map +1 -0
  81. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.d.ts +5 -0
  82. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js +31 -0
  83. package/build/compatible-engine.d/openai-chatcompletions/choice-codec.js.map +1 -0
  84. package/build/compatible-engine.d/openai-chatcompletions/message-codec.d.ts +24 -0
  85. package/build/compatible-engine.d/openai-chatcompletions/message-codec.js +71 -0
  86. package/build/compatible-engine.d/openai-chatcompletions/message-codec.js.map +1 -0
  87. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.d.ts +38 -0
  88. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.js +77 -0
  89. package/build/compatible-engine.d/openai-chatcompletions/transport.d/monolith.js.map +1 -0
  90. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.d.ts +37 -0
  91. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js +190 -0
  92. package/build/compatible-engine.d/openai-chatcompletions/transport.d/stream.js.map +1 -0
  93. package/build/compatible-engine.d/openai-chatcompletions/transport.d.ts +10 -0
  94. package/build/compatible-engine.d/openai-chatcompletions/transport.js +11 -0
  95. package/build/compatible-engine.d/openai-chatcompletions/transport.js.map +1 -0
  96. package/build/compatible-engine.d/openai-chatcompletions.d.ts +17 -0
  97. package/build/compatible-engine.d/openai-chatcompletions.js +14 -0
  98. package/build/compatible-engine.d/openai-chatcompletions.js.map +1 -0
  99. package/build/compatible-engine.d/openai-responses/choice-codec.d.ts +5 -0
  100. package/build/compatible-engine.d/openai-responses/choice-codec.js +30 -0
  101. package/build/compatible-engine.d/openai-responses/choice-codec.js.map +1 -0
  102. package/build/compatible-engine.d/openai-responses/message-codec.d.ts +36 -0
  103. package/build/compatible-engine.d/openai-responses/message-codec.js +96 -0
  104. package/build/compatible-engine.d/openai-responses/message-codec.js.map +1 -0
  105. package/build/compatible-engine.d/openai-responses/transport.d.ts +35 -0
  106. package/build/compatible-engine.d/openai-responses/transport.js +80 -0
  107. package/build/compatible-engine.d/openai-responses/transport.js.map +1 -0
  108. package/build/compatible-engine.d/openai-responses.d.ts +26 -0
  109. package/build/compatible-engine.d/openai-responses.js +46 -0
  110. package/build/compatible-engine.d/openai-responses.js.map +1 -0
  111. package/build/compatible-engine.d.ts +22 -0
  112. package/build/compatible-engine.js +29 -0
  113. package/build/compatible-engine.js.map +1 -0
  114. package/build/config.d.ts +24 -0
  115. package/build/config.js +11 -0
  116. package/build/config.js.map +1 -0
  117. package/build/endpoint-spec.d.ts +20 -0
  118. package/build/endpoint-spec.js +26 -0
  119. package/build/endpoint-spec.js.map +1 -0
  120. package/build/engine/session.d.ts +7 -0
  121. package/build/engine/session.js +1 -0
  122. package/build/engine/session.js.map +1 -0
  123. package/build/engine/transport.d.ts +5 -0
  124. package/build/engine/transport.js +1 -0
  125. package/build/engine/transport.js.map +1 -0
  126. package/build/engine/validation.d.ts +9 -0
  127. package/build/engine/validation.js +1 -0
  128. package/build/engine/validation.js.map +1 -0
  129. package/build/engine.d.ts +82 -0
  130. package/build/engine.js +104 -0
  131. package/build/engine.js.map +1 -0
  132. package/build/exports.d.ts +14 -0
  133. package/build/exports.js +15 -0
  134. package/build/exports.js.map +1 -0
  135. package/build/function.d.ts +106 -0
  136. package/build/function.js +55 -0
  137. package/build/function.js.map +1 -0
  138. package/build/inference-context.d.ts +6 -0
  139. package/build/inference-context.js +1 -0
  140. package/build/inference-context.js.map +1 -0
  141. package/build/native-engines.d/google/message-codec.d.ts +23 -0
  142. package/build/native-engines.d/google/message-codec.js +67 -0
  143. package/build/native-engines.d/google/message-codec.js.map +1 -0
  144. package/build/native-engines.d/google/session.d.ts +58 -0
  145. package/build/native-engines.d/google/session.js +101 -0
  146. package/build/native-engines.d/google/session.js.map +1 -0
  147. package/build/native-engines.d/google/transport.d.ts +34 -0
  148. package/build/native-engines.d/google/transport.js +81 -0
  149. package/build/native-engines.d/google/transport.js.map +1 -0
  150. package/build/native-engines.d/google/validation.d.ts +22 -0
  151. package/build/native-engines.d/google/validation.js +20 -0
  152. package/build/native-engines.d/google/validation.js.map +1 -0
  153. package/build/native-engines.d/google.d/agentloop.d.ts +12 -0
  154. package/build/native-engines.d/google.d/agentloop.js +57 -0
  155. package/build/native-engines.d/google.d/agentloop.js.map +1 -0
  156. package/build/native-engines.d/google.d/exports.d.ts +2 -0
  157. package/build/native-engines.d/google.d/exports.js +3 -0
  158. package/build/native-engines.d/google.d/exports.js.map +1 -0
  159. package/build/native-engines.d/google.d.ts +42 -0
  160. package/build/native-engines.d/google.js +83 -0
  161. package/build/native-engines.d/google.js.map +1 -0
  162. package/build/native-engines.d/openai-responses/choice-codec.d.ts +5 -0
  163. package/build/native-engines.d/openai-responses/choice-codec.js +30 -0
  164. package/build/native-engines.d/openai-responses/choice-codec.js.map +1 -0
  165. package/build/native-engines.d/openai-responses/message-codec.d.ts +23 -0
  166. package/build/native-engines.d/openai-responses/message-codec.js +75 -0
  167. package/build/native-engines.d/openai-responses/message-codec.js.map +1 -0
  168. package/build/native-engines.d/openai-responses/session.d.ts +61 -0
  169. package/build/native-engines.d/openai-responses/session.js +86 -0
  170. package/build/native-engines.d/openai-responses/session.js.map +1 -0
  171. package/build/native-engines.d/openai-responses/structuring.d.ts +19 -0
  172. package/build/native-engines.d/openai-responses/structuring.js +19 -0
  173. package/build/native-engines.d/openai-responses/structuring.js.map +1 -0
  174. package/build/native-engines.d/openai-responses/tool.d.ts +55 -0
  175. package/build/native-engines.d/openai-responses/tool.js +24 -0
  176. package/build/native-engines.d/openai-responses/tool.js.map +1 -0
  177. package/build/native-engines.d/openai-responses/transport.d.ts +35 -0
  178. package/build/native-engines.d/openai-responses/transport.js +84 -0
  179. package/build/native-engines.d/openai-responses/transport.js.map +1 -0
  180. package/build/native-engines.d/openai-responses/validation.d.ts +20 -0
  181. package/build/native-engines.d/openai-responses/validation.js +80 -0
  182. package/build/native-engines.d/openai-responses/validation.js.map +1 -0
  183. package/build/native-engines.d/openai-responses.d/agentloop.d.ts +12 -0
  184. package/build/native-engines.d/openai-responses.d/agentloop.js +61 -0
  185. package/build/native-engines.d/openai-responses.d/agentloop.js.map +1 -0
  186. package/build/native-engines.d/openai-responses.d/exports.d.ts +2 -0
  187. package/build/native-engines.d/openai-responses.d/exports.js +3 -0
  188. package/build/native-engines.d/openai-responses.d/exports.js.map +1 -0
  189. package/build/native-engines.d/openai-responses.d.ts +44 -0
  190. package/build/native-engines.d/openai-responses.js +78 -0
  191. package/build/native-engines.d/openai-responses.js.map +1 -0
  192. package/build/telemetry.d.ts +6 -0
  193. package/build/telemetry.js +19 -0
  194. package/build/telemetry.js.map +1 -0
  195. package/build/throttle.d.ts +11 -0
  196. package/build/throttle.js +39 -0
  197. package/build/throttle.js.map +1 -0
  198. package/build/tsconfig.tsbuildinfo +1 -0
  199. package/build/verbatim/codec/declarations.d.ts +2 -0
  200. package/build/verbatim/codec/declarations.js +22 -0
  201. package/build/verbatim/codec/declarations.js.map +1 -0
  202. package/build/verbatim/codec/request.d.ts +7 -0
  203. package/build/verbatim/codec/request.js +53 -0
  204. package/build/verbatim/codec/request.js.map +1 -0
  205. package/build/verbatim/codec.d.ts +2 -0
  206. package/build/verbatim/codec.js +3 -0
  207. package/build/verbatim/codec.js.map +1 -0
  208. package/build/verbatim.d.ts +74 -0
  209. package/build/verbatim.js +17 -0
  210. package/build/verbatim.js.map +1 -0
  211. package/examples/agent.ts +65 -0
  212. package/examples/chat.ts +24 -0
  213. package/examples/config.ts +24 -0
  214. package/examples/tsconfig.json +28 -0
  215. package/examples/verbatim.ts +44 -0
  216. package/package.json +50 -0
@@ -0,0 +1,82 @@
1
+ import { Function } from './function.ts';
2
+ import { EndpointSpec } from './endpoint-spec.ts';
3
+ import { Throttle } from './throttle.ts';
4
+ import { ProxyAgent } from 'undici';
5
+ import { type InferenceContext } from './inference-context.ts';
6
+ import * as SessionModule from './engine/session.ts';
7
+ import type { Verbatim } from './verbatim.ts';
8
+ import * as ValidationModule from './engine/validation.ts';
9
+ import * as TransportModule from './engine/transport.ts';
10
+ export interface Pricing {
11
+ inputPrice: number;
12
+ cachePrice: number;
13
+ outputPrice: number;
14
+ }
15
+ export interface ProviderSpec {
16
+ baseUrl: string;
17
+ apiKey: string;
18
+ proxyAgent?: ProxyAgent;
19
+ }
20
+ export interface InferenceParams {
21
+ model: string;
22
+ additionalOptions?: Record<string, unknown>;
23
+ maxTokens?: number;
24
+ timeout?: number;
25
+ }
26
+ export type Engine<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto, userm, aim, devm, session extends Engine.Session<userm, aim, devm>> = Engine.Instance<fdm, vdm, userm, aim, devm, session>;
27
+ export declare namespace Engine {
28
+ abstract class Instance<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto, in out userm, in out aim, in out devm, in out session extends Engine.Session<userm, aim, devm>> {
29
+ protected providerSpec: ProviderSpec;
30
+ protected inferenceParams: InferenceParams;
31
+ name: string;
32
+ pricing: Pricing;
33
+ fdm: fdm;
34
+ vdm: vdm;
35
+ protected throttle: Throttle;
36
+ protected abstract parallelToolCall: boolean;
37
+ protected abstract validator: Engine.Validator.From<fdm, vdm, aim>;
38
+ protected abstract transport: Engine.Transport<userm, aim, devm, session>;
39
+ constructor(options: Engine.Options<fdm, vdm>);
40
+ protected infer(wfctx: InferenceContext, session: session, signal?: AbortSignal): Promise<aim>;
41
+ /**
42
+ * @throws {@link UserAbortion} 用户中止
43
+ * @throws {@link InferenceTimeout} 推理超时
44
+ * @throws {@link ResponseInvalid} 模型抽风
45
+ * @throws {@link NetworkError} 网络故障
46
+ */
47
+ stateless(wfctx: InferenceContext, session: session): Promise<aim>;
48
+ /**
49
+ * @param session mutable
50
+ */
51
+ stateful(wfctx: InferenceContext, session: session): Promise<aim>;
52
+ abstract appendUserMessage(session: session, message: userm): session;
53
+ /**
54
+ * @param session mutable
55
+ */
56
+ abstract pushUserMessage(session: session, message: userm): session;
57
+ }
58
+ interface Options<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> extends EndpointSpec {
59
+ throttle: Throttle;
60
+ functionDeclarationMap: fdm;
61
+ verbatimDeclarationMap: vdm;
62
+ parallelToolCall?: boolean;
63
+ }
64
+ export import Session = SessionModule.Session;
65
+ export import Validator = ValidationModule.Validator;
66
+ export import Transport = TransportModule.Transport;
67
+ }
68
+ export declare class ResponseInvalid extends Error {
69
+ }
70
+ export declare class UserAbortion extends Error {
71
+ }
72
+ export declare class InferenceTimeout extends Error {
73
+ }
74
+ export declare class NetworkError extends Error {
75
+ }
76
+ declare global {
77
+ export namespace NodeJS {
78
+ interface ProcessEnv {
79
+ https_proxy?: string;
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,104 @@
1
+ import { ProxyAgent } from 'undici';
2
+ import { env } from 'node:process';
3
+ import { logger } from "./telemetry.js";
4
+ import * as VerbatimCodec from "./verbatim/codec.js";
5
+ export var Engine;
6
+ (function (Engine) {
7
+ class Instance {
8
+ providerSpec;
9
+ inferenceParams;
10
+ name;
11
+ pricing;
12
+ fdm;
13
+ vdm;
14
+ throttle;
15
+ constructor(options) {
16
+ const proxyUrl = options.proxy || env.https_proxy || env.HTTPS_PROXY;
17
+ this.providerSpec = {
18
+ baseUrl: options.baseUrl,
19
+ apiKey: options.apiKey,
20
+ proxyAgent: proxyUrl ? new ProxyAgent(proxyUrl) : undefined,
21
+ };
22
+ this.name = options.name;
23
+ this.inferenceParams = {
24
+ model: options.model,
25
+ additionalOptions: options.additionalOptions,
26
+ timeout: options.timeout,
27
+ maxTokens: options.maxTokens,
28
+ };
29
+ const inputPrice = options.inputPrice ?? 0;
30
+ this.pricing = {
31
+ inputPrice,
32
+ outputPrice: options.outputPrice ?? 0,
33
+ cachePrice: options.cachePrice ?? inputPrice,
34
+ };
35
+ this.fdm = options.functionDeclarationMap;
36
+ this.vdm = options.verbatimDeclarationMap;
37
+ this.throttle = options.throttle;
38
+ }
39
+ async infer(wfctx, session, signal) {
40
+ try {
41
+ const aiMessage = await this.transport.fetch(wfctx, session, signal);
42
+ this.validator.validateParts(aiMessage);
43
+ this.validator.validateChoice(aiMessage);
44
+ return aiMessage;
45
+ }
46
+ catch (e) {
47
+ if (e instanceof VerbatimCodec.Request.Invalid)
48
+ throw new ResponseInvalid('Invalid verbatim message', { cause: e });
49
+ else
50
+ throw e;
51
+ }
52
+ }
53
+ /**
54
+ * @throws {@link UserAbortion} 用户中止
55
+ * @throws {@link InferenceTimeout} 推理超时
56
+ * @throws {@link ResponseInvalid} 模型抽风
57
+ * @throws {@link NetworkError} 网络故障
58
+ */
59
+ async stateless(wfctx, session) {
60
+ for (let retry = 0;; retry++) {
61
+ const signalTimeout = this.inferenceParams.timeout ? AbortSignal.timeout(this.inferenceParams.timeout) : undefined;
62
+ const signal = wfctx.signal && signalTimeout ? AbortSignal.any([
63
+ wfctx.signal,
64
+ signalTimeout,
65
+ ]) : wfctx.signal || signalTimeout;
66
+ try {
67
+ return await this.infer(wfctx, session, signal);
68
+ }
69
+ catch (e) {
70
+ if (wfctx.signal?.aborted)
71
+ throw new UserAbortion(); // 用户中止
72
+ else if (signalTimeout?.aborted)
73
+ e = new InferenceTimeout(undefined, { cause: e }); // 推理超时
74
+ else if (e instanceof ResponseInvalid) { } // 模型抽风
75
+ else if (e instanceof NetworkError) { } // 网络故障
76
+ else
77
+ throw e;
78
+ if (retry < 3)
79
+ logger.message.warn(e);
80
+ else
81
+ throw e;
82
+ }
83
+ }
84
+ }
85
+ /**
86
+ * @param session mutable
87
+ */
88
+ async stateful(wfctx, session) {
89
+ const response = await this.stateless(wfctx, session);
90
+ session.chatMessages.push(response);
91
+ return response;
92
+ }
93
+ }
94
+ Engine.Instance = Instance;
95
+ })(Engine || (Engine = {}));
96
+ export class ResponseInvalid extends Error {
97
+ }
98
+ export class UserAbortion extends Error {
99
+ }
100
+ export class InferenceTimeout extends Error {
101
+ }
102
+ export class NetworkError extends Error {
103
+ }
104
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AA4BrD,MAAM,KAAW,MAAM,CAoItB;AApID,WAAiB,MAAM;IACnB,MAAsB,QAAQ;QAMhB,YAAY,CAAe;QAC3B,eAAe,CAAkB;QACpC,IAAI,CAAS;QACb,OAAO,CAAU;QACjB,GAAG,CAAM;QACT,GAAG,CAAM;QACN,QAAQ,CAAW;QAK7B,YAAmB,OAAiC;YAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC;YAErE,IAAI,CAAC,YAAY,GAAG;gBAChB,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;aAC9D,CAAC;YAEF,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YACzB,IAAI,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S,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpC,OAAO,QAAQ,CAAC;QACpB,CAAC;KAcJ;IAnHqB,eAAQ,WAmH7B,CAAA;AAgBL,CAAC,EApIgB,MAAM,KAAN,MAAM,QAoItB;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAC7C,MAAM,OAAO,YAAa,SAAQ,KAAK;CAAG;AAC1C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG;AAC9C,MAAM,OAAO,YAAa,SAAQ,KAAK;CAAG"}
@@ -0,0 +1,14 @@
1
+ export * from './adaptor.ts';
2
+ export * from './throttle.ts';
3
+ export * from './compatible-engine/session.ts';
4
+ export * from './compatible-engine.ts';
5
+ export * from './function.ts';
6
+ export * from './verbatim.ts';
7
+ export * from './compatible-engine/structuring.ts';
8
+ export * from './config.ts';
9
+ export * from './inference-context.ts';
10
+ export * from './endpoint-spec.ts';
11
+ export * from './compatible-engine.d/agentloop.ts';
12
+ export * from './engine.ts';
13
+ export * from './compatible-engine.ts';
14
+ export * from './telemetry.ts';
@@ -0,0 +1,15 @@
1
+ export * from "./adaptor.js";
2
+ export * from "./throttle.js";
3
+ export * from "./compatible-engine/session.js";
4
+ export * from "./compatible-engine.js";
5
+ export * from "./function.js";
6
+ export * from "./verbatim.js";
7
+ export * from "./compatible-engine/structuring.js";
8
+ export * from "./config.js";
9
+ export * from "./inference-context.js";
10
+ export * from "./endpoint-spec.js";
11
+ export * from "./compatible-engine.d/agentloop.js";
12
+ export * from "./engine.js";
13
+ export * from "./compatible-engine.js";
14
+ export * from "./telemetry.js";
15
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,106 @@
1
+ import { type Static, type TObject, type TSchema } from '@sinclair/typebox';
2
+ declare const NOMINAL: unique symbol;
3
+ export interface Function<in out fd extends Function.Decl.Proto> {
4
+ (params: Static<fd['parameters']>): Promise<string>;
5
+ }
6
+ export declare namespace Function {
7
+ namespace Name {
8
+ type From<fdm extends Function.Decl.Map.Proto> = globalThis.Extract<keyof fdm, string>;
9
+ }
10
+ type Extract<fdm extends Function.Decl.Map.Proto, nameu extends Function.Name.From<fdm>> = Function.Of<Function.Decl.Extract<fdm, nameu>>;
11
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function<fd> : never;
12
+ interface Decl<in out name extends string, in out params extends Function.Decl.Params.Proto> extends Function.Decl.Body<params> {
13
+ name: name;
14
+ }
15
+ namespace Decl {
16
+ interface Proto extends Function.Decl.Body<Function.Decl.Params.Proto> {
17
+ name: string;
18
+ }
19
+ type Args<params extends Params.Proto> = Static<params>;
20
+ namespace Params {
21
+ type Proto = TObject<Record<string, TSchema>>;
22
+ }
23
+ type Extract<fdm extends Function.Decl.Map.Proto, nameu extends Function.Name.From<fdm>> = nameu extends infer name extends Function.Name.From<fdm> ? Function.Decl<name, fdm[name]['parameters']> : never;
24
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Decl.Extract<fdm, Function.Name.From<fdm>>;
25
+ namespace Map {
26
+ type Proto = Record<string, Body.Prototype>;
27
+ }
28
+ interface Body<in out params extends Function.Decl.Params.Proto> {
29
+ description?: string;
30
+ parameters: params;
31
+ }
32
+ namespace Body {
33
+ interface Prototype {
34
+ description?: string;
35
+ parameters: Function.Decl.Params.Proto;
36
+ }
37
+ }
38
+ type Entry<name extends string, params extends Function.Decl.Params.Proto> = [name, Function.Decl.Body<params>];
39
+ namespace Entry {
40
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Entry<fd['name'], fd['parameters']> : never;
41
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Decl.Entry.Of<Function.Decl.From<fdm>>;
42
+ }
43
+ }
44
+ class Call<in out fd extends Function.Decl.Proto> {
45
+ protected [NOMINAL]: never;
46
+ id?: string;
47
+ name: fd['name'];
48
+ args: Static<fd['parameters']>;
49
+ protected constructor(fc: Omit<Call<fd>, never>);
50
+ static of<fdu extends Function.Decl.Proto>(fc: Function.Call.Options.Of<fdu>): Function.Call.Of<fdu>;
51
+ }
52
+ namespace Call {
53
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Call<fd> : never;
54
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Call.Of<Function.Decl.From<fdm>>;
55
+ type Options<fd extends Function.Decl.Proto> = Omit<Function.Call<fd>, never>;
56
+ namespace Options {
57
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
58
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Call.Options.Of<Function.Decl.From<fdm>>;
59
+ }
60
+ }
61
+ abstract class Response<in out fd extends Function.Decl.Proto> {
62
+ id?: string;
63
+ name: fd['name'];
64
+ protected constructor(fr: Omit<Function.Response<fd>, never>);
65
+ }
66
+ namespace Response {
67
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response<fd> : never;
68
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Of<Function.Decl.From<fdm>>;
69
+ class Successful<in out fd extends Function.Decl.Proto> extends Function.Response<fd> {
70
+ protected [NOMINAL]: never;
71
+ text: string;
72
+ protected constructor(fr: Function.Response.Successful.Options<fd>);
73
+ static of<fdu extends Function.Decl.Proto>(fr: Function.Response.Successful.Options.Of<fdu>): Function.Response.Successful.Of<fdu>;
74
+ }
75
+ namespace Successful {
76
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response.Successful<fd> : never;
77
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Successful.Of<Function.Decl.From<fdm>>;
78
+ type Options<fd extends Function.Decl.Proto> = Omit<Function.Response.Successful<fd>, never>;
79
+ namespace Options {
80
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
81
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Successful.Options.Of<Function.Decl.From<fdm>>;
82
+ }
83
+ }
84
+ class Failed<in out fd extends Function.Decl.Proto> extends Function.Response<fd> {
85
+ protected [NOMINAL]: never;
86
+ error: string;
87
+ protected constructor(fr: Function.Response.Failed.Options<fd>);
88
+ static of<fdu extends Function.Decl.Proto>(fr: Function.Response.Failed.Options.Of<fdu>): Function.Response.Failed.Of<fdu>;
89
+ }
90
+ namespace Failed {
91
+ type Options<fd extends Function.Decl.Proto> = Omit<Function.Response.Failed<fd>, never>;
92
+ namespace Options {
93
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Options<fd> : never;
94
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Failed.Options.Of<Function.Decl.From<fdm>>;
95
+ }
96
+ type Of<fdu extends Function.Decl.Proto> = fdu extends infer fd extends Function.Decl.Proto ? Function.Response.Failed<fd> : never;
97
+ type From<fdm extends Function.Decl.Map.Proto> = Function.Response.Failed.Of<Function.Decl.From<fdm>>;
98
+ }
99
+ }
100
+ type Map<fdm extends Function.Decl.Map.Proto> = {
101
+ [name in Function.Name.From<fdm>]: Function<Function.Decl.Extract<fdm, name>>;
102
+ };
103
+ class Error extends globalThis.Error {
104
+ }
105
+ }
106
+ export {};
@@ -0,0 +1,55 @@
1
+ const NOMINAL = Symbol();
2
+ export var Function;
3
+ (function (Function) {
4
+ class Call {
5
+ id;
6
+ name;
7
+ args;
8
+ constructor(fc) {
9
+ this.id = fc.id;
10
+ this.name = fc.name;
11
+ this.args = fc.args;
12
+ }
13
+ static of(fc) {
14
+ return new Function.Call(fc);
15
+ }
16
+ }
17
+ Function.Call = Call;
18
+ class Response {
19
+ id;
20
+ name;
21
+ constructor(fr) {
22
+ this.id = fr.id;
23
+ this.name = fr.name;
24
+ }
25
+ }
26
+ Function.Response = Response;
27
+ (function (Response) {
28
+ class Successful extends Function.Response {
29
+ text;
30
+ constructor(fr) {
31
+ super(fr);
32
+ this.text = fr.text;
33
+ }
34
+ static of(fr) {
35
+ return new Function.Response.Successful(fr);
36
+ }
37
+ }
38
+ Response.Successful = Successful;
39
+ class Failed extends Function.Response {
40
+ error;
41
+ constructor(fr) {
42
+ super(fr);
43
+ this.error = fr.error;
44
+ }
45
+ static of(fr) {
46
+ return new Function.Response.Failed(fr);
47
+ }
48
+ }
49
+ Response.Failed = Failed;
50
+ })(Response = Function.Response || (Function.Response = {}));
51
+ class Error extends globalThis.Error {
52
+ }
53
+ Function.Error = Error;
54
+ })(Function || (Function = {}));
55
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC;AAMzB,MAAM,KAAW,QAAQ,CA6MxB;AA7MD,WAAiB,QAAQ;IAkFrB,MAAa,IAAI;QAEN,EAAE,CAAU;QACZ,IAAI,CAAa;QACjB,IAAI,CAA2B;QACtC,YAAsB,EAAyB;YAC3C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;YAChB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;YACpB,IAAI,CA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AM,SAAQ,UAAU,CAAC,KAAK;KAAG;IAAjC,cAAK,QAA4B,CAAA;AAClD,CAAC,EA7MgB,QAAQ,KAAR,QAAQ,QA6MxB"}
@@ -0,0 +1,6 @@
1
+ import { RWLock } from '@zimtsui/typelocks';
2
+ export interface InferenceContext {
3
+ busy?: RWLock;
4
+ signal?: AbortSignal;
5
+ cost?(deltaCost: number): void;
6
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=inference-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inference-context.js","sourceRoot":"","sources":["../src/inference-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { RoleMessage, type Session } from './session.ts';
2
+ import { Function } from '../../function.ts';
3
+ import * as Google from '@google/genai';
4
+ import { MessageCodec as CompatibleMessageCodec } from '../../compatible-engine.d/google/message-codec.ts';
5
+ import type { ToolCodec } from '../../api-types/google/tool-codec.ts';
6
+ import { 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
+ encodeAiMessage(aiMessage: RoleMessage.Ai.From<fdm, vdm>): Google.Content;
11
+ encodeUserMessage(userMessage: RoleMessage.User.From<fdm>): Google.Content;
12
+ encodeDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
13
+ encodeChatMessages(chatMessages: Session.ChatMessage.From<fdm, vdm>[]): Google.Content[];
14
+ decodeAiMessage(content: Google.Content): RoleMessage.Ai.From<fdm, vdm>;
15
+ }
16
+ export declare namespace MessageCodec {
17
+ interface Context<in out fdm extends Function.Decl.Map.Proto, in out vdm extends Verbatim.Decl.Map.Proto> {
18
+ toolCodec: ToolCodec<fdm>;
19
+ compatibleMessageCodec: CompatibleMessageCodec<fdm, vdm>;
20
+ codeExecution: boolean;
21
+ vdm: vdm;
22
+ }
23
+ }
@@ -0,0 +1,67 @@
1
+ import { ResponseInvalid } from "../../engine.js";
2
+ import { RoleMessage } from "./session.js";
3
+ import * as VerbatimCodec from "../../verbatim/codec.js";
4
+ export class MessageCodec {
5
+ ctx;
6
+ constructor(ctx) {
7
+ this.ctx = ctx;
8
+ }
9
+ encodeAiMessage(aiMessage) {
10
+ return aiMessage.getRaw();
11
+ }
12
+ encodeUserMessage(userMessage) {
13
+ return this.ctx.compatibleMessageCodec.encodeUserMessage(userMessage);
14
+ }
15
+ encodeDeveloperMessage(developerMessage) {
16
+ return this.ctx.compatibleMessageCodec.encodeDeveloperMessage(developerMessage);
17
+ }
18
+ encodeChatMessages(chatMessages) {
19
+ return chatMessages.map(chatMessage => {
20
+ if (chatMessage instanceof RoleMessage.User)
21
+ return this.encodeUserMessage(chatMessage);
22
+ else if (chatMessage instanceof RoleMessage.Ai)
23
+ return this.encodeAiMessage(chatMessage);
24
+ else
25
+ throw new Error();
26
+ });
27
+ }
28
+ decodeAiMessage(content) {
29
+ if (content.parts) { }
30
+ else
31
+ throw new Error();
32
+ const parts = content.parts.flatMap(part => {
33
+ const parts = [];
34
+ if (part.text) {
35
+ const vrs = VerbatimCodec.Request.decode(part.text, this.ctx.vdm);
36
+ parts.push(new RoleMessage.Part.Text(part.text, vrs));
37
+ }
38
+ if (part.functionCall) {
39
+ parts.push(this.ctx.toolCodec.decodeFunctionCall(part.functionCall));
40
+ }
41
+ if (part.executableCode) {
42
+ if (this.ctx.codeExecution) { }
43
+ else
44
+ throw new ResponseInvalid('Unexpected code execution', { cause: content });
45
+ if (part.executableCode.code) { }
46
+ else
47
+ throw new Error();
48
+ if (part.executableCode.language) { }
49
+ else
50
+ throw new Error();
51
+ parts.push(new RoleMessage.Ai.Part.ExecutableCode(part.executableCode.code, part.executableCode.language));
52
+ }
53
+ if (part.codeExecutionResult) {
54
+ if (this.ctx.codeExecution) { }
55
+ else
56
+ throw new ResponseInvalid('Unexpected code execution result', { cause: content });
57
+ if (part.codeExecutionResult.outcome) { }
58
+ else
59
+ throw new Error();
60
+ parts.push(new RoleMessage.Ai.Part.CodeExecutionResult(part.codeExecutionResult.outcome, part.codeExecutionResult.output));
61
+ }
62
+ return parts;
63
+ });
64
+ return new RoleMessage.Ai(parts, content);
65
+ }
66
+ }
67
+ //# sourceMappingURL=message-codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-codec.js","sourceRoot":"","sources":["../../../src/native-engines.d/google/message-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AAMzD,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAC;AAIzD,MAAM,OAAO,YAAY;IAIQ;IAA7B,YAA6B,GAAmC;QAAnC,QAAG,GAAH,GAAG,CAAgC;IAAG,CAAC;IAG7D,eAAe,CAClB,SAAwC;QAExC,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAEM,iBAAiB,CACpB,WAAuC;QAEvC,OAAO,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC1E,CAAC;IAEM,sBAAsB,CACzB,gBAAuC;QAEvC,OAAO,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IACpF,CAAC;IAEM,kBAAkB,CACrB,YAAkD;QAElD,OAAO,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YAClC,IAAI,WAAW,YAAY,WAAW,CAAC,IAAI;gBAAE,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;iBACnF,IAAI,WAAW,YAAY,WAAW,CAAC,EAAE;gBAAE,OAAO,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;;gBACpF,MAAM,IAAI,KAAK,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;I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Ac,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/G,CAAC;YACD,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC3B,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAA,CAAC;;oBAAM,MAAM,IAAI,eAAe,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;gBACtH,IAAI,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAA,CAAC;;oBAAM,MAAM,IAAI,KAAK,EAAE,CAAC;gBAChE,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;YAC/H,CAAC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACJ"}
@@ -0,0 +1,58 @@
1
+ import { RoleMessage as CompatibleRoleMessage } from '../../compatible-engine/session.ts';
2
+ import { Function } from '../../function.ts';
3
+ import * as Google from '@google/genai';
4
+ import type { Engine } from '../../engine.ts';
5
+ import { Verbatim } from '../../verbatim.ts';
6
+ declare const NOMINAL: unique symbol;
7
+ 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
+ export declare namespace Session {
10
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Session<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
11
+ type ChatMessage<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = Engine.Session.ChatMessage<RoleMessage.User<fdu>, RoleMessage.Ai<fdu, vdu>>;
12
+ namespace ChatMessage {
13
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = ChatMessage<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
14
+ }
15
+ }
16
+ export declare namespace RoleMessage {
17
+ namespace Part {
18
+ export import Text = CompatibleRoleMessage.Part.Text;
19
+ }
20
+ class Ai<in out fdu extends Function.Decl.Proto, in out vdu extends Verbatim.Decl.Proto> {
21
+ protected parts: RoleMessage.Ai.Part<fdu, vdu>[];
22
+ protected raw: Google.Content;
23
+ protected [NOMINAL]: never;
24
+ constructor(parts: RoleMessage.Ai.Part<fdu, vdu>[], raw: Google.Content);
25
+ getParts(): RoleMessage.Ai.Part<fdu, vdu>[];
26
+ getRaw(): Google.Content;
27
+ allChatPart(): boolean;
28
+ getChatParts(): RoleMessage.Ai.Part<fdu, vdu>[];
29
+ static encodeChatPart<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto>(part: RoleMessage.Ai.Part<fdu, vdu>): string;
30
+ getChatText(): string;
31
+ getFunctionCalls(): Function.Call.Of<fdu>[];
32
+ getVerbatimRequests(): Verbatim.Request.Of<vdu>[];
33
+ getOnlyFunctionCall(): Function.Call.Of<fdu>;
34
+ getOnlyVerbatimRequest(): Verbatim.Request.Of<vdu>;
35
+ }
36
+ namespace Ai {
37
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Ai<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
38
+ type Part<fdu extends Function.Decl.Proto, vdu extends Verbatim.Decl.Proto> = RoleMessage.Part.Text<vdu> | Function.Call.Of<fdu> | RoleMessage.Ai.Part.ExecutableCode | RoleMessage.Ai.Part.CodeExecutionResult;
39
+ namespace Part {
40
+ type From<fdm extends Function.Decl.Map.Proto, vdm extends Verbatim.Decl.Map.Proto> = Part<Function.Decl.From<fdm>, Verbatim.Decl.From<vdm>>;
41
+ class ExecutableCode {
42
+ code: string;
43
+ language: string;
44
+ protected [NOMINAL]: never;
45
+ constructor(code: string, language: string);
46
+ }
47
+ class CodeExecutionResult {
48
+ outcome: string;
49
+ output?: string | undefined;
50
+ protected [NOMINAL]: never;
51
+ constructor(outcome: string, output?: string | undefined);
52
+ }
53
+ }
54
+ }
55
+ export import User = CompatibleRoleMessage.User;
56
+ export import Developer = CompatibleRoleMessage.Developer;
57
+ }
58
+ export {};