bazilion 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/.understand-anything/.understandignore +25 -0
  2. package/.understand-anything/fingerprints.json +14267 -0
  3. package/.understand-anything/knowledge-graph.json +18128 -0
  4. package/.understand-anything/meta.json +6 -0
  5. package/CLAUDE.md +164 -0
  6. package/LICENSE +21 -0
  7. package/README.md +195 -0
  8. package/apps/cli/package.json +21 -0
  9. package/apps/cli/src/auth-file.ts +18 -0
  10. package/apps/cli/src/client.ts +37 -0
  11. package/apps/cli/src/columnize.ts +32 -0
  12. package/apps/cli/src/commands/agent.ts +574 -0
  13. package/apps/cli/src/commands/auth.ts +110 -0
  14. package/apps/cli/src/commands/backup.ts +135 -0
  15. package/apps/cli/src/commands/completion.ts +155 -0
  16. package/apps/cli/src/commands/config.ts +95 -0
  17. package/apps/cli/src/commands/doctor.ts +131 -0
  18. package/apps/cli/src/commands/group.ts +132 -0
  19. package/apps/cli/src/commands/inbox.ts +82 -0
  20. package/apps/cli/src/commands/login.ts +73 -0
  21. package/apps/cli/src/commands/memory.ts +106 -0
  22. package/apps/cli/src/commands/profile.ts +259 -0
  23. package/apps/cli/src/commands/provider.ts +170 -0
  24. package/apps/cli/src/commands/send.ts +24 -0
  25. package/apps/cli/src/commands/serve.ts +89 -0
  26. package/apps/cli/src/commands/skill.ts +120 -0
  27. package/apps/cli/src/commands/token.ts +148 -0
  28. package/apps/cli/src/commands/trigger.ts +129 -0
  29. package/apps/cli/src/commands/uninstall.ts +156 -0
  30. package/apps/cli/src/index.ts +196 -0
  31. package/apps/cli/src/paths.ts +12 -0
  32. package/apps/cli/test/agent.test.ts +213 -0
  33. package/apps/cli/test/backup.test.ts +95 -0
  34. package/apps/cli/test/chat.test.ts +539 -0
  35. package/apps/cli/test/columnize.test.ts +29 -0
  36. package/apps/cli/test/completion.test.ts +45 -0
  37. package/apps/cli/test/config-page.test.ts +151 -0
  38. package/apps/cli/test/group.test.ts +74 -0
  39. package/apps/cli/test/helpers.ts +70 -0
  40. package/apps/cli/test/inbox-autodeliver.test.ts +143 -0
  41. package/apps/cli/test/inbox.test.ts +147 -0
  42. package/apps/cli/test/memory.test.ts +69 -0
  43. package/apps/cli/test/profile.test.ts +110 -0
  44. package/apps/cli/test/send.test.ts +30 -0
  45. package/apps/cli/test/server-fixture.ts +212 -0
  46. package/apps/cli/test/session-head.test.ts +45 -0
  47. package/apps/cli/test/skill.test.ts +128 -0
  48. package/apps/cli/test/token.test.ts +109 -0
  49. package/apps/cli/test/trigger.test.ts +245 -0
  50. package/apps/cli/tsconfig.json +4 -0
  51. package/apps/daemon/package.json +31 -0
  52. package/apps/daemon/src/app.ts +41 -0
  53. package/apps/daemon/src/core/agent/archive.ts +8 -0
  54. package/apps/daemon/src/core/agent/delete.ts +30 -0
  55. package/apps/daemon/src/core/agent/resolve.ts +31 -0
  56. package/apps/daemon/src/core/agent/spawn.ts +95 -0
  57. package/apps/daemon/src/core/agent/unarchive.ts +11 -0
  58. package/apps/daemon/src/core/availableModels.ts +58 -0
  59. package/apps/daemon/src/core/db/client.ts +113 -0
  60. package/apps/daemon/src/core/db/migrate.ts +41 -0
  61. package/apps/daemon/src/core/db/migrations/0001_init.sql +179 -0
  62. package/apps/daemon/src/core/group/delete.ts +21 -0
  63. package/apps/daemon/src/core/group/register.ts +68 -0
  64. package/apps/daemon/src/core/index.ts +71 -0
  65. package/apps/daemon/src/core/paths.ts +56 -0
  66. package/apps/daemon/src/core/profile/create.ts +78 -0
  67. package/apps/daemon/src/core/profile/delete.ts +26 -0
  68. package/apps/daemon/src/core/profile/identity.ts +70 -0
  69. package/apps/daemon/src/core/profile/load.ts +45 -0
  70. package/apps/daemon/src/core/profile/seed.ts +74 -0
  71. package/apps/daemon/src/core/profile/templates.ts +60 -0
  72. package/apps/daemon/src/core/profile/update.ts +57 -0
  73. package/apps/daemon/src/core/profile/validate.ts +9 -0
  74. package/apps/daemon/src/core/repos/agents.ts +202 -0
  75. package/apps/daemon/src/core/repos/config.ts +78 -0
  76. package/apps/daemon/src/core/repos/groups.ts +55 -0
  77. package/apps/daemon/src/core/repos/messages.ts +127 -0
  78. package/apps/daemon/src/core/repos/profiles.ts +83 -0
  79. package/apps/daemon/src/core/repos/providerModels.ts +58 -0
  80. package/apps/daemon/src/core/repos/providerState.ts +37 -0
  81. package/apps/daemon/src/core/repos/secrets.ts +145 -0
  82. package/apps/daemon/src/core/repos/skillMeta.ts +49 -0
  83. package/apps/daemon/src/core/repos/triggers.ts +101 -0
  84. package/apps/daemon/src/core/repos/webTokens.ts +87 -0
  85. package/apps/daemon/src/core/secrets.ts +65 -0
  86. package/apps/daemon/src/core/services.ts +264 -0
  87. package/apps/daemon/src/core/skills/discover.ts +28 -0
  88. package/apps/daemon/src/core/skills/import.ts +136 -0
  89. package/apps/daemon/src/core/skills/parse.ts +52 -0
  90. package/apps/daemon/src/core/skills/resolve.ts +50 -0
  91. package/apps/daemon/src/index.ts +45 -0
  92. package/apps/daemon/src/lib/agent-cancel.ts +48 -0
  93. package/apps/daemon/src/lib/agent-id.ts +13 -0
  94. package/apps/daemon/src/lib/agent-turn.ts +56 -0
  95. package/apps/daemon/src/lib/api-key.ts +56 -0
  96. package/apps/daemon/src/lib/auth.ts +41 -0
  97. package/apps/daemon/src/lib/cron.ts +93 -0
  98. package/apps/daemon/src/lib/ctx.ts +80 -0
  99. package/apps/daemon/src/lib/messaging-host.ts +34 -0
  100. package/apps/daemon/src/lib/middleware-auth.ts +52 -0
  101. package/apps/daemon/src/lib/scheduler.ts +294 -0
  102. package/apps/daemon/src/routes/agents.ts +772 -0
  103. package/apps/daemon/src/routes/auth-login.ts +193 -0
  104. package/apps/daemon/src/routes/config.ts +267 -0
  105. package/apps/daemon/src/routes/groups.ts +133 -0
  106. package/apps/daemon/src/routes/messages.ts +29 -0
  107. package/apps/daemon/src/routes/misc.ts +239 -0
  108. package/apps/daemon/src/routes/profiles.ts +197 -0
  109. package/apps/daemon/src/routes/skills.ts +123 -0
  110. package/apps/daemon/src/routes/triggers.ts +29 -0
  111. package/apps/daemon/src/runtime/auth/openai-codex.ts +121 -0
  112. package/apps/daemon/src/runtime/auto-reply/heartbeat.ts +31 -0
  113. package/apps/daemon/src/runtime/index.ts +77 -0
  114. package/apps/daemon/src/runtime/memory/files.ts +103 -0
  115. package/apps/daemon/src/runtime/memory/qmd.ts +152 -0
  116. package/apps/daemon/src/runtime/memory/types.ts +16 -0
  117. package/apps/daemon/src/runtime/pi/events.ts +173 -0
  118. package/apps/daemon/src/runtime/pi/session.ts +536 -0
  119. package/apps/daemon/src/runtime/pi/tools.ts +85 -0
  120. package/apps/daemon/src/runtime/providers/catalog.ts +145 -0
  121. package/apps/daemon/src/runtime/providers/pi-adapter.ts +272 -0
  122. package/apps/daemon/src/runtime/providers/registry.ts +374 -0
  123. package/apps/daemon/src/runtime/providers/retry.ts +176 -0
  124. package/apps/daemon/src/runtime/providers/types.ts +33 -0
  125. package/apps/daemon/src/runtime/session/prompt.ts +83 -0
  126. package/apps/daemon/src/runtime/tools/bootstrap.ts +22 -0
  127. package/apps/daemon/src/runtime/tools/home.ts +114 -0
  128. package/apps/daemon/src/runtime/tools/memory.ts +81 -0
  129. package/apps/daemon/src/runtime/tools/messaging.ts +127 -0
  130. package/apps/daemon/src/runtime/tools/registry.ts +29 -0
  131. package/apps/daemon/src/runtime/tools/types.ts +13 -0
  132. package/apps/daemon/src/runtime/tools/web-extract.ts +110 -0
  133. package/apps/daemon/src/runtime/tools/web-ssrf.ts +245 -0
  134. package/apps/daemon/src/runtime/tools/web.ts +273 -0
  135. package/apps/daemon/src/runtime/worker/entry.ts +221 -0
  136. package/apps/daemon/src/runtime/worker/ipc-protocol.ts +75 -0
  137. package/apps/daemon/src/runtime/worker/spawn.ts +249 -0
  138. package/apps/daemon/test/core/agents.test.ts +319 -0
  139. package/apps/daemon/test/core/available-models.test.ts +63 -0
  140. package/apps/daemon/test/core/config.test.ts +99 -0
  141. package/apps/daemon/test/core/groups.test.ts +63 -0
  142. package/apps/daemon/test/core/helpers.ts +50 -0
  143. package/apps/daemon/test/core/identity.test.ts +85 -0
  144. package/apps/daemon/test/core/migrations.test.ts +83 -0
  145. package/apps/daemon/test/core/profiles.test.ts +182 -0
  146. package/apps/daemon/test/core/provider-models.test.ts +57 -0
  147. package/apps/daemon/test/core/provider-state.test.ts +36 -0
  148. package/apps/daemon/test/core/skill-meta.test.ts +45 -0
  149. package/apps/daemon/test/core/skills.test.ts +271 -0
  150. package/apps/daemon/test/core/triggers.test.ts +182 -0
  151. package/apps/daemon/test/core/web-tokens.test.ts +79 -0
  152. package/apps/daemon/test/cron.test.ts +90 -0
  153. package/apps/daemon/test/runtime/heartbeat.test.ts +34 -0
  154. package/apps/daemon/test/runtime/memory-qmd.test.ts +97 -0
  155. package/apps/daemon/test/runtime/memory.test.ts +78 -0
  156. package/apps/daemon/test/runtime/messaging.test.ts +213 -0
  157. package/apps/daemon/test/runtime/mock-server.ts +65 -0
  158. package/apps/daemon/test/runtime/openai-codex-auth.test.ts +116 -0
  159. package/apps/daemon/test/runtime/providers.test.ts +306 -0
  160. package/apps/daemon/test/runtime/retry.test.ts +191 -0
  161. package/apps/daemon/test/runtime/session-head.test.ts +90 -0
  162. package/apps/daemon/test/runtime/tools-home.test.ts +102 -0
  163. package/apps/daemon/test/runtime/tools-web.test.ts +206 -0
  164. package/apps/daemon/tsconfig.json +4 -0
  165. package/apps/mobile/README.md +60 -0
  166. package/apps/mobile/app/_layout.tsx +58 -0
  167. package/apps/mobile/app/agents/[id]/chat.tsx +486 -0
  168. package/apps/mobile/app/agents/[id]/index.tsx +166 -0
  169. package/apps/mobile/app/agents/index.tsx +212 -0
  170. package/apps/mobile/app/index.tsx +21 -0
  171. package/apps/mobile/app/pair.tsx +226 -0
  172. package/apps/mobile/app/settings.tsx +419 -0
  173. package/apps/mobile/app.json +49 -0
  174. package/apps/mobile/assets/adaptive-icon.png +0 -0
  175. package/apps/mobile/assets/favicon.png +0 -0
  176. package/apps/mobile/assets/icon.png +0 -0
  177. package/apps/mobile/assets/splash-icon.png +0 -0
  178. package/apps/mobile/babel.config.js +6 -0
  179. package/apps/mobile/metro.config.js +28 -0
  180. package/apps/mobile/package.json +44 -0
  181. package/apps/mobile/src/auth.ts +66 -0
  182. package/apps/mobile/src/pair-url.ts +48 -0
  183. package/apps/mobile/src/theme-context.tsx +88 -0
  184. package/apps/mobile/src/theme.ts +135 -0
  185. package/apps/mobile/test/pair-url.test.ts +46 -0
  186. package/apps/mobile/tsconfig.json +23 -0
  187. package/apps/web/components.json +25 -0
  188. package/apps/web/package.json +39 -0
  189. package/apps/web/public/baziu.svg +8 -0
  190. package/apps/web/src/components/AgentTabs.tsx +45 -0
  191. package/apps/web/src/components/BaziuLogo.tsx +21 -0
  192. package/apps/web/src/components/ChatPane.tsx +1033 -0
  193. package/apps/web/src/components/ConfigTabs.tsx +29 -0
  194. package/apps/web/src/components/CopyButton.tsx +68 -0
  195. package/apps/web/src/components/CreateGroupDialog.tsx +127 -0
  196. package/apps/web/src/components/FieldRow.tsx +94 -0
  197. package/apps/web/src/components/Footer.tsx +10 -0
  198. package/apps/web/src/components/PawIcon.tsx +15 -0
  199. package/apps/web/src/components/Sidebar.tsx +287 -0
  200. package/apps/web/src/components/SpawnDialog.tsx +129 -0
  201. package/apps/web/src/components/ThemeToggle.tsx +75 -0
  202. package/apps/web/src/components/TopNav.tsx +34 -0
  203. package/apps/web/src/components/ui/button.tsx +67 -0
  204. package/apps/web/src/components/ui/card.tsx +103 -0
  205. package/apps/web/src/components/ui/checkbox.tsx +31 -0
  206. package/apps/web/src/components/ui/dialog.tsx +168 -0
  207. package/apps/web/src/components/ui/input.tsx +19 -0
  208. package/apps/web/src/components/ui/label.tsx +22 -0
  209. package/apps/web/src/components/ui/radio-group.tsx +44 -0
  210. package/apps/web/src/components/ui/select.tsx +192 -0
  211. package/apps/web/src/components/ui/separator.tsx +26 -0
  212. package/apps/web/src/components/ui/table.tsx +116 -0
  213. package/apps/web/src/components/ui/tabs.tsx +88 -0
  214. package/apps/web/src/components/ui/textarea.tsx +18 -0
  215. package/apps/web/src/lib/auth.ts +50 -0
  216. package/apps/web/src/lib/daemon-client.ts +34 -0
  217. package/apps/web/src/lib/md.ts +45 -0
  218. package/apps/web/src/lib/utils.ts +6 -0
  219. package/apps/web/src/lib/wire-constants.ts +27 -0
  220. package/apps/web/src/routeTree.gen.ts +408 -0
  221. package/apps/web/src/router.tsx +20 -0
  222. package/apps/web/src/routes/__root.tsx +123 -0
  223. package/apps/web/src/routes/agents/$id/inbox.tsx +207 -0
  224. package/apps/web/src/routes/agents/$id/index.tsx +527 -0
  225. package/apps/web/src/routes/agents/$id/triggers.tsx +239 -0
  226. package/apps/web/src/routes/agents/index.tsx +265 -0
  227. package/apps/web/src/routes/api/$.ts +88 -0
  228. package/apps/web/src/routes/config/index.tsx +315 -0
  229. package/apps/web/src/routes/config/services.tsx +49 -0
  230. package/apps/web/src/routes/config/tokens.tsx +192 -0
  231. package/apps/web/src/routes/groups/$id/index.tsx +153 -0
  232. package/apps/web/src/routes/groups/$id/memory.tsx +321 -0
  233. package/apps/web/src/routes/groups/index.tsx +191 -0
  234. package/apps/web/src/routes/index.tsx +133 -0
  235. package/apps/web/src/routes/login.tsx +63 -0
  236. package/apps/web/src/routes/profiles/$id.tsx +549 -0
  237. package/apps/web/src/routes/profiles/index.tsx +458 -0
  238. package/apps/web/src/routes/skills/index.tsx +297 -0
  239. package/apps/web/src/routes/welcome.tsx +61 -0
  240. package/apps/web/src/styles.css +449 -0
  241. package/apps/web/tsconfig.json +25 -0
  242. package/apps/web/vite.config.ts +25 -0
  243. package/biome.json +23 -0
  244. package/docs/agent-engine.md +219 -0
  245. package/docs/architecture.md +627 -0
  246. package/docs/backlog/README.md +42 -0
  247. package/docs/backlog/draft/BAZ-001-a2a-federation-spike.md +125 -0
  248. package/docs/openclaw-reference.md +210 -0
  249. package/package.json +38 -0
  250. package/packages/api-types/package.json +11 -0
  251. package/packages/api-types/src/entities.ts +146 -0
  252. package/packages/api-types/src/events.ts +55 -0
  253. package/packages/api-types/src/index.ts +488 -0
  254. package/packages/api-types/src/memory.ts +15 -0
  255. package/packages/client/package.json +13 -0
  256. package/packages/client/src/index.ts +117 -0
  257. package/pnpm-workspace.yaml +3 -0
  258. package/tsconfig.base.json +23 -0
  259. package/tsconfig.json +11 -0
  260. package/vitest.config.ts +22 -0
@@ -0,0 +1,488 @@
1
+ // Wire-shape package. Hermetic: depends on nothing from the daemon, so every
2
+ // client (web, mobile, cli, future SDKs) can pull in API shapes without
3
+ // dragging Node-only code (node:sqlite, undici, pi-ai, the worker spawner)
4
+ // into its TS check graph or runtime bundle. The daemon imports its entity
5
+ // and wire types FROM here.
6
+
7
+ export type {
8
+ Agent,
9
+ AgentIdentityFile,
10
+ AgentSkillAttachment,
11
+ AgentStatus,
12
+ AgentTrigger,
13
+ Group,
14
+ LoadedProfile,
15
+ Message,
16
+ OpenAICodexStatus,
17
+ Profile,
18
+ ReasoningLevel,
19
+ ResolvedAgent,
20
+ SkillMeta,
21
+ SkillsMode,
22
+ Timestamp,
23
+ TriggerKind,
24
+ WebToken,
25
+ } from './entities.ts'
26
+ export { REASONING_LEVELS } from './entities.ts'
27
+ export type {
28
+ ChatFrame,
29
+ ProviderMessage,
30
+ Role,
31
+ SessionEvent,
32
+ ToolCall,
33
+ ToolDef,
34
+ } from './events.ts'
35
+ export type { MemoryEntry, MemoryHit } from './memory.ts'
36
+
37
+ import type { AgentTrigger, Message, ReasoningLevel, WebToken } from './entities.ts'
38
+
39
+ export interface ApiError {
40
+ error: string
41
+ code?: string
42
+ }
43
+
44
+ // --- agents ---
45
+
46
+ export interface ListAgentsQuery {
47
+ includeArchived?: boolean
48
+ }
49
+
50
+ export interface SpawnAgentRequest {
51
+ profileId: string
52
+ name?: string
53
+ model?: string
54
+ reasoningLevel?: ReasoningLevel
55
+ /** Group the new agent joins. Falls back to the seeded 'default' group when omitted. */
56
+ groupId?: string
57
+ }
58
+
59
+ export interface UpdateAgentRequest {
60
+ modelOverride?: string | null
61
+ reasoningLevel?: ReasoningLevel
62
+ }
63
+
64
+ export interface AttachSkillRequest {
65
+ skill: string
66
+ }
67
+
68
+ /** Body for `PATCH /api/agents/:id/group`: move the agent to a new group. */
69
+ export interface MoveAgentRequest {
70
+ groupId: string
71
+ }
72
+
73
+ export interface SendMessageRequest {
74
+ from: string
75
+ payload: { text: string }
76
+ replyTo?: string
77
+ }
78
+
79
+ export interface ListInboxQuery {
80
+ unread?: boolean
81
+ }
82
+
83
+ export interface ListInboxResponse {
84
+ messages: Message[]
85
+ }
86
+
87
+ export interface UpdateMessageRequest {
88
+ read: true
89
+ }
90
+
91
+ // --- profiles ---
92
+
93
+ export interface UpdateProfileRequest {
94
+ name?: string
95
+ defaultModel?: string
96
+ skillsMode?: 'all' | 'selected'
97
+ defaultSkills?: string[]
98
+ }
99
+
100
+ export interface CreateProfileRequest {
101
+ id: string
102
+ name?: string
103
+ defaultModel: string
104
+ skillsMode?: 'all' | 'selected'
105
+ defaultSkills?: string[]
106
+ /** Initial SOUL.md content. Falls back to the built-in template when omitted. */
107
+ soul?: string
108
+ /** Initial IDENTITY.md content. Falls back to the built-in template when omitted. */
109
+ identity?: string
110
+ /** Initial BOOTSTRAP.md content. Omit for default; pass null to skip bootstrap entirely. */
111
+ bootstrap?: string | null
112
+ /** Initial AGENTS.md content. Omit to skip; pass a string to seed the file. */
113
+ agents?: string
114
+ /** Initial TOOLS.md content. Omit to skip; pass a string to seed the file. */
115
+ tools?: string
116
+ /** Initial HEARTBEAT.md content. Omit to skip; pass a string to seed the file. */
117
+ heartbeat?: string
118
+ }
119
+
120
+ // --- groups ---
121
+
122
+ export interface RegisterGroupRequest {
123
+ /** Slug (lowercase, digits, hyphens). Becomes the row id AND the directory
124
+ * name under `~/.bazilion/groups/<slug>/`. */
125
+ id: string
126
+ /** Optional human-readable label. Defaults to `id`. */
127
+ name?: string
128
+ /**
129
+ * Optional symlink target. When set, the daemon materializes the group
130
+ * slot as a symlink to this absolute path instead of as a real directory
131
+ * — useful for "agents working on my existing project tree." Target must
132
+ * exist and be a directory.
133
+ */
134
+ link?: string
135
+ }
136
+
137
+ /** Body for `PUT /api/groups/:id/user-md`. */
138
+ export interface SetGroupUserMdRequest {
139
+ userMd: string
140
+ }
141
+
142
+ // --- skills (write) ---
143
+
144
+ export interface ImportSkillsRequest {
145
+ source: string
146
+ force?: boolean
147
+ }
148
+
149
+ export interface ImportSkillsResponse {
150
+ imported: string[]
151
+ skipped: { name: string; reason: string }[]
152
+ }
153
+
154
+ // --- providers (write) ---
155
+
156
+ export interface ProviderTestRequest {
157
+ model: string
158
+ message?: string
159
+ }
160
+
161
+ export interface ProviderTestResponse {
162
+ content: string
163
+ usage?: {
164
+ promptTokens: number
165
+ completionTokens: number
166
+ }
167
+ }
168
+
169
+ // --- chat streaming ---
170
+
171
+ export interface ChatRequest {
172
+ message: string
173
+ }
174
+
175
+ // --- profile files ---
176
+
177
+ export type ProfileFileName =
178
+ | 'profile.json'
179
+ | 'SOUL.md'
180
+ | 'IDENTITY.md'
181
+ | 'BOOTSTRAP.md'
182
+ | 'AGENTS.md'
183
+ | 'TOOLS.md'
184
+ | 'HEARTBEAT.md'
185
+
186
+ export const PROFILE_FILES: ProfileFileName[] = [
187
+ 'profile.json',
188
+ 'SOUL.md',
189
+ 'IDENTITY.md',
190
+ 'BOOTSTRAP.md',
191
+ 'AGENTS.md',
192
+ 'TOOLS.md',
193
+ 'HEARTBEAT.md',
194
+ ]
195
+
196
+ export interface FileContentResponse {
197
+ content: string
198
+ }
199
+
200
+ export interface PutFileRequest {
201
+ content: string
202
+ }
203
+
204
+ // --- skills ---
205
+
206
+ export interface SkillInfo {
207
+ name: string
208
+ description: string
209
+ source: string | null
210
+ importedAt: number | null
211
+ parseError?: string
212
+ }
213
+
214
+ export interface ResolvedSkillsResponse {
215
+ resolved: SkillInfo[]
216
+ missing: { name: string; reason: string }[]
217
+ }
218
+
219
+ export interface TruncateChatRequest {
220
+ /** Number of leading messages to preserve; everything after is dropped. */
221
+ keepCount: number
222
+ }
223
+
224
+ export interface TruncateChatResponse {
225
+ before: number
226
+ after: number
227
+ }
228
+
229
+ /**
230
+ * Lightweight "has anything new happened on this agent's session?" probe.
231
+ * Polled by the web chat UI to detect out-of-band activity (inbox-wakes,
232
+ * scheduled triggers, turns run from another tab) so it can prompt the user
233
+ * to refresh — the session JSONL is append-only, so either a new filename or
234
+ * a bigger byte-count means new entries landed.
235
+ */
236
+ export interface SessionHeadResponse {
237
+ /** Basename of the most-recent `.jsonl` session file, or `null` if none. */
238
+ file: string | null
239
+ /** Byte size of that file (monotonically increasing while in use). */
240
+ size: number
241
+ }
242
+
243
+ export interface ContextFileEntry {
244
+ /** Basename of the injected profile file (e.g. SOUL.md). */
245
+ name: string
246
+ /** Full character count of the file's contribution to the system prompt. */
247
+ chars: number
248
+ /** Rough token estimate (chars / 4). */
249
+ tokens: number
250
+ }
251
+
252
+ export interface ContextToolEntry {
253
+ name: string
254
+ /** JSON schema char size (what the provider sees as tool definitions). */
255
+ schemaChars: number
256
+ /** Description char size. */
257
+ descriptionChars: number
258
+ /** Count of top-level properties on the input schema, when shaped like JSONSchema. */
259
+ paramCount: number | null
260
+ }
261
+
262
+ export interface ContextSkillEntry {
263
+ name: string
264
+ /** Char count of the skill block injected into the system prompt (currently just the name). */
265
+ blockChars: number
266
+ }
267
+
268
+ export interface ContextGroupEntry {
269
+ id: string
270
+ name: string
271
+ path: string
272
+ userMdChars: number
273
+ }
274
+
275
+ export interface ContextHistoryBreakdown {
276
+ /** Count of `message` entries. */
277
+ messageEntries: number
278
+ /** Count of `compaction` entries (summarization boundaries). */
279
+ compactionEntries: number
280
+ /** Char sum of message `content` fields (LLM input surface). */
281
+ chars: number
282
+ /** Raw wire size of the serialized log on disk. */
283
+ bytes: number
284
+ /** Rough token estimate (chars / 4) for history alone. */
285
+ tokensEstimate: number
286
+ }
287
+
288
+ export interface ChatContextResponse {
289
+ /** Agent being reported on. */
290
+ agentId: string
291
+ /** provider:model string the agent currently resolves to. */
292
+ model: string
293
+ systemPrompt: {
294
+ chars: number
295
+ tokens: number
296
+ /** Per-file breakdown of profile markdown sources (AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, HEARTBEAT.md, BOOTSTRAP.md). */
297
+ files: ContextFileEntry[]
298
+ /** Char count of the skill-list text rendered into the system prompt. */
299
+ skillsListChars: number
300
+ /** Char count of the group block rendered into the system prompt. */
301
+ groupListChars: number
302
+ /** Char count of the USER.md block (0 when the group's userMd is empty). */
303
+ userMdChars: number
304
+ /** Fixed memory-hint block the runtime always appends. */
305
+ memoryHintChars: number
306
+ }
307
+ tools: {
308
+ count: number
309
+ listChars: number
310
+ schemaChars: number
311
+ entries: ContextToolEntry[]
312
+ }
313
+ skills: {
314
+ count: number
315
+ entries: ContextSkillEntry[]
316
+ }
317
+ group: ContextGroupEntry
318
+ history: ContextHistoryBreakdown
319
+ /** Sum of system prompt + tool schemas + history, in chars + tokens. */
320
+ totals: { chars: number; tokens: number }
321
+ }
322
+
323
+ export interface ChatCompactRequest {
324
+ /** Number of trailing message entries to keep verbatim. Default 10. */
325
+ keepTail?: number
326
+ /** Optional freeform guidance prepended to the summarizer system prompt. */
327
+ customInstructions?: string
328
+ }
329
+
330
+ export interface ChatCompactResponse {
331
+ /** Entry count before compaction. */
332
+ before: number
333
+ /** Entry count after compaction (1 compaction + `keptTail` messages). */
334
+ after: number
335
+ /** Message entries summarized into the compaction (the head that was dropped). */
336
+ summarized: number
337
+ /** Message entries preserved verbatim after the compaction boundary. */
338
+ keptTail: number
339
+ /** Rough token estimate of the log before compaction. */
340
+ tokensBefore: number
341
+ /** Rough token estimate of the log after compaction. */
342
+ tokensAfter: number
343
+ /** The summary text produced by the model. */
344
+ summary: string
345
+ }
346
+
347
+ // --- triggers (heartbeats / cron) ---
348
+
349
+ export interface CreateTriggerRequest {
350
+ kind: 'interval' | 'cron'
351
+ /** required when kind='interval' */
352
+ intervalSec?: number
353
+ /** required when kind='cron' — 5-field expression ("m h dom mon dow") */
354
+ cronExpr?: string
355
+ /** injected as the user message when the trigger fires */
356
+ message: string
357
+ enabled?: boolean
358
+ }
359
+
360
+ export interface UpdateTriggerRequest {
361
+ enabled?: boolean
362
+ }
363
+
364
+ export interface CreateTriggerResponse {
365
+ trigger: AgentTrigger
366
+ }
367
+
368
+ export interface UpdateTriggerResponse {
369
+ trigger: AgentTrigger
370
+ }
371
+
372
+ export interface ListTriggersResponse {
373
+ triggers: AgentTrigger[]
374
+ }
375
+
376
+ // --- config page (providers + services + fields) ---
377
+
378
+ /** Per-field UI + storage descriptor — source-of-truth is SERVICES in apps/daemon/src/core/services.ts. */
379
+ export interface ServiceFieldState {
380
+ envVar: string
381
+ kind: 'secret' | 'config'
382
+ label: string
383
+ placeholder?: string
384
+ description?: string
385
+ /** True when the field has a non-empty value in its storage backend. */
386
+ set: boolean
387
+ /** For `kind: 'config'` (plaintext): the actual value. Omitted for secrets. */
388
+ value?: string
389
+ /** For `kind: 'secret'`: a truncated preview like "sk-abc…" so the UI can confirm something is stored. Omitted when unset. */
390
+ preview?: string
391
+ }
392
+
393
+ export interface ServiceCard {
394
+ id: string
395
+ displayName: string
396
+ /** Present for category==='provider' cards — tracks whether the pi-adapter sees it as configured. */
397
+ enabled?: boolean
398
+ envHint?: string
399
+ hint?: string
400
+ fields: ServiceFieldState[]
401
+ }
402
+
403
+ export interface ProviderConfigEntry extends ServiceCard {
404
+ enabled: boolean
405
+ envHint: string
406
+ /** Static catalog from pi-ai's typed model list — empty for providers not in the catalog. */
407
+ catalog: string[]
408
+ /** Live `/v1/models` query — omitted when the provider doesn't expose one. */
409
+ live?: { models: string[]; error?: string }
410
+ /** Curated models the admin has selected — drives the dropdowns in profile/agent forms. */
411
+ curated: string[]
412
+ }
413
+
414
+ export interface ProviderConfigResponse {
415
+ providers: ProviderConfigEntry[]
416
+ }
417
+
418
+ export interface ServiceConfigResponse {
419
+ services: ServiceCard[]
420
+ }
421
+
422
+ export interface SetFieldRequest {
423
+ value: string
424
+ }
425
+
426
+ export interface SetProviderModelsRequest {
427
+ models: string[]
428
+ }
429
+
430
+ export interface SetProviderModelsResponse {
431
+ models: string[]
432
+ }
433
+
434
+ export interface SetProviderEnabledRequest {
435
+ enabled: boolean
436
+ }
437
+
438
+ export interface SetProviderEnabledResponse {
439
+ name: string
440
+ enabled: boolean
441
+ }
442
+
443
+ // --- web tokens ---
444
+
445
+ export interface CreateTokenRequest {
446
+ label: string
447
+ }
448
+
449
+ export interface CreateTokenResponse {
450
+ /** Plaintext token — returned exactly once. */
451
+ token: string
452
+ meta: WebToken
453
+ }
454
+
455
+ export interface ListTokensResponse {
456
+ tokens: WebToken[]
457
+ }
458
+
459
+ // --- health (doctor) ---
460
+
461
+ export interface HealthReport {
462
+ ok: boolean
463
+ home: string
464
+ paths: {
465
+ home: boolean
466
+ db: boolean
467
+ auth: boolean
468
+ profiles: boolean
469
+ agents: boolean
470
+ skills: boolean
471
+ }
472
+ database:
473
+ | { ok: true; profiles: number; activeAgents: number; totalAgents: number; groups: number }
474
+ | { ok: false; error: string }
475
+ | null
476
+ skills: { installed: number; parseErrors: number }
477
+ providers: {
478
+ /** Names of cloud providers with credentials configured (e.g. ['anthropic', 'groq']). */
479
+ configured: string[]
480
+ lmstudio: { baseURL: string; hasKey: boolean }
481
+ ollama: { baseURL: string }
482
+ }
483
+ webSearch: { bravePreview: string | null; searxngUrl: string | null }
484
+ openclaw: { path: string; exists: boolean }
485
+ triggers: { active: number; disabled: number }
486
+ tokens: { active: number }
487
+ scheduler: { enabled: boolean; tickMs: number }
488
+ }
@@ -0,0 +1,15 @@
1
+ // Wire shapes for the per-group memory store. The `MemoryBackend` interface
2
+ // itself stays in apps/daemon/src/runtime/memory (it has methods and is
3
+ // server-internal); these are the values that cross the HTTP wire.
4
+
5
+ export interface MemoryEntry {
6
+ key: string
7
+ content: string
8
+ updatedAt: number
9
+ }
10
+
11
+ export interface MemoryHit {
12
+ key: string
13
+ snippet: string
14
+ score: number
15
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@bazilion/client",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "dependencies": {
11
+ "@bazilion/api-types": "workspace:*"
12
+ }
13
+ }
@@ -0,0 +1,117 @@
1
+ import type { ApiError } from '@bazilion/api-types'
2
+
3
+ export type TokenSource = string | (() => string | Promise<string>)
4
+
5
+ export interface ClientConfig {
6
+ serverUrl: string
7
+ /**
8
+ * Bearer token (or supplier for lazy / rotating credentials). The package
9
+ * sends it as `Authorization: Bearer <token>` and also stamps `Origin:
10
+ * <serverUrl>` to pass Astro's `security.checkOrigin` gate on non-GET
11
+ * requests. Pass a function to support token rotation (OAuth refresh,
12
+ * mobile keychain reads) — it is invoked on every request.
13
+ */
14
+ token: TokenSource
15
+ }
16
+
17
+ export class ApiClientError extends Error {
18
+ status: number
19
+ body: ApiError
20
+ constructor(status: number, body: ApiError) {
21
+ super(`${status}: ${body.error}`)
22
+ this.status = status
23
+ this.body = body
24
+ }
25
+ }
26
+
27
+ async function resolveToken(src: TokenSource): Promise<string> {
28
+ return typeof src === 'function' ? await src() : src
29
+ }
30
+
31
+ export function createClient(cfg: ClientConfig) {
32
+ async function authHeaders(): Promise<Record<string, string>> {
33
+ const token = await resolveToken(cfg.token)
34
+ return {
35
+ authorization: `Bearer ${token}`,
36
+ // Astro 6 enabled `security.checkOrigin` by default for server mode:
37
+ // any state-changing request without an `Origin` matching the server
38
+ // host is rejected with 403. Browsers set this automatically; `fetch`
39
+ // in Node / React Native does not. Stamping the server's own URL is
40
+ // always valid for a legitimate client.
41
+ origin: cfg.serverUrl,
42
+ }
43
+ }
44
+
45
+ async function request<T>(method: string, path: string, body?: unknown): Promise<T> {
46
+ const headers: Record<string, string> = { ...(await authHeaders()) }
47
+ if (body !== undefined) headers['content-type'] = 'application/json'
48
+ const res = await fetch(`${cfg.serverUrl}${path}`, {
49
+ method,
50
+ headers,
51
+ body: body !== undefined ? JSON.stringify(body) : undefined,
52
+ })
53
+ if (!res.ok) {
54
+ const err = (await res.json().catch(() => ({ error: res.statusText }))) as ApiError
55
+ throw new ApiClientError(res.status, err)
56
+ }
57
+ if (res.status === 204) return undefined as T
58
+ return (await res.json()) as T
59
+ }
60
+
61
+ // Multipart POST — lets the runtime set its own `content-type: multipart/form-data;
62
+ // boundary=…` header. Reusing `request()` would stomp that with JSON, so
63
+ // we keep a separate path.
64
+ async function postMultipart<T>(path: string, form: FormData): Promise<T> {
65
+ const res = await fetch(`${cfg.serverUrl}${path}`, {
66
+ method: 'POST',
67
+ headers: { ...(await authHeaders()) },
68
+ body: form,
69
+ })
70
+ if (!res.ok) {
71
+ const err = (await res.json().catch(() => ({ error: res.statusText }))) as ApiError
72
+ throw new ApiClientError(res.status, err)
73
+ }
74
+ if (res.status === 204) return undefined as T
75
+ return (await res.json()) as T
76
+ }
77
+
78
+ async function* stream<T>(method: string, path: string, body?: unknown): AsyncGenerator<T> {
79
+ const headers: Record<string, string> = { ...(await authHeaders()) }
80
+ if (body !== undefined) headers['content-type'] = 'application/json'
81
+ const res = await fetch(`${cfg.serverUrl}${path}`, {
82
+ method,
83
+ headers,
84
+ body: body !== undefined ? JSON.stringify(body) : undefined,
85
+ })
86
+ if (!res.ok || !res.body) {
87
+ const err = (await res.json().catch(() => ({ error: res.statusText }))) as ApiError
88
+ throw new ApiClientError(res.status, err)
89
+ }
90
+ const reader = res.body.getReader()
91
+ const decoder = new TextDecoder()
92
+ let buffer = ''
93
+ while (true) {
94
+ const { done, value } = await reader.read()
95
+ if (done) break
96
+ buffer += decoder.decode(value, { stream: true })
97
+ const lines = buffer.split('\n')
98
+ buffer = lines.pop() ?? ''
99
+ for (const line of lines) {
100
+ if (line.trim()) yield JSON.parse(line) as T
101
+ }
102
+ }
103
+ if (buffer.trim()) yield JSON.parse(buffer) as T
104
+ }
105
+
106
+ return {
107
+ get: <T>(p: string) => request<T>('GET', p),
108
+ post: <T>(p: string, b?: unknown) => request<T>('POST', p, b),
109
+ postMultipart,
110
+ put: <T>(p: string, b?: unknown) => request<T>('PUT', p, b),
111
+ patch: <T>(p: string, b?: unknown) => request<T>('PATCH', p, b),
112
+ del: <T>(p: string) => request<T>('DELETE', p),
113
+ stream,
114
+ }
115
+ }
116
+
117
+ export type BazilionClient = ReturnType<typeof createClient>
@@ -0,0 +1,3 @@
1
+ packages:
2
+ - 'apps/*'
3
+ - 'packages/*'
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "lib": ["ESNext"],
7
+ "types": ["node"],
8
+
9
+ "strict": true,
10
+ "noUncheckedIndexedAccess": true,
11
+ "noImplicitOverride": true,
12
+ "noFallthroughCasesInSwitch": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+
15
+ "esModuleInterop": true,
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "verbatimModuleSyntax": true,
19
+ "allowImportingTsExtensions": true,
20
+ "skipLibCheck": true,
21
+ "noEmit": true
22
+ }
23
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.base.json",
3
+ "include": [
4
+ "apps/cli/src/**/*.ts",
5
+ "apps/cli/test/**/*.ts",
6
+ "apps/daemon/src/**/*.ts",
7
+ "apps/daemon/test/**/*.ts",
8
+ "packages/**/src/**/*.ts"
9
+ ],
10
+ "exclude": ["**/node_modules", "**/dist", "apps/web/**"]
11
+ }
@@ -0,0 +1,22 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['apps/*/test/**/*.test.ts', 'packages/*/test/**/*.test.ts'],
6
+ passWithNoTests: true,
7
+ // CLI integration tests spawn the daemon as a subprocess per test file.
8
+ // 30s is generous for cold start; if it's slower, we want to see it fail
9
+ // quickly and diagnose the real cause rather than silently stall the suite.
10
+ hookTimeout: 30_000,
11
+ // Some CLI tests chain 10+ subprocess calls (each ~200–400 ms). Vitest's
12
+ // 5s default testTimeout is below the realistic ceiling, so give them the
13
+ // same 30s budget as hooks. Real hangs still show up quickly.
14
+ testTimeout: 30_000,
15
+ pool: 'forks',
16
+ poolOptions: {
17
+ forks: {
18
+ maxForks: 8,
19
+ },
20
+ },
21
+ },
22
+ })