stable-harness 0.0.39 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +13 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/docs/architecture/runtime-events.md +10 -0
  5. package/docs/guides/index.md +2 -0
  6. package/docs/guides/workspace-docker-build.md +88 -0
  7. package/docs/protocols/http-runtime.md +8 -0
  8. package/docs/protocols/langgraph-compatible.md +22 -0
  9. package/node_modules/@stable-harness/adapter-deepagents/dist/src/adapter.js +1 -1
  10. package/node_modules/@stable-harness/core/dist/index.d.ts +2 -0
  11. package/node_modules/@stable-harness/core/dist/index.js +1 -1
  12. package/node_modules/@stable-harness/core/dist/runtime/events.d.ts +6 -2
  13. package/node_modules/@stable-harness/core/dist/runtime/progress-narration.js +1 -1
  14. package/node_modules/@stable-harness/core/dist/runtime/tracing/langsmith.d.ts +27 -0
  15. package/node_modules/@stable-harness/core/dist/runtime/tracing/langsmith.js +1 -0
  16. package/node_modules/@stable-harness/core/dist/runtime.d.ts +2 -0
  17. package/node_modules/@stable-harness/core/dist/runtime.js +1 -1
  18. package/node_modules/@stable-harness/core/dist/trace.d.ts +26 -0
  19. package/node_modules/@stable-harness/core/dist/trace.js +1 -1
  20. package/node_modules/@stable-harness/core/dist/workspace/types.d.ts +1 -0
  21. package/node_modules/@stable-harness/protocols/dist/src/http-server.js +1 -1
  22. package/node_modules/@stable-harness/tool-gateway/dist/src/module-loader.js +1 -1
  23. package/node_modules/@stable-harness/workspace-yaml/dist/documents.js +1 -1
  24. package/package.json +5 -2
  25. package/packages/adapter-deepagents/dist/src/adapter.js +1 -1
  26. package/packages/cli/dist/src/args.d.ts +3 -1
  27. package/packages/cli/dist/src/args.js +1 -1
  28. package/packages/cli/dist/src/build.d.ts +9 -0
  29. package/packages/cli/dist/src/build.js +1 -0
  30. package/packages/cli/dist/src/cli.js +1 -1
  31. package/packages/cli/dist/src/index.d.ts +1 -0
  32. package/packages/cli/dist/src/index.js +1 -1
  33. package/packages/cli/dist/src/langgraph-official.js +1 -1
  34. package/packages/core/dist/index.d.ts +2 -0
  35. package/packages/core/dist/index.js +1 -1
  36. package/packages/core/dist/runtime/events.d.ts +6 -2
  37. package/packages/core/dist/runtime/progress-narration.js +1 -1
  38. package/packages/core/dist/runtime/tracing/langsmith.d.ts +27 -0
  39. package/packages/core/dist/runtime/tracing/langsmith.js +1 -0
  40. package/packages/core/dist/runtime.d.ts +2 -0
  41. package/packages/core/dist/runtime.js +1 -1
  42. package/packages/core/dist/trace.d.ts +26 -0
  43. package/packages/core/dist/trace.js +1 -1
  44. package/packages/core/dist/workspace/types.d.ts +1 -0
  45. package/packages/protocols/dist/src/http-server.js +1 -1
  46. package/packages/tool-gateway/dist/src/module-loader.js +1 -1
  47. package/packages/workspace-yaml/dist/documents.js +1 -1
@@ -1 +1 @@
1
- import{createServer as t}from"node:http";import{compileWorkflowPlan as e,projectRuntimeTrace as r,renderWorkflowMermaid as o}from"@stable-harness/core";export function createHttpServer(n){return t(async(t,s)=>{try{if("GET"===t.method&&"/health"===t.url)return void sendJson(s,200,{ok:!0});if("GET"===t.method&&"/inspect"===t.url)return void sendJson(s,200,n.inspect());if("GET"===t.method&&"/requests"===t.url)return void sendJson(s,200,n.listRequests());if("GET"===t.method&&"/sessions"===t.url)return void sendJson(s,200,n.listSessions());const a=function readArtifactList(t){if(!t?.startsWith("/artifacts"))return;const e=new URL(t,"http://stable-harness.local");return"/artifacts"===e.pathname?{...e.searchParams.get("requestId")?{requestId:e.searchParams.get("requestId")}:{},...e.searchParams.get("sessionId")?{sessionId:e.searchParams.get("sessionId")}:{},...e.searchParams.get("agentId")?{agentId:e.searchParams.get("agentId")}:{}}:void 0}(t.url);if("GET"===t.method&&a)return void sendJson(s,200,n.listArtifacts(a));const d=function readArtifactContentId(t){const e=(t??"").match(/^\/artifacts\/([^/]+)\/content$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&d){const t=n.getArtifact(d),e=n.readArtifact(d);return void sendJson(s,t&&void 0!==e?200:404,t&&void 0!==e?{artifact:t,content:e}:{error:"artifact_content_not_found"})}const i=function readArtifactId(t){const e=(t??"").match(/^\/artifacts\/([^/]+)$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&i){const t=n.getArtifact(i);return void sendJson(s,t?200:404,t??{error:"artifact_not_found"})}const c=function readApprovalList(t){if(!t?.startsWith("/approvals"))return;const e=new URL(t,"http://stable-harness.local");if("/approvals"!==e.pathname)return;const r=e.searchParams.get("status");return{status:"pending"===r||"approved"===r||"rejected"===r?r:void 0}}(t.url);if("GET"===t.method&&c)return void sendJson(s,200,await n.listApprovals(c.status));const u=function readApprovalDecision(t){const e=(t??"").match(/^\/approvals\/([^/]+)\/(approve|reject)$/u);if(e?.[1]&&e[2])return{id:decodeURIComponent(e[1]),status:"approve"===e[2]?"approved":"rejected"}}(t.url);if("POST"===t.method&&u){const t=await n.resolveApproval(u.id,u.status);return void sendJson(s,t?200:404,t??{error:"approval_not_found"})}if("GET"===t.method&&"/workflows"===t.url)return void sendJson(s,200,n.inspect().workflows);const f=function readWorkflowMermaidId(t){const e=(t??"").match(/^\/workflows\/([^/]+)\/mermaid$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&f){const t=n.getWorkflow(f);return void sendJson(s,t?200:404,t?{mermaid:o(t)}:{error:"workflow_not_found"})}const l=function readWorkflowPlanId(t){const e=(t??"").match(/^\/workflows\/([^/]+)\/plan$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&l){const t=n.getWorkflow(l);return void sendJson(s,t?200:404,t?e(t):{error:"workflow_not_found"})}const p=function readRequestInspectionId(t){const e=(t??"").match(/^\/requests\/([^/]+)$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&p){const t=n.inspectRequest(p);return void sendJson(s,t?200:404,t??{error:"request_not_found"})}const m=function readTraceRequestId(t){const e=(t??"").match(/^\/runs\/([^/]+)\/trace$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&m){const t=n.getRun(m);return void sendJson(s,t?200:404,t?r(t):{error:"run_not_found"})}const h=function readReplayRequestId(t){const e=(t??"").match(/^\/requests\/([^/]+)\/replay$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&h){const t=n.exportReplayBundle(h);return void sendJson(s,t?200:404,t??{error:"run_not_found"})}if("POST"===t.method&&"/requests"===t.url){const e=await async function readJson(t){const e=[];for await(const r of t)e.push(Buffer.isBuffer(r)?r:Buffer.from(r));return 0===e.length?{}:JSON.parse(Buffer.concat(e).toString("utf8"))}(t);return void sendJson(s,200,await n.request(function readRuntimeRequest(t){const e=function readToolCall(t){if("object"!=typeof t||null===t)return;const e=t;return"string"==typeof e.toolId?{toolId:e.toolId,args:e.args}:void 0}(t.toolCall),r=function readWorkflow(t){const e=readRecord(t);if(e)return{..."string"==typeof e.workflowId?{workflowId:e.workflowId}:{},..."string"==typeof e.routeId?{routeId:e.routeId}:{},...void 0!==e.input?{input:e.input}:{},..."object"==typeof e.metadata&&e.metadata?{metadata:e.metadata}:{}}}(t.workflow),o=function readMemory(t){const e=readRecord(t);if(e)return{..."string"==typeof e.namespace?{namespace:e.namespace}:{},...!1===e.recall||readRecord(e.recall)?{recall:e.recall}:{},...Array.isArray(e.candidates)?{candidates:e.candidates}:{}}}(t.memory),n=readRecord(t.metadata);return{input:"string"==typeof t.input?t.input:"",..."string"==typeof t.agentId?{agentId:t.agentId}:{},..."string"==typeof t.sessionId?{sessionId:t.sessionId}:{},..."string"==typeof t.requestId?{requestId:t.requestId}:{},..."string"==typeof t.parentRunId?{parentRunId:t.parentRunId}:{},...e?{toolCall:e}:{},...r?{workflow:r}:{},...o?{memory:o}:{},...n?{metadata:n}:{}}}(e)))}sendJson(s,404,{error:"not_found"})}catch(t){sendJson(s,500,{error:t instanceof Error?t.message:String(t)})}})}function readRecord(t){return"object"!=typeof t||null===t||Array.isArray(t)?void 0:t}function sendJson(t,e,r){t.writeHead(e,{"content-type":"application/json"}),t.end(JSON.stringify(r))}
1
+ import{createServer as t}from"node:http";import{compileWorkflowPlan as e,projectRuntimeTrace as r,projectRuntimeTraceSpans as o,renderWorkflowMermaid as n}from"@stable-harness/core";export function createHttpServer(s){return t(async(t,a)=>{try{if("GET"===t.method&&"/health"===t.url)return void sendJson(a,200,{ok:!0});if("GET"===t.method&&"/inspect"===t.url)return void sendJson(a,200,s.inspect());if("GET"===t.method&&"/requests"===t.url)return void sendJson(a,200,s.listRequests());if("GET"===t.method&&"/sessions"===t.url)return void sendJson(a,200,s.listSessions());const d=function readArtifactList(t){if(!t?.startsWith("/artifacts"))return;const e=new URL(t,"http://stable-harness.local");return"/artifacts"===e.pathname?{...e.searchParams.get("requestId")?{requestId:e.searchParams.get("requestId")}:{},...e.searchParams.get("sessionId")?{sessionId:e.searchParams.get("sessionId")}:{},...e.searchParams.get("agentId")?{agentId:e.searchParams.get("agentId")}:{}}:void 0}(t.url);if("GET"===t.method&&d)return void sendJson(a,200,s.listArtifacts(d));const i=function readArtifactContentId(t){const e=(t??"").match(/^\/artifacts\/([^/]+)\/content$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&i){const t=s.getArtifact(i),e=s.readArtifact(i);return void sendJson(a,t&&void 0!==e?200:404,t&&void 0!==e?{artifact:t,content:e}:{error:"artifact_content_not_found"})}const u=function readArtifactId(t){const e=(t??"").match(/^\/artifacts\/([^/]+)$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&u){const t=s.getArtifact(u);return void sendJson(a,t?200:404,t??{error:"artifact_not_found"})}const c=function readApprovalList(t){if(!t?.startsWith("/approvals"))return;const e=new URL(t,"http://stable-harness.local");if("/approvals"!==e.pathname)return;const r=e.searchParams.get("status");return{status:"pending"===r||"approved"===r||"rejected"===r?r:void 0}}(t.url);if("GET"===t.method&&c)return void sendJson(a,200,await s.listApprovals(c.status));const f=function readApprovalDecision(t){const e=(t??"").match(/^\/approvals\/([^/]+)\/(approve|reject)$/u);if(e?.[1]&&e[2])return{id:decodeURIComponent(e[1]),status:"approve"===e[2]?"approved":"rejected"}}(t.url);if("POST"===t.method&&f){const t=await s.resolveApproval(f.id,f.status);return void sendJson(a,t?200:404,t??{error:"approval_not_found"})}if("GET"===t.method&&"/workflows"===t.url)return void sendJson(a,200,s.inspect().workflows);const l=function readWorkflowMermaidId(t){const e=(t??"").match(/^\/workflows\/([^/]+)\/mermaid$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&l){const t=s.getWorkflow(l);return void sendJson(a,t?200:404,t?{mermaid:n(t)}:{error:"workflow_not_found"})}const p=function readWorkflowPlanId(t){const e=(t??"").match(/^\/workflows\/([^/]+)\/plan$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&p){const t=s.getWorkflow(p);return void sendJson(a,t?200:404,t?e(t):{error:"workflow_not_found"})}const m=function readRequestInspectionId(t){const e=(t??"").match(/^\/requests\/([^/]+)$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&m){const t=s.inspectRequest(m);return void sendJson(a,t?200:404,t??{error:"request_not_found"})}const h=function readTraceRequestId(t){const e=(t??"").match(/^\/runs\/([^/]+)\/trace$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&h){const t=s.getRun(h);return void sendJson(a,t?200:404,t?r(t):{error:"run_not_found"})}const I=function readSpanRequestId(t){const e=(t??"").match(/^\/runs\/([^/]+)\/spans$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&I){const t=s.getRun(I);return void sendJson(a,t?200:404,t?o(t):{error:"run_not_found"})}const v=function readReplayRequestId(t){const e=(t??"").match(/^\/requests\/([^/]+)\/replay$/u);return e?.[1]?decodeURIComponent(e[1]):void 0}(t.url);if("GET"===t.method&&v){const t=s.exportReplayBundle(v);return void sendJson(a,t?200:404,t??{error:"run_not_found"})}if("POST"===t.method&&"/requests"===t.url){const e=await async function readJson(t){const e=[];for await(const r of t)e.push(Buffer.isBuffer(r)?r:Buffer.from(r));return 0===e.length?{}:JSON.parse(Buffer.concat(e).toString("utf8"))}(t);return void sendJson(a,200,await s.request(function readRuntimeRequest(t){const e=function readToolCall(t){if("object"!=typeof t||null===t)return;const e=t;return"string"==typeof e.toolId?{toolId:e.toolId,args:e.args}:void 0}(t.toolCall),r=function readWorkflow(t){const e=readRecord(t);if(e)return{..."string"==typeof e.workflowId?{workflowId:e.workflowId}:{},..."string"==typeof e.routeId?{routeId:e.routeId}:{},...void 0!==e.input?{input:e.input}:{},..."object"==typeof e.metadata&&e.metadata?{metadata:e.metadata}:{}}}(t.workflow),o=function readMemory(t){const e=readRecord(t);if(e)return{..."string"==typeof e.namespace?{namespace:e.namespace}:{},...!1===e.recall||readRecord(e.recall)?{recall:e.recall}:{},...Array.isArray(e.candidates)?{candidates:e.candidates}:{}}}(t.memory),n=readRecord(t.metadata);return{input:"string"==typeof t.input?t.input:"",..."string"==typeof t.agentId?{agentId:t.agentId}:{},..."string"==typeof t.sessionId?{sessionId:t.sessionId}:{},..."string"==typeof t.requestId?{requestId:t.requestId}:{},..."string"==typeof t.parentRunId?{parentRunId:t.parentRunId}:{},...e?{toolCall:e}:{},...r?{workflow:r}:{},...o?{memory:o}:{},...n?{metadata:n}:{}}}(e)))}sendJson(a,404,{error:"not_found"})}catch(t){sendJson(a,500,{error:t instanceof Error?t.message:String(t)})}})}function readRecord(t){return"object"!=typeof t||null===t||Array.isArray(t)?void 0:t}function sendJson(t,e,r){t.writeHead(e,{"content-type":"application/json"}),t.end(JSON.stringify(r))}
@@ -1 +1 @@
1
- import o from"node:path";import{pathToFileURL as e}from"node:url";import{createInMemoryToolGateway as t}from"./in-memory.js";export async function createModuleToolGateway(o){const e=[];for(const t of o.tools){const o=await loadModuleTool(t);o&&e.push(o)}return t(e,o.options)}async function loadModuleTool(t){if(!t.sourcePath)return;const n=await import(e(o.resolve(t.sourcePath)).href),r=n[t.name??t.id]??n.default;return function hasInvoke(o){return"object"==typeof o&&null!==o&&"invoke"in o&&"function"==typeof o.invoke}(r)?{id:t.id,description:t.description??r.description,schema:t.schema??r.schema,validateArgs:r.validateArgs,invoke:(o,e)=>async function invokeWithWorkspaceCwd(o,e,t){const n=process.cwd();try{return process.chdir(t.workspaceRoot),await o(e,t)}finally{process.chdir(n)}}(r.invoke,o,e)}:void 0}
1
+ import o from"node:path";import{pathToFileURL as e}from"node:url";import{createInMemoryToolGateway as t}from"./in-memory.js";export async function createModuleToolGateway(o){const e=[];for(const t of o.tools){const o=await loadModuleTool(t);o&&e.push(o)}return t(e,o.options)}async function loadModuleTool(t){if(!t.sourcePath||!function isJavaScriptModule(e){const t=o.extname(e);return".mjs"===t||".js"===t||".cjs"===t}(t.sourcePath))return;const n=await import(e(o.resolve(t.sourcePath)).href),r=n[t.name??t.id]??n.default;return function hasInvoke(o){return"object"==typeof o&&null!==o&&"invoke"in o&&"function"==typeof o.invoke}(r)?{id:t.id,description:t.description??r.description,schema:t.schema??r.schema,validateArgs:r.validateArgs,invoke:(o,e)=>async function invokeWithWorkspaceCwd(o,e,t){const n=process.cwd();try{return process.chdir(t.workspaceRoot),await o(e,t)}finally{process.chdir(n)}}(r.invoke,o,e)}:void 0}
@@ -1 +1 @@
1
- import{assertSpecDrivenWorkflowPolicy as e,createSpecDrivenWorkflowPolicy as r}from"@stable-harness/core";function assertRecord(e,r){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(`${r} must be an object`);return e}function readName(e,r){const t=e.metadata?.name;if("string"==typeof t&&t.trim())return t.trim();if(r)return r;throw new Error(`Document kind ${String(e.kind)} requires metadata.name`)}function readDescription(e){const r=e.metadata?.description;return"string"==typeof r&&r.trim()?r.trim():void 0}function readOptionalString(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function toStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.trim().length>0):[]}function resolveValue(e){if("string"!=typeof e)return e;const r=e.match(/^\$\{env:([A-Za-z_][A-Za-z0-9_]*)(?::-(.*))?\}$/u);return r?process.env[r[1]]??r[2]??"":e}export function compileRuntime(e){const r=assertRecord(e.spec,"Runtime.spec"),t=assertRecord(r.routing??{},"Runtime.spec.routing");return{defaultAgentId:"string"==typeof t.defaultAgentId&&t.defaultAgentId.trim()?t.defaultAgentId.trim():"orchestra",...void 0!==t.routes?{routes:readAgentRoutes(t.routes)}:{},...readOptionalString(r.workspaceId)?{workspaceId:readOptionalString(r.workspaceId)}:{},...readOptionalString(r.profile)?{profile:readOptionalString(r.profile)}:{},...void 0!==r.adapters?{adapters:readAdapters(r.adapters)}:{},..."object"==typeof r.workflowRouting&&r.workflowRouting?{workflowRouting:readWorkflowRouting(r.workflowRouting)}:{},..."object"==typeof r.specDrivenWorkflow&&r.specDrivenWorkflow?{specDrivenWorkflow:readSpecDrivenWorkflow(r.specDrivenWorkflow)}:{},..."object"==typeof r.approvals&&r.approvals?{approvals:r.approvals}:{},..."object"==typeof r.recovery&&r.recovery?{recovery:r.recovery}:{},..."object"==typeof r.retry&&r.retry?{retry:r.retry}:{},..."object"==typeof r.toolGateway&&r.toolGateway?{toolGateway:r.toolGateway}:{},..."object"==typeof r.memory&&r.memory?{memory:r.memory}:{},..."object"==typeof r.protocols&&r.protocols?{protocols:r.protocols}:{},..."object"==typeof r.progress&&r.progress?{progress:r.progress}:{},..."object"==typeof r.cli&&r.cli?{cli:r.cli}:{},..."string"==typeof r.quality||"object"==typeof r.quality&&r.quality?{quality:r.quality}:{},..."object"==typeof r.workspaceValidation&&r.workspaceValidation?{workspaceValidation:r.workspaceValidation}:{},..."object"==typeof r.responseLanguage&&r.responseLanguage?{responseLanguage:r.responseLanguage}:{},..."object"==typeof r.responsePresentation&&r.responsePresentation?{responsePresentation:r.responsePresentation}:{}}}function readAgentRoutes(e){if(!Array.isArray(e))throw new Error("Runtime.spec.routing.routes must be an array");return e.map(e=>{const r=assertRecord(e,"Runtime.spec.routing.routes[]"),t=readOptionalString(r.id),o=readOptionalString(r.agentId);if(!t||!o)throw new Error("Runtime.spec.routing.routes[] requires id and agentId");const n=void 0===r.keywords?void 0:function assertStringArray(e,r){if(!Array.isArray(e))throw new Error(`${r} must be an array`);return e.map(e=>{if("string"!=typeof e||!e.trim())throw new Error(`${r} must contain non-empty strings`);return e.trim()})}(r.keywords,"Runtime.spec.routing.routes[].keywords"),i=readOptionalString(r.pattern);if(!(n&&0!==n.length||i))throw new Error("Runtime.spec.routing.routes[] requires keywords or pattern");return{id:t,agentId:o,...n&&n.length>0?{keywords:n}:{},...i?{pattern:i}:{},...readOptionalString(r.description)?{description:readOptionalString(r.description)}:{}}})}function readSpecDrivenWorkflow(t){const o=assertRecord(t,"Runtime.spec.specDrivenWorkflow"),n=r({enabled:!0===o.enabled,constitution:readOptionalString(o.constitution),artifactsDir:readOptionalString(o.artifactsDir),phases:void 0===o.phases?void 0:readSpecDrivenPhases(o.phases),..."object"==typeof o.gates&&o.gates?{gates:o.gates}:{},..."object"==typeof o.config&&o.config?{config:o.config}:{}});return e(n),n}function readSpecDrivenPhases(e){if(!Array.isArray(e))throw new Error("Runtime.spec.specDrivenWorkflow.phases must be an array");return e.map(e=>{if("string"==typeof e&&e.trim())return{id:e.trim()};const r=assertRecord(e,"Runtime.spec.specDrivenWorkflow.phases[]"),t=readOptionalString(r.id);if(!t)throw new Error("Runtime.spec.specDrivenWorkflow.phases[] requires id");return{id:t,...readOptionalString(r.artifactKind)?{artifactKind:readOptionalString(r.artifactKind)}:{},..."boolean"==typeof r.required?{required:r.required}:{},...readOptionalString(r.gate)?{gate:readOptionalString(r.gate)}:{},..."object"==typeof r.config&&r.config?{config:r.config}:{}}})}export function compileAgent(e,r){const t=assertRecord(e.spec,"Agent.spec"),o=readName(e),n=readOptionalString(t.backend);if(!n)throw new Error(`Agent ${o} requires spec.backend`);const i="object"==typeof t.config&&t.config?t.config:{},a="string"==typeof t.systemPrompt?t.systemPrompt:"string"==typeof i.systemPrompt?i.systemPrompt:void 0;return{id:o,...readDescription(e)?{description:readDescription(e)}:{},sourcePath:r,backend:n,..."string"==typeof t.modelRef&&t.modelRef.trim()?{modelRef:(s=t.modelRef,s.replace(/^[^/]+\//u,""))}:{},...void 0!==a?{systemPrompt:a}:{},tools:toStringArray(t.tools),skills:toStringArray(t.skills),memory:Array.isArray(t.memory)?t.memory:[],subagents:toStringArray(t.subagents),...void 0!==t.edges?{edges:readAgentEdges(t.edges,o)}:{},config:i};var s}export function compileModel(e){return compileModelSpec(assertRecord(e.spec,"Model.spec"),readName(e))}export function compileModelSpec(e,r){const t="string"==typeof e.name&&e.name.trim()?e.name.trim():r??"default",o=resolveValue(e.provider),n=resolveValue(e.model),i="string"==typeof o&&o.trim()?o.trim():"unknown",a="string"==typeof n&&n.trim()?n.trim():t,s={...e};return delete s.name,delete s.provider,delete s.model,{id:t,provider:i,model:a,config:Object.fromEntries(Object.entries(s).map(([e,r])=>[e,resolveValue(r)]))}}export function compileTool(e,r){const t=assertRecord(e.spec,"Tool.spec");return{id:readName(e),...r?{sourcePath:r}:{},..."string"==typeof t.description?{description:t.description}:{},...void 0!==t.schema?{schema:t.schema}:{},...void 0!==t.outputSchema?{outputSchema:t.outputSchema}:{},..."object"==typeof t.metadata&&t.metadata?{metadata:t.metadata}:{},..."string"==typeof t.implementation?{implementation:t.implementation}:{}}}export function compileMemory(e){const r=assertRecord(e.spec,"Memory.spec"),t=readName(e),o={...r};return delete o.provider,delete o.profile,delete o.mode,delete o.enabled,delete o.prompts,{id:t,provider:readOptionalString(r.provider)??"langmem",...readOptionalString(r.profile)?{profile:readOptionalString(r.profile)}:{},...readOptionalString(r.mode)?{mode:readOptionalString(r.mode)}:{},enabled:!1!==r.enabled,..."object"==typeof r.prompts&&r.prompts?{prompts:readMemoryPrompts(r.prompts)}:{},...Object.keys(o).length>0?{config:o}:{}}}function readWorkflowRouting(e){const r=assertRecord(e,"Runtime.spec.workflowRouting"),t=void 0===r.routes?void 0:function readWorkflowRoutes(e){if(!Array.isArray(e))throw new Error("Runtime.spec.workflowRouting.routes must be an array");return e.map(e=>{const r=assertRecord(e,"Runtime.spec.workflowRouting.routes[]"),t=readOptionalString(r.id),o=readOptionalString(r.workflowId);if(!t||!o)throw new Error("Runtime.spec.workflowRouting.routes[] requires id and workflowId");return{id:t,workflowId:o,...readOptionalString(r.description)?{description:readOptionalString(r.description)}:{},..."object"==typeof r.metadata&&r.metadata?{metadata:r.metadata}:{}}})}(r.routes);return{...readOptionalString(r.defaultWorkflowId)?{defaultWorkflowId:readOptionalString(r.defaultWorkflowId)}:{},...t?{routes:t}:{}}}function readAdapters(e){if(!Array.isArray(e))throw new Error("Runtime.spec.adapters must be an array");return e.map(readAdapter)}function readAgentEdges(e,r){if(!Array.isArray(e))throw new Error(`Agent ${r} spec.edges must be an array`);return e.map(e=>{const t=assertRecord(e,`Agent ${r} spec.edges[]`),o=readOptionalString(t.from),n=readOptionalString(t.to);if(!o||!n)throw new Error(`Agent ${r} spec.edges[] requires from and to`);return{from:o,to:n,...readOptionalString(t.condition)?{condition:readOptionalString(t.condition)}:{}}})}function readAdapter(e){if("string"==typeof e&&e.trim())return{name:e.trim()};const r=assertRecord(e,"Runtime.spec.adapters[]"),t=readOptionalString(r.name)??readOptionalString(r.id)??readOptionalString(r.backend);if(!t)throw new Error("Runtime.spec.adapters[] requires name");return{name:t,..."boolean"==typeof r.enabled?{enabled:r.enabled}:{},..."object"==typeof r.config&&r.config?{config:r.config}:{}}}function readMemoryPrompts(e){const r=assertRecord(e,"Memory.spec.prompts");return{...readOptionalString(r.semantic)?{semantic:readOptionalString(r.semantic)}:{},...readOptionalString(r.episodic)?{episodic:readOptionalString(r.episodic)}:{},...readOptionalString(r.procedural)?{procedural:readOptionalString(r.procedural)}:{}}}
1
+ import{assertSpecDrivenWorkflowPolicy as e,createSpecDrivenWorkflowPolicy as r}from"@stable-harness/core";function assertRecord(e,r){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(`${r} must be an object`);return e}function readName(e,r){const t=e.metadata?.name;if("string"==typeof t&&t.trim())return t.trim();if(r)return r;throw new Error(`Document kind ${String(e.kind)} requires metadata.name`)}function readDescription(e){const r=e.metadata?.description;return"string"==typeof r&&r.trim()?r.trim():void 0}function readOptionalString(e){return"string"==typeof e&&e.trim()?e.trim():void 0}function toStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.trim().length>0):[]}function resolveValue(e){if("string"!=typeof e)return e;const r=e.match(/^\$\{env:([A-Za-z_][A-Za-z0-9_]*)(?::-(.*))?\}$/u);return r?process.env[r[1]]??r[2]??"":e}export function compileRuntime(e){const r=assertRecord(e.spec,"Runtime.spec"),t=assertRecord(r.routing??{},"Runtime.spec.routing");return{defaultAgentId:"string"==typeof t.defaultAgentId&&t.defaultAgentId.trim()?t.defaultAgentId.trim():"orchestra",...void 0!==t.routes?{routes:readAgentRoutes(t.routes)}:{},...readOptionalString(r.workspaceId)?{workspaceId:readOptionalString(r.workspaceId)}:{},...readOptionalString(r.profile)?{profile:readOptionalString(r.profile)}:{},...void 0!==r.adapters?{adapters:readAdapters(r.adapters)}:{},..."object"==typeof r.workflowRouting&&r.workflowRouting?{workflowRouting:readWorkflowRouting(r.workflowRouting)}:{},..."object"==typeof r.specDrivenWorkflow&&r.specDrivenWorkflow?{specDrivenWorkflow:readSpecDrivenWorkflow(r.specDrivenWorkflow)}:{},..."object"==typeof r.approvals&&r.approvals?{approvals:r.approvals}:{},..."object"==typeof r.recovery&&r.recovery?{recovery:r.recovery}:{},..."object"==typeof r.retry&&r.retry?{retry:r.retry}:{},..."object"==typeof r.toolGateway&&r.toolGateway?{toolGateway:r.toolGateway}:{},..."object"==typeof r.memory&&r.memory?{memory:r.memory}:{},..."object"==typeof r.protocols&&r.protocols?{protocols:r.protocols}:{},..."object"==typeof r.tracing&&r.tracing?{tracing:r.tracing}:{},..."object"==typeof r.progress&&r.progress?{progress:r.progress}:{},..."object"==typeof r.cli&&r.cli?{cli:r.cli}:{},..."string"==typeof r.quality||"object"==typeof r.quality&&r.quality?{quality:r.quality}:{},..."object"==typeof r.workspaceValidation&&r.workspaceValidation?{workspaceValidation:r.workspaceValidation}:{},..."object"==typeof r.responseLanguage&&r.responseLanguage?{responseLanguage:r.responseLanguage}:{},..."object"==typeof r.responsePresentation&&r.responsePresentation?{responsePresentation:r.responsePresentation}:{}}}function readAgentRoutes(e){if(!Array.isArray(e))throw new Error("Runtime.spec.routing.routes must be an array");return e.map(e=>{const r=assertRecord(e,"Runtime.spec.routing.routes[]"),t=readOptionalString(r.id),o=readOptionalString(r.agentId);if(!t||!o)throw new Error("Runtime.spec.routing.routes[] requires id and agentId");const n=void 0===r.keywords?void 0:function assertStringArray(e,r){if(!Array.isArray(e))throw new Error(`${r} must be an array`);return e.map(e=>{if("string"!=typeof e||!e.trim())throw new Error(`${r} must contain non-empty strings`);return e.trim()})}(r.keywords,"Runtime.spec.routing.routes[].keywords"),i=readOptionalString(r.pattern);if(!(n&&0!==n.length||i))throw new Error("Runtime.spec.routing.routes[] requires keywords or pattern");return{id:t,agentId:o,...n&&n.length>0?{keywords:n}:{},...i?{pattern:i}:{},...readOptionalString(r.description)?{description:readOptionalString(r.description)}:{}}})}function readSpecDrivenWorkflow(t){const o=assertRecord(t,"Runtime.spec.specDrivenWorkflow"),n=r({enabled:!0===o.enabled,constitution:readOptionalString(o.constitution),artifactsDir:readOptionalString(o.artifactsDir),phases:void 0===o.phases?void 0:readSpecDrivenPhases(o.phases),..."object"==typeof o.gates&&o.gates?{gates:o.gates}:{},..."object"==typeof o.config&&o.config?{config:o.config}:{}});return e(n),n}function readSpecDrivenPhases(e){if(!Array.isArray(e))throw new Error("Runtime.spec.specDrivenWorkflow.phases must be an array");return e.map(e=>{if("string"==typeof e&&e.trim())return{id:e.trim()};const r=assertRecord(e,"Runtime.spec.specDrivenWorkflow.phases[]"),t=readOptionalString(r.id);if(!t)throw new Error("Runtime.spec.specDrivenWorkflow.phases[] requires id");return{id:t,...readOptionalString(r.artifactKind)?{artifactKind:readOptionalString(r.artifactKind)}:{},..."boolean"==typeof r.required?{required:r.required}:{},...readOptionalString(r.gate)?{gate:readOptionalString(r.gate)}:{},..."object"==typeof r.config&&r.config?{config:r.config}:{}}})}export function compileAgent(e,r){const t=assertRecord(e.spec,"Agent.spec"),o=readName(e),n=readOptionalString(t.backend);if(!n)throw new Error(`Agent ${o} requires spec.backend`);const i="object"==typeof t.config&&t.config?t.config:{},a="string"==typeof t.systemPrompt?t.systemPrompt:"string"==typeof i.systemPrompt?i.systemPrompt:void 0;return{id:o,...readDescription(e)?{description:readDescription(e)}:{},sourcePath:r,backend:n,..."string"==typeof t.modelRef&&t.modelRef.trim()?{modelRef:(s=t.modelRef,s.replace(/^[^/]+\//u,""))}:{},...void 0!==a?{systemPrompt:a}:{},tools:toStringArray(t.tools),skills:toStringArray(t.skills),memory:Array.isArray(t.memory)?t.memory:[],subagents:toStringArray(t.subagents),...void 0!==t.edges?{edges:readAgentEdges(t.edges,o)}:{},config:i};var s}export function compileModel(e){return compileModelSpec(assertRecord(e.spec,"Model.spec"),readName(e))}export function compileModelSpec(e,r){const t="string"==typeof e.name&&e.name.trim()?e.name.trim():r??"default",o=resolveValue(e.provider),n=resolveValue(e.model),i="string"==typeof o&&o.trim()?o.trim():"unknown",a="string"==typeof n&&n.trim()?n.trim():t,s={...e};return delete s.name,delete s.provider,delete s.model,{id:t,provider:i,model:a,config:Object.fromEntries(Object.entries(s).map(([e,r])=>[e,resolveValue(r)]))}}export function compileTool(e,r){const t=assertRecord(e.spec,"Tool.spec");return{id:readName(e),...r?{sourcePath:r}:{},..."string"==typeof t.description?{description:t.description}:{},...void 0!==t.schema?{schema:t.schema}:{},...void 0!==t.outputSchema?{outputSchema:t.outputSchema}:{},..."object"==typeof t.metadata&&t.metadata?{metadata:t.metadata}:{},..."string"==typeof t.implementation?{implementation:t.implementation}:{}}}export function compileMemory(e){const r=assertRecord(e.spec,"Memory.spec"),t=readName(e),o={...r};return delete o.provider,delete o.profile,delete o.mode,delete o.enabled,delete o.prompts,{id:t,provider:readOptionalString(r.provider)??"langmem",...readOptionalString(r.profile)?{profile:readOptionalString(r.profile)}:{},...readOptionalString(r.mode)?{mode:readOptionalString(r.mode)}:{},enabled:!1!==r.enabled,..."object"==typeof r.prompts&&r.prompts?{prompts:readMemoryPrompts(r.prompts)}:{},...Object.keys(o).length>0?{config:o}:{}}}function readWorkflowRouting(e){const r=assertRecord(e,"Runtime.spec.workflowRouting"),t=void 0===r.routes?void 0:function readWorkflowRoutes(e){if(!Array.isArray(e))throw new Error("Runtime.spec.workflowRouting.routes must be an array");return e.map(e=>{const r=assertRecord(e,"Runtime.spec.workflowRouting.routes[]"),t=readOptionalString(r.id),o=readOptionalString(r.workflowId);if(!t||!o)throw new Error("Runtime.spec.workflowRouting.routes[] requires id and workflowId");return{id:t,workflowId:o,...readOptionalString(r.description)?{description:readOptionalString(r.description)}:{},..."object"==typeof r.metadata&&r.metadata?{metadata:r.metadata}:{}}})}(r.routes);return{...readOptionalString(r.defaultWorkflowId)?{defaultWorkflowId:readOptionalString(r.defaultWorkflowId)}:{},...t?{routes:t}:{}}}function readAdapters(e){if(!Array.isArray(e))throw new Error("Runtime.spec.adapters must be an array");return e.map(readAdapter)}function readAgentEdges(e,r){if(!Array.isArray(e))throw new Error(`Agent ${r} spec.edges must be an array`);return e.map(e=>{const t=assertRecord(e,`Agent ${r} spec.edges[]`),o=readOptionalString(t.from),n=readOptionalString(t.to);if(!o||!n)throw new Error(`Agent ${r} spec.edges[] requires from and to`);return{from:o,to:n,...readOptionalString(t.condition)?{condition:readOptionalString(t.condition)}:{}}})}function readAdapter(e){if("string"==typeof e&&e.trim())return{name:e.trim()};const r=assertRecord(e,"Runtime.spec.adapters[]"),t=readOptionalString(r.name)??readOptionalString(r.id)??readOptionalString(r.backend);if(!t)throw new Error("Runtime.spec.adapters[] requires name");return{name:t,..."boolean"==typeof r.enabled?{enabled:r.enabled}:{},..."object"==typeof r.config&&r.config?{config:r.config}:{}}}function readMemoryPrompts(e){const r=assertRecord(e,"Memory.spec.prompts");return{...readOptionalString(r.semantic)?{semantic:readOptionalString(r.semantic)}:{},...readOptionalString(r.episodic)?{episodic:readOptionalString(r.episodic)}:{},...readOptionalString(r.procedural)?{procedural:readOptionalString(r.procedural)}:{}}}