@zimtsui/brainswitch 0.0.41 → 0.0.43

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 (74) hide show
  1. package/build/agentloop.d.ts +1 -1
  2. package/build/agentloop.js +2 -2
  3. package/build/agentloop.js.map +1 -1
  4. package/build/api-types/anthropic.d.ts +18 -22
  5. package/build/api-types/anthropic.js +81 -79
  6. package/build/api-types/anthropic.js.map +1 -1
  7. package/build/api-types/google.d.ts +13 -18
  8. package/build/api-types/google.js +23 -31
  9. package/build/api-types/google.js.map +1 -1
  10. package/build/api-types/openai-chat-completions.d.ts +17 -19
  11. package/build/api-types/openai-chat-completions.js +101 -96
  12. package/build/api-types/openai-chat-completions.js.map +1 -1
  13. package/build/api-types/openai-responses.d.ts +13 -13
  14. package/build/api-types/openai-responses.js +59 -56
  15. package/build/api-types/openai-responses.js.map +1 -1
  16. package/build/compatible-engine.d.ts +19 -24
  17. package/build/compatible-engine.js +55 -56
  18. package/build/compatible-engine.js.map +1 -1
  19. package/build/compatible-engines.d/aliyun.d.ts +36 -55
  20. package/build/compatible-engines.d/aliyun.js +88 -143
  21. package/build/compatible-engines.d/aliyun.js.map +1 -1
  22. package/build/compatible-engines.d/anthropic.d.ts +33 -60
  23. package/build/compatible-engines.d/anthropic.js +228 -296
  24. package/build/compatible-engines.d/anthropic.js.map +1 -1
  25. package/build/compatible-engines.d/google.d.ts +36 -59
  26. package/build/compatible-engines.d/google.js +163 -237
  27. package/build/compatible-engines.d/google.js.map +1 -1
  28. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +7 -14
  29. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +65 -71
  30. package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +1 -1
  31. package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +10 -16
  32. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js +170 -184
  33. package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +1 -1
  34. package/build/compatible-engines.d/openai-chatcompletions.d.ts +12 -18
  35. package/build/compatible-engines.d/openai-chatcompletions.js +64 -67
  36. package/build/compatible-engines.d/openai-chatcompletions.js.map +1 -1
  37. package/build/compatible-engines.d/openai-responses.d.ts +44 -68
  38. package/build/compatible-engines.d/openai-responses.js +216 -281
  39. package/build/compatible-engines.d/openai-responses.js.map +1 -1
  40. package/build/engine.d.ts +7 -24
  41. package/build/engine.js +23 -38
  42. package/build/engine.js.map +1 -1
  43. package/build/exports.d.ts +1 -0
  44. package/build/exports.js +1 -0
  45. package/build/exports.js.map +1 -1
  46. package/build/inference-context.d.ts +1 -10
  47. package/build/inference-context.js +0 -2
  48. package/build/inference-context.js.map +1 -1
  49. package/build/native-engines.d/google/agentloop.d.ts +1 -1
  50. package/build/native-engines.d/google/agentloop.js +2 -2
  51. package/build/native-engines.d/google/agentloop.js.map +1 -1
  52. package/build/native-engines.d/google/engine.d.ts +54 -73
  53. package/build/native-engines.d/google/engine.js +260 -309
  54. package/build/native-engines.d/google/engine.js.map +1 -1
  55. package/build/native-engines.d/google/exports.d.ts +3 -2
  56. package/build/native-engines.d/google/exports.js +3 -2
  57. package/build/native-engines.d/google/exports.js.map +1 -1
  58. package/build/native-engines.d/openai-responses/agentloop.d.ts +1 -1
  59. package/build/native-engines.d/openai-responses/agentloop.js +2 -2
  60. package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
  61. package/build/native-engines.d/openai-responses/engine.d.ts +57 -78
  62. package/build/native-engines.d/openai-responses/engine.js +279 -334
  63. package/build/native-engines.d/openai-responses/engine.js.map +1 -1
  64. package/build/native-engines.d/openai-responses/exports.d.ts +4 -2
  65. package/build/native-engines.d/openai-responses/exports.js +4 -2
  66. package/build/native-engines.d/openai-responses/exports.js.map +1 -1
  67. package/build/telemetry.d.ts +6 -0
  68. package/build/telemetry.js +18 -0
  69. package/build/telemetry.js.map +1 -0
  70. package/build/throttle.d.ts +1 -1
  71. package/build/throttle.js +6 -6
  72. package/build/throttle.js.map +1 -1
  73. package/build/tsconfig.tsbuildinfo +1 -1
  74. package/package.json +2 -2
package/build/engine.d.ts CHANGED
@@ -15,14 +15,14 @@ export declare namespace Engine {
15
15
  parallelToolCall?: boolean;
16
16
  }
17
17
  }
18
- interface Base<in out fdm extends Function.Declaration.Map> {
18
+ interface OwnProps<in out fdm extends Function.Declaration.Map> {
19
19
  baseUrl: string;
20
20
  apiKey: string;
21
21
  model: string;
22
22
  name: string;
23
23
  inputPrice: number;
24
24
  outputPrice: number;
25
- cachedPrice: number;
25
+ cachePrice: number;
26
26
  fdm: fdm;
27
27
  additionalOptions?: Record<string, unknown>;
28
28
  throttle: Throttle;
@@ -30,33 +30,16 @@ export declare namespace Engine {
30
30
  maxTokens?: number;
31
31
  proxyAgent?: ProxyAgent;
32
32
  }
33
- interface Instance<in out fdm extends Function.Declaration.Map> extends Engine.Base<fdm>, Engine {
34
- parallel: boolean;
33
+ namespace OwnProps {
34
+ function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps<fdm>;
35
35
  }
36
- namespace Base {
37
- class Instance<in out fdm extends Function.Declaration.Map> implements Engine.Base<fdm> {
38
- instance: Engine.Instance<fdm>;
39
- baseUrl: string;
40
- apiKey: string;
41
- model: string;
42
- name: string;
43
- inputPrice: number;
44
- outputPrice: number;
45
- cachedPrice: number;
46
- fdm: fdm;
47
- additionalOptions?: Record<string, unknown>;
48
- throttle: Throttle;
49
- timeout?: number;
50
- maxTokens?: number;
51
- proxyAgent?: ProxyAgent;
52
- constructor(instance: Engine.Instance<fdm>, options: Engine.Options<fdm>);
53
- }
36
+ interface Underhood<in out fdm extends Function.Declaration.Map> extends Engine, OwnProps<fdm> {
37
+ parallelToolCall: boolean;
54
38
  }
55
39
  }
56
40
  export declare class ResponseInvalid extends Error {
57
41
  }
58
- export declare class UserAbortion extends Error {
59
- }
42
+ export declare const USER_ABORTION: unique symbol;
60
43
  export declare class InferenceTimeout extends Error {
61
44
  }
62
45
  declare global {
package/build/engine.js CHANGED
@@ -5,48 +5,33 @@ import { ProxyAgent } from 'undici';
5
5
  import { env } from 'node:process';
6
6
  export var Engine;
7
7
  (function (Engine) {
8
- let Base;
9
- (function (Base) {
10
- class Instance {
11
- instance;
12
- baseUrl;
13
- apiKey;
14
- model;
15
- name;
16
- inputPrice;
17
- outputPrice;
18
- cachedPrice;
19
- fdm;
20
- additionalOptions;
21
- throttle;
22
- timeout;
23
- maxTokens;
24
- proxyAgent;
25
- constructor(instance, options) {
26
- this.instance = instance;
27
- this.baseUrl = options.baseUrl;
28
- this.apiKey = options.apiKey;
29
- this.model = options.model;
30
- this.name = options.name;
31
- this.inputPrice = options.inputPrice ?? 0;
32
- this.outputPrice = options.outputPrice ?? 0;
33
- this.cachedPrice = options.cachePrice ?? this.inputPrice;
34
- this.fdm = options.functionDeclarationMap;
35
- this.additionalOptions = options.additionalOptions;
36
- this.throttle = options.throttle;
37
- this.timeout = options.timeout;
38
- this.maxTokens = options.maxTokens;
39
- const proxyUrl = env.https_proxy || env.HTTPS_PROXY;
40
- this.proxyAgent = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
41
- }
8
+ let OwnProps;
9
+ (function (OwnProps) {
10
+ function init(options) {
11
+ const proxyUrl = env.https_proxy || env.HTTPS_PROXY;
12
+ const inputPrice = options.inputPrice ?? 0;
13
+ return {
14
+ baseUrl: options.baseUrl,
15
+ apiKey: options.apiKey,
16
+ model: options.model,
17
+ name: options.name,
18
+ inputPrice,
19
+ outputPrice: options.outputPrice ?? 0,
20
+ cachePrice: options.cachePrice ?? inputPrice,
21
+ fdm: options.functionDeclarationMap,
22
+ additionalOptions: options.additionalOptions,
23
+ throttle: options.throttle,
24
+ timeout: options.timeout,
25
+ maxTokens: options.maxTokens,
26
+ proxyAgent: proxyUrl ? new ProxyAgent(proxyUrl) : undefined,
27
+ };
42
28
  }
43
- Base.Instance = Instance;
44
- })(Base = Engine.Base || (Engine.Base = {}));
29
+ OwnProps.init = init;
30
+ })(OwnProps = Engine.OwnProps || (Engine.OwnProps = {}));
45
31
  })(Engine || (Engine = {}));
46
32
  export class ResponseInvalid extends Error {
47
33
  }
48
- export class UserAbortion extends Error {
49
- }
34
+ export const USER_ABORTION = Symbol();
50
35
  export class InferenceTimeout extends Error {
51
36
  }
52
37
  //# sourceMappingURL=engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAQnC,MAAM,KAAW,MAAM,CAwEtB;AAxED,WAAiB,MAAM;IAkCnB,IAAiB,IAAI,CAqCpB;IArCD,WAAiB,IAAI;QACjB,MAAa,QAAQ;YAiBN;YAhBJ,OAAO,CAAS;YAChB,MAAM,CAAS;YACf,KAAK,CAAS;YACd,IAAI,CAAS;YACb,UAAU,CAAS;YACnB,WAAW,CAAS;YACpB,WAAW,CAAS;YACpB,GAAG,CAAM;YACT,iBAAiB,CAA2B;YAC5C,QAAQ,CAAW;YACnB,OAAO,CAAU;YACjB,SAAS,CAAU;YAEnB,UAAU,CAAc;YAE/B,YACW,QAA8B,EACrC,OAA4B;gBADrB,aAAQ,GAAR,QAAQ,CAAsB;gBAGrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;gBAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;gBAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;gBAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;gBACzB,IAAI,CAAC,UAAU,GAAG,OA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.ts';
11
11
  export * from './compatible-engine.ts';
12
12
  export * from './frontmatter.ts';
13
+ export * from './telemetry.ts';
package/build/exports.js CHANGED
@@ -10,4 +10,5 @@ export * from "./agentloop.js";
10
10
  export * from "./engine.js";
11
11
  export * from "./compatible-engine.js";
12
12
  export * from "./frontmatter.js";
13
+ export * from "./telemetry.js";
13
14
  //# sourceMappingURL=exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -1,15 +1,6 @@
1
1
  import { RWLock } from '@zimtsui/coroutine-locks';
2
- import { type Channel } from '@zimtsui/typelog';
3
- import * as Presets from '@zimtsui/typelog/presets';
4
2
  export interface InferenceContext {
5
3
  busy?: RWLock;
6
- logger: InferenceContext.Logger;
7
4
  signal?: AbortSignal;
8
- }
9
- export declare namespace InferenceContext {
10
- interface Logger {
11
- inference?: Channel<typeof Presets.Level, string>;
12
- message?: Channel<typeof Presets.Level, unknown>;
13
- cost?(deltaCost: number): void;
14
- }
5
+ cost?(deltaCost: number): void;
15
6
  }
@@ -1,4 +1,2 @@
1
1
  import { RWLock } from '@zimtsui/coroutine-locks';
2
- import {} from '@zimtsui/typelog';
3
- import * as Presets from '@zimtsui/typelog/presets';
4
2
  //# sourceMappingURL=inference-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inference-context.js","sourceRoot":"","sources":["../src/inference-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"inference-context.js","sourceRoot":"","sources":["../src/inference-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC"}
@@ -6,7 +6,7 @@ import * as CompatibleAgentloopModule from '../../agentloop.ts';
6
6
  /**
7
7
  * @param session mutable
8
8
  */
9
- export declare function agentloop<fdm extends Function.Declaration.Map>(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, engine: GoogleNativeEngine<fdm>, fnm: Function.Map<fdm>, limit?: number): AsyncGenerator<string, string, void>;
9
+ export declare function agentloop<fdm extends Function.Declaration.Map>(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, engine: GoogleNativeEngine<fdm>, fnm: Function.Map<fdm>, limit?: number): AsyncGenerator<string, string, void>;
10
10
  export declare namespace agentloop {
11
11
  export import FunctionCallLimitExceeded = CompatibleAgentloopModule.agentloop.FunctionCallLimitExceeded;
12
12
  }
@@ -6,9 +6,9 @@ import * as CompatibleAgentloopModule from "../../agentloop.js";
6
6
  /**
7
7
  * @param session mutable
8
8
  */
9
- export async function* agentloop(ctx, session, engine, fnm, limit = Number.POSITIVE_INFINITY) {
9
+ export async function* agentloop(wfctx, session, engine, fnm, limit = Number.POSITIVE_INFINITY) {
10
10
  for (let i = 0; i < limit; i++) {
11
- const response = await engine.stateful(ctx, session);
11
+ const response = await engine.stateful(wfctx, session);
12
12
  const fcs = response.getFunctionCalls();
13
13
  if (!fcs.length)
14
14
  return response.getOnlyText();
@@ -1 +1 @@
1
- {"version":3,"file":"agentloop.js","sourceRoot":"","sources":["../../../src/native-engines.d/google/agentloop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAA2B,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,yBAAyB,MAAM,oBAAoB,CAAC;AAGhE;;GAEG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAA,SAAS,CAC5B,GAAqB,EACrB,OAAgD,EAChD,MAA+B,EAC/B,GAAsB,EACtB,KAAK,GAAG,MAAM,CAAC,iBAAiB;IAGhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACrD,MAAM,GAAG,GAAG,QAAQ,CAAC,gBAAgB,EAAE,CAAC;QACxC,IAAI,CAAC,GAAG,CAAC,MAAM;YAAE,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAmD,EAAE,CAAC;QAChE,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrC,IAAI,IAAI,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACjD,MAAM,IAAI,CAAC,IAAI,CAAC;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AM,IAAI,KAAK,EAAE,CAAC;QAC7B,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAM,GAAG,CAAC,CAAC,CAAC;IACvE,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"}
@@ -3,20 +3,22 @@ import { RoleMessage, type ChatMessage, type Session } from './session.ts';
3
3
  import { Engine } from '../../engine.ts';
4
4
  import { type InferenceContext } from '../../inference-context.ts';
5
5
  import * as Google from '@google/genai';
6
+ import * as Undici from 'undici';
6
7
  import { GoogleEngine } from '../../api-types/google.ts';
7
8
  import { CompatibleEngine } from '../../compatible-engine.ts';
9
+ import { Throttle } from '../../throttle.ts';
8
10
  export interface GoogleNativeEngine<fdm extends Function.Declaration.Map> extends Engine {
9
11
  /**
10
- * @throws {@link UserAbortion} 用户中止
12
+ * @throws {@link USER_ABORTION} 用户中止
11
13
  * @throws {@link InferenceTimeout} 推理超时
12
14
  * @throws {@link ResponseInvalid} 模型抽风
13
15
  * @throws {TypeError} 网络故障
14
16
  */
15
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
17
+ stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
16
18
  /**
17
19
  * @param session mutable
18
20
  */
19
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
21
+ stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
20
22
  appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
21
23
  /**
22
24
  * @param session mutable
@@ -24,19 +26,26 @@ export interface GoogleNativeEngine<fdm extends Function.Declaration.Map> extend
24
26
  pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
25
27
  }
26
28
  export declare namespace GoogleNativeEngine {
27
- interface Options<fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, CompatibleEngine.Options<fdm> {
29
+ interface Options<in out fdm extends Function.Declaration.Map> extends Engine.Options<fdm>, CompatibleEngine.Options.Tools<fdm>, GoogleEngine.Options<fdm> {
28
30
  codeExecution?: boolean;
29
31
  urlContext?: boolean;
30
32
  googleSearch?: boolean;
31
33
  }
32
- interface Base<fdm extends Function.Declaration.Map> {
33
- toolChoice: Function.ToolChoice<fdm>;
34
+ interface OwnProps<in out fdm extends Function.Declaration.Map> {
35
+ apiURL: URL;
34
36
  codeExecution: boolean;
35
37
  urlContext: boolean;
36
38
  googleSearch: boolean;
37
- parallel: boolean;
38
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
39
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
39
+ toolChoice: Function.ToolChoice<fdm>;
40
+ }
41
+ interface ParentUnderhood<in out fdm extends Function.Declaration.Map> extends Engine.Underhood<fdm>, GoogleEngine.Underhood<fdm> {
42
+ }
43
+ namespace OwnProps {
44
+ function init<fdm extends Function.Declaration.Map>(this: ParentUnderhood<fdm>, options: Options<fdm>): OwnProps<fdm>;
45
+ }
46
+ interface Underhood<in out fdm extends Function.Declaration.Map> extends ParentUnderhood<fdm>, GoogleNativeEngine<fdm>, OwnProps<fdm> {
47
+ stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
48
+ stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
40
49
  convertFromUserMessage(userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
41
50
  convertFromAiMessage(aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
42
51
  convertFromDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
@@ -45,75 +54,47 @@ export declare namespace GoogleNativeEngine {
45
54
  convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
46
55
  appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
47
56
  pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
48
- fetch(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
57
+ fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
49
58
  validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
50
59
  }
51
- interface Instance<fdm extends Function.Declaration.Map> extends GoogleEngine.Instance<fdm>, GoogleNativeEngine.Base<fdm>, GoogleNativeEngine<fdm> {
52
- }
53
- namespace Base {
54
- class Instance<in out fdm extends Function.Declaration.Map> implements GoogleNativeEngine.Base<fdm> {
55
- protected instance: GoogleNativeEngine.Instance<fdm>;
56
- protected apiURL: URL;
57
- parallel: boolean;
58
- codeExecution: boolean;
59
- urlContext: boolean;
60
- googleSearch: boolean;
61
- toolChoice: Function.ToolChoice<fdm>;
62
- constructor(instance: GoogleNativeEngine.Instance<fdm>, options: GoogleNativeEngine.Options<fdm>);
63
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
64
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
65
- appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
66
- pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
67
- convertToAiMessage(content: Google.Content): RoleMessage.Ai<Function.Declaration.From<fdm>>;
68
- convertFromAiMessage(aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
69
- convertFromUserMessage(userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
70
- convertFromDeveloperMessage(developerMessage: RoleMessage.Developer): Google.Content;
71
- convertFromChatMessages(chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
72
- convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
73
- fetch(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
74
- validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
75
- }
76
- }
77
- class Instance<in out fdm extends Function.Declaration.Map> implements GoogleNativeEngine.Instance<fdm> {
78
- protected engineBase: Engine.Base<fdm>;
79
- protected googleEngineBase: GoogleEngine.Base<fdm>;
80
- protected googleNativeEngineBase: GoogleNativeEngine.Base<fdm>;
60
+ function stateless<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
61
+ function stateful<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
62
+ function appendUserMessage<fdm extends Function.Declaration.Map>(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
63
+ function pushUserMessage<fdm extends Function.Declaration.Map>(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm>>;
64
+ function convertToAiMessage<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, content: Google.Content): RoleMessage.Ai<Function.Declaration.From<fdm>>;
65
+ function convertFromAiMessage<fdm extends Function.Declaration.Map>(aiMessage: RoleMessage.Ai<Function.Declaration.From<fdm>>): Google.Content;
66
+ function convertFromUserMessage<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, userMessage: RoleMessage.User<Function.Declaration.From<fdm>>): Google.Content;
67
+ function convertFromDeveloperMessage<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, developerMessage: RoleMessage.Developer): Google.Content;
68
+ function convertFromChatMessages<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
69
+ function convertFromToolChoice<fdm extends Function.Declaration.Map>(this: Engine.Underhood<fdm>, toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
70
+ function fetch<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
71
+ function validateToolCallsByToolChoice<fdm extends Function.Declaration.Map>(this: GoogleNativeEngine.Underhood<fdm>, toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
72
+ class Instance<in out fdm extends Function.Declaration.Map> implements GoogleNativeEngine.Underhood<fdm> {
73
+ baseUrl: string;
74
+ apiKey: string;
75
+ model: string;
76
+ name: string;
77
+ inputPrice: number;
78
+ outputPrice: number;
79
+ cachePrice: number;
80
+ fdm: fdm;
81
+ additionalOptions?: Record<string, unknown>;
82
+ throttle: Throttle;
83
+ timeout?: number;
84
+ maxTokens?: number;
85
+ proxyAgent?: Undici.ProxyAgent;
86
+ parallelToolCall: boolean;
87
+ apiURL: URL;
88
+ codeExecution: boolean;
89
+ urlContext: boolean;
90
+ googleSearch: boolean;
91
+ toolChoice: Function.ToolChoice<fdm>;
81
92
  constructor(options: GoogleNativeEngine.Options<fdm>);
82
- get baseUrl(): string;
83
- set baseUrl(value: string);
84
- get apiKey(): string;
85
- set apiKey(value: string);
86
- get model(): string;
87
- set model(value: string);
88
- get name(): string;
89
- set name(value: string);
90
- get inputPrice(): number;
91
- set inputPrice(value: number);
92
- get outputPrice(): number;
93
- set outputPrice(value: number);
94
- get cachedPrice(): number;
95
- set cachedPrice(value: number);
96
- get fdm(): fdm;
97
- set fdm(value: fdm);
98
- get additionalOptions(): Record<string, unknown> | undefined;
99
- set additionalOptions(value: Record<string, unknown> | undefined);
100
- get throttle(): import("../../throttle.ts").Throttle;
101
- set throttle(value: import("../../throttle.ts").Throttle);
102
- get timeout(): number | undefined;
103
- set timeout(value: number | undefined);
104
- get maxTokens(): number | undefined;
105
- set maxTokens(value: number | undefined);
106
- get proxyAgent(): import("undici").ProxyAgent | undefined;
107
- set proxyAgent(value: import("undici").ProxyAgent | undefined);
108
- get toolChoice(): Function.ToolChoice<fdm>;
109
- set toolChoice(value: Function.ToolChoice<fdm>);
110
- stateless(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
111
- stateful(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
93
+ stateless(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
94
+ stateful(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>): Promise<RoleMessage.Ai<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>>;
112
95
  appendUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>;
113
96
  pushUserMessage(session: Session<Function.Declaration.From<fdm>>, message: RoleMessage.User<Function.Declaration.From<fdm>>): Session<Function.Declaration.From<fdm, Extract<keyof fdm, string>>>;
114
97
  validateToolCallsByToolChoice(toolCalls: Function.Call.Distributive<Function.Declaration.From<fdm>>[]): void;
115
- get parallel(): boolean;
116
- set parallel(value: boolean);
117
98
  convertFromFunctionCall(fc: Function.Call.Distributive<Function.Declaration.From<fdm>>): Google.FunctionCall;
118
99
  convertToFunctionCall(googlefc: Google.FunctionCall): Function.Call.Distributive<Function.Declaration.From<fdm>>;
119
100
  convertFromFunctionDeclarationEntry(fdentry: Function.Declaration.Entry.From<fdm>): Google.FunctionDeclaration;
@@ -123,7 +104,7 @@ export declare namespace GoogleNativeEngine {
123
104
  convertFromChatMessages(chatMessages: ChatMessage<Function.Declaration.From<fdm>>[]): Google.Content[];
124
105
  convertToAiMessage(content: Google.Content): RoleMessage.Ai<Function.Declaration.From<fdm>>;
125
106
  convertFromToolChoice(toolChoice: Function.ToolChoice<fdm>): Google.FunctionCallingConfig;
126
- fetch(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
107
+ fetch(wfctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, signal?: AbortSignal): Promise<RoleMessage.Ai<Function.Declaration.From<fdm>>>;
127
108
  }
128
109
  function create<fdm extends Function.Declaration.Map>(options: GoogleNativeEngine.Options<fdm>): GoogleNativeEngine<fdm>;
129
110
  }