@anna-ai/app-runtime 0.7.0 → 0.10.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 (2) hide show
  1. package/dist/index.js +176 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,50 @@
1
1
  /**
2
- * Anna App Runtime SDK — v0.7.0
2
+ * Anna App Runtime SDK — v0.10.0
3
+ *
4
+ * v0.10.0 — Adds `anna.llm.stream(req)` — streaming L1 completion. Takes the
5
+ * SAME request shape as `anna.llm.complete(req)` but returns an
6
+ * AgentRunStream (async-iterable) instead of a single result; the host
7
+ * streams `{event:"model_token", text}` frames followed by a terminal
8
+ * `{event:"complete", role, content, model, stopReason, usage, _meta}` frame
9
+ * over the shared `rpc.stream` topic (same reassembly machinery as
10
+ * `agent.session.run`):
11
+ * for await (const ev of anna.llm.stream({ messages, maxTokens })) {
12
+ * if (ev.event === "model_token") render(ev.text);
13
+ * }
14
+ * Coordinated bump: wire method `llm/stream` — dispatcher_version 0.12.0 +
15
+ * schema 0.12.0 + anna-app-core 0.11.0. Additive: old hosts return
16
+ * `-32601 Method not found` for `llm.stream` (apps should feature-detect
17
+ * and fall back to `llm.complete`).
18
+ *
19
+ * v0.9.0 — Adds the `anna.apps.*` launcher namespace and view `chrome`
20
+ * support. New raw RPCs `apps.list` / `apps.search` / `apps.get` /
21
+ * `apps.launch` browse and open other installed Anna Apps, and the nested
22
+ * `anna.apps.deck.{list,add,remove,reorder}` namespace manages the user's
23
+ * pinned app deck (wire methods `apps/deck.*`). `app_ref` accepts a numeric
24
+ * app id or an `@handle/slug` string. Also surfaces the per-view `chrome`
25
+ * ("solid" | "vibrancy") and `transparent` flags on `viewMeta`, which the
26
+ * host window manager uses to render translucent / transparent chrome.
27
+ * Coordinated bump: wire namespace `apps/*` + manifest `ui.host_api.apps`
28
+ * and `ui.views[].chrome` / `.transparent` — dispatcher_version 0.11.0 +
29
+ * schema 0.11.0 + anna-app-core 0.10.0. Additive: old hosts return
30
+ * `-32601 Method not found` for `apps.*` and ignore `chrome`/`transparent`.
31
+ *
32
+ * v0.8.0 — Adds `anna.agent.session.refresh(args)` plus the same `.refresh()`
33
+ * sugar on the AgentSession handle, and surfaces session lifecycle metadata
34
+ * (`expires_at`, `max_lifetime_at`, `idle_ttl_seconds`, `session_expires_in`)
35
+ * on every AgentSession. `refresh` re-mints the short-lived capability token
36
+ * for an EXISTING session (by `app_session_uuid`) AND slides its idle window,
37
+ * so a session survives long idle gaps, iframe reloads and host restarts:
38
+ * await anna.agent.session.refresh({ app_session_uuid }) // raw RPC
39
+ * await sess.refresh() // handle sugar
40
+ * `refresh` is identity-authed (it does NOT require a live token), which is
41
+ * what lets it recover a session whose token already lapsed
42
+ * (`APP_SESSION_TOKEN_EXPIRED`). It fails with `APP_SESSION_EXPIRED` /
43
+ * `APP_SESSION_REVOKED` only when the underlying session is genuinely gone.
44
+ * The handle's lifecycle fields are refreshed in place from the response.
45
+ * Coordinated bump: wire method `agent/session.refresh` —
46
+ * dispatcher_version 0.10.0 + schema 0.10.0 + anna-app-core 0.9.0.
47
+ * Additive: old hosts return `-32601 Method not found`.
3
48
  *
4
49
  * v0.7.0 — Adds `anna.agent.session.attach(app_session_uuid)` — returns an
5
50
  * AgentSession handle bound to an EXISTING session you already know the
@@ -148,8 +193,10 @@
148
193
  // Also expose raw RPC sub-methods on the function — apps can do
149
194
  // `anna.agent.session.create(...)` if they want to manage state manually.
150
195
  // `list` is account/app-scoped (enumerate this app's sessions), so it
151
- // lives only here, not on the per-session AgentSession wrapper.
152
- for (const m of ["create", "run", "cancel", "history", "delete", "list"]) {
196
+ // lives only here, not on the per-session AgentSession wrapper. `refresh`
197
+ // is identity-authed (re-mints token + slides idle window by uuid) and is
198
+ // also exposed as `.refresh()` sugar on the AgentSession handle.
199
+ for (const m of ["create", "run", "cancel", "history", "delete", "list", "refresh"]) {
153
200
  ns.session[m] = sessionRpcs[m];
154
201
  }
155
202
  // `attach` re-wraps an EXISTING session (known uuid) as an AgentSession
@@ -166,6 +213,95 @@
166
213
  return ns;
167
214
  }
168
215
 
216
+ // ---- LLM namespace (L1) ----
217
+ //
218
+ // `anna.llm.complete(req)` / `anna.llm.embed(req)` are plain RPCs that
219
+ // resolve to a single result. `anna.llm.stream(req)` mirrors
220
+ // `AgentSession.run`: it returns an AgentRunStream (async-iterable) and the
221
+ // host streams `{event:"model_token", text}` frames followed by a terminal
222
+ // `{event:"complete", ...}` frame over the shared `rpc.stream` topic.
223
+ //
224
+ // for await (const ev of anna.llm.stream({ messages, maxTokens })) {
225
+ // if (ev.event === "model_token") render(ev.text);
226
+ // else if (ev.event === "complete") done(ev.content.text);
227
+ // }
228
+ //
229
+ // `stream(req)` takes the SAME request shape as `complete(req)`
230
+ // (`{messages, maxTokens?, temperature?, systemPrompt?, stopSequences?,
231
+ // modelPreferences?, metadata?}`).
232
+ function buildLlmNamespace(rt) {
233
+ return new Proxy(
234
+ {},
235
+ {
236
+ get(_, method) {
237
+ if (typeof method !== "string") return undefined;
238
+ if (method === "stream") {
239
+ return (req = {}) => {
240
+ const stream = new AgentRunStream(null, req.run_id || null);
241
+ rt.call("llm", "stream", req || {}).then(
242
+ (res) => {
243
+ stream.streamId = res.stream_id || stream.streamId;
244
+ stream.runId = res.run_id || stream.runId;
245
+ if (stream.streamId)
246
+ rt._registerStream(stream.streamId, stream);
247
+ // Host returned no stream_id (e.g. cached error) → close.
248
+ if (!stream.streamId) stream._emit(null, true);
249
+ },
250
+ (err) => {
251
+ stream._emit(
252
+ { event: "error", code: err.code, message: err.message },
253
+ true
254
+ );
255
+ }
256
+ );
257
+ return stream;
258
+ };
259
+ }
260
+ return (args, opts) => rt.call("llm", method, args || {}, opts);
261
+ },
262
+ }
263
+ );
264
+ }
265
+
266
+ // ---- Apps namespace (v0.9.0) ----
267
+ //
268
+ // The Apps launcher surface lets an app browse/launch other installed
269
+ // Anna Apps and manage the user's pinned "deck":
270
+ //
271
+ // await anna.apps.list({ search }) // installed apps
272
+ // await anna.apps.search({ q }) // alias of list w/ search
273
+ // await anna.apps.get({ app_ref }) // single card
274
+ // await anna.apps.launch({ app_ref, view, payload }) // open a window
275
+ // await anna.apps.deck.list() // pinned deck
276
+ // await anna.apps.deck.add({ app_ref })
277
+ // await anna.apps.deck.remove({ app_ref })
278
+ // await anna.apps.deck.reorder({ ordered })
279
+ //
280
+ // `app_ref` accepts either a numeric app id or an `@handle/slug` string.
281
+ // The nested `deck.*` methods map to wire methods `apps/deck.<m>`.
282
+ function buildAppsNamespace(rt) {
283
+ const deck = new Proxy(
284
+ {},
285
+ {
286
+ get(_, method) {
287
+ if (typeof method !== "string") return undefined;
288
+ return (args, opts) =>
289
+ rt.call("apps", "deck." + method, args || {}, opts);
290
+ },
291
+ }
292
+ );
293
+ return new Proxy(
294
+ {},
295
+ {
296
+ get(_, method) {
297
+ if (typeof method !== "string") return undefined;
298
+ if (method === "deck") return deck;
299
+ return (args, opts) => rt.call("apps", method, args || {}, opts);
300
+ },
301
+ }
302
+ );
303
+ }
304
+
169
305
  // ---- HTTP-backed namespaces removed in v0.4.0 ----
170
306
  //
171
307
  // `anna.image.*` and `anna.upload.*` are now plain postMessage RPCs
@@ -245,6 +381,24 @@
245
381
  this.submode = info.submode;
246
382
  this.fixed_client_id = info.fixed_client_id || null;
247
383
  this.granted_tools = info.granted_tools || [];
384
+ // Lifecycle metadata (v0.8.0). `expires_at` is the authoritative idle
385
+ // deadline; `max_lifetime_at` is the absolute cap; `idle_ttl_seconds` is
386
+ // how far each activity slides the window; `session_expires_in` is the
387
+ // seconds-until-`expires_at` snapshot at mint/refresh time. All are
388
+ // refreshed in place by `.refresh()`.
389
+ this._applyLifecycle(info);
390
+ }
391
+ // Copy lifecycle fields from a create/refresh response onto the handle.
392
+ _applyLifecycle(info) {
393
+ if (info == null) return;
394
+ if ("expires_in" in info) this.expires_in = info.expires_in;
395
+ this.expires_at = info.expires_at ?? this.expires_at ?? null;
396
+ this.max_lifetime_at =
397
+ info.max_lifetime_at ?? this.max_lifetime_at ?? null;
398
+ this.idle_ttl_seconds =
399
+ info.idle_ttl_seconds ?? this.idle_ttl_seconds ?? null;
400
+ this.session_expires_in =
401
+ info.session_expires_in ?? this.session_expires_in ?? null;
248
402
  }
249
403
  run(opts = {}) {
250
404
  const args = Object.assign(
@@ -279,6 +433,17 @@
279
433
  { app_session_uuid: this.app_session_uuid }, opts
280
434
  ));
281
435
  }
436
+ // Re-mint the capability token AND slide the idle window for this session.
437
+ // Identity-authed — works even if the previous token already lapsed
438
+ // (recovers from APP_SESSION_TOKEN_EXPIRED). Updates the handle's
439
+ // lifecycle fields in place from the response and returns it.
440
+ async refresh(opts = {}) {
441
+ const res = await this._rt.call("agent", "session.refresh", Object.assign(
442
+ { app_session_uuid: this.app_session_uuid }, opts
443
+ ));
444
+ this._applyLifecycle(res || {});
445
+ return res;
446
+ }
282
447
  delete() {
283
448
  return this._rt.call("agent", "session.delete", {
284
449
  app_session_uuid: this.app_session_uuid,
@@ -307,7 +472,7 @@
307
472
  this.tools = buildNamespace(this, "tools");
308
473
  this.chat = buildNamespace(this, "chat");
309
474
  this.artifact = buildNamespace(this, "artifact");
310
- this.llm = buildNamespace(this, "llm");
475
+ this.llm = buildLlmNamespace(this);
311
476
  this.fs = buildNamespace(this, "fs");
312
477
  this.storage = buildNamespace(this, "storage");
313
478
  this.prefs = buildNamespace(this, "prefs");
@@ -336,6 +501,13 @@
336
501
  // anna.files.delete({path, if_match?})
337
502
  this.files = buildNamespace(this, "files");
338
503
 
504
+ // ---- apps namespace (launcher + deck; v0.9.0) ----
505
+ // anna.apps.list({search?}) / search({q}) / get({app_ref}) /
506
+ // launch({app_ref, view?, payload?})
507
+ // anna.apps.deck.list() / add({app_ref}) / remove({app_ref}) /
508
+ // reorder({ordered})
509
+ this.apps = buildAppsNamespace(this);
510
+
339
511
  // Reassembly buffers for `rpc.stream` events. Map<stream_id, AgentRunStream>.
340
512
  this._streams = new Map();
341
513
  this.on("rpc.stream", (payload) => this._onStreamFrame(payload || {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anna-ai/app-runtime",
3
- "version": "0.7.0",
3
+ "version": "0.10.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",