@semacode/cli 2.3.0 → 3.0.0
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/LICENSE +39 -39
- package/README.md +112 -41
- package/dist/agentContextPack.js +14 -10
- package/dist/agentEntryPoints.d.ts +5 -0
- package/dist/agentEntryPoints.js +102 -91
- package/dist/angular-consumer-standalone.d.ts +3 -1
- package/dist/angular-consumer-standalone.js +12 -8
- package/dist/bin.d.ts +6 -0
- package/dist/bin.js +130 -0
- package/dist/cliArgs.js +4 -4
- package/dist/cliControlError.d.ts +12 -0
- package/dist/cliControlError.js +47 -0
- package/dist/cliGrammar.d.ts +11 -0
- package/dist/cliGrammar.js +551 -0
- package/dist/cliHelp.d.ts +13 -0
- package/dist/cliHelp.js +19 -0
- package/dist/cliHelpTexto.d.ts +3 -0
- package/dist/cliHelpTexto.js +168 -0
- package/dist/cliRuntime.d.ts +2 -0
- package/dist/cliRuntime.js +31 -0
- package/dist/comandos.js +9 -22
- package/dist/contexto.js +5 -5
- package/dist/dev/index.d.ts +1 -0
- package/dist/dev/index.js +51 -9
- package/dist/discovery/catalog.js +3 -3
- package/dist/distribuicao/filesystemGlobal.d.ts +63 -0
- package/dist/distribuicao/filesystemGlobal.js +701 -0
- package/dist/distribuicao/index.d.ts +7 -0
- package/dist/distribuicao/index.js +227 -0
- package/dist/distribuicao/launcherGlobal.d.ts +53 -0
- package/dist/distribuicao/launcherGlobal.js +643 -0
- package/dist/distribuicao/launcherWindows.d.ts +28 -0
- package/dist/distribuicao/launcherWindows.js +326 -0
- package/dist/distribuicao/lockContextGlobal.d.ts +10 -0
- package/dist/distribuicao/lockContextGlobal.js +17 -0
- package/dist/distribuicao/lockGlobal.d.ts +6 -0
- package/dist/distribuicao/lockGlobal.js +520 -0
- package/dist/distribuicao/skillGlobal.d.ts +48 -0
- package/dist/distribuicao/skillGlobal.js +652 -0
- package/dist/distribuicao/skillIntentPolicy.d.ts +21 -0
- package/dist/distribuicao/skillIntentPolicy.js +115 -0
- package/dist/distribuicao/tipos.d.ts +50 -0
- package/dist/distribuicao/tipos.js +10 -0
- package/dist/distribuicao/versaoSemantica.d.ts +3 -0
- package/dist/distribuicao/versaoSemantica.js +62 -0
- package/dist/drift.part01.d.ts +34 -2
- package/dist/drift.part01.js +3 -0
- package/dist/drift.part04.d.ts +12 -2
- package/dist/drift.part04.js +89 -15
- package/dist/drift.part05.d.ts +2 -1
- package/dist/drift.part05.js +9 -6
- package/dist/drift.part06.d.ts +2 -1
- package/dist/drift.part06.js +115 -24
- package/dist/drift.part07.d.ts +11 -10
- package/dist/drift.part07.js +261 -255
- package/dist/drift.part08.d.ts +2 -1
- package/dist/drift.part08.js +35 -25
- package/dist/drift.part11.js +279 -32
- package/dist/drift.part12.d.ts +1 -1
- package/dist/drift.part12.js +196 -11
- package/dist/drift.part13.d.ts +18 -2
- package/dist/drift.part13.js +654 -76
- package/dist/drift.part14.js +21 -7
- package/dist/driftCacheCas.d.ts +43 -0
- package/dist/driftCacheCas.js +351 -0
- package/dist/driftCacheFilesystem.d.ts +64 -0
- package/dist/driftCacheFilesystem.js +313 -0
- package/dist/driftCacheModes.d.ts +38 -0
- package/dist/driftCacheModes.js +147 -0
- package/dist/driftCacheStore.d.ts +80 -0
- package/dist/driftCacheStore.js +603 -0
- package/dist/driftCatalogo.d.ts +65 -0
- package/dist/driftCatalogo.js +516 -0
- package/dist/driftEscopo.d.ts +21 -0
- package/dist/driftEscopo.js +647 -0
- package/dist/driftEscopoReferencias.d.ts +8 -0
- package/dist/driftEscopoReferencias.js +612 -0
- package/dist/driftOrcamento.d.ts +6 -0
- package/dist/driftOrcamento.js +20 -3
- package/dist/geracaoCore.js +4 -6
- package/dist/iaPrompts.d.ts +3 -3
- package/dist/iaPrompts.js +13 -14
- package/dist/index.d.ts +4 -1
- package/dist/index.js +6 -25
- package/dist/index.part01.d.ts +21 -14
- package/dist/index.part01.js +20 -165
- package/dist/index.part02.js +57 -43
- package/dist/index.part03.d.ts +23 -1
- package/dist/index.part03.js +83 -8
- package/dist/index.part04.d.ts +10 -2
- package/dist/index.part04.js +48 -14
- package/dist/index.part05.d.ts +1 -1
- package/dist/index.part05.js +109 -30
- package/dist/index.part06.js +34 -16
- package/dist/index.part07.js +31 -27
- package/dist/index.part08.d.ts +1 -1
- package/dist/index.part08.js +23 -28
- package/dist/init/templates.part01.js +393 -393
- package/dist/init/templates.part02.js +189 -189
- package/dist/initCommand.js +5 -1
- package/dist/initTemplatesBackend.js +73 -73
- package/dist/initTemplatesBase.js +7 -5
- package/dist/initTemplatesFlutter.js +137 -137
- package/dist/initTemplatesRuntime.js +350 -350
- package/dist/initTemplatesWeb.js +309 -309
- package/dist/pipelineConteudo/command.d.ts +1 -0
- package/dist/pipelineConteudo/command.js +4 -32
- package/dist/pipelineConteudo/help.d.ts +2 -0
- package/dist/pipelineConteudo/help.js +33 -0
- package/dist/profileAuthorCommand.js +3 -7
- package/dist/profileCommand.js +3 -7
- package/dist/projeto.d.ts +1 -1
- package/dist/projetoCarregar.d.ts +2 -2
- package/dist/projetoCarregar.js +69 -28
- package/dist/projetoCatalogo.d.ts +8 -0
- package/dist/projetoCatalogo.js +164 -0
- package/dist/projetoOrigens.d.ts +2 -0
- package/dist/projetoOrigens.js +65 -9
- package/dist/projetoTipos.d.ts +15 -5
- package/dist/resultadoCli.d.ts +20 -0
- package/dist/resultadoCli.js +57 -0
- package/dist/saidaCli.d.ts +35 -0
- package/dist/saidaCli.js +118 -0
- package/dist/sistemasInterativos/acceptanceEvidence.d.ts +22 -0
- package/dist/sistemasInterativos/acceptanceEvidence.js +345 -0
- package/dist/sistemasInterativos/engineObservation.d.ts +12 -0
- package/dist/sistemasInterativos/engineObservation.js +438 -0
- package/dist/sistemasInterativos/jobOrchestration.d.ts +2 -0
- package/dist/sistemasInterativos/jobOrchestration.js +204 -0
- package/dist/sistemasInterativos/operationPrimitives.d.ts +21 -0
- package/dist/sistemasInterativos/operationPrimitives.js +194 -0
- package/dist/sistemasInterativos/operations.d.ts +4 -39
- package/dist/sistemasInterativos/operations.js +5 -1164
- package/dist/skillCommand.d.ts +5 -0
- package/dist/skillCommand.js +88 -0
- package/dist/sync/index.js +35 -35
- package/docs/README.md +11 -7
- package/docs/ai-integration.md +18 -11
- package/docs/ai-onboarding.md +81 -62
- package/docs/ai-workflow.md +10 -4
- package/docs/auth.md +26 -26
- package/docs/cli.md +197 -79
- package/docs/commands.md +30 -6
- package/docs/database.md +15 -15
- package/docs/deploy.md +54 -41
- package/docs/documentation.md +11 -10
- package/docs/drift-cache.md +108 -0
- package/docs/env.md +16 -16
- package/docs/frontend.md +41 -41
- package/docs/getting-started.md +82 -57
- package/docs/i18n.md +15 -15
- package/docs/repositories.md +60 -43
- package/docs/rollback.md +38 -31
- package/docs/security.md +54 -32
- package/docs/sistemas-interativos.md +27 -27
- package/docs/support.md +8 -8
- package/docs/testing.md +123 -17
- package/docs/vocabulary.md +29 -29
- package/exemplos/agendamento.sema +1 -1
- package/exemplos/assinatura.sema +1 -1
- package/exemplos/auditoria.sema +1 -1
- package/exemplos/autenticacao.sema +1 -1
- package/exemplos/author_obra_comum.sema +1 -1
- package/exemplos/author_tema_sensivel.sema +1 -1
- package/exemplos/automacao.sema +1 -1
- package/exemplos/cadastro_usuario.sema +1 -1
- package/exemplos/calculadora.sema +1 -1
- package/exemplos/crud_simples.sema +1 -1
- package/exemplos/estoque.sema +1 -1
- package/exemplos/exportacao.sema +1 -1
- package/exemplos/fila.sema +1 -1
- package/exemplos/integracao_externa.sema +1 -1
- package/exemplos/multi_tenant.sema +1 -1
- package/exemplos/notificacao.sema +1 -1
- package/exemplos/operacao_estrategia.sema +132 -132
- package/exemplos/operacao_estrategia_discovery.sema +220 -220
- package/exemplos/operacao_estrategia_fluxo.sema +114 -114
- package/exemplos/operacao_estrategia_gates.sema +106 -106
- package/exemplos/operacao_estrategia_quarentena.sema +133 -133
- package/exemplos/operacao_estrategia_rollout.sema +124 -124
- package/exemplos/pagamento.sema +1 -1
- package/exemplos/pagamento_dominio.sema +1 -1
- package/exemplos/pedido.sema +1 -1
- package/exemplos/permissao.sema +1 -1
- package/exemplos/persistencia_vendor_first.sema +1 -1
- package/exemplos/profile_conversas.sema +165 -165
- package/exemplos/profile_game.sema +1 -1
- package/exemplos/profile_legal.sema +1 -1
- package/exemplos/profile_ops.sema +1 -1
- package/exemplos/profile_research.sema +1 -1
- package/exemplos/profile_software.sema +1 -1
- package/exemplos/profile_workflow_n8n.sema +1 -1
- package/exemplos/relatorio.sema +1 -1
- package/exemplos/replica_analitica_erp.sema +1 -1
- package/exemplos/testes_embutidos.sema +1 -1
- package/exemplos/tratamento_erro.sema +1 -1
- package/exemplos/upload_arquivo.sema +1 -1
- package/exemplos/webhook.sema +1 -1
- package/node_modules/@sema/gerador-cpp/dist/index.js +176 -176
- package/node_modules/@sema/gerador-css/dist/index.part01.js +10 -10
- package/node_modules/@sema/gerador-css/dist/index.part02.js +460 -460
- package/node_modules/@sema/gerador-dotnet/dist/index.js +169 -169
- package/node_modules/@sema/gerador-html/dist/index.js +17 -17
- package/node_modules/@sema/gerador-python/dist/index.part02.js +3 -3
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js +11 -11
- package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js +42 -42
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1 -0
- package/package.json +7 -2
- package/scripts/postinstall.mjs +148 -0
- package/skills/sema/SKILL.md +199 -0
- package/skills/sema/agents/openai.yaml +4 -0
- package/node_modules/@sema/gerador-cpp/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-dotnet/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-php/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/snippets.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.declaracoes.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.modulo.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part04.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part05.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part06.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part07.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part08.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/orcamentoSemantico.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
- package/node_modules/@sema/padroes/dist/index.js.map +0 -1
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.sistemas_interativos.operacao, sema.produto.sistemas_interativos.operacao.observacao_engine
|
|
2
|
+
// Descricao: snapshots, diffs, proveniencia de assets e estado declarado de editor, sem sondar runtimes.
|
|
3
|
+
import { ASSET_PROVENANCE_SCHEMA_V1, EDITOR_STATE_SCHEMA_V1, ENGINE_DIFF_SCHEMA_V1, ENGINE_SNAPSHOT_SCHEMA_V1, } from "./operationsTypes.js";
|
|
4
|
+
import { digestJsonOperacional, failure, hasOnlyKeys, inspectPlainJson, isIntegerIn, isIsoTimestamp, isOpaqueSha256, isRecord, isSafeName, isSemanticId, isSha256, isVersion, issue, success, } from "./operationPrimitives.js";
|
|
5
|
+
export function validarSnapshotEngine(input) {
|
|
6
|
+
const issues = inspectPlainJson(input, "snapshot");
|
|
7
|
+
if (!isRecord(input))
|
|
8
|
+
return failure([...issues, issue("snapshot_object_required", "snapshot")]);
|
|
9
|
+
if (!hasOnlyKeys(input, [
|
|
10
|
+
"schemaVersion", "snapshotId", "projectId", "sceneId", "adapter",
|
|
11
|
+
"semanticObjects", "artifactDigest", "readOnly", "authoritative",
|
|
12
|
+
]))
|
|
13
|
+
issues.push(issue("snapshot_unknown_field", "snapshot"));
|
|
14
|
+
if (input.schemaVersion !== ENGINE_SNAPSHOT_SCHEMA_V1)
|
|
15
|
+
issues.push(issue("snapshot_schema_invalid", "schemaVersion"));
|
|
16
|
+
if (!isSemanticId(input.snapshotId))
|
|
17
|
+
issues.push(issue("snapshot_id_invalid", "snapshotId"));
|
|
18
|
+
if (!isSemanticId(input.projectId))
|
|
19
|
+
issues.push(issue("project_id_invalid", "projectId"));
|
|
20
|
+
if (!isSemanticId(input.sceneId))
|
|
21
|
+
issues.push(issue("scene_id_invalid", "sceneId"));
|
|
22
|
+
if (!isSha256(input.artifactDigest))
|
|
23
|
+
issues.push(issue("artifact_digest_invalid", "artifactDigest"));
|
|
24
|
+
if (input.readOnly !== true)
|
|
25
|
+
issues.push(issue("snapshot_must_be_read_only", "readOnly"));
|
|
26
|
+
if (input.authoritative !== false)
|
|
27
|
+
issues.push(issue("snapshot_must_be_non_authoritative", "authoritative"));
|
|
28
|
+
const adapter = input.adapter;
|
|
29
|
+
if (!isRecord(adapter)
|
|
30
|
+
|| !hasOnlyKeys(adapter, ["adapterId", "adapterVersion"])
|
|
31
|
+
|| !isSafeName(adapter.adapterId)
|
|
32
|
+
|| !isVersion(adapter.adapterVersion))
|
|
33
|
+
issues.push(issue("snapshot_adapter_invalid", "adapter"));
|
|
34
|
+
const objects = input.semanticObjects;
|
|
35
|
+
const ids = new Set();
|
|
36
|
+
if (!Array.isArray(objects) || objects.length === 0) {
|
|
37
|
+
issues.push(issue("snapshot_objects_required", "semanticObjects"));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
for (const object of objects) {
|
|
41
|
+
if (!isRecord(object) || !hasOnlyKeys(object, [
|
|
42
|
+
"semanticId", "kind", "parentSemanticId", "stateDigest", "componentDigests",
|
|
43
|
+
])) {
|
|
44
|
+
issues.push(issue("snapshot_object_invalid", "semanticObjects"));
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!isSemanticId(object.semanticId))
|
|
48
|
+
issues.push(issue("semantic_object_id_invalid", "semanticObjects"));
|
|
49
|
+
else if (ids.has(object.semanticId))
|
|
50
|
+
issues.push(issue("semantic_object_id_duplicate", "semanticObjects"));
|
|
51
|
+
else
|
|
52
|
+
ids.add(object.semanticId);
|
|
53
|
+
if (!isSafeName(object.kind))
|
|
54
|
+
issues.push(issue("semantic_object_kind_invalid", "semanticObjects"));
|
|
55
|
+
if (object.parentSemanticId !== undefined && !isSemanticId(object.parentSemanticId)) {
|
|
56
|
+
issues.push(issue("semantic_parent_id_invalid", "semanticObjects"));
|
|
57
|
+
}
|
|
58
|
+
if (!isSha256(object.stateDigest))
|
|
59
|
+
issues.push(issue("semantic_state_digest_invalid", "semanticObjects"));
|
|
60
|
+
if (!isRecord(object.componentDigests)) {
|
|
61
|
+
issues.push(issue("component_digests_invalid", "semanticObjects"));
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
for (const [name, digest] of Object.entries(object.componentDigests)) {
|
|
65
|
+
if (!isSafeName(name) || !isSha256(digest))
|
|
66
|
+
issues.push(issue("component_digest_invalid", "semanticObjects"));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const object of objects) {
|
|
70
|
+
if (isRecord(object) && typeof object.parentSemanticId === "string" && !ids.has(object.parentSemanticId)) {
|
|
71
|
+
issues.push(issue("semantic_parent_missing", "semanticObjects"));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const parentById = new Map();
|
|
75
|
+
for (const object of objects) {
|
|
76
|
+
if (!isRecord(object) || !isSemanticId(object.semanticId) || !isSemanticId(object.parentSemanticId))
|
|
77
|
+
continue;
|
|
78
|
+
if (object.parentSemanticId === object.semanticId) {
|
|
79
|
+
issues.push(issue("semantic_parent_self_reference", "semanticObjects"));
|
|
80
|
+
}
|
|
81
|
+
else if (ids.has(object.parentSemanticId))
|
|
82
|
+
parentById.set(object.semanticId, object.parentSemanticId);
|
|
83
|
+
}
|
|
84
|
+
for (const start of parentById.keys()) {
|
|
85
|
+
const path = new Set();
|
|
86
|
+
let cursor = start;
|
|
87
|
+
while (cursor !== undefined && parentById.has(cursor)) {
|
|
88
|
+
if (path.has(cursor)) {
|
|
89
|
+
issues.push(issue("semantic_parent_cycle", "semanticObjects"));
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
path.add(cursor);
|
|
93
|
+
cursor = parentById.get(cursor);
|
|
94
|
+
}
|
|
95
|
+
if (issues.some((item) => item.code === "semantic_parent_cycle"))
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (issues.length > 0)
|
|
100
|
+
return failure(issues);
|
|
101
|
+
const snapshot = input;
|
|
102
|
+
const normalized = {
|
|
103
|
+
...snapshot,
|
|
104
|
+
adapter: { ...snapshot.adapter },
|
|
105
|
+
semanticObjects: snapshot.semanticObjects.map((object) => ({
|
|
106
|
+
...object,
|
|
107
|
+
componentDigests: Object.fromEntries(Object.entries(object.componentDigests).sort(([left], [right]) => left.localeCompare(right))),
|
|
108
|
+
})).sort((left, right) => left.semanticId.localeCompare(right.semanticId)),
|
|
109
|
+
};
|
|
110
|
+
const snapshotDigest = digestJsonOperacional(normalized);
|
|
111
|
+
return success({ snapshot: normalized, snapshotDigest, localValidationOnly: true }, snapshotDigest);
|
|
112
|
+
}
|
|
113
|
+
export function derivarDiffSnapshotsEngine(beforeInput, afterInput) {
|
|
114
|
+
const beforeResult = validarSnapshotEngine(beforeInput);
|
|
115
|
+
const afterResult = validarSnapshotEngine(afterInput);
|
|
116
|
+
const issues = [];
|
|
117
|
+
if (!beforeResult.valid)
|
|
118
|
+
issues.push(issue("before_snapshot_invalid", "snapshotBefore"), ...beforeResult.issues);
|
|
119
|
+
if (!afterResult.valid)
|
|
120
|
+
issues.push(issue("after_snapshot_invalid", "snapshotAfter"), ...afterResult.issues);
|
|
121
|
+
if (!beforeResult.value || !afterResult.value)
|
|
122
|
+
return failure(issues);
|
|
123
|
+
const before = beforeResult.value.snapshot;
|
|
124
|
+
const after = afterResult.value.snapshot;
|
|
125
|
+
if (before.projectId !== after.projectId)
|
|
126
|
+
issues.push(issue("snapshot_project_binding_mismatch", "projectId"));
|
|
127
|
+
if (before.sceneId !== after.sceneId)
|
|
128
|
+
issues.push(issue("snapshot_scene_binding_mismatch", "sceneId"));
|
|
129
|
+
if (before.adapter.adapterId !== after.adapter.adapterId
|
|
130
|
+
|| before.adapter.adapterVersion !== after.adapter.adapterVersion) {
|
|
131
|
+
issues.push(issue("snapshot_adapter_binding_mismatch", "adapter"));
|
|
132
|
+
}
|
|
133
|
+
if (issues.length > 0)
|
|
134
|
+
return failure(issues);
|
|
135
|
+
const beforeById = new Map(before.semanticObjects.map((item) => [item.semanticId, item]));
|
|
136
|
+
const afterById = new Map(after.semanticObjects.map((item) => [item.semanticId, item]));
|
|
137
|
+
const allIds = [...new Set([...beforeById.keys(), ...afterById.keys()])].sort();
|
|
138
|
+
const changes = [];
|
|
139
|
+
for (const semanticId of allIds) {
|
|
140
|
+
const previous = beforeById.get(semanticId);
|
|
141
|
+
const current = afterById.get(semanticId);
|
|
142
|
+
if (!previous && current) {
|
|
143
|
+
changes.push({ semanticId, change: "ADDED", afterDigest: digestJsonOperacional(current) });
|
|
144
|
+
}
|
|
145
|
+
else if (previous && !current) {
|
|
146
|
+
changes.push({ semanticId, change: "REMOVED", beforeDigest: digestJsonOperacional(previous) });
|
|
147
|
+
}
|
|
148
|
+
else if (previous && current) {
|
|
149
|
+
const beforeDigest = digestJsonOperacional(previous);
|
|
150
|
+
const afterDigest = digestJsonOperacional(current);
|
|
151
|
+
if (beforeDigest !== afterDigest)
|
|
152
|
+
changes.push({ semanticId, change: "MODIFIED", beforeDigest, afterDigest });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const withoutDigest = {
|
|
156
|
+
schemaVersion: ENGINE_DIFF_SCHEMA_V1,
|
|
157
|
+
beforeSnapshotDigest: beforeResult.value.snapshotDigest,
|
|
158
|
+
afterSnapshotDigest: afterResult.value.snapshotDigest,
|
|
159
|
+
bindingDigest: digestJsonOperacional({ projectId: before.projectId, sceneId: before.sceneId, adapter: before.adapter }),
|
|
160
|
+
artifactDigestChanged: before.artifactDigest !== after.artifactDigest,
|
|
161
|
+
changes,
|
|
162
|
+
readOnly: true,
|
|
163
|
+
authoritative: false,
|
|
164
|
+
};
|
|
165
|
+
const diff = { ...withoutDigest, diffDigest: digestJsonOperacional(withoutDigest) };
|
|
166
|
+
return success(diff, diff.diffDigest);
|
|
167
|
+
}
|
|
168
|
+
export function validarProvenienciaAsset(input) {
|
|
169
|
+
const issues = inspectPlainJson(input, "provenance");
|
|
170
|
+
if (!isRecord(input))
|
|
171
|
+
return failure([...issues, issue("provenance_object_required", "provenance")]);
|
|
172
|
+
if (!hasOnlyKeys(input, [
|
|
173
|
+
"schemaVersion", "assetId", "sourceUriRef", "sourceUriRedacted", "license",
|
|
174
|
+
"sourceHash", "contentHash", "transforms", "derivatives", "authoritative",
|
|
175
|
+
]))
|
|
176
|
+
issues.push(issue("provenance_unknown_field", "provenance"));
|
|
177
|
+
if (input.schemaVersion !== ASSET_PROVENANCE_SCHEMA_V1)
|
|
178
|
+
issues.push(issue("provenance_schema_invalid", "schemaVersion"));
|
|
179
|
+
if (!isSemanticId(input.assetId))
|
|
180
|
+
issues.push(issue("asset_id_invalid", "assetId"));
|
|
181
|
+
if (!isOpaqueSha256(input.sourceUriRef))
|
|
182
|
+
issues.push(issue("source_uri_ref_must_be_opaque", "sourceUriRef"));
|
|
183
|
+
if (input.sourceUriRedacted !== true)
|
|
184
|
+
issues.push(issue("source_uri_must_be_redacted", "sourceUriRedacted"));
|
|
185
|
+
if (!isSha256(input.sourceHash))
|
|
186
|
+
issues.push(issue("source_hash_invalid", "sourceHash"));
|
|
187
|
+
if (!isSha256(input.contentHash))
|
|
188
|
+
issues.push(issue("content_hash_invalid", "contentHash"));
|
|
189
|
+
if (input.authoritative !== false)
|
|
190
|
+
issues.push(issue("provenance_must_be_non_authoritative", "authoritative"));
|
|
191
|
+
const license = input.license;
|
|
192
|
+
if (!isRecord(license)
|
|
193
|
+
|| !hasOnlyKeys(license, ["licenseId", "evidenceDigest", "redistributable"])
|
|
194
|
+
|| !isSafeName(license.licenseId)
|
|
195
|
+
|| !isSha256(license.evidenceDigest)
|
|
196
|
+
|| typeof license.redistributable !== "boolean")
|
|
197
|
+
issues.push(issue("asset_license_invalid", "license"));
|
|
198
|
+
const transforms = input.transforms;
|
|
199
|
+
const transformIds = new Set();
|
|
200
|
+
let previousDigest = input.sourceHash;
|
|
201
|
+
if (!Array.isArray(transforms)) {
|
|
202
|
+
issues.push(issue("asset_transforms_invalid", "transforms"));
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
for (const transform of transforms) {
|
|
206
|
+
if (!isRecord(transform) || !hasOnlyKeys(transform, [
|
|
207
|
+
"transformId", "toolRef", "toolVersion", "inputDigest", "outputDigest", "parametersDigest",
|
|
208
|
+
])) {
|
|
209
|
+
issues.push(issue("asset_transform_invalid", "transforms"));
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (!isSemanticId(transform.transformId))
|
|
213
|
+
issues.push(issue("transform_id_invalid", "transforms"));
|
|
214
|
+
else if (transformIds.has(transform.transformId))
|
|
215
|
+
issues.push(issue("transform_id_duplicate", "transforms"));
|
|
216
|
+
else
|
|
217
|
+
transformIds.add(transform.transformId);
|
|
218
|
+
if (!isSafeName(transform.toolRef) || !isVersion(transform.toolVersion))
|
|
219
|
+
issues.push(issue("transform_tool_invalid", "transforms"));
|
|
220
|
+
if (!isSha256(transform.inputDigest) || !isSha256(transform.outputDigest) || !isSha256(transform.parametersDigest)) {
|
|
221
|
+
issues.push(issue("transform_digest_invalid", "transforms"));
|
|
222
|
+
}
|
|
223
|
+
if (transform.inputDigest !== previousDigest)
|
|
224
|
+
issues.push(issue("transform_chain_broken", "transforms"));
|
|
225
|
+
previousDigest = transform.outputDigest;
|
|
226
|
+
}
|
|
227
|
+
if (previousDigest !== input.contentHash)
|
|
228
|
+
issues.push(issue("transform_final_hash_mismatch", "contentHash"));
|
|
229
|
+
}
|
|
230
|
+
const derivatives = input.derivatives;
|
|
231
|
+
const derivativeIds = new Set();
|
|
232
|
+
const derivativeHashes = new Set();
|
|
233
|
+
const parentByHash = new Map();
|
|
234
|
+
if (!Array.isArray(derivatives)) {
|
|
235
|
+
issues.push(issue("asset_derivatives_invalid", "derivatives"));
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
for (const derivative of derivatives) {
|
|
239
|
+
if (!isRecord(derivative) || !hasOnlyKeys(derivative, [
|
|
240
|
+
"assetId", "parentContentHash", "contentHash", "transformDigest",
|
|
241
|
+
])) {
|
|
242
|
+
issues.push(issue("asset_derivative_invalid", "derivatives"));
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (!isSemanticId(derivative.assetId))
|
|
246
|
+
issues.push(issue("derivative_asset_id_invalid", "derivatives"));
|
|
247
|
+
else if (derivativeIds.has(derivative.assetId))
|
|
248
|
+
issues.push(issue("derivative_asset_id_duplicate", "derivatives"));
|
|
249
|
+
else
|
|
250
|
+
derivativeIds.add(derivative.assetId);
|
|
251
|
+
if (!isSha256(derivative.parentContentHash)
|
|
252
|
+
|| !isSha256(derivative.contentHash)
|
|
253
|
+
|| !isSha256(derivative.transformDigest)) {
|
|
254
|
+
issues.push(issue("derivative_digest_invalid", "derivatives"));
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (derivativeHashes.has(derivative.contentHash) || derivative.contentHash === input.contentHash) {
|
|
258
|
+
issues.push(issue("derivative_content_hash_duplicate", "derivatives"));
|
|
259
|
+
}
|
|
260
|
+
derivativeHashes.add(derivative.contentHash);
|
|
261
|
+
parentByHash.set(derivative.contentHash, derivative.parentContentHash);
|
|
262
|
+
}
|
|
263
|
+
const knownHashes = new Set([input.contentHash, ...derivativeHashes]);
|
|
264
|
+
for (const [contentHash, parentHash] of parentByHash) {
|
|
265
|
+
if (!knownHashes.has(parentHash))
|
|
266
|
+
issues.push(issue("derivative_parent_missing", "derivatives"));
|
|
267
|
+
const visited = new Set();
|
|
268
|
+
let cursor = contentHash;
|
|
269
|
+
while (cursor !== undefined && cursor !== input.contentHash) {
|
|
270
|
+
if (visited.has(cursor)) {
|
|
271
|
+
issues.push(issue("derivative_cycle_detected", "derivatives"));
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
visited.add(cursor);
|
|
275
|
+
cursor = parentByHash.get(cursor);
|
|
276
|
+
if (cursor === undefined)
|
|
277
|
+
issues.push(issue("derivative_lineage_incomplete", "derivatives"));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (issues.length > 0)
|
|
282
|
+
return failure(issues);
|
|
283
|
+
const provenance = input;
|
|
284
|
+
const normalized = {
|
|
285
|
+
...provenance,
|
|
286
|
+
license: { ...provenance.license },
|
|
287
|
+
transforms: provenance.transforms.map((item) => ({ ...item })),
|
|
288
|
+
derivatives: provenance.derivatives.map((item) => ({ ...item }))
|
|
289
|
+
.sort((left, right) => left.assetId.localeCompare(right.assetId)),
|
|
290
|
+
};
|
|
291
|
+
const provenanceDigest = digestJsonOperacional(normalized);
|
|
292
|
+
return success({ provenance: normalized, provenanceDigest }, provenanceDigest);
|
|
293
|
+
}
|
|
294
|
+
const BACKGROUND_JOB_STATES = new Set(["QUEUED", "RUNNING", "SUCCEEDED", "FAILED", "CANCELLED"]);
|
|
295
|
+
const EDITOR_MODES = new Set(["EDIT", "PLAY", "PAUSED"]);
|
|
296
|
+
const PROCESS_ROLES = new Set(["ENGINE", "EDITOR", "SHADER_COMPILER", "IMPORT_WORKER", "BUILD_WORKER"]);
|
|
297
|
+
const PROCESS_STATES = new Set(["IDLE", "RUNNING", "BLOCKED", "FAILED", "EXITED"]);
|
|
298
|
+
function validateBackgroundJobs(value, field, issues) {
|
|
299
|
+
const ids = new Set();
|
|
300
|
+
if (!Array.isArray(value)) {
|
|
301
|
+
issues.push(issue("editor_jobs_invalid", field));
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
for (const job of value) {
|
|
305
|
+
if (!isRecord(job)
|
|
306
|
+
|| !hasOnlyKeys(job, ["jobId", "status", "progressBasisPoints"])
|
|
307
|
+
|| !isSemanticId(job.jobId)
|
|
308
|
+
|| typeof job.status !== "string"
|
|
309
|
+
|| !BACKGROUND_JOB_STATES.has(job.status)
|
|
310
|
+
|| !isIntegerIn(job.progressBasisPoints, 0, 10_000)) {
|
|
311
|
+
issues.push(issue("editor_job_invalid", field));
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (ids.has(job.jobId))
|
|
315
|
+
issues.push(issue("editor_job_id_duplicate", field));
|
|
316
|
+
ids.add(job.jobId);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export function validarEstadoEditor(input) {
|
|
320
|
+
const issues = inspectPlainJson(input, "editorState");
|
|
321
|
+
if (!isRecord(input))
|
|
322
|
+
return failure([...issues, issue("editor_state_object_required", "editorState")]);
|
|
323
|
+
if (!hasOnlyKeys(input, [
|
|
324
|
+
"schemaVersion", "editorSessionId", "adapter", "scene", "selection", "mode",
|
|
325
|
+
"unsavedChanges", "shaderJobs", "importJobs", "plugins", "modals", "processes",
|
|
326
|
+
"observedAt", "readOnly", "authoritative",
|
|
327
|
+
]))
|
|
328
|
+
issues.push(issue("editor_state_unknown_field", "editorState"));
|
|
329
|
+
if (input.schemaVersion !== EDITOR_STATE_SCHEMA_V1)
|
|
330
|
+
issues.push(issue("editor_state_schema_invalid", "schemaVersion"));
|
|
331
|
+
if (!isSemanticId(input.editorSessionId))
|
|
332
|
+
issues.push(issue("editor_session_id_invalid", "editorSessionId"));
|
|
333
|
+
if (typeof input.mode !== "string" || !EDITOR_MODES.has(input.mode))
|
|
334
|
+
issues.push(issue("editor_mode_invalid", "mode"));
|
|
335
|
+
if (typeof input.unsavedChanges !== "boolean")
|
|
336
|
+
issues.push(issue("unsaved_changes_invalid", "unsavedChanges"));
|
|
337
|
+
if (!isIsoTimestamp(input.observedAt))
|
|
338
|
+
issues.push(issue("editor_observed_at_invalid", "observedAt"));
|
|
339
|
+
if (input.readOnly !== true)
|
|
340
|
+
issues.push(issue("editor_state_must_be_read_only", "readOnly"));
|
|
341
|
+
if (input.authoritative !== false)
|
|
342
|
+
issues.push(issue("editor_state_must_be_non_authoritative", "authoritative"));
|
|
343
|
+
if (!isRecord(input.adapter)
|
|
344
|
+
|| !hasOnlyKeys(input.adapter, ["adapterId", "adapterVersion"])
|
|
345
|
+
|| !isSafeName(input.adapter.adapterId)
|
|
346
|
+
|| !isVersion(input.adapter.adapterVersion))
|
|
347
|
+
issues.push(issue("editor_adapter_invalid", "adapter"));
|
|
348
|
+
if (!isRecord(input.scene)
|
|
349
|
+
|| !hasOnlyKeys(input.scene, ["semanticId", "artifactDigest"])
|
|
350
|
+
|| !isSemanticId(input.scene.semanticId)
|
|
351
|
+
|| !isSha256(input.scene.artifactDigest))
|
|
352
|
+
issues.push(issue("editor_scene_invalid", "scene"));
|
|
353
|
+
const selectionIds = new Set();
|
|
354
|
+
if (!Array.isArray(input.selection))
|
|
355
|
+
issues.push(issue("editor_selection_invalid", "selection"));
|
|
356
|
+
else
|
|
357
|
+
for (const selected of input.selection) {
|
|
358
|
+
if (!isSemanticId(selected))
|
|
359
|
+
issues.push(issue("editor_selection_id_invalid", "selection"));
|
|
360
|
+
else if (selectionIds.has(selected))
|
|
361
|
+
issues.push(issue("editor_selection_duplicate", "selection"));
|
|
362
|
+
else
|
|
363
|
+
selectionIds.add(selected);
|
|
364
|
+
}
|
|
365
|
+
validateBackgroundJobs(input.shaderJobs, "shaderJobs", issues);
|
|
366
|
+
validateBackgroundJobs(input.importJobs, "importJobs", issues);
|
|
367
|
+
const pluginIds = new Set();
|
|
368
|
+
if (!Array.isArray(input.plugins))
|
|
369
|
+
issues.push(issue("editor_plugins_invalid", "plugins"));
|
|
370
|
+
else
|
|
371
|
+
for (const plugin of input.plugins) {
|
|
372
|
+
if (!isRecord(plugin)
|
|
373
|
+
|| !hasOnlyKeys(plugin, ["pluginId", "version", "enabled", "provenanceDigest"])
|
|
374
|
+
|| !isSafeName(plugin.pluginId)
|
|
375
|
+
|| !isVersion(plugin.version)
|
|
376
|
+
|| typeof plugin.enabled !== "boolean"
|
|
377
|
+
|| !isSha256(plugin.provenanceDigest)) {
|
|
378
|
+
issues.push(issue("editor_plugin_invalid", "plugins"));
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (pluginIds.has(plugin.pluginId))
|
|
382
|
+
issues.push(issue("editor_plugin_id_duplicate", "plugins"));
|
|
383
|
+
pluginIds.add(plugin.pluginId);
|
|
384
|
+
}
|
|
385
|
+
const modalIds = new Set();
|
|
386
|
+
if (!Array.isArray(input.modals))
|
|
387
|
+
issues.push(issue("editor_modals_invalid", "modals"));
|
|
388
|
+
else
|
|
389
|
+
for (const modal of input.modals) {
|
|
390
|
+
if (!isRecord(modal)
|
|
391
|
+
|| !hasOnlyKeys(modal, ["modalId", "kind", "blocking"])
|
|
392
|
+
|| !isSemanticId(modal.modalId)
|
|
393
|
+
|| !isSafeName(modal.kind)
|
|
394
|
+
|| typeof modal.blocking !== "boolean") {
|
|
395
|
+
issues.push(issue("editor_modal_invalid", "modals"));
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (modalIds.has(modal.modalId))
|
|
399
|
+
issues.push(issue("editor_modal_id_duplicate", "modals"));
|
|
400
|
+
modalIds.add(modal.modalId);
|
|
401
|
+
}
|
|
402
|
+
const processRefs = new Set();
|
|
403
|
+
if (!Array.isArray(input.processes))
|
|
404
|
+
issues.push(issue("editor_processes_invalid", "processes"));
|
|
405
|
+
else
|
|
406
|
+
for (const process of input.processes) {
|
|
407
|
+
if (!isRecord(process)
|
|
408
|
+
|| !hasOnlyKeys(process, ["processRef", "role", "state"])
|
|
409
|
+
|| !isOpaqueSha256(process.processRef)
|
|
410
|
+
|| typeof process.role !== "string"
|
|
411
|
+
|| !PROCESS_ROLES.has(process.role)
|
|
412
|
+
|| typeof process.state !== "string"
|
|
413
|
+
|| !PROCESS_STATES.has(process.state)) {
|
|
414
|
+
issues.push(issue("editor_process_invalid", "processes"));
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (processRefs.has(process.processRef))
|
|
418
|
+
issues.push(issue("editor_process_ref_duplicate", "processes"));
|
|
419
|
+
processRefs.add(process.processRef);
|
|
420
|
+
}
|
|
421
|
+
if (issues.length > 0)
|
|
422
|
+
return failure(issues);
|
|
423
|
+
const state = input;
|
|
424
|
+
const normalized = {
|
|
425
|
+
...state,
|
|
426
|
+
adapter: { ...state.adapter },
|
|
427
|
+
scene: { ...state.scene },
|
|
428
|
+
selection: [...state.selection].sort(),
|
|
429
|
+
shaderJobs: state.shaderJobs.map((item) => ({ ...item })).sort((a, b) => a.jobId.localeCompare(b.jobId)),
|
|
430
|
+
importJobs: state.importJobs.map((item) => ({ ...item })).sort((a, b) => a.jobId.localeCompare(b.jobId)),
|
|
431
|
+
plugins: state.plugins.map((item) => ({ ...item })).sort((a, b) => a.pluginId.localeCompare(b.pluginId)),
|
|
432
|
+
modals: state.modals.map((item) => ({ ...item })).sort((a, b) => a.modalId.localeCompare(b.modalId)),
|
|
433
|
+
processes: state.processes.map((item) => ({ ...item })).sort((a, b) => a.processRef.localeCompare(b.processRef)),
|
|
434
|
+
};
|
|
435
|
+
const editorStateDigest = digestJsonOperacional(normalized);
|
|
436
|
+
return success({ state: normalized, editorStateDigest, externallyObserved: false }, editorStateDigest);
|
|
437
|
+
}
|
|
438
|
+
//# sourceMappingURL=engineObservation.js.map
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.sistemas_interativos.operacao.orquestracao_jobs
|
|
2
|
+
// Descricao: planejamento deterministico de filas, locks, budgets, heartbeat, checkpoint e retomada.
|
|
3
|
+
import { JOB_ORCHESTRATION_SCHEMA_V1, } from "./operationsTypes.js";
|
|
4
|
+
import { digestJsonOperacional, failure, hasOnlyKeys, inspectPlainJson, isIntegerIn, isOpaqueSha256, isRecord, isSafeName, isSemanticId, isSha256, isVersion, issue, success, } from "./operationPrimitives.js";
|
|
5
|
+
const RESOURCE_LOCKS = ["GPU", "EDITOR", "CACHE"];
|
|
6
|
+
function validateBudget(value, field, issues) {
|
|
7
|
+
if (!isRecord(value)
|
|
8
|
+
|| !hasOnlyKeys(value, ["ramMb", "vramMb", "diskMb"])
|
|
9
|
+
|| !isIntegerIn(value.ramMb, 1, 16_777_216)
|
|
10
|
+
|| !isIntegerIn(value.vramMb, 0, 16_777_216)
|
|
11
|
+
|| !isIntegerIn(value.diskMb, 1, 1_073_741_824)) {
|
|
12
|
+
issues.push(issue("resource_budget_invalid", field));
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
export function planejarOrquestracaoJobs(input) {
|
|
18
|
+
const issues = inspectPlainJson(input, "jobRequest");
|
|
19
|
+
if (!isRecord(input))
|
|
20
|
+
return failure([...issues, issue("job_request_object_required", "jobRequest")]);
|
|
21
|
+
if (!hasOnlyKeys(input, ["schemaVersion", "queueId", "capacity", "lockCapacity", "jobs"])) {
|
|
22
|
+
issues.push(issue("job_request_unknown_field", "jobRequest"));
|
|
23
|
+
}
|
|
24
|
+
if (input.schemaVersion !== JOB_ORCHESTRATION_SCHEMA_V1)
|
|
25
|
+
issues.push(issue("job_schema_invalid", "schemaVersion"));
|
|
26
|
+
if (!isSemanticId(input.queueId))
|
|
27
|
+
issues.push(issue("queue_id_invalid", "queueId"));
|
|
28
|
+
const capacity = input.capacity;
|
|
29
|
+
const capacityValid = validateBudget(capacity, "capacity", issues);
|
|
30
|
+
const lockCapacity = input.lockCapacity;
|
|
31
|
+
if (!isRecord(lockCapacity)
|
|
32
|
+
|| !hasOnlyKeys(lockCapacity, RESOURCE_LOCKS)
|
|
33
|
+
|| !RESOURCE_LOCKS.every((lock) => isIntegerIn(lockCapacity[lock], 0, 1))) {
|
|
34
|
+
issues.push(issue("lock_capacity_invalid", "lockCapacity"));
|
|
35
|
+
}
|
|
36
|
+
const jobs = input.jobs;
|
|
37
|
+
const ids = new Set();
|
|
38
|
+
if (!Array.isArray(jobs) || jobs.length === 0) {
|
|
39
|
+
issues.push(issue("jobs_required", "jobs"));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const job of jobs) {
|
|
43
|
+
if (!isRecord(job) || !hasOnlyKeys(job, [
|
|
44
|
+
"jobId", "kind", "priority", "dependencies", "locks", "budget",
|
|
45
|
+
"heartbeat", "checkpoint", "adapter",
|
|
46
|
+
])) {
|
|
47
|
+
issues.push(issue("job_invalid", "jobs"));
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (!isSemanticId(job.jobId))
|
|
51
|
+
issues.push(issue("job_id_invalid", "jobs"));
|
|
52
|
+
else if (ids.has(job.jobId))
|
|
53
|
+
issues.push(issue("job_id_duplicate", "jobs"));
|
|
54
|
+
else
|
|
55
|
+
ids.add(job.jobId);
|
|
56
|
+
if (!isSafeName(job.kind))
|
|
57
|
+
issues.push(issue("job_kind_invalid", "jobs"));
|
|
58
|
+
if (!isIntegerIn(job.priority, 0, 100))
|
|
59
|
+
issues.push(issue("job_priority_invalid", "jobs"));
|
|
60
|
+
if (!Array.isArray(job.dependencies)
|
|
61
|
+
|| job.dependencies.some((dependency) => !isSemanticId(dependency))
|
|
62
|
+
|| new Set(job.dependencies).size !== job.dependencies.length
|
|
63
|
+
|| job.dependencies.includes(job.jobId))
|
|
64
|
+
issues.push(issue("job_dependencies_invalid", "jobs"));
|
|
65
|
+
if (!Array.isArray(job.locks)
|
|
66
|
+
|| job.locks.some((lock) => typeof lock !== "string" || !RESOURCE_LOCKS.includes(lock))
|
|
67
|
+
|| new Set(job.locks).size !== job.locks.length)
|
|
68
|
+
issues.push(issue("job_locks_invalid", "jobs"));
|
|
69
|
+
const budget = job.budget;
|
|
70
|
+
const budgetValid = validateBudget(budget, "jobs", issues);
|
|
71
|
+
if (budgetValid && capacityValid
|
|
72
|
+
&& (budget.ramMb > capacity.ramMb
|
|
73
|
+
|| budget.vramMb > capacity.vramMb
|
|
74
|
+
|| budget.diskMb > capacity.diskMb))
|
|
75
|
+
issues.push(issue("job_budget_exceeds_capacity", "jobs"));
|
|
76
|
+
if (Array.isArray(job.locks) && isRecord(lockCapacity)) {
|
|
77
|
+
for (const lock of job.locks) {
|
|
78
|
+
if (typeof lock === "string"
|
|
79
|
+
&& RESOURCE_LOCKS.includes(lock)
|
|
80
|
+
&& lockCapacity[lock] !== 1)
|
|
81
|
+
issues.push(issue("job_lock_unavailable", "jobs"));
|
|
82
|
+
}
|
|
83
|
+
if (job.locks.includes("GPU") && isRecord(job.budget) && job.budget.vramMb === 0) {
|
|
84
|
+
issues.push(issue("gpu_job_requires_vram", "jobs"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!isRecord(job.heartbeat)
|
|
88
|
+
|| !hasOnlyKeys(job.heartbeat, ["intervalMs", "timeoutMs"])
|
|
89
|
+
|| !isIntegerIn(job.heartbeat.intervalMs, 100, 86_400_000)
|
|
90
|
+
|| !isIntegerIn(job.heartbeat.timeoutMs, 100, 86_400_000)
|
|
91
|
+
|| (typeof job.heartbeat.intervalMs === "number"
|
|
92
|
+
&& typeof job.heartbeat.timeoutMs === "number"
|
|
93
|
+
&& job.heartbeat.timeoutMs < job.heartbeat.intervalMs * 2))
|
|
94
|
+
issues.push(issue("job_heartbeat_invalid", "jobs"));
|
|
95
|
+
if (!isRecord(job.checkpoint)
|
|
96
|
+
|| !hasOnlyKeys(job.checkpoint, ["intervalMs", "resume", "checkpointDigest", "recoveryToken"])
|
|
97
|
+
|| !isIntegerIn(job.checkpoint.intervalMs, 100, 86_400_000)
|
|
98
|
+
|| typeof job.checkpoint.resume !== "boolean"
|
|
99
|
+
|| !isOpaqueSha256(job.checkpoint.recoveryToken)
|
|
100
|
+
|| (job.checkpoint.checkpointDigest !== undefined && !isSha256(job.checkpoint.checkpointDigest))
|
|
101
|
+
|| (job.checkpoint.resume === true && !isSha256(job.checkpoint.checkpointDigest))) {
|
|
102
|
+
issues.push(issue("job_checkpoint_invalid", "jobs"));
|
|
103
|
+
}
|
|
104
|
+
if (!isRecord(job.adapter)
|
|
105
|
+
|| !hasOnlyKeys(job.adapter, ["adapterId", "adapterVersion"])
|
|
106
|
+
|| !isSafeName(job.adapter.adapterId)
|
|
107
|
+
|| !isVersion(job.adapter.adapterVersion))
|
|
108
|
+
issues.push(issue("job_adapter_invalid", "jobs"));
|
|
109
|
+
}
|
|
110
|
+
for (const job of jobs) {
|
|
111
|
+
if (!isRecord(job) || !Array.isArray(job.dependencies))
|
|
112
|
+
continue;
|
|
113
|
+
for (const dependency of job.dependencies) {
|
|
114
|
+
if (typeof dependency === "string" && !ids.has(dependency))
|
|
115
|
+
issues.push(issue("job_dependency_missing", "jobs"));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (issues.length > 0)
|
|
120
|
+
return failure(issues);
|
|
121
|
+
const request = input;
|
|
122
|
+
const byId = new Map(request.jobs.map((job) => [job.jobId, job]));
|
|
123
|
+
const indegree = new Map(request.jobs.map((job) => [job.jobId, job.dependencies.length]));
|
|
124
|
+
const dependents = new Map();
|
|
125
|
+
for (const job of request.jobs)
|
|
126
|
+
for (const dependency of job.dependencies) {
|
|
127
|
+
const list = dependents.get(dependency) ?? [];
|
|
128
|
+
list.push(job.jobId);
|
|
129
|
+
dependents.set(dependency, list);
|
|
130
|
+
}
|
|
131
|
+
const compareJobs = (leftId, rightId) => {
|
|
132
|
+
const left = byId.get(leftId);
|
|
133
|
+
const right = byId.get(rightId);
|
|
134
|
+
return right.priority - left.priority || left.jobId.localeCompare(right.jobId);
|
|
135
|
+
};
|
|
136
|
+
const ready = request.jobs.filter((job) => job.dependencies.length === 0)
|
|
137
|
+
.map((job) => job.jobId).sort(compareJobs);
|
|
138
|
+
const ordered = [];
|
|
139
|
+
while (ready.length > 0) {
|
|
140
|
+
const id = ready.shift();
|
|
141
|
+
ordered.push(byId.get(id));
|
|
142
|
+
for (const dependent of (dependents.get(id) ?? []).sort()) {
|
|
143
|
+
const next = (indegree.get(dependent) ?? 0) - 1;
|
|
144
|
+
indegree.set(dependent, next);
|
|
145
|
+
if (next === 0) {
|
|
146
|
+
ready.push(dependent);
|
|
147
|
+
ready.sort(compareJobs);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (ordered.length !== request.jobs.length)
|
|
152
|
+
return failure([issue("job_dependency_cycle", "jobs")]);
|
|
153
|
+
const normalizedRequest = {
|
|
154
|
+
schemaVersion: request.schemaVersion,
|
|
155
|
+
queueId: request.queueId,
|
|
156
|
+
capacity: { ...request.capacity },
|
|
157
|
+
lockCapacity: Object.fromEntries(RESOURCE_LOCKS.map((lock) => [lock, request.lockCapacity[lock]])),
|
|
158
|
+
jobs: request.jobs.map((job) => ({
|
|
159
|
+
jobId: job.jobId,
|
|
160
|
+
kind: job.kind,
|
|
161
|
+
priority: job.priority,
|
|
162
|
+
dependencies: [...job.dependencies].sort(),
|
|
163
|
+
locks: [...job.locks].sort((a, b) => RESOURCE_LOCKS.indexOf(a) - RESOURCE_LOCKS.indexOf(b)),
|
|
164
|
+
budget: { ...job.budget },
|
|
165
|
+
heartbeat: { ...job.heartbeat },
|
|
166
|
+
checkpoint: {
|
|
167
|
+
intervalMs: job.checkpoint.intervalMs,
|
|
168
|
+
resume: job.checkpoint.resume,
|
|
169
|
+
...(job.checkpoint.checkpointDigest === undefined ? {} : { checkpointDigest: job.checkpoint.checkpointDigest }),
|
|
170
|
+
recoveryToken: job.checkpoint.recoveryToken,
|
|
171
|
+
},
|
|
172
|
+
adapter: { ...job.adapter },
|
|
173
|
+
})).sort((left, right) => left.jobId.localeCompare(right.jobId)),
|
|
174
|
+
};
|
|
175
|
+
const requestDigest = digestJsonOperacional(normalizedRequest);
|
|
176
|
+
const queue = ordered.map((job, index) => ({
|
|
177
|
+
position: index + 1,
|
|
178
|
+
jobId: job.jobId,
|
|
179
|
+
kind: job.kind,
|
|
180
|
+
priority: job.priority,
|
|
181
|
+
adapter: { ...job.adapter },
|
|
182
|
+
dependencies: [...job.dependencies].sort(),
|
|
183
|
+
locks: [...job.locks].sort((a, b) => RESOURCE_LOCKS.indexOf(a) - RESOURCE_LOCKS.indexOf(b)),
|
|
184
|
+
budget: { ...job.budget },
|
|
185
|
+
heartbeatIntervalMs: job.heartbeat.intervalMs,
|
|
186
|
+
heartbeatTimeoutMs: job.heartbeat.timeoutMs,
|
|
187
|
+
checkpointIntervalMs: job.checkpoint.intervalMs,
|
|
188
|
+
resume: job.checkpoint.resume,
|
|
189
|
+
...(job.checkpoint.checkpointDigest === undefined ? {} : { checkpointDigest: job.checkpoint.checkpointDigest }),
|
|
190
|
+
recoveryToken: job.checkpoint.recoveryToken,
|
|
191
|
+
}));
|
|
192
|
+
const withoutDigest = {
|
|
193
|
+
schemaVersion: JOB_ORCHESTRATION_SCHEMA_V1,
|
|
194
|
+
queueId: request.queueId,
|
|
195
|
+
queue,
|
|
196
|
+
requestDigest,
|
|
197
|
+
externalRunnerRequired: true,
|
|
198
|
+
resourcesReserved: false,
|
|
199
|
+
authoritative: false,
|
|
200
|
+
};
|
|
201
|
+
const plan = { ...withoutDigest, planDigest: digestJsonOperacional(withoutDigest) };
|
|
202
|
+
return success(plan, plan.planDigest);
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=jobOrchestration.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type OpaqueSha256, type OperationIssue, type OperationResult, type Sha256 } from "./operationsTypes.js";
|
|
2
|
+
export declare const MEDIA_TYPE_PATTERN: RegExp;
|
|
3
|
+
export declare function issue(code: string, field: string): OperationIssue;
|
|
4
|
+
export declare function failure<T>(issues: readonly OperationIssue[]): OperationResult<T>;
|
|
5
|
+
export declare function success<T>(value: T, digest?: Sha256): OperationResult<T>;
|
|
6
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
+
export declare function isSha256(value: unknown): value is Sha256;
|
|
8
|
+
export declare function isOpaqueSha256(value: unknown): value is OpaqueSha256;
|
|
9
|
+
export declare function isSemanticId(value: unknown): value is string;
|
|
10
|
+
export declare function isSafeName(value: unknown): value is string;
|
|
11
|
+
export declare function isVersion(value: unknown): value is string;
|
|
12
|
+
export declare function isIsoTimestamp(value: unknown): value is string;
|
|
13
|
+
export declare function isIntegerIn(value: unknown, minimum: number, maximum: number): value is number;
|
|
14
|
+
export declare function hasOnlyKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean;
|
|
15
|
+
export declare function inspectPlainJson(input: unknown, rootField: string): OperationIssue[];
|
|
16
|
+
export declare function canonicalJson(value: unknown): string;
|
|
17
|
+
export declare function digestJsonOperacional(value: unknown): Sha256;
|
|
18
|
+
export declare function criarReferenciaFonteOpaca(sourceUri: unknown): OperationResult<{
|
|
19
|
+
readonly sourceUriRef: OpaqueSha256;
|
|
20
|
+
readonly sourceUriRedacted: true;
|
|
21
|
+
}>;
|