@emseepea/create-progress-streaming-server 0.0.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 +22 -0
- package/dist/LICENSE +21 -0
- package/dist/create.mjs +44 -0
- package/dist/template/README.md +47 -0
- package/dist/template/eval/meaning.test.mjs +23 -0
- package/dist/template/package.json +29 -0
- package/dist/template/src/server.ts +42 -0
- package/dist/template/test/server.test.mjs +22 -0
- package/dist/template/tsconfig.json +13 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# `@emseepea/create-progress-streaming-server`
|
|
2
|
+
|
|
3
|
+
Create a private, standalone Em See Pea project whose tool streams progress.
|
|
4
|
+
The package builds its starter from the maintained
|
|
5
|
+
[progress streaming example](https://github.com/emseepea/emseepea/tree/main/examples/streaming-progress).
|
|
6
|
+
|
|
7
|
+
## Create the Project
|
|
8
|
+
|
|
9
|
+
This initializer is queued for the next pre-alpha release and is not yet
|
|
10
|
+
available from npm.
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm init @emseepea/progress-streaming-server@next -- my-server
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
cd my-server
|
|
18
|
+
npm install
|
|
19
|
+
npm test
|
|
20
|
+
npm run lint
|
|
21
|
+
npm start
|
|
22
|
+
```
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Windy Road Technology Pty. Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/create.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { cp, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
|
+
|
|
6
|
+
const [destination, ...extra] = process.argv.slice(2);
|
|
7
|
+
if (extra.length > 0 || !destination || !/^[a-z0-9][a-z0-9._-]*$/.test(destination)) {
|
|
8
|
+
throw new Error("Provide one simple lowercase destination name, such as my-server");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const target = resolve(destination);
|
|
12
|
+
if (basename(target) !== destination) throw new Error("The destination must not contain a path");
|
|
13
|
+
const staging = await mkdtemp(join(dirname(target), ".emseepea-create-"));
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await copyContents(new URL("./template/", import.meta.url), staging);
|
|
17
|
+
const manifestPath = resolve(staging, "package.json");
|
|
18
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
19
|
+
await writeFile(manifestPath, `${JSON.stringify({ ...manifest, name: destination }, null, 2)}\n`);
|
|
20
|
+
await mkdir(target);
|
|
21
|
+
try {
|
|
22
|
+
await copyContents(staging, target);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
await rm(target, { recursive: true, force: true });
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (["EEXIST", "ENOTEMPTY"].includes(error.code)) {
|
|
29
|
+
throw new Error(`The destination already exists: ${destination}`);
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
} finally {
|
|
33
|
+
await rm(staging, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function copyContents(source, destination) {
|
|
37
|
+
for (const entry of await readdir(source)) {
|
|
38
|
+
const from = source instanceof URL ? new URL(entry, source) : join(source, entry);
|
|
39
|
+
await cp(from, join(destination, entry), { recursive: true, errorOnExist: true, force: false });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.log(`Created ${destination}.`);
|
|
44
|
+
console.log(`Next: cd ${destination}; npm install; npm test; npm start`);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Streaming Progress Example
|
|
2
|
+
|
|
3
|
+
Choose this example when a tool takes long enough that people benefit from
|
|
4
|
+
seeing progress before the final answer.
|
|
5
|
+
|
|
6
|
+
The public tool reports progress during its request. A client can ask for
|
|
7
|
+
server-sent events (SSE), which carry progress over the same `POST` request.
|
|
8
|
+
Without that request, the tool returns one JSON response when it finishes.
|
|
9
|
+
|
|
10
|
+
## Run
|
|
11
|
+
|
|
12
|
+
From this directory:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install
|
|
16
|
+
npm run build
|
|
17
|
+
npm start
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The server listens on `http://127.0.0.1:3000/mcp` by default. Set `PORT` to
|
|
21
|
+
choose another port. This example starts locally and does not configure a proxy.
|
|
22
|
+
|
|
23
|
+
To adapt it for a public server, see
|
|
24
|
+
[Use Progress Behind a Proxy](https://github.com/emseepea/emseepea/blob/main/packages/framework/README.md#use-progress-behind-a-proxy).
|
|
25
|
+
That option is available in the current source, not yet in a published npm
|
|
26
|
+
release. It does not add saved sessions, replay, subscriptions, or recovery
|
|
27
|
+
after reconnecting.
|
|
28
|
+
|
|
29
|
+
## Check This Example
|
|
30
|
+
|
|
31
|
+
[Ordinary tests](test/) live in `test/`.
|
|
32
|
+
The [AI tool-choice and understanding test](eval/meaning.test.mjs) lives separately in `eval/`.
|
|
33
|
+
The commands below run each suite independently.
|
|
34
|
+
|
|
35
|
+
Run its build and progress-stream checks:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm test
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Check that Claude chooses the roast tool and keeps progress separate from the result:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm run test:llm
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If Claude is not already signed in, run `claude auth login` first.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toolSelectionTest } from "@emseepea/testing/semantic";
|
|
2
|
+
|
|
3
|
+
toolSelectionTest("Progress stages remain distinct from the final roast result", {
|
|
4
|
+
server: new URL("../dist/server.js", import.meta.url),
|
|
5
|
+
question:
|
|
6
|
+
"Run sample-batch. Name the batch, list the progress stages, and report the " +
|
|
7
|
+
"final status and final roasted mass. Keep progress and the completed result " +
|
|
8
|
+
"distinct.",
|
|
9
|
+
criticalFacts: [
|
|
10
|
+
"sample-batch",
|
|
11
|
+
"charge",
|
|
12
|
+
"first crack",
|
|
13
|
+
"cool",
|
|
14
|
+
"complete",
|
|
15
|
+
"820"
|
|
16
|
+
],
|
|
17
|
+
criteria:
|
|
18
|
+
"The answer identifies charge, first crack, and cool as progress stages, then " +
|
|
19
|
+
"separately reports the completed final result of 820 roasted grams for " +
|
|
20
|
+
"sample-batch. It does not treat an intermediate progress stage as the final " +
|
|
21
|
+
"result.",
|
|
22
|
+
expectedTools: ["roast-sample-batch"],
|
|
23
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "emseepea-starter",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.json",
|
|
9
|
+
"start": "node dist/server.js",
|
|
10
|
+
"test": "npm run build && npm run test:built",
|
|
11
|
+
"test:built": "node --test test/*.test.mjs",
|
|
12
|
+
"test:llm": "npm run build && npm run test:llm:built",
|
|
13
|
+
"test:llm:built": "emseepea-test eval",
|
|
14
|
+
"lint": "oxlint src test eval"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@emseepea/server": "0.0.4",
|
|
18
|
+
"zod": "4.4.3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@emseepea/testing": "0.2.1",
|
|
22
|
+
"@types/node": "24.13.3",
|
|
23
|
+
"typescript": "6.0.3",
|
|
24
|
+
"oxlint": "1.80.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=22"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
import { createEmseepea, defineStreamingTool, serveEmseepea } from "@emseepea/server";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
const roastBatch = defineStreamingTool({
|
|
6
|
+
name: "roast-sample-batch",
|
|
7
|
+
access: "public",
|
|
8
|
+
description: "Run a sample coffee-roasting batch with bounded progress.",
|
|
9
|
+
inputSchema: z.object({ batch: z.literal("sample-batch") }),
|
|
10
|
+
outputSchema: z.object({
|
|
11
|
+
batch: z.literal("sample-batch"),
|
|
12
|
+
status: z.literal("complete"),
|
|
13
|
+
roastedGrams: z.literal(820),
|
|
14
|
+
stages: z.tuple([z.literal("charge"), z.literal("first crack"), z.literal("cool")]),
|
|
15
|
+
}),
|
|
16
|
+
async handler({ batch }, { reportProgress, signal }) {
|
|
17
|
+
const stages: ["charge", "first crack", "cool"] = ["charge", "first crack", "cool"];
|
|
18
|
+
for (const [index, stage] of stages.entries()) {
|
|
19
|
+
await reportProgress({ progress: index + 1, total: stages.length, message: stage });
|
|
20
|
+
await delay(150, undefined, { signal });
|
|
21
|
+
}
|
|
22
|
+
const data = { batch, status: "complete" as const, roastedGrams: 820 as const, stages };
|
|
23
|
+
return { text: `${batch} completed at 820 roasted grams`, data };
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const running = await serveEmseepea(createEmseepea({
|
|
28
|
+
name: "emseepea-streaming-progress",
|
|
29
|
+
version: "0.0.0",
|
|
30
|
+
instructions: "Use roast-sample-batch for the sample roast run.",
|
|
31
|
+
tools: [roastBatch],
|
|
32
|
+
}), { port: Number.parseInt(process.env.PORT ?? "3000", 10) });
|
|
33
|
+
|
|
34
|
+
console.log(`Em See Pea streaming-progress example listening at ${running.url}`);
|
|
35
|
+
|
|
36
|
+
async function shutdown(): Promise<void> {
|
|
37
|
+
await running.close();
|
|
38
|
+
process.exitCode = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
process.once("SIGINT", () => void shutdown());
|
|
42
|
+
process.once("SIGTERM", () => void shutdown());
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { startMcpServer } from "@emseepea/testing";
|
|
5
|
+
|
|
6
|
+
test("reports bounded progress before returning the final roast result", async (t) => {
|
|
7
|
+
const running = await startMcpServer(t, new URL("../dist/server.js", import.meta.url));
|
|
8
|
+
const client = await running.connect();
|
|
9
|
+
const progress = [];
|
|
10
|
+
const result = await client.callTool(
|
|
11
|
+
{ name: "roast-sample-batch", arguments: { batch: "sample-batch" } },
|
|
12
|
+
{ onprogress: (update) => progress.push(update) },
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
assert.deepEqual(progress.map(({ message }) => message), ["charge", "first crack", "cool"]);
|
|
16
|
+
assert.deepEqual(result.structuredContent, {
|
|
17
|
+
batch: "sample-batch",
|
|
18
|
+
status: "complete",
|
|
19
|
+
roastedGrams: 820,
|
|
20
|
+
stages: ["charge", "first crack", "cool"],
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "NodeNext",
|
|
4
|
+
"moduleResolution": "NodeNext",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"target": "ES2023",
|
|
9
|
+
"types": ["node"],
|
|
10
|
+
"verbatimModuleSyntax": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts"]
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@emseepea/create-progress-streaming-server",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Create an Em See Pea server that streams tool progress.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/emseepea/emseepea.git",
|
|
9
|
+
"directory": "packages/create-progress-streaming-server"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://emseepea.github.io/emseepea/examples/",
|
|
12
|
+
"bugs": "https://github.com/emseepea/emseepea/issues",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"provenance": false,
|
|
16
|
+
"tag": "next"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": {
|
|
20
|
+
"create-progress-streaming-server": "./dist/create.mjs"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22"
|
|
27
|
+
}
|
|
28
|
+
}
|