@tanstack/ai-angular 0.7.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs +408 -0
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs.map +1 -0
- package/dist/fesm2022/tanstack-ai-angular.mjs +34 -2
- package/dist/fesm2022/tanstack-ai-angular.mjs.map +1 -1
- package/dist/types/tanstack-ai-angular-ui.d.ts +162 -0
- package/dist/types/tanstack-ai-angular.d.ts +30 -3
- package/package.json +12 -6
- package/src/index.ts +4 -0
- package/src/inject-web-mcp-tools.ts +62 -0
- package/ui/ng-package.json +5 -0
- package/ui/src/create-chat-hook.ts +79 -0
- package/ui/src/create-ui.ts +516 -0
- package/ui/src/index.ts +21 -0
- package/ui/src/tokens.ts +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Angular signals integration for TanStack AI streaming chat, structured outputs, and media generation.",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"./package.json": {
|
|
35
35
|
"default": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"./ui": {
|
|
38
|
+
"types": "./dist/types/tanstack-ai-angular-ui.d.ts",
|
|
39
|
+
"default": "./dist/fesm2022/tanstack-ai-angular-ui.mjs"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"sideEffects": false,
|
|
@@ -41,15 +45,17 @@
|
|
|
41
45
|
},
|
|
42
46
|
"files": [
|
|
43
47
|
"dist",
|
|
44
|
-
"src"
|
|
48
|
+
"src",
|
|
49
|
+
"ui"
|
|
45
50
|
],
|
|
46
51
|
"dependencies": {
|
|
47
52
|
"tslib": "^2.8.1",
|
|
48
|
-
"@tanstack/ai-client": "^0.
|
|
53
|
+
"@tanstack/ai-client": "^0.31.0"
|
|
49
54
|
},
|
|
50
55
|
"peerDependencies": {
|
|
56
|
+
"@angular/common": ">=21.0.0",
|
|
51
57
|
"@angular/core": ">=21.0.0",
|
|
52
|
-
"@tanstack/ai": "^0.
|
|
58
|
+
"@tanstack/ai": "^0.53.0"
|
|
53
59
|
},
|
|
54
60
|
"devDependencies": {
|
|
55
61
|
"@analogjs/vite-plugin-angular": "^2.6.2",
|
|
@@ -66,11 +72,11 @@
|
|
|
66
72
|
"vitest": "^4.1.10",
|
|
67
73
|
"zod": "^4.2.0",
|
|
68
74
|
"zone.js": "^0.15.0",
|
|
69
|
-
"@tanstack/ai": "0.
|
|
75
|
+
"@tanstack/ai": "0.53.0"
|
|
70
76
|
},
|
|
71
77
|
"scripts": {
|
|
72
78
|
"clean": "premove ./build ./dist",
|
|
73
|
-
"test:oxlint": "oxlint src --type-aware",
|
|
79
|
+
"test:oxlint": "oxlint src ui/src --type-aware",
|
|
74
80
|
"test:lib": "vitest run",
|
|
75
81
|
"test:lib:dev": "vitest",
|
|
76
82
|
"test:types": "tsc",
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
export { injectChat } from './inject-chat'
|
|
3
3
|
export { injectByok } from './inject-byok'
|
|
4
4
|
|
|
5
|
+
// WebMCP Tools
|
|
6
|
+
export { injectWebMCPTools } from './inject-web-mcp-tools'
|
|
7
|
+
export type { InjectWebMCPToolsOptions } from './inject-web-mcp-tools'
|
|
8
|
+
|
|
5
9
|
// Generation
|
|
6
10
|
export { injectGeneration } from './inject-generation'
|
|
7
11
|
export type {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DestroyRef, assertInInjectionContext, inject } from '@angular/core'
|
|
2
|
+
import { registerWebMCPTools } from '@tanstack/ai-client'
|
|
3
|
+
import type {
|
|
4
|
+
AnyClientTool,
|
|
5
|
+
InferredClientContext,
|
|
6
|
+
RegisterWebMCPToolsOptions,
|
|
7
|
+
} from '@tanstack/ai-client'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@link injectWebMCPTools}.
|
|
11
|
+
*
|
|
12
|
+
* Context is required when a client tool declares a required runtime context.
|
|
13
|
+
*/
|
|
14
|
+
export type InjectWebMCPToolsOptions<
|
|
15
|
+
TTools extends ReadonlyArray<AnyClientTool>,
|
|
16
|
+
TContext = InferredClientContext<TTools>,
|
|
17
|
+
> = Omit<RegisterWebMCPToolsOptions<TTools, TContext>, 'signal'> & {
|
|
18
|
+
/** Receives asynchronous WebMCP registration errors. */
|
|
19
|
+
onError?: (error: unknown) => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Registers executable client tools with WebMCP for the current Angular owner.
|
|
24
|
+
*
|
|
25
|
+
* Angular removes the registrations when it destroys the injection owner. Call
|
|
26
|
+
* this function in an injection context, such as a component field initializer.
|
|
27
|
+
*
|
|
28
|
+
* @param tools - The executable client tools to expose through WebMCP.
|
|
29
|
+
* @param options - Runtime context, per-tool options, and error handling.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* registration = injectWebMCPTools([statusTool], {
|
|
34
|
+
* onError: (error) => console.error(error),
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function injectWebMCPTools<
|
|
39
|
+
const TTools extends ReadonlyArray<AnyClientTool>,
|
|
40
|
+
TContext = InferredClientContext<TTools>,
|
|
41
|
+
>(
|
|
42
|
+
tools: TTools,
|
|
43
|
+
...[options]: {} extends InjectWebMCPToolsOptions<TTools, TContext>
|
|
44
|
+
? [options?: InjectWebMCPToolsOptions<TTools, TContext>]
|
|
45
|
+
: [options: InjectWebMCPToolsOptions<TTools, TContext>]
|
|
46
|
+
) {
|
|
47
|
+
assertInInjectionContext(injectWebMCPTools)
|
|
48
|
+
const destroyRef = inject(DestroyRef)
|
|
49
|
+
const registrationController = new AbortController()
|
|
50
|
+
const { onError, ...registrationOptions } = options ?? {}
|
|
51
|
+
|
|
52
|
+
destroyRef.onDestroy(() => registrationController.abort())
|
|
53
|
+
|
|
54
|
+
void registerWebMCPTools(tools, {
|
|
55
|
+
...registrationOptions,
|
|
56
|
+
signal: registrationController.signal,
|
|
57
|
+
}).catch((error) => {
|
|
58
|
+
if (!registrationController.signal.aborted) {
|
|
59
|
+
onError?.(error)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { assertInInjectionContext } from '@angular/core'
|
|
2
|
+
import type { Type } from '@angular/core'
|
|
3
|
+
import { injectChat } from '@tanstack/ai-angular'
|
|
4
|
+
import type { InjectChatOptions } from '@tanstack/ai-angular'
|
|
5
|
+
import { createChatUI } from './create-ui'
|
|
6
|
+
import type { ChatUIFactoryConfig, ChatUIHost, InputProps } from './create-ui'
|
|
7
|
+
import type {
|
|
8
|
+
ChatUIInterruptsOf,
|
|
9
|
+
ChatUISchemaOf,
|
|
10
|
+
ChatUIToolsOf,
|
|
11
|
+
} from '@tanstack/ai-client/ui'
|
|
12
|
+
import type { InferredClientContext } from '@tanstack/ai-client'
|
|
13
|
+
|
|
14
|
+
type HeadlessOptions<TOptions> = InjectChatOptions<
|
|
15
|
+
ChatUIToolsOf<TOptions>,
|
|
16
|
+
ChatUISchemaOf<TOptions>,
|
|
17
|
+
InferredClientContext<ChatUIToolsOf<TOptions>>,
|
|
18
|
+
ChatUIInterruptsOf<TOptions>
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
type ChatInstanceOverrides<TOptions> = {
|
|
22
|
+
threadId?: string
|
|
23
|
+
live?: HeadlessOptions<TOptions>['live']
|
|
24
|
+
forwardedProps?: HeadlessOptions<TOptions>['forwardedProps']
|
|
25
|
+
body?: HeadlessOptions<TOptions>['body']
|
|
26
|
+
initialMessages?: HeadlessOptions<TOptions>['initialMessages']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Bind chat options and Angular widgets once at module scope.
|
|
31
|
+
*
|
|
32
|
+
* This matches Form `injectForm` and the React `createChatHook` factory:
|
|
33
|
+
* widgets register here. The returned `injectAppChat` creates a chat
|
|
34
|
+
* instance in an injection context. Render `<ai-chat [chat]="chat" />`
|
|
35
|
+
* with the factory `Chat` component.
|
|
36
|
+
*/
|
|
37
|
+
export function createChatHook<
|
|
38
|
+
const TOptions,
|
|
39
|
+
TInput extends Type<unknown> | undefined = Type<unknown> | undefined,
|
|
40
|
+
>({
|
|
41
|
+
options,
|
|
42
|
+
...chatComponents
|
|
43
|
+
}: {
|
|
44
|
+
options: TOptions
|
|
45
|
+
} & ChatUIFactoryConfig<NoInfer<TOptions>, TInput>) {
|
|
46
|
+
const ui = createChatUI(
|
|
47
|
+
options,
|
|
48
|
+
chatComponents as ChatUIFactoryConfig<NoInfer<TOptions>, TInput>,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
function injectAppChat(overrides?: ChatInstanceOverrides<TOptions>) {
|
|
52
|
+
assertInInjectionContext(injectAppChat)
|
|
53
|
+
const chat = (
|
|
54
|
+
overrides
|
|
55
|
+
? injectChat({
|
|
56
|
+
...(options as HeadlessOptions<TOptions>),
|
|
57
|
+
...overrides,
|
|
58
|
+
})
|
|
59
|
+
: injectChat(options as HeadlessOptions<TOptions>)
|
|
60
|
+
) as ChatUIHost<TOptions>
|
|
61
|
+
return chat
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
injectAppChat,
|
|
66
|
+
injectChatContext: ui.injectChatContext,
|
|
67
|
+
Chat: ui.Chat,
|
|
68
|
+
ChatProvider: ui.ChatProvider,
|
|
69
|
+
} as {
|
|
70
|
+
injectAppChat: (
|
|
71
|
+
overrides?: ChatInstanceOverrides<TOptions>,
|
|
72
|
+
) => ChatUIHost<TOptions>
|
|
73
|
+
injectChatContext: () => ChatUIHost<TOptions>
|
|
74
|
+
Chat: Type<unknown>
|
|
75
|
+
ChatProvider: Type<unknown>
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type { InputProps }
|