@anna-ai/app-runtime 0.28.0 → 0.30.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 +57 -1
  2. package/dist/index.js +154 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -49,7 +49,8 @@ anna.on("entry_payload", (p) => console.log(p));
49
49
 
50
50
  Every method is available to an installed App — there is no manifest ACL.
51
51
  Only `credentials.*` (declared provider ids), `share.*`
52
- (`ui.host_api.share = true`), cross-boundary `storage.*`
52
+ (`ui.host_api.share = true`), `conversation.*`
53
+ (`ui.host_api.conversation = true`), cross-boundary `storage.*`
53
54
  scopes (`manifest.storage.scopes`) and host-kit agent tools
54
55
  (`ui.host_api.agent.tools`) consult the manifest.
55
56
 
@@ -75,6 +76,7 @@ const out = await anna.image.generate(
75
76
  | `agent.*` | 300 s | `session.run` loops model + tools many turns |
76
77
  | `llm.*` | 180 s | Long completions / large context |
77
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) |
78
80
  | everything else | 30 s | storage / chat / window / prefs / fs / tools / artifact |
79
81
 
80
82
  The timeout is a *client-side* deadline. The host bridge fetch has no
@@ -93,6 +95,28 @@ The bundle author writes the same
93
95
  `import { AnnaAppRuntime } from "/static/anna-apps/_sdk/latest/index.js"`
94
96
  either way; the URL is part of the host contract.
95
97
 
98
+ ### Loading the exact build the host runs
99
+
100
+ `latest` is a mutable alias: a browser or CDN that still holds an older copy
101
+ can hand your app an SDK that predates the host's (missing namespaces). The
102
+ production host therefore also names the exact build in the iframe URL, as the
103
+ `sdk` query parameter — a content-addressed path such as
104
+ `/static/anna-apps/_sdk/0.29.0/index.js?v=44987f881836`. That address changes
105
+ whenever the SDK does, so no cache can return a stale file. Prefer it, and keep
106
+ `latest` as the fallback for hosts that do not send it (`anna-app dev`, older
107
+ nexus):
108
+
109
+ ```js
110
+ const LATEST = "/static/anna-apps/_sdk/latest/index.js";
111
+ const PINNED = /^\/static\/anna-apps\/_sdk\/[\w.-]+\/index\.js(\?v=[0-9a-f]+)?$/;
112
+
113
+ const named = new URLSearchParams(location.search).get("sdk");
114
+ const { AnnaAppRuntime } = await import(named && PINNED.test(named) ? named : LATEST);
115
+ ```
116
+
117
+ Validate the value as above: it is read from the URL, so accept nothing but
118
+ the host's own SDK path.
119
+
96
120
  ## Versioning
97
121
 
98
122
  This package's version tracks `dispatcher_version` (wire protocol). See
@@ -105,6 +129,38 @@ Single file `dist/index.js`. Native ES module (ends in
105
129
  `export { AnnaAppRuntime, ... }`), no build step, runs directly in any modern
106
130
  browser via `<script type="module">` / `import`.
107
131
 
132
+ ## Durable conversations (v0.29.0)
133
+
134
+ `anna.conversation.*` gives an App the user's long-lived conversations: memory,
135
+ persona, persisted history and the full main-conversation tool surface.
136
+ Conversations are isolated per App. Requires
137
+ `manifest.ui.host_api.conversation = true` (otherwise
138
+ `conversation_not_declared`) and a host with dispatcher ≥ 0.36.0.
139
+
140
+ ```js
141
+ const { conversations } = await anna.conversation.list();
142
+ const main = conversations.find((c) => c.is_default);
143
+
144
+ const stream = anna.conversation.send({
145
+ conversation_uuid: main.uuid,
146
+ message: "Summarise my notes from yesterday",
147
+ });
148
+ const run = await stream.ready; // {task_id, stream_id} | null
149
+ for await (const frame of stream) {
150
+ if (frame.event === "error") { /* publisher-level: {code, message} */ }
151
+ else if (frame.error) { /* in-run: {event:"sse", error, error_type} */ }
152
+ else if (frame.choices) { /* OpenAI-style delta, same as the main chat */ }
153
+ }
154
+ // Always reload the persisted history after a run that errored or recovered.
155
+ const { messages } = await anna.conversation.messages({ conversation_uuid: main.uuid });
156
+ ```
157
+
158
+ Recovery after a refresh: `anna.conversation.status({conversation_uuid})`
159
+ returns `{task, stream_id}`. With a `stream_id`, resume with
160
+ `anna.conversation.attach({stream_id, task_id})` (replays from seq 0, dedups
161
+ against live frames). Without one — the run was started outside the Host API
162
+ or is older than 1 h — poll `status` and reload `messages` when it finishes.
163
+
108
164
  ## Agent run output cap & truncation (v0.26.0)
109
165
 
110
166
  Host ≥ 1.1.0-beta.200 / dispatcher 0.30.0 (forum #403). The per-call output
package/dist/index.js CHANGED
@@ -1,5 +1,40 @@
1
1
  /**
2
- * Anna App Runtime SDK — v0.28.0
2
+ * Anna App Runtime SDK — v0.30.0
3
+ *
4
+ * v0.30.0 — Cross-user messaging (design: docs/design/apps/chat-e2ee.md §6;
5
+ * dispatcher 0.37.0, schema 0.37.0, anna-app-core 0.32.0). Additive:
6
+ * - `anna.peers.me/lookup/block/report`, `anna.peers.keys.publish`,
7
+ * `anna.peers.channel.open/list/respond/leave/append/read` — exchange
8
+ * opaque events with the same App under another user's account. The
9
+ * platform stores and relays bytes it never parses (`body` / `public`
10
+ * are standard base64 on the wire).
11
+ * - `anna.peers.onEvent(fn)` — `{channel_uuid, type, seq}` hints
12
+ * (`type` is "event" or "channel"). Hints are best-effort and carry no
13
+ * content: pull with `channel.read` / `channel.list`, and poll as a
14
+ * fallback. Returns an unsubscribe function.
15
+ * Requires manifest `ui.host_api.peers = true`.
16
+ *
17
+ * v0.29.0 — Durable conversations (design: docs/design/apps/chat.md §5;
18
+ * dispatcher 0.36.0, schema 0.36.0, anna-app-core 0.31.0). Additive:
19
+ * - `anna.conversation.list/create/update/delete/messages/status/cancel/
20
+ * modify/options` — thin RPC wrappers over the user's long-lived
21
+ * conversations (memory, persona, persisted history, the full
22
+ * main-conversation tool surface), isolated per App.
23
+ * - `anna.conversation.send({conversation_uuid, message, ...})` →
24
+ * `AgentRunStream` (same class as `AgentSession.run`); `stream.runId` is
25
+ * the `task_id`, `stream.ready` resolves to `{task_id, stream_id}` once
26
+ * the run is enqueued (null when the RPC was rejected — the rejection is
27
+ * delivered as an `{event:"error", code, message}` frame).
28
+ * - `anna.conversation.attach({stream_id, task_id})` → `AgentRunStream`
29
+ * that replays the stream from seq 0 via `agent.session.frames` while
30
+ * receiving live frames (seq dedup) — refresh / reconnect recovery.
31
+ * Frames are the main-conversation events merged with `{event}`; handle
32
+ * both error shapes: `{event:"error", code, message}` (publisher level) and
33
+ * `{event:"sse", error, error_type}` (in-run). Status frames (`queued`,
34
+ * `started`, `keepalive`) may be absent.
35
+ * Requires manifest `ui.host_api.conversation = true`; otherwise
36
+ * `conversation_not_declared`. Hosts older than dispatcher 0.36.0 reply
37
+ * `unknown_method`.
3
38
  *
4
39
  * v0.28.0 — Public share links (design:
5
40
  * docs/design/app-public-share-static-hosting.md; dispatcher 0.34.0,
@@ -460,6 +495,10 @@
460
495
  // the public prefix before returning; list/revoke/update are quick but
461
496
  // share the namespace default.
462
497
  share: 120000,
498
+ // `conversation.send` resolves only after the run is enqueued — model
499
+ // resolution, quota checks and (agent mode) waking a suspended Cloud
500
+ // Agent happen first. The other methods are quick but share the default.
501
+ conversation: 120000,
463
502
  // `web.*` — search is usually <5s but fetch crawls up to 10 pages with
464
503
  // a 30s per-page budget under host-side concurrency limits. Apps doing
465
504
  // large fetch batches should pass { timeoutMs: 90000 } per call.
@@ -1838,6 +1877,81 @@ var AnnaVoiceClientCore = (function () {
1838
1877
  );
1839
1878
  }
1840
1879
 
1880
+ // ---- peers namespace (v0.30.0; cross-user messaging) ----
1881
+ //
1882
+ // Thin RPC wrappers; the nested `keys.*` / `channel.*` methods map to wire
1883
+ // methods `peers/keys.<m>` / `peers/channel.<m>`.
1884
+ function buildPeersNamespace(rt) {
1885
+ const rpc = (method) => (args, opts) =>
1886
+ rt.call("peers", method, args || {}, opts);
1887
+ const group = (prefix, methods) =>
1888
+ Object.fromEntries(methods.map((m) => [m, rpc(prefix + "." + m)]));
1889
+ return {
1890
+ me: rpc("me"),
1891
+ lookup: rpc("lookup"),
1892
+ block: rpc("block"),
1893
+ report: rpc("report"),
1894
+ keys: group("keys", ["publish"]),
1895
+ channel: group("channel", [
1896
+ "open", "list", "respond", "leave", "append", "read",
1897
+ ]),
1898
+ onEvent: (fn) => rt.on("peers", fn),
1899
+ };
1900
+ }
1901
+
1902
+ // ---- conversation namespace (v0.29.0; durable conversations) ----
1903
+ //
1904
+ // `send` / `attach` reuse AgentRunStream unchanged: frames arrive as
1905
+ // `rpc.stream` events keyed by stream_id and are replayable through
1906
+ // `agent.session.frames` (which addresses streams, not session kinds).
1907
+ const CONVERSATION_RPCS = [
1908
+ "list", "create", "update", "delete", "messages",
1909
+ "status", "cancel", "modify", "options",
1910
+ ];
1911
+ function buildConversationNamespace(rt) {
1912
+ const ns = {};
1913
+ for (const method of CONVERSATION_RPCS) {
1914
+ ns[method] = (args, opts) =>
1915
+ rt.call("conversation", method, args || {}, opts);
1916
+ }
1917
+ ns.send = (args = {}) => {
1918
+ // `firstFrameTimeoutMs` is SDK-local — strip it from the wire args.
1919
+ const { firstFrameTimeoutMs, ...sendArgs } = args || {};
1920
+ const stream = new AgentRunStream(null, null);
1921
+ stream.ready = rt.call("conversation", "send", sendArgs).then(
1922
+ (res) => {
1923
+ stream.streamId = (res && res.stream_id) || null;
1924
+ stream.runId = (res && res.task_id) || null;
1925
+ if (!stream.streamId) {
1926
+ stream._emit(null, true);
1927
+ } else {
1928
+ rt._registerStream(stream.streamId, stream);
1929
+ stream._armPollFallback(rt, firstFrameTimeoutMs);
1930
+ }
1931
+ return { task_id: stream.runId, stream_id: stream.streamId };
1932
+ },
1933
+ (err) => {
1934
+ stream._emit({ event: "error", code: err.code, message: err.message }, true);
1935
+ return null;
1936
+ }
1937
+ );
1938
+ return stream;
1939
+ };
1940
+ ns.attach = (info = {}) => {
1941
+ const stream = new AgentRunStream(info.stream_id || null, info.task_id || null);
1942
+ stream.ready = Promise.resolve({ task_id: stream.runId, stream_id: stream.streamId });
1943
+ if (!stream.streamId) {
1944
+ stream._emit(null, true);
1945
+ return stream;
1946
+ }
1947
+ stream._rt = rt;
1948
+ rt._registerStream(stream.streamId, stream);
1949
+ stream._pollLoop();
1950
+ return stream;
1951
+ };
1952
+ return ns;
1953
+ }
1954
+
1841
1955
  // ---- HTTP-backed namespaces removed in v0.4.0 ----
1842
1956
  //
1843
1957
  // `anna.image.*` and `anna.upload.*` are now plain postMessage RPCs
@@ -2179,6 +2293,45 @@ var AnnaVoiceClientCore = (function () {
2179
2293
  // declaration; design app-public-share-static-hosting.md §5).
2180
2294
  this.share = buildNamespace(this, "share");
2181
2295
 
2296
+ // ---- conversation namespace (v0.29.0; durable conversations) ----
2297
+ // anna.conversation.list() → {conversations}
2298
+ // anna.conversation.create({name?, zen?, override_model?}) → Conversation
2299
+ // anna.conversation.update({conversation_uuid, name?, is_pinned?,
2300
+ // override_model?, thinking?, pinned_agent_id?, pinned_mentions?})
2301
+ // anna.conversation.delete({conversation_uuid}) → {deleted}
2302
+ // anna.conversation.messages({conversation_uuid, limit?, after_id?})
2303
+ // anna.conversation.send({conversation_uuid, message, attachments?,
2304
+ // executa_ids?, app_ids?, mention_modes?, thinking?}) → AgentRunStream
2305
+ // anna.conversation.attach({stream_id, task_id}) → AgentRunStream
2306
+ // anna.conversation.status({conversation_uuid}) → {task, stream_id}
2307
+ // anna.conversation.cancel({conversation_uuid, task_id, reason?})
2308
+ // anna.conversation.modify({conversation_uuid, task_id, instruction})
2309
+ // anna.conversation.options() → {models, executas, agents, settings}
2310
+ // Requires manifest ui.host_api.conversation = true (second-principal
2311
+ // declaration; design apps/chat.md §5.1).
2312
+ this.conversation = buildConversationNamespace(this);
2313
+
2314
+ // ---- peers namespace (v0.30.0; cross-user messaging) ----
2315
+ // anna.peers.me() → {username, display_name, avatar_url, public,
2316
+ // key_updated_at}
2317
+ // anna.peers.lookup({username}) → same shape; exact match only
2318
+ // anna.peers.keys.publish({public}) → {key_updated_at}
2319
+ // anna.peers.channel.open({username}) → Channel
2320
+ // anna.peers.channel.list() → {channels}
2321
+ // anna.peers.channel.respond({channel_uuid, accept}) → Channel
2322
+ // anna.peers.channel.leave({channel_uuid}) → {left}
2323
+ // anna.peers.channel.append({channel_uuid, client_msg_id, body})
2324
+ // → {seq, created_at}; idempotent on client_msg_id
2325
+ // anna.peers.channel.read({channel_uuid, after_seq?, before_seq?,
2326
+ // limit?}) → {events, last_seq}
2327
+ // anna.peers.block({username, blocked}) → {blocked}
2328
+ // anna.peers.report({channel_uuid, reason, evidence?}) → {reported}
2329
+ // anna.peers.onEvent(fn) → unsubscribe; fn({channel_uuid, type, seq})
2330
+ // `body` / `public` are opaque bytes (standard base64) the platform
2331
+ // never parses. Requires manifest ui.host_api.peers = true
2332
+ // (second-principal declaration; design apps/chat-e2ee.md §6.1).
2333
+ this.peers = buildPeersNamespace(this);
2334
+
2182
2335
  // ---- mobile namespace (v0.16.0; anna-mobile native bridge) ----
2183
2336
  // anna.mobile.share({title?, text?, url?, filename?, data_url?})
2184
2337
  // → {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.28.0",
3
+ "version": "0.30.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",