@wowok/agent-mcp 2.7.0 → 2.7.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/dist/config/index.js +1 -1
- package/dist/config/runtime.js +1 -238
- package/dist/customer/customer-advice.js +1 -130
- package/dist/customer/index.js +1 -11
- package/dist/customer/industry-risks.js +1 -438
- package/dist/customer/info-puzzle.js +1 -681
- package/dist/customer/order-monitor.js +1 -328
- package/dist/customer/order-strategy.js +1 -373
- package/dist/customer/post-purchase.js +1 -351
- package/dist/customer/preorder-compare.js +1 -34
- package/dist/customer/reminder-system.js +1 -316
- package/dist/customer/risk-assessment.d.ts +5 -1
- package/dist/customer/risk-assessment.js +1 -397
- package/dist/customer/types.js +1 -13
- package/dist/customer/user-preferences.js +1 -460
- package/dist/evaluation/arbitration-game.d.ts +23 -0
- package/dist/evaluation/arbitration-game.js +1 -0
- package/dist/evaluation/builtins/demand-match.d.ts +15 -0
- package/dist/evaluation/builtins/demand-match.js +1 -0
- package/dist/evaluation/builtins/index.d.ts +3 -0
- package/dist/evaluation/builtins/index.js +1 -0
- package/dist/evaluation/builtins/service-risk.d.ts +6 -0
- package/dist/evaluation/builtins/service-risk.js +1 -0
- package/dist/evaluation/capability.d.ts +50 -0
- package/dist/evaluation/capability.js +1 -0
- package/dist/evaluation/composer.d.ts +13 -0
- package/dist/evaluation/composer.js +1 -0
- package/dist/evaluation/engine.d.ts +18 -0
- package/dist/evaluation/engine.js +1 -0
- package/dist/evaluation/extract.d.ts +30 -0
- package/dist/evaluation/extract.js +1 -0
- package/dist/evaluation/game-strategy.d.ts +27 -0
- package/dist/evaluation/game-strategy.js +1 -0
- package/dist/evaluation/gap.d.ts +2 -0
- package/dist/evaluation/gap.js +1 -0
- package/dist/evaluation/index.d.ts +12 -0
- package/dist/evaluation/index.js +1 -0
- package/dist/evaluation/node-game.d.ts +62 -0
- package/dist/evaluation/node-game.js +1 -0
- package/dist/evaluation/region.d.ts +10 -0
- package/dist/evaluation/region.js +1 -0
- package/dist/evaluation/types.d.ts +77 -0
- package/dist/evaluation/types.js +1 -0
- package/dist/evaluation/user-injection.d.ts +6 -0
- package/dist/evaluation/user-injection.js +1 -0
- package/dist/examples/education-contact-create.json +40 -0
- package/dist/examples/freelance-contact-create.json +40 -0
- package/dist/examples/insurance-machine-create.json +1 -1
- package/dist/examples/insurance-service-allocators.json +1 -1
- package/dist/examples/machine-publish.json +1 -1
- package/dist/examples/rental-ziroom-service-create.json +1 -1
- package/dist/examples/retail-adv-guard-messenger-proof-create.json +1 -1
- package/dist/examples/retail-myshop-service-create.json +1 -1
- package/dist/examples/retail-myshop-service-customer-required.json +1 -1
- package/dist/examples/subscription-contact-create.json +40 -0
- package/dist/examples/threebody-machine-create.json +1 -1
- package/dist/examples/travel-machine-create.json +1 -1
- package/dist/examples/travel-service-create.json +1 -1
- package/dist/experience/experience-reuse.js +1 -103
- package/dist/experience/index.js +1 -5
- package/dist/experience/intent-distill.js +1 -83
- package/dist/experience/realtime-feedback.js +1 -94
- package/dist/experience/types.js +1 -1
- package/dist/experience/user-profile.js +1 -171
- package/dist/extensions/business-modules.js +1 -287
- package/dist/extensions/capability-manifest.js +1 -781
- package/dist/extensions/constraint-registry.js +1 -198
- package/dist/extensions/index.js +1 -6
- package/dist/extensions/metric-registry.js +1 -257
- package/dist/extensions/mode-evaluator.js +1 -170
- package/dist/extensions/modes.js +1 -499
- package/dist/extensions/registry.js +1 -717
- package/dist/extensions/types.js +1 -1
- package/dist/harness/auto-escalation.js +1 -68
- package/dist/harness/checkpoint.js +1 -129
- package/dist/harness/index.js +1 -78
- package/dist/harness/plan.js +1 -276
- package/dist/harness/recover.js +1 -139
- package/dist/harness/types.js +1 -1
- package/dist/harness/verify.js +1 -237
- package/dist/index.js +1 -273
- package/dist/intent/enrich.d.ts +1 -0
- package/dist/intent/enrich.js +1 -0
- package/dist/intent/index.d.ts +23 -0
- package/dist/intent/index.js +1 -0
- package/dist/intent/matcher.d.ts +2 -0
- package/dist/intent/matcher.js +1 -0
- package/dist/intent/store.d.ts +19 -0
- package/dist/intent/store.js +1 -0
- package/dist/intent/types.d.ts +33 -0
- package/dist/intent/types.js +1 -0
- package/dist/knowledge/acquisition-flywheel.js +1 -192
- package/dist/knowledge/allocation-confirm.js +1 -534
- package/dist/knowledge/allocation-context.js +1 -249
- package/dist/knowledge/allocation-ledger.js +1 -463
- package/dist/knowledge/allocation-puzzle.js +1 -298
- package/dist/knowledge/allocation-risk.js +1 -568
- package/dist/knowledge/allocation-templates.js +1 -970
- package/dist/knowledge/allocation-translation.js +1 -585
- package/dist/knowledge/arb-risk.js +1 -210
- package/dist/knowledge/arbitration-confirm.js +1 -559
- package/dist/knowledge/arbitration-context.js +1 -505
- package/dist/knowledge/arbitration-ledger.js +1 -521
- package/dist/knowledge/arbitration-puzzle.js +1 -304
- package/dist/knowledge/arbitration-risk.js +1 -433
- package/dist/knowledge/arbitration-templates.js +1 -276
- package/dist/knowledge/arbitration-translation.js +1 -487
- package/dist/knowledge/arbitration-trust.js +1 -117
- package/dist/knowledge/audit-rules.js +1 -141
- package/dist/knowledge/bridge-risk.js +1 -263
- package/dist/knowledge/contact-risk.js +1 -200
- package/dist/knowledge/contact-templates.d.ts +27 -0
- package/dist/knowledge/contact-templates.js +1 -0
- package/dist/knowledge/demand-confirm.js +1 -206
- package/dist/knowledge/demand-matching.js +1 -132
- package/dist/knowledge/demand-risk.js +1 -240
- package/dist/knowledge/demand-translation.js +1 -354
- package/dist/knowledge/deployment-scanner.js +1 -823
- package/dist/knowledge/dynamic-pricing.js +1 -87
- package/dist/knowledge/examples-scanner-cli.js +1 -26
- package/dist/knowledge/examples-scanner.js +1 -825
- package/dist/knowledge/flywheel-loop.js +1 -404
- package/dist/knowledge/fund-layer.js +1 -973
- package/dist/knowledge/glossary.js +1 -211
- package/dist/knowledge/guard-confirm.js +1 -406
- package/dist/knowledge/guard-context.js +1 -287
- package/dist/knowledge/guard-design-patterns.js +1 -360
- package/dist/knowledge/guard-ledger.js +1 -260
- package/dist/knowledge/guard-lint.js +1 -670
- package/dist/knowledge/guard-migration.js +1 -228
- package/dist/knowledge/guard-puzzle.js +1 -805
- package/dist/knowledge/guard-render.js +1 -700
- package/dist/knowledge/guard-risk.js +1 -1879
- package/dist/knowledge/guard-submission-prompt.js +1 -171
- package/dist/knowledge/guard-templates.js +1 -1105
- package/dist/knowledge/guard-translation.js +1 -1119
- package/dist/knowledge/index.js +1 -436
- package/dist/knowledge/industry-evolution.js +1 -323
- package/dist/knowledge/industry-generalizer.js +1 -381
- package/dist/knowledge/industry-registry.js +1 -174
- package/dist/knowledge/intent-metrics.d.ts +4 -3
- package/dist/knowledge/intent-metrics.js +1 -566
- package/dist/knowledge/machine-confirm.js +1 -559
- package/dist/knowledge/machine-context.js +1 -833
- package/dist/knowledge/machine-ledger.js +1 -338
- package/dist/knowledge/machine-puzzle.js +1 -494
- package/dist/knowledge/machine-render.js +1 -565
- package/dist/knowledge/machine-risk.js +1 -670
- package/dist/knowledge/machine-templates.js +1 -1597
- package/dist/knowledge/machine-topology.js +1 -234
- package/dist/knowledge/machine-translation.js +1 -513
- package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
- package/dist/knowledge/mcp-schema-audit.d.ts +1 -1
- package/dist/knowledge/mcp-schema-audit.js +1 -773
- package/dist/knowledge/onchain-constants.js +1 -35
- package/dist/knowledge/order-confirm.js +1 -573
- package/dist/knowledge/order-context.js +1 -390
- package/dist/knowledge/order-ledger.js +1 -341
- package/dist/knowledge/order-puzzle.js +1 -255
- package/dist/knowledge/order-risk.js +1 -653
- package/dist/knowledge/order-templates.js +1 -368
- package/dist/knowledge/order-translation.js +1 -550
- package/dist/knowledge/overrides-loader.js +1 -65
- package/dist/knowledge/passport-confirm.js +1 -531
- package/dist/knowledge/passport-context.js +1 -306
- package/dist/knowledge/passport-ledger.js +1 -282
- package/dist/knowledge/passport-puzzle.js +1 -333
- package/dist/knowledge/passport-risk.js +1 -450
- package/dist/knowledge/passport-templates.js +1 -568
- package/dist/knowledge/passport-translation.js +1 -516
- package/dist/knowledge/payment-risk.js +1 -249
- package/dist/knowledge/permission-confirm.js +1 -426
- package/dist/knowledge/permission-context.js +1 -224
- package/dist/knowledge/permission-ledger.js +1 -403
- package/dist/knowledge/permission-puzzle.js +1 -173
- package/dist/knowledge/permission-risk.js +1 -411
- package/dist/knowledge/permission-templates.js +1 -234
- package/dist/knowledge/permission-translation.js +1 -350
- package/dist/knowledge/personal-risk.js +1 -212
- package/dist/knowledge/process-model.js +1 -160
- package/dist/knowledge/progress-confirm.js +1 -456
- package/dist/knowledge/progress-context.js +1 -452
- package/dist/knowledge/progress-ledger.js +1 -330
- package/dist/knowledge/progress-puzzle.js +1 -219
- package/dist/knowledge/progress-risk.js +1 -461
- package/dist/knowledge/progress-templates.js +1 -228
- package/dist/knowledge/progress-translation.js +1 -405
- package/dist/knowledge/proof-confirm.js +1 -187
- package/dist/knowledge/proof-risk.js +1 -207
- package/dist/knowledge/proof-translation.js +1 -283
- package/dist/knowledge/registrar-risk.js +1 -217
- package/dist/knowledge/repository-confirm.js +1 -286
- package/dist/knowledge/repository-risk.js +1 -373
- package/dist/knowledge/repository-translation.js +1 -445
- package/dist/knowledge/reputation-rules.js +1 -99
- package/dist/knowledge/resource-risk.js +1 -157
- package/dist/knowledge/reward-confirm.js +1 -526
- package/dist/knowledge/reward-context.js +1 -504
- package/dist/knowledge/reward-ledger.js +1 -502
- package/dist/knowledge/reward-puzzle.js +1 -300
- package/dist/knowledge/reward-risk.js +1 -627
- package/dist/knowledge/reward-templates.js +1 -197
- package/dist/knowledge/reward-translation.js +1 -501
- package/dist/knowledge/safety-rules.js +1 -404
- package/dist/knowledge/scenario-modes.js +1 -321
- package/dist/knowledge/service-confirm.js +1 -807
- package/dist/knowledge/service-context.js +1 -403
- package/dist/knowledge/service-ledger.js +1 -609
- package/dist/knowledge/service-puzzle.js +1 -236
- package/dist/knowledge/service-risk.js +1 -615
- package/dist/knowledge/service-templates.js +1 -456
- package/dist/knowledge/service-translation.js +1 -622
- package/dist/knowledge/template-registry.d.ts +1 -1
- package/dist/knowledge/template-registry.js +1 -341
- package/dist/knowledge/tool-constraints.js +1 -195
- package/dist/knowledge/tools-reference.js +1 -155
- package/dist/knowledge/treasury-confirm.js +1 -512
- package/dist/knowledge/treasury-context.js +1 -363
- package/dist/knowledge/treasury-ledger.js +1 -300
- package/dist/knowledge/treasury-puzzle.js +1 -216
- package/dist/knowledge/treasury-risk.js +1 -440
- package/dist/knowledge/treasury-templates.js +1 -358
- package/dist/knowledge/treasury-translation.js +1 -498
- package/dist/knowledge/trust-metrics.js +1 -198
- package/dist/knowledge/util-risk.js +1 -135
- package/dist/loop-engineering/aggregate.js +1 -132
- package/dist/loop-engineering/context-collect.js +1 -83
- package/dist/loop-engineering/diagnose.js +1 -273
- package/dist/loop-engineering/improve.js +1 -405
- package/dist/loop-engineering/index.js +1 -4
- package/dist/loop-engineering/pipeline.js +1 -56
- package/dist/mode-market/index.js +1 -3
- package/dist/mode-market/registry.js +1 -124
- package/dist/mode-market/review.js +1 -214
- package/dist/mode-market/submission.js +1 -85
- package/dist/participation/collaborator-interest.d.ts +23 -0
- package/dist/participation/collaborator-interest.js +1 -0
- package/dist/participation/customer-interest.d.ts +25 -0
- package/dist/participation/customer-interest.js +1 -0
- package/dist/participation/merchant-interest.js +1 -100
- package/dist/participation/radar-core.d.ts +13 -3
- package/dist/participation/radar-core.js +1 -269
- package/dist/participation/supplier-interest.d.ts +25 -0
- package/dist/participation/supplier-interest.js +1 -0
- package/dist/persona/analyzer.d.ts +16 -0
- package/dist/persona/analyzer.js +1 -0
- package/dist/persona/bridge.d.ts +5 -0
- package/dist/persona/bridge.js +1 -0
- package/dist/persona/defaults.d.ts +4 -0
- package/dist/persona/defaults.js +1 -0
- package/dist/persona/experience-bridge.d.ts +3 -0
- package/dist/persona/experience-bridge.js +1 -0
- package/dist/persona/index.d.ts +18 -0
- package/dist/persona/index.js +1 -0
- package/dist/persona/model.d.ts +7 -0
- package/dist/persona/model.js +1 -0
- package/dist/persona/store.d.ts +19 -0
- package/dist/persona/store.js +1 -0
- package/dist/persona/types.d.ts +45 -0
- package/dist/persona/types.js +1 -0
- package/dist/project/business-puzzle.js +1 -383
- package/dist/project/context-assembly.js +1 -254
- package/dist/project/deployment-bridge.js +1 -120
- package/dist/project/deployment-doc.js +1 -1126
- package/dist/project/edit-planner.js +1 -1342
- package/dist/project/evaluation.js +1 -2011
- package/dist/project/game-theory.js +1 -177
- package/dist/project/graph-builder.js +1 -656
- package/dist/project/graph.js +1 -340
- package/dist/project/handlers.d.ts +5 -0
- package/dist/project/handlers.js +1 -1762
- package/dist/project/index.d.ts +1 -0
- package/dist/project/index.js +1 -301
- package/dist/project/intent-analyzer.js +1 -149
- package/dist/project/machine-nodes.js +1 -36
- package/dist/project/merchant-guide.js +1 -264
- package/dist/project/migration.js +1 -125
- package/dist/project/mode-actions.js +1 -309
- package/dist/project/namespace.js +1 -206
- package/dist/project/participation-radar.js +1 -428
- package/dist/project/pipeline-actions.js +1 -109
- package/dist/project/project-store.js +1 -422
- package/dist/project/query.js +1 -153
- package/dist/project/reverse-mapping.d.ts +34 -0
- package/dist/project/reverse-mapping.js +1 -0
- package/dist/project/risk-aggregator.js +1 -295
- package/dist/project/rollback-policy.js +1 -290
- package/dist/project/semantic-assembler.js +1 -345
- package/dist/project/semantic-graph.js +1 -245
- package/dist/project/stage-gate.js +1 -369
- package/dist/project/substep-trace.js +1 -332
- package/dist/project/task-tracker.js +1 -78
- package/dist/role/derivation.d.ts +18 -0
- package/dist/role/derivation.js +1 -0
- package/dist/role/index.d.ts +5 -0
- package/dist/role/index.js +1 -0
- package/dist/role/model.d.ts +8 -0
- package/dist/role/model.js +1 -0
- package/dist/role/resolution.d.ts +11 -0
- package/dist/role/resolution.js +1 -0
- package/dist/role/types.d.ts +11 -0
- package/dist/role/types.js +1 -0
- package/dist/rules.d.ts +2 -0
- package/dist/rules.js +1 -9
- package/dist/safety/confirm-gate.js +1 -88
- package/dist/safety/index.js +1 -3
- package/dist/safety/preview.js +1 -52
- package/dist/schema/call/allocation.js +1 -34
- package/dist/schema/call/arbitration.js +1 -113
- package/dist/schema/call/base.d.ts +15 -15
- package/dist/schema/call/base.js +1 -370
- package/dist/schema/call/bridge-handler.js +1 -265
- package/dist/schema/call/bridge.d.ts +7 -7
- package/dist/schema/call/bridge.js +1 -458
- package/dist/schema/call/contact.js +1 -37
- package/dist/schema/call/demand.js +1 -47
- package/dist/schema/call/guard.js +1 -161
- package/dist/schema/call/handler.js +1 -322
- package/dist/schema/call/index.js +1 -20
- package/dist/schema/call/machine.js +1 -193
- package/dist/schema/call/order.js +1 -35
- package/dist/schema/call/payment.js +1 -37
- package/dist/schema/call/permission-handler.js +1 -54
- package/dist/schema/call/permission.js +1 -105
- package/dist/schema/call/personal.js +1 -78
- package/dist/schema/call/progress.js +1 -47
- package/dist/schema/call/proof.js +1 -33
- package/dist/schema/call/repository.js +1 -77
- package/dist/schema/call/reward.js +1 -30
- package/dist/schema/call/semantic.js +1 -1657
- package/dist/schema/call/service.js +1 -178
- package/dist/schema/call/treasury.js +1 -71
- package/dist/schema/common/index.js +1 -407
- package/dist/schema/config/index.js +1 -68
- package/dist/schema/evaluation/index.d.ts +4436 -0
- package/dist/schema/evaluation/index.js +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.js +1 -13
- package/dist/schema/intent-radar/index.d.ts +284 -0
- package/dist/schema/intent-radar/index.js +1 -0
- package/dist/schema/local/index.d.ts +21 -21
- package/dist/schema/local/index.js +1 -927
- package/dist/schema/local/wip.js +1 -187
- package/dist/schema/messenger/index.d.ts +7 -7
- package/dist/schema/messenger/index.js +1 -475
- package/dist/schema/operations.d.ts +7 -7
- package/dist/schema/operations.js +1 -520
- package/dist/schema/persona/index.d.ts +1985 -0
- package/dist/schema/persona/index.js +1 -0
- package/dist/schema/project/index.d.ts +96 -50
- package/dist/schema/project/index.js +1 -2057
- package/dist/schema/query/index.d.ts +423 -7
- package/dist/schema/query/index.js +1 -1640
- package/dist/schema/schema-query/index.js +1 -104
- package/dist/schema/schema-version.js +1 -76
- package/dist/schema/sync-layer4.d.ts +1 -1
- package/dist/schema/sync-layer4.js +1 -282
- package/dist/schema/task-status.d.ts +168 -0
- package/dist/schema/task-status.js +1 -0
- package/dist/schema/trust/index.js +1 -314
- package/dist/schema/utils/guard-parser.js +1 -419
- package/dist/schema/utils/guard-query-utils.js +1 -46
- package/dist/schema/utils/node-parser.js +1 -369
- package/dist/schema/utils/object-type-utils.js +1 -35
- package/dist/schema/utils/permission-index-utils.js +1 -7
- package/dist/schema/utils/permission-machine-check.js +1 -121
- package/dist/schema/utils/skills-recommendation.js +1 -77
- package/dist/schema-query/index.js +1 -810
- package/dist/schemas/account_operation.output.json +5 -2
- package/dist/schemas/bridge_operation.output.json +5 -2
- package/dist/schemas/evaluation_operation.output.json +782 -0
- package/dist/schemas/evaluation_operation.schema.json +990 -0
- package/dist/schemas/index.json +25 -1
- package/dist/schemas/intent_radar.output.json +232 -0
- package/dist/schemas/intent_radar.schema.json +138 -0
- package/dist/schemas/local_info_operation.output.json +5 -2
- package/dist/schemas/local_mark_operation.output.json +5 -2
- package/dist/schemas/messenger_operation.output.json +5 -2
- package/dist/schemas/onchain_events.output.json +5 -2
- package/dist/schemas/onchain_operations.output.json +5 -2
- package/dist/schemas/onchain_operations.schema.json +6 -6
- package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +2 -2
- package/dist/schemas/onchain_operations_service.schema.json +3 -3
- package/dist/schemas/onchain_table_data.output.json +6 -3
- package/dist/schemas/persona_operation.output.json +392 -0
- package/dist/schemas/persona_operation.schema.json +250 -0
- package/dist/schemas/project_operation.output.json +28 -8
- package/dist/schemas/query_task_status.output.json +115 -0
- package/dist/schemas/query_task_status.schema.json +24 -0
- package/dist/schemas/query_toolkit.output.json +9 -6
- package/dist/schemas/trust_score.schema.json +1 -1
- package/dist/schemas/wowok_buildin_info.output.json +132 -0
- package/dist/schemas/wowok_buildin_info.schema.json +14 -0
- package/dist/telemetry/index.js +1 -112
- package/dist/telemetry/redact.js +1 -23
- package/dist/telemetry/storage.js +1 -80
- package/dist/tools/handlers/bridge.js +1 -1
- package/dist/tools/handlers/config.js +1 -74
- package/dist/tools/handlers/evaluation.d.ts +2 -0
- package/dist/tools/handlers/evaluation.js +1 -0
- package/dist/tools/handlers/file-export.js +1 -90
- package/dist/tools/handlers/intent-radar.d.ts +2 -0
- package/dist/tools/handlers/intent-radar.js +1 -0
- package/dist/tools/handlers/local.js +1 -53
- package/dist/tools/handlers/messenger.js +1 -188
- package/dist/tools/handlers/onchain.js +1 -1082
- package/dist/tools/handlers/persona.d.ts +4 -0
- package/dist/tools/handlers/persona.js +1 -0
- package/dist/tools/handlers/project.js +1 -211
- package/dist/tools/handlers/query.js +1 -434
- package/dist/tools/handlers/schema-query.js +1 -176
- package/dist/tools/handlers/task-status.d.ts +0 -168
- package/dist/tools/handlers/task-status.js +1 -55
- package/dist/tools/handlers/trust.js +1 -380
- package/dist/tools/handlers/wip.js +1 -90
- package/dist/tools/index.js +1 -1306
- package/dist/tools/retry.js +1 -85
- package/dist/tools/rules-hook.js +1 -23
- package/dist/tools/shared.js +1 -130
- package/dist/tools/types.js +1 -1
- package/dist/tools/upgrade-check.d.ts +19 -0
- package/dist/tools/upgrade-check.js +1 -0
- package/dist/tools/wip-deploy-assist.d.ts +1 -1
- package/dist/tools/wip-deploy-assist.js +1 -278
- package/dist/tools/wrap.js +1 -500
- package/package.json +5 -3
|
@@ -1,717 +1 @@
|
|
|
1
|
-
import { UserModeStorage } from "@wowok/wowok";
|
|
2
|
-
import { CapabilityRegistry } from "./capability-manifest.js";
|
|
3
|
-
import { ModeEvaluator } from "./mode-evaluator.js";
|
|
4
|
-
import { MetricRegistry } from "./metric-registry.js";
|
|
5
|
-
import { ConstraintRegistry } from "./constraint-registry.js";
|
|
6
|
-
import { BUILTIN_MODES } from "./modes.js";
|
|
7
|
-
export class IndustryModeRegistry {
|
|
8
|
-
static instance;
|
|
9
|
-
registrations = new Map();
|
|
10
|
-
userModes = new Map();
|
|
11
|
-
aliases = new Map();
|
|
12
|
-
evaluator;
|
|
13
|
-
initialized = false;
|
|
14
|
-
persistence = new UserModeStorage();
|
|
15
|
-
userModesLoaded = false;
|
|
16
|
-
static Instance() {
|
|
17
|
-
if (!IndustryModeRegistry.instance) {
|
|
18
|
-
IndustryModeRegistry.instance = new IndustryModeRegistry();
|
|
19
|
-
}
|
|
20
|
-
return IndustryModeRegistry.instance;
|
|
21
|
-
}
|
|
22
|
-
constructor() {
|
|
23
|
-
this.evaluator = new ModeEvaluator(CapabilityRegistry.Instance(), MetricRegistry.Instance(), ConstraintRegistry.Instance());
|
|
24
|
-
this.registerBuiltinModes();
|
|
25
|
-
this.initialized = true;
|
|
26
|
-
}
|
|
27
|
-
registerMode(mode, aliases) {
|
|
28
|
-
if (!mode.name || !mode.traits || !mode.machine_shape) {
|
|
29
|
-
console.warn(`[IndustryModeRegistry] registerMode rejected: invalid mode ` +
|
|
30
|
-
`(name=${mode.name || "<missing>"}, traits=${mode.traits ? "ok" : "<missing>"}, ` +
|
|
31
|
-
`machine_shape=${mode.machine_shape ? "ok" : "<missing>"}).`);
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
if (this.registrations.has(mode.name)) {
|
|
35
|
-
const existing = this.registrations.get(mode.name);
|
|
36
|
-
console.warn(`[IndustryModeRegistry] registerMode rejected: mode '${mode.name}' already registered ` +
|
|
37
|
-
`(registered_at=${new Date(existing?.registered_at ?? 0).toISOString()}). ` +
|
|
38
|
-
`Use evolveMode/deriveMode for user modifications, or unregister first.`);
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
this.registrations.set(mode.name, {
|
|
42
|
-
mode,
|
|
43
|
-
aliases,
|
|
44
|
-
enabled: true,
|
|
45
|
-
registered_at: Date.now(),
|
|
46
|
-
});
|
|
47
|
-
if (aliases) {
|
|
48
|
-
for (const alias of aliases) {
|
|
49
|
-
this.aliases.set(alias, mode.name);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
getMode(name) {
|
|
55
|
-
const canonical = this.resolveAlias(name);
|
|
56
|
-
return this.registrations.get(canonical)?.mode;
|
|
57
|
-
}
|
|
58
|
-
listModes() {
|
|
59
|
-
return Array.from(this.registrations.values())
|
|
60
|
-
.filter(r => r.enabled)
|
|
61
|
-
.map(r => r.mode);
|
|
62
|
-
}
|
|
63
|
-
resolveAlias(name) {
|
|
64
|
-
return this.aliases.get(name) ?? name;
|
|
65
|
-
}
|
|
66
|
-
hasMode(name) {
|
|
67
|
-
const canonical = this.resolveAlias(name);
|
|
68
|
-
return this.registrations.has(canonical);
|
|
69
|
-
}
|
|
70
|
-
evaluateMode(name, intent, context) {
|
|
71
|
-
const mode = this.getMode(name);
|
|
72
|
-
if (!mode) {
|
|
73
|
-
return {
|
|
74
|
-
applicable: false,
|
|
75
|
-
risk_score: 100,
|
|
76
|
-
benefit_score: 0,
|
|
77
|
-
risk_benefit_ratio: 0,
|
|
78
|
-
capability_conflicts: [],
|
|
79
|
-
violated_constraints: [],
|
|
80
|
-
unmet_conditions: [`Mode '${name}' not found`],
|
|
81
|
-
recommendations: [`Mode '${name}' not registered, falling back to 'general'`],
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return this.evaluator.evaluateMode(mode, intent, context);
|
|
85
|
-
}
|
|
86
|
-
evaluateMigration(sourceName, targetName) {
|
|
87
|
-
const source = this.getMode(sourceName);
|
|
88
|
-
const target = this.getMode(targetName);
|
|
89
|
-
if (!source || !target) {
|
|
90
|
-
return {
|
|
91
|
-
feasibility_score: 0,
|
|
92
|
-
source_risk_score: 0,
|
|
93
|
-
target_risk_score: 0,
|
|
94
|
-
source_benefit_score: 0,
|
|
95
|
-
target_benefit_score: 0,
|
|
96
|
-
risk_delta: 0,
|
|
97
|
-
benefit_delta: 0,
|
|
98
|
-
added_capabilities: [],
|
|
99
|
-
removed_capabilities: [],
|
|
100
|
-
conflicting_capabilities: [],
|
|
101
|
-
recommendations: [`Mode '${sourceName}' or '${targetName}' not found`],
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return this.evaluator.evaluateMigration(source, target);
|
|
105
|
-
}
|
|
106
|
-
async registerUserMode(mode, userId) {
|
|
107
|
-
await this.ensureUserModesLoaded();
|
|
108
|
-
if (!mode.name || !mode.owner || !mode.machine_shape)
|
|
109
|
-
return false;
|
|
110
|
-
if (mode.source !== "custom")
|
|
111
|
-
return false;
|
|
112
|
-
if (mode.owner !== userId)
|
|
113
|
-
return false;
|
|
114
|
-
const userKey = this.userModeKey(mode.owner, mode.name);
|
|
115
|
-
if (this.registrations.has(mode.name))
|
|
116
|
-
return false;
|
|
117
|
-
if (this.userModes.has(userKey))
|
|
118
|
-
return false;
|
|
119
|
-
if (!mode.evolution_history || mode.evolution_history.length === 0) {
|
|
120
|
-
mode.evolution_history = [{
|
|
121
|
-
version: mode.version || "v1",
|
|
122
|
-
changed_at: Date.now(),
|
|
123
|
-
changes: ["Initial registration (registerUserMode)"],
|
|
124
|
-
}];
|
|
125
|
-
}
|
|
126
|
-
this.userModes.set(userKey, mode);
|
|
127
|
-
await this.persistUserMode(mode);
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
async deriveMode(sourceMode, modifications, userId, newName, newDisplayName) {
|
|
131
|
-
await this.ensureUserModesLoaded();
|
|
132
|
-
const source = this.getMode(sourceMode);
|
|
133
|
-
if (!source)
|
|
134
|
-
return undefined;
|
|
135
|
-
if (!newName || this.registrations.has(newName))
|
|
136
|
-
return undefined;
|
|
137
|
-
const userKey = this.userModeKey(userId, newName);
|
|
138
|
-
if (this.userModes.has(userKey))
|
|
139
|
-
return undefined;
|
|
140
|
-
const derived = {
|
|
141
|
-
name: newName,
|
|
142
|
-
display_name: newDisplayName ?? newName,
|
|
143
|
-
version: "v1",
|
|
144
|
-
source: "custom",
|
|
145
|
-
traits: modifications.traits ?? source.traits,
|
|
146
|
-
machine_shape: modifications.machine_shape ?? source.machine_shape,
|
|
147
|
-
guards: modifications.guards ?? source.guards,
|
|
148
|
-
allocator: modifications.allocator ?? source.allocator,
|
|
149
|
-
risk_checks: modifications.risk_checks ?? source.risk_checks,
|
|
150
|
-
needs: modifications.needs ?? source.needs,
|
|
151
|
-
flywheel: modifications.flywheel ?? source.flywheel,
|
|
152
|
-
key_risk: modifications.key_risk ?? source.key_risk,
|
|
153
|
-
build_notes: modifications.build_notes ?? source.build_notes,
|
|
154
|
-
capabilities_used: modifications.capabilities_used ?? source.capabilities_used,
|
|
155
|
-
config_overrides: modifications.config_overrides ?? source.config_overrides,
|
|
156
|
-
config_override_rules: modifications.config_override_rules ?? source.config_override_rules,
|
|
157
|
-
expected_benefits: modifications.expected_benefits ?? source.expected_benefits,
|
|
158
|
-
risk_appetite: modifications.risk_appetite ?? source.risk_appetite,
|
|
159
|
-
risk_constraints: modifications.risk_constraints ?? source.risk_constraints,
|
|
160
|
-
applicable_conditions: modifications.applicable_conditions ?? source.applicable_conditions,
|
|
161
|
-
similar_industries: modifications.similar_industries ?? source.similar_industries,
|
|
162
|
-
novel_capabilities: modifications.novel_capabilities ?? source.novel_capabilities,
|
|
163
|
-
owner: userId,
|
|
164
|
-
derived_from: sourceMode,
|
|
165
|
-
custom_metrics: modifications.custom_metrics ?? source.custom_metrics,
|
|
166
|
-
custom_constraints: modifications.custom_constraints ?? source.custom_constraints,
|
|
167
|
-
evolution_history: [{
|
|
168
|
-
version: "v1",
|
|
169
|
-
changed_at: Date.now(),
|
|
170
|
-
changes: [`Derived from builtin '${sourceMode}'`],
|
|
171
|
-
}],
|
|
172
|
-
};
|
|
173
|
-
this.userModes.set(userKey, derived);
|
|
174
|
-
await this.persistUserMode(derived);
|
|
175
|
-
return derived;
|
|
176
|
-
}
|
|
177
|
-
async evolveMode(modeName, updates, userId, changeDescription, bumpVersion = true) {
|
|
178
|
-
await this.ensureUserModesLoaded();
|
|
179
|
-
const userKey = this.userModeKey(userId, modeName);
|
|
180
|
-
const existing = this.userModes.get(userKey);
|
|
181
|
-
if (!existing)
|
|
182
|
-
return undefined;
|
|
183
|
-
const newVersion = bumpVersion
|
|
184
|
-
? this.bumpPatchVersion(existing.version)
|
|
185
|
-
: existing.version;
|
|
186
|
-
const evolved = {
|
|
187
|
-
...existing,
|
|
188
|
-
...updates,
|
|
189
|
-
name: existing.name,
|
|
190
|
-
owner: existing.owner,
|
|
191
|
-
source: "custom",
|
|
192
|
-
derived_from: existing.derived_from,
|
|
193
|
-
evolution_history: [
|
|
194
|
-
...(existing.evolution_history ?? []),
|
|
195
|
-
{
|
|
196
|
-
version: newVersion,
|
|
197
|
-
changed_at: Date.now(),
|
|
198
|
-
changes: [changeDescription],
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
version: newVersion,
|
|
202
|
-
};
|
|
203
|
-
this.userModes.set(userKey, evolved);
|
|
204
|
-
await this.persistUserMode(evolved);
|
|
205
|
-
return evolved;
|
|
206
|
-
}
|
|
207
|
-
async listUserModes(userId) {
|
|
208
|
-
await this.ensureUserModesLoaded();
|
|
209
|
-
const result = [];
|
|
210
|
-
for (const mode of this.userModes.values()) {
|
|
211
|
-
if (mode.owner === userId) {
|
|
212
|
-
result.push(mode);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return result;
|
|
216
|
-
}
|
|
217
|
-
async getUserMode(modeName, userId) {
|
|
218
|
-
await this.ensureUserModesLoaded();
|
|
219
|
-
const userKey = this.userModeKey(userId, modeName);
|
|
220
|
-
return this.userModes.get(userKey);
|
|
221
|
-
}
|
|
222
|
-
async unregisterUserMode(modeName, userId) {
|
|
223
|
-
await this.ensureUserModesLoaded();
|
|
224
|
-
const userKey = this.userModeKey(userId, modeName);
|
|
225
|
-
const removed = this.userModes.delete(userKey);
|
|
226
|
-
if (removed) {
|
|
227
|
-
await this.unpersistUserMode(userId, modeName);
|
|
228
|
-
}
|
|
229
|
-
return removed;
|
|
230
|
-
}
|
|
231
|
-
userModeKey(owner, name) {
|
|
232
|
-
return `${owner}:${name}`;
|
|
233
|
-
}
|
|
234
|
-
async ensureUserModesLoaded() {
|
|
235
|
-
if (this.userModesLoaded)
|
|
236
|
-
return;
|
|
237
|
-
this.userModesLoaded = true;
|
|
238
|
-
try {
|
|
239
|
-
const rows = await this.persistence.list();
|
|
240
|
-
for (const row of rows) {
|
|
241
|
-
try {
|
|
242
|
-
const mode = JSON.parse(row.data);
|
|
243
|
-
if (mode?.name && mode?.owner && mode?.machine_shape) {
|
|
244
|
-
this.userModes.set(this.userModeKey(row.owner, row.name), mode);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch {
|
|
248
|
-
console.warn(`[IndustryModeRegistry] Skipping corrupt user_modes row '${row.owner}:${row.name}'.`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
catch (err) {
|
|
253
|
-
console.warn("[IndustryModeRegistry] Failed to load persisted user modes:", err.message);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async persistUserMode(mode) {
|
|
257
|
-
try {
|
|
258
|
-
await this.persistence.save(mode.owner, mode.name, JSON.stringify(mode));
|
|
259
|
-
}
|
|
260
|
-
catch (err) {
|
|
261
|
-
console.warn(`[IndustryModeRegistry] Failed to persist user mode '${mode.owner}:${mode.name}':`, err.message);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async unpersistUserMode(owner, name) {
|
|
265
|
-
try {
|
|
266
|
-
await this.persistence.delete(owner, name);
|
|
267
|
-
}
|
|
268
|
-
catch (err) {
|
|
269
|
-
console.warn(`[IndustryModeRegistry] Failed to delete persisted user mode '${owner}:${name}':`, err.message);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
bumpPatchVersion(version) {
|
|
273
|
-
const stripped = version.replace(/^v/, "");
|
|
274
|
-
const parts = stripped.split(".");
|
|
275
|
-
if (parts.length < 2)
|
|
276
|
-
return `v${stripped}.1`;
|
|
277
|
-
const patch = parseInt(parts[1] ?? "0", 10);
|
|
278
|
-
parts[1] = String(patch + 1);
|
|
279
|
-
return `v${parts.join(".")}`;
|
|
280
|
-
}
|
|
281
|
-
async applyTemplate(name, intent, context) {
|
|
282
|
-
const builtinMode = this.getMode(name);
|
|
283
|
-
if (builtinMode) {
|
|
284
|
-
const blueprint = this.doApplyTemplate(builtinMode, intent, context);
|
|
285
|
-
this.recordCapabilitiesUsed(builtinMode);
|
|
286
|
-
return blueprint;
|
|
287
|
-
}
|
|
288
|
-
if (name.includes(":")) {
|
|
289
|
-
const [owner, modeName] = name.split(":", 2);
|
|
290
|
-
const userMode = await this.getUserMode(modeName, owner);
|
|
291
|
-
if (userMode) {
|
|
292
|
-
const blueprint = this.doApplyTemplate(userMode, intent, context);
|
|
293
|
-
this.recordCapabilitiesUsed(userMode);
|
|
294
|
-
return blueprint;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const general = this.getMode("general");
|
|
298
|
-
if (!general) {
|
|
299
|
-
throw new Error("IndustryMode 'general' not registered — cannot fallback");
|
|
300
|
-
}
|
|
301
|
-
const blueprint = this.doApplyTemplate(general, intent, context);
|
|
302
|
-
this.recordCapabilitiesUsed(general);
|
|
303
|
-
return blueprint;
|
|
304
|
-
}
|
|
305
|
-
async applyUserMode(modeName, userId, intent, context) {
|
|
306
|
-
const userMode = await this.getUserMode(modeName, userId);
|
|
307
|
-
if (!userMode) {
|
|
308
|
-
throw new Error(`User mode '${modeName}' not found for user '${userId}'`);
|
|
309
|
-
}
|
|
310
|
-
const blueprint = this.doApplyTemplate(userMode, intent, context);
|
|
311
|
-
this.recordCapabilitiesUsed(userMode);
|
|
312
|
-
return blueprint;
|
|
313
|
-
}
|
|
314
|
-
doApplyTemplate(mode, intent, context) {
|
|
315
|
-
let objects = this.buildObjects(mode, intent, context);
|
|
316
|
-
objects = this.applyConfigOverrides(mode, objects);
|
|
317
|
-
objects = this.applyConfigOverrideRules(mode, objects, intent, context);
|
|
318
|
-
const edges = this.buildEdges(objects, context);
|
|
319
|
-
const steps = this.buildSteps(objects, edges, context.network);
|
|
320
|
-
const scenarios = this.defaultScenarios(mode, intent, objects);
|
|
321
|
-
const validation = this.validateBlueprint(objects, edges, mode);
|
|
322
|
-
if (validation.errors.length > 0) {
|
|
323
|
-
throw new Error(`Blueprint validation for mode '${mode.name}' failed with ${validation.errors.length} CRITICAL error(s):\n` +
|
|
324
|
-
validation.errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n"));
|
|
325
|
-
}
|
|
326
|
-
if (validation.warnings.length > 0) {
|
|
327
|
-
console.warn(`[IndustryModeRegistry] Blueprint validation for '${mode.name}' produced ${validation.warnings.length} warning(s):`, validation.warnings);
|
|
328
|
-
}
|
|
329
|
-
return {
|
|
330
|
-
context,
|
|
331
|
-
objects,
|
|
332
|
-
edges,
|
|
333
|
-
steps,
|
|
334
|
-
scenarios,
|
|
335
|
-
industry_source: mode.name,
|
|
336
|
-
applied_template: `${mode.name}@${mode.version}`,
|
|
337
|
-
validation,
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
validateBlueprint(objects, edges, mode) {
|
|
341
|
-
const errors = [];
|
|
342
|
-
const warnings = [];
|
|
343
|
-
const machine = objects.find(o => o.object_type === "machine");
|
|
344
|
-
const service = objects.find(o => o.object_type === "service");
|
|
345
|
-
if (machine) {
|
|
346
|
-
const hint = machine.config.entry_node_forward_hint;
|
|
347
|
-
if (!hint) {
|
|
348
|
-
warnings.push("Machine blueprint missing entry_node_forward_hint. " +
|
|
349
|
-
"The AI must ensure the entry node (prev_node='') has ≥1 forward when constructing the Machine creation call (P0-2).");
|
|
350
|
-
}
|
|
351
|
-
else if (hint.required === true && !hint.example_forward) {
|
|
352
|
-
warnings.push("Machine entry_node_forward_hint marked required but example_forward is missing.");
|
|
353
|
-
}
|
|
354
|
-
const nodes = machine.config.nodes;
|
|
355
|
-
if (!nodes || nodes.length === 0) {
|
|
356
|
-
errors.push(`Machine blueprint has no nodes — mode '${mode.name}' machine_shape is empty. ` +
|
|
357
|
-
`Add nodes to the mode's machine_shape before applying template.`);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (service) {
|
|
361
|
-
const compensationFundRef = service.config.compensation_fund;
|
|
362
|
-
if (compensationFundRef) {
|
|
363
|
-
errors.push(`Service blueprint has compensation_fund='${compensationFundRef}' (string reference). ` +
|
|
364
|
-
`BUG: compensation_fund is Balance<T> (numeric), NOT a Treasury object reference. ` +
|
|
365
|
-
`Remove compensation_fund field and use compensation_fund_balance + compensation_fund_add_hint instead. ` +
|
|
366
|
-
`Smart contract (service.move:179): compensation_fund: Balance<T>.`);
|
|
367
|
-
}
|
|
368
|
-
const balanceField = service.config.compensation_fund_balance;
|
|
369
|
-
if (balanceField === undefined) {
|
|
370
|
-
warnings.push("Service blueprint missing compensation_fund_balance. " +
|
|
371
|
-
"Should be 0 (initial Balance<T> state) — filled via service.compensation_fund_add(coin).");
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
const objectIds = new Set(objects.map(o => o.entry_id));
|
|
375
|
-
const objectNames = new Set(objects.map(o => o.name));
|
|
376
|
-
for (const edge of edges) {
|
|
377
|
-
const fromOk = objectIds.has(edge.from) || objectNames.has(edge.from);
|
|
378
|
-
const toOk = objectIds.has(edge.to) || objectNames.has(edge.to);
|
|
379
|
-
if (!fromOk || !toOk) {
|
|
380
|
-
errors.push(`Edge '${edge.from}' → '${edge.to}' (kind='${edge.edge_kind}') references undefined object. ` +
|
|
381
|
-
`from_exists=${fromOk}, to_exists=${toOk}.`);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return { errors, warnings };
|
|
385
|
-
}
|
|
386
|
-
buildObjects(mode, intent, context) {
|
|
387
|
-
const prefix = context.prefix;
|
|
388
|
-
const objects = [];
|
|
389
|
-
objects.push(this.makeObject("permission", `${prefix}_permission`, {
|
|
390
|
-
name: `${prefix}_permission`,
|
|
391
|
-
description: `Permission: role permission index (${mode.display_name})`,
|
|
392
|
-
permission_indexes: this.buildPermissionIndexes(mode),
|
|
393
|
-
tags: [`industry:${mode.name}`],
|
|
394
|
-
}));
|
|
395
|
-
const serviceGuardName = this.getFirstServiceGuardName(mode, prefix);
|
|
396
|
-
for (const guard of mode.guards) {
|
|
397
|
-
const shortName = this.deriveGuardShortName(guard.template_id);
|
|
398
|
-
const guardName = `${prefix}_guard_${shortName}`;
|
|
399
|
-
objects.push(this.makeObject("guard", guardName, {
|
|
400
|
-
name: guardName,
|
|
401
|
-
description: `Guard: ${guard.purpose} (${mode.display_name})`,
|
|
402
|
-
host: guard.host,
|
|
403
|
-
template_id: guard.template_id,
|
|
404
|
-
tags: [`industry:${mode.name}`, `host:${guard.host}`],
|
|
405
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
objects.push(this.makeObject("machine", `${prefix}_machine`, {
|
|
408
|
-
name: `${prefix}_machine`,
|
|
409
|
-
description: `Machine: workflow topology (${mode.display_name}) — ${mode.machine_shape.length} nodes`,
|
|
410
|
-
nodes: mode.machine_shape.map(n => ({ name: n.name, role: n.role })),
|
|
411
|
-
guard_objects: mode.guards
|
|
412
|
-
.filter(g => g.host === "machine")
|
|
413
|
-
.map(g => ({
|
|
414
|
-
template_id: g.template_id,
|
|
415
|
-
object_name: `${prefix}_guard_${this.deriveGuardShortName(g.template_id)}`,
|
|
416
|
-
purpose: g.purpose,
|
|
417
|
-
})),
|
|
418
|
-
permission: `${prefix}_permission`,
|
|
419
|
-
entry_node_forward_hint: {
|
|
420
|
-
entry_node_name: mode.machine_shape[0]?.name ?? "paid",
|
|
421
|
-
required: true,
|
|
422
|
-
example_forward: {
|
|
423
|
-
next_node: mode.machine_shape[0]?.name ?? "paid",
|
|
424
|
-
namedOperator: "",
|
|
425
|
-
weight: 1,
|
|
426
|
-
},
|
|
427
|
-
reason: "Progress starts at current='' and follows the entry node's forwards. " +
|
|
428
|
-
"Without a forward, Progress is permanently stuck (P0-2). " +
|
|
429
|
-
"Schema refinement in MachineNodePairSchema enforces this at publish time.",
|
|
430
|
-
},
|
|
431
|
-
tags: [`industry:${mode.name}`],
|
|
432
|
-
}, true));
|
|
433
|
-
objects.push(this.makeObject("treasury", `${prefix}_treasury`, {
|
|
434
|
-
name: `${prefix}_treasury`,
|
|
435
|
-
description: `Treasury: fund escrow (${mode.display_name})`,
|
|
436
|
-
owner_receive: true,
|
|
437
|
-
tags: [`industry:${mode.name}`],
|
|
438
|
-
}));
|
|
439
|
-
objects.push(this.makeObject("allocation", `${prefix}_allocation`, {
|
|
440
|
-
name: `${prefix}_allocation`,
|
|
441
|
-
description: `Allocation: allocation strategy (${mode.display_name}) — ${mode.allocator.description}`,
|
|
442
|
-
strategy: mode.allocator,
|
|
443
|
-
treasury: `${prefix}_treasury`,
|
|
444
|
-
guard: serviceGuardName,
|
|
445
|
-
tags: [`industry:${mode.name}`],
|
|
446
|
-
}));
|
|
447
|
-
objects.push(this.makeObject("service", `${prefix}_service`, {
|
|
448
|
-
name: `${prefix}_service`,
|
|
449
|
-
description: `Service: business service (${mode.display_name}) — ${intent.slice(0, 100)}`,
|
|
450
|
-
machine: `${prefix}_machine`,
|
|
451
|
-
buy_guard: serviceGuardName,
|
|
452
|
-
permission: `${prefix}_permission`,
|
|
453
|
-
order_allocators: [`${prefix}_allocation`],
|
|
454
|
-
compensation_fund_balance: 0,
|
|
455
|
-
compensation_fund_required: mode.risk_constraints?.require_compensation_fund ?? false,
|
|
456
|
-
compensation_fund_coverage_ratio: mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5,
|
|
457
|
-
compensation_fund_add_hint: "Call service.compensation_fund_add with a Coin<T> to deposit. " +
|
|
458
|
-
"The compensation_fund is a Balance<T> (numeric), not a Treasury object reference. " +
|
|
459
|
-
"Without deposit, arbitration rulings that award refunds to buyers cannot be paid out. " +
|
|
460
|
-
`Recommend ${mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5}× the max single-order amount (P1-1 evaluation rule, industry: ${mode.name}).`,
|
|
461
|
-
arbitrations: [`${prefix}_arb`],
|
|
462
|
-
rewards: [`${prefix}_reward`],
|
|
463
|
-
business_intent: intent,
|
|
464
|
-
industry: mode.name,
|
|
465
|
-
tags: [`industry:${mode.name}`],
|
|
466
|
-
}, true));
|
|
467
|
-
objects.push(this.makeObject("progress", `${prefix}_progress`, {
|
|
468
|
-
name: `${prefix}_progress`,
|
|
469
|
-
description: `Progress: order fulfillment progress (${mode.display_name})`,
|
|
470
|
-
parent: `${prefix}_machine`,
|
|
471
|
-
tags: [`industry:${mode.name}`],
|
|
472
|
-
}));
|
|
473
|
-
objects.push(this.makeObject("arb", `${prefix}_arb`, {
|
|
474
|
-
name: `${prefix}_arb`,
|
|
475
|
-
description: `Arbitration: arbitration rules (${mode.display_name}) — ${mode.key_risk}`,
|
|
476
|
-
guard: `${prefix}_guard_buy`,
|
|
477
|
-
tags: [`industry:${mode.name}`],
|
|
478
|
-
}));
|
|
479
|
-
objects.push(this.makeObject("reward", `${prefix}_reward`, {
|
|
480
|
-
name: `${prefix}_reward`,
|
|
481
|
-
description: `Reward: incentive rules (${mode.display_name})`,
|
|
482
|
-
claim_guard: `${prefix}_guard_buy`,
|
|
483
|
-
tags: [`industry:${mode.name}`],
|
|
484
|
-
}));
|
|
485
|
-
objects.push(this.makeObject("contact", `${prefix}_contact`, {
|
|
486
|
-
name: `${prefix}_contact`,
|
|
487
|
-
description: `Contact: customer service contact (${mode.display_name})`,
|
|
488
|
-
tags: [`industry:${mode.name}`],
|
|
489
|
-
}));
|
|
490
|
-
return objects;
|
|
491
|
-
}
|
|
492
|
-
buildPermissionIndexes(mode) {
|
|
493
|
-
const permOverrides = mode.config_overrides?.["permission"];
|
|
494
|
-
if (permOverrides?.permission_indexes) {
|
|
495
|
-
return permOverrides.permission_indexes;
|
|
496
|
-
}
|
|
497
|
-
return [
|
|
498
|
-
{ name: "merchant", description: "Service owner / provider" },
|
|
499
|
-
{ name: "customer", description: "Service buyer / customer" },
|
|
500
|
-
{ name: "arbiter", description: "Arbitration arbiter" },
|
|
501
|
-
];
|
|
502
|
-
}
|
|
503
|
-
applyConfigOverrides(mode, objects) {
|
|
504
|
-
if (!mode.config_overrides)
|
|
505
|
-
return objects;
|
|
506
|
-
for (const obj of objects) {
|
|
507
|
-
const overrides = mode.config_overrides[obj.object_type];
|
|
508
|
-
if (overrides) {
|
|
509
|
-
for (const [key, value] of Object.entries(overrides)) {
|
|
510
|
-
obj.config[key] = value;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return objects;
|
|
515
|
-
}
|
|
516
|
-
applyConfigOverrideRules(mode, objects, intent, context) {
|
|
517
|
-
if (!mode.config_override_rules)
|
|
518
|
-
return objects;
|
|
519
|
-
for (const rule of mode.config_override_rules) {
|
|
520
|
-
const obj = objects.find(o => o.object_type === rule.object_type);
|
|
521
|
-
if (!obj)
|
|
522
|
-
continue;
|
|
523
|
-
let valueToApply;
|
|
524
|
-
if (rule.condition) {
|
|
525
|
-
const matched = this.evaluateCondition(rule, intent, context);
|
|
526
|
-
valueToApply = matched ? rule.condition.then_value : (rule.condition.else_value ?? rule.value);
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
valueToApply = rule.value;
|
|
530
|
-
}
|
|
531
|
-
if (valueToApply !== undefined) {
|
|
532
|
-
this.setNestedField(obj.config, rule.field_path, valueToApply);
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return objects;
|
|
536
|
-
}
|
|
537
|
-
evaluateCondition(rule, intent, context) {
|
|
538
|
-
if (!rule.condition)
|
|
539
|
-
return false;
|
|
540
|
-
if (rule.condition.intent_contains) {
|
|
541
|
-
return intent.toLowerCase().includes(rule.condition.intent_contains.toLowerCase());
|
|
542
|
-
}
|
|
543
|
-
if (rule.condition.context_field && rule.condition.matches !== undefined) {
|
|
544
|
-
const fieldValue = context[rule.condition.context_field];
|
|
545
|
-
return fieldValue === rule.condition.matches;
|
|
546
|
-
}
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
setNestedField(obj, path, value) {
|
|
550
|
-
const parts = path.split(".");
|
|
551
|
-
let current = obj;
|
|
552
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
553
|
-
const part = parts[i];
|
|
554
|
-
if (current[part] === undefined || current[part] === null) {
|
|
555
|
-
current[part] = {};
|
|
556
|
-
}
|
|
557
|
-
current = current[part];
|
|
558
|
-
}
|
|
559
|
-
current[parts[parts.length - 1]] = value;
|
|
560
|
-
}
|
|
561
|
-
buildEdges(objects, context) {
|
|
562
|
-
const edges = [];
|
|
563
|
-
const find = (name) => objects.find(o => o.name === name);
|
|
564
|
-
const configPrefix = objects[0]?.config?.prefix;
|
|
565
|
-
const prefix = context?.prefix
|
|
566
|
-
?? (typeof configPrefix === "string" ? configPrefix : undefined)
|
|
567
|
-
?? objects[0]?.name.split("_")[0]
|
|
568
|
-
?? "";
|
|
569
|
-
const service = find(`${prefix}_service`);
|
|
570
|
-
const machine = find(`${prefix}_machine`);
|
|
571
|
-
const permission = find(`${prefix}_permission`);
|
|
572
|
-
const allocation = find(`${prefix}_allocation`);
|
|
573
|
-
const treasury = find(`${prefix}_treasury`);
|
|
574
|
-
const arb = find(`${prefix}_arb`);
|
|
575
|
-
const reward = find(`${prefix}_reward`);
|
|
576
|
-
const progress = find(`${prefix}_progress`);
|
|
577
|
-
const allGuards = objects.filter(o => o.object_type === "guard");
|
|
578
|
-
const serviceGuard = allGuards.find(g => g.config?.host === "service");
|
|
579
|
-
const machineGuards = allGuards.filter(g => g.config?.host === "machine");
|
|
580
|
-
if (!service || !machine || !permission) {
|
|
581
|
-
const missing = [];
|
|
582
|
-
if (!service)
|
|
583
|
-
missing.push("service");
|
|
584
|
-
if (!machine)
|
|
585
|
-
missing.push("machine");
|
|
586
|
-
if (!permission)
|
|
587
|
-
missing.push("permission");
|
|
588
|
-
console.warn(`[buildEdges] Missing core objects: ${missing.join(", ")}. ` +
|
|
589
|
-
`Edges will be empty (prefix='${prefix}'). ` +
|
|
590
|
-
`Check buildObjects output or context.prefix.`);
|
|
591
|
-
return edges;
|
|
592
|
-
}
|
|
593
|
-
edges.push(this.makeEdge(service, machine, "machine", "service.machine", true));
|
|
594
|
-
if (serviceGuard) {
|
|
595
|
-
edges.push(this.makeEdge(service, serviceGuard, "buy_guard", "service.buy_guard", true));
|
|
596
|
-
}
|
|
597
|
-
edges.push(this.makeEdge(service, permission, "permission", "service.permission", true));
|
|
598
|
-
if (allocation)
|
|
599
|
-
edges.push(this.makeEdge(service, allocation, "order_allocators", "service.order_allocators", true));
|
|
600
|
-
if (arb)
|
|
601
|
-
edges.push(this.makeEdge(service, arb, "arbitrations", "service.arbitrations", false));
|
|
602
|
-
if (reward)
|
|
603
|
-
edges.push(this.makeEdge(service, reward, "rewards", "service.rewards", false));
|
|
604
|
-
edges.push(this.makeEdge(machine, permission, "permission", "machine.permission", false));
|
|
605
|
-
for (const mg of machineGuards) {
|
|
606
|
-
edges.push(this.makeEdge(machine, mg, "guard", "machine.forwards.guard", false));
|
|
607
|
-
}
|
|
608
|
-
if (progress)
|
|
609
|
-
edges.push(this.makeEdge(progress, machine, "parent", "progress.parent", false));
|
|
610
|
-
if (allocation && treasury)
|
|
611
|
-
edges.push(this.makeEdge(allocation, treasury, "treasury", "allocation.treasury", false));
|
|
612
|
-
if (allocation && serviceGuard)
|
|
613
|
-
edges.push(this.makeEdge(allocation, serviceGuard, "buy_guard", "allocation.guard", false));
|
|
614
|
-
return edges;
|
|
615
|
-
}
|
|
616
|
-
makeEdge(from, to, edge_kind, field_path, required_at_publish) {
|
|
617
|
-
return {
|
|
618
|
-
from: from.entry_id,
|
|
619
|
-
to: to.entry_id,
|
|
620
|
-
edge_kind,
|
|
621
|
-
field_path,
|
|
622
|
-
required_at_publish,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
buildSteps(objects, edges, network) {
|
|
626
|
-
const order = [
|
|
627
|
-
"permission", "guard", "machine", "treasury", "allocation",
|
|
628
|
-
"arb", "reward", "contact", "service", "progress",
|
|
629
|
-
];
|
|
630
|
-
const steps = [];
|
|
631
|
-
const entryToStep = new Map();
|
|
632
|
-
let stepNum = 1;
|
|
633
|
-
for (const type of order) {
|
|
634
|
-
const obj = objects.find(o => o.object_type === type);
|
|
635
|
-
if (!obj)
|
|
636
|
-
continue;
|
|
637
|
-
const depends = [];
|
|
638
|
-
for (const edge of edges) {
|
|
639
|
-
if (edge.to === obj.entry_id) {
|
|
640
|
-
const depStep = entryToStep.get(edge.from);
|
|
641
|
-
if (depStep !== undefined) {
|
|
642
|
-
depends.push(depStep);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
const operation = obj.publish_required ? "publish" : "create";
|
|
647
|
-
steps.push({
|
|
648
|
-
step: stepNum,
|
|
649
|
-
object_type: obj.object_type,
|
|
650
|
-
operation,
|
|
651
|
-
substep_count: 1,
|
|
652
|
-
depends_on: depends,
|
|
653
|
-
entry_id: obj.entry_id,
|
|
654
|
-
network_phase: network,
|
|
655
|
-
});
|
|
656
|
-
entryToStep.set(obj.entry_id, stepNum);
|
|
657
|
-
stepNum++;
|
|
658
|
-
}
|
|
659
|
-
return steps;
|
|
660
|
-
}
|
|
661
|
-
defaultScenarios(mode, intent, objects) {
|
|
662
|
-
const service = objects.find(o => o.object_type === "service");
|
|
663
|
-
return [{
|
|
664
|
-
scenario_id: `${mode.name}_primary`,
|
|
665
|
-
description: `${mode.display_name} main flow: ${intent.slice(0, 80)}`,
|
|
666
|
-
primary_object: service?.entry_id ?? "",
|
|
667
|
-
supporting_objects: objects.filter(o => o.object_type !== "service").map(o => o.entry_id),
|
|
668
|
-
}];
|
|
669
|
-
}
|
|
670
|
-
recordCapabilitiesUsed(mode) {
|
|
671
|
-
if (!mode.capabilities_used)
|
|
672
|
-
return;
|
|
673
|
-
try {
|
|
674
|
-
const registry = CapabilityRegistry.Instance();
|
|
675
|
-
for (const capId of mode.capabilities_used) {
|
|
676
|
-
registry.recordUsage(capId, mode.name);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
catch {
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
deriveGuardShortName(templateId) {
|
|
683
|
-
if (templateId.startsWith("tpl_")) {
|
|
684
|
-
const parts = templateId.split("_");
|
|
685
|
-
return parts[parts.length - 1] || templateId;
|
|
686
|
-
}
|
|
687
|
-
const match = templateId.match(/^([a-z]+)_guard_/);
|
|
688
|
-
if (match)
|
|
689
|
-
return match[1];
|
|
690
|
-
return templateId.split("_")[0] || templateId;
|
|
691
|
-
}
|
|
692
|
-
getFirstServiceGuardName(mode, prefix) {
|
|
693
|
-
const serviceGuard = mode.guards.find(g => g.host === "service");
|
|
694
|
-
if (!serviceGuard)
|
|
695
|
-
return "";
|
|
696
|
-
return `${prefix}_guard_${this.deriveGuardShortName(serviceGuard.template_id)}`;
|
|
697
|
-
}
|
|
698
|
-
makeObject(type, name, config, publish_required = false) {
|
|
699
|
-
return {
|
|
700
|
-
entry_id: `${type}:${name}`,
|
|
701
|
-
object_type: type,
|
|
702
|
-
name,
|
|
703
|
-
config,
|
|
704
|
-
publish_required,
|
|
705
|
-
status: "draft",
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
registerBuiltinModes() {
|
|
709
|
-
for (const mode of BUILTIN_MODES) {
|
|
710
|
-
this.registerMode(mode);
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
export function getIndustryModeRegistry() {
|
|
715
|
-
return IndustryModeRegistry.Instance();
|
|
716
|
-
}
|
|
717
|
-
export const INDUSTRY_MODE_REGISTRY_VERSION = 2.2;
|
|
1
|
+
import{UserModeStorage}from'@wowok/wowok';import{CapabilityRegistry}from'./capability-manifest.js';import{ModeEvaluator}from'./mode-evaluator.js';import{MetricRegistry}from'./metric-registry.js';import{ConstraintRegistry}from'./constraint-registry.js';import{BUILTIN_MODES}from'./modes.js';export class IndustryModeRegistry{static ['instance'];['registrations']=new Map();['userModes']=new Map();['aliases']=new Map();['evaluator'];['initialized']=![];['persistence']=new UserModeStorage();['userModesLoaded']=![];static['Instance'](){return!IndustryModeRegistry['instance']&&(IndustryModeRegistry['instance']=new IndustryModeRegistry()),IndustryModeRegistry['instance'];}constructor(){this['evaluator']=new ModeEvaluator(CapabilityRegistry['Instance'](),MetricRegistry['Instance'](),ConstraintRegistry['Instance']()),this['registerBuiltinModes'](),this['initialized']=!![];}['registerMode'](a,b){if(!a['name']||!a['traits']||!a['machine_shape'])return console['warn']('[IndustryModeRegistry]\x20registerMode\x20rejected:\x20invalid\x20mode\x20'+('(name='+(a['name']||'<missing>')+',\x20traits='+(a['traits']?'ok':'<missing>')+',\x20')+('machine_shape='+(a['machine_shape']?'ok':'<missing>')+').')),![];if(this['registrations']['has'](a['name'])){const c=this['registrations']['get'](a['name']);return console['warn']('[IndustryModeRegistry]\x20registerMode\x20rejected:\x20mode\x20\x27'+a['name']+'\x27\x20already\x20registered\x20'+('(registered_at='+new Date(c?.['registered_at']??0x0)['toISOString']()+').\x20')+'Use\x20evolveMode/deriveMode\x20for\x20user\x20modifications,\x20or\x20unregister\x20first.'),![];}this['registrations']['set'](a['name'],{'mode':a,'aliases':b,'enabled':!![],'registered_at':Date['now']()});if(b)for(const d of b){this['aliases']['set'](d,a['name']);}return!![];}['getMode'](a){const b=this['resolveAlias'](a);return this['registrations']['get'](b)?.['mode'];}['listModes'](){return Array['from'](this['registrations']['values']())['filter'](a=>a['enabled'])['map'](a=>a['mode']);}['resolveAlias'](a){return this['aliases']['get'](a)??a;}['hasMode'](a){const b=this['resolveAlias'](a);return this['registrations']['has'](b);}['evaluateMode'](a,b,c){const d=this['getMode'](a);if(!d)return{'applicable':![],'risk_score':0x64,'benefit_score':0x0,'risk_benefit_ratio':0x0,'capability_conflicts':[],'violated_constraints':[],'unmet_conditions':['Mode\x20\x27'+a+'\x27\x20not\x20found'],'recommendations':['Mode\x20\x27'+a+'\x27\x20not\x20registered,\x20falling\x20back\x20to\x20\x27general\x27']};return this['evaluator']['evaluateMode'](d,b,c);}['evaluateMigration'](a,b){const c=this['getMode'](a),d=this['getMode'](b);if(!c||!d)return{'feasibility_score':0x0,'source_risk_score':0x0,'target_risk_score':0x0,'source_benefit_score':0x0,'target_benefit_score':0x0,'risk_delta':0x0,'benefit_delta':0x0,'added_capabilities':[],'removed_capabilities':[],'conflicting_capabilities':[],'recommendations':['Mode\x20\x27'+a+'\x27\x20or\x20\x27'+b+'\x27\x20not\x20found']};return this['evaluator']['evaluateMigration'](c,d);}async['registerUserMode'](a,b){await this['ensureUserModesLoaded']();if(!a['name']||!a['owner']||!a['machine_shape'])return![];if(a['source']!=='custom')return![];if(a['owner']!==b)return![];const c=this['userModeKey'](a['owner'],a['name']);if(this['registrations']['has'](a['name']))return![];if(this['userModes']['has'](c))return![];return(!a['evolution_history']||a['evolution_history']['length']===0x0)&&(a['evolution_history']=[{'version':a['version']||'v1','changed_at':Date['now'](),'changes':['Initial\x20registration\x20(registerUserMode)']}]),this['userModes']['set'](c,a),await this['persistUserMode'](a),!![];}async['deriveMode'](a,b,c,d,e){await this['ensureUserModesLoaded']();const f=this['getMode'](a);if(!f)return undefined;if(!d||this['registrations']['has'](d))return undefined;const g=this['userModeKey'](c,d);if(this['userModes']['has'](g))return undefined;const h={'name':d,'display_name':e??d,'version':'v1','source':'custom','traits':b['traits']??f['traits'],'machine_shape':b['machine_shape']??f['machine_shape'],'guards':b['guards']??f['guards'],'allocator':b['allocator']??f['allocator'],'risk_checks':b['risk_checks']??f['risk_checks'],'needs':b['needs']??f['needs'],'flywheel':b['flywheel']??f['flywheel'],'key_risk':b['key_risk']??f['key_risk'],'build_notes':b['build_notes']??f['build_notes'],'capabilities_used':b['capabilities_used']??f['capabilities_used'],'config_overrides':b['config_overrides']??f['config_overrides'],'config_override_rules':b['config_override_rules']??f['config_override_rules'],'expected_benefits':b['expected_benefits']??f['expected_benefits'],'risk_appetite':b['risk_appetite']??f['risk_appetite'],'risk_constraints':b['risk_constraints']??f['risk_constraints'],'applicable_conditions':b['applicable_conditions']??f['applicable_conditions'],'similar_industries':b['similar_industries']??f['similar_industries'],'novel_capabilities':b['novel_capabilities']??f['novel_capabilities'],'owner':c,'derived_from':a,'custom_metrics':b['custom_metrics']??f['custom_metrics'],'custom_constraints':b['custom_constraints']??f['custom_constraints'],'evolution_history':[{'version':'v1','changed_at':Date['now'](),'changes':['Derived\x20from\x20builtin\x20\x27'+a+'\x27']}]};return this['userModes']['set'](g,h),await this['persistUserMode'](h),h;}async['evolveMode'](a,b,c,d,e=!![]){await this['ensureUserModesLoaded']();const f=this['userModeKey'](c,a),g=this['userModes']['get'](f);if(!g)return undefined;const h=e?this['bumpPatchVersion'](g['version']):g['version'],i={...g,...b,'name':g['name'],'owner':g['owner'],'source':'custom','derived_from':g['derived_from'],'evolution_history':[...g['evolution_history']??[],{'version':h,'changed_at':Date['now'](),'changes':[d]}],'version':h};return this['userModes']['set'](f,i),await this['persistUserMode'](i),i;}async['listUserModes'](a){await this['ensureUserModesLoaded']();const b=[];for(const c of this['userModes']['values']()){c['owner']===a&&b['push'](c);}return b;}async['getUserMode'](a,b){await this['ensureUserModesLoaded']();const c=this['userModeKey'](b,a);return this['userModes']['get'](c);}async['unregisterUserMode'](a,b){await this['ensureUserModesLoaded']();const c=this['userModeKey'](b,a),d=this['userModes']['delete'](c);return d&&await this['unpersistUserMode'](b,a),d;}['userModeKey'](a,b){return a+':'+b;}async['ensureUserModesLoaded'](){if(this['userModesLoaded'])return;this['userModesLoaded']=!![];try{const a=await this['persistence']['list']();for(const b of a){try{const c=JSON['parse'](b['data']);c?.['name']&&c?.['owner']&&c?.['machine_shape']&&this['userModes']['set'](this['userModeKey'](b['owner'],b['name']),c);}catch{console['warn']('[IndustryModeRegistry]\x20Skipping\x20corrupt\x20user_modes\x20row\x20\x27'+b['owner']+':'+b['name']+'\x27.');}}}catch(d){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20load\x20persisted\x20user\x20modes:',d['message']);}}async['persistUserMode'](a){try{await this['persistence']['save'](a['owner'],a['name'],JSON['stringify'](a));}catch(b){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20persist\x20user\x20mode\x20\x27'+a['owner']+':'+a['name']+'\x27:',b['message']);}}async['unpersistUserMode'](a,b){try{await this['persistence']['delete'](a,b);}catch(c){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20delete\x20persisted\x20user\x20mode\x20\x27'+a+':'+b+'\x27:',c['message']);}}['bumpPatchVersion'](a){const b=a['replace'](/^v/,''),c=b['split']('.');if(c['length']<0x2)return'v'+b+'.1';const d=parseInt(c[0x1]??'0',0xa);return c[0x1]=String(d+0x1),'v'+c['join']('.');}async['applyTemplate'](a,b,c){const d=this['getMode'](a);if(d){const g=this['doApplyTemplate'](d,b,c);return this['recordCapabilitiesUsed'](d),g;}if(a['includes'](':')){const [h,i]=a['split'](':',0x2),j=await this['getUserMode'](i,h);if(j){const k=this['doApplyTemplate'](j,b,c);return this['recordCapabilitiesUsed'](j),k;}}const e=this['getMode']('general');if(!e)throw new Error('IndustryMode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20fallback');const f=this['doApplyTemplate'](e,b,c);return this['recordCapabilitiesUsed'](e),f;}async['applyUserMode'](a,b,c,d){const e=await this['getUserMode'](a,b);if(!e)throw new Error('User\x20mode\x20\x27'+a+'\x27\x20not\x20found\x20for\x20user\x20\x27'+b+'\x27');const f=this['doApplyTemplate'](e,c,d);return this['recordCapabilitiesUsed'](e),f;}['doApplyTemplate'](a,b,c){let d=this['buildObjects'](a,b,c);d=this['applyConfigOverrides'](a,d),d=this['applyConfigOverrideRules'](a,d,b,c);const e=this['buildEdges'](d,c),f=this['buildSteps'](d,e,c['network']),g=this['defaultScenarios'](a,b,d),h=this['validateBlueprint'](d,e,a);if(h['errors']['length']>0x0)throw new Error('Blueprint\x20validation\x20for\x20mode\x20\x27'+a['name']+'\x27\x20failed\x20with\x20'+h['errors']['length']+'\x20CRITICAL\x20error(s):\x0a'+h['errors']['map']((j,k)=>'\x20\x20'+(k+0x1)+'.\x20'+j)['join']('\x0a'));return h['warnings']['length']>0x0&&console['warn']('[IndustryModeRegistry]\x20Blueprint\x20validation\x20for\x20\x27'+a['name']+'\x27\x20produced\x20'+h['warnings']['length']+'\x20warning(s):',h['warnings']),{'context':c,'objects':d,'edges':e,'steps':f,'scenarios':g,'industry_source':a['name'],'applied_template':a['name']+'@'+a['version'],'validation':h};}['validateBlueprint'](a,b,c){const d=[],e=[],f=a['find'](j=>j['object_type']==='machine'),g=a['find'](j=>j['object_type']==='service');if(f){const j=f['config']['entry_node_forward_hint'];if(!j)e['push']('Machine\x20blueprint\x20missing\x20entry_node_forward_hint.\x20'+'The\x20AI\x20must\x20ensure\x20the\x20entry\x20node\x20(prev_node=\x27\x27)\x20has\x20≥1\x20forward\x20when\x20constructing\x20the\x20Machine\x20creation\x20call\x20(P0-2).');else j['required']===!![]&&!j['example_forward']&&e['push']('Machine\x20entry_node_forward_hint\x20marked\x20required\x20but\x20example_forward\x20is\x20missing.');const k=f['config']['nodes'];(!k||k['length']===0x0)&&d['push']('Machine\x20blueprint\x20has\x20no\x20nodes\x20—\x20mode\x20\x27'+c['name']+'\x27\x20machine_shape\x20is\x20empty.\x20'+'Add\x20nodes\x20to\x20the\x20mode\x27s\x20machine_shape\x20before\x20applying\x20template.');}if(g){const l=g['config']['compensation_fund'];l&&d['push']('Service\x20blueprint\x20has\x20compensation_fund=\x27'+l+'\x27\x20(string\x20reference).\x20'+'BUG:\x20compensation_fund\x20is\x20Balance<T>\x20(numeric),\x20NOT\x20a\x20Treasury\x20object\x20reference.\x20'+'Remove\x20compensation_fund\x20field\x20and\x20use\x20compensation_fund_balance\x20+\x20compensation_fund_add_hint\x20instead.\x20'+'Smart\x20contract\x20(service.move:179):\x20compensation_fund:\x20Balance<T>.');const m=g['config']['compensation_fund_balance'];m===undefined&&e['push']('Service\x20blueprint\x20missing\x20compensation_fund_balance.\x20'+'Should\x20be\x200\x20(initial\x20Balance<T>\x20state)\x20—\x20filled\x20via\x20service.compensation_fund_add(coin).');}const h=new Set(a['map'](n=>n['entry_id'])),i=new Set(a['map'](n=>n['name']));for(const n of b){const o=h['has'](n['from'])||i['has'](n['from']),p=h['has'](n['to'])||i['has'](n['to']);(!o||!p)&&d['push']('Edge\x20\x27'+n['from']+'\x27\x20→\x20\x27'+n['to']+'\x27\x20(kind=\x27'+n['edge_kind']+'\x27)\x20references\x20undefined\x20object.\x20'+('from_exists='+o+',\x20to_exists='+p+'.'));}return{'errors':d,'warnings':e};}['buildObjects'](a,b,c){const d=c['prefix'],e=[];e['push'](this['makeObject']('permission',d+'_permission',{'name':d+'_permission','description':'Permission:\x20role\x20permission\x20index\x20('+a['display_name']+')','permission_indexes':this['buildPermissionIndexes'](a),'tags':['industry:'+a['name']]}));const f=this['getFirstServiceGuardName'](a,d);for(const g of a['guards']){const h=this['deriveGuardShortName'](g['template_id']),i=d+'_guard_'+h;e['push'](this['makeObject']('guard',i,{'name':i,'description':'Guard:\x20'+g['purpose']+'\x20('+a['display_name']+')','host':g['host'],'template_id':g['template_id'],'tags':['industry:'+a['name'],'host:'+g['host']]}));}return e['push'](this['makeObject']('machine',d+'_machine',{'name':d+'_machine','description':'Machine:\x20workflow\x20topology\x20('+a['display_name']+')\x20—\x20'+a['machine_shape']['length']+'\x20nodes','nodes':a['machine_shape']['map'](j=>({'name':j['name'],'role':j['role']})),'guard_objects':a['guards']['filter'](j=>j['host']==='machine')['map'](j=>({'template_id':j['template_id'],'object_name':d+'_guard_'+this['deriveGuardShortName'](j['template_id']),'purpose':j['purpose']})),'permission':d+'_permission','entry_node_forward_hint':{'entry_node_name':a['machine_shape'][0x0]?.['name']??'paid','required':!![],'example_forward':{'next_node':a['machine_shape'][0x0]?.['name']??'paid','namedOperator':'','weight':0x1},'reason':'Progress\x20starts\x20at\x20current=\x27\x27\x20and\x20follows\x20the\x20entry\x20node\x27s\x20forwards.\x20'+'Without\x20a\x20forward,\x20Progress\x20is\x20permanently\x20stuck\x20(P0-2).\x20'+'Schema\x20refinement\x20in\x20MachineNodePairSchema\x20enforces\x20this\x20at\x20publish\x20time.'},'tags':['industry:'+a['name']]},!![])),e['push'](this['makeObject']('treasury',d+'_treasury',{'name':d+'_treasury','description':'Treasury:\x20fund\x20escrow\x20('+a['display_name']+')','owner_receive':!![],'tags':['industry:'+a['name']]})),e['push'](this['makeObject']('allocation',d+'_allocation',{'name':d+'_allocation','description':'Allocation:\x20allocation\x20strategy\x20('+a['display_name']+')\x20—\x20'+a['allocator']['description'],'strategy':a['allocator'],'treasury':d+'_treasury','guard':f,'tags':['industry:'+a['name']]})),e['push'](this['makeObject']('service',d+'_service',{'name':d+'_service','description':'Service:\x20business\x20service\x20('+a['display_name']+')\x20—\x20'+b['slice'](0x0,0x64),'machine':d+'_machine','buy_guard':f,'permission':d+'_permission','order_allocators':[d+'_allocation'],'compensation_fund_balance':0x0,'compensation_fund_required':a['risk_constraints']?.['require_compensation_fund']??![],'compensation_fund_coverage_ratio':a['risk_constraints']?.['compensation_fund_coverage_ratio']??0x5,'compensation_fund_add_hint':'Call\x20service.compensation_fund_add\x20with\x20a\x20Coin<T>\x20to\x20deposit.\x20'+'The\x20compensation_fund\x20is\x20a\x20Balance<T>\x20(numeric),\x20not\x20a\x20Treasury\x20object\x20reference.\x20'+'Without\x20deposit,\x20arbitration\x20rulings\x20that\x20award\x20refunds\x20to\x20buyers\x20cannot\x20be\x20paid\x20out.\x20'+('Recommend\x20'+(a['risk_constraints']?.['compensation_fund_coverage_ratio']??0x5)+'×\x20the\x20max\x20single-order\x20amount\x20(P1-1\x20evaluation\x20rule,\x20industry:\x20'+a['name']+').'),'arbitrations':[d+'_arb'],'rewards':[d+'_reward'],'business_intent':b,'industry':a['name'],'tags':['industry:'+a['name']]},!![])),e['push'](this['makeObject']('progress',d+'_progress',{'name':d+'_progress','description':'Progress:\x20order\x20fulfillment\x20progress\x20('+a['display_name']+')','parent':d+'_machine','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('arb',d+'_arb',{'name':d+'_arb','description':'Arbitration:\x20arbitration\x20rules\x20('+a['display_name']+')\x20—\x20'+a['key_risk'],'guard':d+'_guard_buy','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('reward',d+'_reward',{'name':d+'_reward','description':'Reward:\x20incentive\x20rules\x20('+a['display_name']+')','claim_guard':d+'_guard_buy','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('contact',d+'_contact',{'name':d+'_contact','description':'Contact:\x20customer\x20service\x20contact\x20('+a['display_name']+')','tags':['industry:'+a['name']]})),e;}['buildPermissionIndexes'](a){const b=a['config_overrides']?.['permission'];if(b?.['permission_indexes'])return b['permission_indexes'];return[{'name':'merchant','description':'Service\x20owner\x20/\x20provider'},{'name':'customer','description':'Service\x20buyer\x20/\x20customer'},{'name':'arbiter','description':'Arbitration\x20arbiter'}];}['applyConfigOverrides'](a,b){if(!a['config_overrides'])return b;for(const c of b){const d=a['config_overrides'][c['object_type']];if(d)for(const [e,f]of Object['entries'](d)){c['config'][e]=f;}}return b;}['applyConfigOverrideRules'](a,b,c,d){if(!a['config_override_rules'])return b;for(const e of a['config_override_rules']){const f=b['find'](h=>h['object_type']===e['object_type']);if(!f)continue;let g;if(e['condition']){const h=this['evaluateCondition'](e,c,d);g=h?e['condition']['then_value']:e['condition']['else_value']??e['value'];}else g=e['value'];g!==undefined&&this['setNestedField'](f['config'],e['field_path'],g);}return b;}['evaluateCondition'](a,b,c){if(!a['condition'])return![];if(a['condition']['intent_contains'])return b['toLowerCase']()['includes'](a['condition']['intent_contains']['toLowerCase']());if(a['condition']['context_field']&&a['condition']['matches']!==undefined){const d=c[a['condition']['context_field']];return d===a['condition']['matches'];}return![];}['setNestedField'](a,b,c){const d=b['split']('.');let e=a;for(let f=0x0;f<d['length']-0x1;f++){const g=d[f];(e[g]===undefined||e[g]===null)&&(e[g]={}),e=e[g];}e[d[d['length']-0x1]]=c;}['buildEdges'](a,b){const c=[],d=r=>a['find'](s=>s['name']===r),e=a[0x0]?.['config']?.['prefix'],f=b?.['prefix']??(typeof e==='string'?e:undefined)??a[0x0]?.['name']['split']('_')[0x0]??'',g=d(f+'_service'),h=d(f+'_machine'),i=d(f+'_permission'),j=d(f+'_allocation'),k=d(f+'_treasury'),l=d(f+'_arb'),m=d(f+'_reward'),n=d(f+'_progress'),o=a['filter'](r=>r['object_type']==='guard'),p=o['find'](r=>r['config']?.['host']==='service'),q=o['filter'](r=>r['config']?.['host']==='machine');if(!g||!h||!i){const r=[];if(!g)r['push']('service');if(!h)r['push']('machine');if(!i)r['push']('permission');return console['warn']('[buildEdges]\x20Missing\x20core\x20objects:\x20'+r['join'](',\x20')+'.\x20'+('Edges\x20will\x20be\x20empty\x20(prefix=\x27'+f+'\x27).\x20')+'Check\x20buildObjects\x20output\x20or\x20context.prefix.'),c;}c['push'](this['makeEdge'](g,h,'machine','service.machine',!![]));p&&c['push'](this['makeEdge'](g,p,'buy_guard','service.buy_guard',!![]));c['push'](this['makeEdge'](g,i,'permission','service.permission',!![]));if(j)c['push'](this['makeEdge'](g,j,'order_allocators','service.order_allocators',!![]));if(l)c['push'](this['makeEdge'](g,l,'arbitrations','service.arbitrations',![]));if(m)c['push'](this['makeEdge'](g,m,'rewards','service.rewards',![]));c['push'](this['makeEdge'](h,i,'permission','machine.permission',![]));for(const s of q){c['push'](this['makeEdge'](h,s,'guard','machine.forwards.guard',![]));}if(n)c['push'](this['makeEdge'](n,h,'parent','progress.parent',![]));if(j&&k)c['push'](this['makeEdge'](j,k,'treasury','allocation.treasury',![]));if(j&&p)c['push'](this['makeEdge'](j,p,'buy_guard','allocation.guard',![]));return c;}['makeEdge'](a,b,c,d,e){return{'from':a['entry_id'],'to':b['entry_id'],'edge_kind':c,'field_path':d,'required_at_publish':e};}['buildSteps'](a,b,c){const d=['permission','guard','machine','treasury','allocation','arb','reward','contact','service','progress'],e=[],f=new Map();let g=0x1;for(const h of d){const i=a['find'](l=>l['object_type']===h);if(!i)continue;const j=[];for(const l of b){if(l['to']===i['entry_id']){const m=f['get'](l['from']);m!==undefined&&j['push'](m);}}const k=i['publish_required']?'publish':'create';e['push']({'step':g,'object_type':i['object_type'],'operation':k,'substep_count':0x1,'depends_on':j,'entry_id':i['entry_id'],'network_phase':c}),f['set'](i['entry_id'],g),g++;}return e;}['defaultScenarios'](a,b,c){const d=c['find'](e=>e['object_type']==='service');return[{'scenario_id':a['name']+'_primary','description':a['display_name']+'\x20main\x20flow:\x20'+b['slice'](0x0,0x50),'primary_object':d?.['entry_id']??'','supporting_objects':c['filter'](e=>e['object_type']!=='service')['map'](e=>e['entry_id'])}];}['recordCapabilitiesUsed'](a){if(!a['capabilities_used'])return;try{const b=CapabilityRegistry['Instance']();for(const c of a['capabilities_used']){b['recordUsage'](c,a['name']);}}catch{}}['deriveGuardShortName'](a){if(a['startsWith']('tpl_')){const c=a['split']('_');return c[c['length']-0x1]||a;}const b=a['match'](/^([a-z]+)_guard_/);if(b)return b[0x1];return a['split']('_')[0x0]||a;}['getFirstServiceGuardName'](a,b){const c=a['guards']['find'](d=>d['host']==='service');if(!c)return'';return b+'_guard_'+this['deriveGuardShortName'](c['template_id']);}['makeObject'](a,b,c,d=![]){return{'entry_id':a+':'+b,'object_type':a,'name':b,'config':c,'publish_required':d,'status':'draft'};}['registerBuiltinModes'](){for(const a of BUILTIN_MODES){this['registerMode'](a);}}}export function getIndustryModeRegistry(){return IndustryModeRegistry['Instance']();}export const INDUSTRY_MODE_REGISTRY_VERSION=2.2;
|