用途:为 Dune 应用添加基于 Pyodide 的客户端 Python 工具执行能力。Atlas 智能体可在其 CDF 配置中定义 type 为 runPythonCode 的 Python 工具;被调用时以工具确认(自动允许)加客户端工具动作的形式到达,库会自动从智能体配置获取 Python 代码并通过提供的 pythonRuntime 执行。开发者只需两步:用 usePyodideRuntime 获取运行时实例,并把 pythonRuntime 传给 useAtlasChat;不需要编写 PythonToolConfig 条目。
主要能力:usePyodideRuntime 会加载 Pyodide(约 30MB,首次加载后缓存)、安装依赖包并向 Python 环境注入 Cognite SDK 凭据。其返回字段包括 runtime(未就绪时为 undefined)、loading、error、progress(含 stage 与 percent)、isReady(即 !loading && !error && runtime !== undefined)。
使用方式:先安装 pyodide@0.29.3,版本必须与运行时加载的 CDN 构件一致,否则报错,命令为 pnpm add pyodide@0.29.3、npm install pyodide@0.29.3 或 yarn add pyodide@0.29.3。在调用 useAtlasChat 的组件中从 pyodide 导入 loadPyodide,从 @cognite/dune-industrial-components/atlas-agent/pyodide 导入 usePyodideRuntime,传入 loadPyodide、client 及可选的 requirements(如 pandas、numpy)。把返回的 runtime 作为 pythonRuntime 传给 useAtlasChat,并照常传入 agentExternalId 等参数;Python 工具无需通过 tools 声明,智能体已从 CDF 配置知晓。加载期间应禁用整个输入区(如 disabled={isStreaming || pythonLoading})及首页建议项。加载指示器放在输入框上方而非消息列表内,用紧凑的 pill 或 badge 显示 stage 与百分比,错误单独显示徽标。
限制:依赖 @cognite/dune-industrial-components、@sinclair/typebox、ajv、ajv-formats 应已安装,否则需一并安装(参见 integrate-atlas-chat 技能)。首次加载约需 30–60 秒,后续从浏览器缓存加载小于 2 秒。其他平台或版本兼容性资料暂未提供。