stable-harness 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +28 -6
- package/dist/index.js +1 -1
- package/package.json +14 -9
- package/packages/adapter-deepagents/dist/src/adapter.d.ts +1 -0
- package/packages/adapter-deepagents/dist/src/adapter.js +1 -1
- package/packages/adapter-deepagents/dist/src/index.d.ts +1 -0
- package/packages/adapter-deepagents/dist/src/index.js +1 -1
- package/packages/adapter-deepagents/dist/src/{builtin-tool-policy.d.ts → internal/builtin-tool-policy.d.ts} +16 -0
- package/packages/adapter-deepagents/dist/src/internal/builtin-tool-policy.js +1 -0
- package/packages/adapter-deepagents/dist/src/internal/gateway-tools.d.ts +4 -0
- package/packages/adapter-deepagents/dist/src/internal/gateway-tools.js +1 -0
- package/packages/adapter-deepagents/dist/src/internal/trace-projection.d.ts +16 -0
- package/packages/adapter-deepagents/dist/src/internal/trace-projection.js +1 -0
- package/packages/adapter-deepagents/dist/src/memory.d.ts +5 -0
- package/packages/adapter-deepagents/dist/src/memory.js +1 -0
- package/packages/adapter-deepagents/dist/src/retry-policy.js +1 -1
- package/packages/adapter-langgraph/dist/src/graph.d.ts +3 -0
- package/packages/adapter-langgraph/dist/src/graph.js +1 -0
- package/packages/adapter-langgraph/dist/src/index.d.ts +8 -0
- package/packages/adapter-langgraph/dist/src/index.js +1 -0
- package/packages/adapter-langgraph/dist/src/runtime.d.ts +3 -0
- package/packages/adapter-langgraph/dist/src/runtime.js +1 -0
- package/packages/adapter-langgraph/dist/src/skill-providers.d.ts +29 -0
- package/packages/adapter-langgraph/dist/src/skill-providers.js +1 -0
- package/packages/adapter-langgraph/dist/src/types.d.ts +60 -0
- package/packages/adapter-langgraph/dist/src/types.js +1 -0
- package/packages/adapter-langgraph/package.json +16 -0
- package/packages/cli/dist/src/args.d.ts +22 -0
- package/packages/cli/dist/src/args.js +1 -0
- package/packages/cli/dist/src/cli.js +1 -1
- package/packages/cli/dist/src/langgraph-official.d.ts +11 -0
- package/packages/cli/dist/src/langgraph-official.js +1 -0
- package/packages/cli/dist/src/output.d.ts +8 -0
- package/packages/cli/dist/src/output.js +1 -0
- package/packages/cli/dist/src/server.d.ts +3 -0
- package/packages/cli/dist/src/server.js +1 -0
- package/packages/cli/package.json +1 -0
- package/packages/core/dist/execution-contract.d.ts +1 -0
- package/packages/core/dist/execution-contract.js +1 -1
- package/packages/core/dist/index.d.ts +5 -4
- package/packages/core/dist/index.js +1 -1
- package/packages/core/dist/memory-plugins/maintenance.d.ts +42 -0
- package/packages/core/dist/memory-plugins/maintenance.js +1 -0
- package/packages/core/dist/memory-plugins/shared.d.ts +8 -0
- package/packages/core/dist/memory-plugins/shared.js +1 -0
- package/packages/core/dist/memory-plugins.d.ts +5 -48
- package/packages/core/dist/memory-plugins.js +1 -1
- package/packages/core/dist/recovery/tool-call.d.ts +13 -0
- package/packages/core/dist/recovery/tool-call.js +1 -0
- package/packages/core/dist/runtime/completion.d.ts +17 -0
- package/packages/core/dist/runtime/completion.js +1 -0
- package/packages/core/dist/runtime/direct-tool-call.d.ts +10 -0
- package/packages/core/dist/runtime/direct-tool-call.js +1 -0
- package/packages/core/dist/runtime/events.d.ts +147 -0
- package/packages/core/dist/runtime/events.js +1 -0
- package/packages/core/dist/runtime/memory.d.ts +23 -0
- package/packages/core/dist/runtime/memory.js +1 -0
- package/packages/core/dist/{artifacts.d.ts → runtime/persistence/artifacts.d.ts} +1 -1
- package/packages/core/dist/{inspection.d.ts → runtime/persistence/inspection.d.ts} +1 -1
- package/packages/core/dist/{queue.d.ts → runtime/persistence/queue.d.ts} +1 -1
- package/packages/core/dist/{stores.d.ts → runtime/persistence/stores.d.ts} +1 -1
- package/packages/core/dist/runtime/tool-gateway.d.ts +35 -0
- package/packages/core/dist/runtime/tool-gateway.js +1 -0
- package/packages/core/dist/runtime/types.d.ts +168 -0
- package/packages/core/dist/runtime/types.js +1 -0
- package/packages/core/dist/runtime.d.ts +6 -3
- package/packages/core/dist/runtime.js +1 -1
- package/packages/core/dist/trace.js +1 -1
- package/packages/core/dist/types.d.ts +17 -426
- package/packages/core/dist/workflows/index.d.ts +70 -0
- package/packages/core/dist/workflows/index.js +1 -0
- package/packages/core/dist/workflows/runtime.d.ts +12 -0
- package/packages/core/dist/workflows/runtime.js +1 -0
- package/packages/core/dist/workspace/types.d.ts +92 -0
- package/packages/core/dist/workspace/types.js +1 -0
- package/packages/governance/dist/src/types.d.ts +1 -1
- package/packages/protocols/dist/src/http-server.js +1 -1
- package/packages/protocols/dist/src/in-process-client.js +1 -1
- package/packages/protocols/dist/src/openai-compatible.js +1 -1
- package/packages/protocols/dist/src/openai-payload.d.ts +74 -0
- package/packages/protocols/dist/src/openai-payload.js +1 -0
- package/packages/protocols/dist/src/openai-stream.d.ts +39 -0
- package/packages/protocols/dist/src/openai-stream.js +1 -0
- package/packages/tool-gateway/dist/src/argument-guard.js +1 -1
- package/packages/tool-gateway/dist/src/schema-validation.d.ts +3 -0
- package/packages/tool-gateway/dist/src/schema-validation.js +1 -0
- package/packages/workspace-yaml/dist/discovery.d.ts +4 -0
- package/packages/workspace-yaml/dist/discovery.js +1 -0
- package/packages/workspace-yaml/dist/documents.d.ts +16 -0
- package/packages/workspace-yaml/dist/documents.js +1 -0
- package/packages/workspace-yaml/dist/loader.js +1 -1
- package/packages/workspace-yaml/dist/workflows.d.ts +16 -0
- package/packages/workspace-yaml/dist/workflows.js +1 -0
- package/packages/adapter-deepagents/dist/src/builtin-tool-policy.js +0 -1
- /package/packages/adapter-deepagents/dist/src/{messages.d.ts → internal/messages.d.ts} +0 -0
- /package/packages/adapter-deepagents/dist/src/{messages.js → internal/messages.js} +0 -0
- /package/packages/adapter-deepagents/dist/src/{stream-events.d.ts → internal/stream-events.d.ts} +0 -0
- /package/packages/adapter-deepagents/dist/src/{stream-events.js → internal/stream-events.js} +0 -0
- /package/packages/core/dist/{artifacts.js → runtime/persistence/artifacts.js} +0 -0
- /package/packages/core/dist/{inspection.js → runtime/persistence/inspection.js} +0 -0
- /package/packages/core/dist/{queue.js → runtime/persistence/queue.js} +0 -0
- /package/packages/core/dist/{stores.js → runtime/persistence/stores.js} +0 -0
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { ApprovalQueue } from "@stable-harness/governance";
|
|
2
2
|
import type { MemoryProvider, RuntimeMemoryStore } from "@stable-harness/memory";
|
|
3
|
-
import type { CompiledWorkspace, RuntimeToolGateway, RuntimeAdapter, RuntimeStore, StableHarnessRuntime } from "./types.js";
|
|
4
|
-
|
|
3
|
+
import type { CompiledWorkspace, RuntimeToolGateway, RuntimeAdapter, RuntimeStore, RuntimeWorkflowAdapter, StableHarnessRuntime } from "./types.js";
|
|
4
|
+
type RuntimeFactoryInput = {
|
|
5
5
|
workspace: CompiledWorkspace;
|
|
6
6
|
adapters: RuntimeAdapter[];
|
|
7
|
+
workflowAdapters?: RuntimeWorkflowAdapter[];
|
|
7
8
|
memory?: RuntimeMemoryStore;
|
|
8
9
|
memoryProviders?: MemoryProvider[];
|
|
9
10
|
approvals?: ApprovalQueue;
|
|
10
11
|
toolGateway?: RuntimeToolGateway;
|
|
11
12
|
store?: RuntimeStore;
|
|
12
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export declare function createStableHarnessRuntime(input: RuntimeFactoryInput): StableHarnessRuntime;
|
|
15
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{projectRequestInspection as s,projectRequestSummary as r,projectSessionSummaries as o}from"./inspection.js";import{recallMemoryPlugins as
|
|
1
|
+
import{randomUUID as e}from"node:crypto";import{assertExecutionContract as t}from"./execution-contract.js";import{projectRequestInspection as s,projectRequestSummary as r,projectSessionSummaries as o}from"./runtime/persistence/inspection.js";import{recallMemoryPlugins as a,runMemoryPlugins as n}from"./memory-plugins.js";import{assertNoRawToolCallOutput as i,buildAdapterErrorRecoveryPrompt as u,buildResultRecoveryRequest as d,containsRawToolCallOutput as l,isRecoverableAdapterError as c,rawToolCallFailureMessage as p,toolCallRecoveryEnabled as m}from"./recovery/tool-call.js";import{completeRun as w,failRun as I}from"./runtime/completion.js";import{runDirectToolCall as g}from"./runtime/direct-tool-call.js";import{emitMemoryLifecycle as q,runMemoryRecall as f,submitMemoryCandidates as k}from"./runtime/memory.js";import{createInMemoryRuntimeStore as y}from"./runtime/persistence/stores.js";import{runWorkflowRequest as R}from"./workflows/runtime.js";export function createStableHarnessRuntime(b){const C=new Set,j=b.store??y(),S=e=>{j.appendEvent(e);for(const t of C)t(e)};return{request:async s=>async function(s){const{agent:r,adapter:o}=function(e,t){const s=t.agentId??e.workspace.runtime.defaultAgentId,r=e.workspace.agents.get(s);if(!r)throw new Error(`Agent ${s} is not defined in the workspace`);if(t.toolCall||t.workflow)return{agent:r,adapter:void 0};const o=e.adapters.find(e=>e.canRun(r));if(!o)throw new Error(`No runtime adapter can run backend ${r.backend} for agent ${r.id}`);return{agent:r,adapter:o}}(s.input,s.request),y=s.request.requestId??e(),b=s.request.sessionId??e();s.store.createRun(function(e,t,s,r){return{requestId:t,sessionId:s,agentId:r.id,input:e.input,state:"running",parentRunId:e.parentRunId,metadata:e.metadata,artifacts:[],startedAt:(new Date).toISOString(),events:[]}}(s.request,y,b,r)),s.emit({type:"request.started",requestId:y,sessionId:b,agentId:r.id});try{if(s.request.workflow){const e=await R({workspace:s.input.workspace,adapters:s.input.workflowAdapters??[],toolGateway:s.input.toolGateway,request:{input:s.request.input,...s.request.workflow},requestId:y,sessionId:b,agentId:r.id,emit:s.emit});return w({store:s.store,emit:s.emit,requestId:y,sessionId:b,agent:r,result:e})}if(s.request.toolCall){const e=await g({gateway:s.input.toolGateway,workspace:s.input.workspace,emit:s.emit,request:s.request,requestId:y,sessionId:b,agent:r});return w({store:s.store,emit:s.emit,requestId:y,sessionId:b,agent:r,result:e})}return await async function(e){if(!e.adapter)throw new Error(`No runtime adapter can run backend ${e.agent.backend} for agent ${e.agent.id}`);const s=e.adapter,r=await f({memory:e.input.memory,emit:e.emit,request:e.request,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,workspace:e.input.workspace}),o=await a({providers:e.input.memoryProviders,request:e.request,agent:e.agent,workspace:e.input.workspace}),I=e.input.workspace.runtime;let g;try{g=await v(e,s,e.request,r,o)}catch(t){if(!c(t,I))throw t;g=await v(e,s,u(e.request,t,I),r,o)}const y=d({request:e.request,output:g.text,events:e.store.getRun(e.requestId)?.events??[],policy:I});if(y){g=await v(e,s,y,r,o);const t=d({request:y,output:g.text,events:[],policy:I});t&&(g=await v(e,s,t,r,o))}var R;m(I)&&(l(g.text,I)&&(R=e.request.metadata,"message"===("object"!=typeof R?.toolCallRecovery||null===R.toolCallRecovery||Array.isArray(R.toolCallRecovery)?{}:R.toolCallRecovery).onFailure)&&(g={...g,text:p(),metadata:{...g.metadata,toolCallRecovery:{failed:!0,reason:"raw_tool_call_output"}}}),i(g.text,I)),q(e.input.memory,e.emit,e.requestId,e.sessionId,e.agent.id,"read-before-finalize"),await k({memory:e.input.memory,approvals:e.input.approvals,emit:e.emit,request:e.request,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,workspace:e.input.workspace}),t({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,metadata:e.request.metadata});const b=w({store:e.store,emit:e.emit,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,result:g});return await n({providers:e.input.memoryProviders,emit:e.emit,request:e.request,requestId:e.requestId,sessionId:e.sessionId,agent:e.agent,workspace:e.input.workspace,result:g}),b}({...s,adapter:o,requestId:y,sessionId:b,agent:r})}catch(e){return I({store:s.store,emit:s.emit,requestId:y,sessionId:b,agent:r,error:e})}}({input:b,store:j,emit:S,request:s}),subscribe:e=>(C.add(e),()=>C.delete(e)),inspect:()=>({workspaceRoot:b.workspace.root,agents:[...b.workspace.agents.keys()].sort(),workflows:[...b.workspace.workflows.keys()].sort(),...b.workspace.runtime.workflowRouting?.defaultWorkflowId?{defaultWorkflowId:b.workspace.runtime.workflowRouting.defaultWorkflowId}:{},workflowRoutes:(b.workspace.runtime.workflowRouting?.routes??[]).map(e=>e.id).sort(),models:[...b.workspace.models.keys()].sort(),tools:[...b.workspace.tools.keys()].sort(),runs:j.listRuns()}),getRuntimePolicy:()=>b.workspace.runtime,getWorkflow:e=>b.workspace.workflows.get(e),getRun:e=>j.getRun(e),listRequests:e=>j.listRuns(e).map(r),listSessions:()=>o(j.listRuns()),inspectRequest(e){const t=j.getRun(e);return t?s(b.workspace,t):void 0},cancel(e,t){const s=j.getRun(e);s&&"running"===s.state&&(j.updateRun(e,{state:"cancelled",completedAt:(new Date).toISOString()}),S({type:"request.cancelled",requestId:e,sessionId:s.sessionId,agentId:s.agentId,reason:t}))},async stop(){C.clear()}}}async function v(e,t,s,r,o){return"string"==typeof(a=await t.run({workspace:e.input.workspace,agent:e.agent,request:s,requestId:e.requestId,sessionId:e.sessionId,memory:r,pluginMemories:o,toolGateway:e.input.toolGateway,emit:e.emit}))?{text:a}:a;var a}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function projectRuntimeTrace(t){return t.events.map(projectEvent).filter(
|
|
1
|
+
export function projectRuntimeTrace(t){return t.events.map(projectEvent).filter(o)}export function projectEvent(t){return"request.started"===t.type||"request.completed"===t.type||"request.failed"===t.type?r(t,"request",t.type):"request.cancelled"===t.type?r(t,"request",t.type,{reason:t.reason}):"execution.contract.failed"===t.type?r(t,"request",t.type,{reason:t.reason,missingEvidenceTools:t.missingEvidenceTools}):"tool.started"===t.type?r(t,"tool","tool.started",{toolId:t.toolId}):"tool.completed"===t.type?r(t,"tool","tool.completed",{toolId:t.toolId}):"adapter.event"===t.type?function(t){const e=t.event;if(n(e)&&"string"==typeof e.phase){const o=function(t,e){const o=function(t){const e=a(t);return"request"===e||"tool"===e||"adapter"===e||"memory"===e||"artifact"===e||"plan"===e||"delegation"===e?e:void 0}(e.traceType),n=a(e.traceLabel);if(o&&n)return r(t,o,n,e)}(t,e);return o||r(t,"adapter",`adapter.${e.phase}`,e)}return r(t,"adapter","adapter.event",{event:e})}(t):"artifact.created"===t.type?r(t,"artifact","artifact.created",{artifact:t.artifact}):t.type.startsWith("memory.")?r(t,"memory",t.type):void 0}export function readPlanTodos(r){const o=function(t){if(n(t))return t;if("string"==typeof t)try{const e=JSON.parse(t);return n(e)?e:void 0}catch{return}}(r),a=function(t){const e=n(t?.args)?t.args:void 0;return Array.isArray(t?.todos)?t.todos:Array.isArray(e?.todos)?e.todos:[]}(o);return a.map(t).filter(e)}function t(t){if(n(t)&&"string"==typeof t.content)return{content:t.content,status:"string"==typeof t.status?t.status:"pending"}}function e(t){return void 0!==t}function r(t,e,r,o){return{type:e,label:r,agentId:t.agentId,requestId:t.requestId,detail:o}}function o(t){return void 0!==t}function n(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function a(t){return"string"==typeof t&&t.trim()?t:void 0}
|
|
@@ -1,398 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ApprovalQueue
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export type RuntimeArtifact
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
uri?: string;
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
};
|
|
15
|
-
export type RuntimeArtifactRecord = RuntimeArtifact & {
|
|
16
|
-
requestId: string;
|
|
17
|
-
sessionId: string;
|
|
18
|
-
agentId: string;
|
|
19
|
-
createdAt: string;
|
|
20
|
-
contentType?: string;
|
|
21
|
-
size?: number;
|
|
22
|
-
};
|
|
23
|
-
export type RuntimeArtifactInput = RuntimeArtifact & {
|
|
24
|
-
requestId: string;
|
|
25
|
-
sessionId: string;
|
|
26
|
-
agentId: string;
|
|
27
|
-
content?: unknown;
|
|
28
|
-
contentType?: string;
|
|
29
|
-
createdAt?: string;
|
|
30
|
-
};
|
|
31
|
-
export type RuntimeArtifactStore = {
|
|
32
|
-
createArtifact(input: RuntimeArtifactInput): RuntimeArtifactRecord;
|
|
33
|
-
listArtifacts(filter?: RuntimeArtifactFilter): RuntimeArtifactRecord[];
|
|
34
|
-
readArtifact(id: string): unknown;
|
|
35
|
-
};
|
|
36
|
-
export type RuntimeArtifactFilter = {
|
|
37
|
-
requestId?: string;
|
|
38
|
-
sessionId?: string;
|
|
39
|
-
agentId?: string;
|
|
40
|
-
};
|
|
41
|
-
export type WorkspaceModel = {
|
|
42
|
-
id: string;
|
|
43
|
-
provider: string;
|
|
44
|
-
model: string;
|
|
45
|
-
config?: Record<string, unknown>;
|
|
46
|
-
};
|
|
47
|
-
export type WorkspaceTool = {
|
|
48
|
-
id: string;
|
|
49
|
-
description?: string;
|
|
50
|
-
schema?: unknown;
|
|
51
|
-
implementation?: string;
|
|
52
|
-
sourcePath?: string;
|
|
53
|
-
};
|
|
54
|
-
export type WorkspaceSkill = {
|
|
55
|
-
id: string;
|
|
56
|
-
path: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
allowedTools: string[];
|
|
59
|
-
};
|
|
60
|
-
export type WorkspaceMemory = {
|
|
61
|
-
id: string;
|
|
62
|
-
provider: string;
|
|
63
|
-
profile?: string;
|
|
64
|
-
mode?: string;
|
|
65
|
-
enabled: boolean;
|
|
66
|
-
prompts?: {
|
|
67
|
-
semantic?: string;
|
|
68
|
-
episodic?: string;
|
|
69
|
-
procedural?: string;
|
|
70
|
-
};
|
|
71
|
-
config?: Record<string, unknown>;
|
|
72
|
-
};
|
|
73
|
-
export type WorkspaceAgent = {
|
|
74
|
-
id: string;
|
|
75
|
-
description?: string;
|
|
76
|
-
sourcePath?: string;
|
|
77
|
-
backend: string;
|
|
78
|
-
modelRef?: string;
|
|
79
|
-
systemPrompt?: string;
|
|
80
|
-
tools: string[];
|
|
81
|
-
skills?: string[];
|
|
82
|
-
memory?: unknown[];
|
|
83
|
-
subagents: string[];
|
|
84
|
-
config: Record<string, unknown>;
|
|
85
|
-
};
|
|
86
|
-
export type WorkspaceRuntimePolicy = {
|
|
87
|
-
defaultAgentId: string;
|
|
88
|
-
workspaceId?: string;
|
|
89
|
-
profile?: string;
|
|
90
|
-
approvals?: Record<string, unknown>;
|
|
91
|
-
recovery?: Record<string, unknown>;
|
|
92
|
-
retry?: WorkspaceRetryPolicy;
|
|
93
|
-
memory?: Record<string, unknown>;
|
|
94
|
-
protocols?: Record<string, unknown>;
|
|
95
|
-
};
|
|
96
|
-
export type WorkspaceRetryPolicy = {
|
|
97
|
-
model?: WorkspaceRetryTargetPolicy;
|
|
98
|
-
tools?: WorkspaceToolRetryPolicy;
|
|
99
|
-
};
|
|
100
|
-
export type WorkspaceRetryTargetPolicy = {
|
|
101
|
-
enabled?: boolean;
|
|
102
|
-
maxRetries?: number;
|
|
103
|
-
retryOn?: WorkspaceRetryReason[];
|
|
104
|
-
backoffFactor?: number;
|
|
105
|
-
initialDelayMs?: number;
|
|
106
|
-
maxDelayMs?: number;
|
|
107
|
-
jitter?: boolean;
|
|
108
|
-
onFailure?: "continue" | "error";
|
|
109
|
-
};
|
|
110
|
-
export type WorkspaceToolRetryPolicy = WorkspaceRetryTargetPolicy & {
|
|
111
|
-
tools?: string[];
|
|
112
|
-
};
|
|
113
|
-
export type WorkspaceRetryReason = "timeout" | "network" | "rateLimit" | "serverError";
|
|
114
|
-
export type CompiledWorkspace = {
|
|
115
|
-
root: string;
|
|
116
|
-
runtime: WorkspaceRuntimePolicy;
|
|
117
|
-
agents: Map<string, WorkspaceAgent>;
|
|
118
|
-
models: Map<string, WorkspaceModel>;
|
|
119
|
-
tools: Map<string, WorkspaceTool>;
|
|
120
|
-
skills: Map<string, WorkspaceSkill>;
|
|
121
|
-
memories: Map<string, WorkspaceMemory>;
|
|
122
|
-
};
|
|
123
|
-
export type RuntimeRequest = {
|
|
124
|
-
input: string;
|
|
125
|
-
agentId?: string;
|
|
126
|
-
sessionId?: string;
|
|
127
|
-
requestId?: string;
|
|
128
|
-
parentRunId?: string;
|
|
129
|
-
toolCall?: RuntimeToolCallRequest;
|
|
130
|
-
memory?: RuntimeRequestMemory;
|
|
131
|
-
metadata?: Record<string, unknown>;
|
|
132
|
-
};
|
|
133
|
-
export type RuntimeToolCallRequest = {
|
|
134
|
-
toolId: string;
|
|
135
|
-
args?: unknown;
|
|
136
|
-
};
|
|
137
|
-
export type RuntimeRequestMemory = {
|
|
138
|
-
namespace?: string;
|
|
139
|
-
recall?: false | {
|
|
140
|
-
query?: string;
|
|
141
|
-
limit?: number;
|
|
142
|
-
};
|
|
143
|
-
candidates?: RuntimeMemoryCandidateInput[];
|
|
144
|
-
};
|
|
145
|
-
export type RuntimeMemoryCandidateInput = Omit<MemoryCandidate, "namespace"> & {
|
|
146
|
-
namespace?: string;
|
|
147
|
-
};
|
|
148
|
-
export type RuntimeResponse = {
|
|
149
|
-
requestId: string;
|
|
150
|
-
sessionId: string;
|
|
151
|
-
agentId: string;
|
|
152
|
-
state: RuntimeRecordState;
|
|
153
|
-
output: string;
|
|
154
|
-
metadata?: Record<string, unknown>;
|
|
155
|
-
artifacts?: RuntimeArtifact[];
|
|
156
|
-
};
|
|
157
|
-
export type RuntimeRunRecord = {
|
|
158
|
-
requestId: string;
|
|
159
|
-
sessionId: string;
|
|
160
|
-
agentId: string;
|
|
161
|
-
input: string;
|
|
162
|
-
state: RuntimeRecordState;
|
|
163
|
-
output?: string;
|
|
164
|
-
error?: string;
|
|
165
|
-
parentRunId?: string;
|
|
166
|
-
metadata?: Record<string, unknown>;
|
|
167
|
-
artifacts: RuntimeArtifact[];
|
|
168
|
-
startedAt: string;
|
|
169
|
-
completedAt?: string;
|
|
170
|
-
events: RuntimeEvent[];
|
|
171
|
-
};
|
|
172
|
-
export type RuntimeStoreRunPatch = Partial<Pick<RuntimeRunRecord, "state" | "output" | "error" | "metadata" | "artifacts" | "completedAt">>;
|
|
173
|
-
export type RuntimeRunFilter = {
|
|
174
|
-
agentId?: string;
|
|
175
|
-
sessionId?: string;
|
|
176
|
-
state?: RuntimeRecordState;
|
|
177
|
-
};
|
|
178
|
-
export type RuntimeStore = {
|
|
179
|
-
createRun(record: RuntimeRunRecord): void;
|
|
180
|
-
updateRun(requestId: string, patch: RuntimeStoreRunPatch): RuntimeRunRecord | undefined;
|
|
181
|
-
appendEvent(event: RuntimeEvent): RuntimeRunRecord | undefined;
|
|
182
|
-
getRun(requestId: string): RuntimeRunRecord | undefined;
|
|
183
|
-
listRuns(filter?: RuntimeRunFilter): RuntimeRunRecord[];
|
|
184
|
-
};
|
|
185
|
-
export type RuntimeQueueRecord = {
|
|
186
|
-
requestId: string;
|
|
187
|
-
sessionId: string;
|
|
188
|
-
priority: number;
|
|
189
|
-
queueKey?: string;
|
|
190
|
-
enqueuedAt: string;
|
|
191
|
-
availableAt: string;
|
|
192
|
-
claimedBy?: string;
|
|
193
|
-
claimedAt?: string;
|
|
194
|
-
leaseExpiresAt?: string;
|
|
195
|
-
attemptCount: number;
|
|
196
|
-
lastError?: string;
|
|
197
|
-
};
|
|
198
|
-
export type RuntimeRequestControlRecord = {
|
|
199
|
-
requestId: string;
|
|
200
|
-
cancelRequested: boolean;
|
|
201
|
-
cancelReason?: string;
|
|
202
|
-
cancelRequestedAt?: string;
|
|
203
|
-
heartbeatAt?: string;
|
|
204
|
-
workerId?: string;
|
|
205
|
-
workerStartedAt?: string;
|
|
206
|
-
};
|
|
207
|
-
export type RuntimeRecoveryIntent = {
|
|
208
|
-
requestId: string;
|
|
209
|
-
sessionId: string;
|
|
210
|
-
kind: "approval-decision" | "restart-request";
|
|
211
|
-
savedAt: string;
|
|
212
|
-
checkpointRef?: string;
|
|
213
|
-
resumePayload?: unknown;
|
|
214
|
-
attempts: number;
|
|
215
|
-
};
|
|
216
|
-
export type RuntimeQueueStore = {
|
|
217
|
-
enqueue(record: Omit<RuntimeQueueRecord, "attemptCount" | "enqueuedAt"> & {
|
|
218
|
-
attemptCount?: number;
|
|
219
|
-
enqueuedAt?: string;
|
|
220
|
-
}): RuntimeQueueRecord;
|
|
221
|
-
listQueue(): RuntimeQueueRecord[];
|
|
222
|
-
getQueuedRequest(requestId: string): RuntimeQueueRecord | undefined;
|
|
223
|
-
claimNext(input: RuntimeQueueClaimInput): RuntimeQueueRecord | undefined;
|
|
224
|
-
heartbeat(input: RuntimeHeartbeatInput): RuntimeRequestControlRecord | undefined;
|
|
225
|
-
requestCancel(input: RuntimeCancelIntentInput): RuntimeRequestControlRecord;
|
|
226
|
-
getControl(requestId: string): RuntimeRequestControlRecord | undefined;
|
|
227
|
-
listStuck(input: RuntimeStuckRequestInput): RuntimeQueueRecord[];
|
|
228
|
-
saveRecoveryIntent(intent: RuntimeRecoveryIntent): RuntimeRecoveryIntent;
|
|
229
|
-
getRecoveryIntent(requestId: string): RuntimeRecoveryIntent | undefined;
|
|
230
|
-
clearRecoveryIntent(requestId: string): boolean;
|
|
231
|
-
};
|
|
232
|
-
export type RuntimeQueueClaimInput = {
|
|
233
|
-
workerId: string;
|
|
234
|
-
now?: string;
|
|
235
|
-
leaseMs: number;
|
|
236
|
-
queueKey?: string;
|
|
237
|
-
};
|
|
238
|
-
export type RuntimeHeartbeatInput = {
|
|
239
|
-
requestId: string;
|
|
240
|
-
workerId: string;
|
|
241
|
-
now?: string;
|
|
242
|
-
};
|
|
243
|
-
export type RuntimeCancelIntentInput = {
|
|
244
|
-
requestId: string;
|
|
245
|
-
reason?: string;
|
|
246
|
-
now?: string;
|
|
247
|
-
};
|
|
248
|
-
export type RuntimeStuckRequestInput = {
|
|
249
|
-
now?: string;
|
|
250
|
-
staleAfterMs: number;
|
|
251
|
-
};
|
|
252
|
-
export type RuntimeEvent = {
|
|
253
|
-
type: "request.started";
|
|
254
|
-
requestId: string;
|
|
255
|
-
sessionId: string;
|
|
256
|
-
agentId: string;
|
|
257
|
-
} | {
|
|
258
|
-
type: "request.completed";
|
|
259
|
-
requestId: string;
|
|
260
|
-
sessionId: string;
|
|
261
|
-
agentId: string;
|
|
262
|
-
output: string;
|
|
263
|
-
} | {
|
|
264
|
-
type: "request.failed";
|
|
265
|
-
requestId: string;
|
|
266
|
-
sessionId: string;
|
|
267
|
-
agentId: string;
|
|
268
|
-
error: string;
|
|
269
|
-
} | {
|
|
270
|
-
type: "request.cancelled";
|
|
271
|
-
requestId: string;
|
|
272
|
-
sessionId: string;
|
|
273
|
-
agentId: string;
|
|
274
|
-
reason?: string;
|
|
275
|
-
} | {
|
|
276
|
-
type: "artifact.created";
|
|
277
|
-
requestId: string;
|
|
278
|
-
sessionId: string;
|
|
279
|
-
agentId: string;
|
|
280
|
-
artifact: RuntimeArtifact;
|
|
281
|
-
} | {
|
|
282
|
-
type: "execution.contract.failed";
|
|
283
|
-
requestId: string;
|
|
284
|
-
sessionId: string;
|
|
285
|
-
agentId: string;
|
|
286
|
-
reason: string;
|
|
287
|
-
missingEvidenceTools?: string[];
|
|
288
|
-
} | {
|
|
289
|
-
type: "tool.started";
|
|
290
|
-
requestId: string;
|
|
291
|
-
sessionId: string;
|
|
292
|
-
agentId: string;
|
|
293
|
-
toolId: string;
|
|
294
|
-
} | {
|
|
295
|
-
type: "tool.completed";
|
|
296
|
-
requestId: string;
|
|
297
|
-
sessionId: string;
|
|
298
|
-
agentId: string;
|
|
299
|
-
toolId: string;
|
|
300
|
-
output: unknown;
|
|
301
|
-
} | {
|
|
302
|
-
type: "memory.lifecycle";
|
|
303
|
-
requestId: string;
|
|
304
|
-
sessionId: string;
|
|
305
|
-
agentId: string;
|
|
306
|
-
hook: RuntimeMemoryHook;
|
|
307
|
-
} | {
|
|
308
|
-
type: "memory.recall.completed";
|
|
309
|
-
requestId: string;
|
|
310
|
-
sessionId: string;
|
|
311
|
-
agentId: string;
|
|
312
|
-
namespace: string;
|
|
313
|
-
recordIds: string[];
|
|
314
|
-
context: string;
|
|
315
|
-
} | {
|
|
316
|
-
type: "memory.candidate.submitted";
|
|
317
|
-
requestId: string;
|
|
318
|
-
sessionId: string;
|
|
319
|
-
agentId: string;
|
|
320
|
-
candidate: MemoryCandidate;
|
|
321
|
-
decision: MemoryDecision;
|
|
322
|
-
record?: MemoryRecord;
|
|
323
|
-
} | {
|
|
324
|
-
type: "memory.approval.requested";
|
|
325
|
-
requestId: string;
|
|
326
|
-
sessionId: string;
|
|
327
|
-
agentId: string;
|
|
328
|
-
approval: ApprovalRequest;
|
|
329
|
-
} | {
|
|
330
|
-
type: "memory.plugin.started";
|
|
331
|
-
requestId: string;
|
|
332
|
-
sessionId: string;
|
|
333
|
-
agentId: string;
|
|
334
|
-
memoryId: string;
|
|
335
|
-
provider: string;
|
|
336
|
-
namespace: string;
|
|
337
|
-
} | {
|
|
338
|
-
type: "memory.plugin.completed";
|
|
339
|
-
requestId: string;
|
|
340
|
-
sessionId: string;
|
|
341
|
-
agentId: string;
|
|
342
|
-
memoryId: string;
|
|
343
|
-
provider: string;
|
|
344
|
-
namespace: string;
|
|
345
|
-
candidateCount: number;
|
|
346
|
-
} | {
|
|
347
|
-
type: "memory.plugin.failed";
|
|
348
|
-
requestId: string;
|
|
349
|
-
sessionId: string;
|
|
350
|
-
agentId: string;
|
|
351
|
-
memoryId: string;
|
|
352
|
-
provider: string;
|
|
353
|
-
namespace: string;
|
|
354
|
-
error: string;
|
|
355
|
-
} | {
|
|
356
|
-
type: "memory.maintenance.started";
|
|
357
|
-
requestId: string;
|
|
358
|
-
sessionId: string;
|
|
359
|
-
agentId: string;
|
|
360
|
-
target: string;
|
|
361
|
-
} | {
|
|
362
|
-
type: "memory.maintenance.completed";
|
|
363
|
-
requestId: string;
|
|
364
|
-
sessionId: string;
|
|
365
|
-
agentId: string;
|
|
366
|
-
target: string;
|
|
367
|
-
operationCount: number;
|
|
368
|
-
} | {
|
|
369
|
-
type: "memory.maintenance.failed";
|
|
370
|
-
requestId: string;
|
|
371
|
-
sessionId: string;
|
|
372
|
-
agentId: string;
|
|
373
|
-
target: string;
|
|
374
|
-
error: string;
|
|
375
|
-
} | {
|
|
376
|
-
type: "skill.candidate.created";
|
|
377
|
-
requestId: string;
|
|
378
|
-
sessionId: string;
|
|
379
|
-
agentId: string;
|
|
380
|
-
candidateId: string;
|
|
381
|
-
name: string;
|
|
382
|
-
confidence: number;
|
|
383
|
-
evidenceCount: number;
|
|
384
|
-
status: string;
|
|
385
|
-
proposedPath?: string;
|
|
386
|
-
} | {
|
|
387
|
-
type: "adapter.event";
|
|
388
|
-
requestId: string;
|
|
389
|
-
sessionId: string;
|
|
390
|
-
agentId: string;
|
|
391
|
-
event: unknown;
|
|
392
|
-
};
|
|
393
|
-
export type RuntimeMemoryHook = "read-before-plan" | "read-before-finalize" | "write-after-run";
|
|
394
|
-
export type RuntimeEventListener = (event: RuntimeEvent) => void;
|
|
395
|
-
export type RuntimeEmit = (event: RuntimeEvent) => void;
|
|
1
|
+
import type { MemoryProvider, MemoryRecord, RuntimeMemoryStore } from "@stable-harness/memory";
|
|
2
|
+
import type { ApprovalQueue } from "@stable-harness/governance";
|
|
3
|
+
import type { RuntimeWorkflowAdapter, RuntimeWorkflowRequest, WorkspaceWorkflow } from "./workflows/index.js";
|
|
4
|
+
import type { RuntimeEvent, RuntimeEventListener, RuntimeEmit } from "./runtime/events.js";
|
|
5
|
+
import type { RuntimeArtifact, RuntimeOutput, RuntimeRecordState, RuntimeRequest, RuntimeResponse, RuntimeRunFilter, RuntimeRunRecord } from "./runtime/types.js";
|
|
6
|
+
import type { RuntimeToolGateway } from "./runtime/tool-gateway.js";
|
|
7
|
+
import type { CompiledWorkspace, WorkspaceAgent, WorkspaceRuntimePolicy } from "./workspace/types.js";
|
|
8
|
+
export type { RuntimeEvent, RuntimeMemoryHook, RuntimeEventListener, RuntimeEmit } from "./runtime/events.js";
|
|
9
|
+
export type { RuntimeArtifact, RuntimeArtifactFilter, RuntimeArtifactInput, RuntimeArtifactRecord, RuntimeArtifactStore, RuntimeCancelIntentInput, RuntimeHeartbeatInput, RuntimeMemoryCandidateInput, RuntimeOutput, RuntimeQueueClaimInput, RuntimeQueueRecord, RuntimeQueueStore, RuntimeRecoveryIntent, RuntimeRecordState, RuntimeRequest, RuntimeRequestControlRecord, RuntimeRequestMemory, RuntimeResponse, RuntimeRunFilter, RuntimeRunRecord, RuntimeStore, RuntimeStoreRunPatch, RuntimeStuckRequestInput, } from "./runtime/types.js";
|
|
10
|
+
export type { CompiledWorkspace, WorkspaceAdapterPolicy, WorkspaceAgent, WorkspaceMemory, WorkspaceModel, WorkspaceRetryPolicy, WorkspaceRetryReason, WorkspaceRetryTargetPolicy, WorkspaceRuntimePolicy, WorkspaceSkill, WorkspaceTool, WorkspaceToolRetryPolicy, } from "./workspace/types.js";
|
|
11
|
+
export type { RuntimeToolCallRequest, RuntimeToolGateway, RuntimeToolGatewayContext, RuntimeToolGatewayTool, } from "./runtime/tool-gateway.js";
|
|
396
12
|
export type RuntimeAdapterContext = {
|
|
397
13
|
workspace: CompiledWorkspace;
|
|
398
14
|
agent: WorkspaceAgent;
|
|
@@ -415,6 +31,7 @@ export type RuntimeAdapter = {
|
|
|
415
31
|
canRun(agent: WorkspaceAgent): boolean;
|
|
416
32
|
run(input: RuntimeAdapterContext): Promise<RuntimeAdapterResult>;
|
|
417
33
|
};
|
|
34
|
+
export type { RuntimeWorkflowAdapter, RuntimeWorkflowRequest };
|
|
418
35
|
export type RuntimeMemoryServices = {
|
|
419
36
|
store: RuntimeMemoryStore;
|
|
420
37
|
providers?: MemoryProvider[];
|
|
@@ -425,40 +42,12 @@ export type RuntimeGovernanceServices = {
|
|
|
425
42
|
export type RuntimeToolServices = {
|
|
426
43
|
gateway?: RuntimeToolGateway;
|
|
427
44
|
};
|
|
428
|
-
export type RuntimeToolGatewayContext = {
|
|
429
|
-
workspaceRoot: string;
|
|
430
|
-
requestId: string;
|
|
431
|
-
sessionId: string;
|
|
432
|
-
agentId: string;
|
|
433
|
-
};
|
|
434
|
-
export type RuntimeToolGatewayTool = {
|
|
435
|
-
id: string;
|
|
436
|
-
description?: string;
|
|
437
|
-
schema?: unknown;
|
|
438
|
-
};
|
|
439
|
-
export type RuntimeToolGateway = {
|
|
440
|
-
get(toolId: string): RuntimeToolGatewayTool | undefined;
|
|
441
|
-
repairToolCall?(request: {
|
|
442
|
-
toolId: string;
|
|
443
|
-
args?: unknown;
|
|
444
|
-
allowedToolIds?: string[];
|
|
445
|
-
context: RuntimeToolGatewayContext;
|
|
446
|
-
}): Promise<{
|
|
447
|
-
toolId: string;
|
|
448
|
-
args: unknown;
|
|
449
|
-
} | undefined>;
|
|
450
|
-
invoke(request: {
|
|
451
|
-
toolId: string;
|
|
452
|
-
args?: unknown;
|
|
453
|
-
context: RuntimeToolGatewayContext;
|
|
454
|
-
}): Promise<{
|
|
455
|
-
toolId: string;
|
|
456
|
-
output: unknown;
|
|
457
|
-
}>;
|
|
458
|
-
};
|
|
459
45
|
export type RuntimeInspectionSnapshot = {
|
|
460
46
|
workspaceRoot: string;
|
|
461
47
|
agents: string[];
|
|
48
|
+
workflows: string[];
|
|
49
|
+
defaultWorkflowId?: string;
|
|
50
|
+
workflowRoutes: string[];
|
|
462
51
|
models: string[];
|
|
463
52
|
tools: string[];
|
|
464
53
|
runs: RuntimeRunRecord[];
|
|
@@ -514,6 +103,8 @@ export type RuntimeEventSource = {
|
|
|
514
103
|
};
|
|
515
104
|
export type RuntimeInspector = {
|
|
516
105
|
inspect(): RuntimeInspectionSnapshot;
|
|
106
|
+
getRuntimePolicy(): WorkspaceRuntimePolicy;
|
|
107
|
+
getWorkflow(workflowId: string): WorkspaceWorkflow | undefined;
|
|
517
108
|
getRun(requestId: string): RuntimeRunRecord | undefined;
|
|
518
109
|
listRequests(filter?: RuntimeRunFilter): RuntimeRequestSummary[];
|
|
519
110
|
listSessions(): RuntimeSessionSummary[];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { CompiledWorkspace, RuntimeOutput, RuntimeToolGateway } from "../types.js";
|
|
2
|
+
export type WorkspaceWorkflow = {
|
|
3
|
+
id: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
sourcePath?: string;
|
|
6
|
+
adapter?: string;
|
|
7
|
+
entry?: string;
|
|
8
|
+
state?: WorkspaceWorkflowState;
|
|
9
|
+
nodes: WorkspaceWorkflowNode[];
|
|
10
|
+
edges: WorkspaceWorkflowEdge[];
|
|
11
|
+
policies?: Record<string, unknown>;
|
|
12
|
+
config?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
export type WorkspaceWorkflowState = {
|
|
15
|
+
schema?: string;
|
|
16
|
+
config?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
export type WorkspaceWorkflowNode = {
|
|
19
|
+
id: string;
|
|
20
|
+
use: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
config?: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
export type WorkspaceWorkflowEdge = {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
condition?: string;
|
|
28
|
+
};
|
|
29
|
+
export type WorkspaceWorkflowRoutingPolicy = {
|
|
30
|
+
defaultWorkflowId?: string;
|
|
31
|
+
routes?: WorkspaceWorkflowRoute[];
|
|
32
|
+
};
|
|
33
|
+
export type WorkspaceWorkflowRoute = {
|
|
34
|
+
id: string;
|
|
35
|
+
workflowId: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
export type RuntimeWorkflowRequest = {
|
|
40
|
+
workflowId?: string;
|
|
41
|
+
routeId?: string;
|
|
42
|
+
input?: unknown;
|
|
43
|
+
metadata?: Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
export type RuntimeWorkflowAdapterInput = {
|
|
46
|
+
workspace: CompiledWorkspace;
|
|
47
|
+
workflow: WorkspaceWorkflow;
|
|
48
|
+
request: RuntimeWorkflowRequest;
|
|
49
|
+
requestId: string;
|
|
50
|
+
sessionId: string;
|
|
51
|
+
toolGateway?: RuntimeToolGateway;
|
|
52
|
+
emit: (event: unknown) => void;
|
|
53
|
+
};
|
|
54
|
+
export type RuntimeWorkflowAdapter = {
|
|
55
|
+
name: string;
|
|
56
|
+
run(input: RuntimeWorkflowAdapterInput): Promise<string | RuntimeOutput>;
|
|
57
|
+
};
|
|
58
|
+
export type WorkflowPlan = {
|
|
59
|
+
workflowId: string;
|
|
60
|
+
adapter?: string;
|
|
61
|
+
entry: string;
|
|
62
|
+
nodes: WorkspaceWorkflowNode[];
|
|
63
|
+
edges: WorkspaceWorkflowEdge[];
|
|
64
|
+
terminalNodes: string[];
|
|
65
|
+
unreachableNodes: string[];
|
|
66
|
+
cycles: string[][];
|
|
67
|
+
};
|
|
68
|
+
export declare function compileWorkflowPlan(workflow: WorkspaceWorkflow): WorkflowPlan;
|
|
69
|
+
export declare function renderWorkflowMermaid(workflow: WorkspaceWorkflow): string;
|
|
70
|
+
export declare function renderAgentMermaid(workspace: CompiledWorkspace, agentId: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function compileWorkflowPlan(n){const e=n.entry??n.nodes[0]?.id;if(!e)throw new Error(`Workflow ${n.id} has no entry node`);const o=function(n){const e=new Map(n.nodes.map(n=>[n.id,[]]));for(const o of n.edges)e.get(o.from)?.push(o.to);return e}(n),r=function(n,e){const o=new Set,t=[n];for(;t.length>0;){const n=t.pop();o.has(n)||(o.add(n),t.push(...e.get(n)??[]))}return o}(e,o),i=function(n,e){const o=[];for(const r of n)t(r,r,e,[],o);return function(n){const e=new Set;return n.filter(n=>{const o=function(n){const e=n.slice(0,-1);return e.map((n,o)=>[...e.slice(o),...e.slice(0,o)].join("|")).sort()[0]??""}(n);return!e.has(o)&&(e.add(o),!0)})}(o)}(n.nodes.map(n=>n.id),o);return{workflowId:n.id,...n.adapter?{adapter:n.adapter}:{},entry:e,nodes:n.nodes,edges:n.edges,terminalNodes:n.nodes.map(n=>n.id).filter(n=>0===(o.get(n)??[]).length),unreachableNodes:n.nodes.map(n=>n.id).filter(n=>!r.has(n)),cycles:i}}export function renderWorkflowMermaid(n){const e=["flowchart TD"];for(const o of n.nodes)e.push(` ${r(o.id)}["${i(`${o.id}\\n${o.use}`)}"]`);for(const o of n.edges){const n=o.condition?`|${i(o.condition)}|`:"";e.push(` ${r(o.from)} --\x3e${n} ${r(o.to)}`)}return e.join("\n")}export function renderAgentMermaid(t,d){const a=t.agents.get(d);if(!a)throw new Error(`Agent is not defined: ${d}`);const s=function(e){return[...e.subagents.map(e=>n("agent",e)),...(e.skills??[]).map(e=>n("skill",e)),...e.tools.map(e=>n("tool",e))]}(a),c=["flowchart TD",` START_${r(a.id)}([START])`,` END_${r(a.id)}([END])`];for(const n of s)c.push(` ${n.diagramId}["${i(`${n.id}\\n${n.label}`)}"]`);return 0===s.length?(c.push(` START_${r(a.id)} --\x3e END_${r(a.id)}`),c.join("\n")):[...c,...a.edges?.length?e(a,s):o(a,s)].join("\n")}function n(n,e){return{id:e,diagramId:`${n}_${r(e)}`,label:`${n}: ${e}`}}function e(n,e){const o=new Map(e.map(n=>[n.id,n.diagramId])),t=new Set((n.edges??[]).map(n=>n.to)),d=new Set((n.edges??[]).map(n=>n.from)),a=e.filter(n=>!t.has(n.id)).map(n=>n.diagramId),s=e.filter(n=>!d.has(n.id)).map(n=>n.diagramId);return[...a.map(e=>` START_${r(n.id)} --\x3e ${r(e)}`),...(n.edges??[]).flatMap(n=>function(n,e){const o=e.get(n.from),t=e.get(n.to);return o&&t?[` ${o} --\x3e${n.condition?`|${i(n.condition)}|`:""} ${t}`]:[]}(n,o)),...s.map(e=>` ${r(e)} --\x3e END_${r(n.id)}`)]}function o(n,e){return e.flatMap(e=>[` START_${r(n.id)} -. available .-> ${e.diagramId}`,` ${e.diagramId} -.-> END_${r(n.id)}`])}function t(n,e,o,r,i){const d=[...r,e];for(const a of o.get(e)??[])a===n?i.push([...d,n]):r.includes(a)||t(n,a,o,d,i)}function r(n){return n.replace(/[^A-Za-z0-9_]/gu,"_")}function i(n){return n.replace(/"/gu,'\\"')}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CompiledWorkspace, RuntimeEvent, RuntimeOutput } from "../types.js";
|
|
2
|
+
import type { RuntimeWorkflowAdapter, RuntimeWorkflowAdapterInput, RuntimeWorkflowRequest } from "./index.js";
|
|
3
|
+
export declare function runWorkflowRequest(input: {
|
|
4
|
+
workspace: CompiledWorkspace;
|
|
5
|
+
adapters: RuntimeWorkflowAdapter[];
|
|
6
|
+
toolGateway?: RuntimeWorkflowAdapterInput["toolGateway"];
|
|
7
|
+
request: RuntimeWorkflowRequest;
|
|
8
|
+
requestId: string;
|
|
9
|
+
sessionId: string;
|
|
10
|
+
agentId: string;
|
|
11
|
+
emit: (event: RuntimeEvent) => void;
|
|
12
|
+
}): Promise<RuntimeOutput>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export async function runWorkflowRequest(e){const o=function(e,o){const t=o.routeId?e.runtime.workflowRouting?.routes?.find(e=>e.id===o.routeId):void 0;if(o.routeId&&!t)throw new Error(`Workflow route is not defined: ${o.routeId}`);const r=o.workflowId??t?.workflowId??e.runtime.workflowRouting?.defaultWorkflowId;if(!r)throw new Error("Workflow request requires workflowId, routeId, or runtime.workflowRouting.defaultWorkflowId");const n=e.workflows.get(r);if(!n)throw new Error(`Workflow is not defined: ${r}`);return n}(e.workspace,e.request),t=function(e,o){const t=o?e.find(e=>e.name===o):e[0];if(!t)throw new Error("No workflow adapter is configured"+(o?` for ${o}`:""));return t}(e.adapters,o.adapter);e.emit({type:"adapter.event",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agentId,event:{adapter:t.name,phase:"workflow.start",workflowId:o.id}});const r=await t.run({workspace:e.workspace,workflow:o,request:e.request,requestId:e.requestId,sessionId:e.sessionId,toolGateway:e.toolGateway,emit:o=>e.emit({type:"adapter.event",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agentId,event:o})});return e.emit({type:"adapter.event",requestId:e.requestId,sessionId:e.sessionId,agentId:e.agentId,event:{adapter:t.name,phase:"workflow.complete",workflowId:o.id}}),"string"==typeof r?{text:r}:r}
|