@aigne/core 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,141 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var Runtime_1;
11
+ import { produce } from "immer";
12
+ import { merge } from "lodash";
13
+ import { nanoid } from "nanoid";
14
+ import { container, injectable } from "tsyringe";
15
+ import { TYPES } from "./constants";
16
+ import { FunctionAgent } from "./function-agent";
17
+ import { LLMAgent } from "./llm-agent";
18
+ import { LLMDecisionAgent } from "./llm-decision-agent";
19
+ import { LocalFunctionAgent } from "./local-function-agent";
20
+ import { OpenAPIAgent } from "./open-api-agent";
21
+ import { PipelineAgent } from "./pipeline-agent";
22
+ import { Runnable } from "./runnable";
23
+ import { OrderedRecord } from "./utils/ordered-map";
24
+ let Runtime = Runtime_1 = class Runtime {
25
+ constructor(options = {}) {
26
+ // support copy inner from a existing runtime, but not expose to public
27
+ const inner = options.inner;
28
+ if (inner instanceof RuntimeInner)
29
+ this.inner = inner;
30
+ else
31
+ this.inner = new RuntimeInner(options);
32
+ this.container = this.inner.container.createChildContainer();
33
+ this.container.register(TYPES.context, { useValue: this });
34
+ this.config = options.config || { ...this.inner.config };
35
+ this.state = options.state || { ...this.inner.state };
36
+ }
37
+ inner;
38
+ get options() {
39
+ return this.inner.options;
40
+ }
41
+ get id() {
42
+ return this.inner.id;
43
+ }
44
+ get name() {
45
+ return this.inner.name;
46
+ }
47
+ config;
48
+ state;
49
+ agents = new Proxy({}, { get: (_, prop) => this.resolveSync(prop.toString()) });
50
+ container;
51
+ setup(config) {
52
+ this.config = produce(this.config, (draft) => {
53
+ merge(draft, config);
54
+ });
55
+ }
56
+ register(...runnables) {
57
+ for (const runnable of runnables) {
58
+ OrderedRecord.pushOrUpdate(this.inner.runnableDefinitions, runnable instanceof Runnable ? runnable.definition : runnable);
59
+ }
60
+ }
61
+ resolveSync(idOrRunnable) {
62
+ const runnableId = typeof idOrRunnable === "string" ? idOrRunnable : idOrRunnable.id;
63
+ // Find runnable definition by id or name
64
+ let definition = this.inner.runnableDefinitions[runnableId] ??
65
+ OrderedRecord.find(this.inner.runnableDefinitions, (def) => def.name === runnableId);
66
+ if (!definition) {
67
+ // extract definition from runnable
68
+ if (idOrRunnable instanceof Runnable)
69
+ definition = idOrRunnable.definition;
70
+ // directly use runnable as definition
71
+ else if (typeof idOrRunnable === "object")
72
+ definition = idOrRunnable;
73
+ }
74
+ if (definition) {
75
+ const childContainer = this.container
76
+ .createChildContainer()
77
+ .register(TYPES.definition, { useValue: definition });
78
+ const result = childContainer.resolve(definition.type);
79
+ childContainer.dispose();
80
+ return result;
81
+ }
82
+ throw new Error(`Runnable not found: ${idOrRunnable}`);
83
+ }
84
+ async resolve(id) {
85
+ return this.resolveSync(id);
86
+ }
87
+ resolveDependency(token) {
88
+ return this.container.resolve(token);
89
+ }
90
+ copy(options) {
91
+ const clone = new Runtime_1({
92
+ ...options,
93
+ // Copy inner runtime
94
+ ...{ inner: this.inner },
95
+ });
96
+ return clone;
97
+ }
98
+ };
99
+ Runtime = Runtime_1 = __decorate([
100
+ injectable(),
101
+ __metadata("design:paramtypes", [Object])
102
+ ], Runtime);
103
+ export { Runtime };
104
+ class RuntimeInner {
105
+ options;
106
+ constructor(options) {
107
+ this.options = options;
108
+ this.name = options.name;
109
+ this.id = options.id || this.name || nanoid();
110
+ this.config = options.config || {};
111
+ this.state = options.state || {};
112
+ this.container.register("pipeline_agent", { useClass: PipelineAgent });
113
+ this.container.register("llm_agent", { useClass: LLMAgent });
114
+ this.container.register("function_agent", { useClass: FunctionAgent });
115
+ this.container.register("llm_decision_agent", {
116
+ useClass: LLMDecisionAgent,
117
+ });
118
+ this.container.register("local_function_agent", {
119
+ useClass: LocalFunctionAgent,
120
+ });
121
+ this.container.register("open_api_agent", { useClass: OpenAPIAgent });
122
+ if (options.functionRunner)
123
+ this.registerDependency(TYPES.functionRunner, options.functionRunner);
124
+ if (options.llmModel)
125
+ this.registerDependency(TYPES.llmModel, options.llmModel);
126
+ }
127
+ id;
128
+ name;
129
+ config;
130
+ state;
131
+ container = container.createChildContainer();
132
+ runnableDefinitions = OrderedRecord.fromArray([]);
133
+ registerDependency(token, dependency) {
134
+ if (typeof dependency === "function")
135
+ this.container.register(token, {
136
+ useClass: dependency,
137
+ });
138
+ else
139
+ this.container.register(token, { useValue: dependency });
140
+ }
141
+ }
@@ -6,5 +6,6 @@ export * from "./nullable";
6
6
  export * from "./omit";
7
7
  export * from "./open-api-parameter";
8
8
  export * from "./ordered-map";
9
+ export * from "./partial";
9
10
  export * from "./stream-utils";
10
11
  export * from "./union";
@@ -6,5 +6,6 @@ export * from "./nullable";
6
6
  export * from "./omit";
7
7
  export * from "./open-api-parameter";
8
8
  export * from "./ordered-map";
9
+ export * from "./partial";
9
10
  export * from "./stream-utils";
10
11
  export * from "./union";
@@ -0,0 +1,3 @@
1
+ export type DeepPartial<T> = T extends object ? {
2
+ [P in keyof T]?: DeepPartial<T[P]>;
3
+ } : T;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "AIGNE core library",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -31,12 +31,18 @@
31
31
  "tsyringe": "^4.8.0",
32
32
  "ufo": "^1.5.4"
33
33
  },
34
+ "peerDependencies": {
35
+ "@google/generative-ai": "^0.21.0",
36
+ "openai": "^4.79.1"
37
+ },
34
38
  "devDependencies": {
39
+ "@google/generative-ai": "^0.21.0",
35
40
  "@tsconfig/recommended": "^1.0.8",
36
41
  "@types/bun": "^1.1.17",
37
42
  "@types/lodash": "^4.17.14",
38
43
  "core-js": "^3.40.0",
39
44
  "npm-run-all": "^4.1.5",
45
+ "openai": "^4.79.1",
40
46
  "reflect-metadata": "^0.2.2",
41
47
  "rimraf": "^6.0.1",
42
48
  "typescript": "^5.7.3"