蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

用本地 Node 验证练习配置和文件访问范围

JAVASCRIPTNode.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。review-profile.mjs
review-profile.mjs54 行
// Check a small training profile without starting a Gateway or applying a config.
import { readFileSync } from "node:fs";

const approvedKeys = {
  root: new Set(["gateway", "channels"]),
  gateway: new Set(["mode", "bind", "port", "auth"]),
  auth: new Set(["mode", "token"]),
  token: new Set(["source", "provider", "id"]),
};

function object(value) {
  return value !== null && typeof value === "object" && !Array.isArray(value);
}

function hasExtra(value, keys) {
  return !object(value) || Object.keys(value).some(key => !keys.has(key));
}

function inspect(profile) {
  if (hasExtra(profile, approvedKeys.root)) return ["unsupported_profile_field"];
  const { gateway, channels = {} } = profile;
  const issues = [];
  if (!object(channels) || Object.keys(channels).length) issues.push("channels_not_empty");
  if (hasExtra(gateway, approvedKeys.gateway)) return [...issues, "invalid_gateway_shape"];
  const { mode, bind, port, auth } = gateway;
  if (mode !== "local") issues.push("gateway_not_local");
  if (bind !== "loopback") issues.push("gateway_not_loopback");
  if (!Number.isInteger(port) || port < 1024 || port > 65535) issues.push("invalid_training_port");
  if (hasExtra(auth, approvedKeys.auth) || auth.mode !== "token") return [...issues, "token_auth_required"];
  const ref = auth.token;
  if (hasExtra(ref, approvedKeys.token) || ref.source !== "env" || ref.provider !== "default"
      || ref.id !== "MBSKY_DEMO_GATEWAY_TOKEN") issues.push("training_env_reference_required");
  return issues;
}

function examine(path) {
  let profile;
  try {
    profile = JSON.parse(readFileSync(path, "utf8"));
  } catch (error) {
    if (error.code === "ERR_ACCESS_DENIED") return ["file_scope_denied"];
    if (error instanceof SyntaxError) return ["malformed_json"];
    throw error;
  }
  return inspect(profile);
}

const [path] = process.argv.slice(2);
if (!path) throw new Error("Pass the absolute path of the training JSON profile.");
const issues = examine(path);
console.log(JSON.stringify({ version: process.version, status: issues.length ? "blocked" : "ready_for_official_validation",
  issues, gateway_started: false, configuration_written: false }));
process.exitCode = issues.length ? 2 : 0;
本例需在 Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。

入口文件:projects/ai-agent-openclaw-profile/review-profile.mjs

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 review-profile.mjs,或下载右侧课程工程包。
  2. 确认本地已准备 Node.js 24.22.1,独立课程 JSON 与文件许可;无用户配置和第三方账户。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:AI Agent(智能体)

课程关联工程包(登记关联48章) · 含当前章节或实例 · mbskycom202612a3073.zip

下载课程关联工程包:AI Agent(智能体)

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3095.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习