@hivemagnus/magnus-server 0.0.0-stage → 1.0.2
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/.env.example +171 -0
- package/LICENSE +202 -0
- package/README.md +169 -2
- package/agent-version.json +1 -0
- package/dist/ai/HEARTBEAT.md +56 -0
- package/dist/ai/IDENTITY.md +54 -0
- package/dist/ai/MEMORY.md +40 -0
- package/dist/ai/TOOLS.md +538 -0
- package/dist/ai/USER.md +32 -0
- package/dist/cli/args.js +62 -0
- package/dist/cli/env-catalog.js +131 -0
- package/dist/cli/preflight.js +89 -0
- package/dist/cli.js +175 -0
- package/dist/config/cors.js +16 -0
- package/dist/config/env.js +392 -0
- package/dist/config/features.js +16 -0
- package/dist/config/index.js +3 -0
- package/dist/config/listener-security.js +38 -0
- package/dist/config/version.js +31 -0
- package/dist/db/client.js +44 -0
- package/dist/db/generated/prisma/browser.js +18 -0
- package/dist/db/generated/prisma/client.js +35 -0
- package/dist/db/generated/prisma/commonInputTypes.js +11 -0
- package/dist/db/generated/prisma/enums.js +42 -0
- package/dist/db/generated/prisma/internal/class.js +50 -0
- package/dist/db/generated/prisma/internal/prismaNamespace.js +1598 -0
- package/dist/db/generated/prisma/internal/prismaNamespaceBrowser.js +1569 -0
- package/dist/db/generated/prisma/models/A2ATask.js +2 -0
- package/dist/db/generated/prisma/models/AdmissionFence.js +2 -0
- package/dist/db/generated/prisma/models/Agent.js +2 -0
- package/dist/db/generated/prisma/models/AiConversation.js +2 -0
- package/dist/db/generated/prisma/models/AiDashboard.js +2 -0
- package/dist/db/generated/prisma/models/AiMemory.js +2 -0
- package/dist/db/generated/prisma/models/AiMessage.js +2 -0
- package/dist/db/generated/prisma/models/AiScheduledOp.js +2 -0
- package/dist/db/generated/prisma/models/AlertConditionState.js +2 -0
- package/dist/db/generated/prisma/models/AlertRule.js +2 -0
- package/dist/db/generated/prisma/models/AlertViolation.js +2 -0
- package/dist/db/generated/prisma/models/AnomalyEvent.js +2 -0
- package/dist/db/generated/prisma/models/ApplicationObservation.js +2 -0
- package/dist/db/generated/prisma/models/ArdentInstallation.js +2 -0
- package/dist/db/generated/prisma/models/ArdentProfile.js +2 -0
- package/dist/db/generated/prisma/models/ArdentScopeEnrollment.js +2 -0
- package/dist/db/generated/prisma/models/CommandResourceFence.js +2 -0
- package/dist/db/generated/prisma/models/CommandResourceLease.js +2 -0
- package/dist/db/generated/prisma/models/CommandResult.js +2 -0
- package/dist/db/generated/prisma/models/CronJob.js +2 -0
- package/dist/db/generated/prisma/models/CronJobExecution.js +2 -0
- package/dist/db/generated/prisma/models/DeployJob.js +2 -0
- package/dist/db/generated/prisma/models/DriftScan.js +2 -0
- package/dist/db/generated/prisma/models/EngineeringMetricSample.js +2 -0
- package/dist/db/generated/prisma/models/EngineeringRecoveryExercise.js +2 -0
- package/dist/db/generated/prisma/models/ExecutionRun.js +2 -0
- package/dist/db/generated/prisma/models/FilePatchTask.js +2 -0
- package/dist/db/generated/prisma/models/GpuSnapshot.js +2 -0
- package/dist/db/generated/prisma/models/HealthSnapshot.js +2 -0
- package/dist/db/generated/prisma/models/HermesCoreRollout.js +2 -0
- package/dist/db/generated/prisma/models/HermesCoreRolloutHost.js +2 -0
- package/dist/db/generated/prisma/models/HermesCredentialPool.js +2 -0
- package/dist/db/generated/prisma/models/HermesCredentialPoolAttachment.js +2 -0
- package/dist/db/generated/prisma/models/HermesCronJob.js +2 -0
- package/dist/db/generated/prisma/models/HermesHook.js +2 -0
- package/dist/db/generated/prisma/models/HermesInstallation.js +2 -0
- package/dist/db/generated/prisma/models/HermesMcpServer.js +2 -0
- package/dist/db/generated/prisma/models/HermesMcpServerAttachment.js +2 -0
- package/dist/db/generated/prisma/models/HermesMessagingBinding.js +2 -0
- package/dist/db/generated/prisma/models/HermesOperationJob.js +2 -0
- package/dist/db/generated/prisma/models/HermesPluginInstall.js +2 -0
- package/dist/db/generated/prisma/models/HermesProfile.js +2 -0
- package/dist/db/generated/prisma/models/HermesProviderConfig.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryClient.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryInventory.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryReceipt.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryRevision.js +2 -0
- package/dist/db/generated/prisma/models/HermesRegistryTarget.js +2 -0
- package/dist/db/generated/prisma/models/HermesRole.js +2 -0
- package/dist/db/generated/prisma/models/HermesRoleApplication.js +2 -0
- package/dist/db/generated/prisma/models/HermesSkillAssignment.js +2 -0
- package/dist/db/generated/prisma/models/HermesToolsetPolicy.js +2 -0
- package/dist/db/generated/prisma/models/IncidentLesson.js +2 -0
- package/dist/db/generated/prisma/models/LibraryCategory.js +2 -0
- package/dist/db/generated/prisma/models/LibraryFile.js +2 -0
- package/dist/db/generated/prisma/models/LogEntry.js +2 -0
- package/dist/db/generated/prisma/models/MagnusReleaseCanary.js +2 -0
- package/dist/db/generated/prisma/models/MaintenanceWindow.js +2 -0
- package/dist/db/generated/prisma/models/ManagedCronDefinition.js +2 -0
- package/dist/db/generated/prisma/models/ManagedCronOccurrence.js +2 -0
- package/dist/db/generated/prisma/models/Node.js +2 -0
- package/dist/db/generated/prisma/models/Notification.js +2 -0
- package/dist/db/generated/prisma/models/NotificationPreference.js +2 -0
- package/dist/db/generated/prisma/models/RemediationExecution.js +2 -0
- package/dist/db/generated/prisma/models/RemediationRule.js +2 -0
- package/dist/db/generated/prisma/models/RemoteCommand.js +2 -0
- package/dist/db/generated/prisma/models/ResourceDrainParticipant.js +2 -0
- package/dist/db/generated/prisma/models/ResourceEnrollment.js +2 -0
- package/dist/db/generated/prisma/models/ResourceParticipantWork.js +2 -0
- package/dist/db/generated/prisma/models/Role.js +2 -0
- package/dist/db/generated/prisma/models/RoleApplication.js +2 -0
- package/dist/db/generated/prisma/models/RolloutTarget.js +2 -0
- package/dist/db/generated/prisma/models/SecurityExportOutbox.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionAction.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionActionApproval.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCase.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseActivity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseEvent.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCaseRelationship.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCollector.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionCommandOutbox.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionDeletionReceipt.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionDelivery.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEntityAlias.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEvent.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEventEntity.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionEvidence.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionInvestigation.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionNonce.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionReceiptChainHead.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionRuleVersion.js +2 -0
- package/dist/db/generated/prisma/models/SecurityFusionSourceState.js +2 -0
- package/dist/db/generated/prisma/models/SecurityServiceState.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceFence.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceLease.js +2 -0
- package/dist/db/generated/prisma/models/SharedResourceLeaseResource.js +2 -0
- package/dist/db/generated/prisma/models/SkillInstallation.js +2 -0
- package/dist/db/generated/prisma/models/SkillRegistryEntry.js +2 -0
- package/dist/db/generated/prisma/models/SkillTag.js +2 -0
- package/dist/db/generated/prisma/models/SkillVersion.js +2 -0
- package/dist/db/generated/prisma/models/TeamApprovalDecision.js +2 -0
- package/dist/db/generated/prisma/models/User.js +2 -0
- package/dist/db/generated/prisma/models/WebhookDelivery.js +2 -0
- package/dist/db/generated/prisma/models/WebhookEndpoint.js +2 -0
- package/dist/db/generated/prisma/models.js +2 -0
- package/dist/db/index.js +3 -0
- package/dist/db/read-retry.js +35 -0
- package/dist/db/seed.js +348 -0
- package/dist/index.js +162 -0
- package/dist/middleware/auth.js +361 -0
- package/dist/middleware/body-limit.js +14 -0
- package/dist/middleware/correlation-id.js +13 -0
- package/dist/middleware/error-handler.js +28 -0
- package/dist/middleware/iam-token.js +21 -0
- package/dist/middleware/rate-limit.js +78 -0
- package/dist/middleware/request-logger.js +85 -0
- package/dist/middleware/security-headers.js +23 -0
- package/dist/middleware/tracing.js +120 -0
- package/dist/middleware/user-status.js +33 -0
- package/dist/openapi/spec.js +2656 -0
- package/dist/queue/redis.js +20 -0
- package/dist/queue/requeue.js +27 -0
- package/dist/queue/workers.js +342 -0
- package/dist/routes/ai-schedule.js +73 -0
- package/dist/routes/alerts.js +79 -0
- package/dist/routes/anomalies.js +101 -0
- package/dist/routes/ardent.js +82 -0
- package/dist/routes/assistant.js +417 -0
- package/dist/routes/audit.js +138 -0
- package/dist/routes/codex.js +65 -0
- package/dist/routes/commands.js +226 -0
- package/dist/routes/credentials.js +58 -0
- package/dist/routes/cron.js +292 -0
- package/dist/routes/dependencies.js +49 -0
- package/dist/routes/deploy.js +18 -0
- package/dist/routes/discovery.js +168 -0
- package/dist/routes/docs.js +24 -0
- package/dist/routes/drift.js +126 -0
- package/dist/routes/events-stream.js +87 -0
- package/dist/routes/files.js +214 -0
- package/dist/routes/fleet-checks.js +21 -0
- package/dist/routes/health.js +133 -0
- package/dist/routes/heartbeat.js +545 -0
- package/dist/routes/hermes-registry.js +278 -0
- package/dist/routes/hermes.js +61 -0
- package/dist/routes/library.js +402 -0
- package/dist/routes/logs.js +172 -0
- package/dist/routes/managed-cron.js +23 -0
- package/dist/routes/mcp.js +39 -0
- package/dist/routes/metrics.js +187 -0
- package/dist/routes/nodes.js +951 -0
- package/dist/routes/notifications.js +130 -0
- package/dist/routes/ops.js +258 -0
- package/dist/routes/orchestra.js +430 -0
- package/dist/routes/predictions.js +23 -0
- package/dist/routes/profiling.js +68 -0
- package/dist/routes/quick-command.js +72 -0
- package/dist/routes/remediation.js +111 -0
- package/dist/routes/resource-leases.js +297 -0
- package/dist/routes/roles.js +370 -0
- package/dist/routes/rollout.js +124 -0
- package/dist/routes/scan.js +116 -0
- package/dist/routes/security-backup.js +58 -0
- package/dist/routes/security-fusion.js +605 -0
- package/dist/routes/security-integration.js +71 -0
- package/dist/routes/self-update.js +129 -0
- package/dist/routes/shared-resource-leases.js +78 -0
- package/dist/routes/skills.js +485 -0
- package/dist/routes/stats.js +96 -0
- package/dist/routes/team-approvals.js +23 -0
- package/dist/routes/terminal-ticket.js +15 -0
- package/dist/routes/terminal.js +17 -0
- package/dist/routes/topology.js +37 -0
- package/dist/routes/users.js +219 -0
- package/dist/routes/webhooks.js +137 -0
- package/dist/schemas/command-reconciliation.js +14 -0
- package/dist/schemas/commands.js +51 -0
- package/dist/schemas/cron.js +33 -0
- package/dist/schemas/deploy.js +20 -0
- package/dist/schemas/files.js +14 -0
- package/dist/schemas/hermes.js +69 -0
- package/dist/schemas/index.js +11 -0
- package/dist/schemas/library.js +48 -0
- package/dist/schemas/logs.js +35 -0
- package/dist/schemas/managed-cron.js +127 -0
- package/dist/schemas/node-responses.js +87 -0
- package/dist/schemas/node-session-receipt.js +84 -0
- package/dist/schemas/nodes.js +36 -0
- package/dist/schemas/orchestra.js +118 -0
- package/dist/schemas/resource-participant-reconciliation.js +99 -0
- package/dist/schemas/roles.js +54 -0
- package/dist/schemas/shared-resource-lease.js +132 -0
- package/dist/schemas/skills.js +44 -0
- package/dist/schemas/users.js +28 -0
- package/dist/scripts/run-disposable-recovery-exercise.js +39 -0
- package/dist/sdk/index.js +2 -0
- package/dist/sdk/node-api-client.js +474 -0
- package/dist/security/approval-assertion.js +66 -0
- package/dist/security/command-completion-registry.js +35 -0
- package/dist/security/command-request.js +12 -0
- package/dist/security/command-result-signature.js +34 -0
- package/dist/security/managed-http.js +45 -0
- package/dist/security/native-completion-registry.js +44 -0
- package/dist/server.js +178 -0
- package/dist/services/admission-fence.js +71 -0
- package/dist/services/ai-assistant-service.js +2523 -0
- package/dist/services/ai-correlation-service.js +225 -0
- package/dist/services/ai-export-service.js +141 -0
- package/dist/services/ai-insights-service.js +219 -0
- package/dist/services/ai-schedule-service.js +145 -0
- package/dist/services/ai-scratchpad-service.js +222 -0
- package/dist/services/ai-tools.js +1343 -0
- package/dist/services/alert-service.js +313 -0
- package/dist/services/anomaly-detector.js +419 -0
- package/dist/services/api-local-work.js +79 -0
- package/dist/services/application-probes.js +309 -0
- package/dist/services/ardent-scope-enrollment.js +123 -0
- package/dist/services/ardent-service.js +86 -0
- package/dist/services/audit-service.js +308 -0
- package/dist/services/codex-service.js +209 -0
- package/dist/services/command-lifecycle.js +60 -0
- package/dist/services/command-resource-leases.js +305 -0
- package/dist/services/control-host-node.js +242 -0
- package/dist/services/credential-rotation-service.js +294 -0
- package/dist/services/dependency-service.js +145 -0
- package/dist/services/disposable-recovery-runner.js +595 -0
- package/dist/services/docker-group-health.js +121 -0
- package/dist/services/engineering-assurance.js +492 -0
- package/dist/services/engineering-evidence-ledger.js +94 -0
- package/dist/services/engineering-metric-evidence.js +26 -0
- package/dist/services/event-bus.js +227 -0
- package/dist/services/fleet-check-log.js +102 -0
- package/dist/services/forecast-service.js +154 -0
- package/dist/services/health-retention.js +175 -0
- package/dist/services/heartbeat-stream.js +63 -0
- package/dist/services/hermes-catalog-import.js +62 -0
- package/dist/services/hermes-cli-parser.js +671 -0
- package/dist/services/hermes-core-rollout.js +90 -0
- package/dist/services/hermes-dashboard-endpoint.js +13 -0
- package/dist/services/hermes-plugin-source.js +149 -0
- package/dist/services/hermes-registry-service.js +258 -0
- package/dist/services/hermes-service.js +566 -0
- package/dist/services/hivemem-client.js +85 -0
- package/dist/services/host-local-writer.js +82 -0
- package/dist/services/incident-evidence.js +110 -0
- package/dist/services/incident-lessons.js +186 -0
- package/dist/services/llm-providers/anthropic.js +143 -0
- package/dist/services/llm-providers/index.js +7 -0
- package/dist/services/llm-providers/llama-cpp.js +237 -0
- package/dist/services/llm-providers/ollama.js +292 -0
- package/dist/services/llm-providers/openai-compatible.js +200 -0
- package/dist/services/llm-providers/provider-error.js +36 -0
- package/dist/services/llm-providers/registry.js +45 -0
- package/dist/services/llm-providers/types.js +2 -0
- package/dist/services/log-emitter.js +19 -0
- package/dist/services/log-retention.js +66 -0
- package/dist/services/maintenance-service.js +29 -0
- package/dist/services/managed-cron.js +493 -0
- package/dist/services/managed-ssh-admission.js +68 -0
- package/dist/services/monitor-pulse.js +10 -0
- package/dist/services/node-issue-monitor.js +71 -0
- package/dist/services/node-service.js +35 -0
- package/dist/services/notification-retention.js +51 -0
- package/dist/services/notification-service.js +94 -0
- package/dist/services/operational-observations.js +112 -0
- package/dist/services/operations-config.js +67 -0
- package/dist/services/ops-service.js +491 -0
- package/dist/services/orchestra-extras-service.js +370 -0
- package/dist/services/orchestra-resources-service.js +530 -0
- package/dist/services/os-scheduler-writer.js +73 -0
- package/dist/services/password-service.js +22 -0
- package/dist/services/prediction-service.js +284 -0
- package/dist/services/recovery-exercises.js +682 -0
- package/dist/services/remediation-service.js +325 -0
- package/dist/services/resource-enrollment.js +433 -0
- package/dist/services/resource-node-lock.js +18 -0
- package/dist/services/resource-participant-work.js +302 -0
- package/dist/services/role-service.js +388 -0
- package/dist/services/rollout-service.js +440 -0
- package/dist/services/security-export.js +185 -0
- package/dist/services/security-fusion-actions.js +22 -0
- package/dist/services/security-fusion-approvals.js +83 -0
- package/dist/services/security-fusion-evidence-integrity.js +144 -0
- package/dist/services/security-fusion-ingest.js +101 -0
- package/dist/services/security-fusion-outbox.js +185 -0
- package/dist/services/security-fusion-receipt-chain.js +134 -0
- package/dist/services/security-fusion-service.js +751 -0
- package/dist/services/security-fusion-verification.js +50 -0
- package/dist/services/self-update-service.js +200 -0
- package/dist/services/shared-resource-leases.js +413 -0
- package/dist/services/skill-publication-bundle.js +90 -0
- package/dist/services/skill-publication-settlement.js +36 -0
- package/dist/services/skill-publication-state.js +40 -0
- package/dist/services/skill-registry-service.js +327 -0
- package/dist/services/skill-service.js +148 -0
- package/dist/services/ssh-exec-service.js +139 -0
- package/dist/services/ssh-host-verification.js +27 -0
- package/dist/services/tailscale-node-key-service.js +75 -0
- package/dist/services/team-approvals.js +118 -0
- package/dist/services/topology-service.js +138 -0
- package/dist/services/transfer-authority-snapshot.js +151 -0
- package/dist/services/webhook-credential-migration.js +97 -0
- package/dist/services/webhook-security.js +242 -0
- package/dist/services/webhook-service.js +494 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/library.js +3 -0
- package/dist/types/notifications.js +3 -0
- package/dist/types/roles.js +3 -0
- package/dist/types/shared-contracts.js +3 -0
- package/dist/utils/env.js +141 -0
- package/dist/utils/heartbeat-peer.js +19 -0
- package/dist/utils/idempotency.js +45 -0
- package/dist/utils/ip.js +25 -0
- package/dist/utils/json-fields.js +94 -0
- package/dist/utils/local-tls.js +39 -0
- package/dist/utils/magnus-home.js +15 -0
- package/dist/utils/node-url.js +59 -0
- package/dist/utils/redact.js +26 -0
- package/dist/utils/safe-equal.js +13 -0
- package/dist/utils/sentinel-nodes.js +16 -0
- package/dist/utils/validate.js +41 -0
- package/package.json +119 -4
- package/prisma/migrations/20261031000000_baseline/migration.sql +2935 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +2185 -0
- package/prisma.config.ts +14 -0
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import { getDb } from '../db/index.js';
|
|
2
|
+
import { HttpError } from '../middleware/error-handler.js';
|
|
3
|
+
function asJson(value) {
|
|
4
|
+
return JSON.stringify(value ?? null);
|
|
5
|
+
}
|
|
6
|
+
function safeParse(value, fallback) {
|
|
7
|
+
if (!value)
|
|
8
|
+
return fallback;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return fallback;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function ensureInstallation(installationId) {
|
|
17
|
+
const db = getDb();
|
|
18
|
+
const found = await db.hermesInstallation.findUnique({ where: { id: installationId } });
|
|
19
|
+
if (!found)
|
|
20
|
+
throw new HttpError(404, 'NOT_FOUND', `Hermes installation ${installationId} not found`);
|
|
21
|
+
}
|
|
22
|
+
// ── Skill assignments ──────────────────────────────────────────────────────
|
|
23
|
+
export async function listSkillAssignments(filter) {
|
|
24
|
+
const db = getDb();
|
|
25
|
+
return db.hermesSkillAssignment.findMany({
|
|
26
|
+
where: {
|
|
27
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
28
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
29
|
+
},
|
|
30
|
+
orderBy: { createdAt: 'desc' },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export async function createSkillAssignment(input) {
|
|
34
|
+
await ensureInstallation(input.installationId);
|
|
35
|
+
const db = getDb();
|
|
36
|
+
return db.hermesSkillAssignment.create({
|
|
37
|
+
data: {
|
|
38
|
+
installationId: input.installationId,
|
|
39
|
+
profileId: input.profileId ?? "",
|
|
40
|
+
skillSlug: input.skillSlug,
|
|
41
|
+
pinnedVersion: input.pinnedVersion ?? null,
|
|
42
|
+
source: input.source ?? 'magnus-skills',
|
|
43
|
+
enabled: input.enabled ?? true,
|
|
44
|
+
metadata: asJson(input.metadata ?? {}),
|
|
45
|
+
createdBy: input.actorId,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export async function updateSkillAssignment(id, patch) {
|
|
50
|
+
const db = getDb();
|
|
51
|
+
return db.hermesSkillAssignment.update({
|
|
52
|
+
where: { id },
|
|
53
|
+
data: {
|
|
54
|
+
...(patch.pinnedVersion !== undefined ? { pinnedVersion: patch.pinnedVersion } : {}),
|
|
55
|
+
...(patch.enabled !== undefined ? { enabled: patch.enabled } : {}),
|
|
56
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export async function deleteSkillAssignment(id) {
|
|
61
|
+
const db = getDb();
|
|
62
|
+
await db.hermesSkillAssignment.delete({ where: { id } });
|
|
63
|
+
}
|
|
64
|
+
// ── Toolset policies ────────────────────────────────────────────────────────
|
|
65
|
+
export async function listToolsetPolicies(filter) {
|
|
66
|
+
const db = getDb();
|
|
67
|
+
return db.hermesToolsetPolicy.findMany({
|
|
68
|
+
where: {
|
|
69
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
70
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
71
|
+
},
|
|
72
|
+
orderBy: { createdAt: 'desc' },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export async function upsertToolsetPolicy(input) {
|
|
76
|
+
await ensureInstallation(input.installationId);
|
|
77
|
+
const db = getDb();
|
|
78
|
+
return db.hermesToolsetPolicy.upsert({
|
|
79
|
+
where: {
|
|
80
|
+
installationId_profileId_toolset: {
|
|
81
|
+
installationId: input.installationId,
|
|
82
|
+
profileId: input.profileId ?? "",
|
|
83
|
+
toolset: input.toolset,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
create: {
|
|
87
|
+
installationId: input.installationId,
|
|
88
|
+
profileId: input.profileId ?? "",
|
|
89
|
+
toolset: input.toolset,
|
|
90
|
+
enabled: input.enabled ?? true,
|
|
91
|
+
approvalMode: input.approvalMode ?? 'auto',
|
|
92
|
+
perToolHooks: asJson(input.perToolHooks ?? []),
|
|
93
|
+
allowList: asJson(input.allowList ?? []),
|
|
94
|
+
denyList: asJson(input.denyList ?? []),
|
|
95
|
+
metadata: asJson(input.metadata ?? {}),
|
|
96
|
+
createdBy: input.actorId,
|
|
97
|
+
},
|
|
98
|
+
update: {
|
|
99
|
+
...(input.enabled !== undefined ? { enabled: input.enabled } : {}),
|
|
100
|
+
...(input.approvalMode !== undefined ? { approvalMode: input.approvalMode } : {}),
|
|
101
|
+
...(input.perToolHooks !== undefined ? { perToolHooks: asJson(input.perToolHooks) } : {}),
|
|
102
|
+
...(input.allowList !== undefined ? { allowList: asJson(input.allowList) } : {}),
|
|
103
|
+
...(input.denyList !== undefined ? { denyList: asJson(input.denyList) } : {}),
|
|
104
|
+
...(input.metadata !== undefined ? { metadata: asJson(input.metadata) } : {}),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export async function deleteToolsetPolicy(id) {
|
|
109
|
+
const db = getDb();
|
|
110
|
+
await db.hermesToolsetPolicy.delete({ where: { id } });
|
|
111
|
+
}
|
|
112
|
+
export async function updateToolsetPolicyById(id, patch) {
|
|
113
|
+
const db = getDb();
|
|
114
|
+
return db.hermesToolsetPolicy.update({
|
|
115
|
+
where: { id },
|
|
116
|
+
data: {
|
|
117
|
+
...(patch.enabled !== undefined ? { enabled: patch.enabled } : {}),
|
|
118
|
+
...(patch.approvalMode !== undefined ? { approvalMode: patch.approvalMode } : {}),
|
|
119
|
+
...(patch.perToolHooks !== undefined ? { perToolHooks: asJson(patch.perToolHooks) } : {}),
|
|
120
|
+
...(patch.allowList !== undefined ? { allowList: asJson(patch.allowList) } : {}),
|
|
121
|
+
...(patch.denyList !== undefined ? { denyList: asJson(patch.denyList) } : {}),
|
|
122
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// ── Roles ───────────────────────────────────────────────────────────────────
|
|
127
|
+
export async function listHermesRoles() {
|
|
128
|
+
const db = getDb();
|
|
129
|
+
const rows = await db.hermesRole.findMany({
|
|
130
|
+
include: { applications: true },
|
|
131
|
+
orderBy: { createdAt: 'desc' },
|
|
132
|
+
});
|
|
133
|
+
return rows.map((r) => ({
|
|
134
|
+
...r,
|
|
135
|
+
toolsets: safeParse(r.toolsetsJson, []),
|
|
136
|
+
skills: safeParse(r.skillsJson, []),
|
|
137
|
+
provider: safeParse(r.providerJson, {}),
|
|
138
|
+
cron: safeParse(r.cronJson, []),
|
|
139
|
+
messaging: safeParse(r.messagingJson, []),
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
export async function getHermesRole(id) {
|
|
143
|
+
const db = getDb();
|
|
144
|
+
const r = await db.hermesRole.findUnique({ where: { id }, include: { applications: true } });
|
|
145
|
+
if (!r)
|
|
146
|
+
return null;
|
|
147
|
+
return {
|
|
148
|
+
...r,
|
|
149
|
+
toolsets: safeParse(r.toolsetsJson, []),
|
|
150
|
+
skills: safeParse(r.skillsJson, []),
|
|
151
|
+
provider: safeParse(r.providerJson, {}),
|
|
152
|
+
cron: safeParse(r.cronJson, []),
|
|
153
|
+
messaging: safeParse(r.messagingJson, []),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export async function createHermesRole(input) {
|
|
157
|
+
const db = getDb();
|
|
158
|
+
return db.hermesRole.create({
|
|
159
|
+
data: {
|
|
160
|
+
name: input.name,
|
|
161
|
+
description: input.description ?? '',
|
|
162
|
+
personalityMd: input.personalityMd ?? '',
|
|
163
|
+
personalityRef: input.personalityRef ?? null,
|
|
164
|
+
toolsetsJson: asJson(input.toolsets ?? []),
|
|
165
|
+
skillsJson: asJson(input.skills ?? []),
|
|
166
|
+
providerJson: asJson(input.provider ?? {}),
|
|
167
|
+
cronJson: asJson(input.cron ?? []),
|
|
168
|
+
messagingJson: asJson(input.messaging ?? []),
|
|
169
|
+
metadata: asJson(input.metadata ?? {}),
|
|
170
|
+
createdBy: input.actorId,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
export async function updateHermesRole(id, patch) {
|
|
175
|
+
const db = getDb();
|
|
176
|
+
return db.hermesRole.update({
|
|
177
|
+
where: { id },
|
|
178
|
+
data: {
|
|
179
|
+
...(patch.description !== undefined ? { description: patch.description } : {}),
|
|
180
|
+
...(patch.personalityMd !== undefined ? { personalityMd: patch.personalityMd } : {}),
|
|
181
|
+
...(patch.personalityRef !== undefined ? { personalityRef: patch.personalityRef } : {}),
|
|
182
|
+
...(patch.toolsets !== undefined ? { toolsetsJson: asJson(patch.toolsets) } : {}),
|
|
183
|
+
...(patch.skills !== undefined ? { skillsJson: asJson(patch.skills) } : {}),
|
|
184
|
+
...(patch.provider !== undefined ? { providerJson: asJson(patch.provider) } : {}),
|
|
185
|
+
...(patch.cron !== undefined ? { cronJson: asJson(patch.cron) } : {}),
|
|
186
|
+
...(patch.messaging !== undefined ? { messagingJson: asJson(patch.messaging) } : {}),
|
|
187
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
export async function deleteHermesRole(id) {
|
|
192
|
+
const db = getDb();
|
|
193
|
+
await db.hermesRole.delete({ where: { id } });
|
|
194
|
+
}
|
|
195
|
+
export async function applyHermesRole(roleId, scope) {
|
|
196
|
+
await ensureInstallation(scope.installationId);
|
|
197
|
+
const db = getDb();
|
|
198
|
+
const role = await db.hermesRole.findUnique({ where: { id: roleId } });
|
|
199
|
+
if (!role)
|
|
200
|
+
throw new HttpError(404, 'NOT_FOUND', `Hermes role ${roleId} not found`);
|
|
201
|
+
return db.hermesRoleApplication.upsert({
|
|
202
|
+
where: {
|
|
203
|
+
roleId_installationId_profileId: {
|
|
204
|
+
roleId,
|
|
205
|
+
installationId: scope.installationId,
|
|
206
|
+
profileId: scope.profileId ?? "",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
create: {
|
|
210
|
+
roleId,
|
|
211
|
+
installationId: scope.installationId,
|
|
212
|
+
profileId: scope.profileId ?? "",
|
|
213
|
+
createdBy: scope.actorId,
|
|
214
|
+
},
|
|
215
|
+
update: { status: 'pending', error: null },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// ── Provider configs ────────────────────────────────────────────────────────
|
|
219
|
+
export async function getProviderConfig(installationId, profileId) {
|
|
220
|
+
const db = getDb();
|
|
221
|
+
return db.hermesProviderConfig.findFirst({ where: { installationId, profileId: profileId ?? '' } });
|
|
222
|
+
}
|
|
223
|
+
export async function upsertProviderConfig(input) {
|
|
224
|
+
await ensureInstallation(input.installationId);
|
|
225
|
+
const db = getDb();
|
|
226
|
+
return db.hermesProviderConfig.upsert({
|
|
227
|
+
where: {
|
|
228
|
+
installationId_profileId: { installationId: input.installationId, profileId: input.profileId ?? "" },
|
|
229
|
+
},
|
|
230
|
+
create: {
|
|
231
|
+
installationId: input.installationId,
|
|
232
|
+
profileId: input.profileId ?? "",
|
|
233
|
+
chainJson: asJson(input.chain ?? []),
|
|
234
|
+
sortStrategy: input.sortStrategy ?? 'priority',
|
|
235
|
+
whitelistJson: asJson(input.whitelist ?? []),
|
|
236
|
+
blacklistJson: asJson(input.blacklist ?? []),
|
|
237
|
+
visionOverride: input.visionOverride ?? null,
|
|
238
|
+
compressionOverride: input.compressionOverride ?? null,
|
|
239
|
+
metadata: asJson(input.metadata ?? {}),
|
|
240
|
+
createdBy: input.actorId,
|
|
241
|
+
},
|
|
242
|
+
update: {
|
|
243
|
+
...(input.chain !== undefined ? { chainJson: asJson(input.chain) } : {}),
|
|
244
|
+
...(input.sortStrategy !== undefined ? { sortStrategy: input.sortStrategy } : {}),
|
|
245
|
+
...(input.whitelist !== undefined ? { whitelistJson: asJson(input.whitelist) } : {}),
|
|
246
|
+
...(input.blacklist !== undefined ? { blacklistJson: asJson(input.blacklist) } : {}),
|
|
247
|
+
...(input.visionOverride !== undefined ? { visionOverride: input.visionOverride } : {}),
|
|
248
|
+
...(input.compressionOverride !== undefined ? { compressionOverride: input.compressionOverride } : {}),
|
|
249
|
+
...(input.metadata !== undefined ? { metadata: asJson(input.metadata) } : {}),
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
// ── Credential pools ────────────────────────────────────────────────────────
|
|
254
|
+
export async function listCredentialPools() {
|
|
255
|
+
const db = getDb();
|
|
256
|
+
return db.hermesCredentialPool.findMany({
|
|
257
|
+
include: { attachments: true },
|
|
258
|
+
orderBy: { createdAt: 'desc' },
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
export async function createCredentialPool(input) {
|
|
262
|
+
const db = getDb();
|
|
263
|
+
return db.hermesCredentialPool.create({
|
|
264
|
+
data: {
|
|
265
|
+
name: input.name,
|
|
266
|
+
provider: input.provider,
|
|
267
|
+
rotationPolicy: input.rotationPolicy ?? 'rate-limit',
|
|
268
|
+
secretRefsJson: asJson(input.secretRefs ?? []),
|
|
269
|
+
metadata: asJson(input.metadata ?? {}),
|
|
270
|
+
createdBy: input.actorId,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
export async function updateCredentialPool(id, patch) {
|
|
275
|
+
const db = getDb();
|
|
276
|
+
return db.hermesCredentialPool.update({
|
|
277
|
+
where: { id },
|
|
278
|
+
data: {
|
|
279
|
+
...(patch.provider !== undefined ? { provider: patch.provider } : {}),
|
|
280
|
+
...(patch.rotationPolicy !== undefined ? { rotationPolicy: patch.rotationPolicy } : {}),
|
|
281
|
+
...(patch.secretRefs !== undefined ? { secretRefsJson: asJson(patch.secretRefs) } : {}),
|
|
282
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
export async function deleteCredentialPool(id) {
|
|
287
|
+
const db = getDb();
|
|
288
|
+
await db.hermesCredentialPool.delete({ where: { id } });
|
|
289
|
+
}
|
|
290
|
+
export async function attachCredentialPool(poolId, scope) {
|
|
291
|
+
await ensureInstallation(scope.installationId);
|
|
292
|
+
const db = getDb();
|
|
293
|
+
return db.hermesCredentialPoolAttachment.upsert({
|
|
294
|
+
where: {
|
|
295
|
+
poolId_installationId_profileId: { poolId, installationId: scope.installationId, profileId: scope.profileId ?? "" },
|
|
296
|
+
},
|
|
297
|
+
create: { poolId, installationId: scope.installationId, profileId: scope.profileId ?? "", createdBy: scope.actorId },
|
|
298
|
+
update: { status: 'pending' },
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
export async function detachCredentialPool(attachmentId) {
|
|
302
|
+
const db = getDb();
|
|
303
|
+
await db.hermesCredentialPoolAttachment.delete({ where: { id: attachmentId } });
|
|
304
|
+
}
|
|
305
|
+
// ── MCP servers ─────────────────────────────────────────────────────────────
|
|
306
|
+
export async function listMcpServers() {
|
|
307
|
+
const db = getDb();
|
|
308
|
+
return db.hermesMcpServer.findMany({ include: { attachments: true }, orderBy: { createdAt: 'desc' } });
|
|
309
|
+
}
|
|
310
|
+
export async function createMcpServer(input) {
|
|
311
|
+
const db = getDb();
|
|
312
|
+
return db.hermesMcpServer.create({
|
|
313
|
+
data: {
|
|
314
|
+
name: input.name,
|
|
315
|
+
transport: input.transport,
|
|
316
|
+
endpoint: input.endpoint ?? '',
|
|
317
|
+
argsJson: asJson(input.args ?? []),
|
|
318
|
+
envJson: asJson(input.env ?? {}),
|
|
319
|
+
toolFilterJson: asJson(input.toolFilter ?? []),
|
|
320
|
+
samplingEnabled: input.samplingEnabled ?? false,
|
|
321
|
+
metadata: asJson(input.metadata ?? {}),
|
|
322
|
+
createdBy: input.actorId,
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
export async function updateMcpServer(id, patch) {
|
|
327
|
+
const db = getDb();
|
|
328
|
+
return db.hermesMcpServer.update({
|
|
329
|
+
where: { id },
|
|
330
|
+
data: {
|
|
331
|
+
...(patch.transport !== undefined ? { transport: patch.transport } : {}),
|
|
332
|
+
...(patch.endpoint !== undefined ? { endpoint: patch.endpoint } : {}),
|
|
333
|
+
...(patch.args !== undefined ? { argsJson: asJson(patch.args) } : {}),
|
|
334
|
+
...(patch.env !== undefined ? { envJson: asJson(patch.env) } : {}),
|
|
335
|
+
...(patch.toolFilter !== undefined ? { toolFilterJson: asJson(patch.toolFilter) } : {}),
|
|
336
|
+
...(patch.samplingEnabled !== undefined ? { samplingEnabled: patch.samplingEnabled } : {}),
|
|
337
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
export async function deleteMcpServer(id) {
|
|
342
|
+
const db = getDb();
|
|
343
|
+
await db.hermesMcpServer.delete({ where: { id } });
|
|
344
|
+
}
|
|
345
|
+
export async function attachMcpServer(serverId, scope) {
|
|
346
|
+
await ensureInstallation(scope.installationId);
|
|
347
|
+
const db = getDb();
|
|
348
|
+
return db.hermesMcpServerAttachment.upsert({
|
|
349
|
+
where: { serverId_installationId_profileId: { serverId, installationId: scope.installationId, profileId: scope.profileId ?? "" } },
|
|
350
|
+
create: { serverId, installationId: scope.installationId, profileId: scope.profileId ?? "", createdBy: scope.actorId },
|
|
351
|
+
update: { status: 'pending' },
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
export async function detachMcpServer(attachmentId) {
|
|
355
|
+
const db = getDb();
|
|
356
|
+
await db.hermesMcpServerAttachment.delete({ where: { id: attachmentId } });
|
|
357
|
+
}
|
|
358
|
+
// ── Messaging bindings ──────────────────────────────────────────────────────
|
|
359
|
+
export async function listMessagingBindings(filter) {
|
|
360
|
+
const db = getDb();
|
|
361
|
+
return db.hermesMessagingBinding.findMany({
|
|
362
|
+
where: {
|
|
363
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
364
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
365
|
+
},
|
|
366
|
+
orderBy: { createdAt: 'desc' },
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
export async function createMessagingBinding(input) {
|
|
370
|
+
await ensureInstallation(input.installationId);
|
|
371
|
+
const db = getDb();
|
|
372
|
+
return db.hermesMessagingBinding.create({
|
|
373
|
+
data: {
|
|
374
|
+
installationId: input.installationId,
|
|
375
|
+
profileId: input.profileId ?? "",
|
|
376
|
+
platform: input.platform,
|
|
377
|
+
channelIdsJson: asJson(input.channelIds ?? []),
|
|
378
|
+
voiceEnabled: input.voiceEnabled ?? false,
|
|
379
|
+
voiceModel: input.voiceModel ?? null,
|
|
380
|
+
ttsProvider: input.ttsProvider ?? null,
|
|
381
|
+
secretRef: input.secretRef ?? null,
|
|
382
|
+
metadata: asJson(input.metadata ?? {}),
|
|
383
|
+
createdBy: input.actorId,
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
export async function updateMessagingBinding(id, patch) {
|
|
388
|
+
const db = getDb();
|
|
389
|
+
return db.hermesMessagingBinding.update({
|
|
390
|
+
where: { id },
|
|
391
|
+
data: {
|
|
392
|
+
...(patch.channelIds !== undefined ? { channelIdsJson: asJson(patch.channelIds) } : {}),
|
|
393
|
+
...(patch.voiceEnabled !== undefined ? { voiceEnabled: patch.voiceEnabled } : {}),
|
|
394
|
+
...(patch.voiceModel !== undefined ? { voiceModel: patch.voiceModel } : {}),
|
|
395
|
+
...(patch.ttsProvider !== undefined ? { ttsProvider: patch.ttsProvider } : {}),
|
|
396
|
+
...(patch.secretRef !== undefined ? { secretRef: patch.secretRef } : {}),
|
|
397
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
export async function deleteMessagingBinding(id) {
|
|
402
|
+
const db = getDb();
|
|
403
|
+
await db.hermesMessagingBinding.delete({ where: { id } });
|
|
404
|
+
}
|
|
405
|
+
// ── Hermes cron jobs ────────────────────────────────────────────────────────
|
|
406
|
+
export async function listHermesCronJobs(filter) {
|
|
407
|
+
const db = getDb();
|
|
408
|
+
return db.hermesCronJob.findMany({
|
|
409
|
+
where: {
|
|
410
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
411
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
412
|
+
},
|
|
413
|
+
orderBy: { createdAt: 'desc' },
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
export async function createHermesCronJob(input) {
|
|
417
|
+
await ensureInstallation(input.installationId);
|
|
418
|
+
const db = getDb();
|
|
419
|
+
return db.hermesCronJob.create({
|
|
420
|
+
data: {
|
|
421
|
+
installationId: input.installationId,
|
|
422
|
+
profileId: input.profileId ?? "",
|
|
423
|
+
name: input.name,
|
|
424
|
+
prompt: input.prompt ?? '',
|
|
425
|
+
cronExpr: input.cronExpr ?? '',
|
|
426
|
+
naturalLanguage: input.naturalLanguage ?? null,
|
|
427
|
+
attachedSkillsJson: asJson(input.attachedSkills ?? []),
|
|
428
|
+
deliveryJson: asJson(input.delivery ?? {}),
|
|
429
|
+
enabled: input.enabled ?? true,
|
|
430
|
+
metadata: asJson(input.metadata ?? {}),
|
|
431
|
+
createdBy: input.actorId,
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
export async function updateHermesCronJob(id, patch) {
|
|
436
|
+
const db = getDb();
|
|
437
|
+
return db.hermesCronJob.update({
|
|
438
|
+
where: { id },
|
|
439
|
+
data: {
|
|
440
|
+
...(patch.prompt !== undefined ? { prompt: patch.prompt } : {}),
|
|
441
|
+
...(patch.cronExpr !== undefined ? { cronExpr: patch.cronExpr } : {}),
|
|
442
|
+
...(patch.naturalLanguage !== undefined ? { naturalLanguage: patch.naturalLanguage } : {}),
|
|
443
|
+
...(patch.attachedSkills !== undefined ? { attachedSkillsJson: asJson(patch.attachedSkills) } : {}),
|
|
444
|
+
...(patch.delivery !== undefined ? { deliveryJson: asJson(patch.delivery) } : {}),
|
|
445
|
+
...(patch.enabled !== undefined ? { enabled: patch.enabled } : {}),
|
|
446
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
export async function deleteHermesCronJob(id) {
|
|
451
|
+
const db = getDb();
|
|
452
|
+
await db.hermesCronJob.delete({ where: { id } });
|
|
453
|
+
}
|
|
454
|
+
// ── Plugins ─────────────────────────────────────────────────────────────────
|
|
455
|
+
export async function listHermesPlugins(filter) {
|
|
456
|
+
const db = getDb();
|
|
457
|
+
return db.hermesPluginInstall.findMany({
|
|
458
|
+
where: {
|
|
459
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
460
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
461
|
+
},
|
|
462
|
+
orderBy: { createdAt: 'desc' },
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
export async function installHermesPlugin(input) {
|
|
466
|
+
await ensureInstallation(input.installationId);
|
|
467
|
+
const db = getDb();
|
|
468
|
+
return db.hermesPluginInstall.upsert({
|
|
469
|
+
where: { installationId_profileId_pluginSlug: { installationId: input.installationId, profileId: input.profileId ?? "", pluginSlug: input.pluginSlug } },
|
|
470
|
+
create: {
|
|
471
|
+
installationId: input.installationId,
|
|
472
|
+
profileId: input.profileId ?? "",
|
|
473
|
+
pluginSlug: input.pluginSlug,
|
|
474
|
+
pluginType: input.pluginType ?? 'general',
|
|
475
|
+
pinnedVersion: input.pinnedVersion ?? null,
|
|
476
|
+
metadata: asJson(input.metadata ?? {}),
|
|
477
|
+
createdBy: input.actorId,
|
|
478
|
+
},
|
|
479
|
+
update: { status: 'pending', pinnedVersion: input.pinnedVersion ?? null },
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
export async function removeHermesPlugin(id) {
|
|
483
|
+
const db = getDb();
|
|
484
|
+
await db.hermesPluginInstall.delete({ where: { id } });
|
|
485
|
+
}
|
|
486
|
+
// ── Hooks ───────────────────────────────────────────────────────────────────
|
|
487
|
+
export async function listHermesHooks(filter) {
|
|
488
|
+
const db = getDb();
|
|
489
|
+
return db.hermesHook.findMany({
|
|
490
|
+
where: {
|
|
491
|
+
...(filter.installationId ? { installationId: filter.installationId } : {}),
|
|
492
|
+
...(filter.profileId ? { profileId: filter.profileId } : {}),
|
|
493
|
+
},
|
|
494
|
+
orderBy: { createdAt: 'desc' },
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
export async function createHermesHook(input) {
|
|
498
|
+
await ensureInstallation(input.installationId);
|
|
499
|
+
const db = getDb();
|
|
500
|
+
return db.hermesHook.create({
|
|
501
|
+
data: {
|
|
502
|
+
installationId: input.installationId,
|
|
503
|
+
profileId: input.profileId ?? "",
|
|
504
|
+
event: input.event,
|
|
505
|
+
target: input.target,
|
|
506
|
+
configJson: asJson(input.config ?? {}),
|
|
507
|
+
enabled: input.enabled ?? true,
|
|
508
|
+
metadata: asJson(input.metadata ?? {}),
|
|
509
|
+
createdBy: input.actorId,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
export async function updateHermesHook(id, patch) {
|
|
514
|
+
const db = getDb();
|
|
515
|
+
return db.hermesHook.update({
|
|
516
|
+
where: { id },
|
|
517
|
+
data: {
|
|
518
|
+
...(patch.event !== undefined ? { event: patch.event } : {}),
|
|
519
|
+
...(patch.target !== undefined ? { target: patch.target } : {}),
|
|
520
|
+
...(patch.config !== undefined ? { configJson: asJson(patch.config) } : {}),
|
|
521
|
+
...(patch.enabled !== undefined ? { enabled: patch.enabled } : {}),
|
|
522
|
+
...(patch.metadata !== undefined ? { metadata: asJson(patch.metadata) } : {}),
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
export async function deleteHermesHook(id) {
|
|
527
|
+
const db = getDb();
|
|
528
|
+
await db.hermesHook.delete({ where: { id } });
|
|
529
|
+
}
|
|
530
|
+
//# sourceMappingURL=orchestra-resources-service.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Fresh owner proof of the exact, fully quiescent OS scheduler boundary. */
|
|
2
|
+
import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { canonical } from './resource-enrollment.js';
|
|
5
|
+
import { getNodeBaseUrl } from '../utils/node-url.js';
|
|
6
|
+
import { getNodeManagerSecret, RESULT_SIGNING_SECRET } from '../utils/env.js';
|
|
7
|
+
const hex = z.string().regex(/^[a-f0-9]{64}$/);
|
|
8
|
+
const proofSchema = z.object({ version: z.literal(1), sourceClass: z.literal('os-schedulers'),
|
|
9
|
+
nodeId: z.string().min(1).max(128), nodeFqdn: z.string().min(1).max(253),
|
|
10
|
+
epoch: z.number().int().positive(), barrierId: z.string().guid(), nonce: z.string().guid(),
|
|
11
|
+
observedAt: z.number().int().positive(), active: z.literal(0), unknown: z.literal(0),
|
|
12
|
+
scheduleInventorySha256: hex, admissionFenceSha256: hex, signature: hex }).strict();
|
|
13
|
+
const DOMAIN = 'magnus.os-scheduler-writer.v1\n';
|
|
14
|
+
export function verifyOsSchedulerWriterProof(raw, expected, now = Date.now()) {
|
|
15
|
+
const parsed = proofSchema.safeParse(raw);
|
|
16
|
+
if (!parsed.success || RESULT_SIGNING_SECRET.length < 32)
|
|
17
|
+
return null;
|
|
18
|
+
const { signature, ...receipt } = parsed.data;
|
|
19
|
+
if (receipt.nodeId !== expected.nodeId || receipt.nodeFqdn !== expected.nodeFqdn
|
|
20
|
+
|| receipt.nonce !== expected.nonce || receipt.epoch !== expected.epoch
|
|
21
|
+
|| receipt.barrierId !== expected.barrierId || now - receipt.observedAt < -1000
|
|
22
|
+
|| now - receipt.observedAt > 20_000)
|
|
23
|
+
return null;
|
|
24
|
+
const exactFence = createHash('sha256').update(canonical({ sourceClass: 'os-schedulers',
|
|
25
|
+
nodeId: expected.nodeId, nodeFqdn: expected.nodeFqdn, epoch: expected.epoch,
|
|
26
|
+
barrierId: expected.barrierId })).digest('hex');
|
|
27
|
+
if (receipt.admissionFenceSha256 !== exactFence)
|
|
28
|
+
return null;
|
|
29
|
+
const signed = createHmac('sha256', RESULT_SIGNING_SECRET).update(DOMAIN + canonical(receipt)).digest();
|
|
30
|
+
if (!timingSafeEqual(signed, Buffer.from(signature, 'hex')))
|
|
31
|
+
return null;
|
|
32
|
+
return { ownerReceiptSha256: createHash('sha256').update(canonical(parsed.data)).digest('hex'),
|
|
33
|
+
admissionFenceSha256: receipt.admissionFenceSha256,
|
|
34
|
+
scheduleInventorySha256: receipt.scheduleInventorySha256 };
|
|
35
|
+
}
|
|
36
|
+
export async function fetchOsSchedulerWriterProof(node, nodeFqdn, nonce) {
|
|
37
|
+
try {
|
|
38
|
+
if (RESULT_SIGNING_SECRET.length < 32)
|
|
39
|
+
return null;
|
|
40
|
+
const base = getNodeBaseUrl(node.ipAddress, node.port);
|
|
41
|
+
if (new URL(base).protocol !== 'https:')
|
|
42
|
+
return null;
|
|
43
|
+
const url = new URL(base + '/api/v1/cron/os-scheduler-writer-proof');
|
|
44
|
+
url.search = new URLSearchParams({ nodeFqdn, nonce }).toString();
|
|
45
|
+
const response = await fetch(url, { method: 'GET', redirect: 'error', signal: AbortSignal.timeout(5000),
|
|
46
|
+
headers: { 'x-node-token': getNodeManagerSecret(), 'cache-control': 'no-store' } });
|
|
47
|
+
if (!response.ok || !response.body)
|
|
48
|
+
return null;
|
|
49
|
+
const reader = response.body.getReader();
|
|
50
|
+
const parts = [];
|
|
51
|
+
let size = 0;
|
|
52
|
+
try {
|
|
53
|
+
while (true) {
|
|
54
|
+
const { value, done } = await reader.read();
|
|
55
|
+
if (done)
|
|
56
|
+
break;
|
|
57
|
+
size += value.byteLength;
|
|
58
|
+
if (size > 4096)
|
|
59
|
+
return null;
|
|
60
|
+
parts.push(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await reader.cancel().catch(() => undefined);
|
|
65
|
+
}
|
|
66
|
+
const envelope = JSON.parse(Buffer.concat(parts).toString('utf8'));
|
|
67
|
+
return envelope.success === true ? envelope.data : null;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=os-scheduler-writer.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import argon2 from 'argon2';
|
|
2
|
+
/** Argon2id config per project security conventions. */
|
|
3
|
+
const ARGON2_OPTIONS = {
|
|
4
|
+
type: argon2.argon2id,
|
|
5
|
+
memoryCost: 65536,
|
|
6
|
+
timeCost: 3,
|
|
7
|
+
parallelism: 4,
|
|
8
|
+
};
|
|
9
|
+
/** Hash a plaintext password with Argon2id. */
|
|
10
|
+
export async function hashPassword(password) {
|
|
11
|
+
return argon2.hash(password, ARGON2_OPTIONS);
|
|
12
|
+
}
|
|
13
|
+
/** Verify a plaintext password against a stored Argon2id hash. */
|
|
14
|
+
export async function verifyPassword(hash, password) {
|
|
15
|
+
try {
|
|
16
|
+
return await argon2.verify(hash, password);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=password-service.js.map
|