@totalreclaw/mcp-server 1.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 +113 -0
- package/dist/cli/setup.d.ts +43 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +276 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +700 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.d.ts +27 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +219 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +8 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/memory-context.d.ts +16 -0
- package/dist/resources/memory-context.d.ts.map +1 -0
- package/dist/resources/memory-context.js +111 -0
- package/dist/resources/memory-context.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/subgraph/crypto.d.ts +106 -0
- package/dist/subgraph/crypto.d.ts.map +1 -0
- package/dist/subgraph/crypto.js +287 -0
- package/dist/subgraph/crypto.js.map +1 -0
- package/dist/subgraph/embedding.d.ts +47 -0
- package/dist/subgraph/embedding.d.ts.map +1 -0
- package/dist/subgraph/embedding.js +77 -0
- package/dist/subgraph/embedding.js.map +1 -0
- package/dist/subgraph/index.d.ts +7 -0
- package/dist/subgraph/index.d.ts.map +1 -0
- package/dist/subgraph/index.js +23 -0
- package/dist/subgraph/index.js.map +1 -0
- package/dist/subgraph/lsh.d.ts +95 -0
- package/dist/subgraph/lsh.d.ts.map +1 -0
- package/dist/subgraph/lsh.js +211 -0
- package/dist/subgraph/lsh.js.map +1 -0
- package/dist/subgraph/reranker.d.ts +157 -0
- package/dist/subgraph/reranker.d.ts.map +1 -0
- package/dist/subgraph/reranker.js +427 -0
- package/dist/subgraph/reranker.js.map +1 -0
- package/dist/subgraph/search.d.ts +62 -0
- package/dist/subgraph/search.d.ts.map +1 -0
- package/dist/subgraph/search.js +208 -0
- package/dist/subgraph/search.js.map +1 -0
- package/dist/subgraph/store.d.ts +97 -0
- package/dist/subgraph/store.d.ts.map +1 -0
- package/dist/subgraph/store.js +270 -0
- package/dist/subgraph/store.js.map +1 -0
- package/dist/tools/export.d.ts +48 -0
- package/dist/tools/export.d.ts.map +1 -0
- package/dist/tools/export.js +126 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/forget.d.ts +43 -0
- package/dist/tools/forget.d.ts.map +1 -0
- package/dist/tools/forget.js +96 -0
- package/dist/tools/forget.js.map +1 -0
- package/dist/tools/import.d.ts +73 -0
- package/dist/tools/import.d.ts.map +1 -0
- package/dist/tools/import.js +248 -0
- package/dist/tools/import.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +25 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/recall.d.ts +65 -0
- package/dist/tools/recall.d.ts.map +1 -0
- package/dist/tools/recall.js +113 -0
- package/dist/tools/recall.js.map +1 -0
- package/dist/tools/remember.d.ts +109 -0
- package/dist/tools/remember.d.ts.map +1 -0
- package/dist/tools/remember.js +227 -0
- package/dist/tools/remember.js.map +1 -0
- package/dist/tools/status.d.ts +43 -0
- package/dist/tools/status.d.ts.map +1 -0
- package/dist/tools/status.js +110 -0
- package/dist/tools/status.js.map +1 -0
- package/dist/tools/upgrade.d.ts +48 -0
- package/dist/tools/upgrade.d.ts.map +1 -0
- package/dist/tools/upgrade.js +122 -0
- package/dist/tools/upgrade.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP - Subgraph search path
|
|
4
|
+
*
|
|
5
|
+
* Queries facts via GraphQL hash_in through the relay server.
|
|
6
|
+
*
|
|
7
|
+
* Used when subgraph mode is enabled. Replaces the HTTP POST
|
|
8
|
+
* to /v1/search with a GraphQL query to the subgraph via the relay server.
|
|
9
|
+
*
|
|
10
|
+
* The relay server proxies GraphQL queries to Graph Studio with its own
|
|
11
|
+
* API key at `${relayUrl}/v1/subgraph`. Clients never need a subgraph endpoint.
|
|
12
|
+
*
|
|
13
|
+
* Adapted from skill/plugin/subgraph-search.ts for the MCP server context.
|
|
14
|
+
* Accepts relay URL as a parameter (not just env var) so the MCP server can
|
|
15
|
+
* pass its configured URL.
|
|
16
|
+
*
|
|
17
|
+
* Improvements (v3):
|
|
18
|
+
* A1: blindIndices -> blindIndexes (Graph Node pluralization)
|
|
19
|
+
* A2: Small parallel batches (5 trapdoors each) for recall
|
|
20
|
+
* A3: orderBy: id, orderDirection: desc (recency proxy)
|
|
21
|
+
* A4: Cursor-based pagination for saturated batches
|
|
22
|
+
* C4: globalStates for lightweight fact count
|
|
23
|
+
* T322: Index compaction — filter out inactive facts at query level
|
|
24
|
+
* (fact_: { isActive: true }) + client-side safety net
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.searchSubgraph = searchSubgraph;
|
|
28
|
+
exports.getSubgraphFactCount = getSubgraphFactCount;
|
|
29
|
+
const store_js_1 = require("./store.js");
|
|
30
|
+
/** Small batches so rare trapdoor matches aren't drowned by common ones. */
|
|
31
|
+
const DEFAULT_TRAPDOOR_BATCH_SIZE = 5;
|
|
32
|
+
const DEFAULT_PAGE_SIZE = 5000;
|
|
33
|
+
/**
|
|
34
|
+
* Execute a single GraphQL query against the subgraph endpoint.
|
|
35
|
+
* Returns null on any network or HTTP error (never throws).
|
|
36
|
+
*/
|
|
37
|
+
async function gqlQuery(endpoint, query, variables) {
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(endpoint, {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify({ query, variables }),
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok)
|
|
45
|
+
return null;
|
|
46
|
+
const json = await response.json();
|
|
47
|
+
return json.data ?? null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** GraphQL query for blind index lookup — uses Graph Node's `blindIndexes` pluralization.
|
|
54
|
+
* T322: Added `fact_: { isActive: true }` relation filter to exclude blind index
|
|
55
|
+
* entries pointing to soft-deleted facts (decayScore < 0.3) at the query level.
|
|
56
|
+
* Graph Node relation filters use the `field_: { subfield: value }` syntax. */
|
|
57
|
+
const SEARCH_QUERY = `
|
|
58
|
+
query SearchByBlindIndex($trapdoors: [String!]!, $owner: Bytes!, $first: Int!) {
|
|
59
|
+
blindIndexes(
|
|
60
|
+
where: { hash_in: $trapdoors, owner: $owner, fact_: { isActive: true } }
|
|
61
|
+
first: $first
|
|
62
|
+
orderBy: id
|
|
63
|
+
orderDirection: desc
|
|
64
|
+
) {
|
|
65
|
+
id
|
|
66
|
+
fact {
|
|
67
|
+
id
|
|
68
|
+
encryptedBlob
|
|
69
|
+
encryptedEmbedding
|
|
70
|
+
decayScore
|
|
71
|
+
timestamp
|
|
72
|
+
isActive
|
|
73
|
+
contentFp
|
|
74
|
+
sequenceId
|
|
75
|
+
version
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
/** Pagination query — cursor-based using id_gt, ascending for deterministic walk.
|
|
81
|
+
* T322: Added `fact_: { isActive: true }` to match SEARCH_QUERY filtering. */
|
|
82
|
+
const PAGINATE_QUERY = `
|
|
83
|
+
query PaginateBlindIndex($trapdoors: [String!]!, $owner: Bytes!, $first: Int!, $lastId: String!) {
|
|
84
|
+
blindIndexes(
|
|
85
|
+
where: { hash_in: $trapdoors, owner: $owner, id_gt: $lastId, fact_: { isActive: true } }
|
|
86
|
+
first: $first
|
|
87
|
+
orderBy: id
|
|
88
|
+
orderDirection: asc
|
|
89
|
+
) {
|
|
90
|
+
id
|
|
91
|
+
fact {
|
|
92
|
+
id
|
|
93
|
+
encryptedBlob
|
|
94
|
+
encryptedEmbedding
|
|
95
|
+
timestamp
|
|
96
|
+
decayScore
|
|
97
|
+
isActive
|
|
98
|
+
contentFp
|
|
99
|
+
sequenceId
|
|
100
|
+
version
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
/**
|
|
106
|
+
* Search the subgraph for facts matching the given trapdoors.
|
|
107
|
+
*
|
|
108
|
+
* Strategy:
|
|
109
|
+
* 1. Split trapdoors into small chunks (TRAPDOOR_BATCH_SIZE=5).
|
|
110
|
+
* 2. Fire all chunks in parallel via Promise.all.
|
|
111
|
+
* 3. If any chunk returns exactly PAGE_SIZE results (saturated),
|
|
112
|
+
* paginate that chunk using id_gt cursor until exhausted or
|
|
113
|
+
* maxCandidates reached.
|
|
114
|
+
* 4. Dedup across all chunks by fact id.
|
|
115
|
+
*
|
|
116
|
+
* @param owner - Smart Account address (hex)
|
|
117
|
+
* @param trapdoors - Blind index hashes to search for
|
|
118
|
+
* @param maxCandidates - Maximum number of candidate facts to return
|
|
119
|
+
* @param relayUrl - Optional relay URL override. If not provided,
|
|
120
|
+
* falls back to getSubgraphConfig().relayUrl.
|
|
121
|
+
*/
|
|
122
|
+
async function searchSubgraph(owner, trapdoors, maxCandidates, relayUrl) {
|
|
123
|
+
const effectiveRelayUrl = relayUrl ?? (0, store_js_1.getSubgraphConfig)().relayUrl;
|
|
124
|
+
const subgraphUrl = `${effectiveRelayUrl}/v1/subgraph`;
|
|
125
|
+
const allResults = new Map();
|
|
126
|
+
const trapdoorBatchSize = parseInt(process.env.TOTALRECLAW_TRAPDOOR_BATCH_SIZE ?? String(DEFAULT_TRAPDOOR_BATCH_SIZE), 10);
|
|
127
|
+
const pageSize = parseInt(process.env.TOTALRECLAW_SUBGRAPH_PAGE_SIZE ?? String(DEFAULT_PAGE_SIZE), 10);
|
|
128
|
+
// Split trapdoors into small chunks for parallel dispatch.
|
|
129
|
+
const chunks = [];
|
|
130
|
+
for (let i = 0; i < trapdoors.length; i += trapdoorBatchSize) {
|
|
131
|
+
chunks.push(trapdoors.slice(i, i + trapdoorBatchSize));
|
|
132
|
+
}
|
|
133
|
+
// Phase 1: Parallel initial queries (one per chunk).
|
|
134
|
+
const initialResults = await Promise.all(chunks.map(async (chunk) => {
|
|
135
|
+
const data = await gqlQuery(subgraphUrl, SEARCH_QUERY, { trapdoors: chunk, owner, first: pageSize });
|
|
136
|
+
return { chunk, entries: data?.blindIndexes ?? [] };
|
|
137
|
+
}));
|
|
138
|
+
// Collect initial results and identify saturated batches.
|
|
139
|
+
// T322: Client-side safety net — skip facts where isActive is false,
|
|
140
|
+
// in case the subgraph endpoint doesn't support relation filters (e.g. mock).
|
|
141
|
+
const saturatedChunks = [];
|
|
142
|
+
for (const { chunk, entries } of initialResults) {
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
if (entry.fact && entry.fact.isActive !== false && !allResults.has(entry.fact.id)) {
|
|
145
|
+
allResults.set(entry.fact.id, entry.fact);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (entries.length >= pageSize) {
|
|
149
|
+
saturatedChunks.push(chunk);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Phase 2: Cursor-based pagination for saturated batches.
|
|
153
|
+
// Only paginate if we haven't yet reached maxCandidates.
|
|
154
|
+
for (const chunk of saturatedChunks) {
|
|
155
|
+
if (allResults.size >= maxCandidates)
|
|
156
|
+
break;
|
|
157
|
+
// Find the last blind-index id from the initial results for this chunk.
|
|
158
|
+
// We need to re-query with ascending order for deterministic cursor walk.
|
|
159
|
+
let lastId = '';
|
|
160
|
+
while (allResults.size < maxCandidates) {
|
|
161
|
+
const data = await gqlQuery(subgraphUrl, PAGINATE_QUERY, { trapdoors: chunk, owner, first: pageSize, lastId });
|
|
162
|
+
const entries = data?.blindIndexes ?? [];
|
|
163
|
+
if (entries.length === 0)
|
|
164
|
+
break;
|
|
165
|
+
for (const entry of entries) {
|
|
166
|
+
// T322: Client-side safety net for pagination results too.
|
|
167
|
+
if (entry.fact && entry.fact.isActive !== false && !allResults.has(entry.fact.id)) {
|
|
168
|
+
allResults.set(entry.fact.id, entry.fact);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// If we got fewer than PAGE_SIZE, this chunk is exhausted.
|
|
172
|
+
if (entries.length < pageSize)
|
|
173
|
+
break;
|
|
174
|
+
lastId = entries[entries.length - 1].id;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return Array.from(allResults.values());
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get fact count from the subgraph for dynamic pool sizing.
|
|
181
|
+
* Uses the globalStates entity for a lightweight single-row lookup
|
|
182
|
+
* instead of fetching and counting individual fact IDs.
|
|
183
|
+
*
|
|
184
|
+
* @param owner - Smart Account address (hex) — currently unused by globalStates
|
|
185
|
+
* (which is aggregate), but kept for API consistency.
|
|
186
|
+
* @param relayUrl - Optional relay URL override. If not provided,
|
|
187
|
+
* falls back to getSubgraphConfig().relayUrl.
|
|
188
|
+
*/
|
|
189
|
+
async function getSubgraphFactCount(owner, relayUrl) {
|
|
190
|
+
const effectiveRelayUrl = relayUrl ?? (0, store_js_1.getSubgraphConfig)().relayUrl;
|
|
191
|
+
const subgraphUrl = `${effectiveRelayUrl}/v1/subgraph`;
|
|
192
|
+
// globalStates is a singleton entity (id: "global") with aggregate counters.
|
|
193
|
+
// It is NOT per-owner — it tracks totals across the entire subgraph.
|
|
194
|
+
const query = `
|
|
195
|
+
query FactCount {
|
|
196
|
+
globalStates(first: 1) {
|
|
197
|
+
totalFacts
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
`;
|
|
201
|
+
const data = await gqlQuery(subgraphUrl, query, {});
|
|
202
|
+
if (data?.globalStates && data.globalStates.length > 0) {
|
|
203
|
+
const count = parseInt(data.globalStates[0].totalFacts, 10);
|
|
204
|
+
return isNaN(count) ? 0 : count;
|
|
205
|
+
}
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/subgraph/search.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAwHH,wCAgFC;AAYD,oDA6BC;AA/OD,yCAA+C;AAW/C,4EAA4E;AAC5E,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B;;;GAGG;AACH,KAAK,UAAU,QAAQ,CACrB,QAAgB,EAChB,KAAa,EACb,SAAkC;IAElC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;SAC3C,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAkB,CAAC;QACnD,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;gFAGgF;AAChF,MAAM,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBpB,CAAC;AAEF;+EAC+E;AAC/E,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;CAsBtB,CAAC;AAWF;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,cAA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+
*
|
|
4
|
+
* Writes facts on-chain via ERC-4337 UserOps.
|
|
5
|
+
*
|
|
6
|
+
* Used when subgraph mode is enabled. Replaces the HTTP POST
|
|
7
|
+
* to /v1/store with an on-chain transaction flow.
|
|
8
|
+
*
|
|
9
|
+
* Builds UserOps client-side using `permissionless` + `viem` and submits
|
|
10
|
+
* them through the TotalReclaw relay server, which proxies bundler/paymaster
|
|
11
|
+
* JSON-RPC to Pimlico with its own API key. Clients never need a Pimlico key.
|
|
12
|
+
*
|
|
13
|
+
* Adapted from skill/plugin/subgraph-store.ts for the MCP server context.
|
|
14
|
+
* Config can be injected directly (for MCP server state) or read from env vars.
|
|
15
|
+
*/
|
|
16
|
+
import { type Chain } from 'viem';
|
|
17
|
+
export interface SubgraphStoreConfig {
|
|
18
|
+
relayUrl: string;
|
|
19
|
+
mnemonic: string;
|
|
20
|
+
cachePath: string;
|
|
21
|
+
chainId: number;
|
|
22
|
+
dataEdgeAddress: string;
|
|
23
|
+
entryPointAddress: string;
|
|
24
|
+
}
|
|
25
|
+
export interface FactPayload {
|
|
26
|
+
id: string;
|
|
27
|
+
timestamp: string;
|
|
28
|
+
owner: string;
|
|
29
|
+
encryptedBlob: string;
|
|
30
|
+
blindIndices: string[];
|
|
31
|
+
decayScore: number;
|
|
32
|
+
source: string;
|
|
33
|
+
contentFp: string;
|
|
34
|
+
agentId: string;
|
|
35
|
+
encryptedEmbedding?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Encode a fact payload as a minimal Protobuf wire format.
|
|
39
|
+
*
|
|
40
|
+
* Field numbers match server/proto/totalreclaw.proto:
|
|
41
|
+
* 1: id (string), 2: timestamp (string), 3: owner (string),
|
|
42
|
+
* 4: encrypted_blob (bytes), 5: blind_indices (repeated string),
|
|
43
|
+
* 6: decay_score (double), 7: is_active (bool), 8: version (int32),
|
|
44
|
+
* 9: source (string), 10: content_fp (string), 11: agent_id (string),
|
|
45
|
+
* 12: sequence_id (int64), 13: encrypted_embedding (string)
|
|
46
|
+
*/
|
|
47
|
+
export declare function encodeFactProtobuf(fact: FactPayload): Buffer;
|
|
48
|
+
/** Encode an integer as a Protobuf varint */
|
|
49
|
+
export declare function encodeVarint(value: number): Buffer;
|
|
50
|
+
/** Resolve a viem Chain object from chain ID */
|
|
51
|
+
export declare function getChainFromId(chainId: number): Chain;
|
|
52
|
+
/** Build the relay bundler RPC URL from the relay server URL */
|
|
53
|
+
export declare function getRelayBundlerUrl(relayUrl: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Submit a fact on-chain via ERC-4337 UserOp through the relay server.
|
|
56
|
+
*
|
|
57
|
+
* Builds a UserOp client-side using `permissionless` + `viem`:
|
|
58
|
+
* 1. Derives private key from mnemonic (BIP-39 + BIP-44 m/44'/60'/0'/0/0)
|
|
59
|
+
* 2. Creates a SimpleSmartAccount
|
|
60
|
+
* 3. Gets paymaster sponsorship (via relay proxy to Pimlico)
|
|
61
|
+
* 4. Signs and submits the UserOp to relay bundler endpoint
|
|
62
|
+
* 5. Waits for the transaction receipt
|
|
63
|
+
*
|
|
64
|
+
* The relay server proxies all bundler/paymaster JSON-RPC to Pimlico
|
|
65
|
+
* with its own API key. Clients never need a Pimlico API key.
|
|
66
|
+
*/
|
|
67
|
+
export declare function submitFactOnChain(protobufPayload: Buffer, config: SubgraphStoreConfig): Promise<{
|
|
68
|
+
txHash: string;
|
|
69
|
+
userOpHash: string;
|
|
70
|
+
success: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Check if subgraph mode is enabled.
|
|
74
|
+
*
|
|
75
|
+
* Checks the environment variable by default. Can be overridden by passing
|
|
76
|
+
* an explicit value (useful when MCP server manages its own config state).
|
|
77
|
+
*/
|
|
78
|
+
export declare function isSubgraphMode(override?: boolean): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Get subgraph configuration from environment variables, with optional
|
|
81
|
+
* overrides for constructor injection from MCP server state.
|
|
82
|
+
*
|
|
83
|
+
* After the relay refactor, clients only need:
|
|
84
|
+
* - TOTALRECLAW_MASTER_PASSWORD -- BIP-39 mnemonic
|
|
85
|
+
* - TOTALRECLAW_SERVER_URL -- relay server URL (default: http://localhost:8000)
|
|
86
|
+
* - TOTALRECLAW_SUBGRAPH_MODE -- "true" to enable
|
|
87
|
+
* - TOTALRECLAW_CHAIN_ID -- optional, defaults to 10200 (Chiado)
|
|
88
|
+
*
|
|
89
|
+
* Removed from client-side config (now server-side only):
|
|
90
|
+
* - PIMLICO_API_KEY
|
|
91
|
+
* - TOTALRECLAW_SUBGRAPH_ENDPOINT
|
|
92
|
+
*
|
|
93
|
+
* @param overrides - Optional partial config to override env var values.
|
|
94
|
+
* Useful for MCP server injecting config from its state.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getSubgraphConfig(overrides?: Partial<SubgraphStoreConfig>): SubgraphStoreConfig;
|
|
97
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/subgraph/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAoD,KAAK,KAAK,EAAE,MAAM,MAAM,CAAC;AAkBpF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAMD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CA2D5D;AAED,6CAA6C;AAC7C,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASlD;AAMD,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CASrD;AAED,gEAAgE;AAChE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAqFnE;AAMD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAG1D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAe/F"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP - Subgraph store path
|
|
4
|
+
*
|
|
5
|
+
* Writes facts on-chain via ERC-4337 UserOps.
|
|
6
|
+
*
|
|
7
|
+
* Used when subgraph mode is enabled. Replaces the HTTP POST
|
|
8
|
+
* to /v1/store with an on-chain transaction flow.
|
|
9
|
+
*
|
|
10
|
+
* Builds UserOps client-side using `permissionless` + `viem` and submits
|
|
11
|
+
* them through the TotalReclaw relay server, which proxies bundler/paymaster
|
|
12
|
+
* JSON-RPC to Pimlico with its own API key. Clients never need a Pimlico key.
|
|
13
|
+
*
|
|
14
|
+
* Adapted from skill/plugin/subgraph-store.ts for the MCP server context.
|
|
15
|
+
* Config can be injected directly (for MCP server state) or read from env vars.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.encodeFactProtobuf = encodeFactProtobuf;
|
|
19
|
+
exports.encodeVarint = encodeVarint;
|
|
20
|
+
exports.getChainFromId = getChainFromId;
|
|
21
|
+
exports.getRelayBundlerUrl = getRelayBundlerUrl;
|
|
22
|
+
exports.submitFactOnChain = submitFactOnChain;
|
|
23
|
+
exports.isSubgraphMode = isSubgraphMode;
|
|
24
|
+
exports.getSubgraphConfig = getSubgraphConfig;
|
|
25
|
+
const viem_1 = require("viem");
|
|
26
|
+
const account_abstraction_1 = require("viem/account-abstraction");
|
|
27
|
+
const accounts_1 = require("viem/accounts");
|
|
28
|
+
const chains_1 = require("viem/chains");
|
|
29
|
+
const permissionless_1 = require("permissionless");
|
|
30
|
+
const accounts_2 = require("permissionless/accounts");
|
|
31
|
+
const pimlico_1 = require("permissionless/clients/pimlico");
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Types
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
/** Default EventfulDataEdge contract address on Chiado testnet */
|
|
36
|
+
const DEFAULT_DATA_EDGE_ADDRESS = '0x048879569E394af3fC6721d8d44DdcfcDD407543';
|
|
37
|
+
/** Well-known ERC-4337 EntryPoint v0.7 address (same on all chains) */
|
|
38
|
+
const DEFAULT_ENTRYPOINT_ADDRESS = '0x0000000071727De22E5E9d8BAf0edAc6f37da032';
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
// Protobuf encoding (unchanged)
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
/**
|
|
43
|
+
* Encode a fact payload as a minimal Protobuf wire format.
|
|
44
|
+
*
|
|
45
|
+
* Field numbers match server/proto/totalreclaw.proto:
|
|
46
|
+
* 1: id (string), 2: timestamp (string), 3: owner (string),
|
|
47
|
+
* 4: encrypted_blob (bytes), 5: blind_indices (repeated string),
|
|
48
|
+
* 6: decay_score (double), 7: is_active (bool), 8: version (int32),
|
|
49
|
+
* 9: source (string), 10: content_fp (string), 11: agent_id (string),
|
|
50
|
+
* 12: sequence_id (int64), 13: encrypted_embedding (string)
|
|
51
|
+
*/
|
|
52
|
+
function encodeFactProtobuf(fact) {
|
|
53
|
+
const parts = [];
|
|
54
|
+
// Helper: encode a string field
|
|
55
|
+
const writeString = (fieldNumber, value) => {
|
|
56
|
+
if (!value)
|
|
57
|
+
return;
|
|
58
|
+
const data = Buffer.from(value, 'utf-8');
|
|
59
|
+
const key = (fieldNumber << 3) | 2; // wire type 2 = length-delimited
|
|
60
|
+
parts.push(encodeVarint(key));
|
|
61
|
+
parts.push(encodeVarint(data.length));
|
|
62
|
+
parts.push(data);
|
|
63
|
+
};
|
|
64
|
+
// Helper: encode a bytes field
|
|
65
|
+
const writeBytes = (fieldNumber, value) => {
|
|
66
|
+
const key = (fieldNumber << 3) | 2;
|
|
67
|
+
parts.push(encodeVarint(key));
|
|
68
|
+
parts.push(encodeVarint(value.length));
|
|
69
|
+
parts.push(value);
|
|
70
|
+
};
|
|
71
|
+
// Helper: encode a double field (wire type 1 = 64-bit)
|
|
72
|
+
const writeDouble = (fieldNumber, value) => {
|
|
73
|
+
const key = (fieldNumber << 3) | 1;
|
|
74
|
+
parts.push(encodeVarint(key));
|
|
75
|
+
const buf = Buffer.alloc(8);
|
|
76
|
+
buf.writeDoubleLE(value);
|
|
77
|
+
parts.push(buf);
|
|
78
|
+
};
|
|
79
|
+
// Helper: encode a varint field (wire type 0)
|
|
80
|
+
const writeVarintField = (fieldNumber, value) => {
|
|
81
|
+
const key = (fieldNumber << 3) | 0;
|
|
82
|
+
parts.push(encodeVarint(key));
|
|
83
|
+
parts.push(encodeVarint(value));
|
|
84
|
+
};
|
|
85
|
+
// Encode fields
|
|
86
|
+
writeString(1, fact.id);
|
|
87
|
+
writeString(2, fact.timestamp);
|
|
88
|
+
writeString(3, fact.owner);
|
|
89
|
+
writeBytes(4, Buffer.from(fact.encryptedBlob, 'hex'));
|
|
90
|
+
for (const index of fact.blindIndices) {
|
|
91
|
+
writeString(5, index);
|
|
92
|
+
}
|
|
93
|
+
writeDouble(6, fact.decayScore);
|
|
94
|
+
writeVarintField(7, 1); // is_active = true
|
|
95
|
+
writeVarintField(8, 2); // version = 2
|
|
96
|
+
writeString(9, fact.source);
|
|
97
|
+
writeString(10, fact.contentFp);
|
|
98
|
+
writeString(11, fact.agentId);
|
|
99
|
+
// Field 12 (sequence_id) is assigned by the subgraph mapping, not the client
|
|
100
|
+
if (fact.encryptedEmbedding) {
|
|
101
|
+
writeString(13, fact.encryptedEmbedding);
|
|
102
|
+
}
|
|
103
|
+
return Buffer.concat(parts);
|
|
104
|
+
}
|
|
105
|
+
/** Encode an integer as a Protobuf varint */
|
|
106
|
+
function encodeVarint(value) {
|
|
107
|
+
const bytes = [];
|
|
108
|
+
let v = value >>> 0; // unsigned
|
|
109
|
+
while (v > 0x7f) {
|
|
110
|
+
bytes.push((v & 0x7f) | 0x80);
|
|
111
|
+
v >>>= 7;
|
|
112
|
+
}
|
|
113
|
+
bytes.push(v & 0x7f);
|
|
114
|
+
return Buffer.from(bytes);
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Chain helpers
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
/** Resolve a viem Chain object from chain ID */
|
|
120
|
+
function getChainFromId(chainId) {
|
|
121
|
+
switch (chainId) {
|
|
122
|
+
case 100:
|
|
123
|
+
return chains_1.gnosis;
|
|
124
|
+
case 10200:
|
|
125
|
+
return chains_1.gnosisChiado;
|
|
126
|
+
default:
|
|
127
|
+
return chains_1.gnosisChiado;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Build the relay bundler RPC URL from the relay server URL */
|
|
131
|
+
function getRelayBundlerUrl(relayUrl) {
|
|
132
|
+
return `${relayUrl}/v1/bundler`;
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// On-chain submission (Pimlico UserOps)
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Submit a fact on-chain via ERC-4337 UserOp through the relay server.
|
|
139
|
+
*
|
|
140
|
+
* Builds a UserOp client-side using `permissionless` + `viem`:
|
|
141
|
+
* 1. Derives private key from mnemonic (BIP-39 + BIP-44 m/44'/60'/0'/0/0)
|
|
142
|
+
* 2. Creates a SimpleSmartAccount
|
|
143
|
+
* 3. Gets paymaster sponsorship (via relay proxy to Pimlico)
|
|
144
|
+
* 4. Signs and submits the UserOp to relay bundler endpoint
|
|
145
|
+
* 5. Waits for the transaction receipt
|
|
146
|
+
*
|
|
147
|
+
* The relay server proxies all bundler/paymaster JSON-RPC to Pimlico
|
|
148
|
+
* with its own API key. Clients never need a Pimlico API key.
|
|
149
|
+
*/
|
|
150
|
+
async function submitFactOnChain(protobufPayload, config) {
|
|
151
|
+
if (!config.relayUrl) {
|
|
152
|
+
throw new Error('Relay URL is required for on-chain submission');
|
|
153
|
+
}
|
|
154
|
+
if (!config.mnemonic) {
|
|
155
|
+
throw new Error('Mnemonic is required for on-chain submission');
|
|
156
|
+
}
|
|
157
|
+
const chain = getChainFromId(config.chainId);
|
|
158
|
+
const bundlerRpcUrl = getRelayBundlerUrl(config.relayUrl);
|
|
159
|
+
const dataEdgeAddress = config.dataEdgeAddress;
|
|
160
|
+
const entryPointAddr = (config.entryPointAddress || account_abstraction_1.entryPoint07Address);
|
|
161
|
+
// 1. Derive EOA signer from mnemonic (BIP-44 m/44'/60'/0'/0/0)
|
|
162
|
+
const ownerAccount = (0, accounts_1.mnemonicToAccount)(config.mnemonic);
|
|
163
|
+
// 2. Create a public client for chain reads (via relay bundler proxy)
|
|
164
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
165
|
+
chain,
|
|
166
|
+
transport: (0, viem_1.http)(bundlerRpcUrl),
|
|
167
|
+
});
|
|
168
|
+
// 3. Create Pimlico client for bundler + paymaster operations (via relay)
|
|
169
|
+
const pimlicoClient = (0, pimlico_1.createPimlicoClient)({
|
|
170
|
+
chain,
|
|
171
|
+
transport: (0, viem_1.http)(bundlerRpcUrl),
|
|
172
|
+
entryPoint: {
|
|
173
|
+
address: entryPointAddr,
|
|
174
|
+
version: '0.7',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
// 4. Create a SimpleSmartAccount (auto-generates initCode if undeployed)
|
|
178
|
+
const smartAccount = await (0, accounts_2.toSimpleSmartAccount)({
|
|
179
|
+
// @ts-ignore - viem/permissionless type intersection conflict
|
|
180
|
+
client: publicClient,
|
|
181
|
+
owner: ownerAccount,
|
|
182
|
+
entryPoint: {
|
|
183
|
+
address: entryPointAddr,
|
|
184
|
+
version: '0.7',
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
// 5. Create smart account client wired to relay bundler + paymaster
|
|
188
|
+
const smartAccountClient = (0, permissionless_1.createSmartAccountClient)({
|
|
189
|
+
account: smartAccount,
|
|
190
|
+
chain,
|
|
191
|
+
bundlerTransport: (0, viem_1.http)(bundlerRpcUrl),
|
|
192
|
+
// Paymaster sponsorship proxied through relay to Pimlico
|
|
193
|
+
paymaster: pimlicoClient,
|
|
194
|
+
userOperation: {
|
|
195
|
+
estimateFeesPerGas: async () => {
|
|
196
|
+
return (await pimlicoClient.getUserOperationGasPrice()).fast;
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
// 6. Send the transaction: Smart Account execute(dataEdgeAddress, 0, protobufPayload)
|
|
201
|
+
// The DataEdge contract has a fallback() that emits Log(bytes), so the calldata
|
|
202
|
+
// IS the protobuf payload directly (no function selector needed).
|
|
203
|
+
// permissionless encodes the execute() call internally from to/value/data.
|
|
204
|
+
const calldata = `0x${protobufPayload.toString('hex')}`;
|
|
205
|
+
// Use sendUserOperation to get the userOpHash, then wait for receipt
|
|
206
|
+
const userOpHash = await smartAccountClient.sendUserOperation({
|
|
207
|
+
calls: [
|
|
208
|
+
{
|
|
209
|
+
to: dataEdgeAddress,
|
|
210
|
+
value: 0n,
|
|
211
|
+
data: calldata,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
// 7. Wait for the UserOp to be included in a transaction
|
|
216
|
+
const receipt = await pimlicoClient.waitForUserOperationReceipt({
|
|
217
|
+
hash: userOpHash,
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
txHash: receipt.receipt.transactionHash,
|
|
221
|
+
userOpHash,
|
|
222
|
+
success: receipt.success,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// ---------------------------------------------------------------------------
|
|
226
|
+
// Configuration
|
|
227
|
+
// ---------------------------------------------------------------------------
|
|
228
|
+
/**
|
|
229
|
+
* Check if subgraph mode is enabled.
|
|
230
|
+
*
|
|
231
|
+
* Checks the environment variable by default. Can be overridden by passing
|
|
232
|
+
* an explicit value (useful when MCP server manages its own config state).
|
|
233
|
+
*/
|
|
234
|
+
function isSubgraphMode(override) {
|
|
235
|
+
if (override !== undefined)
|
|
236
|
+
return override;
|
|
237
|
+
return process.env.TOTALRECLAW_SUBGRAPH_MODE === 'true';
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get subgraph configuration from environment variables, with optional
|
|
241
|
+
* overrides for constructor injection from MCP server state.
|
|
242
|
+
*
|
|
243
|
+
* After the relay refactor, clients only need:
|
|
244
|
+
* - TOTALRECLAW_MASTER_PASSWORD -- BIP-39 mnemonic
|
|
245
|
+
* - TOTALRECLAW_SERVER_URL -- relay server URL (default: http://localhost:8000)
|
|
246
|
+
* - TOTALRECLAW_SUBGRAPH_MODE -- "true" to enable
|
|
247
|
+
* - TOTALRECLAW_CHAIN_ID -- optional, defaults to 10200 (Chiado)
|
|
248
|
+
*
|
|
249
|
+
* Removed from client-side config (now server-side only):
|
|
250
|
+
* - PIMLICO_API_KEY
|
|
251
|
+
* - TOTALRECLAW_SUBGRAPH_ENDPOINT
|
|
252
|
+
*
|
|
253
|
+
* @param overrides - Optional partial config to override env var values.
|
|
254
|
+
* Useful for MCP server injecting config from its state.
|
|
255
|
+
*/
|
|
256
|
+
function getSubgraphConfig(overrides) {
|
|
257
|
+
const envConfig = {
|
|
258
|
+
relayUrl: process.env.TOTALRECLAW_SERVER_URL || 'http://localhost:8000',
|
|
259
|
+
mnemonic: process.env.TOTALRECLAW_MASTER_PASSWORD || '',
|
|
260
|
+
cachePath: process.env.TOTALRECLAW_CACHE_PATH || `${process.env.HOME}/.totalreclaw/cache.enc`,
|
|
261
|
+
chainId: parseInt(process.env.TOTALRECLAW_CHAIN_ID || '10200'),
|
|
262
|
+
dataEdgeAddress: process.env.TOTALRECLAW_DATA_EDGE_ADDRESS || DEFAULT_DATA_EDGE_ADDRESS,
|
|
263
|
+
entryPointAddress: process.env.TOTALRECLAW_ENTRYPOINT_ADDRESS || DEFAULT_ENTRYPOINT_ADDRESS,
|
|
264
|
+
};
|
|
265
|
+
if (overrides) {
|
|
266
|
+
return { ...envConfig, ...overrides };
|
|
267
|
+
}
|
|
268
|
+
return envConfig;
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/subgraph/store.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAwDH,gDA2DC;AAGD,oCASC;AAOD,wCASC;AAGD,gDAEC;AAmBD,8CAwFC;AAYD,wCAGC;AAmBD,8CAeC;AA9SD,+BAAoF;AACpF,kEAA+D;AAC/D,4CAAkD;AAClD,wCAAmD;AACnD,mDAA0D;AAC1D,sDAA+D;AAC/D,4DAAqE;AAErE,8EAA8E;AAC9E,QAAQ;AACR,8EAA8E;AAE9E,kEAAkE;AAClE,MAAM,y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AE,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,EAAE;QACvD,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,yBAAyB;QAC7F,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO,CAAC;QAC9D,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,yBAAyB;QACvF,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,0BAA0B;KAC5F,CAAC;IAEF,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,GAAG,SAAS,EAAE,GAAG,SAAS,EAAE,CAAC;IACxC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TotalReclaw } from '@totalreclaw/client';
|
|
2
|
+
export interface ExportInput {
|
|
3
|
+
format?: 'markdown' | 'json';
|
|
4
|
+
namespace?: string;
|
|
5
|
+
include_metadata?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ExportOutput {
|
|
8
|
+
content: string;
|
|
9
|
+
format: string;
|
|
10
|
+
fact_count: number;
|
|
11
|
+
exported_at: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const exportToolDefinition: {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
format: {
|
|
20
|
+
type: string;
|
|
21
|
+
enum: string[];
|
|
22
|
+
default: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
namespace: {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
include_metadata: {
|
|
30
|
+
type: string;
|
|
31
|
+
default: boolean;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
annotations: {
|
|
37
|
+
readOnlyHint: boolean;
|
|
38
|
+
destructiveHint: boolean;
|
|
39
|
+
idempotentHint: boolean;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export declare function handleExport(client: TotalReclaw, args: unknown, defaultNamespace: string): Promise<{
|
|
43
|
+
content: Array<{
|
|
44
|
+
type: string;
|
|
45
|
+
text: string;
|
|
46
|
+
}>;
|
|
47
|
+
}>;
|
|
48
|
+
//# sourceMappingURL=export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/tools/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BhC,CAAC;AAEF,wBAAsB,YAAY,CAChC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,OAAO,EACb,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CAgG7D"}
|