@yunlefun/vue 0.4.2 → 0.6.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.
Files changed (75) hide show
  1. package/README.md +6 -0
  2. package/components/YlfAccordion.vue +12 -7
  3. package/components/YlfAgentCard.vue +108 -0
  4. package/components/YlfAgentStatus.vue +69 -0
  5. package/components/YlfAgentTask.vue +85 -0
  6. package/components/YlfButton.vue +145 -28
  7. package/components/YlfCard.vue +10 -4
  8. package/components/YlfCheckbox.vue +70 -7
  9. package/components/YlfCloud.vue +193 -0
  10. package/components/YlfDialog.vue +53 -21
  11. package/components/YlfDropdownMenu.vue +41 -5
  12. package/components/YlfInput.vue +67 -0
  13. package/components/YlfLogo.vue +7 -5
  14. package/components/YlfNavigation.vue +84 -0
  15. package/components/YlfNavigationLink.vue +59 -0
  16. package/components/YlfNavigationTrigger.vue +53 -0
  17. package/components/YlfPopover.vue +43 -7
  18. package/components/YlfRadioGroup.vue +41 -6
  19. package/components/YlfSegmentedControl.vue +80 -10
  20. package/components/YlfSelect.vue +43 -12
  21. package/components/YlfSlider.vue +16 -5
  22. package/components/YlfSwitch.vue +30 -4
  23. package/components/YlfTabs.vue +12 -4
  24. package/components/YlfTooltip.vue +29 -4
  25. package/components/_navigation.scss +38 -0
  26. package/components/accordion/demo.vue +1 -1
  27. package/components/agent-card/demo.vue +17 -0
  28. package/components/agent-card/index.md +25 -0
  29. package/components/agent-status/demo.vue +38 -0
  30. package/components/agent-status/index.md +20 -0
  31. package/components/agent-task/demo.vue +15 -0
  32. package/components/agent-task/index.md +25 -0
  33. package/components/agent.ts +2 -0
  34. package/components/button/demo.vue +21 -0
  35. package/components/button/index.md +20 -11
  36. package/components/cloud/demo.vue +92 -0
  37. package/components/cloud/index.md +66 -0
  38. package/components/cloud.ts +4 -0
  39. package/components/input/demo.vue +22 -0
  40. package/components/input/index.md +19 -0
  41. package/components/navigation/demo.vue +104 -0
  42. package/components/navigation/index.md +90 -0
  43. package/components/navigation-indicator.ts +114 -0
  44. package/dist/ag-ui.cjs +132 -0
  45. package/dist/ag-ui.d.cts +25 -0
  46. package/dist/ag-ui.d.mts +25 -0
  47. package/dist/ag-ui.d.ts +25 -0
  48. package/dist/ag-ui.mjs +130 -0
  49. package/dist/components/YlfAgentCard.vue.d.ts +24 -0
  50. package/dist/components/YlfAgentStatus.vue.d.ts +13 -0
  51. package/dist/components/YlfAgentTask.vue.d.ts +23 -0
  52. package/dist/components/YlfAvatar.vue.d.ts +1 -1
  53. package/dist/components/YlfButton.vue.d.ts +8 -5
  54. package/dist/components/YlfCloud.vue.d.ts +15 -0
  55. package/dist/components/YlfDialog.vue.d.ts +5 -5
  56. package/dist/components/YlfDropdownMenu.vue.d.ts +2 -2
  57. package/dist/components/YlfInput.vue.d.ts +18 -0
  58. package/dist/components/YlfNavigation.vue.d.ts +23 -0
  59. package/dist/components/YlfNavigationLink.vue.d.ts +21 -0
  60. package/dist/components/YlfNavigationTrigger.vue.d.ts +18 -0
  61. package/dist/components/YlfPopover.vue.d.ts +3 -3
  62. package/dist/components/YlfProgress.vue.d.ts +1 -1
  63. package/dist/components/YlfSeparator.vue.d.ts +2 -2
  64. package/dist/components/YlfSwitch.vue.d.ts +1 -1
  65. package/dist/components/YlfTabs.vue.d.ts +3 -3
  66. package/dist/components/YlfTooltip.vue.d.ts +3 -3
  67. package/dist/components/agent.d.ts +2 -0
  68. package/dist/components/cloud.d.ts +3 -0
  69. package/dist/components/navigation-indicator.d.ts +14 -0
  70. package/dist/index.cjs +3 -0
  71. package/dist/index.d.cts +9 -2
  72. package/dist/index.d.mts +9 -2
  73. package/dist/index.d.ts +9 -2
  74. package/dist/index.mjs +3 -1
  75. package/package.json +16 -6
@@ -0,0 +1,104 @@
1
+ <script setup lang="ts">
2
+ import { computed, shallowRef } from 'vue'
3
+ import YlfDropdownMenu from '../YlfDropdownMenu.vue'
4
+ import YlfNavigation from '../YlfNavigation.vue'
5
+ import YlfNavigationLink from '../YlfNavigationLink.vue'
6
+ import YlfNavigationTrigger from '../YlfNavigationTrigger.vue'
7
+
8
+ const current = shallowRef('blog')
9
+ const site = shallowRef('website')
10
+ const items = [
11
+ { id: 'help', label: '帮助' },
12
+ { id: 'membership', label: '会员' },
13
+ { id: 'blog', label: '博客' },
14
+ { id: 'updates', label: '日志' },
15
+ ]
16
+ const sites = [
17
+ { value: 'website', label: '官网' },
18
+ { value: 'apps', label: '应用' },
19
+ { value: 'studio', label: '工作室' },
20
+ ]
21
+ const siteLabel = computed(() => sites.find(item => item.value === site.value)?.label)
22
+ const currentLabel = computed(() => items.find(item => item.id === current.value)?.label)
23
+ </script>
24
+
25
+ <template>
26
+ <div class="ylf-navigation-demo">
27
+ <div class="ylf-navigation-demo__header">
28
+ <div class="ylf-navigation-demo__brand">
29
+ <strong>云乐坊</strong>
30
+ <YlfDropdownMenu :items="sites" @select="site = $event">
31
+ <template #trigger>
32
+ <YlfNavigationTrigger>{{ siteLabel }}</YlfNavigationTrigger>
33
+ </template>
34
+ </YlfDropdownMenu>
35
+ </div>
36
+ <YlfNavigation label="主导航预览">
37
+ <YlfNavigationLink
38
+ v-for="item in items"
39
+ :key="item.id"
40
+ :href="`#${item.id}`"
41
+ :active="current === item.id"
42
+ @click.prevent="current = item.id"
43
+ >
44
+ {{ item.label }}
45
+ </YlfNavigationLink>
46
+ </YlfNavigation>
47
+ </div>
48
+
49
+ <p class="ylf-navigation-demo__status" aria-live="polite">
50
+ 当前选择:{{ siteLabel }} / {{ currentLabel }}
51
+ </p>
52
+ <div class="ylf-navigation-demo__vertical">
53
+ <YlfNavigation label="抽屉导航预览" orientation="vertical">
54
+ <YlfNavigationLink
55
+ v-for="item in items"
56
+ :key="item.id"
57
+ :href="`#${item.id}`"
58
+ :active="current === item.id"
59
+ @click.prevent="current = item.id"
60
+ >
61
+ {{ item.label }}
62
+ </YlfNavigationLink>
63
+ </YlfNavigation>
64
+ </div>
65
+ <YlfNavigationTrigger disabled>
66
+ 更多站点
67
+ </YlfNavigationTrigger>
68
+ </div>
69
+ </template>
70
+
71
+ <style scoped>
72
+ .ylf-navigation-demo {
73
+ display: grid;
74
+ justify-items: start;
75
+ gap: var(--ylf-space-4);
76
+ width: 100%;
77
+ }
78
+ .ylf-navigation-demo__header {
79
+ display: flex;
80
+ flex-wrap: wrap;
81
+ align-items: center;
82
+ gap: var(--ylf-space-4);
83
+ width: 100%;
84
+ padding-block: var(--ylf-space-2);
85
+ border-bottom: 1px solid var(--ylf-c-border);
86
+ }
87
+ .ylf-navigation-demo__brand {
88
+ display: flex;
89
+ align-items: center;
90
+ gap: var(--ylf-space-3);
91
+ }
92
+ .ylf-navigation-demo__status {
93
+ margin: 0;
94
+ color: var(--ylf-c-text-2);
95
+ font-size: var(--ylf-text-sm);
96
+ }
97
+ .ylf-navigation-demo__vertical {
98
+ box-sizing: border-box;
99
+ width: min(100%, 280px);
100
+ padding: var(--ylf-space-2);
101
+ border: 1px solid var(--ylf-c-border);
102
+ border-radius: var(--ylf-radius);
103
+ }
104
+ </style>
@@ -0,0 +1,90 @@
1
+ ---
2
+ title: Navigation
3
+ title_zh: 站点导航
4
+ description: 有呼吸感的站点导航,区分当前位置、悬停和键盘焦点,支持路由链接与站点切换。
5
+ ---
6
+
7
+ `YlfNavigation` 组织链接,`YlfNavigationLink` 标记当前页面,`YlfNavigationTrigger` 为站点切换等下拉菜单提供统一入口。适合官网、内容站和应用页头;页内面板切换请使用 Tabs。
8
+
9
+ ## 间距与状态
10
+
11
+ - 所有入口至少 44px 高;正文 14px / 500;水平链接间距 8px,垂直链接间距 4px。
12
+ - 默认中性文字,悬停使用中性浅底;当前页为晴空蓝,水平导航增加 16×2px 短线,垂直导航使用浅蓝底。
13
+ - 键盘焦点使用内收 2px 轮廓,不替代当前页标记,也不向相邻入口扩张。
14
+ - 水平导航默认用同一条下划线随 `active` 移动,过渡读取 `--ylf-duration-normal`(240ms)与 `--ylf-ease-standard`。快速连续切换会从当前位置转向新目标;布局换行、链接尺寸变化时重新对齐。首次出现不从左侧飞入,无当前页时隐藏,垂直导航保留背景标记。减少动态效果时即时定位,也可用 `:animated="false"` 保留静态下划线。
15
+ - 品牌与站点切换建议间隔 12px,品牌组与导航建议间隔 16px。页头高度、响应式断点及账户区域由应用布局决定。
16
+ - 颜色、圆角、字号与动效读取共享 token;支持局部主题及减少动态效果。
17
+
18
+ ## 接入
19
+
20
+ ```vue
21
+ <script setup lang="ts">
22
+ import YlfNavigation from '@yunlefun/vue/components/YlfNavigation.vue'
23
+ import YlfNavigationLink from '@yunlefun/vue/components/YlfNavigationLink.vue'
24
+ import '@yunlefun/ui/css'
25
+ </script>
26
+
27
+ <template>
28
+ <YlfNavigation label="主导航">
29
+ <YlfNavigationLink href="/docs">
30
+ 帮助
31
+ </YlfNavigationLink>
32
+ <YlfNavigationLink href="/blog" active>
33
+ 博客
34
+ </YlfNavigationLink>
35
+ </YlfNavigation>
36
+ </template>
37
+ ```
38
+
39
+ Nuxt / Vue Router 使用 `as-child` 将样式、当前页语义和事件合并到单个链接,避免嵌套 `<a>`。应用负责计算 `active`,每组仅一个当前页。路由、认证请求和埋点不进入设计组件。
40
+
41
+ ```vue
42
+ <YlfNavigationLink :active="route.path.startsWith('/blog')" as-child>
43
+ <NuxtLink to="/blog">博客</NuxtLink>
44
+ </YlfNavigationLink>
45
+ ```
46
+
47
+ `YlfNavigationTrigger` 放进 `YlfDropdownMenu` 的 `trigger` 插槽,或 Reka `DropdownMenuTrigger as-child`。菜单负责开关状态、`aria-expanded`、焦点恢复与键盘操作;按钮读取这些属性绘制展开状态,不维护第二份 `open`。
48
+
49
+ ```vue
50
+ <YlfDropdownMenu :items="sites" @select="switchSite">
51
+ <template #trigger>
52
+ <YlfNavigationTrigger>官网</YlfNavigationTrigger>
53
+ </template>
54
+ </YlfDropdownMenu>
55
+ ```
56
+
57
+ 水平导航允许换行。手机页头需要收起时,由应用在自己的断点切换到有可访问名称的抽屉,在抽屉内使用 `orientation="vertical"`;不在公共组件内硬编码屏幕宽度或业务链接。
58
+
59
+ ## Props
60
+
61
+ ### YlfNavigation
62
+
63
+ | 属性 | 说明 | 类型 | 默认值 |
64
+ | ------------- | -------------------------------------- | ------------------------ | ------------ |
65
+ | `label` | 必填的可访问名称,同页多个导航应可区分 | `string` | — |
66
+ | `orientation` | 排列方向与当前页标记样式 | `horizontal \| vertical` | `horizontal` |
67
+ | `animated` | 水平当前页下划线的移动动画 | `boolean` | `true` |
68
+
69
+ ### YlfNavigationLink
70
+
71
+ | 属性 | 说明 | 类型 | 默认值 |
72
+ | --------- | ------------------------------------ | --------- | ------- |
73
+ | `active` | 当前页面,输出 `aria-current="page"` | `boolean` | `false` |
74
+ | `asChild` | 将属性合并到插槽的单个链接 | `boolean` | `false` |
75
+
76
+ `href`、`target`、`rel`、可访问属性和事件透传到实际链接。不要给不可访问的页面伪造禁用链接:根据产品需求隐藏入口或显示说明。
77
+
78
+ ### YlfNavigationTrigger
79
+
80
+ | 属性 | 说明 | 类型 | 默认值 |
81
+ | ---------- | -------------- | --------- | ------- |
82
+ | `disabled` | 原生按钮禁用态 | `boolean` | `false` |
83
+
84
+ 三个组件均提供默认插槽。Trigger 的插槽为按钮文案,箭头由组件绘制;其余原生属性与事件透传到按钮,默认 `type="button"`。
85
+
86
+ ## 验收重点
87
+
88
+ 用 Tab 顺序访问链接与触发器,Enter 打开链接或菜单,Escape 关闭菜单后焦点回到触发器。当前位置与相邻焦点应可同时辨认。检查浅色、深色、390px、768px 与桌面,手机入口保留 44px 点击高度。
89
+
90
+ 视觉参考:[Header navigations — Untitled UI / Dribbble](https://dribbble.com/shots/17564385-Header-navigations-Untitled-UI)。规则来自云乐坊主站的实际导航验证,不复制参考稿的品牌或业务内容。
@@ -0,0 +1,114 @@
1
+ import type { Ref } from 'vue'
2
+ import { onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'
3
+
4
+ /** Shared geometry for native documentation menus and YlfNavigation. No routing ownership. */
5
+ export function useNavigationIndicator(root: Readonly<Ref<HTMLElement | null>>, options: {
6
+ links: (root: HTMLElement) => HTMLElement[]
7
+ active: (link: HTMLElement) => boolean
8
+ attributes: string[]
9
+ enabled?: () => boolean
10
+ }) {
11
+ const indicator = shallowRef<{ x: number, y: number } | null>(null)
12
+ let frame: number | undefined
13
+ let resizeObserver: ResizeObserver | undefined
14
+ let mutationObserver: MutationObserver | undefined
15
+ let connectedElement: HTMLElement | null = null
16
+ const observedLinks = new Set<HTMLElement>()
17
+
18
+ function update() {
19
+ const element = root.value
20
+ const active = element && options.links(element).find(options.active)
21
+ if (!element || !active || options.enabled?.() === false) {
22
+ indicator.value = null
23
+ return
24
+ }
25
+ const bounds = element.getBoundingClientRect()
26
+ const target = active.getBoundingClientRect()
27
+ if (!bounds.width || !target.width || !target.height) {
28
+ indicator.value = null
29
+ return
30
+ }
31
+ // Convert viewport coordinates to the padding box, including scaled previews.
32
+ const scaleX = element.offsetWidth ? bounds.width / element.offsetWidth : 1
33
+ const scaleY = element.offsetHeight ? bounds.height / element.offsetHeight : 1
34
+ const x = (target.left - bounds.left + target.width / 2) / scaleX - element.clientLeft + element.scrollLeft - 8
35
+ const y = (target.bottom - bounds.top) / scaleY - element.clientTop + element.scrollTop - 6
36
+ if (indicator.value?.x !== x || indicator.value?.y !== y)
37
+ indicator.value = { x, y }
38
+ }
39
+
40
+ function scheduleUpdate() {
41
+ if (!root.value || frame !== undefined)
42
+ return
43
+ frame = requestAnimationFrame(() => {
44
+ frame = undefined
45
+ update()
46
+ })
47
+ }
48
+
49
+ function observeLinks() {
50
+ const current = new Set(root.value ? options.links(root.value) : [])
51
+ for (const link of observedLinks) {
52
+ if (!current.has(link)) {
53
+ resizeObserver?.unobserve(link)
54
+ observedLinks.delete(link)
55
+ }
56
+ }
57
+ for (const link of current) {
58
+ if (!observedLinks.has(link)) {
59
+ resizeObserver?.observe(link)
60
+ observedLinks.add(link)
61
+ }
62
+ }
63
+ }
64
+
65
+ function disconnect() {
66
+ if (frame !== undefined)
67
+ cancelAnimationFrame(frame)
68
+ frame = undefined
69
+ resizeObserver?.disconnect()
70
+ mutationObserver?.disconnect()
71
+ observedLinks.clear()
72
+ }
73
+
74
+ function connect() {
75
+ if (root.value === connectedElement)
76
+ return
77
+ disconnect()
78
+ indicator.value = null
79
+ const element = root.value
80
+ connectedElement = element
81
+ if (!element)
82
+ return
83
+ if (typeof ResizeObserver !== 'undefined') {
84
+ resizeObserver = new ResizeObserver(scheduleUpdate)
85
+ resizeObserver.observe(element)
86
+ }
87
+ observeLinks()
88
+ mutationObserver = new MutationObserver((mutations) => {
89
+ if (mutations.some(mutation => mutation.type === 'childList'))
90
+ observeLinks()
91
+ scheduleUpdate()
92
+ })
93
+ mutationObserver.observe(element, {
94
+ subtree: true,
95
+ childList: true,
96
+ attributes: true,
97
+ attributeFilter: options.attributes,
98
+ })
99
+ scheduleUpdate()
100
+ }
101
+
102
+ onMounted(() => {
103
+ connect()
104
+ window.addEventListener('resize', scheduleUpdate)
105
+ })
106
+ watch(root, connect, { flush: 'post' })
107
+ if (options.enabled)
108
+ watch(options.enabled, scheduleUpdate, { flush: 'post' })
109
+ onBeforeUnmount(() => {
110
+ disconnect()
111
+ window.removeEventListener('resize', scheduleUpdate)
112
+ })
113
+ return indicator
114
+ }
package/dist/ag-ui.cjs ADDED
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ const client = require('@ag-ui/client');
4
+ const vue = require('vue');
5
+
6
+ function useAgUiAgent(agent) {
7
+ const messages = vue.shallowRef(client.structuredClone_(agent.messages));
8
+ const state = vue.shallowRef(client.structuredClone_(agent.state));
9
+ const status = vue.shallowRef("idle");
10
+ const isRunning = vue.shallowRef(false);
11
+ const error = vue.shallowRef();
12
+ const interrupts = vue.shallowRef(client.structuredClone_(agent.pendingInterrupts));
13
+ const pendingToolCallIds = vue.shallowRef([]);
14
+ let disposed = false;
15
+ let cancelRequested = false;
16
+ function sync() {
17
+ if (disposed)
18
+ return;
19
+ messages.value = client.structuredClone_(agent.messages);
20
+ state.value = client.structuredClone_(agent.state);
21
+ interrupts.value = client.structuredClone_(agent.pendingInterrupts);
22
+ }
23
+ const subscription = agent.subscribe({
24
+ onMessagesChanged: sync,
25
+ onStateChanged: sync,
26
+ onRunFinishedEvent(result) {
27
+ if (disposed || cancelRequested)
28
+ return;
29
+ status.value = result.outcome === "interrupt" ? "interrupted" : result.outcome === "cancelled" ? "cancelled" : "success";
30
+ pendingToolCallIds.value = result.outcome === "success" ? [...result.pendingToolCallIds] : [];
31
+ },
32
+ onRunErrorEvent({ event }) {
33
+ if (disposed || cancelRequested)
34
+ return;
35
+ error.value = new Error(event.message);
36
+ status.value = "error";
37
+ }
38
+ });
39
+ function assertAvailable() {
40
+ if (disposed)
41
+ throw new Error("This AG-UI binding has been disposed.");
42
+ if (isRunning.value || agent.isRunning)
43
+ throw new Error("Wait for the current AG-UI run to finish before starting another.");
44
+ }
45
+ function assertReadyToRun() {
46
+ assertAvailable();
47
+ if (pendingToolCallIds.value.length)
48
+ throw new Error("Provide the pending tool results before starting another AG-UI run.");
49
+ }
50
+ async function run(parameters) {
51
+ assertReadyToRun();
52
+ cancelRequested = false;
53
+ error.value = void 0;
54
+ status.value = "running";
55
+ isRunning.value = true;
56
+ try {
57
+ const result = await agent.runAgent(parameters);
58
+ if (!disposed && !cancelRequested && status.value === "running")
59
+ status.value = "success";
60
+ return result;
61
+ } catch (cause) {
62
+ if (!disposed && !cancelRequested) {
63
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
64
+ status.value = "error";
65
+ }
66
+ } finally {
67
+ if (!disposed) {
68
+ if (cancelRequested)
69
+ status.value = "cancelled";
70
+ isRunning.value = false;
71
+ sync();
72
+ }
73
+ }
74
+ }
75
+ function send(content, parameters) {
76
+ assertReadyToRun();
77
+ if (!content.trim())
78
+ return Promise.resolve(void 0);
79
+ agent.addMessage({ id: client.randomUUID(), role: "user", content });
80
+ sync();
81
+ return run(parameters);
82
+ }
83
+ function cancel() {
84
+ if (disposed || !isRunning.value)
85
+ return;
86
+ cancelRequested = true;
87
+ agent.abortRun();
88
+ }
89
+ function setState(value) {
90
+ assertAvailable();
91
+ agent.setState(client.structuredClone_(value));
92
+ sync();
93
+ }
94
+ function addToolResult(toolCallId, content) {
95
+ assertAvailable();
96
+ if (!pendingToolCallIds.value.includes(toolCallId))
97
+ throw new Error("The tool call is not awaiting a result.");
98
+ agent.addMessage({ id: client.randomUUID(), role: "tool", toolCallId, content });
99
+ pendingToolCallIds.value = pendingToolCallIds.value.filter((id) => id !== toolCallId);
100
+ sync();
101
+ }
102
+ function dispose() {
103
+ if (disposed)
104
+ return;
105
+ cancel();
106
+ disposed = true;
107
+ subscription.unsubscribe();
108
+ isRunning.value = false;
109
+ if (cancelRequested)
110
+ status.value = "cancelled";
111
+ }
112
+ if (vue.getCurrentScope())
113
+ vue.onScopeDispose(dispose);
114
+ return {
115
+ messages: vue.readonly(messages),
116
+ state: vue.readonly(state),
117
+ status: vue.readonly(status),
118
+ isRunning: vue.readonly(isRunning),
119
+ error: vue.readonly(error),
120
+ interrupts: vue.readonly(interrupts),
121
+ pendingToolCallIds: vue.readonly(pendingToolCallIds),
122
+ isAwaitingInput: vue.computed(() => !isRunning.value && (interrupts.value.length > 0 || pendingToolCallIds.value.length > 0)),
123
+ run,
124
+ send,
125
+ cancel,
126
+ setState,
127
+ addToolResult,
128
+ dispose
129
+ };
130
+ }
131
+
132
+ exports.useAgUiAgent = useAgUiAgent;
@@ -0,0 +1,25 @@
1
+ import { Message, Interrupt, RunAgentParameters, RunAgentResult, AbstractAgent } from '@ag-ui/client';
2
+ import { Ref, DeepReadonly, ComputedRef } from 'vue';
3
+
4
+ type AgUiStatus = 'idle' | 'running' | 'success' | 'cancelled' | 'interrupted' | 'error';
5
+ interface AgUiBinding<TState> {
6
+ messages: Readonly<Ref<readonly DeepReadonly<Message>[]>>;
7
+ state: Readonly<Ref<DeepReadonly<TState>>>;
8
+ status: Readonly<Ref<AgUiStatus>>;
9
+ isRunning: Readonly<Ref<boolean>>;
10
+ error: Readonly<Ref<Error | undefined>>;
11
+ interrupts: Readonly<Ref<readonly DeepReadonly<Interrupt>[]>>;
12
+ pendingToolCallIds: Readonly<Ref<readonly string[]>>;
13
+ isAwaitingInput: ComputedRef<boolean>;
14
+ run: (parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
15
+ send: (content: string, parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
16
+ cancel: () => void;
17
+ setState: (value: TState) => void;
18
+ addToolResult: (toolCallId: string, content: string) => void;
19
+ dispose: () => void;
20
+ }
21
+ /** One agent per owner. SDK events remain the source of truth; no transport runs on setup/SSR. */
22
+ declare function useAgUiAgent<TState = Record<string, unknown>>(agent: AbstractAgent): AgUiBinding<TState>;
23
+
24
+ export { useAgUiAgent };
25
+ export type { AgUiBinding, AgUiStatus };
@@ -0,0 +1,25 @@
1
+ import { Message, Interrupt, RunAgentParameters, RunAgentResult, AbstractAgent } from '@ag-ui/client';
2
+ import { Ref, DeepReadonly, ComputedRef } from 'vue';
3
+
4
+ type AgUiStatus = 'idle' | 'running' | 'success' | 'cancelled' | 'interrupted' | 'error';
5
+ interface AgUiBinding<TState> {
6
+ messages: Readonly<Ref<readonly DeepReadonly<Message>[]>>;
7
+ state: Readonly<Ref<DeepReadonly<TState>>>;
8
+ status: Readonly<Ref<AgUiStatus>>;
9
+ isRunning: Readonly<Ref<boolean>>;
10
+ error: Readonly<Ref<Error | undefined>>;
11
+ interrupts: Readonly<Ref<readonly DeepReadonly<Interrupt>[]>>;
12
+ pendingToolCallIds: Readonly<Ref<readonly string[]>>;
13
+ isAwaitingInput: ComputedRef<boolean>;
14
+ run: (parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
15
+ send: (content: string, parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
16
+ cancel: () => void;
17
+ setState: (value: TState) => void;
18
+ addToolResult: (toolCallId: string, content: string) => void;
19
+ dispose: () => void;
20
+ }
21
+ /** One agent per owner. SDK events remain the source of truth; no transport runs on setup/SSR. */
22
+ declare function useAgUiAgent<TState = Record<string, unknown>>(agent: AbstractAgent): AgUiBinding<TState>;
23
+
24
+ export { useAgUiAgent };
25
+ export type { AgUiBinding, AgUiStatus };
@@ -0,0 +1,25 @@
1
+ import { Message, Interrupt, RunAgentParameters, RunAgentResult, AbstractAgent } from '@ag-ui/client';
2
+ import { Ref, DeepReadonly, ComputedRef } from 'vue';
3
+
4
+ type AgUiStatus = 'idle' | 'running' | 'success' | 'cancelled' | 'interrupted' | 'error';
5
+ interface AgUiBinding<TState> {
6
+ messages: Readonly<Ref<readonly DeepReadonly<Message>[]>>;
7
+ state: Readonly<Ref<DeepReadonly<TState>>>;
8
+ status: Readonly<Ref<AgUiStatus>>;
9
+ isRunning: Readonly<Ref<boolean>>;
10
+ error: Readonly<Ref<Error | undefined>>;
11
+ interrupts: Readonly<Ref<readonly DeepReadonly<Interrupt>[]>>;
12
+ pendingToolCallIds: Readonly<Ref<readonly string[]>>;
13
+ isAwaitingInput: ComputedRef<boolean>;
14
+ run: (parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
15
+ send: (content: string, parameters?: RunAgentParameters) => Promise<RunAgentResult | undefined>;
16
+ cancel: () => void;
17
+ setState: (value: TState) => void;
18
+ addToolResult: (toolCallId: string, content: string) => void;
19
+ dispose: () => void;
20
+ }
21
+ /** One agent per owner. SDK events remain the source of truth; no transport runs on setup/SSR. */
22
+ declare function useAgUiAgent<TState = Record<string, unknown>>(agent: AbstractAgent): AgUiBinding<TState>;
23
+
24
+ export { useAgUiAgent };
25
+ export type { AgUiBinding, AgUiStatus };
package/dist/ag-ui.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import { structuredClone_, randomUUID } from '@ag-ui/client';
2
+ import { shallowRef, getCurrentScope, onScopeDispose, computed, readonly } from 'vue';
3
+
4
+ function useAgUiAgent(agent) {
5
+ const messages = shallowRef(structuredClone_(agent.messages));
6
+ const state = shallowRef(structuredClone_(agent.state));
7
+ const status = shallowRef("idle");
8
+ const isRunning = shallowRef(false);
9
+ const error = shallowRef();
10
+ const interrupts = shallowRef(structuredClone_(agent.pendingInterrupts));
11
+ const pendingToolCallIds = shallowRef([]);
12
+ let disposed = false;
13
+ let cancelRequested = false;
14
+ function sync() {
15
+ if (disposed)
16
+ return;
17
+ messages.value = structuredClone_(agent.messages);
18
+ state.value = structuredClone_(agent.state);
19
+ interrupts.value = structuredClone_(agent.pendingInterrupts);
20
+ }
21
+ const subscription = agent.subscribe({
22
+ onMessagesChanged: sync,
23
+ onStateChanged: sync,
24
+ onRunFinishedEvent(result) {
25
+ if (disposed || cancelRequested)
26
+ return;
27
+ status.value = result.outcome === "interrupt" ? "interrupted" : result.outcome === "cancelled" ? "cancelled" : "success";
28
+ pendingToolCallIds.value = result.outcome === "success" ? [...result.pendingToolCallIds] : [];
29
+ },
30
+ onRunErrorEvent({ event }) {
31
+ if (disposed || cancelRequested)
32
+ return;
33
+ error.value = new Error(event.message);
34
+ status.value = "error";
35
+ }
36
+ });
37
+ function assertAvailable() {
38
+ if (disposed)
39
+ throw new Error("This AG-UI binding has been disposed.");
40
+ if (isRunning.value || agent.isRunning)
41
+ throw new Error("Wait for the current AG-UI run to finish before starting another.");
42
+ }
43
+ function assertReadyToRun() {
44
+ assertAvailable();
45
+ if (pendingToolCallIds.value.length)
46
+ throw new Error("Provide the pending tool results before starting another AG-UI run.");
47
+ }
48
+ async function run(parameters) {
49
+ assertReadyToRun();
50
+ cancelRequested = false;
51
+ error.value = void 0;
52
+ status.value = "running";
53
+ isRunning.value = true;
54
+ try {
55
+ const result = await agent.runAgent(parameters);
56
+ if (!disposed && !cancelRequested && status.value === "running")
57
+ status.value = "success";
58
+ return result;
59
+ } catch (cause) {
60
+ if (!disposed && !cancelRequested) {
61
+ error.value = cause instanceof Error ? cause : new Error(String(cause));
62
+ status.value = "error";
63
+ }
64
+ } finally {
65
+ if (!disposed) {
66
+ if (cancelRequested)
67
+ status.value = "cancelled";
68
+ isRunning.value = false;
69
+ sync();
70
+ }
71
+ }
72
+ }
73
+ function send(content, parameters) {
74
+ assertReadyToRun();
75
+ if (!content.trim())
76
+ return Promise.resolve(void 0);
77
+ agent.addMessage({ id: randomUUID(), role: "user", content });
78
+ sync();
79
+ return run(parameters);
80
+ }
81
+ function cancel() {
82
+ if (disposed || !isRunning.value)
83
+ return;
84
+ cancelRequested = true;
85
+ agent.abortRun();
86
+ }
87
+ function setState(value) {
88
+ assertAvailable();
89
+ agent.setState(structuredClone_(value));
90
+ sync();
91
+ }
92
+ function addToolResult(toolCallId, content) {
93
+ assertAvailable();
94
+ if (!pendingToolCallIds.value.includes(toolCallId))
95
+ throw new Error("The tool call is not awaiting a result.");
96
+ agent.addMessage({ id: randomUUID(), role: "tool", toolCallId, content });
97
+ pendingToolCallIds.value = pendingToolCallIds.value.filter((id) => id !== toolCallId);
98
+ sync();
99
+ }
100
+ function dispose() {
101
+ if (disposed)
102
+ return;
103
+ cancel();
104
+ disposed = true;
105
+ subscription.unsubscribe();
106
+ isRunning.value = false;
107
+ if (cancelRequested)
108
+ status.value = "cancelled";
109
+ }
110
+ if (getCurrentScope())
111
+ onScopeDispose(dispose);
112
+ return {
113
+ messages: readonly(messages),
114
+ state: readonly(state),
115
+ status: readonly(status),
116
+ isRunning: readonly(isRunning),
117
+ error: readonly(error),
118
+ interrupts: readonly(interrupts),
119
+ pendingToolCallIds: readonly(pendingToolCallIds),
120
+ isAwaitingInput: computed(() => !isRunning.value && (interrupts.value.length > 0 || pendingToolCallIds.value.length > 0)),
121
+ run,
122
+ send,
123
+ cancel,
124
+ setState,
125
+ addToolResult,
126
+ dispose
127
+ };
128
+ }
129
+
130
+ export { useAgUiAgent };
@@ -0,0 +1,24 @@
1
+ import type { YlfAgentState } from './agent';
2
+ type __VLS_Props = {
3
+ name: string;
4
+ description?: string;
5
+ state: YlfAgentState;
6
+ statusLabel: string;
7
+ };
8
+ declare var __VLS_1: {}, __VLS_8: {}, __VLS_10: {};
9
+ type __VLS_Slots = {} & {
10
+ avatar?: (props: typeof __VLS_1) => any;
11
+ } & {
12
+ default?: (props: typeof __VLS_8) => any;
13
+ } & {
14
+ actions?: (props: typeof __VLS_10) => any;
15
+ };
16
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
18
+ declare const _default: typeof __VLS_export;
19
+ export default _default;
20
+ type __VLS_WithSlots<T, S> = T & {
21
+ new (): {
22
+ $slots: S;
23
+ };
24
+ };