@aigne/aigne-hub 0.10.17-beta.1 → 1.74.0-beta

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 (107) hide show
  1. package/README.md +11 -11
  2. package/dist/aigne-hub-image-model.cjs +91 -0
  3. package/dist/aigne-hub-image-model.mjs +92 -0
  4. package/dist/aigne-hub-image-model.mjs.map +1 -0
  5. package/dist/aigne-hub-model.cjs +80 -0
  6. package/dist/aigne-hub-model.mjs +81 -0
  7. package/dist/aigne-hub-model.mjs.map +1 -0
  8. package/dist/aigne-hub-video-model.cjs +95 -0
  9. package/dist/aigne-hub-video-model.mjs +96 -0
  10. package/dist/aigne-hub-video-model.mjs.map +1 -0
  11. package/dist/index.cjs +139 -0
  12. package/dist/index.d.cts +118 -0
  13. package/dist/index.d.cts.map +1 -0
  14. package/dist/index.d.mts +118 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +117 -0
  17. package/dist/index.mjs.map +1 -0
  18. package/dist/utils/blocklet.cjs +13 -0
  19. package/dist/utils/blocklet.d.cts +5 -0
  20. package/dist/utils/blocklet.d.cts.map +1 -0
  21. package/dist/utils/blocklet.d.mts +5 -0
  22. package/dist/utils/blocklet.d.mts.map +1 -0
  23. package/dist/utils/blocklet.mjs +14 -0
  24. package/dist/utils/blocklet.mjs.map +1 -0
  25. package/dist/utils/constants.cjs +46 -0
  26. package/dist/utils/constants.d.cts +26 -0
  27. package/dist/utils/constants.d.cts.map +1 -0
  28. package/dist/utils/constants.d.mts +26 -0
  29. package/dist/utils/constants.d.mts.map +1 -0
  30. package/dist/utils/constants.mjs +38 -0
  31. package/dist/utils/constants.mjs.map +1 -0
  32. package/dist/utils/find-provider.cjs +161 -0
  33. package/{lib/cjs/utils/find-provider.d.ts → dist/utils/find-provider.d.cts} +10 -5
  34. package/dist/utils/find-provider.d.cts.map +1 -0
  35. package/{lib/esm/utils/find-provider.d.ts → dist/utils/find-provider.d.mts} +10 -5
  36. package/dist/utils/find-provider.d.mts.map +1 -0
  37. package/dist/utils/find-provider.mjs +159 -0
  38. package/dist/utils/find-provider.mjs.map +1 -0
  39. package/dist/utils/hub.cjs +24 -0
  40. package/dist/utils/hub.mjs +25 -0
  41. package/dist/utils/hub.mjs.map +1 -0
  42. package/dist/utils/model.cjs +260 -0
  43. package/dist/utils/model.d.cts +57 -0
  44. package/dist/utils/model.d.cts.map +1 -0
  45. package/dist/utils/model.d.mts +57 -0
  46. package/dist/utils/model.d.mts.map +1 -0
  47. package/dist/utils/model.mjs +255 -0
  48. package/dist/utils/model.mjs.map +1 -0
  49. package/dist/utils/type.cjs +20 -0
  50. package/dist/utils/type.d.cts +28 -0
  51. package/dist/utils/type.d.cts.map +1 -0
  52. package/dist/utils/type.d.mts +29 -0
  53. package/dist/utils/type.d.mts.map +1 -0
  54. package/dist/utils/type.mjs +21 -0
  55. package/dist/utils/type.mjs.map +1 -0
  56. package/package.json +40 -41
  57. package/CHANGELOG.md +0 -4238
  58. package/lib/cjs/aigne-hub-image-model.d.ts +0 -28
  59. package/lib/cjs/aigne-hub-image-model.js +0 -90
  60. package/lib/cjs/aigne-hub-model.d.ts +0 -28
  61. package/lib/cjs/aigne-hub-model.js +0 -80
  62. package/lib/cjs/aigne-hub-video-model.d.ts +0 -28
  63. package/lib/cjs/aigne-hub-video-model.js +0 -89
  64. package/lib/cjs/index.d.ts +0 -112
  65. package/lib/cjs/index.js +0 -135
  66. package/lib/cjs/package.json +0 -3
  67. package/lib/cjs/utils/blocklet.d.ts +0 -1
  68. package/lib/cjs/utils/blocklet.js +0 -15
  69. package/lib/cjs/utils/constants.d.ts +0 -22
  70. package/lib/cjs/utils/constants.js +0 -37
  71. package/lib/cjs/utils/find-provider.js +0 -121
  72. package/lib/cjs/utils/hub.d.ts +0 -16
  73. package/lib/cjs/utils/hub.js +0 -30
  74. package/lib/cjs/utils/model.d.ts +0 -52
  75. package/lib/cjs/utils/model.js +0 -207
  76. package/lib/cjs/utils/type.d.ts +0 -78
  77. package/lib/cjs/utils/type.js +0 -20
  78. package/lib/dts/aigne-hub-image-model.d.ts +0 -28
  79. package/lib/dts/aigne-hub-model.d.ts +0 -28
  80. package/lib/dts/aigne-hub-video-model.d.ts +0 -28
  81. package/lib/dts/index.d.ts +0 -112
  82. package/lib/dts/utils/blocklet.d.ts +0 -1
  83. package/lib/dts/utils/constants.d.ts +0 -22
  84. package/lib/dts/utils/find-provider.d.ts +0 -17
  85. package/lib/dts/utils/hub.d.ts +0 -16
  86. package/lib/dts/utils/model.d.ts +0 -52
  87. package/lib/dts/utils/type.d.ts +0 -78
  88. package/lib/esm/aigne-hub-image-model.d.ts +0 -28
  89. package/lib/esm/aigne-hub-image-model.js +0 -86
  90. package/lib/esm/aigne-hub-model.d.ts +0 -28
  91. package/lib/esm/aigne-hub-model.js +0 -76
  92. package/lib/esm/aigne-hub-video-model.d.ts +0 -28
  93. package/lib/esm/aigne-hub-video-model.js +0 -85
  94. package/lib/esm/index.d.ts +0 -112
  95. package/lib/esm/index.js +0 -115
  96. package/lib/esm/package.json +0 -3
  97. package/lib/esm/utils/blocklet.d.ts +0 -1
  98. package/lib/esm/utils/blocklet.js +0 -12
  99. package/lib/esm/utils/constants.d.ts +0 -22
  100. package/lib/esm/utils/constants.js +0 -33
  101. package/lib/esm/utils/find-provider.js +0 -115
  102. package/lib/esm/utils/hub.d.ts +0 -16
  103. package/lib/esm/utils/hub.js +0 -27
  104. package/lib/esm/utils/model.d.ts +0 -52
  105. package/lib/esm/utils/model.js +0 -197
  106. package/lib/esm/utils/type.d.ts +0 -78
  107. package/lib/esm/utils/type.js +0 -17
package/README.md CHANGED
@@ -2,19 +2,19 @@
2
2
 
3
3
  <p align="center">
4
4
  <picture>
5
- <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
6
- <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
7
- <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
5
+ <source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
6
+ <source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
7
+ <img src="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
8
8
  </picture>
9
9
  </p>
10
10
 
11
- [![GitHub stars](https://img.shields.io/github/stars/AIGNE-io/aigne-framework?style=flat-square)](https://star-history.com/#AIGNE-io/aigne-framework)
12
- [![Open Issues](https://img.shields.io/github/issues-raw/AIGNE-io/aigne-framework?style=flat-square)](https://github.com/AIGNE-io/aigne-framework/issues)
13
- [![codecov](https://codecov.io/gh/AIGNE-io/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/AIGNE-io/aigne-framework)
11
+ [![GitHub stars](https://img.shields.io/github/stars/ArcBlock/aigne-framework?style=flat-square)](https://star-history.com/#ArcBlock/aigne-framework)
12
+ [![Open Issues](https://img.shields.io/github/issues-raw/ArcBlock/aigne-framework?style=flat-square)](https://github.com/ArcBlock/aigne-framework/issues)
13
+ [![codecov](https://codecov.io/gh/ArcBlock/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/ArcBlock/aigne-framework)
14
14
  [![NPM Version](https://img.shields.io/npm/v/@aigne/aigne-hub)](https://www.npmjs.com/package/@aigne/aigne-hub)
15
- [![Elastic-2.0 licensed](https://img.shields.io/npm/l/@aigne/aigne-hub)](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE.md)
15
+ [![Elastic-2.0 licensed](https://img.shields.io/npm/l/@aigne/aigne-hub)](https://github.com/ArcBlock/aigne-framework/blob/main/LICENSE.md)
16
16
 
17
- AIGNE SDK for accessing AI chat models and image generation via [AIGNE Hub](https://github.com/AIGNE-io/aigne-framework), a unified proxy layer for multiple LLM providers.
17
+ AIGNE SDK for accessing AI chat models and image generation via [AIGNE Hub](https://github.com/ArcBlock/aigne-framework), a unified proxy layer for multiple LLM providers.
18
18
 
19
19
  # Introduction
20
20
 
@@ -23,9 +23,9 @@ AIGNE SDK for accessing AI chat models and image generation via [AIGNE Hub](http
23
23
  It enables you to switch providers without changing your client-side logic.
24
24
 
25
25
  <picture>
26
- <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-hub-dark.png" media="(prefers-color-scheme: dark)">
27
- <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-hub.png" media="(prefers-color-scheme: light)">
28
- <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-hub.png" alt="AIGNE Arch" />
26
+ <source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/assets/aigne-hub-dark.png" media="(prefers-color-scheme: dark)">
27
+ <source srcset="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/assets/aigne-hub.png" media="(prefers-color-scheme: light)">
28
+ <img src="https://raw.githubusercontent.com/ArcBlock/aigne-framework/main/assets/aigne-hub.png" alt="AIGNE Arch" />
29
29
  </picture>
30
30
 
31
31
  ## Supported Providers
@@ -0,0 +1,91 @@
1
+ const require_blocklet = require('./utils/blocklet.cjs');
2
+ const require_constants = require('./utils/constants.cjs');
3
+ const require_hub = require('./utils/hub.cjs');
4
+ const require_type = require('./utils/type.cjs');
5
+ let _aigne_core = require("@aigne/core");
6
+ let ufo = require("ufo");
7
+ let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
8
+ let _aigne_transport_http_client_base_client = require("@aigne/transport/http-client/base-client");
9
+ let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
10
+
11
+ //#region src/aigne-hub-image-model.ts
12
+ var AIGNEHubImageModel = class extends _aigne_core.ImageModel {
13
+ constructor(options) {
14
+ (0, _aigne_core_utils_type_utils.checkArguments)("AIGNEHubImageModel", require_type.aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return require_hub.getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "image"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new _aigne_transport_http_client_base_client.BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= require_blocklet.getAIGNEHubMountPoint(this.options.baseURL || require_constants.aigneHubBaseUrl(), require_constants.AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/image";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : (0, ufo.joinURL)(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_IMAGE_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_utils_nodejs.nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
59
+ const response = await (await this.client).__invoke(void 0, {
60
+ ...input,
61
+ modelOptions: {
62
+ ...input.modelOptions,
63
+ model: input.modelOptions?.model || (await this.credential).model
64
+ },
65
+ outputFileType: "url"
66
+ }, {
67
+ ...options,
68
+ streaming: false,
69
+ fetchOptions: {
70
+ ...options.fetchOptions,
71
+ headers: {
72
+ ...options.fetchOptions?.headers,
73
+ "x-aigne-hub-client-did": clientId
74
+ }
75
+ }
76
+ });
77
+ return {
78
+ ...response,
79
+ images: response.images,
80
+ usage: {
81
+ inputTokens: response.usage?.inputTokens ?? 0,
82
+ outputTokens: response.usage?.outputTokens ?? 0,
83
+ ...response.usage
84
+ },
85
+ model: response?.model
86
+ };
87
+ }
88
+ };
89
+
90
+ //#endregion
91
+ exports.AIGNEHubImageModel = AIGNEHubImageModel;
@@ -0,0 +1,92 @@
1
+ import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
2
+ import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_IMAGE_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
3
+ import { getModels } from "./utils/hub.mjs";
4
+ import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
5
+ import { ImageModel } from "@aigne/core";
6
+ import { joinURL } from "ufo";
7
+ import { checkArguments } from "@aigne/core/utils/type-utils";
8
+ import { BaseClient } from "@aigne/transport/http-client/base-client";
9
+ import { nodejs } from "@aigne/utils/nodejs";
10
+
11
+ //#region src/aigne-hub-image-model.ts
12
+ var AIGNEHubImageModel = class extends ImageModel {
13
+ constructor(options) {
14
+ checkArguments("AIGNEHubImageModel", aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "image"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= getAIGNEHubMountPoint(this.options.baseURL || aigneHubBaseUrl(), AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/image";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : joinURL(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_IMAGE_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? nodejs.os.hostname() : "unknown"}`;
59
+ const response = await (await this.client).__invoke(void 0, {
60
+ ...input,
61
+ modelOptions: {
62
+ ...input.modelOptions,
63
+ model: input.modelOptions?.model || (await this.credential).model
64
+ },
65
+ outputFileType: "url"
66
+ }, {
67
+ ...options,
68
+ streaming: false,
69
+ fetchOptions: {
70
+ ...options.fetchOptions,
71
+ headers: {
72
+ ...options.fetchOptions?.headers,
73
+ "x-aigne-hub-client-did": clientId
74
+ }
75
+ }
76
+ });
77
+ return {
78
+ ...response,
79
+ images: response.images,
80
+ usage: {
81
+ inputTokens: response.usage?.inputTokens ?? 0,
82
+ outputTokens: response.usage?.outputTokens ?? 0,
83
+ ...response.usage
84
+ },
85
+ model: response?.model
86
+ };
87
+ }
88
+ };
89
+
90
+ //#endregion
91
+ export { AIGNEHubImageModel };
92
+ //# sourceMappingURL=aigne-hub-image-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aigne-hub-image-model.mjs","names":[],"sources":["../src/aigne-hub-image-model.ts"],"sourcesContent":["import {\n type AgentProcessResult,\n ImageModel,\n type ImageModelInput,\n type ImageModelOutput,\n} from \"@aigne/core\";\nimport { checkArguments } from \"@aigne/core/utils/type-utils\";\nimport { BaseClient, type BaseClientInvokeOptions } from \"@aigne/transport/http-client/base-client\";\nimport { nodejs } from \"@aigne/utils/nodejs\";\nimport { joinURL } from \"ufo\";\nimport { getAIGNEHubMountPoint } from \"./utils/blocklet.js\";\nimport {\n AIGNE_HUB_BLOCKLET_DID,\n AIGNE_HUB_IMAGE_MODEL,\n aigneHubBaseUrl,\n} from \"./utils/constants.js\";\nimport { getModels } from \"./utils/hub.js\";\nimport { type AIGNEHubImageModelOptions, aigneHubModelOptionsSchema } from \"./utils/type.js\";\n\nexport class AIGNEHubImageModel extends ImageModel {\n constructor(public override options: AIGNEHubImageModelOptions) {\n checkArguments(\"AIGNEHubImageModel\", aigneHubModelOptionsSchema, options);\n super();\n }\n\n async models() {\n return getModels({ baseURL: (await this.credential).url, type: \"image\" });\n }\n\n protected _client?: Promise<BaseClient>;\n\n get client() {\n this._client ??= this.credential.then(({ url, apiKey, model }) => {\n const options = { ...this.options, url, apiKey, model };\n return new BaseClient(options);\n });\n return this._client;\n }\n\n private _credential?: Promise<{\n url: string;\n apiKey?: string;\n model: string;\n }>;\n\n override get credential() {\n this._credential ??= getAIGNEHubMountPoint(\n this.options.baseURL || aigneHubBaseUrl(),\n AIGNE_HUB_BLOCKLET_DID,\n ).then((url) => {\n const path = \"/api/v2/image\";\n\n const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;\n let credentialOptions: Record<string, any> = {};\n try {\n credentialOptions =\n typeof rawCredential === \"string\" ? JSON.parse(rawCredential) : (rawCredential ?? {});\n } catch (err) {\n console.error(err);\n }\n\n return {\n ...credentialOptions,\n url: url.endsWith(path) ? url : joinURL(url, path),\n apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,\n model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_IMAGE_MODEL,\n };\n });\n\n return this._credential;\n }\n\n override async process(\n input: ImageModelInput,\n options: BaseClientInvokeOptions,\n ): Promise<AgentProcessResult<ImageModelOutput>> {\n const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;\n const clientId =\n this.options?.clientOptions?.clientId ||\n BLOCKLET_APP_PID ||\n ABT_NODE_DID ||\n `@aigne/aigne-hub:${typeof process !== \"undefined\" ? nodejs.os.hostname() : \"unknown\"}`;\n\n const response = await (await this.client).__invoke<ImageModelInput, ImageModelOutput>(\n undefined,\n {\n ...input,\n modelOptions: {\n ...input.modelOptions,\n model: input.modelOptions?.model || (await this.credential).model,\n },\n // Shouldn't use `local` output type for remote AIGNE Hub call, client can not access the remote filesystem\n outputFileType: \"url\",\n },\n {\n ...options,\n streaming: false,\n fetchOptions: {\n ...options.fetchOptions,\n headers: {\n ...options.fetchOptions?.headers,\n \"x-aigne-hub-client-did\": clientId,\n },\n },\n },\n );\n\n return {\n ...response,\n images: response.images,\n usage: {\n inputTokens: response.usage?.inputTokens ?? 0,\n outputTokens: response.usage?.outputTokens ?? 0,\n ...response.usage,\n },\n model: response?.model,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAa,qBAAb,cAAwC,WAAW;CACjD,YAAY,AAAgB,SAAoC;AAC9D,iBAAe,sBAAsB,4BAA4B,QAAQ;AACzE,SAAO;EAFmB;;CAK5B,MAAM,SAAS;AACb,SAAO,UAAU;GAAE,UAAU,MAAM,KAAK,YAAY;GAAK,MAAM;GAAS,CAAC;;CAG3E,AAAU;CAEV,IAAI,SAAS;AACX,OAAK,YAAY,KAAK,WAAW,MAAM,EAAE,KAAK,QAAQ,YAAY;AAEhE,UAAO,IAAI,WADK;IAAE,GAAG,KAAK;IAAS;IAAK;IAAQ;IAAO,CACzB;IAC9B;AACF,SAAO,KAAK;;CAGd,AAAQ;CAMR,IAAa,aAAa;AACxB,OAAK,gBAAgB,sBACnB,KAAK,QAAQ,WAAW,iBAAiB,EACzC,uBACD,CAAC,MAAM,QAAQ;GACd,MAAM,OAAO;GAEb,MAAM,gBAAgB,QAAQ,IAAI;GAClC,IAAI,oBAAyC,EAAE;AAC/C,OAAI;AACF,wBACE,OAAO,kBAAkB,WAAW,KAAK,MAAM,cAAc,GAAI,iBAAiB,EAAE;YAC/E,KAAK;AACZ,YAAQ,MAAM,IAAI;;AAGpB,UAAO;IACL,GAAG;IACH,KAAK,IAAI,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,KAAK;IAClD,QAAQ,KAAK,QAAQ,UAAU,QAAQ,IAAI,qBAAqB,kBAAkB;IAClF,OAAO,KAAK,QAAQ,SAAS,QAAQ,IAAI,4BAA4B;IACtE;IACD;AAEF,SAAO,KAAK;;CAGd,MAAe,QACb,OACA,SAC+C;EAC/C,MAAM,EAAE,kBAAkB,iBAAiB,OAAO;EAClD,MAAM,WACJ,KAAK,SAAS,eAAe,YAC7B,oBACA,gBACA,oBAAoB,OAAO,YAAY,cAAc,OAAO,GAAG,UAAU,GAAG;EAE9E,MAAM,WAAW,OAAO,MAAM,KAAK,QAAQ,SACzC,QACA;GACE,GAAG;GACH,cAAc;IACZ,GAAG,MAAM;IACT,OAAO,MAAM,cAAc,UAAU,MAAM,KAAK,YAAY;IAC7D;GAED,gBAAgB;GACjB,EACD;GACE,GAAG;GACH,WAAW;GACX,cAAc;IACZ,GAAG,QAAQ;IACX,SAAS;KACP,GAAG,QAAQ,cAAc;KACzB,0BAA0B;KAC3B;IACF;GACF,CACF;AAED,SAAO;GACL,GAAG;GACH,QAAQ,SAAS;GACjB,OAAO;IACL,aAAa,SAAS,OAAO,eAAe;IAC5C,cAAc,SAAS,OAAO,gBAAgB;IAC9C,GAAG,SAAS;IACb;GACD,OAAO,UAAU;GAClB"}
@@ -0,0 +1,80 @@
1
+ const require_blocklet = require('./utils/blocklet.cjs');
2
+ const require_constants = require('./utils/constants.cjs');
3
+ const require_hub = require('./utils/hub.cjs');
4
+ const require_type = require('./utils/type.cjs');
5
+ let _aigne_core = require("@aigne/core");
6
+ let ufo = require("ufo");
7
+ let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
8
+ let _aigne_transport_http_client_base_client = require("@aigne/transport/http-client/base-client");
9
+ let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
10
+
11
+ //#region src/aigne-hub-model.ts
12
+ var AIGNEHubChatModel = class extends _aigne_core.ChatModel {
13
+ constructor(options) {
14
+ (0, _aigne_core_utils_type_utils.checkArguments)("AIGNEHubChatModel", require_type.aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return require_hub.getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "chat"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new _aigne_transport_http_client_base_client.BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= require_blocklet.getAIGNEHubMountPoint(this.options.baseURL || require_constants.aigneHubBaseUrl(), require_constants.AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/chat";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : (0, ufo.joinURL)(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_DEFAULT_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_utils_nodejs.nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
59
+ return await (await this.client).__invoke(void 0, {
60
+ ...input,
61
+ modelOptions: {
62
+ ...input.modelOptions,
63
+ model: input.modelOptions?.model || (await this.credential).model
64
+ },
65
+ outputFileType: "url"
66
+ }, {
67
+ ...options,
68
+ fetchOptions: {
69
+ ...options.fetchOptions,
70
+ headers: {
71
+ ...options.fetchOptions?.headers,
72
+ "x-aigne-hub-client-did": clientId
73
+ }
74
+ }
75
+ });
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ exports.AIGNEHubChatModel = AIGNEHubChatModel;
@@ -0,0 +1,81 @@
1
+ import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
2
+ import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_DEFAULT_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
3
+ import { getModels } from "./utils/hub.mjs";
4
+ import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
5
+ import { ChatModel } from "@aigne/core";
6
+ import { joinURL } from "ufo";
7
+ import { checkArguments } from "@aigne/core/utils/type-utils";
8
+ import { BaseClient } from "@aigne/transport/http-client/base-client";
9
+ import { nodejs } from "@aigne/utils/nodejs";
10
+
11
+ //#region src/aigne-hub-model.ts
12
+ var AIGNEHubChatModel = class extends ChatModel {
13
+ constructor(options) {
14
+ checkArguments("AIGNEHubChatModel", aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "chat"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= getAIGNEHubMountPoint(this.options.baseURL || aigneHubBaseUrl(), AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/chat";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : joinURL(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_DEFAULT_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? nodejs.os.hostname() : "unknown"}`;
59
+ return await (await this.client).__invoke(void 0, {
60
+ ...input,
61
+ modelOptions: {
62
+ ...input.modelOptions,
63
+ model: input.modelOptions?.model || (await this.credential).model
64
+ },
65
+ outputFileType: "url"
66
+ }, {
67
+ ...options,
68
+ fetchOptions: {
69
+ ...options.fetchOptions,
70
+ headers: {
71
+ ...options.fetchOptions?.headers,
72
+ "x-aigne-hub-client-did": clientId
73
+ }
74
+ }
75
+ });
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ export { AIGNEHubChatModel };
81
+ //# sourceMappingURL=aigne-hub-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aigne-hub-model.mjs","names":[],"sources":["../src/aigne-hub-model.ts"],"sourcesContent":["import {\n type AgentInvokeOptions,\n type AgentProcessResult,\n ChatModel,\n type ChatModelInput,\n type ChatModelOutput,\n} from \"@aigne/core\";\nimport { checkArguments } from \"@aigne/core/utils/type-utils\";\nimport { BaseClient, type BaseClientInvokeOptions } from \"@aigne/transport/http-client/base-client\";\nimport { nodejs } from \"@aigne/utils/nodejs\";\nimport { joinURL } from \"ufo\";\nimport { getAIGNEHubMountPoint } from \"./utils/blocklet.js\";\nimport {\n AIGNE_HUB_BLOCKLET_DID,\n AIGNE_HUB_DEFAULT_MODEL,\n aigneHubBaseUrl,\n} from \"./utils/constants.js\";\nimport { getModels } from \"./utils/hub.js\";\nimport { type AIGNEHubChatModelOptions, aigneHubModelOptionsSchema } from \"./utils/type.js\";\n\nexport class AIGNEHubChatModel extends ChatModel {\n constructor(public override options: AIGNEHubChatModelOptions) {\n checkArguments(\"AIGNEHubChatModel\", aigneHubModelOptionsSchema, options);\n super();\n }\n\n async models() {\n return getModels({ baseURL: (await this.credential).url, type: \"chat\" });\n }\n\n protected _client?: Promise<BaseClient>;\n\n get client() {\n this._client ??= this.credential.then(({ url, apiKey, model }) => {\n const options = { ...this.options, url, apiKey, model };\n return new BaseClient(options);\n });\n return this._client;\n }\n\n private _credential?: Promise<{\n url: string;\n apiKey?: string;\n model: string;\n }>;\n\n override get credential() {\n this._credential ??= getAIGNEHubMountPoint(\n this.options.baseURL || aigneHubBaseUrl(),\n AIGNE_HUB_BLOCKLET_DID,\n ).then((url) => {\n const path = \"/api/v2/chat\";\n\n const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;\n let credentialOptions: Record<string, any> = {};\n try {\n credentialOptions =\n typeof rawCredential === \"string\" ? JSON.parse(rawCredential) : (rawCredential ?? {});\n } catch (err) {\n console.error(err);\n }\n\n return {\n ...credentialOptions,\n url: url.endsWith(path) ? url : joinURL(url, path),\n apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,\n model:\n this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_DEFAULT_MODEL,\n };\n });\n\n return this._credential;\n }\n\n override async process(\n input: ChatModelInput,\n options: BaseClientInvokeOptions & AgentInvokeOptions,\n ): Promise<AgentProcessResult<ChatModelOutput>> {\n const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;\n const clientId =\n this.options?.clientOptions?.clientId ||\n BLOCKLET_APP_PID ||\n ABT_NODE_DID ||\n `@aigne/aigne-hub:${typeof process !== \"undefined\" ? nodejs.os.hostname() : \"unknown\"}`;\n\n const response = await (await this.client).__invoke<ChatModelInput, ChatModelOutput>(\n undefined,\n {\n ...input,\n modelOptions: {\n ...input.modelOptions,\n model: input.modelOptions?.model || (await this.credential).model,\n },\n // Shouldn't use `local` output type for remote AIGNE Hub call, client can not access the remote filesystem\n outputFileType: \"url\",\n },\n {\n ...options,\n fetchOptions: {\n ...options.fetchOptions,\n headers: {\n ...options.fetchOptions?.headers,\n \"x-aigne-hub-client-did\": clientId,\n },\n },\n },\n );\n\n return response;\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,IAAa,oBAAb,cAAuC,UAAU;CAC/C,YAAY,AAAgB,SAAmC;AAC7D,iBAAe,qBAAqB,4BAA4B,QAAQ;AACxE,SAAO;EAFmB;;CAK5B,MAAM,SAAS;AACb,SAAO,UAAU;GAAE,UAAU,MAAM,KAAK,YAAY;GAAK,MAAM;GAAQ,CAAC;;CAG1E,AAAU;CAEV,IAAI,SAAS;AACX,OAAK,YAAY,KAAK,WAAW,MAAM,EAAE,KAAK,QAAQ,YAAY;AAEhE,UAAO,IAAI,WADK;IAAE,GAAG,KAAK;IAAS;IAAK;IAAQ;IAAO,CACzB;IAC9B;AACF,SAAO,KAAK;;CAGd,AAAQ;CAMR,IAAa,aAAa;AACxB,OAAK,gBAAgB,sBACnB,KAAK,QAAQ,WAAW,iBAAiB,EACzC,uBACD,CAAC,MAAM,QAAQ;GACd,MAAM,OAAO;GAEb,MAAM,gBAAgB,QAAQ,IAAI;GAClC,IAAI,oBAAyC,EAAE;AAC/C,OAAI;AACF,wBACE,OAAO,kBAAkB,WAAW,KAAK,MAAM,cAAc,GAAI,iBAAiB,EAAE;YAC/E,KAAK;AACZ,YAAQ,MAAM,IAAI;;AAGpB,UAAO;IACL,GAAG;IACH,KAAK,IAAI,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,KAAK;IAClD,QAAQ,KAAK,QAAQ,UAAU,QAAQ,IAAI,qBAAqB,kBAAkB;IAClF,OACE,KAAK,QAAQ,SAAS,QAAQ,IAAI,4BAA4B;IACjE;IACD;AAEF,SAAO,KAAK;;CAGd,MAAe,QACb,OACA,SAC8C;EAC9C,MAAM,EAAE,kBAAkB,iBAAiB,OAAO;EAClD,MAAM,WACJ,KAAK,SAAS,eAAe,YAC7B,oBACA,gBACA,oBAAoB,OAAO,YAAY,cAAc,OAAO,GAAG,UAAU,GAAG;AAyB9E,SAvBiB,OAAO,MAAM,KAAK,QAAQ,SACzC,QACA;GACE,GAAG;GACH,cAAc;IACZ,GAAG,MAAM;IACT,OAAO,MAAM,cAAc,UAAU,MAAM,KAAK,YAAY;IAC7D;GAED,gBAAgB;GACjB,EACD;GACE,GAAG;GACH,cAAc;IACZ,GAAG,QAAQ;IACX,SAAS;KACP,GAAG,QAAQ,cAAc;KACzB,0BAA0B;KAC3B;IACF;GACF,CACF"}
@@ -0,0 +1,95 @@
1
+ const require_blocklet = require('./utils/blocklet.cjs');
2
+ const require_constants = require('./utils/constants.cjs');
3
+ const require_hub = require('./utils/hub.cjs');
4
+ const require_type = require('./utils/type.cjs');
5
+ let _aigne_core = require("@aigne/core");
6
+ let ufo = require("ufo");
7
+ let _aigne_core_utils_type_utils = require("@aigne/core/utils/type-utils");
8
+ let _aigne_transport_http_client_base_client = require("@aigne/transport/http-client/base-client");
9
+ let _aigne_utils_nodejs = require("@aigne/utils/nodejs");
10
+
11
+ //#region src/aigne-hub-video-model.ts
12
+ var AIGNEHubVideoModel = class extends _aigne_core.VideoModel {
13
+ constructor(options) {
14
+ (0, _aigne_core_utils_type_utils.checkArguments)("AIGNEHubVideoModel", require_type.aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return require_hub.getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "video"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new _aigne_transport_http_client_base_client.BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= require_blocklet.getAIGNEHubMountPoint(this.options.baseURL || require_constants.aigneHubBaseUrl(), require_constants.AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/video";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : (0, ufo.joinURL)(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || require_constants.AIGNE_HUB_VIDEO_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = _aigne_utils_nodejs.nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? _aigne_utils_nodejs.nodejs.os.hostname() : "unknown"}`;
59
+ const model = input.model || input.modelOptions?.model || (await this.credential).model;
60
+ const response = await (await this.client).__invoke(void 0, {
61
+ ...input,
62
+ model,
63
+ modelOptions: {
64
+ ...this.options.modelOptions,
65
+ ...input.modelOptions,
66
+ model
67
+ },
68
+ outputFileType: "url"
69
+ }, {
70
+ ...options,
71
+ streaming: false,
72
+ fetchOptions: {
73
+ ...options.fetchOptions,
74
+ timeout: 6e4 * 3,
75
+ headers: {
76
+ ...options.fetchOptions?.headers,
77
+ "x-aigne-hub-client-did": clientId
78
+ }
79
+ }
80
+ });
81
+ return {
82
+ ...response,
83
+ videos: response.videos,
84
+ usage: {
85
+ inputTokens: response.usage?.inputTokens ?? 0,
86
+ outputTokens: response.usage?.outputTokens ?? 0,
87
+ ...response.usage
88
+ },
89
+ model: response?.model
90
+ };
91
+ }
92
+ };
93
+
94
+ //#endregion
95
+ exports.AIGNEHubVideoModel = AIGNEHubVideoModel;
@@ -0,0 +1,96 @@
1
+ import { getAIGNEHubMountPoint } from "./utils/blocklet.mjs";
2
+ import { AIGNE_HUB_BLOCKLET_DID, AIGNE_HUB_VIDEO_MODEL, aigneHubBaseUrl } from "./utils/constants.mjs";
3
+ import { getModels } from "./utils/hub.mjs";
4
+ import { aigneHubModelOptionsSchema } from "./utils/type.mjs";
5
+ import { VideoModel } from "@aigne/core";
6
+ import { joinURL } from "ufo";
7
+ import { checkArguments } from "@aigne/core/utils/type-utils";
8
+ import { BaseClient } from "@aigne/transport/http-client/base-client";
9
+ import { nodejs } from "@aigne/utils/nodejs";
10
+
11
+ //#region src/aigne-hub-video-model.ts
12
+ var AIGNEHubVideoModel = class extends VideoModel {
13
+ constructor(options) {
14
+ checkArguments("AIGNEHubVideoModel", aigneHubModelOptionsSchema, options);
15
+ super();
16
+ this.options = options;
17
+ }
18
+ async models() {
19
+ return getModels({
20
+ baseURL: (await this.credential).url,
21
+ type: "video"
22
+ });
23
+ }
24
+ _client;
25
+ get client() {
26
+ this._client ??= this.credential.then(({ url, apiKey, model }) => {
27
+ return new BaseClient({
28
+ ...this.options,
29
+ url,
30
+ apiKey,
31
+ model
32
+ });
33
+ });
34
+ return this._client;
35
+ }
36
+ _credential;
37
+ get credential() {
38
+ this._credential ??= getAIGNEHubMountPoint(this.options.baseURL || aigneHubBaseUrl(), AIGNE_HUB_BLOCKLET_DID).then((url) => {
39
+ const path = "/api/v2/video";
40
+ const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;
41
+ let credentialOptions = {};
42
+ try {
43
+ credentialOptions = typeof rawCredential === "string" ? JSON.parse(rawCredential) : rawCredential ?? {};
44
+ } catch (err) {
45
+ console.error(err);
46
+ }
47
+ return {
48
+ ...credentialOptions,
49
+ url: url.endsWith(path) ? url : joinURL(url, path),
50
+ apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,
51
+ model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_VIDEO_MODEL
52
+ };
53
+ });
54
+ return this._credential;
55
+ }
56
+ async process(input, options) {
57
+ const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;
58
+ const clientId = this.options?.clientOptions?.clientId || BLOCKLET_APP_PID || ABT_NODE_DID || `@aigne/aigne-hub:${typeof process !== "undefined" ? nodejs.os.hostname() : "unknown"}`;
59
+ const model = input.model || input.modelOptions?.model || (await this.credential).model;
60
+ const response = await (await this.client).__invoke(void 0, {
61
+ ...input,
62
+ model,
63
+ modelOptions: {
64
+ ...this.options.modelOptions,
65
+ ...input.modelOptions,
66
+ model
67
+ },
68
+ outputFileType: "url"
69
+ }, {
70
+ ...options,
71
+ streaming: false,
72
+ fetchOptions: {
73
+ ...options.fetchOptions,
74
+ timeout: 6e4 * 3,
75
+ headers: {
76
+ ...options.fetchOptions?.headers,
77
+ "x-aigne-hub-client-did": clientId
78
+ }
79
+ }
80
+ });
81
+ return {
82
+ ...response,
83
+ videos: response.videos,
84
+ usage: {
85
+ inputTokens: response.usage?.inputTokens ?? 0,
86
+ outputTokens: response.usage?.outputTokens ?? 0,
87
+ ...response.usage
88
+ },
89
+ model: response?.model
90
+ };
91
+ }
92
+ };
93
+
94
+ //#endregion
95
+ export { AIGNEHubVideoModel };
96
+ //# sourceMappingURL=aigne-hub-video-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aigne-hub-video-model.mjs","names":[],"sources":["../src/aigne-hub-video-model.ts"],"sourcesContent":["import {\n type AgentProcessResult,\n VideoModel,\n type VideoModelInput,\n type VideoModelOutput,\n} from \"@aigne/core\";\nimport { checkArguments } from \"@aigne/core/utils/type-utils\";\nimport { BaseClient, type BaseClientInvokeOptions } from \"@aigne/transport/http-client/base-client\";\nimport { nodejs } from \"@aigne/utils/nodejs\";\nimport { joinURL } from \"ufo\";\nimport { getAIGNEHubMountPoint } from \"./utils/blocklet.js\";\nimport {\n AIGNE_HUB_BLOCKLET_DID,\n AIGNE_HUB_VIDEO_MODEL,\n aigneHubBaseUrl,\n} from \"./utils/constants.js\";\nimport { getModels } from \"./utils/hub.js\";\nimport { type AIGNEHubVideoModelOptions, aigneHubModelOptionsSchema } from \"./utils/type.js\";\n\nexport class AIGNEHubVideoModel extends VideoModel {\n constructor(public override options: AIGNEHubVideoModelOptions) {\n checkArguments(\"AIGNEHubVideoModel\", aigneHubModelOptionsSchema, options);\n super();\n }\n\n async models() {\n return getModels({ baseURL: (await this.credential).url, type: \"video\" });\n }\n\n protected _client?: Promise<BaseClient>;\n\n get client() {\n this._client ??= this.credential.then(({ url, apiKey, model }) => {\n const options = { ...this.options, url, apiKey, model };\n return new BaseClient(options);\n });\n return this._client;\n }\n\n private _credential?: Promise<{\n url: string;\n apiKey?: string;\n model: string;\n }>;\n\n override get credential() {\n this._credential ??= getAIGNEHubMountPoint(\n this.options.baseURL || aigneHubBaseUrl(),\n AIGNE_HUB_BLOCKLET_DID,\n ).then((url) => {\n const path = \"/api/v2/video\";\n\n const rawCredential = process.env.BLOCKLET_AIGNE_API_CREDENTIAL;\n let credentialOptions: Record<string, any> = {};\n try {\n credentialOptions =\n typeof rawCredential === \"string\" ? JSON.parse(rawCredential) : (rawCredential ?? {});\n } catch (err) {\n console.error(err);\n }\n\n return {\n ...credentialOptions,\n url: url.endsWith(path) ? url : joinURL(url, path),\n apiKey: this.options.apiKey || process.env.AIGNE_HUB_API_KEY || credentialOptions.apiKey,\n model: this.options.model || process.env.BLOCKLET_AIGNE_API_MODEL || AIGNE_HUB_VIDEO_MODEL,\n };\n });\n\n return this._credential;\n }\n\n override async process(\n input: VideoModelInput,\n options: BaseClientInvokeOptions,\n ): Promise<AgentProcessResult<VideoModelOutput>> {\n const { BLOCKLET_APP_PID, ABT_NODE_DID } = nodejs.env;\n const clientId =\n this.options?.clientOptions?.clientId ||\n BLOCKLET_APP_PID ||\n ABT_NODE_DID ||\n `@aigne/aigne-hub:${typeof process !== \"undefined\" ? nodejs.os.hostname() : \"unknown\"}`;\n const model = input.model || input.modelOptions?.model || (await this.credential).model;\n\n const response = await (await this.client).__invoke<VideoModelInput, VideoModelOutput>(\n undefined,\n {\n ...input,\n model: model,\n modelOptions: { ...this.options.modelOptions, ...input.modelOptions, model: model },\n outputFileType: \"url\",\n },\n {\n ...options,\n streaming: false,\n fetchOptions: {\n ...options.fetchOptions,\n timeout: 60e3 * 3,\n headers: {\n ...options.fetchOptions?.headers,\n \"x-aigne-hub-client-did\": clientId,\n },\n },\n },\n );\n\n return {\n ...response,\n videos: response.videos,\n usage: {\n inputTokens: response.usage?.inputTokens ?? 0,\n outputTokens: response.usage?.outputTokens ?? 0,\n ...response.usage,\n },\n model: response?.model,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,IAAa,qBAAb,cAAwC,WAAW;CACjD,YAAY,AAAgB,SAAoC;AAC9D,iBAAe,sBAAsB,4BAA4B,QAAQ;AACzE,SAAO;EAFmB;;CAK5B,MAAM,SAAS;AACb,SAAO,UAAU;GAAE,UAAU,MAAM,KAAK,YAAY;GAAK,MAAM;GAAS,CAAC;;CAG3E,AAAU;CAEV,IAAI,SAAS;AACX,OAAK,YAAY,KAAK,WAAW,MAAM,EAAE,KAAK,QAAQ,YAAY;AAEhE,UAAO,IAAI,WADK;IAAE,GAAG,KAAK;IAAS;IAAK;IAAQ;IAAO,CACzB;IAC9B;AACF,SAAO,KAAK;;CAGd,AAAQ;CAMR,IAAa,aAAa;AACxB,OAAK,gBAAgB,sBACnB,KAAK,QAAQ,WAAW,iBAAiB,EACzC,uBACD,CAAC,MAAM,QAAQ;GACd,MAAM,OAAO;GAEb,MAAM,gBAAgB,QAAQ,IAAI;GAClC,IAAI,oBAAyC,EAAE;AAC/C,OAAI;AACF,wBACE,OAAO,kBAAkB,WAAW,KAAK,MAAM,cAAc,GAAI,iBAAiB,EAAE;YAC/E,KAAK;AACZ,YAAQ,MAAM,IAAI;;AAGpB,UAAO;IACL,GAAG;IACH,KAAK,IAAI,SAAS,KAAK,GAAG,MAAM,QAAQ,KAAK,KAAK;IAClD,QAAQ,KAAK,QAAQ,UAAU,QAAQ,IAAI,qBAAqB,kBAAkB;IAClF,OAAO,KAAK,QAAQ,SAAS,QAAQ,IAAI,4BAA4B;IACtE;IACD;AAEF,SAAO,KAAK;;CAGd,MAAe,QACb,OACA,SAC+C;EAC/C,MAAM,EAAE,kBAAkB,iBAAiB,OAAO;EAClD,MAAM,WACJ,KAAK,SAAS,eAAe,YAC7B,oBACA,gBACA,oBAAoB,OAAO,YAAY,cAAc,OAAO,GAAG,UAAU,GAAG;EAC9E,MAAM,QAAQ,MAAM,SAAS,MAAM,cAAc,UAAU,MAAM,KAAK,YAAY;EAElF,MAAM,WAAW,OAAO,MAAM,KAAK,QAAQ,SACzC,QACA;GACE,GAAG;GACI;GACP,cAAc;IAAE,GAAG,KAAK,QAAQ;IAAc,GAAG,MAAM;IAAqB;IAAO;GACnF,gBAAgB;GACjB,EACD;GACE,GAAG;GACH,WAAW;GACX,cAAc;IACZ,GAAG,QAAQ;IACX,SAAS,MAAO;IAChB,SAAS;KACP,GAAG,QAAQ,cAAc;KACzB,0BAA0B;KAC3B;IACF;GACF,CACF;AAED,SAAO;GACL,GAAG;GACH,QAAQ,SAAS;GACjB,OAAO;IACL,aAAa,SAAS,OAAO,eAAe;IAC5C,cAAc,SAAS,OAAO,gBAAgB;IAC9C,GAAG,SAAS;IACb;GACD,OAAO,UAAU;GAClB"}