@camelai/run-svelte 0.0.0 → 0.11.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/LICENSE +21 -0
- package/README.md +22 -1
- package/dist/index.d.ts +36 -0
- package/dist/index.js +43 -0
- package/package.json +36 -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,24 @@
|
|
|
1
1
|
# @camelai/run-svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte stores for a chat with an agent on camelRun, through your server's route
|
|
4
|
+
(`createAgentHandler` from `@camelai/run/server`; see the Frontend guide). They follow the
|
|
5
|
+
store contract, so they work in Svelte 4 and 5 (`$messages`), and have no dependency on Svelte.
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { agentChat } from "@camelai/run-svelte";
|
|
10
|
+
const { messages, status, send, stop } = agentChat({ endpoint: "/api/agent" });
|
|
11
|
+
let text = "";
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
{#each $messages as message (message.id)}
|
|
15
|
+
{#if message.role === "user"}<p>{message.text}</p>
|
|
16
|
+
{:else}{#each message.parts as part (part.id)}{#if part.type === "text"}<p>{part.text}</p>{/if}{/each}{/if}
|
|
17
|
+
{/each}
|
|
18
|
+
<form on:submit|preventDefault={() => { send(text); text = ""; }}><input bind:value={text} /><button>Send</button></form>
|
|
19
|
+
{#if $status === "streaming"}<button on:click={() => stop()}>Stop</button>{/if}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`agentChat(options | chat)` returns stores (`messages`, `status`, `inputs`, `error`, `hasOlder`,
|
|
23
|
+
`snapshot`) and actions (`send`, `answer`, `decline`, `stop`, `retry`, `loadOlder`, `fileUrl`). The
|
|
24
|
+
chat connects with the first subscriber and disconnects after the last.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte bindings for an agent chat: stores over the chat with the user's agent, connected while
|
|
3
|
+
* anything subscribes. They follow the store contract, so `$messages` works in Svelte 4 and 5.
|
|
4
|
+
*
|
|
5
|
+
* const chat = agentChat({ endpoint: "/api/agent" });
|
|
6
|
+
* const { messages, status } = chat; // then $messages, $status in markup
|
|
7
|
+
* chat.send("Hello");
|
|
8
|
+
*/
|
|
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
|
+
/** A Svelte store (the store contract), readable only. */
|
|
13
|
+
export interface Readable<T> {
|
|
14
|
+
subscribe(run: (value: T) => void): () => void;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentChatStores {
|
|
17
|
+
chat: AgentChat;
|
|
18
|
+
snapshot: Readable<ChatSnapshot>;
|
|
19
|
+
messages: Readable<ChatSnapshot["messages"]>;
|
|
20
|
+
status: Readable<ChatSnapshot["status"]>;
|
|
21
|
+
inputs: Readable<ChatSnapshot["inputs"]>;
|
|
22
|
+
error: Readable<ChatSnapshot["error"]>;
|
|
23
|
+
hasOlder: Readable<boolean>;
|
|
24
|
+
send: AgentChat["send"];
|
|
25
|
+
answer: AgentChat["answer"];
|
|
26
|
+
decline: AgentChat["decline"];
|
|
27
|
+
stop: AgentChat["stop"];
|
|
28
|
+
retry: AgentChat["retry"];
|
|
29
|
+
loadOlder: AgentChat["loadOlder"];
|
|
30
|
+
fileUrl: AgentChat["fileUrl"];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Stores over a chat: `options` makes one, connected in a browser from the first subscriber to the last
|
|
34
|
+
* (a chat you pass stays as you left it). Each store notifies only when its part of the snapshot changes.
|
|
35
|
+
*/
|
|
36
|
+
export declare function agentChat(options: Omit<AgentChatOptions, "autoConnect"> | AgentChat): AgentChatStores;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Svelte bindings for an agent chat: stores over the chat with the user's agent, connected while
|
|
3
|
+
* anything subscribes. They follow the store contract, so `$messages` works in Svelte 4 and 5.
|
|
4
|
+
*
|
|
5
|
+
* const chat = agentChat({ endpoint: "/api/agent" });
|
|
6
|
+
* const { messages, status } = chat; // then $messages, $status in markup
|
|
7
|
+
* chat.send("Hello");
|
|
8
|
+
*/
|
|
9
|
+
import { createAgentChat } from "@camelai/run/chat";
|
|
10
|
+
export { answerValue, createAgentChat } from "@camelai/run/chat";
|
|
11
|
+
/**
|
|
12
|
+
* Stores over a chat: `options` makes one, connected in a browser from the first subscriber to the last
|
|
13
|
+
* (a chat you pass stays as you left it). Each store notifies only when its part of the snapshot changes.
|
|
14
|
+
*/
|
|
15
|
+
export function agentChat(options) {
|
|
16
|
+
const own = !("getSnapshot" in options);
|
|
17
|
+
const chat = own ? createAgentChat({ ...options, autoConnect: false }) : options;
|
|
18
|
+
let subscribers = 0;
|
|
19
|
+
const select = (pick) => ({
|
|
20
|
+
subscribe(run) {
|
|
21
|
+
// Server rendering subscribes too: a chat connects only in a browser.
|
|
22
|
+
if (subscribers++ === 0 && own && typeof window !== "undefined")
|
|
23
|
+
chat.connect();
|
|
24
|
+
let last = pick(chat.getSnapshot());
|
|
25
|
+
run(last);
|
|
26
|
+
const off = chat.subscribe(() => {
|
|
27
|
+
const next = pick(chat.getSnapshot());
|
|
28
|
+
if (!Object.is(next, last)) {
|
|
29
|
+
last = next;
|
|
30
|
+
run(next);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return () => { off(); if (--subscribers === 0 && own)
|
|
34
|
+
chat.disconnect(); };
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
chat,
|
|
39
|
+
snapshot: select(snapshot => snapshot), messages: select(snapshot => snapshot.messages), status: select(snapshot => snapshot.status),
|
|
40
|
+
inputs: select(snapshot => snapshot.inputs), error: select(snapshot => snapshot.error), hasOlder: select(snapshot => snapshot.hasOlder),
|
|
41
|
+
send: chat.send, answer: chat.answer, decline: chat.decline, stop: chat.stop, retry: chat.retry, loadOlder: chat.loadOlder, fileUrl: chat.fileUrl,
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@camelai/run-svelte",
|
|
3
|
+
"version": "0.11.0",
|
|
4
|
+
"description": "Svelte 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/svelte"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://agents.camelai.dev",
|
|
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.0"
|
|
35
|
+
}
|
|
36
|
+
}
|