@hirey/hi-mcp-server 0.1.1 → 0.1.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './client.js';
2
+ export * from './sse.js';
@@ -0,0 +1,18 @@
1
+ import type { AgentGatewayEventEnvelope } from './client.js';
2
+ export type HiAgentStreamPayload = AgentGatewayEventEnvelope | {
3
+ error: string;
4
+ detail?: string;
5
+ };
6
+ export type HiSseEvent<T = HiAgentStreamPayload> = {
7
+ id: string | null;
8
+ event: string;
9
+ data: T;
10
+ };
11
+ export type StreamAgentEventsOptions = {
12
+ url: string;
13
+ token: string;
14
+ fetchImpl?: typeof fetch;
15
+ lastEventId?: string | null;
16
+ };
17
+ export declare function streamAgentEvents(options: StreamAgentEventsOptions): AsyncGenerator<HiSseEvent, void, void>;
18
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB;IACE,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,oBAAoB,IAAI;IACjD,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAWF,wBAAuB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CA2DlH"}
@@ -0,0 +1,67 @@
1
+ function tryParseJson(raw) {
2
+ try {
3
+ return JSON.parse(raw);
4
+ }
5
+ catch {
6
+ return raw;
7
+ }
8
+ }
9
+ // 简单 SSE 解析器:Hi 的流是 server-sent events,外部 agent 可以直接复用。
10
+ export async function* streamAgentEvents(options) {
11
+ const fetchImpl = options.fetchImpl || fetch;
12
+ const response = await fetchImpl(options.url, {
13
+ headers: {
14
+ authorization: `Bearer ${options.token}`,
15
+ accept: 'text/event-stream',
16
+ ...(options.lastEventId ? { 'last-event-id': options.lastEventId } : {}),
17
+ },
18
+ });
19
+ if (!response.ok || !response.body) {
20
+ throw new Error(`agent_event_stream_failed:${response.status}`);
21
+ }
22
+ const reader = response.body.getReader();
23
+ const decoder = new TextDecoder();
24
+ let buffer = '';
25
+ let currentId = options.lastEventId || null;
26
+ let currentEvent = 'message';
27
+ let dataLines = [];
28
+ while (true) {
29
+ const { done, value } = await reader.read();
30
+ if (done)
31
+ break;
32
+ buffer += decoder.decode(value, { stream: true });
33
+ while (true) {
34
+ const separatorIndex = buffer.indexOf('\n');
35
+ if (separatorIndex < 0)
36
+ break;
37
+ const rawLine = buffer.slice(0, separatorIndex);
38
+ buffer = buffer.slice(separatorIndex + 1);
39
+ const line = rawLine.replace(/\r$/, '');
40
+ if (!line) {
41
+ if (dataLines.length > 0) {
42
+ yield {
43
+ id: currentId,
44
+ event: currentEvent,
45
+ data: tryParseJson(dataLines.join('\n')),
46
+ };
47
+ }
48
+ currentEvent = 'message';
49
+ dataLines = [];
50
+ continue;
51
+ }
52
+ if (line.startsWith(':'))
53
+ continue;
54
+ if (line.startsWith('id:')) {
55
+ currentId = line.slice(3).trim();
56
+ continue;
57
+ }
58
+ if (line.startsWith('event:')) {
59
+ currentEvent = line.slice(6).trim() || 'message';
60
+ continue;
61
+ }
62
+ if (line.startsWith('data:')) {
63
+ dataLines.push(line.slice(5).trimStart());
64
+ }
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@hirey/hi-agent-sdk",
3
+ "version": "0.1.4",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
20
+ "build": "npm run clean && tsc -p tsconfig.json",
21
+ "prepack": "npm run build"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "dependencies": {
27
+ "@hirey/hi-agent-contracts": "^0.1.8"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.11.30",
31
+ "typescript": "^5.4.5"
32
+ }
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hirey/hi-mcp-server",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
@@ -18,6 +18,10 @@
18
18
  "bin": {
19
19
  "hi-mcp-server": "dist/server.js"
20
20
  },
21
+ "bundleDependencies": [
22
+ "@hirey/hi-agent-contracts",
23
+ "@hirey/hi-agent-sdk"
24
+ ],
21
25
  "scripts": {
22
26
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
23
27
  "dev": "tsx watch src/server.ts",