@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.
- package/build/agentloop.d.ts +1 -1
- package/build/agentloop.js +2 -2
- package/build/agentloop.js.map +1 -1
- package/build/api-types/anthropic.d.ts +18 -22
- package/build/api-types/anthropic.js +81 -79
- package/build/api-types/anthropic.js.map +1 -1
- package/build/api-types/google.d.ts +13 -18
- package/build/api-types/google.js +23 -31
- package/build/api-types/google.js.map +1 -1
- package/build/api-types/openai-chat-completions.d.ts +17 -19
- package/build/api-types/openai-chat-completions.js +101 -96
- package/build/api-types/openai-chat-completions.js.map +1 -1
- package/build/api-types/openai-responses.d.ts +13 -13
- package/build/api-types/openai-responses.js +59 -56
- package/build/api-types/openai-responses.js.map +1 -1
- package/build/compatible-engine.d.ts +19 -24
- package/build/compatible-engine.js +55 -56
- package/build/compatible-engine.js.map +1 -1
- package/build/compatible-engines.d/aliyun.d.ts +36 -55
- package/build/compatible-engines.d/aliyun.js +88 -143
- package/build/compatible-engines.d/aliyun.js.map +1 -1
- package/build/compatible-engines.d/anthropic.d.ts +33 -60
- package/build/compatible-engines.d/anthropic.js +228 -296
- package/build/compatible-engines.d/anthropic.js.map +1 -1
- package/build/compatible-engines.d/google.d.ts +36 -59
- package/build/compatible-engines.d/google.js +163 -237
- package/build/compatible-engines.d/google.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.d.ts +7 -14
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js +65 -71
- package/build/compatible-engines.d/openai-chatcompletions.d/monolith.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.d.ts +10 -16
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js +170 -184
- package/build/compatible-engines.d/openai-chatcompletions.d/stream.js.map +1 -1
- package/build/compatible-engines.d/openai-chatcompletions.d.ts +12 -18
- package/build/compatible-engines.d/openai-chatcompletions.js +64 -67
- package/build/compatible-engines.d/openai-chatcompletions.js.map +1 -1
- package/build/compatible-engines.d/openai-responses.d.ts +44 -68
- package/build/compatible-engines.d/openai-responses.js +216 -281
- package/build/compatible-engines.d/openai-responses.js.map +1 -1
- package/build/engine.d.ts +7 -24
- package/build/engine.js +23 -38
- package/build/engine.js.map +1 -1
- package/build/exports.d.ts +1 -0
- package/build/exports.js +1 -0
- package/build/exports.js.map +1 -1
- package/build/inference-context.d.ts +1 -10
- package/build/inference-context.js +0 -2
- package/build/inference-context.js.map +1 -1
- package/build/native-engines.d/google/agentloop.d.ts +1 -1
- package/build/native-engines.d/google/agentloop.js +2 -2
- package/build/native-engines.d/google/agentloop.js.map +1 -1
- package/build/native-engines.d/google/engine.d.ts +54 -73
- package/build/native-engines.d/google/engine.js +260 -309
- package/build/native-engines.d/google/engine.js.map +1 -1
- package/build/native-engines.d/google/exports.d.ts +3 -2
- package/build/native-engines.d/google/exports.js +3 -2
- package/build/native-engines.d/google/exports.js.map +1 -1
- package/build/native-engines.d/openai-responses/agentloop.d.ts +1 -1
- package/build/native-engines.d/openai-responses/agentloop.js +2 -2
- package/build/native-engines.d/openai-responses/agentloop.js.map +1 -1
- package/build/native-engines.d/openai-responses/engine.d.ts +57 -78
- package/build/native-engines.d/openai-responses/engine.js +279 -334
- package/build/native-engines.d/openai-responses/engine.js.map +1 -1
- package/build/native-engines.d/openai-responses/exports.d.ts +4 -2
- package/build/native-engines.d/openai-responses/exports.js +4 -2
- package/build/native-engines.d/openai-responses/exports.js.map +1 -1
- package/build/telemetry.d.ts +6 -0
- package/build/telemetry.js +18 -0
- package/build/telemetry.js.map +1 -0
- package/build/throttle.d.ts +1 -1
- package/build/throttle.js +6 -6
- package/build/throttle.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- 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
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
|
|
33
|
+
namespace OwnProps {
|
|
34
|
+
function init<fdm extends Function.Declaration.Map>(options: Options<fdm>): OwnProps<fdm>;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
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
|
|
9
|
-
(function (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
44
|
-
})(
|
|
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
|
|
49
|
-
}
|
|
34
|
+
export const USER_ABORTION = Symbol();
|
|
50
35
|
export class InferenceTimeout extends Error {
|
|
51
36
|
}
|
|
52
37
|
//# sourceMappingURL=engine.js.map
|
package/build/engine.js.map
CHANGED
|
@@ -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;
|
|
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;AAOnC,MAAM,KAAW,MAAM,CAsDtB;AAtDD,WAAiB,MAAM;IA0BnB,IAAiB,QAAQ,CAoBxB;IApBD,WAAiB,QAAQ;QACrB,SAAgB,IAAI,CAAuC,OAAqB;YAC5E,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,WAAW,CAAC;YACpD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;YAC3C,OAAO;gBACH,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,UAAU;gBACV,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC;gBACrC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,UAAU;gBAC5C,GAAG,EAAE,OAAO,CAAC,sBAAsB;gBACnC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;gBAC5C,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;aAC9D,CAAC;QACN,CAAC;QAlBe,aAAI,OAkBnB,CAAA;IACL,CAAC,EApBgB,QAAQ,GAAR,eAAQ,KAAR,eAAQ,QAoBxB;AAQL,CAAC,EAtDgB,MAAM,KAAN,MAAM,QAsDtB;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAC7C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AACtC,MAAM,OAAO,gBAAiB,SAAQ,KAAK;CAAG"}
|
package/build/exports.d.ts
CHANGED
package/build/exports.js
CHANGED
package/build/exports.js.map
CHANGED
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference-context.js","sourceRoot":"","sources":["../src/inference-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,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>(
|
|
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(
|
|
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(
|
|
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,
|
|
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,KAAuB,EACvB,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,KAAK,EAAE,OAAO,CAAC,CAAC;QACvD,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;YACpB,CAAC;iBAAM,IAAI,IAAI,YAAY,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACvC,MAAM,EAAE,GAAG,IAAuC,CAAC;gBACnD,MAAM,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBACvB,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;oBAClB,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAM;wBACjC,EAAE,EAAE,EAAE,CAAC,EAAE;wBACT,IAAI,EAAE,EAAE,CAAC,IAAI;wBACb,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC;qBACM,CAAC,CAAC;gBAChD,CAAC,CAAC,EAAE,CAAC,CAAC;YACV,CAAC;;gBAAM,MAAM,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
|
|
12
|
+
* @throws {@link USER_ABORTION} 用户中止
|
|
11
13
|
* @throws {@link InferenceTimeout} 推理超时
|
|
12
14
|
* @throws {@link ResponseInvalid} 模型抽风
|
|
13
15
|
* @throws {TypeError} 网络故障
|
|
14
16
|
*/
|
|
15
|
-
stateless(
|
|
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(
|
|
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
|
|
33
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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(
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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(
|
|
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
|
}
|