@anna-ai/app-runtime 0.17.0 → 0.20.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 +32 -0
- package/dist/index.js +356 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,3 +100,35 @@ procedure.
|
|
|
100
100
|
Single file `dist/index.js`. Native ES module (ends in
|
|
101
101
|
`export { AnnaAppRuntime, ... }`), no build step, runs directly in any modern
|
|
102
102
|
browser via `<script type="module">` / `import`.
|
|
103
|
+
|
|
104
|
+
## Media generation (v0.20.0)
|
|
105
|
+
|
|
106
|
+
Async video jobs + sync audio, gated by the per-app `media_grant`
|
|
107
|
+
(manifest must declare `ui.host_api.video` / `.audio`):
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
// One-shot sugar: submit + media_job events + getJob polling fallback
|
|
111
|
+
const job = await anna.video.generateAwait(
|
|
112
|
+
{ prompt: "Aerial drone shot over a misty pine forest", durationSec: 5,
|
|
113
|
+
resolution: "768p", clientTag: "scene-3-broll" },
|
|
114
|
+
{ onProgress: (p) => bar.update(p), signal: abortController.signal }
|
|
115
|
+
);
|
|
116
|
+
video.src = job.result.url; // presigned GET, ~30 min TTL
|
|
117
|
+
|
|
118
|
+
// URL expired (403)? Re-sign via getJob:
|
|
119
|
+
const fresh = await anna.video.getJob({ jobId: job.jobId });
|
|
120
|
+
|
|
121
|
+
// Raw job API: generate / getJob / cancelJob / listJobs
|
|
122
|
+
const { jobId, estimatedCostCU } = await anna.video.generate({ prompt: "..." });
|
|
123
|
+
|
|
124
|
+
// Sync TTS / STT
|
|
125
|
+
const speech = await anna.audio.speak({ text: "Welcome!", voice: "Cherry" });
|
|
126
|
+
const { text } = await anna.audio.transcribe({ audioUrl: "https://..." });
|
|
127
|
+
|
|
128
|
+
// Capability discovery: models, parameter space, CU pricing, remaining quota
|
|
129
|
+
const catalog = await anna.llm.catalog({ serviceType: "video_gen" });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Costs are **pre-charged** from the estimate shown in `estimatedCostCU` and
|
|
133
|
+
fully refunded on failure/cancel/expiry. Aborting `generateAwait` cancels
|
|
134
|
+
the job (queued = full refund; running cancel is best-effort).
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Anna App Runtime SDK — v0.
|
|
2
|
+
* Anna App Runtime SDK — v0.20.0
|
|
3
|
+
*
|
|
4
|
+
* v0.20.0 — Media generation surface (design:
|
|
5
|
+
* platform-media-generation-video-audio.md §7/§9/§10).
|
|
6
|
+
* Adds `anna.video.{generate,getJob,cancelJob,listJobs}` (async video
|
|
7
|
+
* jobs; `generate` returns `{jobId, state, estimatedCostCU, deadlineAt}`),
|
|
8
|
+
* `anna.video.generateAwait(args, {onProgress, signal, timeoutMs})` —
|
|
9
|
+
* submit + `media_job` host-event subscription + adaptive `getJob`
|
|
10
|
+
* polling fallback, mirroring `tools.invokeAsyncAwait`; resolves with the
|
|
11
|
+
* terminal job view (`result.url` = presigned GET, ~30 min TTL — re-sign
|
|
12
|
+
* by calling `getJob` again on 403). AbortSignal → `video.cancelJob`
|
|
13
|
+
* (queued = full refund; running cancel is best-effort).
|
|
14
|
+
* Adds `anna.audio.{speak,transcribe}` (sync TTS ≤ model char cap / STT
|
|
15
|
+
* ≤10 min) and `anna.llm.catalog({serviceType?})` capability discovery
|
|
16
|
+
* (models + CU pricing + remaining quota). All gated by the per-app
|
|
17
|
+
* `media_grant`; manifest must declare `ui.host_api.video` / `.audio`.
|
|
18
|
+
* Coordinated versions: dispatcher_version 0.26.0 + schema 0.26.0.
|
|
19
|
+
* Additive: old hosts reject the new namespaces with `unknown_method`.
|
|
20
|
+
*
|
|
21
|
+
* v0.18.0 — Run-recovery pull surface (forum #341 P3: push pairs with pull).
|
|
22
|
+
* Adds `anna.agent.session.runStatus({app_session_uuid, run_id})` →
|
|
23
|
+
* `{status: "queued"|"running"|"completed"|"failed"|"cancelled", task_id,
|
|
24
|
+
* stream_id, started_at?, finished_at?, model?, error?}` (wire method
|
|
25
|
+
* `agent/session.run.status`; also `.runStatus(runId)` sugar on the
|
|
26
|
+
* AgentSession handle) and `anna.agent.session.frames({stream_id,
|
|
27
|
+
* after_seq?, limit?})` → `{frames, complete}` (archived rpc.stream
|
|
28
|
+
* replay; rate limit 30/min/user shared with the dashboard backfill
|
|
29
|
+
* endpoint; ~1h archive window). Check `runStatus` BEFORE re-running a
|
|
30
|
+
* silent stream — `completed` means the run executed and was charged;
|
|
31
|
+
* recover its output via `frames` instead of re-running.
|
|
32
|
+
* `AgentSession.run()` additionally arms an automatic first-frame
|
|
33
|
+
* fallback: if NO frame arrives within `opts.firstFrameTimeoutMs`
|
|
34
|
+
* (default 20s, stripped from the wire args) the stream self-recovers by
|
|
35
|
+
* polling `agent.session.frames` (3s→30s backoff, seq-deduped against
|
|
36
|
+
* late realtime frames) until a `done` frame — a dead realtime leg
|
|
37
|
+
* degrades to "late frames", never "permanent silence".
|
|
38
|
+
* Fix: seq=0 status frames (queued / watchdog terminal) no longer advance
|
|
39
|
+
* the reassembly cursor — previously ONE seq=0 frame silently dropped the
|
|
40
|
+
* first worker frame (started) via an off-by-one in `_push`.
|
|
41
|
+
* Coordinated versions: dispatcher_version 0.24.0 + schema 0.24.0 +
|
|
42
|
+
* anna-app-core 0.22.0. Additive: old hosts reject the new methods with
|
|
43
|
+
* `unknown_method`; the fallback then disarms silently.
|
|
3
44
|
*
|
|
4
45
|
* v0.17.0 — `anna.llm.complete(req)` transparently delivers LONG outputs over
|
|
5
46
|
* the streaming channel: when `req.maxTokens > 8192` (the platform's sync
|
|
@@ -196,6 +237,9 @@
|
|
|
196
237
|
* });
|
|
197
238
|
* await anna.window.set_title({ title: "My App" });
|
|
198
239
|
* anna.on("entry_payload", (p) => console.log(p));
|
|
240
|
+
* // Host pushes `entry_payload` when a single-instance view is re-invoked
|
|
241
|
+
* // with a fresh payload (forum #376); `p` is the full merged payload and
|
|
242
|
+
* // `anna.entryPayload` is refreshed automatically (SDK >= 0.19.0).
|
|
199
243
|
*/
|
|
200
244
|
|
|
201
245
|
// ---- Internals ----
|
|
@@ -498,6 +542,194 @@
|
|
|
498
542
|
);
|
|
499
543
|
}
|
|
500
544
|
|
|
545
|
+
// ---- Video namespace (v0.20.0) ----
|
|
546
|
+
//
|
|
547
|
+
// `anna.video.generateAwait(args, {onProgress, signal, timeoutMs})` =
|
|
548
|
+
// video.generate + `media_job` host-event subscription + adaptive
|
|
549
|
+
// video.getJob polling fallback — the media twin of
|
|
550
|
+
// `tools.invokeAsyncAwait`. Resolves with the terminal job view
|
|
551
|
+
// ({jobId, state:"succeeded", result:{url, mimeType, durationSec, ...},
|
|
552
|
+
// billedCostCU}); `result.url` is a ~30 min presigned GET — call
|
|
553
|
+
// `anna.video.getJob({jobId})` again to re-sign after expiry.
|
|
554
|
+
|
|
555
|
+
function mediaJobErrorFromView(view) {
|
|
556
|
+
const e = view.error || {};
|
|
557
|
+
const code =
|
|
558
|
+
e.code ||
|
|
559
|
+
(view.state === "expired"
|
|
560
|
+
? "video_timeout"
|
|
561
|
+
: view.state === "cancelled"
|
|
562
|
+
? "cancelled"
|
|
563
|
+
: "video_failed");
|
|
564
|
+
const err = new Error(
|
|
565
|
+
e.message || `media job ${view.jobId} ended as ${view.state}`
|
|
566
|
+
);
|
|
567
|
+
err.code = code;
|
|
568
|
+
err.jobId = view.jobId;
|
|
569
|
+
err.state = view.state;
|
|
570
|
+
return err;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function videoGenerateAwaitImpl(rt, args, opts = {}) {
|
|
574
|
+
const onProgress =
|
|
575
|
+
typeof opts.onProgress === "function" ? opts.onProgress : null;
|
|
576
|
+
const signal = opts.signal || null;
|
|
577
|
+
|
|
578
|
+
return new Promise((resolve, reject) => {
|
|
579
|
+
let settled = false;
|
|
580
|
+
let jobId = null;
|
|
581
|
+
let lastSeq = 0;
|
|
582
|
+
let eventSeen = false;
|
|
583
|
+
let pollTimer = null;
|
|
584
|
+
let wallTimer = null;
|
|
585
|
+
let pollInFlight = false;
|
|
586
|
+
let offEvent = null;
|
|
587
|
+
let onAbort = null;
|
|
588
|
+
|
|
589
|
+
const cleanup = () => {
|
|
590
|
+
if (pollTimer) clearTimeout(pollTimer);
|
|
591
|
+
if (wallTimer) clearTimeout(wallTimer);
|
|
592
|
+
if (offEvent) offEvent();
|
|
593
|
+
if (signal && onAbort) signal.removeEventListener("abort", onAbort);
|
|
594
|
+
};
|
|
595
|
+
const settleOk = (v) => {
|
|
596
|
+
if (settled) return;
|
|
597
|
+
settled = true;
|
|
598
|
+
cleanup();
|
|
599
|
+
resolve(v);
|
|
600
|
+
};
|
|
601
|
+
const settleErr = (e) => {
|
|
602
|
+
if (settled) return;
|
|
603
|
+
settled = true;
|
|
604
|
+
cleanup();
|
|
605
|
+
if (jobId && e && typeof e === "object" && !e.jobId) e.jobId = jobId;
|
|
606
|
+
reject(e);
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const deliverProgress = (seq, progress, state) => {
|
|
610
|
+
if (typeof seq !== "number" || seq <= lastSeq) return;
|
|
611
|
+
lastSeq = seq;
|
|
612
|
+
if (onProgress) {
|
|
613
|
+
try {
|
|
614
|
+
onProgress({ seq, state: state || null, ...(progress || {}) });
|
|
615
|
+
} catch (_) {}
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
const schedulePoll = (delayMs) => {
|
|
620
|
+
if (settled) return;
|
|
621
|
+
if (pollTimer) clearTimeout(pollTimer);
|
|
622
|
+
const delay = Number.isFinite(delayMs)
|
|
623
|
+
? delayMs
|
|
624
|
+
: eventSeen
|
|
625
|
+
? JOB_POLL_WITH_EVENTS_MS
|
|
626
|
+
: JOB_POLL_NO_EVENTS_MS;
|
|
627
|
+
pollTimer = setTimeout(poll, delay);
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
const poll = async () => {
|
|
631
|
+
if (settled || pollInFlight || !jobId) return;
|
|
632
|
+
pollInFlight = true;
|
|
633
|
+
try {
|
|
634
|
+
const view = await rt.call("video", "getJob", { jobId });
|
|
635
|
+
if (view.progress) {
|
|
636
|
+
deliverProgress(view.progress.seq, view.progress, view.state);
|
|
637
|
+
}
|
|
638
|
+
if (JOB_TERMINAL_STATES.has(view.state)) {
|
|
639
|
+
if (view.state === "succeeded") settleOk(view);
|
|
640
|
+
else settleErr(mediaJobErrorFromView(view));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
} catch (e) {
|
|
644
|
+
if (e && (e.code === "VIDEO_JOB_NOT_FOUND" || e.code === "job_not_found")) {
|
|
645
|
+
settleErr(e);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
// transient RPC errors: wait for the next cycle
|
|
649
|
+
} finally {
|
|
650
|
+
pollInFlight = false;
|
|
651
|
+
}
|
|
652
|
+
schedulePoll();
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const onJobEvent = (payload) => {
|
|
656
|
+
if (settled || !payload || payload.jobId !== jobId) return;
|
|
657
|
+
eventSeen = true;
|
|
658
|
+
deliverProgress(payload.seq, payload.progress, payload.state);
|
|
659
|
+
// Terminal push → fetch the authoritative view immediately (the
|
|
660
|
+
// forwarded event never carries the result / re-signed URL).
|
|
661
|
+
schedulePoll(payload.terminal ? 0 : JOB_POLL_WITH_EVENTS_MS);
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
const start = async () => {
|
|
665
|
+
if (signal && signal.aborted) {
|
|
666
|
+
const err = new Error("video.generateAwait aborted before start");
|
|
667
|
+
err.code = "cancelled";
|
|
668
|
+
settleErr(err);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
let created;
|
|
672
|
+
try {
|
|
673
|
+
created = await rt.call("video", "generate", args || {});
|
|
674
|
+
} catch (e) {
|
|
675
|
+
settleErr(e);
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
jobId = created.jobId;
|
|
679
|
+
const deadlineMs = created.deadlineAt
|
|
680
|
+
? Date.parse(created.deadlineAt)
|
|
681
|
+
: NaN;
|
|
682
|
+
const wallMs = Number.isFinite(opts.timeoutMs)
|
|
683
|
+
? opts.timeoutMs
|
|
684
|
+
: Number.isFinite(deadlineMs)
|
|
685
|
+
? Math.max(0, deadlineMs - Date.now()) + 30000
|
|
686
|
+
: 35 * 60 * 1000;
|
|
687
|
+
wallTimer = setTimeout(() => {
|
|
688
|
+
const err = new Error(
|
|
689
|
+
`video.generateAwait wall clock elapsed after ${wallMs}ms; ` +
|
|
690
|
+
`job ${jobId} may still be rendering — recover it with ` +
|
|
691
|
+
`anna.video.getJob({jobId})`
|
|
692
|
+
);
|
|
693
|
+
err.code = "wait_timeout";
|
|
694
|
+
settleErr(err);
|
|
695
|
+
}, wallMs);
|
|
696
|
+
offEvent = rt.on("media_job", onJobEvent);
|
|
697
|
+
if (signal) {
|
|
698
|
+
onAbort = () => {
|
|
699
|
+
// queued cancel = full refund; running cancel is best-effort
|
|
700
|
+
// (provider may refuse — the job then runs to terminal).
|
|
701
|
+
rt.call("video", "cancelJob", { jobId }).catch(() => {});
|
|
702
|
+
schedulePoll(0);
|
|
703
|
+
};
|
|
704
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
705
|
+
}
|
|
706
|
+
schedulePoll(JOB_POLL_NO_EVENTS_MS);
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
start();
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function buildVideoNamespace(rt) {
|
|
714
|
+
return new Proxy(
|
|
715
|
+
{},
|
|
716
|
+
{
|
|
717
|
+
get(_, method) {
|
|
718
|
+
if (typeof method !== "string") return undefined;
|
|
719
|
+
if (method === "onJobEvent") {
|
|
720
|
+
// Raw `media_job` host events ({jobId, state, seq, progress,
|
|
721
|
+
// error, terminal}). Most apps should prefer generateAwait.
|
|
722
|
+
return (fn) => rt.on("media_job", fn);
|
|
723
|
+
}
|
|
724
|
+
if (method === "generateAwait") {
|
|
725
|
+
return (args, opts) => videoGenerateAwaitImpl(rt, args, opts || {});
|
|
726
|
+
}
|
|
727
|
+
return (args, opts) => rt.call("video", method, args || {}, opts);
|
|
728
|
+
},
|
|
729
|
+
}
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
|
|
501
733
|
// ---- Agent namespace (v0.2.0) ----
|
|
502
734
|
//
|
|
503
735
|
// Exposes both raw RPCs (`anna.agent.session.create({submode, ...})`,
|
|
@@ -535,9 +767,14 @@
|
|
|
535
767
|
// also exposed as `.refresh()` sugar on the AgentSession handle.
|
|
536
768
|
// `catalog` is the pre-create discovery surface (platform-tool universe
|
|
537
769
|
// + per-app eligibility) — read-only, no session required.
|
|
538
|
-
for (const m of ["create", "run", "cancel", "history", "delete", "list", "refresh", "catalog"]) {
|
|
770
|
+
for (const m of ["create", "run", "cancel", "history", "delete", "list", "refresh", "catalog", "frames"]) {
|
|
539
771
|
ns.session[m] = sessionRpcs[m];
|
|
540
772
|
}
|
|
773
|
+
// Wire method `session.run.status` contains a dot — expose it as the
|
|
774
|
+
// camelCase `runStatus` (the proxy would map `runStatus` →
|
|
775
|
+
// `session.runStatus`, which is not a wire method).
|
|
776
|
+
ns.session.runStatus = (args, opts) =>
|
|
777
|
+
rt.call("agent", "session.run.status", args || {}, opts);
|
|
541
778
|
// `attach` re-wraps an EXISTING session (known uuid) as an AgentSession
|
|
542
779
|
// handle WITHOUT minting a new one — pure client-side, no RPC. Accepts a
|
|
543
780
|
// bare uuid string or an info object (e.g. a row from `list()`).
|
|
@@ -731,8 +968,69 @@
|
|
|
731
968
|
this._buffer = new Map(); // seq -> payload (out-of-order holding)
|
|
732
969
|
this._nextSeq = 1;
|
|
733
970
|
this._done = false;
|
|
971
|
+
this._gotFrame = false; // any frame received (cancels the fallback timer)
|
|
972
|
+
this._pollTimer = null; // first-frame fallback (forum #341 P3)
|
|
973
|
+
this._polling = false;
|
|
974
|
+
this._rt = null;
|
|
975
|
+
}
|
|
976
|
+
// First-frame fallback (v0.18.0): if no frame arrives within timeoutMs,
|
|
977
|
+
// poll `agent.session.frames` until done. Layered with the host shells'
|
|
978
|
+
// own gate-level fallback — seq dedup makes double delivery harmless.
|
|
979
|
+
_armPollFallback(rt, timeoutMs) {
|
|
980
|
+
if (this._pollTimer || this._polling || this._done || this._gotFrame) return;
|
|
981
|
+
this._rt = rt;
|
|
982
|
+
const deadline =
|
|
983
|
+
typeof timeoutMs === "number" && timeoutMs > 0 ? timeoutMs : 20000;
|
|
984
|
+
this._pollTimer = setTimeout(() => {
|
|
985
|
+
this._pollTimer = null;
|
|
986
|
+
if (!this._gotFrame && !this._done) this._pollLoop();
|
|
987
|
+
}, deadline);
|
|
988
|
+
}
|
|
989
|
+
async _pollLoop() {
|
|
990
|
+
if (this._polling || !this._rt || !this.streamId) return;
|
|
991
|
+
this._polling = true;
|
|
992
|
+
let interval = 3000;
|
|
993
|
+
try {
|
|
994
|
+
while (!this._done) {
|
|
995
|
+
try {
|
|
996
|
+
const res = await this._rt.call("agent", "session.frames", {
|
|
997
|
+
stream_id: this.streamId,
|
|
998
|
+
after_seq: this._nextSeq - 1,
|
|
999
|
+
limit: 500,
|
|
1000
|
+
});
|
|
1001
|
+
const frames = (res && Array.isArray(res.frames) ? res.frames : [])
|
|
1002
|
+
.filter((f) => f && typeof f.seq === "number" && f.seq >= this._nextSeq)
|
|
1003
|
+
.sort((a, b) => a.seq - b.seq);
|
|
1004
|
+
for (const f of frames) {
|
|
1005
|
+
this._push({ seq: f.seq, payload: f.payload, done: !!f.done });
|
|
1006
|
+
if (this._done) return;
|
|
1007
|
+
}
|
|
1008
|
+
interval = frames.length ? 3000 : Math.min(interval * 2, 30000);
|
|
1009
|
+
} catch (e) {
|
|
1010
|
+
// Old host (`unknown_method`/`not_implemented`) → disarm; the
|
|
1011
|
+
// archive window aged out (`not_found`) → nothing to recover.
|
|
1012
|
+
const code = e && e.code;
|
|
1013
|
+
if (
|
|
1014
|
+
code === "unknown_method" ||
|
|
1015
|
+
code === "not_implemented" ||
|
|
1016
|
+
code === "not_found"
|
|
1017
|
+
) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
interval = Math.min(interval * 2, 30000);
|
|
1021
|
+
}
|
|
1022
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
1023
|
+
}
|
|
1024
|
+
} finally {
|
|
1025
|
+
this._polling = false;
|
|
1026
|
+
}
|
|
734
1027
|
}
|
|
735
1028
|
_push(frame) {
|
|
1029
|
+
this._gotFrame = true;
|
|
1030
|
+
if (this._pollTimer) {
|
|
1031
|
+
clearTimeout(this._pollTimer);
|
|
1032
|
+
this._pollTimer = null;
|
|
1033
|
+
}
|
|
736
1034
|
const seq = Number(frame.seq || 0);
|
|
737
1035
|
const payload = frame.payload;
|
|
738
1036
|
const done = !!frame.done;
|
|
@@ -741,7 +1039,7 @@
|
|
|
741
1039
|
return;
|
|
742
1040
|
}
|
|
743
1041
|
this._emit(payload, done);
|
|
744
|
-
this._nextSeq += 1;
|
|
1042
|
+
if (seq) this._nextSeq += 1;
|
|
745
1043
|
// Drain consecutive buffered frames.
|
|
746
1044
|
while (this._buffer.has(this._nextSeq)) {
|
|
747
1045
|
const next = this._buffer.get(this._nextSeq);
|
|
@@ -752,7 +1050,13 @@
|
|
|
752
1050
|
}
|
|
753
1051
|
_emit(payload, done) {
|
|
754
1052
|
if (payload != null) this._queue.push(payload);
|
|
755
|
-
if (done)
|
|
1053
|
+
if (done) {
|
|
1054
|
+
this._done = true;
|
|
1055
|
+
if (this._pollTimer) {
|
|
1056
|
+
clearTimeout(this._pollTimer);
|
|
1057
|
+
this._pollTimer = null;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
756
1060
|
while (this._waiters.length && (this._queue.length || this._done)) {
|
|
757
1061
|
const w = this._waiters.shift();
|
|
758
1062
|
if (this._queue.length) w({ value: this._queue.shift(), done: false });
|
|
@@ -771,6 +1075,10 @@
|
|
|
771
1075
|
},
|
|
772
1076
|
return() {
|
|
773
1077
|
self._done = true;
|
|
1078
|
+
if (self._pollTimer) {
|
|
1079
|
+
clearTimeout(self._pollTimer);
|
|
1080
|
+
self._pollTimer = null;
|
|
1081
|
+
}
|
|
774
1082
|
while (self._waiters.length) self._waiters.shift()({ value: undefined, done: true });
|
|
775
1083
|
return Promise.resolve({ value: undefined, done: true });
|
|
776
1084
|
},
|
|
@@ -809,9 +1117,12 @@
|
|
|
809
1117
|
info.session_expires_in ?? this.session_expires_in ?? null;
|
|
810
1118
|
}
|
|
811
1119
|
run(opts = {}) {
|
|
1120
|
+
// `firstFrameTimeoutMs` is SDK-local (first-frame fallback arm delay,
|
|
1121
|
+
// v0.18.0) — strip it from the wire args.
|
|
1122
|
+
const { firstFrameTimeoutMs, ...runOpts } = opts || {};
|
|
812
1123
|
const args = Object.assign(
|
|
813
1124
|
{ app_session_uuid: this.app_session_uuid },
|
|
814
|
-
|
|
1125
|
+
runOpts
|
|
815
1126
|
);
|
|
816
1127
|
const stream = new AgentRunStream(null, args.run_id || null);
|
|
817
1128
|
// Kick off the RPC; once the host returns {stream_id, run_id} we
|
|
@@ -823,6 +1134,9 @@
|
|
|
823
1134
|
if (stream.streamId) this._rt._registerStream(stream.streamId, stream);
|
|
824
1135
|
// If host returns done immediately (e.g. cached error), close.
|
|
825
1136
|
if (!stream.streamId) stream._emit(null, true);
|
|
1137
|
+
// forum #341 P3: no first frame within the deadline → the stream
|
|
1138
|
+
// self-recovers by polling agent.session.frames until done.
|
|
1139
|
+
else stream._armPollFallback(this._rt, firstFrameTimeoutMs);
|
|
826
1140
|
},
|
|
827
1141
|
(err) => {
|
|
828
1142
|
stream._emit({ event: "error", code: err.code, message: err.message }, true);
|
|
@@ -836,6 +1150,15 @@
|
|
|
836
1150
|
run_id: runId,
|
|
837
1151
|
});
|
|
838
1152
|
}
|
|
1153
|
+
// Point-in-time run status (v0.18.0, forum #341 P3). Check this BEFORE
|
|
1154
|
+
// re-running after a silent stream — `completed` means the run executed
|
|
1155
|
+
// and was charged; recover its output via `agent.session.frames`.
|
|
1156
|
+
runStatus(runId) {
|
|
1157
|
+
return this._rt.call("agent", "session.run.status", {
|
|
1158
|
+
app_session_uuid: this.app_session_uuid,
|
|
1159
|
+
run_id: runId,
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
839
1162
|
history(opts = {}) {
|
|
840
1163
|
return this._rt.call("agent", "session.history", Object.assign(
|
|
841
1164
|
{ app_session_uuid: this.app_session_uuid }, opts
|
|
@@ -873,6 +1196,7 @@
|
|
|
873
1196
|
this.capabilities = null;
|
|
874
1197
|
this.viewMeta = null;
|
|
875
1198
|
this.entryPayload = null;
|
|
1199
|
+
this.app = null;
|
|
876
1200
|
this.runtimeState = null;
|
|
877
1201
|
this.geometry = null;
|
|
878
1202
|
|
|
@@ -901,6 +1225,19 @@
|
|
|
901
1225
|
this.image = buildNamespace(this, "image");
|
|
902
1226
|
this.upload = buildNamespace(this, "upload");
|
|
903
1227
|
|
|
1228
|
+
// ---- video / audio namespaces (v0.20.0; media generation) ----
|
|
1229
|
+
// anna.video.generate({prompt, imageUrl?, durationSec?, resolution?,
|
|
1230
|
+
// aspectRatio?, generateAudio?, model?, clientTag?}) → {jobId, ...}
|
|
1231
|
+
// anna.video.{getJob,cancelJob,listJobs}({jobId|filters})
|
|
1232
|
+
// anna.video.generateAwait(args, {onProgress, signal, timeoutMs})
|
|
1233
|
+
// anna.audio.speak({text, voice?, language?, format?, speed?,
|
|
1234
|
+
// delivery?}) → {url|audioBase64, mimeType, charCount, billedCostCU}
|
|
1235
|
+
// anna.audio.transcribe({audioUrl|audioBase64, language?}) → {text, ...}
|
|
1236
|
+
// Capability discovery: anna.llm.catalog({serviceType?}).
|
|
1237
|
+
// Requires manifest ui.host_api.video / .audio + per-app media_grant.
|
|
1238
|
+
this.video = buildVideoNamespace(this);
|
|
1239
|
+
this.audio = buildNamespace(this, "audio");
|
|
1240
|
+
|
|
904
1241
|
// ---- credentials namespace (v0.11.0; multi-account) ----
|
|
905
1242
|
// anna.credentials.list_accounts({provider}) — metadata only, no tokens
|
|
906
1243
|
// anna.credentials.get_token({provider, account_id?}) — short-lived
|
|
@@ -1019,6 +1356,16 @@
|
|
|
1019
1356
|
this.token = msg.token;
|
|
1020
1357
|
return;
|
|
1021
1358
|
}
|
|
1359
|
+
// forum #376: keep the runtime mirrors fresh before dispatching so
|
|
1360
|
+
// handlers (and later reads) observe the updated values.
|
|
1361
|
+
if (msg.event === "entry_payload") {
|
|
1362
|
+
this.entryPayload = msg.payload || {};
|
|
1363
|
+
} else if (msg.event === "runtime_state_synced") {
|
|
1364
|
+
const patch = msg.payload && msg.payload.patch;
|
|
1365
|
+
if (patch) {
|
|
1366
|
+
this.runtimeState = Object.assign({}, this.runtimeState, patch);
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1022
1369
|
const set = this._handlers.get(msg.event);
|
|
1023
1370
|
if (set) for (const fn of set) try { fn(msg.payload); } catch (_) {}
|
|
1024
1371
|
}
|
|
@@ -1113,6 +1460,10 @@
|
|
|
1113
1460
|
const hello = await rt.call("window", "hello", {});
|
|
1114
1461
|
rt.capabilities = hello.capabilities;
|
|
1115
1462
|
rt.viewMeta = hello.view_meta;
|
|
1463
|
+
// forum #376 DX: the app's own identity — `{id, slug, name}`. `id` is
|
|
1464
|
+
// the numeric AnnaApp.id used by `open_app_view`; null on hosts older
|
|
1465
|
+
// than dispatcher 0.25.0.
|
|
1466
|
+
rt.app = hello.app || null;
|
|
1116
1467
|
rt.entryPayload = hello.entry_payload || {};
|
|
1117
1468
|
rt.runtimeState = hello.runtime_state || {};
|
|
1118
1469
|
rt.geometry = hello.geometry || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anna-ai/app-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.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",
|