@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,11 @@
|
|
|
1
|
+
import { createAITransportDescriptor } from '@vibesdotdev/ai/transports/schemas/descriptor';
|
|
2
|
+
export default createAITransportDescriptor({
|
|
3
|
+
id: 'grok-build',
|
|
4
|
+
name: 'Grok Build subscription',
|
|
5
|
+
description: 'Native Grok execution with isolated provider-managed login and verified subscription-only routing.',
|
|
6
|
+
scopes: ['consumer'],
|
|
7
|
+
bidirectional: false,
|
|
8
|
+
cancellable: true,
|
|
9
|
+
tags: ['grok', 'subscription', 'consumer-only']
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=grok-build.transport.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-build.transport.descriptor.js","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-build.transport.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAE5F,eAAe,2BAA2B,CAAC;IAC1C,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EACV,oGAAoG;IACrG,MAAM,EAAE,CAAC,UAAU,CAAC;IACpB,aAAa,EAAE,KAAK;IACpB,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC;CAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RuntimeRef } from '@vibesdotdev/kernel';
|
|
2
|
+
import type { AITransportInterface, TransportCallOptions } from '@vibesdotdev/ai/transports/interfaces';
|
|
3
|
+
import type { WireRequest, WireResponseChunk } from '@vibesdotdev/ai/specs/interfaces';
|
|
4
|
+
export declare class GrokBuildTransport implements AITransportInterface {
|
|
5
|
+
private readonly runtime;
|
|
6
|
+
readonly descriptor: {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: "ai/transport";
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
scopes: ("cloud" | "consumer")[];
|
|
12
|
+
bidirectional: boolean;
|
|
13
|
+
cancellable: boolean;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
tags?: string[] | undefined;
|
|
16
|
+
};
|
|
17
|
+
constructor(runtime: RuntimeRef);
|
|
18
|
+
send(request: WireRequest, options: TransportCallOptions): AsyncIterable<WireResponseChunk>;
|
|
19
|
+
/** One generation: its chunks, then the outcome that tells `send` whether it failed. */
|
|
20
|
+
private generate;
|
|
21
|
+
private run;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=grok-build.transport.impl.consumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-build.transport.impl.consumer.d.ts","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-build.transport.impl.consumer.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,KAAK,EACX,oBAAoB,EACpB,oBAAoB,EACpB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAwCvF,qBAAa,kBAAmB,YAAW,oBAAoB;IAElD,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,QAAQ,CAAC,UAAU;;;;;;;;;;MAAc;gBACJ,OAAO,EAAE,UAAU;IAEzC,IAAI,CACV,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,oBAAoB,GAC3B,aAAa,CAAC,iBAAiB,CAAC;IAQnC,wFAAwF;YACzE,QAAQ;YAUT,GAAG;CAkEjB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { StructuredRefusalSchema } from "../../../schemas/refusal.js";
|
|
2
|
+
import { CaughtFailureSchema } from '@vibesdotdev/kernel';
|
|
3
|
+
import descriptor from "./grok-build.transport.descriptor.js";
|
|
4
|
+
import { GrokBuildRequestSchema } from "./grok-build.request.js";
|
|
5
|
+
import { withGrokPromptFile } from "./grok-prompt-file.js";
|
|
6
|
+
import { describeGrokFailure, grokRefusal, peerTextCause } from "./grok-refusals.js";
|
|
7
|
+
import { carriesSandboxRefusal } from "./grok-sandbox-signal.js";
|
|
8
|
+
import { checkGrokSubscription, grokSubscriptionError, prepareGrokSubscription, runGrokSubscription } from "./grok-subscription.js";
|
|
9
|
+
import { attempt } from "../../../outcome.js";
|
|
10
|
+
/**
|
|
11
|
+
* Grok Build reports a refused request on its STRUCTURED channel:
|
|
12
|
+
* `--output-format json` prints `{"type":"error","message":"…"}` on stdout and
|
|
13
|
+
* exits non-zero. That message is the difference between "the subscription is
|
|
14
|
+
* broken" and "you asked for a model this subscription does not have" —
|
|
15
|
+
* measured 2026-09-06, a connection whose `defaultModel` was
|
|
16
|
+
* `grok-composer-2.5-fast` produced `Couldn't set model …: "unknown model id"`.
|
|
17
|
+
*
|
|
18
|
+
* Only this channel is read, and its text is the peer's: it is capped and
|
|
19
|
+
* stripped and rides only as the refusal's `cause`, never in its message.
|
|
20
|
+
* Raw stdout and stderr stay inside the owner, as every other subscription
|
|
21
|
+
* operation's does.
|
|
22
|
+
*/
|
|
23
|
+
function readStructuredRefusal(stdout) {
|
|
24
|
+
const trimmed = stdout.trim();
|
|
25
|
+
if (!trimmed.startsWith('{'))
|
|
26
|
+
return null;
|
|
27
|
+
const decoded = attempt(() => JSON.parse(trimmed));
|
|
28
|
+
// Output that opens like a refusal but is not JSON is not a structured one:
|
|
29
|
+
// the caller reports the generic failure instead.
|
|
30
|
+
if (!decoded.ok)
|
|
31
|
+
return null;
|
|
32
|
+
const refusal = StructuredRefusalSchema.safeParse(decoded.value);
|
|
33
|
+
return refusal.success ? refusal.data.message : null;
|
|
34
|
+
}
|
|
35
|
+
export class GrokBuildTransport {
|
|
36
|
+
runtime;
|
|
37
|
+
descriptor = descriptor;
|
|
38
|
+
constructor(runtime) {
|
|
39
|
+
this.runtime = runtime;
|
|
40
|
+
}
|
|
41
|
+
async *send(request, options) {
|
|
42
|
+
const outcome = yield* this.generate(request, options);
|
|
43
|
+
// The owner reports what failed in its own words: a typed refusal as it is,
|
|
44
|
+
// anything else as the fixed unavailability sentence.
|
|
45
|
+
if (!outcome.ok)
|
|
46
|
+
yield { kind: 'error', error: describeGrokFailure(outcome) };
|
|
47
|
+
yield { kind: 'end' };
|
|
48
|
+
}
|
|
49
|
+
/** One generation: its chunks, then the outcome that tells `send` whether it failed. */
|
|
50
|
+
async *generate(request, options) {
|
|
51
|
+
const outcome = await this.run(request, options);
|
|
52
|
+
if (!outcome.ok)
|
|
53
|
+
return outcome;
|
|
54
|
+
yield { kind: 'bytes', data: new TextEncoder().encode(outcome.value) };
|
|
55
|
+
return { ok: true, value: undefined };
|
|
56
|
+
}
|
|
57
|
+
async run(request, options) {
|
|
58
|
+
try {
|
|
59
|
+
const body = GrokBuildRequestSchema.safeParse(request.body);
|
|
60
|
+
if (!body.success)
|
|
61
|
+
throw grokSubscriptionError('INVALID_REQUEST', 'Grok Build requires a text prompt and an optional model');
|
|
62
|
+
if (options.signal?.aborted)
|
|
63
|
+
throw grokSubscriptionError('AUTH_CANCELLED', 'Grok operation cancelled');
|
|
64
|
+
if (options.auth && options.auth.kind !== 'none')
|
|
65
|
+
throw grokRefusal('credentials-not-accepted');
|
|
66
|
+
const session = await prepareGrokSubscription(this.runtime);
|
|
67
|
+
if (!(await checkGrokSubscription(session, 5_000)))
|
|
68
|
+
throw grokSubscriptionError('SUBSCRIPTION_REQUIRED', 'Sign in to the Grok subscription connection on this device before generating');
|
|
69
|
+
const result = await withGrokPromptFile(session, body.data.prompt, (promptFile) => {
|
|
70
|
+
// The prompt is in the file: nothing the caller wrote is an argument.
|
|
71
|
+
const args = [
|
|
72
|
+
'--prompt-file',
|
|
73
|
+
promptFile,
|
|
74
|
+
'--output-format',
|
|
75
|
+
'json',
|
|
76
|
+
'--no-alt-screen',
|
|
77
|
+
'--no-plan',
|
|
78
|
+
'--no-subagents',
|
|
79
|
+
'--disable-web-search',
|
|
80
|
+
'--max-turns',
|
|
81
|
+
'1',
|
|
82
|
+
'--verbatim',
|
|
83
|
+
'--tools',
|
|
84
|
+
'',
|
|
85
|
+
'--deny',
|
|
86
|
+
'MCPTool',
|
|
87
|
+
'--permission-mode',
|
|
88
|
+
'dontAsk',
|
|
89
|
+
'--sandbox',
|
|
90
|
+
'read-only'
|
|
91
|
+
];
|
|
92
|
+
if (body.data.model)
|
|
93
|
+
args.push('--model', body.data.model);
|
|
94
|
+
return runGrokSubscription(session, args, options.timeoutMs ?? 60_000, options.signal);
|
|
95
|
+
});
|
|
96
|
+
if (result.timedOut)
|
|
97
|
+
throw grokSubscriptionError('GENERATION_TIMEOUT', 'Grok subscription generation timed out');
|
|
98
|
+
if (result.exitCode !== 0) {
|
|
99
|
+
// Grok's own refusal to run unprotected, by its fixed marker: stderr's text is never kept.
|
|
100
|
+
if (carriesSandboxRefusal(result.stderr)) {
|
|
101
|
+
throw grokRefusal('sandbox-unavailable', { details: { stage: 'run', exitCode: result.exitCode } });
|
|
102
|
+
}
|
|
103
|
+
const refusal = readStructuredRefusal(result.stdout);
|
|
104
|
+
if (refusal !== null)
|
|
105
|
+
throw grokRefusal('grok-build-refused', { cause: peerTextCause(refusal) });
|
|
106
|
+
throw grokSubscriptionError('GENERATION_FAILED', 'Grok subscription generation failed; verify the subscription connection');
|
|
107
|
+
}
|
|
108
|
+
return { ok: true, value: result.stdout };
|
|
109
|
+
}
|
|
110
|
+
catch (cause) {
|
|
111
|
+
return { ok: false, cause: CaughtFailureSchema.parse(cause) };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=grok-build.transport.impl.consumer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-build.transport.impl.consumer.js","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-build.transport.impl.consumer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,qBAAqB,CAAC;AAM3E,OAAO,UAAU,MAAM,sCAAsC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAgB,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,SAAS,qBAAqB,CAAC,MAAc;IAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC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CAAC,KAAK,CAAC,CAAC;gBAC3D,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACxF,CAAC,CAAC,CAAC;YACH,IAAI,MAAM,CAAC,QAAQ;gBAClB,MAAM,qBAAqB,CAC1B,oBAAoB,EACpB,wCAAwC,CACxC,CAAC;YACH,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;gBAC3B,2FAA2F;gBAC3F,IAAI,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1C,MAAM,WAAW,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBACpG,CAAC;gBACD,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrD,IAAI,OAAO,KAAK,IAAI;oBAAE,MAAM,WAAW,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACjG,MAAM,qBAAqB,CAC1B,mBAAmB,EACnB,yEAAyE,CACzE,CAAC;YACH,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/D,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type GrokSubscriptionSession } from './grok-subscription.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Hand a prompt to Grok Build as a private file, never as an argument: argv is
|
|
4
|
+
* visible to every local user (`ps`), and a prompt that starts with `-` would
|
|
5
|
+
* be read as an option. The file is owner-only, lives in the dedicated profile,
|
|
6
|
+
* has a name nothing the caller supplied can influence, and is removed when
|
|
7
|
+
* `use` ends however it ends.
|
|
8
|
+
*
|
|
9
|
+
* A host whose file adapter cannot write an owner-only file fails closed
|
|
10
|
+
* (`prompt-file-unavailable`): the prompt is never put on the command line
|
|
11
|
+
* instead. A file that cannot be removed fails the call
|
|
12
|
+
* (`prompt-file-cleanup-failed`), because a prompt left on disk is the leak
|
|
13
|
+
* this exists to prevent.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withGrokPromptFile<T>(session: GrokSubscriptionSession, prompt: string, use: (path: string) => Promise<T>): Promise<T>;
|
|
16
|
+
//# sourceMappingURL=grok-prompt-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-prompt-file.d.ts","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-prompt-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAK7F;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACzC,OAAO,EAAE,uBAAuB,EAChC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/B,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getRuntimePath } from '@vibesdotdev/paths';
|
|
2
|
+
import { asError, settle } from "../../../outcome.js";
|
|
3
|
+
import { grokRefusal } from "./grok-refusals.js";
|
|
4
|
+
import { resolveHostFilesystem } from "./grok-subscription.js";
|
|
5
|
+
/** The directory, inside the dedicated profile, that holds a prompt for the length of one run. */
|
|
6
|
+
const PROMPT_DIRECTORY = 'prompts';
|
|
7
|
+
/**
|
|
8
|
+
* Hand a prompt to Grok Build as a private file, never as an argument: argv is
|
|
9
|
+
* visible to every local user (`ps`), and a prompt that starts with `-` would
|
|
10
|
+
* be read as an option. The file is owner-only, lives in the dedicated profile,
|
|
11
|
+
* has a name nothing the caller supplied can influence, and is removed when
|
|
12
|
+
* `use` ends however it ends.
|
|
13
|
+
*
|
|
14
|
+
* A host whose file adapter cannot write an owner-only file fails closed
|
|
15
|
+
* (`prompt-file-unavailable`): the prompt is never put on the command line
|
|
16
|
+
* instead. A file that cannot be removed fails the call
|
|
17
|
+
* (`prompt-file-cleanup-failed`), because a prompt left on disk is the leak
|
|
18
|
+
* this exists to prevent.
|
|
19
|
+
*/
|
|
20
|
+
export async function withGrokPromptFile(session, prompt, use) {
|
|
21
|
+
const filesystem = await resolveHostFilesystem(session, 'write');
|
|
22
|
+
if (!filesystem?.writeFilePrivate)
|
|
23
|
+
throw grokRefusal('prompt-file-unavailable');
|
|
24
|
+
const writePrivate = filesystem.writeFilePrivate.bind(filesystem);
|
|
25
|
+
const paths = await getRuntimePath(session.runtime);
|
|
26
|
+
const directory = paths.join(session.home, PROMPT_DIRECTORY);
|
|
27
|
+
const path = paths.join(directory, `${crypto.randomUUID()}.txt`);
|
|
28
|
+
// Owner-only, like the file inside it.
|
|
29
|
+
await filesystem.mkdir(directory, { recursive: true, mode: 0o700 });
|
|
30
|
+
const written = await settle(() => writePrivate(path, prompt, 'utf8'));
|
|
31
|
+
// Nothing was published, so there is nothing to remove.
|
|
32
|
+
if (!written.ok)
|
|
33
|
+
throw asError(written.cause);
|
|
34
|
+
const used = await settle(() => use(path));
|
|
35
|
+
const removed = await settle(() => filesystem.remove(path));
|
|
36
|
+
if (!removed.ok) {
|
|
37
|
+
throw grokRefusal('prompt-file-cleanup-failed', { cause: !used.ok ? used.cause : removed.cause });
|
|
38
|
+
}
|
|
39
|
+
if (!used.ok)
|
|
40
|
+
throw asError(used.cause);
|
|
41
|
+
return used.value;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=grok-prompt-file.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M,EAAE,MAAM,CAAC,CAAC,CAAC;IACvE,wDAAwD;IACxD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,WAAW,CAAC,4BAA4B,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACnG,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every typed refusal of the Grok agent, request and connection paths.
|
|
3
|
+
*
|
|
4
|
+
* One fixed message per reason. Text the child, the HTTP peer or the caller's
|
|
5
|
+
* request supplied never enters a message or `details`: it rides only in a
|
|
6
|
+
* bounded `cause`, which the logger scrubs and no projection prints.
|
|
7
|
+
*/
|
|
8
|
+
import { CapabilityError, type CapabilityErrorDetails, type CaughtFailure } from '@vibesdotdev/kernel';
|
|
9
|
+
import type { Failure } from '../../../outcome.ts';
|
|
10
|
+
declare const REFUSALS: {
|
|
11
|
+
readonly 'sign-in-required': {
|
|
12
|
+
readonly code: "AUTH_REQUIRED";
|
|
13
|
+
readonly retryable: false;
|
|
14
|
+
readonly message: "Sign in to the Grok subscription connection on this device. Run: vibes dev external grok login";
|
|
15
|
+
};
|
|
16
|
+
readonly 'agent-connect-failed': {
|
|
17
|
+
readonly code: "UNAVAILABLE";
|
|
18
|
+
readonly retryable: true;
|
|
19
|
+
readonly message: "The Grok agent session could not be started.";
|
|
20
|
+
};
|
|
21
|
+
readonly 'sandbox-unavailable': {
|
|
22
|
+
readonly code: "UNAVAILABLE";
|
|
23
|
+
readonly retryable: false;
|
|
24
|
+
readonly message: "Grok refused to start because its read-only sandbox cannot be applied on this host; Grok never runs without it.";
|
|
25
|
+
};
|
|
26
|
+
readonly 'agent-request-failed': {
|
|
27
|
+
readonly code: "UNAVAILABLE";
|
|
28
|
+
readonly retryable: false;
|
|
29
|
+
readonly message: "The Grok agent answered a request with an error.";
|
|
30
|
+
};
|
|
31
|
+
readonly 'agent-closed': {
|
|
32
|
+
readonly code: "UNAVAILABLE";
|
|
33
|
+
readonly retryable: true;
|
|
34
|
+
readonly message: "The Grok agent session ended before the turn finished.";
|
|
35
|
+
};
|
|
36
|
+
readonly 'agent-line-too-long': {
|
|
37
|
+
readonly code: "UNAVAILABLE";
|
|
38
|
+
readonly retryable: false;
|
|
39
|
+
readonly message: "The Grok agent wrote a line longer than the declared maximum.";
|
|
40
|
+
};
|
|
41
|
+
readonly 'agent-record-invalid': {
|
|
42
|
+
readonly code: "UNAVAILABLE";
|
|
43
|
+
readonly retryable: false;
|
|
44
|
+
readonly message: "The Grok agent sent output this integration cannot read.";
|
|
45
|
+
};
|
|
46
|
+
readonly 'agent-output-too-large': {
|
|
47
|
+
readonly code: "UNAVAILABLE";
|
|
48
|
+
readonly retryable: false;
|
|
49
|
+
readonly message: "The Grok agent produced more output than the declared maximum.";
|
|
50
|
+
};
|
|
51
|
+
readonly 'agent-turn-timeout': {
|
|
52
|
+
readonly code: "TIMEOUT";
|
|
53
|
+
readonly retryable: true;
|
|
54
|
+
readonly message: "The Grok agent did not finish the turn within the declared deadline.";
|
|
55
|
+
};
|
|
56
|
+
readonly 'generation-cancelled': {
|
|
57
|
+
readonly code: "CANCELLED";
|
|
58
|
+
readonly retryable: false;
|
|
59
|
+
readonly message: "The Grok generation was cancelled by its caller.";
|
|
60
|
+
};
|
|
61
|
+
readonly 'agent-session-missing': {
|
|
62
|
+
readonly code: "UNAVAILABLE";
|
|
63
|
+
readonly retryable: false;
|
|
64
|
+
readonly message: "The Grok agent did not open a session.";
|
|
65
|
+
};
|
|
66
|
+
readonly 'agent-session-failed': {
|
|
67
|
+
readonly code: "UNAVAILABLE";
|
|
68
|
+
readonly retryable: false;
|
|
69
|
+
readonly message: "The Grok agent session failed.";
|
|
70
|
+
};
|
|
71
|
+
readonly 'agent-permission-refused': {
|
|
72
|
+
readonly code: "PERMISSION_DENIED";
|
|
73
|
+
readonly retryable: false;
|
|
74
|
+
readonly message: "The Grok agent asked for a permission this integration does not grant, so the turn was stopped.";
|
|
75
|
+
};
|
|
76
|
+
readonly 'unsupported-content': {
|
|
77
|
+
readonly code: "INVALID_INPUT";
|
|
78
|
+
readonly retryable: false;
|
|
79
|
+
readonly message: "The Grok text session cannot carry images, tool calls or tool results, so the request was refused instead of dropping them.";
|
|
80
|
+
};
|
|
81
|
+
readonly 'unsupported-modality': {
|
|
82
|
+
readonly code: "INVALID_INPUT";
|
|
83
|
+
readonly retryable: false;
|
|
84
|
+
readonly message: "The Grok text session only encodes text requests.";
|
|
85
|
+
};
|
|
86
|
+
readonly 'invalid-request': {
|
|
87
|
+
readonly code: "INVALID_INPUT";
|
|
88
|
+
readonly retryable: false;
|
|
89
|
+
readonly message: "The Grok text request is not a readable list of role and content messages.";
|
|
90
|
+
};
|
|
91
|
+
readonly 'request-too-large': {
|
|
92
|
+
readonly code: "INVALID_INPUT";
|
|
93
|
+
readonly retryable: false;
|
|
94
|
+
readonly message: "The Grok text request is larger than the declared maximum.";
|
|
95
|
+
};
|
|
96
|
+
readonly 'credentials-not-accepted': {
|
|
97
|
+
readonly code: "INVALID_INPUT";
|
|
98
|
+
readonly retryable: false;
|
|
99
|
+
readonly message: "The Grok subscription transport does not accept API credentials.";
|
|
100
|
+
};
|
|
101
|
+
readonly 'invalid-auth-method': {
|
|
102
|
+
readonly code: "INVALID_INPUT";
|
|
103
|
+
readonly retryable: false;
|
|
104
|
+
readonly message: "The Grok connection authMethod must be grok-cli or api-key.";
|
|
105
|
+
};
|
|
106
|
+
readonly 'invalid-connection': {
|
|
107
|
+
readonly code: "INVALID_INPUT";
|
|
108
|
+
readonly retryable: false;
|
|
109
|
+
readonly message: "The Grok connection configuration is not valid.";
|
|
110
|
+
};
|
|
111
|
+
readonly 'grok-build-refused': {
|
|
112
|
+
readonly code: "UNAVAILABLE";
|
|
113
|
+
readonly retryable: false;
|
|
114
|
+
readonly message: "Grok Build refused the request.";
|
|
115
|
+
};
|
|
116
|
+
readonly 'empty-assistant-content': {
|
|
117
|
+
readonly code: "UNAVAILABLE";
|
|
118
|
+
readonly retryable: false;
|
|
119
|
+
readonly message: "Grok Build wrote no assistant content.";
|
|
120
|
+
};
|
|
121
|
+
readonly 'prompt-file-unavailable': {
|
|
122
|
+
readonly code: "UNAVAILABLE";
|
|
123
|
+
readonly retryable: false;
|
|
124
|
+
readonly message: "No private file adapter on this host can hand the prompt to Grok Build, and the prompt is never placed on the command line.";
|
|
125
|
+
};
|
|
126
|
+
readonly 'prompt-file-cleanup-failed': {
|
|
127
|
+
readonly code: "UNAVAILABLE";
|
|
128
|
+
readonly retryable: false;
|
|
129
|
+
readonly message: "The prompt file handed to Grok Build could not be removed.";
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export type GrokRefusalReason = keyof typeof REFUSALS;
|
|
133
|
+
/** A typed refusal with its reason's fixed message; `details` are the caller's bounded facts and `cause` the underlying failure. */
|
|
134
|
+
export declare function grokRefusal(reason: GrokRefusalReason, extra?: {
|
|
135
|
+
readonly details?: CapabilityErrorDetails;
|
|
136
|
+
readonly cause?: unknown;
|
|
137
|
+
}): CapabilityError;
|
|
138
|
+
/** Whether `failure` is one of this package's own refusals (its message is fixed and safe to report as it is). */
|
|
139
|
+
export declare function isGrokRefusal(failure: CaughtFailure): failure is CapabilityError;
|
|
140
|
+
/**
|
|
141
|
+
* The owner's report of a failed operation: its own refusal (a subscription
|
|
142
|
+
* refusal or a Grok one) as it is, anything else as the fixed unavailability
|
|
143
|
+
* sentence, because the underlying diagnostic can carry configuration values.
|
|
144
|
+
*/
|
|
145
|
+
export declare function describeGrokFailure(failure: Failure): CapabilityError;
|
|
146
|
+
/** Text a peer wrote, reduced to a bounded, control-stripped excerpt, as a cause that carries nothing else. */
|
|
147
|
+
export declare function peerTextCause(text: string): Error;
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=grok-refusals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-refusals.d.ts","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-refusals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,eAAe,EAGf,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHoH,CAAC;AAEnI,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,QAAQ,CAAC;AAEtD,oIAAoI;AACpI,wBAAgB,WAAW,CAC1B,MAAM,EAAE,iBAAiB,EACzB,KAAK,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,sBAAsB,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACjF,eAAe,CAQjB;AAED,kHAAkH;AAClH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,IAAI,eAAe,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAErE;AAED,+GAA+G;AAC/G,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAEjD"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every typed refusal of the Grok agent, request and connection paths.
|
|
3
|
+
*
|
|
4
|
+
* One fixed message per reason. Text the child, the HTTP peer or the caller's
|
|
5
|
+
* request supplied never enters a message or `details`: it rides only in a
|
|
6
|
+
* bounded `cause`, which the logger scrubs and no projection prints.
|
|
7
|
+
*/
|
|
8
|
+
import { CapabilityError, isCapabilityError } from '@vibesdotdev/kernel';
|
|
9
|
+
import { boundedExcerpt } from '@vibesdotdev/external/jsonrpc/errors';
|
|
10
|
+
import { describeGrokSubscriptionFailure, GROK_SUBSCRIPTION_LOGIN_COMMAND } from "./grok-subscription.js";
|
|
11
|
+
const REFUSALS = {
|
|
12
|
+
'sign-in-required': {
|
|
13
|
+
code: 'AUTH_REQUIRED',
|
|
14
|
+
retryable: false,
|
|
15
|
+
message: `Sign in to the Grok subscription connection on this device. Run: ${GROK_SUBSCRIPTION_LOGIN_COMMAND}`
|
|
16
|
+
},
|
|
17
|
+
'agent-connect-failed': {
|
|
18
|
+
code: 'UNAVAILABLE',
|
|
19
|
+
retryable: true,
|
|
20
|
+
message: 'The Grok agent session could not be started.'
|
|
21
|
+
},
|
|
22
|
+
'sandbox-unavailable': {
|
|
23
|
+
code: 'UNAVAILABLE',
|
|
24
|
+
retryable: false,
|
|
25
|
+
message: 'Grok refused to start because its read-only sandbox cannot be applied on this host; Grok never runs without it.'
|
|
26
|
+
},
|
|
27
|
+
'agent-request-failed': {
|
|
28
|
+
code: 'UNAVAILABLE',
|
|
29
|
+
retryable: false,
|
|
30
|
+
message: 'The Grok agent answered a request with an error.'
|
|
31
|
+
},
|
|
32
|
+
'agent-closed': {
|
|
33
|
+
code: 'UNAVAILABLE',
|
|
34
|
+
retryable: true,
|
|
35
|
+
message: 'The Grok agent session ended before the turn finished.'
|
|
36
|
+
},
|
|
37
|
+
'agent-line-too-long': {
|
|
38
|
+
code: 'UNAVAILABLE',
|
|
39
|
+
retryable: false,
|
|
40
|
+
message: 'The Grok agent wrote a line longer than the declared maximum.'
|
|
41
|
+
},
|
|
42
|
+
'agent-record-invalid': {
|
|
43
|
+
code: 'UNAVAILABLE',
|
|
44
|
+
retryable: false,
|
|
45
|
+
message: 'The Grok agent sent output this integration cannot read.'
|
|
46
|
+
},
|
|
47
|
+
'agent-output-too-large': {
|
|
48
|
+
code: 'UNAVAILABLE',
|
|
49
|
+
retryable: false,
|
|
50
|
+
message: 'The Grok agent produced more output than the declared maximum.'
|
|
51
|
+
},
|
|
52
|
+
'agent-turn-timeout': {
|
|
53
|
+
code: 'TIMEOUT',
|
|
54
|
+
retryable: true,
|
|
55
|
+
message: 'The Grok agent did not finish the turn within the declared deadline.'
|
|
56
|
+
},
|
|
57
|
+
'generation-cancelled': {
|
|
58
|
+
code: 'CANCELLED',
|
|
59
|
+
retryable: false,
|
|
60
|
+
message: 'The Grok generation was cancelled by its caller.'
|
|
61
|
+
},
|
|
62
|
+
'agent-session-missing': {
|
|
63
|
+
code: 'UNAVAILABLE',
|
|
64
|
+
retryable: false,
|
|
65
|
+
message: 'The Grok agent did not open a session.'
|
|
66
|
+
},
|
|
67
|
+
'agent-session-failed': {
|
|
68
|
+
code: 'UNAVAILABLE',
|
|
69
|
+
retryable: false,
|
|
70
|
+
message: 'The Grok agent session failed.'
|
|
71
|
+
},
|
|
72
|
+
'agent-permission-refused': {
|
|
73
|
+
code: 'PERMISSION_DENIED',
|
|
74
|
+
retryable: false,
|
|
75
|
+
message: 'The Grok agent asked for a permission this integration does not grant, so the turn was stopped.'
|
|
76
|
+
},
|
|
77
|
+
'unsupported-content': {
|
|
78
|
+
code: 'INVALID_INPUT',
|
|
79
|
+
retryable: false,
|
|
80
|
+
message: 'The Grok text session cannot carry images, tool calls or tool results, so the request was refused instead of dropping them.'
|
|
81
|
+
},
|
|
82
|
+
'unsupported-modality': {
|
|
83
|
+
code: 'INVALID_INPUT',
|
|
84
|
+
retryable: false,
|
|
85
|
+
message: 'The Grok text session only encodes text requests.'
|
|
86
|
+
},
|
|
87
|
+
'invalid-request': {
|
|
88
|
+
code: 'INVALID_INPUT',
|
|
89
|
+
retryable: false,
|
|
90
|
+
message: 'The Grok text request is not a readable list of role and content messages.'
|
|
91
|
+
},
|
|
92
|
+
'request-too-large': {
|
|
93
|
+
code: 'INVALID_INPUT',
|
|
94
|
+
retryable: false,
|
|
95
|
+
message: 'The Grok text request is larger than the declared maximum.'
|
|
96
|
+
},
|
|
97
|
+
'credentials-not-accepted': {
|
|
98
|
+
code: 'INVALID_INPUT',
|
|
99
|
+
retryable: false,
|
|
100
|
+
message: 'The Grok subscription transport does not accept API credentials.'
|
|
101
|
+
},
|
|
102
|
+
'invalid-auth-method': {
|
|
103
|
+
code: 'INVALID_INPUT',
|
|
104
|
+
retryable: false,
|
|
105
|
+
message: 'The Grok connection authMethod must be grok-cli or api-key.'
|
|
106
|
+
},
|
|
107
|
+
'invalid-connection': {
|
|
108
|
+
code: 'INVALID_INPUT',
|
|
109
|
+
retryable: false,
|
|
110
|
+
message: 'The Grok connection configuration is not valid.'
|
|
111
|
+
},
|
|
112
|
+
'grok-build-refused': {
|
|
113
|
+
code: 'UNAVAILABLE',
|
|
114
|
+
retryable: false,
|
|
115
|
+
message: 'Grok Build refused the request.'
|
|
116
|
+
},
|
|
117
|
+
'empty-assistant-content': {
|
|
118
|
+
code: 'UNAVAILABLE',
|
|
119
|
+
retryable: false,
|
|
120
|
+
message: 'Grok Build wrote no assistant content.'
|
|
121
|
+
},
|
|
122
|
+
'prompt-file-unavailable': {
|
|
123
|
+
code: 'UNAVAILABLE',
|
|
124
|
+
retryable: false,
|
|
125
|
+
message: 'No private file adapter on this host can hand the prompt to Grok Build, and the prompt is never placed on the command line.'
|
|
126
|
+
},
|
|
127
|
+
'prompt-file-cleanup-failed': {
|
|
128
|
+
code: 'UNAVAILABLE',
|
|
129
|
+
retryable: false,
|
|
130
|
+
message: 'The prompt file handed to Grok Build could not be removed.'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/** A typed refusal with its reason's fixed message; `details` are the caller's bounded facts and `cause` the underlying failure. */
|
|
134
|
+
export function grokRefusal(reason, extra = {}) {
|
|
135
|
+
const refusal = REFUSALS[reason];
|
|
136
|
+
return new CapabilityError(refusal.message, refusal.code, {
|
|
137
|
+
reason,
|
|
138
|
+
retryable: refusal.retryable,
|
|
139
|
+
details: extra.details,
|
|
140
|
+
cause: extra.cause
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** Whether `failure` is one of this package's own refusals (its message is fixed and safe to report as it is). */
|
|
144
|
+
export function isGrokRefusal(failure) {
|
|
145
|
+
return isCapabilityError(failure) && Object.hasOwn(REFUSALS, failure.reason);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The owner's report of a failed operation: its own refusal (a subscription
|
|
149
|
+
* refusal or a Grok one) as it is, anything else as the fixed unavailability
|
|
150
|
+
* sentence, because the underlying diagnostic can carry configuration values.
|
|
151
|
+
*/
|
|
152
|
+
export function describeGrokFailure(failure) {
|
|
153
|
+
return isGrokRefusal(failure.cause) ? failure.cause : describeGrokSubscriptionFailure(failure).error;
|
|
154
|
+
}
|
|
155
|
+
/** Text a peer wrote, reduced to a bounded, control-stripped excerpt, as a cause that carries nothing else. */
|
|
156
|
+
export function peerTextCause(text) {
|
|
157
|
+
return new Error(boundedExcerpt(text));
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=grok-refusals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-refusals.js","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-refusals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,eAAe,EAC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EAAE,KAAK;QAChB,OAAO,EAAE,6HAA6H;KACtI;IACD,4BAA4B,EAAE;QAC7B,IAAI,EAAE,aAAa;QACnB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,4DAA4D;KACrE;CACgI,CAAC;AAInI,oIAAoI;AACpI,MAAM,UAAU,WAAW,CAC1B,MAAyB,EACzB,QAAiF,EAAE;IAEnF,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE;QACzD,MAAM;QACN,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;KAClB,CAAC,CAAC;AACJ,CAAC;AAED,kHAAkH;AAClH,MAAM,UAAU,aAAa,CAAC,OAAsB;IACnD,OAAO,iBAAiB,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IACnD,OAAO,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,+BAA+B,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;AACtG,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,OAAO,IAAI,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How Grok says it cannot apply the sandbox it was asked for. Measured on grok
|
|
3
|
+
* 1.0.47 for `agent stdio` and for `--prompt-file` runs, with a sandbox that
|
|
4
|
+
* cannot be applied (a symlinked `/var/run/docker.sock`) and with one that does
|
|
5
|
+
* not exist: exit code 1, nothing on stdout, and on stderr a `warning:` line with
|
|
6
|
+
* the cause followed by one fixed `error:` sentence ending in this marker. The
|
|
7
|
+
* marker is a constant of the binary; the cause line varies and is never read.
|
|
8
|
+
* Exit code 1 alone is not the signal (an unrelated failure also exits 1).
|
|
9
|
+
*/
|
|
10
|
+
export declare const GROK_SANDBOX_REFUSAL_MARKER = "Refusing to start with its protections missing.";
|
|
11
|
+
/** Whether `text` (a run's captured stderr) carries Grok's sandbox refusal. */
|
|
12
|
+
export declare function carriesSandboxRefusal(text: string): boolean;
|
|
13
|
+
/** Latches once the marker has been seen in a stream, holding only a short tail so the marker is found across chunk boundaries. */
|
|
14
|
+
export declare class SandboxMarkerWatch {
|
|
15
|
+
#private;
|
|
16
|
+
get seen(): boolean;
|
|
17
|
+
push(text: string): void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Watch a child's stderr for the sandbox refusal without taking it from the
|
|
21
|
+
* client that drains it: the stream is teed, `forClient` goes on to the client and
|
|
22
|
+
* the other branch is read here, in constant memory. `done` settles when the
|
|
23
|
+
* watched branch ends or fails (a failed read just ends the watch).
|
|
24
|
+
*/
|
|
25
|
+
export interface TappedStderr {
|
|
26
|
+
readonly forClient: ReadableStream<Uint8Array> | null;
|
|
27
|
+
readonly done: Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare function tapSandboxMarker(stderr: ReadableStream<Uint8Array> | null, watch: SandboxMarkerWatch): TappedStderr;
|
|
30
|
+
//# sourceMappingURL=grok-sandbox-signal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-sandbox-signal.d.ts","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-sandbox-signal.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,oDAAoD,CAAC;AAE7F,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED,mIAAmI;AACnI,qBAAa,kBAAkB;;IAI9B,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAKxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;IACtD,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,kBAAkB,GAAG,YAAY,CAInH"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { settle } from "../../../outcome.js";
|
|
2
|
+
/**
|
|
3
|
+
* How Grok says it cannot apply the sandbox it was asked for. Measured on grok
|
|
4
|
+
* 1.0.47 for `agent stdio` and for `--prompt-file` runs, with a sandbox that
|
|
5
|
+
* cannot be applied (a symlinked `/var/run/docker.sock`) and with one that does
|
|
6
|
+
* not exist: exit code 1, nothing on stdout, and on stderr a `warning:` line with
|
|
7
|
+
* the cause followed by one fixed `error:` sentence ending in this marker. The
|
|
8
|
+
* marker is a constant of the binary; the cause line varies and is never read.
|
|
9
|
+
* Exit code 1 alone is not the signal (an unrelated failure also exits 1).
|
|
10
|
+
*/
|
|
11
|
+
export const GROK_SANDBOX_REFUSAL_MARKER = 'Refusing to start with its protections missing.';
|
|
12
|
+
/** Whether `text` (a run's captured stderr) carries Grok's sandbox refusal. */
|
|
13
|
+
export function carriesSandboxRefusal(text) {
|
|
14
|
+
return text.includes(GROK_SANDBOX_REFUSAL_MARKER);
|
|
15
|
+
}
|
|
16
|
+
/** Latches once the marker has been seen in a stream, holding only a short tail so the marker is found across chunk boundaries. */
|
|
17
|
+
export class SandboxMarkerWatch {
|
|
18
|
+
#tail = '';
|
|
19
|
+
#seen = false;
|
|
20
|
+
get seen() {
|
|
21
|
+
return this.#seen;
|
|
22
|
+
}
|
|
23
|
+
push(text) {
|
|
24
|
+
if (this.#seen)
|
|
25
|
+
return;
|
|
26
|
+
this.#tail = (this.#tail + text).slice(-2 * GROK_SANDBOX_REFUSAL_MARKER.length);
|
|
27
|
+
this.#seen = carriesSandboxRefusal(this.#tail);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function tapSandboxMarker(stderr, watch) {
|
|
31
|
+
if (!stderr)
|
|
32
|
+
return { forClient: null, done: Promise.resolve() };
|
|
33
|
+
const [forClient, forWatch] = stderr.tee();
|
|
34
|
+
return { forClient, done: scan(forWatch, watch) };
|
|
35
|
+
}
|
|
36
|
+
async function scan(stream, watch) {
|
|
37
|
+
const reader = stream.getReader();
|
|
38
|
+
const decoder = new TextDecoder();
|
|
39
|
+
for (;;) {
|
|
40
|
+
const read = await settle(() => reader.read());
|
|
41
|
+
if (!read.ok || read.value.done)
|
|
42
|
+
return;
|
|
43
|
+
watch.push(decoder.decode(read.value.value, { stream: true }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=grok-sandbox-signal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-sandbox-signal.js","sourceRoot":"","sources":["../../../../src/ai/providers/grok/grok-sandbox-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,iDAAiD,CAAC;AAE7F,+EAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,IAAY;IACjD,OAAO,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,CAAC;AACnD,CAAC;AAED,mIAAmI;AACnI,MAAM,OAAO,kBAAkB;IAC9B,KAAK,GAAG,EAAE,CAAC;IACX,KAAK,GAAG,KAAK,CAAC;IAEd,IAAI,IAAI;QACP,OAAO,IAAI,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