@anna-ai/app-runtime 0.5.0 → 0.8.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.
- package/README.md +22 -7
- package/dist/index.js +86 -2
- 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.
|
|
4
|
-
App iframe;
|
|
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="
|
|
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
|
|
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
|
|
87
|
-
directly in any modern
|
|
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,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anna App Runtime SDK — v0.
|
|
2
|
+
* Anna App Runtime SDK — v0.8.0
|
|
3
|
+
*
|
|
4
|
+
* v0.8.0 — Adds `anna.agent.session.refresh(args)` plus the same `.refresh()`
|
|
5
|
+
* sugar on the AgentSession handle, and surfaces session lifecycle metadata
|
|
6
|
+
* (`expires_at`, `max_lifetime_at`, `idle_ttl_seconds`, `session_expires_in`)
|
|
7
|
+
* on every AgentSession. `refresh` re-mints the short-lived capability token
|
|
8
|
+
* for an EXISTING session (by `app_session_uuid`) AND slides its idle window,
|
|
9
|
+
* so a session survives long idle gaps, iframe reloads and host restarts:
|
|
10
|
+
* await anna.agent.session.refresh({ app_session_uuid }) // raw RPC
|
|
11
|
+
* await sess.refresh() // handle sugar
|
|
12
|
+
* `refresh` is identity-authed (it does NOT require a live token), which is
|
|
13
|
+
* what lets it recover a session whose token already lapsed
|
|
14
|
+
* (`APP_SESSION_TOKEN_EXPIRED`). It fails with `APP_SESSION_EXPIRED` /
|
|
15
|
+
* `APP_SESSION_REVOKED` only when the underlying session is genuinely gone.
|
|
16
|
+
* The handle's lifecycle fields are refreshed in place from the response.
|
|
17
|
+
* Coordinated bump: wire method `agent/session.refresh` —
|
|
18
|
+
* dispatcher_version 0.10.0 + schema 0.10.0 + anna-app-core 0.9.0.
|
|
19
|
+
* Additive: old hosts return `-32601 Method not found`.
|
|
20
|
+
*
|
|
21
|
+
* v0.7.0 — Adds `anna.agent.session.attach(app_session_uuid)` — returns an
|
|
22
|
+
* AgentSession handle bound to an EXISTING session you already know the
|
|
23
|
+
* uuid of (e.g. one returned by `anna.agent.session.list()` after an
|
|
24
|
+
* iframe reload / in another tab). Unlike `anna.agent.session(opts)` it
|
|
25
|
+
* does NOT mint a new session — it is a pure client-side wrapper, so
|
|
26
|
+
* there is no new wire method and no dispatcher/schema change. The
|
|
27
|
+
* returned handle exposes the same streaming `.run()`, `.cancel()`,
|
|
28
|
+
* `.history()`, `.delete()` sugar over the existing `agent.session.*`
|
|
29
|
+
* RPCs (all of which are keyed by `app_session_uuid`). Accepts either a
|
|
30
|
+
* bare uuid string or a `{ app_session_uuid, ... }` info object (e.g. a
|
|
31
|
+
* row from `list()`), which also seeds submode/label metadata.
|
|
32
|
+
*
|
|
33
|
+
* v0.6.0 — Adds `anna.agent.session.list(args)` — account/app-scoped
|
|
34
|
+
* enumeration of the current app's active agent sessions. Lives only on
|
|
35
|
+
* the `agent.session` namespace (raw RPC), NOT on the per-session
|
|
36
|
+
* AgentSession wrapper, since it returns a list across sessions. Args:
|
|
37
|
+
* { include_expired?: boolean, limit?: number (1-100, default 50) }
|
|
38
|
+
* Returns { sessions: [{ app_session_uuid, kind, submode,
|
|
39
|
+
* fixed_client_id, label, created_at, last_active_at, expires_at }] }.
|
|
40
|
+
* Lets an app re-attach to / clean up sessions after an iframe reload or
|
|
41
|
+
* crash. Coordinated bump: dispatcher_version 0.9.0 + schema 0.9.0 +
|
|
42
|
+
* anna-app-core 0.8.0. No breaking changes.
|
|
3
43
|
*
|
|
4
44
|
* v0.4.1 — Per-namespace default RPC timeouts and per-call override.
|
|
5
45
|
* image.* / upload.* / agent.* / llm.* used to share the 30s default,
|
|
@@ -124,9 +164,24 @@
|
|
|
124
164
|
};
|
|
125
165
|
// Also expose raw RPC sub-methods on the function — apps can do
|
|
126
166
|
// `anna.agent.session.create(...)` if they want to manage state manually.
|
|
127
|
-
|
|
167
|
+
// `list` is account/app-scoped (enumerate this app's sessions), so it
|
|
168
|
+
// lives only here, not on the per-session AgentSession wrapper. `refresh`
|
|
169
|
+
// is identity-authed (re-mints token + slides idle window by uuid) and is
|
|
170
|
+
// also exposed as `.refresh()` sugar on the AgentSession handle.
|
|
171
|
+
for (const m of ["create", "run", "cancel", "history", "delete", "list", "refresh"]) {
|
|
128
172
|
ns.session[m] = sessionRpcs[m];
|
|
129
173
|
}
|
|
174
|
+
// `attach` re-wraps an EXISTING session (known uuid) as an AgentSession
|
|
175
|
+
// handle WITHOUT minting a new one — pure client-side, no RPC. Accepts a
|
|
176
|
+
// bare uuid string or an info object (e.g. a row from `list()`).
|
|
177
|
+
ns.session.attach = (info) => {
|
|
178
|
+
const norm =
|
|
179
|
+
typeof info === "string" ? { app_session_uuid: info } : info || {};
|
|
180
|
+
if (!norm.app_session_uuid) {
|
|
181
|
+
throw new Error("agent.session.attach: app_session_uuid is required");
|
|
182
|
+
}
|
|
183
|
+
return new AgentSession(rt, norm);
|
|
184
|
+
};
|
|
130
185
|
return ns;
|
|
131
186
|
}
|
|
132
187
|
|
|
@@ -209,6 +264,24 @@
|
|
|
209
264
|
this.submode = info.submode;
|
|
210
265
|
this.fixed_client_id = info.fixed_client_id || null;
|
|
211
266
|
this.granted_tools = info.granted_tools || [];
|
|
267
|
+
// Lifecycle metadata (v0.8.0). `expires_at` is the authoritative idle
|
|
268
|
+
// deadline; `max_lifetime_at` is the absolute cap; `idle_ttl_seconds` is
|
|
269
|
+
// how far each activity slides the window; `session_expires_in` is the
|
|
270
|
+
// seconds-until-`expires_at` snapshot at mint/refresh time. All are
|
|
271
|
+
// refreshed in place by `.refresh()`.
|
|
272
|
+
this._applyLifecycle(info);
|
|
273
|
+
}
|
|
274
|
+
// Copy lifecycle fields from a create/refresh response onto the handle.
|
|
275
|
+
_applyLifecycle(info) {
|
|
276
|
+
if (info == null) return;
|
|
277
|
+
if ("expires_in" in info) this.expires_in = info.expires_in;
|
|
278
|
+
this.expires_at = info.expires_at ?? this.expires_at ?? null;
|
|
279
|
+
this.max_lifetime_at =
|
|
280
|
+
info.max_lifetime_at ?? this.max_lifetime_at ?? null;
|
|
281
|
+
this.idle_ttl_seconds =
|
|
282
|
+
info.idle_ttl_seconds ?? this.idle_ttl_seconds ?? null;
|
|
283
|
+
this.session_expires_in =
|
|
284
|
+
info.session_expires_in ?? this.session_expires_in ?? null;
|
|
212
285
|
}
|
|
213
286
|
run(opts = {}) {
|
|
214
287
|
const args = Object.assign(
|
|
@@ -243,6 +316,17 @@
|
|
|
243
316
|
{ app_session_uuid: this.app_session_uuid }, opts
|
|
244
317
|
));
|
|
245
318
|
}
|
|
319
|
+
// Re-mint the capability token AND slide the idle window for this session.
|
|
320
|
+
// Identity-authed — works even if the previous token already lapsed
|
|
321
|
+
// (recovers from APP_SESSION_TOKEN_EXPIRED). Updates the handle's
|
|
322
|
+
// lifecycle fields in place from the response and returns it.
|
|
323
|
+
async refresh(opts = {}) {
|
|
324
|
+
const res = await this._rt.call("agent", "session.refresh", Object.assign(
|
|
325
|
+
{ app_session_uuid: this.app_session_uuid }, opts
|
|
326
|
+
));
|
|
327
|
+
this._applyLifecycle(res || {});
|
|
328
|
+
return res;
|
|
329
|
+
}
|
|
246
330
|
delete() {
|
|
247
331
|
return this._rt.call("agent", "session.delete", {
|
|
248
332
|
app_session_uuid: this.app_session_uuid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anna-ai/app-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|