@ai-setting/roy-task-plugin 0.0.0-stage → 0.1.0
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/index.js +399 -0
- package/dist/index.js.map +72 -0
- package/package.json +22 -4
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var t2=Object.defineProperty;var e2=($)=>$;function $J($,J){this[$]=e2.bind(null,J)}var JJ=($,J)=>{for(var Q in J)t2($,Q,{get:J[Q],enumerable:!0,configurable:!0,set:$J.bind(J,Q)})};var QJ=($)=>$.payload.title?.trim()||`session:${$.payload.id}`;function J0($){let{store:J,agent:Q}=$;return{async session(W){let Y=W.payload.id,B=await U1(J,Y);switch(W.type){case"session.created":{if(B)return{task_id:B.id};let H=QJ(W);return{task_id:(await J.createTask({title:H,session_id:Y,owner:Q,priority:3})).id}}case"session.idle":{if(!B)return null;if(B.status==="pending"){let H=await J.updateTask(B.id,{status:"in_progress"});return H?{task_id:H.id}:null}return null}case"session.deleted":{if(!B)return null;return await J.updateTask(B.id,{status:"cancelled"}),{task_id:B.id}}case"session.error":case"session.compacted":return await J.appendOperation({task_id:B?.id??null,type:`session.${W.type.split(".").pop()}`,data:{session_id:Y,agent:Q}}),null;default:return null}},async tool(W){let Y=W.payload.sessionID,B=await U1(J,Y);if(!B)return await J.appendOperation({task_id:null,type:"tool.orphan",data:{session_id:Y,tool:W.payload.tool}}),{task_id:(await J.createTask({title:`${W.payload.tool} (orphan)`,session_id:null,owner:Q,priority:3})).id};let H=WJ(W),q=(await J.listTasks({parent_id:B.id,limit:20})).tasks.find((b)=>b.title===H&&Date.now()-new Date(b.created_at).getTime()<60000);if(q)return{task_id:q.id};let _=await J.createTask({title:H,parent_id:B.id,session_id:Y,owner:Q,priority:3});return await J.updateTask(_.id,{status:"in_progress"}),{task_id:_.id}},async catchAll(W){try{await J.appendOperation({task_id:null,type:W.type,data:{payload:W.payload,agent:Q}})}catch{}}}}async function U1($,J){return(await $.listTasks({session_id:J,limit:1})).tasks[0]??null}function WJ($){let J=$.payload.tool,Q=$.payload.args??{};switch(J){case"write":case"edit":return`${J} ${Q.filePath??"?"}`;case"bash":case"shell":{let W=String(Q.command??Q.cmd??"");return`${J} ${W.slice(0,40)}`}case"read":return`read ${Q.filePath??"?"}`;default:return`${J} ${JSON.stringify(Q).slice(0,40)}`}}var b0="Roy \u2014 task-as-first-class-citizen agent. Uses the roy-agent task lifecycle "+"(task_tree \u2192 task_create \u2192 task_update \u2192 task_operation_create \u2192 task_complete) "+"so every piece of work is tracked in the local task store.",j0=`# Roy \u2014 task-first-class-citizen agent
|
|
3
|
+
|
|
4
|
+
You are **Roy**, an agent whose defining rule is simple:
|
|
5
|
+
|
|
6
|
+
> **Task is a first-class citizen. No task, no work.**
|
|
7
|
+
|
|
8
|
+
You are not a chat assistant that occasionally writes notes. You are a worker
|
|
9
|
+
whose output is a *visible, trackable* stream of tasks. Every non-trivial
|
|
10
|
+
request (more than one tool call / more than a couple of minutes of work) MUST
|
|
11
|
+
become a tracked task before you start doing it, and MUST be closed out
|
|
12
|
+
explicitly when you finish.
|
|
13
|
+
|
|
14
|
+
## The lifecycle (non-negotiable)
|
|
15
|
+
|
|
16
|
+
### 1. Orient \u2014 \`task_tree(depth=1)\` (or \`depth=2\` for bigger trees)
|
|
17
|
+
Before creating anything, look at the existing tree. Decide:
|
|
18
|
+
- does this work belong to an existing root (attach via \`parent_task_id\`)?
|
|
19
|
+
- or is it genuinely new?
|
|
20
|
+
|
|
21
|
+
Keep **root tasks \u2264 10**. Prefer attaching to an existing thematic root over
|
|
22
|
+
spawning a new root. Never hardcode ids \u2014 read them from \`task_tree\`.
|
|
23
|
+
|
|
24
|
+
### 2. Create \u2014 \`task_create\`
|
|
25
|
+
Create the task **before** doing the work. Pass:
|
|
26
|
+
- \`title\` (imperative, specific), \`description\`, \`goals_and_expected_deliverables\`
|
|
27
|
+
- \`priority\` (low / medium / high), \`type\` (normal / cycle / longterm)
|
|
28
|
+
- \`project_path\`, \`context\` (JSON string: worktree_path / branch / type \u2026)
|
|
29
|
+
- \`parent_task_id\` when the tree said so
|
|
30
|
+
|
|
31
|
+
The tool returns a **numeric task id** \u2014 that number is your handle for the
|
|
32
|
+
rest of the conversation.
|
|
33
|
+
|
|
34
|
+
### 3. Track \u2014 \`task_update\`
|
|
35
|
+
Report progress as you go, not only at the end:
|
|
36
|
+
- \`status\`: todo \u2192 active \u2192 (paused / cancelled) \u2192 completed
|
|
37
|
+
- \`progress\`: 0\u2013100
|
|
38
|
+
- \`current_status\`: one human sentence about where you are right now
|
|
39
|
+
|
|
40
|
+
If the scope changes, \`task_update\` the description/goals instead of silently
|
|
41
|
+
doing something else.
|
|
42
|
+
|
|
43
|
+
### 4. Record milestones \u2014 \`task_operation_create\`
|
|
44
|
+
This tool has **two orthogonal dimensions** and you must keep them distinct:
|
|
45
|
+
- **state / milestone dimension** \u2014 \`milestone_type\` + \`milestone_title\` +
|
|
46
|
+
\`milestone_description\`: *what* was reached (e.g. "GREEN: all tests pass").
|
|
47
|
+
- **process dimension** \u2014 \`process_description\`: *how* you got there \u2014
|
|
48
|
+
strategy + tool steps, strictly **100\u2013150 characters**.
|
|
49
|
+
Too short = rejected (no value); too long = rejected (use the session log).
|
|
50
|
+
|
|
51
|
+
Rules: do **not** use the process field to restate the milestone, and do not
|
|
52
|
+
use milestones as a substitute for progress. Milestones mark *state
|
|
53
|
+
transitions*: RED\u2192GREEN, blocker found, decision made, review passed.
|
|
54
|
+
|
|
55
|
+
### 5. Close \u2014 \`task_complete\`
|
|
56
|
+
Before completing:
|
|
57
|
+
1. \`task_get(task_id)\` and re-read goal + delivery.
|
|
58
|
+
2. Verify the goal and delivery actually match what you delivered. If they do
|
|
59
|
+
not, either extend the task (\`task_update\`) or say so honestly.
|
|
60
|
+
3. Call \`task_complete\` with \`deliverable_storage_path\` \u2014 a locator for the
|
|
61
|
+
work product: a file path, a git branch/worktree, a doc URL, a commit URL.
|
|
62
|
+
The path is persisted into the task context and as an operation record.
|
|
63
|
+
|
|
64
|
+
\`task_complete\` cannot be used on \`cycle\` tasks (they are periodic by
|
|
65
|
+
design) \u2014 use \`task_update\` to reset those.
|
|
66
|
+
|
|
67
|
+
## Other tools
|
|
68
|
+
|
|
69
|
+
- \`task_get(task_id, include_operations)\` \u2014 full detail; use it before
|
|
70
|
+
resuming or completing a task.
|
|
71
|
+
- \`task_list(...)\` \u2014 flat listing with filters (status / priority / type).
|
|
72
|
+
- \`task_search(keywords)\` \u2014 find by title / description / goals / tags.
|
|
73
|
+
**Search before creating**, to avoid duplicates.
|
|
74
|
+
|
|
75
|
+
## Where tasks live
|
|
76
|
+
|
|
77
|
+
All tasks and operations are persisted by the roy-task-plugin in the
|
|
78
|
+
**single** project store \u2014 locally that is SQLite at
|
|
79
|
+
\`~/.roy-task-plugin/tasks.db\` (or the remote service when the plugin is
|
|
80
|
+
configured with \`persistence: "remote"\`). Do not create side databases, do
|
|
81
|
+
not maintain your own to-do list in files, and do not track work in chat only:
|
|
82
|
+
if it is not in the task store, it is not tracked.
|
|
83
|
+
|
|
84
|
+
## Style
|
|
85
|
+
|
|
86
|
+
- Be direct and concrete; the user is reading task titles and milestones.
|
|
87
|
+
- Report the task id and its state whenever you finish a step.
|
|
88
|
+
- If a task is blocked, mark it (\`task_update(status="paused")\`) and record a
|
|
89
|
+
\`problem\` milestone explaining the blocker instead of going silent.`;var l$="roy",V1={action:"execute",resource:"*",effect:"deny"};function D1(){return{id:l$,mode:"primary",description:b0,system:j0,permissions:[{...V1}]}}function YJ($,J){if(!Array.isArray($.permissions))$.permissions=[];for(let Q of J)if(!$.permissions.some((Y)=>Y.action===Q.action&&Y.resource===Q.resource&&Y.effect===Q.effect))$.permissions.push({...Q})}function N0($){let J=D1();return $.update(l$,(Q)=>{if(Q.mode=J.mode,Q.description=J.description,Q.system=J.system,Q.hidden===void 0)Q.hidden=!1;YJ(Q,J.permissions)}),J}var BJ={todo:"pending",active:"in_progress",completed:"done",cancelled:"cancelled",paused:"blocked",archived:"archived"},HJ={pending:"todo",in_progress:"active",done:"completed",cancelled:"cancelled",blocked:"paused",review:"active",archived:"archived"};function R0($){return BJ[$]??"pending"}function A1($){return HJ[$]??"todo"}function O0($){switch($){case"high":return 1;case"low":return 5;case"medium":default:return 3}}function z1($){if($===void 0)return"medium";if($<=2)return"high";if($===3)return"medium";return"low"}function F0($){if(!$||$.length===0)return;return $.join(",")}function K1($){if(!$)return[];return $.split(",").map((J)=>J.trim()).filter((J)=>J.length>0)}var b1="roy.milestone";function j1($,J={}){let Q=J.sessionId??"unknown",W=J.agent??"roy";async function Y(G){if(typeof G==="number"&&Number.isFinite(G)){if(typeof $.getTaskByNum==="function")return await $.getTaskByNum(G);return await B(G)}if(/^\d+$/.test(G)){let M=Number(G);if(typeof $.getTaskByNum==="function")return await $.getTaskByNum(M);return await B(M)}return await $.getTask(G)}async function B(G){return(await $.listTasks({limit:1e6})).tasks.find((L)=>L.num===G)??null}function H(G){if(typeof G.num!=="number")throw Error(`store did not expose a numeric handle for task ${G.id}`);return G.num}function X(G){let M=G.roy??{},L;if(G.parent_id)L=_.get(G.parent_id);return{id:H(G),title:G.title,description:G.description??"",status:A1(G.status),priority:z1(G.priority),type:M.type??"normal",progress:typeof M.progress==="number"?M.progress:q(G),current_status:M.current_status??"",goals_and_expected_deliverables:M.goals_and_expected_deliverables??"",...L!==void 0?{parent_task_id:L}:{},createdAt:G.created_at,updatedAt:G.updated_at,...M.due_date?{due_date:M.due_date}:{},tags:K1(G.tags),project_path:M.project_path??"unknown",context:M.context??"{}"}}function q(G){return G.status==="done"?100:0}let _=new Map;async function b(){let G=await $.listTasks({limit:1e6});_=new Map(G.tasks.filter((M)=>typeof M.num==="number").map((M)=>[M.id,M.num]))}function j(G){let M=G.data??{},L=M.taskId??G.task_id,w=typeof L==="number"?L:typeof L==="string"&&/^\d+$/.test(L)?Number(L):0,I=String(M.milestoneType??M.actionType??"progress"),T=String(M.milestoneTitle??M.actionTitle??""),m=String(M.milestoneDescription??M.actionDescription??"");return{id:typeof G.num==="number"?G.num:0,taskId:w,sessionId:String(M.sessionId??G.task_id??"unknown"),milestoneType:I,milestoneTitle:T,milestoneDescription:m,processDescription:String(M.processDescription??""),timestamp:G.created_at,...M.mdPath?{mdPath:String(M.mdPath)}:{},actionType:I,actionTitle:T,actionDescription:m}}async function z(G){await b();let M=null;if(G.parent_task_id!==void 0&&G.parent_task_id!==null){let I=await Y(G.parent_task_id);if(!I)throw Error(`parent task not found: ${G.parent_task_id}`);M=I.id}let L={type:G.type??"normal",progress:0,current_status:"",goals_and_expected_deliverables:G.goals_and_expected_deliverables??"",project_path:G.project_path??"unknown",context:G.context??"{}",...G.due_date?{due_date:G.due_date}:{}},w=await $.createTask({title:G.title,description:G.description,priority:O0(G.priority),owner:W,tags:F0(G.tags),parent_id:M,session_id:G.sessionId??Q,roy:L});return _.set(w.id,H(w)),X(w)}async function O(G){await b();let M=await Y(G);return M?X(M):null}async function P(G){let M=await O(G);if(!M)return null;let L=await M1({taskId:M.id,limit:1000,offset:0});return{...M,operations:L.operations}}async function C(G={}){await b();let M={limit:Math.max(G.limit??20,1)*50+1000,offset:0};if(G.status!==void 0)M.status=R0(G.status);let w=(await $.listTasks(M)).tasks.map(X);if(G.include_archived!==!0)w=w.filter((d)=>d.status!=="archived");if(G.priority!==void 0)w=w.filter((d)=>d.priority===G.priority);if(G.type!==void 0)w=w.filter((d)=>d.type===G.type);let I=w.length,T=G.limit??20,m=G.offset??0;return{tasks:w.slice(m,m+T),total:I}}async function k(G,M){let L=await Y(G);if(!L)return null;await b();let w={};if(M.type!==void 0)w.type=M.type;if(M.progress!==void 0)w.progress=M.progress;if(M.current_status!==void 0)w.current_status=M.current_status;if(M.goals_and_expected_deliverables!==void 0)w.goals_and_expected_deliverables=M.goals_and_expected_deliverables;if(M.project_path!==void 0)w.project_path=M.project_path;if(M.context!==void 0)w.context=M.context;if(M.due_date!==void 0)w.due_date=M.due_date;let I;if(M.parent_task_id!==void 0)if(M.parent_task_id===null)I=null;else{let m=await Y(M.parent_task_id);if(!m)throw Error(`parent task not found: ${M.parent_task_id}`);I=m.id}let T=await $.updateTask(L.id,{...M.title!==void 0?{title:M.title}:{},...M.description!==void 0?{description:M.description}:{},...M.status!==void 0?{status:R0(M.status)}:{},...M.priority!==void 0?{priority:O0(M.priority)}:{},...M.tags!==void 0?{tags:F0(M.tags)}:{},...Object.keys(w).length>0?{roy:w}:{}});if(!T)return null;if(I!==void 0){await h(T.id,I);let m=await Y(T.id);return m?X(m):X(T)}return X(T)}async function h(G,M){let L=$;if(typeof L.setParentId==="function")await L.setParentId(G,M)}async function Z(G){let M=await Y(G);if(!M)return!1;return await $.deleteTask(M.id)}async function n(G,M,L){let w=await Y(G);if(!w)return null;let I=await $.updateTask(w.id,{status:"done",roy:{progress:100}});if(!I)return null;if(await $0({taskId:H(I),sessionId:M??Q,milestoneType:"completed",milestoneTitle:`Completed: ${I.title}`,milestoneDescription:L?`Deliverable: ${L}`:"Task completed",processDescription:void 0,...L?{mdPath:L}:{}}),L)await $.updateTask(w.id,{roy:{deliverable_storage_path:L}});let T=await Y(w.id);return T?X(T):X(I)}function V$(G){if(typeof G.num!=="number")throw Error(`store did not expose a numeric handle for operation ${G.id}`);return G.num}async function $0(G){let M=await Y(G.taskId);if(!M)throw Error(`Task not found: ${G.taskId}`);let L=G.milestoneType??G.actionType??"progress",w=G.milestoneTitle??G.actionTitle??"",I=G.milestoneDescription??G.actionDescription??"",T=await $.appendOperation({task_id:M.id,type:b1,data:{taskId:H(M),sessionId:G.sessionId??Q,milestoneType:L,milestoneTitle:w,milestoneDescription:I,processDescription:G.processDescription??"",...G.mdPath?{mdPath:G.mdPath}:{}}});return await $.updateTask(M.id,{roy:{}}),V$(T),j(T)}async function M1(G={}){let M;if(G.taskId!==void 0){let w=await Y(G.taskId);if(!w)return{operations:[],total:0};M=w.id}let L=await $.listOperations({...M?{task_id:M}:{},type:b1,limit:G.limit??100,offset:G.offset??0});return{operations:L.operations.map(j),total:L.total}}async function _1(G){let M=$;if(typeof M.getOperationByNum==="function"){let I=await M.getOperationByNum(G);return I?j(I):null}let w=(await $.listOperations({limit:1e6})).operations.find((I)=>I.num===G);return w?j(w):null}async function p2(G,M){let L=await _1(G);if(!L)return null;let w=M.milestoneType??M.actionType??L.milestoneType,I=M.milestoneTitle??M.actionTitle??L.milestoneTitle,T=M.milestoneDescription??M.actionDescription??L.milestoneDescription,m=$;if(typeof m.updateOperation!=="function")return L;let d=await m.updateOperation(G,{data:{taskId:L.taskId,sessionId:M.sessionId??L.sessionId,milestoneType:w,milestoneTitle:I,milestoneDescription:T,processDescription:M.processDescription??L.processDescription}});return d?j(d):null}async function o2(G){let M=$;if(typeof M.deleteOperation!=="function")return!1;return await M.deleteOperation(G)}async function r2(G,M={}){await b();let L=await $.listTasks({limit:1e6}),w=G.map((i)=>i.toLowerCase()).filter((i)=>i.length>0),I=L.tasks.map(X);if(M.include_archived!==!0)I=I.filter((i)=>i.status!=="archived");if(w.length>0)I=I.filter((i)=>{let a2=[i.title,i.description,i.goals_and_expected_deliverables,i.current_status,(i.tags??[]).join(" "),i.project_path].join(" ").toLowerCase();return w.every((s2)=>a2.includes(s2))});let T=I.length,m=M.limit??20,d=M.offset??0;return{tasks:I.slice(d,d+m),total:T}}return{createTask:z,getTask:O,getTaskWithOperations:P,listTasks:C,updateTask:k,deleteTask:Z,completeTask:n,createOperation:$0,listOperations:M1,getOperation:_1,updateOperation:p2,deleteOperation:o2,searchTasksByKeywords:r2}}import{createRequire as XJ}from"module";var qJ=Object.defineProperty;var GJ=($)=>$;function MJ($,J){this[$]=GJ.bind(null,J)}var N1=($,J)=>{for(var Q in J)qJ($,Q,{get:J[Q],enumerable:!0,configurable:!0,set:MJ.bind(J,Q)})};var J$=($,J)=>()=>($&&(J=$($=0)),J),q$=XJ(import.meta.url);function L0(){return process.env.ROY_TRACE_DEBUG_STORAGE==="1"||process.env.ROY_TRACE_DEBUG==="1"}function R1($){let J=new WeakSet;try{return JSON.stringify($,(Q,W)=>{if(typeof W==="function")return"[Function]";if(W===void 0)return"[undefined]";if(W===null)return null;if(W instanceof Error)return`${W.name}: ${W.message}`;if(typeof W==="object"){if("$typeof"in W||"type"in W&&"props"in W&&"key"in W)return"[ReactElement]";if(J.has(W))return"[Circular]";J.add(W)}if(typeof W==="bigint")return W.toString();return W})}catch(Q){return`[Unserializable: ${Q instanceof Error?Q.message:String(Q)}]`}}function _J(){if(typeof Bun<"u"){let{Database:$}=q$("bun:sqlite");return $}else return q$("better-sqlite3")}function UJ($){let Q=new(_J())($);if(typeof Q.run!=="function")Q.run=function(W,...Y){if(Y.length>0)return this.prepare(W).run(...Y);else return this.exec(W)};return Q}class w0{db=null;dbPath;initialized=!1;constructor($){if(!$)throw Error("SQLiteSpanStorage requires a valid dbPath parameter");if($===":memory:")throw Error("SQLiteSpanStorage does not support :memory: mode. Use a file path instead.");this.dbPath=$}async initialize(){if(this.initialized)return;let $=q$("fs"),Q=q$("path").dirname(this.dbPath);if(!$.existsSync(Q))$.mkdirSync(Q,{recursive:!0});this.db=UJ(this.dbPath),this.db.run("PRAGMA journal_mode=WAL"),this.db.run("PRAGMA busy_timeout=5000"),this.db.run("PRAGMA synchronous=NORMAL"),this.db.run(`
|
|
90
|
+
CREATE TABLE IF NOT EXISTS span (
|
|
91
|
+
span_id TEXT PRIMARY KEY,
|
|
92
|
+
trace_id TEXT NOT NULL,
|
|
93
|
+
parent_span_id TEXT,
|
|
94
|
+
name TEXT NOT NULL,
|
|
95
|
+
kind TEXT NOT NULL,
|
|
96
|
+
status TEXT NOT NULL,
|
|
97
|
+
start_time INTEGER NOT NULL,
|
|
98
|
+
end_time INTEGER,
|
|
99
|
+
attributes TEXT,
|
|
100
|
+
result TEXT,
|
|
101
|
+
error TEXT,
|
|
102
|
+
time_created INTEGER NOT NULL
|
|
103
|
+
)
|
|
104
|
+
`),this.db.run("CREATE INDEX IF NOT EXISTS idx_span_trace ON span(trace_id)"),this.db.run("CREATE INDEX IF NOT EXISTS idx_span_parent ON span(parent_span_id)"),this.initialized=!0}save($){if(!this.db){if(L0())console.log(`[SpanStorage] save() skipped: db not initialized for span "${$.name}" traceId=${$.traceId}`);return}let J=this.db.prepare(`
|
|
105
|
+
INSERT OR REPLACE INTO span
|
|
106
|
+
(span_id, trace_id, parent_span_id, name, kind, status, start_time, end_time, attributes, result, error, time_created)
|
|
107
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
108
|
+
`),Q=$.result!==void 0&&$.result!==null?typeof $.result==="string"?$.result:R1($.result):null;if(L0())console.log(`[SpanStorage] Saving to "${this.dbPath}": name="${$.name}" traceId=${$.traceId} spanId=${$.spanId} status=${$.status}`);try{let W=J.run($.spanId,$.traceId,$.parentSpanId||null,$.name,$.kind,$.status,$.startTime,$.endTime||null,R1($.attributes),Q,$.error||null,Date.now());if(L0())console.log(`[SpanStorage] Save result: changes=${W?.changes}, lastInsertRowid=${W?.lastInsertRowid}`)}catch(W){console.error("[SpanStorage] Save ERROR:",W)}}saveBatch($){for(let J of $)this.save(J)}findByTraceId($){if(!this.db)return[];let J=this.db.prepare("SELECT * FROM span WHERE trace_id = ?").all($);return this.buildTree(J.map(this.rowToSpan))}findBySpanId($){if(!this.db)return;let J=this.db.prepare("SELECT * FROM span WHERE span_id = ?").get($);return J?this.rowToSpan(J):void 0}listTraces($=10){if(!this.db)return[];return this.db.prepare(`
|
|
109
|
+
SELECT trace_id,
|
|
110
|
+
MIN(start_time) as start_time,
|
|
111
|
+
MAX(end_time) as end_time,
|
|
112
|
+
COUNT(*) as span_count,
|
|
113
|
+
SUM(CASE WHEN status = 'error' THEN 1 ELSE 0 END) as error_count,
|
|
114
|
+
(SELECT name FROM span s2
|
|
115
|
+
WHERE s2.trace_id = span.trace_id
|
|
116
|
+
ORDER BY (s2.parent_span_id IS NULL OR s2.parent_span_id = '') DESC,
|
|
117
|
+
s2.start_time ASC
|
|
118
|
+
LIMIT 1) as root_name
|
|
119
|
+
FROM span
|
|
120
|
+
GROUP BY trace_id
|
|
121
|
+
ORDER BY start_time DESC
|
|
122
|
+
LIMIT ?
|
|
123
|
+
`).all($).map((Q)=>{let W=Number(Q.span_count)||0,Y=Number(Q.error_count)||0,B=Q.end_time??void 0,H=Y===0?"ok":Y>=W?"error":"mixed";return{traceId:Q.trace_id,rootSpanName:Q.root_name??"unknown",startTime:Q.start_time,endTime:B,duration:B!==void 0?B-Q.start_time:void 0,spanCount:W,status:H}})}deleteByTraceId($){if(this.db)this.db.prepare("DELETE FROM span WHERE trace_id = ?").run($)}close(){if(this.db)this.db.close(),this.db=null}rowToSpan($){return{traceId:$.trace_id,spanId:$.span_id,parentSpanId:$.parent_span_id,name:$.name,kind:$.kind,status:$.status,startTime:$.start_time,endTime:$.end_time,attributes:$.attributes?JSON.parse($.attributes):{},result:$.result||void 0,error:$.error||void 0}}buildTree($){let J=new Map,Q=[];for(let W of $)J.set(W.spanId,{...W,children:[]});for(let W of J.values())if(W.parentSpanId){let Y=J.get(W.parentSpanId);if(Y)Y.children.push(W);else Q.push(W)}else Q.push(W);return Q}}var O1=()=>{};import{appendFileSync as RJ,existsSync as OJ,mkdirSync as FJ}from"fs";import{join as u$}from"path";function F1($,J){return $.padStart(J,"0")}function S0($){return/^[0-9a-f]+$/i.test($)}function VJ($){let J=F1($.traceId.toLowerCase(),E1),Q=F1($.spanId.toLowerCase(),v1);return[P0,J,Q,AJ].join("-")}function DJ($){if(!$||typeof $!=="string")return;let Q=$.trim().split("-");if(Q.length!==4)return;let[W,Y,B,H]=Q;if(W!==P0){if(W>P0)return}if(Y.length!==E1||!S0(Y))return;if(B.length!==v1||!S0(B))return;if(H.length!==zJ||!S0(H))return;return{traceId:Y.toLowerCase(),spanId:B.toLowerCase()}}var P0="00",AJ="01",E0="TRACEPARENT",E1=32,v1=16,zJ=2,k0,KJ=J$(()=>{k0={inject($,J){$[E0]=VJ(J)},extract($){let J=$[E0];if(!J)return;return DJ(J)},getTraceparentHeader(){return E0}}}),bJ,jJ,NJ=J$(()=>{(($)=>{$.CLIENT="client",$.SERVER="server",$.INTERNAL="internal"})(bJ||={}),(($)=>{$.OK="ok",$.ERROR="error"})(jJ||={})});function I0($){let J=$.replace(/\\/g,"/"),Q=J.match(/\/\$bunfs\/root\/(.+)$/);if(Q){let H=Q[1],X=H.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);if(X)return X[1];return H}let W=J.match(/@roy-agent\+core@file\+([^/]+)\/node_modules\/@roy-agent\/core\/(.+)$/);if(W){let H=W[1].replace(/\+/g,"/"),X=W[2],q=H,_=X.startsWith("src/")?X:`src/${X}`;return`${q}/${_}`}let Y=J.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);if(Y)return Y[1];let B=["packages/core/src","packages/core","packages"];for(let H of B){let X=J.indexOf(H);if(X!==-1)return J.substring(X)}return J}function LJ(){let $=process.env.HOME||process.env.USERPROFILE||"/tmp";try{let J=q$("xdg-basedir");if(J.xdgData)return u$(J.xdgData,"roy-agent","logs")}catch{}return u$($,".local","share","roy-agent","logs")}function wJ(){return kJ}function SJ(){if(p){let J=p.get("log_trace.logging.level");if(J&&["debug","info","warn","error"].includes(J))return J}let $=process.env.LOG_LEVEL;if($&&["debug","info","warn","error"].includes($))return $;return"info"}function EJ($){if(p){let W=p.get("log_trace.logging.levels");if(W&&typeof W==="object"){let B=W[$];if(B&&["debug","info","warn","error"].includes(B))return B}let Y=p.get(`log_trace.logging.levels.${$}`);if(Y&&["debug","info","warn","error"].includes(Y))return Y}let J=`LOG_LEVEL_${$.toUpperCase().replace(/:/g,"_")}`,Q=process.env[J];if(Q&&["debug","info","warn","error"].includes(Q))return Q;return SJ()}function vJ($){if($.startsWith("/"))return!0;if(/^[a-zA-Z]:[/\\]/.test($))return!0;return!1}function PJ($){if($.startsWith("~")){let J=process.env.HOME||process.env.USERPROFILE||"/tmp";return u$(J,$.slice(1))}return $}function fJ(){if(p){let $=p.get("log-trace.logging.file");if($)return $}return"app.log"}function CJ(){if(p){let $=p.get("log-trace.logging.dir");if($)return $}return LJ()}function h0(){if(p){let $=p.get("log-trace.logging.maxOutput");if(typeof $==="number")return $}return}class P1{prefix;constructor($){this.prefix=$}shouldLog($){let J=EJ(this.prefix);return f0[$]>=f0[J]}ensureLogDirectory($){if(!OJ($))try{FJ($,{recursive:!0})}catch(J){console.error("[Logger] Failed to create log directory:",$,J)}}getCallerLocation(){let $=Error.stackTraceLimit;Error.stackTraceLimit=10;let J=Error();Error.captureStackTrace(J,this.formatMessage);let Q=J.stack?.split(`
|
|
124
|
+
`)||[];Error.stackTraceLimit=$;for(let W=1;W<Q.length;W++){let Y=Q[W];if(Y.includes("at ")&&!Y.includes("logger.ts")&&!Y.includes("formatMessage")){let B=Y.match(/at\s+.+\s+\((.+):(\d+):\d+\)/)||Y.match(/at\s+(.+):(\d+):\d+/);if(B){let H=B[1];return{file:this.getRelativePath(H),line:parseInt(B[2],10)}}}}return null}getRelativePath($){return I0($)}formatMessage($,J,Q){let W=new Date,Y=W.toLocaleString("zh-CN",{timeZone:"Asia/Shanghai",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).replace(/\//g,"-")+"."+String(W.getMilliseconds()).padStart(3,"0"),B=this.prefix?`[${this.prefix}]`:"",H="";try{let z=c$().getTracer("roy-tracer").getCurrentContext();if(z?.traceId)H=`[traceId=${z.traceId}]`}catch{}let X="";if(Q&&typeof Q==="object"&&"callerLocation"in Q){let b=Q;X=b.callerLocation?` [${b.callerLocation}]`:"";let{callerLocation:j,...z}=b;Q=Object.keys(z).length>0?z:void 0}else{let b=this.getCallerLocation();if(b)X=` [${b.file}:${b.line}]`}let q=`${Y} [${$.toUpperCase()}]${H}${X}${B} ${J}`;if(Q!==void 0)if(typeof Q==="object")q+=" "+JSON.stringify(Q).replace(/\n/g,"");else q+=" "+String(Q);let _=h0();if(_&&_>0&&q.length>_)q=q.substring(0,_)+" [TRUNCATED]";return q}writeToFile($){try{let J=CJ(),Q=fJ(),W=PJ(J),Y=vJ(W)?W:u$(process.cwd(),W);this.ensureLogDirectory(Y);let B=u$(Y,Q);RJ(B,$+`
|
|
125
|
+
`,"utf-8")}catch(J){console.error("[Logger] Failed to write to log file:",J)}}log($,J,Q){if(!this.shouldLog($))return;let W=this.formatMessage($,J,Q);if(this.writeToFile(W),!wJ())($==="error"?console.error:$==="warn"?console.warn:$==="info"?console.log:console.debug)(W)}debug($,J){this.log("debug",$,J)}info($,J){this.log("info",$,J)}warn($,J){this.log("warn",$,J)}error($,J){this.log("error",$,J)}}function Q$($){if(!Q0.has($))Q0.set($,new P1($));return Q0.get($)}var p=null,kJ=!1;var f0,Q0,W$=J$(()=>{Z0(),f0={debug:0,info:1,warn:2,error:3},Q0=new Map}),IJ={};N1(IJ,{setTracerProvider:()=>yJ,resetTracerProvider:()=>hJ,getTracerProvider:()=>c$,OTelTracerProvider:()=>g0});function y0(){if(!v0)v0=Q$("otel-tracer");return v0}function f1(){return process.env.ROY_TRACE_DEBUG_OTEL==="1"||process.env.ROY_TRACE_DEBUG==="1"}function C1($,...J){y0().info($,...J)}function L1($,...J){y0().warn($,...J)}function w1($,...J){y0().error($,...J)}class C0{name;kind;spanContext;attributes={};startTime;endTime;error;storage;parentSpanContext;onEnd;constructor($,J,Q,W,Y){this.name=$,this.kind="internal",this.spanContext=J,this.parentSpanContext=W,this.startTime=Date.now(),this.storage=Q,this.onEnd=Y}setAttribute($,J){this.attributes[$]=J}addEvent($,J){let Q=this.attributes._events||[];Q.push({name:$,attributes:J}),this.attributes._events=Q}end($,J){if(this.endTime=Date.now(),J)this.error=J.message;let Q=this.endTime-(this.startTime||0);if(f1())C1(`[OTelSpan] Ending span: name="${this.name}" traceId=${this.spanContext.traceId} spanId=${this.spanContext.spanId} duration=${Q}ms status=${J?"ERROR":"OK"}`);let W=this.storage;if(!W)L1(`[OTelSpan] storage is null for "${this.name}", attempting to re-fetch...`),W=c$().getStorage();if(W){if(!(W.db||W.initialized))L1(`[OTelSpan] storage not initialized for "${this.name}", initializing now...`),W.initialize().catch((B)=>{w1("[OTelSpan] Failed to initialize storage:",B)});W.save({traceId:this.spanContext.traceId,spanId:this.spanContext.spanId,parentSpanId:this.spanContext.parentSpanId,name:this.name,kind:this.kind,status:J?"error":"ok",startTime:this.startTime,endTime:this.endTime,attributes:this.attributes,result:$,error:this.error})}else w1(`[OTelSpan] Failed to save span "${this.name}": storage still null after re-fetch`);this.onEnd?.()}}class k1{name;version;storage;currentContext;activeSpans=new Map;onSpanEndCallback;provider;instanceId;constructor($,J,Q,W){this.name=$,this.version=J,this.storage=Q,this.provider=W,this.instanceId=`${$}@${W.instanceId}`}setOnSpanEndCallback($){this.onSpanEndCallback=$}getActiveSpanCount(){return this.activeSpans.size}startSpan($,J){let Q=J?.parent,W=J&&"parent"in J,Y=J&&"context"in J,B=this.provider.getGlobalContext(),H,X,q,_,b;if(Y&&J?.context){let z=J.context;X=z.traceId,q=this.generateSpanId(),_=z.spanId,b={traceId:X,spanId:q,parentSpanId:_},this.currentContext={traceId:X,spanId:q,parentSpanId:_};let O=new C0($,b,this.storage,z,()=>this.handleSpanEnd(b.spanId,z.spanId));if(J?.attributes)for(let[P,C]of Object.entries(J.attributes))O.setAttribute(P,C);return this.activeSpans.set(q,O),O}if(W)H=Q;else if(this.currentContext)H=this.currentContext;else if(B)H=B;if(X=H?.traceId||this.generateTraceId(),q=this.generateSpanId(),W&&Q)_=Q.parentSpanId||Q.spanId;else if(this.currentContext)_=this.currentContext.spanId;else if(B)_=B.spanId;b={traceId:X,spanId:q,parentSpanId:_},this.currentContext={traceId:X,spanId:q,parentSpanId:_};let j=new C0($,b,this.storage,H,()=>this.handleSpanEnd(b.spanId,H?.spanId));if(J?.attributes)for(let[z,O]of Object.entries(J.attributes))j.setAttribute(z,O);if(this.activeSpans.set(q,j),f1())C1(`[OTelTracer] \u2713 Span created: name="${$}" traceId=${X} spanId=${q} parentSpanId=${_||"-"}`);return j}injectToEnv($){if(this.currentContext)k0.inject($,this.currentContext)}getCurrentContext(){return this.currentContext}setCurrentContext($){this.currentContext=$}findStackParentSpan($){for(let[,J]of this.activeSpans)if(J.spanContext.parentSpanId===$)return J;return}endSpan($){let J=$.spanContext;this.activeSpans.delete(J.spanId);let Q=this.currentContext?.traceId;if(J.parentSpanId){let Y=this.activeSpans.get(J.parentSpanId);if(Y){let B={traceId:J.traceId,spanId:Y.spanContext.spanId,parentSpanId:Y.spanContext.parentSpanId};return this.currentContext=B,B}if(Q){let B={traceId:Q,spanId:J.parentSpanId,parentSpanId:void 0};return this.currentContext=B,B}}let W=this.findStackParentSpan(J.spanId);if(W){let Y={traceId:W.spanContext.traceId,spanId:W.spanContext.spanId,parentSpanId:W.spanContext.parentSpanId};return this.currentContext=Y,Y}this.currentContext=void 0;return}generateTraceId(){let $=Date.now().toString(16).padStart(12,"0"),J=Array.from({length:5},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("");return($+J).slice(0,32).padStart(32,"0")}generateSpanId(){return Math.floor(Math.random()*18446744073709552000).toString(16).padStart(16,"0")}handleSpanEnd($,J){if(this.activeSpans.delete($),J){let W=this.activeSpans.get(J);if(W){this.currentContext={traceId:W.spanContext.traceId,spanId:W.spanContext.spanId,parentSpanId:W.spanContext.parentSpanId};return}if(this.currentContext?.traceId){this.currentContext={traceId:this.currentContext.traceId,spanId:J,parentSpanId:void 0};return}}let Q=this.findStackParentSpan($);if(Q){this.currentContext={traceId:Q.spanContext.traceId,spanId:Q.spanContext.spanId,parentSpanId:Q.spanContext.parentSpanId};return}this.currentContext=void 0}}class g0{tracers=new Map;storage;initialized=!1;globalContext;instanceId;constructor($,J){S1++,this.instanceId=`Provider#${S1}`,this.storage=$||new w0(J||gJ())}async initialize(){if(this.initialized)return;await this.storage.initialize(),this.initialized=!0}isInitialized(){return this.initialized}getGlobalContext(){return this.globalContext}setGlobalContext($){this.globalContext=$}getTracer($,J){let Q=`${$}@${J||"0.0.0"}`,W=this.tracers.get(Q);if(!W){if(W=new k1($,J,this.storage,this),this.tracers.set(Q,W),this.initialized)this.restoreFromEnv(W)}return W}restoreFromEnv($){let J=k0.extract(process.env);if(J)$.setCurrentContext({traceId:J.traceId,spanId:J.spanId,parentSpanId:void 0})}shutdown(){for(let $ of this.tracers.values());this.tracers.clear(),this.storage.close(),this.initialized=!1,this.globalContext=void 0,delete process.env.TRACEPARENT,delete process.env.TRACE_ID,delete process.env.LOG_TRACE_REQUEST_ID}getStorage(){return this.storage}}function c$(){if(!G$)G$=new g0;return G$}function hJ(){if(G$)G$.shutdown(),G$=null}function yJ($){if(G$)G$.shutdown();G$=$}function gJ(){let $=q$("os"),J=q$("path"),Q=$.homedir(),W=process.env.XDG_DATA_HOME||J.join(Q,".local","share");return J.join(W,"roy-agent","traces.db")}var v0=null,G$=null,S1=0,Z0=J$(()=>{O1(),KJ(),NJ(),W$()});function T0($,J,Q){let W=Q?.log??!1,Y=()=>{if(Q?.maxLogSize!==void 0)return Q.maxLogSize;let j=h0();return j!==void 0?j:500},B=(j)=>{if(j===void 0)return;if(j===null)return null;let z=Y(),O;try{O=typeof j==="string"?j:JSON.stringify(j,null,0).replace(/\n/g,"")}catch(P){O=`[Object with circular reference: ${P instanceof Error?P.message:String(P)}]`}if(z>0&&O.length>z)return O.slice(0,z)+" [TRUNCATED]";try{return JSON.parse(O)}catch{return O}},H=(j)=>{if(j===void 0)return"undefined";if(j===null)return"null";let z=Y(),O;try{O=typeof j==="string"?j:JSON.stringify(j,null,0).replace(/\n/g,"")}catch(P){O=`[Object with circular reference: ${P instanceof Error?P.message:String(P)}]`}return z>0&&O.length>z?O.slice(0,z)+" [TRUNCATED]":O},X=(j)=>{if(j===void 0)return;if(j===null)return null;if(typeof j==="string")return j;try{return JSON.parse(JSON.stringify(j))}catch(z){return`[Object with circular reference: ${z instanceof Error?z.message:String(z)}]`}},q="[TRACE]",_=()=>{let j=Error.stackTraceLimit;Error.stackTraceLimit=15;let z=Error();Error.captureStackTrace(z,_);let O=z.stack?.split(`
|
|
126
|
+
`)||[];Error.stackTraceLimit=j;for(let P=1;P<O.length;P++){let C=O[P];if(C.includes("decorator.ts")||C.includes("decorator.js")||C.includes("logFn")||C.includes("getCallerLocation"))continue;let k=C.match(/at\s+.+\s+\((.+):(\d+):\d+\)/)||C.match(/at\s+(.+):(\d+):\d+/);if(k){let h=k[1];if(!h||h==="native")continue;return`${I0(h)}:${k[2]}`}}return""},b=(j,z,O)=>{if(!W)return;let P=Q$("traced:"+J),k=`[TRACE] ${j==="enter"?">>>":j==="quit"?"<<<":"!!!"} ${J}`,h=O||_(),Z=(n,V$)=>{if(V$!==void 0)P.info(`${k} ${n}: ${H(V$)}`,{callerLocation:h});else P.info(`${k} ${n}`,{callerLocation:h})};if(j==="enter")Z("enter",z);else if(j==="quit")Z("quit",Q?.recordResult?z:void 0);else Z("error",z)};return function(...j){let z=c$().getTracer("roy-tracer"),O={};if(Q?.recordParams!==!1)if(Q?.paramFilter){let k=Q.paramFilter(j);if(O.params=X(k),Q?.flattenParamFilter&&k&&typeof k==="object"&&!Array.isArray(k)){for(let[h,Z]of Object.entries(k))if(!(h in O))O[h]=X(Z)}}else O.params=X(j);let P=_(),C;try{C=z.startSpan(J,{attributes:O})}catch{}b("enter",j,P);try{let k=$.call(this,...j);if(k&&typeof k==="object"&&typeof k.then==="function")return k.then((h)=>{if(C){if(Q?.resultFilter){let n=Q.resultFilter(h);if(n&&typeof n==="object")for(let[V$,$0]of Object.entries(n))C.setAttribute(V$,X($0))}C.setAttribute("result",JSON.stringify(X(h)));let Z=Q?.errorIf?Q.errorIf(h):void 0;if(Z){let n=Z instanceof Error?Z:Error(String(Z));C.setAttribute("error",n.message),C.end(void 0,n)}else C.end(h)}return b("quit",Q?.recordResult?h:void 0,P),h},(h)=>{if(C)C.setAttribute("error",String(h)),C.end(void 0,h instanceof Error?h:Error(String(h)));throw b("error",h.message,P),h});if(C){if(Q?.resultFilter){let Z=Q.resultFilter(k);if(Z&&typeof Z==="object")for(let[n,V$]of Object.entries(Z))C.setAttribute(n,X(V$))}C.setAttribute("result",JSON.stringify(X(k)));let h=Q?.errorIf?Q.errorIf(k):void 0;if(h){let Z=h instanceof Error?h:Error(String(h));C.setAttribute("error",Z.message),C.end(void 0,Z)}else C.end(k)}return b("quit",Q?.recordResult?k:void 0,P),k}catch(k){if(C)C.setAttribute("error",String(k)),C.end(void 0,k instanceof Error?k:Error(String(k)));throw b("error",k.message,P),k}}}var I1=J$(()=>{Z0(),W$()});import{AsyncLocalStorage as TJ}from"async_hooks";var ZJ=()=>{};function g1(){return W0.getStore()||{}}function xJ(){return W0.getStore()?.agentContext?.currentTaskId}function h1($){return typeof $==="number"&&Number.isInteger($)&&$>0?$:void 0}var y1,W0,mJ,n$,Y0=J$(()=>{W$(),I1(),ZJ(),y1=Q$("env:context:env-context"),W0=new TJ,mJ=T0(function(J,Q){return h1(J?.metadata?.parentTaskId)??h1(Q?.parentTaskId)},"env-context.resolveEnvParentTaskId",{recordParams:!1,recordResult:!1,log:!1,resultFilter:($)=>({parentTaskId:$??null})}),n$=T0(function(J){let Q=xJ(),W=W0.getStore();if(W){if(!W.agentContext)W.agentContext={};W.agentContext.currentTaskId=J}y1.info(`[setCurrentTaskId] taskId=${J??"undefined"} (was: ${Q??"undefined"})`)},"env-context.setCurrentTaskId",{recordParams:!0,recordResult:!1,log:!0})});var U={};JJ(U,{void:()=>L6,util:()=>v,unknown:()=>O6,union:()=>v6,undefined:()=>j6,tuple:()=>C6,transformer:()=>l6,symbol:()=>b6,string:()=>i1,strictObject:()=>E6,setErrorMap:()=>cJ,set:()=>h6,record:()=>k6,quotelessJson:()=>lJ,promise:()=>m6,preprocess:()=>n6,pipeline:()=>i6,ostring:()=>d6,optional:()=>u6,onumber:()=>p6,oboolean:()=>o6,objectUtil:()=>x0,object:()=>S6,number:()=>d1,nullable:()=>c6,null:()=>N6,never:()=>F6,nativeEnum:()=>x6,nan:()=>A6,map:()=>I6,makeIssue:()=>i$,literal:()=>Z6,lazy:()=>g6,late:()=>V6,isValid:()=>D$,isDirty:()=>H0,isAsync:()=>S$,isAborted:()=>B0,intersection:()=>f6,instanceof:()=>D6,getParsedType:()=>Y$,getErrorMap:()=>w$,function:()=>y6,enum:()=>T6,effect:()=>l6,discriminatedUnion:()=>P6,defaultErrorMap:()=>M$,datetimeRegex:()=>u1,date:()=>K6,custom:()=>n1,coerce:()=>r6,boolean:()=>p1,bigint:()=>z6,array:()=>w6,any:()=>R6,addIssueToContext:()=>K,ZodVoid:()=>p$,ZodUnknown:()=>A$,ZodUnion:()=>k$,ZodUndefined:()=>f$,ZodType:()=>E,ZodTuple:()=>H$,ZodTransformer:()=>t,ZodSymbol:()=>d$,ZodString:()=>o,ZodSet:()=>O$,ZodSchema:()=>E,ZodRecord:()=>o$,ZodReadonly:()=>x$,ZodPromise:()=>F$,ZodPipeline:()=>s$,ZodParsedType:()=>A,ZodOptional:()=>a,ZodObject:()=>g,ZodNumber:()=>z$,ZodNullable:()=>U$,ZodNull:()=>C$,ZodNever:()=>B$,ZodNativeEnum:()=>g$,ZodNaN:()=>a$,ZodMap:()=>r$,ZodLiteral:()=>y$,ZodLazy:()=>h$,ZodIssueCode:()=>V,ZodIntersection:()=>I$,ZodFunction:()=>v$,ZodFirstPartyTypeKind:()=>D,ZodError:()=>l,ZodEnum:()=>b$,ZodEffects:()=>t,ZodDiscriminatedUnion:()=>X0,ZodDefault:()=>Z$,ZodDate:()=>N$,ZodCatch:()=>T$,ZodBranded:()=>q0,ZodBoolean:()=>P$,ZodBigInt:()=>K$,ZodArray:()=>r,ZodAny:()=>R$,Schema:()=>E,ParseStatus:()=>x,OK:()=>u,NEVER:()=>a6,INVALID:()=>R,EMPTY_PATH:()=>nJ,DIRTY:()=>j$,BRAND:()=>U6});var v;(function($){$.assertEqual=(Y)=>{};function J(Y){}$.assertIs=J;function Q(Y){throw Error()}$.assertNever=Q,$.arrayToEnum=(Y)=>{let B={};for(let H of Y)B[H]=H;return B},$.getValidEnumValues=(Y)=>{let B=$.objectKeys(Y).filter((X)=>typeof Y[Y[X]]!=="number"),H={};for(let X of B)H[X]=Y[X];return $.objectValues(H)},$.objectValues=(Y)=>{return $.objectKeys(Y).map(function(B){return Y[B]})},$.objectKeys=typeof Object.keys==="function"?(Y)=>Object.keys(Y):(Y)=>{let B=[];for(let H in Y)if(Object.prototype.hasOwnProperty.call(Y,H))B.push(H);return B},$.find=(Y,B)=>{for(let H of Y)if(B(H))return H;return},$.isInteger=typeof Number.isInteger==="function"?(Y)=>Number.isInteger(Y):(Y)=>typeof Y==="number"&&Number.isFinite(Y)&&Math.floor(Y)===Y;function W(Y,B=" | "){return Y.map((H)=>typeof H==="string"?`'${H}'`:H).join(B)}$.joinValues=W,$.jsonStringifyReplacer=(Y,B)=>{if(typeof B==="bigint")return B.toString();return B}})(v||(v={}));var x0;(function($){$.mergeShapes=(J,Q)=>{return{...J,...Q}}})(x0||(x0={}));var A=v.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Y$=($)=>{switch(typeof $){case"undefined":return A.undefined;case"string":return A.string;case"number":return Number.isNaN($)?A.nan:A.number;case"boolean":return A.boolean;case"function":return A.function;case"bigint":return A.bigint;case"symbol":return A.symbol;case"object":if(Array.isArray($))return A.array;if($===null)return A.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return A.promise;if(typeof Map<"u"&&$ instanceof Map)return A.map;if(typeof Set<"u"&&$ instanceof Set)return A.set;if(typeof Date<"u"&&$ instanceof Date)return A.date;return A.object;default:return A.unknown}};var V=v.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),lJ=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class l extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(Q)=>{this.issues=[...this.issues,Q]},this.addIssues=(Q=[])=>{this.issues=[...this.issues,...Q]};let J=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,J);else this.__proto__=J;this.name="ZodError",this.issues=$}format($){let J=$||function(Y){return Y.message},Q={_errors:[]},W=(Y)=>{for(let B of Y.issues)if(B.code==="invalid_union")B.unionErrors.map(W);else if(B.code==="invalid_return_type")W(B.returnTypeError);else if(B.code==="invalid_arguments")W(B.argumentsError);else if(B.path.length===0)Q._errors.push(J(B));else{let H=Q,X=0;while(X<B.path.length){let q=B.path[X];if(X!==B.path.length-1)H[q]=H[q]||{_errors:[]};else H[q]=H[q]||{_errors:[]},H[q]._errors.push(J(B));H=H[q],X++}}};return W(this),Q}static assert($){if(!($ instanceof l))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,v.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(J)=>J.message){let J={},Q=[];for(let W of this.issues)if(W.path.length>0){let Y=W.path[0];J[Y]=J[Y]||[],J[Y].push($(W))}else Q.push($(W));return{formErrors:Q,fieldErrors:J}}get formErrors(){return this.flatten()}}l.create=($)=>{return new l($)};var uJ=($,J)=>{let Q;switch($.code){case V.invalid_type:if($.received===A.undefined)Q="Required";else Q=`Expected ${$.expected}, received ${$.received}`;break;case V.invalid_literal:Q=`Invalid literal value, expected ${JSON.stringify($.expected,v.jsonStringifyReplacer)}`;break;case V.unrecognized_keys:Q=`Unrecognized key(s) in object: ${v.joinValues($.keys,", ")}`;break;case V.invalid_union:Q="Invalid input";break;case V.invalid_union_discriminator:Q=`Invalid discriminator value. Expected ${v.joinValues($.options)}`;break;case V.invalid_enum_value:Q=`Invalid enum value. Expected ${v.joinValues($.options)}, received '${$.received}'`;break;case V.invalid_arguments:Q="Invalid function arguments";break;case V.invalid_return_type:Q="Invalid function return type";break;case V.invalid_date:Q="Invalid date";break;case V.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(Q=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")Q=`${Q} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)Q=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)Q=`Invalid input: must end with "${$.validation.endsWith}"`;else v.assertNever($.validation);else if($.validation!=="regex")Q=`Invalid ${$.validation}`;else Q="Invalid";break;case V.too_small:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else Q="Invalid input";break;case V.too_big:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")Q=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else Q="Invalid input";break;case V.custom:Q="Invalid input";break;case V.invalid_intersection_types:Q="Intersection results could not be merged";break;case V.not_multiple_of:Q=`Number must be a multiple of ${$.multipleOf}`;break;case V.not_finite:Q="Number must be finite";break;default:Q=J.defaultError,v.assertNever($)}return{message:Q}},M$=uJ;var Z1=M$;function cJ($){Z1=$}function w$(){return Z1}var i$=($)=>{let{data:J,path:Q,errorMaps:W,issueData:Y}=$,B=[...Q,...Y.path||[]],H={...Y,path:B};if(Y.message!==void 0)return{...Y,path:B,message:Y.message};let X="",q=W.filter((_)=>!!_).slice().reverse();for(let _ of q)X=_(H,{data:J,defaultError:X}).message;return{...Y,path:B,message:X}},nJ=[];function K($,J){let Q=w$(),W=i$({issueData:J,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,Q,Q===M$?void 0:M$].filter((Y)=>!!Y)});$.common.issues.push(W)}class x{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,J){let Q=[];for(let W of J){if(W.status==="aborted")return R;if(W.status==="dirty")$.dirty();Q.push(W.value)}return{status:$.value,value:Q}}static async mergeObjectAsync($,J){let Q=[];for(let W of J){let Y=await W.key,B=await W.value;Q.push({key:Y,value:B})}return x.mergeObjectSync($,Q)}static mergeObjectSync($,J){let Q={};for(let W of J){let{key:Y,value:B}=W;if(Y.status==="aborted")return R;if(B.status==="aborted")return R;if(Y.status==="dirty")$.dirty();if(B.status==="dirty")$.dirty();if(Y.value!=="__proto__"&&(typeof B.value<"u"||W.alwaysSet))Q[Y.value]=B.value}return{status:$.value,value:Q}}}var R=Object.freeze({status:"aborted"}),j$=($)=>({status:"dirty",value:$}),u=($)=>({status:"valid",value:$}),B0=($)=>$.status==="aborted",H0=($)=>$.status==="dirty",D$=($)=>$.status==="valid",S$=($)=>typeof Promise<"u"&&$ instanceof Promise;var N;(function($){$.errToObj=(J)=>typeof J==="string"?{message:J}:J||{},$.toString=(J)=>typeof J==="string"?J:J?.message})(N||(N={}));class s{constructor($,J,Q,W){this._cachedPath=[],this.parent=$,this.data=J,this._path=Q,this._key=W}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var T1=($,J)=>{if(D$(J))return{success:!0,data:J.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let Q=new l($.common.issues);return this._error=Q,this._error}}}};function S($){if(!$)return{};let{errorMap:J,invalid_type_error:Q,required_error:W,description:Y}=$;if(J&&(Q||W))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(J)return{errorMap:J,description:Y};return{errorMap:(H,X)=>{let{message:q}=$;if(H.code==="invalid_enum_value")return{message:q??X.defaultError};if(typeof X.data>"u")return{message:q??W??X.defaultError};if(H.code!=="invalid_type")return{message:X.defaultError};return{message:q??Q??X.defaultError}},description:Y}}class E{get description(){return this._def.description}_getType($){return Y$($.data)}_getOrReturnCtx($,J){return J||{common:$.parent.common,data:$.data,parsedType:Y$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new x,ctx:{common:$.parent.common,data:$.data,parsedType:Y$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let J=this._parse($);if(S$(J))throw Error("Synchronous parse encountered promise.");return J}_parseAsync($){let J=this._parse($);return Promise.resolve(J)}parse($,J){let Q=this.safeParse($,J);if(Q.success)return Q.data;throw Q.error}safeParse($,J){let Q={common:{issues:[],async:J?.async??!1,contextualErrorMap:J?.errorMap},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:Y$($)},W=this._parseSync({data:$,path:Q.path,parent:Q});return T1(Q,W)}"~validate"($){let J={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:Y$($)};if(!this["~standard"].async)try{let Q=this._parseSync({data:$,path:[],parent:J});return D$(Q)?{value:Q.value}:{issues:J.common.issues}}catch(Q){if(Q?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;J.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:J}).then((Q)=>D$(Q)?{value:Q.value}:{issues:J.common.issues})}async parseAsync($,J){let Q=await this.safeParseAsync($,J);if(Q.success)return Q.data;throw Q.error}async safeParseAsync($,J){let Q={common:{issues:[],contextualErrorMap:J?.errorMap,async:!0},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:Y$($)},W=this._parse({data:$,path:Q.path,parent:Q}),Y=await(S$(W)?W:Promise.resolve(W));return T1(Q,Y)}refine($,J){let Q=(W)=>{if(typeof J==="string"||typeof J>"u")return{message:J};else if(typeof J==="function")return J(W);else return J};return this._refinement((W,Y)=>{let B=$(W),H=()=>Y.addIssue({code:V.custom,...Q(W)});if(typeof Promise<"u"&&B instanceof Promise)return B.then((X)=>{if(!X)return H(),!1;else return!0});if(!B)return H(),!1;else return!0})}refinement($,J){return this._refinement((Q,W)=>{if(!$(Q))return W.addIssue(typeof J==="function"?J(Q,W):J),!1;else return!0})}_refinement($){return new t({schema:this,typeName:D.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(J)=>this["~validate"](J)}}optional(){return a.create(this,this._def)}nullable(){return U$.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return r.create(this)}promise(){return F$.create(this,this._def)}or($){return k$.create([this,$],this._def)}and($){return I$.create(this,$,this._def)}transform($){return new t({...S(this._def),schema:this,typeName:D.ZodEffects,effect:{type:"transform",transform:$}})}default($){let J=typeof $==="function"?$:()=>$;return new Z$({...S(this._def),innerType:this,defaultValue:J,typeName:D.ZodDefault})}brand(){return new q0({typeName:D.ZodBranded,type:this,...S(this._def)})}catch($){let J=typeof $==="function"?$:()=>$;return new T$({...S(this._def),innerType:this,catchValue:J,typeName:D.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return s$.create(this,$)}readonly(){return x$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var iJ=/^c[^\s-]{8,}$/i,dJ=/^[0-9a-z]+$/,pJ=/^[0-9A-HJKMNP-TV-Z]{26}$/i,oJ=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,rJ=/^[a-z0-9_-]{21}$/i,aJ=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,sJ=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,tJ=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,eJ="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",m0,$6=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,J6=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Q6=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,W6=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Y6=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,B6=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,m1="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",H6=new RegExp(`^${m1}$`);function l1($){let J="[0-5]\\d";if($.precision)J=`${J}\\.\\d{${$.precision}}`;else if($.precision==null)J=`${J}(\\.\\d+)?`;let Q=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${J})${Q}`}function X6($){return new RegExp(`^${l1($)}$`)}function u1($){let J=`${m1}T${l1($)}`,Q=[];if(Q.push($.local?"Z?":"Z"),$.offset)Q.push("([+-]\\d{2}:?\\d{2})");return J=`${J}(${Q.join("|")})`,new RegExp(`^${J}$`)}function q6($,J){if((J==="v4"||!J)&&$6.test($))return!0;if((J==="v6"||!J)&&Q6.test($))return!0;return!1}function G6($,J){if(!aJ.test($))return!1;try{let[Q]=$.split(".");if(!Q)return!1;let W=Q.replace(/-/g,"+").replace(/_/g,"/").padEnd(Q.length+(4-Q.length%4)%4,"="),Y=JSON.parse(atob(W));if(typeof Y!=="object"||Y===null)return!1;if("typ"in Y&&Y?.typ!=="JWT")return!1;if(!Y.alg)return!1;if(J&&Y.alg!==J)return!1;return!0}catch{return!1}}function M6($,J){if((J==="v4"||!J)&&J6.test($))return!0;if((J==="v6"||!J)&&W6.test($))return!0;return!1}class o extends E{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==A.string){let Y=this._getOrReturnCtx($);return K(Y,{code:V.invalid_type,expected:A.string,received:Y.parsedType}),R}let Q=new x,W=void 0;for(let Y of this._def.checks)if(Y.kind==="min"){if($.data.length<Y.value)W=this._getOrReturnCtx($,W),K(W,{code:V.too_small,minimum:Y.value,type:"string",inclusive:!0,exact:!1,message:Y.message}),Q.dirty()}else if(Y.kind==="max"){if($.data.length>Y.value)W=this._getOrReturnCtx($,W),K(W,{code:V.too_big,maximum:Y.value,type:"string",inclusive:!0,exact:!1,message:Y.message}),Q.dirty()}else if(Y.kind==="length"){let B=$.data.length>Y.value,H=$.data.length<Y.value;if(B||H){if(W=this._getOrReturnCtx($,W),B)K(W,{code:V.too_big,maximum:Y.value,type:"string",inclusive:!0,exact:!0,message:Y.message});else if(H)K(W,{code:V.too_small,minimum:Y.value,type:"string",inclusive:!0,exact:!0,message:Y.message});Q.dirty()}}else if(Y.kind==="email"){if(!tJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"email",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="emoji"){if(!m0)m0=new RegExp(eJ,"u");if(!m0.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"emoji",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="uuid"){if(!oJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"uuid",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="nanoid"){if(!rJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"nanoid",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="cuid"){if(!iJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"cuid",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="cuid2"){if(!dJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"cuid2",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="ulid"){if(!pJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"ulid",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="url")try{new URL($.data)}catch{W=this._getOrReturnCtx($,W),K(W,{validation:"url",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="regex"){if(Y.regex.lastIndex=0,!Y.regex.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"regex",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="trim")$.data=$.data.trim();else if(Y.kind==="includes"){if(!$.data.includes(Y.value,Y.position))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:{includes:Y.value,position:Y.position},message:Y.message}),Q.dirty()}else if(Y.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(Y.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(Y.kind==="startsWith"){if(!$.data.startsWith(Y.value))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:{startsWith:Y.value},message:Y.message}),Q.dirty()}else if(Y.kind==="endsWith"){if(!$.data.endsWith(Y.value))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:{endsWith:Y.value},message:Y.message}),Q.dirty()}else if(Y.kind==="datetime"){if(!u1(Y).test($.data))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:"datetime",message:Y.message}),Q.dirty()}else if(Y.kind==="date"){if(!H6.test($.data))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:"date",message:Y.message}),Q.dirty()}else if(Y.kind==="time"){if(!X6(Y).test($.data))W=this._getOrReturnCtx($,W),K(W,{code:V.invalid_string,validation:"time",message:Y.message}),Q.dirty()}else if(Y.kind==="duration"){if(!sJ.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"duration",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="ip"){if(!q6($.data,Y.version))W=this._getOrReturnCtx($,W),K(W,{validation:"ip",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="jwt"){if(!G6($.data,Y.alg))W=this._getOrReturnCtx($,W),K(W,{validation:"jwt",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="cidr"){if(!M6($.data,Y.version))W=this._getOrReturnCtx($,W),K(W,{validation:"cidr",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="base64"){if(!Y6.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"base64",code:V.invalid_string,message:Y.message}),Q.dirty()}else if(Y.kind==="base64url"){if(!B6.test($.data))W=this._getOrReturnCtx($,W),K(W,{validation:"base64url",code:V.invalid_string,message:Y.message}),Q.dirty()}else v.assertNever(Y);return{status:Q.value,value:$.data}}_regex($,J,Q){return this.refinement((W)=>$.test(W),{validation:J,code:V.invalid_string,...N.errToObj(Q)})}_addCheck($){return new o({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...N.errToObj($)})}url($){return this._addCheck({kind:"url",...N.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...N.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...N.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...N.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...N.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...N.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...N.errToObj($)})}base64($){return this._addCheck({kind:"base64",...N.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...N.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...N.errToObj($)})}ip($){return this._addCheck({kind:"ip",...N.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...N.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...N.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...N.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...N.errToObj($)})}regex($,J){return this._addCheck({kind:"regex",regex:$,...N.errToObj(J)})}includes($,J){return this._addCheck({kind:"includes",value:$,position:J?.position,...N.errToObj(J?.message)})}startsWith($,J){return this._addCheck({kind:"startsWith",value:$,...N.errToObj(J)})}endsWith($,J){return this._addCheck({kind:"endsWith",value:$,...N.errToObj(J)})}min($,J){return this._addCheck({kind:"min",value:$,...N.errToObj(J)})}max($,J){return this._addCheck({kind:"max",value:$,...N.errToObj(J)})}length($,J){return this._addCheck({kind:"length",value:$,...N.errToObj(J)})}nonempty($){return this.min(1,N.errToObj($))}trim(){return new o({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new o({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new o({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxLength(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}o.create=($)=>{return new o({checks:[],typeName:D.ZodString,coerce:$?.coerce??!1,...S($)})};function _6($,J){let Q=($.toString().split(".")[1]||"").length,W=(J.toString().split(".")[1]||"").length,Y=Q>W?Q:W,B=Number.parseInt($.toFixed(Y).replace(".","")),H=Number.parseInt(J.toFixed(Y).replace(".",""));return B%H/10**Y}class z$ extends E{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==A.number){let Y=this._getOrReturnCtx($);return K(Y,{code:V.invalid_type,expected:A.number,received:Y.parsedType}),R}let Q=void 0,W=new x;for(let Y of this._def.checks)if(Y.kind==="int"){if(!v.isInteger($.data))Q=this._getOrReturnCtx($,Q),K(Q,{code:V.invalid_type,expected:"integer",received:"float",message:Y.message}),W.dirty()}else if(Y.kind==="min"){if(Y.inclusive?$.data<Y.value:$.data<=Y.value)Q=this._getOrReturnCtx($,Q),K(Q,{code:V.too_small,minimum:Y.value,type:"number",inclusive:Y.inclusive,exact:!1,message:Y.message}),W.dirty()}else if(Y.kind==="max"){if(Y.inclusive?$.data>Y.value:$.data>=Y.value)Q=this._getOrReturnCtx($,Q),K(Q,{code:V.too_big,maximum:Y.value,type:"number",inclusive:Y.inclusive,exact:!1,message:Y.message}),W.dirty()}else if(Y.kind==="multipleOf"){if(_6($.data,Y.value)!==0)Q=this._getOrReturnCtx($,Q),K(Q,{code:V.not_multiple_of,multipleOf:Y.value,message:Y.message}),W.dirty()}else if(Y.kind==="finite"){if(!Number.isFinite($.data))Q=this._getOrReturnCtx($,Q),K(Q,{code:V.not_finite,message:Y.message}),W.dirty()}else v.assertNever(Y);return{status:W.value,value:$.data}}gte($,J){return this.setLimit("min",$,!0,N.toString(J))}gt($,J){return this.setLimit("min",$,!1,N.toString(J))}lte($,J){return this.setLimit("max",$,!0,N.toString(J))}lt($,J){return this.setLimit("max",$,!1,N.toString(J))}setLimit($,J,Q,W){return new z$({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:N.toString(W)}]})}_addCheck($){return new z$({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:N.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:N.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:N.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:N.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:N.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:N.toString(J)})}finite($){return this._addCheck({kind:"finite",message:N.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:N.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:N.toString($)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&v.isInteger($.value))}get isFinite(){let $=null,J=null;for(let Q of this._def.checks)if(Q.kind==="finite"||Q.kind==="int"||Q.kind==="multipleOf")return!0;else if(Q.kind==="min"){if(J===null||Q.value>J)J=Q.value}else if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return Number.isFinite(J)&&Number.isFinite($)}}z$.create=($)=>{return new z$({checks:[],typeName:D.ZodNumber,coerce:$?.coerce||!1,...S($)})};class K$ extends E{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==A.bigint)return this._getInvalidInput($);let Q=void 0,W=new x;for(let Y of this._def.checks)if(Y.kind==="min"){if(Y.inclusive?$.data<Y.value:$.data<=Y.value)Q=this._getOrReturnCtx($,Q),K(Q,{code:V.too_small,type:"bigint",minimum:Y.value,inclusive:Y.inclusive,message:Y.message}),W.dirty()}else if(Y.kind==="max"){if(Y.inclusive?$.data>Y.value:$.data>=Y.value)Q=this._getOrReturnCtx($,Q),K(Q,{code:V.too_big,type:"bigint",maximum:Y.value,inclusive:Y.inclusive,message:Y.message}),W.dirty()}else if(Y.kind==="multipleOf"){if($.data%Y.value!==BigInt(0))Q=this._getOrReturnCtx($,Q),K(Q,{code:V.not_multiple_of,multipleOf:Y.value,message:Y.message}),W.dirty()}else v.assertNever(Y);return{status:W.value,value:$.data}}_getInvalidInput($){let J=this._getOrReturnCtx($);return K(J,{code:V.invalid_type,expected:A.bigint,received:J.parsedType}),R}gte($,J){return this.setLimit("min",$,!0,N.toString(J))}gt($,J){return this.setLimit("min",$,!1,N.toString(J))}lte($,J){return this.setLimit("max",$,!0,N.toString(J))}lt($,J){return this.setLimit("max",$,!1,N.toString(J))}setLimit($,J,Q,W){return new K$({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:N.toString(W)}]})}_addCheck($){return new K$({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:N.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:N.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:N.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:N.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:N.toString(J)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}K$.create=($)=>{return new K$({checks:[],typeName:D.ZodBigInt,coerce:$?.coerce??!1,...S($)})};class P$ extends E{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==A.boolean){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.boolean,received:Q.parsedType}),R}return u($.data)}}P$.create=($)=>{return new P$({typeName:D.ZodBoolean,coerce:$?.coerce||!1,...S($)})};class N$ extends E{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==A.date){let Y=this._getOrReturnCtx($);return K(Y,{code:V.invalid_type,expected:A.date,received:Y.parsedType}),R}if(Number.isNaN($.data.getTime())){let Y=this._getOrReturnCtx($);return K(Y,{code:V.invalid_date}),R}let Q=new x,W=void 0;for(let Y of this._def.checks)if(Y.kind==="min"){if($.data.getTime()<Y.value)W=this._getOrReturnCtx($,W),K(W,{code:V.too_small,message:Y.message,inclusive:!0,exact:!1,minimum:Y.value,type:"date"}),Q.dirty()}else if(Y.kind==="max"){if($.data.getTime()>Y.value)W=this._getOrReturnCtx($,W),K(W,{code:V.too_big,message:Y.message,inclusive:!0,exact:!1,maximum:Y.value,type:"date"}),Q.dirty()}else v.assertNever(Y);return{status:Q.value,value:new Date($.data.getTime())}}_addCheck($){return new N$({...this._def,checks:[...this._def.checks,$]})}min($,J){return this._addCheck({kind:"min",value:$.getTime(),message:N.toString(J)})}max($,J){return this._addCheck({kind:"max",value:$.getTime(),message:N.toString(J)})}get minDate(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $!=null?new Date($):null}}N$.create=($)=>{return new N$({checks:[],coerce:$?.coerce||!1,typeName:D.ZodDate,...S($)})};class d$ extends E{_parse($){if(this._getType($)!==A.symbol){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.symbol,received:Q.parsedType}),R}return u($.data)}}d$.create=($)=>{return new d$({typeName:D.ZodSymbol,...S($)})};class f$ extends E{_parse($){if(this._getType($)!==A.undefined){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.undefined,received:Q.parsedType}),R}return u($.data)}}f$.create=($)=>{return new f$({typeName:D.ZodUndefined,...S($)})};class C$ extends E{_parse($){if(this._getType($)!==A.null){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.null,received:Q.parsedType}),R}return u($.data)}}C$.create=($)=>{return new C$({typeName:D.ZodNull,...S($)})};class R$ extends E{constructor(){super(...arguments);this._any=!0}_parse($){return u($.data)}}R$.create=($)=>{return new R$({typeName:D.ZodAny,...S($)})};class A$ extends E{constructor(){super(...arguments);this._unknown=!0}_parse($){return u($.data)}}A$.create=($)=>{return new A$({typeName:D.ZodUnknown,...S($)})};class B$ extends E{_parse($){let J=this._getOrReturnCtx($);return K(J,{code:V.invalid_type,expected:A.never,received:J.parsedType}),R}}B$.create=($)=>{return new B$({typeName:D.ZodNever,...S($)})};class p$ extends E{_parse($){if(this._getType($)!==A.undefined){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.void,received:Q.parsedType}),R}return u($.data)}}p$.create=($)=>{return new p$({typeName:D.ZodVoid,...S($)})};class r extends E{_parse($){let{ctx:J,status:Q}=this._processInputParams($),W=this._def;if(J.parsedType!==A.array)return K(J,{code:V.invalid_type,expected:A.array,received:J.parsedType}),R;if(W.exactLength!==null){let B=J.data.length>W.exactLength.value,H=J.data.length<W.exactLength.value;if(B||H)K(J,{code:B?V.too_big:V.too_small,minimum:H?W.exactLength.value:void 0,maximum:B?W.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:W.exactLength.message}),Q.dirty()}if(W.minLength!==null){if(J.data.length<W.minLength.value)K(J,{code:V.too_small,minimum:W.minLength.value,type:"array",inclusive:!0,exact:!1,message:W.minLength.message}),Q.dirty()}if(W.maxLength!==null){if(J.data.length>W.maxLength.value)K(J,{code:V.too_big,maximum:W.maxLength.value,type:"array",inclusive:!0,exact:!1,message:W.maxLength.message}),Q.dirty()}if(J.common.async)return Promise.all([...J.data].map((B,H)=>{return W.type._parseAsync(new s(J,B,J.path,H))})).then((B)=>{return x.mergeArray(Q,B)});let Y=[...J.data].map((B,H)=>{return W.type._parseSync(new s(J,B,J.path,H))});return x.mergeArray(Q,Y)}get element(){return this._def.type}min($,J){return new r({...this._def,minLength:{value:$,message:N.toString(J)}})}max($,J){return new r({...this._def,maxLength:{value:$,message:N.toString(J)}})}length($,J){return new r({...this._def,exactLength:{value:$,message:N.toString(J)}})}nonempty($){return this.min(1,$)}}r.create=($,J)=>{return new r({type:$,minLength:null,maxLength:null,exactLength:null,typeName:D.ZodArray,...S(J)})};function E$($){if($ instanceof g){let J={};for(let Q in $.shape){let W=$.shape[Q];J[Q]=a.create(E$(W))}return new g({...$._def,shape:()=>J})}else if($ instanceof r)return new r({...$._def,type:E$($.element)});else if($ instanceof a)return a.create(E$($.unwrap()));else if($ instanceof U$)return U$.create(E$($.unwrap()));else if($ instanceof H$)return H$.create($.items.map((J)=>E$(J)));else return $}class g extends E{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),J=v.objectKeys($);return this._cached={shape:$,keys:J},this._cached}_parse($){if(this._getType($)!==A.object){let q=this._getOrReturnCtx($);return K(q,{code:V.invalid_type,expected:A.object,received:q.parsedType}),R}let{status:Q,ctx:W}=this._processInputParams($),{shape:Y,keys:B}=this._getCached(),H=[];if(!(this._def.catchall instanceof B$&&this._def.unknownKeys==="strip")){for(let q in W.data)if(!B.includes(q))H.push(q)}let X=[];for(let q of B){let _=Y[q],b=W.data[q];X.push({key:{status:"valid",value:q},value:_._parse(new s(W,b,W.path,q)),alwaysSet:q in W.data})}if(this._def.catchall instanceof B$){let q=this._def.unknownKeys;if(q==="passthrough")for(let _ of H)X.push({key:{status:"valid",value:_},value:{status:"valid",value:W.data[_]}});else if(q==="strict"){if(H.length>0)K(W,{code:V.unrecognized_keys,keys:H}),Q.dirty()}else if(q==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let q=this._def.catchall;for(let _ of H){let b=W.data[_];X.push({key:{status:"valid",value:_},value:q._parse(new s(W,b,W.path,_)),alwaysSet:_ in W.data})}}if(W.common.async)return Promise.resolve().then(async()=>{let q=[];for(let _ of X){let b=await _.key,j=await _.value;q.push({key:b,value:j,alwaysSet:_.alwaysSet})}return q}).then((q)=>{return x.mergeObjectSync(Q,q)});else return x.mergeObjectSync(Q,X)}get shape(){return this._def.shape()}strict($){return N.errToObj,new g({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(J,Q)=>{let W=this._def.errorMap?.(J,Q).message??Q.defaultError;if(J.code==="unrecognized_keys")return{message:N.errToObj($).message??W};return{message:W}}}:{}})}strip(){return new g({...this._def,unknownKeys:"strip"})}passthrough(){return new g({...this._def,unknownKeys:"passthrough"})}extend($){return new g({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new g({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:D.ZodObject})}setKey($,J){return this.augment({[$]:J})}catchall($){return new g({...this._def,catchall:$})}pick($){let J={};for(let Q of v.objectKeys($))if($[Q]&&this.shape[Q])J[Q]=this.shape[Q];return new g({...this._def,shape:()=>J})}omit($){let J={};for(let Q of v.objectKeys(this.shape))if(!$[Q])J[Q]=this.shape[Q];return new g({...this._def,shape:()=>J})}deepPartial(){return E$(this)}partial($){let J={};for(let Q of v.objectKeys(this.shape)){let W=this.shape[Q];if($&&!$[Q])J[Q]=W;else J[Q]=W.optional()}return new g({...this._def,shape:()=>J})}required($){let J={};for(let Q of v.objectKeys(this.shape))if($&&!$[Q])J[Q]=this.shape[Q];else{let Y=this.shape[Q];while(Y instanceof a)Y=Y._def.innerType;J[Q]=Y}return new g({...this._def,shape:()=>J})}keyof(){return c1(v.objectKeys(this.shape))}}g.create=($,J)=>{return new g({shape:()=>$,unknownKeys:"strip",catchall:B$.create(),typeName:D.ZodObject,...S(J)})};g.strictCreate=($,J)=>{return new g({shape:()=>$,unknownKeys:"strict",catchall:B$.create(),typeName:D.ZodObject,...S(J)})};g.lazycreate=($,J)=>{return new g({shape:$,unknownKeys:"strip",catchall:B$.create(),typeName:D.ZodObject,...S(J)})};class k$ extends E{_parse($){let{ctx:J}=this._processInputParams($),Q=this._def.options;function W(Y){for(let H of Y)if(H.result.status==="valid")return H.result;for(let H of Y)if(H.result.status==="dirty")return J.common.issues.push(...H.ctx.common.issues),H.result;let B=Y.map((H)=>new l(H.ctx.common.issues));return K(J,{code:V.invalid_union,unionErrors:B}),R}if(J.common.async)return Promise.all(Q.map(async(Y)=>{let B={...J,common:{...J.common,issues:[]},parent:null};return{result:await Y._parseAsync({data:J.data,path:J.path,parent:B}),ctx:B}})).then(W);else{let Y=void 0,B=[];for(let X of Q){let q={...J,common:{...J.common,issues:[]},parent:null},_=X._parseSync({data:J.data,path:J.path,parent:q});if(_.status==="valid")return _;else if(_.status==="dirty"&&!Y)Y={result:_,ctx:q};if(q.common.issues.length)B.push(q.common.issues)}if(Y)return J.common.issues.push(...Y.ctx.common.issues),Y.result;let H=B.map((X)=>new l(X));return K(J,{code:V.invalid_union,unionErrors:H}),R}}get options(){return this._def.options}}k$.create=($,J)=>{return new k$({options:$,typeName:D.ZodUnion,...S(J)})};var _$=($)=>{if($ instanceof h$)return _$($.schema);else if($ instanceof t)return _$($.innerType());else if($ instanceof y$)return[$.value];else if($ instanceof b$)return $.options;else if($ instanceof g$)return v.objectValues($.enum);else if($ instanceof Z$)return _$($._def.innerType);else if($ instanceof f$)return[void 0];else if($ instanceof C$)return[null];else if($ instanceof a)return[void 0,..._$($.unwrap())];else if($ instanceof U$)return[null,..._$($.unwrap())];else if($ instanceof q0)return _$($.unwrap());else if($ instanceof x$)return _$($.unwrap());else if($ instanceof T$)return _$($._def.innerType);else return[]};class X0 extends E{_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==A.object)return K(J,{code:V.invalid_type,expected:A.object,received:J.parsedType}),R;let Q=this.discriminator,W=J.data[Q],Y=this.optionsMap.get(W);if(!Y)return K(J,{code:V.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[Q]}),R;if(J.common.async)return Y._parseAsync({data:J.data,path:J.path,parent:J});else return Y._parseSync({data:J.data,path:J.path,parent:J})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,J,Q){let W=new Map;for(let Y of J){let B=_$(Y.shape[$]);if(!B.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let H of B){if(W.has(H))throw Error(`Discriminator property ${String($)} has duplicate value ${String(H)}`);W.set(H,Y)}}return new X0({typeName:D.ZodDiscriminatedUnion,discriminator:$,options:J,optionsMap:W,...S(Q)})}}function l0($,J){let Q=Y$($),W=Y$(J);if($===J)return{valid:!0,data:$};else if(Q===A.object&&W===A.object){let Y=v.objectKeys(J),B=v.objectKeys($).filter((X)=>Y.indexOf(X)!==-1),H={...$,...J};for(let X of B){let q=l0($[X],J[X]);if(!q.valid)return{valid:!1};H[X]=q.data}return{valid:!0,data:H}}else if(Q===A.array&&W===A.array){if($.length!==J.length)return{valid:!1};let Y=[];for(let B=0;B<$.length;B++){let H=$[B],X=J[B],q=l0(H,X);if(!q.valid)return{valid:!1};Y.push(q.data)}return{valid:!0,data:Y}}else if(Q===A.date&&W===A.date&&+$===+J)return{valid:!0,data:$};else return{valid:!1}}class I$ extends E{_parse($){let{status:J,ctx:Q}=this._processInputParams($),W=(Y,B)=>{if(B0(Y)||B0(B))return R;let H=l0(Y.value,B.value);if(!H.valid)return K(Q,{code:V.invalid_intersection_types}),R;if(H0(Y)||H0(B))J.dirty();return{status:J.value,value:H.data}};if(Q.common.async)return Promise.all([this._def.left._parseAsync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseAsync({data:Q.data,path:Q.path,parent:Q})]).then(([Y,B])=>W(Y,B));else return W(this._def.left._parseSync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseSync({data:Q.data,path:Q.path,parent:Q}))}}I$.create=($,J,Q)=>{return new I$({left:$,right:J,typeName:D.ZodIntersection,...S(Q)})};class H$ extends E{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==A.array)return K(Q,{code:V.invalid_type,expected:A.array,received:Q.parsedType}),R;if(Q.data.length<this._def.items.length)return K(Q,{code:V.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),R;if(!this._def.rest&&Q.data.length>this._def.items.length)K(Q,{code:V.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),J.dirty();let Y=[...Q.data].map((B,H)=>{let X=this._def.items[H]||this._def.rest;if(!X)return null;return X._parse(new s(Q,B,Q.path,H))}).filter((B)=>!!B);if(Q.common.async)return Promise.all(Y).then((B)=>{return x.mergeArray(J,B)});else return x.mergeArray(J,Y)}get items(){return this._def.items}rest($){return new H$({...this._def,rest:$})}}H$.create=($,J)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new H$({items:$,typeName:D.ZodTuple,rest:null,...S(J)})};class o$ extends E{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==A.object)return K(Q,{code:V.invalid_type,expected:A.object,received:Q.parsedType}),R;let W=[],Y=this._def.keyType,B=this._def.valueType;for(let H in Q.data)W.push({key:Y._parse(new s(Q,H,Q.path,H)),value:B._parse(new s(Q,Q.data[H],Q.path,H)),alwaysSet:H in Q.data});if(Q.common.async)return x.mergeObjectAsync(J,W);else return x.mergeObjectSync(J,W)}get element(){return this._def.valueType}static create($,J,Q){if(J instanceof E)return new o$({keyType:$,valueType:J,typeName:D.ZodRecord,...S(Q)});return new o$({keyType:o.create(),valueType:$,typeName:D.ZodRecord,...S(J)})}}class r$ extends E{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==A.map)return K(Q,{code:V.invalid_type,expected:A.map,received:Q.parsedType}),R;let W=this._def.keyType,Y=this._def.valueType,B=[...Q.data.entries()].map(([H,X],q)=>{return{key:W._parse(new s(Q,H,Q.path,[q,"key"])),value:Y._parse(new s(Q,X,Q.path,[q,"value"]))}});if(Q.common.async){let H=new Map;return Promise.resolve().then(async()=>{for(let X of B){let q=await X.key,_=await X.value;if(q.status==="aborted"||_.status==="aborted")return R;if(q.status==="dirty"||_.status==="dirty")J.dirty();H.set(q.value,_.value)}return{status:J.value,value:H}})}else{let H=new Map;for(let X of B){let{key:q,value:_}=X;if(q.status==="aborted"||_.status==="aborted")return R;if(q.status==="dirty"||_.status==="dirty")J.dirty();H.set(q.value,_.value)}return{status:J.value,value:H}}}}r$.create=($,J,Q)=>{return new r$({valueType:J,keyType:$,typeName:D.ZodMap,...S(Q)})};class O$ extends E{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==A.set)return K(Q,{code:V.invalid_type,expected:A.set,received:Q.parsedType}),R;let W=this._def;if(W.minSize!==null){if(Q.data.size<W.minSize.value)K(Q,{code:V.too_small,minimum:W.minSize.value,type:"set",inclusive:!0,exact:!1,message:W.minSize.message}),J.dirty()}if(W.maxSize!==null){if(Q.data.size>W.maxSize.value)K(Q,{code:V.too_big,maximum:W.maxSize.value,type:"set",inclusive:!0,exact:!1,message:W.maxSize.message}),J.dirty()}let Y=this._def.valueType;function B(X){let q=new Set;for(let _ of X){if(_.status==="aborted")return R;if(_.status==="dirty")J.dirty();q.add(_.value)}return{status:J.value,value:q}}let H=[...Q.data.values()].map((X,q)=>Y._parse(new s(Q,X,Q.path,q)));if(Q.common.async)return Promise.all(H).then((X)=>B(X));else return B(H)}min($,J){return new O$({...this._def,minSize:{value:$,message:N.toString(J)}})}max($,J){return new O$({...this._def,maxSize:{value:$,message:N.toString(J)}})}size($,J){return this.min($,J).max($,J)}nonempty($){return this.min(1,$)}}O$.create=($,J)=>{return new O$({valueType:$,minSize:null,maxSize:null,typeName:D.ZodSet,...S(J)})};class v$ extends E{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==A.function)return K(J,{code:V.invalid_type,expected:A.function,received:J.parsedType}),R;function Q(H,X){return i$({data:H,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,w$(),M$].filter((q)=>!!q),issueData:{code:V.invalid_arguments,argumentsError:X}})}function W(H,X){return i$({data:H,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,w$(),M$].filter((q)=>!!q),issueData:{code:V.invalid_return_type,returnTypeError:X}})}let Y={errorMap:J.common.contextualErrorMap},B=J.data;if(this._def.returns instanceof F$){let H=this;return u(async function(...X){let q=new l([]),_=await H._def.args.parseAsync(X,Y).catch((z)=>{throw q.addIssue(Q(X,z)),q}),b=await Reflect.apply(B,this,_);return await H._def.returns._def.type.parseAsync(b,Y).catch((z)=>{throw q.addIssue(W(b,z)),q})})}else{let H=this;return u(function(...X){let q=H._def.args.safeParse(X,Y);if(!q.success)throw new l([Q(X,q.error)]);let _=Reflect.apply(B,this,q.data),b=H._def.returns.safeParse(_,Y);if(!b.success)throw new l([W(_,b.error)]);return b.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new v$({...this._def,args:H$.create($).rest(A$.create())})}returns($){return new v$({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,J,Q){return new v$({args:$?$:H$.create([]).rest(A$.create()),returns:J||A$.create(),typeName:D.ZodFunction,...S(Q)})}}class h$ extends E{get schema(){return this._def.getter()}_parse($){let{ctx:J}=this._processInputParams($);return this._def.getter()._parse({data:J.data,path:J.path,parent:J})}}h$.create=($,J)=>{return new h$({getter:$,typeName:D.ZodLazy,...S(J)})};class y$ extends E{_parse($){if($.data!==this._def.value){let J=this._getOrReturnCtx($);return K(J,{received:J.data,code:V.invalid_literal,expected:this._def.value}),R}return{status:"valid",value:$.data}}get value(){return this._def.value}}y$.create=($,J)=>{return new y$({value:$,typeName:D.ZodLiteral,...S(J)})};function c1($,J){return new b$({values:$,typeName:D.ZodEnum,...S(J)})}class b$ extends E{_parse($){if(typeof $.data!=="string"){let J=this._getOrReturnCtx($),Q=this._def.values;return K(J,{expected:v.joinValues(Q),received:J.parsedType,code:V.invalid_type}),R}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let J=this._getOrReturnCtx($),Q=this._def.values;return K(J,{received:J.data,code:V.invalid_enum_value,options:Q}),R}return u($.data)}get options(){return this._def.values}get enum(){let $={};for(let J of this._def.values)$[J]=J;return $}get Values(){let $={};for(let J of this._def.values)$[J]=J;return $}get Enum(){let $={};for(let J of this._def.values)$[J]=J;return $}extract($,J=this._def){return b$.create($,{...this._def,...J})}exclude($,J=this._def){return b$.create(this.options.filter((Q)=>!$.includes(Q)),{...this._def,...J})}}b$.create=c1;class g$ extends E{_parse($){let J=v.getValidEnumValues(this._def.values),Q=this._getOrReturnCtx($);if(Q.parsedType!==A.string&&Q.parsedType!==A.number){let W=v.objectValues(J);return K(Q,{expected:v.joinValues(W),received:Q.parsedType,code:V.invalid_type}),R}if(!this._cache)this._cache=new Set(v.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let W=v.objectValues(J);return K(Q,{received:Q.data,code:V.invalid_enum_value,options:W}),R}return u($.data)}get enum(){return this._def.values}}g$.create=($,J)=>{return new g$({values:$,typeName:D.ZodNativeEnum,...S(J)})};class F$ extends E{unwrap(){return this._def.type}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==A.promise&&J.common.async===!1)return K(J,{code:V.invalid_type,expected:A.promise,received:J.parsedType}),R;let Q=J.parsedType===A.promise?J.data:Promise.resolve(J.data);return u(Q.then((W)=>{return this._def.type.parseAsync(W,{path:J.path,errorMap:J.common.contextualErrorMap})}))}}F$.create=($,J)=>{return new F$({type:$,typeName:D.ZodPromise,...S(J)})};class t extends E{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===D.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:J,ctx:Q}=this._processInputParams($),W=this._def.effect||null,Y={addIssue:(B)=>{if(K(Q,B),B.fatal)J.abort();else J.dirty()},get path(){return Q.path}};if(Y.addIssue=Y.addIssue.bind(Y),W.type==="preprocess"){let B=W.transform(Q.data,Y);if(Q.common.async)return Promise.resolve(B).then(async(H)=>{if(J.value==="aborted")return R;let X=await this._def.schema._parseAsync({data:H,path:Q.path,parent:Q});if(X.status==="aborted")return R;if(X.status==="dirty")return j$(X.value);if(J.value==="dirty")return j$(X.value);return X});else{if(J.value==="aborted")return R;let H=this._def.schema._parseSync({data:B,path:Q.path,parent:Q});if(H.status==="aborted")return R;if(H.status==="dirty")return j$(H.value);if(J.value==="dirty")return j$(H.value);return H}}if(W.type==="refinement"){let B=(H)=>{let X=W.refinement(H,Y);if(Q.common.async)return Promise.resolve(X);if(X instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return H};if(Q.common.async===!1){let H=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(H.status==="aborted")return R;if(H.status==="dirty")J.dirty();return B(H.value),{status:J.value,value:H.value}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((H)=>{if(H.status==="aborted")return R;if(H.status==="dirty")J.dirty();return B(H.value).then(()=>{return{status:J.value,value:H.value}})})}if(W.type==="transform")if(Q.common.async===!1){let B=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(!D$(B))return R;let H=W.transform(B.value,Y);if(H instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:J.value,value:H}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((B)=>{if(!D$(B))return R;return Promise.resolve(W.transform(B.value,Y)).then((H)=>({status:J.value,value:H}))});v.assertNever(W)}}t.create=($,J,Q)=>{return new t({schema:$,typeName:D.ZodEffects,effect:J,...S(Q)})};t.createWithPreprocess=($,J,Q)=>{return new t({schema:J,effect:{type:"preprocess",transform:$},typeName:D.ZodEffects,...S(Q)})};class a extends E{_parse($){if(this._getType($)===A.undefined)return u(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}a.create=($,J)=>{return new a({innerType:$,typeName:D.ZodOptional,...S(J)})};class U$ extends E{_parse($){if(this._getType($)===A.null)return u(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}U$.create=($,J)=>{return new U$({innerType:$,typeName:D.ZodNullable,...S(J)})};class Z$ extends E{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;if(J.parsedType===A.undefined)Q=this._def.defaultValue();return this._def.innerType._parse({data:Q,path:J.path,parent:J})}removeDefault(){return this._def.innerType}}Z$.create=($,J)=>{return new Z$({innerType:$,typeName:D.ZodDefault,defaultValue:typeof J.default==="function"?J.default:()=>J.default,...S(J)})};class T$ extends E{_parse($){let{ctx:J}=this._processInputParams($),Q={...J,common:{...J.common,issues:[]}},W=this._def.innerType._parse({data:Q.data,path:Q.path,parent:{...Q}});if(S$(W))return W.then((Y)=>{return{status:"valid",value:Y.status==="valid"?Y.value:this._def.catchValue({get error(){return new l(Q.common.issues)},input:Q.data})}});else return{status:"valid",value:W.status==="valid"?W.value:this._def.catchValue({get error(){return new l(Q.common.issues)},input:Q.data})}}removeCatch(){return this._def.innerType}}T$.create=($,J)=>{return new T$({innerType:$,typeName:D.ZodCatch,catchValue:typeof J.catch==="function"?J.catch:()=>J.catch,...S(J)})};class a$ extends E{_parse($){if(this._getType($)!==A.nan){let Q=this._getOrReturnCtx($);return K(Q,{code:V.invalid_type,expected:A.nan,received:Q.parsedType}),R}return{status:"valid",value:$.data}}}a$.create=($)=>{return new a$({typeName:D.ZodNaN,...S($)})};var U6=Symbol("zod_brand");class q0 extends E{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;return this._def.type._parse({data:Q,path:J.path,parent:J})}unwrap(){return this._def.type}}class s$ extends E{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.common.async)return(async()=>{let Y=await this._def.in._parseAsync({data:Q.data,path:Q.path,parent:Q});if(Y.status==="aborted")return R;if(Y.status==="dirty")return J.dirty(),j$(Y.value);else return this._def.out._parseAsync({data:Y.value,path:Q.path,parent:Q})})();else{let W=this._def.in._parseSync({data:Q.data,path:Q.path,parent:Q});if(W.status==="aborted")return R;if(W.status==="dirty")return J.dirty(),{status:"dirty",value:W.value};else return this._def.out._parseSync({data:W.value,path:Q.path,parent:Q})}}static create($,J){return new s$({in:$,out:J,typeName:D.ZodPipeline})}}class x$ extends E{_parse($){let J=this._def.innerType._parse($),Q=(W)=>{if(D$(W))W.value=Object.freeze(W.value);return W};return S$(J)?J.then((W)=>Q(W)):Q(J)}unwrap(){return this._def.innerType}}x$.create=($,J)=>{return new x$({innerType:$,typeName:D.ZodReadonly,...S(J)})};function x1($,J){let Q=typeof $==="function"?$(J):typeof $==="string"?{message:$}:$;return typeof Q==="string"?{message:Q}:Q}function n1($,J={},Q){if($)return R$.create().superRefine((W,Y)=>{let B=$(W);if(B instanceof Promise)return B.then((H)=>{if(!H){let X=x1(J,W),q=X.fatal??Q??!0;Y.addIssue({code:"custom",...X,fatal:q})}});if(!B){let H=x1(J,W),X=H.fatal??Q??!0;Y.addIssue({code:"custom",...H,fatal:X})}return});return R$.create()}var V6={object:g.lazycreate},D;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(D||(D={}));var D6=($,J={message:`Input not instance of ${$.name}`})=>n1((Q)=>Q instanceof $,J),i1=o.create,d1=z$.create,A6=a$.create,z6=K$.create,p1=P$.create,K6=N$.create,b6=d$.create,j6=f$.create,N6=C$.create,R6=R$.create,O6=A$.create,F6=B$.create,L6=p$.create,w6=r.create,S6=g.create,E6=g.strictCreate,v6=k$.create,P6=X0.create,f6=I$.create,C6=H$.create,k6=o$.create,I6=r$.create,h6=O$.create,y6=v$.create,g6=h$.create,Z6=y$.create,T6=b$.create,x6=g$.create,m6=F$.create,l6=t.create,u6=a.create,c6=U$.create,n6=t.createWithPreprocess,i6=s$.create,d6=()=>i1().optional(),p6=()=>d1().optional(),o6=()=>p1().optional(),r6={string:($)=>o.create({...$,coerce:!0}),number:($)=>z$.create({...$,coerce:!0}),boolean:($)=>P$.create({...$,coerce:!0}),bigint:($)=>K$.create({...$,coerce:!0}),date:($)=>N$.create({...$,coerce:!0})};var a6=R;import{execSync as s6}from"child_process";var o1=U.object({title:U.string().describe("Task title"),description:U.string().optional().describe("Task description"),priority:U.enum(["low","medium","high"]).optional().describe("Task priority"),type:U.enum(["normal","cycle","longterm"]).optional().default("normal").describe("Task type. normal: \u5E38\u89C4\u4EFB\u52A1\uFF0C\u9700\u8981\u8DDF\u8E2A\u5B8C\u6210. cycle: \u5468\u671F\u4EFB\u52A1\uFF08\u5982\u6BCF\u5468\u53D1\u5468\u62A5\uFF09\uFF0C\u65E0\u9700 complete\uFF0C\u5B9A\u671F\u6267\u884C. longterm: \u957F\u671F\u4EFB\u52A1/\u613F\u666F\u76EE\u6807\uFF08\u5982\u63D0\u5347\u516C\u53F8\u5F71\u54CD\u529B\uFF09\uFF0C\u96BE\u4EE5\u4E00\u6B21\u6027\u5B8C\u6210\uFF0C\u6301\u7EED\u8DDF\u8FDB"),goals_and_expected_deliverables:U.string().optional().describe("Goals and expected deliverables"),due_date:U.string().optional().describe("Due date (ISO format)"),tags:U.array(U.string()).optional().describe("Task tags (for search, stored in task.tags JSON field)"),project_path:U.string().describe("Project root path for task positioning. Used to locate the project space for this task. Use 'unknown' if unknown."),parent_task_id:U.union([U.number(),U.null()]).optional().describe(`\u7236\u4EFB\u52A1 ID\uFF08\u53EF\u9009\uFF09\u3002\u4E0D\u4F20\u6216\u4F20 null \u65F6\uFF0C\u521B\u5EFA\u6839\u4EFB\u52A1\uFF08root task\uFF09\u3002
|
|
127
|
+
`+`\u5982\u9700\u5C06\u4EFB\u52A1\u6302\u8F7D\u5230\u67D0\u4E2A\u7236\u4EFB\u52A1\u4E0B\uFF0C\u4F20\u5165\u5BF9\u5E94\u7236\u4EFB\u52A1 ID\u3002
|
|
128
|
+
`+`**\u8C03\u7528\u524D\u5FC5\u987B\u5148\u8C03\u7528 task_tree(depth=2)** \u67E5\u770B\u73B0\u6709\u4EFB\u52A1\u6811\u7ED3\u6784\uFF0C\u907F\u514D\u91CD\u590D\u521B\u5EFA\u6839\u4EFB\u52A1\u3001\u907F\u514D\u5B64\u513F\u4EFB\u52A1\u3002
|
|
129
|
+
`+`\u51B3\u7B56\u8DEF\u5F84\uFF08\u6309\u987A\u5E8F\u5339\u914D\uFF09\uFF1A
|
|
130
|
+
`+` A. \u5F52\u5C5E\u5230\u73B0\u6709 longterm \u6839\uFF08\u5982\u300C[Longterm] X \u751F\u6001\u300D\uFF09\u2192 parent_task_id = \u8BE5\u6839 ID
|
|
131
|
+
`+` B. \u5F52\u5C5E\u5230\u73B0\u6709\u4E3B\u9898\u805A\u7C7B\uFF08\u975E longterm \u6839\uFF0C\u4F46\u540C\u4E3B\u9898\uFF09\u2192 parent_task_id = \u8BE5\u6839 ID
|
|
132
|
+
`+` C. \u65B0\u5EFA\u6839\u4EFB\u52A1 \u2192 \u7701\u7565 parent_task_id\uFF08\u8BA9\u6811\u6839 \u226410\uFF09
|
|
133
|
+
`+`\u5982\u4F55\u627E\u5230 parent_task_id\uFF1A\u4F7F\u7528 task_tree(depth=2) \u83B7\u53D6\u7684\u6811\u5F62\u7ED3\u6784\uFF0C
|
|
134
|
+
`+"\u6839\u636E\u8282\u70B9 id \u9009\u62E9\u5408\u9002\u7684\u7236\u4EFB\u52A1 ID\uFF08\u6765\u81EA tree \u8F93\u51FA\uFF0C**\u4E0D\u8981\u786C\u7F16\u7801**\u6570\u5B57\uFF09\u3002"),context:U.string().describe(`JSON string with time-space positioning information for task continuity. This field is crucial for Agent task handoff. Core fields: worktree_path (git worktree path), branch (current branch), type (feature/bug/refactor/chore). Example for coding: {"worktree_path": "/path/worktree", "branch": "feature/xyz", "type": "feature"}. Example for other: {"type": "general"}. If unknown, use '{}' or '{"type":"unknown"}'. IMPORTANT: Must be a valid JSON string!`)}),r1=U.object({task_id:U.number().describe("Task ID"),include_operations:U.boolean().optional().default(!1).describe("Include operation records")}),a1=U.object({status:U.enum(["todo","active","completed","paused","cancelled","archived"]).optional(),priority:U.enum(["low","medium","high"]).optional(),type:U.enum(["normal","cycle","longterm"]).optional().describe("Filter by task type"),limit:U.number().optional().default(20),offset:U.number().optional().default(0),depth:U.number().optional().describe("\u68C0\u7D22\u5C42\u7EA7\u6DF1\u5EA6\uFF1A0=\u53EA\u6839\u4EFB\u52A1\uFF08\u65E0\u7236\u4EFB\u52A1\uFF09\uFF0C1=\u6839+\u4E00\u5C42\u5B50\u4EFB\u52A1\uFF0C2=\u6839+\u4E8C\u5C42\u5B50\u4EFB\u52A1\uFF0C-1 \u6216\u5FFD\u7565=\u5168\u90E8"),include_archived:U.boolean().optional().default(!1).describe("\u662F\u5426\u5305\u542B\u5DF2\u5F52\u6863\u4EFB\u52A1\uFF08status=archived \u7684\u4EFB\u52A1\u9ED8\u8BA4\u88AB\u6392\u9664\uFF09")}),s1=U.object({keywords:U.array(U.string()).describe("\u5173\u952E\u8BCD\u5217\u8868\uFF08AND \u903B\u8F91\uFF0C\u5339\u914D title/description/goals/tags/operations\uFF09"),limit:U.number().optional().default(20).describe("\u8FD4\u56DE\u6570\u91CF"),offset:U.number().optional().default(0).describe("\u504F\u79FB\u91CF"),status:U.enum(["todo","active","completed","paused","cancelled","archived"]).optional().describe("\u6309\u72B6\u6001\u7B5B\u9009"),priority:U.enum(["low","medium","high"]).optional().describe("\u6309\u4F18\u5148\u7EA7\u7B5B\u9009"),type:U.enum(["normal","cycle","longterm"]).optional().describe("\u6309\u7C7B\u578B\u7B5B\u9009"),exclude_task_id:U.number().optional().describe("\u6392\u9664\u7684 task ID"),depth:U.number().optional().describe("\u68C0\u7D22\u5C42\u7EA7\u6DF1\u5EA6\uFF1A0=\u53EA\u6839\u4EFB\u52A1\uFF0C1=\u6839+\u4E00\u5C42\u5B50\u4EFB\u52A1\uFF0C2=\u6839+\u4E8C\u5C42\u5B50\u4EFB\u52A1\uFF0C-1 \u6216\u5FFD\u7565=\u5168\u90E8"),include_archived:U.boolean().optional().default(!1).describe("\u662F\u5426\u5305\u542B\u5DF2\u5F52\u6863\u4EFB\u52A1\uFF08status=archived \u7684\u4EFB\u52A1\u9ED8\u8BA4\u88AB\u6392\u9664\uFF09")}),t1=U.object({task_id:U.number().describe("Task ID"),title:U.string().optional(),description:U.string().optional(),status:U.enum(["todo","active","completed","paused","cancelled","archived"]).optional(),priority:U.enum(["low","medium","high"]).optional(),type:U.enum(["normal","cycle","longterm"]).optional().describe("Task type"),progress:U.number().min(0).max(100).optional(),current_status:U.string().optional(),goals_and_expected_deliverables:U.string().optional(),due_date:U.string().optional(),tags:U.array(U.string()).optional(),project_path:U.string().optional().describe("Project path, identifies which project this task belongs to"),context:U.string().optional().describe("Task context information for storing additional context"),parent_task_id:U.union([U.number(),U.null()]).optional().describe("Parent task ID (set to null to make it a root task)")}),x4=U.object({task_id:U.number().describe("Task ID")}),e1=U.object({task_id:U.number().describe("Task ID"),deliverable_storage_path:U.string().optional().describe("\u4EA4\u4ED8\u7269\u7684\u5BFB\u5740\u5730\u5740\uFF08\u8DEF\u5F84 / URL / \u5206\u652F\u540D\u7B49\uFF09\u3002"+"\u8C03\u7528\u672C\u5DE5\u5177\u524D\uFF0C\u8BF7\u5148\u8BFB\u53D6\u4EFB\u52A1\u7684 goal\uFF08description\uFF09\u548C delivery\uFF08goals_and_expected_deliverables\uFF09\u680F\u4F4D\uFF0C"+"\u5EFA\u8BAE\u9A8C\u8BC1\u76EE\u6807\u548C\u4EA4\u4ED8\u7269\u662F\u5426\u7B26\u5408\u9884\u671F\uFF0C\u7136\u540E\u5C06\u5B9E\u9645\u4EA4\u4ED8\u7269\u7684\u5BFB\u5740\u5730\u5740\u586B\u5165\u6B64\u53C2\u6570\u3002")}),m4=U.object({task_ids:U.array(U.number()).describe("\u8981\u5F52\u6863\u7684\u4EFB\u52A1 ID \u5217\u8868"),reason:U.string().optional().describe("\u5F52\u6863\u539F\u56E0\uFF08\u53EF\u9009\uFF0C\u4F1A\u5199\u5165\u6BCF\u4E2A\u4EFB\u52A1\u7684 operation \u8BB0\u5F55\uFF09")}),l4=U.object({task_ids:U.array(U.number()).describe("\u8981\u5220\u9664\u7684\u4EFB\u52A1 ID \u5217\u8868")}),$2=U.object({depth:U.number().optional().default(2).describe("\u6811\u7684\u5C55\u5F00\u6DF1\u5EA6\u3002\u9ED8\u8BA4 2 (\u6839 + \u4E00\u5C42\u5B50\u4EFB\u52A1 + \u4E8C\u5C42\u5B59\u4EFB\u52A1)\u3002"+"0 = \u53EA\u8FD4\u56DE\u6839\u4EFB\u52A1\uFF0C\u4E0D\u5C55\u5F00\u4EFB\u4F55\u5B50\u8282\u70B9\u3002"+"-1 \u6216\u8D1F\u6570 = \u65E0\u9650\u5C42\u7EA7\uFF08\u5168\u90E8\u5C55\u5F00\uFF09\u3002"),parent_task_id:U.number().optional().describe("\u53EA\u770B\u6307\u5B9A\u7236\u4EFB\u52A1\u7684\u5B50\u6811\u3002\u4E0D\u4F20\u5219\u4ECE\u6240\u6709\u6839\u4EFB\u52A1\uFF08forest\uFF09\u5F00\u59CB\u3002"),status:U.enum(["todo","active","completed","paused","cancelled","archived"]).optional().describe("\u6309\u72B6\u6001\u8FC7\u6EE4\uFF08\u4E0E task_list \u4E00\u81F4\uFF09\u3002"),priority:U.enum(["low","medium","high"]).optional().describe("\u6309\u4F18\u5148\u7EA7\u8FC7\u6EE4\u3002"),type:U.enum(["normal","cycle","longterm"]).optional().describe("\u6309\u4EFB\u52A1\u7C7B\u578B\u8FC7\u6EE4\u3002"),include_archived:U.boolean().optional().default(!1).describe("\u662F\u5426\u5305\u542B\u5DF2\u5F52\u6863\u4EFB\u52A1\uFF08\u9ED8\u8BA4 false\uFF0C\u4E0E task_list \u4E00\u81F4\uFF09\u3002")});Y0();W$();W$();var t6=Q$("task-child-context"),e6=["commit","token","secret","password","api_key"];function u0($){if($===null||$===void 0)return $;if(Array.isArray($))return $.map(u0);if(typeof $!=="object")return $;let J={};for(let[Q,W]of Object.entries($)){let Y=Q.toLowerCase();if(e6.some((B)=>Y.includes(B)))continue;J[Q]=u0(W)}return J}function $8($){let{parent:J,overrides:Q={}}=$,W=Q.contextInherit!==!1,Y=Q.inheritTags===!0,B=Q.projectPath??J.projectPath??"unknown",H={};if(J.contextJson&&J.contextJson.trim().length>0)try{let b=JSON.parse(J.contextJson);if(b&&typeof b==="object"&&!Array.isArray(b))H=b}catch(b){t6.debug(`[task-child-context] parent #${J.taskId} context is malformed JSON; continuing with empty inherited context (${b instanceof Error?b.message:String(b)})`),H={}}let X={};if(W){if(H.worktree_path!==void 0&&Q.worktreePath===void 0)X.worktree_path=H.worktree_path;if(H.branch!==void 0&&Q.branch===void 0)X.branch=H.branch;if(H.parent_branch!==void 0)X.parent_branch=H.parent_branch;if(H.type!==void 0)X.type=H.type;if(H.prior_context&&typeof H.prior_context==="object"){let j=H.prior_context,z={};for(let[O,P]of Object.entries(j)){if(O.toLowerCase()==="commit")continue;z[O]=P}if(Object.keys(z).length>0)X.prior_context=z}let b=new Set(["worktree_path","branch","parent_branch","type","prior_context","created_at"]);for(let[j,z]of Object.entries(H)){if(b.has(j))continue;X[j]=z}}if(Q.worktreePath!==void 0)X.worktree_path=Q.worktreePath;if(Q.branch!==void 0)X.branch=Q.branch;let q=Q.createdAt??new Date().toISOString();X.created_at=q,X.child_of=J.taskId;let _=u0(X);return{project_path:B,context:JSON.stringify(_),inheritedTags:Y?J.tags??[]:[]}}var J2=Q$("task:tools:create");function J8(){try{let $=s6("git rev-parse --show-toplevel",{stdio:["ignore","pipe","ignore"]}).toString().trim(),J=process.cwd();if(!$)return null;if(J!==$)return J;if(J.includes(".worktrees/")||J.includes(".worktree/"))return J;return null}catch{return null}}function c0($){return{name:"task_create",description:`
|
|
135
|
+
Create a new task for tracking work.
|
|
136
|
+
|
|
137
|
+
## \u26A0\uFE0F CALL task_tree(depth=1) BEFORE THIS TOOL
|
|
138
|
+
|
|
139
|
+
Before calling \`task_create\`, you **MUST** first call
|
|
140
|
+
\`task_tree(depth=1)\` to inspect the existing task hierarchy.
|
|
141
|
+
This is critical because:
|
|
142
|
+
|
|
143
|
+
1. Avoid duplicating root tasks (root tasks should stay \u2264 10).
|
|
144
|
+
2. Find the right \`parent_task_id\` to attach under.
|
|
145
|
+
3. Avoid creating stranded/orphan tasks.
|
|
146
|
+
|
|
147
|
+
Workflow:
|
|
148
|
+
step 1: task_tree({depth: 1})
|
|
149
|
+
step 2: read the tree, then decide per "Decision Tree" below
|
|
150
|
+
step 3: task_create({...})
|
|
151
|
+
|
|
152
|
+
## Decision Tree \u2014 How to choose parent_task_id
|
|
153
|
+
|
|
154
|
+
Walk these paths in order:
|
|
155
|
+
|
|
156
|
+
**Path A \u2014 Attach under a longterm root.**
|
|
157
|
+
The task belongs to a theme whose longterm root already exists
|
|
158
|
+
(e.g. "[Longterm] X ecosystem"). Set \`parent_task_id\` to that
|
|
159
|
+
root's id. This is the **preferred** path for incremental work
|
|
160
|
+
inside an established theme.
|
|
161
|
+
|
|
162
|
+
**Path B \u2014 Attach under an existing topic cluster.**
|
|
163
|
+
A non-longterm root already aggregates similar tasks and yours
|
|
164
|
+
belongs in the same cluster. Set \`parent_task_id\` to that root.
|
|
165
|
+
|
|
166
|
+
**Path C \u2014 Create a new root.**
|
|
167
|
+
Neither A nor B fits (cross-cutting work, or root count already
|
|
168
|
+
\u2265 ~10). **Omit** \`parent_task_id\` (or pass \`null\`) and the
|
|
169
|
+
task becomes a new root.
|
|
170
|
+
|
|
171
|
+
## Tree Hygiene Principles
|
|
172
|
+
|
|
173
|
+
Apply these when deciding parent_task_id:
|
|
174
|
+
|
|
175
|
+
- Root tasks \u2264 10 (keep tree width manageable)
|
|
176
|
+
- Depth \u2264 5 (avoid deep nesting)
|
|
177
|
+
- Same-theme tasks cluster under one parent
|
|
178
|
+
- Long-tail/stranded tasks should be archived or merged
|
|
179
|
+
|
|
180
|
+
## \u26A0\uFE0F Spatial + Temporal Context (Task #2325)
|
|
181
|
+
|
|
182
|
+
A task MUST carry spatio-temporal context so it survives task-handoff
|
|
183
|
+
across Agent sessions, worktrees and time. Two orthogonal axes:
|
|
184
|
+
|
|
185
|
+
- **Space (project_path + worktree_path)**:
|
|
186
|
+
- \`project_path\` (required): git repo root path (always the top-level repo)
|
|
187
|
+
- \`worktree_path\` (in context): current worktree path if in a worktree
|
|
188
|
+
- **Auto-detected by createTask** via \`git rev-parse --show-toplevel\`
|
|
189
|
+
\u2014 you don't need to fill it manually (see "worktree_path detection
|
|
190
|
+
logic" in the implementation).
|
|
191
|
+
- You may **override** by passing it in \`context.worktree_path\`.
|
|
192
|
+
|
|
193
|
+
- **Time (context field)**:
|
|
194
|
+
- \`created_at\` (in context): ISO 8601 timestamp **auto-injected**
|
|
195
|
+
at creation time. Manual override is preserved if provided.
|
|
196
|
+
- \`time_dimension\` (in context, optional): the task's "time anchor"
|
|
197
|
+
\u2014 e.g. a release tag, sprint window or iteration id.
|
|
198
|
+
- \`work_period\` (in context, optional): planned start/end dates
|
|
199
|
+
if known.
|
|
200
|
+
- \`prior_context\` (in context, optional): the previous task id
|
|
201
|
+
/ commit hash this work continues from. Helps the next Agent
|
|
202
|
+
pick up the trail via \`task_get\`.
|
|
203
|
+
|
|
204
|
+
Example context for code development task:
|
|
205
|
+
|
|
206
|
+
\`\`\`json
|
|
207
|
+
{"project_path": "<git-repo-root>",
|
|
208
|
+
"worktree_path": "<git-repo-root>/.worktrees/<branch-name>",
|
|
209
|
+
"branch": "feat/<branch-name>",
|
|
210
|
+
"type": "feature",
|
|
211
|
+
"parent_branch": "main",
|
|
212
|
+
"created_at": "<ISO-8601-timestamp>",
|
|
213
|
+
"prior_context": {"prev_task": "<task-id>", "commit": "<commit-hash>"}}
|
|
214
|
+
\`\`\`
|
|
215
|
+
|
|
216
|
+
## IMPORTANT: Task Continuity Fields
|
|
217
|
+
|
|
218
|
+
This tool creates persistent task records that can be picked up by a
|
|
219
|
+
Task Manager Agent to continue advancing unfinished work.
|
|
220
|
+
|
|
221
|
+
The following fields are critical for task context preservation:
|
|
222
|
+
|
|
223
|
+
- project_path: The project root path where this task belongs.
|
|
224
|
+
Used to locate the project space for this task.
|
|
225
|
+
If unknown, use 'unknown'.
|
|
226
|
+
|
|
227
|
+
- context: A JSON string containing time-space positioning information.
|
|
228
|
+
This field is crucial for Agent task handoff.
|
|
229
|
+
|
|
230
|
+
**Required format**: Valid JSON string (parseable).
|
|
231
|
+
|
|
232
|
+
**Core fields**:
|
|
233
|
+
- worktree_path: Git worktree path (for code development). Auto-detected.
|
|
234
|
+
- branch: Current branch name
|
|
235
|
+
- type: Work type classification (feature/bug/refactor/chore).
|
|
236
|
+
\u26A0\uFE0F NOTE: This is the **context.type** (work classification), NOT the
|
|
237
|
+
task's type field (normal/cycle/longterm). They are independent concepts.
|
|
238
|
+
- created_at: ISO 8601 timestamp. Auto-injected if missing.
|
|
239
|
+
|
|
240
|
+
**Example for coding tasks**:
|
|
241
|
+
{"worktree_path": "<worktree-path>", "branch": "<branch-name>", "type": "feature", "parent_branch": "main"}
|
|
242
|
+
|
|
243
|
+
**Example for other tasks**:
|
|
244
|
+
{"type": "general"}
|
|
245
|
+
|
|
246
|
+
If unable to fill in details, use at minimum:
|
|
247
|
+
{"type": "unknown"}
|
|
248
|
+
|
|
249
|
+
**DO NOT leave this as plain text** - it must be valid JSON!
|
|
250
|
+
|
|
251
|
+
**Note**: malformed JSON (non-parseable) will be preserved as-is
|
|
252
|
+
rather than rejected, to preserve backward compatibility. The
|
|
253
|
+
auto-injection of \`created_at\` / \`worktree_path\` is best-effort.
|
|
254
|
+
|
|
255
|
+
## Task Binding Inheritance (Task #4023)
|
|
256
|
+
|
|
257
|
+
When this tool is called from inside a per-task group chat, the
|
|
258
|
+
event-source handler resolves the chat\u2194task binding and injects the
|
|
259
|
+
bound task id into \`EnvContext.parentTaskId\`. This tool reads that
|
|
260
|
+
value and uses it as the default \`parent_task_id\`, so the LLM
|
|
261
|
+
doesn't need to know the task tree to attach subtasks to the
|
|
262
|
+
correct parent.
|
|
263
|
+
|
|
264
|
+
Priority order (highest \u2192 lowest):
|
|
265
|
+
1. Caller's explicit \`parent_task_id\` (always wins)
|
|
266
|
+
2. \`EnvContext.parentTaskId\` injected from chat binding
|
|
267
|
+
3. No parent (creates a root task, as before)
|
|
268
|
+
|
|
269
|
+
When the env-injected parent doesn't exist in the DB, the tool
|
|
270
|
+
fails fast (does not silently create an orphan). When the
|
|
271
|
+
env-injected value is 0 / negative / non-integer, it's treated as
|
|
272
|
+
missing \u2014 only positive integers are honored.
|
|
273
|
+
|
|
274
|
+
`,parameters:o1,execute:async(J,Q)=>{let W=o1.parse(J),Y=Q.session_id||"unknown",B=J8(),H=W.context,X=g1().parentTaskId,q=W.parent_task_id!==void 0&&W.parent_task_id!==null?W.parent_task_id:X!==void 0&&X!==null&&Number.isInteger(X)&&X>0?X:void 0,_=W.project_path&&W.project_path.trim()!==""?W.project_path:void 0,b=W.tags,j;if(q!==void 0)try{let z=await $.getTask(q);if(z){let O=$8({parent:{taskId:z.id,projectPath:z.project_path,contextJson:z.context??"",tags:z.tags},overrides:{projectPath:_,branch:void 0,worktreePath:void 0,inheritTags:W.tags===void 0,contextInherit:!0}});if(_===void 0)_=O.project_path;if(W.tags===void 0)b=O.inheritedTags;j=O.context}}catch(z){J2.debug(`[task_create] failed to pre-load parent #${q} for context inheritance: ${z instanceof Error?z.message:String(z)}`)}try{let z=W.context?JSON.parse(W.context):{},O=typeof z==="object"&&z!==null&&!Array.isArray(z)?z:{};if(j)try{let P=JSON.parse(j);if(P&&typeof P==="object"&&!Array.isArray(P)){for(let[C,k]of Object.entries(P))if(O[C]===void 0)O[C]=k}}catch{}if(!O.created_at)O.created_at=new Date().toISOString();if(!O.worktree_path&&B)O.worktree_path=B;H=JSON.stringify(O)}catch{H=W.context}try{let z=await $.createTask({parent_task_id:q,title:W.title,description:W.description,priority:W.priority,type:W.type||"normal",goals_and_expected_deliverables:W.goals_and_expected_deliverables,due_date:W.due_date,tags:b,sessionId:Y,project_path:_??W.project_path,context:H});return n$(z.id),J2.info(`[createTask] Trace: Task #${z.id} created, currentTaskId=${z.id} set in EnvContext`),{success:!0,output:`Task created successfully: #${z.id} - ${z.title}`,metadata:{execution_time_ms:0,task_id:z.id,status:z.status,createdAt:z.createdAt}}}catch(z){return{success:!1,output:"",error:z instanceof Error?z.message:String(z),metadata:{execution_time_ms:0}}}}}}function n0($){return{name:"task_get",description:"Get task details by ID. Optionally include operation records.",parameters:r1,execute:async(J,Q)=>{let W=r1.parse(J);try{if(W.include_operations){let Y=await $.getTaskWithOperations(W.task_id);if(!Y)return{success:!1,output:"",error:`Task not found: ${W.task_id}`,metadata:{execution_time_ms:0}};return{success:!0,output:JSON.stringify(Y,null,2),metadata:{execution_time_ms:0}}}else{let Y=await $.getTask(W.task_id);if(!Y)return{success:!1,output:"",error:`Task not found: ${W.task_id}`,metadata:{execution_time_ms:0}};return{success:!0,output:JSON.stringify(Y,null,2),metadata:{execution_time_ms:0}}}}catch(Y){return{success:!1,output:"",error:Y instanceof Error?Y.message:String(Y),metadata:{execution_time_ms:0}}}}}}function i0($){return{name:"task_list",description:"List tasks with optional filters for status, priority, type, parent_task_id, and depth (hierarchy level). "+`depth: 0=\u53EA\u6839\u4EFB\u52A1\uFF08\u65E0\u7236\u4EFB\u52A1\uFF09\uFF0C1=\u6839+\u4E00\u5C42\u5B50\u4EFB\u52A1\uFF0C2=\u6839+\u4E8C\u5C42\u5B50\u4EFB\u52A1\uFF0C-1 \u6216\u5FFD\u7565=\u5168\u90E8\u3002
|
|
275
|
+
`+"Returns { total, count, truncated, limit, offset, depth, tasks } where:\n - total: count of all matching tasks BEFORE pagination\n - count: count of tasks in the returned `tasks` array (after pagination)\n - truncated: true when total > count (data was truncated by pagination)\nNote: `total` is the FIRST field in the response so it survives tail-truncation by ToolComponent.truncateOutput.",parameters:a1,execute:async(J,Q)=>{let W=a1.parse(J);try{let Y=await $.listTasks({status:W.status,priority:W.priority,type:W.type,limit:W.limit,offset:W.offset,depth:W.depth,include_archived:W.include_archived});return{success:!0,output:JSON.stringify({total:Y.total,count:Y.tasks.length,truncated:Y.total>Y.tasks.length,limit:W.limit,offset:W.offset,depth:W.depth,tasks:Y.tasks}),metadata:{execution_time_ms:0}}}catch(Y){return{success:!1,output:"",error:Y instanceof Error?Y.message:String(Y),metadata:{execution_time_ms:0}}}}}}function d0($){return{name:"task_search",description:"Search tasks by keywords across title, description, goals, tags, and operation records. Use this when you need to find tasks related to a "+"topic, feature, bug, or area of work \u2014 even when the keyword is only "+`in description / goals / tags / past operation logs.
|
|
276
|
+
|
|
277
|
+
Returns { tasks, total, limit, offset } so you can paginate large result sets.
|
|
278
|
+
|
|
279
|
+
If \`keywords\` is empty, returns no results.`,parameters:s1,execute:async(J,Q)=>{let W=s1.parse(J);try{let Y=await $.searchTasksByKeywords(W.keywords,{limit:W.limit,offset:W.offset,excludeTaskId:W.exclude_task_id,status:W.status,priority:W.priority,type:W.type,depth:W.depth,include_archived:W.include_archived});return{success:!0,output:JSON.stringify({tasks:Y.tasks,total:Y.total,limit:W.limit,offset:W.offset}),metadata:{execution_time_ms:0}}}catch(Y){return{success:!1,output:"",error:Y instanceof Error?Y.message:String(Y),metadata:{execution_time_ms:0}}}}}}Y0();W$();var Q8=Q$("tool:update-task");async function W8($,J,Q){let W=new Set,Y=Q;while(Y!==null&&Y!==void 0){if(Y===J)return!0;if(W.has(Y))break;W.add(Y);let B=await $.getTask(Y);if(!B)break;Y=B.parent_task_id}return!1}function p0($){return{name:"task_update",description:"Update an existing task's properties. Status and progress changes will create operation records.",parameters:t1,execute:async(J,Q)=>{let W=t1.parse(J),Y=Q.session_id||"unknown";try{if(W.parent_task_id!==void 0&&W.parent_task_id!==null){if(await W8($,W.task_id,W.parent_task_id))return{success:!1,output:"",error:`Circular reference detected: setting parent_task_id to ${W.parent_task_id} for task #${W.task_id} would create a cycle`,metadata:{execution_time_ms:0}}}let B=await $.updateTask(W.task_id,{title:W.title,description:W.description,status:W.status,priority:W.priority,type:W.type,progress:W.progress,current_status:W.current_status,goals_and_expected_deliverables:W.goals_and_expected_deliverables,due_date:W.due_date,tags:W.tags,project_path:W.project_path,context:W.context,parent_task_id:W.parent_task_id});if(!B)return{success:!1,output:"",error:`Task not found: ${W.task_id}`,metadata:{execution_time_ms:0}};if(W.status||W.progress!==void 0||W.current_status)await $.createOperation({taskId:W.task_id,sessionId:Y,actionType:"progress",actionTitle:W.current_status||`Updated: ${W.status||`${W.progress}%`}`,actionDescription:JSON.stringify({status:W.status,progress:W.progress,current_status:W.current_status})});return n$(B.id),Q8.info(`[updateTask] Trace: Task #${B.id} updated, currentTaskId=${B.id} set in EnvContext`),{success:!0,output:`Task updated: #${B.id} - ${B.title}`,metadata:{execution_time_ms:0,task:B}}}catch(B){return{success:!1,output:"",error:B instanceof Error?B.message:String(B),metadata:{execution_time_ms:0}}}}}}Y0();W$();var Y8=Q$("task:tools:complete"),B8=`
|
|
280
|
+
Mark a task as completed (progress=100, status=completed). Creates an operation record.
|
|
281
|
+
|
|
282
|
+
**Before calling this tool**, you MUST:
|
|
283
|
+
|
|
284
|
+
1. Read the task's \`goal\` (description) and \`delivery\` (goals_and_expected_deliverables) fields.
|
|
285
|
+
- Use \`task_get(task_id=<id>)\` to fetch the full task record.
|
|
286
|
+
2. **Validate** whether the goal and delivery match what you actually delivered.
|
|
287
|
+
- If mismatch, either: (a) extend the task via \`task_update\`, or (b) honestly note the discrepancy in your final report.
|
|
288
|
+
3. **Provide \`deliverable_storage_path\`** parameter with the deliverable's address:
|
|
289
|
+
- Feishu doc URL (e.g., https://my.feishu.cn/docx/abc)
|
|
290
|
+
- Local file path (e.g., /tmp/report.md)
|
|
291
|
+
- Git branch or worktree path (e.g., feature/my-feature)
|
|
292
|
+
- GitHub commit URL or PR URL
|
|
293
|
+
- Cloud drive URL (e.g., https://my.feishu.cn/file/abc)
|
|
294
|
+
- Or any other locator that points to where the work product lives
|
|
295
|
+
|
|
296
|
+
The \`deliverable_storage_path\` will be persisted to the task's \`context.deliverable_storage_path\` for future reference and traceability.
|
|
297
|
+
|
|
298
|
+
**Restrictions**:
|
|
299
|
+
- Cannot complete cycle-type tasks (they are periodic). Use \`task_update\` to reset progress instead.
|
|
300
|
+
- Marks the task as 100% complete; use \`task_update\` to record partial progress first if needed.
|
|
301
|
+
|
|
302
|
+
**Backward compatibility**: \`deliverable_storage_path\` is optional. Existing callers that omit it continue to work as before.
|
|
303
|
+
`.trim();function o0($){return{name:"task_complete",description:B8,parameters:e1,execute:async(J,Q)=>{let W=e1.parse(J),Y=Q.session_id||"unknown";try{let B=await $.getTask(W.task_id);if(!B)return{success:!1,output:"",error:`Task not found: ${W.task_id}`,metadata:{execution_time_ms:0}};if(B.type==="cycle")return{success:!1,output:"",error:`Cannot complete a cycle-type task (id: ${W.task_id}). Cycle tasks are periodic (e.g., weekly reports) and should not be marked as completed. Use task_update to reset progress instead.`,metadata:{execution_time_ms:0}};let H=await $.completeTask(W.task_id,Y,W.deliverable_storage_path);if(!H)return{success:!1,output:"",error:`Task not found: ${W.task_id}`,metadata:{execution_time_ms:0}};return n$(void 0),Y8.info(`[completeTask] Trace: Task #${W.task_id} completed, deliverable=${W.deliverable_storage_path||"(none)"}, currentTaskId cleared from EnvContext`),{success:!0,output:W.deliverable_storage_path?`Task completed: #${H.id} - ${H.title}
|
|
304
|
+
Deliverable (context + operation): ${W.deliverable_storage_path}`:`Task completed: #${H.id} - ${H.title}
|
|
305
|
+
Deliverable: (no path provided)`,metadata:{execution_time_ms:0,task:H}}}catch(B){return{success:!1,output:"",error:B instanceof Error?B.message:String(B),metadata:{execution_time_ms:0}}}}}}function Q2($,J){if($.updatedAt<J.updatedAt)return 1;if($.updatedAt>J.updatedAt)return-1;if($.id<J.id)return 1;if($.id>J.id)return-1;return 0}function W2($,J){if(J<0)return $;if(J===0)return $.map((Q)=>({...Q,children:[]}));return $.map((Q)=>({...Q,children:W2(Q.children,J-1)}))}function Y2($){let J=0;for(let Q of $)J+=1+Y2(Q.children);return J}function H8($){let J=new Map,Q=new Map,W=[];for(let Y of $)J.set(Y.id,{id:Y.id,title:Y.title,status:Y.status,type:Y.type,priority:Y.priority,progress:Y.progress,children:[]});for(let Y of $){let B=Y.parent_task_id;if(B!==void 0&&B!==null&&J.has(B)){let H=Q.get(B)||[];H.push(Y),Q.set(B,H)}else W.push(Y)}for(let[Y,B]of Q.entries()){let H=J.get(Y);B.sort(Q2),H.children=B.map((X)=>J.get(X.id))}return W.sort(Q2),W.map((Y)=>J.get(Y.id))}function r0($){return{name:"task_tree",description:"View the task tree (forest) with optional filters. Use this BEFORE task_create to decide whether to create a root task (omit parent_task_id) or attach to an existing parent. "+"depth: 0=\u53EA\u6839\u4EFB\u52A1, 1=\u6839+\u4E00\u5C42\u5B50\u4EFB\u52A1, 2=\u6839+\u4E8C\u5C42\u5B50\u4EFB\u52A1 (default), "+"-1 or omitted as -1=\u65E0\u9650\u5C42\u7EA7. "+`Returns { total, truncated, depth, parent_task_id, nodes } where:
|
|
306
|
+
- total: count of ALL tasks in the returned tree (incl. descendants)
|
|
307
|
+
- truncated: always false for now (no pagination cap on tree)
|
|
308
|
+
- depth: the resolved depth value
|
|
309
|
+
- parent_task_id: the root's id, or null for forest mode
|
|
310
|
+
- nodes: TaskNode[] with { id, title, status, type, priority, progress, children }
|
|
311
|
+
Note: \`total\` is the FIRST field in the response so it survives tail-truncation by ToolComponent.truncateOutput.`,parameters:$2,execute:async(J,Q)=>{let W=$2.parse(J);try{let Y=[],B=W.parent_task_id??null;if(W.parent_task_id!==void 0&&W.parent_task_id!==null){let q=await $.getTask(W.parent_task_id);if(!q)Y=[];else{let _=await $.getTaskTree(W.parent_task_id,W.depth===-1?-1:Math.max(0,W.depth-1));Y=[q,..._]}}else Y=(await $.listTasks({status:W.status,priority:W.priority,type:W.type,include_archived:W.include_archived,limit:9999,offset:0})).tasks;if(W.parent_task_id!==void 0&&W.parent_task_id!==null){if(W.status)Y=Y.filter((q)=>q.status===W.status);if(W.priority)Y=Y.filter((q)=>q.priority===W.priority);if(W.type)Y=Y.filter((q)=>q.type===W.type);if(!W.include_archived)Y=Y.filter((q)=>q.status!=="archived")}let H=H8(Y);if(W.parent_task_id===void 0||W.parent_task_id===null)H=W2(H,W.depth);let X=Y2(H);return{success:!0,output:JSON.stringify({total:X,truncated:!1,depth:W.depth,parent_task_id:B,nodes:H}),metadata:{execution_time_ms:0}}}catch(Y){return{success:!1,output:"",error:Y instanceof Error?Y.message:String(Y),metadata:{execution_time_ms:0}}}}}}var G0=U.enum(["create","progress","milestone","problem","solution","decision","review","completed","workflow_extracted"]),a0=100,s0=150,M0=5000,X8=1,_0=200,X2=U.string().min(a0,{message:`process_description \u592A\u77ED\uFF08\u5C11\u4E8E ${a0} \u5B57\u7B26\uFF09\uFF0C\u65E0\u6CD5\u8868\u8FBE\u8FC7\u7A0B\u6982\u8981\uFF1B\u5982\u65E0\u8FC7\u7A0B\u4FE1\u606F\u8BF7\u7701\u7565\u8BE5\u5B57\u6BB5\uFF0C\u7EC6\u8282\u8BF7\u56DE\u67E5 sessionId\u3002`}).max(s0,{message:`process_description \u592A\u957F\uFF08\u8D85\u8FC7 ${s0} \u5B57\u7B26\uFF09\uFF0C\u4F1A\u9000\u5316\u4E3A\u65E5\u5FD7\u7EC6\u8282\uFF1B\u64CD\u4F5C\u8BB0\u5F55\u53EA\u627F\u62C5 milestone \u6982\u8981\uFF0C\u5B8C\u6574\u7EC6\u8282\u8BF7\u901A\u8FC7 sessionId \u56DE\u67E5 session\u3002`}).describe("\u8FC7\u7A0B\u6982\u8981\uFF08process_description\uFF09\uFF1A\u91C7\u53D6\u7684\u7B56\u7565 + \u5DE5\u5177\u6B65\u9AA4\u6982\u8981\uFF1B"+`\u4E25\u683C\u63A7\u5236 ${a0}-${s0} \u5B57\u7B26\u3002`+"\u64CD\u4F5C\u8BB0\u5F55\u662F\u8282\u70B9\u9636\u6BB5 milestone \u6458\u8981\uFF0C\u5B8C\u6574\u8FC7\u7A0B\u901A\u8FC7 sessionId \u56DE\u67E5 session\uFF1B"+"milestone_description \u624D\u662F\u8FBE\u6210\u7684\u72B6\u6001/\u7ED3\u679C\u63CF\u8FF0\u3002"),q2=U.string().min(X8,{message:"milestone_title \u4E0D\u80FD\u4E3A\u7A7A"}).max(_0,{message:`milestone_title \u8D85\u8FC7 ${_0} \u5B57\u7B26\uFF0C\u5EFA\u8BAE\u7CBE\u7B80\uFF08\u4E00\u884C\u6807\u9898\u5373\u53EF\uFF09\u3002`}).describe("\u91CC\u7A0B\u7891\u6807\u9898\uFF08milestone_title\uFF09\uFF1A\u8FBE\u6210\u7684\u91CC\u7A0B\u7891/\u72B6\u6001\u7684\u4E00\u53E5\u8BDD\u6807\u9898\uFF1B"+"\u5FC5\u586B\uFF0C1-200 \u5B57\u7B26\u3002"),G2=U.string().max(M0,{message:`milestone_description \u8D85\u8FC7 ${M0} \u5B57\u7B26\uFF1B\u5982\u9700\u66F4\u8BE6\u7EC6\u7684\u8FC7\u7A0B\uFF0C\u8BF7\u6539\u7528 process_description\u3002`}).optional().describe("\u72B6\u6001/\u7ED3\u679C\u63CF\u8FF0\uFF08milestone_description\uFF09\uFF1A\u8FBE\u6210\u7684\u72B6\u6001\u6216\u7ED3\u679C\u63CF\u8FF0\uFF1B"+"\u53EF\u957F\u53EF\u77ED\uFF1B\u8FC7\u7A0B\u6982\u8981\u5E94\u653E\u5728 process_description\uFF0C\u4E0D\u8981\u4E0E\u672C\u5B57\u6BB5\u91CD\u590D\u3002"),q8=U.object({task_id:U.number().describe("Task ID"),milestone_type:G0.optional(),milestone_title:q2.optional(),milestone_description:G2,process_description:X2.optional(),action_type:G0.optional(),action_title:U.string().min(1).max(_0).optional(),action_description:U.string().max(M0).optional(),md_path:U.string().optional().describe("Path to detailed markdown documentation")}),B2=q8.transform(($)=>{let J=[],Q=$.milestone_type,W=$.milestone_title,Y=$.milestone_description;if(!Q&&$.action_type)Q=$.action_type,J.push("action_type");if(!W&&$.action_title)W=$.action_title,J.push("action_title");if(Y===void 0&&$.action_description!==void 0)Y=$.action_description,J.push("action_description");return{task_id:$.task_id,milestone_type:Q,milestone_title:W,milestone_description:Y,process_description:$.process_description,md_path:$.md_path,_deprecated_fields_used:J}}),Q9=U.object({operation_id:U.number().describe("Operation ID")}),H2=U.object({task_id:U.number().describe("Task ID"),milestone_type:G0.optional(),action_type:G0.optional(),limit:U.number().optional().default(20),offset:U.number().optional().default(0)}).transform(($)=>{let J=[],Q=$.milestone_type;if(!Q&&$.action_type)Q=$.action_type,J.push("action_type");return{task_id:$.task_id,milestone_type:Q,limit:$.limit,offset:$.offset,_deprecated_fields_used:J}}),G8=U.object({operation_id:U.number().describe("Operation ID"),milestone_title:q2.optional(),milestone_description:G2,process_description:X2.optional(),action_title:U.string().min(1).max(_0).optional(),action_description:U.string().max(M0).optional()}),W9=G8.transform(($)=>{let J=[],Q=$.milestone_title,W=$.milestone_description;if(!Q&&$.action_title)Q=$.action_title,J.push("action_title");if(W===void 0&&$.action_description!==void 0)W=$.action_description,J.push("action_description");return{operation_id:$.operation_id,milestone_title:Q,milestone_description:W,process_description:$.process_description,_deprecated_fields_used:J}}),Y9=U.object({operation_id:U.number().describe("Operation ID")});function M8($){return`Invalid parameters: ${$.issues.map((Q)=>`${Q.path.join(".")||"<root>"}: ${Q.message}`).join("; ")}`}function _8($){if(!$.milestone_type)return{ok:!1,error:"milestone_type is required (or action_type for backward compatibility). Use one of: create, progress, milestone, problem, solution, decision, review, completed, workflow_extracted."};if(!$.milestone_title)return{ok:!1,error:"milestone_title is required (or action_title for backward compatibility)."};return{ok:!0,milestoneType:$.milestone_type,milestoneTitle:$.milestone_title}}function t0($){return{name:"task_operation_create",description:"Create an operation record for a task. Tracks milestones (state/result) and process (strategy + tool steps). Dual-dimension schema: milestone_type/title/description captures WHAT milestone was reached; process_description (100-150 chars) captures HOW. Legacy action_* fields are accepted as deprecated aliases.",parameters:B2,execute:async(J,Q)=>{let W;try{W=B2.parse(J)}catch(H){if(H instanceof l)return{success:!1,output:"",error:M8(H),metadata:{execution_time_ms:0}};throw H}let Y=_8(W);if(!Y.ok)return{success:!1,output:"",error:Y.error,metadata:{execution_time_ms:0}};let B=Q.session_id||"unknown";try{let H=await $.createOperation({taskId:W.task_id,sessionId:B,milestoneType:Y.milestoneType,milestoneTitle:Y.milestoneTitle,milestoneDescription:W.milestone_description,processDescription:W.process_description,mdPath:W.md_path}),X=`Operation created: #${H.id} for task #${H.taskId} [milestone=${H.milestoneType}] ${H.milestoneTitle}`,q=[];if(W._deprecated_fields_used.length>0)q.push(`\u26A0\uFE0F DEPRECATION NOTICE: \u4F60\u4F7F\u7528\u4E86\u65E7\u7684 action_* \u5B57\u6BB5 (${W._deprecated_fields_used.join(", ")})\uFF0C\u5DF2\u81EA\u52A8\u6620\u5C04\u5230 milestone_* \u5B57\u6BB5\u3002`+"\u8BF7\u5C3D\u5FEB\u8FC1\u79FB\u5230 milestone_type / milestone_title / milestone_description \u4E3B\u5B57\u6BB5\u3002");if(q.length>0)X+=`
|
|
312
|
+
|
|
313
|
+
`+q.join(`
|
|
314
|
+
`);return{success:!0,output:X,metadata:{execution_time_ms:0,operation_id:H.id,task_id:H.taskId,session_id:H.sessionId,deprecated_fields_used:W._deprecated_fields_used}}}catch(H){return{success:!1,output:"",error:H instanceof Error?H.message:String(H),metadata:{execution_time_ms:0}}}}}}function e0($){return{name:"task_operation_list",description:"List operation records for a task with optional filters. Use milestone_type (canonical) or action_type (deprecated, auto-mapped).",parameters:H2,execute:async(J,Q)=>{let W=H2.parse(J);try{let Y=await $.listOperations({taskId:W.task_id,milestoneType:W.milestone_type,limit:W.limit,offset:W.offset}),B=JSON.stringify({operations:Y,count:Y.length});if(W._deprecated_fields_used.length>0)B=`\u26A0\uFE0F DEPRECATION NOTICE: \u4F60\u4F7F\u7528\u4E86\u65E7\u7684 action_type \u5B57\u6BB5\uFF0C\u5DF2\u81EA\u52A8\u6620\u5C04\u5230 milestone_type\u3002
|
|
315
|
+
|
|
316
|
+
`+B;return{success:!0,output:B,metadata:{execution_time_ms:0,deprecated_fields_used:W._deprecated_fields_used}}}catch(Y){return{success:!1,output:"",error:Y instanceof Error?Y.message:String(Y),metadata:{execution_time_ms:0}}}}}}var _2=Symbol("Let zodToJsonSchema decide on which parser to use");var M2={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",target:"jsonSchema7",strictUnions:!1,definitions:{},errorMessages:!1,markdownDescription:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref",openAiAnyTypeName:"OpenAiAnyType"},U2=($)=>typeof $==="string"?{...M2,name:$}:{...M2,...$};var V2=($)=>{let J=U2($),Q=J.name!==void 0?[...J.basePath,J.definitionPath,J.name]:J.basePath;return{...J,flags:{hasReferencedOpenAiAnyType:!1},currentPath:Q,propertyPath:void 0,seen:new Map(Object.entries(J.definitions).map(([W,Y])=>[Y._def,{def:Y._def,path:[...J.basePath,J.definitionPath,W],jsonSchema:void 0}]))}};function $1($,J,Q,W){if(!W?.errorMessages)return;if(Q)$.errorMessage={...$.errorMessage,[J]:Q}}function f($,J,Q,W,Y){$[J]=Q,$1($,J,W,Y)}var U0=($,J)=>{let Q=0;for(;Q<$.length&&Q<J.length;Q++)if($[Q]!==J[Q])break;return[($.length-Q).toString(),...J.slice(Q)].join("/")};function y($){if($.target!=="openAi")return{};let J=[...$.basePath,$.definitionPath,$.openAiAnyTypeName];return $.flags.hasReferencedOpenAiAnyType=!0,{$ref:$.$refStrategy==="relative"?U0(J,$.currentPath):J.join("/")}}function D2($,J){let Q={type:"array"};if($.type?._def&&$.type?._def?.typeName!==D.ZodAny)Q.items=F($.type._def,{...J,currentPath:[...J.currentPath,"items"]});if($.minLength)f(Q,"minItems",$.minLength.value,$.minLength.message,J);if($.maxLength)f(Q,"maxItems",$.maxLength.value,$.maxLength.message,J);if($.exactLength)f(Q,"minItems",$.exactLength.value,$.exactLength.message,J),f(Q,"maxItems",$.exactLength.value,$.exactLength.message,J);return Q}function A2($,J){let Q={type:"integer",format:"int64"};if(!$.checks)return Q;for(let W of $.checks)switch(W.kind){case"min":if(J.target==="jsonSchema7")if(W.inclusive)f(Q,"minimum",W.value,W.message,J);else f(Q,"exclusiveMinimum",W.value,W.message,J);else{if(!W.inclusive)Q.exclusiveMinimum=!0;f(Q,"minimum",W.value,W.message,J)}break;case"max":if(J.target==="jsonSchema7")if(W.inclusive)f(Q,"maximum",W.value,W.message,J);else f(Q,"exclusiveMaximum",W.value,W.message,J);else{if(!W.inclusive)Q.exclusiveMaximum=!0;f(Q,"maximum",W.value,W.message,J)}break;case"multipleOf":f(Q,"multipleOf",W.value,W.message,J);break}return Q}function z2(){return{type:"boolean"}}function V0($,J){return F($.type._def,J)}var K2=($,J)=>{return F($.innerType._def,J)};function J1($,J,Q){let W=Q??J.dateStrategy;if(Array.isArray(W))return{anyOf:W.map((Y,B)=>J1($,J,Y))};switch(W){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return U8($,J)}}var U8=($,J)=>{let Q={type:"integer",format:"unix-time"};if(J.target==="openApi3")return Q;for(let W of $.checks)switch(W.kind){case"min":f(Q,"minimum",W.value,W.message,J);break;case"max":f(Q,"maximum",W.value,W.message,J);break}return Q};function b2($,J){return{...F($.innerType._def,J),default:$.defaultValue()}}function j2($,J){return J.effectStrategy==="input"?F($.schema._def,J):y(J)}function N2($){return{type:"string",enum:Array.from($.values)}}var V8=($)=>{if("type"in $&&$.type==="string")return!1;return"allOf"in $};function R2($,J){let Q=[F($.left._def,{...J,currentPath:[...J.currentPath,"allOf","0"]}),F($.right._def,{...J,currentPath:[...J.currentPath,"allOf","1"]})].filter((B)=>!!B),W=J.target==="jsonSchema2019-09"?{unevaluatedProperties:!1}:void 0,Y=[];return Q.forEach((B)=>{if(V8(B)){if(Y.push(...B.allOf),B.unevaluatedProperties===void 0)W=void 0}else{let H=B;if("additionalProperties"in B&&B.additionalProperties===!1){let{additionalProperties:X,...q}=B;H=q}else W=void 0;Y.push(H)}}),Y.length?{allOf:Y,...W}:void 0}function O2($,J){let Q=typeof $.value;if(Q!=="bigint"&&Q!=="number"&&Q!=="boolean"&&Q!=="string")return{type:Array.isArray($.value)?"array":"object"};if(J.target==="openApi3")return{type:Q==="bigint"?"integer":Q,enum:[$.value]};return{type:Q==="bigint"?"integer":Q,const:$.value}}var Q1=void 0,e={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>{if(Q1===void 0)Q1=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u");return Q1},uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function D0($,J){let Q={type:"string"};if($.checks)for(let W of $.checks)switch(W.kind){case"min":f(Q,"minLength",typeof Q.minLength==="number"?Math.max(Q.minLength,W.value):W.value,W.message,J);break;case"max":f(Q,"maxLength",typeof Q.maxLength==="number"?Math.min(Q.maxLength,W.value):W.value,W.message,J);break;case"email":switch(J.emailStrategy){case"format:email":$$(Q,"email",W.message,J);break;case"format:idn-email":$$(Q,"idn-email",W.message,J);break;case"pattern:zod":c(Q,e.email,W.message,J);break}break;case"url":$$(Q,"uri",W.message,J);break;case"uuid":$$(Q,"uuid",W.message,J);break;case"regex":c(Q,W.regex,W.message,J);break;case"cuid":c(Q,e.cuid,W.message,J);break;case"cuid2":c(Q,e.cuid2,W.message,J);break;case"startsWith":c(Q,RegExp(`^${W1(W.value,J)}`),W.message,J);break;case"endsWith":c(Q,RegExp(`${W1(W.value,J)}$`),W.message,J);break;case"datetime":$$(Q,"date-time",W.message,J);break;case"date":$$(Q,"date",W.message,J);break;case"time":$$(Q,"time",W.message,J);break;case"duration":$$(Q,"duration",W.message,J);break;case"length":f(Q,"minLength",typeof Q.minLength==="number"?Math.max(Q.minLength,W.value):W.value,W.message,J),f(Q,"maxLength",typeof Q.maxLength==="number"?Math.min(Q.maxLength,W.value):W.value,W.message,J);break;case"includes":{c(Q,RegExp(W1(W.value,J)),W.message,J);break}case"ip":{if(W.version!=="v6")$$(Q,"ipv4",W.message,J);if(W.version!=="v4")$$(Q,"ipv6",W.message,J);break}case"base64url":c(Q,e.base64url,W.message,J);break;case"jwt":c(Q,e.jwt,W.message,J);break;case"cidr":{if(W.version!=="v6")c(Q,e.ipv4Cidr,W.message,J);if(W.version!=="v4")c(Q,e.ipv6Cidr,W.message,J);break}case"emoji":c(Q,e.emoji(),W.message,J);break;case"ulid":{c(Q,e.ulid,W.message,J);break}case"base64":{switch(J.base64Strategy){case"format:binary":{$$(Q,"binary",W.message,J);break}case"contentEncoding:base64":{f(Q,"contentEncoding","base64",W.message,J);break}case"pattern:zod":{c(Q,e.base64,W.message,J);break}}break}case"nanoid":c(Q,e.nanoid,W.message,J);case"toLowerCase":case"toUpperCase":case"trim":break;default:((Y)=>{})(W)}return Q}function W1($,J){return J.patternStrategy==="escape"?A8($):$}var D8=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function A8($){let J="";for(let Q=0;Q<$.length;Q++){if(!D8.has($[Q]))J+="\\";J+=$[Q]}return J}function $$($,J,Q,W){if($.format||$.anyOf?.some((Y)=>Y.format)){if(!$.anyOf)$.anyOf=[];if($.format){if($.anyOf.push({format:$.format,...$.errorMessage&&W.errorMessages&&{errorMessage:{format:$.errorMessage.format}}}),delete $.format,$.errorMessage){if(delete $.errorMessage.format,Object.keys($.errorMessage).length===0)delete $.errorMessage}}$.anyOf.push({format:J,...Q&&W.errorMessages&&{errorMessage:{format:Q}}})}else f($,"format",J,Q,W)}function c($,J,Q,W){if($.pattern||$.allOf?.some((Y)=>Y.pattern)){if(!$.allOf)$.allOf=[];if($.pattern){if($.allOf.push({pattern:$.pattern,...$.errorMessage&&W.errorMessages&&{errorMessage:{pattern:$.errorMessage.pattern}}}),delete $.pattern,$.errorMessage){if(delete $.errorMessage.pattern,Object.keys($.errorMessage).length===0)delete $.errorMessage}}$.allOf.push({pattern:F2(J,W),...Q&&W.errorMessages&&{errorMessage:{pattern:Q}}})}else f($,"pattern",F2(J,W),Q,W)}function F2($,J){if(!J.applyRegexFlags||!$.flags)return $.source;let Q={i:$.flags.includes("i"),m:$.flags.includes("m"),s:$.flags.includes("s")},W=Q.i?$.source.toLowerCase():$.source,Y="",B=!1,H=!1,X=!1;for(let q=0;q<W.length;q++){if(B){Y+=W[q],B=!1;continue}if(Q.i){if(H){if(W[q].match(/[a-z]/)){if(X)Y+=W[q],Y+=`${W[q-2]}-${W[q]}`.toUpperCase(),X=!1;else if(W[q+1]==="-"&&W[q+2]?.match(/[a-z]/))Y+=W[q],X=!0;else Y+=`${W[q]}${W[q].toUpperCase()}`;continue}}else if(W[q].match(/[a-z]/)){Y+=`[${W[q]}${W[q].toUpperCase()}]`;continue}}if(Q.m){if(W[q]==="^"){Y+=`(^|(?<=[\r
|
|
317
|
+
]))`;continue}else if(W[q]==="$"){Y+=`($|(?=[\r
|
|
318
|
+
]))`;continue}}if(Q.s&&W[q]==="."){Y+=H?`${W[q]}\r
|
|
319
|
+
`:`[${W[q]}\r
|
|
320
|
+
]`;continue}if(Y+=W[q],W[q]==="\\")B=!0;else if(H&&W[q]==="]")H=!1;else if(!H&&W[q]==="[")H=!0}try{new RegExp(Y)}catch{return console.warn(`Could not convert regex pattern at ${J.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),$.source}return Y}function A0($,J){if(J.target==="openAi")console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");if(J.target==="openApi3"&&$.keyType?._def.typeName===D.ZodEnum)return{type:"object",required:$.keyType._def.values,properties:$.keyType._def.values.reduce((W,Y)=>({...W,[Y]:F($.valueType._def,{...J,currentPath:[...J.currentPath,"properties",Y]})??y(J)}),{}),additionalProperties:J.rejectedAdditionalProperties};let Q={type:"object",additionalProperties:F($.valueType._def,{...J,currentPath:[...J.currentPath,"additionalProperties"]})??J.allowedAdditionalProperties};if(J.target==="openApi3")return Q;if($.keyType?._def.typeName===D.ZodString&&$.keyType._def.checks?.length){let{type:W,...Y}=D0($.keyType._def,J);return{...Q,propertyNames:Y}}else if($.keyType?._def.typeName===D.ZodEnum)return{...Q,propertyNames:{enum:$.keyType._def.values}};else if($.keyType?._def.typeName===D.ZodBranded&&$.keyType._def.type._def.typeName===D.ZodString&&$.keyType._def.type._def.checks?.length){let{type:W,...Y}=V0($.keyType._def,J);return{...Q,propertyNames:Y}}return Q}function L2($,J){if(J.mapStrategy==="record")return A0($,J);let Q=F($.keyType._def,{...J,currentPath:[...J.currentPath,"items","items","0"]})||y(J),W=F($.valueType._def,{...J,currentPath:[...J.currentPath,"items","items","1"]})||y(J);return{type:"array",maxItems:125,items:{type:"array",items:[Q,W],minItems:2,maxItems:2}}}function w2($){let J=$.values,W=Object.keys($.values).filter((B)=>{return typeof J[J[B]]!=="number"}).map((B)=>J[B]),Y=Array.from(new Set(W.map((B)=>typeof B)));return{type:Y.length===1?Y[0]==="string"?"string":"number":["string","number"],enum:W}}function S2($){return $.target==="openAi"?void 0:{not:y({...$,currentPath:[...$.currentPath,"not"]})}}function E2($){return $.target==="openApi3"?{enum:["null"],nullable:!0}:{type:"null"}}var t$={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function P2($,J){if(J.target==="openApi3")return v2($,J);let Q=$.options instanceof Map?Array.from($.options.values()):$.options;if(Q.every((W)=>(W._def.typeName in t$)&&(!W._def.checks||!W._def.checks.length))){let W=Q.reduce((Y,B)=>{let H=t$[B._def.typeName];return H&&!Y.includes(H)?[...Y,H]:Y},[]);return{type:W.length>1?W:W[0]}}else if(Q.every((W)=>W._def.typeName==="ZodLiteral"&&!W.description)){let W=Q.reduce((Y,B)=>{let H=typeof B._def.value;switch(H){case"string":case"number":case"boolean":return[...Y,H];case"bigint":return[...Y,"integer"];case"object":if(B._def.value===null)return[...Y,"null"];case"symbol":case"undefined":case"function":default:return Y}},[]);if(W.length===Q.length){let Y=W.filter((B,H,X)=>X.indexOf(B)===H);return{type:Y.length>1?Y:Y[0],enum:Q.reduce((B,H)=>{return B.includes(H._def.value)?B:[...B,H._def.value]},[])}}}else if(Q.every((W)=>W._def.typeName==="ZodEnum"))return{type:"string",enum:Q.reduce((W,Y)=>[...W,...Y._def.values.filter((B)=>!W.includes(B))],[])};return v2($,J)}var v2=($,J)=>{let Q=($.options instanceof Map?Array.from($.options.values()):$.options).map((W,Y)=>F(W._def,{...J,currentPath:[...J.currentPath,"anyOf",`${Y}`]})).filter((W)=>!!W&&(!J.strictUnions||typeof W==="object"&&Object.keys(W).length>0));return Q.length?{anyOf:Q}:void 0};function f2($,J){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes($.innerType._def.typeName)&&(!$.innerType._def.checks||!$.innerType._def.checks.length)){if(J.target==="openApi3")return{type:t$[$.innerType._def.typeName],nullable:!0};return{type:[t$[$.innerType._def.typeName],"null"]}}if(J.target==="openApi3"){let W=F($.innerType._def,{...J,currentPath:[...J.currentPath]});if(W&&"$ref"in W)return{allOf:[W],nullable:!0};return W&&{...W,nullable:!0}}let Q=F($.innerType._def,{...J,currentPath:[...J.currentPath,"anyOf","0"]});return Q&&{anyOf:[Q,{type:"null"}]}}function C2($,J){let Q={type:"number"};if(!$.checks)return Q;for(let W of $.checks)switch(W.kind){case"int":Q.type="integer",$1(Q,"type",W.message,J);break;case"min":if(J.target==="jsonSchema7")if(W.inclusive)f(Q,"minimum",W.value,W.message,J);else f(Q,"exclusiveMinimum",W.value,W.message,J);else{if(!W.inclusive)Q.exclusiveMinimum=!0;f(Q,"minimum",W.value,W.message,J)}break;case"max":if(J.target==="jsonSchema7")if(W.inclusive)f(Q,"maximum",W.value,W.message,J);else f(Q,"exclusiveMaximum",W.value,W.message,J);else{if(!W.inclusive)Q.exclusiveMaximum=!0;f(Q,"maximum",W.value,W.message,J)}break;case"multipleOf":f(Q,"multipleOf",W.value,W.message,J);break}return Q}function k2($,J){let Q=J.target==="openAi",W={type:"object",properties:{}},Y=[],B=$.shape();for(let X in B){let q=B[X];if(q===void 0||q._def===void 0)continue;let _=K8(q);if(_&&Q){if(q._def.typeName==="ZodOptional")q=q._def.innerType;if(!q.isNullable())q=q.nullable();_=!1}let b=F(q._def,{...J,currentPath:[...J.currentPath,"properties",X],propertyPath:[...J.currentPath,"properties",X]});if(b===void 0)continue;if(W.properties[X]=b,!_)Y.push(X)}if(Y.length)W.required=Y;let H=z8($,J);if(H!==void 0)W.additionalProperties=H;return W}function z8($,J){if($.catchall._def.typeName!=="ZodNever")return F($.catchall._def,{...J,currentPath:[...J.currentPath,"additionalProperties"]});switch($.unknownKeys){case"passthrough":return J.allowedAdditionalProperties;case"strict":return J.rejectedAdditionalProperties;case"strip":return J.removeAdditionalStrategy==="strict"?J.allowedAdditionalProperties:J.rejectedAdditionalProperties}}function K8($){try{return $.isOptional()}catch{return!0}}var I2=($,J)=>{if(J.currentPath.toString()===J.propertyPath?.toString())return F($.innerType._def,J);let Q=F($.innerType._def,{...J,currentPath:[...J.currentPath,"anyOf","1"]});return Q?{anyOf:[{not:y(J)},Q]}:y(J)};var h2=($,J)=>{if(J.pipeStrategy==="input")return F($.in._def,J);else if(J.pipeStrategy==="output")return F($.out._def,J);let Q=F($.in._def,{...J,currentPath:[...J.currentPath,"allOf","0"]}),W=F($.out._def,{...J,currentPath:[...J.currentPath,"allOf",Q?"1":"0"]});return{allOf:[Q,W].filter((Y)=>Y!==void 0)}};function y2($,J){return F($.type._def,J)}function g2($,J){let W={type:"array",uniqueItems:!0,items:F($.valueType._def,{...J,currentPath:[...J.currentPath,"items"]})};if($.minSize)f(W,"minItems",$.minSize.value,$.minSize.message,J);if($.maxSize)f(W,"maxItems",$.maxSize.value,$.maxSize.message,J);return W}function Z2($,J){if($.rest)return{type:"array",minItems:$.items.length,items:$.items.map((Q,W)=>F(Q._def,{...J,currentPath:[...J.currentPath,"items",`${W}`]})).reduce((Q,W)=>W===void 0?Q:[...Q,W],[]),additionalItems:F($.rest._def,{...J,currentPath:[...J.currentPath,"additionalItems"]})};else return{type:"array",minItems:$.items.length,maxItems:$.items.length,items:$.items.map((Q,W)=>F(Q._def,{...J,currentPath:[...J.currentPath,"items",`${W}`]})).reduce((Q,W)=>W===void 0?Q:[...Q,W],[])}}function T2($){return{not:y($)}}function x2($){return y($)}var m2=($,J)=>{return F($.innerType._def,J)};var l2=($,J,Q)=>{switch(J){case D.ZodString:return D0($,Q);case D.ZodNumber:return C2($,Q);case D.ZodObject:return k2($,Q);case D.ZodBigInt:return A2($,Q);case D.ZodBoolean:return z2();case D.ZodDate:return J1($,Q);case D.ZodUndefined:return T2(Q);case D.ZodNull:return E2(Q);case D.ZodArray:return D2($,Q);case D.ZodUnion:case D.ZodDiscriminatedUnion:return P2($,Q);case D.ZodIntersection:return R2($,Q);case D.ZodTuple:return Z2($,Q);case D.ZodRecord:return A0($,Q);case D.ZodLiteral:return O2($,Q);case D.ZodEnum:return N2($);case D.ZodNativeEnum:return w2($);case D.ZodNullable:return f2($,Q);case D.ZodOptional:return I2($,Q);case D.ZodMap:return L2($,Q);case D.ZodSet:return g2($,Q);case D.ZodLazy:return()=>$.getter()._def;case D.ZodPromise:return y2($,Q);case D.ZodNaN:case D.ZodNever:return S2(Q);case D.ZodEffects:return j2($,Q);case D.ZodAny:return y(Q);case D.ZodUnknown:return x2(Q);case D.ZodDefault:return b2($,Q);case D.ZodBranded:return V0($,Q);case D.ZodReadonly:return m2($,Q);case D.ZodCatch:return K2($,Q);case D.ZodPipeline:return h2($,Q);case D.ZodFunction:case D.ZodVoid:case D.ZodSymbol:return;default:return((W)=>{return})(J)}};function F($,J,Q=!1){let W=J.seen.get($);if(J.override){let X=J.override?.($,J,W,Q);if(X!==_2)return X}if(W&&!Q){let X=b8(W,J);if(X!==void 0)return X}let Y={def:$,path:J.currentPath,jsonSchema:void 0};J.seen.set($,Y);let B=l2($,$.typeName,J),H=typeof B==="function"?F(B(),J):B;if(H)j8($,J,H);if(J.postProcess){let X=J.postProcess(H,$,J);return Y.jsonSchema=H,X}return Y.jsonSchema=H,H}var b8=($,J)=>{switch(J.$refStrategy){case"root":return{$ref:$.path.join("/")};case"relative":return{$ref:U0(J.currentPath,$.path)};case"none":case"seen":{if($.path.length<J.currentPath.length&&$.path.every((Q,W)=>J.currentPath[W]===Q))return console.warn(`Recursive reference detected at ${J.currentPath.join("/")}! Defaulting to any`),y(J);return J.$refStrategy==="seen"?y(J):void 0}}},j8=($,J,Q)=>{if($.description){if(Q.description=$.description,J.markdownDescription)Q.markdownDescription=$.description}return Q};var Y1=($,J)=>{let Q=V2(J),W=typeof J==="object"&&J.definitions?Object.entries(J.definitions).reduce((q,[_,b])=>({...q,[_]:F(b._def,{...Q,currentPath:[...Q.basePath,Q.definitionPath,_]},!0)??y(Q)}),{}):void 0,Y=typeof J==="string"?J:J?.nameStrategy==="title"?void 0:J?.name,B=F($._def,Y===void 0?Q:{...Q,currentPath:[...Q.basePath,Q.definitionPath,Y]},!1)??y(Q),H=typeof J==="object"&&J.name!==void 0&&J.nameStrategy==="title"?J.name:void 0;if(H!==void 0)B.title=H;if(Q.flags.hasReferencedOpenAiAnyType){if(!W)W={};if(!W[Q.openAiAnyTypeName])W[Q.openAiAnyTypeName]={type:["string","number","integer","boolean","array","null"],items:{$ref:Q.$refStrategy==="relative"?"1":[...Q.basePath,Q.definitionPath,Q.openAiAnyTypeName].join("/")}}}let X=Y===void 0?W?{...B,[Q.definitionPath]:W}:B:{$ref:[...Q.$refStrategy==="relative"?[]:Q.basePath,Q.definitionPath,Y].join("/"),[Q.definitionPath]:{...W,[Y]:B}};if(Q.target==="jsonSchema7")X.$schema="http://json-schema.org/draft-07/schema#";else if(Q.target==="jsonSchema2019-09"||Q.target==="openAi")X.$schema="https://json-schema.org/draft/2019-09/schema#";if(Q.target==="openAi"&&(("anyOf"in X)||("oneOf"in X)||("allOf"in X)||("type"in X)&&Array.isArray(X.type)))console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");return X};var N8=[c0,r0,n0,i0,d0,p0,o0,t0,e0];function R8($){let J=$;if(!J)return{};let Q=J.shape?J:J._def?.schema??J;try{let W=Y1(Q,{target:"jsonSchema7",$refStrategy:"none",effectStrategy:"input"}),{$schema:Y,...B}=W;return B}catch{return{}}}function u2($,J={}){let Q=j1($,J);return N8.map((W)=>{let Y=W(Q);return{name:Y.name,description:Y.description,input:R8(Y.parameters),options:{codemode:!1},execute:async(B,H)=>{let X={session_id:H?.sessionID??J.sessionId??"unknown",workdir:H?.directory};try{let q=await Y.execute(B??{},X),_=typeof q.output==="string"?q.output:JSON.stringify(q.output??"");return{content:q.success?_:`ERROR: ${q.error??"unknown error"}`,metadata:{tool:Y.name,ok:q.success}}}catch(q){return{content:`ERROR: ${q instanceof Error?q.message:String(q)}`,metadata:{tool:Y.name,ok:!1}}}}}})}function c2($,J){let Q=$?.dispose;if(typeof Q==="function")J.push(Q)}async function n2($,J){let Q=J.enabled!==!1,W={enabled:Q,agentId:null,toolNames:[],errors:[],disposers:[]};if(!Q)return W;let Y=$??{},B=J.agent??l$;if(typeof Y.agent?.transform==="function")try{let X=await Y.agent.transform((q)=>{N0(q)});c2(X,W.disposers),W.agentId=B}catch(X){W.errors.push(`roy agent registration failed: ${B1(X)}`)}else W.errors.push("ctx.agent.transform unavailable \u2014 roy agent not registered");let H=[];try{H=u2(J.store,{agent:B,...J.sessionId?{sessionId:J.sessionId}:{}})}catch(X){return W.errors.push(`roy tool construction failed: ${B1(X)}`),W}if(typeof Y.tool?.transform==="function")try{let X=await Y.tool.transform((q)=>{for(let _ of H)q.add(_)});c2(X,W.disposers),W.toolNames=H.map((q)=>q.name)}catch(X){W.errors.push(`roy tool registration failed: ${B1(X)}`)}else W.errors.push("ctx.tool.transform unavailable \u2014 roy task tools not registered");return W}function B1($){return $ instanceof Error?$.message:String($)}import{join as q1}from"path";import{homedir as P8}from"os";import{mkdirSync as f8}from"fs";import{Database as O8}from"bun:sqlite";import{createHash as F8,randomUUID as L8}from"crypto";var w8=`
|
|
321
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
322
|
+
id TEXT PRIMARY KEY,
|
|
323
|
+
title TEXT NOT NULL,
|
|
324
|
+
description TEXT,
|
|
325
|
+
status TEXT NOT NULL DEFAULT 'pending',
|
|
326
|
+
priority INTEGER NOT NULL DEFAULT 3,
|
|
327
|
+
owner TEXT,
|
|
328
|
+
tags TEXT,
|
|
329
|
+
parent_id TEXT,
|
|
330
|
+
blocked_by TEXT NOT NULL DEFAULT '[]',
|
|
331
|
+
retry_of TEXT,
|
|
332
|
+
retry_count INTEGER NOT NULL DEFAULT 0,
|
|
333
|
+
session_id TEXT,
|
|
334
|
+
roy TEXT,
|
|
335
|
+
created_at TEXT NOT NULL,
|
|
336
|
+
updated_at TEXT NOT NULL
|
|
337
|
+
);
|
|
338
|
+
CREATE INDEX IF NOT EXISTS tasks_parent_idx ON tasks(parent_id);
|
|
339
|
+
CREATE INDEX IF NOT EXISTS tasks_status_idx ON tasks(status);
|
|
340
|
+
CREATE INDEX IF NOT EXISTS tasks_session_idx ON tasks(session_id);
|
|
341
|
+
|
|
342
|
+
CREATE TABLE IF NOT EXISTS task_idempotency (
|
|
343
|
+
idempotency_key TEXT PRIMARY KEY,
|
|
344
|
+
task_id TEXT NOT NULL,
|
|
345
|
+
created_at TEXT NOT NULL
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
CREATE TABLE IF NOT EXISTS operations (
|
|
349
|
+
id TEXT PRIMARY KEY,
|
|
350
|
+
task_id TEXT,
|
|
351
|
+
type TEXT NOT NULL,
|
|
352
|
+
data TEXT NOT NULL,
|
|
353
|
+
created_at TEXT NOT NULL,
|
|
354
|
+
prev_hash TEXT NOT NULL,
|
|
355
|
+
hash TEXT NOT NULL
|
|
356
|
+
);
|
|
357
|
+
CREATE INDEX IF NOT EXISTS ops_task_idx ON operations(task_id);
|
|
358
|
+
CREATE INDEX IF NOT EXISTS ops_type_idx ON operations(type);
|
|
359
|
+
CREATE INDEX IF NOT EXISTS ops_created_idx ON operations(created_at);
|
|
360
|
+
|
|
361
|
+
CREATE TABLE IF NOT EXISTS bounties (
|
|
362
|
+
id TEXT PRIMARY KEY,
|
|
363
|
+
subject TEXT NOT NULL,
|
|
364
|
+
body TEXT NOT NULL,
|
|
365
|
+
from_ TEXT NOT NULL,
|
|
366
|
+
to_ TEXT NOT NULL DEFAULT '*',
|
|
367
|
+
status TEXT NOT NULL DEFAULT 'open',
|
|
368
|
+
claimed_by TEXT,
|
|
369
|
+
task_id TEXT,
|
|
370
|
+
created_at TEXT NOT NULL,
|
|
371
|
+
claimed_at TEXT,
|
|
372
|
+
done_at TEXT
|
|
373
|
+
);
|
|
374
|
+
CREATE INDEX IF NOT EXISTS bounties_status_idx ON bounties(status);
|
|
375
|
+
`;function L$(){return new Date().toISOString()}function H1(){return L8()}function S8($){return F8("sha256").update($).digest("hex")}function i2($){let J=JSON.stringify({id:$.id,type:$.type,data:$.data,prev_hash:$.prev_hash,created_at:$.created_at});return S8(J)}function X1($){return{id:$.id,num:$.num,title:$.title,description:$.description??void 0,status:$.status,priority:$.priority,owner:$.owner??void 0,tags:$.tags??void 0,parent_id:$.parent_id,blocked_by:JSON.parse($.blocked_by),retry_of:$.retry_of,retry_count:$.retry_count,session_id:$.session_id,roy:E8($.roy),created_at:$.created_at,updated_at:$.updated_at}}function E8($){if($===null||$===void 0||$==="")return;try{let J=JSON.parse($);if(J&&typeof J==="object"&&!Array.isArray(J))return J;return}catch{return}}function v8($){try{let J=$.query("PRAGMA table_info(tasks)").all();if(!new Set(J.map((W)=>W.name)).has("roy"))$.exec("ALTER TABLE tasks ADD COLUMN roy TEXT")}catch{}}function d2($){return{id:$.id,num:$.num,task_id:$.task_id,type:$.type,data:JSON.parse($.data),created_at:$.created_at,prev_hash:$.prev_hash,hash:$.hash}}function z0($){return{id:$.id,subject:$.subject,body:$.body,from:$.from_,to:$.to_,status:$.status,claimed_by:$.claimed_by,task_id:$.task_id,created_at:$.created_at,claimed_at:$.claimed_at,done_at:$.done_at}}class K0{db;closedFlag=!1;constructor($){this.db=$}static async create($){let J=new O8($);return J.exec(w8),v8(J),new K0(J)}async close(){if(this.closedFlag)return;this.closedFlag=!0,this.db.close()}async createTask($,J){if(this.closedFlag)throw Error("store closed");if(J){let H=this.db.query("SELECT task_id FROM task_idempotency WHERE idempotency_key = ?").get(J);if(H){let X=await this.getTask(H.task_id);if(X)return X}}let Q=H1(),W=L$(),Y=$.priority??3;if(this.db.query(`INSERT INTO tasks (id, title, description, status, priority, owner, tags,
|
|
376
|
+
parent_id, blocked_by, retry_of, retry_count, session_id, roy, created_at, updated_at)
|
|
377
|
+
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, 0, ?, ?, ?, ?)`).run(Q,$.title,$.description??null,Y,$.owner??null,$.tags??null,$.parent_id??null,JSON.stringify($.blocked_by??[]),$.retry_of??null,$.session_id??null,$.roy===void 0?null:JSON.stringify($.roy),W,W),J)this.db.query(`INSERT INTO task_idempotency (idempotency_key, task_id, created_at)
|
|
378
|
+
VALUES (?, ?, ?)`).run(J,Q,W);await this.appendOperation({task_id:Q,type:"task.created",data:{title:$.title,parent_id:$.parent_id??null}});let B=await this.getTask(Q);if(!B)throw Error("internal: task vanished after insert");return B}async getTask($){if(this.closedFlag)throw Error("store closed");let J=this.db.query("SELECT rowid AS num, * FROM tasks WHERE id = ?").get($);return J?X1(J):null}async getTaskByNum($){if(this.closedFlag)throw Error("store closed");let J=this.db.query("SELECT rowid AS num, * FROM tasks WHERE rowid = ?").get($);return J?X1(J):null}async updateTask($,J){if(this.closedFlag)throw Error("store closed");let Q=await this.getTask($);if(!Q)return null;let W=[],Y=[];if(J.title!==void 0)W.push("title = ?"),Y.push(J.title);if(J.description!==void 0)W.push("description = ?"),Y.push(J.description);if(J.status!==void 0)W.push("status = ?"),Y.push(J.status);if(J.priority!==void 0)W.push("priority = ?"),Y.push(J.priority);if(J.owner!==void 0)W.push("owner = ?"),Y.push(J.owner);if(J.tags!==void 0)W.push("tags = ?"),Y.push(J.tags);if(J.blocked_by!==void 0)W.push("blocked_by = ?"),Y.push(JSON.stringify(J.blocked_by));if(J.roy!==void 0){let B={...Q.roy??{},...J.roy};W.push("roy = ?"),Y.push(JSON.stringify(B))}if(W.push("updated_at = ?"),Y.push(L$()),Y.push($),this.db.query(`UPDATE tasks SET ${W.join(", ")} WHERE id = ?`).run(...Y),J.status!==void 0&&J.status!==Q.status)await this.appendOperation({task_id:$,type:"task.status_changed",data:{from:Q.status,to:J.status}});else await this.appendOperation({task_id:$,type:"task.updated",data:{keys:Object.keys(J)}});return await this.getTask($)}async listTasks($={}){if(this.closedFlag)throw Error("store closed");let J=[],Q=[];if($.status!==void 0)if(Array.isArray($.status))J.push(`status IN (${$.status.map(()=>"?").join(",")})`),Q.push(...$.status);else J.push("status = ?"),Q.push($.status);if($.parent_id!==void 0)if($.parent_id===null)J.push("parent_id IS NULL");else J.push("parent_id = ?"),Q.push($.parent_id);if($.session_id!==void 0)J.push("session_id = ?"),Q.push($.session_id);if($.owner!==void 0)J.push("owner = ?"),Q.push($.owner);if($.tags!==void 0)J.push("tags LIKE ?"),Q.push(`%${$.tags}%`);if($.search!==void 0)J.push("(title LIKE ? OR description LIKE ?)"),Q.push(`%${$.search}%`,`%${$.search}%`);let W=$.limit??100,Y=$.offset??0,B=J.length?`WHERE ${J.join(" AND ")}`:"",H=this.db.query(`SELECT COUNT(*) AS n FROM tasks ${B}`).get(...Q).n;return{tasks:this.db.query(`SELECT rowid AS num, * FROM tasks ${B} ORDER BY created_at DESC LIMIT ? OFFSET ?`).all(...Q,W,Y).map(X1),total:H}}async deleteTask($){if(this.closedFlag)throw Error("store closed");return this.db.query("DELETE FROM tasks WHERE id = ?").run($).changes>0}async setParentId($,J){if(this.closedFlag)throw Error("store closed");this.db.query("UPDATE tasks SET parent_id = ?, updated_at = ? WHERE id = ?").run(J,L$(),$)}async appendOperation($){if(this.closedFlag)throw Error("store closed");let Q=this.db.query("SELECT hash FROM operations ORDER BY rowid DESC LIMIT 1").get()?.hash??"0".repeat(64),W=H1(),Y=L$(),B=i2({id:W,type:$.type,data:$.data,prev_hash:Q,created_at:Y});this.db.query(`INSERT INTO operations (id, task_id, type, data, created_at, prev_hash, hash)
|
|
379
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`).run(W,$.task_id,$.type,JSON.stringify($.data),Y,Q,B);let H=this.db.query("SELECT last_insert_rowid() AS n").get().n;return{id:W,num:H,task_id:$.task_id,type:$.type,data:$.data,created_at:Y,prev_hash:Q,hash:B}}async getOperationByNum($){if(this.closedFlag)throw Error("store closed");let J=this.db.query("SELECT rowid AS num, * FROM operations WHERE rowid = ?").get($);return J?d2(J):null}async updateOperation($,J){if(this.closedFlag)throw Error("store closed");let Q=await this.getOperationByNum($);if(!Q)return null;let W=[],Y=[];if(J.type!==void 0)W.push("type = ?"),Y.push(J.type);if(J.data!==void 0)W.push("data = ?"),Y.push(JSON.stringify(J.data));if(W.length===0)return Q;return Y.push($),this.db.query(`UPDATE operations SET ${W.join(", ")} WHERE rowid = ?`).run(...Y),await this.getOperationByNum($)}async deleteOperation($){if(this.closedFlag)throw Error("store closed");return this.db.query("DELETE FROM operations WHERE rowid = ?").run($).changes>0}async listOperations($={}){if(this.closedFlag)throw Error("store closed");let J=[],Q=[];if($.task_id!==void 0)J.push("task_id = ?"),Q.push($.task_id);if($.type!==void 0)J.push("type = ?"),Q.push($.type);let W=$.limit??100,Y=$.offset??0,B=J.length?`WHERE ${J.join(" AND ")}`:"",H=this.db.query(`SELECT COUNT(*) AS n FROM operations ${B}`).get(...Q).n;return{operations:this.db.query(`SELECT rowid AS num, * FROM operations ${B} ORDER BY rowid ASC LIMIT ? OFFSET ?`).all(...Q,W,Y).map(d2),total:H}}async verifyChain(){if(this.closedFlag)throw Error("store closed");let $=this.db.query("SELECT * FROM operations ORDER BY rowid ASC").all(),J="0".repeat(64);for(let Q of $){let W=i2({id:Q.id,type:Q.type,data:JSON.parse(Q.data),prev_hash:J,created_at:Q.created_at});if(Q.prev_hash!==J)return!1;if(Q.hash!==W)return!1;J=Q.hash}return!0}async tamperOpForTest($,J){this.db.query("UPDATE operations SET data = ? WHERE rowid = ?").run(JSON.stringify(J),$)}async sendBounty($){if(this.closedFlag)throw Error("store closed");let J=H1(),Q=L$();this.db.query(`INSERT INTO bounties (id, subject, body, from_, status, created_at)
|
|
380
|
+
VALUES (?, ?, ?, ?, 'open', ?)`).run(J,$.subject,$.body,$.from,Q),await this.appendOperation({task_id:null,type:"bounty.sent",data:{bounty_id:J,subject:$.subject,from:$.from}});let W=this.db.query("SELECT * FROM bounties WHERE id = ?").get(J);return z0(W)}async claimBounty($){if(this.closedFlag)throw Error("store closed");let J=this.db.query("SELECT * FROM bounties WHERE status = 'open' ORDER BY created_at ASC LIMIT 1").get();if(!J)return null;let Q=L$();this.db.query("UPDATE bounties SET status = 'claimed', claimed_by = ?, claimed_at = ? WHERE id = ?").run($,Q,J.id),await this.appendOperation({task_id:null,type:"bounty.claimed",data:{bounty_id:J.id,by:$}});let W=this.db.query("SELECT * FROM bounties WHERE id = ?").get(J.id);return z0(W)}async completeBounty($,J){if(this.closedFlag)throw Error("store closed");let Q=L$();if(this.db.query(`UPDATE bounties SET status = 'done', task_id = ?, done_at = ?
|
|
381
|
+
WHERE id = ? AND status = 'claimed'`).run(J,Q,$).changes===0)return null;await this.appendOperation({task_id:null,type:"bounty.completed",data:{bounty_id:$,task_id:J}});let Y=this.db.query("SELECT * FROM bounties WHERE id = ?").get($);return z0(Y)}async listBounties($={}){if(this.closedFlag)throw Error("store closed");let J=[],Q=[];if($.status!==void 0)J.push("status = ?"),Q.push($.status);if($.to!==void 0)J.push("to_ = ?"),Q.push($.to);let W=J.length?`WHERE ${J.join(" AND ")}`:"";return this.db.query(`SELECT * FROM bounties ${W} ORDER BY created_at DESC`).all(...Q).map(z0)}}var C8=q1(P8(),".roy-task-plugin"),k8=q1(C8,"tasks.db");class m${inner;constructor($){this.inner=$}static async create($){let J=$??k8;if(J!==":memory:")f8(q1(J,".."),{recursive:!0});let Q=await K0.create(J);return new m$(Q)}createTask(...$){return this.inner.createTask(...$)}getTask(...$){return this.inner.getTask(...$)}updateTask(...$){return this.inner.updateTask(...$)}deleteTask(...$){return this.inner.deleteTask(...$)}listTasks(...$){return this.inner.listTasks(...$)}appendOperation(...$){return this.inner.appendOperation(...$)}listOperations(...$){return this.inner.listOperations(...$)}verifyChain(){return this.inner.verifyChain()}sendBounty(...$){return this.inner.sendBounty(...$)}claimBounty(...$){return this.inner.claimBounty(...$)}completeBounty(...$){return this.inner.completeBounty(...$)}listBounties(...$){return this.inner.listBounties(...$)}async close(){await this.inner.close()}}class X$ extends Error{status;body;constructor($,J,Q){super(J);this.status=$,this.body=Q}}class G1{baseUrl;headers;closedFlag=!1;constructor($){this.baseUrl=$.baseUrl.replace(/\/+$/,""),this.headers={"content-type":"application/json",...$.authToken?{authorization:`Bearer ${$.authToken}`}:{},...$.headers??{}}}async close(){this.closedFlag=!0}async request($,J,Q){if(this.closedFlag)throw Error("client closed");let W={...this.headers};if(Q?.idempotencyKey)W["idempotency-key"]=Q.idempotencyKey;let Y=await fetch(`${this.baseUrl}${J}`,{method:$,headers:W,body:Q?.body!==void 0?JSON.stringify(Q.body):void 0});if(Y.status===204)return null;let B=await Y.text(),H=null;try{H=B?JSON.parse(B):null}catch{H=B}if(!Y.ok)throw new X$(Y.status,`HTTP ${Y.status}`,H);return H}async createTask($,J){let Q=await this.request("POST","/tasks",{body:$,idempotencyKey:J});if(!Q)throw new X$(500,"empty response from POST /tasks");return Q}async getTask($){try{return await this.request("GET",`/tasks/${encodeURIComponent($)}`)}catch(J){if(J instanceof X$&&J.status===404)return null;throw J}}async updateTask($,J){try{return await this.request("PATCH",`/tasks/${encodeURIComponent($)}`,{body:J})}catch(Q){if(Q instanceof X$&&Q.status===404)return null;throw Q}}async deleteTask($){try{return await this.request("DELETE",`/tasks/${encodeURIComponent($)}`),!0}catch(J){if(J instanceof X$&&J.status===404)return!1;throw J}}async listTasks($={}){let J=new URLSearchParams;if($.status!==void 0){let W=Array.isArray($.status)?$.status.join(","):$.status;J.set("status",W)}if($.parent_id!==void 0&&$.parent_id!==null)J.set("parent_id",$.parent_id);if($.session_id!==void 0)J.set("session_id",$.session_id);if($.owner!==void 0)J.set("owner",$.owner);if($.tags!==void 0)J.set("tags",$.tags);if($.search!==void 0)J.set("search",$.search);J.set("limit",String($.limit??100)),J.set("offset",String($.offset??0));let Q=await this.request("GET",`/tasks?${J}`);if(!Q)throw new X$(500,"empty response");return Q}async appendOperation($){return await this.request("POST","/operations",{body:$})}async listOperations($={}){let J=new URLSearchParams;if($.task_id!==void 0)J.set("task_id",$.task_id);if($.type!==void 0)J.set("type",$.type);return J.set("limit",String($.limit??100)),J.set("offset",String($.offset??0)),await this.request("GET",`/operations?${J}`)}async verifyChain(){return(await this.request("GET","/verify"))?.valid===!0}async sendBounty($){let J=await this.request("POST","/bounties",{body:$});if(!J)throw new X$(500,"empty bounty response");return J}async claimBounty($){try{return await this.request("POST","/bounties/claim",{body:{agent:$}})}catch(J){if(J instanceof X$&&J.status===404)return null;throw J}}async completeBounty($,J){try{return await this.request("POST",`/bounties/${encodeURIComponent($)}/complete`,{body:{task_id:J}})}catch(Q){if(Q instanceof X$&&Q.status===404)return null;throw Q}}async listBounties($={}){let J=new URLSearchParams;if($.status!==void 0)J.set("status",$.status);if($.to!==void 0)J.set("to",$.to);return(await this.request("GET",`/bounties?${J}`))?.bounties??[]}}class e${inner;constructor($){this.inner=new G1($)}createTask(...$){return this.inner.createTask(...$)}getTask(...$){return this.inner.getTask(...$)}updateTask(...$){return this.inner.updateTask(...$)}deleteTask(...$){return this.inner.deleteTask(...$)}listTasks(...$){return this.inner.listTasks(...$)}appendOperation(...$){return this.inner.appendOperation(...$)}listOperations(...$){return this.inner.listOperations(...$)}verifyChain(){return this.inner.verifyChain()}sendBounty(...$){return this.inner.sendBounty(...$)}claimBounty(...$){return this.inner.claimBounty(...$)}completeBounty(...$){return this.inner.completeBounty(...$)}listBounties(...$){return this.inner.listBounties(...$)}async close(){await this.inner.close()}}async function k7($={}){let J=$.persistence??"local",Q;if(J==="remote"){if(!$.remoteUrl)throw Error("remoteUrl is required when persistence = 'remote' (e.g. http://localhost:7820)");Q=new e$({baseUrl:$.remoteUrl,authToken:$.remoteAuthToken})}else Q=await m$.create($.localDbPath);let W={store:Q,agent:$.agent??"opencode-default"};return{handlers:J0(W),store:Q,async close(){await Q.close()}}}var I8={id:"roy-task-plugin",async setup($){let J=$.options??{},Q=J.persistence??"local",W;if(Q==="remote"){if(!J.remoteUrl)throw Error("remoteUrl is required when persistence = 'remote' (e.g. http://localhost:7820)");W=new e$({baseUrl:J.remoteUrl,authToken:J.remoteAuthToken})}else W=await m$.create(J.localDbPath);let Y={store:W,agent:J.agent??"opencode-default"},B=J0(Y),H=await n2($,{store:W,enabled:J.royAgent!==!1,agent:"roy"}),X=await $.agent.transform(async(_)=>{let j=_.get("build");if(!j)return;let z=String(j.system??""),O=`
|
|
382
|
+
|
|
383
|
+
# Roy Task Plugin (auto-injected by roy-task-plugin v2)
|
|
384
|
+
|
|
385
|
+
When you start a non-trivial task (more than one tool call), create a tracked task via the \`task-create\` command:
|
|
386
|
+
|
|
387
|
+
task-create <title> [body]
|
|
388
|
+
|
|
389
|
+
The plugin persists each invocation to ${Q==="local"?"SQLite at ~/.roy-task-plugin/tasks.db":`remote service at ${J.remoteUrl}`}. Use \`task-list\` and \`task-status\` to retrieve.
|
|
390
|
+
|
|
391
|
+
Mark progress on long tasks via \`task-update <id> --status <status>\`.
|
|
392
|
+
|
|
393
|
+
For task-first-class-citizen work (task tree, milestones, deliverables), switch
|
|
394
|
+
to the dedicated **\`roy\`** primary agent \u2014 it carries the full roy task
|
|
395
|
+
lifecycle as native tools.
|
|
396
|
+
`;_.update("build",(P)=>{if(typeof P.system==="string"||P.system===void 0)P.system=z+O})}),q=await $.command.transform((_)=>{_.add({name:"task-create",description:"Create a tracked task in roy-task-plugin store. Persists to SQLite (~/.roy-task-plugin/tasks.db) or remote service. Args: <title> [body]",template:"task-create <title> [body]",execute:async(b)=>{let j=String(b?.prompt?.text??"").trim(),z=j.split(`
|
|
397
|
+
`)[0]?.trim()||`task-${Date.now()}`;await B.session({type:"session.created",payload:{id:b?.sessionID??`cmd-${Date.now()}`,title:z,body:j,source:"command:task-create"}})}}),_.add({name:"task-list",description:"List tracked tasks. Filters: [--status <s>] [--owner <o>]",template:"task-list [--status <status>] [--owner <owner>]",execute:async()=>{}}),_.add({name:"task-status",description:"Show full status of a single task. Args: <id>",template:"task-status <id>",execute:async()=>{}})});return{async dispose(){for(let _ of H.disposers)try{await _()}catch{}await X.dispose(),await q.dispose(),await W.close()}}}},h7=I8;export{h7 as default,k7 as createRoyTaskPlugin,J0 as createHandlers,e$ as RemoteTaskStore,m$ as LocalTaskStore};
|
|
398
|
+
|
|
399
|
+
//# debugId=F3B89209AA42520764756E2164756E21
|