@use-lattice/litmus 0.121.3

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 (199) hide show
  1. package/LICENSE +19 -0
  2. package/dist/src/accounts-Bt1oJb1Z.cjs +219 -0
  3. package/dist/src/accounts-DjOU8Rm3.js +178 -0
  4. package/dist/src/agentic-utils-D03IiXQc.js +153 -0
  5. package/dist/src/agentic-utils-Dh7xaMQM.cjs +180 -0
  6. package/dist/src/agents-C6BIMlZa.js +231 -0
  7. package/dist/src/agents-DvIpNX1L.cjs +666 -0
  8. package/dist/src/agents-ZP0RP9vV.cjs +231 -0
  9. package/dist/src/agents-maJXdjbR.js +665 -0
  10. package/dist/src/aimlapi-BTbQjG2E.cjs +30 -0
  11. package/dist/src/aimlapi-CwMxqfXP.js +30 -0
  12. package/dist/src/audio-BBUdvsde.cjs +97 -0
  13. package/dist/src/audio-D5DPZ7I-.js +97 -0
  14. package/dist/src/base-BEysXrkq.cjs +222 -0
  15. package/dist/src/base-C451JQfq.js +193 -0
  16. package/dist/src/blobs-BY8MDmpo.js +230 -0
  17. package/dist/src/blobs-BgcNn97m.cjs +256 -0
  18. package/dist/src/cache-BBE_lsTA.cjs +4 -0
  19. package/dist/src/cache-BkrqU5Ba.js +237 -0
  20. package/dist/src/cache-DsCxFlsZ.cjs +297 -0
  21. package/dist/src/chat-CPJWDP6a.cjs +289 -0
  22. package/dist/src/chat-CXX3xzkk.cjs +811 -0
  23. package/dist/src/chat-CcDgZFJ4.js +787 -0
  24. package/dist/src/chat-Dz5ZeGO2.js +289 -0
  25. package/dist/src/chatkit-Dw0mKkML.cjs +1158 -0
  26. package/dist/src/chatkit-swAIVuea.js +1157 -0
  27. package/dist/src/chunk-DEq-mXcV.js +15 -0
  28. package/dist/src/claude-agent-sdk-BXZJtOg6.js +379 -0
  29. package/dist/src/claude-agent-sdk-CkfyjDoG.cjs +383 -0
  30. package/dist/src/cloudflare-ai-BzpJcqUH.js +161 -0
  31. package/dist/src/cloudflare-ai-Cmy_R1y2.cjs +161 -0
  32. package/dist/src/cloudflare-gateway-B9tVQKok.cjs +272 -0
  33. package/dist/src/cloudflare-gateway-DrD3ew3H.js +272 -0
  34. package/dist/src/codex-sdk-Dezj9Nwm.js +1056 -0
  35. package/dist/src/codex-sdk-Dl9D4k5B.cjs +1060 -0
  36. package/dist/src/cometapi-C-9YvCHC.js +54 -0
  37. package/dist/src/cometapi-DHgDKoO2.cjs +54 -0
  38. package/dist/src/completion-B8Ctyxpr.js +120 -0
  39. package/dist/src/completion-Cxrt08sj.cjs +131 -0
  40. package/dist/src/createHash-BwgE13yv.cjs +27 -0
  41. package/dist/src/createHash-DmPQkvBh.js +15 -0
  42. package/dist/src/docker-BiqcTwLv.js +80 -0
  43. package/dist/src/docker-C7tEJnP-.cjs +80 -0
  44. package/dist/src/esm-C62Zofr1.cjs +409 -0
  45. package/dist/src/esm-DMVc93eh.js +379 -0
  46. package/dist/src/evalResult-C3NJPQOo.cjs +301 -0
  47. package/dist/src/evalResult-C7JJAPBb.js +295 -0
  48. package/dist/src/evalResult-DoVTZZWI.cjs +2 -0
  49. package/dist/src/extractor-DnMD3fwt.cjs +391 -0
  50. package/dist/src/extractor-DtlL28vL.js +374 -0
  51. package/dist/src/fetch-BTxakTSg.cjs +1133 -0
  52. package/dist/src/fetch-DQckpUFz.js +928 -0
  53. package/dist/src/fileExtensions-DnqA1y9x.js +85 -0
  54. package/dist/src/fileExtensions-bYh77CN8.cjs +114 -0
  55. package/dist/src/genaiTracer-CyZrmaK0.cjs +268 -0
  56. package/dist/src/genaiTracer-D3fD9dNV.js +256 -0
  57. package/dist/src/graders-BNscxFrU.js +13644 -0
  58. package/dist/src/graders-D2oE9Msq.js +2 -0
  59. package/dist/src/graders-c0Ez_w-9.cjs +2 -0
  60. package/dist/src/graders-d0F2M3e9.cjs +14056 -0
  61. package/dist/src/image-0ZhE0VlR.cjs +280 -0
  62. package/dist/src/image-CWE1pdNv.js +257 -0
  63. package/dist/src/image-D9ZK6hwL.js +163 -0
  64. package/dist/src/image-DKZgZITg.cjs +163 -0
  65. package/dist/src/index.cjs +11366 -0
  66. package/dist/src/index.d.cts +19640 -0
  67. package/dist/src/index.d.ts +19641 -0
  68. package/dist/src/index.js +11306 -0
  69. package/dist/src/invariant-Ddh24eXh.js +25 -0
  70. package/dist/src/invariant-kfQ8Bu82.cjs +30 -0
  71. package/dist/src/knowledgeBase-BgPyGFUd.cjs +122 -0
  72. package/dist/src/knowledgeBase-DyHilYaP.js +122 -0
  73. package/dist/src/litellm-CyMeneHS.js +135 -0
  74. package/dist/src/litellm-DWDF73yF.cjs +135 -0
  75. package/dist/src/logger-C40ZGil9.js +717 -0
  76. package/dist/src/logger-DyfK9PBt.cjs +917 -0
  77. package/dist/src/luma-ray-BAU9X_ep.cjs +315 -0
  78. package/dist/src/luma-ray-nwVseBbv.js +313 -0
  79. package/dist/src/messages-B5ADWTTv.js +245 -0
  80. package/dist/src/messages-BCnZfqrS.cjs +257 -0
  81. package/dist/src/meteor-DLZZ3osF.cjs +134 -0
  82. package/dist/src/meteor-DUiCJRC-.js +134 -0
  83. package/dist/src/modelslab-00cveB8L.cjs +163 -0
  84. package/dist/src/modelslab-D9sCU_L7.js +163 -0
  85. package/dist/src/nova-reel-CTapvqYH.js +276 -0
  86. package/dist/src/nova-reel-DlWuuroF.cjs +278 -0
  87. package/dist/src/nova-sonic-5UPWfeMv.cjs +363 -0
  88. package/dist/src/nova-sonic-BhSwQNym.js +363 -0
  89. package/dist/src/openai-BWrJK9d8.cjs +52 -0
  90. package/dist/src/openai-DumO8WQn.js +47 -0
  91. package/dist/src/openclaw-B8brrjC_.cjs +577 -0
  92. package/dist/src/openclaw-Bkayww9q.js +571 -0
  93. package/dist/src/opencode-sdk-7xjoDNiM.cjs +562 -0
  94. package/dist/src/opencode-sdk-SGwAPxht.js +558 -0
  95. package/dist/src/otlpReceiver-CoAHfAN9.cjs +15 -0
  96. package/dist/src/otlpReceiver-oO3EQwI9.js +14 -0
  97. package/dist/src/providerRegistry-4yjhaEM8.js +45 -0
  98. package/dist/src/providerRegistry-DhV4rJIc.cjs +50 -0
  99. package/dist/src/providers-B5RJVG-7.cjs +33609 -0
  100. package/dist/src/providers-BdmZCLzV.js +33262 -0
  101. package/dist/src/providers-CxtRxn8e.js +2 -0
  102. package/dist/src/providers-DnQLNbx1.cjs +3 -0
  103. package/dist/src/pythonUtils-BD0druiM.cjs +275 -0
  104. package/dist/src/pythonUtils-IBhn5YGR.js +249 -0
  105. package/dist/src/quiverai-BDOwZBsM.cjs +213 -0
  106. package/dist/src/quiverai-D3JTF5lD.js +213 -0
  107. package/dist/src/responses-B2LCDCXZ.js +667 -0
  108. package/dist/src/responses-BvNm4Xv9.cjs +685 -0
  109. package/dist/src/rubyUtils-B0NwnfpY.cjs +245 -0
  110. package/dist/src/rubyUtils-BroxzZ7c.cjs +2 -0
  111. package/dist/src/rubyUtils-hqVw5UvJ.js +222 -0
  112. package/dist/src/sagemaker-Cno2V-Sx.js +689 -0
  113. package/dist/src/sagemaker-fV_KUgs5.cjs +691 -0
  114. package/dist/src/server-BOuAXb06.cjs +238 -0
  115. package/dist/src/server-CtI-EWzm.cjs +2 -0
  116. package/dist/src/server-Cy3DZymt.js +189 -0
  117. package/dist/src/slack-CP8xBePa.js +135 -0
  118. package/dist/src/slack-DSQ1yXVb.cjs +135 -0
  119. package/dist/src/store-BwDDaBjb.cjs +246 -0
  120. package/dist/src/store-DcbLC593.cjs +2 -0
  121. package/dist/src/store-IGpqMIkv.js +240 -0
  122. package/dist/src/tables-3Q2cL7So.cjs +373 -0
  123. package/dist/src/tables-Bi2fjr4W.js +288 -0
  124. package/dist/src/telemetry-Bg2WqF79.js +161 -0
  125. package/dist/src/telemetry-D0x6u5kX.cjs +166 -0
  126. package/dist/src/telemetry-DXNimrI0.cjs +2 -0
  127. package/dist/src/text-B_UCRPp2.js +22 -0
  128. package/dist/src/text-CW1cyrwj.cjs +33 -0
  129. package/dist/src/tokenUsageUtils-NYT-WKS6.js +138 -0
  130. package/dist/src/tokenUsageUtils-bVa1ga6f.cjs +173 -0
  131. package/dist/src/transcription-Cl_W16Pr.js +122 -0
  132. package/dist/src/transcription-yt1EecY8.cjs +124 -0
  133. package/dist/src/transform-BCtGrl_W.cjs +228 -0
  134. package/dist/src/transform-Bv6gG2MJ.cjs +1688 -0
  135. package/dist/src/transform-CY1wbpRy.js +1507 -0
  136. package/dist/src/transform-DU8rUL9P.cjs +2 -0
  137. package/dist/src/transform-yWaShiKr.js +216 -0
  138. package/dist/src/transformersAvailability-BGkzavwb.js +35 -0
  139. package/dist/src/transformersAvailability-DKoRtQLy.cjs +35 -0
  140. package/dist/src/types-5aqHpBwE.cjs +3769 -0
  141. package/dist/src/types-Bn6D9c4U.js +3300 -0
  142. package/dist/src/util-BkKlTkI2.js +293 -0
  143. package/dist/src/util-CTh0bfOm.cjs +1119 -0
  144. package/dist/src/util-D17oBwo7.cjs +328 -0
  145. package/dist/src/util-DsS_-v4p.js +613 -0
  146. package/dist/src/util-DuntT1Ga.js +951 -0
  147. package/dist/src/util-aWjdCYMI.cjs +667 -0
  148. package/dist/src/utils-CisQwpjA.js +94 -0
  149. package/dist/src/utils-yWamDvmz.cjs +123 -0
  150. package/dist/tsconfig.tsbuildinfo +1 -0
  151. package/drizzle/0000_lush_hellion.sql +36 -0
  152. package/drizzle/0001_wide_calypso.sql +3 -0
  153. package/drizzle/0002_tidy_juggernaut.sql +1 -0
  154. package/drizzle/0003_lively_naoko.sql +8 -0
  155. package/drizzle/0004_minor_peter_quill.sql +19 -0
  156. package/drizzle/0005_silky_millenium_guard.sql +2 -0
  157. package/drizzle/0006_harsh_caretaker.sql +42 -0
  158. package/drizzle/0007_cloudy_wong.sql +1 -0
  159. package/drizzle/0008_broad_boomer.sql +2 -0
  160. package/drizzle/0009_strong_marten_broadcloak.sql +19 -0
  161. package/drizzle/0010_needy_bishop.sql +11 -0
  162. package/drizzle/0011_moaning_millenium_guard.sql +1 -0
  163. package/drizzle/0012_late_marten_broadcloak.sql +2 -0
  164. package/drizzle/0013_previous_dormammu.sql +9 -0
  165. package/drizzle/0014_lazy_captain_universe.sql +2 -0
  166. package/drizzle/0015_zippy_wallop.sql +29 -0
  167. package/drizzle/0016_jazzy_zemo.sql +2 -0
  168. package/drizzle/0017_reflective_praxagora.sql +4 -0
  169. package/drizzle/0018_fat_vanisher.sql +22 -0
  170. package/drizzle/0019_new_clint_barton.sql +8 -0
  171. package/drizzle/0020_skinny_maverick.sql +1 -0
  172. package/drizzle/0021_mysterious_madelyne_pryor.sql +13 -0
  173. package/drizzle/0022_sleepy_ultimo.sql +25 -0
  174. package/drizzle/0023_wooden_mandrill.sql +2 -0
  175. package/drizzle/AGENTS.md +68 -0
  176. package/drizzle/CLAUDE.md +1 -0
  177. package/drizzle/meta/0000_snapshot.json +221 -0
  178. package/drizzle/meta/0001_snapshot.json +214 -0
  179. package/drizzle/meta/0002_snapshot.json +221 -0
  180. package/drizzle/meta/0005_snapshot.json +369 -0
  181. package/drizzle/meta/0006_snapshot.json +638 -0
  182. package/drizzle/meta/0007_snapshot.json +640 -0
  183. package/drizzle/meta/0008_snapshot.json +649 -0
  184. package/drizzle/meta/0009_snapshot.json +554 -0
  185. package/drizzle/meta/0010_snapshot.json +619 -0
  186. package/drizzle/meta/0011_snapshot.json +627 -0
  187. package/drizzle/meta/0012_snapshot.json +639 -0
  188. package/drizzle/meta/0013_snapshot.json +717 -0
  189. package/drizzle/meta/0014_snapshot.json +717 -0
  190. package/drizzle/meta/0015_snapshot.json +897 -0
  191. package/drizzle/meta/0016_snapshot.json +1031 -0
  192. package/drizzle/meta/0018_snapshot.json +1210 -0
  193. package/drizzle/meta/0019_snapshot.json +1165 -0
  194. package/drizzle/meta/0020_snapshot.json +1232 -0
  195. package/drizzle/meta/0021_snapshot.json +1311 -0
  196. package/drizzle/meta/0022_snapshot.json +1481 -0
  197. package/drizzle/meta/0023_snapshot.json +1496 -0
  198. package/drizzle/meta/_journal.json +174 -0
  199. package/package.json +240 -0
@@ -0,0 +1,571 @@
1
+ import { r as logger, x as getEnvString } from "./logger-C40ZGil9.js";
2
+ import { M as VERSION, h as REQUEST_TIMEOUT_MS, t as fetchWithProxy } from "./fetch-DQckpUFz.js";
3
+ import { t as OpenAiChatCompletionProvider } from "./chat-CcDgZFJ4.js";
4
+ import { t as OpenAiResponsesProvider } from "./responses-B2LCDCXZ.js";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import os from "os";
8
+ import crypto from "crypto";
9
+ import WebSocket from "ws";
10
+ import JSON5 from "json5";
11
+ //#region src/providers/openclaw/shared.ts
12
+ const DEFAULT_GATEWAY_PORT = 18789;
13
+ const DEFAULT_GATEWAY_HOST = "127.0.0.1";
14
+ /**
15
+ * Cached config to avoid re-reading the file multiple times during provider init.
16
+ */
17
+ let cachedConfig;
18
+ let cachedConfigPath;
19
+ function resolveConfigPath(env) {
20
+ return env?.OPENCLAW_CONFIG_PATH || getEnvString("OPENCLAW_CONFIG_PATH") || path.join(os.homedir(), ".openclaw", "openclaw.json");
21
+ }
22
+ function normalizeGatewayUrl(url, transport) {
23
+ const trimmed = url.trim();
24
+ if (!trimmed) return;
25
+ if (transport === "http") {
26
+ if (trimmed.startsWith("wss://")) return `https://${trimmed.slice(6)}`;
27
+ if (trimmed.startsWith("ws://")) return `http://${trimmed.slice(5)}`;
28
+ return trimmed;
29
+ }
30
+ if (trimmed.startsWith("https://")) return `wss://${trimmed.slice(8)}`;
31
+ if (trimmed.startsWith("http://")) return `ws://${trimmed.slice(7)}`;
32
+ return trimmed;
33
+ }
34
+ function resolveGatewayHost(gatewayConfig) {
35
+ const bind = gatewayConfig?.bind?.trim();
36
+ const customBindHost = gatewayConfig?.customBindHost?.trim();
37
+ if (!bind || bind === "auto" || bind === "loopback" || bind === "lan" || bind === "tailnet" || bind === "0.0.0.0" || bind === "::" || bind === "127.0.0.1" || bind === "localhost" || bind === "::1") return DEFAULT_GATEWAY_HOST;
38
+ if (bind === "custom") {
39
+ if (!customBindHost || customBindHost === "0.0.0.0" || customBindHost === "::" || customBindHost === "127.0.0.1" || customBindHost === "localhost" || customBindHost === "::1") return DEFAULT_GATEWAY_HOST;
40
+ return customBindHost;
41
+ }
42
+ return bind;
43
+ }
44
+ function buildLocalGatewayUrl(gatewayConfig, transport) {
45
+ const scheme = transport === "ws" ? gatewayConfig?.tls?.enabled ? "wss" : "ws" : gatewayConfig?.tls?.enabled ? "https" : "http";
46
+ const port = gatewayConfig?.port ?? 18789;
47
+ return `${scheme}://${resolveGatewayHost(gatewayConfig)}:${port}`;
48
+ }
49
+ function resolveGatewayUrlFromConfig(openclawConfig, transport) {
50
+ const gatewayConfig = openclawConfig?.gateway;
51
+ if (!gatewayConfig) return;
52
+ if (gatewayConfig.mode === "remote") {
53
+ const remoteUrl = normalizeGatewayUrl(gatewayConfig.remote?.url ?? "", transport);
54
+ if (remoteUrl) return remoteUrl;
55
+ }
56
+ return buildLocalGatewayUrl(gatewayConfig, transport);
57
+ }
58
+ function toAuthSecret(kind, value) {
59
+ const trimmed = value?.trim();
60
+ return trimmed ? {
61
+ kind,
62
+ value: trimmed
63
+ } : void 0;
64
+ }
65
+ function resolveAuthSecretFromConfig(openclawConfig) {
66
+ const gatewayConfig = openclawConfig?.gateway;
67
+ const authMode = gatewayConfig?.auth?.mode?.trim();
68
+ const preferRemoteCredentials = gatewayConfig?.mode === "remote";
69
+ const localToken = toAuthSecret("token", gatewayConfig?.auth?.token);
70
+ const localPassword = toAuthSecret("password", gatewayConfig?.auth?.password);
71
+ const remoteToken = toAuthSecret("token", gatewayConfig?.remote?.token);
72
+ const remotePassword = toAuthSecret("password", gatewayConfig?.remote?.password);
73
+ if (preferRemoteCredentials) {
74
+ if (authMode === "password") return remotePassword || localPassword || remoteToken || localToken;
75
+ if (authMode === "token") return remoteToken || localToken || remotePassword || localPassword;
76
+ return remoteToken || remotePassword || localToken || localPassword;
77
+ }
78
+ if (authMode === "password") return localPassword || remotePassword || localToken || remoteToken;
79
+ if (authMode === "token") return localToken || remoteToken || localPassword || remotePassword;
80
+ return localToken || localPassword || remoteToken || remotePassword;
81
+ }
82
+ /**
83
+ * Read and parse the active OpenClaw configuration file.
84
+ * Results are cached based on file modification time.
85
+ * Returns undefined if the file doesn't exist or can't be parsed.
86
+ */
87
+ function readOpenClawConfig(env) {
88
+ const configPath = resolveConfigPath(env);
89
+ try {
90
+ if (!fs.existsSync(configPath)) return;
91
+ const mtime = fs.statSync(configPath).mtimeMs;
92
+ if (cachedConfig && cachedConfigPath === configPath && cachedConfig.mtime === mtime) return cachedConfig.config;
93
+ const raw = fs.readFileSync(configPath, "utf-8");
94
+ const config = JSON5.parse(raw);
95
+ cachedConfig = {
96
+ config,
97
+ mtime
98
+ };
99
+ cachedConfigPath = configPath;
100
+ return config;
101
+ } catch (err) {
102
+ logger.debug(`Failed to read OpenClaw config at ${configPath}: ${err}`);
103
+ return;
104
+ }
105
+ }
106
+ /**
107
+ * Auto-detect the OpenClaw gateway URL from config, env overrides, or the active config file.
108
+ */
109
+ function resolveGatewayUrl(config, env) {
110
+ return resolveGatewayTransportUrl(config, env, "http");
111
+ }
112
+ function resolveGatewayWsUrl(config, env) {
113
+ return resolveGatewayTransportUrl(config, env, "ws");
114
+ }
115
+ function resolveGatewayTransportUrl(config, env, transport) {
116
+ const configUrl = config?.gateway_url?.trim();
117
+ if (configUrl) return normalizeGatewayUrl(configUrl, transport) || configUrl;
118
+ const trimmedEnvUrl = (env?.OPENCLAW_GATEWAY_URL || getEnvString("OPENCLAW_GATEWAY_URL") || env?.CLAWDBOT_GATEWAY_URL || getEnvString("CLAWDBOT_GATEWAY_URL"))?.trim();
119
+ if (trimmedEnvUrl) return normalizeGatewayUrl(trimmedEnvUrl, transport) || trimmedEnvUrl;
120
+ const resolvedUrl = resolveGatewayUrlFromConfig(readOpenClawConfig(env), transport);
121
+ if (resolvedUrl) return resolvedUrl;
122
+ return `${transport === "ws" ? "ws" : "http"}://${DEFAULT_GATEWAY_HOST}:${DEFAULT_GATEWAY_PORT}`;
123
+ }
124
+ function resolveAuthSecret(config, env) {
125
+ if (config?.auth_token) return {
126
+ kind: "token",
127
+ value: config.auth_token
128
+ };
129
+ if (config?.auth_password) return {
130
+ kind: "password",
131
+ value: config.auth_password
132
+ };
133
+ const envToken = env?.OPENCLAW_GATEWAY_TOKEN || getEnvString("OPENCLAW_GATEWAY_TOKEN") || env?.CLAWDBOT_GATEWAY_TOKEN || getEnvString("CLAWDBOT_GATEWAY_TOKEN");
134
+ if (envToken) return {
135
+ kind: "token",
136
+ value: envToken
137
+ };
138
+ const envPassword = env?.OPENCLAW_GATEWAY_PASSWORD || getEnvString("OPENCLAW_GATEWAY_PASSWORD") || env?.CLAWDBOT_GATEWAY_PASSWORD || getEnvString("CLAWDBOT_GATEWAY_PASSWORD");
139
+ if (envPassword) return {
140
+ kind: "password",
141
+ value: envPassword
142
+ };
143
+ return resolveAuthSecretFromConfig(readOpenClawConfig(env));
144
+ }
145
+ /**
146
+ * Auto-detect the OpenClaw gateway bearer secret from config, env overrides, or the active
147
+ * config file. OpenClaw accepts either a token or password as the HTTP bearer secret.
148
+ */
149
+ function resolveAuthToken(config, env) {
150
+ return resolveAuthSecret(config, env)?.value;
151
+ }
152
+ /**
153
+ * Build common OpenClaw headers for agent-id and session-key.
154
+ * Note: thinking_level is only supported by the WS Agent provider and is
155
+ * passed as an RPC param there, not as an HTTP header.
156
+ */
157
+ function buildOpenClawHeaders(agentId, config) {
158
+ const headers = { "x-openclaw-agent-id": agentId };
159
+ if (config?.session_key) headers["x-openclaw-session-key"] = config.session_key;
160
+ return headers;
161
+ }
162
+ /**
163
+ * Build provider options for OpenAI-compatible OpenClaw providers (chat, responses).
164
+ * Resolves gateway URL, auth token, and merges OpenClaw-specific headers.
165
+ */
166
+ function buildOpenClawProviderOptions(agentId, providerOptions) {
167
+ const config = providerOptions.config || {};
168
+ const env = providerOptions.env;
169
+ const gatewayUrl = resolveGatewayUrl(config, env);
170
+ const authToken = resolveAuthToken(config, env);
171
+ return {
172
+ ...providerOptions,
173
+ config: {
174
+ ...config,
175
+ apiBaseUrl: `${gatewayUrl}/v1`,
176
+ ...authToken && { apiKey: authToken },
177
+ apiKeyRequired: false,
178
+ headers: {
179
+ ...config.headers,
180
+ ...buildOpenClawHeaders(agentId, config)
181
+ }
182
+ }
183
+ };
184
+ }
185
+ //#endregion
186
+ //#region src/providers/openclaw/agent.ts
187
+ const OPENCLAW_PROTOCOL_VERSION = 3;
188
+ /**
189
+ * OpenClaw WebSocket Agent Provider
190
+ *
191
+ * Custom provider that uses the native OpenClaw WS RPC protocol to invoke agents.
192
+ * Supports full streaming with event accumulation.
193
+ *
194
+ * Protocol flow:
195
+ * 1. Open WS connection to gateway
196
+ * 2. Receive connect.challenge event → send connect request
197
+ * 3. Receive hello-ok response → send agent request
198
+ * 4. Receive agent accepted response → send agent.wait
199
+ * 5. Accumulate streaming "agent" events (stream: "assistant")
200
+ * 6. Resolve on agent.wait response
201
+ *
202
+ * Usage:
203
+ * openclaw:agent - default agent (main)
204
+ * openclaw:agent:main - explicit agent ID
205
+ * openclaw:agent:my-agent - custom agent ID
206
+ */
207
+ var OpenClawAgentProvider = class {
208
+ agentId;
209
+ gatewayUrl;
210
+ authKind;
211
+ authSecret;
212
+ openclawConfig;
213
+ timeoutMs;
214
+ activeConnections = /* @__PURE__ */ new Set();
215
+ constructor(agentId, providerOptions = {}) {
216
+ this.agentId = agentId;
217
+ this.openclawConfig = providerOptions.config || {};
218
+ const env = providerOptions.env;
219
+ this.gatewayUrl = resolveGatewayWsUrl(this.openclawConfig, env);
220
+ const authSecret = resolveAuthSecret(this.openclawConfig, env);
221
+ this.authKind = authSecret?.kind;
222
+ this.authSecret = authSecret?.value;
223
+ this.timeoutMs = this.openclawConfig.timeoutMs ?? REQUEST_TIMEOUT_MS;
224
+ }
225
+ id() {
226
+ return `openclaw:agent:${this.agentId}`;
227
+ }
228
+ toString() {
229
+ return `[OpenClaw Agent Provider ${this.agentId}]`;
230
+ }
231
+ toJSON() {
232
+ return { provider: this.id() };
233
+ }
234
+ async cleanup() {
235
+ for (const ws of this.activeConnections) ws.close();
236
+ this.activeConnections.clear();
237
+ }
238
+ async callApi(prompt) {
239
+ const sessionKey = this.openclawConfig.session_key || `promptfoo-${crypto.randomUUID()}`;
240
+ return new Promise((resolve) => {
241
+ const ws = new WebSocket(this.gatewayUrl);
242
+ this.activeConnections.add(ws);
243
+ const agentRequestId = crypto.randomUUID();
244
+ const waitRequestId = crypto.randomUUID();
245
+ const idempotencyKey = crypto.randomUUID();
246
+ let lastText = "";
247
+ let runId;
248
+ let connected = false;
249
+ let resolved = false;
250
+ const finish = (result, closeSocket = true) => {
251
+ if (resolved) return;
252
+ resolved = true;
253
+ clearTimeout(timeout);
254
+ this.activeConnections.delete(ws);
255
+ if (closeSocket) ws.close();
256
+ resolve(result);
257
+ };
258
+ const timeout = setTimeout(() => {
259
+ finish({ error: `OpenClaw agent request timed out after ${this.timeoutMs}ms` });
260
+ }, this.timeoutMs);
261
+ ws.on("error", (err) => {
262
+ finish({ error: `OpenClaw WebSocket error: ${err.message}` });
263
+ });
264
+ ws.on("close", () => {
265
+ this.activeConnections.delete(ws);
266
+ if (!resolved) finish({ error: "OpenClaw WebSocket connection closed unexpectedly" }, false);
267
+ });
268
+ ws.on("message", (data) => {
269
+ let frame;
270
+ try {
271
+ frame = JSON.parse(data.toString());
272
+ } catch {
273
+ logger.debug("[OpenClaw Agent] Failed to parse WS frame");
274
+ return;
275
+ }
276
+ logger.debug("[OpenClaw Agent] Frame received", {
277
+ type: frame.type,
278
+ event: frame.event,
279
+ id: frame.id
280
+ });
281
+ if (frame.type === "event" && frame.event === "connect.challenge") {
282
+ ws.send(JSON.stringify({
283
+ type: "req",
284
+ id: crypto.randomUUID(),
285
+ method: "connect",
286
+ params: {
287
+ minProtocol: OPENCLAW_PROTOCOL_VERSION,
288
+ maxProtocol: OPENCLAW_PROTOCOL_VERSION,
289
+ client: {
290
+ id: "gateway-client",
291
+ displayName: "promptfoo",
292
+ version: VERSION,
293
+ platform: process.platform,
294
+ mode: "cli"
295
+ },
296
+ role: "operator",
297
+ scopes: ["operator.read", "operator.write"],
298
+ caps: [],
299
+ commands: [],
300
+ permissions: {},
301
+ ...this.authSecret && this.authKind && { auth: this.authKind === "password" ? { password: this.authSecret } : { token: this.authSecret } }
302
+ }
303
+ }));
304
+ return;
305
+ }
306
+ if (frame.type === "res" && !connected) {
307
+ if (!frame.ok) {
308
+ finish({ error: `OpenClaw connect failed: ${frame.error?.message || "unknown error"}` });
309
+ return;
310
+ }
311
+ connected = true;
312
+ ws.send(JSON.stringify({
313
+ type: "req",
314
+ id: agentRequestId,
315
+ method: "agent",
316
+ params: {
317
+ message: prompt,
318
+ agentId: this.agentId,
319
+ idempotencyKey,
320
+ sessionKey,
321
+ ...this.openclawConfig.thinking_level && { thinking: this.openclawConfig.thinking_level },
322
+ ...this.openclawConfig.extra_system_prompt && { extraSystemPrompt: this.openclawConfig.extra_system_prompt }
323
+ }
324
+ }));
325
+ return;
326
+ }
327
+ if (frame.type === "res" && frame.id === agentRequestId) {
328
+ if (!frame.ok) {
329
+ finish({ error: `OpenClaw agent error: ${frame.error?.message || "unknown error"}` });
330
+ return;
331
+ }
332
+ const payload = frame.payload;
333
+ runId = typeof payload?.runId === "string" && payload.runId.trim() ? payload.runId : void 0;
334
+ if (!runId) {
335
+ logger.warn("[OpenClaw Agent] Missing runId in accepted response", {
336
+ agentId: this.agentId,
337
+ payload
338
+ });
339
+ finish({ error: "OpenClaw agent error: gateway accepted request without a runId" });
340
+ return;
341
+ }
342
+ ws.send(JSON.stringify({
343
+ type: "req",
344
+ id: waitRequestId,
345
+ method: "agent.wait",
346
+ params: {
347
+ runId,
348
+ timeoutMs: this.timeoutMs
349
+ }
350
+ }));
351
+ return;
352
+ }
353
+ if (frame.type === "event" && frame.event === "agent") {
354
+ const payload = frame.payload;
355
+ if (payload?.runId && runId && payload.runId !== runId) return;
356
+ if (payload?.stream === "assistant" && payload?.data?.text) lastText = payload.data.text;
357
+ return;
358
+ }
359
+ if (frame.type === "res" && frame.id === waitRequestId) {
360
+ if (frame.ok) finish({ output: lastText || "No output from agent" });
361
+ else finish({ error: `OpenClaw agent error: ${frame.error?.message || "unknown error"}` });
362
+ return;
363
+ }
364
+ });
365
+ });
366
+ }
367
+ };
368
+ //#endregion
369
+ //#region src/providers/openclaw/chat.ts
370
+ /**
371
+ * OpenClaw chat provider extends OpenAI chat completion provider.
372
+ *
373
+ * OpenClaw exposes an OpenAI-compatible HTTP API at /v1/chat/completions.
374
+ * This provider auto-detects gateway URL and bearer auth from:
375
+ * 1. Explicit config (gateway_url, auth_token, auth_password)
376
+ * 2. Environment variables (OPENCLAW_GATEWAY_URL, OPENCLAW_GATEWAY_TOKEN, OPENCLAW_GATEWAY_PASSWORD)
377
+ * 3. The active OpenClaw config file (OPENCLAW_CONFIG_PATH or ~/.openclaw/openclaw.json),
378
+ * including gateway.remote.url and gateway.tls.enabled
379
+ *
380
+ * Usage:
381
+ * openclaw - default agent (main)
382
+ * openclaw:main - specific agent
383
+ * openclaw:coding-agent - named agent
384
+ */
385
+ var OpenClawChatProvider = class extends OpenAiChatCompletionProvider {
386
+ agentId;
387
+ constructor(agentId, providerOptions = {}) {
388
+ super(`openclaw:${agentId}`, buildOpenClawProviderOptions(agentId, providerOptions));
389
+ this.agentId = agentId;
390
+ }
391
+ id() {
392
+ return `openclaw:${this.agentId}`;
393
+ }
394
+ toString() {
395
+ return `[OpenClaw Provider ${this.agentId}]`;
396
+ }
397
+ getApiUrlDefault() {
398
+ return `http://${DEFAULT_GATEWAY_HOST}:${DEFAULT_GATEWAY_PORT}/v1`;
399
+ }
400
+ getApiKey() {
401
+ return this.config.apiKey;
402
+ }
403
+ getApiUrl() {
404
+ return this.config.apiBaseUrl || this.getApiUrlDefault();
405
+ }
406
+ };
407
+ //#endregion
408
+ //#region src/providers/openclaw/responses.ts
409
+ /**
410
+ * OpenClaw Responses API Provider
411
+ *
412
+ * Extends OpenAI Responses API provider with OpenClaw-specific configuration.
413
+ * Routes through the OpenClaw gateway's /v1/responses endpoint.
414
+ *
415
+ * Requires `gateway.http.endpoints.responses.enabled=true` in OpenClaw config.
416
+ *
417
+ * Usage:
418
+ * openclaw:responses - default agent (main)
419
+ * openclaw:responses:main - explicit agent ID
420
+ * openclaw:responses:X - custom agent ID
421
+ */
422
+ var OpenClawResponsesProvider = class extends OpenAiResponsesProvider {
423
+ agentId;
424
+ constructor(agentId, providerOptions = {}) {
425
+ super(`openclaw:${agentId}`, buildOpenClawProviderOptions(agentId, providerOptions));
426
+ this.agentId = agentId;
427
+ }
428
+ id() {
429
+ return `openclaw:responses:${this.agentId}`;
430
+ }
431
+ toString() {
432
+ return `[OpenClaw Responses Provider ${this.agentId}]`;
433
+ }
434
+ getApiUrlDefault() {
435
+ return `http://${DEFAULT_GATEWAY_HOST}:${DEFAULT_GATEWAY_PORT}/v1`;
436
+ }
437
+ getApiKey() {
438
+ return this.config.apiKey;
439
+ }
440
+ getApiUrl() {
441
+ return this.config.apiBaseUrl || this.getApiUrlDefault();
442
+ }
443
+ async getOpenAiBody(prompt, context, callApiOptions) {
444
+ const result = await super.getOpenAiBody(prompt, context, callApiOptions);
445
+ if ("text" in result.body) delete result.body.text;
446
+ return result;
447
+ }
448
+ };
449
+ //#endregion
450
+ //#region src/providers/openclaw/tools.ts
451
+ /**
452
+ * OpenClaw Tool Invoke Provider
453
+ *
454
+ * Simple HTTP provider for direct tool invocation via POST /tools/invoke.
455
+ * The tool name is extracted from the provider path:
456
+ * openclaw:tools:sessions_list → tool="sessions_list"
457
+ *
458
+ * The prompt is parsed as JSON for tool arguments. If it's not valid JSON,
459
+ * it's passed as a single `input` argument.
460
+ *
461
+ * Usage:
462
+ * openclaw:tools:sessions_list - invoke the sessions_list tool
463
+ * openclaw:tools:session_status - invoke the session_status tool
464
+ *
465
+ * Optional config:
466
+ * action - tool sub-action, forwarded as body.action
467
+ * dry_run - dry-run hint, forwarded as body.dryRun
468
+ */
469
+ var OpenClawToolInvokeProvider = class {
470
+ toolName;
471
+ gatewayUrl;
472
+ authToken;
473
+ openclawConfig;
474
+ timeoutMs;
475
+ constructor(toolName, providerOptions = {}) {
476
+ this.toolName = toolName;
477
+ this.openclawConfig = providerOptions.config || {};
478
+ const env = providerOptions.env;
479
+ this.gatewayUrl = resolveGatewayUrl(this.openclawConfig, env);
480
+ this.authToken = resolveAuthToken(this.openclawConfig, env);
481
+ this.timeoutMs = this.openclawConfig.timeoutMs ?? REQUEST_TIMEOUT_MS;
482
+ }
483
+ id() {
484
+ return `openclaw:tools:${this.toolName}`;
485
+ }
486
+ toString() {
487
+ return `[OpenClaw Tool Provider ${this.toolName}]`;
488
+ }
489
+ toJSON() {
490
+ return { provider: this.id() };
491
+ }
492
+ async callApi(prompt) {
493
+ let args;
494
+ try {
495
+ args = JSON.parse(prompt);
496
+ } catch {
497
+ args = { input: prompt };
498
+ }
499
+ const url = `${this.gatewayUrl}/tools/invoke`;
500
+ const headers = {
501
+ "Content-Type": "application/json",
502
+ ...this.openclawConfig.headers || {}
503
+ };
504
+ if (this.authToken) headers["Authorization"] = `Bearer ${this.authToken}`;
505
+ const body = {
506
+ tool: this.toolName,
507
+ ...this.openclawConfig.action && { action: this.openclawConfig.action },
508
+ args,
509
+ ...typeof this.openclawConfig.dry_run === "boolean" && { dryRun: this.openclawConfig.dry_run },
510
+ ...this.openclawConfig.session_key && { sessionKey: this.openclawConfig.session_key }
511
+ };
512
+ logger.debug(`[OpenClaw Tool] POST ${url}`, {
513
+ tool: this.toolName,
514
+ args
515
+ });
516
+ try {
517
+ const controller = new AbortController();
518
+ const fetchTimeout = setTimeout(() => controller.abort(), this.timeoutMs);
519
+ const response = await fetchWithProxy(url, {
520
+ method: "POST",
521
+ headers,
522
+ body: JSON.stringify(body),
523
+ signal: controller.signal
524
+ }).finally(() => clearTimeout(fetchTimeout));
525
+ if (!response.ok) {
526
+ const text = await response.text();
527
+ return { error: `OpenClaw tool invoke failed (${response.status}): ${text}` };
528
+ }
529
+ const data = await response.json();
530
+ if (data.ok) return { output: typeof data.result === "string" ? data.result : JSON.stringify(data.result) };
531
+ return { error: data.error || "Unknown tool error" };
532
+ } catch (err) {
533
+ return { error: `OpenClaw tool invoke error: ${err instanceof Error ? err.message : String(err)}` };
534
+ }
535
+ }
536
+ };
537
+ //#endregion
538
+ //#region src/providers/openclaw/index.ts
539
+ /**
540
+ * Create an OpenClaw provider from a provider path string.
541
+ *
542
+ * Routing:
543
+ * openclaw → OpenClawChatProvider('main')
544
+ * openclaw:main → OpenClawChatProvider('main')
545
+ * openclaw:my-agent → OpenClawChatProvider('my-agent')
546
+ * openclaw:responses → OpenClawResponsesProvider('main')
547
+ * openclaw:responses:X → OpenClawResponsesProvider('X')
548
+ * openclaw:agent → OpenClawAgentProvider('main')
549
+ * openclaw:agent:X → OpenClawAgentProvider('X')
550
+ * openclaw:tools:sessions_list → OpenClawToolInvokeProvider('sessions_list')
551
+ */
552
+ function createOpenClawProvider(providerPath, providerOptions = {}, env) {
553
+ const splits = providerPath.split(":");
554
+ const keyword = splits[1];
555
+ const opts = {
556
+ ...providerOptions,
557
+ env
558
+ };
559
+ if (keyword === "responses") return new OpenClawResponsesProvider(splits[2] || "main", opts);
560
+ if (keyword === "agent") return new OpenClawAgentProvider(splits[2] || "main", opts);
561
+ if (keyword === "tools") {
562
+ const toolName = splits.slice(2).join(":");
563
+ if (!toolName) throw new Error("OpenClaw tools provider requires a tool name: openclaw:tools:<tool-name>");
564
+ return new OpenClawToolInvokeProvider(toolName, opts);
565
+ }
566
+ return new OpenClawChatProvider(splits.length > 1 ? splits.slice(1).join(":") : "main", opts);
567
+ }
568
+ //#endregion
569
+ export { createOpenClawProvider };
570
+
571
+ //# sourceMappingURL=openclaw-Bkayww9q.js.map