@elizaos/plugin-elizacloud 2.0.0-alpha.7 → 2.0.0-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.
- package/LICENSE +21 -0
- package/README.md +220 -0
- package/auto-enable.ts +17 -0
- package/dist/browser/index.browser.js +2 -21
- package/dist/browser/index.browser.js.map +5 -37
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.node.cjs +12173 -2271
- package/dist/cjs/index.node.js.map +135 -27
- package/dist/cloud/auth.d.ts +19 -0
- package/dist/cloud/auth.d.ts.map +1 -0
- package/dist/cloud/auth.js +330 -0
- package/dist/cloud/auth.js.map +12 -0
- package/dist/cloud/backup.d.ts +18 -0
- package/dist/cloud/backup.d.ts.map +1 -0
- package/dist/cloud/backup.js +63 -0
- package/dist/cloud/backup.js.map +10 -0
- package/dist/cloud/base-url.d.ts +3 -0
- package/dist/cloud/base-url.d.ts.map +1 -0
- package/dist/cloud/base-url.js +77 -0
- package/dist/cloud/base-url.js.map +10 -0
- package/dist/cloud/bridge-client.d.ts +126 -0
- package/dist/cloud/bridge-client.d.ts.map +1 -0
- package/dist/cloud/bridge-client.js +432 -0
- package/dist/cloud/bridge-client.js.map +11 -0
- package/dist/cloud/cloud-api-key.d.ts +26 -0
- package/dist/cloud/cloud-api-key.d.ts.map +1 -0
- package/dist/cloud/cloud-api-key.js +60 -0
- package/dist/cloud/cloud-api-key.js.map +10 -0
- package/dist/cloud/cloud-manager.d.ts +33 -0
- package/dist/cloud/cloud-manager.d.ts.map +1 -0
- package/dist/cloud/cloud-manager.js +853 -0
- package/dist/cloud/cloud-manager.js.map +16 -0
- package/dist/cloud/cloud-proxy.d.ts +20 -0
- package/dist/cloud/cloud-proxy.d.ts.map +1 -0
- package/dist/cloud/cloud-proxy.js +54 -0
- package/dist/cloud/cloud-proxy.js.map +10 -0
- package/dist/cloud/cloud-wallet.d.ts +94 -0
- package/dist/cloud/cloud-wallet.d.ts.map +1 -0
- package/dist/cloud/cloud-wallet.js +5195 -0
- package/dist/cloud/cloud-wallet.js.map +92 -0
- package/dist/cloud/index.d.ts +9 -0
- package/dist/cloud/index.d.ts.map +1 -0
- package/dist/cloud/index.js +30 -0
- package/dist/cloud/index.js.map +9 -0
- package/dist/cloud/reconnect.d.ts +26 -0
- package/dist/cloud/reconnect.d.ts.map +1 -0
- package/dist/cloud/reconnect.js +104 -0
- package/dist/cloud/reconnect.js.map +10 -0
- package/dist/cloud/validate-url.d.ts +2 -0
- package/dist/cloud/validate-url.d.ts.map +1 -0
- package/dist/cloud/validate-url.js +174 -0
- package/dist/cloud/validate-url.js.map +10 -0
- package/dist/cloud-providers/cloud-status.d.ts.map +1 -1
- package/dist/cloud-providers/cloud-status.js +78 -0
- package/dist/cloud-providers/cloud-status.js.map +10 -0
- package/dist/cloud-providers/container-health.d.ts.map +1 -1
- package/dist/cloud-providers/container-health.js +74 -0
- package/dist/cloud-providers/container-health.js.map +10 -0
- package/dist/cloud-providers/credit-balance.d.ts.map +1 -1
- package/dist/cloud-providers/credit-balance.js +85 -0
- package/dist/cloud-providers/credit-balance.js.map +10 -0
- package/dist/cloud-providers/index.d.ts.map +1 -1
- package/dist/cloud-providers/index.js +24 -0
- package/dist/cloud-providers/index.js.map +9 -0
- package/dist/cloud-providers/model-registry.d.ts.map +1 -1
- package/dist/cloud-providers/model-registry.js +71 -0
- package/dist/cloud-providers/model-registry.js.map +10 -0
- package/dist/index.browser.d.ts +4 -2
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12851 -0
- package/dist/index.js.map +145 -0
- package/dist/index.node.d.ts +15 -2
- package/dist/index.node.d.ts.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +169 -0
- package/dist/init.js.map +12 -0
- package/dist/lib/cloud-connection.d.ts +78 -0
- package/dist/lib/cloud-connection.d.ts.map +1 -0
- package/dist/lib/cloud-connection.js +731 -0
- package/dist/lib/cloud-connection.js.map +14 -0
- package/dist/lib/cloud-secrets.d.ts +23 -0
- package/dist/lib/cloud-secrets.d.ts.map +1 -0
- package/dist/lib/cloud-secrets.js +64 -0
- package/dist/lib/cloud-secrets.js.map +10 -0
- package/dist/lib/config-env.d.ts +5 -0
- package/dist/lib/config-env.d.ts.map +1 -0
- package/dist/lib/config-env.js +191 -0
- package/dist/lib/config-env.js.map +11 -0
- package/dist/lib/config-like.d.ts +40 -0
- package/dist/lib/config-like.d.ts.map +1 -0
- package/dist/lib/config-like.js +103 -0
- package/dist/lib/config-like.js.map +10 -0
- package/dist/lib/credential-type-map.d.ts +53 -0
- package/dist/lib/credential-type-map.d.ts.map +1 -0
- package/dist/lib/credential-type-map.js +88 -0
- package/dist/lib/credential-type-map.js.map +10 -0
- package/dist/lib/feature-flags.d.ts +2 -0
- package/dist/lib/feature-flags.d.ts.map +1 -0
- package/dist/lib/feature-flags.js +40 -0
- package/dist/lib/feature-flags.js.map +10 -0
- package/dist/lib/http.d.ts +22 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +107 -0
- package/dist/lib/http.js.map +10 -0
- package/dist/lib/server-cloud-tts.d.ts +34 -0
- package/dist/lib/server-cloud-tts.d.ts.map +1 -0
- package/dist/lib/server-cloud-tts.js +549 -0
- package/dist/lib/server-cloud-tts.js.map +13 -0
- package/dist/lib/state-paths.d.ts +4 -0
- package/dist/lib/state-paths.d.ts.map +1 -0
- package/dist/lib/state-paths.js +52 -0
- package/dist/lib/state-paths.js.map +10 -0
- package/dist/lib/tts-debug.d.ts +4 -0
- package/dist/lib/tts-debug.d.ts.map +1 -0
- package/dist/lib/tts-debug.js +57 -0
- package/dist/lib/tts-debug.js.map +10 -0
- package/dist/models/embeddings.d.ts.map +1 -1
- package/dist/models/embeddings.js +319 -0
- package/dist/models/embeddings.js.map +13 -0
- package/dist/models/image.d.ts.map +1 -1
- package/dist/models/image.js +374 -0
- package/dist/models/image.js.map +14 -0
- package/dist/models/index.d.ts +1 -2
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1386 -0
- package/dist/models/index.js.map +20 -0
- package/dist/models/research.d.ts.map +1 -1
- package/dist/models/research.js +324 -0
- package/dist/models/research.js.map +13 -0
- package/dist/models/speech.d.ts.map +1 -1
- package/dist/models/speech.js +273 -0
- package/dist/models/speech.js.map +13 -0
- package/dist/models/text.d.ts +5 -2
- package/dist/models/text.d.ts.map +1 -1
- package/dist/models/text.js +803 -0
- package/dist/models/text.js.map +15 -0
- package/dist/models/tokenization.d.ts.map +1 -1
- package/dist/models/tokenization.js +65 -0
- package/dist/models/tokenization.js.map +10 -0
- package/dist/models/transcription.d.ts.map +1 -1
- package/dist/models/transcription.js +283 -0
- package/dist/models/transcription.js.map +13 -0
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.node.js +12171 -2266
- package/dist/node/index.node.js.map +135 -27
- package/dist/onboarding.d.ts +35 -0
- package/dist/onboarding.d.ts.map +1 -0
- package/dist/onboarding.js +883 -0
- package/dist/onboarding.js.map +14 -0
- package/dist/plugin.d.ts +20 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +7611 -0
- package/dist/plugin.js.map +104 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +127 -0
- package/dist/providers/openai.js.map +11 -0
- package/dist/register-routes.d.ts +2 -0
- package/dist/register-routes.d.ts.map +1 -0
- package/dist/register-routes.js +7612 -0
- package/dist/register-routes.js.map +105 -0
- package/dist/routes/cloud-billing-routes.d.ts +9 -0
- package/dist/routes/cloud-billing-routes.d.ts.map +1 -0
- package/dist/routes/cloud-billing-routes.js +807 -0
- package/dist/routes/cloud-billing-routes.js.map +14 -0
- package/dist/routes/cloud-compat-routes.d.ts +10 -0
- package/dist/routes/cloud-compat-routes.d.ts.map +1 -0
- package/dist/routes/cloud-compat-routes.js +538 -0
- package/dist/routes/cloud-compat-routes.js.map +14 -0
- package/dist/routes/cloud-features-routes.d.ts +9 -0
- package/dist/routes/cloud-features-routes.d.ts.map +1 -0
- package/dist/routes/cloud-features-routes.js +124 -0
- package/dist/routes/cloud-features-routes.js.map +11 -0
- package/dist/routes/cloud-provisioning.d.ts +14 -0
- package/dist/routes/cloud-provisioning.d.ts.map +1 -0
- package/dist/routes/cloud-provisioning.js +37 -0
- package/dist/routes/cloud-provisioning.js.map +10 -0
- package/dist/routes/cloud-relay-routes.d.ts +22 -0
- package/dist/routes/cloud-relay-routes.d.ts.map +1 -0
- package/dist/routes/cloud-relay-routes.js +60 -0
- package/dist/routes/cloud-relay-routes.js.map +10 -0
- package/dist/routes/cloud-routes-autonomous.d.ts +83 -0
- package/dist/routes/cloud-routes-autonomous.d.ts.map +1 -0
- package/dist/routes/cloud-routes-autonomous.js +6134 -0
- package/dist/routes/cloud-routes-autonomous.js.map +97 -0
- package/dist/routes/cloud-routes.d.ts +35 -0
- package/dist/routes/cloud-routes.d.ts.map +1 -0
- package/dist/routes/cloud-routes.js +6888 -0
- package/dist/routes/cloud-routes.js.map +100 -0
- package/dist/routes/cloud-status-routes-autonomous.d.ts +15 -0
- package/dist/routes/cloud-status-routes-autonomous.d.ts.map +1 -0
- package/dist/routes/cloud-status-routes-autonomous.js +396 -0
- package/dist/routes/cloud-status-routes-autonomous.js.map +13 -0
- package/dist/routes/cloud-status-routes.d.ts +4 -0
- package/dist/routes/cloud-status-routes.d.ts.map +1 -0
- package/dist/routes/cloud-status-routes.js +771 -0
- package/dist/routes/cloud-status-routes.js.map +15 -0
- package/dist/services/cloud-auth.d.ts +140 -5
- package/dist/services/cloud-auth.d.ts.map +1 -1
- package/dist/services/cloud-auth.js +363 -0
- package/dist/services/cloud-auth.js.map +12 -0
- package/dist/services/cloud-backup.d.ts.map +1 -1
- package/dist/services/cloud-backup.js +176 -0
- package/dist/services/cloud-backup.js.map +11 -0
- package/dist/services/cloud-bootstrap.d.ts +38 -0
- package/dist/services/cloud-bootstrap.d.ts.map +1 -0
- package/dist/services/cloud-bootstrap.js +84 -0
- package/dist/services/cloud-bootstrap.js.map +10 -0
- package/dist/services/cloud-bridge.d.ts +1 -1
- package/dist/services/cloud-bridge.d.ts.map +1 -1
- package/dist/services/cloud-bridge.js +308 -0
- package/dist/services/cloud-bridge.js.map +11 -0
- package/dist/services/cloud-container.d.ts.map +1 -1
- package/dist/services/cloud-container.js +241 -0
- package/dist/services/cloud-container.js.map +11 -0
- package/dist/services/cloud-credential-provider.d.ts +55 -0
- package/dist/services/cloud-credential-provider.d.ts.map +1 -0
- package/dist/services/cloud-credential-provider.js +190 -0
- package/dist/services/cloud-credential-provider.js.map +11 -0
- package/dist/services/cloud-managed-gateway-relay.d.ts +38 -0
- package/dist/services/cloud-managed-gateway-relay.d.ts.map +1 -0
- package/dist/services/cloud-managed-gateway-relay.js +479 -0
- package/dist/services/cloud-managed-gateway-relay.js.map +10 -0
- package/dist/services/cloud-model-registry.d.ts.map +1 -1
- package/dist/services/cloud-model-registry.js +175 -0
- package/dist/services/cloud-model-registry.js.map +10 -0
- package/dist/services/index.d.ts +3 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +29 -0
- package/dist/services/index.js.map +9 -0
- package/dist/types/cloud.d.ts +41 -19
- package/dist/types/cloud.d.ts.map +1 -1
- package/dist/types/cloud.js +52 -0
- package/dist/types/cloud.js.map +10 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +9 -0
- package/dist/utils/cloud-api.d.ts +2 -27
- package/dist/utils/cloud-api.d.ts.map +1 -1
- package/dist/utils/cloud-api.js +33 -0
- package/dist/utils/cloud-api.js.map +10 -0
- package/dist/utils/cloud-sdk/client.d.ts +133 -0
- package/dist/utils/cloud-sdk/client.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/client.js +3561 -0
- package/dist/utils/cloud-sdk/client.js.map +13 -0
- package/dist/utils/cloud-sdk/http.d.ts +37 -0
- package/dist/utils/cloud-sdk/http.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/http.js +237 -0
- package/dist/utils/cloud-sdk/http.js.map +11 -0
- package/dist/utils/cloud-sdk/index.d.ts +6 -0
- package/dist/utils/cloud-sdk/index.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/index.js +29 -0
- package/dist/utils/cloud-sdk/index.js.map +9 -0
- package/dist/utils/cloud-sdk/public-routes.d.ts +5377 -0
- package/dist/utils/cloud-sdk/public-routes.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/public-routes.js +2950 -0
- package/dist/utils/cloud-sdk/public-routes.js.map +10 -0
- package/dist/utils/cloud-sdk/types.cloud-api.d.ts +101 -0
- package/dist/utils/cloud-sdk/types.cloud-api.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/types.cloud-api.js +2 -0
- package/dist/utils/cloud-sdk/types.cloud-api.js.map +9 -0
- package/dist/utils/cloud-sdk/types.d.ts +655 -0
- package/dist/utils/cloud-sdk/types.d.ts.map +1 -0
- package/dist/utils/cloud-sdk/types.js +29 -0
- package/dist/utils/cloud-sdk/types.js.map +10 -0
- package/dist/utils/config.d.ts +7 -3
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +137 -0
- package/dist/utils/config.js.map +10 -0
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/events.js +43 -0
- package/dist/utils/events.js.map +10 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +103 -0
- package/dist/utils/helpers.js.map +10 -0
- package/dist/utils/responses-output.d.ts +13 -0
- package/dist/utils/responses-output.d.ts.map +1 -0
- package/dist/utils/responses-output.js +102 -0
- package/dist/utils/responses-output.js.map +10 -0
- package/dist/utils/sdk-client.d.ts +5 -0
- package/dist/utils/sdk-client.d.ts.map +1 -0
- package/dist/utils/sdk-client.js +144 -0
- package/dist/utils/sdk-client.js.map +11 -0
- package/package.json +108 -19
- package/src/cloud/auth.ts +175 -0
- package/src/cloud/backup.ts +46 -0
- package/src/cloud/base-url.ts +62 -0
- package/src/cloud/bridge-client.ts +602 -0
- package/src/cloud/cloud-api-key.ts +80 -0
- package/src/cloud/cloud-manager.ts +163 -0
- package/src/cloud/cloud-proxy.ts +52 -0
- package/src/cloud/cloud-wallet.ts +341 -0
- package/src/cloud/index.ts +28 -0
- package/src/cloud/reconnect.ts +111 -0
- package/src/cloud/validate-url.ts +181 -0
- package/src/cloud-providers/cloud-status.ts +75 -0
- package/src/cloud-providers/container-health.ts +68 -0
- package/src/cloud-providers/credit-balance.ts +70 -0
- package/src/cloud-providers/index.ts +3 -0
- package/src/cloud-providers/model-registry.ts +74 -0
- package/src/index.browser.ts +10 -0
- package/src/index.node.ts +39 -0
- package/src/index.ts +347 -0
- package/src/init.ts +39 -0
- package/src/lib/cloud-connection.ts +663 -0
- package/src/lib/cloud-secrets.ts +58 -0
- package/src/lib/config-env.ts +168 -0
- package/src/lib/config-like.ts +149 -0
- package/src/lib/credential-type-map.ts +130 -0
- package/src/lib/feature-flags.ts +26 -0
- package/src/lib/http.ts +139 -0
- package/src/lib/server-cloud-tts.ts +609 -0
- package/src/lib/state-paths.ts +28 -0
- package/src/lib/tts-debug.ts +34 -0
- package/src/models/embeddings.ts +234 -0
- package/src/models/image.ts +219 -0
- package/src/models/index.ts +16 -0
- package/src/models/research.ts +265 -0
- package/src/models/speech.ts +78 -0
- package/src/models/text.ts +899 -0
- package/src/models/tokenization.ts +67 -0
- package/src/models/transcription.ts +97 -0
- package/src/onboarding.ts +396 -0
- package/src/plugin.ts +243 -0
- package/src/providers/openai.ts +16 -0
- package/src/register-routes.ts +6 -0
- package/src/routes/cloud-billing-routes.ts +754 -0
- package/src/routes/cloud-compat-routes.ts +314 -0
- package/src/routes/cloud-features-routes.ts +57 -0
- package/src/routes/cloud-provisioning.ts +37 -0
- package/src/routes/cloud-relay-routes.ts +89 -0
- package/src/routes/cloud-routes-autonomous.ts +996 -0
- package/src/routes/cloud-routes.ts +576 -0
- package/src/routes/cloud-status-routes-autonomous.ts +234 -0
- package/src/routes/cloud-status-routes.ts +73 -0
- package/src/services/cloud-auth.ts +567 -0
- package/src/services/cloud-backup.ts +208 -0
- package/src/services/cloud-bootstrap.ts +108 -0
- package/src/services/cloud-bridge.ts +386 -0
- package/src/services/cloud-container.ts +297 -0
- package/src/services/cloud-credential-provider.ts +210 -0
- package/src/services/cloud-managed-gateway-relay.ts +663 -0
- package/src/services/cloud-model-registry.ts +202 -0
- package/src/services/index.ts +17 -0
- package/{types → src/types}/cloud.ts +52 -29
- package/{types → src/types}/index.ts +6 -0
- package/src/utils/cloud-api.ts +10 -0
- package/src/utils/cloud-sdk/client.ts +735 -0
- package/src/utils/cloud-sdk/http.ts +291 -0
- package/src/utils/cloud-sdk/index.ts +23 -0
- package/src/utils/cloud-sdk/public-routes.ts +5070 -0
- package/src/utils/cloud-sdk/types.cloud-api.ts +120 -0
- package/src/utils/cloud-sdk/types.ts +762 -0
- package/src/utils/config.ts +174 -0
- package/src/utils/events.ts +37 -0
- package/src/utils/helpers.ts +107 -0
- package/src/utils/responses-output.ts +115 -0
- package/src/utils/sdk-client.ts +37 -0
- package/dist/actions/check-credits.d.ts +0 -6
- package/dist/actions/check-credits.d.ts.map +0 -1
- package/dist/actions/freeze-agent.d.ts +0 -9
- package/dist/actions/freeze-agent.d.ts.map +0 -1
- package/dist/actions/index.d.ts +0 -5
- package/dist/actions/index.d.ts.map +0 -1
- package/dist/actions/provision-agent.d.ts +0 -8
- package/dist/actions/provision-agent.d.ts.map +0 -1
- package/dist/actions/resume-agent.d.ts +0 -9
- package/dist/actions/resume-agent.d.ts.map +0 -1
- package/dist/build.d.ts +0 -3
- package/dist/build.d.ts.map +0 -1
- package/dist/generated/specs/specs.d.ts +0 -55
- package/dist/generated/specs/specs.d.ts.map +0 -1
- package/dist/models/object.d.ts +0 -4
- package/dist/models/object.d.ts.map +0 -1
- package/dist/utils/forwarded-settings.d.ts +0 -8
- package/dist/utils/forwarded-settings.d.ts.map +0 -1
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
18
|
+
|
|
19
|
+
// src/utils/config.ts
|
|
20
|
+
import { logger } from "@elizaos/core";
|
|
21
|
+
import { DEFAULT_ELIZA_CLOUD_TEXT_MODEL } from "@elizaos/core";
|
|
22
|
+
var DEFAULT_ELIZA_CLOUD_LARGE_MODEL = "deepseek/deepseek-v4-pro";
|
|
23
|
+
function getEnvValue(key) {
|
|
24
|
+
if (typeof process === "undefined") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const value = process.env[key];
|
|
28
|
+
return value === undefined ? undefined : String(value);
|
|
29
|
+
}
|
|
30
|
+
function getSetting(runtime, key, defaultValue) {
|
|
31
|
+
const value = runtime.getSetting(key);
|
|
32
|
+
if (value !== undefined && value !== null) {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
return getEnvValue(key) ?? defaultValue;
|
|
36
|
+
}
|
|
37
|
+
function isBrowser() {
|
|
38
|
+
return typeof globalThis !== "undefined" && typeof globalThis.document !== "undefined";
|
|
39
|
+
}
|
|
40
|
+
function isProxyMode(runtime) {
|
|
41
|
+
return isBrowser() && !!getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL");
|
|
42
|
+
}
|
|
43
|
+
function getBaseURL(runtime) {
|
|
44
|
+
const browserURL = getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL");
|
|
45
|
+
const baseURL = isBrowser() && browserURL ? browserURL : getSetting(runtime, "ELIZAOS_CLOUD_BASE_URL", "https://www.elizacloud.ai/api/v1");
|
|
46
|
+
return baseURL;
|
|
47
|
+
}
|
|
48
|
+
function getEmbeddingBaseURL(runtime) {
|
|
49
|
+
const embeddingURL = isBrowser() ? getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_EMBEDDING_URL") || getSetting(runtime, "ELIZAOS_CLOUD_BROWSER_BASE_URL") : getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_URL");
|
|
50
|
+
if (embeddingURL) {
|
|
51
|
+
logger.debug(`[ELIZAOS_CLOUD] Using specific embedding base URL: ${embeddingURL}`);
|
|
52
|
+
return embeddingURL;
|
|
53
|
+
}
|
|
54
|
+
logger.debug("[ELIZAOS_CLOUD] Falling back to general base URL for embeddings.");
|
|
55
|
+
return getBaseURL(runtime);
|
|
56
|
+
}
|
|
57
|
+
function getApiKey(runtime) {
|
|
58
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_API_KEY");
|
|
59
|
+
}
|
|
60
|
+
function getEmbeddingApiKey(runtime) {
|
|
61
|
+
const embeddingApiKey = getSetting(runtime, "ELIZAOS_CLOUD_EMBEDDING_API_KEY");
|
|
62
|
+
if (embeddingApiKey) {
|
|
63
|
+
logger.debug("[ELIZAOS_CLOUD] Using specific embedding API key (present)");
|
|
64
|
+
return embeddingApiKey;
|
|
65
|
+
}
|
|
66
|
+
logger.debug("[ELIZAOS_CLOUD] Falling back to general API key for embeddings.");
|
|
67
|
+
return getApiKey(runtime);
|
|
68
|
+
}
|
|
69
|
+
function getSmallModel(runtime) {
|
|
70
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_SMALL_MODEL") ?? getSetting(runtime, "SMALL_MODEL", DEFAULT_ELIZA_CLOUD_TEXT_MODEL);
|
|
71
|
+
}
|
|
72
|
+
function getNanoModel(runtime) {
|
|
73
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_NANO_MODEL") ?? getSetting(runtime, "NANO_MODEL") ?? getSmallModel(runtime);
|
|
74
|
+
}
|
|
75
|
+
function getMediumModel(runtime) {
|
|
76
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_MEDIUM_MODEL") ?? getSetting(runtime, "MEDIUM_MODEL") ?? getSmallModel(runtime);
|
|
77
|
+
}
|
|
78
|
+
function getLargeModel(runtime) {
|
|
79
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_LARGE_MODEL") ?? getSetting(runtime, "LARGE_MODEL", DEFAULT_ELIZA_CLOUD_LARGE_MODEL);
|
|
80
|
+
}
|
|
81
|
+
function getMegaModel(runtime) {
|
|
82
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_MEGA_MODEL") ?? getSetting(runtime, "MEGA_MODEL") ?? getLargeModel(runtime);
|
|
83
|
+
}
|
|
84
|
+
function getResponseHandlerModel(runtime) {
|
|
85
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_RESPONSE_HANDLER_MODEL") ?? getSetting(runtime, "ELIZAOS_CLOUD_SHOULD_RESPOND_MODEL") ?? getSetting(runtime, "RESPONSE_HANDLER_MODEL") ?? getSetting(runtime, "SHOULD_RESPOND_MODEL") ?? getSmallModel(runtime);
|
|
86
|
+
}
|
|
87
|
+
function getActionPlannerModel(runtime) {
|
|
88
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_ACTION_PLANNER_MODEL") ?? getSetting(runtime, "ELIZAOS_CLOUD_PLANNER_MODEL") ?? getSetting(runtime, "ACTION_PLANNER_MODEL") ?? getSetting(runtime, "PLANNER_MODEL") ?? getLargeModel(runtime);
|
|
89
|
+
}
|
|
90
|
+
function getResponseModel(runtime) {
|
|
91
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_RESPONSE_MODEL") ?? getSetting(runtime, "RESPONSE_MODEL") ?? getLargeModel(runtime);
|
|
92
|
+
}
|
|
93
|
+
function getImageDescriptionModel(runtime) {
|
|
94
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_IMAGE_DESCRIPTION_MODEL", "gpt-5.4-mini");
|
|
95
|
+
}
|
|
96
|
+
function getImageGenerationModel(runtime) {
|
|
97
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_IMAGE_GENERATION_MODEL", "google/gemini-2.5-flash-image") ?? "google/gemini-2.5-flash-image";
|
|
98
|
+
}
|
|
99
|
+
function getResearchModel(runtime) {
|
|
100
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_RESEARCH_MODEL") ?? getSetting(runtime, "RESEARCH_MODEL", "o3-deep-research");
|
|
101
|
+
}
|
|
102
|
+
function getTTSModel(runtime) {
|
|
103
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_TTS_MODEL", "gpt-5-mini-tts");
|
|
104
|
+
}
|
|
105
|
+
function getTranscriptionModel(runtime) {
|
|
106
|
+
return getSetting(runtime, "ELIZAOS_CLOUD_TRANSCRIPTION_MODEL", "gpt-5-mini-transcribe");
|
|
107
|
+
}
|
|
108
|
+
function getExperimentalTelemetry(runtime) {
|
|
109
|
+
const setting = getSetting(runtime, "ELIZAOS_CLOUD_EXPERIMENTAL_TELEMETRY", "false");
|
|
110
|
+
return String(setting).toLowerCase() === "true";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/utils/sdk-client.ts
|
|
114
|
+
import { CloudApiClient, ElizaCloudClient } from "@elizaos/cloud-sdk";
|
|
115
|
+
function trimTrailingSlash(value) {
|
|
116
|
+
return value.replace(/\/+$/, "");
|
|
117
|
+
}
|
|
118
|
+
function apiBaseToSiteBaseUrl(apiBaseUrl) {
|
|
119
|
+
const trimmed = trimTrailingSlash(apiBaseUrl);
|
|
120
|
+
return trimmed.endsWith("/api/v1") ? trimmed.slice(0, -"/api/v1".length) : trimmed;
|
|
121
|
+
}
|
|
122
|
+
function apiKeyForRuntime(runtime, embedding = false) {
|
|
123
|
+
if (isBrowser())
|
|
124
|
+
return;
|
|
125
|
+
return embedding ? getEmbeddingApiKey(runtime) : getApiKey(runtime);
|
|
126
|
+
}
|
|
127
|
+
function createCloudApiClient(runtime, embedding = false) {
|
|
128
|
+
const baseUrl = embedding ? getEmbeddingBaseURL(runtime) : getBaseURL(runtime);
|
|
129
|
+
return new CloudApiClient(trimTrailingSlash(baseUrl), apiKeyForRuntime(runtime, embedding));
|
|
130
|
+
}
|
|
131
|
+
function createElizaCloudClient(runtime) {
|
|
132
|
+
const apiBaseUrl = trimTrailingSlash(getBaseURL(runtime));
|
|
133
|
+
return new ElizaCloudClient({
|
|
134
|
+
apiBaseUrl,
|
|
135
|
+
baseUrl: apiBaseToSiteBaseUrl(apiBaseUrl),
|
|
136
|
+
apiKey: apiKeyForRuntime(runtime)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/utils/events.ts
|
|
141
|
+
import {
|
|
142
|
+
EventType
|
|
143
|
+
} from "@elizaos/core";
|
|
144
|
+
function emitModelUsageEvent(runtime, type, _prompt, usage) {
|
|
145
|
+
const inputTokens = Number(usage.inputTokens || 0);
|
|
146
|
+
const outputTokens = Number(usage.outputTokens || 0);
|
|
147
|
+
const totalTokens = Number(usage.totalTokens != null ? usage.totalTokens : inputTokens + outputTokens);
|
|
148
|
+
const payload = {
|
|
149
|
+
runtime,
|
|
150
|
+
source: "elizacloud",
|
|
151
|
+
type,
|
|
152
|
+
tokens: {
|
|
153
|
+
prompt: inputTokens,
|
|
154
|
+
completion: outputTokens,
|
|
155
|
+
total: totalTokens
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
runtime.emitEvent(EventType.MODEL_USED, payload);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/providers/openai.ts
|
|
162
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
163
|
+
function createOpenAIClient(runtime) {
|
|
164
|
+
const baseURL = getBaseURL(runtime);
|
|
165
|
+
const apiKey = getApiKey(runtime) ?? (isProxyMode(runtime) ? "eliza-proxy" : undefined);
|
|
166
|
+
return createOpenAI({
|
|
167
|
+
apiKey: apiKey ?? "",
|
|
168
|
+
baseURL
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/utils/responses-output.ts
|
|
173
|
+
function asRecord(value) {
|
|
174
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
function normalizeContentItems(value) {
|
|
180
|
+
if (Array.isArray(value))
|
|
181
|
+
return value;
|
|
182
|
+
if (typeof value === "string")
|
|
183
|
+
return [{ type: "text", text: value }];
|
|
184
|
+
return value && typeof value === "object" ? [value] : [];
|
|
185
|
+
}
|
|
186
|
+
function extractTextFromContentItem(value) {
|
|
187
|
+
if (typeof value === "string") {
|
|
188
|
+
return [value];
|
|
189
|
+
}
|
|
190
|
+
const record = asRecord(value);
|
|
191
|
+
if (!record)
|
|
192
|
+
return [];
|
|
193
|
+
const text = typeof record.text === "string" ? record.text : typeof record.output_text === "string" ? record.output_text : typeof record.content === "string" ? record.content : "";
|
|
194
|
+
const type = typeof record.type === "string" ? record.type : undefined;
|
|
195
|
+
if (text && (!type || type === "output_text" || type === "text")) {
|
|
196
|
+
return [text];
|
|
197
|
+
}
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
function extractTextFromOutputItem(value) {
|
|
201
|
+
const record = asRecord(value);
|
|
202
|
+
if (!record)
|
|
203
|
+
return [];
|
|
204
|
+
const directContent = normalizeContentItems(record.content);
|
|
205
|
+
if (directContent.length > 0) {
|
|
206
|
+
return directContent.flatMap(extractTextFromContentItem);
|
|
207
|
+
}
|
|
208
|
+
const nestedMessage = asRecord(record.message);
|
|
209
|
+
if (nestedMessage) {
|
|
210
|
+
return normalizeContentItems(nestedMessage.content).flatMap(extractTextFromContentItem);
|
|
211
|
+
}
|
|
212
|
+
const type = typeof record.type === "string" ? record.type : undefined;
|
|
213
|
+
const text = typeof record.text === "string" ? record.text : typeof record.output_text === "string" ? record.output_text : "";
|
|
214
|
+
if (text && (type === "output_text" || type === "text")) {
|
|
215
|
+
return [text];
|
|
216
|
+
}
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
function extractTextFromChoice(value) {
|
|
220
|
+
const record = asRecord(value);
|
|
221
|
+
if (!record)
|
|
222
|
+
return [];
|
|
223
|
+
if (typeof record.text === "string" && record.text) {
|
|
224
|
+
return [record.text];
|
|
225
|
+
}
|
|
226
|
+
const message = asRecord(record.message);
|
|
227
|
+
if (!message) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
return normalizeContentItems(message.content).flatMap(extractTextFromContentItem);
|
|
231
|
+
}
|
|
232
|
+
function extractResponsesOutputText(data) {
|
|
233
|
+
const record = asRecord(data);
|
|
234
|
+
if (!record)
|
|
235
|
+
return "";
|
|
236
|
+
if (typeof record.output_text === "string" && record.output_text.trim()) {
|
|
237
|
+
return record.output_text;
|
|
238
|
+
}
|
|
239
|
+
if (Array.isArray(record.output)) {
|
|
240
|
+
const fromOutput = record.output.flatMap(extractTextFromOutputItem).join("");
|
|
241
|
+
if (fromOutput.trim())
|
|
242
|
+
return fromOutput;
|
|
243
|
+
}
|
|
244
|
+
if (Array.isArray(record.choices)) {
|
|
245
|
+
const fromChoices = record.choices.flatMap(extractTextFromChoice).join("");
|
|
246
|
+
if (fromChoices.trim())
|
|
247
|
+
return fromChoices;
|
|
248
|
+
}
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// src/models/text.ts
|
|
253
|
+
import {
|
|
254
|
+
buildCanonicalSystemPrompt,
|
|
255
|
+
logger as logger2,
|
|
256
|
+
ModelType,
|
|
257
|
+
renderChatMessagesForPrompt,
|
|
258
|
+
resolveEffectiveSystemPrompt
|
|
259
|
+
} from "@elizaos/core";
|
|
260
|
+
var TEXT_NANO_MODEL_TYPE = ModelType.TEXT_NANO ?? "TEXT_NANO";
|
|
261
|
+
var TEXT_MEDIUM_MODEL_TYPE = ModelType.TEXT_MEDIUM ?? "TEXT_MEDIUM";
|
|
262
|
+
var TEXT_SMALL_MODEL_TYPE = ModelType.TEXT_SMALL;
|
|
263
|
+
var TEXT_LARGE_MODEL_TYPE = ModelType.TEXT_LARGE;
|
|
264
|
+
var TEXT_MEGA_MODEL_TYPE = ModelType.TEXT_MEGA ?? "TEXT_MEGA";
|
|
265
|
+
var RESPONSE_HANDLER_MODEL_TYPE = ModelType.RESPONSE_HANDLER ?? "RESPONSE_HANDLER";
|
|
266
|
+
var ACTION_PLANNER_MODEL_TYPE = ModelType.ACTION_PLANNER ?? "ACTION_PLANNER";
|
|
267
|
+
var REASONING_MODEL_PATTERNS = [
|
|
268
|
+
"o1",
|
|
269
|
+
"o3",
|
|
270
|
+
"o4",
|
|
271
|
+
"deepseek-r1",
|
|
272
|
+
"deepseek-reasoner",
|
|
273
|
+
"claude-opus-4.7",
|
|
274
|
+
"claude-opus-4-7",
|
|
275
|
+
"gpt-5"
|
|
276
|
+
];
|
|
277
|
+
var RESPONSES_ROUTED_PREFIXES = ["openai/", "anthropic/"];
|
|
278
|
+
function buildUserContent(params) {
|
|
279
|
+
const content = [{ type: "text", text: params.prompt ?? "" }];
|
|
280
|
+
for (const attachment of params.attachments ?? []) {
|
|
281
|
+
content.push({
|
|
282
|
+
type: "file",
|
|
283
|
+
data: attachment.data,
|
|
284
|
+
mediaType: attachment.mediaType,
|
|
285
|
+
...attachment.filename ? { filename: attachment.filename } : {}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return content;
|
|
289
|
+
}
|
|
290
|
+
function isReasoningModel(modelName) {
|
|
291
|
+
const lower = modelName.toLowerCase();
|
|
292
|
+
return REASONING_MODEL_PATTERNS.some((pattern) => lower.includes(pattern));
|
|
293
|
+
}
|
|
294
|
+
function supportsStopSequences(modelName) {
|
|
295
|
+
const lower = modelName.toLowerCase();
|
|
296
|
+
return !RESPONSES_ROUTED_PREFIXES.some((prefix) => lower.startsWith(prefix));
|
|
297
|
+
}
|
|
298
|
+
function isRecord(value) {
|
|
299
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
300
|
+
}
|
|
301
|
+
function asRecord2(value) {
|
|
302
|
+
return isRecord(value) ? value : {};
|
|
303
|
+
}
|
|
304
|
+
function recordAt(value, key) {
|
|
305
|
+
return asRecord2(value[key]);
|
|
306
|
+
}
|
|
307
|
+
function firstString(...values) {
|
|
308
|
+
for (const value of values) {
|
|
309
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
310
|
+
return value.trim();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
function firstNumber(...values) {
|
|
316
|
+
for (const value of values) {
|
|
317
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
320
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
321
|
+
const parsed = Number(value);
|
|
322
|
+
if (Number.isFinite(parsed)) {
|
|
323
|
+
return parsed;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
function parseJsonIfPossible(value) {
|
|
330
|
+
if (typeof value !== "string") {
|
|
331
|
+
return value ?? {};
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
return JSON.parse(value);
|
|
335
|
+
} catch {
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function stringifyMessageContent(content) {
|
|
340
|
+
if (typeof content === "string") {
|
|
341
|
+
return content;
|
|
342
|
+
}
|
|
343
|
+
if (content == null) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
return typeof content === "object" ? JSON.stringify(content) : String(content);
|
|
347
|
+
}
|
|
348
|
+
function hasNativeTransportOptions(params) {
|
|
349
|
+
return Boolean(params.messages || params.tools || params.toolChoice || params.responseSchema || params.providerOptions);
|
|
350
|
+
}
|
|
351
|
+
function shouldReturnNativeResult(params) {
|
|
352
|
+
return Boolean(params.messages || params.tools || params.toolChoice || params.responseSchema);
|
|
353
|
+
}
|
|
354
|
+
function buildNativeMessages(params, promptText, systemPrompt) {
|
|
355
|
+
if (Array.isArray(params.messages) && params.messages.length > 0) {
|
|
356
|
+
const messages2 = params.messages.map((message) => isRecord(message) ? { ...message } : { role: "user", content: stringifyMessageContent(message) });
|
|
357
|
+
const first = asRecord2(messages2[0]);
|
|
358
|
+
if (systemPrompt && first.role !== "system") {
|
|
359
|
+
return [{ role: "system", content: systemPrompt }, ...messages2];
|
|
360
|
+
}
|
|
361
|
+
return messages2;
|
|
362
|
+
}
|
|
363
|
+
const messages = [];
|
|
364
|
+
if (systemPrompt) {
|
|
365
|
+
messages.push({ role: "system", content: systemPrompt });
|
|
366
|
+
}
|
|
367
|
+
messages.push({ role: "user", content: promptText });
|
|
368
|
+
return messages;
|
|
369
|
+
}
|
|
370
|
+
function unwrapJsonSchema(value) {
|
|
371
|
+
const record = asRecord2(value);
|
|
372
|
+
return record.schema ?? record.jsonSchema ?? value;
|
|
373
|
+
}
|
|
374
|
+
function normalizeNativeTools(tools) {
|
|
375
|
+
if (!tools) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (Array.isArray(tools)) {
|
|
379
|
+
return tools;
|
|
380
|
+
}
|
|
381
|
+
const toolSet = asRecord2(tools);
|
|
382
|
+
const normalized = [];
|
|
383
|
+
for (const [name, rawTool] of Object.entries(toolSet)) {
|
|
384
|
+
const tool = asRecord2(rawTool);
|
|
385
|
+
const inputSchema = unwrapJsonSchema(tool.inputSchema ?? tool.parameters ?? tool.schema ?? { type: "object" });
|
|
386
|
+
normalized.push({
|
|
387
|
+
type: "function",
|
|
388
|
+
function: {
|
|
389
|
+
name,
|
|
390
|
+
...typeof tool.description === "string" ? { description: tool.description } : {},
|
|
391
|
+
parameters: inputSchema
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
396
|
+
}
|
|
397
|
+
function normalizeNativeToolChoice(toolChoice) {
|
|
398
|
+
if (!toolChoice) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (typeof toolChoice === "string" && (toolChoice === "auto" || toolChoice === "none" || toolChoice === "required")) {
|
|
402
|
+
return toolChoice;
|
|
403
|
+
}
|
|
404
|
+
const choice = asRecord2(toolChoice);
|
|
405
|
+
if (choice.type === "function") {
|
|
406
|
+
return toolChoice;
|
|
407
|
+
}
|
|
408
|
+
if (choice.type === "tool") {
|
|
409
|
+
const toolName2 = firstString(choice.toolName, choice.name);
|
|
410
|
+
return toolName2 ? { type: "function", function: { name: toolName2 } } : toolChoice;
|
|
411
|
+
}
|
|
412
|
+
const functionChoice = asRecord2(choice.function);
|
|
413
|
+
const toolName = firstString(choice.toolName, choice.name, functionChoice.name);
|
|
414
|
+
return toolName ? { type: "function", function: { name: toolName } } : toolChoice;
|
|
415
|
+
}
|
|
416
|
+
function buildNativeResponseFormat(responseSchema) {
|
|
417
|
+
if (!responseSchema) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const schemaRecord = asRecord2(responseSchema);
|
|
421
|
+
if (schemaRecord.responseFormat) {
|
|
422
|
+
return schemaRecord.responseFormat;
|
|
423
|
+
}
|
|
424
|
+
const schemaOptions = "schema" in schemaRecord ? {
|
|
425
|
+
schema: schemaRecord.schema,
|
|
426
|
+
name: firstString(schemaRecord.name) ?? "structured_response",
|
|
427
|
+
description: firstString(schemaRecord.description)
|
|
428
|
+
} : { schema: responseSchema, name: "structured_response", description: undefined };
|
|
429
|
+
return {
|
|
430
|
+
type: "json_schema",
|
|
431
|
+
json_schema: {
|
|
432
|
+
name: schemaOptions.name,
|
|
433
|
+
...schemaOptions.description ? { description: schemaOptions.description } : {},
|
|
434
|
+
schema: schemaOptions.schema
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function resolvePromptCacheKey(providerOptions) {
|
|
439
|
+
const eliza = recordAt(providerOptions, "eliza");
|
|
440
|
+
const openrouter = recordAt(providerOptions, "openrouter");
|
|
441
|
+
const openai = recordAt(providerOptions, "openai");
|
|
442
|
+
const cerebras = recordAt(providerOptions, "cerebras");
|
|
443
|
+
return firstString(providerOptions.promptCacheKey, providerOptions.prompt_cache_key, eliza.promptCacheKey, eliza.prompt_cache_key, openrouter.promptCacheKey, openrouter.prompt_cache_key, openai.promptCacheKey, openai.prompt_cache_key, cerebras.promptCacheKey, cerebras.prompt_cache_key);
|
|
444
|
+
}
|
|
445
|
+
function resolveNativeProviderOptions(params) {
|
|
446
|
+
const raw = asRecord2(params.providerOptions);
|
|
447
|
+
if (Object.keys(raw).length === 0) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
const { agentName: _agentName, eliza: _eliza, ...rest } = raw;
|
|
451
|
+
const providerOptions = { ...rest };
|
|
452
|
+
const promptCacheKey = resolvePromptCacheKey(raw);
|
|
453
|
+
if (promptCacheKey) {
|
|
454
|
+
providerOptions.openai = {
|
|
455
|
+
...recordAt(providerOptions, "openai"),
|
|
456
|
+
promptCacheKey,
|
|
457
|
+
prompt_cache_key: promptCacheKey
|
|
458
|
+
};
|
|
459
|
+
providerOptions.openrouter = {
|
|
460
|
+
...recordAt(providerOptions, "openrouter"),
|
|
461
|
+
promptCacheKey,
|
|
462
|
+
prompt_cache_key: promptCacheKey
|
|
463
|
+
};
|
|
464
|
+
providerOptions.cerebras = {
|
|
465
|
+
...recordAt(providerOptions, "cerebras"),
|
|
466
|
+
prompt_cache_key: promptCacheKey
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
|
470
|
+
}
|
|
471
|
+
function applyOpenRouterPassthroughFields(requestBody, providerOptions) {
|
|
472
|
+
if (!providerOptions) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const openrouter = recordAt(providerOptions, "openrouter");
|
|
476
|
+
if (Object.keys(openrouter).length > 0) {
|
|
477
|
+
const provider = openrouter.provider;
|
|
478
|
+
if (provider !== undefined) {
|
|
479
|
+
requestBody.provider = provider;
|
|
480
|
+
}
|
|
481
|
+
for (const key of ["models", "route", "transforms", "reasoning"]) {
|
|
482
|
+
if (openrouter[key] !== undefined) {
|
|
483
|
+
requestBody[key] = openrouter[key];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const gateway = providerOptions.gateway;
|
|
488
|
+
if (gateway !== undefined) {
|
|
489
|
+
requestBody.gateway = gateway;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function buildNativeRequestBody(params, modelName, promptText, systemPrompt) {
|
|
493
|
+
const providerOptions = resolveNativeProviderOptions(params);
|
|
494
|
+
const promptCacheKey = providerOptions ? resolvePromptCacheKey(providerOptions) : undefined;
|
|
495
|
+
const tools = normalizeNativeTools(params.tools);
|
|
496
|
+
const toolChoice = normalizeNativeToolChoice(params.toolChoice);
|
|
497
|
+
const responseFormat = buildNativeResponseFormat(params.responseSchema);
|
|
498
|
+
const requestBody = {
|
|
499
|
+
model: modelName,
|
|
500
|
+
messages: buildNativeMessages(params, promptText, systemPrompt),
|
|
501
|
+
max_tokens: params.maxTokens ?? 8192
|
|
502
|
+
};
|
|
503
|
+
if (!isReasoningModel(modelName) && typeof params.temperature === "number") {
|
|
504
|
+
requestBody.temperature = params.temperature;
|
|
505
|
+
}
|
|
506
|
+
if (tools) {
|
|
507
|
+
requestBody.tools = tools;
|
|
508
|
+
}
|
|
509
|
+
if (toolChoice) {
|
|
510
|
+
requestBody.tool_choice = toolChoice;
|
|
511
|
+
}
|
|
512
|
+
if (responseFormat) {
|
|
513
|
+
requestBody.response_format = responseFormat;
|
|
514
|
+
}
|
|
515
|
+
if (providerOptions) {
|
|
516
|
+
requestBody.providerOptions = providerOptions;
|
|
517
|
+
requestBody.provider_options = providerOptions;
|
|
518
|
+
}
|
|
519
|
+
if (promptCacheKey) {
|
|
520
|
+
requestBody.promptCacheKey = promptCacheKey;
|
|
521
|
+
requestBody.prompt_cache_key = promptCacheKey;
|
|
522
|
+
}
|
|
523
|
+
applyOpenRouterPassthroughFields(requestBody, providerOptions);
|
|
524
|
+
return requestBody;
|
|
525
|
+
}
|
|
526
|
+
function extractTextFromContent(content) {
|
|
527
|
+
if (typeof content === "string") {
|
|
528
|
+
return content;
|
|
529
|
+
}
|
|
530
|
+
if (!Array.isArray(content)) {
|
|
531
|
+
return "";
|
|
532
|
+
}
|
|
533
|
+
return content.map((item) => {
|
|
534
|
+
if (typeof item === "string")
|
|
535
|
+
return item;
|
|
536
|
+
const record = asRecord2(item);
|
|
537
|
+
return firstString(record.text, record.output_text, record.content) ?? "";
|
|
538
|
+
}).join("");
|
|
539
|
+
}
|
|
540
|
+
function extractChatCompletionText(data) {
|
|
541
|
+
const firstChoice = data.choices?.[0];
|
|
542
|
+
if (!firstChoice) {
|
|
543
|
+
return "";
|
|
544
|
+
}
|
|
545
|
+
return firstString(firstChoice.text, extractTextFromContent(firstChoice.message?.content)) ?? "";
|
|
546
|
+
}
|
|
547
|
+
function extractNativeToolCalls(data) {
|
|
548
|
+
const rawCalls = data.choices?.[0]?.message?.tool_calls ?? [];
|
|
549
|
+
if (!Array.isArray(rawCalls)) {
|
|
550
|
+
return [];
|
|
551
|
+
}
|
|
552
|
+
return rawCalls.map((rawCall) => {
|
|
553
|
+
const call = asRecord2(rawCall);
|
|
554
|
+
const fn = recordAt(call, "function");
|
|
555
|
+
const toolName = firstString(call.name, call.toolName, fn.name);
|
|
556
|
+
if (!toolName) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
type: "tool-call",
|
|
561
|
+
toolCallId: firstString(call.id, call.toolCallId) ?? `call_${toolName}`,
|
|
562
|
+
toolName,
|
|
563
|
+
input: parseJsonIfPossible(call.input ?? call.arguments ?? fn.arguments ?? {})
|
|
564
|
+
};
|
|
565
|
+
}).filter((call) => call !== undefined);
|
|
566
|
+
}
|
|
567
|
+
function convertNativeUsage(usage) {
|
|
568
|
+
const root = asRecord2(usage);
|
|
569
|
+
if (Object.keys(root).length === 0) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const inputTokenDetails = recordAt(root, "inputTokenDetails");
|
|
573
|
+
const promptTokenDetails = recordAt(root, "prompt_tokens_details");
|
|
574
|
+
const inputTokenDetailsSnake = recordAt(root, "input_tokens_details");
|
|
575
|
+
const promptTokens = firstNumber(root.inputTokens, root.input_tokens, root.promptTokens, root.prompt_tokens) ?? 0;
|
|
576
|
+
const completionTokens = firstNumber(root.outputTokens, root.output_tokens, root.completionTokens, root.completion_tokens) ?? 0;
|
|
577
|
+
const cacheReadInputTokens = firstNumber(root.cacheReadInputTokens, root.cache_read_input_tokens, root.cachedInputTokens, root.cached_input_tokens, root.cachedTokens, root.cached_tokens, inputTokenDetails.cacheReadTokens, inputTokenDetails.cachedInputTokens, inputTokenDetails.cachedTokens, promptTokenDetails.cached_tokens, inputTokenDetailsSnake.cache_read_input_tokens, inputTokenDetailsSnake.cached_tokens);
|
|
578
|
+
const cacheCreationInputTokens = firstNumber(root.cacheCreationInputTokens, root.cache_creation_input_tokens, root.cacheWriteInputTokens, root.cache_write_input_tokens, inputTokenDetails.cacheCreationInputTokens, inputTokenDetails.cacheCreationTokens, inputTokenDetails.cacheWriteTokens, inputTokenDetailsSnake.cache_creation_input_tokens);
|
|
579
|
+
return {
|
|
580
|
+
promptTokens,
|
|
581
|
+
completionTokens,
|
|
582
|
+
totalTokens: firstNumber(root.totalTokens, root.total_tokens) ?? promptTokens + completionTokens,
|
|
583
|
+
cachedPromptTokens: cacheReadInputTokens,
|
|
584
|
+
cacheReadInputTokens,
|
|
585
|
+
cacheCreationInputTokens
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
function getPurposeForModelType(modelType) {
|
|
589
|
+
switch (modelType) {
|
|
590
|
+
case RESPONSE_HANDLER_MODEL_TYPE:
|
|
591
|
+
return "should_respond";
|
|
592
|
+
case ACTION_PLANNER_MODEL_TYPE:
|
|
593
|
+
return "action_planner";
|
|
594
|
+
default:
|
|
595
|
+
return "response";
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function getModelNameForType(runtime, modelType) {
|
|
599
|
+
switch (modelType) {
|
|
600
|
+
case TEXT_NANO_MODEL_TYPE:
|
|
601
|
+
return getNanoModel(runtime);
|
|
602
|
+
case TEXT_MEDIUM_MODEL_TYPE:
|
|
603
|
+
return getMediumModel(runtime);
|
|
604
|
+
case TEXT_SMALL_MODEL_TYPE:
|
|
605
|
+
return getSmallModel(runtime);
|
|
606
|
+
case TEXT_LARGE_MODEL_TYPE:
|
|
607
|
+
return getLargeModel(runtime);
|
|
608
|
+
case TEXT_MEGA_MODEL_TYPE:
|
|
609
|
+
return getMegaModel(runtime);
|
|
610
|
+
case RESPONSE_HANDLER_MODEL_TYPE:
|
|
611
|
+
return getResponseHandlerModel(runtime);
|
|
612
|
+
case ACTION_PLANNER_MODEL_TYPE:
|
|
613
|
+
return getActionPlannerModel(runtime);
|
|
614
|
+
default:
|
|
615
|
+
return getLargeModel(runtime);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function buildGenerateParams(runtime, modelType, params) {
|
|
619
|
+
const paramsWithAttachments = params;
|
|
620
|
+
const prompt = params.prompt ?? "";
|
|
621
|
+
const maxTokens = params.maxTokens ?? 8192;
|
|
622
|
+
const openai = createOpenAIClient(runtime);
|
|
623
|
+
const modelName = getModelNameForType(runtime, modelType);
|
|
624
|
+
const experimentalTelemetry = getExperimentalTelemetry(runtime);
|
|
625
|
+
const userContent = (paramsWithAttachments.attachments?.length ?? 0) > 0 ? buildUserContent(paramsWithAttachments) : undefined;
|
|
626
|
+
const model = openai.chat(modelName);
|
|
627
|
+
const reasoning = isReasoningModel(modelName);
|
|
628
|
+
const stopSequences = !reasoning && supportsStopSequences(modelName) && Array.isArray(params.stopSequences) && params.stopSequences.length > 0 ? params.stopSequences : undefined;
|
|
629
|
+
const systemPrompt = resolveEffectiveSystemPrompt({
|
|
630
|
+
params,
|
|
631
|
+
fallback: buildCanonicalSystemPrompt({ character: runtime.character })
|
|
632
|
+
});
|
|
633
|
+
const promptText = renderChatMessagesForPrompt(params.messages, {
|
|
634
|
+
omitDuplicateSystem: systemPrompt
|
|
635
|
+
}) ?? prompt;
|
|
636
|
+
const generateParams = {
|
|
637
|
+
model,
|
|
638
|
+
...userContent ? { messages: [{ role: "user", content: userContent }] } : { prompt: promptText },
|
|
639
|
+
system: systemPrompt,
|
|
640
|
+
...stopSequences ? { stopSequences } : {},
|
|
641
|
+
maxOutputTokens: maxTokens,
|
|
642
|
+
experimental_telemetry: {
|
|
643
|
+
isEnabled: experimentalTelemetry
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
return { generateParams, modelName, modelType, prompt: promptText, systemPrompt };
|
|
647
|
+
}
|
|
648
|
+
async function generateTextWithModel(runtime, modelType, params) {
|
|
649
|
+
const { modelName, prompt, systemPrompt } = buildGenerateParams(runtime, modelType, params);
|
|
650
|
+
const paramsWithNative = params;
|
|
651
|
+
logger2.debug(`[ELIZAOS_CLOUD] Generating text with ${modelType} model: ${modelName}`);
|
|
652
|
+
if (params.stream) {
|
|
653
|
+
logger2.debug("[ELIZAOS_CLOUD] Streaming text disabled for responses compatibility; falling back to buffered response.");
|
|
654
|
+
}
|
|
655
|
+
logger2.log(`[ELIZAOS_CLOUD] Using ${modelType} model: ${modelName}`);
|
|
656
|
+
logger2.log(prompt);
|
|
657
|
+
if (hasNativeTransportOptions(paramsWithNative)) {
|
|
658
|
+
const nativeResult = await generateNativeChatCompletion(runtime, modelType, paramsWithNative, {
|
|
659
|
+
modelName,
|
|
660
|
+
prompt,
|
|
661
|
+
systemPrompt
|
|
662
|
+
});
|
|
663
|
+
return shouldReturnNativeResult(paramsWithNative) ? nativeResult : nativeResult.text;
|
|
664
|
+
}
|
|
665
|
+
const reasoning = isReasoningModel(modelName);
|
|
666
|
+
const input = [];
|
|
667
|
+
if (systemPrompt) {
|
|
668
|
+
input.push({
|
|
669
|
+
role: "system",
|
|
670
|
+
content: [{ type: "input_text", text: systemPrompt }]
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
input.push({
|
|
674
|
+
role: "user",
|
|
675
|
+
content: [{ type: "input_text", text: prompt }]
|
|
676
|
+
});
|
|
677
|
+
const requestBody = {
|
|
678
|
+
model: modelName,
|
|
679
|
+
input,
|
|
680
|
+
max_output_tokens: params.maxTokens ?? 8192
|
|
681
|
+
};
|
|
682
|
+
if (!reasoning && typeof params.temperature === "number") {
|
|
683
|
+
requestBody.temperature = params.temperature;
|
|
684
|
+
}
|
|
685
|
+
const response = await createCloudApiClient(runtime).requestRaw("POST", "/responses", {
|
|
686
|
+
headers: {
|
|
687
|
+
"X-Eliza-Llm-Purpose": getPurposeForModelType(modelType),
|
|
688
|
+
"X-Eliza-Model-Type": modelType
|
|
689
|
+
},
|
|
690
|
+
json: requestBody
|
|
691
|
+
});
|
|
692
|
+
const responseText = await response.text();
|
|
693
|
+
let data = {};
|
|
694
|
+
if (responseText) {
|
|
695
|
+
try {
|
|
696
|
+
data = JSON.parse(responseText);
|
|
697
|
+
} catch (parseErr) {
|
|
698
|
+
logger2.error(`[ELIZAOS_CLOUD] Failed to parse responses JSON: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (!response.ok) {
|
|
702
|
+
const errorBody = typeof data === "object" && data ? data.error : undefined;
|
|
703
|
+
const errorMessage = typeof errorBody?.message === "string" && errorBody.message.trim() ? errorBody.message.trim() : `elizaOS Cloud error ${response.status}`;
|
|
704
|
+
const requestError = new Error(errorMessage);
|
|
705
|
+
requestError.status = response.status;
|
|
706
|
+
if (errorBody) {
|
|
707
|
+
requestError.error = errorBody;
|
|
708
|
+
}
|
|
709
|
+
throw requestError;
|
|
710
|
+
}
|
|
711
|
+
if (data.usage) {
|
|
712
|
+
emitModelUsageEvent(runtime, modelType, prompt, {
|
|
713
|
+
inputTokens: data.usage.input_tokens ?? 0,
|
|
714
|
+
outputTokens: data.usage.output_tokens ?? 0,
|
|
715
|
+
totalTokens: data.usage.total_tokens ?? 0
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
const text = extractResponsesOutputText(data);
|
|
719
|
+
if (!text.trim()) {
|
|
720
|
+
throw new Error("elizaOS Cloud returned no text response");
|
|
721
|
+
}
|
|
722
|
+
return text;
|
|
723
|
+
}
|
|
724
|
+
async function generateNativeChatCompletion(runtime, modelType, params, context) {
|
|
725
|
+
const requestBody = buildNativeRequestBody(params, context.modelName, context.prompt, context.systemPrompt);
|
|
726
|
+
const response = await createCloudApiClient(runtime).requestRaw("POST", "/chat/completions", {
|
|
727
|
+
headers: {
|
|
728
|
+
"X-Eliza-Llm-Purpose": getPurposeForModelType(modelType),
|
|
729
|
+
"X-Eliza-Model-Type": modelType
|
|
730
|
+
},
|
|
731
|
+
json: requestBody
|
|
732
|
+
});
|
|
733
|
+
const responseText = await response.text();
|
|
734
|
+
let data = {};
|
|
735
|
+
if (responseText) {
|
|
736
|
+
try {
|
|
737
|
+
data = JSON.parse(responseText);
|
|
738
|
+
} catch (parseErr) {
|
|
739
|
+
logger2.error(`[ELIZAOS_CLOUD] Failed to parse chat completions JSON: ${parseErr instanceof Error ? parseErr.message : String(parseErr)}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (!response.ok) {
|
|
743
|
+
const errorBody = typeof data === "object" && data ? data.error : undefined;
|
|
744
|
+
const errorMessage = typeof errorBody?.message === "string" && errorBody.message.trim() ? errorBody.message.trim() : `elizaOS Cloud error ${response.status}`;
|
|
745
|
+
const requestError = new Error(errorMessage);
|
|
746
|
+
requestError.status = response.status;
|
|
747
|
+
if (errorBody) {
|
|
748
|
+
requestError.error = errorBody;
|
|
749
|
+
}
|
|
750
|
+
throw requestError;
|
|
751
|
+
}
|
|
752
|
+
const usage = convertNativeUsage(data.usage);
|
|
753
|
+
if (usage) {
|
|
754
|
+
emitModelUsageEvent(runtime, modelType, context.prompt, usage);
|
|
755
|
+
}
|
|
756
|
+
const text = extractChatCompletionText(data);
|
|
757
|
+
const toolCalls = extractNativeToolCalls(data);
|
|
758
|
+
if (!text.trim() && toolCalls.length === 0) {
|
|
759
|
+
throw new Error("elizaOS Cloud returned no text or tool calls");
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
text,
|
|
763
|
+
toolCalls,
|
|
764
|
+
finishReason: data.choices?.[0]?.finish_reason,
|
|
765
|
+
usage,
|
|
766
|
+
providerMetadata: {
|
|
767
|
+
modelName: context.modelName,
|
|
768
|
+
usage: data.usage
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
async function handleTextSmall(runtime, params) {
|
|
773
|
+
return generateTextWithModel(runtime, TEXT_SMALL_MODEL_TYPE, params);
|
|
774
|
+
}
|
|
775
|
+
async function handleTextNano(runtime, params) {
|
|
776
|
+
return generateTextWithModel(runtime, TEXT_NANO_MODEL_TYPE, params);
|
|
777
|
+
}
|
|
778
|
+
async function handleTextMedium(runtime, params) {
|
|
779
|
+
return generateTextWithModel(runtime, TEXT_MEDIUM_MODEL_TYPE, params);
|
|
780
|
+
}
|
|
781
|
+
async function handleTextLarge(runtime, params) {
|
|
782
|
+
return generateTextWithModel(runtime, TEXT_LARGE_MODEL_TYPE, params);
|
|
783
|
+
}
|
|
784
|
+
async function handleTextMega(runtime, params) {
|
|
785
|
+
return generateTextWithModel(runtime, TEXT_MEGA_MODEL_TYPE, params);
|
|
786
|
+
}
|
|
787
|
+
async function handleResponseHandler(runtime, params) {
|
|
788
|
+
return generateTextWithModel(runtime, RESPONSE_HANDLER_MODEL_TYPE, params);
|
|
789
|
+
}
|
|
790
|
+
async function handleActionPlanner(runtime, params) {
|
|
791
|
+
return generateTextWithModel(runtime, ACTION_PLANNER_MODEL_TYPE, params);
|
|
792
|
+
}
|
|
793
|
+
export {
|
|
794
|
+
handleTextSmall,
|
|
795
|
+
handleTextNano,
|
|
796
|
+
handleTextMega,
|
|
797
|
+
handleTextMedium,
|
|
798
|
+
handleTextLarge,
|
|
799
|
+
handleResponseHandler,
|
|
800
|
+
handleActionPlanner
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
//# debugId=DF0E0E9E46BB9DE664756E2164756E21
|