@denisvieiradev/gitwise-core 0.1.0 → 1.3.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/dist/index.d.ts +60 -20
- package/dist/index.js +561 -186
- package/dist/index.js.map +1 -1
- package/dist/testing/index.d.ts +3 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/types-BURqSokx.d.ts +36 -0
- package/package.json +2 -2
- package/dist/types-DnMpR1qf.d.ts +0 -29
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as LLMProvider,
|
|
1
|
+
import { L as LLMProvider, b as LLMChatRequest, c as LLMChatResponse } from '../types-BURqSokx.js';
|
|
2
2
|
|
|
3
3
|
interface MockResponse {
|
|
4
4
|
content: string;
|
|
@@ -6,6 +6,8 @@ interface MockResponse {
|
|
|
6
6
|
input: number;
|
|
7
7
|
output: number;
|
|
8
8
|
};
|
|
9
|
+
/** AD-002: defaults to true (matches every real provider's common case). */
|
|
10
|
+
tokensAvailable?: boolean;
|
|
9
11
|
}
|
|
10
12
|
interface PrefixMatcher {
|
|
11
13
|
prefix: string;
|
package/dist/testing/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var MockLLMProvider = class {
|
|
|
34
34
|
const tokens = r.tokens ?? { input: 10, output: 5 };
|
|
35
35
|
this.totalInputTokens += tokens.input;
|
|
36
36
|
this.totalOutputTokens += tokens.output;
|
|
37
|
-
return { content: r.content, tokens };
|
|
37
|
+
return { content: r.content, tokens, tokensAvailable: r.tokensAvailable ?? true };
|
|
38
38
|
}
|
|
39
39
|
/** Returns all recorded calls. */
|
|
40
40
|
getCalls() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/testing/mock-llm-provider.ts","../../src/testing/index.ts"],"sourcesContent":["import type { LLMProvider, LLMChatRequest, LLMChatResponse } from \"../providers/types.js\";\n\nexport interface MockResponse {\n content: string;\n tokens?: { input: number; output: number };\n}\n\nexport interface PrefixMatcher {\n prefix: string;\n response: MockResponse;\n}\n\n/**\n * MockLLMProvider — deterministic LLM stub for tests.\n *\n * Usage:\n * const mock = new MockLLMProvider();\n * mock.queueByIndex({ content: \"result\" }); // first call\n * mock.queueByPrefix(\"Analyze\", { content: \"analysis\" }); // by prompt prefix\n * await someFunction(mock);\n * mock.assertCallCount(2);\n * mock.assertTotalTokens({ input: 10, output: 5 });\n */\nexport class MockLLMProvider implements LLMProvider {\n private readonly indexedResponses: MockResponse[] = [];\n private readonly prefixResponses: PrefixMatcher[] = [];\n private callCount = 0;\n private totalInputTokens = 0;\n private totalOutputTokens = 0;\n private readonly calls: LLMChatRequest[] = [];\n\n /** Queue a response to return for the N-th call (0-indexed). */\n queueByIndex(response: MockResponse): this {\n this.indexedResponses.push(response);\n return this;\n }\n\n /** Queue a response to return when userMessage starts with the given prefix. */\n queueByPrefix(prefix: string, response: MockResponse): this {\n this.prefixResponses.push({ prefix, response });\n return this;\n }\n\n async chat(req: LLMChatRequest): Promise<LLMChatResponse> {\n this.calls.push(req);\n const idx = this.callCount++;\n\n // Prefix matching takes precedence\n for (const matcher of this.prefixResponses) {\n if (req.userMessage.startsWith(matcher.prefix) || req.systemPrompt.startsWith(matcher.prefix)) {\n return this.buildResponse(matcher.response);\n }\n }\n\n // Index-based fallback\n const indexed = this.indexedResponses[idx];\n if (indexed) {\n return this.buildResponse(indexed);\n }\n\n // Default response\n return this.buildResponse({ content: `mock-response-${idx}` });\n }\n\n private buildResponse(r: MockResponse): LLMChatResponse {\n const tokens = r.tokens ?? { input: 10, output: 5 };\n this.totalInputTokens += tokens.input;\n this.totalOutputTokens += tokens.output;\n return { content: r.content, tokens };\n }\n\n /** Returns all recorded calls. */\n getCalls(): readonly LLMChatRequest[] {\n return this.calls;\n }\n\n /** Returns the number of chat() calls made. */\n getCallCount(): number {\n return this.callCount;\n }\n\n /** Assert the provider was called exactly N times. */\n assertCallCount(expected: number): void {\n if (this.callCount !== expected) {\n throw new Error(`Expected ${expected} LLM call(s), got ${this.callCount}`);\n }\n }\n\n /** Assert accumulated token totals. */\n assertTotalTokens(expected: { input?: number; output?: number }): void {\n if (expected.input !== undefined && this.totalInputTokens !== expected.input) {\n throw new Error(`Expected ${expected.input} input tokens, got ${this.totalInputTokens}`);\n }\n if (expected.output !== undefined && this.totalOutputTokens !== expected.output) {\n throw new Error(`Expected ${expected.output} output tokens, got ${this.totalOutputTokens}`);\n }\n }\n\n getTotalTokens(): { input: number; output: number } {\n return { input: this.totalInputTokens, output: this.totalOutputTokens };\n }\n\n reset(): void {\n this.indexedResponses.length = 0;\n this.prefixResponses.length = 0;\n this.calls.length = 0;\n this.callCount = 0;\n this.totalInputTokens = 0;\n this.totalOutputTokens = 0;\n }\n}\n","export const __testingPlaceholder__ = Symbol.for(\n \"@denisvieiradev/gitwise-core/testing#placeholder\",\n);\n\nexport { MockLLMProvider } from \"./mock-llm-provider.js\";\nexport type { MockResponse, PrefixMatcher } from \"./mock-llm-provider.js\";\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/testing/mock-llm-provider.ts","../../src/testing/index.ts"],"sourcesContent":["import type { LLMProvider, LLMChatRequest, LLMChatResponse } from \"../providers/types.js\";\n\nexport interface MockResponse {\n content: string;\n tokens?: { input: number; output: number };\n /** AD-002: defaults to true (matches every real provider's common case). */\n tokensAvailable?: boolean;\n}\n\nexport interface PrefixMatcher {\n prefix: string;\n response: MockResponse;\n}\n\n/**\n * MockLLMProvider — deterministic LLM stub for tests.\n *\n * Usage:\n * const mock = new MockLLMProvider();\n * mock.queueByIndex({ content: \"result\" }); // first call\n * mock.queueByPrefix(\"Analyze\", { content: \"analysis\" }); // by prompt prefix\n * await someFunction(mock);\n * mock.assertCallCount(2);\n * mock.assertTotalTokens({ input: 10, output: 5 });\n */\nexport class MockLLMProvider implements LLMProvider {\n private readonly indexedResponses: MockResponse[] = [];\n private readonly prefixResponses: PrefixMatcher[] = [];\n private callCount = 0;\n private totalInputTokens = 0;\n private totalOutputTokens = 0;\n private readonly calls: LLMChatRequest[] = [];\n\n /** Queue a response to return for the N-th call (0-indexed). */\n queueByIndex(response: MockResponse): this {\n this.indexedResponses.push(response);\n return this;\n }\n\n /** Queue a response to return when userMessage starts with the given prefix. */\n queueByPrefix(prefix: string, response: MockResponse): this {\n this.prefixResponses.push({ prefix, response });\n return this;\n }\n\n async chat(req: LLMChatRequest): Promise<LLMChatResponse> {\n this.calls.push(req);\n const idx = this.callCount++;\n\n // Prefix matching takes precedence\n for (const matcher of this.prefixResponses) {\n if (req.userMessage.startsWith(matcher.prefix) || req.systemPrompt.startsWith(matcher.prefix)) {\n return this.buildResponse(matcher.response);\n }\n }\n\n // Index-based fallback\n const indexed = this.indexedResponses[idx];\n if (indexed) {\n return this.buildResponse(indexed);\n }\n\n // Default response\n return this.buildResponse({ content: `mock-response-${idx}` });\n }\n\n private buildResponse(r: MockResponse): LLMChatResponse {\n const tokens = r.tokens ?? { input: 10, output: 5 };\n this.totalInputTokens += tokens.input;\n this.totalOutputTokens += tokens.output;\n return { content: r.content, tokens, tokensAvailable: r.tokensAvailable ?? true };\n }\n\n /** Returns all recorded calls. */\n getCalls(): readonly LLMChatRequest[] {\n return this.calls;\n }\n\n /** Returns the number of chat() calls made. */\n getCallCount(): number {\n return this.callCount;\n }\n\n /** Assert the provider was called exactly N times. */\n assertCallCount(expected: number): void {\n if (this.callCount !== expected) {\n throw new Error(`Expected ${expected} LLM call(s), got ${this.callCount}`);\n }\n }\n\n /** Assert accumulated token totals. */\n assertTotalTokens(expected: { input?: number; output?: number }): void {\n if (expected.input !== undefined && this.totalInputTokens !== expected.input) {\n throw new Error(`Expected ${expected.input} input tokens, got ${this.totalInputTokens}`);\n }\n if (expected.output !== undefined && this.totalOutputTokens !== expected.output) {\n throw new Error(`Expected ${expected.output} output tokens, got ${this.totalOutputTokens}`);\n }\n }\n\n getTotalTokens(): { input: number; output: number } {\n return { input: this.totalInputTokens, output: this.totalOutputTokens };\n }\n\n reset(): void {\n this.indexedResponses.length = 0;\n this.prefixResponses.length = 0;\n this.calls.length = 0;\n this.callCount = 0;\n this.totalInputTokens = 0;\n this.totalOutputTokens = 0;\n }\n}\n","export const __testingPlaceholder__ = Symbol.for(\n \"@denisvieiradev/gitwise-core/testing#placeholder\",\n);\n\nexport { MockLLMProvider } from \"./mock-llm-provider.js\";\nexport type { MockResponse, PrefixMatcher } from \"./mock-llm-provider.js\";\n"],"mappings":";AAyBO,IAAM,kBAAN,MAA6C;AAAA,EACjC,mBAAmC,CAAC;AAAA,EACpC,kBAAmC,CAAC;AAAA,EAC7C,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACX,QAA0B,CAAC;AAAA;AAAA,EAG5C,aAAa,UAA8B;AACzC,SAAK,iBAAiB,KAAK,QAAQ;AACnC,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,cAAc,QAAgB,UAA8B;AAC1D,SAAK,gBAAgB,KAAK,EAAE,QAAQ,SAAS,CAAC;AAC9C,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,KAAK,KAA+C;AACxD,SAAK,MAAM,KAAK,GAAG;AACnB,UAAM,MAAM,KAAK;AAGjB,eAAW,WAAW,KAAK,iBAAiB;AAC1C,UAAI,IAAI,YAAY,WAAW,QAAQ,MAAM,KAAK,IAAI,aAAa,WAAW,QAAQ,MAAM,GAAG;AAC7F,eAAO,KAAK,cAAc,QAAQ,QAAQ;AAAA,MAC5C;AAAA,IACF;AAGA,UAAM,UAAU,KAAK,iBAAiB,GAAG;AACzC,QAAI,SAAS;AACX,aAAO,KAAK,cAAc,OAAO;AAAA,IACnC;AAGA,WAAO,KAAK,cAAc,EAAE,SAAS,iBAAiB,GAAG,GAAG,CAAC;AAAA,EAC/D;AAAA,EAEQ,cAAc,GAAkC;AACtD,UAAM,SAAS,EAAE,UAAU,EAAE,OAAO,IAAI,QAAQ,EAAE;AAClD,SAAK,oBAAoB,OAAO;AAChC,SAAK,qBAAqB,OAAO;AACjC,WAAO,EAAE,SAAS,EAAE,SAAS,QAAQ,iBAAiB,EAAE,mBAAmB,KAAK;AAAA,EAClF;AAAA;AAAA,EAGA,WAAsC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,eAAuB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,gBAAgB,UAAwB;AACtC,QAAI,KAAK,cAAc,UAAU;AAC/B,YAAM,IAAI,MAAM,YAAY,QAAQ,qBAAqB,KAAK,SAAS,EAAE;AAAA,IAC3E;AAAA,EACF;AAAA;AAAA,EAGA,kBAAkB,UAAqD;AACrE,QAAI,SAAS,UAAU,UAAa,KAAK,qBAAqB,SAAS,OAAO;AAC5E,YAAM,IAAI,MAAM,YAAY,SAAS,KAAK,sBAAsB,KAAK,gBAAgB,EAAE;AAAA,IACzF;AACA,QAAI,SAAS,WAAW,UAAa,KAAK,sBAAsB,SAAS,QAAQ;AAC/E,YAAM,IAAI,MAAM,YAAY,SAAS,MAAM,uBAAuB,KAAK,iBAAiB,EAAE;AAAA,IAC5F;AAAA,EACF;AAAA,EAEA,iBAAoD;AAClD,WAAO,EAAE,OAAO,KAAK,kBAAkB,QAAQ,KAAK,kBAAkB;AAAA,EACxE;AAAA,EAEA,QAAc;AACZ,SAAK,iBAAiB,SAAS;AAC/B,SAAK,gBAAgB,SAAS;AAC9B,SAAK,MAAM,SAAS;AACpB,SAAK,YAAY;AACjB,SAAK,mBAAmB;AACxB,SAAK,oBAAoB;AAAA,EAC3B;AACF;;;AChHO,IAAM,yBAAyB,uBAAO;AAAA,EAC3C;AACF;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type ModelTier = "fast" | "balanced" | "powerful";
|
|
2
|
+
type ProviderKind = "api" | "claude-code" | "codex" | "copilot" | "kiro";
|
|
3
|
+
declare const PROVIDER_KINDS: readonly ProviderKind[];
|
|
4
|
+
interface LLMChatRequest {
|
|
5
|
+
systemPrompt: string;
|
|
6
|
+
userMessage: string;
|
|
7
|
+
tier: ModelTier;
|
|
8
|
+
}
|
|
9
|
+
interface LLMChatResponse {
|
|
10
|
+
content: string;
|
|
11
|
+
tokens: {
|
|
12
|
+
input: number;
|
|
13
|
+
output: number;
|
|
14
|
+
};
|
|
15
|
+
/** AD-002: false when the provider does not report usage; `tokens` is then 0/0 and must not be shown as real. */
|
|
16
|
+
tokensAvailable: boolean;
|
|
17
|
+
}
|
|
18
|
+
interface LLMProvider {
|
|
19
|
+
chat(req: LLMChatRequest): Promise<LLMChatResponse>;
|
|
20
|
+
}
|
|
21
|
+
interface ModelConfig {
|
|
22
|
+
fast: string;
|
|
23
|
+
balanced: string;
|
|
24
|
+
powerful: string;
|
|
25
|
+
}
|
|
26
|
+
interface ProviderConfig {
|
|
27
|
+
kind: ProviderKind;
|
|
28
|
+
models: ModelConfig;
|
|
29
|
+
apiKey?: string;
|
|
30
|
+
claudeCliPath?: string;
|
|
31
|
+
codexCliPath?: string;
|
|
32
|
+
copilotCliPath?: string;
|
|
33
|
+
kiroCliPath?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { type LLMProvider as L, type ModelTier as M, type ProviderKind as P, type ProviderConfig as a, type LLMChatRequest as b, type LLMChatResponse as c, type ModelConfig as d, PROVIDER_KINDS as e };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denisvieiradev/gitwise-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared logic for gitwise: non-interactive commit/review/pr/release commands, LLM providers, git/github primitives, prompt templates.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"node": ">=22.12.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@anthropic-ai/sdk": "^0.
|
|
56
|
+
"@anthropic-ai/sdk": "^0.127.0"
|
|
57
57
|
}
|
|
58
58
|
}
|
package/dist/types-DnMpR1qf.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
type ModelTier = "fast" | "balanced" | "powerful";
|
|
2
|
-
interface LLMChatRequest {
|
|
3
|
-
systemPrompt: string;
|
|
4
|
-
userMessage: string;
|
|
5
|
-
tier: ModelTier;
|
|
6
|
-
}
|
|
7
|
-
interface LLMChatResponse {
|
|
8
|
-
content: string;
|
|
9
|
-
tokens: {
|
|
10
|
-
input: number;
|
|
11
|
-
output: number;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
interface LLMProvider {
|
|
15
|
-
chat(req: LLMChatRequest): Promise<LLMChatResponse>;
|
|
16
|
-
}
|
|
17
|
-
interface ModelConfig {
|
|
18
|
-
fast: string;
|
|
19
|
-
balanced: string;
|
|
20
|
-
powerful: string;
|
|
21
|
-
}
|
|
22
|
-
interface ProviderConfig {
|
|
23
|
-
kind: "api" | "claude-code";
|
|
24
|
-
models: ModelConfig;
|
|
25
|
-
apiKey?: string;
|
|
26
|
-
claudeCliPath?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type { LLMProvider as L, ModelTier as M, ProviderConfig as P, LLMChatRequest as a, LLMChatResponse as b, ModelConfig as c };
|