opencodekit 0.15.19 → 0.15.20
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.js +1 -1
- package/dist/template/.opencode/memory/observations/2026-01-30-discovery-context-management-research-critical-gap.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-decision-copilot-auth-plugin-updated-with-baseurl.md +63 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-auth-comparison-finding.md +61 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-learning-opencode-copilot-reasoning-architecture-.md +66 -0
- package/dist/template/.opencode/memory/observations/2026-01-31-warning-copilot-claude-v1-endpoint-returns-404-c.md +48 -0
- package/dist/template/.opencode/memory/research/context-management-analysis.md +685 -0
- package/dist/template/.opencode/opencode.json +52 -156
- package/dist/template/.opencode/package.json +1 -1
- package/dist/template/.opencode/plugins/copilot-auth.ts +289 -24
- package/dist/template/.opencode/plugins/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +181 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/get-response-metadata.ts +15 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +19 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-api-types.ts +72 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-chat-language-model.ts +823 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-chat-options.ts +30 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +48 -0
- package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-prepare-tools.ts +92 -0
- package/dist/template/.opencode/plugins/sdk/copilot/copilot-provider.ts +94 -0
- package/dist/template/.opencode/plugins/sdk/copilot/index.ts +5 -0
- package/dist/template/.opencode/plugins/sdk/copilot/openai-compatible-error.ts +30 -0
- package/package.json +1 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export type OpenAICompatibleChatModelId = string;
|
|
4
|
+
|
|
5
|
+
export const openaiCompatibleProviderOptions = z.object({
|
|
6
|
+
/**
|
|
7
|
+
* A unique identifier representing your end-user, which can help the provider to
|
|
8
|
+
* monitor and detect abuse.
|
|
9
|
+
*/
|
|
10
|
+
user: z.string().optional(),
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
14
|
+
*/
|
|
15
|
+
reasoningEffort: z.string().optional(),
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Controls the verbosity of the generated text. Defaults to `medium`.
|
|
19
|
+
*/
|
|
20
|
+
textVerbosity: z.string().optional(),
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Copilot thinking_budget used for Anthropic models.
|
|
24
|
+
*/
|
|
25
|
+
thinking_budget: z.number().optional(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type OpenAICompatibleProviderOptions = z.infer<
|
|
29
|
+
typeof openaiCompatibleProviderOptions
|
|
30
|
+
>;
|
package/dist/template/.opencode/plugins/sdk/copilot/chat/openai-compatible-metadata-extractor.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SharedV2ProviderMetadata } from "@ai-sdk/provider";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Extracts provider-specific metadata from API responses.
|
|
5
|
+
Used to standardize metadata handling across different LLM providers while allowing
|
|
6
|
+
provider-specific metadata to be captured.
|
|
7
|
+
*/
|
|
8
|
+
export type MetadataExtractor = {
|
|
9
|
+
/**
|
|
10
|
+
* Extracts provider metadata from a complete, non-streaming response.
|
|
11
|
+
*
|
|
12
|
+
* @param parsedBody - The parsed response JSON body from the provider's API.
|
|
13
|
+
*
|
|
14
|
+
* @returns Provider-specific metadata or undefined if no metadata is available.
|
|
15
|
+
* The metadata should be under a key indicating the provider id.
|
|
16
|
+
*/
|
|
17
|
+
extractMetadata: ({
|
|
18
|
+
parsedBody,
|
|
19
|
+
}: {
|
|
20
|
+
parsedBody: unknown;
|
|
21
|
+
}) => Promise<SharedV2ProviderMetadata | undefined>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates an extractor for handling streaming responses. The returned object provides
|
|
25
|
+
* methods to process individual chunks and build the final metadata from the accumulated
|
|
26
|
+
* stream data.
|
|
27
|
+
*
|
|
28
|
+
* @returns An object with methods to process chunks and build metadata from a stream
|
|
29
|
+
*/
|
|
30
|
+
createStreamExtractor: () => {
|
|
31
|
+
/**
|
|
32
|
+
* Process an individual chunk from the stream. Called for each chunk in the response stream
|
|
33
|
+
* to accumulate metadata throughout the streaming process.
|
|
34
|
+
*
|
|
35
|
+
* @param parsedChunk - The parsed JSON response chunk from the provider's API
|
|
36
|
+
*/
|
|
37
|
+
processChunk(parsedChunk: unknown): void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Builds the metadata object after all chunks have been processed.
|
|
41
|
+
* Called at the end of the stream to generate the complete provider metadata.
|
|
42
|
+
*
|
|
43
|
+
* @returns Provider-specific metadata or undefined if no metadata is available.
|
|
44
|
+
* The metadata should be under a key indicating the provider id.
|
|
45
|
+
*/
|
|
46
|
+
buildMetadata(): SharedV2ProviderMetadata | undefined;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type LanguageModelV2CallOptions,
|
|
3
|
+
type LanguageModelV2CallWarning,
|
|
4
|
+
UnsupportedFunctionalityError,
|
|
5
|
+
} from "@ai-sdk/provider";
|
|
6
|
+
|
|
7
|
+
export function prepareTools({
|
|
8
|
+
tools,
|
|
9
|
+
toolChoice,
|
|
10
|
+
}: {
|
|
11
|
+
tools: LanguageModelV2CallOptions["tools"];
|
|
12
|
+
toolChoice?: LanguageModelV2CallOptions["toolChoice"];
|
|
13
|
+
}): {
|
|
14
|
+
tools:
|
|
15
|
+
| undefined
|
|
16
|
+
| Array<{
|
|
17
|
+
type: "function";
|
|
18
|
+
function: {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string | undefined;
|
|
21
|
+
parameters: unknown;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
toolChoice:
|
|
25
|
+
| { type: "function"; function: { name: string } }
|
|
26
|
+
| "auto"
|
|
27
|
+
| "none"
|
|
28
|
+
| "required"
|
|
29
|
+
| undefined;
|
|
30
|
+
toolWarnings: LanguageModelV2CallWarning[];
|
|
31
|
+
} {
|
|
32
|
+
// when the tools array is empty, change it to undefined to prevent errors:
|
|
33
|
+
tools = tools?.length ? tools : undefined;
|
|
34
|
+
|
|
35
|
+
const toolWarnings: LanguageModelV2CallWarning[] = [];
|
|
36
|
+
|
|
37
|
+
if (tools == null) {
|
|
38
|
+
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const openaiCompatTools: Array<{
|
|
42
|
+
type: "function";
|
|
43
|
+
function: {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string | undefined;
|
|
46
|
+
parameters: unknown;
|
|
47
|
+
};
|
|
48
|
+
}> = [];
|
|
49
|
+
|
|
50
|
+
for (const tool of tools) {
|
|
51
|
+
if (tool.type === "provider-defined") {
|
|
52
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
53
|
+
} else {
|
|
54
|
+
openaiCompatTools.push({
|
|
55
|
+
type: "function",
|
|
56
|
+
function: {
|
|
57
|
+
name: tool.name,
|
|
58
|
+
description: tool.description,
|
|
59
|
+
parameters: tool.inputSchema,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (toolChoice == null) {
|
|
66
|
+
return { tools: openaiCompatTools, toolChoice: undefined, toolWarnings };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const type = toolChoice.type;
|
|
70
|
+
|
|
71
|
+
switch (type) {
|
|
72
|
+
case "auto":
|
|
73
|
+
case "none":
|
|
74
|
+
case "required":
|
|
75
|
+
return { tools: openaiCompatTools, toolChoice: type, toolWarnings };
|
|
76
|
+
case "tool":
|
|
77
|
+
return {
|
|
78
|
+
tools: openaiCompatTools,
|
|
79
|
+
toolChoice: {
|
|
80
|
+
type: "function",
|
|
81
|
+
function: { name: toolChoice.toolName },
|
|
82
|
+
},
|
|
83
|
+
toolWarnings,
|
|
84
|
+
};
|
|
85
|
+
default: {
|
|
86
|
+
const _exhaustiveCheck: never = type;
|
|
87
|
+
throw new UnsupportedFunctionalityError({
|
|
88
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { LanguageModelV2 } from "@ai-sdk/provider";
|
|
2
|
+
import {
|
|
3
|
+
type FetchFunction,
|
|
4
|
+
withUserAgentSuffix,
|
|
5
|
+
withoutTrailingSlash,
|
|
6
|
+
} from "@ai-sdk/provider-utils";
|
|
7
|
+
import { OpenAICompatibleChatLanguageModel } from "./chat/openai-compatible-chat-language-model";
|
|
8
|
+
|
|
9
|
+
// Import the version or define it
|
|
10
|
+
const VERSION = "0.1.0";
|
|
11
|
+
|
|
12
|
+
export type OpenaiCompatibleModelId = string;
|
|
13
|
+
|
|
14
|
+
export interface OpenaiCompatibleProviderSettings {
|
|
15
|
+
/**
|
|
16
|
+
* API key for authenticating requests.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Base URL for the OpenAI Compatible API calls.
|
|
22
|
+
*/
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Name of the provider.
|
|
27
|
+
*/
|
|
28
|
+
name?: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Custom headers to include in the requests.
|
|
32
|
+
*/
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Custom fetch implementation.
|
|
37
|
+
*/
|
|
38
|
+
fetch?: FetchFunction;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface OpenaiCompatibleProvider {
|
|
42
|
+
(modelId: OpenaiCompatibleModelId): LanguageModelV2;
|
|
43
|
+
chat(modelId: OpenaiCompatibleModelId): LanguageModelV2;
|
|
44
|
+
languageModel(modelId: OpenaiCompatibleModelId): LanguageModelV2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create an OpenAI Compatible provider instance for GitHub Copilot.
|
|
49
|
+
* This custom provider handles Claude reasoning tokens (thinking_budget).
|
|
50
|
+
*/
|
|
51
|
+
export function createOpenaiCompatible(
|
|
52
|
+
options: OpenaiCompatibleProviderSettings = {},
|
|
53
|
+
): OpenaiCompatibleProvider {
|
|
54
|
+
const baseURL = withoutTrailingSlash(
|
|
55
|
+
options.baseURL ?? "https://api.openai.com/v1",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (!baseURL) {
|
|
59
|
+
throw new Error("baseURL is required");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Merge headers: defaults first, then user overrides
|
|
63
|
+
const headers = {
|
|
64
|
+
// Default OpenAI Compatible headers (can be overridden by user)
|
|
65
|
+
...(options.apiKey && { Authorization: `Bearer ${options.apiKey}` }),
|
|
66
|
+
...options.headers,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getHeaders = () =>
|
|
70
|
+
withUserAgentSuffix(headers, `ai-sdk/openai-compatible/${VERSION}`);
|
|
71
|
+
|
|
72
|
+
const createChatModel = (modelId: OpenaiCompatibleModelId) => {
|
|
73
|
+
return new OpenAICompatibleChatLanguageModel(modelId, {
|
|
74
|
+
provider: `${options.name ?? "openai-compatible"}.chat`,
|
|
75
|
+
headers: getHeaders,
|
|
76
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
77
|
+
fetch: options.fetch,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const createLanguageModel = (modelId: OpenaiCompatibleModelId) =>
|
|
82
|
+
createChatModel(modelId);
|
|
83
|
+
|
|
84
|
+
const provider = (modelId: OpenaiCompatibleModelId) =>
|
|
85
|
+
createChatModel(modelId);
|
|
86
|
+
|
|
87
|
+
provider.languageModel = createLanguageModel;
|
|
88
|
+
provider.chat = createChatModel;
|
|
89
|
+
|
|
90
|
+
return provider as OpenaiCompatibleProvider;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Default OpenAI Compatible provider instance
|
|
94
|
+
export const openaiCompatible = createOpenaiCompatible();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ZodType, z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const openaiCompatibleErrorDataSchema = z.object({
|
|
4
|
+
error: z.object({
|
|
5
|
+
message: z.string(),
|
|
6
|
+
|
|
7
|
+
// The additional information below is handled loosely to support
|
|
8
|
+
// OpenAI-compatible providers that have slightly different error
|
|
9
|
+
// responses:
|
|
10
|
+
type: z.string().nullish(),
|
|
11
|
+
param: z.any().nullish(),
|
|
12
|
+
code: z.union([z.string(), z.number()]).nullish(),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export type OpenAICompatibleErrorData = z.infer<
|
|
17
|
+
typeof openaiCompatibleErrorDataSchema
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export type ProviderErrorStructure<T> = {
|
|
21
|
+
errorSchema: ZodType<T>;
|
|
22
|
+
errorToMessage: (error: T) => string;
|
|
23
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const defaultOpenAICompatibleErrorStructure: ProviderErrorStructure<OpenAICompatibleErrorData> =
|
|
27
|
+
{
|
|
28
|
+
errorSchema: openaiCompatibleErrorDataSchema,
|
|
29
|
+
errorToMessage: (data) => data.error.message,
|
|
30
|
+
};
|
package/package.json
CHANGED