@gravity-rail/cli 0.55.1 → 0.57.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/README.md +8 -4
- package/dist/{account-verify-phone-OXHKM36Z.js → account-verify-phone-Q4FKI4PX.js} +3 -3
- package/dist/{chunk-73INPBWK.js → chunk-CB4K2FBU.js} +47 -3
- package/dist/chunk-CB4K2FBU.js.map +1 -0
- package/dist/{chunk-RAFKHKG2.js → chunk-TY6HKHOV.js} +2 -2
- package/dist/cli-utils.js +1 -1
- package/dist/gr.js +1303 -457
- package/dist/gr.js.map +1 -1
- package/dist/lib.d.ts +32 -3
- package/dist/lib.js +759 -372
- package/dist/lib.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-73INPBWK.js.map +0 -1
- /package/dist/{account-verify-phone-OXHKM36Z.js.map → account-verify-phone-Q4FKI4PX.js.map} +0 -0
- /package/dist/{chunk-RAFKHKG2.js.map → chunk-TY6HKHOV.js.map} +0 -0
package/dist/lib.js
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
startAccountPhoneVerify,
|
|
34
34
|
stderr,
|
|
35
35
|
unwrapItems
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-TY6HKHOV.js";
|
|
37
37
|
import {
|
|
38
38
|
AGUIClient,
|
|
39
39
|
formatTimestamp,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
isRecord,
|
|
43
43
|
performOAuthFlow,
|
|
44
44
|
selectFromList
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-CB4K2FBU.js";
|
|
46
46
|
import {
|
|
47
47
|
AuthRequiredError,
|
|
48
48
|
CLIError,
|
|
@@ -258,7 +258,7 @@ function commandNeedsJsonBody(cmd, parsedArgs) {
|
|
|
258
258
|
}
|
|
259
259
|
return false;
|
|
260
260
|
}
|
|
261
|
-
if (cmd.acceptsJsonInput === true) {
|
|
261
|
+
if (cmd.acceptsJsonInput === true || cmd.pipesJsonInput !== void 0) {
|
|
262
262
|
return true;
|
|
263
263
|
}
|
|
264
264
|
if (parsedArgs.data !== void 0 || parsedArgs.file !== void 0) {
|
|
@@ -279,7 +279,19 @@ function commandNeedsJsonBody(cmd, parsedArgs) {
|
|
|
279
279
|
}
|
|
280
280
|
return false;
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
var PIPED_INPUT_FIRST_BYTE_WAIT_MS = 6e4;
|
|
283
|
+
function commandAwaitsPipedInput(cmd, parsedArgs) {
|
|
284
|
+
if (parsedArgs.data !== void 0 || parsedArgs.file !== void 0) return false;
|
|
285
|
+
const declared = cmd.pipesJsonInput;
|
|
286
|
+
return typeof declared === "function" ? declared(parsedArgs) : declared === true;
|
|
287
|
+
}
|
|
288
|
+
async function readCommandJsonInput(cmd, parsedArgs) {
|
|
289
|
+
if (!commandNeedsJsonBody(cmd, parsedArgs)) return void 0;
|
|
290
|
+
return readJsonInput(parsedArgs, {
|
|
291
|
+
pipedInputWaitMs: commandAwaitsPipedInput(cmd, parsedArgs) ? PIPED_INPUT_FIRST_BYTE_WAIT_MS : 0
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
async function readJsonInput(args, options = {}) {
|
|
283
295
|
const dataStr = args.data;
|
|
284
296
|
const filePath = args.file;
|
|
285
297
|
if (dataStr) {
|
|
@@ -310,15 +322,17 @@ async function readJsonInput(args) {
|
|
|
310
322
|
if (process.stdin.isTTY === true) {
|
|
311
323
|
return void 0;
|
|
312
324
|
}
|
|
313
|
-
return readStdinIfPiped();
|
|
325
|
+
return readStdinIfPiped(options.pipedInputWaitMs ?? 0);
|
|
314
326
|
}
|
|
315
|
-
function readStdinIfPiped() {
|
|
327
|
+
function readStdinIfPiped(firstByteWaitMs) {
|
|
316
328
|
return new Promise((resolve, reject) => {
|
|
317
329
|
let data = "";
|
|
318
330
|
let settled = false;
|
|
331
|
+
let idleTimer;
|
|
319
332
|
const finish2 = (value) => {
|
|
320
333
|
if (settled) return;
|
|
321
334
|
settled = true;
|
|
335
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
322
336
|
resolve(value);
|
|
323
337
|
};
|
|
324
338
|
const flush = () => {
|
|
@@ -347,6 +361,15 @@ function readStdinIfPiped() {
|
|
|
347
361
|
flush();
|
|
348
362
|
return;
|
|
349
363
|
}
|
|
364
|
+
if (firstByteWaitMs > 0) {
|
|
365
|
+
idleTimer = setTimeout(() => {
|
|
366
|
+
if (!data) {
|
|
367
|
+
process.stdin.pause();
|
|
368
|
+
finish2(void 0);
|
|
369
|
+
}
|
|
370
|
+
}, firstByteWaitMs);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
350
373
|
finish2(void 0);
|
|
351
374
|
});
|
|
352
375
|
});
|
|
@@ -1383,9 +1406,9 @@ Optional
|
|
|
1383
1406
|
systemPrompt (string) Base instructions / identity
|
|
1384
1407
|
chatModelConfig (object|null) Chat model overrides (temperature, thinking, \u2026)
|
|
1385
1408
|
realtimeModelId (string|null) Voice/realtime model (see \`gr ai-models realtime\`)
|
|
1386
|
-
e.g. "xai:realtime:voice-agent-
|
|
1387
|
-
|
|
1388
|
-
|
|
1409
|
+
e.g. "xai:realtime:voice-agent-3" (Grok Voice 3, the
|
|
1410
|
+
default; not yet cleared for strict-routing workflows).
|
|
1411
|
+
"xai:realtime:voice-agent-2" is deprecated.
|
|
1389
1412
|
Native models auto-fill tts=native + default voice when
|
|
1390
1413
|
realtimeModelConfig is omitted.
|
|
1391
1414
|
realtimeModelConfig (object|null) Realtime config. Native example:
|
|
@@ -1403,11 +1426,7 @@ Attach an agent\u2019s models/identity to a workflow (draft), then publish:
|
|
|
1403
1426
|
gr workflows update --id <wf> -d '{"copyFromAgentId": <agentId>}'
|
|
1404
1427
|
gr workflows publish --workflow-id <wf>
|
|
1405
1428
|
|
|
1406
|
-
One-shot workflow voice WITHOUT creating an agent (preferred for "use Grok Voice
|
|
1407
|
-
gr workflows update --id <wf> -d '{"realtimeModelId":"xai:realtime:voice-agent-2"}'
|
|
1408
|
-
gr workflows publish --workflow-id <wf>
|
|
1409
|
-
|
|
1410
|
-
Opt a workflow into Grok Voice 3.0 (same xAI voices as 2.0; not the default):
|
|
1429
|
+
One-shot workflow voice WITHOUT creating an agent (preferred for "use Grok Voice 3"):
|
|
1411
1430
|
gr workflows update --id <wf> -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}'
|
|
1412
1431
|
gr workflows publish --workflow-id <wf>
|
|
1413
1432
|
|
|
@@ -1435,11 +1454,10 @@ ${AGENT_FIELD_REFERENCE}`,
|
|
|
1435
1454
|
updateHelp: `Update an agent. All fields optional.
|
|
1436
1455
|
${AGENT_FIELD_REFERENCE}`,
|
|
1437
1456
|
createExamples: [
|
|
1438
|
-
`gr agents create -d '{"name":"Support","chatModelId":"openai:chat:gpt-6-luna","realtimeModelId":"xai:realtime:voice-agent-
|
|
1457
|
+
`gr agents create -d '{"name":"Support","chatModelId":"openai:chat:gpt-6-luna","realtimeModelId":"xai:realtime:voice-agent-3"}'`,
|
|
1439
1458
|
"gr agents create --file agent.json"
|
|
1440
1459
|
],
|
|
1441
1460
|
updateExamples: [
|
|
1442
|
-
`gr agents update --id 42 -d '{"realtimeModelId":"xai:realtime:voice-agent-2"}'`,
|
|
1443
1461
|
`gr agents update --id 42 -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}'`,
|
|
1444
1462
|
"gr agents update --id 42 --file agent.json"
|
|
1445
1463
|
]
|
|
@@ -3164,23 +3182,24 @@ Assistant / models (live on the DRAFT revision \u2014 publish to go live)
|
|
|
3164
3182
|
chatModelId (string) Text chat model (see \`gr ai-models chat\`)
|
|
3165
3183
|
chatModelConfig (object|null) Chat model overrides
|
|
3166
3184
|
realtimeModelId (string|null) Voice/realtime model (see \`gr ai-models realtime\`)
|
|
3167
|
-
create: omit \u2192 xai:realtime:voice-agent-
|
|
3168
|
-
voice xai:voice:cosmo; null = voice off
|
|
3185
|
+
create: omit \u2192 xai:realtime:voice-agent-3 with
|
|
3186
|
+
voice xai:voice:cosmo; null = voice off.
|
|
3187
|
+
routingMode "strict": omit \u2192 no voice (use
|
|
3188
|
+
custom:realtime:composable)
|
|
3169
3189
|
update: null = voice off
|
|
3170
3190
|
One-shot switch (keeps the stored voice and
|
|
3171
3191
|
call settings; resets only a voice the new
|
|
3172
3192
|
model cannot use):
|
|
3173
|
-
{"realtimeModelId":"xai:realtime:voice-agent-2"}
|
|
3174
|
-
Opt in to Grok Voice 3.0 (not the default; not yet
|
|
3175
|
-
cleared for routingMode "strict"; same xAI voices):
|
|
3176
3193
|
{"realtimeModelId":"xai:realtime:voice-agent-3"}
|
|
3194
|
+
Grok Voice 3 is not yet cleared for routingMode
|
|
3195
|
+
"strict". voice-agent-2 is deprecated.
|
|
3177
3196
|
On create, a native model id with no stored or
|
|
3178
3197
|
copied config gets tts=native + that
|
|
3179
3198
|
provider's fallback voice. A composable id
|
|
3180
3199
|
still needs its own config. On update,
|
|
3181
3200
|
omitting the config keeps the stored one.
|
|
3182
3201
|
Explicit config replaces it:
|
|
3183
|
-
{"realtimeModelId":"xai:realtime:voice-agent-
|
|
3202
|
+
{"realtimeModelId":"xai:realtime:voice-agent-3",
|
|
3184
3203
|
"realtimeModelConfig":{"ttsModel":"native",
|
|
3185
3204
|
"voiceModel":"xai:voice:ara"}}
|
|
3186
3205
|
realtimeModelConfig (object|null) Realtime config. Omit on update to keep the
|
|
@@ -8360,7 +8379,7 @@ var bundlesDomain = {
|
|
|
8360
8379
|
},
|
|
8361
8380
|
{
|
|
8362
8381
|
path: ["bundles", "draft", "set"],
|
|
8363
|
-
description: 'Replace draft items from {"items": [...]};
|
|
8382
|
+
description: 'Replace draft items from {"items": [...]}. Journey items require {"key", "kind":"journey", "journeyUuid"}; the server captures the source Journey. An optional "links": [{"label", "url"}] replaces the draft links. Use --expected-generation from draft get to protect edits.',
|
|
8364
8383
|
requiresWorkspace: true,
|
|
8365
8384
|
mutates: true,
|
|
8366
8385
|
args: [BUNDLE_ARG, GENERATION_ARG],
|
|
@@ -9735,9 +9754,9 @@ var REALTIME_AUDIO_USD_PER_MIN = {
|
|
|
9735
9754
|
"xai:realtime:voice-agent": 0.05,
|
|
9736
9755
|
// Grok Voice Think Fast 1
|
|
9737
9756
|
"xai:realtime:voice-agent-2": 0.08,
|
|
9738
|
-
// Grok Voice
|
|
9757
|
+
// Grok Voice 2 (pinned grok-voice-2.0)
|
|
9739
9758
|
"xai:realtime:voice-agent-3": 0.08
|
|
9740
|
-
// Grok Voice 3
|
|
9759
|
+
// Grok Voice 3 — same audio rate as 2.0
|
|
9741
9760
|
};
|
|
9742
9761
|
var DEFAULT_REALTIME_AUDIO_USD_PER_MIN = 0.08;
|
|
9743
9762
|
var EST_AUDIO_MIN_PER_RUN = 3;
|
|
@@ -9816,6 +9835,10 @@ function runToBatchRow(job, workflowId, run, error, batchLabel, pinnedRevisionId
|
|
|
9816
9835
|
...job.realtime ? { realtime_model_id: job.modelId } : {},
|
|
9817
9836
|
...batchLabel ? { batch_label: batchLabel } : {},
|
|
9818
9837
|
run_id: run?.id,
|
|
9838
|
+
lane: run?.lane ?? null,
|
|
9839
|
+
outcome: run?.outcome ?? null,
|
|
9840
|
+
assistant_chat_model_id: run?.assistantChatModelId ?? null,
|
|
9841
|
+
assistant_realtime_model_id: run?.assistantRealtimeModelId ?? null,
|
|
9819
9842
|
error,
|
|
9820
9843
|
failure_reason: run?.failureReason ?? null,
|
|
9821
9844
|
passed: run?.passed ?? null,
|
|
@@ -10110,7 +10133,15 @@ var SCENARIO_COLUMNS = [
|
|
|
10110
10133
|
COL.id(),
|
|
10111
10134
|
COL.name(),
|
|
10112
10135
|
{ header: "PERSONA", getValue: (item) => item.personaName ?? "" },
|
|
10113
|
-
{ header: "CHANNEL", getValue: (item) => item.channel ?? "" }
|
|
10136
|
+
{ header: "CHANNEL", getValue: (item) => item.channel ?? "" },
|
|
10137
|
+
{
|
|
10138
|
+
header: "SEED",
|
|
10139
|
+
getValue: (item) => {
|
|
10140
|
+
const turns = Array.isArray(item.seedTurns) ? item.seedTurns.length : 0;
|
|
10141
|
+
if (turns === 0) return "";
|
|
10142
|
+
return item.singleTurn ? `${turns} turns, single-turn` : `${turns} turns`;
|
|
10143
|
+
}
|
|
10144
|
+
}
|
|
10114
10145
|
];
|
|
10115
10146
|
var RUN_COLUMNS = [
|
|
10116
10147
|
COL.id(),
|
|
@@ -10202,7 +10233,7 @@ var qualificationsDomain = {
|
|
|
10202
10233
|
},
|
|
10203
10234
|
{
|
|
10204
10235
|
path: ["qualifications", "scenarios", "create"],
|
|
10205
|
-
description:
|
|
10236
|
+
description: 'Create a scenario on a qualification (pass JSON via --data). Seed history: "seedTurns": [{"speaker": "member"|"agent", "content": "..."}]; "singleTurn": true grades only the Agent reply to the last seeded member turn',
|
|
10206
10237
|
mutates: true,
|
|
10207
10238
|
requiresWorkspace: true,
|
|
10208
10239
|
args: [{ name: "qualification-id", description: "Qualification ID", required: true }],
|
|
@@ -10217,7 +10248,7 @@ var qualificationsDomain = {
|
|
|
10217
10248
|
},
|
|
10218
10249
|
{
|
|
10219
10250
|
path: ["qualifications", "scenarios", "update"],
|
|
10220
|
-
description:
|
|
10251
|
+
description: 'Update a scenario (pass JSON via --data). "seedTurns": [] clears the seed history; "singleTurn" needs seed turns that end on a member turn',
|
|
10221
10252
|
mutates: true,
|
|
10222
10253
|
requiresWorkspace: true,
|
|
10223
10254
|
args: [{ name: "id", description: "Scenario ID", required: true }],
|
|
@@ -12911,7 +12942,7 @@ var COLUMNS15 = [
|
|
|
12911
12942
|
];
|
|
12912
12943
|
var aiModelsDomain = {
|
|
12913
12944
|
name: "ai-models",
|
|
12914
|
-
description: `List available AI models (chat, realtime/voice stacks, speaker voices). Use realtime ids as workflow/agent realtimeModelId; voice ids go in realtimeModelConfig.voiceModel. One-shot workflow voice: gr workflows update -d '{"realtimeModelId":"xai:realtime:voice-agent-
|
|
12945
|
+
description: `List available AI models (chat, realtime/voice stacks, speaker voices). Use realtime ids as workflow/agent realtimeModelId; voice ids go in realtimeModelConfig.voiceModel. One-shot workflow voice: gr workflows update -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}' then publish.`,
|
|
12915
12946
|
commands: [
|
|
12916
12947
|
{
|
|
12917
12948
|
path: ["ai-models", "list"],
|
|
@@ -12933,7 +12964,7 @@ var aiModelsDomain = {
|
|
|
12933
12964
|
},
|
|
12934
12965
|
{
|
|
12935
12966
|
path: ["ai-models", "realtime"],
|
|
12936
|
-
description: "List realtime/voice stacks (use as realtimeModelId). e.g. xai:realtime:voice-agent-
|
|
12967
|
+
description: "List realtime/voice stacks (use as realtimeModelId). e.g. xai:realtime:voice-agent-3 = Grok Voice 3 (default). Deprecated models (xai:realtime:voice-agent-2) are not listed.",
|
|
12937
12968
|
requiresWorkspace: false,
|
|
12938
12969
|
handler: async ({ ctx }) => {
|
|
12939
12970
|
const result2 = await requireAuth(ctx).apiClient.getRealtimeModels();
|
|
@@ -14219,7 +14250,9 @@ var memberMemoriesDomain = {
|
|
|
14219
14250
|
{ name: "key", description: "Memory key", required: true },
|
|
14220
14251
|
{
|
|
14221
14252
|
name: "type",
|
|
14222
|
-
|
|
14253
|
+
// The API refuses preferences and semantic deletes (a Member cannot
|
|
14254
|
+
// be shown to own those AgentCore records), so they are not offered.
|
|
14255
|
+
description: "Memory type (basic, summaries, episodic)"
|
|
14223
14256
|
}
|
|
14224
14257
|
],
|
|
14225
14258
|
handler: async ({ ctx, workspace, args }) => {
|
|
@@ -19588,13 +19621,6 @@ var pronunciationsDomain = {
|
|
|
19588
19621
|
|
|
19589
19622
|
// src/domains/recordings.ts
|
|
19590
19623
|
import { writeFileSync as writeFileSync3 } from "fs";
|
|
19591
|
-
var CHUNK_COLUMNS = [
|
|
19592
|
-
{ header: "IDX", getValue: (item) => String(item.chunkIndex ?? "") },
|
|
19593
|
-
{ header: "ROLE", getValue: (item) => item.role ?? "" },
|
|
19594
|
-
{ header: "START", getValue: (item) => item.startTime ?? "" },
|
|
19595
|
-
{ header: "FORMAT", getValue: (item) => item.audioFormat ?? "" },
|
|
19596
|
-
{ header: "MIME", getValue: (item) => item.mimeType ?? "" }
|
|
19597
|
-
];
|
|
19598
19624
|
var URL_COLUMNS = [
|
|
19599
19625
|
{ header: "DOWNLOAD URL", getValue: (item) => item.downloadUrl ?? "" },
|
|
19600
19626
|
{ header: "EXPIRES IN", getValue: (item) => String(item.expiresIn ?? "") },
|
|
@@ -19611,24 +19637,6 @@ var recordingsDomain = {
|
|
|
19611
19637
|
name: "recordings",
|
|
19612
19638
|
description: "Download recorded voice-call audio (per chat)",
|
|
19613
19639
|
commands: [
|
|
19614
|
-
{
|
|
19615
|
-
path: ["recordings", "list"],
|
|
19616
|
-
description: "List recorded audio chunks for a chat (metadata only)",
|
|
19617
|
-
requiresWorkspace: true,
|
|
19618
|
-
args: [
|
|
19619
|
-
{ name: "chat-id", aliases: ["id"], description: "Chat ID", required: true },
|
|
19620
|
-
{ name: "role", description: "Filter by role: 'assistant' or 'member'" }
|
|
19621
|
-
],
|
|
19622
|
-
handler: async ({ ctx, workspace, args }) => {
|
|
19623
|
-
const role = typeof args.role === "string" ? args.role : void 0;
|
|
19624
|
-
const result2 = await requireAuth(ctx).apiClient.listChatRecordings(
|
|
19625
|
-
workspace,
|
|
19626
|
-
requireNumber(args, "chat-id"),
|
|
19627
|
-
role ? { role } : {}
|
|
19628
|
-
);
|
|
19629
|
-
outputData(result2.items, ctx, CHUNK_COLUMNS);
|
|
19630
|
-
}
|
|
19631
|
-
},
|
|
19632
19640
|
{
|
|
19633
19641
|
path: ["recordings", "download-url"],
|
|
19634
19642
|
description: "Get a single short-lived presigned URL for the whole-call recording WAV",
|
|
@@ -20305,6 +20313,92 @@ async function streamSyncRun(response, verbose) {
|
|
|
20305
20313
|
console.log(JSON.stringify(lastRun, null, 2));
|
|
20306
20314
|
}
|
|
20307
20315
|
}
|
|
20316
|
+
var SYNC_RUN_OPTION_ARGS = [
|
|
20317
|
+
{ name: "dry-run", description: "Test sync without making changes", isFlag: true },
|
|
20318
|
+
{
|
|
20319
|
+
name: "full-resync",
|
|
20320
|
+
description: "Clear checkpoints and re-sync all records",
|
|
20321
|
+
isFlag: true
|
|
20322
|
+
},
|
|
20323
|
+
{ name: "quiet", description: "Only output final result JSON", isFlag: true },
|
|
20324
|
+
{ name: "entity-type", description: "Scope to entity type: member or record" },
|
|
20325
|
+
{
|
|
20326
|
+
name: "board-id",
|
|
20327
|
+
description: "Scope to a single board mapping (requires --entity-type)"
|
|
20328
|
+
},
|
|
20329
|
+
{
|
|
20330
|
+
name: "record-limit",
|
|
20331
|
+
description: "Cap the run to a preview sample (1..200). Requires --dry-run and --entity-type."
|
|
20332
|
+
}
|
|
20333
|
+
];
|
|
20334
|
+
var VALID_ENTITY_TYPES = ["member", "record"];
|
|
20335
|
+
function parseSyncRunOptions(args) {
|
|
20336
|
+
const dryRun = args["dry-run"] === true;
|
|
20337
|
+
const fullResync = args["full-resync"] === true;
|
|
20338
|
+
const quiet = args["quiet"] === true;
|
|
20339
|
+
const rawEntityType = args["entity-type"];
|
|
20340
|
+
let entityType;
|
|
20341
|
+
if (rawEntityType) {
|
|
20342
|
+
if (!VALID_ENTITY_TYPES.includes(rawEntityType)) {
|
|
20343
|
+
throw new CLIError(
|
|
20344
|
+
`Invalid --entity-type "${rawEntityType}". Allowed values: ${VALID_ENTITY_TYPES.join(", ")}`
|
|
20345
|
+
);
|
|
20346
|
+
}
|
|
20347
|
+
entityType = rawEntityType;
|
|
20348
|
+
}
|
|
20349
|
+
const boardId = args["board-id"];
|
|
20350
|
+
const rawRecordLimit = args["record-limit"];
|
|
20351
|
+
let recordLimit;
|
|
20352
|
+
if (rawRecordLimit !== void 0 && rawRecordLimit !== "") {
|
|
20353
|
+
const parsed = Number(rawRecordLimit);
|
|
20354
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 200) {
|
|
20355
|
+
throw new CLIError(
|
|
20356
|
+
`Invalid --record-limit "${rawRecordLimit}". Must be an integer between 1 and 200.`
|
|
20357
|
+
);
|
|
20358
|
+
}
|
|
20359
|
+
if (!dryRun) {
|
|
20360
|
+
throw new CLIError("--record-limit requires --dry-run: capped runs are preview-only.");
|
|
20361
|
+
}
|
|
20362
|
+
if (entityType === void 0) {
|
|
20363
|
+
throw new CLIError(
|
|
20364
|
+
"--record-limit requires --entity-type: capped previews must target a single entity type."
|
|
20365
|
+
);
|
|
20366
|
+
}
|
|
20367
|
+
recordLimit = parsed;
|
|
20368
|
+
}
|
|
20369
|
+
if (fullResync && (dryRun || recordLimit !== void 0)) {
|
|
20370
|
+
throw new CLIError(
|
|
20371
|
+
"--full-resync is incompatible with --dry-run / --record-limit: checkpoint reset must happen on a non-preview run."
|
|
20372
|
+
);
|
|
20373
|
+
}
|
|
20374
|
+
return { dryRun, fullResync, quiet, entityType, boardId, recordLimit };
|
|
20375
|
+
}
|
|
20376
|
+
async function runSyncAndStream(ctx, workspace, connectionId, options) {
|
|
20377
|
+
const { dryRun, fullResync, quiet, entityType, boardId, recordLimit } = options;
|
|
20378
|
+
if (!quiet) {
|
|
20379
|
+
const flags = [
|
|
20380
|
+
dryRun && "(dry run)",
|
|
20381
|
+
fullResync && "(full re-sync)",
|
|
20382
|
+
entityType && `(${entityType} only)`,
|
|
20383
|
+
boardId && `(board ${boardId})`,
|
|
20384
|
+
recordLimit !== void 0 && `(limit ${recordLimit})`
|
|
20385
|
+
].filter(Boolean).join(" ");
|
|
20386
|
+
console.error(`Starting sync for connection ${connectionId}${flags ? ` ${flags}` : ""}...`);
|
|
20387
|
+
}
|
|
20388
|
+
const response = await requireAuth(ctx).apiClient.startSyncRun(workspace, connectionId, {
|
|
20389
|
+
dryRun,
|
|
20390
|
+
resetCheckpoints: fullResync,
|
|
20391
|
+
entityType,
|
|
20392
|
+
boardId,
|
|
20393
|
+
recordLimit
|
|
20394
|
+
});
|
|
20395
|
+
if (!response.ok) {
|
|
20396
|
+
const text = await response.text();
|
|
20397
|
+
console.error(`Sync failed: ${response.status} ${text}`);
|
|
20398
|
+
process.exit(1);
|
|
20399
|
+
}
|
|
20400
|
+
await streamSyncRun(response, !quiet);
|
|
20401
|
+
}
|
|
20308
20402
|
var syncDomain = {
|
|
20309
20403
|
name: "sync",
|
|
20310
20404
|
description: "Run and monitor connection syncs",
|
|
@@ -20314,22 +20408,7 @@ var syncDomain = {
|
|
|
20314
20408
|
description: "Start a sync run and stream progress (SSE)",
|
|
20315
20409
|
args: [
|
|
20316
20410
|
{ name: "connection-id", description: "Connection ID", required: true },
|
|
20317
|
-
|
|
20318
|
-
{
|
|
20319
|
-
name: "full-resync",
|
|
20320
|
-
description: "Clear checkpoints and re-sync all records",
|
|
20321
|
-
isFlag: true
|
|
20322
|
-
},
|
|
20323
|
-
{ name: "quiet", description: "Only output final result JSON", isFlag: true },
|
|
20324
|
-
{ name: "entity-type", description: "Scope to entity type: member or record" },
|
|
20325
|
-
{
|
|
20326
|
-
name: "board-id",
|
|
20327
|
-
description: "Scope to a single board mapping (requires --entity-type)"
|
|
20328
|
-
},
|
|
20329
|
-
{
|
|
20330
|
-
name: "record-limit",
|
|
20331
|
-
description: "Cap the run to a preview sample (1..200). Requires --dry-run and --entity-type."
|
|
20332
|
-
}
|
|
20411
|
+
...SYNC_RUN_OPTION_ARGS
|
|
20333
20412
|
],
|
|
20334
20413
|
examples: [
|
|
20335
20414
|
"sync run --connection-id 6",
|
|
@@ -20343,76 +20422,7 @@ var syncDomain = {
|
|
|
20343
20422
|
mutates: true,
|
|
20344
20423
|
handler: async ({ ctx, args, workspace }) => {
|
|
20345
20424
|
const connectionId = requireNumber(args, "connection-id");
|
|
20346
|
-
|
|
20347
|
-
const fullResync = args["full-resync"] === true;
|
|
20348
|
-
const quiet = args["quiet"] === true;
|
|
20349
|
-
const VALID_ENTITY_TYPES = ["member", "record"];
|
|
20350
|
-
const rawEntityType = args["entity-type"];
|
|
20351
|
-
let entityType;
|
|
20352
|
-
if (rawEntityType) {
|
|
20353
|
-
if (!VALID_ENTITY_TYPES.includes(rawEntityType)) {
|
|
20354
|
-
throw new CLIError(
|
|
20355
|
-
`Invalid --entity-type "${rawEntityType}". Allowed values: ${VALID_ENTITY_TYPES.join(", ")}`
|
|
20356
|
-
);
|
|
20357
|
-
}
|
|
20358
|
-
entityType = rawEntityType;
|
|
20359
|
-
}
|
|
20360
|
-
const boardId = args["board-id"];
|
|
20361
|
-
const rawRecordLimit = args["record-limit"];
|
|
20362
|
-
let recordLimit;
|
|
20363
|
-
if (rawRecordLimit !== void 0 && rawRecordLimit !== "") {
|
|
20364
|
-
const parsed = Number(rawRecordLimit);
|
|
20365
|
-
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 200) {
|
|
20366
|
-
throw new CLIError(
|
|
20367
|
-
`Invalid --record-limit "${rawRecordLimit}". Must be an integer between 1 and 200.`
|
|
20368
|
-
);
|
|
20369
|
-
}
|
|
20370
|
-
if (!dryRun) {
|
|
20371
|
-
throw new CLIError(
|
|
20372
|
-
"--record-limit requires --dry-run: capped runs are preview-only."
|
|
20373
|
-
);
|
|
20374
|
-
}
|
|
20375
|
-
if (entityType === void 0) {
|
|
20376
|
-
throw new CLIError(
|
|
20377
|
-
"--record-limit requires --entity-type: capped previews must target a single entity type."
|
|
20378
|
-
);
|
|
20379
|
-
}
|
|
20380
|
-
recordLimit = parsed;
|
|
20381
|
-
}
|
|
20382
|
-
if (fullResync && (dryRun || recordLimit !== void 0)) {
|
|
20383
|
-
throw new CLIError(
|
|
20384
|
-
"--full-resync is incompatible with --dry-run / --record-limit: checkpoint reset must happen on a non-preview run."
|
|
20385
|
-
);
|
|
20386
|
-
}
|
|
20387
|
-
if (!quiet) {
|
|
20388
|
-
const flags = [
|
|
20389
|
-
dryRun && "(dry run)",
|
|
20390
|
-
fullResync && "(full re-sync)",
|
|
20391
|
-
entityType && `(${entityType} only)`,
|
|
20392
|
-
boardId && `(board ${boardId})`,
|
|
20393
|
-
recordLimit !== void 0 && `(limit ${recordLimit})`
|
|
20394
|
-
].filter(Boolean).join(" ");
|
|
20395
|
-
console.error(
|
|
20396
|
-
`Starting sync for connection ${connectionId}${flags ? ` ${flags}` : ""}...`
|
|
20397
|
-
);
|
|
20398
|
-
}
|
|
20399
|
-
const response = await requireAuth(ctx).apiClient.startSyncRun(
|
|
20400
|
-
workspace,
|
|
20401
|
-
connectionId,
|
|
20402
|
-
{
|
|
20403
|
-
dryRun,
|
|
20404
|
-
resetCheckpoints: fullResync,
|
|
20405
|
-
entityType,
|
|
20406
|
-
boardId,
|
|
20407
|
-
recordLimit
|
|
20408
|
-
}
|
|
20409
|
-
);
|
|
20410
|
-
if (!response.ok) {
|
|
20411
|
-
const text = await response.text();
|
|
20412
|
-
console.error(`Sync failed: ${response.status} ${text}`);
|
|
20413
|
-
process.exit(1);
|
|
20414
|
-
}
|
|
20415
|
-
await streamSyncRun(response, !quiet);
|
|
20425
|
+
await runSyncAndStream(ctx, workspace, connectionId, parseSyncRunOptions(args));
|
|
20416
20426
|
}
|
|
20417
20427
|
},
|
|
20418
20428
|
{
|
|
@@ -21172,71 +21182,6 @@ var ENCOUNTER_RUN_COLUMNS = [
|
|
|
21172
21182
|
getValue: (item) => summarizeReasons(item.attribution?.collections, "errorReasonCounts")
|
|
21173
21183
|
}
|
|
21174
21184
|
];
|
|
21175
|
-
var ONBOARDING_START_COLUMNS = [
|
|
21176
|
-
{ header: "MODE", getValue: (item) => item.mode ?? "" },
|
|
21177
|
-
{ header: "WORKFLOW ID", getValue: (item) => item.workflowId ?? "" },
|
|
21178
|
-
{ header: "RUN ID", getValue: (item) => item.runId ?? "" }
|
|
21179
|
-
];
|
|
21180
|
-
var ONBOARDING_PAIR_COLUMNS = [
|
|
21181
|
-
{ header: "DEPARTMENT", getValue: (item) => String(item.departmentId ?? "") },
|
|
21182
|
-
{ header: "PATIENT STATUS", getValue: (item) => item.patientStatus ?? "" },
|
|
21183
|
-
{ header: "STATUS", getValue: (item) => item.status ?? "" },
|
|
21184
|
-
{ header: "STOP REASON", getValue: (item) => item.stopReason ?? "" },
|
|
21185
|
-
{ header: "GEN", getValue: (item) => String(item.generation ?? "") },
|
|
21186
|
-
{ header: "NEXT OFFSET", getValue: (item) => String(item.nextOffset ?? "") },
|
|
21187
|
-
{ header: "PAGES (RUN)", getValue: (item) => String(item.pagesDone ?? 0) },
|
|
21188
|
-
{ header: "~FETCHED", getValue: (item) => String(item.totals?.fetched ?? 0) },
|
|
21189
|
-
{ header: "~APPLIED", getValue: (item) => String(item.totals?.applied ?? 0) },
|
|
21190
|
-
{ header: "~SKIPPED", getValue: (item) => String(item.totals?.skipped ?? 0) },
|
|
21191
|
-
{ header: "~FAILED", getValue: (item) => String(item.totals?.failed ?? 0) },
|
|
21192
|
-
{ header: "RUN ID", getValue: (item) => item.runId ?? "" }
|
|
21193
|
-
];
|
|
21194
|
-
var RESUMABLE_PAIR_STATUSES = /* @__PURE__ */ new Set([
|
|
21195
|
-
"failed",
|
|
21196
|
-
"aborted",
|
|
21197
|
-
"truncated",
|
|
21198
|
-
"pending",
|
|
21199
|
-
"running",
|
|
21200
|
-
"waiting"
|
|
21201
|
-
]);
|
|
21202
|
-
function onboardingStatusLines(status, connectionId) {
|
|
21203
|
-
const lines = [];
|
|
21204
|
-
const execution = status.execution;
|
|
21205
|
-
if (execution) {
|
|
21206
|
-
const failure = execution.failureCode ? ` (failure: ${execution.failureCode})` : "";
|
|
21207
|
-
lines.push(
|
|
21208
|
-
`Temporal execution: ${execution.workflowId} run ${execution.runId ?? "-"} \u2014 ${execution.status}${failure}`
|
|
21209
|
-
);
|
|
21210
|
-
} else {
|
|
21211
|
-
lines.push("Temporal execution: none recorded");
|
|
21212
|
-
}
|
|
21213
|
-
if (status.waitingUntil) {
|
|
21214
|
-
lines.push(
|
|
21215
|
-
`Waiting for the operator window (21:00\u201308:00 America/New_York) until ${status.waitingUntil}`
|
|
21216
|
-
);
|
|
21217
|
-
}
|
|
21218
|
-
if (status.preview) {
|
|
21219
|
-
const previewPairs = status.preview.pairs ?? [];
|
|
21220
|
-
const admitted = previewPairs.reduce((n, p) => n + (p.totals?.admitted ?? 0), 0);
|
|
21221
|
-
const notAdmitted = previewPairs.reduce(
|
|
21222
|
-
(n, p) => n + (p.totals?.notAdmitted ?? 0),
|
|
21223
|
-
0
|
|
21224
|
-
);
|
|
21225
|
-
lines.push(
|
|
21226
|
-
`Latest preview: ${previewPairs.length} pair(s), ~${admitted} admission-eligible (incl. already-linked), ~${notAdmitted} not admitted (read-only)`
|
|
21227
|
-
);
|
|
21228
|
-
}
|
|
21229
|
-
lines.push("Counts are approximate.");
|
|
21230
|
-
const unfinished = (status.pairs ?? []).some(
|
|
21231
|
-
(p) => p.inCurrentCohort && RESUMABLE_PAIR_STATUSES.has(p.status) && p.runId
|
|
21232
|
-
);
|
|
21233
|
-
if (unfinished && execution?.status !== "running") {
|
|
21234
|
-
lines.push(
|
|
21235
|
-
`Unfinished pairs continue only on an explicit resume: gr fhir-connections onboarding-import start --id ${connectionId} --resume --allow-write`
|
|
21236
|
-
);
|
|
21237
|
-
}
|
|
21238
|
-
return lines;
|
|
21239
|
-
}
|
|
21240
21185
|
var fhirConnectionsDomain = {
|
|
21241
21186
|
name: "fhir-connections",
|
|
21242
21187
|
description: "Manage FHIR connections",
|
|
@@ -21294,77 +21239,6 @@ var fhirConnectionsDomain = {
|
|
|
21294
21239
|
);
|
|
21295
21240
|
outputData(runs, ctx, ENCOUNTER_RUN_COLUMNS);
|
|
21296
21241
|
}
|
|
21297
|
-
},
|
|
21298
|
-
{
|
|
21299
|
-
// athenahealth onboarding import (PR-C): one explicit, audited
|
|
21300
|
-
// operator execution per connection, at most 50 pages per pair per
|
|
21301
|
-
// run. Thin over the SDK; the server decides everything.
|
|
21302
|
-
path: ["fhir-connections", "onboarding-import", "start"],
|
|
21303
|
-
description: "Start an athenahealth onboarding import (or --resume / --override / --dry-run preview)",
|
|
21304
|
-
requiresWorkspace: true,
|
|
21305
|
-
mutates: true,
|
|
21306
|
-
args: [
|
|
21307
|
-
{ name: "id", description: "FHIR connection ID", required: true },
|
|
21308
|
-
{
|
|
21309
|
-
name: "dry-run",
|
|
21310
|
-
description: "Preview: read and classify admission only, write no Members",
|
|
21311
|
-
isFlag: true
|
|
21312
|
-
},
|
|
21313
|
-
{
|
|
21314
|
-
name: "resume",
|
|
21315
|
-
description: "Continue unfinished (failed, truncated, aborted) pairs at their stored frontier",
|
|
21316
|
-
isFlag: true
|
|
21317
|
-
},
|
|
21318
|
-
{
|
|
21319
|
-
name: "override",
|
|
21320
|
-
description: "Rescan completed pairs from offset 0 under a new generation",
|
|
21321
|
-
isFlag: true
|
|
21322
|
-
}
|
|
21323
|
-
],
|
|
21324
|
-
examples: [
|
|
21325
|
-
"fhir-connections onboarding-import start --id 12 --dry-run --allow-write",
|
|
21326
|
-
"fhir-connections onboarding-import start --id 12 --allow-write",
|
|
21327
|
-
"fhir-connections onboarding-import start --id 12 --resume --allow-write"
|
|
21328
|
-
],
|
|
21329
|
-
handler: async ({ ctx, workspace, args }) => {
|
|
21330
|
-
const connectionId = requireNumber(args, "id");
|
|
21331
|
-
const started = await requireAuth(ctx).apiClient.fhirStartOnboardingImport(
|
|
21332
|
-
workspace,
|
|
21333
|
-
connectionId,
|
|
21334
|
-
{
|
|
21335
|
-
dryRun: args["dry-run"] === true,
|
|
21336
|
-
resume: args["resume"] === true,
|
|
21337
|
-
override: args["override"] === true
|
|
21338
|
-
}
|
|
21339
|
-
);
|
|
21340
|
-
outputSingle(started, ctx, ONBOARDING_START_COLUMNS);
|
|
21341
|
-
hint(ctx, [
|
|
21342
|
-
`Started. Follow progress with: gr fhir-connections onboarding-import status --id ${connectionId}`
|
|
21343
|
-
]);
|
|
21344
|
-
}
|
|
21345
|
-
},
|
|
21346
|
-
{
|
|
21347
|
-
path: ["fhir-connections", "onboarding-import", "status"],
|
|
21348
|
-
description: "Show athenahealth onboarding-import progress and its Temporal execution (read-only)",
|
|
21349
|
-
requiresWorkspace: true,
|
|
21350
|
-
args: [{ name: "id", description: "FHIR connection ID", required: true }],
|
|
21351
|
-
examples: [
|
|
21352
|
-
"fhir-connections onboarding-import status --id 12",
|
|
21353
|
-
"fhir-connections onboarding-import status --id 12 --output-format json"
|
|
21354
|
-
],
|
|
21355
|
-
handler: async ({ ctx, workspace, args }) => {
|
|
21356
|
-
const connectionId = requireNumber(args, "id");
|
|
21357
|
-
const status = await requireAuth(ctx).apiClient.fhirGetOnboardingImportStatus(
|
|
21358
|
-
workspace,
|
|
21359
|
-
connectionId
|
|
21360
|
-
);
|
|
21361
|
-
if (ctx.jq || (ctx.outputFormat ?? "table") !== "table") {
|
|
21362
|
-
outputSingle(status, ctx);
|
|
21363
|
-
return;
|
|
21364
|
-
}
|
|
21365
|
-
outputData(status.pairs, ctx, ONBOARDING_PAIR_COLUMNS);
|
|
21366
|
-
hint(ctx, onboardingStatusLines(status, connectionId));
|
|
21367
|
-
}
|
|
21368
21242
|
}
|
|
21369
21243
|
]
|
|
21370
21244
|
};
|
|
@@ -21689,7 +21563,312 @@ var documoFaxDomain = {
|
|
|
21689
21563
|
]
|
|
21690
21564
|
};
|
|
21691
21565
|
|
|
21566
|
+
// src/domains/integrations/connection-commands.ts
|
|
21567
|
+
var POLL_INTERVAL_MIN_MINUTES = 15;
|
|
21568
|
+
var POLL_INTERVAL_MAX_MINUTES = 1440;
|
|
21569
|
+
function connectionIdArg(target) {
|
|
21570
|
+
return {
|
|
21571
|
+
name: "connection-id",
|
|
21572
|
+
description: `Connection ID (default: the workspace's ${target.label} connection)`
|
|
21573
|
+
};
|
|
21574
|
+
}
|
|
21575
|
+
async function resolveConnectionId(ctx, workspace, target, args) {
|
|
21576
|
+
const explicit = optionalNumber(args, "connection-id");
|
|
21577
|
+
if (explicit !== void 0) return explicit;
|
|
21578
|
+
const connections = await requireAuth(ctx).apiClient.listAppConnections(workspace);
|
|
21579
|
+
const matches = connections.filter((c) => c.connectionType === target.connectionType);
|
|
21580
|
+
if (matches.length === 0) {
|
|
21581
|
+
throw new CLIError(
|
|
21582
|
+
`No ${target.label} connection in this workspace. Run: gr ${target.command} install`
|
|
21583
|
+
);
|
|
21584
|
+
}
|
|
21585
|
+
if (matches.length > 1) {
|
|
21586
|
+
const ids = matches.map((c) => c.id).join(", ");
|
|
21587
|
+
throw new CLIError(
|
|
21588
|
+
`This workspace has ${matches.length} ${target.label} connections (${ids}). Pass --connection-id.`
|
|
21589
|
+
);
|
|
21590
|
+
}
|
|
21591
|
+
return matches[0].id;
|
|
21592
|
+
}
|
|
21593
|
+
function parsePollInterval(raw) {
|
|
21594
|
+
const minutes = Number(raw);
|
|
21595
|
+
if (!Number.isInteger(minutes) || minutes < POLL_INTERVAL_MIN_MINUTES || minutes > POLL_INTERVAL_MAX_MINUTES) {
|
|
21596
|
+
throw new CLIError(
|
|
21597
|
+
`Invalid --poll-interval "${String(raw)}". Must be a whole number of minutes between ${POLL_INTERVAL_MIN_MINUTES} and ${POLL_INTERVAL_MAX_MINUTES}.`
|
|
21598
|
+
);
|
|
21599
|
+
}
|
|
21600
|
+
return minutes;
|
|
21601
|
+
}
|
|
21602
|
+
function connectionCommands(target) {
|
|
21603
|
+
const c = target.command;
|
|
21604
|
+
const connectionId = connectionIdArg(target);
|
|
21605
|
+
return [
|
|
21606
|
+
{
|
|
21607
|
+
path: [c, "sync-config", "get"],
|
|
21608
|
+
description: `Get the ${target.label} sync configuration`,
|
|
21609
|
+
requiresWorkspace: true,
|
|
21610
|
+
args: [connectionId],
|
|
21611
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21612
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21613
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncConfig(workspace, id);
|
|
21614
|
+
outputSingle(result2, ctx);
|
|
21615
|
+
}
|
|
21616
|
+
},
|
|
21617
|
+
{
|
|
21618
|
+
path: [c, "sync-config", "set"],
|
|
21619
|
+
// `sync-config get -o json | … | sync-config set` pipes the whole
|
|
21620
|
+
// configuration; with --poll-interval alone there is no body to wait for.
|
|
21621
|
+
pipesJsonInput: (args) => args["poll-interval"] === void 0,
|
|
21622
|
+
description: `Replace the ${target.label} sync configuration (--data), or change one setting of the saved configuration (--poll-interval)`,
|
|
21623
|
+
mutates: true,
|
|
21624
|
+
requiresWorkspace: true,
|
|
21625
|
+
args: [
|
|
21626
|
+
connectionId,
|
|
21627
|
+
{
|
|
21628
|
+
name: "poll-interval",
|
|
21629
|
+
description: `Inbound poll cadence in minutes (${POLL_INTERVAL_MIN_MINUTES}..${POLL_INTERVAL_MAX_MINUTES}). Without --data, updates the saved configuration.`
|
|
21630
|
+
}
|
|
21631
|
+
],
|
|
21632
|
+
examples: [
|
|
21633
|
+
`gr ${c} sync-config get -w <ws> -o json > sync-config.json`,
|
|
21634
|
+
`gr ${c} sync-config set -w <ws> --allow-write --file sync-config.json`,
|
|
21635
|
+
`gr ${c} sync-config set -w <ws> --allow-write --poll-interval 60`
|
|
21636
|
+
],
|
|
21637
|
+
handler: async ({ ctx, workspace, args, data }) => {
|
|
21638
|
+
const rawInterval = args["poll-interval"];
|
|
21639
|
+
const hasInterval = rawInterval !== void 0 && rawInterval !== "";
|
|
21640
|
+
if (!data && !hasInterval) {
|
|
21641
|
+
throw new CLIError(
|
|
21642
|
+
"Pass the configuration (--data, --file, or stdin) or --poll-interval"
|
|
21643
|
+
);
|
|
21644
|
+
}
|
|
21645
|
+
if (data !== void 0 && (typeof data !== "object" || data === null || Array.isArray(data) || Object.keys(data).length === 0)) {
|
|
21646
|
+
throw new CLIError(
|
|
21647
|
+
"The configuration must be a non-empty JSON object (start from `sync-config get -o json`)"
|
|
21648
|
+
);
|
|
21649
|
+
}
|
|
21650
|
+
const minutes = hasInterval ? parsePollInterval(rawInterval) : void 0;
|
|
21651
|
+
const api = requireAuth(ctx).apiClient;
|
|
21652
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21653
|
+
const base = data ?? await api.getConnectionSyncConfig(workspace, id);
|
|
21654
|
+
const config = minutes === void 0 ? base : { ...base, inboundPollIntervalMinutes: minutes };
|
|
21655
|
+
const result2 = await api.updateConnectionSyncConfig(workspace, id, config);
|
|
21656
|
+
outputSingle(result2, ctx);
|
|
21657
|
+
}
|
|
21658
|
+
},
|
|
21659
|
+
{
|
|
21660
|
+
path: [c, "sync", "capabilities"],
|
|
21661
|
+
description: `What the ${target.label} sync engine supports (entities, directions, modes)`,
|
|
21662
|
+
requiresWorkspace: true,
|
|
21663
|
+
args: [connectionId],
|
|
21664
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21665
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21666
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncCapabilities(
|
|
21667
|
+
workspace,
|
|
21668
|
+
id
|
|
21669
|
+
);
|
|
21670
|
+
outputSingle(result2, ctx);
|
|
21671
|
+
}
|
|
21672
|
+
},
|
|
21673
|
+
{
|
|
21674
|
+
path: [c, "sync", "run"],
|
|
21675
|
+
description: `Start a ${target.label} sync run and stream its progress`,
|
|
21676
|
+
mutates: true,
|
|
21677
|
+
requiresWorkspace: true,
|
|
21678
|
+
args: [connectionId, ...SYNC_RUN_OPTION_ARGS],
|
|
21679
|
+
examples: [
|
|
21680
|
+
`gr ${c} sync run -w <ws> --allow-write --dry-run --entity-type member --record-limit 5`,
|
|
21681
|
+
`gr ${c} sync run -w <ws> --allow-write`,
|
|
21682
|
+
`gr ${c} sync run -w <ws> --allow-write --full-resync --quiet`
|
|
21683
|
+
],
|
|
21684
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21685
|
+
const options = parseSyncRunOptions(args);
|
|
21686
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21687
|
+
await runSyncAndStream(ctx, workspace, id, options);
|
|
21688
|
+
}
|
|
21689
|
+
},
|
|
21690
|
+
{
|
|
21691
|
+
path: [c, "sync", "runs"],
|
|
21692
|
+
description: `List recent ${target.label} sync runs`,
|
|
21693
|
+
requiresWorkspace: true,
|
|
21694
|
+
args: [connectionId, { name: "limit", description: "Max runs to return (default 20)" }],
|
|
21695
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21696
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21697
|
+
const runs = await requireAuth(ctx).apiClient.getSyncRuns(
|
|
21698
|
+
workspace,
|
|
21699
|
+
id,
|
|
21700
|
+
optionalNumber(args, "limit") ?? 20
|
|
21701
|
+
);
|
|
21702
|
+
outputData(runs, ctx, RUN_COLUMNS2);
|
|
21703
|
+
}
|
|
21704
|
+
},
|
|
21705
|
+
{
|
|
21706
|
+
path: [c, "sync", "run-items"],
|
|
21707
|
+
description: `List the items of one ${target.label} sync run`,
|
|
21708
|
+
requiresWorkspace: true,
|
|
21709
|
+
args: [
|
|
21710
|
+
connectionId,
|
|
21711
|
+
{ name: "run-id", description: "Run ID (from sync runs)", required: true },
|
|
21712
|
+
{ name: "limit", description: "Max items to return (default 500)" }
|
|
21713
|
+
],
|
|
21714
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21715
|
+
const runId = requireString(args, "run-id");
|
|
21716
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21717
|
+
const items = await requireAuth(ctx).apiClient.getSyncRunItems(
|
|
21718
|
+
workspace,
|
|
21719
|
+
id,
|
|
21720
|
+
runId,
|
|
21721
|
+
optionalNumber(args, "limit") ?? 500
|
|
21722
|
+
);
|
|
21723
|
+
outputData(items, ctx, ITEM_COLUMNS2);
|
|
21724
|
+
}
|
|
21725
|
+
},
|
|
21726
|
+
{
|
|
21727
|
+
path: [c, "sync", "checkpoint"],
|
|
21728
|
+
description: `Show the ${target.label} sync checkpoint (where the next run resumes)`,
|
|
21729
|
+
requiresWorkspace: true,
|
|
21730
|
+
args: [
|
|
21731
|
+
connectionId,
|
|
21732
|
+
{ name: "direction", description: "'inbound' (default) or 'outbound'" },
|
|
21733
|
+
{ name: "sync-key", description: "Sync key (default 'default')" }
|
|
21734
|
+
],
|
|
21735
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21736
|
+
const direction = args["direction"] ?? "inbound";
|
|
21737
|
+
if (direction !== "inbound" && direction !== "outbound") {
|
|
21738
|
+
throw new CLIError(
|
|
21739
|
+
`--direction must be 'inbound' or 'outbound', got '${direction}'`
|
|
21740
|
+
);
|
|
21741
|
+
}
|
|
21742
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21743
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncCheckpoint(
|
|
21744
|
+
workspace,
|
|
21745
|
+
id,
|
|
21746
|
+
direction,
|
|
21747
|
+
args["sync-key"] ?? "default"
|
|
21748
|
+
);
|
|
21749
|
+
outputSingle(result2, ctx);
|
|
21750
|
+
}
|
|
21751
|
+
},
|
|
21752
|
+
{
|
|
21753
|
+
path: [c, "sync", "member-summary"],
|
|
21754
|
+
description: `Count members by ${target.label} sync state (linked, failed, never synced)`,
|
|
21755
|
+
requiresWorkspace: true,
|
|
21756
|
+
args: [connectionId],
|
|
21757
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21758
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21759
|
+
const result2 = await requireAuth(ctx).apiClient.getMemberSyncSummary(workspace, id);
|
|
21760
|
+
outputSingle(result2, ctx);
|
|
21761
|
+
}
|
|
21762
|
+
},
|
|
21763
|
+
{
|
|
21764
|
+
path: [c, "field-keys"],
|
|
21765
|
+
description: `List the Member field keys the ${target.label} connection holds values for`,
|
|
21766
|
+
requiresWorkspace: true,
|
|
21767
|
+
args: [connectionId],
|
|
21768
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21769
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21770
|
+
const result2 = await requireAuth(ctx).apiClient.listConnectionMemberFieldKeys(
|
|
21771
|
+
workspace,
|
|
21772
|
+
id
|
|
21773
|
+
);
|
|
21774
|
+
outputData(result2.keys, ctx);
|
|
21775
|
+
}
|
|
21776
|
+
},
|
|
21777
|
+
{
|
|
21778
|
+
path: [c, "reconciliation", "relink"],
|
|
21779
|
+
description: `Let sync re-link a member you unlinked from ${target.label} (clears the manual-unlink exclusion). Idempotent: cleared=false when there was none.`,
|
|
21780
|
+
mutates: true,
|
|
21781
|
+
requiresWorkspace: true,
|
|
21782
|
+
args: [connectionId, { name: "member-id", description: "Member ID", required: true }],
|
|
21783
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21784
|
+
const memberId = requireNumber(args, "member-id");
|
|
21785
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21786
|
+
const result2 = await requireAuth(ctx).apiClient.clearConnectionMemberExclusion(
|
|
21787
|
+
workspace,
|
|
21788
|
+
id,
|
|
21789
|
+
memberId
|
|
21790
|
+
);
|
|
21791
|
+
outputSingle(result2, ctx);
|
|
21792
|
+
}
|
|
21793
|
+
},
|
|
21794
|
+
{
|
|
21795
|
+
path: [c, "reconciliation", "link-by-identity"],
|
|
21796
|
+
description: `Start the background run that links unlinked members to their ${target.label} records by identity, then syncs them. Prints the run's workflowId. Refused (400) when the connector has no identity resolver, and (409) while the connection is disabled or a run is already in flight.`,
|
|
21797
|
+
mutates: true,
|
|
21798
|
+
requiresWorkspace: true,
|
|
21799
|
+
args: [connectionId],
|
|
21800
|
+
examples: [
|
|
21801
|
+
`gr ${c} reconciliation link-by-identity -w <ws> --allow-write`,
|
|
21802
|
+
`gr ${c} reconciliation linked -w <ws> # check the new links afterwards`
|
|
21803
|
+
],
|
|
21804
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21805
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21806
|
+
const result2 = await requireAuth(ctx).apiClient.linkUnlinkedMembersByIdentity(
|
|
21807
|
+
workspace,
|
|
21808
|
+
id
|
|
21809
|
+
);
|
|
21810
|
+
outputSingle(result2, ctx);
|
|
21811
|
+
}
|
|
21812
|
+
}
|
|
21813
|
+
];
|
|
21814
|
+
}
|
|
21815
|
+
|
|
21692
21816
|
// src/domains/integrations/hubspot.ts
|
|
21817
|
+
var HUBSPOT = {
|
|
21818
|
+
command: "hubspot",
|
|
21819
|
+
label: "HubSpot",
|
|
21820
|
+
connectionType: "hubspot_connection"
|
|
21821
|
+
};
|
|
21822
|
+
var OBJECT_TYPES = ["contacts", "companies", "deals"];
|
|
21823
|
+
var SEARCHABLE_OBJECT_TYPES = ["contacts", "companies"];
|
|
21824
|
+
var SEARCH_COLUMNS = [
|
|
21825
|
+
{ header: "ID", getValue: (item) => item.id ?? "" },
|
|
21826
|
+
{ header: "TYPE", getValue: (item) => item.objectType ?? "" },
|
|
21827
|
+
{ header: "NAME", getValue: (item) => item.name ?? "" },
|
|
21828
|
+
{ header: "EMAIL", getValue: (item) => item.email ?? "" },
|
|
21829
|
+
{
|
|
21830
|
+
header: "MEMBER",
|
|
21831
|
+
getValue: (item) => item.existingMember ? `${item.existingMember.memberId} (${item.existingMember.matchType})` : ""
|
|
21832
|
+
}
|
|
21833
|
+
];
|
|
21834
|
+
var MATCH_COLUMNS2 = [
|
|
21835
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21836
|
+
{ header: "RECORD", getValue: (item) => item.hubspotRecordId ?? "" },
|
|
21837
|
+
{ header: "MATCH", getValue: (item) => item.matchType ?? "" },
|
|
21838
|
+
{ header: "OBJECT", getValue: (item) => item.objectType ?? "" }
|
|
21839
|
+
];
|
|
21840
|
+
var LINKED_COLUMNS2 = [
|
|
21841
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21842
|
+
{ header: "RECORD", getValue: (item) => item.hubspotRecordId ?? "" },
|
|
21843
|
+
{ header: "NAME", getValue: (item) => item.memberName ?? "" },
|
|
21844
|
+
{ header: "LAST SYNC", getValue: (item) => item.lastSyncStatus ?? "" }
|
|
21845
|
+
];
|
|
21846
|
+
var IMPORT_COLUMNS = [
|
|
21847
|
+
{ header: "HUBSPOT ID", getValue: (item) => item.hubspotId ?? "" },
|
|
21848
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21849
|
+
{ header: "OK", getValue: (item) => item.success ? "yes" : "no" },
|
|
21850
|
+
{ header: "ERROR", getValue: (item) => item.error ?? "" }
|
|
21851
|
+
];
|
|
21852
|
+
function importRecordsFrom(data) {
|
|
21853
|
+
const body = data;
|
|
21854
|
+
const rows = Array.isArray(body) ? body : Array.isArray(body?.records) ? body.records : Array.isArray(body?.results) ? body.results : void 0;
|
|
21855
|
+
if (!rows) {
|
|
21856
|
+
throw new CLIError(
|
|
21857
|
+
'JSON input must be {"records":[...]}, a `gr hubspot search -o json` response, or an array'
|
|
21858
|
+
);
|
|
21859
|
+
}
|
|
21860
|
+
return rows.map((row, index) => {
|
|
21861
|
+
const hubspotId = row?.hubspotId ?? row?.id;
|
|
21862
|
+
if (!hubspotId) throw new CLIError(`Record ${index} has no hubspotId (or id)`);
|
|
21863
|
+
return {
|
|
21864
|
+
hubspotId: String(hubspotId),
|
|
21865
|
+
name: row.name ?? null,
|
|
21866
|
+
email: row.email ?? null,
|
|
21867
|
+
phone: row.phone ?? null,
|
|
21868
|
+
objectType: row.objectType ?? "contacts"
|
|
21869
|
+
};
|
|
21870
|
+
});
|
|
21871
|
+
}
|
|
21693
21872
|
var hubspotDomain = {
|
|
21694
21873
|
name: "hubspot",
|
|
21695
21874
|
description: "HubSpot CRM integration",
|
|
@@ -21701,18 +21880,21 @@ var hubspotDomain = {
|
|
|
21701
21880
|
requiresWorkspace: true,
|
|
21702
21881
|
examples: [
|
|
21703
21882
|
"# When the response shows platformAppAvailable=true, the workspace connects through",
|
|
21704
|
-
"# the shared Gravity Rail HubSpot app:
|
|
21705
|
-
"gr hubspot
|
|
21706
|
-
"gr hubspot authorize -w <ws> --allow-write # then open the returned authorizeUrl",
|
|
21883
|
+
"# the shared Gravity Rail HubSpot app: one command, then open the authorizeUrl.",
|
|
21884
|
+
"gr hubspot connect -w <ws> --allow-write",
|
|
21707
21885
|
"",
|
|
21708
21886
|
"# To use your own HubSpot app instead (a Projects-platform app; HubSpot no longer",
|
|
21709
21887
|
"# allows new private or developer apps):",
|
|
21710
21888
|
'# 1. install -> creates the connection; the response includes the OAuth "callbackUrl"',
|
|
21711
21889
|
"# 2. in HubSpot: give your app that callbackUrl as a Redirect URL, with CRM scopes",
|
|
21712
|
-
"# (contacts/companies/deals read+write)
|
|
21890
|
+
"# (contacts/companies/deals read+write), plus crm.lists.read and",
|
|
21891
|
+
"# crm.objects.owners.read, forms, and scheduler.meetings.meeting-link.read",
|
|
21892
|
+
"# as OPTIONAL scopes (HubSpot rejects the authorize",
|
|
21893
|
+
"# request if the app lacks them).",
|
|
21894
|
+
"# Copy the Client ID + Secret.",
|
|
21713
21895
|
"# 3. configure -> save that Client ID / Secret",
|
|
21714
21896
|
'# 4. authorize -> returns an "authorizeUrl"; open it to grant access.',
|
|
21715
|
-
"gr hubspot
|
|
21897
|
+
"gr hubspot install -w <ws> --allow-write",
|
|
21716
21898
|
`gr hubspot configure -w <ws> --allow-write -d '{"clientId":"...","clientSecret":"..."}'`,
|
|
21717
21899
|
"gr hubspot authorize -w <ws> --allow-write # then open the returned authorizeUrl"
|
|
21718
21900
|
],
|
|
@@ -21721,6 +21903,33 @@ var hubspotDomain = {
|
|
|
21721
21903
|
outputSingle(result2, ctx);
|
|
21722
21904
|
}
|
|
21723
21905
|
},
|
|
21906
|
+
{
|
|
21907
|
+
path: ["hubspot", "connect"],
|
|
21908
|
+
description: "Install HubSpot if needed and start OAuth: prints the authorizeUrl to open and the exact callbackUrl the HubSpot app must allow",
|
|
21909
|
+
mutates: true,
|
|
21910
|
+
requiresWorkspace: true,
|
|
21911
|
+
examples: ["gr hubspot connect -w <ws> --allow-write"],
|
|
21912
|
+
handler: async ({ ctx, workspace }) => {
|
|
21913
|
+
const api = requireAuth(ctx).apiClient;
|
|
21914
|
+
const installed = await api.installHubspot(workspace);
|
|
21915
|
+
if (!installed.configured) {
|
|
21916
|
+
outputSingle(installed, ctx);
|
|
21917
|
+
throw new CLIError(
|
|
21918
|
+
"HubSpot is installed but has no app credentials. Register the callbackUrl above on your HubSpot app, then run: gr hubspot configure, then gr hubspot connect"
|
|
21919
|
+
);
|
|
21920
|
+
}
|
|
21921
|
+
const started = await api.startHubspotOAuth(workspace);
|
|
21922
|
+
outputSingle(
|
|
21923
|
+
{
|
|
21924
|
+
connectionId: started.connectionId,
|
|
21925
|
+
usesPlatformApp: started.usesPlatformApp,
|
|
21926
|
+
callbackUrl: started.callbackUrl,
|
|
21927
|
+
authorizeUrl: started.authorizeUrl
|
|
21928
|
+
},
|
|
21929
|
+
ctx
|
|
21930
|
+
);
|
|
21931
|
+
}
|
|
21932
|
+
},
|
|
21724
21933
|
{
|
|
21725
21934
|
path: ["hubspot", "status"],
|
|
21726
21935
|
description: "Get HubSpot connection status (shows configured/connected state + the OAuth callback URL)",
|
|
@@ -21732,6 +21941,8 @@ var hubspotDomain = {
|
|
|
21732
21941
|
},
|
|
21733
21942
|
{
|
|
21734
21943
|
path: ["hubspot", "configure"],
|
|
21944
|
+
// Reads its body from --data, --file or piped stdin.
|
|
21945
|
+
acceptsJsonInput: true,
|
|
21735
21946
|
description: "Configure HubSpot credentials (setup step 3): save the Client ID / Secret",
|
|
21736
21947
|
mutates: true,
|
|
21737
21948
|
requiresWorkspace: true,
|
|
@@ -21759,7 +21970,7 @@ var hubspotDomain = {
|
|
|
21759
21970
|
},
|
|
21760
21971
|
{
|
|
21761
21972
|
path: ["hubspot", "disconnect"],
|
|
21762
|
-
description: "Disconnect HubSpot",
|
|
21973
|
+
description: "Disconnect HubSpot: clear the stored OAuth tokens and return the connection to setup (HubSpot keeps the app install)",
|
|
21763
21974
|
mutates: true,
|
|
21764
21975
|
requiresWorkspace: true,
|
|
21765
21976
|
handler: async ({ ctx, workspace }) => {
|
|
@@ -21798,121 +22009,270 @@ var hubspotDomain = {
|
|
|
21798
22009
|
}
|
|
21799
22010
|
},
|
|
21800
22011
|
{
|
|
21801
|
-
path: ["hubspot", "
|
|
21802
|
-
description: "
|
|
22012
|
+
path: ["hubspot", "search"],
|
|
22013
|
+
description: "Search HubSpot contacts or companies; each result shows the workspace member it matches",
|
|
21803
22014
|
requiresWorkspace: true,
|
|
21804
|
-
|
|
21805
|
-
|
|
21806
|
-
|
|
21807
|
-
|
|
21808
|
-
|
|
21809
|
-
|
|
21810
|
-
|
|
21811
|
-
|
|
21812
|
-
|
|
22015
|
+
args: [
|
|
22016
|
+
{
|
|
22017
|
+
name: "query",
|
|
22018
|
+
description: "Contacts whose email, or companies whose name, contains this text; empty lists all"
|
|
22019
|
+
},
|
|
22020
|
+
{ name: "object-type", description: "'contacts' (default) or 'companies'" },
|
|
22021
|
+
{ name: "limit", description: "Max results (1..100, default 20)" },
|
|
22022
|
+
{
|
|
22023
|
+
name: "after",
|
|
22024
|
+
description: "Cursor from a previous page (nextCursor); only without --query"
|
|
22025
|
+
}
|
|
22026
|
+
],
|
|
22027
|
+
examples: [
|
|
22028
|
+
"gr hubspot search -w <ws> --query smith",
|
|
22029
|
+
"gr hubspot search -w <ws> --object-type companies --limit 50"
|
|
22030
|
+
],
|
|
22031
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22032
|
+
const objectType = args["object-type"] ?? "contacts";
|
|
22033
|
+
if (!SEARCHABLE_OBJECT_TYPES.includes(objectType)) {
|
|
22034
|
+
throw new CLIError(
|
|
22035
|
+
`--object-type must be one of ${SEARCHABLE_OBJECT_TYPES.join(", ")}, got '${objectType}'`
|
|
22036
|
+
);
|
|
22037
|
+
}
|
|
22038
|
+
if (args["query"] && args["after"]) {
|
|
22039
|
+
throw new CLIError("--after pages only the listing without --query");
|
|
22040
|
+
}
|
|
22041
|
+
const result2 = await requireAuth(ctx).apiClient.searchHubspotRecords(workspace, {
|
|
22042
|
+
query: args["query"] ?? "",
|
|
22043
|
+
objectType,
|
|
22044
|
+
limit: optionalNumber(args, "limit") ?? 20,
|
|
22045
|
+
...args["after"] ? { after: String(args["after"]) } : {}
|
|
22046
|
+
});
|
|
22047
|
+
if (ctx.outputFormat !== "table") {
|
|
22048
|
+
outputSingle(result2, ctx);
|
|
22049
|
+
return;
|
|
22050
|
+
}
|
|
22051
|
+
outputData(result2.results, ctx, SEARCH_COLUMNS);
|
|
22052
|
+
if (result2.hasMore && result2.nextCursor && !args["query"]) {
|
|
22053
|
+
console.error(`More results: --after ${result2.nextCursor}`);
|
|
22054
|
+
}
|
|
21813
22055
|
}
|
|
21814
22056
|
},
|
|
21815
22057
|
{
|
|
21816
|
-
path: ["hubspot", "
|
|
21817
|
-
|
|
22058
|
+
path: ["hubspot", "import-members"],
|
|
22059
|
+
// Its input is usually the previous command's output: wait for the pipe.
|
|
22060
|
+
pipesJsonInput: true,
|
|
22061
|
+
description: "Create (or update and link) workspace members from HubSpot records (max 100 per call)",
|
|
21818
22062
|
mutates: true,
|
|
21819
22063
|
requiresWorkspace: true,
|
|
21820
|
-
|
|
21821
|
-
|
|
21822
|
-
|
|
21823
|
-
|
|
21824
|
-
|
|
21825
|
-
|
|
21826
|
-
|
|
21827
|
-
|
|
21828
|
-
|
|
21829
|
-
|
|
21830
|
-
|
|
22064
|
+
args: [
|
|
22065
|
+
{
|
|
22066
|
+
name: "member-role-id",
|
|
22067
|
+
description: "Member role for new members (overrides memberRoleId in the body)"
|
|
22068
|
+
},
|
|
22069
|
+
{
|
|
22070
|
+
name: "ids",
|
|
22071
|
+
description: "Comma-separated HubSpot IDs: import only these rows of the input"
|
|
22072
|
+
},
|
|
22073
|
+
{ name: "add-to-org", description: "Also add new members to the org", isFlag: true },
|
|
22074
|
+
{
|
|
22075
|
+
name: "org-role",
|
|
22076
|
+
description: "Org role with --add-to-org: 'member' (default), 'admin', 'owner'"
|
|
22077
|
+
}
|
|
22078
|
+
],
|
|
22079
|
+
examples: [
|
|
22080
|
+
"gr hubspot search -w <ws> --query smith -o json \\",
|
|
22081
|
+
" | gr hubspot import-members -w <ws> --member-role-id 3 --allow-write",
|
|
22082
|
+
"gr hubspot search -w <ws> -o json > found.json",
|
|
22083
|
+
"gr hubspot import-members -w <ws> --file found.json --ids 101,102 --member-role-id 3 --allow-write"
|
|
22084
|
+
],
|
|
22085
|
+
handler: async ({ ctx, workspace, args, data }) => {
|
|
22086
|
+
if (!data) {
|
|
22087
|
+
throw new CLIError(
|
|
22088
|
+
"JSON input required (--data, --file, or stdin): pipe `gr hubspot search -o json`"
|
|
22089
|
+
);
|
|
22090
|
+
}
|
|
22091
|
+
let records = importRecordsFrom(data);
|
|
22092
|
+
const rawIds = args["ids"];
|
|
22093
|
+
if (rawIds) {
|
|
22094
|
+
const wanted = new Set(
|
|
22095
|
+
rawIds.split(",").map((id) => id.trim()).filter(Boolean)
|
|
22096
|
+
);
|
|
22097
|
+
records = records.filter((r) => wanted.has(r.hubspotId));
|
|
22098
|
+
const missing = [...wanted].filter((id) => !records.some((r) => r.hubspotId === id));
|
|
22099
|
+
if (missing.length > 0) {
|
|
22100
|
+
throw new CLIError(`--ids not found in the input: ${missing.join(", ")}`);
|
|
22101
|
+
}
|
|
22102
|
+
}
|
|
22103
|
+
if (records.length === 0) throw new CLIError("No records to import");
|
|
22104
|
+
if (records.length > 100) {
|
|
22105
|
+
throw new CLIError(`At most 100 records per import; got ${records.length}`);
|
|
22106
|
+
}
|
|
22107
|
+
const bodyRoleId = data?.memberRoleId;
|
|
22108
|
+
const memberRoleId = optionalNumber(args, "member-role-id") ?? (typeof bodyRoleId === "number" ? bodyRoleId : void 0);
|
|
22109
|
+
if (memberRoleId === void 0) {
|
|
22110
|
+
throw new CLIError("--member-role-id is required (see: gr member-roles list)");
|
|
22111
|
+
}
|
|
22112
|
+
const addToOrg = args["add-to-org"] === true || data?.addToOrg === true;
|
|
22113
|
+
const orgRole = args["org-role"] ?? data?.orgRole;
|
|
22114
|
+
const result2 = await requireAuth(ctx).apiClient.importHubspotMembers(workspace, {
|
|
22115
|
+
records,
|
|
22116
|
+
memberRoleId,
|
|
22117
|
+
addToOrg,
|
|
22118
|
+
...orgRole ? { orgRole } : {}
|
|
22119
|
+
});
|
|
22120
|
+
if (ctx.outputFormat !== "table") {
|
|
22121
|
+
outputSingle(result2, ctx);
|
|
22122
|
+
return;
|
|
22123
|
+
}
|
|
22124
|
+
outputData(result2.results, ctx, IMPORT_COLUMNS);
|
|
22125
|
+
console.error(`Imported ${result2.imported}, failed ${result2.failed}`);
|
|
21831
22126
|
}
|
|
21832
22127
|
},
|
|
21833
22128
|
{
|
|
21834
|
-
path: ["hubspot", "reconciliation"],
|
|
21835
|
-
description: "Find
|
|
22129
|
+
path: ["hubspot", "reconciliation", "matches"],
|
|
22130
|
+
description: "Find unlinked members with a likely HubSpot record (by email/phone); queries HubSpot",
|
|
21836
22131
|
requiresWorkspace: true,
|
|
21837
22132
|
args: [
|
|
21838
|
-
{ name: "offset", description: "
|
|
21839
|
-
{ name: "limit", description: "Max
|
|
22133
|
+
{ name: "offset", description: "Scan offset (default 0)" },
|
|
22134
|
+
{ name: "limit", description: "Max members to scan (default 50, max 200)" }
|
|
21840
22135
|
],
|
|
21841
22136
|
handler: async ({ ctx, workspace, args }) => {
|
|
21842
|
-
const offset = args["offset"] ? Number(args["offset"]) : void 0;
|
|
21843
|
-
const limit = args["limit"] ? Number(args["limit"]) : void 0;
|
|
21844
22137
|
const result2 = await requireAuth(ctx).apiClient.getHubspotReconciliationMatches(
|
|
21845
22138
|
workspace,
|
|
21846
|
-
{
|
|
21847
|
-
offset,
|
|
21848
|
-
limit
|
|
21849
|
-
}
|
|
22139
|
+
{ offset: optionalNumber(args, "offset"), limit: optionalNumber(args, "limit") }
|
|
21850
22140
|
);
|
|
21851
|
-
outputData(result2, ctx);
|
|
22141
|
+
outputData(result2, ctx, MATCH_COLUMNS2);
|
|
21852
22142
|
}
|
|
21853
22143
|
},
|
|
21854
22144
|
{
|
|
21855
|
-
path: ["hubspot", "linked
|
|
21856
|
-
description: "List members linked to HubSpot
|
|
22145
|
+
path: ["hubspot", "reconciliation", "linked"],
|
|
22146
|
+
description: "List members linked to HubSpot records",
|
|
21857
22147
|
requiresWorkspace: true,
|
|
21858
|
-
args:
|
|
22148
|
+
args: [
|
|
22149
|
+
...LIST_PAGINATION_ARGS,
|
|
22150
|
+
{ name: "search", description: "Filter by member name/email/phone or HubSpot ID" }
|
|
22151
|
+
],
|
|
21859
22152
|
handler: async ({ ctx, workspace, args }) => {
|
|
21860
22153
|
const pag = parsePaginationArgs(args);
|
|
22154
|
+
const search = args["search"] ? String(args["search"]) : void 0;
|
|
22155
|
+
const api = requireAuth(ctx).apiClient;
|
|
21861
22156
|
if (pag.all) {
|
|
21862
22157
|
const allItems = await fetchAllPages(
|
|
21863
|
-
({ page, pageSize }) =>
|
|
22158
|
+
({ page, pageSize }) => api.getLinkedHubspotMembers(workspace, { page, pageSize, search })
|
|
21864
22159
|
);
|
|
21865
|
-
outputData(allItems, ctx);
|
|
22160
|
+
outputData(allItems, ctx, LINKED_COLUMNS2);
|
|
21866
22161
|
return;
|
|
21867
22162
|
}
|
|
21868
|
-
const
|
|
21869
|
-
|
|
21870
|
-
|
|
21871
|
-
|
|
21872
|
-
|
|
21873
|
-
|
|
21874
|
-
);
|
|
21875
|
-
outputData(listResult(result2, true), ctx);
|
|
22163
|
+
const result2 = await api.getLinkedHubspotMembers(workspace, {
|
|
22164
|
+
...pag.page ? { page: pag.page } : {},
|
|
22165
|
+
...pag.pageSize ? { pageSize: pag.pageSize } : {},
|
|
22166
|
+
...search ? { search } : {}
|
|
22167
|
+
});
|
|
22168
|
+
outputData(listResult(result2, true), ctx, LINKED_COLUMNS2);
|
|
21876
22169
|
}
|
|
21877
22170
|
},
|
|
21878
22171
|
{
|
|
21879
|
-
path: ["hubspot", "link
|
|
21880
|
-
description: "Link a member to a HubSpot
|
|
22172
|
+
path: ["hubspot", "reconciliation", "link"],
|
|
22173
|
+
description: "Link a member to a HubSpot record",
|
|
21881
22174
|
mutates: true,
|
|
21882
22175
|
requiresWorkspace: true,
|
|
21883
22176
|
args: [
|
|
21884
22177
|
{ name: "member-id", description: "Member ID", required: true },
|
|
21885
|
-
{ name: "
|
|
22178
|
+
{ name: "record-id", description: "HubSpot record ID", required: true },
|
|
22179
|
+
{ name: "object-type", description: "HubSpot object type (default 'contacts')" }
|
|
22180
|
+
],
|
|
22181
|
+
examples: [
|
|
22182
|
+
"gr hubspot reconciliation link -w <ws> --member-id 42 --record-id 101 --allow-write"
|
|
21886
22183
|
],
|
|
21887
22184
|
handler: async ({ ctx, workspace, args }) => {
|
|
22185
|
+
const objectType = args["object-type"] ? String(args["object-type"]) : void 0;
|
|
21888
22186
|
const result2 = await requireAuth(ctx).apiClient.linkMemberToHubspot(workspace, {
|
|
21889
22187
|
memberId: requireNumber(args, "member-id"),
|
|
21890
|
-
hubspotRecordId: requireString(args, "
|
|
22188
|
+
hubspotRecordId: requireString(args, "record-id"),
|
|
22189
|
+
...objectType ? { objectType } : {}
|
|
21891
22190
|
});
|
|
21892
22191
|
outputSingle(result2, ctx);
|
|
21893
22192
|
}
|
|
21894
22193
|
},
|
|
21895
22194
|
{
|
|
21896
|
-
path: ["hubspot", "
|
|
21897
|
-
|
|
22195
|
+
path: ["hubspot", "reconciliation", "link-bulk"],
|
|
22196
|
+
// Its input is usually the previous command's output: wait for the pipe.
|
|
22197
|
+
pipesJsonInput: true,
|
|
22198
|
+
description: 'Link many members at once. Body: {"links":[{"memberId":1,"recordId":"101"}]} (hubspotRecordId is accepted too); `reconciliation matches -o json` pipes in',
|
|
22199
|
+
mutates: true,
|
|
22200
|
+
requiresWorkspace: true,
|
|
22201
|
+
examples: [
|
|
22202
|
+
"gr hubspot reconciliation matches -w <ws> -o json \\",
|
|
22203
|
+
" | gr hubspot reconciliation link-bulk -w <ws> --allow-write"
|
|
22204
|
+
],
|
|
22205
|
+
handler: async ({ ctx, workspace, data }) => {
|
|
22206
|
+
const body = data;
|
|
22207
|
+
const rows = Array.isArray(body) ? body : body?.links;
|
|
22208
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
22209
|
+
throw new CLIError('JSON input must be {"links":[...]} or an array of matches');
|
|
22210
|
+
}
|
|
22211
|
+
const links = rows.map((row, index) => {
|
|
22212
|
+
const memberId = Number(row?.memberId);
|
|
22213
|
+
const recordId = row?.recordId ?? row?.hubspotRecordId;
|
|
22214
|
+
if (!Number.isInteger(memberId) || !recordId) {
|
|
22215
|
+
throw new CLIError(
|
|
22216
|
+
`links[${index}] needs a numeric memberId and a recordId (or hubspotRecordId)`
|
|
22217
|
+
);
|
|
22218
|
+
}
|
|
22219
|
+
return {
|
|
22220
|
+
memberId,
|
|
22221
|
+
hubspotRecordId: String(recordId),
|
|
22222
|
+
...row.objectType ? { objectType: String(row.objectType) } : {}
|
|
22223
|
+
};
|
|
22224
|
+
});
|
|
22225
|
+
const result2 = await requireAuth(ctx).apiClient.bulkLinkMembersToHubspot(workspace, {
|
|
22226
|
+
links
|
|
22227
|
+
});
|
|
22228
|
+
outputSingle(result2, ctx);
|
|
22229
|
+
}
|
|
22230
|
+
},
|
|
22231
|
+
{
|
|
22232
|
+
path: ["hubspot", "reconciliation", "unlink"],
|
|
22233
|
+
description: "Unlink a member from HubSpot (sync will not re-link them until reconciliation relink)",
|
|
21898
22234
|
mutates: true,
|
|
21899
22235
|
requiresWorkspace: true,
|
|
21900
22236
|
args: [{ name: "member-id", description: "Member ID", required: true }],
|
|
21901
22237
|
handler: async ({ ctx, workspace, args }) => {
|
|
21902
|
-
await requireAuth(ctx).apiClient.unlinkMemberFromHubspot(
|
|
22238
|
+
const result2 = await requireAuth(ctx).apiClient.unlinkMemberFromHubspot(
|
|
21903
22239
|
workspace,
|
|
21904
22240
|
requireNumber(args, "member-id")
|
|
21905
22241
|
);
|
|
21906
|
-
|
|
22242
|
+
outputSingle(result2, ctx);
|
|
21907
22243
|
}
|
|
21908
22244
|
},
|
|
21909
22245
|
{
|
|
21910
|
-
path: ["hubspot", "
|
|
21911
|
-
description: "List
|
|
22246
|
+
path: ["hubspot", "properties"],
|
|
22247
|
+
description: "List HubSpot property definitions: the sync-mappable contact properties by default, or every property of --object-type as HubSpot defines it",
|
|
21912
22248
|
requiresWorkspace: true,
|
|
21913
|
-
|
|
21914
|
-
|
|
21915
|
-
|
|
22249
|
+
args: [
|
|
22250
|
+
{
|
|
22251
|
+
name: "object-type",
|
|
22252
|
+
description: "Raw HubSpot schema for 'contacts', 'companies' or 'deals'"
|
|
22253
|
+
}
|
|
22254
|
+
],
|
|
22255
|
+
examples: [
|
|
22256
|
+
"gr hubspot properties -w <ws>",
|
|
22257
|
+
"gr hubspot properties -w <ws> --object-type deals -o json"
|
|
22258
|
+
],
|
|
22259
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22260
|
+
const objectType = args["object-type"];
|
|
22261
|
+
const api = requireAuth(ctx).apiClient;
|
|
22262
|
+
if (objectType === void 0) {
|
|
22263
|
+
outputData(await api.getHubspotContactProperties(workspace), ctx);
|
|
22264
|
+
return;
|
|
22265
|
+
}
|
|
22266
|
+
if (!OBJECT_TYPES.includes(objectType)) {
|
|
22267
|
+
throw new CLIError(
|
|
22268
|
+
`--object-type must be one of ${OBJECT_TYPES.join(", ")}, got '${objectType}'`
|
|
22269
|
+
);
|
|
22270
|
+
}
|
|
22271
|
+
const result2 = await api.getHubspotObjectProperties(
|
|
22272
|
+
workspace,
|
|
22273
|
+
objectType
|
|
22274
|
+
);
|
|
22275
|
+
outputSingle(result2, ctx);
|
|
21916
22276
|
}
|
|
21917
22277
|
},
|
|
21918
22278
|
{
|
|
@@ -21924,6 +22284,22 @@ var hubspotDomain = {
|
|
|
21924
22284
|
outputData(result2, ctx);
|
|
21925
22285
|
}
|
|
21926
22286
|
},
|
|
22287
|
+
{
|
|
22288
|
+
path: ["hubspot", "sync", "logs"],
|
|
22289
|
+
description: "List HubSpot managed-rule executions (newest first, cursor-paged)",
|
|
22290
|
+
requiresWorkspace: true,
|
|
22291
|
+
args: [
|
|
22292
|
+
{ name: "page-size", description: "Rows per page" },
|
|
22293
|
+
{ name: "cursor", description: "Cursor from a previous page (nextCursor)" }
|
|
22294
|
+
],
|
|
22295
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22296
|
+
const result2 = await requireAuth(ctx).apiClient.getHubspotSyncLogs(workspace, {
|
|
22297
|
+
pageSize: optionalNumber(args, "page-size"),
|
|
22298
|
+
cursor: args["cursor"] ? String(args["cursor"]) : void 0
|
|
22299
|
+
});
|
|
22300
|
+
outputSingle(result2, ctx);
|
|
22301
|
+
}
|
|
22302
|
+
},
|
|
21927
22303
|
{
|
|
21928
22304
|
path: ["hubspot", "transform-presets"],
|
|
21929
22305
|
description: "List available HubSpot field transform presets",
|
|
@@ -21932,7 +22308,8 @@ var hubspotDomain = {
|
|
|
21932
22308
|
const result2 = await requireAuth(ctx).apiClient.getHubspotTransformPresets(workspace);
|
|
21933
22309
|
outputData(result2, ctx);
|
|
21934
22310
|
}
|
|
21935
|
-
}
|
|
22311
|
+
},
|
|
22312
|
+
...connectionCommands(HUBSPOT)
|
|
21936
22313
|
]
|
|
21937
22314
|
};
|
|
21938
22315
|
|
|
@@ -22208,37 +22585,39 @@ var salesforceDomain = {
|
|
|
22208
22585
|
commands: [
|
|
22209
22586
|
{
|
|
22210
22587
|
path: ["salesforce", "install"],
|
|
22211
|
-
description: "Install Salesforce (setup step 1): create the connection
|
|
22588
|
+
description: "Install Salesforce (setup step 1): create the connection for an environment, then authorize",
|
|
22212
22589
|
mutates: true,
|
|
22213
22590
|
requiresWorkspace: true,
|
|
22214
22591
|
args: [
|
|
22215
22592
|
{
|
|
22216
|
-
name: "
|
|
22217
|
-
description: "Salesforce
|
|
22593
|
+
name: "environment",
|
|
22594
|
+
description: "Salesforce environment: production (default) or sandbox"
|
|
22595
|
+
},
|
|
22596
|
+
{
|
|
22597
|
+
name: "my-domain",
|
|
22598
|
+
description: "The org's My Domain host (e.g. acme.my.salesforce.com), only for an org that blocks login.salesforce.com / test.salesforce.com"
|
|
22218
22599
|
}
|
|
22219
22600
|
],
|
|
22220
22601
|
examples: [
|
|
22221
|
-
"#
|
|
22222
|
-
|
|
22223
|
-
|
|
22224
|
-
"#
|
|
22225
|
-
"#
|
|
22226
|
-
|
|
22227
|
-
'# 4. authorize -> returns an "authorizeUrl"; open it to grant access. status then',
|
|
22228
|
-
"# reports configured=true and connected=true.",
|
|
22602
|
+
"# One-click setup through the shared Gravity Rail Salesforce app:",
|
|
22603
|
+
"# 1. install -> creates the connection for the chosen environment",
|
|
22604
|
+
'# 2. authorize -> returns an "authorizeUrl"; open it, sign in and approve access.',
|
|
22605
|
+
"# status then reports connected=true.",
|
|
22606
|
+
"# Advanced (own app): run configure between install and authorize, with an app whose",
|
|
22607
|
+
'# Callback URL is the status "callbackUrl".',
|
|
22229
22608
|
"",
|
|
22230
22609
|
"gr salesforce install -w <ws> --allow-write",
|
|
22231
|
-
"gr salesforce install -w <ws> --
|
|
22232
|
-
"gr salesforce
|
|
22233
|
-
|
|
22234
|
-
"gr salesforce authorize -w <ws> --allow-write # then open the returned authorizeUrl"
|
|
22610
|
+
"gr salesforce install -w <ws> --environment sandbox --allow-write",
|
|
22611
|
+
"gr salesforce authorize -w <ws> --allow-write # then open the returned authorizeUrl",
|
|
22612
|
+
"gr salesforce status -w <ws>"
|
|
22235
22613
|
],
|
|
22236
22614
|
handler: async ({ ctx, workspace, args }) => {
|
|
22237
|
-
const
|
|
22238
|
-
const
|
|
22239
|
-
|
|
22240
|
-
typeof
|
|
22241
|
-
|
|
22615
|
+
const environment = args["environment"];
|
|
22616
|
+
const myDomain = args["my-domain"];
|
|
22617
|
+
const result2 = await requireAuth(ctx).apiClient.installSalesforce(workspace, {
|
|
22618
|
+
...typeof environment === "string" ? { environment } : {},
|
|
22619
|
+
...typeof myDomain === "string" ? { myDomain } : {}
|
|
22620
|
+
});
|
|
22242
22621
|
outputSingle(result2, ctx);
|
|
22243
22622
|
}
|
|
22244
22623
|
},
|
|
@@ -22253,12 +22632,12 @@ var salesforceDomain = {
|
|
|
22253
22632
|
},
|
|
22254
22633
|
{
|
|
22255
22634
|
path: ["salesforce", "configure"],
|
|
22256
|
-
description: "
|
|
22635
|
+
description: "Advanced: save your own Salesforce app's Client ID / Secret and environment, then open the returned authorizeUrl",
|
|
22257
22636
|
mutates: true,
|
|
22258
22637
|
requiresWorkspace: true,
|
|
22259
22638
|
examples: [
|
|
22260
22639
|
"gr salesforce configure -w <ws> --allow-write \\",
|
|
22261
|
-
` -d '{"clientId":"3MVG9...","clientSecret":"1A2B...","
|
|
22640
|
+
` -d '{"clientId":"3MVG9...","clientSecret":"1A2B...","environment":"production"}'`
|
|
22262
22641
|
],
|
|
22263
22642
|
handler: async ({ ctx, workspace, data }) => {
|
|
22264
22643
|
if (!data) throw new CLIError("JSON data required (--data, --file, or stdin)");
|
|
@@ -22271,7 +22650,7 @@ var salesforceDomain = {
|
|
|
22271
22650
|
},
|
|
22272
22651
|
{
|
|
22273
22652
|
path: ["salesforce", "authorize"],
|
|
22274
|
-
description: "Authorize Salesforce via OAuth (setup step
|
|
22653
|
+
description: "Authorize Salesforce via OAuth (setup step 2): returns an authorizeUrl to open in a browser",
|
|
22275
22654
|
mutates: true,
|
|
22276
22655
|
requiresWorkspace: true,
|
|
22277
22656
|
handler: async ({ ctx, workspace }) => {
|
|
@@ -24486,10 +24865,15 @@ var RealtimeClient = class extends EventEmitter {
|
|
|
24486
24865
|
message: { role: "user", content }
|
|
24487
24866
|
});
|
|
24488
24867
|
}
|
|
24489
|
-
/**
|
|
24868
|
+
/**
|
|
24869
|
+
* Send interrupt signal with playback position.
|
|
24870
|
+
*
|
|
24871
|
+
* The position goes out as whole non-negative milliseconds, as the browser
|
|
24872
|
+
* sends it: the player reports fractional sample durations.
|
|
24873
|
+
*/
|
|
24490
24874
|
sendInterrupt(audioEndMs, messageId) {
|
|
24491
24875
|
this.sendCustom("voice.interrupt", {
|
|
24492
|
-
audio_end_ms: audioEndMs,
|
|
24876
|
+
audio_end_ms: Math.max(0, Math.floor(audioEndMs)),
|
|
24493
24877
|
message_id: messageId
|
|
24494
24878
|
});
|
|
24495
24879
|
}
|
|
@@ -27213,7 +27597,7 @@ var topLevelCommands = [
|
|
|
27213
27597
|
mutates: true,
|
|
27214
27598
|
args: [{ name: "phone", description: "E.164 phone number (optional; prompts if omitted)" }],
|
|
27215
27599
|
handler: async (hctx) => {
|
|
27216
|
-
const { accountVerifyPhoneCommand } = await import("./account-verify-phone-
|
|
27600
|
+
const { accountVerifyPhoneCommand } = await import("./account-verify-phone-Q4FKI4PX.js");
|
|
27217
27601
|
await accountVerifyPhoneCommand(hctx);
|
|
27218
27602
|
}
|
|
27219
27603
|
},
|
|
@@ -27320,6 +27704,7 @@ export {
|
|
|
27320
27704
|
CommandRegistry,
|
|
27321
27705
|
LIST_PAGINATION_ARGS,
|
|
27322
27706
|
PAGINATION_ARGS,
|
|
27707
|
+
PIPED_INPUT_FIRST_BYTE_WAIT_MS,
|
|
27323
27708
|
WORKSPACE_EXPORT_ZIP,
|
|
27324
27709
|
authBrowserCommand,
|
|
27325
27710
|
authImportDevCommand,
|
|
@@ -27327,6 +27712,7 @@ export {
|
|
|
27327
27712
|
authSwitchCommand,
|
|
27328
27713
|
buildCliConciergeAppContext,
|
|
27329
27714
|
chatCommand,
|
|
27715
|
+
commandAwaitsPipedInput,
|
|
27330
27716
|
commandNeedsJsonBody,
|
|
27331
27717
|
conciergeCommand,
|
|
27332
27718
|
conciergeOutboundCommand,
|
|
@@ -27371,6 +27757,7 @@ export {
|
|
|
27371
27757
|
parseGlobalOptions,
|
|
27372
27758
|
parsePaginationArgs,
|
|
27373
27759
|
profilesFromDevRealms,
|
|
27760
|
+
readCommandJsonInput,
|
|
27374
27761
|
readJsonInput,
|
|
27375
27762
|
registerPublicDomains,
|
|
27376
27763
|
requireAuth,
|