typed-agents 1.0.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/LICENSE +19 -0
- package/README.md +201 -0
- package/dist/agents/agent.decorator.d.ts +19 -0
- package/dist/agents/agent.decorator.d.ts.map +1 -0
- package/dist/agents/agent.decorator.js +38 -0
- package/dist/agents/agent.decorator.js.map +1 -0
- package/dist/agents/agent.runtime.d.ts +133 -0
- package/dist/agents/agent.runtime.d.ts.map +1 -0
- package/dist/agents/agent.runtime.js +593 -0
- package/dist/agents/agent.runtime.js.map +1 -0
- package/dist/agents/agent.types.d.ts +245 -0
- package/dist/agents/agent.types.d.ts.map +1 -0
- package/dist/agents/agent.types.js +27 -0
- package/dist/agents/agent.types.js.map +1 -0
- package/dist/agents/behavior-engine/behavior.types.d.ts +23 -0
- package/dist/agents/behavior-engine/behavior.types.d.ts.map +1 -0
- package/dist/agents/behavior-engine/behavior.types.js +3 -0
- package/dist/agents/behavior-engine/behavior.types.js.map +1 -0
- package/dist/agents/behavior-engine/build-system-prompt.d.ts +12 -0
- package/dist/agents/behavior-engine/build-system-prompt.d.ts.map +1 -0
- package/dist/agents/behavior-engine/build-system-prompt.js +29 -0
- package/dist/agents/behavior-engine/build-system-prompt.js.map +1 -0
- package/dist/agents/behavior-engine/index.d.ts +7 -0
- package/dist/agents/behavior-engine/index.d.ts.map +1 -0
- package/dist/agents/behavior-engine/index.js +23 -0
- package/dist/agents/behavior-engine/index.js.map +1 -0
- package/dist/agents/behavior-engine/load-behavior.d.ts +16 -0
- package/dist/agents/behavior-engine/load-behavior.d.ts.map +1 -0
- package/dist/agents/behavior-engine/load-behavior.js +36 -0
- package/dist/agents/behavior-engine/load-behavior.js.map +1 -0
- package/dist/agents/behavior-engine/merge-behavior.d.ts +12 -0
- package/dist/agents/behavior-engine/merge-behavior.d.ts.map +1 -0
- package/dist/agents/behavior-engine/merge-behavior.js +33 -0
- package/dist/agents/behavior-engine/merge-behavior.js.map +1 -0
- package/dist/agents/behavior-engine/parse-behavior.d.ts +10 -0
- package/dist/agents/behavior-engine/parse-behavior.d.ts.map +1 -0
- package/dist/agents/behavior-engine/parse-behavior.js +66 -0
- package/dist/agents/behavior-engine/parse-behavior.js.map +1 -0
- package/dist/agents/behavior-engine/watch-behavior.d.ts +10 -0
- package/dist/agents/behavior-engine/watch-behavior.d.ts.map +1 -0
- package/dist/agents/behavior-engine/watch-behavior.js +34 -0
- package/dist/agents/behavior-engine/watch-behavior.js.map +1 -0
- package/dist/agents/compose.d.ts +41 -0
- package/dist/agents/compose.d.ts.map +1 -0
- package/dist/agents/compose.js +29 -0
- package/dist/agents/compose.js.map +1 -0
- package/dist/agents/index.d.ts +7 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +25 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/runtime-engine/build-tool-map.d.ts +16 -0
- package/dist/agents/runtime-engine/build-tool-map.d.ts.map +1 -0
- package/dist/agents/runtime-engine/build-tool-map.js +88 -0
- package/dist/agents/runtime-engine/build-tool-map.js.map +1 -0
- package/dist/agents/runtime-engine/convert-zod-to-tool-schema.d.ts +13 -0
- package/dist/agents/runtime-engine/convert-zod-to-tool-schema.d.ts.map +1 -0
- package/dist/agents/runtime-engine/convert-zod-to-tool-schema.js +26 -0
- package/dist/agents/runtime-engine/convert-zod-to-tool-schema.js.map +1 -0
- package/dist/agents/runtime-engine/execute-tool.d.ts +19 -0
- package/dist/agents/runtime-engine/execute-tool.d.ts.map +1 -0
- package/dist/agents/runtime-engine/execute-tool.js +100 -0
- package/dist/agents/runtime-engine/execute-tool.js.map +1 -0
- package/dist/agents/runtime-engine/index.d.ts +7 -0
- package/dist/agents/runtime-engine/index.d.ts.map +1 -0
- package/dist/agents/runtime-engine/index.js +23 -0
- package/dist/agents/runtime-engine/index.js.map +1 -0
- package/dist/agents/runtime-engine/parse-tool-arguments.d.ts +12 -0
- package/dist/agents/runtime-engine/parse-tool-arguments.d.ts.map +1 -0
- package/dist/agents/runtime-engine/parse-tool-arguments.js +42 -0
- package/dist/agents/runtime-engine/parse-tool-arguments.js.map +1 -0
- package/dist/agents/runtime-engine/retry.utils.d.ts +26 -0
- package/dist/agents/runtime-engine/retry.utils.d.ts.map +1 -0
- package/dist/agents/runtime-engine/retry.utils.js +55 -0
- package/dist/agents/runtime-engine/retry.utils.js.map +1 -0
- package/dist/agents/runtime-engine/state-persistence.d.ts +56 -0
- package/dist/agents/runtime-engine/state-persistence.d.ts.map +1 -0
- package/dist/agents/runtime-engine/state-persistence.js +70 -0
- package/dist/agents/runtime-engine/state-persistence.js.map +1 -0
- package/dist/clients/index.d.ts +3 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +19 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/llm.client.d.ts +48 -0
- package/dist/clients/llm.client.d.ts.map +1 -0
- package/dist/clients/llm.client.js +3 -0
- package/dist/clients/llm.client.js.map +1 -0
- package/dist/clients/ollama.client.d.ts +20 -0
- package/dist/clients/ollama.client.d.ts.map +1 -0
- package/dist/clients/ollama.client.js +85 -0
- package/dist/clients/ollama.client.js.map +1 -0
- package/dist/core/logger/index.d.ts +2 -0
- package/dist/core/logger/index.d.ts.map +1 -0
- package/dist/core/logger/index.js +18 -0
- package/dist/core/logger/index.js.map +1 -0
- package/dist/core/logger/logger.d.ts +7 -0
- package/dist/core/logger/logger.d.ts.map +1 -0
- package/dist/core/logger/logger.js +19 -0
- package/dist/core/logger/logger.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/agent.runner.d.ts +29 -0
- package/dist/runtime/agent.runner.d.ts.map +1 -0
- package/dist/runtime/agent.runner.js +39 -0
- package/dist/runtime/agent.runner.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +18 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +128 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +140 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tool.decorator.d.ts +71 -0
- package/dist/tools/tool.decorator.d.ts.map +1 -0
- package/dist/tools/tool.decorator.js +98 -0
- package/dist/tools/tool.decorator.js.map +1 -0
- package/dist/tools/tool.types.d.ts +231 -0
- package/dist/tools/tool.types.d.ts.map +1 -0
- package/dist/tools/tool.types.js +3 -0
- package/dist/tools/tool.types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleep = void 0;
|
|
4
|
+
exports.withRetry = withRetry;
|
|
5
|
+
/**
|
|
6
|
+
* Sleeps for the specified number of milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* @param ms - Milliseconds to sleep.
|
|
9
|
+
* @returns A promise that resolves after the delay.
|
|
10
|
+
*/
|
|
11
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
12
|
+
exports.sleep = sleep;
|
|
13
|
+
/**
|
|
14
|
+
* Executes a function with retry logic, emitting events on failures.
|
|
15
|
+
*
|
|
16
|
+
* Retries up to maxRetries times with exponential backoff if enabled.
|
|
17
|
+
* Emits "retry:attempt" events for each failure, and throws on final failure.
|
|
18
|
+
*
|
|
19
|
+
* @param fn - The async function to execute and retry.
|
|
20
|
+
* @param maxRetries - Maximum number of retry attempts.
|
|
21
|
+
* @param baseDelay - Base delay in ms between retries.
|
|
22
|
+
* @param backoff - Whether to use exponential backoff.
|
|
23
|
+
* @param emit - Event emitter function for retry events.
|
|
24
|
+
* @param context - Context object with a "name" for logging.
|
|
25
|
+
* @returns The result of the successful function call.
|
|
26
|
+
* @throws The last error if all retries fail.
|
|
27
|
+
*/
|
|
28
|
+
async function withRetry(fn, maxRetries, baseDelay, backoff, emit, context) {
|
|
29
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
30
|
+
try {
|
|
31
|
+
return await fn();
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
const isLast = attempt === maxRetries;
|
|
35
|
+
emit({
|
|
36
|
+
type: "retry:attempt",
|
|
37
|
+
log: {
|
|
38
|
+
level: isLast ? "error" : "warn",
|
|
39
|
+
message: `🔄 Retry ${attempt + 1}/${maxRetries + 1} su ${context.name}`,
|
|
40
|
+
},
|
|
41
|
+
payload: {
|
|
42
|
+
name: context.name,
|
|
43
|
+
attempt: attempt + 1,
|
|
44
|
+
error: String(err),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
if (isLast)
|
|
48
|
+
throw err;
|
|
49
|
+
const delay = backoff ? baseDelay * Math.pow(2, attempt) : baseDelay;
|
|
50
|
+
await (0, exports.sleep)(delay);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error("Unreachable");
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=retry.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.utils.js","sourceRoot":"","sources":["../../../src/agents/runtime-engine/retry.utils.ts"],"names":[],"mappings":";;;AAuBA,8BAiCC;AAxDD;;;;;GAKG;AACI,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAA9D,QAAA,KAAK,SAAyD;AAE3E;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,SAAS,CAC7B,EAAoB,EACpB,UAAkB,EAClB,SAAiB,EACjB,OAAgB,EAChB,IAA0B,EAC1B,OAAyB;IAEzB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,OAAO,KAAK,UAAU,CAAC;YACtC,IAAI,CAAC;gBACH,IAAI,EAAE,eAAe;gBACrB,GAAG,EAAE;oBACH,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;oBAChC,OAAO,EAAE,YAAY,OAAO,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,OAAO,OAAO,CAAC,IAAI,EAAE;iBACxE;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,OAAO,EAAE,OAAO,GAAG,CAAC;oBACpB,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;iBACnB;aACF,CAAC,CAAC;YAEH,IAAI,MAAM;gBAAE,MAAM,GAAG,CAAC;YAEtB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACrE,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SerializedState } from "../agent.types";
|
|
2
|
+
/**
|
|
3
|
+
* Interface for state persistence implementations.
|
|
4
|
+
* Allows saving/loading agent run states and listing run IDs.
|
|
5
|
+
*/
|
|
6
|
+
export interface Persister {
|
|
7
|
+
/**
|
|
8
|
+
* Saves a serialized state for a given run ID.
|
|
9
|
+
* @param runId - Unique identifier for the run.
|
|
10
|
+
* @param state - The serialized state to save.
|
|
11
|
+
*/
|
|
12
|
+
save(runId: string, state: SerializedState): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Loads a serialized state for a given run ID, or null if not found.
|
|
15
|
+
* @param runId - Unique identifier for the run.
|
|
16
|
+
* @returns The loaded state or null.
|
|
17
|
+
*/
|
|
18
|
+
load(runId: string): Promise<SerializedState | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns all available run IDs.
|
|
21
|
+
* @returns Array of run ID strings.
|
|
22
|
+
*/
|
|
23
|
+
getAllRunIds(): string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* In-memory persister using a Map. Each instance has its own store,
|
|
27
|
+
* preventing shared state between parallel AgentRuntime instances.
|
|
28
|
+
* Uses structuredClone to avoid accidental mutations.
|
|
29
|
+
*/
|
|
30
|
+
export declare class MemoryPersister implements Persister {
|
|
31
|
+
private store;
|
|
32
|
+
save(runId: string, state: SerializedState): Promise<void>;
|
|
33
|
+
load(runId: string): Promise<SerializedState | null>;
|
|
34
|
+
getAllRunIds(): string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* File-based persister that saves states as JSON files in a directory.
|
|
38
|
+
* Creates the directory if it doesn't exist.
|
|
39
|
+
*/
|
|
40
|
+
export declare class FilePersister implements Persister {
|
|
41
|
+
private baseDir;
|
|
42
|
+
constructor(baseDir: string);
|
|
43
|
+
save(runId: string, state: SerializedState): Promise<void>;
|
|
44
|
+
load(runId: string): Promise<SerializedState | null>;
|
|
45
|
+
getAllRunIds(): string[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Null-object pattern persister for "none" mode.
|
|
49
|
+
* Does nothing, replacing the inline anonymous object.
|
|
50
|
+
*/
|
|
51
|
+
export declare class NullPersister implements Persister {
|
|
52
|
+
save(): Promise<void>;
|
|
53
|
+
load(): Promise<null>;
|
|
54
|
+
getAllRunIds(): string[];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=state-persistence.d.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ACzB"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NullPersister = exports.FilePersister = exports.MemoryPersister = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* In-memory persister using a Map. Each instance has its own store,
|
|
11
|
+
* preventing shared state between parallel AgentRuntime instances.
|
|
12
|
+
* Uses structuredClone to avoid accidental mutations.
|
|
13
|
+
*/
|
|
14
|
+
class MemoryPersister {
|
|
15
|
+
store = new Map();
|
|
16
|
+
async save(runId, state) {
|
|
17
|
+
this.store.set(runId, structuredClone(state));
|
|
18
|
+
}
|
|
19
|
+
async load(runId) {
|
|
20
|
+
const entry = this.store.get(runId);
|
|
21
|
+
return entry ? structuredClone(entry) : null;
|
|
22
|
+
}
|
|
23
|
+
getAllRunIds() {
|
|
24
|
+
return Array.from(this.store.keys());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MemoryPersister = MemoryPersister;
|
|
28
|
+
/**
|
|
29
|
+
* File-based persister that saves states as JSON files in a directory.
|
|
30
|
+
* Creates the directory if it doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
class FilePersister {
|
|
33
|
+
baseDir;
|
|
34
|
+
constructor(baseDir) {
|
|
35
|
+
this.baseDir = baseDir;
|
|
36
|
+
fs_1.default.mkdirSync(baseDir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
async save(runId, state) {
|
|
39
|
+
const file = path_1.default.join(this.baseDir, `${runId}.json`);
|
|
40
|
+
await fs_1.default.promises.writeFile(file, JSON.stringify(state, null, 2));
|
|
41
|
+
}
|
|
42
|
+
async load(runId) {
|
|
43
|
+
const file = path_1.default.join(this.baseDir, `${runId}.json`);
|
|
44
|
+
try {
|
|
45
|
+
const content = await fs_1.default.promises.readFile(file, "utf-8");
|
|
46
|
+
return JSON.parse(content);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getAllRunIds() {
|
|
53
|
+
return fs_1.default
|
|
54
|
+
.readdirSync(this.baseDir)
|
|
55
|
+
.filter((f) => f.endsWith(".json") && !f.includes("-cache"))
|
|
56
|
+
.map((f) => f.replace(".json", ""));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.FilePersister = FilePersister;
|
|
60
|
+
/**
|
|
61
|
+
* Null-object pattern persister for "none" mode.
|
|
62
|
+
* Does nothing, replacing the inline anonymous object.
|
|
63
|
+
*/
|
|
64
|
+
class NullPersister {
|
|
65
|
+
async save() { }
|
|
66
|
+
async load() { return null; }
|
|
67
|
+
getAllRunIds() { return []; }
|
|
68
|
+
}
|
|
69
|
+
exports.NullPersister = NullPersister;
|
|
70
|
+
//# sourceMappingURL=state-persistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-persistence.js","sourceRoot":"","sources":["../../../src/agents/runtime-engine/state-persistence.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AA6BxB;;;;GAIG;AACH,MAAa,eAAe;IAClB,KAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;IAEnD,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,KAAsB;QAC9C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,C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Q,CAAC,CAAC;aAC3D,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AA1BD,sCA0BC;AAED;;;GAGG;AACH,MAAa,aAAa;IACxB,KAAK,CAAC,IAAI,KAAmB,CAAC;IAC9B,KAAK,CAAC,IAAI,KAAoB,OAAO,IAAI,CAAC,CAAC,CAAC;IAC5C,YAAY,KAAe,OAAO,EAAE,CAAC,CAAC,CAAC;CACxC;AAJD,sCAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./llm.client"), exports);
|
|
18
|
+
__exportStar(require("./ollama.client"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ToolDefinition } from "../tools/tool.types";
|
|
2
|
+
export interface LLMMessage {
|
|
3
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
4
|
+
content: string;
|
|
5
|
+
tool_calls?: StandardToolCall[];
|
|
6
|
+
tool_call_id?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface StandardToolCall {
|
|
9
|
+
id?: string;
|
|
10
|
+
function: {
|
|
11
|
+
name: string;
|
|
12
|
+
arguments: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface LLMResponse {
|
|
16
|
+
text: string;
|
|
17
|
+
tool_calls?: StandardToolCall[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Discriminated union emitted during streaming.
|
|
21
|
+
* - text_delta: incremental text token
|
|
22
|
+
* - tool_call_delta: a tool call discovered mid-stream
|
|
23
|
+
* - done: signals end of stream with the full assembled response
|
|
24
|
+
*/
|
|
25
|
+
export type StreamChunk = {
|
|
26
|
+
type: "text_delta";
|
|
27
|
+
delta: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "tool_call_delta";
|
|
30
|
+
tool_call: StandardToolCall;
|
|
31
|
+
} | {
|
|
32
|
+
type: "done";
|
|
33
|
+
response: LLMResponse;
|
|
34
|
+
};
|
|
35
|
+
export interface LLMClient {
|
|
36
|
+
invoke(messages: LLMMessage[], tools?: ToolDefinition[], options?: {
|
|
37
|
+
temperature?: number;
|
|
38
|
+
}): Promise<LLMResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Optional streaming variant. Clients that support it should implement this.
|
|
41
|
+
* The runtime falls back to `invoke` when this is absent.
|
|
42
|
+
*/
|
|
43
|
+
invokeStream?(messages: LLMMessage[], tools?: ToolDefinition[], options?: {
|
|
44
|
+
temperature?: number;
|
|
45
|
+
}): AsyncGenerator<StreamChunk>;
|
|
46
|
+
getModelIdentifier(): string;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=llm.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.client.d.ts","sourceRoot":"","sources":["../../src/clients/llm.client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACjC;AAED;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAM,KAAK,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAY,QAAQ,EAAE,WAAW,CAAA;CAAE,CAAC;AAEvD,MAAM,WAAW,SAAS;IACxB,MAAM,CACJ,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACjC,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;OAGG;IACH,YAAY,CAAC,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACjC,cAAc,CAAC,WAAW,CAAC,CAAC;IAE/B,kBAAkB,IAAI,MAAM,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.client.js","sourceRoot":"","sources":["../../src/clients/llm.client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LLMClient, LLMMessage, LLMResponse, StreamChunk } from "./llm.client";
|
|
2
|
+
import type { ToolDefinition } from "../tools/tool.types";
|
|
3
|
+
export declare class OllamaClient implements LLMClient {
|
|
4
|
+
private model;
|
|
5
|
+
private ollama;
|
|
6
|
+
constructor(model: string);
|
|
7
|
+
invoke(messages: LLMMessage[], tools?: ToolDefinition[], options?: {
|
|
8
|
+
temperature?: number;
|
|
9
|
+
}): Promise<LLMResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Streams text deltas token by token.
|
|
12
|
+
* Tool calls are collected silently and emitted as tool_call_delta chunks,
|
|
13
|
+
* then included in the final "done" chunk.
|
|
14
|
+
*/
|
|
15
|
+
invokeStream(messages: LLMMessage[], tools?: ToolDefinition[], options?: {
|
|
16
|
+
temperature?: number;
|
|
17
|
+
}): AsyncGenerator<StreamChunk>;
|
|
18
|
+
getModelIdentifier(): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ollama.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.client.d.ts","sourceRoot":"","sources":["../../src/clients/ollama.client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,WAAW,EAEX,WAAW,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAkB1D,qBAAa,YAAa,YAAW,SAAS;IAGhC,OAAO,CAAC,KAAK;IAFzB,OAAO,CAAC,MAAM,CAAgB;gBAEV,KAAK,EAAE,MAAM;IAE3B,MAAM,CACV,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO,GACrC,OAAO,CAAC,WAAW,CAAC;IAkBvB;;;;OAIG;IACI,YAAY,CACjB,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO,GACrC,cAAc,CAAC,WAAW,CAAC;IAoC9B,kBAAkB,IAAI,MAAM;CAG7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OllamaClient = void 0;
|
|
4
|
+
const ollama_1 = require("ollama");
|
|
5
|
+
function normalizeToolCall(tc) {
|
|
6
|
+
const argsRaw = tc.function.arguments;
|
|
7
|
+
const parsedArgs = typeof argsRaw === "string"
|
|
8
|
+
? (() => {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(argsRaw || "{}");
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
})()
|
|
16
|
+
: (argsRaw ?? {});
|
|
17
|
+
return {
|
|
18
|
+
id: tc.id,
|
|
19
|
+
function: { name: tc.function.name, arguments: parsedArgs },
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
class OllamaClient {
|
|
23
|
+
model;
|
|
24
|
+
ollama = new ollama_1.Ollama();
|
|
25
|
+
constructor(model) {
|
|
26
|
+
this.model = model;
|
|
27
|
+
}
|
|
28
|
+
async invoke(messages, tools, options = {}) {
|
|
29
|
+
const response = await this.ollama.chat({
|
|
30
|
+
model: this.model,
|
|
31
|
+
messages,
|
|
32
|
+
tools: tools,
|
|
33
|
+
keep_alive: -1,
|
|
34
|
+
options: {
|
|
35
|
+
num_predict: 1000,
|
|
36
|
+
temperature: options.temperature ?? 0.2,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
text: response.message.content || "",
|
|
41
|
+
tool_calls: (response.message.tool_calls ?? []).map(normalizeToolCall),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Streams text deltas token by token.
|
|
46
|
+
* Tool calls are collected silently and emitted as tool_call_delta chunks,
|
|
47
|
+
* then included in the final "done" chunk.
|
|
48
|
+
*/
|
|
49
|
+
async *invokeStream(messages, tools, options = {}) {
|
|
50
|
+
const stream = await this.ollama.chat({
|
|
51
|
+
model: this.model,
|
|
52
|
+
messages,
|
|
53
|
+
tools: tools,
|
|
54
|
+
stream: true,
|
|
55
|
+
keep_alive: -1,
|
|
56
|
+
options: {
|
|
57
|
+
num_predict: 1000,
|
|
58
|
+
temperature: options.temperature ?? 0.2,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
let fullText = "";
|
|
62
|
+
const collectedToolCalls = [];
|
|
63
|
+
for await (const part of stream) {
|
|
64
|
+
const delta = part.message.content ?? "";
|
|
65
|
+
if (delta) {
|
|
66
|
+
fullText += delta;
|
|
67
|
+
yield { type: "text_delta", delta };
|
|
68
|
+
}
|
|
69
|
+
for (const tc of part.message.tool_calls ?? []) {
|
|
70
|
+
const normalized = normalizeToolCall(tc);
|
|
71
|
+
collectedToolCalls.push(normalized);
|
|
72
|
+
yield { type: "tool_call_delta", tool_call: normalized };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
yield {
|
|
76
|
+
type: "done",
|
|
77
|
+
response: { text: fullText, tool_calls: collectedToolCalls },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
getModelIdentifier() {
|
|
81
|
+
return this.model;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.OllamaClient = OllamaClient;
|
|
85
|
+
//# sourceMappingURL=ollama.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.client.js","sourceRoot":"","sources":["../../src/clients/ollama.client.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAWhC,SAAS,iBAAiB,CAAC,EAA8B;IACvD,MAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;IACtC,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ;QACzB,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,IAAI,CAAC;gBAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;YAAC,CAAC;YAC3C,MAAM,CAAC;gBAAC,OAAO,EAAE,CAAC;YAAC,CAAC;QACtB,CAAC,CAAC,EAAE;QACN,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAEtB,OAAO;QACL,EAAE,EAAE,EAAE,CAAC,EAAE;QACT,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE;KAC5D,CAAC;AACJ,CAAC;AAED,MAAa,YAAY;IAGH;IAFZ,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;IAE9B,YAAoB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAErC,KAAK,CAAC,MAAM,CACV,QAAsB,EACtB,KAAwB,EACxB,UAAoC,EAAE;QAEtC,MAAM,QAAQ,GAAiB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACpD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ;YACR,KAA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AAC,CAAC;gBACvE,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACpC,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;YAC3D,CAAC;QACH,CAAC;QAED,MAAM;YACJ,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE;SAC7D,CAAC;IACJ,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AA3ED,oCA2EC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/core/logger/logger.ts"],"names":[],"mappings":"AAAA,qBAAa,MAAM;IAEjB,OAAO,CAAC,MAAM,CAAC,GAAG;IAIlB,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAI1B,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAI1B,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAI5B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
static now() {
|
|
6
|
+
return new Date().toISOString();
|
|
7
|
+
}
|
|
8
|
+
static info(...args) {
|
|
9
|
+
console.log(`[INFO ${this.now()}]`, ...args);
|
|
10
|
+
}
|
|
11
|
+
static warn(...args) {
|
|
12
|
+
console.warn(`[WARN ${this.now()}]`, ...args);
|
|
13
|
+
}
|
|
14
|
+
static error(...args) {
|
|
15
|
+
console.error(`[ERROR ${this.now()}]`, ...args);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Logger = Logger;
|
|
19
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/core/logger/logger.ts"],"names":[],"mappings":";;;AAAA,MAAa,MAAM;IAET,MAAM,CAAC,GAAG;QAChB,OAAO,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAG,IAAW;QACxB,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,GAAG,IAAW;QACxB,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,GAAG,IAAW;QACzB,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD,CAAC;CAEF;AAlBD,wBAkBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./agents"), exports);
|
|
18
|
+
__exportStar(require("./clients"), exports);
|
|
19
|
+
__exportStar(require("./core/logger"), exports);
|
|
20
|
+
__exportStar(require("./runtime"), exports);
|
|
21
|
+
__exportStar(require("./tools"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,gDAA8B;AAC9B,4CAA0B;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AgentRuntime } from "../agents/agent.runtime";
|
|
2
|
+
import { LLMClient } from "../clients/llm.client";
|
|
3
|
+
import type { RunOptions } from "../agents/agent.types";
|
|
4
|
+
/**
|
|
5
|
+
* P1 FIX: `globalRuntime` singleton eliminated.
|
|
6
|
+
*
|
|
7
|
+
* Before: a single shared runtime for all agents caused state collisions
|
|
8
|
+
* when multiple runAgent calls ran in parallel.
|
|
9
|
+
*
|
|
10
|
+
* Now: each call creates its own isolated runtime, unless one is explicitly
|
|
11
|
+
* passed (useful for sharing event listeners or cache between agents
|
|
12
|
+
* coordinated by the same orchestrator).
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Runs an agent class with the given prompt and options.
|
|
16
|
+
*
|
|
17
|
+
* Creates a new AgentRuntime instance if not provided, allowing for isolated
|
|
18
|
+
* execution. Supports custom LLM clients, persistence, and runtime options.
|
|
19
|
+
*
|
|
20
|
+
* @param agentClass - The agent class decorated with `@agent()` to run.
|
|
21
|
+
* @param prompt - The user input prompt to start the agent conversation.
|
|
22
|
+
* @param showLogs - Whether to enable console logging (overridden by options.silent).
|
|
23
|
+
* @param client - Optional LLM client to use instead of the agent's default.
|
|
24
|
+
* @param options - Runtime options like maxSteps, temperature, persistence, etc.
|
|
25
|
+
* @param runtime - Optional pre-configured AgentRuntime to use (for shared state).
|
|
26
|
+
* @returns The final output string from the agent.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runAgent(agentClass: new () => object, prompt: string, showLogs?: boolean, client?: LLMClient, options?: RunOptions, runtime?: AgentRuntime): Promise<string>;
|
|
29
|
+
//# sourceMappingURL=agent.runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.runner.d.ts","sourceRoot":"","sources":["../../src/runtime/agent.runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,uBAAuB,CAAC;AAEvE;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAC5B,UAAU,EAAE,UAAU,MAAM,EAC5B,MAAM,EAAE,MAAM,EACd,QAAQ,UAAO,EACf,MAAM,CAAC,EAAE,SAAS,EAClB,OAAO,GAAE,UAAe,EACxB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAgent = runAgent;
|
|
4
|
+
const agent_runtime_1 = require("../agents/agent.runtime");
|
|
5
|
+
/**
|
|
6
|
+
* P1 FIX: `globalRuntime` singleton eliminated.
|
|
7
|
+
*
|
|
8
|
+
* Before: a single shared runtime for all agents caused state collisions
|
|
9
|
+
* when multiple runAgent calls ran in parallel.
|
|
10
|
+
*
|
|
11
|
+
* Now: each call creates its own isolated runtime, unless one is explicitly
|
|
12
|
+
* passed (useful for sharing event listeners or cache between agents
|
|
13
|
+
* coordinated by the same orchestrator).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Runs an agent class with the given prompt and options.
|
|
17
|
+
*
|
|
18
|
+
* Creates a new AgentRuntime instance if not provided, allowing for isolated
|
|
19
|
+
* execution. Supports custom LLM clients, persistence, and runtime options.
|
|
20
|
+
*
|
|
21
|
+
* @param agentClass - The agent class decorated with `@agent()` to run.
|
|
22
|
+
* @param prompt - The user input prompt to start the agent conversation.
|
|
23
|
+
* @param showLogs - Whether to enable console logging (overridden by options.silent).
|
|
24
|
+
* @param client - Optional LLM client to use instead of the agent's default.
|
|
25
|
+
* @param options - Runtime options like maxSteps, temperature, persistence, etc.
|
|
26
|
+
* @param runtime - Optional pre-configured AgentRuntime to use (for shared state).
|
|
27
|
+
* @returns The final output string from the agent.
|
|
28
|
+
*/
|
|
29
|
+
async function runAgent(agentClass, prompt, showLogs = true, client, options = {}, runtime) {
|
|
30
|
+
const effectiveShowLogs = showLogs && !(options.silent ?? false);
|
|
31
|
+
const persistCfg = typeof options.persist === "boolean"
|
|
32
|
+
? options.persist
|
|
33
|
+
? { mode: "file", dir: "./.agent-runs" }
|
|
34
|
+
: { mode: "none" }
|
|
35
|
+
: (options.persist ?? { mode: "none" });
|
|
36
|
+
const usedRuntime = runtime ?? new agent_runtime_1.AgentRuntime(effectiveShowLogs, persistCfg);
|
|
37
|
+
return usedRuntime.run(agentClass, prompt, client, options);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=agent.runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.runner.js","sourceRoot":"","sources":["../../src/runtime/agent.runner.ts"],"names":[],"mappings":";;AA6BA,4BAmBC;AAhDD,2DAAuD;AAIvD;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,QAAQ,CAC5B,UAA4B,EAC5B,MAAc,EACd,QAAQ,GAAG,IAAI,EACf,MAAkB,EAClB,UAAsB,EAAE,EACxB,OAAsB;IAEtB,MAAM,iBAAiB,GAAG,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;IAEjE,MAAM,UAAU,GACd,OAAO,OAAO,CAAC,OAAO,KAAK,SAAS;QAClC,CAAC,CAAC,OAAO,CAAC,OAAO;YACf,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,EAAE;YACxC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;QACpB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAE5C,MAAM,WAAW,GAAG,OAAO,IAAI,IAAI,4BAAY,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAC/E,OAAO,WAAW,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./agent.runner"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
|