@anna-ai/app-runtime 0.27.0 → 0.29.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 (3) hide show
  1. package/README.md +45 -10
  2. package/dist/index.js +126 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -47,8 +47,12 @@ anna.on("entry_payload", (p) => console.log(p));
47
47
  { kind: "req"|"res"|"event", id, ns, method, args | result | error }
48
48
  ```
49
49
 
50
- The host validates every call against the app's manifest ACL before
51
- forwarding to the backend.
50
+ Every method is available to an installed App — there is no manifest ACL.
51
+ Only `credentials.*` (declared provider ids), `share.*`
52
+ (`ui.host_api.share = true`), `conversation.*`
53
+ (`ui.host_api.conversation = true`), cross-boundary `storage.*`
54
+ scopes (`manifest.storage.scopes`) and host-kit agent tools
55
+ (`ui.host_api.agent.tools`) consult the manifest.
52
56
 
53
57
  ## RPC timeouts
54
58
 
@@ -71,6 +75,8 @@ const out = await anna.image.generate(
71
75
  | `upload.*` | 120 s | Large multipart / negotiate+confirm |
72
76
  | `agent.*` | 300 s | `session.run` loops model + tools many turns |
73
77
  | `llm.*` | 180 s | Long completions / large context |
78
+ | `share.*` | 120 s | `publish` server-side-copies up to 200 snapshot files |
79
+ | `conversation.*` | 120 s | `send` resolves after the run is enqueued (may wake a Cloud Agent first) |
74
80
  | everything else | 30 s | storage / chat / window / prefs / fs / tools / artifact |
75
81
 
76
82
  The timeout is a *client-side* deadline. The host bridge fetch has no
@@ -101,6 +107,38 @@ Single file `dist/index.js`. Native ES module (ends in
101
107
  `export { AnnaAppRuntime, ... }`), no build step, runs directly in any modern
102
108
  browser via `<script type="module">` / `import`.
103
109
 
110
+ ## Durable conversations (v0.29.0)
111
+
112
+ `anna.conversation.*` gives an App the user's long-lived conversations: memory,
113
+ persona, persisted history and the full main-conversation tool surface.
114
+ Conversations are isolated per App. Requires
115
+ `manifest.ui.host_api.conversation = true` (otherwise
116
+ `conversation_not_declared`) and a host with dispatcher ≥ 0.36.0.
117
+
118
+ ```js
119
+ const { conversations } = await anna.conversation.list();
120
+ const main = conversations.find((c) => c.is_default);
121
+
122
+ const stream = anna.conversation.send({
123
+ conversation_uuid: main.uuid,
124
+ message: "Summarise my notes from yesterday",
125
+ });
126
+ const run = await stream.ready; // {task_id, stream_id} | null
127
+ for await (const frame of stream) {
128
+ if (frame.event === "error") { /* publisher-level: {code, message} */ }
129
+ else if (frame.error) { /* in-run: {event:"sse", error, error_type} */ }
130
+ else if (frame.choices) { /* OpenAI-style delta, same as the main chat */ }
131
+ }
132
+ // Always reload the persisted history after a run that errored or recovered.
133
+ const { messages } = await anna.conversation.messages({ conversation_uuid: main.uuid });
134
+ ```
135
+
136
+ Recovery after a refresh: `anna.conversation.status({conversation_uuid})`
137
+ returns `{task, stream_id}`. With a `stream_id`, resume with
138
+ `anna.conversation.attach({stream_id, task_id})` (replays from seq 0, dedups
139
+ against live frames). Without one — the run was started outside the Host API
140
+ or is older than 1 h — poll `status` and reload `messages` when it finishes.
141
+
104
142
  ## Agent run output cap & truncation (v0.26.0)
105
143
 
106
144
  Host ≥ 1.1.0-beta.200 / dispatcher 0.30.0 (forum #403). The per-call output
@@ -132,7 +170,7 @@ for await (const ev of sess.run({ content: prompt, maxTokens: 16384 })) {
132
170
 
133
171
  The dashboard tells every App which **theme** and **UI language** the user
134
172
  chose, so Apps no longer guess from `prefers-color-scheme` / `navigator.language`.
135
- No manifest grant is involved — these are one-way host→app broadcasts (like
173
+ These are one-way host→app broadcasts (like
136
174
  `auth.refresh`), never callable RPC methods.
137
175
 
138
176
  ```js
@@ -162,8 +200,8 @@ than this release send neither — the SDK falls back to `prefers-color-scheme`
162
200
 
163
201
  ## Media generation (v0.20.0)
164
202
 
165
- Async video jobs + sync audio, gated by the per-app `media_grant`
166
- (manifest must declare `ui.host_api.video` / `.audio`):
203
+ Async video jobs + sync audio — available to every installed App (CU quota is
204
+ the only gate):
167
205
 
168
206
  ```js
169
207
  // One-shot sugar: submit + media_job events + getJob polling fallback
@@ -191,8 +229,7 @@ const catalog = await anna.llm.catalog({ serviceType: "video_gen" });
191
229
  ### Music generation (v0.23.0)
192
230
 
193
231
  Async music jobs (`mjob_…`) with the exact same job API, `media_job` events and
194
- pre-hold → settle → refund billing as video. Requires `ui.host_api.music` +
195
- per-app `media_grant.music`.
232
+ pre-hold → settle → refund billing as video.
196
233
 
197
234
  ```js
198
235
  // Capability discovery first — models differ (lyrics vs prompt-embedded lyrics,
@@ -225,9 +262,7 @@ await anna.music.generate({ prompt: "ambient pad", model: "fal-ai/ace-step", dur
225
262
  2K/4K or `quality: "high"` renders (60–120 s) opt into the same async-job shape
226
263
  as video / music — `ijob_…` ids, `media_job` events, pre-hold → settle (on the
227
264
  actual number of images) → refund — and re-sign any already-paid artifact for
228
- 7 days instead of losing it after the 30-min URL TTL. Requires
229
- `ui.host_api.image` listing the new method names + the existing `image_grant`
230
- (`allowGenerate` / `allowEdit`; no new grant).
265
+ 7 days instead of losing it after the 30-min URL TTL.
231
266
 
232
267
  ```js
233
268
  // Same request body as image.generate, plus clientTag / idempotencyKey.
package/dist/index.js CHANGED
@@ -1,5 +1,34 @@
1
1
  /**
2
- * Anna App Runtime SDK — v0.27.0
2
+ * Anna App Runtime SDK — v0.29.0
3
+ *
4
+ * v0.29.0 — Durable conversations (design: docs/design/apps/chat.md §5;
5
+ * dispatcher 0.36.0, schema 0.36.0, anna-app-core 0.31.0). Additive:
6
+ * - `anna.conversation.list/create/update/delete/messages/status/cancel/
7
+ * modify/options` — thin RPC wrappers over the user's long-lived
8
+ * conversations (memory, persona, persisted history, the full
9
+ * main-conversation tool surface), isolated per App.
10
+ * - `anna.conversation.send({conversation_uuid, message, ...})` →
11
+ * `AgentRunStream` (same class as `AgentSession.run`); `stream.runId` is
12
+ * the `task_id`, `stream.ready` resolves to `{task_id, stream_id}` once
13
+ * the run is enqueued (null when the RPC was rejected — the rejection is
14
+ * delivered as an `{event:"error", code, message}` frame).
15
+ * - `anna.conversation.attach({stream_id, task_id})` → `AgentRunStream`
16
+ * that replays the stream from seq 0 via `agent.session.frames` while
17
+ * receiving live frames (seq dedup) — refresh / reconnect recovery.
18
+ * Frames are the main-conversation events merged with `{event}`; handle
19
+ * both error shapes: `{event:"error", code, message}` (publisher level) and
20
+ * `{event:"sse", error, error_type}` (in-run). Status frames (`queued`,
21
+ * `started`, `keepalive`) may be absent.
22
+ * Requires manifest `ui.host_api.conversation = true`; otherwise
23
+ * `conversation_not_declared`. Hosts older than dispatcher 0.36.0 reply
24
+ * `unknown_method`.
25
+ *
26
+ * v0.28.0 — Public share links (design:
27
+ * docs/design/app-public-share-static-hosting.md; dispatcher 0.34.0,
28
+ * schema 0.34.0, anna-app-core 0.29.0). Additive:
29
+ * - `anna.share.publish/list/revoke/update` — publish rendered static
30
+ * snapshots (APS objects) to platform-hosted, long-lived, revocable
31
+ * public URLs. Requires manifest `ui.host_api.share = true`.
3
32
  *
4
33
  * v0.27.0 — Thinking / reasoning control (forum #454; design:
5
34
  * docs/design/llm-thinking-control.md; dispatcher 0.32.0, schema 0.32.0,
@@ -449,6 +478,14 @@
449
478
  // browser→R2 PUT itself is direct (not via this SDK), but the host
450
479
  // round-trip for finalize needs DB+R2 head ~ up to a few seconds.
451
480
  files: 60000,
481
+ // `share.publish` server-side CopyObjects up to 200 snapshot files to
482
+ // the public prefix before returning; list/revoke/update are quick but
483
+ // share the namespace default.
484
+ share: 120000,
485
+ // `conversation.send` resolves only after the run is enqueued — model
486
+ // resolution, quota checks and (agent mode) waking a suspended Cloud
487
+ // Agent happen first. The other methods are quick but share the default.
488
+ conversation: 120000,
452
489
  // `web.*` — search is usually <5s but fetch crawls up to 10 pages with
453
490
  // a 30s per-page budget under host-side concurrency limits. Apps doing
454
491
  // large fetch batches should pass { timeoutMs: 90000 } per call.
@@ -1827,6 +1864,59 @@ var AnnaVoiceClientCore = (function () {
1827
1864
  );
1828
1865
  }
1829
1866
 
1867
+ // ---- conversation namespace (v0.29.0; durable conversations) ----
1868
+ //
1869
+ // `send` / `attach` reuse AgentRunStream unchanged: frames arrive as
1870
+ // `rpc.stream` events keyed by stream_id and are replayable through
1871
+ // `agent.session.frames` (which addresses streams, not session kinds).
1872
+ const CONVERSATION_RPCS = [
1873
+ "list", "create", "update", "delete", "messages",
1874
+ "status", "cancel", "modify", "options",
1875
+ ];
1876
+ function buildConversationNamespace(rt) {
1877
+ const ns = {};
1878
+ for (const method of CONVERSATION_RPCS) {
1879
+ ns[method] = (args, opts) =>
1880
+ rt.call("conversation", method, args || {}, opts);
1881
+ }
1882
+ ns.send = (args = {}) => {
1883
+ // `firstFrameTimeoutMs` is SDK-local — strip it from the wire args.
1884
+ const { firstFrameTimeoutMs, ...sendArgs } = args || {};
1885
+ const stream = new AgentRunStream(null, null);
1886
+ stream.ready = rt.call("conversation", "send", sendArgs).then(
1887
+ (res) => {
1888
+ stream.streamId = (res && res.stream_id) || null;
1889
+ stream.runId = (res && res.task_id) || null;
1890
+ if (!stream.streamId) {
1891
+ stream._emit(null, true);
1892
+ } else {
1893
+ rt._registerStream(stream.streamId, stream);
1894
+ stream._armPollFallback(rt, firstFrameTimeoutMs);
1895
+ }
1896
+ return { task_id: stream.runId, stream_id: stream.streamId };
1897
+ },
1898
+ (err) => {
1899
+ stream._emit({ event: "error", code: err.code, message: err.message }, true);
1900
+ return null;
1901
+ }
1902
+ );
1903
+ return stream;
1904
+ };
1905
+ ns.attach = (info = {}) => {
1906
+ const stream = new AgentRunStream(info.stream_id || null, info.task_id || null);
1907
+ stream.ready = Promise.resolve({ task_id: stream.runId, stream_id: stream.streamId });
1908
+ if (!stream.streamId) {
1909
+ stream._emit(null, true);
1910
+ return stream;
1911
+ }
1912
+ stream._rt = rt;
1913
+ rt._registerStream(stream.streamId, stream);
1914
+ stream._pollLoop();
1915
+ return stream;
1916
+ };
1917
+ return ns;
1918
+ }
1919
+
1830
1920
  // ---- HTTP-backed namespaces removed in v0.4.0 ----
1831
1921
  //
1832
1922
  // `anna.image.*` and `anna.upload.*` are now plain postMessage RPCs
@@ -2151,6 +2241,41 @@ var AnnaVoiceClientCore = (function () {
2151
2241
  // user-enabled per-app credentials_grant.
2152
2242
  this.credentials = buildNamespace(this, "credentials");
2153
2243
 
2244
+ // ---- share namespace (v0.28.0; public share links) ----
2245
+ // anna.share.publish({paths, entry, title, description?,
2246
+ // thumbnail_path?, path_map?, expires_at?, pub_id?})
2247
+ // → {pub_id, url, version, entry, title, total_bytes, file_count,
2248
+ // status, expires_at, created_at}
2249
+ // Snapshots finalized APS objects (scope=app self) into a
2250
+ // platform-hosted, long-lived public URL. Passing `pub_id`
2251
+ // republishes (URL unchanged, version += 1).
2252
+ // anna.share.list({cursor?, limit?}) → {items, next_cursor}
2253
+ // anna.share.revoke({pub_id}) — tombstones the URL immediately
2254
+ // (CDN residue <= 5 min) and releases quota bytes.
2255
+ // anna.share.update({pub_id, title?, description?, expires_at?})
2256
+ // — metadata only; never touches the snapshot.
2257
+ // Requires manifest ui.host_api.share = true (second-principal
2258
+ // declaration; design app-public-share-static-hosting.md §5).
2259
+ this.share = buildNamespace(this, "share");
2260
+
2261
+ // ---- conversation namespace (v0.29.0; durable conversations) ----
2262
+ // anna.conversation.list() → {conversations}
2263
+ // anna.conversation.create({name?, zen?, override_model?}) → Conversation
2264
+ // anna.conversation.update({conversation_uuid, name?, is_pinned?,
2265
+ // override_model?, thinking?, pinned_agent_id?, pinned_mentions?})
2266
+ // anna.conversation.delete({conversation_uuid}) → {deleted}
2267
+ // anna.conversation.messages({conversation_uuid, limit?, after_id?})
2268
+ // anna.conversation.send({conversation_uuid, message, attachments?,
2269
+ // executa_ids?, app_ids?, mention_modes?, thinking?}) → AgentRunStream
2270
+ // anna.conversation.attach({stream_id, task_id}) → AgentRunStream
2271
+ // anna.conversation.status({conversation_uuid}) → {task, stream_id}
2272
+ // anna.conversation.cancel({conversation_uuid, task_id, reason?})
2273
+ // anna.conversation.modify({conversation_uuid, task_id, instruction})
2274
+ // anna.conversation.options() → {models, executas, agents, settings}
2275
+ // Requires manifest ui.host_api.conversation = true (second-principal
2276
+ // declaration; design apps/chat.md §5.1).
2277
+ this.conversation = buildConversationNamespace(this);
2278
+
2154
2279
  // ---- mobile namespace (v0.16.0; anna-mobile native bridge) ----
2155
2280
  // anna.mobile.share({title?, text?, url?, filename?, data_url?})
2156
2281
  // → {shared} (user cancel = {shared:false}, not an error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anna-ai/app-runtime",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "description": "Anna App browser runtime SDK. Loaded by every Anna App iframe; provides typed proxy over the postMessage RPC bridge to the host (Anna dashboard / `anna-app dev` harness).",
5
5
  "license": "MIT",
6
6
  "type": "module",