@wowok/agent-mcp 3.0.3 → 3.0.4

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.
Files changed (88) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/knowledge/event-semantics.js +1 -1
  3. package/dist/knowledge/guard-puzzle.js +1 -1
  4. package/dist/knowledge/safety-rules.js +1 -1
  5. package/dist/knowledge/service-ledger.js +1 -1
  6. package/dist/knowledge/tools-reference.js +1 -1
  7. package/dist/safety/confirm-gate.js +1 -1
  8. package/dist/schema/call/allocation.d.ts +5 -0
  9. package/dist/schema/call/arbitration.d.ts +5 -0
  10. package/dist/schema/call/base.d.ts +5 -0
  11. package/dist/schema/call/base.js +1 -1
  12. package/dist/schema/call/bridge.d.ts +25 -0
  13. package/dist/schema/call/contact.d.ts +5 -0
  14. package/dist/schema/call/demand.d.ts +5 -0
  15. package/dist/schema/call/guard.d.ts +15 -0
  16. package/dist/schema/call/machine.d.ts +10 -0
  17. package/dist/schema/call/order.d.ts +5 -0
  18. package/dist/schema/call/payment.d.ts +5 -0
  19. package/dist/schema/call/permission.d.ts +5 -0
  20. package/dist/schema/call/personal.d.ts +5 -0
  21. package/dist/schema/call/progress.d.ts +5 -0
  22. package/dist/schema/call/proof.d.ts +10 -0
  23. package/dist/schema/call/repository.d.ts +5 -0
  24. package/dist/schema/call/reward.d.ts +5 -0
  25. package/dist/schema/call/service.d.ts +5 -0
  26. package/dist/schema/call/treasury.d.ts +5 -0
  27. package/dist/schema/common/index.js +1 -1
  28. package/dist/schema/index.d.ts +1 -0
  29. package/dist/schema/index.js +1 -1
  30. package/dist/schema/interaction/index.d.ts +34 -0
  31. package/dist/schema/interaction/index.js +1 -0
  32. package/dist/schema/local/index.js +1 -1
  33. package/dist/schema/messenger/index.d.ts +6 -0
  34. package/dist/schema/messenger/index.js +1 -1
  35. package/dist/schema/operations.d.ts +90 -0
  36. package/dist/schema/operations.js +1 -1
  37. package/dist/schema/query/index.js +1 -1
  38. package/dist/schema/schema-version.js +1 -1
  39. package/dist/schema-query-impl/index.js +1 -1
  40. package/dist/schemas/ask_user.output.json +54 -0
  41. package/dist/schemas/ask_user.schema.json +78 -0
  42. package/dist/schemas/bridge_operation.schema.json +50 -5
  43. package/dist/schemas/guard2file.schema.json +10 -1
  44. package/dist/schemas/index.json +7 -1
  45. package/dist/schemas/machineNode2file.schema.json +10 -1
  46. package/dist/schemas/messenger_operation.output.json +8 -0
  47. package/dist/schemas/messenger_operation.schema.json +8 -0
  48. package/dist/schemas/onchain_events.output.json +2 -2
  49. package/dist/schemas/onchain_operations.schema.json +180 -18
  50. package/dist/schemas/onchain_operations_allocation.schema.json +10 -1
  51. package/dist/schemas/onchain_operations_arbitration.schema.json +10 -1
  52. package/dist/schemas/onchain_operations_contact.schema.json +10 -1
  53. package/dist/schemas/onchain_operations_demand.schema.json +10 -1
  54. package/dist/schemas/onchain_operations_gen_passport.schema.json +10 -1
  55. package/dist/schemas/onchain_operations_gen_proof.schema.json +10 -1
  56. package/dist/schemas/onchain_operations_guard.schema.json +10 -1
  57. package/dist/schemas/onchain_operations_machine.schema.json +10 -1
  58. package/dist/schemas/onchain_operations_order.schema.json +10 -1
  59. package/dist/schemas/onchain_operations_payment.schema.json +10 -1
  60. package/dist/schemas/onchain_operations_permission.schema.json +10 -1
  61. package/dist/schemas/onchain_operations_personal.schema.json +10 -1
  62. package/dist/schemas/onchain_operations_progress.schema.json +10 -1
  63. package/dist/schemas/onchain_operations_proof.schema.json +10 -1
  64. package/dist/schemas/onchain_operations_repository.schema.json +10 -1
  65. package/dist/schemas/onchain_operations_reward.schema.json +10 -1
  66. package/dist/schemas/onchain_operations_service.schema.json +10 -1
  67. package/dist/schemas/onchain_operations_treasury.schema.json +10 -1
  68. package/dist/schemas/query_toolkit.schema.json +1 -1
  69. package/dist/tools/handlers/ask-user.d.ts +3 -0
  70. package/dist/tools/handlers/ask-user.js +1 -0
  71. package/dist/tools/handlers/config.js +1 -1
  72. package/dist/tools/handlers/messenger.js +1 -1
  73. package/dist/tools/handlers/onchain.js +1 -1
  74. package/dist/tools/index.d.ts +2 -2
  75. package/dist/tools/index.js +1 -1
  76. package/dist/tools/registry/bridge.js +1 -1
  77. package/dist/tools/registry/business.js +1 -1
  78. package/dist/tools/registry/interaction.d.ts +2 -0
  79. package/dist/tools/registry/interaction.js +1 -0
  80. package/dist/tools/registry/local.js +1 -1
  81. package/dist/tools/registry/monitor.js +1 -1
  82. package/dist/tools/registry/onchain.js +1 -1
  83. package/dist/tools/registry/query.js +1 -1
  84. package/dist/tools/shared.js +1 -1
  85. package/dist/tools/types.d.ts +7 -1
  86. package/dist/tools/wrap.d.ts +3 -3
  87. package/dist/tools/wrap.js +1 -1
  88. package/package.json +2 -2
@@ -22,10 +22,16 @@ export interface ToolDispatchResult {
22
22
  text: string;
23
23
  }[];
24
24
  structuredContent: Record<string, unknown> | undefined;
25
+ resultType?: "input_required";
26
+ inputRequests?: Record<string, unknown>;
27
+ requestState?: string;
28
+ }
29
+ export interface ToolRequestContext {
30
+ inputResponses?: Record<string, unknown>;
25
31
  }
26
32
  export interface ToolEntry {
27
33
  name: string;
28
- handler: (args: unknown) => Promise<ToolDispatchResult>;
34
+ handler: (args: unknown, req?: ToolRequestContext) => Promise<ToolDispatchResult>;
29
35
  config: ToolConfig;
30
36
  errorShapeBuilder?: ErrorShapeBuilder;
31
37
  timeoutMs?: number;
@@ -1,6 +1,6 @@
1
- import type { ErrorShapeBuilder, ToolDispatchResult } from "./types.js";
1
+ import type { ErrorShapeBuilder, ToolDispatchResult, ToolRequestContext } from "./types.js";
2
2
  export declare function withTimeout<T>(promise: Promise<T>, timeoutMs?: number, operationName?: string): Promise<T>;
3
- export declare function wrapHandlerWithErrorShape(handler: (args: unknown) => Promise<ToolDispatchResult>, timeoutMs: number, toolName: string, errorShapeBuilder?: ErrorShapeBuilder): (args: unknown) => Promise<ToolDispatchResult>;
3
+ export declare function wrapHandlerWithErrorShape(handler: (args: unknown, req?: import("./types.js").ToolRequestContext) => Promise<ToolDispatchResult>, timeoutMs: number, toolName: string, errorShapeBuilder?: ErrorShapeBuilder): (args: unknown, req?: import("./types.js").ToolRequestContext) => Promise<ToolDispatchResult>;
4
4
  export declare const statusErrorShape: ErrorShapeBuilder;
5
5
  export declare const operationErrorShape: ErrorShapeBuilder;
6
6
  export declare const strictStatusErrorShape: ErrorShapeBuilder;
@@ -11,4 +11,4 @@ export interface HarnessHookContext {
11
11
  result?: ToolDispatchResult;
12
12
  error?: unknown;
13
13
  }
14
- export declare function dispatchWithHarness(handler: (args: unknown) => Promise<ToolDispatchResult>, toolName: string): (args: unknown) => Promise<ToolDispatchResult>;
14
+ export declare function dispatchWithHarness(handler: (args: unknown, req?: ToolRequestContext) => Promise<ToolDispatchResult>, toolName: string): (args: unknown, req?: ToolRequestContext) => Promise<ToolDispatchResult>;
@@ -1 +1 @@
1
- import{classifyError,buildDataSemantic}from'../schema/call/semantic.js';import{buildClassifiedErrorResult}from'./shared.js';import{shouldRunLightHooks,shouldRunHeavyHooks,recordOperationFailure,recordCriticalRisk,recordCriticalOperation,recordSubstepFailure}from'../harness/auto-escalation.js';import{getHarnessTier,setHarnessTier,isEnabled}from'../config/runtime.js';import{getHarness}from'../harness/index.js';import{recordOperationOutcome}from'../experience/index.js';import{recordIndustrySignal}from'../knowledge/flywheel-loop.js';import{getStageCache}from'../playbooks/service-build/index.js';import{SERVICE_BUILD_STAGES}from'../playbooks/service-build/process.js';import{extractAmount,getAmountThreshold,formatAmount}from'../knowledge/safety-rules.js';function stageIndexOf(a){const b=SERVICE_BUILD_STAGES['indexOf'](a);return b>=0x0?b:0x0;}export function withTimeout(a,b=0x7530,c='operation'){let d;return Promise['race']([a['finally'](()=>{if(d)clearTimeout(d);}),new Promise((e,f)=>{d=setTimeout(()=>{let g='';c['includes']('messenger')&&(g='\x20This\x20is\x20a\x20messenger\x20network\x20operation.\x20Possible\x20causes:\x20'+'(1)\x20messenger\x20server\x20(https://messenger.wowok.net)\x20unreachable,\x20'+'(2)\x20no\x20messenger-enabled\x20account\x20configured\x20(use\x20account_operation\x20to\x20set\x20messenger\x20name),\x20'+'(3)\x20network\x20connectivity\x20issue.\x20'+'Ensure\x20you\x20have\x20a\x20messenger-enabled\x20account\x20and\x20the\x20server\x20is\x20reachable.'),f(new Error('Operation\x20\x27'+c+'\x27\x20timed\x20out\x20after\x20'+b+'ms.'+g));},b);})]);}export function wrapHandlerWithErrorShape(a,b,c,d){return async e=>{try{return await withTimeout(a(e),b,c);}catch(f){if(d){const g=f instanceof Error?f['message']:String(f),h=classifyError(g),i={'operation_type':c,'data':e},j=d(g,h,i);return{'content':[{'type':'text','text':'Error:\x20'+g}],'structuredContent':j};}throw f;}};}export const statusErrorShape=(a,b,c)=>({'result':buildClassifiedErrorResult({'status':'error'},a,b),'semantic':buildDataSemantic(undefined,c,!![],a)});export const operationErrorShape=(a,b,c)=>({'result':buildClassifiedErrorResult({'operation':'error'},a,b),'semantic':buildDataSemantic(undefined,c,!![],a)});export const strictStatusErrorShape=(a,b,c)=>({'result':{'status':'error','error':a}});function checkProjectStage(a,b,c){const d={'analyze_intent':'puzzle','aggregate_risks':'risk','trace_substeps':'substeps'},e=d[a];if(!e)return null;const f=getStageCache(b,c);if(!f){if(a==='analyze_intent')return null;return'project_stage:\x20calling\x20\x27'+a+'\x27\x20before\x20\x27analyze_intent\x27\x20—\x20recommend\x20calling\x20analyze_intent\x20first\x20for\x20project\x20\x27'+b+':'+c+'\x27';}if(stageIndexOf(f['stage'])<stageIndexOf(e)-0x1)return'project_stage:\x20calling\x20\x27'+a+'\x27\x20(stage\x20\x27'+e+'\x27)\x20but\x20project\x20is\x20at\x20stage\x20\x27'+f['stage']+'\x27\x20—\x20recommend\x20completing\x20prior\x20stages\x20first\x20for\x20\x27'+b+':'+c+'\x27';return null;}export function dispatchWithHarness(a,b){return async d=>{const f=[],g=getHarness(),h=shouldRunLightHooks(),i=shouldRunHeavyHooks(),j=isPublishOperation(b,d),k=isSignOperation(b,d),l=getHarnessTier();let m;if(h)try{const o=extractOperationType(b,d),p=extractIntent(b,d);o&&p&&(m=g['expect'](b,p,o,extractData(d)));}catch(q){f['push']('pre_call\x20hook\x20failed:\x20'+(q instanceof Error?q['message']:String(q)));}if(b==='goal_operation'&&h)try{const r=d,s=r?.['action'],t=r?.['project'],u=r?.['version'];if(s&&t&&u){const v=checkProjectStage(s,t,u);v&&f['push'](v);}}catch{}j&&l==='lightweight'&&(setHarnessTier('full'),f['push']('pre_publish:\x20tier\x20forced\x20to\x20full\x20for\x20publish-class\x20operation\x20(GLM5-21\x20§3.3)'));if(j&&l!=='off')try{const x=runPrePublishChecks(b,d);f['push'](...x['warnings']);if(x['critical']['length']>0x0){for(const y of x['critical']){const z=recordCriticalRisk(y);if(z)f['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+z['reason']);}return buildHarnessBlockResult('pre_publish','Publish\x20BLOCKED\x20by\x20Harness\x20pre-publish\x20gate\x20(GLM5-21\x20V6):\x20'+(x['critical']['length']+'\x20CRITICAL\x20risk(s)\x20must\x20be\x20resolved\x20before\x20publish.'),x['critical'],x['warnings'],'immutable_violation','Fix\x20the\x20CRITICAL\x20risks\x20listed\x20in\x20the\x20message\x20(e.g.\x20rename\x20dispute/refund\x20nodes\x20per\x20R-M1-11,\x20add\x20the\x20entry\x20pair\x20prev_node=\x22\x22),\x20then\x20retry\x20publish.\x20Nodes/pairs/forwards\x20are\x20immutable\x20after\x20publish\x20—\x20verify\x20via\x20machineNode2file\x20first.');}}catch(A){f['push']('pre_publish\x20hook\x20failed:\x20'+(A instanceof Error?A['message']:String(A)));}if(k&&i)try{const B=extractData(d),C=B?extractAmount(B):null;if(C!==null){const D=getAmountThreshold();let E=null;try{E=BigInt(C);}catch{E=null;}if(E!==null&&E>D)return buildHarnessBlockResult('pre_sign','Sign\x20BLOCKED\x20by\x20Harness\x20pre-sign\x20gate\x20(GLM5-21\x20V7):\x20amount\x20'+formatAmount(E)+'\x20WOW\x20exceeds\x20the\x20full-tier\x20threshold\x20'+formatAmount(D)+'\x20WOW.',['amount\x20'+C+'\x20(smallest\x20unit)\x20>\x20threshold\x20'+D['toString']()+'\x20(smallest\x20unit)'],[],'invalid_parameter','Raise\x20WOWOK_AMOUNT_THRESHOLD\x20to\x20match\x20the\x20intended\x20amount,\x20split\x20the\x20transaction,\x20or\x20reset\x20the\x20harness\x20tier\x20to\x20lightweight\x20(config_operation)\x20after\x20explicit\x20user\x20confirmation.');}}catch(F){f['push']('pre_sign\x20hook\x20failed:\x20'+(F instanceof Error?F['message']:String(F)));}let n;try{n=await a(d);}catch(G){const H=G instanceof Error?G['message']:String(G),I=recordOperationFailure(b,H);I&&f['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+I['reason']);if(b==='onchain_operations')try{const J=classifyError(H,G);if(!J['retryable']&&J['error_code']!=='unknown'){const K=recordCriticalOperation(b,J['error_code']);if(K)f['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+K['reason']);}}catch{}throw G;}if(h&&m)try{if(n?.['structuredContent']){const L=buildVerifyInput(m,n),M=g['verify'](L);if(M['status']==='fail')f['push']('Harness\x20verify\x20FAIL:\x20'+M['summary']);else M['status']==='warn'&&f['push']('Harness\x20verify\x20WARN:\x20'+M['summary']);}}catch(N){f['push']('post_call\x20hook\x20failed:\x20'+(N instanceof Error?N['message']:String(N)));}if(b==='onchain_operations')try{if(classifyOutcome(n)==='failed'){const O=extractErrorCode(n)??'',P=classifyError(O);if(!P['retryable']&&P['error_code']!=='unknown'){const Q=recordCriticalOperation(b,P['error_code']);if(Q)f['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+Q['reason']);}}}catch{}if(h){const R=extractIntent(b,d)??b;try{const S=classifyOutcome(n);if(S==='failed'){const T=extractErrorCode(n)??'',U=classifyError(T),V=g['recover'](U['error_code'],R,{'operation_type':b,'data':extractData(d)});f['push']('Harness\x20recover:\x20strategy='+V['strategy']+('\x20(attempt\x20'+V['current_attempt']+'/'+V['max_attempts']+')')+(V['should_retry']?'\x20—\x20retryable':'\x20—\x20do\x20NOT\x20retry\x20blindly')+(V['user_prompt']?'\x20—\x20'+V['user_prompt']:'\x20—\x20'+V['detail']));}else S==='success'&&g['resetRecovery'](R);}catch(W){f['push']('recover\x20hook\x20failed:\x20'+(W instanceof Error?W['message']:String(W)));}}if(b==='goal_operation')try{const X=d?.['action'];if(X==='trace_substeps'){const Y=extractCriticalFindingCount(n);if(Y>0x0){const Z=recordSubstepFailure(String(X)+':\x20'+Y+'\x20critical\x20finding(s)');if(Z)f['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+Z['reason']);}}}catch{}if(isWriteClassTool(b)&&!SEMANTIC_RECORDED_TOOLS['has'](b))try{const a0=extractOperationType(b,d)??b,a1=extractIntent(b,d)??b,a2=extractData(d)??d,a3=classifyOutcome(n),a4=extractErrorCode(n),a5=isEnabled('experience_layer');if(a5)recordOperationOutcome(a0,a2,a1,a3,a4);else{const a6=extractIndustry(d);a6&&isEnabled('industry_evolution')&&recordIndustrySignal(a6,{'type':a0},{'success':a3==='success','error_code':a4});}}catch(a7){f['push']('signal\x20collection\x20failed:\x20'+(a7 instanceof Error?a7['message']:String(a7)));}if(f['length']>0x0){if(n?.['structuredContent']){const a8=n['structuredContent'],a9=a8['semantic'];if(a9){const aa=Array['isArray'](a9['warnings'])?a9['warnings']:[];a9['warnings']=[...aa,...f];}else for(const ab of f){console['warn']('[harness]\x20'+ab);}}else for(const ac of f){console['warn']('[harness]\x20'+ac);}}return n;};}function isPublishOperation(a,b){if(a!=='onchain_operations')return![];const c=extractOperationType(a,b);if(c!=='service'&&c!=='machine')return![];const d=extractData(b);return d?.['publish']===!![]||d?.['bPublished']===!![];}function isSignOperation(a,b){if(a==='wip_file'){const c=b?.['operation_type'];return c==='sign';}return a==='onchain_operations';}function extractOperationType(a,b){if(!b||typeof b!=='object')return undefined;const c=b;if(a==='onchain_operations')return typeof c['operation_type']==='string'?c['operation_type']:undefined;if(a==='goal_operation'||a==='industry_pack_operation')return typeof c['action']==='string'?c['action']:undefined;return typeof c['operation_type']==='string'?c['operation_type']:undefined;}function extractIntent(a,b){if(!b||typeof b!=='object')return undefined;const c=b;if((a==='goal_operation'||a==='industry_pack_operation')&&typeof c['action']==='string')return a+':'+c['action'];const d=c['operation_type'];if(typeof d==='string')return a+':'+d;return a;}function extractData(a){if(!a||typeof a!=='object')return undefined;const b=a,c=b['data'];return c&&typeof c==='object'?c:undefined;}function buildVerifyInput(a,b){const c=b['structuredContent']??{},d=c['semantic'];return{'expected':a,'actual':{'result_type':typeof c['result_type']==='string'?c['result_type']:undefined,'semantic':d,'error_code':typeof c['error_code']==='string'?c['error_code']:undefined,'error':typeof c['error']==='string'?c['error']:undefined}};}const WRITE_CLASS_TOOLS=new Set(['onchain_operations','goal_operation','industry_pack_operation','wip_file','messenger_operation','bridge_operation']),SEMANTIC_RECORDED_TOOLS=new Set(['onchain_operations','bridge_operation']);function isWriteClassTool(a){return WRITE_CLASS_TOOLS['has'](a);}function classifyOutcome(a){if(!a?.['structuredContent'])return'failed';const b=a['structuredContent'],c=typeof b['status']==='string'?b['status']:typeof b['result_type']==='string'?b['result_type']:'';if(c==='error'||c==='failed')return'failed';if(c==='partial')return'partial';return'success';}function extractErrorCode(a){if(!a?.['structuredContent'])return undefined;const b=a['structuredContent'];if(typeof b['error_code']==='string')return b['error_code'];const c=b['error'];if(typeof c==='string')return c;if(c&&typeof c==='object'){const d=c['code'];if(typeof d==='string')return d;}return undefined;}function extractIndustry(a){if(!a||typeof a!=='object')return undefined;const b=a;if(typeof b['industry']==='string')return b['industry'];const c=b['data'];if(c&&typeof c==='object'){const e=c;if(typeof e['industry']==='string')return e['industry'];}return undefined;}const ANTI_PATTERN_NODE_REGEX=/(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;function runPrePublishChecks(a,b){const c=[],d=[],e=extractOperationType(a,b),g=extractData(b)??{};if(e==='machine'){const h=g['node'],i=Array['isArray'](h)?h:Array['isArray'](h?.['nodes'])?h['nodes']:[];if(i['length']>0x0){for(const l of i){const m=typeof l?.['name']==='string'?l['name']:'';m&&ANTI_PATTERN_NODE_REGEX['test'](m)&&c['push']('R-M1-11:\x20machine\x20node\x20\x22'+m+'\x22\x20models\x20dispute/refund\x20flow\x20—\x20'+'refunds\x20must\x20route\x20via\x20an\x20Allocator\x20triggered\x20by\x20business\x20states,\x20'+'disputes\x20via\x20the\x20separate\x20Arbitration\x20object\x20(off-Machine)');}const j=new Set();for(const o of i){const q=typeof o?.['name']==='string'?o['name']:'';if(!q)continue;j['has'](q)&&c['push']('MC-C-04:\x20duplicate\x20machine\x20node\x20name\x20\x22'+q+'\x22\x20—\x20on-chain\x20will\x20reject\x20the\x20publish\x20transaction'),j['add'](q);}const k=i['some'](r=>Array['isArray'](r?.['pairs'])&&r['pairs']['some'](s=>s?.['prev_node']===''));!k&&c['push']('Machine\x20has\x20no\x20entry\x20pair\x20(prev_node=\x22\x22)\x20—\x20Progress\x20can\x20never\x20advance\x20'+'from\x20the\x20initial\x20state;\x20orders\x20are\x20permanently\x20stuck');for(const r of i){const s=typeof r?.['name']==='string'?r['name']:'?';for(const t of r?.['pairs']??[]){for(const u of t?.['forwards']??[]){const v=u?.['namedOperator']!==undefined&&u?.['namedOperator']!==null,w=u?.['permissionIndex']!==undefined&&u?.['permissionIndex']!==null;!v&&!w&&d['push']('pre_publish:\x20node\x20\x22'+s+'\x22\x20forward\x20\x22'+String(u?.['name']??'?')+'\x22\x20has\x20neither\x20namedOperator\x20nor\x20permissionIndex\x20—\x20no\x20one\x20can\x20advance\x20it');}}}}else d['push']('pre_publish:\x20publishing\x20machine\x20without\x20inline\x20node\x20data\x20—\x20topology\x20not\x20verifiable\x20in\x20this\x20call;\x20'+'verify\x20nodes/pairs/forwards\x20via\x20machineNode2file\x20BEFORE\x20publish\x20(immutable\x20after\x20publish,\x20IMMUT-001)');d['push']('pre_publish:\x20machine\x20nodes/pairs/forwards\x20become\x20immutable\x20after\x20publish\x20(IMMUT-001)');}return e==='service'&&(d['push']('pre_publish:\x20service\x20machine/order_allocators/arbitrations\x20become\x20immutable\x20after\x20publish\x20(IMMUT-002);\x20sales\x20remains\x20modifiable'),g['machine']===undefined&&d['push']('pre_publish:\x20\x27machine\x27\x20not\x20set\x20in\x20this\x20call\x20—\x20if\x20the\x20service\x20was\x20never\x20bound\x20to\x20a\x20published\x20machine,\x20'+'it\x20cannot\x20process\x20orders\x20and\x20CANNOT\x20be\x20fixed\x20after\x20publish'),g['order_allocators']===undefined&&d['push']('pre_publish:\x20\x27order_allocators\x27\x20not\x20set\x20in\x20this\x20call\x20—\x20immutable\x20after\x20publish;\x20'+'orders\x20will\x20have\x20no\x20fund\x20distribution\x20if\x20never\x20configured')),{'critical':c,'warnings':d};}function buildHarnessBlockResult(a,b,c,d,e,f){const g=[...c['map'](i=>'CRITICAL:\x20'+i),...d['map'](i=>'WARN:\x20'+i)]['join']('\x0a'),h='Error:\x20'+b+(g?'\x0a'+g:'')+'\x0aRecovery:\x20'+f;return{'content':[{'type':'text','text':h}],'structuredContent':{'result':{'type':'error','error':b+'\x20[gate='+a+']','error_code':e,'retryable':![],'recovery_hint':f},'message':h}};}function extractCriticalFindingCount(a){const b=a?.['structuredContent'];if(!b)return 0x0;const c=b['semantic'],d=c?.['summary'];if(typeof d?.['critical_count']==='number'&&d['critical_count']>0x0)return d['critical_count'];const e=b['findings']??c?.['findings'];if(Array['isArray'](e))return e['filter'](h=>h?.['severity']==='error')['length'];const f=a?.['content']?.['map'](h=>'text'in h?h['text']:'')['join']('\x0a')??'',g=f['match'](/\[AUDIT ERROR\]/g);return g?g['length']:0x0;}
1
+ import{classifyError,buildDataSemantic}from'../schema/call/semantic.js';import{buildClassifiedErrorResult}from'./shared.js';import{shouldRunLightHooks,shouldRunHeavyHooks,recordOperationFailure,recordCriticalRisk,recordCriticalOperation,recordSubstepFailure}from'../harness/auto-escalation.js';import{getHarnessTier,setHarnessTier,isEnabled}from'../config/runtime.js';import{getHarness}from'../harness/index.js';import{recordOperationOutcome}from'../experience/index.js';import{recordIndustrySignal}from'../knowledge/flywheel-loop.js';import{getStageCache}from'../playbooks/service-build/index.js';import{SERVICE_BUILD_STAGES}from'../playbooks/service-build/process.js';import{extractAmount,getAmountThreshold,formatAmount}from'../knowledge/safety-rules.js';function stageIndexOf(a){const b=SERVICE_BUILD_STAGES['indexOf'](a);return b>=0x0?b:0x0;}export function withTimeout(a,b=0x7530,c='operation'){let d;return Promise['race']([a['finally'](()=>{if(d)clearTimeout(d);}),new Promise((e,f)=>{d=setTimeout(()=>{let g='';if(c['includes']('messenger'))g='\x20This\x20is\x20a\x20messenger\x20network\x20operation.\x20Possible\x20causes:\x20'+'(1)\x20messenger\x20server\x20(https://messenger.wowok.net)\x20unreachable,\x20'+'(2)\x20no\x20messenger-enabled\x20account\x20configured\x20(use\x20account_operation\x20to\x20set\x20messenger\x20name),\x20'+'(3)\x20network\x20connectivity\x20issue.\x20'+'Ensure\x20you\x20have\x20a\x20messenger-enabled\x20account\x20and\x20the\x20server\x20is\x20reachable.';else(c['includes']('onchain')||c['includes']('account_operation')||c['includes']('bridge')||c['includes']('workflow')||c['includes']('keeper')||c['includes']('wowok'))&&(g='\x20This\x20tool\x20may\x20submit\x20an\x20ON-CHAIN\x20transaction.\x20The\x20transaction\x20was\x20NOT\x20cancelled\x20'+'by\x20this\x20timeout\x20—\x20it\x20may\x20already\x20be\x20submitted\x20and\x20still\x20finalize\x20on-chain.\x20'+'DO\x20NOT\x20blindly\x20retry\x20(risk\x20of\x20duplicate\x20operations).\x20First\x20verify:\x20'+'(1)\x20if\x20the\x20error\x20above\x20carries\x20a\x20tx\x20digest,\x20check\x20it\x20via\x20query_toolkit\x20'+'(query_type=\x27onchain_transaction\x27);\x20(2)\x20otherwise\x20re-query\x20the\x20target\x20object\x20state\x20'+'(query_toolkit\x20onchain_objects)\x20and\x20only\x20retry\x20if\x20the\x20operation\x20truly\x20did\x20not\x20land.');f(new Error('Operation\x20\x27'+c+'\x27\x20timed\x20out\x20after\x20'+b+'ms.'+g));},b);})]);}export function wrapHandlerWithErrorShape(a,b,c,d){return async(e,f)=>{try{return await withTimeout(a(e,f),b,c);}catch(g){if(d){const h=g instanceof Error?g['message']:String(g),i=classifyError(h),j={'operation_type':c,'data':e},k=d(h,i,j);return{'content':[{'type':'text','text':'Error:\x20'+h}],'structuredContent':k};}throw g;}};}export const statusErrorShape=(a,b,c)=>({'result':buildClassifiedErrorResult({'status':'error'},a,b),'semantic':buildDataSemantic(undefined,c,!![],a)});export const operationErrorShape=(a,b,c)=>({'result':buildClassifiedErrorResult({'operation':'error'},a,b),'semantic':buildDataSemantic(undefined,c,!![],a)});export const strictStatusErrorShape=(a,b,c)=>({'result':{'status':'error','error':a}});function checkProjectStage(a,b,c){const d={'analyze_intent':'puzzle','aggregate_risks':'risk','trace_substeps':'substeps'},e=d[a];if(!e)return null;const f=getStageCache(b,c);if(!f){if(a==='analyze_intent')return null;return'project_stage:\x20calling\x20\x27'+a+'\x27\x20before\x20\x27analyze_intent\x27\x20—\x20recommend\x20calling\x20analyze_intent\x20first\x20for\x20project\x20\x27'+b+':'+c+'\x27';}if(stageIndexOf(f['stage'])<stageIndexOf(e)-0x1)return'project_stage:\x20calling\x20\x27'+a+'\x27\x20(stage\x20\x27'+e+'\x27)\x20but\x20project\x20is\x20at\x20stage\x20\x27'+f['stage']+'\x27\x20—\x20recommend\x20completing\x20prior\x20stages\x20first\x20for\x20\x27'+b+':'+c+'\x27';return null;}export function dispatchWithHarness(a,b){return async(d,f)=>{const g=[],h=getHarness(),i=shouldRunLightHooks(),j=shouldRunHeavyHooks(),k=isPublishOperation(b,d),l=isSignOperation(b,d),m=getHarnessTier();let n;if(i)try{const p=extractOperationType(b,d),q=extractIntent(b,d);p&&q&&(n=h['expect'](b,q,p,extractData(d)));}catch(r){g['push']('pre_call\x20hook\x20failed:\x20'+(r instanceof Error?r['message']:String(r)));}if(b==='goal_operation'&&i)try{const s=d,t=s?.['action'],u=s?.['project'],v=s?.['version'];if(t&&u&&v){const x=checkProjectStage(t,u,v);x&&g['push'](x);}}catch{}k&&m==='lightweight'&&(setHarnessTier('full'),g['push']('pre_publish:\x20tier\x20forced\x20to\x20full\x20for\x20publish-class\x20operation\x20(GLM5-21\x20§3.3)'));if(k&&m!=='off')try{const y=runPrePublishChecks(b,d);g['push'](...y['warnings']);if(y['critical']['length']>0x0){for(const z of y['critical']){const A=recordCriticalRisk(z);if(A)g['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+A['reason']);}return buildHarnessBlockResult('pre_publish','Publish\x20BLOCKED\x20by\x20Harness\x20pre-publish\x20gate\x20(GLM5-21\x20V6):\x20'+(y['critical']['length']+'\x20CRITICAL\x20risk(s)\x20must\x20be\x20resolved\x20before\x20publish.'),y['critical'],y['warnings'],'immutable_violation','Fix\x20the\x20CRITICAL\x20risks\x20listed\x20in\x20the\x20message\x20(e.g.\x20rename\x20dispute/refund\x20nodes\x20per\x20R-M1-11,\x20add\x20the\x20entry\x20pair\x20prev_node=\x22\x22),\x20then\x20retry\x20publish.\x20Nodes/pairs/forwards\x20are\x20immutable\x20after\x20publish\x20—\x20verify\x20via\x20machineNode2file\x20first.');}}catch(B){g['push']('pre_publish\x20hook\x20failed:\x20'+(B instanceof Error?B['message']:String(B)));}if(l&&j)try{const C=extractData(d),D=C?extractAmount(C):null;if(D!==null){const E=getAmountThreshold();let F=null;try{F=BigInt(D);}catch{F=null;}if(F!==null&&F>E)return buildHarnessBlockResult('pre_sign','Sign\x20BLOCKED\x20by\x20Harness\x20pre-sign\x20gate\x20(GLM5-21\x20V7):\x20amount\x20'+formatAmount(F)+'\x20WOW\x20exceeds\x20the\x20full-tier\x20threshold\x20'+formatAmount(E)+'\x20WOW.',['amount\x20'+D+'\x20(smallest\x20unit)\x20>\x20threshold\x20'+E['toString']()+'\x20(smallest\x20unit)'],[],'invalid_parameter','Raise\x20WOWOK_AMOUNT_THRESHOLD\x20to\x20match\x20the\x20intended\x20amount,\x20split\x20the\x20transaction,\x20or\x20reset\x20the\x20harness\x20tier\x20to\x20lightweight\x20(config_operation)\x20after\x20explicit\x20user\x20confirmation.');}}catch(G){g['push']('pre_sign\x20hook\x20failed:\x20'+(G instanceof Error?G['message']:String(G)));}let o;try{o=await a(d,f);}catch(H){const I=H instanceof Error?H['message']:String(H),J=recordOperationFailure(b,I);J&&g['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+J['reason']);if(b==='onchain_operations')try{const K=classifyError(I,H);if(!K['retryable']&&K['error_code']!=='unknown'){const L=recordCriticalOperation(b,K['error_code']);if(L)g['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+L['reason']);}}catch{}throw H;}if(i&&n)try{if(o?.['structuredContent']){const M=buildVerifyInput(n,o),N=h['verify'](M);if(N['status']==='fail')g['push']('Harness\x20verify\x20FAIL:\x20'+N['summary']);else N['status']==='warn'&&g['push']('Harness\x20verify\x20WARN:\x20'+N['summary']);}}catch(O){g['push']('post_call\x20hook\x20failed:\x20'+(O instanceof Error?O['message']:String(O)));}if(b==='onchain_operations')try{if(classifyOutcome(o)==='failed'){const P=extractErrorCode(o)??'',Q=classifyError(P);if(!Q['retryable']&&Q['error_code']!=='unknown'){const R=recordCriticalOperation(b,Q['error_code']);if(R)g['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+R['reason']);}}}catch{}if(i){const S=extractIntent(b,d)??b;try{const T=classifyOutcome(o);if(T==='failed'){const U=extractErrorCode(o)??'',V=classifyError(U),W=h['recover'](V['error_code'],S,{'operation_type':b,'data':extractData(d)});g['push']('Harness\x20recover:\x20strategy='+W['strategy']+('\x20(attempt\x20'+W['current_attempt']+'/'+W['max_attempts']+')')+(W['should_retry']?'\x20—\x20retryable':'\x20—\x20do\x20NOT\x20retry\x20blindly')+(W['user_prompt']?'\x20—\x20'+W['user_prompt']:'\x20—\x20'+W['detail']));}else T==='success'&&h['resetRecovery'](S);}catch(X){g['push']('recover\x20hook\x20failed:\x20'+(X instanceof Error?X['message']:String(X)));}}if(b==='goal_operation')try{const Y=d?.['action'];if(Y==='trace_substeps'){const Z=extractCriticalFindingCount(o);if(Z>0x0){const a0=recordSubstepFailure(String(Y)+':\x20'+Z+'\x20critical\x20finding(s)');if(a0)g['push']('Harness\x20escalated\x20to\x20full\x20tier:\x20'+a0['reason']);}}}catch{}if(isWriteClassTool(b)&&!SEMANTIC_RECORDED_TOOLS['has'](b))try{const a1=extractOperationType(b,d)??b,a2=extractIntent(b,d)??b,a3=extractData(d)??d,a4=classifyOutcome(o),a5=extractErrorCode(o),a6=isEnabled('experience_layer');if(a6)recordOperationOutcome(a1,a3,a2,a4,a5);else{const a7=extractIndustry(d);a7&&isEnabled('industry_evolution')&&recordIndustrySignal(a7,{'type':a1},{'success':a4==='success','error_code':a5});}}catch(a8){g['push']('signal\x20collection\x20failed:\x20'+(a8 instanceof Error?a8['message']:String(a8)));}if(g['length']>0x0){if(o?.['structuredContent']){const a9=o['structuredContent'],aa=a9['semantic'];if(aa){const ab=Array['isArray'](aa['warnings'])?aa['warnings']:[];aa['warnings']=[...ab,...g];}else for(const ac of g){console['warn']('[harness]\x20'+ac);}}else for(const ad of g){console['warn']('[harness]\x20'+ad);}}return o;};}function isPublishOperation(a,b){if(a!=='onchain_operations')return![];const c=extractOperationType(a,b);if(c!=='service'&&c!=='machine')return![];const d=extractData(b);return d?.['publish']===!![]||d?.['bPublished']===!![];}function isSignOperation(a,b){if(a==='wip_file'){const c=b?.['operation_type'];return c==='sign';}return a==='onchain_operations';}function extractOperationType(a,b){if(!b||typeof b!=='object')return undefined;const c=b;if(a==='onchain_operations')return typeof c['operation_type']==='string'?c['operation_type']:undefined;if(a==='goal_operation'||a==='industry_pack_operation')return typeof c['action']==='string'?c['action']:undefined;return typeof c['operation_type']==='string'?c['operation_type']:undefined;}function extractIntent(a,b){if(!b||typeof b!=='object')return undefined;const c=b;if((a==='goal_operation'||a==='industry_pack_operation')&&typeof c['action']==='string')return a+':'+c['action'];const d=c['operation_type'];if(typeof d==='string')return a+':'+d;return a;}function extractData(a){if(!a||typeof a!=='object')return undefined;const b=a,c=b['data'];return c&&typeof c==='object'?c:undefined;}function buildVerifyInput(a,b){const c=b['structuredContent']??{},d=c['semantic'];return{'expected':a,'actual':{'result_type':typeof c['result_type']==='string'?c['result_type']:undefined,'semantic':d,'error_code':typeof c['error_code']==='string'?c['error_code']:undefined,'error':typeof c['error']==='string'?c['error']:undefined}};}const WRITE_CLASS_TOOLS=new Set(['onchain_operations','goal_operation','industry_pack_operation','wip_file','messenger_operation','bridge_operation']),SEMANTIC_RECORDED_TOOLS=new Set(['onchain_operations','bridge_operation']);function isWriteClassTool(a){return WRITE_CLASS_TOOLS['has'](a);}function classifyOutcome(a){if(!a?.['structuredContent'])return'failed';const b=a['structuredContent'],c=typeof b['status']==='string'?b['status']:typeof b['result_type']==='string'?b['result_type']:'';if(c==='error'||c==='failed')return'failed';if(c==='partial')return'partial';return'success';}function extractErrorCode(a){if(!a?.['structuredContent'])return undefined;const b=a['structuredContent'];if(typeof b['error_code']==='string')return b['error_code'];const c=b['error'];if(typeof c==='string')return c;if(c&&typeof c==='object'){const d=c['code'];if(typeof d==='string')return d;}return undefined;}function extractIndustry(a){if(!a||typeof a!=='object')return undefined;const b=a;if(typeof b['industry']==='string')return b['industry'];const c=b['data'];if(c&&typeof c==='object'){const e=c;if(typeof e['industry']==='string')return e['industry'];}return undefined;}const ANTI_PATTERN_NODE_REGEX=/(^|_)(disputed?|refund(?:ed)?|arbitration|arb)(_|$)/i;function runPrePublishChecks(a,b){const c=[],d=[],e=extractOperationType(a,b),g=extractData(b)??{};if(e==='machine'){const h=g['node'],i=Array['isArray'](h)?h:Array['isArray'](h?.['nodes'])?h['nodes']:[];if(i['length']>0x0){for(const l of i){const m=typeof l?.['name']==='string'?l['name']:'';m&&ANTI_PATTERN_NODE_REGEX['test'](m)&&c['push']('R-M1-11:\x20machine\x20node\x20\x22'+m+'\x22\x20models\x20dispute/refund\x20flow\x20—\x20'+'refunds\x20must\x20route\x20via\x20an\x20Allocator\x20triggered\x20by\x20business\x20states,\x20'+'disputes\x20via\x20the\x20separate\x20Arbitration\x20object\x20(off-Machine)');}const j=new Set();for(const o of i){const q=typeof o?.['name']==='string'?o['name']:'';if(!q)continue;j['has'](q)&&c['push']('MC-C-04:\x20duplicate\x20machine\x20node\x20name\x20\x22'+q+'\x22\x20—\x20on-chain\x20will\x20reject\x20the\x20publish\x20transaction'),j['add'](q);}const k=i['some'](r=>Array['isArray'](r?.['pairs'])&&r['pairs']['some'](s=>s?.['prev_node']===''));!k&&c['push']('Machine\x20has\x20no\x20entry\x20pair\x20(prev_node=\x22\x22)\x20—\x20Progress\x20can\x20never\x20advance\x20'+'from\x20the\x20initial\x20state;\x20orders\x20are\x20permanently\x20stuck');for(const r of i){const s=typeof r?.['name']==='string'?r['name']:'?';for(const t of r?.['pairs']??[]){for(const u of t?.['forwards']??[]){const v=u?.['namedOperator']!==undefined&&u?.['namedOperator']!==null,w=u?.['permissionIndex']!==undefined&&u?.['permissionIndex']!==null;!v&&!w&&d['push']('pre_publish:\x20node\x20\x22'+s+'\x22\x20forward\x20\x22'+String(u?.['name']??'?')+'\x22\x20has\x20neither\x20namedOperator\x20nor\x20permissionIndex\x20—\x20no\x20one\x20can\x20advance\x20it');}}}}else d['push']('pre_publish:\x20publishing\x20machine\x20without\x20inline\x20node\x20data\x20—\x20topology\x20not\x20verifiable\x20in\x20this\x20call;\x20'+'verify\x20nodes/pairs/forwards\x20via\x20machineNode2file\x20BEFORE\x20publish\x20(immutable\x20after\x20publish,\x20IMMUT-001)');d['push']('pre_publish:\x20machine\x20nodes/pairs/forwards\x20become\x20immutable\x20after\x20publish\x20(IMMUT-001)');}return e==='service'&&(d['push']('pre_publish:\x20service\x20machine/order_allocators/arbitrations\x20become\x20immutable\x20after\x20publish\x20(IMMUT-002);\x20sales\x20remains\x20modifiable'),g['machine']===undefined&&d['push']('pre_publish:\x20\x27machine\x27\x20not\x20set\x20in\x20this\x20call\x20—\x20if\x20the\x20service\x20was\x20never\x20bound\x20to\x20a\x20published\x20machine,\x20'+'it\x20cannot\x20process\x20orders\x20and\x20CANNOT\x20be\x20fixed\x20after\x20publish'),g['order_allocators']===undefined&&d['push']('pre_publish:\x20\x27order_allocators\x27\x20not\x20set\x20in\x20this\x20call\x20—\x20immutable\x20after\x20publish;\x20'+'orders\x20will\x20have\x20no\x20fund\x20distribution\x20if\x20never\x20configured')),{'critical':c,'warnings':d};}function buildHarnessBlockResult(a,b,c,d,e,f){const g=[...c['map'](i=>'CRITICAL:\x20'+i),...d['map'](i=>'WARN:\x20'+i)]['join']('\x0a'),h='Error:\x20'+b+(g?'\x0a'+g:'')+'\x0aRecovery:\x20'+f;return{'content':[{'type':'text','text':h}],'structuredContent':{'result':{'type':'error','error':b+'\x20[gate='+a+']','error_code':e,'retryable':![],'recovery_hint':f},'message':h}};}function extractCriticalFindingCount(a){const b=a?.['structuredContent'];if(!b)return 0x0;const c=b['semantic'],d=c?.['summary'];if(typeof d?.['critical_count']==='number'&&d['critical_count']>0x0)return d['critical_count'];const e=b['findings']??c?.['findings'];if(Array['isArray'](e))return e['filter'](h=>h?.['severity']==='error')['length'];const f=a?.['content']?.['map'](h=>'text'in h?h['text']:'')['join']('\x0a')??'',g=f['match'](/\[AUDIT ERROR\]/g);return g?g['length']:0x0;}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wowok/agent-mcp",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "license": "Apache-2.0",
51
51
  "dependencies": {
52
52
  "@modelcontextprotocol/server": "^2.0.0",
53
- "@wowok/wowok": "3.0.5",
53
+ "@wowok/wowok": "3.0.6",
54
54
  "lodash": "^4.18.1",
55
55
  "zod": "^4.2.0"
56
56
  },