@hilbras/sdk 0.26.0 → 0.26.6
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/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 +53 -0
- package/dist/frameworks/angular/chat.service.d.ts.map +1 -0
- package/dist/frameworks/angular/chat.service.js +154 -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 +42 -0
- package/dist/frameworks/astro/endpoints.d.ts.map +1 -0
- package/dist/frameworks/astro/endpoints.js +75 -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 +62 -0
- package/dist/frameworks/nextjs/route-handlers.d.ts.map +1 -0
- package/dist/frameworks/nextjs/route-handlers.js +74 -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/use-chat.d.ts +28 -0
- package/dist/frameworks/qwik/use-chat.d.ts.map +1 -0
- package/dist/frameworks/qwik/use-chat.js +91 -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/index.d.ts +14 -0
- package/dist/frameworks/react/index.d.ts.map +1 -0
- package/dist/frameworks/react/index.js +10 -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 +19 -0
- package/dist/frameworks/react/use-chat.d.ts.map +1 -0
- package/dist/frameworks/react/use-chat.js +173 -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 +38 -0
- package/dist/frameworks/remix/actions.d.ts.map +1 -0
- package/dist/frameworks/remix/actions.js +72 -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/use-chat.d.ts +28 -0
- package/dist/frameworks/solid/use-chat.d.ts.map +1 -0
- package/dist/frameworks/solid/use-chat.js +91 -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 +31 -0
- package/dist/frameworks/svelte/use-chat.d.ts.map +1 -0
- package/dist/frameworks/svelte/use-chat.js +146 -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 +64 -0
- package/dist/frameworks/vue/use-chat.d.ts.map +1 -0
- package/dist/frameworks/vue/use-chat.js +119 -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/package.json +97 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/angular — Object Service
|
|
3
|
+
*
|
|
4
|
+
* Angular service for streaming structured JSON output from an LLM backend.
|
|
5
|
+
* Uses Angular signals for reactive state management.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* @Component({ ... })
|
|
9
|
+
* export class ObjectComponent {
|
|
10
|
+
* obj = inject(HilbrasObjectService);
|
|
11
|
+
* partial = this.obj.object;
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
export interface ObjectOptions<T> {
|
|
15
|
+
api: string;
|
|
16
|
+
schemaName: string;
|
|
17
|
+
onFinish?: (object: T) => void;
|
|
18
|
+
onError?: (error: Error) => void;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
body?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export declare class HilbrasObjectService {
|
|
23
|
+
private _object;
|
|
24
|
+
private _isLoading;
|
|
25
|
+
private _error;
|
|
26
|
+
private _abortController;
|
|
27
|
+
readonly object: import("./angular-shim.js").Signal<Partial<unknown> | null>;
|
|
28
|
+
readonly isLoading: import("./angular-shim.js").Signal<boolean>;
|
|
29
|
+
readonly error: import("./angular-shim.js").Signal<Error | null>;
|
|
30
|
+
stop(): void;
|
|
31
|
+
clear(): void;
|
|
32
|
+
submit<T>(options: ObjectOptions<T>): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=object.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.service.d.ts","sourceRoot":"","sources":["../../../src/frameworks/angular/object.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,qBACa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAAyC;IACxD,OAAO,CAAC,UAAU,CAAiB;IACnC,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,gBAAgB,CAAgC;IAExD,QAAQ,CAAC,MAAM,8DAA6B;IAC5C,QAAQ,CAAC,SAAS,8CAAgC;IAClD,QAAQ,CAAC,KAAK,mDAA4B;IAE1C,IAAI,IAAI,IAAI,CAIX;IAED,KAAK,IAAI,IAAI,CAIZ;IAEK,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsExD;CACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/angular — Object Service
|
|
3
|
+
*
|
|
4
|
+
* Angular service for streaming structured JSON output from an LLM backend.
|
|
5
|
+
* Uses Angular signals for reactive state management.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* @Component({ ... })
|
|
9
|
+
* export class ObjectComponent {
|
|
10
|
+
* obj = inject(HilbrasObjectService);
|
|
11
|
+
* partial = this.obj.object;
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
};
|
|
20
|
+
import { Injectable, signal } from "./angular-shim.js";
|
|
21
|
+
let HilbrasObjectService = class HilbrasObjectService {
|
|
22
|
+
_object = signal(null);
|
|
23
|
+
_isLoading = signal(false);
|
|
24
|
+
_error = signal(null);
|
|
25
|
+
_abortController = null;
|
|
26
|
+
object = this._object.asReadonly();
|
|
27
|
+
isLoading = this._isLoading.asReadonly();
|
|
28
|
+
error = this._error.asReadonly();
|
|
29
|
+
stop() {
|
|
30
|
+
this._abortController?.abort();
|
|
31
|
+
this._abortController = null;
|
|
32
|
+
this._isLoading.set(false);
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
|
+
this._object.set(null);
|
|
36
|
+
this._error.set(null);
|
|
37
|
+
this.stop();
|
|
38
|
+
}
|
|
39
|
+
async submit(options) {
|
|
40
|
+
if (this._isLoading())
|
|
41
|
+
return;
|
|
42
|
+
this._object.set(null);
|
|
43
|
+
this._isLoading.set(true);
|
|
44
|
+
this._error.set(null);
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
this._abortController = controller;
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch(options.api, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json", ...options.headers },
|
|
51
|
+
body: JSON.stringify({
|
|
52
|
+
schema: options.schemaName,
|
|
53
|
+
stream: true,
|
|
54
|
+
...options.body,
|
|
55
|
+
}),
|
|
56
|
+
signal: controller.signal,
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
60
|
+
if (!res.body)
|
|
61
|
+
throw new Error("Response body is null");
|
|
62
|
+
const reader = res.body.getReader();
|
|
63
|
+
const decoder = new TextDecoder();
|
|
64
|
+
let buffer = "";
|
|
65
|
+
let partialArgs = "";
|
|
66
|
+
let result = {};
|
|
67
|
+
while (true) {
|
|
68
|
+
const { done, value } = await reader.read();
|
|
69
|
+
if (done)
|
|
70
|
+
break;
|
|
71
|
+
buffer += decoder.decode(value, { stream: true });
|
|
72
|
+
const parts = buffer.split("\n\n");
|
|
73
|
+
buffer = parts.pop() ?? "";
|
|
74
|
+
for (const part of parts) {
|
|
75
|
+
const lines = part.split("\n");
|
|
76
|
+
let rawData = "";
|
|
77
|
+
for (const line of lines) {
|
|
78
|
+
if (line.startsWith("data: "))
|
|
79
|
+
rawData = line.slice(6).trim();
|
|
80
|
+
}
|
|
81
|
+
if (!rawData || rawData === "[DONE]")
|
|
82
|
+
continue;
|
|
83
|
+
let data;
|
|
84
|
+
try {
|
|
85
|
+
data = JSON.parse(rawData);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (data.type === "tool_call_delta" && data.args) {
|
|
91
|
+
partialArgs += data.args;
|
|
92
|
+
try {
|
|
93
|
+
result = JSON.parse(partialArgs);
|
|
94
|
+
this._object.set({ ...result });
|
|
95
|
+
}
|
|
96
|
+
catch { /* partial JSON */ }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
options.onFinish?.(result);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err.name === "AbortError")
|
|
104
|
+
return;
|
|
105
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
106
|
+
this._error.set(error);
|
|
107
|
+
options.onError?.(error);
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
this._abortController = null;
|
|
111
|
+
this._isLoading.set(false);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
HilbrasObjectService = __decorate([
|
|
116
|
+
Injectable({ providedIn: "root" })
|
|
117
|
+
], HilbrasObjectService);
|
|
118
|
+
export { HilbrasObjectService };
|
|
119
|
+
//# sourceMappingURL=object.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.service.js","sourceRoot":"","sources":["../../../src/frameworks/angular/object.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;;;;;;;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAYhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACvB,OAAO,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IAChD,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,GAAG,MAAM,CAAe,IAAI,CAA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7FY,oBAAoB;IADhC,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;GACtB,oBAAoB,CA6FhC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Astro API Endpoint
|
|
3
|
+
*
|
|
4
|
+
* Create API endpoints for streaming chat/completion in Astro.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatMessage {
|
|
7
|
+
role: "user" | "assistant" | "system";
|
|
8
|
+
content: string;
|
|
9
|
+
}
|
|
10
|
+
export interface EndpointOptions {
|
|
11
|
+
provider: string;
|
|
12
|
+
model: string;
|
|
13
|
+
systemPrompt?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a streaming chat endpoint for Astro.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // src/pages/api/chat.ts
|
|
21
|
+
* import { createChatEndpoint } from "@hilbras/astro";
|
|
22
|
+
*
|
|
23
|
+
* export const { POST } = createChatEndpoint({
|
|
24
|
+
* provider: "OpenAI",
|
|
25
|
+
* model: "gpt-4o",
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function createChatEndpoint(options: EndpointOptions): {
|
|
30
|
+
POST: ({ request }: {
|
|
31
|
+
request: Request;
|
|
32
|
+
}) => Promise<Response>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create a non-streaming completion endpoint for Astro.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createCompletionEndpoint(options: EndpointOptions): {
|
|
38
|
+
POST: ({ request }: {
|
|
39
|
+
request: Request;
|
|
40
|
+
}) => Promise<Response>;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../../src/frameworks/astro/endpoints.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe;wBACxB;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,KAAG,OAAO,CAAC,QAAQ,CAAC;EAsC1E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,eAAe;wBAC9B;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,KAAG,OAAO,CAAC,QAAQ,CAAC;EAe1E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Astro API Endpoint
|
|
3
|
+
*
|
|
4
|
+
* Create API endpoints for streaming chat/completion in Astro.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Create a streaming chat endpoint for Astro.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // src/pages/api/chat.ts
|
|
12
|
+
* import { createChatEndpoint } from "@hilbras/astro";
|
|
13
|
+
*
|
|
14
|
+
* export const { POST } = createChatEndpoint({
|
|
15
|
+
* provider: "OpenAI",
|
|
16
|
+
* model: "gpt-4o",
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function createChatEndpoint(options) {
|
|
21
|
+
async function POST({ request }) {
|
|
22
|
+
const body = await request.json();
|
|
23
|
+
const { messages } = body;
|
|
24
|
+
const encoder = new TextEncoder();
|
|
25
|
+
const stream = new ReadableStream({
|
|
26
|
+
async start(controller) {
|
|
27
|
+
try {
|
|
28
|
+
const allMessages = options.systemPrompt
|
|
29
|
+
? [{ role: "system", content: options.systemPrompt }, ...messages]
|
|
30
|
+
: messages;
|
|
31
|
+
// Placeholder streaming response
|
|
32
|
+
for (const msg of allMessages) {
|
|
33
|
+
if (msg.role === "user") {
|
|
34
|
+
const response = `Response to: ${msg.content}`;
|
|
35
|
+
for (const char of response) {
|
|
36
|
+
controller.enqueue(encoder.encode(char));
|
|
37
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
controller.close();
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
controller.error(error);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return new Response(stream, {
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
51
|
+
"Cache-Control": "no-cache",
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return { POST };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a non-streaming completion endpoint for Astro.
|
|
59
|
+
*/
|
|
60
|
+
export function createCompletionEndpoint(options) {
|
|
61
|
+
async function POST({ request }) {
|
|
62
|
+
const body = await request.json();
|
|
63
|
+
return new Response(JSON.stringify({
|
|
64
|
+
id: `cmpl-${Date.now()}`,
|
|
65
|
+
choices: [{
|
|
66
|
+
message: { role: "assistant", content: `Response to: ${body.prompt || ""}` },
|
|
67
|
+
finishReason: "stop",
|
|
68
|
+
}],
|
|
69
|
+
}), {
|
|
70
|
+
headers: { "Content-Type": "application/json" },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return { POST };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../../src/frameworks/astro/endpoints.ts"],"names":[],"mappings":"AAAA;;;;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,CAAC,MAAM,EAAE;YAC1B,OAAO,EAAE;gBACP,cAAc,EAAE,2BAA2B;gBAC3C,eAAe,EAAE,UAAU;aAC5B;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAwB;IAC/D,KAAK,UAAU,IAAI,CAAC,EAAE,OAAO,EAAwB;QACnD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QAElC,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;YACjC,EAAE,EAAE,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE;YACxB,OAAO,EAAE,CAAC;oBACR,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,IAAI,CAAC,MAAM,IAAI,EAAE,EAAE,EAAE;oBAC5E,YAAY,EAAE,MAAM;iBACrB,CAAC;SACH,CAAC,EAAE;YACF,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;SAChD,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Client-side hooks
|
|
3
|
+
*/
|
|
4
|
+
export interface Message {
|
|
5
|
+
role: "user" | "assistant" | "system";
|
|
6
|
+
content: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UseChatOptions {
|
|
10
|
+
api?: string;
|
|
11
|
+
onFinish?: (message: Message) => void;
|
|
12
|
+
onError?: (error: Error) => void;
|
|
13
|
+
initialMessages?: Message[];
|
|
14
|
+
}
|
|
15
|
+
export interface UseChatReturn {
|
|
16
|
+
messages: Message[];
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
error: Error | null;
|
|
19
|
+
setMessages: (msgs: Message[]) => void;
|
|
20
|
+
append: (message: Message) => Promise<void>;
|
|
21
|
+
reload: () => Promise<void>;
|
|
22
|
+
stop: () => void;
|
|
23
|
+
clear: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create chat state for Astro islands.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createChatState(options?: UseChatOptions): UseChatReturn;
|
|
29
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/frameworks/astro/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACvC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CA+E3E"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Client-side hooks
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Create chat state for Astro islands.
|
|
6
|
+
*/
|
|
7
|
+
export function createChatState(options = {}) {
|
|
8
|
+
const { api = "/api/chat", onFinish, onError, initialMessages = [] } = options;
|
|
9
|
+
let _messages = [...initialMessages];
|
|
10
|
+
let _isLoading = false;
|
|
11
|
+
let _error = null;
|
|
12
|
+
let abortController = null;
|
|
13
|
+
async function sendRequest(msgs) {
|
|
14
|
+
_isLoading = true;
|
|
15
|
+
_error = null;
|
|
16
|
+
abortController = new AbortController();
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(api, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/json" },
|
|
21
|
+
body: JSON.stringify({ messages: msgs }),
|
|
22
|
+
signal: abortController.signal,
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
26
|
+
}
|
|
27
|
+
const reader = response.body?.getReader();
|
|
28
|
+
if (!reader)
|
|
29
|
+
throw new Error("No response body");
|
|
30
|
+
const decoder = new TextDecoder();
|
|
31
|
+
let text = "";
|
|
32
|
+
const assistantMsg = { role: "assistant", content: "", id: crypto.randomUUID() };
|
|
33
|
+
_messages = [..._messages, assistantMsg];
|
|
34
|
+
while (true) {
|
|
35
|
+
const { done, value } = await reader.read();
|
|
36
|
+
if (done)
|
|
37
|
+
break;
|
|
38
|
+
text += decoder.decode(value, { stream: true });
|
|
39
|
+
_messages = _messages.map((m, i) => i === _messages.length - 1 ? { ...m, content: text } : m);
|
|
40
|
+
}
|
|
41
|
+
onFinish?.({ ...assistantMsg, content: text });
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err.name !== "AbortError") {
|
|
45
|
+
_error = err;
|
|
46
|
+
onError?.(_error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
_isLoading = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
get messages() { return _messages; },
|
|
55
|
+
get isLoading() { return _isLoading; },
|
|
56
|
+
get error() { return _error; },
|
|
57
|
+
setMessages: (msgs) => { _messages = msgs; },
|
|
58
|
+
append: async (message) => {
|
|
59
|
+
const newMessages = [..._messages, message];
|
|
60
|
+
_messages = newMessages;
|
|
61
|
+
await sendRequest(newMessages);
|
|
62
|
+
},
|
|
63
|
+
reload: async () => {
|
|
64
|
+
if (_messages.length === 0)
|
|
65
|
+
return;
|
|
66
|
+
const userMsgs = _messages.slice(0, -1);
|
|
67
|
+
_messages = userMsgs;
|
|
68
|
+
await sendRequest(userMsgs);
|
|
69
|
+
},
|
|
70
|
+
stop: () => {
|
|
71
|
+
abortController?.abort();
|
|
72
|
+
_isLoading = false;
|
|
73
|
+
},
|
|
74
|
+
clear: () => {
|
|
75
|
+
_messages = [];
|
|
76
|
+
_error = null;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/frameworks/astro/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AA0BH;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAO,GAAmB,EAAE;IAC1D,MAAM,EAAE,GAAG,GAAG,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAE/E,IAAI,SAAS,GAAc,CAAC,GAAG,eAAe,CAAC,CAAC;IAChD,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,MAAM,GAAiB,IAAI,CAAC;IAChC,IAAI,eAAe,GAA2B,IA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C,CAAC,CAAC;YACxC,SAAS,GAAG,QAAQ,CAAC;YACrB,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,EAAE,GAAG,EAAE;YACT,eAAe,EAAE,KAAK,EAAE,CAAC;YACzB,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACV,SAAS,GAAG,EAAE,CAAC;YACf,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Astro Integration
|
|
3
|
+
*
|
|
4
|
+
* API endpoints and client-side hooks for Astro.
|
|
5
|
+
*/
|
|
6
|
+
export { createChatEndpoint, createCompletionEndpoint, type EndpointOptions, type ChatMessage } from "./endpoints.js";
|
|
7
|
+
export { createChatState, type UseChatOptions, type UseChatReturn, type Message } from "./hooks.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frameworks/astro/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACtH,OAAO,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/astro — Astro Integration
|
|
3
|
+
*
|
|
4
|
+
* API endpoints and client-side hooks for Astro.
|
|
5
|
+
*/
|
|
6
|
+
export { createChatEndpoint, createCompletionEndpoint } from "./endpoints.js";
|
|
7
|
+
export { createChatState } from "./hooks.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frameworks/astro/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAA0C,MAAM,gBAAgB,CAAC;AACtH,OAAO,EAAE,eAAe,EAAyD,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/nextjs — Client Components
|
|
3
|
+
*
|
|
4
|
+
* React components and hooks for Next.js client-side use.
|
|
5
|
+
*/
|
|
6
|
+
export { useChat } from "./use-chat.js";
|
|
7
|
+
export { useCompletion } from "./use-completion.js";
|
|
8
|
+
export interface Message {
|
|
9
|
+
role: "user" | "assistant" | "system";
|
|
10
|
+
content: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/frameworks/nextjs/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/frameworks/nextjs/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/nextjs — Next.js Integration
|
|
3
|
+
*
|
|
4
|
+
* Server-side:
|
|
5
|
+
* - createServerClient: Create a HilbrasClient for Server Components
|
|
6
|
+
* - ServerHilbrasClient: Server client with streaming helpers
|
|
7
|
+
*
|
|
8
|
+
* Route Handlers:
|
|
9
|
+
* - createChatHandler: Streaming chat endpoint
|
|
10
|
+
* - createCompletionHandler: Non-streaming completion endpoint
|
|
11
|
+
*
|
|
12
|
+
* Client-side:
|
|
13
|
+
* - useChat: Streaming chat hook
|
|
14
|
+
* - useCompletion: Text completion hook
|
|
15
|
+
*/
|
|
16
|
+
export { createServerClient, ServerHilbrasClient, type ServerClientOptions } from "./server.js";
|
|
17
|
+
export { createChatHandler, createCompletionHandler, type ChatRequest, type ChatResponse } from "./route-handlers.js";
|
|
18
|
+
export { useChat, type UseChatOptions, type UseChatReturn } from "./use-chat.js";
|
|
19
|
+
export { useCompletion, type UseCompletionOptions, type UseCompletionReturn } from "./use-completion.js";
|
|
20
|
+
export type { Message } from "./client.js";
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frameworks/nextjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzG,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/nextjs — Next.js Integration
|
|
3
|
+
*
|
|
4
|
+
* Server-side:
|
|
5
|
+
* - createServerClient: Create a HilbrasClient for Server Components
|
|
6
|
+
* - ServerHilbrasClient: Server client with streaming helpers
|
|
7
|
+
*
|
|
8
|
+
* Route Handlers:
|
|
9
|
+
* - createChatHandler: Streaming chat endpoint
|
|
10
|
+
* - createCompletionHandler: Non-streaming completion endpoint
|
|
11
|
+
*
|
|
12
|
+
* Client-side:
|
|
13
|
+
* - useChat: Streaming chat hook
|
|
14
|
+
* - useCompletion: Text completion hook
|
|
15
|
+
*/
|
|
16
|
+
export { createServerClient, ServerHilbrasClient } from "./server.js";
|
|
17
|
+
export { createChatHandler, createCompletionHandler } from "./route-handlers.js";
|
|
18
|
+
export { useChat } from "./use-chat.js";
|
|
19
|
+
export { useCompletion } from "./use-completion.js";
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frameworks/nextjs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAA4B,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAuC,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAE,OAAO,EAA2C,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,aAAa,EAAuD,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hilbras/nextjs — Route Handler Helpers
|
|
3
|
+
*
|
|
4
|
+
* Helpers for Next.js App Router route handlers.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatRequest {
|
|
7
|
+
messages: Array<{
|
|
8
|
+
role: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}>;
|
|
11
|
+
model?: string;
|
|
12
|
+
provider?: string;
|
|
13
|
+
systemPrompt?: string;
|
|
14
|
+
temperature?: number;
|
|
15
|
+
maxTokens?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ChatResponse {
|
|
18
|
+
id: string;
|
|
19
|
+
choices: Array<{
|
|
20
|
+
message: {
|
|
21
|
+
role: string;
|
|
22
|
+
content: string;
|
|
23
|
+
};
|
|
24
|
+
finishReason: string;
|
|
25
|
+
}>;
|
|
26
|
+
usage?: {
|
|
27
|
+
promptTokens: number;
|
|
28
|
+
completionTokens: number;
|
|
29
|
+
totalTokens: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a streaming chat endpoint handler.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // app/api/chat/route.ts
|
|
38
|
+
* import { createChatHandler } from "@hilbras/nextjs";
|
|
39
|
+
*
|
|
40
|
+
* export const { POST } = createChatHandler({
|
|
41
|
+
* provider: "OpenAI",
|
|
42
|
+
* model: "gpt-4o",
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function createChatHandler(options: {
|
|
47
|
+
provider: string;
|
|
48
|
+
model: string;
|
|
49
|
+
systemPrompt?: string;
|
|
50
|
+
}): {
|
|
51
|
+
POST: (req: Request) => Promise<Response>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Create a non-streaming completion endpoint handler.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createCompletionHandler(options: {
|
|
57
|
+
provider: string;
|
|
58
|
+
model: string;
|
|
59
|
+
}): {
|
|
60
|
+
POST: (req: Request) => Promise<Response>;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=route-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-handlers.d.ts","sourceRoot":"","sources":["../../../src/frameworks/nextjs/route-handlers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;QACb,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3C,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;gBAC0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;EA8BrD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;gBAC0B,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC;EAqBrD"}
|