11// Qa Lab plugin module implements Crabline local-provider transport behavior.
22import fs from "node:fs/promises" ;
33import path from "node:path" ;
4- import { setTimeout as sleep } from "node:timers/promises" ;
54import {
65 startOpenClawCrablineAdapter ,
76 type OpenClawCrablineChannelDriverSelection ,
87 type OpenClawCrablineInbound ,
98 type StartedOpenClawCrablineAdapter ,
109} from "@openclaw/crabline" ;
1110import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts" ;
12- import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime" ;
1311import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime" ;
1412import {
1513 isRecord ,
@@ -23,10 +21,10 @@ import {
2321 resolveCrablineStateConversation ,
2422 resolveTelegramQaSenderId ,
2523} from "./crabline-provider-targets.js" ;
26- import { QaSuiteInfraError } from "./errors.js" ;
2724import { discardIgnoredResponseBody } from "./ignored-response-body.js" ;
2825import {
2926 QaStateBackedTransportAdapter ,
27+ waitForQaTransportAccountReady ,
3028 waitForQaTransportOutboundSequence ,
3129} from "./qa-transport.js" ;
3230import type {
@@ -164,64 +162,6 @@ function readTelegramLifecycleEvent(params: {
164162 } ;
165163}
166164
167- async function waitForCrablineReady ( params : {
168- accountId : string ;
169- channel : string ;
170- gateway : QaTransportGatewayClient ;
171- timeoutMs ?: number ;
172- pollIntervalMs ?: number ;
173- } ) {
174- const timeoutMs = params . timeoutMs ?? 45_000 ;
175- const pollIntervalMs = params . pollIntervalMs ?? 500 ;
176- const startedAt = Date . now ( ) ;
177- let lastAccountStatus = `no ${ params . channel } accounts reported` ;
178- let lastProbeError : string | null = null ;
179-
180- while ( Date . now ( ) - startedAt < timeoutMs ) {
181- try {
182- const payload = ( await params . gateway . call (
183- "channels.status" ,
184- { probe : false , timeoutMs : 2_000 } ,
185- { timeoutMs : 5_000 } ,
186- ) ) as {
187- channelAccounts ?: Record <
188- string ,
189- Array < {
190- accountId ?: string ;
191- running ?: boolean ;
192- restartPending ?: boolean ;
193- } >
194- > ;
195- } ;
196- const accounts = payload . channelAccounts ?. [ params . channel ] ?? [ ] ;
197- const account = accounts . find ( ( entry ) => entry . accountId === params . accountId ) ?? accounts [ 0 ] ;
198- lastProbeError = null ;
199- lastAccountStatus = account
200- ? JSON . stringify ( {
201- accountId : account . accountId ?? null ,
202- running : account . running ?? null ,
203- restartPending : account . restartPending ?? null ,
204- } )
205- : `no ${ params . channel } accounts reported` ;
206- if ( account ?. running && account . restartPending !== true ) {
207- return ;
208- }
209- } catch ( error ) {
210- lastProbeError = formatErrorMessage ( error ) ;
211- }
212- await sleep ( pollIntervalMs ) ;
213- }
214-
215- throw new QaSuiteInfraError (
216- "transport_ready_timeout" ,
217- [
218- `timed out after ${ timeoutMs } ms waiting for ${ params . channel } ready` ,
219- `last status: ${ lastAccountStatus } ` ,
220- ...( lastProbeError ? [ `last probe error: ${ lastProbeError } ` ] : [ ] ) ,
221- ] . join ( "; " ) ,
222- ) ;
223- }
224-
225165async function postCrablineInbound ( params : {
226166 adapter : StartedOpenClawCrablineAdapter ;
227167 providerInbound : OpenClawCrablineInbound ;
@@ -449,7 +389,7 @@ class QaCrablineTransport extends QaStateBackedTransportAdapter {
449389 timeoutMs ?: number ;
450390 pollIntervalMs ?: number ;
451391 } ) =>
452- waitForCrablineReady ( {
392+ waitForQaTransportAccountReady ( {
453393 ...params ,
454394 accountId : this . #adapter. accountId ,
455395 channel : this . #adapter. channel ,
0 commit comments