@aigne/core 0.4.209 → 0.4.211-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/lib/cjs/api-agent.js +70 -0
  2. package/lib/cjs/data-type-schema.js +46 -0
  3. package/lib/cjs/data-type.js +2 -0
  4. package/lib/cjs/definitions/api-parameter.js +10 -0
  5. package/lib/cjs/definitions/data-type-schema.js +3 -3
  6. package/lib/cjs/definitions/open-api.js +2 -0
  7. package/lib/cjs/index.js +3 -0
  8. package/lib/cjs/memory.js +32 -0
  9. package/lib/cjs/open-api-agent.js +62 -0
  10. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  11. package/lib/cjs/utils/constants.js +4 -0
  12. package/lib/cjs/utils/fetch-api.js +35 -0
  13. package/lib/cjs/utils/fetch-open-api.js +30 -0
  14. package/lib/cjs/utils/fetch.js +20 -0
  15. package/lib/cjs/utils/flatten-openapi.js +14 -0
  16. package/lib/cjs/utils/format-parameter.js +126 -0
  17. package/lib/cjs/utils/index.js +3 -0
  18. package/lib/cjs/utils/open-api-parameter.js +84 -0
  19. package/lib/esm/api-agent.js +67 -0
  20. package/lib/esm/data-type-schema.js +43 -0
  21. package/lib/esm/data-type.js +1 -0
  22. package/lib/esm/definitions/api-parameter.js +7 -0
  23. package/lib/esm/definitions/data-type-schema.js +1 -1
  24. package/lib/esm/definitions/open-api.js +1 -0
  25. package/lib/esm/index.js +3 -0
  26. package/lib/esm/memory.js +27 -0
  27. package/lib/esm/open-api-agent.js +59 -0
  28. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  29. package/lib/esm/utils/constants.js +1 -0
  30. package/lib/esm/utils/fetch-api.js +31 -0
  31. package/lib/esm/utils/fetch-open-api.js +26 -0
  32. package/lib/esm/utils/fetch.js +17 -0
  33. package/lib/esm/utils/flatten-openapi.js +11 -0
  34. package/lib/esm/utils/format-parameter.js +116 -0
  35. package/lib/esm/utils/index.js +3 -0
  36. package/lib/esm/utils/open-api-parameter.js +78 -0
  37. package/lib/types/api-agent.d.ts +53 -0
  38. package/lib/types/context.d.ts +1 -0
  39. package/lib/types/data-type-schema.d.ts +46 -0
  40. package/lib/types/data-type.d.ts +32 -0
  41. package/lib/types/definitions/api-parameter.d.ts +55 -0
  42. package/lib/types/definitions/data-type-schema.d.ts +1 -1
  43. package/lib/types/definitions/open-api.d.ts +36 -0
  44. package/lib/types/index.d.ts +3 -0
  45. package/lib/types/memory.d.ts +184 -0
  46. package/lib/types/open-api-agent.d.ts +55 -0
  47. package/lib/types/tsconfig.tsbuildinfo +1 -1
  48. package/lib/types/utils/constants.d.ts +1 -0
  49. package/lib/types/utils/fetch-api.d.ts +3 -0
  50. package/lib/types/utils/fetch-open-api.d.ts +2 -0
  51. package/lib/types/utils/fetch.d.ts +1 -0
  52. package/lib/types/utils/flatten-openapi.d.ts +25 -0
  53. package/lib/types/utils/format-parameter.d.ts +6 -0
  54. package/lib/types/utils/index.d.ts +3 -0
  55. package/lib/types/utils/open-api-parameter.d.ts +7 -0
  56. package/package.json +2 -20
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OpenAPIAgent = void 0;
16
+ const lodash_1 = require("lodash");
17
+ const nanoid_1 = require("nanoid");
18
+ const tsyringe_1 = require("tsyringe");
19
+ const agent_1 = require("./agent");
20
+ const constants_1 = require("./constants");
21
+ const data_type_schema_1 = require("./definitions/data-type-schema");
22
+ const fetch_api_1 = require("./utils/fetch-api");
23
+ const format_parameter_1 = require("./utils/format-parameter");
24
+ let OpenAPIAgent = class OpenAPIAgent extends agent_1.Agent {
25
+ definition;
26
+ static create = create;
27
+ constructor(definition, context) {
28
+ super(definition, context);
29
+ this.definition = definition;
30
+ }
31
+ async process(input) {
32
+ const { definition: { url, method, auth, inputs }, context, } = this;
33
+ if (!url)
34
+ throw new Error('API url is required');
35
+ const api = {
36
+ url,
37
+ method,
38
+ auth,
39
+ };
40
+ const request = (0, format_parameter_1.formatRequest)(api, inputs, input);
41
+ const contextState = (0, lodash_1.pick)(context?.state, ['userId', 'sessionId']);
42
+ request.query = { ...contextState, ...(request.query || {}) };
43
+ return this.fetch(request);
44
+ }
45
+ fetch(request) {
46
+ return (0, fetch_api_1.fetchApi)(request);
47
+ }
48
+ };
49
+ exports.OpenAPIAgent = OpenAPIAgent;
50
+ exports.OpenAPIAgent = OpenAPIAgent = __decorate([
51
+ (0, tsyringe_1.injectable)(),
52
+ __param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
53
+ __param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
54
+ __metadata("design:paramtypes", [Object, Object])
55
+ ], OpenAPIAgent);
56
+ function create({ context, ...options }) {
57
+ const agentId = options.id || options.name || (0, nanoid_1.nanoid)();
58
+ const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
59
+ const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
60
+ return new OpenAPIAgent({
61
+ id: agentId,
62
+ name: options.name,
63
+ type: 'api_agent',
64
+ inputs,
65
+ outputs,
66
+ url: options.url,
67
+ method: options.method,
68
+ auth: options.auth,
69
+ }, context);
70
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schemaToDataType = schemaToDataType;
4
+ const nanoid_1 = require("nanoid");
5
+ const utils_1 = require("./utils");
6
+ function schemaToDataType(dataType) {
7
+ return utils_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
8
+ const base = {
9
+ ...schema,
10
+ id: (0, nanoid_1.nanoid)(),
11
+ name,
12
+ };
13
+ switch (schema.type) {
14
+ case 'string':
15
+ return {
16
+ ...base,
17
+ type: 'string',
18
+ };
19
+ case 'number':
20
+ return {
21
+ ...base,
22
+ type: 'number',
23
+ };
24
+ case 'boolean':
25
+ return {
26
+ ...base,
27
+ type: 'boolean',
28
+ };
29
+ case 'object':
30
+ return {
31
+ ...base,
32
+ type: 'object',
33
+ properties: schemaToDataType(schema.properties),
34
+ };
35
+ case 'array':
36
+ return {
37
+ ...base,
38
+ type: 'array',
39
+ items: utils_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === 'items'),
40
+ };
41
+ default: {
42
+ throw new Error(`Unknown data type: ${schema.type}`);
43
+ }
44
+ }
45
+ }));
46
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTPMethod = void 0;
4
+ var HTTPMethod;
5
+ (function (HTTPMethod) {
6
+ HTTPMethod["GET"] = "GET";
7
+ HTTPMethod["POST"] = "POST";
8
+ HTTPMethod["PUT"] = "PUT";
9
+ HTTPMethod["DELETE"] = "DELETE";
10
+ })(HTTPMethod || (exports.HTTPMethod = HTTPMethod = {}));
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schemaToDataType = schemaToDataType;
4
4
  const nanoid_1 = require("nanoid");
5
- const utils_1 = require("../utils");
5
+ const ordered_map_1 = require("../utils/ordered-map");
6
6
  function schemaToDataType(dataType) {
7
- return utils_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
7
+ return ordered_map_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
8
8
  const base = {
9
9
  ...schema,
10
10
  id: (0, nanoid_1.nanoid)(),
@@ -36,7 +36,7 @@ function schemaToDataType(dataType) {
36
36
  return {
37
37
  ...base,
38
38
  type: 'array',
39
- items: schema.items && utils_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === 'items'),
39
+ items: schema.items && ordered_map_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === 'items'),
40
40
  };
41
41
  default: {
42
42
  throw new Error(`Unknown data type: ${schema.type}`);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/lib/cjs/index.js CHANGED
@@ -18,6 +18,8 @@ __exportStar(require("./utils"), exports);
18
18
  __exportStar(require("./constants"), exports);
19
19
  __exportStar(require("./definitions/data-type"), exports);
20
20
  __exportStar(require("./definitions/data-type-schema"), exports);
21
+ __exportStar(require("./definitions/open-api"), exports);
22
+ __exportStar(require("./definitions/memory"), exports);
21
23
  __exportStar(require("./context"), exports);
22
24
  __exportStar(require("./runnable"), exports);
23
25
  __exportStar(require("./agent"), exports);
@@ -28,4 +30,5 @@ __exportStar(require("./function-agent"), exports);
28
30
  __exportStar(require("./function-runner"), exports);
29
31
  __exportStar(require("./llm-decision-agent"), exports);
30
32
  __exportStar(require("./local-function-agent"), exports);
33
+ __exportStar(require("./open-api-agent"), exports);
31
34
  __exportStar(require("./memorable"), exports);
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryRunner = exports.Memory = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const runnable_1 = require("./runnable");
6
+ const utils_1 = require("./utils");
7
+ class Memory extends runnable_1.Runnable {
8
+ constructor() {
9
+ super({
10
+ id: 'memory',
11
+ type: 'memory',
12
+ name: 'Memory',
13
+ inputs: utils_1.OrderedRecord.fromArray([]),
14
+ outputs: utils_1.OrderedRecord.fromArray([]),
15
+ });
16
+ }
17
+ }
18
+ exports.Memory = Memory;
19
+ class MemoryRunner extends runnable_1.Runnable {
20
+ constructor(name) {
21
+ const id = `${(0, lodash_1.camelCase)(name)}_runner`;
22
+ super({
23
+ id,
24
+ type: id,
25
+ name: `${(0, lodash_1.startCase)(name)} Runner`,
26
+ description: `${(0, lodash_1.startCase)(name)} Runner`,
27
+ inputs: utils_1.OrderedRecord.fromArray([]),
28
+ outputs: utils_1.OrderedRecord.fromArray([]),
29
+ });
30
+ }
31
+ }
32
+ exports.MemoryRunner = MemoryRunner;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OpenAPIAgent = void 0;
16
+ const nanoid_1 = require("nanoid");
17
+ const tsyringe_1 = require("tsyringe");
18
+ const agent_1 = require("./agent");
19
+ const constants_1 = require("./constants");
20
+ const data_type_schema_1 = require("./definitions/data-type-schema");
21
+ const fetch_open_api_1 = require("./utils/fetch-open-api");
22
+ const open_api_parameter_1 = require("./utils/open-api-parameter");
23
+ let OpenAPIAgent = class OpenAPIAgent extends agent_1.Agent {
24
+ definition;
25
+ static create = create;
26
+ constructor(definition, context) {
27
+ super(definition, context);
28
+ this.definition = definition;
29
+ }
30
+ async process(input) {
31
+ const { url, method = 'get', auth, inputs } = this.definition;
32
+ if (!url)
33
+ throw new Error('API url is required');
34
+ const request = await (0, open_api_parameter_1.formatOpenAPIRequest)({ url, method, auth }, inputs, input);
35
+ return this.fetch(request);
36
+ }
37
+ fetch(request) {
38
+ return (0, fetch_open_api_1.fetchOpenApi)(request);
39
+ }
40
+ };
41
+ exports.OpenAPIAgent = OpenAPIAgent;
42
+ exports.OpenAPIAgent = OpenAPIAgent = __decorate([
43
+ (0, tsyringe_1.injectable)(),
44
+ __param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
45
+ __param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
46
+ __metadata("design:paramtypes", [Object, Object])
47
+ ], OpenAPIAgent);
48
+ function create({ context, ...options }) {
49
+ const agentId = options.id || options.name || (0, nanoid_1.nanoid)();
50
+ const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
51
+ const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
52
+ return new OpenAPIAgent({
53
+ id: agentId,
54
+ name: options.name,
55
+ type: 'open_api_agent',
56
+ inputs,
57
+ outputs,
58
+ url: options.url,
59
+ method: options.method,
60
+ auth: options.auth,
61
+ }, context);
62
+ }