@vibesdotdev/integrations-grok 0.0.0-stage → 1.0.0-rc.1
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/LICENSE +126 -0
- package/README.md +43 -2
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-3-mini.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-3.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-4-5.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-4-6.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-4-7.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-4-fast.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-4.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-code-fast.json +18 -0
- package/dist/ai/metadata/provider-models/grok/grok-grok-composer-2-5-fast.json +18 -0
- package/dist/ai/metadata/providers/grok.json +8 -0
- package/dist/ai/provider.consumer.plugin.d.ts +11 -0
- package/dist/ai/provider.consumer.plugin.d.ts.map +1 -0
- package/dist/ai/provider.consumer.plugin.js +43 -0
- package/dist/ai/provider.consumer.plugin.js.map +1 -0
- package/dist/ai/provider.plugin.d.ts +3 -0
- package/dist/ai/provider.plugin.d.ts.map +1 -0
- package/dist/ai/provider.plugin.js +3 -0
- package/dist/ai/provider.plugin.js.map +1 -0
- package/dist/ai/provider.shared.plugin.d.ts +6 -0
- package/dist/ai/provider.shared.plugin.d.ts.map +1 -0
- package/dist/ai/provider.shared.plugin.js +118 -0
- package/dist/ai/provider.shared.plugin.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/config/config.grok.descriptor.d.ts +4194 -0
- package/dist/ai/providers/cloud/frontier/grok/config/config.grok.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/config/config.grok.descriptor.js +15 -0
- package/dist/ai/providers/cloud/frontier/grok/config/config.grok.descriptor.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/config/schemas/index.d.ts +67 -0
- package/dist/ai/providers/cloud/frontier/grok/config/schemas/index.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/config/schemas/index.js +70 -0
- package/dist/ai/providers/cloud/frontier/grok/config/schemas/index.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/index.d.ts +5 -0
- package/dist/ai/providers/cloud/frontier/grok/index.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/index.js +4 -0
- package/dist/ai/providers/cloud/frontier/grok/index.js.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/provider.grok.descriptor.d.ts +183 -0
- package/dist/ai/providers/cloud/frontier/grok/provider.grok.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/cloud/frontier/grok/provider.grok.descriptor.js +114 -0
- package/dist/ai/providers/cloud/frontier/grok/provider.grok.descriptor.js.map +1 -0
- package/dist/ai/providers/grok/detection/index.d.ts +2 -0
- package/dist/ai/providers/grok/detection/index.d.ts.map +1 -0
- package/dist/ai/providers/grok/detection/index.js +2 -0
- package/dist/ai/providers/grok/detection/index.js.map +1 -0
- package/dist/ai/providers/grok/detection/system.d.ts +11 -0
- package/dist/ai/providers/grok/detection/system.d.ts.map +1 -0
- package/dist/ai/providers/grok/detection/system.js +78 -0
- package/dist/ai/providers/grok/detection/system.js.map +1 -0
- package/dist/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.d.ts +4 -0
- package/dist/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.js +21 -0
- package/dist/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/budget.d.ts +14 -0
- package/dist/ai/providers/grok/grok-agent/budget.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/budget.js +23 -0
- package/dist/ai/providers/grok/grok-agent/budget.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/connection.d.ts +36 -0
- package/dist/ai/providers/grok/grok-agent/connection.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/connection.js +137 -0
- package/dist/ai/providers/grok/grok-agent/connection.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/failures.d.ts +12 -0
- package/dist/ai/providers/grok/grok-agent/failures.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/failures.js +47 -0
- package/dist/ai/providers/grok/grok-agent/failures.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.d.ts +29 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.js +18 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.impl.d.ts +32 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.impl.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.impl.js +113 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.spec.impl.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.descriptor.d.ts +13 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.descriptor.js +11 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.descriptor.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.impl.consumer.d.ts +39 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.impl.consumer.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.impl.consumer.js +79 -0
- package/dist/ai/providers/grok/grok-agent/grok-agent.transport.impl.consumer.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/protocol.d.ts +117 -0
- package/dist/ai/providers/grok/grok-agent/protocol.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/protocol.js +84 -0
- package/dist/ai/providers/grok/grok-agent/protocol.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/runtime-execution.d.ts +14 -0
- package/dist/ai/providers/grok/grok-agent/runtime-execution.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/runtime-execution.js +42 -0
- package/dist/ai/providers/grok/grok-agent/runtime-execution.js.map +1 -0
- package/dist/ai/providers/grok/grok-agent/session.d.ts +12 -0
- package/dist/ai/providers/grok/grok-agent/session.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-agent/session.js +140 -0
- package/dist/ai/providers/grok/grok-agent/session.js.map +1 -0
- package/dist/ai/providers/grok/grok-build.request.d.ts +7 -0
- package/dist/ai/providers/grok/grok-build.request.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-build.request.js +11 -0
- package/dist/ai/providers/grok/grok-build.request.js.map +1 -0
- package/dist/ai/providers/grok/grok-build.transport.descriptor.d.ts +13 -0
- package/dist/ai/providers/grok/grok-build.transport.descriptor.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-build.transport.descriptor.js +11 -0
- package/dist/ai/providers/grok/grok-build.transport.descriptor.js.map +1 -0
- package/dist/ai/providers/grok/grok-build.transport.impl.consumer.d.ts +23 -0
- package/dist/ai/providers/grok/grok-build.transport.impl.consumer.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-build.transport.impl.consumer.js +115 -0
- package/dist/ai/providers/grok/grok-build.transport.impl.consumer.js.map +1 -0
- package/dist/ai/providers/grok/grok-prompt-file.d.ts +16 -0
- package/dist/ai/providers/grok/grok-prompt-file.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-prompt-file.js +43 -0
- package/dist/ai/providers/grok/grok-prompt-file.js.map +1 -0
- package/dist/ai/providers/grok/grok-refusals.d.ts +149 -0
- package/dist/ai/providers/grok/grok-refusals.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-refusals.js +159 -0
- package/dist/ai/providers/grok/grok-refusals.js.map +1 -0
- package/dist/ai/providers/grok/grok-sandbox-signal.d.ts +30 -0
- package/dist/ai/providers/grok/grok-sandbox-signal.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-sandbox-signal.js +46 -0
- package/dist/ai/providers/grok/grok-sandbox-signal.js.map +1 -0
- package/dist/ai/providers/grok/grok-subscription.d.ts +116 -0
- package/dist/ai/providers/grok/grok-subscription.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok-subscription.js +473 -0
- package/dist/ai/providers/grok/grok-subscription.js.map +1 -0
- package/dist/ai/providers/grok/grok.provider.impl.d.ts +47 -0
- package/dist/ai/providers/grok/grok.provider.impl.d.ts.map +1 -0
- package/dist/ai/providers/grok/grok.provider.impl.js +202 -0
- package/dist/ai/providers/grok/grok.provider.impl.js.map +1 -0
- package/dist/ai/providers/grok/index.d.ts +3 -0
- package/dist/ai/providers/grok/index.d.ts.map +1 -0
- package/dist/ai/providers/grok/index.js +3 -0
- package/dist/ai/providers/grok/index.js.map +1 -0
- package/dist/ai/providers/grok/recommendations.d.ts +23 -0
- package/dist/ai/providers/grok/recommendations.d.ts.map +1 -0
- package/dist/ai/providers/grok/recommendations.js +21 -0
- package/dist/ai/providers/grok/recommendations.js.map +1 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.descriptor.d.ts +32 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.descriptor.d.ts.map +1 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.descriptor.js +21 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.descriptor.js.map +1 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.impl.d.ts +36 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.impl.d.ts.map +1 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.impl.js +78 -0
- package/dist/ai/specs/grok-build-exec/grok-build-exec.spec.impl.js.map +1 -0
- package/dist/ai/specs/grok-messages.d.ts +20 -0
- package/dist/ai/specs/grok-messages.d.ts.map +1 -0
- package/dist/ai/specs/grok-messages.js +79 -0
- package/dist/ai/specs/grok-messages.js.map +1 -0
- package/dist/external/external.plugin.d.ts +3 -0
- package/dist/external/external.plugin.d.ts.map +1 -0
- package/dist/external/external.plugin.js +23 -0
- package/dist/external/external.plugin.js.map +1 -0
- package/dist/external/grok-build/index.d.ts +162 -0
- package/dist/external/grok-build/index.d.ts.map +1 -0
- package/dist/external/grok-build/index.js +7 -0
- package/dist/external/grok-build/index.js.map +1 -0
- package/dist/external/grok-build/manifest.d.ts +6 -0
- package/dist/external/grok-build/manifest.d.ts.map +1 -0
- package/dist/external/grok-build/manifest.js +91 -0
- package/dist/external/grok-build/manifest.js.map +1 -0
- package/dist/external/grok-build-presets.d.ts +210 -0
- package/dist/external/grok-build-presets.d.ts.map +1 -0
- package/dist/external/grok-build-presets.js +46 -0
- package/dist/external/grok-build-presets.js.map +1 -0
- package/dist/external/grok-subscription.operation.descriptors.d.ts +57 -0
- package/dist/external/grok-subscription.operation.descriptors.d.ts.map +1 -0
- package/dist/external/grok-subscription.operation.descriptors.js +22 -0
- package/dist/external/grok-subscription.operation.descriptors.js.map +1 -0
- package/dist/external/grok-subscription.operations.d.ts +4 -0
- package/dist/external/grok-subscription.operations.d.ts.map +1 -0
- package/dist/external/grok-subscription.operations.js +73 -0
- package/dist/external/grok-subscription.operations.js.map +1 -0
- package/dist/external/index.d.ts +3 -0
- package/dist/external/index.d.ts.map +1 -0
- package/dist/external/index.js +3 -0
- package/dist/external/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/outcome.d.ts +9 -0
- package/dist/outcome.d.ts.map +1 -0
- package/dist/outcome.js +8 -0
- package/dist/outcome.js.map +1 -0
- package/dist/schemas/health.d.ts +20 -0
- package/dist/schemas/health.d.ts.map +1 -0
- package/dist/schemas/health.js +17 -0
- package/dist/schemas/health.js.map +1 -0
- package/dist/schemas/output.d.ts +8 -0
- package/dist/schemas/output.d.ts.map +1 -0
- package/dist/schemas/output.js +10 -0
- package/dist/schemas/output.js.map +1 -0
- package/dist/schemas/refusal.d.ts +6 -0
- package/dist/schemas/refusal.d.ts.map +1 -0
- package/dist/schemas/refusal.js +6 -0
- package/dist/schemas/refusal.js.map +1 -0
- package/dist/schemas/subscription.d.ts +42 -0
- package/dist/schemas/subscription.d.ts.map +1 -0
- package/dist/schemas/subscription.js +36 -0
- package/dist/schemas/subscription.js.map +1 -0
- package/package.json +104 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type GrokSubscriptionCode } from '../../../schemas/subscription.ts';
|
|
2
|
+
import { CapabilityError, type RuntimeRef } from '@vibesdotdev/kernel';
|
|
3
|
+
import { type ExecuteResult, type ExecutionOutputLine, type RuntimeExecution } from '@vibesdotdev/kernel/execution';
|
|
4
|
+
import type { FileSystemAdapterInterface } from '@vibesdotdev/filesystem';
|
|
5
|
+
import { type Failure } from '../../../outcome.ts';
|
|
6
|
+
/**
|
|
7
|
+
* Terminal sign-in for the dedicated profile. The external CLI projector owns
|
|
8
|
+
* the command; this package does not register an `ai` group of its own.
|
|
9
|
+
*/
|
|
10
|
+
export declare const GROK_SUBSCRIPTION_LOGIN_COMMAND = "vibes dev external grok login";
|
|
11
|
+
/** Read-only check of that same profile. */
|
|
12
|
+
export declare const GROK_SUBSCRIPTION_STATUS_COMMAND = "vibes dev external grok status";
|
|
13
|
+
/**
|
|
14
|
+
* A device-code sign-in is a person walking to a browser, reading a code, and
|
|
15
|
+
* confirming it. Five minutes is the wait Grok's own flow expects.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GROK_SUBSCRIPTION_LOGIN_TIMEOUT_MS = 300000;
|
|
18
|
+
/** Every way a subscription operation refuses or fails, by the stable Grok code the surfaces report. */
|
|
19
|
+
export type { GrokSubscriptionCode } from '../../../schemas/subscription.ts';
|
|
20
|
+
/** The `NOT_FOUND` subject kind of the three states in which this host offers no Grok subscription. */
|
|
21
|
+
export declare const GROK_SUBSCRIPTION_KIND = "grok-subscription";
|
|
22
|
+
/**
|
|
23
|
+
* Confirmed absences of the subscription on a host, by subject id: no consumer
|
|
24
|
+
* runtime to run it on, no Grok Build binary, and no profile route the owner
|
|
25
|
+
* can verify. `CapabilityError.isAbsenceOf(error, GROK_SUBSCRIPTION_KIND, id)`
|
|
26
|
+
* names exactly one of them.
|
|
27
|
+
*/
|
|
28
|
+
export declare const GROK_SUBSCRIPTION_ABSENCE: {
|
|
29
|
+
readonly consumerRuntime: "consumer-runtime";
|
|
30
|
+
readonly cli: "cli";
|
|
31
|
+
readonly route: "verified-route";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A subscription failure as Runtime's typed outcome. `code`, `reason` and
|
|
35
|
+
* `details.subscription` name the failure; the Grok code stays readable through
|
|
36
|
+
* {@link grokSubscriptionCode}. `message` is the one sentence that leaves the
|
|
37
|
+
* owner. `cause` rides along for logs and `-v` and is never part of a projection,
|
|
38
|
+
* so only a diagnostic that carries no configuration value belongs there.
|
|
39
|
+
*/
|
|
40
|
+
export declare function grokSubscriptionError(subscription: GrokSubscriptionCode, message: string, options?: {
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
}): CapabilityError;
|
|
43
|
+
/** The Grok code of a subscription failure, or undefined for any other error. */
|
|
44
|
+
export declare function grokSubscriptionCode(error: Error): GrokSubscriptionCode | undefined;
|
|
45
|
+
/** A subscription operation's failure as the owner reports it. */
|
|
46
|
+
export interface GrokSubscriptionFailure {
|
|
47
|
+
readonly code: GrokSubscriptionCode;
|
|
48
|
+
readonly error: CapabilityError;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The owner's decision for a caught failure: its own typed refusal passes
|
|
52
|
+
* through; anything else is reported as the fixed unavailability sentence,
|
|
53
|
+
* because the underlying diagnostic can carry configuration values.
|
|
54
|
+
*/
|
|
55
|
+
export declare function describeGrokSubscriptionFailure(failure: Failure): GrokSubscriptionFailure;
|
|
56
|
+
export interface GrokSubscriptionSession {
|
|
57
|
+
runtime: RuntimeRef;
|
|
58
|
+
execution: RuntimeExecution;
|
|
59
|
+
command: string;
|
|
60
|
+
home: string;
|
|
61
|
+
configPath: string;
|
|
62
|
+
env: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
/** The native CLI owns this profile's login state. Vibes does not read auth.json. */
|
|
65
|
+
export declare function prepareGrokSubscription(runtime: RuntimeRef): Promise<GrokSubscriptionSession>;
|
|
66
|
+
export declare function inspectGrokSubscription(session: GrokSubscriptionSession, cwd?: string): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the dedicated profile is signed in: `true` (the catalog was listed),
|
|
69
|
+
* `false` (the CLI said it is signed out), or a typed `STATUS_CHECK_FAILED`
|
|
70
|
+
* when the check itself failed (a non-zero exit, output that says neither). A
|
|
71
|
+
* failed check is never reported as "not signed in": the caller would send the
|
|
72
|
+
* user to sign in again for a failure that signing in does not fix.
|
|
73
|
+
*/
|
|
74
|
+
export declare function checkGrokSubscription(session: GrokSubscriptionSession, timeout: number): Promise<boolean>;
|
|
75
|
+
/** The declared bounds of a buffered native operation's output. */
|
|
76
|
+
export declare const GROK_PROCESS_OUTPUT_LIMITS: {
|
|
77
|
+
/** Bytes of stdout kept; more stops the child and fails the operation. */
|
|
78
|
+
readonly maxStdoutBytes: 8388608;
|
|
79
|
+
/** Characters of stderr kept (the tail); stderr is a diagnostic that never leaves the owner. */
|
|
80
|
+
readonly maxStderrChars: 65536;
|
|
81
|
+
};
|
|
82
|
+
/** Buffered native operation with real cancellation; raw diagnostics never leave the owner. */
|
|
83
|
+
export declare function runGrokSubscription(session: GrokSubscriptionSession, args: string[], timeout: number, signal?: AbortSignal, onLine?: ExecutionOutputLine): Promise<ExecuteResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Sign the dedicated profile in.
|
|
86
|
+
*
|
|
87
|
+
* With no `onMessage` this is Grok's browser OAuth flow, and the CLI's output
|
|
88
|
+
* stays inside this boundary as every other subscription operation's does.
|
|
89
|
+
* With one, it is the device-code flow instead: the verification URL and user
|
|
90
|
+
* code are streamed to the caller as Grok prints them, because a headless host
|
|
91
|
+
* has no browser to open and a device code is worthless to anyone who cannot
|
|
92
|
+
* also answer the prompt. Either way the credential Grok stores afterwards
|
|
93
|
+
* never crosses this boundary.
|
|
94
|
+
*/
|
|
95
|
+
export declare function loginGrokSubscription(session: GrokSubscriptionSession, options?: {
|
|
96
|
+
timeout?: number;
|
|
97
|
+
signal?: AbortSignal;
|
|
98
|
+
onMessage?: (message: string) => void;
|
|
99
|
+
}): Promise<ExecuteResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Read one file from the dedicated profile through the consumer host adapter.
|
|
102
|
+
* Native profile state does not belong to the active workspace projection.
|
|
103
|
+
*/
|
|
104
|
+
export declare function readDedicatedProfileFile(session: GrokSubscriptionSession, path: string): Promise<string>;
|
|
105
|
+
/**
|
|
106
|
+
* The consumer host's own file adapter for `capability`, never an active
|
|
107
|
+
* workspace's contained projection, or `undefined` when the host composes none.
|
|
108
|
+
*/
|
|
109
|
+
export declare function resolveHostFilesystem(session: GrokSubscriptionSession, capability: 'read' | 'write'): Promise<FileSystemAdapterInterface | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* The typed failure for a subscription operation that failed outside the
|
|
112
|
+
* owner's own refusals. The underlying diagnostic can carry configuration
|
|
113
|
+
* values, so only this fixed sentence leaves the owner.
|
|
114
|
+
*/
|
|
115
|
+
export declare function grokSubscriptionUnavailable(): CapabilityError;
|
|
116
|
+
//# sourceMappingURL=grok-subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-subscription.d.ts","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-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AM,CAAC,CASjB;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,uBAAuB,EAChC,UAAU,EAAE,MAAM,GAAG,OAAO,GAC1B,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAcjD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,eAAe,CAK7D"}
|
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { inspectionSchema, nativeBookkeepingSchema, SubscriptionDetailsSchema } from "../../../schemas/subscription.js";
|
|
2
|
+
import { CapabilityError, composeChildEnv, isCapabilityError } from '@vibesdotdev/kernel';
|
|
3
|
+
import { getRuntimeExecution } from '@vibesdotdev/kernel/execution';
|
|
4
|
+
import { getPathRoots, getRuntimePath } from '@vibesdotdev/paths';
|
|
5
|
+
import { parse as parseToml } from 'smol-toml';
|
|
6
|
+
import * as z from 'zod/v4';
|
|
7
|
+
import { attempt } from "../../../outcome.js";
|
|
8
|
+
/**
|
|
9
|
+
* Terminal sign-in for the dedicated profile. The external CLI projector owns
|
|
10
|
+
* the command; this package does not register an `ai` group of its own.
|
|
11
|
+
*/
|
|
12
|
+
export const GROK_SUBSCRIPTION_LOGIN_COMMAND = 'vibes dev external grok login';
|
|
13
|
+
/** Read-only check of that same profile. */
|
|
14
|
+
export const GROK_SUBSCRIPTION_STATUS_COMMAND = 'vibes dev external grok status';
|
|
15
|
+
/**
|
|
16
|
+
* A device-code sign-in is a person walking to a browser, reading a code, and
|
|
17
|
+
* confirming it. Five minutes is the wait Grok's own flow expects.
|
|
18
|
+
*/
|
|
19
|
+
export const GROK_SUBSCRIPTION_LOGIN_TIMEOUT_MS = 300_000;
|
|
20
|
+
const PASSTHROUGH_ENV = [
|
|
21
|
+
'PATH',
|
|
22
|
+
'USER',
|
|
23
|
+
'LOGNAME',
|
|
24
|
+
'TMPDIR',
|
|
25
|
+
'TMP',
|
|
26
|
+
'TEMP',
|
|
27
|
+
'SystemRoot',
|
|
28
|
+
'WINDIR',
|
|
29
|
+
'APPDATA',
|
|
30
|
+
'LOCALAPPDATA',
|
|
31
|
+
'LANG',
|
|
32
|
+
'LC_ALL',
|
|
33
|
+
'LC_CTYPE',
|
|
34
|
+
'TERM',
|
|
35
|
+
'DISPLAY',
|
|
36
|
+
'WAYLAND_DISPLAY',
|
|
37
|
+
'XDG_RUNTIME_DIR',
|
|
38
|
+
'DBUS_SESSION_BUS_ADDRESS',
|
|
39
|
+
'HTTP_PROXY',
|
|
40
|
+
'HTTPS_PROXY',
|
|
41
|
+
'ALL_PROXY',
|
|
42
|
+
'NO_PROXY',
|
|
43
|
+
'http_proxy',
|
|
44
|
+
'https_proxy',
|
|
45
|
+
'all_proxy',
|
|
46
|
+
'no_proxy',
|
|
47
|
+
'SSL_CERT_FILE',
|
|
48
|
+
'SSL_CERT_DIR'
|
|
49
|
+
];
|
|
50
|
+
/** The `NOT_FOUND` subject kind of the three states in which this host offers no Grok subscription. */
|
|
51
|
+
export const GROK_SUBSCRIPTION_KIND = 'grok-subscription';
|
|
52
|
+
/**
|
|
53
|
+
* Confirmed absences of the subscription on a host, by subject id: no consumer
|
|
54
|
+
* runtime to run it on, no Grok Build binary, and no profile route the owner
|
|
55
|
+
* can verify. `CapabilityError.isAbsenceOf(error, GROK_SUBSCRIPTION_KIND, id)`
|
|
56
|
+
* names exactly one of them.
|
|
57
|
+
*/
|
|
58
|
+
export const GROK_SUBSCRIPTION_ABSENCE = {
|
|
59
|
+
consumerRuntime: 'consumer-runtime',
|
|
60
|
+
cli: 'cli',
|
|
61
|
+
route: 'verified-route'
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* What each failure is to the cross-surface contract. The three absences carry
|
|
65
|
+
* the `NOT_FOUND` subject `CapabilityError.isAbsenceOf` names.
|
|
66
|
+
*/
|
|
67
|
+
const SUBSCRIPTION_OUTCOMES = {
|
|
68
|
+
CONSUMER_RUNTIME_REQUIRED: {
|
|
69
|
+
code: 'NOT_FOUND',
|
|
70
|
+
reason: 'consumer-runtime-required',
|
|
71
|
+
subject: { kind: GROK_SUBSCRIPTION_KIND, id: GROK_SUBSCRIPTION_ABSENCE.consumerRuntime }
|
|
72
|
+
},
|
|
73
|
+
CLI_UNAVAILABLE: {
|
|
74
|
+
code: 'NOT_FOUND',
|
|
75
|
+
reason: 'cli-unavailable',
|
|
76
|
+
subject: { kind: GROK_SUBSCRIPTION_KIND, id: GROK_SUBSCRIPTION_ABSENCE.cli }
|
|
77
|
+
},
|
|
78
|
+
SUBSCRIPTION_ROUTE_UNVERIFIED: {
|
|
79
|
+
code: 'NOT_FOUND',
|
|
80
|
+
reason: 'route-unverified',
|
|
81
|
+
subject: { kind: GROK_SUBSCRIPTION_KIND, id: GROK_SUBSCRIPTION_ABSENCE.route }
|
|
82
|
+
},
|
|
83
|
+
SUBSCRIPTION_REQUIRED: { code: 'AUTH_REQUIRED', reason: 'subscription-required', subject: {} },
|
|
84
|
+
AUTH_TIMEOUT: { code: 'TIMEOUT', reason: 'auth-timeout', subject: {} },
|
|
85
|
+
GENERATION_TIMEOUT: { code: 'TIMEOUT', reason: 'generation-timeout', subject: {} },
|
|
86
|
+
AUTH_CANCELLED: { code: 'CANCELLED', reason: 'auth-cancelled', subject: {} },
|
|
87
|
+
INVALID_REQUEST: { code: 'INVALID_INPUT', reason: 'invalid-request', subject: {} },
|
|
88
|
+
GENERATION_FAILED: { code: 'UNAVAILABLE', reason: 'generation-failed', subject: {} },
|
|
89
|
+
STATUS_CHECK_FAILED: { code: 'UNAVAILABLE', reason: 'status-check-failed', subject: {} },
|
|
90
|
+
SUBSCRIPTION_UNAVAILABLE: { code: 'UNAVAILABLE', reason: 'subscription-unavailable', subject: {} }
|
|
91
|
+
};
|
|
92
|
+
function subscriptionDetails(subscription) {
|
|
93
|
+
return { subscription, ...SUBSCRIPTION_OUTCOMES[subscription].subject };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A subscription failure as Runtime's typed outcome. `code`, `reason` and
|
|
97
|
+
* `details.subscription` name the failure; the Grok code stays readable through
|
|
98
|
+
* {@link grokSubscriptionCode}. `message` is the one sentence that leaves the
|
|
99
|
+
* owner. `cause` rides along for logs and `-v` and is never part of a projection,
|
|
100
|
+
* so only a diagnostic that carries no configuration value belongs there.
|
|
101
|
+
*/
|
|
102
|
+
export function grokSubscriptionError(subscription, message, options = {}) {
|
|
103
|
+
return new CapabilityError(message, SUBSCRIPTION_OUTCOMES[subscription].code, {
|
|
104
|
+
reason: SUBSCRIPTION_OUTCOMES[subscription].reason,
|
|
105
|
+
details: subscriptionDetails(subscription),
|
|
106
|
+
cause: options.cause
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** The Grok code of a subscription failure, or undefined for any other error. */
|
|
110
|
+
export function grokSubscriptionCode(error) {
|
|
111
|
+
if (!isCapabilityError(error))
|
|
112
|
+
return undefined;
|
|
113
|
+
const details = SubscriptionDetailsSchema.safeParse(error.details);
|
|
114
|
+
return details.success ? details.data.subscription : undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The owner's decision for a caught failure: its own typed refusal passes
|
|
118
|
+
* through; anything else is reported as the fixed unavailability sentence,
|
|
119
|
+
* because the underlying diagnostic can carry configuration values.
|
|
120
|
+
*/
|
|
121
|
+
export function describeGrokSubscriptionFailure(failure) {
|
|
122
|
+
const caught = z.instanceof(Error).safeParse(failure.cause);
|
|
123
|
+
if (caught.success && isCapabilityError(caught.data)) {
|
|
124
|
+
const code = grokSubscriptionCode(caught.data);
|
|
125
|
+
if (code !== undefined)
|
|
126
|
+
return { code, error: caught.data };
|
|
127
|
+
}
|
|
128
|
+
return { code: 'SUBSCRIPTION_UNAVAILABLE', error: grokSubscriptionUnavailable() };
|
|
129
|
+
}
|
|
130
|
+
/** The native CLI owns this profile's login state. Vibes does not read auth.json. */
|
|
131
|
+
export async function prepareGrokSubscription(runtime) {
|
|
132
|
+
if (runtime.scope.hardware === 'cloud') {
|
|
133
|
+
throw grokSubscriptionError('CONSUMER_RUNTIME_REQUIRED', 'Grok subscription execution requires a connected consumer host');
|
|
134
|
+
}
|
|
135
|
+
// A host that composes no execution kind cannot run Grok Build. A composed
|
|
136
|
+
// execution provider that is unavailable or fails is an owner failure and
|
|
137
|
+
// propagates typed.
|
|
138
|
+
const execution = runtime.hasKind('runtime/execution')
|
|
139
|
+
? await getRuntimeExecution(runtime)
|
|
140
|
+
: undefined;
|
|
141
|
+
const command = await execution?.resolveCommand('grok');
|
|
142
|
+
if (!execution || !command)
|
|
143
|
+
throw grokSubscriptionError('CLI_UNAVAILABLE', 'Grok Build CLI is unavailable');
|
|
144
|
+
const roots = getPathRoots(runtime);
|
|
145
|
+
const paths = await getRuntimePath(runtime);
|
|
146
|
+
const home = paths.join(roots.dataDir, 'providers', 'grok-subscription');
|
|
147
|
+
const env = composeChildEnv(runtime, { inheritEnv: [...PASSTHROUGH_ENV], env: {
|
|
148
|
+
HOME: roots.userHome,
|
|
149
|
+
GROK_HOME: home,
|
|
150
|
+
GROK_DISABLE_API_KEY_AUTH: '1',
|
|
151
|
+
GROK_DISABLE_AUTOUPDATER: '1',
|
|
152
|
+
GROK_MEMORY: '0'
|
|
153
|
+
} });
|
|
154
|
+
const session = {
|
|
155
|
+
runtime,
|
|
156
|
+
execution,
|
|
157
|
+
command,
|
|
158
|
+
home,
|
|
159
|
+
configPath: paths.join(home, 'config.toml'),
|
|
160
|
+
env
|
|
161
|
+
};
|
|
162
|
+
// Inspection initializes Grok's native home without reading or copying a login.
|
|
163
|
+
// The profile may not exist yet. Bootstrap at its filesystem root: using the
|
|
164
|
+
// user's home makes Grok load ~/.grok/config.toml as project configuration.
|
|
165
|
+
await inspectGrokSubscription(session, paths.resolve(home, '/'));
|
|
166
|
+
return session;
|
|
167
|
+
}
|
|
168
|
+
const INSPECTION_UNVERIFIABLE = 'Grok Build reported an inspection this runtime cannot verify: managed machine policy must permit subscription-only use (API-key auth disabled, no configuration warnings).';
|
|
169
|
+
export async function inspectGrokSubscription(session, cwd = session.home) {
|
|
170
|
+
const result = await session.execution.execute({
|
|
171
|
+
command: session.command,
|
|
172
|
+
args: ['inspect', '--json'],
|
|
173
|
+
cwd,
|
|
174
|
+
env: session.env,
|
|
175
|
+
envMode: 'replace',
|
|
176
|
+
timeout: 5_000
|
|
177
|
+
});
|
|
178
|
+
// Four different conditions used to share one sentence, so a machine that
|
|
179
|
+
// could not run the CLI at all read exactly like a profile carrying an
|
|
180
|
+
// unsafe key. Each says which one it is; none quotes a configuration value.
|
|
181
|
+
if (result.timedOut) {
|
|
182
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', `Grok Build did not answer \`inspect\` in time. Run: ${GROK_SUBSCRIPTION_STATUS_COMMAND}`);
|
|
183
|
+
}
|
|
184
|
+
if (result.exitCode !== 0) {
|
|
185
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', `Grok Build's \`inspect\` exited ${result.exitCode ?? 'without a code'}. Run: ${GROK_SUBSCRIPTION_STATUS_COMMAND}`);
|
|
186
|
+
}
|
|
187
|
+
let inspection;
|
|
188
|
+
try {
|
|
189
|
+
inspection = JSON.parse(result.stdout);
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', INSPECTION_UNVERIFIABLE, { cause: error });
|
|
193
|
+
}
|
|
194
|
+
const parsed = inspectionSchema.safeParse(inspection);
|
|
195
|
+
if (!parsed.success) {
|
|
196
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', INSPECTION_UNVERIFIABLE);
|
|
197
|
+
}
|
|
198
|
+
const unsafe = await describeUnsafeNativeConfiguration(session, parsed.data.configSources.layers);
|
|
199
|
+
if (unsafe) {
|
|
200
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', unsafe);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Return null when the dedicated profile carries nothing but the vendor's own
|
|
205
|
+
* bookkeeping, or a sentence naming WHY it does not. Key PATHS are named (a
|
|
206
|
+
* key path is not a secret); values never are, because a value can be one.
|
|
207
|
+
*/
|
|
208
|
+
/** Compare profile paths without caring which slash the host or the CLI used. */
|
|
209
|
+
function profilePath(value) {
|
|
210
|
+
return value.replaceAll('\\', '/').replace(/\/+$/, '');
|
|
211
|
+
}
|
|
212
|
+
/** A layer belongs to the dedicated profile when it sits under its directory. */
|
|
213
|
+
function isInsideProfile(session, path) {
|
|
214
|
+
const home = profilePath(session.home);
|
|
215
|
+
const candidate = profilePath(path);
|
|
216
|
+
return candidate === home || candidate.startsWith(`${home}/`);
|
|
217
|
+
}
|
|
218
|
+
async function describeUnsafeNativeConfiguration(session, layers) {
|
|
219
|
+
if (layers.length === 0)
|
|
220
|
+
return null;
|
|
221
|
+
// Grok discovers its own home layout: running inside the profile it reports
|
|
222
|
+
// `managed_config.toml` and `requirements.toml` alongside `config.toml`,
|
|
223
|
+
// both `note: "empty"` (measured 2026-09-06, grok 1.0.21). Empty files that
|
|
224
|
+
// live inside the dedicated profile carry nothing and are admitted; a layer
|
|
225
|
+
// outside the profile, or a non-empty layer that is not the profile's own
|
|
226
|
+
// `config.toml`, is not.
|
|
227
|
+
const outside = layers.find((layer) => !isInsideProfile(session, layer.path));
|
|
228
|
+
if (outside) {
|
|
229
|
+
return 'Grok Build is loading configuration from outside its dedicated Vibes profile, so the subscription route cannot be trusted.';
|
|
230
|
+
}
|
|
231
|
+
const substantive = layers.filter((layer) => layer.note !== 'empty');
|
|
232
|
+
if (substantive.some((layer) => layer.role !== 'user' || profilePath(layer.path) !== profilePath(session.configPath))) {
|
|
233
|
+
return "Grok Build's dedicated profile carries a configuration layer other than its own user config, so the subscription route cannot be trusted.";
|
|
234
|
+
}
|
|
235
|
+
if (substantive.length === 0)
|
|
236
|
+
return null;
|
|
237
|
+
let content;
|
|
238
|
+
try {
|
|
239
|
+
content = await readDedicatedProfileFile(session, session.configPath);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (error instanceof Error && grokSubscriptionCode(error) !== undefined)
|
|
243
|
+
throw error;
|
|
244
|
+
// Adapter diagnostics can include configuration values: only the sentence leaves.
|
|
245
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', "Grok Build's dedicated profile could not be read on this host.");
|
|
246
|
+
}
|
|
247
|
+
const toml = attempt(() => parseToml(content));
|
|
248
|
+
if (!toml.ok) {
|
|
249
|
+
// Parser diagnostics quote the offending line, values included: only the sentence leaves.
|
|
250
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', "Grok Build's dedicated profile is not valid TOML.");
|
|
251
|
+
}
|
|
252
|
+
const parsed = nativeBookkeepingSchema.safeParse(toml.value);
|
|
253
|
+
if (parsed.success)
|
|
254
|
+
return null;
|
|
255
|
+
// A strict object reports an unrecognized key on the PARENT's path, with the
|
|
256
|
+
// offending names in `keys`; anything else (a wrong type) is named by its
|
|
257
|
+
// own path. Neither carries a value.
|
|
258
|
+
const keys = Array.from(new Set(parsed.error.issues.flatMap((issue) => {
|
|
259
|
+
const prefix = issue.path.join('.');
|
|
260
|
+
if (issue.code === 'unrecognized_keys') {
|
|
261
|
+
return issue.keys.map((key) => (prefix ? `${prefix}.${key}` : key));
|
|
262
|
+
}
|
|
263
|
+
return prefix ? [prefix] : [];
|
|
264
|
+
}))).sort();
|
|
265
|
+
return keys.length > 0
|
|
266
|
+
? `Grok Build's dedicated profile carries configuration outside native bookkeeping (${keys.join(', ')}); only Grok's own bookkeeping is admitted, so the subscription route cannot be trusted.`
|
|
267
|
+
: "Grok Build's dedicated profile carries configuration outside native bookkeeping, so the subscription route cannot be trusted.";
|
|
268
|
+
}
|
|
269
|
+
/** What the CLI prints when the profile is not signed in. */
|
|
270
|
+
const SIGNED_OUT_OUTPUT = /not authenticated|not signed in|no auth credentials|authentication required|failed to fetch models/i;
|
|
271
|
+
/**
|
|
272
|
+
* Whether the dedicated profile is signed in: `true` (the catalog was listed),
|
|
273
|
+
* `false` (the CLI said it is signed out), or a typed `STATUS_CHECK_FAILED`
|
|
274
|
+
* when the check itself failed (a non-zero exit, output that says neither). A
|
|
275
|
+
* failed check is never reported as "not signed in": the caller would send the
|
|
276
|
+
* user to sign in again for a failure that signing in does not fix.
|
|
277
|
+
*/
|
|
278
|
+
export async function checkGrokSubscription(session, timeout) {
|
|
279
|
+
await inspectGrokSubscription(session);
|
|
280
|
+
const result = await session.execution.execute({
|
|
281
|
+
command: session.command,
|
|
282
|
+
args: ['models'],
|
|
283
|
+
cwd: session.home,
|
|
284
|
+
env: session.env,
|
|
285
|
+
envMode: 'replace',
|
|
286
|
+
timeout
|
|
287
|
+
});
|
|
288
|
+
if (result.timedOut)
|
|
289
|
+
throw grokSubscriptionError('AUTH_TIMEOUT', 'Grok authentication check timed out');
|
|
290
|
+
const output = `${result.stdout}\n${result.stderr}`;
|
|
291
|
+
if (SIGNED_OUT_OUTPUT.test(output))
|
|
292
|
+
return false;
|
|
293
|
+
if (result.exitCode === 0 && /Available models:/i.test(output))
|
|
294
|
+
return true;
|
|
295
|
+
throw grokSubscriptionError('STATUS_CHECK_FAILED', 'Grok Build could not report the subscription status; this is a failed check, not a sign-out', { cause: new Error(`models exited ${result.exitCode ?? 'without a code'}`) });
|
|
296
|
+
}
|
|
297
|
+
/** The declared bounds of a buffered native operation's output. */
|
|
298
|
+
export const GROK_PROCESS_OUTPUT_LIMITS = {
|
|
299
|
+
/** Bytes of stdout kept; more stops the child and fails the operation. */
|
|
300
|
+
maxStdoutBytes: 8_388_608,
|
|
301
|
+
/** Characters of stderr kept (the tail); stderr is a diagnostic that never leaves the owner. */
|
|
302
|
+
maxStderrChars: 65_536
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Drain a child's streams within `limits`: stdout past its cap stops the child
|
|
306
|
+
* (`onOverflow`) and is reported, stderr keeps its tail. Lines go to `onLine`
|
|
307
|
+
* as they complete.
|
|
308
|
+
*/
|
|
309
|
+
async function collectBoundedOutput(child, limits, onOverflow, onLine) {
|
|
310
|
+
let overflowed = false;
|
|
311
|
+
const drain = async (stream, name) => {
|
|
312
|
+
if (!stream)
|
|
313
|
+
return '';
|
|
314
|
+
const reader = stream.getReader();
|
|
315
|
+
const decoder = new TextDecoder();
|
|
316
|
+
let kept = '';
|
|
317
|
+
let bytes = 0;
|
|
318
|
+
let pending = '';
|
|
319
|
+
try {
|
|
320
|
+
for (;;) {
|
|
321
|
+
const { done, value } = await reader.read();
|
|
322
|
+
if (done)
|
|
323
|
+
break;
|
|
324
|
+
if (name === 'stdout') {
|
|
325
|
+
bytes += value.length;
|
|
326
|
+
if (bytes > limits.maxStdoutBytes) {
|
|
327
|
+
overflowed = true;
|
|
328
|
+
onOverflow();
|
|
329
|
+
await reader.cancel();
|
|
330
|
+
return kept;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const text = decoder.decode(value, { stream: true });
|
|
334
|
+
kept = name === 'stderr' ? (kept + text).slice(-limits.maxStderrChars) : kept + text;
|
|
335
|
+
pending += text;
|
|
336
|
+
const lines = pending.split('\n');
|
|
337
|
+
pending = (lines.pop() ?? '').slice(-limits.maxStderrChars);
|
|
338
|
+
// A line is a prompt for the user (a device code), not a log: it is bounded like the output.
|
|
339
|
+
for (const line of lines)
|
|
340
|
+
if (line.length > 0)
|
|
341
|
+
onLine?.(name, line.slice(0, limits.maxStderrChars));
|
|
342
|
+
}
|
|
343
|
+
const tail = decoder.decode();
|
|
344
|
+
kept = name === 'stderr' ? (kept + tail).slice(-limits.maxStderrChars) : kept + tail;
|
|
345
|
+
pending += tail;
|
|
346
|
+
if (pending.length > 0)
|
|
347
|
+
onLine?.(name, pending.slice(0, limits.maxStderrChars));
|
|
348
|
+
return kept;
|
|
349
|
+
}
|
|
350
|
+
finally {
|
|
351
|
+
reader.releaseLock();
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
const [exit, stdout, stderr] = await Promise.all([
|
|
355
|
+
child.exited,
|
|
356
|
+
drain(child.stdout, 'stdout'),
|
|
357
|
+
drain(child.stderr, 'stderr')
|
|
358
|
+
]);
|
|
359
|
+
return { code: exit.code, stdout, stderr, overflowed };
|
|
360
|
+
}
|
|
361
|
+
/** Buffered native operation with real cancellation; raw diagnostics never leave the owner. */
|
|
362
|
+
export async function runGrokSubscription(session, args, timeout, signal, onLine) {
|
|
363
|
+
if (signal?.aborted)
|
|
364
|
+
throw grokSubscriptionError('AUTH_CANCELLED', 'Grok operation cancelled');
|
|
365
|
+
const started = Date.now();
|
|
366
|
+
const child = await session.execution.spawn({
|
|
367
|
+
command: session.command,
|
|
368
|
+
args,
|
|
369
|
+
cwd: session.home,
|
|
370
|
+
env: session.env,
|
|
371
|
+
envMode: 'replace',
|
|
372
|
+
stdin: 'ignore',
|
|
373
|
+
stdout: 'pipe',
|
|
374
|
+
stderr: 'pipe'
|
|
375
|
+
});
|
|
376
|
+
let timedOut = false;
|
|
377
|
+
let cancelForceStop;
|
|
378
|
+
const cancel = () => {
|
|
379
|
+
child.kill('SIGTERM');
|
|
380
|
+
if (cancelForceStop)
|
|
381
|
+
return;
|
|
382
|
+
const armed = attempt(() => session.runtime.lifecycle.timeout(() => child.kill('SIGKILL'), 1_000));
|
|
383
|
+
// A runtime that is ending starts no timers, so nothing could wait out the grace: the child is stopped for good now.
|
|
384
|
+
if (!armed.ok)
|
|
385
|
+
child.kill('SIGKILL');
|
|
386
|
+
else
|
|
387
|
+
cancelForceStop = armed.value;
|
|
388
|
+
};
|
|
389
|
+
const cancelTimer = session.runtime.lifecycle.timeout(() => {
|
|
390
|
+
timedOut = true;
|
|
391
|
+
cancel();
|
|
392
|
+
}, timeout);
|
|
393
|
+
signal?.addEventListener('abort', cancel, { once: true });
|
|
394
|
+
if (signal?.aborted)
|
|
395
|
+
cancel();
|
|
396
|
+
try {
|
|
397
|
+
const output = await collectBoundedOutput(child, GROK_PROCESS_OUTPUT_LIMITS, cancel, onLine);
|
|
398
|
+
if (signal?.aborted)
|
|
399
|
+
throw grokSubscriptionError('AUTH_CANCELLED', 'Grok operation cancelled');
|
|
400
|
+
if (output.overflowed)
|
|
401
|
+
throw grokSubscriptionError('GENERATION_FAILED', 'Grok Build wrote more output than the declared maximum');
|
|
402
|
+
return {
|
|
403
|
+
exitCode: output.code,
|
|
404
|
+
stdout: output.stdout,
|
|
405
|
+
stderr: output.stderr,
|
|
406
|
+
timedOut,
|
|
407
|
+
durationMs: Date.now() - started
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
cancelTimer();
|
|
412
|
+
cancelForceStop?.();
|
|
413
|
+
signal?.removeEventListener('abort', cancel);
|
|
414
|
+
child.kill('SIGTERM');
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Sign the dedicated profile in.
|
|
419
|
+
*
|
|
420
|
+
* With no `onMessage` this is Grok's browser OAuth flow, and the CLI's output
|
|
421
|
+
* stays inside this boundary as every other subscription operation's does.
|
|
422
|
+
* With one, it is the device-code flow instead: the verification URL and user
|
|
423
|
+
* code are streamed to the caller as Grok prints them, because a headless host
|
|
424
|
+
* has no browser to open and a device code is worthless to anyone who cannot
|
|
425
|
+
* also answer the prompt. Either way the credential Grok stores afterwards
|
|
426
|
+
* never crosses this boundary.
|
|
427
|
+
*/
|
|
428
|
+
export async function loginGrokSubscription(session, options = {}) {
|
|
429
|
+
const { onMessage } = options;
|
|
430
|
+
return await runGrokSubscription(session, ['login', onMessage ? '--device-auth' : '--oauth'], options.timeout ?? GROK_SUBSCRIPTION_LOGIN_TIMEOUT_MS, options.signal, onMessage
|
|
431
|
+
? (_stream, line) => {
|
|
432
|
+
const text = line.trim();
|
|
433
|
+
if (text.length > 0)
|
|
434
|
+
onMessage(text);
|
|
435
|
+
}
|
|
436
|
+
: undefined);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Read one file from the dedicated profile through the consumer host adapter.
|
|
440
|
+
* Native profile state does not belong to the active workspace projection.
|
|
441
|
+
*/
|
|
442
|
+
export async function readDedicatedProfileFile(session, path) {
|
|
443
|
+
const filesystem = await resolveHostFilesystem(session, 'read');
|
|
444
|
+
if (!filesystem)
|
|
445
|
+
throw grokSubscriptionError('SUBSCRIPTION_ROUTE_UNVERIFIED', 'No consumer filesystem adapter can read the Grok profile on this host.');
|
|
446
|
+
const raw = await filesystem.readFile(path, 'utf8');
|
|
447
|
+
return raw instanceof Uint8Array ? new TextDecoder().decode(raw) : raw;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The consumer host's own file adapter for `capability`, never an active
|
|
451
|
+
* workspace's contained projection, or `undefined` when the host composes none.
|
|
452
|
+
*/
|
|
453
|
+
export async function resolveHostFilesystem(session, capability) {
|
|
454
|
+
const query = session.runtime
|
|
455
|
+
.query('filesystem/adapter')
|
|
456
|
+
.enabled();
|
|
457
|
+
const hostAdapter = query
|
|
458
|
+
.descriptors()
|
|
459
|
+
.find((descriptor) => !descriptor.cloudNative &&
|
|
460
|
+
(!descriptor.hardware || descriptor.hardware.includes('consumer')) &&
|
|
461
|
+
descriptor.protocols.includes('file') &&
|
|
462
|
+
descriptor.capabilities.includes(capability));
|
|
463
|
+
return hostAdapter ? query.withId(hostAdapter.id).resolve() : undefined;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* The typed failure for a subscription operation that failed outside the
|
|
467
|
+
* owner's own refusals. The underlying diagnostic can carry configuration
|
|
468
|
+
* values, so only this fixed sentence leaves the owner.
|
|
469
|
+
*/
|
|
470
|
+
export function grokSubscriptionUnavailable() {
|
|
471
|
+
return grokSubscriptionError('SUBSCRIPTION_UNAVAILABLE', 'Grok subscription execution is unavailable on this consumer host');
|
|
472
|
+
}
|
|
473
|
+
//# sourceMappingURL=grok-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-subscription.js","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-subscription.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