@elizaos/plugin-nostr 2.0.3-beta.5 → 2.0.3-beta.7
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/accounts.d.ts +15 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +139 -0
- package/dist/accounts.js.map +1 -0
- package/dist/connector-account-provider.d.ts +20 -0
- package/dist/connector-account-provider.d.ts.map +1 -0
- package/dist/connector-account-provider.js +78 -0
- package/dist/connector-account-provider.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/identityContext.d.ts +6 -0
- package/dist/providers/identityContext.d.ts.map +1 -0
- package/dist/providers/identityContext.js +69 -0
- package/dist/providers/identityContext.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +5 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/service.d.ts +116 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +980 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +192 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
2
|
+
import { type NostrSettings } from "./types.js";
|
|
3
|
+
export declare const DEFAULT_NOSTR_ACCOUNT_ID = "default";
|
|
4
|
+
export type NostrAccountConfig = Partial<Omit<NostrSettings, "relays" | "allowFrom" | "publicKey" | "accountId">> & {
|
|
5
|
+
accountId?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
relays?: string[] | string;
|
|
8
|
+
allowFrom?: string[] | string;
|
|
9
|
+
};
|
|
10
|
+
export declare function normalizeNostrAccountId(accountId?: unknown): string;
|
|
11
|
+
export declare function listNostrAccountIds(runtime: IAgentRuntime): string[];
|
|
12
|
+
export declare function resolveDefaultNostrAccountId(runtime: IAgentRuntime): string;
|
|
13
|
+
export declare function readNostrAccountId(...sources: unknown[]): string | undefined;
|
|
14
|
+
export declare function resolveNostrAccountSettings(runtime: IAgentRuntime, requestedAccountId?: string | null): NostrSettings;
|
|
15
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1F,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAElD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC,CACxE,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CAC/B,CAAC;AAoEF,wBAAgB,uBAAuB,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAInE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAepE;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAQ3E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CA2B5E;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,aAAa,EACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,aAAa,CAqCf"}
|
package/dist/accounts.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { DEFAULT_NOSTR_RELAYS } from "./types.js";
|
|
2
|
+
export const DEFAULT_NOSTR_ACCOUNT_ID = "default";
|
|
3
|
+
function stringSetting(runtime, key) {
|
|
4
|
+
const value = runtime.getSetting(key);
|
|
5
|
+
if (typeof value === "string" && value.trim())
|
|
6
|
+
return value.trim();
|
|
7
|
+
return process.env[key];
|
|
8
|
+
}
|
|
9
|
+
function characterConfig(runtime) {
|
|
10
|
+
const settings = runtime.character.settings;
|
|
11
|
+
const raw = settings?.nostr;
|
|
12
|
+
return raw && typeof raw === "object" ? raw : {};
|
|
13
|
+
}
|
|
14
|
+
function parseAccountsJson(runtime) {
|
|
15
|
+
const raw = stringSetting(runtime, "NOSTR_ACCOUNTS");
|
|
16
|
+
if (!raw)
|
|
17
|
+
return {};
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
if (Array.isArray(parsed)) {
|
|
21
|
+
return Object.fromEntries(parsed
|
|
22
|
+
.filter((item) => Boolean(item) && typeof item === "object")
|
|
23
|
+
.map((item) => [normalizeNostrAccountId(item.accountId ?? item.id), item]));
|
|
24
|
+
}
|
|
25
|
+
return parsed && typeof parsed === "object"
|
|
26
|
+
? parsed
|
|
27
|
+
: {};
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function allAccountConfigs(runtime) {
|
|
34
|
+
return {
|
|
35
|
+
...(characterConfig(runtime).accounts ?? {}),
|
|
36
|
+
...parseAccountsJson(runtime),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function accountConfig(runtime, accountId) {
|
|
40
|
+
const accounts = allAccountConfigs(runtime);
|
|
41
|
+
return accounts[accountId] ?? accounts[normalizeNostrAccountId(accountId)] ?? {};
|
|
42
|
+
}
|
|
43
|
+
function boolValue(value, fallback = true) {
|
|
44
|
+
if (typeof value === "boolean")
|
|
45
|
+
return value;
|
|
46
|
+
if (typeof value === "string")
|
|
47
|
+
return value.trim().toLowerCase() !== "false";
|
|
48
|
+
return fallback;
|
|
49
|
+
}
|
|
50
|
+
function stringList(value) {
|
|
51
|
+
if (Array.isArray(value))
|
|
52
|
+
return value.map((item) => String(item).trim()).filter(Boolean);
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
return value
|
|
55
|
+
.split(",")
|
|
56
|
+
.map((item) => item.trim())
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
export function normalizeNostrAccountId(accountId) {
|
|
62
|
+
if (typeof accountId !== "string")
|
|
63
|
+
return DEFAULT_NOSTR_ACCOUNT_ID;
|
|
64
|
+
const trimmed = accountId.trim();
|
|
65
|
+
return trimmed || DEFAULT_NOSTR_ACCOUNT_ID;
|
|
66
|
+
}
|
|
67
|
+
export function listNostrAccountIds(runtime) {
|
|
68
|
+
const ids = new Set();
|
|
69
|
+
const config = characterConfig(runtime);
|
|
70
|
+
if (stringSetting(runtime, "NOSTR_PRIVATE_KEY") || config.privateKey) {
|
|
71
|
+
ids.add(DEFAULT_NOSTR_ACCOUNT_ID);
|
|
72
|
+
}
|
|
73
|
+
for (const id of Object.keys(allAccountConfigs(runtime))) {
|
|
74
|
+
ids.add(normalizeNostrAccountId(id));
|
|
75
|
+
}
|
|
76
|
+
return Array.from(ids.size ? ids : new Set([DEFAULT_NOSTR_ACCOUNT_ID])).sort((a, b) => a.localeCompare(b));
|
|
77
|
+
}
|
|
78
|
+
export function resolveDefaultNostrAccountId(runtime) {
|
|
79
|
+
const requested = stringSetting(runtime, "NOSTR_DEFAULT_ACCOUNT_ID") ??
|
|
80
|
+
stringSetting(runtime, "NOSTR_ACCOUNT_ID");
|
|
81
|
+
if (requested)
|
|
82
|
+
return normalizeNostrAccountId(requested);
|
|
83
|
+
const ids = listNostrAccountIds(runtime);
|
|
84
|
+
return ids.includes(DEFAULT_NOSTR_ACCOUNT_ID) ? DEFAULT_NOSTR_ACCOUNT_ID : ids[0];
|
|
85
|
+
}
|
|
86
|
+
export function readNostrAccountId(...sources) {
|
|
87
|
+
for (const source of sources) {
|
|
88
|
+
if (!source || typeof source !== "object")
|
|
89
|
+
continue;
|
|
90
|
+
const record = source;
|
|
91
|
+
const parameters = record.parameters && typeof record.parameters === "object"
|
|
92
|
+
? record.parameters
|
|
93
|
+
: {};
|
|
94
|
+
const data = record.data && typeof record.data === "object"
|
|
95
|
+
? record.data
|
|
96
|
+
: {};
|
|
97
|
+
const metadata = record.metadata && typeof record.metadata === "object"
|
|
98
|
+
? record.metadata
|
|
99
|
+
: {};
|
|
100
|
+
const nostr = data.nostr && typeof data.nostr === "object" ? data.nostr : {};
|
|
101
|
+
const value = record.accountId ??
|
|
102
|
+
parameters.accountId ??
|
|
103
|
+
data.accountId ??
|
|
104
|
+
nostr.accountId ??
|
|
105
|
+
metadata.accountId;
|
|
106
|
+
if (typeof value === "string" && value.trim())
|
|
107
|
+
return normalizeNostrAccountId(value);
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
export function resolveNostrAccountSettings(runtime, requestedAccountId) {
|
|
112
|
+
const accountId = normalizeNostrAccountId(requestedAccountId ?? resolveDefaultNostrAccountId(runtime));
|
|
113
|
+
const base = characterConfig(runtime);
|
|
114
|
+
const account = accountConfig(runtime, accountId);
|
|
115
|
+
const allowEnv = accountId === DEFAULT_NOSTR_ACCOUNT_ID;
|
|
116
|
+
const relays = stringList(account.relays ?? base.relays ?? (allowEnv ? stringSetting(runtime, "NOSTR_RELAYS") : undefined));
|
|
117
|
+
const allowFrom = stringList(account.allowFrom ??
|
|
118
|
+
base.allowFrom ??
|
|
119
|
+
(allowEnv ? stringSetting(runtime, "NOSTR_ALLOW_FROM") : undefined));
|
|
120
|
+
return {
|
|
121
|
+
accountId,
|
|
122
|
+
privateKey: account.privateKey ??
|
|
123
|
+
base.privateKey ??
|
|
124
|
+
(allowEnv ? stringSetting(runtime, "NOSTR_PRIVATE_KEY") : undefined) ??
|
|
125
|
+
"",
|
|
126
|
+
publicKey: "",
|
|
127
|
+
relays: relays.length ? relays : DEFAULT_NOSTR_RELAYS,
|
|
128
|
+
dmPolicy: (account.dmPolicy ??
|
|
129
|
+
base.dmPolicy ??
|
|
130
|
+
(allowEnv ? stringSetting(runtime, "NOSTR_DM_POLICY") : undefined) ??
|
|
131
|
+
"pairing"),
|
|
132
|
+
allowFrom,
|
|
133
|
+
profile: account.profile ?? base.profile,
|
|
134
|
+
enabled: boolValue(account.enabled ??
|
|
135
|
+
base.enabled ??
|
|
136
|
+
(allowEnv ? stringSetting(runtime, "NOSTR_ENABLED") : undefined)),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=accounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.js","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAA0C,MAAM,YAAY,CAAC;AAE1F,MAAM,CAAC,MAAM,wBAAwB,GAAG,SAAS,CAAC;AAelD,SAAS,aAAa,CAAC,OAAsB,EAAE,GAAW;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE;QAAE,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACnE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,OAAsB;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,QAA+C,CAAC;IACnF,MAAM,GAAG,GAAG,QAAQ,EAAE,KAAK,CAAC;IAC5B,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAE,GAA+B,CAAC,CAAC,C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AC,SAAS,CAAC,CACjG,CAAC;IACF,MAAM,SAAS,GAAG,UAAU,CAC1B,OAAO,CAAC,SAAS;QACf,IAAI,CAAC,SAAS;QACd,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CACtE,CAAC;IAEF,OAAO;QACL,SAAS;QACT,UAAU,EACR,OAAO,CAAC,UAAU;YAClB,IAAI,CAAC,UAAU;YACf,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACpE,EAAE;QACJ,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB;QACrD,QAAQ,EAAE,CAAC,OAAO,CAAC,QAAQ;YACzB,IAAI,CAAC,QAAQ;YACb,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAClE,SAAS,CAAkB;QAC7B,SAAS;QACT,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;QACxC,OAAO,EAAE,SAAS,CAChB,OAAO,CAAC,OAAO;YACb,IAAI,CAAC,OAAO;YACZ,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CACnE;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nostr ConnectorAccountManager provider.
|
|
3
|
+
*
|
|
4
|
+
* Adapts the multi-account resolution helpers in `accounts.ts` to the
|
|
5
|
+
* `ConnectorAccountProvider` contract from
|
|
6
|
+
* `@elizaos/core/connectors/account-manager`.
|
|
7
|
+
*
|
|
8
|
+
* Source of truth for accounts is character settings (`character.settings.nostr`)
|
|
9
|
+
* + NOSTR_ACCOUNTS JSON env var + single-account env vars (NOSTR_PRIVATE_KEY,
|
|
10
|
+
* NOSTR_RELAYS, NOSTR_DM_POLICY).
|
|
11
|
+
*
|
|
12
|
+
* AccountKey is the nostr pubkey (hex). Role is `OWNER` since the private key
|
|
13
|
+
* is the user's identity. Public key is derived at service start time, so
|
|
14
|
+
* `externalId` may be empty until the service has resolved it; the manager
|
|
15
|
+
* tolerates this.
|
|
16
|
+
*/
|
|
17
|
+
import type { ConnectorAccountProvider, IAgentRuntime } from "@elizaos/core";
|
|
18
|
+
export declare const NOSTR_PROVIDER_ID = "nostr";
|
|
19
|
+
export declare function createNostrConnectorAccountProvider(runtime: IAgentRuntime): ConnectorAccountProvider;
|
|
20
|
+
//# sourceMappingURL=connector-account-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-account-provider.d.ts","sourceRoot":"","sources":["../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAIV,wBAAwB,EACxB,aAAa,EACd,MAAM,eAAe,CAAC;AASvB,eAAO,MAAM,iBAAiB,UAAU,CAAC;AA+BzC,wBAAgB,mCAAmC,CACjD,OAAO,EAAE,aAAa,GACrB,wBAAwB,CAiC1B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nostr ConnectorAccountManager provider.
|
|
3
|
+
*
|
|
4
|
+
* Adapts the multi-account resolution helpers in `accounts.ts` to the
|
|
5
|
+
* `ConnectorAccountProvider` contract from
|
|
6
|
+
* `@elizaos/core/connectors/account-manager`.
|
|
7
|
+
*
|
|
8
|
+
* Source of truth for accounts is character settings (`character.settings.nostr`)
|
|
9
|
+
* + NOSTR_ACCOUNTS JSON env var + single-account env vars (NOSTR_PRIVATE_KEY,
|
|
10
|
+
* NOSTR_RELAYS, NOSTR_DM_POLICY).
|
|
11
|
+
*
|
|
12
|
+
* AccountKey is the nostr pubkey (hex). Role is `OWNER` since the private key
|
|
13
|
+
* is the user's identity. Public key is derived at service start time, so
|
|
14
|
+
* `externalId` may be empty until the service has resolved it; the manager
|
|
15
|
+
* tolerates this.
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_NOSTR_ACCOUNT_ID, listNostrAccountIds, normalizeNostrAccountId, resolveNostrAccountSettings, } from "./accounts.js";
|
|
18
|
+
export const NOSTR_PROVIDER_ID = "nostr";
|
|
19
|
+
function accessGateForAccount(settings) {
|
|
20
|
+
if (settings.dmPolicy === "pairing")
|
|
21
|
+
return "pairing";
|
|
22
|
+
if (settings.dmPolicy === "disabled")
|
|
23
|
+
return "disabled";
|
|
24
|
+
return "open";
|
|
25
|
+
}
|
|
26
|
+
function toConnectorAccount(settings) {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
const configured = Boolean(settings.privateKey);
|
|
29
|
+
return {
|
|
30
|
+
id: normalizeNostrAccountId(settings.accountId),
|
|
31
|
+
provider: NOSTR_PROVIDER_ID,
|
|
32
|
+
label: settings.profile?.name ?? (settings.publicKey || settings.accountId),
|
|
33
|
+
role: "OWNER",
|
|
34
|
+
purpose: ["messaging"],
|
|
35
|
+
accessGate: accessGateForAccount(settings),
|
|
36
|
+
status: settings.enabled !== false && configured ? "connected" : "disabled",
|
|
37
|
+
externalId: settings.publicKey || undefined,
|
|
38
|
+
displayHandle: settings.profile?.name ?? (settings.publicKey || undefined),
|
|
39
|
+
createdAt: now,
|
|
40
|
+
updatedAt: now,
|
|
41
|
+
metadata: {
|
|
42
|
+
relays: settings.relays,
|
|
43
|
+
dmPolicy: settings.dmPolicy,
|
|
44
|
+
hasProfile: Boolean(settings.profile),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function createNostrConnectorAccountProvider(runtime) {
|
|
49
|
+
return {
|
|
50
|
+
provider: NOSTR_PROVIDER_ID,
|
|
51
|
+
label: "Nostr",
|
|
52
|
+
listAccounts: async (_manager) => {
|
|
53
|
+
const ids = listNostrAccountIds(runtime);
|
|
54
|
+
if (ids.length === 0) {
|
|
55
|
+
return [toConnectorAccount(resolveNostrAccountSettings(runtime, DEFAULT_NOSTR_ACCOUNT_ID))];
|
|
56
|
+
}
|
|
57
|
+
return ids.map((id) => toConnectorAccount(resolveNostrAccountSettings(runtime, id)));
|
|
58
|
+
},
|
|
59
|
+
createAccount: async (input, _manager) => {
|
|
60
|
+
return {
|
|
61
|
+
...input,
|
|
62
|
+
provider: NOSTR_PROVIDER_ID,
|
|
63
|
+
role: input.role ?? "OWNER",
|
|
64
|
+
purpose: input.purpose ?? ["messaging"],
|
|
65
|
+
accessGate: input.accessGate ?? "open",
|
|
66
|
+
status: input.status ?? "pending",
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
patchAccount: async (_accountId, patch, _manager) => {
|
|
70
|
+
return { ...patch, provider: NOSTR_PROVIDER_ID };
|
|
71
|
+
},
|
|
72
|
+
deleteAccount: async (_accountId, _manager) => {
|
|
73
|
+
// Provider-layer account deletion returns cleanly; runtime credentials live in character
|
|
74
|
+
// settings; deletion of those is out of band.
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=connector-account-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-account-provider.js","sourceRoot":"","sources":["../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAGvB,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC,SAAS,oBAAoB,CAAC,QAAuB;IACnD,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtD,IAAI,QAAQ,CAAC,QAA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CAAC,CAAC;YACzC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACrB,OAAO,CAAC,kBAAkB,CAAC,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC;YAC9F,CAAC;YACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,kBAAkB,CAAC,2BAA2B,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACvF,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,KAA4B,EAAE,QAAiC,EAAE,EAAE;YACvF,OAAO;gBACL,GAAG,KAAK;gBACR,QAAQ,EAAE,iBAAiB;gBAC3B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,OAAO;gBAC3B,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC;gBACvC,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,MAAM;gBACtC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,SAAS;aAClC,CAAC;QACJ,CAAC;QACD,YAAY,EAAE,KAAK,EACjB,UAAkB,EAClB,KAA4B,EAC5B,QAAiC,EACjC,EAAE;YACF,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC;QACnD,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,UAAkB,EAAE,QAAiC,EAAE,EAAE;YAC7E,yFAAyF;YACzF,8CAA8C;QAChD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nostr Plugin for ElizaOS
|
|
3
|
+
*
|
|
4
|
+
* Provides Nostr decentralized messaging integration for ElizaOS agents,
|
|
5
|
+
* supporting encrypted DMs via NIP-04 and profile management.
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from "@elizaos/core";
|
|
8
|
+
import { identityContextProvider } from "./providers/index.js";
|
|
9
|
+
import { NostrService } from "./service.js";
|
|
10
|
+
export * from "./accounts.js";
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
export { identityContextProvider, NostrService };
|
|
13
|
+
/**
|
|
14
|
+
* Nostr plugin definition
|
|
15
|
+
*/
|
|
16
|
+
declare const nostrPlugin: Plugin;
|
|
17
|
+
export default nostrPlugin;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,eAAe,CAAC;AAE9B,cAAc,YAAY,CAAC;AAI3B,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,CAAC;AAEjD;;GAEG;AACH,QAAA,MAAM,WAAW,EAAE,MA4DlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nostr Plugin for ElizaOS
|
|
3
|
+
*
|
|
4
|
+
* Provides Nostr decentralized messaging integration for ElizaOS agents,
|
|
5
|
+
* supporting encrypted DMs via NIP-04 and profile management.
|
|
6
|
+
*/
|
|
7
|
+
import { getConnectorAccountManager, logger } from "@elizaos/core";
|
|
8
|
+
import { createNostrConnectorAccountProvider } from "./connector-account-provider.js";
|
|
9
|
+
import { identityContextProvider } from "./providers/index.js";
|
|
10
|
+
import { NostrService } from "./service.js";
|
|
11
|
+
import { DEFAULT_NOSTR_RELAYS } from "./types.js";
|
|
12
|
+
export * from "./accounts.js";
|
|
13
|
+
// Export types
|
|
14
|
+
export * from "./types.js";
|
|
15
|
+
// Export service / providers / actions
|
|
16
|
+
// Nostr DMs route through MESSAGE. Public notes route through POST. Profile
|
|
17
|
+
// publishing is connector-owned identity metadata, not a planner action.
|
|
18
|
+
export { identityContextProvider, NostrService };
|
|
19
|
+
/**
|
|
20
|
+
* Nostr plugin definition
|
|
21
|
+
*/
|
|
22
|
+
const nostrPlugin = {
|
|
23
|
+
name: "nostr",
|
|
24
|
+
description: "Nostr decentralized messaging plugin for ElizaOS agents",
|
|
25
|
+
services: [NostrService],
|
|
26
|
+
actions: [],
|
|
27
|
+
providers: [identityContextProvider],
|
|
28
|
+
tests: [],
|
|
29
|
+
// Self-declared auto-enable: activate when the "nostr" connector is
|
|
30
|
+
// configured under config.connectors. The hardcoded CONNECTOR_PLUGINS map
|
|
31
|
+
// in plugin-auto-enable-engine.ts still serves as a fallback.
|
|
32
|
+
autoEnable: {
|
|
33
|
+
connectorKeys: ["nostr"],
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* Plugin initialization hook
|
|
37
|
+
*/
|
|
38
|
+
init: async (config, runtime) => {
|
|
39
|
+
logger.info("Initializing Nostr plugin...");
|
|
40
|
+
try {
|
|
41
|
+
const manager = getConnectorAccountManager(runtime);
|
|
42
|
+
manager.registerProvider(createNostrConnectorAccountProvider(runtime));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
logger.warn({
|
|
46
|
+
src: "plugin:nostr",
|
|
47
|
+
err: err instanceof Error ? err.message : String(err),
|
|
48
|
+
}, "Failed to register Nostr provider with ConnectorAccountManager");
|
|
49
|
+
}
|
|
50
|
+
// Log configuration status
|
|
51
|
+
const hasPrivateKey = Boolean(config.NOSTR_PRIVATE_KEY || process.env.NOSTR_PRIVATE_KEY);
|
|
52
|
+
const relaysRaw = config.NOSTR_RELAYS || process.env.NOSTR_RELAYS || "";
|
|
53
|
+
const relays = relaysRaw ? relaysRaw.split(",").length : DEFAULT_NOSTR_RELAYS.length;
|
|
54
|
+
logger.info(`Nostr plugin configuration:`);
|
|
55
|
+
logger.info(` - Private key configured: ${hasPrivateKey ? "Yes" : "No"}`);
|
|
56
|
+
logger.info(` - Relays: ${relays} relay(s)`);
|
|
57
|
+
logger.info(` - DM policy: ${config.NOSTR_DM_POLICY || process.env.NOSTR_DM_POLICY || "pairing"}`);
|
|
58
|
+
if (!hasPrivateKey) {
|
|
59
|
+
logger.warn("Nostr private key not configured. Set NOSTR_PRIVATE_KEY (hex or nsec format).");
|
|
60
|
+
}
|
|
61
|
+
logger.info("Nostr plugin initialized");
|
|
62
|
+
},
|
|
63
|
+
async dispose(runtime) {
|
|
64
|
+
const svc = runtime.getService(NostrService.serviceType);
|
|
65
|
+
await svc?.stop();
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
export default nostrPlugin;
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,cAAc,eAAe,CAAC;AAC9B,eAAe;AACf,cAAc,YAAY,CAAC;AAC3B,uCAAuC;AACvC,4EAA4E;AAC5E,yEAAyE;AACzE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,GAAW;IAC1B,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,yDAAyD;IAEtE,QAAQ,EAAE,CAAC,YAAY,CAAC;IAExB,OAAO,EAAE,EAAE;IAEX,SAAS,EAAE,CAAC,uBAAuB,CAA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AAC;QAC9C,MAAM,CAAC,IAAI,CACT,kBAAkB,MAAM,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,SAAS,EAAE,CACvF,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,CAAC,IAAI,CAAC,+EAA+E,CAAC,CAAC;QAC/F,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,OAAsB;QAClC,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAe,YAAY,CAAC,WAAW,CAAC,CAAC;QACvE,MAAM,GAAG,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC;CACF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityContext.d.ts","sourceRoot":"","sources":["../../src/providers/identityContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAM5F,eAAO,MAAM,uBAAuB,EAAE,QAmErC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity context provider for Nostr plugin.
|
|
3
|
+
*/
|
|
4
|
+
import { NOSTR_SERVICE_NAME } from "../types.js";
|
|
5
|
+
const MAX_RELAYS_IN_STATE = 12;
|
|
6
|
+
export const identityContextProvider = {
|
|
7
|
+
name: "nostrIdentityContext",
|
|
8
|
+
description: "Provides information about the bot's Nostr identity",
|
|
9
|
+
descriptionCompressed: "provide information bot Nostr identity",
|
|
10
|
+
dynamic: true,
|
|
11
|
+
contextGate: { anyOf: ["social", "connectors"] },
|
|
12
|
+
cacheStable: false,
|
|
13
|
+
cacheScope: "turn",
|
|
14
|
+
contexts: ["social", "connectors"],
|
|
15
|
+
get: async (runtime, message, state) => {
|
|
16
|
+
// Only provide context for Nostr messages
|
|
17
|
+
if (message.content.source !== "nostr") {
|
|
18
|
+
return {
|
|
19
|
+
data: {},
|
|
20
|
+
values: {},
|
|
21
|
+
text: "",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const nostrService = runtime.getService(NOSTR_SERVICE_NAME);
|
|
25
|
+
if (!nostrService?.isConnected()) {
|
|
26
|
+
return {
|
|
27
|
+
data: { connected: false },
|
|
28
|
+
values: { connected: false },
|
|
29
|
+
text: "",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const agentName = state.agentName || "The agent";
|
|
33
|
+
try {
|
|
34
|
+
const publicKey = nostrService.getPublicKey();
|
|
35
|
+
const npub = nostrService.getNpub();
|
|
36
|
+
const relays = nostrService.getRelays();
|
|
37
|
+
const shownRelays = relays.slice(0, MAX_RELAYS_IN_STATE);
|
|
38
|
+
const truncated = relays.length > shownRelays.length;
|
|
39
|
+
const responseText = `${agentName} is connected to Nostr with pubkey ${npub}. ` +
|
|
40
|
+
`Connected to ${relays.length} relay(s): ${shownRelays.join(", ")}${truncated ? " ..." : ""}. ` +
|
|
41
|
+
`Nostr is a decentralized social protocol using cryptographic keys for identity.`;
|
|
42
|
+
return {
|
|
43
|
+
data: {
|
|
44
|
+
publicKey,
|
|
45
|
+
npub,
|
|
46
|
+
relays: shownRelays,
|
|
47
|
+
relayCount: relays.length,
|
|
48
|
+
shownRelayCount: shownRelays.length,
|
|
49
|
+
truncated,
|
|
50
|
+
connected: true,
|
|
51
|
+
},
|
|
52
|
+
values: {
|
|
53
|
+
publicKey,
|
|
54
|
+
npub,
|
|
55
|
+
relayCount: relays.length,
|
|
56
|
+
},
|
|
57
|
+
text: responseText,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return {
|
|
62
|
+
data: { connected: false, error: error instanceof Error ? error.message : String(error) },
|
|
63
|
+
values: { connected: false },
|
|
64
|
+
text: "",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=identityContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityContext.js","sourceRoot":"","sources":["../../src/providers/identityContext.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,MAAM,uBAAuB,GAAa;IAC/C,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EAAE,qDAAqD;IAClE,qBAAqB,EAAE,wCAAwC;IAC/D,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE;IAChD,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;IAClC,GAAG,EAAE,KAAK,EAAE,OAAsB,EAAE,OAAe,EAAE,KAAY,EAA2B,EAAE;QAC5F,0CAA0C;QAC1C,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YACvC,OAAO;gBACL,IAAI,EAAE,EAAE;gBACR,MAAM,EAAE,EAAE;gBACV,IAAI,EAAE,EAAE;aACT,CAAC;QACJ,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAe,kBAAkB,CAAC,CAAC;QAE1E,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,CAAC;YACjC,OAAO;gBACL,IAAI,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC1B,MAAM,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC5B,IAAI,EAAE,EAAE;aACT,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,WAAW,CAAC;QACjD,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,YAAY,CAAC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"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nostr service implementation for ElizaOS.
|
|
3
|
+
*/
|
|
4
|
+
import { type Content, type IAgentRuntime, type Memory, type MessageConnectorQueryContext, type MessageConnectorTarget, type MessageConnectorUserContext, Service, type TargetInfo, type UUID } from "@elizaos/core";
|
|
5
|
+
import { type INostrService, type NostrDmSendOptions, type NostrProfile, type NostrSendResult, type NostrSettings } from "./types.js";
|
|
6
|
+
interface PostConnectorQueryContext {
|
|
7
|
+
runtime: IAgentRuntime;
|
|
8
|
+
roomId?: UUID;
|
|
9
|
+
source?: string;
|
|
10
|
+
target?: TargetInfo;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export declare class NostrService extends Service implements INostrService {
|
|
14
|
+
static serviceType: string;
|
|
15
|
+
capabilityDescription: string;
|
|
16
|
+
private settings;
|
|
17
|
+
private pool;
|
|
18
|
+
private privateKey;
|
|
19
|
+
private connected;
|
|
20
|
+
private seenEventIds;
|
|
21
|
+
private accountServices;
|
|
22
|
+
/**
|
|
23
|
+
* Start the Nostr service.
|
|
24
|
+
*/
|
|
25
|
+
static start(runtime: IAgentRuntime): Promise<NostrService>;
|
|
26
|
+
static registerSendHandlers(runtime: IAgentRuntime, serviceInstance: NostrService): void;
|
|
27
|
+
private registerPostConnector;
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the service.
|
|
30
|
+
*/
|
|
31
|
+
private initialize;
|
|
32
|
+
private initializeAccount;
|
|
33
|
+
/**
|
|
34
|
+
* Stop the Nostr service.
|
|
35
|
+
*/
|
|
36
|
+
stop(): Promise<void>;
|
|
37
|
+
private getAccountServiceList;
|
|
38
|
+
private getDefaultAccountService;
|
|
39
|
+
private getAccountService;
|
|
40
|
+
/**
|
|
41
|
+
* Load settings from runtime configuration.
|
|
42
|
+
*/
|
|
43
|
+
private loadSettings;
|
|
44
|
+
/**
|
|
45
|
+
* Validate the settings.
|
|
46
|
+
*/
|
|
47
|
+
private validateSettings;
|
|
48
|
+
/**
|
|
49
|
+
* Start the DM subscription.
|
|
50
|
+
*/
|
|
51
|
+
private startSubscription;
|
|
52
|
+
/**
|
|
53
|
+
* Handle an incoming event.
|
|
54
|
+
*/
|
|
55
|
+
private handleEvent;
|
|
56
|
+
/**
|
|
57
|
+
* Check if the service is connected.
|
|
58
|
+
*/
|
|
59
|
+
isConnected(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get the bot's public key in hex format.
|
|
62
|
+
*/
|
|
63
|
+
getPublicKey(): string;
|
|
64
|
+
getAccountId(runtime?: IAgentRuntime): string;
|
|
65
|
+
/**
|
|
66
|
+
* Get the bot's public key in npub format.
|
|
67
|
+
*/
|
|
68
|
+
getNpub(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Get connected relays.
|
|
71
|
+
*/
|
|
72
|
+
getRelays(): string[];
|
|
73
|
+
handleSendMessage(_runtime: IAgentRuntime, target: TargetInfo, content: Content): Promise<void>;
|
|
74
|
+
handleSendPost(runtime: IAgentRuntime, content: Content): Promise<Memory>;
|
|
75
|
+
fetchConnectorFeed(context: PostConnectorQueryContext, params?: {
|
|
76
|
+
feed?: string;
|
|
77
|
+
target?: TargetInfo;
|
|
78
|
+
limit?: number;
|
|
79
|
+
cursor?: string;
|
|
80
|
+
}): Promise<Memory[]>;
|
|
81
|
+
searchConnectorPosts(context: PostConnectorQueryContext, params: {
|
|
82
|
+
query: string;
|
|
83
|
+
limit?: number;
|
|
84
|
+
cursor?: string;
|
|
85
|
+
}): Promise<Memory[]>;
|
|
86
|
+
fetchConnectorMessages(context: MessageConnectorQueryContext, params?: {
|
|
87
|
+
target?: TargetInfo;
|
|
88
|
+
limit?: number;
|
|
89
|
+
before?: string;
|
|
90
|
+
after?: string;
|
|
91
|
+
}): Promise<Memory[]>;
|
|
92
|
+
resolveConnectorTargets(query: string, _context: MessageConnectorQueryContext): Promise<MessageConnectorTarget[]>;
|
|
93
|
+
listRecentConnectorTargets(_context: MessageConnectorQueryContext): Promise<MessageConnectorTarget[]>;
|
|
94
|
+
getConnectorUserContext(entityId: string, _context: MessageConnectorQueryContext): Promise<MessageConnectorUserContext | null>;
|
|
95
|
+
private nostrEventToPostMemory;
|
|
96
|
+
private nostrEventToDmMemory;
|
|
97
|
+
private buildPubkeyTarget;
|
|
98
|
+
/**
|
|
99
|
+
* Send a DM to a pubkey.
|
|
100
|
+
*/
|
|
101
|
+
sendDm(options: NostrDmSendOptions): Promise<NostrSendResult>;
|
|
102
|
+
/**
|
|
103
|
+
* Publish profile (kind:0).
|
|
104
|
+
*/
|
|
105
|
+
publishProfile(profile: NostrProfile): Promise<NostrSendResult>;
|
|
106
|
+
/**
|
|
107
|
+
* Publish a text note (kind:1).
|
|
108
|
+
*/
|
|
109
|
+
publishNote(text: string, tags?: string[][]): Promise<NostrSendResult>;
|
|
110
|
+
/**
|
|
111
|
+
* Get the settings.
|
|
112
|
+
*/
|
|
113
|
+
getSettings(): NostrSettings | null;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,KAAK,OAAO,EAGZ,KAAK,aAAa,EAElB,KAAK,MAAM,EACX,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,OAAO,EACP,KAAK,UAAU,EACf,KAAK,IAAI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