@dvina/agents 0.3.6 → 0.4.0

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.
@@ -0,0 +1,105 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // src/runtime/langchain/model-resolver.ts
34
+ import { AzureChatOpenAI, ChatOpenAI } from "@langchain/openai";
35
+ var LangchainModelResolver = class {
36
+ constructor(config) {
37
+ this.config = config;
38
+ }
39
+ resolve(modelString, tags) {
40
+ const parts = modelString.split(":");
41
+ if (parts.length === 2) {
42
+ const [provider, modelName] = parts;
43
+ return this.resolveByProvider(provider, "default", modelName, tags);
44
+ }
45
+ if (parts.length === 3) {
46
+ const [provider, configName, modelName] = parts;
47
+ return this.resolveByProvider(provider, configName, modelName, tags);
48
+ }
49
+ throw new Error(
50
+ 'Model string must follow format "provider:modelName" (uses "default" config) or "provider:configName:modelName"'
51
+ );
52
+ }
53
+ resolveByProvider(provider, configName, modelName, tags) {
54
+ switch (provider) {
55
+ case "openai":
56
+ return this.resolveOpenAI(configName, modelName, tags);
57
+ case "azure":
58
+ return this.resolveAzure(configName, modelName, tags);
59
+ default:
60
+ throw new Error(`Unsupported model provider: ${provider}`);
61
+ }
62
+ }
63
+ resolveOpenAI(configName, modelName, tags) {
64
+ const providerConfig = this.config.openai?.[configName];
65
+ if (!providerConfig) {
66
+ throw new Error(`Configuration "${configName}" for provider "openai" is missing`);
67
+ }
68
+ return new ChatOpenAI({
69
+ apiKey: providerConfig.apiKey,
70
+ modelName,
71
+ tags
72
+ });
73
+ }
74
+ resolveAzure(configName, deploymentName, tags) {
75
+ const providerConfig = this.config.azure?.[configName];
76
+ if (!providerConfig) {
77
+ throw new Error(`Configuration "${configName}" for provider "azure" is missing`);
78
+ }
79
+ return new AzureChatOpenAI({
80
+ model: providerConfig.model,
81
+ // shows (perhaps even uses) 3.5-turbo when not specifid
82
+ azureOpenAIApiKey: providerConfig.apiKey,
83
+ azureOpenAIApiInstanceName: this.extractInstanceName(providerConfig.endpoint),
84
+ azureOpenAIApiDeploymentName: deploymentName,
85
+ azureOpenAIApiVersion: providerConfig.apiVersion,
86
+ tags
87
+ });
88
+ }
89
+ extractInstanceName(endpoint) {
90
+ try {
91
+ const url = new URL(endpoint);
92
+ return url.hostname.split(".")[0];
93
+ } catch (e) {
94
+ return endpoint;
95
+ }
96
+ }
97
+ };
98
+
99
+ export {
100
+ __require,
101
+ __commonJS,
102
+ __toESM,
103
+ LangchainModelResolver
104
+ };
105
+ //# sourceMappingURL=chunk-LEEZCLZM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/langchain/model-resolver.ts"],"sourcesContent":["import { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { AzureChatOpenAI, ChatOpenAI } from '@langchain/openai';\n\nexport type LangchainOpenAIConfig = {\n\tapiKey: string;\n};\n\nexport type LangchainAzureConfig = {\n\tmodel: string;\n\tapiKey: string;\n\tendpoint: string;\n\tapiVersion: string;\n};\n\nexport type LangchainModelConfig = {\n\topenai?: Record<string, LangchainOpenAIConfig>;\n\tazure?: Record<string, LangchainAzureConfig>;\n};\n\nexport class LangchainModelResolver {\n\tconstructor(private config: LangchainModelConfig) {}\n\n\tresolve(modelString: string, tags?: string[]): BaseLanguageModel {\n\t\tconst parts = modelString.split(':');\n\n\t\tif (parts.length === 2) {\n\t\t\tconst [provider, modelName] = parts;\n\t\t\treturn this.resolveByProvider(provider, 'default', modelName, tags);\n\t\t}\n\n\t\tif (parts.length === 3) {\n\t\t\tconst [provider, configName, modelName] = parts;\n\t\t\treturn this.resolveByProvider(provider, configName, modelName, tags);\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t'Model string must follow format \"provider:modelName\" (uses \"default\" config) or \"provider:configName:modelName\"',\n\t\t);\n\t}\n\n\tprivate resolveByProvider(\n\t\tprovider: string,\n\t\tconfigName: string,\n\t\tmodelName: string,\n\t\ttags?: string[],\n\t): BaseLanguageModel {\n\t\tswitch (provider) {\n\t\t\tcase 'openai':\n\t\t\t\treturn this.resolveOpenAI(configName, modelName, tags);\n\t\t\tcase 'azure':\n\t\t\t\treturn this.resolveAzure(configName, modelName, tags);\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported model provider: ${provider}`);\n\t\t}\n\t}\n\n\tprivate resolveOpenAI(configName: string, modelName: string, tags?: string[]): ChatOpenAI {\n\t\tconst providerConfig = this.config.openai?.[configName];\n\t\tif (!providerConfig) {\n\t\t\tthrow new Error(`Configuration \"${configName}\" for provider \"openai\" is missing`);\n\t\t}\n\n\t\treturn new ChatOpenAI({\n\t\t\tapiKey: providerConfig.apiKey,\n\t\t\tmodelName: modelName,\n\t\t\ttags: tags,\n\t\t});\n\t}\n\n\tprivate resolveAzure(configName: string, deploymentName: string, tags?: string[]): AzureChatOpenAI {\n\t\tconst providerConfig = this.config.azure?.[configName];\n\t\tif (!providerConfig) {\n\t\t\tthrow new Error(`Configuration \"${configName}\" for provider \"azure\" is missing`);\n\t\t}\n\n\t\treturn new AzureChatOpenAI({\n\t\t\tmodel: providerConfig.model, // shows (perhaps even uses) 3.5-turbo when not specifid\n\t\t\tazureOpenAIApiKey: providerConfig.apiKey,\n\t\t\tazureOpenAIApiInstanceName: this.extractInstanceName(providerConfig.endpoint),\n\t\t\tazureOpenAIApiDeploymentName: deploymentName,\n\t\t\tazureOpenAIApiVersion: providerConfig.apiVersion,\n\t\t\ttags: tags,\n\t\t});\n\t}\n\n\tprivate extractInstanceName(endpoint: string): string {\n\t\ttry {\n\t\t\tconst url = new URL(endpoint);\n\t\t\treturn url.hostname.split('.')[0];\n\t\t} catch (e) {\n\t\t\treturn endpoint;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAS,iBAAiB,kBAAkB;AAkBrC,IAAM,yBAAN,MAA6B;AAAA,EACnC,YAAoB,QAA8B;AAA9B;AAAA,EAA+B;AAAA,EAEnD,QAAQ,aAAqB,MAAoC;AAChE,UAAM,QAAQ,YAAY,MAAM,GAAG;AAEnC,QAAI,MAAM,WAAW,GAAG;AACvB,YAAM,CAAC,UAAU,SAAS,IAAI;AAC9B,aAAO,KAAK,kBAAkB,UAAU,WAAW,WAAW,IAAI;AAAA,IACnE;AAEA,QAAI,MAAM,WAAW,GAAG;AACvB,YAAM,CAAC,UAAU,YAAY,SAAS,IAAI;AAC1C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 -0,0 +1,109 @@
1
+ import { L as LangchainModelConfig } from '../model-resolver-BRAaBV9n.mjs';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+
4
+ interface EvalConfig {
5
+ modelConfig: LangchainModelConfig;
6
+ model: string;
7
+ /** Model for evaluators needing LLM calls (language detection, LLM-as-judge). Defaults to `model`. */
8
+ evaluatorModel?: string;
9
+ /** System prompt prepended to every eval invocation. Can be overridden per-suite or per-case. */
10
+ systemPrompt?: string;
11
+ }
12
+ declare function configureEvals(config: EvalConfig): void;
13
+
14
+ interface MockToolDef {
15
+ name: string;
16
+ description: string;
17
+ schema: Record<string, unknown>;
18
+ /**
19
+ * Canned response the mock tool returns.
20
+ * Can be a static string, or a function that receives input and returns a response.
21
+ * If a function is provided, it receives the full invocation count as a second arg
22
+ * to support scenarios like "first call fails, second call succeeds".
23
+ */
24
+ response: string | ((input: Record<string, unknown>, callCount: number) => string);
25
+ }
26
+
27
+ type EvaluatorFn = (args: {
28
+ outputs: Record<string, any>;
29
+ referenceOutputs: Record<string, any>;
30
+ }) => Promise<any>;
31
+ interface ResolvedExpectation {
32
+ evaluator: EvaluatorFn;
33
+ referenceOutputs: Record<string, unknown>;
34
+ }
35
+ /** A factory that receives test context and returns an evaluator + its referenceOutputs. */
36
+ type Expectation = (ctx: {
37
+ message: string;
38
+ }) => ResolvedExpectation;
39
+ /**
40
+ * Expect the agent to call tools in order (superset trajectory match).
41
+ * Empty `[]` means the agent should answer directly without calling any tools.
42
+ */
43
+ declare function toolsCalled(tools: string[]): Expectation;
44
+ /**
45
+ * Run an LLM-as-judge evaluator on the trajectory.
46
+ * Requires `toolsCalled` in the same expect array.
47
+ * Uses the globally configured evaluator model.
48
+ */
49
+ declare function llmJudge(): Expectation;
50
+ /** Assert the agent made zero tool calls. */
51
+ declare function noTools(): Expectation;
52
+ /**
53
+ * Assert the response is in the given language (ISO 639-1 code).
54
+ * Uses the globally configured evaluator model for language detection.
55
+ * @param code - ISO 639-1 language code (e.g. 'en', 'tr', 'de').
56
+ */
57
+ declare function respondsInLanguage(code: string): Expectation;
58
+ /** Assert the response contains all given strings. */
59
+ declare function contains(strings: string[]): Expectation;
60
+ /** Assert the response does not contain any of the given strings. */
61
+ declare function notContains(strings: string[]): Expectation;
62
+
63
+ declare function human(content: string): {
64
+ role: "human";
65
+ content: string;
66
+ };
67
+ declare function ai(content: string, toolCalls?: string[]): {
68
+ toolCalls?: string[] | undefined;
69
+ role: "ai";
70
+ content: string;
71
+ };
72
+ declare function toolResult(content: string): {
73
+ role: "tool";
74
+ content: string;
75
+ };
76
+ type Message = ReturnType<typeof human> | ReturnType<typeof ai> | ReturnType<typeof toolResult>;
77
+ interface ToolDef {
78
+ description: string;
79
+ schema?: Record<string, string>;
80
+ /** Auto-stringified if not a string or function. */
81
+ response: unknown | ((input: Record<string, unknown>, callCount: number) => string);
82
+ }
83
+ interface TestCase {
84
+ /** Test name. Defaults to the last human message content if omitted. */
85
+ name?: string;
86
+ messages: Message[];
87
+ systemPrompt?: string;
88
+ /** Override suite-level tools for this case. */
89
+ tools?: Record<string, ToolDef>;
90
+ expect: Expectation[];
91
+ }
92
+ type TargetFn = (inputs: {
93
+ systemPrompt?: string;
94
+ messages: Message[];
95
+ tools: MockToolDef[];
96
+ }) => Promise<{
97
+ messages: BaseMessage[];
98
+ }>;
99
+ interface SuiteConfig {
100
+ /** Custom target function, or model string override. Auto-created from global config if omitted. */
101
+ target?: TargetFn | string;
102
+ /** System prompt for all cases in this suite. Overrides the global prompt; can be overridden per-case. */
103
+ systemPrompt?: string;
104
+ tools: Record<string, ToolDef>;
105
+ cases: TestCase[];
106
+ }
107
+ declare function defineSuite(name: string, config: SuiteConfig): void;
108
+
109
+ export { type EvalConfig, type Expectation, type SuiteConfig, type TestCase, type ToolDef, ai, configureEvals, contains, defineSuite, human, llmJudge, noTools, notContains, respondsInLanguage, toolResult, toolsCalled };
@@ -0,0 +1,109 @@
1
+ import { L as LangchainModelConfig } from '../model-resolver-BRAaBV9n.js';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+
4
+ interface EvalConfig {
5
+ modelConfig: LangchainModelConfig;
6
+ model: string;
7
+ /** Model for evaluators needing LLM calls (language detection, LLM-as-judge). Defaults to `model`. */
8
+ evaluatorModel?: string;
9
+ /** System prompt prepended to every eval invocation. Can be overridden per-suite or per-case. */
10
+ systemPrompt?: string;
11
+ }
12
+ declare function configureEvals(config: EvalConfig): void;
13
+
14
+ interface MockToolDef {
15
+ name: string;
16
+ description: string;
17
+ schema: Record<string, unknown>;
18
+ /**
19
+ * Canned response the mock tool returns.
20
+ * Can be a static string, or a function that receives input and returns a response.
21
+ * If a function is provided, it receives the full invocation count as a second arg
22
+ * to support scenarios like "first call fails, second call succeeds".
23
+ */
24
+ response: string | ((input: Record<string, unknown>, callCount: number) => string);
25
+ }
26
+
27
+ type EvaluatorFn = (args: {
28
+ outputs: Record<string, any>;
29
+ referenceOutputs: Record<string, any>;
30
+ }) => Promise<any>;
31
+ interface ResolvedExpectation {
32
+ evaluator: EvaluatorFn;
33
+ referenceOutputs: Record<string, unknown>;
34
+ }
35
+ /** A factory that receives test context and returns an evaluator + its referenceOutputs. */
36
+ type Expectation = (ctx: {
37
+ message: string;
38
+ }) => ResolvedExpectation;
39
+ /**
40
+ * Expect the agent to call tools in order (superset trajectory match).
41
+ * Empty `[]` means the agent should answer directly without calling any tools.
42
+ */
43
+ declare function toolsCalled(tools: string[]): Expectation;
44
+ /**
45
+ * Run an LLM-as-judge evaluator on the trajectory.
46
+ * Requires `toolsCalled` in the same expect array.
47
+ * Uses the globally configured evaluator model.
48
+ */
49
+ declare function llmJudge(): Expectation;
50
+ /** Assert the agent made zero tool calls. */
51
+ declare function noTools(): Expectation;
52
+ /**
53
+ * Assert the response is in the given language (ISO 639-1 code).
54
+ * Uses the globally configured evaluator model for language detection.
55
+ * @param code - ISO 639-1 language code (e.g. 'en', 'tr', 'de').
56
+ */
57
+ declare function respondsInLanguage(code: string): Expectation;
58
+ /** Assert the response contains all given strings. */
59
+ declare function contains(strings: string[]): Expectation;
60
+ /** Assert the response does not contain any of the given strings. */
61
+ declare function notContains(strings: string[]): Expectation;
62
+
63
+ declare function human(content: string): {
64
+ role: "human";
65
+ content: string;
66
+ };
67
+ declare function ai(content: string, toolCalls?: string[]): {
68
+ toolCalls?: string[] | undefined;
69
+ role: "ai";
70
+ content: string;
71
+ };
72
+ declare function toolResult(content: string): {
73
+ role: "tool";
74
+ content: string;
75
+ };
76
+ type Message = ReturnType<typeof human> | ReturnType<typeof ai> | ReturnType<typeof toolResult>;
77
+ interface ToolDef {
78
+ description: string;
79
+ schema?: Record<string, string>;
80
+ /** Auto-stringified if not a string or function. */
81
+ response: unknown | ((input: Record<string, unknown>, callCount: number) => string);
82
+ }
83
+ interface TestCase {
84
+ /** Test name. Defaults to the last human message content if omitted. */
85
+ name?: string;
86
+ messages: Message[];
87
+ systemPrompt?: string;
88
+ /** Override suite-level tools for this case. */
89
+ tools?: Record<string, ToolDef>;
90
+ expect: Expectation[];
91
+ }
92
+ type TargetFn = (inputs: {
93
+ systemPrompt?: string;
94
+ messages: Message[];
95
+ tools: MockToolDef[];
96
+ }) => Promise<{
97
+ messages: BaseMessage[];
98
+ }>;
99
+ interface SuiteConfig {
100
+ /** Custom target function, or model string override. Auto-created from global config if omitted. */
101
+ target?: TargetFn | string;
102
+ /** System prompt for all cases in this suite. Overrides the global prompt; can be overridden per-case. */
103
+ systemPrompt?: string;
104
+ tools: Record<string, ToolDef>;
105
+ cases: TestCase[];
106
+ }
107
+ declare function defineSuite(name: string, config: SuiteConfig): void;
108
+
109
+ export { type EvalConfig, type Expectation, type SuiteConfig, type TestCase, type ToolDef, ai, configureEvals, contains, defineSuite, human, llmJudge, noTools, notContains, respondsInLanguage, toolResult, toolsCalled };