@anna-ai/app-runtime 0.5.0 → 0.7.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 +22 -7
  2. package/dist/index.js +38 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,27 @@
1
1
  # @anna-ai/app-runtime
2
2
 
3
- Browser runtime SDK for Anna Apps. Loaded as a `<script>` inside every Anna
4
- App iframe; exposes a global `AnnaAppRuntime` that proxies RPC calls over
3
+ Browser runtime SDK for Anna Apps. A native ES module imported by every Anna
4
+ App iframe; exports `AnnaAppRuntime`, which proxies RPC calls over
5
5
  `postMessage` to the host page (Anna dashboard in production, the
6
6
  `anna-app dev` harness in local development).
7
7
 
8
+ > **0.3.1+**: the SDK is a pure ES module. Load it with
9
+ > `<script type="module">` + `import { AnnaAppRuntime } from "…"`. The old
10
+ > classic `<script src>` + `window.AnnaAppRuntime` global is removed.
11
+
8
12
  ## Use inside an Anna App bundle
9
13
 
14
+ Make your entry script a module and import the SDK directly:
15
+
10
16
  ```html
11
17
  <!-- index.html -->
12
- <script src="/static/anna-apps/_sdk/0.1.0/index.js" defer></script>
13
- <script src="./app.js" type="module" defer></script>
18
+ <script src="./app.js" type="module"></script>
14
19
  ```
15
20
 
16
21
  ```js
17
22
  // app.js
23
+ import { AnnaAppRuntime } from "/static/anna-apps/_sdk/latest/index.js";
24
+
18
25
  const anna = await AnnaAppRuntime.connect();
19
26
 
20
27
  await anna.window.set_title({ title: "My App" });
@@ -28,6 +35,12 @@ const out = await anna.tools.invoke({
28
35
  anna.on("entry_payload", (p) => console.log(p));
29
36
  ```
30
37
 
38
+ > **Don't use inline `<script>`.** The bundle CSP is
39
+ > `script-src 'self' <sdk-origin>` with no `unsafe-inline`/nonce, so any
40
+ > inline script (including an inline module that bridges the SDK to a
41
+ > global) is blocked. Always make your entry an **external** module
42
+ > (`<script src="app.js" type="module">`) and `import` the SDK inside it.
43
+
31
44
  ## Wire envelope
32
45
 
33
46
  ```
@@ -72,7 +85,8 @@ and the eventual response is discarded.
72
85
  | Production (Anna dashboard) | `matrix-nexus` static server, path `/static/anna-apps/_sdk/<version>/index.js` |
73
86
  | Local dev (`anna-app dev`) | `@anna-ai/cli` harness server resolves this package from its `node_modules` and serves the same path |
74
87
 
75
- The bundle author writes the same `<script src="/static/anna-apps/_sdk/...">`
88
+ The bundle author writes the same
89
+ `import { AnnaAppRuntime } from "/static/anna-apps/_sdk/latest/index.js"`
76
90
  either way; the URL is part of the host contract.
77
91
 
78
92
  ## Versioning
@@ -83,5 +97,6 @@ procedure.
83
97
 
84
98
  ## Contents
85
99
 
86
- Single file `dist/index.js` (~8 KB). Plain ES5 IIFE, no build step, runs
87
- directly in any modern browser.
100
+ Single file `dist/index.js`. Native ES module (ends in
101
+ `export { AnnaAppRuntime, ... }`), no build step, runs directly in any modern
102
+ browser via `<script type="module">` / `import`.
package/dist/index.js CHANGED
@@ -1,5 +1,28 @@
1
1
  /**
2
- * Anna App Runtime SDK — v0.4.1
2
+ * Anna App Runtime SDK — v0.7.0
3
+ *
4
+ * v0.7.0 — Adds `anna.agent.session.attach(app_session_uuid)` — returns an
5
+ * AgentSession handle bound to an EXISTING session you already know the
6
+ * uuid of (e.g. one returned by `anna.agent.session.list()` after an
7
+ * iframe reload / in another tab). Unlike `anna.agent.session(opts)` it
8
+ * does NOT mint a new session — it is a pure client-side wrapper, so
9
+ * there is no new wire method and no dispatcher/schema change. The
10
+ * returned handle exposes the same streaming `.run()`, `.cancel()`,
11
+ * `.history()`, `.delete()` sugar over the existing `agent.session.*`
12
+ * RPCs (all of which are keyed by `app_session_uuid`). Accepts either a
13
+ * bare uuid string or a `{ app_session_uuid, ... }` info object (e.g. a
14
+ * row from `list()`), which also seeds submode/label metadata.
15
+ *
16
+ * v0.6.0 — Adds `anna.agent.session.list(args)` — account/app-scoped
17
+ * enumeration of the current app's active agent sessions. Lives only on
18
+ * the `agent.session` namespace (raw RPC), NOT on the per-session
19
+ * AgentSession wrapper, since it returns a list across sessions. Args:
20
+ * { include_expired?: boolean, limit?: number (1-100, default 50) }
21
+ * Returns { sessions: [{ app_session_uuid, kind, submode,
22
+ * fixed_client_id, label, created_at, last_active_at, expires_at }] }.
23
+ * Lets an app re-attach to / clean up sessions after an iframe reload or
24
+ * crash. Coordinated bump: dispatcher_version 0.9.0 + schema 0.9.0 +
25
+ * anna-app-core 0.8.0. No breaking changes.
3
26
  *
4
27
  * v0.4.1 — Per-namespace default RPC timeouts and per-call override.
5
28
  * image.* / upload.* / agent.* / llm.* used to share the 30s default,
@@ -124,9 +147,22 @@
124
147
  };
125
148
  // Also expose raw RPC sub-methods on the function — apps can do
126
149
  // `anna.agent.session.create(...)` if they want to manage state manually.
127
- for (const m of ["create", "run", "cancel", "history", "delete"]) {
150
+ // `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"]) {
128
153
  ns.session[m] = sessionRpcs[m];
129
154
  }
155
+ // `attach` re-wraps an EXISTING session (known uuid) as an AgentSession
156
+ // handle WITHOUT minting a new one — pure client-side, no RPC. Accepts a
157
+ // bare uuid string or an info object (e.g. a row from `list()`).
158
+ ns.session.attach = (info) => {
159
+ const norm =
160
+ typeof info === "string" ? { app_session_uuid: info } : info || {};
161
+ if (!norm.app_session_uuid) {
162
+ throw new Error("agent.session.attach: app_session_uuid is required");
163
+ }
164
+ return new AgentSession(rt, norm);
165
+ };
130
166
  return ns;
131
167
  }
132
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anna-ai/app-runtime",
3
- "version": "0.5.0",
3
+ "version": "0.7.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",