@assistant-ui/appos 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/dist/chunks/ai-call.js +71 -0
- package/dist/chunks/ai-sdk.js +66 -0
- package/dist/chunks/src.js +1468 -0
- package/dist/index.js +1662 -0
- package/dist/next-page.js +150 -0
- package/dist/next-runtime.js +102 -0
- package/dist/next-server.js +50 -0
- package/dist/next.js +215 -0
- package/dist/pack.js +112 -0
- package/dist/server.js +77 -0
- package/dist/types/packages/appos-client/src/ai-sdk.d.ts +7 -0
- package/dist/types/packages/appos-client/src/index.d.ts +661 -0
- package/dist/types/packages/appos-client/src/theme.d.ts +16 -0
- package/dist/types/packages/appos-client/src/update-text.d.ts +13 -0
- package/dist/types/packages/appos-host/src/AppOSApp.d.ts +20 -0
- package/dist/types/packages/appos-host/src/ai-call.d.ts +31 -0
- package/dist/types/packages/appos-host/src/ai.d.ts +61 -0
- package/dist/types/packages/appos-host/src/embed.d.ts +119 -0
- package/dist/types/packages/appos-host/src/index.d.ts +6 -0
- package/dist/types/packages/appos-host/src/next/adapter.d.ts +43 -0
- package/dist/types/packages/appos-host/src/next/page.d.ts +1 -0
- package/dist/types/packages/appos-host/src/next/routes.d.ts +2 -0
- package/dist/types/packages/appos-host/src/next/runtime.d.ts +11 -0
- package/dist/types/packages/appos-host/src/next/server.d.ts +22 -0
- package/dist/types/packages/appos-host/src/pack.d.ts +16 -0
- package/dist/types/packages/appos-host/src/server.d.ts +23 -0
- package/dist/types/src/lib/ai-spend.d.ts +51 -0
- package/dist/types/src/lib/bundle-meta.d.ts +13 -0
- package/dist/types/src/lib/color-scheme.d.ts +17 -0
- package/dist/types/src/lib/external-link.d.ts +5 -0
- package/dist/types/src/lib/frame-pinch.d.ts +6 -0
- package/dist/types/src/lib/pack.d.ts +17 -0
- package/dist/types/src/lib/swbn/cbor.d.ts +16 -0
- package/dist/types/src/lib/swbn/identity.d.ts +121 -0
- package/dist/types/src/lib/swbn/integrity.d.ts +51 -0
- package/dist/types/src/lib/swbn/keys.d.ts +25 -0
- package/dist/types/src/lib/swbn/manifest.d.ts +144 -0
- package/dist/types/src/lib/swbn/release.d.ts +39 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/server.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { i as sanitizeAiOptions, n as plainAiError, r as plainPart, t as AiError } from "./chunks/ai-call.js";
|
|
2
|
+
// packages/appos-host/src/server.ts
|
|
3
|
+
/** A failed call as the embed reads it: { error: { code, message } }. */
|
|
4
|
+
function aiErrorResponse(status, code, message, headers) {
|
|
5
|
+
const h = new Headers(headers);
|
|
6
|
+
h.set("content-type", "application/json");
|
|
7
|
+
h.set("cache-control", "no-store");
|
|
8
|
+
return new Response(JSON.stringify({ error: {
|
|
9
|
+
code,
|
|
10
|
+
message
|
|
11
|
+
} }), {
|
|
12
|
+
status,
|
|
13
|
+
headers: h
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Runs one AI call and streams it: NDJSON lines { part } …, then { done }
|
|
18
|
+
* or { error }. A body that isn't a valid call answers 400 (or 413).
|
|
19
|
+
*/
|
|
20
|
+
async function aiResponse(body, { model, signal, headers }) {
|
|
21
|
+
const b = body;
|
|
22
|
+
let options;
|
|
23
|
+
try {
|
|
24
|
+
options = sanitizeAiOptions(b?.options);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
const err = plainAiError(e);
|
|
27
|
+
return aiErrorResponse(err.code === "too-large" ? 413 : 400, err.code, err.message);
|
|
28
|
+
}
|
|
29
|
+
const hint = typeof b?.model === "string" ? b.model : void 0;
|
|
30
|
+
const encoder = new TextEncoder();
|
|
31
|
+
const line = (m) => encoder.encode(`${JSON.stringify(m)}\n`);
|
|
32
|
+
const abort = new AbortController();
|
|
33
|
+
signal?.addEventListener("abort", () => abort.abort(), { once: true });
|
|
34
|
+
let reader;
|
|
35
|
+
const stream = new ReadableStream({
|
|
36
|
+
async pull(controller) {
|
|
37
|
+
try {
|
|
38
|
+
if (!reader) {
|
|
39
|
+
const { stream: parts } = await (await model(hint)).doStream({
|
|
40
|
+
...options,
|
|
41
|
+
abortSignal: abort.signal
|
|
42
|
+
});
|
|
43
|
+
reader = parts.getReader();
|
|
44
|
+
}
|
|
45
|
+
for (;;) {
|
|
46
|
+
const { done, value } = await reader.read();
|
|
47
|
+
if (done) {
|
|
48
|
+
controller.enqueue(line({ done: true }));
|
|
49
|
+
controller.close();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const p = plainPart(value);
|
|
53
|
+
if (p) {
|
|
54
|
+
controller.enqueue(line({ part: p }));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
controller.enqueue(line({ error: plainAiError(e) }));
|
|
60
|
+
controller.close();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
cancel() {
|
|
64
|
+
abort.abort();
|
|
65
|
+
reader?.cancel().catch(() => {});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const h = new Headers(headers);
|
|
69
|
+
h.set("content-type", "application/x-ndjson; charset=utf-8");
|
|
70
|
+
h.set("cache-control", "no-store");
|
|
71
|
+
h.set("x-content-type-options", "nosniff");
|
|
72
|
+
return new Response(stream, {
|
|
73
|
+
status: 200,
|
|
74
|
+
headers: h
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export { AiError, aiErrorResponse, aiResponse };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LanguageModelV4 } from "@ai-sdk/provider";
|
|
2
|
+
/**
|
|
3
|
+
* A language model the shell serves. The id is a hint: the shell's provider
|
|
4
|
+
* decides. Errors carry a stable `code` ("not-configured", "denied",
|
|
5
|
+
* "rate-limited", "unavailable", …).
|
|
6
|
+
*/
|
|
7
|
+
export declare function apposModel(modelId?: string): LanguageModelV4;
|