@vellumai/assistant 0.10.6-dev.202607070156.c1cb3c2 → 0.10.6-dev.202607070525.69af9c2
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/eslint-rules/cli-no-daemon-internals.js +5 -0
- package/openapi.yaml +0 -22
- package/package.json +1 -1
- package/src/__tests__/oauth-commands-routes.test.ts +94 -4
- package/src/__tests__/oauth-store.test.ts +79 -0
- package/src/cli/commands/__tests__/cache.test.ts +16 -10
- package/src/cli/commands/__tests__/inference-send.test.ts +9 -13
- package/src/cli/commands/__tests__/tts.test.ts +15 -8
- package/src/cli/commands/__tests__/ui.test.ts +12 -14
- package/src/cli/commands/cache.ts +2 -9
- package/src/cli/commands/conversations-import.ts +24 -7
- package/src/cli/commands/email.ts +2 -1
- package/src/cli/commands/inference.ts +2 -3
- package/src/cli/commands/oauth/request.ts +21 -5
- package/src/cli/commands/tts.ts +3 -2
- package/src/cli/commands/ui.ts +337 -335
- package/src/config/feature-flag-registry.json +1 -17
- package/src/messaging/providers/gmail/client.ts +10 -0
- package/src/oauth/__tests__/seed-providers-managed.test.ts +10 -0
- package/src/oauth/connection-resolver.test.ts +114 -0
- package/src/oauth/connection-resolver.ts +104 -19
- package/src/oauth/oauth-store.ts +29 -0
- package/src/oauth/seed-providers.ts +30 -2
- package/src/runtime/routes/__tests__/tts-routes.test.ts +36 -169
- package/src/runtime/routes/oauth-commands-routes.ts +47 -3
- package/src/runtime/routes/tts-routes.ts +3 -66
- package/src/tools/terminal/shell.test.ts +34 -0
- package/src/util/__tests__/read-stdin.test.ts +92 -0
- package/src/util/read-stdin.ts +27 -0
- package/src/watcher/providers/gmail.ts +2 -0
|
@@ -25,6 +25,11 @@ const ALLOWED_PREFIXES = {
|
|
|
25
25
|
// deps) — status prints it to surface CLI-vs-runtime version drift.
|
|
26
26
|
"../../version",
|
|
27
27
|
"../../../version",
|
|
28
|
+
// Robust stdin reader (leaf module; only node:fs, no daemon deps) —
|
|
29
|
+
// commands that accept piped payloads read fd 0 through it at depth-1
|
|
30
|
+
// and depth-2.
|
|
31
|
+
"../../util/read-stdin",
|
|
32
|
+
"../../../util/read-stdin",
|
|
28
33
|
// Logger / output at depth-1 and depth-2.
|
|
29
34
|
"../logger",
|
|
30
35
|
"../output",
|
package/openapi.yaml
CHANGED
|
@@ -18874,28 +18874,6 @@ paths:
|
|
|
18874
18874
|
- memoryRecall
|
|
18875
18875
|
- memoryV2Activation
|
|
18876
18876
|
additionalProperties: false
|
|
18877
|
-
/v1/messages/{messageId}/tts:
|
|
18878
|
-
post:
|
|
18879
|
-
operationId: messages_by_messageId_tts_post
|
|
18880
|
-
summary: Synthesize message to speech
|
|
18881
|
-
description: Synthesize a message's text content to audio using the configured TTS provider.
|
|
18882
|
-
tags:
|
|
18883
|
-
- messages
|
|
18884
|
-
parameters:
|
|
18885
|
-
- name: messageId
|
|
18886
|
-
in: path
|
|
18887
|
-
required: true
|
|
18888
|
-
schema:
|
|
18889
|
-
type: string
|
|
18890
|
-
- name: conversationId
|
|
18891
|
-
in: query
|
|
18892
|
-
required: false
|
|
18893
|
-
schema:
|
|
18894
|
-
type: string
|
|
18895
|
-
description: Conversation that contains the message
|
|
18896
|
-
responses:
|
|
18897
|
-
"200":
|
|
18898
|
-
description: Successful response
|
|
18899
18877
|
/v1/messages/lexical/backfill:
|
|
18900
18878
|
post:
|
|
18901
18879
|
operationId: messages_lexical_backfill_post
|
package/package.json
CHANGED
|
@@ -111,14 +111,23 @@ mock.module("../oauth/oauth-store.js", () => ({
|
|
|
111
111
|
listConnections: (provider: string) => mockAllConnections[provider] ?? [],
|
|
112
112
|
}));
|
|
113
113
|
|
|
114
|
-
mock.module("../oauth/connection-resolver.js", () =>
|
|
115
|
-
|
|
114
|
+
mock.module("../oauth/connection-resolver.js", () => {
|
|
115
|
+
const makeConnection = () => ({
|
|
116
|
+
accountInfo: "user@example.com",
|
|
116
117
|
request: async (req: unknown) => {
|
|
117
118
|
mockResolveRequests.push(req);
|
|
118
119
|
return mockResolveResponse;
|
|
119
120
|
},
|
|
120
|
-
})
|
|
121
|
-
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
resolveOAuthConnection: async (_provider: string) => makeConnection(),
|
|
124
|
+
resolveOAuthConnectionWithMeta: async (_provider: string) => ({
|
|
125
|
+
connection: makeConnection(),
|
|
126
|
+
ambiguous: false,
|
|
127
|
+
allAccounts: ["user@example.com"],
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
});
|
|
122
131
|
|
|
123
132
|
mock.module("../oauth/manual-token-connection.js", () => ({
|
|
124
133
|
syncManualTokenConnection: async (provider: string) => {
|
|
@@ -626,6 +635,20 @@ describe("POST oauth/request", () => {
|
|
|
626
635
|
).rejects.toBeInstanceOf(BadRequestError);
|
|
627
636
|
});
|
|
628
637
|
|
|
638
|
+
test("rejects @- stdin body data — daemon stdin is not the caller's", async () => {
|
|
639
|
+
await expect(
|
|
640
|
+
getRoute("POST", "oauth/request").handler(
|
|
641
|
+
makeArgs({
|
|
642
|
+
body: {
|
|
643
|
+
provider: "google",
|
|
644
|
+
url: "https://api.google.com/v1/me",
|
|
645
|
+
data: "@-",
|
|
646
|
+
},
|
|
647
|
+
}),
|
|
648
|
+
),
|
|
649
|
+
).rejects.toBeInstanceOf(BadRequestError);
|
|
650
|
+
});
|
|
651
|
+
|
|
629
652
|
test("happy-path GET returns response payload", async () => {
|
|
630
653
|
mockResolveResponse = {
|
|
631
654
|
status: 200,
|
|
@@ -777,6 +800,73 @@ describe("POST oauth/request", () => {
|
|
|
777
800
|
expect(result.hint).toContain("oauth status");
|
|
778
801
|
});
|
|
779
802
|
|
|
803
|
+
test("attaches wrong-host/path hint on HTML 404 for a relative path", async () => {
|
|
804
|
+
mockResolveResponse = {
|
|
805
|
+
status: 404,
|
|
806
|
+
headers: { "content-type": "text/html; charset=UTF-8" },
|
|
807
|
+
body: "<html><title>Error 404 (Not Found)</title></html>",
|
|
808
|
+
};
|
|
809
|
+
const result = (await getRoute("POST", "oauth/request").handler(
|
|
810
|
+
makeArgs({
|
|
811
|
+
body: {
|
|
812
|
+
provider: "google",
|
|
813
|
+
url: "/calendar/v3/calendars/primary/events",
|
|
814
|
+
},
|
|
815
|
+
}),
|
|
816
|
+
)) as { ok: boolean; status: number; hint?: string };
|
|
817
|
+
expect(result.ok).toBe(false);
|
|
818
|
+
expect(result.status).toBe(404);
|
|
819
|
+
expect(result.hint).toContain("HTML");
|
|
820
|
+
// Reports the resolved base URL the relative path was joined onto.
|
|
821
|
+
expect(result.hint).toContain("https://api.google.com");
|
|
822
|
+
// Steers the caller toward an absolute URL.
|
|
823
|
+
expect(result.hint).toContain("absolute URL");
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
test("does not attach HTML-404 hint when a 404 body is JSON", async () => {
|
|
827
|
+
mockResolveResponse = {
|
|
828
|
+
status: 404,
|
|
829
|
+
headers: { "content-type": "application/json" },
|
|
830
|
+
body: { error: "not found" },
|
|
831
|
+
};
|
|
832
|
+
const result = (await getRoute("POST", "oauth/request").handler(
|
|
833
|
+
makeArgs({
|
|
834
|
+
body: { provider: "google", url: "/v1/missing" },
|
|
835
|
+
}),
|
|
836
|
+
)) as { ok: boolean; status: number; hint?: string };
|
|
837
|
+
expect(result.ok).toBe(false);
|
|
838
|
+
expect(result.status).toBe(404);
|
|
839
|
+
expect(result.hint).toBeUndefined();
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test("HTML-404 hint reports an absolute URL's own host as the resolved base", async () => {
|
|
843
|
+
mockProviders.google = {
|
|
844
|
+
...baseProvider,
|
|
845
|
+
injectionTemplates: JSON.stringify([
|
|
846
|
+
{
|
|
847
|
+
hostPattern: "www.googleapis.com",
|
|
848
|
+
injectionType: "header",
|
|
849
|
+
headerName: "Authorization",
|
|
850
|
+
valuePrefix: "Bearer ",
|
|
851
|
+
},
|
|
852
|
+
]),
|
|
853
|
+
};
|
|
854
|
+
mockResolveResponse = {
|
|
855
|
+
status: 404,
|
|
856
|
+
headers: { "content-type": "text/html" },
|
|
857
|
+
body: "<html>nope</html>",
|
|
858
|
+
};
|
|
859
|
+
const result = (await getRoute("POST", "oauth/request").handler(
|
|
860
|
+
makeArgs({
|
|
861
|
+
body: {
|
|
862
|
+
provider: "google",
|
|
863
|
+
url: "https://www.googleapis.com/calendar/v3/nope",
|
|
864
|
+
},
|
|
865
|
+
}),
|
|
866
|
+
)) as { hint?: string };
|
|
867
|
+
expect(result.hint).toContain("https://www.googleapis.com");
|
|
868
|
+
});
|
|
869
|
+
|
|
780
870
|
test("rejects unregistered client_id in BYO mode", async () => {
|
|
781
871
|
// No entry in mockApps for google:client-x
|
|
782
872
|
await expect(
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
isProviderConnected,
|
|
57
57
|
listActiveConnectionsByProvider,
|
|
58
58
|
listConnections,
|
|
59
|
+
migrateProviderBaseUrl,
|
|
59
60
|
registerProvider,
|
|
60
61
|
seedProviders,
|
|
61
62
|
updateConnection,
|
|
@@ -583,6 +584,84 @@ describe("provider operations", () => {
|
|
|
583
584
|
expect(outlook!.revokeUrl).toBeNull();
|
|
584
585
|
});
|
|
585
586
|
|
|
587
|
+
test("seedOAuthProviders seeds google with a host-only base URL", () => {
|
|
588
|
+
seedOAuthProviders();
|
|
589
|
+
const google = getProvider("google");
|
|
590
|
+
expect(google!.baseUrl).toBe("https://www.googleapis.com");
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test("seedOAuthProviders advances a stale gmail-scoped google base URL to the host-only default", () => {
|
|
594
|
+
// Simulate a pre-existing install seeded with the old mailbox-scoped base
|
|
595
|
+
// URL, then preserved by seedProviders' COALESCE on subsequent startups.
|
|
596
|
+
seedProviders([
|
|
597
|
+
{
|
|
598
|
+
provider: "google",
|
|
599
|
+
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
600
|
+
tokenExchangeUrl: "https://oauth2.googleapis.com/token",
|
|
601
|
+
baseUrl: "https://gmail.googleapis.com/gmail/v1/users/me",
|
|
602
|
+
defaultScopes: [],
|
|
603
|
+
},
|
|
604
|
+
]);
|
|
605
|
+
expect(getProvider("google")!.baseUrl).toBe(
|
|
606
|
+
"https://gmail.googleapis.com/gmail/v1/users/me",
|
|
607
|
+
);
|
|
608
|
+
|
|
609
|
+
seedOAuthProviders();
|
|
610
|
+
|
|
611
|
+
expect(getProvider("google")!.baseUrl).toBe("https://www.googleapis.com");
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test("seedOAuthProviders leaves a user-customized google base URL untouched", () => {
|
|
615
|
+
seedProviders([
|
|
616
|
+
{
|
|
617
|
+
provider: "google",
|
|
618
|
+
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
619
|
+
tokenExchangeUrl: "https://oauth2.googleapis.com/token",
|
|
620
|
+
baseUrl: "https://proxy.internal.example/google",
|
|
621
|
+
defaultScopes: [],
|
|
622
|
+
},
|
|
623
|
+
]);
|
|
624
|
+
|
|
625
|
+
seedOAuthProviders();
|
|
626
|
+
|
|
627
|
+
expect(getProvider("google")!.baseUrl).toBe(
|
|
628
|
+
"https://proxy.internal.example/google",
|
|
629
|
+
);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
test("migrateProviderBaseUrl only rewrites rows holding the stale value", () => {
|
|
633
|
+
seedProviders([
|
|
634
|
+
{
|
|
635
|
+
provider: "test-provider",
|
|
636
|
+
authorizeUrl: "https://example.com/authorize",
|
|
637
|
+
tokenExchangeUrl: "https://example.com/token",
|
|
638
|
+
baseUrl: "https://old.example.com",
|
|
639
|
+
defaultScopes: [],
|
|
640
|
+
},
|
|
641
|
+
]);
|
|
642
|
+
|
|
643
|
+
const changed = migrateProviderBaseUrl({
|
|
644
|
+
provider: "test-provider",
|
|
645
|
+
staleBaseUrl: "https://old.example.com",
|
|
646
|
+
nextBaseUrl: "https://new.example.com",
|
|
647
|
+
});
|
|
648
|
+
expect(changed).toBe(1);
|
|
649
|
+
expect(getProvider("test-provider")!.baseUrl).toBe(
|
|
650
|
+
"https://new.example.com",
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
// Idempotent: a second run matches nothing.
|
|
654
|
+
const changedAgain = migrateProviderBaseUrl({
|
|
655
|
+
provider: "test-provider",
|
|
656
|
+
staleBaseUrl: "https://old.example.com",
|
|
657
|
+
nextBaseUrl: "https://new.example.com",
|
|
658
|
+
});
|
|
659
|
+
expect(changedAgain).toBe(0);
|
|
660
|
+
expect(getProvider("test-provider")!.baseUrl).toBe(
|
|
661
|
+
"https://new.example.com",
|
|
662
|
+
);
|
|
663
|
+
});
|
|
664
|
+
|
|
586
665
|
test("applies client_secret_post default when tokenEndpointAuthMethod is omitted from seed", () => {
|
|
587
666
|
seedProviders([
|
|
588
667
|
{
|
|
@@ -88,25 +88,31 @@ mock.module("../../../util/logger.js", () => ({
|
|
|
88
88
|
}));
|
|
89
89
|
|
|
90
90
|
mock.module("../../lib/cache-fs.js", () => ({
|
|
91
|
+
// File reads (`--file`) resolve real paths. Stdin never flows through here:
|
|
92
|
+
// reopening "/dev/stdin" fails ENXIO for pipe read-ends, so any regression
|
|
93
|
+
// to path-based stdin reading trips this loud throw.
|
|
91
94
|
readFileSync: (path: string | number, encoding?: BufferEncoding) => {
|
|
92
|
-
// Stdin must be read via fd 0, not by reopening "/dev/stdin": a spawned
|
|
93
|
-
// subprocess whose stdin is a pipe (Bun.spawn stdin:"pipe") cannot reopen
|
|
94
|
-
// its read-end by path — open("/dev/stdin") fails ENXIO. Throwing here on
|
|
95
|
-
// the path makes any regression to path-based reading fail loudly.
|
|
96
95
|
if (path === "/dev/stdin") {
|
|
97
96
|
throw new Error("ENXIO: no such device or address, open '/dev/stdin'");
|
|
98
97
|
}
|
|
99
|
-
if (path === 0) {
|
|
100
|
-
if (mockStdinContent === null) {
|
|
101
|
-
throw new Error("EAGAIN: resource temporarily unavailable");
|
|
102
|
-
}
|
|
103
|
-
return mockStdinContent;
|
|
104
|
-
}
|
|
105
98
|
return actualReadFileSync(path, encoding);
|
|
106
99
|
},
|
|
107
100
|
existsSync: actualExistsSync,
|
|
108
101
|
}));
|
|
109
102
|
|
|
103
|
+
// Stdin is read via fd 0 through the shared helper, never by reopening
|
|
104
|
+
// "/dev/stdin". Returning the simulated content exercises the piped path;
|
|
105
|
+
// a null content simulates stdin with no readable data.
|
|
106
|
+
mock.module("../../../util/read-stdin.js", () => ({
|
|
107
|
+
STDIN_FD: 0,
|
|
108
|
+
readStdinSync: () => {
|
|
109
|
+
if (mockStdinContent === null) {
|
|
110
|
+
throw new Error("EAGAIN: resource temporarily unavailable");
|
|
111
|
+
}
|
|
112
|
+
return mockStdinContent;
|
|
113
|
+
},
|
|
114
|
+
}));
|
|
115
|
+
|
|
110
116
|
// ---------------------------------------------------------------------------
|
|
111
117
|
// Import module under test (after mocks)
|
|
112
118
|
// ---------------------------------------------------------------------------
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
* request contract without opening an assistant socket.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
existsSync as actualExistsSync,
|
|
15
|
-
readFileSync as actualReadFileSync,
|
|
16
|
-
} from "node:fs";
|
|
17
13
|
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
18
14
|
|
|
19
15
|
import { Command } from "commander";
|
|
@@ -89,17 +85,17 @@ mock.module("../../../util/logger.js", () => ({
|
|
|
89
85
|
}),
|
|
90
86
|
}));
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
// Stdin is read via fd 0 through the shared helper, never by reopening
|
|
89
|
+
// "/dev/stdin" (which fails ENXIO for pipe read-ends). A null content
|
|
90
|
+
// simulates stdin with no readable data.
|
|
91
|
+
mock.module("../../../util/read-stdin.js", () => ({
|
|
92
|
+
STDIN_FD: 0,
|
|
93
|
+
readStdinSync: () => {
|
|
94
|
+
if (mockStdinContent === null) {
|
|
95
|
+
throw new Error("EAGAIN: resource temporarily unavailable");
|
|
99
96
|
}
|
|
100
|
-
return
|
|
97
|
+
return mockStdinContent;
|
|
101
98
|
},
|
|
102
|
-
existsSync: actualExistsSync,
|
|
103
99
|
}));
|
|
104
100
|
|
|
105
101
|
const { registerInferenceCommand } = await import("../inference.js");
|
|
@@ -62,18 +62,21 @@ mock.module("../../logger.js", () => ({
|
|
|
62
62
|
mock.module("node:fs", () => ({
|
|
63
63
|
existsSync: () => true,
|
|
64
64
|
mkdirSync: () => {},
|
|
65
|
-
readFileSync: (path: string) => {
|
|
66
|
-
if (path === "/dev/stdin") {
|
|
67
|
-
if (stdinReturnsText) return "piped text";
|
|
68
|
-
throw new Error("stdin unavailable");
|
|
69
|
-
}
|
|
70
|
-
throw new Error("unexpected readFileSync call");
|
|
71
|
-
},
|
|
72
65
|
writeFileSync: (path: string, data: Buffer) => {
|
|
73
66
|
writeFileCalls.push({ path, data });
|
|
74
67
|
},
|
|
75
68
|
}));
|
|
76
69
|
|
|
70
|
+
// Stdin is read via fd 0 through the shared helper, never by reopening
|
|
71
|
+
// "/dev/stdin" (which fails ENXIO for pipe read-ends).
|
|
72
|
+
mock.module("../../../util/read-stdin.js", () => ({
|
|
73
|
+
STDIN_FD: 0,
|
|
74
|
+
readStdinSync: () => {
|
|
75
|
+
if (stdinReturnsText) return "piped text";
|
|
76
|
+
throw new Error("stdin unavailable");
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
|
|
77
80
|
// ---------------------------------------------------------------------------
|
|
78
81
|
// Import module under test (after mocks)
|
|
79
82
|
// ---------------------------------------------------------------------------
|
|
@@ -140,7 +143,11 @@ async function runCommand(
|
|
|
140
143
|
const exitCode = process.exitCode ?? 0;
|
|
141
144
|
process.exitCode = 0;
|
|
142
145
|
|
|
143
|
-
return {
|
|
146
|
+
return {
|
|
147
|
+
exitCode,
|
|
148
|
+
stdout: localStdout.join(""),
|
|
149
|
+
stderr: localStderr.join(""),
|
|
150
|
+
};
|
|
144
151
|
}
|
|
145
152
|
|
|
146
153
|
// ---------------------------------------------------------------------------
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
* - Exit code behavior on IPC errors
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
existsSync as actualExistsSync,
|
|
16
|
-
readFileSync as actualReadFileSync,
|
|
17
|
-
} from "node:fs";
|
|
18
14
|
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
19
15
|
|
|
20
16
|
import { Command } from "commander";
|
|
@@ -83,17 +79,17 @@ mock.module("../../../util/logger.js", () => ({
|
|
|
83
79
|
}),
|
|
84
80
|
}));
|
|
85
81
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
// Stdin is read via fd 0 through the shared helper, never by reopening
|
|
83
|
+
// "/dev/stdin" (which fails ENXIO for pipe read-ends). A null content
|
|
84
|
+
// simulates stdin with no readable data.
|
|
85
|
+
mock.module("../../../util/read-stdin.js", () => ({
|
|
86
|
+
STDIN_FD: 0,
|
|
87
|
+
readStdinSync: () => {
|
|
88
|
+
if (mockStdinContent === null) {
|
|
89
|
+
throw new Error("EAGAIN: resource temporarily unavailable");
|
|
93
90
|
}
|
|
94
|
-
return
|
|
91
|
+
return mockStdinContent;
|
|
95
92
|
},
|
|
96
|
-
existsSync: actualExistsSync,
|
|
97
93
|
}));
|
|
98
94
|
|
|
99
95
|
// ---------------------------------------------------------------------------
|
|
@@ -743,7 +739,9 @@ describe("ui request — --actions parsing", () => {
|
|
|
743
739
|
]);
|
|
744
740
|
|
|
745
741
|
expect(exitCode).toBe(0);
|
|
746
|
-
expect(lastIpcCall!.params.body.actions).toEqual([
|
|
742
|
+
expect(lastIpcCall!.params.body.actions).toEqual([
|
|
743
|
+
{ id: "ok", label: "OK" },
|
|
744
|
+
]);
|
|
747
745
|
});
|
|
748
746
|
|
|
749
747
|
test("actions are omitted from IPC params when --actions is not provided", async () => {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { Command } from "commander";
|
|
9
9
|
|
|
10
10
|
import { cliIpcCall } from "../../ipc/cli-client.js";
|
|
11
|
+
import { readStdinSync } from "../../util/read-stdin.js";
|
|
11
12
|
import { existsSync, readFileSync } from "../lib/cache-fs.js";
|
|
12
13
|
import { registerCommand } from "../lib/register-command.js";
|
|
13
14
|
import { log } from "../logger.js";
|
|
@@ -17,9 +18,6 @@ import { log } from "../logger.js";
|
|
|
17
18
|
/** Warn (stderr) when a raw payload exceeds this byte count. */
|
|
18
19
|
const MAX_PAYLOAD_BYTES = 1_000_000; // 1 MB
|
|
19
20
|
|
|
20
|
-
/** Standard input file descriptor. */
|
|
21
|
-
const STDIN_FD = 0;
|
|
22
|
-
|
|
23
21
|
// ── TTL parsing ───────────────────────────────────────────────────────
|
|
24
22
|
|
|
25
23
|
const TTL_PATTERN = /^(\d+(?:\.\d+)?)\s*(ms|s|m|h)$/;
|
|
@@ -102,11 +100,6 @@ function parseJsonPayload(raw: string, source: string): unknown {
|
|
|
102
100
|
* Read JSON payload from stdin when piped. Throws when stdin is a TTY
|
|
103
101
|
* (no piped input) or when the input is empty/invalid JSON, so the CLI
|
|
104
102
|
* can surface actionable parse errors.
|
|
105
|
-
*
|
|
106
|
-
* Reads file descriptor 0 directly rather than reopening the `/dev/stdin`
|
|
107
|
-
* path. When the caller is a spawned subprocess whose stdin is a pipe (e.g.
|
|
108
|
-
* `Bun.spawn(..., { stdin: "pipe" })`), `open("/dev/stdin")` fails with ENXIO
|
|
109
|
-
* because a pipe read-end cannot be reopened by path; the fd is readable.
|
|
110
103
|
*/
|
|
111
104
|
function readPayloadFromStdin(): unknown {
|
|
112
105
|
if (process.stdin.isTTY) {
|
|
@@ -119,7 +112,7 @@ function readPayloadFromStdin(): unknown {
|
|
|
119
112
|
|
|
120
113
|
let raw: string;
|
|
121
114
|
try {
|
|
122
|
-
raw =
|
|
115
|
+
raw = readStdinSync();
|
|
123
116
|
} catch (err) {
|
|
124
117
|
throw new Error(
|
|
125
118
|
`Failed to read stdin: ${err instanceof Error ? err.message : String(err)}.\n` +
|
|
@@ -3,6 +3,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
3
3
|
import type { Command } from "commander";
|
|
4
4
|
|
|
5
5
|
import { cliIpcCall, exitFromIpcResult } from "../../ipc/cli-client.js";
|
|
6
|
+
import { readStdinSync } from "../../util/read-stdin.js";
|
|
6
7
|
import { registerCommand } from "../lib/register-command.js";
|
|
7
8
|
import { log } from "../logger.js";
|
|
8
9
|
|
|
@@ -51,7 +52,9 @@ function validatePayload(raw: unknown): ImportPayload {
|
|
|
51
52
|
for (let i = 0; i < obj.conversations.length; i++) {
|
|
52
53
|
const conv = obj.conversations[i] as Record<string, unknown>;
|
|
53
54
|
if (!conv.title || typeof conv.title !== "string") {
|
|
54
|
-
throw new Error(
|
|
55
|
+
throw new Error(
|
|
56
|
+
`conversations[${i}].title is required and must be a string`,
|
|
57
|
+
);
|
|
55
58
|
}
|
|
56
59
|
if (!Array.isArray(conv.messages) || conv.messages.length === 0) {
|
|
57
60
|
throw new Error(`conversations[${i}].messages must be a non-empty array`);
|
|
@@ -62,7 +65,9 @@ function validatePayload(raw: unknown): ImportPayload {
|
|
|
62
65
|
throw new Error(`conversations[${i}].messages[${j}].role is required`);
|
|
63
66
|
}
|
|
64
67
|
if (msg.content === undefined || msg.content === null) {
|
|
65
|
-
throw new Error(
|
|
68
|
+
throw new Error(
|
|
69
|
+
`conversations[${i}].messages[${j}].content is required`,
|
|
70
|
+
);
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
}
|
|
@@ -71,7 +76,9 @@ function validatePayload(raw: unknown): ImportPayload {
|
|
|
71
76
|
|
|
72
77
|
// -- CLI registration --
|
|
73
78
|
|
|
74
|
-
export function registerConversationsImportCommand(
|
|
79
|
+
export function registerConversationsImportCommand(
|
|
80
|
+
conversations: Command,
|
|
81
|
+
): void {
|
|
75
82
|
registerCommand(conversations, {
|
|
76
83
|
name: "import",
|
|
77
84
|
transport: "ipc",
|
|
@@ -119,7 +126,7 @@ Examples:
|
|
|
119
126
|
"No input provided. Pipe JSON into stdin or use --file <path>.",
|
|
120
127
|
);
|
|
121
128
|
}
|
|
122
|
-
raw =
|
|
129
|
+
raw = readStdinSync();
|
|
123
130
|
}
|
|
124
131
|
} catch (err) {
|
|
125
132
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -158,9 +165,17 @@ Examples:
|
|
|
158
165
|
}
|
|
159
166
|
|
|
160
167
|
const r = await cliIpcCall<ImportResult>("conversations_import", {
|
|
161
|
-
body: {
|
|
168
|
+
body: {
|
|
169
|
+
conversations: payload.conversations as unknown as Record<
|
|
170
|
+
string,
|
|
171
|
+
unknown
|
|
172
|
+
>[],
|
|
173
|
+
},
|
|
162
174
|
});
|
|
163
|
-
if (!r.ok)
|
|
175
|
+
if (!r.ok)
|
|
176
|
+
return exitFromIpcResult(
|
|
177
|
+
r as { ok: false; error?: string; statusCode?: number },
|
|
178
|
+
);
|
|
164
179
|
|
|
165
180
|
const result = r.result!;
|
|
166
181
|
if (opts.json) {
|
|
@@ -170,7 +185,9 @@ Examples:
|
|
|
170
185
|
`Imported ${result.imported} conversation(s) with ${result.messages} message(s).`,
|
|
171
186
|
];
|
|
172
187
|
if (result.skipped > 0) {
|
|
173
|
-
lines.push(
|
|
188
|
+
lines.push(
|
|
189
|
+
`Skipped ${result.skipped} already-imported conversation(s).`,
|
|
190
|
+
);
|
|
174
191
|
}
|
|
175
192
|
if (result.errors.length > 0) {
|
|
176
193
|
lines.push(`Failed: ${result.errors.length} conversation(s).`);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
cliIpcCallStream,
|
|
15
15
|
exitFromIpcResult,
|
|
16
16
|
} from "../../ipc/cli-client.js";
|
|
17
|
+
import { readStdinSync } from "../../util/read-stdin.js";
|
|
17
18
|
import { registerCommand } from "../lib/register-command.js";
|
|
18
19
|
import { getCliLogger } from "../logger.js";
|
|
19
20
|
import { shouldOutputJson, writeOutput } from "../output.js";
|
|
@@ -513,7 +514,7 @@ Examples:
|
|
|
513
514
|
}
|
|
514
515
|
if (!text && !process.stdin.isTTY) {
|
|
515
516
|
try {
|
|
516
|
-
text =
|
|
517
|
+
text = readStdinSync();
|
|
517
518
|
} catch (err) {
|
|
518
519
|
log.error(
|
|
519
520
|
`Failed to read body from stdin: ${err instanceof Error ? err.message : String(err)}`,
|
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
* The `llm` alias exposes only `send`.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { readFileSync } from "node:fs";
|
|
13
|
-
|
|
14
12
|
import type { Command } from "commander";
|
|
15
13
|
|
|
16
14
|
import { cliIpcCall } from "../../ipc/cli-client.js";
|
|
15
|
+
import { readStdinSync } from "../../util/read-stdin.js";
|
|
17
16
|
import { registerCommand } from "../lib/register-command.js";
|
|
18
17
|
import { log } from "../logger.js";
|
|
19
18
|
import { attachProvidersSubcommand } from "./inference-providers.js";
|
|
@@ -168,7 +167,7 @@ Examples:
|
|
|
168
167
|
|
|
169
168
|
if (!messageText && !process.stdin.isTTY) {
|
|
170
169
|
try {
|
|
171
|
-
messageText =
|
|
170
|
+
messageText = readStdinSync().trim();
|
|
172
171
|
} catch {
|
|
173
172
|
// stdin not available or empty
|
|
174
173
|
}
|
|
@@ -3,6 +3,7 @@ import { readFileSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import type { Command } from "commander";
|
|
4
4
|
|
|
5
5
|
import { cliIpcCall, exitFromIpcResult } from "../../../ipc/cli-client.js";
|
|
6
|
+
import { readStdinSync } from "../../../util/read-stdin.js";
|
|
6
7
|
import { shouldOutputJson, writeOutput } from "../../output.js";
|
|
7
8
|
|
|
8
9
|
// ---------------------------------------------------------------------------
|
|
@@ -55,7 +56,7 @@ function tryJsonParse(raw: string): unknown {
|
|
|
55
56
|
*/
|
|
56
57
|
function readBodyData(data: string): unknown {
|
|
57
58
|
if (data === "@-") {
|
|
58
|
-
const raw =
|
|
59
|
+
const raw = readStdinSync();
|
|
59
60
|
return tryJsonParse(raw);
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -109,9 +110,14 @@ the token (using \`assistant oauth token\`) and making the request directly.
|
|
|
109
110
|
This command resolves the OAuth connection automatically (regardless of whether
|
|
110
111
|
the provider's mode is set to "managed" or "your-own") and injects tokens transparently.
|
|
111
112
|
|
|
112
|
-
URL can be absolute (https://api.
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
URL can be absolute (https://api.x.com/2/tweets) or relative (/2/tweets).
|
|
114
|
+
An absolute URL sets the host and full path explicitly. A relative path is
|
|
115
|
+
joined onto the provider's configured default base URL — the base URL shown by
|
|
116
|
+
'assistant oauth providers get <provider>'. For providers whose default base
|
|
117
|
+
URL points at one specific service, a relative path for a different service on
|
|
118
|
+
the same provider will resolve against the wrong host or path and fail (often
|
|
119
|
+
with an opaque HTML 404). When in doubt, pass an absolute URL: it is the safe
|
|
120
|
+
form for any service other than the provider's default.
|
|
115
121
|
|
|
116
122
|
Note: The Authorization header is set automatically. User-supplied
|
|
117
123
|
-H "Authorization: ..." will be overridden by the OAuth bearer token.
|
|
@@ -120,7 +126,7 @@ Examples:
|
|
|
120
126
|
$ assistant oauth request --provider twitter https://api.x.com/2/tweets
|
|
121
127
|
$ assistant oauth request --provider google /gmail/v1/users/me/messages -G
|
|
122
128
|
$ assistant oauth request --provider twitter -X POST -d '{"text":"Hello"}' https://api.x.com/2/tweets
|
|
123
|
-
$ assistant oauth request --provider google
|
|
129
|
+
$ assistant oauth request --provider google https://www.googleapis.com/calendar/v3/calendars/primary/events
|
|
124
130
|
$ assistant oauth request --provider slack -H "Content-Type: application/json" -d '{"channel":"C123"}' /api/chat.postMessage --json`,
|
|
125
131
|
)
|
|
126
132
|
.action(
|
|
@@ -216,6 +222,8 @@ Examples:
|
|
|
216
222
|
headers: Record<string, string>;
|
|
217
223
|
body: unknown;
|
|
218
224
|
hint?: string;
|
|
225
|
+
account?: string | null;
|
|
226
|
+
accountWarning?: string;
|
|
219
227
|
}>("oauth_request", { body });
|
|
220
228
|
|
|
221
229
|
if (!r.ok) return exitFromIpcResult(r);
|
|
@@ -227,6 +235,14 @@ Examples:
|
|
|
227
235
|
process.exitCode = 1;
|
|
228
236
|
}
|
|
229
237
|
|
|
238
|
+
// Which account served the request, and any multi-account ambiguity.
|
|
239
|
+
if (result.account) {
|
|
240
|
+
writeInfo(`* Account: ${result.account}`);
|
|
241
|
+
}
|
|
242
|
+
if (result.accountWarning) {
|
|
243
|
+
writeInfo(result.accountWarning);
|
|
244
|
+
}
|
|
245
|
+
|
|
230
246
|
// Auth hint
|
|
231
247
|
if (result.hint) {
|
|
232
248
|
writeInfo(result.hint);
|