@vinaverse/client 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (41) hide show
  1. package/README.md +46 -0
  2. package/dist/agent/index.cjs +2852 -0
  3. package/dist/agent/index.cjs.map +1 -0
  4. package/dist/agent/index.d.cts +57 -0
  5. package/dist/agent/index.d.ts +57 -0
  6. package/dist/agent/index.js +99 -0
  7. package/dist/agent/index.js.map +1 -0
  8. package/dist/{chunk-MKUNSAMT.js → chunk-GWLLUOFY.js} +3 -9
  9. package/dist/chunk-GWLLUOFY.js.map +1 -0
  10. package/dist/chunk-VSJDVLCP.js +9 -0
  11. package/dist/chunk-VSJDVLCP.js.map +1 -0
  12. package/dist/chunk-XPES5PZ3.js +416 -0
  13. package/dist/chunk-XPES5PZ3.js.map +1 -0
  14. package/dist/chunk-ZWG2TMUL.js +975 -0
  15. package/dist/chunk-ZWG2TMUL.js.map +1 -0
  16. package/dist/contract-_NMdPjgN.d.cts +6 -0
  17. package/dist/contract-_NMdPjgN.d.ts +6 -0
  18. package/dist/conversation/index.cjs +1 -1
  19. package/dist/conversation/index.cjs.map +1 -1
  20. package/dist/conversation/index.d.cts +6 -377
  21. package/dist/conversation/index.d.ts +6 -377
  22. package/dist/conversation/index.js +5 -973
  23. package/dist/conversation/index.js.map +1 -1
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +2 -1
  26. package/dist/index.d.ts +2 -1
  27. package/dist/index.js +2 -1
  28. package/dist/runtime-CErMdYxJ.d.cts +234 -0
  29. package/dist/runtime-DLJbJkSr.d.ts +234 -0
  30. package/dist/{session-C3qZwGPG.d.cts → session-8W3fRNeb.d.cts} +1514 -253
  31. package/dist/{session-C3qZwGPG.d.ts → session-8W3fRNeb.d.ts} +1514 -253
  32. package/dist/store-C7FtS5AY.d.cts +384 -0
  33. package/dist/store-DFk0ayh8.d.ts +384 -0
  34. package/dist/testing/index.cjs +237 -0
  35. package/dist/testing/index.cjs.map +1 -0
  36. package/dist/testing/index.d.cts +49 -0
  37. package/dist/testing/index.d.ts +49 -0
  38. package/dist/testing/index.js +222 -0
  39. package/dist/testing/index.js.map +1 -0
  40. package/package.json +33 -1
  41. package/dist/chunk-MKUNSAMT.js.map +0 -1
package/README.md CHANGED
@@ -90,6 +90,52 @@ conversation.subscribe(() => draw(conversation.getSnapshot()));
90
90
 
91
91
  How it works, and what it guarantees: [docs/architecture/client.md](../../docs/architecture/client.md).
92
92
 
93
+ ## The agent runtime (`@vinaverse/client/agent`)
94
+
95
+ An app that hosts an agent writes one thing, its `AgentBackend` (its own API: open a session, a fresh secret, status,
96
+ feedback, sign-out), and the runtime does the rest: one conversation per person, mode, business and thread; kept
97
+ across screens while its session lives; the backend waited out, never answered with a new conversation; the agent's
98
+ status and name; ratings; sign-out; events for analytics. `readCard` reads a card for drawing, every field checked.
99
+
100
+ ```ts
101
+ import { AgentRefusal, createAgentRuntime } from '@vinaverse/client/agent';
102
+
103
+ const runtime = createAgentRuntime({
104
+ backend: {
105
+ openSession: async (request) => {
106
+ const answer = await api.openAgentSession(request); // your API, with the person's own sign-in
107
+ if (!answer.available) throw new AgentRefusal('unavailable');
108
+ return answer.session; // id, realtime_url, turns_url, client_secret, conversation_id, expires_at …
109
+ },
110
+ refreshSecret: (sessionId) => api.refreshAgentSecret(sessionId),
111
+ status: () => api.agentStatus(),
112
+ },
113
+ conversation: { locale: 'en-US', closeInBackground: true, deepLinkPrefixes: ['yourapp://'] },
114
+ onEvent: (event) => analytics.track(`agent_${event.type}`, event),
115
+ });
116
+
117
+ const chat = runtime.conversation({ subject: user.id, mode: 'customer' });
118
+ const release = chat.show({ place: { screen: 'explore' }, entryPoint: 'button' }); // when the screen goes: release()
119
+ ```
120
+
121
+ Policies and adapters: `retry: { delays, isRetryable }`, `clock: { now }` (the server's time for a session's end),
122
+ `keepAlive: 'session' | 'view'`, `onEvent` (analytics). `AgentBackend.updateContext` tells a new place live where your
123
+ API serves it. Failures are typed on the conversation (`failure`, `reason`, `code`), with `startNew(key)`.
124
+ History's "Continue" is `continue(key, conversationId)`: the key goes on with that conversation, and one that is gone
125
+ is said as `ended` (your backend throws `AgentRefusal('ended', { code })` on a 404 or 410). A session must have an id
126
+ and a secret, and `wss://` and `https://` addresses whatever transport you supply (a wrapper adding headers or logging
127
+ still gets only secure ones). `insecureAddresses: { realtime, turns }` allows plaintext for one leg: dangerous, for mocks
128
+ and local development only, and the runtime warns outside `__DEV__` (through `onWarning`, your logger, else `console.warn`).
129
+ A UI binding reads the key's conversation with `peek(key)`, which ends nothing (a render must not): one past its
130
+ session's end is ended when it is next shown, and `subscribe` then tells the binding to read the next one.
131
+
132
+ For a mock mode and tests, `@vinaverse/client/testing` has a scripted agent: `createMockAgent({ reply, refuse, welcome })`
133
+ gives an `AgentBackend` and a WebSocket factory that speaks the protocol (`conversation.transport.webSocket`), and
134
+ `mockCards` the cards your tools would.
135
+
136
+ The contract's types are exported too (`paths`, `components`, `operations`, `Schemas`): import them instead of copying
137
+ the spec. Design: [docs/architecture/agent-runtime.md](../../docs/architecture/agent-runtime.md).
138
+
93
139
  ## License
94
140
 
95
141
  Apache-2.0