stable-harness 0.0.125 → 0.0.126
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/node_modules/@stable-harness/adapter-deepagents/package.json +2 -2
- package/node_modules/@stable-harness/adapter-langgraph/package.json +2 -2
- package/node_modules/@stable-harness/core/dist/recovery/execution-contract.d.ts +2 -1
- package/node_modules/@stable-harness/core/dist/recovery/execution-contract.js +1 -1
- package/node_modules/@stable-harness/core/dist/recovery/raw-args.js +1 -1
- package/node_modules/@stable-harness/core/dist/runtime.js +1 -1
- package/node_modules/@stable-harness/core/package.json +3 -3
- package/node_modules/@stable-harness/governance/package.json +1 -1
- package/node_modules/@stable-harness/memory/package.json +1 -1
- package/node_modules/@stable-harness/protocols/package.json +2 -2
- package/node_modules/@stable-harness/tool-gateway/package.json +1 -1
- package/node_modules/@stable-harness/workspace-yaml/package.json +2 -2
- package/package.json +9 -9
- package/packages/adapter-deepagents/package.json +2 -2
- package/packages/adapter-langgraph/package.json +2 -2
- package/packages/cli/package.json +8 -8
- package/packages/core/dist/recovery/execution-contract.d.ts +2 -1
- package/packages/core/dist/recovery/execution-contract.js +1 -1
- package/packages/core/dist/recovery/raw-args.js +1 -1
- package/packages/core/dist/runtime.js +1 -1
- package/packages/core/package.json +3 -3
- package/packages/evaluation/package.json +2 -2
- package/packages/governance/package.json +1 -1
- package/packages/memory/package.json +1 -1
- package/packages/protocols/package.json +2 -2
- package/packages/tool-gateway/package.json +1 -1
- package/packages/workspace-yaml/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/adapter-deepagents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@langchain/node-vfs": "^0.1.4",
|
|
17
17
|
"@langchain/ollama": "^1.2.7",
|
|
18
18
|
"@langchain/openai": "^1.4.5",
|
|
19
|
-
"@stable-harness/core": "0.0.
|
|
19
|
+
"@stable-harness/core": "0.0.126",
|
|
20
20
|
"deepagents": "^1.10.1",
|
|
21
21
|
"langchain": "^1.4.0"
|
|
22
22
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/adapter-langgraph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
"types": "dist/src/index.d.ts",
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@langchain/langgraph": "^1.3.0",
|
|
15
|
-
"@stable-harness/core": "0.0.
|
|
15
|
+
"@stable-harness/core": "0.0.126"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RuntimeEvent, RuntimeRequest } from "../types.js";
|
|
1
|
+
import type { RuntimeEvent, RuntimeRequest, WorkspaceAgent } from "../types.js";
|
|
2
2
|
export declare function buildExecutionContractRecoveryRequest(input: {
|
|
3
3
|
request: RuntimeRequest;
|
|
4
4
|
events: RuntimeEvent[];
|
|
5
|
+
agent: WorkspaceAgent;
|
|
5
6
|
policy: unknown;
|
|
6
7
|
}): RuntimeRequest | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{successfulEvidenceItems as e}from"../quality/event-evidence.js";export function buildExecutionContractRecoveryRequest(
|
|
1
|
+
import{successfulEvidenceItems as e}from"../quality/event-evidence.js";export function buildExecutionContractRecoveryRequest(t){if(!0!==function readToolCallRecovery(e){if(!isRecord(e))return{};const t=isRecord(e.recovery)?e.recovery:{};return isRecord(t.toolCall)?t.toolCall:{}}(t.policy).enabled)return;const n=function lastExecutionContractFailure(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if("runtime.execution.contract.failed"===n?.type)return{reason:n.reason,missing:readStringArray(n.missingEvidenceTools)}}return{missing:[]}}(t.events);if(0===n.missing.length)return;if("missing_required_evidence_usage"===n.reason){const e=recentSuccessfulEvidence(t.events);return recoverRequest(t.request,["Stable runtime recovery: the execution contract was not satisfied.",`The final answer did not use required executed evidence from: ${n.missing.join(", ")}`,"Synthesize from those required source(s), or call them through normal structured tool calling if their evidence is unavailable.","Do not replace required evidence with unrelated intermediate evidence, progress text, or summaries from other tools.",...e.length>0?["","Prior successful tool evidence:",...e]:[]])}const r=recentSuccessfulEvidence(t.events),o=function recoveryToolTargets(t,n,r){const o=function readToolDependencies(e){return isRecord(e)?new Map(Object.entries(e).map(([e,t])=>[e,readStringArray(t)]).filter(e=>e[1].length>0)):new Map}(function readExecutionContract(e){return isRecord(e.config.executionContract)?e.config.executionContract:{}}(t).toolDependencies),i=new Set(e(r).map(e=>e.source)),s=new Set;for(const e of n)s.add(e),collectUnmetDependencies(e,o,i,s,new Set([e]));return[...s].filter(e=>t.tools.includes(e))}(t.agent,n.missing,t.events);return recoverRequest(t.request,["Stable runtime recovery: the execution contract was not satisfied.",`Required evidence tool(s) were missing: ${n.missing.join(", ")}`,`For this recovery turn, the allowed next tool call target(s) are: ${o.join(", ")}`,"Allowed targets include missing required evidence tools and any declared dependency tools that are still needed to build valid arguments.","Reuse exact values from prior successful tool evidence when building the required tool call. Do not invent replacement paths, IDs, handles, URLs, or parameters.","The next assistant action must be the backend's structured tool call for one allowed target, with no prose before it.","Do not call already completed intermediate tools unless they are listed above.","Do not produce a final answer until the required evidence tool call has executed and you have synthesized its result.","Do not print XML, JSON, markdown fences, pseudo tool-call text, plans, or future-intent text in the final answer.",...r.length>0?["","Prior successful tool evidence:",...r]:[]],{stableHarnessRequiredEvidenceTools:o})}function recoverRequest(e,t,n={}){return{...e,input:[e.input,"",...t].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call",...n}}}function collectUnmetDependencies(e,t,n,r,o){for(const i of t.get(e)??[])o.has(i)||(o.add(i),n.has(i)||r.add(i),collectUnmetDependencies(i,t,n,r,o))}function isRecord(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function readStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.length>0):[]}function recentSuccessfulEvidence(t){return e(t).slice(-5).map(e=>`- ${e.source}: ${function previewEvidence(e){const t=e.replace(/\s+/gu," ").trim();return t.length>1500?`${t.slice(0,1497)}...`:t}(e.output)}`)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{selectCallCandidateByArgsSchema as e}from"@easynet/better-call";export function buildRawArgsRecoveryRequest(e){if(!toolCallRecoveryEnabled(e.policy))return;const t=matchUniqueRawArgsTool(e);return t?function buildRawArgsRecoveryPrompt(e,t){return{...e,input:[e.input,"","Stable runtime recovery: your previous final answer was a JSON argument object for a declared tool, not the final answer.",`Matched configured tool: ${t.toolId}`,"Continue the same user request by calling that tool through the backend's normal structured tool-calling mechanism with the JSON arguments below.","If the tool call succeeds, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Previous JSON arguments:",JSON.stringify(t.args)].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call"}}}(e.request,t):void 0}export function buildRawArgsToolEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer repeated a JSON argument object for a declared tool after a structured tool-call recovery request.",`Matched configured tool: ${e.match.toolId}`,"Stable runtime executed that matched declared tool through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Executed JSON arguments:",JSON.stringify(e.match.args),"","Executed tool output:",e.toolOutput].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function hasUniqueRawArgsTool(e){return toolCallRecoveryEnabled(e.policy)&&Boolean(matchUniqueRawArgsTool(e))}export function buildRawArgsToolSequenceEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer printed multiple JSON argument objects for declared tools after a recovery request.","Stable runtime matched and executed those declared tools through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","",...e.evidences.flatMap((e,t)=>[`Executed tool ${t+1}: ${e.match.toolId}`,"Executed JSON arguments:",JSON.stringify(e.match.args),"Executed tool output:",e.toolOutput,""])].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function matchUniqueRawArgsTool(t){const
|
|
1
|
+
import{selectCallCandidateByArgsSchema as e}from"@easynet/better-call";export function buildRawArgsRecoveryRequest(e){if(!toolCallRecoveryEnabled(e.policy))return;const t=matchUniqueRawArgsTool(e);return t?function buildRawArgsRecoveryPrompt(e,t){return{...e,input:[e.input,"","Stable runtime recovery: your previous final answer was a JSON argument object for a declared tool, not the final answer.",`Matched configured tool: ${t.toolId}`,"Continue the same user request by calling that tool through the backend's normal structured tool-calling mechanism with the JSON arguments below.","If the tool call succeeds, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Previous JSON arguments:",JSON.stringify(t.args)].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call"}}}(e.request,t):void 0}export function buildRawArgsToolEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer repeated a JSON argument object for a declared tool after a structured tool-call recovery request.",`Matched configured tool: ${e.match.toolId}`,"Stable runtime executed that matched declared tool through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Executed JSON arguments:",JSON.stringify(e.match.args),"","Executed tool output:",e.toolOutput].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function hasUniqueRawArgsTool(e){return toolCallRecoveryEnabled(e.policy)&&Boolean(matchUniqueRawArgsTool(e))}export function buildRawArgsToolSequenceEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer printed multiple JSON argument objects for declared tools after a recovery request.","Stable runtime matched and executed those declared tools through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","",...e.evidences.flatMap((e,t)=>[`Executed tool ${t+1}: ${e.match.toolId}`,"Executed JSON arguments:",JSON.stringify(e.match.args),"Executed tool output:",e.toolOutput,""])].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function matchUniqueRawArgsTool(t){const o=parseStandaloneJsonValues(t.output,{allowArray:!1})[0];if(!o)return;const r=matchToolEnvelope(o,t);if(r)return r;const n=isRawArgsRecord(o)?o:void 0;if(!n)return;const a=e({args:n,candidates:buildCallCandidates(t)});if(a.ok)return{toolId:a.candidateId,args:a.args};const s=function latestSingleToolCandidate(e,t){for(let o=(e?.length??0)-1;o>=0;o-=1){const r=e[o];if(!r||!("diagnostics"in r)||!isRecord(r.diagnostics))continue;const n=readStringArray(r.diagnostics.toolCandidateIds).filter(e=>t.has(e));if(1===n.length)return n[0];if(n.length>1)return}}(t.events,new Set(candidateToolIds(t)));return s?{toolId:s,args:n}:void 0}export function matchRawArgsToolSequence(t){if(!toolCallRecoveryEnabled(t.policy))return[];const o=parseStandaloneJsonValues(t.output,{allowArray:!0});if(o.length<2)return[];const r=buildCallCandidates(t),n=[];for(const a of o){const o=matchToolEnvelope(a,t);if(o){n.push(o);continue}if(!isRawArgsRecord(a))return[];const s=e({args:a,candidates:r});if(!s.ok)return[];n.push({toolId:s.candidateId,args:s.args})}return n}function buildCallCandidates(e){return candidateToolIds(e).map(t=>({id:t,schema:e.workspace.tools.get(t)?.schema??e.toolGateway?.get(t)?.schema}))}function candidateToolIds(e){const t=new Set(e.agent.tools),o=(e.candidateToolIds??[]).filter(e=>t.has(e));return o.length>0?o:e.agent.tools}function parseStandaloneJsonValues(e,t){const o=e.trim(),r=o.match(/^```(?:json)?\s*\n([\s\S]*?)\n```$/iu)?.[1]?.trim(),n=r??o;if(n.length>6e3)return[];if(!(t.allowArray||n.startsWith("{")&&n.endsWith("}")))return[];if(t.allowArray&&!(n.startsWith("{")&&n.endsWith("}")||n.startsWith("[")&&n.endsWith("]")))return[];try{const e=JSON.parse(n);return Array.isArray(e)&&t.allowArray?e:[e]}catch{return[]}}function matchToolEnvelope(e,t){if(!isRecord(e))return;const o=function readEnvelopeToolId(e){const t=["toolId","toolName","tool","tool_name","name"].map(t=>e[t]).filter(e=>"string"==typeof e&&e.length>0);return 1===new Set(t).size?t[0]:void 0}(e),r=function readEnvelopeArgs(e){for(const t of["args","arguments","parameters","params","kwargs"]){const o=e[t];if(isRecord(o))return o}}(e),n=candidateToolIds(t);return o&&r&&n.includes(o)?{toolId:o,args:r}:void 0}function isRawArgsRecord(e){return isRecord(e)&&!function isToolCallEnvelope(e){const t=["tool","tool_name","name","type","subagent_type"].some(t=>"string"==typeof e[t]),o=["args","arguments","parameters","kwargs"].some(t=>t in e);return t&&o}(e)&&!function isRuntimeControlObject(e){return"string"==typeof e.status||"string"==typeof e.error||"string"==typeof e.controlStatus}(e)}function toolCallRecoveryEnabled(e){return!!(isRecord(e)&&isRecord(e.recovery)&&isRecord(e.recovery.toolCall))&&!0===e.recovery.toolCall.enabled}function readStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.length>0):[]}function isRecord(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{buildExecutionContractRecoveryRequest as r}from"./recovery/execution-contract.js";import{buildAdapterErrorRecoveryPrompt as a,isRecoverableAdapterError as o}from"./recovery/tool-call.js";import{recoverQualityReview as
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{buildExecutionContractRecoveryRequest as r}from"./recovery/execution-contract.js";import{buildAdapterErrorRecoveryPrompt as a,isRecoverableAdapterError as o}from"./recovery/tool-call.js";import{recoverQualityReview as n,resolveQualityPolicy as s}from"./quality/index.js";import{recoverAdapterResultOutput as i}from"./runtime/recovery/adapter-result.js";import{completeRun as u,failRun as c}from"./runtime/completion.js";import{createRuntimeAdministrationMethods as p}from"./runtime/admin/administration.js";import{runDirectToolCall as m}from"./runtime/direct-tool-call.js";import{createApprovalGatedToolGateway as d}from"./runtime/governance/approval-gate.js";import{createSandboxedToolGateway as l}from"./runtime/governance/sandbox.js";import{createRuntimeImprovementAdministration as w}from"./runtime/improvement/admin.js";import{createRuntimeEvidenceAdministration as g}from"./runtime/improvement/evidence-admin.js";import{createInMemoryRuntimeImprovementStore as y}from"./runtime/improvement/store.js";import{createRuntimeInspectionMethods as I}from"./runtime/inspection/methods.js";import{createRuntimeCapabilityRegistry as f,normalizeAdapterResult as q}from"./runtime/capabilities.js";import{createMemoryRuntimeCapability as v}from"./runtime/memory.js";import{resolveToolCallRecoveryPolicy as R}from"./runtime/recovery/tool-call-policy.js";import{createRuntimeMemoryAdministration as k}from"./runtime/admin/memory.js";import{createInMemoryRuntimeStore as A}from"./runtime/persistence/stores.js";import{createProgressNarrationCapability as b}from"./runtime/progress-narration.js";import{repairRuntimeSelection as C}from"./runtime/selection-repair.js";import{createLangSmithTracingCapability as j}from"./runtime/tracing/langsmith.js";import{createToolFailureTracker as x}from"./runtime/tool-failure.js";import{runWorkflowRequest as E}from"./workflows/runtime.js";export function createStableHarnessRuntime(t){const q=new Set,G=t.store??A(),S=t.improvements??y(),T=f([v(t),b({options:t.progressNarration,policy:t.workspace.runtime}),j({policy:t.workspace.runtime,store:G,options:t.langSmithTracing}),...t.capabilities??[]]),emitBase=t=>{const r=function enrichRuntimeEvent(t){return{...t,eventId:t.eventId??e(),emittedAt:t.emittedAt??(new Date).toISOString()}}(t);G.appendEvent(r);for(const e of q)e(r)},emit=e=>{emitBase(e),T.emitSideEffects(e,emitBase)},h=l({gateway:d({gateway:t.toolGateway,approvals:t.approvals,workspace:t.workspace,emit:emit}),workspace:t.workspace,sandbox:t.sandbox,emit:emit}),M={...t,toolGateway:h},O=x(function readToolFailurePolicy(e){if("object"!=typeof e||null===e||Array.isArray(e))return;const t=e.failurePolicy;return"object"!=typeof t||null===t||Array.isArray(t)?void 0:t}(t.workspace.runtime.toolGateway));return{request:async t=>async function runRuntimeRequest(t){const p=t.request.requestId??e(),d=t.request.sessionId??e(),l=[],{agent:w,adapter:g}=await async function resolveExecution(e,t,r){const a=t.agentId?await async function resolveRequestedAgentId(e,t,r){if(e.agents.has(t))return t;const a=await C({id:t,candidates:[...e.agents.values()].map(e=>({id:e.id,description:e.description})),trace:{...r,agentId:t,layer:"agent",owner:"stable_runtime_policy"}});return a.ok?a.id:t}(e.workspace,t.agentId,r):e.workspace.runtime.defaultAgentId,o=e.workspace.agents.get(a);if(!o)throw new Error(`Agent ${a} is not defined in the workspace`);if(t.toolCall||t.workflow)return{agent:o,adapter:void 0};const n=e.adapters.find(e=>e.canRun(o));if(!n)throw new Error(`No runtime adapter can run backend ${o.backend} for agent ${o.id}`);return{agent:o,adapter:n}}(t.input,t.request,{requestId:p,sessionId:d,emit:e=>l.push(e)});t.store.createRun(function createRunRecord(e,t,r,a){return{requestId:t,sessionId:r,agentId:a.id,input:e.input,state:"running",parentRunId:e.parentRunId,metadata:e.metadata,artifacts:[],startedAt:(new Date).toISOString(),events:[]}}(t.request,p,d,w)),l.forEach(t.emit),t.emit({type:"runtime.request.started",requestId:p,sessionId:d,agentId:w.id,input:t.request.input});try{if(t.request.workflow){const e=await E({workspace:t.input.workspace,adapters:t.input.workflowAdapters??[],toolGateway:t.input.toolGateway,request:{input:t.request.input,...t.request.workflow},requestId:p,sessionId:d,agentId:w.id,emit:t.emit});return u({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,result:e,artifacts:t.input.artifacts})}if(t.request.toolCall){const e=await m({gateway:t.input.toolGateway,workspace:t.input.workspace,emit:t.emit,request:t.request,requestId:p,sessionId:d,agent:w,toolFailureTracker:t.toolFailureTracker,toolGuardrails:t.input.toolGuardrails,events:t.store.getRun(p)?.events??[]});return u({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,result:e,artifacts:t.input.artifacts})}return await async function runAdapterRequest(e){if(!e.adapter)throw new Error(`No runtime adapter can run backend ${e.agent.backend} for agent ${e.agent.id}`);const t=e.adapter,c=await e.capabilities.beforeAdapterRun(createCapabilityContext(e)),p=c.memory,m=c.pluginMemories??[],d=R({workspace:e.input.workspace,agent:e.agent}),l=s(e.input.workspace.runtime,e.agent),w=new Map;let g;try{g=await runAdapterOnce(e,t,e.request,p,m,w,d)}catch(r){if(!o(r,d))throw r;e.emit(repairStarted(e,"adapter_error",1,errorMessage(r))),g=await runAdapterOnce(e,t,a(e.request,r,d),p,m,w,d),e.emit(repairCompleted(e,"adapter_error","retried",1,errorMessage(r)))}g=await i({...e,request:e.request,result:g,recoveryPolicy:d,workspace:e.input.workspace,toolGateway:e.input.toolGateway,runAdapter:r=>runAdapterOnce(e,t,r,p,m,w,d),runRecoveredToolCall:(t,r)=>runRecoveredToolCall(e,t,r)}),g=await n(createQualityRuntimeInput(e,p,m,w,d),e.request,g,l),await e.capabilities.beforeAdapterResultContract({...createCapabilityContext(e),result:g});try{assertRequestExecutionContract(e,g)}catch(a){const o=r({request:e.request,events:e.store.getRun(e.requestId)?.events??[],agent:e.agent,policy:d});if(!o)throw a;e.emit(repairStarted(e,"execution_contract",1,errorMessage(a))),g=await runAdapterOnce(e,t,o,p,m,w,d),g=await i({...e,request:o,result:g,recoveryPolicy:d,workspace:e.input.workspace,toolGateway:e.input.toolGateway,runAdapter:r=>runAdapterOnce(e,t,r,p,m,w,d),runRecoveredToolCall:(t,r)=>runRecoveredToolCall(e,t,r)}),g=await n(createQualityRuntimeInput(e,p,m,w,d),o,g,l),assertRequestExecutionContract(e,g),e.emit(repairCompleted(e,"execution_contract","retried",1,errorMessage(a)))}const y=u({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,result:g,artifacts:e.input.artifacts});return await e.capabilities.afterAdapterResponse({...createCapabilityContext(e),result:g,response:y}),y}({...t,adapter:g,requestId:p,sessionId:d,agent:w})}catch(e){return c({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,error:e})}}({input:M,capabilities:T,store:G,emit:emit,request:t,toolFailureTracker:O}),subscribe:e=>(q.add(e),()=>q.delete(e)),...I({workspace:t.workspace,store:G,artifacts:t.artifacts,approvals:t.approvals,emit:emit}),...p({store:G,emit:emit}),...w({runtimeStore:G,store:S,emit:emit}),...g({runtimeStore:G,emit:emit}),...k({memory:t.memory}),cancel(e,t){const r=G.getRun(e);r&&"running"===r.state&&(G.updateRun(e,{state:"cancelled",completedAt:(new Date).toISOString()}),emit({type:"runtime.request.cancelled",requestId:e,sessionId:r.sessionId,agentId:r.agentId,reason:t}))},async stop(){await T.stop(),q.clear()}}}function runRecoveredToolCall(e,t,r){return m({gateway:e.input.toolGateway,workspace:e.input.workspace,emit:e.emit,request:{...e.request,toolCall:{toolId:t,args:r}},requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,toolFailureTracker:e.input.toolFailureTracker,toolGuardrails:e.input.toolGuardrails,events:e.store.getRun(e.requestId)?.events??[]})}function createCapabilityContext(e){return{workspace:e.input.workspace,store:e.store,emit:e.emit,request:e.request,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent}}function createQualityRuntimeInput(e,t,r,a,o){return{workspace:e.input.workspace,agent:e.agent,request:e.request,requestId:e.requestId,sessionId:e.sessionId,events:e.store.getRun(e.requestId)?.events??[],emit:e.emit,getEvents:()=>e.store.getRun(e.requestId)?.events??[],runAdapter:n=>runAdapterOnce(e,e.adapter,n,t,r,a,o),reviewModel:e.input.qualityReviewModel,executionEvaluatorRules:e.input.executionEvaluatorRules,memory:t,pluginMemories:r}}function assertRequestExecutionContract(e,r){t({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,output:r.text,metadata:e.request.metadata})}async function runAdapterOnce(e,t,r,a,o,n,s){return q(await t.run({workspace:{...e.input.workspace,runtime:s},agent:e.agent,request:r,requestId:e.requestId,sessionId:e.sessionId,memory:a,pluginMemories:o,toolGateway:e.input.toolGateway,toolFailureTracker:e.input.toolFailureTracker,toolGuardrails:e.input.toolGuardrails,executionEvaluatorRules:e.input.executionEvaluatorRules,requestState:n,getEvents:()=>e.store.getRun(e.requestId)?.events??[],emit:e.emit}))}function repairStarted(e,t,r,a){return{type:"runtime.repair.started",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agent.id,layer:t,attempt:r,reason:a}}function repairCompleted(e,t,r,a,o){return{type:"runtime.repair.completed",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agent.id,layer:t,outcome:r,attempt:a,reason:o}}function errorMessage(e){return e instanceof Error?e.message:String(e)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
".": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@stable-harness/governance": "0.0.
|
|
16
|
-
"@stable-harness/memory": "0.0.
|
|
15
|
+
"@stable-harness/governance": "0.0.126",
|
|
16
|
+
"@stable-harness/memory": "0.0.126"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/protocols",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"main": "dist/src/index.js",
|
|
12
12
|
"types": "dist/src/index.d.ts",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@stable-harness/core": "0.0.
|
|
14
|
+
"@stable-harness/core": "0.0.126"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/workspace-yaml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
".": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@stable-harness/core": "0.0.
|
|
15
|
+
"@stable-harness/core": "0.0.126"
|
|
16
16
|
}
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stable-harness",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Stable application runtime and operator control plane for agent workspaces.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -82,14 +82,14 @@
|
|
|
82
82
|
"@langchain/node-vfs": "^0.1.4",
|
|
83
83
|
"@langchain/ollama": "^1.2.7",
|
|
84
84
|
"@langchain/openai": "^1.4.5",
|
|
85
|
-
"@stable-harness/adapter-deepagents": "0.0.
|
|
86
|
-
"@stable-harness/adapter-langgraph": "0.0.
|
|
87
|
-
"@stable-harness/core": "0.0.
|
|
88
|
-
"@stable-harness/governance": "0.0.
|
|
89
|
-
"@stable-harness/memory": "0.0.
|
|
90
|
-
"@stable-harness/protocols": "0.0.
|
|
91
|
-
"@stable-harness/tool-gateway": "0.0.
|
|
92
|
-
"@stable-harness/workspace-yaml": "0.0.
|
|
85
|
+
"@stable-harness/adapter-deepagents": "0.0.126",
|
|
86
|
+
"@stable-harness/adapter-langgraph": "0.0.126",
|
|
87
|
+
"@stable-harness/core": "0.0.126",
|
|
88
|
+
"@stable-harness/governance": "0.0.126",
|
|
89
|
+
"@stable-harness/memory": "0.0.126",
|
|
90
|
+
"@stable-harness/protocols": "0.0.126",
|
|
91
|
+
"@stable-harness/tool-gateway": "0.0.126",
|
|
92
|
+
"@stable-harness/workspace-yaml": "0.0.126",
|
|
93
93
|
"deepagents": "^1.10.1",
|
|
94
94
|
"langchain": "^1.4.0",
|
|
95
95
|
"yaml": "^2.8.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/adapter-deepagents",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@langchain/node-vfs": "^0.1.4",
|
|
17
17
|
"@langchain/ollama": "^1.2.7",
|
|
18
18
|
"@langchain/openai": "^1.4.5",
|
|
19
|
-
"@stable-harness/core": "0.0.
|
|
19
|
+
"@stable-harness/core": "0.0.126",
|
|
20
20
|
"deepagents": "^1.10.1",
|
|
21
21
|
"langchain": "^1.4.0"
|
|
22
22
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/adapter-langgraph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
"types": "dist/src/index.d.ts",
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@langchain/langgraph": "^1.3.0",
|
|
15
|
-
"@stable-harness/core": "0.0.
|
|
15
|
+
"@stable-harness/core": "0.0.126"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"types": "dist/src/index.d.ts",
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@langchain/langgraph-api": "^1.2.1",
|
|
18
|
-
"@stable-harness/adapter-deepagents": "0.0.
|
|
19
|
-
"@stable-harness/adapter-langgraph": "0.0.
|
|
20
|
-
"@stable-harness/core": "0.0.
|
|
21
|
-
"@stable-harness/memory": "0.0.
|
|
22
|
-
"@stable-harness/protocols": "0.0.
|
|
23
|
-
"@stable-harness/tool-gateway": "0.0.
|
|
24
|
-
"@stable-harness/workspace-yaml": "0.0.
|
|
18
|
+
"@stable-harness/adapter-deepagents": "0.0.126",
|
|
19
|
+
"@stable-harness/adapter-langgraph": "0.0.126",
|
|
20
|
+
"@stable-harness/core": "0.0.126",
|
|
21
|
+
"@stable-harness/memory": "0.0.126",
|
|
22
|
+
"@stable-harness/protocols": "0.0.126",
|
|
23
|
+
"@stable-harness/tool-gateway": "0.0.126",
|
|
24
|
+
"@stable-harness/workspace-yaml": "0.0.126"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { RuntimeEvent, RuntimeRequest } from "../types.js";
|
|
1
|
+
import type { RuntimeEvent, RuntimeRequest, WorkspaceAgent } from "../types.js";
|
|
2
2
|
export declare function buildExecutionContractRecoveryRequest(input: {
|
|
3
3
|
request: RuntimeRequest;
|
|
4
4
|
events: RuntimeEvent[];
|
|
5
|
+
agent: WorkspaceAgent;
|
|
5
6
|
policy: unknown;
|
|
6
7
|
}): RuntimeRequest | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{successfulEvidenceItems as e}from"../quality/event-evidence.js";export function buildExecutionContractRecoveryRequest(
|
|
1
|
+
import{successfulEvidenceItems as e}from"../quality/event-evidence.js";export function buildExecutionContractRecoveryRequest(t){if(!0!==function readToolCallRecovery(e){if(!isRecord(e))return{};const t=isRecord(e.recovery)?e.recovery:{};return isRecord(t.toolCall)?t.toolCall:{}}(t.policy).enabled)return;const n=function lastExecutionContractFailure(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if("runtime.execution.contract.failed"===n?.type)return{reason:n.reason,missing:readStringArray(n.missingEvidenceTools)}}return{missing:[]}}(t.events);if(0===n.missing.length)return;if("missing_required_evidence_usage"===n.reason){const e=recentSuccessfulEvidence(t.events);return recoverRequest(t.request,["Stable runtime recovery: the execution contract was not satisfied.",`The final answer did not use required executed evidence from: ${n.missing.join(", ")}`,"Synthesize from those required source(s), or call them through normal structured tool calling if their evidence is unavailable.","Do not replace required evidence with unrelated intermediate evidence, progress text, or summaries from other tools.",...e.length>0?["","Prior successful tool evidence:",...e]:[]])}const r=recentSuccessfulEvidence(t.events),o=function recoveryToolTargets(t,n,r){const o=function readToolDependencies(e){return isRecord(e)?new Map(Object.entries(e).map(([e,t])=>[e,readStringArray(t)]).filter(e=>e[1].length>0)):new Map}(function readExecutionContract(e){return isRecord(e.config.executionContract)?e.config.executionContract:{}}(t).toolDependencies),i=new Set(e(r).map(e=>e.source)),s=new Set;for(const e of n)s.add(e),collectUnmetDependencies(e,o,i,s,new Set([e]));return[...s].filter(e=>t.tools.includes(e))}(t.agent,n.missing,t.events);return recoverRequest(t.request,["Stable runtime recovery: the execution contract was not satisfied.",`Required evidence tool(s) were missing: ${n.missing.join(", ")}`,`For this recovery turn, the allowed next tool call target(s) are: ${o.join(", ")}`,"Allowed targets include missing required evidence tools and any declared dependency tools that are still needed to build valid arguments.","Reuse exact values from prior successful tool evidence when building the required tool call. Do not invent replacement paths, IDs, handles, URLs, or parameters.","The next assistant action must be the backend's structured tool call for one allowed target, with no prose before it.","Do not call already completed intermediate tools unless they are listed above.","Do not produce a final answer until the required evidence tool call has executed and you have synthesized its result.","Do not print XML, JSON, markdown fences, pseudo tool-call text, plans, or future-intent text in the final answer.",...r.length>0?["","Prior successful tool evidence:",...r]:[]],{stableHarnessRequiredEvidenceTools:o})}function recoverRequest(e,t,n={}){return{...e,input:[e.input,"",...t].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call",...n}}}function collectUnmetDependencies(e,t,n,r,o){for(const i of t.get(e)??[])o.has(i)||(o.add(i),n.has(i)||r.add(i),collectUnmetDependencies(i,t,n,r,o))}function isRecord(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function readStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.length>0):[]}function recentSuccessfulEvidence(t){return e(t).slice(-5).map(e=>`- ${e.source}: ${function previewEvidence(e){const t=e.replace(/\s+/gu," ").trim();return t.length>1500?`${t.slice(0,1497)}...`:t}(e.output)}`)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{selectCallCandidateByArgsSchema as e}from"@easynet/better-call";export function buildRawArgsRecoveryRequest(e){if(!toolCallRecoveryEnabled(e.policy))return;const t=matchUniqueRawArgsTool(e);return t?function buildRawArgsRecoveryPrompt(e,t){return{...e,input:[e.input,"","Stable runtime recovery: your previous final answer was a JSON argument object for a declared tool, not the final answer.",`Matched configured tool: ${t.toolId}`,"Continue the same user request by calling that tool through the backend's normal structured tool-calling mechanism with the JSON arguments below.","If the tool call succeeds, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Previous JSON arguments:",JSON.stringify(t.args)].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call"}}}(e.request,t):void 0}export function buildRawArgsToolEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer repeated a JSON argument object for a declared tool after a structured tool-call recovery request.",`Matched configured tool: ${e.match.toolId}`,"Stable runtime executed that matched declared tool through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Executed JSON arguments:",JSON.stringify(e.match.args),"","Executed tool output:",e.toolOutput].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function hasUniqueRawArgsTool(e){return toolCallRecoveryEnabled(e.policy)&&Boolean(matchUniqueRawArgsTool(e))}export function buildRawArgsToolSequenceEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer printed multiple JSON argument objects for declared tools after a recovery request.","Stable runtime matched and executed those declared tools through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","",...e.evidences.flatMap((e,t)=>[`Executed tool ${t+1}: ${e.match.toolId}`,"Executed JSON arguments:",JSON.stringify(e.match.args),"Executed tool output:",e.toolOutput,""])].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function matchUniqueRawArgsTool(t){const
|
|
1
|
+
import{selectCallCandidateByArgsSchema as e}from"@easynet/better-call";export function buildRawArgsRecoveryRequest(e){if(!toolCallRecoveryEnabled(e.policy))return;const t=matchUniqueRawArgsTool(e);return t?function buildRawArgsRecoveryPrompt(e,t){return{...e,input:[e.input,"","Stable runtime recovery: your previous final answer was a JSON argument object for a declared tool, not the final answer.",`Matched configured tool: ${t.toolId}`,"Continue the same user request by calling that tool through the backend's normal structured tool-calling mechanism with the JSON arguments below.","If the tool call succeeds, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Previous JSON arguments:",JSON.stringify(t.args)].join("\n"),metadata:{...e.metadata,stableHarnessRecovery:"tool_call"}}}(e.request,t):void 0}export function buildRawArgsToolEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer repeated a JSON argument object for a declared tool after a structured tool-call recovery request.",`Matched configured tool: ${e.match.toolId}`,"Stable runtime executed that matched declared tool through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","","Executed JSON arguments:",JSON.stringify(e.match.args),"","Executed tool output:",e.toolOutput].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function hasUniqueRawArgsTool(e){return toolCallRecoveryEnabled(e.policy)&&Boolean(matchUniqueRawArgsTool(e))}export function buildRawArgsToolSequenceEvidenceRecoveryRequest(e){return{...e.request,input:[e.request.input,"","Stable runtime recovery: your previous final answer printed multiple JSON argument objects for declared tools after a recovery request.","Stable runtime matched and executed those declared tools through the governed tool gateway.","Continue the same user request from the executed evidence below.","If another declared tool is needed, call it through the backend's normal structured tool-calling mechanism.","Otherwise, synthesize the final user-facing answer from the executed evidence.","Do not print JSON argument objects, raw tool-call markup, plans, or future-intent text as the final answer.","",...e.evidences.flatMap((e,t)=>[`Executed tool ${t+1}: ${e.match.toolId}`,"Executed JSON arguments:",JSON.stringify(e.match.args),"Executed tool output:",e.toolOutput,""])].join("\n"),metadata:{...e.request.metadata,stableHarnessRecovery:"tool_call"}}}export function matchUniqueRawArgsTool(t){const o=parseStandaloneJsonValues(t.output,{allowArray:!1})[0];if(!o)return;const r=matchToolEnvelope(o,t);if(r)return r;const n=isRawArgsRecord(o)?o:void 0;if(!n)return;const a=e({args:n,candidates:buildCallCandidates(t)});if(a.ok)return{toolId:a.candidateId,args:a.args};const s=function latestSingleToolCandidate(e,t){for(let o=(e?.length??0)-1;o>=0;o-=1){const r=e[o];if(!r||!("diagnostics"in r)||!isRecord(r.diagnostics))continue;const n=readStringArray(r.diagnostics.toolCandidateIds).filter(e=>t.has(e));if(1===n.length)return n[0];if(n.length>1)return}}(t.events,new Set(candidateToolIds(t)));return s?{toolId:s,args:n}:void 0}export function matchRawArgsToolSequence(t){if(!toolCallRecoveryEnabled(t.policy))return[];const o=parseStandaloneJsonValues(t.output,{allowArray:!0});if(o.length<2)return[];const r=buildCallCandidates(t),n=[];for(const a of o){const o=matchToolEnvelope(a,t);if(o){n.push(o);continue}if(!isRawArgsRecord(a))return[];const s=e({args:a,candidates:r});if(!s.ok)return[];n.push({toolId:s.candidateId,args:s.args})}return n}function buildCallCandidates(e){return candidateToolIds(e).map(t=>({id:t,schema:e.workspace.tools.get(t)?.schema??e.toolGateway?.get(t)?.schema}))}function candidateToolIds(e){const t=new Set(e.agent.tools),o=(e.candidateToolIds??[]).filter(e=>t.has(e));return o.length>0?o:e.agent.tools}function parseStandaloneJsonValues(e,t){const o=e.trim(),r=o.match(/^```(?:json)?\s*\n([\s\S]*?)\n```$/iu)?.[1]?.trim(),n=r??o;if(n.length>6e3)return[];if(!(t.allowArray||n.startsWith("{")&&n.endsWith("}")))return[];if(t.allowArray&&!(n.startsWith("{")&&n.endsWith("}")||n.startsWith("[")&&n.endsWith("]")))return[];try{const e=JSON.parse(n);return Array.isArray(e)&&t.allowArray?e:[e]}catch{return[]}}function matchToolEnvelope(e,t){if(!isRecord(e))return;const o=function readEnvelopeToolId(e){const t=["toolId","toolName","tool","tool_name","name"].map(t=>e[t]).filter(e=>"string"==typeof e&&e.length>0);return 1===new Set(t).size?t[0]:void 0}(e),r=function readEnvelopeArgs(e){for(const t of["args","arguments","parameters","params","kwargs"]){const o=e[t];if(isRecord(o))return o}}(e),n=candidateToolIds(t);return o&&r&&n.includes(o)?{toolId:o,args:r}:void 0}function isRawArgsRecord(e){return isRecord(e)&&!function isToolCallEnvelope(e){const t=["tool","tool_name","name","type","subagent_type"].some(t=>"string"==typeof e[t]),o=["args","arguments","parameters","kwargs"].some(t=>t in e);return t&&o}(e)&&!function isRuntimeControlObject(e){return"string"==typeof e.status||"string"==typeof e.error||"string"==typeof e.controlStatus}(e)}function toolCallRecoveryEnabled(e){return!!(isRecord(e)&&isRecord(e.recovery)&&isRecord(e.recovery.toolCall))&&!0===e.recovery.toolCall.enabled}function readStringArray(e){return Array.isArray(e)?e.filter(e=>"string"==typeof e&&e.length>0):[]}function isRecord(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{buildExecutionContractRecoveryRequest as r}from"./recovery/execution-contract.js";import{buildAdapterErrorRecoveryPrompt as a,isRecoverableAdapterError as o}from"./recovery/tool-call.js";import{recoverQualityReview as
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{buildExecutionContractRecoveryRequest as r}from"./recovery/execution-contract.js";import{buildAdapterErrorRecoveryPrompt as a,isRecoverableAdapterError as o}from"./recovery/tool-call.js";import{recoverQualityReview as n,resolveQualityPolicy as s}from"./quality/index.js";import{recoverAdapterResultOutput as i}from"./runtime/recovery/adapter-result.js";import{completeRun as u,failRun as c}from"./runtime/completion.js";import{createRuntimeAdministrationMethods as p}from"./runtime/admin/administration.js";import{runDirectToolCall as m}from"./runtime/direct-tool-call.js";import{createApprovalGatedToolGateway as d}from"./runtime/governance/approval-gate.js";import{createSandboxedToolGateway as l}from"./runtime/governance/sandbox.js";import{createRuntimeImprovementAdministration as w}from"./runtime/improvement/admin.js";import{createRuntimeEvidenceAdministration as g}from"./runtime/improvement/evidence-admin.js";import{createInMemoryRuntimeImprovementStore as y}from"./runtime/improvement/store.js";import{createRuntimeInspectionMethods as I}from"./runtime/inspection/methods.js";import{createRuntimeCapabilityRegistry as f,normalizeAdapterResult as q}from"./runtime/capabilities.js";import{createMemoryRuntimeCapability as v}from"./runtime/memory.js";import{resolveToolCallRecoveryPolicy as R}from"./runtime/recovery/tool-call-policy.js";import{createRuntimeMemoryAdministration as k}from"./runtime/admin/memory.js";import{createInMemoryRuntimeStore as A}from"./runtime/persistence/stores.js";import{createProgressNarrationCapability as b}from"./runtime/progress-narration.js";import{repairRuntimeSelection as C}from"./runtime/selection-repair.js";import{createLangSmithTracingCapability as j}from"./runtime/tracing/langsmith.js";import{createToolFailureTracker as x}from"./runtime/tool-failure.js";import{runWorkflowRequest as E}from"./workflows/runtime.js";export function createStableHarnessRuntime(t){const q=new Set,G=t.store??A(),S=t.improvements??y(),T=f([v(t),b({options:t.progressNarration,policy:t.workspace.runtime}),j({policy:t.workspace.runtime,store:G,options:t.langSmithTracing}),...t.capabilities??[]]),emitBase=t=>{const r=function enrichRuntimeEvent(t){return{...t,eventId:t.eventId??e(),emittedAt:t.emittedAt??(new Date).toISOString()}}(t);G.appendEvent(r);for(const e of q)e(r)},emit=e=>{emitBase(e),T.emitSideEffects(e,emitBase)},h=l({gateway:d({gateway:t.toolGateway,approvals:t.approvals,workspace:t.workspace,emit:emit}),workspace:t.workspace,sandbox:t.sandbox,emit:emit}),M={...t,toolGateway:h},O=x(function readToolFailurePolicy(e){if("object"!=typeof e||null===e||Array.isArray(e))return;const t=e.failurePolicy;return"object"!=typeof t||null===t||Array.isArray(t)?void 0:t}(t.workspace.runtime.toolGateway));return{request:async t=>async function runRuntimeRequest(t){const p=t.request.requestId??e(),d=t.request.sessionId??e(),l=[],{agent:w,adapter:g}=await async function resolveExecution(e,t,r){const a=t.agentId?await async function resolveRequestedAgentId(e,t,r){if(e.agents.has(t))return t;const a=await C({id:t,candidates:[...e.agents.values()].map(e=>({id:e.id,description:e.description})),trace:{...r,agentId:t,layer:"agent",owner:"stable_runtime_policy"}});return a.ok?a.id:t}(e.workspace,t.agentId,r):e.workspace.runtime.defaultAgentId,o=e.workspace.agents.get(a);if(!o)throw new Error(`Agent ${a} is not defined in the workspace`);if(t.toolCall||t.workflow)return{agent:o,adapter:void 0};const n=e.adapters.find(e=>e.canRun(o));if(!n)throw new Error(`No runtime adapter can run backend ${o.backend} for agent ${o.id}`);return{agent:o,adapter:n}}(t.input,t.request,{requestId:p,sessionId:d,emit:e=>l.push(e)});t.store.createRun(function createRunRecord(e,t,r,a){return{requestId:t,sessionId:r,agentId:a.id,input:e.input,state:"running",parentRunId:e.parentRunId,metadata:e.metadata,artifacts:[],startedAt:(new Date).toISOString(),events:[]}}(t.request,p,d,w)),l.forEach(t.emit),t.emit({type:"runtime.request.started",requestId:p,sessionId:d,agentId:w.id,input:t.request.input});try{if(t.request.workflow){const e=await E({workspace:t.input.workspace,adapters:t.input.workflowAdapters??[],toolGateway:t.input.toolGateway,request:{input:t.request.input,...t.request.workflow},requestId:p,sessionId:d,agentId:w.id,emit:t.emit});return u({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,result:e,artifacts:t.input.artifacts})}if(t.request.toolCall){const e=await m({gateway:t.input.toolGateway,workspace:t.input.workspace,emit:t.emit,request:t.request,requestId:p,sessionId:d,agent:w,toolFailureTracker:t.toolFailureTracker,toolGuardrails:t.input.toolGuardrails,events:t.store.getRun(p)?.events??[]});return u({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,result:e,artifacts:t.input.artifacts})}return await async function runAdapterRequest(e){if(!e.adapter)throw new Error(`No runtime adapter can run backend ${e.agent.backend} for agent ${e.agent.id}`);const t=e.adapter,c=await e.capabilities.beforeAdapterRun(createCapabilityContext(e)),p=c.memory,m=c.pluginMemories??[],d=R({workspace:e.input.workspace,agent:e.agent}),l=s(e.input.workspace.runtime,e.agent),w=new Map;let g;try{g=await runAdapterOnce(e,t,e.request,p,m,w,d)}catch(r){if(!o(r,d))throw r;e.emit(repairStarted(e,"adapter_error",1,errorMessage(r))),g=await runAdapterOnce(e,t,a(e.request,r,d),p,m,w,d),e.emit(repairCompleted(e,"adapter_error","retried",1,errorMessage(r)))}g=await i({...e,request:e.request,result:g,recoveryPolicy:d,workspace:e.input.workspace,toolGateway:e.input.toolGateway,runAdapter:r=>runAdapterOnce(e,t,r,p,m,w,d),runRecoveredToolCall:(t,r)=>runRecoveredToolCall(e,t,r)}),g=await n(createQualityRuntimeInput(e,p,m,w,d),e.request,g,l),await e.capabilities.beforeAdapterResultContract({...createCapabilityContext(e),result:g});try{assertRequestExecutionContract(e,g)}catch(a){const o=r({request:e.request,events:e.store.getRun(e.requestId)?.events??[],agent:e.agent,policy:d});if(!o)throw a;e.emit(repairStarted(e,"execution_contract",1,errorMessage(a))),g=await runAdapterOnce(e,t,o,p,m,w,d),g=await i({...e,request:o,result:g,recoveryPolicy:d,workspace:e.input.workspace,toolGateway:e.input.toolGateway,runAdapter:r=>runAdapterOnce(e,t,r,p,m,w,d),runRecoveredToolCall:(t,r)=>runRecoveredToolCall(e,t,r)}),g=await n(createQualityRuntimeInput(e,p,m,w,d),o,g,l),assertRequestExecutionContract(e,g),e.emit(repairCompleted(e,"execution_contract","retried",1,errorMessage(a)))}const y=u({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,result:g,artifacts:e.input.artifacts});return await e.capabilities.afterAdapterResponse({...createCapabilityContext(e),result:g,response:y}),y}({...t,adapter:g,requestId:p,sessionId:d,agent:w})}catch(e){return c({store:t.store,emit:t.emit,requestId:p,sessionId:d,agent:w,error:e})}}({input:M,capabilities:T,store:G,emit:emit,request:t,toolFailureTracker:O}),subscribe:e=>(q.add(e),()=>q.delete(e)),...I({workspace:t.workspace,store:G,artifacts:t.artifacts,approvals:t.approvals,emit:emit}),...p({store:G,emit:emit}),...w({runtimeStore:G,store:S,emit:emit}),...g({runtimeStore:G,emit:emit}),...k({memory:t.memory}),cancel(e,t){const r=G.getRun(e);r&&"running"===r.state&&(G.updateRun(e,{state:"cancelled",completedAt:(new Date).toISOString()}),emit({type:"runtime.request.cancelled",requestId:e,sessionId:r.sessionId,agentId:r.agentId,reason:t}))},async stop(){await T.stop(),q.clear()}}}function runRecoveredToolCall(e,t,r){return m({gateway:e.input.toolGateway,workspace:e.input.workspace,emit:e.emit,request:{...e.request,toolCall:{toolId:t,args:r}},requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,toolFailureTracker:e.input.toolFailureTracker,toolGuardrails:e.input.toolGuardrails,events:e.store.getRun(e.requestId)?.events??[]})}function createCapabilityContext(e){return{workspace:e.input.workspace,store:e.store,emit:e.emit,request:e.request,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent}}function createQualityRuntimeInput(e,t,r,a,o){return{workspace:e.input.workspace,agent:e.agent,request:e.request,requestId:e.requestId,sessionId:e.sessionId,events:e.store.getRun(e.requestId)?.events??[],emit:e.emit,getEvents:()=>e.store.getRun(e.requestId)?.events??[],runAdapter:n=>runAdapterOnce(e,e.adapter,n,t,r,a,o),reviewModel:e.input.qualityReviewModel,executionEvaluatorRules:e.input.executionEvaluatorRules,memory:t,pluginMemories:r}}function assertRequestExecutionContract(e,r){t({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,output:r.text,metadata:e.request.metadata})}async function runAdapterOnce(e,t,r,a,o,n,s){return q(await t.run({workspace:{...e.input.workspace,runtime:s},agent:e.agent,request:r,requestId:e.requestId,sessionId:e.sessionId,memory:a,pluginMemories:o,toolGateway:e.input.toolGateway,toolFailureTracker:e.input.toolFailureTracker,toolGuardrails:e.input.toolGuardrails,executionEvaluatorRules:e.input.executionEvaluatorRules,requestState:n,getEvents:()=>e.store.getRun(e.requestId)?.events??[],emit:e.emit}))}function repairStarted(e,t,r,a){return{type:"runtime.repair.started",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agent.id,layer:t,attempt:r,reason:a}}function repairCompleted(e,t,r,a,o){return{type:"runtime.repair.completed",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agent.id,layer:t,outcome:r,attempt:a,reason:o}}function errorMessage(e){return e instanceof Error?e.message:String(e)}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
".": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@stable-harness/governance": "0.0.
|
|
16
|
-
"@stable-harness/memory": "0.0.
|
|
15
|
+
"@stable-harness/governance": "0.0.126",
|
|
16
|
+
"@stable-harness/memory": "0.0.126"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/evaluation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"main": "dist/src/index.js",
|
|
12
12
|
"types": "dist/src/index.d.ts",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@stable-harness/core": "0.0.
|
|
14
|
+
"@stable-harness/core": "0.0.126"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/protocols",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"main": "dist/src/index.js",
|
|
12
12
|
"types": "dist/src/index.d.ts",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@stable-harness/core": "0.0.
|
|
14
|
+
"@stable-harness/core": "0.0.126"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stable-harness/workspace-yaml",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
".": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@stable-harness/core": "0.0.
|
|
15
|
+
"@stable-harness/core": "0.0.126"
|
|
16
16
|
}
|
|
17
17
|
}
|