@aroha-sdk/mcp-bridge 1.0.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/bridge.test.d.ts +2 -0
- package/dist/bridge.test.d.ts.map +1 -0
- package/dist/bridge.test.js +140 -0
- package/dist/bridge.test.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -2
- package/tsconfig.json +0 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.test.d.ts","sourceRoot":"","sources":["../src/bridge.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { mcpToolsToArohaCapabilities, arohaAgentToMcpTools } from "./index.js";
|
|
3
|
+
import * as ed from "@noble/ed25519";
|
|
4
|
+
import { sha512 } from "@noble/hashes/sha512";
|
|
5
|
+
ed.etc.sha512Sync = (...m) => sha512(...m);
|
|
6
|
+
function makeMcpTool(name, description = "A test tool") {
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
description,
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: { query: { type: "string" } },
|
|
13
|
+
required: ["query"],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function makeDiscoveredAgent() {
|
|
18
|
+
return {
|
|
19
|
+
record: {
|
|
20
|
+
didHash: "0xtest-provider",
|
|
21
|
+
ownerAddress: "0xOwner",
|
|
22
|
+
manifestCID: "Qm123",
|
|
23
|
+
publicKeyB64: Buffer.alloc(32).toString("base64url"),
|
|
24
|
+
stakedWei: 1000000000000000000n,
|
|
25
|
+
reputationScore: 8000,
|
|
26
|
+
active: true,
|
|
27
|
+
registeredAt: Date.now() - 86400_000,
|
|
28
|
+
lastUpdatedAt: Date.now(),
|
|
29
|
+
},
|
|
30
|
+
manifest: {
|
|
31
|
+
aroha: "1.0",
|
|
32
|
+
did: "did:aroha:test-provider",
|
|
33
|
+
name: "Test Provider",
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
endpoint: "https://provider.example.com/aroha",
|
|
36
|
+
capabilities: [
|
|
37
|
+
{
|
|
38
|
+
id: "search-flights",
|
|
39
|
+
version: "1.0.0",
|
|
40
|
+
description: "Search for flights",
|
|
41
|
+
inputSchema: { type: "object", properties: { origin: { type: "string" } } },
|
|
42
|
+
outputSchema: { type: "object", properties: { flights: { type: "array" } } },
|
|
43
|
+
async: false,
|
|
44
|
+
maxResponseMs: 5000,
|
|
45
|
+
requiredTrustLevel: 1,
|
|
46
|
+
pricing: { model: "free" },
|
|
47
|
+
sagaRole: "none",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "book-flight",
|
|
51
|
+
version: "1.0.0",
|
|
52
|
+
description: "Book a flight",
|
|
53
|
+
inputSchema: { type: "object", properties: { flightId: { type: "string" } } },
|
|
54
|
+
outputSchema: { type: "object", properties: { booking: { type: "string" } } },
|
|
55
|
+
async: false,
|
|
56
|
+
maxResponseMs: 10000,
|
|
57
|
+
requiredTrustLevel: 2,
|
|
58
|
+
pricing: { model: "per-transaction", fee: "10.00" },
|
|
59
|
+
sagaRole: "participant",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
protocols: ["aroha/1.0"],
|
|
63
|
+
createdAt: new Date().toISOString(),
|
|
64
|
+
signature: "dummy-sig",
|
|
65
|
+
},
|
|
66
|
+
endpoint: "https://provider.example.com/aroha",
|
|
67
|
+
publicKey: new Uint8Array(32),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
describe("mcpToolsToArohaCapabilities", () => {
|
|
71
|
+
it("converts MCP tools to Aroha capability definitions", () => {
|
|
72
|
+
const tools = [makeMcpTool("aroha_search_flights"), makeMcpTool("aroha_book_hotel")];
|
|
73
|
+
const caps = mcpToolsToArohaCapabilities(tools);
|
|
74
|
+
expect(caps).toHaveLength(2);
|
|
75
|
+
expect(caps[0].id).toBe("search-flights");
|
|
76
|
+
expect(caps[1].id).toBe("book-hotel");
|
|
77
|
+
});
|
|
78
|
+
it("sets correct default fields", () => {
|
|
79
|
+
const caps = mcpToolsToArohaCapabilities([makeMcpTool("aroha_do_thing", "Does the thing")]);
|
|
80
|
+
const cap = caps[0];
|
|
81
|
+
expect(cap.version).toBe("1.0.0");
|
|
82
|
+
expect(cap.async).toBe(false);
|
|
83
|
+
expect(cap.requiredTrustLevel).toBe(1);
|
|
84
|
+
expect(cap.pricing.model).toBe("free");
|
|
85
|
+
expect(cap.sagaRole).toBe("none");
|
|
86
|
+
expect(cap.description).toBe("Does the thing");
|
|
87
|
+
});
|
|
88
|
+
it("preserves the inputSchema", () => {
|
|
89
|
+
const tool = makeMcpTool("aroha_test");
|
|
90
|
+
const caps = mcpToolsToArohaCapabilities([tool]);
|
|
91
|
+
expect(caps[0].inputSchema).toEqual(tool.inputSchema);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe("arohaAgentToMcpTools", () => {
|
|
95
|
+
it("produces one MCP tool per capability", async () => {
|
|
96
|
+
const priv = ed.utils.randomPrivateKey();
|
|
97
|
+
const agent = makeDiscoveredAgent();
|
|
98
|
+
const mockClient = { send: vi.fn(), stream: vi.fn(), fetchDIDDocument: vi.fn() };
|
|
99
|
+
const { tools } = arohaAgentToMcpTools(agent, "did:aroha:orchestrator", priv, mockClient, "saga-test");
|
|
100
|
+
expect(tools).toHaveLength(2);
|
|
101
|
+
expect(tools[0].name).toBe("aroha_search_flights");
|
|
102
|
+
expect(tools[1].name).toBe("aroha_book_flight");
|
|
103
|
+
});
|
|
104
|
+
it("tool definitions include _aroha metadata", async () => {
|
|
105
|
+
const priv = ed.utils.randomPrivateKey();
|
|
106
|
+
const agent = makeDiscoveredAgent();
|
|
107
|
+
const mockClient = { send: vi.fn(), stream: vi.fn(), fetchDIDDocument: vi.fn() };
|
|
108
|
+
const { tools } = arohaAgentToMcpTools(agent, "did:aroha:orchestrator", priv, mockClient, "saga-test");
|
|
109
|
+
expect(tools[0]._aroha?.agentDID).toBe("did:aroha:test-provider");
|
|
110
|
+
expect(tools[0]._aroha?.capabilityId).toBe("search-flights");
|
|
111
|
+
});
|
|
112
|
+
it("handleToolCall returns error for unknown tool", async () => {
|
|
113
|
+
const priv = ed.utils.randomPrivateKey();
|
|
114
|
+
const agent = makeDiscoveredAgent();
|
|
115
|
+
const mockClient = { send: vi.fn(), stream: vi.fn(), fetchDIDDocument: vi.fn() };
|
|
116
|
+
const { handleToolCall } = arohaAgentToMcpTools(agent, "did:aroha:orchestrator", priv, mockClient, "saga-test");
|
|
117
|
+
const result = await handleToolCall("aroha_nonexistent", {});
|
|
118
|
+
expect(result.isError).toBe(true);
|
|
119
|
+
expect(result.content[0].text).toMatch(/Unknown tool/);
|
|
120
|
+
});
|
|
121
|
+
it("handleToolCall calls client.send and returns result", async () => {
|
|
122
|
+
const priv = ed.utils.randomPrivateKey();
|
|
123
|
+
const agent = makeDiscoveredAgent();
|
|
124
|
+
const mockResponse = {
|
|
125
|
+
type: "ArohaResponse",
|
|
126
|
+
body: { capability: "search-flights", result: { flights: ["AA100"] } },
|
|
127
|
+
};
|
|
128
|
+
const mockClient = {
|
|
129
|
+
send: vi.fn().mockResolvedValue(mockResponse),
|
|
130
|
+
stream: vi.fn(),
|
|
131
|
+
fetchDIDDocument: vi.fn(),
|
|
132
|
+
};
|
|
133
|
+
const { handleToolCall } = arohaAgentToMcpTools(agent, "did:aroha:orchestrator", priv, mockClient, "saga-test");
|
|
134
|
+
const result = await handleToolCall("aroha_search_flights", { origin: "JFK" });
|
|
135
|
+
expect(result.isError).toBeUndefined();
|
|
136
|
+
expect(result.content[0].text).toContain("AA100");
|
|
137
|
+
expect(mockClient.send).toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=bridge.test.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
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha ↔ MCP Bridge
|
|
3
|
+
*
|
|
4
|
+
* Two directions:
|
|
5
|
+
*
|
|
6
|
+
* toMcp() — Wrap a discovered Aroha agent's capabilities as MCP tool definitions.
|
|
7
|
+
* Claude Desktop / any MCP client can call them as normal tools.
|
|
8
|
+
* The bridge transparently sends ArohaRequest messages under the hood.
|
|
9
|
+
*
|
|
10
|
+
* fromMcp() — Expose an MCP server's tools as a Aroha capability manifest.
|
|
11
|
+
* Any Aroha orchestrator can discover and call the MCP server
|
|
12
|
+
* without knowing it's MCP-backed.
|
|
13
|
+
*
|
|
14
|
+
* The bridge is purely an adapter — it translates formats.
|
|
15
|
+
* It adds no business logic and changes no message semantics.
|
|
16
|
+
*/
|
|
17
|
+
import { ArohaClient } from "@aroha-sdk/core";
|
|
18
|
+
import { type DiscoveredAgent, type CapabilityDefinition } from "@aroha-sdk/registry";
|
|
19
|
+
export interface McpToolDefinition {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: "object";
|
|
24
|
+
properties: Record<string, unknown>;
|
|
25
|
+
required?: string[];
|
|
26
|
+
};
|
|
27
|
+
/** Aroha metadata — carried as an extension field */
|
|
28
|
+
_aroha?: {
|
|
29
|
+
agentDID: string;
|
|
30
|
+
capabilityId: string;
|
|
31
|
+
sagaRole: "none" | "participant";
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type McpToolCallResult = {
|
|
35
|
+
content: Array<{
|
|
36
|
+
type: "text";
|
|
37
|
+
text: string;
|
|
38
|
+
}>;
|
|
39
|
+
isError?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Convert a discovered Aroha agent's capabilities into MCP tool definitions.
|
|
43
|
+
* Returns both the definitions (for registering with MCP) and a handler
|
|
44
|
+
* function that executes the tool call via Aroha.
|
|
45
|
+
*/
|
|
46
|
+
export declare function arohaAgentToMcpTools(agent: DiscoveredAgent, orchestratorDID: string, orchestratorPrivateKey: Uint8Array, client: ArohaClient, correlationId: string): {
|
|
47
|
+
tools: McpToolDefinition[];
|
|
48
|
+
handleToolCall: (toolName: string, args: Record<string, unknown>) => Promise<McpToolCallResult>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Convert MCP tool definitions into a Aroha capability manifest fragment.
|
|
52
|
+
* Use this to register an MCP server as a Aroha agent.
|
|
53
|
+
*/
|
|
54
|
+
export declare function mcpToolsToArohaCapabilities(tools: McpToolDefinition[]): CapabilityDefinition[];
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAEL,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAItF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IACF,qDAAqD;IACrD,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC;KAClC,CAAC;CACH;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,eAAe,EACtB,eAAe,EAAE,MAAM,EACvB,sBAAsB,EAAE,UAAU,EAClC,MAAM,EAAE,WAAW,EACnB,aAAa,EAAE,MAAM,GACpB;IACD,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACjG,CA6CA;AAID;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,iBAAiB,EAAE,GACzB,oBAAoB,EAAE,CAaxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aroha ↔ MCP Bridge
|
|
3
|
+
*
|
|
4
|
+
* Two directions:
|
|
5
|
+
*
|
|
6
|
+
* toMcp() — Wrap a discovered Aroha agent's capabilities as MCP tool definitions.
|
|
7
|
+
* Claude Desktop / any MCP client can call them as normal tools.
|
|
8
|
+
* The bridge transparently sends ArohaRequest messages under the hood.
|
|
9
|
+
*
|
|
10
|
+
* fromMcp() — Expose an MCP server's tools as a Aroha capability manifest.
|
|
11
|
+
* Any Aroha orchestrator can discover and call the MCP server
|
|
12
|
+
* without knowing it's MCP-backed.
|
|
13
|
+
*
|
|
14
|
+
* The bridge is purely an adapter — it translates formats.
|
|
15
|
+
* It adds no business logic and changes no message semantics.
|
|
16
|
+
*/
|
|
17
|
+
import { buildEnvelope, } from "@aroha-sdk/core";
|
|
18
|
+
// ─── Aroha → MCP ───────────────────────────────────────────────────────────────
|
|
19
|
+
/**
|
|
20
|
+
* Convert a discovered Aroha agent's capabilities into MCP tool definitions.
|
|
21
|
+
* Returns both the definitions (for registering with MCP) and a handler
|
|
22
|
+
* function that executes the tool call via Aroha.
|
|
23
|
+
*/
|
|
24
|
+
export function arohaAgentToMcpTools(agent, orchestratorDID, orchestratorPrivateKey, client, correlationId) {
|
|
25
|
+
const tools = agent.manifest.capabilities.map((cap) => capabilityToMcpTool(cap, agent.manifest.did));
|
|
26
|
+
const handleToolCall = async (toolName, args) => {
|
|
27
|
+
const cap = agent.manifest.capabilities.find((c) => mcpToolName(c.id) === toolName);
|
|
28
|
+
if (!cap) {
|
|
29
|
+
return { content: [{ type: "text", text: `Unknown tool: ${toolName}` }], isError: true };
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const body = { capability: cap.id, params: args };
|
|
33
|
+
const envelope = await buildEnvelope("ArohaRequest", orchestratorDID, agent.manifest.did, body, correlationId, orchestratorPrivateKey);
|
|
34
|
+
const response = await client.send(agent.endpoint, envelope);
|
|
35
|
+
if (!response) {
|
|
36
|
+
return { content: [{ type: "text", text: "Agent returned no response (async)" }] };
|
|
37
|
+
}
|
|
38
|
+
if (response.type === "ArohaError") {
|
|
39
|
+
const err = response.body;
|
|
40
|
+
return { content: [{ type: "text", text: err.message }], isError: true };
|
|
41
|
+
}
|
|
42
|
+
const result = response.body.result;
|
|
43
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
return { content: [{ type: "text", text: String(err) }], isError: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
return { tools, handleToolCall };
|
|
50
|
+
}
|
|
51
|
+
// ─── MCP → Aroha ───────────────────────────────────────────────────────────────
|
|
52
|
+
/**
|
|
53
|
+
* Convert MCP tool definitions into a Aroha capability manifest fragment.
|
|
54
|
+
* Use this to register an MCP server as a Aroha agent.
|
|
55
|
+
*/
|
|
56
|
+
export function mcpToolsToArohaCapabilities(tools) {
|
|
57
|
+
return tools.map((tool) => ({
|
|
58
|
+
id: arohaCapabilityId(tool.name),
|
|
59
|
+
version: "1.0.0",
|
|
60
|
+
description: tool.description,
|
|
61
|
+
inputSchema: tool.inputSchema,
|
|
62
|
+
outputSchema: { type: "object", properties: { result: { type: "object" } } },
|
|
63
|
+
async: false,
|
|
64
|
+
maxResponseMs: 30_000,
|
|
65
|
+
requiredTrustLevel: 1,
|
|
66
|
+
pricing: { model: "free" },
|
|
67
|
+
sagaRole: "none",
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
71
|
+
function capabilityToMcpTool(cap, agentDID) {
|
|
72
|
+
return {
|
|
73
|
+
name: mcpToolName(cap.id),
|
|
74
|
+
description: cap.description ?? cap.id,
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: cap.inputSchema?.properties ?? {},
|
|
78
|
+
required: cap.inputSchema?.required,
|
|
79
|
+
},
|
|
80
|
+
_aroha: {
|
|
81
|
+
agentDID,
|
|
82
|
+
capabilityId: cap.id,
|
|
83
|
+
sagaRole: cap.sagaRole,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** Convert a Aroha capability ID to a valid MCP tool name (snake_case). */
|
|
88
|
+
function mcpToolName(capabilityId) {
|
|
89
|
+
return `aroha_${capabilityId.replace(/-/g, "_")}`;
|
|
90
|
+
}
|
|
91
|
+
/** Convert an MCP tool name back to a Aroha capability ID. */
|
|
92
|
+
function arohaCapabilityId(mcpName) {
|
|
93
|
+
return mcpName.replace(/^aroha_/, "").replace(/_/g, "-");
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,aAAa,GAGd,MAAM,iBAAiB,CAAC;AA2BzB,kFAAkF;AAElF;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAsB,EACtB,eAAuB,EACvB,sBAAkC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AAM,EAAE;QAC1B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC,CAAC;AACN,CAAC;AAED,iFAAiF;AAEjF,SAAS,mBAAmB,CAC1B,GAAyB,EACzB,QAAgB;IAEhB,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,EAAE;QACtC,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAG,GAAG,CAAC,WAAuD,EAAE,UAAU,IAAI,EAAE;YAC1F,QAAQ,EAAG,GAAG,CAAC,WAAuC,EAAE,QAAQ;SACjE;QACD,MAAM,EAAE;YACN,QAAQ;YACR,YAAY,EAAE,GAAG,CAAC,EAAE;YACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;SACvB;KACF,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,SAAS,WAAW,CAAC,YAAoB;IACvC,OAAO,SAAS,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;AACpD,CAAC;AAED,8DAA8D;AAC9D,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aroha-sdk/mcp-bridge",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Aroha
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Aroha ↔ MCP (Model Context Protocol) adapter",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"src"
|
|
8
|
+
],
|
|
5
9
|
"type": "module",
|
|
6
10
|
"main": "./dist/index.js",
|
|
7
11
|
"types": "./dist/index.d.ts",
|
package/tsconfig.json
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": { "composite": true, "outDir": "./dist", "rootDir": "./src" },
|
|
4
|
-
"references": [{ "path": "../aroha-core" }, { "path": "../aroha-registry" }],
|
|
5
|
-
"include": ["src/**/*"],
|
|
6
|
-
"exclude": ["dist", "node_modules"]
|
|
7
|
-
}
|