@wowok/agent-mcp 3.2.3 → 3.2.6
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/chain-semantics/field-capability.js +1 -1
- package/dist/chain-semantics/freeze-map.js +1 -1
- package/dist/chain-semantics/fund-flow.js +1 -1
- package/dist/chain-semantics/guard-verbs.js +1 -1
- package/dist/communication/proof-reuse.d.ts +9 -0
- package/dist/communication/proof-reuse.js +1 -0
- package/dist/composition/blueprint-view.d.ts +64 -0
- package/dist/composition/blueprint-view.js +1 -0
- package/dist/evaluation/builtins/graph-service.spec.js +1 -1
- package/dist/evaluation/engine.js +1 -1
- package/dist/experience/realtime-feedback.js +1 -1
- package/dist/extensions/industry-pack.d.ts +1 -0
- package/dist/extensions/industry-pack.js +1 -1
- package/dist/extensions/modes.js +1 -1
- package/dist/extensions/registry.d.ts +1 -2
- package/dist/extensions/registry.js +1 -1
- package/dist/graph/onchain/expand.js +1 -1
- package/dist/graph/onchain/exposure.js +1 -1
- package/dist/graph/onchain/facts.js +1 -1
- package/dist/harness/recover.js +1 -1
- package/dist/knowledge/allocation-ledger.js +1 -1
- package/dist/knowledge/audit-rules.d.ts +2 -0
- package/dist/knowledge/audit-rules.js +1 -1
- package/dist/knowledge/baselines/rules/allocation.json +5 -5
- package/dist/knowledge/baselines/rules/arb.json +1 -1
- package/dist/knowledge/baselines/rules/guard.json +9 -9
- package/dist/knowledge/baselines/rules/machine.json +5 -5
- package/dist/knowledge/baselines/rules/order.json +1 -1
- package/dist/knowledge/builtin-templates.d.ts +2 -1
- package/dist/knowledge/builtin-templates.js +1 -1
- package/dist/knowledge/entity-recipient-guard.js +1 -1
- package/dist/knowledge/getting-started.js +1 -1
- package/dist/knowledge/guard-bindings.js +1 -1
- package/dist/knowledge/guard-design-patterns.d.ts +1 -1
- package/dist/knowledge/guard-design-patterns.js +1 -1
- package/dist/knowledge/guard-ledger.js +1 -1
- package/dist/knowledge/guard-risk.js +1 -1
- package/dist/knowledge/guard-templates.d.ts +1 -1
- package/dist/knowledge/guard-templates.js +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/knowledge/industry-generalizer.js +1 -1
- package/dist/knowledge/industry-registry.js +1 -1
- package/dist/knowledge/jsonrpc-enum.js +1 -1
- package/dist/knowledge/machine-ledger.js +1 -1
- package/dist/knowledge/machine-templates.js +1 -1
- package/dist/knowledge/order-ledger.js +1 -1
- package/dist/knowledge/progress-ledger.js +1 -1
- package/dist/knowledge/scenario-modes.d.ts +3 -4
- package/dist/knowledge/scenario-modes.js +1 -1
- package/dist/knowledge/service-ledger.js +1 -1
- package/dist/knowledge/service-templates.js +1 -1
- package/dist/knowledge/template-loader.d.ts +8 -2
- package/dist/knowledge/template-loader.js +1 -1
- package/dist/knowledge/template-registry.js +1 -1
- package/dist/knowledge/template-scanner.js +1 -1
- package/dist/knowledge/template-validation.d.ts +2 -0
- package/dist/knowledge/template-validation.js +1 -0
- package/dist/monitor/MonitorLoop.js +1 -1
- package/dist/participation/radar-core.js +1 -1
- package/dist/playbooks/service-build/business-puzzle.js +1 -1
- package/dist/playbooks/service-build/game-theory.d.ts +2 -2
- package/dist/playbooks/service-build/game-theory.js +1 -1
- package/dist/playbooks/service-build/machine-panorama.js +1 -1
- package/dist/playbooks/service-build/merchant-guide.d.ts +54 -11
- package/dist/playbooks/service-build/merchant-guide.js +1 -1
- 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.js +1 -1
- package/dist/playbooks/service-build/reverse-mapping-nk4.spec.d.ts +1 -0
- package/dist/playbooks/service-build/reverse-mapping-nk4.spec.js +1 -0
- package/dist/playbooks/service-build/reverse-mapping.d.ts +24 -0
- package/dist/playbooks/service-build/reverse-mapping.js +1 -1
- package/dist/playbooks/service-build/service-panorama.js +1 -1
- package/dist/playbooks/service-build/service-quote.js +1 -1
- package/dist/playbooks/service-build/service-quote.spec.d.ts +1 -0
- package/dist/playbooks/service-build/service-quote.spec.js +1 -0
- package/dist/playbooks/service-build/workflow-design-assessment.d.ts +2 -2
- package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
- package/dist/review/index.js +1 -1
- package/dist/safety/confirm-gate.js +1 -1
- package/dist/schema/call/arbitration.js +1 -1
- package/dist/schema/call/base.d.ts +4 -0
- package/dist/schema/call/base.js +1 -1
- package/dist/schema/call/bridge.d.ts +1 -0
- package/dist/schema/call/error-codes.d.ts +1 -1
- package/dist/schema/call/error-codes.js +1 -1
- package/dist/schema/call/handler.js +1 -1
- package/dist/schema/call/machine.js +1 -1
- package/dist/schema/call/semantic.js +1 -1
- package/dist/schema/call/service.d.ts +14 -0
- package/dist/schema/call/service.js +1 -1
- package/dist/schema/common/index.js +1 -1
- package/dist/schema/goal/planning.js +1 -1
- package/dist/schema/interaction/index.d.ts +1 -1
- package/dist/schema/local/index.d.ts +10 -0
- package/dist/schema/local/index.js +1 -1
- package/dist/schema/operations.d.ts +7 -0
- package/dist/schema/query/bi.d.ts +26 -0
- package/dist/schema/query/bi.js +1 -1
- package/dist/schema/schema-version.js +1 -1
- package/dist/schema-query-impl/index.js +1 -1
- package/dist/schemas/account_operation.output.json +1 -0
- package/dist/schemas/bridge_operation.output.json +1 -0
- package/dist/schemas/goal_operation.schema.json +1 -1
- package/dist/schemas/index.json +1 -1
- package/dist/schemas/local_cache_operation.output.json +1 -0
- package/dist/schemas/local_history_operation.output.json +1 -0
- package/dist/schemas/local_info_operation.output.json +1 -0
- package/dist/schemas/local_mark_operation.output.json +1 -0
- package/dist/schemas/onchain_operations.output.json +1 -0
- package/dist/schemas/onchain_operations.schema.json +40 -5
- package/dist/schemas/onchain_operations_arbitration.schema.json +1 -1
- package/dist/schemas/onchain_operations_machine.schema.json +1 -1
- package/dist/schemas/onchain_operations_service.schema.json +38 -3
- package/dist/schemas/query_toolkit.output.json +91 -7
- package/dist/tools/handlers/benchmark-migration.d.ts +2 -13
- package/dist/tools/handlers/benchmark-migration.js +1 -1
- package/dist/tools/handlers/config.js +1 -1
- package/dist/tools/handlers/industry-pack.js +1 -1
- package/dist/tools/handlers/messenger.js +1 -1
- package/dist/tools/handlers/onchain.js +1 -1
- package/dist/tools/handlers/query.js +1 -1
- package/dist/tools/move-fn-index.gen.js +1 -1
- package/dist/tools/registry/agent.js +1 -1
- package/dist/tools/wip-deploy-assist.js +1 -1
- package/dist/tools/wrap.js +1 -1
- package/package.json +2 -2
- package/dist/playbooks/service-build/semantic-graph.d.ts +0 -99
- package/dist/playbooks/service-build/semantic-graph.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SERVICE_TEMPLATES=[{'id':'T-S-01','name':'Retail\x20e-commerce\x20Service','description':'Standard\x20retail\x20shop\x20with\x20multiple\x20SKUs,\x20WIP-verified\x20products,\x20owner-only\x20allocation','applicable_scenes':['service_retail','service_buy_guard'],'industry_tags':['retail','ecommerce','digital_goods'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20address\x20(receives\x20payments)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address\x20(must\x20be\x20owned\x20by\x20owner)','required':!![]},{'name':'description','type':'string','description':'Shop\x20description','required':!![]},{'name':'location','type':'string','description':'Service\x20geographic\x20location\x20(city/region)','required':![],'default':''},{'name':'sales_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'buy_guard_address','type':'address','description':'Buyer\x20eligibility\x20Guard\x20(null\x20for\x20public\x20sale)','required':![],'default':''}],'body':a=>{const b={'object':null,'description':a['description'],'permission':a['permission_address'],'location':a['location']||undefined,'sales':{'op':'add','sales':a['sales_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]};if(a['buy_guard_address'])b['buy_guard']=a['buy_guard_address'];return b;},'notes':['WIP\x20hash\x20is\x20MANDATORY\x20for\x20tamper\x20protection\x20—\x20never\x20leave\x20empty\x20if\x20wip\x20URL\x20is\x20set','Use\x20buy_guard\x20for\x20pre-sale\x20whitelist\x20phase,\x20then\x20clear\x20for\x20public\x20sale','Single-recipient\x20allocation\x20(owner\x20100%)\x20—\x20use\x20T-S-08\x20for\x20multi-party\x20split'],'post_publish_considerations':['machine/arbitrations/order_allocators\x20become\x20immutable\x20—\x20verify\x20before\x20publish','Sales\x20can\x20still\x20be\x20added/removed/updated\x20post-publish','buy_guard\x20can\x20be\x20changed\x20post-publish\x20(unusual\x20exception)']},{'id':'T-S-02','name':'Rental\x20Service\x20(deposit\x20+\x20use\x20+\x20return)','description':'Equipment/asset\x20rental\x20with\x20deposit\x20guarantee,\x20Machine\x20workflow,\x20and\x20arbitration','applicable_scenes':['service_rental'],'industry_tags':['rental','equipment','real_estate'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(rental\x20company)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Rental\x20service\x20description','required':!![]},{'name':'machine_address','type':'address','description':'Published\x20Machine\x20with\x20Reserve→Pay→Pickup→Return→Refund\x20nodes','required':!![]},{'name':'arbitration_object','type':'address','description':'Arbitration\x20for\x20deposit\x20disputes','required':!![]},{'name':'rental_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock=1,\x20wip,\x20wip_hash}','required':!![]},{'name':'compensation_fund_balance','type':'string','description':'Initial\x20deposit\x20to\x20compensation_fund\x20(in\x20base\x20units)','required':![],'default':'0'}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'machine':a['machine_address'],'arbitrations':{'op':'add','objects':[a['arbitration_object']]},'sales':{'op':'add','sales':a['rental_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}],'compensation_fund_add':a['compensation_fund_balance']&&a['compensation_fund_balance']!=='0'?{'balance':a['compensation_fund_balance']}:undefined}),'notes':['stock=1\x20per\x20rental\x20item\x20(unique\x20items)\x20—\x20once\x20rented,\x20stock\x20becomes\x200','Machine\x20must\x20define\x20deposit/return/refund\x20nodes\x20for\x20proper\x20rental\x20flow','compensation_fund\x20holds\x20deposit\x20guarantees\x20—\x20separate\x20from\x20rental\x20fee','Arbitration\x20required\x20if\x20compensation_fund\x20>\x200\x20(F-S-19)'],'post_publish_considerations':['Machine\x20binding\x20is\x20permanent\x20—\x20verify\x20workflow\x20before\x20publish','Arbitration\x20binding\x20is\x20permanent\x20—\x20choose\x20reputable\x20arbiters','Sales\x20can\x20be\x20updated\x20(add\x20new\x20rental\x20items,\x20remove\x20deprecated\x20ones)']},{'id':'T-S-03','name':'Subscription\x20Service\x20(tiered\x20plans)','description':'Recurring-access\x20service\x20with\x20tiered\x20plans\x20(Free/Pro/Enterprise),\x20discount\x20coupons,\x20loyalty\x20rewards','applicable_scenes':['service_subscription'],'industry_tags':['subscription','saas','membership'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Subscription\x20service\x20description','required':!![]},{'name':'tier_plans','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock=999999,\x20wip,\x20wip_hash}\x20for\x20each\x20tier','required':!![]},{'name':'trial_discount_count','type':'number','description':'Number\x20of\x20trial\x20discount\x20coupons\x20to\x20issue','required':![],'default':0x0},{'name':'reward_address','type':'address','description':'Loyalty\x20Reward\x20object\x20address\x20(optional)','required':![],'default':''}],'body':a=>{const b={'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['tier_plans']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]};return a['reward_address']&&(b['rewards']={'op':'add','objects':[a['reward_address']]}),b;},'notes':['Subscription\x20renewals\x20are\x20handled\x20by\x20repeat\x20orders\x20(no\x20native\x20recurring\x20billing)','Use\x20large\x20stock\x20values\x20(e.g.\x20999999)\x20since\x20subscriptions\x20are\x20not\x20inventory-limited','Trial\x20discounts:\x20issue\x20via\x20discount\x20(312)\x20post-publish','Loyalty\x20rewards:\x20bind\x20via\x20the\x20add-reward\x20operation\x20(318)\x20—\x20locked\x20by\x20setting_lock_duration'],'post_publish_considerations':['Tier\x20prices\x20can\x20be\x20updated\x20via\x20the\x20sales\x20update\x20operation\x20(existing\x20subscribers\x20unaffected)','Discount\x20coupons\x20can\x20be\x20issued/destroyed\x20post-publish','Rewards\x20can\x20be\x20added\x20but\x20removal\x20locked\x20by\x20duration']},{'id':'T-S-04','name':'Workflow-bound\x20Service\x20(machine-driven\x20delivery)','description':'Service\x20with\x20multi-step\x20delivery\x20workflow\x20(e.g.\x20freelance,\x20custom\x20manufacturing,\x20course)','applicable_scenes':['service_workflow','service_rental'],'industry_tags':['workflow','freelance','manufacturing','education'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(provider)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'machine_address','type':'address','description':'Published\x20Machine\x20with\x20Pay→Confirm→Deliver→Sign-off\x20nodes','required':!![]},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'customer_required','type':'string[]','description':'Required\x20info\x20fields\x20(e.g.\x20[\x27name\x27,\x27project_brief\x27])','required':![],'default':[]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'machine':a['machine_address'],'sales':{'op':'add','sales':a['service_items']},'customer_required':a['customer_required'],'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Machine\x20MUST\x20be\x20published\x20before\x20binding\x20(via\x20the\x20Machine\x20publish\x20operation)','Each\x20order\x20creates\x20a\x20Progress\x20object\x20tracking\x20the\x20workflow','Named\x20operators\x20can\x20be\x20assigned\x20per\x20Forward\x20in\x20the\x20Machine','Service.bPaused\x20does\x20NOT\x20affect\x20already-created\x20Progress\x20(existing\x20orders\x20continue)'],'post_publish_considerations':['Machine\x20binding\x20is\x20PERMANENT\x20—\x20cannot\x20upgrade\x20workflow\x20post-publish','To\x20change\x20workflow:\x20clone\x20Service\x20with\x20new\x20Machine,\x20migrate\x20customers\x20via\x20discounts','customer_required\x20fields\x20can\x20be\x20updated\x20post-publish']},{'id':'T-S-05','name':'Arbitration-bound\x20Service\x20(dispute-ready)','description':'Service\x20with\x20multiple\x20Arbitration\x20objects\x20for\x20different\x20dispute\x20scopes\x20+\x20compensation_fund','applicable_scenes':['service_arbitration','service_arbitration_binding'],'industry_tags':['arbitration','dispute_resolution','high_value'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'arbitration_addresses','type':'string[]','description':'1-3\x20Arbitration\x20object\x20addresses\x20(different\x20scopes)','required':!![]},{'name':'compensation_fund_balance','type':'string','description':'Initial\x20compensation_fund\x20deposit\x20(base\x20units)','required':!![]},{'name':'setting_lock_duration_ms','type':'number','description':'Initial\x20setting_lock_duration\x20in\x20ms\x20(default\x2030\x20days)','required':![],'default':0x9a7ec800},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'arbitrations':{'op':'add','objects':a['arbitration_addresses']},'compensation_fund_add':{'balance':a['compensation_fund_balance']},'setting_lock_duration_add':a['setting_lock_duration_ms'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Use\x202-3\x20Arbitration\x20objects:\x20e.g.\x20one\x20for\x20quality\x20disputes,\x20one\x20for\x20delivery\x20disputes','compensation_fund\x20>\x200\x20REQUIRES\x20arbitrations\x20non-empty\x20(F-S-19,\x20E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)','compensation_fund\x20coin\x20type\x20MUST\x20match\x20Service<T>\x20type\x20parameter','setting_lock_duration\x20protects\x20customers\x20—\x20only-increase\x20mechanism'],'post_publish_considerations':['Arbitration\x20bindings\x20are\x20PERMANENT\x20—\x20verify\x20arb\x20reputation\x20before\x20publish','compensation_fund_add\x20(deposit)\x20is\x20always\x20mutable\x20post-publish','compensation_fund_withdraw\x20requires\x20bPaused=true\x20+\x20lock_duration\x20expired','Cannot\x20add\x20new\x20Arbitration\x20post-publish\x20—\x20only\x20pre-publish']},{'id':'T-S-06','name':'Compensation\x20fund\x20Service\x20(embedded\x20Balance<T>)','description':'Service\x20focused\x20on\x20compensation_fund\x20management\x20—\x20emphasizes\x20distinction\x20from\x20Treasury','applicable_scenes':['service_compensation_fund','service_arbitration'],'industry_tags':['finance','escrow','guarantee'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'arbitration_addresses','type':'string[]','description':'Arbitration\x20objects\x20(required\x20when\x20fund\x20>\x200)','required':!![]},{'name':'initial_deposit','type':'string','description':'Initial\x20compensation_fund\x20deposit\x20(base\x20units)','required':!![]},{'name':'lock_duration_ms','type':'number','description':'setting_lock_duration\x20(ms)','required':![],'default':0x9a7ec800},{'name':'service_items','type':'object','description':'Sales\x20items','required':!![]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'arbitrations':{'op':'add','objects':a['arbitration_addresses']},'compensation_fund_add':{'balance':a['initial_deposit']},'setting_lock_duration_add':a['lock_duration_ms'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['⚠️\x20compensation_fund\x20is\x20INTERNAL\x20Balance<T>\x20—\x20distinct\x20from\x20Treasury\x20(external)','Treasury\x20is\x20referenced\x20via\x20order_allocators.sharing.who=Entity\x20(Treasury\x20address)','compensation_fund\x20is\x20consumed\x20by\x20the\x20arbitration\x20compensation\x20claim\x20(driven\x20by\x20arb\x20result)','Owner\x20can\x20only\x20withdraw\x20via\x20compensation_fund_withdraw\x20(requires\x20paused\x20+\x20lock\x20expired)'],'post_publish_considerations':['Deposits\x20(compensation_fund_add)\x20always\x20allowed','Withdrawals\x20(compensation_fund_withdraw)\x20require\x20bPaused=true\x20+\x20lock_duration\x20expired','Receive\x20(compensation_fund_receive)\x20locked\x20by\x20duration','setting_lock_duration\x20only-increase\x20—\x20plan\x20withdrawal\x20timeline\x20carefully']},{'id':'T-S-07','name':'Dynamic\x20pricing\x20Service\x20(discount-driven)','description':'Service\x20with\x20promotional\x20discount\x20coupons\x20—\x20supports\x20rates\x20(basis\x20points,\x20per\x2010000)\x20and\x20minus\x20(direct\x20deduction)\x20types','applicable_scenes':['service_dynamic_pricing'],'industry_tags':['retail','marketing','promotion'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'discount_specs','type':'object','description':'Array\x20of\x20{name,\x20type,\x20data,\x20count,\x20expire_at}\x20for\x20initial\x20discounts','required':![],'default':[]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Discounts\x20are\x20issued\x20POST-PUBLISH\x20via\x20discount\x20(312)\x20—\x20not\x20in\x20create\x20body','discount_type=0\x20rates\x20(basis\x20points,\x20e.g.\x201000=10%);\x201=minus\x20(direct\x20deduction,\x20base\x20units)','MAX_DISCOUNT_COUNT_ONCE\x20=\x201000\x20per\x20issue\x20call','MAX_DISCOUNT_RECEIVER_ONCE\x20=\x201000\x20receivers\x20per\x20call','MAX_DISCOUNT_TOTAL_COUNT\x20=\x2020000\x20total\x20coupons\x20per\x20Service','discount_destroy\x20is\x20holder-only\x20(no\x20SERVICE_DISCOUNT\x20permission\x20needed)'],'post_publish_considerations':['Discount\x20coupons\x20can\x20be\x20issued/destroyed\x20freely','Sales\x20prices\x20can\x20be\x20updated\x20via\x20the\x20sales\x20update\x20operation\x20(existing\x20orders\x20unaffected)','Track\x20discount\x20usage\x20to\x20avoid\x20stockout\x20of\x20promotional\x20items']},{'id':'T-S-08','name':'Multi-allocator\x20Service\x20(tiered\x20fund\x20distribution)','description':'Service\x20with\x20multiple\x20allocator\x20tiers\x20—\x20guard-selected\x20distribution\x20based\x20on\x20order\x20value','applicable_scenes':['service_multi_allocator','service_order_allocator','service_reward'],'industry_tags':['marketplace','platform','logistics'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(merchant)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'platform_address','type':'address','description':'Platform\x20fee\x20recipient','required':!![]},{'name':'logistics_address','type':'address','description':'Logistics\x20fee\x20recipient\x20(optional)','required':![],'default':''},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'tier1_threshold','type':'string','description':'Small\x20order\x20threshold\x20(base\x20units,\x20e.g.\x20\x270\x27)','required':![],'default':'0'},{'name':'tier2_threshold','type':'string','description':'Medium\x20order\x20threshold\x20(base\x20units)','required':![],'default':'10000000000'},{'name':'tier3_threshold','type':'string','description':'Large\x20order\x20threshold\x20(base\x20units)','required':![],'default':'100000000000'}],'body':a=>{const b=[{'threshold':a['tier1_threshold'],'sharing':[{'who':{'Object':a['owner_address']},'weight':0x5a},{'who':{'Object':a['platform_address']},'weight':0xa}]},{'threshold':a['tier2_threshold'],'sharing':a['logistics_address']?[{'who':{'Object':a['owner_address']},'weight':0x50},{'who':{'Object':a['platform_address']},'weight':0xa},{'who':{'Object':a['logistics_address']},'weight':0xa}]:[{'who':{'Object':a['owner_address']},'weight':0x55},{'who':{'Object':a['platform_address']},'weight':0xf}]},{'threshold':a['tier3_threshold'],'sharing':a['logistics_address']?[{'who':{'Object':a['owner_address']},'weight':0x46},{'who':{'Object':a['platform_address']},'weight':0xa},{'who':{'Object':a['logistics_address']},'weight':0x14}]:[{'who':{'Object':a['owner_address']},'weight':0x50},{'who':{'Object':a['platform_address']},'weight':0x14}]}];return{'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':b};},'notes':['Each\x20allocator\x20tier\x20is\x20bound\x20to\x20a\x20DIFFERENT\x20guard\x20—\x20the\x20caller\x27s\x20submitted\x20guard\x20selects\x20which\x20tier\x20fires','Each\x20tier\x20can\x20have\x20its\x20own\x20Guard\x20for\x20execution\x20authorization\x20(optional)','Thresholds\x20must\x20be\x20ascending\x20(tier1\x20<\x20tier2\x20<\x20tier3)','MAX_SHARING_COUNT\x20=\x20100\x20per\x20allocator\x20(sum\x20of\x20sharing\x20entries)','Treasury\x20addresses\x20can\x20be\x20referenced\x20via\x20sharing.who=Entity\x20(Treasury\x20object)'],'post_publish_considerations':['⚠️\x20order_allocators\x20is\x20IMMUTABLE\x20post-publish\x20(F-S-22)\x20—\x20verify\x20tiers\x20before\x20publish','To\x20change\x20fee\x20split:\x20clone\x20Service\x20with\x20new\x20allocators\x20(cannot\x20migrate\x20existing\x20Orders)','Sales\x20can\x20still\x20be\x20updated\x20post-publish\x20(only\x20allocator\x20is\x20locked)']},{'id':'T-S-09','name':'Supply\x20Chain\x20Sub-order\x20Service\x20(milestone\x20unlock\x20via\x20buy_guard)','description':'Sub-service\x20whose\x20buy_guard\x20verifies\x20the\x20user\x20purchased\x20the\x20main\x20service\x20order.\x20Each\x20milestone\x20=\x20one\x20sub-order.\x20Enables\x20supply\x20chain\x20composition:\x20main\x20service\x20→\x20multiple\x20sub-services\x20with\x20conditional\x20access.','applicable_scenes':['service_buy_guard'],'industry_tags':['travel','rental','education','freelance','ecommerce','supply_chain'],'params':[{'name':'owner_address','type':'address','description':'Sub-service\x20owner\x20address','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Sub-service\x20description\x20(e.g.,\x20\x27Hotel\x20booking\x20for\x20tour\x20package\x20X\x27)','required':!![]},{'name':'main_service_address','type':'address','description':'Main\x20Service\x20object\x20address\x20(the\x20parent\x20service)','required':!![]},{'name':'buy_guard_address','type':'address','description':'Guard\x20address\x20verifying\x20main\x20order\x20ownership\x20(order.owner==Signer\x20AND\x20order.service==main_service)','required':!![]},{'name':'price','type':'number','description':'Sub-service\x20price','required':!![]},{'name':'machine_address','type':'address','description':'Machine\x20object\x20for\x20sub-order\x20workflow','required':!![]}],'body':a=>({'object':null,'description':a['description'],'service_type':'supply_chain_sub','buy_guard':a['buy_guard_address'],'price':a['price'],'machine':a['machine_address'],'permission':a['permission_address']}),'notes':['VERIFIED:\x20buy_guard:\x20Option<address>;\x20the\x20Passport-verified\x20purchase\x20evaluates\x20buy_guard','VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20main\x20Order\x20as\x20evidence\x20(b_submission=true),\x20buy_guard\x20verifies\x20order.owner==Signer\x20AND\x20order.service==main_service_address','No\x20parent_order\x20field\x20needed\x20—\x20relationship\x20verified\x20via\x20buy_guard\x20querying\x20submitted\x20Order\x20fields','Each\x20milestone\x20=\x20one\x20sub-order\x20with\x20its\x20own\x20Service\x20+\x20buy_guard\x20+\x20Machine','Main\x20flow\x20Machine\x20can\x20branch\x20to\x20different\x20sub-services\x20based\x20on\x20node\x20progression','Use\x20tpl_buy_guard_order_holder\x20(guard-templates.ts)\x20for\x20the\x20buy_guard\x20design'],'post_publish_considerations':['buy_guard\x20is\x20mutable\x20post-publish\x20(can\x20update\x20the\x20guard\x20address)','If\x20main\x20service\x20is\x20unpublished,\x20sub-service\x20buy_guard\x20will\x20fail\x20(order.service\x20won\x27t\x20match)','Consider\x20publishing\x20main\x20service\x20before\x20sub-services']}];export const SERVICE_TEMPLATES_VERSION='1.0.0';export function getAllServiceTemplates(){return[...SERVICE_TEMPLATES];}export function getServiceTemplateById(a){return SERVICE_TEMPLATES['find'](b=>b['id']===a);}export function getServiceTemplatesByScene(a){return SERVICE_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getServiceTemplatesByIndustry(a){return SERVICE_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestServiceTemplateForScene(a){const b=getServiceTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listServiceTemplates(){return SERVICE_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export const SERVICE_PRICING_NOTE='Pricing\x20coin:\x20prices\x20in\x20the\x20generated\x20body\x20are\x20denominated\x20in\x20the\x20object\x27s\x20type_parameter\x20token\x20(default\x200x2::wow::WOW),\x20which\x20is\x20FIXED\x20at\x20creation\x20—\x20buyers\x20must\x20hold\x20that\x20exact\x20token\x20to\x20order.\x20To\x20price\x20in\x20a\x20different\x20token,\x20pass\x20its\x20full\x20type\x20(from\x20wowok_buildin_info\x20\x27mainnet\x20bridge\x20tokens\x27\x20wowTypeTag)\x20as\x20type_parameter\x20BEFORE\x20creating.\x20Testnet\x20has\x20ONLY\x20WOW\x20(no\x20stablecoins\x20are\x20bridged);\x20multi-token\x20pricing\x20is\x20a\x20mainnet\x20capability.';export function fillServiceTemplate(a,b){const c=getServiceTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};const d=[];for(const f of c['params']){f['required']&&!(f['name']in b)&&d['push'](f['name']);}if(d['length']>0x0)return{'ok':![],'error':'Missing\x20required\x20params:\x20'+d['join'](',\x20'),'missing_required':d};const e={...b};for(const g of c['params']){!(g['name']in e)&&g['default']!==undefined&&(e[g['name']]=g['default']);}return{'ok':!![],'body':c['body'](e),'pricing_note':SERVICE_PRICING_NOTE};}
|
|
1
|
+
export const SERVICE_TEMPLATES=[{'id':'T-S-01','name':'Retail\x20e-commerce\x20Service','description':'Standard\x20retail\x20shop\x20with\x20multiple\x20SKUs,\x20WIP-verified\x20products,\x20owner-only\x20allocation','applicable_scenes':['service_retail','service_buy_guard'],'industry_tags':['retail','ecommerce','digital_goods'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20address\x20(receives\x20payments)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address\x20(must\x20be\x20owned\x20by\x20owner)','required':!![]},{'name':'description','type':'string','description':'Shop\x20description','required':!![]},{'name':'location','type':'string','description':'Service\x20geographic\x20location\x20(city/region)','required':![],'default':''},{'name':'sales_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'buy_guard_address','type':'address','description':'Buyer\x20eligibility\x20Guard\x20(null\x20for\x20public\x20sale)','required':![],'default':''}],'body':a=>{const b={'object':null,'description':a['description'],'permission':a['permission_address'],'location':a['location']||undefined,'sales':{'op':'add','sales':a['sales_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]};if(a['buy_guard_address'])b['buy_guard']=a['buy_guard_address'];return b;},'notes':['WIP\x20hash\x20is\x20MANDATORY\x20for\x20tamper\x20protection\x20—\x20never\x20leave\x20empty\x20if\x20wip\x20URL\x20is\x20set','Use\x20buy_guard\x20for\x20pre-sale\x20whitelist\x20phase,\x20then\x20clear\x20for\x20public\x20sale','Single-recipient\x20allocation\x20(owner\x20100%)\x20—\x20use\x20T-S-08\x20for\x20multi-party\x20split'],'post_publish_considerations':['machine/arbitrations/order_allocators\x20become\x20immutable\x20—\x20verify\x20before\x20publish','Sales\x20can\x20still\x20be\x20added/removed/updated\x20post-publish','buy_guard\x20can\x20be\x20changed\x20post-publish\x20(unusual\x20exception)']},{'id':'T-S-02','name':'Rental\x20Service\x20(deposit\x20+\x20use\x20+\x20return)','description':'Equipment/asset\x20rental\x20with\x20deposit\x20guarantee,\x20Machine\x20workflow,\x20and\x20arbitration','applicable_scenes':['service_rental'],'industry_tags':['rental','equipment','real_estate'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(rental\x20company)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Rental\x20service\x20description','required':!![]},{'name':'machine_address','type':'address','description':'Published\x20Machine\x20with\x20Reserve→Pay→Pickup→Return→Refund\x20nodes','required':!![]},{'name':'arbitration_object','type':'address','description':'Arbitration\x20for\x20deposit\x20disputes','required':!![]},{'name':'rental_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock=1,\x20wip,\x20wip_hash}','required':!![]},{'name':'compensation_fund_balance','type':'string','description':'Initial\x20deposit\x20to\x20compensation_fund\x20(in\x20base\x20units)','required':![],'default':'0'}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'machine':a['machine_address'],'arbitrations':{'op':'add','objects':[a['arbitration_object']]},'sales':{'op':'add','sales':a['rental_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}],'compensation_fund_add':a['compensation_fund_balance']&&a['compensation_fund_balance']!=='0'?{'balance':a['compensation_fund_balance']}:undefined}),'notes':['stock=1\x20per\x20rental\x20item\x20(unique\x20items)\x20—\x20once\x20rented,\x20stock\x20becomes\x200','Machine\x20must\x20define\x20deposit/return/refund\x20nodes\x20for\x20proper\x20rental\x20flow','compensation_fund\x20holds\x20deposit\x20guarantees\x20—\x20separate\x20from\x20rental\x20fee','Arbitration\x20required\x20if\x20compensation_fund\x20>\x200\x20(F-S-19)'],'post_publish_considerations':['Machine\x20binding\x20is\x20permanent\x20—\x20verify\x20workflow\x20before\x20publish','Arbitration\x20binding\x20is\x20permanent\x20—\x20choose\x20reputable\x20arbiters','Sales\x20can\x20be\x20updated\x20(add\x20new\x20rental\x20items,\x20remove\x20deprecated\x20ones)']},{'id':'T-S-03','name':'Subscription\x20Service\x20(tiered\x20plans)','description':'Recurring-access\x20service\x20with\x20tiered\x20plans\x20(Free/Pro/Enterprise),\x20discount\x20coupons,\x20loyalty\x20rewards','applicable_scenes':['service_subscription'],'industry_tags':['subscription','saas','membership'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Subscription\x20service\x20description','required':!![]},{'name':'tier_plans','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock=999999,\x20wip,\x20wip_hash}\x20for\x20each\x20tier','required':!![]},{'name':'trial_discount_count','type':'number','description':'Number\x20of\x20trial\x20discount\x20coupons\x20to\x20issue','required':![],'default':0x0},{'name':'reward_address','type':'address','description':'Loyalty\x20Reward\x20object\x20address\x20(optional)','required':![],'default':''}],'body':a=>{const b={'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['tier_plans']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]};return a['reward_address']&&(b['rewards']={'op':'add','objects':[a['reward_address']]}),b;},'notes':['Subscription\x20renewals\x20are\x20handled\x20by\x20repeat\x20orders\x20(no\x20native\x20recurring\x20billing)','Use\x20large\x20stock\x20values\x20(e.g.\x20999999)\x20since\x20subscriptions\x20are\x20not\x20inventory-limited','Trial\x20discounts:\x20issue\x20via\x20discount\x20(312)\x20post-publish','Loyalty\x20rewards:\x20bind\x20via\x20the\x20add-reward\x20operation\x20(318)\x20—\x20locked\x20by\x20setting_lock_duration'],'post_publish_considerations':['Tier\x20prices\x20can\x20be\x20updated\x20via\x20the\x20sales\x20update\x20operation\x20(existing\x20subscribers\x20unaffected)','Discount\x20coupons\x20can\x20be\x20issued/destroyed\x20post-publish','Rewards\x20can\x20be\x20added\x20but\x20removal\x20locked\x20by\x20duration']},{'id':'T-S-04','name':'Workflow-bound\x20Service\x20(machine-driven\x20delivery)','description':'Service\x20with\x20multi-step\x20delivery\x20workflow\x20(e.g.\x20freelance,\x20custom\x20manufacturing,\x20course)','applicable_scenes':['service_workflow','service_rental'],'industry_tags':['workflow','freelance','manufacturing','education'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(provider)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'machine_address','type':'address','description':'Published\x20Machine\x20with\x20Pay→Confirm→Deliver→Sign-off\x20nodes','required':!![]},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'customer_required','type':'string[]','description':'Required\x20info\x20fields\x20(e.g.\x20[\x27name\x27,\x27project_brief\x27])','required':![],'default':[]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'machine':a['machine_address'],'sales':{'op':'add','sales':a['service_items']},'customer_required':a['customer_required'],'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Machine\x20MUST\x20be\x20published\x20before\x20binding\x20(via\x20the\x20Machine\x20publish\x20operation)','Each\x20order\x20creates\x20a\x20Progress\x20object\x20tracking\x20the\x20workflow','Named\x20operators\x20can\x20be\x20assigned\x20per\x20Forward\x20in\x20the\x20Machine','Service.bPaused\x20does\x20NOT\x20affect\x20already-created\x20Progress\x20(existing\x20orders\x20continue)'],'post_publish_considerations':['Machine\x20binding\x20is\x20PERMANENT\x20—\x20cannot\x20upgrade\x20workflow\x20post-publish','To\x20change\x20workflow:\x20clone\x20Service\x20with\x20new\x20Machine,\x20migrate\x20customers\x20via\x20discounts','customer_required\x20fields\x20can\x20be\x20updated\x20post-publish']},{'id':'T-S-05','name':'Arbitration-bound\x20Service\x20(dispute-ready)','description':'Service\x20with\x20multiple\x20Arbitration\x20objects\x20for\x20different\x20dispute\x20scopes\x20+\x20compensation_fund','applicable_scenes':['service_arbitration','service_arbitration_binding'],'industry_tags':['arbitration','dispute_resolution','high_value'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'arbitration_addresses','type':'string[]','description':'1-3\x20Arbitration\x20object\x20addresses\x20(different\x20scopes)','required':!![]},{'name':'compensation_fund_balance','type':'string','description':'Initial\x20compensation_fund\x20deposit\x20(base\x20units)','required':!![]},{'name':'setting_lock_duration_ms','type':'number','description':'Initial\x20setting_lock_duration\x20in\x20ms\x20(default\x2030\x20days)','required':![],'default':0x9a7ec800},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'arbitrations':{'op':'add','objects':a['arbitration_addresses']},'compensation_fund_add':{'balance':a['compensation_fund_balance']},'setting_lock_duration_add':a['setting_lock_duration_ms'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Use\x202-3\x20Arbitration\x20objects:\x20e.g.\x20one\x20for\x20quality\x20disputes,\x20one\x20for\x20delivery\x20disputes','compensation_fund\x20>\x200\x20REQUIRES\x20arbitrations\x20non-empty\x20(F-S-19,\x20E_ARBITRATION_NOT_SET_WITH_COMPENSATION_FUND)','compensation_fund\x20coin\x20type\x20MUST\x20match\x20Service<T>\x20type\x20parameter','setting_lock_duration\x20protects\x20customers\x20—\x20only-increase\x20mechanism'],'post_publish_considerations':['Arbitration\x20bindings\x20are\x20PERMANENT\x20—\x20verify\x20arb\x20reputation\x20before\x20publish','compensation_fund_add\x20(deposit)\x20is\x20always\x20mutable\x20post-publish','compensation_fund_withdraw\x20requires\x20bPaused=true\x20+\x20lock_duration\x20expired','Cannot\x20add\x20new\x20Arbitration\x20post-publish\x20—\x20only\x20pre-publish']},{'id':'T-S-06','name':'Compensation\x20fund\x20Service\x20(embedded\x20Balance<T>)','description':'Service\x20focused\x20on\x20compensation_fund\x20management\x20—\x20emphasizes\x20distinction\x20from\x20Treasury','applicable_scenes':['service_compensation_fund','service_arbitration'],'industry_tags':['finance','escrow','guarantee'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'arbitration_addresses','type':'string[]','description':'Arbitration\x20objects\x20(required\x20when\x20fund\x20>\x200)','required':!![]},{'name':'initial_deposit','type':'string','description':'Initial\x20compensation_fund\x20deposit\x20(base\x20units)','required':!![]},{'name':'lock_duration_ms','type':'number','description':'setting_lock_duration\x20(ms)','required':![],'default':0x9a7ec800},{'name':'service_items','type':'object','description':'Sales\x20items','required':!![]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'arbitrations':{'op':'add','objects':a['arbitration_addresses']},'compensation_fund_add':{'balance':a['initial_deposit']},'setting_lock_duration_add':a['lock_duration_ms'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['⚠️\x20compensation_fund\x20is\x20INTERNAL\x20Balance<T>\x20—\x20distinct\x20from\x20Treasury\x20(external)','Treasury\x20is\x20referenced\x20via\x20order_allocators.sharing.who=Entity\x20(Treasury\x20address)','compensation_fund\x20is\x20consumed\x20by\x20the\x20arbitration\x20compensation\x20claim\x20(driven\x20by\x20arb\x20result)','Owner\x20can\x20only\x20withdraw\x20via\x20compensation_fund_withdraw\x20(requires\x20paused\x20+\x20lock\x20expired)'],'post_publish_considerations':['Deposits\x20(compensation_fund_add)\x20always\x20allowed','Withdrawals\x20(compensation_fund_withdraw)\x20require\x20bPaused=true\x20+\x20lock_duration\x20expired','Receive\x20(compensation_fund_receive)\x20locked\x20by\x20duration','setting_lock_duration\x20only-increase\x20—\x20plan\x20withdrawal\x20timeline\x20carefully']},{'id':'T-S-07','name':'Dynamic\x20pricing\x20Service\x20(discount-driven)','description':'Service\x20with\x20promotional\x20discount\x20coupons\x20—\x20supports\x20rates\x20(basis\x20points,\x20per\x2010000)\x20and\x20minus\x20(direct\x20deduction)\x20types','applicable_scenes':['service_dynamic_pricing'],'industry_tags':['retail','marketing','promotion'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'discount_specs','type':'object','description':'Array\x20of\x20{name,\x20type,\x20data,\x20count,\x20expire_at}\x20for\x20initial\x20discounts','required':![],'default':[]}],'body':a=>({'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':[{'threshold':'0','sharing':[{'who':{'Object':a['owner_address']},'weight':0x64}]}]}),'notes':['Discounts\x20are\x20issued\x20POST-PUBLISH\x20via\x20discount\x20(312)\x20—\x20not\x20in\x20create\x20body','discount_type=0\x20rates\x20(basis\x20points,\x20e.g.\x201000=10%);\x201=minus\x20(direct\x20deduction,\x20base\x20units)','MAX_DISCOUNT_COUNT_ONCE\x20=\x201000\x20per\x20issue\x20call','MAX_DISCOUNT_RECEIVER_ONCE\x20=\x201000\x20receivers\x20per\x20call','MAX_DISCOUNT_TOTAL_COUNT\x20=\x2020000\x20total\x20coupons\x20per\x20Service','discount_destroy\x20is\x20holder-only\x20(no\x20SERVICE_DISCOUNT\x20permission\x20needed)','discount_send\x20transfers\x20owned\x20transferable:true\x20coupons\x20to\x20another\x20address\x20(holder-only)'],'post_publish_considerations':['Discount\x20coupons\x20can\x20be\x20issued/destroyed\x20freely','Sales\x20prices\x20can\x20be\x20updated\x20via\x20the\x20sales\x20update\x20operation\x20(existing\x20orders\x20unaffected)','Track\x20discount\x20usage\x20to\x20avoid\x20stockout\x20of\x20promotional\x20items']},{'id':'T-S-08','name':'Multi-allocator\x20Service\x20(tiered\x20fund\x20distribution)','description':'Service\x20with\x20multiple\x20allocator\x20tiers\x20—\x20guard-selected\x20distribution\x20based\x20on\x20order\x20value','applicable_scenes':['service_multi_allocator','service_order_allocator','service_reward'],'industry_tags':['marketplace','platform','logistics'],'params':[{'name':'owner_address','type':'address','description':'Service\x20owner\x20(merchant)','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Service\x20description','required':!![]},{'name':'platform_address','type':'address','description':'Platform\x20fee\x20recipient','required':!![]},{'name':'logistics_address','type':'address','description':'Logistics\x20fee\x20recipient\x20(optional)','required':![],'default':''},{'name':'service_items','type':'object','description':'Array\x20of\x20{name,\x20price,\x20stock,\x20wip,\x20wip_hash}','required':!![]},{'name':'tier1_threshold','type':'string','description':'Small\x20order\x20threshold\x20(base\x20units,\x20e.g.\x20\x270\x27)','required':![],'default':'0'},{'name':'tier2_threshold','type':'string','description':'Medium\x20order\x20threshold\x20(base\x20units)','required':![],'default':'10000000000'},{'name':'tier3_threshold','type':'string','description':'Large\x20order\x20threshold\x20(base\x20units)','required':![],'default':'100000000000'}],'body':a=>{const b=[{'threshold':a['tier1_threshold'],'sharing':[{'who':{'Object':a['owner_address']},'weight':0x5a},{'who':{'Object':a['platform_address']},'weight':0xa}]},{'threshold':a['tier2_threshold'],'sharing':a['logistics_address']?[{'who':{'Object':a['owner_address']},'weight':0x50},{'who':{'Object':a['platform_address']},'weight':0xa},{'who':{'Object':a['logistics_address']},'weight':0xa}]:[{'who':{'Object':a['owner_address']},'weight':0x55},{'who':{'Object':a['platform_address']},'weight':0xf}]},{'threshold':a['tier3_threshold'],'sharing':a['logistics_address']?[{'who':{'Object':a['owner_address']},'weight':0x46},{'who':{'Object':a['platform_address']},'weight':0xa},{'who':{'Object':a['logistics_address']},'weight':0x14}]:[{'who':{'Object':a['owner_address']},'weight':0x50},{'who':{'Object':a['platform_address']},'weight':0x14}]}];return{'object':null,'description':a['description'],'permission':a['permission_address'],'sales':{'op':'add','sales':a['service_items']},'order_allocators':b};},'notes':['Each\x20allocator\x20tier\x20is\x20bound\x20to\x20a\x20DIFFERENT\x20guard\x20—\x20the\x20caller\x27s\x20submitted\x20guard\x20selects\x20which\x20tier\x20fires','Each\x20tier\x20can\x20have\x20its\x20own\x20Guard\x20for\x20execution\x20authorization\x20(optional)','Thresholds\x20must\x20be\x20ascending\x20(tier1\x20<\x20tier2\x20<\x20tier3)','MAX_SHARING_COUNT\x20=\x20100\x20per\x20allocator\x20(sum\x20of\x20sharing\x20entries)','Treasury\x20addresses\x20can\x20be\x20referenced\x20via\x20sharing.who=Entity\x20(Treasury\x20object)'],'post_publish_considerations':['⚠️\x20order_allocators\x20is\x20IMMUTABLE\x20post-publish\x20(F-S-22)\x20—\x20verify\x20tiers\x20before\x20publish','To\x20change\x20fee\x20split:\x20clone\x20Service\x20with\x20new\x20allocators\x20(cannot\x20migrate\x20existing\x20Orders)','Sales\x20can\x20still\x20be\x20updated\x20post-publish\x20(only\x20allocator\x20is\x20locked)']},{'id':'T-S-09','name':'Supply\x20Chain\x20Sub-order\x20Service\x20(milestone\x20unlock\x20via\x20buy_guard)','description':'Sub-service\x20whose\x20buy_guard\x20verifies\x20the\x20user\x20purchased\x20the\x20main\x20service\x20order.\x20Each\x20milestone\x20=\x20one\x20sub-order.\x20Enables\x20supply\x20chain\x20composition:\x20main\x20service\x20→\x20multiple\x20sub-services\x20with\x20conditional\x20access.','applicable_scenes':['service_buy_guard'],'industry_tags':['travel','rental','education','freelance','ecommerce','supply_chain'],'params':[{'name':'owner_address','type':'address','description':'Sub-service\x20owner\x20address','required':!![]},{'name':'permission_address','type':'address','description':'Permission\x20object\x20address','required':!![]},{'name':'description','type':'string','description':'Sub-service\x20description\x20(e.g.,\x20\x27Hotel\x20booking\x20for\x20tour\x20package\x20X\x27)','required':!![]},{'name':'main_service_address','type':'address','description':'Main\x20Service\x20object\x20address\x20(the\x20parent\x20service)','required':!![]},{'name':'buy_guard_address','type':'address','description':'Guard\x20address\x20verifying\x20main\x20order\x20ownership\x20(order.owner==Signer\x20AND\x20order.service==main_service)','required':!![]},{'name':'price','type':'number','description':'Sub-service\x20price','required':!![]},{'name':'machine_address','type':'address','description':'Machine\x20object\x20for\x20sub-order\x20workflow','required':!![]}],'body':a=>({'object':null,'description':a['description'],'service_type':'supply_chain_sub','buy_guard':a['buy_guard_address'],'price':a['price'],'machine':a['machine_address'],'permission':a['permission_address']}),'notes':['VERIFIED:\x20buy_guard:\x20Option<address>;\x20the\x20Passport-verified\x20purchase\x20evaluates\x20buy_guard','VERIFIER-EVIDENCE\x20DESIGN:\x20user\x20submits\x20main\x20Order\x20as\x20evidence\x20(b_submission=true),\x20buy_guard\x20verifies\x20order.owner==Signer\x20AND\x20order.service==main_service_address','No\x20parent_order\x20field\x20needed\x20—\x20relationship\x20verified\x20via\x20buy_guard\x20querying\x20submitted\x20Order\x20fields','Each\x20milestone\x20=\x20one\x20sub-order\x20with\x20its\x20own\x20Service\x20+\x20buy_guard\x20+\x20Machine','Main\x20flow\x20Machine\x20can\x20branch\x20to\x20different\x20sub-services\x20based\x20on\x20node\x20progression','Use\x20tpl_buy_guard_order_holder\x20(guard-templates.ts)\x20for\x20the\x20buy_guard\x20design'],'post_publish_considerations':['buy_guard\x20is\x20mutable\x20post-publish\x20(can\x20update\x20the\x20guard\x20address)','If\x20main\x20service\x20is\x20unpublished,\x20sub-service\x20buy_guard\x20will\x20fail\x20(order.service\x20won\x27t\x20match)','Consider\x20publishing\x20main\x20service\x20before\x20sub-services']}];export const SERVICE_TEMPLATES_VERSION='1.0.0';export function getAllServiceTemplates(){return[...SERVICE_TEMPLATES];}export function getServiceTemplateById(a){return SERVICE_TEMPLATES['find'](b=>b['id']===a);}export function getServiceTemplatesByScene(a){return SERVICE_TEMPLATES['filter'](b=>b['applicable_scenes']['includes'](a));}export function getServiceTemplatesByIndustry(a){return SERVICE_TEMPLATES['filter'](b=>b['industry_tags']['includes'](a)||b['industry_tags']['includes']('universal'));}export function suggestServiceTemplateForScene(a){const b=getServiceTemplatesByScene(a);return b['length']>0x0?b[0x0]:undefined;}export function listServiceTemplates(){return SERVICE_TEMPLATES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'scenes':a['applicable_scenes']}));}export const SERVICE_PRICING_NOTE='Pricing\x20coin:\x20prices\x20in\x20the\x20generated\x20body\x20are\x20denominated\x20in\x20the\x20object\x27s\x20type_parameter\x20token\x20(default\x200x2::wow::WOW),\x20which\x20is\x20FIXED\x20at\x20creation\x20—\x20buyers\x20must\x20hold\x20that\x20exact\x20token\x20to\x20order.\x20To\x20price\x20in\x20a\x20different\x20token,\x20pass\x20its\x20full\x20type\x20(from\x20wowok_buildin_info\x20\x27mainnet\x20bridge\x20tokens\x27\x20wowTypeTag)\x20as\x20type_parameter\x20BEFORE\x20creating.\x20Testnet\x20has\x20ONLY\x20WOW\x20(no\x20stablecoins\x20are\x20bridged);\x20multi-token\x20pricing\x20is\x20a\x20mainnet\x20capability.';export function fillServiceTemplate(a,b){const c=getServiceTemplateById(a);if(!c)return{'ok':![],'error':'Template\x20'+a+'\x20not\x20found'};const d=[];for(const f of c['params']){f['required']&&!(f['name']in b)&&d['push'](f['name']);}if(d['length']>0x0)return{'ok':![],'error':'Missing\x20required\x20params:\x20'+d['join'](',\x20'),'missing_required':d};const e={...b};for(const g of c['params']){!(g['name']in e)&&g['default']!==undefined&&(e[g['name']]=g['default']);}return{'ok':!![],'body':c['body'](e),'pricing_note':SERVICE_PRICING_NOTE};}
|
|
@@ -27,6 +27,7 @@ export declare const TemplateFrontmatterSchema: z.ZodObject<{
|
|
|
27
27
|
final: "final";
|
|
28
28
|
cancelled: "cancelled";
|
|
29
29
|
}>>;
|
|
30
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
30
31
|
from: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
31
32
|
prev: z.ZodString;
|
|
32
33
|
forward: z.ZodOptional<z.ZodString>;
|
|
@@ -123,6 +124,9 @@ export interface IndustryTemplate extends TemplateFrontmatter {
|
|
|
123
124
|
body: string;
|
|
124
125
|
source_path: string;
|
|
125
126
|
}
|
|
127
|
+
import { validateAllocatorRows } from "./template-validation.js";
|
|
128
|
+
export { validateAllocatorRows };
|
|
129
|
+
export declare function platformShareBps(fee: Record<string, number | string>): number | undefined;
|
|
126
130
|
export declare function parseTemplateFile(raw: string): {
|
|
127
131
|
frontmatter: Record<string, unknown>;
|
|
128
132
|
body: string;
|
|
@@ -131,11 +135,12 @@ export declare const TEMPLATE_SENTINEL_KIND = "industry-template";
|
|
|
131
135
|
export declare function renderTemplateFile(t: ArchetypeTemplate): string;
|
|
132
136
|
export interface TemplateSeedResult {
|
|
133
137
|
template: string;
|
|
134
|
-
status: "written" | "
|
|
138
|
+
status: "written" | "restamped" | "current" | "skipped_modified" | "skipped_user_file" | "would_update" | "updated" | "error";
|
|
135
139
|
path: string;
|
|
136
140
|
detail?: string;
|
|
137
141
|
}
|
|
138
142
|
export declare function seedBuiltinTemplates(): TemplateSeedResult[];
|
|
143
|
+
export declare function summarizeTemplateDiff(onDiskContent: string, canonical: string): string;
|
|
139
144
|
export declare function repairBuiltinTemplates(options?: {
|
|
140
145
|
backup?: boolean;
|
|
141
146
|
dryRun?: boolean;
|
|
@@ -143,7 +148,8 @@ export declare function repairBuiltinTemplates(options?: {
|
|
|
143
148
|
export declare function builtinTemplateDrift(): Array<{
|
|
144
149
|
template: string;
|
|
145
150
|
path: string;
|
|
146
|
-
state: "
|
|
151
|
+
state: "missing" | "modified";
|
|
152
|
+
repairable: boolean;
|
|
147
153
|
detail: string;
|
|
148
154
|
}>;
|
|
149
155
|
export declare function reloadTemplates(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,renameSync,rmdirSync,statSync,writeFileSync}from'node:fs';import{join}from'node:path';import{z}from'zod';import{getWowokDataDir,getWowokIndustryDir}from'@wowok/wowok';import{SUPPORTED_INDUSTRIES}from'../customer/user-preferences.js';import{isRegisteredIndustry}from'./industry-registry.js';import{BUILTIN_TEMPLATES,BUILTIN_TEMPLATES_VERSION}from'./builtin-templates.js';import{classifyRelease,releaseBodyHash,releaseSentinelLine,stripReleaseSentinel}from'./release-sentinel.js';export const TEMPLATES_SUBDIR='templates';export function resolveTemplatesDir(){return process['env']['WOWOK_TEMPLATES_DIR']||getWowokIndustryDir();}function resolveLegacyTemplatesDir(){return process['env']['WOWOK_LEGACY_TEMPLATES_DIR']||join(getWowokDataDir(),'templates');}const MachineEdgeSchema=z['object']({'prev':z['string'](),'forward':z['string']()['min'](0x1)['optional'](),'operator':z['enum'](['merchant','order_payer'])['optional'](),'permission_index':z['number']()['int']()['min'](0x3e8)['optional'](),'guard_key':z['string']()['min'](0x1)['optional']()}),MachineNodeSchema=z['object']({'name':z['string']()['min'](0x1),'role':z['string']()['min'](0x1),'operator':z['enum'](['merchant','order_payer'])['optional'](),'semantic_role':z['enum'](['draft','active','delivered','final','cancelled'])['optional'](),'from':z['array'](z['union']([z['string'](),MachineEdgeSchema]))['optional']()}),GuardRefSchema=z['object']({'template_id':z['string']()['regex'](/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/,'guard\x20template_id\x20must\x20be\x20a\x20\x27pattern.*\x27\x20design\x20pattern\x20or\x20\x27tpl_*\x27\x20guard\x20template'),'host':z['enum'](['service','machine','reward','repository','arbitration']),'purpose':z['string']()['min'](0x1),'key':z['string']()['min'](0x1)['optional']()}),AllocatorRowSchema=z['object']({'track':z['enum'](['settlement','refund']),'recipient':z['enum'](['entity','guard_identifier','signer']),'recipient_key':z['string']()['min'](0x1)['optional'](),'mode':z['enum'](['amount','rate','surplus']),'value':z['union']([z['string'](),z['number']()])['optional'](),'value_from':z['string']()['optional'](),'fix':z['union']([z['string'](),z['number']()])['optional'](),'fix_from':z['string']()['optional'](),'guard_key':z['string']()['min'](0x1)['optional'](),'note':z['string']()['optional']()})['strict'](),AllocatorSchema=z['object']({'recipient':z['enum'](['signer','entity','fixed']),'recipient_key':z['string']()['min'](0x1)['optional'](),'refund_track':z['enum'](['order_anchored'])['optional'](),'count':z['number']()['int']()['positive'](),'mode':z['enum'](['amount','rate','surplus']),'once_per_order':z['boolean']()['optional'](),'rows':z['array'](AllocatorRowSchema)['optional'](),'description':z['string']()['min'](0x1)})['strict'](),IndustryNameSchema=z['string']()['regex'](/^[a-z][a-z0-9_]*$/,'industry\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)')['refine'](a=>isRegisteredIndustry(a),{'message':'unknown\x20industry\x20—\x20register\x20it\x20first\x20via\x20an\x20industry\x20pack\x20'+'(industry_pack_operation\x20action=\x27scaffold\x27)\x20or\x20the\x20industry\x20generalizer;\x20'+('builtin\x20industries:\x20'+SUPPORTED_INDUSTRIES['join'](',\x20'))});export const TemplateFrontmatterSchema=z['object']({'id':z['string']()['regex'](/^[a-z][a-z0-9_-]*\/[a-z][a-z0-9_-]*$/,'id\x20must\x20be\x20\x27<industry>/<variant>\x27'),'industry':IndustryNameSchema,'variant':z['string']()['regex'](/^[a-z][a-z0-9_-]*$/),'product_ref':z['string']()['regex'](/^[a-z][a-z0-9._-]*$/,'product_ref\x20must\x20be\x20a\x20lowercase\x20product\x20slug')['optional'](),'archetype':z['enum'](['leader','challenger']),'phase':z['number']()['int']()['min'](0x1)['max'](0x3),'machine_shape':z['array'](MachineNodeSchema)['min'](0x1),'guards':z['array'](GuardRefSchema),'allocator':AllocatorSchema,'fee_params':z['record'](z['string'](),z['union']([z['number'](),z['string']()])),'trust_mechanisms':z['array'](z['string']()),'keeper_dependencies':z['array'](z['string']()),'recommended_role':z['enum'](['merchant','supplier','both']),'role_rationale':z['string']()['min'](0x1),'differences':z['array'](z['string']()),'user_inputs':z['array'](z['string']()),'key_risk':z['string']()['min'](0x1)['max'](0x12c,'key_risk\x20must\x20be\x20a\x20one-line\x20risk\x20statement\x20(<=\x20300\x20chars)\x20—\x20rules\x20and\x20doctrine\x20do\x20not\x20belong\x20in\x20this\x20field')['refine'](a=>!/STANDING RULE|TECHNOLOGY PROVIDER|NOT A PARTY TO THE DEAL|Full text:/i['test'](a),{'message':'key_risk\x20carries\x20an\x20instruction-block\x20fragment\x20(STANDING\x20RULE\x20/\x20provider\x20doctrine\x20/\x20\x27Full\x20text:\x27\x20reference)\x20—\x20keep\x20doctrine\x20in\x20body\x20prose\x20or\x20playbooks,\x20not\x20in\x20this\x20field'}),'build_notes':z['array'](z['string']()),'time_anchors':z['record'](z['string'](),z['string']())['optional'](),'payment_model':z['enum'](['milestone','subscription','escrow'])['optional'](),'arbitration_mode':z['enum'](['none','merchant_pick','mutual_pick','third_party'])['optional']()})['strict']();export function parseTemplateFile(a){const b=a['replace'](/^\uFEFF/,'')['replace'](/^<!-- builtin:[a-z0-9-]+:v\d+:[0-9a-f]+ -->\r?\n/,''),c=b['split'](/\r?\n/);if(c[0x0]?.['trim']()!=='---')throw new Error('template\x20must\x20start\x20with\x20a\x20\x27---\x27\x20frontmatter\x20block');let d=-0x1;for(let f=0x1;f<c['length'];f++){if(c[f]['trim']()==='---'){d=f;break;}}if(d===-0x1)throw new Error('unterminated\x20frontmatter\x20block\x20(missing\x20closing\x20\x27---\x27)');const e={};for(let g=0x1;g<d;g++){const h=c[g];if(!h['trim']()||h['trim']()['startsWith']('#'))continue;const j=h['indexOf'](':');if(j===-0x1)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20\x27'+h['trim']()+'\x27\x20(expected\x20\x27key:\x20value\x27)');const k=h['slice'](0x0,j)['trim'](),l=h['slice'](j+0x1)['trim']();if(!k)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20empty\x20key');if(l['startsWith']('[')||l['startsWith']('{'))try{e[k]=JSON['parse'](l);}catch(m){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+m['message']);}else/^-?\d+(\.\d+)?$/['test'](l)?e[k]=Number(l):e[k]=l;}return{'frontmatter':e,'body':c['slice'](d+0x1)['join']('\x0a')['trim']()};}function frontmatterLine(a,b){if(typeof b==='number')return a+':\x20'+b;if(typeof b==='string')return a+':\x20'+b;return a+':\x20'+JSON['stringify'](b);}export const TEMPLATE_SENTINEL_KIND='industry-template';function canonicalTemplateContent(a){const b=[['id',a['id']],['industry',a['industry']],['variant',a['variant']],['product_ref',a['product_ref']],['archetype',a['archetype']],['phase',a['phase']],['recommended_role',a['recommended_role']],['role_rationale',a['role_rationale']],['key_risk',a['key_risk']],['machine_shape',a['machine_shape']],['guards',a['guards']],['allocator',a['allocator']],['fee_params',a['fee_params']],['trust_mechanisms',a['trust_mechanisms']],['keeper_dependencies',a['keeper_dependencies']],['differences',a['differences']],['user_inputs',a['user_inputs']],['build_notes',a['build_notes']],...a['time_anchors']?[['time_anchors',a['time_anchors']]]:[],...a['payment_model']?[['payment_model',a['payment_model']]]:[],...a['arbitration_mode']?[['arbitration_mode',a['arbitration_mode']]]:[]],c=['---',...b['map'](([e,f])=>frontmatterLine(e,f)),'---'],d=['','#\x20'+a['industry']+'\x20/\x20'+a['variant']+'\x20('+a['archetype']+')','','>\x20Industry\x20archetype\x20template.\x20Editable\x20and\x20migratable:\x20the\x20frontmatter\x20is','>\x20zod-validated\x20on\x20every\x20load;\x20the\x20body\x20is\x20free-form\x20guidance\x20for\x20the\x20AI.','','##\x20Key\x20risk','',a['key_risk'],'','##\x20Differences\x20vs\x20the\x20sibling\x20variant','',...a['differences']['map'](e=>'-\x20'+e),'','##\x20User\x20inputs\x20(inject\x20at\x20build\x20time)','',...a['user_inputs']['map'](e=>'-\x20'+e),'','##\x20Risk-avoidance\x20checklist\x20(R1-R10)','',...a['trust_mechanisms']['map'](e=>'-\x20'+e),'','##\x20Build\x20notes','',...a['build_notes']['map'](e=>'-\x20'+e),''];return[...c,...d]['join']('\x0a');}export function renderTemplateFile(a){const b=canonicalTemplateContent(a);return releaseSentinelLine(TEMPLATE_SENTINEL_KIND,BUILTIN_TEMPLATES_VERSION,releaseBodyHash(b))+'\x0a'+b;}let seeded=![];function migrateLegacyTemplates(a){const b=resolveLegacyTemplatesDir();if(b===a)return;if(!existsSync(b))return;try{for(const c of readdirSync(b,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(b,c['name']),e=join(a,c['name'],TEMPLATES_SUBDIR);for(const g of readdirSync(d,{'withFileTypes':!![]})){if(!g['isFile']()||!g['name']['endsWith']('.md'))continue;const h=join(e,g['name']);if(existsSync(h))continue;mkdirSync(e,{'recursive':!![]}),renameSync(join(d,g['name']),h);}try{rmdirSync(d);}catch{}}try{rmdirSync(b);}catch{}}catch{}}export function seedBuiltinTemplates(){const a=[],b=resolveTemplatesDir();migrateLegacyTemplates(b);for(const c of BUILTIN_TEMPLATES){const d=join(b,c['industry'],TEMPLATES_SUBDIR),e=join(d,c['variant']+'.md'),f={'template':c['id'],'status':'written','path':e};try{if(!existsSync(e))mkdirSync(d,{'recursive':!![]}),writeFileSync(e,renderTemplateFile(c),'utf-8');else{const {sentinel:g,content:h}=stripReleaseSentinel(readFileSync(e,'utf-8'),TEMPLATE_SENTINEL_KIND);if(!g)f['status']='skipped_user_file',f['detail']='template\x20file\x20exists\x20without\x20builtin\x20sentinel;\x20leaving\x20user\x20file\x20untouched';else{const i=classifyRelease(g,h,BUILTIN_TEMPLATES_VERSION);if(i==='current')f['status']='current';else i==='user_modified'?(f['status']='skipped_user_modified',f['detail']='template\x20file\x20was\x20edited\x20locally;\x20keeping\x20user\x20content\x20and\x20not\x20upgrading'):(writeFileSync(e,renderTemplateFile(c),'utf-8'),f['status']='updated');}}}catch(j){f['status']='error',f['detail']=j['message'];}a['push'](f);}return a;}export function repairBuiltinTemplates(a){const b=[],c=resolveTemplatesDir(),d=a?.['backup']!==![],e=a?.['dryRun']===!![];for(const f of BUILTIN_TEMPLATES){const g=join(c,f['industry'],TEMPLATES_SUBDIR),h=join(g,f['variant']+'.md'),i={'template':f['id'],'status':'skipped_user_file','path':h};if(!existsSync(h))continue;let j=null;try{j=stripReleaseSentinel(readFileSync(h,'utf-8'),TEMPLATE_SENTINEL_KIND)['sentinel'];}catch(l){i['status']='error',i['detail']=l['message'],b['push'](i);continue;}if(j)continue;let k;try{k=String(parseTemplateFile(readFileSync(h,'utf-8'))['frontmatter']['id']??'');}catch{continue;}if(k!==f['id'])continue;if(e){i['status']='would_update',i['detail']='legacy\x20sentinel-less\x20builtin\x20file\x20would\x20be\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+f['id']+')'+(d?';\x20previous\x20content\x20would\x20be\x20saved\x20as\x20<file>.bak':'')+'\x20—\x20execute\x20with\x20authorize=true\x20after\x20the\x20user\x20explicitly\x20confirms',b['push'](i);continue;}try{if(d)copyFileSync(h,h+'.bak');writeFileSync(h,renderTemplateFile(f),'utf-8'),cache['delete'](h),i['status']='updated',i['detail']='legacy\x20sentinel-less\x20builtin\x20file\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+f['id']+')'+(d?';\x20previous\x20content\x20saved\x20as\x20<file>.bak':'');}catch(m){i['status']='error',i['detail']=m['message'];}b['push'](i);}return b;}export function builtinTemplateDrift(){const a=[],b=resolveTemplatesDir();for(const c of BUILTIN_TEMPLATES){const d=join(b,c['industry'],TEMPLATES_SUBDIR,c['variant']+'.md');if(!existsSync(d)){a['push']({'template':c['id'],'path':d,'state':'missing','detail':'no\x20file\x20on\x20disk;\x20seeding\x20will\x20create\x20it'});continue;}let e=null,f='';try{const h=stripReleaseSentinel(readFileSync(d,'utf-8'),TEMPLATE_SENTINEL_KIND);e=h['sentinel'],f=h['content'];}catch(i){a['push']({'template':c['id'],'path':d,'state':'missing','detail':'unreadable:\x20'+i['message']});continue;}if(!e){let j;try{j=String(parseTemplateFile(readFileSync(d,'utf-8'))['frontmatter']['id']??'');}catch{j=undefined;}a['push']({'template':c['id'],'path':d,'state':'no_sentinel_legacy','detail':j===c['id']?'builtin\x20id\x20but\x20NO\x20release\x20sentinel\x20—\x20seeding\x20classifies\x20this\x20as\x20a\x20user\x20file\x20and\x20will\x20NEVER\x20upgrade\x20it;\x20every\x20code-side\x20fix\x20to\x20this\x20template\x20is\x20invisible\x20at\x20runtime':'no\x20release\x20sentinel\x20and\x20id\x20\x27'+(j??'<unparseable>')+'\x27\x20does\x20not\x20match\x20a\x20builtin\x20id\x20—\x20treated\x20as\x20a\x20user\x20template,\x20never\x20touched'});continue;}const g=classifyRelease(e,f,BUILTIN_TEMPLATES_VERSION);if(g==='current')continue;a['push']({'template':c['id'],'path':d,'state':g==='user_modified'?'user_modified':'stale_release','detail':g==='user_modified'?'sentinel\x20present,\x20body\x20edited\x20locally\x20—\x20kept\x20by\x20design':'sentinel\x20present,\x20older\x20release\x20—\x20seeding\x20upgrades\x20it\x20on\x20next\x20access'});}return a;}const cache=new Map();export function reloadTemplates(){cache['clear'](),seeded=![];}export function loadAndValidate(a){const b=readFileSync(a,'utf-8');let c;try{c=parseTemplateFile(b);}catch(e){throw new Error('template\x20\x27'+a+'\x27\x20failed\x20to\x20parse:\x20'+e['message']);}const d=TemplateFrontmatterSchema['safeParse'](c['frontmatter']);if(!d['success']){const f=d['error']['issues']['map'](g=>(g['path']['join']('.')||'<root>')+':\x20'+g['message'])['join'](';\x20');throw new Error('template\x20\x27'+a+'\x27\x20failed\x20validation:\x20'+f);}return{...d['data'],'body':c['body'],'source_path':a};}function templateFilesOnDisk(a){const b=[];if(!existsSync(a))return b;for(const c of readdirSync(a,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(a,c['name'],TEMPLATES_SUBDIR);if(!existsSync(d))continue;for(const e of readdirSync(d,{'withFileTypes':!![]})){if(e['isFile']()&&e['name']['endsWith']('.md'))b['push'](join(d,e['name']));}}return b['sort']();}export function listTemplates(){!seeded&&(seedBuiltinTemplates(),seeded=!![]);const a=resolveTemplatesDir(),b=[],c=[],d=new Set();for(const e of templateFilesOnDisk(a)){d['add'](e);try{const f=statSync(e)['mtimeMs'],g=cache['get'](e);if(g&&g['mtimeMs']===f){b['push'](g['template']);continue;}const h=loadAndValidate(e);cache['set'](e,{'mtimeMs':f,'template':h}),b['push'](h);}catch(i){cache['delete'](e),c['push'](i['message']);}}for(const j of[...cache['keys']()]){if(!d['has'](j))cache['delete'](j);}return b['sort']((k,l)=>k['id']['localeCompare'](l['id'])),{'templates':b,'errors':c};}export function getTemplate(a){return listTemplates()['templates']['find'](b=>b['id']===a);}export function getTemplatesByIndustry(a){return listTemplates()['templates']['filter'](b=>b['industry']===a);}
|
|
1
|
+
import{copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,renameSync,rmdirSync,statSync,writeFileSync}from'node:fs';import{join}from'node:path';import{z}from'zod';import{getWowokDataDir,getWowokIndustryDir}from'@wowok/wowok';import{SUPPORTED_INDUSTRIES}from'../customer/user-preferences.js';import{isRegisteredIndustry}from'./industry-registry.js';import{BUILTIN_TEMPLATES,BUILTIN_TEMPLATES_VERSION}from'./builtin-templates.js';import{releaseBodyHash,releaseSentinelLine,stripReleaseSentinel}from'./release-sentinel.js';export const TEMPLATES_SUBDIR='templates';export function resolveTemplatesDir(){return process['env']['WOWOK_TEMPLATES_DIR']||getWowokIndustryDir();}function resolveLegacyTemplatesDir(){return process['env']['WOWOK_LEGACY_TEMPLATES_DIR']||join(getWowokDataDir(),'templates');}const MachineEdgeSchema=z['object']({'prev':z['string'](),'forward':z['string']()['min'](0x1)['optional'](),'operator':z['enum'](['merchant','order_payer'])['optional'](),'permission_index':z['number']()['int']()['min'](0x3e8)['optional'](),'guard_key':z['string']()['min'](0x1)['optional']()}),MachineNodeSchema=z['object']({'name':z['string']()['min'](0x1),'role':z['string']()['min'](0x1),'operator':z['enum'](['merchant','order_payer'])['optional'](),'semantic_role':z['enum'](['draft','active','delivered','final','cancelled'])['optional'](),'optional':z['boolean']()['optional'](),'from':z['array'](z['union']([z['string'](),MachineEdgeSchema]))['optional']()}),GuardRefSchema=z['object']({'template_id':z['string']()['regex'](/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/,'guard\x20template_id\x20must\x20be\x20a\x20\x27pattern.*\x27\x20design\x20pattern\x20or\x20\x27tpl_*\x27\x20guard\x20template'),'host':z['enum'](['service','machine','reward','repository','arbitration']),'purpose':z['string']()['min'](0x1),'key':z['string']()['min'](0x1)['optional']()}),AllocatorRowSchema=z['object']({'track':z['enum'](['settlement','refund']),'recipient':z['enum'](['entity','guard_identifier','signer']),'recipient_key':z['string']()['min'](0x1)['optional'](),'mode':z['enum'](['amount','rate','surplus']),'value':z['union']([z['string'](),z['number']()])['optional'](),'value_from':z['string']()['optional'](),'fix':z['union']([z['string'](),z['number']()])['optional'](),'fix_from':z['string']()['optional'](),'guard_key':z['string']()['min'](0x1)['optional'](),'note':z['string']()['optional']()})['strict'](),AllocatorSchema=z['object']({'recipient':z['enum'](['signer','entity','fixed']),'recipient_key':z['string']()['min'](0x1)['optional'](),'refund_track':z['enum'](['order_anchored'])['optional'](),'count':z['number']()['int']()['positive'](),'mode':z['enum'](['amount','rate','surplus']),'once_per_order':z['boolean']()['optional'](),'rows':z['array'](AllocatorRowSchema)['optional'](),'description':z['string']()['min'](0x1)})['strict'](),IndustryNameSchema=z['string']()['regex'](/^[a-z][a-z0-9_]*$/,'industry\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)')['refine'](a=>isRegisteredIndustry(a),{'message':'unknown\x20industry\x20—\x20register\x20it\x20first\x20via\x20an\x20industry\x20pack\x20'+'(industry_pack_operation\x20action=\x27scaffold\x27)\x20or\x20the\x20industry\x20generalizer;\x20'+('builtin\x20industries:\x20'+SUPPORTED_INDUSTRIES['join'](',\x20'))});export const TemplateFrontmatterSchema=z['object']({'id':z['string']()['regex'](/^[a-z][a-z0-9_-]*\/[a-z][a-z0-9_-]*$/,'id\x20must\x20be\x20\x27<industry>/<variant>\x27'),'industry':IndustryNameSchema,'variant':z['string']()['regex'](/^[a-z][a-z0-9_-]*$/),'product_ref':z['string']()['regex'](/^[a-z][a-z0-9._-]*$/,'product_ref\x20must\x20be\x20a\x20lowercase\x20product\x20slug')['optional'](),'archetype':z['enum'](['leader','challenger']),'phase':z['number']()['int']()['min'](0x1)['max'](0x3),'machine_shape':z['array'](MachineNodeSchema)['min'](0x1),'guards':z['array'](GuardRefSchema),'allocator':AllocatorSchema,'fee_params':z['record'](z['string'](),z['union']([z['number'](),z['string']()])),'trust_mechanisms':z['array'](z['string']()),'keeper_dependencies':z['array'](z['string']()),'recommended_role':z['enum'](['merchant','supplier','both']),'role_rationale':z['string']()['min'](0x1),'differences':z['array'](z['string']()),'user_inputs':z['array'](z['string']()),'key_risk':z['string']()['min'](0x1)['max'](0x12c,'key_risk\x20must\x20be\x20a\x20one-line\x20risk\x20statement\x20(<=\x20300\x20chars)\x20—\x20rules\x20and\x20doctrine\x20do\x20not\x20belong\x20in\x20this\x20field')['refine'](a=>!/STANDING RULE|TECHNOLOGY PROVIDER|NOT A PARTY TO THE DEAL|Full text:/i['test'](a),{'message':'key_risk\x20carries\x20an\x20instruction-block\x20fragment\x20(STANDING\x20RULE\x20/\x20provider\x20doctrine\x20/\x20\x27Full\x20text:\x27\x20reference)\x20—\x20keep\x20doctrine\x20in\x20body\x20prose\x20or\x20playbooks,\x20not\x20in\x20this\x20field'}),'build_notes':z['array'](z['string']()),'time_anchors':z['record'](z['string'](),z['string']())['optional'](),'payment_model':z['enum'](['milestone','subscription','escrow'])['optional'](),'arbitration_mode':z['enum'](['none','merchant_pick','mutual_pick','third_party'])['optional']()})['strict']();import{validateAllocatorRows}from'./template-validation.js';export{validateAllocatorRows};export function platformShareBps(a){const b=Object['keys'](a)['find'](c=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](c)&&!/^attributed_/['test'](c)&&typeof a[c]==='number');return b!==undefined?a[b]:undefined;}export function parseTemplateFile(a){const b=a['replace'](/^\uFEFF/,'')['replace'](/^<!-- builtin:[a-z0-9-]+:v\d+:[0-9a-f]+ -->\r?\n/,''),c=b['split'](/\r?\n/);if(c[0x0]?.['trim']()!=='---')throw new Error('template\x20must\x20start\x20with\x20a\x20\x27---\x27\x20frontmatter\x20block');let d=-0x1;for(let f=0x1;f<c['length'];f++){if(c[f]['trim']()==='---'){d=f;break;}}if(d===-0x1)throw new Error('unterminated\x20frontmatter\x20block\x20(missing\x20closing\x20\x27---\x27)');const e={};for(let g=0x1;g<d;g++){const h=c[g];if(!h['trim']()||h['trim']()['startsWith']('#'))continue;const j=h['indexOf'](':');if(j===-0x1)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20\x27'+h['trim']()+'\x27\x20(expected\x20\x27key:\x20value\x27)');const k=h['slice'](0x0,j)['trim'](),l=h['slice'](j+0x1)['trim']();if(!k)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20empty\x20key');if(l['startsWith']('[')||l['startsWith']('{'))try{e[k]=JSON['parse'](l);}catch(m){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+m['message']);}else/^-?\d+(\.\d+)?$/['test'](l)?e[k]=Number(l):e[k]=l;}return{'frontmatter':e,'body':c['slice'](d+0x1)['join']('\x0a')['trim']()};}function frontmatterLine(a,b){if(typeof b==='number')return a+':\x20'+b;if(typeof b==='string')return a+':\x20'+b;return a+':\x20'+JSON['stringify'](b);}export const TEMPLATE_SENTINEL_KIND='industry-template';function canonicalTemplateContent(a){const b=[['id',a['id']],['industry',a['industry']],['variant',a['variant']],['product_ref',a['product_ref']],['archetype',a['archetype']],['phase',a['phase']],['recommended_role',a['recommended_role']],['role_rationale',a['role_rationale']],['key_risk',a['key_risk']],['machine_shape',a['machine_shape']],['guards',a['guards']],['allocator',a['allocator']],['fee_params',a['fee_params']],['trust_mechanisms',a['trust_mechanisms']],['keeper_dependencies',a['keeper_dependencies']],['differences',a['differences']],['user_inputs',a['user_inputs']],['build_notes',a['build_notes']],...a['time_anchors']?[['time_anchors',a['time_anchors']]]:[],...a['payment_model']?[['payment_model',a['payment_model']]]:[],...a['arbitration_mode']?[['arbitration_mode',a['arbitration_mode']]]:[]],c=['---',...b['map'](([e,f])=>frontmatterLine(e,f)),'---'],d=['','#\x20'+a['industry']+'\x20/\x20'+a['variant']+'\x20('+a['archetype']+')','','>\x20Industry\x20archetype\x20template.\x20Editable\x20and\x20migratable:\x20the\x20frontmatter\x20is','>\x20zod-validated\x20on\x20every\x20load;\x20the\x20body\x20is\x20free-form\x20guidance\x20for\x20the\x20AI.','','##\x20Key\x20risk','',a['key_risk'],'','##\x20Differences\x20vs\x20the\x20sibling\x20variant','',...a['differences']['map'](e=>'-\x20'+e),'','##\x20User\x20inputs\x20(inject\x20at\x20build\x20time)','',...a['user_inputs']['map'](e=>'-\x20'+e),'','##\x20Risk-avoidance\x20checklist\x20(R1-R10)','',...a['trust_mechanisms']['map'](e=>'-\x20'+e),'','##\x20Build\x20notes','',...a['build_notes']['map'](e=>'-\x20'+e),''];return[...c,...d]['join']('\x0a');}export function renderTemplateFile(a){const b=canonicalTemplateContent(a);return releaseSentinelLine(TEMPLATE_SENTINEL_KIND,BUILTIN_TEMPLATES_VERSION,releaseBodyHash(b))+'\x0a'+b;}let seeded=![];function migrateLegacyTemplates(a){const b=resolveLegacyTemplatesDir();if(b===a)return;if(!existsSync(b))return;try{for(const c of readdirSync(b,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(b,c['name']),e=join(a,c['name'],TEMPLATES_SUBDIR);for(const g of readdirSync(d,{'withFileTypes':!![]})){if(!g['isFile']()||!g['name']['endsWith']('.md'))continue;const h=join(e,g['name']);if(existsSync(h))continue;mkdirSync(e,{'recursive':!![]}),renameSync(join(d,g['name']),h);}try{rmdirSync(d);}catch{}}try{rmdirSync(b);}catch{}}catch{}}export function seedBuiltinTemplates(){const a=[],b=resolveTemplatesDir();migrateLegacyTemplates(b);for(const c of BUILTIN_TEMPLATES){const d=join(b,c['industry'],TEMPLATES_SUBDIR),e=join(d,c['variant']+'.md'),f=canonicalTemplateContent(c),g={'template':c['id'],'status':'written','path':e};try{if(!existsSync(e))mkdirSync(d,{'recursive':!![]}),writeFileSync(e,renderTemplateFile(c),'utf-8');else{const h=readFileSync(e,'utf-8'),{sentinel:i,content:j}=stripReleaseSentinel(h,TEMPLATE_SENTINEL_KIND);!i?j===f?(writeFileSync(e,renderTemplateFile(c),'utf-8'),g['status']='restamped',g['detail']='body\x20matches\x20canonical\x20but\x20no\x20sentinel\x20present;\x20sentinel\x20header\x20added,\x20body\x20untouched'):(g['status']='skipped_user_file',g['detail']='template\x20file\x20exists\x20without\x20builtin\x20sentinel\x20and\x20body\x20differs\x20from\x20canonical;\x20leaving\x20user\x20file\x20untouched'):j===f?i['version']!==BUILTIN_TEMPLATES_VERSION||releaseBodyHash(j)!==i['hash']?(writeFileSync(e,renderTemplateFile(c),'utf-8'),g['status']='restamped',g['detail']='body\x20matches\x20canonical\x20but\x20sentinel\x20stale/wrong;\x20header\x20refreshed,\x20body\x20untouched'):g['status']='current':(g['status']='skipped_modified',g['detail']='body\x20differs\x20from\x20canonical;\x20not\x20overwritten\x20by\x20seeding\x20—\x20use\x20repair_builtin_templates\x20(preview→confirm)\x20to\x20reseed');}}catch(k){g['status']='error',g['detail']=k['message'];}a['push'](g);}return a;}export function summarizeTemplateDiff(a,b){let c,d;try{c=parseTemplateFile(a);}catch(g){return'on-disk\x20file\x20is\x20not\x20parseable\x20('+g['message']+');\x20full\x20content\x20will\x20be\x20replaced';}try{d=parseTemplateFile(b);}catch{return'canonical\x20render\x20is\x20not\x20parseable\x20(code\x20defect);\x20full\x20content\x20will\x20be\x20replaced';}const e=[],f=new Set([...Object['keys'](c['frontmatter']),...Object['keys'](d['frontmatter'])]);for(const h of[...f]['sort']()){const i=h in c['frontmatter'],j=h in d['frontmatter'];if(i&&!j)e['push']('-'+h);else{if(!i&&j)e['push']('+'+h);else{if(JSON['stringify'](c['frontmatter'][h])!==JSON['stringify'](d['frontmatter'][h]))e['push']('~'+h);}}}return c['body']!==d['body']&&e['push']('~body\x20('+c['body']['split']('\x0a')['length']+'\x20->\x20'+d['body']['split']('\x0a')['length']+'\x20lines)'),e['length']>0x0?e['join'](',\x20'):'whitespace/ordering\x20only';}export function repairBuiltinTemplates(a){const b=[],c=resolveTemplatesDir(),d=a?.['backup']!==![],e=a?.['dryRun']===!![];for(const f of BUILTIN_TEMPLATES){const g=join(c,f['industry'],TEMPLATES_SUBDIR),h=join(g,f['variant']+'.md');if(!existsSync(h))continue;const i=canonicalTemplateContent(f);let j=null,k='';const l={'template':f['id'],'status':'would_update','path':h};try{const o=stripReleaseSentinel(readFileSync(h,'utf-8'),TEMPLATE_SENTINEL_KIND);j=o['sentinel'],k=o['content'];}catch(p){l['status']='error',l['detail']=p['message'],b['push'](l);continue;}if(k===i)continue;let m;if(j){if(releaseBodyHash(k)!==j['hash'])continue;m='untouched\x20older\x20release\x20(sentinel\x20v'+j['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')';}else{let q;try{q=String(parseTemplateFile(k)['frontmatter']['id']??'');}catch{continue;}if(q!==f['id'])continue;m='legacy\x20sentinel-less\x20builtin\x20file';}const n=summarizeTemplateDiff(k,i);if(e){l['status']='would_update',l['detail']=m+'\x20would\x20be\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+f['id']+')\x20—\x20diff\x20vs\x20canonical:\x20'+n+(d?';\x20previous\x20body\x20would\x20be\x20saved\x20as\x20<file>.bak':'')+'\x20—\x20execute\x20with\x20authorize=true\x20after\x20the\x20user\x20explicitly\x20confirms',b['push'](l);continue;}try{if(d)copyFileSync(h,h+'.bak');writeFileSync(h,renderTemplateFile(f),'utf-8'),cache['delete'](h),l['status']='updated',l['detail']=m+'\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+f['id']+')\x20—\x20diff\x20was:\x20'+n+(d?';\x20previous\x20body\x20saved\x20as\x20<file>.bak':'');}catch(r){l['status']='error',l['detail']=r['message'];}b['push'](l);}return b;}export function builtinTemplateDrift(){const a=[],b=resolveTemplatesDir();for(const c of BUILTIN_TEMPLATES){const d=join(b,c['industry'],TEMPLATES_SUBDIR,c['variant']+'.md');if(!existsSync(d)){a['push']({'template':c['id'],'path':d,'state':'missing','repairable':!![],'detail':'no\x20file\x20on\x20disk;\x20seeding\x20will\x20create\x20it'});continue;}const e=canonicalTemplateContent(c);let f=null,g='';try{const i=stripReleaseSentinel(readFileSync(d,'utf-8'),TEMPLATE_SENTINEL_KIND);f=i['sentinel'],g=i['content'];}catch(j){a['push']({'template':c['id'],'path':d,'state':'modified','repairable':![],'detail':'unreadable:\x20'+j['message']});continue;}if(g===e)continue;const h=summarizeTemplateDiff(g,e);if(!f){let k;try{k=String(parseTemplateFile(g)['frontmatter']['id']??'');}catch{k=undefined;}k===c['id']?a['push']({'template':c['id'],'path':d,'state':'modified','repairable':!![],'detail':'legacy\x20sentinel-less\x20builtin\x20file\x20—\x20seeding\x20never\x20rewrites\x20it\x20and\x20no\x20sentinel\x20proves\x20provenance;\x20repair\x20can\x20reseed\x20—\x20diff\x20vs\x20canonical:\x20'+h}):a['push']({'template':c['id'],'path':d,'state':'modified','repairable':![],'detail':'no\x20release\x20sentinel\x20and\x20id\x20\x27'+(k??'<unparseable>')+'\x27\x20does\x20not\x20match\x20the\x20builtin\x20id\x20—\x20a\x20user\x20file\x20occupies\x20this\x20path;\x20never\x20touched\x20(rename\x20it\x20to\x20free\x20the\x20slot)'});continue;}releaseBodyHash(g)===f['hash']?a['push']({'template':c['id'],'path':d,'state':'modified','repairable':!![],'detail':'untouched\x20older\x20release\x20(sentinel\x20v'+f['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20repair\x20can\x20upgrade\x20—\x20diff\x20vs\x20canonical:\x20'+h}):a['push']({'template':c['id'],'path':d,'state':'modified','repairable':![],'detail':'user-edited\x20body\x20—\x20kept\x20by\x20design;\x20repair\x20never\x20overwrites\x20user\x20edits\x20—\x20diff\x20vs\x20canonical:\x20'+h});}return a;}const cache=new Map();export function reloadTemplates(){cache['clear'](),seeded=![];}export function loadAndValidate(a){const b=readFileSync(a,'utf-8');let c;try{c=parseTemplateFile(b);}catch(f){throw new Error('template\x20\x27'+a+'\x27\x20failed\x20to\x20parse:\x20'+f['message']);}const d=TemplateFrontmatterSchema['safeParse'](c['frontmatter']);if(!d['success']){const g=d['error']['issues']['map'](h=>(h['path']['join']('.')||'<root>')+':\x20'+h['message'])['join'](';\x20');throw new Error('template\x20\x27'+a+'\x27\x20failed\x20validation:\x20'+g);}const e=validateAllocatorRows(d['data']);if(e['length']>0x0)throw new Error('template\x20\x27'+a+'\x27\x20failed\x20allocator-row\x20validation:\x20'+e['join'](';\x20'));return{...d['data'],'body':c['body'],'source_path':a};}function templateFilesOnDisk(a){const b=[];if(!existsSync(a))return b;for(const c of readdirSync(a,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(a,c['name'],TEMPLATES_SUBDIR);if(!existsSync(d))continue;for(const e of readdirSync(d,{'withFileTypes':!![]})){if(e['isFile']()&&e['name']['endsWith']('.md'))b['push'](join(d,e['name']));}}return b['sort']();}export function listTemplates(){!seeded&&(seedBuiltinTemplates(),seeded=!![]);const a=resolveTemplatesDir(),b=[],c=[],d=new Set();for(const e of templateFilesOnDisk(a)){d['add'](e);try{const f=statSync(e)['mtimeMs'],g=cache['get'](e);if(g&&g['mtimeMs']===f){b['push'](g['template']);continue;}const h=loadAndValidate(e);cache['set'](e,{'mtimeMs':f,'template':h}),b['push'](h);}catch(i){cache['delete'](e),c['push'](i['message']);}}for(const j of[...cache['keys']()]){if(!d['has'](j))cache['delete'](j);}return b['sort']((k,l)=>k['id']['localeCompare'](l['id'])),{'templates':b,'errors':c};}export function getTemplate(a){return listTemplates()['templates']['find'](b=>b['id']===a);}export function getTemplatesByIndustry(a){return listTemplates()['templates']['filter'](b=>b['industry']===a);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as
|
|
1
|
+
import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as a261a}from'./machine-templates.js';import{SERVICE_TEMPLATES,fillServiceTemplate}from'./service-templates.js';import{ORDER_TEMPLATES,fillTemplate as a261b}from'./order-templates.js';import{PROGRESS_TEMPLATES,fillProgressTemplate}from'./progress-templates.js';import{ARBITRATION_TEMPLATES,fillTemplate as a261c}from'./arbitration-templates.js';import{TREASURY_TEMPLATES,fillTemplate as a261d}from'./treasury-templates.js';import{PERMISSION_TEMPLATES,fillTemplate as a261e}from'./permission-templates.js';import{PASSPORT_TEMPLATES,fillTemplate as a261f}from'./passport-templates.js';import{ALLOCATION_TEMPLATES,fillTemplate as a261g}from'./allocation-templates.js';import{CONTACT_TEMPLATES,fillTemplate as a261h}from'./contact-templates.js';import{REWARD_TEMPLATES}from'./reward-templates.js';export const TEMPLATE_REGISTRY_VERSION=0x1;export const TEMPLATE_OBJECT_TYPES=['guard','machine','service','order','progress','arbitration','treasury','permission','passport','allocation','reward','contact'];function normalizeParam(a){return{'name':a['name'],'type':a['type'],'description':a['description']??'','required':a['required'],...a['default']!==undefined?{'default':a['default']}:{},...a['constraint']!==undefined?{'constraint':a['constraint']}:{}};}function guardMeta(a){return{'id':a['id'],'object_type':'guard','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function machineMeta(a){return{'id':a['id'],'object_type':'machine','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function bodyMeta(a,b,c,d){return{'id':a['id'],'object_type':b,'name':a['name'],'description':a['description'],'scenes':c,'industries':d,'instantiable':!![],'parameters':a['params']['map'](e=>normalizeParam(e))};}function rewardMeta(a){return{'id':a['type'],'object_type':'reward','name':a['name'],'description':a['description'],'scenes':[],'industries':[],'instantiable':![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}let REGISTRY=null,ID_COLLISIONS=[];function buildRegistry(){const a=new Map(),b=[],c=d=>{if(a['has'](d['meta']['id'])){b['push'](d['meta']['id']);return;}a['set'](d['meta']['id'],d);};for(const d of GUARD_TEMPLATES){c({'meta':guardMeta(d),'raw':d,'notes':d['creation_notes']});}for(const e of MACHINE_TEMPLATES){c({'meta':machineMeta(e),'raw':e,'notes':e['creation_notes']});}for(const f of SERVICE_TEMPLATES){c({'meta':bodyMeta(f,'service',f['applicable_scenes'],f['industry_tags']),'raw':f,'notes':f['notes']});}for(const g of ORDER_TEMPLATES){c({'meta':bodyMeta(g,'order',g['applicable_scenes'],g['industry_tags']),'raw':g,'notes':g['notes']});}for(const h of PROGRESS_TEMPLATES){c({'meta':bodyMeta(h,'progress',h['applicable_scenes'],h['industry_tags']),'raw':h,'notes':h['notes']});}for(const i of ARBITRATION_TEMPLATES){c({'meta':bodyMeta(i,'arbitration',i['applicable_scenes'],i['industry_tags']),'raw':i,'notes':i['notes']});}for(const j of TREASURY_TEMPLATES){c({'meta':bodyMeta(j,'treasury',j['applicable_scenes'],j['industry_tags']),'raw':j,'notes':j['notes']});}for(const k of PERMISSION_TEMPLATES){c({'meta':bodyMeta(k,'permission',k['applicable_scenes'],k['industry_tags']),'raw':k,'notes':k['notes']});}for(const l of PASSPORT_TEMPLATES){c({'meta':bodyMeta(l,'passport',l['applicable_scenarios'],l['industry_tags']),'raw':l,'notes':l['notes']});}for(const m of ALLOCATION_TEMPLATES){c({'meta':bodyMeta(m,'allocation',m['applicable_scenes'],m['industry_tags']),'raw':m,'notes':m['notes']});}for(const n of REWARD_TEMPLATES){c({'meta':rewardMeta(n),'raw':n,'guidance':{'guardCondition':n['guardCondition'],'amountRange':n['amountRange'],'allocationStrategy':n['allocationStrategy'],'example':n['example'],'relevantGuardOps':n['relevantGuardOps']}});}for(const o of CONTACT_TEMPLATES){c({'meta':bodyMeta(o,'contact',o['applicable_scenes'],o['industry_tags']),'raw':o,'notes':o['notes']});}return ID_COLLISIONS=b,a;}function registry(){return!REGISTRY&&(REGISTRY=buildRegistry()),REGISTRY;}export function getTemplateIdCollisions(){return registry(),ID_COLLISIONS;}export function getTemplateCounts(){const a=Object['fromEntries'](TEMPLATE_OBJECT_TYPES['map'](b=>[b,0x0]));for(const b of registry()['values']()){a[b['meta']['object_type']]+=0x1;}return a;}export function listTemplates(a){const b=[...registry()['values']()]['map'](c=>c['meta']);return a?b['filter'](c=>c['object_type']===a):b;}export function getTemplateDetail(a){const b=registry()['get'](a);if(!b)return null;return{...b['meta'],'raw':b['raw'],...b['notes']?{'notes':b['notes']}:{},...b['guidance']?{'guidance':b['guidance']}:{}};}export function findTemplateObjectType(a){return registry()['get'](a)?.['meta']['object_type']??null;}export function instantiateTemplate(a,b){const c=registry()['get'](a);if(!c)return{'ok':![],'object_type':null,'template_id':a,'error':'Template\x20not\x20found:\x20'+a+'.\x20Use\x20get_templates\x20without\x20\x27template\x27\x20to\x20list\x20all\x20template\x20ids.'};const d=c['meta']['object_type'];if(!c['meta']['instantiable'])return{'ok':![],'object_type':d,'template_id':a,'error':'Reward\x20templates\x20are\x20guidance-only\x20(prose\x20guard\x20conditions)\x20and\x20cannot\x20be\x20'+'instantiated\x20into\x20executable\x20JSON.\x20Use\x20the\x20guidance\x20payload\x20to\x20design\x20the\x20'+'Reward\x20+\x20Guard\x20manually.','guidance':c['guidance']};switch(d){case'guard':{const e=fillGuardTemplate(a,b);if(!e['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':e['error'],...e['missing']?{'missing_params':e['missing']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'table':e['table'],'root':e['root']},...c['notes']?{'notes':c['notes']}:{}};}case'machine':{const f=a261a(a,b);if(!f['success'])return{'ok':![],'object_type':d,'template_id':a,'error':f['validation_errors']?.['join'](';\x20')??'Machine\x20template\x20fill\x20failed',...f['missing_params']?{'missing_params':f['missing_params']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'nodes':f['filled_nodes'],'pairs':f['filled_pairs']},...c['notes']?{'notes':c['notes']}:{}};}case'service':{const g=fillServiceTemplate(a,b);if(!g['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':g['error']??'Service\x20template\x20fill\x20failed',...g['missing_required']?{'missing_params':g['missing_required']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':g['body'],...c['notes']?{'notes':c['notes']}:{}};}case'order':case'arbitration':case'treasury':case'permission':case'passport':case'allocation':case'progress':case'contact':{const h=fillBodyTemplate(d,a,b);if(!h['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':h['error']};return{'ok':!![],'object_type':d,'template_id':a,'body':h['body'],...c['notes']?{'notes':c['notes']}:{}};}default:return{'ok':![],'object_type':d,'template_id':a,'error':'Instantiation\x20not\x20supported\x20for\x20object_type\x20\x27'+d+'\x27'};}}function fillBodyTemplate(a,b,c){switch(a){case'order':return a261b(b,c);case'arbitration':return a261c(b,c);case'treasury':return a261d(b,c);case'permission':return a261e(b,c);case'passport':return a261f(b,c);case'allocation':return a261g(b,c);case'progress':return fillProgressTemplate(b,c);case'contact':return a261h(b,c);default:return{'ok':![],'error':'No\x20body-template\x20fill\x20for\x20\x27'+a+'\x27'};}}
|