@celljs/ai-agent 0.0.0-stage → 4.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/README.md +68 -2
- package/cell.yml +5 -0
- package/esm/node/agent/agent-factory.d.ts +10 -0
- package/esm/node/agent/agent-factory.js +76 -0
- package/esm/node/agent/agent-factory.js.map +1 -0
- package/esm/node/agent/index.d.ts +1 -0
- package/esm/node/agent/index.js +2 -0
- package/esm/node/agent/index.js.map +1 -0
- package/esm/node/agent-protocol.d.ts +32 -0
- package/esm/node/agent-protocol.js +5 -0
- package/esm/node/agent-protocol.js.map +1 -0
- package/esm/node/error/errors.d.ts +11 -0
- package/esm/node/error/errors.js +16 -0
- package/esm/node/error/errors.js.map +1 -0
- package/esm/node/error/index.d.ts +1 -0
- package/esm/node/error/index.js +2 -0
- package/esm/node/error/index.js.map +1 -0
- package/esm/node/event/agent-event-util.d.ts +37 -0
- package/esm/node/event/agent-event-util.js +60 -0
- package/esm/node/event/agent-event-util.js.map +1 -0
- package/esm/node/event/index.d.ts +1 -0
- package/esm/node/event/index.js +2 -0
- package/esm/node/event/index.js.map +1 -0
- package/esm/node/index.d.ts +5 -0
- package/esm/node/index.js +6 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/pi/index.d.ts +2 -0
- package/esm/node/pi/index.js +3 -0
- package/esm/node/pi/index.js.map +1 -0
- package/esm/node/pi/pi-agent-core-util.d.ts +6 -0
- package/esm/node/pi/pi-agent-core-util.js +17 -0
- package/esm/node/pi/pi-agent-core-util.js.map +1 -0
- package/esm/node/pi/pi-types.d.ts +6 -0
- package/esm/node/pi/pi-types.js +2 -0
- package/esm/node/pi/pi-types.js.map +1 -0
- package/esm/node/test/index.d.ts +2 -0
- package/esm/node/test/index.js +3 -0
- package/esm/node/test/index.js.map +1 -0
- package/esm/node/test/test-container.d.ts +7 -0
- package/esm/node/test/test-container.js +11 -0
- package/esm/node/test/test-container.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/agent/agent-factory.d.ts +11 -0
- package/lib/node/agent/agent-factory.d.ts.map +1 -0
- package/lib/node/agent/agent-factory.js +79 -0
- package/lib/node/agent/agent-factory.js.map +1 -0
- package/lib/node/agent/agent-factory.spec.d.ts +47 -0
- package/lib/node/agent/agent-factory.spec.d.ts.map +1 -0
- package/lib/node/agent/agent-factory.spec.js +109 -0
- package/lib/node/agent/agent-factory.spec.js.map +1 -0
- package/lib/node/agent/index.d.ts +2 -0
- package/lib/node/agent/index.d.ts.map +1 -0
- package/lib/node/agent/index.js +18 -0
- package/lib/node/agent/index.js.map +1 -0
- package/lib/node/agent-protocol.d.ts +33 -0
- package/lib/node/agent-protocol.d.ts.map +1 -0
- package/lib/node/agent-protocol.js +8 -0
- package/lib/node/agent-protocol.js.map +1 -0
- package/lib/node/error/errors.d.ts +12 -0
- package/lib/node/error/errors.d.ts.map +1 -0
- package/lib/node/error/errors.js +22 -0
- package/lib/node/error/errors.js.map +1 -0
- package/lib/node/error/index.d.ts +2 -0
- package/lib/node/error/index.d.ts.map +1 -0
- package/lib/node/error/index.js +18 -0
- package/lib/node/error/index.js.map +1 -0
- package/lib/node/event/agent-event-util.d.ts +38 -0
- package/lib/node/event/agent-event-util.d.ts.map +1 -0
- package/lib/node/event/agent-event-util.js +63 -0
- package/lib/node/event/agent-event-util.js.map +1 -0
- package/lib/node/event/agent-event-util.spec.d.ts +2 -0
- package/lib/node/event/agent-event-util.spec.d.ts.map +1 -0
- package/lib/node/event/agent-event-util.spec.js +81 -0
- package/lib/node/event/agent-event-util.spec.js.map +1 -0
- package/lib/node/event/index.d.ts +2 -0
- package/lib/node/event/index.d.ts.map +1 -0
- package/lib/node/event/index.js +18 -0
- package/lib/node/event/index.js.map +1 -0
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +22 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/pi/index.d.ts +3 -0
- package/lib/node/pi/index.d.ts.map +1 -0
- package/lib/node/pi/index.js +19 -0
- package/lib/node/pi/index.js.map +1 -0
- package/lib/node/pi/pi-agent-core-util.d.ts +7 -0
- package/lib/node/pi/pi-agent-core-util.d.ts.map +1 -0
- package/lib/node/pi/pi-agent-core-util.js +20 -0
- package/lib/node/pi/pi-agent-core-util.js.map +1 -0
- package/lib/node/pi/pi-types.d.ts +7 -0
- package/lib/node/pi/pi-types.d.ts.map +1 -0
- package/lib/node/pi/pi-types.js +3 -0
- package/lib/node/pi/pi-types.js.map +1 -0
- package/lib/node/test/index.d.ts +3 -0
- package/lib/node/test/index.d.ts.map +1 -0
- package/lib/node/test/index.js +21 -0
- package/lib/node/test/index.js.map +1 -0
- package/lib/node/test/test-container.d.ts +8 -0
- package/lib/node/test/test-container.d.ts.map +1 -0
- package/lib/node/test/test-container.js +14 -0
- package/lib/node/test/test-container.js.map +1 -0
- package/package.json +94 -4
- package/src/node/agent/agent-factory.spec.ts +97 -0
- package/src/node/agent/agent-factory.ts +60 -0
- package/src/node/agent/index.ts +1 -0
- package/src/node/agent-protocol.ts +39 -0
- package/src/node/error/errors.ts +20 -0
- package/src/node/error/index.ts +1 -0
- package/src/node/event/agent-event-util.spec.ts +87 -0
- package/src/node/event/agent-event-util.ts +79 -0
- package/src/node/event/index.ts +1 -0
- package/src/node/index.ts +5 -0
- package/src/node/module.ts +4 -0
- package/src/node/pi/index.ts +2 -0
- package/src/node/pi/pi-agent-core-util.ts +19 -0
- package/src/node/pi/pi-types.ts +8 -0
- package/src/node/test/index.ts +2 -0
- package/src/node/test/test-container.ts +15 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/pi/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,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("./pi-agent-core-util"), exports);
|
|
18
|
+
__exportStar(require("./pi-types"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/pi/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,6CAA2B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The module namespace of `@earendil-works/pi-agent-core`. */
|
|
2
|
+
export type PiAgentCore = typeof import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } });
|
|
3
|
+
export declare namespace PiAgentCoreUtil {
|
|
4
|
+
/** Loads pi-agent-core once, with a dynamic `import()`: it is an ES module package. */
|
|
5
|
+
function load(): Promise<PiAgentCore>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=pi-agent-core-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-agent-core-util.d.ts","sourceRoot":"","sources":["../../../src/node/pi/pi-agent-core-util.ts"],"names":[],"mappings":"AAEA,+DAA+D;AAC/D,MAAM,MAAM,WAAW,GAAG,cAAc,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,CAAE,CAAC;AAEnH,yBAAiB,eAAe,CAAC;IAG7B,uFAAuF;IACvF,SAAgB,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,CAQ3C;CACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PiAgentCoreUtil = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
var PiAgentCoreUtil;
|
|
6
|
+
(function (PiAgentCoreUtil) {
|
|
7
|
+
let core;
|
|
8
|
+
/** Loads pi-agent-core once, with a dynamic `import()`: it is an ES module package. */
|
|
9
|
+
function load() {
|
|
10
|
+
core !== null && core !== void 0 ? core : (core = import('@earendil-works/pi-agent-core').catch(cause => {
|
|
11
|
+
core = undefined;
|
|
12
|
+
throw new error_1.AgentError('Cannot load @earendil-works/pi-agent-core. Install it next to @celljs/ai-agent; it needs Node.js >= 22.19.0 or Bun.', {
|
|
13
|
+
cause,
|
|
14
|
+
});
|
|
15
|
+
}));
|
|
16
|
+
return core;
|
|
17
|
+
}
|
|
18
|
+
PiAgentCoreUtil.load = load;
|
|
19
|
+
})(PiAgentCoreUtil || (exports.PiAgentCoreUtil = PiAgentCoreUtil = {}));
|
|
20
|
+
//# sourceMappingURL=pi-agent-core-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-agent-core-util.js","sourceRoot":"","sources":["../../../src/node/pi/pi-agent-core-util.ts"],"names":[],"mappings":";;;AAAA,oCAAsC;AAKtC,IAAiB,eAAe,CAa/B;AAbD,WAAiB,eAAe;IAC5B,IAAI,IAAsC,CAAC;IAE3C,uFAAuF;IACvF,SAAgB,IAAI;QAChB,IAAI,aAAJ,IAAI,cAAJ,IAAI,IAAJ,IAAI,GAAK,MAAM,CAAC,+BAA+B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAC3D,IAAI,GAAG,SAAS,CAAC;YACjB,MAAM,IAAI,kBAAU,CAAC,qHAAqH,EAAE;gBACxI,KAAK;aACR,CAAC,CAAC;QACP,CAAC,CAAC,EAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC;IARe,gBAAA,IAAI,OAQnB,CAAA;AACL,CAAC,EAbgB,eAAe,aAAf,eAAe,GAAf,eAAe,QAa/B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Agent = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).Agent;
|
|
2
|
+
export type AgentEvent = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).AgentEvent;
|
|
3
|
+
export type AgentMessage = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).AgentMessage;
|
|
4
|
+
export type AgentToolResult<T = any> = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).AgentToolResult<T>;
|
|
5
|
+
export type AgentToolUpdateCallback<T = any> = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).AgentToolUpdateCallback<T>;
|
|
6
|
+
export type ThinkingLevel = import('@earendil-works/pi-agent-core', { with: { 'resolution-mode': 'import' } }).ThinkingLevel;
|
|
7
|
+
//# sourceMappingURL=pi-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.d.ts","sourceRoot":"","sources":["../../../src/node/pi/pi-types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,KAAK,GAAG,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,KAAK,CAAC;AAC5G,MAAM,MAAM,UAAU,GAAG,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,UAAU,CAAC;AACtH,MAAM,MAAM,YAAY,GAAG,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,YAAY,CAAC;AAC1H,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AAC5I,MAAM,MAAM,uBAAuB,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,uBAAuB,CAAC,CAAC,CAAC,CAAC;AAC5J,MAAM,MAAM,aAAa,GAAG,OAAO,+BAA+B,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-types.js","sourceRoot":"","sources":["../../../src/node/pi/pi-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/test/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC7E,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
exports.FauxPiModels = void 0;
|
|
18
|
+
var test_1 = require("@celljs/ai-pi/lib/node/test");
|
|
19
|
+
Object.defineProperty(exports, "FauxPiModels", { enumerable: true, get: function () { return test_1.FauxPiModels; } });
|
|
20
|
+
__exportStar(require("./test-container"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/test/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAA6E;AAApE,oGAAA,YAAY,OAAA;AACrB,mDAAiC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createPiTestContainer, type PiTestContainer } from '@celljs/ai-pi/lib/node/test';
|
|
2
|
+
import type { AgentOptions } from '../agent-protocol';
|
|
3
|
+
import '../index';
|
|
4
|
+
type ContainerModule = Parameters<typeof createPiTestContainer>[1];
|
|
5
|
+
/** A container with ai-core, ai-pi, this package and the scripted `FauxPiModels` as the agents' model. */
|
|
6
|
+
export declare function createAgentTestContainer(options?: AgentOptions, ...modules: ContainerModule[]): Promise<PiTestContainer>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=test-container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-container.d.ts","sourceRoot":"","sources":["../../../src/node/test/test-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAgB,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAExG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,UAAU,CAAC;AAIlB,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE,0GAA0G;AAC1G,wBAAsB,wBAAwB,CAAC,OAAO,GAAE,YAAiB,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAIlI"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAgentTestContainer = createAgentTestContainer;
|
|
4
|
+
const test_1 = require("@celljs/ai-pi/lib/node/test");
|
|
5
|
+
const core_1 = require("@celljs/core");
|
|
6
|
+
require("../index");
|
|
7
|
+
const agentModule = (0, core_1.autoBind)();
|
|
8
|
+
/** A container with ai-core, ai-pi, this package and the scripted `FauxPiModels` as the agents' model. */
|
|
9
|
+
async function createAgentTestContainer(options = {}, ...modules) {
|
|
10
|
+
const test = await (0, test_1.createPiTestContainer)({}, agentModule, ...modules);
|
|
11
|
+
core_1.currentThis.cellProps.cell.ai.agent = { model: test_1.FauxPiModels.MODEL, ...options };
|
|
12
|
+
return test;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=test-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/node/test/test-container.ts"],"names":[],"mappings":";;;AAAA,sDAAwG;AACxG,uCAAqD;AAErD,oBAAkB;AAElB,MAAM,WAAW,GAAG,IAAA,eAAQ,GAAE,CAAC;AAI/B,0GAA0G;AACnG,KAAK,mCAAmC,OAAO,GAAiB,EAAE,EAAE,GAAG,OAA0B;IACpG,MAAM,IAAI,GAAG,MAAM,IAAA,4BAAqB,EAAC,EAAE,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC;IACtE,kBAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,mBAAY,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;IAChF,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ai-agent",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "General-purpose pi agents (pi-agent-core) with tools as Cell components",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cell-component"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/cellbang/cell",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/cellbang/cell/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/cellbang/cell.git"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22.19.0"
|
|
19
|
+
},
|
|
20
|
+
"main": "lib/node/index.js",
|
|
21
|
+
"typings": "lib/node/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"esm",
|
|
25
|
+
"src",
|
|
26
|
+
"cell.yml"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
30
|
+
"clean": "rm -rf lib esm *.tsbuildinfo",
|
|
31
|
+
"test": "bun test --preload reflect-metadata ./lib",
|
|
32
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@celljs/ai-pi": "4.0.0",
|
|
36
|
+
"@celljs/core": "4.0.0",
|
|
37
|
+
"@earendil-works/pi-agent-core": "^1.5.0",
|
|
38
|
+
"tslib": "^2.8.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@celljs/ai-core": "4.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"cell": {
|
|
47
|
+
"modules": {
|
|
48
|
+
"backend": [
|
|
49
|
+
"lib/node/module"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"optionalDependencies": [
|
|
53
|
+
"@earendil-works/pi-agent-core"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"exports": {
|
|
57
|
+
".": {
|
|
58
|
+
"import": "./esm/node/index.js",
|
|
59
|
+
"default": "./lib/node/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./package.json": "./package.json",
|
|
62
|
+
"./lib/node": {
|
|
63
|
+
"import": "./esm/node/index.js",
|
|
64
|
+
"default": "./lib/node/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./lib/node/agent": {
|
|
67
|
+
"import": "./esm/node/agent/index.js",
|
|
68
|
+
"default": "./lib/node/agent/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./lib/node/error": {
|
|
71
|
+
"import": "./esm/node/error/index.js",
|
|
72
|
+
"default": "./lib/node/error/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./lib/node/event": {
|
|
75
|
+
"import": "./esm/node/event/index.js",
|
|
76
|
+
"default": "./lib/node/event/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./lib/node/pi": {
|
|
79
|
+
"import": "./esm/node/pi/index.js",
|
|
80
|
+
"default": "./lib/node/pi/index.js"
|
|
81
|
+
},
|
|
82
|
+
"./lib/node/test": {
|
|
83
|
+
"import": "./esm/node/test/index.js",
|
|
84
|
+
"default": "./lib/node/test/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./lib/*.js": {
|
|
87
|
+
"import": "./esm/*.js",
|
|
88
|
+
"default": "./lib/*.js"
|
|
89
|
+
},
|
|
90
|
+
"./lib/*": {
|
|
91
|
+
"import": "./esm/*.js",
|
|
92
|
+
"default": "./lib/*.js"
|
|
93
|
+
},
|
|
94
|
+
"./*": "./*"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { Autowired, autoBind, Component } from '@celljs/core';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
import { AgentFactory, AgentTool } from '../agent-protocol';
|
|
5
|
+
import { AgentToolNotFoundError } from '../error';
|
|
6
|
+
import { createAgentTestContainer } from '../test';
|
|
7
|
+
|
|
8
|
+
@Component()
|
|
9
|
+
export class Inventory {
|
|
10
|
+
count(item: string): number {
|
|
11
|
+
return item === 'apple' ? 3 : 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Component(AgentTool)
|
|
16
|
+
export class CountTool implements AgentTool<{ type: 'object' }> {
|
|
17
|
+
readonly name = 'count';
|
|
18
|
+
readonly label = 'Count';
|
|
19
|
+
readonly description = 'Counts the items in stock';
|
|
20
|
+
readonly parameters = { type: 'object' as const, properties: { item: { type: 'string' } }, required: ['item'] };
|
|
21
|
+
|
|
22
|
+
@Autowired(Inventory)
|
|
23
|
+
protected readonly inventory: Inventory;
|
|
24
|
+
|
|
25
|
+
async execute(_toolCallId: string, params: any) {
|
|
26
|
+
return { content: [{ type: 'text' as const, text: String(this.inventory.count(params.item)) }], details: {} };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Component(AgentTool)
|
|
31
|
+
export class ClockTool implements AgentTool<{ type: 'object' }> {
|
|
32
|
+
readonly name = 'clock';
|
|
33
|
+
readonly label = 'Clock';
|
|
34
|
+
readonly description = 'Tells the time';
|
|
35
|
+
readonly parameters = { type: 'object' as const, properties: {} };
|
|
36
|
+
|
|
37
|
+
async execute() {
|
|
38
|
+
return { content: [{ type: 'text' as const, text: 'noon' }], details: {} };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const toolsModule = autoBind();
|
|
43
|
+
|
|
44
|
+
const lastText = (messages: any[]) =>
|
|
45
|
+
messages
|
|
46
|
+
.filter(m => m.role === 'assistant')
|
|
47
|
+
.at(-1)
|
|
48
|
+
?.content.filter((c: any) => c.type === 'text')
|
|
49
|
+
.map((c: any) => c.text)
|
|
50
|
+
.join('');
|
|
51
|
+
|
|
52
|
+
describe('AgentFactory', () => {
|
|
53
|
+
it('creates agents that answer with the configured model', async () => {
|
|
54
|
+
const { container, faux } = await createAgentTestContainer({ systemPrompt: 'Be brief.' });
|
|
55
|
+
faux.reply('Hello!');
|
|
56
|
+
const agent = await container.get<AgentFactory>(AgentFactory).create();
|
|
57
|
+
await agent.prompt('Hi');
|
|
58
|
+
expect(lastText(agent.state.messages)).to.equal('Hello!');
|
|
59
|
+
expect(JSON.stringify(faux.contexts[0])).to.include('Be brief.');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('gives agents the AgentTool components, with their injected services', async () => {
|
|
63
|
+
const { container, faux } = await createAgentTestContainer({}, toolsModule);
|
|
64
|
+
faux.reply({ tool: 'count', args: { item: 'apple' } }, 'There are 3 apples.');
|
|
65
|
+
const agent = await container.get<AgentFactory>(AgentFactory).create();
|
|
66
|
+
expect(agent.state.tools.map(t => t.name).sort()).to.deep.equal(['clock', 'count']);
|
|
67
|
+
await agent.prompt('How many apples?');
|
|
68
|
+
const result = agent.state.messages.find(m => m.role === 'toolResult') as any;
|
|
69
|
+
expect(result.content[0].text).to.equal('3');
|
|
70
|
+
expect(lastText(agent.state.messages)).to.equal('There are 3 apples.');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('selects tools by name, per agent or in the configuration', async () => {
|
|
74
|
+
const { container } = await createAgentTestContainer({ tools: ['clock'] }, toolsModule);
|
|
75
|
+
const factory = container.get<AgentFactory>(AgentFactory);
|
|
76
|
+
expect((await factory.create()).state.tools.map(t => t.name)).to.deep.equal(['clock']);
|
|
77
|
+
expect((await factory.create({ tools: ['count'] })).state.tools.map(t => t.name)).to.deep.equal(['count']);
|
|
78
|
+
let error: unknown;
|
|
79
|
+
await factory.create({ tools: ['missing'] }).catch(e => (error = e));
|
|
80
|
+
expect(error).to.be.instanceOf(AgentToolNotFoundError);
|
|
81
|
+
expect((error as Error).message)
|
|
82
|
+
.to.include('clock')
|
|
83
|
+
.and.include('count');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('continues a saved conversation', async () => {
|
|
87
|
+
const { container, faux } = await createAgentTestContainer();
|
|
88
|
+
const factory = container.get<AgentFactory>(AgentFactory);
|
|
89
|
+
faux.reply('First answer');
|
|
90
|
+
const first = await factory.create();
|
|
91
|
+
await first.prompt('First question');
|
|
92
|
+
faux.reply('Second answer');
|
|
93
|
+
const second = await factory.create({ messages: first.state.messages });
|
|
94
|
+
await second.prompt('Second question');
|
|
95
|
+
expect(JSON.stringify(faux.contexts[1])).to.include('First question').and.include('First answer');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PiModelsProvider } from '@celljs/ai-pi';
|
|
2
|
+
import { Autowired, Component, Optional, Value } from '@celljs/core';
|
|
3
|
+
import { AGENT_OPTIONS, type AgentCreateOptions, AgentFactory, type AgentOptions, AgentTool } from '../agent-protocol';
|
|
4
|
+
import { AgentModelMissingError, AgentToolNotFoundError } from '../error';
|
|
5
|
+
import { type Agent, PiAgentCoreUtil } from '../pi';
|
|
6
|
+
|
|
7
|
+
@Component(AgentFactory)
|
|
8
|
+
export class DefaultAgentFactory implements AgentFactory {
|
|
9
|
+
@Value(AGENT_OPTIONS)
|
|
10
|
+
protected readonly options?: AgentOptions;
|
|
11
|
+
|
|
12
|
+
@Autowired(PiModelsProvider)
|
|
13
|
+
protected readonly modelsProvider: PiModelsProvider;
|
|
14
|
+
|
|
15
|
+
@Autowired(AgentTool)
|
|
16
|
+
@Optional()
|
|
17
|
+
protected readonly tools: AgentTool[] = [];
|
|
18
|
+
|
|
19
|
+
async create(createOptions: AgentCreateOptions = {}): Promise<Agent> {
|
|
20
|
+
const options: AgentOptions = { ...this.options };
|
|
21
|
+
for (const [key, value] of Object.entries(createOptions)) {
|
|
22
|
+
if (value !== undefined && key !== 'messages') {
|
|
23
|
+
(options as any)[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const [core, models] = await Promise.all([PiAgentCoreUtil.load(), this.modelsProvider.provide()]);
|
|
27
|
+
const model = options.model ? await this.modelsProvider.resolve(options.model) : (await models.getAvailable())[0];
|
|
28
|
+
if (!model) {
|
|
29
|
+
throw new AgentModelMissingError();
|
|
30
|
+
}
|
|
31
|
+
return new core.Agent({
|
|
32
|
+
initialState: {
|
|
33
|
+
systemPrompt: options.systemPrompt ?? '',
|
|
34
|
+
model,
|
|
35
|
+
thinkingLevel: options.thinkingLevel ?? 'off',
|
|
36
|
+
tools: this.selectTools(options.tools),
|
|
37
|
+
messages: createOptions.messages ?? [],
|
|
38
|
+
},
|
|
39
|
+
streamFn: models.streamSimple.bind(models),
|
|
40
|
+
toolExecution: options.toolExecution,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected selectTools(names?: string[]): AgentTool[] {
|
|
45
|
+
const tools = this.tools ?? [];
|
|
46
|
+
if (!names) {
|
|
47
|
+
return tools;
|
|
48
|
+
}
|
|
49
|
+
return names.map(name => {
|
|
50
|
+
const tool = tools.find(t => t.name === name);
|
|
51
|
+
if (!tool) {
|
|
52
|
+
throw new AgentToolNotFoundError(
|
|
53
|
+
name,
|
|
54
|
+
tools.map(t => t.name),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return tool;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './agent-factory';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Agent, AgentMessage, ThinkingLevel } from './pi';
|
|
2
|
+
|
|
3
|
+
export const AgentTool = Symbol('AgentTool');
|
|
4
|
+
export const AgentFactory = Symbol('AgentFactory');
|
|
5
|
+
|
|
6
|
+
/** Configuration key of {@link AgentOptions}. */
|
|
7
|
+
export const AGENT_OPTIONS = 'cell.ai.agent';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A tool as a Cell component: pi-agent-core's `AgentTool` (`name`, `label`, `description`, JSON Schema
|
|
11
|
+
* `parameters`, `execute`). `execute` throws on failure. The same components are tools of coding agent
|
|
12
|
+
* sessions (@celljs/ai-coding-agent).
|
|
13
|
+
*/
|
|
14
|
+
export type AgentTool<TParameters extends object = object, TDetails = any> = import('@earendil-works/pi-agent-core', { with: {
|
|
15
|
+
'resolution-mode': 'import',
|
|
16
|
+
}}).AgentTool<TParameters, TDetails>;
|
|
17
|
+
|
|
18
|
+
/** `cell.ai.agent`. */
|
|
19
|
+
export interface AgentOptions {
|
|
20
|
+
/** `<provider>/<model id>` of pi-ai (@celljs/ai-pi). Default: the first model with credentials. */
|
|
21
|
+
model?: string;
|
|
22
|
+
systemPrompt?: string;
|
|
23
|
+
thinkingLevel?: ThinkingLevel;
|
|
24
|
+
/** Names of the AgentTool components the agent gets. Default: all of them. */
|
|
25
|
+
tools?: string[];
|
|
26
|
+
/** How the tool calls of one model response run. Default: parallel. */
|
|
27
|
+
toolExecution?: 'parallel' | 'sequential';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Options of one agent; they override `cell.ai.agent`. */
|
|
31
|
+
export interface AgentCreateOptions extends Omit<AgentOptions, 'toolExecution'> {
|
|
32
|
+
/** Conversation to continue, e.g. `agent.state.messages` saved earlier. */
|
|
33
|
+
messages?: AgentMessage[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Creates pi-agent-core `Agent`s with the models of @celljs/ai-pi and the {@link AgentTool} components. */
|
|
37
|
+
export interface AgentFactory {
|
|
38
|
+
create(options?: AgentCreateOptions): Promise<Agent>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CustomError } from '@celljs/core';
|
|
2
|
+
|
|
3
|
+
export class AgentError extends CustomError {}
|
|
4
|
+
|
|
5
|
+
export class AgentToolNotFoundError extends AgentError {
|
|
6
|
+
constructor(
|
|
7
|
+
readonly tool: string,
|
|
8
|
+
readonly available: string[],
|
|
9
|
+
) {
|
|
10
|
+
super(`No AgentTool component is named ${tool}. Known tools: ${available.length ? available.join(', ') : 'none; add one with @Component(AgentTool)'}.`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class AgentModelMissingError extends AgentError {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(
|
|
17
|
+
'No model is available for the agent: set cell.ai.agent.model ("<provider>/<model id>") and the API key of its provider (e.g. ANTHROPIC_API_KEY or cell.ai.pi.apiKeys).',
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './errors';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it } from 'bun:test';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { AgentFactory } from '../agent-protocol';
|
|
4
|
+
import { createAgentTestContainer } from '../test';
|
|
5
|
+
import { AgentEventUtil, type EventStreamResponse } from './agent-event-util';
|
|
6
|
+
|
|
7
|
+
class RecordingResponse implements EventStreamResponse {
|
|
8
|
+
readonly headers: Record<string, string> = {};
|
|
9
|
+
chunks = '';
|
|
10
|
+
writableEnded = false;
|
|
11
|
+
|
|
12
|
+
setHeader(name: string, value: string): void {
|
|
13
|
+
this.headers[name.toLowerCase()] = value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
write(chunk: string): void {
|
|
17
|
+
expect(this.writableEnded).to.equal(false);
|
|
18
|
+
this.chunks += chunk;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
end(): void {
|
|
22
|
+
this.writableEnded = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get frames(): { event: string; data: any }[] {
|
|
26
|
+
return this.chunks
|
|
27
|
+
.split('\n\n')
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.map(frame => {
|
|
30
|
+
const [event, data] = frame.split('\n');
|
|
31
|
+
return { event: event.slice('event: '.length), data: JSON.parse(data.slice('data: '.length)) };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('AgentEventUtil', () => {
|
|
37
|
+
describe('toWire', () => {
|
|
38
|
+
const usage = { input: 1, output: 2 };
|
|
39
|
+
const update = (assistantMessageEvent: any) => ({ type: 'message_update', message: { role: 'assistant', usage, content: [] }, assistantMessageEvent });
|
|
40
|
+
|
|
41
|
+
it('keeps the delta and the usage of message_update', () => {
|
|
42
|
+
const wire = AgentEventUtil.toWire(update({ type: 'text_delta', contentIndex: 0, delta: 'Hi', partial: { content: [] } }));
|
|
43
|
+
expect(wire).to.deep.equal({ type: 'message_update', usage, assistantMessageEvent: { type: 'text_delta', contentIndex: 0, delta: 'Hi' } });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('names the tool of toolcall_start', () => {
|
|
47
|
+
const partial = {
|
|
48
|
+
content: [
|
|
49
|
+
{ type: 'text', text: '' },
|
|
50
|
+
{ type: 'toolCall', id: 'call-1', name: 'greet', arguments: {} },
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
const wire = AgentEventUtil.toWire(update({ type: 'toolcall_start', contentIndex: 1, partial }));
|
|
54
|
+
expect(wire.assistantMessageEvent).to.deep.equal({ type: 'toolcall_start', contentIndex: 1, id: 'call-1', toolName: 'greet' });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('leaves other events unchanged', () => {
|
|
58
|
+
const event = { type: 'agent_end', messages: [] };
|
|
59
|
+
expect(AgentEventUtil.toWire(event)).to.equal(event);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('stream', () => {
|
|
64
|
+
it('writes the events of an agent run as Server-Sent Events and ends the response', async () => {
|
|
65
|
+
const { container, faux } = await createAgentTestContainer();
|
|
66
|
+
faux.reply('Hello from pi');
|
|
67
|
+
const agent = await container.get<AgentFactory>(AgentFactory).create();
|
|
68
|
+
const response = new RecordingResponse();
|
|
69
|
+
await AgentEventUtil.stream(agent, response, () => agent.prompt('hi'));
|
|
70
|
+
expect(response.headers['content-type']).to.equal('text/event-stream; charset=utf-8');
|
|
71
|
+
expect(response.writableEnded).to.equal(true);
|
|
72
|
+
const frames = response.frames;
|
|
73
|
+
expect(frames[0].event).to.equal('agent_start');
|
|
74
|
+
expect(frames.at(-1)!.event).to.equal('agent_end');
|
|
75
|
+
const deltas = frames.filter(f => f.data.assistantMessageEvent?.type === 'text_delta');
|
|
76
|
+
expect(deltas.map(f => f.data.assistantMessageEvent.delta).join('')).to.equal('Hello from pi');
|
|
77
|
+
expect(frames.every(f => f.event === f.data.type && !f.data.assistantMessageEvent?.partial)).to.equal(true);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('sends an error event when the run fails', async () => {
|
|
81
|
+
const response = new RecordingResponse();
|
|
82
|
+
await AgentEventUtil.stream({ subscribe: () => () => undefined }, response, () => Promise.reject(new Error('no credits')));
|
|
83
|
+
expect(response.frames).to.deep.equal([{ event: 'error', data: { type: 'error', message: 'no credits' } }]);
|
|
84
|
+
expect(response.writableEnded).to.equal(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|