@anna-ai/app-runtime 0.28.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 +35 -1
  2. package/dist/index.js +98 -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
@@ -105,6 +107,38 @@ Single file `dist/index.js`. Native ES module (ends in
105
107
  `export { AnnaAppRuntime, ... }`), no build step, runs directly in any modern
106
108
  browser via `<script type="module">` / `import`.
107
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
+
108
142
  ## Agent run output cap & truncation (v0.26.0)
109
143
 
110
144
  Host ≥ 1.1.0-beta.200 / dispatcher 0.30.0 (forum #403). The per-call output
package/dist/index.js CHANGED
@@ -1,5 +1,27 @@
1
1
  /**
2
- * Anna App Runtime SDK — v0.28.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`.
3
25
  *
4
26
  * v0.28.0 — Public share links (design:
5
27
  * docs/design/app-public-share-static-hosting.md; dispatcher 0.34.0,
@@ -460,6 +482,10 @@
460
482
  // the public prefix before returning; list/revoke/update are quick but
461
483
  // share the namespace default.
462
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,
463
489
  // `web.*` — search is usually <5s but fetch crawls up to 10 pages with
464
490
  // a 30s per-page budget under host-side concurrency limits. Apps doing
465
491
  // large fetch batches should pass { timeoutMs: 90000 } per call.
@@ -1838,6 +1864,59 @@ var AnnaVoiceClientCore = (function () {
1838
1864
  );
1839
1865
  }
1840
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
+
1841
1920
  // ---- HTTP-backed namespaces removed in v0.4.0 ----
1842
1921
  //
1843
1922
  // `anna.image.*` and `anna.upload.*` are now plain postMessage RPCs
@@ -2179,6 +2258,24 @@ var AnnaVoiceClientCore = (function () {
2179
2258
  // declaration; design app-public-share-static-hosting.md §5).
2180
2259
  this.share = buildNamespace(this, "share");
2181
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
+
2182
2279
  // ---- mobile namespace (v0.16.0; anna-mobile native bridge) ----
2183
2280
  // anna.mobile.share({title?, text?, url?, filename?, data_url?})
2184
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.28.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",