chatbase 0.2.0 → 0.4.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.
@@ -0,0 +1,78 @@
1
+ import { Flags } from '@oclif/core';
2
+ import { AgentCommand } from '../../base/agent-command.js';
3
+ import { throwIfError } from '../../client/client.js';
4
+ const VOICE_SESSION_COLUMNS = [
5
+ { key: 'sessionId', header: 'SESSION' },
6
+ { key: 'conversationId', header: 'CONVERSATION' },
7
+ { key: 'userId', header: 'USER' },
8
+ { key: 'roomName', header: 'ROOM' },
9
+ { key: 'maxDurationSeconds', header: 'MAX_SECONDS' },
10
+ { key: 'participantToken', header: 'TOKEN' }
11
+ ];
12
+ export default class VoiceStart extends AgentCommand {
13
+ static summary = 'Start a voice session';
14
+ static description = 'Create a real-time voice session for an agent and print its ' +
15
+ 'credentials. Pass the response to the Chatbase Voice SDK ' +
16
+ '(@chatbase-co/voice-sdk) in your client: the SDK connects, publishes ' +
17
+ 'the microphone, and the agent joins automatically. Requires a plan ' +
18
+ 'with voice mode enabled; voice minutes consume message credits. The ' +
19
+ 'participant token is abbreviated in the default output — use --json ' +
20
+ 'or --plain for the full value.';
21
+ static examples = [
22
+ '<%= config.bin %> voice start -a agt_123',
23
+ '<%= config.bin %> voice start --user user_42 --timezone Europe/Paris -a agt_123',
24
+ '<%= config.bin %> voice start --conversation 0b6a1f2e-7c3d-4a5b-8e9f-1a2b3c4d5e6f --json -a agt_123'
25
+ ];
26
+ static flags = {
27
+ ...AgentCommand.baseFlags,
28
+ conversation: Flags.string({
29
+ description: 'Conversation ID to reuse, grouping several sessions into one conversation (default: start a new conversation)'
30
+ }),
31
+ user: Flags.string({
32
+ description: 'Your end-user ID; send a stable value so per-user voice limits apply (default: generated per session)'
33
+ }),
34
+ timezone: Flags.string({
35
+ description: 'IANA timezone of the end user, used by the agent for time-aware answers',
36
+ default: 'UTC'
37
+ })
38
+ };
39
+ async run() {
40
+ const { flags } = await this.parse(VoiceStart);
41
+ const client = this.apiClient(flags);
42
+ const agentId = await this.agentId(flags, client);
43
+ // `timezone` carries a spec default, so it is required in the body type.
44
+ const body = {
45
+ timezone: flags.timezone,
46
+ ...(flags.conversation
47
+ ? { conversationId: flags.conversation }
48
+ : {}),
49
+ ...(flags.user ? { userId: flags.user } : {})
50
+ };
51
+ const { data, error, response } = await client.POST('/agents/{agentId}/voice/sessions', { params: { path: { agentId } }, body });
52
+ throwIfError(response, error);
53
+ const session = data.data;
54
+ const row = {
55
+ sessionId: session.sessionId,
56
+ conversationId: session.conversationId,
57
+ userId: session.userId,
58
+ roomName: session.roomName,
59
+ maxDurationSeconds: String(session.maxDurationSeconds),
60
+ participantToken: session.participantToken
61
+ };
62
+ this.success(flags, 'Voice session started');
63
+ this.printDetail(flags, data, row, VOICE_SESSION_COLUMNS, [
64
+ ['Session', session.sessionId],
65
+ ['Conversation', session.conversationId],
66
+ ['User', session.userId],
67
+ ['Room', session.roomName],
68
+ ['Max duration', `${session.maxDurationSeconds}s`],
69
+ [
70
+ 'Token',
71
+ `${session.participantToken.slice(0, 16)}… (${session.participantToken.length} chars)`
72
+ ]
73
+ ]);
74
+ if (this.mode(flags) === 'pretty') {
75
+ this.note(flags, '→ rerun with --json to get the full participant token for the Voice SDK');
76
+ }
77
+ }
78
+ }