@oakagentkit/addon 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +12 -2
  3. package/build/dist/action-result.d.ts +3 -0
  4. package/build/dist/action-result.js +1 -0
  5. package/build/dist/bridge.d.ts +65 -0
  6. package/build/dist/bridge.js +1 -0
  7. package/build/dist/chunks/2NJCYRBM.js +1 -0
  8. package/build/dist/chunks/44YOYZLT.js +1 -0
  9. package/build/dist/chunks/4B2GMIK7.js +1 -0
  10. package/build/dist/chunks/4LWKW7PM.js +2 -0
  11. package/build/dist/chunks/67E2KBUQ.js +1 -0
  12. package/build/dist/chunks/GONTF7K4.js +1 -0
  13. package/build/dist/chunks/I5LKYO3W.js +3 -0
  14. package/build/dist/chunks/IVR4JOHU.js +1 -0
  15. package/build/dist/chunks/OB7JDPFV.js +1 -0
  16. package/build/dist/chunks/QIDB35RS.js +1 -0
  17. package/build/dist/chunks/RDCN3YPX.js +5 -0
  18. package/build/dist/chunks/RGOGWTRI.js +1 -0
  19. package/build/dist/chunks/U3IXRJH7.js +5 -0
  20. package/build/dist/chunks/U5VW3XSD.js +2 -0
  21. package/build/dist/chunks/UTTRLIY5.js +1 -0
  22. package/build/dist/chunks/VZCMAMZL.js +2 -0
  23. package/build/dist/chunks/YR4WKA4P.js +1 -0
  24. package/build/dist/chunks/YVAFJM4Y.js +1 -0
  25. package/build/dist/cli.d.ts +67 -0
  26. package/build/dist/cli.js +6 -0
  27. package/build/dist/confirm.d.ts +120 -0
  28. package/build/dist/confirm.js +1 -0
  29. package/build/dist/execution-trace.d.ts +30 -0
  30. package/build/dist/execution-trace.js +1 -0
  31. package/build/dist/identity.d.ts +48 -0
  32. package/build/dist/identity.js +1 -0
  33. package/build/dist/journal.d.ts +53 -0
  34. package/build/dist/journal.js +1 -0
  35. package/build/dist/module-destinations.d.ts +4 -0
  36. package/build/dist/module-destinations.js +1 -0
  37. package/build/dist/onboarding.d.ts +38 -0
  38. package/build/dist/onboarding.js +1 -0
  39. package/build/dist/private-files.d.ts +5 -0
  40. package/build/dist/private-files.js +1 -0
  41. package/build/dist/recipes.d.ts +26 -0
  42. package/build/dist/recipes.js +1 -0
  43. package/build/dist/redact.d.ts +4 -0
  44. package/build/dist/redact.js +1 -0
  45. package/build/dist/renew.d.ts +2 -0
  46. package/build/dist/renew.js +1 -0
  47. package/build/dist/schema/recipe.schema.json +1 -0
  48. package/build/dist/sender.d.ts +141 -0
  49. package/build/dist/sender.js +1 -0
  50. package/build/dist/session.d.ts +45 -0
  51. package/build/dist/session.js +1 -0
  52. package/build/dist/setup.d.ts +26 -0
  53. package/build/dist/setup.js +1 -0
  54. package/build/dist/subscribe.d.ts +347 -0
  55. package/build/dist/subscribe.js +1 -0
  56. package/build/dist/terminal-confirm.d.ts +7 -0
  57. package/build/dist/terminal-confirm.js +1 -0
  58. package/build/dist/version.d.ts +1 -0
  59. package/build/dist/version.js +1 -0
  60. package/build/dist/wallet.d.ts +11 -0
  61. package/build/dist/wallet.js +12 -0
  62. package/package.json +49 -3
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ import { type OwnerSign } from './identity.js';
3
+ import { type SetupRequest } from './setup.js';
4
+ import type { Address } from 'viem';
5
+ import { createBridge } from './bridge.js';
6
+ import { SubscriptionLifecycle } from './subscribe.js';
7
+ import { createWallet, exportKey } from './wallet.js';
8
+ type Config = Record<string, string>;
9
+ export declare function readConfig(path?: string): Promise<Config>;
10
+ export declare function createRuntime(config: Config, writeDisplay: (text: string) => void | Promise<void>, recipeDirectory?: string, setupOptions?: {
11
+ configPath?: string;
12
+ signOwner?: OwnerSign;
13
+ terminalConfirmation?: boolean;
14
+ }): Promise<{
15
+ wallet: `0x${string}`;
16
+ bridge: {
17
+ listTools: () => Promise<import("./bridge.js").ListedTool[]>;
18
+ postTool: (name: string, args: import("@oakagentkit/core/types").ToolArgs) => Promise<unknown>;
19
+ callTool: (name: string, original: import("@oakagentkit/core/types").ToolArgs) => Promise<unknown>;
20
+ start: (transport?: import("@modelcontextprotocol/sdk/shared/transport").Transport) => Promise<void>;
21
+ stop: () => Promise<void>;
22
+ confirmSignature: import("./confirm.js").Confirm;
23
+ };
24
+ readonly lifecycle: SubscriptionLifecycle;
25
+ subscribe: (plan: "holder" | "nohold") => Promise<import("./subscribe.js").LifecycleResult>;
26
+ cancel: () => Promise<import("./subscribe.js").LifecycleResult>;
27
+ renew: () => Promise<import("./subscribe.js").LifecycleResult>;
28
+ setup: (request: SetupRequest) => Promise<{
29
+ summary: string;
30
+ identity: import("@oakagentkit/core/identity-link").SessionIdentity;
31
+ hashes: string[];
32
+ status: string;
33
+ }>;
34
+ profile: import("@oakagentkit/core/types").ToolArgs | {
35
+ type: string;
36
+ name: string;
37
+ description: string;
38
+ image: string;
39
+ services: never[];
40
+ x402Support: boolean;
41
+ active: boolean;
42
+ registrations: never[];
43
+ };
44
+ }>;
45
+ type Runtime = Pick<Awaited<ReturnType<typeof createRuntime>>, 'wallet' | 'profile' | 'renew'> & {
46
+ bridge: Pick<ReturnType<typeof createBridge>, 'postTool' | 'callTool' | 'start'>;
47
+ lifecycle: Pick<SubscriptionLifecycle, 'subscribe' | 'cancel'>;
48
+ setup?: (request: SetupRequest) => Promise<unknown>;
49
+ subscribe?: (plan: 'holder' | 'nohold') => Promise<unknown>;
50
+ cancel?: () => Promise<unknown>;
51
+ };
52
+ export interface CliOptions {
53
+ output?: (text: string) => void;
54
+ error?: (text: string) => void;
55
+ isTTY?: boolean;
56
+ initialize?: typeof createWallet;
57
+ exportWallet?: typeof exportKey;
58
+ address?: () => Promise<Address>;
59
+ runtime?: () => Promise<Runtime>;
60
+ configPath?: string;
61
+ recipeDirectory?: string;
62
+ signOwner?: OwnerSign;
63
+ chooseSetup?: () => Promise<string>;
64
+ }
65
+ export declare function runCli(argv: string[], options?: CliOptions): Promise<number>;
66
+ export declare function terminalOwnerSign(display: (text: string) => void): OwnerSign;
67
+ export {};
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import{a as _e}from"./chunks/I5LKYO3W.js";import{a as he}from"./chunks/OB7JDPFV.js";import{e as F,f as ge}from"./chunks/UTTRLIY5.js";import{a as pe}from"./chunks/44YOYZLT.js";import{d as O,e as B,g as we}from"./chunks/RDCN3YPX.js";import{a as Q}from"./chunks/RGOGWTRI.js";import{d as ne,e as J,f as ie}from"./chunks/4LWKW7PM.js";import{c as oe}from"./chunks/U5VW3XSD.js";import{b as le,c as de,d as fe,e as ue}from"./chunks/VZCMAMZL.js";import{a as te,c as re,d as L}from"./chunks/GONTF7K4.js";import{a as $,b as Z,d as ee}from"./chunks/YVAFJM4Y.js";import"./chunks/IVR4JOHU.js";import"./chunks/U3IXRJH7.js";import"./chunks/2NJCYRBM.js";import{c as j,f as se,g as ae,i as ce}from"./chunks/YR4WKA4P.js";import"./chunks/4B2GMIK7.js";import"./chunks/QIDB35RS.js";import"./chunks/67E2KBUQ.js";import{buildIdentityLinkTypedData as Ke,canonicalSessionIdentity as Ee,identityNetwork as ye}from"@oakagentkit/core/identity-link";import{constants as k}from"node:fs";import{realpath as ke,rename as Ie,unlink as Ne}from"node:fs/promises";import{randomUUID as Pe}from"node:crypto";import{homedir as Ce}from"node:os";import{dirname as me,join as ve}from"node:path";import{pathToFileURL as Le}from"node:url";import{createPublicClient as Ue,getAddress as y,http as He}from"viem";import{ETH_USDG_POOL as xe,NETWORKS as I,assertNetworkRpc as We,assertNetworkUsdg as Oe,resolveNetwork as N}from"@oakagentkit/core/addresses";import{DEFAULT_RPC_URL as $e}from"@oakagentkit/core/chain";import{createWallet as Je,exportKey as je,loadSigner as Re}from"#oak-wallet";var Be="oak identity unlink [--owner <linkId>]|setup [register [--no-tag]|link <agentId>]|init [--recover [--replace]]|address|status|backup|export|subscribe --plan <holder|nohold>|renew|cancel|register [--no-tag]|recipes add|remove|list <pkg-or-path>|config set <k> <v>|mcp|call <tool> <json>",Se="The command or its arguments are not valid. Run oak --help and retry with the listed arguments.",Ae="as-is, not reviewed by Oak",U=()=>ve(Ce(),".oak","config.json"),Fe=new Set(["OAK_PRIVATE_TEST_MODE","OAK_LAUNCH_BOOTSTRAP","OAK_NETWORK","OAK_CHAIN_ID","OAK_SERVER_URL","OAK_RPC_URL","OAK_SUBSCRIPTION_ADDRESS","OAK_RETIRED_SUBSCRIPTION_ADDRESSES","OAK_TOKEN_ADDRESS","OAK_USDG_ADDRESS","OAK_ORACLE_ADDRESS","OAK_ETH_USDG_POOL_ADDRESS","OAK_FINALITY","profile","grandfather","identity","confirm"]);function G(n,i){if(!Fe.has(n)&&!/^OAK_RPC_URL_[1-9][0-9]*$/.test(n))throw new Error("Unknown setting. Wallet keys cannot be stored in config.");if(!i.trim()||i.length>1048576)throw new Error("Invalid configuration value.");if(["OAK_LAUNCH_BOOTSTRAP","OAK_PRIVATE_TEST_MODE"].includes(n)&&!["true","false"].includes(i))throw new Error("Set the mode to true or false.");if(n==="confirm"&&i!=="ask"&&i!=="auto")throw new Error("Set confirm to ask or auto.");if(n==="OAK_NETWORK")N(i);else{if(n==="OAK_CHAIN_ID"&&!["4663","46630"].includes(i))throw new Error("Set OAK_CHAIN_ID to 4663 or 46630.");if(n==="OAK_SERVER_URL")B(i);else if(n.startsWith("OAK_RPC_URL")){let o=new URL(i);if(!["https:","http:"].includes(o.protocol))throw new Error("RPC URL must use HTTP or HTTPS.")}else if(n.endsWith("_ADDRESS"))y(i);else if(n==="OAK_RETIRED_SUBSCRIPTION_ADDRESSES")i.split(",").forEach(o=>y(o.trim()));else{if(n==="OAK_FINALITY"&&i!=="safe"&&i!=="finalized"&&(!/^[1-9][0-9]*$/.test(i)||!Number.isSafeInteger(Number(i))))throw new Error("Invalid finality setting.");if(n==="identity"){let o=O(JSON.parse(i));Ee(o,ye(o.chainId))}else(n==="profile"||n==="grandfather")&&O(JSON.parse(i))}}}async function H(n=U()){let i;try{i=await L(n,k.O_RDONLY,2097152)}catch(o){if(o.code==="ENOENT")return{};throw ee()}try{let o=await i.stat();if(!o.isFile()||o.size>2097152)throw new Error("Invalid local Oak configuration.");let l=O(JSON.parse(await i.readFile("utf8")));for(let[p,s]of Object.entries(l)){if(typeof s!="string")throw new Error("Configuration values must be strings.");G(p,s)}return l}finally{await i.close()}}async function Y(n,i,o){if(o!==void 0)G(i,o);else if(i!=="identity")throw new Error("Only the public identity setting can be cleared.");let l={...await H(n)};o===void 0?delete l[i]:l[i]=o;let p=`${JSON.stringify(l,null,2)}
3
+ `;if(Buffer.byteLength(p)>2097152)throw new Error("Local Oak configuration exceeds 2 MiB. Remove unused settings before retrying.");await te(me(n),!0);let s=`${n}.${Pe()}.tmp`,w=await L(s,k.O_WRONLY|k.O_CREAT|k.O_EXCL,2097152);try{try{await w.writeFile(p),await w.sync()}finally{await w.close()}try{await(await L(n,k.O_RDONLY,2097152)).close()}catch(r){if(r.code!=="ENOENT")throw r}await Ie(s,n),await re(me(n))}finally{await Ne(s).catch(r=>{if(r.code!=="ENOENT")throw r})}}async function Ye(n,i,o,l={}){n={...n};let p=t=>i($(t)),s=t=>process.env[t]??n[t],w=t=>{let c=s(t);if(!c)throw new Error(`Set ${t} with oak config set before this command.`);return c},r=N(n.OAK_NETWORK);if(process.env.OAK_NETWORK!==void 0&&N(process.env.OAK_NETWORK)!==r)throw new Error("OAK_NETWORK disagrees with the local config; set the network in the config explicitly.");let{chainId:e,usdg:S}=I[r];if((n.OAK_CHAIN_ID??String(I.mainnet.chainId))!==String(e)||process.env.OAK_CHAIN_ID!==void 0&&process.env.OAK_CHAIN_ID!==String(e))throw new Error(`Set OAK_CHAIN_ID to ${e} in the local deployment config.`);let g=(t,c)=>{let f=n[t]??c;if(!f)throw new Error(`Set ${t} in the local deployment config.`);let m=y(f);if(process.env[t]!==void 0&&y(process.env[t])!==m)throw new Error(`${t} disagrees with the local deployment config.`);return m},A=n.OAK_PRIVATE_TEST_MODE==="true",E=n.OAK_LAUNCH_BOOTSTRAP==="true";if(E&&A)throw new Error("Choose private test mode or launch-only bootstrap, then restart Oak.");if((E||A)&&r!=="mainnet")throw new Error("Launch bootstrap requires mainnet chain 4663.");let T=()=>{let t={network:r,chainId:e,subscription:g("OAK_SUBSCRIPTION_ADDRESS"),usdg:g("OAK_USDG_ADDRESS",S),oak:g("OAK_TOKEN_ADDRESS"),oracle:g("OAK_ORACLE_ADDRESS"),ethUsdgPool:g("OAK_ETH_USDG_POOL_ADDRESS")};return Oe(r,t.usdg),F(t),t},b=["OAK_SUBSCRIPTION_ADDRESS","OAK_TOKEN_ADDRESS","OAK_ORACLE_ADDRESS","OAK_ETH_USDG_POOL_ADDRESS"];for(let t of b)if(process.env[t]!==void 0&&n[t]===void 0)throw new Error(`Set ${t} in the local deployment config; environment-only addresses are not accepted.`);!E&&!A&&b.every(t=>n[t])&&T();let D=B(s("OAK_SERVER_URL")??(r==="mainnet"?"https://api.oakagentkit.org":w("OAK_SERVER_URL"))),d=async()=>{if(b.every(m=>n[m])){T();return}let t;try{let m=await fetch(new URL("/v1/config",D),{redirect:"error",signal:AbortSignal.timeout(5e3)}),K=O(await m.json());if(!m.ok||K.ok!==!0)throw new Error;t=O(K.data)}catch{throw new Error("Oak deployment configuration is unavailable. Ask the operator to enable /v1/config or configure the published Oak contract addresses. Your wallet address and read tools remain available.")}if(t.network!==r||t.chainId!==e||typeof t.usdg!="string")throw new Error("The Oak service configuration does not match the selected network.");Oe(r,y(t.usdg));let c={OAK_SUBSCRIPTION_ADDRESS:t.subscription,OAK_TOKEN_ADDRESS:t.oak,OAK_ORACLE_ADDRESS:t.oracle,OAK_ETH_USDG_POOL_ADDRESS:t.ethUsdgPool},f={};for(let[m,K]of Object.entries(c)){if(typeof K!="string")throw new Error("The Oak service deployment configuration is invalid.");let X=y(K);if(n[m]&&y(n[m])!==X)throw new Error(`${m} disagrees with the local deployment config.`);f[m]=X}if(F({network:r,chainId:e,subscription:f.OAK_SUBSCRIPTION_ADDRESS,oak:f.OAK_TOKEN_ADDRESS,oracle:f.OAK_ORACLE_ADDRESS,ethUsdgPool:f.OAK_ETH_USDG_POOL_ADDRESS,usdg:y(t.usdg)}),r==="mainnet"&&f.OAK_ETH_USDG_POOL_ADDRESS!==xe)throw new Error("ETH/USDG pool must match the pinned mainnet pool.");Object.assign(n,f),T()},u=new Map,a=t=>{let c=u.get(t);if(!c){let f=t===e?s("OAK_RPC_URL")??(r==="mainnet"?$e:w("OAK_RPC_URL")):w(`OAK_RPC_URL_${t}`);c=Ue({transport:He(f,{timeout:1e4,retryCount:0}),cacheTime:0}),u.set(t,c)}return c},h=[e,...Object.keys({...n,...process.env}).filter(t=>/^OAK_RPC_URL_[1-9][0-9]*$/.test(t)).map(t=>Number(t.slice(12)))];if(h.includes(r==="testnet"?I.mainnet.chainId:I.testnet.chainId))throw new Error("Do not configure the other Robinhood network as an additional RPC. Set OAK_NETWORK and OAK_RPC_URL together.");await Promise.all([...new Set(h)].filter(t=>t!==e||s("OAK_RPC_URL")).map(async t=>{let c=a(t);if(t===e)await We(r,c);else if(await c.getChainId()!==t)throw new Error(`RPC chain does not match configured chain ${t}.`)}));let _=s("OAK_FINALITY");_&&G("OAK_FINALITY",_);let P=_===void 0?void 0:_==="safe"||_==="finalized"?_:Number(_),R=await Re(),M=t=>{if(!t)return;let c=JSON.parse(t),f=Ee(c,ye(c.chainId));return f.chainId===e?f:void 0},x=ce({base:D,signer:R,network:r,identity:E||A?void 0:M(n.identity),clearIdentity:()=>Y(l.configPath??U(),"identity"),loadIdentity:async()=>E||A?void 0:M((await H(l.configPath)).identity)}),W=oe({signer:R,clientFor:a,allowedChainIds:h,finality:P,preview:p,confirm:l.terminalConfirmation?_e(n.confirm==="auto"?"auto":"ask"):t=>v.confirmSignature(t)}),Te={withAction:t=>W.withAction(c=>t({...c,send:async f=>(f.length&&await p(JSON.stringify(await v.postTool("preview",{txs:f}))),c.send(f))}))},be,C=()=>be??=new ge({wallet:R.address,deployment:T(),client:a(e),sender:Te,issueNote:async t=>{try{let c=await fetch(new URL("/v1/price-note",D),{method:"POST",redirect:"error",headers:{"content-type":"application/json"},body:JSON.stringify(t),signal:AbortSignal.timeout(3e4)}),f=await c.json();if(!c.ok&&!("reason"in f))throw new Error;return f}catch{throw new Error("Price note is unavailable. Retry when the server is reachable.")}},...n.grandfather?{grandfatherList:async()=>JSON.parse(n.grandfather)}:{}}),q=async()=>(await d(),he(C())),V=async t=>(await x.requireVerified(),await d(),C().subscribe(t)),De=async()=>(await d(),C().cancel()),v=we({oakTokenAddress:n.OAK_TOKEN_ADDRESS,confirmMode:n.confirm==="auto"?"auto":"ask",network:r,launchOnly:E,privateTestMode:A,identity:x,signOwner:l.signOwner,setup:t=>z(t),serverUrl:D.href,signer:R,sender:W,display:p,ensureSubscribed:q,startupInstructions:()=>le(R.address,r),subscribe:V,recipes:()=>J({directory:o}),recipeClient:a(e)}),z=pe({network:r,signer:{...R,signTypedData:t=>W.signTypedData(t)},identity:x,callTool:v.callTool,signOwner:l.signOwner,save:t=>Y(l.configPath??U(),"identity",JSON.stringify(t))});return{wallet:R.address,bridge:v,get lifecycle(){return C()},subscribe:V,cancel:De,renew:q,setup:z,profile:n.profile?O(JSON.parse(n.profile)):ue}}async function Ge(n,i={}){let o=i.output??(r=>{process.stdout.write(`${r}
4
+ `)}),l=i.error??i.output??(r=>{process.stderr.write(`${r}
5
+ `)}),p=r=>l($(r)),s=r=>o(JSON.stringify(r)),w=()=>{if(!(i.isTTY??(process.stdin.isTTY===!0&&process.stdout.isTTY===!0)))throw new Error("run this in your own terminal, not through the agent")};try{let[r,...e]=n;if(r==="--version"||r==="-v")return o(Q),0;if(r==="--help"||r==="-h")return o(Be),0;if(r==="init"&&(!e.length||e[0]==="--recover"&&(e.length===1||e.length===2&&e[1]==="--replace"))){w();let a=i.initialize??Je;return s(await(e.length?a({recover:!0,replace:e[1]==="--replace"}):a())),0}if(r==="export"&&!e.length)return w(),await(i.exportWallet??je)(),0;if(r==="backup"&&!e.length)return o(fe),0;if(r==="address"&&!e.length){let a=await H(i.configPath),h=N(a.OAK_NETWORK);if(process.env.OAK_NETWORK!==void 0&&N(process.env.OAK_NETWORK)!==h)throw new Error("OAK_NETWORK disagrees with the local config; set the network in the config explicitly.");let _=I[h].chainId;if(a.OAK_CHAIN_ID!==void 0&&a.OAK_CHAIN_ID!==String(_)||process.env.OAK_CHAIN_ID!==void 0&&process.env.OAK_CHAIN_ID!==String(_))throw new Error(`Set OAK_CHAIN_ID to ${_} for the selected network.`);return s(de(await(i.address??(async()=>(await Re()).address))(),h)),0}if(r==="config"&&e.length===3&&e[0]==="set")return e[1]==="confirm"&&e[2]==="auto"&&w(),await Y(i.configPath??U(),e[1],e[2]),o(`Saved ${e[1]}.`),0;if(r==="recipes"){let a={directory:i.recipeDirectory};if(e[0]==="add"&&e.length===2)s({recipes:await ne(e[1],a),label:Ae});else if(e[0]==="remove"&&e.length===2)await ie(e[1],a),o("Recipe project removed.");else if(e[0]==="list"&&e.length<=2)s({recipes:(await J(a)).filter(h=>!e[1]||h.project===e[1]),label:Ae});else throw new Error(Se);return 0}let S=r==="identity"&&e[0]==="unlink"&&(e.length===1||e.length===3&&e[1]==="--owner"&&/^0x[0-9a-f]{64}$/.test(e[2])),g=r==="setup"&&(!e.length||e[0]==="register"&&(e.length===1||e.length===2&&e[1]==="--no-tag")||e[0]==="link"&&e.length===2),A=["status","renew","cancel","mcp"].includes(r??"")&&!e.length,E=r==="subscribe"&&e.length===2&&e[0]==="--plan"&&["holder","nohold"].includes(e[1]),T=r==="register"&&(!e.length||e.length===1&&e[0]==="--no-tag"),b=r==="call"&&e.length===2;if(!S&&!g&&!A&&!E&&!T&&!b)throw new Error(Se);let D=b?O(JSON.parse(e[1])):void 0,d=await(i.runtime??(async()=>Ye(await H(i.configPath),p,i.recipeDirectory,{configPath:i.configPath,terminalConfirmation:r!=="mcp",signOwner:i.signOwner??(["setup","identity","mcp","call"].includes(r??"")?Me(p):void 0)})))(),u;switch(r){case"identity":u=await d.bridge.callTool("oak_identity_unlink",e[1]==="--owner"?{actor:"owner",linkId:e[2]}:{actor:"agent"});break;case"setup":{if(!d.setup)throw new Error("Identity setup is unavailable in this runtime.");let a=e[0],h=e[1];if(!a){let P=(i.chooseSetup?await i.chooseSetup():"register").trim().split(/\s+/);a=P[0],h=P[1]}if(a==="link"&&h)u=await d.setup({mode:a,agentId:h});else if(a==="register"){if(!d.profile)throw new Error("Set a registration-v1 profile with oak config set profile <json>, then run oak setup register.");u=await d.setup({mode:a,profile:d.profile,tag:h!=="--no-tag"})}else throw new Error("Choose register or link <agentId> with oak setup.");break}case"status":u={wallet:d.wallet,...O(await d.bridge.postTool("account",{}))};break;case"subscribe":u=await(d.subscribe??(a=>d.lifecycle.subscribe(a)))(e[1]);break;case"renew":u=await d.renew();break;case"cancel":u=await(d.cancel??(()=>d.lifecycle.cancel()))();break;case"register":if(!d.profile)throw new Error("Set a registration-v1 profile with oak config set profile <json>, then run oak register.");u=await d.bridge.callTool("erc8004_register",{profile:d.profile,tag:e[0]!=="--no-tag"});break;case"call":u=await d.bridge.callTool(e[0],D);break;case"mcp":return await d.bridge.start(),0}return s(u),u&&typeof u=="object"&&"ok"in u&&u.ok===!1?1:0}catch(r){return p(r instanceof SyntaxError?"The JSON is not valid. Use a JSON object with double-quoted field names and strings, then retry.":Z(r,"Oak command failed. Run oak status and retry when the server is reachable.")),1}}function Me(n){return async i=>{if(!process.stdin.isTTY||!process.stderr.isTTY)throw new Error(ae);return n("In the current owner\u2019s wallet, sign this EIP-712 identity request (the audience identifies link or unlink). Paste only the signature below; input is hidden. Never paste a key or recovery words."),n(JSON.stringify(Ke(i),(o,l)=>typeof l=="bigint"?l.toString():l)),new Promise((o,l)=>{let p=process.stdin.isRaw,s="",w=S=>{process.stdin.off("data",e),process.stdin.off("end",r),process.stdin.setRawMode(p===!0),process.stdin.pause(),S?l(S):/^0x(?:[0-9a-fA-F]{2})+$/.test(s)?o(s):l(new Error(j))},r=()=>w(new Error(se)),e=S=>{for(let g of S.toString("utf8")){if(g===""||g===""){r();return}if(g==="\r"||g===`
6
+ `){w();return}if(g==="\x7F"?s=s.slice(0,-1):s+=g,s.length>131072){w(new Error(j));return}}};process.stdin.setRawMode(!0),process.stdin.on("data",e),process.stdin.once("end",r),process.stdin.resume()})}}process.argv[1]&&import.meta.url===Le(await ke(process.argv[1])).href&&(process.exitCode=await Ge(process.argv.slice(2)));export{Ye as createRuntime,H as readConfig,Ge as runCli,Me as terminalOwnerSign};
@@ -0,0 +1,120 @@
1
+ import { type Address, type Hex, type PublicClient } from 'viem';
2
+ import { type SwapQuote } from '@oakagentkit/core/swap';
3
+ import type { Recipe, ToolArgs, TypedDataRequest, UnsignedTx } from '@oakagentkit/core/types';
4
+ export declare const confirmationUnavailable = "Human confirmation is unavailable. Use an MCP client with form elicitation, or run oak config set confirm auto yourself in your own terminal. Restore confirmations with oak config set confirm ask.";
5
+ export type ConfirmMode = 'ask' | 'auto';
6
+ export interface ConfirmationRequest {
7
+ hash: Hex;
8
+ summary: string;
9
+ }
10
+ export type Confirm = (request: ConfirmationRequest) => Promise<void>;
11
+ export interface Elicitor {
12
+ getClientCapabilities(): {
13
+ elicitation?: {
14
+ form?: unknown;
15
+ url?: unknown;
16
+ };
17
+ } | undefined;
18
+ elicitInput(params: {
19
+ mode: 'form';
20
+ message: string;
21
+ requestedSchema: {
22
+ type: 'object';
23
+ properties: {
24
+ confirm: {
25
+ type: 'boolean';
26
+ title: string;
27
+ default: false;
28
+ };
29
+ };
30
+ required: string[];
31
+ };
32
+ }, options: {
33
+ timeout: number;
34
+ }): Promise<{
35
+ action: string;
36
+ content?: Record<string, unknown>;
37
+ }>;
38
+ }
39
+ export declare const CONFIRMATION_SECONDS = 300;
40
+ export declare function createConfirmation(mode?: ConfirmMode, client?: () => Elicitor | undefined, timeout?: number): Confirm;
41
+ export type SigningTransaction = {
42
+ chainId: number;
43
+ to: Address;
44
+ data: Hex;
45
+ value: bigint;
46
+ gas: bigint;
47
+ nonce: number;
48
+ maxFeePerGas: bigint;
49
+ maxPriorityFeePerGas: bigint;
50
+ };
51
+ export declare function assertConfirmedBytes(rawTx: Hex, approved: SigningTransaction): void;
52
+ export declare function confirmTransaction(confirm: Confirm, tx: SigningTransaction, summary: string): Promise<SigningTransaction>;
53
+ export declare function snapshotTypedData(request: TypedDataRequest): TypedDataRequest;
54
+ export declare function confirmTypedData(confirm: Confirm, request: TypedDataRequest, action?: Pick<ActionRequest, 'name'>): Promise<TypedDataRequest>;
55
+ export declare function typedDataSummary(request: TypedDataRequest, action?: Pick<ActionRequest, 'name'>): string;
56
+ export interface ActionRequest {
57
+ name: string;
58
+ args: ToolArgs;
59
+ quote?: SwapQuote;
60
+ quoteArgs?: ToolArgs;
61
+ chainId?: number;
62
+ oakTokenAddress?: Address;
63
+ recipe?: Recipe;
64
+ destinations?: Address[];
65
+ }
66
+ export interface AssetInput {
67
+ token: Address;
68
+ amount: bigint;
69
+ id?: bigint;
70
+ }
71
+ export interface Transfer {
72
+ token: Address;
73
+ from: Address;
74
+ to: Address;
75
+ amount: bigint;
76
+ id?: bigint;
77
+ }
78
+ export declare function decodeTransfers(calls: readonly {
79
+ logs?: unknown;
80
+ }[], wallet: Address): Transfer[];
81
+ export interface ApprovalChange {
82
+ token: Address;
83
+ spender: Address;
84
+ amount: bigint;
85
+ expiration?: number;
86
+ permit2?: Address;
87
+ kind?: 'permit';
88
+ nft?: true;
89
+ }
90
+ export declare const MAX_PERMIT2_LIFETIME: number;
91
+ export declare function approvalDetails(tx: UnsignedTx, now?: number): ApprovalChange | undefined;
92
+ export declare function decodeApprovals(calls: readonly {
93
+ logs?: unknown;
94
+ }[], wallet: Address, now?: number): ApprovalChange[];
95
+ export declare const allowanceKey: (change: Pick<ApprovalChange, "token" | "spender">) => string;
96
+ type ApprovalCall = {
97
+ logs?: unknown;
98
+ status?: unknown;
99
+ returnData?: unknown;
100
+ data?: unknown;
101
+ };
102
+ export type AllowanceReader = (token: Address, spender: Address, blockNumber: bigint) => Promise<unknown>;
103
+ export type AllowancePair = Pick<ApprovalChange, 'token' | 'spender'>;
104
+ export type PostAllowanceSimulation = (index: number, pairs: readonly AllowancePair[]) => Promise<readonly ApprovalCall[]>;
105
+ export declare function allowanceCall(pair: AllowancePair, wallet: Address): {
106
+ account: `0x${string}`;
107
+ to: `0x${string}`;
108
+ data: `0x${string}`;
109
+ value: bigint;
110
+ gas: bigint;
111
+ };
112
+ export declare function assertApprovalChanges(calls: readonly ApprovalCall[], wallet: Address, txs: UnsignedTx[], now?: number, preState?: ReadonlyMap<string, bigint>, postStates?: readonly ReadonlyMap<string, bigint>[], pins?: readonly Address[]): ApprovalChange[];
113
+ export declare function verifyApprovalChanges(calls: readonly ApprovalCall[], wallet: Address, txs: UnsignedTx[], readAllowance: AllowanceReader, blockNumber: bigint, now?: number, simulatePostState?: PostAllowanceSimulation, pins?: readonly Address[]): Promise<ApprovalChange[]>;
114
+ export declare function assertOutflows(transfers: Transfer[], wallet: Address, inputs: AssetInput[], spent?: Map<string, bigint>, txs?: UnsignedTx[]): Map<string, bigint>;
115
+ export declare function assertModuleTransactions(txs: UnsignedTx[], action: ActionRequest): void;
116
+ export declare function assertActionTransactions(txs: UnsignedTx[], action: ActionRequest, wallet: Address, inputs: AssetInput[]): void;
117
+ export declare function summaryValue(value: string): string;
118
+ export declare function transactionSummary(name: string, tx: SigningTransaction, transfers: Transfer[], wallet: Address, txs: UnsignedTx[], approvals?: ApprovalChange[]): string;
119
+ export declare function actionInputs(action: ActionRequest, wallet: Address, client: Pick<PublicClient, 'readContract'>): Promise<AssetInput[]>;
120
+ export {};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v}from"./chunks/U3IXRJH7.js";import"./chunks/67E2KBUQ.js";export{b as CONFIRMATION_SECONDS,j as MAX_PERMIT2_LIFETIME,v as actionInputs,n as allowanceCall,m as allowanceKey,k as approvalDetails,s as assertActionTransactions,o as assertApprovalChanges,d as assertConfirmedBytes,r as assertModuleTransactions,q as assertOutflows,e as confirmTransaction,g as confirmTypedData,a as confirmationUnavailable,c as createConfirmation,l as decodeApprovals,i as decodeTransfers,f as snapshotTypedData,t as summaryValue,u as transactionSummary,h as typedDataSummary,p as verifyApprovalChanges};
@@ -0,0 +1,30 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ export interface TraceCall {
3
+ account: Address;
4
+ to: Address;
5
+ data: Hex;
6
+ value: bigint;
7
+ blockNumber?: bigint;
8
+ gas?: bigint;
9
+ nonce?: number;
10
+ maxFeePerGas?: bigint;
11
+ maxPriorityFeePerGas?: bigint;
12
+ }
13
+ export declare function assertExecutionTrace(result: unknown, call: TraceCall, pins: readonly Address[]): void;
14
+ export declare function executionTraceRequest(call: TraceCall): {
15
+ method: string;
16
+ params: (string | {
17
+ maxPriorityFeePerGas?: `0x${string}` | undefined;
18
+ maxFeePerGas?: `0x${string}` | undefined;
19
+ nonce?: `0x${string}` | undefined;
20
+ gas?: `0x${string}` | undefined;
21
+ from: `0x${string}`;
22
+ to: `0x${string}`;
23
+ data: `0x${string}`;
24
+ value: `0x${string}`;
25
+ tracer?: undefined;
26
+ } | {
27
+ tracer: string;
28
+ })[];
29
+ };
30
+ export declare function createExecutionChecker(traceCall?: (call: TraceCall) => Promise<unknown>): (call: TraceCall, pins: readonly Address[], approvalToken?: Address) => Promise<"callTracer" | "simulation-only">;
@@ -0,0 +1 @@
1
+ import{a,b,c}from"./chunks/2NJCYRBM.js";export{a as assertExecutionTrace,c as createExecutionChecker,b as executionTraceRequest};
@@ -0,0 +1,48 @@
1
+ import { type SessionIdentity } from '@oakagentkit/core/identity-link';
2
+ import type { IdentityLink, SignedIdentityLink } from '@oakagentkit/core/types';
3
+ import type { OakNetwork } from '@oakagentkit/core/addresses';
4
+ import type { WalletSigner } from './wallet.js';
5
+ export declare const identityPaused = "Identity changed, expired or link revoked. Run oak setup link <agentId> with the current owner to verify or link it again. Reads remain available; actions are paused.";
6
+ export declare const identityUnknown = "Identity status is unavailable. Please try again. Reads remain available; actions are paused.";
7
+ export declare const ownerMismatch = "This wallet does not own that agent ID. Ask the current owner to sign the link in oak setup link <agentId>.";
8
+ export declare const challengeExpired = "The identity challenge expired. Run oak setup link <agentId> again for a fresh owner signature.";
9
+ export declare const wrongNetwork = "Wrong identity network or registry. Set OAK_NETWORK and OAK_CHAIN_ID to match the owner\u2019s agent, then run oak setup again.";
10
+ export declare const signingCancelled = "Owner signing cancelled. Run the identity command again when ready.";
11
+ export declare const signingUnavailable = "Owner signing requires your terminal. Run oak setup link <agentId> or oak identity unlink --owner <linkId> there.";
12
+ export type UnlinkRequest = {
13
+ actor: 'agent' | 'owner';
14
+ linkId?: `0x${string}`;
15
+ };
16
+ export type OwnerSign = (link: IdentityLink) => Promise<SignedIdentityLink['signature']>;
17
+ export declare function identityError(value: unknown): Error;
18
+ export declare function createIdentityClient(options: {
19
+ base: URL;
20
+ signer: WalletSigner;
21
+ network: OakNetwork;
22
+ identity?: SessionIdentity;
23
+ fetch?: typeof fetch;
24
+ now?: () => number;
25
+ loadIdentity?: () => Promise<SessionIdentity | undefined>;
26
+ clearIdentity?: () => Promise<void>;
27
+ }): {
28
+ sessions: {
29
+ readonly identity: {
30
+ chainId: number;
31
+ registry: import("viem").Address;
32
+ agentId: import("@oakagentkit/core/types").DecimalString;
33
+ linkId?: import("viem").Hex;
34
+ } | undefined;
35
+ setIdentity(value?: SessionIdentity): void;
36
+ clear: () => void;
37
+ get(): Promise<string>;
38
+ headers(method: string, path: string, body: string): Promise<Record<string, string>>;
39
+ };
40
+ requireVerified(): Promise<void>;
41
+ unlink(request?: UnlinkRequest, sign?: OwnerSign): Promise<{
42
+ unlinked: boolean;
43
+ summary: string;
44
+ }>;
45
+ accept(identity: SessionIdentity): Promise<SessionIdentity>;
46
+ link(identity: SessionIdentity, sign: OwnerSign): Promise<SessionIdentity>;
47
+ };
48
+ export type IdentityClient = ReturnType<typeof createIdentityClient>;
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i}from"./chunks/YR4WKA4P.js";import"./chunks/4B2GMIK7.js";export{d as challengeExpired,i as createIdentityClient,h as identityError,a as identityPaused,b as identityUnknown,c as ownerMismatch,f as signingCancelled,g as signingUnavailable,e as wrongNetwork};
@@ -0,0 +1,53 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ export interface JournalEntry {
3
+ nonce: number;
4
+ hash: Hex;
5
+ rawTx: Hex;
6
+ kind: 'approval' | 'main' | 'burn';
7
+ sentAt: number;
8
+ notAfter?: number;
9
+ chainId: number;
10
+ blockNumber: string;
11
+ previous?: Hex[];
12
+ }
13
+ export type ClearReason = 'nonce_consumed';
14
+ export interface ClearedEntry {
15
+ hash: Hex;
16
+ nonce: number;
17
+ chainId: number;
18
+ kind: 'approval' | 'main' | 'burn';
19
+ sentAt: number;
20
+ blockNumber: string;
21
+ reason: ClearReason;
22
+ clearedAt: number;
23
+ }
24
+ export declare const walletDirectory: () => string;
25
+ export declare const entryHashes: (entry: JournalEntry) => Hex[];
26
+ export declare function withWalletLock<T>(address: Address, action: () => Promise<T>, options?: {
27
+ directory?: string;
28
+ pollMs?: number;
29
+ timeoutMs?: number;
30
+ }): Promise<T>;
31
+ export declare class Journal {
32
+ readonly address: Address;
33
+ readonly directory: string;
34
+ readonly path: string;
35
+ readonly clearedPath: string;
36
+ readonly approvalsPath: string;
37
+ constructor(address: Address, directory?: string);
38
+ private signedCall;
39
+ private validate;
40
+ private validateCleared;
41
+ private load;
42
+ private store;
43
+ approvals(): Promise<JournalEntry[]>;
44
+ retainApproval(entry: JournalEntry): Promise<void>;
45
+ forgetApproval(hash: Hex): Promise<void>;
46
+ read(): Promise<JournalEntry[]>;
47
+ cleared(): Promise<ClearedEntry[]>;
48
+ private write;
49
+ append(entry: JournalEntry): Promise<void>;
50
+ replace(hash: Hex, rawTx: Hex, blockNumber: string, sentAt: number): Promise<JournalEntry>;
51
+ burn(hash: Hex, rawTx: Hex, blockNumber: string, sentAt: number, notAfter?: number): Promise<JournalEntry>;
52
+ clear(hash: Hex, reason?: ClearReason): Promise<void>;
53
+ }
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"./chunks/QIDB35RS.js";export{d as Journal,b as entryHashes,a as walletDirectory,c as withWalletLock};
@@ -0,0 +1,4 @@
1
+ import { type Address, type PublicClient } from 'viem';
2
+ import type { ActionRequest } from './confirm.js';
3
+ export declare function moduleDestinations(action: ActionRequest, chainId?: number): Address[];
4
+ export declare function resolveModuleDestinations(action: ActionRequest, client: Pick<PublicClient, 'readContract'>, chainId?: number): Promise<Address[]>;
@@ -0,0 +1 @@
1
+ import{a,b}from"./chunks/67E2KBUQ.js";export{a as moduleDestinations,b as resolveModuleDestinations};
@@ -0,0 +1,38 @@
1
+ import { type Address } from 'viem';
2
+ import { type OakNetwork } from '@oakagentkit/core/addresses';
3
+ export declare function walletSummary(address: Address, network: OakNetwork): string;
4
+ export declare function startupInstructions(address: Address, network: OakNetwork, directory?: string): Promise<string>;
5
+ export declare function walletStatus(address: Address, network: OakNetwork): {
6
+ wallet: `0x${string}`;
7
+ address: `0x${string}`;
8
+ network: "testnet" | "mainnet";
9
+ chainId: 4663 | 46630;
10
+ funding: {
11
+ gas: {
12
+ address: string;
13
+ symbol: string;
14
+ decimals: number;
15
+ chainId: 4663 | 46630;
16
+ };
17
+ payment: {
18
+ address: `0x${string}`;
19
+ symbol: string;
20
+ decimals: number;
21
+ chainId: 4663 | 46630;
22
+ };
23
+ };
24
+ message: string;
25
+ backup: string;
26
+ notice: string;
27
+ };
28
+ export declare const backupGuidance = "Backups are optional. When you hold more than pocket change, run oak export in your own terminal, never through an agent. Keep the exported private key offline and private. Restore it with oak init --recover in your own terminal. Automatic wallets have no recovery phrase. Oak cannot recover a lost key.";
29
+ export declare const defaultProfile: {
30
+ type: string;
31
+ name: string;
32
+ description: string;
33
+ image: string;
34
+ services: never[];
35
+ x402Support: boolean;
36
+ active: boolean;
37
+ registrations: never[];
38
+ };
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e}from"./chunks/VZCMAMZL.js";import"./chunks/GONTF7K4.js";export{d as backupGuidance,e as defaultProfile,b as startupInstructions,c as walletStatus,a as walletSummary};
@@ -0,0 +1,5 @@
1
+ import { type FileHandle } from 'node:fs/promises';
2
+ export declare function privateDirectory(path: string, create?: boolean): Promise<void>;
3
+ export declare function privateFile(handle: FileHandle, maximum: number): Promise<void>;
4
+ export declare function syncPrivateDirectory(path: string): Promise<void>;
5
+ export declare function openPrivateFile(path: string, flags: number, maximum: number, createDirectory?: boolean): Promise<FileHandle>;
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"./chunks/GONTF7K4.js";export{d as openPrivateFile,a as privateDirectory,b as privateFile,c as syncPrivateDirectory};
@@ -0,0 +1,26 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import type { JsonValue, Recipe, UnsignedTx } from '@oakagentkit/core/types';
3
+ export declare function loadRecipe(json: unknown): Recipe;
4
+ export type DecodedResult = JsonValue;
5
+ export interface RecipeReadClient {
6
+ getChainId(): Promise<number>;
7
+ call(args: {
8
+ to: Address;
9
+ data: Hex;
10
+ }): Promise<{
11
+ data?: Hex;
12
+ }>;
13
+ }
14
+ export declare function buildRead(recipe: Recipe, args: Record<string, unknown>, options?: {
15
+ client?: RecipeReadClient;
16
+ }): Promise<DecodedResult>;
17
+ export declare function buildTx(recipe: Recipe, args: Record<string, unknown>, wallet: Address): UnsignedTx[];
18
+ export interface RecipeStoreOptions {
19
+ directory?: string;
20
+ }
21
+ export interface RecipeImportOptions extends RecipeStoreOptions {
22
+ fetch?: typeof fetch;
23
+ }
24
+ export declare function addRecipes(source: string, options?: RecipeImportOptions): Promise<Recipe[]>;
25
+ export declare function listRecipes(options?: RecipeStoreOptions): Promise<Recipe[]>;
26
+ export declare function removeRecipes(project: string, options?: RecipeStoreOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f}from"./chunks/4LWKW7PM.js";import"./chunks/GONTF7K4.js";import"./chunks/YVAFJM4Y.js";export{d as addRecipes,b as buildRead,c as buildTx,e as listRecipes,a as loadRecipe,f as removeRecipes};
@@ -0,0 +1,4 @@
1
+ export declare function redact(text: string): string;
2
+ export declare function errorMessage(error: unknown, fallback?: string): string;
3
+ export declare const publicError: (error: unknown) => Error;
4
+ export declare const configReadError: () => Error;
@@ -0,0 +1 @@
1
+ import{a,b,c,d}from"./chunks/YVAFJM4Y.js";export{d as configReadError,b as errorMessage,c as publicError,a as redact};
@@ -0,0 +1,2 @@
1
+ import { SubscriptionLifecycle, type LifecycleResult } from './subscribe.js';
2
+ export declare function ensureSubscribed(lifecycle: SubscriptionLifecycle): Promise<LifecycleResult>;
@@ -0,0 +1 @@
1
+ import{a}from"./chunks/OB7JDPFV.js";import"./chunks/UTTRLIY5.js";import"./chunks/U5VW3XSD.js";import"./chunks/YVAFJM4Y.js";import"./chunks/IVR4JOHU.js";import"./chunks/U3IXRJH7.js";import"./chunks/2NJCYRBM.js";import"./chunks/QIDB35RS.js";import"./chunks/67E2KBUQ.js";export{a as ensureSubscribed};
@@ -0,0 +1 @@
1
+ {"$schema":"http://json-schema.org/draft-07/schema#","$id":"https://oakagentkit.org/schema/recipe.schema.json","title":"Oak declarative recipe v1","type":"object","additionalProperties":false,"required":["schema","project","name","description","chainId","contract","function","inputs","kind"],"properties":{"schema":{"const":"oak-recipe/v1"},"project":{"$ref":"#/definitions/slug"},"name":{"$ref":"#/definitions/slug"},"description":{"type":"string"},"chainId":{"const":4663},"contract":{"type":"string","format":"eip55"},"function":{"type":"object","additionalProperties":false,"required":["type","name","stateMutability","inputs","outputs"],"properties":{"type":{"const":"function"},"name":{"type":"string","pattern":"^[A-Za-z_][A-Za-z0-9_]*$"},"stateMutability":{"enum":["view","pure","nonpayable","payable"]},"inputs":{"type":"array","maxItems":128,"items":{"$ref":"#/definitions/parameter"}},"outputs":{"type":"array","maxItems":128,"items":{"$ref":"#/definitions/parameter"}}}},"inputs":{"type":"array","maxItems":128,"items":{"type":"object","additionalProperties":false,"required":["name","type","description"],"properties":{"name":{"type":"string","pattern":"^[A-Za-z_][A-Za-z0-9_]*$"},"type":{"type":"string","pattern":"^(address|bool|string|bytes([1-9]|[12][0-9]|3[0-2])?|u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?|tuple)(\\[([1-9][0-9]*)?\\])*$"},"description":{"type":"string"},"default":{}}}},"kind":{"enum":["read","tx"]},"value":{"type":"object","additionalProperties":false,"required":["fromInput"],"properties":{"fromInput":{"type":"string","pattern":"^[A-Za-z_][A-Za-z0-9_]*$"}}},"approve":{"type":"object","additionalProperties":false,"required":["token","amountFromInput"],"properties":{"token":{"type":"string","format":"eip55"},"amountFromInput":{"type":"string","pattern":"^[A-Za-z_][A-Za-z0-9_]*$"}}}},"definitions":{"slug":{"type":"string","pattern":"^[a-z0-9-]{1,40}$"},"parameter":{"type":"object","additionalProperties":false,"required":["type"],"properties":{"name":{"type":"string","pattern":"^([A-Za-z_][A-Za-z0-9_]*)?$"},"type":{"type":"string","pattern":"^(address|bool|string|bytes([1-9]|[12][0-9]|3[0-2])?|u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?|tuple)(\\[([1-9][0-9]*)?\\])*$"},"internalType":{"type":"string"},"components":{"type":"array","minItems":1,"maxItems":128,"items":{"$ref":"#/definitions/parameter"}}}}}}
@@ -0,0 +1,141 @@
1
+ import { type ActionRequest, type Confirm } from './confirm.js';
2
+ import { type TraceCall } from './execution-trace.js';
3
+ import { erc20Abi, type Address, type Hex } from 'viem';
4
+ import type { SenderResult, TypedDataRequest, UnsignedTx } from '@oakagentkit/core/types';
5
+ import { type WalletSigner } from './wallet.js';
6
+ type Receipt = {
7
+ blockHash?: Hex;
8
+ transactionHash: Hex;
9
+ blockNumber: bigint;
10
+ status: 'success' | 'reverted';
11
+ };
12
+ type Call = {
13
+ account: Address;
14
+ to: Address;
15
+ data: Hex;
16
+ value: bigint;
17
+ gas?: bigint;
18
+ nonce?: number;
19
+ };
20
+ type SimulationCall = Call & ({
21
+ gasPrice?: bigint;
22
+ maxFeePerGas?: never;
23
+ maxPriorityFeePerGas?: never;
24
+ } | {
25
+ gasPrice?: never;
26
+ maxFeePerGas: bigint;
27
+ maxPriorityFeePerGas: bigint;
28
+ });
29
+ type SimulatedCall = {
30
+ data?: Hex;
31
+ returnData?: Hex;
32
+ logs?: unknown;
33
+ status: 'success' | 'failure';
34
+ gasUsed: bigint;
35
+ maxUsedGas?: bigint;
36
+ };
37
+ export interface ChainClient {
38
+ traceCall?(call: TraceCall): Promise<unknown>;
39
+ getChainId(): Promise<number>;
40
+ getBalance(args: {
41
+ address: Address;
42
+ blockTag: 'pending';
43
+ }): Promise<bigint>;
44
+ estimateMaxPriorityFeePerGas(): Promise<bigint>;
45
+ estimateGas(args: Call): Promise<bigint>;
46
+ simulateBlocks(args: {
47
+ blocks: [{
48
+ calls: SimulationCall[];
49
+ }];
50
+ validation: false;
51
+ traceTransfers: true;
52
+ blockNumber?: bigint;
53
+ }): Promise<readonly {
54
+ calls: readonly SimulatedCall[];
55
+ }[]>;
56
+ readContract(args: {
57
+ address: Address;
58
+ abi: typeof erc20Abi;
59
+ functionName: 'allowance';
60
+ args: readonly [Address, Address];
61
+ blockNumber?: bigint;
62
+ }): Promise<unknown>;
63
+ getTransactionCount(args: {
64
+ address: Address;
65
+ } & ({
66
+ blockTag: 'pending' | 'latest' | 'safe' | 'finalized';
67
+ blockNumber?: never;
68
+ } | {
69
+ blockNumber: bigint;
70
+ blockTag?: never;
71
+ })): Promise<number>;
72
+ getBlock(args: {
73
+ blockTag: 'latest' | 'safe' | 'finalized';
74
+ blockNumber?: never;
75
+ } | {
76
+ blockNumber: bigint;
77
+ blockTag?: never;
78
+ }): Promise<{
79
+ hash?: Hex | null;
80
+ number: bigint | null;
81
+ timestamp: bigint;
82
+ baseFeePerGas?: bigint | null;
83
+ gasLimit?: bigint;
84
+ }>;
85
+ getTransactionReceipt(args: {
86
+ hash: Hex;
87
+ }): Promise<Receipt>;
88
+ getTransaction(args: {
89
+ hash: Hex;
90
+ }): Promise<{
91
+ hash: Hex;
92
+ }>;
93
+ sendRawTransaction(args: {
94
+ serializedTransaction: Hex;
95
+ }): Promise<Hex>;
96
+ waitForTransactionReceipt(args: {
97
+ hash: Hex;
98
+ confirmations: number;
99
+ timeout: number;
100
+ }): Promise<Receipt>;
101
+ }
102
+ export type Finality = number | 'safe' | 'finalized';
103
+ export declare const NOT_AFTER_SECONDS = 300;
104
+ export type PreparedTx = UnsignedTx & {
105
+ notAfter?: number;
106
+ };
107
+ export type Reprepare = () => Promise<{
108
+ txs: PreparedTx[];
109
+ action?: ActionRequest;
110
+ }>;
111
+ export interface SenderOptions {
112
+ signer?: WalletSigner;
113
+ confirm?: Confirm;
114
+ clientFor?: (chainId: number) => ChainClient;
115
+ allowedChainIds?: readonly number[];
116
+ directory?: string;
117
+ finality?: Finality;
118
+ receiptTimeoutMs?: number;
119
+ now?: () => number;
120
+ notAfterSeconds?: number;
121
+ preview?: (text: string) => void | Promise<void>;
122
+ }
123
+ export interface LockedSender {
124
+ approvalStatus?(): Promise<string>;
125
+ send(txs: PreparedTx[], action?: ActionRequest, reprepare?: Reprepare): Promise<SenderResult>;
126
+ signTypedData(request: TypedDataRequest, action?: Pick<ActionRequest, 'name'>): Promise<Hex>;
127
+ assertCanPayGas(txs: PreparedTx[]): Promise<void>;
128
+ }
129
+ export declare class SenderError extends Error {
130
+ }
131
+ export declare function createSender(options?: SenderOptions): {
132
+ withAction: <T>(action: (locked: LockedSender) => Promise<T>) => Promise<T>;
133
+ send: (txs: PreparedTx[], action?: ActionRequest, reprepare?: Reprepare) => Promise<SenderResult>;
134
+ signTypedData: (request: TypedDataRequest, action?: Pick<ActionRequest, "name">) => Promise<`0x${string}`>;
135
+ assertCanPayGas: (txs: UnsignedTx[]) => Promise<void>;
136
+ blockNumber: (chainId?: number) => Promise<bigint>;
137
+ };
138
+ export declare const send: (txs: UnsignedTx[], options?: SenderOptions) => Promise<SenderResult>;
139
+ export declare const signTypedData: (request: TypedDataRequest, options?: SenderOptions) => Promise<`0x${string}`>;
140
+ export declare const assertCanPayGas: (txs: UnsignedTx[], options?: SenderOptions) => Promise<void>;
141
+ export {};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f}from"./chunks/U5VW3XSD.js";import"./chunks/YVAFJM4Y.js";import"./chunks/IVR4JOHU.js";import"./chunks/U3IXRJH7.js";import"./chunks/2NJCYRBM.js";import"./chunks/QIDB35RS.js";import"./chunks/67E2KBUQ.js";export{a as NOT_AFTER_SECONDS,b as SenderError,f as assertCanPayGas,c as createSender,d as send,e as signTypedData};