DOCS
JS 客户端
SvedaClient 是挂载面。Vue、React、Svelte、Solid 与 web component 可选。
JS 客户端
SvedaClient 是挂载面。Vue、React、Svelte、Solid 与 web component 可选。
SvedaClient 选项、endpoint、header、session.send、frontend tool 注册表与 context。包 @sveda-ai/core。
Package
npm i @sveda-ai/core.
Main class
SvedaClient.
Session class
SvedaChatSession.
Product overview:
JS client.
SvedaClient options
endpoints.stream
is required. It is the
POST
target for a turn. Optional endpoints match the runtime:
message,
histories,
history(chatId),
documentsExtract.
-
protocolModedefaults to'sveda'. These docs cover that mode. -
headersis aRecord<string, string>or a getter() => Record<string, string>resolved on each request. -
toolsis aSvedaToolRegistry. If omitted, the client constructs one. -
contextis aSvedaContextRegistry. Snapshots merge into the stream bodycontextfield. -
autoSubmitFrontendToolResultsdefaults totrue. After atool.callwithtarget: "frontend", the session runs the handler and posts results on a follow-up stream turn.
import { SvedaClient, SvedaToolRegistry, SvedaContextRegistry } from '@sveda-ai/core'
const tools = new SvedaToolRegistry()
const context = new SvedaContextRegistry()
const client = new SvedaClient({
endpoints: {
stream: 'http://127.0.0.1:8787/sveda/stream',
message: 'http://127.0.0.1:8787/sveda/message',
histories: 'http://127.0.0.1:8787/sveda/chat-histories',
history: (chatId) => `http://127.0.0.1:8787/sveda/chat-histories/${chatId}`,
documentsExtract: 'http://127.0.0.1:8787/sveda/documents/extract',
},
protocolMode: 'sveda',
headers: {
'x-sveda-embed-token': token,
},
tools,
context,
autoSubmitFrontendToolResults: true,
})import { SvedaClient, SvedaToolRegistry, SvedaContextRegistry } from '@sveda-ai/core'
const tools = new SvedaToolRegistry()
const context = new SvedaContextRegistry()
const client = new SvedaClient({
endpoints: {
stream: 'http://127.0.0.1:8787/sveda/stream',
message: 'http://127.0.0.1:8787/sveda/message',
histories: 'http://127.0.0.1:8787/sveda/chat-histories',
history: (chatId) => `http://127.0.0.1:8787/sveda/chat-histories/${chatId}`,
documentsExtract: 'http://127.0.0.1:8787/sveda/documents/extract',
},
protocolMode: 'sveda',
headers: {
'x-sveda-embed-token': token,
},
tools,
context,
autoSubmitFrontendToolResults: true,
}) Headers
Typical embed header:
x-sveda-embed-token.
The runtime also accepts
Authorization: Bearer sveda_embed_….
A getter is useful when the token rotates.
const client = new SvedaClient({
endpoints: { stream: '/sveda/stream' },
headers: () => ({
'x-sveda-embed-token': currentToken(),
}),
})const client = new SvedaClient({
endpoints: { stream: '/sveda/stream' },
headers: () => ({
'x-sveda-embed-token': currentToken(),
}),
}) session.send and stop
client.session(chatId)
(or
createSession())
returns
SvedaChatSession.
send(text, options?)
POSTs JSON to
endpoints.stream
with
messages,
prompt,
chatId,
context,
clientTools,
optional
toolDecisions
when resolving a confirming tool call, and optional
model,
provider,
options.
stop()
aborts the in-flight request.
const session = client.session('chat_1')
await session.send('Summarize the last deploy.')
session.stop()const session = client.session('chat_1')
await session.send('Summarize the last deploy.')
session.stop() Tool confirmation
When the stream emits
tool.call
with
confirmation: "required",
call
resolveToolConfirmation
after the user chooses. Backend tools send
toolDecisions
without repeating arguments; frontend tools run the handler only on approve. While a call is pending, do not send a new user prompt — the server returns 409. Protocol and UI details:
tool confirmation.
await session.resolveToolConfirmation('call_del_1', 'approve')
// deny → host MCP is not called; frontend handler is skippedawait session.resolveToolConfirmation('call_del_1', 'approve')
// deny → host MCP is not called; frontend handler is skipped Accept
In
protocolMode: 'sveda'
the client sets this Accept header. The server still responds with SSE
(text/event-stream).
See stream protocol.
Accept: application/vnd.sveda.stream+jsonAccept: application/vnd.sveda.stream+json
Optional UI packages
@sveda-ai/vue,
@sveda-ai/react,
@sveda-ai/svelte,
@sveda-ai/solid,
and
@sveda-ai/element
wrap the same core client. Mount snippets:
chat UI.
They are not required to stream a turn.
npm i @sveda-ai/vue
npm i @sveda-ai/react
npm i @sveda-ai/svelte
npm i @sveda-ai/solid
npm i @sveda-ai/elementnpm i @sveda-ai/vue npm i @sveda-ai/react npm i @sveda-ai/svelte npm i @sveda-ai/solid npm i @sveda-ai/element
Related
Get started
Install, bind, mint, send.
Host SDKs
Mint the embed token from PHP, Python, Node, and more.
Stream protocol
SSE framing and event types.
MCP and tools
SvedaToolRegistry.register and builtins.
Tool confirmation
resolveToolConfirmation and toolDecisions.
Product: JS client
Universal attach, not a Vue widget.
Chat UI
Vue, React, Svelte, and Solid widgets.
Appearance
appearance on the UI package wins over sveda.yaml.