@zimtsui/brainswitch 0.0.1

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/LICENSE +165 -0
  2. package/README.md +164 -0
  3. package/build/adaptor.d.ts +12 -0
  4. package/build/adaptor.js +62 -0
  5. package/build/adaptor.js.map +1 -0
  6. package/build/agentloop.d.ts +12 -0
  7. package/build/agentloop.js +47 -0
  8. package/build/agentloop.js.map +1 -0
  9. package/build/api-types/base.d.ts +21 -0
  10. package/build/api-types/base.js +37 -0
  11. package/build/api-types/base.js.map +1 -0
  12. package/build/api-types/google-base.d.ts +22 -0
  13. package/build/api-types/google-base.js +142 -0
  14. package/build/api-types/google-base.js.map +1 -0
  15. package/build/api-types/google-rest.d.ts +20 -0
  16. package/build/api-types/google-rest.js +113 -0
  17. package/build/api-types/google-rest.js.map +1 -0
  18. package/build/api-types/huggingface-cerebras-qwen3-thinking.d.ts +13 -0
  19. package/build/api-types/huggingface-cerebras-qwen3-thinking.js +52 -0
  20. package/build/api-types/huggingface-cerebras-qwen3-thinking.js.map +1 -0
  21. package/build/api-types/openai-chatcompletions-base.d.ts +28 -0
  22. package/build/api-types/openai-chatcompletions-base.js +150 -0
  23. package/build/api-types/openai-chatcompletions-base.js.map +1 -0
  24. package/build/api-types/openai-chatcompletions-monolith-base.d.ts +10 -0
  25. package/build/api-types/openai-chatcompletions-monolith-base.js +85 -0
  26. package/build/api-types/openai-chatcompletions-monolith-base.js.map +1 -0
  27. package/build/api-types/openai-chatcompletions-stream-base.d.ts +11 -0
  28. package/build/api-types/openai-chatcompletions-stream-base.js +110 -0
  29. package/build/api-types/openai-chatcompletions-stream-base.js.map +1 -0
  30. package/build/api-types/openai-chatcompletions.d.ts +6 -0
  31. package/build/api-types/openai-chatcompletions.js +10 -0
  32. package/build/api-types/openai-chatcompletions.js.map +1 -0
  33. package/build/api-types/openai-responses.d.ts +30 -0
  34. package/build/api-types/openai-responses.js +216 -0
  35. package/build/api-types/openai-responses.js.map +1 -0
  36. package/build/api-types/openrouter-monolith.d.ts +21 -0
  37. package/build/api-types/openrouter-monolith.js +57 -0
  38. package/build/api-types/openrouter-monolith.js.map +1 -0
  39. package/build/api-types/openrouter-stream.d.ts +27 -0
  40. package/build/api-types/openrouter-stream.js +68 -0
  41. package/build/api-types/openrouter-stream.js.map +1 -0
  42. package/build/api-types/qwen.d.ts +11 -0
  43. package/build/api-types/qwen.js +13 -0
  44. package/build/api-types/qwen.js.map +1 -0
  45. package/build/config.d.ts +23 -0
  46. package/build/config.js +12 -0
  47. package/build/config.js.map +1 -0
  48. package/build/endpoint-spec.d.ts +19 -0
  49. package/build/endpoint-spec.js +28 -0
  50. package/build/endpoint-spec.js.map +1 -0
  51. package/build/engine.d.ts +23 -0
  52. package/build/engine.js +18 -0
  53. package/build/engine.js.map +1 -0
  54. package/build/exports.d.ts +9 -0
  55. package/build/exports.js +10 -0
  56. package/build/exports.js.map +1 -0
  57. package/build/function.d.ts +68 -0
  58. package/build/function.js +41 -0
  59. package/build/function.js.map +1 -0
  60. package/build/inference-context.d.ts +15 -0
  61. package/build/inference-context.js +4 -0
  62. package/build/inference-context.js.map +1 -0
  63. package/build/session.d.ts +55 -0
  64. package/build/session.js +78 -0
  65. package/build/session.js.map +1 -0
  66. package/build/test.d.ts +1 -0
  67. package/build/test.js +23 -0
  68. package/build/test.js.map +1 -0
  69. package/build/throttle.d.ts +14 -0
  70. package/build/throttle.js +50 -0
  71. package/build/throttle.js.map +1 -0
  72. package/build/tsconfig.tsbuildinfo +1 -0
  73. package/package.json +38 -0
  74. package/typedoc.json +8 -0
@@ -0,0 +1,68 @@
1
+ import { Engine } from "../engine.js";
2
+ import { Function } from "../function.js";
3
+ import OpenAI from 'openai';
4
+ import assert from 'node:assert';
5
+ import { OpenAIChatCompletionsStreamAPIBase } from "./openai-chatcompletions-stream-base.js";
6
+ const EXCHANGE_RATE_USD_CNY = 8;
7
+ export class OpenRouterStreamAPI extends OpenAIChatCompletionsStreamAPIBase {
8
+ static create(options) {
9
+ const api = new OpenRouterStreamAPI(options);
10
+ return api.stream.bind(api);
11
+ }
12
+ calcCost(usage) {
13
+ return usage.cost * EXCHANGE_RATE_USD_CNY;
14
+ }
15
+ getDeltaThoughts(delta) {
16
+ return delta.reasoning ?? '';
17
+ }
18
+ makeStreamParams(session) {
19
+ const params = {
20
+ model: this.model,
21
+ messages: [
22
+ ...(session.developerMessage ? this.convertFromRoleMessage(session.developerMessage) : []),
23
+ ...session.chatMessages.flatMap(chatMessage => this.convertFromRoleMessage(chatMessage)),
24
+ ],
25
+ tools: Object.keys(this.functionDeclarationMap).length
26
+ ? Object.entries(this.functionDeclarationMap).map(fdentry => this.convertFromFunctionDeclarationEntry(fdentry))
27
+ : undefined,
28
+ tool_choice: Object.keys(this.functionDeclarationMap).length && this.toolChoice ? this.convertFromFunctionCallMode(this.toolChoice) : undefined,
29
+ stream: true,
30
+ usage: {
31
+ include: true,
32
+ },
33
+ ...this.customOptions,
34
+ };
35
+ return params;
36
+ }
37
+ convertToFunctionCallFromDelta(apifc) {
38
+ assert(apifc.id, new Error(undefined, { cause: apifc }));
39
+ assert(apifc.function?.name, new Error(undefined, { cause: apifc }));
40
+ assert(typeof apifc.function?.arguments === 'string', new Error(undefined, { cause: apifc }));
41
+ assert(apifc.type === 'function', new Error(undefined, { cause: apifc }));
42
+ return this.convertToFunctionCall(apifc);
43
+ }
44
+ convertToFunctionCall(apifc) {
45
+ if (apifc.function.arguments)
46
+ return super.convertToFunctionCall(apifc);
47
+ else
48
+ return super.convertToFunctionCall({
49
+ ...apifc,
50
+ function: {
51
+ ...apifc.function,
52
+ arguments: '{}',
53
+ },
54
+ });
55
+ }
56
+ async stream(ctx, session, retry = 0) {
57
+ try {
58
+ return await super.stream(ctx, session, retry);
59
+ }
60
+ catch (e) {
61
+ if (e instanceof TypeError && e.message === 'terminated')
62
+ return await this.stream(ctx, session, retry + 1);
63
+ else
64
+ throw e;
65
+ }
66
+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KAAmD;QAC3F,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS;YAC3B,OAAO,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;;YAE1C,OAAO,KAAK,CAAC,qBAAqB,CAAC;gBAClC,GAAG,KAAK;gBACR,QAAQ,EAAE;oBACT,GAAG,KAAK,CAAC,QAAQ;oBACjB,SAAS,EAAE,IAAI;iBACf;aACD,CAAC,CAAC;IACL,CAAC;IAEe,KAAK,CAAC,MAAM,CAC3B,GAAqB,EAAE,OAAgD,EAAE,KAAK,GAAG,CAAC;QAElF,IAAI,CAAC;YACJ,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,SAAS,IAAI,CAAC,CAAC,OAAO,KAAK,YAAY;gBACvD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,GAAC,CAAC,CAAC,CAAC;;gBAC5C,MAAM,CAAC,CAAC;QACd,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,11 @@
1
+ import type OpenAI from 'openai';
2
+ import { Engine } from '../engine.ts';
3
+ import { Function } from '../function.ts';
4
+ import { OpenAIChatCompletionsStreamAPIBase } from './openai-chatcompletions-stream-base.ts';
5
+ export interface QwenChatCompletionChunkChoiceDelta extends OpenAI.ChatCompletionChunk.Choice.Delta {
6
+ reasoning_content?: string;
7
+ }
8
+ export declare class QwenAPI<in out fdm extends Function.Declaration.Map = {}> extends OpenAIChatCompletionsStreamAPIBase<fdm> {
9
+ static create<fdm extends Function.Declaration.Map = never>(options: Engine.Options<fdm>): Engine<Function.Declaration.From<fdm>>;
10
+ protected getDeltaThoughts(delta: OpenAI.ChatCompletionChunk.Choice.Delta): string;
11
+ }
@@ -0,0 +1,13 @@
1
+ import { Engine } from "../engine.js";
2
+ import { Function } from "../function.js";
3
+ import { OpenAIChatCompletionsStreamAPIBase } from "./openai-chatcompletions-stream-base.js";
4
+ export class QwenAPI extends OpenAIChatCompletionsStreamAPIBase {
5
+ static create(options) {
6
+ const api = new QwenAPI(options);
7
+ return api.stream.bind(api);
8
+ }
9
+ getDeltaThoughts(delta) {
10
+ return delta.reasoning_content ?? '';
11
+ }
12
+ }
13
+ //# sourceMappingURL=qwen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qwen.js","sourceRoot":"","sources":["../../src/api-types/qwen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAQ7F,MAAM,OAAO,OAA0D,SAAQ,kCAAuC;IAC9G,MAAM,CAAC,MAAM,CAA+C,OAA4B;QAC9F,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;QACjC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAEkB,gBAAgB,CAAC,KAA8C;QACjF,OAAQ,KAA4C,CAAC,iBAAiB,IAAI,EAAE,CAAC;IAC9E,CAAC;CACD"}
@@ -0,0 +1,23 @@
1
+ import { type Static } from '@sinclair/typebox';
2
+ export type Config = Static<typeof Config.schema>;
3
+ export declare namespace Config {
4
+ const schema: import("@sinclair/typebox").TObject<{
5
+ brainswitch: import("@sinclair/typebox").TObject<{
6
+ endpoints: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TObject<{
7
+ baseUrl: import("@sinclair/typebox").TString;
8
+ proxy: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
9
+ apiKey: import("@sinclair/typebox").TString;
10
+ model: import("@sinclair/typebox").TString;
11
+ name: import("@sinclair/typebox").TString;
12
+ apiType: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"openai-chatcompletions">, import("@sinclair/typebox").TLiteral<"openai-responses">, import("@sinclair/typebox").TLiteral<"google">, import("@sinclair/typebox").TLiteral<"qwen">, import("@sinclair/typebox").TLiteral<"openrouter-monolith">, import("@sinclair/typebox").TLiteral<"openrouter-stream">, import("@sinclair/typebox").TLiteral<"huggingface-cerebras-qwen3-thinking">]>;
13
+ inputPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
14
+ outputPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
15
+ cachedPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
16
+ customOptions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
17
+ rpm: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
18
+ tpm: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
19
+ timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
20
+ }>>;
21
+ }>;
22
+ }>;
23
+ }
@@ -0,0 +1,12 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ import { EndpointSpec } from "./endpoint-spec.js";
3
+ import {} from '@sinclair/typebox';
4
+ export var Config;
5
+ (function (Config) {
6
+ Config.schema = Type.Object({
7
+ brainswitch: Type.Object({
8
+ endpoints: Type.Record(Type.String(), EndpointSpec.schema),
9
+ }),
10
+ });
11
+ })(Config || (Config = {}));
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAe,MAAM,mBAAmB,CAAC;AAIhD,MAAM,KAAW,MAAM,CAMtB;AAND,WAAiB,MAAM;IACT,aAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACjC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;YACxB,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,YAAY,CAAC,MAAM,CAAC;SAC1D,CAAC;KACF,CAAC,CAAC;AACJ,CAAC,EANgB,MAAM,KAAN,MAAM,QAMtB"}
@@ -0,0 +1,19 @@
1
+ import { type Static } from "@sinclair/typebox";
2
+ export type EndpointSpec = Static<typeof EndpointSpec.schema>;
3
+ export declare namespace EndpointSpec {
4
+ const schema: import("@sinclair/typebox").TObject<{
5
+ baseUrl: import("@sinclair/typebox").TString;
6
+ proxy: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
7
+ apiKey: import("@sinclair/typebox").TString;
8
+ model: import("@sinclair/typebox").TString;
9
+ name: import("@sinclair/typebox").TString;
10
+ apiType: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"openai-chatcompletions">, import("@sinclair/typebox").TLiteral<"openai-responses">, import("@sinclair/typebox").TLiteral<"google">, import("@sinclair/typebox").TLiteral<"qwen">, import("@sinclair/typebox").TLiteral<"openrouter-monolith">, import("@sinclair/typebox").TLiteral<"openrouter-stream">, import("@sinclair/typebox").TLiteral<"huggingface-cerebras-qwen3-thinking">]>;
11
+ inputPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
12
+ outputPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
13
+ cachedPrice: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
14
+ customOptions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
15
+ rpm: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
16
+ tpm: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
17
+ timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
18
+ }>;
19
+ }
@@ -0,0 +1,28 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ export var EndpointSpec;
3
+ (function (EndpointSpec) {
4
+ EndpointSpec.schema = Type.Object({
5
+ baseUrl: Type.String(),
6
+ proxy: Type.Optional(Type.String()),
7
+ apiKey: Type.String(),
8
+ model: Type.String(),
9
+ name: Type.String(),
10
+ apiType: Type.Union([
11
+ Type.Literal('openai-chatcompletions'),
12
+ Type.Literal('openai-responses'),
13
+ Type.Literal('google'),
14
+ Type.Literal('qwen'),
15
+ Type.Literal('openrouter-monolith'),
16
+ Type.Literal('openrouter-stream'),
17
+ Type.Literal('huggingface-cerebras-qwen3-thinking'),
18
+ ]),
19
+ inputPrice: Type.Optional(Type.Number()),
20
+ outputPrice: Type.Optional(Type.Number()),
21
+ cachedPrice: Type.Optional(Type.Number()),
22
+ customOptions: Type.Optional(Type.Record(Type.String(), Type.Any())),
23
+ rpm: Type.Optional(Type.Number()),
24
+ tpm: Type.Optional(Type.Number()),
25
+ timeout: Type.Optional(Type.Number()),
26
+ });
27
+ })(EndpointSpec || (EndpointSpec = {}));
28
+ //# sourceMappingURL=endpoint-spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-spec.js","sourceRoot":"","sources":["../src/endpoint-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AAItD,MAAM,KAAW,YAAY,CAwB5B;AAxBD,WAAiB,YAAY;IACf,mBAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACjC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;QACtB,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;QACrB,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;QACpB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC;YACnB,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC;YACtC,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,qCAAqC,CAAC;SACnD,CAAC;QACF,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACxC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACzC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACzC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;KACrC,CAAC,CAAC;AACJ,CAAC,EAxBgB,YAAY,KAAZ,YAAY,QAwB5B"}
@@ -0,0 +1,23 @@
1
+ import { RoleMessage, type Session } from './session.ts';
2
+ import { Function } from './function.ts';
3
+ import { EndpointSpec } from './endpoint-spec.ts';
4
+ import { type InferenceContext } from './inference-context.ts';
5
+ import { Throttle } from './throttle.ts';
6
+ export interface Engine<in out fdu extends Function.Declaration = never> {
7
+ (ctx: InferenceContext, session: Session<fdu>): Promise<RoleMessage.AI<fdu>>;
8
+ }
9
+ export declare namespace Engine {
10
+ namespace Options {
11
+ interface Functions<in out fdm extends Function.Declaration.Map = {}> {
12
+ functionDeclarationMap: fdm;
13
+ functionCallMode?: Function.ToolChoice<fdm>;
14
+ }
15
+ }
16
+ interface Options<in out fdm extends Function.Declaration.Map = {}> extends EndpointSpec, Options.Functions<fdm> {
17
+ throttle: Throttle;
18
+ }
19
+ /**
20
+ * @param session mutable
21
+ */
22
+ function apply<fdm extends Function.Declaration.Map = {}>(ctx: InferenceContext, session: Session<Function.Declaration.From<fdm>>, cc: Engine<Function.Declaration.From<fdm>>): Promise<RoleMessage.AI<Function.Declaration.From<fdm>>>;
23
+ }
@@ -0,0 +1,18 @@
1
+ import { RoleMessage } from "./session.js";
2
+ import { Function } from "./function.js";
3
+ import { EndpointSpec } from "./endpoint-spec.js";
4
+ import {} from "./inference-context.js";
5
+ import { Throttle } from "./throttle.js";
6
+ export var Engine;
7
+ (function (Engine) {
8
+ /**
9
+ * @param session mutable
10
+ */
11
+ async function apply(ctx, session, cc) {
12
+ const response = await cc(ctx, session);
13
+ session.chatMessages.push(response);
14
+ return response;
15
+ }
16
+ Engine.apply = apply;
17
+ })(Engine || (Engine = {}));
18
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAyB,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAOzC,MAAM,KAAW,MAAM,CAwBtB;AAxBD,WAAiB,MAAM;IAYtB;;OAEG;IACI,KAAK,UAAU,KAAK,CAC1B,GAAqB,EACrB,OAAgD,EAChD,EAA0C;QAE1C,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,OAAO,QAAQ,CAAC;IACjB,CAAC;IARqB,YAAK,QAQ1B,CAAA;AACF,CAAC,EAxBgB,MAAM,KAAN,MAAM,QAwBtB"}
@@ -0,0 +1,9 @@
1
+ export * from './adaptor.ts';
2
+ export * from './throttle.ts';
3
+ export * from './session.ts';
4
+ export * from './engine.ts';
5
+ export * from './function.ts';
6
+ export * from './config.ts';
7
+ export * from './inference-context.ts';
8
+ export * from './endpoint-spec.ts';
9
+ export * from './agentloop.ts';
@@ -0,0 +1,10 @@
1
+ export * from "./adaptor.js";
2
+ export * from "./throttle.js";
3
+ export * from "./session.js";
4
+ export * from "./engine.js";
5
+ export * from "./function.js";
6
+ export * from "./config.js";
7
+ export * from "./inference-context.js";
8
+ export * from "./endpoint-spec.js";
9
+ export * from "./agentloop.js";
10
+ //# 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,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type Static, type TSchema } from '@sinclair/typebox';
2
+ export interface Function<in out fd extends Function.Declaration> {
3
+ (params: Static<fd['paraschema']>): Promise<string> | string;
4
+ }
5
+ export declare namespace Function {
6
+ interface Declaration<name extends string = string, ps extends TSchema = TSchema> extends Declaration.Item<ps> {
7
+ name: name;
8
+ }
9
+ namespace Declaration {
10
+ type From<fdm extends Map, name extends Map.NameOf<fdm> = Map.NameOf<fdm>> = {
11
+ [name in Map.NameOf<fdm>]: Declaration<name, fdm[name]['paraschema']>;
12
+ }[name];
13
+ type Map = Record<string, Item<TSchema>>;
14
+ namespace Map {
15
+ type NameOf<fdm extends Map> = Extract<keyof fdm, string>;
16
+ }
17
+ interface Item<in out ps extends TSchema = TSchema> {
18
+ description?: string;
19
+ paraschema: ps;
20
+ }
21
+ namespace Item {
22
+ type From<fdm extends Map, name extends Map.NameOf<fdm> = Map.NameOf<fdm>> = Item<fdm[name]['paraschema']>;
23
+ }
24
+ type Entry<name extends string, ps extends TSchema> = [name, Item<ps>];
25
+ namespace Entry {
26
+ type From<fdm extends Map, name extends Map.NameOf<fdm> = Map.NameOf<fdm>> = Entry<name, fdm[name]['paraschema']>;
27
+ }
28
+ }
29
+ class Call<in out fd extends Declaration> {
30
+ static readonly CALL_NOMINAL: unique symbol;
31
+ private readonly [Call.CALL_NOMINAL];
32
+ id?: string;
33
+ name: fd['name'];
34
+ args: Static<fd['paraschema']>;
35
+ private constructor();
36
+ static create<fdu extends Declaration>(fc: Call.create.Options<fdu>): Call.Distributive<fdu>;
37
+ }
38
+ namespace Call {
39
+ type Distributive<fdu extends Declaration> = fdu extends infer fd extends Declaration ? Call<fd> : never;
40
+ namespace create {
41
+ type Options<fdu extends Declaration> = fdu extends infer fd extends Function.Declaration ? Omit<Call<fd>, never> : never;
42
+ }
43
+ }
44
+ class Response<in out fd extends Declaration> {
45
+ static readonly RESPONSE_NOMINAL: unique symbol;
46
+ private readonly [Response.RESPONSE_NOMINAL];
47
+ id?: string;
48
+ name: fd['name'];
49
+ text: string;
50
+ private constructor();
51
+ static create<fdu extends Declaration>(fr: Response.create.Options<fdu>): Response.Distributive<fdu>;
52
+ }
53
+ namespace Response {
54
+ type Distributive<fdu extends Declaration> = fdu extends infer fd extends Declaration ? Response<fd> : never;
55
+ namespace create {
56
+ type Options<fdu extends Declaration> = fdu extends infer fd extends Function.Declaration ? Omit<Response<fd>, never> : never;
57
+ }
58
+ }
59
+ type ToolChoice<fdm extends Function.Declaration.Map> = Function.Declaration.Map.NameOf<fdm>[] | typeof ToolChoice.NONE | typeof ToolChoice.REQUIRED | typeof ToolChoice.AUTO;
60
+ namespace ToolChoice {
61
+ const NONE: unique symbol;
62
+ const REQUIRED: unique symbol;
63
+ const AUTO: unique symbol;
64
+ }
65
+ type Map<fdm extends Function.Declaration.Map> = {
66
+ [name in Function.Declaration.Map.NameOf<fdm>]: Function<Function.Declaration.From<fdm, name>>;
67
+ };
68
+ }
@@ -0,0 +1,41 @@
1
+ import {} from '@sinclair/typebox';
2
+ export var Function;
3
+ (function (Function) {
4
+ class Call {
5
+ static CALL_NOMINAL = Symbol();
6
+ id;
7
+ name;
8
+ args;
9
+ constructor(fc) {
10
+ this.id = fc.id;
11
+ this.name = fc.name;
12
+ this.args = fc.args;
13
+ }
14
+ static create(fc) {
15
+ return new Call(fc);
16
+ }
17
+ }
18
+ Function.Call = Call;
19
+ class Response {
20
+ static RESPONSE_NOMINAL = Symbol();
21
+ id;
22
+ name;
23
+ text;
24
+ constructor(fr) {
25
+ this.id = fr.id;
26
+ this.name = fr.name;
27
+ this.text = fr.text;
28
+ }
29
+ static create(fr) {
30
+ return new Response(fr);
31
+ }
32
+ }
33
+ Function.Response = Response;
34
+ let ToolChoice;
35
+ (function (ToolChoice) {
36
+ ToolChoice.NONE = Symbol();
37
+ ToolChoice.REQUIRED = Symbol();
38
+ ToolChoice.AUTO = Symbol();
39
+ })(ToolChoice = Function.ToolChoice || (Function.ToolChoice = {}));
40
+ })(Function || (Function = {}));
41
+ //# sourceMappingURL=function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.js","sourceRoot":"","sources":["../src/function.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AAO9D,MAAM,KAAW,QAAQ,CAsFxB;AAtFD,WAAiB,QAAQ;IA4BxB,MAAa,IAAI;QACT,MAA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tsui/typelog/presets';
4
+ export interface InferenceContext {
5
+ busy?: RWLock;
6
+ logger: InferenceContext.Logger;
7
+ 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
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ import { RWLock } from '@zimtsui/coroutine-locks';
2
+ import { Channel } from '@zimtsui/typelog';
3
+ import * as Presets from '@zimtsui/typelog/presets';
4
+ //# sourceMappingURL=inference-context.js.map
@@ -0,0 +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,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { Function } from './function.ts';
2
+ export interface Session<out fdu extends Function.Declaration = never> {
3
+ developerMessage?: RoleMessage.Developer;
4
+ chatMessages: ChatMessage<fdu>[];
5
+ }
6
+ export type ChatMessage<fdu extends Function.Declaration = never> = RoleMessage.User<fdu> | RoleMessage.AI<fdu>;
7
+ export declare abstract class RoleMessage<out fdu extends Function.Declaration = never> {
8
+ static readonly ROLE_MESSAGE_NOMINAL: unique symbol;
9
+ private readonly [RoleMessage.ROLE_MESSAGE_NOMINAL];
10
+ }
11
+ export declare namespace RoleMessage {
12
+ class Text {
13
+ text: string;
14
+ static readonly Text_NOMINAL: unique symbol;
15
+ private readonly [Text.Text_NOMINAL];
16
+ constructor(text: string);
17
+ }
18
+ class AI<out fdu extends Function.Declaration = never> extends RoleMessage<fdu> {
19
+ parts: AI.Part<fdu>[];
20
+ static readonly AI_NOMINAL: unique symbol;
21
+ private readonly [AI.AI_NOMINAL];
22
+ constructor(parts: AI.Part<fdu>[]);
23
+ getText(): string;
24
+ getOnlyText(): string;
25
+ getOnlyFunctionCall(): Function.Call.Distributive<fdu>;
26
+ getFunctionCalls(): Function.Call.Distributive<fdu>[];
27
+ }
28
+ namespace AI {
29
+ type Part<fdu extends Function.Declaration = never> = Text | Function.Call.Distributive<fdu>;
30
+ }
31
+ class User<out fdu extends Function.Declaration = never> extends RoleMessage<fdu> {
32
+ parts: User.Part<fdu>[];
33
+ static readonly USER_NOMINAL: unique symbol;
34
+ private readonly [User.USER_NOMINAL];
35
+ constructor(parts: User.Part<fdu>[]);
36
+ getText(): string;
37
+ getOnlyText(): string;
38
+ getFunctionResponses(): Function.Response.Distributive<fdu>[];
39
+ getOnlyFunctionResponse(): Function.Response.Distributive<fdu>;
40
+ }
41
+ namespace User {
42
+ type Part<fdu extends Function.Declaration = never> = Text | Function.Response.Distributive<fdu>;
43
+ }
44
+ class Developer extends RoleMessage {
45
+ parts: Developer.Part[];
46
+ static readonly DEVELOPER_NOMINAL: unique symbol;
47
+ private readonly [Developer.DEVELOPER_NOMINAL];
48
+ constructor(parts: Developer.Part[]);
49
+ getText(): string;
50
+ getOnlyText(): string;
51
+ }
52
+ namespace Developer {
53
+ type Part = Text;
54
+ }
55
+ }
@@ -0,0 +1,78 @@
1
+ import assert from 'node:assert';
2
+ import { Function } from "./function.js";
3
+ export class RoleMessage {
4
+ static ROLE_MESSAGE_NOMINAL = Symbol();
5
+ }
6
+ (function (RoleMessage) {
7
+ class Text {
8
+ text;
9
+ static Text_NOMINAL = Symbol();
10
+ constructor(text) {
11
+ this.text = text;
12
+ }
13
+ }
14
+ RoleMessage.Text = Text;
15
+ class AI extends RoleMessage {
16
+ parts;
17
+ static AI_NOMINAL = Symbol();
18
+ constructor(parts) {
19
+ super();
20
+ this.parts = parts;
21
+ }
22
+ getText() {
23
+ return this.parts.filter(part => part instanceof Text).map(part => part.text).join('');
24
+ }
25
+ getOnlyText() {
26
+ assert(this.parts.every(part => part instanceof Text));
27
+ return this.getText();
28
+ }
29
+ getOnlyFunctionCall() {
30
+ const fcs = this.getFunctionCalls();
31
+ assert(fcs.length === 1);
32
+ return fcs[0];
33
+ }
34
+ getFunctionCalls() {
35
+ return this.parts.filter(part => part instanceof Function.Call);
36
+ }
37
+ }
38
+ RoleMessage.AI = AI;
39
+ class User extends RoleMessage {
40
+ parts;
41
+ static USER_NOMINAL = Symbol();
42
+ constructor(parts) {
43
+ super();
44
+ this.parts = parts;
45
+ }
46
+ getText() {
47
+ return this.parts.filter(part => part instanceof Text).map(part => part.text).join('');
48
+ }
49
+ getOnlyText() {
50
+ assert(this.parts.every(part => part instanceof Text));
51
+ return this.getText();
52
+ }
53
+ getFunctionResponses() {
54
+ return this.parts.filter(part => part instanceof Function.Response);
55
+ }
56
+ getOnlyFunctionResponse() {
57
+ assert(this.parts.length === 1 && this.parts[0] instanceof Function.Response);
58
+ return this.parts[0];
59
+ }
60
+ }
61
+ RoleMessage.User = User;
62
+ class Developer extends RoleMessage {
63
+ parts;
64
+ static DEVELOPER_NOMINAL = Symbol();
65
+ constructor(parts) {
66
+ super();
67
+ this.parts = parts;
68
+ }
69
+ getText() {
70
+ return this.parts.map(part => part.text).join('');
71
+ }
72
+ getOnlyText() {
73
+ return this.getText();
74
+ }
75
+ }
76
+ RoleMessage.Developer = Developer;
77
+ })(RoleMessage || (RoleMessage = {}));
78
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAWzC,MAAM,OAAgB,WAAW;IACzB,MAAM,CAAU,oBAAoB,GAAG,MAAM,EAAE,CAAC;;AAIxD,WAAiB,WAAW;IAC3B,MAAa,IAAI;QAGU;QAFnB,MAAM,CAAU,YAAY,GAAG,MAAM,EAAE,CAAC;QAE/C,YAA0B,IAAY;YAAZ,SAAI,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
+ export {};
package/build/test.js ADDED
@@ -0,0 +1,23 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ import { Function } from '@zimtsui/brainswitch';
3
+ const fdm = {
4
+ foo: {
5
+ description: 'foo',
6
+ paraschema: Type.Object({
7
+ bar: Type.String(),
8
+ }),
9
+ },
10
+ bar: {
11
+ description: 'bar',
12
+ paraschema: Type.Object({
13
+ baz: Type.String(),
14
+ }),
15
+ },
16
+ };
17
+ const fd = {
18
+ name: 'foo',
19
+ paraschema: Type.Object({
20
+ bar: Type.String(),
21
+ }),
22
+ };
23
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD,MAAM,GAAG,GAAG;IACX,GAAG,EAAE;QACJ,WAAW,EAAE,KAAc;QAC3B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;YACvB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;SAClB,CAAC;KACF;IACD,GAAG,EAAE;QACJ,WAAW,EAAE,KAAc;QAC3B,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;YACvB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;SAClB,CAAC;KACF;CACkC,CAAC;AAIrC,MAAM,EAAE,GAAQ;IACf,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACvB,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;KAClB,CAAC;CACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { InferenceContext } from './inference-context.ts';
2
+ export declare class Throttle {
3
+ private rpm;
4
+ private tpm;
5
+ private redundancy;
6
+ private fifo;
7
+ private tokenCount;
8
+ private valve;
9
+ private interval;
10
+ constructor(rpm: number, tpm: number, redundancy?: number);
11
+ requests(ctx: InferenceContext): Promise<void>;
12
+ inputTokens(deltaTokenCount: number, ctx: InferenceContext): Promise<void>;
13
+ outputTokens(deltaTokenCount: number): void;
14
+ }