@wowok/agent-mcp 2.7.10 → 3.0.1
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/communication/evidence.d.ts +6 -0
- package/dist/communication/evidence.js +1 -0
- package/dist/evaluation/acceptance.d.ts +24 -0
- package/dist/evaluation/acceptance.js +1 -0
- package/dist/evaluation/builtins/demand-match.d.ts +3 -2
- package/dist/evaluation/builtins/demand-match.js +1 -1
- package/dist/evaluation/builtins/service-risk.d.ts +2 -1
- package/dist/evaluation/builtins/service-risk.js +1 -1
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.js +1 -1
- package/dist/evaluation/match-operation.d.ts +14 -0
- package/dist/evaluation/match-operation.js +1 -0
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/extensions/capability-manifest.d.ts +1 -82
- package/dist/extensions/capability-manifest.js +1 -1
- package/dist/extensions/constraint-registry.d.ts +6 -4
- package/dist/extensions/constraint-registry.js +1 -1
- package/dist/extensions/index.d.ts +4 -5
- package/dist/extensions/index.js +1 -1
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/extensions/metric-registry.d.ts +6 -4
- package/dist/extensions/metric-registry.js +1 -1
- package/dist/extensions/mode-evaluator.d.ts +2 -3
- package/dist/extensions/mode-evaluator.js +1 -1
- package/dist/extensions/modes.js +1 -1
- package/dist/extensions/registry.d.ts +3 -25
- package/dist/extensions/registry.js +1 -1
- package/dist/extensions/types.d.ts +0 -68
- package/dist/goal/GoalClassifier.js +1 -1
- package/dist/goal/GoalEngine.d.ts +44 -1
- package/dist/goal/GoalEngine.js +1 -1
- package/dist/goal/types.d.ts +5 -1
- package/dist/harness/auto-escalation.d.ts +0 -12
- package/dist/harness/auto-escalation.js +1 -1
- package/dist/harness/index.d.ts +1 -14
- package/dist/harness/index.js +1 -1
- package/dist/harness/types.d.ts +0 -38
- package/dist/keeper/KeeperScan.d.ts +39 -0
- package/dist/keeper/KeeperScan.js +1 -0
- package/dist/keeper/KeeperStore.d.ts +43 -0
- package/dist/keeper/KeeperStore.js +1 -0
- package/dist/keeper/detectors.d.ts +23 -0
- package/dist/keeper/detectors.js +1 -0
- package/dist/keeper/keeper.spec.d.ts +1 -0
- package/dist/keeper/keeper.spec.js +1 -0
- package/dist/keeper/types.d.ts +65 -0
- package/dist/keeper/types.js +1 -0
- package/dist/knowledge/account-marks.d.ts +1 -0
- package/dist/knowledge/account-marks.js +1 -1
- package/dist/knowledge/demand-risk.js +1 -1
- package/dist/knowledge/event-semantics.d.ts +3 -0
- package/dist/knowledge/event-semantics.js +1 -1
- package/dist/knowledge/event-semantics.spec.d.ts +1 -0
- package/dist/knowledge/event-semantics.spec.js +1 -0
- package/dist/knowledge/evidence-review.d.ts +23 -0
- package/dist/knowledge/evidence-review.js +1 -1
- package/dist/knowledge/examples-scanner-cli.js +1 -1
- package/dist/knowledge/examples-scanner.js +1 -1
- package/dist/knowledge/fund-layer.d.ts +13 -9
- package/dist/knowledge/fund-layer.js +1 -1
- package/dist/knowledge/goal-completion.js +1 -1
- package/dist/knowledge/guard-bindings.d.ts +21 -0
- package/dist/knowledge/guard-bindings.js +1 -0
- package/dist/knowledge/guard-bytecode-spec.d.ts +82 -0
- package/dist/knowledge/guard-bytecode-spec.js +1 -0
- package/dist/knowledge/guard-design-patterns.d.ts +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/index.d.ts +13 -7
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/mcp-schema-audit-cli.js +1 -1
- package/dist/knowledge/mcp-schema-audit.js +1 -1
- package/dist/knowledge/reward-risk.d.ts +1 -1
- package/dist/knowledge/reward-risk.js +1 -1
- package/dist/knowledge/safety-rules.d.ts +2 -1
- package/dist/knowledge/safety-rules.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +1 -1
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/scenario-topology.d.ts +43 -0
- package/dist/knowledge/scenario-topology.js +1 -0
- package/dist/knowledge/supply-chain.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/tools-reference.js +1 -1
- package/dist/knowledge/workflow-guidance.d.ts +55 -0
- package/dist/knowledge/workflow-guidance.js +1 -1
- package/dist/knowledge/workspace-lists.d.ts +1 -0
- package/dist/knowledge/workspace-lists.js +1 -1
- package/dist/monitor/MonitorLoop.d.ts +3 -0
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/monitor/ScopeResolver.js +1 -1
- package/dist/monitor/SuggestionBridge.d.ts +38 -0
- package/dist/monitor/SuggestionBridge.js +1 -0
- package/dist/monitor/SuggestionBridge.spec.d.ts +1 -0
- package/dist/monitor/SuggestionBridge.spec.js +1 -0
- package/dist/monitor/types.d.ts +0 -1
- package/dist/monitor/types.js +1 -1
- package/dist/participation/arbitrator-interest.d.ts +20 -0
- package/dist/participation/arbitrator-interest.js +1 -0
- package/dist/participation/demander-interest.d.ts +23 -0
- package/dist/participation/demander-interest.js +1 -0
- package/dist/participation/employee-kpi.d.ts +12 -0
- package/dist/participation/employee-kpi.js +1 -1
- package/dist/participation/employee-kpi.spec.d.ts +1 -0
- package/dist/participation/employee-kpi.spec.js +1 -0
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/context-assembly.js +1 -1
- package/dist/playbooks/service-build/machine-nodes.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/merchant-guide.d.ts +20 -0
- package/dist/playbooks/service-build/merchant-guide.js +1 -1
- package/dist/playbooks/service-build/mode-actions.d.ts +30 -12
- package/dist/playbooks/service-build/mode-actions.js +1 -1
- package/dist/playbooks/service-build/object-panorama.js +1 -1
- package/dist/playbooks/service-build/participation-radar.js +1 -1
- package/dist/playbooks/service-build/relationship-profile.d.ts +2 -0
- package/dist/playbooks/service-build/relationship-profile.js +1 -0
- package/dist/playbooks/service-build/semantic-graph.d.ts +5 -1
- package/dist/playbooks/service-build/semantic-graph.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/relationship/derivation.d.ts +94 -0
- package/dist/relationship/derivation.js +1 -0
- package/dist/relationship/derivation.spec.d.ts +1 -0
- package/dist/relationship/derivation.spec.js +1 -0
- package/dist/relationship/incentive.d.ts +38 -0
- package/dist/relationship/incentive.js +1 -0
- package/dist/relationship/index.d.ts +4 -0
- package/dist/relationship/index.js +1 -0
- package/dist/relationship/registry.d.ts +13 -0
- package/dist/relationship/registry.js +1 -0
- package/dist/relationship/types.d.ts +45 -0
- package/dist/relationship/types.js +1 -0
- package/dist/review/progress.js +1 -1
- package/dist/role/index.d.ts +2 -2
- package/dist/role/index.js +1 -1
- package/dist/role/model.d.ts +2 -1
- package/dist/role/model.js +1 -1
- package/dist/role/types.d.ts +5 -0
- package/dist/rules.d.ts +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/safety/preview.js +1 -1
- package/dist/schema/call/bridge.d.ts +25 -3
- package/dist/schema/call/bridge.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/employee/index.d.ts +61 -1
- package/dist/schema/employee/index.js +1 -1
- package/dist/schema/evaluation/index.d.ts +70 -5
- package/dist/schema/evaluation/index.js +1 -1
- package/dist/schema/goal/index.d.ts +40 -14
- package/dist/schema/goal/index.js +1 -1
- package/dist/schema/goal/planning.d.ts +6 -6
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -1
- package/dist/schema/industry-pack/index.d.ts +59 -7
- package/dist/schema/industry-pack/index.js +1 -1
- package/dist/schema/industry-pack/modes.d.ts +59 -7
- package/dist/schema/industry-pack/modes.js +1 -1
- package/dist/schema/intent-radar/index.d.ts +19 -19
- package/dist/schema/keeper/index.d.ts +475 -0
- package/dist/schema/keeper/index.js +1 -0
- package/dist/schema/local/index.d.ts +11 -0
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/messenger/index.d.ts +2 -0
- package/dist/schema/messenger/index.js +1 -1
- package/dist/schema/operations.d.ts +64 -16
- package/dist/schema/persona/index.d.ts +1 -1
- package/dist/schema/query/bi.d.ts +244 -16
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/query/index.d.ts +2 -2
- package/dist/schema/schema-query/index.d.ts +2 -11
- package/dist/schema/schema-query/index.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema/utils/skills-recommendation.js +1 -1
- package/dist/schema/watch/index.d.ts +4 -0
- package/dist/schema/watch/index.js +1 -1
- package/dist/schema-query-impl/index.d.ts +33 -14
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +29 -0
- package/dist/schemas/account_operation.schema.json +6 -2
- package/dist/schemas/bridge_operation.output.json +24 -1
- package/dist/schemas/bridge_operation.schema.json +73 -1
- package/dist/schemas/employee_operation.output.json +100 -0
- package/dist/schemas/employee_operation.schema.json +148 -5
- package/dist/schemas/evaluation_operation.output.json +135 -9
- package/dist/schemas/evaluation_operation.schema.json +176 -7
- package/dist/schemas/goal_operation.schema.json +76 -0
- package/dist/schemas/index.json +7 -1
- package/dist/schemas/industry_pack_operation.output.json +172 -27
- package/dist/schemas/industry_pack_operation.schema.json +19 -0
- package/dist/schemas/keeper_operation.output.json +1274 -0
- package/dist/schemas/keeper_operation.schema.json +359 -0
- package/dist/schemas/messenger_operation.schema.json +8 -0
- package/dist/schemas/onchain_events.output.json +1 -1
- package/dist/schemas/onchain_operations.schema.json +41 -41
- package/dist/schemas/onchain_operations_allocation.schema.json +4 -4
- package/dist/schemas/onchain_operations_arbitration.schema.json +3 -3
- package/dist/schemas/onchain_operations_contact.schema.json +2 -2
- package/dist/schemas/onchain_operations_demand.schema.json +2 -2
- package/dist/schemas/onchain_operations_machine.schema.json +2 -2
- package/dist/schemas/onchain_operations_order.schema.json +2 -2
- package/dist/schemas/onchain_operations_payment.schema.json +1 -1
- package/dist/schemas/onchain_operations_permission.schema.json +2 -2
- package/dist/schemas/onchain_operations_progress.schema.json +2 -2
- package/dist/schemas/onchain_operations_repository.schema.json +2 -2
- package/dist/schemas/onchain_operations_reward.schema.json +6 -6
- package/dist/schemas/onchain_operations_service.schema.json +7 -7
- package/dist/schemas/onchain_operations_treasury.schema.json +6 -6
- package/dist/schemas/onchain_table_data.output.json +71 -0
- package/dist/schemas/query_toolkit.output.json +485 -7
- package/dist/schemas/query_toolkit.schema.json +71 -0
- package/dist/schemas/schema_query.output.json +1 -64
- package/dist/schemas/schema_query.schema.json +18 -3
- package/dist/schemas/watch_operation.output.json +21 -1
- package/dist/task/ProcessStore.d.ts +18 -1
- package/dist/task/ProcessStore.js +1 -1
- package/dist/task/playbook.js +1 -1
- package/dist/task/types.d.ts +24 -0
- package/dist/tools/handlers/bridge.js +1 -1
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/employee.d.ts +6 -0
- package/dist/tools/handlers/employee.js +1 -1
- package/dist/tools/handlers/employee.spec.d.ts +1 -0
- package/dist/tools/handlers/employee.spec.js +1 -0
- package/dist/tools/handlers/evaluation.js +1 -1
- package/dist/tools/handlers/evaluation.spec.d.ts +1 -0
- package/dist/tools/handlers/evaluation.spec.js +1 -0
- package/dist/tools/handlers/goal.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/keeper.d.ts +12 -0
- package/dist/tools/handlers/keeper.js +1 -0
- package/dist/tools/handlers/local.d.ts +4 -3
- package/dist/tools/handlers/local.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/permission.js +1 -1
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/handlers/schema-query.js +1 -1
- package/dist/tools/handlers/watch.js +1 -1
- package/dist/tools/handlers/workflow.js +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/registry/agent.d.ts +2 -0
- package/dist/tools/registry/agent.js +1 -0
- package/dist/tools/registry/bridge.d.ts +2 -0
- package/dist/tools/registry/bridge.js +1 -0
- package/dist/tools/registry/business.d.ts +2 -0
- package/dist/tools/registry/business.js +1 -0
- package/dist/tools/registry/config.d.ts +2 -0
- package/dist/tools/registry/config.js +1 -0
- package/dist/tools/registry/files.d.ts +2 -0
- package/dist/tools/registry/files.js +1 -0
- package/dist/tools/registry/identity.d.ts +2 -0
- package/dist/tools/registry/identity.js +1 -0
- package/dist/tools/registry/local.d.ts +2 -0
- package/dist/tools/registry/local.js +1 -0
- package/dist/tools/registry/messenger.d.ts +2 -0
- package/dist/tools/registry/messenger.js +1 -0
- package/dist/tools/registry/monitor.d.ts +2 -0
- package/dist/tools/registry/monitor.js +1 -0
- package/dist/tools/registry/onchain.d.ts +2 -0
- package/dist/tools/registry/onchain.js +1 -0
- package/dist/tools/registry/query.d.ts +2 -0
- package/dist/tools/registry/query.js +1 -0
- package/dist/tools/registry/trust.d.ts +2 -0
- package/dist/tools/registry/trust.js +1 -0
- package/dist/tools/rules-hook.d.ts +1 -0
- package/dist/tools/rules-hook.js +1 -1
- package/dist/tools/shared.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
- package/dist/examples/arbitration-dispute-create.json +0 -41
- package/dist/examples/arbitration-vote-weighted.json +0 -35
- package/dist/examples/arbitration-voting-guard-add.json +0 -38
- package/dist/examples/demand-present-service.json +0 -33
- package/dist/examples/education-contact-create.json +0 -40
- package/dist/examples/freelance-contact-create.json +0 -40
- package/dist/examples/gen-passport-verify-guard.json +0 -48
- package/dist/examples/guard-template-balance-check.json +0 -59
- package/dist/examples/guard-template-time-lock.json +0 -60
- package/dist/examples/insurance-guard-claim-timelock.json +0 -75
- package/dist/examples/insurance-guard-withdraw-allocation.json +0 -96
- package/dist/examples/insurance-machine-create.json +0 -75
- package/dist/examples/insurance-service-allocators.json +0 -55
- package/dist/examples/machine-multisig-threshold.json +0 -87
- package/dist/examples/machine-publish.json +0 -30
- package/dist/examples/machine-template-7node-rental.json +0 -119
- package/dist/examples/payment-scenario-bound.json +0 -45
- package/dist/examples/rental-ziroom-machine-create.json +0 -148
- package/dist/examples/rental-ziroom-permission-create.json +0 -41
- package/dist/examples/rental-ziroom-service-create.json +0 -36
- package/dist/examples/retail-adv-guard-customer-win-create.json +0 -80
- package/dist/examples/retail-adv-guard-messenger-proof-create.json +0 -65
- package/dist/examples/retail-adv-guard-reward-timeout-create.json +0 -92
- package/dist/examples/retail-adv-reward-guard-add.json +0 -51
- package/dist/examples/retail-myshop-allocation-activate.json +0 -55
- package/dist/examples/retail-myshop-arbitration-create.json +0 -40
- package/dist/examples/retail-myshop-contact-create.json +0 -43
- package/dist/examples/retail-myshop-order-create.json +0 -56
- package/dist/examples/retail-myshop-progress-operate.json +0 -38
- package/dist/examples/retail-myshop-reward-create.json +0 -35
- package/dist/examples/retail-myshop-service-create.json +0 -38
- package/dist/examples/retail-myshop-service-customer-required.json +0 -31
- package/dist/examples/service-discount-issue.json +0 -46
- package/dist/examples/subscription-contact-create.json +0 -40
- package/dist/examples/threebody-guard-create.json +0 -56
- package/dist/examples/threebody-machine-create.json +0 -71
- package/dist/examples/threebody-permission-create.json +0 -38
- package/dist/examples/threebody-service-allocators.json +0 -48
- package/dist/examples/travel-guard-time-lock.json +0 -69
- package/dist/examples/travel-guard-weather-oracle.json +0 -70
- package/dist/examples/travel-machine-create.json +0 -135
- package/dist/examples/travel-repository-create.json +0 -47
- package/dist/examples/travel-service-create.json +0 -34
- package/dist/examples/travel-treasury-create.json +0 -34
- package/dist/examples/treasury-deposit.json +0 -37
- package/dist/examples/treasury-withdraw.json +0 -38
- package/dist/harness/plan.d.ts +0 -33
- package/dist/harness/plan.js +0 -1
- package/dist/knowledge/demand-matching.d.ts +0 -29
- package/dist/knowledge/demand-matching.js +0 -1
- package/dist/knowledge/guard-context.d.ts +0 -56
- package/dist/knowledge/guard-context.js +0 -1
- package/dist/knowledge/guard-migration.d.ts +0 -48
- package/dist/knowledge/guard-migration.js +0 -1
- package/dist/mode-market/index.d.ts +0 -3
- package/dist/mode-market/index.js +0 -1
- package/dist/mode-market/registry.d.ts +0 -53
- package/dist/mode-market/registry.js +0 -1
- package/dist/mode-market/review.d.ts +0 -27
- package/dist/mode-market/review.js +0 -1
- package/dist/mode-market/submission.d.ts +0 -25
- package/dist/mode-market/submission.js +0 -1
- package/dist/schemas/guard-node-schema.json +0 -1000
- package/dist/task/stage-gate.d.ts +0 -22
- package/dist/task/stage-gate.js +0 -1
|
@@ -18,6 +18,18 @@ export interface LiabilityResolution {
|
|
|
18
18
|
}
|
|
19
19
|
export declare function assessReactionKpi(node: string, assigned_at: number, advanced_at: number | undefined, budget_ms?: number): ReactionKpi;
|
|
20
20
|
export declare function resolveLiability(liability: EmployeeLiability, loss_amount: number, hybrid_threshold?: number): LiabilityResolution;
|
|
21
|
+
export interface NodeTiming {
|
|
22
|
+
node: string;
|
|
23
|
+
assigned_at?: number;
|
|
24
|
+
advanced_at?: number;
|
|
25
|
+
source: "monitor_events" | "none";
|
|
26
|
+
gap?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function deriveNodeTiming(timeline: Array<{
|
|
29
|
+
node?: string;
|
|
30
|
+
time: number;
|
|
31
|
+
hold?: boolean | null;
|
|
32
|
+
}>, node: string): NodeTiming;
|
|
21
33
|
export interface EmployeeProfileValidation {
|
|
22
34
|
valid: boolean;
|
|
23
35
|
issues: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const DEFAULT_RESPONSE_BUDGET_MS=0x30*0x3c*0x3c*0x3e8;export function assessReactionKpi(a,b,c,d=DEFAULT_RESPONSE_BUDGET_MS){if(c===undefined)return{'node':a,'reaction_ms':-0x1,'within_budget':![],'status':'warn'};const e=c-b,f=e<=d;return{'node':a,'reaction_ms':e,'within_budget':f,'status':f?'pass':'fail'};}export function resolveLiability(a,b,c=0x0){let d;switch(a){case'merchant_bears':d='merchant';break;case'self_bears':d='employee';break;case'hybrid':default:d=b>c?'employee':'merchant';break;}return{'bears':d,'must_compensate_before_resume':b>0x0,'note':d==='merchant'?'Merchant\x20bears\x20the\x20'+b+'\x20loss;\x20employee\x20error\x20is\x20attributed\x20to\x20the\x20merchant\x27s\x20problem\x20list\x20in\x20arbitration.':'Employee\x20bears\x20the\x20'+b+'\x20loss\x20(serious\x20negligence);\x20the\x20order\x20user\x20is\x20compensated\x20first,\x20then\x20the\x20workflow\x20resumes.'};}export function validateEmployeeProfile(a){const b=[];if(!a['department'])b['push']('department\x20is\x20required');if(!a['liability'])b['push']('liability\x20is\x20required');return a['response_time_budget_ms']!==undefined&&a['response_time_budget_ms']<=0x0&&b['push']('response_time_budget_ms\x20must\x20be\x20a\x20positive\x20number'),{'valid':b['length']===0x0,'issues':b};}
|
|
1
|
+
const DEFAULT_RESPONSE_BUDGET_MS=0x30*0x3c*0x3c*0x3e8;export function assessReactionKpi(a,b,c,d=DEFAULT_RESPONSE_BUDGET_MS){if(c===undefined)return{'node':a,'reaction_ms':-0x1,'within_budget':![],'status':'warn'};const e=c-b,f=e<=d;return{'node':a,'reaction_ms':e,'within_budget':f,'status':f?'pass':'fail'};}export function resolveLiability(a,b,c=0x0){let d;switch(a){case'merchant_bears':d='merchant';break;case'self_bears':d='employee';break;case'hybrid':default:d=b>c?'employee':'merchant';break;}return{'bears':d,'must_compensate_before_resume':b>0x0,'note':d==='merchant'?'Merchant\x20bears\x20the\x20'+b+'\x20loss;\x20employee\x20error\x20is\x20attributed\x20to\x20the\x20merchant\x27s\x20problem\x20list\x20in\x20arbitration.':'Employee\x20bears\x20the\x20'+b+'\x20loss\x20(serious\x20negligence);\x20the\x20order\x20user\x20is\x20compensated\x20first,\x20then\x20the\x20workflow\x20resumes.'};}export function deriveNodeTiming(a,b){const c=a['filter'](g=>g['hold']===undefined||g['hold']===null),d=c['findIndex'](g=>g['node']===b);if(d<0x0)return{'node':b,'source':'none','gap':'no\x20ProgressEvent\x20entering\x20node\x20\x27'+b+'\x27\x20in\x20the\x20monitored\x20timeline\x20—\x20the\x20node\x20may\x20not\x20be\x20reached\x20yet,\x20or\x20its\x20entry\x20predates\x20the\x20monitored\x20window;\x20supply\x20assigned_at/advanced_at\x20manually'};const e=c[d]['time'],f=d+0x1<c['length']?c[d+0x1]:undefined;return{'node':b,'assigned_at':e,'advanced_at':f?.['time'],'source':'monitor_events'};}export function validateEmployeeProfile(a){const b=[];if(!a['department'])b['push']('department\x20is\x20required');if(!a['liability'])b['push']('liability\x20is\x20required');return a['response_time_budget_ms']!==undefined&&a['response_time_budget_ms']<=0x0&&b['push']('response_time_budget_ms\x20must\x20be\x20a\x20positive\x20number'),{'valid':b['length']===0x0,'issues':b};}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{describe,expect,it}from'vitest';import{deriveNodeTiming}from'./employee-kpi.js';describe('deriveNodeTiming',()=>{it('middle\x20node:\x20assigned_at\x20=\x20entry,\x20advanced_at\x20=\x20exit\x20(next\x20entry)',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8},{'node':'preparing','time':0x7d0},{'node':'shipped','time':0x2328}],'preparing');expect(a)['toEqual']({'node':'preparing','assigned_at':0x7d0,'advanced_at':0x2328,'source':'monitor_events'});}),it('first\x20node:\x20assigned_at\x20=\x20its\x20own\x20entry\x20(not\x20a\x20pre-monitor\x20gap)',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8},{'node':'preparing','time':0x7d0}],'received');expect(a['assigned_at'])['toBe'](0x3e8),expect(a['advanced_at'])['toBe'](0x7d0),expect(a['source'])['toBe']('monitor_events'),expect(a['gap'])['toBeUndefined']();}),it('last\x20observed\x20node\x20is\x20still\x20current:\x20advanced_at\x20undefined\x20(still\x20waiting),\x20no\x20gap',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8},{'node':'preparing','time':0x7d0}],'preparing');expect(a['assigned_at'])['toBe'](0x7d0),expect(a['advanced_at'])['toBeUndefined'](),expect(a['source'])['toBe']('monitor_events'),expect(a['gap'])['toBeUndefined']();}),it('node\x20not\x20found:\x20source\x20none\x20+\x20actionable\x20gap',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8}],'preparing');expect(a['source'])['toBe']('none'),expect(a['assigned_at'])['toBeUndefined'](),expect(a['advanced_at'])['toBeUndefined'](),expect(a['gap'])['toMatch'](/no ProgressEvent entering node 'preparing'/),expect(a['gap'])['toMatch'](/manually/);}),it('empty\x20timeline:\x20source\x20none',()=>{const a=deriveNodeTiming([],'received');expect(a['source'])['toBe']('none');}),it('hold\x20signals\x20are\x20not\x20entries:\x20a\x20hold\x20TOWARD\x20the\x20target\x20is\x20not\x20its\x20entry',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8},{'node':'preparing','time':0x5dc,'hold':!![]},{'node':'preparing','time':0x7d0},{'node':'shipped','time':0x2328}],'preparing');expect(a['assigned_at'])['toBe'](0x7d0),expect(a['advanced_at'])['toBe'](0x2328);}),it('hold\x20signals\x20are\x20not\x20exits:\x20a\x20hold\x20after\x20entry\x20leaves\x20the\x20node\x20still\x20current',()=>{const a=deriveNodeTiming([{'node':'received','time':0x3e8},{'node':'preparing','time':0x7d0},{'node':'shipped','time':0x9c4,'hold':![]}],'preparing');expect(a['assigned_at'])['toBe'](0x7d0),expect(a['advanced_at'])['toBeUndefined']();}),it('repeated\x20passages:\x20measures\x20the\x20FIRST\x20passage\x20through\x20the\x20node',()=>{const a=deriveNodeTiming([{'node':'review','time':0x3e8},{'node':'rework','time':0x7d0},{'node':'review','time':0xbb8},{'node':'done','time':0xfa0}],'review');expect(a['assigned_at'])['toBe'](0x3e8),expect(a['advanced_at'])['toBe'](0x7d0);}),it('self-loop:\x20an\x20advance\x20into\x20the\x20same\x20node\x20counts\x20as\x20exit\x20of\x20the\x20first\x20passage',()=>{const a=deriveNodeTiming([{'node':'poll','time':0x3e8},{'node':'poll','time':0x7d0}],'poll');expect(a['assigned_at'])['toBe'](0x3e8),expect(a['advanced_at'])['toBe'](0x7d0);});});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{initServicePuzzleFromIntent,initMachinePuzzleFromIntent,initAllocationPuzzleFromIntent,initTreasuryPuzzleFromIntent,initArbitrationPuzzleFromIntent,initRewardPuzzleFromIntent,initProgressPuzzleFromIntent,initOrderPuzzleFromIntent,initPuzzleFromIntent as
|
|
1
|
+
import{initServicePuzzleFromIntent,initMachinePuzzleFromIntent,initAllocationPuzzleFromIntent,initTreasuryPuzzleFromIntent,initArbitrationPuzzleFromIntent,initRewardPuzzleFromIntent,initProgressPuzzleFromIntent,initOrderPuzzleFromIntent,initPuzzleFromIntent as a292a,checkServicePuzzleCompleteness,checkMachinePuzzleCompleteness,checkAllocationPuzzleCompleteness,checkTreasuryPuzzleCompleteness,checkArbitrationPuzzleCompleteness,checkRewardPuzzleCompleteness,checkProgressPuzzleCompleteness,checkOrderPuzzleCompleteness,checkPuzzleCompleteness as a292b}from'../../knowledge/index.js';import{initPuzzleFromIntent as a292c,checkPuzzleCompleteness as a292d}from'../../knowledge/permission-puzzle.js';const KEYWORD_TABLE=[{'category':'Product/Service','keywords_zh':['product','selling','sell','sales','store','open\x20shop'],'keywords_en':['sell','product','sale','shop','store'],'objects':['service','order','progress'],'required_level':'R','scene_id':'retail'},{'category':'Subscription','keywords_zh':['subscription','cycle','renewal'],'keywords_en':['subscribe','recurring','subscription'],'objects':['service','machine','reward'],'required_level':'C','scene_id':'subscription'},{'category':'Rental','keywords_zh':['rent','lease','return'],'keywords_en':['rent','lease','return'],'objects':['service','machine','arb'],'required_level':'C','scene_id':'rental_return'},{'category':'Trust','keywords_zh':['deposit','pledge','verify','trust'],'keywords_en':['deposit','trust','verify'],'objects':['guard','permission','treasury'],'required_level':'R','scene_id':'trust_deposit'},{'category':'Funds','keywords_zh':['split','collect','share\x20profit','income','incentive'],'keywords_en':['split','revenue','reward'],'objects':['allocation','treasury','reward'],'required_level':'R','scene_id':'revenue_split'},{'category':'Workflow','keywords_zh':['node','stage','process','workflow'],'keywords_en':['workflow','stage','node'],'objects':['machine','progress'],'required_level':'R','scene_id':'workflow'},{'category':'Dispute','keywords_zh':['arbitration','refund','conflict','rights\x20protection'],'keywords_en':['arbitration','refund','dispute'],'objects':['arb','proof'],'required_level':'C','scene_id':'arbitration_dispute'},{'category':'Contact','keywords_zh':['customer\x20service','contact','communication'],'keywords_en':['contact','support','im'],'objects':['contact'],'required_level':'C','scene_id':'contact_im'},{'category':'Data','keywords_zh':['evidence','record','data'],'keywords_en':['evidence','record','data'],'objects':['repository','proof'],'required_level':'C','scene_id':'evidence_record'},{'category':'User\x20Profile','keywords_zh':['personal\x20info','preference','privacy'],'keywords_en':['personal','profile','privacy'],'objects':['personal','contact'],'required_level':'OPTIONAL','scene_id':'user_profile'},{'category':'Demand\x20Submission','keywords_zh':['demand','publish','inquiry'],'keywords_en':['demand','request','inquiry'],'objects':['demand'],'required_level':'OPTIONAL','scene_id':'demand_inquiry'}],INDUSTRY_KEYWORDS=[{'industry':'freelance','words':['freelance','outsourcing','freelance','gig']},{'industry':'rental','words':['rental','lease','rental','rent']},{'industry':'education','words':['education','course','training','education','course']},{'industry':'travel','words':['travel','tour','itinerary','travel','trip']},{'industry':'subscription','words':['subscription','cycle','subscription','recurring']}];function buildPuzzleDispatch(){const a=(c,d)=>{try{return c(d);}catch{return undefined;}},b=(c,d)=>{if(!c)return{'missing':[],'complete':![],'next_step':'init\x20failed'};try{return d(c);}catch{return{'missing':[],'complete':![],'next_step':'check\x20failed'};}};return{'service':{'init':c=>a(initServicePuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkServicePuzzleCompleteness)},'machine':{'init':c=>a(initMachinePuzzleFromIntent,c),'check':c=>b(c,checkMachinePuzzleCompleteness)},'allocation':{'init':c=>a(initAllocationPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkAllocationPuzzleCompleteness)},'treasury':{'init':c=>a(initTreasuryPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkTreasuryPuzzleCompleteness)},'arb':{'init':c=>a(initArbitrationPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkArbitrationPuzzleCompleteness)},'reward':{'init':c=>a(initRewardPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkRewardPuzzleCompleteness)},'progress':{'init':c=>a(initProgressPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkProgressPuzzleCompleteness)},'order':{'init':c=>a(initOrderPuzzleFromIntent,{'primary_goal':c}),'check':c=>b(c,checkOrderPuzzleCompleteness)},'permission':{'init':c=>a(a292c,{'primary_goal':c}),'check':c=>b(c,a292d)},'guard':{'init':c=>a(a292a,{'primary_goal':c}),'check':c=>b(c,a292b)}};}export function extractKeywords(a){if(!a||typeof a!=='string')return[];const b=[];for(const c of KEYWORD_TABLE){const d=[...c['keywords_zh'],...c['keywords_en']];for(const e of d){try{const f=new RegExp(escapeRegex(e),'gi'),g=(a['match'](f)||[])['length'];g>0x0&&b['push']({'keyword':e,'category':c['category'],'matched_objects':[...c['objects']],'required_level':c['required_level'],'match_count':g});}catch{}}}return b['sort']((h,i)=>i['match_count']-h['match_count']),b;}function escapeRegex(a){return a['replace'](/[.*+?^${}()|[\]\\]/g,'\x5c$&');}export function resolveIndustry(a,b){const c=((a??'')+'\x20'+(b??''))['toLowerCase']();for(const d of INDUSTRY_KEYWORDS){for(const e of d['words']){if(c['includes'](e['toLowerCase']()))return d['industry'];}}return'general';}export function identifyObjects(a,b){if(b['length']===0x0)return{'primary':'service','secondary':['permission','machine','progress'],'scenes':[{'object':'service','scene_id':'general'}]};const c=b['find'](i=>i['required_level']==='R'),d=(c??b[0x0])['matched_objects'][0x0],e=new Set([d]),f=[];for(const i of b){for(const j of i['matched_objects']){!e['has'](j)&&(e['add'](j),f['push'](j));}}const g=[],h=new Set();for(const k of KEYWORD_TABLE){const l=b['find'](n=>n['category']===k['category']);if(!l)continue;if(h['has'](k['scene_id']))continue;h['add'](k['scene_id']),g['push']({'object':k['objects'][0x0],'scene_id':k['scene_id']});}return{'primary':d,'secondary':f,'scenes':g};}export function analyzeBusinessIntent(a){const b=[];if(!a||!a['user_intent']||typeof a['user_intent']!=='string')return{'intent_parsed':{'primary_object':'service','secondary_objects':[],'detected_scenes':[],'industry':'general','keyword_matches':[]},'puzzles':{},'overall_completeness':'empty','next_step':'Please\x20provide\x20a\x20non-empty\x20business\x20intent.','recommended_creation_order':[],'warnings':['input.user_intent\x20is\x20empty']};const c=a['user_intent'],e=extractKeywords(c),f=resolveIndustry(c,a['industry']),{primary:g,secondary:h,scenes:i}=identifyObjects(c,e);let j=[g,...h];if(a['target_objects']&&a['target_objects']['length']>0x0){const p=a['target_objects']['filter'](q=>['service','machine','guard','permission','reward','arb','progress','treasury','demand','repository','contact','order','allocation','personal','payment','proof']['includes'](q));if(p['length']>0x0)j=p;}const k=buildPuzzleDispatch(),l={};for(const q of j){const r=k[q];if(!r){b['push']('No\x20puzzle\x20module\x20for\x20\x27'+q+'\x27\x20—\x20skipped\x20(L3\x20object)');continue;}const s=r['init'](c),t=s?r['check'](s):undefined,u=extractMissingDimensions(t);l[q]={'puzzle':s,'completeness':t,'missing_dimensions':u},!s&&b['push']('Puzzle\x20init\x20failed\x20for\x20\x27'+q+'\x27');}const m=aggregatePuzzleCompleteness(l),n=suggestNextPuzzleStep({'intent_parsed':{'primary_object':g,'secondary_objects':h,'detected_scenes':i,'industry':f,'keyword_matches':e},'puzzles':l,'overall_completeness':m,'next_step':'','recommended_creation_order':[],'warnings':b}),o=['permission','progress','guard','allocation','machine','service'];return{'intent_parsed':{'primary_object':g,'secondary_objects':h,'detected_scenes':i,'industry':f,'keyword_matches':e},'puzzles':l,'overall_completeness':m,'next_step':n,'recommended_creation_order':o,'warnings':b};}function extractMissingDimensions(a){if(!a||typeof a!=='object')return[];const b=a,d=b['missing'];if(Array['isArray'](d))return d['map'](f=>String(f));const e=b['missing_details'];if(Array['isArray'](e))return e['map'](f=>String(f?.['dimension']??f));return[];}export function aggregatePuzzleCompleteness(a){const b=Object['values'](a??{});if(b['length']===0x0)return'empty';const c=b['filter'](f=>!f['puzzle'])['length'];if(c===b['length'])return'empty';const d=b['reduce']((f,g)=>f+(g['missing_dimensions']?.['length']??0x0),0x0);if(d===0x0)return'complete';return'partial';}export function suggestNextPuzzleStep(a){if(!a)return'No\x20result\x20to\x20suggest\x20from.';if(a['overall_completeness']==='complete')return'All\x20puzzle\x20dimensions\x20are\x20complete\x20—\x20ready\x20for\x20risk\x20calibration\x20(stage\x203).';if(a['overall_completeness']==='empty')return'No\x20puzzle\x20has\x20been\x20initialized.\x20Provide\x20more\x20concrete\x20business\x20intent\x20so\x20the\x20primary\x20object\x20can\x20be\x20identified.';const b=['permission','treasury','allocation','guard','machine','service','order','progress','arb','reward','proof','repository','demand','contact','personal','payment'],d=a['puzzles']??{},e=b['filter'](f=>d[f]);for(const f of e){const g=d[f];if(!g)continue;const h=g['missing_dimensions']??[];if(h['length']===0x0)continue;const i=g['completeness'],j=i&&typeof i==='object'?i['next_step']:undefined;if(typeof j==='string'&&j['trim']())return'['+f+']\x20'+j;return'['+f+']\x20Complete\x20dimension'+(h['length']>0x1?'s':'')+'\x20'+h['join'](',\x20')+'\x20to\x20advance\x20the\x20puzzle.';}return'Continue\x20dialog\x20to\x20fill\x20remaining\x20pending\x20fields.';}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash}from'crypto';import{query_objects,query_events}from'@wowok/wowok';import{annotateEventsMonetaryFields}from'../../knowledge/fund-layer.js';import{buildDataSemantic}from'../../schema/call/semantic.js';import{collectContextExperience}from'../../loop-engineering/context-collect.js';const STATE_TRANSITION_EVENTS=['NewOrderEvent','ProgressEvent','ArbEvent','DemandPresentEvent','DemandFeedbackEvent','NewEntityEvent'],MAX_OBJECTS_PER_QUERY=0x32;export async function assembleContext(a){const b=a['context_objects'];if(!b||b['length']===0x0)throw new Error('assemble_context\x20requires\x20\x27context_objects\x27\x20—\x20an\x20array\x20of\x20object\x20IDs\x20or\x20LocalMark\x20names.');const c=a['context_network']??'testnet',d=a['include_events']??![],e=Math['max'](0x0,Math['min'](0x5,a['context_depth']??0x0)),g=a['context_include']?.['length']?new Set(a['context_include']):null,h=await
|
|
1
|
+
import{createHash}from'crypto';import{query_objects,query_events}from'@wowok/wowok';import{annotateEventsMonetaryFields}from'../../knowledge/fund-layer.js';import{batchQueryObjectsByIds}from'../../knowledge/workflow-guidance.js';import{buildDataSemantic}from'../../schema/call/semantic.js';import{collectContextExperience}from'../../loop-engineering/context-collect.js';const STATE_TRANSITION_EVENTS=['NewOrderEvent','ProgressEvent','ArbEvent','DemandPresentEvent','DemandFeedbackEvent','NewEntityEvent'],MAX_OBJECTS_PER_QUERY=0x32;export async function assembleContext(a){const b=a['context_objects'];if(!b||b['length']===0x0)throw new Error('assemble_context\x20requires\x20\x27context_objects\x27\x20—\x20an\x20array\x20of\x20object\x20IDs\x20or\x20LocalMark\x20names.');const c=a['context_network']??'testnet',d=a['include_events']??![],e=Math['max'](0x0,Math['min'](0x5,a['context_depth']??0x0)),g=a['context_include']?.['length']?new Set(a['context_include']):null,h=await batchQueryObjectsByIds(b,c,![]),k=[],l=[];if(e>0x0){const z=new Set();for(const B of h){const C=B?.['object'];if(typeof C==='string')z['add'](C);}let A=[];for(const D of h){const E=safeExtractAddressFields(D);for(const F of E){if(g&&!g['has'](F['field']))continue;if(z['has'](F['address']))continue;A['push']({'id':F['address'],'parent':D?.['object']??'','viaField':F['field'],'viaType':F['type'],'depth':0x1});}}for(let G=0x1;G<=e&&A['length']>0x0;G++){const H=new Set(),I=[];for(const K of A){if(z['has'](K['id'])||H['has'](K['id']))continue;H['add'](K['id']),z['add'](K['id']),I['push'](K);}if(I['length']===0x0)break;const J=[];for(let L=0x0;L<I['length'];L+=MAX_OBJECTS_PER_QUERY){const M=I['slice'](L,L+MAX_OBJECTS_PER_QUERY);let N;try{N=await query_objects({'objects':M['map'](P=>P['id']),'no_cache':![],'network':c});}catch{continue;}const O=N?.['objects']??[];for(let P=0x0;P<M['length'];P++){const Q=M[P],R=O[P];if(!R)continue;k['push']({'object':Q['id'],'depth':Q['depth'],'via_field':Q['viaField'],'via_type':Q['viaType'],'parent':Q['parent']}),l['push'](R);if(G<e){const S=safeExtractAddressFields(R);for(const T of S){if(g&&!g['has'](T['field']))continue;if(z['has'](T['address']))continue;J['push']({'id':T['address'],'parent':Q['id'],'viaField':T['field'],'viaType':T['type'],'depth':G+0x1});}}}}A=J;}}const m=[...h,...l],n=extractEmbeddedHistory(m),p=Object['keys'](n)['length']>0x0;let q;if(d){q=[];for(const U of STATE_TRANSITION_EVENTS){try{const V=await query_events({'type':U,'limit':0x5,'order':'descending','network':c});V?.['data']&&V['data']['length']>0x0&&q['push'](...V['data']);}catch{}}if(q['length']===0x0)q=undefined;else try{await annotateEventsMonetaryFields(q,c);}catch{}}const s={'operation_type':'assemble_context','data':{'context_objects':h,'embedded_history':n,'events':q}},t=buildDataSemantic({'objects':h,'embedded_history':n,'events':q},s),u=h['map'](W=>(W?.['object']??W?.['data']?.['object']??'?')+':'+(W?.['version']??W?.['data']?.['version']??'?'));l['length']>0x0&&u['push']('deps:'+l['map'](W=>(W?.['object']??'?')+':'+(W?.['version']??'?'))['join'](','));u['push']('ts:'+Date['now']());const v=createHash('sha256')['update'](u['join']('|'))['digest']('hex')['substring'](0x0,0x10),w=k['length']>0x0,x=w?'Context\x20assembled\x20with\x20'+k['length']+'\x20dependency\x20object(s)\x20across\x20'+e+'\x20level(s).\x20'+'Use\x20onchain_transaction\x20with\x20a\x20specific\x20digest\x20to\x20verify\x20a\x20past\x20operation,\x20'+'or\x20proceed\x20with\x20onchain_operations\x20(consider\x20dry_run=true\x20first\x20to\x20validate).':p?'Context\x20assembled\x20with\x20embedded\x20operation\x20history.\x20Use\x20onchain_transaction\x20with\x20a\x20specific\x20digest\x20to\x20verify\x20a\x20past\x20operation,\x20or\x20proceed\x20with\x20onchain_operations\x20(consider\x20dry_run=true\x20first\x20to\x20validate).':q&&q['length']>0x0?'Context\x20assembled\x20with\x20recent\x20events.\x20Use\x20onchain_transaction\x20with\x20a\x20specific\x20digest\x20to\x20verify\x20any\x20event\x27s\x20tx,\x20or\x20proceed\x20with\x20onchain_operations.':'Context\x20assembled\x20(current\x20state\x20only).\x20Proceed\x20with\x20onchain_operations\x20(consider\x20dry_run=true\x20first\x20to\x20validate).';let y;try{y=collectContextExperience({'action':'assemble_context','objects':h,'events':q,'embedded_history':p?n:undefined,'semantic_summary':t,'context_digest':v,'next_action':x},c);}catch{}return{'action':'assemble_context','objects':h,'events':q,'embedded_history':p?n:undefined,'dependencies':w?k:undefined,'dependency_objects':w?l:undefined,'semantic_summary':t,'context_digest':v,'next_action':x,'flywheel_collected':y};}export function extractAddressFields(a){const b=[],c=a['type'];let d=c;if(c&&c['includes']('::')){const k=c['split']('::');d=k[k['length']-0x1];}const e=l=>typeof l==='string'&&l['startsWith']('0x')&&l['length']>=0xa,f=(l,m,n)=>{e(l)&&l!=='0x0'&&l!==a['object']&&b['push']({'address':l,'field':m,'type':n});},h=(l,m,n)=>{if(Array['isArray'](l))for(const o of l){f(o,m,n);}},i=(l,m,n)=>{l!==null&&l!==undefined&&f(l,m,n);},j=a;switch(d){case'Service':{i(j['machine'],'machine','bind'),i(j['buy_guard'],'buy_guard','validate'),i(j['um'],'um','bind'),f(j['permission'],'permission','validate'),h(j['repositories'],'repositories','consume'),h(j['arbitrations'],'arbitrations','trigger'),h(j['rewards'],'rewards','trigger');if(j['order_allocators']?.['allocators']){for(const m of j['order_allocators']['allocators']){f(m['guard'],'allocator_guard','validate');}const l=j['order_allocators']['allocators'][0x0]?.['guard'];f(l,'order_allocators','create');}break;}case'Machine':{f(j['permission'],'permission','validate'),h(j['consensus_repositories'],'consensus_repositories','consume');break;}case'Order':{f(j['service'],'service','consume'),i(j['machine'],'machine','consume'),i(j['progress'],'progress','trigger'),h(j['dispute'],'dispute','trigger'),i(j['allocation'],'allocation','bind');break;}case'Progress':{f(j['machine'],'machine','bind'),h(j['context_repositories'],'context_repositories','consume');break;}case'Treasury':{f(j['permission'],'permission','validate');if(Array['isArray'](j['external_deposit_guard'])){for(const n of j['external_deposit_guard'])f(n?.['guard'],'external_deposit_guard','validate');}if(Array['isArray'](j['external_withdraw_guard'])){for(const o of j['external_withdraw_guard'])f(o?.['guard'],'external_withdraw_guard','validate');}break;}case'Allocation':{if(Array['isArray'](j['allocators'])){for(const p of j['allocators'])f(p?.['guard'],'allocator_guard','validate');}i(j['payment_info']?.['for_object'],'for_object','bind'),i(j['payment_info']?.['for_guard'],'for_guard','validate'),h(j['payment'],'payment','trigger');break;}case'Arbitration':{f(j['permission'],'permission','validate');if(Array['isArray'](j['voting_guard'])){for(const q of j['voting_guard'])f(q?.['guard'],'voting_guard','validate');}i(j['usage_guard'],'usage_guard','validate');break;}case'Reward':{f(j['permission'],'permission','validate');if(Array['isArray'](j['guards'])){for(const s of j['guards'])f(s?.['guard'],'guard','validate');}break;}case'Repository':{f(j['permission'],'permission','validate'),h(j['rewards'],'rewards','trigger');if(Array['isArray'](j['policies']))for(const t of j['policies']){if(Array['isArray'](t?.['write_guard'])){for(const u of t['write_guard'])f(u?.['guard'],'write_guard','validate');}i(t?.['quote_guard'],'quote_guard','validate');}break;}case'Demand':{f(j['permission'],'permission','validate');if(Array['isArray'](j['guards'])){for(const v of j['guards'])f(v?.['guard'],'guard','validate');}h(j['rewards'],'rewards','trigger');break;}case'Contact':{f(j['permission'],'permission','validate');break;}case'Permission':{break;}case'Payment':{i(j['info']?.['for_object'],'for_object','bind'),i(j['info']?.['for_guard'],'for_guard','validate');if(Array['isArray'](j['record']))for(const w of j['record']){const x=w?.['recipient'];x&&typeof x==='object'&&typeof x['Entity']==='string'&&f(x['Entity'],'recipient_entity','consume');}break;}case'Guard':{break;}default:break;}return b;}function safeExtractAddressFields(a){if(!a||typeof a!=='object')return[];try{return extractAddressFields(a);}catch{return[];}}function extractEmbeddedHistory(a){const b={};for(const c of a){const d=c?.['data']??c,e=c?.['object']??d?.['object'];if(!e)continue;const f=d?.['type']??'',g={};f['includes']('Progress')&&d?.['session']?.['forwards']&&(g['operation_history']=d['session']['forwards']['map'](h=>({'operation':h['forward'],'operator':h['who'],'accomplished':h['accomplished'],'time':h['time'],'message':h['msg']})),g['next_node']=d['session']?.['next_node'],g['threshold']=d['session']?.['threshold']),f['includes']('Order')&&(d?.['dispute']&&Array['isArray'](d['dispute'])&&d['dispute']['length']>0x0&&(g['disputes']=d['dispute']),d?.['claimed_by']&&(g['claimed_by']=d['claimed_by']),d?.['progress']&&(g['progress_object']=d['progress'])),f['includes']('Service')&&d?.['sales']&&(g['sale_count']=Array['isArray'](d['sales'])?d['sales']['length']:0x0),Object['keys'](g)['length']>0x0&&(b[e]=g);}return b;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{batchQueryTableItems}from'../../knowledge/workflow-guidance.js';export async function fetchMachineNodes(a,b){const {items:c}=await batchQueryTableItems(a,{'network':b}),d=[];for(const e of c){e['object']?.['type']==='TableItem_MachineNode'&&d['push'](e['object']);}return d;}export function normalizeForwards(a){if(!Array['isArray'](a))return[];return a['map'](b=>{const c=b?.['guard'],d=c&&typeof c==='object'&&typeof c['guard']==='string';return{'name':typeof b?.['name']==='string'?b['name']:'','weight':typeof b?.['weight']==='number'?b['weight']:0x0,'guard':d?c['guard']:typeof c==='string'?c:null,'retained_submission':d&&Array['isArray'](c['retained_submission'])?c['retained_submission']:null,'named_operator':typeof b?.['namedOperator']==='string'?b['namedOperator']:null,'permission_index':typeof b?.['permissionIndex']==='number'?b['permissionIndex']:null};});}export function buildMachineGraph(a){const b=new Map(),c=[];for(const d of a){const e=d['name'];if(!e)continue;!b['has'](e)&&b['set'](e,{'name':e,'description':null});const f=Array['isArray'](d['value'])?d['value']:[];for(const g of f){if(!g||typeof g!=='object')continue;const h=typeof g['prev_node']==='string'?g['prev_node']:'';if(!h)continue;c['push']({'from':h,'to':e,'threshold':typeof g['threshold']==='number'?g['threshold']:0x1,'forwards':normalizeForwards(g['forwards'])});}}for(const i of c){!b['has'](i['from'])&&b['set'](i['from'],{'name':i['from'],'description':null}),!b['has'](i['to'])&&b['set'](i['to'],{'name':i['to'],'description':null});}return{'nodes':Array['from'](b['values']()),'edges':c};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Config,LocalMark,query_objects,
|
|
1
|
+
import{Config,LocalMark,query_objects,objectTypeFromAddress,ObjectType}from'@wowok/wowok';import{fetchMachineNodes,buildMachineGraph}from'./machine-nodes.js';import{batchQueryObjectsByIds,fetchObjectLinkerTx}from'../../knowledge/workflow-guidance.js';export async function handleMachinePanorama(a){const b=a['object_address'];if(!b)throw new Error('\x27object_address\x27\x20is\x20required\x20for\x20machine_panorama');let c=a['context_network']??undefined;const d=[];let f=b;if(!/^0x[0-9a-fA-F]{32,64}$/['test'](b)){const p=await LocalMark['Instance']()['get_address'](b);if(!p)throw new Error('Cannot\x20resolve\x20machine\x20\x27'+b+'\x27\x20—\x20not\x20a\x20valid\x20address\x20and\x20no\x20LocalMark\x20entry\x20found.\x20'+'Pass\x20the\x200x\x20Machine\x20object\x20address\x20directly\x20or\x20register\x20the\x20name\x20via\x20local_mark_operation.');f=p;}let g=null;try{if(!c)c=await Config['Instance']()['network_get']();const q=await query_objects({'objects':[f],'network':c});g=q?.['objects']?.[0x0]??null;if(!g&&a['context_network']){const s=await Config['Instance']()['network_get']();if(s&&s!==c){const t=await query_objects({'objects':[f],'network':s,'no_cache':!![]}),u=t?.['objects']?.[0x0]??null;u&&(g=u,c=s);}}}catch(w){throw new Error('Failed\x20to\x20query\x20Machine\x20'+f+'\x20on\x20'+c+':\x20'+(''+(w instanceof Error?w['message']:String(w))));}if(!g)throw new Error('Machine\x20'+f+'\x20not\x20found\x20on\x20'+c+'.\x20It\x20may\x20not\x20exist\x20on\x20this\x20network.');f=g['object']??f;let h=null,j=[];try{const x=await LocalMark['Instance']()['list']({'address':f});x['length']>0x0&&(h=x[0x0]['name']??null,j=(x[0x0]['tags']??[])['map'](y=>String(y)));}catch{d['push']('head:\x20LocalMark\x20lookup\x20failed');}let k={'nodes':[],'edges':[]};try{const y=await fetchMachineNodes(f,c);k=buildMachineGraph(y);}catch{d['push']('graph:\x20node\x20fetch\x20failed\x20(non-blocking)');}const l=[];let m=0x0,n=0x0;try{const z=await fetchObjectLinkerTx(f,c,!![]),A=z?.['items']??[],B=new Set();for(const G of A){const H=typeof G?.['who']==='string'?G['who']['toLowerCase']():'';if(!H||H==='0x0')continue;if(!objectTypeFromAddress(H))continue;B['add'](H);}n=B['size'];const C=A['filter'](I=>objectTypeFromAddress(I['who'])===ObjectType['Progress']);m=C['length'];const D=C['slice'](-0x32)['reverse'](),E=D['map'](I=>I['who']),F=new Map();if(E['length']>0x0)try{const I=await batchQueryObjectsByIds(E,c,!![]);for(const J of I){if(J?.['object'])F['set'](J['object'],J);}}catch{d['push']('progresses:\x20detail\x20fetch\x20failed');}for(const K of D){const L=typeof K?.['who']==='string'?K['who']:'';if(!L)continue;const M=F['get'](L);l['push']({'progress':L,'name':null,'current':M?.['current']??null,'task':M?.['task']??null,'history_count':typeof M?.['history_count']==='number'?M['history_count']:null,'current_time':typeof M?.['current_time']==='number'?M['current_time']:null,'created_at':typeof K?.['time']==='number'?K['time']:null});}}catch{d['push']('progresses:\x20global-table\x20lookup\x20failed\x20(non-blocking)');}return{'action':'machine_panorama','machineAddress':f,'network':String(c),'head':{'name':h,'tags':j,'description':typeof g['description']==='string'?g['description']:null,'published':typeof g['bPublished']==='boolean'?g['bPublished']:null,'paused':typeof g['bPaused']==='boolean'?g['bPaused']:null},'fields':{'permission':g['permission']??null,'um':g['um']??null,'node_count':typeof g['node_count']==='number'?g['node_count']:null,'consensus_repositories':Array['isArray'](g['consensus_repositories'])?g['consensus_repositories']:[]},'graph':k,'progresses':{'count':m,'items':l},'related':{'count':n},'data_gaps':d};}
|
|
@@ -52,6 +52,7 @@ export declare function handleMerchantGuide(v: MerchantGuideInput): Promise<{
|
|
|
52
52
|
next_action: string;
|
|
53
53
|
intent?: undefined;
|
|
54
54
|
adopted_modules?: undefined;
|
|
55
|
+
mode_prior?: undefined;
|
|
55
56
|
blueprint?: undefined;
|
|
56
57
|
evaluation_preview?: undefined;
|
|
57
58
|
graph_validation?: undefined;
|
|
@@ -94,6 +95,25 @@ export declare function handleMerchantGuide(v: MerchantGuideInput): Promise<{
|
|
|
94
95
|
user_protections: string[];
|
|
95
96
|
merchant_obligations: string[];
|
|
96
97
|
}[];
|
|
98
|
+
mode_prior: {
|
|
99
|
+
name: string;
|
|
100
|
+
display_name: string;
|
|
101
|
+
source: import("../../knowledge/industry-registry.js").IndustrySource;
|
|
102
|
+
risk_appetite: import("../../extensions/types.js").RiskAppetite;
|
|
103
|
+
key_risk: string;
|
|
104
|
+
machine_shape: {
|
|
105
|
+
name: string;
|
|
106
|
+
role: string;
|
|
107
|
+
}[];
|
|
108
|
+
guards: {
|
|
109
|
+
template_id: string;
|
|
110
|
+
host: "reward" | "service" | "machine" | "arbitration" | "repository";
|
|
111
|
+
purpose: string;
|
|
112
|
+
}[];
|
|
113
|
+
allocator: import("../../knowledge/scenario-modes.js").ModeAllocatorStrategy;
|
|
114
|
+
risk_constraints: import("../../extensions/types.js").ModeRiskConstraints;
|
|
115
|
+
build_notes: string[];
|
|
116
|
+
} | undefined;
|
|
97
117
|
blueprint: {
|
|
98
118
|
nodes: {
|
|
99
119
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{analyzeIntent}from'./intent-analyzer.js';import{buildSemanticGraph,validateGraph}from'./semantic-graph.js';import{checkGameTheoryConstraints}from'./game-theory.js';import{assessWorkflowDesign}from'./workflow-design-assessment.js';import{CORE_BUSINESS_MODULES,getBusinessModule,recommendModules,checkModuleConstraints}from'../../extensions/business-modules.js';function derivePlanSatisfiedConstraints(a,b){const c=new Set(),d=h=>a['edges']['some'](i=>i['relation']===h),e=h=>a['nodes']['some'](i=>i['id']===h),f=h=>a['nodes']['some'](i=>i['type']===h),g=h=>a['adoptedModules']['includes'](h);if(d('has_order_allocators'))c['add']('order_allocators_bound');if(d('uses_machine'))c['add']('machine_bound_before_publish');if(d('has_arbitration'))c['add']('arbitration_bound_to_service');if(e('main_machine'))c['add']('machine_published');if(e('main_repository'))c['add']('repository_published');if(e('main_service'))c['add']('service_published');e('arb_permission')&&e('main_permission')&&c['add']('arbitration_permission_independent');g('independent_arbitration')&&e('guard_independent_arbitration')&&c['add']('voting_guard_configured');g('accept_timeout_protection')&&(c['add']('time_guard_configured'),c['add']('adminUnhold_permission'));g('milestone_escrow')&&f('guard')&&c['add']('milestone_forward_guarded');if(e('main_allocation')&&b['payment']['allocation']&&b['payment']['allocation']['length']>0x0){c['add']('allocators_configured');const h=b['payment']['allocation']['reduce']((j,k)=>j+k['percentage'],0x0);if(Math['abs'](h-0x64)<0.001)c['add']('sharing_sum_100');const i=b['payment']['allocation']['find'](j=>j['recipient']==='platform');if(i&&i['percentage']===0x0)c['add']('platform_fee_zero');g('supplier_collaboration')&&(c['add']('allocation_sharing_configured'),c['add']('demand_configured'));}return g('wip_provenance')&&e('main_repository')&&c['add']('wip_hash_before_delivery'),g('subscription_with_proof')&&e('main_repository')&&(c['add']('delivery_guard_per_cycle'),c['add']('repository_updated')),g('damage_attestation')&&(c['add']('pre_rental_hash'),c['add']('post_rental_hash')),g('refund_guarantee')&&(c['add']('compensation_fund_positive'),c['add']('refund_guard_configured')),c;}function deriveDeployTimeChecks(a){const b=[];return a['nodes']['some'](c=>c['id']==='main_machine')&&b['push']('Machine\x20published\x20AND\x20bound\x20to\x20Service\x20BEFORE\x20Service.publish\x20(machine\x20is\x20immutable\x20after\x20publish)'),a['edges']['some'](c=>c['relation']==='has_order_allocators')&&b['push']('Service.order_allocators\x20bound\x20(verify\x20via\x20query_objects\x20after\x20publish\x20—\x20order_allocators\x20is\x20FROZEN\x20at\x20publish)'),a['nodes']['some'](c=>c['id']==='main_arbitration')&&b['push']('Arbitration.permission\x20!=\x20Service.permission\x20on-chain\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)'),a['nodes']['some'](c=>c['id']==='main_repository')&&b['push']('Repository\x20published\x20and\x20Guard\x20write\x20validation\x20configured'),b['push']('After\x20materialization,\x20confirm\x20the\x20on-chain\x20state\x20matches\x20this\x20plan\x20(query_toolkit\x20query_type=\x27service_panorama\x27)'),b;}function buildCreationPlan(a){const b=[],c=new Map(a['nodes']['map'](i=>[i['id'],i])),f=new Map();for(const i of a['nodes'])f['set'](i['id'],new Set());for(const j of a['edges']){j['required']&&f['has'](j['from'])&&c['has'](j['to'])&&f['get'](j['from'])['add'](j['to']);}const g=[],h=new Map(f);while(h['size']>0x0){const k=[...h['entries']()]['filter'](([,l])=>l['size']===0x0)['map'](([l])=>l);if(k['length']===0x0){g['push'](...h['keys']());break;}k['sort']();for(const l of k){g['push'](l),h['delete'](l);for(const m of h['values']())m['delete'](l);}}return g['forEach']((o,p)=>{const q=c['get'](o),r=q['config']['name'];b['push']({'order':p+0x1,'node_id':o,'object_type':q['type'],'suggested_name':r?.['type']==='string'?r['value']:o,'depends_on':[...f['get'](o)??[]],'operation_hint':'Create\x20'+q['type']+'\x20via\x20onchain_operations,\x20then\x20configure.\x20Purpose:\x20'+q['purpose']});}),b;}export async function handleMerchantGuide(a){const b=a['guide_state']??{'intent_text':''},c=a['guide_confirm']??{},d={'intent_text':(a['intent']??b['intent_text']??'')['trim'](),'confirmed_industry':c['industry']??b['confirmed_industry'],'currency':c['currency']??b['currency'],'deliverables':c['deliverables']??b['deliverables'],'payment_override':c['payment']??b['payment_override'],'trust_override':c['trust']??b['trust_override'],'adopted_module_ids':c['adopted_module_ids']??b['adopted_module_ids']};for(const r of Object['keys'](d)){if(d[r]===undefined)delete d[r];}if(!d['intent_text'])throw new Error('merchant_guide\x20requires\x20\x27intent\x27\x20(business\x20description)\x20for\x20Step\x201.\x20'+'Example:\x20intent=\x27I\x20want\x20to\x20offer\x20online\x20design\x20service\x20with\x20milestone\x20payments\x27.\x20'+'Pass\x20the\x20returned\x20guide_state\x20back\x20UNCHANGED\x20on\x20subsequent\x20calls,\x20plus\x20guide_confirm\x20for\x20merchant\x20decisions.');const e=await analyzeIntent(d['intent_text'],{'preferredIndustry':d['confirmed_industry'],'currency':d['currency']});if(!d['confirmed_industry'])return{'action':'merchant_guide','current_step':0x2,'step_name':'Industry\x20Matching','guide_state':d,'intent_draft':e['intent'],'industry_options':{'inferred':e['inferredIndustry'],'confidence':e['industryConfidence'],'similar':e['similarIndustries']},'warnings':e['warnings'],'next_action':'Confirm\x20the\x20industry\x20by\x20calling\x20merchant_guide\x20again\x20with\x20guide_state\x20(UNCHANGED)\x20'+('plus\x20guide_confirm={\x20industry:\x20\x27<one\x20of:\x20'+e['similarIndustries']['join'](',\x20')+'\x20—\x20or\x20any\x20other\x20industry\x20id>\x27\x20}')};const f={...e['intent'],'industry':d['confirmed_industry'],'deliverables':d['deliverables']??e['intent']['deliverables'],'payment':{...e['intent']['payment'],...d['payment_override']??{}},'trust':{...e['intent']['trust'],...d['trust_override']??{}}},g=d['adopted_module_ids']?d['adopted_module_ids']['map'](s=>getBusinessModule(s))['filter'](s=>!!s):recommendModules(d['confirmed_industry'],d['intent_text'],{'maxModules':0x5}),h=buildSemanticGraph(f,g),i=validateGraph(h),j=derivePlanSatisfiedConstraints(h,f),l=g['map'](s=>checkModuleConstraints(s,j)),m=deriveDeployTimeChecks(h),n=l['filter'](s=>!s['adopted']),o=checkGameTheoryConstraints(h,f),p=assessWorkflowDesign(h),q=buildCreationPlan(h);return{'action':'merchant_guide','current_step':n['length']>0x0?0x9:0xa,'step_name':n['length']>0x0?'Harness\x20Check\x20(issues\x20found)':'Submission\x20Plan\x20Ready','guide_state':{...d,'adopted_module_ids':g['map'](s=>s['id'])},'intent':{'intent_type':f['intent'],'industry':f['industry'],'roles':f['roles'],'deliverables':f['deliverables'],'payment':f['payment'],'trust':f['trust']},'adopted_modules':g['map'](s=>({'id':s['id'],'name':s['name'],'description':s['description'],'requires_keeper':s['requiresKeeper'],'keeper_hint':s['keeperHint'],'user_protections':s['userProtections'],'merchant_obligations':s['merchantObligations']})),'blueprint':{'nodes':h['nodes']['map'](s=>({'id':s['id'],'type':s['type'],'purpose':s['purpose']})),'edges':h['edges']['map'](s=>({'from':s['from'],'to':s['to'],'relation':s['relation'],'required':s['required']}))},'evaluation_preview':h['evaluationPreview'],'graph_validation':{'valid':i['valid'],'hard_violations':i['hardViolations']['map'](s=>({'id':s['id'],'description':s['description'],'fix':s['fixSuggestion']})),'soft_notes':i['softViolations']['map'](s=>({'id':s['id'],'description':s['description']}))},'harness_check':{'module_constraints':l['map'](s=>({'module':s['module'],'plan_satisfied':s['adopted'],'missing':s['missingConstraints'],'reason':s['reason'],'estimated_score_boost':s['estimatedScoreBoost']})),'blocking_issues':n['map'](s=>({'module':s['module'],'missing_constraints':s['missingConstraints'],'fix':s['reason']})),'deploy_time_checks':m},'game_theory':{'summary':o['summary'],'coverage':o['coveredCount']+'/'+o['totalCount'],'exposed_scenarios':o['exposedScenarios'],'wow_alignments':o['wowAlignments'],'scenarios':o['results']['map'](s=>({'scenario':s['scenario'],'covered':s['covered'],'conflict':s['conflict'],'user_protection':s['userProtection'],'evaluation_metric':s['evaluationMetric'],'recommendation':s['recommendation']}))},'workflow_design_assessment':{'score':p['score'],'summary':p['summary'],'findings':p['findings']['map'](s=>({'kind':s['kind'],'severity':s['severity'],'message':s['message'],'fix':s['fix']})),'checks':p['checks']['map'](s=>({'id':s['id'],'dimension':s['dimension'],'passed':s['passed'],'severity':s['severity'],'message':s['message'],'fix':s['fix']}))},'creation_plan':q,'warnings':e['warnings'],'next_action':n['length']>0x0?'Resolve\x20the\x20blocking_issues\x20above\x20(adjust\x20guide_confirm\x20payment/trust/modules,\x20or\x20accept\x20and\x20drop\x20the\x20affected\x20module\x20via\x20guide_confirm.adopted_module_ids),\x20then\x20call\x20merchant_guide\x20again.':'Plan\x20ready.\x20Materialize:\x20create\x20the\x20objects\x20in\x20creation_plan\x20order\x20via\x20onchain_operations,\x20then\x20publish\x20the\x20Service\x20(machine\x20binding\x20is\x20immutable\x20after\x20publish).'};}export function listBusinessModules(){return CORE_BUSINESS_MODULES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'industry_fit':a['industryFit'],'addresses_pain_points':a['addressesPainPoints'],'requires_keeper':a['requiresKeeper']}));}
|
|
1
|
+
import{analyzeIntent}from'./intent-analyzer.js';import{buildSemanticGraph,validateGraph}from'./semantic-graph.js';import{checkGameTheoryConstraints}from'./game-theory.js';import{assessWorkflowDesign}from'./workflow-design-assessment.js';import{CORE_BUSINESS_MODULES,getBusinessModule,recommendModules,checkModuleConstraints}from'../../extensions/business-modules.js';import{getIndustryModeRegistry}from'../../extensions/index.js';import{LOCAL_MODE_OWNER}from'./mode-actions.js';function derivePlanSatisfiedConstraints(a,b){const c=new Set(),d=h=>a['edges']['some'](i=>i['relation']===h),e=h=>a['nodes']['some'](i=>i['id']===h),f=h=>a['nodes']['some'](i=>i['type']===h),g=h=>a['adoptedModules']['includes'](h);if(d('has_order_allocators'))c['add']('order_allocators_bound');if(d('uses_machine'))c['add']('machine_bound_before_publish');if(d('has_arbitration'))c['add']('arbitration_bound_to_service');if(e('main_machine'))c['add']('machine_published');if(e('main_repository'))c['add']('repository_published');if(e('main_service'))c['add']('service_published');e('arb_permission')&&e('main_permission')&&c['add']('arbitration_permission_independent');g('independent_arbitration')&&e('guard_independent_arbitration')&&c['add']('voting_guard_configured');g('accept_timeout_protection')&&(c['add']('time_guard_configured'),c['add']('adminUnhold_permission'));g('milestone_escrow')&&f('guard')&&c['add']('milestone_forward_guarded');if(e('main_allocation')&&b['payment']['allocation']&&b['payment']['allocation']['length']>0x0){c['add']('allocators_configured');const h=b['payment']['allocation']['reduce']((j,k)=>j+k['percentage'],0x0);if(Math['abs'](h-0x64)<0.001)c['add']('sharing_sum_100');const i=b['payment']['allocation']['find'](j=>j['recipient']==='platform');if(i&&i['percentage']===0x0)c['add']('platform_fee_zero');g('supplier_collaboration')&&(c['add']('allocation_sharing_configured'),c['add']('demand_configured'));}return g('wip_provenance')&&e('main_repository')&&c['add']('wip_hash_before_delivery'),g('subscription_with_proof')&&e('main_repository')&&(c['add']('delivery_guard_per_cycle'),c['add']('repository_updated')),g('damage_attestation')&&(c['add']('pre_rental_hash'),c['add']('post_rental_hash')),g('refund_guarantee')&&(c['add']('compensation_fund_positive'),c['add']('refund_guard_configured')),c;}function deriveDeployTimeChecks(a){const b=[];return a['nodes']['some'](c=>c['id']==='main_machine')&&b['push']('Machine\x20published\x20AND\x20bound\x20to\x20Service\x20BEFORE\x20Service.publish\x20(machine\x20is\x20immutable\x20after\x20publish)'),a['edges']['some'](c=>c['relation']==='has_order_allocators')&&b['push']('Service.order_allocators\x20bound\x20(verify\x20via\x20query_objects\x20after\x20publish\x20—\x20order_allocators\x20is\x20FROZEN\x20at\x20publish)'),a['nodes']['some'](c=>c['id']==='main_arbitration')&&b['push']('Arbitration.permission\x20!=\x20Service.permission\x20on-chain\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)'),a['nodes']['some'](c=>c['id']==='main_repository')&&b['push']('Repository\x20published\x20and\x20Guard\x20write\x20validation\x20configured'),b['push']('After\x20materialization,\x20confirm\x20the\x20on-chain\x20state\x20matches\x20this\x20plan\x20(query_toolkit\x20query_type=\x27service_panorama\x27)'),b;}function buildCreationPlan(a){const b=[],c=new Map(a['nodes']['map'](i=>[i['id'],i])),f=new Map();for(const i of a['nodes'])f['set'](i['id'],new Set());for(const j of a['edges']){j['required']&&f['has'](j['from'])&&c['has'](j['to'])&&f['get'](j['from'])['add'](j['to']);}const g=[],h=new Map(f);while(h['size']>0x0){const k=[...h['entries']()]['filter'](([,l])=>l['size']===0x0)['map'](([l])=>l);if(k['length']===0x0){g['push'](...h['keys']());break;}k['sort']();for(const l of k){g['push'](l),h['delete'](l);for(const m of h['values']())m['delete'](l);}}return g['forEach']((o,p)=>{const q=c['get'](o),r=q['config']['name'];b['push']({'order':p+0x1,'node_id':o,'object_type':q['type'],'suggested_name':r?.['type']==='string'?r['value']:o,'depends_on':[...f['get'](o)??[]],'operation_hint':'Create\x20'+q['type']+'\x20via\x20onchain_operations,\x20then\x20configure.\x20Purpose:\x20'+q['purpose']});}),b;}async function resolveModePrior(a){if(!a)return undefined;const b=getIndustryModeRegistry(),c=await b['getUserMode'](a,LOCAL_MODE_OWNER);return c??b['getMode'](a);}export async function handleMerchantGuide(a){const b=a['guide_state']??{'intent_text':''},c=a['guide_confirm']??{},d={'intent_text':(a['intent']??b['intent_text']??'')['trim'](),'confirmed_industry':c['industry']??b['confirmed_industry'],'currency':c['currency']??b['currency'],'deliverables':c['deliverables']??b['deliverables'],'payment_override':c['payment']??b['payment_override'],'trust_override':c['trust']??b['trust_override'],'adopted_module_ids':c['adopted_module_ids']??b['adopted_module_ids']};for(const s of Object['keys'](d)){if(d[s]===undefined)delete d[s];}if(!d['intent_text'])throw new Error('merchant_guide\x20requires\x20\x27intent\x27\x20(business\x20description)\x20for\x20Step\x201.\x20'+'Example:\x20intent=\x27I\x20want\x20to\x20offer\x20online\x20design\x20service\x20with\x20milestone\x20payments\x27.\x20'+'Pass\x20the\x20returned\x20guide_state\x20back\x20UNCHANGED\x20on\x20subsequent\x20calls,\x20plus\x20guide_confirm\x20for\x20merchant\x20decisions.');const e=await analyzeIntent(d['intent_text'],{'preferredIndustry':d['confirmed_industry'],'currency':d['currency']});if(!d['confirmed_industry'])return{'action':'merchant_guide','current_step':0x2,'step_name':'Industry\x20Matching','guide_state':d,'intent_draft':e['intent'],'industry_options':{'inferred':e['inferredIndustry'],'confidence':e['industryConfidence'],'similar':e['similarIndustries']},'warnings':e['warnings'],'next_action':'Confirm\x20the\x20industry\x20by\x20calling\x20merchant_guide\x20again\x20with\x20guide_state\x20(UNCHANGED)\x20'+('plus\x20guide_confirm={\x20industry:\x20\x27<one\x20of:\x20'+e['similarIndustries']['join'](',\x20')+'\x20—\x20or\x20any\x20other\x20industry\x20id>\x27\x20}')};const f={...e['intent'],'industry':d['confirmed_industry'],'deliverables':d['deliverables']??e['intent']['deliverables'],'payment':{...e['intent']['payment'],...d['payment_override']??{}},'trust':{...e['intent']['trust'],...d['trust_override']??{}}},g=d['adopted_module_ids']?d['adopted_module_ids']['map'](t=>getBusinessModule(t))['filter'](t=>!!t):recommendModules(d['confirmed_industry'],d['intent_text'],{'maxModules':0x5}),h=await resolveModePrior(d['confirmed_industry']),i=buildSemanticGraph(f,g,h,{'paymentExplicit':!!(d['payment_override']||d['trust_override'])}),j=validateGraph(i),l=derivePlanSatisfiedConstraints(i,f),m=g['map'](t=>checkModuleConstraints(t,l)),n=deriveDeployTimeChecks(i),o=m['filter'](t=>!t['adopted']),p=checkGameTheoryConstraints(i,f),q=assessWorkflowDesign(i),r=buildCreationPlan(i);return{'action':'merchant_guide','current_step':o['length']>0x0?0x9:0xa,'step_name':o['length']>0x0?'Harness\x20Check\x20(issues\x20found)':'Submission\x20Plan\x20Ready','guide_state':{...d,'adopted_module_ids':g['map'](t=>t['id'])},'intent':{'intent_type':f['intent'],'industry':f['industry'],'roles':f['roles'],'deliverables':f['deliverables'],'payment':f['payment'],'trust':f['trust']},'adopted_modules':g['map'](t=>({'id':t['id'],'name':t['name'],'description':t['description'],'requires_keeper':t['requiresKeeper'],'keeper_hint':t['keeperHint'],'user_protections':t['userProtections'],'merchant_obligations':t['merchantObligations']})),'mode_prior':h?{'name':h['name'],'display_name':h['display_name'],'source':h['source'],'risk_appetite':h['risk_appetite'],'key_risk':h['key_risk'],'machine_shape':h['machine_shape']['map'](t=>({'name':t['name'],'role':t['role']})),'guards':h['guards']['map'](t=>({'template_id':t['template_id'],'host':t['host'],'purpose':t['purpose']})),'allocator':h['allocator'],'risk_constraints':h['risk_constraints'],'build_notes':h['build_notes']??[]}:undefined,'blueprint':{'nodes':i['nodes']['map'](t=>({'id':t['id'],'type':t['type'],'purpose':t['purpose']})),'edges':i['edges']['map'](t=>({'from':t['from'],'to':t['to'],'relation':t['relation'],'required':t['required']}))},'evaluation_preview':i['evaluationPreview'],'graph_validation':{'valid':j['valid'],'hard_violations':j['hardViolations']['map'](t=>({'id':t['id'],'description':t['description'],'fix':t['fixSuggestion']})),'soft_notes':j['softViolations']['map'](t=>({'id':t['id'],'description':t['description']}))},'harness_check':{'module_constraints':m['map'](t=>({'module':t['module'],'plan_satisfied':t['adopted'],'missing':t['missingConstraints'],'reason':t['reason'],'estimated_score_boost':t['estimatedScoreBoost']})),'blocking_issues':o['map'](t=>({'module':t['module'],'missing_constraints':t['missingConstraints'],'fix':t['reason']})),'deploy_time_checks':n},'game_theory':{'summary':p['summary'],'coverage':p['coveredCount']+'/'+p['totalCount'],'exposed_scenarios':p['exposedScenarios'],'wow_alignments':p['wowAlignments'],'scenarios':p['results']['map'](t=>({'scenario':t['scenario'],'covered':t['covered'],'conflict':t['conflict'],'user_protection':t['userProtection'],'evaluation_metric':t['evaluationMetric'],'recommendation':t['recommendation']}))},'workflow_design_assessment':{'score':q['score'],'summary':q['summary'],'findings':q['findings']['map'](t=>({'kind':t['kind'],'severity':t['severity'],'message':t['message'],'fix':t['fix']})),'checks':q['checks']['map'](t=>({'id':t['id'],'dimension':t['dimension'],'passed':t['passed'],'severity':t['severity'],'message':t['message'],'fix':t['fix']}))},'creation_plan':r,'warnings':e['warnings'],'next_action':o['length']>0x0?'Resolve\x20the\x20blocking_issues\x20above\x20(adjust\x20guide_confirm\x20payment/trust/modules,\x20or\x20accept\x20and\x20drop\x20the\x20affected\x20module\x20via\x20guide_confirm.adopted_module_ids),\x20then\x20call\x20merchant_guide\x20again.':'Plan\x20ready.\x20Materialize:\x20create\x20the\x20objects\x20in\x20creation_plan\x20order\x20via\x20onchain_operations,\x20then\x20publish\x20the\x20Service\x20(machine\x20binding\x20is\x20immutable\x20after\x20publish).'};}export function listBusinessModules(){return CORE_BUSINESS_MODULES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'industry_fit':a['industryFit'],'addresses_pain_points':a['addressesPainPoints'],'requires_keeper':a['requiresKeeper']}));}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type MetricType, type MetricScale, type ConstraintRule, type ConstraintSeverity, type ConstraintViolationAction } from "../../extensions/index.js";
|
|
2
|
+
import { type InfrastructureLever } from "../../persona/strategy-intent.js";
|
|
3
|
+
export declare const LOCAL_MODE_OWNER = "local";
|
|
2
4
|
export interface RecommendIndustryInput {
|
|
3
5
|
intent?: string;
|
|
4
6
|
project_description?: string;
|
|
5
7
|
project_name?: string;
|
|
8
|
+
strategy?: string | string[];
|
|
6
9
|
}
|
|
7
10
|
export declare function handleRecommendIndustry(v: RecommendIndustryInput): {
|
|
8
11
|
action: "recommend_industry";
|
|
@@ -10,16 +13,17 @@ export declare function handleRecommendIndustry(v: RecommendIndustryInput): {
|
|
|
10
13
|
inferred_traits: import("../../knowledge/industry-registry.js").IndustryTraits;
|
|
11
14
|
inference_confidence: number;
|
|
12
15
|
matched_keywords: string[];
|
|
16
|
+
strategy_intents: import("../../persona/strategy-intent.js").StrategyIntent[];
|
|
17
|
+
lever_suggestions: import("../../persona/strategy-intent.js").LeverSuggestion[];
|
|
13
18
|
recommendations: {
|
|
14
19
|
industry: string;
|
|
15
20
|
similarity: number;
|
|
16
21
|
matched_traits: string[];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}[];
|
|
22
|
+
strategy_alignment: {
|
|
23
|
+
score: number;
|
|
24
|
+
matched_levers: InfrastructureLever[];
|
|
25
|
+
missing_levers: InfrastructureLever[];
|
|
26
|
+
} | undefined;
|
|
23
27
|
}[];
|
|
24
28
|
hint: string;
|
|
25
29
|
};
|
|
@@ -135,7 +139,7 @@ export interface RegisterCustomMetricInput {
|
|
|
135
139
|
metric_scale?: MetricScale;
|
|
136
140
|
metric_weight?: number;
|
|
137
141
|
}
|
|
138
|
-
export declare function handleRegisterCustomMetric(v: RegisterCustomMetricInput): {
|
|
142
|
+
export declare function handleRegisterCustomMetric(v: RegisterCustomMetricInput): Promise<{
|
|
139
143
|
action: "register_custom_metric";
|
|
140
144
|
metric: {
|
|
141
145
|
metric_id: string;
|
|
@@ -148,7 +152,14 @@ export declare function handleRegisterCustomMetric(v: RegisterCustomMetricInput)
|
|
|
148
152
|
owner: string;
|
|
149
153
|
};
|
|
150
154
|
hint: string;
|
|
151
|
-
}
|
|
155
|
+
}>;
|
|
156
|
+
export declare function handleUnregisterCustomMetric(v: {
|
|
157
|
+
metric_id?: string;
|
|
158
|
+
}): Promise<{
|
|
159
|
+
action: "unregister_custom_metric";
|
|
160
|
+
removed: true;
|
|
161
|
+
metric_id: string;
|
|
162
|
+
}>;
|
|
152
163
|
export interface RegisterCustomConstraintInput {
|
|
153
164
|
constraint_id?: string;
|
|
154
165
|
constraint_display_name?: string;
|
|
@@ -157,7 +168,7 @@ export interface RegisterCustomConstraintInput {
|
|
|
157
168
|
constraint_severity?: ConstraintSeverity;
|
|
158
169
|
constraint_on_violation?: ConstraintViolationAction;
|
|
159
170
|
}
|
|
160
|
-
export declare function handleRegisterCustomConstraint(v: RegisterCustomConstraintInput): {
|
|
171
|
+
export declare function handleRegisterCustomConstraint(v: RegisterCustomConstraintInput): Promise<{
|
|
161
172
|
action: "register_custom_constraint";
|
|
162
173
|
constraint: {
|
|
163
174
|
constraint_id: string;
|
|
@@ -170,12 +181,19 @@ export declare function handleRegisterCustomConstraint(v: RegisterCustomConstrai
|
|
|
170
181
|
owner: string;
|
|
171
182
|
};
|
|
172
183
|
hint: string;
|
|
173
|
-
}
|
|
184
|
+
}>;
|
|
185
|
+
export declare function handleUnregisterCustomConstraint(v: {
|
|
186
|
+
constraint_id?: string;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
action: "unregister_custom_constraint";
|
|
189
|
+
removed: true;
|
|
190
|
+
constraint_id: string;
|
|
191
|
+
}>;
|
|
174
192
|
export interface ListMetricsConstraintsInput {
|
|
175
193
|
metric_type_filter?: MetricType;
|
|
176
194
|
scope_filter?: "builtin" | "custom";
|
|
177
195
|
}
|
|
178
|
-
export declare function handleListMetricsConstraints(v: ListMetricsConstraintsInput): {
|
|
196
|
+
export declare function handleListMetricsConstraints(v: ListMetricsConstraintsInput): Promise<{
|
|
179
197
|
action: "list_metrics_constraints";
|
|
180
198
|
metrics: {
|
|
181
199
|
metric_id: string;
|
|
@@ -196,4 +214,4 @@ export declare function handleListMetricsConstraints(v: ListMetricsConstraintsIn
|
|
|
196
214
|
scope: "custom" | "builtin";
|
|
197
215
|
}[];
|
|
198
216
|
hint: string;
|
|
199
|
-
}
|
|
217
|
+
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getIndustryModeRegistry,getMetricRegistry,getConstraintRegistry}from'../../extensions/index.js';import{inferTraitsFromDescription,findSimilarIndustries}from'../../knowledge/industry-generalizer.js';import{searchExamples}from'../../schema-query-impl/index.js';const LOCAL_MODE_OWNER='local',RM1_11_NODE_REGEX=/(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;function validateMachineShape(a,b){const c=[];if(!Array['isArray'](a))return c;const d=new Set();for(const e of a){const f=e?.['name'];if(typeof f!=='string'||!f){c['push'](b+':\x20every\x20node\x20must\x20have\x20a\x20non-empty\x20string\x20\x27name\x27');continue;}d['has'](f)&&c['push'](b+':\x20duplicate\x20node\x20name\x20\x27'+f+'\x27\x20(R-M1-10)'),d['add'](f),RM1_11_NODE_REGEX['test'](f)&&c['push'](b+':\x20node\x20\x27'+f+'\x27\x20violates\x20R-M1-11\x20—\x20dispute/refund\x20flows\x20must\x20NOT\x20be\x20'+'modeled\x20as\x20Machine\x20nodes.\x20Disputes\x20flow\x20through\x20Service.arbitrations\x20→\x20Arbitration.dispute()\x20'+'independently\x20of\x20the\x20Machine.\x20Use\x20business-state\x20nodes\x20(e.g.\x20\x27cancelled\x27,\x20\x27return_approved\x27)\x20'+'and\x20route\x20fund\x20refunds\x20via\x20Allocator\x20triggered\x20by\x20those\x20states.');}return c;}export function handleRecommendIndustry(a){const b=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!b)throw new Error('recommend_industry\x20requires\x20\x27intent\x27\x20(business\x20description\x20text).\x20'+'Example:\x20intent=\x27I\x20rent\x20cameras\x20to\x20photographers\x20with\x20deposit\x20and\x20damage\x20inspection\x27.');const c=inferTraitsFromDescription(b),d=findSimilarIndustries(c['traits'],0x3),e=d['map'](g=>{const h=searchExamples(g['industry'])['slice'](0x0,0x3)['map'](i=>({'file':i['file'],'title':i['title'],'operation_type':i['operation_type'],'verified':i['verified']}));return{'industry':g['industry'],'similarity':g['similarity'],'matched_traits':g['matched_traits'],'reference_examples':h};}),f=e[0x0];return{'action':'recommend_industry','intent':b,'inferred_traits':c['traits'],'inference_confidence':c['confidence'],'matched_keywords':c['matched_keywords'],'recommendations':e,'hint':f?'Top\x20match:\x20\x27'+f['industry']+'\x27\x20(similarity\x20'+(f['similarity']*0x64)['toFixed'](0x0)+'%).\x20'+'Use\x20it\x20to\x20shape\x20the\x20build\x20—\x20run\x20goal_operation\x20action=\x27merchant_guide\x27\x20(or\x20\x27analyze_intent\x27)\x20with\x20this\x20industry\x20context,\x20'+'or\x20choose\x20another\x20industry\x20from\x20\x27recommendations\x27.\x20'+'Review\x20reference\x20examples\x20via\x20schema_query\x20action=\x27search_examples\x27\x20query=\x27<industry>\x27.':'No\x20similar\x20industry\x20found.\x20Shape\x20the\x20build\x20from\x20scratch\x20via\x20goal_operation\x20action=\x27merchant_guide\x27.'};}export async function handleListModes(){const a=getIndustryModeRegistry(),b=a['listModes']()['filter'](d=>d['source']==='builtin')['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'similar_industries':d['similar_industries']??[]})),c=(await a['listUserModes'](LOCAL_MODE_OWNER))['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'derived_from':d['derived_from']??null,'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'evolution_history':(d['evolution_history']??[])['map'](e=>({'version':e['version'],'changed_at':e['changed_at'],'changes':e['changes']}))}));return{'action':'list_modes','builtin_modes':b,'user_modes':c,'owner':LOCAL_MODE_OWNER,'hint':'Use\x20a\x20builtin\x20mode\x20name\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build\x20(see\x20recommend_industry\x20/\x20merchant_guide).\x20'+'Use\x20derive_user_mode\x20to\x20customize\x20a\x20builtin\x20mode,\x20or\x20register_user_mode\x20for\x20a\x20fully\x20custom\x20mode.\x20'+'User\x20modes\x20are\x20referenced\x20as\x20\x27<name>\x27\x20in\x20derive/evolve/unregister\x20actions.'};}export async function handleDeriveUserMode(a){const b=requireField(a['mode_source'],'mode_source'),c=requireField(a['mode_name'],'mode_name'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('derive_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['deriveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_display_name']);if(!g)throw new Error('derive_user_mode\x20failed:\x20source\x20mode\x20\x27'+b+'\x27\x20not\x20found,\x20or\x20name\x20\x27'+c+'\x27\x20conflicts\x20'+'with\x20a\x20builtin/existing\x20user\x20mode.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'derive_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+c+'\x27\x20derived\x20from\x20\x27'+b+'\x27.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.\x20'+'Iterate\x20with\x20evolve_user_mode.'};}export async function handleEvolveUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=requireField(a['mode_change_description'],'mode_change_description'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('evolve_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['evolveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_bump_version']??!![]);if(!g)throw new Error('evolve_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.\x20'+'Call\x20list_modes\x20to\x20see\x20your\x20modes.');return{'action':'evolve_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+b+'\x27\x20evolved\x20to\x20'+g['version']+'.\x20Evolution\x20history\x20recorded.'};}export async function handleRegisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=a['mode_changes']??{},d=[];(!Array['isArray'](c['machine_shape'])||c['machine_shape']['length']===0x0)&&d['push']('machine_shape\x20(non-empty\x20array\x20of\x20{name,\x20role})');(typeof c['key_risk']!=='string'||!c['key_risk'])&&d['push']('key_risk\x20(string\x20describing\x20the\x20industry\x27s\x20key\x20risk)');if(d['length']>0x0)throw new Error('register_user_mode\x20requires\x20these\x20fields\x20in\x20mode_changes:\x20'+d['join'](',\x20')+'.\x20'+'Tip:\x20derive_user_mode\x20from\x20a\x20builtin\x20mode\x20is\x20usually\x20easier\x20than\x20registering\x20from\x20scratch.');const e=validateMachineShape(c['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('register_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=f['getMode']('general');if(!g)throw new Error('Builtin\x20mode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20build\x20custom\x20mode\x20defaults');const h={...g,...c,'name':b,'display_name':a['mode_display_name']??b,'version':'v1','source':'custom','owner':LOCAL_MODE_OWNER,'derived_from':undefined,'evolution_history':[]},i=await f['registerUserMode'](h,LOCAL_MODE_OWNER);if(!i)throw new Error('register_user_mode\x20failed:\x20name\x20\x27'+b+'\x27\x20conflicts\x20with\x20a\x20builtin/existing\x20user\x20mode,\x20'+'or\x20payload\x20is\x20invalid.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'register_user_mode','mode':summarizeUserMode(h),'hint':'Custom\x20mode\x20\x27'+b+'\x27\x20registered.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.'};}export async function handleUnregisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=getIndustryModeRegistry(),d=await c['unregisterUserMode'](b,LOCAL_MODE_OWNER);if(!d)throw new Error('unregister_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.');return{'action':'unregister_user_mode','removed':!![],'mode_name':b};}export function handleRegisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=requireField(a['metric_display_name'],'metric_display_name'),d=requireField(a['metric_description'],'metric_description'),e=requireField(a['metric_type'],'metric_type'),f=requireField(a['metric_scale'],'metric_scale'),g=getMetricRegistry()['registerCustomMetric'](b,c,d,e,f,LOCAL_MODE_OWNER,a['metric_weight']);if(!g)throw new Error('register_custom_metric\x20failed:\x20metric_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20fields\x20are\x20invalid.');return{'action':'register_custom_metric','metric':{'metric_id':b,'display_name':c,'description':d,'type':e,'scale':f,'weight':a['metric_weight']??0x1,'scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20metric\x20\x27'+b+'\x27\x20registered\x20globally\x20—\x20all\x20modes\x20can\x20reference\x20it\x20via\x20custom_metrics.'};}export function handleRegisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=requireField(a['constraint_display_name'],'constraint_display_name'),d=requireField(a['constraint_description'],'constraint_description'),e=a['constraint_rule'];if(!e||typeof e!=='object'||!('type'in e))throw new Error('constraint_rule\x20is\x20required\x20and\x20must\x20be\x20one\x20of:\x20'+'{type:\x27capability_required\x27,\x20capability_id}\x20|\x20{type:\x27capability_forbidden\x27,\x20capability_id}\x20|\x20'+'{type:\x27numeric_limit\x27,\x20field,\x20max?,\x20min?}\x20|\x20{type:\x27condition_required\x27,\x20condition,\x20ai_evaluated:true}');const f=getConstraintRegistry()['registerCustomConstraint'](b,c,d,e,LOCAL_MODE_OWNER,a['constraint_severity']??'soft',a['constraint_on_violation']??'warn');if(!f)throw new Error('register_custom_constraint\x20failed:\x20constraint_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20rule\x20is\x20invalid.');return{'action':'register_custom_constraint','constraint':{'constraint_id':b,'display_name':c,'description':d,'rule':e,'severity':a['constraint_severity']??'soft','on_violation':a['constraint_on_violation']??'warn','scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20constraint\x20\x27'+b+'\x27\x20registered.\x20\x27hard\x27\x20constraints\x20block\x20applyTemplate\x20on\x20violation;\x20\x27soft\x27\x20only\x20warn.'};}export function handleListMetricsConstraints(a){const b=getMetricRegistry()['listMetrics']({'type':a['metric_type_filter'],'scope':a['scope_filter']})['map'](d=>({'metric_id':d['metric_id'],'display_name':d['display_name'],'description':d['description'],'type':d['type'],'scale':d['scale'],'weight':d['weight'],'scope':d['scope']})),c=getConstraintRegistry()['listConstraints']({'scope':a['scope_filter']})['map'](d=>({'constraint_id':d['constraint_id'],'display_name':d['display_name'],'description':d['description'],'rule':d['rule'],'severity':d['severity'],'on_violation':d['on_violation'],'scope':d['scope']}));return{'action':'list_metrics_constraints','metrics':b,'constraints':c,'hint':'Register\x20custom\x20entries\x20via\x20register_custom_metric\x20/\x20register_custom_constraint.\x20'+'Filter\x20with\x20metric_type_filter\x20(\x27risk\x27|\x27benefit\x27)\x20or\x20scope_filter\x20(\x27builtin\x27|\x27custom\x27).'};}function requireField(a,b){if(a===undefined||a===null||typeof a==='string'&&!a['trim']())throw new Error('\x27'+b+'\x27\x20is\x20required\x20for\x20this\x20action');return a;}function summarizeUserMode(a){return{'name':a['name'],'display_name':a['display_name'],'version':a['version'],'derived_from':a['derived_from']??null,'owner':a['owner'],'key_risk':a['key_risk'],'machine_nodes':a['machine_shape']['map'](b=>b['name']),'evolution_history':(a['evolution_history']??[])['map'](b=>({'version':b['version'],'changed_at':b['changed_at'],'changes':b['changes']}))};}
|
|
1
|
+
import{getIndustryModeRegistry,getMetricRegistry,getConstraintRegistry}from'../../extensions/index.js';import{inferTraitsFromDescription,findSimilarIndustries}from'../../knowledge/industry-generalizer.js';import{resolveObjective,buildStrategyIntent,suggestLevers}from'../../persona/strategy-intent.js';export const LOCAL_MODE_OWNER='local';const RM1_11_NODE_REGEX=/(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;function validateMachineShape(a,b){const c=[];if(!Array['isArray'](a))return c;const d=new Set();for(const e of a){const f=e?.['name'];if(typeof f!=='string'||!f){c['push'](b+':\x20every\x20node\x20must\x20have\x20a\x20non-empty\x20string\x20\x27name\x27');continue;}d['has'](f)&&c['push'](b+':\x20duplicate\x20node\x20name\x20\x27'+f+'\x27\x20(R-M1-10)'),d['add'](f),RM1_11_NODE_REGEX['test'](f)&&c['push'](b+':\x20node\x20\x27'+f+'\x27\x20violates\x20R-M1-11\x20—\x20dispute/refund\x20flows\x20must\x20NOT\x20be\x20'+'modeled\x20as\x20Machine\x20nodes.\x20Disputes\x20flow\x20through\x20Service.arbitrations\x20→\x20Arbitration.dispute()\x20'+'independently\x20of\x20the\x20Machine.\x20Use\x20business-state\x20nodes\x20(e.g.\x20\x27cancelled\x27,\x20\x27return_approved\x27)\x20'+'and\x20route\x20fund\x20refunds\x20via\x20Allocator\x20triggered\x20by\x20those\x20states.');}return c;}function modeLevers(a){const b=[];return(a['capabilities_used']['some'](d=>d['startsWith']('reward.'))||a['flywheel']?.['rewardStrategy']&&a['flywheel']['rewardStrategy']!=='User-defined')&&b['push']('reward'),(a['flywheel']?.['discountStrategy']&&a['flywheel']['discountStrategy']!=='User-defined'||a['config_overrides']?.['service']?.['first_order_discount']===!![])&&b['push']('discount'),(a['capabilities_used']['includes']('guard.validate_buy')||a['guards']['some'](c=>c['template_id']['includes']('buy')))&&b['push']('buy_guard'),a['capabilities_used']['includes']('machine.node_topology')&&a['machine_shape']['length']>0x0&&b['push']('machine_design'),b;}function resolveStrategyObjectives(a){const b=typeof a==='string'?[a]:a??[],c=new Set();for(const d of b){const e=resolveObjective(d);if(e)c['add'](e);}return[...c];}export function handleRecommendIndustry(a){const b=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!b)throw new Error('recommend_industry\x20requires\x20\x27intent\x27\x20(business\x20description\x20text).\x20'+'Example:\x20intent=\x27I\x20rent\x20cameras\x20to\x20photographers\x20with\x20deposit\x20and\x20damage\x20inspection\x27.');const c=inferTraitsFromDescription(b),d=findSimilarIndustries(c['traits'],0x3),e=resolveStrategyObjectives(a['strategy']),f=e['map'](k=>buildStrategyIntent(k)),g=[...new Set(f['flatMap'](k=>k['levers']))],h=getIndustryModeRegistry(),i=d['map'](k=>{const l=h['getMode'](k['industry']),n=l?modeLevers(l):[],o=g['filter'](q=>n['includes'](q)),p=g['length']>0x0?{'score':o['length']/g['length'],'matched_levers':o,'missing_levers':g['filter'](q=>!n['includes'](q))}:undefined;return{'industry':k['industry'],'similarity':k['similarity'],'matched_traits':k['matched_traits'],'strategy_alignment':p};});g['length']>0x0&&i['sort']((k,l)=>{const m=k['similarity']*0.7+(k['strategy_alignment']?.['score']??0x0)*0.3,n=l['similarity']*0.7+(l['strategy_alignment']?.['score']??0x0)*0.3;return n-m;});const j=i[0x0];return{'action':'recommend_industry','intent':b,'inferred_traits':c['traits'],'inference_confidence':c['confidence'],'matched_keywords':c['matched_keywords'],'strategy_intents':f,'lever_suggestions':f['flatMap'](k=>suggestLevers(k)),'recommendations':i,'hint':j?'Top\x20match:\x20\x27'+j['industry']+'\x27\x20(similarity\x20'+(j['similarity']*0x64)['toFixed'](0x0)+'%'+(g['length']>0x0?',\x20strategy\x20alignment\x20'+((j['strategy_alignment']?.['score']??0x0)*0x64)['toFixed'](0x0)+'%':'')+').\x20Use\x20it\x20to\x20shape\x20the\x20build\x20—\x20run\x20goal_operation\x20action=\x27merchant_guide\x27\x20(or\x20\x27analyze_intent\x27)\x20with\x20this\x20industry\x20context,\x20'+'or\x20choose\x20another\x20industry\x20from\x20\x27recommendations\x27.':'No\x20similar\x20industry\x20found.\x20Shape\x20the\x20build\x20from\x20scratch\x20via\x20goal_operation\x20action=\x27merchant_guide\x27.'};}export async function handleListModes(){const a=getIndustryModeRegistry(),b=a['listModes']()['filter'](d=>d['source']==='builtin')['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'similar_industries':d['similar_industries']??[]})),c=(await a['listUserModes'](LOCAL_MODE_OWNER))['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'derived_from':d['derived_from']??null,'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'evolution_history':(d['evolution_history']??[])['map'](e=>({'version':e['version'],'changed_at':e['changed_at'],'changes':e['changes']}))}));return{'action':'list_modes','builtin_modes':b,'user_modes':c,'owner':LOCAL_MODE_OWNER,'hint':'Use\x20a\x20builtin\x20mode\x20name\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build\x20(see\x20recommend_industry\x20/\x20merchant_guide).\x20'+'Use\x20derive_user_mode\x20to\x20customize\x20a\x20builtin\x20mode,\x20or\x20register_user_mode\x20for\x20a\x20fully\x20custom\x20mode.\x20'+'User\x20modes\x20are\x20referenced\x20as\x20\x27<name>\x27\x20in\x20derive/evolve/unregister\x20actions.'};}export async function handleDeriveUserMode(a){const b=requireField(a['mode_source'],'mode_source'),c=requireField(a['mode_name'],'mode_name'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('derive_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['deriveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_display_name']);if(!g)throw new Error('derive_user_mode\x20failed:\x20source\x20mode\x20\x27'+b+'\x27\x20not\x20found,\x20or\x20name\x20\x27'+c+'\x27\x20conflicts\x20'+'with\x20a\x20builtin/existing\x20user\x20mode.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'derive_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+c+'\x27\x20derived\x20from\x20\x27'+b+'\x27.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.\x20'+'Iterate\x20with\x20evolve_user_mode.'};}export async function handleEvolveUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=requireField(a['mode_change_description'],'mode_change_description'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('evolve_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['evolveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_bump_version']??!![]);if(!g)throw new Error('evolve_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.\x20'+'Call\x20list_modes\x20to\x20see\x20your\x20modes.');return{'action':'evolve_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+b+'\x27\x20evolved\x20to\x20'+g['version']+'.\x20Evolution\x20history\x20recorded.'};}export async function handleRegisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=a['mode_changes']??{},d=[];(!Array['isArray'](c['machine_shape'])||c['machine_shape']['length']===0x0)&&d['push']('machine_shape\x20(non-empty\x20array\x20of\x20{name,\x20role})');(typeof c['key_risk']!=='string'||!c['key_risk'])&&d['push']('key_risk\x20(string\x20describing\x20the\x20industry\x27s\x20key\x20risk)');if(d['length']>0x0)throw new Error('register_user_mode\x20requires\x20these\x20fields\x20in\x20mode_changes:\x20'+d['join'](',\x20')+'.\x20'+'Tip:\x20derive_user_mode\x20from\x20a\x20builtin\x20mode\x20is\x20usually\x20easier\x20than\x20registering\x20from\x20scratch.');const e=validateMachineShape(c['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('register_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=f['getMode']('general');if(!g)throw new Error('Builtin\x20mode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20build\x20custom\x20mode\x20defaults');const h={...g,...c,'name':b,'display_name':a['mode_display_name']??b,'version':'v1','source':'custom','owner':LOCAL_MODE_OWNER,'derived_from':undefined,'evolution_history':[]},i=await f['registerUserMode'](h,LOCAL_MODE_OWNER);if(!i)throw new Error('register_user_mode\x20failed:\x20name\x20\x27'+b+'\x27\x20conflicts\x20with\x20a\x20builtin/existing\x20user\x20mode,\x20'+'or\x20payload\x20is\x20invalid.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'register_user_mode','mode':summarizeUserMode(h),'hint':'Custom\x20mode\x20\x27'+b+'\x27\x20registered.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.'};}export async function handleUnregisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=getIndustryModeRegistry(),d=await c['unregisterUserMode'](b,LOCAL_MODE_OWNER);if(!d)throw new Error('unregister_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.');return{'action':'unregister_user_mode','removed':!![],'mode_name':b};}export async function handleRegisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=requireField(a['metric_display_name'],'metric_display_name'),d=requireField(a['metric_description'],'metric_description'),e=requireField(a['metric_type'],'metric_type'),f=requireField(a['metric_scale'],'metric_scale'),g=await getMetricRegistry()['registerCustomMetric'](b,c,d,e,f,LOCAL_MODE_OWNER,a['metric_weight']);if(!g)throw new Error('register_custom_metric\x20failed:\x20metric_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20fields\x20are\x20invalid.');return{'action':'register_custom_metric','metric':{'metric_id':b,'display_name':c,'description':d,'type':e,'scale':f,'weight':a['metric_weight']??0x1,'scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20metric\x20\x27'+b+'\x27\x20registered\x20globally\x20and\x20persisted\x20(survives\x20restart)\x20—\x20all\x20modes\x20reference\x20it\x20in\x20evaluation.'};}export async function handleUnregisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=await getMetricRegistry()['unregisterMetric'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_metric\x20failed:\x20custom\x20metric\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20metrics\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20metrics.');return{'action':'unregister_custom_metric','removed':!![],'metric_id':b};}export async function handleRegisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=requireField(a['constraint_display_name'],'constraint_display_name'),d=requireField(a['constraint_description'],'constraint_description'),e=a['constraint_rule'];if(!e||typeof e!=='object'||!('type'in e))throw new Error('constraint_rule\x20is\x20required\x20and\x20must\x20be\x20one\x20of:\x20'+'{type:\x27capability_required\x27,\x20capability_id}\x20|\x20{type:\x27capability_forbidden\x27,\x20capability_id}\x20|\x20'+'{type:\x27numeric_limit\x27,\x20field,\x20max?,\x20min?}\x20|\x20{type:\x27condition_required\x27,\x20condition,\x20ai_evaluated:true}');const f=await getConstraintRegistry()['registerCustomConstraint'](b,c,d,e,LOCAL_MODE_OWNER,a['constraint_severity']??'soft',a['constraint_on_violation']??'warn');if(!f)throw new Error('register_custom_constraint\x20failed:\x20constraint_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20rule\x20is\x20invalid.');return{'action':'register_custom_constraint','constraint':{'constraint_id':b,'display_name':c,'description':d,'rule':e,'severity':a['constraint_severity']??'soft','on_violation':a['constraint_on_violation']??'warn','scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20constraint\x20\x27'+b+'\x27\x20registered\x20and\x20persisted\x20(survives\x20restart).\x20\x27hard\x27\x20constraints\x20mark\x20a\x20mode\x20not\x20applicable\x20on\x20violation;\x20\x27soft\x27\x20only\x20warn.'};}export async function handleUnregisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=await getConstraintRegistry()['unregisterConstraint'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_constraint\x20failed:\x20custom\x20constraint\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20constraints\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20constraints.');return{'action':'unregister_custom_constraint','removed':!![],'constraint_id':b};}export async function handleListMetricsConstraints(a){const b=(await getMetricRegistry()['listMetrics']({'type':a['metric_type_filter'],'scope':a['scope_filter']}))['map'](d=>({'metric_id':d['metric_id'],'display_name':d['display_name'],'description':d['description'],'type':d['type'],'scale':d['scale'],'weight':d['weight'],'scope':d['scope']})),c=(await getConstraintRegistry()['listConstraints']({'scope':a['scope_filter']}))['map'](d=>({'constraint_id':d['constraint_id'],'display_name':d['display_name'],'description':d['description'],'rule':d['rule'],'severity':d['severity'],'on_violation':d['on_violation'],'scope':d['scope']}));return{'action':'list_metrics_constraints','metrics':b,'constraints':c,'hint':'Register\x20custom\x20entries\x20via\x20register_custom_metric\x20/\x20register_custom_constraint;\x20'+'delete\x20via\x20unregister_custom_metric\x20/\x20unregister_custom_constraint\x20(custom\x20only).\x20'+'Custom\x20entries\x20are\x20persisted\x20and\x20survive\x20restart.\x20'+'Filter\x20with\x20metric_type_filter\x20(\x27risk\x27|\x27benefit\x27)\x20or\x20scope_filter\x20(\x27builtin\x27|\x27custom\x27).'};}function requireField(a,b){if(a===undefined||a===null||typeof a==='string'&&!a['trim']())throw new Error('\x27'+b+'\x27\x20is\x20required\x20for\x20this\x20action');return a;}function summarizeUserMode(a){return{'name':a['name'],'display_name':a['display_name'],'version':a['version'],'derived_from':a['derived_from']??null,'owner':a['owner'],'key_risk':a['key_risk'],'machine_nodes':a['machine_shape']['map'](b=>b['name']),'evolution_history':(a['evolution_history']??[])['map'](b=>({'version':b['version'],'changed_at':b['changed_at'],'changes':b['changes']}))};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Config,LocalMark,query_objects,query_object_last_updated,queryTableItem_ObjectLinkerTx,queryTableItem_DemandPresenter,objectTypeFromAddress,ObjectType}from'@wowok/wowok';const js=a=>{if(typeof a==='bigint')return a['toString']();if(a&&typeof a==='object'&&!Array['isArray'](a)){const b={};for(const [c,d]of Object['entries'](a)){b[c]=js(d);}return b;}if(Array['isArray'](a))return a['map'](js);return a;},str=a=>a===null||a===undefined?null:String(a),ownerAddr=a=>{if(typeof a==='string')return a;const b=a;if(b&&typeof b==='object'){if(typeof b['AddressOwner']==='string')return b['AddressOwner'];if(typeof b['ObjectOwner']==='string')return b['ObjectOwner'];const c=Object['values'](b)['find'](d=>typeof d==='string'&&d['length']>0x14);if(typeof c==='string')return c;}return null;},num=a=>{if(typeof a==='bigint')return Number(a);if(typeof a==='number')return Number['isFinite'](a)?a:null;if(typeof a==='string'&&a['trim']()!==''){const b=Number(a);return Number['isFinite'](b)?b:null;}return null;},arr=a=>Array['isArray'](a)?a:[],ARB_STATUS_NAMES={0x0:'Principal_confirming',0x1:'Arbitrator_confirming',0x2:'Voting',0x3:'Arbitrated',0x4:'Objectionable',0x5:'Finished',0x6:'Withdrawn'};async function resolveObject(a,b){let c=a;if(!/^0x[0-9a-fA-F]{32,64}$/['test'](c)){const g=await LocalMark['Instance']()['get_address'](c);if(!g)throw new Error('Cannot\x20resolve\x20\x27'+c+'\x27\x20—\x20not\x20a\x20valid\x20address\x20and\x20no\x20LocalMark\x20entry\x20found.');c=g;}let d=b??undefined,f=null;if(!d)d=await Config['Instance']()['network_get']();try{const h=await query_objects({'objects':[c],'network':d});f=h?.['objects']?.[0x0]??null;if(!f&&b){const i=await Config['Instance']()['network_get']();if(i&&i!==d){const j=await query_objects({'objects':[c],'network':i,'no_cache':!![]}),k=j?.['objects']?.[0x0]??null;k&&(f=k,d=i);}}}catch(l){throw new Error('Failed\x20to\x20query\x20'+c+'\x20on\x20'+d+':\x20'+(l instanceof Error?l['message']:String(l)));}if(!f)throw new Error(c+'\x20not\x20found\x20on\x20'+d+'.\x20It\x20may\x20not\x20exist\x20on\x20this\x20network.');return f['object']=f['object']??c,{'network':String(d),'obj':f};}async function resolveHead(a,b,c){let d=null,e=[];try{const f=await LocalMark['Instance']()['list']({'address':a});f['length']>0x0&&(d=f[0x0]['name']??null,e=(f[0x0]['tags']??[])['map'](g=>String(g)));}catch{c['push']('head:\x20LocalMark\x20lookup\x20failed');}return{'name':d,'tags':e,'description':str(b['description'])};}async function buildPresenters(a,b,c){const d=[];let e=0x0;try{const f=await queryTableItem_ObjectLinkerTx({'address':a,'no_cache':!![],'network':b}),g=(f?.['items']??[])['map'](j=>({'service':String(j?.['who']??''),'time':typeof j?.['time']==='number'?j['time']:null}))['filter'](i=>objectTypeFromAddress(i['service'])===ObjectType['Service']);e=g['length'];const h=g['slice'](-0x32)['reverse']();for(const i of h){let j;try{j=await queryTableItem_DemandPresenter({'parent':a,'address':i['service'],'no_cache':!![],'network':b});}catch{c['push']('presenters:\x20detail\x20fetch\x20failed\x20for\x20one\x20entry');}d['push']({'service':i['service'],'recommend':str(j?.['recommend']),'acceptance_score':num(j?.['acceptance_score']),'feedback':str(j?.['feedback']),'feedback_time':num(j?.['feedback_time']),'update_time':num(j?.['update_time'])??i['time']});}}catch{c['push']('presenters:\x20global-table\x20lookup\x20failed\x20(non-blocking)');}return{'count':e,'items':d};}async function buildRepositoryData(a,b,c){return void a,void b,c['push']('data:\x20per-key\x20enumeration\x20requires\x20the\x20{entity,name}\x20pair\x20—\x20showing\x20count\x20only'),{'count':null,'items':[]};}export async function handleObjectPanorama(b){const c=b['object_address'];if(!c)throw new Error('\x27object_address\x27\x20is\x20required\x20for\x20object_panorama');const {network:d,obj:e}=await resolveObject(c,b['context_network']),f=String(e['object']),g=[],h=await resolveHead(f,e,g),j=String(e['type']??'');if(j==='Progress'){const k=arr(e['session'])[0x0],l=k?{'next_node':str(k['next_node']),'weights':num(k['weights']),'threshold':num(k['threshold']),'forwards':arr(k['forwards'])['map'](n=>{const o=n;return{'forward':str(o['forward'])??'','who':str(o['who']),'accomplished':o['accomplished']===!![],'msg':str(o['msg']),'time':num(o['time'])};})}:null,m={'key':typeof e['machine']==='string'?e['machine']:null,'items':[],'count':0x0};if(m['key'])try{const n=await queryTableItem_ObjectLinkerTx({'address':m['key'],'no_cache':!![],'network':d}),o=n?.['items']??[];for(const q of o['slice'](-0x32)['reverse']()){const r=typeof q?.['who']==='string'?q['who']:'';if(!r||r['toLowerCase']()===f['toLowerCase']())continue;let s;try{s=objectTypeFromAddress(r);}catch{}if(!s)continue;m['items']['push']({'address':r,'object_type':s,'time':typeof q?.['time']==='number'?q['time']:null});}m['count']=m['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(machine)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Progress','network':d,'head':h,'fields':{'machine':str(e['machine']),'current':str(e['current']),'task':str(e['task']),'history_count':num(e['history_count']),'current_time':num(e['current_time'])},'context_repositories':arr(e['context_repositories'])['map'](t=>String(t)),'operators':arr(e['namedOperator'])['map'](t=>{const u=t;return{'name':str(u['name'])??'','operators':arr(u['operators'])['map'](w=>String(w))};}),'session':l,'related':m,'data_gaps':g};}if(j==='Demand')return{'action':'object_panorama','object':f,'object_type':'Demand','network':d,'head':h,'fields':{'location':str(e['location']),'um':str(e['um']),'permission':str(e['permission']),'presenters_count':num(e['presenters_count'])},'rewards':arr(e['rewards'])['map'](t=>String(t)),'guards':arr(e['guards'])['map'](t=>({'guard':str(t['guard'])??''})),'presenters':await buildPresenters(f,d,g),'data_gaps':g};if(j==='Order'){let t=null;try{const C=await query_object_last_updated({'object':f,'network':d,'previous_transaction':str(e['previousTransaction'])});t=C?.['timestamp_ms']?Number(C['timestamp_ms'])||null:null;}catch{}let u='none',w=null,x=null;const y=str(e['allocation']),z=str(e['progress']),A=[y,z]['filter'](D=>!!D);if(A['length']>0x0)try{const D=await query_objects({'objects':A,'network':d}),E=D?.['objects']??[];if(y){u='pending';const F=E['find'](H=>H?.['object']===y),G=Number(F?.['balance']??NaN);if(Number['isFinite'](G)&&G===0x0)u='allocated';}if(z){const H=E['find'](I=>I?.['object']===z);w=str(H?.['current']),x=num(H?.['current_time']);}}catch{}const B={'key':f,'items':[],'count':0x0};try{const I=await queryTableItem_ObjectLinkerTx({'address':f,'no_cache':!![],'network':d}),J=I?.['items']??[];for(const K of J['slice'](-0x32)['reverse']()){const L=typeof K?.['who']==='string'?K['who']:'';if(!L||L['toLowerCase']()===f['toLowerCase']())continue;let M;try{M=objectTypeFromAddress(L);}catch{}if(!M)continue;B['items']['push']({'address':L,'object_type':M,'time':typeof K?.['time']==='number'?K['time']:null});}B['count']=B['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(order)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Order','network':d,'head':h,'fields':{'service':str(e['service']),'machine':str(e['machine']),'progress':z,'allocation':y,'discount':str(e['discount']),'amount':str(e['amount']),'owner':ownerAddr(e['builder']??e['owner']),'claimed_by':str(e['claimed_by']),'required_info':str(e['required_info']),'time':num(e['time'])},'updated_ms':t,'related':B,'allocation_state':u,'progress_next':w,'progress_since':x,'items':arr(e['items'])['map'](N=>{const O=N;return{'name':str(O['name']),'price':str(O['price']),'quantity':str(O['quantity']),'wip_hash':str(O['wip_hash'])};}),'disputes':arr(e['dispute'])['map'](N=>String(N)),'agents':arr(e['agent'])['map'](N=>String(N)),'data_gaps':g};}if(j==='Arb'){const N=e['indemnity'];let O=null;try{const S=await query_object_last_updated({'object':f,'network':d,'previous_transaction':str(e['previousTransaction'])});O=S?.['timestamp_ms']?Number(S['timestamp_ms'])||null:null;}catch{}const P=str(e['order']);let Q=null;if(P)try{const T=await query_objects({'objects':[P],'network':d}),U=T?.['objects']?.[0x0];Q=str(U?.['service']);}catch{}const R={'key':f,'items':[],'count':0x0};try{const V=await queryTableItem_ObjectLinkerTx({'address':f,'no_cache':!![],'network':d}),W=V?.['items']??[];for(const X of W['slice'](-0x32)['reverse']()){const Y=typeof X?.['who']==='string'?X['who']:'';if(!Y||Y['toLowerCase']()===f['toLowerCase']())continue;let Z;try{Z=objectTypeFromAddress(Y);}catch{}if(!Z)continue;R['items']['push']({'address':Y,'object_type':Z,'time':typeof X?.['time']==='number'?X['time']:null});}R['count']=R['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(arb)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Arb','network':d,'head':h,'fields':{'arbitration':str(e['arbitration']),'order':str(e['order']),'service':Q,'fee':str(e['fee']),'feedback':str(e['feedback']),'indemnity':N?{'amount':str(N['amount']),'time':num(N['time'])}:null,'voting_deadline':num(e['voting_deadline']),'objection':str(e['objection']),'status':ARB_STATUS_NAMES[num(e['status'])??-0x1]??str(e['status']),'compensation_time':num(e['compensation_time']),'time':num(e['time']),'type_raw':str(e['type_raw'])},'voted':arr(e['voted'])['map'](a0=>{const a1=a0;return{'voter':str(a1['voter'])??'','agrees':arr(a1['agrees'])['map'](a2=>Number(a2)),'weight':num(a1['weight'])??0x0,'time':num(a1['time'])??0x0};}),'proposition':arr(e['proposition'])['map'](a0=>{const a1=a0;return{'name':str(a1['name'])??'','votes':num(a1['votes'])??0x0};}),'related':R,'updated_ms':O,'data_gaps':g};}if(j==='Repository')return{'action':'object_panorama','object':f,'object_type':'Repository','network':d,'head':h,'fields':{'um':str(e['um']),'permission':str(e['permission']),'data_count':num(e['data_count'])},'policies':arr(e['policies'])['map'](a0=>{const a1=a0;return{'name':str(a1['name'])??'','description':str(a1['description']),'id_from':str(a1['id_from']),'value_type':str(a1['value_type']),'write_guards':arr(a1['write_guard'])['length'],'quote_guard':str(a1['quote_guard'])};}),'rewards':arr(e['rewards'])['map'](a0=>String(a0)),'data_entries':await buildRepositoryData(f,d,g),'data_gaps':g};throw new Error('object_panorama:\x20unsupported\x20object\x20type\x20\x27'+(j||'unknown')+'\x27\x20for\x20'+f+'.\x20'+'Supported:\x20Progress\x20/\x20Demand\x20/\x20Order\x20/\x20Arb\x20/\x20Repository.');}
|
|
1
|
+
import{Config,LocalMark,query_objects,query_object_last_updated,objectTypeFromAddress,ObjectType}from'@wowok/wowok';import{batchReadAddressKeyedFields,fetchObjectLinkerTx}from'../../knowledge/workflow-guidance.js';const js=a=>{if(typeof a==='bigint')return a['toString']();if(a&&typeof a==='object'&&!Array['isArray'](a)){const b={};for(const [c,d]of Object['entries'](a)){b[c]=js(d);}return b;}if(Array['isArray'](a))return a['map'](js);return a;},str=a=>a===null||a===undefined?null:String(a),ownerAddr=a=>{if(typeof a==='string')return a;const b=a;if(b&&typeof b==='object'){if(typeof b['AddressOwner']==='string')return b['AddressOwner'];if(typeof b['ObjectOwner']==='string')return b['ObjectOwner'];const c=Object['values'](b)['find'](d=>typeof d==='string'&&d['length']>0x14);if(typeof c==='string')return c;}return null;},num=a=>{if(typeof a==='bigint')return Number(a);if(typeof a==='number')return Number['isFinite'](a)?a:null;if(typeof a==='string'&&a['trim']()!==''){const b=Number(a);return Number['isFinite'](b)?b:null;}return null;},arr=a=>Array['isArray'](a)?a:[],ARB_STATUS_NAMES={0x0:'Principal_confirming',0x1:'Arbitrator_confirming',0x2:'Voting',0x3:'Arbitrated',0x4:'Objectionable',0x5:'Finished',0x6:'Withdrawn'};async function resolveObject(a,b){let c=a;if(!/^0x[0-9a-fA-F]{32,64}$/['test'](c)){const g=await LocalMark['Instance']()['get_address'](c);if(!g)throw new Error('Cannot\x20resolve\x20\x27'+c+'\x27\x20—\x20not\x20a\x20valid\x20address\x20and\x20no\x20LocalMark\x20entry\x20found.');c=g;}let d=b??undefined,f=null;if(!d)d=await Config['Instance']()['network_get']();try{const h=await query_objects({'objects':[c],'network':d});f=h?.['objects']?.[0x0]??null;if(!f&&b){const i=await Config['Instance']()['network_get']();if(i&&i!==d){const j=await query_objects({'objects':[c],'network':i,'no_cache':!![]}),k=j?.['objects']?.[0x0]??null;k&&(f=k,d=i);}}}catch(l){throw new Error('Failed\x20to\x20query\x20'+c+'\x20on\x20'+d+':\x20'+(l instanceof Error?l['message']:String(l)));}if(!f)throw new Error(c+'\x20not\x20found\x20on\x20'+d+'.\x20It\x20may\x20not\x20exist\x20on\x20this\x20network.');return f['object']=f['object']??c,{'network':String(d),'obj':f};}async function resolveHead(a,b,c){let d=null,e=[];try{const f=await LocalMark['Instance']()['list']({'address':a});f['length']>0x0&&(d=f[0x0]['name']??null,e=(f[0x0]['tags']??[])['map'](g=>String(g)));}catch{c['push']('head:\x20LocalMark\x20lookup\x20failed');}return{'name':d,'tags':e,'description':str(b['description'])};}async function buildPresenters(a,b,c){const d=[];let e=0x0;try{const f=await fetchObjectLinkerTx(a,b,!![]),g=(f?.['items']??[])['map'](j=>({'service':String(j?.['who']??''),'time':typeof j?.['time']==='number'?j['time']:null}))['filter'](j=>objectTypeFromAddress(j['service'])===ObjectType['Service']);e=g['length'];const h=g['slice'](-0x32)['reverse'](),i=await batchReadAddressKeyedFields(a,h['map'](j=>j['service']),b,!![]);for(const j of h){const k=i['get'](j['service']['toLowerCase']());d['push']({'service':j['service'],'recommend':str(k?.['recommend']),'acceptance_score':num(k?.['acceptance_score']),'feedback':str(k?.['feedback']),'feedback_time':num(k?.['feedback_time']),'update_time':num(k?.['update_time'])??j['time']});}}catch{c['push']('presenters:\x20global-table\x20lookup\x20failed\x20(non-blocking)');}return{'count':e,'items':d};}async function buildRepositoryData(a,b,c){return void a,void b,c['push']('data:\x20per-key\x20enumeration\x20requires\x20the\x20{entity,name}\x20pair\x20—\x20showing\x20count\x20only'),{'count':null,'items':[]};}export async function handleObjectPanorama(b){const c=b['object_address'];if(!c)throw new Error('\x27object_address\x27\x20is\x20required\x20for\x20object_panorama');const {network:d,obj:e}=await resolveObject(c,b['context_network']),f=String(e['object']),g=[],h=await resolveHead(f,e,g),j=String(e['type']??'');if(j==='Progress'){const k=arr(e['session'])[0x0],l=k?{'next_node':str(k['next_node']),'weights':num(k['weights']),'threshold':num(k['threshold']),'forwards':arr(k['forwards'])['map'](n=>{const o=n;return{'forward':str(o['forward'])??'','who':str(o['who']),'accomplished':o['accomplished']===!![],'msg':str(o['msg']),'time':num(o['time'])};})}:null,m={'key':typeof e['machine']==='string'?e['machine']:null,'items':[],'count':0x0};if(m['key'])try{const n=await fetchObjectLinkerTx(m['key'],d,!![]),o=n?.['items']??[];for(const q of o['slice'](-0x32)['reverse']()){const r=typeof q?.['who']==='string'?q['who']:'';if(!r||r['toLowerCase']()===f['toLowerCase']())continue;let s;try{s=objectTypeFromAddress(r);}catch{}if(!s)continue;m['items']['push']({'address':r,'object_type':s,'time':typeof q?.['time']==='number'?q['time']:null});}m['count']=m['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(machine)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Progress','network':d,'head':h,'fields':{'machine':str(e['machine']),'current':str(e['current']),'task':str(e['task']),'history_count':num(e['history_count']),'current_time':num(e['current_time'])},'context_repositories':arr(e['context_repositories'])['map'](t=>String(t)),'operators':arr(e['namedOperator'])['map'](t=>{const u=t;return{'name':str(u['name'])??'','operators':arr(u['operators'])['map'](w=>String(w))};}),'session':l,'related':m,'data_gaps':g};}if(j==='Demand')return{'action':'object_panorama','object':f,'object_type':'Demand','network':d,'head':h,'fields':{'location':str(e['location']),'um':str(e['um']),'permission':str(e['permission']),'presenters_count':num(e['presenters_count'])},'rewards':arr(e['rewards'])['map'](t=>String(t)),'guards':arr(e['guards'])['map'](t=>({'guard':str(t['guard'])??''})),'presenters':await buildPresenters(f,d,g),'data_gaps':g};if(j==='Order'){let t=null;try{const C=await query_object_last_updated({'object':f,'network':d,'previous_transaction':str(e['previousTransaction'])});t=C?.['timestamp_ms']?Number(C['timestamp_ms'])||null:null;}catch{}let u='none',w=null,x=null;const y=str(e['allocation']),z=str(e['progress']),A=[y,z]['filter'](D=>!!D);if(A['length']>0x0)try{const D=await query_objects({'objects':A,'network':d}),E=D?.['objects']??[];if(y){u='pending';const F=E['find'](H=>H?.['object']===y),G=Number(F?.['balance']??NaN);if(Number['isFinite'](G)&&G===0x0)u='allocated';}if(z){const H=E['find'](I=>I?.['object']===z);w=str(H?.['current']),x=num(H?.['current_time']);}}catch{}const B={'key':f,'items':[],'count':0x0};try{const I=await fetchObjectLinkerTx(f,d,!![]),J=I?.['items']??[];for(const K of J['slice'](-0x32)['reverse']()){const L=typeof K?.['who']==='string'?K['who']:'';if(!L||L['toLowerCase']()===f['toLowerCase']())continue;let M;try{M=objectTypeFromAddress(L);}catch{}if(!M)continue;B['items']['push']({'address':L,'object_type':M,'time':typeof K?.['time']==='number'?K['time']:null});}B['count']=B['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(order)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Order','network':d,'head':h,'fields':{'service':str(e['service']),'machine':str(e['machine']),'progress':z,'allocation':y,'discount':str(e['discount']),'amount':str(e['amount']),'owner':ownerAddr(e['builder']??e['owner']),'claimed_by':str(e['claimed_by']),'required_info':str(e['required_info']),'time':num(e['time'])},'updated_ms':t,'related':B,'allocation_state':u,'progress_next':w,'progress_since':x,'items':arr(e['items'])['map'](N=>{const O=N;return{'name':str(O['name']),'price':str(O['price']),'quantity':str(O['quantity']),'wip_hash':str(O['wip_hash'])};}),'disputes':arr(e['dispute'])['map'](N=>String(N)),'agents':arr(e['agent'])['map'](N=>String(N)),'data_gaps':g};}if(j==='Arb'){const N=e['indemnity'];let O=null;try{const S=await query_object_last_updated({'object':f,'network':d,'previous_transaction':str(e['previousTransaction'])});O=S?.['timestamp_ms']?Number(S['timestamp_ms'])||null:null;}catch{}const P=str(e['order']);let Q=null;if(P)try{const T=await query_objects({'objects':[P],'network':d}),U=T?.['objects']?.[0x0];Q=str(U?.['service']);}catch{}const R={'key':f,'items':[],'count':0x0};try{const V=await fetchObjectLinkerTx(f,d,!![]),W=V?.['items']??[];for(const X of W['slice'](-0x32)['reverse']()){const Y=typeof X?.['who']==='string'?X['who']:'';if(!Y||Y['toLowerCase']()===f['toLowerCase']())continue;let Z;try{Z=objectTypeFromAddress(Y);}catch{}if(!Z)continue;R['items']['push']({'address':Y,'object_type':Z,'time':typeof X?.['time']==='number'?X['time']:null});}R['count']=R['items']['length'];}catch{g['push']('related:\x20ObjectLinkerTx(arb)\x20lookup\x20failed');}return{'action':'object_panorama','object':f,'object_type':'Arb','network':d,'head':h,'fields':{'arbitration':str(e['arbitration']),'order':str(e['order']),'service':Q,'fee':str(e['fee']),'feedback':str(e['feedback']),'indemnity':N?{'amount':str(N['amount']),'time':num(N['time'])}:null,'voting_deadline':num(e['voting_deadline']),'objection':str(e['objection']),'status':ARB_STATUS_NAMES[num(e['status'])??-0x1]??str(e['status']),'compensation_time':num(e['compensation_time']),'time':num(e['time']),'type_raw':str(e['type_raw'])},'voted':arr(e['voted'])['map'](a0=>{const a1=a0;return{'voter':str(a1['voter'])??'','agrees':arr(a1['agrees'])['map'](a2=>Number(a2)),'weight':num(a1['weight'])??0x0,'time':num(a1['time'])??0x0};}),'proposition':arr(e['proposition'])['map'](a0=>{const a1=a0;return{'name':str(a1['name'])??'','votes':num(a1['votes'])??0x0};}),'related':R,'updated_ms':O,'data_gaps':g};}if(j==='Repository')return{'action':'object_panorama','object':f,'object_type':'Repository','network':d,'head':h,'fields':{'um':str(e['um']),'permission':str(e['permission']),'data_count':num(e['data_count'])},'policies':arr(e['policies'])['map'](a0=>{const a1=a0;return{'name':str(a1['name'])??'','description':str(a1['description']),'id_from':str(a1['id_from']),'value_type':str(a1['value_type']),'write_guards':arr(a1['write_guard'])['length'],'quote_guard':str(a1['quote_guard'])};}),'rewards':arr(e['rewards'])['map'](a0=>String(a0)),'data_entries':await buildRepositoryData(f,d,g),'data_gaps':g};throw new Error('object_panorama:\x20unsupported\x20object\x20type\x20\x27'+(j||'unknown')+'\x27\x20for\x20'+f+'.\x20'+'Supported:\x20Progress\x20/\x20Demand\x20/\x20Order\x20/\x20Arb\x20/\x20Repository.');}
|