@camelai/run-vue 0.0.0 → 0.11.1
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/LICENSE +21 -0
- package/README.md +29 -1
- package/dist/index.d.ts +37 -0
- package/dist/index.js +62 -0
- package/package.json +39 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 qaml-ai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
# @camelai/run-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vue 3 bindings for a chat with an agent on camelRun, through your server's route
|
|
4
|
+
(`createAgentHandler` from `@camelai/run/server`; see the Frontend guide).
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { ref } from "vue";
|
|
9
|
+
import { useAgentChat } from "@camelai/run-vue";
|
|
10
|
+
|
|
11
|
+
const { messages, status, send, stop } = useAgentChat({ endpoint: "/api/agent" });
|
|
12
|
+
const text = ref("");
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<div v-for="message in messages" :key="message.id">
|
|
17
|
+
<p v-if="message.role === 'user'">{{ message.text }}</p>
|
|
18
|
+
<template v-else v-for="part in message.parts" :key="part.id">
|
|
19
|
+
<p v-if="part.type === 'text'">{{ part.text }}</p>
|
|
20
|
+
<small v-else-if="part.type === 'tool'">{{ part.name }}: {{ part.state }}</small>
|
|
21
|
+
</template>
|
|
22
|
+
</div>
|
|
23
|
+
<form @submit.prevent="send(text); text = ''"><input v-model="text" /><button>Send</button></form>
|
|
24
|
+
<button v-if="status === 'streaming'" @click="stop()">Stop</button>
|
|
25
|
+
</template>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`useAgentChat(options | chat)` returns refs (`messages`, `status`, `inputs`, `error`, `hasOlder`,
|
|
29
|
+
`snapshot`) and actions (`send`, `answer`, `decline`, `stop`, `retry`, `loadOlder`, `fileUrl`); the chat
|
|
30
|
+
is connected until the component unmounts. `provideAgentChat` / `useAgent` share one chat with
|
|
31
|
+
descendants. Render markdown with `parseMarkdown` from `@camelai/run/markdown`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue bindings for an agent chat: `useAgentChat` in a component's setup gives reactive refs over the
|
|
3
|
+
* chat with the user's agent (connected while the component lives) and its actions; `provideAgentChat`
|
|
4
|
+
* and `useAgent` share one chat with descendants.
|
|
5
|
+
*
|
|
6
|
+
* const { messages, status, send, stop } = useAgentChat({ endpoint: "/api/agent" });
|
|
7
|
+
*/
|
|
8
|
+
import { type Ref } from "vue";
|
|
9
|
+
import { type AgentChat, type AgentChatOptions, type ChatSnapshot } from "@camelai/run/chat";
|
|
10
|
+
export type * from "@camelai/run/chat";
|
|
11
|
+
export { answerValue, createAgentChat } from "@camelai/run/chat";
|
|
12
|
+
export interface UseAgentChat {
|
|
13
|
+
chat: AgentChat;
|
|
14
|
+
snapshot: Readonly<Ref<ChatSnapshot>>;
|
|
15
|
+
messages: Readonly<Ref<ChatSnapshot["messages"]>>;
|
|
16
|
+
status: Readonly<Ref<ChatSnapshot["status"]>>;
|
|
17
|
+
inputs: Readonly<Ref<ChatSnapshot["inputs"]>>;
|
|
18
|
+
error: Readonly<Ref<ChatSnapshot["error"]>>;
|
|
19
|
+
hasOlder: Readonly<Ref<boolean>>;
|
|
20
|
+
send: AgentChat["send"];
|
|
21
|
+
answer: AgentChat["answer"];
|
|
22
|
+
decline: AgentChat["decline"];
|
|
23
|
+
stop: AgentChat["stop"];
|
|
24
|
+
retry: AgentChat["retry"];
|
|
25
|
+
loadOlder: AgentChat["loadOlder"];
|
|
26
|
+
fileUrl: AgentChat["fileUrl"];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Refs over a chat: `options` makes one, or pass a chat you made. One it makes connects once the
|
|
30
|
+
* component is mounted (never while rendering on the server, as in Nuxt) and is destroyed with it (or
|
|
31
|
+
* with the effect scope). Each ref changes only when its part of the snapshot does.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useAgentChat(options: Omit<AgentChatOptions, "autoConnect"> | AgentChat): UseAgentChat;
|
|
34
|
+
/** Make a chat for this component and its descendants (`useAgent()` reads it). */
|
|
35
|
+
export declare function provideAgentChat(options: Omit<AgentChatOptions, "autoConnect"> | AgentChat): UseAgentChat;
|
|
36
|
+
/** The chat an ancestor provided. */
|
|
37
|
+
export declare function useAgent(): UseAgentChat;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue bindings for an agent chat: `useAgentChat` in a component's setup gives reactive refs over the
|
|
3
|
+
* chat with the user's agent (connected while the component lives) and its actions; `provideAgentChat`
|
|
4
|
+
* and `useAgent` share one chat with descendants.
|
|
5
|
+
*
|
|
6
|
+
* const { messages, status, send, stop } = useAgentChat({ endpoint: "/api/agent" });
|
|
7
|
+
*/
|
|
8
|
+
import { getCurrentInstance, getCurrentScope, inject, onMounted, onScopeDispose, provide, readonly, shallowRef } from "vue";
|
|
9
|
+
import { createAgentChat } from "@camelai/run/chat";
|
|
10
|
+
export { answerValue, createAgentChat } from "@camelai/run/chat";
|
|
11
|
+
/**
|
|
12
|
+
* Refs over a chat: `options` makes one, or pass a chat you made. One it makes connects once the
|
|
13
|
+
* component is mounted (never while rendering on the server, as in Nuxt) and is destroyed with it (or
|
|
14
|
+
* with the effect scope). Each ref changes only when its part of the snapshot does.
|
|
15
|
+
*/
|
|
16
|
+
export function useAgentChat(options) {
|
|
17
|
+
const own = !("getSnapshot" in options);
|
|
18
|
+
const chat = own ? createAgentChat({ ...options, autoConnect: false }) : options;
|
|
19
|
+
const snapshot = shallowRef(chat.getSnapshot());
|
|
20
|
+
const messages = shallowRef(snapshot.value.messages), status = shallowRef(snapshot.value.status), inputs = shallowRef(snapshot.value.inputs);
|
|
21
|
+
const error = shallowRef(snapshot.value.error), hasOlder = shallowRef(snapshot.value.hasOlder);
|
|
22
|
+
const unsubscribe = chat.subscribe(() => {
|
|
23
|
+
const next = chat.getSnapshot();
|
|
24
|
+
snapshot.value = next;
|
|
25
|
+
// shallowRef only triggers on a new value: unchanged parts keep their identity, so nothing re-renders for them.
|
|
26
|
+
messages.value = next.messages;
|
|
27
|
+
status.value = next.status;
|
|
28
|
+
inputs.value = next.inputs;
|
|
29
|
+
error.value = next.error;
|
|
30
|
+
hasOlder.value = next.hasOlder;
|
|
31
|
+
});
|
|
32
|
+
if (own) {
|
|
33
|
+
// In a component: once mounted, which only happens in a browser. Elsewhere: at once, in a browser only.
|
|
34
|
+
if (getCurrentInstance())
|
|
35
|
+
onMounted(() => chat.connect());
|
|
36
|
+
else if (typeof window !== "undefined")
|
|
37
|
+
chat.connect();
|
|
38
|
+
}
|
|
39
|
+
if (getCurrentScope())
|
|
40
|
+
onScopeDispose(() => { unsubscribe(); if (own)
|
|
41
|
+
chat.destroy(); });
|
|
42
|
+
return {
|
|
43
|
+
chat, snapshot: readonly(snapshot),
|
|
44
|
+
messages: readonly(messages), status: readonly(status), inputs: readonly(inputs),
|
|
45
|
+
error: readonly(error), hasOlder: readonly(hasOlder),
|
|
46
|
+
send: chat.send, answer: chat.answer, decline: chat.decline, stop: chat.stop, retry: chat.retry, loadOlder: chat.loadOlder, fileUrl: chat.fileUrl,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const KEY = Symbol("agent-chat");
|
|
50
|
+
/** Make a chat for this component and its descendants (`useAgent()` reads it). */
|
|
51
|
+
export function provideAgentChat(options) {
|
|
52
|
+
const value = useAgentChat(options);
|
|
53
|
+
provide(KEY, value);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
/** The chat an ancestor provided. */
|
|
57
|
+
export function useAgent() {
|
|
58
|
+
const value = inject(KEY, null);
|
|
59
|
+
if (!value)
|
|
60
|
+
throw new Error("useAgent needs an ancestor that called provideAgentChat");
|
|
61
|
+
return value;
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@camelai/run-vue",
|
|
3
|
+
"version": "0.11.1",
|
|
4
|
+
"description": "Vue bindings for chatting with agents on camelRun.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/qaml-ai/run.git",
|
|
10
|
+
"directory": "packages/vue"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://run.camelai.com",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"registry": "https://registry.npmjs.org",
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@camelai/run": "0.11.1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"vue": "^3.3.0"
|
|
38
|
+
}
|
|
39
|
+
}
|