@nuvin/nuvin-core 1.1.0 → 1.1.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.
package/dist/VERSION CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.1.0",
3
- "commit": "6618d91"
2
+ "version": "1.1.2",
3
+ "commit": "76be190"
4
4
  }
package/dist/index.d.ts CHANGED
@@ -19,6 +19,11 @@ type AgentTemplate = {
19
19
  shareContext?: boolean;
20
20
  metadata?: Record<string, unknown>;
21
21
  };
22
+ /**
23
+ * CompleteAgent is an AgentTemplate with all required fields populated
24
+ * Used for registered agents that have gone through applyDefaults()
25
+ */
26
+ type CompleteAgent = Required<Pick<AgentTemplate, 'id' | 'name' | 'description' | 'systemPrompt' | 'tools' | 'temperature' | 'maxTokens'>> & Pick<AgentTemplate, 'provider' | 'model' | 'topP' | 'timeoutMs' | 'shareContext' | 'metadata'>;
22
27
  /**
23
28
  * Specialist Agent Configuration (Internal - used by AgentManager)
24
29
  */
@@ -135,7 +140,7 @@ declare class AgentRegistry {
135
140
  */
136
141
  applyDefaults(partial: Partial<AgentTemplate> & {
137
142
  systemPrompt: string;
138
- }): AgentTemplate;
143
+ }): CompleteAgent;
139
144
  /**
140
145
  * Load agents from memory persistence
141
146
  */
@@ -161,7 +166,7 @@ declare class AgentRegistry {
161
166
  /**
162
167
  * Save agent to file
163
168
  */
164
- saveToFile(agent: AgentTemplate): Promise<void>;
169
+ saveToFile(agent: CompleteAgent): Promise<void>;
165
170
  /**
166
171
  * Delete agent from file
167
172
  */
@@ -177,11 +182,11 @@ declare class AgentRegistry {
177
182
  /**
178
183
  * Get an agent template by ID
179
184
  */
180
- get(agentId: string): AgentTemplate | undefined;
185
+ get(agentId: string): CompleteAgent | undefined;
181
186
  /**
182
187
  * List all registered agent templates
183
188
  */
184
- list(): AgentTemplate[];
189
+ list(): CompleteAgent[];
185
190
  /**
186
191
  * Check if an agent exists
187
192
  */
@@ -349,15 +354,29 @@ type ToolDefinition = {
349
354
  type ToolInvocation = {
350
355
  id: string;
351
356
  name: string;
352
- parameters: Record<string, any>;
357
+ parameters: Record<string, unknown>;
353
358
  };
359
+ declare enum ErrorReason {
360
+ Aborted = "aborted",
361
+ Denied = "denied",
362
+ Timeout = "timeout",
363
+ NotFound = "not_found",
364
+ PermissionDenied = "permission_denied",
365
+ InvalidInput = "invalid_input",
366
+ NetworkError = "network_error",
367
+ RateLimit = "rate_limit",
368
+ ToolNotFound = "tool_not_found",
369
+ Unknown = "unknown"
370
+ }
354
371
  type ToolExecutionResult = {
355
372
  id: string;
356
373
  name: string;
357
374
  status: 'success' | 'error';
358
375
  type: 'text' | 'json';
359
376
  result: string | object;
360
- metadata?: Record<string, unknown>;
377
+ metadata?: Record<string, unknown> & {
378
+ errorReason?: ErrorReason;
379
+ };
361
380
  durationMs?: number;
362
381
  };
363
382
  interface ToolPort {
@@ -908,7 +927,7 @@ declare class DefaultSpecialistAgentFactory implements SpecialistAgentFactory {
908
927
  systemContextProvider?: SystemContextProvider;
909
928
  agentListProvider?: AgentListProvider;
910
929
  idGenerator?: IdGenerator;
911
- });
930
+ } | undefined);
912
931
  create(input: SpecialistAgentFactoryInput): SpecialistAgentConfig;
913
932
  }
914
933
 
@@ -924,7 +943,7 @@ declare class AgentManager {
924
943
  private llmResolver;
925
944
  private activeAgents;
926
945
  private eventCollectors;
927
- constructor(delegatingConfig: AgentConfig, delegatingTools: ToolPort, llmFactory?: LLMFactory, eventCallback?: (event: AgentEvent) => void, configResolver?: () => Partial<AgentConfig>);
946
+ constructor(delegatingConfig: AgentConfig, delegatingTools: ToolPort, llmFactory?: LLMFactory | undefined, eventCallback?: ((event: AgentEvent) => void) | undefined, configResolver?: (() => Partial<AgentConfig>) | undefined);
928
947
  /**
929
948
  * Create and execute a specialist agent for a specific task
930
949
  */
@@ -956,7 +975,7 @@ declare class AgentManagerCommandRunner implements AgentCommandRunner {
956
975
  private readonly delegatingTools;
957
976
  private readonly llmFactory?;
958
977
  private readonly configResolver?;
959
- constructor(delegatingConfig: AgentConfig, delegatingTools: ToolPort, llmFactory?: LLMFactory, configResolver?: () => Partial<AgentConfig>);
978
+ constructor(delegatingConfig: AgentConfig, delegatingTools: ToolPort, llmFactory?: LLMFactory | undefined, configResolver?: (() => Partial<AgentConfig>) | undefined);
960
979
  run(config: Parameters<AgentManager['executeTask']>[0], context?: ToolExecutionContext): Promise<SpecialistAgentResult>;
961
980
  }
962
981
 
@@ -981,7 +1000,7 @@ declare class DefaultDelegationResultFormatter implements DelegationResultFormat
981
1000
  status: "success" | "error" | "timeout";
982
1001
  executionTimeMs: number;
983
1002
  toolCallsExecuted: number;
984
- tokensUsed: number;
1003
+ tokensUsed: number | undefined;
985
1004
  };
986
1005
  };
987
1006
  formatError(error: unknown): string;
@@ -1143,9 +1162,9 @@ declare class GithubAuthTransport implements HttpTransport {
1143
1162
  }
1144
1163
 
1145
1164
  declare class LLMError extends Error {
1146
- readonly statusCode?: number;
1165
+ readonly statusCode?: number | undefined;
1147
1166
  readonly isRetryable: boolean;
1148
- constructor(message: string, statusCode?: number, isRetryable?: boolean, cause?: unknown);
1167
+ constructor(message: string, statusCode?: number | undefined, isRetryable?: boolean, cause?: unknown);
1149
1168
  }
1150
1169
  declare abstract class BaseLLM implements LLMPort {
1151
1170
  protected transport: HttpTransport | null;
@@ -1314,6 +1333,7 @@ declare function loadMCPConfig(filePath?: string): Promise<MCPConfig | null>;
1314
1333
  declare class PersistingConsoleEventPort implements EventPort {
1315
1334
  private memory;
1316
1335
  private maxPerConversation;
1336
+ private writeQueue;
1317
1337
  constructor(opts?: {
1318
1338
  memory?: MemoryPort<AgentEvent>;
1319
1339
  filename?: string;
@@ -1328,4 +1348,4 @@ declare function resolveBackspaces(s: string): string;
1328
1348
  declare function stripAnsiAndControls(s: string): string;
1329
1349
  declare function canonicalizeTerminalPaste(raw: string): string;
1330
1350
 
1331
- export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignParams, BashTool, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, NoopReminders, type OrchestratorAwareToolPort, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UserAttachment, type UserMessagePayload, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, createLLM, generateFolderTree, getAvailableProviders, loadMCPConfig, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels };
1351
+ export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignParams, BashTool, type CompleteAgent, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, ErrorReason, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, NoopReminders, type OrchestratorAwareToolPort, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UserAttachment, type UserMessagePayload, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, createLLM, generateFolderTree, getAvailableProviders, loadMCPConfig, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels };
package/dist/index.js CHANGED
@@ -1,4 +1,17 @@
1
1
  // ports.ts
2
+ var ErrorReason = /* @__PURE__ */ ((ErrorReason2) => {
3
+ ErrorReason2["Aborted"] = "aborted";
4
+ ErrorReason2["Denied"] = "denied";
5
+ ErrorReason2["Timeout"] = "timeout";
6
+ ErrorReason2["NotFound"] = "not_found";
7
+ ErrorReason2["PermissionDenied"] = "permission_denied";
8
+ ErrorReason2["InvalidInput"] = "invalid_input";
9
+ ErrorReason2["NetworkError"] = "network_error";
10
+ ErrorReason2["RateLimit"] = "rate_limit";
11
+ ErrorReason2["ToolNotFound"] = "tool_not_found";
12
+ ErrorReason2["Unknown"] = "unknown";
13
+ return ErrorReason2;
14
+ })(ErrorReason || {});
2
15
  var MessageRoles = {
3
16
  System: "system",
4
17
  User: "user",
@@ -1860,8 +1873,9 @@ import * as path3 from "path";
1860
1873
  function ok(result, metadata) {
1861
1874
  return { status: "success", type: "text", result, metadata };
1862
1875
  }
1863
- function err(result, metadata) {
1864
- return { status: "error", type: "text", result, metadata };
1876
+ function err(result, metadata, errorReason) {
1877
+ const finalMetadata = errorReason ? { ...metadata, errorReason } : metadata;
1878
+ return { status: "error", type: "text", result, metadata: finalMetadata };
1865
1879
  }
1866
1880
 
1867
1881
  // tools/FileReadTool.ts
@@ -2288,15 +2302,15 @@ var BashTool = class {
2288
2302
  return await this.execOnce(p, ctx?.signal);
2289
2303
  } catch (e) {
2290
2304
  if (e instanceof Error && e.name === "AbortError") {
2291
- return err("Command execution aborted by user");
2305
+ return err("Command execution aborted by user", void 0, "aborted" /* Aborted */);
2292
2306
  }
2293
2307
  const message = e instanceof Error ? e.message : String(e);
2294
- return err(message);
2308
+ return err(message, void 0, "unknown" /* Unknown */);
2295
2309
  }
2296
2310
  }
2297
2311
  async execOnce(p, signal) {
2298
2312
  if (signal?.aborted) {
2299
- return err("Command execution aborted by user");
2313
+ return err("Command execution aborted by user", void 0, "aborted" /* Aborted */);
2300
2314
  }
2301
2315
  const { cmd, cwd = process.cwd(), timeoutMs = DEFAULTS.timeoutMs } = p;
2302
2316
  const maxOutputBytes = DEFAULTS.maxOutputBytes;
@@ -2314,7 +2328,7 @@ var BashTool = class {
2314
2328
  });
2315
2329
  } catch (error) {
2316
2330
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
2317
- return err(`Shell not found: ${executable}`);
2331
+ return err(`Shell not found: ${executable}`, void 0, "not_found" /* NotFound */);
2318
2332
  }
2319
2333
  throw error;
2320
2334
  }
@@ -2324,8 +2338,10 @@ var BashTool = class {
2324
2338
  }
2325
2339
  });
2326
2340
  let timer = null;
2341
+ let timedOut = false;
2327
2342
  const deadline = new Promise((_, rej) => {
2328
2343
  timer = setTimeout(() => {
2344
+ timedOut = true;
2329
2345
  try {
2330
2346
  child.kill("SIGKILL");
2331
2347
  } catch {
@@ -2368,8 +2384,12 @@ var BashTool = class {
2368
2384
  }
2369
2385
  arr.push(chunk);
2370
2386
  };
2371
- child.stdout.on("data", (d) => capPush(stdout, d));
2372
- child.stderr.on("data", (d) => capPush(stderr, d));
2387
+ if (child.stdout) {
2388
+ child.stdout.on("data", (d) => capPush(stdout, d));
2389
+ }
2390
+ if (child.stderr) {
2391
+ child.stderr.on("data", (d) => capPush(stderr, d));
2392
+ }
2373
2393
  const exit = new Promise((res) => {
2374
2394
  child.on("close", (code, signal2) => res({ code, signal: signal2 }));
2375
2395
  });
@@ -2383,10 +2403,17 @@ var BashTool = class {
2383
2403
  const partialOutput = output ? `
2384
2404
  Output before abort:
2385
2405
  ${output}` : "";
2386
- return err(`Command execution aborted by user${partialOutput}`);
2406
+ return err(`Command execution aborted by user${partialOutput}`, { cwd }, "aborted" /* Aborted */);
2387
2407
  }
2388
2408
  if (code !== 0) {
2389
- return err(output, { code, signal: exitSignal, cwd });
2409
+ const metadata = { code, signal: exitSignal, cwd };
2410
+ if (output.toLowerCase().includes("permission denied")) {
2411
+ return err(output, { ...metadata, errorReason: "permission_denied" /* PermissionDenied */ });
2412
+ }
2413
+ if (output.toLowerCase().includes("command not found") || output.toLowerCase().includes("not found")) {
2414
+ return err(output, { ...metadata, errorReason: "not_found" /* NotFound */ });
2415
+ }
2416
+ return err(output, metadata);
2390
2417
  }
2391
2418
  return ok(output, { code, signal: exitSignal, cwd });
2392
2419
  } catch (e) {
@@ -2399,9 +2426,12 @@ ${output}` : "";
2399
2426
  const partialOutput = output ? `
2400
2427
  Output before abort:
2401
2428
  ${output}` : "";
2402
- return err(`Command execution aborted by user${partialOutput}`);
2429
+ return err(`Command execution aborted by user${partialOutput}`, { cwd }, "aborted" /* Aborted */);
2403
2430
  }
2404
- return err(message);
2431
+ if (timedOut) {
2432
+ return err(message, { cwd }, "timeout" /* Timeout */);
2433
+ }
2434
+ return err(message, { cwd }, "unknown" /* Unknown */);
2405
2435
  }
2406
2436
  }
2407
2437
  defaultShell() {
@@ -2617,8 +2647,10 @@ var AgentRegistry = class {
2617
2647
  this.filePersistence = options?.filePersistence;
2618
2648
  for (const agent of defaultAgents) {
2619
2649
  const complete = this.applyDefaults(agent);
2620
- this.agents.set(complete.id, complete);
2621
- this.defaultAgentIds.add(complete.id);
2650
+ if (complete.id) {
2651
+ this.agents.set(complete.id, complete);
2652
+ this.defaultAgentIds.add(complete.id);
2653
+ }
2622
2654
  }
2623
2655
  this.loadingPromise = this.loadAgents();
2624
2656
  }
@@ -2700,7 +2732,7 @@ var AgentRegistry = class {
2700
2732
  for (const agent of loadedAgents) {
2701
2733
  if (this.validateTemplate(agent)) {
2702
2734
  const complete = this.applyDefaults(agent);
2703
- if (!this.defaultAgentIds.has(complete.id)) {
2735
+ if (complete.id && !this.defaultAgentIds.has(complete.id)) {
2704
2736
  this.agents.set(complete.id, complete);
2705
2737
  }
2706
2738
  }
@@ -2749,9 +2781,6 @@ var AgentRegistry = class {
2749
2781
  if (!this.filePersistence) {
2750
2782
  throw new Error("File persistence not configured");
2751
2783
  }
2752
- if (!agent.id) {
2753
- throw new Error("Cannot save agent without ID");
2754
- }
2755
2784
  if (this.defaultAgentIds.has(agent.id)) {
2756
2785
  throw new Error(`Cannot save default agent "${agent.id}" to file`);
2757
2786
  }
@@ -2973,8 +3002,8 @@ var AgentManager = class {
2973
3002
  this.llmFactory = llmFactory;
2974
3003
  this.eventCallback = eventCallback;
2975
3004
  this.configResolver = configResolver;
2976
- if (llmFactory) {
2977
- this.llmResolver = new LLMResolver(llmFactory);
3005
+ if (this.llmFactory) {
3006
+ this.llmResolver = new LLMResolver(this.llmFactory);
2978
3007
  }
2979
3008
  }
2980
3009
  llmResolver = null;
@@ -3152,7 +3181,9 @@ var AgentManager = class {
3152
3181
  */
3153
3182
  resolveLLM(config) {
3154
3183
  if (!this.llmResolver) {
3155
- throw new Error("AgentManager requires LLMFactory to create sub-agents. Please provide llmFactory in constructor.");
3184
+ throw new Error(
3185
+ "AgentManager requires LLMFactory to create sub-agents. Please provide llmFactory in constructor."
3186
+ );
3156
3187
  }
3157
3188
  return this.llmResolver.resolve(config);
3158
3189
  }
@@ -3385,9 +3416,7 @@ var ToolRegistry = class {
3385
3416
  const delegationService = factory.create({
3386
3417
  agentRegistry: this.agentRegistry,
3387
3418
  commandRunner,
3388
- agentListProvider: () => this.agentRegistry.list().filter(
3389
- (agent) => typeof agent.id === "string" && typeof agent.name === "string" && typeof agent.description === "string"
3390
- ).map((agent) => ({
3419
+ agentListProvider: () => this.agentRegistry.list().map((agent) => ({
3391
3420
  id: agent.id,
3392
3421
  name: agent.name,
3393
3422
  description: agent.description
@@ -3423,6 +3452,7 @@ var ToolRegistry = class {
3423
3452
  status: "error",
3424
3453
  type: "text",
3425
3454
  result: "Tool execution aborted by user",
3455
+ metadata: { errorReason: "aborted" /* Aborted */ },
3426
3456
  durationMs: 0
3427
3457
  });
3428
3458
  }
@@ -3438,6 +3468,7 @@ var ToolRegistry = class {
3438
3468
  status: "error",
3439
3469
  type: "text",
3440
3470
  result: "Tool execution aborted by user",
3471
+ metadata: { errorReason: "aborted" /* Aborted */ },
3441
3472
  durationMs: 0
3442
3473
  };
3443
3474
  }
@@ -3451,6 +3482,7 @@ var ToolRegistry = class {
3451
3482
  status: "error",
3452
3483
  type: "text",
3453
3484
  result: `Tool '${c.name}' not found`,
3485
+ metadata: { errorReason: "tool_not_found" /* ToolNotFound */ },
3454
3486
  durationMs: durationMs2
3455
3487
  };
3456
3488
  }
@@ -3656,9 +3688,7 @@ var AgentFilePersistence = class {
3656
3688
  fs8.unlinkSync(filePath);
3657
3689
  }
3658
3690
  } catch (error) {
3659
- throw new Error(
3660
- `Failed to delete agent ${agentId}: ${error instanceof Error ? error.message : String(error)}`
3661
- );
3691
+ throw new Error(`Failed to delete agent ${agentId}: ${error instanceof Error ? error.message : String(error)}`);
3662
3692
  }
3663
3693
  }
3664
3694
  /**
@@ -3898,7 +3928,7 @@ var BaseLLM = class {
3898
3928
  }
3899
3929
  for (const ch of choices) {
3900
3930
  const delta = ch.delta ?? ch.message ?? {};
3901
- const textDelta = delta.content || delta.reasoning;
3931
+ const textDelta = delta.content ?? void 0;
3902
3932
  if (typeof textDelta === "string" && textDelta.length > 0) {
3903
3933
  if (content === "") {
3904
3934
  const trimmedDelta = textDelta.replace(/^\n+/, "");
@@ -4364,7 +4394,7 @@ var GithubAuthTransport = class {
4364
4394
  if (!Array.isArray(messages.messages)) return false;
4365
4395
  return messages.messages.some((msg) => isVisionMessage(msg));
4366
4396
  }
4367
- makeAuthHeaders(url, headers, body) {
4397
+ makeAuthHeaders(headers, body) {
4368
4398
  const base = headers ? { ...headers } : {};
4369
4399
  if (this.apiKey) base.Authorization = `Bearer ${this.apiKey}`;
4370
4400
  base["editor-version"] = base["editor-version"] || "vscode/1.104.2";
@@ -4402,11 +4432,11 @@ var GithubAuthTransport = class {
4402
4432
  await this.exchangeToken(signal);
4403
4433
  }
4404
4434
  const fullUrl = this.buildFullUrl(url);
4405
- let res = await this.inner.get(fullUrl, this.makeAuthHeaders(fullUrl, headers), signal);
4435
+ let res = await this.inner.get(fullUrl, this.makeAuthHeaders(headers), signal);
4406
4436
  if (res.status === 401 && this.accessToken) {
4407
4437
  await this.exchangeToken(signal);
4408
4438
  const retryUrl = this.buildFullUrl(url);
4409
- res = await this.inner.get(retryUrl, this.makeAuthHeaders(retryUrl, headers), signal);
4439
+ res = await this.inner.get(retryUrl, this.makeAuthHeaders(headers), signal);
4410
4440
  }
4411
4441
  return res;
4412
4442
  }
@@ -4415,11 +4445,11 @@ var GithubAuthTransport = class {
4415
4445
  await this.exchangeToken(signal);
4416
4446
  }
4417
4447
  const fullUrl = this.buildFullUrl(url);
4418
- let res = await this.inner.postJson(fullUrl, body, this.makeAuthHeaders(fullUrl, headers, body), signal);
4448
+ let res = await this.inner.postJson(fullUrl, body, this.makeAuthHeaders(headers, body), signal);
4419
4449
  if (res.status === 401 && this.accessToken) {
4420
4450
  await this.exchangeToken(signal);
4421
4451
  const retryUrl = this.buildFullUrl(url);
4422
- res = await this.inner.postJson(retryUrl, body, this.makeAuthHeaders(retryUrl, headers, body), signal);
4452
+ res = await this.inner.postJson(retryUrl, body, this.makeAuthHeaders(headers, body), signal);
4423
4453
  }
4424
4454
  return res;
4425
4455
  }
@@ -4428,12 +4458,12 @@ var GithubAuthTransport = class {
4428
4458
  await this.exchangeToken(signal);
4429
4459
  }
4430
4460
  const fullUrl = this.buildFullUrl(url);
4431
- const hdrs = this.makeAuthHeaders(fullUrl, { Accept: "text/event-stream", ...headers || {} }, body);
4461
+ const hdrs = this.makeAuthHeaders({ Accept: "text/event-stream", ...headers || {} }, body);
4432
4462
  let res = await this.inner.postStream(fullUrl, body, hdrs, signal);
4433
4463
  if (res.status === 401 && this.accessToken) {
4434
4464
  await this.exchangeToken(signal);
4435
4465
  const retryUrl = this.buildFullUrl(url);
4436
- res = await this.inner.postStream(retryUrl, body, this.makeAuthHeaders(retryUrl, hdrs, body), signal);
4466
+ res = await this.inner.postStream(retryUrl, body, this.makeAuthHeaders(hdrs, body), signal);
4437
4467
  }
4438
4468
  return res;
4439
4469
  }
@@ -4572,9 +4602,11 @@ var AnthropicAISDKLLM = class {
4572
4602
  }
4573
4603
  updateCredentials(result) {
4574
4604
  if (result.type === "success" && result.access && result.refresh && result.expires) {
4575
- this.opts.oauth.access = result.access;
4576
- this.opts.oauth.refresh = result.refresh;
4577
- this.opts.oauth.expires = result.expires;
4605
+ if (this.opts.oauth) {
4606
+ this.opts.oauth.access = result.access;
4607
+ this.opts.oauth.refresh = result.refresh;
4608
+ this.opts.oauth.expires = result.expires;
4609
+ }
4578
4610
  this.opts.onTokenUpdate?.({
4579
4611
  access: result.access,
4580
4612
  refresh: result.refresh,
@@ -5376,7 +5408,7 @@ function normalizeMCPConfig(raw) {
5376
5408
  return { mcpServers: servers };
5377
5409
  }
5378
5410
  }
5379
- if (asRecord.config && typeof asRecord.config === "object") {
5411
+ if ("config" in asRecord && asRecord.config && typeof asRecord.config === "object") {
5380
5412
  const nested = asRecord.config;
5381
5413
  if (isValidConfig(nested)) {
5382
5414
  const servers = nested.mcpServers;
@@ -5405,23 +5437,26 @@ function isValidConfig(value) {
5405
5437
 
5406
5438
  // events.ts
5407
5439
  var PersistingConsoleEventPort = class {
5408
- // private console = new ConsoleEventPort();
5409
5440
  memory;
5410
5441
  maxPerConversation;
5442
+ writeQueue = Promise.resolve();
5411
5443
  constructor(opts) {
5412
5444
  this.memory = opts?.memory ?? new PersistedMemory(new JsonFileMemoryPersistence(opts?.filename || "events.json"));
5413
5445
  this.maxPerConversation = opts?.maxPerConversation ?? 500;
5414
5446
  }
5415
5447
  async emit(event) {
5416
- try {
5417
- const key = event?.conversationId ?? "default";
5418
- const existing = await this.memory.get(key);
5419
- const next = [...existing, { ...event }];
5420
- const max = this.maxPerConversation;
5421
- const trimmed = max > 0 && next.length > max ? next.slice(next.length - max) : next;
5422
- await this.memory.set(key, trimmed);
5423
- } catch {
5424
- }
5448
+ this.writeQueue = this.writeQueue.then(async () => {
5449
+ try {
5450
+ const key = event?.conversationId ?? "default";
5451
+ const existing = await this.memory.get(key);
5452
+ const next = [...existing, { ...event }];
5453
+ const max = this.maxPerConversation;
5454
+ const trimmed = max > 0 && next.length > max ? next.slice(next.length - max) : next;
5455
+ await this.memory.set(key, trimmed);
5456
+ } catch {
5457
+ }
5458
+ });
5459
+ return this.writeQueue;
5425
5460
  }
5426
5461
  };
5427
5462
  export {
@@ -5443,6 +5478,7 @@ export {
5443
5478
  DefaultDelegationService,
5444
5479
  DefaultSpecialistAgentFactory,
5445
5480
  DelegationServiceFactory,
5481
+ ErrorReason,
5446
5482
  GithubLLM,
5447
5483
  InMemoryMemory,
5448
5484
  InMemoryMetadata,
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@nuvin/nuvin-core",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
+ "author": "Marsch Huynh <marsch.huynh@gmail.com>",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/marschhuynh/nuvin-cli.git",
13
+ "directory": "packages/nuvin-core"
14
+ },
9
15
  "files": [
10
16
  "dist"
11
17
  ],
@@ -19,7 +25,6 @@
19
25
  "access": "public"
20
26
  },
21
27
  "keywords": [],
22
- "author": "Marsch Huynh <marsch.huynh@gmail.com>",
23
28
  "license": "Apache-2.0",
24
29
  "dependencies": {
25
30
  "@ai-sdk/anthropic": "^2.0.30",