@haikeilabs/agentware 0.1.0 → 0.1.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 (54) hide show
  1. package/dist/executor/agent_loop.d.ts +41 -0
  2. package/dist/executor/agent_loop.d.ts.map +1 -0
  3. package/dist/executor/agent_loop.js +206 -0
  4. package/dist/executor/index.d.ts +2 -1
  5. package/dist/executor/index.d.ts.map +1 -1
  6. package/dist/executor/index.js +2 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -0
  10. package/dist/llm/backend.d.ts +7 -0
  11. package/dist/llm/backend.d.ts.map +1 -1
  12. package/dist/llm/index.d.ts +2 -1
  13. package/dist/llm/index.d.ts.map +1 -1
  14. package/dist/llm/index.js +1 -0
  15. package/dist/llm/openai_backend.d.ts +51 -0
  16. package/dist/llm/openai_backend.d.ts.map +1 -0
  17. package/dist/llm/openai_backend.js +203 -0
  18. package/dist/llm/response.d.ts +5 -0
  19. package/dist/llm/response.d.ts.map +1 -1
  20. package/dist/middleware/guardrails/response_validator.d.ts +1 -1
  21. package/dist/middleware/guardrails/response_validator.d.ts.map +1 -1
  22. package/dist/middleware/guardrails/response_validator.js +1 -1
  23. package/dist/middleware/index.d.ts +5 -0
  24. package/dist/middleware/index.d.ts.map +1 -1
  25. package/dist/middleware/index.js +5 -0
  26. package/dist/middleware/inference.d.ts +8 -0
  27. package/dist/middleware/inference.d.ts.map +1 -1
  28. package/dist/middleware/inference.js +73 -31
  29. package/dist/reasoning/adapter.d.ts +33 -0
  30. package/dist/reasoning/adapter.d.ts.map +1 -0
  31. package/dist/reasoning/adapter.js +365 -0
  32. package/dist/reasoning/errors.d.ts +28 -0
  33. package/dist/reasoning/errors.d.ts.map +1 -0
  34. package/dist/reasoning/errors.js +57 -0
  35. package/dist/reasoning/index.d.ts +6 -0
  36. package/dist/reasoning/index.d.ts.map +1 -0
  37. package/dist/reasoning/index.js +4 -0
  38. package/dist/reasoning/options.d.ts +18 -0
  39. package/dist/reasoning/options.d.ts.map +1 -0
  40. package/dist/reasoning/options.js +18 -0
  41. package/dist/reasoning/types.d.ts +44 -0
  42. package/dist/reasoning/types.d.ts.map +1 -0
  43. package/dist/reasoning/types.js +32 -0
  44. package/dist/toolformat/formatter.d.ts +3 -3
  45. package/dist/toolformat/formatter.d.ts.map +1 -1
  46. package/dist/tools/index.d.ts +2 -2
  47. package/dist/tools/index.d.ts.map +1 -1
  48. package/dist/tools/index.js +2 -2
  49. package/dist/tools/registry.d.ts +4 -4
  50. package/dist/tools/registry.d.ts.map +1 -1
  51. package/dist/tools/tool.d.ts +8 -1
  52. package/dist/tools/tool.d.ts.map +1 -1
  53. package/dist/tools/tool.js +7 -0
  54. package/package.json +10 -1
@@ -0,0 +1,41 @@
1
+ import type { AsyncBackend, Message, ToolDefinition } from "../llm/index.js";
2
+ import type { ToolRegistry } from "../tools/index.js";
3
+ import type { ResponseValidator } from "../middleware/guardrails/response_validator.js";
4
+ import { ErrorTracker, ErrorCategory } from "../middleware/guardrails/error_tracker.js";
5
+ import { StepEnforcer } from "../middleware/guardrails/step_enforcer.js";
6
+ export declare enum AgentTerminationReason {
7
+ COMPLETE = "complete",
8
+ MAX_ITERATIONS = "max_iterations",
9
+ NUDGES_EXHAUSTED = "nudges_exhausted",
10
+ ERROR = "error"
11
+ }
12
+ export interface AgentLoopConfig {
13
+ backend: AsyncBackend;
14
+ registry: ToolRegistry;
15
+ validator: ResponseValidator;
16
+ error_tracker?: ErrorTracker;
17
+ step_enforcer?: StepEnforcer;
18
+ max_iterations?: number;
19
+ max_nudges?: number;
20
+ require_tool_call?: boolean;
21
+ }
22
+ export interface AgentResult {
23
+ final_response: string;
24
+ iterations: number;
25
+ tool_calls_made: number;
26
+ nudges: number;
27
+ termination_reason: AgentTerminationReason;
28
+ conversation: Message[];
29
+ }
30
+ export declare function registryToolDefinitions(registry: ToolRegistry): ToolDefinition[];
31
+ export declare function categorizeError(message: string): ErrorCategory;
32
+ export declare class AgentLoop {
33
+ private readonly config;
34
+ private readonly maxIterations;
35
+ private readonly maxNudges;
36
+ constructor(config: AgentLoopConfig);
37
+ run(system_prompt: string, user_message: string, history?: Message[], session_id?: string): Promise<AgentResult>;
38
+ private validate;
39
+ private finish;
40
+ }
41
+ //# sourceMappingURL=agent_loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_loop.d.ts","sourceRoot":"","sources":["../../src/executor/agent_loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,YAAY,EACZ,aAAa,EACd,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAQzE,oBAAY,sBAAsB;IAChC,QAAQ,aAAa;IACrB,cAAc,mBAAmB;IACjC,gBAAgB,qBAAqB;IACrC,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,YAAY,CAAC;IACvB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,sBAAsB,CAAC;IAC3C,YAAY,EAAE,OAAO,EAAE,CAAC;CACzB;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,YAAY,GACrB,cAAc,EAAE,CASlB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CA0B9D;AAiBD,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,MAAM,EAAE,eAAe;IAU7B,GAAG,CACP,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,OAAO,EAAO,EACvB,UAAU,GAAE,MAAW,GACtB,OAAO,CAAC,WAAW,CAAC;IAsLvB,OAAO,CAAC,QAAQ;IAiBhB,OAAO,CAAC,MAAM;CAiBf"}
@@ -0,0 +1,206 @@
1
+ import { Role } from "../llm/index.js";
2
+ import { executeTool, Result } from "../tools/index.js";
3
+ import { ErrorCategory, } from "../middleware/guardrails/error_tracker.js";
4
+ import { NudgeKind, stepNudge, } from "../middleware/guardrails/nudge.js";
5
+ import { MessageType } from "../middleware/types.js";
6
+ export var AgentTerminationReason;
7
+ (function (AgentTerminationReason) {
8
+ AgentTerminationReason["COMPLETE"] = "complete";
9
+ AgentTerminationReason["MAX_ITERATIONS"] = "max_iterations";
10
+ AgentTerminationReason["NUDGES_EXHAUSTED"] = "nudges_exhausted";
11
+ AgentTerminationReason["ERROR"] = "error";
12
+ })(AgentTerminationReason || (AgentTerminationReason = {}));
13
+ export function registryToolDefinitions(registry) {
14
+ return registry.all().map((tool) => ({
15
+ name: tool.name,
16
+ description: tool.description,
17
+ input_schema: "inputSchema" in tool
18
+ ? tool.inputSchema()
19
+ : {},
20
+ }));
21
+ }
22
+ export function categorizeError(message) {
23
+ const m = message.toLowerCase();
24
+ if (m.includes("timeout") || m.includes("timed out")) {
25
+ return ErrorCategory.TIMEOUT;
26
+ }
27
+ if (m.includes("not found") || m.includes("unknown tool")) {
28
+ return ErrorCategory.NOT_FOUND;
29
+ }
30
+ if (m.includes("invalid arg") ||
31
+ m.includes("schema") ||
32
+ m.includes("validation")) {
33
+ return ErrorCategory.INVALID_ARGS;
34
+ }
35
+ if (m.includes("permission") ||
36
+ m.includes("denied") ||
37
+ m.includes("forbidden")) {
38
+ return ErrorCategory.PERMISSION;
39
+ }
40
+ if (m.includes("rate limit") || m.includes("rate_limit")) {
41
+ return ErrorCategory.RATE_LIMIT;
42
+ }
43
+ return ErrorCategory.UNKNOWN;
44
+ }
45
+ function nudgeMetaType(kind) {
46
+ switch (kind) {
47
+ case NudgeKind.STEP:
48
+ return MessageType.STEP_NUDGE;
49
+ case NudgeKind.PREREQUISITE:
50
+ return MessageType.PREREQUISITE_NUDGE;
51
+ default:
52
+ return MessageType.RETRY_NUDGE;
53
+ }
54
+ }
55
+ function toError(err) {
56
+ return err instanceof Error ? err : new Error(String(err));
57
+ }
58
+ export class AgentLoop {
59
+ config;
60
+ maxIterations;
61
+ maxNudges;
62
+ constructor(config) {
63
+ this.config = config;
64
+ this.maxIterations =
65
+ config.max_iterations && config.max_iterations > 0
66
+ ? config.max_iterations
67
+ : 20;
68
+ this.maxNudges =
69
+ config.max_nudges && config.max_nudges > 0 ? config.max_nudges : 3;
70
+ }
71
+ async run(system_prompt, user_message, history = [], session_id = "") {
72
+ const conversation = [...history];
73
+ conversation.push({ role: Role.SYSTEM, content: system_prompt });
74
+ conversation.push({ role: Role.USER, content: user_message });
75
+ const toolDefs = registryToolDefinitions(this.config.registry);
76
+ let iterations = 0;
77
+ let toolCallsMade = 0;
78
+ let nudges = 0;
79
+ let finalResponse = "";
80
+ while (iterations < this.maxIterations) {
81
+ iterations++;
82
+ let resp;
83
+ try {
84
+ resp = await this.config.backend.complete(conversation, toolDefs);
85
+ }
86
+ catch (err) {
87
+ this.config.error_tracker?.recordError(session_id, "", {}, toError(err), ErrorCategory.UNKNOWN);
88
+ return this.finish(finalResponse, iterations, toolCallsMade, nudges, AgentTerminationReason.ERROR, conversation);
89
+ }
90
+ const validation = this.validate(resp);
91
+ if (validation.needsRetry) {
92
+ if (nudges >= this.maxNudges) {
93
+ return this.finish(resp.content, iterations, toolCallsMade, nudges, AgentTerminationReason.NUDGES_EXHAUSTED, conversation);
94
+ }
95
+ nudges++;
96
+ conversation.push({
97
+ role: Role.ASSISTANT,
98
+ content: resp.content,
99
+ meta: { type: MessageType.TEXT_RESPONSE },
100
+ });
101
+ if (validation.nudge) {
102
+ conversation.push({
103
+ role: Role.USER,
104
+ content: validation.nudge.content,
105
+ meta: { type: nudgeMetaType(validation.nudge.kind) },
106
+ });
107
+ }
108
+ continue;
109
+ }
110
+ if (validation.toolCalls.length === 0) {
111
+ finalResponse = resp.content;
112
+ return this.finish(finalResponse, iterations, toolCallsMade, nudges, AgentTerminationReason.COMPLETE, conversation);
113
+ }
114
+ let stepNudged = false;
115
+ for (const call of validation.toolCalls) {
116
+ if (this.config.step_enforcer) {
117
+ const [allowed, missing] = this.config.step_enforcer.canExecute(session_id, call.tool);
118
+ if (!allowed) {
119
+ if (nudges >= this.maxNudges) {
120
+ return this.finish(resp.content, iterations, toolCallsMade, nudges, AgentTerminationReason.NUDGES_EXHAUSTED, conversation);
121
+ }
122
+ nudges++;
123
+ stepNudged = true;
124
+ const nudge = stepNudge(call.tool, missing, Math.min(3, nudges));
125
+ conversation.push({
126
+ role: Role.USER,
127
+ content: nudge.content,
128
+ meta: { type: MessageType.STEP_NUDGE },
129
+ });
130
+ continue;
131
+ }
132
+ }
133
+ if (this.config.error_tracker &&
134
+ this.config.error_tracker.shouldBlockTool(session_id, call.tool)) {
135
+ conversation.push({
136
+ role: Role.TOOL,
137
+ content: `Tool ${call.tool} error: blocked after repeated errors`,
138
+ meta: { type: MessageType.TOOL_RESULT },
139
+ });
140
+ continue;
141
+ }
142
+ const tool = this.config.registry.get(call.tool);
143
+ if (!tool) {
144
+ conversation.push({
145
+ role: Role.TOOL,
146
+ content: `Tool ${call.tool} error: unknown tool`,
147
+ meta: { type: MessageType.TOOL_RESULT },
148
+ });
149
+ continue;
150
+ }
151
+ toolCallsMade++;
152
+ let result;
153
+ try {
154
+ result = await executeTool(tool, call.args);
155
+ }
156
+ catch (err) {
157
+ result = new Result(false, null, toError(err).message);
158
+ }
159
+ if (result.success) {
160
+ this.config.step_enforcer?.markStepComplete(session_id, call.tool);
161
+ conversation.push({
162
+ role: Role.TOOL,
163
+ content: `Tool ${call.tool} result: ${JSON.stringify(result.data)}`,
164
+ meta: { type: MessageType.TOOL_RESULT },
165
+ });
166
+ }
167
+ else {
168
+ const message = result.error ?? "tool failed";
169
+ this.config.error_tracker?.recordError(session_id, call.tool, call.args, new Error(message), categorizeError(message));
170
+ conversation.push({
171
+ role: Role.TOOL,
172
+ content: `Tool ${call.tool} error: ${message}`,
173
+ meta: { type: MessageType.TOOL_RESULT },
174
+ });
175
+ }
176
+ }
177
+ if (stepNudged) {
178
+ continue;
179
+ }
180
+ }
181
+ return this.finish(finalResponse, iterations, toolCallsMade, nudges, AgentTerminationReason.MAX_ITERATIONS, conversation);
182
+ }
183
+ validate(resp) {
184
+ if (resp.tool_calls.length > 0) {
185
+ return this.config.validator.validateToolCalls(resp.tool_calls.map((tc) => ({ tool: tc.name, args: tc.arguments })));
186
+ }
187
+ const textValidation = this.config.validator.validateTextResponse(resp.content);
188
+ if (textValidation.toolCalls.length > 0) {
189
+ return textValidation;
190
+ }
191
+ if (this.config.require_tool_call) {
192
+ return textValidation;
193
+ }
194
+ return { toolCalls: [], nudge: null, needsRetry: false };
195
+ }
196
+ finish(finalResponse, iterations, toolCallsMade, nudges, termination, conversation) {
197
+ return {
198
+ final_response: finalResponse,
199
+ iterations,
200
+ tool_calls_made: toolCallsMade,
201
+ nudges,
202
+ termination_reason: termination,
203
+ conversation,
204
+ };
205
+ }
206
+ }
@@ -1,2 +1,3 @@
1
- export { Executor, ExecuteRequest, ExecuteResult, TerminationReason, InferenceExecutor, InferenceExecutorConfig } from "./executor.js";
1
+ export { Executor, ExecuteRequest, ExecuteResult, TerminationReason, InferenceExecutor, InferenceExecutorConfig, } from "./executor.js";
2
+ export { AgentLoop, AgentLoopConfig, AgentResult, AgentTerminationReason, registryToolDefinitions, categorizeError, } from "./agent_loop.js";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/executor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/executor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,GAChB,MAAM,iBAAiB,CAAC"}
@@ -1 +1,2 @@
1
- export { TerminationReason, InferenceExecutor } from "./executor.js";
1
+ export { TerminationReason, InferenceExecutor, } from "./executor.js";
2
+ export { AgentLoop, AgentTerminationReason, registryToolDefinitions, categorizeError, } from "./agent_loop.js";
package/dist/index.d.ts CHANGED
@@ -7,4 +7,5 @@ export * from "./llmcontext/index.js";
7
7
  export * from "./prompts/index.js";
8
8
  export * from "./toolformat/index.js";
9
9
  export * from "./memory/index.js";
10
+ export * from "./reasoning/index.js";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -7,3 +7,4 @@ export * from "./llmcontext/index.js";
7
7
  export * from "./prompts/index.js";
8
8
  export * from "./toolformat/index.js";
9
9
  export * from "./memory/index.js";
10
+ export * from "./reasoning/index.js";
@@ -1,4 +1,5 @@
1
1
  import type { Message } from "./request.js";
2
+ import type { ToolDefinition } from "./request.js";
2
3
  import type { Response } from "./response.js";
3
4
  export interface Backend {
4
5
  complete(messages: Message[]): Response;
@@ -6,4 +7,10 @@ export interface Backend {
6
7
  modelName(): string;
7
8
  contextWindowSize(): number;
8
9
  }
10
+ export interface AsyncBackend {
11
+ complete(messages: Message[], tools?: ToolDefinition[]): Promise<Response>;
12
+ supportsNativeToolCalling(): boolean;
13
+ modelName(): string;
14
+ contextWindowSize(): number;
15
+ }
9
16
  //# sourceMappingURL=backend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/llm/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACxC,yBAAyB,IAAI,OAAO,CAAC;IACrC,SAAS,IAAI,MAAM,CAAC;IACpB,iBAAiB,IAAI,MAAM,CAAC;CAC7B"}
1
+ {"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/llm/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;IACxC,yBAAyB,IAAI,OAAO,CAAC;IACrC,SAAS,IAAI,MAAM,CAAC;IACpB,iBAAiB,IAAI,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3E,yBAAyB,IAAI,OAAO,CAAC;IACrC,SAAS,IAAI,MAAM,CAAC;IACpB,iBAAiB,IAAI,MAAM,CAAC;CAC7B"}
@@ -1,4 +1,5 @@
1
- export { Backend } from "./backend.js";
1
+ export { Backend, AsyncBackend } from "./backend.js";
2
2
  export { Message, Role, Request, ToolDefinition } from "./request.js";
3
3
  export { Response, ToolCall, TokenUsage } from "./response.js";
4
+ export { OpenAIBackend, OpenAIBackendConfig, OpenAIError, FetchFn, FetchLikeInit, FetchLikeResponse, parseToolArguments, } from "./openai_backend.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/llm/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { Role } from "./request.js";
2
+ export { OpenAIBackend, OpenAIError, parseToolArguments, } from "./openai_backend.js";
@@ -0,0 +1,51 @@
1
+ import type { Message, ToolDefinition } from "./request.js";
2
+ import type { Response } from "./response.js";
3
+ import type { AsyncBackend } from "./backend.js";
4
+ export interface FetchLikeResponse {
5
+ ok: boolean;
6
+ status: number;
7
+ text(): Promise<string>;
8
+ }
9
+ export interface FetchLikeInit {
10
+ method?: string;
11
+ headers?: Record<string, string>;
12
+ body?: string;
13
+ signal?: AbortSignal;
14
+ }
15
+ export type FetchFn = (url: string, init?: FetchLikeInit) => Promise<FetchLikeResponse>;
16
+ export declare class OpenAIError extends Error {
17
+ readonly status?: number;
18
+ constructor(message: string, status?: number);
19
+ }
20
+ export interface OpenAIBackendConfig {
21
+ model: string;
22
+ baseUrl?: string;
23
+ apiKey?: string;
24
+ fetchFn?: FetchFn;
25
+ timeoutMs?: number;
26
+ maxResponseBytes?: number;
27
+ maxToolArgBytes?: number;
28
+ contextWindowSize?: number;
29
+ temperature?: number;
30
+ maxTokens?: number;
31
+ }
32
+ export declare function parseToolArguments(raw: string | null | undefined, maxBytes: number): Record<string, unknown>;
33
+ export declare class OpenAIBackend implements AsyncBackend {
34
+ private readonly model;
35
+ private readonly baseUrl;
36
+ private readonly apiKey;
37
+ private readonly fetchFn;
38
+ private readonly timeoutMs;
39
+ private readonly maxResponseBytes;
40
+ private readonly maxToolArgBytes;
41
+ private readonly contextWindow;
42
+ private readonly temperature?;
43
+ private readonly maxTokens?;
44
+ constructor(config: OpenAIBackendConfig);
45
+ complete(messages: Message[], tools?: ToolDefinition[]): Promise<Response>;
46
+ private parseCompletion;
47
+ supportsNativeToolCalling(): boolean;
48
+ modelName(): string;
49
+ contextWindowSize(): number;
50
+ }
51
+ //# sourceMappingURL=openai_backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai_backend.d.ts","sourceRoot":"","sources":["../../src/llm/openai_backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,KAAK,EAAE,QAAQ,EAAwB,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,OAAO,GAAG,CACpB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,aAAa,KACjB,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEhC,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAK7C;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAwCD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczB;AAkDD,qBAAa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAExB,MAAM,EAAE,mBAAmB;IAajC,QAAQ,CACZ,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,CAAC,EAAE,cAAc,EAAE,GACvB,OAAO,CAAC,QAAQ,CAAC;IA2EpB,OAAO,CAAC,eAAe;IA2CvB,yBAAyB,IAAI,OAAO;IAIpC,SAAS,IAAI,MAAM;IAInB,iBAAiB,IAAI,MAAM;CAG5B"}
@@ -0,0 +1,203 @@
1
+ import { Role } from "./request.js";
2
+ export class OpenAIError extends Error {
3
+ status;
4
+ constructor(message, status) {
5
+ super(message);
6
+ this.name = "OpenAIError";
7
+ this.status = status;
8
+ }
9
+ }
10
+ const DEFAULT_BASE_URL = "https://api.openai.com/v1";
11
+ const DEFAULT_TIMEOUT_MS = 60_000;
12
+ const DEFAULT_MAX_RESPONSE_BYTES = 1_048_576;
13
+ const DEFAULT_MAX_TOOL_ARG_BYTES = 65_536;
14
+ const DEFAULT_CONTEXT_WINDOW = 128_000;
15
+ const MAX_ERROR_DETAIL_CHARS = 512;
16
+ export function parseToolArguments(raw, maxBytes) {
17
+ if (!raw) {
18
+ return {};
19
+ }
20
+ const bounded = raw.length > maxBytes ? raw.slice(0, maxBytes) : raw;
21
+ try {
22
+ const parsed = JSON.parse(bounded);
23
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
24
+ return parsed;
25
+ }
26
+ }
27
+ catch {
28
+ // fall through to raw fallback
29
+ }
30
+ return { _raw: bounded };
31
+ }
32
+ function toOpenAIMessage(message) {
33
+ switch (message.role) {
34
+ case Role.TOOL:
35
+ return {
36
+ role: "tool",
37
+ tool_call_id: message.tool_call_id ?? "",
38
+ content: message.content,
39
+ };
40
+ case Role.ASSISTANT:
41
+ if (message.tool_calls && message.tool_calls.length > 0) {
42
+ return {
43
+ role: "assistant",
44
+ content: message.content || null,
45
+ tool_calls: message.tool_calls.map((tc) => ({
46
+ id: tc.id,
47
+ type: "function",
48
+ function: { name: tc.name, arguments: JSON.stringify(tc.arguments) },
49
+ })),
50
+ };
51
+ }
52
+ return { role: "assistant", content: message.content };
53
+ default:
54
+ return { role: message.role, content: message.content };
55
+ }
56
+ }
57
+ function toOpenAITool(tool) {
58
+ return {
59
+ type: "function",
60
+ function: {
61
+ name: tool.name,
62
+ description: tool.description,
63
+ parameters: tool.input_schema,
64
+ },
65
+ };
66
+ }
67
+ function truncateDetail(text) {
68
+ if (text.length <= MAX_ERROR_DETAIL_CHARS) {
69
+ return text;
70
+ }
71
+ return text.slice(0, MAX_ERROR_DETAIL_CHARS) + "...";
72
+ }
73
+ function toError(err) {
74
+ return err instanceof Error ? err : new Error(String(err));
75
+ }
76
+ export class OpenAIBackend {
77
+ model;
78
+ baseUrl;
79
+ apiKey;
80
+ fetchFn;
81
+ timeoutMs;
82
+ maxResponseBytes;
83
+ maxToolArgBytes;
84
+ contextWindow;
85
+ temperature;
86
+ maxTokens;
87
+ constructor(config) {
88
+ this.model = config.model;
89
+ this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
90
+ this.apiKey = config.apiKey ?? "";
91
+ this.fetchFn = config.fetchFn ?? fetch;
92
+ this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
93
+ this.maxResponseBytes = config.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;
94
+ this.maxToolArgBytes = config.maxToolArgBytes ?? DEFAULT_MAX_TOOL_ARG_BYTES;
95
+ this.contextWindow = config.contextWindowSize ?? DEFAULT_CONTEXT_WINDOW;
96
+ this.temperature = config.temperature;
97
+ this.maxTokens = config.maxTokens;
98
+ }
99
+ async complete(messages, tools) {
100
+ const payload = {
101
+ model: this.model,
102
+ messages: messages.map(toOpenAIMessage),
103
+ };
104
+ if (this.temperature !== undefined) {
105
+ payload.temperature = this.temperature;
106
+ }
107
+ if (this.maxTokens !== undefined) {
108
+ payload.max_tokens = this.maxTokens;
109
+ }
110
+ if (tools && tools.length > 0) {
111
+ payload.tools = tools.map(toOpenAITool);
112
+ payload.tool_choice = "auto";
113
+ }
114
+ const headers = {
115
+ "Content-Type": "application/json",
116
+ };
117
+ if (this.apiKey) {
118
+ headers.Authorization = `Bearer ${this.apiKey}`;
119
+ }
120
+ const controller = new AbortController();
121
+ const timer = setTimeout(() => controller.abort(), this.timeoutMs);
122
+ try {
123
+ let res;
124
+ try {
125
+ res = await this.fetchFn(`${this.baseUrl}/chat/completions`, {
126
+ method: "POST",
127
+ headers,
128
+ body: JSON.stringify(payload),
129
+ signal: controller.signal,
130
+ });
131
+ }
132
+ catch (err) {
133
+ if (controller.signal.aborted ||
134
+ (err instanceof Error && err.name === "AbortError")) {
135
+ throw new OpenAIError(`request timed out after ${this.timeoutMs}ms`);
136
+ }
137
+ throw new OpenAIError(`request failed: ${toError(err).message}`);
138
+ }
139
+ const text = await res.text();
140
+ if (text.length > this.maxResponseBytes) {
141
+ throw new OpenAIError(`response body exceeds limit of ${this.maxResponseBytes} bytes`);
142
+ }
143
+ if (!res.ok) {
144
+ throw new OpenAIError(`HTTP ${res.status}: ${truncateDetail(text)}`, res.status);
145
+ }
146
+ let data;
147
+ try {
148
+ data = JSON.parse(text);
149
+ }
150
+ catch {
151
+ throw new OpenAIError("malformed JSON in response body");
152
+ }
153
+ return this.parseCompletion(data);
154
+ }
155
+ finally {
156
+ clearTimeout(timer);
157
+ }
158
+ }
159
+ parseCompletion(data) {
160
+ const completion = data;
161
+ const choice = completion.choices?.[0];
162
+ const message = choice?.message;
163
+ if (!message) {
164
+ throw new OpenAIError("unexpected response shape: missing choices[0].message");
165
+ }
166
+ const toolCalls = [];
167
+ if (message.tool_calls) {
168
+ for (let i = 0; i < message.tool_calls.length; i++) {
169
+ const tc = message.tool_calls[i];
170
+ const name = tc.function?.name;
171
+ if (!name) {
172
+ continue;
173
+ }
174
+ toolCalls.push({
175
+ id: tc.id ?? `call_${i}`,
176
+ name,
177
+ arguments: parseToolArguments(tc.function?.arguments, this.maxToolArgBytes),
178
+ });
179
+ }
180
+ }
181
+ const usage = {
182
+ prompt_tokens: completion.usage?.prompt_tokens ?? 0,
183
+ completion_tokens: completion.usage?.completion_tokens ?? 0,
184
+ total_tokens: completion.usage?.total_tokens ?? 0,
185
+ };
186
+ return {
187
+ content: message.content ?? "",
188
+ reasoning: message.reasoning_content ?? "",
189
+ tool_calls: toolCalls,
190
+ finish_reason: choice?.finish_reason ?? "",
191
+ usage_tokens: usage,
192
+ };
193
+ }
194
+ supportsNativeToolCalling() {
195
+ return true;
196
+ }
197
+ modelName() {
198
+ return this.model;
199
+ }
200
+ contextWindowSize() {
201
+ return this.contextWindow;
202
+ }
203
+ }
@@ -10,6 +10,11 @@ export interface TokenUsage {
10
10
  }
11
11
  export interface Response {
12
12
  content: string;
13
+ /** Raw reasoning returned on a separate channel (e.g. reasoning_content for
14
+ * DeepSeek-style models). Never written into content, never returned to the
15
+ * end user, and never recorded on a default audit record; consumers
16
+ * normalize it with the reasoning adapter. */
17
+ reasoning: string;
13
18
  tool_calls: ToolCall[];
14
19
  finish_reason: string;
15
20
  usage_tokens: TokenUsage;
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/llm/response.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,UAAU,CAAC;CAC1B"}
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/llm/response.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB;;;kDAG8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,UAAU,CAAC;CAC1B"}
@@ -1,4 +1,4 @@
1
- import { Nudge } from "./nudge";
1
+ import { Nudge } from "./nudge.js";
2
2
  export interface ToolCall {
3
3
  tool: string;
4
4
  args: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"response_validator.d.ts","sourceRoot":"","sources":["../../../src/middleware/guardrails/response_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgC,MAAM,SAAS,CAAC;AAE9D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,YAAY,CAAsD;IAE1E,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,mBAAmB,CAAS;gBAGlC,SAAS,EAAE,MAAM,EAAE,EACnB,aAAa,GAAE,OAAc,EAC7B,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,KAAK;IAapE,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAYxD,iBAAiB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,gBAAgB;IAoB1D,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,uBAAuB;CAGhC"}
1
+ {"version":3,"file":"response_validator.d.ts","sourceRoot":"","sources":["../../../src/middleware/guardrails/response_validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgC,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,YAAY,CAAsD;IAE1E,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,mBAAmB,CAAS;gBAGlC,SAAS,EAAE,MAAM,EAAE,EACnB,aAAa,GAAE,OAAc,EAC7B,YAAY,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,KAAK;IAapE,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAYxD,iBAAiB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,gBAAgB;IAoB1D,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,uBAAuB;CAGhC"}
@@ -1,4 +1,4 @@
1
- import { retryNudge, unknownToolNudge } from "./nudge";
1
+ import { retryNudge, unknownToolNudge } from "./nudge.js";
2
2
  export class ResponseValidator {
3
3
  toolNames;
4
4
  rescueEnabled;
@@ -2,4 +2,9 @@ export { MiddlewareImpl, Middleware, ToolExecutor } from "./middleware.js";
2
2
  export { Action, CallerContext, Decision, MessageType, MessageMeta } from "./types.js";
3
3
  export { PolicyEvaluator, Policy, Rule, Condition, Operator, SimplePolicyEvaluator } from "./policy.js";
4
4
  export { Auditor, AuditRecord, InMemoryAuditor, AuditFilter } from "./audit.js";
5
+ export { runInference, InferenceConfig, InferenceResult, RetriesExhaustedError, } from "./inference.js";
6
+ export { ResponseValidator, ValidationResult, ToolCall as ValidatedToolCall, } from "./guardrails/response_validator.js";
7
+ export { Nudge, NudgeKind, retryNudge, unknownToolNudge, stepNudge, prerequisiteNudge, } from "./guardrails/nudge.js";
8
+ export { ErrorTracker, ErrorCategory, ToolError, } from "./guardrails/error_tracker.js";
9
+ export { StepEnforcer, StepNotAllowedError } from "./guardrails/step_enforcer.js";
5
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,YAAY,EACZ,eAAe,EACf,eAAe,EACf,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,IAAI,iBAAiB,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,GACV,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC"}
@@ -2,3 +2,8 @@ export { MiddlewareImpl } from "./middleware.js";
2
2
  export { Action, MessageType } from "./types.js";
3
3
  export { Operator, SimplePolicyEvaluator } from "./policy.js";
4
4
  export { InMemoryAuditor } from "./audit.js";
5
+ export { runInference, RetriesExhaustedError, } from "./inference.js";
6
+ export { ResponseValidator, } from "./guardrails/response_validator.js";
7
+ export { NudgeKind, retryNudge, unknownToolNudge, stepNudge, prerequisiteNudge, } from "./guardrails/nudge.js";
8
+ export { ErrorTracker, ErrorCategory, } from "./guardrails/error_tracker.js";
9
+ export { StepEnforcer, StepNotAllowedError } from "./guardrails/step_enforcer.js";