@aigne/core 0.0.2 → 0.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.
Files changed (168) hide show
  1. package/lib/cjs/index.js +1 -1
  2. package/lib/cjs/types/index.js +2 -4
  3. package/lib/esm/index.js +1 -1
  4. package/lib/esm/types/index.js +2 -4
  5. package/lib/types/index.d.ts +1 -1
  6. package/lib/types/types/agent.d.ts +5 -0
  7. package/lib/types/types/index.d.ts +2 -4
  8. package/lib/types/types/runnable.d.ts +20 -0
  9. package/package.json +6 -7
  10. package/lib/cjs/assistant/generate-output.js +0 -101
  11. package/lib/cjs/assistant/select-agent.js +0 -76
  12. package/lib/cjs/assistant/type.js +0 -11
  13. package/lib/cjs/common/aid.js +0 -42
  14. package/lib/cjs/common/index.js +0 -238
  15. package/lib/cjs/common/resource-manager.js +0 -199
  16. package/lib/cjs/constants.js +0 -9
  17. package/lib/cjs/executor/agent.js +0 -10
  18. package/lib/cjs/executor/aigc.js +0 -28
  19. package/lib/cjs/executor/api.js +0 -64
  20. package/lib/cjs/executor/base.js +0 -676
  21. package/lib/cjs/executor/blocklet.js +0 -25
  22. package/lib/cjs/executor/call-agent.js +0 -105
  23. package/lib/cjs/executor/decision.js +0 -478
  24. package/lib/cjs/executor/image-blender.js +0 -32
  25. package/lib/cjs/executor/index.js +0 -81
  26. package/lib/cjs/executor/llm.js +0 -379
  27. package/lib/cjs/executor/logic.js +0 -167
  28. package/lib/cjs/libs/blocklet/vc.js +0 -92
  29. package/lib/cjs/libs/openapi/request/index.js +0 -24
  30. package/lib/cjs/libs/openapi/request/util.js +0 -146
  31. package/lib/cjs/libs/openapi/types/index.js +0 -17
  32. package/lib/cjs/libs/openapi/util/call.js +0 -15
  33. package/lib/cjs/libs/openapi/util/check-schema.js +0 -67
  34. package/lib/cjs/libs/openapi/util/convert-schema.js +0 -44
  35. package/lib/cjs/libs/openapi/util/flatten-open-api.js +0 -21
  36. package/lib/cjs/libs/openapi/util/get-open-api-i18n-text.js +0 -7
  37. package/lib/cjs/runtime/resource-blocklet.js +0 -5
  38. package/lib/cjs/runtime/runtime.js +0 -143
  39. package/lib/cjs/types/assistant/index.js +0 -31
  40. package/lib/cjs/types/assistant/mustache/ReadableMustache.js +0 -69
  41. package/lib/cjs/types/assistant/mustache/directive.js +0 -35
  42. package/lib/cjs/types/assistant/mustache/mustache.js +0 -688
  43. package/lib/cjs/types/resource/index.js +0 -47
  44. package/lib/cjs/types/resource/project.js +0 -35
  45. package/lib/cjs/types/runtime/error.js +0 -18
  46. package/lib/cjs/types/runtime/index.js +0 -37
  47. package/lib/cjs/types/runtime/runtime-resource-blocklet-state.js +0 -4
  48. package/lib/cjs/types/runtime/schema.js +0 -259
  49. package/lib/cjs/utils/cron-job.js +0 -48
  50. package/lib/cjs/utils/extract-metadata-transform.js +0 -58
  51. package/lib/cjs/utils/extract-metadata-transform.test.js +0 -61
  52. package/lib/cjs/utils/fs.js +0 -49
  53. package/lib/cjs/utils/get-blocklet-agent.js +0 -351
  54. package/lib/cjs/utils/geti.js +0 -37
  55. package/lib/cjs/utils/is-non-nullable.js +0 -20
  56. package/lib/cjs/utils/render-message.js +0 -23
  57. package/lib/cjs/utils/resolve-secret-inputs.js +0 -49
  58. package/lib/cjs/utils/retry.js +0 -19
  59. package/lib/cjs/utils/task-id.js +0 -7
  60. package/lib/cjs/utils/tool-calls-transform.js +0 -18
  61. package/lib/esm/assistant/generate-output.js +0 -91
  62. package/lib/esm/assistant/select-agent.js +0 -71
  63. package/lib/esm/assistant/type.js +0 -7
  64. package/lib/esm/common/aid.js +0 -38
  65. package/lib/esm/common/index.js +0 -232
  66. package/lib/esm/common/resource-manager.js +0 -192
  67. package/lib/esm/constants.js +0 -6
  68. package/lib/esm/executor/agent.js +0 -6
  69. package/lib/esm/executor/aigc.js +0 -24
  70. package/lib/esm/executor/api.js +0 -34
  71. package/lib/esm/executor/base.js +0 -668
  72. package/lib/esm/executor/blocklet.js +0 -21
  73. package/lib/esm/executor/call-agent.js +0 -98
  74. package/lib/esm/executor/decision.js +0 -471
  75. package/lib/esm/executor/image-blender.js +0 -25
  76. package/lib/esm/executor/index.js +0 -74
  77. package/lib/esm/executor/llm.js +0 -372
  78. package/lib/esm/executor/logic.js +0 -160
  79. package/lib/esm/libs/blocklet/vc.js +0 -85
  80. package/lib/esm/libs/openapi/request/index.js +0 -20
  81. package/lib/esm/libs/openapi/request/util.js +0 -136
  82. package/lib/esm/libs/openapi/types/index.js +0 -1
  83. package/lib/esm/libs/openapi/util/call.js +0 -8
  84. package/lib/esm/libs/openapi/util/check-schema.js +0 -62
  85. package/lib/esm/libs/openapi/util/convert-schema.js +0 -42
  86. package/lib/esm/libs/openapi/util/flatten-open-api.js +0 -19
  87. package/lib/esm/libs/openapi/util/get-open-api-i18n-text.js +0 -5
  88. package/lib/esm/runtime/resource-blocklet.js +0 -2
  89. package/lib/esm/runtime/runtime.js +0 -136
  90. package/lib/esm/types/assistant/index.js +0 -9
  91. package/lib/esm/types/assistant/mustache/ReadableMustache.js +0 -63
  92. package/lib/esm/types/assistant/mustache/directive.js +0 -29
  93. package/lib/esm/types/assistant/mustache/mustache.js +0 -686
  94. package/lib/esm/types/resource/index.js +0 -26
  95. package/lib/esm/types/resource/project.js +0 -29
  96. package/lib/esm/types/runtime/error.js +0 -14
  97. package/lib/esm/types/runtime/index.js +0 -20
  98. package/lib/esm/types/runtime/runtime-resource-blocklet-state.js +0 -1
  99. package/lib/esm/types/runtime/schema.js +0 -249
  100. package/lib/esm/utils/cron-job.js +0 -44
  101. package/lib/esm/utils/extract-metadata-transform.js +0 -54
  102. package/lib/esm/utils/extract-metadata-transform.test.js +0 -59
  103. package/lib/esm/utils/fs.js +0 -41
  104. package/lib/esm/utils/get-blocklet-agent.js +0 -344
  105. package/lib/esm/utils/geti.js +0 -30
  106. package/lib/esm/utils/is-non-nullable.js +0 -13
  107. package/lib/esm/utils/render-message.js +0 -20
  108. package/lib/esm/utils/resolve-secret-inputs.js +0 -46
  109. package/lib/esm/utils/retry.js +0 -16
  110. package/lib/esm/utils/task-id.js +0 -3
  111. package/lib/esm/utils/tool-calls-transform.js +0 -15
  112. package/lib/types/assistant/generate-output.d.ts +0 -29
  113. package/lib/types/assistant/select-agent.d.ts +0 -14
  114. package/lib/types/assistant/type.d.ts +0 -61
  115. package/lib/types/common/aid.d.ts +0 -18
  116. package/lib/types/common/index.d.ts +0 -7
  117. package/lib/types/common/resource-manager.d.ts +0 -88
  118. package/lib/types/constants.d.ts +0 -6
  119. package/lib/types/executor/agent.d.ts +0 -5
  120. package/lib/types/executor/aigc.d.ts +0 -9
  121. package/lib/types/executor/api.d.ts +0 -9
  122. package/lib/types/executor/base.d.ts +0 -209
  123. package/lib/types/executor/blocklet.d.ts +0 -9
  124. package/lib/types/executor/call-agent.d.ts +0 -12
  125. package/lib/types/executor/decision.d.ts +0 -20
  126. package/lib/types/executor/image-blender.d.ts +0 -9
  127. package/lib/types/executor/index.d.ts +0 -8
  128. package/lib/types/executor/llm.d.ts +0 -38
  129. package/lib/types/executor/logic.d.ts +0 -9
  130. package/lib/types/libs/blocklet/vc.d.ts +0 -17
  131. package/lib/types/libs/openapi/request/index.d.ts +0 -17
  132. package/lib/types/libs/openapi/request/util.d.ts +0 -40
  133. package/lib/types/libs/openapi/types/index.d.ts +0 -20
  134. package/lib/types/libs/openapi/util/call.d.ts +0 -2
  135. package/lib/types/libs/openapi/util/check-schema.d.ts +0 -3
  136. package/lib/types/libs/openapi/util/convert-schema.d.ts +0 -8
  137. package/lib/types/libs/openapi/util/flatten-open-api.d.ts +0 -3
  138. package/lib/types/libs/openapi/util/get-open-api-i18n-text.d.ts +0 -2
  139. package/lib/types/runtime/resource-blocklet.d.ts +0 -2
  140. package/lib/types/runtime/runtime.d.ts +0 -20
  141. package/lib/types/types/assistant/index.d.ts +0 -405
  142. package/lib/types/types/assistant/mustache/ReadableMustache.d.ts +0 -2
  143. package/lib/types/types/assistant/mustache/directive.d.ts +0 -6
  144. package/lib/types/types/assistant/mustache/mustache.d.ts +0 -2
  145. package/lib/types/types/common/index.d.ts +0 -45
  146. package/lib/types/types/resource/index.d.ts +0 -17
  147. package/lib/types/types/resource/project.d.ts +0 -41
  148. package/lib/types/types/runtime/agent.d.ts +0 -33
  149. package/lib/types/types/runtime/error.d.ts +0 -10
  150. package/lib/types/types/runtime/index.d.ts +0 -116
  151. package/lib/types/types/runtime/runtime-resource-blocklet-state.d.ts +0 -5
  152. package/lib/types/types/runtime/schema.d.ts +0 -110
  153. package/lib/types/utils/cron-job.d.ts +0 -22
  154. package/lib/types/utils/extract-metadata-transform.d.ts +0 -16
  155. package/lib/types/utils/extract-metadata-transform.test.d.ts +0 -1
  156. package/lib/types/utils/fs.d.ts +0 -9
  157. package/lib/types/utils/get-blocklet-agent.d.ts +0 -219
  158. package/lib/types/utils/geti.d.ts +0 -1
  159. package/lib/types/utils/is-non-nullable.d.ts +0 -2
  160. package/lib/types/utils/render-message.d.ts +0 -6
  161. package/lib/types/utils/resolve-secret-inputs.d.ts +0 -11
  162. package/lib/types/utils/retry.d.ts +0 -1
  163. package/lib/types/utils/task-id.d.ts +0 -1
  164. package/lib/types/utils/tool-calls-transform.d.ts +0 -2
  165. /package/lib/cjs/types/{runtime/agent.js → agent.js} +0 -0
  166. /package/lib/cjs/types/{common/index.js → runnable.js} +0 -0
  167. /package/lib/esm/types/{runtime/agent.js → agent.js} +0 -0
  168. /package/lib/esm/types/{common/index.js → runnable.js} +0 -0
@@ -1,92 +0,0 @@
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.authService = void 0;
7
- exports.issueVC = issueVC;
8
- const auth_1 = __importDefault(require("@blocklet/sdk/lib/service/auth"));
9
- const constants_1 = require("../../constants");
10
- exports.authService = new auth_1.default();
11
- async function issueVC({ context: { entry }, userDid, name, title, description, reissue = false, displayUrl, notify = true, }) {
12
- // NOTE: ensure name starts with AIGNE_ISSUE_VC_PREFIX to avoid conflict with internal passports such as admin/owner
13
- if (!name.startsWith(constants_1.AIGNE_ISSUE_VC_PREFIX))
14
- name = `${constants_1.AIGNE_ISSUE_VC_PREFIX}${name}`;
15
- await createPassportIfNotExist({ name, title, description });
16
- const userResult = await exports.authService.getUser(userDid, { includeTags: true });
17
- if (!userResult.user)
18
- throw new Error(`User not found ${userDid}`);
19
- if (!reissue) {
20
- const vc = userResult.user.passports.find((p) => p.role === name);
21
- if (vc)
22
- return { user: userResult.user, vc };
23
- }
24
- const issueResult = await exports.authService.issuePassportToUser({
25
- userDid,
26
- role: name,
27
- display: displayUrl ? { type: 'url', content: displayUrl } : undefined,
28
- notify,
29
- notification: JSON.stringify({
30
- title: `You just received a VC ${title}`,
31
- body: description,
32
- attachments: [
33
- {
34
- type: 'image',
35
- data: {
36
- url: displayUrl,
37
- alt: title,
38
- },
39
- },
40
- ],
41
- appInfo: {
42
- title: entry.project.name,
43
- // logo: getProjectIconUrl(entry.project.id, {
44
- // blockletDid: entry.blockletDid,
45
- // working: entry.working,
46
- // updatedAt: entry.project.updatedAt,
47
- // }),
48
- url: entry.appUrl,
49
- description: entry.project.description,
50
- },
51
- poweredBy: {
52
- name: 'AIGNE',
53
- url: 'https://www.aigne.io',
54
- },
55
- severity: 'success',
56
- }),
57
- });
58
- if (issueResult.code !== 'ok')
59
- throw new Error(`Issue VC failed got ${issueResult.code}`);
60
- const vc = issueResult.user.passports.findLast((p) => p.role === name);
61
- if (!vc)
62
- throw new Error('Issue VC got empty result');
63
- return { user: issueResult.user, vc };
64
- }
65
- const CREATE_PASSPORT_TASKS = {};
66
- async function createPassportIfNotExist({ name, title, description, }) {
67
- CREATE_PASSPORT_TASKS[name] ??= (async () => {
68
- try {
69
- let result = await exports.authService.getRole(name);
70
- if (!result.role) {
71
- // Create a role for custom display
72
- result = await exports.authService.createRole({
73
- title,
74
- name,
75
- description,
76
- permissions: [],
77
- extra: JSON.stringify({
78
- display: 'custom',
79
- types: [name],
80
- }),
81
- });
82
- }
83
- return result;
84
- }
85
- catch (error) {
86
- // NOTE: reset task if failed
87
- delete CREATE_PASSPORT_TASKS[name];
88
- throw error;
89
- }
90
- })();
91
- return CREATE_PASSPORT_TASKS[name];
92
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callBlockletApi = void 0;
4
- const component_1 = require("@blocklet/sdk/lib/component");
5
- const util_1 = require("./util");
6
- const callBlockletApi = (pathItem, data, options) => {
7
- const requestConfig = (0, util_1.getRequestConfig)(pathItem, data, {
8
- params: options?.params || {},
9
- data: options?.data || {},
10
- });
11
- const { headers, method, url, params, ...config } = requestConfig;
12
- const did = options?.user?.did || '';
13
- if (!pathItem.name)
14
- throw new Error('Blocklet name is required to call blocklet api');
15
- return (0, component_1.call)({
16
- ...config,
17
- method: method,
18
- name: pathItem.name,
19
- path: url,
20
- headers,
21
- params: { ...params, userId: did },
22
- });
23
- };
24
- exports.callBlockletApi = callBlockletApi;
@@ -1,146 +0,0 @@
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.getRequestConfig = void 0;
7
- exports.extractRequestBodyParameters = extractRequestBodyParameters;
8
- exports.getAllParameters = getAllParameters;
9
- exports.getRequiredFields = getRequiredFields;
10
- const convert_schema_1 = __importDefault(require("../util/convert-schema"));
11
- const getRequestConfig = (pathItem, requestData, options) => {
12
- let url = pathItem.path || '';
13
- const config = {
14
- method: pathItem.method,
15
- url,
16
- headers: {},
17
- params: options?.params || {},
18
- data: options?.data || {},
19
- cookies: {},
20
- body: {},
21
- };
22
- const data = { ...requestData };
23
- const requestBodyData = { ...data };
24
- for (const parameter of pathItem.parameters || []) {
25
- if (Object.prototype.hasOwnProperty.call(data, parameter.name)) {
26
- const value = data[parameter.name];
27
- switch (parameter.in) {
28
- case 'path':
29
- url = url.replace(`{${parameter.name}}`, encodeURIComponent(value));
30
- break;
31
- case 'query':
32
- config.params[parameter.name] = value;
33
- break;
34
- case 'header':
35
- config.headers[parameter.name] = value;
36
- break;
37
- case 'cookie':
38
- config.cookies[parameter.name] = value;
39
- break;
40
- default:
41
- throw new Error('Unsupported parameter type');
42
- }
43
- delete requestBodyData[parameter.name];
44
- }
45
- }
46
- if (['POST', 'PUT', 'PATCH'].includes(pathItem.method.toUpperCase()) && pathItem.requestBody) {
47
- config.headers['Content-Type'] = getContentType(pathItem.requestBody);
48
- config.data = getRequestBody(pathItem.requestBody, requestBodyData || {});
49
- }
50
- config.url = url;
51
- config.body = requestBodyData;
52
- return config;
53
- };
54
- exports.getRequestConfig = getRequestConfig;
55
- function getContentType(requestBody) {
56
- if (requestBody && requestBody.content) {
57
- const [firstMediaType] = Object.keys(requestBody.content);
58
- return firstMediaType || 'application/json';
59
- }
60
- return 'application/json';
61
- }
62
- function getRequestBody(requestBody, requestBodyData) {
63
- if (requestBody && requestBody.content) {
64
- const contentType = getContentType(requestBody);
65
- const mediaTypeObject = requestBody.content[contentType];
66
- if (mediaTypeObject && mediaTypeObject.schema) {
67
- switch (contentType) {
68
- case 'application/json':
69
- return JSON.stringify(requestBodyData);
70
- case 'application/x-www-form-urlencoded':
71
- return serializeFormEncoded(requestBodyData);
72
- case 'multipart/form-data':
73
- // eslint-disable-next-line no-case-declarations
74
- const formData = new FormData();
75
- Object.keys(requestBodyData).forEach((key) => {
76
- const value = requestBodyData[key];
77
- if (Array.isArray(value)) {
78
- value.forEach((item, index) => formData.append(`${key}[${index}]`, item));
79
- }
80
- else if (typeof value === 'object' && value !== null) {
81
- Object.keys(value).forEach((subKey) => {
82
- formData.append(`${key}[${subKey}]`, value[subKey]);
83
- });
84
- }
85
- else {
86
- formData.append(key, value);
87
- }
88
- });
89
- return formData;
90
- default:
91
- throw new Error(`Unsupported content type: ${contentType}`);
92
- }
93
- }
94
- }
95
- return requestBodyData;
96
- }
97
- function serializeFormEncoded(data) {
98
- return Object.keys(data)
99
- .map((key) => {
100
- const value = data[key];
101
- if (typeof value === 'object' && value !== null) {
102
- return serializeNestedObject(key, value);
103
- }
104
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
105
- })
106
- .join('&');
107
- }
108
- function serializeNestedObject(parentKey, obj) {
109
- return Object.keys(obj)
110
- .map((key) => {
111
- const value = obj[key];
112
- const fullKey = `${parentKey}[${key}]`;
113
- if (typeof value === 'object' && value !== null) {
114
- return serializeNestedObject(fullKey, value);
115
- }
116
- return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value)}`;
117
- })
118
- .join('&');
119
- }
120
- function extractRequestBodyParameters(requestBody) {
121
- if (!requestBody || !requestBody.content) {
122
- return [];
123
- }
124
- const contentType = getContentType(requestBody);
125
- const mediaTypeObject = requestBody.content[contentType];
126
- if (!mediaTypeObject || !mediaTypeObject.schema) {
127
- console.warn(`No schema available for content type: ${contentType}`);
128
- return [];
129
- }
130
- const { schema } = mediaTypeObject;
131
- const schemaObject = (0, convert_schema_1.default)(schema);
132
- return Object.entries(schemaObject).map(([key, value]) => ({ name: key, ...value })) || [];
133
- }
134
- function getAllParameters(dataset) {
135
- const requestBody = extractRequestBodyParameters(dataset?.requestBody);
136
- const datasetParameters = [
137
- ...(dataset?.parameters ?? []).map((i) => ({ ...i, type: i.schema?.type })),
138
- ...(requestBody ?? []),
139
- ];
140
- return datasetParameters;
141
- }
142
- function getRequiredFields(dataset) {
143
- const parameterFields = dataset.parameters?.filter((param) => param.required).map((param) => param.name) || [];
144
- const requestBodyFields = Object.values(dataset.requestBody?.content || {}).flatMap((mediaObject) => mediaObject.schema?.required || []);
145
- return [...new Set([...parameterFields, ...requestBodyFields])];
146
- }
@@ -1,17 +0,0 @@
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("openapi3-ts/oas31"), exports);
@@ -1,15 +0,0 @@
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.call = void 0;
7
- const component_1 = require("@blocklet/sdk/lib/component");
8
- const isNil_1 = __importDefault(require("lodash/isNil"));
9
- const call = (options) => {
10
- return (0, component_1.call)({
11
- ...options,
12
- params: Object.fromEntries(Object.entries(options.params ?? {}).map(([key, value]) => [key, (0, isNil_1.default)(value) ? '' : String(value)])),
13
- });
14
- };
15
- exports.call = call;
@@ -1,67 +0,0 @@
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
- const joi_1 = __importDefault(require("joi"));
7
- const CustomJoi = joi_1.default.extend((joi) => ({
8
- type: 'string',
9
- base: joi.string(),
10
- messages: {
11
- 'string.customId': '{{#label}} does not match the expected format (type:path:method)',
12
- },
13
- rules: {
14
- customId: {
15
- validate(value, helpers) {
16
- const [, path, method] = value.split(':');
17
- const parts = helpers.state.ancestors[0];
18
- if (!path || !method) {
19
- return helpers.error('string.customId');
20
- }
21
- if (path !== parts.path || (method || '').toLocaleLowerCase() !== (parts.method || '').toLocaleLowerCase()) {
22
- return helpers.error('string.customId');
23
- }
24
- return value;
25
- },
26
- },
27
- },
28
- }));
29
- const BaseParameterObjectSchema = joi_1.default.object({
30
- description: joi_1.default.string().optional(),
31
- required: joi_1.default.boolean().optional(),
32
- deprecated: joi_1.default.boolean().optional(),
33
- allowEmptyValue: joi_1.default.boolean().optional(),
34
- style: joi_1.default.string()
35
- .valid('matrix', 'label', 'form', 'simple', 'spaceDelimited', 'pipeDelimited', 'deepObject')
36
- .insensitive()
37
- .optional(),
38
- explode: joi_1.default.boolean().optional(),
39
- allowReserved: joi_1.default.boolean().optional(),
40
- schema: joi_1.default.any().optional(),
41
- examples: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.any).optional(),
42
- example: joi_1.default.any().optional(),
43
- content: joi_1.default.any().optional(),
44
- }).optional();
45
- const ParameterObjectSchema = BaseParameterObjectSchema.keys({
46
- name: joi_1.default.string().required(),
47
- in: joi_1.default.string().valid('query', 'header', 'path', 'cookie').insensitive().required(),
48
- });
49
- const RequestBodyObjectSchema = joi_1.default.object({});
50
- const ResponsesObjectSchema = joi_1.default.object({});
51
- exports.default = joi_1.default.object({
52
- id: CustomJoi.string().customId().required(),
53
- name: joi_1.default.string().optional().allow('').empty([null, '']),
54
- type: joi_1.default.string().optional().allow('').empty([null, '']),
55
- url: joi_1.default.string()
56
- .pattern(/^https?:\/\//)
57
- .optional()
58
- .allow('')
59
- .empty([null, '']),
60
- path: joi_1.default.string().required(),
61
- method: joi_1.default.string().valid('GET', 'POST', 'PUT', 'DELETE', 'PATCH').insensitive().required(),
62
- summary: joi_1.default.string().optional().allow('').empty([null, '']),
63
- description: joi_1.default.string().optional().allow('').empty([null, '']),
64
- parameters: joi_1.default.array().items(ParameterObjectSchema).optional().allow(null, '').empty([null, '']),
65
- requestBody: RequestBodyObjectSchema.optional().allow('').empty([null, '']),
66
- responses: ResponsesObjectSchema.optional().allow('').empty([null, '']),
67
- }).unknown(true);
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const convertSchemaToObject = (schema) => {
4
- if (!schema || typeof schema !== 'object') {
5
- throw new Error('Invalid schema: Schema must be an object');
6
- }
7
- switch (schema.type) {
8
- case 'object':
9
- return convertObjectSchema(schema);
10
- case 'array':
11
- return convertArraySchema(schema);
12
- default:
13
- return convertPrimitiveSchema(schema);
14
- }
15
- };
16
- const convertObjectSchema = (schema) => {
17
- const result = {};
18
- if (schema.properties && typeof schema.properties === 'object') {
19
- Object.keys(schema.properties).forEach((property) => {
20
- result[property] = schema.properties[property];
21
- });
22
- }
23
- return result;
24
- };
25
- const convertArraySchema = (schema) => {
26
- if (!schema.items) {
27
- return [];
28
- }
29
- return [convertSchemaToObject(schema.items)];
30
- };
31
- const convertPrimitiveSchema = (schema) => {
32
- switch (schema.type) {
33
- case 'string':
34
- return { ...schema, value: schema.default ?? (schema.enum ? schema.enum[0] : '') };
35
- case 'integer':
36
- case 'number':
37
- return { ...schema, value: schema.default ?? 0 };
38
- case 'boolean':
39
- return { ...schema, value: schema.default ?? false };
40
- default:
41
- return { ...schema, value: schema.default ?? null };
42
- }
43
- };
44
- exports.default = convertSchemaToObject;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function flattenApiStructure(apiStructure) {
4
- const flattened = [];
5
- const paths = apiStructure?.paths || {};
6
- for (const path in paths) {
7
- for (const method in paths[path]) {
8
- const endpoint = paths[path]?.[method];
9
- flattened.push({
10
- id: endpoint['x-id'],
11
- name: endpoint['x-did'],
12
- path: endpoint['x-path'],
13
- method: endpoint['x-method'],
14
- did: endpoint['x-did'],
15
- ...endpoint,
16
- });
17
- }
18
- }
19
- return flattened;
20
- }
21
- exports.default = flattenApiStructure;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const getOpenApiTextFromI18n = (data, key, locale) => {
4
- const i18nKey = `x-${key}-${locale}`;
5
- return data[i18nKey] || data[key];
6
- };
7
- exports.default = getOpenApiTextFromI18n;
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resourceManager = void 0;
4
- const resource_manager_1 = require("../common/resource-manager");
5
- exports.resourceManager = new resource_manager_1.ResourceManager();
@@ -1,143 +0,0 @@
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.AIGNERuntime = void 0;
7
- const path_1 = require("path");
8
- const call_1 = require("@blocklet/ai-kit/api/call");
9
- const fs_extra_1 = require("fs-extra");
10
- const glob_1 = require("glob");
11
- const yaml_1 = require("yaml");
12
- const common_1 = require("../common");
13
- const aid_1 = require("../common/aid");
14
- const executor_1 = require("../executor");
15
- const logger_1 = __importDefault(require("../logger"));
16
- const task_id_1 = require("../utils/task-id");
17
- const resource_blocklet_1 = require("./resource-blocklet");
18
- class AIGNERuntime {
19
- project;
20
- static async load(options) {
21
- const projectFilePath = (0, path_1.join)(options.path, 'project.yaml');
22
- const project = (0, yaml_1.parse)((await (0, fs_extra_1.readFile)(projectFilePath)).toString());
23
- // TODO: validate parsed project
24
- const agentFilePaths = await (0, glob_1.glob)((0, path_1.join)(options.path, 'prompts', '**/*.yaml'));
25
- const agents = await Promise.all(agentFilePaths.map(async (filename) => {
26
- const agent = (0, yaml_1.parse)((await (0, fs_extra_1.readFile)(filename)).toString());
27
- // TODO: validate parsed agent
28
- return agent;
29
- }));
30
- const memoryFilePath = (0, path_1.join)(options.path, 'config/variable.yaml');
31
- const memories = (0, yaml_1.parse)((await (0, fs_extra_1.readFile)(memoryFilePath)).toString())?.variables;
32
- // TODO: validate parsed memories
33
- const p = {
34
- ...project,
35
- agents,
36
- memories,
37
- };
38
- return new AIGNERuntime(p);
39
- }
40
- constructor(project) {
41
- this.project = project;
42
- }
43
- async runAgent(agentId, inputs) {
44
- const agent = this.project.agents?.find((a) => a.id === agentId);
45
- if (!agent)
46
- throw new Error(`Agent ${agentId} not found`);
47
- const taskId = (0, task_id_1.nextId)();
48
- const messageId = (0, task_id_1.nextId)();
49
- const callAI = async ({ input }) => {
50
- return await (0, call_1.chatCompletions)({ ...input, model: input.model || common_1.defaultTextModel });
51
- };
52
- const callAIImage = async ({ assistant, input }) => {
53
- const imageAssistant = assistant.type === 'image' ? assistant : undefined;
54
- const supportImages = await (0, common_1.getSupportedImagesModels)();
55
- const imageModel = supportImages.find((i) => i.model === (imageAssistant?.model || common_1.defaultImageModel));
56
- const model = {
57
- model: input.model || imageModel?.model,
58
- n: input.n || imageModel?.nDefault,
59
- quality: input.quality || imageModel?.qualityDefault,
60
- style: input.style || imageModel?.styleDefault,
61
- size: input.size || imageModel?.sizeDefault,
62
- };
63
- return (0, call_1.imageGenerations)({
64
- ...input,
65
- ...model,
66
- responseFormat: 'url',
67
- });
68
- };
69
- const executor = new executor_1.RuntimeExecutor({
70
- entry: { project: this.project },
71
- callback: () => { },
72
- callAI,
73
- callAIImage,
74
- getMemoryVariables: async (options) => {
75
- if (options.projectId === this.project.id)
76
- return this.project.memories ?? [];
77
- logger_1.default.warn('Unsupported to get memory variables from other projects');
78
- return [];
79
- },
80
- getAgent: async (options) => {
81
- const identity = (0, aid_1.parseIdentity)(options.aid, { rejectWhenError: true });
82
- let agent;
83
- if (identity.blockletDid) {
84
- const { blockletDid, projectId, agentId } = identity;
85
- const res = await resource_blocklet_1.resourceManager.getAgent({ blockletDid, projectId, agentId });
86
- if (res) {
87
- agent = {
88
- ...res.agent,
89
- project: res.project,
90
- identity: {
91
- blockletDid,
92
- projectId,
93
- agentId,
94
- aid: (0, aid_1.stringifyIdentity)({ blockletDid, projectId, agentId }),
95
- },
96
- };
97
- }
98
- }
99
- else if (identity.projectId === this.project.id) {
100
- const a = this.project.agents?.find((a) => a.id === identity.agentId);
101
- if (a) {
102
- agent = {
103
- ...a,
104
- project: this.project,
105
- identity: {
106
- projectId: this.project.id,
107
- agentId: a.id,
108
- aid: (0, aid_1.stringifyIdentity)({ projectId: this.project.id, agentId: a.id }),
109
- },
110
- };
111
- }
112
- }
113
- if (options.rejectOnEmpty && !agent)
114
- throw new Error('No such agent');
115
- return agent;
116
- },
117
- entryProjectId: this.project.id,
118
- sessionId: this.project.id,
119
- messageId,
120
- clientTime: new Date().toISOString(),
121
- queryCache: async ({ aid, cacheKey }) => {
122
- // TODO: implement cache
123
- return null;
124
- },
125
- setCache: async ({ aid, cacheKey, inputs, outputs }) => {
126
- // TODO: implement cache
127
- },
128
- }, {
129
- ...agent,
130
- identity: {
131
- projectId: this.project.id,
132
- agentId: agent.id,
133
- aid: (0, aid_1.stringifyIdentity)({ projectId: this.project.id, agentId: agent.id }),
134
- },
135
- project: this.project,
136
- }, {
137
- inputs,
138
- taskId,
139
- });
140
- return executor.execute();
141
- }
142
- }
143
- exports.AIGNERuntime = AIGNERuntime;
@@ -1,31 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.OnTaskCompletion = exports.Mustache = void 0;
21
- exports.isUserInputParameter = isUserInputParameter;
22
- var mustache_1 = require("./mustache/mustache");
23
- Object.defineProperty(exports, "Mustache", { enumerable: true, get: function () { return __importDefault(mustache_1).default; } });
24
- __exportStar(require("./mustache/directive"), exports);
25
- var OnTaskCompletion;
26
- (function (OnTaskCompletion) {
27
- OnTaskCompletion["EXIT"] = "EXIT";
28
- })(OnTaskCompletion || (exports.OnTaskCompletion = OnTaskCompletion = {}));
29
- function isUserInputParameter(parameter) {
30
- return parameter.type !== 'source';
31
- }