@agentled/cli
Version:
CLI for Agentled — manage workflows, apps, and knowledge from the command line. Zero context-window cost for AI agents.
107 lines • 3.65 kB
JavaScript
/**
* AgentledClient — CLI-facing wrapper around the shared Agentled external API client.
*
* Reads credentials from:
* 1. AGENTLED_API_KEY env var
* 2. ~/.agentled/config.json (active workspace profile)
*
* Base URL from AGENTLED_URL env var or config file (default: https://www.agentled.app)
*/
import { AgentledApiClient, DEFAULT_AGENTLED_URL, deleteAgentledConfig, getAgentledBaseUrl, getAgentledConfigPath, listAgentledWorkspaceProfiles, loadAgentledConfig, removeAgentledWorkspaceProfile, resolveAgentledWorkspaceProfile, saveAgentledConfig, setActiveAgentledWorkspaceProfile, upsertAgentledWorkspaceProfile, } from '@agentled/core';
export { DEFAULT_AGENTLED_URL };
export function loadConfig() {
return loadAgentledConfig();
}
export function getWorkspaceSelector() {
const workspace = process.env.AGENTLED_WORKSPACE?.trim();
return workspace || undefined;
}
export function listWorkspaces(config = loadAgentledConfig()) {
return listAgentledWorkspaceProfiles(config);
}
export function getSelectedWorkspace(config = loadAgentledConfig(), workspaceRef = getWorkspaceSelector()) {
return resolveAgentledWorkspaceProfile(config, workspaceRef);
}
export function getBaseUrl() {
const config = loadAgentledConfig();
return getAgentledBaseUrl({
baseUrl: process.env.AGENTLED_URL,
config,
workspace: getWorkspaceSelector(),
});
}
export function saveConfig(config) {
saveAgentledConfig(config);
}
export function deleteConfig() {
return deleteAgentledConfig();
}
export function getConfigPath() {
return getAgentledConfigPath();
}
export function saveWorkspaceProfile(input) {
const nextConfig = upsertAgentledWorkspaceProfile(loadAgentledConfig(), input);
saveAgentledConfig(nextConfig);
return nextConfig;
}
export function setActiveWorkspace(workspaceRef) {
const nextConfig = setActiveAgentledWorkspaceProfile(loadAgentledConfig(), workspaceRef);
saveAgentledConfig(nextConfig);
return nextConfig;
}
export function removeWorkspace(workspaceRef) {
const nextConfig = removeAgentledWorkspaceProfile(loadAgentledConfig(), workspaceRef);
if (listAgentledWorkspaceProfiles(nextConfig).length === 0) {
deleteAgentledConfig();
return nextConfig;
}
saveAgentledConfig(nextConfig);
return nextConfig;
}
export function resolveAuthContext() {
const config = loadAgentledConfig();
const workspace = getSelectedWorkspace(config);
const baseUrl = getAgentledBaseUrl({
baseUrl: process.env.AGENTLED_URL,
config,
workspace: getWorkspaceSelector(),
});
if (process.env.AGENTLED_API_KEY) {
return {
authenticated: true,
source: 'environment',
apiKey: process.env.AGENTLED_API_KEY,
baseUrl,
workspace,
config,
};
}
if (workspace?.apiKey) {
return {
authenticated: true,
source: 'config',
apiKey: workspace.apiKey,
baseUrl,
workspace,
config,
};
}
return {
authenticated: false,
source: 'none',
baseUrl,
workspace,
config,
};
}
export class AgentledClient extends AgentledApiClient {
constructor() {
const authContext = resolveAuthContext();
super({
apiKey: authContext.apiKey || '',
baseUrl: authContext.baseUrl || DEFAULT_AGENTLED_URL,
missingAuthMessage: 'Not authenticated. Run "agentled auth login" or set AGENTLED_API_KEY.',
});
}
}
//# sourceMappingURL=client.js.map