-
Notifications
You must be signed in to change notification settings - Fork 19
添加agent studio的cli能力 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chenanran555
wants to merge
12
commits into
main
Choose a base branch
from
feat/cma
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
添加agent studio的cli能力 #116
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6329427
feat(agent): add agent command group with session and state management
chenanran555 d6bd38a
feat(agent): agent相关cli命令的client层功能,对齐cli client的基础能力
chenanran555 1c9dac2
feat(cma): login时初始化agent相关的baseUrl
chenanran555 7cbd61d
Merge remote-tracking branch 'origin/main' into feat/cma
chenanran555 9e59b01
feat: update openagentpack sdk
chenanran555 1da3367
feat: fix ci
chenanran555 64335a6
feat(agent): rename cli command to managed-agent
chenanran555 9cad199
feat(agent): validate by client apiKey auth type
chenanran555 1d589c5
Merge remote-tracking branch 'origin/main' into feat/cma
chenanran555 1bf4fec
feat(agent): support --dry-run for all local and remote mutations
chenanran555 1e6165d
fix(agent): guarantee single valid JSON on stdout for --output json
chenanran555 247bb82
test(agent): cover config-write, profile, logout and error-mapping au…
chenanran555 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,7 @@ node_modules | |
| dist | ||
| *.log | ||
| .DS_Store | ||
| outputs/ | ||
| outputs/ | ||
| # agents | ||
| agents.state.json | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| version: "1" | ||
|
|
||
| providers: | ||
| bailian: | ||
| # bl auth login --api-key <key> sets DASHSCOPE_API_KEY; --agentstudio-base-url <url> sets BAILIAN_BASE_URL | ||
| api_key: ${DASHSCOPE_API_KEY} | ||
| base_url: ${BAILIAN_BASE_URL} | ||
|
|
||
| defaults: | ||
| provider: bailian | ||
|
|
||
| environments: | ||
| dev: | ||
| config: | ||
| type: cloud | ||
| networking: | ||
| type: unrestricted | ||
|
|
||
| agents: | ||
| assistant: | ||
| description: "General-purpose assistant" | ||
| model: qwen3.7-max | ||
| instructions: | | ||
| You are a helpful assistant. | ||
| environment: dev | ||
| tools: | ||
| builtin: [bash, read, glob, grep] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/commands/src/commands/managed-agent/_engine/address-utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { ResourceAddress } from "@openagentpack/sdk"; | ||
|
|
||
| /** Full state address: provider.type.name */ | ||
| export function formatResourceAddress(address: ResourceAddress): string { | ||
| return `${address.provider}.${address.type}.${address.name}`; | ||
| } | ||
|
|
||
| /** CLI display short label: type.name (provider) */ | ||
| export function formatResourceLabel(address: ResourceAddress): string { | ||
| return `${address.type}.${address.name} (${address.provider})`; | ||
| } |
91 changes: 91 additions & 0 deletions
91
packages/commands/src/commands/managed-agent/_engine/config-loader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { | ||
| createProjectRuntime, | ||
| type LoadedProjectConfig, | ||
| type ProjectRuntimeContext, | ||
| resolveProjectConfig, | ||
| UserError, | ||
| } from "@openagentpack/sdk"; | ||
| import { | ||
| assertProviderCredentials, | ||
| type CredentialHost, | ||
| injectProviderCredentials, | ||
| prepareProviderEnv, | ||
| scrubCredentialEnv, | ||
| } from "./credentials.ts"; | ||
| import { loadFileState } from "./file-state-manager.ts"; | ||
| import { type HostContext, installSdkTransport } from "./transport.ts"; | ||
|
|
||
| export { CREDENTIALS_NOTE } from "./credentials.ts"; | ||
|
|
||
| interface AgentConfigOptions { | ||
| resolveEnv?: boolean; | ||
| projectName?: string; | ||
| statePath?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve agents.yaml with credentials injected the bl way and scrubbed from the | ||
| * environment — the shared credential spine for every SDK-engine command: | ||
| * 1. prepare env (SDK bootstrap for non-bailian + placeholders so interpolation | ||
| * never throws on a value we're about to supply/reject) | ||
| * 2. resolve + interpolate the config | ||
| * 3. override the bailian block with the CLI auth chain's credential (in-memory) | ||
| * 4. scrub all credential vars from process.env (real values now live only in | ||
| * the config object → provider adapters, never the environment) | ||
| * 5. fail with a CLI-authoritative AUTH error if any provider's key is empty | ||
| */ | ||
| export async function resolveAgentProjectConfig( | ||
| host: CredentialHost, | ||
| filePath: string, | ||
| options: AgentConfigOptions = {}, | ||
| ): Promise<LoadedProjectConfig> { | ||
| prepareProviderEnv(); | ||
| const resolved = await resolveProjectConfig(filePath, options); | ||
| injectProviderCredentials(resolved.config.providers, host); | ||
| scrubCredentialEnv(); | ||
| assertProviderCredentials(resolved.config.providers); | ||
| return resolved; | ||
| } | ||
|
|
||
| /** | ||
| * Build a full ProjectRuntimeContext from a config file path — the standard | ||
| * entry point for agent commands that need the SDK engine. Mirrors OpenAgentPack | ||
| * CLI's buildCliRuntime: resolve config → load local state → assemble runtime. | ||
| * Takes the host context first so every SDK-engine command wires the | ||
| * instrumented transport (UA / tracking headers / verbose) and the bl-resolved, | ||
| * in-memory-injected credential ({@link resolveAgentProjectConfig}) by construction. | ||
| */ | ||
| export async function buildAgentRuntime( | ||
| host: HostContext & CredentialHost, | ||
| filePath: string, | ||
| options: AgentConfigOptions = {}, | ||
| ): Promise<ProjectRuntimeContext & { configPath: string }> { | ||
| installSdkTransport(host); | ||
| const { config, configPath, projectName } = await resolveAgentProjectConfig( | ||
| host, | ||
| filePath, | ||
| options, | ||
| ); | ||
| const state = await loadFileState(configPath, options.statePath, projectName); | ||
| const ctx = createProjectRuntime({ | ||
| projectName, | ||
| config, | ||
| state, | ||
| configPath, | ||
| providers: config.providers, | ||
| }); | ||
| return { ...ctx, configPath }; | ||
| } | ||
|
|
||
| /** Ensure a user-supplied --provider value is actually configured in agents.yaml. */ | ||
| export function assertProviderConfigured( | ||
| ctx: ProjectRuntimeContext, | ||
| provider: string | undefined, | ||
| ): void { | ||
| if (!provider || provider === "all") return; | ||
| if (ctx.providers.has(provider)) return; | ||
| const available = Array.from(ctx.providers.keys()).join(", ") || "none"; | ||
| throw new UserError( | ||
| `Provider '${provider}' is not configured. Available providers: ${available}.`, | ||
| ); | ||
| } |
23 changes: 23 additions & 0 deletions
23
packages/commands/src/commands/managed-agent/_engine/console-capture.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * Redirect `console.log` / `console.info` to stderr while `fn` runs. | ||
| * | ||
| * The OpenAgentPack SDK's provider adapters emit progress/debug logging via | ||
| * `console.log` (e.g. `[skill-upload]`), which would corrupt bl's stdout data | ||
| * channel in `--output json` mode. Wrapping SDK calls that may log keeps stdout | ||
| * a clean data channel. Restores the originals on completion. | ||
| */ | ||
| export async function withStdoutProtected<T>(fn: () => Promise<T>): Promise<T> { | ||
| const originalLog = console.log; | ||
| const originalInfo = console.info; | ||
| const toStderr = (...args: unknown[]): void => { | ||
| process.stderr.write(`${args.map((arg) => String(arg)).join(" ")}\n`); | ||
| }; | ||
| console.log = toStderr; | ||
| console.info = toStderr; | ||
| try { | ||
| return await fn(); | ||
| } finally { | ||
| console.log = originalLog; | ||
| console.info = originalInfo; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] SDK 的 Node 版本破坏现有发布契约
当前引入的
@openagentpack/sdk声明engines.node >=22,但bailian-cli、bailian-cli-commands和 README 仍承诺 Node >=18.17。Agent commands 又通过 commands index 静态导出,SDK 没有被安全隔离到bl cma执行时才加载,因此 Node 18/20 下可能影响整个bl的启动。请先统一运行时契约:要么让 SDK 支持并验证现有 Node 范围,要么同步提升所有发布包、README、CI 和发布检查的 Node 下限。需要增加最低支持 Node 版本下的安装及
bl --helpsmoke。