indusagi-coding-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2249 -0
- package/README.md +546 -0
- package/dist/cli/args.js +282 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.js +78 -0
- package/dist/cli/list-models.js +91 -0
- package/dist/cli/session-picker.js +31 -0
- package/dist/cli.js +10 -0
- package/dist/config.js +158 -0
- package/dist/core/agent-session.js +2097 -0
- package/dist/core/auth-storage.js +278 -0
- package/dist/core/bash-executor.js +211 -0
- package/dist/core/compaction/branch-summarization.js +241 -0
- package/dist/core/compaction/compaction.js +606 -0
- package/dist/core/compaction/index.js +6 -0
- package/dist/core/compaction/utils.js +137 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/exec.js +70 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.js +221 -0
- package/dist/core/export-html/template.css +905 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1549 -0
- package/dist/core/export-html/tool-renderer.js +56 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.js +8 -0
- package/dist/core/extensions/loader.js +395 -0
- package/dist/core/extensions/runner.js +499 -0
- package/dist/core/extensions/types.js +31 -0
- package/dist/core/extensions/wrapper.js +101 -0
- package/dist/core/footer-data-provider.js +133 -0
- package/dist/core/index.js +8 -0
- package/dist/core/keybindings.js +140 -0
- package/dist/core/messages.js +122 -0
- package/dist/core/model-registry.js +454 -0
- package/dist/core/model-resolver.js +309 -0
- package/dist/core/package-manager.js +1142 -0
- package/dist/core/prompt-templates.js +250 -0
- package/dist/core/resource-loader.js +569 -0
- package/dist/core/sdk.js +225 -0
- package/dist/core/session-manager.js +1078 -0
- package/dist/core/settings-manager.js +430 -0
- package/dist/core/skills.js +339 -0
- package/dist/core/system-prompt.js +136 -0
- package/dist/core/timings.js +24 -0
- package/dist/core/tools/bash.js +226 -0
- package/dist/core/tools/edit-diff.js +242 -0
- package/dist/core/tools/edit.js +145 -0
- package/dist/core/tools/find.js +205 -0
- package/dist/core/tools/grep.js +238 -0
- package/dist/core/tools/index.js +60 -0
- package/dist/core/tools/ls.js +117 -0
- package/dist/core/tools/path-utils.js +52 -0
- package/dist/core/tools/read.js +165 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.js +77 -0
- package/dist/index.js +41 -0
- package/dist/main.js +565 -0
- package/dist/migrations.js +260 -0
- package/dist/modes/index.js +7 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.js +86 -0
- package/dist/modes/interactive/components/bash-execution.js +155 -0
- package/dist/modes/interactive/components/bordered-loader.js +47 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.js +458 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.js +61 -0
- package/dist/modes/interactive/components/custom-message.js +80 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/extension-editor.js +96 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.js +213 -0
- package/dist/modes/interactive/components/index.js +31 -0
- package/dist/modes/interactive/components/keybinding-hints.js +60 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.js +253 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +262 -0
- package/dist/modes/interactive/components/session-selector-search.js +145 -0
- package/dist/modes/interactive/components/session-selector.js +698 -0
- package/dist/modes/interactive/components/settings-selector.js +250 -0
- package/dist/modes/interactive/components/show-images-selector.js +33 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.js +43 -0
- package/dist/modes/interactive/components/thinking-selector.js +45 -0
- package/dist/modes/interactive/components/tool-execution.js +608 -0
- package/dist/modes/interactive/components/tree-selector.js +892 -0
- package/dist/modes/interactive/components/user-message-selector.js +109 -0
- package/dist/modes/interactive/components/user-message.js +15 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.js +3576 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.js +938 -0
- package/dist/modes/print-mode.js +96 -0
- package/dist/modes/rpc/rpc-client.js +390 -0
- package/dist/modes/rpc/rpc-mode.js +448 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/clipboard-image.js +116 -0
- package/dist/utils/clipboard.js +58 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.js +5 -0
- package/dist/utils/image-convert.js +34 -0
- package/dist/utils/image-resize.js +180 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.js +164 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.js +186 -0
- package/docs/compaction.md +390 -0
- package/docs/custom-provider.md +538 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +1733 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +79 -0
- package/docs/keybindings.md +162 -0
- package/docs/models.md +193 -0
- package/docs/packages.md +163 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +147 -0
- package/docs/rpc.md +1048 -0
- package/docs/sdk.md +957 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +216 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +226 -0
- package/docs/terminal-setup.md +65 -0
- package/docs/themes.md +295 -0
- package/docs/tree.md +219 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +192 -0
- package/examples/extensions/antigravity-image-gen.ts +414 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +115 -0
- package/examples/extensions/custom-footer.ts +65 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +605 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +350 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +83 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +133 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +105 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/handoff.ts +151 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +60 -0
- package/examples/extensions/modal-editor.ts +86 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +25 -0
- package/examples/extensions/overlay-qa-tests.ts +882 -0
- package/examples/extensions/overlay-test.ts +151 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +341 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +399 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/qna.ts +120 -0
- package/examples/extensions/question.ts +265 -0
- package/examples/extensions/questionnaire.ts +428 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/sandbox/index.ts +318 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +344 -0
- package/examples/extensions/space-invaders.ts +561 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +40 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +127 -0
- package/examples/extensions/subagent/index.ts +964 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +196 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/todo.ts +300 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +147 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +193 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +50 -0
- package/examples/sdk/03-custom-prompt.ts +55 -0
- package/examples/sdk/04-skills.ts +46 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +47 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +82 -0
- package/examples/sdk/13-codex-oauth.ts +37 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +85 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitLab Duo Provider Extension
|
|
3
|
+
*
|
|
4
|
+
* Provides access to GitLab Duo AI models (Claude and GPT) through GitLab's AI Gateway.
|
|
5
|
+
* Delegates to indusagi-ai's built-in Anthropic and OpenAI streaming implementations.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* indusagi -e ./packages/coding-agent/examples/extensions/custom-provider-gitlab-duo
|
|
9
|
+
* # Then /login gitlab-duo, or set GITLAB_TOKEN=glpat-...
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
type Api,
|
|
14
|
+
type AssistantMessageEventStream,
|
|
15
|
+
type Context,
|
|
16
|
+
createAssistantMessageEventStream,
|
|
17
|
+
type Model,
|
|
18
|
+
type OAuthCredentials,
|
|
19
|
+
type OAuthLoginCallbacks,
|
|
20
|
+
type SimpleStreamOptions,
|
|
21
|
+
streamSimpleAnthropic,
|
|
22
|
+
streamSimpleOpenAIResponses,
|
|
23
|
+
} from "indusagi/ai";
|
|
24
|
+
import type { ExtensionAPI } from "indusagi-coding-agent";
|
|
25
|
+
|
|
26
|
+
// =============================================================================
|
|
27
|
+
// Constants
|
|
28
|
+
// =============================================================================
|
|
29
|
+
|
|
30
|
+
const GITLAB_COM_URL = "https://gitlab.com";
|
|
31
|
+
const AI_GATEWAY_URL = "https://cloud.gitlab.com";
|
|
32
|
+
const ANTHROPIC_PROXY_URL = `${AI_GATEWAY_URL}/ai/v1/proxy/anthropic/`;
|
|
33
|
+
const OPENAI_PROXY_URL = `${AI_GATEWAY_URL}/ai/v1/proxy/openai/v1`;
|
|
34
|
+
|
|
35
|
+
const BUNDLED_CLIENT_ID = "da4edff2e6ebd2bc3208611e2768bc1c1dd7be791dc5ff26ca34ca9ee44f7d4b";
|
|
36
|
+
const OAUTH_SCOPES = ["api"];
|
|
37
|
+
const REDIRECT_URI = "http://127.0.0.1:8080/callback";
|
|
38
|
+
const DIRECT_ACCESS_TTL = 25 * 60 * 1000;
|
|
39
|
+
|
|
40
|
+
// =============================================================================
|
|
41
|
+
// Models - exported for use by tests
|
|
42
|
+
// =============================================================================
|
|
43
|
+
|
|
44
|
+
type Backend = "anthropic" | "openai";
|
|
45
|
+
|
|
46
|
+
interface GitLabModel {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
backend: Backend;
|
|
50
|
+
baseUrl: string;
|
|
51
|
+
reasoning: boolean;
|
|
52
|
+
input: ("text" | "image")[];
|
|
53
|
+
cost: { input: number; output: number; cacheRead: number; cacheWrite: number };
|
|
54
|
+
contextWindow: number;
|
|
55
|
+
maxTokens: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const MODELS: GitLabModel[] = [
|
|
59
|
+
// Anthropic
|
|
60
|
+
{
|
|
61
|
+
id: "claude-opus-4-5-20251101",
|
|
62
|
+
name: "Claude Opus 4.5",
|
|
63
|
+
backend: "anthropic",
|
|
64
|
+
baseUrl: ANTHROPIC_PROXY_URL,
|
|
65
|
+
reasoning: true,
|
|
66
|
+
input: ["text", "image"],
|
|
67
|
+
cost: { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
68
|
+
contextWindow: 200000,
|
|
69
|
+
maxTokens: 32000,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: "claude-sonnet-4-5-20250929",
|
|
73
|
+
name: "Claude Sonnet 4.5",
|
|
74
|
+
backend: "anthropic",
|
|
75
|
+
baseUrl: ANTHROPIC_PROXY_URL,
|
|
76
|
+
reasoning: true,
|
|
77
|
+
input: ["text", "image"],
|
|
78
|
+
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
79
|
+
contextWindow: 200000,
|
|
80
|
+
maxTokens: 16384,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "claude-haiku-4-5-20251001",
|
|
84
|
+
name: "Claude Haiku 4.5",
|
|
85
|
+
backend: "anthropic",
|
|
86
|
+
baseUrl: ANTHROPIC_PROXY_URL,
|
|
87
|
+
reasoning: true,
|
|
88
|
+
input: ["text", "image"],
|
|
89
|
+
cost: { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
90
|
+
contextWindow: 200000,
|
|
91
|
+
maxTokens: 8192,
|
|
92
|
+
},
|
|
93
|
+
// OpenAI (all use Responses API)
|
|
94
|
+
{
|
|
95
|
+
id: "gpt-5.1-2025-11-13",
|
|
96
|
+
name: "GPT-5.1",
|
|
97
|
+
backend: "openai",
|
|
98
|
+
baseUrl: OPENAI_PROXY_URL,
|
|
99
|
+
reasoning: true,
|
|
100
|
+
input: ["text", "image"],
|
|
101
|
+
cost: { input: 2.5, output: 10, cacheRead: 0, cacheWrite: 0 },
|
|
102
|
+
contextWindow: 128000,
|
|
103
|
+
maxTokens: 16384,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "gpt-5-mini-2025-08-07",
|
|
107
|
+
name: "GPT-5 Mini",
|
|
108
|
+
backend: "openai",
|
|
109
|
+
baseUrl: OPENAI_PROXY_URL,
|
|
110
|
+
reasoning: true,
|
|
111
|
+
input: ["text", "image"],
|
|
112
|
+
cost: { input: 0.15, output: 0.6, cacheRead: 0, cacheWrite: 0 },
|
|
113
|
+
contextWindow: 128000,
|
|
114
|
+
maxTokens: 16384,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "gpt-5-codex",
|
|
118
|
+
name: "GPT-5 Codex",
|
|
119
|
+
backend: "openai",
|
|
120
|
+
baseUrl: OPENAI_PROXY_URL,
|
|
121
|
+
reasoning: true,
|
|
122
|
+
input: ["text", "image"],
|
|
123
|
+
cost: { input: 2.5, output: 10, cacheRead: 0, cacheWrite: 0 },
|
|
124
|
+
contextWindow: 128000,
|
|
125
|
+
maxTokens: 16384,
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
const MODEL_MAP = new Map(MODELS.map((m) => [m.id, m]));
|
|
130
|
+
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Direct Access Token Cache
|
|
133
|
+
// =============================================================================
|
|
134
|
+
|
|
135
|
+
interface DirectAccessToken {
|
|
136
|
+
token: string;
|
|
137
|
+
headers: Record<string, string>;
|
|
138
|
+
expiresAt: number;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let cachedDirectAccess: DirectAccessToken | null = null;
|
|
142
|
+
|
|
143
|
+
async function getDirectAccessToken(gitlabAccessToken: string): Promise<DirectAccessToken> {
|
|
144
|
+
const now = Date.now();
|
|
145
|
+
if (cachedDirectAccess && cachedDirectAccess.expiresAt > now) {
|
|
146
|
+
return cachedDirectAccess;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const response = await fetch(`${GITLAB_COM_URL}/api/v4/ai/third_party_agents/direct_access`, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
headers: { Authorization: `Bearer ${gitlabAccessToken}`, "Content-Type": "application/json" },
|
|
152
|
+
body: JSON.stringify({ feature_flags: { DuoAgentPlatformNext: true } }),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
const errorText = await response.text();
|
|
157
|
+
if (response.status === 403) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`GitLab Duo access denied. Ensure GitLab Duo is enabled for your account. Error: ${errorText}`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
throw new Error(`Failed to get direct access token: ${response.status} ${errorText}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const data = (await response.json()) as { token: string; headers: Record<string, string> };
|
|
166
|
+
cachedDirectAccess = { token: data.token, headers: data.headers, expiresAt: now + DIRECT_ACCESS_TTL };
|
|
167
|
+
return cachedDirectAccess;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function invalidateDirectAccessToken() {
|
|
171
|
+
cachedDirectAccess = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// =============================================================================
|
|
175
|
+
// OAuth
|
|
176
|
+
// =============================================================================
|
|
177
|
+
|
|
178
|
+
async function generatePKCE(): Promise<{ verifier: string; challenge: string }> {
|
|
179
|
+
const array = new Uint8Array(32);
|
|
180
|
+
crypto.getRandomValues(array);
|
|
181
|
+
const verifier = btoa(String.fromCharCode(...array))
|
|
182
|
+
.replace(/\+/g, "-")
|
|
183
|
+
.replace(/\//g, "_")
|
|
184
|
+
.replace(/=+$/, "");
|
|
185
|
+
const hash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
186
|
+
const challenge = btoa(String.fromCharCode(...new Uint8Array(hash)))
|
|
187
|
+
.replace(/\+/g, "-")
|
|
188
|
+
.replace(/\//g, "_")
|
|
189
|
+
.replace(/=+$/, "");
|
|
190
|
+
return { verifier, challenge };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function loginGitLab(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
|
|
194
|
+
const { verifier, challenge } = await generatePKCE();
|
|
195
|
+
const authParams = new URLSearchParams({
|
|
196
|
+
client_id: BUNDLED_CLIENT_ID,
|
|
197
|
+
redirect_uri: REDIRECT_URI,
|
|
198
|
+
response_type: "code",
|
|
199
|
+
scope: OAUTH_SCOPES.join(" "),
|
|
200
|
+
code_challenge: challenge,
|
|
201
|
+
code_challenge_method: "S256",
|
|
202
|
+
state: crypto.randomUUID(),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
callbacks.onAuth({ url: `${GITLAB_COM_URL}/oauth/authorize?${authParams.toString()}` });
|
|
206
|
+
const callbackUrl = await callbacks.onPrompt({ message: "Paste the callback URL:" });
|
|
207
|
+
const code = new URL(callbackUrl).searchParams.get("code");
|
|
208
|
+
if (!code) throw new Error("No authorization code found in callback URL");
|
|
209
|
+
|
|
210
|
+
const tokenResponse = await fetch(`${GITLAB_COM_URL}/oauth/token`, {
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
213
|
+
body: new URLSearchParams({
|
|
214
|
+
client_id: BUNDLED_CLIENT_ID,
|
|
215
|
+
grant_type: "authorization_code",
|
|
216
|
+
code,
|
|
217
|
+
code_verifier: verifier,
|
|
218
|
+
redirect_uri: REDIRECT_URI,
|
|
219
|
+
}).toString(),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
if (!tokenResponse.ok) throw new Error(`Token exchange failed: ${await tokenResponse.text()}`);
|
|
223
|
+
const data = (await tokenResponse.json()) as {
|
|
224
|
+
access_token: string;
|
|
225
|
+
refresh_token: string;
|
|
226
|
+
expires_in: number;
|
|
227
|
+
created_at: number;
|
|
228
|
+
};
|
|
229
|
+
invalidateDirectAccessToken();
|
|
230
|
+
return {
|
|
231
|
+
refresh: data.refresh_token,
|
|
232
|
+
access: data.access_token,
|
|
233
|
+
expires: (data.created_at + data.expires_in) * 1000 - 5 * 60 * 1000,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function refreshGitLabToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {
|
|
238
|
+
const response = await fetch(`${GITLAB_COM_URL}/oauth/token`, {
|
|
239
|
+
method: "POST",
|
|
240
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
241
|
+
body: new URLSearchParams({
|
|
242
|
+
client_id: BUNDLED_CLIENT_ID,
|
|
243
|
+
grant_type: "refresh_token",
|
|
244
|
+
refresh_token: credentials.refresh,
|
|
245
|
+
}).toString(),
|
|
246
|
+
});
|
|
247
|
+
if (!response.ok) throw new Error(`Token refresh failed: ${await response.text()}`);
|
|
248
|
+
const data = (await response.json()) as {
|
|
249
|
+
access_token: string;
|
|
250
|
+
refresh_token: string;
|
|
251
|
+
expires_in: number;
|
|
252
|
+
created_at: number;
|
|
253
|
+
};
|
|
254
|
+
invalidateDirectAccessToken();
|
|
255
|
+
return {
|
|
256
|
+
refresh: data.refresh_token,
|
|
257
|
+
access: data.access_token,
|
|
258
|
+
expires: (data.created_at + data.expires_in) * 1000 - 5 * 60 * 1000,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// =============================================================================
|
|
263
|
+
// Stream Function
|
|
264
|
+
// =============================================================================
|
|
265
|
+
|
|
266
|
+
export function streamGitLabDuo(
|
|
267
|
+
model: Model<Api>,
|
|
268
|
+
context: Context,
|
|
269
|
+
options?: SimpleStreamOptions,
|
|
270
|
+
): AssistantMessageEventStream {
|
|
271
|
+
const stream = createAssistantMessageEventStream();
|
|
272
|
+
|
|
273
|
+
(async () => {
|
|
274
|
+
try {
|
|
275
|
+
const gitlabAccessToken = options?.apiKey;
|
|
276
|
+
if (!gitlabAccessToken) throw new Error("No GitLab access token. Run /login gitlab-duo or set GITLAB_TOKEN");
|
|
277
|
+
|
|
278
|
+
const cfg = MODEL_MAP.get(model.id);
|
|
279
|
+
if (!cfg) throw new Error(`Unknown model: ${model.id}`);
|
|
280
|
+
|
|
281
|
+
const directAccess = await getDirectAccessToken(gitlabAccessToken);
|
|
282
|
+
const modelWithBaseUrl = { ...model, baseUrl: cfg.baseUrl };
|
|
283
|
+
const headers = { ...directAccess.headers, Authorization: `Bearer ${directAccess.token}` };
|
|
284
|
+
const streamOptions = { ...options, apiKey: "gitlab-duo", headers };
|
|
285
|
+
|
|
286
|
+
const innerStream =
|
|
287
|
+
cfg.backend === "anthropic"
|
|
288
|
+
? streamSimpleAnthropic(modelWithBaseUrl as Model<"anthropic-messages">, context, streamOptions)
|
|
289
|
+
: streamSimpleOpenAIResponses(modelWithBaseUrl as Model<"openai-responses">, context, streamOptions);
|
|
290
|
+
|
|
291
|
+
for await (const event of innerStream) stream.push(event);
|
|
292
|
+
stream.end();
|
|
293
|
+
} catch (error) {
|
|
294
|
+
stream.push({
|
|
295
|
+
type: "error",
|
|
296
|
+
reason: "error",
|
|
297
|
+
error: {
|
|
298
|
+
role: "assistant",
|
|
299
|
+
content: [],
|
|
300
|
+
api: model.api,
|
|
301
|
+
provider: model.provider,
|
|
302
|
+
model: model.id,
|
|
303
|
+
usage: {
|
|
304
|
+
input: 0,
|
|
305
|
+
output: 0,
|
|
306
|
+
cacheRead: 0,
|
|
307
|
+
cacheWrite: 0,
|
|
308
|
+
totalTokens: 0,
|
|
309
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
310
|
+
},
|
|
311
|
+
stopReason: "error",
|
|
312
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
313
|
+
timestamp: Date.now(),
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
stream.end();
|
|
317
|
+
}
|
|
318
|
+
})();
|
|
319
|
+
|
|
320
|
+
return stream;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// =============================================================================
|
|
324
|
+
// Extension Entry Point
|
|
325
|
+
// =============================================================================
|
|
326
|
+
|
|
327
|
+
export default function (indusagi: ExtensionAPI) {
|
|
328
|
+
indusagi.registerProvider("gitlab-duo", {
|
|
329
|
+
baseUrl: AI_GATEWAY_URL,
|
|
330
|
+
apiKey: "GITLAB_TOKEN",
|
|
331
|
+
api: "gitlab-duo-api",
|
|
332
|
+
models: MODELS.map(({ id, name, reasoning, input, cost, contextWindow, maxTokens }) => ({
|
|
333
|
+
id,
|
|
334
|
+
name,
|
|
335
|
+
reasoning,
|
|
336
|
+
input,
|
|
337
|
+
cost,
|
|
338
|
+
contextWindow,
|
|
339
|
+
maxTokens,
|
|
340
|
+
})),
|
|
341
|
+
oauth: {
|
|
342
|
+
name: "GitLab Duo",
|
|
343
|
+
login: loginGitLab,
|
|
344
|
+
refreshToken: refreshGitLabToken,
|
|
345
|
+
getApiKey: (cred) => cred.access,
|
|
346
|
+
},
|
|
347
|
+
streamSimple: streamGitLabDuo,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "indusagi-extension-custom-provider-gitlab-duo",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "echo 'nothing to clean'",
|
|
8
|
+
"build": "echo 'nothing to build'",
|
|
9
|
+
"check": "echo 'nothing to check'"
|
|
10
|
+
},
|
|
11
|
+
"indusagi": {
|
|
12
|
+
"extensions": [
|
|
13
|
+
"./index.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test script for GitLab Duo extension
|
|
3
|
+
* Run: npx tsx test.ts [model-id] [--thinking]
|
|
4
|
+
*
|
|
5
|
+
* Examples:
|
|
6
|
+
* npx tsx test.ts # Test default (claude-sonnet-4-5-20250929)
|
|
7
|
+
* npx tsx test.ts gpt-5-codex # Test GPT-5 Codex
|
|
8
|
+
* npx tsx test.ts claude-sonnet-4-5-20250929 --thinking
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { type Api, type Context, type Model, registerApiProvider, streamSimple } from "indusagi/ai";
|
|
12
|
+
import { readFileSync } from "fs";
|
|
13
|
+
import { homedir } from "os";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
import { MODELS, streamGitLabDuo } from "./index.js";
|
|
16
|
+
|
|
17
|
+
const MODEL_MAP = new Map(MODELS.map((m) => [m.id, m]));
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
const modelId = process.argv[2] || "claude-sonnet-4-5-20250929";
|
|
21
|
+
const useThinking = process.argv.includes("--thinking");
|
|
22
|
+
|
|
23
|
+
const cfg = MODEL_MAP.get(modelId);
|
|
24
|
+
if (!cfg) {
|
|
25
|
+
console.error(`Unknown model: ${modelId}`);
|
|
26
|
+
console.error("Available:", MODELS.map((m) => m.id).join(", "));
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Read auth
|
|
31
|
+
const authPath = join(homedir(), ".indusagi", "agent", "auth.json");
|
|
32
|
+
const authData = JSON.parse(readFileSync(authPath, "utf-8"));
|
|
33
|
+
const gitlabCred = authData["gitlab-duo"];
|
|
34
|
+
if (!gitlabCred?.access) {
|
|
35
|
+
console.error("No gitlab-duo credentials. Run /login gitlab-duo first.");
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Register provider
|
|
40
|
+
registerApiProvider({
|
|
41
|
+
api: "gitlab-duo-api" as Api,
|
|
42
|
+
stream: streamGitLabDuo,
|
|
43
|
+
streamSimple: streamGitLabDuo,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Create model
|
|
47
|
+
const model: Model<Api> = {
|
|
48
|
+
id: cfg.id,
|
|
49
|
+
name: cfg.name,
|
|
50
|
+
api: "gitlab-duo-api" as Api,
|
|
51
|
+
provider: "gitlab-duo",
|
|
52
|
+
baseUrl: cfg.baseUrl,
|
|
53
|
+
reasoning: cfg.reasoning,
|
|
54
|
+
input: cfg.input,
|
|
55
|
+
cost: cfg.cost,
|
|
56
|
+
contextWindow: cfg.contextWindow,
|
|
57
|
+
maxTokens: cfg.maxTokens,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const context: Context = {
|
|
61
|
+
messages: [{ role: "user", content: "Say hello in exactly 3 words.", timestamp: Date.now() }],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
console.log(`Model: ${model.id}, Backend: ${cfg.backend}, Thinking: ${useThinking}`);
|
|
65
|
+
|
|
66
|
+
const stream = streamSimple(model, context, {
|
|
67
|
+
apiKey: gitlabCred.access,
|
|
68
|
+
maxTokens: 100,
|
|
69
|
+
reasoning: useThinking ? "low" : undefined,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
for await (const event of stream) {
|
|
73
|
+
if (event.type === "thinking_start") console.log("[Thinking]");
|
|
74
|
+
else if (event.type === "thinking_delta") process.stdout.write(event.delta);
|
|
75
|
+
else if (event.type === "thinking_end") console.log("\n[/Thinking]\n");
|
|
76
|
+
else if (event.type === "text_delta") process.stdout.write(event.delta);
|
|
77
|
+
else if (event.type === "error") console.error("\nError:", event.error.errorMessage);
|
|
78
|
+
else if (event.type === "done") console.log("\n\nDone!", event.reason, event.message.usage);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main().catch(console.error);
|
|
83
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dirty Repo Guard Extension
|
|
3
|
+
*
|
|
4
|
+
* Prevents session changes when there are uncommitted git changes.
|
|
5
|
+
* Useful to ensure work is committed before switching context.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI, ExtensionContext } from "indusagi-coding-agent";
|
|
9
|
+
|
|
10
|
+
async function checkDirtyRepo(
|
|
11
|
+
indusagi: ExtensionAPI,
|
|
12
|
+
ctx: ExtensionContext,
|
|
13
|
+
action: string,
|
|
14
|
+
): Promise<{ cancel: boolean } | undefined> {
|
|
15
|
+
// Check for uncommitted changes
|
|
16
|
+
const { stdout, code } = await indusagi.exec("git", ["status", "--porcelain"]);
|
|
17
|
+
|
|
18
|
+
if (code !== 0) {
|
|
19
|
+
// Not a git repo, allow the action
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const hasChanges = stdout.trim().length > 0;
|
|
24
|
+
if (!hasChanges) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!ctx.hasUI) {
|
|
29
|
+
// In non-interactive mode, block by default
|
|
30
|
+
return { cancel: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Count changed files
|
|
34
|
+
const changedFiles = stdout.trim().split("\n").filter(Boolean).length;
|
|
35
|
+
|
|
36
|
+
const choice = await ctx.ui.select(`You have ${changedFiles} uncommitted file(s). ${action} anyway?`, [
|
|
37
|
+
"Yes, proceed anyway",
|
|
38
|
+
"No, let me commit first",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
if (choice !== "Yes, proceed anyway") {
|
|
42
|
+
ctx.ui.notify("Commit your changes first", "warning");
|
|
43
|
+
return { cancel: true };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default function (indusagi: ExtensionAPI) {
|
|
48
|
+
indusagi.on("session_before_switch", async (event, ctx) => {
|
|
49
|
+
const action = event.reason === "new" ? "new session" : "switch session";
|
|
50
|
+
return checkDirtyRepo(indusagi, ctx, action);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
indusagi.on("session_before_fork", async (_event, ctx) => {
|
|
54
|
+
return checkDirtyRepo(indusagi, ctx, "fork");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# DOOM Overlay Demo
|
|
2
|
+
|
|
3
|
+
Play DOOM as an overlay in indusagi. Demonstrates that the overlay system can handle real-time game rendering at 35 FPS.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
indusagi --extension ./examples/extensions/doom-overlay
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Then run:
|
|
12
|
+
```
|
|
13
|
+
/doom-overlay
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The shareware WAD file (~4MB) is auto-downloaded on first run.
|
|
17
|
+
|
|
18
|
+
## Controls
|
|
19
|
+
|
|
20
|
+
| Action | Keys |
|
|
21
|
+
|--------|------|
|
|
22
|
+
| Move | WASD or Arrow Keys |
|
|
23
|
+
| Run | Shift + WASD |
|
|
24
|
+
| Fire | F or Ctrl |
|
|
25
|
+
| Use/Open | Space |
|
|
26
|
+
| Weapons | 1-7 |
|
|
27
|
+
| Map | Tab |
|
|
28
|
+
| Menu | Escape |
|
|
29
|
+
| Pause/Quit | Q |
|
|
30
|
+
|
|
31
|
+
## How It Works
|
|
32
|
+
|
|
33
|
+
DOOM runs as WebAssembly compiled from [doomgeneric](https://github.com/ozkl/doomgeneric). Each frame is rendered using half-block characters (▀) with 24-bit color, where the top pixel is the foreground color and the bottom pixel is the background color.
|
|
34
|
+
|
|
35
|
+
The overlay uses:
|
|
36
|
+
- `width: "90%"` - 90% of terminal width
|
|
37
|
+
- `maxHeight: "80%"` - Maximum 80% of terminal height
|
|
38
|
+
- `anchor: "center"` - Centered in terminal
|
|
39
|
+
|
|
40
|
+
Height is calculated from width to maintain DOOM's 3.2:1 aspect ratio (accounting for half-block rendering).
|
|
41
|
+
|
|
42
|
+
## Credits
|
|
43
|
+
|
|
44
|
+
- [id Software](https://github.com/id-Software/DOOM) for the original DOOM
|
|
45
|
+
- [doomgeneric](https://github.com/ozkl/doomgeneric) for the portable DOOM implementation
|
|
46
|
+
- [indusagi-doom](https://github.com/badlogic/indusagi-doom) for the original indusagi integration
|