@haikeilabs/agentware 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.
- package/README.md +45 -0
- package/dist/evals/cases/file_search.d.ts +4 -0
- package/dist/evals/cases/file_search.d.ts.map +1 -0
- package/dist/evals/cases/file_search.js +99 -0
- package/dist/evals/cases/general.d.ts +4 -0
- package/dist/evals/cases/general.d.ts.map +1 -0
- package/dist/evals/cases/general.js +113 -0
- package/dist/evals/index.d.ts +5 -0
- package/dist/evals/index.d.ts.map +1 -0
- package/dist/evals/index.js +4 -0
- package/dist/evals/main.d.ts +2 -0
- package/dist/evals/main.d.ts.map +1 -0
- package/dist/evals/main.js +109 -0
- package/dist/evals/models.d.ts +38 -0
- package/dist/evals/models.d.ts.map +1 -0
- package/dist/evals/models.js +69 -0
- package/dist/evals/runner.d.ts +40 -0
- package/dist/evals/runner.d.ts.map +1 -0
- package/dist/evals/runner.js +131 -0
- package/dist/executor/executor.d.ts +42 -0
- package/dist/executor/executor.d.ts.map +1 -0
- package/dist/executor/executor.js +63 -0
- package/dist/executor/index.d.ts +2 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/jobs/index.d.ts +3 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +2 -0
- package/dist/jobs/job.d.ts +18 -0
- package/dist/jobs/job.d.ts.map +1 -0
- package/dist/jobs/job.js +20 -0
- package/dist/jobs/manager.d.ts +23 -0
- package/dist/jobs/manager.d.ts.map +1 -0
- package/dist/jobs/manager.js +63 -0
- package/dist/llm/backend.d.ts +9 -0
- package/dist/llm/backend.d.ts.map +1 -0
- package/dist/llm/backend.js +1 -0
- package/dist/llm/index.d.ts +4 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/request.d.ts +28 -0
- package/dist/llm/request.d.ts.map +1 -0
- package/dist/llm/request.js +7 -0
- package/dist/llm/response.d.ts +17 -0
- package/dist/llm/response.d.ts.map +1 -0
- package/dist/llm/response.js +1 -0
- package/dist/llmcontext/context_window.d.ts +36 -0
- package/dist/llmcontext/context_window.d.ts.map +1 -0
- package/dist/llmcontext/context_window.js +115 -0
- package/dist/llmcontext/index.d.ts +4 -0
- package/dist/llmcontext/index.d.ts.map +1 -0
- package/dist/llmcontext/index.js +3 -0
- package/dist/llmcontext/manager.d.ts +27 -0
- package/dist/llmcontext/manager.d.ts.map +1 -0
- package/dist/llmcontext/manager.js +27 -0
- package/dist/llmcontext/strategies.d.ts +21 -0
- package/dist/llmcontext/strategies.d.ts.map +1 -0
- package/dist/llmcontext/strategies.js +180 -0
- package/dist/memory/client.d.ts +107 -0
- package/dist/memory/client.d.ts.map +1 -0
- package/dist/memory/client.js +210 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/tools.d.ts +22 -0
- package/dist/memory/tools.d.ts.map +1 -0
- package/dist/memory/tools.js +57 -0
- package/dist/middleware/audit.d.ts +27 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/audit.js +26 -0
- package/dist/middleware/guardrails/error_tracker.d.ts +34 -0
- package/dist/middleware/guardrails/error_tracker.d.ts.map +1 -0
- package/dist/middleware/guardrails/error_tracker.js +70 -0
- package/dist/middleware/guardrails/nudge.d.ts +17 -0
- package/dist/middleware/guardrails/nudge.d.ts.map +1 -0
- package/dist/middleware/guardrails/nudge.js +67 -0
- package/dist/middleware/guardrails/response_validator.d.ts +29 -0
- package/dist/middleware/guardrails/response_validator.d.ts.map +1 -0
- package/dist/middleware/guardrails/response_validator.js +145 -0
- package/dist/middleware/guardrails/step_enforcer.d.ts +20 -0
- package/dist/middleware/guardrails/step_enforcer.d.ts.map +1 -0
- package/dist/middleware/guardrails/step_enforcer.js +65 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +4 -0
- package/dist/middleware/inference.d.ts +28 -0
- package/dist/middleware/inference.d.ts.map +1 -0
- package/dist/middleware/inference.js +141 -0
- package/dist/middleware/middleware.d.ts +22 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +51 -0
- package/dist/middleware/policy.d.ts +46 -0
- package/dist/middleware/policy.d.ts.map +1 -0
- package/dist/middleware/policy.js +122 -0
- package/dist/middleware/types.d.ts +42 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/middleware/types.js +36 -0
- package/dist/prompts/generator.d.ts +10 -0
- package/dist/prompts/generator.d.ts.map +1 -0
- package/dist/prompts/generator.js +24 -0
- package/dist/prompts/index.d.ts +2 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +1 -0
- package/dist/toolformat/formatter.d.ts +20 -0
- package/dist/toolformat/formatter.d.ts.map +1 -0
- package/dist/toolformat/formatter.js +22 -0
- package/dist/toolformat/index.d.ts +2 -0
- package/dist/toolformat/index.d.ts.map +1 -0
- package/dist/toolformat/index.js +1 -0
- package/dist/tools/async.d.ts +42 -0
- package/dist/tools/async.d.ts.map +1 -0
- package/dist/tools/async.js +89 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/registry.d.ts +11 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +27 -0
- package/dist/tools/tool.d.ts +29 -0
- package/dist/tools/tool.d.ts.map +1 -0
- package/dist/tools/tool.js +31 -0
- package/package.json +49 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { ModelClient } from "./models.js";
|
|
4
|
+
export class EvalRunner {
|
|
5
|
+
baseURL;
|
|
6
|
+
maxTurns;
|
|
7
|
+
results = [];
|
|
8
|
+
constructor(baseURL, maxTurns = 10) {
|
|
9
|
+
this.baseURL = baseURL;
|
|
10
|
+
this.maxTurns = maxTurns;
|
|
11
|
+
}
|
|
12
|
+
passRate(model) {
|
|
13
|
+
const modelResults = this.results.filter((r) => r.model_name === model);
|
|
14
|
+
if (modelResults.length === 0)
|
|
15
|
+
return 0.0;
|
|
16
|
+
const passed = modelResults.filter((r) => r.success).length;
|
|
17
|
+
return passed / modelResults.length;
|
|
18
|
+
}
|
|
19
|
+
async runCase(case_, model, toolExecutor) {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
const client = new ModelClient(this.baseURL, model);
|
|
22
|
+
const messages = [
|
|
23
|
+
{ role: "system", content: case_.systemPrompt },
|
|
24
|
+
{ role: "user", content: case_.userMessage },
|
|
25
|
+
];
|
|
26
|
+
const toolCallsMade = [];
|
|
27
|
+
let turns = 0;
|
|
28
|
+
let error = "";
|
|
29
|
+
try {
|
|
30
|
+
while (turns < case_.maxTurns) {
|
|
31
|
+
const result = await client.complete(messages, case_.tools, 0.0, 2048);
|
|
32
|
+
turns++;
|
|
33
|
+
if (result.tool_calls.length === 0) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
for (const tc of result.tool_calls) {
|
|
37
|
+
toolCallsMade.push({
|
|
38
|
+
turn: turns,
|
|
39
|
+
name: tc.name,
|
|
40
|
+
arguments: tc.arguments,
|
|
41
|
+
});
|
|
42
|
+
if (tc.name === case_.expectedTool) {
|
|
43
|
+
const durationMs = Date.now() - start;
|
|
44
|
+
return {
|
|
45
|
+
case_name: case_.name,
|
|
46
|
+
model_name: model,
|
|
47
|
+
success: true,
|
|
48
|
+
turns: turns,
|
|
49
|
+
tool_calls: toolCallsMade,
|
|
50
|
+
error: "",
|
|
51
|
+
duration_ms: durationMs,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const args = JSON.parse(tc.arguments);
|
|
55
|
+
const toolResult = await toolExecutor(tc.name, args);
|
|
56
|
+
messages.push({
|
|
57
|
+
role: "assistant",
|
|
58
|
+
content: "",
|
|
59
|
+
});
|
|
60
|
+
messages.push({
|
|
61
|
+
role: "tool",
|
|
62
|
+
content: toolResult,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const durationMs = Date.now() - start;
|
|
67
|
+
error = `Expected tool '${case_.expectedTool}' not called in ${turns} turns`;
|
|
68
|
+
return {
|
|
69
|
+
case_name: case_.name,
|
|
70
|
+
model_name: model,
|
|
71
|
+
success: false,
|
|
72
|
+
turns: turns,
|
|
73
|
+
tool_calls: toolCallsMade,
|
|
74
|
+
error: error,
|
|
75
|
+
duration_ms: durationMs,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
const durationMs = Date.now() - start;
|
|
80
|
+
return {
|
|
81
|
+
case_name: case_.name,
|
|
82
|
+
model_name: model,
|
|
83
|
+
success: false,
|
|
84
|
+
turns: turns,
|
|
85
|
+
tool_calls: toolCallsMade,
|
|
86
|
+
error: e instanceof Error ? e.message : String(e),
|
|
87
|
+
duration_ms: durationMs,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async runEvals(cases, models, toolExecutor) {
|
|
92
|
+
const report = {
|
|
93
|
+
timestamp: new Date().toISOString(),
|
|
94
|
+
models: models,
|
|
95
|
+
results: [],
|
|
96
|
+
};
|
|
97
|
+
for (const model of models) {
|
|
98
|
+
console.log(`\n=== Testing model: ${model} ===`);
|
|
99
|
+
for (const case_ of cases) {
|
|
100
|
+
process.stdout.write(` Running: ${case_.name}...`);
|
|
101
|
+
const result = await this.runCase(case_, model, toolExecutor);
|
|
102
|
+
this.results.push(result);
|
|
103
|
+
report.results.push(result);
|
|
104
|
+
const status = result.success ? "PASS" : "FAIL";
|
|
105
|
+
console.log(`${status} (${result.turns} turns, ${result.duration_ms}ms)`);
|
|
106
|
+
if (!result.success) {
|
|
107
|
+
console.log(` Error: ${result.error}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return report;
|
|
112
|
+
}
|
|
113
|
+
saveReport(report, outputPath) {
|
|
114
|
+
const dir = path.dirname(outputPath);
|
|
115
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
116
|
+
const output = {
|
|
117
|
+
timestamp: report.timestamp,
|
|
118
|
+
models: report.models,
|
|
119
|
+
results: report.results.map((r) => ({
|
|
120
|
+
case: r.case_name,
|
|
121
|
+
model: r.model_name,
|
|
122
|
+
success: r.success,
|
|
123
|
+
turns: r.turns,
|
|
124
|
+
tool_calls: r.tool_calls,
|
|
125
|
+
error: r.error,
|
|
126
|
+
duration_ms: r.duration_ms,
|
|
127
|
+
})),
|
|
128
|
+
};
|
|
129
|
+
fs.writeFileSync(outputPath, JSON.stringify(output, null, 2));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Backend, Message } from "../llm/index.js";
|
|
2
|
+
import type { CallerContext } from "../middleware/index.js";
|
|
3
|
+
import type { ToolRegistry } from "../tools/index.js";
|
|
4
|
+
import type { ToolFormatter } from "../toolformat/index.js";
|
|
5
|
+
export declare enum TerminationReason {
|
|
6
|
+
COMPLETE = "complete",
|
|
7
|
+
MAX_ITERATIONS = "max_iterations",
|
|
8
|
+
ERROR = "error",
|
|
9
|
+
CANCELED = "canceled"
|
|
10
|
+
}
|
|
11
|
+
export interface ExecuteRequest {
|
|
12
|
+
system_prompt: string;
|
|
13
|
+
user_message: string;
|
|
14
|
+
history: Message[];
|
|
15
|
+
max_iterations?: number;
|
|
16
|
+
caller_ctx: CallerContext;
|
|
17
|
+
job_id?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecuteResult {
|
|
20
|
+
final_response: string;
|
|
21
|
+
iterations: number;
|
|
22
|
+
tool_calls_made: number;
|
|
23
|
+
termination_reason: TerminationReason;
|
|
24
|
+
conversation: Message[];
|
|
25
|
+
}
|
|
26
|
+
export interface Executor {
|
|
27
|
+
execute(req: ExecuteRequest): ExecuteResult;
|
|
28
|
+
}
|
|
29
|
+
export interface InferenceExecutorConfig {
|
|
30
|
+
backend: Backend;
|
|
31
|
+
registry: ToolRegistry;
|
|
32
|
+
tool_executor: unknown;
|
|
33
|
+
formatter: ToolFormatter;
|
|
34
|
+
max_iterations: number;
|
|
35
|
+
completion_signal: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class InferenceExecutor implements Executor {
|
|
38
|
+
private config;
|
|
39
|
+
constructor(config: InferenceExecutorConfig);
|
|
40
|
+
execute(req: ExecuteRequest): ExecuteResult;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/executor/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAIxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,oBAAY,iBAAiB;IAC3B,QAAQ,aAAa;IACrB,cAAc,mBAAmB;IACjC,KAAK,UAAU;IACf,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,aAAa,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,iBAAiB,CAAC;IACtC,YAAY,EAAE,OAAO,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,aAAa,CAAC;CAC7C;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,aAAa,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,iBAAkB,YAAW,QAAQ;IAChD,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,EAAE,uBAAuB;IAQ3C,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,aAAa;CA2D5C"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Role } from "../llm/index.js";
|
|
2
|
+
export var TerminationReason;
|
|
3
|
+
(function (TerminationReason) {
|
|
4
|
+
TerminationReason["COMPLETE"] = "complete";
|
|
5
|
+
TerminationReason["MAX_ITERATIONS"] = "max_iterations";
|
|
6
|
+
TerminationReason["ERROR"] = "error";
|
|
7
|
+
TerminationReason["CANCELED"] = "canceled";
|
|
8
|
+
})(TerminationReason || (TerminationReason = {}));
|
|
9
|
+
export class InferenceExecutor {
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = {
|
|
13
|
+
...config,
|
|
14
|
+
max_iterations: config.max_iterations || 20,
|
|
15
|
+
completion_signal: config.completion_signal || "TASK_COMPLETE",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
execute(req) {
|
|
19
|
+
const conversation = [...req.history];
|
|
20
|
+
conversation.push({ role: Role.SYSTEM, content: req.system_prompt });
|
|
21
|
+
conversation.push({ role: Role.USER, content: req.user_message });
|
|
22
|
+
let iterations = 0;
|
|
23
|
+
let tool_calls_made = 0;
|
|
24
|
+
let final_response = "";
|
|
25
|
+
const max_iters = req.max_iterations || this.config.max_iterations;
|
|
26
|
+
while (iterations < max_iters) {
|
|
27
|
+
const response = this.config.backend.complete(conversation);
|
|
28
|
+
if (!response.tool_calls || response.tool_calls.length === 0) {
|
|
29
|
+
final_response = response.content;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
tool_calls_made += response.tool_calls.length;
|
|
33
|
+
for (const tool_call of response.tool_calls) {
|
|
34
|
+
const [result, success, error] = this.config.tool_executor.execute(tool_call.name, tool_call.arguments, req.caller_ctx);
|
|
35
|
+
conversation.push({
|
|
36
|
+
role: Role.TOOL,
|
|
37
|
+
content: success
|
|
38
|
+
? `Tool ${tool_call.name} result: ${JSON.stringify(result)}`
|
|
39
|
+
: `Tool ${tool_call.name} error: ${error}`,
|
|
40
|
+
tool_call_id: tool_call.id,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
iterations++;
|
|
44
|
+
}
|
|
45
|
+
let termination;
|
|
46
|
+
if (iterations >= max_iters) {
|
|
47
|
+
termination = TerminationReason.MAX_ITERATIONS;
|
|
48
|
+
}
|
|
49
|
+
else if (final_response) {
|
|
50
|
+
termination = TerminationReason.COMPLETE;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
termination = TerminationReason.ERROR;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
final_response,
|
|
57
|
+
iterations,
|
|
58
|
+
tool_calls_made,
|
|
59
|
+
termination_reason: termination,
|
|
60
|
+
conversation,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TerminationReason, InferenceExecutor } from "./executor.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./tools/index.js";
|
|
2
|
+
export * from "./middleware/index.js";
|
|
3
|
+
export * from "./executor/index.js";
|
|
4
|
+
export * from "./jobs/index.js";
|
|
5
|
+
export * from "./llm/index.js";
|
|
6
|
+
export * from "./llmcontext/index.js";
|
|
7
|
+
export * from "./prompts/index.js";
|
|
8
|
+
export * from "./toolformat/index.js";
|
|
9
|
+
export * from "./memory/index.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./tools/index.js";
|
|
2
|
+
export * from "./middleware/index.js";
|
|
3
|
+
export * from "./executor/index.js";
|
|
4
|
+
export * from "./jobs/index.js";
|
|
5
|
+
export * from "./llm/index.js";
|
|
6
|
+
export * from "./llmcontext/index.js";
|
|
7
|
+
export * from "./prompts/index.js";
|
|
8
|
+
export * from "./toolformat/index.js";
|
|
9
|
+
export * from "./memory/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jobs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare enum JobStatus {
|
|
2
|
+
PENDING = "pending",
|
|
3
|
+
RUNNING = "running",
|
|
4
|
+
COMPLETE = "complete",
|
|
5
|
+
FAILED = "failed",
|
|
6
|
+
CANCELED = "canceled"
|
|
7
|
+
}
|
|
8
|
+
export interface Job {
|
|
9
|
+
id: string;
|
|
10
|
+
status: JobStatus;
|
|
11
|
+
description: string;
|
|
12
|
+
created_at: Date;
|
|
13
|
+
updated_at: Date;
|
|
14
|
+
result: string;
|
|
15
|
+
error: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function createJob(id: string, description: string): Job;
|
|
18
|
+
//# sourceMappingURL=job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../../src/jobs/job.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,GAAG,CAW9D"}
|
package/dist/jobs/job.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export var JobStatus;
|
|
2
|
+
(function (JobStatus) {
|
|
3
|
+
JobStatus["PENDING"] = "pending";
|
|
4
|
+
JobStatus["RUNNING"] = "running";
|
|
5
|
+
JobStatus["COMPLETE"] = "complete";
|
|
6
|
+
JobStatus["FAILED"] = "failed";
|
|
7
|
+
JobStatus["CANCELED"] = "canceled";
|
|
8
|
+
})(JobStatus || (JobStatus = {}));
|
|
9
|
+
export function createJob(id, description) {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
return {
|
|
12
|
+
id,
|
|
13
|
+
status: JobStatus.PENDING,
|
|
14
|
+
description,
|
|
15
|
+
created_at: now,
|
|
16
|
+
updated_at: now,
|
|
17
|
+
result: "",
|
|
18
|
+
error: "",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Job, JobStatus } from "./job.js";
|
|
2
|
+
export interface JobManager {
|
|
3
|
+
create(description: string): string;
|
|
4
|
+
start(jobId: string): void;
|
|
5
|
+
complete(jobId: string, result: string): void;
|
|
6
|
+
fail(jobId: string, error: string): void;
|
|
7
|
+
cancel(jobId: string): void;
|
|
8
|
+
get(jobId: string): Job;
|
|
9
|
+
list(status?: JobStatus): Job[];
|
|
10
|
+
}
|
|
11
|
+
export declare class InMemoryJobManager implements JobManager {
|
|
12
|
+
private jobs;
|
|
13
|
+
private counter;
|
|
14
|
+
private lock;
|
|
15
|
+
create(description: string): string;
|
|
16
|
+
start(jobId: string): void;
|
|
17
|
+
complete(jobId: string, result: string): void;
|
|
18
|
+
fail(jobId: string, error: string): void;
|
|
19
|
+
cancel(jobId: string): void;
|
|
20
|
+
get(jobId: string): Job;
|
|
21
|
+
list(status?: JobStatus): Job[];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/jobs/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,GAAG,EAAE,CAAC;CACjC;AAED,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,IAAI,CAA2B;IAEvC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAiBnC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO1B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAQ7C,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAQxC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO3B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAMvB,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,GAAG,EAAE;CAIhC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { JobStatus } from "./job.js";
|
|
2
|
+
export class InMemoryJobManager {
|
|
3
|
+
jobs = new Map();
|
|
4
|
+
counter = 0;
|
|
5
|
+
lock = new Map();
|
|
6
|
+
create(description) {
|
|
7
|
+
this.counter++;
|
|
8
|
+
const jobId = `${Date.now().toString().slice(0, 14)}-${String(this.counter).padStart(4, "0")}`;
|
|
9
|
+
const now = new Date();
|
|
10
|
+
const job = {
|
|
11
|
+
id: jobId,
|
|
12
|
+
status: JobStatus.PENDING,
|
|
13
|
+
description,
|
|
14
|
+
created_at: now,
|
|
15
|
+
updated_at: now,
|
|
16
|
+
result: "",
|
|
17
|
+
error: "",
|
|
18
|
+
};
|
|
19
|
+
this.jobs.set(jobId, job);
|
|
20
|
+
return jobId;
|
|
21
|
+
}
|
|
22
|
+
start(jobId) {
|
|
23
|
+
const job = this.jobs.get(jobId);
|
|
24
|
+
if (!job)
|
|
25
|
+
throw new Error(`job not found: ${jobId}`);
|
|
26
|
+
job.status = JobStatus.RUNNING;
|
|
27
|
+
job.updated_at = new Date();
|
|
28
|
+
}
|
|
29
|
+
complete(jobId, result) {
|
|
30
|
+
const job = this.jobs.get(jobId);
|
|
31
|
+
if (!job)
|
|
32
|
+
throw new Error(`job not found: ${jobId}`);
|
|
33
|
+
job.status = JobStatus.COMPLETE;
|
|
34
|
+
job.result = result;
|
|
35
|
+
job.updated_at = new Date();
|
|
36
|
+
}
|
|
37
|
+
fail(jobId, error) {
|
|
38
|
+
const job = this.jobs.get(jobId);
|
|
39
|
+
if (!job)
|
|
40
|
+
throw new Error(`job not found: ${jobId}`);
|
|
41
|
+
job.status = JobStatus.FAILED;
|
|
42
|
+
job.error = error;
|
|
43
|
+
job.updated_at = new Date();
|
|
44
|
+
}
|
|
45
|
+
cancel(jobId) {
|
|
46
|
+
const job = this.jobs.get(jobId);
|
|
47
|
+
if (!job)
|
|
48
|
+
throw new Error(`job not found: ${jobId}`);
|
|
49
|
+
job.status = JobStatus.CANCELED;
|
|
50
|
+
job.updated_at = new Date();
|
|
51
|
+
}
|
|
52
|
+
get(jobId) {
|
|
53
|
+
const job = this.jobs.get(jobId);
|
|
54
|
+
if (!job)
|
|
55
|
+
throw new Error(`job not found: ${jobId}`);
|
|
56
|
+
return job;
|
|
57
|
+
}
|
|
58
|
+
list(status) {
|
|
59
|
+
if (!status)
|
|
60
|
+
return Array.from(this.jobs.values());
|
|
61
|
+
return Array.from(this.jobs.values()).filter((j) => j.status === status);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Message } from "./request.js";
|
|
2
|
+
import type { Response } from "./response.js";
|
|
3
|
+
export interface Backend {
|
|
4
|
+
complete(messages: Message[]): Response;
|
|
5
|
+
supportsNativeToolCalling(): boolean;
|
|
6
|
+
modelName(): string;
|
|
7
|
+
contextWindowSize(): number;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Role } from "./request.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ToolCall } from "./response.js";
|
|
2
|
+
import type { MessageMeta } from "../middleware/types.js";
|
|
3
|
+
export declare enum Role {
|
|
4
|
+
SYSTEM = "system",
|
|
5
|
+
USER = "user",
|
|
6
|
+
ASSISTANT = "assistant",
|
|
7
|
+
TOOL = "tool"
|
|
8
|
+
}
|
|
9
|
+
export interface Message {
|
|
10
|
+
role: Role;
|
|
11
|
+
content: string;
|
|
12
|
+
tool_call_id?: string;
|
|
13
|
+
tool_calls?: ToolCall[];
|
|
14
|
+
meta?: MessageMeta;
|
|
15
|
+
}
|
|
16
|
+
export interface ToolDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
input_schema: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface Request {
|
|
22
|
+
messages: Message[];
|
|
23
|
+
tools: ToolDefinition[];
|
|
24
|
+
temperature?: number;
|
|
25
|
+
max_tokens?: number;
|
|
26
|
+
stop?: string[];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/llm/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,oBAAY,IAAI;IACd,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ToolCall {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
arguments: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface TokenUsage {
|
|
7
|
+
prompt_tokens: number;
|
|
8
|
+
completion_tokens: number;
|
|
9
|
+
total_tokens: number;
|
|
10
|
+
}
|
|
11
|
+
export interface Response {
|
|
12
|
+
content: string;
|
|
13
|
+
tool_calls: ToolCall[];
|
|
14
|
+
finish_reason: string;
|
|
15
|
+
usage_tokens: TokenUsage;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Message } from "../llm/request.js";
|
|
2
|
+
import type { CompactionStrategy, TokenCounter } from "./strategies.js";
|
|
3
|
+
export interface CompactEvent {
|
|
4
|
+
step_index: number;
|
|
5
|
+
tokens_before: number;
|
|
6
|
+
tokens_after: number;
|
|
7
|
+
budget_tokens: number;
|
|
8
|
+
messages_before: number;
|
|
9
|
+
messages_after: number;
|
|
10
|
+
phase_reached: number;
|
|
11
|
+
strategy_name: string;
|
|
12
|
+
}
|
|
13
|
+
export type CompactCallback = (event: CompactEvent) => void;
|
|
14
|
+
export type ThresholdCallback = (tokens: number, budget: number, pct: number) => string | null;
|
|
15
|
+
export declare function defaultContextWarning(tokens: number, budget: number, pct: number): string | null;
|
|
16
|
+
export declare class ContextWindowManager {
|
|
17
|
+
private contextWindow;
|
|
18
|
+
private compactionRatio;
|
|
19
|
+
private counter;
|
|
20
|
+
private strategy;
|
|
21
|
+
private lastKnownTokens;
|
|
22
|
+
private contextThresholds;
|
|
23
|
+
private onContextThreshold;
|
|
24
|
+
private firedThresholds;
|
|
25
|
+
private onCompact;
|
|
26
|
+
constructor(contextWindow: number, counter?: TokenCounter | null, strategy?: CompactionStrategy | null, contextThresholds?: number[] | null, onContextThreshold?: ThresholdCallback | null, onCompact?: CompactCallback | null);
|
|
27
|
+
setCompactionRatio(ratio: number): void;
|
|
28
|
+
updateTokenCount(totalTokens: number): void;
|
|
29
|
+
check(messages: Message[]): [number, boolean];
|
|
30
|
+
shouldCompact(messages: Message[]): boolean;
|
|
31
|
+
compact(messages: Message[]): Message[];
|
|
32
|
+
checkThresholds(messages: Message[]): string | null;
|
|
33
|
+
private estimateTokens;
|
|
34
|
+
}
|
|
35
|
+
export declare function defaultCounter(messages: Message[]): number;
|
|
36
|
+
//# sourceMappingURL=context_window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context_window.d.ts","sourceRoot":"","sources":["../../src/llmcontext/context_window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGxE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,KACR,MAAM,GAAG,IAAI,CAAC;AAEnB,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,IAAI,CAQf;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,iBAAiB,CAAW;IACpC,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,eAAe,CAAc;IACrC,OAAO,CAAC,SAAS,CAAyB;gBAGxC,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,YAAY,GAAG,IAAW,EACnC,QAAQ,GAAE,kBAAkB,GAAG,IAAW,EAC1C,iBAAiB,GAAE,MAAM,EAAE,GAAG,IAAW,EACzC,kBAAkB,GAAE,iBAAiB,GAAG,IAAW,EACnD,SAAS,GAAE,eAAe,GAAG,IAAW;IAe1C,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIvC,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAI3C,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAM7C,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO;IAM3C,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE;IAgCvC,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,IAAI;IAqBnD,OAAO,CAAC,cAAc;CAMvB;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CAY1D"}
|