@wowok/agent-mcp 2.7.1 → 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.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 +9 -2
- package/dist/evaluation/arbitration-game.js +1 -48
- package/dist/evaluation/builtins/demand-match.js +1 -153
- package/dist/evaluation/builtins/index.js +1 -10
- package/dist/evaluation/builtins/service-risk.js +1 -55
- package/dist/evaluation/capability.js +1 -13
- package/dist/evaluation/composer.js +1 -40
- package/dist/evaluation/engine.js +1 -175
- package/dist/evaluation/extract.js +1 -115
- package/dist/evaluation/game-strategy.d.ts +27 -0
- package/dist/evaluation/game-strategy.js +1 -0
- package/dist/evaluation/gap.js +1 -100
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.js +1 -11
- package/dist/evaluation/node-game.d.ts +31 -3
- package/dist/evaluation/node-game.js +1 -57
- package/dist/evaluation/region.js +1 -36
- package/dist/evaluation/types.d.ts +1 -0
- package/dist/evaluation/types.js +1 -1
- package/dist/evaluation/user-injection.js +1 -27
- 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 -315
- 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.js +1 -67
- package/dist/intent/index.js +1 -60
- package/dist/intent/matcher.js +1 -81
- package/dist/intent/store.js +1 -55
- package/dist/intent/types.js +1 -10
- 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 -423
- 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.js +1 -60
- 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 -843
- 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 -669
- 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.js +1 -777
- 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 -651
- package/dist/knowledge/service-templates.js +1 -456
- package/dist/knowledge/service-translation.js +1 -622
- package/dist/knowledge/template-registry.js +1 -353
- package/dist/knowledge/tool-constraints.js +1 -195
- package/dist/knowledge/tools-reference.js +1 -178
- 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.js +1 -66
- package/dist/persona/bridge.js +1 -86
- package/dist/persona/defaults.js +1 -195
- package/dist/persona/experience-bridge.js +1 -23
- package/dist/persona/index.js +1 -71
- package/dist/persona/model.js +1 -111
- package/dist/persona/store.js +1 -62
- package/dist/persona/types.d.ts +3 -1
- package/dist/persona/types.js +1 -5
- 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.js +1 -1784
- 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 -292
- 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.js +1 -52
- 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 -1679
- package/dist/schema/call/service.js +1 -184
- 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 +213 -16
- package/dist/schema/evaluation/index.js +1 -356
- package/dist/schema/index.js +1 -17
- package/dist/schema/intent-radar/index.d.ts +13 -13
- package/dist/schema/intent-radar/index.js +1 -89
- 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 +54 -54
- package/dist/schema/persona/index.js +1 -148
- package/dist/schema/project/index.d.ts +94 -48
- package/dist/schema/project/index.js +1 -2057
- package/dist/schema/query/index.d.ts +423 -7
- package/dist/schema/query/index.js +1 -1646
- package/dist/schema/schema-query/index.js +1 -104
- package/dist/schema/schema-version.js +1 -76
- package/dist/schema/sync-layer4.js +1 -286
- package/dist/schema/task-status.js +1 -36
- 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 +112 -7
- package/dist/schemas/evaluation_operation.schema.json +93 -6
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/intent_radar.output.json +4 -1
- package/dist/schemas/intent_radar.schema.json +4 -1
- 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 +4 -4
- 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 +1 -1
- package/dist/schemas/onchain_table_data.output.json +6 -3
- package/dist/schemas/persona_operation.output.json +4 -1
- package/dist/schemas/persona_operation.schema.json +4 -1
- package/dist/schemas/project_operation.output.json +28 -8
- package/dist/schemas/query_toolkit.output.json +8 -5
- 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.js +1 -123
- package/dist/tools/handlers/file-export.js +1 -90
- package/dist/tools/handlers/intent-radar.js +1 -76
- package/dist/tools/handlers/local.js +1 -53
- package/dist/tools/handlers/messenger.js +1 -188
- package/dist/tools/handlers/onchain.js +1 -1180
- package/dist/tools/handlers/persona.js +1 -89
- 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.js +1 -26
- package/dist/tools/handlers/trust.js +1 -380
- package/dist/tools/handlers/wip.js +1 -90
- package/dist/tools/index.js +1 -1382
- 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.js +1 -306
- package/dist/tools/wrap.js +1 -500
- package/package.json +4 -2
package/dist/evaluation/gap.js
CHANGED
|
@@ -1,100 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { relateRegion } from "./region.js";
|
|
3
|
-
const IMPACT = {
|
|
4
|
-
has_arbitration: "critical",
|
|
5
|
-
has_refund_path: "critical",
|
|
6
|
-
has_compensation_fund: "major",
|
|
7
|
-
has_wip_verification: "major",
|
|
8
|
-
has_milestone_nodes: "minor",
|
|
9
|
-
has_messenger: "minor",
|
|
10
|
-
has_buy_guard: "minor",
|
|
11
|
-
has_dynamic_pricing: "minor",
|
|
12
|
-
};
|
|
13
|
-
const SUGGEST = {
|
|
14
|
-
has_arbitration: "bind an independent Arbitration object to the Service",
|
|
15
|
-
has_refund_path: "configure a refund path (Arbitration + compensation_fund, or a refund Allocator)",
|
|
16
|
-
has_compensation_fund: "deposit compensation_fund to cover the order amount",
|
|
17
|
-
has_wip_verification: "set a wip_hash on the sale to prevent tampering",
|
|
18
|
-
has_milestone_nodes: "add milestone nodes to the Machine workflow",
|
|
19
|
-
has_messenger: "bind a Contact (um) to enable Messenger",
|
|
20
|
-
has_buy_guard: "configure a buy_guard for purchase eligibility",
|
|
21
|
-
has_dynamic_pricing: "configure discount/dynamic pricing",
|
|
22
|
-
};
|
|
23
|
-
export function summarizeCapabilityGaps(demand, service) {
|
|
24
|
-
const satisfied = [];
|
|
25
|
-
const missing = [];
|
|
26
|
-
for (const k of requiredCapabilities(demand.capabilities)) {
|
|
27
|
-
const ok = service.capabilities[k];
|
|
28
|
-
const gap = {
|
|
29
|
-
dimension: k,
|
|
30
|
-
requirement: `requires ${k}`,
|
|
31
|
-
provided: ok ? "provided" : "missing",
|
|
32
|
-
status: ok ? "satisfied" : "missing",
|
|
33
|
-
impact: ok ? "minor" : (IMPACT[k] ?? "minor"),
|
|
34
|
-
suggestion: ok ? "" : (SUGGEST[k] ?? ""),
|
|
35
|
-
};
|
|
36
|
-
(ok ? satisfied : missing).push(gap);
|
|
37
|
-
}
|
|
38
|
-
if (demand.industry !== "general" && demand.industry !== service.industry) {
|
|
39
|
-
missing.push({
|
|
40
|
-
dimension: "industry",
|
|
41
|
-
requirement: demand.industry,
|
|
42
|
-
provided: service.industry,
|
|
43
|
-
status: "missing",
|
|
44
|
-
impact: "major",
|
|
45
|
-
suggestion: `switch to a service in the '${demand.industry}' industry`,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const rel = relateRegion(demand.region, service.region);
|
|
49
|
-
if (rel === "mismatch") {
|
|
50
|
-
missing.push({
|
|
51
|
-
dimension: "region",
|
|
52
|
-
requirement: demand.region.raw,
|
|
53
|
-
provided: service.region.raw,
|
|
54
|
-
status: "missing",
|
|
55
|
-
impact: "critical",
|
|
56
|
-
suggestion: "choose a service in a compatible region",
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
else if (rel === "overlap") {
|
|
60
|
-
missing.push({
|
|
61
|
-
dimension: "region",
|
|
62
|
-
requirement: demand.region.raw,
|
|
63
|
-
provided: service.region.raw,
|
|
64
|
-
status: "partial",
|
|
65
|
-
impact: "minor",
|
|
66
|
-
suggestion: "different city in the same province",
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (demand.price_max !== undefined && service.price_min !== undefined && service.price_min > demand.price_max) {
|
|
70
|
-
missing.push({
|
|
71
|
-
dimension: "price",
|
|
72
|
-
requirement: `≤ ${demand.price_max}`,
|
|
73
|
-
provided: `${service.price_min}`,
|
|
74
|
-
status: "missing",
|
|
75
|
-
impact: "major",
|
|
76
|
-
suggestion: "negotiate a lower price or raise the budget",
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (service.trust_score < demand.trust_score) {
|
|
80
|
-
missing.push({
|
|
81
|
-
dimension: "trust",
|
|
82
|
-
requirement: `≥ ${demand.trust_score}`,
|
|
83
|
-
provided: `${service.trust_score}`,
|
|
84
|
-
status: "missing",
|
|
85
|
-
impact: "major",
|
|
86
|
-
suggestion: "find a more trustworthy merchant or require more safeguards",
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const total = satisfied.length + missing.length;
|
|
90
|
-
const coverage = total === 0 ? 100 : Math.round((satisfied.length / total) * 100);
|
|
91
|
-
return {
|
|
92
|
-
entity_id: service.id,
|
|
93
|
-
satisfied,
|
|
94
|
-
missing,
|
|
95
|
-
coverage_score: coverage,
|
|
96
|
-
summary: missing.length === 0
|
|
97
|
-
? `Service fully covers the demand's requirements (${coverage}/100)`
|
|
98
|
-
: `${missing.length} requirement(s) unmet (coverage ${coverage}/100): ${missing.map((m) => m.dimension).join(", ")}`,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
1
|
+
import{requiredCapabilities}from'./capability.js';import{relateRegion}from'./region.js';const IMPACT={'has_arbitration':'critical','has_refund_path':'critical','has_compensation_fund':'major','has_wip_verification':'major','has_milestone_nodes':'minor','has_messenger':'minor','has_buy_guard':'minor','has_dynamic_pricing':'minor'},SUGGEST={'has_arbitration':'bind\x20an\x20independent\x20Arbitration\x20object\x20to\x20the\x20Service','has_refund_path':'configure\x20a\x20refund\x20path\x20(Arbitration\x20+\x20compensation_fund,\x20or\x20a\x20refund\x20Allocator)','has_compensation_fund':'deposit\x20compensation_fund\x20to\x20cover\x20the\x20order\x20amount','has_wip_verification':'set\x20a\x20wip_hash\x20on\x20the\x20sale\x20to\x20prevent\x20tampering','has_milestone_nodes':'add\x20milestone\x20nodes\x20to\x20the\x20Machine\x20workflow','has_messenger':'bind\x20a\x20Contact\x20(um)\x20to\x20enable\x20Messenger','has_buy_guard':'configure\x20a\x20buy_guard\x20for\x20purchase\x20eligibility','has_dynamic_pricing':'configure\x20discount/dynamic\x20pricing'};export function summarizeCapabilityGaps(a,b){const c=[],d=[];for(const h of requiredCapabilities(a['capabilities'])){const i=b['capabilities'][h],j={'dimension':h,'requirement':'requires\x20'+h,'provided':i?'provided':'missing','status':i?'satisfied':'missing','impact':i?'minor':IMPACT[h]??'minor','suggestion':i?'':SUGGEST[h]??''};(i?c:d)['push'](j);}a['industry']!=='general'&&a['industry']!==b['industry']&&d['push']({'dimension':'industry','requirement':a['industry'],'provided':b['industry'],'status':'missing','impact':'major','suggestion':'switch\x20to\x20a\x20service\x20in\x20the\x20\x27'+a['industry']+'\x27\x20industry'});const e=relateRegion(a['region'],b['region']);if(e==='mismatch')d['push']({'dimension':'region','requirement':a['region']['raw'],'provided':b['region']['raw'],'status':'missing','impact':'critical','suggestion':'choose\x20a\x20service\x20in\x20a\x20compatible\x20region'});else e==='overlap'&&d['push']({'dimension':'region','requirement':a['region']['raw'],'provided':b['region']['raw'],'status':'partial','impact':'minor','suggestion':'different\x20city\x20in\x20the\x20same\x20province'});a['price_max']!==undefined&&b['price_min']!==undefined&&b['price_min']>a['price_max']&&d['push']({'dimension':'price','requirement':'≤\x20'+a['price_max'],'provided':''+b['price_min'],'status':'missing','impact':'major','suggestion':'negotiate\x20a\x20lower\x20price\x20or\x20raise\x20the\x20budget'});b['trust_score']<a['trust_score']&&d['push']({'dimension':'trust','requirement':'≥\x20'+a['trust_score'],'provided':''+b['trust_score'],'status':'missing','impact':'major','suggestion':'find\x20a\x20more\x20trustworthy\x20merchant\x20or\x20require\x20more\x20safeguards'});const f=c['length']+d['length'],g=f===0x0?0x64:Math['round'](c['length']/f*0x64);return{'entity_id':b['id'],'satisfied':c,'missing':d,'coverage_score':g,'summary':d['length']===0x0?'Service\x20fully\x20covers\x20the\x20demand\x27s\x20requirements\x20('+g+'/100)':d['length']+'\x20requirement(s)\x20unmet\x20(coverage\x20'+g+'/100):\x20'+d['map'](l=>l['dimension'])['join'](',\x20')};}
|
|
@@ -5,6 +5,7 @@ export * from "./capability.js";
|
|
|
5
5
|
export * from "./extract.js";
|
|
6
6
|
export * from "./gap.js";
|
|
7
7
|
export * from "./composer.js";
|
|
8
|
+
export * from "./game-strategy.js";
|
|
8
9
|
export * from "./node-game.js";
|
|
9
10
|
export * from "./arbitration-game.js";
|
|
10
11
|
export * from "./builtins/index.js";
|
package/dist/evaluation/index.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./user-injection.js";
|
|
3
|
-
export * from "./region.js";
|
|
4
|
-
export * from "./capability.js";
|
|
5
|
-
export * from "./extract.js";
|
|
6
|
-
export * from "./gap.js";
|
|
7
|
-
export * from "./composer.js";
|
|
8
|
-
export * from "./node-game.js";
|
|
9
|
-
export * from "./arbitration-game.js";
|
|
10
|
-
export * from "./builtins/index.js";
|
|
11
|
-
export { EvaluationEngine, getEvaluationEngine, levelFromScore } from "./engine.js";
|
|
1
|
+
export*from'./types.js';export*from'./user-injection.js';export*from'./region.js';export*from'./capability.js';export*from'./extract.js';export*from'./gap.js';export*from'./composer.js';export*from'./game-strategy.js';export*from'./node-game.js';export*from'./arbitration-game.js';export*from'./builtins/index.js';export{EvaluationEngine,getEvaluationEngine,levelFromScore}from'./engine.js';
|
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import type { ExecutionPath
|
|
1
|
+
import type { ExecutionPath } from "../participation/radar-core.js";
|
|
2
|
+
import type { CommercialRole } from "../role/types.js";
|
|
3
|
+
import { type RiskAppetite } from "./game-strategy.js";
|
|
2
4
|
export interface NodeForwardInput {
|
|
3
5
|
name: string;
|
|
4
6
|
to_node: string;
|
|
5
7
|
execution_path: ExecutionPath;
|
|
6
8
|
guard?: string;
|
|
7
9
|
consequence?: string;
|
|
10
|
+
weight?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface AllocationSummary {
|
|
13
|
+
recipient_slots: number;
|
|
14
|
+
guard_gated_slots: number;
|
|
15
|
+
direct_to_me_slots: number;
|
|
16
|
+
to_payer_slots: number;
|
|
8
17
|
}
|
|
9
18
|
export interface NodeGameInput {
|
|
10
19
|
current_node: string;
|
|
11
|
-
perspective:
|
|
20
|
+
perspective: CommercialRole;
|
|
21
|
+
appetite?: RiskAppetite;
|
|
22
|
+
threshold?: number;
|
|
23
|
+
allocation?: AllocationSummary;
|
|
24
|
+
requirements?: string[];
|
|
25
|
+
order_amount?: string;
|
|
26
|
+
compensation_fund?: string;
|
|
12
27
|
operable: NodeForwardInput[];
|
|
13
28
|
waiting_on: Array<{
|
|
14
29
|
role: string;
|
|
@@ -21,14 +36,27 @@ export interface NodeGameAction {
|
|
|
21
36
|
execution_path: ExecutionPath;
|
|
22
37
|
guard?: string;
|
|
23
38
|
favorability: number;
|
|
39
|
+
gain_score: number;
|
|
40
|
+
risk_score: number;
|
|
24
41
|
is_optimal: boolean;
|
|
25
42
|
payoff_note: string;
|
|
26
43
|
risk: "low" | "medium" | "high";
|
|
27
44
|
}
|
|
45
|
+
export interface CooperationInfo {
|
|
46
|
+
threshold: number;
|
|
47
|
+
my_weight: number;
|
|
48
|
+
needed_from_others: number;
|
|
49
|
+
collaborators: string[];
|
|
50
|
+
allocation?: AllocationSummary;
|
|
51
|
+
allocation_note?: string;
|
|
52
|
+
}
|
|
28
53
|
export interface NodeGameAdvice {
|
|
29
54
|
current_node: string;
|
|
30
|
-
perspective:
|
|
55
|
+
perspective: CommercialRole;
|
|
31
56
|
actions: NodeGameAction[];
|
|
57
|
+
cooperation?: CooperationInfo;
|
|
58
|
+
value_at_stake?: string;
|
|
59
|
+
risk_exposure?: string;
|
|
32
60
|
summary: string;
|
|
33
61
|
}
|
|
34
62
|
export declare function evaluateNodeGame(input: NodeGameInput): NodeGameAdvice;
|
|
@@ -1,57 +1 @@
|
|
|
1
|
-
export function evaluateNodeGame(
|
|
2
|
-
const actions = input.operable.map((f) => {
|
|
3
|
-
const s = scoreForward(f, input.perspective);
|
|
4
|
-
return {
|
|
5
|
-
forward: f.name,
|
|
6
|
-
to_node: f.to_node,
|
|
7
|
-
execution_path: f.execution_path,
|
|
8
|
-
guard: f.guard,
|
|
9
|
-
favorability: s.favorability,
|
|
10
|
-
is_optimal: false,
|
|
11
|
-
payoff_note: s.payoff,
|
|
12
|
-
risk: s.risk,
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
actions.sort((a, b) => b.favorability - a.favorability);
|
|
16
|
-
if (actions.length > 0) {
|
|
17
|
-
actions[0].is_optimal = true;
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
current_node: input.current_node,
|
|
21
|
-
perspective: input.perspective,
|
|
22
|
-
actions,
|
|
23
|
-
summary: buildSummary(input, actions),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function scoreForward(f, perspective) {
|
|
27
|
-
const isCompletion = !!f.consequence?.startsWith("Completion");
|
|
28
|
-
const isRefund = !!f.consequence?.startsWith("Refund");
|
|
29
|
-
if (perspective === "customer") {
|
|
30
|
-
if (isRefund) {
|
|
31
|
-
return { favorability: 90, payoff: "funds return to you (refund/cancel path)", risk: "low" };
|
|
32
|
-
}
|
|
33
|
-
if (isCompletion) {
|
|
34
|
-
return { favorability: 40, payoff: "releases escrowed funds to the merchant — only confirm if the deliverable matches the agreement", risk: "high" };
|
|
35
|
-
}
|
|
36
|
-
return { favorability: 60, payoff: "advances the order to the next node", risk: "medium" };
|
|
37
|
-
}
|
|
38
|
-
if (perspective === "operator") {
|
|
39
|
-
if (isCompletion) {
|
|
40
|
-
return { favorability: 90, payoff: "settlement + shorter fund-settlement cycle", risk: "low" };
|
|
41
|
-
}
|
|
42
|
-
if (isRefund) {
|
|
43
|
-
return { favorability: 20, payoff: "refund — downside, recorded on-chain (arb-loss/stall stats)", risk: "high" };
|
|
44
|
-
}
|
|
45
|
-
return { favorability: 70, payoff: "advance the workflow to shorten settlement", risk: "low" };
|
|
46
|
-
}
|
|
47
|
-
return { favorability: 50, payoff: "neutral (observer)", risk: "medium" };
|
|
48
|
-
}
|
|
49
|
-
function buildSummary(input, actions) {
|
|
50
|
-
if (actions.length === 0) {
|
|
51
|
-
return input.waiting_on.length > 0
|
|
52
|
-
? `Waiting on ${input.waiting_on.map((w) => w.role).join(", ")}`
|
|
53
|
-
: `No operable actions at node '${input.current_node || "(entry)"}'`;
|
|
54
|
-
}
|
|
55
|
-
const top = actions[0];
|
|
56
|
-
return `Optimal for ${input.perspective}: '${top.forward}' → '${top.to_node}' (${top.payoff_note})`;
|
|
57
|
-
}
|
|
1
|
+
import{classifyOutcome,evaluateOutcome}from'./game-strategy.js';export function evaluateNodeGame(a){const b=a['operable']['map'](c=>{const d=scoreForward(c,a['perspective'],{'risk_appetite':a['appetite'],'requirements':a['requirements']},a['order_amount']);return{'forward':c['name'],'to_node':c['to_node'],'execution_path':c['execution_path'],'guard':c['guard'],'favorability':d['favorability'],'gain_score':d['gain_score'],'risk_score':d['risk_score'],'is_optimal':![],'payoff_note':d['payoff'],'risk':d['risk']};});return b['sort']((c,d)=>d['favorability']-c['favorability']),b['length']>0x0&&(b[0x0]['is_optimal']=!![]),{'current_node':a['current_node'],'perspective':a['perspective'],'actions':b,'cooperation':evaluateCooperation(a),'value_at_stake':a['order_amount'],'risk_exposure':a['compensation_fund'],'summary':buildSummary(a,b)};}function evaluateCooperation(a){if(!a['threshold']||a['threshold']<=0x1)return undefined;const b=a['operable']['reduce']((g,h)=>g+(h['weight']??0x1),0x0),c=a['threshold']-b,d=c>0x0?a['waiting_on']['map'](f=>f['role']):[],e=a['allocation'];return{'threshold':a['threshold'],'my_weight':b,'needed_from_others':Math['max'](0x0,c),'collaborators':d,'allocation':e,'allocation_note':e?describeAllocation(e):undefined};}function describeAllocation(b){const c=['settlement\x20splits\x20across\x20'+b['recipient_slots']+'\x20recipient\x20slot(s)'];if(b['direct_to_me_slots']>0x0)c['push'](b['direct_to_me_slots']+'\x20pay\x20directly\x20to\x20you');if(b['guard_gated_slots']>0x0)c['push'](b['guard_gated_slots']+'\x20are\x20guard-resolved\x20(may\x20pay\x20a\x20cooperating\x20party)');if(b['to_payer_slots']>0x0)c['push'](b['to_payer_slots']+'\x20route\x20back\x20to\x20the\x20payer\x20(refund-oriented)');return c['join'](';\x20')+'.';}function scoreForward(a,b,c,d){const e=classifyOutcome(a['consequence']),g=evaluateOutcome(e,b,c);return{'favorability':g['net_score'],'gain_score':g['gain_score'],'risk_score':g['risk_score'],'payoff':payoffNote(e,b,d),'risk':riskOf(e,b)};}function amountSuffix(a){return a!=null?'\x20('+a+'\x20raw\x20units)':'';}function payoffNote(a,b,c){if(b==='customer'||b==='prospect')switch(a){case'refund':return'funds\x20return\x20to\x20you'+amountSuffix(c)+'\x20(refund/cancel\x20path)';case'completion':return'releases\x20escrowed\x20funds'+amountSuffix(c)+'\x20to\x20the\x20merchant\x20—\x20only\x20confirm\x20if\x20the\x20deliverable\x20matches\x20the\x20agreement';case'advance':return'advances\x20the\x20order\x20to\x20the\x20next\x20node\x20(funds'+amountSuffix(c)+'\x20stay\x20escrowed)';}if(b==='merchant'||b==='collaborator'||b==='supplier')switch(a){case'completion':return'settlement'+amountSuffix(c)+'\x20released\x20to\x20you\x20+\x20shorter\x20fund-settlement\x20cycle';case'refund':return'refund'+amountSuffix(c)+'\x20—\x20downside,\x20recorded\x20on-chain\x20(arb-loss/stall\x20stats)';case'advance':return'advance\x20the\x20workflow\x20to\x20shorten\x20settlement'+amountSuffix(c);}return'neutral\x20for\x20'+b;}function riskOf(a,b){if(b==='customer'||b==='prospect'){if(a==='completion')return'high';if(a==='refund')return'low';return'medium';}if(b==='merchant'||b==='collaborator'||b==='supplier'){if(a==='refund')return'high';return'low';}return'medium';}function buildSummary(a,b){if(b['length']===0x0)return a['waiting_on']['length']>0x0?'Waiting\x20on\x20'+a['waiting_on']['map'](e=>e['role'])['join'](',\x20'):'No\x20operable\x20actions\x20at\x20node\x20\x27'+(a['current_node']||'(entry)')+'\x27';const c=b[0x0];let d='Optimal\x20for\x20'+a['perspective']+':\x20\x27'+c['forward']+'\x27\x20→\x20\x27'+c['to_node']+'\x27\x20('+c['payoff_note']+')';return b['length']>0x1&&(d+='\x20—\x20choosing\x20this\x20closes\x20the\x20other\x20'+(b['length']-0x1)+'\x20option(s)\x20(opportunity\x20competition:\x20your\x20gain\x20may\x20be\x20another\x20role\x27s\x20lost\x20chance).'),d;}
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
const REMOTE_KEYWORDS =
|
|
2
|
-
export function parseRegion(raw) {
|
|
3
|
-
const trimmed = raw?.trim() ?? "";
|
|
4
|
-
const lower = trimmed.toLowerCase();
|
|
5
|
-
const isRemote = REMOTE_KEYWORDS.some((k) => lower.includes(k));
|
|
6
|
-
if (isRemote) {
|
|
7
|
-
return { mode: "remote", raw: trimmed };
|
|
8
|
-
}
|
|
9
|
-
return { mode: "physical", raw: trimmed };
|
|
10
|
-
}
|
|
11
|
-
export function relateRegion(a, b) {
|
|
12
|
-
if (a.mode === "remote" || b.mode === "remote") {
|
|
13
|
-
return "compatible";
|
|
14
|
-
}
|
|
15
|
-
const na = normalizePhysical(a.raw);
|
|
16
|
-
const nb = normalizePhysical(b.raw);
|
|
17
|
-
if (!na || !nb) {
|
|
18
|
-
return "mismatch";
|
|
19
|
-
}
|
|
20
|
-
if (na === nb) {
|
|
21
|
-
return "exact";
|
|
22
|
-
}
|
|
23
|
-
if (na.includes(nb) || nb.includes(na)) {
|
|
24
|
-
return "contains";
|
|
25
|
-
}
|
|
26
|
-
if (a.province && b.province && a.province === b.province) {
|
|
27
|
-
return "overlap";
|
|
28
|
-
}
|
|
29
|
-
return "mismatch";
|
|
30
|
-
}
|
|
31
|
-
function normalizePhysical(raw) {
|
|
32
|
-
return raw
|
|
33
|
-
.trim()
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.replace(/\s+/g, "");
|
|
36
|
-
}
|
|
1
|
+
const REMOTE_KEYWORDS=['remote','online','anywhere'];export function parseRegion(a){const b=a?.['trim']()??'',c=b['toLowerCase'](),d=REMOTE_KEYWORDS['some'](e=>c['includes'](e));if(d)return{'mode':'remote','raw':b};return{'mode':'physical','raw':b};}export function relateRegion(c,d){if(c['mode']==='remote'||d['mode']==='remote')return'compatible';const e=normalizePhysical(c['raw']),f=normalizePhysical(d['raw']);if(!e||!f)return'mismatch';if(e===f)return'exact';if(e['includes'](f)||f['includes'](e))return'contains';if(c['province']&&d['province']&&c['province']===d['province'])return'overlap';return'mismatch';}function normalizePhysical(a){return a['trim']()['toLowerCase']()['replace'](/\s+/g,'');}
|
package/dist/evaluation/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{};
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
export const REQUIREMENT_PASS_THRESHOLD =
|
|
2
|
-
export function normalizeInjection(injection) {
|
|
3
|
-
return {
|
|
4
|
-
intent: injection?.intent,
|
|
5
|
-
preferences: injection?.preferences,
|
|
6
|
-
requirements: injection?.requirements ?? [],
|
|
7
|
-
overrides: injection?.overrides ?? {},
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export function isRuleEnabled(ruleId, injection) {
|
|
11
|
-
const override = injection?.overrides?.rules?.[ruleId];
|
|
12
|
-
if (override && override.enabled !== undefined)
|
|
13
|
-
return override.enabled;
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
export function isDataSourceEnabled(dataSourceId, injection) {
|
|
17
|
-
const override = injection?.overrides?.data_sources?.[dataSourceId];
|
|
18
|
-
if (override && override.enabled !== undefined)
|
|
19
|
-
return override.enabled;
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
export function effectiveWeight(rule, injection) {
|
|
23
|
-
const override = injection?.overrides?.rules?.[rule.id];
|
|
24
|
-
if (override && override.weight !== undefined)
|
|
25
|
-
return override.weight;
|
|
26
|
-
return rule.weight;
|
|
27
|
-
}
|
|
1
|
+
export const REQUIREMENT_PASS_THRESHOLD=0x3c;export function normalizeInjection(a){return{'intent':a?.['intent'],'preferences':a?.['preferences'],'requirements':a?.['requirements']??[],'overrides':a?.['overrides']??{}};}export function isRuleEnabled(a,b){const c=b?.['overrides']?.['rules']?.[a];if(c&&c['enabled']!==undefined)return c['enabled'];return!![];}export function isDataSourceEnabled(a,b){const c=b?.['overrides']?.['data_sources']?.[a];if(c&&c['enabled']!==undefined)return c['enabled'];return!![];}export function effectiveWeight(a,b){const c=b?.['overrides']?.['rules']?.[a['id']];if(c&&c['weight']!==undefined)return c['weight'];return a['weight'];}
|
|
@@ -1,103 +1 @@
|
|
|
1
|
-
import { extractSignals }
|
|
2
|
-
const MAX_HISTORY = 200;
|
|
3
|
-
const history = [];
|
|
4
|
-
export function recordSignature(sig) {
|
|
5
|
-
try {
|
|
6
|
-
history.push(sig);
|
|
7
|
-
if (history.length > MAX_HISTORY) {
|
|
8
|
-
history.shift();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function findMatches(intent, operation_type, data, limit = 3) {
|
|
15
|
-
try {
|
|
16
|
-
const currentSignals = extractSignals(operation_type, data);
|
|
17
|
-
const now = Date.now();
|
|
18
|
-
const scored = history
|
|
19
|
-
.map((sig) => {
|
|
20
|
-
const relevance = computeRelevance(sig, intent, currentSignals, now);
|
|
21
|
-
return { signature: sig, relevance };
|
|
22
|
-
})
|
|
23
|
-
.filter((s) => s.relevance > 0.3)
|
|
24
|
-
.sort((a, b) => b.relevance - a.relevance)
|
|
25
|
-
.slice(0, limit);
|
|
26
|
-
return scored.map((s) => formatMatch(s.signature, s.relevance));
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function computeRelevance(sig, currentIntent, currentSignals, now) {
|
|
33
|
-
let score = 0;
|
|
34
|
-
if (sig.intent === currentIntent) {
|
|
35
|
-
score += 0.5;
|
|
36
|
-
}
|
|
37
|
-
else if (sig.intent.startsWith(currentIntent.split("_")[0])) {
|
|
38
|
-
score += 0.2;
|
|
39
|
-
}
|
|
40
|
-
const sigKeys = Object.keys(sig.signals);
|
|
41
|
-
if (sigKeys.length > 0) {
|
|
42
|
-
const overlap = sigKeys.filter((k) => {
|
|
43
|
-
const sigVal = JSON.stringify(sig.signals[k]);
|
|
44
|
-
const curVal = JSON.stringify(currentSignals[k]);
|
|
45
|
-
return sigVal === curVal;
|
|
46
|
-
}).length;
|
|
47
|
-
score += (overlap / sigKeys.length) * 0.3;
|
|
48
|
-
}
|
|
49
|
-
const ageDays = (now - sig.timestamp) / (1000 * 60 * 60 * 24);
|
|
50
|
-
const decay = Math.exp(-ageDays / 30);
|
|
51
|
-
score *= decay;
|
|
52
|
-
return Math.min(1, score);
|
|
53
|
-
}
|
|
54
|
-
function formatMatch(sig, relevance) {
|
|
55
|
-
const advice = buildAdvice(sig);
|
|
56
|
-
const avoid = buildAvoid(sig);
|
|
57
|
-
return {
|
|
58
|
-
signature: sig,
|
|
59
|
-
relevance,
|
|
60
|
-
advice,
|
|
61
|
-
avoid,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function buildAdvice(sig) {
|
|
65
|
-
if (sig.outcome === "success") {
|
|
66
|
-
if (sig.recovery_path && sig.recovery_path.length > 0) {
|
|
67
|
-
return `Last ${sig.intent} succeeded (after ${sig.recovery_path.length} recovery steps), you can follow the same path.`;
|
|
68
|
-
}
|
|
69
|
-
return `Last ${sig.intent} succeeded, parameter configuration is valid.`;
|
|
70
|
-
}
|
|
71
|
-
if (sig.outcome === "failed" && sig.error_code) {
|
|
72
|
-
return `Last ${sig.intent} failed (${sig.error_code}), please check the relevant parameters.`;
|
|
73
|
-
}
|
|
74
|
-
return `Last ${sig.intent} partially succeeded, check result completeness.`;
|
|
75
|
-
}
|
|
76
|
-
function buildAvoid(sig) {
|
|
77
|
-
const avoid = [];
|
|
78
|
-
if (sig.outcome !== "success" && sig.error_code) {
|
|
79
|
-
avoid.push(`Avoid triggering ${sig.error_code} error`);
|
|
80
|
-
}
|
|
81
|
-
if (sig.recovery_path && sig.recovery_path.length > 0) {
|
|
82
|
-
avoid.push(`Note: last time required ${sig.recovery_path.length} recovery steps to succeed`);
|
|
83
|
-
}
|
|
84
|
-
return avoid;
|
|
85
|
-
}
|
|
86
|
-
export function getHistory(intent) {
|
|
87
|
-
if (intent) {
|
|
88
|
-
return history.filter((h) => h.intent === intent);
|
|
89
|
-
}
|
|
90
|
-
return [...history];
|
|
91
|
-
}
|
|
92
|
-
export function clearHistory() {
|
|
93
|
-
history.length = 0;
|
|
94
|
-
}
|
|
95
|
-
export function getHistoryStats() {
|
|
96
|
-
const byOutcome = {};
|
|
97
|
-
const byIntent = {};
|
|
98
|
-
for (const h of history) {
|
|
99
|
-
byOutcome[h.outcome] = (byOutcome[h.outcome] ?? 0) + 1;
|
|
100
|
-
byIntent[h.intent] = (byIntent[h.intent] ?? 0) + 1;
|
|
101
|
-
}
|
|
102
|
-
return { total: history.length, by_outcome: byOutcome, by_intent: byIntent };
|
|
103
|
-
}
|
|
1
|
+
import{extractSignals}from'./intent-distill.js';const MAX_HISTORY=0xc8,history=[];export function recordSignature(a){try{history['push'](a),history['length']>MAX_HISTORY&&history['shift']();}catch{}}export function findMatches(a,b,c,d=0x3){try{const e=extractSignals(b,c),f=Date['now'](),g=history['map'](h=>{const i=computeRelevance(h,a,e,f);return{'signature':h,'relevance':i};})['filter'](h=>h['relevance']>0.3)['sort']((h,i)=>i['relevance']-h['relevance'])['slice'](0x0,d);return g['map'](h=>formatMatch(h['signature'],h['relevance']));}catch{return[];}}function computeRelevance(a,b,c,d){let e=0x0;if(a['intent']===b)e+=0.5;else a['intent']['startsWith'](b['split']('_')[0x0])&&(e+=0.2);const f=Object['keys'](a['signals']);if(f['length']>0x0){const i=f['filter'](j=>{const l=JSON['stringify'](a['signals'][j]),m=JSON['stringify'](c[j]);return l===m;})['length'];e+=i/f['length']*0.3;}const g=(d-a['timestamp'])/(0x3e8*0x3c*0x3c*0x18),h=Math['exp'](-g/0x1e);return e*=h,Math['min'](0x1,e);}function formatMatch(a,b){const c=buildAdvice(a),d=buildAvoid(a);return{'signature':a,'relevance':b,'advice':c,'avoid':d};}function buildAdvice(a){if(a['outcome']==='success'){if(a['recovery_path']&&a['recovery_path']['length']>0x0)return'Last\x20'+a['intent']+'\x20succeeded\x20(after\x20'+a['recovery_path']['length']+'\x20recovery\x20steps),\x20you\x20can\x20follow\x20the\x20same\x20path.';return'Last\x20'+a['intent']+'\x20succeeded,\x20parameter\x20configuration\x20is\x20valid.';}if(a['outcome']==='failed'&&a['error_code'])return'Last\x20'+a['intent']+'\x20failed\x20('+a['error_code']+'),\x20please\x20check\x20the\x20relevant\x20parameters.';return'Last\x20'+a['intent']+'\x20partially\x20succeeded,\x20check\x20result\x20completeness.';}function buildAvoid(a){const b=[];return a['outcome']!=='success'&&a['error_code']&&b['push']('Avoid\x20triggering\x20'+a['error_code']+'\x20error'),a['recovery_path']&&a['recovery_path']['length']>0x0&&b['push']('Note:\x20last\x20time\x20required\x20'+a['recovery_path']['length']+'\x20recovery\x20steps\x20to\x20succeed'),b;}export function getHistory(a){if(a)return history['filter'](b=>b['intent']===a);return[...history];}export function clearHistory(){history['length']=0x0;}export function getHistoryStats(){const a={},b={};for(const c of history){a[c['outcome']]=(a[c['outcome']]??0x0)+0x1,b[c['intent']]=(b[c['intent']]??0x0)+0x1;}return{'total':history['length'],'by_outcome':a,'by_intent':b};}
|
package/dist/experience/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getProfile, updateFromOperation, resetProfile, getProfileStats, } from "./user-profile.js";
|
|
3
|
-
import { findMatches, recordSignature, getHistory, clearHistory, getHistoryStats, } from "./experience-reuse.js";
|
|
4
|
-
import { getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION, } from "./realtime-feedback.js";
|
|
5
|
-
export { distillIntent, extractSignals, getProfile, updateFromOperation, resetProfile, getProfileStats, findMatches, recordSignature, getHistory, clearHistory, getHistoryStats, getExperienceFeedback, recordOperationOutcome, EXPERIENCE_LAYER_VERSION, };
|
|
1
|
+
import{distillIntent,extractSignals}from'./intent-distill.js';import{getProfile,updateFromOperation,resetProfile,getProfileStats}from'./user-profile.js';import{findMatches,recordSignature,getHistory,clearHistory,getHistoryStats}from'./experience-reuse.js';import{getExperienceFeedback,recordOperationOutcome,EXPERIENCE_LAYER_VERSION}from'./realtime-feedback.js';export{distillIntent,extractSignals,getProfile,updateFromOperation,resetProfile,getProfileStats,findMatches,recordSignature,getHistory,clearHistory,getHistoryStats,getExperienceFeedback,recordOperationOutcome,EXPERIENCE_LAYER_VERSION};
|
|
@@ -1,83 +1 @@
|
|
|
1
|
-
const URGENCY_RULES = [
|
|
2
|
-
{ operation_type: "payment", urgency: "critical" },
|
|
3
|
-
{ operation_type: "service", signals: (d) => d?.publish === true, urgency: "critical" },
|
|
4
|
-
{ operation_type: "arbitration", signals: (d) => d?.arb === true || d?.arb_operation === "raise", urgency: "critical" },
|
|
5
|
-
{ operation_type: "reward", urgency: "high" },
|
|
6
|
-
{ operation_type: "allocation", urgency: "high" },
|
|
7
|
-
{ operation_type: "treasury", urgency: "high" },
|
|
8
|
-
{ operation_type: "order", urgency: "high" },
|
|
9
|
-
{ operation_type: "service", urgency: "normal" },
|
|
10
|
-
{ operation_type: "machine", urgency: "normal" },
|
|
11
|
-
{ operation_type: "guard", urgency: "normal" },
|
|
12
|
-
{ operation_type: "permission", urgency: "normal" },
|
|
13
|
-
{ operation_type: "progress", urgency: "normal" },
|
|
14
|
-
{ operation_type: "repository", urgency: "normal" },
|
|
15
|
-
{ operation_type: "personal", urgency: "normal" },
|
|
16
|
-
{ operation_type: "contact", urgency: "normal" },
|
|
17
|
-
{ operation_type: "demand", urgency: "normal" },
|
|
18
|
-
{ operation_type: "query_toolkit", urgency: "low" },
|
|
19
|
-
{ operation_type: "onchain_events", urgency: "low" },
|
|
20
|
-
{ operation_type: "onchain_table_data", urgency: "low" },
|
|
21
|
-
{ operation_type: "account_balance", urgency: "low" },
|
|
22
|
-
{ operation_type: "mark_query", urgency: "low" },
|
|
23
|
-
{ operation_type: "local_info", urgency: "low" },
|
|
24
|
-
];
|
|
25
|
-
const SCENARIO_RULES = [
|
|
26
|
-
{ signals: (d) => typeof d?.description === "string" && /freelance|freelancer|design|development|outsourcing/i.test(d.description), scenario: "freelance" },
|
|
27
|
-
{ signals: (d) => typeof d?.description === "string" && /rental|rent|lease/i.test(d.description), scenario: "rental" },
|
|
28
|
-
{ signals: (d) => typeof d?.description === "string" && /course|education|training/i.test(d.description), scenario: "education" },
|
|
29
|
-
{ signals: (d) => typeof d?.description === "string" && /travel|tour|trip/i.test(d.description), scenario: "travel" },
|
|
30
|
-
{ signals: (d) => typeof d?.description === "string" && /subscri|subscription|membership/i.test(d.description), scenario: "subscription" },
|
|
31
|
-
{ signals: (d) => typeof d?.namedNew?.name === "string" && /shop|store|retail/i.test(d.namedNew.name), scenario: "retail" },
|
|
32
|
-
];
|
|
33
|
-
const SECONDARY_INTENT_RULES = [
|
|
34
|
-
{ signals: (d) => d?.publish === true, intent: "immutable_commit" },
|
|
35
|
-
{ signals: (d) => d?.amount?.amount !== undefined && BigInt(d.amount.amount) > 100000000000n, intent: "large_amount" },
|
|
36
|
-
{ signals: (d) => d?.replaceExistName === true, intent: "force_claim_name" },
|
|
37
|
-
{ signals: (d) => d?.arb !== undefined, intent: "dispute_resolution" },
|
|
38
|
-
{ signals: (d) => d?.onChain === true, intent: "public_identity" },
|
|
39
|
-
];
|
|
40
|
-
export function distillIntent(operation_type, data, baseIntent) {
|
|
41
|
-
const urgencyRules = URGENCY_RULES.filter((r) => r.operation_type === operation_type);
|
|
42
|
-
const signaled = urgencyRules.find((r) => r.signals && r.signals(data));
|
|
43
|
-
const urgency = (signaled ?? urgencyRules.find((r) => !r.signals))?.urgency ?? "normal";
|
|
44
|
-
const scenarioRule = SCENARIO_RULES.find((r) => r.signals(data));
|
|
45
|
-
const scenario = scenarioRule?.scenario;
|
|
46
|
-
const secondary_intents = SECONDARY_INTENT_RULES
|
|
47
|
-
.filter((r) => r.signals(data))
|
|
48
|
-
.map((r) => r.intent);
|
|
49
|
-
let confidence = 0.8;
|
|
50
|
-
if (scenario)
|
|
51
|
-
confidence = Math.min(1, confidence + 0.1);
|
|
52
|
-
if (secondary_intents.length > 0)
|
|
53
|
-
confidence = Math.min(1, confidence + 0.05);
|
|
54
|
-
if (baseIntent === operation_type)
|
|
55
|
-
confidence -= 0.15;
|
|
56
|
-
return {
|
|
57
|
-
primary_intent: baseIntent,
|
|
58
|
-
secondary_intents,
|
|
59
|
-
confidence: Math.max(0, confidence),
|
|
60
|
-
urgency,
|
|
61
|
-
scenario,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
export function extractSignals(operation_type, data) {
|
|
65
|
-
const signals = {};
|
|
66
|
-
if (!data || typeof data !== "object")
|
|
67
|
-
return signals;
|
|
68
|
-
const keys = ["publish", "amount", "price", "arb", "service", "machine", "order", "reward", "guard", "permission", "replaceExistName", "onChain", "type_parameter"];
|
|
69
|
-
for (const k of keys) {
|
|
70
|
-
if (data[k] !== undefined) {
|
|
71
|
-
signals[k] = data[k];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (operation_type === "service") {
|
|
75
|
-
if (data.namedNew?.name)
|
|
76
|
-
signals.name = data.namedNew.name;
|
|
77
|
-
}
|
|
78
|
-
if (operation_type === "payment" || operation_type === "reward") {
|
|
79
|
-
if (data.amount?.amount)
|
|
80
|
-
signals.amount_value = data.amount.amount;
|
|
81
|
-
}
|
|
82
|
-
return signals;
|
|
83
|
-
}
|
|
1
|
+
const URGENCY_RULES=[{'operation_type':'payment','urgency':'critical'},{'operation_type':'service','signals':a=>a?.['publish']===!![],'urgency':'critical'},{'operation_type':'arbitration','signals':a=>a?.['arb']===!![]||a?.['arb_operation']==='raise','urgency':'critical'},{'operation_type':'reward','urgency':'high'},{'operation_type':'allocation','urgency':'high'},{'operation_type':'treasury','urgency':'high'},{'operation_type':'order','urgency':'high'},{'operation_type':'service','urgency':'normal'},{'operation_type':'machine','urgency':'normal'},{'operation_type':'guard','urgency':'normal'},{'operation_type':'permission','urgency':'normal'},{'operation_type':'progress','urgency':'normal'},{'operation_type':'repository','urgency':'normal'},{'operation_type':'personal','urgency':'normal'},{'operation_type':'contact','urgency':'normal'},{'operation_type':'demand','urgency':'normal'},{'operation_type':'query_toolkit','urgency':'low'},{'operation_type':'onchain_events','urgency':'low'},{'operation_type':'onchain_table_data','urgency':'low'},{'operation_type':'account_balance','urgency':'low'},{'operation_type':'mark_query','urgency':'low'},{'operation_type':'local_info','urgency':'low'}],SCENARIO_RULES=[{'signals':a=>typeof a?.['description']==='string'&&/freelance|freelancer|design|development|outsourcing/i['test'](a['description']),'scenario':'freelance'},{'signals':a=>typeof a?.['description']==='string'&&/rental|rent|lease/i['test'](a['description']),'scenario':'rental'},{'signals':a=>typeof a?.['description']==='string'&&/course|education|training/i['test'](a['description']),'scenario':'education'},{'signals':a=>typeof a?.['description']==='string'&&/travel|tour|trip/i['test'](a['description']),'scenario':'travel'},{'signals':a=>typeof a?.['description']==='string'&&/subscri|subscription|membership/i['test'](a['description']),'scenario':'subscription'},{'signals':a=>typeof a?.['namedNew']?.['name']==='string'&&/shop|store|retail/i['test'](a['namedNew']['name']),'scenario':'retail'}],SECONDARY_INTENT_RULES=[{'signals':a=>a?.['publish']===!![],'intent':'immutable_commit'},{'signals':a=>a?.['amount']?.['amount']!==undefined&&BigInt(a['amount']['amount'])>0x174876e800n,'intent':'large_amount'},{'signals':a=>a?.['replaceExistName']===!![],'intent':'force_claim_name'},{'signals':a=>a?.['arb']!==undefined,'intent':'dispute_resolution'},{'signals':a=>a?.['onChain']===!![],'intent':'public_identity'}];export function distillIntent(a,b,c){const d=URGENCY_RULES['filter'](k=>k['operation_type']===a),e=d['find'](k=>k['signals']&&k['signals'](b)),f=(e??d['find'](k=>!k['signals']))?.['urgency']??'normal',g=SCENARIO_RULES['find'](k=>k['signals'](b)),h=g?.['scenario'],i=SECONDARY_INTENT_RULES['filter'](k=>k['signals'](b))['map'](k=>k['intent']);let j=0.8;if(h)j=Math['min'](0x1,j+0.1);if(i['length']>0x0)j=Math['min'](0x1,j+0.05);if(c===a)j-=0.15;return{'primary_intent':c,'secondary_intents':i,'confidence':Math['max'](0x0,j),'urgency':f,'scenario':h};}export function extractSignals(a,b){const c={};if(!b||typeof b!=='object')return c;const d=['publish','amount','price','arb','service','machine','order','reward','guard','permission','replaceExistName','onChain','type_parameter'];for(const e of d){b[e]!==undefined&&(c[e]=b[e]);}if(a==='service'){if(b['namedNew']?.['name'])c['name']=b['namedNew']['name'];}if(a==='payment'||a==='reward'){if(b['amount']?.['amount'])c['amount_value']=b['amount']['amount'];}return c;}
|