@aigne/core 0.0.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 (170) hide show
  1. package/lib/cjs/assistant/generate-output.js +101 -0
  2. package/lib/cjs/assistant/select-agent.js +76 -0
  3. package/lib/cjs/assistant/type.js +11 -0
  4. package/lib/cjs/common/aid.js +42 -0
  5. package/lib/cjs/common/index.js +238 -0
  6. package/lib/cjs/common/resource-manager.js +199 -0
  7. package/lib/cjs/constants.js +9 -0
  8. package/lib/cjs/executor/agent.js +10 -0
  9. package/lib/cjs/executor/aigc.js +28 -0
  10. package/lib/cjs/executor/api.js +64 -0
  11. package/lib/cjs/executor/base.js +676 -0
  12. package/lib/cjs/executor/blocklet.js +25 -0
  13. package/lib/cjs/executor/call-agent.js +105 -0
  14. package/lib/cjs/executor/decision.js +478 -0
  15. package/lib/cjs/executor/image-blender.js +32 -0
  16. package/lib/cjs/executor/index.js +81 -0
  17. package/lib/cjs/executor/llm.js +379 -0
  18. package/lib/cjs/executor/logic.js +167 -0
  19. package/lib/cjs/index.js +17 -0
  20. package/lib/cjs/libs/blocklet/vc.js +92 -0
  21. package/lib/cjs/libs/openapi/request/index.js +24 -0
  22. package/lib/cjs/libs/openapi/request/util.js +146 -0
  23. package/lib/cjs/libs/openapi/types/index.js +17 -0
  24. package/lib/cjs/libs/openapi/util/call.js +15 -0
  25. package/lib/cjs/libs/openapi/util/check-schema.js +67 -0
  26. package/lib/cjs/libs/openapi/util/convert-schema.js +44 -0
  27. package/lib/cjs/libs/openapi/util/flatten-open-api.js +21 -0
  28. package/lib/cjs/libs/openapi/util/get-open-api-i18n-text.js +7 -0
  29. package/lib/cjs/logger.js +4 -0
  30. package/lib/cjs/runtime/resource-blocklet.js +5 -0
  31. package/lib/cjs/runtime/runtime.js +143 -0
  32. package/lib/cjs/types/assistant/index.js +31 -0
  33. package/lib/cjs/types/assistant/mustache/ReadableMustache.js +69 -0
  34. package/lib/cjs/types/assistant/mustache/directive.js +35 -0
  35. package/lib/cjs/types/assistant/mustache/mustache.js +688 -0
  36. package/lib/cjs/types/common/index.js +2 -0
  37. package/lib/cjs/types/index.js +20 -0
  38. package/lib/cjs/types/resource/index.js +47 -0
  39. package/lib/cjs/types/resource/project.js +35 -0
  40. package/lib/cjs/types/runtime/agent.js +2 -0
  41. package/lib/cjs/types/runtime/error.js +18 -0
  42. package/lib/cjs/types/runtime/index.js +37 -0
  43. package/lib/cjs/types/runtime/runtime-resource-blocklet-state.js +4 -0
  44. package/lib/cjs/types/runtime/schema.js +259 -0
  45. package/lib/cjs/utils/cron-job.js +48 -0
  46. package/lib/cjs/utils/extract-metadata-transform.js +58 -0
  47. package/lib/cjs/utils/extract-metadata-transform.test.js +61 -0
  48. package/lib/cjs/utils/fs.js +49 -0
  49. package/lib/cjs/utils/get-blocklet-agent.js +351 -0
  50. package/lib/cjs/utils/geti.js +37 -0
  51. package/lib/cjs/utils/is-non-nullable.js +20 -0
  52. package/lib/cjs/utils/render-message.js +23 -0
  53. package/lib/cjs/utils/resolve-secret-inputs.js +49 -0
  54. package/lib/cjs/utils/retry.js +19 -0
  55. package/lib/cjs/utils/task-id.js +7 -0
  56. package/lib/cjs/utils/tool-calls-transform.js +18 -0
  57. package/lib/esm/assistant/generate-output.js +91 -0
  58. package/lib/esm/assistant/select-agent.js +71 -0
  59. package/lib/esm/assistant/type.js +7 -0
  60. package/lib/esm/common/aid.js +38 -0
  61. package/lib/esm/common/index.js +232 -0
  62. package/lib/esm/common/resource-manager.js +192 -0
  63. package/lib/esm/constants.js +6 -0
  64. package/lib/esm/executor/agent.js +6 -0
  65. package/lib/esm/executor/aigc.js +24 -0
  66. package/lib/esm/executor/api.js +34 -0
  67. package/lib/esm/executor/base.js +668 -0
  68. package/lib/esm/executor/blocklet.js +21 -0
  69. package/lib/esm/executor/call-agent.js +98 -0
  70. package/lib/esm/executor/decision.js +471 -0
  71. package/lib/esm/executor/image-blender.js +25 -0
  72. package/lib/esm/executor/index.js +74 -0
  73. package/lib/esm/executor/llm.js +372 -0
  74. package/lib/esm/executor/logic.js +160 -0
  75. package/lib/esm/index.js +1 -0
  76. package/lib/esm/libs/blocklet/vc.js +85 -0
  77. package/lib/esm/libs/openapi/request/index.js +20 -0
  78. package/lib/esm/libs/openapi/request/util.js +136 -0
  79. package/lib/esm/libs/openapi/types/index.js +1 -0
  80. package/lib/esm/libs/openapi/util/call.js +8 -0
  81. package/lib/esm/libs/openapi/util/check-schema.js +62 -0
  82. package/lib/esm/libs/openapi/util/convert-schema.js +42 -0
  83. package/lib/esm/libs/openapi/util/flatten-open-api.js +19 -0
  84. package/lib/esm/libs/openapi/util/get-open-api-i18n-text.js +5 -0
  85. package/lib/esm/logger.js +2 -0
  86. package/lib/esm/runtime/resource-blocklet.js +2 -0
  87. package/lib/esm/runtime/runtime.js +136 -0
  88. package/lib/esm/types/assistant/index.js +9 -0
  89. package/lib/esm/types/assistant/mustache/ReadableMustache.js +63 -0
  90. package/lib/esm/types/assistant/mustache/directive.js +29 -0
  91. package/lib/esm/types/assistant/mustache/mustache.js +686 -0
  92. package/lib/esm/types/common/index.js +1 -0
  93. package/lib/esm/types/index.js +4 -0
  94. package/lib/esm/types/resource/index.js +26 -0
  95. package/lib/esm/types/resource/project.js +29 -0
  96. package/lib/esm/types/runtime/agent.js +1 -0
  97. package/lib/esm/types/runtime/error.js +14 -0
  98. package/lib/esm/types/runtime/index.js +20 -0
  99. package/lib/esm/types/runtime/runtime-resource-blocklet-state.js +1 -0
  100. package/lib/esm/types/runtime/schema.js +249 -0
  101. package/lib/esm/utils/cron-job.js +44 -0
  102. package/lib/esm/utils/extract-metadata-transform.js +54 -0
  103. package/lib/esm/utils/extract-metadata-transform.test.js +59 -0
  104. package/lib/esm/utils/fs.js +41 -0
  105. package/lib/esm/utils/get-blocklet-agent.js +344 -0
  106. package/lib/esm/utils/geti.js +30 -0
  107. package/lib/esm/utils/is-non-nullable.js +13 -0
  108. package/lib/esm/utils/render-message.js +20 -0
  109. package/lib/esm/utils/resolve-secret-inputs.js +46 -0
  110. package/lib/esm/utils/retry.js +16 -0
  111. package/lib/esm/utils/task-id.js +3 -0
  112. package/lib/esm/utils/tool-calls-transform.js +15 -0
  113. package/lib/types/assistant/generate-output.d.ts +29 -0
  114. package/lib/types/assistant/select-agent.d.ts +14 -0
  115. package/lib/types/assistant/type.d.ts +61 -0
  116. package/lib/types/common/aid.d.ts +18 -0
  117. package/lib/types/common/index.d.ts +7 -0
  118. package/lib/types/common/resource-manager.d.ts +88 -0
  119. package/lib/types/constants.d.ts +6 -0
  120. package/lib/types/executor/agent.d.ts +5 -0
  121. package/lib/types/executor/aigc.d.ts +9 -0
  122. package/lib/types/executor/api.d.ts +9 -0
  123. package/lib/types/executor/base.d.ts +209 -0
  124. package/lib/types/executor/blocklet.d.ts +9 -0
  125. package/lib/types/executor/call-agent.d.ts +12 -0
  126. package/lib/types/executor/decision.d.ts +20 -0
  127. package/lib/types/executor/image-blender.d.ts +9 -0
  128. package/lib/types/executor/index.d.ts +8 -0
  129. package/lib/types/executor/llm.d.ts +38 -0
  130. package/lib/types/executor/logic.d.ts +9 -0
  131. package/lib/types/index.d.ts +1 -0
  132. package/lib/types/libs/blocklet/vc.d.ts +17 -0
  133. package/lib/types/libs/openapi/request/index.d.ts +17 -0
  134. package/lib/types/libs/openapi/request/util.d.ts +40 -0
  135. package/lib/types/libs/openapi/types/index.d.ts +20 -0
  136. package/lib/types/libs/openapi/util/call.d.ts +2 -0
  137. package/lib/types/libs/openapi/util/check-schema.d.ts +3 -0
  138. package/lib/types/libs/openapi/util/convert-schema.d.ts +8 -0
  139. package/lib/types/libs/openapi/util/flatten-open-api.d.ts +3 -0
  140. package/lib/types/libs/openapi/util/get-open-api-i18n-text.d.ts +2 -0
  141. package/lib/types/logger.d.ts +2 -0
  142. package/lib/types/runtime/resource-blocklet.d.ts +2 -0
  143. package/lib/types/runtime/runtime.d.ts +20 -0
  144. package/lib/types/types/assistant/index.d.ts +405 -0
  145. package/lib/types/types/assistant/mustache/ReadableMustache.d.ts +2 -0
  146. package/lib/types/types/assistant/mustache/directive.d.ts +6 -0
  147. package/lib/types/types/assistant/mustache/mustache.d.ts +2 -0
  148. package/lib/types/types/common/index.d.ts +45 -0
  149. package/lib/types/types/index.d.ts +4 -0
  150. package/lib/types/types/resource/index.d.ts +17 -0
  151. package/lib/types/types/resource/project.d.ts +41 -0
  152. package/lib/types/types/runtime/agent.d.ts +33 -0
  153. package/lib/types/types/runtime/error.d.ts +10 -0
  154. package/lib/types/types/runtime/index.d.ts +116 -0
  155. package/lib/types/types/runtime/runtime-resource-blocklet-state.d.ts +5 -0
  156. package/lib/types/types/runtime/schema.d.ts +110 -0
  157. package/lib/types/utils/cron-job.d.ts +22 -0
  158. package/lib/types/utils/extract-metadata-transform.d.ts +16 -0
  159. package/lib/types/utils/extract-metadata-transform.test.d.ts +1 -0
  160. package/lib/types/utils/fs.d.ts +9 -0
  161. package/lib/types/utils/get-blocklet-agent.d.ts +219 -0
  162. package/lib/types/utils/geti.d.ts +1 -0
  163. package/lib/types/utils/is-non-nullable.d.ts +2 -0
  164. package/lib/types/utils/render-message.d.ts +6 -0
  165. package/lib/types/utils/resolve-secret-inputs.d.ts +11 -0
  166. package/lib/types/utils/retry.d.ts +1 -0
  167. package/lib/types/utils/task-id.d.ts +1 -0
  168. package/lib/types/utils/tool-calls-transform.d.ts +2 -0
  169. package/package.json +67 -0
  170. package/tsconfig.json +12 -0
@@ -0,0 +1,69 @@
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.renderMustacheStream = renderMustacheStream;
7
+ const web_1 = require("stream/web");
8
+ const fastq_1 = __importDefault(require("fastq"));
9
+ const render_message_1 = require("../../../utils/render-message");
10
+ function renderMustacheStream(template, context) {
11
+ return new web_1.ReadableStream({
12
+ async start(controller) {
13
+ try {
14
+ // 异步任务队列,每个任务完成之后都会重新渲染模板并返回最新的结果到流中
15
+ const queue = fastq_1.default.promise(async (p) => {
16
+ await p;
17
+ await render();
18
+ }, 100);
19
+ let reject;
20
+ const errorPromise = new Promise((_, rej) => {
21
+ reject = rej;
22
+ });
23
+ queue.error((error) => {
24
+ if (error)
25
+ reject?.(error);
26
+ });
27
+ // 任务缓存,每个任务的 key 为渲染后的子模板(其中可能包含参数)
28
+ const cache = new Map();
29
+ const ctx = context((fn) => {
30
+ return async (template, render) => {
31
+ const rendered = await render(template);
32
+ const key = rendered;
33
+ let task = cache.get(key);
34
+ if (!task) {
35
+ const res = fn(template, render, rendered);
36
+ if (res instanceof Promise) {
37
+ task = { promise: res };
38
+ res
39
+ .then((value) => {
40
+ task.result = { data: value };
41
+ })
42
+ .catch((error) => {
43
+ task.error = { error };
44
+ });
45
+ queue.push(res);
46
+ }
47
+ else {
48
+ task = { result: { data: res } };
49
+ }
50
+ cache.set(key, task);
51
+ }
52
+ if (task.error)
53
+ throw task.error.error;
54
+ // 返回 promise 完成后的数据,没完成则返回 undefined,避免阻塞 mustache 渲染
55
+ return task.result?.data;
56
+ };
57
+ });
58
+ const render = async () => controller.enqueue(await (0, render_message_1.renderMessage)(template, ctx, { escapeJsonSymbols: true }));
59
+ await render();
60
+ // wait for all promise in the queue to be resolved
61
+ await Promise.race([queue.drained(), errorPromise]);
62
+ }
63
+ catch (error) {
64
+ controller.error(error);
65
+ }
66
+ controller.close();
67
+ },
68
+ });
69
+ }
@@ -0,0 +1,35 @@
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.parseDirectives = parseDirectives;
7
+ const mustache_1 = __importDefault(require("./mustache"));
8
+ function parseDirectives(...content) {
9
+ return content.flatMap((content) => {
10
+ // 捕获 api/{{var/api/task/{{list}} 这种错误
11
+ try {
12
+ const spans = mustache_1.default.parse(content);
13
+ const directives = [];
14
+ for (const span of spans) {
15
+ switch (span[0]) {
16
+ case 'name': {
17
+ const name = span[1];
18
+ if (name)
19
+ directives.push({ type: 'variable', name });
20
+ break;
21
+ }
22
+ case 'text': {
23
+ break;
24
+ }
25
+ default:
26
+ console.warn('Unknown directive', span);
27
+ }
28
+ }
29
+ return directives;
30
+ }
31
+ catch (error) {
32
+ return [];
33
+ }
34
+ });
35
+ }