@cortex-agent/server 2026.8.3-2 → 2026.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/config/thread-templates/agents/benchmark-coder.json +2 -2
- package/defaults/config/thread-templates/agents/benchmark-fixer.json +17 -0
- package/defaults/config/thread-templates/agents/benchmark-reviewer.json +5 -5
- package/defaults/config/thread-templates/templates/benchmark-coder-review-fix.json +21 -0
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +1 -0
- package/defaults/prompts/directives/benchmark-coder.md +1 -0
- package/defaults/prompts/directives/benchmark-fixer.md +1 -0
- package/defaults/prompts/directives/benchmark-reviewer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-coder.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-fixer.md +1 -0
- package/defaults/prompts/systemPrompts/benchmark-reviewer.md +1 -0
- package/dist/agent-adapter/capabilities.d.ts +32 -1
- package/dist/agent-adapter/capabilities.js +39 -1
- package/dist/agent-adapter/claude/adapter.d.ts +15 -0
- package/dist/agent-adapter/claude/adapter.js +29 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -2
- package/dist/agent-adapter/claude/spawn-args.js +29 -6
- package/dist/agent-adapter/index.js +11 -1
- package/dist/agent-adapter/normalize/tool-names.d.ts +4 -0
- package/dist/agent-adapter/normalize/tool-names.js +10 -0
- package/dist/agent-adapter/pi/adapter.d.ts +20 -8
- package/dist/agent-adapter/pi/adapter.js +130 -35
- package/dist/agent-adapter/pi/agent-dir.d.ts +20 -53
- package/dist/agent-adapter/pi/agent-dir.js +48 -89
- package/dist/agent-adapter/pi/custom-catalog.d.ts +10 -0
- package/dist/agent-adapter/pi/custom-catalog.js +42 -0
- package/dist/agent-adapter/pi/defaults.d.ts +9 -0
- package/dist/agent-adapter/pi/defaults.js +14 -4
- package/dist/agent-adapter/pi/discovery.d.ts +1 -3
- package/dist/agent-adapter/pi/discovery.js +3 -15
- package/dist/agent-adapter/pi/event-parser.js +8 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +31 -6
- package/dist/agent-adapter/pi/mcp-duration.d.ts +28 -0
- package/dist/agent-adapter/pi/mcp-duration.js +48 -0
- package/dist/agent-adapter/pi/policy-guard.d.ts +40 -0
- package/dist/agent-adapter/pi/policy-guard.js +111 -0
- package/dist/agent-adapter/pi/providers-config.d.ts +62 -0
- package/dist/agent-adapter/pi/providers-config.js +101 -0
- package/dist/agent-adapter/pi/quota-probe.d.ts +11 -0
- package/dist/agent-adapter/pi/quota-probe.js +36 -0
- package/dist/agent-adapter/pi/quota-sink.d.ts +25 -0
- package/dist/agent-adapter/pi/quota-sink.js +31 -0
- package/dist/agent-adapter/pi/session-files.d.ts +2 -0
- package/dist/agent-adapter/pi/session-files.js +19 -0
- package/dist/agent-adapter/pi/session-support.d.ts +14 -3
- package/dist/agent-adapter/pi/session-support.js +8 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +11 -1
- package/dist/agent-adapter/pi/spawn-args.js +13 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +2 -2
- package/dist/agent-adapter/pi/tool-shims.js +32 -21
- package/dist/agent-adapter/pi/web-search.js +36 -8
- package/dist/agent-adapter/types.d.ts +14 -0
- package/dist/core/locales/en.d.ts +54 -1
- package/dist/core/locales/en.js +2 -0
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/providers.d.ts +45 -0
- package/dist/core/locales/slices/providers.js +95 -0
- package/dist/core/locales/zh.js +2 -0
- package/dist/core/resilient-watch.d.ts +28 -0
- package/dist/core/resilient-watch.js +110 -0
- package/dist/core/settings.js +15 -20
- package/dist/core/types/agent-types.d.ts +6 -0
- package/dist/core/types/thread-types.d.ts +21 -3
- package/dist/domain/agent-run/agent-run-cli.js +3 -1
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.d.ts +31 -0
- package/dist/domain/agent-run/benchmark-local-thread-orchestrator.js +231 -24
- package/dist/domain/agent-run/benchmark-thread-identity.d.ts +15 -2
- package/dist/domain/agent-run/benchmark-thread-identity.js +123 -34
- package/dist/domain/agent-run/identity.d.ts +5 -0
- package/dist/domain/agent-run/identity.js +4 -1
- package/dist/domain/agent-run/journal.d.ts +3 -2
- package/dist/domain/agent-run/manifest.js +11 -4
- package/dist/domain/agent-run/pinned-node-process.d.ts +4 -0
- package/dist/domain/agent-run/pinned-node-process.js +9 -0
- package/dist/domain/agent-run/role-surface.d.ts +2 -2
- package/dist/domain/agent-run/role-surface.js +7 -3
- package/dist/domain/agent-run/run-config.d.ts +10 -1
- package/dist/domain/agent-run/run-config.js +57 -6
- package/dist/domain/agent-run/runner.js +149 -31
- package/dist/domain/agents/facade.d.ts +37 -122
- package/dist/domain/agents/facade.js +47 -115
- package/dist/domain/agents/spawn-config.d.ts +135 -0
- package/dist/domain/agents/spawn-config.js +121 -0
- package/dist/domain/benchmark/accounting-reconciliation.d.ts +98 -0
- package/dist/domain/benchmark/accounting-reconciliation.js +218 -0
- package/dist/domain/benchmark/arm-schema.d.ts +43 -0
- package/dist/domain/benchmark/arm-schema.js +243 -0
- package/dist/domain/benchmark/capabilities.d.ts +4 -0
- package/dist/domain/benchmark/capabilities.js +54 -0
- package/dist/domain/benchmark/decimal-text.d.ts +27 -0
- package/dist/domain/benchmark/decimal-text.js +67 -0
- package/dist/domain/benchmark/lease-echo.d.ts +43 -0
- package/dist/domain/benchmark/lease-echo.js +56 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.d.ts +14 -0
- package/dist/domain/benchmark/policy-backed-runtime-deps.js +47 -0
- package/dist/domain/benchmark/policy-compiler.d.ts +68 -0
- package/dist/domain/benchmark/policy-compiler.js +680 -0
- package/dist/domain/benchmark/resolved-policy.d.ts +110 -0
- package/dist/domain/benchmark/resolved-policy.js +195 -0
- package/dist/domain/benchmark/trial-adapter-factory.d.ts +38 -0
- package/dist/domain/benchmark/trial-adapter-factory.js +165 -0
- package/dist/domain/benchmark/trial-thread-adapter.d.ts +25 -0
- package/dist/domain/benchmark/trial-thread-adapter.js +106 -0
- package/dist/domain/benchmark/variant-proposal.d.ts +45 -0
- package/dist/domain/benchmark/variant-proposal.js +42 -0
- package/dist/domain/benchmark/workspace-lease.d.ts +99 -0
- package/dist/domain/benchmark/workspace-lease.js +272 -0
- package/dist/domain/costs/codex-quota.d.ts +29 -0
- package/dist/domain/costs/codex-quota.js +102 -0
- package/dist/domain/costs/cost-tracker.d.ts +48 -9
- package/dist/domain/costs/cost-tracker.js +74 -18
- package/dist/domain/costs/rate-limit-throttle.d.ts +23 -1
- package/dist/domain/costs/rate-limit-throttle.js +61 -6
- package/dist/domain/costs/resume-registry.d.ts +3 -1
- package/dist/domain/costs/resume-registry.js +10 -1
- package/dist/domain/mcp/tools/benchmark-thread-run.d.ts +26 -2
- package/dist/domain/mcp/tools/benchmark-thread-run.js +63 -20
- package/dist/domain/mcp/tools/cost.js +15 -6
- package/dist/domain/pi-providers/custom-provider-model.d.ts +53 -0
- package/dist/domain/pi-providers/custom-provider-model.js +122 -0
- package/dist/domain/pi-providers/custom-provider-service.d.ts +59 -0
- package/dist/domain/pi-providers/custom-provider-service.js +143 -0
- package/dist/domain/pi-providers/gateway-route-store.d.ts +23 -0
- package/dist/domain/pi-providers/gateway-route-store.js +78 -0
- package/dist/domain/pi-providers/index.d.ts +4 -0
- package/dist/domain/pi-providers/index.js +8 -0
- package/dist/domain/pi-providers/models-json-store.d.ts +6 -0
- package/dist/domain/pi-providers/models-json-store.js +77 -0
- package/dist/domain/scheduling/jobs/_shared.d.ts +4 -1
- package/dist/domain/scheduling/jobs/_shared.js +11 -2
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +49 -54
- package/dist/domain/sessions/session-lifecycle.d.ts +22 -0
- package/dist/domain/sessions/session-lifecycle.js +20 -1
- package/dist/domain/system/system-notice.d.ts +4 -1
- package/dist/domain/system/system-notice.js +6 -2
- package/dist/domain/tasks/dispatch-utils.d.ts +0 -4
- package/dist/domain/tasks/dispatch-utils.js +24 -37
- package/dist/domain/threads/runner.d.ts +16 -1
- package/dist/domain/threads/runner.js +62 -8
- package/dist/domain/threads/template-loader.d.ts +5 -0
- package/dist/domain/threads/template-loader.js +120 -36
- package/dist/domain/threads/template-validate.d.ts +244 -0
- package/dist/domain/threads/template-validate.js +574 -0
- package/dist/domain/threads/template-validate.parity.d.ts +1 -0
- package/dist/domain/threads/template-validate.parity.js +47 -0
- package/dist/domain/threads/template-writer.d.ts +55 -0
- package/dist/domain/threads/template-writer.js +131 -0
- package/dist/domain/ui-service/app-router.d.ts +143 -1
- package/dist/domain/ui-service/app-router.js +29 -3
- package/dist/domain/ui-service/input-schemas.d.ts +228 -4
- package/dist/domain/ui-service/input-schemas.js +132 -1
- package/dist/domain/ui-service/mutate/config.d.ts +10 -1
- package/dist/domain/ui-service/mutate/config.js +45 -5
- package/dist/domain/ui-service/mutate/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/mutate/custom-providers.js +37 -0
- package/dist/domain/ui-service/mutate/profiles.d.ts +21 -0
- package/dist/domain/ui-service/mutate/profiles.js +156 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +53 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +25 -1
- package/dist/domain/ui-service/mutate/system.d.ts +2 -1
- package/dist/domain/ui-service/mutate/system.js +17 -3
- package/dist/domain/ui-service/mutate/thread-templates.d.ts +4 -0
- package/dist/domain/ui-service/mutate/thread-templates.js +71 -0
- package/dist/domain/ui-service/query/config.js +30 -0
- package/dist/domain/ui-service/query/custom-providers.d.ts +8 -0
- package/dist/domain/ui-service/query/custom-providers.js +13 -0
- package/dist/domain/ui-service/query/machine-detail.d.ts +2 -0
- package/dist/domain/ui-service/query/machine-detail.js +56 -0
- package/dist/domain/ui-service/query/machine-probe.d.ts +18 -0
- package/dist/domain/ui-service/query/machine-probe.js +136 -0
- package/dist/domain/ui-service/query/schedules.js +5 -0
- package/dist/domain/ui-service/query/sessions.js +8 -2
- package/dist/domain/ui-service/query/thread-template-detail.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-template-detail.js +94 -0
- package/dist/domain/ui-service/query/thread-templates.d.ts +5 -3
- package/dist/domain/ui-service/query/thread-templates.js +44 -7
- package/dist/domain/ui-service/types.d.ts +298 -7
- package/dist/domain/ui-service/ui-service.js +27 -3
- package/dist/entry/app.js +24 -3
- package/dist/entry/auth-cli.d.ts +4 -1
- package/dist/entry/auth-cli.js +10 -2
- package/dist/entry/cli-help.js +6 -2
- package/dist/entry/cli.js +2 -1
- package/dist/entry/daemon.d.ts +0 -11
- package/dist/entry/daemon.js +5 -49
- package/dist/entry/provider-cli.d.ts +16 -0
- package/dist/entry/provider-cli.js +203 -0
- package/dist/events/event-types.d.ts +2 -1
- package/dist/orchestration/agent-runner.js +3 -2
- package/dist/orchestration/routing/commands/cost.d.ts +8 -0
- package/dist/orchestration/routing/commands/cost.js +93 -21
- package/dist/orchestration/routing/commands/login-custom.d.ts +26 -0
- package/dist/orchestration/routing/commands/login-custom.js +89 -0
- package/dist/orchestration/routing/commands/login.d.ts +3 -0
- package/dist/orchestration/routing/commands/login.js +7 -0
- package/dist/orchestration/routing/message-router.js +48 -33
- package/dist/orchestration/routing/webhook.js +1 -1
- package/dist/orchestration/session-events.d.ts +2 -1
- package/dist/orchestration/session-events.js +1 -0
- package/dist/orchestration/thread-callback.js +1 -1
- package/dist/store/conversation-history-repo.d.ts +5 -1
- package/dist/store/conversation-history-repo.js +2 -1
- package/dist/store/cost-repo.d.ts +17 -0
- package/dist/store/cost-repo.js +47 -5
- package/dist/store/profile-repo.d.ts +0 -10
- package/dist/store/profile-repo.js +34 -56
- package/dist/store/session-registry-repo.d.ts +12 -0
- package/dist/store/session-registry-repo.js +16 -0
- package/package.json +1 -1
- package/web/dist/assets/index-DYMfaAi4.css +1 -0
- package/web/dist/assets/index-uOoZjGKa.js +141 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-XqBCYtkw.js +0 -139
- package/web/dist/assets/index-zpf3OSKC.css +0 -1
package/dist/entry/app.js
CHANGED
|
@@ -36,7 +36,7 @@ import { projectStore } from '../domain/projects/index.js';
|
|
|
36
36
|
import { sendStartupDmIfConfigured } from './startup-notify.js';
|
|
37
37
|
import { subscribeDaemonNotices } from './daemon-notice.js';
|
|
38
38
|
import { startGateway, stopGateway } from '../domain/costs/gateway-manager.js';
|
|
39
|
-
import { startClientManager, stopClientManager, startAllRemoteClients, getOnlineDevices, isDeviceOnline } from '../domain/remote/client-manager.js';
|
|
39
|
+
import { startClientManager, stopClientManager, startAllRemoteClients, getOnlineDevices, isDeviceOnline, sendCommand } from '../domain/remote/client-manager.js';
|
|
40
40
|
import { checkAndUpdateClients, formatUpdateSlackMessage } from '../domain/remote/client-hot-reload.js';
|
|
41
41
|
import { checkServerUpdate } from '../domain/system/server-update-check.js';
|
|
42
42
|
import { emitSystemNotice } from '../domain/system/system-notice.js';
|
|
@@ -71,7 +71,7 @@ import { respondToPlan } from '../orchestration/interactions/plan-response.js';
|
|
|
71
71
|
import { CommandActionRouter } from '../orchestration/interactions/command-action-router.js';
|
|
72
72
|
import { createUpdatePrompt } from '../orchestration/interactions/update-prompt.js';
|
|
73
73
|
import { registerMessageHandler } from '../orchestration/routing/message-router.js';
|
|
74
|
-
import { initRateLimitThrottle } from '../domain/costs/rate-limit-throttle.js';
|
|
74
|
+
import { initRateLimitThrottle, clearThrottle, RATE_LIMIT_CLEAR_ACTION_ID } from '../domain/costs/rate-limit-throttle.js';
|
|
75
75
|
import { initResumeRegistry, getResumeCount, recordResume } from '../domain/costs/resume-registry.js';
|
|
76
76
|
import { dispatchPendingResumes, registerResumeWakeOnAgentSettle, } from '../orchestration/resume-dispatcher.js';
|
|
77
77
|
import { scheduleRepo } from '../store/schedule-repo.js';
|
|
@@ -86,7 +86,7 @@ import { costRepo } from '../store/cost-repo.js';
|
|
|
86
86
|
import { PROFILES_FILE, profileRepo, startProfileWatcher, setAdminNotifier as setProfileNotifier } from '../store/profile-repo.js';
|
|
87
87
|
import { sessionStore } from '../store/session-registry-repo.js';
|
|
88
88
|
import { cleanupAllBackups } from '../domain/sessions/session-backup.js';
|
|
89
|
-
import { createDirectSession } from '../domain/sessions/session-lifecycle.js';
|
|
89
|
+
import { createDirectSession, adoptScheduledSession } from '../domain/sessions/session-lifecycle.js';
|
|
90
90
|
import { setSessionAsync } from '../domain/sessions/session.js';
|
|
91
91
|
import { isSessionCompactionSupported, resolveBackendForChannel, switchChannelProfile } from '../domain/agents/index.js';
|
|
92
92
|
import { initDiskMonitor, stopDiskMonitor } from '../domain/monitor/disk-monitor.js';
|
|
@@ -395,6 +395,7 @@ process.on('SIGTERM', async () => {
|
|
|
395
395
|
}
|
|
396
396
|
return task;
|
|
397
397
|
},
|
|
398
|
+
update: (id, patch) => scheduler.update(id, patch),
|
|
398
399
|
},
|
|
399
400
|
executionRegistry,
|
|
400
401
|
executionLogTailer,
|
|
@@ -412,6 +413,11 @@ process.on('SIGTERM', async () => {
|
|
|
412
413
|
getOnlineDevices,
|
|
413
414
|
isDeviceOnline,
|
|
414
415
|
getMachineRegistry,
|
|
416
|
+
// machines.detail expand: run the read-only telemetry probe over the existing client WebSocket.
|
|
417
|
+
probeMachine: async (device, command, timeout) => {
|
|
418
|
+
const result = await sendCommand(device, { action: 'bash', params: { command }, timeout });
|
|
419
|
+
return typeof result?.stdout === 'string' ? result.stdout : '';
|
|
420
|
+
},
|
|
415
421
|
},
|
|
416
422
|
// S4 chat Stop: cancel the agent(s) running on the session's channel via the orchestration
|
|
417
423
|
// channel-cancel path (same code the no-arg/`--all` !cancel command uses). Injected here so the
|
|
@@ -433,6 +439,9 @@ process.on('SIGTERM', async () => {
|
|
|
433
439
|
initConversation: async (channel, a) => { await conversationLedger.initConversation(channel, a); },
|
|
434
440
|
resolveBackend: resolveBackendForChannel,
|
|
435
441
|
}, opts),
|
|
442
|
+
// Replying to a scheduled run (design 27b): adopt it as a normal direct session on its own
|
|
443
|
+
// web:<sid> conduit before the send. Wired here so ui-service never imports the lifecycle.
|
|
444
|
+
adoptScheduledSession: ({ sessionId }) => adoptScheduledSession(sessionStore, sessionId),
|
|
436
445
|
// Web profile switch: apply the shared per-channel profile-switch rule (same one the Slack/Feishu
|
|
437
446
|
// `!profile` command uses). Wired here so the ui-service domain never imports domain/agents.
|
|
438
447
|
switchSessionProfile: (opts) => switchChannelProfile(opts),
|
|
@@ -575,6 +584,18 @@ process.on('SIGTERM', async () => {
|
|
|
575
584
|
save: (state) => providerStateRepo.setRateLimitThrottle(state),
|
|
576
585
|
load: () => providerStateRepo.getRateLimitThrottle(),
|
|
577
586
|
}, () => { void dispatchPendingResumes(adapter); }, () => { bus.publish({ type: 'rate-limit.changed' }); });
|
|
587
|
+
// Rate-limit notices carry a "Resume now" button (Slack/Feishu interactive). Clicking it
|
|
588
|
+
// clears the throttle early for that provider (or all when the value is empty) and dispatches
|
|
589
|
+
// paused work immediately — the same recovery path as a natural window expiry.
|
|
590
|
+
adapter.onAction(RATE_LIMIT_CLEAR_ACTION_ID, async (ctx) => {
|
|
591
|
+
const result = await clearThrottle(ctx.value || null);
|
|
592
|
+
const conduit = ctx.messageRef?.conduit ?? '';
|
|
593
|
+
const names = result.cleared.map((c) => c.displayName).join(', ');
|
|
594
|
+
const text = result.cleared.length > 0
|
|
595
|
+
? `Rate limit cleared for ${names} — paused work is resuming now.`
|
|
596
|
+
: 'No active rate limit to clear.';
|
|
597
|
+
await adapter.postMessage({ type: 'interactive-reply', conduit, sessionId: '' }, { text }, { threadId: ctx.messageRef?.messageId }).catch((e) => log.error(`rate-limit:clear reply failed: ${e.message}`));
|
|
598
|
+
});
|
|
578
599
|
if (getResumeCount() > 0) {
|
|
579
600
|
log.info(`Startup: evaluating ${getResumeCount()} pending provider resume(s)`);
|
|
580
601
|
void dispatchPendingResumes(adapter);
|
package/dist/entry/auth-cli.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { AuthStatusSnapshot } from '../domain/auth/auth-status.js';
|
|
2
|
+
import type { CustomProviderStores } from '../domain/pi-providers/index.js';
|
|
2
3
|
export interface AuthCliDeps {
|
|
3
4
|
getAuthStatus?: () => Promise<AuthStatusSnapshot>;
|
|
5
|
+
/** Where custom PI providers are stored. Injected so the CLI states its own file paths. */
|
|
6
|
+
customProviderStores?: CustomProviderStores;
|
|
4
7
|
}
|
|
5
8
|
export interface AuthCliResult {
|
|
6
9
|
exitCode: number;
|
|
7
10
|
stdout: string;
|
|
8
11
|
stderr: string;
|
|
9
12
|
}
|
|
10
|
-
export declare function runAuthCli(args: string[], readStatus: () => Promise<AuthStatusSnapshot
|
|
13
|
+
export declare function runAuthCli(args: string[], readStatus: () => Promise<AuthStatusSnapshot>, stores?: CustomProviderStores): Promise<AuthCliResult>;
|
package/dist/entry/auth-cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import { formatError } from '../core/cli-utils.js';
|
|
|
6
6
|
import { t } from '../core/i18n.js';
|
|
7
7
|
import { formatAuthStatusSummary } from '../domain/auth/auth-format.js';
|
|
8
8
|
import { getAuthHelp } from './cli-help.js';
|
|
9
|
+
import { runProviderCli } from './provider-cli.js';
|
|
9
10
|
function authErrorLabels() {
|
|
10
11
|
return {
|
|
11
12
|
validValues: t('cmd.auth.cli.validValues'),
|
|
@@ -20,7 +21,7 @@ function parseAuthCommand(args) {
|
|
|
20
21
|
return args.slice(1);
|
|
21
22
|
const message = t('cmd.auth.cli.unknownSubcommand', { command: args[0] });
|
|
22
23
|
const stderr = formatError(message, {
|
|
23
|
-
validValues: ['status'], hint: 'cortex auth --help', labels: authErrorLabels(),
|
|
24
|
+
validValues: ['status', 'provider'], hint: 'cortex auth --help', labels: authErrorLabels(),
|
|
24
25
|
});
|
|
25
26
|
return { exitCode: 1, stdout: '', stderr };
|
|
26
27
|
}
|
|
@@ -37,7 +38,14 @@ function validateAuthOptions(options) {
|
|
|
37
38
|
});
|
|
38
39
|
return { exitCode: 1, stdout: '', stderr };
|
|
39
40
|
}
|
|
40
|
-
export async function runAuthCli(args, readStatus) {
|
|
41
|
+
export async function runAuthCli(args, readStatus, stores) {
|
|
42
|
+
// Custom providers are part of the account surface, so they hang off `cortex auth`.
|
|
43
|
+
if (args[0] === 'provider') {
|
|
44
|
+
if (!stores) {
|
|
45
|
+
return { exitCode: 1, stdout: '', stderr: t('provider.cli.writeFailed') };
|
|
46
|
+
}
|
|
47
|
+
return runProviderCli(args.slice(1), stores);
|
|
48
|
+
}
|
|
41
49
|
const parsed = parseAuthCommand(args);
|
|
42
50
|
if (!Array.isArray(parsed))
|
|
43
51
|
return parsed;
|
package/dist/entry/cli-help.js
CHANGED
|
@@ -110,8 +110,11 @@ export function getAuthHelp() {
|
|
|
110
110
|
return formatHelp({
|
|
111
111
|
name: 'cortex auth',
|
|
112
112
|
description: t('cmd.auth.cli.description'),
|
|
113
|
-
usage: 'cortex auth status [
|
|
114
|
-
commands: [
|
|
113
|
+
usage: 'cortex auth <status|provider> [options]',
|
|
114
|
+
commands: [
|
|
115
|
+
{ name: 'status', description: t('cmd.auth.cli.statusDescription') },
|
|
116
|
+
{ name: 'provider', description: t('provider.cli.description') },
|
|
117
|
+
],
|
|
115
118
|
options: [
|
|
116
119
|
{ flag: '--json', description: t('cmd.auth.cli.jsonDescription') },
|
|
117
120
|
{ flag: '--help, -h', description: t('cmd.auth.cli.helpDescription') },
|
|
@@ -119,6 +122,7 @@ export function getAuthHelp() {
|
|
|
119
122
|
examples: [
|
|
120
123
|
{ description: t('cmd.auth.cli.exampleSummary'), command: 'cortex auth status' },
|
|
121
124
|
{ description: t('cmd.auth.cli.exampleJson'), command: 'cortex auth status --json' },
|
|
125
|
+
{ description: t('provider.cli.exampleList'), command: 'cortex auth provider list' },
|
|
122
126
|
],
|
|
123
127
|
labels: {
|
|
124
128
|
usage: t('cmd.auth.cli.helpUsage'),
|
package/dist/entry/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import { discoverEndpoints, writeMergedGatewayYaml, validateProfilesAgainstGatew
|
|
|
17
17
|
import { generateProfiles, writeProfilesJson } from '../core/profile-generator.js';
|
|
18
18
|
import { CORTEX_VERSION } from '../core/version.js';
|
|
19
19
|
import { getAuthStatus } from '../domain/auth/auth-status.js';
|
|
20
|
+
import { defaultCustomProviderStores } from '../domain/pi-providers/index.js';
|
|
20
21
|
import { runAuthCli } from './auth-cli.js';
|
|
21
22
|
import { getCliHelp, getInitHelp, getSetupGatewayHelp, getTuiHelp, } from './cli-help.js';
|
|
22
23
|
export { getAuthHelp, getCliHelp, getInitHelp, getSetupGatewayHelp, getTuiHelp } from './cli-help.js';
|
|
@@ -562,7 +563,7 @@ async function runDaemonCli(args) {
|
|
|
562
563
|
const CLI_HANDLERS = {
|
|
563
564
|
init: (args) => runInitCli(args),
|
|
564
565
|
config: () => ({ exitCode: 0, stdout: getConfigOutput(), stderr: '' }),
|
|
565
|
-
auth: (args, deps) => runAuthCli(args, deps.getAuthStatus ?? getAuthStatus),
|
|
566
|
+
auth: (args, deps) => runAuthCli(args, deps.getAuthStatus ?? getAuthStatus, deps.customProviderStores ?? defaultCustomProviderStores()),
|
|
566
567
|
doctor: (args) => runDoctorCli(args),
|
|
567
568
|
feishu: (args) => cmdFeishu(args),
|
|
568
569
|
restart: () => runRestartCli(),
|
package/dist/entry/daemon.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type FSWatcher } from 'fs';
|
|
2
1
|
declare function buildChildProcessConfig(restartReason?: string | null): {
|
|
3
2
|
cwd: string;
|
|
4
3
|
stdio: ("pipe" | "ignore" | "ipc")[];
|
|
@@ -7,16 +6,6 @@ declare function buildChildProcessConfig(restartReason?: string | null): {
|
|
|
7
6
|
[key: string]: string;
|
|
8
7
|
};
|
|
9
8
|
};
|
|
10
|
-
export interface WatchMonitor {
|
|
11
|
-
close(): void;
|
|
12
|
-
}
|
|
13
|
-
export interface ResilientWatchOptions {
|
|
14
|
-
label: string;
|
|
15
|
-
startWatching: () => FSWatcher[];
|
|
16
|
-
poll?: () => void;
|
|
17
|
-
warn?: (message: string) => void;
|
|
18
|
-
}
|
|
19
|
-
export declare function createResilientWatchMonitor(options: ResilientWatchOptions): WatchMonitor;
|
|
20
9
|
export interface RebuildStep {
|
|
21
10
|
/** Short stable name used in logs and in the abort notice. */
|
|
22
11
|
label: string;
|
package/dist/entry/daemon.js
CHANGED
|
@@ -45,6 +45,7 @@ import { watch, existsSync, unlinkSync, statSync, writeFileSync, readdirSync, }
|
|
|
45
45
|
import * as path from 'path';
|
|
46
46
|
import { createLogger } from '../core/log.js';
|
|
47
47
|
import { loadRuntimeDotenv } from '../core/runtime-env.js';
|
|
48
|
+
import { createResilientWatchMonitor } from '../core/resilient-watch.js';
|
|
48
49
|
import { isMainModule, moduleDir, DATA_DIR, CONFIG_DIR, STORE_DIR } from '../core/utils.js';
|
|
49
50
|
import { tryAcquireSingletonLock, releaseSingletonLock as releaseLock } from '../core/singleton-lock.js';
|
|
50
51
|
// Load .env BEFORE reading any CORTEX_* env vars below. Mirrors app.ts §61 — the
|
|
@@ -77,7 +78,6 @@ const BUILD_DEBOUNCE_MS = 2500; // src/*.ts — slower, build takes seconds anyw
|
|
|
77
78
|
const BACKOFF_INITIAL = 1000;
|
|
78
79
|
const BACKOFF_MAX = 30_000;
|
|
79
80
|
const HEALTHY_THRESHOLD = 10_000; // if alive > 10s, reset backoff
|
|
80
|
-
const WATCH_FALLBACK_MS = 5000;
|
|
81
81
|
// Src-watch filter: paths under SRC_WATCH_PATH that should NOT trigger a rebuild.
|
|
82
82
|
const SRC_IGNORE_PREFIXES = ['tests/', 'tmp/', 'node_modules/', 'dist/', 'vendor/'];
|
|
83
83
|
const SRC_IGNORE_SUFFIXES = ['.d.ts', '.test.ts', '.spec.ts'];
|
|
@@ -265,12 +265,7 @@ async function restart(reason) {
|
|
|
265
265
|
nextRestartReason = reason;
|
|
266
266
|
startChild();
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
if (!(error instanceof Error))
|
|
270
|
-
return String(error);
|
|
271
|
-
const code = error.code;
|
|
272
|
-
return code ? `${code}: ${error.message}` : error.message;
|
|
273
|
-
}
|
|
268
|
+
// --- File Watching ---
|
|
274
269
|
function closeWatchers(watchers) {
|
|
275
270
|
for (const watcher of watchers.splice(0)) {
|
|
276
271
|
try {
|
|
@@ -279,48 +274,6 @@ function closeWatchers(watchers) {
|
|
|
279
274
|
catch { }
|
|
280
275
|
}
|
|
281
276
|
}
|
|
282
|
-
function pollSafely(options, warn) {
|
|
283
|
-
try {
|
|
284
|
-
options.poll?.();
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
warn(`${options.label} polling failed (${formatWatchError(error)})`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
function failWatchMonitor(state, options, warn, error) {
|
|
291
|
-
if (state.failed || state.closed)
|
|
292
|
-
return;
|
|
293
|
-
state.failed = true;
|
|
294
|
-
closeWatchers(state.watchers);
|
|
295
|
-
const detail = formatWatchError(error);
|
|
296
|
-
if (!options.poll) {
|
|
297
|
-
warn(`${options.label} watcher failed (${detail}); watcher disabled`);
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
warn(`${options.label} watcher failed (${detail}); polling every ${WATCH_FALLBACK_MS}ms`);
|
|
301
|
-
state.pollTimer = setInterval(() => pollSafely(options, warn), WATCH_FALLBACK_MS);
|
|
302
|
-
}
|
|
303
|
-
function closeWatchMonitor(state) {
|
|
304
|
-
state.closed = true;
|
|
305
|
-
closeWatchers(state.watchers);
|
|
306
|
-
if (state.pollTimer)
|
|
307
|
-
clearInterval(state.pollTimer);
|
|
308
|
-
state.pollTimer = null;
|
|
309
|
-
}
|
|
310
|
-
export function createResilientWatchMonitor(options) {
|
|
311
|
-
const state = { watchers: [], pollTimer: null, failed: false, closed: false };
|
|
312
|
-
const warn = options.warn ?? (message => log.warn(message));
|
|
313
|
-
const fallBack = (error) => failWatchMonitor(state, options, warn, error);
|
|
314
|
-
try {
|
|
315
|
-
state.watchers = options.startWatching();
|
|
316
|
-
for (const watcher of state.watchers)
|
|
317
|
-
watcher.on('error', fallBack);
|
|
318
|
-
}
|
|
319
|
-
catch (error) {
|
|
320
|
-
fallBack(error);
|
|
321
|
-
}
|
|
322
|
-
return { close: () => closeWatchMonitor(state) };
|
|
323
|
-
}
|
|
324
277
|
/** Recursively watch each directory on Windows, closing partial setup on failure. */
|
|
325
278
|
function watchTree(root, callback) {
|
|
326
279
|
const watchers = [];
|
|
@@ -380,6 +333,7 @@ function setupSourceMonitor() {
|
|
|
380
333
|
}
|
|
381
334
|
return createResilientWatchMonitor({
|
|
382
335
|
label: `Source ${SRC_WATCH_PATH}`,
|
|
336
|
+
warn: (message) => log.warn(message),
|
|
383
337
|
startWatching: () => {
|
|
384
338
|
if (process.platform === 'win32') {
|
|
385
339
|
const watchers = watchTree(SRC_WATCH_PATH, (_event, filename) => handleSourceChange(filename));
|
|
@@ -411,6 +365,7 @@ function setupRestartTriggerMonitor() {
|
|
|
411
365
|
const triggerName = path.basename(RESTART_TRIGGER);
|
|
412
366
|
return createResilientWatchMonitor({
|
|
413
367
|
label: `Restart trigger ${RESTART_TRIGGER}`,
|
|
368
|
+
warn: (message) => log.warn(message),
|
|
414
369
|
startWatching: () => {
|
|
415
370
|
const watcher = watch(triggerDir, (_event, filename) => {
|
|
416
371
|
if (filename && String(filename) === triggerName)
|
|
@@ -460,6 +415,7 @@ function setupEnvMonitor() {
|
|
|
460
415
|
label: `Environment file ${ENV_FILE}`,
|
|
461
416
|
startWatching: () => startEnvWatcher(envDir, envName, handleChange),
|
|
462
417
|
poll,
|
|
418
|
+
warn: (message) => log.warn(message),
|
|
463
419
|
});
|
|
464
420
|
}
|
|
465
421
|
function setupWatchers() {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CustomProviderStores } from '../domain/pi-providers/index.js';
|
|
2
|
+
export interface ProviderCliResult {
|
|
3
|
+
exitCode: number;
|
|
4
|
+
stdout: string;
|
|
5
|
+
stderr: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ProviderCliOptions {
|
|
8
|
+
/** Reads the key when `--key -` is used. Injected so tests need no real stdin. */
|
|
9
|
+
readSecret?: () => string;
|
|
10
|
+
}
|
|
11
|
+
export declare function getProviderHelp(): string;
|
|
12
|
+
/**
|
|
13
|
+
* `cortex auth provider <list|add|remove>`. `add` is an upsert, so retrying it is safe; `remove`
|
|
14
|
+
* takes `--dry-run` because it deletes a gateway route the running gateway is serving.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runProviderCli(args: string[], stores: CustomProviderStores, options?: ProviderCliOptions): ProviderCliResult;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// input: provider subcommand arguments and the two store paths
|
|
2
|
+
// output: custom provider listing, saving and removal with CLI framing
|
|
3
|
+
// pos: Custom PI provider CLI handler
|
|
4
|
+
// >>> If I am updated, update my header and folder CORTEX.md <<<
|
|
5
|
+
import { formatError, formatHelp, readStdinSync } from '../core/cli-utils.js';
|
|
6
|
+
import { t } from '../core/i18n.js';
|
|
7
|
+
import { CUSTOM_PROVIDER_APIS, getCustomProvider, listCustomProviders, removeCustomProvider, upsertCustomProvider, } from '../domain/pi-providers/index.js';
|
|
8
|
+
const SUBCOMMANDS = ['list', 'add', 'remove'];
|
|
9
|
+
function labels() {
|
|
10
|
+
return { validValues: t('provider.cli.validValues'), hint: t('provider.cli.hint') };
|
|
11
|
+
}
|
|
12
|
+
function fail(message, opts) {
|
|
13
|
+
return {
|
|
14
|
+
exitCode: 1,
|
|
15
|
+
stdout: '',
|
|
16
|
+
stderr: formatError(message, { ...opts, labels: labels() }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function getProviderHelp() {
|
|
20
|
+
return formatHelp({
|
|
21
|
+
name: 'cortex auth provider',
|
|
22
|
+
description: t('provider.cli.description'),
|
|
23
|
+
usage: 'cortex auth provider <list|add|remove> [options]',
|
|
24
|
+
commands: [
|
|
25
|
+
{ name: 'list', description: t('provider.cli.listDescription') },
|
|
26
|
+
{ name: 'add', description: t('provider.cli.addDescription') },
|
|
27
|
+
{ name: 'remove', description: t('provider.cli.removeDescription') },
|
|
28
|
+
],
|
|
29
|
+
options: [
|
|
30
|
+
{ flag: '--name <name>', description: t('provider.cli.nameDescription') },
|
|
31
|
+
{ flag: '--api <api>', description: `${t('provider.cli.apiDescription')} (${CUSTOM_PROVIDER_APIS.join(' | ')})` },
|
|
32
|
+
{ flag: '--url <url>', description: t('provider.cli.urlDescription') },
|
|
33
|
+
{ flag: '--key <key|->', description: t('provider.cli.keyDescription') },
|
|
34
|
+
{ flag: '--model <id>', description: t('provider.cli.modelDescription') },
|
|
35
|
+
{ flag: '--dry-run', description: t('provider.cli.dryRunDescription') },
|
|
36
|
+
{ flag: '--json', description: t('provider.cli.jsonDescription') },
|
|
37
|
+
{ flag: '--help, -h', description: t('provider.cli.helpDescription') },
|
|
38
|
+
],
|
|
39
|
+
examples: [
|
|
40
|
+
{
|
|
41
|
+
description: t('provider.cli.exampleAdd'),
|
|
42
|
+
command: 'cortex auth provider add --name my-vllm --api anthropic-messages --url http://127.0.0.1:8100 --model Model-27B',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
description: t('provider.cli.exampleAddPiped'),
|
|
46
|
+
command: 'pass show my-endpoint | cortex auth provider add --name my-proxy --api openai-completions --url https://proxy.example.com/v1 --model small --key -',
|
|
47
|
+
},
|
|
48
|
+
{ description: t('provider.cli.exampleList'), command: 'cortex auth provider list --json' },
|
|
49
|
+
{ description: t('provider.cli.exampleRemove'), command: 'cortex auth provider remove --name my-vllm --dry-run' },
|
|
50
|
+
],
|
|
51
|
+
labels: {
|
|
52
|
+
usage: t('cmd.auth.cli.helpUsage'),
|
|
53
|
+
commands: t('cmd.auth.cli.helpCommands'),
|
|
54
|
+
options: t('cmd.auth.cli.helpOptions'),
|
|
55
|
+
examples: t('cmd.auth.cli.helpExamples'),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const VALUE_FLAGS = new Set(['--name', '--api', '--url', '--key']);
|
|
60
|
+
function parseFlags(args) {
|
|
61
|
+
const values = new Map();
|
|
62
|
+
const models = [];
|
|
63
|
+
let json = false;
|
|
64
|
+
let dryRun = false;
|
|
65
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
66
|
+
const arg = args[i];
|
|
67
|
+
if (arg === '--json') {
|
|
68
|
+
json = true;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (arg === '--dry-run') {
|
|
72
|
+
dryRun = true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (arg === '--model' || VALUE_FLAGS.has(arg)) {
|
|
76
|
+
const value = args[i + 1];
|
|
77
|
+
if (value === undefined || value.startsWith('--')) {
|
|
78
|
+
return fail(t('provider.cli.flagNeedsValue', { flag: arg }), { hint: 'cortex auth provider --help' });
|
|
79
|
+
}
|
|
80
|
+
i += 1;
|
|
81
|
+
if (arg === '--model')
|
|
82
|
+
models.push(value);
|
|
83
|
+
else
|
|
84
|
+
values.set(arg, value);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
return fail(t('provider.cli.unknownFlag', { flag: arg }), {
|
|
88
|
+
validValues: ['--name', '--api', '--url', '--key', '--model', '--dry-run', '--json'],
|
|
89
|
+
hint: 'cortex auth provider --help',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return { values, models, json, dryRun };
|
|
93
|
+
}
|
|
94
|
+
function issueText(issue) {
|
|
95
|
+
return t(`provider.issue.${issue}`);
|
|
96
|
+
}
|
|
97
|
+
function renderProvider(provider) {
|
|
98
|
+
return provider.routed
|
|
99
|
+
? t('provider.cli.listItem', { name: provider.name, api: provider.api, upstream: provider.upstreamUrl ?? '' })
|
|
100
|
+
: t('provider.cli.listItemUnrouted', { name: provider.name, api: provider.api });
|
|
101
|
+
}
|
|
102
|
+
function runList(flags, stores) {
|
|
103
|
+
const providers = listCustomProviders(stores);
|
|
104
|
+
if (flags.json) {
|
|
105
|
+
return { exitCode: 0, stdout: JSON.stringify({ ok: true, providers }, null, 2), stderr: '' };
|
|
106
|
+
}
|
|
107
|
+
const stdout = providers.length === 0
|
|
108
|
+
? t('provider.cli.listEmpty')
|
|
109
|
+
: providers.map(renderProvider).join('\n');
|
|
110
|
+
return { exitCode: 0, stdout, stderr: '' };
|
|
111
|
+
}
|
|
112
|
+
function resolveKey(flags, options) {
|
|
113
|
+
const raw = flags.values.get('--key');
|
|
114
|
+
if (raw === undefined)
|
|
115
|
+
return undefined;
|
|
116
|
+
if (raw !== '-')
|
|
117
|
+
return raw;
|
|
118
|
+
const read = options.readSecret ?? readStdinSync;
|
|
119
|
+
return read().trim();
|
|
120
|
+
}
|
|
121
|
+
function runAdd(flags, stores, options) {
|
|
122
|
+
for (const flag of ['--name', '--api', '--url']) {
|
|
123
|
+
if (!flags.values.has(flag)) {
|
|
124
|
+
return fail(t('provider.cli.missingFlag', { flag }), { hint: 'cortex auth provider add --help' });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const api = flags.values.get('--api');
|
|
128
|
+
if (!CUSTOM_PROVIDER_APIS.includes(api)) {
|
|
129
|
+
return fail(issueText('api-invalid'), {
|
|
130
|
+
validValues: [...CUSTOM_PROVIDER_APIS],
|
|
131
|
+
hint: 'cortex auth provider add --help',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const result = upsertCustomProvider(stores, {
|
|
135
|
+
name: flags.values.get('--name'),
|
|
136
|
+
api,
|
|
137
|
+
upstreamUrl: flags.values.get('--url'),
|
|
138
|
+
apiKey: resolveKey(flags, options),
|
|
139
|
+
models: flags.models.map((id) => ({ id })),
|
|
140
|
+
});
|
|
141
|
+
// `=== false` rather than `!result.ok`: this project typechecks with `strict: false`, where
|
|
142
|
+
// truthiness alone does not narrow a boolean-literal discriminant.
|
|
143
|
+
if (result.ok === false) {
|
|
144
|
+
return fail(result.errors.map(issueText).join('\n'), { hint: 'cortex auth provider add --help' });
|
|
145
|
+
}
|
|
146
|
+
const stdout = flags.json
|
|
147
|
+
? JSON.stringify({ ok: true, provider: result.provider }, null, 2)
|
|
148
|
+
: t('provider.cli.added', {
|
|
149
|
+
name: result.provider.name,
|
|
150
|
+
upstream: result.provider.upstreamUrl ?? '',
|
|
151
|
+
});
|
|
152
|
+
return { exitCode: 0, stdout, stderr: '' };
|
|
153
|
+
}
|
|
154
|
+
function runRemove(flags, stores) {
|
|
155
|
+
const name = flags.values.get('--name');
|
|
156
|
+
if (!name) {
|
|
157
|
+
return fail(t('provider.cli.missingFlag', { flag: '--name' }), { hint: 'cortex auth provider remove --help' });
|
|
158
|
+
}
|
|
159
|
+
const existing = getCustomProvider(stores, name);
|
|
160
|
+
if (!existing) {
|
|
161
|
+
return fail(t('provider.cli.notFound', { name }), { hint: 'cortex auth provider list' });
|
|
162
|
+
}
|
|
163
|
+
if (flags.dryRun) {
|
|
164
|
+
const payload = { dry_run: true, would_remove: existing };
|
|
165
|
+
return { exitCode: 0, stdout: JSON.stringify(payload, null, 2), stderr: '' };
|
|
166
|
+
}
|
|
167
|
+
const result = removeCustomProvider(stores, name);
|
|
168
|
+
if (result.ok === false) {
|
|
169
|
+
return fail(result.errors.map(issueText).join('\n'), { hint: 'cortex auth provider list' });
|
|
170
|
+
}
|
|
171
|
+
const stdout = flags.json
|
|
172
|
+
? JSON.stringify({ ok: true, name }, null, 2)
|
|
173
|
+
: t('provider.cli.removed', { name });
|
|
174
|
+
return { exitCode: 0, stdout, stderr: '' };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* `cortex auth provider <list|add|remove>`. `add` is an upsert, so retrying it is safe; `remove`
|
|
178
|
+
* takes `--dry-run` because it deletes a gateway route the running gateway is serving.
|
|
179
|
+
*/
|
|
180
|
+
export function runProviderCli(args, stores, options = {}) {
|
|
181
|
+
if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
|
|
182
|
+
return { exitCode: 0, stdout: getProviderHelp(), stderr: '' };
|
|
183
|
+
}
|
|
184
|
+
const subcommand = args[0];
|
|
185
|
+
if (!SUBCOMMANDS.includes(subcommand)) {
|
|
186
|
+
return fail(t('provider.cli.unknownSubcommand', { command: subcommand }), {
|
|
187
|
+
validValues: [...SUBCOMMANDS],
|
|
188
|
+
hint: 'cortex auth provider --help',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
const rest = args.slice(1);
|
|
192
|
+
if (rest.includes('--help') || rest.includes('-h')) {
|
|
193
|
+
return { exitCode: 0, stdout: getProviderHelp(), stderr: '' };
|
|
194
|
+
}
|
|
195
|
+
const flags = parseFlags(rest);
|
|
196
|
+
if (!('values' in flags))
|
|
197
|
+
return flags;
|
|
198
|
+
if (subcommand === 'list')
|
|
199
|
+
return runList(flags, stores);
|
|
200
|
+
if (subcommand === 'add')
|
|
201
|
+
return runAdd(flags, stores, options);
|
|
202
|
+
return runRemove(flags, stores);
|
|
203
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthNoticeAction, ChatNoticeLevel, SessionContextUsage } from '../core/types/agent-types.js';
|
|
1
|
+
import type { AuthNoticeAction, ChatNoticeLevel, NoticeAction, SessionContextUsage } from '../core/types/agent-types.js';
|
|
2
2
|
export type AuthErrorKind = 'login_required' | 'oauth_expired' | 'invalid_api_key' | 'unauthorized' | 'invalid_grant';
|
|
3
3
|
/** All CortexEvent variants. `ts` is ISO-8601, injected by EventBus.publish(). */
|
|
4
4
|
export type CortexEvent = {
|
|
@@ -24,6 +24,7 @@ export type CortexEvent = {
|
|
|
24
24
|
toolInput?: string;
|
|
25
25
|
blockId?: string;
|
|
26
26
|
noticeLevel?: ChatNoticeLevel;
|
|
27
|
+
noticeAction?: NoticeAction;
|
|
27
28
|
authAction?: AuthNoticeAction;
|
|
28
29
|
pending?: boolean;
|
|
29
30
|
pendingId?: string;
|
|
@@ -287,7 +287,7 @@ export class AgentRunner {
|
|
|
287
287
|
},
|
|
288
288
|
onExecutionRegistered: () => finishTurnTracking(channel, turnTrackingToken),
|
|
289
289
|
onAssistantDelta: deltaStream ? (text, blockId) => deltaStream.onDelta(text, blockId) : null,
|
|
290
|
-
onAssistantMessage: (text, blockId, noticeLevel) => {
|
|
290
|
+
onAssistantMessage: (text, blockId, noticeLevel, noticeAction) => {
|
|
291
291
|
// Drain this block's preview FIRST: the authoritative message must never be overtaken by
|
|
292
292
|
// a delta still sitting in the coalescer, or the UI would replace the row and then append
|
|
293
293
|
// a stale fragment to it.
|
|
@@ -296,11 +296,12 @@ export class AgentRunner {
|
|
|
296
296
|
callbacks.onAssistantMsg(text);
|
|
297
297
|
if (sessionId && text) {
|
|
298
298
|
const ts = new Date().toISOString();
|
|
299
|
-
recordHistory(conversationHistory.appendAssistant(sessionId, { text, ts, noticeLevel }));
|
|
299
|
+
recordHistory(conversationHistory.appendAssistant(sessionId, { text, ts, noticeLevel, noticeAction }));
|
|
300
300
|
publishSessionMessage({
|
|
301
301
|
sessionId, channel, role: 'assistant', text, ts,
|
|
302
302
|
...(blockId ? { blockId } : {}),
|
|
303
303
|
...(noticeLevel ? { noticeLevel } : {}),
|
|
304
|
+
...(noticeAction ? { noticeAction } : {}),
|
|
304
305
|
});
|
|
305
306
|
}
|
|
306
307
|
},
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
2
|
export declare function handleCostCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* `!budget` — global status
|
|
5
|
+
* `!budget $50/d $1000/m` — set the global limits
|
|
6
|
+
* `!budget list` — global limits + every per-project override
|
|
7
|
+
* `!budget <project>` — that project's status (own override or inherited globals)
|
|
8
|
+
* `!budget <project> $50/d $1000/m` — set that project's override (both limits required)
|
|
9
|
+
* `!budget <project> clear` — drop that project's override
|
|
10
|
+
*/
|
|
3
11
|
export declare function handleBudgetCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|