@kbve/droid 0.0.6 → 0.1.2

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 (190) hide show
  1. package/droid.mjs +2312 -74
  2. package/index.d.ts +32 -0
  3. package/lib/agents/api-types.d.ts +121 -0
  4. package/lib/agents/api-types.d.ts.map +1 -0
  5. package/lib/agents/auth/init.d.ts +8 -0
  6. package/lib/agents/auth/init.d.ts.map +1 -0
  7. package/lib/agents/cache.d.ts +9 -0
  8. package/lib/agents/cache.d.ts.map +1 -0
  9. package/lib/agents/client/callGuildVault.d.ts +3 -0
  10. package/lib/agents/client/callGuildVault.d.ts.map +1 -0
  11. package/lib/agents/client/callJson.d.ts +3 -0
  12. package/lib/agents/client/callJson.d.ts.map +1 -0
  13. package/lib/agents/config.d.ts +36 -0
  14. package/lib/agents/config.d.ts.map +1 -0
  15. package/lib/agents/constants.d.ts +11 -0
  16. package/lib/agents/constants.d.ts.map +1 -0
  17. package/lib/agents/createAgents.d.ts +4 -0
  18. package/lib/agents/createAgents.d.ts.map +1 -0
  19. package/lib/agents/ctx.d.ts +46 -0
  20. package/lib/agents/ctx.d.ts.map +1 -0
  21. package/lib/agents/discord/bot.d.ts +21 -0
  22. package/lib/agents/discord/bot.d.ts.map +1 -0
  23. package/lib/agents/discord/guilds.d.ts +8 -0
  24. package/lib/agents/discord/guilds.d.ts.map +1 -0
  25. package/lib/agents/formDrafts.d.ts +5 -0
  26. package/lib/agents/formDrafts.d.ts.map +1 -0
  27. package/lib/agents/generated/agents-schema.d.ts +73 -0
  28. package/lib/agents/generated/agents-schema.d.ts.map +1 -0
  29. package/lib/agents/generated/discordsh-agents-schema.d.ts +71 -0
  30. package/lib/agents/generated/discordsh-agents-schema.d.ts.map +1 -0
  31. package/lib/agents/github/backfill.d.ts +23 -0
  32. package/lib/agents/github/backfill.d.ts.map +1 -0
  33. package/lib/agents/github/events.d.ts +10 -0
  34. package/lib/agents/github/events.d.ts.map +1 -0
  35. package/lib/agents/github/pat.d.ts +13 -0
  36. package/lib/agents/github/pat.d.ts.map +1 -0
  37. package/lib/agents/github/repoConfig.d.ts +25 -0
  38. package/lib/agents/github/repoConfig.d.ts.map +1 -0
  39. package/lib/agents/github/tokens.d.ts +22 -0
  40. package/lib/agents/github/tokens.d.ts.map +1 -0
  41. package/lib/agents/github/webhook.d.ts +37 -0
  42. package/lib/agents/github/webhook.d.ts.map +1 -0
  43. package/lib/agents/index.d.ts +8 -0
  44. package/lib/agents/index.d.ts.map +1 -0
  45. package/lib/agents/state/atoms.d.ts +122 -0
  46. package/lib/agents/state/atoms.d.ts.map +1 -0
  47. package/lib/agents/types.d.ts +65 -0
  48. package/lib/agents/types.d.ts.map +1 -0
  49. package/lib/gateway/SupabaseGateway.d.ts +38 -0
  50. package/lib/gateway/SupabaseGateway.d.ts.map +1 -0
  51. package/lib/gateway/WorkerCommunication.d.ts +39 -0
  52. package/lib/gateway/WorkerCommunication.d.ts.map +1 -0
  53. package/lib/gateway/WorkerPool.d.ts +55 -0
  54. package/lib/gateway/WorkerPool.d.ts.map +1 -0
  55. package/lib/gateway/capabilities.d.ts +23 -0
  56. package/lib/gateway/capabilities.d.ts.map +1 -0
  57. package/lib/gateway/index.d.ts +9 -0
  58. package/lib/gateway/index.d.ts.map +1 -0
  59. package/lib/gateway/strategies/DirectStrategy.d.ts +52 -0
  60. package/lib/gateway/strategies/DirectStrategy.d.ts.map +1 -0
  61. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts +46 -0
  62. package/lib/gateway/strategies/SharedWorkerStrategy.d.ts.map +1 -0
  63. package/lib/gateway/strategies/WebWorkerStrategy.d.ts +45 -0
  64. package/lib/gateway/strategies/WebWorkerStrategy.d.ts.map +1 -0
  65. package/lib/gateway/types.d.ts +81 -0
  66. package/lib/gateway/types.d.ts.map +1 -0
  67. package/lib/workers/canvas-ui-renderer.d.ts +25 -0
  68. package/lib/workers/canvas-ui-renderer.d.ts.map +1 -0
  69. package/lib/workers/canvas-worker.d.ts +14 -0
  70. package/lib/workers/canvas-worker.d.ts.map +1 -0
  71. package/lib/workers/canvas-worker.js +5 -302
  72. package/lib/workers/data.d.ts +40 -0
  73. package/lib/workers/data.d.ts.map +1 -0
  74. package/lib/workers/db-worker.d.ts +69 -0
  75. package/lib/workers/db-worker.d.ts.map +1 -0
  76. package/lib/workers/db-worker.js +13 -3636
  77. package/lib/workers/events.d.ts +11 -0
  78. package/lib/workers/events.d.ts.map +1 -0
  79. package/lib/workers/flexbuilder.d.ts +4 -0
  80. package/lib/workers/flexbuilder.d.ts.map +1 -0
  81. package/lib/workers/init.d.ts +11 -0
  82. package/lib/workers/init.d.ts.map +1 -0
  83. package/lib/workers/main.d.ts +105 -0
  84. package/lib/workers/main.d.ts.map +1 -0
  85. package/lib/workers/supabase-db-worker.d.ts +2 -0
  86. package/lib/workers/supabase-db-worker.d.ts.map +1 -0
  87. package/lib/workers/supabase-db-worker.js +23 -0
  88. package/lib/workers/supabase-shared-worker.d.ts +2 -0
  89. package/lib/workers/supabase-shared-worker.d.ts.map +1 -0
  90. package/lib/workers/supabase-shared-worker.js +25 -0
  91. package/lib/workers/tools.d.ts +4 -0
  92. package/lib/workers/tools.d.ts.map +1 -0
  93. package/lib/workers/validate.d.ts +15 -0
  94. package/lib/workers/validate.d.ts.map +1 -0
  95. package/lib/workers/ws-worker.d.ts +10 -0
  96. package/lib/workers/ws-worker.d.ts.map +1 -0
  97. package/lib/workers/ws-worker.js +5 -273
  98. package/main.js +5711 -0
  99. package/package.json +18 -6
  100. package/src/index.ts +41 -13
  101. package/src/lib/agents/api-types.ts +170 -0
  102. package/src/lib/agents/auth/init.ts +200 -0
  103. package/src/lib/agents/cache.ts +127 -0
  104. package/src/lib/agents/client/callGuildVault.ts +71 -0
  105. package/src/lib/agents/client/callJson.ts +64 -0
  106. package/src/lib/agents/config.ts +83 -0
  107. package/src/lib/agents/constants.ts +11 -0
  108. package/src/lib/agents/createAgents.ts +62 -0
  109. package/src/lib/agents/ctx.ts +63 -0
  110. package/src/lib/agents/discord/bot.ts +169 -0
  111. package/src/lib/agents/discord/guilds.ts +106 -0
  112. package/src/lib/agents/formDrafts.ts +55 -0
  113. package/src/lib/agents/generated/agents-schema.ts +155 -0
  114. package/src/lib/agents/generated/discordsh-agents-schema.ts +96 -0
  115. package/src/lib/agents/github/backfill.ts +126 -0
  116. package/src/lib/agents/github/events.ts +131 -0
  117. package/src/lib/agents/github/pat.ts +150 -0
  118. package/src/lib/agents/github/repoConfig.ts +240 -0
  119. package/src/lib/agents/github/tokens.ts +222 -0
  120. package/src/lib/agents/github/webhook.ts +349 -0
  121. package/src/lib/agents/index.ts +35 -0
  122. package/src/lib/agents/state/atoms.ts +122 -0
  123. package/src/lib/agents/types.ts +83 -0
  124. package/src/lib/api.ts +71 -0
  125. package/src/lib/droid.spec.ts +14 -19
  126. package/src/lib/droid.ts +48 -4
  127. package/src/lib/gateway/SupabaseGateway.ts +236 -0
  128. package/src/lib/gateway/WorkerCommunication.ts +132 -0
  129. package/src/lib/gateway/WorkerPool.ts +304 -0
  130. package/src/lib/gateway/capabilities.spec.ts +144 -0
  131. package/src/lib/gateway/capabilities.ts +80 -0
  132. package/src/lib/gateway/index.ts +15 -0
  133. package/src/lib/gateway/strategies/DirectStrategy.ts +443 -0
  134. package/src/lib/gateway/strategies/SharedWorkerStrategy.ts +278 -0
  135. package/src/lib/gateway/strategies/WebWorkerStrategy.ts +278 -0
  136. package/src/lib/gateway/types.ts +139 -0
  137. package/src/lib/mod/mod-manager.ts +13 -8
  138. package/src/lib/mod/module/bento/mod-bento.worker.ts +1 -1
  139. package/src/lib/mod/module/supabase/mod-supabase.spec.ts +21 -25
  140. package/src/lib/mod/module/supabase/mod-supabase.ts +73 -0
  141. package/src/lib/mod/module/supabase/mod-supabase.worker.ts +1 -56
  142. package/src/lib/state/auth.spec.ts +58 -0
  143. package/src/lib/state/auth.ts +148 -0
  144. package/src/lib/state/bento.spec.ts +76 -0
  145. package/src/lib/state/bento.ts +51 -0
  146. package/src/lib/state/index.ts +98 -0
  147. package/src/lib/state/overlay-manager.ts +125 -0
  148. package/src/lib/state/profile-sync.ts +214 -0
  149. package/src/lib/state/profile.ts +155 -0
  150. package/src/lib/state/router.ts +24 -0
  151. package/src/lib/state/staff.ts +128 -0
  152. package/src/lib/state/sync-bus.ts +109 -0
  153. package/src/lib/state/theme-sync.ts +75 -0
  154. package/src/lib/state/toasts.spec.ts +106 -0
  155. package/src/lib/state/toasts.ts +34 -0
  156. package/src/lib/state/ui.spec.ts +148 -0
  157. package/src/lib/state/ui.ts +45 -0
  158. package/src/lib/state/welcome-toast.spec.ts +101 -0
  159. package/src/lib/state/welcome-toast.ts +76 -0
  160. package/src/lib/sw-recovery.spec.ts +165 -0
  161. package/src/lib/sw-recovery.ts +141 -0
  162. package/src/lib/types/bento.spec.ts +116 -0
  163. package/src/lib/types/bento.ts +94 -55
  164. package/src/lib/types/event-schemas.spec.ts +120 -0
  165. package/src/lib/types/event-types.spec.ts +96 -0
  166. package/src/lib/types/event-types.ts +113 -3
  167. package/src/lib/types/modules.ts +12 -5
  168. package/src/lib/types/ui-event-types.ts +66 -0
  169. package/src/lib/workers/canvas-ui-renderer.ts +266 -0
  170. package/src/lib/workers/canvas-worker.ts +94 -9
  171. package/src/lib/workers/data.ts +64 -37
  172. package/src/lib/workers/db-worker.ts +105 -32
  173. package/src/lib/workers/events.spec.ts +208 -0
  174. package/src/lib/workers/events.ts +27 -14
  175. package/src/lib/workers/flexbuilder.ts +2 -2
  176. package/src/lib/workers/init.ts +25 -17
  177. package/src/lib/workers/main.ts +506 -327
  178. package/src/lib/workers/supabase-db-worker.ts +243 -0
  179. package/src/lib/workers/supabase-shared-worker.ts +607 -0
  180. package/src/lib/workers/validate.ts +64 -0
  181. package/src/lib/workers/ws-worker.spec.ts +41 -0
  182. package/src/lib/workers/ws-worker.ts +255 -31
  183. package/src/setup-vitest.ts +4 -2
  184. package/src/types.ts +30 -0
  185. package/src/vite-env.d.ts +1 -0
  186. package/workers/main.js +2 -1125
  187. package/comlink.js +0 -253
  188. package/index.js +0 -2972
  189. package/reference.js +0 -259
  190. package/src/types.d.ts +0 -31
@@ -0,0 +1,120 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ DroidEventSchemas,
4
+ DroidFirstConnectSchema,
5
+ DroidReadySchema,
6
+ AuthReadySchema,
7
+ AuthErrorSchema,
8
+ WorkerErrorSchema,
9
+ PageLifecycleSchema,
10
+ PanelEventSchema,
11
+ DroidDownscaleSchema,
12
+ DroidUpscaleSchema,
13
+ DroidModReadySchema,
14
+ } from './event-types';
15
+
16
+ describe('DroidEventSchemas — happy path round-trips', () => {
17
+ it.each([
18
+ ['droid-ready', DroidReadySchema, { timestamp: 1 }],
19
+ [
20
+ 'droid-first-connect',
21
+ DroidFirstConnectSchema,
22
+ { timestamp: 1, workersFirst: { db: true, ws: false } },
23
+ ],
24
+ [
25
+ 'droid-mod-ready',
26
+ DroidModReadySchema,
27
+ { meta: { id: 'x', name: 'X', version: '1.0.0' }, timestamp: 1 },
28
+ ],
29
+ [
30
+ 'droid-downscale',
31
+ DroidDownscaleSchema,
32
+ { timestamp: 1, level: 'minimal' },
33
+ ],
34
+ ['droid-upscale', DroidUpscaleSchema, { timestamp: 1, level: 'full' }],
35
+ [
36
+ 'panel-open',
37
+ PanelEventSchema,
38
+ { id: 'right', payload: { foo: 'bar' } },
39
+ ],
40
+ ['panel-close', PanelEventSchema, { id: 'top' }],
41
+ [
42
+ 'auth-ready',
43
+ AuthReadySchema,
44
+ { timestamp: 1, tone: 'auth' as const, name: 'Alice' },
45
+ ],
46
+ [
47
+ 'auth-error',
48
+ AuthErrorSchema,
49
+ { timestamp: 1, message: 'invalid grant' },
50
+ ],
51
+ [
52
+ 'worker-error',
53
+ WorkerErrorSchema,
54
+ {
55
+ timestamp: 1,
56
+ worker: 'ws' as const,
57
+ operation: 'connect',
58
+ message: 'closed',
59
+ },
60
+ ],
61
+ [
62
+ 'page-mount',
63
+ PageLifecycleSchema,
64
+ { timestamp: 1, url: '/foo', source: 'initial' as const },
65
+ ],
66
+ ])('%s accepts a valid payload', (_name, schema, payload) => {
67
+ expect(schema.safeParse(payload).success).toBe(true);
68
+ });
69
+ });
70
+
71
+ describe('DroidEventSchemas — rejection cases', () => {
72
+ it('rejects droid-first-connect without workersFirst', () => {
73
+ expect(
74
+ DroidFirstConnectSchema.safeParse({ timestamp: 1 }).success,
75
+ ).toBe(false);
76
+ });
77
+
78
+ it('rejects auth-ready with an unknown tone', () => {
79
+ expect(
80
+ AuthReadySchema.safeParse({ timestamp: 1, tone: 'staff' }).success,
81
+ ).toBe(false);
82
+ });
83
+
84
+ it('rejects worker-error with an unknown worker name', () => {
85
+ expect(
86
+ WorkerErrorSchema.safeParse({
87
+ timestamp: 1,
88
+ worker: 'gateway',
89
+ operation: 'x',
90
+ message: 'y',
91
+ }).success,
92
+ ).toBe(false);
93
+ });
94
+
95
+ it('rejects page-lifecycle with an unknown source', () => {
96
+ expect(
97
+ PageLifecycleSchema.safeParse({
98
+ timestamp: 1,
99
+ url: '/x',
100
+ source: 'turbolinks',
101
+ }).success,
102
+ ).toBe(false);
103
+ });
104
+
105
+ it('rejects schemas missing the timestamp field', () => {
106
+ expect(DroidReadySchema.safeParse({}).success).toBe(false);
107
+ expect(AuthErrorSchema.safeParse({ message: 'x' }).success).toBe(false);
108
+ });
109
+ });
110
+
111
+ describe('DroidEventSchemas — registry contract', () => {
112
+ it('every key resolves to a schema with safeParse', () => {
113
+ for (const [key, schema] of Object.entries(DroidEventSchemas)) {
114
+ expect(typeof (schema as { safeParse?: unknown }).safeParse).toBe(
115
+ 'function',
116
+ );
117
+ expect(key).toMatch(/^[a-z]+(-[a-z]+)+$/);
118
+ }
119
+ });
120
+ });
@@ -0,0 +1,96 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ DroidEventSchemas,
4
+ DroidReadySchema,
5
+ DroidFirstConnectSchema,
6
+ DroidDownscaleSchema,
7
+ DroidUpscaleSchema,
8
+ } from './event-types';
9
+
10
+ describe('DroidEventSchemas', () => {
11
+ it('has all expected event keys', () => {
12
+ const keys = Object.keys(DroidEventSchemas);
13
+ expect(keys).toContain('droid-first-connect');
14
+ expect(keys).toContain('droid-ready');
15
+ expect(keys).toContain('droid-mod-ready');
16
+ expect(keys).toContain('droid-downscale');
17
+ expect(keys).toContain('droid-upscale');
18
+ expect(keys).toContain('panel-open');
19
+ expect(keys).toContain('panel-close');
20
+ expect(keys).toContain('toast-added');
21
+ expect(keys).toContain('toast-removed');
22
+ expect(keys).toContain('tooltip-opened');
23
+ expect(keys).toContain('tooltip-closed');
24
+ expect(keys).toContain('modal-opened');
25
+ expect(keys).toContain('modal-closed');
26
+ expect(keys).toContain('auth-ready');
27
+ expect(keys).toContain('auth-error');
28
+ expect(keys).toContain('palworld-live-snapshot');
29
+ });
30
+
31
+ it('has exactly 21 event types', () => {
32
+ expect(Object.keys(DroidEventSchemas)).toHaveLength(21);
33
+ });
34
+ });
35
+
36
+ describe('DroidReadySchema', () => {
37
+ it('accepts valid payload', () => {
38
+ const result = DroidReadySchema.safeParse({ timestamp: 123 });
39
+ expect(result.success).toBe(true);
40
+ });
41
+
42
+ it('rejects missing timestamp', () => {
43
+ const result = DroidReadySchema.safeParse({});
44
+ expect(result.success).toBe(false);
45
+ });
46
+
47
+ it('rejects non-number timestamp', () => {
48
+ const result = DroidReadySchema.safeParse({ timestamp: 'now' });
49
+ expect(result.success).toBe(false);
50
+ });
51
+ });
52
+
53
+ describe('DroidFirstConnectSchema', () => {
54
+ it('accepts valid payload', () => {
55
+ const result = DroidFirstConnectSchema.safeParse({
56
+ timestamp: 1,
57
+ workersFirst: { db: true, ws: false },
58
+ });
59
+ expect(result.success).toBe(true);
60
+ });
61
+
62
+ it('rejects missing workersFirst', () => {
63
+ const result = DroidFirstConnectSchema.safeParse({ timestamp: 1 });
64
+ expect(result.success).toBe(false);
65
+ });
66
+ });
67
+
68
+ describe('DroidDownscaleSchema', () => {
69
+ it('accepts valid payload', () => {
70
+ const result = DroidDownscaleSchema.safeParse({
71
+ timestamp: 1,
72
+ level: 'minimal',
73
+ });
74
+ expect(result.success).toBe(true);
75
+ });
76
+
77
+ it('rejects missing level', () => {
78
+ const result = DroidDownscaleSchema.safeParse({ timestamp: 1 });
79
+ expect(result.success).toBe(false);
80
+ });
81
+ });
82
+
83
+ describe('DroidUpscaleSchema', () => {
84
+ it('accepts valid payload', () => {
85
+ const result = DroidUpscaleSchema.safeParse({
86
+ timestamp: 1,
87
+ level: 'full',
88
+ });
89
+ expect(result.success).toBe(true);
90
+ });
91
+
92
+ it('rejects missing timestamp', () => {
93
+ const result = DroidUpscaleSchema.safeParse({ level: 'full' });
94
+ expect(result.success).toBe(false);
95
+ });
96
+ });
@@ -1,5 +1,10 @@
1
1
  import { z } from 'zod';
2
2
  import { PanelIdSchema } from './panel-types';
3
+ import {
4
+ ToastPayloadSchema,
5
+ TooltipPayloadSchema,
6
+ ModalPayloadSchema,
7
+ } from './ui-event-types';
3
8
 
4
9
  export const ModMetaSchema = z.object({
5
10
  name: z.string(),
@@ -20,16 +25,121 @@ export const DroidReadySchema = z.object({
20
25
  timestamp: z.number(),
21
26
  });
22
27
 
28
+ export const DroidFirstConnectSchema = z.object({
29
+ timestamp: z.number(),
30
+ workersFirst: z.object({
31
+ db: z.boolean(),
32
+ ws: z.boolean(),
33
+ }),
34
+ });
35
+
36
+ export const DroidDownscaleSchema = z.object({
37
+ timestamp: z.number(),
38
+ level: z.string(),
39
+ });
40
+
41
+ export const DroidUpscaleSchema = z.object({
42
+ timestamp: z.number(),
43
+ level: z.string(),
44
+ });
45
+
46
+ export const AuthReadySchema = z.object({
47
+ timestamp: z.number(),
48
+ tone: z.enum(['auth', 'anon']),
49
+ name: z.string().optional(),
50
+ });
51
+
52
+ export const AuthErrorSchema = z.object({
53
+ timestamp: z.number(),
54
+ message: z.string(),
55
+ });
56
+
57
+ export const WorkerErrorSchema = z.object({
58
+ timestamp: z.number(),
59
+ worker: z.enum(['shared', 'db', 'ws']),
60
+ operation: z.string(),
61
+ message: z.string(),
62
+ });
63
+
64
+ export const GatewayStrategyFallbackSchema = z.object({
65
+ timestamp: z.number(),
66
+ from: z.enum(['shared-worker', 'web-worker', 'direct']),
67
+ to: z.enum(['shared-worker', 'web-worker', 'direct']),
68
+ reason: z.string(),
69
+ });
70
+
71
+ // Page lifecycle — emitted by @kbve/astro's onMount/onSwap helpers so any
72
+ // module on the bus (mods, plugins, vanilla driver) can react to navigation
73
+ // without knowing whether the host is using ClientRouter, native cross-doc
74
+ // view transitions, full reloads, or bfcache restores.
75
+ export const PageLifecycleSchema = z.object({
76
+ timestamp: z.number(),
77
+ url: z.string(),
78
+ source: z.enum(['initial', 'astro-swap', 'page-reveal', 'bfcache']),
79
+ });
80
+
81
+ export const PalworldLiveSnapshotSchema = z.object({
82
+ ts: z.number(),
83
+ offline: z.boolean(),
84
+ players: z.array(
85
+ z.object({
86
+ name: z.string(),
87
+ level: z.number(),
88
+ x: z.number(),
89
+ y: z.number(),
90
+ }),
91
+ ),
92
+ bosses: z.array(
93
+ z.object({
94
+ id: z.string(),
95
+ x: z.number(),
96
+ y: z.number(),
97
+ defeated_at: z.number(),
98
+ respawn_at: z.number(),
99
+ }),
100
+ ),
101
+ events: z.array(
102
+ z.object({
103
+ kind: z.string(),
104
+ class: z.string(),
105
+ x: z.number(),
106
+ y: z.number(),
107
+ first_seen: z.number(),
108
+ }),
109
+ ),
110
+ });
111
+
23
112
  export const DroidEventSchemas = {
24
- 'droid-ready': DroidReadySchema,
113
+ 'droid-first-connect': DroidFirstConnectSchema,
114
+ 'droid-ready': DroidReadySchema,
25
115
  'droid-mod-ready': DroidModReadySchema,
116
+ 'droid-downscale': DroidDownscaleSchema,
117
+ 'droid-upscale': DroidUpscaleSchema,
26
118
  'panel-open': PanelEventSchema,
27
119
  'panel-close': PanelEventSchema,
120
+ 'toast-added': ToastPayloadSchema,
121
+ 'toast-removed': ToastPayloadSchema.pick({ id: true }),
122
+ 'tooltip-opened': TooltipPayloadSchema,
123
+ 'tooltip-closed': TooltipPayloadSchema.pick({ id: true }),
124
+ 'modal-opened': ModalPayloadSchema,
125
+ 'modal-closed': ModalPayloadSchema.pick({ id: true }),
126
+ 'auth-ready': AuthReadySchema,
127
+ 'auth-error': AuthErrorSchema,
128
+ 'worker-error': WorkerErrorSchema,
129
+ 'gateway-strategy-fallback': GatewayStrategyFallbackSchema,
130
+ 'page-mount': PageLifecycleSchema,
131
+ 'page-swap': PageLifecycleSchema,
132
+ 'page-hide': PageLifecycleSchema,
133
+ 'palworld-live-snapshot': PalworldLiveSnapshotSchema,
28
134
  };
29
135
 
30
136
  export type DroidEventMap = {
31
- [K in keyof typeof DroidEventSchemas]: z.infer<(typeof DroidEventSchemas)[K]>;
137
+ [K in keyof typeof DroidEventSchemas]: z.infer<
138
+ (typeof DroidEventSchemas)[K]
139
+ >;
32
140
  };
33
141
 
34
142
  export type EventKey = keyof DroidEventMap;
35
- export type EventHandler<K extends EventKey> = (payload: DroidEventMap[K]) => void;
143
+ export type EventHandler<K extends EventKey> = (
144
+ payload: DroidEventMap[K],
145
+ ) => void;
@@ -1,8 +1,13 @@
1
1
  import type { Remote } from 'comlink';
2
2
 
3
+ export interface ModInitContext {
4
+ emitFromWorker?: (msg: unknown) => void;
5
+ }
6
+
3
7
  export interface BaseModAPI {
4
8
  getMeta(): Promise<ModMeta>;
5
- init?(ctx: any): void | Promise<void>;
9
+ init?(ctx: ModInitContext): void | Promise<void>;
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
11
  [key: string]: any;
7
12
  }
8
13
 
@@ -31,8 +36,10 @@ export interface ModManager {
31
36
 
32
37
  export interface SupabaseModAPI extends BaseModAPI {
33
38
  configure(url: string, key: string): Promise<void>;
34
- queryTestTable(): Promise<{ data: any; error: any }>;
35
- insertTest(payload: Record<string, any>): Promise<{ data: any; error: any }>;
39
+ queryTestTable(): Promise<{ data: unknown; error: unknown }>;
40
+ insertTest(
41
+ payload: Record<string, unknown>,
42
+ ): Promise<{ data: unknown; error: unknown }>;
36
43
  }
37
44
 
38
45
  export type VirtualNode = {
@@ -40,7 +47,7 @@ export type VirtualNode = {
40
47
  id?: string;
41
48
  key?: string;
42
49
  class?: string;
43
- attrs?: Record<string, any>;
50
+ attrs?: Record<string, string | number | boolean>;
44
51
  style?: Partial<CSSStyleDeclaration>;
45
52
  children?: (string | VirtualNode)[];
46
- };
53
+ };
@@ -0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ import type { VirtualNode } from './modules';
3
+
4
+ // Recursive VirtualNode schema matching the type in modules.ts.
5
+ // Validates worker-produced descriptors at runtime.
6
+ const VirtualNodeSchema: z.ZodType<VirtualNode, VirtualNode> = z.lazy(() =>
7
+ z.object({
8
+ tag: z.string(),
9
+ id: z.string().optional(),
10
+ key: z.string().optional(),
11
+ class: z.string().optional(),
12
+ attrs: z.record(z.string(), z.any()).optional(),
13
+ style: z.record(z.string(), z.string()).optional(),
14
+ children: z.array(z.union([z.string(), VirtualNodeSchema])).optional(),
15
+ }),
16
+ );
17
+
18
+ // ── Toast ──
19
+
20
+ export const ToastSeveritySchema = z.enum([
21
+ 'success',
22
+ 'warning',
23
+ 'error',
24
+ 'info',
25
+ ]);
26
+ export type ToastSeverity = z.infer<typeof ToastSeveritySchema>;
27
+
28
+ export const ToastPayloadSchema = z.object({
29
+ id: z.string(),
30
+ message: z.string(),
31
+ severity: ToastSeveritySchema,
32
+ duration: z.number().positive().optional(),
33
+ vnode: VirtualNodeSchema.optional(),
34
+ });
35
+ export type ToastPayload = z.infer<typeof ToastPayloadSchema>;
36
+
37
+ // ── Tooltip ──
38
+
39
+ export const TooltipPositionSchema = z.enum([
40
+ 'top',
41
+ 'bottom',
42
+ 'left',
43
+ 'right',
44
+ 'auto',
45
+ ]);
46
+ export type TooltipPosition = z.infer<typeof TooltipPositionSchema>;
47
+
48
+ export const TooltipPayloadSchema = z.object({
49
+ id: z.string(),
50
+ content: z.union([z.string(), VirtualNodeSchema]).optional(),
51
+ position: TooltipPositionSchema.optional(),
52
+ anchor: z.string().optional(),
53
+ });
54
+ export type TooltipPayload = z.infer<typeof TooltipPayloadSchema>;
55
+
56
+ // ── Modal ──
57
+
58
+ export const ModalPayloadSchema = z.object({
59
+ id: z.string(),
60
+ content: VirtualNodeSchema.optional(),
61
+ title: z.string().optional(),
62
+ metadata: z.record(z.string(), z.any()).optional(),
63
+ });
64
+ export type ModalPayload = z.infer<typeof ModalPayloadSchema>;
65
+
66
+ export { VirtualNodeSchema };