@hilbras/sdk 0.26.0 → 1.0.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 +1 -1
- package/dist/catalog/provider-catalog.json +92 -57
- package/dist/client/client.d.ts +5 -10
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +125 -26
- package/dist/client/client.js.map +1 -1
- package/dist/features/agent/index.d.ts +13 -0
- package/dist/features/agent/index.d.ts.map +1 -0
- package/dist/features/agent/index.js +12 -0
- package/dist/features/agent/index.js.map +1 -0
- package/dist/features/agent/plan-and-execute.d.ts +49 -0
- package/dist/features/agent/plan-and-execute.d.ts.map +1 -0
- package/dist/features/agent/plan-and-execute.js +184 -0
- package/dist/features/agent/plan-and-execute.js.map +1 -0
- package/dist/features/agent/react.d.ts +49 -0
- package/dist/features/agent/react.d.ts.map +1 -0
- package/dist/features/agent/react.js +165 -0
- package/dist/features/agent/react.js.map +1 -0
- package/dist/features/agent/tool-loop.d.ts +58 -0
- package/dist/features/agent/tool-loop.d.ts.map +1 -0
- package/dist/features/agent/tool-loop.js +217 -0
- package/dist/features/agent/tool-loop.js.map +1 -0
- package/dist/features/agent/types.d.ts +136 -0
- package/dist/features/agent/types.d.ts.map +1 -0
- package/dist/features/agent/types.js +7 -0
- package/dist/features/agent/types.js.map +1 -0
- package/dist/features/eval/evaluate.d.ts +39 -0
- package/dist/features/eval/evaluate.d.ts.map +1 -0
- package/dist/features/eval/evaluate.js +153 -0
- package/dist/features/eval/evaluate.js.map +1 -0
- package/dist/features/eval/index.d.ts +9 -0
- package/dist/features/eval/index.d.ts.map +1 -0
- package/dist/features/eval/index.js +8 -0
- package/dist/features/eval/index.js.map +1 -0
- package/dist/features/eval/metrics.d.ts +38 -0
- package/dist/features/eval/metrics.d.ts.map +1 -0
- package/dist/features/eval/metrics.js +133 -0
- package/dist/features/eval/metrics.js.map +1 -0
- package/dist/features/eval/types.d.ts +116 -0
- package/dist/features/eval/types.d.ts.map +1 -0
- package/dist/features/eval/types.js +7 -0
- package/dist/features/eval/types.js.map +1 -0
- package/dist/features/fine-tune/formatters.d.ts +11 -0
- package/dist/features/fine-tune/formatters.d.ts.map +1 -0
- package/dist/features/fine-tune/formatters.js +155 -0
- package/dist/features/fine-tune/formatters.js.map +1 -0
- package/dist/features/fine-tune/index.d.ts +10 -0
- package/dist/features/fine-tune/index.d.ts.map +1 -0
- package/dist/features/fine-tune/index.js +9 -0
- package/dist/features/fine-tune/index.js.map +1 -0
- package/dist/features/fine-tune/quality.d.ts +37 -0
- package/dist/features/fine-tune/quality.d.ts.map +1 -0
- package/dist/features/fine-tune/quality.js +97 -0
- package/dist/features/fine-tune/quality.js.map +1 -0
- package/dist/features/fine-tune/split.d.ts +23 -0
- package/dist/features/fine-tune/split.d.ts.map +1 -0
- package/dist/features/fine-tune/split.js +43 -0
- package/dist/features/fine-tune/split.js.map +1 -0
- package/dist/features/fine-tune/types.d.ts +85 -0
- package/dist/features/fine-tune/types.d.ts.map +1 -0
- package/dist/features/fine-tune/types.js +5 -0
- package/dist/features/fine-tune/types.js.map +1 -0
- package/dist/features/rag/chunker.d.ts +42 -0
- package/dist/features/rag/chunker.d.ts.map +1 -0
- package/dist/features/rag/chunker.js +115 -0
- package/dist/features/rag/chunker.js.map +1 -0
- package/dist/features/rag/in-memory-store.d.ts +21 -0
- package/dist/features/rag/in-memory-store.d.ts.map +1 -0
- package/dist/features/rag/in-memory-store.js +81 -0
- package/dist/features/rag/in-memory-store.js.map +1 -0
- package/dist/features/rag/index.d.ts +15 -0
- package/dist/features/rag/index.d.ts.map +1 -0
- package/dist/features/rag/index.js +14 -0
- package/dist/features/rag/index.js.map +1 -0
- package/dist/features/rag/pipeline.d.ts +92 -0
- package/dist/features/rag/pipeline.d.ts.map +1 -0
- package/dist/features/rag/pipeline.js +102 -0
- package/dist/features/rag/pipeline.js.map +1 -0
- package/dist/features/rag/retriever.d.ts +71 -0
- package/dist/features/rag/retriever.d.ts.map +1 -0
- package/dist/features/rag/retriever.js +99 -0
- package/dist/features/rag/retriever.js.map +1 -0
- package/dist/features/rag/vector-store.d.ts +43 -0
- package/dist/features/rag/vector-store.d.ts.map +1 -0
- package/dist/features/rag/vector-store.js +8 -0
- package/dist/features/rag/vector-store.js.map +1 -0
- package/dist/frameworks/angular/angular-shim.d.ts +19 -0
- package/dist/frameworks/angular/angular-shim.d.ts.map +1 -0
- package/dist/frameworks/angular/angular-shim.js +22 -0
- package/dist/frameworks/angular/angular-shim.js.map +1 -0
- package/dist/frameworks/angular/chat.service.d.ts +74 -0
- package/dist/frameworks/angular/chat.service.d.ts.map +1 -0
- package/dist/frameworks/angular/chat.service.js +263 -0
- package/dist/frameworks/angular/chat.service.js.map +1 -0
- package/dist/frameworks/angular/completion.service.d.ts +34 -0
- package/dist/frameworks/angular/completion.service.d.ts.map +1 -0
- package/dist/frameworks/angular/completion.service.js +114 -0
- package/dist/frameworks/angular/completion.service.js.map +1 -0
- package/dist/frameworks/angular/index.d.ts +12 -0
- package/dist/frameworks/angular/index.d.ts.map +1 -0
- package/dist/frameworks/angular/index.js +9 -0
- package/dist/frameworks/angular/index.js.map +1 -0
- package/dist/frameworks/angular/object.service.d.ts +34 -0
- package/dist/frameworks/angular/object.service.d.ts.map +1 -0
- package/dist/frameworks/angular/object.service.js +119 -0
- package/dist/frameworks/angular/object.service.js.map +1 -0
- package/dist/frameworks/astro/endpoints.d.ts +46 -0
- package/dist/frameworks/astro/endpoints.d.ts.map +1 -0
- package/dist/frameworks/astro/endpoints.js +78 -0
- package/dist/frameworks/astro/endpoints.js.map +1 -0
- package/dist/frameworks/astro/hooks.d.ts +29 -0
- package/dist/frameworks/astro/hooks.d.ts.map +1 -0
- package/dist/frameworks/astro/hooks.js +80 -0
- package/dist/frameworks/astro/hooks.js.map +1 -0
- package/dist/frameworks/astro/index.d.ts +8 -0
- package/dist/frameworks/astro/index.d.ts.map +1 -0
- package/dist/frameworks/astro/index.js +8 -0
- package/dist/frameworks/astro/index.js.map +1 -0
- package/dist/frameworks/nextjs/client.d.ts +13 -0
- package/dist/frameworks/nextjs/client.d.ts.map +1 -0
- package/dist/frameworks/nextjs/client.js +8 -0
- package/dist/frameworks/nextjs/client.js.map +1 -0
- package/dist/frameworks/nextjs/index.d.ts +21 -0
- package/dist/frameworks/nextjs/index.d.ts.map +1 -0
- package/dist/frameworks/nextjs/index.js +20 -0
- package/dist/frameworks/nextjs/index.js.map +1 -0
- package/dist/frameworks/nextjs/route-handlers.d.ts +69 -0
- package/dist/frameworks/nextjs/route-handlers.d.ts.map +1 -0
- package/dist/frameworks/nextjs/route-handlers.js +81 -0
- package/dist/frameworks/nextjs/route-handlers.js.map +1 -0
- package/dist/frameworks/nextjs/server.d.ts +78 -0
- package/dist/frameworks/nextjs/server.d.ts.map +1 -0
- package/dist/frameworks/nextjs/server.js +89 -0
- package/dist/frameworks/nextjs/server.js.map +1 -0
- package/dist/frameworks/nextjs/signal-shim.d.ts +9 -0
- package/dist/frameworks/nextjs/signal-shim.d.ts.map +1 -0
- package/dist/frameworks/nextjs/signal-shim.js +14 -0
- package/dist/frameworks/nextjs/signal-shim.js.map +1 -0
- package/dist/frameworks/nextjs/use-chat.d.ts +22 -0
- package/dist/frameworks/nextjs/use-chat.d.ts.map +1 -0
- package/dist/frameworks/nextjs/use-chat.js +89 -0
- package/dist/frameworks/nextjs/use-chat.js.map +1 -0
- package/dist/frameworks/nextjs/use-completion.d.ts +18 -0
- package/dist/frameworks/nextjs/use-completion.d.ts.map +1 -0
- package/dist/frameworks/nextjs/use-completion.js +67 -0
- package/dist/frameworks/nextjs/use-completion.js.map +1 -0
- package/dist/frameworks/qwik/index.d.ts +11 -0
- package/dist/frameworks/qwik/index.d.ts.map +1 -0
- package/dist/frameworks/qwik/index.js +11 -0
- package/dist/frameworks/qwik/index.js.map +1 -0
- package/dist/frameworks/qwik/signal-shim.d.ts +11 -0
- package/dist/frameworks/qwik/signal-shim.d.ts.map +1 -0
- package/dist/frameworks/qwik/signal-shim.js +15 -0
- package/dist/frameworks/qwik/signal-shim.js.map +1 -0
- package/dist/frameworks/qwik/stream-parser.d.ts +8 -0
- package/dist/frameworks/qwik/stream-parser.d.ts.map +1 -0
- package/dist/frameworks/qwik/stream-parser.js +42 -0
- package/dist/frameworks/qwik/stream-parser.js.map +1 -0
- package/dist/frameworks/qwik/use-chat.d.ts +37 -0
- package/dist/frameworks/qwik/use-chat.d.ts.map +1 -0
- package/dist/frameworks/qwik/use-chat.js +205 -0
- package/dist/frameworks/qwik/use-chat.js.map +1 -0
- package/dist/frameworks/qwik/use-completion.d.ts +20 -0
- package/dist/frameworks/qwik/use-completion.d.ts.map +1 -0
- package/dist/frameworks/qwik/use-completion.js +69 -0
- package/dist/frameworks/qwik/use-completion.js.map +1 -0
- package/dist/frameworks/react/generative-ui.d.ts +122 -0
- package/dist/frameworks/react/generative-ui.d.ts.map +1 -0
- package/dist/frameworks/react/generative-ui.js +120 -0
- package/dist/frameworks/react/generative-ui.js.map +1 -0
- package/dist/frameworks/react/index.d.ts +16 -0
- package/dist/frameworks/react/index.d.ts.map +1 -0
- package/dist/frameworks/react/index.js +11 -0
- package/dist/frameworks/react/index.js.map +1 -0
- package/dist/frameworks/react/stream-parser.d.ts +8 -0
- package/dist/frameworks/react/stream-parser.d.ts.map +1 -0
- package/dist/frameworks/react/stream-parser.js +42 -0
- package/dist/frameworks/react/stream-parser.js.map +1 -0
- package/dist/frameworks/react/use-chat.d.ts +44 -0
- package/dist/frameworks/react/use-chat.d.ts.map +1 -0
- package/dist/frameworks/react/use-chat.js +294 -0
- package/dist/frameworks/react/use-chat.js.map +1 -0
- package/dist/frameworks/react/use-completion.d.ts +11 -0
- package/dist/frameworks/react/use-completion.d.ts.map +1 -0
- package/dist/frameworks/react/use-completion.js +91 -0
- package/dist/frameworks/react/use-completion.js.map +1 -0
- package/dist/frameworks/react/use-object.d.ts +45 -0
- package/dist/frameworks/react/use-object.d.ts.map +1 -0
- package/dist/frameworks/react/use-object.js +100 -0
- package/dist/frameworks/react/use-object.js.map +1 -0
- package/dist/frameworks/remix/actions.d.ts +42 -0
- package/dist/frameworks/remix/actions.d.ts.map +1 -0
- package/dist/frameworks/remix/actions.js +76 -0
- package/dist/frameworks/remix/actions.js.map +1 -0
- package/dist/frameworks/remix/hooks.d.ts +40 -0
- package/dist/frameworks/remix/hooks.d.ts.map +1 -0
- package/dist/frameworks/remix/hooks.js +97 -0
- package/dist/frameworks/remix/hooks.js.map +1 -0
- package/dist/frameworks/remix/index.d.ts +8 -0
- package/dist/frameworks/remix/index.d.ts.map +1 -0
- package/dist/frameworks/remix/index.js +8 -0
- package/dist/frameworks/remix/index.js.map +1 -0
- package/dist/frameworks/solid/index.d.ts +13 -0
- package/dist/frameworks/solid/index.d.ts.map +1 -0
- package/dist/frameworks/solid/index.js +13 -0
- package/dist/frameworks/solid/index.js.map +1 -0
- package/dist/frameworks/solid/solid-shim.d.ts +13 -0
- package/dist/frameworks/solid/solid-shim.d.ts.map +1 -0
- package/dist/frameworks/solid/solid-shim.js +15 -0
- package/dist/frameworks/solid/solid-shim.js.map +1 -0
- package/dist/frameworks/solid/stream-parser.d.ts +8 -0
- package/dist/frameworks/solid/stream-parser.d.ts.map +1 -0
- package/dist/frameworks/solid/stream-parser.js +42 -0
- package/dist/frameworks/solid/stream-parser.js.map +1 -0
- package/dist/frameworks/solid/use-chat.d.ts +38 -0
- package/dist/frameworks/solid/use-chat.d.ts.map +1 -0
- package/dist/frameworks/solid/use-chat.js +203 -0
- package/dist/frameworks/solid/use-chat.js.map +1 -0
- package/dist/frameworks/solid/use-completion.d.ts +20 -0
- package/dist/frameworks/solid/use-completion.d.ts.map +1 -0
- package/dist/frameworks/solid/use-completion.js +66 -0
- package/dist/frameworks/solid/use-completion.js.map +1 -0
- package/dist/frameworks/solid/use-object.d.ts +19 -0
- package/dist/frameworks/solid/use-object.d.ts.map +1 -0
- package/dist/frameworks/solid/use-object.js +70 -0
- package/dist/frameworks/solid/use-object.js.map +1 -0
- package/dist/frameworks/svelte/index.d.ts +15 -0
- package/dist/frameworks/svelte/index.d.ts.map +1 -0
- package/dist/frameworks/svelte/index.js +11 -0
- package/dist/frameworks/svelte/index.js.map +1 -0
- package/dist/frameworks/svelte/stream-parser.d.ts +8 -0
- package/dist/frameworks/svelte/stream-parser.d.ts.map +1 -0
- package/dist/frameworks/svelte/stream-parser.js +42 -0
- package/dist/frameworks/svelte/stream-parser.js.map +1 -0
- package/dist/frameworks/svelte/use-chat.d.ts +54 -0
- package/dist/frameworks/svelte/use-chat.d.ts.map +1 -0
- package/dist/frameworks/svelte/use-chat.js +276 -0
- package/dist/frameworks/svelte/use-chat.js.map +1 -0
- package/dist/frameworks/svelte/use-completion.d.ts +25 -0
- package/dist/frameworks/svelte/use-completion.d.ts.map +1 -0
- package/dist/frameworks/svelte/use-completion.js +108 -0
- package/dist/frameworks/svelte/use-completion.js.map +1 -0
- package/dist/frameworks/svelte/use-object.d.ts +28 -0
- package/dist/frameworks/svelte/use-object.d.ts.map +1 -0
- package/dist/frameworks/svelte/use-object.js +122 -0
- package/dist/frameworks/svelte/use-object.js.map +1 -0
- package/dist/frameworks/vue/index.d.ts +12 -0
- package/dist/frameworks/vue/index.d.ts.map +1 -0
- package/dist/frameworks/vue/index.js +10 -0
- package/dist/frameworks/vue/index.js.map +1 -0
- package/dist/frameworks/vue/stream-parser.d.ts +8 -0
- package/dist/frameworks/vue/stream-parser.d.ts.map +1 -0
- package/dist/frameworks/vue/stream-parser.js +42 -0
- package/dist/frameworks/vue/stream-parser.js.map +1 -0
- package/dist/frameworks/vue/use-chat.d.ts +107 -0
- package/dist/frameworks/vue/use-chat.d.ts.map +1 -0
- package/dist/frameworks/vue/use-chat.js +248 -0
- package/dist/frameworks/vue/use-chat.js.map +1 -0
- package/dist/frameworks/vue/use-completion.d.ts +18 -0
- package/dist/frameworks/vue/use-completion.d.ts.map +1 -0
- package/dist/frameworks/vue/use-completion.js +87 -0
- package/dist/frameworks/vue/use-completion.js.map +1 -0
- package/dist/frameworks/vue/use-object.d.ts +22 -0
- package/dist/frameworks/vue/use-object.d.ts.map +1 -0
- package/dist/frameworks/vue/use-object.js +101 -0
- package/dist/frameworks/vue/use-object.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/types/schema.d.ts +38 -0
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/streams.d.ts +25 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/streams.js +4 -0
- package/dist/types/streams.js.map +1 -1
- package/dist/types/ui-protocol.d.ts +34 -2
- package/dist/types/ui-protocol.d.ts.map +1 -1
- package/dist/utils/sse-writer.d.ts +68 -0
- package/dist/utils/sse-writer.d.ts.map +1 -0
- package/dist/utils/sse-writer.js +233 -0
- package/dist/utils/sse-writer.js.map +1 -0
- package/package.json +97 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/qwik — useChat
|
|
3
|
+
*
|
|
4
|
+
* Qwik-compatible chat hook with tool call support.
|
|
5
|
+
*/
|
|
6
|
+
import { useSignal } from "./signal-shim.js";
|
|
7
|
+
import { parseUIStream } from "./stream-parser.js";
|
|
8
|
+
let _idCounter = 0;
|
|
9
|
+
function generateId() {
|
|
10
|
+
return `msg_${Date.now()}_${_idCounter++}`;
|
|
11
|
+
}
|
|
12
|
+
export function useChat(options = {}) {
|
|
13
|
+
const { api = "/api/chat", onFinish, onError, initialMessages = [], provider, model, maxSteps = 1, onToolCall, headers = {}, body = {}, } = options;
|
|
14
|
+
const messages = useSignal(initialMessages);
|
|
15
|
+
const isLoading = useSignal(false);
|
|
16
|
+
const error = useSignal(null);
|
|
17
|
+
let abortController = null;
|
|
18
|
+
async function sendRequest(messageHistory, assistantMessage) {
|
|
19
|
+
isLoading.value = true;
|
|
20
|
+
error.value = null;
|
|
21
|
+
abortController = new AbortController();
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(api, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
26
|
+
body: JSON.stringify({
|
|
27
|
+
messages: messageHistory.map((m) => ({ role: m.role, content: m.content })),
|
|
28
|
+
provider,
|
|
29
|
+
model,
|
|
30
|
+
stream: true,
|
|
31
|
+
maxSteps,
|
|
32
|
+
...body,
|
|
33
|
+
}),
|
|
34
|
+
signal: abortController.signal,
|
|
35
|
+
});
|
|
36
|
+
if (!res.ok)
|
|
37
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
38
|
+
if (!res.body)
|
|
39
|
+
throw new Error("Response body is null");
|
|
40
|
+
let content = "";
|
|
41
|
+
const toolInvocations = [];
|
|
42
|
+
const pendingToolCalls = new Map();
|
|
43
|
+
for await (const msg of parseUIStream(res.body)) {
|
|
44
|
+
switch (msg.type) {
|
|
45
|
+
case "text_delta":
|
|
46
|
+
content += msg.text;
|
|
47
|
+
messages.value = messages.value.map((m) => m.id === assistantMessage.id ? { ...m, content } : m);
|
|
48
|
+
break;
|
|
49
|
+
case "tool_call_start": {
|
|
50
|
+
const invocation = {
|
|
51
|
+
id: msg.id,
|
|
52
|
+
name: msg.name,
|
|
53
|
+
args: {},
|
|
54
|
+
state: "call",
|
|
55
|
+
};
|
|
56
|
+
toolInvocations.push(invocation);
|
|
57
|
+
pendingToolCalls.set(msg.id, { name: msg.name, argsBuffer: "" });
|
|
58
|
+
messages.value = messages.value.map((m) => m.id === assistantMessage.id
|
|
59
|
+
? { ...m, toolInvocations: [...toolInvocations] }
|
|
60
|
+
: m);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case "tool_call_delta": {
|
|
64
|
+
const pending = pendingToolCalls.get(msg.id);
|
|
65
|
+
if (pending) {
|
|
66
|
+
pending.argsBuffer += msg.args;
|
|
67
|
+
try {
|
|
68
|
+
const partialArgs = JSON.parse(pending.argsBuffer);
|
|
69
|
+
const invocation = toolInvocations.find((t) => t.id === msg.id);
|
|
70
|
+
if (invocation) {
|
|
71
|
+
invocation.args = partialArgs;
|
|
72
|
+
messages.value = messages.value.map((m) => m.id === assistantMessage.id
|
|
73
|
+
? { ...m, toolInvocations: [...toolInvocations] }
|
|
74
|
+
: m);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Partial JSON not parseable yet
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
case "tool_call_end": {
|
|
84
|
+
const pending = pendingToolCalls.get(msg.id);
|
|
85
|
+
const invocation = toolInvocations.find((t) => t.id === msg.id);
|
|
86
|
+
if (invocation && pending) {
|
|
87
|
+
try {
|
|
88
|
+
invocation.args = JSON.parse(pending.argsBuffer || "{}");
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
invocation.args = { raw: pending.argsBuffer };
|
|
92
|
+
}
|
|
93
|
+
pendingToolCalls.delete(msg.id);
|
|
94
|
+
if (onToolCall) {
|
|
95
|
+
try {
|
|
96
|
+
invocation.state = "call";
|
|
97
|
+
const result = await onToolCall({
|
|
98
|
+
id: msg.id,
|
|
99
|
+
name: invocation.name,
|
|
100
|
+
args: invocation.args,
|
|
101
|
+
});
|
|
102
|
+
invocation.result = result;
|
|
103
|
+
invocation.state = "result";
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
invocation.state = "error";
|
|
107
|
+
invocation.error = err.message;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
invocation.state = "call";
|
|
112
|
+
}
|
|
113
|
+
messages.value = messages.value.map((m) => m.id === assistantMessage.id
|
|
114
|
+
? { ...m, toolInvocations: [...toolInvocations] }
|
|
115
|
+
: m);
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case "message_end":
|
|
120
|
+
if (msg.usage) {
|
|
121
|
+
messages.value = messages.value.map((m) => m.id === assistantMessage.id ? { ...m, usage: msg.usage } : m);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case "error":
|
|
125
|
+
throw new Error(msg.error);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const finalMessage = {
|
|
129
|
+
...assistantMessage,
|
|
130
|
+
content,
|
|
131
|
+
toolInvocations: toolInvocations.length > 0 ? toolInvocations : undefined,
|
|
132
|
+
};
|
|
133
|
+
onFinish?.(finalMessage);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
if (err.name !== "AbortError") {
|
|
137
|
+
const e = err instanceof Error ? err : new Error(String(err));
|
|
138
|
+
error.value = e;
|
|
139
|
+
onError?.(e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
isLoading.value = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function append(message) {
|
|
147
|
+
const userMessage = {
|
|
148
|
+
id: generateId(),
|
|
149
|
+
role: "user",
|
|
150
|
+
content: message.content,
|
|
151
|
+
createdAt: Date.now(),
|
|
152
|
+
};
|
|
153
|
+
const assistantMessage = {
|
|
154
|
+
id: generateId(),
|
|
155
|
+
role: "assistant",
|
|
156
|
+
content: "",
|
|
157
|
+
createdAt: Date.now(),
|
|
158
|
+
provider,
|
|
159
|
+
model,
|
|
160
|
+
};
|
|
161
|
+
messages.value = [...messages.value, userMessage, assistantMessage];
|
|
162
|
+
await sendRequest([...messages.value.slice(0, -2), userMessage], assistantMessage);
|
|
163
|
+
}
|
|
164
|
+
async function reload() {
|
|
165
|
+
const msgs = messages.value;
|
|
166
|
+
if (msgs.length === 0 || isLoading.value)
|
|
167
|
+
return;
|
|
168
|
+
const lastUserIdx = msgs.findLastIndex((m) => m.role === "user");
|
|
169
|
+
if (lastUserIdx === -1)
|
|
170
|
+
return;
|
|
171
|
+
const messagesUpToLastUser = msgs.slice(0, lastUserIdx + 1);
|
|
172
|
+
const assistantMessage = {
|
|
173
|
+
id: generateId(),
|
|
174
|
+
role: "assistant",
|
|
175
|
+
content: "",
|
|
176
|
+
createdAt: Date.now(),
|
|
177
|
+
provider,
|
|
178
|
+
model,
|
|
179
|
+
};
|
|
180
|
+
messages.value = [...messagesUpToLastUser, assistantMessage];
|
|
181
|
+
await sendRequest(messagesUpToLastUser, assistantMessage);
|
|
182
|
+
}
|
|
183
|
+
function stop() {
|
|
184
|
+
abortController?.abort();
|
|
185
|
+
isLoading.value = false;
|
|
186
|
+
}
|
|
187
|
+
function clear() {
|
|
188
|
+
messages.value = [];
|
|
189
|
+
error.value = null;
|
|
190
|
+
}
|
|
191
|
+
function setMessages(msgs) {
|
|
192
|
+
messages.value = msgs;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
messages: () => messages.value,
|
|
196
|
+
isLoading: () => isLoading.value,
|
|
197
|
+
error: () => error.value,
|
|
198
|
+
setMessages,
|
|
199
|
+
append,
|
|
200
|
+
reload,
|
|
201
|
+
stop,
|
|
202
|
+
clear,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=use-chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-chat.js","sourceRoot":"","sources":["../../../src/frameworks/qwik/use-chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,SAAS,UAAU;IACjB,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,UAAU,EAAE,EAAE,CAAC;AAC7C,CAAC;AA0BD,MAAM,UAAU,OAAO,CAAC,OAAO,GAAmB,EAAE;IAClD,MAAM,EACJ,GAAG,GAAG,WAAW,EACjB,QAAQ,EACR,OAAO,EACP,eAAe,GAAG,EAAE,EACpB,QAAQ,EACR,KAAK,EACL,QAAQ,GAAG,CAAC,EACZ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G,KAAK,CAAC;IAC1B,CAAC;IAED,SAAS,KAAK;QACZ,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC;QACpB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,SAAS,WAAW,CAAC,IAAiB;QACpC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK;QAC9B,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK;QAChC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK;QACxB,WAAW;QACX,MAAM;QACN,MAAM;QACN,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/qwik — useCompletion
|
|
3
|
+
*
|
|
4
|
+
* Qwik-compatible completion hook.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseCompletionOptions {
|
|
7
|
+
api?: string;
|
|
8
|
+
onFinish?: (text: string) => void;
|
|
9
|
+
onError?: (error: Error) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UseCompletionReturn {
|
|
12
|
+
completion: () => string;
|
|
13
|
+
isLoading: () => boolean;
|
|
14
|
+
error: () => Error | null;
|
|
15
|
+
setCompletion: (value: string) => void;
|
|
16
|
+
complete: (prompt: string) => Promise<void>;
|
|
17
|
+
stop: () => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function useCompletion(options?: UseCompletionOptions): UseCompletionReturn;
|
|
20
|
+
//# sourceMappingURL=use-completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-completion.d.ts","sourceRoot":"","sources":["../../../src/frameworks/qwik/use-completion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,KAAK,EAAE,MAAM,KAAK,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CAqErF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/qwik — useCompletion
|
|
3
|
+
*
|
|
4
|
+
* Qwik-compatible completion hook.
|
|
5
|
+
*/
|
|
6
|
+
import { useSignal } from "./signal-shim.js";
|
|
7
|
+
export function useCompletion(options = {}) {
|
|
8
|
+
const { api = "/api/completion", onFinish, onError } = options;
|
|
9
|
+
const completion = useSignal("");
|
|
10
|
+
const isLoading = useSignal(false);
|
|
11
|
+
const error = useSignal(null);
|
|
12
|
+
let abortController = null;
|
|
13
|
+
async function complete(prompt) {
|
|
14
|
+
isLoading.value = true;
|
|
15
|
+
error.value = null;
|
|
16
|
+
completion.value = "";
|
|
17
|
+
abortController = new AbortController();
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(api, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json" },
|
|
22
|
+
body: JSON.stringify({ prompt }),
|
|
23
|
+
signal: abortController.signal,
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
const reader = response.body?.getReader();
|
|
29
|
+
if (!reader)
|
|
30
|
+
throw new Error("No response body");
|
|
31
|
+
const decoder = new TextDecoder();
|
|
32
|
+
let text = "";
|
|
33
|
+
while (true) {
|
|
34
|
+
const { done, value } = await reader.read();
|
|
35
|
+
if (done)
|
|
36
|
+
break;
|
|
37
|
+
text += decoder.decode(value, { stream: true });
|
|
38
|
+
completion.value = text;
|
|
39
|
+
}
|
|
40
|
+
onFinish?.(text);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if (err.name !== "AbortError") {
|
|
44
|
+
const e = err;
|
|
45
|
+
error.value = e;
|
|
46
|
+
onError?.(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
isLoading.value = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function stop() {
|
|
54
|
+
abortController?.abort();
|
|
55
|
+
isLoading.value = false;
|
|
56
|
+
}
|
|
57
|
+
function setCompletion(value) {
|
|
58
|
+
completion.value = value;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
completion: () => completion.value,
|
|
62
|
+
isLoading: () => isLoading.value,
|
|
63
|
+
error: () => error.value,
|
|
64
|
+
setCompletion,
|
|
65
|
+
complete,
|
|
66
|
+
stop,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=use-completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-completion.js","sourceRoot":"","sources":["../../../src/frameworks/qwik/use-completion.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAiB7C,MAAM,UAAU,aAAa,CAAC,OAAO,GAAyB,EAAE;IAC9D,MAAM,EAAE,GAAG,GAAG,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE/D,MAAM,UAAU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AC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;gBAChD,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC;YAC1B,CAAC;YAED,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAK,GAAa,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBACzC,MAAM,CAAC,GAAG,GAAY,CAAC;gBACvB,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC;gBAChB,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;YACf,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,SAAS,IAAI;QACX,eAAe,EAAE,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC;IAC1B,CAAC;IAED,SAAS,aAAa,CAAC,KAAa;QAClC,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,OAAO;QACL,UAAU,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK;QAClC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK;QAChC,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK;QACxB,aAAa;QACb,QAAQ;QACR,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/react — Generative UI
|
|
3
|
+
*
|
|
4
|
+
* Allows tool calls to render custom React components inline.
|
|
5
|
+
* Components are rendered server-side and serialized for client consumption.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { streamUI } from "@hilbras/sdk/react";
|
|
10
|
+
* import { WeatherCard } from "./components";
|
|
11
|
+
*
|
|
12
|
+
* const result = await streamUI({
|
|
13
|
+
* model: "gpt-4o",
|
|
14
|
+
* messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
|
|
15
|
+
* tools: {
|
|
16
|
+
* get_weather: {
|
|
17
|
+
* render: async (args) => {
|
|
18
|
+
* const weather = await fetchWeather(args.city);
|
|
19
|
+
* return <WeatherCard city={args.city} temp={weather.temp} />;
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import type { ReactNode } from "react";
|
|
27
|
+
/** A serializable component reference */
|
|
28
|
+
export interface ComponentRef {
|
|
29
|
+
/** Component name (must be registered in the registry) */
|
|
30
|
+
name: string;
|
|
31
|
+
/** Props to pass to the component */
|
|
32
|
+
props: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/** A rendered component result */
|
|
35
|
+
export interface RenderedComponent {
|
|
36
|
+
type: "component";
|
|
37
|
+
/** The component reference (serializable) */
|
|
38
|
+
ref: ComponentRef;
|
|
39
|
+
/** The actual React element (client-side only, not serialized) */
|
|
40
|
+
element?: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
/** A tool definition with optional render function for generative UI */
|
|
43
|
+
export interface GenerativeTool<TArgs = Record<string, unknown>> {
|
|
44
|
+
/** Description of the tool for the LLM */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** JSON Schema for the tool's parameters */
|
|
47
|
+
parameters?: Record<string, unknown>;
|
|
48
|
+
/** Execute the tool and return data */
|
|
49
|
+
execute?: (args: TArgs) => Promise<unknown> | unknown;
|
|
50
|
+
/** Render a React component for the tool result */
|
|
51
|
+
render?: (args: TArgs) => Promise<ReactNode> | ReactNode;
|
|
52
|
+
}
|
|
53
|
+
/** Options for the streamUI function */
|
|
54
|
+
export interface StreamUIOptions {
|
|
55
|
+
/** Provider to use */
|
|
56
|
+
provider?: string;
|
|
57
|
+
/** Model to use */
|
|
58
|
+
model?: string;
|
|
59
|
+
/** Messages for the conversation */
|
|
60
|
+
messages: Array<{
|
|
61
|
+
role: string;
|
|
62
|
+
content: string;
|
|
63
|
+
}>;
|
|
64
|
+
/** Tools with optional render functions */
|
|
65
|
+
tools: Record<string, GenerativeTool>;
|
|
66
|
+
/** Component registry for deserializing components on the client */
|
|
67
|
+
componentRegistry?: Record<string, React.ComponentType<Record<string, unknown>>>;
|
|
68
|
+
}
|
|
69
|
+
/** Result of a streamUI call */
|
|
70
|
+
export interface StreamUIResult {
|
|
71
|
+
/** The rendered content (mix of text and components) */
|
|
72
|
+
content: ReactNode[];
|
|
73
|
+
/** Tool invocations with their rendered components */
|
|
74
|
+
toolInvocations: Array<{
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
args: Record<string, unknown>;
|
|
78
|
+
result?: unknown;
|
|
79
|
+
rendered?: ReactNode;
|
|
80
|
+
}>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Registry for mapping component names to React components.
|
|
84
|
+
* Used for deserializing ComponentRefs on the client side.
|
|
85
|
+
*/
|
|
86
|
+
export declare class ComponentRegistry {
|
|
87
|
+
private _components;
|
|
88
|
+
/** Register a component */
|
|
89
|
+
register(name: string, component: React.ComponentType<Record<string, unknown>>): void;
|
|
90
|
+
/** Register multiple components */
|
|
91
|
+
registerAll(components: Record<string, React.ComponentType<Record<string, unknown>>>): void;
|
|
92
|
+
/** Get a registered component */
|
|
93
|
+
get(name: string): React.ComponentType<Record<string, unknown>> | undefined;
|
|
94
|
+
/** Check if a component is registered */
|
|
95
|
+
has(name: string): boolean;
|
|
96
|
+
/** Get all registered component names */
|
|
97
|
+
names(): string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Deserialize a ComponentRef into a React element.
|
|
101
|
+
* Requires a ComponentRegistry with the referenced component registered.
|
|
102
|
+
*
|
|
103
|
+
* @param ref - The serializable component reference
|
|
104
|
+
* @param registry - The component registry
|
|
105
|
+
* @returns The React element, or a fallback element if not found
|
|
106
|
+
*/
|
|
107
|
+
export declare function deserializeComponent(ref: ComponentRef, registry: ComponentRegistry): ReactNode;
|
|
108
|
+
/**
|
|
109
|
+
* Serialize a React element into a ComponentRef.
|
|
110
|
+
* Useful for server-side rendering tool results.
|
|
111
|
+
*
|
|
112
|
+
* @param element - The React element to serialize
|
|
113
|
+
* @param registry - The component registry
|
|
114
|
+
* @returns The serializable component reference, or null if not serializable
|
|
115
|
+
*/
|
|
116
|
+
export declare function serializeComponent(element: ReactNode, registry: ComponentRegistry): ComponentRef | null;
|
|
117
|
+
/**
|
|
118
|
+
* Initialize the generative UI module.
|
|
119
|
+
* Must be called before using serializeComponent/deserializeComponent.
|
|
120
|
+
*/
|
|
121
|
+
export declare function initGenerativeUI(): void;
|
|
122
|
+
//# sourceMappingURL=generative-ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generative-ui.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/generative-ui.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,kCAAkC;AAClC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,6CAA6C;IAC7C,GAAG,EAAE,YAAY,CAAC;IAClB,kEAAkE;IAClE,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB;AAED,wEAAwE;AACxE,MAAM,WAAW,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,M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E,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,CAEpF;IAED,mCAAmC;IACnC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAI1F;IAED,iCAAiC;IACjC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAE1E;IAED,yCAAyC;IACzC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,yCAAyC;IACzC,KAAK,IAAI,MAAM,EAAE,CAEhB;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,iBAAiB,GAC1B,SAAS,CAOX;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,EAClB,QAAQ,EAAE,iBAAiB,GAC1B,YAAY,GAAG,IAAI,CAiBrB;AAKD;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAYvC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/react — Generative UI
|
|
3
|
+
*
|
|
4
|
+
* Allows tool calls to render custom React components inline.
|
|
5
|
+
* Components are rendered server-side and serialized for client consumption.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { streamUI } from "@hilbras/sdk/react";
|
|
10
|
+
* import { WeatherCard } from "./components";
|
|
11
|
+
*
|
|
12
|
+
* const result = await streamUI({
|
|
13
|
+
* model: "gpt-4o",
|
|
14
|
+
* messages: [{ role: "user", content: "What's the weather in Tokyo?" }],
|
|
15
|
+
* tools: {
|
|
16
|
+
* get_weather: {
|
|
17
|
+
* render: async (args) => {
|
|
18
|
+
* const weather = await fetchWeather(args.city);
|
|
19
|
+
* return <WeatherCard city={args.city} temp={weather.temp} />;
|
|
20
|
+
* },
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Registry for mapping component names to React components.
|
|
28
|
+
* Used for deserializing ComponentRefs on the client side.
|
|
29
|
+
*/
|
|
30
|
+
export class ComponentRegistry {
|
|
31
|
+
_components = new Map();
|
|
32
|
+
/** Register a component */
|
|
33
|
+
register(name, component) {
|
|
34
|
+
this._components.set(name, component);
|
|
35
|
+
}
|
|
36
|
+
/** Register multiple components */
|
|
37
|
+
registerAll(components) {
|
|
38
|
+
for (const [name, component] of Object.entries(components)) {
|
|
39
|
+
this._components.set(name, component);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Get a registered component */
|
|
43
|
+
get(name) {
|
|
44
|
+
return this._components.get(name);
|
|
45
|
+
}
|
|
46
|
+
/** Check if a component is registered */
|
|
47
|
+
has(name) {
|
|
48
|
+
return this._components.has(name);
|
|
49
|
+
}
|
|
50
|
+
/** Get all registered component names */
|
|
51
|
+
names() {
|
|
52
|
+
return Array.from(this._components.keys());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Deserialize a ComponentRef into a React element.
|
|
57
|
+
* Requires a ComponentRegistry with the referenced component registered.
|
|
58
|
+
*
|
|
59
|
+
* @param ref - The serializable component reference
|
|
60
|
+
* @param registry - The component registry
|
|
61
|
+
* @returns The React element, or a fallback element if not found
|
|
62
|
+
*/
|
|
63
|
+
export function deserializeComponent(ref, registry) {
|
|
64
|
+
const Component = registry.get(ref.name);
|
|
65
|
+
if (!Component) {
|
|
66
|
+
// Return a fallback element
|
|
67
|
+
return `Unknown component: ${ref.name}`;
|
|
68
|
+
}
|
|
69
|
+
return createElement(Component, ref.props);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Serialize a React element into a ComponentRef.
|
|
73
|
+
* Useful for server-side rendering tool results.
|
|
74
|
+
*
|
|
75
|
+
* @param element - The React element to serialize
|
|
76
|
+
* @param registry - The component registry
|
|
77
|
+
* @returns The serializable component reference, or null if not serializable
|
|
78
|
+
*/
|
|
79
|
+
export function serializeComponent(element, registry) {
|
|
80
|
+
// Check if element is a React element with type and props
|
|
81
|
+
if (element &&
|
|
82
|
+
typeof element === "object" &&
|
|
83
|
+
"type" in element &&
|
|
84
|
+
"props" in element) {
|
|
85
|
+
const el = element;
|
|
86
|
+
if (typeof el.type === "string" && registry.has(el.type)) {
|
|
87
|
+
return {
|
|
88
|
+
name: el.type,
|
|
89
|
+
props: el.props,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/** React.createElement import (lazy) */
|
|
96
|
+
let createElement;
|
|
97
|
+
/**
|
|
98
|
+
* Initialize the generative UI module.
|
|
99
|
+
* Must be called before using serializeComponent/deserializeComponent.
|
|
100
|
+
*/
|
|
101
|
+
export function initGenerativeUI() {
|
|
102
|
+
try {
|
|
103
|
+
// Dynamic import to avoid hard dependency on React
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
105
|
+
const react = require("react");
|
|
106
|
+
createElement = react.createElement;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
throw new Error("Generative UI requires React to be installed. " +
|
|
110
|
+
"Install it with: npm install react");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Auto-initialize on import
|
|
114
|
+
try {
|
|
115
|
+
initGenerativeUI();
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// React may not be available — that's OK, the error will surface when trying to use generative UI
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=generative-ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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AS,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAkB,EAClB,QAA2B;IAE3B,0DAA0D;IAC1D,IACE,OAAO;QACP,OAAO,OAAO,KAAK,QAAQ;QAC3B,MAAM,IAAI,OAAO;QACjB,OAAO,IAAI,OAAO,EAClB,CAAC;QACD,MAAM,EAAE,GAAG,OAA4D,CAAC;QACxE,IAAI,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,OAAO;gBACL,IAAI,EAAE,EAAE,CAAC,IAAI;gBACb,KAAK,EAAE,EAAE,CAAC,KAAK;aAChB,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,wCAAwC;AACxC,IAAI,aAAmD,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,CAAC;QACH,mDAAmD;QACnD,iEAAiE;QACjE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAC/B,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,gDAAgD;YAChD,oCAAoC,CACrC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,4BAA4B;AAC5B,IAAI,CAAC;IACH,gBAAgB,EAAE,CAAC;AACrB,CAAC;AAAC,MAAM,CAAC;IACP,kGAAkG;AACpG,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/react — React Hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for building streaming LLM UIs with @hilbras/sdk.
|
|
5
|
+
*/
|
|
6
|
+
export { useChat } from "./use-chat.js";
|
|
7
|
+
export type { UseChatReturn } from "./use-chat.js";
|
|
8
|
+
export { useCompletion } from "./use-completion.js";
|
|
9
|
+
export type { UseCompletionReturn } from "./use-completion.js";
|
|
10
|
+
export { useObject } from "./use-object.js";
|
|
11
|
+
export type { UseObjectReturn, UseObjectOptions, UseObjectState, UseObjectActions } from "./use-object.js";
|
|
12
|
+
export { parseUIStream } from "./stream-parser.js";
|
|
13
|
+
export { ComponentRegistry, deserializeComponent, serializeComponent, initGenerativeUI, } from "./generative-ui.js";
|
|
14
|
+
export type { ComponentRef, RenderedComponent, GenerativeTool, StreamUIOptions, StreamUIResult, } from "./generative-ui.js";
|
|
15
|
+
export type { UIMessage, UIToolInvocation, DataAnnotation, UIProtocolMessage, UseChatOptions, UseChatState, UseChatActions, UseCompletionOptions, UseCompletionState, UseCompletionActions, } from "../../index.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAE3G,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/react — React Hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for building streaming LLM UIs with @hilbras/sdk.
|
|
5
|
+
*/
|
|
6
|
+
export { useChat } from "./use-chat.js";
|
|
7
|
+
export { useCompletion } from "./use-completion.js";
|
|
8
|
+
export { useObject } from "./use-object.js";
|
|
9
|
+
export { parseUIStream } from "./stream-parser.js";
|
|
10
|
+
export { ComponentRegistry, deserializeComponent, serializeComponent, initGenerativeUI, } from "./generative-ui.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frameworks/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/react — Stream Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses the UIMessage protocol from a ReadableStream and yields UIProtocolMessage objects.
|
|
5
|
+
*/
|
|
6
|
+
import type { UIProtocolMessage } from "../../index.js";
|
|
7
|
+
export declare function parseUIStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<UIProtocolMessage>;
|
|
8
|
+
//# sourceMappingURL=stream-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../../../src/frameworks/react/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,wBAAuB,aAAa,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,iBAAiB,CAAC,CAmCnC"}
|