UNPKG

@agentled/cli

Version:

CLI for Agentled — manage workflows, apps, and knowledge from the command line. Zero context-window cost for AI agents.

75 lines 3.12 kB
/** * Read the canonical company context text from the workspace KG. * * Used by `agentled setup` to decide whether to prompt the user for company * information or skip straight to "workspace already configured". We probe * The product stores editable company context at `company.profile` and * `company.products`. Older CLI setup releases briefly wrote * `knowledge.company.*`, so those keys are read as aliases only. * * Uses the typed `AgentledApiClient.getKnowledgeText` surface. Failures are * non-fatal: setup must not break on a network blip or a missing endpoint. */ const COMPANY_PROFILE_KEYS = ['company.profile', 'knowledge.company.profile']; const COMPANY_PRODUCTS_KEYS = ['company.products', 'knowledge.company.products']; function isMissingTextError(error) { const message = String(error?.message || ''); return message.includes('not found') || message.includes('404'); } async function fetchKnowledgeText(client, keys) { let firstReadError = null; for (const key of keys) { try { const res = (await client.getKnowledgeText(key)); if (!res) continue; // The API returns `content` for upsert/get parity, but tolerate `text` // as a defensive fallback for older response shapes. const value = res.content ?? res.text ?? null; if (typeof value === 'string' && value.trim().length > 0) { return value; } } catch (error) { if (!isMissingTextError(error)) { firstReadError = error instanceof Error ? error : new Error(String(error)); break; } } } if (firstReadError) throw firstReadError; return null; } export async function probeCompanyKnowledge(client) { try { const [profile, products] = await Promise.all([ fetchKnowledgeText(client, COMPANY_PROFILE_KEYS), fetchKnowledgeText(client, COMPANY_PRODUCTS_KEYS), ]); const profilePresent = typeof profile === 'string' && profile.trim().length > 0; const productsPresent = typeof products === 'string' && products.trim().length > 0; return { profilePresent, productsPresent, profilePreview: profilePresent && profile ? profile.trim().slice(0, 120) : undefined, }; } catch (err) { return { profilePresent: false, productsPresent: false, error: err?.message ?? String(err), }; } } export function summarizeKnowledgeProbe(r) { if (r.error) return `Could not read workspace knowledge (${r.error}). You can run \`agentled workspace company-profile\` later.`; if (r.profilePresent) { const preview = r.profilePreview ? ` — "${r.profilePreview}${r.profilePreview.length >= 120 ? '…' : ''}"` : ''; return `Workspace already configured (company.profile is set${preview}).`; } return 'Workspace knowledge is empty — collecting company profile now.'; } //# sourceMappingURL=knowledge-probe.js.map