@j0hanz/memory-mcp 1.1.0 → 1.2.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/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/instructions.js +2 -88
- package/dist/lib/instructions.js.map +1 -1
- package/dist/lib/tool-contracts.d.ts.map +1 -1
- package/dist/lib/tool-contracts.js +68 -13
- package/dist/lib/tool-contracts.js.map +1 -1
- package/dist/lib/tool-response.d.ts.map +1 -1
- package/dist/lib/tool-response.js +7 -8
- package/dist/lib/tool-response.js.map +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +70 -5
- package/dist/resources/index.js.map +1 -1
- package/dist/resources/instructions.d.ts +2 -0
- package/dist/resources/instructions.d.ts.map +1 -0
- package/dist/resources/instructions.js +106 -0
- package/dist/resources/instructions.js.map +1 -0
- package/dist/resources/server-config.d.ts +2 -0
- package/dist/resources/server-config.d.ts.map +1 -0
- package/dist/resources/server-config.js +72 -0
- package/dist/resources/server-config.js.map +1 -0
- package/dist/resources/tool-catalog.d.ts +2 -0
- package/dist/resources/tool-catalog.d.ts.map +1 -0
- package/dist/resources/tool-catalog.js +64 -0
- package/dist/resources/tool-catalog.js.map +1 -0
- package/dist/resources/tool-info.d.ts +5 -0
- package/dist/resources/tool-info.d.ts.map +1 -0
- package/dist/resources/tool-info.js +129 -0
- package/dist/resources/tool-info.js.map +1 -0
- package/dist/resources/workflows.d.ts +2 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +55 -0
- package/dist/resources/workflows.js.map +1 -0
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +55 -27
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/schemas/outputs.d.ts.map +1 -1
- package/dist/schemas/outputs.js +144 -91
- package/dist/schemas/outputs.js.map +1 -1
- package/dist/tools/get-relationships.js +1 -1
- package/dist/tools/get-relationships.js.map +1 -1
- package/dist/tools/progress.d.ts.map +1 -1
- package/dist/tools/progress.js +3 -5
- package/dist/tools/progress.js.map +1 -1
- package/dist/tools/retrieve-context.d.ts.map +1 -1
- package/dist/tools/retrieve-context.js +4 -6
- package/dist/tools/retrieve-context.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAIA,wBAAgB,gBAAgB,IAAI,MAAM,CAOzC"}
|
package/dist/lib/instructions.js
CHANGED
|
@@ -1,96 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const SHARED_CONSTRAINTS = [
|
|
3
|
-
'Idempotence: `store_memory` and `store_memories` return `created: false` if content+tags already exist.',
|
|
4
|
-
'Atomic Transactions: `store_memories` and `delete_memories` roll back entirely on unexpected errors.',
|
|
5
|
-
'Hash Changes: `update_memory` changes the hash when content or tags change. Relationships survive via CASCADE.',
|
|
6
|
-
'FTS Search Limits: Query terms matched individually (all-OR logic). Phrase operators and negation not supported.',
|
|
7
|
-
'Recall Limits: BFS traversal is bounded by env vars (RECALL_MAX_FRONTIER_SIZE, RECALL_MAX_EDGE_ROWS, RECALL_MAX_VISITED_NODES). Returns `aborted: true` with partial results when limits are hit.',
|
|
8
|
-
];
|
|
9
|
-
const ERROR_CODES = [
|
|
10
|
-
'| Code | Meaning |',
|
|
11
|
-
'| --- | --- |',
|
|
12
|
-
'| `E_NOT_FOUND` | Hash or relationship does not exist |',
|
|
13
|
-
'| `E_CONFLICT` | `update_memory` target content+tags already maps to an existing hash |',
|
|
14
|
-
'| `E_CANCELLED` | Request was cancelled |',
|
|
15
|
-
'| `E_UNKNOWN` | Unexpected internal error — retry once |',
|
|
16
|
-
];
|
|
17
|
-
const DATA_MODEL = `
|
|
18
|
-
### Memory
|
|
19
|
-
- \`hash\` — SHA-256 of \`(content + sorted tags)\`; deterministic; changes when content or tags change
|
|
20
|
-
- \`content\` — Text; 1–100,000 chars
|
|
21
|
-
- \`tags\` — Array; 1–100 tags; each 1–50 chars, no whitespace; minimum 1 required
|
|
22
|
-
- \`memory_type\` — \`general\` | \`fact\` | \`plan\` | \`decision\` | \`reflection\` | \`lesson\` | \`error\` | \`gradient\` (default \`general\`)
|
|
23
|
-
- \`importance\` — Integer 0–10 (default 0; 10 = critical)
|
|
24
|
-
- \`created_at\`, \`updated_at\` — ISO 8601 timestamps
|
|
25
|
-
|
|
26
|
-
### Relationship
|
|
27
|
-
- Directed edge: \`from_hash -[relation_type]-> to_hash\`
|
|
28
|
-
- \`relation_type\` — Free-form string, 1–50 chars, no whitespace
|
|
29
|
-
- Suggested types: \`related_to\`, \`causes\`, \`depends_on\`, \`parent_of\`, \`child_of\`, \`supersedes\`, \`contradicts\`, \`supports\`, \`references\`
|
|
30
|
-
- Both endpoints must exist before creating a relationship
|
|
31
|
-
- Cascade-deleted when either endpoint memory is deleted
|
|
32
|
-
- Cascade-updated when either endpoint hash changes (ON UPDATE CASCADE)
|
|
33
|
-
`;
|
|
34
|
-
const WORKFLOWS = `
|
|
35
|
-
### Store and Link
|
|
36
|
-
\`\`\`
|
|
37
|
-
store_memories({ items: [...] }) → { items[].hash, succeeded, failed }
|
|
38
|
-
create_relationship({ from_hash, to_hash, relation_type }) × N
|
|
39
|
-
\`\`\`
|
|
40
|
-
|
|
41
|
-
### Search and Read
|
|
42
|
-
\`\`\`
|
|
43
|
-
search_memories({ query, limit }) → { memories[], nextCursor }
|
|
44
|
-
# or, for relationship navigation:
|
|
45
|
-
recall({ query, depth: 1 }) → { memories[], graph[] }
|
|
46
|
-
\`\`\`
|
|
47
|
-
|
|
48
|
-
### Fill Context Window
|
|
49
|
-
\`\`\`
|
|
50
|
-
retrieve_context({ query, token_budget: 4000, strategy: 'relevance' })
|
|
51
|
-
→ { memories[], estimated_tokens, truncated }
|
|
52
|
-
\`\`\`
|
|
53
|
-
|
|
54
|
-
### Update a Memory
|
|
55
|
-
\`\`\`
|
|
56
|
-
update_memory({ hash, content }) → { old_hash, new_hash }
|
|
57
|
-
# Existing relationships auto-update to new_hash via CASCADE
|
|
58
|
-
\`\`\`
|
|
59
|
-
|
|
60
|
-
### Batch Delete
|
|
61
|
-
\`\`\`
|
|
62
|
-
delete_memories({ hashes: [...] }) → { items[].{ hash, deleted }, succeeded, failed }
|
|
63
|
-
# deleted: false means hash not found — not an error
|
|
64
|
-
\`\`\`
|
|
65
|
-
`;
|
|
1
|
+
import { buildServerInstructions } from '../resources/instructions.js';
|
|
66
2
|
let cachedInstructions;
|
|
67
3
|
export function loadInstructions() {
|
|
68
4
|
if (cachedInstructions !== undefined) {
|
|
69
5
|
return cachedInstructions;
|
|
70
6
|
}
|
|
71
|
-
|
|
72
|
-
const toolRows = contracts.map((c) => {
|
|
73
|
-
return `| \`${c.name}\` | ${c.description.split('.')[0] ?? ''} |`;
|
|
74
|
-
});
|
|
75
|
-
cachedInstructions = [
|
|
76
|
-
'# Memory MCP — Usage Guide',
|
|
77
|
-
'## Tool Routing',
|
|
78
|
-
'| Tool | Purpose |',
|
|
79
|
-
'| --- | --- |',
|
|
80
|
-
...toolRows,
|
|
81
|
-
'',
|
|
82
|
-
'## Shared Constraints',
|
|
83
|
-
SHARED_CONSTRAINTS.map((c) => `- ${c}`).join('\n'),
|
|
84
|
-
'## Error Codes',
|
|
85
|
-
ERROR_CODES.join('\n'),
|
|
86
|
-
'## Data Model',
|
|
87
|
-
DATA_MODEL,
|
|
88
|
-
'## Common Workflows',
|
|
89
|
-
WORKFLOWS,
|
|
90
|
-
'## Resources',
|
|
91
|
-
'- `internal://instructions` — This document. Read for tool routing, error codes, and workflows.',
|
|
92
|
-
'- `memory://memories/{hash}` — Fetch a single memory by URI with hash auto-completion.',
|
|
93
|
-
].join('\n\n');
|
|
7
|
+
cachedInstructions = buildServerInstructions();
|
|
94
8
|
return cachedInstructions;
|
|
95
9
|
}
|
|
96
10
|
//# sourceMappingURL=instructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,IAAI,kBAAsC,CAAC;AAE3C,MAAM,UAAU,gBAAgB;IAC9B,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,kBAAkB,GAAG,uBAAuB,EAAE,CAAC;IAC/C,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-contracts.d.ts","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,QAAQ,CAAC;AAgChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;IACvB,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC;IACxB,WAAW,EAAE;QACX,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"tool-contracts.d.ts","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,QAAQ,CAAC;AAgChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;IACvB,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC;IACxB,WAAW,EAAE;QACX,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,YAAY,EA6KxC,CAAC;AAEF,wBAAgB,gBAAgB,IAAI,YAAY,EAAE,CAEjD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAM1D"}
|
|
@@ -8,7 +8,12 @@ export const TOOL_CONTRACTS = [
|
|
|
8
8
|
description: 'Store a single memory with content, tags, and optional type/importance. Returns the SHA-256 hash. Idempotent — storing the same content+tags returns the existing hash with `created: false`. For storing multiple memories at once, prefer `store_memories`.',
|
|
9
9
|
inputSchema: StoreMemoryInputSchema,
|
|
10
10
|
outputSchema: StoreResultSchema,
|
|
11
|
-
annotations: {
|
|
11
|
+
annotations: {
|
|
12
|
+
readOnlyHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
openWorldHint: false,
|
|
16
|
+
},
|
|
12
17
|
},
|
|
13
18
|
{
|
|
14
19
|
name: 'store_memories',
|
|
@@ -16,7 +21,12 @@ export const TOOL_CONTRACTS = [
|
|
|
16
21
|
description: 'Store up to 50 memories atomically. Each item is independently idempotent — same content+tags returns existing hash with `created: false`. Returns per-item results. Transaction rolls back entirely on unexpected error.',
|
|
17
22
|
inputSchema: StoreMemoriesInputSchema,
|
|
18
23
|
outputSchema: BatchResultSchema,
|
|
19
|
-
annotations: {
|
|
24
|
+
annotations: {
|
|
25
|
+
readOnlyHint: false,
|
|
26
|
+
idempotentHint: true,
|
|
27
|
+
destructiveHint: false,
|
|
28
|
+
openWorldHint: false,
|
|
29
|
+
},
|
|
20
30
|
},
|
|
21
31
|
{
|
|
22
32
|
name: 'get_memory',
|
|
@@ -24,7 +34,11 @@ export const TOOL_CONTRACTS = [
|
|
|
24
34
|
description: 'Retrieve a single memory by its exact SHA-256 hash. Returns the full memory object or E_NOT_FOUND. Use `search_memories` or `recall` when you do not know the exact hash.',
|
|
25
35
|
inputSchema: GetMemoryInputSchema,
|
|
26
36
|
outputSchema: MemoryResultSchema,
|
|
27
|
-
annotations: {
|
|
37
|
+
annotations: {
|
|
38
|
+
readOnlyHint: true,
|
|
39
|
+
destructiveHint: false,
|
|
40
|
+
openWorldHint: false,
|
|
41
|
+
},
|
|
28
42
|
},
|
|
29
43
|
{
|
|
30
44
|
name: 'search_memories',
|
|
@@ -32,7 +46,11 @@ export const TOOL_CONTRACTS = [
|
|
|
32
46
|
description: 'Full-text search over memory content and tags using FTS5. Returns ranked results with cursor pagination. Query terms are individually matched (all-OR logic; FTS5 phrase operators and negation are not supported). Use `recall` when you need to follow relationships between memories after the search.',
|
|
33
47
|
inputSchema: SearchMemoriesInputSchema,
|
|
34
48
|
outputSchema: SearchResultSchema,
|
|
35
|
-
annotations: {
|
|
49
|
+
annotations: {
|
|
50
|
+
readOnlyHint: true,
|
|
51
|
+
destructiveHint: false,
|
|
52
|
+
openWorldHint: false,
|
|
53
|
+
},
|
|
36
54
|
},
|
|
37
55
|
{
|
|
38
56
|
name: 'retrieve_context',
|
|
@@ -40,7 +58,11 @@ export const TOOL_CONTRACTS = [
|
|
|
40
58
|
description: 'FTS search with automatic token-budget management. Returns relevance-ranked memories totalling at most `token_budget` tokens. `strategy` controls sort: `relevance` (FTS rank, default), `importance` (highest first), or `recency` (newest first). Returns `truncated: true` when budget was reached before all candidates were included.',
|
|
41
59
|
inputSchema: RetrieveContextInputSchema,
|
|
42
60
|
outputSchema: RetrieveContextResultSchema,
|
|
43
|
-
annotations: {
|
|
61
|
+
annotations: {
|
|
62
|
+
readOnlyHint: true,
|
|
63
|
+
destructiveHint: false,
|
|
64
|
+
openWorldHint: false,
|
|
65
|
+
},
|
|
44
66
|
},
|
|
45
67
|
{
|
|
46
68
|
name: 'recall',
|
|
@@ -48,7 +70,11 @@ export const TOOL_CONTRACTS = [
|
|
|
48
70
|
description: 'Search for memories and explore their connections (knowledge graph). FTS search then BFS graph traversal up to `depth` hops. Returns all discovered memories and edges. Use when exploring memory relationships or understanding context. Emits progress per hop. Returns `aborted: true` with partial results when safety limits are hit (env: RECALL_MAX_FRONTIER_SIZE, RECALL_MAX_EDGE_ROWS, RECALL_MAX_VISITED_NODES).',
|
|
49
71
|
inputSchema: RecallInputSchema,
|
|
50
72
|
outputSchema: RecallResultSchema,
|
|
51
|
-
annotations: {
|
|
73
|
+
annotations: {
|
|
74
|
+
readOnlyHint: true,
|
|
75
|
+
destructiveHint: false,
|
|
76
|
+
openWorldHint: false,
|
|
77
|
+
},
|
|
52
78
|
},
|
|
53
79
|
{
|
|
54
80
|
name: 'update_memory',
|
|
@@ -56,7 +82,11 @@ export const TOOL_CONTRACTS = [
|
|
|
56
82
|
description: 'Replace the content (and optionally tags) of an existing memory. Returns both old and new SHA-256 hashes, since content changes alter the hash. Returns E_NOT_FOUND if the memory does not exist; E_CONFLICT if the new content+tags already maps to an existing hash.',
|
|
57
83
|
inputSchema: UpdateMemoryInputSchema,
|
|
58
84
|
outputSchema: UpdateResultSchema,
|
|
59
|
-
annotations: {
|
|
85
|
+
annotations: {
|
|
86
|
+
readOnlyHint: false,
|
|
87
|
+
destructiveHint: true,
|
|
88
|
+
openWorldHint: false,
|
|
89
|
+
},
|
|
60
90
|
},
|
|
61
91
|
{
|
|
62
92
|
name: 'delete_memory',
|
|
@@ -64,7 +94,11 @@ export const TOOL_CONTRACTS = [
|
|
|
64
94
|
description: 'Delete a single memory by its SHA-256 hash. Cascade-deletes all relationships involving it. Returns E_NOT_FOUND if the hash does not exist.',
|
|
65
95
|
inputSchema: DeleteMemoryInputSchema,
|
|
66
96
|
outputSchema: DeleteResultSchema,
|
|
67
|
-
annotations: {
|
|
97
|
+
annotations: {
|
|
98
|
+
readOnlyHint: false,
|
|
99
|
+
destructiveHint: true,
|
|
100
|
+
openWorldHint: false,
|
|
101
|
+
},
|
|
68
102
|
},
|
|
69
103
|
{
|
|
70
104
|
name: 'delete_memories',
|
|
@@ -72,7 +106,11 @@ export const TOOL_CONTRACTS = [
|
|
|
72
106
|
description: 'Delete up to 50 memories atomically. Cascade-deletes all relationships for each hash. Per-item `deleted: false` means the hash was not found — not an error, the batch still succeeds. Transaction rolls back entirely on unexpected error.',
|
|
73
107
|
inputSchema: DeleteMemoriesInputSchema,
|
|
74
108
|
outputSchema: BatchResultSchema,
|
|
75
|
-
annotations: {
|
|
109
|
+
annotations: {
|
|
110
|
+
readOnlyHint: false,
|
|
111
|
+
destructiveHint: true,
|
|
112
|
+
openWorldHint: false,
|
|
113
|
+
},
|
|
76
114
|
},
|
|
77
115
|
{
|
|
78
116
|
name: 'create_relationship',
|
|
@@ -80,7 +118,12 @@ export const TOOL_CONTRACTS = [
|
|
|
80
118
|
description: 'Create a directed labeled edge between two memories. Idempotent — re-creating an existing relationship is a no-op and returns `created: false`. Both endpoint memories must already exist, otherwise returns E_NOT_FOUND for the missing endpoint.',
|
|
81
119
|
inputSchema: CreateRelationshipInputSchema,
|
|
82
120
|
outputSchema: CreateRelationshipResultSchema,
|
|
83
|
-
annotations: {
|
|
121
|
+
annotations: {
|
|
122
|
+
readOnlyHint: false,
|
|
123
|
+
idempotentHint: true,
|
|
124
|
+
destructiveHint: false,
|
|
125
|
+
openWorldHint: false,
|
|
126
|
+
},
|
|
84
127
|
},
|
|
85
128
|
{
|
|
86
129
|
name: 'delete_relationship',
|
|
@@ -88,7 +131,11 @@ export const TOOL_CONTRACTS = [
|
|
|
88
131
|
description: 'Remove a single directed relationship edge between two memories. All three fields (from_hash, to_hash, relation_type) must match exactly. Returns E_NOT_FOUND if the exact relationship does not exist.',
|
|
89
132
|
inputSchema: DeleteRelationshipInputSchema,
|
|
90
133
|
outputSchema: DeleteRelationshipResultSchema,
|
|
91
|
-
annotations: {
|
|
134
|
+
annotations: {
|
|
135
|
+
readOnlyHint: false,
|
|
136
|
+
destructiveHint: true,
|
|
137
|
+
openWorldHint: false,
|
|
138
|
+
},
|
|
92
139
|
},
|
|
93
140
|
{
|
|
94
141
|
name: 'get_relationships',
|
|
@@ -96,7 +143,11 @@ export const TOOL_CONTRACTS = [
|
|
|
96
143
|
description: 'Retrieve all relationships for a memory, with the related memory inlined. Filter by direction (outgoing | incoming | both). Returns E_NOT_FOUND if the source memory does not exist.',
|
|
97
144
|
inputSchema: GetRelationshipsInputSchema,
|
|
98
145
|
outputSchema: RelationshipResultSchema,
|
|
99
|
-
annotations: {
|
|
146
|
+
annotations: {
|
|
147
|
+
readOnlyHint: true,
|
|
148
|
+
destructiveHint: false,
|
|
149
|
+
openWorldHint: false,
|
|
150
|
+
},
|
|
100
151
|
},
|
|
101
152
|
{
|
|
102
153
|
name: 'memory_stats',
|
|
@@ -104,7 +155,11 @@ export const TOOL_CONTRACTS = [
|
|
|
104
155
|
description: 'Return aggregate statistics: total memories, total relationships, oldest/newest timestamps, average importance, and per-type counts. No input required.',
|
|
105
156
|
inputSchema: MemoryStatsInputSchema,
|
|
106
157
|
outputSchema: StatsResultSchema,
|
|
107
|
-
annotations: {
|
|
158
|
+
annotations: {
|
|
159
|
+
readOnlyHint: true,
|
|
160
|
+
destructiveHint: false,
|
|
161
|
+
openWorldHint: false,
|
|
162
|
+
},
|
|
108
163
|
},
|
|
109
164
|
];
|
|
110
165
|
export function getToolContracts() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-contracts.js","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAgB/B,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,cAAc;QACrB,WAAW,EACT,+PAA+P;QACjQ,WAAW,EAAE,sBAAsB;QACnC,YAAY,EAAE,iBAAiB;QAC/B,WAAW,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"tool-contracts.js","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,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ings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-response.d.ts","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAyBzE,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,cAAc,CAKhB;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,cAAc,CAKhB"}
|
|
@@ -7,17 +7,16 @@ function createStructuredError(code, message) {
|
|
|
7
7
|
error: { code, message },
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
export function createToolResponse(payload) {
|
|
11
11
|
return {
|
|
12
|
-
content: [toTextContent(
|
|
13
|
-
structuredContent:
|
|
14
|
-
...(isError ? { isError: true } : {}),
|
|
12
|
+
content: [toTextContent(payload)],
|
|
13
|
+
structuredContent: payload,
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
export function createToolResponse(payload) {
|
|
18
|
-
return buildResponse(payload);
|
|
19
|
-
}
|
|
20
16
|
export function createErrorResponse(code, message) {
|
|
21
|
-
return
|
|
17
|
+
return {
|
|
18
|
+
content: [toTextContent(createStructuredError(code, message))],
|
|
19
|
+
isError: true,
|
|
20
|
+
};
|
|
22
21
|
}
|
|
23
22
|
//# sourceMappingURL=tool-response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-response.js","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAWA,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,qBAAqB,CAC5B,IAAY,EACZ,OAAe;IAEf,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC;AACJ,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"tool-response.js","sourceRoot":"","sources":["../../src/lib/tool-response.ts"],"names":[],"mappings":"AAWA,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,qBAAqB,CAC5B,IAAY,EACZ,OAAe;IAEf,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAAgC;IAEhC,OAAO;QACL,OAAO,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACjC,iBAAiB,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,OAAe;IAEf,OAAO;QACL,OAAO,EAAE,CAAC,aAAa,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9D,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA2E9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAkJzE"}
|
package/dist/resources/index.js
CHANGED
|
@@ -4,9 +4,20 @@ import { createHashCompletionCallback } from '../completions/index.js';
|
|
|
4
4
|
import { loadInstructions } from '../lib/instructions.js';
|
|
5
5
|
import { SELECT_MEMORY_BY_HASH_SQL } from '../lib/sql.js';
|
|
6
6
|
import { parseMemoryRow } from '../lib/types.js';
|
|
7
|
+
import { buildServerConfig } from './server-config.js';
|
|
8
|
+
import { buildToolCatalog } from './tool-catalog.js';
|
|
9
|
+
import { getToolInfo, getToolNames } from './tool-info.js';
|
|
10
|
+
import { buildWorkflowGuide } from './workflows.js';
|
|
7
11
|
const HASH_REGEX = /^[a-f0-9]{64}$/;
|
|
8
12
|
const INSTRUCTIONS_URI = 'internal://instructions';
|
|
13
|
+
const TOOL_CATALOG_URI = 'internal://tool-catalog';
|
|
14
|
+
const TOOL_INFO_URI_TEMPLATE = 'internal://tool-info/{toolName}';
|
|
15
|
+
const WORKFLOWS_URI = 'internal://workflows';
|
|
16
|
+
const SERVER_CONFIG_URI = 'internal://server-config';
|
|
9
17
|
const MEMORY_RESOURCE_URI_TEMPLATE = 'memory://memories/{hash}';
|
|
18
|
+
function createMarkdownContent(uri, text) {
|
|
19
|
+
return { uri, mimeType: 'text/markdown', text };
|
|
20
|
+
}
|
|
10
21
|
function createJsonContent(uri, payload) {
|
|
11
22
|
return {
|
|
12
23
|
uri,
|
|
@@ -25,22 +36,76 @@ function getSingleVariable(value) {
|
|
|
25
36
|
function readMemoryByHash(db, hash) {
|
|
26
37
|
return db.prepareOnce(SELECT_MEMORY_BY_HASH_SQL).get(hash);
|
|
27
38
|
}
|
|
39
|
+
// --- Pre-computed static content ---
|
|
28
40
|
const INSTRUCTIONS_CONTENT = loadInstructions();
|
|
41
|
+
const TOOL_CATALOG_CONTENT = buildToolCatalog();
|
|
42
|
+
const WORKFLOW_GUIDE_CONTENT = buildWorkflowGuide();
|
|
43
|
+
const SERVER_CONFIG_CONTENT = buildServerConfig();
|
|
44
|
+
// --- Registration ---
|
|
29
45
|
export function registerAllResources(server, db) {
|
|
46
|
+
// internal://instructions
|
|
30
47
|
server.registerResource('instructions', INSTRUCTIONS_URI, {
|
|
31
48
|
title: 'Memory Instructions',
|
|
32
49
|
description: 'Complete usage guide: tool inventory, routing decisions, error codes, data model, and workflow patterns. Read this first.',
|
|
33
50
|
mimeType: 'text/markdown',
|
|
34
51
|
annotations: { audience: ['assistant'], priority: 0.9 },
|
|
52
|
+
}, () => ({
|
|
53
|
+
contents: [createMarkdownContent(INSTRUCTIONS_URI, INSTRUCTIONS_CONTENT)],
|
|
54
|
+
}));
|
|
55
|
+
// internal://tool-catalog
|
|
56
|
+
server.registerResource('tool-catalog', TOOL_CATALOG_URI, {
|
|
57
|
+
title: 'Tool Catalog',
|
|
58
|
+
description: 'Tool reference table, optional parameter matrix, and cross-tool data flow.',
|
|
59
|
+
mimeType: 'text/markdown',
|
|
60
|
+
annotations: { audience: ['assistant'], priority: 0.7 },
|
|
61
|
+
}, () => ({
|
|
62
|
+
contents: [createMarkdownContent(TOOL_CATALOG_URI, TOOL_CATALOG_CONTENT)],
|
|
63
|
+
}));
|
|
64
|
+
// internal://tool-info/{toolName}
|
|
65
|
+
server.registerResource('tool-info', new ResourceTemplate(TOOL_INFO_URI_TEMPLATE, {
|
|
66
|
+
list: undefined,
|
|
67
|
+
complete: {
|
|
68
|
+
toolName: (value) => getToolNames().filter((n) => n.startsWith(value)),
|
|
69
|
+
},
|
|
70
|
+
}), {
|
|
71
|
+
title: 'Tool Info',
|
|
72
|
+
description: 'Per-tool detail: parameters, behavior, and output shape. Supports toolName auto-completion.',
|
|
73
|
+
mimeType: 'text/markdown',
|
|
74
|
+
annotations: { audience: ['assistant'], priority: 0.6 },
|
|
75
|
+
}, (uri, variables) => {
|
|
76
|
+
const toolName = getSingleVariable(variables['toolName']);
|
|
77
|
+
if (!toolName) {
|
|
78
|
+
throw new McpError(ErrorCode.InvalidParams, 'Missing toolName parameter');
|
|
79
|
+
}
|
|
80
|
+
const info = getToolInfo(toolName);
|
|
81
|
+
if (!info) {
|
|
82
|
+
throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${toolName}`);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
contents: [createMarkdownContent(uri.href, info)],
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
// internal://workflows
|
|
89
|
+
server.registerResource('workflows', WORKFLOWS_URI, {
|
|
90
|
+
title: 'Workflow Guide',
|
|
91
|
+
description: 'Recommended multi-step workflow sequences with guardrails and tool reference.',
|
|
92
|
+
mimeType: 'text/markdown',
|
|
93
|
+
annotations: { audience: ['assistant'], priority: 0.7 },
|
|
94
|
+
}, () => ({
|
|
95
|
+
contents: [createMarkdownContent(WORKFLOWS_URI, WORKFLOW_GUIDE_CONTENT)],
|
|
96
|
+
}));
|
|
97
|
+
// internal://server-config
|
|
98
|
+
server.registerResource('server-config', SERVER_CONFIG_URI, {
|
|
99
|
+
title: 'Server Configuration',
|
|
100
|
+
description: 'Runtime configuration, environment variables, capabilities, and data limits.',
|
|
101
|
+
mimeType: 'text/markdown',
|
|
102
|
+
annotations: { audience: ['user', 'assistant'], priority: 0.5 },
|
|
35
103
|
}, () => ({
|
|
36
104
|
contents: [
|
|
37
|
-
|
|
38
|
-
uri: INSTRUCTIONS_URI,
|
|
39
|
-
mimeType: 'text/markdown',
|
|
40
|
-
text: INSTRUCTIONS_CONTENT,
|
|
41
|
-
},
|
|
105
|
+
createMarkdownContent(SERVER_CONFIG_URI, SERVER_CONFIG_CONTENT),
|
|
42
106
|
],
|
|
43
107
|
}));
|
|
108
|
+
// memory://memories/{hash}
|
|
44
109
|
const hashCompletion = createHashCompletionCallback(db);
|
|
45
110
|
server.registerResource('memory', new ResourceTemplate(MEMORY_RESOURCE_URI_TEMPLATE, {
|
|
46
111
|
list: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAEpC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,sBAAsB,GAAG,iCAAiC,CAAC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ts","sourceRoot":"","sources":["../../src/resources/instructions.ts"],"names":[],"mappings":"AAsFA,wBAAgB,uBAAuB,IAAI,MAAM,CA0BhD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getToolContracts } from '../lib/tool-contracts.js';
|
|
2
|
+
import { getSharedConstraints } from './tool-info.js';
|
|
3
|
+
const PROMPTS_INVENTORY = ['- `get-help` — Return full usage instructions.'];
|
|
4
|
+
const RESOURCES_INVENTORY = [
|
|
5
|
+
'- `internal://instructions` — This document. Read for tool routing, error codes, and workflows.',
|
|
6
|
+
'- `internal://tool-catalog` — Tool reference table, optional parameter matrix, and cross-tool data flow.',
|
|
7
|
+
'- `internal://tool-info/{toolName}` — Per-tool detail: parameters, behavior, and output shape.',
|
|
8
|
+
'- `internal://workflows` — Recommended multi-step workflow sequences.',
|
|
9
|
+
'- `internal://server-config` — Runtime configuration, limits, and capabilities.',
|
|
10
|
+
'- `memory://memories/{hash}` — Fetch a single memory by URI with hash auto-completion.',
|
|
11
|
+
];
|
|
12
|
+
const ERROR_CODES = [
|
|
13
|
+
'| Code | Meaning |',
|
|
14
|
+
'| --- | --- |',
|
|
15
|
+
'| `E_NOT_FOUND` | Hash or relationship does not exist |',
|
|
16
|
+
'| `E_CONFLICT` | `update_memory` target content+tags already maps to an existing hash |',
|
|
17
|
+
'| `E_CANCELLED` | Request was cancelled |',
|
|
18
|
+
'| `E_UNKNOWN` | Unexpected internal error — retry once |',
|
|
19
|
+
];
|
|
20
|
+
const DATA_MODEL = `### Memory
|
|
21
|
+
- \`hash\` — SHA-256 of \`(content + sorted tags)\`; deterministic; changes when content or tags change
|
|
22
|
+
- \`content\` — Text; 1–100,000 chars
|
|
23
|
+
- \`tags\` — Array; 1–100 tags; each 1–50 chars, no whitespace; minimum 1 required
|
|
24
|
+
- \`memory_type\` — \`general\` | \`fact\` | \`plan\` | \`decision\` | \`reflection\` | \`lesson\` | \`error\` | \`gradient\` (default \`general\`)
|
|
25
|
+
- \`importance\` — Integer 0–10 (default 0; 10 = critical)
|
|
26
|
+
- \`created_at\`, \`updated_at\` — ISO 8601 timestamps
|
|
27
|
+
|
|
28
|
+
### Relationship
|
|
29
|
+
- Directed edge: \`from_hash -[relation_type]-> to_hash\`
|
|
30
|
+
- \`relation_type\` — Free-form string, 1–50 chars, no whitespace
|
|
31
|
+
- Suggested types: \`related_to\`, \`causes\`, \`depends_on\`, \`parent_of\`, \`child_of\`, \`supersedes\`, \`contradicts\`, \`supports\`, \`references\`
|
|
32
|
+
- Both endpoints must exist before creating a relationship
|
|
33
|
+
- Cascade-deleted when either endpoint memory is deleted
|
|
34
|
+
- Cascade-updated when either endpoint hash changes (ON UPDATE CASCADE)`;
|
|
35
|
+
const WORKFLOWS = `### Store and Link
|
|
36
|
+
\`\`\`
|
|
37
|
+
store_memories({ items: [...] }) → { items[].hash, succeeded, failed }
|
|
38
|
+
create_relationship({ from_hash, to_hash, relation_type }) × N
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
### Search and Read
|
|
42
|
+
\`\`\`
|
|
43
|
+
search_memories({ query, limit }) → { memories[], nextCursor }
|
|
44
|
+
# or, for relationship navigation:
|
|
45
|
+
recall({ query, depth: 1 }) → { memories[], graph[] }
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
### Fill Context Window
|
|
49
|
+
\`\`\`
|
|
50
|
+
retrieve_context({ query, token_budget: 4000, strategy: 'relevance' })
|
|
51
|
+
→ { memories[], estimated_tokens, truncated }
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
### Update a Memory
|
|
55
|
+
\`\`\`
|
|
56
|
+
update_memory({ hash, content }) → { old_hash, new_hash }
|
|
57
|
+
# Existing relationships auto-update to new_hash via CASCADE
|
|
58
|
+
\`\`\`
|
|
59
|
+
|
|
60
|
+
### Batch Delete
|
|
61
|
+
\`\`\`
|
|
62
|
+
delete_memories({ hashes: [...] }) → { items[].{ hash, deleted }, succeeded, failed }
|
|
63
|
+
# deleted: false means hash not found — not an error
|
|
64
|
+
\`\`\``;
|
|
65
|
+
function buildToolRouting() {
|
|
66
|
+
const contracts = getToolContracts();
|
|
67
|
+
const rows = contracts.map((c) => {
|
|
68
|
+
const purpose = c.description.split('.')[0] ?? '';
|
|
69
|
+
return `| \`${c.name}\` | ${purpose} |`;
|
|
70
|
+
});
|
|
71
|
+
return [
|
|
72
|
+
'## Tool Routing',
|
|
73
|
+
'',
|
|
74
|
+
'| Tool | Purpose |',
|
|
75
|
+
'| --- | --- |',
|
|
76
|
+
...rows,
|
|
77
|
+
].join('\n');
|
|
78
|
+
}
|
|
79
|
+
export function buildServerInstructions() {
|
|
80
|
+
return [
|
|
81
|
+
'# Memory MCP — Usage Guide',
|
|
82
|
+
'',
|
|
83
|
+
buildToolRouting(),
|
|
84
|
+
'',
|
|
85
|
+
'## Shared Constraints',
|
|
86
|
+
getSharedConstraints()
|
|
87
|
+
.map((c) => `- ${c}`)
|
|
88
|
+
.join('\n'),
|
|
89
|
+
'',
|
|
90
|
+
'## Error Codes',
|
|
91
|
+
ERROR_CODES.join('\n'),
|
|
92
|
+
'',
|
|
93
|
+
'## Data Model',
|
|
94
|
+
DATA_MODEL,
|
|
95
|
+
'',
|
|
96
|
+
'## Common Workflows',
|
|
97
|
+
WORKFLOWS,
|
|
98
|
+
'',
|
|
99
|
+
'## Prompts',
|
|
100
|
+
PROMPTS_INVENTORY.join('\n'),
|
|
101
|
+
'',
|
|
102
|
+
'## Resources',
|
|
103
|
+
RESOURCES_INVENTORY.join('\n'),
|
|
104
|
+
].join('\n');
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/resources/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,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,qBAAqB;QACrB,SAAS;QACT,EAAE;QACF,YAAY;QACZ,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,EAAE;QACF,cAAc;QACd,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC;KAC/B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-config.d.ts","sourceRoot":"","sources":["../../src/resources/server-config.ts"],"names":[],"mappings":"AAgDA,wBAAgB,iBAAiB,IAAI,MAAM,CA8B1C"}
|