@codeworksh/aikit 0.12.1 → 0.13.0-canary.100.1.g71d09a02

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.
Files changed (50) hide show
  1. package/cli.mjs +5 -5
  2. package/{codex-CLDBTrFm.mjs → codex-DvULd3EJ.mjs} +2 -56
  3. package/codex-DvULd3EJ.mjs.map +1 -0
  4. package/{copilot-DvUXC6Kx.mjs → copilot-D9T1jbpu.mjs} +13 -3
  5. package/copilot-D9T1jbpu.mjs.map +1 -0
  6. package/{copilot-headers-BLnBaJyp.mjs → copilot-headers-I-AOoDed.mjs} +2 -2
  7. package/{copilot-headers-BLnBaJyp.mjs.map → copilot-headers-I-AOoDed.mjs.map} +1 -1
  8. package/{failure-5Wjd-qFH.d.mts → failure-CCCRfhCf.d.mts} +6 -3
  9. package/{failure-DFQNKc-O.mjs → failure-D0qEqOsO.mjs} +37 -5
  10. package/failure-D0qEqOsO.mjs.map +1 -0
  11. package/github-copilot-C75m0xwW.mjs +3 -0
  12. package/{github-copilot-BcmOr0jd.mjs → github-copilot-CdkIxdQS.mjs} +31 -15
  13. package/github-copilot-CdkIxdQS.mjs.map +1 -0
  14. package/index.d.mts +540 -237
  15. package/index.mjs +566 -103
  16. package/index.mjs.map +1 -1
  17. package/interactive-c0deRdi7.mjs +115 -0
  18. package/interactive-c0deRdi7.mjs.map +1 -0
  19. package/llm/failure.d.mts +2 -2
  20. package/llm/failure.mjs +2 -2
  21. package/{model-Cjp-Dr8V.mjs → model-BZZZAySN.mjs} +564 -617
  22. package/{model-Cjp-Dr8V.mjs.map → model-BZZZAySN.mjs.map} +1 -1
  23. package/{model-D3wc9-u4.d.mts → model-Dgf7E5gc.d.mts} +20 -1
  24. package/{openai-codex-C1Yb02kM.mjs → model-av44O6GQ.mjs} +340 -355
  25. package/model-av44O6GQ.mjs.map +1 -0
  26. package/{modelgen-DXMmI80T.mjs → modelgen-f3yv7FiK.mjs} +50 -17
  27. package/modelgen-f3yv7FiK.mjs.map +1 -0
  28. package/modelgen.d.mts +1 -1
  29. package/modelgen.mjs +2 -2
  30. package/oauth/github/copilot.d.mts +10 -0
  31. package/oauth/github/copilot.mjs +2 -2
  32. package/oauth/interactive.d.mts +6 -1
  33. package/oauth/interactive.mjs +2 -2
  34. package/oauth/openai/codex.mjs +1 -1
  35. package/openai-codex-BGNrJzTb.mjs +2 -0
  36. package/openai-codex-DL0lqVuN.mjs +117 -0
  37. package/openai-codex-DL0lqVuN.mjs.map +1 -0
  38. package/package.json +1 -1
  39. package/{registry-u49t0S4S.mjs → registry-BULNTLAP.mjs} +10 -6
  40. package/{registry-u49t0S4S.mjs.map → registry-BULNTLAP.mjs.map} +1 -1
  41. package/codex-CLDBTrFm.mjs.map +0 -1
  42. package/copilot-DvUXC6Kx.mjs.map +0 -1
  43. package/failure-DFQNKc-O.mjs.map +0 -1
  44. package/github-copilot-BcmOr0jd.mjs.map +0 -1
  45. package/github-copilot-llyP2NK4.mjs +0 -3
  46. package/interactive-eoNnscGB.mjs +0 -57
  47. package/interactive-eoNnscGB.mjs.map +0 -1
  48. package/modelgen-DXMmI80T.mjs.map +0 -1
  49. package/openai-codex-C1Yb02kM.mjs.map +0 -1
  50. package/openai-codex-CHxShIN3.mjs +0 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-copilot-CdkIxdQS.mjs","names":[],"sources":["../../src/providers/github-copilot/copilot-fetch.ts","../../src/providers/github-copilot/copilot-provider.ts"],"sourcesContent":["import { LoadAPIKeyError } from \"@ai-sdk/provider\";\nimport { applyCopilotHeaders, type GitHubCopilotInteractionType } from \"./copilot-headers.ts\";\n\nexport type GitHubCopilotApiKey = string | (() => string | PromiseLike<string | undefined> | undefined);\n\nexport type CopilotFetchOptions = {\n\t/** Static token or async resolver — e.g. `() => getGitHubCopilotApiKey()`. */\n\tapiKey?: GitHubCopilotApiKey;\n\t/** Upstream fetch implementation; defaults to `globalThis.fetch`. */\n\tfetch?: typeof globalThis.fetch;\n\t/** Sent as `X-Interaction-Id` so Copilot can group requests by session. */\n\tsessionId?: string;\n\tinteractionType?: GitHubCopilotInteractionType;\n};\n\n// Only the Copilot-specific variable: GITHUB_TOKEN and GH_TOKEN are usually set\n// for git or `gh` and have no Copilot access.\nconst API_KEY_ENV = \"COPILOT_GITHUB_TOKEN\";\n\nasync function resolveToken(apiKey: GitHubCopilotApiKey | undefined): Promise<string> {\n\tconst resolved = typeof apiKey === \"function\" ? await apiKey() : apiKey;\n\tif (resolved) return resolved;\n\tconst fromEnv = typeof process === \"undefined\" ? undefined : process.env[API_KEY_ENV];\n\tif (fromEnv) return fromEnv;\n\tthrow new LoadAPIKeyError({\n\t\tmessage: `GitHub Copilot API key is missing. Set ${API_KEY_ENV}, pass an apiKey, or authenticate with \\`aikit auth --github-copilot\\`.`,\n\t});\n}\n\nfunction parseJson(text: string): unknown {\n\ttry {\n\t\treturn JSON.parse(text) as unknown;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Wrap an upstream fetch with Copilot auth and request metadata. The wrapped\n * call replaces adapter-set auth headers, injects the Copilot identity\n * headers, and derives `x-initiator` / `Copilot-Vision-Request` from the\n * serialized JSON body without consuming it.\n */\nexport function createCopilotFetch(options: CopilotFetchOptions = {}): typeof globalThis.fetch {\n\tconst upstream = options.fetch ?? globalThis.fetch;\n\treturn async (input, init) => {\n\t\tconst token = await resolveToken(options.apiKey);\n\t\tconst headers = new Headers(init?.headers);\n\t\tconst url = input instanceof URL ? input.href : typeof input === \"string\" ? input : input.url;\n\t\tconst body = typeof init?.body === \"string\" ? parseJson(init.body) : undefined;\n\t\tapplyCopilotHeaders(headers, {\n\t\t\ttoken,\n\t\t\turl,\n\t\t\tbody,\n\t\t\t...(options.sessionId !== undefined && { sessionId: options.sessionId }),\n\t\t\t...(options.interactionType !== undefined && { interactionType: options.interactionType }),\n\t\t});\n\t\treturn upstream(input, { ...init, headers });\n\t};\n}\n","/**\n * GitHub Copilot provider.\n *\n * Copilot exposes three inference protocols on one host — OpenAI Chat\n * Completions (`/chat/completions`), OpenAI Responses (`/responses`), and\n * Anthropic Messages (`/v1/messages`) — so this provider routes each model\n * through `api.method`. Chat and Messages use the official AI SDK adapters;\n * Responses uses aikit's own Responses model, which declares tools added\n * mid-conversation in place. Auth and Copilot request headers are applied inside\n * the shared fetch wrapper, which is why the adapters receive a placeholder key:\n * their headers never reach the wire.\n */\n\nimport { createAnthropic } from \"@ai-sdk/anthropic\";\nimport { createOpenAICompatible } from \"@ai-sdk/openai-compatible\";\nimport { NoSuchModelError, type LanguageModelV3, type LanguageModelV4, type ProviderV4 } from \"@ai-sdk/provider\";\nimport {\n\tResponsesLanguageModel,\n\ttype ResponsesCompatibility,\n\ttype ResponsesRequestProfile,\n} from \"../responses/model.ts\";\nimport { createCopilotFetch, type GitHubCopilotApiKey } from \"./copilot-fetch.ts\";\nimport type { GitHubCopilotInteractionType } from \"./copilot-headers.ts\";\n\nexport const GITHUB_COPILOT_DEFAULT_BASE_URL = \"https://api.githubcopilot.com\";\nexport const GITHUB_COPILOT_PROVIDER_NAME = \"github-copilot\";\n\nconst PLACEHOLDER_API_KEY = \"github-copilot\";\n\n/** The copilot fetch reads the JSON body for its headers, so it goes uncompressed. */\nconst COPILOT_RESPONSES_REQUEST: ResponsesRequestProfile = {\n\tsystemPrompt: \"developer\",\n\tmaxOutputTokens: true,\n\tencryptedReasoning: \"withEffort\",\n\tcompress: false,\n\ttoolDefaults: false,\n};\n\nexport interface GitHubCopilotProvider extends ProviderV4 {\n\t/** Chat Completions — the generic fallback for third-party models. */\n\t(modelId: string): LanguageModelV4;\n\tlanguageModel(modelId: string): LanguageModelV4;\n\t/** `POST /chat/completions` — Gemini, Kimi, and other third-party models. */\n\tchat(modelId: string): LanguageModelV4;\n\t/** `POST /responses` — GPT, Grok, OSWE, and MAI models. */\n\tresponses(modelId: string): LanguageModelV3;\n\t/** `POST /v1/messages` — Claude models. */\n\tmessages(modelId: string): LanguageModelV4;\n}\n\nexport interface GitHubCopilotProviderSettings {\n\t/**\n\t * Copilot API host. Defaults to `https://api.githubcopilot.com`; OAuth\n\t * credentials can carry a plan-specific `apiEndpoint` that overrides this.\n\t */\n\tbaseURL?: string;\n\t/**\n\t * GitHub OAuth token (`ghu_`/`gho_`) or an async resolver, e.g.\n\t * `() => getGitHubCopilotApiKey()`. Falls back to `COPILOT_GITHUB_TOKEN`.\n\t */\n\tapiKey?: GitHubCopilotApiKey;\n\t/** Extra headers merged into every request. */\n\theaders?: Record<string, string>;\n\t/** Custom fetch implementation, applied underneath the Copilot wrapper. */\n\tfetch?: typeof globalThis.fetch;\n\t/** Sent as `X-Interaction-Id` so Copilot can group requests by session. */\n\tsessionId?: string;\n\tinteractionType?: GitHubCopilotInteractionType;\n\t/** Forwarded to the Chat Completions adapter only. */\n\ttransformRequestBody?: (body: Record<string, unknown>) => Record<string, unknown>;\n\t/** Sent as `prompt_cache_key` on Responses requests. */\n\tpromptCacheKey?: string;\n\t/** Responses model capabilities supplied by aikit; absent flags are disabled. */\n\tcompat?: ResponsesCompatibility;\n}\n\nexport function createGitHubCopilot(options: GitHubCopilotProviderSettings = {}): GitHubCopilotProvider {\n\tconst baseURL = (options.baseURL ?? GITHUB_COPILOT_DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n\tconst fetch = createCopilotFetch({\n\t\t...(options.apiKey !== undefined && { apiKey: options.apiKey }),\n\t\t...(options.fetch !== undefined && { fetch: options.fetch }),\n\t\t...(options.sessionId !== undefined && { sessionId: options.sessionId }),\n\t\t...(options.interactionType !== undefined && { interactionType: options.interactionType }),\n\t});\n\tconst headers = options.headers !== undefined ? { headers: options.headers } : {};\n\n\tconst chat = createOpenAICompatible({\n\t\tname: GITHUB_COPILOT_PROVIDER_NAME,\n\t\tbaseURL,\n\t\tapiKey: PLACEHOLDER_API_KEY,\n\t\t...headers,\n\t\tfetch,\n\t\tincludeUsage: true,\n\t\t...(options.transformRequestBody !== undefined && { transformRequestBody: options.transformRequestBody }),\n\t});\n\tconst responses = (modelId: string) =>\n\t\tnew ResponsesLanguageModel(modelId, {\n\t\t\tprovider: GITHUB_COPILOT_PROVIDER_NAME,\n\t\t\tlabel: \"GitHub Copilot\",\n\t\t\turl: `${baseURL}/responses`,\n\t\t\theaders: () => ({ ...options.headers, accept: \"text/event-stream\", \"content-type\": \"application/json\" }),\n\t\t\tfetch,\n\t\t\trequest: COPILOT_RESPONSES_REQUEST,\n\t\t\t...(options.promptCacheKey !== undefined && { promptCacheKey: options.promptCacheKey }),\n\t\t\t...(options.compat !== undefined && { compat: options.compat }),\n\t\t});\n\tconst messages = createAnthropic({\n\t\tname: GITHUB_COPILOT_PROVIDER_NAME,\n\t\t// The Anthropic adapter appends /messages to its baseURL.\n\t\tbaseURL: `${baseURL}/v1`,\n\t\tauthToken: PLACEHOLDER_API_KEY,\n\t\t...headers,\n\t\tfetch,\n\t});\n\n\tconst provider = function (modelId: string): LanguageModelV4 {\n\t\tif (new.target) {\n\t\t\tthrow new Error(\"github copilot model function cannot be called with the new keyword.\");\n\t\t}\n\t\treturn chat.chatModel(modelId);\n\t};\n\tprovider.specificationVersion = \"v4\" as const;\n\tprovider.languageModel = (modelId: string) => chat.chatModel(modelId);\n\tprovider.chat = (modelId: string) => chat.chatModel(modelId);\n\tprovider.responses = responses;\n\tprovider.messages = (modelId: string) => messages.messages(modelId);\n\tprovider.embeddingModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({\n\t\t\tmodelId,\n\t\t\tmodelType: \"embeddingModel\",\n\t\t\tmessage: \"github copilot does not expose embedding models\",\n\t\t});\n\t};\n\tprovider.textEmbeddingModel = provider.embeddingModel;\n\tprovider.imageModel = (modelId: string) => {\n\t\tthrow new NoSuchModelError({\n\t\t\tmodelId,\n\t\t\tmodelType: \"imageModel\",\n\t\t\tmessage: \"github copilot does not expose image models\",\n\t\t});\n\t};\n\n\treturn provider;\n}\n\nexport const githubCopilot = createGitHubCopilot();\n"],"mappings":";;;;;;AAiBA,MAAM,cAAc;AA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