agent-memory-hub 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +256 -0
- package/dist/cli.js.map +1 -0
- package/dist/core/approval.d.ts +23 -0
- package/dist/core/approval.js +18 -0
- package/dist/core/approval.js.map +1 -0
- package/dist/core/atomic.d.ts +6 -0
- package/dist/core/atomic.js +37 -0
- package/dist/core/atomic.js.map +1 -0
- package/dist/core/errors.d.ts +17 -0
- package/dist/core/errors.js +22 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/frontmatter.d.ts +20 -0
- package/dist/core/frontmatter.js +248 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/hub.d.ts +25 -0
- package/dist/core/hub.js +119 -0
- package/dist/core/hub.js.map +1 -0
- package/dist/core/ids.d.ts +13 -0
- package/dist/core/ids.js +45 -0
- package/dist/core/ids.js.map +1 -0
- package/dist/core/inject.d.ts +44 -0
- package/dist/core/inject.js +60 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/journal.d.ts +25 -0
- package/dist/core/journal.js +73 -0
- package/dist/core/journal.js.map +1 -0
- package/dist/core/ledger.d.ts +32 -0
- package/dist/core/ledger.js +35 -0
- package/dist/core/ledger.js.map +1 -0
- package/dist/core/lock.d.ts +50 -0
- package/dist/core/lock.js +104 -0
- package/dist/core/lock.js.map +1 -0
- package/dist/core/registry.d.ts +44 -0
- package/dist/core/registry.js +85 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/search.d.ts +59 -0
- package/dist/core/search.js +189 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/store.d.ts +84 -0
- package/dist/core/store.js +255 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/time.d.ts +5 -0
- package/dist/core/time.js +21 -0
- package/dist/core/time.js.map +1 -0
- package/dist/core/transcript.d.ts +42 -0
- package/dist/core/transcript.js +77 -0
- package/dist/core/transcript.js.map +1 -0
- package/dist/core/types.d.ts +47 -0
- package/dist/core/types.js +10 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/transport/http.d.ts +11 -0
- package/dist/transport/http.js +45 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/mcp.d.ts +27 -0
- package/dist/transport/mcp.js +469 -0
- package/dist/transport/mcp.js.map +1 -0
- package/dist/transport/panel.d.ts +6 -0
- package/dist/transport/panel.js +86 -0
- package/dist/transport/panel.js.map +1 -0
- package/dist/transport/server.d.ts +21 -0
- package/dist/transport/server.js +211 -0
- package/dist/transport/server.js.map +1 -0
- package/package.json +60 -4
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, readFileSync, appendFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tokenize } from './search.js';
|
|
4
|
+
import { atomicWrite } from './atomic.js';
|
|
5
|
+
export const TRANSCRIPT_INDEX_FILE = 'records/transcript-index.jsonl';
|
|
6
|
+
function indexPath(root) {
|
|
7
|
+
return join(root, TRANSCRIPT_INDEX_FILE);
|
|
8
|
+
}
|
|
9
|
+
/** Index one session transcript: tokens + preview only (body stays with the host). */
|
|
10
|
+
export function indexTranscript(root, input) {
|
|
11
|
+
const tokens = [...new Set(tokenize(input.text))];
|
|
12
|
+
const record = {
|
|
13
|
+
sessionId: input.sessionId,
|
|
14
|
+
at: input.at ?? new Date().toISOString(),
|
|
15
|
+
tokens,
|
|
16
|
+
preview: input.text.replace(/\s+/g, ' ').slice(0, 160),
|
|
17
|
+
location: input.location,
|
|
18
|
+
};
|
|
19
|
+
appendFileSync(indexPath(root), `${JSON.stringify(record)}\n`, 'utf8');
|
|
20
|
+
return record;
|
|
21
|
+
}
|
|
22
|
+
export function readTranscriptIndex(root) {
|
|
23
|
+
const path = indexPath(root);
|
|
24
|
+
if (!existsSync(path))
|
|
25
|
+
return [];
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const line of readFileSync(path, 'utf8').split('\n')) {
|
|
28
|
+
if (line.trim() === '')
|
|
29
|
+
continue;
|
|
30
|
+
try {
|
|
31
|
+
out.push(JSON.parse(line));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// skip malformed
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Detect deja-vu: sessions whose token set overlaps the query tokens above the
|
|
41
|
+
* threshold (default 0.35 — deliberately conservative; this is a hint, not a
|
|
42
|
+
* verdict). Read-only; the host decides what to do with the pointer.
|
|
43
|
+
*/
|
|
44
|
+
export function detectDejaVu(root, query, threshold) {
|
|
45
|
+
const queryTokens = new Set(tokenize(query));
|
|
46
|
+
if (queryTokens.size === 0)
|
|
47
|
+
return [];
|
|
48
|
+
const min = threshold ?? 0.35;
|
|
49
|
+
const hits = [];
|
|
50
|
+
for (const record of readTranscriptIndex(root)) {
|
|
51
|
+
const set = new Set(record.tokens);
|
|
52
|
+
let shared = 0;
|
|
53
|
+
for (const token of queryTokens)
|
|
54
|
+
if (set.has(token))
|
|
55
|
+
shared += 1;
|
|
56
|
+
const overlap = shared / queryTokens.size;
|
|
57
|
+
if (overlap >= min) {
|
|
58
|
+
hits.push({
|
|
59
|
+
sessionId: record.sessionId,
|
|
60
|
+
at: record.at,
|
|
61
|
+
preview: record.preview,
|
|
62
|
+
location: record.location,
|
|
63
|
+
overlap: Math.round(overlap * 1000) / 1000,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return hits.sort((a, b) => b.overlap - a.overlap);
|
|
68
|
+
}
|
|
69
|
+
/** Rebuild the index file atomically (dedup by sessionId keeps the latest). */
|
|
70
|
+
export function rebuildTranscriptIndex(root, records) {
|
|
71
|
+
const bySession = new Map();
|
|
72
|
+
for (const record of records)
|
|
73
|
+
bySession.set(record.sessionId, record);
|
|
74
|
+
const lines = [...bySession.values()].map((r) => `${JSON.stringify(r)}\n`);
|
|
75
|
+
atomicWrite(indexPath(root), lines.join(''));
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../src/core/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAqBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,gCAAgC,CAAA;AAErE,SAAS,SAAS,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAA;AAC1C,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,KAAyE;IAEzE,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,MAAM,GAAqB;QAC/B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,EAAE,EAAE,KAAK,CAAC,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACxC,MAAM;QACN,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;QACtD,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAA;IACD,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC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;QAChE,MAAM,OAAO,GAAG,MAAM,GAAG,WAAW,CAAC,IAAI,CAAA;QACzC,IAAI,OAAO,IAAI,GAAG,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC;gBACR,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI;aAC3C,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAA;AACnD,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAE,OAA2B;IAC9E,MAAM,SAAS,GAAG,IAAI,GAAG,EAA4B,CAAA;IACrD,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IACrE,MAAM,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IAC1E,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge entry types — the hub-directory format contract.
|
|
3
|
+
*
|
|
4
|
+
* Format compatibility with dsh-memory-hub hub directories is a hard contract:
|
|
5
|
+
* this repo reads existing hub directories directly (zero migration). The type
|
|
6
|
+
* shape below mirrors the stable subset of that format; drift is prevented by
|
|
7
|
+
* cross-referenced format contract tests in both repos.
|
|
8
|
+
*/
|
|
9
|
+
/** Knowledge type classification (stable across both repos). */
|
|
10
|
+
export type KnowledgeType = 'decision' | 'constraint' | 'knowledge' | 'api-catalog' | 'process' | 'open-questions' | 'runtime-base' | 'playbooks' | 'assets';
|
|
11
|
+
/** Lifecycle status of an entry. */
|
|
12
|
+
export type KnowledgeStatus = 'candidate' | 'accepted' | 'rejected' | 'superseded' | 'deprecated';
|
|
13
|
+
/** Scope levels: project < domain < global. A project entry belongs to exactly one workspace. */
|
|
14
|
+
export type KnowledgeScope = {
|
|
15
|
+
level: 'global';
|
|
16
|
+
} | {
|
|
17
|
+
level: 'domain';
|
|
18
|
+
domainId: string;
|
|
19
|
+
} | {
|
|
20
|
+
level: 'project';
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Parsed frontmatter of a knowledge file. Unknown keys are preserved verbatim
|
|
25
|
+
* (forward compatibility): readers must not drop fields they do not understand.
|
|
26
|
+
*/
|
|
27
|
+
export interface KnowledgeFrontmatter {
|
|
28
|
+
id: string;
|
|
29
|
+
version: number;
|
|
30
|
+
type: KnowledgeType;
|
|
31
|
+
status: KnowledgeStatus;
|
|
32
|
+
title: string;
|
|
33
|
+
summary: string;
|
|
34
|
+
scope: KnowledgeScope;
|
|
35
|
+
tags: string[];
|
|
36
|
+
created?: string;
|
|
37
|
+
updated?: string;
|
|
38
|
+
last_verified?: string;
|
|
39
|
+
/** Unknown/extra frontmatter keys, preserved as-is. */
|
|
40
|
+
extra: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/** A knowledge file split into its contract parts. */
|
|
43
|
+
export interface ParsedKnowledgeFile {
|
|
44
|
+
frontmatter: KnowledgeFrontmatter;
|
|
45
|
+
/** Body Markdown, without the frontmatter block, trimmed. */
|
|
46
|
+
body: string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge entry types — the hub-directory format contract.
|
|
3
|
+
*
|
|
4
|
+
* Format compatibility with dsh-memory-hub hub directories is a hard contract:
|
|
5
|
+
* this repo reads existing hub directories directly (zero migration). The type
|
|
6
|
+
* shape below mirrors the stable subset of that format; drift is prevented by
|
|
7
|
+
* cross-referenced format contract tests in both repos.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of agent-memory-hub. Host packages (the DSH thin adapter,
|
|
3
|
+
* CLIs, panels) import ONLY from this barrel — never deep paths — so the
|
|
4
|
+
* internal layout can move without breaking hosts.
|
|
5
|
+
*/
|
|
6
|
+
export type { KnowledgeType, KnowledgeStatus, KnowledgeScope, KnowledgeFrontmatter, } from './core/types.js';
|
|
7
|
+
export type { Sequences } from './core/ids.js';
|
|
8
|
+
export type { LedgerAction, LedgerRecord } from './core/ledger.js';
|
|
9
|
+
export type { WriterLock, LockOptions, AcquireResult } from './core/lock.js';
|
|
10
|
+
export type { SaveKnowledgeInput, KnowledgeEntry } from './core/store.js';
|
|
11
|
+
export type { SearchHit, SearchIndex, SearchMetrics, SearchOptions, DetailLevel } from './core/search.js';
|
|
12
|
+
export type { PreflightResult, PreflightOptions } from './core/inject.js';
|
|
13
|
+
export type { JournalEntry, AppendJournalInput } from './core/journal.js';
|
|
14
|
+
export type { TranscriptRecord, DejaVu } from './core/transcript.js';
|
|
15
|
+
export type { ApprovalChannel } from './core/approval.js';
|
|
16
|
+
export { ErrorCode, HubError } from './core/errors.js';
|
|
17
|
+
export { nowIso, parseIso } from './core/time.js';
|
|
18
|
+
export { newLockToken } from './core/ids.js';
|
|
19
|
+
export { HUB_DIRS, KNOWLEDGE_TYPES_DIR, HUB_CONFIG, HUB_README, LEDGER_FILE, SEQUENCES_FILE, LOCK_FILE, isHubInitialized, initHub, readHubConfig, knowledgeDir, historyDir, pendingDir, journalDir, } from './core/hub.js';
|
|
20
|
+
export { atomicWrite } from './core/atomic.js';
|
|
21
|
+
export { appendLedger, ledgerPath, readLedger, readSequences, writeSequences } from './core/ledger.js';
|
|
22
|
+
export { commitKnowledge, createProposal, deprecateEntry, hardDeleteEntry, findTitleConflict, getEntry, listEntries, listProposals, renderKnowledgeMarkdown, } from './core/store.js';
|
|
23
|
+
export { resolveWorkspace, registerWorkspace, readRegisteredWorkspaces, slugifyDir, workspaceIdFromOrigin, } from './core/registry.js';
|
|
24
|
+
export type { ResolvedWorkspace } from './core/registry.js';
|
|
25
|
+
export { acquireLock, heartbeatLock, releaseLock, assertFencing, isLockFresh, lockInfo, readLock } from './core/lock.js';
|
|
26
|
+
export { buildIndex, search, searchWithMetrics, emptyMetrics, tokenize, isVisible } from './core/search.js';
|
|
27
|
+
export { preflight, preflightIndex, renderPack, estimateTokens } from './core/inject.js';
|
|
28
|
+
export { requireApproval, isHumanChannel, HUMAN_CHANNELS } from './core/approval.js';
|
|
29
|
+
export { appendJournal, readJournal, trimJournal } from './core/journal.js';
|
|
30
|
+
export { indexTranscript, readTranscriptIndex, detectDejaVu, rebuildTranscriptIndex, TRANSCRIPT_INDEX_FILE, } from './core/transcript.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of agent-memory-hub. Host packages (the DSH thin adapter,
|
|
3
|
+
* CLIs, panels) import ONLY from this barrel — never deep paths — so the
|
|
4
|
+
* internal layout can move without breaking hosts.
|
|
5
|
+
*/
|
|
6
|
+
// Errors
|
|
7
|
+
export { ErrorCode, HubError } from './core/errors.js';
|
|
8
|
+
// Time + ids
|
|
9
|
+
export { nowIso, parseIso } from './core/time.js';
|
|
10
|
+
export { newLockToken } from './core/ids.js';
|
|
11
|
+
// Hub lifecycle
|
|
12
|
+
export { HUB_DIRS, KNOWLEDGE_TYPES_DIR, HUB_CONFIG, HUB_README, LEDGER_FILE, SEQUENCES_FILE, LOCK_FILE, isHubInitialized, initHub, readHubConfig, knowledgeDir, historyDir, pendingDir, journalDir, } from './core/hub.js';
|
|
13
|
+
// Atomic writes
|
|
14
|
+
export { atomicWrite } from './core/atomic.js';
|
|
15
|
+
// Ledger + sequences
|
|
16
|
+
export { appendLedger, ledgerPath, readLedger, readSequences, writeSequences } from './core/ledger.js';
|
|
17
|
+
// Store
|
|
18
|
+
export { commitKnowledge, createProposal, deprecateEntry, hardDeleteEntry, findTitleConflict, getEntry, listEntries, listProposals, renderKnowledgeMarkdown, } from './core/store.js';
|
|
19
|
+
// Registry (ADR-0002 zero-config identity)
|
|
20
|
+
export { resolveWorkspace, registerWorkspace, readRegisteredWorkspaces, slugifyDir, workspaceIdFromOrigin, } from './core/registry.js';
|
|
21
|
+
// Lock
|
|
22
|
+
export { acquireLock, heartbeatLock, releaseLock, assertFencing, isLockFresh, lockInfo, readLock } from './core/lock.js';
|
|
23
|
+
// Search
|
|
24
|
+
export { buildIndex, search, searchWithMetrics, emptyMetrics, tokenize, isVisible } from './core/search.js';
|
|
25
|
+
// Preflight / injection
|
|
26
|
+
export { preflight, preflightIndex, renderPack, estimateTokens } from './core/inject.js';
|
|
27
|
+
// Approval gate
|
|
28
|
+
export { requireApproval, isHumanChannel, HUMAN_CHANNELS } from './core/approval.js';
|
|
29
|
+
// Journal
|
|
30
|
+
export { appendJournal, readJournal, trimJournal } from './core/journal.js';
|
|
31
|
+
// Transcript (deja-vu)
|
|
32
|
+
export { indexTranscript, readTranscriptIndex, detectDejaVu, rebuildTranscriptIndex, TRANSCRIPT_INDEX_FILE, } from './core/transcript.js';
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|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B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAExF,gBAAgB;AAChB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEpF,UAAU;AACV,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE3E,uBAAuB;AACvB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { type ApiState } from './server.js';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP adapter: thin node:http server delegating to the pure handleApi
|
|
5
|
+
* router. Binds 127.0.0.1 by default (the panel is a local human channel).
|
|
6
|
+
*/
|
|
7
|
+
export interface ServeOptions {
|
|
8
|
+
port?: number;
|
|
9
|
+
host?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function startServer(state: ApiState, options?: ServeOptions): ReturnType<typeof createServer>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { PANEL_HTML } from './panel.js';
|
|
3
|
+
import { handleApi } from './server.js';
|
|
4
|
+
export function startServer(state, options) {
|
|
5
|
+
const server = createServer((req, res) => {
|
|
6
|
+
void route(state, req, res);
|
|
7
|
+
});
|
|
8
|
+
server.listen(options?.port ?? 7777, options?.host ?? '127.0.0.1');
|
|
9
|
+
return server;
|
|
10
|
+
}
|
|
11
|
+
async function route(state, req, res) {
|
|
12
|
+
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
13
|
+
const path = url.pathname;
|
|
14
|
+
if (req.method === 'GET' && (path === '/' || path === '/panel')) {
|
|
15
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
16
|
+
res.end(PANEL_HTML);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (path.startsWith('/api/')) {
|
|
20
|
+
let body;
|
|
21
|
+
if (req.method === 'POST') {
|
|
22
|
+
const chunks = [];
|
|
23
|
+
for await (const chunk of req)
|
|
24
|
+
chunks.push(chunk);
|
|
25
|
+
const raw = Buffer.concat(chunks).toString('utf8');
|
|
26
|
+
if (raw !== '') {
|
|
27
|
+
try {
|
|
28
|
+
body = JSON.parse(raw);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
res.writeHead(400, { 'content-type': 'application/json' });
|
|
32
|
+
res.end(JSON.stringify({ error: 'invalid JSON body' }));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const response = handleApi(state, req.method ?? 'GET', path, body);
|
|
38
|
+
res.writeHead(response.status, { 'content-type': 'application/json' });
|
|
39
|
+
res.end(JSON.stringify(response.body));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
res.writeHead(404, { 'content-type': 'application/json' });
|
|
43
|
+
res.end(JSON.stringify({ error: `no route: ${req.method} ${path}` }));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAA;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAiB,MAAM,aAAa,CAAA;AAYtD,MAAM,UAAU,WAAW,CAAC,KAAe,EAAE,OAAsB;IACjE,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACvC,KAAK,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IAC7B,CAAC,CAAC,C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AC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;oBAC1D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAA;oBACvD,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,IAAI,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;QAClE,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;QACtE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;QACtC,OAAM;IACR,CAAC;IACD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;IAC1D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ResolvedWorkspace } from '../core/registry.js';
|
|
2
|
+
import { type SearchIndex, type SearchMetrics } from '../core/search.js';
|
|
3
|
+
export interface TransportState {
|
|
4
|
+
hubRoot: string;
|
|
5
|
+
workspace: ResolvedWorkspace;
|
|
6
|
+
index: SearchIndex;
|
|
7
|
+
metrics: SearchMetrics;
|
|
8
|
+
lockToken?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createState(hubRoot: string, workspaceArg?: string): TransportState;
|
|
11
|
+
interface ToolDef {
|
|
12
|
+
description: string;
|
|
13
|
+
inputSchema: Record<string, unknown>;
|
|
14
|
+
handler: (state: TransportState, args: Record<string, unknown>) => unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare const TOOLS: Record<string, ToolDef>;
|
|
17
|
+
export declare function heartbeat(state: TransportState): boolean;
|
|
18
|
+
export interface RpcRequest {
|
|
19
|
+
jsonrpc?: string;
|
|
20
|
+
id?: number | string | null;
|
|
21
|
+
method?: string;
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export declare function handleRpc(state: TransportState, line: string): string | null;
|
|
25
|
+
/** Blocking stdio loop (server mode). Exits cleanly on EOF. */
|
|
26
|
+
export declare function serveStdio(state: TransportState): void;
|
|
27
|
+
export {};
|