@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 @@
|
|
|
1
|
+
{"version":3,"file":"ai.providers.grok.docs.descriptor.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,QAAA,MAAM,UAAU,EAAE,mBAkBjB,CAAC;AACF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const descriptor = {
|
|
2
|
+
kind: 'docs/topic', id: 'ai.providers.grok', title: 'Grok provider', summary: 'Use Grok through Grok Build or runtime-resolved xAI credentials.',
|
|
3
|
+
body: { type: 'markdown', sourceType: 'raw', source: `# Grok provider
|
|
4
|
+
|
|
5
|
+
\`@vibesdotdev/integrations-grok\` owns Grok provider assets and the Grok Build
|
|
6
|
+
wire spec. Framework retains provider-neutral kinds. Consumer runtimes can reuse
|
|
7
|
+
the official Grok Build session through its agent protocol; cloud runtimes resolve
|
|
8
|
+
an \`XAI_API_KEY\` credential reference. Generation resolves \`ai/generation\`.
|
|
9
|
+
|
|
10
|
+
Consumer hosts compose \`/ai/plugin\` (also \`/ai/consumer.plugin\`); cloud/browser
|
|
11
|
+
hosts compose \`/ai/shared.plugin\`. Resolve provider, recommendation, spec and
|
|
12
|
+
transport implementations through their AI kinds. Subscription transports refuse
|
|
13
|
+
cloud resolution with \`NOT_FOUND / not-registered\`.
|
|
14
|
+
|
|
15
|
+
Current model guidance: https://docs.x.ai/developers/models
|
|
16
|
+
` },
|
|
17
|
+
tags: ['ai', 'providers', 'grok', 'xai'], parent: 'ai.providers', order: 4,
|
|
18
|
+
surfaces: ['cli', 'web', 'in-app'], hardware: ['consumer', 'cloud'], enabled: true
|
|
19
|
+
};
|
|
20
|
+
export default descriptor;
|
|
21
|
+
//# sourceMappingURL=ai.providers.grok.docs.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.providers.grok.docs.descriptor.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/docs/ai.providers.grok.docs.descriptor.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,GAAwB;IACvC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,mBAAmB,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,kEAAkE;IAChJ,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE;;;;;;;;;;;;;CAarD,EAAE;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;IAC1E,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI;CAClF,CAAC;AACF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RuntimeRef } from '@vibesdotdev/kernel';
|
|
2
|
+
/**
|
|
3
|
+
* The caller's declared deadline for one generation, spread over the requests
|
|
4
|
+
* it makes (handshake, `session/new`, `session/prompt`). The deadline is the
|
|
5
|
+
* caller's `options.timeoutMs` and nothing else: with none declared a request
|
|
6
|
+
* waits for its answer, its caller's abort, or the agent's end. No ceiling is
|
|
7
|
+
* hidden here.
|
|
8
|
+
*/
|
|
9
|
+
export interface GrokAgentBudget {
|
|
10
|
+
/** Milliseconds left for the next request, or `undefined` when the caller declared no deadline. Throws `agent-turn-timeout` once spent. */
|
|
11
|
+
remaining(stage: string): number | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function createGrokAgentBudget(runtime: Pick<RuntimeRef, 'lifecycle'>, timeoutMs: number | undefined): GrokAgentBudget;
|
|
14
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQtD;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,2IAA2I;IAC3I,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC7C;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,EACtC,SAAS,EAAE,MAAM,GAAG,SAAS,GAC3B,eAAe,CAcjB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { grokRefusal } from "../grok-refusals.js";
|
|
3
|
+
/** The most a host timer honours; the shared client refuses a longer deadline. */
|
|
4
|
+
const MAX_DEADLINE_MS = 2_147_483_647;
|
|
5
|
+
const TimeoutMsSchema = z.int().min(1).max(MAX_DEADLINE_MS);
|
|
6
|
+
export function createGrokAgentBudget(runtime, timeoutMs) {
|
|
7
|
+
if (timeoutMs === undefined)
|
|
8
|
+
return { remaining: () => undefined };
|
|
9
|
+
const declared = TimeoutMsSchema.safeParse(timeoutMs);
|
|
10
|
+
if (!declared.success) {
|
|
11
|
+
throw grokRefusal('invalid-request', { details: { field: 'timeoutMs' } });
|
|
12
|
+
}
|
|
13
|
+
const started = runtime.lifecycle.now();
|
|
14
|
+
return {
|
|
15
|
+
remaining(stage) {
|
|
16
|
+
const left = declared.data - (runtime.lifecycle.now() - started);
|
|
17
|
+
if (left < 1)
|
|
18
|
+
throw grokRefusal('agent-turn-timeout', { details: { stage, deadlineMs: declared.data } });
|
|
19
|
+
return Math.ceil(left);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/budget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,kFAAkF;AAClF,MAAM,eAAe,GAAG,aAAa,CAAC;AACtC,MAAM,eAAe,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAc5D,MAAM,UAAU,qBAAqB,CACpC,OAAsC,EACtC,SAA6B;IAE7B,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;IACnE,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,WAAW,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;IACxC,OAAO;QACN,SAAS,CAAC,KAAK;YACd,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC;YACjE,IAAI,IAAI,GAAG,CAAC;gBAAE,MAAM,WAAW,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzG,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type RuntimeRef } from '@vibesdotdev/kernel';
|
|
2
|
+
import { type JsonRpcChild, type JsonRpcProcess } from '@vibesdotdev/external/jsonrpc';
|
|
3
|
+
import type { GrokAgentBudget } from './budget.ts';
|
|
4
|
+
/** Starts `grok agent stdio` and returns the process the shared client drives. */
|
|
5
|
+
export type GrokAgentSpawner = () => Promise<JsonRpcProcess> | JsonRpcProcess;
|
|
6
|
+
/** The ACP method the agent uses to ask the client to approve a tool; this client never approves one. */
|
|
7
|
+
export declare const GROK_AGENT_PERMISSION_METHOD = "session/request_permission";
|
|
8
|
+
export interface GrokAgentConnectOptions {
|
|
9
|
+
/** The runtime whose lifecycle owns the child's timers and whose logger receives the client's value-free diagnostics. */
|
|
10
|
+
readonly runtime: RuntimeRef;
|
|
11
|
+
readonly spawn: GrokAgentSpawner;
|
|
12
|
+
/** The caller's deadline, spread over the handshake and the turn. */
|
|
13
|
+
readonly budget: GrokAgentBudget;
|
|
14
|
+
readonly signal?: AbortSignal | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* One ACP session's process: the shared JSON-RPC client over `grok agent stdio`
|
|
18
|
+
* after `initialize` and `authenticate`. Authentication is `cached_token`: the
|
|
19
|
+
* CLI session, never an API key and never a bearer this process reads from disk.
|
|
20
|
+
*
|
|
21
|
+
* The client marks itself closed when the child ends or its stream fails, so a
|
|
22
|
+
* transport drops a dead connection and spawns a new one.
|
|
23
|
+
*/
|
|
24
|
+
export declare class GrokAgentConnection {
|
|
25
|
+
#private;
|
|
26
|
+
readonly client: JsonRpcChild;
|
|
27
|
+
private constructor();
|
|
28
|
+
/** Whether the agent asked for a permission (answered `-32601`, the turn stopped). */
|
|
29
|
+
get permissionRequested(): boolean;
|
|
30
|
+
/** Call `listener` when the agent asks for a permission; once. */
|
|
31
|
+
onPermissionRequest(listener: () => void): void;
|
|
32
|
+
/** SIGTERM, grace, SIGKILL and a joined exit, through the shared client. */
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
static open(options: GrokAgentConnectOptions): Promise<GrokAgentConnection>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAGN,KAAK,YAAY,EAEjB,KAAK,cAAc,EACnB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD,kFAAkF;AAClF,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AAE9E,yGAAyG;AACzG,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AAEzE,MAAM,WAAW,uBAAuB;IACvC,yHAAyH;IACzH,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC1C;AAmBD;;;;;;;GAOG;AACH,qBAAa,mBAAmB;;IAI9B,QAAQ,CAAC,MAAM,EAAE,YAAY;IAD9B,OAAO;IAOP,sFAAsF;IACtF,IAAI,mBAAmB,IAAI,OAAO,CAEjC;IAED,kEAAkE;IAClE,mBAAmB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAI/C,4EAA4E;IAC5E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;WAIT,IAAI,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAkEjF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { isCapabilityError } from '@vibesdotdev/kernel';
|
|
2
|
+
import { getLogger } from '@vibesdotdev/logging';
|
|
3
|
+
import { boundedExcerpt, createJsonRpcChild } from '@vibesdotdev/external/jsonrpc';
|
|
4
|
+
import { asError, settle } from "../../../../outcome.js";
|
|
5
|
+
import { grokRefusal } from "../grok-refusals.js";
|
|
6
|
+
import { SandboxMarkerWatch, tapSandboxMarker } from "../grok-sandbox-signal.js";
|
|
7
|
+
import { grokAgentFailure } from "./failures.js";
|
|
8
|
+
import { GROK_AGENT_LIMITS, GrokAgentInitializeResultSchema } from "./protocol.js";
|
|
9
|
+
/** The ACP method the agent uses to ask the client to approve a tool; this client never approves one. */
|
|
10
|
+
export const GROK_AGENT_PERMISSION_METHOD = 'session/request_permission';
|
|
11
|
+
/** Whether the agent asked for a permission, and who to tell: the client reports it before the connection exists. */
|
|
12
|
+
class PermissionWatch {
|
|
13
|
+
requested = false;
|
|
14
|
+
#listener;
|
|
15
|
+
asked() {
|
|
16
|
+
if (this.requested)
|
|
17
|
+
return;
|
|
18
|
+
this.requested = true;
|
|
19
|
+
this.#listener?.();
|
|
20
|
+
}
|
|
21
|
+
onAsked(listener) {
|
|
22
|
+
this.#listener = listener;
|
|
23
|
+
if (this.requested)
|
|
24
|
+
listener();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One ACP session's process: the shared JSON-RPC client over `grok agent stdio`
|
|
29
|
+
* after `initialize` and `authenticate`. Authentication is `cached_token`: the
|
|
30
|
+
* CLI session, never an API key and never a bearer this process reads from disk.
|
|
31
|
+
*
|
|
32
|
+
* The client marks itself closed when the child ends or its stream fails, so a
|
|
33
|
+
* transport drops a dead connection and spawns a new one.
|
|
34
|
+
*/
|
|
35
|
+
export class GrokAgentConnection {
|
|
36
|
+
client;
|
|
37
|
+
#watch;
|
|
38
|
+
constructor(client, watch) {
|
|
39
|
+
this.client = client;
|
|
40
|
+
this.#watch = watch;
|
|
41
|
+
}
|
|
42
|
+
/** Whether the agent asked for a permission (answered `-32601`, the turn stopped). */
|
|
43
|
+
get permissionRequested() {
|
|
44
|
+
return this.#watch.requested;
|
|
45
|
+
}
|
|
46
|
+
/** Call `listener` when the agent asks for a permission; once. */
|
|
47
|
+
onPermissionRequest(listener) {
|
|
48
|
+
this.#watch.onAsked(listener);
|
|
49
|
+
}
|
|
50
|
+
/** SIGTERM, grace, SIGKILL and a joined exit, through the shared client. */
|
|
51
|
+
close() {
|
|
52
|
+
return this.client.close();
|
|
53
|
+
}
|
|
54
|
+
static async open(options) {
|
|
55
|
+
const { runtime, budget, signal } = options;
|
|
56
|
+
if (signal?.aborted)
|
|
57
|
+
throw grokRefusal('generation-cancelled', { details: { stage: 'connect' } });
|
|
58
|
+
const logger = getLogger('integrations-grok', runtime);
|
|
59
|
+
const watch = new PermissionWatch();
|
|
60
|
+
// Only value-free facts are logged: a method name or a message is the child's text.
|
|
61
|
+
const diagnostics = (event) => {
|
|
62
|
+
switch (event.kind) {
|
|
63
|
+
case 'unhandled-request': {
|
|
64
|
+
// The client already answered -32601. A permission request also stops the turn.
|
|
65
|
+
const permission = boundedExcerpt(event.method) === GROK_AGENT_PERMISSION_METHOD;
|
|
66
|
+
if (permission)
|
|
67
|
+
watch.asked();
|
|
68
|
+
logger.warn('grok agent request refused', { permission });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
case 'unmatched-response':
|
|
72
|
+
logger.warn('grok agent client diagnostic', { kind: event.kind, late: event.late });
|
|
73
|
+
return;
|
|
74
|
+
case 'cleanup-failed':
|
|
75
|
+
logger.warn('grok agent client diagnostic', { kind: event.kind, stage: event.stage });
|
|
76
|
+
return;
|
|
77
|
+
case 'join-timeout':
|
|
78
|
+
logger.warn('grok agent client diagnostic', { kind: event.kind, pending: event.pending });
|
|
79
|
+
return;
|
|
80
|
+
default:
|
|
81
|
+
logger.warn('grok agent client diagnostic', { kind: event.kind });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// stderr is watched for Grok's fixed sandbox refusal (never read for text); the client drains its own branch.
|
|
85
|
+
const sandbox = new SandboxMarkerWatch();
|
|
86
|
+
let scanned = Promise.resolve();
|
|
87
|
+
const spawn = async () => {
|
|
88
|
+
const process = await options.spawn();
|
|
89
|
+
const tapped = tapSandboxMarker(process.stderr, sandbox);
|
|
90
|
+
scanned = tapped.done;
|
|
91
|
+
return {
|
|
92
|
+
stdin: process.stdin,
|
|
93
|
+
stdout: process.stdout,
|
|
94
|
+
stderr: tapped.forClient,
|
|
95
|
+
exited: process.exited,
|
|
96
|
+
kill: (signal) => process.kill(signal)
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const opened = await settle(() => createJsonRpcChild({
|
|
100
|
+
runtime,
|
|
101
|
+
spawn,
|
|
102
|
+
maxLineBytes: GROK_AGENT_LIMITS.maxLineBytes,
|
|
103
|
+
graceMs: GROK_AGENT_LIMITS.graceMs,
|
|
104
|
+
envelope: 'jsonrpc-2.0',
|
|
105
|
+
diagnostics,
|
|
106
|
+
handshake: (child) => handshake(child, budget, signal)
|
|
107
|
+
}));
|
|
108
|
+
if (!opened.ok) {
|
|
109
|
+
// The child is stopped and joined by now, so its stderr has ended: let the watch finish, bounded.
|
|
110
|
+
await settle(() => runtime.lifecycle.wait(() => scanned, { timeoutMs: 500, reason: 'grok sandbox marker scan' }));
|
|
111
|
+
const failure = opened.cause;
|
|
112
|
+
// Only a child that exited while starting, having said so: a refusal to run unprotected, not a generic start failure.
|
|
113
|
+
if (sandbox.seen && isCapabilityError(failure) && failure.reason === 'jsonrpc-child-exited') {
|
|
114
|
+
throw grokRefusal('sandbox-unavailable', { details: { stage: 'connect', exitCode: failure.details?.exitCode }, cause: failure });
|
|
115
|
+
}
|
|
116
|
+
throw grokAgentFailure(failure, 'connect');
|
|
117
|
+
}
|
|
118
|
+
return new GrokAgentConnection(opened.value, watch);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** `initialize`, then `authenticate` by the saved login. Only a real sign-in need is `AUTH_REQUIRED`. */
|
|
122
|
+
async function handshake(client, budget, signal) {
|
|
123
|
+
const init = await client.requestParsed('initialize', { protocolVersion: 1, clientCapabilities: {} }, GrokAgentInitializeResultSchema, { signal, deadlineMs: budget.remaining('initialize') });
|
|
124
|
+
if (!(init.authMethods ?? []).some((method) => method.id === 'cached_token')) {
|
|
125
|
+
throw grokRefusal('sign-in-required', { details: { stage: 'initialize' } });
|
|
126
|
+
}
|
|
127
|
+
const deadlineMs = budget.remaining('authenticate');
|
|
128
|
+
const authenticated = await settle(() => client.request('authenticate', { methodId: 'cached_token', _meta: { headless: true } }, { signal, deadlineMs }));
|
|
129
|
+
if (authenticated.ok)
|
|
130
|
+
return;
|
|
131
|
+
// The agent advertised the saved login and then declined it: that is the CLI reporting it is signed out.
|
|
132
|
+
if (isCapabilityError(authenticated.cause) && authenticated.cause.reason === 'jsonrpc-error') {
|
|
133
|
+
throw grokRefusal('sign-in-required', { details: { stage: 'authenticate' }, cause: authenticated.cause });
|
|
134
|
+
}
|
|
135
|
+
throw asError(authenticated.cause);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":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IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,cAAc,CAAC,EAAE,CAAC;QAC9E,MAAM,WAAW,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,CACvC,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAC/G,CAAC;IACF,IAAI,aAAa,CAAC,EAAE;QAAE,OAAO;IAC7B,yGAAyG;IACzG,IAAI,iBAAiB,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,MAAM,KAAK,eAAe,EAAE,CAAC;QAC9F,MAAM,WAAW,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3G,CAAC;IACD,MAAM,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CapabilityError, type CaughtFailure } from '@vibesdotdev/kernel';
|
|
2
|
+
/** Where in an agent call a failure happened: the handshake, opening the session, or the turn. */
|
|
3
|
+
export type GrokAgentStage = 'connect' | 'session' | 'prompt';
|
|
4
|
+
/**
|
|
5
|
+
* The Grok refusal for what the shared JSON-RPC client reported. The client's
|
|
6
|
+
* own typed failure rides as the `cause` (its child text is a bounded excerpt
|
|
7
|
+
* in its `details`, which no projection prints); the message is this package's
|
|
8
|
+
* fixed sentence. Whatever is not the client's is this package's own refusal
|
|
9
|
+
* and passes through; anything else is a failed session with its cause kept.
|
|
10
|
+
*/
|
|
11
|
+
export declare function grokAgentFailure(failure: CaughtFailure, stage: GrokAgentStage): CapabilityError;
|
|
12
|
+
//# sourceMappingURL=failures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/failures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIlG,kGAAkG;AAClG,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AA0B9D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,cAAc,GAAG,eAAe,CAW/F"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isCapabilityError } from '@vibesdotdev/kernel';
|
|
2
|
+
import { asError } from "../../../../outcome.js";
|
|
3
|
+
import { grokRefusal } from "../grok-refusals.js";
|
|
4
|
+
/** This package's reason for one of the shared JSON-RPC client's reasons, or `undefined` for a reason that is not the client's. */
|
|
5
|
+
function grokReasonFor(reason) {
|
|
6
|
+
switch (reason) {
|
|
7
|
+
case 'jsonrpc-cancelled':
|
|
8
|
+
return 'generation-cancelled';
|
|
9
|
+
case 'jsonrpc-timeout':
|
|
10
|
+
return 'agent-turn-timeout';
|
|
11
|
+
case 'jsonrpc-protocol-invalid':
|
|
12
|
+
return 'agent-record-invalid';
|
|
13
|
+
case 'jsonrpc-line-too-large':
|
|
14
|
+
return 'agent-line-too-long';
|
|
15
|
+
case 'jsonrpc-notification-overflow':
|
|
16
|
+
return 'agent-output-too-large';
|
|
17
|
+
case 'jsonrpc-closed':
|
|
18
|
+
case 'jsonrpc-kill-failed':
|
|
19
|
+
case 'jsonrpc-child-exited':
|
|
20
|
+
return 'agent-closed';
|
|
21
|
+
case 'jsonrpc-error':
|
|
22
|
+
return 'agent-request-failed';
|
|
23
|
+
default:
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The Grok refusal for what the shared JSON-RPC client reported. The client's
|
|
29
|
+
* own typed failure rides as the `cause` (its child text is a bounded excerpt
|
|
30
|
+
* in its `details`, which no projection prints); the message is this package's
|
|
31
|
+
* fixed sentence. Whatever is not the client's is this package's own refusal
|
|
32
|
+
* and passes through; anything else is a failed session with its cause kept.
|
|
33
|
+
*/
|
|
34
|
+
export function grokAgentFailure(failure, stage) {
|
|
35
|
+
if (!isCapabilityError(failure)) {
|
|
36
|
+
return grokRefusal(stage === 'connect' ? 'agent-connect-failed' : 'agent-session-failed', { details: { stage }, cause: asError(failure) });
|
|
37
|
+
}
|
|
38
|
+
if (!failure.reason.startsWith('jsonrpc-'))
|
|
39
|
+
return failure;
|
|
40
|
+
const details = { stage };
|
|
41
|
+
// A failure to start is a connect failure whatever the client called it, unless the caller's own deadline or abort ended it.
|
|
42
|
+
if (stage === 'connect' && failure.reason !== 'jsonrpc-cancelled' && failure.reason !== 'jsonrpc-timeout') {
|
|
43
|
+
return grokRefusal('agent-connect-failed', { details, cause: failure });
|
|
44
|
+
}
|
|
45
|
+
return grokRefusal(grokReasonFor(failure.reason) ?? 'agent-session-failed', { details, cause: failure });
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=failures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failures.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/failures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA4C,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,WAAW,EAA0B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AAC,CAAC;IACzE,CAAC;IACD,OAAO,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,sBAAsB,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC1G,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription turns over Grok's documented ACP session (`grok agent stdio`).
|
|
3
|
+
* The CLI owns the login. This spec does not accept or persist tokens.
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: "ai/spec";
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
modalities: ("image" | "text" | "audio" | "video" | "embedding" | "transcription" | "evaluation" | "speech" | "ocr")[];
|
|
11
|
+
streamFraming: "none" | "sse" | "sse-named" | "ndjson" | "binary-chunked" | "ws-frame";
|
|
12
|
+
toolCallEnvelope: string;
|
|
13
|
+
transports: string[];
|
|
14
|
+
external: boolean;
|
|
15
|
+
priority: number;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
capabilities?: ("streaming" | "json_mode" | "text_generation" | "chat_completion" | "function_calling" | "embedding_generation" | "image_generation_text_to_image" | "image_generation_image_to_image" | "image_generation_inpainting" | "image_generation_outpainting" | "image_upscaling" | "image_editing_via_instructions" | "audio_generation_text_to_speech" | "audio_generation_voice_cloning" | "audio_generation_music" | "audio_generation_sound_effects" | "audio_transcription" | "audio_transcription_realtime" | "video_generation_text_to_video" | "workflow_execution" | "code_generation" | "image_understanding" | "structured_evaluation")[] | undefined;
|
|
18
|
+
imageControls?: {
|
|
19
|
+
steps: boolean;
|
|
20
|
+
cfg: boolean;
|
|
21
|
+
sampler: boolean;
|
|
22
|
+
scheduler: boolean;
|
|
23
|
+
negativePrompt: boolean;
|
|
24
|
+
seed: boolean;
|
|
25
|
+
} | undefined;
|
|
26
|
+
tags?: string[] | undefined;
|
|
27
|
+
};
|
|
28
|
+
export default _default;
|
|
29
|
+
//# sourceMappingURL=grok-agent.spec.descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.spec.descriptor.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.ts"],"names":[],"mappings":"AAEA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAYG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createAISpecDescriptor } from '@vibesdotdev/ai/specs/schemas/descriptor';
|
|
2
|
+
/**
|
|
3
|
+
* Subscription turns over Grok's documented ACP session (`grok agent stdio`).
|
|
4
|
+
* The CLI owns the login. This spec does not accept or persist tokens.
|
|
5
|
+
*/
|
|
6
|
+
export default createAISpecDescriptor({
|
|
7
|
+
id: 'grok-agent',
|
|
8
|
+
name: 'Grok Agent Session',
|
|
9
|
+
description: 'Subscription-backed, provider-managed agent turns over the Grok ACP stdio session.',
|
|
10
|
+
modalities: ['text'],
|
|
11
|
+
streamFraming: 'ndjson',
|
|
12
|
+
toolCallEnvelope: 'openai-tool-calls',
|
|
13
|
+
transports: ['grok-agent'],
|
|
14
|
+
capabilities: ['text_generation', 'function_calling'],
|
|
15
|
+
priority: 110,
|
|
16
|
+
tags: ['grok', 'xai', 'acp', 'grok-managed-auth', 'provider-managed-tool-loop', 'consumer-only']
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=grok-agent.spec.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.spec.descriptor.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.spec.descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAElF;;;GAGG;AACH,eAAe,sBAAsB,CAAC;IACrC,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACV,oFAAoF;IACrF,UAAU,EAAE,CAAC,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ;IACvB,gBAAgB,EAAE,mBAAmB;IACrC,UAAU,EAAE,CAAC,YAAY,CAAC;IAC1B,YAAY,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;IACrD,QAAQ,EAAE,GAAG;IACb,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,eAAe,CAAC;CAChG,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AISpecInterface, DecodedEvent, SpecCallContext, WireRequest, WireResponseChunk } from '@vibesdotdev/ai/specs/interfaces';
|
|
2
|
+
import type { GenerationRequest } from '@vibesdotdev/ai/interfaces';
|
|
3
|
+
import type { Modality } from '@vibesdotdev/ai/models/schemas';
|
|
4
|
+
export declare class GrokAgentSpec implements AISpecInterface {
|
|
5
|
+
readonly descriptor: {
|
|
6
|
+
id: string;
|
|
7
|
+
kind: "ai/spec";
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
modalities: ("image" | "text" | "audio" | "video" | "embedding" | "transcription" | "evaluation" | "speech" | "ocr")[];
|
|
11
|
+
streamFraming: "none" | "sse" | "sse-named" | "ndjson" | "binary-chunked" | "ws-frame";
|
|
12
|
+
toolCallEnvelope: string;
|
|
13
|
+
transports: string[];
|
|
14
|
+
external: boolean;
|
|
15
|
+
priority: number;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
capabilities?: ("streaming" | "json_mode" | "text_generation" | "chat_completion" | "function_calling" | "embedding_generation" | "image_generation_text_to_image" | "image_generation_image_to_image" | "image_generation_inpainting" | "image_generation_outpainting" | "image_upscaling" | "image_editing_via_instructions" | "audio_generation_text_to_speech" | "audio_generation_voice_cloning" | "audio_generation_music" | "audio_generation_sound_effects" | "audio_transcription" | "audio_transcription_realtime" | "video_generation_text_to_video" | "workflow_execution" | "code_generation" | "image_understanding" | "structured_evaluation")[] | undefined;
|
|
18
|
+
imageControls?: {
|
|
19
|
+
steps: boolean;
|
|
20
|
+
cfg: boolean;
|
|
21
|
+
sampler: boolean;
|
|
22
|
+
scheduler: boolean;
|
|
23
|
+
negativePrompt: boolean;
|
|
24
|
+
seed: boolean;
|
|
25
|
+
} | undefined;
|
|
26
|
+
tags?: string[] | undefined;
|
|
27
|
+
};
|
|
28
|
+
encodeRequest<M extends Modality>(request: GenerationRequest<M>, context: SpecCallContext): WireRequest;
|
|
29
|
+
decodeResponse<M extends Modality>(chunks: AsyncIterable<WireResponseChunk>, request: GenerationRequest<M>, context: SpecCallContext): AsyncIterable<DecodedEvent<M>>;
|
|
30
|
+
}
|
|
31
|
+
export default GrokAgentSpec;
|
|
32
|
+
//# sourceMappingURL=grok-agent.spec.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.spec.impl.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.spec.impl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,YAAY,EACZ,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAA0B,MAAM,4BAA4B,CAAC;AAC5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAgB/D,qBAAa,aAAc,YAAW,eAAe;IACpD,QAAQ,CAAC,UAAU;;;;;;;;;;;;;;;;;;;;;;MAAc;IAEjC,aAAa,CAAC,CAAC,SAAS,QAAQ,EAC/B,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,eAAe,GACtB,WAAW;IAkBP,cAAc,CAAC,CAAC,SAAS,QAAQ,EACvC,MAAM,EAAE,aAAa,CAAC,iBAAiB,CAAC,EACxC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,eAAe,GACtB,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CA0DjC;AAyBD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { textResultEvent } from '@vibesdotdev/ai/specs/interfaces';
|
|
2
|
+
import descriptor from "./grok-agent.spec.descriptor.js";
|
|
3
|
+
import { encodeGrokMessage, readGrokTextMessages } from "../../../specs/grok-messages.js";
|
|
4
|
+
import { attempt } from "../../../../outcome.js";
|
|
5
|
+
import { grokRefusal } from "../grok-refusals.js";
|
|
6
|
+
import { createGrokAgentSessionProgram } from "./session.js";
|
|
7
|
+
import { GROK_AGENT_LIMITS, GrokAgentRecordSchema } from "./protocol.js";
|
|
8
|
+
export class GrokAgentSpec {
|
|
9
|
+
descriptor = descriptor;
|
|
10
|
+
encodeRequest(request, context) {
|
|
11
|
+
// Refuses images, tool calls and tool results typed: the session carries text only, and nothing is dropped.
|
|
12
|
+
const messages = readGrokTextMessages(request);
|
|
13
|
+
const cwd = context.executionPolicy?.workspacePath ?? '';
|
|
14
|
+
const prompt = encodePrompt(messages.map(encodeGrokMessage));
|
|
15
|
+
return {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
path: '',
|
|
18
|
+
headers: { 'content-type': 'application/x-ndjson' },
|
|
19
|
+
body: {
|
|
20
|
+
cwd,
|
|
21
|
+
prompt,
|
|
22
|
+
sessionProgram: createGrokAgentSessionProgram({ cwd, prompt })
|
|
23
|
+
},
|
|
24
|
+
streaming: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async *decodeResponse(chunks, request, context) {
|
|
28
|
+
const content = [];
|
|
29
|
+
const thinking = [];
|
|
30
|
+
let contentChars = 0;
|
|
31
|
+
let thinkingChars = 0;
|
|
32
|
+
let resultSeen = false;
|
|
33
|
+
for await (const chunk of chunks) {
|
|
34
|
+
if (chunk.kind === 'error') {
|
|
35
|
+
yield { kind: 'error', error: chunk.error };
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (chunk.kind !== 'ndjson-record')
|
|
39
|
+
continue;
|
|
40
|
+
const record = parseRecord(chunk.data);
|
|
41
|
+
if (!record) {
|
|
42
|
+
yield { kind: 'error', error: grokRefusal('agent-record-invalid', { details: { stage: 'decode' } }) };
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (record.type === 'text-delta') {
|
|
46
|
+
contentChars += record.delta.length;
|
|
47
|
+
if (contentChars > GROK_AGENT_LIMITS.maxTextChars) {
|
|
48
|
+
yield { kind: 'error', error: grokRefusal('agent-output-too-large', { details: { stage: 'decode', what: 'text' } }) };
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
content.push(record.delta);
|
|
52
|
+
yield { kind: 'text-delta', delta: record.delta };
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (record.type === 'thinking-delta') {
|
|
56
|
+
thinkingChars += record.delta.length;
|
|
57
|
+
if (thinkingChars > GROK_AGENT_LIMITS.maxThinkingChars) {
|
|
58
|
+
yield { kind: 'error', error: grokRefusal('agent-output-too-large', { details: { stage: 'decode', what: 'thinking' } }) };
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
thinking.push(record.delta);
|
|
62
|
+
yield { kind: 'thinking-delta', delta: record.delta };
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const result = {
|
|
66
|
+
id: `${context.providerId}.grok-agent`,
|
|
67
|
+
timestamp: new Date(),
|
|
68
|
+
content: content.join(''),
|
|
69
|
+
metadata: {
|
|
70
|
+
modelVersion: context.wireModelId,
|
|
71
|
+
finishReason: finishReason(record.stopReason),
|
|
72
|
+
providerManagedToolLoop: true
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
if (thinking.length > 0)
|
|
76
|
+
result.thinking = thinking.join('');
|
|
77
|
+
if (record.toolCalls.length > 0)
|
|
78
|
+
result.toolCalls = record.toolCalls.map(toTextToolCall);
|
|
79
|
+
yield textResultEvent(request, result);
|
|
80
|
+
// The stream is read to its end, so the transport finishes (and stops the agent) in the normal flow.
|
|
81
|
+
resultSeen = true;
|
|
82
|
+
}
|
|
83
|
+
// The session ended without its result record: never an empty success.
|
|
84
|
+
if (!resultSeen) {
|
|
85
|
+
yield { kind: 'error', error: grokRefusal('agent-record-invalid', { details: { stage: 'decode', what: 'no-result' } }) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function toTextToolCall(tool) {
|
|
90
|
+
const call = { id: tool.id, name: tool.name, arguments: tool.arguments };
|
|
91
|
+
if (tool.result !== undefined)
|
|
92
|
+
call.result = tool.result;
|
|
93
|
+
return call;
|
|
94
|
+
}
|
|
95
|
+
function encodePrompt(framed) {
|
|
96
|
+
return framed.map((text) => ({ type: 'text', text }));
|
|
97
|
+
}
|
|
98
|
+
function parseRecord(value) {
|
|
99
|
+
const decoded = attempt(() => JSON.parse(value));
|
|
100
|
+
if (!decoded.ok)
|
|
101
|
+
return undefined;
|
|
102
|
+
const parsed = GrokAgentRecordSchema.safeParse(decoded.value);
|
|
103
|
+
return parsed.success ? parsed.data : undefined;
|
|
104
|
+
}
|
|
105
|
+
function finishReason(stopReason) {
|
|
106
|
+
if (stopReason === 'end_turn')
|
|
107
|
+
return 'stop';
|
|
108
|
+
if (stopReason === 'max_tokens' || stopReason === 'max_turn_requests')
|
|
109
|
+
return 'length';
|
|
110
|
+
return stopReason;
|
|
111
|
+
}
|
|
112
|
+
export default GrokAgentSpec;
|
|
113
|
+
//# sourceMappingURL=grok-agent.spec.impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.spec.impl.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.spec.impl.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE,OAAO,UAAU,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,oBA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: string;
|
|
6
|
+
scopes: ("cloud" | "consumer")[];
|
|
7
|
+
bidirectional: boolean;
|
|
8
|
+
cancellable: boolean;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
tags?: string[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
13
|
+
//# sourceMappingURL=grok-agent.transport.descriptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.transport.descriptor.d.ts","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.transport.descriptor.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,wBASG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createAITransportDescriptor } from '@vibesdotdev/ai/transports/schemas/descriptor';
|
|
2
|
+
export default createAITransportDescriptor({
|
|
3
|
+
id: 'grok-agent',
|
|
4
|
+
name: 'Grok Agent Session',
|
|
5
|
+
description: 'Consumer Grok ACP session (`grok agent stdio`) authenticated by the dedicated Grok Build profile.',
|
|
6
|
+
scopes: ['consumer'],
|
|
7
|
+
bidirectional: true,
|
|
8
|
+
cancellable: true,
|
|
9
|
+
tags: ['grok', 'acp', 'grok-managed-auth', 'consumer-only']
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=grok-agent.transport.descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok-agent.transport.descriptor.js","sourceRoot":"","sources":["../../../../../src/ai/providers/grok/grok-agent/grok-agent.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,oBAAoB;IAC1B,WAAW,EACV,mGAAmG;IACpG,MAAM,EAAE,CAAC,UAAU,CAAC;IACpB,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,eAAe,CAAC;CAC3D,CAAC,CAAC"}
|