@sundaeswap/sprinkles 0.6.1 → 0.8.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.
Files changed (197) hide show
  1. package/README.md +178 -181
  2. package/dist/cjs/Sprinkle/__tests__/action-integration.test.js +590 -0
  3. package/dist/cjs/Sprinkle/__tests__/action-integration.test.js.map +1 -0
  4. package/dist/cjs/Sprinkle/__tests__/action-registry.test.js +193 -0
  5. package/dist/cjs/Sprinkle/__tests__/action-registry.test.js.map +1 -0
  6. package/dist/cjs/Sprinkle/__tests__/action-runner.test.js +304 -0
  7. package/dist/cjs/Sprinkle/__tests__/action-runner.test.js.map +1 -0
  8. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js +1110 -0
  9. package/dist/cjs/Sprinkle/__tests__/builtin-actions.test.js.map +1 -0
  10. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js +744 -0
  11. package/dist/cjs/Sprinkle/__tests__/cli-adapter.test.js.map +1 -0
  12. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  13. package/dist/cjs/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  14. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js +711 -0
  15. package/dist/cjs/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -0
  16. package/dist/cjs/Sprinkle/__tests__/native-script.test.js +390 -0
  17. package/dist/cjs/Sprinkle/__tests__/native-script.test.js.map +1 -0
  18. package/dist/cjs/Sprinkle/__tests__/tui-helpers.test.js +334 -0
  19. package/dist/cjs/Sprinkle/__tests__/tui-helpers.test.js.map +1 -0
  20. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js +367 -0
  21. package/dist/cjs/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  22. package/dist/cjs/Sprinkle/__tests__/wallet-transaction-actions.test.js +749 -0
  23. package/dist/cjs/Sprinkle/__tests__/wallet-transaction-actions.test.js.map +1 -0
  24. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js +164 -0
  25. package/dist/cjs/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  26. package/dist/cjs/Sprinkle/actions/builtin/blaze-helper.js +61 -0
  27. package/dist/cjs/Sprinkle/actions/builtin/blaze-helper.js.map +1 -0
  28. package/dist/cjs/Sprinkle/actions/builtin/index.js +174 -0
  29. package/dist/cjs/Sprinkle/actions/builtin/index.js.map +1 -0
  30. package/dist/cjs/Sprinkle/actions/builtin/native-script.js +139 -0
  31. package/dist/cjs/Sprinkle/actions/builtin/native-script.js.map +1 -0
  32. package/dist/cjs/Sprinkle/actions/builtin/profile-actions.js +202 -0
  33. package/dist/cjs/Sprinkle/actions/builtin/profile-actions.js.map +1 -0
  34. package/dist/cjs/Sprinkle/actions/builtin/settings-actions.js +87 -0
  35. package/dist/cjs/Sprinkle/actions/builtin/settings-actions.js.map +1 -0
  36. package/dist/cjs/Sprinkle/actions/builtin/transaction-actions.js +345 -0
  37. package/dist/cjs/Sprinkle/actions/builtin/transaction-actions.js.map +1 -0
  38. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js +218 -0
  39. package/dist/cjs/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  40. package/dist/cjs/Sprinkle/actions/builtin/wallet-actions.js +212 -0
  41. package/dist/cjs/Sprinkle/actions/builtin/wallet-actions.js.map +1 -0
  42. package/dist/cjs/Sprinkle/actions/cli-adapter.js +390 -0
  43. package/dist/cjs/Sprinkle/actions/cli-adapter.js.map +1 -0
  44. package/dist/cjs/Sprinkle/actions/index.js +139 -0
  45. package/dist/cjs/Sprinkle/actions/index.js.map +1 -0
  46. package/dist/cjs/Sprinkle/actions/mcp-adapter.js +557 -0
  47. package/dist/cjs/Sprinkle/actions/mcp-adapter.js.map +1 -0
  48. package/dist/cjs/Sprinkle/actions/registry.js +92 -0
  49. package/dist/cjs/Sprinkle/actions/registry.js.map +1 -0
  50. package/dist/cjs/Sprinkle/actions/runner.js +190 -0
  51. package/dist/cjs/Sprinkle/actions/runner.js.map +1 -0
  52. package/dist/cjs/Sprinkle/actions/tui-helpers.js +96 -0
  53. package/dist/cjs/Sprinkle/actions/tui-helpers.js.map +1 -0
  54. package/dist/cjs/Sprinkle/actions/types.js +68 -0
  55. package/dist/cjs/Sprinkle/actions/types.js.map +1 -0
  56. package/dist/cjs/Sprinkle/index.js +678 -5
  57. package/dist/cjs/Sprinkle/index.js.map +1 -1
  58. package/dist/cjs/Sprinkle/prompts.js +12 -7
  59. package/dist/cjs/Sprinkle/prompts.js.map +1 -1
  60. package/dist/cjs/Sprinkle/schemas.js +17 -1
  61. package/dist/cjs/Sprinkle/schemas.js.map +1 -1
  62. package/dist/cjs/Sprinkle/type-guards.js +7 -1
  63. package/dist/cjs/Sprinkle/type-guards.js.map +1 -1
  64. package/dist/esm/Sprinkle/__tests__/action-integration.test.js +588 -0
  65. package/dist/esm/Sprinkle/__tests__/action-integration.test.js.map +1 -0
  66. package/dist/esm/Sprinkle/__tests__/action-registry.test.js +192 -0
  67. package/dist/esm/Sprinkle/__tests__/action-registry.test.js.map +1 -0
  68. package/dist/esm/Sprinkle/__tests__/action-runner.test.js +302 -0
  69. package/dist/esm/Sprinkle/__tests__/action-runner.test.js.map +1 -0
  70. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js +1107 -0
  71. package/dist/esm/Sprinkle/__tests__/builtin-actions.test.js.map +1 -0
  72. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js +742 -0
  73. package/dist/esm/Sprinkle/__tests__/cli-adapter.test.js.map +1 -0
  74. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js +15 -1
  75. package/dist/esm/Sprinkle/__tests__/fill-in-struct.test.js.map +1 -1
  76. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js +710 -0
  77. package/dist/esm/Sprinkle/__tests__/mcp-adapter.test.js.map +1 -0
  78. package/dist/esm/Sprinkle/__tests__/native-script.test.js +388 -0
  79. package/dist/esm/Sprinkle/__tests__/native-script.test.js.map +1 -0
  80. package/dist/esm/Sprinkle/__tests__/tui-helpers.test.js +332 -0
  81. package/dist/esm/Sprinkle/__tests__/tui-helpers.test.js.map +1 -0
  82. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js +365 -0
  83. package/dist/esm/Sprinkle/__tests__/utility-actions.test.js.map +1 -0
  84. package/dist/esm/Sprinkle/__tests__/wallet-transaction-actions.test.js +747 -0
  85. package/dist/esm/Sprinkle/__tests__/wallet-transaction-actions.test.js.map +1 -0
  86. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js +159 -0
  87. package/dist/esm/Sprinkle/actions/builtin/addressbook-actions.js.map +1 -0
  88. package/dist/esm/Sprinkle/actions/builtin/blaze-helper.js +55 -0
  89. package/dist/esm/Sprinkle/actions/builtin/blaze-helper.js.map +1 -0
  90. package/dist/esm/Sprinkle/actions/builtin/index.js +37 -0
  91. package/dist/esm/Sprinkle/actions/builtin/index.js.map +1 -0
  92. package/dist/esm/Sprinkle/actions/builtin/native-script.js +133 -0
  93. package/dist/esm/Sprinkle/actions/builtin/native-script.js.map +1 -0
  94. package/dist/esm/Sprinkle/actions/builtin/profile-actions.js +197 -0
  95. package/dist/esm/Sprinkle/actions/builtin/profile-actions.js.map +1 -0
  96. package/dist/esm/Sprinkle/actions/builtin/settings-actions.js +81 -0
  97. package/dist/esm/Sprinkle/actions/builtin/settings-actions.js.map +1 -0
  98. package/dist/esm/Sprinkle/actions/builtin/transaction-actions.js +340 -0
  99. package/dist/esm/Sprinkle/actions/builtin/transaction-actions.js.map +1 -0
  100. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js +213 -0
  101. package/dist/esm/Sprinkle/actions/builtin/utility-actions.js.map +1 -0
  102. package/dist/esm/Sprinkle/actions/builtin/wallet-actions.js +207 -0
  103. package/dist/esm/Sprinkle/actions/builtin/wallet-actions.js.map +1 -0
  104. package/dist/esm/Sprinkle/actions/cli-adapter.js +379 -0
  105. package/dist/esm/Sprinkle/actions/cli-adapter.js.map +1 -0
  106. package/dist/esm/Sprinkle/actions/index.js +12 -0
  107. package/dist/esm/Sprinkle/actions/index.js.map +1 -0
  108. package/dist/esm/Sprinkle/actions/mcp-adapter.js +547 -0
  109. package/dist/esm/Sprinkle/actions/mcp-adapter.js.map +1 -0
  110. package/dist/esm/Sprinkle/actions/registry.js +85 -0
  111. package/dist/esm/Sprinkle/actions/registry.js.map +1 -0
  112. package/dist/esm/Sprinkle/actions/runner.js +182 -0
  113. package/dist/esm/Sprinkle/actions/runner.js.map +1 -0
  114. package/dist/esm/Sprinkle/actions/tui-helpers.js +91 -0
  115. package/dist/esm/Sprinkle/actions/tui-helpers.js.map +1 -0
  116. package/dist/esm/Sprinkle/actions/types.js +61 -0
  117. package/dist/esm/Sprinkle/actions/types.js.map +1 -0
  118. package/dist/esm/Sprinkle/index.js +517 -7
  119. package/dist/esm/Sprinkle/index.js.map +1 -1
  120. package/dist/esm/Sprinkle/prompts.js +12 -7
  121. package/dist/esm/Sprinkle/prompts.js.map +1 -1
  122. package/dist/esm/Sprinkle/schemas.js +16 -0
  123. package/dist/esm/Sprinkle/schemas.js.map +1 -1
  124. package/dist/esm/Sprinkle/type-guards.js +3 -0
  125. package/dist/esm/Sprinkle/type-guards.js.map +1 -1
  126. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts +50 -0
  127. package/dist/types/Sprinkle/actions/builtin/addressbook-actions.d.ts.map +1 -0
  128. package/dist/types/Sprinkle/actions/builtin/blaze-helper.d.ts +39 -0
  129. package/dist/types/Sprinkle/actions/builtin/blaze-helper.d.ts.map +1 -0
  130. package/dist/types/Sprinkle/actions/builtin/index.d.ts +30 -0
  131. package/dist/types/Sprinkle/actions/builtin/index.d.ts.map +1 -0
  132. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts +27 -0
  133. package/dist/types/Sprinkle/actions/builtin/native-script.d.ts.map +1 -0
  134. package/dist/types/Sprinkle/actions/builtin/profile-actions.d.ts +55 -0
  135. package/dist/types/Sprinkle/actions/builtin/profile-actions.d.ts.map +1 -0
  136. package/dist/types/Sprinkle/actions/builtin/settings-actions.d.ts +32 -0
  137. package/dist/types/Sprinkle/actions/builtin/settings-actions.d.ts.map +1 -0
  138. package/dist/types/Sprinkle/actions/builtin/transaction-actions.d.ts +70 -0
  139. package/dist/types/Sprinkle/actions/builtin/transaction-actions.d.ts.map +1 -0
  140. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts +48 -0
  141. package/dist/types/Sprinkle/actions/builtin/utility-actions.d.ts.map +1 -0
  142. package/dist/types/Sprinkle/actions/builtin/wallet-actions.d.ts +50 -0
  143. package/dist/types/Sprinkle/actions/builtin/wallet-actions.d.ts.map +1 -0
  144. package/dist/types/Sprinkle/actions/cli-adapter.d.ts +104 -0
  145. package/dist/types/Sprinkle/actions/cli-adapter.d.ts.map +1 -0
  146. package/dist/types/Sprinkle/actions/index.d.ts +13 -0
  147. package/dist/types/Sprinkle/actions/index.d.ts.map +1 -0
  148. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts +116 -0
  149. package/dist/types/Sprinkle/actions/mcp-adapter.d.ts.map +1 -0
  150. package/dist/types/Sprinkle/actions/registry.d.ts +42 -0
  151. package/dist/types/Sprinkle/actions/registry.d.ts.map +1 -0
  152. package/dist/types/Sprinkle/actions/runner.d.ts +45 -0
  153. package/dist/types/Sprinkle/actions/runner.d.ts.map +1 -0
  154. package/dist/types/Sprinkle/actions/tui-helpers.d.ts +53 -0
  155. package/dist/types/Sprinkle/actions/tui-helpers.d.ts.map +1 -0
  156. package/dist/types/Sprinkle/actions/types.d.ts +76 -0
  157. package/dist/types/Sprinkle/actions/types.d.ts.map +1 -0
  158. package/dist/types/Sprinkle/index.d.ts +84 -2
  159. package/dist/types/Sprinkle/index.d.ts.map +1 -1
  160. package/dist/types/Sprinkle/prompts.d.ts.map +1 -1
  161. package/dist/types/Sprinkle/schemas.d.ts +72 -0
  162. package/dist/types/Sprinkle/schemas.d.ts.map +1 -1
  163. package/dist/types/Sprinkle/type-guards.d.ts +4 -1
  164. package/dist/types/Sprinkle/type-guards.d.ts.map +1 -1
  165. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  166. package/package.json +9 -2
  167. package/src/Sprinkle/__tests__/action-integration.test.ts +558 -0
  168. package/src/Sprinkle/__tests__/action-registry.test.ts +187 -0
  169. package/src/Sprinkle/__tests__/action-runner.test.ts +324 -0
  170. package/src/Sprinkle/__tests__/builtin-actions.test.ts +1022 -0
  171. package/src/Sprinkle/__tests__/cli-adapter.test.ts +736 -0
  172. package/src/Sprinkle/__tests__/fill-in-struct.test.ts +23 -1
  173. package/src/Sprinkle/__tests__/mcp-adapter.test.ts +720 -0
  174. package/src/Sprinkle/__tests__/native-script.test.ts +341 -0
  175. package/src/Sprinkle/__tests__/tui-helpers.test.ts +325 -0
  176. package/src/Sprinkle/__tests__/utility-actions.test.ts +348 -0
  177. package/src/Sprinkle/__tests__/wallet-transaction-actions.test.ts +695 -0
  178. package/src/Sprinkle/actions/builtin/addressbook-actions.ts +168 -0
  179. package/src/Sprinkle/actions/builtin/blaze-helper.ts +89 -0
  180. package/src/Sprinkle/actions/builtin/index.ts +125 -0
  181. package/src/Sprinkle/actions/builtin/native-script.ts +165 -0
  182. package/src/Sprinkle/actions/builtin/profile-actions.ts +229 -0
  183. package/src/Sprinkle/actions/builtin/settings-actions.ts +99 -0
  184. package/src/Sprinkle/actions/builtin/transaction-actions.ts +381 -0
  185. package/src/Sprinkle/actions/builtin/utility-actions.ts +285 -0
  186. package/src/Sprinkle/actions/builtin/wallet-actions.ts +233 -0
  187. package/src/Sprinkle/actions/cli-adapter.ts +446 -0
  188. package/src/Sprinkle/actions/index.ts +33 -0
  189. package/src/Sprinkle/actions/mcp-adapter.ts +638 -0
  190. package/src/Sprinkle/actions/registry.ts +97 -0
  191. package/src/Sprinkle/actions/runner.ts +200 -0
  192. package/src/Sprinkle/actions/tui-helpers.ts +114 -0
  193. package/src/Sprinkle/actions/types.ts +91 -0
  194. package/src/Sprinkle/index.ts +612 -3
  195. package/src/Sprinkle/prompts.ts +118 -72
  196. package/src/Sprinkle/schemas.ts +20 -0
  197. package/src/Sprinkle/type-guards.ts +9 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Built-in profile management actions for the Sprinkle action system.
3
+ * These actions expose profile CRUD operations as non-interactive actions
4
+ * available in CLI and MCP modes.
5
+ *
6
+ * All actions use category "sprinkles".
7
+ */
8
+
9
+ import { Type } from "@sinclair/typebox";
10
+ import type { TSchema } from "@sinclair/typebox";
11
+ import { ActionError } from "../types.js";
12
+ import type { IAction } from "../types.js";
13
+
14
+ /** Shape of a profile entry as returned by profile actions */
15
+ const ProfileEntrySchema = Type.Object({
16
+ id: Type.String(),
17
+ name: Type.String(),
18
+ description: Type.Optional(Type.String()),
19
+ createdAt: Type.String(),
20
+ updatedAt: Type.String(),
21
+ });
22
+
23
+ /**
24
+ * `list-profiles` -- Returns all profiles and the active profile ID.
25
+ */
26
+ export const listProfiles: IAction<
27
+ Record<string, never>,
28
+ { profiles: unknown[]; activeProfileId: string | undefined },
29
+ TSchema
30
+ > = {
31
+ name: "list-profiles",
32
+ description: "List all profiles and indicate which one is currently active.",
33
+ category: "sprinkles",
34
+ inputSchema: Type.Object({}),
35
+ outputSchema: Type.Object({
36
+ profiles: Type.Array(ProfileEntrySchema),
37
+ activeProfileId: Type.Optional(Type.String()),
38
+ }),
39
+ execute: async (_input, context) => {
40
+ const entries = context.sprinkle.scanProfiles();
41
+ const profiles = entries.map((e) => ({
42
+ id: e.id,
43
+ name: e.meta.name,
44
+ description: e.meta.description,
45
+ createdAt: e.meta.createdAt,
46
+ updatedAt: e.meta.updatedAt,
47
+ }));
48
+ return {
49
+ profiles,
50
+ activeProfileId: context.sprinkle.currentProfile?.id,
51
+ };
52
+ },
53
+ };
54
+
55
+ /**
56
+ * `get-profile` -- Returns metadata and settings for a specific profile.
57
+ * Settings are masked by default; pass `includeSensitive: true` to get raw values.
58
+ */
59
+ export const getProfile: IAction<
60
+ { id: string; includeSensitive?: boolean },
61
+ unknown,
62
+ TSchema
63
+ > = {
64
+ name: "get-profile",
65
+ description:
66
+ "Get metadata and settings for a profile. Sensitive fields are masked by default.",
67
+ category: "sprinkles",
68
+ inputSchema: Type.Object({
69
+ id: Type.String(),
70
+ includeSensitive: Type.Optional(Type.Boolean({ default: false })),
71
+ }),
72
+ outputSchema: Type.Object({
73
+ id: Type.String(),
74
+ name: Type.String(),
75
+ description: Type.Optional(Type.String()),
76
+ createdAt: Type.String(),
77
+ updatedAt: Type.String(),
78
+ settings: Type.Any(),
79
+ }),
80
+ execute: async (input, context) => {
81
+ // Validate ID to prevent path traversal (defense in depth)
82
+ if (input.id.includes("/") || input.id.includes("\\") || input.id.includes("..")) {
83
+ throw new ActionError(
84
+ `Invalid profile ID "${input.id}".`,
85
+ "INVALID_PROFILE_ID",
86
+ { id: input.id },
87
+ );
88
+ }
89
+
90
+ const profile = context.sprinkle.getProfileById(input.id);
91
+ if (!profile) {
92
+ throw new ActionError(
93
+ `Profile "${input.id}" not found.`,
94
+ "PROFILE_NOT_FOUND",
95
+ { id: input.id },
96
+ );
97
+ }
98
+
99
+ // Read the profile file to get settings
100
+ const fs = await import("fs");
101
+ const path = await import("path");
102
+ const storagePath = context.sprinkle.storagePath;
103
+
104
+ const profilePath = path.join(storagePath, "profiles", `${input.id}.json`);
105
+ let settings: unknown = {};
106
+ try {
107
+ const content = fs.readFileSync(profilePath, "utf-8");
108
+ const parsed = JSON.parse(content);
109
+ settings = parsed.settings ?? {};
110
+ } catch (err) {
111
+ // Throw an error so the caller knows the profile file couldn't be read
112
+ throw new ActionError(
113
+ `Failed to read profile "${input.id}": ${err instanceof Error ? err.message : String(err)}`,
114
+ "PROFILE_READ_ERROR",
115
+ { id: input.id, error: err instanceof Error ? err.message : String(err) },
116
+ );
117
+ }
118
+
119
+ // Mask sensitive fields unless includeSensitive is true
120
+ if (!input.includeSensitive) {
121
+ const { maskSensitiveFields } = await import("../../encryption.js");
122
+ settings = maskSensitiveFields(settings, context.sprinkle.type);
123
+ }
124
+
125
+ return {
126
+ id: profile.id,
127
+ name: profile.meta.name,
128
+ description: profile.meta.description,
129
+ createdAt: profile.meta.createdAt,
130
+ updatedAt: profile.meta.updatedAt,
131
+ settings,
132
+ };
133
+ },
134
+ };
135
+
136
+ /**
137
+ * `set-profile` -- Switch the active profile.
138
+ */
139
+ export const setProfile: IAction<
140
+ { id: string },
141
+ { id: string; name: string },
142
+ TSchema
143
+ > = {
144
+ name: "set-profile",
145
+ description: "Switch the active profile.",
146
+ category: "sprinkles",
147
+ inputSchema: Type.Object({
148
+ id: Type.String(),
149
+ }),
150
+ outputSchema: Type.Object({
151
+ id: Type.String(),
152
+ name: Type.String(),
153
+ }),
154
+ execute: async (input, context) => {
155
+ const profile = context.sprinkle.getProfileById(input.id);
156
+ if (!profile) {
157
+ throw new ActionError(
158
+ `Profile "${input.id}" not found.`,
159
+ "PROFILE_NOT_FOUND",
160
+ { id: input.id },
161
+ );
162
+ }
163
+
164
+ await context.sprinkle.loadProfile(input.id);
165
+ return {
166
+ id: input.id,
167
+ name: profile.meta.name,
168
+ };
169
+ },
170
+ };
171
+
172
+ /**
173
+ * `create-profile` -- Create a new profile without prompts.
174
+ */
175
+ export const createProfile: IAction<
176
+ { name: string; description?: string; settings?: unknown },
177
+ { id: string; name: string },
178
+ TSchema
179
+ > = {
180
+ name: "create-profile",
181
+ description: "Create a new profile.",
182
+ category: "sprinkles",
183
+ inputSchema: Type.Object({
184
+ name: Type.String(),
185
+ description: Type.Optional(Type.String()),
186
+ settings: Type.Optional(Type.Any()),
187
+ }),
188
+ outputSchema: Type.Object({
189
+ id: Type.String(),
190
+ name: Type.String(),
191
+ }),
192
+ execute: async (input, context) => {
193
+ const entry = await context.sprinkle.createProfileNonInteractive(
194
+ input.name,
195
+ input.description,
196
+ input.settings as never,
197
+ );
198
+ return {
199
+ id: entry.id,
200
+ name: entry.meta.name,
201
+ };
202
+ },
203
+ };
204
+
205
+ /**
206
+ * `delete-profile` -- Delete a profile by ID.
207
+ * Cannot delete the only profile or the currently active profile.
208
+ */
209
+ export const deleteProfile: IAction<
210
+ { id: string },
211
+ { deleted: boolean; id: string },
212
+ TSchema
213
+ > = {
214
+ name: "delete-profile",
215
+ description:
216
+ "Delete a profile. Cannot delete the only profile or the active profile.",
217
+ category: "sprinkles",
218
+ inputSchema: Type.Object({
219
+ id: Type.String(),
220
+ }),
221
+ outputSchema: Type.Object({
222
+ deleted: Type.Boolean(),
223
+ id: Type.String(),
224
+ }),
225
+ execute: async (input, context) => {
226
+ context.sprinkle.deleteProfileById(input.id);
227
+ return { deleted: true, id: input.id };
228
+ },
229
+ };
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Built-in settings actions for the Sprinkle action system.
3
+ * These actions expose settings read and update operations as non-interactive
4
+ * actions available in CLI and MCP modes.
5
+ *
6
+ * All actions use category "sprinkles".
7
+ */
8
+
9
+ import { Type } from "@sinclair/typebox";
10
+ import { Value } from "@sinclair/typebox/value";
11
+ import type { TSchema } from "@sinclair/typebox";
12
+ import { ActionError } from "../types.js";
13
+ import type { IAction } from "../types.js";
14
+
15
+ /**
16
+ * `get-settings` -- Returns the current profile settings.
17
+ * Sensitive fields are masked by default; pass `includeSensitive: true` for raw values.
18
+ */
19
+ export const getSettings: IAction<
20
+ { includeSensitive?: boolean },
21
+ { settings: unknown; profileId: string; profileName: string },
22
+ TSchema
23
+ > = {
24
+ name: "get-settings",
25
+ description:
26
+ "Get the current profile settings. Sensitive fields are masked by default.",
27
+ category: "sprinkles",
28
+ inputSchema: Type.Object({
29
+ includeSensitive: Type.Optional(Type.Boolean({ default: false })),
30
+ }),
31
+ outputSchema: Type.Object({
32
+ settings: Type.Any(),
33
+ profileId: Type.String(),
34
+ profileName: Type.String(),
35
+ }),
36
+ execute: async (input, context) => {
37
+ const settings = input.includeSensitive
38
+ ? context.sprinkle.settings
39
+ : context.sprinkle.getDisplaySettings();
40
+
41
+ return {
42
+ settings,
43
+ profileId: context.sprinkle.profileId,
44
+ profileName: context.sprinkle.profileMeta.name,
45
+ };
46
+ },
47
+ };
48
+
49
+ /**
50
+ * `update-settings` -- Shallow-merges settings onto the current profile and persists.
51
+ * Validates the merged result against the Sprinkle schema before saving.
52
+ * Returns masked settings.
53
+ */
54
+ export const updateSettings: IAction<
55
+ { settings: Record<string, unknown> },
56
+ { settings: unknown; profileId: string },
57
+ TSchema
58
+ > = {
59
+ name: "update-settings",
60
+ description:
61
+ "Merge partial settings onto the current profile and save. Returns masked settings.",
62
+ category: "sprinkles",
63
+ inputSchema: Type.Object({
64
+ settings: Type.Record(Type.String(), Type.Any()),
65
+ }),
66
+ outputSchema: Type.Object({
67
+ settings: Type.Any(),
68
+ profileId: Type.String(),
69
+ }),
70
+ execute: async (input, context) => {
71
+ // Shallow merge the incoming settings onto the current settings
72
+ const merged = {
73
+ ...(context.sprinkle.settings as Record<string, unknown>),
74
+ ...input.settings,
75
+ };
76
+
77
+ // Validate the merged result against the Sprinkle schema
78
+ if (!Value.Check(context.sprinkle.type, merged)) {
79
+ const errors = [...Value.Errors(context.sprinkle.type, merged)];
80
+ const message = errors
81
+ .map((e) => `${e.path}: ${e.message}`)
82
+ .join("; ");
83
+ throw new ActionError(
84
+ `Settings validation failed: ${message}`,
85
+ "VALIDATION_ERROR",
86
+ { errors },
87
+ );
88
+ }
89
+
90
+ // Apply and persist
91
+ context.sprinkle.settings = merged as typeof context.sprinkle.settings;
92
+ context.sprinkle.saveSettings();
93
+
94
+ return {
95
+ settings: context.sprinkle.getDisplaySettings(),
96
+ profileId: context.sprinkle.profileId,
97
+ };
98
+ },
99
+ };
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Built-in transaction actions for the Sprinkle action system.
3
+ * These actions expose transaction signing, submission, and decoding
4
+ * as non-interactive actions available in CLI and MCP modes.
5
+ *
6
+ * Sign/submit actions use category "wallet".
7
+ * The decode action uses category "transaction" (no wallet required).
8
+ */
9
+
10
+ import { Type } from "@sinclair/typebox";
11
+ import type { TSchema } from "@sinclair/typebox";
12
+ import { Core } from "@blaze-cardano/sdk";
13
+ import { ActionError } from "../types.js";
14
+ import type { IAction } from "../types.js";
15
+ import { getBlazeFromContext, isHotWallet } from "./blaze-helper.js";
16
+ import { countSignatures, getRequiredSigners } from "../../tx-dialog.js";
17
+
18
+ /** Shared token entry schema (also used in wallet-actions) */
19
+ const TokenEntrySchema = Type.Object({
20
+ policyId: Type.String({ description: "Policy ID of the token" }),
21
+ assetName: Type.String({ description: "Asset name of the token (hex)" }),
22
+ quantity: Type.String({ description: "Token quantity as string (BigInt-safe)" }),
23
+ });
24
+
25
+ /**
26
+ * Parses a hex CBOR string into a `Core.Transaction`.
27
+ * Throws `ActionError("INVALID_CBOR")` if the string is not valid transaction CBOR.
28
+ */
29
+ function parseTxCbor(txCbor: string): Core.Transaction {
30
+ try {
31
+ return Core.Transaction.fromCbor(Core.TxCBOR(txCbor));
32
+ } catch (err) {
33
+ throw new ActionError(
34
+ `Invalid transaction CBOR: ${err instanceof Error ? err.message : String(err)}`,
35
+ "INVALID_CBOR",
36
+ { error: err instanceof Error ? err.message : String(err) },
37
+ );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * `sign-transaction` -- Signs a transaction with the configured hot wallet.
43
+ * Cold wallets cannot sign; use an external signing tool and submit the result.
44
+ */
45
+ export const signTransaction: IAction<
46
+ { txCbor: string },
47
+ { signedTxCbor: string; txHash: string; signatureCount: number },
48
+ TSchema
49
+ > = {
50
+ name: "sign-transaction",
51
+ description:
52
+ "Sign a transaction with the configured hot wallet. Requires a hot wallet; cold wallets cannot sign.",
53
+ category: "wallet",
54
+ inputSchema: Type.Object({
55
+ txCbor: Type.String({ description: "Transaction CBOR hex string to sign" }),
56
+ }),
57
+ outputSchema: Type.Object({
58
+ signedTxCbor: Type.String({ description: "Signed transaction CBOR hex" }),
59
+ txHash: Type.String({ description: "Transaction hash" }),
60
+ signatureCount: Type.Number({ description: "Number of VKey witnesses after signing" }),
61
+ }),
62
+ execute: async (input, context) => {
63
+ const blaze = await getBlazeFromContext(context);
64
+
65
+ if (!isHotWallet(blaze)) {
66
+ throw new ActionError(
67
+ "Cold wallets cannot sign transactions. Export the CBOR and sign externally, then use submit-transaction.",
68
+ "COLD_WALLET",
69
+ );
70
+ }
71
+
72
+ const tx = parseTxCbor(input.txCbor);
73
+
74
+ let signedTx: Core.Transaction;
75
+ try {
76
+ signedTx = await blaze.signTransaction(tx);
77
+ } catch (err) {
78
+ throw new ActionError(
79
+ `Failed to sign transaction: ${err instanceof Error ? err.message : String(err)}`,
80
+ "SIGN_ERROR",
81
+ { error: err instanceof Error ? err.message : String(err) },
82
+ );
83
+ }
84
+
85
+ return {
86
+ signedTxCbor: signedTx.toCbor(),
87
+ txHash: signedTx.body().hash().toString(),
88
+ signatureCount: countSignatures(signedTx),
89
+ };
90
+ },
91
+ };
92
+
93
+ /**
94
+ * `submit-transaction` -- Submits a signed transaction to the blockchain.
95
+ */
96
+ export const submitTransaction: IAction<
97
+ { txCbor: string },
98
+ { txHash: string; submitted: boolean },
99
+ TSchema
100
+ > = {
101
+ name: "submit-transaction",
102
+ description: "Submit a signed transaction to the blockchain.",
103
+ category: "wallet",
104
+ inputSchema: Type.Object({
105
+ txCbor: Type.String({ description: "Signed transaction CBOR hex string to submit" }),
106
+ }),
107
+ outputSchema: Type.Object({
108
+ txHash: Type.String({ description: "Submitted transaction hash" }),
109
+ submitted: Type.Boolean(),
110
+ }),
111
+ execute: async (input, context) => {
112
+ const blaze = await getBlazeFromContext(context);
113
+ const tx = parseTxCbor(input.txCbor);
114
+
115
+ let txHash: Core.TransactionId;
116
+ try {
117
+ txHash = await blaze.submitTransaction(tx);
118
+ } catch (err) {
119
+ throw new ActionError(
120
+ `Transaction submission failed: ${err instanceof Error ? err.message : String(err)}`,
121
+ "SUBMISSION_ERROR",
122
+ { error: err instanceof Error ? err.message : String(err) },
123
+ );
124
+ }
125
+
126
+ return {
127
+ txHash: txHash.toString(),
128
+ submitted: true,
129
+ };
130
+ },
131
+ };
132
+
133
+ /**
134
+ * `sign-and-submit` -- Signs a transaction and immediately submits it.
135
+ * Optionally waits for on-chain confirmation with a configurable timeout.
136
+ */
137
+ export const signAndSubmit: IAction<
138
+ {
139
+ txCbor: string;
140
+ waitForConfirmation?: boolean;
141
+ confirmationTimeout?: number;
142
+ },
143
+ {
144
+ txHash: string;
145
+ submitted: boolean;
146
+ confirmed?: boolean;
147
+ signedTxCbor: string;
148
+ },
149
+ TSchema
150
+ > = {
151
+ name: "sign-and-submit",
152
+ description:
153
+ "Sign and submit a transaction. Optionally wait for on-chain confirmation.",
154
+ category: "wallet",
155
+ inputSchema: Type.Object({
156
+ txCbor: Type.String({ description: "Transaction CBOR hex string to sign and submit" }),
157
+ waitForConfirmation: Type.Optional(
158
+ Type.Boolean({
159
+ default: false,
160
+ description: "Whether to wait for on-chain confirmation before returning",
161
+ }),
162
+ ),
163
+ confirmationTimeout: Type.Optional(
164
+ Type.Number({
165
+ default: 60,
166
+ description: "Timeout in seconds to wait for confirmation",
167
+ }),
168
+ ),
169
+ }),
170
+ outputSchema: Type.Object({
171
+ txHash: Type.String({ description: "Transaction hash" }),
172
+ submitted: Type.Boolean(),
173
+ confirmed: Type.Optional(Type.Boolean({ description: "Whether tx was confirmed on-chain" })),
174
+ signedTxCbor: Type.String({ description: "Signed transaction CBOR hex" }),
175
+ }),
176
+ execute: async (input, context) => {
177
+ const blaze = await getBlazeFromContext(context);
178
+
179
+ if (!isHotWallet(blaze)) {
180
+ throw new ActionError(
181
+ "Cold wallets cannot sign transactions. Export the CBOR and sign externally, then use submit-transaction.",
182
+ "COLD_WALLET",
183
+ );
184
+ }
185
+
186
+ const tx = parseTxCbor(input.txCbor);
187
+
188
+ // Sign
189
+ let signedTx: Core.Transaction;
190
+ try {
191
+ signedTx = await blaze.signTransaction(tx);
192
+ } catch (err) {
193
+ throw new ActionError(
194
+ `Failed to sign transaction: ${err instanceof Error ? err.message : String(err)}`,
195
+ "SIGN_ERROR",
196
+ { error: err instanceof Error ? err.message : String(err) },
197
+ );
198
+ }
199
+
200
+ const signedTxCbor = signedTx.toCbor();
201
+
202
+ // Submit
203
+ let txHash: Core.TransactionId;
204
+ try {
205
+ txHash = await blaze.submitTransaction(signedTx);
206
+ } catch (err) {
207
+ throw new ActionError(
208
+ `Transaction submission failed: ${err instanceof Error ? err.message : String(err)}`,
209
+ "SUBMISSION_ERROR",
210
+ { error: err instanceof Error ? err.message : String(err), signedTxCbor },
211
+ );
212
+ }
213
+
214
+ const txHashStr = txHash.toString();
215
+
216
+ // If confirmation not requested, return immediately
217
+ if (!input.waitForConfirmation) {
218
+ return {
219
+ txHash: txHashStr,
220
+ submitted: true,
221
+ signedTxCbor,
222
+ };
223
+ }
224
+
225
+ // Poll for confirmation
226
+ const timeoutSeconds = input.confirmationTimeout ?? 60;
227
+ const deadline = Date.now() + timeoutSeconds * 1000;
228
+ const pollIntervalMs = 5000; // 5 seconds between polls
229
+
230
+ let confirmed = false;
231
+ while (Date.now() < deadline) {
232
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
233
+ try {
234
+ // Query UTxOs and check if any reference this tx hash
235
+ // This is a lightweight confirmation check using the provider
236
+ const utxos = await blaze.provider.getUnspentOutputs(
237
+ await blaze.wallet.getChangeAddress(),
238
+ );
239
+ // If provider returns without error and tx hash appears in a UTxO input or
240
+ // the query succeeds after submission, assume confirmed.
241
+ // A more precise check would be to look up the tx directly.
242
+ // Use resolveUnspentOutputs if available, otherwise accept the provider response.
243
+ const anyMatch = utxos.some(
244
+ (u) => u.input().transactionId().toString() === txHashStr,
245
+ );
246
+ // If we get a fresh UTxO referencing our tx, confirmed
247
+ if (anyMatch) {
248
+ confirmed = true;
249
+ break;
250
+ }
251
+ // Check if we got back any UTxOs at all - for a send transaction the
252
+ // change output should be visible once confirmed
253
+ // Fall through and keep polling
254
+ } catch {
255
+ // Provider error during poll -- keep trying until timeout
256
+ }
257
+ }
258
+
259
+ if (!confirmed && input.waitForConfirmation) {
260
+ // Return partial success rather than throwing -- tx was submitted successfully
261
+ // but we couldn't confirm within the timeout
262
+ return {
263
+ txHash: txHashStr,
264
+ submitted: true,
265
+ confirmed: false,
266
+ signedTxCbor,
267
+ };
268
+ }
269
+
270
+ return {
271
+ txHash: txHashStr,
272
+ submitted: true,
273
+ confirmed,
274
+ signedTxCbor,
275
+ };
276
+ },
277
+ };
278
+
279
+ /**
280
+ * `decode-transaction` -- Decodes a transaction CBOR hex without requiring a wallet.
281
+ * Extracts inputs, outputs, fee, witness count, and required signers from the tx body.
282
+ */
283
+ export const decodeTransaction: IAction<
284
+ { txCbor: string },
285
+ {
286
+ txHash: string;
287
+ inputs: Array<{ txHash: string; outputIndex: number }>;
288
+ outputs: Array<{
289
+ address: string;
290
+ lovelace: string;
291
+ tokens: Array<{ policyId: string; assetName: string; quantity: string }>;
292
+ }>;
293
+ fee: string;
294
+ signatureCount: number;
295
+ requiredSigners: string[];
296
+ },
297
+ TSchema
298
+ > = {
299
+ name: "decode-transaction",
300
+ description:
301
+ "Decode a transaction CBOR hex and return its inputs, outputs, fee, and signers. Does not require a wallet.",
302
+ category: "transaction",
303
+ inputSchema: Type.Object({
304
+ txCbor: Type.String({ description: "Transaction CBOR hex string to decode" }),
305
+ }),
306
+ outputSchema: Type.Object({
307
+ txHash: Type.String({ description: "Transaction body hash" }),
308
+ inputs: Type.Array(
309
+ Type.Object({
310
+ txHash: Type.String({ description: "Input transaction hash" }),
311
+ outputIndex: Type.Number({ description: "Input output index" }),
312
+ }),
313
+ ),
314
+ outputs: Type.Array(
315
+ Type.Object({
316
+ address: Type.String({ description: "Output address (bech32 or hex)" }),
317
+ lovelace: Type.String({ description: "Output lovelace amount as string" }),
318
+ tokens: Type.Array(TokenEntrySchema),
319
+ }),
320
+ ),
321
+ fee: Type.String({ description: "Transaction fee in lovelace as string" }),
322
+ signatureCount: Type.Number({ description: "Number of VKey witnesses" }),
323
+ requiredSigners: Type.Array(
324
+ Type.String({ description: "Required signer key hashes" }),
325
+ ),
326
+ }),
327
+ execute: async (input, _context) => {
328
+ // No Blaze instance needed -- pure CBOR parsing
329
+ const tx = parseTxCbor(input.txCbor);
330
+
331
+ const body = tx.body();
332
+ const txHash = body.hash().toString();
333
+
334
+ // Extract inputs
335
+ const inputSet = body.inputs();
336
+ const inputs = Array.from(inputSet.values()).map((txInput) => ({
337
+ txHash: txInput.transactionId().toString(),
338
+ outputIndex: Number(txInput.index()),
339
+ }));
340
+
341
+ // Extract outputs
342
+ const outputs = body.outputs().map((txOutput) => {
343
+ const value = txOutput.amount();
344
+ const tokens: Array<{ policyId: string; assetName: string; quantity: string }> = [];
345
+
346
+ const multiasset = value.multiasset();
347
+ if (multiasset) {
348
+ for (const [assetId, quantity] of multiasset.entries()) {
349
+ tokens.push({
350
+ policyId: Core.AssetId.getPolicyId(assetId),
351
+ assetName: Core.AssetId.getAssetName(assetId),
352
+ quantity: quantity.toString(),
353
+ });
354
+ }
355
+ }
356
+
357
+ // Attempt bech32 address, fall back to hex if conversion fails
358
+ let address: string;
359
+ try {
360
+ address = txOutput.address().toBech32();
361
+ } catch {
362
+ address = txOutput.address().toBytes();
363
+ }
364
+
365
+ return {
366
+ address,
367
+ lovelace: value.coin().toString(),
368
+ tokens,
369
+ };
370
+ });
371
+
372
+ return {
373
+ txHash,
374
+ inputs,
375
+ outputs,
376
+ fee: body.fee().toString(),
377
+ signatureCount: countSignatures(tx),
378
+ requiredSigners: getRequiredSigners(tx),
379
+ };
380
+ },
381
+ };