experimental-ash 0.22.2 → 0.23.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/CHANGELOG.md +14 -0
- package/dist/docs/public/faqs.md +67 -0
- package/dist/docs/public/meta.json +1 -0
- package/dist/docs/public/schedules.md +11 -0
- package/dist/docs/public/session-context.md +46 -89
- package/dist/docs/public/skills.md +13 -0
- package/dist/docs/public/subagents.md +12 -6
- package/dist/docs/public/tools.md +9 -13
- package/dist/docs/public/typescript-api.md +2 -2
- package/dist/src/chunks/{client-CKsU8Li3.js → client-nshDsWNF.js} +1 -1
- package/dist/src/chunks/{dev-authored-source-watcher-BLzYWh05.js → dev-authored-source-watcher-d_35Mp8T.js} +1 -1
- package/dist/src/chunks/{host-DREC8e8Z.js → host-tji7W0Nn.js} +2 -2
- package/dist/src/chunks/paths-YoCQlavu.js +89 -0
- package/dist/src/chunks/{prewarm-hz8p2jlZ.js → prewarm-6duWvvb5.js} +1 -1
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/dev/repl.js +2 -2
- package/dist/src/cli/run.js +1 -1
- package/dist/src/client/session.js +8 -0
- package/dist/src/client/types.d.ts +12 -1
- package/dist/src/compiled/.vendor-stamp.json +1 -1
- package/dist/src/compiled/@workflow/core/_ms.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/_workflow-serde.d.ts +5 -0
- package/dist/src/compiled/@workflow/core/_workflow-utils.d.ts +8 -0
- package/dist/src/compiled/@workflow/core/_workflow-world.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/capabilities.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/capture-stack.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/class-serialization.d.ts +31 -0
- package/dist/src/compiled/@workflow/core/classify-error.d.ts +19 -0
- package/dist/src/compiled/@workflow/core/context-errors.d.ts +27 -0
- package/dist/src/compiled/@workflow/core/context-violation-error.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/create-hook.d.ts +179 -0
- package/dist/src/compiled/@workflow/core/define-hook.d.ts +68 -0
- package/dist/src/compiled/@workflow/core/describe-error.d.ts +70 -0
- package/dist/src/compiled/@workflow/core/encryption.d.ts +45 -0
- package/dist/src/compiled/@workflow/core/events-consumer.d.ts +64 -0
- package/dist/src/compiled/@workflow/core/flushable-stream.d.ts +82 -0
- package/dist/src/compiled/@workflow/core/global.d.ts +48 -0
- package/dist/src/compiled/@workflow/core/index.d.ts +19 -38
- package/dist/src/compiled/@workflow/core/log-format.d.ts +25 -0
- package/dist/src/compiled/@workflow/core/logger.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/private.d.ts +59 -10
- package/dist/src/compiled/@workflow/core/runtime/constants.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/runtime/get-port-lazy.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/runtime/get-world-lazy.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime/helpers.d.ts +97 -0
- package/dist/src/compiled/@workflow/core/runtime/resume-hook.d.ts +77 -0
- package/dist/src/compiled/@workflow/core/runtime/run.d.ts +134 -0
- package/dist/src/compiled/@workflow/core/runtime/runs.d.ts +50 -0
- package/dist/src/compiled/@workflow/core/runtime/start.d.ts +59 -0
- package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/runtime/step-handler.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/runtime/suspension-handler.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/runtime/world-init.d.ts +75 -0
- package/dist/src/compiled/@workflow/core/runtime/world.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/runtime.d.ts +22 -67
- package/dist/src/compiled/@workflow/core/schemas.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/serialization/client.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/codec-devalue.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/serialization/codec.d.ts +90 -0
- package/dist/src/compiled/@workflow/core/serialization/encryption.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/serialization/errors.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/serialization/format.d.ts +60 -0
- package/dist/src/compiled/@workflow/core/serialization/index.d.ts +18 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/class.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/common.d.ts +16 -0
- package/dist/src/compiled/@workflow/core/serialization/reducers/step-function.d.ts +35 -0
- package/dist/src/compiled/@workflow/core/serialization/step.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/serialization/types.d.ts +201 -0
- package/dist/src/compiled/@workflow/core/serialization/workflow.d.ts +29 -0
- package/dist/src/compiled/@workflow/core/serialization-format.d.ts +171 -0
- package/dist/src/compiled/@workflow/core/serialization.d.ts +329 -0
- package/dist/src/compiled/@workflow/core/sleep.d.ts +33 -0
- package/dist/src/compiled/@workflow/core/source-map.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/step/context-storage.d.ts +13 -0
- package/dist/src/compiled/@workflow/core/step/get-closure-vars.d.ts +9 -0
- package/dist/src/compiled/@workflow/core/step/get-step-metadata.d.ts +42 -0
- package/dist/src/compiled/@workflow/core/step/get-workflow-metadata.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/step/writable-stream.d.ts +22 -0
- package/dist/src/compiled/@workflow/core/step.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/symbols.d.ts +20 -0
- package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +283 -0
- package/dist/src/compiled/@workflow/core/telemetry.d.ts +53 -0
- package/dist/src/compiled/@workflow/core/types.d.ts +14 -0
- package/dist/src/compiled/@workflow/core/util.d.ts +40 -0
- package/dist/src/compiled/@workflow/core/version.d.ts +2 -0
- package/dist/src/compiled/@workflow/core/vm/index.d.ts +17 -0
- package/dist/src/compiled/@workflow/core/vm/uint8array-base64.d.ts +21 -0
- package/dist/src/compiled/@workflow/core/vm/uuid.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/abort-controller.d.ts +65 -0
- package/dist/src/compiled/@workflow/core/workflow/create-hook.d.ts +7 -0
- package/dist/src/compiled/@workflow/core/workflow/define-hook.d.ts +10 -0
- package/dist/src/compiled/@workflow/core/workflow/get-workflow-metadata.d.ts +32 -0
- package/dist/src/compiled/@workflow/core/workflow/hook.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/index.d.ts +11 -0
- package/dist/src/compiled/@workflow/core/workflow/sleep.d.ts +4 -0
- package/dist/src/compiled/@workflow/core/workflow/world-init-stub.d.ts +15 -0
- package/dist/src/compiled/@workflow/core/workflow/writable-stream.d.ts +3 -0
- package/dist/src/compiled/@workflow/core/workflow.d.ts +1 -38
- package/dist/src/evals/cli/eval.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/protocol/message.d.ts +6 -1
- package/dist/src/public/channels/ash.js +50 -3
- package/dist/src/public/context/index.d.ts +4 -7
- package/dist/src/public/context/index.js +4 -5
- package/dist/src/public/definitions/state.d.ts +33 -0
- package/dist/src/public/definitions/state.js +34 -0
- package/dist/src/public/next/index.d.ts +7 -0
- package/dist/src/public/next/index.js +2 -0
- package/dist/src/public/next/vercel-json.d.ts +1 -0
- package/dist/src/public/next/vercel-json.js +1 -0
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/use-ash-agent.d.ts +8 -0
- package/dist/src/react/use-ash-agent.js +26 -4
- package/dist/src/services/dev-client.d.ts +4 -1
- package/dist/src/services/dev-client.js +1 -0
- package/package.json +1 -1
- package/dist/src/chunks/paths-C6sp4T2U.js +0 -88
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{E as e,S as t,T as n,_ as r,a as i,c as a,d as o,g as s,h as c,l,m as u,p as ee,s as te,u as d,x as f,y as p}from"./paths-
|
|
1
|
+
import{E as e,S as t,T as n,_ as r,a as i,c as a,d as o,g as s,h as c,l,m as u,p as ee,s as te,u as d,x as f,y as p}from"./paths-YoCQlavu.js";import{t as m}from"./authored-module-loader-XcFLnl49.js";import{t as h}from"./errors-DsO9xmQL.js";import{i as g,t as _}from"./package-DmsQgn4v.js";import{join as v,posix as y}from"node:path";import{mkdir as ne,readFile as re,readdir as ie,realpath as b,writeFile as x}from"node:fs/promises";import{createHash as S}from"node:crypto";import{existsSync as C}from"node:fs";function w(e){return e.dev?{appRoot:e.appRoot,dev:e.dev,moduleMapLoaderPath:g(`src/internal/authored-module-map-loader.ts`)}:{appRoot:e.appRoot,dev:e.dev}}const T=`#ash-channel/`;function E(e){let t=e.compileResult.manifest.channels,n=new Set,r=[],i=new Set,o=a();for(let e of t){if(e.kind===`disabled`){if(!o.has(e.name))throw Error(`agent/channels/${e.name}.ts exports disableRoute() but "${e.name}" is not a framework channel. Rename the file to one of: ${[...o].sort().join(`, `)}.`);i.add(e.name);continue}n.add(e.name),r.push({method:e.method,route:e.urlPath})}let s=l().filter(e=>!n.has(e.name)&&!i.has(e.name)).map(e=>({method:e.method,route:e.urlPath})),c=new Set,u=[];for(let e of[...s,...r]){let t=k(e);c.has(t)||(c.add(t),u.push(e))}return u}function D(e,t){for(let n of t.registrations)A(e,{artifactsConfig:t.artifactsConfig,method:n.method,route:n.route})}function O(e,t){return N(t.previous,t.next)?!1:(j(e),D(e,{artifactsConfig:t.artifactsConfig,registrations:t.next}),e.routing.sync(),!0)}function k(e){return`${e.method.toUpperCase()} ${e.route}`}function A(e,t){let r=k(t),i=`${T}${r}`,a=n(g(`src/internal/nitro/routes/channel-dispatch.ts`));e.options.handlers.push({handler:i,method:t.method,route:t.route}),e.options.virtual[i]=[`import { dispatchChannelRequest } from ${a};`,`const config = ${JSON.stringify(t.artifactsConfig)};`,`export default (event) => dispatchChannelRequest(event, ${JSON.stringify(r)}, config);`].join(`
|
|
2
2
|
`)}function j(e){for(let t=e.options.handlers.length-1;t>=0;--t){let n=e.options.handlers[t];n!==void 0&&M(n)&&e.options.handlers.splice(t,1)}for(let t of Object.keys(e.options.virtual))t.startsWith(T)&&delete e.options.virtual[t]}function M(e){return e.handler.startsWith(T)}function N(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r===void 0||i===void 0||r.method!==i.method||r.route!==i.route)return!1}return!0}const P=`ash.schedule.`;var F=class extends Error{scheduleId;sourceId;taskName;constructor(e,t={}){super(e),this.name=`ScheduleRegistrationError`,t.scheduleId!==void 0&&(this.scheduleId=t.scheduleId),t.sourceId!==void 0&&(this.sourceId=t.sourceId),t.taskName!==void 0&&(this.taskName=t.taskName)}};function I(e){let t=e.map(e=>({cron:e.cron,description:`Run Ash schedule "${e.name}" from "${e.logicalPath}".`,logicalPath:e.logicalPath,scheduleId:e.name,sourceId:e.sourceId,taskName:R(e.sourceId)})).sort((e,t)=>e.sourceId.localeCompare(t.sourceId));return L(t),t}function L(e){let t=new Map;for(let n of e){let e=t.get(n.scheduleId);if(e===void 0){t.set(n.scheduleId,n);continue}throw new F(`Duplicate authored schedule id "${n.scheduleId}" found in "${e.logicalPath}" and "${n.logicalPath}".`,{scheduleId:n.scheduleId,sourceId:n.sourceId,taskName:n.taskName})}}function R(e){return`${P}${Buffer.from(e,`utf8`).toString(`base64url`)}`}const z=`#ash-schedule-task/`;function B(e,t){if(t.registrations.length!==0){e.options.experimental.tasks=!0;for(let n of t.registrations)U(e,{artifactsConfig:t.artifactsConfig,dispatchModulePath:t.dispatchModulePath,registration:n})}}function V(e,t){let n=!G(t.previous,t.next);return H(e),B(e,{artifactsConfig:t.artifactsConfig,dispatchModulePath:t.dispatchModulePath,registrations:t.next}),n}function H(e){for(let t of Object.keys(e.options.tasks))t.startsWith(`ash.schedule.`)&&delete e.options.tasks[t];for(let t of Object.keys(e.options.virtual))t.startsWith(z)&&delete e.options.virtual[t];for(let[t,n]of Object.entries(e.options.scheduledTasks)){let r=W(n).filter(e=>!e.startsWith(P));if(r.length===0){delete e.options.scheduledTasks[t];continue}if(r.length===1){let[n]=r;n!==void 0&&(e.options.scheduledTasks[t]=n);continue}e.options.scheduledTasks[t]=r}}function U(e,t){let r=`${z}${t.registration.taskName}`,i=n(t.dispatchModulePath);e.options.tasks[t.registration.taskName]={description:t.registration.description,handler:r},e.options.virtual[r]=[`import { dispatchScheduleTask } from ${i};`,`const config = ${JSON.stringify(t.artifactsConfig)};`,`export default {`,` meta: { description: ${JSON.stringify(t.registration.description)} },`,` async run(event) {`,` return { result: await dispatchScheduleTask(event.name, config) };`,` },`,`};`].join(`
|
|
3
3
|
`),ae(e,t.registration.cron,t.registration.taskName)}function ae(e,t,n){let r=e.options.scheduledTasks[t];if(r===void 0){e.options.scheduledTasks[t]=n;return}if(typeof r==`string`){e.options.scheduledTasks[t]=[r,n];return}r.includes(n)||r.push(n)}function W(e){return typeof e==`string`?[e]:[...e]}function G(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r===void 0||i===void 0||r.cron!==i.cron||r.description!==i.description||r.logicalPath!==i.logicalPath||r.scheduleId!==i.scheduleId||r.sourceId!==i.sourceId||r.taskName!==i.taskName)return!1}return!0}async function K(e){return[...e.manifest.schedules].map(e=>{let t={cron:e.cron,hasRun:e.hasRun,logicalPath:e.logicalPath,name:e.name,sourceId:e.sourceId,sourceKind:e.sourceKind};return e.markdown===void 0?t:{...t,markdown:e.markdown}})}async function q(e){return await K({manifest:await o({compiledArtifactsSource:e.compiledArtifactsSource})})}async function J(e){let t=v(e.outDir,`compiled-artifacts-bootstrap.mjs`),n=v(e.outDir,`compiled-artifacts-instrumentation.mjs`),r=se(e.compileResult.manifest.agentRoot);await ne(e.outDir,{recursive:!0}),await x(t,await le({compileResult:e.compileResult,installModulePath:g(`src/runtime/loaders/bundled-artifacts.ts`),moduleMapPath:t,metadata:e.compileResult.metadata})),r!==void 0&&await x(n,ue({agentName:e.compileResult.manifest.config.name,instrumentationPath:r,registerConfigPath:g(`src/harness/instrumentation-config.ts`)}));let i={bootstrapPath:t};return r!==void 0&&(i.instrumentationPluginPath=n,i.instrumentationSourcePath=r),i}const oe=[`.ts`,`.mts`,`.js`,`.mjs`];function se(e){for(let t of oe){let n=v(e,`instrumentation${t}`);if(C(n))return n}}function ce(e){return e.replace(/^export const moduleMap = /m,`const moduleMap = `).replace(/\nexport default moduleMap;\n?$/,`
|
|
4
4
|
`)}async function le(e){let r=ce(t({importSpecifierStyle:`absolute`,manifest:e.compileResult.manifest,moduleMapPath:e.moduleMapPath})).trim();return[`// Generated by Ash. Do not edit by hand.`,`import { installBundledCompiledArtifacts } from ${n(e.installModulePath)};`,``,r,``,`const metadata = ${JSON.stringify(e.metadata,null,2)};`,``,`const manifest = ${JSON.stringify(e.compileResult.manifest,null,2)};`,``,`export function installCompiledArtifactsBootstrap() {`,` installBundledCompiledArtifacts({`,` manifest,`,` metadata,`,` moduleMap,`,` });`,`}`,``,`installCompiledArtifactsBootstrap();`,``,`// Default export satisfies the Nitro plugin contract so this file`,`// can be used directly as a Nitro plugin without a separate wrapper.`,`export default function installCompiledArtifactsPlugin() {`,` // Already installed on import above.`,`}`,``,`export async function __ashInstallCompiledArtifactsStep() {`,` "use step";`,` return null;`,`}`,``].join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{D as e,b as t,t as n,v as r,y as i}from"../../chunks/paths-
|
|
1
|
+
import{D as e,b as t,t as n,v as r,y as i}from"../../chunks/paths-YoCQlavu.js";import{d as a,f as o,h as s}from"../../chunks/types-MZUhN0Zy.js";import{createCliTheme as c,renderCliBanner as l,renderCliSection as u}from"../ui/output.js";async function d(e){let t=await f(e);return{application:n(t?.project.appRoot??e),compiledState:t,messaging:{createSessionRoutePath:o,continueSessionRoutePattern:a,streamRoutePattern:s}}}async function f(n){try{return await i({startPath:n})}catch(n){if(n instanceof r)return n.result;if(n instanceof e||n instanceof t)return null;throw n}}function p(e,t){return`${e} ${t}${e===1?``:`s`}`}function m(e,t){return`${`${e} error${e===1?``:`s`}`}, ${`${t} warning${t===1?``:`s`}`}`}function h(e){switch(e){case`ready`:return`success`;case`failed`:return`danger`;default:return`warning`}}async function g(e,t){let n=await d(t),r=n.compiledState,i=n.application,a=c(),o=[{label:`App Root`,value:i.appRoot}],s=[{label:`Workflow Build`,value:i.workflowBuildDir},{label:`Output`,value:i.outputDir}],f=[];r===null?o.push({label:`Compile`,tone:`warning`,value:`unavailable`}):(o.push({label:`Agent Root`,value:r.project.agentRoot},{label:`Layout`,value:r.project.layout},{label:`Compile`,tone:h(r.metadata.status),value:r.metadata.status},{label:`Diagnostics`,tone:r.metadata.discovery.summary.errors>0?`danger`:r.metadata.discovery.summary.warnings>0?`warning`:`success`,value:m(r.metadata.discovery.summary.errors,r.metadata.discovery.summary.warnings)},{label:`Instructions`,value:r.manifest.instructions?.logicalPath??`none`},{label:`Skills`,value:p(r.manifest.skills.length,`skill`)}),s.unshift({label:`Compiled Manifest`,value:r.paths.compiledManifestPath},{label:`Discovery Manifest`,value:r.paths.discoveryManifestPath},{label:`Diagnostics`,value:r.paths.diagnosticsPath},{label:`Module Map`,value:r.paths.moduleMapPath},{label:`Metadata`,value:r.paths.compileMetadataPath}),f.push(r.manifest.instructions===void 0?{label:`Instructions`,value:`No instructions prompt discovered.`}:{label:`Instructions`,value:r.manifest.instructions.logicalPath})),e.log([l(a,{subtitle:`Resolved application paths and the active message contract.`,title:`Ash Info`}),``,u(a,{rows:o,title:`Application`}),``,u(a,{rows:s,title:`Artifacts`}),...r===null?[]:[``,u(a,{rows:f,title:`Instructions`})],``,u(a,{rows:[{label:`Workflow ID`,value:i.workflowId},{label:`Source Dir`,value:i.workflowSourceDir},{label:`Create`,tone:`info`,value:`POST ${n.messaging.createSessionRoutePath}`},{label:`Continue`,tone:`info`,value:`POST ${n.messaging.continueSessionRoutePattern}`},{label:`Stream`,tone:`info`,value:`GET ${n.messaging.streamRoutePattern}`}],title:`Messaging`})].join(`
|
|
2
2
|
`))}export{g as printApplicationInfo};
|
package/dist/src/cli/dev/repl.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"../../chunks/errors-DsO9xmQL.js";import{c as t,d as n,f as r,h as i,l as a}from"../../chunks/types-MZUhN0Zy.js";import{createCliTheme as o,renderCliBanner as s,renderCliSection as c,renderCliSpeakerLine as l,renderCliTaggedLine as u}from"../ui/output.js";import{n as d,r as f,t as p}from"../../chunks/input-requests-BsBi7_5K.js";import{parseDevReplInput as m}from"./input.js";import{a as h,i as g,n as _,o as v,r as y,s as b,t as x}from"../../chunks/client-
|
|
2
|
-
`)}var A=h();async function j(){try{let e=(await(0,A.getVercelOidcToken)()).trim();if(e.length>0)return e}catch{}return process.env.VERCEL_OIDC_TOKEN?.trim()||``}const M=new Set([`localhost`,`127.0.0.1`,`0.0.0.0`,`::1`,`[::1]`]);function N(e){try{return M.has(new URL(e).hostname)}catch{return!1}}async function P(e){let t={},n=process.env.VERCEL_AUTOMATION_BYPASS_SECRET?.trim();if(n&&(t[_]=n),!e.isLocal){let e=await j();e.length>0&&(t[y]=e)}return t}var F=class{#e;#t;constructor(e){let t=N(e.serverUrl);this.#e=new x({headers:()=>P({isLocal:t}),host:e.serverUrl,...t?{}:{auth:{bearer:j}}}),this.#t=this.#e.session()}async clear(){this.#t=this.#e.session()}async close(){}getSession(){return this.#t.state}async sendMessage(e){return await this.send({message:e.message,onEvent:e.onEvent,onResponseStart:e.onResponseStart})}async send(e){let t=await this.#t.send({inputResponses:e.inputResponses,message:e.message});e.onResponseStart?.({sessionId:t.sessionId});let n=[];for await(let r of t)n.push(r),e.onEvent?.(r);return{events:n,sessionId:t.sessionId,session:this.#t.state}}};function I(e){return new F(e)}function L(e){let t=[{label:`Server`,tone:`info`,value:e.serverUrl},{label:`Create`,tone:`info`,value:`POST ${r}`},{label:`Continue`,tone:`info`,value:`POST ${n}`},{label:`Stream`,tone:`info`,value:`GET ${i}`}];return t.push({label:`Session`,value:`Follow-up messages reuse the active continuation token.`}),t}function R(){return[{label:`/help`,value:`Print the connection contract and available commands.`},{label:`/new`,value:`Clear the current durable session cursor.`},{label:`/exit`,value:`Exit the REPL.`}]}function z(e,t){return[s(e,{subtitle:`Interactive development REPL for the active Ash server.`,title:`Ash Dev`}),``,c(e,{rows:L(t),title:`Connection`}),``,c(e,{rows:R(),title:`Commands`})].join(`
|
|
1
|
+
import{t as e}from"../../chunks/errors-DsO9xmQL.js";import{c as t,d as n,f as r,h as i,l as a}from"../../chunks/types-MZUhN0Zy.js";import{createCliTheme as o,renderCliBanner as s,renderCliSection as c,renderCliSpeakerLine as l,renderCliTaggedLine as u}from"../ui/output.js";import{n as d,r as f,t as p}from"../../chunks/input-requests-BsBi7_5K.js";import{parseDevReplInput as m}from"./input.js";import{a as h,i as g,n as _,o as v,r as y,s as b,t as x}from"../../chunks/client-nshDsWNF.js";import{createDevelopmentTerminal as S}from"./terminal.js";import{createInterface as C,emitKeypressEvents as ee}from"node:readline";function te(e){return[...e].reverse().find(a)}function ne(e){let t=new URL(e);return t.hash=``,t.search=``,t.pathname.endsWith(`/`)||(t.pathname=`${t.pathname}/`),t}function w(e){return new URL(e.routePath.replace(/^\/+/,``),ne(e.serverUrl))}function T(e){let t=e.resource.trim();try{return new URL(t)}catch{return w({routePath:t,serverUrl:e.serverUrl})}}const E=[`vercel.com/sso-api`,`<title>Authentication Required</title>`,`Vercel Authentication`];function D(e){if(e.length===0)return!1;for(let t of E)if(e.includes(t))return!0;return!1}function O(e){return e instanceof b||typeof e==`object`&&e&&`body`in e&&typeof e.body==`string`?D(e.body):!1}function k(e){return[`Vercel Deployment Protection blocked the request to ${e.serverUrl}.`,``,"To access the deployment from `ash dev`, do one of:"," • Run `vercel link` in this project so the CLI can mint an OIDC",` token for the deployment automatically.`,` • Set VERCEL_AUTOMATION_BYPASS_SECRET to a Protection Bypass for`,` Automation token (Project Settings → Deployment Protection).`,` • Disable Deployment Protection on the target deployment.`,``,`Docs: https://vercel.com/docs/deployment-protection`].join(`
|
|
2
|
+
`)}var A=h();async function j(){try{let e=(await(0,A.getVercelOidcToken)()).trim();if(e.length>0)return e}catch{}return process.env.VERCEL_OIDC_TOKEN?.trim()||``}const M=new Set([`localhost`,`127.0.0.1`,`0.0.0.0`,`::1`,`[::1]`]);function N(e){try{return M.has(new URL(e).hostname)}catch{return!1}}async function P(e){let t={},n=process.env.VERCEL_AUTOMATION_BYPASS_SECRET?.trim();if(n&&(t[_]=n),!e.isLocal){let e=await j();e.length>0&&(t[y]=e)}return t}var F=class{#e;#t;constructor(e){let t=N(e.serverUrl);this.#e=new x({headers:()=>P({isLocal:t}),host:e.serverUrl,...t?{}:{auth:{bearer:j}}}),this.#t=this.#e.session()}async clear(){this.#t=this.#e.session()}async close(){}getSession(){return this.#t.state}async sendMessage(e){return await this.send({message:e.message,onEvent:e.onEvent,onResponseStart:e.onResponseStart})}async send(e){let t=await this.#t.send({clientContext:e.clientContext,inputResponses:e.inputResponses,message:e.message});e.onResponseStart?.({sessionId:t.sessionId});let n=[];for await(let r of t)n.push(r),e.onEvent?.(r);return{events:n,sessionId:t.sessionId,session:this.#t.state}}};function I(e){return new F(e)}function L(e){let t=[{label:`Server`,tone:`info`,value:e.serverUrl},{label:`Create`,tone:`info`,value:`POST ${r}`},{label:`Continue`,tone:`info`,value:`POST ${n}`},{label:`Stream`,tone:`info`,value:`GET ${i}`}];return t.push({label:`Session`,value:`Follow-up messages reuse the active continuation token.`}),t}function R(){return[{label:`/help`,value:`Print the connection contract and available commands.`},{label:`/new`,value:`Clear the current durable session cursor.`},{label:`/exit`,value:`Exit the REPL.`}]}function z(e,t){return[s(e,{subtitle:`Interactive development REPL for the active Ash server.`,title:`Ash Dev`}),``,c(e,{rows:L(t),title:`Connection`}),``,c(e,{rows:R(),title:`Commands`})].join(`
|
|
3
3
|
`)}function re(e){let t=e.trim();return t.length>0?t:null}function B(e){return e.options?.sourceKind===`subagent`?`subagent`:e.fallback}function V(e){return e.options?.sourceKind===`subagent`?`subagent`:e.fallback}function H(e){return e.options?.sourceLabel===void 0?e.message:`${e.options.sourceLabel}${e.separator??` `}${e.message}`}function U(e,t,n){switch(t.type){case`message.appended`:return{finalized:!1,kind:`message`,line:l(e,{message:t.data.messageSoFar,speaker:n?.sourceLabel??`agent`,tone:V({fallback:`accent`,options:n})})};case`message.completed`:if(t.data.message===null)return;if(t.data.finishReason===`tool-calls`){let r=re(t.data.message);return r===null?void 0:{finalized:!0,kind:`message`,line:u(e,{message:H({message:r,options:n,separator:`: `}),tag:B({fallback:`step`,options:n}),tone:V({fallback:`accent`,options:n})})}}return{finalized:!0,kind:`message`,line:l(e,{message:t.data.message,speaker:n?.sourceLabel??`agent`,tone:V({fallback:`accent`,options:n})})};case`reasoning.appended`:return{finalized:!1,kind:`reasoning`,line:u(e,{message:H({message:t.data.reasoningSoFar,options:n,separator:`: `}),tag:B({fallback:`reasoning`,options:n}),tone:V({fallback:`info`,options:n})})};case`reasoning.completed`:return{finalized:!0,kind:`reasoning`,line:u(e,{message:H({message:t.data.reasoning,options:n,separator:`: `}),tag:B({fallback:`reasoning`,options:n}),tone:V({fallback:`info`,options:n})})};default:return}}function W(e,t,n){let r=U(e,t,n);if(r!==void 0)return r.line;switch(t.type){case`message.received`:return;case`actions.requested`:return u(e,{message:H({message:`${t.type} (${t.data.actions.length} action${t.data.actions.length===1?``:`s`})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`muted`,options:n})});case`input.requested`:return u(e,{message:H({message:`${t.type} (${t.data.requests.length} request${t.data.requests.length===1?``:`s`})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`info`,options:n})});case`action.result`:return u(e,{message:H({message:`${t.type} (${Z(t.data.result)})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`muted`,options:n})});case`session.waiting`:case`session.completed`:return;case`connection.authorization_required`:return u(e,{message:H({message:`${t.type} (${t.data.connectionName}: ${t.data.description}${ae(t.data.authorization)})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`warning`,options:n})});case`compaction.requested`:return u(e,{message:H({message:`compacting conversation history`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`muted`,options:n})});case`compaction.completed`:return u(e,{message:H({message:`conversation history compacted`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`muted`,options:n})});case`step.failed`:case`turn.failed`:case`session.failed`:return;case`subagent.called`:return u(e,{message:H({message:`${t.type} (${t.data.name} -> ${t.data.childSessionId})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`info`,options:n})});case`subagent.started`:return u(e,{message:H({message:`${t.type} (${t.data.subagentName})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`info`,options:n})});case`subagent.event`:return u(e,{message:H({message:`${t.type} (${t.data.subagentName}: ${oe(t.data.event)})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`muted`,options:n})});case`subagent.completed`:return u(e,{message:H({message:`${t.type} (${t.data.subagentName})`,options:n}),tag:B({fallback:`event`,options:n}),tone:V({fallback:`info`,options:n})});default:return}}function G(e){switch(e.type){case`message.appended`:case`message.completed`:case`reasoning.appended`:case`reasoning.completed`:return`content`;default:return`meta`}}function K(){return{activeLiveContentKind:null,lastPrintedBlockKind:null}}function q(e){let t=e.state;return t.activeLiveContentKind!==null&&(e.terminal.commitLive(),t={activeLiveContentKind:null,lastPrintedBlockKind:`content`}),t.lastPrintedBlockKind!==null&&t.lastPrintedBlockKind!==e.kind&&e.terminal.print(``),e.terminal.print(e.line),{activeLiveContentKind:null,lastPrintedBlockKind:e.kind}}function J(e){let t=U(e.theme,e.event,e.options);if(t!==void 0){let n=e.state;return n.activeLiveContentKind!==null&&n.activeLiveContentKind!==t.kind&&(e.terminal.commitLive(),n={activeLiveContentKind:null,lastPrintedBlockKind:`content`}),n.lastPrintedBlockKind!==null&&n.lastPrintedBlockKind!==`content`&&e.terminal.print(``),e.terminal.updateLive(t.line),t.finalized?(e.terminal.commitLive(),{activeLiveContentKind:null,lastPrintedBlockKind:`content`}):{activeLiveContentKind:t.kind,lastPrintedBlockKind:`content`}}let n=W(e.theme,e.event,e.options);return n===void 0?e.state:q({kind:G(e.event),line:n,state:e.state,terminal:e.terminal})}function Y(e){return(e instanceof DOMException||e instanceof Error)&&e.name===`AbortError`}function X(e){return e.length===0}var ie=class{#e=new Map;#t;#n;#r;#i;constructor(e){this.#t=e.displayStateRef,this.#n=e.serverUrl,this.#r=e.terminal,this.#i=e.theme}subscribe(e){if(this.#e.has(e.sessionId))return;let t=new AbortController,n=this.#a({controller:t,sessionId:e.sessionId,subagentName:e.subagentName}).finally(()=>{this.#e.delete(e.sessionId)});this.#e.set(e.sessionId,{controller:t,done:n,label:e.subagentName})}async waitForIdle(){for(;this.#e.size>0;)await Promise.all([...this.#e.values()].map(e=>e.done))}async close(){let e=[...this.#e.values()];for(let t of e)t.controller.abort();await Promise.allSettled(e.map(e=>e.done))}async#a(n){let r=T({resource:t(n.sessionId),serverUrl:this.#n});try{for await(let e of v({host:this.#n,maxReconnectAttempts:3,resolveHeaders:async()=>await g({resourceUrl:r}),sessionId:n.sessionId,signal:n.controller.signal,startIndex:0}))if(this.#t.current=J({event:e,options:{sourceKind:`subagent`,sourceLabel:n.subagentName},state:this.#t.current,terminal:this.#r,theme:this.#i}),e.type===`subagent.called`&&this.subscribe({sessionId:e.data.childSessionId,subagentName:e.data.name}),a(e))return}catch(t){if(Y(t))return;let r=e(t);this.#t.current=q({kind:`meta`,line:u(this.#i,{message:`${n.subagentName} stream failed: ${r}`,tag:`subagent`,tone:`danger`}),state:this.#t.current,terminal:this.#r})}finally{n.controller.abort()}}};function Z(e){switch(e.kind){case`load-skill-result`:return e.kind;case`subagent-result`:return`${e.kind}:${e.subagentName}`;case`tool-result`:return`${e.kind}:${e.toolName}`}}function ae(e){if(e===void 0)return``;let t=[];return e.url!==void 0&&t.push(e.url),e.userCode!==void 0&&t.push(`code ${e.userCode}`),e.instructions!==void 0&&t.push(e.instructions),t.length===0?``:` — ${t.join(`, `)}`}function oe(e){switch(e.type){case`actions.requested`:{let t=e.data.actions,n=t.map(e=>e.kind===`tool-call`?e.toolName:e.kind).join(`,`);return`${e.type} (${t.length} action${t.length===1?``:`s`}${n.length>0?`: ${n}`:``})`}case`action.result`:return`${e.type} (${Z(e.data.result)})`;case`input.requested`:return`${e.type} (${e.data.requests.length} request${e.data.requests.length===1?``:`s`})`;default:return e.type}}function se(e,t){return t.continuationToken?u(e,{message:`resuming session ${t.continuationToken}`,tag:`session`,tone:`info`}):u(e,{message:`starting a new session`,tag:`session`,tone:`info`})}function ce(e,t){return t.turn.inputResponses!==void 0&&t.turn.message===void 0?u(e,{message:`responding to pending input request${t.turn.inputResponses.length===1?``:`s`}`,tag:`session`,tone:`info`}):se(e,t.session)}function le(e,t){let n=te(t),r=d(t);switch(n?.type){case`session.waiting`:return[u(e,{message:r.length>0?`waiting for input approval/answer or the next message`:`waiting for the next message`,tag:`session`,tone:`success`})];case`session.completed`:return[u(e,{message:`session completed; the next input starts a new session`,tag:`session`,tone:`success`})];case`session.failed`:{let t=n.data.details&&typeof n.data.details.name==`string`?n.data.details.name:void 0;return[u(e,{message:t?`session failed (${t}): ${n.data.message}`:`session failed: ${n.data.message}`,tag:`session`,tone:`danger`}),u(e,{message:`cleared; the next input starts a new session`,tag:`session`,tone:`warning`})]}default:return[]}}async function Q(e,t,n={}){return await new Promise(r=>{let i=e.input,a=()=>{e.off(`close`,o),e.off(`line`,s),i.off(`keypress`,c)},o=()=>{a(),r(void 0)},s=e=>{a(),r(e)},c=(t,i)=>{n.allowEscape!==!0||i.name!==`escape`||(a(),e.write(null,{ctrl:!0,name:`u`}),r(p))};e.setPrompt(t),e.once(`close`,o),e.once(`line`,s),n.allowEscape&&(ee(i,e),i.on(`keypress`,c)),e.prompt()})}async function $(e){let n=e.turn,r={current:K()},i=new ie({displayStateRef:r,serverUrl:e.serverUrl,terminal:e.terminal,theme:e.theme}),a=async t=>{e.terminal.startPrompt(e.rl,t);let n=await Q(e.rl,t,{allowEscape:!0});return e.terminal.stopPrompt(),n};try{for(;;){let o=e.client.getSession();r.current=q({kind:`meta`,line:ce(e.theme,{session:o,turn:n}),state:r.current,terminal:e.terminal});let s=await e.client.send({inputResponses:n.inputResponses,message:n.message,onEvent(t){r.current=J({event:t,state:r.current,terminal:e.terminal,theme:e.theme}),t.type===`subagent.called`&&i.subscribe({sessionId:t.data.childSessionId,subagentName:t.data.name})},onResponseStart(n){n.sessionId&&o.sessionId!==n.sessionId&&(r.current=q({kind:`meta`,line:u(e.theme,{message:n.sessionId,tag:`session`,tone:`accent`}),state:r.current,terminal:e.terminal}),r.current=q({kind:`meta`,line:u(e.theme,{message:T({resource:t(n.sessionId),serverUrl:e.serverUrl}).toString(),tag:`stream`,tone:`info`}),state:r.current,terminal:e.terminal}))}}),c=d(s.events);if(X(c)){await i.waitForIdle();for(let t of le(e.theme,s.events))r.current=q({kind:`meta`,line:t,state:r.current,terminal:e.terminal});return`continue`}let l=await f({ask:a,print(t){r.current=q({kind:`meta`,line:t,state:r.current,terminal:e.terminal})},requests:c,theme:e.theme});if(l.kind===`aborted`)return`exit`;if(l.kind===`deferred`)return r.current=q({kind:`meta`,line:u(e.theme,{message:`left pending input requests unresolved; send a new message to ignore them`,tag:`session`,tone:`warning`}),state:r.current,terminal:e.terminal}),`continue`;n={inputResponses:l.inputResponses}}}finally{await i.close()}}async function ue(t){let n=S(),r=o({color:!0}),i=C({input:process.stdin,output:n.output,terminal:!0});i.on(`SIGINT`,()=>{i.close()});let a=I({serverUrl:t.serverUrl});try{for(n.print(z(r,t)),n.print(``);;){n.print(``),n.startPrompt(i,`you> `);let o=await Q(i,`you> `);if(n.stopPrompt(),o===void 0)return;let s=m(o);switch(s.kind!==`empty`&&s.kind!==`exit`&&n.print(``),s.kind){case`empty`:continue;case`help`:n.print(z(r,t)),n.print(``);continue;case`exit`:return;case`new`:await a.clear(),n.print(u(r,{message:`cleared; the next input starts a new session`,tag:`session`,tone:`warning`})),n.print(``);continue;case`message`:try{if(await $({client:a,rl:i,serverUrl:t.serverUrl,terminal:n,theme:r,turn:{message:s.message}})===`exit`)return}catch(i){O(i)?n.printError(u(r,{message:k({serverUrl:t.serverUrl}),tag:`auth`,tone:`warning`})):n.printError(u(r,{message:e(i),tag:`error`,tone:`danger`}))}n.print(``)}}}finally{await a.close(),i.close(),n.dispose()}}export{K as createTurnDisplayState,U as formatContentEvent,W as formatEvent,J as renderTurnEvent,ue as runDevelopmentRepl,X as shouldDrainSubagentStreamsOnBoundary};
|
package/dist/src/cli/run.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"../chunks/package-DmsQgn4v.js";import{createCliTheme as t,renderCliTaggedLine as n}from"./ui/output.js";import{i as r,n as i,r as a,t as o}from"../chunks/url-BVRhVE2O.js";import{resolve as s}from"node:path";async function c(){return(await import(`../chunks/host-
|
|
1
|
+
import{t as e}from"../chunks/package-DmsQgn4v.js";import{createCliTheme as t,renderCliTaggedLine as n}from"./ui/output.js";import{i as r,n as i,r as a,t as o}from"../chunks/url-BVRhVE2O.js";import{resolve as s}from"node:path";async function c(){return(await import(`../chunks/host-tji7W0Nn.js`).then(e=>e.t)).buildHost}async function l(){return(await import(`./commands/info.js`)).printApplicationInfo}async function u(){return(await import(`./dev/repl.js`)).runDevelopmentRepl}async function d(){return(await import(`../evals/cli/eval.js`)).runEvalCommand}async function f(){return(await import(`../chunks/host-tji7W0Nn.js`).then(e=>e.t)).startHost}function p(e=process.cwd()){return s(e)}function m(e){return`Ash (v${e})`}function h(e){return e.name()===`info`||e.name()===`dev`}async function g(e){await new Promise((t,n)=>{let r=!1,i=()=>{process.off(`SIGINT`,a),process.off(`SIGTERM`,a)},a=()=>{r||(r=!0,i(),e.close().then(t,n))};process.once(`SIGINT`,a),process.once(`SIGTERM`,a)})}function _(e){if(!/^-?\d+$/.test(e))throw new r(`Expected a numeric port, received "${e}".`);let t=Number(e);if(!Number.isInteger(t))throw new r(`Expected a numeric port, received "${e}".`);if(t<0||t>65535)throw new r(`Expected a port between 0 and 65535, received "${e}".`);return t}function v(){return!!(process.stdin.isTTY&&process.stdout.isTTY)}function y(e){let t=e[1];return e[0]!==`dev`||e.length!==2||t===void 0||t.startsWith(`-`)?[...e]:[`dev`,`--url`,t]}function b(e){if(e.url){if(e.host!==void 0)throw new r(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new r(`The --port option cannot be used with --url.`);if(e.repl===!1)throw new r(`The --no-repl option cannot be used with --url.`);return e.url}}function x(r,a){let s=p(),y=e().version,x=new i,S=t();return x.name(`ash`).description(`Build and run an Ash application.`).version(y).showHelpAfterError().exitOverride().hook(`preAction`,(e,t)=>{h(t)&&r.log(m(y))}).configureOutput({writeErr:e=>{r.error(e.trimEnd())},writeOut:e=>{r.log(e.trimEnd())}}),x.command(`build`).description(`Build the current Ash application.`).action(async()=>{let{loadDevelopmentEnvironmentFiles:e}=await import(`./dev/environment.js`);e(s);let t=await(a.buildHost??await c())(s);r.log(n(S,{message:`built output at ${t}`,tag:`build`,tone:`success`}))}),x.command(`dev`).description(`Start the Ash development server or connect the REPL to an existing URL.`).option(`--host <host>`,`Host interface to bind`).option(`--no-repl`,`Start the server without the interactive REPL`).option(`--port <port>`,`Port to listen on (defaults to $PORT, then 3000)`,_).option(`--schedules`,`Run scheduled tasks during development (off by default)`).option(`-u, --url <url>`,`Connect the REPL to an existing server URL`,o).addHelpText(`after`,`
|
|
2
2
|
You can also pass a bare URL as the only argument, for example: ash dev https://example.com
|
|
3
3
|
`).action(async e=>{let t=b(e),{loadDevelopmentEnvironmentFiles:i}=await import(`./dev/environment.js`);if(i(s),t){if(r.log(n(S,{message:`REPL connecting to ${t}`,tag:`dev`,tone:`info`})),!v()){r.log(n(S,{message:`Interactive REPL disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`}));return}r.log(``),await(a.runDevelopmentRepl??await u())({serverUrl:t});return}let o=await(a.startHost??await f())(s,{host:e.host,port:e.port,schedules:e.schedules===!0}),c=!1,l=async()=>{c||(c=!0,await o.close())};try{if(r.log(n(S,{message:`server listening at ${o.url}`,tag:`dev`,tone:`success`})),e.repl===!1)return await g({close:l});if(!v())return r.log(n(S,{message:`Interactive REPL disabled because the current terminal is not a TTY.`,tag:`dev`,tone:`warning`})),await g({close:l});r.log(``),await(a.runDevelopmentRepl??await u())({serverUrl:o.url})}finally{await l()}}),x.command(`info`).description(`Print resolved application information.`).action(async()=>{await(a.printApplicationInfo??await l())(r,s)}),x.command(`eval`).description(`Run eval suites against an Ash agent.`).option(`--suite <id...>`,`Suite IDs to run (repeatable)`).option(`--all`,`Run all discovered suites`).option(`--url <url>`,`Remote agent URL (skip local host startup)`).option(`--timeout <ms>`,`Per-case timeout in milliseconds`).option(`--max-concurrency <n>`,`Max concurrent case executions per suite`).option(`--json`,`Output results as JSON`).option(`--list-suites`,`List discovered suites and exit`).option(`--skip-report`,`Skip suite-defined reporters (e.g. Braintrust)`).action(async e=>{await(a.runEvalCommand??await d())(e,r)}),x}async function S(e=process.argv.slice(2),t=console,n={}){let r=x(t,n),i=e.length===0?[`info`]:y(e);try{await r.parseAsync(i,{from:`user`})}catch(e){if(e instanceof a){if(e.exitCode===0)return;throw Error(e.message)}throw e}}export{S as runCli};
|
|
@@ -185,6 +185,9 @@ function createHandleMessageBody(input) {
|
|
|
185
185
|
if (input.input.inputResponses !== undefined && input.input.inputResponses.length > 0) {
|
|
186
186
|
body.inputResponses = input.input.inputResponses;
|
|
187
187
|
}
|
|
188
|
+
if (input.input.clientContext !== undefined) {
|
|
189
|
+
body.clientContext = input.input.clientContext;
|
|
190
|
+
}
|
|
188
191
|
if (input.session.continuationToken !== undefined) {
|
|
189
192
|
body.continuationToken = input.session.continuationToken;
|
|
190
193
|
}
|
|
@@ -194,6 +197,11 @@ function createHandleMessageBody(input) {
|
|
|
194
197
|
if (input.session.continuationToken === undefined && body.message === undefined) {
|
|
195
198
|
return null;
|
|
196
199
|
}
|
|
200
|
+
if (input.session.continuationToken !== undefined &&
|
|
201
|
+
body.message === undefined &&
|
|
202
|
+
body.inputResponses === undefined) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
197
205
|
if ("continuationToken" in body && Object.keys(body).length === 1) {
|
|
198
206
|
return null;
|
|
199
207
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { UserContent } from "ai";
|
|
1
2
|
import type { HandleMessageStreamEvent } from "#protocol/message.js";
|
|
2
3
|
import type { InputResponse } from "#runtime/input/types.js";
|
|
4
|
+
import type { JsonObject } from "#shared/json.js";
|
|
3
5
|
/**
|
|
4
6
|
* Static credential value or per-request credential resolver.
|
|
5
7
|
*/
|
|
@@ -66,6 +68,15 @@ export interface SendMessageOptions {
|
|
|
66
68
|
* Input payload for {@link Session.send}.
|
|
67
69
|
*/
|
|
68
70
|
export interface SendTurnInput {
|
|
71
|
+
/**
|
|
72
|
+
* Ephemeral client/page context for the next model call only.
|
|
73
|
+
*
|
|
74
|
+
* Strings are rendered as user-role model context messages. Objects are
|
|
75
|
+
* JSON-serialized into one user-role model context message. Client context
|
|
76
|
+
* piggybacks on a message or HITL response; it does not dispatch a turn by
|
|
77
|
+
* itself and is never persisted to durable session history.
|
|
78
|
+
*/
|
|
79
|
+
readonly clientContext?: string | readonly string[] | JsonObject;
|
|
69
80
|
/**
|
|
70
81
|
* HITL responses resolving pending approvals or questions.
|
|
71
82
|
*/
|
|
@@ -73,7 +84,7 @@ export interface SendTurnInput {
|
|
|
73
84
|
/**
|
|
74
85
|
* Optional follow-up user message for the same turn.
|
|
75
86
|
*/
|
|
76
|
-
readonly message?: string;
|
|
87
|
+
readonly message?: string | UserContent;
|
|
77
88
|
}
|
|
78
89
|
/**
|
|
79
90
|
* Options for {@link ClientSession.openStream}.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Auto-generated stub for `@workflow/utils` types referenced by a vendored .d.ts.
|
|
2
|
+
// Emitted by scripts/vendor-compiled/@workflow/core.mjs.
|
|
3
|
+
|
|
4
|
+
export interface PromiseWithResolvers<T = unknown> {
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
resolve(value: T | PromiseLike<T>): void;
|
|
7
|
+
reject(reason?: unknown): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Auto-generated stub for `@workflow/world` types referenced by a vendored .d.ts.
|
|
2
|
+
// Emitted by scripts/vendor-compiled/@workflow/core.mjs.
|
|
3
|
+
|
|
4
|
+
type JsonishRecord = Record<string, any>;
|
|
5
|
+
type PaginatedResponse<T> = { cursor?: string | null; data: T[]; hasMore?: boolean };
|
|
6
|
+
|
|
7
|
+
export interface Event extends JsonishRecord {
|
|
8
|
+
correlationId?: string | null;
|
|
9
|
+
eventType?: string;
|
|
10
|
+
}
|
|
11
|
+
export type HealthCheckPayload = JsonishRecord;
|
|
12
|
+
export interface Hook extends JsonishRecord {
|
|
13
|
+
hookId: string;
|
|
14
|
+
token: string;
|
|
15
|
+
}
|
|
16
|
+
export type ValidQueueName = string;
|
|
17
|
+
export interface WorkflowRun extends JsonishRecord {
|
|
18
|
+
runId: string;
|
|
19
|
+
status: WorkflowRunStatus;
|
|
20
|
+
}
|
|
21
|
+
export type WorkflowRunStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
22
|
+
export interface World {
|
|
23
|
+
specVersion?: number;
|
|
24
|
+
createQueueHandler?: any;
|
|
25
|
+
queue(...args: any[]): Promise<void>;
|
|
26
|
+
runs: {
|
|
27
|
+
get(id: string, params?: JsonishRecord): Promise<WorkflowRun>;
|
|
28
|
+
list(params?: JsonishRecord): Promise<PaginatedResponse<WorkflowRun>>;
|
|
29
|
+
};
|
|
30
|
+
steps: {
|
|
31
|
+
get(runId: string, stepId: string, params?: JsonishRecord): Promise<any>;
|
|
32
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<any>>;
|
|
33
|
+
};
|
|
34
|
+
events: {
|
|
35
|
+
create(...args: any[]): Promise<any>;
|
|
36
|
+
get(runId: string, eventId: string, params?: JsonishRecord): Promise<Event>;
|
|
37
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<Event>>;
|
|
38
|
+
listByCorrelationId(params: JsonishRecord): Promise<PaginatedResponse<Event>>;
|
|
39
|
+
};
|
|
40
|
+
hooks: {
|
|
41
|
+
get(hookId: string, params?: JsonishRecord): Promise<Hook>;
|
|
42
|
+
getByToken(token: string, params?: JsonishRecord): Promise<Hook>;
|
|
43
|
+
list(params: JsonishRecord): Promise<PaginatedResponse<Hook>>;
|
|
44
|
+
};
|
|
45
|
+
streams: {
|
|
46
|
+
write(runId: string, name: string, chunk: string | Uint8Array): Promise<void>;
|
|
47
|
+
writeMulti?(runId: string, name: string, chunks: (string | Uint8Array)[]): Promise<void>;
|
|
48
|
+
close(runId: string, name: string): Promise<void>;
|
|
49
|
+
get(runId: string, name: string, startIndex?: number): Promise<ReadableStream<Uint8Array>>;
|
|
50
|
+
list(runId: string): Promise<string[]>;
|
|
51
|
+
getChunks(runId: string, name: string, options?: JsonishRecord): Promise<any>;
|
|
52
|
+
getInfo(runId: string, name: string): Promise<any>;
|
|
53
|
+
};
|
|
54
|
+
getEncryptionKeyForRun?(run: WorkflowRun): Promise<Uint8Array | undefined>;
|
|
55
|
+
getEncryptionKeyForRun?(runId: string, context?: JsonishRecord): Promise<Uint8Array | undefined>;
|
|
56
|
+
resolveLatestDeploymentId?(): Promise<string>;
|
|
57
|
+
start?(): Promise<void>;
|
|
58
|
+
close?(): Promise<void>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities table for workflow runs based on their `@workflow/core` version.
|
|
3
|
+
*
|
|
4
|
+
* When resuming a hook or webhook, the payload must be encoded in a format
|
|
5
|
+
* that the *target* workflow run's deployment can decode. This module provides
|
|
6
|
+
* a way to look up what serialization formats a given `@workflow/core` version
|
|
7
|
+
* supports, so that newer deployments can avoid encoding payloads in formats
|
|
8
|
+
* that older deployments don't understand (e.g., the `encr` encryption format).
|
|
9
|
+
*
|
|
10
|
+
* ## Adding a new format
|
|
11
|
+
*
|
|
12
|
+
* When a new serialization format is introduced:
|
|
13
|
+
* 1. Add the format constant to `SerializationFormat` in `serialization.ts`
|
|
14
|
+
* 2. Add an entry to `FORMAT_VERSION_TABLE` below with the minimum
|
|
15
|
+
* `@workflow/core` version that supports it
|
|
16
|
+
* 3. The `getRunCapabilities()` function will automatically include it
|
|
17
|
+
*
|
|
18
|
+
* ## History
|
|
19
|
+
*
|
|
20
|
+
* - `encr` (AES-256-GCM encryption): added in `4.2.0-beta.64`
|
|
21
|
+
* Commit: 7618ac36 "Wire AES-GCM encryption into serialization layer (#1251)"
|
|
22
|
+
* https://github.com/vercel/workflow/commit/7618ac36
|
|
23
|
+
*/
|
|
24
|
+
import { type SerializationFormatType } from './serialization.js';
|
|
25
|
+
/**
|
|
26
|
+
* Capabilities of a workflow run based on its `@workflow/core` version.
|
|
27
|
+
*/
|
|
28
|
+
export interface RunCapabilities {
|
|
29
|
+
/**
|
|
30
|
+
* The set of serialization format prefixes that the target run can decode.
|
|
31
|
+
* Use `supportedFormats.has(SerializationFormat.ENCRYPTED)` to check
|
|
32
|
+
* if encryption is supported, etc.
|
|
33
|
+
*/
|
|
34
|
+
supportedFormats: ReadonlySet<SerializationFormatType>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Look up what serialization capabilities a workflow run supports based on
|
|
38
|
+
* its `@workflow/core` version string (from `executionContext.workflowCoreVersion`).
|
|
39
|
+
*
|
|
40
|
+
* When the version is `undefined`, not a string, or not a valid semver string
|
|
41
|
+
* (e.g. very old runs that predate the field, or corrupted metadata),
|
|
42
|
+
* we assume the most conservative capabilities (baseline formats only).
|
|
43
|
+
*/
|
|
44
|
+
export declare function getRunCapabilities(workflowCoreVersion: string | undefined): RunCapabilities;
|
|
45
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V8-only (Node, Bun, Chrome, Deno). Rewrites `err.stack` so the top frame is
|
|
3
|
+
* the caller of `stackStartFn` instead of the framework function that threw.
|
|
4
|
+
* Without this, terminal overlays (Next.js, Turbopack, VS Code) render the
|
|
5
|
+
* code frame at our `throw` site inside `@workflow/core`, which is useless
|
|
6
|
+
* to the user.
|
|
7
|
+
*
|
|
8
|
+
* No-op on engines that don't expose `Error.captureStackTrace` — the stack
|
|
9
|
+
* degrades gracefully to the default behavior.
|
|
10
|
+
*
|
|
11
|
+
* Kept in its own tiny module so callers that can't participate in the
|
|
12
|
+
* `context-errors.ts` ↔ `workflow/get-workflow-metadata.ts` import cycle can
|
|
13
|
+
* still pull in the helper without pulling in the full error classes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function redirectStackToCaller(err: Error, stackStartFn: Function): void;
|
|
16
|
+
//# sourceMappingURL=capture-stack.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class serialization utilities.
|
|
3
|
+
*
|
|
4
|
+
* This module is separate from private.ts to avoid pulling in Node.js-only
|
|
5
|
+
* dependencies (like async_hooks via get-closure-vars.ts) when used in
|
|
6
|
+
* workflow bundles.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Register a class constructor for serialization.
|
|
10
|
+
* This allows class constructors to be deserialized by looking up the classId.
|
|
11
|
+
*
|
|
12
|
+
* Note: The SWC plugin now inlines equivalent registration logic as a
|
|
13
|
+
* self-contained IIFE (using the same globalThis Symbol-keyed registry),
|
|
14
|
+
* so this function is no longer imported by generated code. It is retained
|
|
15
|
+
* for programmatic use and testing.
|
|
16
|
+
*
|
|
17
|
+
* Also sets the `classId` property on the class so the serializer can find it
|
|
18
|
+
* when serializing instances (e.g., step return values).
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerSerializationClass(classId: string, cls: Function): void;
|
|
21
|
+
/**
|
|
22
|
+
* Find a registered class constructor by ID (used during deserialization)
|
|
23
|
+
*
|
|
24
|
+
* @param classId - The class ID to look up
|
|
25
|
+
* @param global - The global object to check. This ensures workflow code running
|
|
26
|
+
* in a VM only accesses classes registered on the VM's global,
|
|
27
|
+
* matching production serverless behavior where workflow code
|
|
28
|
+
* runs in isolation.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSerializationClass(classId: string, global: Record<string, any>): Function | undefined;
|
|
31
|
+
//# sourceMappingURL=class-serialization.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RunErrorCode } from '#compiled/@workflow/errors/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Classify an error that caused a workflow run to fail.
|
|
4
|
+
*
|
|
5
|
+
* After the structural separation of infrastructure vs user code error
|
|
6
|
+
* handling, the only errors that reach the `run_failed` try/catch are:
|
|
7
|
+
* - User code errors (throws from workflow functions, propagated step failures)
|
|
8
|
+
* - WorkflowRuntimeError and subclasses (corrupted event log, missing
|
|
9
|
+
* timestamps, workflow/step not registered, etc.)
|
|
10
|
+
*
|
|
11
|
+
* Uses each subclass's `.is()` static (a name-based duck check) instead of
|
|
12
|
+
* a single `instanceof` check because workflows execute in a separate
|
|
13
|
+
* `vm` realm: the VM-context `WorkflowRuntimeError` and the host-context
|
|
14
|
+
* one are distinct classes, so `instanceof` returns `false` for any error
|
|
15
|
+
* thrown inside the workflow VM and we'd misclassify genuine runtime
|
|
16
|
+
* errors as user errors.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyRunError(err: unknown): RunErrorCode;
|
|
19
|
+
//# sourceMappingURL=classify-error.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ContextViolationError, type DocsUrl, NotInStepContextError, NotInWorkflowContextError, NotInWorkflowOrStepContextError } from './context-violation-error.js';
|
|
2
|
+
export { ContextViolationError, NotInStepContextError, NotInWorkflowContextError, NotInWorkflowOrStepContextError, };
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when an API that MUST NOT run inside a workflow function is called
|
|
5
|
+
* from one (e.g. `resumeHook()`, which would cause determinism issues).
|
|
6
|
+
* The message names the specific workflow that made the offending call.
|
|
7
|
+
*/
|
|
8
|
+
export declare class UnavailableInWorkflowContextError extends ContextViolationError {
|
|
9
|
+
name: string;
|
|
10
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Throw a {@link NotInWorkflowContextError} whose stack trace points at the
|
|
14
|
+
* user code that called `stackStartFn`, not at our framework internals.
|
|
15
|
+
*
|
|
16
|
+
* Prefer this over `throw new NotInWorkflowContextError(...)` so tooling
|
|
17
|
+
* (Next.js error overlay, VS Code terminal linkifier, Sentry, etc.) shows
|
|
18
|
+
* the user's call site as the relevant frame.
|
|
19
|
+
*/
|
|
20
|
+
export declare function throwNotInWorkflowContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
21
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
22
|
+
export declare function throwNotInStepContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
23
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
24
|
+
export declare function throwNotInWorkflowOrStepContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
25
|
+
/** See {@link throwNotInWorkflowContext}. */
|
|
26
|
+
export declare function throwUnavailableInWorkflowContext(functionName: string, docsUrl: DocsUrl, stackStartFn: Function): never;
|
|
27
|
+
//# sourceMappingURL=context-errors.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `docs:` line URL. The leading protocol is part of the type so call sites
|
|
3
|
+
* can't accidentally pass a protocol-relative or bare path.
|
|
4
|
+
*/
|
|
5
|
+
export type DocsUrl = `https://${string}`;
|
|
6
|
+
declare const INSPECT_CUSTOM: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Structured data for a framed error. The base class takes this and renders
|
|
9
|
+
* it to plain text (for `.message` / `.stack` / structured logs) or to an
|
|
10
|
+
* ANSI-framed string (for terminal display via `util.inspect` / `toString`).
|
|
11
|
+
*
|
|
12
|
+
* Keeping the pieces structured means we never have to strip ANSI back out
|
|
13
|
+
* once it's in the message — we just don't put it there in the first place.
|
|
14
|
+
*/
|
|
15
|
+
export interface FramedContent {
|
|
16
|
+
/** Headline. `{ code: 'foo()' }` segments render as backticked inline code. */
|
|
17
|
+
readonly title: readonly Segment[];
|
|
18
|
+
/** One framed branch per entry. The last uses `╰▶`, others use `├▶`. */
|
|
19
|
+
readonly details: readonly Detail[];
|
|
20
|
+
}
|
|
21
|
+
export type Segment = {
|
|
22
|
+
readonly text: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly code: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly dim: string;
|
|
27
|
+
};
|
|
28
|
+
export type Detail = {
|
|
29
|
+
readonly type: 'plain';
|
|
30
|
+
readonly segments: readonly Segment[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: 'docs';
|
|
33
|
+
readonly url: DocsUrl;
|
|
34
|
+
};
|
|
35
|
+
export declare function renderPlain(c: FramedContent): string;
|
|
36
|
+
export declare function renderPretty(c: FramedContent): string;
|
|
37
|
+
/**
|
|
38
|
+
* Base class for structured context-violation errors.
|
|
39
|
+
*
|
|
40
|
+
* Design notes:
|
|
41
|
+
*
|
|
42
|
+
* - `.message` is **plain text** (no ANSI escape bytes). Structured logs,
|
|
43
|
+
* log drains, CBOR-serialized event data, and anything else that reads
|
|
44
|
+
* `err.message` / `err.stack` as a string gets clean output — no mojibake
|
|
45
|
+
* in JSON, no `\x1B[...m` noise in Vercel logs.
|
|
46
|
+
*
|
|
47
|
+
* - The ANSI-framed version is rendered **lazily** via `toString()` and
|
|
48
|
+
* `[util.inspect.custom]`. When the error is thrown and Node prints it
|
|
49
|
+
* via `util.inspect`, the user sees the colored, framed box. When it's
|
|
50
|
+
* attached to a structured log field, the consumer sees plain text.
|
|
51
|
+
*
|
|
52
|
+
* - `fatal = true` marks these as non-retryable. Calling `createHook()`
|
|
53
|
+
* from a step function will never succeed no matter how many retries —
|
|
54
|
+
* burning attempts just produces duplicated log output. The runtime's
|
|
55
|
+
* `FatalError.is(err)` gate recognizes any error with `fatal: true`.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class ContextViolationError extends Error {
|
|
58
|
+
#private;
|
|
59
|
+
/** Non-retryable — see class doc. */
|
|
60
|
+
readonly fatal = true;
|
|
61
|
+
constructor(content: FramedContent);
|
|
62
|
+
/**
|
|
63
|
+
* `console.log(err)` and most Node internals route through `util.inspect`,
|
|
64
|
+
* which respects this symbol. Returning a custom string here means the
|
|
65
|
+
* thrown error prints as a pretty frame in the terminal while `.message`
|
|
66
|
+
* and `.stack` stay plain.
|
|
67
|
+
*/
|
|
68
|
+
[INSPECT_CUSTOM](): string;
|
|
69
|
+
toString(): string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Thrown when an API that must run inside a workflow function is called
|
|
73
|
+
* from outside a workflow context (e.g. from a step function or from
|
|
74
|
+
* regular application code).
|
|
75
|
+
*/
|
|
76
|
+
export declare class NotInWorkflowContextError extends ContextViolationError {
|
|
77
|
+
name: string;
|
|
78
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when an API that must run inside a step function is called from
|
|
82
|
+
* outside a step context.
|
|
83
|
+
*/
|
|
84
|
+
export declare class NotInStepContextError extends ContextViolationError {
|
|
85
|
+
name: string;
|
|
86
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Thrown when an API that must run inside either a workflow or step function
|
|
90
|
+
* is called from regular application code.
|
|
91
|
+
*/
|
|
92
|
+
export declare class NotInWorkflowOrStepContextError extends ContextViolationError {
|
|
93
|
+
name: string;
|
|
94
|
+
constructor(functionName: string, docsUrl: DocsUrl);
|
|
95
|
+
}
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=context-violation-error.d.ts.map
|