bailian-cli-core 2.10.2 → 2.10.4

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.d.mts CHANGED
@@ -2869,6 +2869,23 @@ export declare const httpTransport: {
2869
2869
  fetch(this: void, input: string | URL | Request, init?: RequestInit): Promise<Response>;
2870
2870
  };
2871
2871
  //#endregion
2872
+ //#region src/client/network-diagnostics.d.ts
2873
+ /**
2874
+ * Network failure diagnostics: extract errno from the fetch cause chain and recognize sandbox network-denial signatures.
2875
+ *
2876
+ * When an agent host sandbox (e.g. Codex's default workspace-write) disables outbound network, connect fails immediately
2877
+ * with EPERM/EACCES/ENETUNREACH/EHOSTUNREACH — this is not a regional network issue and mirrors cannot fix it;
2878
+ * the hint must guide toward enabling network or using an egress proxy, never mislead the user into switching sources.
2879
+ */
2880
+ /** Take the first string errno along the cause chain (undici wraps connect errors inside TypeError.cause). */
2881
+ export declare function networkCauseCode(error: unknown): string | undefined;
2882
+ /** Whether the code is a sandbox network-denial signature (EPERM/EACCES/ENETUNREACH/EHOSTUNREACH). */
2883
+ export declare function isSandboxNetworkDenialCode(code: string | undefined): boolean;
2884
+ /** Core-layer sandbox-block guidance (abstract actions; no product command names or URLs). */
2885
+ export declare const SANDBOX_NETWORK_HINT = "The execution environment (for example an AI agent sandbox) may be blocking outbound network. Enable network access for this process in the agent settings, or run the command in a regular terminal. If an egress proxy is required, set HTTPS_PROXY.";
2886
+ /** TCP reachability probe: undefined on success, errno on failure (used by the doctor host network preflight). */
2887
+ export declare function probeTcpHost(host: string, port: number, timeoutMs: number): Promise<string | undefined>;
2888
+ //#endregion
2872
2889
  //#region src/console/response.d.ts
2873
2890
  /**
2874
2891
  * Read the known Console protocol layers, not arbitrary business `data` fields.
@@ -2888,6 +2905,12 @@ interface ModelListParams {
2888
2905
  name?: string;
2889
2906
  providers?: string[];
2890
2907
  capabilities?: string[];
2908
+ /**
2909
+ * Server-side capability scope, e.g. `{ fineTune: true }` for the trainable
2910
+ * catalog. Omitted by default, which returns the inference-scoped catalog;
2911
+ * training-only base models and their snapshots only appear when scoped.
2912
+ */
2913
+ supports?: Record<string, boolean>;
2891
2914
  }
2892
2915
  interface ModelListResult {
2893
2916
  total: number;
@@ -2902,7 +2925,7 @@ export declare function fetchModelListAll(call: ConsoleCall, params?: Omit<Model
2902
2925
  * substring match, so an exact `model` equality check narrows the result
2903
2926
  * (e.g. avoids `qwen3-8b` matching `qwen3-8b-v2`).
2904
2927
  */
2905
- export declare function findModelByName(call: ConsoleCall, modelName: string): Promise<Record<string, unknown> | null>;
2928
+ export declare function findModelByName(call: ConsoleCall, modelName: string, supports?: Record<string, boolean>): Promise<Record<string, unknown> | null>;
2906
2929
  interface ModelPriceInfo {
2907
2930
  type?: string;
2908
2931
  priceUnit?: string;
@@ -3212,6 +3235,8 @@ export interface DatasetUploadParams {
3212
3235
  purpose?: string;
3213
3236
  /** 已由调用方校验的不可变字节;提供时不再读取 filePath。 */
3214
3237
  fileBlob?: Blob;
3238
+ /** Sent as X-DashScope-WorkSpace; omit when the API key is workspace-bound. */
3239
+ workspaceId?: string;
3215
3240
  signal?: AbortSignal;
3216
3241
  }
3217
3242
  /**
@@ -3843,13 +3868,31 @@ export interface FineTuneHyperParameters {
3843
3868
  /** Future-compat: arbitrary additional fields are forwarded as-is. */
3844
3869
  [k: string]: unknown;
3845
3870
  }
3871
+ /**
3872
+ * Dataset descriptor used by OPD (pg_opd) jobs. The server also accepts the
3873
+ * flat `training_file_ids` form, but OPD submissions and readbacks use these
3874
+ * descriptors, so the CLI sends the same shape.
3875
+ */
3876
+ export interface FineTuneDatasetDescriptor {
3877
+ type: "training" | "validation";
3878
+ data_source_type: "file_id";
3879
+ file_id: string;
3880
+ }
3881
+ /** MTU resource configuration for OPD jobs (kept separate from hyper_parameters). */
3882
+ export interface FineTuneResourceConfig {
3883
+ charge_type?: string;
3884
+ mtu_spec_code?: string;
3885
+ mtu_capacity?: number;
3886
+ [k: string]: unknown;
3887
+ }
3846
3888
  /** POST /api/v1/fine-tunes request body. */
3847
3889
  export interface CreateFineTuneRequest {
3848
3890
  /** Base model ID, or a previously fine-tuned model ID for continued training. */
3849
3891
  model: string;
3850
- training_file_ids: string[];
3892
+ /** Flat file-id form (sft/dpo/cpt). OPD uses training_datasets instead. */
3893
+ training_file_ids?: string[];
3851
3894
  /**
3852
- * Server-supported values: `cpt | sft | efficient_sft | dpo_full | dpo_lora`.
3895
+ * Server-supported values: `cpt | sft | efficient_sft | dpo_full | dpo_lora | pg_opd`.
3853
3896
  *
3854
3897
  * NOTE — current bailian-cli scope: `sft` (default) and `efficient_sft`.
3855
3898
  * Other values are rejected by the CLI at parse time so users get an
@@ -3868,6 +3911,14 @@ export interface CreateFineTuneRequest {
3868
3911
  model_name?: string;
3869
3912
  /** Suffix appended by the platform; field is `finetuned_output_suffix` (NOT `suffix`). */
3870
3913
  finetuned_output_suffix?: string;
3914
+ /** OPD (pg_opd): platform-registered teacher model ID. */
3915
+ teacher_model?: string;
3916
+ /** OPD (pg_opd): training dataset descriptors. */
3917
+ training_datasets?: FineTuneDatasetDescriptor[];
3918
+ /** OPD (pg_opd): validation dataset descriptors. */
3919
+ validation_datasets?: FineTuneDatasetDescriptor[];
3920
+ /** OPD (pg_opd): MTU charge type / spec / capacity. */
3921
+ resource_config?: FineTuneResourceConfig;
3871
3922
  }
3872
3923
  /** GET /api/v1/fine-tunes/{id}/logs response. */
3873
3924
  export interface FineTuneLogEntry {
@@ -3977,6 +4028,12 @@ export interface FineTuneJob {
3977
4028
  training_file_ids?: string[];
3978
4029
  validation_file_ids?: string[];
3979
4030
  hyper_parameters?: FineTuneHyperParameters;
4031
+ /** OPD (pg_opd) readback fields. */
4032
+ teacher_model?: string;
4033
+ training_datasets?: FineTuneDatasetDescriptor[];
4034
+ validation_datasets?: FineTuneDatasetDescriptor[];
4035
+ mtu_spec_code?: string;
4036
+ mtu_capacity?: number;
3980
4037
  /** Server-side timestamps (DashScope uses snake_case `create_time` / `end_time`). */
3981
4038
  create_time?: string;
3982
4039
  end_time?: string;
@@ -4192,26 +4249,30 @@ export interface CompressJobActionResponse {
4192
4249
  //#endregion
4193
4250
  //#region src/finetune/api.d.ts
4194
4251
  /** POST /api/v1/fine-tunes */
4195
- export declare function createFineTune(client: Client, body: CreateFineTuneRequest, signal?: AbortSignal): Promise<CreateFineTuneResponse>;
4252
+ export declare function createFineTune(client: Client, body: CreateFineTuneRequest, signal?: AbortSignal, workspaceId?: string): Promise<CreateFineTuneResponse>;
4196
4253
  export interface ListFineTunesParams {
4197
4254
  pageNo?: number;
4198
4255
  pageSize?: number;
4199
4256
  status?: string;
4200
4257
  /** Filter by base model ID (server-side). */
4201
4258
  model?: string;
4259
+ /** Sent as X-DashScope-WorkSpace; use the job's owning workspace. */
4260
+ workspaceId?: string;
4202
4261
  signal?: AbortSignal;
4203
4262
  }
4204
4263
  /** GET /api/v1/fine-tunes */
4205
4264
  export declare function listFineTunes(client: Client, params?: ListFineTunesParams): Promise<ListFineTunesResponse>;
4206
4265
  /** GET /api/v1/fine-tunes/{job_id} */
4207
- export declare function getFineTune(client: Client, jobId: string, signal?: AbortSignal): Promise<GetFineTuneResponse>;
4266
+ export declare function getFineTune(client: Client, jobId: string, signal?: AbortSignal, workspaceId?: string): Promise<GetFineTuneResponse>;
4208
4267
  /** POST /api/v1/fine-tunes/{job_id}/cancel */
4209
- export declare function cancelFineTune(client: Client, jobId: string, signal?: AbortSignal): Promise<CancelFineTuneResponse>;
4268
+ export declare function cancelFineTune(client: Client, jobId: string, signal?: AbortSignal, workspaceId?: string): Promise<CancelFineTuneResponse>;
4210
4269
  /** DELETE /api/v1/fine-tunes/{job_id} */
4211
- export declare function deleteFineTune(client: Client, jobId: string, signal?: AbortSignal): Promise<DeleteFineTuneResponse>;
4270
+ export declare function deleteFineTune(client: Client, jobId: string, signal?: AbortSignal, workspaceId?: string): Promise<DeleteFineTuneResponse>;
4212
4271
  export interface GetFineTuneLogsParams {
4213
4272
  pageNo?: number;
4214
4273
  pageSize?: number;
4274
+ /** Sent as X-DashScope-WorkSpace; use the job's owning workspace. */
4275
+ workspaceId?: string;
4215
4276
  signal?: AbortSignal;
4216
4277
  }
4217
4278
  /** GET /api/v1/fine-tunes/{job_id}/logs */
@@ -4256,7 +4317,7 @@ export interface ListBasicMetricsParams {
4256
4317
  */
4257
4318
  export declare function listBasicMetrics(client: Client, jobId: string, params?: ListBasicMetricsParams): Promise<ListBasicMetricsResponse>;
4258
4319
  /** GET /api/v1/fine-tunes/{job_id}/checkpoints */
4259
- export declare function listCheckpoints(client: Client, jobId: string, signal?: AbortSignal): Promise<ListCheckpointsResponse>;
4320
+ export declare function listCheckpoints(client: Client, jobId: string, signal?: AbortSignal, workspaceId?: string): Promise<ListCheckpointsResponse>;
4260
4321
  /**
4261
4322
  * GET /api/v1/fine-tunes/{job_id}/export/{checkpoint}?model_name={name}
4262
4323
  *
@@ -4264,7 +4325,7 @@ export declare function listCheckpoints(client: Client, jobId: string, signal?:
4264
4325
  * `deploy <modality> create` can target it. The platform may auto-export the best
4265
4326
  * checkpoint on SUCCEEDED, but explicit export is the canonical path.
4266
4327
  */
4267
- export declare function exportCheckpoint(client: Client, jobId: string, checkpoint: string, modelName: string, signal?: AbortSignal): Promise<ExportCheckpointResponse>;
4328
+ export declare function exportCheckpoint(client: Client, jobId: string, checkpoint: string, modelName: string, signal?: AbortSignal, workspaceId?: string): Promise<ExportCheckpointResponse>;
4268
4329
  //#endregion
4269
4330
  //#region src/finetune/compress.d.ts
4270
4331
  export interface ListCompressTemplatesParams {
@@ -4358,6 +4419,13 @@ export type TrainingTypeCli = keyof typeof TRAINING_TYPE_MAP;
4358
4419
  export declare const TRAINING_TYPES_CLI: readonly TrainingTypeCli[];
4359
4420
  /** Default training type when `--training-type` is omitted. */
4360
4421
  export declare const DEFAULT_TRAINING_TYPE: TrainingTypeCli;
4422
+ /**
4423
+ * Catalog scope for training-capability queries. The default `listFoundationModels`
4424
+ * catalog is inference-scoped and omits training-only base models (and their dated
4425
+ * snapshots); scoping by `fineTune` returns the trainable universe the console
4426
+ * training selector shows. Shared by both capability query directions.
4427
+ */
4428
+ export declare const FINETUNE_CATALOG_SUPPORTS: Record<string, boolean>;
4361
4429
  /** Subset of `supports` relevant to training capability. */
4362
4430
  interface ModelSupports {
4363
4431
  sft?: boolean;
@@ -4503,6 +4571,823 @@ export declare function estimateSftDpoTokens(client: Client, datasetIds: string[
4503
4571
  */
4504
4572
  export declare function estimateCptTokens(client: Client, model: string, datasetIdsCsv: string, nEpochs: number): Promise<TokenEstimate>;
4505
4573
  //#endregion
4574
+ //#region src/finetune/rl/types.d.ts
4575
+ /**
4576
+ * RL / OPD training spec types.
4577
+ *
4578
+ * Mirrors the DashScope SDK `job.yaml` shape (snake_case preserved verbatim —
4579
+ * the SDK owns these field names). CLI-only metadata lives under the `bailian`
4580
+ * namespace and is stripped before the spec is handed to the SDK.
4581
+ */
4582
+ /** FC runtime sizing + env for a single function component. */
4583
+ export interface RlFunctionRuntime {
4584
+ cpu?: number;
4585
+ memory_size?: number;
4586
+ disk_size?: number;
4587
+ concurrency?: number;
4588
+ capacity?: number;
4589
+ min_capacity?: number;
4590
+ max_capacity?: number;
4591
+ memory_scale_threshold?: number;
4592
+ concurrency_scale_threshold?: number;
4593
+ env?: Record<string, string>;
4594
+ [key: string]: unknown;
4595
+ }
4596
+ /** Upload package descriptor for a function component. */
4597
+ export interface RlFcModel {
4598
+ /** Source root uploaded as the function package; rewritten to deploy-copy. */
4599
+ zipdir?: string;
4600
+ /** Python entry class, relative to zipdir; never rewritten. */
4601
+ classpath?: string;
4602
+ /** Requirements path relative to the package root; kept as-is. */
4603
+ requirements_path?: string;
4604
+ [key: string]: unknown;
4605
+ }
4606
+ /** A rollout / reward function component. */
4607
+ export interface RlFunction {
4608
+ type?: string;
4609
+ name?: string;
4610
+ timeout?: number;
4611
+ weight?: number;
4612
+ reward_metric_weight?: Record<string, number>;
4613
+ fcmodel?: RlFcModel;
4614
+ runtime?: RlFunctionRuntime;
4615
+ [key: string]: unknown;
4616
+ }
4617
+ /** A training / validation dataset entry. */
4618
+ export interface RlDataset {
4619
+ type?: string;
4620
+ data_source_type?: string;
4621
+ /** Local file path; rewritten into the task data dir before submission. */
4622
+ file_name?: string;
4623
+ /** Reuse an already-uploaded file; mutually exclusive with a local upload. */
4624
+ file_id?: string;
4625
+ [key: string]: unknown;
4626
+ }
4627
+ export interface RlModel {
4628
+ name?: string;
4629
+ [key: string]: unknown;
4630
+ }
4631
+ export interface RlResources {
4632
+ charge_type?: string;
4633
+ mtu_spec_code?: string;
4634
+ mtu_capacity?: number;
4635
+ instance_id?: string;
4636
+ [key: string]: unknown;
4637
+ }
4638
+ export interface RlTraining {
4639
+ type?: string;
4640
+ hyper_parameters?: Record<string, unknown>;
4641
+ resources?: RlResources;
4642
+ [key: string]: unknown;
4643
+ }
4644
+ /** CLI-only metadata; stripped before handing the spec to the SDK. */
4645
+ export interface RlBailianMeta {
4646
+ schema_version?: number;
4647
+ profile?: string;
4648
+ code_dir?: string;
4649
+ requirements?: string;
4650
+ package?: {
4651
+ include?: string[];
4652
+ exclude?: string[];
4653
+ };
4654
+ execution?: {
4655
+ watch?: boolean;
4656
+ timeout?: number;
4657
+ };
4658
+ /** Secret references only (env var names); never plaintext credentials. */
4659
+ function_secret_env?: Record<string, string>;
4660
+ [key: string]: unknown;
4661
+ }
4662
+ /** The full job.yaml document (SDK fields + bailian namespace). */
4663
+ export interface RlJobSpec {
4664
+ name?: string;
4665
+ model?: RlModel;
4666
+ /** OPD teacher model; forbidden for plain RL. */
4667
+ teacher_model?: string;
4668
+ functions?: RlFunction[];
4669
+ datasets?: RlDataset[];
4670
+ training?: RlTraining;
4671
+ observability?: Record<string, unknown>;
4672
+ bailian?: RlBailianMeta;
4673
+ [key: string]: unknown;
4674
+ }
4675
+ /**
4676
+ * Parsed CLI business params fed into {@link resolveTrainingSpec}.
4677
+ *
4678
+ * The command layer maps raw flags into this shape; core stays free of any
4679
+ * runtime flag-parsing dependency. Repeatable flags arrive as string arrays
4680
+ * in the original `KEY=VALUE` / `name.field=value` syntax.
4681
+ */
4682
+ export interface RlRunParams {
4683
+ name?: string;
4684
+ model?: string;
4685
+ teacherModel?: string;
4686
+ trainFiles?: string[];
4687
+ trainFileIds?: string[];
4688
+ validationFiles?: string[];
4689
+ validationFileIds?: string[];
4690
+ codeDir?: string;
4691
+ requirements?: string;
4692
+ include?: string[];
4693
+ exclude?: string[];
4694
+ /** Single rollout classpath. */
4695
+ rollout?: string;
4696
+ /** Repeatable `name=classpath`. */
4697
+ rewards?: string[];
4698
+ clearFunctions?: boolean;
4699
+ /** Repeatable `name=sec`. */
4700
+ functionTimeouts?: string[];
4701
+ /** Repeatable `name.field=value`. */
4702
+ functionRuntime?: string[];
4703
+ /** Repeatable `name=num`. */
4704
+ rewardWeights?: string[];
4705
+ /** Repeatable `name.metric=num`. */
4706
+ rewardMetrics?: string[];
4707
+ /** Repeatable `name.KEY=value`. */
4708
+ functionEnv?: string[];
4709
+ /** Repeatable `key=value`, parsed by type. */
4710
+ hp?: string[];
4711
+ chargeType?: string;
4712
+ mtuSpec?: string;
4713
+ mtuCount?: number;
4714
+ instanceId?: string;
4715
+ /** Repeatable `key=value`, top-level shallow override (SDK init(**kwargs)). */
4716
+ set?: string[];
4717
+ /** Force OPD mode: training.type=pg_opd + teacher_model required. */
4718
+ opd?: boolean;
4719
+ }
4720
+ /** Task-directory paths needed to rewrite filesystem references in the YAML. */
4721
+ export interface RlTaskPaths {
4722
+ /** Writable source copy the SDK packages (zipdir target). */
4723
+ deployCopyDir: string;
4724
+ /** Staged training/validation data (file_name target). */
4725
+ dataDir: string;
4726
+ }
4727
+ /** Result of {@link resolveTrainingSpec}: merged spec + assembly diagnostics. */
4728
+ export interface IResolvedTrainingSpec {
4729
+ spec: RlJobSpec;
4730
+ /** Whether any function component (rollout/reward) is present. */
4731
+ hasFunctions: boolean;
4732
+ /** Whether this is an OPD job (pg_opd + teacher_model). */
4733
+ isOpd: boolean;
4734
+ }
4735
+ //#endregion
4736
+ //#region src/finetune/rl/params.d.ts
4737
+ /**
4738
+ * Parsers for the repeatable `KEY=VALUE` style RL flags.
4739
+ *
4740
+ * Core stays free of runtime flag parsing: the command layer hands raw entry
4741
+ * strings here and these helpers turn them into structured assignments.
4742
+ * All errors are {@link UsageError} (exit 2) — they describe user input, not
4743
+ * server-side failures.
4744
+ */
4745
+ /**
4746
+ * Parse a scalar by type: boolean / null / JSON object-or-array / number,
4747
+ * falling back to the original string. Used for `--hp key=value`.
4748
+ */
4749
+ export declare function parseTypedValue(raw: string): unknown;
4750
+ /**
4751
+ * Parse a value as JSON, falling back to the original string. Used for
4752
+ * `--set key=value` (matches the SDK `init(**kwargs)` top-level override).
4753
+ */
4754
+ export declare function parseJsonValue(raw: string): unknown;
4755
+ /** A `key=value` assignment split on the first `=`. */
4756
+ export interface KeyValueAssignment {
4757
+ key: string;
4758
+ value: string;
4759
+ }
4760
+ /**
4761
+ * Split `key=value` on the first `=`. Both sides must be non-empty.
4762
+ * `formatHint` describes the expected syntax for the error message.
4763
+ */
4764
+ export declare function parseAssignment(entry: string, flag: string, formatHint: string): KeyValueAssignment;
4765
+ /** A `name.field=value` assignment (name and field split on the first `.`). */
4766
+ export interface DottedAssignment {
4767
+ name: string;
4768
+ field: string;
4769
+ value: string;
4770
+ }
4771
+ /**
4772
+ * Split `name.field=value` into its three parts. Used for `--function-runtime`,
4773
+ * `--function-env` and `--reward-metric`. The value may itself contain `.` or
4774
+ * `=`; only the first `=` and the first `.` of the left side are separators.
4775
+ */
4776
+ export declare function parseDottedAssignment(entry: string, flag: string, formatHint: string): DottedAssignment;
4777
+ /** Parse a numeric flag value, rejecting non-finite input. */
4778
+ export declare function parseNumericValue(raw: string, flag: string): number;
4779
+ //#endregion
4780
+ //#region src/finetune/rl/config.d.ts
4781
+ /** Parse the optional `--config` YAML document into a spec (empty when absent). */
4782
+ export declare function parseJobYaml(yamlText: string): RlJobSpec;
4783
+ /**
4784
+ * Merge CLI params over an optional YAML document into a single SDK spec.
4785
+ * Enforces model presence and the RL/OPD type constraints.
4786
+ */
4787
+ export declare function resolveTrainingSpec(params: RlRunParams, yamlText?: string): IResolvedTrainingSpec;
4788
+ /**
4789
+ * Serialize the task-local YAML handed to the SDK: strip the `bailian` namespace
4790
+ * and rewrite every filesystem reference into the task directory. `classpath`
4791
+ * and `requirements_path` stay relative to the package root and are untouched.
4792
+ */
4793
+ export declare function buildTaskYaml(spec: RlJobSpec, paths: RlTaskPaths): string;
4794
+ //#endregion
4795
+ //#region src/finetune/rl/auth.d.ts
4796
+ /** Authorization target: plain reinforcement learning or OPD distillation. */
4797
+ export type RlAuthTarget = "rl" | "opd";
4798
+ export type RlAuthStatus = "READY" | "MISSING" | "UNKNOWN" | "REQUIRES_USER_ACTION" | "FAILED";
4799
+ export interface IRlAuthCheck {
4800
+ name: string;
4801
+ /** Required checks must be READY for the report to pass; advisory ones may degrade. */
4802
+ required: boolean;
4803
+ status: RlAuthStatus;
4804
+ detail?: string;
4805
+ }
4806
+ export interface IRlAuthReport {
4807
+ target: RlAuthTarget;
4808
+ checks: IRlAuthCheck[];
4809
+ /** True when every required check is READY. */
4810
+ ok: boolean;
4811
+ /** Audit trail of mutations actually attempted (name, or name:failed). */
4812
+ actions: string[];
4813
+ }
4814
+ /** Console gateway seam: `(api, data) => client.console(api, data)`. */
4815
+ export type RlConsoleCaller = (api: string, data: Record<string, unknown>) => Promise<unknown>;
4816
+ export interface IRlAuthOptions {
4817
+ target: RlAuthTarget;
4818
+ console: RlConsoleCaller;
4819
+ workspaceId?: string;
4820
+ /** Permit business enablement. Read-only probe when false (default). */
4821
+ authorize?: boolean;
4822
+ /** Locale selector for user-facing guidance; defaults to en-US when omitted. */
4823
+ localize?: (text: LocalizedText) => string;
4824
+ /** Console doc URL guiding manual SLR authorization; injected by the command layer. */
4825
+ manualAuthDocUrl: string;
4826
+ }
4827
+ /**
4828
+ * Console zelda API names, aligned with the model-training console. The
4829
+ * `.m_efm` suffix and `{input}` wrapper belong to the customFetcherIo family;
4830
+ * the telemetry and finetune HTTP APIs use `{reqDTO}` instead.
4831
+ */
4832
+ export declare const RL_AUTH_API: {
4833
+ readonly checkUserWhitelist: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/common/checkUserWhitelist";
4834
+ readonly queryReinforcementEnabled: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/reinforcement/query_reinforcement_enabled";
4835
+ readonly queryOpdEnabled: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/opd/query_opd_enabled";
4836
+ readonly checkFineTuningSlrAuth: "zeldaEasy.broadscope-platform.modelInstance.checkSlrAuth.m_efm";
4837
+ readonly getTelemetrySlrStatus: "zeldaEasy.bailian-telemetry.activate.getTelemetrySlrStatus";
4838
+ readonly getTelemetryServiceStatus: "zeldaEasy.bailian-telemetry.activate.getTelemetryServiceStatus";
4839
+ readonly enableReinforcement: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/reinforcement/enable_reinforcement";
4840
+ readonly enableOpd: "zeldaHttp.dashscopeFinetune./zelda/api/v1/finetune/opd/enable_opd";
4841
+ };
4842
+ /**
4843
+ * Extract a boolean state from a gateway business payload. The console host
4844
+ * exposes the flag under different keys depending on the API: a bare boolean
4845
+ * (origin responses), `{result}` (wrapped scalars), `{openStatus}` (telemetry
4846
+ * service) or `{enabled}` (SLS). Returns undefined when no recognizable flag is
4847
+ * present so the caller reports UNKNOWN.
4848
+ */
4849
+ export declare function extractEnabledFlag(response: unknown): boolean | undefined;
4850
+ /**
4851
+ * Run the authorization state machine for one target. Read-only by default;
4852
+ * pass `authorize: true` to enable the target once its prerequisites (manual
4853
+ * role authorization included) are ready. Roles are never created by the CLI;
4854
+ * SLS activation is always a manual console step (static advisory).
4855
+ */
4856
+ export declare function runRlAuthorization(options: IRlAuthOptions): Promise<IRlAuthReport>;
4857
+ //#endregion
4858
+ //#region src/isolation/types.d.ts
4859
+ /**
4860
+ * 隔离层类型契约。
4861
+ *
4862
+ * 两层隔离:确定性应用层(全平台必选)+ OS 强制(环境闭环硬性 fail-closed,
4863
+ * 其余增强可降级)。平台差异收敛在 os-isolation/ 适配层,上层逻辑无平台分支。
4864
+ */
4865
+ /** 本地白名单代理策略。 */
4866
+ export interface IProxyPolicy {
4867
+ /** 管理面精确域名,如 dashscope.aliyuncs.com。 */
4868
+ managementDomains: string[];
4869
+ /** OSS 域名后缀白名单,如 .oss-cn-beijing.aliyuncs.com。 */
4870
+ ossSuffixes: string[];
4871
+ /** 允许的 CONNECT 端口,首版仅 443。 */
4872
+ allowedPorts: number[];
4873
+ }
4874
+ /** 一次隔离执行的完整输入。 */
4875
+ export interface IIsolationSpec {
4876
+ runId: string;
4877
+ /** 托管 Python + SDK 目录。 */
4878
+ runtimeRoot: string;
4879
+ /** <data>/runs/<run-id>。 */
4880
+ taskDir: string;
4881
+ snapshotDir: string;
4882
+ deployCopyDir: string;
4883
+ dataDir: string;
4884
+ /** 重定向的 HOME/USERPROFILE。 */
4885
+ homeDir: string;
4886
+ tmpDir: string;
4887
+ cacheDir: string;
4888
+ configPath: string;
4889
+ /** [python, -I, -m, dashscope, ...]。 */
4890
+ command: string[];
4891
+ /** 注入用,绝不进日志。 */
4892
+ apiKey: string;
4893
+ /** 企业 profile 指定时才注入 DASHSCOPE_HTTP_BASE_URL。 */
4894
+ baseUrl?: string;
4895
+ /** 真实凭据路径,OS 禁读目标(如真实 ~/.dashscope)。 */
4896
+ credentialDenyPaths: string[];
4897
+ network: IProxyPolicy;
4898
+ /** 本地代理端口(app-layer 启动代理后回填,供 OS 网络放行)。 */
4899
+ proxyPort?: number;
4900
+ timeoutMs: number;
4901
+ maxOutputBytes: number;
4902
+ logLevel?: string;
4903
+ /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */
4904
+ sdkEnv?: Record<string, string>;
4905
+ }
4906
+ /** 增强能力实际启用情况(可降级,不阻断)。 */
4907
+ export interface IIsolationHardening {
4908
+ networkEnforce: boolean;
4909
+ processTree: boolean;
4910
+ memoryLimit: boolean;
4911
+ }
4912
+ /** 平台探测结果:硬性凭据禁读与增强分开判定。 */
4913
+ export interface IIsolationCapability {
4914
+ credentialDenyRead: {
4915
+ available: boolean;
4916
+ mechanism: "sbpl" | "bwrap-nobind" | "appcontainer" | "none";
4917
+ reason?: string;
4918
+ };
4919
+ hardening: IIsolationHardening;
4920
+ }
4921
+ /** 一次隔离执行的结果。 */
4922
+ export interface IIsolationResult {
4923
+ exitCode: number | null;
4924
+ signal: string | null;
4925
+ stdout: string;
4926
+ stderr: string;
4927
+ timedOut: boolean;
4928
+ /** 凭据禁读是否由 OS 强制(硬性,必须 true 才执行)。 */
4929
+ credentialDenyEnforced: boolean;
4930
+ hardening: IIsolationHardening;
4931
+ }
4932
+ /** OS 适配层统一接口。app-layer 负责编排,OS 层只注入强制 argv 与资源准备。 */
4933
+ export interface IIsolationAdapter {
4934
+ /** 探测凭据禁读能力;不可用则 run 前 fail-closed。 */
4935
+ detect(): Promise<IIsolationCapability>;
4936
+ /** OS 资源准备(如写 SBPL profile、授权 SID)。 */
4937
+ prepare(spec: IIsolationSpec): Promise<void>;
4938
+ /** 把原始 argv 包装成 OS 强制 argv(sandbox-exec / bwrap);无包装原样返回。 */
4939
+ wrapCommand(spec: IIsolationSpec, command: string[]): string[];
4940
+ dispose(): Promise<void>;
4941
+ }
4942
+ //#endregion
4943
+ //#region src/isolation/paths.d.ts
4944
+ /**
4945
+ * 任务目录与运行时目录布局。
4946
+ *
4947
+ * 数据目录统一经 getConfigDir() 派生(仓库约定,全平台一致,不做平台分支):
4948
+ * runs/<run-id>/ 随调用结束立即销毁(app-layer finally);崩溃路径孤儿由
4949
+ * runtime clean / prepare 按 TTL 兜底回收(见 cleanup.ts)。
4950
+ */
4951
+ /** 一次任务的目录布局。 */
4952
+ export interface ITaskDirLayout {
4953
+ runId: string;
4954
+ taskDir: string;
4955
+ snapshotDir: string;
4956
+ dataDir: string;
4957
+ deployCopyDir: string;
4958
+ tmpDir: string;
4959
+ homeDir: string;
4960
+ dashscopeDir: string;
4961
+ cacheDir: string;
4962
+ configPath: string;
4963
+ resultPath: string;
4964
+ }
4965
+ /** 生成随机 run-id(不依赖时间戳,避免可预测)。 */
4966
+ export declare function newRunId(): string;
4967
+ export declare function runsRoot(): string;
4968
+ /** 创建任务目录骨架(含 home/.dashscope),返回布局。 */
4969
+ export declare function createTaskDir(runId?: string): ITaskDirLayout;
4970
+ /** 托管运行时安装目录:<data>/runtimes/rl/<runtime-id>/。 */
4971
+ export declare function runtimeRoot(runtimeId: string): string;
4972
+ /** 托管运行时版本目录的根:<data>/runtimes/rl/(旧版本回收的扫描范围)。 */
4973
+ export declare function managedRuntimesRoot(): string;
4974
+ /** 运行时下载缓存目录。 */
4975
+ export declare function runtimeCacheRoot(): string;
4976
+ //#endregion
4977
+ //#region src/isolation/env.d.ts
4978
+ /**
4979
+ * 环境变量清洗 + home 重定向。
4980
+ *
4981
+ * 核心:不是"在用户环境上追加",而是构造一个全新的最小环境对象。凭据/代理/
4982
+ * Python 劫持变量一律不继承;home 变量重定向到任务目录,使 SDK 的
4983
+ * expanduser("~/.dashscope/...") 解析到任务 home 而非真实 home。
4984
+ */
4985
+ /** 构造最小环境所需的输入。 */
4986
+ export interface ISandboxEnvInput {
4987
+ homeDir: string;
4988
+ tmpDir: string;
4989
+ cacheDir: string;
4990
+ runtimeRoot: string;
4991
+ apiKey: string;
4992
+ baseUrl?: string;
4993
+ proxyPort: number;
4994
+ logLevel?: string;
4995
+ /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */
4996
+ sdkEnv?: Record<string, string>;
4997
+ /** 目标平台,默认当前进程平台(便于跨平台单测)。 */
4998
+ platform?: NodeJS.Platform;
4999
+ /** 宿主环境,仅用于挑选必要系统变量(SystemRoot/locale),默认 process.env。 */
5000
+ hostEnv?: Record<string, string | undefined>;
5001
+ }
5002
+ /**
5003
+ * 构造全新最小环境。只包含注入项 + 必要系统变量;其余(DASHSCOPE_CONFIG、
5004
+ * DASHSCOPE_API_KEY_FILE_PATH、PYTHONPATH/PYTHONHOME、SSH_AUTH_SOCK、用户代理、
5005
+ * AWS / ALIBABA_CLOUD / AZURE 系列凭据变量等)因全新构造而天然不存在。
5006
+ */
5007
+ export declare function buildSandboxEnv(input: ISandboxEnvInput): Record<string, string>;
5008
+ /**
5009
+ * 预生成任务 home 下的 .dashscope/config.toml。
5010
+ *
5011
+ * API Key 经环境变量注入(优先级最高),刻意不落盘以减少持久化秘密;此处仅
5012
+ * 写入非秘密设置(如企业 base_url),确保 SDK 读到受控配置而非回退真实 home。
5013
+ */
5014
+ export declare function prepareTaskHome(homeDir: string, baseUrl?: string): string;
5015
+ //#endregion
5016
+ //#region src/isolation/snapshot.d.ts
5017
+ /**
5018
+ * 文件快照 + deploy-copy + 数据暂存。
5019
+ *
5020
+ * SDK 的 zip_dir() 会递归读取整个 zipdir 并写 start.sh,因此不能直接指向用户
5021
+ * 原工程:先按 include/exclude 复制到只读 snapshot/,再复制出可写 deploy-copy/
5022
+ * 供 SDK 落 start.sh;数据单独复制到 data/。内置安全排除 + 拒绝符号链接。
5023
+ */
5024
+ export interface ISnapshotOptions {
5025
+ sourceDir: string;
5026
+ snapshotDir: string;
5027
+ deployCopyDir: string;
5028
+ include?: string[];
5029
+ exclude?: string[];
5030
+ maxPackageBytes?: number;
5031
+ }
5032
+ export interface ISnapshotResult {
5033
+ fileCount: number;
5034
+ totalBytes: number;
5035
+ /** 相对 sourceDir 的 posix 路径列表(上传摘要)。 */
5036
+ files: string[];
5037
+ }
5038
+ /**
5039
+ * 复制源码到 snapshot/ 并生成可写 deploy-copy/。返回上传摘要。
5040
+ */
5041
+ export declare function createSnapshot(options: ISnapshotOptions): ISnapshotResult;
5042
+ /**
5043
+ * 将数据文件单独复制到 data/(不混进代码包)。返回暂存后的绝对路径。
5044
+ */
5045
+ export declare function stageDataFiles(files: string[], dataDir: string): string[];
5046
+ //#endregion
5047
+ //#region src/isolation/proxy.d.ts
5048
+ /** 默认策略:管理面精确域名 + 全区域 OSS 后缀 + 仅 443。 */
5049
+ export declare const DEFAULT_PROXY_POLICY: IProxyPolicy;
5050
+ export interface IProxyEvent {
5051
+ type: "allow" | "deny";
5052
+ host: string;
5053
+ port: number;
5054
+ }
5055
+ export interface IWhitelistProxy {
5056
+ port: number;
5057
+ close(): Promise<void>;
5058
+ }
5059
+ export interface IProxyOptions {
5060
+ policy?: IProxyPolicy;
5061
+ /** 仅 host:port 级别事件,供诊断/测试;默认无操作。 */
5062
+ onEvent?: (event: IProxyEvent) => void;
5063
+ }
5064
+ /** 判断 IP 是否属于禁止目标(私网/loopback/link-local/metadata/保留)。 */
5065
+ export declare function isDeniedIp(ip: string): boolean;
5066
+ /**
5067
+ * 将用户配置的服务端点 host 并入管理面白名单(返回新策略,不改原对象)。
5068
+ * 默认白名单只含legacy dashscope.aliyuncs.com;workspace 网关(ws-*.<region>.maas.aliyuncs.com)
5069
+ * 等自定义 base_url 不在其中,SDK 经代理访问会被 403。仅放行精确 host,不放开后缀。
5070
+ */
5071
+ export declare function withEndpointDomain(policy: IProxyPolicy, baseUrl?: string): IProxyPolicy;
5072
+ /** 启动白名单代理,监听 127.0.0.1 随机端口。 */
5073
+ export declare function startWhitelistProxy(options?: IProxyOptions): Promise<IWhitelistProxy>;
5074
+ //#endregion
5075
+ //#region src/isolation/process.d.ts
5076
+ /**
5077
+ * 进程启动 / 超时 / 输出限额 / 进程树管理。
5078
+ *
5079
+ * 参数数组 + shell:false(绝不经过 shell);POSIX 用 detached 进程组以便整组
5080
+ * kill;墙钟超时与输出超限均杀进程;支持 AbortSignal 中断(命令层接 SIGINT)。
5081
+ * OS 强制由 wrapCommand 钩子注入(darwin sandbox-exec / linux bwrap)。
5082
+ */
5083
+ export interface IProcessOptions {
5084
+ /** 完整 argv,含解释器,如 [python, -I, -m, dashscope, ...]。 */
5085
+ command: string[];
5086
+ env: Record<string, string>;
5087
+ cwd: string;
5088
+ timeoutMs: number;
5089
+ maxOutputBytes: number;
5090
+ /** OS 包装:把原始 argv 转成沙箱 argv;缺省直接执行。 */
5091
+ wrapCommand?: (command: string[]) => string[];
5092
+ signal?: AbortSignal;
5093
+ onStdout?: (chunk: string) => void;
5094
+ onStderr?: (chunk: string) => void;
5095
+ }
5096
+ export interface IProcessResult {
5097
+ exitCode: number | null;
5098
+ signal: string | null;
5099
+ stdout: string;
5100
+ stderr: string;
5101
+ timedOut: boolean;
5102
+ }
5103
+ /** 启动受控子进程,收集 stdout/stderr,按超时/输出限额/中断杀进程。 */
5104
+ export declare function runSandboxedProcess(options: IProcessOptions): Promise<IProcessResult>;
5105
+ //#endregion
5106
+ //#region src/isolation/app-layer.d.ts
5107
+ /** 一次隔离执行的输入(任务目录与命令由命令层组装)。 */
5108
+ export interface IIsolatedRunInput {
5109
+ layout: ITaskDirLayout;
5110
+ runtimeRoot: string;
5111
+ /** 完整 argv,含解释器,如 [python, -I, -m, dashscope, ...]。 */
5112
+ command: string[];
5113
+ apiKey: string;
5114
+ baseUrl?: string;
5115
+ credentialDenyPaths: string[];
5116
+ network?: IProxyPolicy;
5117
+ timeoutMs: number;
5118
+ maxOutputBytes: number;
5119
+ logLevel?: string;
5120
+ /** 受控 SDK 环境变量(如 FC_PYPI_LIB),由黑盒显式注入,绝不从宿主继承。 */
5121
+ sdkEnv?: Record<string, string>;
5122
+ /** 沙箱进程 cwd,默认 taskDir。SDK 会相对 cwd 写部署文件(如 start.sh),
5123
+ * 带代码包的命令须传 deployCopyDir,使相对写入落在可写的代码包内。 */
5124
+ cwd?: string;
5125
+ signal?: AbortSignal;
5126
+ }
5127
+ /** 日志脱敏:OSS 签名参数与 API Key。 */
5128
+ export declare function sanitizeSecrets(text: string): string;
5129
+ /**
5130
+ * 在两层隔离下执行命令。环境闭环不可用时 fail-closed(不创建任何云资源)。
5131
+ */
5132
+ export declare function executeIsolatedRun(input: IIsolatedRunInput, adapter: IIsolationAdapter): Promise<IIsolationResult>;
5133
+ //#endregion
5134
+ //#region src/isolation/cleanup.d.ts
5135
+ /**
5136
+ * 沙箱产物生命周期清理(计划式,支持 dry-run 预览)。
5137
+ *
5138
+ * 两类产物、两种策略:
5139
+ * - runs/<run-id>/:正常路径在调用结束时立即销毁(见 app-layer 的 finally),
5140
+ * 留到这里的都是崩溃路径孤儿(SIGKILL/断电致 finally 未执行),按 TTL 回收。
5141
+ * - runtimes/rl/<runtime-id>/:不可变运行时按版本跨调用复用;基线升级后旧版本
5142
+ * 目录成为死重,按「只保留当前基线」回收。
5143
+ * 下载缓存(cache/rl,按 SHA 内容寻址、跨版本复用)与 override 开发目录绝不触碰。
5144
+ */
5145
+ /** runs 孤儿默认年龄阈值:24 小时(正常调用分钟级结束,阈值极宽裕)。 */
5146
+ export declare const DEFAULT_RUNS_TTL_MS: number;
5147
+ export interface ICleanupOptions {
5148
+ /** 基准时间(ms epoch),默认 Date.now()。 */
5149
+ now?: number;
5150
+ /** runs 孤儿年龄阈值(毫秒),默认 24h。 */
5151
+ runsTtlMs?: number;
5152
+ /** 回收 runs 孤儿,默认 true。 */
5153
+ pruneRuns?: boolean;
5154
+ /** 回收旧版本运行时,默认 false(prepare 顺手清理只动 runs)。 */
5155
+ pruneRuntimes?: boolean;
5156
+ /** 当前基线 runtime-id;pruneRuntimes 时缺省则跳过运行时回收(fail-safe)。 */
5157
+ currentRuntimeId?: string;
5158
+ /** 只产出计划,不删除。 */
5159
+ dryRun?: boolean;
5160
+ /** 目录覆盖(测试用);缺省取隔离布局的标准路径。 */
5161
+ runsDir?: string;
5162
+ runtimesDir?: string;
5163
+ }
5164
+ /** 单个产物的处置决定(keep 也列出,保证预览透明)。 */
5165
+ export interface ICleanupEntry {
5166
+ path: string;
5167
+ kind: "run" | "runtime";
5168
+ action: "remove" | "keep";
5169
+ reason: string;
5170
+ }
5171
+ export interface ICleanupResult {
5172
+ dryRun: boolean;
5173
+ entries: ICleanupEntry[];
5174
+ /** 实际删除数(dryRun 时为计划删除数)。 */
5175
+ removedCount: number;
5176
+ }
5177
+ /**
5178
+ * 清理沙箱产物:先对每个目录产出 remove/keep 计划,再统一执行删除。
5179
+ * 单目录删除失败降级为 keep(不抛错、不中断其余清理);stat 竞态直接跳过。
5180
+ */
5181
+ export declare function cleanupSandboxArtifacts(options?: ICleanupOptions): ICleanupResult;
5182
+ //#endregion
5183
+ //#region src/isolation/os-isolation/detect.d.ts
5184
+ /** 按平台创建 OS 隔离适配器。 */
5185
+ export declare function createIsolationAdapter(platform?: NodeJS.Platform): IIsolationAdapter;
5186
+ /** 探测当前(或指定)平台的隔离能力。 */
5187
+ export declare function detectIsolation(platform?: NodeJS.Platform): Promise<IIsolationCapability>;
5188
+ //#endregion
5189
+ //#region src/isolation/os-isolation/darwin.d.ts
5190
+ /** 生成 deny-default + 显式 allow 的 SBPL profile。 */
5191
+ export declare function buildSbplProfile(spec: IIsolationSpec): string;
5192
+ /** 探测 sandbox-exec 是否可用(非嵌套沙箱)。 */
5193
+ export declare function probeSandboxExec(): IIsolationCapability;
5194
+ /** 创建 macOS 适配器。 */
5195
+ export declare function createDarwinAdapter(): IIsolationAdapter;
5196
+ //#endregion
5197
+ //#region src/isolation/os-isolation/linux.d.ts
5198
+ /** 生成 bwrap 参数:只绑定运行时与任务目录,绝不绑定真实 home。 */
5199
+ export declare function buildBwrapArgs(spec: IIsolationSpec, command: string[]): string[];
5200
+ /** 探测 bwrap 存在且用户命名空间可用。 */
5201
+ export declare function probeBwrap(): IIsolationCapability;
5202
+ /** 创建 Linux 适配器。 */
5203
+ export declare function createLinuxAdapter(): IIsolationAdapter;
5204
+ //#endregion
5205
+ //#region src/isolation/os-isolation/windows.d.ts
5206
+ /** 创建 Windows 适配器(当前 fail-closed 占位)。 */
5207
+ export declare function createWindowsAdapter(): IIsolationAdapter;
5208
+ //#endregion
5209
+ //#region src/rl-runtime/manifest.d.ts
5210
+ /**
5211
+ * Runtime manifest schema and integrity verification (schema v2, real multi-source).
5212
+ *
5213
+ * The manifest describes real download sources for a pinned runtime: one CPython per platform (python-build-standalone
5214
+ * install_only tar.gz) + a single dashscope wheel shared across platforms (PyPI, py3-none-any). On first init the black box
5215
+ * downloads and verifies CPython per manifest, then pip --require-hashes installs dashscope and transitive deps from the bundled lockfile.
5216
+ * The manifest is a reviewed artifact shipped as a TS constant (manifest-data.ts, generated from the repo-root
5217
+ * runtime-manifest.json); SHA256 values come from official SHA256SUMS / PyPI, never invented.
5218
+ */
5219
+ /** Reviewed pinned dashscope version (upgrades require re-review + lockfile regeneration). */
5220
+ export declare const RL_DASHSCOPE_VERSION = "1.25.23";
5221
+ /** SHA256 of the dashscope==1.25.23 wheel (official PyPI value, verified). */
5222
+ export declare const RL_DASHSCOPE_WHEEL_SHA256 = "7cb2cc48fd82536202e3100e93730e92c952435bb8cbe16d45de9700e1546bcc";
5223
+ /** Reviewed pinned CPython version. */
5224
+ export declare const RL_PYTHON_VERSION = "3.11.9";
5225
+ /** Custom CPython mirror env var: replaces the GitHub release download prefix (1:1 path mapping, SHA unchanged). */
5226
+ export declare const RL_PYTHON_MIRROR_ENV = "BAILIAN_RL_PYTHON_MIRROR";
5227
+ /** Custom pip index env var: restricted regions can point at a stable PyPI mirror (Tsinghua tuna / Aliyun); a mirror lagging PyPI fails closed on missing pinned versions. */
5228
+ export declare const RL_PIP_INDEX_ENV = "BAILIAN_RL_PIP_INDEX_URL";
5229
+ /** Built-in fallback mirror: Aliyun CNPM npmmirror, 1:1 with GitHub release paths, verified byte-identical. */
5230
+ export declare const DEFAULT_PYTHON_MIRRORS: string[];
5231
+ /** Per-platform CPython download entry. */
5232
+ export interface IRuntimeManifestEntry {
5233
+ os: "darwin" | "linux";
5234
+ arch: string;
5235
+ /** python-build-standalone target triple (matches os/arch). */
5236
+ triple: string;
5237
+ pythonVersion: string;
5238
+ pythonUrl: string;
5239
+ pythonSha256: string;
5240
+ }
5241
+ /** Runtime manifest (schema v2). The dashscope wheel is shared across platforms and lives at the top level. */
5242
+ export interface IRuntimeManifest {
5243
+ schemaVersion: 2;
5244
+ dashscopeVersion: string;
5245
+ dashscopeUrl: string;
5246
+ dashscopeSha256: string;
5247
+ entries: IRuntimeManifestEntry[];
5248
+ }
5249
+ /** Parse and validate manifest text; any malformed shape/hash is rejected (fail-closed). */
5250
+ export declare function parseRuntimeManifest(text: string): IRuntimeManifest;
5251
+ /** Bundled reviewed manifest (parsed from manifest-data.ts). */
5252
+ export declare function bundledRuntimeManifest(): IRuntimeManifest;
5253
+ /** Select the platform entry by os/arch; undefined when nothing matches (caller fails closed). */
5254
+ export declare function selectManifestEntry(manifest: IRuntimeManifest, platform: NodeJS.Platform, arch: string): IRuntimeManifestEntry | undefined;
5255
+ /** Compute the byte SHA256 (hex). */
5256
+ export declare function sha256Hex(data: Buffer | string): string;
5257
+ /**
5258
+ * Build CPython download candidates (ordered, deduplicated): custom mirror (if set) → canonical → built-in fallback mirror.
5259
+ * Switching sources changes only the origin, never the SHA256; the caller verifies integrity per source and moves on after any failure. Custom manifest URLs
5260
+ * that are not GitHub canonical are never mirror-rewritten; they download as-is.
5261
+ */
5262
+ export declare function pythonDownloadCandidates(pythonUrl: string, env?: Record<string, string | undefined>): string[];
5263
+ /** Verify downloaded artifact integrity; reject immediately on mismatch (timing-safe comparison). */
5264
+ export declare function assertArtifactIntegrity(data: Buffer, expectedSha256: string): void;
5265
+ //#endregion
5266
+ //#region src/rl-runtime/manager.d.ts
5267
+ /** Dev override env var: points at a local Python dir with dashscope (the reviewed baseline version) installed. */
5268
+ export declare const RUNTIME_OVERRIDE_ENV = "BAILIAN_RL_RUNTIME";
5269
+ /** Resolved runtime (runs use the interpreter absolute path). */
5270
+ export interface IResolvedRuntime {
5271
+ runtimeRoot: string;
5272
+ pythonPath: string;
5273
+ dashscopeVersion: string;
5274
+ source: "override" | "managed";
5275
+ }
5276
+ /** Controlled command execution result (tar / python / pip self-checks). */
5277
+ export interface IRuntimeCommandResult {
5278
+ exitCode: number | null;
5279
+ stdout: string;
5280
+ stderr: string;
5281
+ }
5282
+ /** Dependency-injection seam for the install lifecycle (defaults to real fetch/spawn; mockable in unit tests). */
5283
+ export interface IRuntimeDeps {
5284
+ download(url: string): Promise<Buffer>;
5285
+ run(command: string, args: string[], options?: {
5286
+ cwd?: string;
5287
+ }): Promise<IRuntimeCommandResult>;
5288
+ }
5289
+ export interface IResolveRuntimeOptions {
5290
+ /** Manifest passed directly (takes precedence over manifestPath and the bundled manifest). */
5291
+ manifest?: IRuntimeManifest;
5292
+ /** Manifest file path (overrides the bundled manifest; for review / integration debugging). */
5293
+ manifestPath?: string;
5294
+ /** Whether first-time runtime preparation is allowed (defaults to false for non-interactive use). */
5295
+ allowInstall?: boolean;
5296
+ env?: Record<string, string | undefined>;
5297
+ platform?: NodeJS.Platform;
5298
+ arch?: string;
5299
+ deps?: IRuntimeDeps;
5300
+ }
5301
+ /** Download failure wrapper: message carries the errno; sandbox-denial codes append network-enable/proxy guidance (mirrors cannot help). */
5302
+ export declare function runtimeDownloadFailure(url: string, error: unknown): BailianError;
5303
+ /** Absolute path of the extracted CPython interpreter (install_only tarball top level is python/). */
5304
+ export declare function managedPythonPath(root: string, platform: NodeJS.Platform): string;
5305
+ /** Managed runtime-id for the current baseline (bundled reviewed manifest); undefined when this platform has no entry. */
5306
+ export declare function currentManagedRuntimeId(platform?: NodeJS.Platform, arch?: string): string | undefined;
5307
+ /** Resolve the runtime: dev override first, then managed READY, then first-time download + install if allowed. */
5308
+ export declare function resolveRuntime(options?: IResolveRuntimeOptions): Promise<IResolvedRuntime>;
5309
+ /** Full install lifecycle; an interruption never writes READY, so the next attempt rebuilds in a fresh directory. */
5310
+ export declare function installRuntime(entry: IRuntimeManifestEntry, manifest: IRuntimeManifest, root: string, deps: IRuntimeDeps, platform: NodeJS.Platform, env?: Record<string, string | undefined>): Promise<void>;
5311
+ //#endregion
5312
+ //#region src/rl-runtime/sandbox.d.ts
5313
+ /** API credential injected into the sandbox (structurally compatible with client.exportApiCredential()). */
5314
+ export interface ISandboxCredential {
5315
+ token: string;
5316
+ baseUrl?: string;
5317
+ }
5318
+ export interface ISandboxRunInput {
5319
+ /** dashscope SDK args (without the interpreter and -I -m dashscope prefix, injected by the black box). */
5320
+ sdkArgs: string[] | ((layout: ITaskDirLayout) => string[]);
5321
+ credential: ISandboxCredential;
5322
+ /** Staging input after the task dir is ready and before spawn; returning a YAML string writes --config. */
5323
+ prepare?: (layout: ITaskDirLayout) => string | void;
5324
+ timeoutMs?: number;
5325
+ maxOutputBytes?: number;
5326
+ signal?: AbortSignal;
5327
+ /** Allow first-time runtime download/preparation (interactive run). */
5328
+ allowInstall?: boolean;
5329
+ /** Real credential paths the OS must deny reads for; defaults to denying the real ~/.dashscope. */
5330
+ credentialDenyPaths?: string[];
5331
+ /** Runtime resolution overrides (manifest/deps/platform) for tests and management commands. */
5332
+ runtimeOptions?: IResolveRuntimeOptions;
5333
+ adapter?: IIsolationAdapter;
5334
+ }
5335
+ /** Normalize the in-sandbox SDK result: timeout/non-zero exit passes through as an error; success returns parsed JSON. */
5336
+ export declare function normalizeSandboxResult(result: IIsolationResult): unknown;
5337
+ /** The black box's sole execution entry: manifest in → internal init + confinement execution → normalized result out. */
5338
+ export declare function executeInSandbox(input: ISandboxRunInput): Promise<unknown>;
5339
+ //#endregion
5340
+ //#region src/rl-runtime/doctor.d.ts
5341
+ /** Single check result. */
5342
+ export interface IDoctorCheck {
5343
+ name: string;
5344
+ /** Required fail/skip fails the report; enhanced degradation does not block. */
5345
+ required: boolean;
5346
+ status: "pass" | "fail" | "degraded" | "skip";
5347
+ detail?: string;
5348
+ }
5349
+ export interface IDoctorReport {
5350
+ checks: IDoctorCheck[];
5351
+ /** True only when every required check passes. */
5352
+ ok: boolean;
5353
+ }
5354
+ export interface IDoctorOptions {
5355
+ /** Resolved runtime; when missing, runtime-related checks are skipped. */
5356
+ runtime?: IResolvedRuntime;
5357
+ /** Real credential paths (targets of the closed-loop negative test), e.g. the real ~/.dashscope. */
5358
+ credentialDenyPaths?: string[];
5359
+ adapter?: IIsolationAdapter;
5360
+ platform?: NodeJS.Platform;
5361
+ /** Per-self-check timeout (ms). */
5362
+ timeoutMs?: number;
5363
+ /** Whether to probe host outbound network reachability (enhanced; off by default so doctor stays usable offline). */
5364
+ checkHostNetwork?: boolean;
5365
+ /** Host network probe targets (defaults to the API / CPython download / PyPI host trio). */
5366
+ hostNetworkTargets?: {
5367
+ host: string;
5368
+ port: number;
5369
+ }[];
5370
+ /** Probe injection seam (unit tests inject results, no real outbound); returns an errno, or undefined for success. */
5371
+ hostNetworkProbe?: (host: string, port: number) => Promise<string | undefined>;
5372
+ }
5373
+ /** Run doctor and return the per-check report. */
5374
+ export declare function runRuntimeDoctor(options?: IDoctorOptions): Promise<IDoctorReport>;
5375
+ /** Throw when doctor fails overall (for the command layer to normalize the exit code). */
5376
+ export declare function assertDoctorPassed(report: IDoctorReport): void;
5377
+ //#endregion
5378
+ //#region src/rl-runtime/locks.d.ts
5379
+ /**
5380
+ * Bundled dependency lockfile (universal, wheel hashes for all platforms).
5381
+ *
5382
+ * Generated by uv pip compile --universal --generate-hashes --python-version 3.11 against
5383
+ * dashscope==1.25.23 (explicitly adding runtime deps the SDK does not declare — pyyaml/tenacity —
5384
+ * plus fastapi/uvicorn/opentelemetry/tiktoken used by the RL function chain); written to disk on first black-box init
5385
+ * and installed via pip install --require-hashes, making transitive deps reproducible and guarding against supply-chain tampering.
5386
+ * Regenerate when upgrading the pinned dashscope version; do not edit by hand.
5387
+ */
5388
+ /** Full lockfile text (directly consumable by pip --require-hashes). */
5389
+ export declare const RL_DEPENDENCY_LOCK: string;
5390
+ //#endregion
4506
5391
  //#region src/deploy/types.d.ts
4507
5392
  /**
4508
5393
  * Model-deployment API types.