@anna-ai/app-runtime 0.4.2 → 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.
- package/README.md +22 -7
- package/dist/index.js +50 -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,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anna App Runtime SDK — v0.
|
|
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,
|
|
@@ -71,6 +94,10 @@
|
|
|
71
94
|
// Apps requesting longer per call must pass { timeoutMs }; bounded
|
|
72
95
|
// server-side by ANNA_APP_TOOLS_INVOKE_TIMEOUT_MAX_MS.
|
|
73
96
|
tools: 70000,
|
|
97
|
+
// `files.*` covers R2 presign + DB write (upload_init/finalize); the
|
|
98
|
+
// browser→R2 PUT itself is direct (not via this SDK), but the host
|
|
99
|
+
// round-trip for finalize needs DB+R2 head ~ up to a few seconds.
|
|
100
|
+
files: 60000,
|
|
74
101
|
};
|
|
75
102
|
const DEFAULT_TIMEOUT_MS = 30000;
|
|
76
103
|
|
|
@@ -120,9 +147,22 @@
|
|
|
120
147
|
};
|
|
121
148
|
// Also expose raw RPC sub-methods on the function — apps can do
|
|
122
149
|
// `anna.agent.session.create(...)` if they want to manage state manually.
|
|
123
|
-
|
|
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"]) {
|
|
124
153
|
ns.session[m] = sessionRpcs[m];
|
|
125
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
|
+
};
|
|
126
166
|
return ns;
|
|
127
167
|
}
|
|
128
168
|
|
|
@@ -288,6 +328,14 @@
|
|
|
288
328
|
this.image = buildNamespace(this, "image");
|
|
289
329
|
this.upload = buildNamespace(this, "upload");
|
|
290
330
|
|
|
331
|
+
// ---- files namespace (APS object/blob API; v0.5.x) ----
|
|
332
|
+
// anna.files.upload_init({path, content_type, size, ttl_seconds?, metadata?, tags?, if_match?})
|
|
333
|
+
// anna.files.upload_finalize({path, etag, size_bytes, metadata?})
|
|
334
|
+
// anna.files.download_url({path, ttl_seconds?, disposition?})
|
|
335
|
+
// anna.files.list({prefix?, cursor?, limit?})
|
|
336
|
+
// anna.files.delete({path, if_match?})
|
|
337
|
+
this.files = buildNamespace(this, "files");
|
|
338
|
+
|
|
291
339
|
// Reassembly buffers for `rpc.stream` events. Map<stream_id, AgentRunStream>.
|
|
292
340
|
this._streams = new Map();
|
|
293
341
|
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.
|
|
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",
|