beeos-claw 0.6.95 → 0.6.96
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isDeepStrictEqual}from"node:util";import{CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN,RUNTIME_HASH_DOMAINS}from"@beeos-ai/beeos-types/runtime";import{assertCentralNativeReceipt}from"./central-native-context-engine.js";import{runtimeMessageHash}from"./runtime-message-channel-contract.js";const object=e=>null!==e&&"object"==typeof e&&!Array.isArray(e),promptText=e=>{if("string"==typeof e.text&&e.text.length>0)return e.text;return(Array.isArray(e.parts)?e.parts:[]).filter(object).filter(e=>"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n")},text=e=>"string"==typeof e&&e.length>0,decimal=e=>"string"==typeof e&&/^(0|[1-9][0-9]*)$/.test(e),associationKeys=["context","session_id","history_generation","branch_id","writer","response_id","attempt_id","watermark","config_pin","persona_ref"],GRANT_CLOCK_SKEW_SECONDS=30,grantInvalid=e=>new Error(`central native original signed intent is invalid: ${e}`),grantDecodeReason=e=>{const t=e.split(".")[1];if(!t)return"grant_signature_invalid";let r;try{const e=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));if(!object(e))return"grant_signature_invalid";r=e}catch{return"grant_signature_invalid"}return r.iss!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.issuer?"grant_issuer_mismatch":r.aud!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.audience?"grant_audience_mismatch":r.purpose!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.purpose?"grant_binding_mismatch":"grant_signature_invalid"};export function isCentralNativeResponse(e){const t=e.message?.payload,r=t?.request;return 2===t?.schemaVersion&&"session/prompt"===t.method&&object(r)&&object(r.params)&&Object.hasOwn(r.params,"centralChat")}export function verifyCentralNativeIntent(e){const t=e.executionGrant,r=e.request;if(!t)throw grantInvalid("grant_binding_mismatch");const i=e.verifier.verifyAndDecodeGrant(t);if(!i)throw grantInvalid(grantDecodeReason(t));const n=i.claims,a=object(r.request)?r.request:{},s=object(a.params)?a.params:{},o=object(s.centralChat)?s.centralChat:{},c=object(r.command)?r.command:{},d=object(c.context)?c.context:{},p=object(d.conversation)?d.conversation:{},l=object(o.context)?o.context:{},m=object(o.writer)?o.writer:{},u=object(o.config_pin)?o.config_pin:{},h=u.credential_set_ref,g=()=>{const t=e.getLease();if(!t||t.instanceId!==e.lease.instanceId||t.leaseId!==e.lease.leaseId||t.handlerIdentity!==e.lease.handlerIdentity||t.runtimeEpoch!==e.lease.runtimeEpoch||!Number.isFinite(Date.parse(t.leaseExpiresAt))||Date.parse(t.leaseExpiresAt)<=Date.now())throw new Error("central native execution is fenced")},_=Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(n.iat)||!Number.isSafeInteger(n.exp)||n.exp<=n.iat||n.exp-n.iat>60)throw grantInvalid("grant_binding_mismatch");if(n.exp+30<_)throw grantInvalid("grant_expired");if(n.iat>_+30)throw grantInvalid("grant_iat_future");if(!object(r)||2!==r.schemaVersion||"session/prompt"!==r.method||!Object.hasOwn(s,"centralChat")||"string"!=typeof r.executionGrantHash||!/^[a-f0-9]{64}$/.test(r.executionGrantHash)||"cloud"!==r.authorityRealm||!object(r.cloudSubject)||r.cloudSubject.instanceId!==e.lease.instanceId||!isDeepStrictEqual(r.cloudSubject,n.cloudSubject)||r.instanceId!==e.lease.instanceId||r.leaseId!==e.lease.leaseId||r.runtimeHandlerIdentity!==e.lease.handlerIdentity||r.dispatchEpoch!==e.lease.runtimeEpoch||"cloud"!==n.authorityRealm||"session/prompt"!==n.method||"conversation"!==n.scope||"start"!==n.executionMode||n.platformConversationId!==o.session_id||n.historyGeneration!==o.history_generation||n.platformAgentId!==s.platformAgentId||!text(n.runtimeAgentUid)||s.conversationId!==o.session_id||"conversation"!==d.scope||p.runtimeConversationUid!==o.session_id||p.runtimeSessionKey!==o.session_id||d.historyGeneration!==o.history_generation||d.operationId!==r.operationId||d.runtimeInstanceUid!==r.instanceId||d.dispatchEpoch!==r.dispatchEpoch||d.paramsHash!==r.paramsHash||!isDeepStrictEqual(n.command,c)||n.sub!==e.lease.handlerIdentity||n.handlerIdentity!==e.lease.handlerIdentity||["operationId","requestMessageId","instanceId","leaseId","dispatchEpoch","requestHash","paramsHash","commandHash","idempotencyKeyHash"].some(e=>!text(r[e])||n[e]!==r[e])||"2.0"!==a.jsonrpc||"session/prompt"!==a.method||"session.prompt"!==c.name||!text(s.runtimeRunId)||s.taskId!==r.operationId||s.taskRequestMessageId!==r.requestMessageId||runtimeMessageHash(RUNTIME_HASH_DOMAINS.request,a)!==r.requestHash||runtimeMessageHash(RUNTIME_HASH_DOMAINS.params,{method:r.method,params:s})!==r.paramsHash||runtimeMessageHash(RUNTIME_HASH_DOMAINS.command,{command:c})!==r.commandHash||![o.session_id,o.history_generation,o.branch_id,o.response_id,o.attempt_id,l.tenant_ref,l.scope_ref,l.request_id,m.writer_id,m.writer_epoch].every(text)||!Number.isSafeInteger(l.authorization_revision)||l.authorization_revision<1||!Number.isSafeInteger(l.erasure_epoch)||l.erasure_epoch<0||!decimal(o.history_generation)||!decimal(o.watermark)||!decimal(m.writer_epoch)||"0"===m.writer_epoch||Object.keys(o).length!==associationKeys.length||!associationKeys.every(e=>Object.hasOwn(o,e))||4!==Object.keys(u).length||u.agent_id!==s.platformAgentId||!text(u.revision)||"string"!=typeof u.content_sha256||!/^[a-f0-9]{64}$/.test(u.content_sha256)||null!==h&&(!object(h)||2!==Object.keys(h).length||!text(h.set_id)||!Number.isSafeInteger(h.version)||h.version<1)||null!==o.persona_ref&&(!object(o.persona_ref)||2!==Object.keys(o.persona_ref).length||!text(o.persona_ref.persona_id)||!text(o.persona_ref.revision)))throw grantInvalid("grant_binding_mismatch");g();return{binding:{sessionId:o.session_id,historyGeneration:o.history_generation,branchId:o.branch_id,responseId:o.response_id,attemptId:o.attempt_id,operationId:r.operationId,context:l,writer:m},params:structuredClone(s),assertCurrent:g}}export class CentralNativeResponse{options;constructor(e){this.options=e}async execute(e){const t=this.options;await t.verifier.refresh();const r=e.delivery.message.payload;if("runtime_rpc_request"!==e.delivery.message.type||"completed"!==e.delivery.message.state||e.delivery.message.message_id!==r.requestMessageId||e.delivery.message.channel_id!==r.operationId)throw new Error("central native original delivery is invalid");const i=e.delivery.executionGrant,{binding:n,params:a,assertCurrent:s}=verifyCentralNativeIntent({request:r,executionGrant:i,verifier:t.verifier,lease:e.lease,getLease:t.getLease});e.onVerified?.({operationId:r.operationId,requestMessageId:r.requestMessageId,requestHash:r.requestHash,dispatchEpoch:r.dispatchEpoch,method:"session/prompt"}),t.bindCredential(n,i,r.requestHash,{requestMessageId:r.requestMessageId,verifier:t.verifier});const o=await t.pending.terminal(n);if(o){const e=o.request??{binding:o.binding,idempotencyKey:o.receipt.idempotency_key,payloadDigest:o.receipt.payload_sha256},{context:r,...i}=e.binding,{context:a,...c}=n;if(!isDeepStrictEqual(i,c)||r.tenant_ref!==a.tenant_ref||r.scope_ref!==a.scope_ref)throw new Error("central terminal original binding changed");const d=await t.store.receipt({...e,binding:n});if(s(),!d?.terminal||o.receipt&&!isDeepStrictEqual(d,o.receipt))throw new Error("central terminal outcome is unknown");return o.request&&(assertCentralNativeReceipt(o.request,d),await t.pending.complete(o.request,d)),await this.settleJournal(n.operationId),d}const c=await t.store.load(n);if(c.terminal?.response_id===n.responseId)throw new Error("original Response is already terminal; reconcile its original receipt before native execution");const d="completed"!==c.terminal?.status;if(s(),e.signal.aborted)throw new Error("central native execution stopped before dispatch; original owner stop reconciliation is required");let p=await t.journal.get(n.operationId);if(p&&("session.prompt"!==p.command||p.paramsHash!==r.paramsHash||p.runtimeEpoch!==e.lease.runtimeEpoch||"prepared"!==p.phase))throw new Error("central native execution already started; original terminal reconciliation is required");if(p=await t.journal.acceptMessageRequest({operationId:n.operationId,command:"session.prompt",paramsHash:r.paramsHash,runtimeEpoch:e.lease.runtimeEpoch,requestMessageId:r.requestMessageId,requestHash:r.requestHash}),s(),await t.journal.transition({operationId:n.operationId,expectedRevision:p.revision,phase:"started"}),e.signal.aborted)throw new Error("central native execution stopped before dispatch; original owner stop reconciliation is required");const l=await t.host.run({params:structuredClone(a),binding:n,requestMessageId:r.requestMessageId,signal:e.signal,assertCurrent:s});s();const m=await t.pending.terminal(n);if(!m?.receipt||!m.receipt.terminal||m.receipt.terminal.status!==l.status)throw new Error("native owner did not confirm its original atomic suffix/terminal transaction");const u=await t.store.receipt({binding:n,idempotencyKey:m.receipt.idempotency_key,payloadDigest:m.receipt.payload_sha256});if(s(),!u||!isDeepStrictEqual(u,m.receipt))throw new Error("original native terminal receipt is unavailable");return await this.settleJournal(n.operationId),"completed"===l.status&&d&&t.recordGeneratedTitle?.({binding:n,question:promptText(a),answer:l.finalText??""}),u}async settleJournal(e){let t=await this.options.journal.get(e);"started"===t?.phase&&(t=await this.options.journal.transition({operationId:e,expectedRevision:t.revision,phase:"effect_committed"})),"effect_committed"===t?.phase&&await this.options.journal.transition({operationId:e,expectedRevision:t.revision,phase:"projection_committed"})}}
|
|
1
|
+
import{createHash}from"node:crypto";import{isDeepStrictEqual}from"node:util";import{CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN,RUNTIME_HASH_DOMAINS}from"@beeos-ai/beeos-types/runtime";import{assertCentralNativeReceipt}from"./central-native-context-engine.js";import{runtimeMessageHash}from"./runtime-message-channel-contract.js";const object=e=>null!==e&&"object"==typeof e&&!Array.isArray(e),promptText=e=>{if("string"==typeof e.text&&e.text.length>0)return e.text;return(Array.isArray(e.parts)?e.parts:[]).filter(object).filter(e=>"text"===e.type&&"string"==typeof e.text).map(e=>e.text).join("\n")},text=e=>"string"==typeof e&&e.length>0,decimal=e=>"string"==typeof e&&/^(0|[1-9][0-9]*)$/.test(e),associationKeys=["context","session_id","history_generation","branch_id","writer","response_id","attempt_id","watermark","config_pin","persona_ref"],GRANT_CLOCK_SKEW_SECONDS=30,grantInvalid=e=>new Error(`central native original signed intent is invalid: ${e}`),grantDecodeReason=e=>{const t=e.split(".")[1];if(!t)return"grant_signature_invalid";let r;try{const e=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));if(!object(e))return"grant_signature_invalid";r=e}catch{return"grant_signature_invalid"}return r.iss!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.issuer?"grant_issuer_mismatch":r.aud!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.audience?"grant_audience_mismatch":r.purpose!==CLOUD_RUNTIME_EXECUTION_GRANT_DOMAIN.purpose?"grant_binding_mismatch":"grant_signature_invalid"};export function isCentralNativeResponse(e){const t=e.message?.payload,r=t?.request;return 2===t?.schemaVersion&&"session/prompt"===t.method&&object(r)&&object(r.params)&&Object.hasOwn(r.params,"centralChat")}const verifiedIntents=new WeakMap;export function retainedCentralNativeRequest(e){const t=verifiedIntents.get(e);return t&&isDeepStrictEqual(e.request,t)?structuredClone(t):null}export function verifyCentralNativeIntent(e){const t=e.executionGrant,r=e.request;if(!t)throw grantInvalid("grant_binding_mismatch");const a=e.verifier.verifyAndDecodeGrant(t);if(!a)throw grantInvalid(grantDecodeReason(t));const n=a.claims,i=object(r.request)?r.request:{},s=object(i.params)?i.params:{},o=object(s.centralChat)?s.centralChat:{},c=object(r.command)?r.command:{},d=object(c.context)?c.context:{},p=object(d.conversation)?d.conversation:{},l=object(o.context)?o.context:{},u=object(o.writer)?o.writer:{},h=object(o.config_pin)?o.config_pin:{},m=h.credential_set_ref,g=()=>{const t=e.getLease();if(!t||t.instanceId!==e.lease.instanceId||t.leaseId!==e.lease.leaseId||t.handlerIdentity!==e.lease.handlerIdentity||t.runtimeEpoch!==e.lease.runtimeEpoch||!Number.isFinite(Date.parse(t.leaseExpiresAt))||Date.parse(t.leaseExpiresAt)<=Date.now())throw new Error("central native execution is fenced")},_=Math.floor(Date.now()/1e3);if(!Number.isSafeInteger(n.iat)||!Number.isSafeInteger(n.exp)||n.exp<=n.iat||n.exp-n.iat>60)throw grantInvalid("grant_binding_mismatch");if(n.exp+30<_)throw grantInvalid("grant_expired");if(n.iat>_+30)throw grantInvalid("grant_iat_future");if(!object(r)||2!==r.schemaVersion||"session/prompt"!==r.method||!Object.hasOwn(s,"centralChat")||"string"!=typeof r.executionGrantHash||!/^[a-f0-9]{64}$/.test(r.executionGrantHash)||"cloud"!==r.authorityRealm||!object(r.cloudSubject)||r.cloudSubject.instanceId!==e.lease.instanceId||!isDeepStrictEqual(r.cloudSubject,n.cloudSubject)||r.instanceId!==e.lease.instanceId||r.leaseId!==e.lease.leaseId||r.runtimeHandlerIdentity!==e.lease.handlerIdentity||r.dispatchEpoch!==e.lease.runtimeEpoch||"cloud"!==n.authorityRealm||"session/prompt"!==n.method||"conversation"!==n.scope||"start"!==n.executionMode||n.platformConversationId!==o.session_id||n.historyGeneration!==o.history_generation||n.platformAgentId!==s.platformAgentId||!text(n.runtimeAgentUid)||s.conversationId!==o.session_id||"conversation"!==d.scope||p.runtimeConversationUid!==o.session_id||p.runtimeSessionKey!==o.session_id||d.historyGeneration!==o.history_generation||d.operationId!==r.operationId||d.runtimeInstanceUid!==r.instanceId||d.dispatchEpoch!==r.dispatchEpoch||d.paramsHash!==r.paramsHash||!isDeepStrictEqual(n.command,c)||n.sub!==e.lease.handlerIdentity||n.handlerIdentity!==e.lease.handlerIdentity||["operationId","requestMessageId","instanceId","leaseId","dispatchEpoch","requestHash","paramsHash","commandHash","idempotencyKeyHash"].some(e=>!text(r[e])||n[e]!==r[e])||"2.0"!==i.jsonrpc||"session/prompt"!==i.method||"session.prompt"!==c.name||!text(s.runtimeRunId)||s.taskId!==r.operationId||s.taskRequestMessageId!==r.requestMessageId||runtimeMessageHash(RUNTIME_HASH_DOMAINS.request,i)!==r.requestHash||runtimeMessageHash(RUNTIME_HASH_DOMAINS.params,{method:r.method,params:s})!==r.paramsHash||runtimeMessageHash(RUNTIME_HASH_DOMAINS.command,{command:c})!==r.commandHash||![o.session_id,o.history_generation,o.branch_id,o.response_id,o.attempt_id,l.tenant_ref,l.scope_ref,l.request_id,u.writer_id,u.writer_epoch].every(text)||!Number.isSafeInteger(l.authorization_revision)||l.authorization_revision<1||!Number.isSafeInteger(l.erasure_epoch)||l.erasure_epoch<0||!decimal(o.history_generation)||!decimal(o.watermark)||!decimal(u.writer_epoch)||"0"===u.writer_epoch||Object.keys(o).length!==associationKeys.length||!associationKeys.every(e=>Object.hasOwn(o,e))||4!==Object.keys(h).length||h.agent_id!==s.platformAgentId||!text(h.revision)||"string"!=typeof h.content_sha256||!/^[a-f0-9]{64}$/.test(h.content_sha256)||null!==m&&(!object(m)||2!==Object.keys(m).length||!text(m.set_id)||!Number.isSafeInteger(m.version)||m.version<1)||null!==o.persona_ref&&(!object(o.persona_ref)||2!==Object.keys(o.persona_ref).length||!text(o.persona_ref.persona_id)||!text(o.persona_ref.revision)))throw grantInvalid("grant_binding_mismatch");g();const I={sessionId:o.session_id,historyGeneration:o.history_generation,branchId:o.branch_id,responseId:o.response_id,attemptId:o.attempt_id,operationId:r.operationId,context:l,writer:u},f={request:structuredClone(r),binding:I,params:structuredClone(s),assertCurrent:g};return verifiedIntents.set(f,structuredClone(r)),f}export class CentralNativeResponse{options;constructor(e){this.options=e}async execute(e){const t=this.options;await t.verifier.refresh();const r=e.delivery.message.payload;if("runtime_rpc_request"!==e.delivery.message.type||"completed"!==e.delivery.message.state||e.delivery.message.message_id!==r.requestMessageId||e.delivery.message.channel_id!==r.operationId)throw new Error("central native original delivery is invalid");const a=e.delivery.executionGrant,n=verifyCentralNativeIntent({request:r,executionGrant:a,verifier:t.verifier,lease:e.lease,getLease:t.getLease}),{binding:i,params:s,assertCurrent:o}=n;e.onVerified?.({operationId:r.operationId,requestMessageId:r.requestMessageId,requestHash:r.requestHash,dispatchEpoch:r.dispatchEpoch,method:"session/prompt"}),t.bindCredential(i,a,r.requestHash,{requestMessageId:r.requestMessageId,verifier:t.verifier});const c=await t.pending.terminal(i);if(c){const e=c.request??{binding:c.binding,idempotencyKey:c.receipt.idempotency_key,payloadDigest:c.receipt.payload_sha256},{context:r,...a}=e.binding,{context:n,...s}=i;if(!isDeepStrictEqual(a,s)||r.tenant_ref!==n.tenant_ref||r.scope_ref!==n.scope_ref)throw new Error("central terminal original binding changed");const d=await t.store.receipt({...e,binding:i});if(o(),!d?.terminal||c.receipt&&!isDeepStrictEqual(d,c.receipt))throw new Error("central terminal outcome is unknown");return c.request&&(assertCentralNativeReceipt(c.request,d),await t.pending.complete(c.request,d)),await this.settleJournal(i.operationId),d}const d=await t.store.load(i);if(d.terminal?.response_id===i.responseId)throw new Error("original Response is already terminal; reconcile its original receipt before native execution");const p="completed"!==d.terminal?.status;if(o(),e.signal.aborted)throw new Error("central native execution stopped before dispatch; original owner stop reconciliation is required");let l=await t.journal.get(i.operationId);if(l&&("session.prompt"!==l.command||l.paramsHash!==r.paramsHash||l.runtimeEpoch!==e.lease.runtimeEpoch||"prepared"!==l.phase))throw new Error("central native execution already started; original terminal reconciliation is required");l=await t.journal.acceptMessageRequest({operationId:i.operationId,command:"session.prompt",paramsHash:r.paramsHash,runtimeEpoch:e.lease.runtimeEpoch,requestMessageId:r.requestMessageId,requestHash:r.requestHash}),o();const u={operationId:i.operationId,lease:t.getLease(),currentCentralIntent:n},h=await t.channel.history(u);if(o(),"found"!==h.status||h.snapshot.terminal||h.snapshot.cancelRequested)throw new Error("central native start history is unavailable or closed");let m=h.snapshot.started;if(!m){if(e.signal.aborted)throw new Error("central native execution stopped before dispatch; original owner stop reconciliation is required");m=(await t.channel.append({...u,lease:t.getLease(),executionGrant:a,type:"runtime_operation_started",payload:{schemaVersion:1,operationId:i.operationId,requestMessageId:r.requestMessageId,requestHash:r.requestHash,dispatchEpoch:e.lease.runtimeEpoch,method:"session/prompt",executionGrantHash:createHash("sha256").update(a).digest("hex"),handlerIdentity:e.lease.handlerIdentity,executionMode:"start",claimedAt:l.updatedAt}})).message}const g=m.payload;if("runtime_operation_started"!==m.type||m.publisher_id!==e.lease.handlerIdentity||g.handlerIdentity!==e.lease.handlerIdentity||"start"!==g.executionMode||g.claimedAt!==l.updatedAt||"string"!=typeof g.executionGrantHash||!/^[a-f0-9]{64}$/.test(g.executionGrantHash))throw new Error("central native Started does not match the prepared local execution");if(o(),await t.journal.transition({operationId:i.operationId,expectedRevision:l.revision,phase:"started"}),e.signal.aborted)throw new Error("central native execution stopped before dispatch; original owner stop reconciliation is required");const _=await t.host.run({params:structuredClone(s),binding:i,requestMessageId:r.requestMessageId,signal:e.signal,assertCurrent:o});o();const I=await t.pending.terminal(i);if(!I?.receipt||!I.receipt.terminal||I.receipt.terminal.status!==_.status)throw new Error("native owner did not confirm its original atomic suffix/terminal transaction");const f=await t.store.receipt({binding:i,idempotencyKey:I.receipt.idempotency_key,payloadDigest:I.receipt.payload_sha256});if(o(),!f||!isDeepStrictEqual(f,I.receipt))throw new Error("original native terminal receipt is unavailable");return await this.settleJournal(i.operationId),"completed"===_.status&&p&&t.recordGeneratedTitle?.({binding:i,question:promptText(s),answer:_.finalText??""}),f}async settleJournal(e){let t=await this.options.journal.get(e);"started"===t?.phase&&(t=await this.options.journal.transition({operationId:e,expectedRevision:t.revision,phase:"effect_committed"})),"effect_committed"===t?.phase&&await this.options.journal.transition({operationId:e,expectedRevision:t.revision,phase:"projection_committed"})}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{RUNTIME_HASH_DOMAINS}from"@beeos-ai/beeos-types/runtime";import{HarnessProtocolError,RuntimeMessagePlane}from"@beeos-ai/cloud-harness-sdk";import{isDeepStrictEqual}from"node:util";import{runtimeLeaseHttp}from"./message-service-runtime-authenticated-fetch.js";import{retainedVerifiedNativePrompt}from"./native-prompt-authority.js";import{runtimeMessageHash,semanticEqual,validateRuntimeCancelEnvelope,validateRuntimeRequestEnvelope}from"./runtime-message-channel-contract.js";export class RuntimeMessageChannelProtocolError extends Error{status;code;constructor(e,t,r){super(e),this.status=t,this.code=r,this.name="RuntimeMessageChannelProtocolError"}}export class MessageServiceRuntimeMessageChannel{options;plane;constructor(e){if(this.options=e,!e.scopedDeliveryKey)throw new Error("Message runtime delivery credential is required");this.plane=new RuntimeMessagePlane(runtimeLeaseHttp(e.serviceUrl,(t,r)=>e.transport.fetchBounded(t,r)))}async read(e){const t=await this.invoke(()=>this.plane.readDeliveries(this.credential(e.lease),{maxCount:e.maxCount,blockMs:e.blockMs},e.signal),"runtime delivery read failed");if(!record(t)||"deliveries"!==t.status||!Array.isArray(t.deliveries)||t.deliveries.length>e.maxCount||!t.deliveries.every(isDelivery)||new Set(t.deliveries.map(e=>e.deliveryId)).size!==t.deliveries.length)throw new RuntimeMessageChannelProtocolError("Message Service returned invalid runtime deliveries");return t.deliveries}async renew(e){const t=await this.invoke(()=>this.plane.renewDeliveries(this.credential(e.lease),e.deliveryIds),"runtime delivery renew failed");if(!(record(t)&&"renewed"===t.status&&strings(t.renewed)&&strings(t.notPending)&&exactIdPartition(e.deliveryIds,t.renewed,t.notPending)))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid delivery renewal");return{renewed:t.renewed,notPending:t.notPending}}async acknowledge(e){const t=await this.invoke(()=>this.plane.ackDeliveries(this.credential(e.lease),e.deliveryIds),"runtime delivery ack failed");if(!record(t)||"acknowledged"!==t.status||!strings(t.deliveryIds)||!sameIds(t.deliveryIds,e.deliveryIds))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid delivery acknowledgement")}async history(e){let t;try{t=await this.plane.operationHistory(this.credential(e.lease),e.operationId)}catch(e){if(!(e instanceof HarnessProtocolError))throw e;if(404===e.status)return{status:"not_found"};if(410===e.status)return{status:"expired"};throw harnessFailure(e,"runtime history read failed")}if(!isHistory(t,e.operationId))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid operation history");return{status:"found",snapshot:t}}async append(e){const t=appendResult(await this.invoke(()=>this.plane.appendOperationMessage(this.credential(e.lease,e.executionGrant),e.operationId,{type:e.type,payload:e.payload}),"runtime message-channel append failed")),r="runtime_rpc_response"===e.type?e.payload.requestMessageId:void 0;if(t.message.channel_id!==e.operationId||t.message.type!==e.type||t.message.in_reply_to!==r||!semanticEqual(t.message.payload,e.payload))throw new RuntimeMessageChannelProtocolError("Message Service append response correlation mismatch");return t}credential(e,t){return{runtimeLeaseCredential:e.runtimeLeaseCredential,scopedDeliveryKey:this.options.scopedDeliveryKey,...t?{executionGrant:t}:{}}}async invoke(e,t){try{return await e()}catch(e){if(e instanceof HarnessProtocolError)throw harnessFailure(e,t);throw e}}}export function decodeRuntimeBrokerDelivery(e){if(!isDelivery(e))throw new RuntimeMessageChannelProtocolError("Message Service returned an invalid runtime delivery");return e}export function decodeRuntimeOperationHistory(e,t){if(!isHistory(e,t))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid operation history");return e}export function decodeNativePromptOperationHistory(e,t){const r=retainedVerifiedNativePrompt(t);if(!(r&&record(e)&&envelope(e.request)&&"runtime_rpc_request"===e.request.type&&void 0===e.request.in_reply_to&&e.request.message_id===r.request.requestMessageId&&e.request.channel_id===r.request.operationId&&isDeepStrictEqual(e.request.payload,r.request)&&isHistory(e,r.request.operationId,e.request)))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid native prompt operation history");if(void 0!==e.runBoundary&&!validNativeRunObservation(e.runBoundary,r))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid native run audit");return e}function validNativeRunObservation(e,t){if(!record(e))return!1;const r=t.params,n=t.request,o=["operationId","requestMessageId","requestHash","conversationId","runtimeRunId","taskRequestMessageId","replyMessageId","historyGeneration"];if(o.some(t=>"string"!=typeof e[t])||Object.keys(e).some(e=>![...o,"registration","finishedReceipt"].includes(e))||e.operationId!==n.operationId||e.requestMessageId!==n.requestMessageId||e.requestHash!==n.requestHash||e.conversationId!==r.conversationId||e.runtimeRunId!==r.runtimeRunId||e.taskRequestMessageId!==r.taskRequestMessageId||e.replyMessageId!==r.replyMessageId||e.historyGeneration!==t.historyGeneration)return!1;const i=(e,t)=>{if(!record(e)||e.activeRunRegistrationId!==r.taskId||!["active","finished"].includes(e.state)||t&&"finished"!==e.state||Object.keys(e).some(e=>!["activeRunRegistrationId","state","terminalState","source","replyState","replyStopReason","replyUpdatedAt","finishedAt"].includes(e)))return!1;if("active"===e.state)return 2===Object.keys(e).length;const n=e=>"string"==typeof e&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(e)&&Date.parse(e)>0,o=e=>{const t=e.match(/\.(\d{1,9})/)?.[1]??"";return 1000000n*BigInt(Date.parse(e))+BigInt(t.padEnd(9,"0").slice(3))};return["completed","failed","cancelled"].includes(e.terminalState)&&["runtime","recovery"].includes(e.source)&&["completed","failed","refused","cancelled"].includes(e.replyState)&&("refused"===e.replyState?"failed":e.replyState)===e.terminalState&&"string"==typeof e.replyStopReason&&e.replyStopReason.length>0&&n(e.replyUpdatedAt)&&n(e.finishedAt)&&o(e.finishedAt)>=o(e.replyUpdatedAt)};return(void 0===e.registration||i(e.registration,!1))&&(void 0===e.finishedReceipt||i(e.finishedReceipt,!0))}export function decodeRuntimeAppendMessage(e,t){if(!envelope(e))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid append result");const r="runtime_rpc_response"===t.type?t.payload.requestMessageId:void 0;if(e.channel_id!==t.operationId||e.type!==t.type||e.in_reply_to!==r||!semanticEqual(e.payload,t.payload))throw new RuntimeMessageChannelProtocolError("Message Service append response correlation mismatch");return e}function appendResult(e){if(!record(e)||"persisted"!==e.status||"created"!==e.disposition&&"reused"!==e.disposition||!envelope(e.message))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid append result");return{disposition:e.disposition,message:e.message}}function harnessFailure(e,t){let r;if(e.body)try{r=JSON.parse(e.body)}catch{r=void 0}const n=record(r)&&"string"==typeof r.code?r.code:void 0,o=record(r)&&"string"==typeof r.message?r.message:t;return new RuntimeMessageChannelProtocolError(`${o} (${e.status})`,e.status,n)}function record(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function strings(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}function sameIds(e,t){return e.length===t.length&&[...e].sort().every((e,r)=>e===[...t].sort()[r])}function exactIdPartition(e,...t){return new Set(e).size===e.length&&!t.some(e=>new Set(e).size!==e.length)&&sameIds(t.flat(),e)}function envelope(e){return!!record(e)&&("string"==typeof e.message_id&&Number.isInteger(e.offset)&&e.offset>=1&&"string"==typeof e.channel_id&&(void 0===e.in_reply_to||"string"==typeof e.in_reply_to)&&["runtime_rpc_request","runtime_operation_started","runtime_operation_progress","runtime_effect_committed","runtime_projection_pending","runtime_projection_synced","runtime_projection_blocked","runtime_rpc_response","runtime_operation_cancel_requested"].includes(e.type)&&record(e.payload)&&"string"==typeof e.publisher_id&&"string"==typeof e.idempotency_key&&"string"==typeof e.created_at&&"completed"===e.state)}function isDelivery(e){return record(e)&&"string"==typeof e.deliveryId&&"boolean"==typeof e.redelivered&&Number.isInteger(e.idleMs)&&e.idleMs>=0&&envelope(e.message)&&(void 0===e.executionGrant||"string"==typeof e.executionGrant&&/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e.executionGrant))&&["runtime_rpc_request","runtime_operation_cancel_requested"].includes(e.message.type)}function isHistory(e,t,r){if(!record(e))return!1;if(!(1===e.schemaVersion&&"string"==typeof e.operationId&&e.operationId===t&&"string"==typeof e.requestMessageId&&"string"==typeof e.requestHash&&["queued","running","runtime_committed","projection_pending","projection_blocked","succeeded","failed","cancelled","expired","outcome_unknown"].includes(e.status)&&["","committed"].includes(e.effectState)&&"boolean"==typeof e.terminal&&["none","final_message","deadline"].includes(e.terminalSource)&&"boolean"==typeof e.cancelRequested&&["","reserved","pending","synced","blocked","not_applicable"].includes(e.projectionState)&&Array.isArray(e.messages)&&e.messages.every(envelope)&&Number.isInteger(e.latestOffset)&&!(e.latestOffset<1)))return!1;const n=r?{ok:!0,envelope:r}:validateRuntimeRequestEnvelope(e.request);if(!n.ok||e.request.channel_id!==e.operationId||n.envelope.payload.operationId!==e.operationId||n.envelope.payload.requestMessageId!==e.requestMessageId||n.envelope.payload.requestHash!==e.requestHash)return!1;const o=n.envelope.payload;if(void 0!==e.started&&!correlatedEnvelope(e.started,"runtime_operation_started",o,["schemaVersion","operationId","requestMessageId","requestHash","executionGrantHash","handlerIdentity","dispatchEpoch","method","executionMode","claimedAt"]))return!1;if(void 0!==e.latestProgress&&!correlatedEnvelope(e.latestProgress,"runtime_operation_progress",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","phase","progress"]))return!1;if(!(void 0===e.effectCommitted||correlatedEnvelope(e.effectCommitted,"runtime_effect_committed",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","effectRecord","effectRecordHash","committedAt"])&&validEffectCommitted(e.effectCommitted.payload,o)))return!1;if(void 0!==e.projectionPending&&!correlatedEnvelope(e.projectionPending,"runtime_projection_pending",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision"]))return!1;if(void 0!==e.projectionSynced&&!correlatedEnvelope(e.projectionSynced,"runtime_projection_synced",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision"]))return!1;if(void 0!==e.projectionBlocked&&!correlatedEnvelope(e.projectionBlocked,"runtime_projection_blocked",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision","errorCode"]))return!1;if(void 0!==e.cancel){const t=validateRuntimeCancelEnvelope(e.cancel);if(!t.ok||!sameCorrelation(t.envelope,o))return!1}if(void 0!==e.final&&!correlatedEnvelope(e.final,"runtime_rpc_response",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","outcome","response","completedAt"]))return!1;const i=e.messages;if(0===i.length||e.latestOffset!==i.length||i.some((t,r)=>t.offset!==r+1||t.channel_id!==e.operationId)||!semanticEqual(i[0],e.request)||!historyMessagesMatchSummaries(i,e)||!projectionStateMatches(e))return!1;if(e.terminal!==("none"!==e.terminalSource)||"committed"===e.effectState!=(void 0!==e.effectCommitted)||void 0!==e.effectCommitted&&void 0===e.started||"queued"===e.status&&(void 0!==e.started||void 0!==e.effectCommitted)||["running","runtime_committed","projection_pending","projection_blocked"].includes(e.status)&&void 0===e.started)return!1;if("none"===e.terminalSource)return void 0===e.final&&["queued","running","runtime_committed","projection_pending","projection_blocked"].includes(e.status);if("deadline"===e.terminalSource)return void 0===e.final&&(void 0===e.started?"expired"===e.status:"outcome_unknown"===e.status);if(!envelope(e.final))return!1;const s=e.final.payload.outcome,a="succeeded"===s?"succeeded":"cancelled"===s?"cancelled":"expired"===s?"expired":"outcome_unknown"===s?"outcome_unknown":"projection_blocked"===s?"projection_blocked":"failed"===s?"failed":void 0;return e.status===a}function validEffectCommitted(e,t){const r=e.effectRecord;return!!(record(r)&&1===r.schemaVersion&&r.operationId===t.operationId&&r.method===t.method&&"string"==typeof r.coreResultRef&&0!==r.coreResultRef.length&&"string"==typeof r.coreResultHash&&/^[0-9a-f]{64}$/.test(r.coreResultHash)&&(void 0===r.projectionRevision||"string"==typeof r.projectionRevision&&/^(0|[1-9][0-9]*)$/.test(r.projectionRevision))&&"string"==typeof e.effectRecordHash&&/^[0-9a-f]{64}$/.test(e.effectRecordHash)&&runtimeMessageHash(RUNTIME_HASH_DOMAINS.effectRecord,r)===e.effectRecordHash&&"string"==typeof e.committedAt&&Number.isFinite(Date.parse(e.committedAt)))}function projectionStateMatches(e){const t=e.effectCommitted?.payload?.effectRecord?.projectionRevision,r="deadline"===e.terminalSource,n=e=>record(e)&&record(e.payload)&&e.payload.revision===t;switch(e.projectionState){case"":return void 0===e.effectCommitted&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||["queued","running","succeeded","failed","cancelled","expired","outcome_unknown"].includes(e.status));case"not_applicable":return void 0!==e.effectCommitted&&void 0===t&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||["runtime_committed","succeeded","outcome_unknown"].includes(e.status));case"reserved":return void 0!==e.effectCommitted&&void 0!==t&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||"runtime_committed"===e.status);case"pending":return void 0!==t&&n(e.projectionPending)&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||"projection_pending"===e.status);case"synced":return void 0!==t&&n(e.projectionPending)&&n(e.projectionSynced)&&void 0===e.projectionBlocked&&(r||["runtime_committed","succeeded"].includes(e.status));case"blocked":return void 0!==t&&n(e.projectionPending)&&void 0===e.projectionSynced&&n(e.projectionBlocked)&&(r||"projection_blocked"===e.status);default:return!1}}function historyMessagesMatchSummaries(e,t){const r=t=>e.filter(e=>e.type===t),n=(e,t,n=1)=>{const o=r(e);return o.length<=n&&(void 0===t?0===o.length:o.length>0&&semanticEqual(t,o.at(-1)))};if(!(n("runtime_rpc_request",t.request)&&n("runtime_operation_started",t.started)&&n("runtime_effect_committed",t.effectCommitted)&&n("runtime_projection_pending",t.projectionPending)&&n("runtime_projection_synced",t.projectionSynced)&&n("runtime_projection_blocked",t.projectionBlocked)&&n("runtime_operation_cancel_requested",t.cancel)&&n("runtime_rpc_response",t.final)))return!1;const o=r("runtime_operation_progress");if(void 0===t.latestProgress?0!==o.length:0===o.length||!semanticEqual(t.latestProgress,o.at(-1)))return!1;if(t.cancelRequested!==(void 0!==t.cancel))return!1;const i=e.findIndex(e=>"runtime_rpc_response"===e.type);return-1===i||i===e.length-1}function correlatedEnvelope(e,t,r,n){const o="runtime_rpc_response"===t?r.requestMessageId:void 0;return!(!envelope(e)||e.type!==t||!hasKeys(e.payload,n)||e.in_reply_to!==o)&&sameCorrelation(e,r)}function sameCorrelation(e,t){const r=e.payload;return e.channel_id===t.operationId&&r.operationId===t.operationId&&r.requestMessageId===t.requestMessageId&&r.requestHash===t.requestHash&&r.dispatchEpoch===t.dispatchEpoch&&r.method===t.method}function hasKeys(e,t){return t.every(t=>void 0!==e[t])}
|
|
1
|
+
import{retainedCentralNativeRequest}from"./central-native-response.js";import{RUNTIME_HASH_DOMAINS}from"@beeos-ai/beeos-types/runtime";import{HarnessProtocolError,RuntimeMessagePlane}from"@beeos-ai/cloud-harness-sdk";import{isDeepStrictEqual}from"node:util";import{runtimeLeaseHttp}from"./message-service-runtime-authenticated-fetch.js";import{retainedVerifiedNativePrompt}from"./native-prompt-authority.js";import{runtimeMessageHash,semanticEqual,validateRuntimeCancelEnvelope,validateRuntimeRequestEnvelope}from"./runtime-message-channel-contract.js";export class RuntimeMessageChannelProtocolError extends Error{status;code;constructor(e,t,r){super(e),this.status=t,this.code=r,this.name="RuntimeMessageChannelProtocolError"}}export class MessageServiceRuntimeMessageChannel{options;plane;constructor(e){if(this.options=e,!e.scopedDeliveryKey)throw new Error("Message runtime delivery credential is required");this.plane=new RuntimeMessagePlane(runtimeLeaseHttp(e.serviceUrl,(t,r)=>e.transport.fetchBounded(t,r)))}async read(e){const t=await this.invoke(()=>this.plane.readDeliveries(this.credential(e.lease),{maxCount:e.maxCount,blockMs:e.blockMs},e.signal),"runtime delivery read failed");if(!record(t)||"deliveries"!==t.status||!Array.isArray(t.deliveries)||t.deliveries.length>e.maxCount||!t.deliveries.every(isDelivery)||new Set(t.deliveries.map(e=>e.deliveryId)).size!==t.deliveries.length)throw new RuntimeMessageChannelProtocolError("Message Service returned invalid runtime deliveries");return t.deliveries}async renew(e){const t=await this.invoke(()=>this.plane.renewDeliveries(this.credential(e.lease),e.deliveryIds),"runtime delivery renew failed");if(!(record(t)&&"renewed"===t.status&&strings(t.renewed)&&strings(t.notPending)&&exactIdPartition(e.deliveryIds,t.renewed,t.notPending)))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid delivery renewal");return{renewed:t.renewed,notPending:t.notPending}}async acknowledge(e){const t=await this.invoke(()=>this.plane.ackDeliveries(this.credential(e.lease),e.deliveryIds),"runtime delivery ack failed");if(!record(t)||"acknowledged"!==t.status||!strings(t.deliveryIds)||!sameIds(t.deliveryIds,e.deliveryIds))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid delivery acknowledgement")}async history(e){let t;try{t=await this.plane.operationHistory(this.credential(e.lease),e.operationId)}catch(e){if(!(e instanceof HarnessProtocolError))throw e;if(404===e.status)return{status:"not_found"};if(410===e.status)return{status:"expired"};throw harnessFailure(e,"runtime history read failed")}if(!isHistory(t,e.operationId))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid operation history");return{status:"found",snapshot:t}}async append(e){const t=appendResult(await this.invoke(()=>this.plane.appendOperationMessage(this.credential(e.lease,e.executionGrant),e.operationId,{type:e.type,payload:e.payload}),"runtime message-channel append failed")),r="runtime_rpc_response"===e.type?e.payload.requestMessageId:void 0;if(t.message.channel_id!==e.operationId||t.message.type!==e.type||t.message.in_reply_to!==r||!semanticEqual(t.message.payload,e.payload))throw new RuntimeMessageChannelProtocolError("Message Service append response correlation mismatch");return t}credential(e,t){return{runtimeLeaseCredential:e.runtimeLeaseCredential,scopedDeliveryKey:this.options.scopedDeliveryKey,...t?{executionGrant:t}:{}}}async invoke(e,t){try{return await e()}catch(e){if(e instanceof HarnessProtocolError)throw harnessFailure(e,t);throw e}}}export function decodeRuntimeBrokerDelivery(e){if(!isDelivery(e))throw new RuntimeMessageChannelProtocolError("Message Service returned an invalid runtime delivery");return e}export function decodeRuntimeOperationHistory(e,t){if(!isHistory(e,t))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid operation history");return e}export function decodeNativePromptOperationHistory(e,t){const r=retainedVerifiedNativePrompt(t);if(!(r&&record(e)&&envelope(e.request)&&"runtime_rpc_request"===e.request.type&&void 0===e.request.in_reply_to&&e.request.message_id===r.request.requestMessageId&&e.request.channel_id===r.request.operationId&&isDeepStrictEqual(e.request.payload,r.request)&&isHistory(e,r.request.operationId,e.request)))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid native prompt operation history");if(void 0!==e.runBoundary&&!validNativeRunObservation(e.runBoundary,r))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid native run audit");return e}export function decodeCentralNativeOperationHistory(e,t){const r=retainedCentralNativeRequest(t),n=record(e)&&envelope(e.request)?e.request.payload:null,o=e=>Object.fromEntries(Object.entries(e).filter(([e])=>!["executionGrantHash","claimDeadlineAt","createdAt"].includes(e)));if(!r||!record(e)||!envelope(e.request)||"runtime_rpc_request"!==e.request.type||void 0!==e.request.in_reply_to||e.request.message_id!==r.requestMessageId||e.request.channel_id!==r.operationId||!n||!isDeepStrictEqual(o(n),o(r))||"string"!=typeof n.executionGrantHash||!/^[a-f0-9]{64}$/.test(n.executionGrantHash)||![n.claimDeadlineAt,n.createdAt].every(e=>"string"==typeof e&&Number.isFinite(Date.parse(e)))||Date.parse(n.createdAt)>Date.parse(n.claimDeadlineAt)||Date.parse(n.claimDeadlineAt)>Date.parse(r.executionDeadlineAt)||void 0!==e.runBoundary||!isHistory(e,r.operationId,e.request))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid central native operation history");return e}function validNativeRunObservation(e,t){if(!record(e))return!1;const r=t.params,n=t.request,o=["operationId","requestMessageId","requestHash","conversationId","runtimeRunId","taskRequestMessageId","replyMessageId","historyGeneration"];if(o.some(t=>"string"!=typeof e[t])||Object.keys(e).some(e=>![...o,"registration","finishedReceipt"].includes(e))||e.operationId!==n.operationId||e.requestMessageId!==n.requestMessageId||e.requestHash!==n.requestHash||e.conversationId!==r.conversationId||e.runtimeRunId!==r.runtimeRunId||e.taskRequestMessageId!==r.taskRequestMessageId||e.replyMessageId!==r.replyMessageId||e.historyGeneration!==t.historyGeneration)return!1;const i=(e,t)=>{if(!record(e)||e.activeRunRegistrationId!==r.taskId||!["active","finished"].includes(e.state)||t&&"finished"!==e.state||Object.keys(e).some(e=>!["activeRunRegistrationId","state","terminalState","source","replyState","replyStopReason","replyUpdatedAt","finishedAt"].includes(e)))return!1;if("active"===e.state)return 2===Object.keys(e).length;const n=e=>"string"==typeof e&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(e)&&Date.parse(e)>0,o=e=>{const t=e.match(/\.(\d{1,9})/)?.[1]??"";return 1000000n*BigInt(Date.parse(e))+BigInt(t.padEnd(9,"0").slice(3))};return["completed","failed","cancelled"].includes(e.terminalState)&&["runtime","recovery"].includes(e.source)&&["completed","failed","refused","cancelled"].includes(e.replyState)&&("refused"===e.replyState?"failed":e.replyState)===e.terminalState&&"string"==typeof e.replyStopReason&&e.replyStopReason.length>0&&n(e.replyUpdatedAt)&&n(e.finishedAt)&&o(e.finishedAt)>=o(e.replyUpdatedAt)};return(void 0===e.registration||i(e.registration,!1))&&(void 0===e.finishedReceipt||i(e.finishedReceipt,!0))}export function decodeRuntimeAppendMessage(e,t){if(!envelope(e))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid append result");const r="runtime_rpc_response"===t.type?t.payload.requestMessageId:void 0;if(e.channel_id!==t.operationId||e.type!==t.type||e.in_reply_to!==r||!semanticEqual(e.payload,t.payload))throw new RuntimeMessageChannelProtocolError("Message Service append response correlation mismatch");return e}function appendResult(e){if(!record(e)||"persisted"!==e.status||"created"!==e.disposition&&"reused"!==e.disposition||!envelope(e.message))throw new RuntimeMessageChannelProtocolError("Message Service returned invalid append result");return{disposition:e.disposition,message:e.message}}function harnessFailure(e,t){let r;if(e.body)try{r=JSON.parse(e.body)}catch{r=void 0}const n=record(r)&&"string"==typeof r.code?r.code:void 0,o=record(r)&&"string"==typeof r.message?r.message:t;return new RuntimeMessageChannelProtocolError(`${o} (${e.status})`,e.status,n)}function record(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)}function strings(e){return Array.isArray(e)&&e.every(e=>"string"==typeof e)}function sameIds(e,t){return e.length===t.length&&[...e].sort().every((e,r)=>e===[...t].sort()[r])}function exactIdPartition(e,...t){return new Set(e).size===e.length&&!t.some(e=>new Set(e).size!==e.length)&&sameIds(t.flat(),e)}function envelope(e){return!!record(e)&&("string"==typeof e.message_id&&Number.isInteger(e.offset)&&e.offset>=1&&"string"==typeof e.channel_id&&(void 0===e.in_reply_to||"string"==typeof e.in_reply_to)&&["runtime_rpc_request","runtime_operation_started","runtime_operation_progress","runtime_effect_committed","runtime_projection_pending","runtime_projection_synced","runtime_projection_blocked","runtime_rpc_response","runtime_operation_cancel_requested"].includes(e.type)&&record(e.payload)&&"string"==typeof e.publisher_id&&"string"==typeof e.idempotency_key&&"string"==typeof e.created_at&&"completed"===e.state)}function isDelivery(e){return record(e)&&"string"==typeof e.deliveryId&&"boolean"==typeof e.redelivered&&Number.isInteger(e.idleMs)&&e.idleMs>=0&&envelope(e.message)&&(void 0===e.executionGrant||"string"==typeof e.executionGrant&&/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e.executionGrant))&&["runtime_rpc_request","runtime_operation_cancel_requested"].includes(e.message.type)}function isHistory(e,t,r){if(!record(e))return!1;if(!(1===e.schemaVersion&&"string"==typeof e.operationId&&e.operationId===t&&"string"==typeof e.requestMessageId&&"string"==typeof e.requestHash&&["queued","running","runtime_committed","projection_pending","projection_blocked","succeeded","failed","cancelled","expired","outcome_unknown"].includes(e.status)&&["","committed"].includes(e.effectState)&&"boolean"==typeof e.terminal&&["none","final_message","deadline"].includes(e.terminalSource)&&"boolean"==typeof e.cancelRequested&&["","reserved","pending","synced","blocked","not_applicable"].includes(e.projectionState)&&Array.isArray(e.messages)&&e.messages.every(envelope)&&Number.isInteger(e.latestOffset)&&!(e.latestOffset<1)))return!1;const n=r?{ok:!0,envelope:r}:validateRuntimeRequestEnvelope(e.request);if(!n.ok||e.request.channel_id!==e.operationId||n.envelope.payload.operationId!==e.operationId||n.envelope.payload.requestMessageId!==e.requestMessageId||n.envelope.payload.requestHash!==e.requestHash)return!1;const o=n.envelope.payload;if(void 0!==e.started&&!correlatedEnvelope(e.started,"runtime_operation_started",o,["schemaVersion","operationId","requestMessageId","requestHash","executionGrantHash","handlerIdentity","dispatchEpoch","method","executionMode","claimedAt"]))return!1;if(void 0!==e.latestProgress&&!correlatedEnvelope(e.latestProgress,"runtime_operation_progress",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","phase","progress"]))return!1;if(!(void 0===e.effectCommitted||correlatedEnvelope(e.effectCommitted,"runtime_effect_committed",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","effectRecord","effectRecordHash","committedAt"])&&validEffectCommitted(e.effectCommitted.payload,o)))return!1;if(void 0!==e.projectionPending&&!correlatedEnvelope(e.projectionPending,"runtime_projection_pending",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision"]))return!1;if(void 0!==e.projectionSynced&&!correlatedEnvelope(e.projectionSynced,"runtime_projection_synced",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision"]))return!1;if(void 0!==e.projectionBlocked&&!correlatedEnvelope(e.projectionBlocked,"runtime_projection_blocked",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","revision","errorCode"]))return!1;if(void 0!==e.cancel){const t=validateRuntimeCancelEnvelope(e.cancel);if(!t.ok||!sameCorrelation(t.envelope,o))return!1}if(void 0!==e.final&&!correlatedEnvelope(e.final,"runtime_rpc_response",o,["schemaVersion","operationId","requestMessageId","requestHash","dispatchEpoch","method","outcome","response","completedAt"]))return!1;const i=e.messages;if(0===i.length||e.latestOffset!==i.length||i.some((t,r)=>t.offset!==r+1||t.channel_id!==e.operationId)||!semanticEqual(i[0],e.request)||!historyMessagesMatchSummaries(i,e)||!projectionStateMatches(e))return!1;if(e.terminal!==("none"!==e.terminalSource)||"committed"===e.effectState!=(void 0!==e.effectCommitted)||void 0!==e.effectCommitted&&void 0===e.started||"queued"===e.status&&(void 0!==e.started||void 0!==e.effectCommitted)||["running","runtime_committed","projection_pending","projection_blocked"].includes(e.status)&&void 0===e.started)return!1;if("none"===e.terminalSource)return void 0===e.final&&["queued","running","runtime_committed","projection_pending","projection_blocked"].includes(e.status);if("deadline"===e.terminalSource)return void 0===e.final&&(void 0===e.started?"expired"===e.status:"outcome_unknown"===e.status);if(!envelope(e.final))return!1;const s=e.final.payload.outcome,a="succeeded"===s?"succeeded":"cancelled"===s?"cancelled":"expired"===s?"expired":"outcome_unknown"===s?"outcome_unknown":"projection_blocked"===s?"projection_blocked":"failed"===s?"failed":void 0;return e.status===a}function validEffectCommitted(e,t){const r=e.effectRecord;return!!(record(r)&&1===r.schemaVersion&&r.operationId===t.operationId&&r.method===t.method&&"string"==typeof r.coreResultRef&&0!==r.coreResultRef.length&&"string"==typeof r.coreResultHash&&/^[0-9a-f]{64}$/.test(r.coreResultHash)&&(void 0===r.projectionRevision||"string"==typeof r.projectionRevision&&/^(0|[1-9][0-9]*)$/.test(r.projectionRevision))&&"string"==typeof e.effectRecordHash&&/^[0-9a-f]{64}$/.test(e.effectRecordHash)&&runtimeMessageHash(RUNTIME_HASH_DOMAINS.effectRecord,r)===e.effectRecordHash&&"string"==typeof e.committedAt&&Number.isFinite(Date.parse(e.committedAt)))}function projectionStateMatches(e){const t=e.effectCommitted?.payload?.effectRecord?.projectionRevision,r="deadline"===e.terminalSource,n=e=>record(e)&&record(e.payload)&&e.payload.revision===t;switch(e.projectionState){case"":return void 0===e.effectCommitted&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||["queued","running","succeeded","failed","cancelled","expired","outcome_unknown"].includes(e.status));case"not_applicable":return void 0!==e.effectCommitted&&void 0===t&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||["runtime_committed","succeeded","outcome_unknown"].includes(e.status));case"reserved":return void 0!==e.effectCommitted&&void 0!==t&&void 0===e.projectionPending&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||"runtime_committed"===e.status);case"pending":return void 0!==t&&n(e.projectionPending)&&void 0===e.projectionSynced&&void 0===e.projectionBlocked&&(r||"projection_pending"===e.status);case"synced":return void 0!==t&&n(e.projectionPending)&&n(e.projectionSynced)&&void 0===e.projectionBlocked&&(r||["runtime_committed","succeeded"].includes(e.status));case"blocked":return void 0!==t&&n(e.projectionPending)&&void 0===e.projectionSynced&&n(e.projectionBlocked)&&(r||"projection_blocked"===e.status);default:return!1}}function historyMessagesMatchSummaries(e,t){const r=t=>e.filter(e=>e.type===t),n=(e,t,n=1)=>{const o=r(e);return o.length<=n&&(void 0===t?0===o.length:o.length>0&&semanticEqual(t,o.at(-1)))};if(!(n("runtime_rpc_request",t.request)&&n("runtime_operation_started",t.started)&&n("runtime_effect_committed",t.effectCommitted)&&n("runtime_projection_pending",t.projectionPending)&&n("runtime_projection_synced",t.projectionSynced)&&n("runtime_projection_blocked",t.projectionBlocked)&&n("runtime_operation_cancel_requested",t.cancel)&&n("runtime_rpc_response",t.final)))return!1;const o=r("runtime_operation_progress");if(void 0===t.latestProgress?0!==o.length:0===o.length||!semanticEqual(t.latestProgress,o.at(-1)))return!1;if(t.cancelRequested!==(void 0!==t.cancel))return!1;const i=e.findIndex(e=>"runtime_rpc_response"===e.type);return-1===i||i===e.length-1}function correlatedEnvelope(e,t,r,n){const o="runtime_rpc_response"===t?r.requestMessageId:void 0;return!(!envelope(e)||e.type!==t||!hasKeys(e.payload,n)||e.in_reply_to!==o)&&sameCorrelation(e,r)}function sameCorrelation(e,t){const r=e.payload;return e.channel_id===t.operationId&&r.operationId===t.operationId&&r.requestMessageId===t.requestMessageId&&r.requestHash===t.requestHash&&r.dispatchEpoch===t.dispatchEpoch&&r.method===t.method}function hasKeys(e,t){return t.every(t=>void 0!==e[t])}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CloudGatewayGrantJwksVerifier,GatewayGrantJwksVerifier}from"@beeos-ai/cloud-harness-sdk";import{MsRuntimeMessageChannelAdapter}from"./ms-runtime-message-channel-adapter.js";import{decodeRuntimeAppendMessage,decodeRuntimeBrokerDelivery,decodeRuntimeOperationHistory,decodeNativePromptOperationHistory,RuntimeMessageChannelProtocolError}from"./message-service-runtime-message-channel.js";import{isCanonicalSessionNewDelivery,SessionNewRuntimeDeliveryBridge}from"./session-new-runtime-delivery-bridge.js";import{NativeCloudPromptBridge}from"./native-cloud-prompt-bridge.js";import{CentralNativeResponse,isCentralNativeResponse}from"./central-native-response.js";export class MsRuntimeMessageChannelConsumerFactory{deps;constructor(e){if(this.deps=e,Boolean(e.client)===Boolean(e.runtimeDelivery))throw new Error("exactly one runtime delivery owner is required");if(e.runtimeDelivery&&!(e.verifier instanceof CloudGatewayGrantJwksVerifier))throw new Error("runtime delivery owner and grant realm differ")}async create(e){let t;const r=new SdkRuntimeMessageChannel(()=>{if(!t)throw new Error("SDK runtime delivery consumer is not attached");return t}),n=this.deps.centralPrompt&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?new CentralNativeResponse({...this.deps.centralPrompt,verifier:this.deps.verifier,journal:this.deps.journal,getLease:()=>e.getLease()}):void 0,i=new MsRuntimeMessageChannelAdapter(e.dispatcher,r,this.deps.verifier,this.deps.ports,this.deps.journal,()=>e.getLease(),{...this.deps.options,allowedMethods:this.deps.allowedMethods,...n?{centralPromptBridge:n}:{},...this.deps.nativePrompt&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?{nativePromptBridge:new NativeCloudPromptBridge({...this.deps.nativePrompt,verifier:this.deps.verifier,channel:r,journal:this.deps.journal,getLease:()=>e.getLease(),getLineage:()=>{const t=e.getBinding?.()??e.binding;return{journalStoreId:t.journalStoreId,journalGeneration:t.journalGeneration}}})}:{},journalStoreId:e.binding.journalStoreId,journalGeneration:e.binding.journalGeneration,...e.getBinding?{getJournalLineage:()=>{const t=e.getBinding();return{journalStoreId:t.journalStoreId,journalGeneration:t.journalGeneration}}}:{}}),s=this.deps.client&&this.deps.verifier instanceof GatewayGrantJwksVerifier?legacySessionNewConversationCreator(this.deps.client):this.deps.runtimeDelivery&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?this.deps.sessionNewConversation:void 0,o=s?new SessionNewRuntimeDeliveryBridge({conversations:s,consumer:()=>{if(!t)throw new Error("SDK runtime delivery consumer is not attached");return t},verifier:this.deps.verifier,getLease:()=>e.getLease(),createRuntimeSession:e.createRuntimeSession,poison:async(e,t,r)=>{await i.acceptPoisonDelivery(e,t,r)}}):void 0,a=this.deps.client?.methods??this.deps.runtimeDelivery;if(!a)throw new Error("runtime delivery owner is unavailable");return t=a.consume({onDelivery:async(t,r)=>{runtimeDeliveryTrace(t);let s="fence";try{const a=currentFencedLease(e,r.lease);s="decode";if(isCentralNativeResponse(t)&&!n)throw new Error("central native Response startup composition is unavailable");const d=t,l=this.deps.nativePrompt&&2===d.message?.payload?.schemaVersion&&"session/prompt"===d.message.payload.method?t:decodeRuntimeBrokerDelivery(t);if(s="dispatch",isCanonicalSessionNewDelivery(l))return o?void await o.acceptDelivery(l,a,r.signal):void await i.acceptPoisonDelivery(l,"cloud_session_new_unsupported",a);await i.acceptDelivery(l,a,r.signal)}catch(e){runtimeDeliveryError(e);throw e}},onError:this.deps.options.onDeliveryError,readCount:this.deps.options.readCount,blockMs:this.deps.options.blockMs,idleDelayMs:this.deps.options.idleDelayMs,renewIntervalMs:this.deps.options.renewIntervalMs}),i.attachExternalDeliveryOwner(t),i}}export class SdkRuntimeMessageChannel{consumer;constructor(e){this.consumer=e}async read(){throw new Error("MessageClient owns runtime delivery reads")}async renew(){throw new Error("MessageClient owns runtime delivery renewal")}async acknowledge(e){assertLeaseAvailable(e.lease),await this.consumer().acknowledge(e.deliveryIds)}async history(e){assertLeaseAvailable(e.lease);const t=await this.consumer().history(e.operationId);return"found"!==t.status?t:{status:"found",snapshot:this.decodeHistory(t.snapshot,e)}}async append(e){assertLeaseAvailable(e.lease);const t=await this.consumer().append(e.operationId,e.type,e.payload,e.executionGrant);if("created"===t.outcome||"duplicate"===t.outcome)return{disposition:"created"===t.outcome?"created":"reused",message:decodeRuntimeAppendMessage(t.message,e)};if(t.history){const r=
|
|
1
|
+
import{CloudGatewayGrantJwksVerifier,GatewayGrantJwksVerifier}from"@beeos-ai/cloud-harness-sdk";import{MsRuntimeMessageChannelAdapter}from"./ms-runtime-message-channel-adapter.js";import{decodeRuntimeAppendMessage,decodeRuntimeBrokerDelivery,decodeRuntimeOperationHistory,decodeNativePromptOperationHistory,decodeCentralNativeOperationHistory,RuntimeMessageChannelProtocolError}from"./message-service-runtime-message-channel.js";import{isCanonicalSessionNewDelivery,SessionNewRuntimeDeliveryBridge}from"./session-new-runtime-delivery-bridge.js";import{NativeCloudPromptBridge}from"./native-cloud-prompt-bridge.js";import{CentralNativeResponse,isCentralNativeResponse}from"./central-native-response.js";export class MsRuntimeMessageChannelConsumerFactory{deps;constructor(e){if(this.deps=e,Boolean(e.client)===Boolean(e.runtimeDelivery))throw new Error("exactly one runtime delivery owner is required");if(e.runtimeDelivery&&!(e.verifier instanceof CloudGatewayGrantJwksVerifier))throw new Error("runtime delivery owner and grant realm differ")}async create(e){let t;const r=new SdkRuntimeMessageChannel(()=>{if(!t)throw new Error("SDK runtime delivery consumer is not attached");return t}),n=this.deps.centralPrompt&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?new CentralNativeResponse({...this.deps.centralPrompt,verifier:this.deps.verifier,journal:this.deps.journal,channel:r,getLease:()=>e.getLease()}):void 0,i=new MsRuntimeMessageChannelAdapter(e.dispatcher,r,this.deps.verifier,this.deps.ports,this.deps.journal,()=>e.getLease(),{...this.deps.options,allowedMethods:this.deps.allowedMethods,...n?{centralPromptBridge:n}:{},...this.deps.nativePrompt&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?{nativePromptBridge:new NativeCloudPromptBridge({...this.deps.nativePrompt,verifier:this.deps.verifier,channel:r,journal:this.deps.journal,getLease:()=>e.getLease(),getLineage:()=>{const t=e.getBinding?.()??e.binding;return{journalStoreId:t.journalStoreId,journalGeneration:t.journalGeneration}}})}:{},journalStoreId:e.binding.journalStoreId,journalGeneration:e.binding.journalGeneration,...e.getBinding?{getJournalLineage:()=>{const t=e.getBinding();return{journalStoreId:t.journalStoreId,journalGeneration:t.journalGeneration}}}:{}}),s=this.deps.client&&this.deps.verifier instanceof GatewayGrantJwksVerifier?legacySessionNewConversationCreator(this.deps.client):this.deps.runtimeDelivery&&this.deps.verifier instanceof CloudGatewayGrantJwksVerifier?this.deps.sessionNewConversation:void 0,o=s?new SessionNewRuntimeDeliveryBridge({conversations:s,consumer:()=>{if(!t)throw new Error("SDK runtime delivery consumer is not attached");return t},verifier:this.deps.verifier,getLease:()=>e.getLease(),createRuntimeSession:e.createRuntimeSession,poison:async(e,t,r)=>{await i.acceptPoisonDelivery(e,t,r)}}):void 0,a=this.deps.client?.methods??this.deps.runtimeDelivery;if(!a)throw new Error("runtime delivery owner is unavailable");return t=a.consume({onDelivery:async(t,r)=>{runtimeDeliveryTrace(t);let s="fence";try{const a=currentFencedLease(e,r.lease);s="decode";if(isCentralNativeResponse(t)&&!n)throw new Error("central native Response startup composition is unavailable");const d=t,l=this.deps.nativePrompt&&2===d.message?.payload?.schemaVersion&&"session/prompt"===d.message.payload.method?t:decodeRuntimeBrokerDelivery(t);if(s="dispatch",isCanonicalSessionNewDelivery(l))return o?void await o.acceptDelivery(l,a,r.signal):void await i.acceptPoisonDelivery(l,"cloud_session_new_unsupported",a);await i.acceptDelivery(l,a,r.signal)}catch(e){runtimeDeliveryError(e);throw e}},onError:this.deps.options.onDeliveryError,readCount:this.deps.options.readCount,blockMs:this.deps.options.blockMs,idleDelayMs:this.deps.options.idleDelayMs,renewIntervalMs:this.deps.options.renewIntervalMs}),i.attachExternalDeliveryOwner(t),i}}export class SdkRuntimeMessageChannel{consumer;constructor(e){this.consumer=e}async read(){throw new Error("MessageClient owns runtime delivery reads")}async renew(){throw new Error("MessageClient owns runtime delivery renewal")}async acknowledge(e){assertLeaseAvailable(e.lease),await this.consumer().acknowledge(e.deliveryIds)}async history(e){assertLeaseAvailable(e.lease);const t=await this.consumer().history(e.operationId);return"found"!==t.status?t:{status:"found",snapshot:this.decodeHistory(t.snapshot,e)}}async append(e){assertLeaseAvailable(e.lease);const t=await this.consumer().append(e.operationId,e.type,e.payload,e.executionGrant);if("created"===t.outcome||"duplicate"===t.outcome)return{disposition:"created"===t.outcome?"created":"reused",message:decodeRuntimeAppendMessage(t.message,e)};if(t.history){const r=this.decodeHistory(t.history,e);if(e.currentCentralIntent&&(r.terminal||r.cancelRequested))throw new RuntimeMessageChannelProtocolError("central native start history is closed",409,"authority_rejected");const n=findReconciledMessage(r,e);if(n)return{disposition:"reused",message:n}}throw new RuntimeMessageChannelProtocolError("runtime append outcome is unknown after history reconcile",503,"OUTCOME_UNKNOWN")}decodeHistory(e,t){if(t.currentCentralIntent){if(t.currentCentralIntent.request.operationId!==t.operationId)throw new RuntimeMessageChannelProtocolError("central native history operation changed");return decodeCentralNativeOperationHistory(e,t.currentCentralIntent)}if(!t.currentNativePrompt)return decodeRuntimeOperationHistory(e,t.operationId);if(t.currentNativePrompt.request.operationId!==t.operationId)throw new RuntimeMessageChannelProtocolError("native history operation does not match current proof");return decodeNativePromptOperationHistory(e,t.currentNativePrompt)}}function currentFencedLease(e,t){const r=e.getLease(),n=e.getBinding?.()??e.binding;if(!r||r.instanceId!==t.instanceId||r.handlerIdentity!==t.handlerIdentity||r.runtimeEpoch!==t.runtimeEpoch||r.leaseId!==t.leaseId||n.journalStoreId!==t.journalStoreId||n.journalGeneration!==t.journalGeneration)throw new Error("runtime delivery lease fence changed");if(Date.parse(r.leaseExpiresAt)<=Date.now())throw new Error("runtime delivery lease expired");return r}function assertLeaseAvailable(e){if(!Number.isFinite(Date.parse(e.leaseExpiresAt))||Date.parse(e.leaseExpiresAt)<=Date.now())throw new Error("runtime delivery lease expired")}function legacySessionNewConversationCreator(e){return{async create(t){const r=t.platformAgentId.startsWith("agent:")?t.platformAgentId:`agent:${t.platformAgentId}`;return{conversationId:(await e.conversations.create({agentId:t.platformAgentId,participants:dedupe([t.runtimeInstanceId,r,t.callerIdentityId??""]),...t.title?{title:t.title}:{},metadata:{source:"session/new",runtimeSessionId:t.runtimeSessionId,runtimeSessionKey:t.runtimeSessionKey,runtimeInstanceId:t.runtimeInstanceId,runtimeEpoch:t.runtimeEpoch,platformAgentId:t.platformAgentId},idempotencyKey:t.operationId})).id}}}}function dedupe(e){return[...new Set(e.filter(e=>e.length>0))]}function safeRuntimeDeliveryId(e){return"string"==typeof e&&e.length>0&&e.length<=256&&!/[\u0000-\u001f\u007f]/.test(e)?JSON.stringify(e):JSON.stringify("unavailable")}function safeRuntimeDeliveryCode(e){return"string"==typeof e&&/^[A-Za-z0-9_.:-]{1,64}$/.test(e)?e:"unavailable"}function runtimeDeliveryTrace(e){const t=null!==e&&"object"==typeof e?e:{};return{channelId:safeRuntimeDeliveryId((null!==t.message&&"object"==typeof t.message?t.message:{}).channel_id),deliveryId:safeRuntimeDeliveryId(t.deliveryId)}}function runtimeDeliveryError(e){const t=null!==e&&"object"==typeof e?e:{};return{code:safeRuntimeDeliveryCode(t.code),status:"number"==typeof t.status&&Number.isInteger(t.status)&&t.status>=100&&t.status<=599?String(t.status):"unavailable"}}function findReconciledMessage(e,t){for(let r=e.messages.length-1;r>=0;r-=1)try{return decodeRuntimeAppendMessage(e.messages[r],t)}catch{}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beeos-claw",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.96",
|
|
4
4
|
"description": "OpenClaw plugin that bridges the BeeOS platform with the local OpenClaw Gateway, providing file transfer, ACP bridge, and observability.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BeeOS <dev@beeos.ai>",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"zod": "4.6.7",
|
|
94
94
|
"qs": "6.16.1"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "bd6b67b59ecf8110733d116b6221110088733fbd"
|
|
97
97
|
}
|