incantx 0.1.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,7 @@
1
+ import type { ChatAgent } from "./types";
2
+ export type OpenAIChatAgentOptions = {
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ defaultModel?: string;
6
+ };
7
+ export declare function createOpenAIChatAgent(options?: OpenAIChatAgentOptions): ChatAgent;
@@ -0,0 +1,48 @@
1
+ export type ToolCall = {
2
+ id: string;
3
+ type: "function";
4
+ function: {
5
+ name: string;
6
+ arguments: string;
7
+ };
8
+ };
9
+ export type SystemMessage = {
10
+ role: "system";
11
+ content: string;
12
+ };
13
+ export type UserMessage = {
14
+ role: "user";
15
+ content: string;
16
+ };
17
+ export type AssistantMessage = {
18
+ role: "assistant";
19
+ content: string;
20
+ tool_calls?: ToolCall[];
21
+ };
22
+ export type ToolMessage = {
23
+ role: "tool";
24
+ tool_call_id: string;
25
+ name: string;
26
+ content: string;
27
+ };
28
+ export type ChatMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
29
+ export type ToolDefinition = {
30
+ type: "function";
31
+ function: {
32
+ name: string;
33
+ description?: string;
34
+ parameters?: unknown;
35
+ };
36
+ };
37
+ export type ChatAgentRequest = {
38
+ model?: string;
39
+ messages: ChatMessage[];
40
+ tools?: ToolDefinition[];
41
+ tool_choice?: "auto" | "none" | {
42
+ type: "function";
43
+ function: {
44
+ name: string;
45
+ };
46
+ };
47
+ };
48
+ export type ChatAgent = (req: ChatAgentRequest) => Promise<AssistantMessage>;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,2 @@
1
+ import type { FixtureFile } from "./types";
2
+ export declare function loadFixtureFile(yamlText: string, env?: Record<string, string | undefined>): FixtureFile;
@@ -0,0 +1,31 @@
1
+ import type { ChatMessage } from "../agent/types";
2
+ export type FixtureFile = {
3
+ agent?: AgentSpec;
4
+ fixtures: Fixture[];
5
+ };
6
+ export type Fixture = {
7
+ id: string;
8
+ agent?: AgentSpec;
9
+ history?: ChatMessage[];
10
+ input: string;
11
+ expect?: FixtureExpectation;
12
+ };
13
+ export type AgentSpec = {
14
+ type?: "subprocess";
15
+ command: string[];
16
+ cwd?: string;
17
+ env?: Record<string, string>;
18
+ timeout_ms?: number;
19
+ };
20
+ export type FixtureExpectation = {
21
+ assistant?: AssistantExpectation;
22
+ tool_calls_match?: "contains" | "exact";
23
+ tool_calls?: ToolCallExpectation[];
24
+ };
25
+ export type AssistantExpectation = {
26
+ llm: string;
27
+ };
28
+ export type ToolCallExpectation = {
29
+ name: string;
30
+ arguments?: Record<string, unknown>;
31
+ };
@@ -0,0 +1,11 @@
1
+ import type { AssistantMessage } from "../agent/types";
2
+ import type { ExpectationResult } from "../runner/expectations";
3
+ export type OpenAIJudgeOptions = {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ model?: string;
7
+ };
8
+ export declare function createOpenAIJudge(options: OpenAIJudgeOptions): ({ expectation, message }: {
9
+ expectation: string;
10
+ message: AssistantMessage;
11
+ }) => Promise<ExpectationResult>;
@@ -0,0 +1 @@
1
+ export declare function deepPartialMatch(expected: unknown, actual: unknown): boolean;
@@ -0,0 +1,16 @@
1
+ import type { AssistantMessage } from "../agent/types";
2
+ import type { FixtureExpectation } from "../fixture/types";
3
+ export type ExpectationResult = {
4
+ status: "pass";
5
+ } | {
6
+ status: "fail";
7
+ reason: string;
8
+ } | {
9
+ status: "skip";
10
+ reason: string;
11
+ };
12
+ export type Judge = (args: {
13
+ expectation: string;
14
+ message: AssistantMessage;
15
+ }) => Promise<ExpectationResult>;
16
+ export declare function evaluateExpectations(expect: FixtureExpectation | undefined, message: AssistantMessage, judge: Judge | undefined): Promise<ExpectationResult>;
@@ -0,0 +1,17 @@
1
+ import type { AssistantMessage } from "../agent/types";
2
+ export type JudgeMode = "off" | "auto" | "on";
3
+ export type RunOptions = {
4
+ judgeMode?: JudgeMode;
5
+ judgeModel?: string;
6
+ };
7
+ export type FixtureResult = {
8
+ id: string;
9
+ status: "pass" | "fail" | "skip";
10
+ reason?: string;
11
+ message?: AssistantMessage;
12
+ };
13
+ export type FixtureFileResult = {
14
+ path: string;
15
+ results: FixtureResult[];
16
+ };
17
+ export declare function runFixtureFile(path: string, options?: RunOptions): Promise<FixtureFileResult>;
@@ -0,0 +1,3 @@
1
+ import type { AssistantMessage, ChatAgentRequest } from "../agent/types";
2
+ import type { AgentSpec } from "../fixture/types";
3
+ export declare function callSubprocessAgent(spec: AgentSpec, request: ChatAgentRequest): Promise<AssistantMessage>;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "incantx",
3
+ "version": "0.1.0",
4
+ "description": "YAML-driven agent conversation testing (history + tool calls) for Bun-based agents.",
5
+ "keywords": ["ai", "agent", "testing", "fixtures", "yaml", "bun"],
6
+ "license": "UNLICENSED",
7
+ "module": "dist/index.js",
8
+ "type": "module",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "engines": {
17
+ "bun": ">=1.3.0"
18
+ },
19
+ "packageManager": "bun@1.3.3",
20
+ "main": "dist/index.js",
21
+ "files": ["dist", "README.md"],
22
+ "bin": {
23
+ "incantx": "dist/cli.js"
24
+ },
25
+ "scripts": {
26
+ "cli": "bun src/cli.ts",
27
+ "test:fixtures": "bun src/cli.ts tests/fixtures --judge off",
28
+ "test": "bun run test:fixtures",
29
+ "clean": "bun -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true });\"",
30
+ "build:js": "bun build index.ts src/cli.ts --target=bun --format=esm --outdir dist --entry-naming=[name].[ext] --packages=external --sourcemap=external",
31
+ "build:types": "bunx tsc -p tsconfig.build.json",
32
+ "build": "bun run clean && bun run build:js && bun run build:types",
33
+ "typecheck": "bunx tsc -p tsconfig.json",
34
+ "prepack": "bun run build",
35
+ "prepublishOnly": "bun run build && bun run typecheck && bun run test:fixtures",
36
+ "pack:dry": "bun pm pack --dry-run",
37
+ "publish:dry": "bun publish --dry-run"
38
+ },
39
+ "devDependencies": {
40
+ "@types/bun": "latest",
41
+ "typescript": "^5.9.3"
42
+ },
43
+ "dependencies": {
44
+ "yaml": "^2.8.2"
45
+ }
46
+ }