@roll-agent/runtime 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{tool as e}from"ai";import{z as t}from"zod";import{gateToolCall as r}from"./build-tools.js";import{TOOL_OUTCOME_KINDS as n,failedToolResult as i,successfulToolResult as s,toolResultToModelOutput as o}from"./normalize-result.js";import{TOOL_RESOURCE_ACCESS_MODES as a,executeCoordinatedTool as c}from"./tool-execution-coordinator.js";export const SCHEDULE_TOOL_AGENT_NAME="roll";export const SCHEDULE_CREATE_TOOL_NAME="schedule_create";export const SCHEDULE_LIST_TOOL_NAME="schedule_list";export const SCHEDULE_CREATE_TOOL_ID="roll__schedule_create";export const SCHEDULE_LIST_TOOL_ID="roll__schedule_list";const l=t.object({name:t.string().trim().min(1).max(120).describe("任务名称(确认界面与任务列表中展示)"),prompt:t.string().trim().min(1).max(4e3).describe("每次触发时交给新一轮 chat 的任务描述,写清要做什么"),every:t.string().trim().min(1).describe("触发间隔,格式 <数字><s|m|h|d>,如 30m、2h、1d(最短 60s,最长 365d)"),cwd:t.string().optional().describe("任务运行的工作目录;省略时使用当前会话工作目录,相对路径相对会话目录解析"),maxRun:t.string().optional().describe("单次运行时长上限,格式同 every(60s..24h;省略时默认 1 小时)")}),u=t.object({status:t.enum(["all","active","paused"]).optional().describe("按状态过滤,省略时返回全部"),offset:t.number().int().min(0).optional().describe("分页偏移,默认 0"),limit:t.number().int().min(1).max(100).optional().describe("最多返回条数,默认 50")}),d=Symbol("schedule-invalid-input");function m(e){return"object"==typeof e&&null!==e&&e.kind===d}function p(e){return"object"==typeof e&&null!==e&&!1===e.ok}function g(e){const t="invalid_input"===e.code||"schedule_invalid"===e.code||"schedule_trigger_invalid"===e.code?n.invalidInput:n.toolFailed;return i(t,e.message,{raw:e})}function $(e){return 0===e.warnings.length?"":`\n${e.warnings.map(e=>`注意:${e.message}。`).join("\n")}`}function f(e){return{name:e.name,prompt:e.prompt,every:e.everyDisplay,cwd:e.cwd,maxRun:e.maxRunDisplay,firstRunAt:_(e.firstRunAt),lifecycle:"会持续运行,直到暂停或删除;创建时记录当前权限边界",...e.readiness.warnings.length>0?{serviceStatus:e.readiness.warnings.map(e=>e.message).join(";")}:{}}}function _(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}export function buildScheduleToolset(t,h,y){const v=t.includeCreate??!0?h.register("roll","schedule_create"):void 0,x=h.register("roll","schedule_list"),E={captureExecutionState:e=>{const r=l.safeParse(e);return r.success?t.port.captureCreate(r.data,t.sessionCwd):{kind:d,message:`参数校验失败: ${r.error.issues.map(e=>e.message).join("; ")}`}},prepare:async(e,t)=>{if(m(t))return i(n.invalidInput,t.message);if(p(t))return g(t);const s=t;return r(y,"roll","schedule_create",f(s),void 0,{explanation:`将登记定时任务「${s.name}」(${s.everyDisplay})`})},resources:()=>[{key:"schedule-ledger",mode:a.write}]};void 0!==v&&y.coordinator?.register(v,E);const b={prepare:async e=>r(y,"roll","schedule_list",e??{},{readOnlyHint:!0}),resources:()=>[{key:"schedule-ledger",mode:a.read}]};y.coordinator?.register(x,b);return{createTools:void 0===v?{}:{[v]:e({description:"登记一个按固定间隔重复运行的定时任务:到点后由 roll 调度器发起新一轮无人值守 chat 执行 prompt。创建前会向用户展示完整参数并请求确认,不要在调用前重复询问。仅支持固定间隔(every),不支持一次性时间点、cron 表达式或时区。",inputSchema:l,toModelOutput:({output:e})=>o(e),execute:async(e,r)=>c(y.coordinator,E,v,r.toolCallId,e,r.abortSignal,async e=>{if(m(e))return i(n.invalidInput,e.message);if(p(e))return g(e);const r=e,o=await t.port.create(r);if(p(o))return g(o);const a=o.schedule,c=o.created?`已登记定时任务 "${a.name}"(${a.trigger.display},单次上限 ${a.maxRun.display})。`:o.reauthorized?`已存在相同定义的任务 "${a.name}"(id ${a.id}),未重复创建;已按当前权限边界重新授权。`:`已存在相同定义的任务 "${a.name}"(id ${a.id}),未重复创建。`,l=void 0===a.nextRunAt?"":`下次运行约 ${_(a.nextRunAt)}。`,u
|
|
1
|
+
import{tool as e}from"ai";import{z as t}from"zod";import{gateToolCall as r}from"./build-tools.js";import{TOOL_OUTCOME_KINDS as n,failedToolResult as i,successfulToolResult as s,toolResultToModelOutput as o}from"./normalize-result.js";import{TOOL_RESOURCE_ACCESS_MODES as a,executeCoordinatedTool as c}from"./tool-execution-coordinator.js";export const SCHEDULE_TOOL_AGENT_NAME="roll";export const SCHEDULE_CREATE_TOOL_NAME="schedule_create";export const SCHEDULE_LIST_TOOL_NAME="schedule_list";export const SCHEDULE_CREATE_TOOL_ID="roll__schedule_create";export const SCHEDULE_LIST_TOOL_ID="roll__schedule_list";const l=t.object({name:t.string().trim().min(1).max(120).describe("任务名称(确认界面与任务列表中展示)"),prompt:t.string().trim().min(1).max(4e3).describe("每次触发时交给新一轮 chat 的任务描述,写清要做什么"),every:t.string().trim().min(1).describe("触发间隔,格式 <数字><s|m|h|d>,如 30m、2h、1d(最短 60s,最长 365d)"),cwd:t.string().optional().describe("任务运行的工作目录;省略时使用当前会话工作目录,相对路径相对会话目录解析"),maxRun:t.string().optional().describe("单次运行时长上限,格式同 every(60s..24h;省略时默认 1 小时)")}),u=t.object({status:t.enum(["all","active","paused"]).optional().describe("按状态过滤,省略时返回全部"),offset:t.number().int().min(0).optional().describe("分页偏移,默认 0"),limit:t.number().int().min(1).max(100).optional().describe("最多返回条数,默认 50")}),d=Symbol("schedule-invalid-input");function m(e){return"object"==typeof e&&null!==e&&e.kind===d}function p(e){return"object"==typeof e&&null!==e&&!1===e.ok}function g(e){const t="invalid_input"===e.code||"schedule_invalid"===e.code||"schedule_trigger_invalid"===e.code?n.invalidInput:n.toolFailed;return i(t,e.message,{raw:e})}function $(e){return 0===e.warnings.length?"":`\n${e.warnings.map(e=>`注意:${e.message}。`).join("\n")}`}function f(e){return{name:e.name,prompt:e.prompt,every:e.everyDisplay,cwd:e.cwd,maxRun:e.maxRunDisplay,firstRunAt:_(e.firstRunAt),lifecycle:"会持续运行,直到暂停或删除;创建时记录当前权限边界",...e.readiness.warnings.length>0?{serviceStatus:e.readiness.warnings.map(e=>e.message).join(";")}:{}}}function _(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}export function buildScheduleToolset(t,h,y){const v=t.includeCreate??!0?h.register("roll","schedule_create"):void 0,x=h.register("roll","schedule_list"),E={captureExecutionState:e=>{const r=l.safeParse(e);return r.success?t.port.captureCreate(r.data,t.sessionCwd):{kind:d,message:`参数校验失败: ${r.error.issues.map(e=>e.message).join("; ")}`}},prepare:async(e,t)=>{if(m(t))return i(n.invalidInput,t.message);if(p(t))return g(t);const s=t;return r(y,"roll","schedule_create",f(s),void 0,{explanation:`将登记定时任务「${s.name}」(${s.everyDisplay})`})},resources:()=>[{key:"schedule-ledger",mode:a.write}]};void 0!==v&&y.coordinator?.register(v,E);const b={prepare:async e=>r(y,"roll","schedule_list",e??{},{readOnlyHint:!0}),resources:()=>[{key:"schedule-ledger",mode:a.read}]};y.coordinator?.register(x,b);return{createTools:void 0===v?{}:{[v]:e({description:"登记一个按固定间隔重复运行的定时任务:到点后由 roll 调度器发起新一轮无人值守 chat 执行 prompt。创建前会向用户展示完整参数并请求确认,不要在调用前重复询问。仅支持固定间隔(every),不支持一次性时间点、cron 表达式或时区。",inputSchema:l,toModelOutput:({output:e})=>o(e),execute:async(e,r)=>c(y.coordinator,E,v,r.toolCallId,e,r.abortSignal,async e=>{if(m(e))return i(n.invalidInput,e.message);if(p(e))return g(e);const r=e,o=await t.port.create(r);if(p(o))return g(o);const a=o.schedule,c=o.created?`已登记定时任务 "${a.name}"(${a.trigger.display},单次上限 ${a.maxRun.display})。`:o.reauthorized?`已存在相同定义的任务 "${a.name}"(id ${a.id}),未重复创建;已按当前权限边界重新授权。`:`已存在相同定义的任务 "${a.name}"(id ${a.id}),未重复创建。`,l=void 0===a.nextRunAt?"":`下次运行约 ${_(a.nextRunAt)}。`,u=$(o.readiness)||(o.readiness.automaticRunsReady?"":"\n注意:调度服务未就绪,任务不会自动执行。");return s(`${c}${l}${u}`,{raw:o})})})},listTools:{[x]:e({description:"列出当前配置下已登记的定时任务(含状态、频率、下次运行时间与最近错误摘要)。创建前可用它确认是否已有同类任务。",inputSchema:u,toModelOutput:({output:e})=>o(e),execute:async(e,r)=>c(y.coordinator,b,x,r.toolCallId,e,r.abortSignal,async()=>{const r=u.safeParse(e??{});if(!r.success)return i(n.invalidInput,`参数校验失败: ${r.error.issues.map(e=>e.message).join("; ")}`);const o=await t.port.list(r.data,t.sessionCwd);if(p(o))return g(o);if(0===o.total)return s(`暂无定时任务。${$(o.readiness)}`.trim(),{raw:o});const a=o.schedules.map(e=>{const t="active"===e.status&&void 0!==e.nextRunAt?`,下次 ${_(e.nextRunAt)}`:"",r=void 0===e.lastError?"":`,最近错误:${e.lastError}`;return`- ${e.name}(${e.status},${e.trigger}${t})id=${e.id}\n 内容:${e.promptExcerpt}${r}`}),c=o.hasMore?`\n共 ${String(o.total)} 个,仅显示 ${String(o.schedules.length)} 个;用 offset/limit 翻页。`:"";return s(`${a.join("\n")}${c}${$(o.readiness)}`,{raw:o})})})}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roll-agent/runtime",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@ai-sdk/provider": "^4.0.7",
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
31
|
+
"@roll-agent/protocol": "0.6.1",
|
|
31
32
|
"@vscode/ripgrep": "1.18.0",
|
|
32
33
|
"ai": "^7.0.65",
|
|
33
34
|
"yaml": "2.8.3",
|
|
34
|
-
"zod": "^3.25.76"
|
|
35
|
-
"@roll-agent/protocol": "0.6.1"
|
|
35
|
+
"zod": "^3.25.76"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
38
|
+
"@roll-agent/core": "0.36.0",
|
|
39
|
+
"@types/node": "^22.0.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/obfuscate.mjs",
|