stageflow 0.2.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +179 -14
- package/dist/agent/activity.d.ts +12 -1
- package/dist/agent/activity.js +37 -2
- package/dist/agent/activityObserver.d.ts +5 -1
- package/dist/agent/activityObserver.js +174 -11
- package/dist/agent/cursorProvider.d.ts +1 -10
- package/dist/agent/cursorProvider.js +18 -10
- package/dist/agent/fakeAgent.js +15 -7
- package/dist/agent/piAdapter.d.ts +18 -1
- package/dist/agent/piAdapter.js +115 -45
- package/dist/agent/port.d.ts +7 -0
- package/dist/agent/port.js +3 -0
- package/dist/agent/providerAuth.js +12 -7
- package/dist/catalog/displayCatalogPath.d.ts +12 -0
- package/dist/catalog/displayCatalogPath.js +28 -0
- package/dist/cli/artifactCommand.d.ts +10 -0
- package/dist/cli/artifactCommand.js +120 -0
- package/dist/cli/envelopeCommand.d.ts +32 -0
- package/dist/cli/envelopeCommand.js +285 -0
- package/dist/cli/exportRunCommand.d.ts +10 -0
- package/dist/cli/exportRunCommand.js +150 -0
- package/dist/cli/handoffFormat.d.ts +22 -0
- package/dist/cli/handoffFormat.js +61 -0
- package/dist/cli/initCommand.d.ts +9 -0
- package/dist/cli/initCommand.js +71 -0
- package/dist/cli/initTemplates.d.ts +3 -0
- package/dist/cli/initTemplates.js +19 -0
- package/dist/cli/operatorCatalog.d.ts +10 -0
- package/dist/cli/operatorCatalog.js +16 -0
- package/dist/cli/runCommand.d.ts +7 -1
- package/dist/cli/runCommand.js +83 -11
- package/dist/cli/runOutput.d.ts +4 -1
- package/dist/cli/runOutput.js +36 -8
- package/dist/cli/skillsCommand.d.ts +16 -0
- package/dist/cli/skillsCommand.js +459 -0
- package/dist/cli/validateCommand.d.ts +1 -1
- package/dist/cli/validateCommand.js +20 -3
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +128 -22
- package/dist/config/browseCatalog.d.ts +45 -0
- package/dist/config/browseCatalog.js +170 -0
- package/dist/config/createPipeline.d.ts +12 -3
- package/dist/config/createPipeline.js +292 -100
- package/dist/config/createStage.d.ts +10 -4
- package/dist/config/createStage.js +44 -14
- package/dist/config/listConfig.d.ts +14 -19
- package/dist/config/listConfig.js +26 -191
- package/dist/config/listModelsFromManifest.d.ts +2 -0
- package/dist/config/listModelsFromManifest.js +4 -0
- package/dist/config/loadOutcome.d.ts +4 -0
- package/dist/config/loadPipeline.d.ts +1 -15
- package/dist/config/loadPipeline.js +88 -142
- package/dist/config/loadStage.d.ts +4 -0
- package/dist/config/loadStage.js +60 -32
- package/dist/config/loadStageflowManifest.d.ts +5 -0
- package/dist/config/loadStageflowManifest.js +157 -0
- package/dist/config/mergePipelineIncludes.d.ts +9 -0
- package/dist/config/mergePipelineIncludes.js +141 -0
- package/dist/config/normalizePipelineStageEntry.d.ts +18 -0
- package/dist/config/normalizePipelineStageEntry.js +210 -0
- package/dist/config/pipelineStageKeys.d.ts +4 -0
- package/dist/config/pipelineStageKeys.js +14 -0
- package/dist/config/resolveCatalogContext.d.ts +13 -0
- package/dist/config/resolveCatalogContext.js +13 -0
- package/dist/config/resolveForkEmitContext.d.ts +4 -0
- package/dist/config/resolveForkEmitContext.js +34 -0
- package/dist/config/resolvePipelineDag.d.ts +5 -1
- package/dist/config/resolvePipelineDag.js +86 -36
- package/dist/config/scanCatalogPaths.d.ts +4 -0
- package/dist/config/scanCatalogPaths.js +83 -0
- package/dist/config/validateCatalog.d.ts +22 -4
- package/dist/config/validateCatalog.js +169 -132
- package/dist/envelope/check.d.ts +2 -0
- package/dist/envelope/check.js +58 -0
- package/dist/envelope/cloneForks.d.ts +2 -0
- package/dist/envelope/cloneForks.js +62 -0
- package/dist/envelope/forkChoice.d.ts +3 -0
- package/dist/envelope/forkChoice.js +47 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/mcp/catalogTools.d.ts +3 -0
- package/dist/mcp/catalogTools.js +187 -0
- package/dist/mcp/controlTools.d.ts +3 -0
- package/dist/mcp/controlTools.js +147 -0
- package/dist/mcp/deps.d.ts +11 -0
- package/dist/mcp/deps.js +1 -0
- package/dist/mcp/projectRun.d.ts +1 -37
- package/dist/mcp/projectRun.js +1 -57
- package/dist/mcp/resources.d.ts +5 -0
- package/dist/mcp/resources.js +45 -0
- package/dist/mcp/server.d.ts +16 -3
- package/dist/mcp/server.js +159 -3
- package/dist/mcp/toolResults.d.ts +7 -0
- package/dist/mcp/toolResults.js +6 -0
- package/dist/mcp/tools.d.ts +2 -7
- package/dist/mcp/tools.js +52 -86
- package/dist/mcp/waitRun.d.ts +46 -0
- package/dist/mcp/waitRun.js +146 -0
- package/dist/mcp/waitingGates.d.ts +12 -0
- package/dist/mcp/waitingGates.js +83 -0
- package/dist/project/findProjectRoot.d.ts +2 -0
- package/dist/project/findProjectRoot.js +51 -0
- package/dist/project/globalHome.d.ts +2 -0
- package/dist/project/globalHome.js +19 -0
- package/dist/project/resolveProjectContext.d.ts +9 -0
- package/dist/project/resolveProjectContext.js +38 -0
- package/dist/project/resolveStageflowContext.d.ts +11 -0
- package/dist/project/resolveStageflowContext.js +66 -0
- package/dist/projection/projectRun.d.ts +44 -0
- package/dist/projection/projectRun.js +71 -0
- package/dist/prompt/priorEnvelope.d.ts +1 -1
- package/dist/prompt/priorEnvelope.js +4 -1
- package/dist/runstore/normalizeCatalogPath.d.ts +1 -0
- package/dist/runstore/normalizeCatalogPath.js +4 -0
- package/dist/runstore/paths.js +2 -0
- package/dist/runstore/pipelineDagSnapshot.d.ts +9 -0
- package/dist/runstore/pipelineDagSnapshot.js +90 -1
- package/dist/runstore/port.d.ts +22 -2
- package/dist/runstore/port.js +4 -1
- package/dist/runstore/runProjection.d.ts +1 -1
- package/dist/runstore/runProjection.js +25 -4
- package/dist/runstore/sqlite/SqliteRunStore.d.ts +3 -2
- package/dist/runstore/sqlite/SqliteRunStore.js +65 -7
- package/dist/runstore/sqlite/schema.d.ts +1 -1
- package/dist/runstore/sqlite/schema.js +4 -1
- package/dist/runstore/stageInstanceId.d.ts +4 -0
- package/dist/runstore/stageInstanceId.js +23 -0
- package/dist/runstore/syntheticStageSnapshot.d.ts +1 -1
- package/dist/runstore/syntheticStageSnapshot.js +2 -1
- package/dist/runstore/trackProjection.js +28 -12
- package/dist/runstore/workspaceLayout.d.ts +1 -0
- package/dist/runstore/workspaceLayout.js +1 -1
- package/dist/runtime/cloneSchedule.d.ts +18 -0
- package/dist/runtime/cloneSchedule.js +233 -0
- package/dist/runtime/credentialBinding.d.ts +8 -6
- package/dist/runtime/credentialBinding.js +18 -24
- package/dist/runtime/envelopeRouting.d.ts +2 -1
- package/dist/runtime/envelopeRouting.js +80 -13
- package/dist/runtime/pipelineRunner.d.ts +3 -0
- package/dist/runtime/pipelineRunner.js +15 -1
- package/dist/runtime/pipelineScheduler.d.ts +8 -2
- package/dist/runtime/pipelineScheduler.js +215 -39
- package/dist/runtime/reloadRunCatalog.d.ts +5 -0
- package/dist/runtime/reloadRunCatalog.js +44 -0
- package/dist/runtime/resumeReconstruct.d.ts +1 -0
- package/dist/runtime/resumeReconstruct.js +31 -10
- package/dist/runtime/runChangeBus.d.ts +18 -0
- package/dist/runtime/runChangeBus.js +83 -0
- package/dist/runtime/runManager.d.ts +4 -0
- package/dist/runtime/runManager.js +36 -16
- package/dist/runtime/settingsFile.d.ts +12 -0
- package/dist/runtime/settingsFile.js +87 -6
- package/dist/runtime/stageAttemptBootstrap.d.ts +1 -0
- package/dist/runtime/stageAttemptBootstrap.js +18 -7
- package/dist/runtime/stageProcessLauncher.js +3 -0
- package/dist/runtime/stageRecovery.js +3 -1
- package/dist/runtime/stageRunner.d.ts +1 -0
- package/dist/runtime/stageRunner.js +17 -15
- package/dist/runtime/stageWorker.js +13 -10
- package/dist/server/bootstrap.d.ts +32 -0
- package/dist/server/bootstrap.js +56 -0
- package/dist/server/createHttpHost.d.ts +34 -0
- package/dist/server/createHttpHost.js +70 -0
- package/dist/server/http.d.ts +6 -13
- package/dist/server/http.js +297 -352
- package/dist/server/mcpHost.d.ts +22 -0
- package/dist/server/mcpHost.js +21 -0
- package/dist/server/operatorResults.d.ts +13 -0
- package/dist/server/operatorResults.js +22 -0
- package/dist/tools/emitStageEnvelope.d.ts +12 -1
- package/dist/tools/emitStageEnvelope.js +27 -1
- package/dist/types/envelope.d.ts +3 -0
- package/dist/types/forkChoice.d.ts +30 -0
- package/dist/types/forkChoice.js +1 -0
- package/dist/types/pipeline.d.ts +59 -2
- package/dist/types/stageflowManifest.d.ts +23 -0
- package/dist/types/stageflowManifest.js +1 -0
- package/dist/ui/assets/{index-DCsDopak.css → index-C3N7MXAC.css} +1 -1
- package/dist/ui/assets/index-CSoGDA3A.js +118 -0
- package/dist/ui/index.html +3 -2
- package/dist/ui/stageflow-icon.svg +12 -0
- package/package.json +8 -5
- package/skills/install-suite.sh +107 -0
- package/skills/stageflow/SKILL.md +26 -0
- package/skills/stageflow/references/control-surface.md +26 -0
- package/skills/stageflow/scripts/detect-host.mjs +54 -0
- package/skills/stageflow/scripts/detect-host.test.mjs +97 -0
- package/skills/stageflow-author/SKILL.md +58 -0
- package/skills/stageflow-author/assets/examples/branch-decision/hotfix.yaml +10 -0
- package/skills/stageflow-author/assets/examples/branch-decision/release-gate.pipeline.yaml +12 -0
- package/skills/stageflow-author/assets/examples/branch-decision/run-tests.yaml +13 -0
- package/skills/stageflow-author/assets/examples/branch-decision/ship.yaml +10 -0
- package/skills/stageflow-author/assets/examples/linear-review/draft.yaml +9 -0
- package/skills/stageflow-author/assets/examples/linear-review/publish.yaml +10 -0
- package/skills/stageflow-author/assets/examples/linear-review/review-loop.pipeline.yaml +10 -0
- package/skills/stageflow-author/assets/examples/linear-review/review.yaml +15 -0
- package/skills/stageflow-author/assets/examples/non-sdlc-digest/gather.yaml +9 -0
- package/skills/stageflow-author/assets/examples/non-sdlc-digest/research-digest.pipeline.yaml +10 -0
- package/skills/stageflow-author/assets/examples/non-sdlc-digest/send.yaml +10 -0
- package/skills/stageflow-author/assets/examples/non-sdlc-digest/summarize.yaml +9 -0
- package/skills/stageflow-author/references/catalog-mapping.md +131 -0
- package/skills/stageflow-author/references/catalog-write-conventions.md +29 -0
- package/skills/stageflow-author/references/stage-prompt-template.md +55 -0
- package/skills/stageflow-author/references/validate-and-report.md +38 -0
- package/skills/stageflow-delegate/SKILL.md +18 -0
- package/skills/stageflow-delegate/references/authoring-or-run.md +15 -0
- package/skills/stageflow-delegate/references/example-walkthrough.md +30 -0
- package/skills/stageflow-delegate/references/pattern-detection.md +44 -0
- package/skills/stageflow-run/SKILL.md +151 -0
- package/skills/stageflow-run/references/mcp-call.md +17 -0
- package/skills/stageflow-run/references/task-and-pipeline-selection.md +52 -0
- package/skills/stageflow-run/scripts/mcp-call.mjs +299 -0
- package/skills/stageflow-run/scripts/mcp-call.test.mjs +271 -0
- package/skills/stageflow-session-capture/SKILL.md +94 -0
- package/skills/stageflow-session-capture/assets/example-pipeline/example.pipeline.yaml +7 -0
- package/skills/stageflow-session-capture/assets/example-pipeline/implement.yaml +8 -0
- package/skills/stageflow-session-capture/assets/example-pipeline/research.yaml +8 -0
- package/skills/stageflow-session-capture/references/catalog-authoring.md +40 -0
- package/skills/stageflow-session-capture/references/transcript-sources.md +25 -0
- package/skills/stageflow-session-capture/scripts/check-provider-gate.mjs +43 -0
- package/skills/stageflow-session-capture/scripts/locate-session-transcript.mjs +141 -0
- package/skills/stageflow-session-capture/scripts/resolve-catalog-id.mjs +119 -0
- package/skills/stageflow-setup/SKILL.md +110 -0
- package/dist/ui/assets/index-Cry0Tpfx.js +0 -118
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PiAgentAdapter } from "../agent/piAdapter.js";
|
|
2
|
-
import {
|
|
3
|
-
import { loadTaskFromYaml } from "../config/loadTask.js";
|
|
2
|
+
import { definitionIdForInstance } from "../runstore/stageInstanceId.js";
|
|
4
3
|
import { createRunStore } from "../runstore/createStore.js";
|
|
4
|
+
import { loadRunContext } from "./resumeReconstruct.js";
|
|
5
5
|
import { bindPiAgentDirEnv, rootsForStageWorker, withResolvedAuthPath, } from "./stageRoots.js";
|
|
6
6
|
import { runStage, isRunStageWaiting, } from "./stageRunner.js";
|
|
7
7
|
import { openStageAttempt } from "./stageAttemptBootstrap.js";
|
|
@@ -9,17 +9,16 @@ import { attemptContext } from "./stageAttemptContext.js";
|
|
|
9
9
|
import { outcomeToWorkerResult, STAGE_WORKER_EXIT, } from "./stageWorkerProtocol.js";
|
|
10
10
|
export async function runStageWorker(input) {
|
|
11
11
|
const store = createRunStore({ rootDir: input.rootDir });
|
|
12
|
-
const meta = await store.
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const loaded = await loadPipeline(meta.pipeline_id, { cwd: input.rootDir });
|
|
16
|
-
const stage = loaded.stages.find((s) => s.id === input.stageId);
|
|
12
|
+
const { meta, task, loaded } = await loadRunContext(store, input.runId, input.rootDir);
|
|
13
|
+
const definitionId = definitionIdForInstance(meta.pipeline_dag, input.stageId);
|
|
14
|
+
const stage = loaded.stages.find((s) => s.id === definitionId);
|
|
17
15
|
if (!stage) {
|
|
18
16
|
return {
|
|
19
17
|
ok: false,
|
|
20
18
|
reason: `Stage ${input.stageId} not in pipeline ${meta.pipeline_id}`,
|
|
21
19
|
};
|
|
22
20
|
}
|
|
21
|
+
const dag = meta.pipeline_dag ?? loaded.dag;
|
|
23
22
|
const agent = new PiAgentAdapter();
|
|
24
23
|
const workspaceDir = store.getWorkspaceDir(input.runId);
|
|
25
24
|
const checkoutRoot = meta.checkout_root;
|
|
@@ -36,8 +35,9 @@ export async function runStageWorker(input) {
|
|
|
36
35
|
store,
|
|
37
36
|
runId: input.runId,
|
|
38
37
|
stage,
|
|
38
|
+
stageId: input.stageId,
|
|
39
39
|
task,
|
|
40
|
-
dag
|
|
40
|
+
dag,
|
|
41
41
|
checkoutRoot,
|
|
42
42
|
workspaceDir,
|
|
43
43
|
factoryCwd: input.rootDir,
|
|
@@ -58,12 +58,14 @@ export async function runStageWorker(input) {
|
|
|
58
58
|
store,
|
|
59
59
|
runId: input.runId,
|
|
60
60
|
stage,
|
|
61
|
+
stageId: input.stageId,
|
|
61
62
|
task,
|
|
62
|
-
dag
|
|
63
|
+
dag,
|
|
63
64
|
checkoutRoot,
|
|
64
65
|
workspaceDir,
|
|
65
66
|
skipStarted: true,
|
|
66
67
|
existingHandle: opened.handle,
|
|
68
|
+
workerMode: true,
|
|
67
69
|
roots,
|
|
68
70
|
attemptCtx,
|
|
69
71
|
factoryCwd: input.rootDir,
|
|
@@ -77,8 +79,9 @@ export async function runStageWorker(input) {
|
|
|
77
79
|
store,
|
|
78
80
|
runId: input.runId,
|
|
79
81
|
stage,
|
|
82
|
+
stageId: input.stageId,
|
|
80
83
|
task,
|
|
81
|
-
dag
|
|
84
|
+
dag,
|
|
82
85
|
checkoutRoot,
|
|
83
86
|
workspaceDir,
|
|
84
87
|
workerMode: true,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AgentPort } from "../agent/port.js";
|
|
2
|
+
import type { ProviderAuthContext } from "../agent/providerAuth.js";
|
|
3
|
+
import { type RunStoreKind } from "../runstore/createStore.js";
|
|
4
|
+
import type { RunStore } from "../runstore/port.js";
|
|
5
|
+
import { RunManager } from "../runtime/runManager.js";
|
|
6
|
+
import { type RunChangeBus } from "../runtime/runChangeBus.js";
|
|
7
|
+
import { type McpHttpHandler } from "../mcp/server.js";
|
|
8
|
+
export type StageflowHostOptions = {
|
|
9
|
+
agent: AgentPort;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
agentDir?: string;
|
|
12
|
+
rootDir?: string;
|
|
13
|
+
store?: RunStore;
|
|
14
|
+
storeKind?: RunStoreKind;
|
|
15
|
+
maxConcurrent?: number;
|
|
16
|
+
providerAuthContext?: ProviderAuthContext;
|
|
17
|
+
mcpStateless?: boolean;
|
|
18
|
+
runChangeBus?: RunChangeBus;
|
|
19
|
+
};
|
|
20
|
+
export type StageflowHostBootstrap = {
|
|
21
|
+
cwd: string;
|
|
22
|
+
agentDir: string;
|
|
23
|
+
rootDir: string;
|
|
24
|
+
isGitProject: boolean;
|
|
25
|
+
store: RunStore;
|
|
26
|
+
manager: RunManager;
|
|
27
|
+
runChangeBus: RunChangeBus;
|
|
28
|
+
mcpStateless: boolean;
|
|
29
|
+
providerAuthContext: ProviderAuthContext | undefined;
|
|
30
|
+
mcpHandler: McpHttpHandler;
|
|
31
|
+
};
|
|
32
|
+
export declare function bootstrapStageflowHost(options: StageflowHostOptions): Promise<StageflowHostBootstrap>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { createRunStore } from "../runstore/createStore.js";
|
|
3
|
+
import { resolveStageflowContext } from "../project/resolveStageflowContext.js";
|
|
4
|
+
import { findProjectRoot } from "../project/findProjectRoot.js";
|
|
5
|
+
import { RunManager } from "../runtime/runManager.js";
|
|
6
|
+
import { createRunChangeBus, getRunChangeBusFromWrappedStore, isRunStoreWrapped, wrapRunStoreWithChangeBus, } from "../runtime/runChangeBus.js";
|
|
7
|
+
import { createMcpHttpHandler, resolveMcpStateless, } from "../mcp/server.js";
|
|
8
|
+
export async function bootstrapStageflowHost(options) {
|
|
9
|
+
const invocationCwd = options.cwd ?? process.cwd();
|
|
10
|
+
const ctx = await resolveStageflowContext(invocationCwd);
|
|
11
|
+
const cwd = ctx.invocationCwd;
|
|
12
|
+
const agentDir = options.agentDir ?? getAgentDir();
|
|
13
|
+
const rootDir = options.rootDir ?? ctx.projectRoot;
|
|
14
|
+
const isGitProject = options.rootDir !== undefined
|
|
15
|
+
? findProjectRoot(rootDir) !== null
|
|
16
|
+
: ctx.isGitProject;
|
|
17
|
+
const rawStore = options.store ??
|
|
18
|
+
createRunStore({ rootDir, kind: options.storeKind });
|
|
19
|
+
const boundBus = isRunStoreWrapped(rawStore)
|
|
20
|
+
? getRunChangeBusFromWrappedStore(rawStore)
|
|
21
|
+
: undefined;
|
|
22
|
+
if (boundBus !== undefined &&
|
|
23
|
+
options.runChangeBus !== undefined &&
|
|
24
|
+
options.runChangeBus !== boundBus) {
|
|
25
|
+
throw new Error("runChangeBus does not match the bus already bound to the provided store");
|
|
26
|
+
}
|
|
27
|
+
const runChangeBus = options.runChangeBus ?? boundBus ?? createRunChangeBus();
|
|
28
|
+
const store = wrapRunStoreWithChangeBus(rawStore, runChangeBus);
|
|
29
|
+
const manager = new RunManager({
|
|
30
|
+
agent: options.agent,
|
|
31
|
+
cwd,
|
|
32
|
+
projectRoot: rootDir,
|
|
33
|
+
isGitProject,
|
|
34
|
+
store,
|
|
35
|
+
maxConcurrent: options.maxConcurrent,
|
|
36
|
+
operatorCatalog: { cwd, agentDir },
|
|
37
|
+
});
|
|
38
|
+
await manager.attachWaitingStages();
|
|
39
|
+
await manager.reconcileOrphanedStages();
|
|
40
|
+
const mcpStateless = resolveMcpStateless({
|
|
41
|
+
mcpStateless: options.mcpStateless,
|
|
42
|
+
});
|
|
43
|
+
const mcpHandler = createMcpHttpHandler({ manager, store, cwd, runChangeBus }, { mcpStateless });
|
|
44
|
+
return {
|
|
45
|
+
cwd,
|
|
46
|
+
agentDir,
|
|
47
|
+
rootDir,
|
|
48
|
+
isGitProject,
|
|
49
|
+
store,
|
|
50
|
+
manager,
|
|
51
|
+
runChangeBus,
|
|
52
|
+
mcpStateless,
|
|
53
|
+
providerAuthContext: options.providerAuthContext,
|
|
54
|
+
mcpHandler,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type IncomingMessage, type ServerResponse, type Server } from "node:http";
|
|
2
|
+
import type { RunStore } from "../runstore/port.js";
|
|
3
|
+
import type { RunManager } from "../runtime/runManager.js";
|
|
4
|
+
import type { RunChangeBus } from "../runtime/runChangeBus.js";
|
|
5
|
+
import type { StageflowHostBootstrap } from "./bootstrap.js";
|
|
6
|
+
export declare const DEFAULT_PORT = 3847;
|
|
7
|
+
export declare function json(res: ServerResponse, status: number, body: unknown): void;
|
|
8
|
+
export type HttpHostRouteContext = {
|
|
9
|
+
req: IncomingMessage;
|
|
10
|
+
res: ServerResponse;
|
|
11
|
+
url: URL;
|
|
12
|
+
pathname: string;
|
|
13
|
+
method: string;
|
|
14
|
+
json: typeof json;
|
|
15
|
+
boot: StageflowHostBootstrap;
|
|
16
|
+
};
|
|
17
|
+
export type CreateHttpHostOptions = {
|
|
18
|
+
boot: StageflowHostBootstrap;
|
|
19
|
+
host: string;
|
|
20
|
+
port: number;
|
|
21
|
+
routes: (ctx: HttpHostRouteContext) => Promise<boolean | void>;
|
|
22
|
+
};
|
|
23
|
+
export type HttpHostEnvelope = {
|
|
24
|
+
server: Server;
|
|
25
|
+
port: number;
|
|
26
|
+
host: string;
|
|
27
|
+
url: string;
|
|
28
|
+
mcpUrl: string;
|
|
29
|
+
manager: RunManager;
|
|
30
|
+
store: RunStore;
|
|
31
|
+
runChangeBus: RunChangeBus;
|
|
32
|
+
mcpStateless: boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare function createHttpHost(options: CreateHttpHostOptions): Promise<HttpHostEnvelope>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createServer, } from "node:http";
|
|
2
|
+
import { localhostHostValidation, localhostOriginValidation, } from "@modelcontextprotocol/node";
|
|
3
|
+
export const DEFAULT_PORT = 3847;
|
|
4
|
+
export function json(res, status, body) {
|
|
5
|
+
const payload = JSON.stringify(body);
|
|
6
|
+
res.writeHead(status, {
|
|
7
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
8
|
+
"Content-Length": Buffer.byteLength(payload),
|
|
9
|
+
});
|
|
10
|
+
res.end(payload);
|
|
11
|
+
}
|
|
12
|
+
export async function createHttpHost(options) {
|
|
13
|
+
const { boot, host, port, routes } = options;
|
|
14
|
+
const validateMcpHost = localhostHostValidation();
|
|
15
|
+
const validateMcpOrigin = localhostOriginValidation();
|
|
16
|
+
const server = createServer(async (req, res) => {
|
|
17
|
+
const method = req.method ?? "GET";
|
|
18
|
+
const url = new URL(req.url ?? "/", `http://${host}:${port}`);
|
|
19
|
+
const pathname = url.pathname;
|
|
20
|
+
if (pathname === "/mcp") {
|
|
21
|
+
if (!validateMcpHost(req, res) || !validateMcpOrigin(req, res)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
await boot.mcpHandler.handle(req, res);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (!res.headersSent) {
|
|
29
|
+
res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
|
|
30
|
+
res.end(err instanceof Error ? err.message : String(err));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const handled = await routes({
|
|
36
|
+
req,
|
|
37
|
+
res,
|
|
38
|
+
url,
|
|
39
|
+
pathname,
|
|
40
|
+
method,
|
|
41
|
+
json,
|
|
42
|
+
boot,
|
|
43
|
+
});
|
|
44
|
+
if (handled)
|
|
45
|
+
return;
|
|
46
|
+
json(res, 404, { error: "Not found" });
|
|
47
|
+
});
|
|
48
|
+
server.requestTimeout = 0;
|
|
49
|
+
server.on("close", () => {
|
|
50
|
+
void boot.mcpHandler.close();
|
|
51
|
+
});
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
server.listen(port, host, () => resolve());
|
|
54
|
+
server.on("error", reject);
|
|
55
|
+
});
|
|
56
|
+
const address = server.address();
|
|
57
|
+
const boundPort = address && typeof address !== "string" ? address.port : port;
|
|
58
|
+
const url = `http://${host}:${boundPort}`;
|
|
59
|
+
return {
|
|
60
|
+
server,
|
|
61
|
+
port: boundPort,
|
|
62
|
+
host,
|
|
63
|
+
url,
|
|
64
|
+
mcpUrl: `${url}/mcp`,
|
|
65
|
+
manager: boot.manager,
|
|
66
|
+
store: boot.store,
|
|
67
|
+
runChangeBus: boot.runChangeBus,
|
|
68
|
+
mcpStateless: boot.mcpStateless,
|
|
69
|
+
};
|
|
70
|
+
}
|
package/dist/server/http.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { type Server } from "node:http";
|
|
2
1
|
import type { AgentPort } from "../agent/port.js";
|
|
3
2
|
import { type ProviderAuthContext } from "../agent/providerAuth.js";
|
|
4
|
-
import {
|
|
3
|
+
import type { RunStoreKind } from "../runstore/createStore.js";
|
|
5
4
|
import type { RunStore } from "../runstore/port.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import type { RunChangeBus } from "../runtime/runChangeBus.js";
|
|
6
|
+
import { DEFAULT_PORT, type HttpHostEnvelope } from "./createHttpHost.js";
|
|
8
7
|
export type UiServerOptions = {
|
|
9
8
|
agent: AgentPort;
|
|
10
9
|
cwd?: string;
|
|
@@ -17,15 +16,9 @@ export type UiServerOptions = {
|
|
|
17
16
|
uiDistDir?: string;
|
|
18
17
|
maxConcurrent?: number;
|
|
19
18
|
providerAuthContext?: ProviderAuthContext;
|
|
19
|
+
mcpStateless?: boolean;
|
|
20
|
+
runChangeBus?: RunChangeBus;
|
|
20
21
|
};
|
|
21
22
|
export declare function defaultUiDistDir(): string;
|
|
22
|
-
export declare function startUiServer(options: UiServerOptions): Promise<
|
|
23
|
-
server: Server;
|
|
24
|
-
port: number;
|
|
25
|
-
host: string;
|
|
26
|
-
url: string;
|
|
27
|
-
mcpUrl: string;
|
|
28
|
-
manager: RunManager;
|
|
29
|
-
store: RunStore;
|
|
30
|
-
}>;
|
|
23
|
+
export declare function startUiServer(options: UiServerOptions): Promise<HttpHostEnvelope>;
|
|
31
24
|
export { DEFAULT_PORT };
|