@gravity-rail/cli 4.0.0 → 6.1.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,128 @@
1
+ // src/lib/concierge-api.ts
2
+ function baseUrl(ctx) {
3
+ return `${ctx.envConfig.apiUrl}/api/v2/concierge`;
4
+ }
5
+ function authHeaders(ctx) {
6
+ return {
7
+ Authorization: `Bearer ${ctx.accessToken}`,
8
+ "Content-Type": "application/json"
9
+ };
10
+ }
11
+ function toCamelChat(raw) {
12
+ return {
13
+ id: raw.id,
14
+ uuid: raw.uuid,
15
+ chatType: raw.chatType,
16
+ title: raw.title,
17
+ threadId: raw.threadId,
18
+ createdAt: raw.createdAt,
19
+ updatedAt: raw.updatedAt
20
+ };
21
+ }
22
+ function toCamelMessage(raw) {
23
+ return {
24
+ id: raw.id,
25
+ role: raw.role,
26
+ content: raw.content ?? "",
27
+ createdAt: raw.createdAt ?? null,
28
+ // Protocol-exempt snake_case on wire (see ConciergeMessageResponse)
29
+ toolCalls: raw.tool_calls ?? null,
30
+ toolCallId: raw.tool_call_id ?? null
31
+ };
32
+ }
33
+ async function listConciergeChats(ctx) {
34
+ const res = await fetch(`${baseUrl(ctx)}/chats`, { headers: authHeaders(ctx) });
35
+ if (!res.ok) throw new Error(`Failed to list concierge chats: ${res.status}`);
36
+ const data = await res.json();
37
+ return data.map(toCamelChat);
38
+ }
39
+ async function createConciergeChat(ctx, title) {
40
+ const res = await fetch(`${baseUrl(ctx)}/chats`, {
41
+ method: "POST",
42
+ headers: authHeaders(ctx),
43
+ body: JSON.stringify({ title: title ?? null })
44
+ });
45
+ if (!res.ok) throw new Error(`Failed to create concierge chat: ${res.status}`);
46
+ return toCamelChat(await res.json());
47
+ }
48
+ async function getConciergeChat(ctx, chatId) {
49
+ const res = await fetch(`${baseUrl(ctx)}/chats/${chatId}`, { headers: authHeaders(ctx) });
50
+ if (!res.ok) throw new Error(`Failed to get concierge chat ${chatId}: ${res.status}`);
51
+ return toCamelChat(await res.json());
52
+ }
53
+ async function originateConciergeCall(ctx, kind = "concierge_setup", outboundMessage, clientSurface) {
54
+ const body = { kind };
55
+ if (outboundMessage) body.outbound_message = outboundMessage;
56
+ if (clientSurface) body.client_surface = clientSurface;
57
+ const res = await fetch(`${baseUrl(ctx)}/calls`, {
58
+ method: "POST",
59
+ headers: authHeaders(ctx),
60
+ body: JSON.stringify(body)
61
+ });
62
+ if (res.status === 412) {
63
+ throw new Error("Your account phone is not verified. Run `gr account verify-phone` first.");
64
+ }
65
+ if (!res.ok) {
66
+ const detail = await res.text();
67
+ throw new Error(`Failed to start concierge call: ${res.status} ${detail}`);
68
+ }
69
+ return await res.json();
70
+ }
71
+ async function originateConciergeSms(ctx, kind = "concierge_setup") {
72
+ const res = await fetch(`${baseUrl(ctx)}/sms`, {
73
+ method: "POST",
74
+ headers: authHeaders(ctx),
75
+ body: JSON.stringify({ kind })
76
+ });
77
+ if (res.status === 412) {
78
+ throw new Error("Your account phone is not verified. Run `gr account verify-phone` first.");
79
+ }
80
+ if (!res.ok) {
81
+ const detail = await res.text();
82
+ throw new Error(`Failed to start concierge SMS: ${res.status} ${detail}`);
83
+ }
84
+ return await res.json();
85
+ }
86
+ async function startAccountPhoneVerify(ctx, phone) {
87
+ const res = await fetch(`${ctx.envConfig.apiUrl}/api/v2/account/phone/verify/start`, {
88
+ method: "POST",
89
+ headers: authHeaders(ctx),
90
+ body: JSON.stringify({ phone })
91
+ });
92
+ if (!res.ok) {
93
+ const detail = await res.text();
94
+ throw new Error(`Failed to send verification code: ${res.status} ${detail}`);
95
+ }
96
+ }
97
+ async function confirmAccountPhoneVerify(ctx, code) {
98
+ const res = await fetch(`${ctx.envConfig.apiUrl}/api/v2/account/phone/verify/confirm`, {
99
+ method: "POST",
100
+ headers: authHeaders(ctx),
101
+ body: JSON.stringify({ code })
102
+ });
103
+ if (!res.ok) {
104
+ const detail = await res.text();
105
+ throw new Error(`Failed to confirm verification code: ${res.status} ${detail}`);
106
+ }
107
+ }
108
+ async function getConciergeChatMessages(ctx, chatId) {
109
+ const res = await fetch(`${baseUrl(ctx)}/chats/${chatId}/messages`, {
110
+ headers: authHeaders(ctx)
111
+ });
112
+ if (!res.ok)
113
+ throw new Error(`Failed to get concierge messages for chat ${chatId}: ${res.status}`);
114
+ const data = await res.json();
115
+ return data.map(toCamelMessage);
116
+ }
117
+
118
+ export {
119
+ listConciergeChats,
120
+ createConciergeChat,
121
+ getConciergeChat,
122
+ originateConciergeCall,
123
+ originateConciergeSms,
124
+ startAccountPhoneVerify,
125
+ confirmAccountPhoneVerify,
126
+ getConciergeChatMessages
127
+ };
128
+ //# sourceMappingURL=chunk-LQLGLI4Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/concierge-api.ts"],"sourcesContent":["/**\n * Concierge API client — direct HTTP calls to the global concierge endpoints.\n *\n * The concierge is account-level (no workspace), so these bypass the ApiClient\n * which is workspace-oriented.\n */\n\nimport type { AuthenticatedContext } from './context';\n\nexport interface ConciergeChat {\n id: number;\n uuid: string;\n chatType: string;\n title: string | null;\n threadId: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ConciergeMessage {\n id: string;\n role: string;\n content: string;\n createdAt: string | null;\n toolCalls: any[] | null;\n toolCallId: string | null;\n}\n\nfunction baseUrl(ctx: AuthenticatedContext): string {\n return `${ctx.envConfig.apiUrl}/api/v2/concierge`;\n}\n\nfunction authHeaders(ctx: AuthenticatedContext): Record<string, string> {\n return {\n Authorization: `Bearer ${ctx.accessToken}`,\n 'Content-Type': 'application/json',\n };\n}\n\n/**\n * Map GlobalChatResponse wire → local shape.\n *\n * App fields are camelCase only (we own both ends — no snake dual-read).\n * `tool_calls` / `tool_call_id` on messages stay snake_case intentionally\n * (OpenAI message protocol on ConciergeMessageResponse). (#19305)\n */\nfunction toCamelChat(raw: any): ConciergeChat {\n return {\n id: raw.id,\n uuid: raw.uuid,\n chatType: raw.chatType,\n title: raw.title,\n threadId: raw.threadId,\n createdAt: raw.createdAt,\n updatedAt: raw.updatedAt,\n };\n}\n\nfunction toCamelMessage(raw: any): ConciergeMessage {\n return {\n id: raw.id,\n role: raw.role,\n content: raw.content ?? '',\n createdAt: raw.createdAt ?? null,\n // Protocol-exempt snake_case on wire (see ConciergeMessageResponse)\n toolCalls: raw.tool_calls ?? null,\n toolCallId: raw.tool_call_id ?? null,\n };\n}\n\nexport async function listConciergeChats(ctx: AuthenticatedContext): Promise<ConciergeChat[]> {\n const res = await fetch(`${baseUrl(ctx)}/chats`, { headers: authHeaders(ctx) });\n if (!res.ok) throw new Error(`Failed to list concierge chats: ${res.status}`);\n const data = await res.json();\n return (data as any[]).map(toCamelChat);\n}\n\nexport async function createConciergeChat(\n ctx: AuthenticatedContext,\n title?: string\n): Promise<ConciergeChat> {\n const res = await fetch(`${baseUrl(ctx)}/chats`, {\n method: 'POST',\n headers: authHeaders(ctx),\n body: JSON.stringify({ title: title ?? null }),\n });\n if (!res.ok) throw new Error(`Failed to create concierge chat: ${res.status}`);\n return toCamelChat(await res.json());\n}\n\nexport async function getConciergeChat(\n ctx: AuthenticatedContext,\n chatId: number\n): Promise<ConciergeChat> {\n const res = await fetch(`${baseUrl(ctx)}/chats/${chatId}`, { headers: authHeaders(ctx) });\n if (!res.ok) throw new Error(`Failed to get concierge chat ${chatId}: ${res.status}`);\n return toCamelChat(await res.json());\n}\n\nexport interface ConciergeCallResult {\n callSid: string;\n startedAt: string;\n}\n\nexport interface ConciergeSmsResult {\n messageSid: string;\n conversationId: string;\n}\n\nexport async function originateConciergeCall(\n ctx: AuthenticatedContext,\n kind = 'concierge_setup',\n outboundMessage?: string,\n clientSurface?: string\n): Promise<ConciergeCallResult> {\n const body: Record<string, string | undefined> = { kind };\n if (outboundMessage) body.outbound_message = outboundMessage;\n if (clientSurface) body.client_surface = clientSurface;\n const res = await fetch(`${baseUrl(ctx)}/calls`, {\n method: 'POST',\n headers: authHeaders(ctx),\n body: JSON.stringify(body),\n });\n if (res.status === 412) {\n throw new Error('Your account phone is not verified. Run `gr account verify-phone` first.');\n }\n if (!res.ok) {\n const detail = await res.text();\n throw new Error(`Failed to start concierge call: ${res.status} ${detail}`);\n }\n return (await res.json()) as ConciergeCallResult;\n}\n\nexport async function originateConciergeSms(\n ctx: AuthenticatedContext,\n kind = 'concierge_setup'\n): Promise<ConciergeSmsResult> {\n const res = await fetch(`${baseUrl(ctx)}/sms`, {\n method: 'POST',\n headers: authHeaders(ctx),\n body: JSON.stringify({ kind }),\n });\n if (res.status === 412) {\n throw new Error('Your account phone is not verified. Run `gr account verify-phone` first.');\n }\n if (!res.ok) {\n const detail = await res.text();\n throw new Error(`Failed to start concierge SMS: ${res.status} ${detail}`);\n }\n return (await res.json()) as ConciergeSmsResult;\n}\n\nexport async function startAccountPhoneVerify(\n ctx: AuthenticatedContext,\n phone: string\n): Promise<void> {\n const res = await fetch(`${ctx.envConfig.apiUrl}/api/v2/account/phone/verify/start`, {\n method: 'POST',\n headers: authHeaders(ctx),\n body: JSON.stringify({ phone }),\n });\n if (!res.ok) {\n const detail = await res.text();\n throw new Error(`Failed to send verification code: ${res.status} ${detail}`);\n }\n}\n\nexport async function confirmAccountPhoneVerify(\n ctx: AuthenticatedContext,\n code: string\n): Promise<void> {\n const res = await fetch(`${ctx.envConfig.apiUrl}/api/v2/account/phone/verify/confirm`, {\n method: 'POST',\n headers: authHeaders(ctx),\n body: JSON.stringify({ code }),\n });\n if (!res.ok) {\n const detail = await res.text();\n throw new Error(`Failed to confirm verification code: ${res.status} ${detail}`);\n }\n}\n\nexport async function getConciergeChatMessages(\n ctx: AuthenticatedContext,\n chatId: number\n): Promise<ConciergeMessage[]> {\n const res = await fetch(`${baseUrl(ctx)}/chats/${chatId}/messages`, {\n headers: authHeaders(ctx),\n });\n if (!res.ok)\n throw new Error(`Failed to get concierge messages for chat ${chatId}: ${res.status}`);\n const data = await res.json();\n return (data as any[]).map(toCamelMessage);\n}\n"],"mappings":";AA4BA,SAAS,QAAQ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C,IAAI,MAAM,IAAI,MAAM,EAAE;AAAA,EAC3E;AACA,SAAQ,MAAM,IAAI,KAAK;AAC1B;AAEA,eAAsB,wBACnB,KACA,OACc;AACd,QAAM,MAAM,MAAM,MAAM,GAAG,IAAI,UAAU,MAAM,sCAAsC;AAAA,IAClF,QAAQ;AAAA,IACR,SAAS,YAAY,GAAG;AAAA,IACxB,MAAM,KAAK,UAAU,EAAE,MAAM,CAAC;AAAA,EACjC,CAAC;AACD,MAAI,CAAC,IAAI,IAAI;AACV,UAAM,SAAS,MAAM,IAAI,KAAK;AAC9B,UAAM,IAAI,MAAM,qCAAqC,IAAI,MAAM,IAAI,MAAM,EAAE;AAAA,EAC9E;AACH;AAEA,eAAsB,0BACnB,KACA,MACc;AACd,QAAM,MAAM,MAAM,MAAM,GAAG,IAAI,UAAU,MAAM,wCAAwC;AAAA,IACpF,QAAQ;AAAA,IACR,SAAS,YAAY,GAAG;AAAA,IACxB,MAAM,KAAK,UAAU,EAAE,KAAK,CAAC;AAAA,EAChC,CAAC;AACD,MAAI,CAAC,IAAI,IAAI;AACV,UAAM,SAAS,MAAM,IAAI,KAAK;AAC9B,UAAM,IAAI,MAAM,wCAAwC,IAAI,MAAM,IAAI,MAAM,EAAE;AAAA,EACjF;AACH;AAEA,eAAsB,yBACnB,KACA,QAC4B;AAC5B,QAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,CAAC,UAAU,MAAM,aAAa;AAAA,IACjE,SAAS,YAAY,GAAG;AAAA,EAC3B,CAAC;AACD,MAAI,CAAC,IAAI;AACN,UAAM,IAAI,MAAM,6CAA6C,MAAM,KAAK,IAAI,MAAM,EAAE;AACvF,QAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,SAAQ,KAAe,IAAI,cAAc;AAC5C;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import { C as CLICredentials, E as EnvironmentConfig, a as CredentialsManager } from './cli-client-context-BVZdWMkY.js';
2
2
  import { ConciergeAppContextPayload } from './lib.js';
3
3
  export { c as CALLBACK_PATH, d as CALLBACK_PORT, e as CheckoutClassification, D as DEFAULT_PROFILE, f as ENVIRONMENTS, g as EnvironmentConfigOptions, P as ProfileSummary, R as REDIRECT_URI, W as WorktreeConfigError, h as classifyCheckout, i as getEnvironmentConfig, p as parsePublishedTarget } from './cli-client-context-BVZdWMkY.js';
4
+ import { ProposedMessageSettlementStatus } from '@gravity-rail/sdk';
4
5
 
5
6
  /**
6
7
  * CLI OAuth2 authentication utilities
@@ -209,6 +210,17 @@ declare function clearScreen(): void;
209
210
  * chat responses. See: https://docs.ag-ui.com/concepts/events
210
211
  */
211
212
 
213
+ /** How asking the server to send or discard a drafted message ended. */
214
+ type ProposedMessageSettleResult = {
215
+ kind: 'settled';
216
+ status: ProposedMessageSettlementStatus;
217
+ detail?: string | null;
218
+ } | {
219
+ kind: 'refused';
220
+ status: number;
221
+ } | {
222
+ kind: 'transport';
223
+ };
212
224
  /**
213
225
  * AG-UI event types
214
226
  */
@@ -269,6 +281,14 @@ declare class AGUIClient {
269
281
  connectUrl: string;
270
282
  expiresInMinutes: number;
271
283
  } | null>;
284
+ /**
285
+ * Send or discard a message the Manager proposed as a draft. The three
286
+ * results are different things to tell the operator: `settled` carries how
287
+ * it ended, `refused` is the server saying no (a 409 is a draft settled
288
+ * elsewhere), and `transport` is not knowing — the draft is unchanged as
289
+ * far as this client can tell.
290
+ */
291
+ settleProposedMessage(promptId: string, decision: 'send' | 'discard'): Promise<ProposedMessageSettleResult>;
272
292
  private inferenceStatusUrl;
273
293
  private waitForInferenceInactive;
274
294
  /**
package/dist/cli-utils.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  selectFromList,
31
31
  startCallbackServer,
32
32
  wrapText
33
- } from "./chunk-KDWGBYCM.js";
33
+ } from "./chunk-HTPFRSPP.js";
34
34
  export {
35
35
  AGUIClient,
36
36
  CALLBACK_PATH,
@@ -0,0 +1,13 @@
1
+ import {
2
+ AuthRequiredError,
3
+ CLIError,
4
+ handleError,
5
+ unauthorizedHint
6
+ } from "./chunk-HTPFRSPP.js";
7
+ export {
8
+ AuthRequiredError,
9
+ CLIError,
10
+ handleError,
11
+ unauthorizedHint
12
+ };
13
+ //# sourceMappingURL=errors-CBQHNNRI.js.map