
























@@ -1,3 +1,4 @@
1+/** Auth probe planning and execution helpers for model diagnostics. */
12import crypto from "node:crypto";
23import fs from "node:fs/promises";
34import { normalizeUniqueStringEntries } from "@openclaw/normalization-core/string-normalization";
@@ -46,6 +47,7 @@ function loadEmbeddedRunnerModule() {
4647return embeddedRunnerModuleLoader.load();
4748}
484950+/** Normalized probe status bucket for auth/model diagnostics. */
4951export type AuthProbeStatus =
5052| "ok"
5153| "auth"
@@ -56,6 +58,7 @@ export type AuthProbeStatus =
5658| "unknown"
5759| "no_model";
586061+/** Reason code for probes that never reached a model call. */
5962export type AuthProbeReasonCode =
6063| "excluded_by_auth_order"
6164| "missing_credential"
@@ -65,6 +68,7 @@ export type AuthProbeReasonCode =
6568| "ineligible_profile"
6669| "no_model";
677071+/** Result for one profile/env/models.json auth probe target. */
6872export type AuthProbeResult = {
6973provider: string;
7074model?: string;
@@ -87,6 +91,7 @@ type AuthProbeTarget = {
8791mode?: string;
8892};
899394+/** Summary for a full auth probe run. */
9095export type AuthProbeSummary = {
9196startedAt: number;
9297finishedAt: number;
@@ -102,6 +107,7 @@ export type AuthProbeSummary = {
102107results: AuthProbeResult[];
103108};
104109110+/** Runtime options controlling provider/profile filtering and probe cost. */
105111export type AuthProbeOptions = {
106112provider?: string;
107113profileIds?: string[];
@@ -110,6 +116,7 @@ export type AuthProbeOptions = {
110116maxTokens: number;
111117};
112118119+/** Maps runtime failover reasons into stable auth probe status buckets. */
113120export function mapFailoverReasonToProbeStatus(reason?: string | null): AuthProbeStatus {
114121if (!reason) {
115122return "unknown";
@@ -285,6 +292,7 @@ async function maybeResolveUnresolvedRefIssue(params: {
285292}
286293}
287294295+/** Builds probe targets plus preflight failures for missing/invalid credentials. */
288296export async function buildProbeTargets(params: {
289297cfg: OpenClawConfig;
290298agentDir?: string;
@@ -334,6 +342,8 @@ export async function buildProbeTargets(params: {
334342explicitOrder && explicitOrder.length > 0
335343 ? new Set(resolveAuthProfileOrder({ cfg, store, provider: providerKey }))
336344 : null;
345+// Explicit auth.order both selects and documents profile eligibility; report
346+// excluded profiles instead of silently skipping them.
337347const filteredProfiles = profileFilter.size
338348 ? profileIds.filter((id) => profileFilter.has(id))
339349 : profileIds;
@@ -605,6 +615,7 @@ async function runTargetsWithConcurrency(params: {
605615return results.filter((entry): entry is AuthProbeResult => Boolean(entry));
606616}
607617618+/** Runs all auth probes with bounded concurrency and returns a summary. */
608619export async function runAuthProbes(params: {
609620cfg: OpenClawConfig;
610621agentId?: string;
@@ -654,13 +665,15 @@ export async function runAuthProbes(params: {
654665};
655666}
656667668+/** Formats probe latency for table output. */
657669export function formatProbeLatency(latencyMs?: number | null) {
658670if (!latencyMs && latencyMs !== 0) {
659671return "-";
660672}
661673return formatMs(latencyMs);
662674}
663675676+/** Groups probe results by provider. */
664677export function groupProbeResults(results: AuthProbeResult[]): Map<string, AuthProbeResult[]> {
665678const map = new Map<string, AuthProbeResult[]>();
666679for (const result of results) {
@@ -671,6 +684,7 @@ export function groupProbeResults(results: AuthProbeResult[]): Map<string, AuthP
671684return map;
672685}
673686687+/** Sorts probe results by provider and display label. */
674688export function sortProbeResults(results: AuthProbeResult[]): AuthProbeResult[] {
675689return results.slice().toSorted((a, b) => {
676690const provider = a.provider.localeCompare(b.provider);
@@ -683,6 +697,7 @@ export function sortProbeResults(results: AuthProbeResult[]): AuthProbeResult[]
683697});
684698}
685699700+/** Produces the terse completion line for auth probe output. */
686701export function describeProbeSummary(summary: AuthProbeSummary): string {
687702if (summary.totalTargets === 0) {
688703return "No probe targets.";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。