@alashi/cli 0.5.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/assets/v1/chat.js
CHANGED
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
* inherits the app's theme tokens.
|
|
11
11
|
*
|
|
12
12
|
* Attributes:
|
|
13
|
-
* app
|
|
14
|
-
* placeholder
|
|
13
|
+
* app app name (default: derived from /app/<name>/ in the URL)
|
|
14
|
+
* placeholder input placeholder text
|
|
15
|
+
* conversations "hidden" for single-conversation mode: no sidebar, no
|
|
16
|
+
* conversations request on connect, no auto-open of the
|
|
17
|
+
* newest conversation. The app drives which transcript is
|
|
18
|
+
* shown via openConversation(id) / adoptSession(...).
|
|
19
|
+
* Any other value (or absence) keeps the default sidebar.
|
|
15
20
|
*
|
|
16
21
|
* Methods:
|
|
17
22
|
* adoptSession(sessionId, title) create a conversation resuming an
|
|
@@ -112,6 +117,9 @@
|
|
|
112
117
|
this._initialized = true;
|
|
113
118
|
this.conversationId = null;
|
|
114
119
|
this._render();
|
|
120
|
+
// Single-conversation mode: the embedding app opens the transcript it
|
|
121
|
+
// wants, so skip both the listing fetch and the auto-open.
|
|
122
|
+
if (this._conversationsHidden) return;
|
|
115
123
|
this._loadConversations()
|
|
116
124
|
.then((conversations) => {
|
|
117
125
|
if (conversations.length > 0) this.openConversation(conversations[0].id);
|
|
@@ -123,6 +131,10 @@
|
|
|
123
131
|
return this.getAttribute('app') ?? decodeURIComponent(window.location.pathname.split('/')[2]);
|
|
124
132
|
}
|
|
125
133
|
|
|
134
|
+
get _conversationsHidden() {
|
|
135
|
+
return this.getAttribute('conversations') === 'hidden';
|
|
136
|
+
}
|
|
137
|
+
|
|
126
138
|
_hostApi(path) {
|
|
127
139
|
return `/api/apps/${encodeURIComponent(this.app)}${path}`;
|
|
128
140
|
}
|
|
@@ -142,12 +154,19 @@
|
|
|
142
154
|
event.preventDefault();
|
|
143
155
|
this._submit();
|
|
144
156
|
});
|
|
157
|
+
const main = el('div', { className: 'panel chat-main' }, [this._log, form, this._status]);
|
|
158
|
+
// In single-conversation mode the sidebar is never appended; `this._list`
|
|
159
|
+
// stays a detached <ul> so the rest of the component keeps working.
|
|
160
|
+
if (this._conversationsHidden) {
|
|
161
|
+
this.append(el('div', { className: 'chat-layout' }, [main]));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
145
164
|
const newChat = el('button', { type: 'button', textContent: '+ New chat' });
|
|
146
165
|
newChat.addEventListener('click', () => this.newChat());
|
|
147
166
|
this.append(
|
|
148
167
|
el('div', { className: 'chat-layout' }, [
|
|
149
168
|
el('div', { className: 'panel conversations-panel' }, [newChat, this._list]),
|
|
150
|
-
|
|
169
|
+
main,
|
|
151
170
|
]),
|
|
152
171
|
);
|
|
153
172
|
}
|
|
@@ -194,6 +213,8 @@
|
|
|
194
213
|
}
|
|
195
214
|
|
|
196
215
|
async _loadConversations() {
|
|
216
|
+
// No sidebar to fill, and no reason to ask the host for a list.
|
|
217
|
+
if (this._conversationsHidden) return [];
|
|
197
218
|
const res = await fetch(this._hostApi('/chat/conversations'));
|
|
198
219
|
const { conversations } = await res.json();
|
|
199
220
|
this._list.replaceChildren(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alashi/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "alashi host: install, manage, and run Claude Code-powered apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"templates"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@alashi/apps-sdk": "^0.
|
|
32
|
+
"@alashi/apps-sdk": "^0.6.0",
|
|
33
33
|
"@hono/node-server": "^2.1.1",
|
|
34
34
|
"commander": "^14.0.0",
|
|
35
35
|
"croner": "^10.0.1",
|
|
36
36
|
"hono": "^4.13.2",
|
|
37
37
|
"semver": "^7.8.5",
|
|
38
38
|
"zod": "^4.4.3",
|
|
39
|
-
"@alashi/provider-claude": "^0.
|
|
39
|
+
"@alashi/provider-claude": "^0.2.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^26.2.0",
|
|
@@ -29,13 +29,22 @@ Beside the manifest: `routes` (fetch-style `(Request, ctx) => Response`) and
|
|
|
29
29
|
`jobHandlers` (`{ [name]: (ctx) => Promise<void> }`).
|
|
30
30
|
|
|
31
31
|
Known gap: `onInstall`/`onUpdate` exist in the SDK but the host never calls
|
|
32
|
-
them —
|
|
32
|
+
them — so nothing runs at install time and the app owns its own schema. Schema
|
|
33
|
+
lives in ordered `.sql` files in `migrations/` (`001-init.sql`,
|
|
34
|
+
`002-add-....sql`), applied by `runMigrations(db, join(import.meta.dirname,
|
|
35
|
+
'migrations'))` every time the DB is opened. It is forward-only and tracked in
|
|
36
|
+
`PRAGMA user_version`: a schema change is **a new numbered file**, never an
|
|
37
|
+
edit to one that has already been applied, and there are no down-migrations.
|
|
38
|
+
Statements that cannot run inside a transaction — notably
|
|
39
|
+
`PRAGMA journal_mode = WAL` — must not live in a migration file; set those on
|
|
40
|
+
the connection before calling `runMigrations`.
|
|
33
41
|
|
|
34
42
|
## Runtime surface (`ctx`)
|
|
35
43
|
|
|
36
44
|
- `ctx.dataDir` — the **only** writable directory. SQLite DB and files go
|
|
37
45
|
here (`node:sqlite` `DatabaseSync`). Treat the repo itself as read-only at
|
|
38
|
-
runtime.
|
|
46
|
+
runtime — the DB lives in `ctx.dataDir`, but the `migrations/` files that
|
|
47
|
+
shape it are code and are read from the app repo (`import.meta.dirname`).
|
|
39
48
|
- `ctx.config` — merged config (readonly).
|
|
40
49
|
- `ctx.state` — small key/value store; `ctx.logger` — log here, not console.
|
|
41
50
|
- `ctx.ai.createSession()` — an agent session, pre-scoped by the host
|
|
@@ -59,7 +68,9 @@ them — create DB schema lazily (`CREATE TABLE IF NOT EXISTS` on first open).
|
|
|
59
68
|
`:root { --accent: ... }` token overrides only) and `/assets/v1/chat.js` —
|
|
60
69
|
the `<alashi-chat>` web component (conversations, SSE streaming, safe
|
|
61
70
|
markdown incl. images, tool status, cost). Attributes: `app`,
|
|
62
|
-
`placeholder
|
|
71
|
+
`placeholder`, `conversations` (`"hidden"` = single-conversation mode: no
|
|
72
|
+
sidebar, no conversations fetch on connect; the app picks the transcript
|
|
73
|
+
with `openConversation`/`adoptSession`). Methods: `adoptSession(sessionId, title?)`,
|
|
63
74
|
`openConversation(id)`, `newChat()`. Bubbling events: `alashi-chat:turn`
|
|
64
75
|
(`{ok, costUsd, error, conversationId}`), `alashi-chat:conversation`.
|
|
65
76
|
Never vendor or fork system UI; breaking changes ship as `/assets/v2/`.
|
|
@@ -18,6 +18,7 @@ your changes are live.
|
|
|
18
18
|
| File | What it is |
|
|
19
19
|
|---|---|
|
|
20
20
|
| `index.mjs` | The app: manifest, API routes, job handlers |
|
|
21
|
+
| `migrations/` | Ordered `.sql` files — the DB schema, applied at DB open |
|
|
21
22
|
| `ui/index.html` | The web UI, served at `/app/__APP_NAME__/` |
|
|
22
23
|
| `AGENTS.md` | The platform contract, written for coding agents working in this repo |
|
|
23
24
|
|
|
@@ -27,7 +28,12 @@ your `routes` handler, so you can also server-render pages.
|
|
|
27
28
|
## What the app gets
|
|
28
29
|
|
|
29
30
|
- **`ctx.dataDir`** — the only writable directory; put your SQLite DB and
|
|
30
|
-
files here (the template
|
|
31
|
+
files here (the template opens `app.db` there on first request and applies
|
|
32
|
+
`migrations/` to it)
|
|
33
|
+
- **`migrations/`** — the schema, as ordered `.sql` files applied by
|
|
34
|
+
`runMigrations` at DB open: forward-only, tracked in `PRAGMA user_version`.
|
|
35
|
+
To change the schema, add the next numbered file (`002-...sql`) — never edit
|
|
36
|
+
one that has already run
|
|
31
37
|
- **`ctx.state`** — small key/value store (`state.json`)
|
|
32
38
|
- **`ctx.config`** — `configDefaults` merged with the user's per-app config
|
|
33
39
|
- **`ctx.ai`** — AI sessions through the host; the Chat page uses the host's
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
-
import { defineApp } from '@alashi/apps-sdk';
|
|
3
|
+
import { defineApp, runMigrations } from '@alashi/apps-sdk';
|
|
4
4
|
|
|
5
5
|
export default defineApp({
|
|
6
6
|
name: '__APP_NAME__',
|
|
7
7
|
version: '0.1.0',
|
|
8
8
|
description: 'An alashi app',
|
|
9
|
-
sdkVersion: '^0.
|
|
9
|
+
sdkVersion: '^0.6.0',
|
|
10
10
|
ui: 'ui',
|
|
11
11
|
configDefaults: {
|
|
12
12
|
greeting: 'What should we work on?',
|
|
@@ -27,11 +27,12 @@ export default defineApp({
|
|
|
27
27
|
routes: (ctx) => {
|
|
28
28
|
// The app's own SQLite database, living in its data dir.
|
|
29
29
|
const db = new DatabaseSync(join(ctx.dataDir, 'app.db'));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// Schema comes from the ordered .sql files in this repo's migrations/
|
|
31
|
+
// (not ctx.dataDir), applied forward-only at DB open. A schema change
|
|
32
|
+
// ships as a new numbered file — never as an edit to an applied one.
|
|
33
|
+
// Pragmas that cannot run inside a transaction (journal_mode) go here,
|
|
34
|
+
// before the call, not into a migration file.
|
|
35
|
+
runMigrations(db, join(import.meta.dirname, 'migrations'), { logger: ctx.logger });
|
|
35
36
|
|
|
36
37
|
return async (req) => {
|
|
37
38
|
const url = new URL(req.url);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Applied once, then never touched again. Schema changes ship as a new
|
|
2
|
+
-- numbered file (002-..., 003-...), never as an edit to this one.
|
|
3
|
+
CREATE TABLE notes (
|
|
4
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
5
|
+
text TEXT NOT NULL,
|
|
6
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
|
|
7
|
+
);
|