MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / AxonClient

Class AxonClient

src/api/client.ts:36–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36export class AxonClient implements LLMClient {
37 private client: OpenAI;
38 private options: AxonClientOptions;
39
40 constructor(options: AxonClientOptions) {
41 this.options = options;
42 this.client = new OpenAI({
43 // Use the gateway URL directly. Do not rehost it through
44 // getUrlFromToken — that helper rewrites any api.matterai.so host
45 // onto the control plane, which would send inference to
46 // api.matterai.so instead of the gateway at api2.matterai.so.
47 // Per-model `baseUrl` overrides (e.g. local dev) still win.
48 baseURL: options.baseUrl || API_GATEWAY_PATH,
49 apiKey: options.token,
50 defaultHeaders: DEFAULT_HEADERS,
51 });
52 }
53
54 private requestHeaders(): Record<string, string> {
55 const headers: Record<string, string> = {
56 [X_AXONCODE_TASKID]: this.options.taskId,
57 };
58 if (this.options.organizationId)
59 headers[X_ORGANIZATIONID] = this.options.organizationId;
60 if (this.options.repo) headers[X_AXON_REPO] = this.options.repo;
61 return headers;
62 }
63
64 async *createMessage(
65 systemPrompt: string,
66 messages: OpenAI.Chat.ChatCompletionMessageParam[],
67 tools: OpenAI.Chat.ChatCompletionTool[],
68 abortSignal?: AbortSignal,
69 ): AsyncGenerator<ApiStreamChunk> {
70 const model = getModel(this.options.modelId);
71
72 const requestOptions: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming =
73 {
74 model: model.id,
75 temperature: 0.2,
76 messages: [
77 { role: "system", content: systemPrompt },
78 ...stripReasoningDetails(messages),
79 ],
80 stream: true,
81 stream_options: { include_usage: true },
82 max_tokens: model.maxOutputTokens,
83 };
84 if (tools.length > 0) {
85 requestOptions.tools = tools;
86 requestOptions.tool_choice = "auto";
87 requestOptions.parallel_tool_calls = true;
88 }
89
90 const stream = await this.client.chat.completions.create(requestOptions, {
91 headers: this.requestHeaders(),
92 signal: abortSignal,
93 });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected