clawdi 0.14.58 → 0.14.59
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/dist/index.js +15 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -841,14 +841,25 @@ await sdk.mutateConfigFile({
|
|
|
841
841
|
mutate: (draft) => applyMergePatch(draft, patch),
|
|
842
842
|
});
|
|
843
843
|
`;var wP=b(()=>{eo();Mn();Qi();nt();dr();ete=new Map,tte=new Map});import{readFileSync as Y4e}from"node:fs";function Xz(e){if(Array.isArray(e))return e.some(Xz);if(e===null||typeof e!=="object")return!1;return Object.hasOwn(e,"$include")||Object.values(e).some(Xz)}function e2(e,t,n,r){let i;try{i=Y4e(t.configPath,"utf8")}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")return{providers:{},included:!1};throw Error("OpenClaw native provider ownership could not be inspected")}try{let o=v.record(v.string(),v.unknown()),s=o.parse(ite.default.parse(i)),a=s.models===void 0?{}:o.parse(s.models),l=Object.hasOwn(s,"$include")||Xz(a),c;if(l){let u={...r,NO_COLOR:"1",CLICOLOR:"0"};delete u.FORCE_COLOR,delete u.CLICOLOR_FORCE;let d=me(e,["config","get","models","--json"],t.home,n,{environment:u,environmentOverrides:{FORCE_COLOR:void 0,CLICOLOR_FORCE:void 0},timeoutMs:30000,maxBufferBytes:16777216});if(d.status!==0){if(d.status===1&&!d.error&&(d.stdout===""&&d.stderr===Q4e||d.stderr===""&&e6e.safeParse(JSON.parse(String(d.stdout))).success))return{providers:{},included:l};throw Error("Included provider config is unavailable")}let p=o.parse(JSON.parse(String(d.stdout)));c=p.providers===void 0?{}:o.parse(p.providers)}else c=a.providers===void 0?{}:o.parse(a.providers);return{providers:c,included:l}}catch{throw Error("OpenClaw native provider ownership could not be inspected")}}function ote(e,t,n,r){let{providers:i,included:o}=e2(e,t,n,r);return Object.entries(i).flatMap(([s,a])=>{let l=X4e.safeParse(a);if(!l.success)return[];let c=$l("openclaw",s,l.data.baseUrl);return c&&(c.runtime_env_name===l.data.apiKey.id||o&&l.data.apiKey.id==="__OPENCLAW_REDACTED__")?[s]:[]})}function Qz(e,t,n,r,i,o){if(me(e,t,r,i,{...o,input:n}).status!==0)throw Error("OpenClaw native provider configuration failed")}function ste(e,t,n,r,i){let o=new Map(e.flatMap(({routing:u})=>{let d=[[u.openclaw.plugin,u.openclaw.package]];if(u.openclaw.companion_plugin&&u.openclaw.companion_package)d.push([u.openclaw.companion_plugin,u.openclaw.companion_package]);return d}));if(o.size===0)return!1;let s=(u)=>{let d=me(t,u,n,r,{timeoutMs:30000,environment:i});return{status:d.status,stdout:String(d.stdout??""),stderr:String(d.stderr??"")}},a=()=>{let u=s(["plugins","list","--json"]);if(u.status!==0)throw Error("Native OpenClaw provider plugins could not be inspected");return vP.parse(JSON.parse(String(u.stdout)))},l=!1,c=a();for(let[u,d]of o){if(!c.plugins.some((m)=>m.id===u))Qz(t,["plugins","install",d,"--force","--pin",...od("install",s)],"",n,r,{timeoutMs:180000,environment:i}),l=!0,c=a();let p=c.plugins.filter((m)=>m.id===u);if(p.length!==1||p[0]?.status==="error")throw Error(`Required native OpenClaw provider plugin ${u} is unavailable`);if(p[0]?.enabled!==!0)Qz(t,["plugins","enable",u,...od("enable",s)],"",n,r,{timeoutMs:30000,environment:i}),l=!0,c=a();if(!c.plugins.some((m)=>m.id===u&&m.enabled&&m.status==="loaded"))throw Error(`Required native OpenClaw provider plugin ${u} did not activate`)}return l}function _P(e,t){let n={},r=[];for(let i of e){if(i.auth.kind!=="api-key")continue;let o=i.routing.openclaw.provider;r.push(o),n[o]={baseUrl:i.routing.base_url,auth:"api-key",apiKey:{source:"env",provider:"clawdi-native",id:i.auth.envName}}}for(let i of t)if(!r.includes(i))n[i]={apiKey:null,auth:null,baseUrl:null};return{providerIds:r,config:{...e.length||Object.keys(n).length?{models:{...e.length?{mode:"merge"}:{},...Object.keys(n).length?{providers:n}:{}}}:{},...r.length?{secrets:{providers:{"clawdi-native":{source:"env"}}}}:{}}}}function ate(e){let{command:t,context:n,workspaceRoot:r,environment:i}=e;if(sd(n,e.patch.config))return!1;return Qz(t,["config","patch","--stdin"],JSON.stringify(e.patch.config),n.home,r,{timeoutMs:30000,environment:i}),!0}var ite,X4e,Q4e=`Config path not found: models. Run openclaw config validate to inspect config shape.
|
|
844
|
-
`,e6e;var t2=b(()=>{ri();Xt();_w();wP();nt();ite=Fg(Yee(),1),X4e=v.object({baseUrl:v.string(),auth:v.literal("api-key"),apiKey:v.strictObject({source:v.literal("env"),provider:v.literal("clawdi-native"),id:v.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/)})}),e6e=v.strictObject({ok:v.literal(!1),error:v.strictObject({type:v.literal("cli_error"),message:v.literal("Config path is valid but unset: models. The runtime default applies until you set an authored value with openclaw config set models <value>.")})})});import{join as lte}from"node:path";function ute(e){let{placeholderEnv:t,configEnv:n,secretEnv:r}=Ta(e.manifest,e.runtime),i={...t,...n};for(let[o,s]of Object.entries(r)){let a=ft(e.secretValues??{},s);if(!a)throw Error("Connection provider credential is unavailable");i[o]=a}return i}function dte(e){if(e.runtime==="openclaw"){if(!e.observation.commandPath)throw Error("OpenClaw config command is unavailable");return e2(e.observation.commandPath,e.openClawContext,e.workspaceRoot,ute(e)).providers}if(e.runtime!=="hermes"||!e.hermesConfig)throw Error("Connection runtime config is unavailable");let t=Gr(e.hermesConfig,"providers");if(!t.exists)return{};let n=z(t.value);if(!n)throw Error("Hermes providers must be an object");return n}function pte(e,t){return ht(Object.fromEntries(t.sort().map((n)=>[n,e[n]??null])))}function mte(e){let t=gw(e.manifest,e.runtime);if(e.runtime!=="hermes"||t.length===0)return;let n=nd("hermes",e.home);if(!n)throw Error("Hermes application path is unavailable");let r=me(lte(n,"
|
|
844
|
+
`,e6e;var t2=b(()=>{ri();Xt();_w();wP();nt();ite=Fg(Yee(),1),X4e=v.object({baseUrl:v.string(),auth:v.literal("api-key"),apiKey:v.strictObject({source:v.literal("env"),provider:v.literal("clawdi-native"),id:v.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/)})}),e6e=v.strictObject({ok:v.literal(!1),error:v.strictObject({type:v.literal("cli_error"),message:v.literal("Config path is valid but unset: models. The runtime default applies until you set an authored value with openclaw config set models <value>.")})})});import{join as lte}from"node:path";function ute(e){let{placeholderEnv:t,configEnv:n,secretEnv:r}=Ta(e.manifest,e.runtime),i={...t,...n};for(let[o,s]of Object.entries(r)){let a=ft(e.secretValues??{},s);if(!a)throw Error("Connection provider credential is unavailable");i[o]=a}return i}function dte(e){if(e.runtime==="openclaw"){if(!e.observation.commandPath)throw Error("OpenClaw config command is unavailable");return e2(e.observation.commandPath,e.openClawContext,e.workspaceRoot,ute(e)).providers}if(e.runtime!=="hermes"||!e.hermesConfig)throw Error("Connection runtime config is unavailable");let t=Gr(e.hermesConfig,"providers");if(!t.exists)return{};let n=z(t.value);if(!n)throw Error("Hermes providers must be an object");return n}function pte(e,t){return ht(Object.fromEntries(t.sort().map((n)=>[n,e[n]??null])))}function mte(e){let t=gw(e.manifest,e.runtime);if(e.runtime!=="hermes"||t.length===0)return;let n=nd("hermes",e.home);if(!n)throw Error("Hermes application path is unavailable");let r=me(lte(n,"venv","bin","python"),["-c",r6e,n],e.home,e.workspaceRoot,{environmentOverrides:{HERMES_HOME:lte(e.home,".hermes")},input:JSON.stringify(t.map(({id:i,baseUrl:o})=>({id:i,baseUrl:o}))),timeoutMs:30000,maxBufferBytes:65536});if(r.status!==0||String(r.stdout).trim()!=="ok")throw Error("Hermes custom provider credential conflict or unsupported public pool API")}function cte(e,t){let n=z(e);return n?.source==="env"&&(n.provider==="clawdi-connection"||n.provider==="default")&&n.id===t}function fte(e){let t=gw(e.manifest,e.runtime);for(let s of t)if(!ft(e.secretValues??{},s.secretRef))throw Error("Connection provider credential is unavailable");let n=dte(e),r={...e.ownership.providers},i={};for(let s of t){let{id:a,baseUrl:l,apiMode:c,envName:u}=s,d=z(n[a]);if(!d)throw Error(`Connection provider ${a} must already exist`);let p=r[a];if(p&&p.envName!==u)throw Error("Connection credential environment is immutable");let m=e.runtime==="openclaw"?d.baseUrl:d.api??d.url??d.base_url,f=e.runtime==="openclaw"?d.api??"openai-completions":d.api_mode??d.transport,g=e.runtime==="openclaw"?t6e[c]:n6e[c];if(!g)throw Error("Connection protocol is unsupported by this runtime");if(!p&&(m!==l||f!==g))throw Error(`Connection provider ${a} routing changed before handoff`);let y={};if(e.runtime==="openclaw"){if(!Array.isArray(d.models))throw Error("Custom OpenClaw provider must retain its models array");if(d.apiKey!==void 0&&!cte(d.apiKey,u))throw Error("OpenClaw connection credential ownership conflict");if(d.auth!==void 0&&d.auth!=="api-key")throw Error("OpenClaw connection auth mode conflict");if(y.auth="api-key",y.apiKey={source:"env",provider:"clawdi-connection",id:u},p&&m!==l)y.baseUrl=l;if(p&&f!==g)y.api=g}else{if(d.api_key||d.key_cmd||d.key_env&&d.key_env!==u||d.api_key_env&&d.api_key_env!==u)throw Error("Hermes connection credential ownership conflict");if(y.key_env=u,p&&m!==l)y[Object.hasOwn(d,"api")?"api":Object.hasOwn(d,"url")?"url":"base_url"]=l;if(p&&f!==g)y[Object.hasOwn(d,"api_mode")?"api_mode":"transport"]=g}r[a]={envName:u,baseUrl:l,apiMode:c},i[a]=y}let o=new Set(t.map((s)=>s.id));for(let[s,a]of Object.entries(r)){if(o.has(s))continue;let l=z(n[s]);if(!l)continue;if(e.runtime==="openclaw"&&cte(l.apiKey,a.envName))i[s]={apiKey:null,...l.auth==="api-key"?{auth:null}:{}};if(e.runtime==="hermes"){let c=Object.fromEntries(["key_env","api_key_env"].filter((u)=>l[u]===a.envName).map((u)=>[u,null]));if(Object.keys(c).length)i[s]=c}}return mte(e),{runtime:e.runtime,providers:r,sourceRevision:pte(n,Object.keys(r)),patch:i}}function gte(e){let t=e.ownership.prepared;if(!t||t.runtime!==e.runtime||!zs(t.providers,e.ownership.providers))throw Error("Connection providers require a durably prepared ownership transfer");let n=dte(e);if(pte(n,Object.keys(t.providers))!==t.sourceRevision)throw Error("Connection provider config changed after preflight");mte(e);let r=!1,i={};for(let[o,s]of Object.entries(t.patch)){let a=z(n[o])??{},l={...a};for(let[c,u]of Object.entries(s))if(u===null)delete l[c];else l[c]=u;if(zs(a,l))continue;r=!0,i[o]=s,n[o]=l}if(!r)return!1;if(e.runtime==="hermes"){if(!e.hermesConfig)throw Error("Hermes config command is unavailable");qt(e.hermesConfig,"providers",n)}else{if(!e.observation.commandPath)throw Error("OpenClaw config command is unavailable");let o={models:{providers:i},...gw(e.manifest,e.runtime).length?{secrets:{providers:{"clawdi-connection":{source:"env"}}}}:{}};if(me(e.observation.commandPath,["config","patch","--stdin"],e.home,e.workspaceRoot,{input:JSON.stringify(o),environment:ute(e),timeoutMs:30000}).status!==0)throw Error("OpenClaw connection configuration failed")}return!0}var t6e,n6e,r6e=`
|
|
845
845
|
import contextlib, io, json, sys
|
|
846
846
|
sys.path.insert(0, sys.argv[1])
|
|
847
847
|
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
|
848
|
-
from agent
|
|
848
|
+
from agent import credential_pool
|
|
849
849
|
from hermes_cli.auth import read_credential_pool
|
|
850
|
+
candidates = getattr(credential_pool, "custom_provider_pool_key_candidates", None)
|
|
851
|
+
legacy_key = getattr(credential_pool, "get_custom_provider_pool_key", None)
|
|
850
852
|
for connection in json.load(sys.stdin):
|
|
851
|
-
|
|
853
|
+
if callable(candidates):
|
|
854
|
+
keys = candidates(connection["baseUrl"], provider_name=connection["id"])
|
|
855
|
+
elif callable(legacy_key):
|
|
856
|
+
key = legacy_key(connection["baseUrl"], provider_name=connection["id"])
|
|
857
|
+
keys = [] if key is None else [key]
|
|
858
|
+
else:
|
|
859
|
+
raise ValueError("Custom provider public pool API is unavailable")
|
|
860
|
+
if not isinstance(keys, (list, tuple)) or any(not isinstance(key, str) or not key for key in keys):
|
|
861
|
+
raise ValueError("Custom provider public pool API returned invalid keys")
|
|
862
|
+
for key in keys:
|
|
852
863
|
rows = read_credential_pool(key)
|
|
853
864
|
if not isinstance(rows, list) or rows:
|
|
854
865
|
raise ValueError("Custom provider credential pool conflicts with connection ownership")
|
|
@@ -1088,7 +1099,7 @@ def main():
|
|
|
1088
1099
|
|
|
1089
1100
|
if __name__ == "__main__":
|
|
1090
1101
|
main()
|
|
1091
|
-
`;var hte=()=>{};import{existsSync as o6e}from"node:fs";import{join as r2}from"node:path";function wte(e){if(e.providers.length===0&&e.previousProviderIds.length===0&&!o6e(r2(e.home,".clawdi","runtime","hermes-native-credentials.json")))return{changed:!1,strategyUpdates:{},selectedProvider:e.selectedProvider??null};let t=nd("hermes",e.home);if(!t)throw Error("Hermes application path is unavailable");let n=me(r2(t,"
|
|
1102
|
+
`;var hte=()=>{};import{existsSync as o6e}from"node:fs";import{join as r2}from"node:path";function wte(e){if(e.providers.length===0&&e.previousProviderIds.length===0&&!o6e(r2(e.home,".clawdi","runtime","hermes-native-credentials.json")))return{changed:!1,strategyUpdates:{},selectedProvider:e.selectedProvider??null};let t=nd("hermes",e.home);if(!t)throw Error("Hermes application path is unavailable");let n=me(r2(t,"venv","bin","python"),["-c",yte,t],e.home,e.workspaceRoot,{environmentOverrides:{HERMES_HOME:r2(e.home,".hermes")},input:JSON.stringify({providers:e.providers,previousProviderIds:e.previousProviderIds,strategies:e.strategies,selectedProvider:e.selectedProvider}),timeoutMs:30000,maxBufferBytes:65536});if(n.status!==0)throw Error("Hermes native credential synchronization failed");try{return s6e.parse(JSON.parse(String(n.stdout)))}catch{throw Error("Hermes native credential synchronization returned invalid output")}}var vte,s6e;var _te=b(()=>{Xt();hte();eo();nt();vte=v.string().regex(/^[a-z][a-z0-9-]{0,119}$/),s6e=v.object({changed:v.boolean(),selectedProvider:vte.nullable(),strategyUpdates:v.record(vte,v.object({exists:v.boolean(),value:v.unknown().optional()}))})});function bte(e){let{connections:t,config:n}=e,r=t.flatMap((c)=>{if(c.auth.kind!=="api-key")return[];let u=ft(e.secretValues,c.auth.secretRef);if(!u)throw Error("Native Hermes provider credential is unavailable");return[{providerId:c.routing.hermes.provider,apiKey:u,baseUrl:c.routing.base_url}]}),i=Gr(n,"credential_pool_strategies");if(i.exists&&!Ze(i.value))throw Error("Hermes credential strategies must be an object");let o=Ze(i.value)?i.value:{},s=Gr(n,"model.provider"),a=wte({home:e.home,workspaceRoot:e.workspaceRoot,providers:r,previousProviderIds:e.previousProviderIds,strategies:o,selectedProvider:gt(s.value)?.trim().toLowerCase()}),l=a.changed;if(t.some((c)=>c.routing.hermes.provider===a.selectedProvider))for(let c of["base_url","api_key","api","key_env","api_mode","auth_mode"]){let u=`model.${c}`;if(Gr(n,u).exists)qt(n,u,void 0),l=!0}if(Object.keys(a.strategyUpdates).length>0){let c={...o};for(let[u,d]of Object.entries(a.strategyUpdates))if(d.exists)c[u]=d.value;else delete c[u];qt(n,"credential_pool_strategies",Object.keys(c).length>0?c:void 0)}return{changed:l,providerIds:r.map((c)=>c.providerId)}}var Ste=b(()=>{As();_te();Mn();dr()});function s2(e){let{desiredCredentialRevision:t,desiredNativeProfileId:n,desiredCredentialFingerprint:r,ledger:i,native:o}=e;if(t===null)return a6e(i,o);if(n===null||r===null)throw Error("Desired OAuth credential requires native identity and fingerprint evidence");if(i?.state==="intent")return l6e({desiredCredentialRevision:t,desiredNativeProfileId:n,desiredCredentialFingerprint:r,ledger:i,native:o});if(i&&i.nativeProfileId===n&&i.credentialRevision===t){if(o.state==="missing")return Xn({nativeProfileId:n,credentialRevision:t,state:"revoked"});let s=i.state==="seeded"&&i.credentialFingerprint!==void 0&&o.credentialFingerprint===i.credentialFingerprint;if(i.state==="seeded"&&(o.state==="managed"||s))return Xn(Sf(n,t,i.credentialFingerprint));return Xn({nativeProfileId:n,credentialRevision:t,state:"adopted"})}if(o.state==="missing")return bP(n,t,r,!0);return o2(n,t,Ete(o),r,!0)}function a2(e,t=null){if(!e.requiresWriteAheadIntent||e.nativeAction==="preserve")throw Error("OAuth credential decision does not require a write-ahead intent");if((e.nativeAction==="upsert"||e.nativeAction==="remove")&&!e.expectedCredentialFingerprint)throw Error(`${e.nativeAction} intent requires before-credential evidence`);if((e.nativeAction==="seed"||e.nativeAction==="upsert")&&!e.targetCredentialFingerprint)throw Error(`${e.nativeAction} intent requires target-credential evidence`);let n=e.nextLedger??t;if(!n)throw Error("OAuth credential intent requires ledger identity");return{nativeProfileId:n.nativeProfileId,credentialRevision:n.credentialRevision,state:"intent",operation:e.nativeAction,...e.expectedCredentialFingerprint?{beforeCredentialFingerprint:e.expectedCredentialFingerprint}:{},...e.targetCredentialFingerprint?{targetCredentialFingerprint:e.targetCredentialFingerprint}:{}}}function a6e(e,t){if(!e)return Xn(null);if(e.state==="intent"){if(e.operation==="remove"){if(t.state==="missing")return Xn(null);if(e.beforeCredentialFingerprint&&t.credentialFingerprint===e.beforeCredentialFingerprint)return i2(e.beforeCredentialFingerprint,!1);return Xn(e)}let r=kte(e);if(r&&t.credentialFingerprint===r)return i2(r,!0);if(e.operation==="seed"&&t.state==="missing")return Xn(null);if(e.operation==="upsert"&&e.beforeCredentialFingerprint&&t.credentialFingerprint===e.beforeCredentialFingerprint)return Xn(null);return Xn(e)}if(e.state==="seeded"&&t.state!=="missing"&&(t.state==="managed"||e.credentialFingerprint!==void 0&&t.credentialFingerprint===e.credentialFingerprint))return i2(Ete(t),!0);return Xn(null)}function l6e(e){let{desiredCredentialRevision:t,desiredNativeProfileId:n,desiredCredentialFingerprint:r,ledger:i,native:o}=e,s=i.nativeProfileId===n&&i.credentialRevision===t,a=kte(i);if(s&&i.operation==="seed"){if(o.state==="missing")return bP(n,t,a??r,!1);if(a&&o.credentialFingerprint===a)return Xn(Sf(n,t,a));return Xn(i)}if(s&&i.operation==="upsert"){if(a&&o.credentialFingerprint===a)return Xn(Sf(n,t,a));if(i.beforeCredentialFingerprint&&o.credentialFingerprint===i.beforeCredentialFingerprint)return o2(n,t,i.beforeCredentialFingerprint,a??r,!1);return Xn(i)}if(s&&i.operation==="remove"){if(o.state==="missing")return bP(n,t,r,!0);if(i.beforeCredentialFingerprint&&o.credentialFingerprint===i.beforeCredentialFingerprint)return Xn(Sf(n,t,i.beforeCredentialFingerprint));return Xn(i)}if(o.state==="missing")return bP(n,t,r,!0);let l=a&&o.credentialFingerprint===a||i.beforeCredentialFingerprint&&o.credentialFingerprint===i.beforeCredentialFingerprint?o.credentialFingerprint:void 0;if(!l)return Xn(i);return o2(n,t,l,r,!0)}function bP(e,t,n,r){return{nativeAction:"seed",requiresWriteAheadIntent:r,targetCredentialFingerprint:n,nextLedger:Sf(e,t,n)}}function o2(e,t,n,r,i){return{nativeAction:"upsert",requiresWriteAheadIntent:i,expectedCredentialFingerprint:n,targetCredentialFingerprint:r,nextLedger:Sf(e,t,r)}}function i2(e,t){return{nativeAction:"remove",requiresWriteAheadIntent:t,expectedCredentialFingerprint:e,nextLedger:null}}function Xn(e){return{nativeAction:"preserve",requiresWriteAheadIntent:!1,nextLedger:e}}function Sf(e,t,n){return{nativeProfileId:e,credentialRevision:t,state:"seeded",...n?{credentialFingerprint:n}:{}}}function kte(e){return e.targetCredentialFingerprint??e.credentialFingerprint}function Ete(e){if(!e.credentialFingerprint)throw Error("Native OAuth credential is present without verifiable fingerprint evidence");return e.credentialFingerprint}import{createHash as c6e}from"node:crypto";import{existsSync as u6e,readFileSync as d6e}from"node:fs";import{dirname as p6e,join as m6e}from"node:path";function Pte(e,t,n){let r=c6e("sha256").update(n).digest("hex");return m6e(e,t,`${r}.json`)}function l2(e){if(!u6e(e))return null;let t=JSON.parse(d6e(e,"utf8"));return Rte.parse(t)}function bw(e,t,n,r={}){let i=Rte.parse({schemaVersion:Ate,...t,...n});return ue(e,`${JSON.stringify(i,null,2)}
|
|
1092
1103
|
`,{mode:384,dirMode:448}),r.afterWrite?.(e,p6e(e)),i}function c2(e){if(!e)return null;return{nativeProfileId:e.nativeProfileId,credentialRevision:e.credentialRevision,state:e.state,...e.operation?{operation:e.operation}:{},...e.credentialFingerprint?{credentialFingerprint:e.credentialFingerprint}:{},...e.beforeCredentialFingerprint?{beforeCredentialFingerprint:e.beforeCredentialFingerprint}:{},...e.targetCredentialFingerprint?{targetCredentialFingerprint:e.targetCredentialFingerprint}:{}}}var Ate="clawdi.oauthCredentialOwnership.v2",Rte;var Cte=b(()=>{Xt();kt();Rte=v.object({schemaVersion:v.literal(Ate),runtime:v.enum(["hermes","openclaw"]),providerId:v.string().min(1),nativeProfileId:v.string().min(1),credentialRevision:v.string().min(1).max(64),state:v.enum(["intent","seeded","adopted","revoked"]),operation:v.enum(["seed","upsert","remove"]).optional(),credentialFingerprint:v.string().regex(/^sha256:[a-f0-9]{64}$/).optional(),beforeCredentialFingerprint:v.string().regex(/^sha256:[a-f0-9]{64}$/).optional(),targetCredentialFingerprint:v.string().regex(/^sha256:[a-f0-9]{64}$/).optional()}).strict().superRefine((e,t)=>{if(e.state==="intent"&&!e.operation)t.addIssue({code:"custom",message:"intent ledger requires an operation"});if(e.state==="intent"&&(e.operation==="seed"||e.operation==="upsert")&&!e.targetCredentialFingerprint)t.addIssue({code:"custom",message:"credential write intent requires target evidence"});if(e.state==="intent"&&(e.operation==="upsert"||e.operation==="remove")&&!e.beforeCredentialFingerprint)t.addIssue({code:"custom",message:"credential mutation intent requires before evidence"});if(e.state!=="intent"&&e.operation)t.addIssue({code:"custom",message:"stable ledger cannot carry an operation"});if(e.state!=="intent"&&(e.beforeCredentialFingerprint||e.targetCredentialFingerprint))t.addIssue({code:"custom",message:"stable ledger cannot carry intent evidence"})})});function kP(e){return e.startsWith("# Generated by clawdi runtime init. Do not edit inside hosted runtime.")}function Sw(){return process.env.CLAWDI_RUNTIME_USER?.trim()||"clawdi"}function $te(e){let t=`/run/user/${e}`;return{XDG_RUNTIME_DIR:t,DBUS_SESSION_BUS_ADDRESS:`unix:path=${t}/bus`}}var SP="# Generated by clawdi runtime init. Do not edit inside hosted runtime.";import{existsSync as f6e,readdirSync as g6e,readFileSync as h6e}from"node:fs";import{join as xte}from"node:path";function kf(e,t=Ite){if(!f6e(e))return[];let n=[];for(let r of g6e(e)){if(r.endsWith(".service")){let s=xte(e,r);if(r.startsWith("clawdi-"))n.push({kind:"base-unit",unitName:r,path:s});else{let a=u2(s,t);if(a!==null)n.push({kind:"base-unit",unitName:r,path:s,generatedContents:a})}continue}if(!r.endsWith(".service.d"))continue;let i=xte(e,r,EP),o=u2(i,t);if(o===null)continue;n.push({kind:"hosted-drop-in",unitName:r.slice(0,-2),path:i,generatedContents:o})}return n}function d2(e){return u2(e,Ite)!==null}function Ite(e){try{return h6e(e,"utf-8")}catch{return null}}function u2(e,t){let n=t(e);return n!==null&&kP(n)?n:null}function zo(){return process.env.CLAWDI_SYSTEMCTL_PATH?.trim()||"systemctl"}function Ef(e){return Object.fromEntries(e.split(/\r?\n/).map((t)=>t.trim()).filter(Boolean).map((t)=>{let n=t.indexOf("=");return n<0?[t,""]:[t.slice(0,n),t.slice(n+1)]}))}var EP="10-clawdi-hosted.conf";var kw=()=>{};import{existsSync as y6e,readFileSync as v6e}from"node:fs";import{isAbsolute as w6e,join as ad,resolve as _6e}from"node:path";function Nte(e){return[e.stderr,e.stdout].filter((t)=>typeof t==="string").join(`
|
|
1093
1104
|
`)}function $6e(e){let t=Nte(e);return t.includes(R6e)&&t.includes('Run "openclaw doctor --fix"')}function Dte(e){return!e.error&&!e.signal&&Nte(e).includes(P6e)}function x6e(e){for(let t of[ad(e,".local","bin","openclaw"),ad(e,".openclaw","bin","openclaw")])if(rn(t))return t;return null}function Aw(e){let t=x6e(e);if(t)return t;throw Error("installed OpenClaw CLI is unavailable")}function I6e(e){let t;try{t=RT(e)}catch{throw Error("OpenClaw official agent workspace roster is malformed")}let n=t.filter((r)=>r.id===b6e);if(n.length!==1||!w6e(n[0].workspace))throw Error("OpenClaw official agent workspace roster is malformed");return _6e(n[0].workspace)}function m2(e){try{let t=JSON.parse(v6e(ad(e,".openclaw","openclaw.json"),"utf8")),n=t&&typeof t==="object"&&!Array.isArray(t)?t:{},r=n.agents&&typeof n.agents==="object"&&!Array.isArray(n.agents)?n.agents:{},i=r.defaults&&typeof r.defaults==="object"&&!Array.isArray(r.defaults)?r.defaults:{};return ht({defaultWorkspace:i.workspace??null,entries:r.entries??null,list:r.list??null})}catch{return"unavailable"}}function O6e(e){let t=me(zo(),["--user","show",k6e,"--property=LoadState","--property=ActiveState"],e,e,{timeoutMs:Ew,maxBufferBytes:65536});if(t.status!==0)return!1;let n=Ef(String(t.stdout));return n.LoadState==="loaded"&&(n.ActiveState==="activating"||n.ActiveState==="deactivating")}function D6e(){Atomics.wait(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)),0,0,A6e)}function f2(e){let t=Aw(e),n=[ln(t),m2(e)].join("\x00"),r=Ote.get(e);if(r?.revision===n)return r.workspace;let i=me(t,["agents","list","--json"],e,e,{timeoutMs:Ew,maxBufferBytes:1048576});for(let s=0;i.status!==0&&s<E6e&&O6e(e);s+=1)D6e(),i=me(t,["agents","list","--json"],e,e,{timeoutMs:Ew,maxBufferBytes:1048576});if($6e(i))throw new AP(!0);if(i.status!==0)throw new AP(!1);let o=I6e(String(i.stdout));return Ote.set(e,{revision:n,workspace:o}),o}function T6e(e){if(e.status!==1||e.error||e.signal)return!1;let t;try{t=JSON.parse(String(e.stdout))}catch{return!1}if(!t||typeof t!=="object"||Array.isArray(t))return!1;let n=t;if(n.valid!==!1||typeof n.path!=="string"||!Array.isArray(n.issues)||n.issues.length===0)return!1;return n.issues.every((r)=>{if(!r||typeof r!=="object"||Array.isArray(r))return!1;let i=r;return typeof i.path==="string"&&typeof i.message==="string"})}function N6e(e){let t=Aw(e),n=me(t,["config","validate","--json"],e,e,{timeoutMs:Ew,maxBufferBytes:1048576});if(!T6e(n))return!1;return jte(e,t),!0}function p2(e,t=Aw(e)){return me(t,["doctor","--fix","--non-interactive"],e,e,{timeoutMs:S6e,maxBufferBytes:4194304})}function jte(e,t=Aw(e)){if(p2(e,t).status!==0)throw Error("OpenClaw official repair failed")}function j6e(e,t){let n=Oy(e,[t],Nl.doctorMigrations);if(!n)throw Error("installed OpenClaw public migration archive SDK is unavailable");if(me("node",["--input-type=module","--eval",C6e,n,ad(e,".openclaw","identity","device.json")],e,e,{timeoutMs:Ew,maxBufferBytes:1048576}).status!==0)throw Error("OpenClaw legacy device identity archive failed")}function Mte(e){if(!y6e(ad(e,".openclaw","identity","device.json")))return!1;let t=Aw(e),n=p2(e,t);if(!Dte(n)){if(n.status!==0)throw Error("OpenClaw official repair failed");return!0}j6e(e,t);let r=p2(e,t);if(r.status!==0||Dte(r))throw Error("OpenClaw legacy device identity retirement did not clear the conflict");return!0}function Lte(e,t){if(t instanceof AP&&t.doctorRepairRequired)return jte(e),!0;return N6e(e)}function Tte(e,t={}){let n=[t.commandPath,t.appRoot],r=(o)=>Oy(e,n,o),i=()=>{let a=process.env.CLAWDI_RUNTIME_TEST_OPENCLAW_PROVIDER_AUTH_SDK?.trim();if(a&&process.env.CLAWDI_RUNTIME_ALLOW_TEST_INSTALLERS!=="1")throw Error("CLAWDI_RUNTIME_TEST_OPENCLAW_PROVIDER_AUTH_SDK requires CLAWDI_RUNTIME_ALLOW_TEST_INSTALLERS=1");return a||null};return{configMutation:r(Nl.configMutation),deviceBootstrap:r(Nl.deviceBootstrap),providerAuth:i()??r(Nl.providerAuth)}}function Ute(e,t){let n=ad(t,".openclaw"),r=(...s)=>ad(n,...s),i=r("openclaw.json"),o=Tte(t);return{home:t,managedApiKeyProjection:M6e(e),stateRoot:n,configPath:i,agentDirs:{main:r("agents","main","agent"),managed:[]},sdk:o,requireSdkExport(s){let a=o[s];if(a)return a;let l=Nl[s];throw Error(`installed OpenClaw ${l} SDK export is unavailable`)},refreshSdkExports(s){Object.assign(o,Tte(t,s))}}}function M6e(e){let t=e.runtimes.openclaw,n=t?.provider_ids?.[0];if(!n||!Gi(n))return!1;let r=L6e(e.projection?.providers?.[n]),o=Nz(jz(e,"openclaw"))?.catalog.providers.find((s)=>s.id===Nn);return t?.enabled===!0&&t.providerMode==="configured"&&r?.managed_by==="clawdi"&&typeof r.apiKeySecretRef==="string"&&o?.managed_by==="clawdi"&&o.runtime_env_name===Er&&o.auth.type==="api_key"&&o.auth.source==="managed"}function L6e(e){if(!e||typeof e!=="object"||Array.isArray(e))return null;return e}var b6e="main",Ew=15000,S6e=120000,k6e="openclaw-gateway.service",E6e=2,A6e=3000,Ote,R6e="OpenClaw startup migrations did not complete cleanly",P6e="canonical SQLite device identity differs from the legacy identity",C6e=`
|
|
1094
1105
|
import { pathToFileURL } from "node:url";
|
package/package.json
CHANGED