@assistant-ui/appos 0.0.0-stage → 0.0.1
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 +1174 -0
- package/dist/index.js +1618 -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 +107 -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 +467 -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 +106 -0
- package/dist/types/src/lib/swbn/release.d.ts +39 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgentbaseAI Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// packages/appos-host/src/ai-call.ts
|
|
2
|
+
/** Call options an app may set. Headers and signals stay the shell's. */
|
|
3
|
+
var AI_OPTION_KEYS = [
|
|
4
|
+
"prompt",
|
|
5
|
+
"maxOutputTokens",
|
|
6
|
+
"temperature",
|
|
7
|
+
"stopSequences",
|
|
8
|
+
"topP",
|
|
9
|
+
"topK",
|
|
10
|
+
"presencePenalty",
|
|
11
|
+
"frequencyPenalty",
|
|
12
|
+
"responseFormat",
|
|
13
|
+
"seed",
|
|
14
|
+
"tools",
|
|
15
|
+
"toolChoice",
|
|
16
|
+
"reasoning",
|
|
17
|
+
"providerOptions"
|
|
18
|
+
];
|
|
19
|
+
var AiError = class extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "AiError";
|
|
24
|
+
this.code = code;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The options a shell passes on to its model: only AI_OPTION_KEYS, and no
|
|
29
|
+
* Anthropic options that change where requests go or what they cost beyond
|
|
30
|
+
* the prompt (container, mcpServers). Throws AiError ("bad-request",
|
|
31
|
+
* "too-large").
|
|
32
|
+
*/
|
|
33
|
+
function sanitizeAiOptions(options) {
|
|
34
|
+
if (!options || typeof options !== "object") throw new AiError("bad-request", "ai needs call options.");
|
|
35
|
+
const o = options;
|
|
36
|
+
if (!Array.isArray(o.prompt)) throw new AiError("bad-request", "ai needs a prompt.");
|
|
37
|
+
if (JSON.stringify(o).length > 4194304) throw new AiError("too-large", "The AI request is over 4 MB.");
|
|
38
|
+
const out = {};
|
|
39
|
+
for (const k of AI_OPTION_KEYS) if (o[k] !== void 0) out[k] = o[k];
|
|
40
|
+
const provider = out.providerOptions;
|
|
41
|
+
if (provider?.anthropic) {
|
|
42
|
+
const { container: _c, mcpServers: _m, ...rest } = provider.anthropic;
|
|
43
|
+
out.providerOptions = {
|
|
44
|
+
...provider,
|
|
45
|
+
anthropic: rest
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** Any error as { code, message }: its own string code (an AiError, or one off the wire), else "provider". */
|
|
51
|
+
function plainAiError(e) {
|
|
52
|
+
const err = e;
|
|
53
|
+
if (typeof err?.code === "string" && typeof err.message === "string") return {
|
|
54
|
+
code: err.code,
|
|
55
|
+
message: err.message.slice(0, 2e3)
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
code: "provider",
|
|
59
|
+
message: String(err?.message ?? e).slice(0, 2e3)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** A part as plain data: no raw chunks, errors as { code, message }. */
|
|
63
|
+
function plainPart(part) {
|
|
64
|
+
if (part.type === "raw") return void 0;
|
|
65
|
+
if (part.type === "error") return {
|
|
66
|
+
type: "error",
|
|
67
|
+
error: plainAiError(part.error)
|
|
68
|
+
};
|
|
69
|
+
return part;
|
|
70
|
+
}
|
|
71
|
+
export { sanitizeAiOptions as i, plainAiError as n, plainPart as r, AiError as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { CloudError, aiCall } from "./src.js";
|
|
2
|
+
// packages/appos-client/src/ai-sdk.ts
|
|
3
|
+
/**
|
|
4
|
+
* A language model the shell serves. The id is a hint: the shell's provider
|
|
5
|
+
* decides. Errors carry a stable `code` ("not-configured", "denied",
|
|
6
|
+
* "rate-limited", "unavailable", …).
|
|
7
|
+
*/
|
|
8
|
+
function apposModel(modelId = "default") {
|
|
9
|
+
return {
|
|
10
|
+
specificationVersion: "v4",
|
|
11
|
+
provider: "appos",
|
|
12
|
+
modelId,
|
|
13
|
+
supportedUrls: {},
|
|
14
|
+
async doGenerate(options) {
|
|
15
|
+
const { stream } = await this.doStream(options);
|
|
16
|
+
return collect(stream);
|
|
17
|
+
},
|
|
18
|
+
async doStream(options) {
|
|
19
|
+
const { abortSignal, headers: _headers, includeRawChunks: _raw, ...call } = options;
|
|
20
|
+
return { stream: aiCall(call, modelId === "default" ? void 0 : modelId, abortSignal) };
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Collects stream parts into one generate result. */
|
|
25
|
+
async function collect(stream) {
|
|
26
|
+
const content = [];
|
|
27
|
+
const open = /* @__PURE__ */ new Map();
|
|
28
|
+
let finish;
|
|
29
|
+
let warnings = [];
|
|
30
|
+
const reader = stream.getReader();
|
|
31
|
+
for (let r = await reader.read(); !r.done; r = await reader.read()) {
|
|
32
|
+
const p = r.value;
|
|
33
|
+
if (p.type === "text-start" || p.type === "reasoning-start") {
|
|
34
|
+
const part = {
|
|
35
|
+
type: p.type === "text-start" ? "text" : "reasoning",
|
|
36
|
+
text: ""
|
|
37
|
+
};
|
|
38
|
+
open.set(p.type + p.id, part);
|
|
39
|
+
content.push(part);
|
|
40
|
+
} else if (p.type === "text-delta" || p.type === "reasoning-delta") {
|
|
41
|
+
const key = (p.type === "text-delta" ? "text-start" : "reasoning-start") + p.id;
|
|
42
|
+
let part = open.get(key);
|
|
43
|
+
if (!part) {
|
|
44
|
+
part = {
|
|
45
|
+
type: p.type === "text-delta" ? "text" : "reasoning",
|
|
46
|
+
text: ""
|
|
47
|
+
};
|
|
48
|
+
open.set(key, part);
|
|
49
|
+
content.push(part);
|
|
50
|
+
}
|
|
51
|
+
part.text += p.delta;
|
|
52
|
+
} else if (p.type === "stream-start") warnings = p.warnings;
|
|
53
|
+
else if (p.type === "finish") finish = p;
|
|
54
|
+
else if (p.type === "error") throw p.error;
|
|
55
|
+
else if (p.type === "tool-call" || p.type === "tool-result" || p.type === "file" || p.type === "source") content.push(p);
|
|
56
|
+
}
|
|
57
|
+
if (!finish) throw new CloudError("unavailable", "The model stream ended without finishing.");
|
|
58
|
+
return {
|
|
59
|
+
content,
|
|
60
|
+
finishReason: finish.finishReason,
|
|
61
|
+
usage: finish.usage,
|
|
62
|
+
providerMetadata: finish.providerMetadata,
|
|
63
|
+
warnings
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export { apposModel };
|