@ai-sdk/angular 3.0.0-beta.87 → 3.0.0-beta.88
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/CHANGELOG.md +12 -0
- package/dist/index.js +46 -61
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/index.d.mts +0 -113
- package/dist/index.mjs +0 -305
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/angular
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.88
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ef992f8: Remove CommonJS exports from all packages. All packages are now ESM-only (`"type": "module"`). Consumers using `require()` must switch to ESM `import` syntax.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ef992f8]
|
|
12
|
+
- ai@7.0.0-beta.88
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.0-beta.19
|
|
14
|
+
|
|
3
15
|
## 3.0.0-beta.87
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,35 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
Chat: () => Chat,
|
|
24
|
-
Completion: () => Completion,
|
|
25
|
-
StructuredObject: () => StructuredObject
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
|
|
29
1
|
// src/lib/chat.ng.ts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import { signal } from "@angular/core";
|
|
3
|
+
import {
|
|
4
|
+
AbstractChat
|
|
5
|
+
} from "ai";
|
|
6
|
+
var Chat = class extends AbstractChat {
|
|
33
7
|
constructor(init) {
|
|
34
8
|
super({
|
|
35
9
|
...init,
|
|
@@ -39,9 +13,9 @@ var Chat = class extends import_ai.AbstractChat {
|
|
|
39
13
|
};
|
|
40
14
|
var AngularChatState = class {
|
|
41
15
|
constructor(initialMessages = []) {
|
|
42
|
-
this.#messages =
|
|
43
|
-
this.#status =
|
|
44
|
-
this.#error =
|
|
16
|
+
this.#messages = signal([]);
|
|
17
|
+
this.#status = signal("ready");
|
|
18
|
+
this.#error = signal(void 0);
|
|
45
19
|
this.setMessages = (messages) => {
|
|
46
20
|
this.#messages.set([...messages]);
|
|
47
21
|
};
|
|
@@ -85,16 +59,19 @@ var AngularChatState = class {
|
|
|
85
59
|
};
|
|
86
60
|
|
|
87
61
|
// src/lib/completion.ng.ts
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
62
|
+
import { signal as signal2 } from "@angular/core";
|
|
63
|
+
import {
|
|
64
|
+
callCompletionApi,
|
|
65
|
+
generateId
|
|
66
|
+
} from "ai";
|
|
67
|
+
import { normalizeHeaders } from "@ai-sdk/provider-utils";
|
|
91
68
|
var Completion = class {
|
|
92
69
|
constructor(options = {}) {
|
|
93
70
|
// Reactive state
|
|
94
|
-
this.#input = (
|
|
95
|
-
this.#completion = (
|
|
96
|
-
this.#error = (
|
|
97
|
-
this.#loading = (
|
|
71
|
+
this.#input = signal2("");
|
|
72
|
+
this.#completion = signal2("");
|
|
73
|
+
this.#error = signal2(void 0);
|
|
74
|
+
this.#loading = signal2(false);
|
|
98
75
|
this.#abortController = null;
|
|
99
76
|
/** Abort the current request immediately, keep the generated tokens if any. */
|
|
100
77
|
this.stop = () => {
|
|
@@ -116,13 +93,13 @@ var Completion = class {
|
|
|
116
93
|
}
|
|
117
94
|
};
|
|
118
95
|
this.#triggerRequest = async (prompt, options) => {
|
|
119
|
-
return
|
|
96
|
+
return callCompletionApi({
|
|
120
97
|
api: this.api,
|
|
121
98
|
prompt,
|
|
122
99
|
credentials: this.#options.credentials,
|
|
123
100
|
headers: {
|
|
124
|
-
...
|
|
125
|
-
...
|
|
101
|
+
...normalizeHeaders(this.#options.headers),
|
|
102
|
+
...normalizeHeaders(options?.headers)
|
|
126
103
|
},
|
|
127
104
|
body: {
|
|
128
105
|
...this.#options.body,
|
|
@@ -150,7 +127,7 @@ var Completion = class {
|
|
|
150
127
|
this.#completion.set(options.initialCompletion ?? "");
|
|
151
128
|
this.#input.set(options.initialInput ?? "");
|
|
152
129
|
this.api = options.api ?? "/api/completion";
|
|
153
|
-
this.id = options.id ??
|
|
130
|
+
this.id = options.id ?? generateId();
|
|
154
131
|
this.streamProtocol = options.streamProtocol ?? "data";
|
|
155
132
|
}
|
|
156
133
|
#options;
|
|
@@ -185,15 +162,24 @@ var Completion = class {
|
|
|
185
162
|
};
|
|
186
163
|
|
|
187
164
|
// src/lib/structured-object.ng.ts
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
165
|
+
import {
|
|
166
|
+
generateId as generateId2,
|
|
167
|
+
isAbortError,
|
|
168
|
+
normalizeHeaders as normalizeHeaders2,
|
|
169
|
+
safeValidateTypes
|
|
170
|
+
} from "@ai-sdk/provider-utils";
|
|
171
|
+
import { signal as signal3 } from "@angular/core";
|
|
172
|
+
import {
|
|
173
|
+
asSchema,
|
|
174
|
+
isDeepEqualData,
|
|
175
|
+
parsePartialJson
|
|
176
|
+
} from "ai";
|
|
191
177
|
var StructuredObject = class {
|
|
192
178
|
constructor(options) {
|
|
193
179
|
// Reactive state
|
|
194
|
-
this.#object = (
|
|
195
|
-
this.#loading = (
|
|
196
|
-
this.#error = (
|
|
180
|
+
this.#object = signal3(void 0);
|
|
181
|
+
this.#loading = signal3(false);
|
|
182
|
+
this.#error = signal3(void 0);
|
|
197
183
|
/**
|
|
198
184
|
* Abort the current request immediately, keep the current partial object if any.
|
|
199
185
|
*/
|
|
@@ -221,7 +207,7 @@ var StructuredObject = class {
|
|
|
221
207
|
method: "POST",
|
|
222
208
|
headers: {
|
|
223
209
|
"Content-Type": "application/json",
|
|
224
|
-
...(
|
|
210
|
+
...normalizeHeaders2(this.options.headers)
|
|
225
211
|
},
|
|
226
212
|
credentials: this.options.credentials,
|
|
227
213
|
signal: abortController.signal,
|
|
@@ -244,9 +230,9 @@ var StructuredObject = class {
|
|
|
244
230
|
throw new DOMException("Stream aborted", "AbortError");
|
|
245
231
|
}
|
|
246
232
|
accumulatedText += chunk;
|
|
247
|
-
const { value } = await
|
|
233
|
+
const { value } = await parsePartialJson(accumulatedText);
|
|
248
234
|
const currentObject = value;
|
|
249
|
-
if (!
|
|
235
|
+
if (!isDeepEqualData(latestObject, currentObject)) {
|
|
250
236
|
latestObject = currentObject;
|
|
251
237
|
this.#object.set(currentObject);
|
|
252
238
|
}
|
|
@@ -255,9 +241,9 @@ var StructuredObject = class {
|
|
|
255
241
|
this.#loading.set(false);
|
|
256
242
|
this.#abortController = void 0;
|
|
257
243
|
if (this.options.onFinish != null) {
|
|
258
|
-
const validationResult = await
|
|
244
|
+
const validationResult = await safeValidateTypes({
|
|
259
245
|
value: latestObject,
|
|
260
|
-
schema:
|
|
246
|
+
schema: asSchema(this.options.schema)
|
|
261
247
|
});
|
|
262
248
|
if (validationResult.success) {
|
|
263
249
|
this.options.onFinish({
|
|
@@ -275,7 +261,7 @@ var StructuredObject = class {
|
|
|
275
261
|
})
|
|
276
262
|
);
|
|
277
263
|
} catch (error) {
|
|
278
|
-
if (
|
|
264
|
+
if (isAbortError(error)) {
|
|
279
265
|
return;
|
|
280
266
|
}
|
|
281
267
|
const coalescedError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -287,7 +273,7 @@ var StructuredObject = class {
|
|
|
287
273
|
}
|
|
288
274
|
};
|
|
289
275
|
this.options = options;
|
|
290
|
-
this.id = options.id ?? (
|
|
276
|
+
this.id = options.id ?? generateId2();
|
|
291
277
|
this.#object.set(options.initialValue);
|
|
292
278
|
}
|
|
293
279
|
#abortController;
|
|
@@ -311,10 +297,9 @@ var StructuredObject = class {
|
|
|
311
297
|
return this.#loading();
|
|
312
298
|
}
|
|
313
299
|
};
|
|
314
|
-
|
|
315
|
-
0 && (module.exports = {
|
|
300
|
+
export {
|
|
316
301
|
Chat,
|
|
317
302
|
Completion,
|
|
318
303
|
StructuredObject
|
|
319
|
-
}
|
|
304
|
+
};
|
|
320
305
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/chat.ng.ts","../src/lib/completion.ng.ts","../src/lib/structured-object.ng.ts"],"sourcesContent":["export { Chat } from './lib/chat.ng';\nexport { Completion, type CompletionOptions } from './lib/completion.ng';\nexport {\n StructuredObject,\n type StructuredObjectOptions,\n} from './lib/structured-object.ng';\n","import { signal } from '@angular/core';\nimport {\n type ChatState,\n type ChatStatus,\n type UIMessage,\n type ChatInit,\n AbstractChat,\n} from 'ai';\n\nexport class Chat<\n UI_MESSAGE extends UIMessage = UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor(init: ChatInit<UI_MESSAGE>) {\n super({\n ...init,\n state: new AngularChatState(init.messages),\n });\n }\n}\n\nclass AngularChatState<\n UI_MESSAGE extends UIMessage = UIMessage,\n> implements ChatState<UI_MESSAGE> {\n readonly #messages = signal<UI_MESSAGE[]>([]);\n readonly #status = signal<ChatStatus>('ready');\n readonly #error = signal<Error | undefined>(undefined);\n\n get messages(): UI_MESSAGE[] {\n return this.#messages();\n }\n\n set messages(messages: UI_MESSAGE[]) {\n this.#messages.set([...messages]);\n }\n\n get status(): ChatStatus {\n return this.#status();\n }\n\n set status(status: ChatStatus) {\n this.#status.set(status);\n }\n\n get error(): Error | undefined {\n return this.#error();\n }\n\n set error(error: Error | undefined) {\n this.#error.set(error);\n }\n\n constructor(initialMessages: UI_MESSAGE[] = []) {\n this.#messages.set([...initialMessages]);\n }\n\n setMessages = (messages: UI_MESSAGE[]) => {\n this.#messages.set([...messages]);\n };\n\n pushMessage = (message: UI_MESSAGE) => {\n this.#messages.update(msgs => [...msgs, message]);\n };\n\n popMessage = () => {\n this.#messages.update(msgs => msgs.slice(0, -1));\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n this.#messages.update(msgs => {\n const copy = [...msgs];\n copy[index] = message;\n return copy;\n });\n };\n\n snapshot = <T>(thing: T): T => structuredClone(thing);\n}\n","import { signal } from '@angular/core';\nimport {\n callCompletionApi,\n generateId,\n type CompletionRequestOptions,\n type UseCompletionOptions,\n} from 'ai';\nimport { normalizeHeaders } from '@ai-sdk/provider-utils';\n\nexport type CompletionOptions = Readonly<UseCompletionOptions>;\n\nexport class Completion {\n readonly #options: CompletionOptions;\n\n // Static config\n readonly id: string;\n readonly api: string;\n readonly streamProtocol: 'data' | 'text';\n\n // Reactive state\n readonly #input = signal('');\n readonly #completion = signal<string>('');\n readonly #error = signal<Error | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n\n #abortController: AbortController | null = null;\n\n constructor(options: CompletionOptions = {}) {\n this.#options = options;\n this.#completion.set(options.initialCompletion ?? '');\n this.#input.set(options.initialInput ?? '');\n this.api = options.api ?? '/api/completion';\n this.id = options.id ?? generateId();\n this.streamProtocol = options.streamProtocol ?? 'data';\n }\n\n /** Current value of the completion. Writable. */\n get completion(): string {\n return this.#completion();\n }\n set completion(value: string) {\n this.#completion.set(value);\n }\n\n /** Current value of the input. Writable. */\n get input(): string {\n return this.#input();\n }\n set input(value: string) {\n this.#input.set(value);\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /** Flag that indicates whether an API request is in progress. */\n get loading(): boolean {\n return this.#loading();\n }\n\n /** Abort the current request immediately, keep the generated tokens if any. */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = null;\n }\n };\n\n /** Send a new prompt to the API endpoint and update the completion state. */\n complete = async (prompt: string, options?: CompletionRequestOptions) =>\n this.#triggerRequest(prompt, options);\n\n /** Form submission handler to automatically reset input and call the completion API */\n handleSubmit = async (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n if (this.#input()) {\n await this.complete(this.#input());\n }\n };\n\n #triggerRequest = async (\n prompt: string,\n options?: CompletionRequestOptions,\n ) => {\n return callCompletionApi({\n api: this.api,\n prompt,\n credentials: this.#options.credentials,\n headers: {\n ...normalizeHeaders(this.#options.headers),\n ...normalizeHeaders(options?.headers),\n },\n body: {\n ...this.#options.body,\n ...options?.body,\n },\n streamProtocol: this.streamProtocol,\n fetch: this.#options.fetch,\n setCompletion: (completion: string) => {\n this.#completion.set(completion);\n },\n setLoading: (loading: boolean) => {\n this.#loading.set(loading);\n },\n setError: (error: any) => {\n this.#error.set(error);\n },\n setAbortController: abortController => {\n this.#abortController = abortController ?? null;\n },\n onFinish: this.#options.onFinish,\n onError: this.#options.onError,\n });\n };\n}\n","import {\n generateId,\n isAbortError,\n normalizeHeaders,\n safeValidateTypes,\n type FetchFunction,\n type FlexibleSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { signal } from '@angular/core';\nimport {\n asSchema,\n isDeepEqualData,\n parsePartialJson,\n type DeepPartial,\n} from 'ai';\n\nexport type StructuredObjectOptions<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n> = {\n /**\n * The API endpoint. It should stream JSON that matches the schema as chunked text.\n */\n api: string;\n\n /**\n * A schema that defines the shape of the complete object.\n */\n schema: SCHEMA;\n\n /**\n * A unique identifier. If not provided, a random one will be\n * generated. When provided, the `useObject` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * An optional value for the initial object.\n */\n initialValue?: DeepPartial<RESULT>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Callback that is called when the stream has finished.\n */\n onFinish?: (event: {\n /**\n * The generated object (typed according to the schema).\n * Can be undefined if the final object does not match the schema.\n */\n object: RESULT | undefined;\n\n /**\n * Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.\n */\n error: Error | undefined;\n }) => Promise<void> | void;\n\n /**\n * Callback function to be called when an error is encountered.\n */\n onError?: (error: Error) => void;\n\n /**\n * Additional HTTP headers to be included in the request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n};\n\nexport class StructuredObject<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n INPUT = unknown,\n> {\n readonly options: StructuredObjectOptions<SCHEMA, RESULT>;\n readonly id: string;\n #abortController: AbortController | undefined;\n\n // Reactive state\n readonly #object = signal<DeepPartial<RESULT> | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n readonly #error = signal<Error | undefined>(undefined);\n\n /**\n * The current value for the generated object. Updated as the API streams JSON chunks.\n */\n get object(): DeepPartial<RESULT> | undefined {\n return this.#object();\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /**\n * Flag that indicates whether an API request is in progress.\n */\n get loading(): boolean {\n return this.#loading();\n }\n\n constructor(options: StructuredObjectOptions<SCHEMA, RESULT>) {\n this.options = options;\n this.id = options.id ?? generateId();\n this.#object.set(options.initialValue);\n }\n\n /**\n * Abort the current request immediately, keep the current partial object if any.\n */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = undefined;\n }\n };\n\n /**\n * Calls the API with the provided input as JSON body.\n */\n submit = async (input: INPUT) => {\n try {\n this.#object.set(undefined); // reset the data\n this.#loading.set(true);\n this.#error.set(undefined);\n\n const abortController = new AbortController();\n this.#abortController = abortController;\n\n const actualFetch = this.options.fetch ?? fetch;\n const response = await actualFetch(this.options.api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...normalizeHeaders(this.options.headers),\n },\n credentials: this.options.credentials,\n signal: abortController.signal,\n body: JSON.stringify(input),\n });\n\n if (!response.ok) {\n throw new Error(\n (await response.text()) ?? 'Failed to fetch the response.',\n );\n }\n\n if (response.body == null) {\n throw new Error('The response body is empty.');\n }\n\n let accumulatedText = '';\n let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n new WritableStream<string>({\n write: async chunk => {\n if (abortController?.signal.aborted) {\n throw new DOMException('Stream aborted', 'AbortError');\n }\n accumulatedText += chunk;\n\n const { value } = await parsePartialJson(accumulatedText);\n const currentObject = value as DeepPartial<RESULT>;\n\n if (!isDeepEqualData(latestObject, currentObject)) {\n latestObject = currentObject;\n\n this.#object.set(currentObject);\n }\n },\n\n close: async () => {\n this.#loading.set(false);\n this.#abortController = undefined;\n\n if (this.options.onFinish != null) {\n const validationResult = await safeValidateTypes({\n value: latestObject,\n schema: asSchema(this.options.schema),\n });\n\n if (validationResult.success) {\n this.options.onFinish({\n object: validationResult.value,\n error: undefined,\n });\n } else {\n this.options.onFinish({\n object: undefined,\n error: (validationResult as { error: Error }).error,\n });\n }\n }\n },\n }),\n );\n } catch (error) {\n if (isAbortError(error)) {\n return;\n }\n\n const coalescedError =\n error instanceof Error ? error : new Error(String(error));\n if (this.options.onError) {\n this.options.onError(coalescedError);\n }\n\n this.#loading.set(false);\n this.#error.set(coalescedError);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAuB;AACvB,gBAMO;AAEA,IAAM,OAAN,cAEG,uBAAyB;AAAA,EACjC,YAAY,MAA4B;AACtC,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,OAAO,IAAI,iBAAiB,KAAK,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,IAAM,mBAAN,MAEmC;AAAA,EA6BjC,YAAY,kBAAgC,CAAC,GAAG;AA5BhD,SAAS,gBAAY,oBAAqB,CAAC,CAAC;AAC5C,SAAS,cAAU,oBAAmB,OAAO;AAC7C,SAAS,aAAS,oBAA0B,MAAS;AA8BrD,uBAAc,CAAC,aAA2B;AACxC,WAAK,UAAU,IAAI,CAAC,GAAG,QAAQ,CAAC;AAAA,IAClC;AAEA,uBAAc,CAAC,YAAwB;AACrC,WAAK,UAAU,OAAO,UAAQ,CAAC,GAAG,MAAM,OAAO,CAAC;AAAA,IAClD;AAEA,sBAAa,MAAM;AACjB,WAAK,UAAU,OAAO,UAAQ,KAAK,MAAM,GAAG,EAAE,CAAC;AAAA,IACjD;AAEA,0BAAiB,CAAC,OAAe,YAAwB;AACvD,WAAK,UAAU,OAAO,UAAQ;AAC5B,cAAM,OAAO,CAAC,GAAG,IAAI;AACrB,aAAK,KAAK,IAAI;AACd,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,oBAAW,CAAI,UAAgB,gBAAgB,KAAK;AAvBlD,SAAK,UAAU,IAAI,CAAC,GAAG,eAAe,CAAC;AAAA,EACzC;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AK,SAAS,IAAI,KAAK;AACvB,aAAK,OAAO,IAAI,cAAc;AAAA,MAChC;AAAA,IACF;AAjHE,SAAK,UAAU;AACf,SAAK,KAAK,QAAQ,UAAM,mCAAW;AACnC,SAAK,QAAQ,IAAI,QAAQ,YAAY;AAAA,EACvC;AAAA,EA9BA;AAAA,EAGS;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKT,IAAI,SAA0C;AAC5C,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA,EAGA,IAAI,QAA2B;AAC7B,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAmB;AACrB,WAAO,KAAK,SAAS;AAAA,EACvB;AAqHF;","names":["import_core","import_ai","import_provider_utils","import_core","import_ai"]}
|
|
1
|
+
{"version":3,"sources":["../src/lib/chat.ng.ts","../src/lib/completion.ng.ts","../src/lib/structured-object.ng.ts"],"sourcesContent":["import { signal } from '@angular/core';\nimport {\n type ChatState,\n type ChatStatus,\n type UIMessage,\n type ChatInit,\n AbstractChat,\n} from 'ai';\n\nexport class Chat<\n UI_MESSAGE extends UIMessage = UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor(init: ChatInit<UI_MESSAGE>) {\n super({\n ...init,\n state: new AngularChatState(init.messages),\n });\n }\n}\n\nclass AngularChatState<\n UI_MESSAGE extends UIMessage = UIMessage,\n> implements ChatState<UI_MESSAGE> {\n readonly #messages = signal<UI_MESSAGE[]>([]);\n readonly #status = signal<ChatStatus>('ready');\n readonly #error = signal<Error | undefined>(undefined);\n\n get messages(): UI_MESSAGE[] {\n return this.#messages();\n }\n\n set messages(messages: UI_MESSAGE[]) {\n this.#messages.set([...messages]);\n }\n\n get status(): ChatStatus {\n return this.#status();\n }\n\n set status(status: ChatStatus) {\n this.#status.set(status);\n }\n\n get error(): Error | undefined {\n return this.#error();\n }\n\n set error(error: Error | undefined) {\n this.#error.set(error);\n }\n\n constructor(initialMessages: UI_MESSAGE[] = []) {\n this.#messages.set([...initialMessages]);\n }\n\n setMessages = (messages: UI_MESSAGE[]) => {\n this.#messages.set([...messages]);\n };\n\n pushMessage = (message: UI_MESSAGE) => {\n this.#messages.update(msgs => [...msgs, message]);\n };\n\n popMessage = () => {\n this.#messages.update(msgs => msgs.slice(0, -1));\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n this.#messages.update(msgs => {\n const copy = [...msgs];\n copy[index] = message;\n return copy;\n });\n };\n\n snapshot = <T>(thing: T): T => structuredClone(thing);\n}\n","import { signal } from '@angular/core';\nimport {\n callCompletionApi,\n generateId,\n type CompletionRequestOptions,\n type UseCompletionOptions,\n} from 'ai';\nimport { normalizeHeaders } from '@ai-sdk/provider-utils';\n\nexport type CompletionOptions = Readonly<UseCompletionOptions>;\n\nexport class Completion {\n readonly #options: CompletionOptions;\n\n // Static config\n readonly id: string;\n readonly api: string;\n readonly streamProtocol: 'data' | 'text';\n\n // Reactive state\n readonly #input = signal('');\n readonly #completion = signal<string>('');\n readonly #error = signal<Error | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n\n #abortController: AbortController | null = null;\n\n constructor(options: CompletionOptions = {}) {\n this.#options = options;\n this.#completion.set(options.initialCompletion ?? '');\n this.#input.set(options.initialInput ?? '');\n this.api = options.api ?? '/api/completion';\n this.id = options.id ?? generateId();\n this.streamProtocol = options.streamProtocol ?? 'data';\n }\n\n /** Current value of the completion. Writable. */\n get completion(): string {\n return this.#completion();\n }\n set completion(value: string) {\n this.#completion.set(value);\n }\n\n /** Current value of the input. Writable. */\n get input(): string {\n return this.#input();\n }\n set input(value: string) {\n this.#input.set(value);\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /** Flag that indicates whether an API request is in progress. */\n get loading(): boolean {\n return this.#loading();\n }\n\n /** Abort the current request immediately, keep the generated tokens if any. */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = null;\n }\n };\n\n /** Send a new prompt to the API endpoint and update the completion state. */\n complete = async (prompt: string, options?: CompletionRequestOptions) =>\n this.#triggerRequest(prompt, options);\n\n /** Form submission handler to automatically reset input and call the completion API */\n handleSubmit = async (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n if (this.#input()) {\n await this.complete(this.#input());\n }\n };\n\n #triggerRequest = async (\n prompt: string,\n options?: CompletionRequestOptions,\n ) => {\n return callCompletionApi({\n api: this.api,\n prompt,\n credentials: this.#options.credentials,\n headers: {\n ...normalizeHeaders(this.#options.headers),\n ...normalizeHeaders(options?.headers),\n },\n body: {\n ...this.#options.body,\n ...options?.body,\n },\n streamProtocol: this.streamProtocol,\n fetch: this.#options.fetch,\n setCompletion: (completion: string) => {\n this.#completion.set(completion);\n },\n setLoading: (loading: boolean) => {\n this.#loading.set(loading);\n },\n setError: (error: any) => {\n this.#error.set(error);\n },\n setAbortController: abortController => {\n this.#abortController = abortController ?? null;\n },\n onFinish: this.#options.onFinish,\n onError: this.#options.onError,\n });\n };\n}\n","import {\n generateId,\n isAbortError,\n normalizeHeaders,\n safeValidateTypes,\n type FetchFunction,\n type FlexibleSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { signal } from '@angular/core';\nimport {\n asSchema,\n isDeepEqualData,\n parsePartialJson,\n type DeepPartial,\n} from 'ai';\n\nexport type StructuredObjectOptions<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n> = {\n /**\n * The API endpoint. It should stream JSON that matches the schema as chunked text.\n */\n api: string;\n\n /**\n * A schema that defines the shape of the complete object.\n */\n schema: SCHEMA;\n\n /**\n * A unique identifier. If not provided, a random one will be\n * generated. When provided, the `useObject` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * An optional value for the initial object.\n */\n initialValue?: DeepPartial<RESULT>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Callback that is called when the stream has finished.\n */\n onFinish?: (event: {\n /**\n * The generated object (typed according to the schema).\n * Can be undefined if the final object does not match the schema.\n */\n object: RESULT | undefined;\n\n /**\n * Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.\n */\n error: Error | undefined;\n }) => Promise<void> | void;\n\n /**\n * Callback function to be called when an error is encountered.\n */\n onError?: (error: Error) => void;\n\n /**\n * Additional HTTP headers to be included in the request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n};\n\nexport class StructuredObject<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n INPUT = unknown,\n> {\n readonly options: StructuredObjectOptions<SCHEMA, RESULT>;\n readonly id: string;\n #abortController: AbortController | undefined;\n\n // Reactive state\n readonly #object = signal<DeepPartial<RESULT> | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n readonly #error = signal<Error | undefined>(undefined);\n\n /**\n * The current value for the generated object. Updated as the API streams JSON chunks.\n */\n get object(): DeepPartial<RESULT> | undefined {\n return this.#object();\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /**\n * Flag that indicates whether an API request is in progress.\n */\n get loading(): boolean {\n return this.#loading();\n }\n\n constructor(options: StructuredObjectOptions<SCHEMA, RESULT>) {\n this.options = options;\n this.id = options.id ?? generateId();\n this.#object.set(options.initialValue);\n }\n\n /**\n * Abort the current request immediately, keep the current partial object if any.\n */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = undefined;\n }\n };\n\n /**\n * Calls the API with the provided input as JSON body.\n */\n submit = async (input: INPUT) => {\n try {\n this.#object.set(undefined); // reset the data\n this.#loading.set(true);\n this.#error.set(undefined);\n\n const abortController = new AbortController();\n this.#abortController = abortController;\n\n const actualFetch = this.options.fetch ?? fetch;\n const response = await actualFetch(this.options.api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...normalizeHeaders(this.options.headers),\n },\n credentials: this.options.credentials,\n signal: abortController.signal,\n body: JSON.stringify(input),\n });\n\n if (!response.ok) {\n throw new Error(\n (await response.text()) ?? 'Failed to fetch the response.',\n );\n }\n\n if (response.body == null) {\n throw new Error('The response body is empty.');\n }\n\n let accumulatedText = '';\n let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n new WritableStream<string>({\n write: async chunk => {\n if (abortController?.signal.aborted) {\n throw new DOMException('Stream aborted', 'AbortError');\n }\n accumulatedText += chunk;\n\n const { value } = await parsePartialJson(accumulatedText);\n const currentObject = value as DeepPartial<RESULT>;\n\n if (!isDeepEqualData(latestObject, currentObject)) {\n latestObject = currentObject;\n\n this.#object.set(currentObject);\n }\n },\n\n close: async () => {\n this.#loading.set(false);\n this.#abortController = undefined;\n\n if (this.options.onFinish != null) {\n const validationResult = await safeValidateTypes({\n value: latestObject,\n schema: asSchema(this.options.schema),\n });\n\n if (validationResult.success) {\n this.options.onFinish({\n object: validationResult.value,\n error: undefined,\n });\n } else {\n this.options.onFinish({\n object: undefined,\n error: (validationResult as { error: Error }).error,\n });\n }\n }\n },\n }),\n );\n } catch (error) {\n if (isAbortError(error)) {\n return;\n }\n\n const coalescedError =\n error instanceof Error ? error : new Error(String(error));\n if (this.options.onError) {\n this.options.onError(coalescedError);\n }\n\n this.#loading.set(false);\n this.#error.set(coalescedError);\n }\n };\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB;AAAA,EAKE;AAAA,OACK;AAEA,IAAM,OAAN,cAEG,aAAyB;AAAA,EACjC,YAAY,MAA4B;AACtC,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,OAAO,IAAI,iBAAiB,KAAK,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,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A,EAKA,IAAI,UAAmB;AACrB,WAAO,KAAK,SAAS;AAAA,EACvB;AAqHF;","names":["signal","generateId","normalizeHeaders","signal"]}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/angular",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.88",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"description": "Angular implementation of ai-sdk.",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.mjs",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
"./package.json": "./package.json",
|
|
11
11
|
".": {
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.
|
|
14
|
-
"
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"ai": "
|
|
28
|
+
"ai": "7.0.0-beta.88",
|
|
29
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.19"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "20.17.24",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typescript": "5.8.3",
|
|
36
36
|
"vitest": "^4.1.0",
|
|
37
37
|
"zod": "3.25.76",
|
|
38
|
-
"@ai-sdk/test-server": "2.0.0-beta.
|
|
38
|
+
"@ai-sdk/test-server": "2.0.0-beta.1",
|
|
39
39
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
package/dist/index.d.mts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { UIMessage, AbstractChat, ChatInit, UseCompletionOptions, CompletionRequestOptions, DeepPartial } from 'ai';
|
|
2
|
-
import { FlexibleSchema, InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
|
|
4
|
-
declare class Chat<UI_MESSAGE extends UIMessage = UIMessage> extends AbstractChat<UI_MESSAGE> {
|
|
5
|
-
constructor(init: ChatInit<UI_MESSAGE>);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
type CompletionOptions = Readonly<UseCompletionOptions>;
|
|
9
|
-
declare class Completion {
|
|
10
|
-
#private;
|
|
11
|
-
readonly id: string;
|
|
12
|
-
readonly api: string;
|
|
13
|
-
readonly streamProtocol: 'data' | 'text';
|
|
14
|
-
constructor(options?: CompletionOptions);
|
|
15
|
-
/** Current value of the completion. Writable. */
|
|
16
|
-
get completion(): string;
|
|
17
|
-
set completion(value: string);
|
|
18
|
-
/** Current value of the input. Writable. */
|
|
19
|
-
get input(): string;
|
|
20
|
-
set input(value: string);
|
|
21
|
-
/** The error object of the API request */
|
|
22
|
-
get error(): Error | undefined;
|
|
23
|
-
/** Flag that indicates whether an API request is in progress. */
|
|
24
|
-
get loading(): boolean;
|
|
25
|
-
/** Abort the current request immediately, keep the generated tokens if any. */
|
|
26
|
-
stop: () => void;
|
|
27
|
-
/** Send a new prompt to the API endpoint and update the completion state. */
|
|
28
|
-
complete: (prompt: string, options?: CompletionRequestOptions) => Promise<string | null | undefined>;
|
|
29
|
-
/** Form submission handler to automatically reset input and call the completion API */
|
|
30
|
-
handleSubmit: (event?: {
|
|
31
|
-
preventDefault?: () => void;
|
|
32
|
-
}) => Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type StructuredObjectOptions<SCHEMA extends FlexibleSchema, RESULT = InferSchema<SCHEMA>> = {
|
|
36
|
-
/**
|
|
37
|
-
* The API endpoint. It should stream JSON that matches the schema as chunked text.
|
|
38
|
-
*/
|
|
39
|
-
api: string;
|
|
40
|
-
/**
|
|
41
|
-
* A schema that defines the shape of the complete object.
|
|
42
|
-
*/
|
|
43
|
-
schema: SCHEMA;
|
|
44
|
-
/**
|
|
45
|
-
* A unique identifier. If not provided, a random one will be
|
|
46
|
-
* generated. When provided, the `useObject` hook with the same `id` will
|
|
47
|
-
* have shared states across components.
|
|
48
|
-
*/
|
|
49
|
-
id?: string;
|
|
50
|
-
/**
|
|
51
|
-
* An optional value for the initial object.
|
|
52
|
-
*/
|
|
53
|
-
initialValue?: DeepPartial<RESULT>;
|
|
54
|
-
/**
|
|
55
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
56
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
57
|
-
*/
|
|
58
|
-
fetch?: FetchFunction;
|
|
59
|
-
/**
|
|
60
|
-
* Callback that is called when the stream has finished.
|
|
61
|
-
*/
|
|
62
|
-
onFinish?: (event: {
|
|
63
|
-
/**
|
|
64
|
-
* The generated object (typed according to the schema).
|
|
65
|
-
* Can be undefined if the final object does not match the schema.
|
|
66
|
-
*/
|
|
67
|
-
object: RESULT | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
|
|
70
|
-
*/
|
|
71
|
-
error: Error | undefined;
|
|
72
|
-
}) => Promise<void> | void;
|
|
73
|
-
/**
|
|
74
|
-
* Callback function to be called when an error is encountered.
|
|
75
|
-
*/
|
|
76
|
-
onError?: (error: Error) => void;
|
|
77
|
-
/**
|
|
78
|
-
* Additional HTTP headers to be included in the request.
|
|
79
|
-
*/
|
|
80
|
-
headers?: Record<string, string> | Headers;
|
|
81
|
-
/**
|
|
82
|
-
* The credentials mode to be used for the fetch request.
|
|
83
|
-
* Possible values are: 'omit', 'same-origin', 'include'.
|
|
84
|
-
* Defaults to 'same-origin'.
|
|
85
|
-
*/
|
|
86
|
-
credentials?: RequestCredentials;
|
|
87
|
-
};
|
|
88
|
-
declare class StructuredObject<SCHEMA extends FlexibleSchema, RESULT = InferSchema<SCHEMA>, INPUT = unknown> {
|
|
89
|
-
#private;
|
|
90
|
-
readonly options: StructuredObjectOptions<SCHEMA, RESULT>;
|
|
91
|
-
readonly id: string;
|
|
92
|
-
/**
|
|
93
|
-
* The current value for the generated object. Updated as the API streams JSON chunks.
|
|
94
|
-
*/
|
|
95
|
-
get object(): DeepPartial<RESULT> | undefined;
|
|
96
|
-
/** The error object of the API request */
|
|
97
|
-
get error(): Error | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* Flag that indicates whether an API request is in progress.
|
|
100
|
-
*/
|
|
101
|
-
get loading(): boolean;
|
|
102
|
-
constructor(options: StructuredObjectOptions<SCHEMA, RESULT>);
|
|
103
|
-
/**
|
|
104
|
-
* Abort the current request immediately, keep the current partial object if any.
|
|
105
|
-
*/
|
|
106
|
-
stop: () => void;
|
|
107
|
-
/**
|
|
108
|
-
* Calls the API with the provided input as JSON body.
|
|
109
|
-
*/
|
|
110
|
-
submit: (input: INPUT) => Promise<void>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export { Chat, Completion, CompletionOptions, StructuredObject, StructuredObjectOptions };
|
package/dist/index.mjs
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
// src/lib/chat.ng.ts
|
|
2
|
-
import { signal } from "@angular/core";
|
|
3
|
-
import {
|
|
4
|
-
AbstractChat
|
|
5
|
-
} from "ai";
|
|
6
|
-
var Chat = class extends AbstractChat {
|
|
7
|
-
constructor(init) {
|
|
8
|
-
super({
|
|
9
|
-
...init,
|
|
10
|
-
state: new AngularChatState(init.messages)
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var AngularChatState = class {
|
|
15
|
-
constructor(initialMessages = []) {
|
|
16
|
-
this.#messages = signal([]);
|
|
17
|
-
this.#status = signal("ready");
|
|
18
|
-
this.#error = signal(void 0);
|
|
19
|
-
this.setMessages = (messages) => {
|
|
20
|
-
this.#messages.set([...messages]);
|
|
21
|
-
};
|
|
22
|
-
this.pushMessage = (message) => {
|
|
23
|
-
this.#messages.update((msgs) => [...msgs, message]);
|
|
24
|
-
};
|
|
25
|
-
this.popMessage = () => {
|
|
26
|
-
this.#messages.update((msgs) => msgs.slice(0, -1));
|
|
27
|
-
};
|
|
28
|
-
this.replaceMessage = (index, message) => {
|
|
29
|
-
this.#messages.update((msgs) => {
|
|
30
|
-
const copy = [...msgs];
|
|
31
|
-
copy[index] = message;
|
|
32
|
-
return copy;
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
this.snapshot = (thing) => structuredClone(thing);
|
|
36
|
-
this.#messages.set([...initialMessages]);
|
|
37
|
-
}
|
|
38
|
-
#messages;
|
|
39
|
-
#status;
|
|
40
|
-
#error;
|
|
41
|
-
get messages() {
|
|
42
|
-
return this.#messages();
|
|
43
|
-
}
|
|
44
|
-
set messages(messages) {
|
|
45
|
-
this.#messages.set([...messages]);
|
|
46
|
-
}
|
|
47
|
-
get status() {
|
|
48
|
-
return this.#status();
|
|
49
|
-
}
|
|
50
|
-
set status(status) {
|
|
51
|
-
this.#status.set(status);
|
|
52
|
-
}
|
|
53
|
-
get error() {
|
|
54
|
-
return this.#error();
|
|
55
|
-
}
|
|
56
|
-
set error(error) {
|
|
57
|
-
this.#error.set(error);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// src/lib/completion.ng.ts
|
|
62
|
-
import { signal as signal2 } from "@angular/core";
|
|
63
|
-
import {
|
|
64
|
-
callCompletionApi,
|
|
65
|
-
generateId
|
|
66
|
-
} from "ai";
|
|
67
|
-
import { normalizeHeaders } from "@ai-sdk/provider-utils";
|
|
68
|
-
var Completion = class {
|
|
69
|
-
constructor(options = {}) {
|
|
70
|
-
// Reactive state
|
|
71
|
-
this.#input = signal2("");
|
|
72
|
-
this.#completion = signal2("");
|
|
73
|
-
this.#error = signal2(void 0);
|
|
74
|
-
this.#loading = signal2(false);
|
|
75
|
-
this.#abortController = null;
|
|
76
|
-
/** Abort the current request immediately, keep the generated tokens if any. */
|
|
77
|
-
this.stop = () => {
|
|
78
|
-
try {
|
|
79
|
-
this.#abortController?.abort();
|
|
80
|
-
} catch {
|
|
81
|
-
} finally {
|
|
82
|
-
this.#loading.set(false);
|
|
83
|
-
this.#abortController = null;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
/** Send a new prompt to the API endpoint and update the completion state. */
|
|
87
|
-
this.complete = async (prompt, options) => this.#triggerRequest(prompt, options);
|
|
88
|
-
/** Form submission handler to automatically reset input and call the completion API */
|
|
89
|
-
this.handleSubmit = async (event) => {
|
|
90
|
-
event?.preventDefault?.();
|
|
91
|
-
if (this.#input()) {
|
|
92
|
-
await this.complete(this.#input());
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
this.#triggerRequest = async (prompt, options) => {
|
|
96
|
-
return callCompletionApi({
|
|
97
|
-
api: this.api,
|
|
98
|
-
prompt,
|
|
99
|
-
credentials: this.#options.credentials,
|
|
100
|
-
headers: {
|
|
101
|
-
...normalizeHeaders(this.#options.headers),
|
|
102
|
-
...normalizeHeaders(options?.headers)
|
|
103
|
-
},
|
|
104
|
-
body: {
|
|
105
|
-
...this.#options.body,
|
|
106
|
-
...options?.body
|
|
107
|
-
},
|
|
108
|
-
streamProtocol: this.streamProtocol,
|
|
109
|
-
fetch: this.#options.fetch,
|
|
110
|
-
setCompletion: (completion) => {
|
|
111
|
-
this.#completion.set(completion);
|
|
112
|
-
},
|
|
113
|
-
setLoading: (loading) => {
|
|
114
|
-
this.#loading.set(loading);
|
|
115
|
-
},
|
|
116
|
-
setError: (error) => {
|
|
117
|
-
this.#error.set(error);
|
|
118
|
-
},
|
|
119
|
-
setAbortController: (abortController) => {
|
|
120
|
-
this.#abortController = abortController ?? null;
|
|
121
|
-
},
|
|
122
|
-
onFinish: this.#options.onFinish,
|
|
123
|
-
onError: this.#options.onError
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
this.#options = options;
|
|
127
|
-
this.#completion.set(options.initialCompletion ?? "");
|
|
128
|
-
this.#input.set(options.initialInput ?? "");
|
|
129
|
-
this.api = options.api ?? "/api/completion";
|
|
130
|
-
this.id = options.id ?? generateId();
|
|
131
|
-
this.streamProtocol = options.streamProtocol ?? "data";
|
|
132
|
-
}
|
|
133
|
-
#options;
|
|
134
|
-
#input;
|
|
135
|
-
#completion;
|
|
136
|
-
#error;
|
|
137
|
-
#loading;
|
|
138
|
-
#abortController;
|
|
139
|
-
/** Current value of the completion. Writable. */
|
|
140
|
-
get completion() {
|
|
141
|
-
return this.#completion();
|
|
142
|
-
}
|
|
143
|
-
set completion(value) {
|
|
144
|
-
this.#completion.set(value);
|
|
145
|
-
}
|
|
146
|
-
/** Current value of the input. Writable. */
|
|
147
|
-
get input() {
|
|
148
|
-
return this.#input();
|
|
149
|
-
}
|
|
150
|
-
set input(value) {
|
|
151
|
-
this.#input.set(value);
|
|
152
|
-
}
|
|
153
|
-
/** The error object of the API request */
|
|
154
|
-
get error() {
|
|
155
|
-
return this.#error();
|
|
156
|
-
}
|
|
157
|
-
/** Flag that indicates whether an API request is in progress. */
|
|
158
|
-
get loading() {
|
|
159
|
-
return this.#loading();
|
|
160
|
-
}
|
|
161
|
-
#triggerRequest;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// src/lib/structured-object.ng.ts
|
|
165
|
-
import {
|
|
166
|
-
generateId as generateId2,
|
|
167
|
-
isAbortError,
|
|
168
|
-
normalizeHeaders as normalizeHeaders2,
|
|
169
|
-
safeValidateTypes
|
|
170
|
-
} from "@ai-sdk/provider-utils";
|
|
171
|
-
import { signal as signal3 } from "@angular/core";
|
|
172
|
-
import {
|
|
173
|
-
asSchema,
|
|
174
|
-
isDeepEqualData,
|
|
175
|
-
parsePartialJson
|
|
176
|
-
} from "ai";
|
|
177
|
-
var StructuredObject = class {
|
|
178
|
-
constructor(options) {
|
|
179
|
-
// Reactive state
|
|
180
|
-
this.#object = signal3(void 0);
|
|
181
|
-
this.#loading = signal3(false);
|
|
182
|
-
this.#error = signal3(void 0);
|
|
183
|
-
/**
|
|
184
|
-
* Abort the current request immediately, keep the current partial object if any.
|
|
185
|
-
*/
|
|
186
|
-
this.stop = () => {
|
|
187
|
-
try {
|
|
188
|
-
this.#abortController?.abort();
|
|
189
|
-
} catch {
|
|
190
|
-
} finally {
|
|
191
|
-
this.#loading.set(false);
|
|
192
|
-
this.#abortController = void 0;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Calls the API with the provided input as JSON body.
|
|
197
|
-
*/
|
|
198
|
-
this.submit = async (input) => {
|
|
199
|
-
try {
|
|
200
|
-
this.#object.set(void 0);
|
|
201
|
-
this.#loading.set(true);
|
|
202
|
-
this.#error.set(void 0);
|
|
203
|
-
const abortController = new AbortController();
|
|
204
|
-
this.#abortController = abortController;
|
|
205
|
-
const actualFetch = this.options.fetch ?? fetch;
|
|
206
|
-
const response = await actualFetch(this.options.api, {
|
|
207
|
-
method: "POST",
|
|
208
|
-
headers: {
|
|
209
|
-
"Content-Type": "application/json",
|
|
210
|
-
...normalizeHeaders2(this.options.headers)
|
|
211
|
-
},
|
|
212
|
-
credentials: this.options.credentials,
|
|
213
|
-
signal: abortController.signal,
|
|
214
|
-
body: JSON.stringify(input)
|
|
215
|
-
});
|
|
216
|
-
if (!response.ok) {
|
|
217
|
-
throw new Error(
|
|
218
|
-
await response.text() ?? "Failed to fetch the response."
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
if (response.body == null) {
|
|
222
|
-
throw new Error("The response body is empty.");
|
|
223
|
-
}
|
|
224
|
-
let accumulatedText = "";
|
|
225
|
-
let latestObject = void 0;
|
|
226
|
-
await response.body.pipeThrough(new TextDecoderStream()).pipeTo(
|
|
227
|
-
new WritableStream({
|
|
228
|
-
write: async (chunk) => {
|
|
229
|
-
if (abortController?.signal.aborted) {
|
|
230
|
-
throw new DOMException("Stream aborted", "AbortError");
|
|
231
|
-
}
|
|
232
|
-
accumulatedText += chunk;
|
|
233
|
-
const { value } = await parsePartialJson(accumulatedText);
|
|
234
|
-
const currentObject = value;
|
|
235
|
-
if (!isDeepEqualData(latestObject, currentObject)) {
|
|
236
|
-
latestObject = currentObject;
|
|
237
|
-
this.#object.set(currentObject);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
close: async () => {
|
|
241
|
-
this.#loading.set(false);
|
|
242
|
-
this.#abortController = void 0;
|
|
243
|
-
if (this.options.onFinish != null) {
|
|
244
|
-
const validationResult = await safeValidateTypes({
|
|
245
|
-
value: latestObject,
|
|
246
|
-
schema: asSchema(this.options.schema)
|
|
247
|
-
});
|
|
248
|
-
if (validationResult.success) {
|
|
249
|
-
this.options.onFinish({
|
|
250
|
-
object: validationResult.value,
|
|
251
|
-
error: void 0
|
|
252
|
-
});
|
|
253
|
-
} else {
|
|
254
|
-
this.options.onFinish({
|
|
255
|
-
object: void 0,
|
|
256
|
-
error: validationResult.error
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
);
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (isAbortError(error)) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const coalescedError = error instanceof Error ? error : new Error(String(error));
|
|
268
|
-
if (this.options.onError) {
|
|
269
|
-
this.options.onError(coalescedError);
|
|
270
|
-
}
|
|
271
|
-
this.#loading.set(false);
|
|
272
|
-
this.#error.set(coalescedError);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
this.options = options;
|
|
276
|
-
this.id = options.id ?? generateId2();
|
|
277
|
-
this.#object.set(options.initialValue);
|
|
278
|
-
}
|
|
279
|
-
#abortController;
|
|
280
|
-
#object;
|
|
281
|
-
#loading;
|
|
282
|
-
#error;
|
|
283
|
-
/**
|
|
284
|
-
* The current value for the generated object. Updated as the API streams JSON chunks.
|
|
285
|
-
*/
|
|
286
|
-
get object() {
|
|
287
|
-
return this.#object();
|
|
288
|
-
}
|
|
289
|
-
/** The error object of the API request */
|
|
290
|
-
get error() {
|
|
291
|
-
return this.#error();
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Flag that indicates whether an API request is in progress.
|
|
295
|
-
*/
|
|
296
|
-
get loading() {
|
|
297
|
-
return this.#loading();
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
export {
|
|
301
|
-
Chat,
|
|
302
|
-
Completion,
|
|
303
|
-
StructuredObject
|
|
304
|
-
};
|
|
305
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/chat.ng.ts","../src/lib/completion.ng.ts","../src/lib/structured-object.ng.ts"],"sourcesContent":["import { signal } from '@angular/core';\nimport {\n type ChatState,\n type ChatStatus,\n type UIMessage,\n type ChatInit,\n AbstractChat,\n} from 'ai';\n\nexport class Chat<\n UI_MESSAGE extends UIMessage = UIMessage,\n> extends AbstractChat<UI_MESSAGE> {\n constructor(init: ChatInit<UI_MESSAGE>) {\n super({\n ...init,\n state: new AngularChatState(init.messages),\n });\n }\n}\n\nclass AngularChatState<\n UI_MESSAGE extends UIMessage = UIMessage,\n> implements ChatState<UI_MESSAGE> {\n readonly #messages = signal<UI_MESSAGE[]>([]);\n readonly #status = signal<ChatStatus>('ready');\n readonly #error = signal<Error | undefined>(undefined);\n\n get messages(): UI_MESSAGE[] {\n return this.#messages();\n }\n\n set messages(messages: UI_MESSAGE[]) {\n this.#messages.set([...messages]);\n }\n\n get status(): ChatStatus {\n return this.#status();\n }\n\n set status(status: ChatStatus) {\n this.#status.set(status);\n }\n\n get error(): Error | undefined {\n return this.#error();\n }\n\n set error(error: Error | undefined) {\n this.#error.set(error);\n }\n\n constructor(initialMessages: UI_MESSAGE[] = []) {\n this.#messages.set([...initialMessages]);\n }\n\n setMessages = (messages: UI_MESSAGE[]) => {\n this.#messages.set([...messages]);\n };\n\n pushMessage = (message: UI_MESSAGE) => {\n this.#messages.update(msgs => [...msgs, message]);\n };\n\n popMessage = () => {\n this.#messages.update(msgs => msgs.slice(0, -1));\n };\n\n replaceMessage = (index: number, message: UI_MESSAGE) => {\n this.#messages.update(msgs => {\n const copy = [...msgs];\n copy[index] = message;\n return copy;\n });\n };\n\n snapshot = <T>(thing: T): T => structuredClone(thing);\n}\n","import { signal } from '@angular/core';\nimport {\n callCompletionApi,\n generateId,\n type CompletionRequestOptions,\n type UseCompletionOptions,\n} from 'ai';\nimport { normalizeHeaders } from '@ai-sdk/provider-utils';\n\nexport type CompletionOptions = Readonly<UseCompletionOptions>;\n\nexport class Completion {\n readonly #options: CompletionOptions;\n\n // Static config\n readonly id: string;\n readonly api: string;\n readonly streamProtocol: 'data' | 'text';\n\n // Reactive state\n readonly #input = signal('');\n readonly #completion = signal<string>('');\n readonly #error = signal<Error | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n\n #abortController: AbortController | null = null;\n\n constructor(options: CompletionOptions = {}) {\n this.#options = options;\n this.#completion.set(options.initialCompletion ?? '');\n this.#input.set(options.initialInput ?? '');\n this.api = options.api ?? '/api/completion';\n this.id = options.id ?? generateId();\n this.streamProtocol = options.streamProtocol ?? 'data';\n }\n\n /** Current value of the completion. Writable. */\n get completion(): string {\n return this.#completion();\n }\n set completion(value: string) {\n this.#completion.set(value);\n }\n\n /** Current value of the input. Writable. */\n get input(): string {\n return this.#input();\n }\n set input(value: string) {\n this.#input.set(value);\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /** Flag that indicates whether an API request is in progress. */\n get loading(): boolean {\n return this.#loading();\n }\n\n /** Abort the current request immediately, keep the generated tokens if any. */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = null;\n }\n };\n\n /** Send a new prompt to the API endpoint and update the completion state. */\n complete = async (prompt: string, options?: CompletionRequestOptions) =>\n this.#triggerRequest(prompt, options);\n\n /** Form submission handler to automatically reset input and call the completion API */\n handleSubmit = async (event?: { preventDefault?: () => void }) => {\n event?.preventDefault?.();\n if (this.#input()) {\n await this.complete(this.#input());\n }\n };\n\n #triggerRequest = async (\n prompt: string,\n options?: CompletionRequestOptions,\n ) => {\n return callCompletionApi({\n api: this.api,\n prompt,\n credentials: this.#options.credentials,\n headers: {\n ...normalizeHeaders(this.#options.headers),\n ...normalizeHeaders(options?.headers),\n },\n body: {\n ...this.#options.body,\n ...options?.body,\n },\n streamProtocol: this.streamProtocol,\n fetch: this.#options.fetch,\n setCompletion: (completion: string) => {\n this.#completion.set(completion);\n },\n setLoading: (loading: boolean) => {\n this.#loading.set(loading);\n },\n setError: (error: any) => {\n this.#error.set(error);\n },\n setAbortController: abortController => {\n this.#abortController = abortController ?? null;\n },\n onFinish: this.#options.onFinish,\n onError: this.#options.onError,\n });\n };\n}\n","import {\n generateId,\n isAbortError,\n normalizeHeaders,\n safeValidateTypes,\n type FetchFunction,\n type FlexibleSchema,\n type InferSchema,\n} from '@ai-sdk/provider-utils';\nimport { signal } from '@angular/core';\nimport {\n asSchema,\n isDeepEqualData,\n parsePartialJson,\n type DeepPartial,\n} from 'ai';\n\nexport type StructuredObjectOptions<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n> = {\n /**\n * The API endpoint. It should stream JSON that matches the schema as chunked text.\n */\n api: string;\n\n /**\n * A schema that defines the shape of the complete object.\n */\n schema: SCHEMA;\n\n /**\n * A unique identifier. If not provided, a random one will be\n * generated. When provided, the `useObject` hook with the same `id` will\n * have shared states across components.\n */\n id?: string;\n\n /**\n * An optional value for the initial object.\n */\n initialValue?: DeepPartial<RESULT>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Callback that is called when the stream has finished.\n */\n onFinish?: (event: {\n /**\n * The generated object (typed according to the schema).\n * Can be undefined if the final object does not match the schema.\n */\n object: RESULT | undefined;\n\n /**\n * Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.\n */\n error: Error | undefined;\n }) => Promise<void> | void;\n\n /**\n * Callback function to be called when an error is encountered.\n */\n onError?: (error: Error) => void;\n\n /**\n * Additional HTTP headers to be included in the request.\n */\n headers?: Record<string, string> | Headers;\n\n /**\n * The credentials mode to be used for the fetch request.\n * Possible values are: 'omit', 'same-origin', 'include'.\n * Defaults to 'same-origin'.\n */\n credentials?: RequestCredentials;\n};\n\nexport class StructuredObject<\n SCHEMA extends FlexibleSchema,\n RESULT = InferSchema<SCHEMA>,\n INPUT = unknown,\n> {\n readonly options: StructuredObjectOptions<SCHEMA, RESULT>;\n readonly id: string;\n #abortController: AbortController | undefined;\n\n // Reactive state\n readonly #object = signal<DeepPartial<RESULT> | undefined>(undefined);\n readonly #loading = signal<boolean>(false);\n readonly #error = signal<Error | undefined>(undefined);\n\n /**\n * The current value for the generated object. Updated as the API streams JSON chunks.\n */\n get object(): DeepPartial<RESULT> | undefined {\n return this.#object();\n }\n\n /** The error object of the API request */\n get error(): Error | undefined {\n return this.#error();\n }\n\n /**\n * Flag that indicates whether an API request is in progress.\n */\n get loading(): boolean {\n return this.#loading();\n }\n\n constructor(options: StructuredObjectOptions<SCHEMA, RESULT>) {\n this.options = options;\n this.id = options.id ?? generateId();\n this.#object.set(options.initialValue);\n }\n\n /**\n * Abort the current request immediately, keep the current partial object if any.\n */\n stop = () => {\n try {\n this.#abortController?.abort();\n } catch {\n // ignore\n } finally {\n this.#loading.set(false);\n this.#abortController = undefined;\n }\n };\n\n /**\n * Calls the API with the provided input as JSON body.\n */\n submit = async (input: INPUT) => {\n try {\n this.#object.set(undefined); // reset the data\n this.#loading.set(true);\n this.#error.set(undefined);\n\n const abortController = new AbortController();\n this.#abortController = abortController;\n\n const actualFetch = this.options.fetch ?? fetch;\n const response = await actualFetch(this.options.api, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...normalizeHeaders(this.options.headers),\n },\n credentials: this.options.credentials,\n signal: abortController.signal,\n body: JSON.stringify(input),\n });\n\n if (!response.ok) {\n throw new Error(\n (await response.text()) ?? 'Failed to fetch the response.',\n );\n }\n\n if (response.body == null) {\n throw new Error('The response body is empty.');\n }\n\n let accumulatedText = '';\n let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n new WritableStream<string>({\n write: async chunk => {\n if (abortController?.signal.aborted) {\n throw new DOMException('Stream aborted', 'AbortError');\n }\n accumulatedText += chunk;\n\n const { value } = await parsePartialJson(accumulatedText);\n const currentObject = value as DeepPartial<RESULT>;\n\n if (!isDeepEqualData(latestObject, currentObject)) {\n latestObject = currentObject;\n\n this.#object.set(currentObject);\n }\n },\n\n close: async () => {\n this.#loading.set(false);\n this.#abortController = undefined;\n\n if (this.options.onFinish != null) {\n const validationResult = await safeValidateTypes({\n value: latestObject,\n schema: asSchema(this.options.schema),\n });\n\n if (validationResult.success) {\n this.options.onFinish({\n object: validationResult.value,\n error: undefined,\n });\n } else {\n this.options.onFinish({\n object: undefined,\n error: (validationResult as { error: Error }).error,\n });\n }\n }\n },\n }),\n );\n } catch (error) {\n if (isAbortError(error)) {\n return;\n }\n\n const coalescedError =\n error instanceof Error ? error : new Error(String(error));\n if (this.options.onError) {\n this.options.onError(coalescedError);\n }\n\n this.#loading.set(false);\n this.#error.set(coalescedError);\n }\n };\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB;AAAA,EAKE;AAAA,OACK;AAEA,IAAM,OAAN,cAEG,aAAyB;AAAA,EACjC,YAAY,MAA4B;AACtC,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,OAAO,IAAI,iBAAiB,KAAK,QAAQ;AAAA,IAC3C,CAAC;AAAA,EACH;AACF;AAEA,IAAM,mBAAN,MAEmC;AAAA,EA6BjC,YAAY,kBAAgC,CAAC,GAAG;AA5BhD,SAAS,YAAY,OAAqB,C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