@polka-codes/core 0.7.0 → 0.7.2

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 (2) hide show
  1. package/dist/index.js +43 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13420,6 +13420,7 @@ class OpenRouterService extends AiServiceBase {
13420
13420
  #client;
13421
13421
  #apiKey;
13422
13422
  #options;
13423
+ #modelProviderInfo;
13423
13424
  model;
13424
13425
  constructor(options) {
13425
13426
  super(options.usageMeter);
@@ -13444,6 +13445,9 @@ class OpenRouterService extends AiServiceBase {
13444
13445
  id: options.model,
13445
13446
  info: {}
13446
13447
  };
13448
+ fetch(`https://openrouter.ai/api/v1/models/${this.model.id}/endpoints`).then((res) => res.json()).then((data) => {
13449
+ this.#modelProviderInfo = data.data;
13450
+ });
13447
13451
  }
13448
13452
  async* sendImpl(systemPrompt, messages) {
13449
13453
  const openAiMessages = [
@@ -13564,12 +13568,20 @@ class OpenRouterService extends AiServiceBase {
13564
13568
  signal: controller.signal
13565
13569
  });
13566
13570
  const responseBody = await response.json();
13567
- const generation = responseBody.data;
13571
+ const generation = responseBody.data ?? {};
13572
+ let totalCost = generation.total_cost || 0;
13573
+ if (generation.is_byok && this.#modelProviderInfo) {
13574
+ const price = this.#modelProviderInfo.endpoints.find((e) => e.provider_name === generation.provider_name)?.pricing;
13575
+ if (price) {
13576
+ totalCost += (generation.native_tokens_prompt || 0) * price.request;
13577
+ totalCost += (generation.native_tokens_completion || 0) * price.completion;
13578
+ }
13579
+ }
13568
13580
  yield {
13569
13581
  type: "usage",
13570
- inputTokens: generation?.native_tokens_prompt || 0,
13571
- outputTokens: generation?.native_tokens_completion || 0,
13572
- totalCost: generation?.total_cost || 0
13582
+ inputTokens: generation.native_tokens_prompt || 0,
13583
+ outputTokens: generation.native_tokens_completion || 0,
13584
+ totalCost
13573
13585
  };
13574
13586
  } catch (error) {
13575
13587
  console.error("Error fetching OpenRouter generation details:", error);
@@ -15072,7 +15084,7 @@ ${agents}`;
15072
15084
  content: userMessage
15073
15085
  });
15074
15086
  let currentAssistantMessage = "";
15075
- const retryCount = 3;
15087
+ const retryCount = 5;
15076
15088
  for (let i = 0;i < retryCount; i++) {
15077
15089
  currentAssistantMessage = "";
15078
15090
  const stream = this.ai.send(this.config.systemPrompt, this.messages);
@@ -15848,14 +15860,38 @@ var prompt = `You are an AiTool designed to assist users in creating new project
15848
15860
  - ".env.*"
15849
15861
  \`\`\`
15850
15862
 
15851
- 5. **Handover to Coder Agent:**
15863
+ 5. **Generate Essential Project Files:**
15864
+ - Create a .gitattributes file with appropriate configurations:
15865
+ - Mark lock files as generated and exclude them from diffs
15866
+ - Example for different package managers:
15867
+
15868
+ # For Bun
15869
+ bun.lock linguist-generated=true
15870
+ bun.lock -diff
15871
+
15872
+ # For npm
15873
+ package-lock.json linguist-generated=true
15874
+ package-lock.json -diff
15875
+
15876
+ # For Yarn
15877
+ yarn.lock linguist-generated=true
15878
+ yarn.lock -diff
15879
+
15880
+ # For pnpm
15881
+ pnpm-lock.yaml linguist-generated=true
15882
+ pnpm-lock.yaml -diff
15883
+
15884
+ - Include other common configurations as needed based on project type
15885
+
15886
+ 6. **Handover to Coder Agent:**
15852
15887
  - Once all required information is collected and validated by the user, compile:
15853
15888
  1. The final project specifications
15854
15889
  2. The .polkacodes.yml configuration content
15855
15890
  - Clearly hand over these details to the coder agent, instructing them to:
15856
15891
  1. Create the new project based on the confirmed specifications
15857
15892
  2. Include the .polkacodes.yml file in the project root
15858
- 3. Ensure all specified tools and configurations are properly set up`;
15893
+ 3. Include the .gitattributes file with appropriate configurations
15894
+ 4. Ensure all specified tools and configurations are properly set up`;
15859
15895
  var createNewProject_default = {
15860
15896
  name: "createNewProject",
15861
15897
  description: "Creates a new project",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",