@zimtsui/brainswitch 0.0.3 → 0.0.4
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/README.md +9 -9
- package/build/adaptor.js +0 -3
- package/build/adaptor.js.map +1 -1
- package/build/api-types/base.d.ts +3 -0
- package/build/api-types/base.js +5 -0
- package/build/api-types/base.js.map +1 -1
- package/build/api-types/google-rest.d.ts +0 -1
- package/build/api-types/google-rest.js +5 -4
- package/build/api-types/google-rest.js.map +1 -1
- package/build/api-types/openai-chatcompletions-base.d.ts +0 -3
- package/build/api-types/openai-chatcompletions-base.js +0 -10
- package/build/api-types/openai-chatcompletions-base.js.map +1 -1
- package/build/api-types/openai-chatcompletions-monolith-base.d.ts +3 -0
- package/build/api-types/openai-chatcompletions-monolith-base.js +21 -2
- package/build/api-types/openai-chatcompletions-monolith-base.js.map +1 -1
- package/build/api-types/openai-chatcompletions-stream-base.d.ts +3 -0
- package/build/api-types/openai-chatcompletions-stream-base.js +14 -0
- package/build/api-types/openai-chatcompletions-stream-base.js.map +1 -1
- package/build/api-types/openai-responses.d.ts +1 -3
- package/build/api-types/openai-responses.js +17 -13
- package/build/api-types/openai-responses.js.map +1 -1
- package/build/api-types/openrouter-monolith.js +1 -0
- package/build/api-types/openrouter-monolith.js.map +1 -1
- package/build/api-types/openrouter-stream.js +1 -0
- package/build/api-types/openrouter-stream.js.map +1 -1
- package/build/assets.d.ts +7 -0
- package/build/assets.js +8 -0
- package/build/assets.js.map +1 -0
- package/build/config.d.ts +1 -0
- package/build/endpoint-spec.d.ts +1 -0
- package/build/endpoint-spec.js +1 -0
- package/build/endpoint-spec.js.map +1 -1
- package/build/safe-engine.d.ts +6 -0
- package/build/safe-engine.js +16 -0
- package/build/safe-engine.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/validate.d.ts +34 -0
- package/build/validate.js +56 -0
- package/build/validate.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RoleMessage } from './session.ts';
|
|
2
|
+
import { Function } from './function.ts';
|
|
3
|
+
import { type InferenceContext } from './inference-context.ts';
|
|
4
|
+
import { Engine } from './engine.ts';
|
|
5
|
+
export interface Validate<in out fdu extends Function.Declaration> {
|
|
6
|
+
(ctx: InferenceContext, response: RoleMessage.AI<fdu>): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace Validate {
|
|
9
|
+
class Rejection extends Error {
|
|
10
|
+
raw: string;
|
|
11
|
+
constructor(reason: string, raw: string);
|
|
12
|
+
}
|
|
13
|
+
function create<fdm extends Function.Declaration.Map>(vengine: Engine<Validate.fdu>): Validate<Function.Declaration.From<fdm>>;
|
|
14
|
+
const fdm: {
|
|
15
|
+
accept: {
|
|
16
|
+
description: string;
|
|
17
|
+
paraschema: import("@sinclair/typebox").TObject<{}>;
|
|
18
|
+
};
|
|
19
|
+
reject: {
|
|
20
|
+
description: string;
|
|
21
|
+
paraschema: import("@sinclair/typebox").TObject<{
|
|
22
|
+
reason: import("@sinclair/typebox").TString;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
throw: {
|
|
26
|
+
description: string;
|
|
27
|
+
paraschema: import("@sinclair/typebox").TObject<{
|
|
28
|
+
reason: import("@sinclair/typebox").TString;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type fdm = typeof fdm;
|
|
33
|
+
type fdu = Function.Declaration.From<fdm>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Assets from '#assets';
|
|
2
|
+
import { RoleMessage } from "./session.js";
|
|
3
|
+
import { Function } from "./function.js";
|
|
4
|
+
import {} from "./inference-context.js";
|
|
5
|
+
import { Type } from '@sinclair/typebox';
|
|
6
|
+
import { Engine } from "./engine.js";
|
|
7
|
+
export var Validate;
|
|
8
|
+
(function (Validate) {
|
|
9
|
+
class Rejection extends Error {
|
|
10
|
+
raw;
|
|
11
|
+
constructor(reason, raw) {
|
|
12
|
+
super(reason);
|
|
13
|
+
this.raw = raw;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Validate.Rejection = Rejection;
|
|
17
|
+
function create(vengine) {
|
|
18
|
+
return async (ctx, response) => {
|
|
19
|
+
const text = response.getText();
|
|
20
|
+
const vsession = {
|
|
21
|
+
developerMessage: RoleMessage.Developer.create([Assets.Validate.task]),
|
|
22
|
+
chatMessages: [RoleMessage.User.create([RoleMessage.Part.Text.paragraph(text)])],
|
|
23
|
+
};
|
|
24
|
+
const vresponse = await vengine(ctx, vsession);
|
|
25
|
+
const vfc = vresponse.getOnlyFunctionCall();
|
|
26
|
+
if (vfc.name === 'throw')
|
|
27
|
+
throw new Error(vfc.args.reason);
|
|
28
|
+
else if (vfc.name === 'reject')
|
|
29
|
+
throw new Rejection(vfc.args.reason, text);
|
|
30
|
+
else if (vfc.name === 'accept')
|
|
31
|
+
return;
|
|
32
|
+
else
|
|
33
|
+
throw new Error();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
Validate.create = create;
|
|
37
|
+
Validate.fdm = {
|
|
38
|
+
accept: {
|
|
39
|
+
description: '提取的对话内容是正确的。',
|
|
40
|
+
paraschema: Type.Object({}, { additionalProperties: false }),
|
|
41
|
+
},
|
|
42
|
+
reject: {
|
|
43
|
+
description: '提取的对话内容是错误的。',
|
|
44
|
+
paraschema: Type.Object({
|
|
45
|
+
reason: Type.String(),
|
|
46
|
+
}, { additionalProperties: false }),
|
|
47
|
+
},
|
|
48
|
+
throw: {
|
|
49
|
+
description: '无法判断提取的对话内容是否正确。',
|
|
50
|
+
paraschema: Type.Object({
|
|
51
|
+
reason: Type.String(),
|
|
52
|
+
}, { additionalProperties: false }),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
})(Validate || (Validate = {}));
|
|
56
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sour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BACtD,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iBACtE,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO;;gBAClC,MAAM,IAAI,KAAK,EAAE,CAAC;QACxB,CAAC,CAAA;IACF,CAAC;IAfe,eAAM,SAerB,CAAA;IAEY,YAAG,GAAG;QAClB,MAAM,EAAE;YACP,WAAW,EAAE,cAAc;YAC3B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;SAC5D;QACD,MAAM,EAAE;YACP,WAAW,EAAE,cAAc;YAC3B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;aACrB,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;SACnC;QACD,KAAK,EAAE;YACN,WAAW,EAAE,kBAAkB;YAC/B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;aACrB,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;SACnC;KACkC,CAAC;AAGtC,CAAC,EA/CgB,QAAQ,KAAR,QAAQ,QA+CxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zimtsui/brainswitch",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"exports": "./build/exports.js",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#config": "./build/config.js"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
15
|
"build": "tsc -b ./src/tsconfig.json",
|
|
16
|
-
"clean": "rm -rf ./build",
|
|
16
|
+
"clean": "rm -rf ./build && rm -rf ./docs",
|
|
17
17
|
"docs": "typedoc --tsconfig ./src/tsconfig.json ./src/exports.ts"
|
|
18
18
|
},
|
|
19
19
|
"author": "Zim",
|