@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,681 +1 @@
|
|
|
1
|
-
import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
|
|
2
|
-
export function assembleServiceBasics(serviceId, raw, wipVerified = false) {
|
|
3
|
-
const activeSales = (raw.sales ?? []).filter((s) => !s.suspension);
|
|
4
|
-
const hasWip = activeSales.some((s) => s.wip_hash && s.wip_hash.length > 0);
|
|
5
|
-
return {
|
|
6
|
-
service_id: serviceId,
|
|
7
|
-
name: raw.name ?? serviceId,
|
|
8
|
-
bPublished: raw.bPublished ?? false,
|
|
9
|
-
bPaused: raw.bPaused ?? false,
|
|
10
|
-
price: raw.price ?? "0",
|
|
11
|
-
price_raw: raw.priceRaw ?? 0n,
|
|
12
|
-
token_type: raw.token_type ?? "0x2::wow::WOW",
|
|
13
|
-
sales_count: activeSales.length,
|
|
14
|
-
machine_id: raw.machine,
|
|
15
|
-
buy_guard_id: raw.buy_guard,
|
|
16
|
-
customer_required_count: raw.customer_required?.length ?? 0,
|
|
17
|
-
customer_required: (raw.customer_required ?? []).filter((x) => typeof x === "string"),
|
|
18
|
-
arbitrations_count: raw.arbitrations?.length ?? 0,
|
|
19
|
-
compensation_fund_balance: raw.compensation_fund?.balance ?? 0n,
|
|
20
|
-
compensation_lock_duration: raw.compensation_lock_duration ?? 0,
|
|
21
|
-
um_id: raw.um,
|
|
22
|
-
has_wip: hasWip,
|
|
23
|
-
wip_verified: wipVerified,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export function assembleWorkflowAnalysis(nodes, isPublished, isPaused, serviceRaw) {
|
|
27
|
-
const riskSignals = [];
|
|
28
|
-
const terminalNodes = [];
|
|
29
|
-
const deadEndNodes = [];
|
|
30
|
-
let userOperable = 0;
|
|
31
|
-
let providerOnly = 0;
|
|
32
|
-
let guardGated = 0;
|
|
33
|
-
let hasMilestone = false;
|
|
34
|
-
let hasWonderNode = false;
|
|
35
|
-
let hasDisputeAntiPattern = false;
|
|
36
|
-
const antiPatternNodeRegex = /(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;
|
|
37
|
-
const wonderNodeRegex = /^(wonder|no_wonder|praise|complain|thumbs_up|thumbs_down|positive_review|negative_review)$/i;
|
|
38
|
-
const totalForwards = nodes.reduce((sum, n) => sum + (n.forwards?.length ?? 0), 0);
|
|
39
|
-
for (const node of nodes) {
|
|
40
|
-
if (antiPatternNodeRegex.test(node.name.trim())) {
|
|
41
|
-
hasDisputeAntiPattern = true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
for (const node of nodes) {
|
|
45
|
-
const outForwards = node.forwards ?? [];
|
|
46
|
-
if (outForwards.length === 0) {
|
|
47
|
-
terminalNodes.push(node.name);
|
|
48
|
-
}
|
|
49
|
-
for (const fwd of outForwards) {
|
|
50
|
-
const op = fwd.namedOperator;
|
|
51
|
-
const guard = fwd.guard;
|
|
52
|
-
if (op === "") {
|
|
53
|
-
if (guard) {
|
|
54
|
-
guardGated++;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
userOperable++;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if (op === null || op === undefined) {
|
|
61
|
-
providerOnly++;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
providerOnly++;
|
|
65
|
-
}
|
|
66
|
-
const target = (fwd.to ?? "").trim().toLowerCase();
|
|
67
|
-
if (wonderNodeRegex.test(target)) {
|
|
68
|
-
hasWonderNode = true;
|
|
69
|
-
}
|
|
70
|
-
if (target.includes("milestone")) {
|
|
71
|
-
hasMilestone = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
for (const node of nodes) {
|
|
76
|
-
const outForwards = node.forwards ?? [];
|
|
77
|
-
if (outForwards.length > 0 && !terminalNodes.includes(node.name)) {
|
|
78
|
-
const allProviderOnly = outForwards.every((f) => f.namedOperator !== "" && f.namedOperator !== null);
|
|
79
|
-
if (allProviderOnly && userOperable === 0) {
|
|
80
|
-
deadEndNodes.push(node.name);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const hasArbitrationBinding = (serviceRaw?.arbitrations?.length ?? 0) > 0;
|
|
85
|
-
const compBalance = serviceRaw?.compensation_fund?.balance ?? 0n;
|
|
86
|
-
const hasArbRefundPath = hasArbitrationBinding && compBalance > 0n;
|
|
87
|
-
const allocators = serviceRaw?.order_allocators?.[0]?.allocators ?? [];
|
|
88
|
-
const hasRefundAllocator = allocators.some((a) => a.surplus_to === "order" || a.surplus_to === "Order");
|
|
89
|
-
const hasRefundPath = hasArbRefundPath || hasRefundAllocator;
|
|
90
|
-
if (!hasRefundPath)
|
|
91
|
-
riskSignals.push("no_refund_path");
|
|
92
|
-
if (!hasArbitrationBinding)
|
|
93
|
-
riskSignals.push("no_arbitration_binding");
|
|
94
|
-
if (hasDisputeAntiPattern)
|
|
95
|
-
riskSignals.push("dispute_anti_pattern");
|
|
96
|
-
if (userOperable === 0)
|
|
97
|
-
riskSignals.push("no_user_operable_path");
|
|
98
|
-
if (deadEndNodes.length > 0)
|
|
99
|
-
riskSignals.push("potential_dead_ends");
|
|
100
|
-
return {
|
|
101
|
-
machine_published: isPublished,
|
|
102
|
-
machine_paused: isPaused,
|
|
103
|
-
total_nodes: nodes.length,
|
|
104
|
-
total_forwards: totalForwards,
|
|
105
|
-
user_operable_forwards: userOperable,
|
|
106
|
-
provider_only_forwards: providerOnly,
|
|
107
|
-
guard_gated_forwards: guardGated,
|
|
108
|
-
has_refund_path: hasRefundPath,
|
|
109
|
-
has_arbitration_path: hasArbitrationBinding,
|
|
110
|
-
has_arbitration_binding: hasArbitrationBinding,
|
|
111
|
-
has_wonder_node: hasWonderNode,
|
|
112
|
-
has_dispute_anti_pattern: hasDisputeAntiPattern,
|
|
113
|
-
has_milestone_nodes: hasMilestone,
|
|
114
|
-
dead_end_nodes: deadEndNodes,
|
|
115
|
-
terminal_nodes: terminalNodes,
|
|
116
|
-
risk_signals: riskSignals,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
export function assembleFundSafety(raw, orderAmount) {
|
|
120
|
-
const allocators = raw.order_allocators?.[0]?.allocators ?? [];
|
|
121
|
-
const compBalance = raw.compensation_fund?.balance ?? 0n;
|
|
122
|
-
const lockDuration = raw.compensation_lock_duration ?? 0;
|
|
123
|
-
const refundAllocator = allocators.find((a) => {
|
|
124
|
-
const amt = a.amount;
|
|
125
|
-
return amt?.type === "FixedValue" && amt.value === orderAmount;
|
|
126
|
-
});
|
|
127
|
-
const hasRefundAllocator = allocators.some((a) => a.surplus_to === "order" || a.surplus_to === "Order");
|
|
128
|
-
let priceAnomaly = "none";
|
|
129
|
-
if (orderAmount > 0n) {
|
|
130
|
-
if (compBalance > 0n && orderAmount > compBalance * 3n) {
|
|
131
|
-
priceAnomaly = "low";
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const lockSafe = lockDuration === 0 || lockDuration > 7;
|
|
135
|
-
return {
|
|
136
|
-
has_order_allocator: allocators.length > 0,
|
|
137
|
-
has_refund_allocator: !!refundAllocator || hasRefundAllocator,
|
|
138
|
-
allocator_count: allocators.length,
|
|
139
|
-
refund_allocator_exists: hasRefundAllocator,
|
|
140
|
-
surplus_to_provider: allocators.some((a) => a.surplus_to !== "order" && a.surplus_to !== "Order"),
|
|
141
|
-
user_path_has_allocator: allocators.length > 0,
|
|
142
|
-
compensation_covers_order: compBalance >= orderAmount,
|
|
143
|
-
compensation_ratio: orderAmount > 0n
|
|
144
|
-
? Math.min(1, Number((compBalance * 100n) / orderAmount) / 100)
|
|
145
|
-
: 0,
|
|
146
|
-
lock_duration_safe: lockSafe,
|
|
147
|
-
price_anomaly: priceAnomaly,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
export function assembleTrustSignals(service, reviews, trustScore, arbitrationOwner, serviceOwner, permissionShared, permissionOverlap) {
|
|
151
|
-
const likes = reviews.filter((r) => r.rating === "like").length;
|
|
152
|
-
const dislikes = reviews.filter((r) => r.rating === "dislike").length;
|
|
153
|
-
const verified = reviews.filter((r) => r.verified || r.has_evidence).length;
|
|
154
|
-
const total = reviews.length;
|
|
155
|
-
const likeRate = total > 0 ? likes / total : 0;
|
|
156
|
-
const arbitrationIndependent = arbitrationOwner !== undefined && serviceOwner !== undefined
|
|
157
|
-
? arbitrationOwner !== serviceOwner
|
|
158
|
-
: true;
|
|
159
|
-
return {
|
|
160
|
-
arbitration_independent: arbitrationIndependent,
|
|
161
|
-
arbitration_count: service.arbitrations?.length ?? 0,
|
|
162
|
-
arbitration_paused: false,
|
|
163
|
-
review_likes: likes,
|
|
164
|
-
review_dislikes: dislikes,
|
|
165
|
-
review_verified_count: verified,
|
|
166
|
-
review_total: total,
|
|
167
|
-
like_rate: likeRate,
|
|
168
|
-
trust_score: trustScore.score,
|
|
169
|
-
trust_level: trustScore.level,
|
|
170
|
-
has_contact: !!service.um,
|
|
171
|
-
has_messenger: !!service.um,
|
|
172
|
-
arbitration_permission_shared: permissionShared,
|
|
173
|
-
arbitration_permission_overlap: permissionOverlap,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
const REPUTATION_MIN_VOTES = 3;
|
|
177
|
-
function toReputation(rep) {
|
|
178
|
-
const total = rep.likes + rep.dislikes;
|
|
179
|
-
return {
|
|
180
|
-
likes: rep.likes,
|
|
181
|
-
dislikes: rep.dislikes,
|
|
182
|
-
like_ratio: total > 0 ? rep.likes / total : 1,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
function reputationRedFlags(rep) {
|
|
186
|
-
if (!rep)
|
|
187
|
-
return [];
|
|
188
|
-
const total = rep.likes + rep.dislikes;
|
|
189
|
-
if (total >= REPUTATION_MIN_VOTES && rep.like_ratio < 0.5) {
|
|
190
|
-
return ["reputation_negative"];
|
|
191
|
-
}
|
|
192
|
-
return [];
|
|
193
|
-
}
|
|
194
|
-
export function assembleMerchantBehavior(events, orderHistory, reputation) {
|
|
195
|
-
const rep = reputation ? toReputation(reputation) : undefined;
|
|
196
|
-
const repFlags = reputationRedFlags(rep);
|
|
197
|
-
if (orderHistory && orderHistory.length > 0) {
|
|
198
|
-
const total = orderHistory.length;
|
|
199
|
-
const completed = orderHistory.filter((o) => o.status === "completed").length;
|
|
200
|
-
const disputed = orderHistory.filter((o) => o.has_dispute).length;
|
|
201
|
-
const repeated = orderHistory.filter((o) => o.is_repeat).length;
|
|
202
|
-
const completedRate = total > 0 ? completed / total : 0;
|
|
203
|
-
const disputeRate = total > 0 ? disputed / total : 0;
|
|
204
|
-
const repeatRate = total > 0 ? repeated / total : 0;
|
|
205
|
-
const half = Math.floor(total / 2);
|
|
206
|
-
let trend = "stable";
|
|
207
|
-
if (total >= 4 && half > 0) {
|
|
208
|
-
const firstHalfDisputes = orderHistory.slice(0, half).filter((o) => o.has_dispute).length;
|
|
209
|
-
const secondHalfDisputes = orderHistory.slice(half).filter((o) => o.has_dispute).length;
|
|
210
|
-
const firstRate = firstHalfDisputes / half;
|
|
211
|
-
const secondRate = secondHalfDisputes / (total - half);
|
|
212
|
-
if (secondRate < firstRate * 0.85)
|
|
213
|
-
trend = "improving";
|
|
214
|
-
else if (secondRate > firstRate * 1.15)
|
|
215
|
-
trend = "declining";
|
|
216
|
-
}
|
|
217
|
-
const redFlags = [...repFlags];
|
|
218
|
-
if (disputeRate > 0.1)
|
|
219
|
-
redFlags.push("dispute_rate_high");
|
|
220
|
-
if (trend === "declining")
|
|
221
|
-
redFlags.push("declining_trend");
|
|
222
|
-
return {
|
|
223
|
-
total_orders: total,
|
|
224
|
-
completed_rate: completedRate,
|
|
225
|
-
dispute_rate: disputeRate,
|
|
226
|
-
refund_rate: 0,
|
|
227
|
-
arb_loss_rate: 0,
|
|
228
|
-
repeat_buyer_rate: repeatRate,
|
|
229
|
-
recent_trend: trend,
|
|
230
|
-
red_flags: redFlags,
|
|
231
|
-
reputation: rep,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
const orderEvents = events.filter((e) => e.type.includes("Order") || e.type.includes("order"));
|
|
235
|
-
const disputeEvents = events.filter((e) => e.type.includes("Dispute") || e.type.includes("Arb"));
|
|
236
|
-
const total = orderEvents.length;
|
|
237
|
-
const disputes = disputeEvents.length;
|
|
238
|
-
const disputeRate = total > 0 ? disputes / total : 0;
|
|
239
|
-
const redFlags = [...repFlags];
|
|
240
|
-
if (disputeRate > 0.1)
|
|
241
|
-
redFlags.push("dispute_rate_high");
|
|
242
|
-
return {
|
|
243
|
-
total_orders: total,
|
|
244
|
-
completed_rate: total > 0 ? Math.max(0, 1 - disputeRate) : 0,
|
|
245
|
-
dispute_rate: disputeRate,
|
|
246
|
-
refund_rate: 0,
|
|
247
|
-
arb_loss_rate: 0,
|
|
248
|
-
repeat_buyer_rate: 0,
|
|
249
|
-
recent_trend: "stable",
|
|
250
|
-
red_flags: redFlags,
|
|
251
|
-
reputation: rep,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
export function assembleMarketContext(similarServices, currentPrice) {
|
|
255
|
-
if (similarServices.length === 0) {
|
|
256
|
-
return {
|
|
257
|
-
similar_services_count: 0,
|
|
258
|
-
avg_price: 0n,
|
|
259
|
-
min_price: 0n,
|
|
260
|
-
max_price: 0n,
|
|
261
|
-
price_percentile: 0,
|
|
262
|
-
supply_demand_ratio: 0,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
const prices = similarServices.map((s) => s.price).sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
266
|
-
const sum = prices.reduce((acc, p) => acc + p, 0n);
|
|
267
|
-
const avg = sum / BigInt(prices.length);
|
|
268
|
-
const min = prices[0];
|
|
269
|
-
const max = prices[prices.length - 1];
|
|
270
|
-
let below = 0;
|
|
271
|
-
for (const p of prices) {
|
|
272
|
-
if (p < currentPrice)
|
|
273
|
-
below++;
|
|
274
|
-
}
|
|
275
|
-
const percentile = prices.length > 0 ? below / prices.length : 0;
|
|
276
|
-
return {
|
|
277
|
-
similar_services_count: similarServices.length,
|
|
278
|
-
avg_price: avg,
|
|
279
|
-
min_price: min,
|
|
280
|
-
max_price: max,
|
|
281
|
-
price_percentile: percentile,
|
|
282
|
-
supply_demand_ratio: similarServices.length,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
export function assembleInfoPuzzle(serviceId, raw, depth = "evaluate") {
|
|
286
|
-
const gaps = [];
|
|
287
|
-
const serviceBasics = assembleServiceBasics(serviceId, raw.service, raw.wip_verified ?? false);
|
|
288
|
-
let workflowAnalysis;
|
|
289
|
-
let fundSafety;
|
|
290
|
-
let trustSignals;
|
|
291
|
-
if (depth === "evaluate" || depth === "preorder" || depth === "monitor") {
|
|
292
|
-
if (raw.machine_nodes) {
|
|
293
|
-
workflowAnalysis = assembleWorkflowAnalysis(raw.machine_nodes, raw.machine_published ?? false, raw.machine_paused ?? false, raw.service);
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
gaps.push("machine_workflow");
|
|
297
|
-
}
|
|
298
|
-
const orderAmount = raw.order_amount ?? serviceBasics.price_raw;
|
|
299
|
-
fundSafety = assembleFundSafety(raw.service, orderAmount);
|
|
300
|
-
if (raw.reviews && raw.trust_score) {
|
|
301
|
-
trustSignals = assembleTrustSignals(raw.service, raw.reviews, raw.trust_score, raw.arbitration_owner, raw.service_owner);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
gaps.push("reviews_or_trust_score");
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
let merchantBehavior;
|
|
308
|
-
if (depth === "preorder" || depth === "monitor") {
|
|
309
|
-
if (raw.events || raw.order_history) {
|
|
310
|
-
merchantBehavior = assembleMerchantBehavior(raw.events ?? [], raw.order_history, raw.merchant_reputation);
|
|
311
|
-
}
|
|
312
|
-
else if (raw.merchant_reputation) {
|
|
313
|
-
merchantBehavior = assembleMerchantBehavior([], undefined, raw.merchant_reputation);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
gaps.push("merchant_behavior");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
let marketContext;
|
|
320
|
-
if (depth === "evaluate" || depth === "preorder") {
|
|
321
|
-
if (raw.similar_services) {
|
|
322
|
-
marketContext = assembleMarketContext(raw.similar_services, serviceBasics.price_raw);
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
gaps.push("market_context");
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
let userMetrics;
|
|
329
|
-
if (raw.user_metrics_config && raw.user_metrics_config.metrics.length > 0) {
|
|
330
|
-
userMetrics = assembleUserMetrics(raw.user_metrics_config, raw.user_metrics_context ?? {});
|
|
331
|
-
}
|
|
332
|
-
let serviceNesting = raw.service_nesting;
|
|
333
|
-
if (!serviceNesting && raw.service_nesting_raw) {
|
|
334
|
-
serviceNesting = evaluateServiceNesting(raw.service_nesting_raw);
|
|
335
|
-
}
|
|
336
|
-
return {
|
|
337
|
-
service_id: serviceId,
|
|
338
|
-
service_basics: serviceBasics,
|
|
339
|
-
workflow_analysis: workflowAnalysis,
|
|
340
|
-
fund_safety: fundSafety,
|
|
341
|
-
trust_signals: trustSignals,
|
|
342
|
-
merchant_behavior: merchantBehavior,
|
|
343
|
-
market_context: marketContext,
|
|
344
|
-
user_metrics: userMetrics,
|
|
345
|
-
service_nesting: serviceNesting,
|
|
346
|
-
completeness: computeCompleteness(depth, [
|
|
347
|
-
serviceBasics,
|
|
348
|
-
workflowAnalysis,
|
|
349
|
-
fundSafety,
|
|
350
|
-
trustSignals,
|
|
351
|
-
merchantBehavior,
|
|
352
|
-
marketContext,
|
|
353
|
-
userMetrics,
|
|
354
|
-
serviceNesting,
|
|
355
|
-
]),
|
|
356
|
-
gaps,
|
|
357
|
-
assembled_at: Date.now(),
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
export function assembleUserMetrics(config, context) {
|
|
361
|
-
const cap = config.adjustment_cap ?? 10;
|
|
362
|
-
const results = [];
|
|
363
|
-
const totalWeight = config.metrics.reduce((sum, m) => sum + Math.max(0, m.weight), 0);
|
|
364
|
-
for (const metric of config.metrics) {
|
|
365
|
-
const normalizedWeight = totalWeight > 0 ? Math.max(0, metric.weight) / totalWeight : 0;
|
|
366
|
-
const observed = resolvePath(context, metric.params.path ?? metric.name);
|
|
367
|
-
const { passed, score, observed_value } = evaluateMetric(metric, observed);
|
|
368
|
-
results.push({
|
|
369
|
-
name: metric.name,
|
|
370
|
-
label: metric.label,
|
|
371
|
-
passed,
|
|
372
|
-
score,
|
|
373
|
-
observed_value: formatObservedValue(observed),
|
|
374
|
-
weight: normalizedWeight,
|
|
375
|
-
advice: passed
|
|
376
|
-
? metric.advice_on_pass
|
|
377
|
-
: metric.advice_on_fail,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
const aggregated = results.reduce((sum, r) => sum + r.score * r.weight, 0);
|
|
381
|
-
const score = Math.round(aggregated * 100);
|
|
382
|
-
const adjustment = Math.round(((score - 50) / 50) * cap);
|
|
383
|
-
return {
|
|
384
|
-
metrics: results,
|
|
385
|
-
score,
|
|
386
|
-
adjustment,
|
|
387
|
-
source_file: config.source_file,
|
|
388
|
-
evaluated_at: Date.now(),
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
function resolvePath(obj, path) {
|
|
392
|
-
if (!path)
|
|
393
|
-
return undefined;
|
|
394
|
-
const parts = path.split(".");
|
|
395
|
-
let current = obj;
|
|
396
|
-
for (const part of parts) {
|
|
397
|
-
if (current === null || current === undefined)
|
|
398
|
-
return undefined;
|
|
399
|
-
if (typeof current !== "object")
|
|
400
|
-
return undefined;
|
|
401
|
-
current = current[part];
|
|
402
|
-
}
|
|
403
|
-
return current;
|
|
404
|
-
}
|
|
405
|
-
function evaluateMetric(metric, observed) {
|
|
406
|
-
const p = metric.params;
|
|
407
|
-
switch (metric.evaluator) {
|
|
408
|
-
case "threshold": {
|
|
409
|
-
const v = typeof observed === "number" ? observed
|
|
410
|
-
: typeof observed === "string" ? Number(observed)
|
|
411
|
-
: typeof observed === "bigint" ? Number(observed)
|
|
412
|
-
: NaN;
|
|
413
|
-
const threshold = typeof p.threshold === "number" ? p.threshold
|
|
414
|
-
: typeof p.threshold === "string" ? Number(p.threshold)
|
|
415
|
-
: NaN;
|
|
416
|
-
if (isNaN(v) || isNaN(threshold)) {
|
|
417
|
-
return { passed: false, score: 0, observed_value: observed };
|
|
418
|
-
}
|
|
419
|
-
const passed = p.invert ? v <= threshold : v >= threshold;
|
|
420
|
-
const margin = Math.abs(threshold) * 0.5 || 1;
|
|
421
|
-
const rawScore = p.invert
|
|
422
|
-
? (threshold - v) / margin + 1
|
|
423
|
-
: (v - threshold) / margin + 1;
|
|
424
|
-
const score = Math.max(0, Math.min(1, rawScore));
|
|
425
|
-
return { passed, score, observed_value: observed };
|
|
426
|
-
}
|
|
427
|
-
case "ratio": {
|
|
428
|
-
const v = typeof observed === "number" ? observed
|
|
429
|
-
: typeof observed === "string" ? Number(observed)
|
|
430
|
-
: NaN;
|
|
431
|
-
const min = p.min ?? 0;
|
|
432
|
-
const max = p.max ?? 1;
|
|
433
|
-
if (isNaN(v)) {
|
|
434
|
-
return { passed: false, score: 0, observed_value: observed };
|
|
435
|
-
}
|
|
436
|
-
const passed = v >= min && v <= max;
|
|
437
|
-
const range = max - min;
|
|
438
|
-
const mid = (min + max) / 2;
|
|
439
|
-
const score = range > 0 ? Math.max(0, 1 - Math.abs(v - mid) / (range / 2)) : 1;
|
|
440
|
-
return { passed, score, observed_value: observed };
|
|
441
|
-
}
|
|
442
|
-
case "boolean": {
|
|
443
|
-
const passed = !!observed;
|
|
444
|
-
return { passed, score: passed ? 1 : 0, observed_value: observed };
|
|
445
|
-
}
|
|
446
|
-
case "presence": {
|
|
447
|
-
const present = observed !== undefined && observed !== null && observed !== "";
|
|
448
|
-
return { passed: present, score: present ? 1 : 0, observed_value: observed };
|
|
449
|
-
}
|
|
450
|
-
case "regex_match": {
|
|
451
|
-
if (typeof observed !== "string" || !p.pattern) {
|
|
452
|
-
return { passed: false, score: 0, observed_value: observed };
|
|
453
|
-
}
|
|
454
|
-
try {
|
|
455
|
-
const regex = new RegExp(p.pattern);
|
|
456
|
-
const passed = regex.test(observed);
|
|
457
|
-
return { passed, score: passed ? 1 : 0, observed_value: observed };
|
|
458
|
-
}
|
|
459
|
-
catch {
|
|
460
|
-
return { passed: false, score: 0, observed_value: observed };
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
case "custom_query": {
|
|
464
|
-
return { passed: false, score: 0.5, observed_value: observed };
|
|
465
|
-
}
|
|
466
|
-
default:
|
|
467
|
-
return { passed: false, score: 0, observed_value: observed };
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function formatObservedValue(v) {
|
|
471
|
-
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
472
|
-
return v;
|
|
473
|
-
if (typeof v === "bigint")
|
|
474
|
-
return v.toString();
|
|
475
|
-
if (v === undefined || v === null)
|
|
476
|
-
return undefined;
|
|
477
|
-
try {
|
|
478
|
-
return JSON.stringify(v);
|
|
479
|
-
}
|
|
480
|
-
catch {
|
|
481
|
-
return String(v);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
function computeCompleteness(depth, dimensions) {
|
|
485
|
-
const requiredCount = depth === "browse" ? 1
|
|
486
|
-
: depth === "evaluate" ? 4
|
|
487
|
-
: depth === "preorder" ? 6
|
|
488
|
-
: 5;
|
|
489
|
-
const requiredDimensions = dimensions.slice(0, requiredCount);
|
|
490
|
-
const presentCount = requiredDimensions.filter((d) => d !== undefined && d !== null).length;
|
|
491
|
-
return Math.min(1, presentCount / requiredCount);
|
|
492
|
-
}
|
|
493
|
-
export function evaluateServiceNesting(raw) {
|
|
494
|
-
const depth = raw.depth ?? 0;
|
|
495
|
-
const maxDepth = raw.maxDepth ?? 3;
|
|
496
|
-
const truncated = depth >= maxDepth;
|
|
497
|
-
const bindings = {
|
|
498
|
-
arbitrations: [],
|
|
499
|
-
rewards: [],
|
|
500
|
-
repositories: [],
|
|
501
|
-
};
|
|
502
|
-
let totalEvaluated = 0;
|
|
503
|
-
if (raw.machine) {
|
|
504
|
-
const m = raw.machine;
|
|
505
|
-
const issues = [];
|
|
506
|
-
let score = 0;
|
|
507
|
-
if (m.published)
|
|
508
|
-
score += 10;
|
|
509
|
-
else
|
|
510
|
-
issues.push("Machine not published");
|
|
511
|
-
if (m.paused) {
|
|
512
|
-
score += 40;
|
|
513
|
-
issues.push("Machine paused");
|
|
514
|
-
}
|
|
515
|
-
if (m.has_no_entry) {
|
|
516
|
-
score += 50;
|
|
517
|
-
issues.push("No entry point (R-M1-01)");
|
|
518
|
-
}
|
|
519
|
-
if (m.has_no_terminal) {
|
|
520
|
-
score += 50;
|
|
521
|
-
issues.push("No terminal node (R-M1-02)");
|
|
522
|
-
}
|
|
523
|
-
if (m.has_dispute_anti_pattern) {
|
|
524
|
-
score += 60;
|
|
525
|
-
issues.push("Dispute anti-pattern (R-M1-11): machine illegally models dispute flow");
|
|
526
|
-
}
|
|
527
|
-
const structIssues = m.structural_issue_count ?? 0;
|
|
528
|
-
if (structIssues > 0) {
|
|
529
|
-
score += structIssues * 15;
|
|
530
|
-
issues.push(`${structIssues} structural issue(s) detected (cycles/dead-ends/orphans)`);
|
|
531
|
-
}
|
|
532
|
-
score = Math.min(100, score);
|
|
533
|
-
bindings.machine = {
|
|
534
|
-
object_id: m.object_id,
|
|
535
|
-
published: m.published,
|
|
536
|
-
risk_level: scoreToNestingLevel(score),
|
|
537
|
-
issues,
|
|
538
|
-
};
|
|
539
|
-
totalEvaluated++;
|
|
540
|
-
}
|
|
541
|
-
for (const arb of raw.arbitrations ?? []) {
|
|
542
|
-
const issues = [];
|
|
543
|
-
let score = 0;
|
|
544
|
-
if (arb.voting_guard_count === 0) {
|
|
545
|
-
score += 50;
|
|
546
|
-
issues.push("No voting_guard configured — no arbitrators can vote");
|
|
547
|
-
}
|
|
548
|
-
else if (arb.voting_guard_count <= 2) {
|
|
549
|
-
score += 30;
|
|
550
|
-
issues.push("Few arbitrators (<=2) — limited dispute resolution capacity");
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
score += 10;
|
|
554
|
-
}
|
|
555
|
-
if (arb.paused) {
|
|
556
|
-
score += 40;
|
|
557
|
-
issues.push("Arbitration paused — disputes cannot be filed");
|
|
558
|
-
}
|
|
559
|
-
if (arb.fee_balance === 0n) {
|
|
560
|
-
score += 30;
|
|
561
|
-
issues.push("No compensation fund balance — rulings cannot pay out");
|
|
562
|
-
}
|
|
563
|
-
score = Math.min(100, score);
|
|
564
|
-
bindings.arbitrations.push({
|
|
565
|
-
object_id: arb.object_id,
|
|
566
|
-
voting_guard_count: arb.voting_guard_count,
|
|
567
|
-
fee_balance: arb.fee_balance.toString(),
|
|
568
|
-
paused: arb.paused,
|
|
569
|
-
risk_level: scoreToNestingLevel(score),
|
|
570
|
-
issues,
|
|
571
|
-
});
|
|
572
|
-
totalEvaluated++;
|
|
573
|
-
}
|
|
574
|
-
for (const r of raw.rewards ?? []) {
|
|
575
|
-
const issues = [];
|
|
576
|
-
let score = 0;
|
|
577
|
-
if (r.balance === 0n) {
|
|
578
|
-
score += 60;
|
|
579
|
-
issues.push("Reward fund empty — claims will fail");
|
|
580
|
-
}
|
|
581
|
-
if (r.guard_count === 0) {
|
|
582
|
-
score += 50;
|
|
583
|
-
issues.push("No claim_guard — anyone could claim (or no one can, depending on default)");
|
|
584
|
-
}
|
|
585
|
-
if (r.expiration_time && r.expiration_time > 0 && r.expiration_time < Date.now()) {
|
|
586
|
-
score += 40;
|
|
587
|
-
issues.push("Reward expired — claims no longer possible");
|
|
588
|
-
}
|
|
589
|
-
score = Math.min(100, score);
|
|
590
|
-
bindings.rewards.push({
|
|
591
|
-
object_id: r.object_id,
|
|
592
|
-
balance: r.balance.toString(),
|
|
593
|
-
guard_count: r.guard_count,
|
|
594
|
-
risk_level: scoreToNestingLevel(score),
|
|
595
|
-
issues,
|
|
596
|
-
});
|
|
597
|
-
totalEvaluated++;
|
|
598
|
-
}
|
|
599
|
-
for (const repo of raw.repositories ?? []) {
|
|
600
|
-
const issues = [];
|
|
601
|
-
let score = 0;
|
|
602
|
-
if (!repo.has_write_guard) {
|
|
603
|
-
score += 40;
|
|
604
|
-
issues.push("No write_guard — Repository is open to arbitrary writes");
|
|
605
|
-
}
|
|
606
|
-
if (repo.is_empty) {
|
|
607
|
-
score += 20;
|
|
608
|
-
issues.push("Repository empty — no historical data for evaluation");
|
|
609
|
-
}
|
|
610
|
-
score = Math.min(100, score);
|
|
611
|
-
bindings.repositories.push({
|
|
612
|
-
object_id: repo.object_id,
|
|
613
|
-
risk_level: scoreToNestingLevel(score),
|
|
614
|
-
issues,
|
|
615
|
-
});
|
|
616
|
-
totalEvaluated++;
|
|
617
|
-
}
|
|
618
|
-
if (totalEvaluated === 0) {
|
|
619
|
-
return undefined;
|
|
620
|
-
}
|
|
621
|
-
const machineScore = bindings.machine ? nestingLevelToScore(bindings.machine.risk_level) : 0;
|
|
622
|
-
const machineWeight = bindings.machine ? 35 : 0;
|
|
623
|
-
const arbScore = bindings.arbitrations.length > 0
|
|
624
|
-
? Math.max(...bindings.arbitrations.map((a) => nestingLevelToScore(a.risk_level)))
|
|
625
|
-
: 0;
|
|
626
|
-
const arbWeight = bindings.arbitrations.length > 0 ? 30 : 0;
|
|
627
|
-
const rewardScore = bindings.rewards.length > 0
|
|
628
|
-
? Math.max(...bindings.rewards.map((r) => nestingLevelToScore(r.risk_level)))
|
|
629
|
-
: 0;
|
|
630
|
-
const rewardWeight = bindings.rewards.length > 0 ? 20 : 0;
|
|
631
|
-
const repoScore = bindings.repositories.length > 0
|
|
632
|
-
? Math.max(...bindings.repositories.map((r) => nestingLevelToScore(r.risk_level)))
|
|
633
|
-
: 0;
|
|
634
|
-
const repoWeight = bindings.repositories.length > 0 ? 15 : 0;
|
|
635
|
-
const totalWeight = machineWeight + arbWeight + rewardWeight + repoWeight;
|
|
636
|
-
const overallScore = totalWeight > 0
|
|
637
|
-
? Math.round((machineScore * machineWeight + arbScore * arbWeight
|
|
638
|
-
+ rewardScore * rewardWeight + repoScore * repoWeight) / totalWeight)
|
|
639
|
-
: 0;
|
|
640
|
-
const allLevels = [];
|
|
641
|
-
if (bindings.machine)
|
|
642
|
-
allLevels.push(bindings.machine.risk_level);
|
|
643
|
-
for (const a of bindings.arbitrations)
|
|
644
|
-
allLevels.push(a.risk_level);
|
|
645
|
-
for (const r of bindings.rewards)
|
|
646
|
-
allLevels.push(r.risk_level);
|
|
647
|
-
for (const r of bindings.repositories)
|
|
648
|
-
allLevels.push(r.risk_level);
|
|
649
|
-
const overallLevel = allLevels.reduce(highestLevel, "low");
|
|
650
|
-
return {
|
|
651
|
-
depth_reached: depth,
|
|
652
|
-
truncated,
|
|
653
|
-
bindings,
|
|
654
|
-
overall_risk_level: overallLevel,
|
|
655
|
-
overall_risk_score: overallScore,
|
|
656
|
-
total_bindings_evaluated: totalEvaluated,
|
|
657
|
-
evaluated_at: Date.now(),
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
function scoreToNestingLevel(score) {
|
|
661
|
-
if (score >= 75)
|
|
662
|
-
return "critical";
|
|
663
|
-
if (score >= 50)
|
|
664
|
-
return "high";
|
|
665
|
-
if (score >= 25)
|
|
666
|
-
return "medium";
|
|
667
|
-
return "low";
|
|
668
|
-
}
|
|
669
|
-
function nestingLevelToScore(level) {
|
|
670
|
-
switch (level) {
|
|
671
|
-
case "critical": return 90;
|
|
672
|
-
case "high": return 65;
|
|
673
|
-
case "medium": return 40;
|
|
674
|
-
case "low": return 10;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
function highestLevel(a, b) {
|
|
678
|
-
const order = { low: 0, medium: 1, high: 2, critical: 3 };
|
|
679
|
-
return order[a] >= order[b] ? a : b;
|
|
680
|
-
}
|
|
681
|
-
export { CUSTOMER_INTELLIGENCE_VERSION };
|
|
1
|
+
import{CUSTOMER_INTELLIGENCE_VERSION}from'./types.js';export function assembleServiceBasics(a,b,c=![]){const d=(b['sales']??[])['filter'](f=>!f['suspension']),e=d['some'](f=>f['wip_hash']&&f['wip_hash']['length']>0x0);return{'service_id':a,'name':b['name']??a,'bPublished':b['bPublished']??![],'bPaused':b['bPaused']??![],'price':b['price']??'0','price_raw':b['priceRaw']??0x0n,'token_type':b['token_type']??'0x2::wow::WOW','sales_count':d['length'],'machine_id':b['machine'],'buy_guard_id':b['buy_guard'],'customer_required_count':b['customer_required']?.['length']??0x0,'customer_required':(b['customer_required']??[])['filter'](f=>typeof f==='string'),'arbitrations_count':b['arbitrations']?.['length']??0x0,'compensation_fund_balance':b['compensation_fund']?.['balance']??0x0n,'compensation_lock_duration':b['compensation_lock_duration']??0x0,'um_id':b['um'],'has_wip':e,'wip_verified':c};}export function assembleWorkflowAnalysis(a,b,c,d){const e=[],f=[],g=[];let h=0x0,i=0x0,j=0x0,k=![],l=![],m=![];const n=/(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i,o=/^(wonder|no_wonder|praise|complain|thumbs_up|thumbs_down|positive_review|negative_review)$/i,p=a['reduce']((w,x)=>w+(x['forwards']?.['length']??0x0),0x0);for(const w of a){n['test'](w['name']['trim']())&&(m=!![]);}for(const x of a){const y=x['forwards']??[];y['length']===0x0&&f['push'](x['name']);for(const z of y){const A=z['namedOperator'],B=z['guard'];if(A==='')B?j++:h++;else A===null||A===undefined?i++:i++;const C=(z['to']??'')['trim']()['toLowerCase']();o['test'](C)&&(l=!![]),C['includes']('milestone')&&(k=!![]);}}for(const D of a){const E=D['forwards']??[];if(E['length']>0x0&&!f['includes'](D['name'])){const F=E['every'](G=>G['namedOperator']!==''&&G['namedOperator']!==null);F&&h===0x0&&g['push'](D['name']);}}const q=(d?.['arbitrations']?.['length']??0x0)>0x0,r=d?.['compensation_fund']?.['balance']??0x0n,s=q&&r>0x0n,t=d?.['order_allocators']?.[0x0]?.['allocators']??[],u=t['some'](G=>G['surplus_to']==='order'||G['surplus_to']==='Order'),v=s||u;if(!v)e['push']('no_refund_path');if(!q)e['push']('no_arbitration_binding');if(m)e['push']('dispute_anti_pattern');if(h===0x0)e['push']('no_user_operable_path');if(g['length']>0x0)e['push']('potential_dead_ends');return{'machine_published':b,'machine_paused':c,'total_nodes':a['length'],'total_forwards':p,'user_operable_forwards':h,'provider_only_forwards':i,'guard_gated_forwards':j,'has_refund_path':v,'has_arbitration_path':q,'has_arbitration_binding':q,'has_wonder_node':l,'has_dispute_anti_pattern':m,'has_milestone_nodes':k,'dead_end_nodes':g,'terminal_nodes':f,'risk_signals':e};}export function assembleFundSafety(a,b){const c=a['order_allocators']?.[0x0]?.['allocators']??[],d=a['compensation_fund']?.['balance']??0x0n,e=a['compensation_lock_duration']??0x0,f=c['find'](j=>{const k=j['amount'];return k?.['type']==='FixedValue'&&k['value']===b;}),g=c['some'](j=>j['surplus_to']==='order'||j['surplus_to']==='Order');let h='none';b>0x0n&&(d>0x0n&&b>d*0x3n&&(h='low'));const i=e===0x0||e>0x7;return{'has_order_allocator':c['length']>0x0,'has_refund_allocator':!!f||g,'allocator_count':c['length'],'refund_allocator_exists':g,'surplus_to_provider':c['some'](j=>j['surplus_to']!=='order'&&j['surplus_to']!=='Order'),'user_path_has_allocator':c['length']>0x0,'compensation_covers_order':d>=b,'compensation_ratio':b>0x0n?Math['min'](0x1,Number(d*0x64n/b)/0x64):0x0,'lock_duration_safe':i,'price_anomaly':h};}export function assembleTrustSignals(a,b,c,d,e,f,g){const h=b['filter'](n=>n['rating']==='like')['length'],i=b['filter'](n=>n['rating']==='dislike')['length'],j=b['filter'](n=>n['verified']||n['has_evidence'])['length'],k=b['length'],l=k>0x0?h/k:0x0,m=d!==undefined&&e!==undefined?d!==e:!![];return{'arbitration_independent':m,'arbitration_count':a['arbitrations']?.['length']??0x0,'arbitration_paused':![],'review_likes':h,'review_dislikes':i,'review_verified_count':j,'review_total':k,'like_rate':l,'trust_score':c['score'],'trust_level':c['level'],'has_contact':!!a['um'],'has_messenger':!!a['um'],'arbitration_permission_shared':f,'arbitration_permission_overlap':g};}const REPUTATION_MIN_VOTES=0x3;function toReputation(a){const b=a['likes']+a['dislikes'];return{'likes':a['likes'],'dislikes':a['dislikes'],'like_ratio':b>0x0?a['likes']/b:0x1};}function reputationRedFlags(a){if(!a)return[];const b=a['likes']+a['dislikes'];if(b>=REPUTATION_MIN_VOTES&&a['like_ratio']<0.5)return['reputation_negative'];return[];}export function assembleMerchantBehavior(a,b,c){const d=c?toReputation(c):undefined,e=reputationRedFlags(d);if(b&&b['length']>0x0){const l=b['length'],m=b['filter'](v=>v['status']==='completed')['length'],n=b['filter'](v=>v['has_dispute'])['length'],o=b['filter'](v=>v['is_repeat'])['length'],p=l>0x0?m/l:0x0,q=l>0x0?n/l:0x0,r=l>0x0?o/l:0x0,s=Math['floor'](l/0x2);let t='stable';if(l>=0x4&&s>0x0){const v=b['slice'](0x0,s)['filter'](z=>z['has_dispute'])['length'],w=b['slice'](s)['filter'](z=>z['has_dispute'])['length'],x=v/s,y=w/(l-s);if(y<x*0.85)t='improving';else{if(y>x*1.15)t='declining';}}const u=[...e];if(q>0.1)u['push']('dispute_rate_high');if(t==='declining')u['push']('declining_trend');return{'total_orders':l,'completed_rate':p,'dispute_rate':q,'refund_rate':0x0,'arb_loss_rate':0x0,'repeat_buyer_rate':r,'recent_trend':t,'red_flags':u,'reputation':d};}const f=a['filter'](z=>z['type']['includes']('Order')||z['type']['includes']('order')),g=a['filter'](z=>z['type']['includes']('Dispute')||z['type']['includes']('Arb')),h=f['length'],i=g['length'],j=h>0x0?i/h:0x0,k=[...e];if(j>0.1)k['push']('dispute_rate_high');return{'total_orders':h,'completed_rate':h>0x0?Math['max'](0x0,0x1-j):0x0,'dispute_rate':j,'refund_rate':0x0,'arb_loss_rate':0x0,'repeat_buyer_rate':0x0,'recent_trend':'stable','red_flags':k,'reputation':d};}export function assembleMarketContext(a,b){if(a['length']===0x0)return{'similar_services_count':0x0,'avg_price':0x0n,'min_price':0x0n,'max_price':0x0n,'price_percentile':0x0,'supply_demand_ratio':0x0};const c=a['map'](j=>j['price'])['sort']((j,k)=>j<k?-0x1:j>k?0x1:0x0),d=c['reduce']((j,k)=>j+k,0x0n),e=d/BigInt(c['length']),f=c[0x0],g=c[c['length']-0x1];let h=0x0;for(const j of c){if(j<b)h++;}const i=c['length']>0x0?h/c['length']:0x0;return{'similar_services_count':a['length'],'avg_price':e,'min_price':f,'max_price':g,'price_percentile':i,'supply_demand_ratio':a['length']};}export function assembleInfoPuzzle(a,b,c='evaluate'){const d=[],e=assembleServiceBasics(a,b['service'],b['wip_verified']??![]);let f,g,h;if(c==='evaluate'||c==='preorder'||c==='monitor'){b['machine_nodes']?f=assembleWorkflowAnalysis(b['machine_nodes'],b['machine_published']??![],b['machine_paused']??![],b['service']):d['push']('machine_workflow');const m=b['order_amount']??e['price_raw'];g=assembleFundSafety(b['service'],m),b['reviews']&&b['trust_score']?h=assembleTrustSignals(b['service'],b['reviews'],b['trust_score'],b['arbitration_owner'],b['service_owner']):d['push']('reviews_or_trust_score');}let i;if(c==='preorder'||c==='monitor'){if(b['events']||b['order_history'])i=assembleMerchantBehavior(b['events']??[],b['order_history'],b['merchant_reputation']);else b['merchant_reputation']?i=assembleMerchantBehavior([],undefined,b['merchant_reputation']):d['push']('merchant_behavior');}let j;(c==='evaluate'||c==='preorder')&&(b['similar_services']?j=assembleMarketContext(b['similar_services'],e['price_raw']):d['push']('market_context'));let k;b['user_metrics_config']&&b['user_metrics_config']['metrics']['length']>0x0&&(k=assembleUserMetrics(b['user_metrics_config'],b['user_metrics_context']??{}));let l=b['service_nesting'];return!l&&b['service_nesting_raw']&&(l=evaluateServiceNesting(b['service_nesting_raw'])),{'service_id':a,'service_basics':e,'workflow_analysis':f,'fund_safety':g,'trust_signals':h,'merchant_behavior':i,'market_context':j,'user_metrics':k,'service_nesting':l,'completeness':computeCompleteness(c,[e,f,g,h,i,j,k,l]),'gaps':d,'assembled_at':Date['now']()};}export function assembleUserMetrics(a,b){const c=a['adjustment_cap']??0xa,d=[],e=a['metrics']['reduce']((i,j)=>i+Math['max'](0x0,j['weight']),0x0);for(const i of a['metrics']){const j=e>0x0?Math['max'](0x0,i['weight'])/e:0x0,k=resolvePath(b,i['params']['path']??i['name']),{passed:l,score:m,observed_value:n}=evaluateMetric(i,k);d['push']({'name':i['name'],'label':i['label'],'passed':l,'score':m,'observed_value':formatObservedValue(k),'weight':j,'advice':l?i['advice_on_pass']:i['advice_on_fail']});}const f=d['reduce']((o,p)=>o+p['score']*p['weight'],0x0),g=Math['round'](f*0x64),h=Math['round']((g-0x32)/0x32*c);return{'metrics':d,'score':g,'adjustment':h,'source_file':a['source_file'],'evaluated_at':Date['now']()};}function resolvePath(a,b){if(!b)return undefined;const c=b['split']('.');let d=a;for(const e of c){if(d===null||d===undefined)return undefined;if(typeof d!=='object')return undefined;d=d[e];}return d;}function evaluateMetric(a,b){const c=a['params'];switch(a['evaluator']){case'threshold':{const d=typeof b==='number'?b:typeof b==='string'?Number(b):typeof b==='bigint'?Number(b):NaN,e=typeof c['threshold']==='number'?c['threshold']:typeof c['threshold']==='string'?Number(c['threshold']):NaN;if(isNaN(d)||isNaN(e))return{'passed':![],'score':0x0,'observed_value':b};const f=c['invert']?d<=e:d>=e,g=Math['abs'](e)*0.5||0x1,h=c['invert']?(e-d)/g+0x1:(d-e)/g+0x1,i=Math['max'](0x0,Math['min'](0x1,h));return{'passed':f,'score':i,'observed_value':b};}case'ratio':{const j=typeof b==='number'?b:typeof b==='string'?Number(b):NaN,k=c['min']??0x0,l=c['max']??0x1;if(isNaN(j))return{'passed':![],'score':0x0,'observed_value':b};const m=j>=k&&j<=l,n=l-k,o=(k+l)/0x2,q=n>0x0?Math['max'](0x0,0x1-Math['abs'](j-o)/(n/0x2)):0x1;return{'passed':m,'score':q,'observed_value':b};}case'boolean':{const r=!!b;return{'passed':r,'score':r?0x1:0x0,'observed_value':b};}case'presence':{const s=b!==undefined&&b!==null&&b!=='';return{'passed':s,'score':s?0x1:0x0,'observed_value':b};}case'regex_match':{if(typeof b!=='string'||!c['pattern'])return{'passed':![],'score':0x0,'observed_value':b};try{const t=new RegExp(c['pattern']),u=t['test'](b);return{'passed':u,'score':u?0x1:0x0,'observed_value':b};}catch{return{'passed':![],'score':0x0,'observed_value':b};}}case'custom_query':{return{'passed':![],'score':0.5,'observed_value':b};}default:return{'passed':![],'score':0x0,'observed_value':b};}}function formatObservedValue(a){if(typeof a==='string'||typeof a==='number'||typeof a==='boolean')return a;if(typeof a==='bigint')return a['toString']();if(a===undefined||a===null)return undefined;try{return JSON['stringify'](a);}catch{return String(a);}}function computeCompleteness(a,b){const c=a==='browse'?0x1:a==='evaluate'?0x4:a==='preorder'?0x6:0x5,d=b['slice'](0x0,c),e=d['filter'](f=>f!==undefined&&f!==null)['length'];return Math['min'](0x1,e/c);}export function evaluateServiceNesting(b){const c=b['depth']??0x0,d=b['maxDepth']??0x3,e=c>=d,f={'arbitrations':[],'rewards':[],'repositories':[]};let g=0x0;if(b['machine']){const v=b['machine'],w=[];let x=0x0;if(v['published'])x+=0xa;else w['push']('Machine\x20not\x20published');v['paused']&&(x+=0x28,w['push']('Machine\x20paused'));v['has_no_entry']&&(x+=0x32,w['push']('No\x20entry\x20point\x20(R-M1-01)'));v['has_no_terminal']&&(x+=0x32,w['push']('No\x20terminal\x20node\x20(R-M1-02)'));v['has_dispute_anti_pattern']&&(x+=0x3c,w['push']('Dispute\x20anti-pattern\x20(R-M1-11):\x20machine\x20illegally\x20models\x20dispute\x20flow'));const y=v['structural_issue_count']??0x0;y>0x0&&(x+=y*0xf,w['push'](y+'\x20structural\x20issue(s)\x20detected\x20(cycles/dead-ends/orphans)')),x=Math['min'](0x64,x),f['machine']={'object_id':v['object_id'],'published':v['published'],'risk_level':scoreToNestingLevel(x),'issues':w},g++;}for(const z of b['arbitrations']??[]){const A=[];let B=0x0;if(z['voting_guard_count']===0x0)B+=0x32,A['push']('No\x20voting_guard\x20configured\x20—\x20no\x20arbitrators\x20can\x20vote');else z['voting_guard_count']<=0x2?(B+=0x1e,A['push']('Few\x20arbitrators\x20(<=2)\x20—\x20limited\x20dispute\x20resolution\x20capacity')):B+=0xa;z['paused']&&(B+=0x28,A['push']('Arbitration\x20paused\x20—\x20disputes\x20cannot\x20be\x20filed')),z['fee_balance']===0x0n&&(B+=0x1e,A['push']('No\x20compensation\x20fund\x20balance\x20—\x20rulings\x20cannot\x20pay\x20out')),B=Math['min'](0x64,B),f['arbitrations']['push']({'object_id':z['object_id'],'voting_guard_count':z['voting_guard_count'],'fee_balance':z['fee_balance']['toString'](),'paused':z['paused'],'risk_level':scoreToNestingLevel(B),'issues':A}),g++;}for(const C of b['rewards']??[]){const D=[];let E=0x0;C['balance']===0x0n&&(E+=0x3c,D['push']('Reward\x20fund\x20empty\x20—\x20claims\x20will\x20fail')),C['guard_count']===0x0&&(E+=0x32,D['push']('No\x20claim_guard\x20—\x20anyone\x20could\x20claim\x20(or\x20no\x20one\x20can,\x20depending\x20on\x20default)')),C['expiration_time']&&C['expiration_time']>0x0&&C['expiration_time']<Date['now']()&&(E+=0x28,D['push']('Reward\x20expired\x20—\x20claims\x20no\x20longer\x20possible')),E=Math['min'](0x64,E),f['rewards']['push']({'object_id':C['object_id'],'balance':C['balance']['toString'](),'guard_count':C['guard_count'],'risk_level':scoreToNestingLevel(E),'issues':D}),g++;}for(const F of b['repositories']??[]){const G=[];let H=0x0;!F['has_write_guard']&&(H+=0x28,G['push']('No\x20write_guard\x20—\x20Repository\x20is\x20open\x20to\x20arbitrary\x20writes')),F['is_empty']&&(H+=0x14,G['push']('Repository\x20empty\x20—\x20no\x20historical\x20data\x20for\x20evaluation')),H=Math['min'](0x64,H),f['repositories']['push']({'object_id':F['object_id'],'risk_level':scoreToNestingLevel(H),'issues':G}),g++;}if(g===0x0)return undefined;const h=f['machine']?nestingLevelToScore(f['machine']['risk_level']):0x0,i=f['machine']?0x23:0x0,j=f['arbitrations']['length']>0x0?Math['max'](...f['arbitrations']['map'](I=>nestingLevelToScore(I['risk_level']))):0x0,k=f['arbitrations']['length']>0x0?0x1e:0x0,l=f['rewards']['length']>0x0?Math['max'](...f['rewards']['map'](I=>nestingLevelToScore(I['risk_level']))):0x0,n=f['rewards']['length']>0x0?0x14:0x0,o=f['repositories']['length']>0x0?Math['max'](...f['repositories']['map'](I=>nestingLevelToScore(I['risk_level']))):0x0,p=f['repositories']['length']>0x0?0xf:0x0,q=i+k+n+p,s=q>0x0?Math['round']((h*i+j*k+l*n+o*p)/q):0x0,t=[];if(f['machine'])t['push'](f['machine']['risk_level']);for(const I of f['arbitrations'])t['push'](I['risk_level']);for(const J of f['rewards'])t['push'](J['risk_level']);for(const K of f['repositories'])t['push'](K['risk_level']);const u=t['reduce'](highestLevel,'low');return{'depth_reached':c,'truncated':e,'bindings':f,'overall_risk_level':u,'overall_risk_score':s,'total_bindings_evaluated':g,'evaluated_at':Date['now']()};}function scoreToNestingLevel(a){if(a>=0x4b)return'critical';if(a>=0x32)return'high';if(a>=0x19)return'medium';return'low';}function nestingLevelToScore(a){switch(a){case'critical':return 0x5a;case'high':return 0x41;case'medium':return 0x28;case'low':return 0xa;}}function highestLevel(c,d){const e={'low':0x0,'medium':0x1,'high':0x2,'critical':0x3};return e[c]>=e[d]?c:d;}export{CUSTOMER_INTELLIGENCE_VERSION};
|